mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-26 05:33:33 +08:00
add checker for multitopic msg naming
This commit is contained in:
@@ -37,6 +37,7 @@ import os
|
|||||||
import argparse
|
import argparse
|
||||||
import yaml
|
import yaml
|
||||||
import re
|
import re
|
||||||
|
import difflib
|
||||||
|
|
||||||
|
|
||||||
class Classifier():
|
class Classifier():
|
||||||
@@ -48,7 +49,10 @@ class Classifier():
|
|||||||
self.msg_folder = msg_folder
|
self.msg_folder = msg_folder
|
||||||
self.all_msgs_list = self.set_all_msgs()
|
self.all_msgs_list = self.set_all_msgs()
|
||||||
self.msg_id_map = self.parse_yaml_msg_id_file(yaml_file)
|
self.msg_id_map = self.parse_yaml_msg_id_file(yaml_file)
|
||||||
|
|
||||||
|
# Checkers
|
||||||
self.check_if_listed(yaml_file)
|
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_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()
|
self.msgs_to_receive, self.alias_msgs_to_receive = self.set_msgs_to_receive()
|
||||||
@@ -71,7 +75,8 @@ class Classifier():
|
|||||||
for dict in self.msg_id_map['rtps']:
|
for dict in self.msg_id_map['rtps']:
|
||||||
if 'send' in dict.keys():
|
if 'send' in dict.keys():
|
||||||
if 'alias' 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:
|
else:
|
||||||
send.update({dict['msg']: dict['id']})
|
send.update({dict['msg']: dict['id']})
|
||||||
return send, send_alias
|
return send, send_alias
|
||||||
@@ -82,7 +87,8 @@ class Classifier():
|
|||||||
for dict in self.msg_id_map['rtps']:
|
for dict in self.msg_id_map['rtps']:
|
||||||
if 'receive' in dict.keys():
|
if 'receive' in dict.keys():
|
||||||
if 'alias' 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:
|
else:
|
||||||
receive.update({dict['msg']: dict['id']})
|
receive.update({dict['msg']: dict['id']})
|
||||||
return receive, receive_alias
|
return receive, receive_alias
|
||||||
@@ -93,7 +99,8 @@ class Classifier():
|
|||||||
for dict in self.msg_id_map['rtps']:
|
for dict in self.msg_id_map['rtps']:
|
||||||
if (('send' not in dict.keys()) and ('receive' not in dict.keys())):
|
if (('send' not in dict.keys()) and ('receive' not in dict.keys())):
|
||||||
if 'alias' 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:
|
else:
|
||||||
ignore.update({dict['msg']: dict['id']})
|
ignore.update({dict['msg']: dict['id']})
|
||||||
return ignore, ignore_alias
|
return ignore, ignore_alias
|
||||||
@@ -133,6 +140,24 @@ class Classifier():
|
|||||||
"to be sent or received by the micro-RTPS bridge.\n"
|
"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")
|
"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
|
@staticmethod
|
||||||
def parse_yaml_msg_id_file(yaml_file):
|
def parse_yaml_msg_id_file(yaml_file):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -255,22 +255,22 @@ rtps:
|
|||||||
# multi topics
|
# multi topics
|
||||||
- msg: actuator_controls_0
|
- msg: actuator_controls_0
|
||||||
id: 120
|
id: 120
|
||||||
alias: actuactor_controls
|
alias: actuator_controls
|
||||||
- msg: actuator_controls_1
|
- msg: actuator_controls_1
|
||||||
id: 121
|
id: 121
|
||||||
alias: actuactor_controls
|
alias: actuator_controls
|
||||||
- msg: actuator_controls_2
|
- msg: actuator_controls_2
|
||||||
id: 122
|
id: 122
|
||||||
alias: actuactor_controls
|
alias: actuator_controls
|
||||||
- msg: actuator_controls_3
|
- msg: actuator_controls_3
|
||||||
id: 123
|
id: 123
|
||||||
alias: actuactor_controls
|
alias: actuator_controls
|
||||||
- msg: actuator_controls_virtual_fw
|
- msg: actuator_controls_virtual_fw
|
||||||
id: 124
|
id: 124
|
||||||
alias: actuactor_controls
|
alias: actuator_controls
|
||||||
- msg: actuator_controls_virtual_mc
|
- msg: actuator_controls_virtual_mc
|
||||||
id: 125
|
id: 125
|
||||||
alias: actuactor_controls
|
alias: actuator_controls
|
||||||
- msg: mc_virtual_attitude_setpoint
|
- msg: mc_virtual_attitude_setpoint
|
||||||
id: 126
|
id: 126
|
||||||
alias: vehicle_attitude_setpoint
|
alias: vehicle_attitude_setpoint
|
||||||
|
|||||||
Reference in New Issue
Block a user