Index: scripts/MsgUtils/msgutils/MsgData.py =================================================================== diff -u -rbde1243eb2ff6af2868f6c6ad0cb4f5760aaf68b -r2202de40fe8377f73b17cd3ab3d432b167dd5b66 --- scripts/MsgUtils/msgutils/MsgData.py (.../MsgData.py) (revision bde1243eb2ff6af2868f6c6ad0cb4f5760aaf68b) +++ scripts/MsgUtils/msgutils/MsgData.py (.../MsgData.py) (revision 2202de40fe8377f73b17cd3ab3d432b167dd5b66) @@ -35,7 +35,7 @@ # \return hex string representation of the inputted value @staticmethod def value_to_hex_string(value): - return f"0x{f'{value:x}'.upper()}" + return f"0x{f'{value:04x}'.upper()}" # \brief Print all loaded data to the console @@ -117,7 +117,7 @@ 'type': result[0], }) if msg_id_value in self.data: - print(f"WARNING: found MesgIDs with same value, {self.data[msg_id_value]['msg_id']} will be replaced by {row_data['msg_id']} for value {row_data['msg_id_hex_string']}") + print(f"WARNING: found MesgIDs ({self.data[msg_id_value]['msg_id_hex_string']}) with same value, {self.data[msg_id_value]['msg_id']} will be replaced by {row_data['msg_id']} for value {row_data['msg_id_hex_string']}") self.data[msg_id_value] = row_data in_file.close() # sort the collected entries @@ -133,7 +133,7 @@ # otherwise new data will be added to the existing data # \return none def loadConf(self, filename, clear=True): - name_regex = re.compile(r'[a-zA-Z][a-zA-Z0-9_]*') + name_regex = re.compile(r'^[a-zA-Z](?:[a-zA-Z0-9_]*[a-zA-Z0-9])?$') filename = Path(filename).resolve() if clear: self.data = { } @@ -146,18 +146,14 @@ if not line and row_data is not None: # check to see if data has already been collected for this msg_id_value if row_data['msg_id_value'] in self.data: - print(f"WARNING: found MesgIDs with same value, {self.data[row_data['msg_id_value']]['msg_id']} will be replaced by {row_data['msg_id']} for value {row_data['msg_id_hex_string']}") + print(f"WARNING: found message ({self.data[msg_id_value]['msg_id_hex_string']}) with same ID ({self.data[row_data['msg_id_value']]['msg_id']}) will be replaced by {row_data['msg_id']} for value {row_data['msg_id_hex_string']}") for item in self.data.values(): if item['msg_name'] == row_data['msg_name']: - print(f"WARNING: found MesgIDs with same name, {row_data['msg_name']}, skipping message") + print(f"WARNING: found message ({item['msg_id_hex_string']}, {row_data['msg_id_hex_string']}) with same name ({row_data['msg_name']}), skipping message") row_data = None break if row_data is not None: - if row_data['msg_id'] == '': - print(f"WARNING: message with ID {row_data['msg_id_hex_string']} contains blank msg_id, skipping message") - elif row_data['msg_name'] == '': - print(f"WARNING: message with ID {row_data['msg_id_hex_string']} contains blank msg_name, skipping message") - else: + if row_data['msg_id'] != '' and row_data['msg_name'] != '': self.data[row_data['msg_id_value']] = row_data entry_count += 1 row_data = None @@ -180,10 +176,13 @@ 'raw': line + '\n', } # message name (first line of message section) - elif row_data is not None and row_data['msg_id'] == '' and re.fullmatch(name_regex, line): + elif row_data is not None and row_data['msg_id'] == '': row_data['raw'] += line + '\n' row_data['msg_id'] = 'MSG_ID_' + '_'.join(word.upper() for word in line.split('_')) - row_data['msg_name'] = self.__message_name(row_data['msg_id']) + if re.fullmatch(name_regex, line): + row_data['msg_name'] = self.__message_name(row_data['msg_id']) + else: + print(f"WARNING: message {row_data['msg_id_hex_string']} contains invalid message name ({line})") # payload parameter elif row_data is not None and '=' in line: row_data['raw'] += line + '\n'