Skip to content

Commit

Permalink
gpsd-report() -> gpsd_log()
Browse files Browse the repository at this point in the history
This change is done so we can add a "log" hook to the pps_thread_t
structure (this is not done yet) and harmonize with the name of the
outer logging function. If that name had been left as gpsd_report()
there would have been scope for bad confusion with the report_hook
member.

Also, remove two stray duplicative printf calls from the NMEA2000 driver
(drivers shouldn't have printfs!) and fix one typo.

This is a step towards factoring out ntplib. For that to happen, the
PPS thread code needs to be decoupled from the core session structure.

No logic changes. Object compatibility preserved. All regression tests pass.
  • Loading branch information
eric-s-raymond committed Mar 7, 2015
1 parent 9c49083 commit df34a3a
Show file tree
Hide file tree
Showing 42 changed files with 2,920 additions and 2,876 deletions.
2 changes: 1 addition & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ boolopts = (
("reconfigure", True, "allow gpsd to change device settings"),
("controlsend", True, "allow gpsctl/gpsmon to change device settings"),
("nofloats", False, "float ops are expensive, suppress error estimates"),
("squelch", False, "squelch gpsd_report/gpsd_hexdump to save cpu"),
("squelch", False, "squelch gpsd_log/gpsd_hexdump to save cpu"),
# Build control
("shared", True, "build shared libraries, not static"),
("implicit_link", imloads,"implicit linkage is supported in shared libs"),
Expand Down
23 changes: 0 additions & 23 deletions doc/explan_gpsd.c.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,6 @@
the process is in the background and return a value of
0.</para></entry>
</row>
<row>
<entry><function>void gpsd_report(int errlevel, const char *fmt, ... )</function></entry>
<entry><para>This code is used for error reporting, but is dependant
on SQUELCH_DISABLE so that embedded systems (for example) are not
burdened with unnecessary noise. The first thing to check is if the
error level offered is high enough to be of interest (controlled by
the debug level we are running at).</para><para>If we are
interested, the first step is to protect the code with a mutex if we
are using the 1PPS input.</para><para>Now we build a message buffer
which has a fixed header (<quote>gpsd: </quote>) and the incoming
data. The output buffer is prepared (load the start with a NULL) and
then the input buffer is scanned, byte-by-byte, up to its
terminating NULL. The scanned data is transferred on the fly to the
output buffer subject to the following tests:-</para><para>If the
character is printable, it passes through unchanged.</para><para>If
it is a space and either of the next two bytes is NULL it will also
pass through unchanged.</para><para>In any other case, it is copied
across as a hexadecimal string like
<quote>x09</quote>.</para><para>The completed output buffer is then
either sent to the system logger if we are in background mode
(daemon) or to the stderr file if we are in foreground
mode.</para></entry>
</row>
<row>
<entry><function>static void usage(void)</function></entry>
<entry><para>Simply print a big list of the invocation parameters to
Expand Down
11 changes: 6 additions & 5 deletions doc/explan_gpsd_report.c.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<sect1 id="gpsd_report.c"><title><filename>report.c</filename></title>
<sect1 id="gpsd_log.c"><title><filename>libgpsd_core.c</filename></title>
<informaltable frame='all' pgwide='1'>
<tgroup cols='2'>
<colspec colname='c1'></colspec>
Expand All @@ -13,15 +13,16 @@

<tfoot>
<row>
<entry spanname='s1' align='left'>Notes based on code as of Mon Apr 5 21:38:06 2010 -0400</entry>
<entry spanname='s1' align='left'>Notes based on code as of Sat Mar 7 10:11:55 EST 2015</entry>
</row>
</tfoot>

<tbody>
<row>
<entry><function>void gpsd_report(int errlevel UNUSED, const char *fmt, ... )</function></entry>
<entry><para>Provides the outputting of strings to stderr for anyone
who needs it. Used extensively by many functions to report errors or
<entry><function>void gpsd_log(struct gpsd_errout_t, int errlevel, const char *fmt, ... )</function></entry>
<entry><para>Provides the outputting of strings to stderr or through a
specified hook function in the errout structure for anyone
who needs it. Used extensively by many functions to log errors or
progress. Responds according to the <function>errlevel</function>
argument, which is filled by the DEBUG command line argument, so
that the verbosity of output is conditional on the user's wishes at
Expand Down
25 changes: 24 additions & 1 deletion doc/explan_libgpsd_core.c.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,34 @@

<tfoot>
<row>
<entry spanname='s1' align='left'>Notes based on code as of Mon Apr 5 21:38:06 2010 -0400.</entry>
<entry spanname='s1' align='left'>Notes based mostly on code as of Mon Apr 5 21:38:06 2010 -040.</entry>
</row>
</tfoot>

<tbody>
<row>
<entry><function>void gpsd_log(const struct errout_t, int errlevel, const char *fmt, ... )</function></entry>
<entry><para>This code is used for error reporting, but is dependant
on SQUELCH_DISABLE so that embedded systems (for example) are not
burdened with unnecessary noise. The first thing to check is if the
error level offered is high enough to be of interest (controlled by
the debug level we are running at).</para><para>If we are
interested, the first step is to protect the code with a mutex if we
are using the 1PPS input.</para><para>Now we build a message buffer
which has a fixed header (<quote>gpsd: </quote>) and the incoming
data. The output buffer is prepared (load the start with a NULL) and
then the input buffer is scanned, byte-by-byte, up to its
terminating NULL. The scanned data is transferred on the fly to the
output buffer subject to the following tests:-</para><para>If the
character is printable, it passes through unchanged.</para><para>If
it is a space and either of the next two bytes is NULL it will also
pass through unchanged.</para><para>In any other case, it is copied
across as a hexadecimal string like
<quote>x09</quote>.</para><para>The completed output buffer is then
either sent to the system logger if we are in background mode
(daemon) or to the stderr file if we are in foreground
mode.</para></entry>
</row>
<row>
<entry><function>int gpsd_switch_driver(struct gps_device_t *session, char* typename)</function></entry>
<entry><para>Test if the function is called with the same name as
Expand Down
4 changes: 2 additions & 2 deletions doc/internals.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<!ENTITY gps.h SYSTEM "explan_gps.h.xml">
<!ENTITY gpsd.c SYSTEM "explan_gpsd.c.xml">
<!ENTITY gpsd.h SYSTEM "explan_gpsd.h.xml">
<!ENTITY gpsd_report.c SYSTEM "explan_gpsd_report.c.xml">
<!ENTITY gpsd_log.c SYSTEM "explan_gpsd_log.c.xml">
<!ENTITY gpsdclient.c SYSTEM "explan_gpsdclient.c.xml">
<!ENTITY gpsutils.c SYSTEM "explan_gpsutils.c.xml">
<!ENTITY isgps.c SYSTEM "explan_isgps.c.xml">
Expand Down Expand Up @@ -93,7 +93,7 @@ is not yet documented here.</para>
&gps.h;
&gpsd.c;
&gpsd.h;
&gpsd_report.c;
&gpsd_log.c;
&gpsdclient.c;
&gpsutils.c;
&isgps.c;
Expand Down
74 changes: 37 additions & 37 deletions driver_ais.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,26 @@ bool ais_binary_decode(const struct gpsd_errout_t *errout,
ais->type = UBITS(0, 6);
ais->repeat = UBITS(6, 2);
ais->mmsi = UBITS(8, 30);
gpsd_report(errout, LOG_INF,
"AIVDM message type %d, MMSI %09d:\n",
ais->type, ais->mmsi);
gpsd_log(errout, LOG_INF,
"AIVDM message type %d, MMSI %09d:\n",
ais->type, ais->mmsi);

#define PERMISSIVE_LENGTH_CHECK(correct) \
if (bitlen < correct) { \
gpsd_report(errout, LOG_ERROR, \
"AIVDM message type %d size < %d bits (%zd).\n", \
ais->type, correct, bitlen); \
gpsd_log(errout, LOG_ERROR, \
"AIVDM message type %d size < %d bits (%zd).\n", \
ais->type, correct, bitlen); \
return false; \
} else if (bitlen > correct) { \
gpsd_report(errout, LOG_WARN, \
"AIVDM message type %d size > %d bits (%zd).\n", \
ais->type, correct, bitlen); \
gpsd_log(errout, LOG_WARN, \
"AIVDM message type %d size > %d bits (%zd).\n", \
ais->type, correct, bitlen); \
}
#define RANGE_CHECK(min, max) \
if (bitlen < min || bitlen > max) { \
gpsd_report(errout, LOG_ERROR, \
"AIVDM message type %d size is out of range (%zd).\n", \
ais->type, bitlen); \
gpsd_log(errout, LOG_ERROR, \
"AIVDM message type %d size is out of range (%zd).\n", \
ais->type, bitlen); \
return false; \
}

Expand Down Expand Up @@ -144,9 +144,9 @@ bool ais_binary_decode(const struct gpsd_errout_t *errout,
break;
case 5: /* Ship static and voyage related data */
if (bitlen != 424) {
gpsd_report(errout, LOG_WARN,
"AIVDM message type 5 size not 424 bits (%zd).\n",
bitlen);
gpsd_log(errout, LOG_WARN,
"AIVDM message type 5 size not 424 bits (%zd).\n",
bitlen);
/*
* For unknown reasons, a lot of transmitters in the wild ship
* with a length of 420 or 422. This is a recoverable error.
Expand Down Expand Up @@ -943,9 +943,9 @@ bool ais_binary_decode(const struct gpsd_errout_t *errout,
{
struct ais_type24a_t *saveptr = &type24_queue->ships[type24_queue->index];

gpsd_report(errout, LOG_PROG,
"AIVDM: 24A from %09u stashed.\n",
ais->mmsi);
gpsd_log(errout, LOG_PROG,
"AIVDM: 24A from %09u stashed.\n",
ais->mmsi);
saveptr->mmsi = ais->mmsi;
UCHARS(40, saveptr->shipname);
++type24_queue->index;
Expand Down Expand Up @@ -990,9 +990,9 @@ bool ais_binary_decode(const struct gpsd_errout_t *errout,
(void)strlcpy(ais->type24.shipname,
type24_queue->ships[i].shipname,
sizeof(ais->type24.shipname));
gpsd_report(errout, LOG_PROG,
"AIVDM 24B from %09u matches a 24A.\n",
ais->mmsi);
gpsd_log(errout, LOG_PROG,
"AIVDM 24B from %09u matches a 24A.\n",
ais->mmsi);
/* prevent false match if a 24B is repeated */
type24_queue->ships[i].mmsi = 0;
ais->type24.part = both;
Expand All @@ -1004,24 +1004,24 @@ bool ais_binary_decode(const struct gpsd_errout_t *errout,
ais->type24.part = part_b;
return true;
default:
gpsd_report(errout, LOG_WARN,
"AIVDM message type 24 of subtype unknown.\n");
gpsd_log(errout, 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(errout, LOG_WARN,
"AIVDM message type 25 size not between 40 to 168 bits (%zd).\n",
bitlen);
gpsd_log(errout, 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(errout, LOG_WARN,
"AIVDM message type 25 too short for mode.\n");
gpsd_log(errout, LOG_WARN,
"AIVDM message type 25 too short for mode.\n");
return false;
}
if (ais->type25.addressed)
Expand All @@ -1044,8 +1044,8 @@ bool ais_binary_decode(const struct gpsd_errout_t *errout,
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(errout, LOG_WARN,
"AIVDM message type 26 too short for mode.\n");
gpsd_log(errout, LOG_WARN,
"AIVDM message type 26 too short for mode.\n");
return false;
}
if (ais->type26.addressed)
Expand All @@ -1064,17 +1064,17 @@ bool ais_binary_decode(const struct gpsd_errout_t *errout,
break;
case 27: /* Long Range AIS Broadcast message */
if (bitlen != 96 && bitlen != 168) {
gpsd_report(errout, LOG_WARN,
"unexpected AIVDM message type 27 (%zd).\n",
bitlen);
gpsd_log(errout, LOG_WARN,
"unexpected AIVDM message type 27 (%zd).\n",
bitlen);
return false;
} if (bitlen == 168) {
/*
* This is an implementation error observed in the wild,
* sending a full 168-bit slot rather than just 96 bits.
*/
gpsd_report(errout, LOG_WARN,
"oversized 169=8-bit AIVDM message type 27.\n");
gpsd_log(errout, LOG_WARN,
"oversized 169=8-bit AIVDM message type 27.\n");
}
ais->type27.accuracy = (bool)UBITS(38, 1);
ais->type27.raim = UBITS(39, 1)!=0;
Expand All @@ -1086,8 +1086,8 @@ bool ais_binary_decode(const struct gpsd_errout_t *errout,
ais->type27.gnss = (bool)UBITS(94, 1);
break;
default:
gpsd_report(errout, LOG_ERROR,
"Unparsed AIVDM message type %d.\n",ais->type);
gpsd_log(errout, LOG_ERROR,
"Unparsed AIVDM message type %d.\n",ais->type);
return false;
}
/* *INDENT-ON* */
Expand Down
Loading

0 comments on commit df34a3a

Please sign in to comment.