check_command_GyBhhy.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. import sys
  2. sys.path.append("..")
  3. import threading
  4. import time
  5. import async_communication as CM
  6. import uuid
  7. import message_pb2 as message
  8. import google.protobuf.text_format as tf
  9. MeasureStatu={"ok":0,"无数据":1,"噪声":2,"超界":3}
  10. ArrowType={0:"正确图片",0x01:"向后调整",0x02:"向前调整",0x04:"向右调整",0x08:"向左调整"
  11. ,0x10:"左前调整",0x06:"右前调整",0x09:"右后调整",0x05:"左后调整"}
  12. class CommandChecker(threading.Thread):
  13. def __init__(self,db):
  14. threading.Thread.__init__(self)
  15. self._db = db
  16. self._dispatch_statu = CM.TimeStatu(timeout=0.1)
  17. self._measure_statu = CM.TimeStatu(timeout=0.1)
  18. self._plate_color = {'蓝色':'1','黑色':'2','黄色':'3','白色':'4','绿色':'5','其他':'6'}
  19. self.is_close = False
  20. def receive_dispatch_statu(self, statu, ex, key):
  21. self._dispatch_statu = statu
  22. def receive_measure_info(self,statu, ex, key):
  23. print(111)
  24. self._measure_statu = statu
  25. def stop(self):
  26. self.is_close = True
  27. def exit_isOK(self, pick_body):
  28. pick_table = message.pick_table()
  29. try:
  30. tf.Parse(pick_body, pick_table)
  31. except Exception as e:
  32. pick_table.statu.execute_statu = message.eError
  33. pick_table.statu.statu_description = "设备故障,请联系管理员!" + "(取车表单错误)" + str(e.args)
  34. return pick_table
  35. if pick_table.primary_key is None or pick_table.primary_key == '':
  36. pick_table.statu.execute_statu = message.eWarning
  37. pick_table.statu.statu_description = " 唯一码不能为空!"
  38. else:
  39. # 查询车位表和指令表是否有该车
  40. space_res = self._db.query_space_in_primary_key(pick_table.primary_key)
  41. command_res = self._db.query_command_in_primary_key(pick_table.primary_key)
  42. if len(command_res) > 0:
  43. pick_table.statu.execute_statu = message.eWarning
  44. pick_table.statu.statu_description = "指令正在执行中!请稍等!"
  45. elif len(space_res) <= 0:
  46. pick_table.statu.execute_statu = message.eWarning
  47. pick_table.statu.statu_description = "车辆信息不存在!"
  48. return pick_table
  49. def entrance_isOK(self, park_body):
  50. # 停车表单
  51. park_table = message.park_table()
  52. try:
  53. tf.Parse(park_body, park_table)
  54. except Exception as e:
  55. park_table.statu.execute_statu = message.eError
  56. park_table.statu.statu_description = "设备故障,请联系管理员!" + "(停车表单错误)" + str(e.args)
  57. return park_table
  58. # 检查调度状态
  59. key = "dispatch_%d_statu_port" % park_table.unit_id
  60. if (key in self._dispatch_statu) is False or self._dispatch_statu[key].timeout():
  61. park_table.statu.execute_statu = message.eError
  62. park_table.statu.statu_description = "设备故障,请联系管理员!" + "(调度)"
  63. return park_table
  64. key = "measure_%d_statu_port" % park_table.unit_id
  65. if (key in self._measure_statu) is False or self._measure_statu[key].timeout():
  66. park_table.statu.execute_statu = message.eError
  67. park_table.statu.statu_description = "设备故障,请联系管理员!" + "(雷达)"
  68. return park_table
  69. # 获取车高信息
  70. dispatch_node_statu = message.dispatch_node_statu()
  71. try:
  72. tf.Parse(self._dispatch_statu[key].statu, dispatch_node_statu)
  73. except Exception:
  74. park_table.statu.execute_statu = message.eError
  75. park_table.statu.statu_description = "设备故障,请联系管理员!" + "(调度状态消息错误)"
  76. return park_table
  77. if dispatch_node_statu.plc_carrier_status == 0:
  78. park_table.statu.execute_statu = message.eError
  79. park_table.statu.statu_description = "设备故障,请联系管理员!" + "(搬运器)"
  80. return park_table
  81. elif dispatch_node_statu.plc_carrier_status == 4:
  82. park_table.statu.execute_statu = message.eWarning
  83. park_table.statu.statu_description = "该单元设备维护中!请前往其他入口!"
  84. return park_table
  85. car_height = dispatch_node_statu.dispatch_plc_passway_status_vector[park_table.import_id - 1].car_height
  86. if car_height == 0:
  87. park_table.statu.execute_statu = message.eWarning
  88. park_table.statu.statu_description = "未检测到车辆!"
  89. return park_table
  90. elif car_height == 4:
  91. park_table.statu.execute_statu = message.eWarning
  92. park_table.statu.statu_description = "车辆超高,请退出车库!"
  93. return park_table
  94. # 填写车高信息
  95. measure_info = message.measure_info()
  96. measure_info.height = car_height
  97. park_table.entrance_measure_info.CopyFrom(measure_info)
  98. # 赋值唯一码
  99. uid = str(uuid.uuid1())
  100. park_table.primary_key = uid
  101. # 查询车位表和指令表是否有该车
  102. space_res = self._db.query_space_in_car_number(park_table.car_number)
  103. command_res = self._db.query_command_in_car_number(park_table.car_number)
  104. if len(command_res) > 0:
  105. park_table.statu.execute_statu = message.eWarning
  106. park_table.statu.statu_description = "指令正在执行中!请稍等!"
  107. elif len(space_res) > 0:
  108. park_table.statu.execute_statu = message.eWarning
  109. park_table.statu.statu_description = "车辆 :%s 已在库内!" % park_table.car_number
  110. else:
  111. # 车辆不在库内 查询是否有对应大小空车位
  112. space_res = self._db.query_space_in_height_unit_and_empty(measure_info.height, park_table.unit_id)
  113. command_res = self._db.query_command_in_height_unit_and_statu(measure_info.height, park_table.unit_id)
  114. if len(space_res) - len(command_res) <= 0:
  115. park_table.statu.execute_statu = message.eWarning
  116. park_table.statu.statu_description = "没有空余车位,车牌号:%s 高度:%.3fm!" % (park_table.car_number, measure_info.height)
  117. return park_table
  118. def run(self):
  119. while self.is_close is False:
  120. # print(self.error_str)
  121. time.sleep(0.05)
  122. # 先判断连接状态
  123. if self._dispatch_statu.timeout():
  124. self.error_str = "服务器超时,请联系管理员!"
  125. continue
  126. if self.measure_statu.timeout():
  127. self.error_str = '服务器超时,请联系管理员!'
  128. continue
  129. # 有车才显示
  130. icpu_statu = message.in_mcpu_statu()
  131. try:
  132. tf.Parse(self.icpu_statu.statu, icpu_statu)
  133. except:
  134. print(self.icpu_statu.statu)
  135. continue
  136. if icpu_statu.heighth == 1:
  137. self.error_str = '未知车高!'
  138. continue
  139. if icpu_statu.heighth == 5:
  140. self.error_str = '车辆超高!'
  141. continue
  142. # 以下是有车的处理
  143. # 1,显示测量数据(实时和静态)
  144. measure_info = message.measure_info()
  145. tf.Parse(self.measure_statu.statu, measure_info)
  146. # 2,获取车辆运动状态(静止or动态)
  147. border_statu = measure_info.border_statu
  148. is_moving = ((border_statu >> 11) & 0x01) == 1
  149. lidar_statu = measure_info.ground_status # 测量状态(正常,无数据、噪声、超界)
  150. if is_moving:
  151. self.last_moving_statu = None
  152. else:
  153. # 当前静止
  154. if lidar_statu == MeasureStatu["ok"]:
  155. self.last_moving_statu = measure_info
  156. elif lidar_statu == MeasureStatu["超界"]:
  157. if not self.last_moving_statu == None:
  158. # 上一刻静止且数据正确,当前静止,不可能出现超界,将超界清除
  159. new_border = border_statu
  160. new_border = (new_border & (~(0x01 << 0)))
  161. new_border = (new_border & (~(0x01 << 1)))
  162. new_border = (new_border & (~(0x01 << 2)))
  163. new_border = (new_border & (~(0x01 << 3)))
  164. new_border = (new_border & (~(0x01 << 6)))
  165. new_border = (new_border & (~(0x01 << 7)))
  166. new_border = (new_border & (~(0x01 << 8)))
  167. new_border = (new_border & (~(0x01 << 9)))
  168. border_statu = new_border
  169. elif lidar_statu == MeasureStatu["无数据"]:
  170. # 当前静止无车,清除上一时刻数据
  171. self.last_moving_statu = None
  172. elif lidar_statu == MeasureStatu["噪声"]:
  173. if not self.last_moving_statu == None:
  174. # 上一时刻静止且正确,当前噪声,不显示当前数据,显示上一正确数据
  175. measure_info.CopyFrom(self.last_moving_statu)
  176. # 先判断光电
  177. if is_moving:
  178. if icpu_statu.back_io == 1:
  179. self.error_str = '请按提示调整!'
  180. self.last_show = "调整"
  181. continue
  182. # 光电正常
  183. if lidar_statu == MeasureStatu["无数据"] and icpu_statu.is_occupy != 2:
  184. self.error_str = '无车!'
  185. self.last_show = "空闲"
  186. continue
  187. elif lidar_statu == MeasureStatu["噪声"]:
  188. if self.last_show == "超时":
  189. self.error_str = '雷达噪声'
  190. self.last_show = "空闲"
  191. continue
  192. elif lidar_statu == MeasureStatu["ok"]:
  193. self.error_str = 'OK'
  194. continue
  195. elif lidar_statu == MeasureStatu["超界"]:
  196. if (border_statu >> 7) & 0x01 == 1:
  197. self.error_str = '轴距不满足规格,请驶出!'
  198. self.last_show = "轴距超差"
  199. continue
  200. if (border_statu >> 9) & 0x01 == 1:
  201. self.error_str = '请按提示调整!'
  202. self.last_show = "请调整"
  203. continue
  204. if (border_statu >> 8) & 0x01 == 1:
  205. self.error_str = '请按提示调整!'
  206. self.last_show = "请调整"
  207. continue
  208. if (border_statu >> 10) & 0x01 == 1:
  209. self.error_str = '请按提示调整!'
  210. self.last_show = "请调整"
  211. continue
  212. if (border_statu >> 6) & 0x01 == 1:
  213. self.error_str = '车宽不满足规格,请驶出!'
  214. self.last_show = "超宽"
  215. continue
  216. border = border_statu & 0x0f
  217. if (border in ArrowType.keys()) is False:
  218. self.error_str = '服务器超时,请联系管理员!'
  219. self.last_show = "超时"
  220. else:
  221. if ArrowType[border] == "正确图片":
  222. self.error_str = "OK"
  223. self.last_show = "正确"
  224. else:
  225. self.error_str = "请按提示调整"
  226. self.last_show = "请调整"