Skip to content

Commit

Permalink
[python] ivy_msg_interface: find message class by name
Browse files Browse the repository at this point in the history
and don't treat sender_name (first string in ivy message) as msg_class
  • Loading branch information
flixr committed Dec 28, 2015
1 parent e282981 commit e80ac19
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
29 changes: 11 additions & 18 deletions sw/lib/python/ivy_msg_interface.py
Expand Up @@ -74,28 +74,21 @@ def on_ivy_msg(self, agent, *larg):
return

# check which message class it is
# pass non-telemetry messages with ac_id 0
if data[0] in ["sim", "ground_dl", "dl"]:
if self.verbose:
print("ignoring message " + larg[0])
sys.stdout.flush()
msg_name = data[1]
msg_class, msg_name = messages_xml_map.find_msg_by_name(msg_name)
if msg_class is None:
print("Ignoring unknown message " + larg[0])
return
elif data[0] in ["ground"]:
msg_class = data[0]
msg_name = data[1]
ac_id = 0
values = list(filter(None, data[2:]))
else:
# pass non-telemetry messages with ac_id 0
if msg_class == "telemetry":
try:
ac_id = int(data[0])
except ValueError:
if self.verbose:
print("ignoring message " + larg[0])
sys.stdout.flush()
return
msg_class = "telemetry"
msg_name = data[1]
values = list(filter(None, data[2:]))
print("ignoring message " + larg[0])
sys.stdout.flush()
else:
ac_id = 0
values = list(filter(None, data[2:]))
msg = PprzMessage(msg_class, msg_name)
msg.set_values(values)
self.callback(ac_id, msg)
Expand Down
11 changes: 11 additions & 0 deletions sw/lib/python/pprz_msg/messages_xml_map.py
Expand Up @@ -72,6 +72,17 @@ def parse_messages(messages_file=''):
message_dictionary_coefs[class_name][message_id].append(1.)


def find_msg_by_name(name):
if not message_dictionary:
parse_messages()
for msg_class in message_dictionary:
if name in message_dictionary[msg_class]:
#print("found msg name %s in class %s" % (name, msg_class))
return msg_class, name
print("Error: msg_name %s not found." % name)
return None, None


def get_msgs(msg_class):
if not message_dictionary:
parse_messages()
Expand Down

0 comments on commit e80ac19

Please sign in to comment.