CheckCommand.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import message_pb2 as message
  2. import google.protobuf.text_format as tf
  3. from async_communication import rabbit_async_communicator as g_rabbitmq
  4. MeasureStatu={"ok":0,"无数据":1,"噪声":2,"超界":3}
  5. class CheckCommand():
  6. def check_park_command(self, msg):
  7. park = message.park_table()
  8. tf.Parse(msg, park)
  9. unit_id = park.unit_id
  10. terminal_id = park.terminal_id
  11. measure_key="statu_ex:measure_%d_statu_port"% terminal_id
  12. in_mcpu_key="statu_ex:in_mcpu_%d_statu_port"% terminal_id
  13. dispatch_key="statu_ex:dispatch_%d_statu_port"% unit_id
  14. measure_results = self.check_measure_statu(measure_key)
  15. in_mcpu_results = self.check_in_mcpu_statu(in_mcpu_key)
  16. dispatch_results = self.check_dispatch_node_statu(dispatch_key)
  17. if measure_results is True and in_mcpu_results is True and dispatch_results is True:
  18. measure_statu = message.measure_info()
  19. tf.Parse(g_rabbitmq[measure_key].statu,measure_statu)
  20. park.entrance_measure_info.CopyFrom(measure_statu)
  21. park.entrance_measure_info.height = self.get_height(in_mcpu_key)
  22. return tf.MessageToString(park, as_utf8=True)
  23. else:
  24. park.statu.execute_statu = message.eError
  25. park.statu.statu_description = ""
  26. if measure_results is not True:
  27. park.statu.statu_description = park.statu.statu_description + measure_results + " "
  28. if in_mcpu_results is not True:
  29. park.statu.statu_description = park.statu.statu_description + in_mcpu_results + " "
  30. if dispatch_results is not True:
  31. park.statu.statu_description = park.statu.statu_description + dispatch_results + " "
  32. return tf.MessageToString(park, as_utf8=True)
  33. def check_pick_command(self, msg):
  34. pick = message.park_table()
  35. tf.Parse(msg, pick)
  36. unit_id = pick.unit_id
  37. if pick.primary_key is None:
  38. pick.statu.execute_statu = message.eError
  39. pick.statu.statu_description = " 唯一码不能为空!"
  40. return tf.MessageToString(pick, as_utf8=True)
  41. results = self.check_dispatch_node_statu(unit_id)
  42. if results is not True:
  43. pick.statu.execute_statu = message.eError
  44. pick.statu.statu_description = " 调度状态错误!"
  45. return tf.MessageToString(pick, as_utf8=True)
  46. return tf.MessageToString(pick, as_utf8=True)
  47. def check_measure_statu(self, key):
  48. if g_rabbitmq[key].statu is not None and g_rabbitmq[key].timeout() is False:
  49. # if 0.85 > self.measure_info[index].theta or self.measure_info[index].theta> 0.95:
  50. # return "角度偏差较大!"
  51. measure_info = message.measure_info()
  52. tf.Parse(g_rabbitmq[key].statu,measure_info)
  53. border_statu = measure_info.border_statu
  54. lidar_statu=measure_info.ground_status # 测量状态(正常,无数据、噪声、超界)
  55. if lidar_statu==MeasureStatu["ok"] :
  56. return True
  57. else:
  58. return "请根据提示操作!"
  59. #检测雷达超界信息
  60. # if (((border_statu >> 0) & 0x01) > 0):
  61. # results = results + "前超界!"
  62. # if (((border_statu >> 1) & 0x01) > 0):
  63. # results = results + "后超界!"
  64. # if (((border_statu >> 2) & 0x01) > 0):
  65. # results = results + "左超界!"
  66. # if (((border_statu >> 3) & 0x01) > 0):
  67. # results = results + "右超界!"
  68. # if (((border_statu >> 6) & 0x01) > 0):
  69. # results = results + "车辆超宽!"
  70. # if (((border_statu >> 7) & 0x01) > 0):
  71. # results = results + "轴距超差!"
  72. # if (((border_statu >> 8) & 0x01) > 0) or ((border_statu >> 9) & 0x01):
  73. # results = results + "方向盘未回正!"
  74. # if results == "" :
  75. # return True
  76. # else:
  77. # return results
  78. else:
  79. return "设备故障!"
  80. def check_in_mcpu_statu(self, key):
  81. if g_rabbitmq[key].statu is not None and g_rabbitmq[key].timeout() is False:
  82. im_mcpu_statu = message.in_mcpu_statu()
  83. tf.Parse(g_rabbitmq[key].statu,im_mcpu_statu)
  84. results = ""
  85. if im_mcpu_statu.back_io != 1:
  86. results = results + "车辆后超界!"
  87. if im_mcpu_statu.is_occupy != 2:
  88. results = results + "库位无车!"
  89. if im_mcpu_statu.heighth == 1:
  90. results = results + "未知车高!"
  91. if im_mcpu_statu.heighth == 5:
  92. results = results + "车辆超高!"
  93. if results == "" :
  94. return True
  95. else:
  96. return results
  97. else:
  98. return "设备故障!"
  99. def check_dispatch_node_statu(self, key):
  100. if g_rabbitmq[key].statu is not None and \
  101. g_rabbitmq[key].timeout() is False:
  102. dispatch_node_statu = message.dispatch_node_statu()
  103. tf.Parse(g_rabbitmq[key].statu,dispatch_node_statu)
  104. if dispatch_node_statu.statu != message.eFault:
  105. return True
  106. return "设备故障!"
  107. def get_height(self, in_mcpu_key):
  108. im_mcpu_statu = message.in_mcpu_statu()
  109. tf.Parse(g_rabbitmq[in_mcpu_key].statu,im_mcpu_statu)
  110. if im_mcpu_statu.heighth == 2:
  111. return 1.50
  112. elif im_mcpu_statu.heighth == 3:
  113. return 1.70
  114. elif im_mcpu_statu.heighth == 4:
  115. return 1.90
  116. check_command = CheckCommand()