|
@@ -13,10 +13,14 @@ from lib.UserWorkRecord import UserWorkRecord
|
|
|
|
|
|
topic_info_dict = {} # {<topic_name>: <last_log_key>}
|
|
topic_info_dict = {} # {<topic_name>: <last_log_key>}
|
|
|
|
|
|
|
|
+
|
|
def method_v001(_client, _userdata, message):
|
|
def method_v001(_client, _userdata, message):
|
|
"""消息处理方法"""
|
|
"""消息处理方法"""
|
|
|
|
+ # --- get ---
|
|
|
|
+ topic = _client.casper_info.get('topic')
|
|
|
|
+
|
|
# --- debug ---
|
|
# --- debug ---
|
|
- # methods.debug_log(f"TopicListener|17", f"#message.payload: {message.payload}")
|
|
|
|
|
|
+ # methods.debug_log(f"TopicListener|{topic}|23", f"#message.payload: {message.payload}")
|
|
# return
|
|
# return
|
|
|
|
|
|
# --- check ---
|
|
# --- check ---
|
|
@@ -32,15 +36,15 @@ def method_v001(_client, _userdata, message):
|
|
vehicle_id = log_dict.get('VehicleID')
|
|
vehicle_id = log_dict.get('VehicleID')
|
|
cockpit_id = log_dict.get('cockpitID')
|
|
cockpit_id = log_dict.get('cockpitID')
|
|
except Exception as exception:
|
|
except Exception as exception:
|
|
- methods.debug_log("TopicListener|35", f"#message.payload: {message.payload}")
|
|
|
|
- methods.debug_log("TopicListener|35", f"#exception: {exception.__class__.__name__}")
|
|
|
|
- methods.debug_log("TopicListener|35", f"#traceback: {traceback.format_exc()}")
|
|
|
|
|
|
+ methods.debug_log(f"TopicListener|{topic}|39", f"#message.payload: {message.payload}")
|
|
|
|
+ methods.debug_log(f"TopicListener|{topic}|39", f"#exception: {exception.__class__.__name__}")
|
|
|
|
+ methods.debug_log(f"TopicListener|{topic}|39", f"#traceback: {traceback.format_exc()}")
|
|
return
|
|
return
|
|
|
|
|
|
# --- check ---
|
|
# --- check ---
|
|
log_uuid = UserWorkRecord.get_log_uuid(user_uuid, log_time, vehicle_id, cockpit_id)
|
|
log_uuid = UserWorkRecord.get_log_uuid(user_uuid, log_time, vehicle_id, cockpit_id)
|
|
if not log_uuid:
|
|
if not log_uuid:
|
|
- methods.debug_log(f"TopicListener|error50", f"user_uuid: {user_uuid}, log_time: {log_time}")
|
|
|
|
|
|
+ methods.debug_log(f"TopicListener|{topic}|39", f"user_uuid: {user_uuid}, log_time: {log_time}")
|
|
return
|
|
return
|
|
|
|
|
|
# --- fill log_list ---
|
|
# --- fill log_list ---
|
|
@@ -97,7 +101,6 @@ def method_v001(_client, _userdata, message):
|
|
]
|
|
]
|
|
|
|
|
|
# --- get ---
|
|
# --- get ---
|
|
- topic = _client.casper_info.get('topic')
|
|
|
|
last_log_key = topic_info_dict.get(topic)
|
|
last_log_key = topic_info_dict.get(topic)
|
|
|
|
|
|
# --- check ---
|
|
# --- check ---
|
|
@@ -110,13 +113,11 @@ def method_v001(_client, _userdata, message):
|
|
topic_info_dict[topic] = log_key
|
|
topic_info_dict[topic] = log_key
|
|
|
|
|
|
# --- save ---
|
|
# --- save ---
|
|
- # methods.debug_log(f"TopicListener|113", f"#log_list: {log_list}")
|
|
|
|
|
|
+ # methods.debug_log(f"TopicListener|{topic}|116", f"#log_list: {log_list}")
|
|
log_file_path = os.path.join(Global.save_dir, f'{log_uuid}.log')
|
|
log_file_path = os.path.join(Global.save_dir, f'{log_uuid}.log')
|
|
methods.write_text(log_file_path, ' | '.join(log_list) + '\n', 'a')
|
|
methods.write_text(log_file_path, ' | '.join(log_list) + '\n', 'a')
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
def method_c001(_client, _userdata, message):
|
|
def method_c001(_client, _userdata, message):
|
|
"""消息处理方法"""
|
|
"""消息处理方法"""
|
|
"""
|
|
"""
|
|
@@ -171,19 +172,22 @@ def method_c001(_client, _userdata, message):
|
|
'vehicleID': '0538'
|
|
'vehicleID': '0538'
|
|
}
|
|
}
|
|
"""
|
|
"""
|
|
|
|
+ # --- get ---
|
|
|
|
+ topic = _client.casper_info.get('topic')
|
|
|
|
+
|
|
# --- debug ---
|
|
# --- debug ---
|
|
# methods.debug_log(f"TopicListener|168", f"#_client: {_client.casper_info} | {type(_client.casper_info)}")
|
|
# methods.debug_log(f"TopicListener|168", f"#_client: {_client.casper_info} | {type(_client.casper_info)}")
|
|
# methods.debug_log(f"TopicListener|168", f"#_client: {_userdata} | {type(_userdata)}")
|
|
# methods.debug_log(f"TopicListener|168", f"#_client: {_userdata} | {type(_userdata)}")
|
|
- # methods.debug_log(f"TopicListener|168", f"#message.payload: {message.payload}")
|
|
|
|
|
|
+ # methods.debug_log(f"TopicListener|{topic}|179", f"#message.payload: {message.payload}")
|
|
# return
|
|
# return
|
|
|
|
|
|
# --- check ---
|
|
# --- check ---
|
|
try:
|
|
try:
|
|
log_dict = json.loads(message.payload)
|
|
log_dict = json.loads(message.payload)
|
|
except Exception as exception:
|
|
except Exception as exception:
|
|
- methods.debug_log("TopicListener|79", f"#message.payload: {message.payload}")
|
|
|
|
- methods.debug_log("TopicListener|79", f"#exception: {exception.__class__.__name__}")
|
|
|
|
- methods.debug_log("TopicListener|79", f"#traceback: {traceback.format_exc()}")
|
|
|
|
|
|
+ methods.debug_log(f"TopicListener|{topic}|186", f"#message.payload: {message.payload}")
|
|
|
|
+ methods.debug_log(f"TopicListener|{topic}|186", f"#exception: {exception.__class__.__name__}")
|
|
|
|
+ methods.debug_log(f"TopicListener|{topic}|186", f"#traceback: {traceback.format_exc()}")
|
|
return
|
|
return
|
|
|
|
|
|
# --- check ---
|
|
# --- check ---
|
|
@@ -194,7 +198,7 @@ def method_c001(_client, _userdata, message):
|
|
cockpit_id = log_dict.get('cockpitID')
|
|
cockpit_id = log_dict.get('cockpitID')
|
|
log_uuid = UserWorkRecord.get_log_uuid(user_uuid, log_time, vehicle_id, cockpit_id)
|
|
log_uuid = UserWorkRecord.get_log_uuid(user_uuid, log_time, vehicle_id, cockpit_id)
|
|
if not log_uuid:
|
|
if not log_uuid:
|
|
- methods.debug_log(f"TopicListener|error92", f"user_uuid: {user_uuid}, log_time: {log_time}")
|
|
|
|
|
|
+ methods.debug_log(f"TopicListener|{topic}|201|error201", f"user_uuid: {user_uuid}, log_time: {log_time}")
|
|
return
|
|
return
|
|
|
|
|
|
# --- fill log_list ---
|
|
# --- fill log_list ---
|
|
@@ -249,7 +253,6 @@ def method_c001(_client, _userdata, message):
|
|
]
|
|
]
|
|
|
|
|
|
# --- get ---
|
|
# --- get ---
|
|
- topic = _client.casper_info.get('topic')
|
|
|
|
last_log_key = topic_info_dict.get(topic)
|
|
last_log_key = topic_info_dict.get(topic)
|
|
|
|
|
|
# --- check ---
|
|
# --- check ---
|
|
@@ -262,7 +265,7 @@ def method_c001(_client, _userdata, message):
|
|
topic_info_dict[topic] = log_key
|
|
topic_info_dict[topic] = log_key
|
|
|
|
|
|
# --- save ---
|
|
# --- save ---
|
|
- # methods.debug_log(f"TopicListener|158", f"#log_list: {log_list}")
|
|
|
|
|
|
+ # methods.debug_log(f"TopicListener|{topic}|268", f"#log_list: {log_list}")
|
|
log_file_path = os.path.join(Global.save_dir, f'{log_uuid}.log')
|
|
log_file_path = os.path.join(Global.save_dir, f'{log_uuid}.log')
|
|
methods.write_text(log_file_path, ' | '.join(log_list) + '\n', 'a')
|
|
methods.write_text(log_file_path, ' | '.join(log_list) + '\n', 'a')
|
|
|
|
|
|
@@ -271,17 +274,16 @@ class TopicListener:
|
|
"""
|
|
"""
|
|
"""
|
|
"""
|
|
|
|
|
|
-
|
|
|
|
def __init__(self, subscribe_topic, method_name):
|
|
def __init__(self, subscribe_topic, method_name):
|
|
self.subscribe_topic = subscribe_topic
|
|
self.subscribe_topic = subscribe_topic
|
|
self.method_name = method_name
|
|
self.method_name = method_name
|
|
|
|
|
|
def subscribe(self):
|
|
def subscribe(self):
|
|
|
|
|
|
-
|
|
|
|
|
|
+ # --- define ---
|
|
topic_info_dict[self.subscribe_topic] = str()
|
|
topic_info_dict[self.subscribe_topic] = str()
|
|
-
|
|
|
|
|
|
|
|
|
|
+ # --- set ---
|
|
if self.method_name == 'method_v001':
|
|
if self.method_name == 'method_v001':
|
|
method = method_v001
|
|
method = method_v001
|
|
elif self.method_name == 'method_c001':
|
|
elif self.method_name == 'method_c001':
|
|
@@ -289,7 +291,7 @@ class TopicListener:
|
|
else:
|
|
else:
|
|
method = None
|
|
method = None
|
|
|
|
|
|
-
|
|
|
|
|
|
+ # --- start ---
|
|
client = Global.emqx_factory.Client(host=Global.emqx_host, port=Global.emqx_port)
|
|
client = Global.emqx_factory.Client(host=Global.emqx_host, port=Global.emqx_port)
|
|
client.casper_info = {
|
|
client.casper_info = {
|
|
'topic': self.subscribe_topic
|
|
'topic': self.subscribe_topic
|