CheckCommand.py 5.7 KB

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