3 generate a MAVLink test suite 5 Copyright Andrew Tridgell 2011 6 Released under GNU GPL version 3 or later 8 from __future__
import print_function
9 from builtins
import range
12 from argparse
import ArgumentParser
15 from .
import mavparse
18 '''generate a test value for the ith field of a message''' 22 if type.find(
"[") != -1:
24 basetype = type[0:aidx]
25 if basetype ==
"array":
28 return '(const %s *)"%s%u"' % (basetype, f.name, i)
29 return '"%s%u"' % (f.name, i)
37 if type
in [
'int8_t',
'uint8_t']:
39 if type
in [
'uint8_t_mavlink_version']:
41 if type
in [
'int16_t',
'uint16_t']:
43 if type
in [
'int32_t',
'uint32_t']:
48 if type
in [
'int64_t',
'uint64_t']:
49 v = 9223372036854775807 + i*63
59 MAVLink protocol test implementation (auto-generated by mavtestgen.py) 63 Note: this file has been auto-generated. DO NOT EDIT 68 def generate_outputs(mav): 69 '''generate all message types as outputs''' 72 if m.name ==
"HEARTBEAT":
continue 73 outf.write(
"\tmav.%s_send(" % m.name.lower())
74 for i
in range(0, len(m.fields)):
76 outf.write(
"%s=%s" % (f.name,
gen_value(f, i,
'py')))
77 if i != len(m.fields)-1:
85 MAVLink protocol test implementation (auto-generated by mavtestgen.py) 89 Note: this file has been auto-generated. DO NOT EDIT 92 static void mavtest_generate_outputs(mavlink_channel_t chan) 96 if m.name ==
"HEARTBEAT":
continue 97 outf.write(
"\tmavlink_msg_%s_send(chan," % m.name.lower())
98 for i
in range(0, len(m.fields)):
101 if i != len(m.fields)-1:
111 parser = ArgumentParser(description=
"This tool generate MAVLink test suite")
112 parser.add_argument(
"-o",
"--output", default=
"mavtest", help=
"output folder [default: %(default)s]")
113 parser.add_argument(
"definitions", metavar=
"XML", nargs=
"+", help=
"MAVLink definitions")
114 args = parser.parse_args()
119 for fname
in args.definitions:
120 (m, e) = mavparse.parse_mavlink_xml(fname)
125 if mavparse.check_duplicates(msgs):
128 print(
"Found %u MAVLink message types" % len(msgs))
130 print(
"Generating python %s" % (args.output+
'.py'))
131 outf = open(args.output +
'.py',
"w")
135 print(
"Generating C %s" % (args.output+
'.h'))
136 outf = open(args.output +
'.h',
"w")
140 print(
"Generated %s OK" % args.output)
def generate_methods_python(outf, msgs)
def generate_methods_C(outf, msgs)
def gen_value(f, i, language)