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. if pick.primary_key is None:
  37. pick.statu.execute_statu = message.eError
  38. pick.statu.statu_description = " 唯一码不能为空!"
  39. return tf.MessageToString(pick, as_utf8=True)
  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. def check_measure_statu(self, key):
  47. if g_rabbitmq[key].statu is not None and g_rabbitmq[key].timeout() is False:
  48. # if 0.85 > self.measure_info[index].theta or self.measure_info[index].theta> 0.95:
  49. # return "角度偏差较大!"
  50. measure_info = message.measure_info()
  51. tf.Parse(g_rabbitmq[key].statu,measure_info)
  52. border_statu = measure_info.border_statu
  53. lidar_statu=measure_info.ground_status # 测量状态(正常,无数据、噪声、超界)
  54. if lidar_statu==MeasureStatu["ok"] :
  55. return True
  56. else:
  57. return "请根据提示操作!"
  58. #检测雷达超界信息
  59. # if (((border_statu >> 0) & 0x01) > 0):
  60. # results = results + "前超界!"
  61. # if (((border_statu >> 1) & 0x01) > 0):
  62. # results = results + "后超界!"
  63. # if (((border_statu >> 2) & 0x01) > 0):
  64. # results = results + "左超界!"
  65. # if (((border_statu >> 3) & 0x01) > 0):
  66. # results = results + "右超界!"
  67. # if (((border_statu >> 6) & 0x01) > 0):
  68. # results = results + "车辆超宽!"
  69. # if (((border_statu >> 7) & 0x01) > 0):
  70. # results = results + "轴距超差!"
  71. # if (((border_statu >> 8) & 0x01) > 0) or ((border_statu >> 9) & 0x01):
  72. # results = results + "方向盘未回正!"
  73. # if results == "" :
  74. # return True
  75. # else:
  76. # return results
  77. else:
  78. return "设备故障!"
  79. def check_in_mcpu_statu(self, key):
  80. if g_rabbitmq[key].statu is not None and g_rabbitmq[key].timeout() is False:
  81. im_mcpu_statu = message.in_mcpu_statu()
  82. tf.Parse(g_rabbitmq[key].statu,im_mcpu_statu)
  83. results = ""
  84. if im_mcpu_statu.back_io != 2:
  85. results = results + "车辆后超界!"
  86. if im_mcpu_statu.is_occupy != 2:
  87. results = results + "库位无车!"
  88. if im_mcpu_statu.heighth == 1:
  89. results = results + "未知车高!"
  90. if im_mcpu_statu.heighth == 5:
  91. results = results + "车辆超高!"
  92. if results == "" :
  93. return True
  94. else:
  95. return results
  96. else:
  97. return "设备故障!"
  98. def check_dispatch_node_statu(self, key):
  99. if g_rabbitmq[key].statu is not None and \
  100. g_rabbitmq[key].timeout() is False:
  101. dispatch_node_statu = message.dispatch_node_statu()
  102. tf.Parse(g_rabbitmq[key].statu,dispatch_node_statu)
  103. if dispatch_node_statu.statu != message.eFault:
  104. return True
  105. return "设备故障!"
  106. def get_height(self, in_mcpu_key):
  107. im_mcpu_statu = message.in_mcpu_statu()
  108. tf.Parse(g_rabbitmq[in_mcpu_key].statu,im_mcpu_statu)
  109. if im_mcpu_statu.heighth == 2:
  110. return 1.50
  111. elif im_mcpu_statu.heighth == 3:
  112. return 1.70
  113. elif im_mcpu_statu.heighth == 4:
  114. return 1.90
  115. check_command = CheckCommand()