Skip to content
Snippets Groups Projects
Commit 2250946e authored by TSC21's avatar TSC21 Committed by Beat Küng
Browse files

add verification for the ID uniqueness; give list of available ID's

parent fc980493
No related branches found
No related tags found
No related merge requests found
......@@ -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'
......
......@@ -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)))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment