MessageListener.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from hub import methods, Global
  2. import threading
  3. import traceback
  4. import time
  5. import json
  6. import os
  7. class MessageListener:
  8. """
  9. """
  10. @classmethod
  11. def run(cls, background_is=True):
  12. from lib.UserWorkRecord import UserWorkRecord
  13. UserWorkRecord.init()
  14. from lib.TopicListener import TopicListener
  15. t1 = TopicListener('Cockpit/CanBus/CanId001/Cop001', 'method_c001')
  16. t2 = TopicListener('Vehicle/ControlVehicle/Veh001', 'method_v001')
  17. v1 = TopicListener('Vehicle/ControlVehicle/Veh0533', 'method_v001')
  18. v2 = TopicListener('Vehicle/ControlVehicle/Veh0534', 'method_v001')
  19. v3 = TopicListener('Vehicle/ControlVehicle/Veh0535', 'method_v001')
  20. v4 = TopicListener('Vehicle/ControlVehicle/Veh0537', 'method_v001')
  21. v5 = TopicListener('Vehicle/ControlVehicle/Veh0538', 'method_v001')
  22. thread_list = [
  23. threading.Thread(target=t1.subscribe),
  24. threading.Thread(target=t2.subscribe),
  25. threading.Thread(target=v1.subscribe),
  26. threading.Thread(target=v2.subscribe),
  27. threading.Thread(target=v3.subscribe),
  28. threading.Thread(target=v4.subscribe),
  29. threading.Thread(target=v5.subscribe),
  30. ]
  31. for thread in thread_list:
  32. thread.setDaemon(True)
  33. thread.start()
  34. if background_is:
  35. return
  36. for thread in thread_list:
  37. thread.join()
  38. if __name__ == '__main__':
  39. # --- test ---
  40. MessageListener.run()