diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2009-09-01 07:16:05 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2009-09-01 07:16:05 +0000 |
commit | 2ca680896b4daea2a9a72e43ccb902e5ea2c9421 (patch) | |
tree | c84425c62c570ba2632446ab762ceac457b8e8c0 /jsongen.py | |
parent | 3ac6e831d951904c243b502af6e0db3fadedc874 (diff) | |
download | gpsd-2ca680896b4daea2a9a72e43ccb902e5ea2c9421.tar.gz |
Field type data for AIS message 5.
Diffstat (limited to 'jsongen.py')
-rwxr-xr-x | jsongen.py | 76 |
1 files changed, 51 insertions, 25 deletions
@@ -9,17 +9,11 @@ # import sys, getopt -# Map shared field names to data types -overrides = { - "raim":"boolean", - "accuracy":"boolean", - } - # # Here is the information that makes it all work - attribute, type, and # defult information for all fields. We can generate either a JSON # parser template spec or the C code for the correspondong dump functio -# from this informstion. Doing it this way guarantees consistency. +# from this information. Doing it this way guarantees consistency. # ais_specs = ( { @@ -38,8 +32,8 @@ ais_specs = ( ('heading', 'integer', 'AIS_HEADING_NOT_AVAILABLE'), ('second', 'uinteger', 'AIS_SEC_NOT_AVAILABLE'), ('maneuver', 'integer', 'AIS_SEC_INOPERATIVE'), - ('raim', 'boolean', ' false'), - ('radio', 'integer', ' 0'), + ('raim', 'boolean', 'false'), + ('radio', 'integer', '0'), ), }, { @@ -58,9 +52,51 @@ ais_specs = ( ), "stringbuffered":("timestamp",), }, + { + "initname" : "json_ais5", + "header": "\tAIS_HEADER,", + "structname": "ais->type5", + "fieldmap":( + # fieldname type default + ('imo', 'uinteger', '0'), + ('ais_version', 'uinteger', '0'), + ('callsign', 'string', None), + ('shipname', 'string', None), + ('shiptype', 'string', None), + ('to_bow', 'uinteger', '0'), + ('to_stern', 'uinteger', '0'), + ('to_port', 'uinteger', '0'), + ('to_starboard', 'uinteger', '0'), + ('epfd', 'string', None), + ('eta', 'string', None), + ('draught', 'real', '0.0'), + ('destination', 'string', None), + ('dte', 'uinteger', '1'), + ), + "stringbuffered":("eta",), + }, ) - + +# Map shared field names to data types +overrides = { + "raim":"boolean", + "accuracy":"boolean", + } + +# Give this global the string spec you need to convert with -g +# We do it this mildly odd way only becaue passing Python multiline +# string literals on the command line is inconvenient. +stringspec = \ + "\"seqno\":%u,\"dest_mmsi\":%u,"\ + "\"retransmit\":%u,\"application_id\":%u,"\ + "\"data\":\"%u:%s\"}\r\n" + +# You should not need to modify anything below this liine. + def generate(spec): + for (attr, itype, default) in spec["fieldmap"]: + if attr in spec.get("stringbuffered", []): + print " char %s[JSON_VAL_MAX+1];" % attr print " const struct json_attr_t %s[] = {" % spec["initname"] if "header" in spec: print spec["header"] @@ -100,7 +136,7 @@ def string_to_specifier(strspec): "integer": "0", "uinteger": "0", "real": "0.0", - "string": "None", + "string": None, "boolean": "false" } strspec = strspec.strip() @@ -119,23 +155,13 @@ def string_to_specifier(strspec): attr = attr[:-1] if attr in overrides: itype = overrides[attr] - print " (%s,%s%s,%s%s)," % (attr, " "*(14-len(attr)), itype, " "*(14-len(itype)), dftmap[itype]) + dflt = dftmap[itype] + if dflt is not None: + dflt = `dflt` + print " ('%s',%s'%s',%s%s)," % (attr, " "*(14-len(attr)), itype, " "*(14-len(itype)), dflt) print " )" -# Give this global the string spec you need to convert. -# We do it this mildly odd way only becaue passing Python multiline -# string literals on the command line is inconvenient. -stringspec = \ - "\"imo\":%u,\"ais_version\":%u,\"callsign\":\"%s\","\ - "\"shipname\":\"%s\",\"shiptype\":\"%s\","\ - "\"to_bow\":%u,\"to_stern\":%u,\"to_port\":%u,"\ - "\"to_starboard\":%u,\"epfd\":\"%u\","\ - "\"eta\":\"%02u-%02uT%02u:%02uZ\","\ - "\"draught\":%.1f,\"destination\":\"%s\","\ - "\"dte\":%u}\r\n" - - if __name__ == '__main__': try: (options, arguments) = getopt.getopt(sys.argv[1:], "g") |