node.py 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import sys
  2. from PyQt5.QtWidgets import QWidget, QApplication,QMainWindow,QLabel
  3. from PyQt5.QtCore import Qt
  4. import window_screen_pyqt as ws
  5. import async_communication as CM
  6. import led
  7. import DatabaseSearch as DB
  8. import json
  9. import google.protobuf.text_format as tf
  10. import message_pb2 as message
  11. with open("./ui_config.json",'r',encoding='utf-8') as fp:
  12. config=json.load(fp)
  13. led_cfg=config["led"]
  14. db_cfg=config["db"]
  15. rabbitmq_cfg=config["rabbitmq"]
  16. node_id=config["entrance_id"]
  17. unit=config["unit"]
  18. prj_parameter=config.get("prj")
  19. #启动入口单片机,向rabbitmq发送数据,并接收关门请求
  20. #[消息服务器ip,port,用户,密码,状态交换机名称,状态消息key]
  21. statu_ex_keys=[["statu_ex","in_mcpu_%d_statu_port"%node_id],
  22. ["statu_ex","measure_%d_statu_port"%node_id],
  23. ["statu_ex","terminal_node_%d_statu_port"%node_id]
  24. ]
  25. cpu_ex,cpu_key=statu_ex_keys[0]
  26. measure_ex,measure_key=statu_ex_keys[1]
  27. terminal_ex,terminal_key=statu_ex_keys[2]
  28. g_rabbitmq=CM.RabbitAsyncCommunicator(rabbitmq_cfg["ip"],rabbitmq_cfg["port"],
  29. rabbitmq_cfg["user"],rabbitmq_cfg["password"])
  30. g_rabbitmq.Init(None,statu_ex_keys)
  31. g_rabbitmq.start()
  32. #启动led
  33. led=led.EntranceLED(led_cfg["ip"],led_cfg['port'])
  34. def db_callback(suv,small):
  35. idle = False
  36. time_statu = g_rabbitmq._status.get(cpu_ex+":"+cpu_key)
  37. if not time_statu==None:
  38. if not time_statu.statu==None:
  39. icpu_statu = message.in_mcpu_statu()
  40. tf.Parse(time_statu.statu, icpu_statu)
  41. idle = icpu_statu.is_occupy == 2
  42. led.fresh_led(suv,small,idle)
  43. #启动数据库,绑定led与数据库
  44. DBSearcher=DB.DBSeacher(db_cfg["ip"],db_cfg["port"],db_cfg["database"],
  45. db_cfg["user"],db_cfg["password"],unit)
  46. DBSearcher.set_ledcallback(db_callback)
  47. DBSearcher.start()
  48. #启动界面
  49. #绑定单片机与界面
  50. images={"传感器超时":"./resource/arrows/传感器超时.png",
  51. "测绘超时":"./resource/arrows/测绘超时.png",
  52. "正确文字":"./resource/arrows/正确文字.png",
  53. "正确图片":"./resource/arrows/正确图片.png",
  54. "超宽车辆":"./resource/arrows/超宽车辆.png",
  55. "轴距超差":"./resource/arrows/轴距超差.png",
  56. "请调整":"./resource/arrows/请调整.png",
  57. "向前调整":"./resource/arrows/向前调整.png",
  58. "向后调整":"./resource/arrows/向后调整.png",
  59. "向左调整":"./resource/arrows/向左调整.png",
  60. "向右调整":"./resource/arrows/向右调整.png",
  61. "左前调整":"./resource/arrows/左前调整.png",
  62. "左后调整":"./resource/arrows/左后调整.png",
  63. "右前调整":"./resource/arrows/右前调整.png",
  64. "右后调整":"./resource/arrows/右后调整.png",
  65. "向左旋转":"./resource/arrows/向左旋转.png",
  66. "向右旋转":"./resource/arrows/向右旋转.png",
  67. "空闲":"./resource/arrows/空闲.png",
  68. "回正方向盘":"./resource/arrows/回正方向盘.png",
  69. "检查杂物":"./resource/arrows/检查杂物.png"}
  70. app = QApplication(sys.argv)
  71. frame = ws.Frame(images,prj_parameter,True)
  72. frame.resize(600, 900)
  73. frame.setWindowTitle("楚天大厦入口 %d 引导"%node_id)
  74. frame.show()
  75. frame.setWindowFlags(Qt.WindowMaximizeButtonHint|Qt.WindowCloseButtonHint)
  76. frame.showMaximized()
  77. g_rabbitmq.bind_statu_callback(cpu_ex,cpu_key,frame.receive_icpu)
  78. g_rabbitmq.bind_statu_callback(measure_ex,measure_key,frame.receive_measureInfo)
  79. g_rabbitmq.bind_statu_callback(terminal_ex,terminal_key,frame.receive_terminal)
  80. app.exec()
  81. DBSearcher.close()
  82. g_rabbitmq.close()
  83. DBSearcher.join()
  84. g_rabbitmq.join()