summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2007-03-21 21:47:25 +0000
committerEric S. Raymond <esr@thyrsus.com>2007-03-21 21:47:25 +0000
commitbe0c304dc40e754c81fff15ef635120f29d0aeec (patch)
treecd431d2fa29811a54fd433f6d182fc098445732e /doc
parentec2599f2ee5a34cc007fc67208f74a242a1c95e3 (diff)
downloadgpsd-be0c304dc40e754c81fff15ef635120f29d0aeec.tar.gz
First version of internals documentation.
Diffstat (limited to 'doc')
-rw-r--r--doc/Makefile32
-rw-r--r--doc/README1
-rw-r--r--doc/explan_bits.h.xml22
-rw-r--r--doc/explan_dgnss.c.xml49
-rw-r--r--doc/explan_dgpsip.c.xml41
-rw-r--r--doc/explan_driver_proto.c.xml22
-rw-r--r--doc/explan_drivers.c.xml53
-rw-r--r--doc/explan_geoid.c.xml45
-rw-r--r--doc/explan_gps.h.xml37
-rw-r--r--doc/explan_gpsd.c.xml117
-rw-r--r--doc/explan_gpsd.h.xml41
-rw-r--r--doc/explan_gpsd_dbus.c.xml33
-rw-r--r--doc/explan_gpsutils.c.xml81
-rw-r--r--doc/explan_isgps.c.xml49
-rw-r--r--doc/explan_libgps.c.xml81
-rw-r--r--doc/explan_libgpsd_core.c.xml93
-rw-r--r--doc/explan_libgpsmm.cpp.xml22
-rw-r--r--doc/explan_libgpsmm.h.xml22
-rw-r--r--doc/explan_netlib.c.xml29
-rw-r--r--doc/explan_nmea_parse.c.xml85
-rw-r--r--doc/explan_ntpshm.c.xml49
-rw-r--r--doc/explan_ntrip.c.xml57
-rw-r--r--doc/explan_packet.c.xml57
-rw-r--r--doc/explan_packet_names.h.xml22
-rw-r--r--doc/explan_packet_states.h.xml19
-rw-r--r--doc/explan_report.c.xml29
-rw-r--r--doc/explan_rtcm.c.xml57
-rw-r--r--doc/explan_serial.c.xml66
-rw-r--r--doc/explan_subframe.c.xml29
-rw-r--r--doc/explan_timebase.h.xml37
-rw-r--r--doc/explan_wrapup.xml6
-rw-r--r--doc/explanation.xml87
32 files changed, 1470 insertions, 0 deletions
diff --git a/doc/Makefile b/doc/Makefile
new file mode 100644
index 00000000..1be7b834
--- /dev/null
+++ b/doc/Makefile
@@ -0,0 +1,32 @@
+XML_SOURCES = explanation.xml \
+ explan_bits.h.xml \
+ explan_dgnss.c.xml \
+ explan_dgpsip.c.xml \
+ explan_drivers.c.xml \
+ explan_geoid.c.xml \
+ explan_gpsd.c.xml \
+ explan_gpsd_dbus.c.xml \
+ explan_gpsd.h.xml \
+ explan_gps.h.xml \
+ explan_gpsutils.c.xml \
+ explan_isgps.c.xml \
+ explan_libgps.c.xml \
+ explan_libgpsd_core.c.xml \
+ explan_libgpsmm.cpp.xml \
+ explan_libgpsmm.h.xml \
+ explan_netlib.c.xml \
+ explan_nmea_parse.c.xml \
+ explan_ntpshm.c.xml \
+ explan_ntrip.c.xml \
+ explan_packet.c.xml \
+ explan_packet_names.h.xml \
+ explan_packet_states.h.xml \
+ explan_report.c.xml \
+ explan_rtcm.c.xml \
+ explan_serial.c.xml \
+ explan_subframe.c.xml \
+ explan_timebase.h.xml \
+ explan_wrapup.xml
+
+explanation.html: $(SOURCES)
+ xmlto xhtml-nochunks explanation.xml
diff --git a/doc/README b/doc/README
new file mode 100644
index 00000000..122d3b59
--- /dev/null
+++ b/doc/README
@@ -0,0 +1 @@
+This is internals documentation written by Mick Durkin.
diff --git a/doc/explan_bits.h.xml b/doc/explan_bits.h.xml
new file mode 100644
index 00000000..1cdd50cb
--- /dev/null
+++ b/doc/explan_bits.h.xml
@@ -0,0 +1,22 @@
+<sect1 id="bits.h"><title><filename>bits.h</filename></title>
+<informaltable frame='all' pgwide='1'>
+<tgroup cols='1'>
+<colspec colname='c1'></colspec>
+<colspec colname='c2'></colspec>
+<spanspec spanname='s1' namest='c1' nameend='c2'></spanspec>
+
+<tbody>
+<row>
+ <entry><para>This file only contains macros that convert data variables from the native format of the device output (MSB-first or LSB-first) into a standard form for <application>gpsd</application> use. This makes data parsing consistent regardless of the underlying format. If the device driver file makes no deliberate selection, the default is to assume the device emits data in big-endian (network byte) order.</para></entry>
+</row>
+</tbody>
+
+<tfoot>
+<row>
+ <entry spanname='s1' align='left'>Notes based on <function>$Id: bits.h 4030 2006-11-30 07:29:25Z esr $</function></entry>
+</row>
+</tfoot>
+
+</tgroup>
+</informaltable>
+</sect1>
diff --git a/doc/explan_dgnss.c.xml b/doc/explan_dgnss.c.xml
new file mode 100644
index 00000000..a0543485
--- /dev/null
+++ b/doc/explan_dgnss.c.xml
@@ -0,0 +1,49 @@
+<sect1 id="dgnss.c"><title><filename>dgnss.c</filename></title>
+<informaltable frame='all' pgwide='1'>
+<tgroup cols='2'>
+<colspec colname='c1'></colspec>
+<colspec colname='c2'></colspec>
+<spanspec spanname='s1' namest='c1' nameend='c2'></spanspec>
+
+<thead>
+<row>
+ <entry>Functions:-</entry><entry>This file provides the interface to Differential GNSS (Global Navigation Satellite Systems) services.</entry>
+</row>
+</thead>
+
+<tbody>
+<row>
+ <entry><function>bool dgnss_url(char *name)</function></entry>
+ <entry><para>Check if a URL is valid for DGPS service.</para></entry>
+</row>
+<row>
+ <entry><function>int dgnss_open(struct gps_context_t *context, char *dgnss_service)</function></entry>
+ <entry><para>Try to open a connection to the nominated service. If the service cannot be opened, the return is -1. The supported services are <emphasis>dgpsip</emphasis> (differential corrections via IP) and <emphasis>ntrip</emphasis> (differential corrections in http form).</para></entry>
+</row>
+<row>
+ <entry><function>int dgnss_poll(struct gps_context_t *context)</function></entry>
+ <entry><para>Try to poll the DGNSS service for a correction report. If no socket is active, simply return 0. If a socket is active, on successful read it stores the current timestamp and the report in the context buffer then returns 0. If no data is ready or an error (except <errortype>EAGAIN</errortype>) occurs, drop the connection and return -1.</para></entry>
+</row>
+<row>
+ <entry><function>void dgnss_report(struct gps_device_t *session)</function></entry>
+ <entry><para>Call the <function>dgpsip_report()</function> or <function>ntrip_report()</function> function if either is active.</para></entry>
+</row>
+<row>
+ <entry><function>void dgnss_autoconnect(struct gps_context_t *context, double lat, double lon)</function></entry>
+ <entry><para>Call the <function>autoconnect()</function> function in <function>dgpsip.c</function></para></entry>
+</row>
+<row>
+ <entry><function>void rtcm_relay(struct gps_device_t *session)</function></entry>
+ <entry><para>If there is a DGNSS connection report in the context buffer, pass it to the caller. If the transaction fails, generate an error log, otherwise, update the session timestamp.</para></entry>
+</row>
+</tbody>
+
+<tfoot>
+<row>
+ <entry spanname='s1' align='left'>Notes based on <function>$Id: dgnss.c 3771 2006-11-02 05:15:20Z esr $</function></entry>
+</row>
+</tfoot>
+
+</tgroup>
+</informaltable>
+</sect1>
diff --git a/doc/explan_dgpsip.c.xml b/doc/explan_dgpsip.c.xml
new file mode 100644
index 00000000..bf7b4316
--- /dev/null
+++ b/doc/explan_dgpsip.c.xml
@@ -0,0 +1,41 @@
+<sect1 id="dgpsip.c"><title><filename>dgpsip.c</filename></title>
+<informaltable frame='all' pgwide='1'>
+<tgroup cols='2'>
+<colspec colname='c1'></colspec>
+<colspec colname='c2'></colspec>
+<spanspec spanname='s1' namest='c1' nameend='c2'></spanspec>
+
+<thead>
+<row>
+ <entry>Functions:-</entry><entry>This file provides the actual services for dgpsip corrections to <function>dgnss.c</function>.</entry>
+</row>
+</thead>
+
+<tbody>
+<row>
+ <entry><function>int dgpsip_open(struct gps_context_t *context, const char *dgpsserver)</function></entry>
+ <entry><para>Tries to open a connection to a dgpsip server. Returns either -1 on failure or the socket number on success. On success, it initializes the connection, sends a <quote>HELO</quote> to the server and stores the type of dgnss service in the context data.</para></entry>
+</row>
+<row>
+ <entry><function>void dgpsip_report(struct gps_device_t *session)</function></entry>
+ <entry><para>If we have not contacted the server and we have at received least 10 fixes, send a report to the server and set the flag, so we don't do it again.</para></entry>
+</row>
+<row>
+ <entry><function>static int srvcmp(const void *s, const void *t)</function></entry>
+ <entry><para>Compare the distance of two servers from our location. Return -ve, 0 or +ve depending if server <function>s</function> is nearer, the same distance away or further away than server <function>t</function>.</para></entry>
+</row>
+<row>
+ <entry><function>void dgpsip_autoconnect(struct gps_context_t *context, double lat, double lon, const char *serverlist)</function></entry>
+ <entry><para>This function takes a list of servers and tries to get a connection to the closest one relative to our location. If no servers are within 1600 km or none are in the list, the dsock value is set to -2 to lock out the function.</para></entry>
+</row>
+</tbody>
+
+<tfoot>
+<row>
+ <entry spanname='s1' align='left'>Notes based on <function>$Id: dgpsip.c 3771 2006-11-02 05:15:20Z esr $</function></entry>
+</row>
+</tfoot>
+
+</tgroup>
+</informaltable>
+</sect1>
diff --git a/doc/explan_driver_proto.c.xml b/doc/explan_driver_proto.c.xml
new file mode 100644
index 00000000..d0f72618
--- /dev/null
+++ b/doc/explan_driver_proto.c.xml
@@ -0,0 +1,22 @@
+<sect1 id="driver_proto.c"><title><filename>driver_proto.c</filename></title>
+<informaltable frame='all' pgwide='1'>
+<tgroup cols='1'>
+<colspec colname='c1'></colspec>
+<colspec colname='c2'></colspec>
+<spanspec spanname='s1' namest='c1' nameend='c2'></spanspec>
+
+<tbody>
+<row>
+ <entry><para>This is a dummy file to use as a skeleton for writing a new driver. The driver is heavily commented, so refer to the source code.</para></entry>
+</row>
+</tbody>
+
+<tfoot>
+<row>
+ <entry spanname='s1' align='left'>Notes based on <function>$Id: driver_proto.c 4229 2007-01-10 23:24:52Z ckuethe $</function></entry>
+</row>
+</tfoot>
+
+</tgroup>
+</informaltable>
+</sect1>
diff --git a/doc/explan_drivers.c.xml b/doc/explan_drivers.c.xml
new file mode 100644
index 00000000..b92efcb7
--- /dev/null
+++ b/doc/explan_drivers.c.xml
@@ -0,0 +1,53 @@
+<sect1 id="drivers.c"><title><filename>drivers.c</filename></title>
+<informaltable frame='all' pgwide='1'>
+<tgroup cols='2'>
+<colspec colname='c1'></colspec>
+<colspec colname='c2'></colspec>
+<spanspec spanname='s1' namest='c1' nameend='c2'></spanspec>
+
+<thead>
+<row>
+ <entry>Functions:-</entry><entry>This is the main driver for NMEA, both plain vanilla and any manufacturer specific variety of NMEA output. This is NOT where manufacturer specific binary matters are handled.</entry>
+</row>
+</thead>
+
+<tbody>
+<row>
+ <entry><function>ssize_t generic_get(struct gps_device_t *session)</function></entry>
+ <entry><para>This is a wrapper to call the real packet getter function, <function>packet_get()</function>.</para></entry>
+</row>
+<row>
+ <entry><function>ssize_t pass_rtcm(struct gps_device_t *session, char *buf, size_t rtcmbytes)</function></entry>
+ <entry><para>This writes the rtcm data to the device.</para></entry>
+</row>
+<row>
+ <entry><function>gps_mask_t nmea_parse_input(struct gps_device_t *session)</function></entry>
+ <entry><para>If the packet is a comment packet, ignore it and return 0.</para><para>If it is one of several binary packets, issue a warning to that effect.</para><para>If the relevant driver exists, switch to that driver and get it to parse the packet. The return value is that of the binary parser.</para><para>If the driver does not exist, ignore the packet and return 0.</para><para>If after all this, it is likely to be an NMEA packet, so try to parse it with the NMEA parser. If that returns a 0 (unsuccessful), then check if it is a trigger packet for one of the triggerable drivers.</para><para>If this succeeds, return 1, otherwise issue an unrecognised packet error.</para><para>Finally checks are made against openBSD's NMEA Line Discipline to make use of timestamping and if ntpd synchronising is active, the time is passed to the ntp daemon.</para></entry>
+</row>
+<row>
+ <entry><function>static void nmea_probe_subtype(struct gps_device_t *session, unsigned int seq)</function></entry>
+ <entry><para>This tries to probe for the NMEA mode of several popular chipsets. Most are detected by a trigger string.</para></entry>
+</row>
+<row>
+ <entry> </entry>
+ <entry><para>Several functions are omitted which are device specific. These are not covered here since they ARE device specific.</para></entry>
+</row>
+<row>
+ <entry><function>static gps_mask_t rtcm104_analyze(struct gps_device_t *session)</function></entry>
+ <entry><para>This function calls <function>rtcm_unpack()</function> to unpack rtcm packets into the session buffer.</para></entry>
+</row>
+<row>
+ <entry> </entry>
+ <entry><para>The last important thing in this code is an array of addresses, one for each compiled-in driver. This address gets us to the <quote>capabilities</quote> table in the bottom of each driver where we find what functions a driver supports and the entry address for each function.</para></entry>
+</row>
+</tbody>
+
+<tfoot>
+<row>
+ <entry spanname='s1' align='left'>Notes based on <function>$Id: drivers.c 4297 2007-03-09 07:11:46Z ckuethe $</function></entry>
+</row>
+</tfoot>
+
+</tgroup>
+</informaltable>
+</sect1>
diff --git a/doc/explan_geoid.c.xml b/doc/explan_geoid.c.xml
new file mode 100644
index 00000000..071e9579
--- /dev/null
+++ b/doc/explan_geoid.c.xml
@@ -0,0 +1,45 @@
+<sect1 id="geoid.c"><title><filename>geoid.c</filename></title>
+<informaltable frame='all' pgwide='1'>
+<tgroup cols='2'>
+<colspec colname='c1'></colspec>
+<colspec colname='c2'></colspec>
+<spanspec spanname='s1' namest='c1' nameend='c2'></spanspec>
+
+<thead>
+<row>
+ <entry>Functions:-</entry><entry>Provides conversion between the ECEF and WGS84 co-ordinate reference systems.</entry>
+</row>
+</thead>
+
+<tbody>
+<row>
+ <entry><function>static double bilinear(double x1, double y1, double x2, double y2, double x, double y, double z11, double z12, double z21, double z22)</function></entry>
+ <entry><para>This is a piece of mathematical manipulation only used internally in this code, so wrestle with it if you will!</para></entry>
+</row>
+<row>
+ <entry><function>double wgs84_separation(double lat, double lon)</function></entry>
+ <entry><para>This is used by drivers to get the separation of MSL from the WGS84 datum at a pair of Latitude/Longitude co-ordinates. The data is in a pre-defined table.</para></entry>
+</row>
+<row>
+ <entry><function>void ecef_to_wgs84fix(struct gps_data_t *gpsdata, double x, double y, double z, double vx, double vy, double vz)</function></entry>
+ <entry><para>This does exactly what it says! Co-ordinate system conversion from ecef to the wgs84 equivalent.</para></entry>
+</row>
+<row>
+ <entry><function>static double fix_minuz(double d)</function></entry>
+ <entry><para>This forces a value of -0.0 to be the same as 0.0 so that certain trig functions act in a predictable manner.</para></entry>
+</row>
+<row>
+ <entry><function>int main(int argc, char **argv)</function></entry>
+ <entry><para>This is a local test routine which exercises the other code for debugging purposes. It is normally shut off by an <function>#ifdef</function>.</para></entry>
+</row>
+</tbody>
+
+<tfoot>
+<row>
+ <entry spanname='s1' align='left'>Notes based on <function>$Id: geoid.c 4257 2007-01-18 03:56:43Z ckuethe $</function></entry>
+</row>
+</tfoot>
+
+</tgroup>
+</informaltable>
+</sect1>
diff --git a/doc/explan_gps.h.xml b/doc/explan_gps.h.xml
new file mode 100644
index 00000000..ac08310a
--- /dev/null
+++ b/doc/explan_gps.h.xml
@@ -0,0 +1,37 @@
+<sect1 id="gps.h"><title><filename>gps.h</filename></title>
+<informaltable frame='all' pgwide='1'>
+<tgroup cols='2'>
+<colspec colname='c1'></colspec>
+<colspec colname='c2'></colspec>
+<spanspec spanname='s1' namest='c1' nameend='c2'></spanspec>
+
+<thead>
+<row>
+ <entry>Structures:-</entry><entry>The interface of the libgps library, provides data structures the library needs and that the daemon fills.</entry>
+</row>
+</thead>
+
+<tbody>
+<row>
+ <entry><function>struct gps_fix_t {}</function></entry>
+ <entry><para>This is the fix related data gathered from the gps device. Each client session has 2, the current fix and the previous fix.</para></entry>
+</row>
+<row>
+ <entry><function>struct rtcm_t {}</function></entry>
+ <entry><para>This holds the data being processed by the rtcm functions.</para></entry>
+</row>
+<row>
+ <entry><function>struct gps_data_t {}</function></entry>
+ <entry><para>This contains ALL the data available from the daemon; the actual fix, status flags, headings etc. Basically any good stuff that we might want goes here.</para></entry>
+</row>
+</tbody>
+
+<tfoot>
+<row>
+ <entry spanname='s1' align='left'>Notes based on <function>$Id: gps.h 4284 2007-01-27 07:27:42Z ckuethe $</function></entry>
+</row>
+</tfoot>
+
+</tgroup>
+</informaltable>
+</sect1>
diff --git a/doc/explan_gpsd.c.xml b/doc/explan_gpsd.c.xml
new file mode 100644
index 00000000..c214560e
--- /dev/null
+++ b/doc/explan_gpsd.c.xml
@@ -0,0 +1,117 @@
+<sect1 id="gpsd.c"><title><filename>gpsd.c</filename></title>
+<informaltable frame='all' pgwide='1'>
+<tgroup cols='2'>
+<colspec colname='c1'></colspec>
+<colspec colname='c2'></colspec>
+<spanspec spanname='s1' namest='c1' nameend='c2'></spanspec>
+
+<thead>
+<row>
+ <entry>Functions:-</entry><entry>This is the main body of the daemon.</entry>
+</row>
+</thead>
+
+<tbody>
+<row>
+ <entry><function>static void onsig(int sig)</function></entry>
+ <entry><para>Reset a previously modified signal to default handling.</para></entry>
+</row>
+<row>
+ <entry><function>static int daemonize(void)</function></entry>
+ <entry><para>Try to <function>fork()</function> a child process. The parent will get a return value of either -1 (on a failure to <function>fork()</function>) or non-zero (the child's PID). The parent routine will use this information to either return -1 or exit with an exit code of 0 (i.e. the parent terminates, leaving the child running).</para><para>The child instance gets a return value of 0 (on an unsuccessful <function>fork()</function> there is no child), so this value is used as the trigger to do the following useful stuff.</para><para>First, the child tries to create a new session, returning -1 if unable to do so. If succesful, it will have inherited the exiting parent's session.</para><para>Next switch to the root directory and try to open <quote>/dev/null</quote>. If that succeeds, force stdin, stdout and stderr to duplicate the fd of <quote>/dev/null</quote>. If the fd being used for the operation is >2, release it.</para><para>Finally, set the flag which indicates 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 unneccessary 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 the default <application>gpsd</application> port (2947, allocated by IANA).</para></entry>
+</row>
+<row>
+ <entry><function>static int passivesock(char *service, char *protocol, int qlen)</function></entry>
+ <entry><para>Initialise an Internet socket address structure and preload the family and address fields to accept Internet Protocol and any address.</para><para>Test to see if the incoming service and protocol exist in <function>/etc/services</function>. If they do, store the port number in the structure (massaging byte order as needed); if they don't, exit with a -1.</para><para>Test to see if the protocol is listed in <function>/etc/services</function>, exiting with -1 if it is not.</para><para>Test if the protocol is udp or not, setting the type accordingly.</para><para>Try to open a socket with the accumulated settings, exiting with -1 if it fails.</para><para>Try to set the socket options correctly, again exiting with -1 if it fails.</para><para>Try to bind to the open socket; if it fails exit with -1 as earlier, but give a special warning if the error indicates that <application>gpsd</application> may already be active on the socket.</para><para>If we are using a stream type socket and we are unable to listen to the port we exit with -1.</para><para>The last possibilty is a successful set of operations which is signalled by returning the socket fd number.</para></entry>
+</row>
+<row>
+ <entry><function>static int filesock(char *filename)</function></entry>
+ <entry><para>Try and open a socket for Local (UNIX) communications in streaming mode. If the open fails, return with a -1.</para><para>If it opens, copy the incoming filename into the socket control structure, bind to the socket and try to listen on it.</para><para>Signal a failure by returning -1 and success by returning the socket fd number.</para></entry>
+</row>
+<row>
+ <entry><function>static void adjust_max_fd(int fd, bool on)</function></entry>
+ <entry><para>If the incoming boolean flag is active, check if the fd number passed is greater than the highest seen so far. If so, save it as the new highest value.</para><para>If the boolean is passive we can take some further action, depending if we are interested in limiting the maximum number of devices and client fds (set by compile time options).</para><para>If we are not limiting ourselves, then we check for the case when we are actually at the highest fd seen so far. In that case, scan through all fds available to the system and store the highest active fd number in our allocation set as the new highest value.</para></entry>
+</row>
+<row>
+ <entry><function>static bool have_fix(struct subscriber_t *whoami)</function></entry>
+ <entry><para>If the call is made from a client with no associated device, return a false indication.</para><para>If the status and mode don't agree about having a fix, return a false indication.</para><para>If both status and mode agree that we have a fix, return a true indication.</para><para>Finally, the fall through is that there really is no fix, so return a false indication.</para></entry>
+</row>
+<row>
+ <entry><function>static struct subscriber_t* allocate_client(void)</function></entry>
+ <entry><para>Scan through all the client file descriptors, looking for one which does not have a device allocated to it.</para><para>On a match, exit early, returning this fd.</para><para>If none are available, return a NULL.</para></entry>
+</row>
+<row>
+ <entry><function>static void detach_client(struct subscriber_t *sub)</function></entry>
+ <entry><para>Close the given fd and remove it from our allocation set.</para><para>Make a call to <function>adjust_max_fd()</function> to housekeep the highest fd marker if needed.</para><para>Set important fields in the client's datablock to safe values for the next re-use, then return.</para></entry>
+</row>
+<row>
+ <entry><function>static ssize_t throttled_write(struct subscriber_t *sub, char *buf, ssize_t len)</function></entry>
+ <entry><para>Check if we have a high enough debug level active to warrant printing out the information we are about to send to the client.</para><para>Make the actual <function>write()</function> call and if that was successful, return the counter value from that operation.</para><para>If we have suffered some kind of failure, try to analyse it.</para><para>Trap <function>EBADF</function> and generate a suitable report.</para><para>Trap <function>EWOULDBLOCK</function> and if the client has not read data for more than a reasonable amount of time, generate a suitable report.</para><para>For all other errors, generate a general error and call <function>detach_cient()</function>.</para><para>Finally, return the status (-1 in this case).</para></entry>
+</row>
+<row>
+ <entry><function>static void notify_watchers(struct gps_device_t *device, char *sentence, ...)</function></entry>
+ <entry><para>For every possible subscriber, check if the subscriber is in watcher mode and is interested in the gps device indicated in the calling parameter <function>gps_device_t</function>.</para><para>If so, send the data via a call to <function>throttled_write()</function>.</para></entry>
+</row>
+<row>
+ <entry><function>static void raw_hook(struct gps_data_t *ud, char *sentence, size_t len, int level)</function></entry>
+ <entry><para>For every possible subscriber, check if the incoming level matches the subscriber's raw setting, that the subscriber has a device associated with it and that the gps device indicated in the calling parameter <function>gps_device_t</function> is the one the subscriber is interested in.</para><para>If all conditions are satisfied, send the data via <function>throttled_write()</function>.</para></entry>
+</row>
+<row>
+ <entry><function>static struct gps_device_t *find_device(char *device_name)</function></entry>
+ <entry><para>For every possible channel, check if the channel is allocated and if the device on the channel is the one passed to us.</para><para>If it is so, exit early and return the channel number.</para><para>If there is no match, return a NULL.</para></entry>
+</row>
+<row>
+ <entry><function>static struct gps_device_t *open_device(char *device_name)</function></entry>
+ <entry><para>Check if the incoming device name is a DGPS URL via a call to <function>dgnss_url()</function>.</para><para>If it is, try to open it via a call to <function>dgnss_open()</function>.</para><para>If this worked, add the fd to our list of active fds and housekeep the highest fd number via a call to <function>adjust_max_fd()</function>. Exit by returning the address of the channels array (see the comment in the code!!).</para><para>For a non-DGPS (normal) device, scan all channels looking for an unallocated one. Exit early on a successful search. If none is found, return a NULL.</para><para>If one is found, make a call to <function>gpsd_init()</function> and store address of the local <function>raw_hook()</function> code in the selected channel's <function>gpsdata.raw_hook</function>.</para><para>Try to activate the device via a call to <function>gpsd_activate()</function>.</para><para>If this fails return -1.</para><para>If it succeeds, add the fd to our list of active fds, housekeep the highest fd number and return the channel number allocated.</para></entry>
+</row>
+<row>
+ <entry><function>static bool allocation_policy(struct gps_device_t *channel, struct subscriber_t *user, double most_recent)</function></entry>
+ <entry><para>Test that the caller has an active device and that the timestamp of the proposed channel's last sentence is not older than the caller's most recent data.</para><para>If the tests fail, return <quote>false</quote>.</para><para>Check what type of device is required by the caller.</para><para>If the caller has no preference, just return <quote>true</quote>.</para><para>If the requirement is RTCM and the channel is giving RTCM data, return <quote>true</quote>.</para><para>If the user needs gps and the channel is giving good, non-RTCM, packets return <quote>true</quote>.</para><para>If there is no match, default to returning <quote>false</quote>.</para></entry>
+</row>
+<row>
+ <entry><function>static bool assign_channel(struct subscriber_t *user)</function></entry>
+ <entry><para>Test if the user has a device assigned.</para><para>If none is assigned, scan all channels and test each one to see if it is allocated.</para><para>If it is allocated, test with <function>allocation_policy()</function> to see if we can use it.</para><para>If we can, link the channel to the user and stash the value of its last sentence.</para><para>At the end of the loop, we either have a NULL on no allocation or we have allocated once or more, retaining a suitable device which has the most recent data.</para><para>If we failed to allocate, return <quote>false</quote>.</para><para>Test if the channel has an active fd.</para><para>If it does not, make a call to <function>gpsd_activate()</function>.</para><para>If this fails, return <quote>false</quote>, if not, add the fd to our list of active fds and housekeep the highest fd.</para><para>Check if the user is in watcher mode but not tied to a specific device.</para><para>If these conditions are sastified, generate a string and send it to the caller to advise them of the assigned device's name.</para><para>Finally, if the caller is in watcher mode and did not have a device previously assigned, generate and send a string advising the caller of the time and the assigned device name/subtype from a call to <function>gpsd_id()</function>.</para></entry>
+</row>
+<row>
+ <entry><function>static int handle_rtcm_request(struct subscriber_t* sub UNUSED, char *buf UNUSED, int buflen UNUSED)</function></entry>
+ <entry><para>Does nothing except return 0 at the moment.</para></entry>
+</row>
+<row>
+ <entry><function>static char *snarfline(char *p, char **out)</function></entry>
+ <entry><para>Copy the input line into a new buffer stopping at the first non-printable or whitespace character.</para></entry>
+</row>
+<row>
+ <entry><function>static bool privileged_user(struct subscriber_t *who)</function></entry>
+ <entry><para>Scan all susbcribers and count all who are connected to the caller's device. If only the one user is connected, return <quote>true</quote>, otherwise return <quote>false</quote>.</para></entry>
+</row>
+<row>
+ <entry><function>static int handle_gpsd_request(struct subscriber_t* sub, char *buf, int buflen)</function></entry>
+ <entry><para>Start by filling the return buffer with <quote>GPSD</quote> in readiness.</para><para>Scan through the input buffer until the end of the string is reached. Act on the first character (it is assumed to be a command character).</para><para>The commands are checked in a switch statement and either simply generate some output to the buffer or generate output and also cause the input buffer pointer to be advanced over one or more characters as needed (individual command handling will not be analysed here).</para><para>This technique allows several concatenated parameters to be extracted and handled in any order.</para><para>After some checks on the output buffer length (which generate an error return on overflow), the output buffer is passed to <function>throttled_write()</function> and its return value is used used as the return value for the function.</para></entry>
+</row>
+<row>
+ <entry><function>static void handle_control(int sfd, char *buf)</function></entry>
+ <entry><para>This code is similar in function to <function>handle_gpsd_request()</function> in that it parses user input. It expects the commands to be one per line and despatches them according to the leading character, which is limited to one of '-', '+' or '!'.</para><para>In the first case, the body of the command is assumed to be a device to remove from the search list. If found, it is removed, any clients are advised and <quote>OK</quote> is written to the calling socket fd. If the device is not found <quote>ERROR</quote> is written to the calling socket fd.</para><para>In the second case, the body of the command is assumed to be a device to be used by the daemon. If the device is already known, or does not respond to <function>open_device()</function>, <quote>ERROR</quote> is written to the calling socket fd, otherwise <quote>OK</quote> is written.</para><para>In the third case, the command is assumed to be a device-specific control string in the form <quote>!device_name=control_string</quote>. If the string is ill-formed or the device is not found <quote>ERROR</quote> is written to the calling socket fd. If all is well, the control string is written to the device and <quote>OK</quote> is written to the calling socket fd.</para></entry>
+</row>
+<row>
+ <entry><function>int main(int argc, char *argv[])</function></entry>
+ <entry><para>If the 1PPS function is compiled in, initialise the local mutex structure for use by the program.</para><para>A <function>while()</function> loop reads in any command line arguments which are options and handles the options. Most set an internal variable to contol action when running, either to a fixed value or to the associated option's parameter.</para><para>Carry out a series of calls to routines to set things up ready for the main task (e.g. opening a control socket if one is needed). We also take care of tasks such as daemonizing when appropriate. The last piece of preparation is to set the permissions of the default devices correctly if we are daemonizing and are presently running as root.</para><para>Switch to the compiled in user name (typically <quote>nobody</quote>) and the group used by the tty devices.</para><para>Now we clear important data for all the records in the subscriber list.</para><para>Use <function>setjmp()</function> to prepare things for when the daemon terminates.</para><para>Set some important signals so they are trapped by a local handler. This handler just resets the calling signal to its default behaviour and calls <function>longjmp()</function>. This will bring things back to the <function>setjmp()</function> just mentioned and initiate a clean up and exit.</para><para>Add the command and RTCM sockets (if active) to the list of active fds, housekeeping the highest fd number and pre-clear the list of control fds.</para><para>Process the remaining parameter on the command line which should be the device name and try to open the specified device.</para><para>Enter the main execution loop, an endless <function>for()</function> loop. What follows will repeat over and over until an external termination happens or the <function>select()</function> function fails due to some unexpected reason.</para><para>First we make a working copy of the active fds and then we make a time-limited (1 second time limit) call to <function>select()</function> using the working copy of the fds. This means that when the <function>select()</function> returns, we will either have returned on timeout or because some fd became ready to read.</para><para>First we check if any new clients have come active and (if we have resources) allocate a subscriber slot to it, doing housekeeping such as adding it to the main list of active fds and removing it from the local copy of the list. If RTCM support is compiled in, the last operation is repeated for any new RTCM client. The operation is then repeated for any new control socket clients.</para><para>If we are expecting DGPS reports, make a call to <function>dgnss_poll()</function> and if there are no ready reports, clear the fd from the main and local active fd lists.</para><para>Check if any of the active control sockets has sent one or more commands.</para><para>For every one which has sent commands, make calls to <function>handle_control()</function> to process them and remove the associated fd from the main and control lists of active fds.</para><para>Poll every active gps device and send RTCM data to it (if needed), followed by reading its output (if any). If the device returns an error, disable the device. If it has gone off-line, disable the device.</para><para>If we get here, we have something to handle, so we take care of a device which we know about, but do not have a subtype for.</para><para>We send the available data to all subscribers who are connected to this device. If the data is RTCM information, pass it to all gps devices that can accept the data.</para><para>Handle any subscribers who are in watcher mode building up an approriate set of requests, depending on the available data and passing the requests to <function>handle_gpsd_request()</function>.</para><para>If we care about DBUS, send the fix to the DBUS.</para><para><emphasis>Note that this small section of code is presently disabled pending development of the DGNSS function.</emphasis> If DGNSS is avalable and we have a fix, we poll a DGNSS report via <function>dgnss_autoconnect()</function>.</para><para>Loop round all clients and process active ones. We check for input from them and if the read fails, the client is released with <function>detach_cleint()</function>. If it succeeds, any data is handled via <function>handle_rtc_request()</function> or <function>handle_gpsd_request()</function>.</para><para>If the transaction fails, the client is released with <function>detach_client()</function>.</para><para>If the client has timed out with no device assigned, it is released with <function>detach_client()</function>.</para><para>If the client has a device, but has timed out on no response (when not in raw or watcher modes) it is released with <function>detach_client()</function>.</para><para>If we are not running in <quote>nowait</quote> mode, we are supposed to go idle when there are no clients. However, this is subject to a restriction that a device is not allowed to go idle like this until we have actually discovered what it is. This means we stay active until the packet sniffer has returned the packet type.</para><para>If a device (with a known type) has no active clients, then we can actually make it idle via <function>gpsd_deactivate()</function>.</para><para>If we reach here, we are out of the endless loop, so finally we check for the existance of a control socket or a pid file and delete them.</para></entry>
+</row>
+</tbody>
+
+<tfoot>
+<row>
+ <entry spanname='s1' align='left'>Notes based on <function>$Id: gpsd.c 4302 2007-03-14 02:27:45Z ckuethe $</function></entry>
+</row>
+</tfoot>
+
+</tgroup>
+</informaltable>
+</sect1>
diff --git a/doc/explan_gpsd.h.xml b/doc/explan_gpsd.h.xml
new file mode 100644
index 00000000..736d83fb
--- /dev/null
+++ b/doc/explan_gpsd.h.xml
@@ -0,0 +1,41 @@
+<sect1 id="gpsd.h"><title><filename>gpsd.h</filename></title>
+<informaltable frame='all' pgwide='1'>
+<tgroup cols='2'>
+<colspec colname='c1'></colspec>
+<colspec colname='c2'></colspec>
+<spanspec spanname='s1' namest='c1' nameend='c2'></spanspec>
+
+<thead>
+<row>
+ <entry>Structures:-</entry><entry>Provides fundamental types and structures for the GPS daemon. Only key structures are analysed here. Simple definitions and prototype definitions are ignored.</entry>
+</row>
+</thead>
+
+<tbody>
+<row>
+ <entry><function>struct gps_packet_t {}</function></entry>
+ <entry><para>Provides the data structure used by <function>packet_getter()</function>. 1 per <application>gpsd</application> session.</para></entry>
+</row>
+<row>
+ <entry><function>struct gps_context_t {}</function></entry>
+ <entry><para>Provides context data like number of good fixes seen. 1 per <application>gpsd</application> session.</para></entry>
+</row>
+<row>
+ <entry><function>struct gps_type_t {}</function></entry>
+ <entry><para>This is the method table that every driver uses to communicate with the daemon. It is a table of entry points or externally visible data. 1 per driver type.</para></entry>
+</row>
+<row>
+ <entry><function>struct gps_device_t {}</function></entry>
+ <entry><para>This is the data belonging to a session (global state) and also private storage for the session's associated device driver (if needed). 1 per <application>gpsd</application> session.</para></entry>
+</row>
+</tbody>
+
+<tfoot>
+<row>
+ <entry spanname='s1' align='left'>Notes based on <function>$Id: gpsd.h 4304 2007-03-14 06:07:46Z ckuethe $</function></entry>
+</row>
+</tfoot>
+
+</tgroup>
+</informaltable>
+</sect1>
diff --git a/doc/explan_gpsd_dbus.c.xml b/doc/explan_gpsd_dbus.c.xml
new file mode 100644
index 00000000..ef87deaa
--- /dev/null
+++ b/doc/explan_gpsd_dbus.c.xml
@@ -0,0 +1,33 @@
+<sect1 id="gpsd_dbus.c"><title><filename>gpsd_dbus.c</filename></title>
+<informaltable frame='all' pgwide='1'>
+<tgroup cols='2'>
+<colspec colname='c1'></colspec>
+<colspec colname='c2'></colspec>
+<spanspec spanname='s1' namest='c1' nameend='c2'></spanspec>
+
+<thead>
+<row>
+ <entry>Functions:-</entry><entry>Handles initialization of and communication with the DBUS.</entry>
+</row>
+</thead>
+
+<tbody>
+<row>
+ <entry><function>int initialize_dbus_connection(void)</function></entry>
+ <entry><para>Initializes the DBUS connection.</para></entry>
+</row>
+<row>
+ <entry><function>void send_dbus_fix(struct gps_device_t* channel)</function></entry>
+ <entry><para>Sends the current fix data for this channel via dbus</para></entry>
+</row>
+</tbody>
+
+<tfoot>
+<row>
+ <entry spanname='s1' align='left'>Notes based on <function>$Id: gpsd_dbus.c 3666 2006-10-26 23:11:51Z ckuethe $</function></entry>
+</row>
+</tfoot>
+
+</tgroup>
+</informaltable>
+</sect1>
diff --git a/doc/explan_gpsutils.c.xml b/doc/explan_gpsutils.c.xml
new file mode 100644
index 00000000..aac06e84
--- /dev/null
+++ b/doc/explan_gpsutils.c.xml
@@ -0,0 +1,81 @@
+<sect1 id="gpsuitls.c"><title><filename>gpsutils.c</filename></title>
+<informaltable frame='all' pgwide='1'>
+<tgroup cols='2'>
+<colspec colname='c1'></colspec>
+<colspec colname='c2'></colspec>
+<spanspec spanname='s1' namest='c1' nameend='c2'></spanspec>
+
+<thead>
+<row>
+ <entry>Functions:-</entry><entry>Code shared between low-level and high-level interfaces. Most of them do exactly what they say on the tin.</entry>
+</row>
+</thead>
+
+<tbody>
+<row>
+ <entry><function>void gps_clear_fix(struct gps_fix_t *fixp)</function></entry>
+ <entry><para>Stuff a fix structure with recognizable out-of-band values.</para></entry>
+</row>
+<row>
+ <entry><function>unsigned int gps_valid_fields(struct gps_fix_t *fixp)</function></entry>
+ <entry><para>Clears certain status flags, depending if the associated fields are invalid.</para></entry>
+</row>
+<row>
+ <entry><function>char *gps_show_transfer(int transfer)</function></entry>
+ <entry><para>Takes a mask word and uses it to check certain status flags. If the associated flag is active, the name of the status is written to the return buffer.</para></entry>
+</row>
+<row>
+ <entry><function>void gps_merge_fix(struct gps_fix_t *to, gps_mask_t transfer, struct gps_fix_t *from)</function></entry>
+ <entry><para>Merges (overwrites the contents of) an old fix with the contents of a new fix for those fields where the associated bit in the mask word is set and the new fix data is valid.</para></entry>
+</row>
+<row>
+ <entry><function>double timestamp(void)</function></entry>
+ <entry><para>Returns the number of seconds and microseconds since the UNIX Epoch (00:00:00 UTC, January 1, 1970); i.e. a unique value which can be used to timestamp any event.</para></entry>
+</row>
+<row>
+ <entry><function>time_t mkgmtime(register struct tm *t)</function></entry>
+ <entry><para>Convert a struct <function>tm {}</function> (see <function>time.h</function>) to seconds since UNIX Epoch.</para></entry>
+</row>
+<row>
+ <entry><function>double iso8601_to_unix(char *isotime)</function></entry>
+ <entry><para>Convert an ISO8601 UTC string (like 2006-01-25T13:15:22.9) to Unix UTC.</para></entry>
+</row>
+<row>
+ <entry><function>char *unix_to_iso8601(double fixtime, char isotime[], int len)</function></entry>
+ <entry><para>Reverse of the above, no timezone adjustment.</para></entry>
+</row>
+<row>
+ <entry><function>double gpstime_to_unix(int week, double tow)</function></entry>
+ <entry><para>Convert gps time to UNIX time, allowing for the gps week number rollover.</para></entry>
+</row>
+<row>
+ <entry><function>void unix_to_gpstime(double unixtime, int *week, double *tow)</function></entry>
+ <entry><para>Reverse of the above.</para></entry>
+</row>
+<row>
+ <entry><function>static double CalcRad(double lat)</function></entry>
+ <entry><para>Return the earth's radius of curvature in meters at specified latitude.</para></entry>
+</row>
+<row>
+ <entry><function>double earth_distance(double lat1, double lon1, double lat2, double lon2)</function></entry>
+ <entry><para>Return the distance in meters between two points specified in degrees.</para></entry>
+</row>
+<row>
+ <entry><function>static int invert(double mat[4][4], double inverse[4][4])</function></entry>
+ <entry><para>Try and invert an array. If it is possible, fill the inverted array and return a 1. Return a 0 if it is not possible.</para></entry>
+</row>
+<row>
+ <entry><function>gps_mask_t dop(struct gps_data_t *gpsdata)</function></entry>
+ <entry><para>Take a gps data structure and try to calculate the DOP values from the other data in it. Return 0 if it is not possible or update the appropriate DOP fields in the structure and set a mask which tells which fields were updated.</para></entry>
+</row>
+</tbody>
+
+<tfoot>
+<row>
+ <entry spanname='s1' align='left'>Notes based on <function>$Id: gpsutils.c 4108 2006-12-08 11:48:31Z esr $</function></entry>
+</row>
+</tfoot>
+
+</tgroup>
+</informaltable>
+</sect1>
diff --git a/doc/explan_isgps.c.xml b/doc/explan_isgps.c.xml
new file mode 100644
index 00000000..45deb281
--- /dev/null
+++ b/doc/explan_isgps.c.xml
@@ -0,0 +1,49 @@
+<sect1 id="isgps.c"><title><filename>isgps.c</filename></title>
+<informaltable frame='all' pgwide='1'>
+<tgroup cols='2'>
+<colspec colname='c1'></colspec>
+<colspec colname='c2'></colspec>
+<spanspec spanname='s1' namest='c1' nameend='c2'></spanspec>
+
+<thead>
+<row>
+ <entry>Functions:-</entry><entry>This contains low level handling for the data transmission format of the satellite downlink and the rtcm radio data stream. ESR comments <quote>You are not expected to understand any of this.</quote>. Let's try anyhow.</entry>
+</row>
+</thead>
+
+<tbody>
+<row>
+ <entry><function>static unsigned char parity_array[]</function></entry>
+ <entry><para>An array of parity values to allow fast lookup instead of calculation.</para></entry>
+</row>
+<row>
+ <entry><function>static unsigned int reverse_bits[]</function></entry>
+ <entry><para>An array of conversion values to allow fast lookup instead of calculation.</para></entry>
+</row>
+<row>
+ <entry><function>unsigned int isgps_parity(isgps30bits_t th)</function></entry>
+ <entry><para>Calculate the ISGPS parity for the incoming 30 bit word. This involves lots of masking (with preset values or values searched through <function>parity_array[]</function>) and shifting</para></entry>
+</row>
+<row>
+ <entry><function>void isgps_init(struct gps_packet_t *session)</function></entry>
+ <entry><para>Initialise the ISGPS data for the current session.</para></entry>
+</row>
+<row>
+ <entry><function>enum isgpsstat_t isgps_decode(struct gps_packet_t *session, bool (*preamble_match)(isgps30bits_t *), bool (*length_check)(struct gps_packet_t *), size_t maxlen, unsigned int c)</function></entry>
+ <entry><para>Check the validity of the ISGPS word tag (incoming data <function>unsigned int c</function>) and exit with an error if it is not valid.</para><para>If the session has not already locked with the datastream, loop through the data and try and sync up. If sync is achieved, exit early with an indication of sync, or fall through still marked unsynced.</para><para>If the session is already locked to the datastream, read the data into the session buffer. All the while, take care that the datastream is not corrupted. Any error will result in an early return with an appropriate error code. At the end of this section, return the status of the operations.</para><para>Finally, if the above two sections failed, exit with an error indicating that lock was not achieved.</para></entry>
+</row>
+<row>
+ <entry><function>void isgps_output_magnavox(isgps30bits_t *ip, unsigned int len, FILE *fp)</function></entry>
+ <entry><para>Ship an IS-GPS-200 message to standard output in Magnavox format.</para></entry>
+</row>
+</tbody>
+
+<tfoot>
+<row>
+ <entry spanname='s1' align='left'>Notes based on <function>$Id: isgps.c 4065 2006-12-04 05:31:59Z esr $</function></entry>
+</row>
+</tfoot>
+
+</tgroup>
+</informaltable>
+</sect1>
diff --git a/doc/explan_libgps.c.xml b/doc/explan_libgps.c.xml
new file mode 100644
index 00000000..669ee7af
--- /dev/null
+++ b/doc/explan_libgps.c.xml
@@ -0,0 +1,81 @@
+<sect1 id="libgps.c"><title><filename>libgps.c</filename></title>
+<informaltable frame='all' pgwide='1'>
+<tgroup cols='2'>
+<colspec colname='c1'></colspec>
+<colspec colname='c2'></colspec>
+<spanspec spanname='s1' namest='c1' nameend='c2'></spanspec>
+
+<thead>
+<row>
+ <entry>Functions:-</entry><entry>The client interface library for the <application>gpsd</application> daemon.</entry>
+</row>
+</thead>
+
+<tbody>
+<row>
+ <entry><function>enum unit gpsd_units(void)</function></entry>
+ <entry><para>Simple check of the environment to determine what units are required. If all else fails, use compiled in units.</para></entry>
+</row>
+<row>
+ <entry><function>struct gps_data_t *gps_open(const char *host, const char *port)</function></entry>
+ <entry><para>Open a connection to a gps daemon.</para><para>Try to get a <function>gps_data_t</function> structure. If it fails, return a NULL.</para><para>Test for a specified host and/or port number, using defaults if nothing is specified in the command line invocation.</para><para>Try to connect to the now defined socket; on error, release the resources and return NULL. On success, initialise the data structure and return the pointer to it.</para></entry>
+</row>
+<row>
+ <entry><function>int gps_close(struct gps_data_t *gpsdata)</function></entry>
+ <entry><para>Close the fd associated with the <function>gps_data_t</function> structure and stash the result.</para><para>If there is a device id stored, NULL it and the associated path.</para><para>If the device list has any data in it, free this and mark the number of available devices as invalid.</para><para>Free the <function>gps_data_t</function> structure itself and return the stashed <function>close()</function> result.</para></entry>
+</row>
+<row>
+ <entry><function>void gps_set_raw_hook(struct gps_data_t *gpsdata, void (*hook)(struct gps_data_t *, char *, size_t len, int level))</function></entry>
+ <entry><para>Fill in the hook to the data for use in raw mode.</para></entry>
+</row>
+<row>
+ <entry><function>static void gps_unpack(char *buf, struct gps_data_t *gpsdata)</function></entry>
+ <entry><para>Keep looping through the data in <function>buf</function> finding an occurrence of <quote>GPSD</quote>.</para><para>Each time one is found, read data in, discarding the initial <quote>GPSD</quote>.</para><para>The data is parsed by scanning to either a <quote>,</quote> or a CR or a LF. This will break the response into <application>gpsd</application> tuples. These are analysed by a big switch statement and the relevant fields and flags are set in the <function>gps_data_t</function> structure.</para><para>Any empty fields (<quote>?</quote> in them) are set to a safe value such as NaN.</para><para>If either of the raw data or thread data hooks is valid, hook the new data in at level 1 (raw mode).</para></entry>
+</row>
+<row>
+ <entry><function>int gps_poll(struct gps_data_t *gpsdata)</function></entry>
+ <entry><para>Poll the daemon and if there is no data or an error, return -1.</para><para>If there is something to read, clear the buffer, note the time as the received data time and the online time, then unpack the data.</para><para>If profiling is active, use the received data time, the fix time and the present time to calcluate the decode time and the client receipt time.</para></entry>
+</row>
+<row>
+ <entry><function>int gps_query(struct gps_data_t *gpsdata, const char *fmt, ... )</function></entry>
+ <entry><para>Gather up the instructions to a <application>gpsd</application> instance for information to return and write them to the device.</para><para>If the write fails, return -1; if it succeeds, call <function>gps_poll()</function> to get any response and return its result.</para></entry>
+</row>
+<row>
+ <entry><function>static void *poll_gpsd(void *args)</function></entry>
+ <entry><para>Set the thread parameters the way we need them (asynchronously cancellable) and then call <function>gps_poll()</function> continuously until we get a failure.</para></entry>
+</row>
+<row>
+ <entry><function>int gps_set_callback(struct gps_data_t *gpsdata, void (*callback)(struct gps_data_t *sentence, char *buf, size_t len, int level), pthread_t *handler)</function></entry>
+ <entry><para>Set <application>gpsd</application> into watcher mode, so it will be generating data.</para><para>If the thread hook is already active, set it to hook to our data and return a 0, otherwise set it to hook to our data and make a call to <function>pthread_create()</function> and return its value (0 if it succeeded).</para></entry>
+</row>
+<row>
+ <entry><function>int gps_del_callback(struct gps_data_t *gpsdata, pthread_t *handler)</function></entry>
+ <entry><para>Cancel the thread and stash the return value.</para><para>Set the hook to NULL now it is not needed.</para><para>If the stashed result was good, switch <application>gpsd</application> out of watcher mode.</para><para>In all cases, return the stashed result.</para></entry>
+</row>
+<row>
+ <entry></entry>
+ <entry><para>The following three functions are guarded by an <function>#ifdef</function> so they only compile if it is required to be able to test the library and set up a command line exerciser interface.</para></entry>
+</row>
+<row>
+ <entry><function>static void data_dump(struct gps_data_t *collect, time_t now)</function></entry>
+ <entry><para>A data dumper used when debugging. It outputs data according to the command line input data.</para></entry>
+</row>
+<row>
+ <entry><function>static void dumpline(struct gps_data_t *ud UNUSED, char *buf, size_t ulen UNUSED, int level UNUSED)</function></entry>
+ <entry><para>A simple call to UNIX <function>puts()</function>.</para></entry>
+</row>
+<row>
+ <entry><function>int main(int argc, char *argv[])</function></entry>
+ <entry><para>A simple command line parser and endless loop to exercise the daemon when deugging.</para></entry>
+</row>
+</tbody>
+
+<tfoot>
+<row>
+ <entry spanname='s1' align='left'>Notes based on <function>$Id: libgps.c 4226 2007-01-06 20:26:47Z ckuethe $</function></entry>
+</row>
+</tfoot>
+
+</tgroup>
+</informaltable>
+</sect1>
diff --git a/doc/explan_libgpsd_core.c.xml b/doc/explan_libgpsd_core.c.xml
new file mode 100644
index 00000000..9cdf4e99
--- /dev/null
+++ b/doc/explan_libgpsd_core.c.xml
@@ -0,0 +1,93 @@
+<sect1 id="libgpsd_core.c"><title><filename>libgpsd_core.c</filename></title>
+<informaltable frame='all' pgwide='1'>
+<tgroup cols='2'>
+<colspec colname='c1'></colspec>
+<colspec colname='c2'></colspec>
+<spanspec spanname='s1' namest='c1' nameend='c2'></spanspec>
+
+<thead>
+<row>
+ <entry>Functions:-</entry><entry>Direct access to GPSes on serial or USB devices.</entry>
+</row>
+</thead>
+
+<tbody>
+<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 the active driver.</para><para>If it is, test if the driver has a configurator function and is able to be reconfigured. A good result here will call the configurator and return a 0.</para><para>For an entry with a different driver name, scan all available drivers to see if the wanted one is there. An unmatched name exits, returning 0.</para><para>If we got a match, get the baudrate for the device with <function>gpsd_assert_sync()</function>, probe for the subtype if we have one.</para><para>If the device has a configurator and is reconfigurable, trigger the configurator.</para><para>Return a 1 to indicate a device switch.</para></entry>
+</row>
+<row>
+ <entry><function>void gpsd_init(struct gps_device_t *session, struct gps_context_t *context, char *device)</function></entry>
+ <entry><para>Copy the device name to the session data structure, initialise important data fields and call <function>gpsd_tty_init()</function>, <function>gpsd_zero_satellites()</function> and <function>packet_reset()</function>.</para></entry>
+</row>
+<row>
+ <entry><function>void gpsd_deactivate(struct gps_device_t *session)</function></entry>
+ <entry><para>Release the NTPD resources, including the 1PPS resourecs if they are active.</para><para>If the device has a revert function, trigger it.</para><para>If it has an NMEA mode switcher, invoke it.</para><para>If it has a wrapup routine, invoke it.</para><para>Finally, close the device.</para></entry>
+</row>
+<row>
+ <entry><function>static void *gpsd_ppsmonitor(void *arg)</function></entry>
+ <entry><para>An <function>ioctl()</function> call is made which returns either 0 if the status of the port changed, or an error.</para><para>If we got a change, we read the modem control bits and extract the 1PPS information.</para><para>We check the returned value and see if it has changed recently. A counter of 10 unchanged events will disable further testing.</para><para>If we are still hanging in there, we now see if we already have had more than 4 good fixes, otherwise we can't trust the 1PPS.</para><para>We then finally test the pulse duration. If it is either a genuine 1PPS or a 2Hz squarewave, we call <function>ntpshm_pps()</function>.</para><para>Short or long PPS pulses are dropped with an error report.</para></entry>
+</row>
+<row>
+ <entry><function>int gpsd_activate(struct gps_device_t *session, bool reconfigurable)</function></entry>
+ <entry><para>Try and open the device, returning -1 if we fail.</para><para>Probe all possible drivers to see if one recognises the device.</para><para>Set some fundamental data to a clean value.</para><para>Handle the initialisation of NTP and 1PPS functions if needed.</para><para>If we did succeed in probing some device type, try and get the subtype.</para><para>If we need to do so, we now configure the device.</para><para>Finally, signal success by returning the file descriptor given by the device open call.</para></entry>
+</row>
+<row>
+ <entry><function>char *gpsd_id(struct gps_device_t *session)</function></entry>
+ <entry><para>If the device type is known, return it along with, where appropriate, the subtype. If the data is not available, return <quote>unknown</quote>.</para></entry>
+</row>
+<row>
+ <entry><function>static double degtodm(double a)</function></entry>
+ <entry><para>Converts a fractional degree value (like 125.3567) into an NMEA field as dddmm.xxx (like 12521.402).</para></entry>
+</row>
+<row>
+ <entry><function>void gpsd_position_fix_dump(struct gps_device_t *session, /char bufp[], size_t len)</function></entry>
+ <entry><para>If possible, create a $GPGGA message (full time, position and fix data) from the fix data, taking care about the validity of subsidiary fields like HDOP and altitude.</para></entry>
+</row>
+<row>
+ <entry><function>static void gpsd_transit_fix_dump(struct gps_device_t *session, char bufp[], size_t len)</function></entry>
+ <entry><para>Create a $GPRMC message (minimum navigation data) from the fix data.</para></entry>
+</row>
+<row>
+ <entry><function>static void gpsd_binary_fix_dump(struct gps_device_t *session, char bufp[], size_t len)</function></entry>
+ <entry><para>Make a call to <function>gpsd_position_fix_dump()</function> and <function>gpsd_transit_fix_dump()</function>.</para></entry>
+</row>
+<row>
+ <entry><function>static void gpsd_binary_satellite_dump(struct gps_device_t *session, char bufp[], size_t len)</function></entry>
+ <entry><para>Create one or more $GPGSV messages from the status data of all satellites we know about.</para></entry>
+</row>
+<row>
+ <entry><function>static void gpsd_binary_quality_dump(struct gps_device_t *session, char bufp[], size_t len)</function></entry>
+ <entry><para>Create a $GPGSA message taking care that if any xDOP is not valid, we substitute a <quote>0.0</quote> value.</para><para>If any of the error estimates is available, generate a $PGRME message again taking care about possibly invalid values.</para></entry>
+</row>
+<row>
+ <entry><function>static void gpsd_binary_dump(struct gps_device_t *session, char bufp[], size_t len)</function></entry>
+ <entry><para>Dump such binary data as we have available; a fix, a quality value and a satellite status block. Each is enabled by the approriate status bits in the session mask variable.</para></entry>
+</row>
+<row>
+ <entry><function>void gpsd_error_model(struct gps_device_t *session, struct gps_fix_t *fix, struct gps_fix_t *oldfix)</function></entry>
+ <entry><para>Check we have a 2D fix (or better) and if the gps didn't provide an eph value, use the HDOP to calculate one or fail to NAN.</para><para>Do the same with epv/VDOP if we have a 3D or better fix.</para><para>Do the same with epe/PDOP.</para><para>Consider speed error; check if we have two fixes with differing timestamps and use their times and eph values to calculate the speed.</para><para>If we have two valid 3D fixes, we can calculate the climb/sink rate.</para><para>Finally, just before exiting, save this fix as the old fix for the next comparison round.</para></entry>
+</row>
+<row>
+ <entry><function>gps_mask_t gpsd_poll(struct gps_device_t *session)</function></entry>
+ <entry><para>Make a call to <function>gps_clear_fix()</function> to prepare the data structure.</para><para>Check if we know the device type. If we do, stash the count of of characters we are able to get from it.</para><para>If the read has given a full packet, we can call the subtype probing method, if the device supports it.</para><para>If we don't know the device type, try and figure out what it is, exiting if we can't.</para><para>Make some checks if the device is offline or the packet is incomplete, using the stashed count of characters and the full packet indicator.</para><para>If a full packet is available, we try to get the fix data and update the main data stucture. We also compute the DOPs so we can fill them in if they are not included in the gps device output.</para><para>Finally, send the data to any clients who need raw mode data.</para></entry>
+</row>
+<row>
+ <entry><function>void gpsd_wrap(struct gps_device_t *session)</function></entry>
+ <entry><para>Simple call to <function>gpsd_deactivate(session)</function>.</para></entry>
+</row>
+<row>
+ <entry><function>void gpsd_zero_satellites(struct gps_data_t *out)</function></entry>
+ <entry><para>Zero the status data for all satellites.</para></entry>
+</row>
+</tbody>
+
+<tfoot>
+<row>
+ <entry spanname='s1' align='left'>Notes based on <function>$Id: libgpsd_core.c 4284 2007-01-27 07:27:42Z ckuethe $</function></entry>
+</row>
+</tfoot>
+
+</tgroup>
+</informaltable>
+</sect1>
diff --git a/doc/explan_libgpsmm.cpp.xml b/doc/explan_libgpsmm.cpp.xml
new file mode 100644
index 00000000..41627d45
--- /dev/null
+++ b/doc/explan_libgpsmm.cpp.xml
@@ -0,0 +1,22 @@
+<sect1 id="libgpsmm.cpp"><title><filename>libgpsmm.cpp</filename></title>
+<informaltable frame='all' pgwide='1'>
+<tgroup cols='1'>
+<colspec colname='c1'></colspec>
+<colspec colname='c2'></colspec>
+<spanspec spanname='s1' namest='c1' nameend='c2'></spanspec>
+
+<tbody>
+<row>
+ <entry><para>C++ class wrapper for the <function>libgps</function> C binding.</para></entry>
+</row>
+</tbody>
+
+<tfoot>
+<row>
+ <entry spanname='s1' align='left'>Notes based on <function>$Id: libgpsmm.cpp 4219 2007-01-05 17:44:07Z ckuethe $</function></entry>
+</row>
+</tfoot>
+
+</tgroup>
+</informaltable>
+</sect1>
diff --git a/doc/explan_libgpsmm.h.xml b/doc/explan_libgpsmm.h.xml
new file mode 100644
index 00000000..c13b3d9e
--- /dev/null
+++ b/doc/explan_libgpsmm.h.xml
@@ -0,0 +1,22 @@
+<sect1 id="libgpsmm.h"><title><filename>libgpsmm.h</filename></title>
+<informaltable frame='all' pgwide='1'>
+<tgroup cols='1'>
+<colspec colname='c1'></colspec>
+<colspec colname='c2'></colspec>
+<spanspec spanname='s1' namest='c1' nameend='c2'></spanspec>
+
+<tbody>
+<row>
+ <entry><para>Headers for <function>libgpsmm.cpp</function>.</para></entry>
+</row>
+</tbody>
+
+<tfoot>
+<row>
+ <entry spanname='s1' align='left'>Notes based on <function>$Id: libgpsmm.h 3666 2006-10-26 23:11:51Z ckuethe $</function></entry>
+</row>
+</tfoot>
+
+</tgroup>
+</informaltable>
+</sect1>
diff --git a/doc/explan_netlib.c.xml b/doc/explan_netlib.c.xml
new file mode 100644
index 00000000..08724c4c
--- /dev/null
+++ b/doc/explan_netlib.c.xml
@@ -0,0 +1,29 @@
+<sect1 id="netlib.c"><title><filename>netlib.c</filename></title>
+<informaltable frame='all' pgwide='1'>
+<tgroup cols='2'>
+<colspec colname='c1'></colspec>
+<colspec colname='c2'></colspec>
+<spanspec spanname='s1' namest='c1' nameend='c2'></spanspec>
+
+<thead>
+<row>
+ <entry>Functions:-</entry><entry>This provides socket connectivity.</entry>
+</row>
+</thead>
+
+<tbody>
+<row>
+ <entry><function>int netlib_connectsock(const char *host, const char *service, const char *protocol)</function></entry>
+ <entry><para>This attempts to connect the to nominated service on the nominated host using the nominated protocol. On success, the return value is the socket number. On error, an appropriate system defined error code is returned.</para></entry>
+</row>
+</tbody>
+
+<tfoot>
+<row>
+ <entry spanname='s1' align='left'>Notes based on <function>$Id: netlib.c 4264 2007-01-22 15:53:33Z ckuethe $</function></entry>
+</row>
+</tfoot>
+
+</tgroup>
+</informaltable>
+</sect1>
diff --git a/doc/explan_nmea_parse.c.xml b/doc/explan_nmea_parse.c.xml
new file mode 100644
index 00000000..630ea54d
--- /dev/null
+++ b/doc/explan_nmea_parse.c.xml
@@ -0,0 +1,85 @@
+<sect1 id="nmea_parse.c"><title><filename>nmea_parse.c</filename></title>
+<informaltable frame='all' pgwide='1'>
+<tgroup cols='2'>
+<colspec colname='c1'></colspec>
+<colspec colname='c2'></colspec>
+<spanspec spanname='s1' namest='c1' nameend='c2'></spanspec>
+
+<thead>
+<row>
+ <entry>Functions:-</entry><entry>Parser for NMEA strings, generic and proprietary.</entry>
+</row>
+</thead>
+
+<tbody>
+<row>
+ <entry><function>static void do_lat_lon(char *field[], struct gps_data_t *out)</function></entry>
+ <entry><para>Reads a four element array containing the value and hemisphere of the latitude and longitude of a location as text. It converts them into signed (-ve for S and W) values and if they are not the same as the values in the <function>gps_data_t</function> structure, it is updated with the new value(s).</para></entry>
+</row>
+<row>
+ <entry><function>static void merge_ddmmyy(char *ddmmyy, struct gps_device_t *session)</function></entry>
+ <entry><para>If the century has not yet been stored in the nmea driver private data, take the supplied ddmmyy date and generate and store a ddmmyyyy date, using the century value compiled in from <function>timebase.h</function>.</para></entry>
+</row>
+<row>
+ <entry><function>static void merge_hhmmss(char *hhmmss, struct gps_device_t *session)</function></entry>
+ <entry><para>Stash the present hour value before updating it from the incoming data. If the new hour is less than the stashed value, we have passed midnight, so update the day value. Finally update the minutes, seconds and fractions of a second from the incoming data.</para></entry>
+</row>
+<row>
+ <entry><function>static gps_mask_t processGPRMC(int count, char *field[], struct gps_device_t *session)</function></entry>
+ <entry><para>Handle a $GPRMC sentence stored in an array of strings, one member per field.</para><para>Check if the message is stamped valid or not.</para><para>If it is invalid, set the status and fix mode to NO_FIX and save the corresponding flags locally; also save the online flag so we know we have handled a known sentence.</para><para>If the fix is autonomous and valid, start to decode the fields.</para><para>First, test if there are enough fields available; then handle the date and time via <function>merge_ddmmyy()</function> and <function>merge_hhmmss()</function>, storing the TIME_SET flag and storing the fix time as a UNIX-epoch relative value.</para><para>If the sentence time and this fix time are different, we have started a new cycle of observation, so update the sentence time and the store the CYCLE_START_SET flag.</para><para>Whatever the number of fields, store the fix co-ordinates via <function>do_lat_lon()</function>, store the speed and the track and save the corresponding flags.</para><para>Return the local aggregated flags to allow the main copy in the session data to be updated.</para></entry>
+</row>
+<row>
+ <entry><function>static gps_mask_t processGPGLL(int count, char *field[], struct gps_device_t *session)</function></entry>
+ <entry><para>Preload the local flag with the ERROR_SET flag.</para><para>Check that the sentence is usable, exiting with the preset error flag if it is not.</para><para>If it is usable, clear the local flags and start processing the fields, updating any local flag fields on the way.</para><para>If the year is already known, update the time and check for the start of cycle (see <function>processGPRMC()</function> above).</para><para>Handle the fix location and, if the number of received fixes is more than 8 and the status is differential, stash the new status as STATUS_DGPS_FIX; otherwise stash STATUS_FIX.</para><para>If the present mode is less than 2D_FIX, update it to 2D_FIX.</para><para>Update the status to the stashed value of newstatus and return all the locally aggregated flags.</para></entry>
+</row>
+<row>
+ <entry><function>static gps_mask_t processGPGGA(int c UNUSED, char *field[], struct gps_device_t *session)</function></entry>
+ <entry><para>Stash the last fix time. Set the status to the value in the message and update the local flag variable.</para><para>If the status is STATUS_NO_FIX, exit immediately, returning the locally aggregated flags. If there is a fix, process it.</para><para>Handle the time as in <function>processGPGLL()</function> above. Handle the latitiude and longitude with a call to <function>do_lat_lon()</function> above and set the local flag.</para><para>Update the <function>satellites_used</function> field and stash the altitude.</para><para>If the altitude is empty, force the fix mode and status to 2D if it was 3D previously.</para><para>If it is not empty, stash the old value of altitude and replace it with the new value stashed earlier and set the local flag variable. If the mode is presently less than 3D, update it to 3D and set the local flag.</para><para>If the stashed old altitude is NaN or the stashed fix time and current fix time are equal, set the climb rate to 0 otherwise calculate it by dividing the altitude difference by the time difference and set the local flag.</para><para>If the geoid separation is available, store it, otherwise store the value from <function>wgs84_separation()</function> that depends on current location.</para><para>Finally, return all the locally aggregated flags.</para></entry>
+</row>
+<row>
+ <entry><function>static gps_mask_t processGPGSA(int count, char *field[], struct gps_device_t *session)</function></entry>
+ <entry><para>Start with a simple validity check on the number of fields (for i.Trek M3) and bail out with a simple indication of on-line status if it fails.</para><para>Set the fix mode from the sentence and either clear the local flag variable (if an Antaris chipset says we are in dead-reckoning mode) or set the MODE_SET flag.</para><para>Update all the DOP fields from the sentence, clear the count of used satellites, then scan all the satellite data.</para><para>If any satellite is good (prn != 0), store the prn and increment the count of used satellites.</para><para>Finally, set the local flags to indicate that DOPs are available and return all the locally aggregated flags.</para></entry>
+</row>
+<row>
+ <entry><function>static gps_mask_t processGPGSV(int count, char *field[], struct gps_device_t *session)</function></entry>
+ <entry><para>Check if the sentence has too few fields or the wrong number fo fields. In this case, clear the data for all satellites and return with an error indication.</para><para>Start to parse the sentence. First, note how many sentences are to be expected to complete the data transfer.</para><para>If the sentence number is invalid, clear the data for all satellites and return with an error indication.</para><para>If this is the first sentence of the sequence, clear the data for all satellites.</para><para>Loop through the sentence fields, updating the session's satellite data.</para><para>If any satellite number is higher than the number of channels, clear all satellite data and break out of the loop.</para><para>Assuming this is not a buggy chipset (e.g. Motorola Oncore GT+), update the satellite count and loop again.</para><para>If this was the last sentence of the block and the number of satellites seen is not the same as the number reported, generate an error log.</para><para>If this is not the last sentence of the block, exit early and return an error flag as a guard.</para><para>Finally, on the last sentence, carry out a sanity check and either return an error flag or a SATELLITE_SET flag.</para></entry>
+</row>
+<row>
+ <entry><function>static gps_mask_t processPGRME(int c UNUSED, char *field[], struct gps_device_t *session)</function></entry>
+ <entry><para>Check that the error estimate data is good. If not, set all error estimate fields to 100m and return an error flag.</para><para>If they are good, calcluate the error value and store it. Return the approriate flag values.</para></entry>
+</row>
+<row>
+ <entry><function>static gps_mask_t processGPZDA(int c UNUSED, char *field[], struct gps_device_t *session)</function></entry>
+ <entry><para>Set the local flag variable to indicate that the time is available.</para><para>Store the actual time by a call to <function>merge_hhmmss()</function> and fill in the other fields from the sentence data.</para><para>If the sentence is not timestamped the same as the fixtime, update the fixtime and set the CYCLE_START_SET flag.</para><para>Finally, return all the locally aggregated flags.</para></entry>
+</row>
+<row>
+ <entry><function>static gps_mask_t processTNTHTM(int c UNUSED, char *field[], struct gps_device_t *session)</function></entry>
+ <entry><para>Set the local variable to indicate the the unit is on-line.</para><para>Fill all appropriate fields from the sentence and set the associated flags in the local flag variable.</para><para>Set the fix status and freturn all the locally aggregated flags.</para></entry>
+</row>
+<row>
+ <entry><function>static short nmea_checksum(char *sentence, unsigned char *correct_sum)</function></entry>
+ <entry><para>Calcluate and return the checksum of an NMEA sentence.</para></entry>
+</row>
+<row>
+ <entry><function>gps_mask_t nmea_parse(char *sentence, struct gps_device_t *session)</function></entry>
+ <entry><para>Take an NMEA sentence and check the checksum with <function>nmea_checksum()</function> (note:- this is switched off at the moment).</para><para>Test the length is acceptable, retuning an on-line indication if it is too long to handle.</para><para>If it is within limits, make a local copy and split it on the commas into an array, one field per element.</para><para>Use the first element to match the command to the table of decodable commands.</para><para>If it is supported and the number of fields is reasonable, invoke the correct decoder and return the value from that call.</para><para>If it fails the testing, return an on-line status.</para></entry>
+</row>
+<row>
+ <entry><function>void nmea_add_checksum(char *sentence)</function></entry>
+ <entry><para>Calcluate the checksum then insert a '*', the checksum and CR+LF into the end of an NMEA Sentence, skipping any existing '*'.</para></entry>
+</row>
+<row>
+ <entry><function>int nmea_send(int fd, const char *fmt, ... )</function></entry>
+ <entry><para>Read the incoming data into a buffer, reserving the last 5 bytes (at least) for the terminating data.</para><para>If the buffer starts with a '$', asssume it is an NMEA sentence and call nmea_add_checksum; otherwise, just add a CR+LF.</para><para>Write the buffer to the device, stashing the byte count returned. Wait until all output is sent.</para><para>Check the returned value against the number of bytes in the buffer. If they are equal, return the stashed count. If not, return -1.</para></entry>
+</row>
+</tbody>
+
+<tfoot>
+<row>
+ <entry spanname='s1' align='left'>Notes based on <function>$Id: nmea_parse.c 4306 2007-03-15 06:33:17Z ckuethe $</function></entry>
+</row>
+</tfoot>
+
+</tgroup>
+</informaltable>
+</sect1>
diff --git a/doc/explan_ntpshm.c.xml b/doc/explan_ntpshm.c.xml
new file mode 100644
index 00000000..88ff86de
--- /dev/null
+++ b/doc/explan_ntpshm.c.xml
@@ -0,0 +1,49 @@
+<sect1 id="ntpshm.c"><title><filename>ntpshm.c</filename></title>
+<informaltable frame='all' pgwide='1'>
+<tgroup cols='2'>
+<colspec colname='c1'></colspec>
+<colspec colname='c2'></colspec>
+<spanspec spanname='s1' namest='c1' nameend='c2'></spanspec>
+
+<thead>
+<row>
+ <entry>Functions:-</entry><entry>This puts time information into a shared memory segment for the ntp daemon to use.</entry>
+</row>
+</thead>
+
+<tbody>
+<row>
+ <entry><function>static struct shmTime *getShmTime(int unit)</function></entry>
+ <entry><para>This requests a block of shared memory to communicate to the ntp daemon. It returns a pointer to the memory on success or NULL on failure.</para></entry>
+</row>
+<row>
+ <entry><function>void ntpshm_init(struct gps_context_t *context, bool enablepps)</function></entry>
+ <entry><para>Attaches all ntp shared memeory segments.</para></entry>
+</row>
+<row>
+ <entry><function>int ntpshm_alloc(struct gps_context_t *context)</function></entry>
+ <entry><para>This allocates a free ntp shared memory segment.</para><para>If one is available, initialise it for use and flag it as in use.</para><para>Returns the segment number on success or -1 on failure.</para></entry>
+</row>
+<row>
+ <entry><function>bool ntpshm_free(struct gps_context_t *context, int segment)</function></entry>
+ <entry><para>This releases a previously allocated ntp shared memory segment. Indicates the outcome by returning true (success) or false.</para></entry>
+</row>
+<row>
+ <entry><function>int ntpshm_put(struct gps_device_t *session, double fixtime)</function></entry>
+ <entry><para>If the shared memory index allocated to the session is valid and the <function>shmTime</function> structure of the session is valid, store the time of the fix.</para><para>Success is indicated by a return value of 1 and errors are indicated by a return value of 0.</para></entry>
+</row>
+<row>
+ <entry><function>int ntpshm_pps(struct gps_device_t *session, struct timeval *tv)</function></entry>
+ <entry><para>Only available if the 1PPS function is compiled in.</para><para>Checks if the shared memory structures are valid. If so, it validates that the time received is within the locking range.</para><para>If good, the time is stored in the shared memory.</para><para>A return value of 1 indicates successful update; 0 indicates there is a problem with the shared memory structures and -1 indicates that the time could not be locked to.</para></entry>
+</row>
+</tbody>
+
+<tfoot>
+<row>
+ <entry spanname='s1' align='left'>Notes based on <function>$Id: ntpshm.c 3771 2006-11-02 05:15:20Z esr $</function></entry>
+</row>
+</tfoot>
+
+</tgroup>
+</informaltable>
+</sect1>
diff --git a/doc/explan_ntrip.c.xml b/doc/explan_ntrip.c.xml
new file mode 100644
index 00000000..27e42269
--- /dev/null
+++ b/doc/explan_ntrip.c.xml
@@ -0,0 +1,57 @@
+<sect1 id="ntrip.c"><title><filename>ntrip.c</filename></title>
+<informaltable frame='all' pgwide='1'>
+<tgroup cols='2'>
+<colspec colname='c1'></colspec>
+<colspec colname='c2'></colspec>
+<spanspec spanname='s1' namest='c1' nameend='c2'></spanspec>
+
+<thead>
+<row>
+ <entry>Functions:-</entry><entry>Gather and dispatch DGNSS data from Ntrip broadcasters.</entry>
+</row>
+</thead>
+
+<tbody>
+<row>
+ <entry><function>static char *ntrip_field_iterate(char *start, char *prev, const char *eol)</function></entry>
+ <entry><para>Extract individual fields from the STR data block using ';' as the separator but handling string-embedded ';' characters correctly.</para></entry>
+</row>
+<row>
+ <entry><function>static void ntrip_str_parse(char *str, size_t len, struct ntrip_stream_t *hold)</function></entry>
+ <entry><para>Break an STR data block down using <function>ntrip_field_iterate()</function> and store the relevant details in an accumulation buffer.</para></entry>
+</row>
+<row>
+ <entry><function>static int ntrip_sourcetable_parse(int fd, char *buf, ssize_t blen, const char *stream, struct ntrip_stream_t *keep)</function></entry>
+ <entry><para>Parse a block of ntrip data by passing the STR data to <function>ntrip_str_parse()</function>.</para><para>Return a 0 on success or -1 on any of the many possible failures.</para></entry>
+</row>
+<row>
+ <entry><function>static int ntrip_stream_probe(const char *caster, const char *port, const char *stream, struct ntrip_stream_t *keep)</function></entry>
+ <entry><para>Send a request to the broadcaster for a block of correction data.</para><para>If successful, return the result of parsing the table. On error return -1.</para></entry>
+</row>
+<row>
+ <entry><function>static int ntrip_auth_encode(const struct ntrip_stream_t *stream, const char *auth, char buf[], size_t size)</function></entry>
+ <entry><para>Check the authorisation of the stream and return 0 if there is none or it is basic. Return -1 in all other cases.</para></entry>
+</row>
+<row>
+ <entry><function>static int ntrip_stream_open(const char *caster, const char *port, const char *auth, struct gps_context_t *context, struct ntrip_stream_t *stream)</function></entry>
+ <entry><para>Check the authorisation of the stream and if successful, try to connect.</para><para>On connection, try to read data and test for various errors.</para><para>On success, return the socket number, on error return -1.</para></entry>
+</row>
+<row>
+ <entry><function>int ntrip_open(struct gps_context_t *context, char *caster)</function></entry>
+ <entry><para>Try to establish a connection to the ntrip server. On success, return the socket number. Signal error with a return of -1.</para></entry>
+</row>
+<row>
+ <entry><function>void ntrip_report(struct gps_device_t *session)</function></entry>
+ <entry><para>If we have not contacted the server already and we have at least 10 fixes, send a report to the server and set the flag, so we don't do it again.</para></entry>
+</row>
+</tbody>
+
+<tfoot>
+<row>
+ <entry spanname='s1' align='left'>Notes based on <function>$Id: ntrip.c 3771 2006-11-02 05:15:20Z esr $</function></entry>
+</row>
+</tfoot>
+
+</tgroup>
+</informaltable>
+</sect1>
diff --git a/doc/explan_packet.c.xml b/doc/explan_packet.c.xml
new file mode 100644
index 00000000..d459d714
--- /dev/null
+++ b/doc/explan_packet.c.xml
@@ -0,0 +1,57 @@
+<sect1 id="packet.c"><title><filename>packet.c</filename></title>
+<informaltable frame='all' pgwide='1'>
+<tgroup cols='2'>
+<colspec colname='c1'></colspec>
+<colspec colname='c2'></colspec>
+<spanspec spanname='s1' namest='c1' nameend='c2'></spanspec>
+
+<thead>
+<row>
+ <entry>Functions:-</entry><entry>The packet-sniffing engine for reading data packets from GPS devices.</entry>
+</row>
+</thead>
+
+<tbody>
+<row>
+ <entry><function>static void nextstate(struct gps_packet_t *lexer, unsigned char c)</function></entry>
+ <entry><para>This is the main parser loop. It scans the character against the definitions of all the packet structures known to <application>gpsd</application> and, if possible, sets a new packet state.</para><para>If the state is <quote>xxx_RECOGNIZED</quote>, the packet_parse routine will despatch the packet to the appropriate driver.</para></entry>
+</row>
+<row>
+ <entry><function>static void packet_accept(struct gps_packet_t *lexer, int packet_type)</function></entry>
+ <entry><para>This shifts a packet that has been recognized into the output buffer, provided it is not bigger than the buffer.</para></entry>
+</row>
+<row>
+ <entry><function>static void packet_discard(struct gps_packet_t *lexer)</function></entry>
+ <entry><para>This clears a handled packet out of the the input buffer.</para></entry>
+</row>
+<row>
+ <entry><function>static void character_discard(struct gps_packet_t *lexer)</function></entry>
+ <entry><para>This is called if the <function>nextstate()</function> function returns <quote>GROUND_STATE</quote>.</para><para>In this case the character does not match any pattern, so to discard it, the input buffer is shifted back by one character to overwrite the <quote>bad</quote> character.</para></entry>
+</row>
+<row>
+ <entry><function>ssize_t packet_parse(struct gps_packet_t *lexer, size_t fix)</function></entry>
+ <entry><para>Call the <function>nextstate()</function> function to process the available data and set the recognition state correctly. Return the number of characters handled.</para></entry>
+</row>
+<row>
+ <entry><function>ssize_t packet_get(int fd, struct gps_packet_t *lexer)</function></entry>
+ <entry><para>Reads raw data from the input port. Returns the number of characters read (0 or more) or BAD_PACKET if there was an error in reading. Errors <errortype>EAGAIN</errortype> and <errortype>EINTR</errortype> are not classed as failures and cause a return of 0.</para></entry>
+</row>
+<row>
+ <entry><function>void packet_reset(struct gps_packet_t *lexer)</function></entry>
+ <entry><para>This simply resets the entire packet state machine to the ground state.</para></entry>
+</row>
+<row>
+ <entry><function>void packet_pushback(struct gps_packet_t *lexer)</function></entry>
+ <entry><para>This pushes back the last packet from the output buffer to the input buffer, provided doing so would not overflow the input buffer.</para></entry>
+</row>
+</tbody>
+
+<tfoot>
+<row>
+ <entry spanname='s1' align='left'>Notes based on <function>$Id: packet.c 4299 2007-03-11 19:51:22Z ckuethe $</function></entry>
+</row>
+</tfoot>
+
+</tgroup>
+</informaltable>
+</sect1>
diff --git a/doc/explan_packet_names.h.xml b/doc/explan_packet_names.h.xml
new file mode 100644
index 00000000..407468c9
--- /dev/null
+++ b/doc/explan_packet_names.h.xml
@@ -0,0 +1,22 @@
+<sect1 id="packet_names.h"><title><filename>packet_names.h</filename></title>
+<informaltable frame='all' pgwide='1'>
+<tgroup cols='1'>
+<colspec colname='c1'></colspec>
+<colspec colname='c2'></colspec>
+<spanspec spanname='s1' namest='c1' nameend='c2'></spanspec>
+
+<tbody>
+<row>
+ <entry><para>This is a file generated by the <quote>make</quote> process from <function>packet_states.h</function>. It takes all the state names in that file and surrounds them with speech marks. These values are read into a table of packet names, <function>state_table[]</function>, in <function>packet.c</function>.</para></entry>
+</row>
+</tbody>
+
+<tfoot>
+<row>
+ <entry spanname='s1' align='left'>Notes based on <function>$Id: packet_names.h 4231 2007-01-11 02:06:56Z ckuethe $</function></entry>
+</row>
+</tfoot>
+
+</tgroup>
+</informaltable>
+</sect1>
diff --git a/doc/explan_packet_states.h.xml b/doc/explan_packet_states.h.xml
new file mode 100644
index 00000000..df3e9e60
--- /dev/null
+++ b/doc/explan_packet_states.h.xml
@@ -0,0 +1,19 @@
+<sect1 id="packet_states.h"><title><filename>packet_states.h</filename></title>
+<informaltable frame='all' pgwide='1'>
+<tgroup cols='1'>
+
+<tbody>
+<row>
+ <entry><para>This is a list of every possible state generated by every driver. The inclusion of each driver's states is controlled by <function>#ifdef</function> blocks, so we only include the states for drivers selected for compilation. These form an enumeration list in <function>packet.c</function> which indexes the <function>state_table[]</function> array mentioned in <function>packet_names.h</function>.</para></entry>
+</row>
+</tbody>
+
+<tfoot>
+<row>
+ <entry spanname='s1' align='left'>Notes based on <function>$Id: packet_states.h 4299 2007-03-11 19:51:22Z ckuethe $</function></entry>
+</row>
+</tfoot>
+
+</tgroup>
+</informaltable>
+</sect1>
diff --git a/doc/explan_report.c.xml b/doc/explan_report.c.xml
new file mode 100644
index 00000000..83fbd1d0
--- /dev/null
+++ b/doc/explan_report.c.xml
@@ -0,0 +1,29 @@
+<sect1 id="report.c"><title><filename>report.c</filename></title>
+<informaltable frame='all' pgwide='1'>
+<tgroup cols='2'>
+<colspec colname='c1'></colspec>
+<colspec colname='c2'></colspec>
+<spanspec spanname='s1' namest='c1' nameend='c2'></spanspec>
+
+<thead>
+<row>
+ <entry>Functions:-</entry><entry>General string output routine for any module to use.</entry>
+</row>
+</thead>
+
+<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 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 runtime.</para></entry>
+</row>
+</tbody>
+
+<tfoot>
+<row>
+ <entry spanname='s1' align='left'>Notes based on <function>$Id: report.c 3666 2006-10-26 23:11:51Z ckuethe $</function></entry>
+</row>
+</tfoot>
+
+</tgroup>
+</informaltable>
+</sect1>
diff --git a/doc/explan_rtcm.c.xml b/doc/explan_rtcm.c.xml
new file mode 100644
index 00000000..690dc323
--- /dev/null
+++ b/doc/explan_rtcm.c.xml
@@ -0,0 +1,57 @@
+<sect1 id="rtcm.c"><title><filename>rtcm.c</filename></title>
+<informaltable frame='all' pgwide='1'>
+<tgroup cols='2'>
+<colspec colname='c1'></colspec>
+<colspec colname='c2'></colspec>
+<spanspec spanname='s1' namest='c1' nameend='c2'></spanspec>
+
+<thead>
+<row>
+ <entry>Functions:-</entry><entry>This is a decoder for the RTCM-104 serial protocol.</entry>
+</row>
+</thead>
+
+<tbody>
+<row>
+ <entry><function>void rtcm_unpack(struct rtcm_t *tp, char *buf)</function></entry>
+ <entry><para>Splits RTCM raw data into fields.</para></entry>
+</row>
+<row>
+ <entry><function>bool rtcm_repack(struct rtcm_t *tp, isgps30bits_t *buf)</function></entry>
+ <entry><para>Packs RTCM fields into a raw data stream.</para></entry>
+</row>
+<row>
+ <entry><function>static bool preamble_match(isgps30bits_t *w)</function></entry>
+ <entry><para>Tells if the preamble field in a message is valid or not.</para></entry>
+</row>
+<row>
+ <entry><function>static bool length_check(struct gps_packet_t *lexer)</function></entry>
+ <entry><para>Tells if the message length is valid or not.</para></entry>
+</row>
+<row>
+ <entry><function>enum isgpsstat_t rtcm_decode(struct gps_packet_t *lexer, unsigned int c)</function></entry>
+ <entry><para>A simple call to <function>isgps_decode()</function>.</para></entry>
+</row>
+<row>
+ <entry><function>void rtcm_dump(struct rtcm_t *rtcm, char buf[], size_t buflen)</function></entry>
+ <entry><para>Dump the contents of a parsed RTCM104 message.</para></entry>
+</row>
+<row>
+ <entry><function>int rtcm_undump(struct rtcm_t *rtcmp, char *buf)</function></entry>
+ <entry><para>Merge a line of data into an RTCM structure, return 0 if done.</para></entry>
+</row>
+<row>
+ <entry><function>void rtcm_output_magnavox(isgps30bits_t *ip, FILE *fp)</function></entry>
+ <entry><para>Ship an RTCM message in the format emitted by Magnavox DGPS receivers.</para></entry>
+</row>
+</tbody>
+
+<tfoot>
+<row>
+ <entry spanname='s1' align='left'>Notes based on <function>$Id: rtcm.c 4065 2006-12-04 05:31:59Z esr $</function></entry>
+</row>
+</tfoot>
+
+</tgroup>
+</informaltable>
+</sect1>
diff --git a/doc/explan_serial.c.xml b/doc/explan_serial.c.xml
new file mode 100644
index 00000000..8901b318
--- /dev/null
+++ b/doc/explan_serial.c.xml
@@ -0,0 +1,66 @@
+<sect1 id="serial.c"><title><filename>serial.c</filename></title>
+<informaltable frame='all' pgwide='1'>
+<tgroup cols='2'>
+<colspec colname='c1'></colspec>
+<colspec colname='c2'></colspec>
+<spanspec spanname='s1' namest='c1' nameend='c2'></spanspec>
+
+<thead>
+<row>
+ <entry>Functions:-</entry><entry>This provides serial port handling services to the daemon. It handles the tricky task of scanning for and changing port parameters, especially baudrate.</entry>
+</row>
+</thead>
+
+<tbody>
+<row>
+ <entry><function>void gpsd_tty_init(struct gps_device_t *session)</function></entry>
+ <entry><para>To be called on allocating a device. Mark GPS fd closed and its baud rate unknown.</para></entry>
+</row>
+<row>
+ <entry><function>void cfmakeraw(struct termios *termios_p)</function></entry>
+ <entry><para>Workaround for Cygwin, which is missing <function>cfmakeraw()</function>. It is pasted from man page and added in <function>serial.c</function> arbitrarily.</para></entry>
+</row>
+<row>
+ <entry><function>speed_t gpsd_get_speed(struct termios* ttyctl)</function></entry>
+ <entry><para>Calls <function>cfgetospeed()</function> and returns the baud rate, if known. Default otherwise is 115200.</para></entry>
+</row>
+<row>
+ <entry><function>bool gpsd_set_raw(struct gps_device_t *session)</function></entry>
+ <entry><para>Tries to set port to raw mode and returns success or not.</para></entry>
+</row>
+<row>
+ <entry><function>void gpsd_set_speed(struct gps_device_t *session, speed_t speed, unsigned char parity, unsigned int stopbits)</function></entry>
+ <entry><para>Sets the speed, parity and stopbits.</para><para>Lots of black magic fiddling goes on to ensure the port is flushed on the baud rate change and wakeup strings are fired off just in case the device needs prodding into life.</para><para>READ THE CODE AND COMMENTS!!!</para></entry>
+</row>
+<row>
+ <entry><function>int gpsd_open(struct gps_device_t *session)</function></entry>
+ <entry><para>Test the device and flag it as R/W if it is a character device, or R/O if it isn't.</para><para>Try to open it in non-blocking and no-control mode.</para><para>If that fails, try again, adding read-only mode. If that also fails, exit with an error.</para><para>On no error, force the saved baudrate if we have a fixed port speed (typically embedded devices). Check if we have a saved baudrate and if so, activate it.</para><para>Preset the packet type to BAD_PACKET.</para><para>Check if the device we have opened is a tty. If it is a tty, read the original terminal paramters.</para><para>Exit with an error code -1 on failure to do so.</para><para>Save the old parameters, set important control flags, then set the speed.</para><para>Finally, return the allocated fd.</para></entry>
+</row>
+<row>
+ <entry><function>bool gpsd_write(struct gps_device_t *session, void const *buf, size_t len)</function></entry>
+ <entry><para>Try to write <function>len</function> characters to the device. waiting until all data has been sent.</para><para>If the write was successful (number of bytes written = <function>len</function>), return <quote>true</quote>, othewise return <quote>false</quote>.</para></entry>
+</row>
+<row>
+ <entry><function>bool gpsd_next_hunt_setting(struct gps_device_t *session)</function></entry>
+ <entry><para>Check if we have had SNIFF_RETRIES attempts at current baudrate. If not, return <quote>true</quote>.</para><para>If we have exceeded the limit, reset the counter and see if there are any more rates to try at.</para><para>If no (fixed baudrate or all attempts exhausted), return <quote>false</quote>, otherwise, set the next speed and return <quote>true</quote>.</para></entry>
+</row>
+<row>
+ <entry><function>void gpsd_assert_sync(struct gps_device_t *session)</function></entry>
+ <entry><para>To be called when we want to register that we've synced with a device. We've achieved first sync with the device. Remember the baudrate so we can try it first next time this device is opened.</para></entry>
+</row>
+<row>
+ <entry><function>void gpsd_close(struct gps_device_t *session)</function></entry>
+ <entry><para>If there is an active fd, check if it is a tty device. If it is, force the baudrate to 0 (should terminate the connection and de-assert control lines).</para><para>
+Set the HUPCL flag in the original data, write the old data to the port, close the fd and clear that fd number from the session data.</para></entry>
+</row>
+</tbody>
+
+<tfoot>
+<row>
+ <entry spanname='s1' align='left'>Notes based on <function>$Id: serial.c 4302 2007-03-14 02:27:45Z ckuethe $</function></entry>
+</row>
+</tfoot>
+
+</tgroup>
+</informaltable>
+</sect1>
diff --git a/doc/explan_subframe.c.xml b/doc/explan_subframe.c.xml
new file mode 100644
index 00000000..3e186dcd
--- /dev/null
+++ b/doc/explan_subframe.c.xml
@@ -0,0 +1,29 @@
+<sect1 id="subframe.c"><title><filename>subframe.c</filename></title>
+<informaltable frame='all' pgwide='1'>
+<tgroup cols='2'>
+<colspec colname='c1'></colspec>
+<colspec colname='c2'></colspec>
+<spanspec spanname='s1' namest='c1' nameend='c2'></spanspec>
+
+<thead>
+<row>
+ <entry>Functions:-</entry><entry>This code interprets satellite RTCM-104 subframe data.</entry>
+</row>
+</thead>
+
+<tbody>
+<row>
+ <entry><function>void gpsd_interpret_subframe(struct gps_device_t *session,unsigned int words[])</function></entry>
+ <entry><para>Extracts leap-second from RTCM-104 subframe data.</para></entry>
+</row>
+</tbody>
+
+<tfoot>
+<row>
+ <entry spanname='s1' align='left'>Notes based on <function>$Id: subframe.c 3770 2006-11-02 05:07:11Z esr $</function></entry>
+</row>
+</tfoot>
+
+</tgroup>
+</informaltable>
+</sect1>
diff --git a/doc/explan_timebase.h.xml b/doc/explan_timebase.h.xml
new file mode 100644
index 00000000..307bdf43
--- /dev/null
+++ b/doc/explan_timebase.h.xml
@@ -0,0 +1,37 @@
+<sect1 id="timebase.h"><title><filename>timebase.h</filename></title>
+<informaltable frame='all' pgwide='1'>
+<tgroup cols='2'>
+<colspec colname='c1'></colspec>
+<colspec colname='c2'></colspec>
+<spanspec spanname='s1' namest='c1' nameend='c2'></spanspec>
+
+<thead>
+<row>
+ <entry>Functions:-</entry><entry>Contains date and time related constants that will require patching over time.</entry>
+</row>
+</thead>
+
+<tbody>
+<row>
+ <entry><function>LEAP_SECONDS</function></entry>
+ <entry><para>Currently 14</para></entry>
+</row>
+<row>
+ <entry><function>START_SUBFRAME</function></entry>
+ <entry><para>Currently 1183262400 or 1 Jun 2007 00:00:00</para></entry>
+</row>
+<row>
+ <entry><function>CENTURY_BASE</function></entry>
+ <entry><para>Currently 2000</para></entry>
+</row>
+</tbody>
+
+<tfoot>
+<row>
+ <entry spanname='s1' align='left'>Notes based on <function>$Id: timebase.h 4040 2006-12-01 03:41:42Z esr $</function></entry>
+</row>
+</tfoot>
+
+</tgroup>
+</informaltable>
+</sect1>
diff --git a/doc/explan_wrapup.xml b/doc/explan_wrapup.xml
new file mode 100644
index 00000000..9e833538
--- /dev/null
+++ b/doc/explan_wrapup.xml
@@ -0,0 +1,6 @@
+<sect1 id="signoff">
+<para>Mick Durkin
+&lt;mick.durkin@saunalahti.fi&gt;</para>
+<para>Helsinki</para>
+<para>March 2007</para>
+</sect1>
diff --git a/doc/explanation.xml b/doc/explanation.xml
new file mode 100644
index 00000000..d51cc9a9
--- /dev/null
+++ b/doc/explanation.xml
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE article PUBLIC
+ "-//OASIS//DTD DocBook XML V4.1.2//EN"
+ "docbook/docbookx.dtd" [
+<!ENTITY homepage "http://gpsd.berlios.de">
+<!ENTITY bits.h SYSTEM "explan_bits.h.xml">
+<!ENTITY dgnss.c SYSTEM "explan_dgnss.c.xml">
+<!ENTITY dgpsip.c SYSTEM "explan_dgpsip.c.xml">
+<!ENTITY driver_proto.c SYSTEM "explan_driver_proto.c.xml">
+<!ENTITY drivers.c SYSTEM "explan_drivers.c.xml">
+<!ENTITY geoid.c SYSTEM "explan_geoid.c.xml">
+<!ENTITY gpsd.c SYSTEM "explan_gpsd.c.xml">
+<!ENTITY gpsd.h SYSTEM "explan_gpsd.h.xml">
+<!ENTITY gpsd_dbus.c SYSTEM "explan_gpsd_dbus.c.xml">
+<!ENTITY gps.h SYSTEM "explan_gps.h.xml">
+<!ENTITY gpsutils.c SYSTEM "explan_gpsutils.c.xml">
+<!ENTITY isgps.c SYSTEM "explan_isgps.c.xml">
+<!ENTITY libgps.c SYSTEM "explan_libgps.c.xml">
+<!ENTITY libgpsd_core.c SYSTEM "explan_libgpsd_core.c.xml">
+<!ENTITY libgpsmm.cpp SYSTEM "explan_libgpsmm.cpp.xml">
+<!ENTITY libgpsmm.h SYSTEM "explan_libgpsmm.h.xml">
+<!ENTITY netlib.c SYSTEM "explan_netlib.c.xml">
+<!ENTITY nmea_parse.c SYSTEM "explan_nmea_parse.c.xml">
+<!ENTITY ntpshm.c SYSTEM "explan_ntpshm.c.xml">
+<!ENTITY ntrip.c SYSTEM "explan_ntrip.c.xml">
+<!ENTITY packet.c SYSTEM "explan_packet.c.xml">
+<!ENTITY packet_names.h SYSTEM "explan_packet_names.h.xml">
+<!ENTITY packet_states.h SYSTEM "explan_packet_states.h.xml">
+<!ENTITY report.c SYSTEM "explan_report.c.xml">
+<!ENTITY rtcm.c SYSTEM "explan_rtcm.c.xml">
+<!ENTITY serial.c SYSTEM "explan_serial.c.xml">
+<!ENTITY subframe.c SYSTEM "explan_subframe.c.xml">
+<!ENTITY timebase.h SYSTEM "explan_timebase.h.xml">
+<!ENTITY wrapup SYSTEM "explan_wrapup.xml">
+]>
+<article>
+<title>Notes on the structure of the code in the GPSD Driver</title>
+<articleinfo>
+<author>
+ <firstname>Mick</firstname>
+ <surname>Durkin</surname>
+</author>
+<revhistory>
+ <revision>
+ <revnumber>1.0</revnumber>
+ <date>20 March 2007</date>
+ <authorinitials>md</authorinitials>
+ <revremark>Initial draft</revremark>
+ </revision>
+</revhistory>
+
+<abstract>
+<para>These notes are meant as an aid to reading and understanding some of the main code files forming the <application>gpsd</application> daemon and its support libraries. They are not a line-by-line explanation but only pick out the important (or unusual) aspects of the code.</para><para>They do not address the many programs that are used for test purposes, the individual device driver files or any of the supplied applications that use <application>gpsd</application>.</para>
+</abstract>
+
+</articleinfo>
+
+&bits.h;
+&dgnss.c;
+&dgpsip.c;
+&driver_proto.c;
+&drivers.c;
+&geoid.c;
+&gpsd.c;
+&gpsd.h;
+&gpsd_dbus.c;
+&gps.h;
+&gpsutils.c;
+&isgps.c;
+&libgps.c;
+&libgpsd_core.c;
+&libgpsmm.cpp;
+&libgpsmm.h;
+&netlib.c;
+&nmea_parse.c;
+&ntpshm.c;
+&ntrip.c;
+&packet.c;
+&packet_names.h;
+&packet_states.h;
+&report.c;
+&rtcm.c;
+&serial.c;
+&subframe.c;
+&timebase.h;
+&wrapup;
+</article> \ No newline at end of file