mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-23 22:58:10 +08:00
improve verification of RTPS ID's uniqueness
This commit is contained in:
@@ -57,28 +57,63 @@ except ImportError:
|
||||
|
||||
def check_rtps_id_uniqueness(classifier):
|
||||
"""
|
||||
Checks if:
|
||||
1. there are no ID's for different msgs repeated on the map
|
||||
2. the same msg is set to be sent/received and unclassified at the same time
|
||||
Checks if there are no ID's for different msgs repeated on the map
|
||||
"""
|
||||
msgs_to_use = classifier.msgs_to_send
|
||||
msgs_to_use.update(classifier.msgs_to_receive)
|
||||
msgs_to_ignore = classifier.msgs_to_ignore
|
||||
|
||||
used_ids = msgs_to_use.values()
|
||||
used_ids.sort()
|
||||
repeated_ids = dict()
|
||||
|
||||
repeated_keys = dict()
|
||||
for key, value in msgs_to_use.items():
|
||||
if used_ids.count(value) > 1:
|
||||
repeated_keys.update({key: value})
|
||||
# check if there are repeated ID's on the messages to send
|
||||
for key, value in classifier.msgs_to_send.items():
|
||||
if classifier.msgs_to_send.values().count(value) > 1:
|
||||
repeated_ids.update({key: value})
|
||||
|
||||
if not repeated_keys:
|
||||
# check if there are repeated ID's on the messages to receive
|
||||
for key, value in classifier.msgs_to_receive.items():
|
||||
if classifier.msgs_to_receive.values().count(value) > 1:
|
||||
repeated_ids.update({key: value})
|
||||
|
||||
# check if there are repeated ID's on the messages to ignore
|
||||
for key, value in classifier.msgs_to_ignore.items():
|
||||
if classifier.msgs_to_ignore.values().count(value) > 1:
|
||||
repeated_ids.update({key: value})
|
||||
|
||||
# check if there are repeated IDs between classfied and unclassified msgs
|
||||
# check send and ignore lists
|
||||
send_ignore_common_ids = list(set(classifier.msgs_to_ignore.values(
|
||||
)).intersection(classifier.msgs_to_send.values()))
|
||||
for item in zip(classifier.msgs_to_send.items(), classifier.msgs_to_ignore.items()):
|
||||
for repeated in send_ignore_common_ids:
|
||||
if item[1] == repeated:
|
||||
repeated_ids.update({item[0]: item[1]})
|
||||
for item in classifier.msgs_to_ignore.items():
|
||||
for repeated in send_ignore_common_ids:
|
||||
if item[1] == repeated:
|
||||
repeated_ids.update({item[0]: item[1]})
|
||||
|
||||
# check receive and ignore lists
|
||||
receive_ignore_common_ids = list(set(classifier.msgs_to_ignore.values(
|
||||
)).intersection(classifier.msgs_to_receive.values()))
|
||||
for item in classifier.msgs_to_receive.items():
|
||||
for repeated in receive_ignore_common_ids:
|
||||
if item[1] == repeated:
|
||||
repeated_ids.update({item[0]: item[1]})
|
||||
for item in classifier.msgs_to_ignore.items():
|
||||
for repeated in receive_ignore_common_ids:
|
||||
if item[1] == repeated:
|
||||
repeated_ids.update({item[0]: item[1]})
|
||||
|
||||
all_msgs = classifier.msgs_to_send
|
||||
all_msgs.update(classifier.msgs_to_receive)
|
||||
all_msgs.update(classifier.msgs_to_ignore)
|
||||
all_ids = all_msgs.values()
|
||||
all_ids.sort()
|
||||
|
||||
if not repeated_ids:
|
||||
print("All good. RTPS ID's are unique")
|
||||
else:
|
||||
raise AssertionError(", ".join('%s' % msgs for msgs in repeated_keys.keys()) +
|
||||
" have their keys repeated. Please choose from the following pool:\n" +
|
||||
", ".join('%d' % id for id in px_generate_uorb_topic_helper.check_available_ids(used_ids)))
|
||||
raise AssertionError(", ".join('%s' % msgs for msgs in repeated_ids.keys()) +
|
||||
" have their ID's repeated. Please choose from the following pool:\n" +
|
||||
", ".join('%d' % id for id in px_generate_uorb_topic_helper.check_available_ids(all_ids)))
|
||||
|
||||
|
||||
default_client_out = px_generate_uorb_topic_helper.get_absolute_path(
|
||||
|
||||
@@ -377,18 +377,23 @@ def rtps_message_id(msg_id_map, message):
|
||||
"""
|
||||
Get RTPS ID of uORB message
|
||||
"""
|
||||
error_msg = ""
|
||||
|
||||
# check if the message has an ID set
|
||||
for dict in msg_id_map[0]['rtps']:
|
||||
if message in dict['msg']:
|
||||
if dict['id'] is not None:
|
||||
return dict['id']
|
||||
else:
|
||||
error_msg = "ID is None!"
|
||||
break
|
||||
|
||||
# create list of the available IDs if it fails to get an ID
|
||||
used_ids = list()
|
||||
# check 'send' list
|
||||
for dict in msg_id_map[0]['rtps']['send']:
|
||||
used_ids.append(dict['id'])
|
||||
if message in dict['msg']:
|
||||
return dict['id']
|
||||
# check 'receive' list
|
||||
for dict in msg_id_map[0]['rtps']['receive']:
|
||||
used_ids.append(dict['id'])
|
||||
if message in dict['msg']:
|
||||
return dict['id']
|
||||
for dict in msg_id_map[0]['rtps']:
|
||||
if dict['id'] is not None:
|
||||
used_ids.append(dict['id'])
|
||||
|
||||
raise AssertionError(
|
||||
"%s does not have a RTPS ID set in the definition file. Please add an ID from the available pool:\n" % message +
|
||||
"%s %s Please add an ID from the available pool:\n" % (message, error_msg) +
|
||||
", ".join('%d' % id for id in check_available_ids(used_ids)))
|
||||
|
||||
@@ -89,33 +89,36 @@ class Classifier():
|
||||
# setters (for class init)
|
||||
def set_msgs_to_send(self):
|
||||
send = {}
|
||||
for dict in self.msg_id_map['rtps']['send']:
|
||||
send.update({dict['msg']: dict['id']})
|
||||
for dict in self.msg_id_map['rtps']:
|
||||
if 'send' in dict.keys():
|
||||
send.update({dict['msg']: dict['id']})
|
||||
return send
|
||||
|
||||
def set_msgs_to_receive(self):
|
||||
receive = {}
|
||||
for dict in self.msg_id_map['rtps']['receive']:
|
||||
receive.update({dict['msg']: dict['id']})
|
||||
for dict in self.msg_id_map['rtps']:
|
||||
if 'receive' in dict.keys():
|
||||
receive.update({dict['msg']: dict['id']})
|
||||
return receive
|
||||
|
||||
def set_msgs_to_ignore(self):
|
||||
ignore = {}
|
||||
for dict in self.msg_id_map['rtps']['unclassified']:
|
||||
ignore.update({dict['msg']: dict['id']})
|
||||
for dict in self.msg_id_map['rtps']:
|
||||
if ('send' not in dict.keys()) and ('receive' not in dict.keys()):
|
||||
ignore.update({dict['msg']: dict['id']})
|
||||
return ignore
|
||||
|
||||
def set_msg_files_send(self):
|
||||
return [os.path.join(self.msg_folder, msg + ".msg")
|
||||
for msg in self.msgs_to_send.keys()]
|
||||
for msg in self.msgs_to_send.keys()]
|
||||
|
||||
def set_msg_files_receive(self):
|
||||
return [os.path.join(self.msg_folder, msg + ".msg")
|
||||
for msg in self.msgs_to_receive.keys()]
|
||||
for msg in self.msgs_to_receive.keys()]
|
||||
|
||||
def set_msg_files_ignore(self):
|
||||
return [os.path.join(self.msg_folder, msg + ".msg")
|
||||
for msg in self.msgs_to_ignore.keys()]
|
||||
for msg in self.msgs_to_ignore.keys()]
|
||||
|
||||
@staticmethod
|
||||
def parse_yaml_msg_id_file(yaml_file):
|
||||
@@ -154,7 +157,8 @@ if __name__ == "__main__":
|
||||
args = parser.parse_args()
|
||||
|
||||
msg_folder = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
classifier = Classifier(os.path.join(msg_folder, args.yaml_file), msg_folder)
|
||||
classifier = Classifier(os.path.join(
|
||||
msg_folder, args.yaml_file), msg_folder)
|
||||
|
||||
if args.send:
|
||||
if args.path:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user