mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-28 02:36:37 +08:00
add verification for the ID uniqueness; give list of available ID's
This commit is contained in:
@@ -82,6 +82,35 @@ def parse_yaml_msg_id_file(yaml_file):
|
|||||||
raise
|
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(
|
default_client_out = get_absolute_path(
|
||||||
"src/modules/micrortps_bridge/micrortps_client")
|
"src/modules/micrortps_bridge/micrortps_client")
|
||||||
default_agent_out = get_absolute_path(
|
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)
|
urtps_templates_dir = os.path.join(msg_folder, args.urtps_templates)
|
||||||
# parse yaml file into a map of ids
|
# parse yaml file into a map of ids
|
||||||
rtps_ids = parse_yaml_msg_id_file(os.path.join(msg_folder, args.yaml_file))
|
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'
|
uRTPS_CLIENT_TEMPL_FILE = 'microRTPS_client.cpp.template'
|
||||||
|
|||||||
@@ -347,18 +347,23 @@ def print_field_def(field):
|
|||||||
array_size, comment))
|
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):
|
def rtps_message_id(msg_id_map, message):
|
||||||
"""
|
"""
|
||||||
Get RTPS ID of uORB message
|
Get RTPS ID of uORB message
|
||||||
"""
|
"""
|
||||||
msg_id = -1
|
used_ids = list()
|
||||||
for dict in msg_id_map[0]['rtps']:
|
for dict in msg_id_map[0]['rtps']:
|
||||||
|
used_ids.append(dict['id'])
|
||||||
if message in dict['msg']:
|
if message in dict['msg']:
|
||||||
msg_id = dict['id']
|
return dict['id']
|
||||||
|
|
||||||
if msg_id != -1:
|
raise AssertionError(
|
||||||
return msg_id
|
"%s does not have a RTPS ID set in the definition file. Please add an ID from the available pool:\n" % message +
|
||||||
else:
|
", ".join('%d' % id for id in check_available_ids(used_ids)))
|
||||||
raise AssertionError(
|
|
||||||
"%s does not have a RTPS ID set in the definition file. Please add an ID from the available pool!")
|
|
||||||
exit(1)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user