main.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/bluenviron/goroslib/v2/pkg/msgs/diagnostic_msgs"
  5. "strconv"
  6. )
  7. /*
  8. 激光雷达通讯轻微丢失
  9. */
  10. var (
  11. errorType = "2"
  12. errorCode = "21031001"
  13. code12 = "21"
  14. hardwareIdIndex = map[string]string{
  15. "batter": "00",
  16. "cloud": "01",
  17. "gateway": "02",
  18. "mcu": "03",
  19. "imu": "04",
  20. "odom": "05",
  21. "motor": "06",
  22. "preventFall": "07",
  23. "sonar": "08",
  24. "locate": "09",
  25. "laserLadar": "10",
  26. "electricDrive": "11",
  27. "infrared": "12",
  28. "livoxLidar": "13",
  29. "camera": "14",
  30. "navigation": "15",
  31. "system": "16",
  32. }
  33. )
  34. func Topic() string {
  35. return "/diagnostics"
  36. }
  37. func Label() string {
  38. return "errorcode#" + errorType + "#" + errorCode
  39. }
  40. func Rule(data *diagnostic_msgs.DiagnosticArray) string {
  41. if len(data.Status) == 0 {
  42. return ""
  43. }
  44. for _, status := range data.Status {
  45. if status.Level != 5 || len(status.Values) == 0 {
  46. continue
  47. }
  48. code34 := fmt.Sprintf("%02d", status.Level)
  49. code56 := hardwareIdIndex[status.HardwareId]
  50. intVal, err := strconv.Atoi(status.Values[1].Value)
  51. if err != nil {
  52. fmt.Println("字段 【status.Values[1].Value】转整数报错:", err)
  53. return ""
  54. }
  55. code78 := fmt.Sprintf("%02d", intVal)
  56. if errorCode == code12+code34+code56+code78 {
  57. return Label()
  58. }
  59. }
  60. return ""
  61. }