gpsd-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gpsd-dev] Bug in JSON encoding AIVDM type 9 messages


From: Stefan Roels
Subject: [gpsd-dev] Bug in JSON encoding AIVDM type 9 messages
Date: Mon, 05 Oct 2015 22:12:06 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0

Dear all,

While working on my AIS decoder, I ran into some other bugs in the decoding and the JSON output.

- Type 8, DAC = 1 FID = 11: airtemp, dewpoint and watertemp calculations go wrong due to unsigned ints. - Type 8, DAC = 1 FID = 16: This should only be decoded as "Persons on board" if the message length is either 72 or 136 bits long (if even then). - Type 8, DAC = 1 FID = 16: If decoded, the json output should use the ais->type8.dac1fid16.persons field and not the type6 field - Type 9: the ais->type9.speed field should be used instead of the type1 field

I have prepared a patch for these problems. I have also corrected some test outputs that are related to the spacing patch I send in earlier. Please do look at the test data, as I get some problems when running scons check, but I cannot find where I missed something.

Regards,
Stefan Roels



diff --git a/driver_ais.c b/driver_ais.c
index 1942ef7..abed4ca 100644
--- a/driver_ais.c
+++ b/driver_ais.c
@@ -527,11 +527,14 @@ bool ais_binary_decode(const struct gpsd_errout_t *errout,
                ais->type8.structured = true;
                break;
            case 16:        /* Number of Persons On Board */
-               if (ais->type8.bitcount == 136)
+               if (ais->type8.bitcount == 136) {
                    ais->type8.dac1fid16.persons = UBITS(88, 13);/* 289 */
-               else
+                       ais->type8.structured = true;
+               }
+               else if (ais->type8.bitcount == 72) {
                    ais->type8.dac1fid16.persons = UBITS(55, 13);/* 236 */
-               ais->type8.structured = true;
+                       ais->type8.structured = true;
+               }
                break;
            case 17:        /* IMO289 - VTS-generated/synthetic targets */
 #define ARRAY_BASE 56
diff --git a/gps.h b/gps.h
index 5602b0d..4954b8f 100644
--- a/gps.h
+++ b/gps.h
@@ -1314,13 +1314,13 @@ struct ais_t
 #define DAC1FID11_WDIR_NOT_AVAILABLE           511
unsigned int airtemp; /* temperature, units 0.1C */
 #define DAC1FID11_AIRTEMP_NOT_AVAILABLE                2047
-#define DAC1FID11_AIRTEMP_OFFSET               600
+#define DAC1FID11_AIRTEMP_OFFSET               600.0
 #define DAC1FID11_AIRTEMP_DIV                  10.0
                    unsigned int humidity;      /* relative humidity, % */
 #define DAC1FID11_HUMIDITY_NOT_AVAILABLE       127
                    unsigned int dewpoint;      /* dew point, units 0.1C */
 #define DAC1FID11_DEWPOINT_NOT_AVAILABLE       1023
-#define DAC1FID11_DEWPOINT_OFFSET              200
+#define DAC1FID11_DEWPOINT_OFFSET              200.0
 #define DAC1FID11_DEWPOINT_DIV         10.0
                    unsigned int pressure;      /* air pressure, hpa */
 #define DAC1FID11_PRESSURE_NOT_AVAILABLE       511
@@ -1362,7 +1362,7 @@ struct ais_t
 #define DAC1FID11_SEASTATE_NOT_AVAILABLE       15
                    unsigned int watertemp;     /* units 0.1deg Celsius */
 #define DAC1FID11_WATERTEMP_NOT_AVAILABLE      1023
-#define DAC1FID11_WATERTEMP_OFFSET             100
+#define DAC1FID11_WATERTEMP_OFFSET             100.0
 #define DAC1FID11_WATERTEMP_DIV                10.0
                    unsigned int preciptype;    /* 0-7, enumerated */
 #define DAC1FID11_PRECIPTYPE_NOT_AVAILABLE     7
diff --git a/gpsd_json.c b/gpsd_json.c
index 6641846..839727f 100644
--- a/gpsd_json.c
+++ b/gpsd_json.c
@@ -2296,7 +2296,7 @@ void json_aivdm_dump(const struct ais_t *ais,
                break;
            case 16:    /* IMO289 - Number of persons on board */
                str_appendf(buf, buflen,
- "\"persons\":%u}\r\n", ais->type6.dac1fid16.persons); + "\"persons\":%u}\r\n", ais->type8.dac1fid16.persons);
                break;
            case 17:        /* IMO289 - VTS-generated/synthetic targets */
                (void)strlcat(buf, "\"targets\":[", buflen);
@@ -2804,7 +2804,7 @@ void json_aivdm_dump(const struct ais_t *ais,
(void)strlcpy(speedlegend, "\"fast\"", sizeof(speedlegend));
            else
                (void)snprintf(speedlegend, sizeof(speedlegend),
-                              "%u", ais->type1.speed);
+                              "%u", ais->type9.speed);

            str_appendf(buf, buflen,
"\"alt\":%s,\"speed\":%s,\"accuracy\":%s,"
diff --git a/test/sample.aivdm b/test/sample.aivdm
index cc413c3..8321f73 100644
--- a/test/sample.aivdm
+++ b/test/sample.aivdm
@@ -483,6 +483,25 @@
 #       RAIM flag                : 0
 #       Radio status             : 24597
 #
+# Type 9:
+# From AISHub
+!AIVDM,1,1,,B,91b55wi;address@hidden,0*30
+#       Message Type             : 9
+#       Repeat Indicator         : 0
+#       MMSI                     : 111232511
+#       Altitude                 : 303
+#       SOG                      : 42
+#       Position Accuracy        : 0
+#       Longitude                : 0xFC683F6 (-6.27884)
+#       Latitude                 : 0x2145300 ( 58.144 )
+#       Course Over Ground       : 0x0609 (154.5)
+#       Time Stamp               : 15
+#       Regional reserved        : 0
+#       DTE                      : 1
+#       Assigned                 : 0
+#       RAIM flag                : 0
+#       Radio status             : 33392
+#
 # Type 10:
# From Kurt Schwehr. Two destination MMSIs. Checked with the noaadata tools.
 !AIVDM,1,1,,B,:5MlU41GMK6@,0*6C
diff --git a/test/sample.aivdm.js.chk b/test/sample.aivdm.js.chk
index ccfa428..8671140 100644
--- a/test/sample.aivdm.js.chk
+++ b/test/sample.aivdm.js.chk
@@ -21,10 +21,11 @@
 {"class":"AIS","device":"stdin","type":8,"repeat":0,"mmsi":244650946,"scaled":true,"dac":200,"fid":10,"vin":"02103547","length":390,"beam":50,"shiptype":8010,"shiptype_text":"Motor 
freighter","hazard":0,"hazard_text":"0 blue cones/lights","draught":204,"loaded":1,"loaded_text":"Unloaded","speed_q":false,"course_q":false,"heading_q":false}
 
{"class":"AIS","device":"stdin","type":8,"repeat":0,"mmsi":244650946,"scaled":true,"dac":200,"fid":10,"data":"368:c32c70cf5d370c3064fa50198800b4987e9555557e083a544f082003b809ae511bfc75f0a7ff960808ccb6be7ed5"}
 
{"class":"AIS","device":"stdin","type":9,"repeat":0,"mmsi":111265591,"scaled":true,"alt":15,"speed":0,"accuracy":false,"lon":11.8816,"lat":57.7785,"course":0.0,"second":28,"regional":0,"dte":0,"raim":false,"radio":49194}
+{"class":"AIS","device":"stdin","type":9,"repeat":0,"mmsi":111232511,"scaled":true,"alt":303,"speed":42,"accuracy":false,"lon":-6.2788,"lat":58.1440,"course":154.5,"second":15,"regional":0,"dte":1,"raim":false,"radio":33392}^M
 
{"class":"AIS","device":"stdin","type":10,"repeat":0,"mmsi":366814480,"scaled":true,"dest_mmsi":366832740}
 
{"class":"AIS","device":"stdin","type":10,"repeat":0,"mmsi":440882000,"scaled":true,"dest_mmsi":366972000}
 
{"class":"AIS","device":"stdin","type":11,"repeat":0,"mmsi":304137000,"scaled":true,"timestamp":"2009-05-22T02:22:40Z","accuracy":true,"lon":-94.4077,"lat":28.4091,"epfd":1,"epfd_text":"GPS","raim":false,"radio":0}
-{"class":"AIS","device":"stdin","type":12,"repeat":0,"mmsi":2275200,"scaled":true,"seqno":0,"dest_mmsi":215724000,"retransmit":false,"text":"PLEASE REPORT TO JOBOURG TRAFFIC CHANNEL 13 "} +{"class":"AIS","device":"stdin","type":12,"repeat":0,"mmsi":2275200,"scaled":true,"seqno":0,"dest_mmsi":215724000,"retransmit":false,"text":"PLEASE REPORT TO JOBOURG TRAFFIC CHANNEL 13"}^M
 
{"class":"AIS","device":"stdin","type":12,"repeat":0,"mmsi":351853000,"scaled":true,"seqno":0,"dest_mmsi":316123456,"retransmit":false,"text":"GOOD"}
 
{"class":"AIS","device":"stdin","type":12,"repeat":0,"mmsi":351853000,"scaled":true,"seqno":1,"dest_mmsi":351809000,"retransmit":false,"text":"THANX"}
 
{"class":"AIS","device":"stdin","type":12,"repeat":0,"mmsi":271002099,"scaled":true,"seqno":0,"dest_mmsi":271002111,"retransmit":true,"text":"MSG
 FROM 271002099"}
diff --git a/test/sample.aivdm.ju.chk b/test/sample.aivdm.ju.chk
index a6de2b3..00e2dce 100644
--- a/test/sample.aivdm.ju.chk
+++ b/test/sample.aivdm.ju.chk
@@ -24,7 +24,7 @@
 
{"class":"AIS","device":"stdin","type":10,"repeat":0,"mmsi":366814480,"scaled":false,"dest_mmsi":366832740}
 
{"class":"AIS","device":"stdin","type":10,"repeat":0,"mmsi":440882000,"scaled":false,"dest_mmsi":366972000}
 
{"class":"AIS","device":"stdin","type":11,"repeat":0,"mmsi":304137000,"scaled":false,"timestamp":"2009-05-22T02:22:40Z","accuracy":true,"lon":-56644610,"lat":17045470,"epfd":1,"epfd_text":"GPS","raim":false,"radio":0}
-{"class":"AIS","device":"stdin","type":12,"repeat":0,"mmsi":2275200,"scaled":false,"seqno":0,"dest_mmsi":215724000,"retransmit":false,"text":"PLEASE REPORT TO JOBOURG TRAFFIC CHANNEL 13 "} +{"class":"AIS","device":"stdin","type":12,"repeat":0,"mmsi":2275200,"scaled":false,"seqno":0,"dest_mmsi":215724000,"retransmit":false,"text":"PLEASE REPORT TO JOBOURG TRAFFIC CHANNEL 13"}^M
 
{"class":"AIS","device":"stdin","type":12,"repeat":0,"mmsi":351853000,"scaled":false,"seqno":0,"dest_mmsi":316123456,"retransmit":false,"text":"GOOD"}
 
{"class":"AIS","device":"stdin","type":12,"repeat":0,"mmsi":351853000,"scaled":false,"seqno":1,"dest_mmsi":351809000,"retransmit":false,"text":"THANX"}
 
{"class":"AIS","device":"stdin","type":12,"repeat":0,"mmsi":271002099,"scaled":false,"seqno":0,"dest_mmsi":271002111,"retransmit":true,"text":"MSG
 FROM 271002099"}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]