|
@@ -10,12 +10,14 @@ import os
|
|
|
|
|
|
|
|
|
|
|
|
-save_dir = r'C:\temp'
|
|
|
+save_dir = r'C:\logs'
|
|
|
+
|
|
|
|
|
|
|
|
|
class MessageListener(object):
|
|
|
"""
|
|
|
"""
|
|
|
+ log_key = str()
|
|
|
|
|
|
@staticmethod
|
|
|
def v001(client, userdata, message):
|
|
@@ -25,28 +27,32 @@ class MessageListener(object):
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ file_name = methods.now_string('v001-%Y-%m-%d-%H.log')
|
|
|
+ log_file_path = os.path.join(save_dir, file_name)
|
|
|
log_dict = json.loads(message.payload)
|
|
|
-
|
|
|
- log_time = int(log_dict.get('timestamp'))/1000
|
|
|
- log_time = methods.ts_to_string(log_time)
|
|
|
- methods.debug_log(f"MessageListener24", f"#log_time: {log_time}")
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ log_list = [
|
|
|
+ f"timestamp: {methods.ts_to_string(int(log_dict.get('timestamp'))/1000)}",
|
|
|
+ f"userID: {log_dict.get('userID')}",
|
|
|
+ f"VehicleID: {log_dict.get('VehicleID')}",
|
|
|
+ f"directSwitch: {log_dict.get('baseControl')[0].get('directSwitch')}",
|
|
|
+ f"eStop: {log_dict.get('eStop')[0].get('eStop')}",
|
|
|
+ f"gearCaontrol: {log_dict.get('gearCaontrol')[0].get('gearCaontrol')}",
|
|
|
+ f"hazardLight: {log_dict.get('hazardLight')[0].get('hazardLight')}",
|
|
|
+ ]
|
|
|
+
|
|
|
+
|
|
|
+ if MessageListener.log_key and MessageListener.log_key == '-'.join(log_list[1:]):
|
|
|
+ return
|
|
|
+
|
|
|
+
|
|
|
+ if not MessageListener.log_key:
|
|
|
+ MessageListener.log_key = '-'.join(log_list[1:])
|
|
|
+
|
|
|
+ print(f'MessageListener24: #log_list: {log_list}', flush=True)
|
|
|
+ methods.write_text(log_file_path, ' | '.join(log_list) + '\n', 'a')
|
|
|
|
|
|
@classmethod
|
|
|
- def start_check_loop(cls):
|
|
|
+ def subscribe001(cls):
|
|
|
""""""
|
|
|
|
|
|
|
|
@@ -63,13 +69,13 @@ class MessageListener(object):
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
def run(cls, background_is=True):
|
|
|
thread_list = [
|
|
|
- threading.Thread(target=cls.start_check_loop),
|
|
|
+ threading.Thread(target=cls.subscribe001),
|
|
|
]
|
|
|
for thread in thread_list:
|
|
|
thread.setDaemon(True)
|