CheckEntrance.py 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. import datetime
  2. import threading
  3. import time
  4. import async_communication as CM
  5. import message_pb2 as message
  6. import google.protobuf.text_format as tf
  7. import asyncio
  8. MeasureStatu={"ok":0,"无数据":1,"噪声":2,"超界":3}
  9. ArrowType={0:"正确图片",0x01:"向后调整",0x02:"向前调整",0x04:"向右调整",0x08:"向左调整"
  10. ,0x10:"左前调整",0x06:"右前调整",0x09:"右后调整",0x05:"左后调整"}
  11. class EntranceChecker(threading.Thread):
  12. def __init__(self):
  13. threading.Thread.__init__(self)
  14. self.icpu_statu = CM.TimeStatu(timeout=0.1)
  15. self.measure_statu = CM.TimeStatu(timeout=0.1)
  16. self.last_door_statu=None
  17. self.last_moving_statu = None
  18. self.last_show = None
  19. self.lock = threading.Lock()
  20. self.error_str=""
  21. self.is_close = False
  22. def receive_icpu(self,statu):
  23. self.icpu_statu=statu
  24. def receive_measureInfo(self,statu):
  25. self.measure_statu=statu
  26. async def exit_isOK(self, pick_table):
  27. if pick_table.primary_key is None:
  28. pick_table.statu.execute_statu = message.eError
  29. pick_table.statu.statu_description = " 唯一码不能为空!"
  30. return tf.MessageToString(pick_table, as_utf8=True)
  31. return tf.MessageToString(pick_table, as_utf8=True)
  32. async def entrance_isOK(self,park_table):
  33. park = message.park_table()
  34. park.CopyFrom(park_table)
  35. measure_info = message.measure_info()
  36. tf.Parse(self.measure_statu.statu, measure_info)
  37. tm = time.time()
  38. if self.error_str == 'OK':
  39. while time.time() - tm < 2:
  40. if measure_info.border_statu == MeasureStatu["ok"] and measure_info.ground_status == 0:
  41. park.statu.execute_statu = message.eNormal
  42. park.statu.statu_description = self.error_str
  43. park.entrance_measure_info.CopyFrom(measure_info)
  44. im_mcpu_statu = message.in_mcpu_statu()
  45. tf.Parse(self.icpu_statu.statu, im_mcpu_statu)
  46. if im_mcpu_statu.heighth == 2:
  47. park.entrance_measure_info.height = 1.50
  48. elif im_mcpu_statu.heighth == 3:
  49. park.entrance_measure_info.height = 1.70
  50. elif im_mcpu_statu.heighth == 4:
  51. park.entrance_measure_info.height = 1.90
  52. return tf.MessageToString(park, as_utf8=True)
  53. else:
  54. await asyncio.sleep(0.1)
  55. #time.sleep(0.1)
  56. if self.measure_statu.statu is not None and self.measure_statu.timeout() is False:
  57. try:
  58. measure_info = message.measure_info()
  59. tf.Parse(self.measure_statu.statu, measure_info)
  60. print("check measure info again:",measure_info)
  61. except:
  62. print("parse exception:\n"+self.measure_statu.statu)
  63. print(measure_info)
  64. park.statu.execute_statu = message.eError
  65. park.statu.statu_description = "请检查入口处是否有人员逗留!"
  66. return tf.MessageToString(park, as_utf8=True)
  67. else:
  68. print(measure_info)
  69. park.statu.execute_statu = message.eError
  70. park.statu.statu_description = self.error_str
  71. return tf.MessageToString(park, as_utf8=True)
  72. def run(self):
  73. while self.is_close is False:
  74. # print(self.error_str)
  75. time.sleep(0.05)
  76. #先判断连接状态
  77. if self.icpu_statu.timeout():
  78. self.error_str="服务器超时,请联系管理员!"
  79. continue
  80. if self.measure_statu.timeout():
  81. self.error_str='服务器超时,请联系管理员!'
  82. continue
  83. #有车才显示
  84. icpu_statu=message.in_mcpu_statu()
  85. try:
  86. tf.Parse(self.icpu_statu.statu,icpu_statu)
  87. except:
  88. print(self.icpu_statu.statu)
  89. continue
  90. if icpu_statu.heighth == 1:
  91. self.error_str = '未知车高!'
  92. continue
  93. if icpu_statu.heighth == 5:
  94. self.error_str = '车辆超高!'
  95. continue
  96. #以下是有车的处理
  97. #1,显示测量数据(实时和静态)
  98. measure_info=message.measure_info()
  99. tf.Parse(self.measure_statu.statu,measure_info)
  100. #2,获取车辆运动状态(静止or动态)
  101. border_statu=measure_info.border_statu
  102. is_moving = ((border_statu >> 11) & 0x01) == 1
  103. lidar_statu=measure_info.ground_status # 测量状态(正常,无数据、噪声、超界)
  104. if is_moving:
  105. self.last_moving_statu=None
  106. else:
  107. #当前静止
  108. if lidar_statu==MeasureStatu["ok"]:
  109. self.last_moving_statu=measure_info
  110. elif lidar_statu==MeasureStatu["超界"]:
  111. if not self.last_moving_statu ==None:
  112. #上一刻静止且数据正确,当前静止,不可能出现超界,将超界清除
  113. new_border=border_statu
  114. new_border = (new_border & (~(0x01 << 0)))
  115. new_border = (new_border & (~(0x01 << 1)))
  116. new_border = (new_border & (~(0x01 << 2)))
  117. new_border = (new_border & (~(0x01 << 3)))
  118. new_border = (new_border & (~(0x01 << 6)))
  119. new_border = (new_border & (~(0x01 << 7)))
  120. new_border = (new_border & (~(0x01 << 8)))
  121. new_border = (new_border & (~(0x01 << 9)))
  122. border_statu=new_border
  123. elif lidar_statu==MeasureStatu["无数据"]:
  124. #当前静止无车,清除上一时刻数据
  125. self.last_moving_statu=None
  126. elif lidar_statu==MeasureStatu["噪声"]:
  127. if not self.last_moving_statu==None:
  128. #上一时刻静止且正确,当前噪声,不显示当前数据,显示上一正确数据
  129. measure_info.CopyFrom(self.last_moving_statu)
  130. #先判断光电
  131. if is_moving:
  132. if icpu_statu.back_io==1:
  133. self.error_str='请按提示调整!'
  134. self.last_show="调整"
  135. continue
  136. #光电正常
  137. if lidar_statu==MeasureStatu["无数据"]and icpu_statu.is_occupy != 2:
  138. self.error_str='无车!'
  139. self.last_show="空闲"
  140. continue
  141. elif lidar_statu==MeasureStatu["噪声"]:
  142. if self.last_show=="超时":
  143. self.error_str='雷达噪声'
  144. self.last_show="空闲"
  145. continue
  146. elif lidar_statu==MeasureStatu["ok"]:
  147. self.error_str='OK'
  148. continue
  149. elif lidar_statu==MeasureStatu["超界"]:
  150. if (border_statu>>7)&0x01==1:
  151. self.error_str='轴距不满足规格,请驶出!'
  152. self.last_show="轴距超差"
  153. continue
  154. if (border_statu>>9)&0x01==1:
  155. self.error_str='请按提示调整!'
  156. self.last_show="请调整"
  157. continue
  158. if (border_statu>>8)&0x01==1:
  159. self.error_str='请按提示调整!'
  160. self.last_show="请调整"
  161. continue
  162. if (border_statu>>10)&0x01==1:
  163. self.error_str='请按提示调整!'
  164. self.last_show="请调整"
  165. continue
  166. if (border_statu>>6)&0x01==1:
  167. self.error_str='车宽不满足规格,请驶出!'
  168. self.last_show="超宽"
  169. continue
  170. border=border_statu&0x0f
  171. if (border in ArrowType.keys()) is False:
  172. self.error_str='服务器超时,请联系管理员!'
  173. self.last_show = "超时"
  174. else:
  175. if ArrowType[border] == "正确图片":
  176. self.error_str="OK"
  177. self.last_show="正确"
  178. else:
  179. self.error_str="请按提示调整"
  180. self.last_show="请调整"