diff --git a/msg/tools/generate_microRTPS_bridge.py b/msg/tools/generate_microRTPS_bridge.py index fe16649e7a..0082b6758f 100644 --- a/msg/tools/generate_microRTPS_bridge.py +++ b/msg/tools/generate_microRTPS_bridge.py @@ -82,6 +82,35 @@ def parse_yaml_msg_id_file(yaml_file): raise +def get_used_rtps_ids(msg_id_map): + msg_ids = {} + for dict in msg_id_map['rtps']: + msg_ids.update({dict['msg']: dict['id']}) + return msg_ids + + +def check_rtps_id_uniqueness(msg_id_map): + """ + Checks if there are no ID's repeated on the map + """ + msg_ids = get_used_rtps_ids(msg_id_map) + + used_ids = msg_ids.values() + used_ids.sort() + + repeated_keys = dict() + for key, value in msg_ids.items(): + if used_ids.count(value) > 1: + repeated_keys.update({key: value}) + + if not repeated_keys: + 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))) + + default_client_out = get_absolute_path( "src/modules/micrortps_bridge/micrortps_client") default_agent_out = get_absolute_path( @@ -206,6 +235,8 @@ uorb_templates_dir = os.path.join(msg_folder, args.uorb_templates) urtps_templates_dir = os.path.join(msg_folder, args.urtps_templates) # parse yaml file into a map of ids rtps_ids = parse_yaml_msg_id_file(os.path.join(msg_folder, args.yaml_file)) +# check if there are no ID's repeated +check_rtps_id_uniqueness(rtps_ids) uRTPS_CLIENT_TEMPL_FILE = 'microRTPS_client.cpp.template' diff --git a/msg/tools/px_generate_uorb_topic_helper.py b/msg/tools/px_generate_uorb_topic_helper.py index 6f3a6bb79f..40accb4565 100644 --- a/msg/tools/px_generate_uorb_topic_helper.py +++ b/msg/tools/px_generate_uorb_topic_helper.py @@ -347,18 +347,23 @@ def print_field_def(field): array_size, comment)) +def check_available_ids(used_msg_ids_list): + """ + Checks the available RTPS ID's + """ + return set(list(range(0, 255))) - set(used_msg_ids_list) + + def rtps_message_id(msg_id_map, message): """ Get RTPS ID of uORB message """ - msg_id = -1 + used_ids = list() for dict in msg_id_map[0]['rtps']: + used_ids.append(dict['id']) if message in dict['msg']: - msg_id = dict['id'] + return dict['id'] - if msg_id != -1: - return msg_id - else: - raise AssertionError( - "%s does not have a RTPS ID set in the definition file. Please add an ID from the available pool!") - exit(1) + raise AssertionError( + "%s does not have a RTPS ID set in the definition file. Please add an ID from the available pool:\n" % message + + ", ".join('%d' % id for id in check_available_ids(used_ids)))