|
|
|
@ -9,19 +9,33 @@ import sys
@@ -9,19 +9,33 @@ import sys
|
|
|
|
|
|
|
|
|
|
raw_messages = glob.glob(sys.argv[1]+"/msg/*.msg") |
|
|
|
|
messages = [] |
|
|
|
|
message_floats = [] |
|
|
|
|
message_elements = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for index,m in enumerate(raw_messages): |
|
|
|
|
temp_list = [] |
|
|
|
|
temp_list_floats = [] |
|
|
|
|
temp_list_uint64 = [] |
|
|
|
|
temp_list_bool = [] |
|
|
|
|
if("actuator_control" not in m and "pwm_input" not in m and "position_setpoint" not in m): |
|
|
|
|
temp_list = [] |
|
|
|
|
f = open(m,'r') |
|
|
|
|
for line in f.readlines(): |
|
|
|
|
if(line.split(' ')[0] == "float32"): |
|
|
|
|
temp_list.append(line.split(' ')[1].split('\t')[0].split('\n')[0]) |
|
|
|
|
temp_list.append(("float",line.split(' ')[1].split('\t')[0].split('\n')[0])) |
|
|
|
|
elif(line.split(' ')[0] == "uint64"): |
|
|
|
|
temp_list.append(("uint64",line.split(' ')[1].split('\t')[0].split('\n')[0])) |
|
|
|
|
elif (line.split(' ')[0] == "bool"): |
|
|
|
|
temp_list.append(("bool",line.split(' ')[1].split('\t')[0].split('\n')[0])) |
|
|
|
|
elif (line.split(' ')[0] == "uint8") and len(line.split('=')) == 1: |
|
|
|
|
temp_list.append(("uint8",line.split(' ')[1].split('\t')[0].split('\n')[0])) |
|
|
|
|
elif ('float32[' in line.split(' ')[0]): |
|
|
|
|
num_floats = int(line.split(" ")[0].split("[")[1].split("]")[0]) |
|
|
|
|
temp_list.append(("float_array",line.split(' ')[1].split('\t')[0].split('\n')[0],num_floats)) |
|
|
|
|
|
|
|
|
|
f.close() |
|
|
|
|
messages.append(m.split('/')[-1].split('.')[0]) |
|
|
|
|
message_floats.append(temp_list) |
|
|
|
|
message_elements.append(temp_list) |
|
|
|
|
|
|
|
|
|
num_messages = len(messages); |
|
|
|
|
|
|
|
|
|
print |
|
|
|
@ -76,6 +90,7 @@ print """
@@ -76,6 +90,7 @@ print """
|
|
|
|
|
#include <cstring> |
|
|
|
|
#include <uORB/uORB.h> |
|
|
|
|
#include <string.h> |
|
|
|
|
#include <stdint.h> |
|
|
|
|
""" |
|
|
|
|
for m in messages: |
|
|
|
|
print "#include <uORB/topics/%s.h>" % m |
|
|
|
@ -104,10 +119,28 @@ for index,m in enumerate(messages[1:]):
@@ -104,10 +119,28 @@ for index,m in enumerate(messages[1:]):
|
|
|
|
|
print "\t\tID = ORB_ID(%s);" % m |
|
|
|
|
print "\t\tstruct %s_s container;" % m |
|
|
|
|
print "\t\tmemset(&container, 0, sizeof(container));" |
|
|
|
|
print "\t\tbool updated;" |
|
|
|
|
print "\t\tfor(uint32_t i = 0;i<num_msgs;i++) {" |
|
|
|
|
print "\t\t\torb_check(sub,&updated);" |
|
|
|
|
print "\t\t\tupdated = true;" |
|
|
|
|
print "\t\t\tif(updated) {" |
|
|
|
|
print "\t\t\torb_copy(ID,sub,&container);" |
|
|
|
|
for item in message_floats[index+1]: |
|
|
|
|
print "\t\t\tprintf(\"%s: %%f\\n \",container.%s);" % (item, item) |
|
|
|
|
for item in message_elements[index+1]: |
|
|
|
|
if item[0] == "float": |
|
|
|
|
print "\t\t\tprintf(\"%s: %%f\\n \",container.%s);" % (item[1], item[1]) |
|
|
|
|
elif item[0] == "float_array": |
|
|
|
|
print "\t\t\tprintf(\"%s:\");" % item[1] |
|
|
|
|
print "\t\t\tfor (int j=0;j<%d;j++) {" % item[2] |
|
|
|
|
print "\t\t\t\tprintf(\"%%f \",container.%s[j]);" % item[1] |
|
|
|
|
print "\t\t\t}" |
|
|
|
|
print "\t\t\tprintf(\"\\n\");" |
|
|
|
|
elif item[0] == "uint64": |
|
|
|
|
print "\t\t\tprintf(\"%s: %%f\\n \",(float)container.%s);" % (item[1], item[1]) |
|
|
|
|
elif item[0] == "uint8": |
|
|
|
|
print "\t\t\tprintf(\"%s: %%f\\n \",(float)container.%s);" % (item[1], item[1]) |
|
|
|
|
elif item[0] == "bool": |
|
|
|
|
print "\t\t\tprintf(\"%s: %%s\\n \",container.%s ? \"True\" : \"False\");" % (item[1], item[1]) |
|
|
|
|
print "\t\t\t}" |
|
|
|
|
print "\t\t}" |
|
|
|
|
print "\t} else {" |
|
|
|
|
print "\t\t printf(\" Topic did not match any known topics\\n\");" |
|
|
|
|