|
@@ -13,10 +13,14 @@ from lib.UserWorkRecord import UserWorkRecord
|
|
|
|
|
|
topic_info_dict = {}
|
|
|
|
|
|
+
|
|
|
def method_v001(_client, _userdata, message):
|
|
|
"""消息处理方法"""
|
|
|
+
|
|
|
+ topic = _client.casper_info.get('topic')
|
|
|
+
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -32,15 +36,15 @@ def method_v001(_client, _userdata, message):
|
|
|
vehicle_id = log_dict.get('VehicleID')
|
|
|
cockpit_id = log_dict.get('cockpitID')
|
|
|
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
|
|
|
|
|
|
|
|
|
log_uuid = UserWorkRecord.get_log_uuid(user_uuid, log_time, vehicle_id, cockpit_id)
|
|
|
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
|
|
|
|
|
|
|
|
@@ -66,7 +70,7 @@ def method_v001(_client, _userdata, message):
|
|
|
f"accPedalF: {log_dict.get('driveControl')[0].get('accPedal')[0].get('accPedalF')}",
|
|
|
f"accPedalH: {log_dict.get('driveControl')[0].get('accPedal')[0].get('accPedalH')}",
|
|
|
|
|
|
- f"accPedalH: {log_dict.get('driveControl')[0].get('brakePedal')}",
|
|
|
+ f"brakePedal: {log_dict.get('driveControl')[0].get('brakePedal')}",
|
|
|
f"steeringWheel: {log_dict.get('driveControl')[0].get('steeringWheel')}",
|
|
|
f"turnMode: {log_dict.get('driveControl')[0].get('turnMode')}",
|
|
|
f"turnSignal: {log_dict.get('driveControl')[0].get('turnSignal')}",
|
|
@@ -97,7 +101,6 @@ def method_v001(_client, _userdata, message):
|
|
|
]
|
|
|
|
|
|
|
|
|
- topic = _client.casper_info.get('topic')
|
|
|
last_log_key = topic_info_dict.get(topic)
|
|
|
|
|
|
|
|
@@ -110,13 +113,11 @@ def method_v001(_client, _userdata, message):
|
|
|
topic_info_dict[topic] = log_key
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
log_file_path = os.path.join(Global.save_dir, f'{log_uuid}.log')
|
|
|
methods.write_text(log_file_path, ' | '.join(log_list) + '\n', 'a')
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
def method_c001(_client, _userdata, message):
|
|
|
"""消息处理方法"""
|
|
|
"""
|
|
@@ -171,19 +172,22 @@ def method_c001(_client, _userdata, message):
|
|
|
'vehicleID': '0538'
|
|
|
}
|
|
|
"""
|
|
|
+
|
|
|
+ topic = _client.casper_info.get('topic')
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
log_dict = json.loads(message.payload)
|
|
|
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
|
|
|
|
|
|
|
|
@@ -194,7 +198,7 @@ def method_c001(_client, _userdata, message):
|
|
|
cockpit_id = log_dict.get('cockpitID')
|
|
|
log_uuid = UserWorkRecord.get_log_uuid(user_uuid, log_time, vehicle_id, cockpit_id)
|
|
|
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
|
|
|
|
|
|
|
|
@@ -249,7 +253,6 @@ def method_c001(_client, _userdata, message):
|
|
|
]
|
|
|
|
|
|
|
|
|
- topic = _client.casper_info.get('topic')
|
|
|
last_log_key = topic_info_dict.get(topic)
|
|
|
|
|
|
|
|
@@ -262,7 +265,7 @@ def method_c001(_client, _userdata, message):
|
|
|
topic_info_dict[topic] = log_key
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
log_file_path = os.path.join(Global.save_dir, f'{log_uuid}.log')
|
|
|
methods.write_text(log_file_path, ' | '.join(log_list) + '\n', 'a')
|
|
|
|
|
@@ -271,17 +274,16 @@ class TopicListener:
|
|
|
"""
|
|
|
"""
|
|
|
|
|
|
-
|
|
|
def __init__(self, subscribe_topic, method_name):
|
|
|
self.subscribe_topic = subscribe_topic
|
|
|
self.method_name = method_name
|
|
|
|
|
|
def subscribe(self):
|
|
|
|
|
|
-
|
|
|
+
|
|
|
topic_info_dict[self.subscribe_topic] = str()
|
|
|
-
|
|
|
|
|
|
+
|
|
|
if self.method_name == 'method_v001':
|
|
|
method = method_v001
|
|
|
elif self.method_name == 'method_c001':
|
|
@@ -289,7 +291,7 @@ class TopicListener:
|
|
|
else:
|
|
|
method = None
|
|
|
|
|
|
-
|
|
|
+
|
|
|
client = Global.emqx_factory.Client(host=Global.emqx_host, port=Global.emqx_port)
|
|
|
client.casper_info = {
|
|
|
'topic': self.subscribe_topic
|