AuLongStop.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package main
  2. import (
  3. "cicv-data-closedloop/pjisuv_msgs"
  4. "cicv-data-closedloop/pjisuv_param"
  5. "fmt"
  6. "time"
  7. )
  8. var (
  9. StartTime int64
  10. IsStopped bool
  11. )
  12. func Topic() string {
  13. return "/cicv_location"
  14. }
  15. // Label todo 禁止存在下划线_
  16. func Label() string {
  17. return "AuLongStop"
  18. }
  19. func Rule(data *pjisuv_msgs.PerceptionLocalization, param *pjisuv_param.PjisuvParam) string {
  20. defer func() {
  21. if r := recover(); r != nil {
  22. fmt.Println("Recovered from panic:", r)
  23. }
  24. }()
  25. if param.AutomodeOfPjVehicleFdbPub == 1 {
  26. if data.VelocityX < 0.5 {
  27. // 如果之前没有记录开始时间,记录当前时间
  28. if StartTime == 0 {
  29. StartTime = time.Now().Unix()
  30. }
  31. // 判断是否持续超过 50s
  32. if time.Now().Unix()-StartTime > 50 {
  33. if !IsStopped {
  34. eventLabel := "AuLongStop"
  35. fmt.Println(eventLabel)
  36. IsStopped = true
  37. return "AuLongStop"
  38. }
  39. }
  40. } else {
  41. // 如果速度大于 0.1,重置开始时间和停止标志
  42. StartTime = 0
  43. IsStopped = false
  44. }
  45. } else {
  46. StartTime = 0
  47. IsStopped = false
  48. }
  49. return ""
  50. }