OverspeedAtNight.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package main
  2. import (
  3. "cicv-data-closedloop/pjisuv_msgs"
  4. "fmt"
  5. "sync"
  6. "time"
  7. )
  8. var (
  9. threshold float64 = 25 / 3.6
  10. count1 int = 0
  11. )
  12. func Topic() string {
  13. return "/cicv_location"
  14. }
  15. // 禁止存在下划线_
  16. func Label() string {
  17. return "OverspeedAtNight"
  18. }
  19. func Ifatnight() bool {
  20. // 获取当前时间
  21. now := time.Now()
  22. later := now.Add(0 * time.Hour)
  23. // 获取当前小时
  24. hour := later.Hour()
  25. // 判断当前时间是白天还是夜晚
  26. if hour >= 0 && hour < 5 || hour >= 20 && hour <= 23 {
  27. return true
  28. } else {
  29. return false
  30. }
  31. }
  32. func Rule(shareVars *sync.Map, data *pjisuv_msgs.PerceptionLocalization) string {
  33. defer func() {
  34. if r := recover(); r != nil {
  35. fmt.Println("Recovered from panic:", r)
  36. }
  37. }()
  38. if count1%100 == 0 {
  39. Automode, _ := shareVars.Load("AutomodeOfPjVehicleFdbPub")
  40. OutsideWorkshopFlag, _ := shareVars.Load("OutsideWorkshopFlag")
  41. Automode = Automode.(int16)
  42. if OutsideWorkshopFlag.(bool) && Automode == 1 && Ifatnight() {
  43. absspeed, ok := shareVars.Load("AbsSpeed")
  44. if ok && absspeed.(float64) >= threshold {
  45. eventLabel := "OverspeedAtNight"
  46. fmt.Println(eventLabel)
  47. count1 = 1
  48. return Label()
  49. }
  50. }
  51. count1 = 1
  52. }
  53. count1++
  54. return ""
  55. }