diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2009-09-01 12:36:35 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2009-09-01 12:36:35 +0000 |
commit | 6c9afa38868a44acbaa5ae37e69dc92b7935b54e (patch) | |
tree | 4c055586844fda0cceb19014f371715de67a1323 | |
parent | be2c36e3ea8010065754858912fa700a48e58232 (diff) | |
download | gpsd-6c9afa38868a44acbaa5ae37e69dc92b7935b54e.tar.gz |
Generated AIS parser code compiles. All tests pass.
String field postprocessing and unit tests are next.
-rw-r--r-- | Makefile.am | 15 | ||||
-rw-r--r-- | ais_json.c | 68 | ||||
-rw-r--r-- | driver_aivdm.c | 22 | ||||
-rw-r--r-- | gps.h | 12 | ||||
-rw-r--r-- | gpsd_json.c | 59 | ||||
-rw-r--r-- | gpsdecode.c | 17 | ||||
-rwxr-xr-x | jsongen.py | 204 |
7 files changed, 138 insertions, 259 deletions
diff --git a/Makefile.am b/Makefile.am index f68a37b6..b8d6fa0f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -184,23 +184,30 @@ libgpsd_h_sources = \ bits.h \ crc24q.h -BUILT_SOURCES = packet_names.h gpsd.h +BUILT_SOURCES = packet_names.h gpsd.h ais_json.i packet_names.h: packet_states.h + rm -f $(srcdir)/packet_names.h sed -e '/^ *\([A-Z][A-Z0-9_]*\),/s// "\1",/' -e '/_states/s//_names/' < `test -f 'packet_states.h' || echo '$(srcdir)/'`packet_states.h > packet_names.h + chmod a-w $(srcdir)/packet_names.h gpsd.h: gpsd.h-head gpsd.h-tail gpsd_config.h - rm -f gpsd.h + rm -f $(srcdir)/gpsd.h echo "/* This file is generated. Do not hand-hack it! */" >gpsd.h cat $(srcdir)/gpsd.h-head >>gpsd.h grep VERSION gpsd_config.h >>gpsd.h grep ENABLE gpsd_config.h >>gpsd.h cat $(srcdir)/gpsd.h-tail >>gpsd.h - chmod a-w gpsd.h + chmod a-w $(srcdir)/gpsd.h + +ais_json.i: jsongen.py + rm -f $(srcdir)/ais_json.i + jsongen.py --ais --target=parser >ais_json.i + chmod a-w $(srcdir)/ais_json.i libgps_la_SOURCES = $(libgpsd_c_sources) $(libgpsd_h_sources) \ driver_rtcm2.h libgpsmm.cpp packet_states.h -nodist_libgps_la_SOURCES = packet_names.h +nodist_libgps_la_SOURCES = packet_names.h ais_json.i libgps_la_LIBADD = $(LIBM) $(LIBC) $(LIBNSL) $(LIBSOCKET) $(LIBPTHREAD) # @@ -33,44 +33,12 @@ int json_ais_read(const char *buf, {"device", string, .addr.string = path, \ .len = pathlen}, \ {"repeat", uinteger, .addr.uinteger = &ais->repeat}, \ - {"mmsi", uinteger, .addr.uinteger = &ais->mmsi}, + {"mmsi", uinteger, .addr.uinteger = &ais->mmsi} int status; - const struct json_attr_t json_ais1[] = { - AIS_HEADER - {NULL}, - }; - const struct json_attr_t json_ais4[] = { - AIS_HEADER - {NULL}, - }; - - const struct json_attr_t json_ais5[] = { - AIS_HEADER - {NULL}, - }; - - const struct json_attr_t json_ais6[] = { - AIS_HEADER - {NULL}, - }; - - const struct json_attr_t json_ais7[] = { - AIS_HEADER - {NULL}, - }; - - const struct json_attr_t json_ais8[] = { - AIS_HEADER - {NULL}, - }; - - const struct json_attr_t json_ais16[] = { - AIS_HEADER - {NULL}, - }; +#include "ais_json.i" /* JSON parser template structures */ #undef AIS_HEADER @@ -79,17 +47,47 @@ int json_ais_read(const char *buf, if (strstr(buf, "\"type\":1,")!=NULL || strstr(buf, "\"type\":2,")!=NULL || strstr(buf, "\"type\":3,")!=NULL) { status = json_read_object(buf, json_ais1, endptr); } else if (strstr(buf, "\"type\":4,") != NULL || strstr(buf, "\"type\":11,")!=NULL) { + // FIXME: Needs processing to handle timestamp status = json_read_object(buf, json_ais4, endptr); + // FIXME: Needs processing to handle eta } else if (strstr(buf, "\"type\":5,") != NULL) { status = json_read_object(buf, json_ais5, endptr); } else if (strstr(buf, "\"type\":6,") != NULL) { status = json_read_object(buf, json_ais6, endptr); - } else if (strstr(buf, "\"type\":7,") != NULL) { + } else if (strstr(buf, "\"type\":7,") != NULL || strstr(buf, "\"type\":13,") != NULL) { status = json_read_object(buf, json_ais7, endptr); } else if (strstr(buf, "\"type\":8,") != NULL) { + // FIXME: requires postprocessing of data field status = json_read_object(buf, json_ais8, endptr); + } else if (strstr(buf, "\"type\":9,") != NULL) { + status = json_read_object(buf, json_ais9, endptr); + } else if (strstr(buf, "\"type\":10,") != NULL) { + status = json_read_object(buf, json_ais10, endptr); + } else if (strstr(buf, "\"type\":12,") != NULL) { + status = json_read_object(buf, json_ais12, endptr); + } else if (strstr(buf, "\"type\":14,") != NULL) { + status = json_read_object(buf, json_ais14, endptr); + } else if (strstr(buf, "\"type\":15,") != NULL) { + status = json_read_object(buf, json_ais15, endptr); } else if (strstr(buf, "\"type\":16,") != NULL) { status = json_read_object(buf, json_ais16, endptr); + } else if (strstr(buf, "\"type\":17,") != NULL) { + // FIXME: requires postprocessing of data field + status = json_read_object(buf, json_ais17, endptr); + } else if (strstr(buf, "\"type\":18,") != NULL) { + status = json_read_object(buf, json_ais18, endptr); + } else if (strstr(buf, "\"type\":18,") != NULL) { + status = json_read_object(buf, json_ais17, endptr); + } else if (strstr(buf, "\"type\":19,") != NULL) { + status = json_read_object(buf, json_ais19, endptr); + } else if (strstr(buf, "\"type\":20,") != NULL) { + status = json_read_object(buf, json_ais20, endptr); + } else if (strstr(buf, "\"type\":21,") != NULL) { + status = json_read_object(buf, json_ais21, endptr); + } else if (strstr(buf, "\"type\":22,") != NULL) { + status = json_read_object(buf, json_ais22, endptr); + } else if (strstr(buf, "\"type\":24,") != NULL) { + status = json_read_object(buf, json_ais24, endptr); } else { return JSON_ERR_MISC; } diff --git a/driver_aivdm.c b/driver_aivdm.c index 71c0e403..684a1c83 100644 --- a/driver_aivdm.c +++ b/driver_aivdm.c @@ -244,13 +244,21 @@ bool aivdm_decode(char *buf, size_t buflen, struct aivdm_context_t *ais_context) ais->type6.bitcount); break; case 7: /* Binary acknowledge */ - for (i = 0; i < sizeof(ais->type7.mmsi)/sizeof(ais->type7.mmsi[0]); i++) + case 13: /* Safety Related Acknowledge */ + { + unsigned int mmsi[4]; + for (i = 0; i < sizeof(mmsi)/sizeof(mmsi[0]); i++) if (ais_context->bitlen > 40 + 32*i) - ais->type7.mmsi[i] = UBITS(40 + 32*i, 30); + mmsi[i] = UBITS(40 + 32*i, 30); else - ais->type7.mmsi[i] = 0; + mmsi[i] = 0; + ais->type7.mmsi1 = mmsi[0]; + ais->type7.mmsi2 = mmsi[1]; + ais->type7.mmsi3 = mmsi[2]; + ais->type7.mmsi4 = mmsi[3]; gpsd_report(LOG_INF, "\n"); break; + } case 8: /* Binary Broadcast Message */ //ais->type8.spare = UBITS(38, 2); ais->type8.app_id = UBITS(40, 16); @@ -304,14 +312,6 @@ bool aivdm_decode(char *buf, size_t buflen, struct aivdm_context_t *ais_context) ais->type12.seqno, ais->type12.dest_mmsi); break; - case 13: /* Safety Related Acknowledge */ - for (i = 0; i < sizeof(ais->type13.mmsi)/sizeof(ais->type13.mmsi[0]); i++) - if (ais_context->bitlen > 40 + 32*i) - ais->type13.mmsi[i] = UBITS(40 + 32*i, 30); - else - ais->type13.mmsi[i] = 0; - gpsd_report(LOG_INF, "\n"); - break; case 14: /* Safety Related Broadcast Message */ //ais->type14.spare = UBITS(38, 2); from_sixbit((char *)ais_context->bits, @@ -565,7 +565,11 @@ struct ais_t } type6; /* Type 7 - Binary Acknowledge */ struct { - uint mmsi[4]; /* spares ignored, they're only padding here */ + uint mmsi1; + uint mmsi2; + uint mmsi3; + uint mmsi4; + /* spares ignored, they're only padding here */ } type7; /* Type 8 - Broadcast Binary Message */ struct { @@ -608,10 +612,6 @@ struct ais_t #define AIS_TYPE12_TEXT_MAX 157 /* 936 bits of six-bit, plus NUL */ char text[AIS_TYPE12_TEXT_MAX]; } type12; - /* Type 7 - Safety-Related Acknowledge */ - struct { - uint mmsi[4]; /* spares ignored, they're only padding here */ - } type13; /* Type 14 - Safety-Related Broadcast Message */ struct { //uint spare; spare bit(s) */ @@ -695,7 +695,7 @@ struct ais_t uint to_starboard; /* dimension to starboard */ uint epfd; /* type of position fix deviuce */ bool raim; /* RAIM flag */ - bool dte; /* date terminal enable */ + uint dte; /* date terminal enable */ bool assigned; /* assigned-mode flag */ //uint spare; spare bits */ } type19; diff --git a/gpsd_json.c b/gpsd_json.c index 39b86b90..f6c0c610 100644 --- a/gpsd_json.c +++ b/gpsd_json.c @@ -658,8 +658,8 @@ void aivdm_json_dump(struct ais_t *ais, bool scaled, char *buf, size_t buflen) (void)snprintf(buf+strlen(buf), buflen-strlen(buf), "\"status\":\"%s\",\"turn\":%s,\"speed\":%s," "\"accuracy\":%s,\"lon\":%.4f,\"lat\":%.4f," - "\"course\":%u,\"heading\":%d,\"second\":%u," - "\"maneuver\":%d,\"raim\":%s,\"radio\":%d}\r\n", + "\"course\":%u,\"heading\":%u,\"second\":%u," + "\"maneuver\":%u,\"raim\":%s,\"radio\":%u}\r\n", nav_legends[ais->type1.status], turnlegend, speedlegend, @@ -676,8 +676,8 @@ void aivdm_json_dump(struct ais_t *ais, bool scaled, char *buf, size_t buflen) (void)snprintf(buf+strlen(buf), buflen-strlen(buf), "\"status\":%u,\"turn\":%d,\"speed\":%u," "\"accuracy\":%s,\"lon\":%d,\"lat\":%d," - "\"course\":%u,\"heading\":%d,\"second\":%u," - "\"maneuver\":%d,\"raim\":%s,\"radio\":%d}\r\n", + "\"course\":%u,\"heading\":%u,\"second\":%u," + "\"maneuver\":%u,\"raim\":%s,\"radio\":%u}\r\n", ais->type1.status, ais->type1.turn, ais->type1.speed, @@ -698,7 +698,7 @@ void aivdm_json_dump(struct ais_t *ais, bool scaled, char *buf, size_t buflen) (void)snprintf(buf+strlen(buf), buflen-strlen(buf), "\"timestamp\":\"%4u:%02u:%02uT%02u:%02u:%02uZ\"," "\"accuracy\":%s,\"lon\":%.4f,\"lat\":%.4f," - "\"epfd\":\"%s\",\"raim\":%s,\"radio\":%d}\r\n", + "\"epfd\":\"%s\",\"raim\":%s,\"radio\":%u}\r\n", ais->type4.year, ais->type4.month, ais->type4.day, @@ -715,7 +715,7 @@ void aivdm_json_dump(struct ais_t *ais, bool scaled, char *buf, size_t buflen) (void)snprintf(buf+strlen(buf), buflen-strlen(buf), "\"timestamp\":\"%4u:%02u:%02uT%02u:%02u:%02uZ\"," "\"accuracy\":%s,\"lon\":%d,\"lat\":%d," - "\"epfd\":%u,\"raim\":%s,\"radio\":%d}\r\n", + "\"epfd\":%u,\"raim\":%s,\"radio\":%u}\r\n", ais->type4.year, ais->type4.month, ais->type4.day, @@ -799,12 +799,13 @@ void aivdm_json_dump(struct ais_t *ais, bool scaled, char *buf, size_t buflen) (ais->type6.bitcount+7)/8)); break; case 7: /* Binary Acknowledge */ + case 13: /* Safety Related Acknowledge */ (void)snprintf(buf+strlen(buf), buflen-strlen(buf), "\"mmsi1\":%u,\"mmsi2\":%u,\"mmsi3\":%u,\"mmsi4\":%u}\r\n", - ais->type7.mmsi[0], - ais->type7.mmsi[1], - ais->type7.mmsi[2], - ais->type7.mmsi[3]); + ais->type7.mmsi1, + ais->type7.mmsi2, + ais->type7.mmsi3, + ais->type7.mmsi4); break; case 8: /* Binary Broadcast Message */ (void)snprintf(buf+strlen(buf), buflen-strlen(buf), @@ -819,8 +820,8 @@ void aivdm_json_dump(struct ais_t *ais, bool scaled, char *buf, size_t buflen) (void)snprintf(buf+strlen(buf), buflen-strlen(buf), "\"alt\":%u,\"speed\":%u,\"accuracy\":%s," "\"lon\":%.4f,\"lat\":%.4f,\"course\":%.1f," - "\"second\":%u,\"regional\":%d,\"dte\":%u," - "\"raim\":%s,\"radio\":%d}\r\n", + "\"second\":%u,\"regional\":%u,\"dte\":%u," + "\"raim\":%s,\"radio\":%u}\r\n", ais->type9.alt, ais->type9.speed, JSON_BOOL(ais->type9.accuracy), @@ -836,8 +837,8 @@ void aivdm_json_dump(struct ais_t *ais, bool scaled, char *buf, size_t buflen) (void)snprintf(buf+strlen(buf), buflen-strlen(buf), "\"alt\":%u,\"SPEED\":%u,\"accuracy\":%s," "\"lon\":%d,\"lat\":%d,\"course\":%u," - "\"second\":%u,\"regional\":%d,\"dte\":%u," - "\"raim\":%s,\"radio\":%d}\r\n", + "\"second\":%u,\"regional\":%u,\"dte\":%u," + "\"raim\":%s,\"radio\":%u}\r\n", ais->type9.alt, ais->type9.speed, JSON_BOOL(ais->type9.accuracy), @@ -858,20 +859,12 @@ void aivdm_json_dump(struct ais_t *ais, bool scaled, char *buf, size_t buflen) break; case 12: /* Safety Related Message */ (void)snprintf(buf+strlen(buf), buflen-strlen(buf), - "\"seq\":%u,\"dst\":%u,\"rexmit\":%u,\"text\":\"%s\"}\r\n", + "\"seqno\":%u,\"dest_mmsi\":%u,\"retransmit\":%s,\"text\":\"%s\"}\r\n", ais->type12.seqno, ais->type12.dest_mmsi, - ais->type12.retransmit, + JSON_BOOL(ais->type12.retransmit), json_stringify(buf1, sizeof(buf1), ais->type12.text)); break; - case 13: /* Safety Related Acknowledge */ - (void)snprintf(buf+strlen(buf), buflen-strlen(buf), - "\"mmsi1\":%u,\"mmsi2\":%u,\"mmsi3\":%u,\"mmsi4\":%u}\r\n", - ais->type13.mmsi[0], - ais->type13.mmsi[1], - ais->type13.mmsi[2], - ais->type13.mmsi[3]); - break; case 14: /* Safety Related Broadcast Message */ (void)snprintf(buf+strlen(buf), buflen-strlen(buf), "\"text\":\"%s\"}\r\n", @@ -926,9 +919,9 @@ void aivdm_json_dump(struct ais_t *ais, bool scaled, char *buf, size_t buflen) (void)snprintf(buf+strlen(buf), buflen-strlen(buf), "\"reserved\":%u,\"speed\":%.1f,\"accuracy\":%s," "\"lon\":%.4f,\"lat\":%.4f,\"course\":%.1f," - "\"heading\":%d,\"second\":%u,\"regional\":%d," + "\"heading\":%u,\"second\":%u,\"regional\":%u," "\"cs\":%s,\"display\":%s,\"dsc\":%s,\"band\":%s," - "\"msg22\":%s,\"raim\":%s,\"radio\":%d}\r\n", + "\"msg22\":%s,\"raim\":%s,\"radio\":%u}\r\n", ais->type18.reserved, ais->type18.speed / 10.0, JSON_BOOL(ais->type18.accuracy), @@ -949,9 +942,9 @@ void aivdm_json_dump(struct ais_t *ais, bool scaled, char *buf, size_t buflen) (void)snprintf(buf+strlen(buf), buflen-strlen(buf), "\"reserved\":%u,\"speed\":%u,\"accuracy\":%s," "\"lon\":%d,\"lat\":%d,\"course\":%u," - "\"heading\":%d,\"second\":%u,\"regional\":%d," + "\"heading\":%u,\"second\":%u,\"regional\":%u," "\"cs\":%s,\"display\":%s,\"dsc\":%s,\"band\":%s," - "\"msg22\":%s,\"raim\":%s,\"radio\":%d}\r\n", + "\"msg22\":%s,\"raim\":%s,\"radio\":%u}\r\n", ais->type18.reserved, ais->type18.speed, JSON_BOOL(ais->type18.accuracy), @@ -975,7 +968,7 @@ void aivdm_json_dump(struct ais_t *ais, bool scaled, char *buf, size_t buflen) (void)snprintf(buf+strlen(buf), buflen-strlen(buf), "\"reserved\":%u,\"speed\":%.1f,\"accuracy\":%s," "\"lon\":%.4f,\"lat\":%.4f,\"course\":%.1f," - "\"heading\":%d,\"second\":%u,\"regional\":%d," + "\"heading\":%u,\"second\":%u,\"regional\":%u," "\"shipname\":\"%s\",\"shiptype\":\"%s\"," "\"to_bow\":%u,\"to_stern\":%u,\"to_port\":%u," "\"to_starboard\":%u,\"epfd\":\"%s\",\"raim\":%s," @@ -1003,7 +996,7 @@ void aivdm_json_dump(struct ais_t *ais, bool scaled, char *buf, size_t buflen) (void)snprintf(buf+strlen(buf), buflen-strlen(buf), "\"reserved\":%u,\"speed\":%u,\"accuracy\":%s," "\"lon\":%d,\"lat\":%d,\"course\":%u," - "\"heading\":%d,\"second\":%u,\"regional\":%d," + "\"heading\":%u,\"second\":%u,\"regional\":%u," "\"shipname\":\"%s\",\"shiptype\":%u," "\"to_bow\":%u,\"to_stern\":%u,\"to_port\":%u," "\"starboard\":%u,\"epfd\":%u,\"raim\":%s," @@ -1063,7 +1056,7 @@ void aivdm_json_dump(struct ais_t *ais, bool scaled, char *buf, size_t buflen) "\"lat\":%.4f,\"accuracy\":%s,\"to_bow\":%u," "\"to_stern\":%u,\"to_port\":%u," "\"to_starboard\":%u,\"epfd\":\"%s\"," - "\"second\":%u,\"regional\":%d," + "\"second\":%u,\"regional\":%u," "\"off_position\":%s,\"raim\":%s," "\"virtual_aid\":%s}\r\n", NAVAIDTYPE_DISPLAY(ais->type21.type), @@ -1086,7 +1079,7 @@ void aivdm_json_dump(struct ais_t *ais, bool scaled, char *buf, size_t buflen) "\"type\":%u,\"name\":\"%s\",\"accuracy\":%s," "\"lon\":%d,\"lat\":%d,\"to_bow\":%u," "\"to_stern\":%u,\"to_port\":%u,\"to_starboard\":%u," - "\"epfd\":%u,\"second\":%u,\"regional\":%d," + "\"epfd\":%u,\"second\":%u,\"regional\":%u," "\"off_position\":%s,\"raim\":%s," "\"virtual_aid\":%s}\r\n", ais->type21.type, @@ -1151,7 +1144,7 @@ void aivdm_json_dump(struct ais_t *ais, bool scaled, char *buf, size_t buflen) break; case 24: /* Class B CS Static Data Report */ (void)snprintf(buf+strlen(buf), buflen-strlen(buf), - "\"partno\":%u,", ais->type24.part); + "\"part\":%u,", ais->type24.part); if (ais->type24.part == 0) { (void)snprintf(buf+strlen(buf), buflen-strlen(buf), "\"shipname\":\"%s\"}\r\n", diff --git a/gpsdecode.c b/gpsdecode.c index 923960f3..956175fa 100644 --- a/gpsdecode.c +++ b/gpsdecode.c @@ -112,12 +112,13 @@ static void aivdm_csv_dump(struct ais_t *ais, char *buf, size_t buflen) (ais->type6.bitcount+7)/8)); break; case 7: /* Binary Acknowledge */ + case 13: /* Safety Related Acknowledge */ (void)snprintf(buf+strlen(buf), buflen-strlen(buf), "%u,%u,%u,%u", - ais->type7.mmsi[0], - ais->type7.mmsi[1], - ais->type7.mmsi[2], - ais->type7.mmsi[3]); + ais->type7.mmsi1, + ais->type7.mmsi2, + ais->type7.mmsi3, + ais->type7.mmsi4); break; case 8: /* Binary Broadcast Message */ (void)snprintf(buf+strlen(buf), buflen-strlen(buf), @@ -155,14 +156,6 @@ static void aivdm_csv_dump(struct ais_t *ais, char *buf, size_t buflen) ais->type12.retransmit, ais->type12.text); break; - case 13: /* Safety Related Acknowledge */ - (void)snprintf(buf+strlen(buf), buflen-strlen(buf), - "%u,%u,%u,%u", - ais->type13.mmsi[0], - ais->type13.mmsi[1], - ais->type13.mmsi[2], - ais->type13.mmsi[3]); - break; case 14: /* Safety Related Broadcast Message */ (void)snprintf(buf+strlen(buf), buflen-strlen(buf), "%s", @@ -24,16 +24,16 @@ ais_specs = ( # fieldname type default ('status', 'uinteger', '0'), ('turn', 'integer', 'AIS_TURN_NOT_AVAILABLE'), - ('speed', 'uinteger', 'SPEED_NOT_AVAILABLE'), + ('speed', 'uinteger', 'AIS_SPEED_NOT_AVAILABLE'), ('accuracy', 'boolean', 'false'), ('lon', 'integer', 'AIS_LON_NOT_AVAILABLE'), ('lat', 'integer', 'AIS_LAT_NOT_AVAILABLE'), ('course', 'uinteger', 'AIS_COURSE_NOT_AVAILABLE'), - ('heading', 'integer', 'AIS_HEADING_NOT_AVAILABLE'), + ('heading', 'uinteger', 'AIS_HEADING_NOT_AVAILABLE'), ('second', 'uinteger', 'AIS_SEC_NOT_AVAILABLE'), - ('maneuver', 'integer', 'AIS_SEC_INOPERATIVE'), + ('maneuver', 'uinteger', 'AIS_SEC_INOPERATIVE'), ('raim', 'boolean', 'false'), - ('radio', 'integer', '0'), + ('radio', 'uinteger', '0'), ), }, # Message types 2 and 3 duplicate 1 @@ -49,7 +49,7 @@ ais_specs = ( ('lat', 'integer', "AIS_LAT_NOT_AVAILABLE"), ('epfd', 'uinteger', "0"), ('raim', 'boolean', "false"), - ('radio', 'integer', "0"), + ('radio', 'uinteger', "0"), ), "stringbuffered":("timestamp",), }, @@ -63,14 +63,14 @@ ais_specs = ( ('ais_version', 'uinteger', '0'), ('callsign', 'string', None), ('shipname', 'string', None), - ('shiptype', 'string', None), + ('shiptype', 'uinteger', '0'), ('to_bow', 'uinteger', '0'), ('to_stern', 'uinteger', '0'), ('to_port', 'uinteger', '0'), ('to_starboard', 'uinteger', '0'), - ('epfd', 'string', None), + ('epfd', 'uinteger', '0'), ('eta', 'string', None), - ('draught', 'real', '0.0'), + ('draught', 'uinteger', '0'), ('destination', 'string', None), ('dte', 'uinteger', '1'), ), @@ -84,7 +84,7 @@ ais_specs = ( # fieldname type default ('seqno', 'uinteger', '0'), ('dest_mmsi', 'uinteger', '0'), - ('retransmit', 'uinteger', '0'), + ('retransmit', 'boolean', 'false'), ('app_id', 'uinteger', '0'), ('data', 'string', None), ), @@ -122,14 +122,14 @@ ais_specs = ( ('alt', 'uinteger', 'AIS_ALT_NOT_AVAILABLE'), ('speed', 'uinteger', 'AIS_SPEED_NOT_AVAILABLE'), ('accuracy', 'boolean', 'false'), - ('lon', 'real', 'AIS_LON_NOT_AVAILABLE'), - ('lat', 'real', 'AIS_LAT_NOT_AVAILABLE'), - ('course', 'real', 'AIS_COURSE_NOT_AVAILABLE'), + ('lon', 'integer', 'AIS_LON_NOT_AVAILABLE'), + ('lat', 'integer', 'AIS_LAT_NOT_AVAILABLE'), + ('course', 'uinteger', 'AIS_COURSE_NOT_AVAILABLE'), ('second', 'uinteger', 'AIS_SEC_NOT_AVAILABLE'), - ('regional', 'integer', '0'), + ('regional', 'uinteger', '0'), ('dte', 'uinteger', '1'), ('raim', 'boolean', 'false'), - ('radio', 'integer', '0'), + ('radio', 'uinteger', '0'), ), }, { @@ -148,24 +148,13 @@ ais_specs = ( "structname": "ais->type12", "fieldmap":( # fieldname type default - ('seq', 'uinteger', '0'), - ('dst', 'uinteger', '0'), - ('rexmit', 'uinteger', '0'), + ('seqno', 'uinteger', '0'), + ('dest_mmsi', 'uinteger', '0'), + ('retransmit', 'boolean', '0'), ('text', 'string', None), ), }, - { - "initname" : "json_ais13", - "header": "\tAIS_HEADER,", - "structname": "ais->type13", - "fieldmap":( - # fieldname type default - ('mmsi1', 'uinteger', '0'), - ('mmsi2', 'uinteger', '0'), - ('mmsi3', 'uinteger', '0'), - ('mmsi4', 'uinteger', '0'), - ), - }, + # Message type 13 duplicates 7 { "initname" : "json_ais14", "header": "\tAIS_HEADER,", @@ -215,6 +204,7 @@ ais_specs = ( ('lat', 'integer', 'AIS_GNS_LAT_NOT_AVAILABLE'), ('data', 'string', None), ), + "stringbuffered":("data",), }, { "initname" : "json_ais18", @@ -228,16 +218,16 @@ ais_specs = ( ('lon', 'integer', 'AIS_LON_NOT_AVAILABLE'), ('lat', 'integer', 'AIS_LAT_NOT_AVAILABLE'), ('course', 'uinteger', 'AIS_COURSE_NOT_AVAILABLE'), - ('heading', 'integer', 'AIS_HEADING_NOT_AVAILABLE'), + ('heading', 'uinteger', 'AIS_HEADING_NOT_AVAILABLE'), ('second', 'uinteger', 'AIS_SEC_NOT_AVAILABLE'), - ('regional', 'integer', '0'), + ('regional', 'uinteger', '0'), ('cs', 'boolean', 'false'), ('display', 'boolean', 'false'), ('dsc', 'boolean', 'false'), ('band', 'boolean', 'false'), ('msg22', 'boolean', 'false'), ('raim', 'boolean', 'false'), - ('radio', 'integer', '0'), + ('radio', 'uinteger', '0'), ), }, { @@ -252,9 +242,9 @@ ais_specs = ( ('lon', 'integer', 'AIS_LON_NOT_AVAILABLE'), ('lat', 'integer', 'AIS_LAT_NOT_AVAILABLE'), ('course', 'uinteger', 'AIS_COURSE_NOT_AVAILABLE'), - ('heading', 'integer', 'AIS_HEADING_NOT_AVAILABLE'), + ('heading', 'uinteger', 'AIS_HEADING_NOT_AVAILABLE'), ('second', 'uinteger', 'AIS_SEC_NOT_AVAILABLE'), - ('regional', 'integer', '0'), + ('regional', 'uinteger', '0'), ('shipname', 'string', None), ('shiptype', 'uinteger', '0'), ('to_bow', 'uinteger', '0'), @@ -263,123 +253,7 @@ ais_specs = ( ('to_starboard', 'uinteger', '0'), ('epfd', 'uinteger', '0'), ('raim', 'boolean', 'false'), - ('dte', 'integer', '1'), - ('assigned', 'boolean', 'false'), - ), - }, - { - "initname" : "json_ais20", - "header": "\tAIS_HEADER,", - "structname": "ais->type20", - "fieldmap":( - # fieldname type default - ('offset1', 'uinteger', '0'), - ('number1', 'uinteger', '0'), - ('timeout1', 'uinteger', '0'), - ('increment1', 'uinteger', '0'), - ('offset2', 'uinteger', '0'), - ('number2', 'uinteger', '0'), - ('timeout2', 'uinteger', '0'), - ('increment2', 'uinteger', '0'), - ('offset3', 'uinteger', '0'), - ('number3', 'uinteger', '0'), - ('timeout3', 'uinteger', '0'), - ('increment3', 'uinteger', '0'), - ('offset4', 'uinteger', '0'), - ('number4', 'uinteger', '0'), - ('timeout4', 'uinteger', '0'), - ('increment4', 'uinteger', '0'), - ), - }, - { - "initname" : "json_ais15", - "header": "\tAIS_HEADER,", - "structname": "ais->type15", - "fieldmap":( - # fieldname type default - ('mmsi1', 'uinteger', '0'), - ('type1_1', 'uinteger', '0'), - ('offset1_1', 'uinteger', '0'), - ('type1_2', 'uinteger', '0'), - ('offset1_2', 'uinteger', '0'), - ('mmsi2', 'uinteger', '0'), - ('type2_1', 'uinteger', '0'), - ('offset2_1', 'uinteger', '0'), - ), - }, - { - "initname" : "json_ais16", - "header": "\tAIS_HEADER,", - "structname": "ais->type16", - "fieldmap":( - # fieldname type default - ('mmsi1', 'uinteger', '0'), - ('offset1', 'uinteger', '0'), - ('increment1', 'uinteger', '0'), - ('mmsi2', 'uinteger', '0'), - ('offset2', 'uinteger', '0'), - ('increment2', 'uinteger', '0'), - ), - }, - { - "initname" : "json_ais17", - "header": "\tAIS_HEADER,", - "structname": "ais->type17", - "fieldmap":( - # fieldname type default - ('lon', 'integer', 'AIS_GNS_LON_NOT_AVAILABLE'), - ('lat', 'integer', 'AIS_GNS_LAT_NOT_AVAILABLE'), - ('data', 'string', None), - ), - }, - { - "initname" : "json_ais18", - "header": "\tAIS_HEADER,", - "structname": "ais->type18", - "fieldmap":( - # fieldname type default - ('reserved', 'uinteger', '0'), - ('speed', 'uinteger', 'AIS_SPEED_NOT_AVAILABLE'), - ('accuracy', 'boolean', 'false'), - ('lon', 'integer', 'AIS_LON_NOT_AVAILABLE'), - ('lat', 'integer', 'AIS_LAT_NOT_AVAILABLE'), - ('course', 'uinteger', 'AIS_COURSE_NOT_AVAILABLE'), - ('heading', 'integer', 'AIS_HEADING_NOT_AVAILABLE'), - ('second', 'uinteger', 'AIS_SEC_NOT_AVAILABLE'), - ('regional', 'integer', '0'), - ('cs', 'boolean', 'false'), - ('display', 'boolean', 'false'), - ('dsc', 'boolean', 'false'), - ('band', 'boolean', 'false'), - ('msg22', 'boolean', 'false'), - ('raim', 'boolean', 'false'), - ('radio', 'integer', '0'), - ), - }, - { - "initname" : "json_ais19", - "header": "\tAIS_HEADER,", - "structname": "ais->type19", - "fieldmap":( - # fieldname type default - ('reserved', 'uinteger', '0'), - ('speed', 'uinteger', 'AIS_SPEED_NOT_AVAILABLE'), - ('accuracy', 'boolean', 'false'), - ('lon', 'integer', 'AIS_LON_NOT_AVAILABLE'), - ('lat', 'integer', 'AIS_LAT_NOT_AVAILABLE'), - ('course', 'uinteger', 'AIS_COURSE_NOT_AVAILABLE'), - ('heading', 'integer', 'AIS_HEADING_NOT_AVAILABLE'), - ('second', 'uinteger', 'AIS_SEC_NOT_AVAILABLE'), - ('regional', 'integer', '0'), - ('shipname', 'string', None), - ('shiptype', 'uinteger', '0'), - ('to_bow', 'uinteger', '0'), - ('stern', 'uinteger', '0'), - ('port', 'uinteger', '0'), - ('starboard', 'uinteger', '0'), - ('epfd', 'uinteger', '0'), - ('raim', 'boolean', 'false'), - ('dte', 'integer', '1'), + ('dte', 'uinteger', '1'), ('assigned', 'boolean', 'false'), ), }, @@ -424,7 +298,7 @@ ais_specs = ( ('to_starboard', 'uinteger', '0'), ('epfd', 'uinteger', '0'), ('second', 'uinteger', '0'), - ('regional', 'integer', '0'), + ('regional', 'uinteger', '0'), ('off_position', 'boolean', 'false'), ('raim', 'boolean', 'false'), ('virtual_aid', 'boolean', 'false'), @@ -457,7 +331,7 @@ ais_specs = ( "structname": "ais->type24", "fieldmap":( # fieldname type default - ('partno', 'uinteger', '0'), + ('part', 'uinteger', '0'), ('a.shipname', 'string', None), # Part A ('b.shiptype', 'uinteger', '0'), # Part B ('b.vendorid', 'string', None), # Part B @@ -505,7 +379,7 @@ def generate(spec): (attr, " "*(12-len(attr)), itype, " "*(10-len(itype)), itype, deref, target) leader = " " * 35 if itype == "string": - print leader + ".maxlen = sizeof(%s)}," % target + print leader + ".len = sizeof(%s)}," % target else: print leader + ".dflt.%s = %s}," % (itype, default) @@ -559,24 +433,38 @@ def string_to_specifier(strspec): if __name__ == '__main__': try: - (options, arguments) = getopt.getopt(sys.argv[1:], "g") + # The --ais and --target= options are (required) placeho;lders. + # In the future, this script will generate more different kinds + # of code. + (options, arguments) = getopt.getopt(sys.argv[1:], "g", ["ais", "target="]) except getopt.GetoptError, msg: print "jsongen.py: " + str(msg) raise SystemExit, 1 specify = False + spec = None + target = None for (switch, val) in options: - if (switch == '-g'): + if switch == '-g': specify = True + elif switch == '--ais': + spec = ais_specs + elif switch == '--target': + target = val + + if not specify and (not target or not spec): + print "jsongen.py: must specify type and target." + sys,exit(1) + if specify: string_to_specifier(stringspec) else: print """/* - * This is code generated by jsongen.py. Do not hand-hack it. + * This is code generated by jsongen.py. Do not hand-hack it! */ """ outboard = [] - for description in ais_specs: + for description in spec: generate(description) print "/* Generated code ends. */" |