diff options
-rw-r--r-- | driver_aivdm.c | 13 | ||||
-rw-r--r-- | drivers.c | 2 | ||||
-rw-r--r-- | gpsd.h-tail | 8 | ||||
-rw-r--r-- | gpsdecode.c | 2 |
4 files changed, 20 insertions, 5 deletions
diff --git a/driver_aivdm.c b/driver_aivdm.c index e2de18fe..5937001b 100644 --- a/driver_aivdm.c +++ b/driver_aivdm.c @@ -62,7 +62,8 @@ static void from_sixbit(char *bitvec, uint start, int count, char *to) /*@ +charint @*/ bool aivdm_decode(const char *buf, size_t buflen, - struct aivdm_context_t *ais_context, struct ais_t *ais) + struct aivdm_context_t ais_contexts[AIVDM_CHANNELS], + struct ais_t *ais) { #ifdef __UNUSED_DEBUG__ char *sixbits[64] = { @@ -86,6 +87,7 @@ bool aivdm_decode(const char *buf, size_t buflen, unsigned char fieldcopy[NMEA_MAX+1]; unsigned char *data, *cp = fieldcopy; unsigned char ch, pad; + struct aivdm_context_t *ais_context; int i; if (buflen == 0) @@ -103,6 +105,15 @@ bool aivdm_decode(const char *buf, size_t buflen, *cp = '\0'; field[nfields++] = cp + 1; } + + switch (field[4][0]) { + case 'A': ais_context = &ais_contexts[0]; break; + case 'B': ais_context = &ais_contexts[1]; break; + default: + gpsd_report(LOG_ERROR, "invalid AIS channel %c\n", field[5][0]); + return false; + } + ais_context->await = atoi((char *)field[1]); ais_context->part = atoi((char *)field[2]); data = field[5]; @@ -1058,7 +1058,7 @@ static gps_mask_t aivdm_analyze(struct gps_device_t *session) if (session->packet.type == AIVDM_PACKET) { if (aivdm_decode ((char *)session->packet.outbuffer, session->packet.outbuflen, - &session->aivdm, &session->gpsdata.ais)) { + session->aivdm, &session->gpsdata.ais)) { return ONLINE_IS | AIS_IS; } else return ONLINE_IS; diff --git a/gpsd.h-tail b/gpsd.h-tail index 9702788c..c8904bb6 100644 --- a/gpsd.h-tail +++ b/gpsd.h-tail @@ -149,6 +149,8 @@ extern size_t oncore_payload_cksum_length(unsigned char id1,unsigned char id2); #define NTPSHMSEGS 4 /* number of NTP SHM segments */ +#define AIVDM_CHANNELS 2 /* A, B */ + struct gps_context_t { int valid; /* member validity flags */ bool readonly; /* if true, never write to device */ @@ -454,7 +456,7 @@ struct gps_device_t { * systems may come over the same wire with GPS NMEA sentences. */ #ifdef AIVDM_ENABLE - struct aivdm_context_t aivdm; + struct aivdm_context_t aivdm[AIVDM_CHANNELS]; #endif /* AIVDM_ENABLE */ #ifdef TIMING_ENABLE @@ -584,7 +586,9 @@ extern bool ubx_write(struct gps_device_t *, unsigned int, unsigned int, /*@null@*/unsigned char *, unsigned short); #endif /* UBX_ENABLE */ #ifdef AIVDM_ENABLE -extern bool aivdm_decode(const char *, size_t, struct aivdm_context_t *, struct ais_t *); +extern bool aivdm_decode(const char *, size_t, + struct aivdm_context_t [], + struct ais_t *); extern void aivdm_json_dump(const struct ais_t *, bool, /*@out@*/char *, size_t); #endif /* AIVDM_ENABLE */ #ifdef MTK3301_ENABLE diff --git a/gpsdecode.c b/gpsdecode.c index f952ffc7..10b389e8 100644 --- a/gpsdecode.c +++ b/gpsdecode.c @@ -365,7 +365,7 @@ static void decode(FILE * fpin, FILE * fpout) struct rtcm2_t rtcm2; struct rtcm3_t rtcm3; struct ais_t ais; - struct aivdm_context_t aivdm; + struct aivdm_context_t aivdm[AIVDM_CHANNELS]; char buf[BUFSIZ]; memset(&aivdm, '\0', sizeof(aivdm)); |