summaryrefslogtreecommitdiff
path: root/ais_json.c
diff options
context:
space:
mode:
authorChristian Gagneraud <cgagneraud@techworks.ie>2012-06-04 01:14:27 +0100
committerChristian Gagneraud <chris@techworks.ie>2012-06-20 10:05:41 +0100
commit5214d309cf07b428ccfac647f7ac9ed8d597186f (patch)
tree672ecb9d61a1973252be347eb5b1bf13b7dfe7d1 /ais_json.c
parent9e6cdcb27d6af143721bb27bd886fc43d1214626 (diff)
downloadgpsd-5214d309cf07b428ccfac647f7ac9ed8d597186f.tar.gz
[AIS] Fix plenty of small bugs unveiled by aishub test campaign.
A test campaign was run with live data from aishub.net (ca. 25 millions sentence, 1.2 GB of logs), the goal was to check the decoding and the JSON parsing and dumping code. On all the AIS data, the following tests were done: - AIVDM decoding - JSON scaled dump - JSON validity check on scaled dump. - JSON unscaled dump - JSON validity check on unscaled dump - JSON unscaled idempotency check - JSON unscaled/scaled idempotency check The last check consisted of: - parsing the unscaled dump - dumping it back in scaled mode - compare it with the original scaled dump. This test campaign has unveiled plenty of small bugs all around the AIS code. This patch fixes all of them and adds new sentences in the regression tests.
Diffstat (limited to 'ais_json.c')
-rw-r--r--ais_json.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/ais_json.c b/ais_json.c
index f7a69665..75130280 100644
--- a/ais_json.c
+++ b/ais_json.c
@@ -97,8 +97,9 @@ int json_ais_read(const char *buf,
ais->type4.hour = AIS_HOUR_NOT_AVAILABLE;
ais->type4.minute = AIS_MINUTE_NOT_AVAILABLE;
ais->type4.second = AIS_SECOND_NOT_AVAILABLE;
+ // We use %u for the date to allow for dodgy years (>9999) to go through
// cppcheck-suppress uninitvar
- (void)sscanf(timestamp, "%4u-%02u-%02uT%02u:%02u:%02uZ",
+ (void)sscanf(timestamp, "%u-%02u-%02uT%02u:%02u:%02uZ",
&ais->type4.year,
&ais->type4.month,
&ais->type4.day,
@@ -157,14 +158,15 @@ int json_ais_read(const char *buf,
status = json_read_object(buf, json_ais6_fid16, endptr);
imo = true;
}
- else if (strstr(buf, "\"fid\":18,") != NULL || strstr(buf, "\"fid\":11,") != NULL) {
+ else if (strstr(buf, "\"fid\":18,") != NULL) {
status = json_read_object(buf, json_ais6_fid18, endptr);
if (status == 0) {
ais->type6.dac1fid18.day = AIS_DAY_NOT_AVAILABLE;
ais->type6.dac1fid18.hour = AIS_HOUR_NOT_AVAILABLE;
ais->type6.dac1fid18.minute = AIS_MINUTE_NOT_AVAILABLE;
// cppcheck-suppress uninitvar
- (void)sscanf(arrival, "%02uT%02u:%02uZ",
+ (void)sscanf(arrival, "%02u-%02uT%02u:%02uZ",
+ &ais->type6.dac1fid18.month,
&ais->type6.dac1fid18.day,
&ais->type6.dac1fid18.hour,
&ais->type6.dac1fid18.minute);
@@ -360,8 +362,14 @@ int json_ais_read(const char *buf,
status = json_read_object(buf, json_ais24, endptr);
} else if (strstr(buf, "\"type\":25,") != NULL) {
status = json_read_object(buf, json_ais25, endptr);
+ if (status == 0)
+ lenhex_unpack(data, &ais->type25.bitcount,
+ ais->type25.bitdata, sizeof(ais->type25.bitdata));
} else if (strstr(buf, "\"type\":26,") != NULL) {
status = json_read_object(buf, json_ais26, endptr);
+ if (status == 0)
+ lenhex_unpack(data, &ais->type26.bitcount,
+ ais->type26.bitdata, sizeof(ais->type26.bitdata));
} else if (strstr(buf, "\"type\":27,") != NULL) {
status = json_read_object(buf, json_ais27, endptr);
} else {