summaryrefslogtreecommitdiff
path: root/driver_ais.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2013-09-29 01:42:45 -0400
committerEric S. Raymond <esr@thyrsus.com>2013-09-29 01:46:53 -0400
commit4361ec2d89bdf451602d659ddfd0fb9a79c178a2 (patch)
treeaf067d1d7614a9e67f449eec933ba3347cde10b0 /driver_ais.c
parenta77b95b57475c2856707e91b197f8aaa8e5eb407 (diff)
downloadgpsd-4361ec2d89bdf451602d659ddfd0fb9a79c178a2.tar.gz
Change gpsd_report to no longer use a global. All regression tests pass.
This is a large, ugly change. But without it we can't troubleshoot the ICP/IP-source initialization bug properly - colliding definitions of gpsd_report() were interfering with error reporting early in gpsd runs. More cleanup work remains to be done, but at least this is working.
Diffstat (limited to 'driver_ais.c')
-rw-r--r--driver_ais.c100
1 files changed, 65 insertions, 35 deletions
diff --git a/driver_ais.c b/driver_ais.c
index d482aadc..b69a0592 100644
--- a/driver_ais.c
+++ b/driver_ais.c
@@ -59,9 +59,10 @@ static void from_sixbit(unsigned char *bitvec, uint start, int count, char *to)
}
/*@ +charint @*/
-bool ais_binary_decode(struct ais_t *ais,
- const unsigned char *bits, size_t bitlen,
- struct ais_type24_queue_t *type24_queue)
+bool ais_binary_decode(const int debug,
+ struct ais_t *ais,
+ const unsigned char *bits, size_t bitlen,
+ struct ais_type24_queue_t *type24_queue)
/* decode an AIS binary packet */
{
bool imo;
@@ -76,7 +77,8 @@ bool ais_binary_decode(struct ais_t *ais,
ais->type = UBITS(0, 6);
ais->repeat = UBITS(6, 2);
ais->mmsi = UBITS(8, 30);
- gpsd_report(LOG_INF, "AIVDM message type %d, MMSI %09d:\n",
+ gpsd_report(debug, LOG_INF,
+ "AIVDM message type %d, MMSI %09d:\n",
ais->type, ais->mmsi);
/*
* Something about the shape of this switch statement confuses
@@ -89,7 +91,8 @@ bool ais_binary_decode(struct ais_t *ais,
case 2:
case 3:
if (bitlen != 168) {
- gpsd_report(LOG_WARN, "AIVDM message type %d size not 168 bits (%zd).\n",
+ gpsd_report(debug, LOG_WARN,
+ "AIVDM message type %d size not 168 bits (%zd).\n",
ais->type,
bitlen);
return false;
@@ -111,7 +114,8 @@ bool ais_binary_decode(struct ais_t *ais,
case 4: /* Base Station Report */
case 11: /* UTC/Date Response */
if (bitlen != 168) {
- gpsd_report(LOG_WARN, "AIVDM message type %d size not 168 bits (%zd).\n",
+ gpsd_report(debug, LOG_WARN,
+ "AIVDM message type %d size not 168 bits (%zd).\n",
ais->type,
bitlen);
return false;
@@ -132,7 +136,8 @@ bool ais_binary_decode(struct ais_t *ais,
break;
case 5: /* Ship static and voyage related data */
if (bitlen != 424) {
- gpsd_report(LOG_WARN, "AIVDM message type 5 size not 424 bits (%zd).\n",
+ gpsd_report(debug, LOG_WARN,
+ "AIVDM message type 5 size not 424 bits (%zd).\n",
bitlen);
return false;
}
@@ -157,7 +162,8 @@ bool ais_binary_decode(struct ais_t *ais,
break;
case 6: /* Addressed Binary Message */
if (bitlen < 88 || bitlen > 1008) {
- gpsd_report(LOG_WARN, "AIVDM message type 6 size is out of range (%zd).\n",
+ gpsd_report(debug, LOG_WARN,
+ "AIVDM message type 6 size is out of range (%zd).\n",
bitlen);
return false;
}
@@ -366,7 +372,8 @@ bool ais_binary_decode(struct ais_t *ais,
{
unsigned int mmsi[4];
if (bitlen < 72 || bitlen > 158) {
- gpsd_report(LOG_WARN, "AIVDM message type %d size is out of range (%zd).\n",
+ gpsd_report(debug, LOG_WARN,
+ "AIVDM message type %d size is out of range (%zd).\n",
ais->type,
bitlen);
return false;
@@ -386,7 +393,8 @@ bool ais_binary_decode(struct ais_t *ais,
}
case 8: /* Binary Broadcast Message */
if (bitlen < 56 || bitlen > 1008) {
- gpsd_report(LOG_WARN, "AIVDM message type 8 size is out of range (%zd).\n",
+ gpsd_report(debug, LOG_WARN,
+ "AIVDM message type 8 size is out of range (%zd).\n",
bitlen);
return false;
}
@@ -589,7 +597,8 @@ bool ais_binary_decode(struct ais_t *ais,
break;
case 9: /* Standard SAR Aircraft Position Report */
if (bitlen != 168) {
- gpsd_report(LOG_WARN, "AIVDM message type 9 size not 168 bits (%zd).\n",
+ gpsd_report(debug, LOG_WARN,
+ "AIVDM message type 9 size not 168 bits (%zd).\n",
bitlen);
return false;
}
@@ -609,7 +618,8 @@ bool ais_binary_decode(struct ais_t *ais,
break;
case 10: /* UTC/Date inquiry */
if (bitlen != 72) {
- gpsd_report(LOG_WARN, "AIVDM message type 10 size not 72 bits (%zd).\n",
+ gpsd_report(debug, LOG_WARN,
+ "AIVDM message type 10 size not 72 bits (%zd).\n",
bitlen);
return false;
}
@@ -619,7 +629,8 @@ bool ais_binary_decode(struct ais_t *ais,
break;
case 12: /* Safety Related Message */
if (bitlen < 72 || bitlen > 1008) {
- gpsd_report(LOG_WARN, "AIVDM message type 12 size is out of range (%zd).\n",
+ gpsd_report(debug, LOG_WARN,
+ "AIVDM message type 12 size is out of range (%zd).\n",
bitlen);
return false;
}
@@ -631,7 +642,8 @@ bool ais_binary_decode(struct ais_t *ais,
break;
case 14: /* Safety Related Broadcast Message */
if (bitlen < 40 || bitlen > 1008) {
- gpsd_report(LOG_WARN, "AIVDM message type 14 size is out of range (%zd).\n",
+ gpsd_report(debug, LOG_WARN,
+ "AIVDM message type 14 size is out of range (%zd).\n",
bitlen);
return false;
}
@@ -640,7 +652,8 @@ bool ais_binary_decode(struct ais_t *ais,
break;
case 15: /* Interrogation */
if (bitlen < 88 || bitlen > 168) {
- gpsd_report(LOG_WARN, "AIVDM message type 15 size is out of range (%zd).\n",
+ gpsd_report(debug, LOG_WARN,
+ "AIVDM message type 15 size is out of range (%zd).\n",
bitlen);
return false;
}
@@ -665,7 +678,8 @@ bool ais_binary_decode(struct ais_t *ais,
break;
case 16: /* Assigned Mode Command */
if (bitlen != 96 && bitlen != 144) {
- gpsd_report(LOG_WARN, "AIVDM message type 16 size is out of range (%zd).\n",
+ gpsd_report(debug, LOG_WARN,
+ "AIVDM message type 16 size is out of range (%zd).\n",
bitlen);
return false;
}
@@ -682,7 +696,8 @@ bool ais_binary_decode(struct ais_t *ais,
break;
case 17: /* GNSS Broadcast Binary Message */
if (bitlen < 80 || bitlen > 816) {
- gpsd_report(LOG_WARN, "AIVDM message type 17 size is out of range (%zd).\n",
+ gpsd_report(debug, LOG_WARN,
+ "AIVDM message type 17 size is out of range (%zd).\n",
bitlen);
return false;
}
@@ -697,7 +712,8 @@ bool ais_binary_decode(struct ais_t *ais,
break;
case 18: /* Standard Class B CS Position Report */
if (bitlen != 168) {
- gpsd_report(LOG_WARN, "AIVDM message type 18 size not 168 bits (%zd).\n",
+ gpsd_report(debug, LOG_WARN,
+ "AIVDM message type 18 size not 168 bits (%zd).\n",
bitlen);
return false;
}
@@ -721,7 +737,8 @@ bool ais_binary_decode(struct ais_t *ais,
break;
case 19: /* Extended Class B CS Position Report */
if (bitlen != 312) {
- gpsd_report(LOG_WARN, "AIVDM message type 19 size not 312 bits (%zd).\n",
+ gpsd_report(debug, LOG_WARN,
+ "AIVDM message type 19 size not 312 bits (%zd).\n",
bitlen);
return false;
}
@@ -748,7 +765,8 @@ bool ais_binary_decode(struct ais_t *ais,
break;
case 20: /* Data Link Management Message */
if (bitlen < 72 || bitlen > 160) {
- gpsd_report(LOG_WARN, "AIVDM message type 20 size is out of range (%zd).\n",
+ gpsd_report(debug, LOG_WARN,
+ "AIVDM message type 20 size is out of range (%zd).\n",
bitlen);
return false;
}
@@ -772,7 +790,8 @@ bool ais_binary_decode(struct ais_t *ais,
break;
case 21: /* Aid-to-Navigation Report */
if (bitlen < 272 || bitlen > 360) {
- gpsd_report(LOG_WARN, "AIVDM message type 21 size is out of range (%zd).\n",
+ gpsd_report(debug, LOG_WARN,
+ "AIVDM message type 21 size is out of range (%zd).\n",
bitlen);
return false;
}
@@ -799,7 +818,8 @@ bool ais_binary_decode(struct ais_t *ais,
break;
case 22: /* Channel Management */
if (bitlen != 168) {
- gpsd_report(LOG_WARN, "AIVDM message type 22 size not 168 bits (%zd).\n",
+ gpsd_report(debug, LOG_WARN,
+ "AIVDM message type 22 size not 168 bits (%zd).\n",
bitlen);
return false;
}
@@ -823,7 +843,8 @@ bool ais_binary_decode(struct ais_t *ais,
break;
case 23: /* Group Assignment Command */
if (bitlen != 160) {
- gpsd_report(LOG_WARN, "AIVDM message type 23 size not 160 bits (%zd).\n",
+ gpsd_report(debug, LOG_WARN,
+ "AIVDM message type 23 size not 160 bits (%zd).\n",
bitlen);
return false;
}
@@ -841,7 +862,8 @@ bool ais_binary_decode(struct ais_t *ais,
switch (UBITS(38, 2)) {
case 0:
if (bitlen != 160) {
- gpsd_report(LOG_WARN, "AIVDM message type 24A size not 160 bits (%zd).\n",
+ gpsd_report(debug, LOG_WARN,
+ "AIVDM message type 24A size not 160 bits (%zd).\n",
bitlen);
return false;
}
@@ -851,7 +873,7 @@ bool ais_binary_decode(struct ais_t *ais,
{
struct ais_type24a_t *saveptr = &type24_queue->ships[type24_queue->index];
- gpsd_report(LOG_PROG,
+ gpsd_report(debug, LOG_PROG,
"AIVDM: 24A from %09u stashed.\n",
ais->mmsi);
saveptr->mmsi = ais->mmsi;
@@ -870,7 +892,8 @@ bool ais_binary_decode(struct ais_t *ais,
}
case 1:
if (bitlen != 168) {
- gpsd_report(LOG_WARN, "AIVDM message type 24B size not 168 bits (%zd).\n",
+ gpsd_report(debug, LOG_WARN,
+ "AIVDM message type 24B size not 168 bits (%zd).\n",
bitlen);
return false;
}
@@ -907,7 +930,7 @@ bool ais_binary_decode(struct ais_t *ais,
(void)strlcpy(ais->type24.shipname,
type24_queue->ships[i].shipname,
sizeof(type24_queue->ships[i].shipname));
- gpsd_report(LOG_PROG,
+ gpsd_report(debug, LOG_PROG,
"AIVDM 24B from %09u matches a 24A.\n",
ais->mmsi);
/* prevent false match if a 24B is repeated */
@@ -915,7 +938,7 @@ bool ais_binary_decode(struct ais_t *ais,
return true;
}
}
- gpsd_report(LOG_WARN,
+ gpsd_report(debug, LOG_WARN,
"AIVDM 24B from %09u can't be matched to a 24A.\n",
ais->mmsi);
ais->type24.part = both;
@@ -927,21 +950,24 @@ bool ais_binary_decode(struct ais_t *ais,
return true;
}
default:
- gpsd_report(LOG_WARN, "AIVDM message type 24 of subtype unknown.\n");
+ gpsd_report(debug, LOG_WARN,
+ "AIVDM message type 24 of subtype unknown.\n");
return false;
}
// break;
case 25: /* Binary Message, Single Slot */
/* this check and the following one reject line noise */
if (bitlen < 40 || bitlen > 168) {
- gpsd_report(LOG_WARN, "AIVDM message type 25 size not between 40 to 168 bits (%zd).\n",
+ gpsd_report(debug, LOG_WARN,
+ "AIVDM message type 25 size not between 40 to 168 bits (%zd).\n",
bitlen);
return false;
}
ais->type25.addressed = (bool)UBITS(38, 1);
ais->type25.structured = (bool)UBITS(39, 1);
if (bitlen < (unsigned)(40 + (16*ais->type25.structured) + (30*ais->type25.addressed))) {
- gpsd_report(LOG_WARN, "AIVDM message type 25 too short for mode.\n");
+ gpsd_report(debug, LOG_WARN,
+ "AIVDM message type 25 too short for mode.\n");
return false;
}
if (ais->type25.addressed)
@@ -964,14 +990,16 @@ bool ais_binary_decode(struct ais_t *ais,
break;
case 26: /* Binary Message, Multiple Slot */
if (bitlen < 60 || bitlen > 1004) {
- gpsd_report(LOG_WARN, "AIVDM message type 26 size is out of range (%zd).\n",
+ gpsd_report(debug, LOG_WARN,
+ "AIVDM message type 26 size is out of range (%zd).\n",
bitlen);
return false;
}
ais->type26.addressed = (bool)UBITS(38, 1);
ais->type26.structured = (bool)UBITS(39, 1);
if ((signed)bitlen < 40 + 16*ais->type26.structured + 30*ais->type26.addressed + 20) {
- gpsd_report(LOG_WARN, "AIVDM message type 26 too short for mode.\n");
+ gpsd_report(debug, LOG_WARN,
+ "AIVDM message type 26 too short for mode.\n");
return false;
}
if (ais->type26.addressed)
@@ -985,7 +1013,8 @@ bool ais_binary_decode(struct ais_t *ais,
break;
case 27: /* Long Range AIS Broadcast message */
if (bitlen != 96) {
- gpsd_report(LOG_WARN, "AIVDM message type 27 size not 96 bits (%zd).\n",
+ gpsd_report(debug, LOG_WARN,
+ "AIVDM message type 27 size not 96 bits (%zd).\n",
bitlen);
return false;
}
@@ -999,7 +1028,8 @@ bool ais_binary_decode(struct ais_t *ais,
ais->type27.gnss = (bool)UBITS(94, 1);
break;
default:
- gpsd_report(LOG_ERROR, "Unparsed AIVDM message type %d.\n",ais->type);
+ gpsd_report(debug, LOG_ERROR,
+ "Unparsed AIVDM message type %d.\n",ais->type);
return false;
}
/* *INDENT-ON* */