diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2009-09-01 10:55:29 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2009-09-01 10:55:29 +0000 |
commit | be2c36e3ea8010065754858912fa700a48e58232 (patch) | |
tree | b51687f6ad1110338346075027bc1881d422c27c /jsongen.py | |
parent | 77d904797cfe8d1d2499e58c5cf316aa4731fa36 (diff) | |
download | gpsd-be2c36e3ea8010065754858912fa700a48e58232.tar.gz |
More fixes for dumping of AIS message 19.
Checkpoint before integrating generated parser code.
All regression tests pass.
Diffstat (limited to 'jsongen.py')
-rwxr-xr-x | jsongen.py | 54 |
1 files changed, 38 insertions, 16 deletions
@@ -258,9 +258,9 @@ ais_specs = ( ('shipname', 'string', None), ('shiptype', 'uinteger', '0'), ('to_bow', 'uinteger', '0'), - ('stern', 'uinteger', '0'), - ('port', 'uinteger', '0'), - ('starboard', 'uinteger', '0'), + ('to_stern', 'uinteger', '0'), + ('to_port', 'uinteger', '0'), + ('to_starboard', 'uinteger', '0'), ('epfd', 'uinteger', '0'), ('raim', 'boolean', 'false'), ('dte', 'integer', '1'), @@ -450,28 +450,37 @@ ais_specs = ( ('zonesize', 'uinteger', '0'), ), }, + # Structure of mesage 23 is a mystery + { + "initname" : "json_ais24", + "header": "\tAIS_HEADER,", + "structname": "ais->type24", + "fieldmap":( + # fieldname type default + ('partno', 'uinteger', '0'), + ('a.shipname', 'string', None), # Part A + ('b.shiptype', 'uinteger', '0'), # Part B + ('b.vendorid', 'string', None), # Part B + ('b.callsign', 'string', None), # Part B + ('b.mothership_mmsi', 'uinteger', '0'), # Part B + ('b.dim.to_bow', 'uinteger', '0'), # Part B + ('b.dim.to_stern', 'uinteger', '0'), # Part B + ('b.dim.to_port', 'uinteger', '0'), # Part B + ('b.dim.to_starboard', 'uinteger', '0'), # Part B + ), + }, ) # Give this global the string spec you need to convert with -g # We do it this mildly odd way only because passing Python multiline # string literals on the command line is inconvenient. -stringspec = \ - "\"channel_a\":%u,\"channel_b\":%u,"\ - "\"mode\":%u,\"power\":%u,"\ - "\"ne_lon\":%d,\"ne_lat\":%d,"\ - "\"sw_lon\":%d,\"sw_lat\":%d,"\ - "\"addressed\":%s,\"band_a\":%s,"\ - "\"band_b\":%s,\"zonesize\":\":%u}\r\n" +stringspec = "" -# You should not need to modify anything below this liine. +# You should not need to modify anything below this line. def generate(spec): - print """/* - * This is code generated by jsongen.py. Do not hand-hack it. - */ -""" - outboard = [] + global outboard for (attr, itype, default) in spec["fieldmap"]: if attr in spec.get("stringbuffered", []): if attr not in outboard: @@ -490,6 +499,8 @@ def generate(spec): target = attr else: target = structname + "." + attr + if "." in attr: + attr = attr[attr.rfind(".")+1:] print '\t{"%s",%s%s,%s.addr.%s = %s%s,' % \ (attr, " "*(12-len(attr)), itype, " "*(10-len(itype)), itype, deref, target) leader = " " * 35 @@ -503,6 +514,11 @@ def generate(spec): }; """ +# No code for gernerating dump functions yet. +# When we do this, remembeer that we have to suppress dump function +# generation from any spec with a union dot in the field names; +# those will have to be coded by hand. + def string_to_specifier(strspec): "Compile a Python-style format string to an attribute-type fieldmap." # Map C and Python-type format letters to JSON parser datatypes @@ -556,5 +572,11 @@ if __name__ == '__main__': if specify: string_to_specifier(stringspec) else: + print """/* + * This is code generated by jsongen.py. Do not hand-hack it. + */ +""" + outboard = [] for description in ais_specs: generate(description) + print "/* Generated code ends. */" |