Skip to content

Commit

Permalink
add checker for multitopic msg naming
Browse files Browse the repository at this point in the history
  • Loading branch information
TSC21 authored and bkueng committed Jul 26, 2019
1 parent 3d9f83a commit 5b2d952
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
31 changes: 28 additions & 3 deletions msg/tools/uorb_rtps_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import argparse
import yaml
import re
import difflib


class Classifier():
Expand All @@ -48,7 +49,10 @@ def __init__(self, yaml_file, msg_folder):
self.msg_folder = msg_folder
self.all_msgs_list = self.set_all_msgs()
self.msg_id_map = self.parse_yaml_msg_id_file(yaml_file)

# Checkers
self.check_if_listed(yaml_file)
self.check_base_type()

self.msgs_to_send, self.alias_msgs_to_send = self.set_msgs_to_send()
self.msgs_to_receive, self.alias_msgs_to_receive = self.set_msgs_to_receive()
Expand All @@ -71,7 +75,8 @@ def set_msgs_to_send(self):
for dict in self.msg_id_map['rtps']:
if 'send' in dict.keys():
if 'alias' in dict.keys():
send_alias.append(({dict['msg']: dict['id']}, dict['alias']))
send_alias.append(
({dict['msg']: dict['id']}, dict['alias']))
else:
send.update({dict['msg']: dict['id']})
return send, send_alias
Expand All @@ -82,7 +87,8 @@ def set_msgs_to_receive(self):
for dict in self.msg_id_map['rtps']:
if 'receive' in dict.keys():
if 'alias' in dict.keys():
receive_alias.append(({dict['msg']: dict['id']}, dict['alias']))
receive_alias.append(
({dict['msg']: dict['id']}, dict['alias']))
else:
receive.update({dict['msg']: dict['id']})
return receive, receive_alias
Expand All @@ -93,7 +99,8 @@ def set_msgs_to_ignore(self):
for dict in self.msg_id_map['rtps']:
if (('send' not in dict.keys()) and ('receive' not in dict.keys())):
if 'alias' in dict.keys():
ignore_alias.append(({dict['msg']: dict['id']}, dict['alias']))
ignore_alias.append(
({dict['msg']: dict['id']}, dict['alias']))
else:
ignore.update({dict['msg']: dict['id']})
return ignore, ignore_alias
Expand Down Expand Up @@ -133,6 +140,24 @@ def check_if_listed(self, yaml_file):
"to be sent or received by the micro-RTPS bridge.\n"
"NOTE: If the message has multi-topics (#TOPICS), these should be added as well.\n")

def check_base_type(self):
"""
Check if alias message has correct base type
"""
rtps_registered_msgs = list(
dict['alias'] for dict in self.msg_id_map['rtps'] if 'alias' in dict.keys())
uorb_msg = list(msg for msg in self.all_msgs_list)
incorrect_base_types = list(set(rtps_registered_msgs) - set(uorb_msg))

base_types = {}
for incorrect in incorrect_base_types:
base_types.update({incorrect: difflib.get_close_matches(
incorrect, uorb_msg, n=1, cutoff=0.8)})

if len(base_types) > 0:
raise AssertionError(
('\n' + '\n'.join('\t- The multi-topic message base type {} does not exist. Did you mean \'{}\'?'.format(k, v[0]) for k, v in base_types.items())))

@staticmethod
def parse_yaml_msg_id_file(yaml_file):
"""
Expand Down
12 changes: 6 additions & 6 deletions msg/tools/uorb_rtps_message_ids.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -255,22 +255,22 @@ rtps:
# multi topics
- msg: actuator_controls_0
id: 120
alias: actuactor_controls
alias: actuator_controls
- msg: actuator_controls_1
id: 121
alias: actuactor_controls
alias: actuator_controls
- msg: actuator_controls_2
id: 122
alias: actuactor_controls
alias: actuator_controls
- msg: actuator_controls_3
id: 123
alias: actuactor_controls
alias: actuator_controls
- msg: actuator_controls_virtual_fw
id: 124
alias: actuactor_controls
alias: actuator_controls
- msg: actuator_controls_virtual_mc
id: 125
alias: actuactor_controls
alias: actuator_controls
- msg: mc_virtual_attitude_setpoint
id: 126
alias: vehicle_attitude_setpoint
Expand Down

0 comments on commit 5b2d952

Please sign in to comment.