summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--HACKING25
-rw-r--r--README10
-rw-r--r--Tachometer.c2
-rw-r--r--em.c122
-rw-r--r--gps.c12
-rw-r--r--gpsd.c59
-rw-r--r--gpsd.h19
-rw-r--r--netlib.c32
-rw-r--r--nmea.h8
-rw-r--r--outdata.h2
-rw-r--r--send_nmea.c4
-rw-r--r--serial.c14
-rw-r--r--tm.c24
-rw-r--r--xgpsspeed.c14
14 files changed, 187 insertions, 160 deletions
diff --git a/HACKING b/HACKING
new file mode 100644
index 00000000..f5c68be0
--- /dev/null
+++ b/HACKING
@@ -0,0 +1,25 @@
+ Hacker's Guide to gpsd
+
+This is not a complicated piece of code. Essentially, it spins in a loop
+polling for input from one of three sources:
+
+1) The GPS, connected via serial or USB device.
+
+2) A client making requests over a TCP/IP port.
+
+4) A DGPS server issuing periodic differential-GPS updates.
+
+GPS input updates an internal data structure called gNMEAdata, which has
+slots in it for all the data you can get from a GPS. Client commands mine
+that structure and ship reports up the socket to the client. DGPS data is
+passed through, raw, to the GPS
+
+The program supports multiple GPS types. All are represented by
+driver method tables; the main loop knows nothing about the driver
+methods except when to call them. At any given time one driver is
+active; by default it's the NMEA one. A driver may change the active
+type, in which case the new driver's initializer method should be
+called before processing goes any forther.
+
+That's about all there is to it.
+
diff --git a/README b/README
index dd5c94c5..5f763a0d 100644
--- a/README
+++ b/README
@@ -33,11 +33,15 @@ I have a boat connected to the internet (Ricochet modem) running
gpsd, the maping program runs here at home (no, I will not give
you the boats IP address :-)
-There is a sample client included. It is called "gps". It simply connects
-to a gpsd and displays satellites in their current position in the sky.
-This only works for some GPS receivers!
+There is a GPS tester included. It is called "gps". It simply connects
+to a GPS and displays your latitude, longitude, altitude, and the signal
+quality from visible satellites. When querying NMEA-compliant GPSes, it
+will show a diagram of satellites in their current position in the sky.
+It uses the same library code as gpsd.
gpsd is tested with DeLorme's TripMate, EarthMate and Garmin units.
+Also with the BU-303 USB GPS sold as the NaviLock, Deluo, and Hyperdata.
+
CREDITS
diff --git a/Tachometer.c b/Tachometer.c
index 7f8ba77f..9443e957 100644
--- a/Tachometer.c
+++ b/Tachometer.c
@@ -9,7 +9,7 @@
* author's name is retained. The author assumes no responsibility for lost
* sleep as a consequence of use of this software.
*
- * Send any comments, bug reports, etc. to shutoh@isl.yamaha.JUNET
+ * Send any comments, bug gpscli_reports, etc. to shutoh@isl.yamaha.JUNET
*
*
* Modifications : ilham@mit.edu (July 10 '90)
diff --git a/em.c b/em.c
index 33bb9997..e2d795fc 100644
--- a/em.c
+++ b/em.c
@@ -45,7 +45,7 @@ struct header {
static void analyze(struct header *, unsigned short *, fd_set *, fd_set *);
-static unsigned short em_checksum(unsigned short *w, int n)
+static unsigned short em_gps_checksum(unsigned short *w, int n)
{
unsigned short csum = 0;
@@ -56,8 +56,8 @@ static unsigned short em_checksum(unsigned short *w, int n)
}
/* em_spew - Takes a message type, an array of data words, and a length
- for the array, and prepends a 5 word header (including checksum).
- The data words are expected to be checksummed */
+ for the array, and prepends a 5 word header (including gps_checksum).
+ The data words are expected to be gps_checksummed */
#if defined (WORDS_BIGENDIAN)
@@ -93,7 +93,7 @@ static void em_spew(int type, unsigned short *dat, int dlen)
h.sync = 0x81ff;
h.id = type;
h.ndata = dlen - 1;
- h.csum = em_checksum((unsigned short *) &h, 4);
+ h.csum = em_gps_checksum((unsigned short *) &h, 4);
if (session.fdout != -1) {
end_write(session.fdout, &h, sizeof(h));
@@ -147,7 +147,7 @@ static void em_init()
*(long *) (data + 13) = putlong(session.initpos.longitude, (session.initpos.lond == 'W') ? 1 : 0);
data[15] = data[16] = 0;
data[17] = data[18] = data[19] = data[20] = 0;
- data[21] = em_checksum(data, 21);
+ data[21] = em_gps_checksum(data, 21);
em_spew(1200, data, 22);
}
@@ -165,7 +165,7 @@ static void send_rtcm(char *rtcmbuf, int rtcmbytes)
data[0] = sn; /* sequence number */
memcpy(&data[1], rtcmbuf, rtcmbytes);
- data[n] = em_checksum(data, n);
+ data[n] = em_gps_checksum(data, n);
em_spew(1351, data, n+1);
}
@@ -216,28 +216,28 @@ static double degtodm(double a)
static void handle1000(unsigned short *p)
{
#if 0
- report(1, "date: %d %d %d %d:%d:%d\n",
+ gpscli_report(1, "date: %d %d %d %d:%d:%d\n",
p[O(19)], p[O(20)], p[O(21)], p[O(22)], p[O(23)], p[O(24)]);
- report(1, " solution invalid:\n");
- report(1, " altitude: %d\n", (p[O(10)] & 1) ? 1 : 0);
- report(1, " no diff gps: %d\n", (p[O(10)] & 2) ? 1 : 0);
- report(1, " not enough satellites: %d\n", (p[O(10)] & 4) ? 1 : 0);
- report(1, " exceed max EHPE: %d\n", (p[O(10)] & 8) ? 1 : 0);
- report(1, " exceed max EVPE: %d\n", (p[O(10)] & 16) ? 1 : 0);
- report(1, " solution type:\n");
- report(1, " propagated: %d\n", (p[O(11)] & 1) ? 1 : 0);
- report(1, " altitude: %d\n", (p[O(11)] & 2) ? 1 : 0);
- report(1, " differential: %d\n", (p[O(11)] & 4) ? 1 : 0);
- report(1, "Number of measurements in solution: %d\n", p[O(12)]);
- report(1, "Lat: %f\n", 180.0 / (PI / ((double) getlong(p + O(27)) / 100000000)));
- report(1, "Lon: %f\n", 180.0 / (PI / ((double) getlong(p + O(29)) / 100000000)));
- report(1, "Alt: %f\n", (double) getlong(p + O(31)) / 100.0);
- report(1, "Speed: %f\n", (double) getlong(p + O(34)) / 100.0) * 1.94387;
- report(1, "Map datum: %d\n", p[O(39)]);
- report(1, "Magnetic variation: %f\n", p[O(37)] * 180 / (PI * 10000));
- report(1, "Course: %f\n", (p[O(36)] * 180 / (PI * 1000)));
- report(1, "Separation: %f\n", (p[O(33)] / 100));
+ gpscli_report(1, " solution invalid:\n");
+ gpscli_report(1, " altitude: %d\n", (p[O(10)] & 1) ? 1 : 0);
+ gpscli_report(1, " no diff gps: %d\n", (p[O(10)] & 2) ? 1 : 0);
+ gpscli_report(1, " not enough satellites: %d\n", (p[O(10)] & 4) ? 1 : 0);
+ gpscli_report(1, " exceed max EHPE: %d\n", (p[O(10)] & 8) ? 1 : 0);
+ gpscli_report(1, " exceed max EVPE: %d\n", (p[O(10)] & 16) ? 1 : 0);
+ gpscli_report(1, " solution type:\n");
+ gpscli_report(1, " propagated: %d\n", (p[O(11)] & 1) ? 1 : 0);
+ gpscli_report(1, " altitude: %d\n", (p[O(11)] & 2) ? 1 : 0);
+ gpscli_report(1, " differential: %d\n", (p[O(11)] & 4) ? 1 : 0);
+ gpscli_report(1, "Number of measurements in solution: %d\n", p[O(12)]);
+ gpscli_report(1, "Lat: %f\n", 180.0 / (PI / ((double) getlong(p + O(27)) / 100000000)));
+ gpscli_report(1, "Lon: %f\n", 180.0 / (PI / ((double) getlong(p + O(29)) / 100000000)));
+ gpscli_report(1, "Alt: %f\n", (double) getlong(p + O(31)) / 100.0);
+ gpscli_report(1, "Speed: %f\n", (double) getlong(p + O(34)) / 100.0) * 1.94387;
+ gpscli_report(1, "Map datum: %d\n", p[O(39)]);
+ gpscli_report(1, "Magnetic variation: %f\n", p[O(37)] * 180 / (PI * 10000));
+ gpscli_report(1, "Course: %f\n", (p[O(36)] * 180 / (PI * 1000)));
+ gpscli_report(1, "Separation: %f\n", (p[O(33)] / 100));
#endif
sprintf(session.gNMEAdata.utc, "%02d/%02d/%d %02d:%02d:%02d",
@@ -292,13 +292,13 @@ static void handle1002(unsigned short *p)
session.gNMEAdata.Zs[i] = p[O(16 + (3 * i))];
session.gNMEAdata.Zv[i] = (p[O(15 + (3 * i))] & 0xf);
#if 0
- report(1, "Sat%02d:", i);
- report(1, " used:%d", (p[O(15 + (3 * i))] & 1) ? 1 : 0);
- report(1, " eph:%d", (p[O(15 + (3 * i))] & 2) ? 1 : 0);
- report(1, " val:%d", (p[O(15 + (3 * i))] & 4) ? 1 : 0);
- report(1, " dgps:%d", (p[O(15 + (3 * i))] & 8) ? 1 : 0);
- report(1, " PRN:%d", p[O(16 + (3 * i))]);
- report(1, " C/No:%d\n", p[O(17 + (3 * i))]);
+ gpscli_report(1, "Sat%02d:", i);
+ gpscli_report(1, " used:%d", (p[O(15 + (3 * i))] & 1) ? 1 : 0);
+ gpscli_report(1, " eph:%d", (p[O(15 + (3 * i))] & 2) ? 1 : 0);
+ gpscli_report(1, " val:%d", (p[O(15 + (3 * i))] & 4) ? 1 : 0);
+ gpscli_report(1, " dgps:%d", (p[O(15 + (3 * i))] & 8) ? 1 : 0);
+ gpscli_report(1, " PRN:%d", p[O(16 + (3 * i))]);
+ gpscli_report(1, " C/No:%d\n", p[O(17 + (3 * i))]);
#endif
for (j = 0; j < 12; j++) {
if (session.gNMEAdata.PRN[j] != p[O(16 + (3 * i))])
@@ -326,11 +326,11 @@ static void handle1003(unsigned short *p)
session.gNMEAdata.azimuth[j] = p[O(16 + (3 * j))] * 180 / (PI * 10000);
session.gNMEAdata.elevation[j] = p[O(17 + (3 * j))] * 180 / (PI * 10000);
#if 0
- report(1, "Sat%02d:", i);
- report(1, " PRN:%d", p[O(15 + (3 * i))]);
- report(1, " az:%d", p[O(16 + (3 * i))]);
- report(1, " el:%d", p[O(17 + (3 * i))]);
- report(1, "\n");
+ gpscli_report(1, "Sat%02d:", i);
+ gpscli_report(1, " PRN:%d", p[O(15 + (3 * i))]);
+ gpscli_report(1, " az:%d", p[O(16 + (3 * i))]);
+ gpscli_report(1, " el:%d", p[O(17 + (3 * i))]);
+ gpscli_report(1, "\n");
#endif
} else {
session.gNMEAdata.PRN[j] = 0;
@@ -346,20 +346,20 @@ static void handle1005(unsigned short *p)
int numcorrections = p[O(12)];
#if 1
- report(1, "Station bad: %d\n", (p[O(9)] & 1) ? 1 : 0);
- report(1, "User disabled: %d\n", (p[O(9)] & 2) ? 1 : 0);
- report(1, "Station ID: %d\n", p[O(10)]);
- report(1, "Age of last correction in seconds: %d\n", p[O(11)]);
- report(1, "Number of corrections: %d\n", p[O(12)]);
+ gpscli_report(1, "Station bad: %d\n", (p[O(9)] & 1) ? 1 : 0);
+ gpscli_report(1, "User disabled: %d\n", (p[O(9)] & 2) ? 1 : 0);
+ gpscli_report(1, "Station ID: %d\n", p[O(10)]);
+ gpscli_report(1, "Age of last correction in seconds: %d\n", p[O(11)]);
+ gpscli_report(1, "Number of corrections: %d\n", p[O(12)]);
for (i = 0; i < numcorrections; i++) {
- report(1, "Sat%02d:", p[O(13+i)] & 0x3f);
- report(1, "ephemeris:%d", (p[O(13+i)] & 64) ? 1 : 0);
- report(1, "rtcm corrections:%d", (p[O(13+i)] & 128) ? 1 : 0);
- report(1, "rtcm udre:%d", (p[O(13+i)] & 256) ? 1 : 0);
- report(1, "sat health:%d", (p[O(13+i)] & 512) ? 1 : 0);
- report(1, "rtcm sat health:%d", (p[O(13+i)] & 1024) ? 1 : 0);
- report(1, "corrections state:%d", (p[O(13+i)] & 2048) ? 1 : 0);
- report(1, "iode mismatch:%d", (p[O(13+i)] & 4096) ? 1 : 0);
+ gpscli_report(1, "Sat%02d:", p[O(13+i)] & 0x3f);
+ gpscli_report(1, "ephemeris:%d", (p[O(13+i)] & 64) ? 1 : 0);
+ gpscli_report(1, "rtcm corrections:%d", (p[O(13+i)] & 128) ? 1 : 0);
+ gpscli_report(1, "rtcm udre:%d", (p[O(13+i)] & 256) ? 1 : 0);
+ gpscli_report(1, "sat health:%d", (p[O(13+i)] & 512) ? 1 : 0);
+ gpscli_report(1, "rtcm sat health:%d", (p[O(13+i)] & 1024) ? 1 : 0);
+ gpscli_report(1, "corrections state:%d", (p[O(13+i)] & 2048) ? 1 : 0);
+ gpscli_report(1, "iode mismatch:%d", (p[O(13+i)] & 4096) ? 1 : 0);
}
#endif
}
@@ -371,9 +371,9 @@ static void analyze(struct header *h, unsigned short *p, fd_set * afds, fd_set *
char *bufp2;
int i = 0, j = 0, nmea = 0;
- if (p[h->ndata] == em_checksum(p, h->ndata)) {
+ if (p[h->ndata] == em_gps_checksum(p, h->ndata)) {
if (session.debug > 5)
- report(1, "id %d\n", h->id);
+ gpscli_report(1, "id %d\n", h->id);
switch (h->id) {
case 1000:
handle1000(p);
@@ -388,7 +388,7 @@ static void analyze(struct header *h, unsigned short *p, fd_set * afds, fd_set *
((session.gNMEAdata.longitude > 0) ? 'E' : 'W'),
session.gNMEAdata.mode, session.gNMEAdata.satellites, session.gNMEAdata.hdop,
session.gNMEAdata.altitude, 'M', session.gNMEAdata.separation, 'M', "", "");
- add_checksum(bufp + 1);
+ gps_add_checksum(bufp + 1);
bufp = bufp + strlen(bufp);
}
sprintf(bufp,
@@ -401,7 +401,7 @@ static void analyze(struct header *h, unsigned short *p, fd_set * afds, fd_set *
session.gNMEAdata.course, session.gNMEAdata.day, session.gNMEAdata.month,
(session.gNMEAdata.year % 100), session.gNMEAdata.mag_var,
(session.gNMEAdata.mag_var > 0) ? 'E' : 'W');
- add_checksum(bufp + 1);
+ gps_add_checksum(bufp + 1);
nmea = 1000;
break;
case 1002:
@@ -423,7 +423,7 @@ static void analyze(struct header *h, unsigned short *p, fd_set * afds, fd_set *
bufp = bufp + strlen(bufp);
sprintf(bufp, "%.2f,%.2f,%.2f*", session.gNMEAdata.pdop, session.gNMEAdata.hdop,
session.gNMEAdata.vdop);
- add_checksum(bufp2 + 1);
+ gps_add_checksum(bufp2 + 1);
bufp2 = bufp = bufp + strlen(bufp);
sprintf(bufp, "$PRWIZCH");
bufp = bufp + strlen(bufp);
@@ -433,7 +433,7 @@ static void analyze(struct header *h, unsigned short *p, fd_set * afds, fd_set *
}
sprintf(bufp, "*");
bufp = bufp + strlen(bufp);
- add_checksum(bufp2 + 1);
+ gps_add_checksum(bufp2 + 1);
nmea = 1002;
break;
case 1003:
@@ -453,7 +453,7 @@ static void analyze(struct header *h, unsigned short *p, fd_set * afds, fd_set *
bufp += strlen(bufp);
if (i % 4 == 3) {
sprintf(bufp, "*");
- add_checksum(bufp2 + 1);
+ gps_add_checksum(bufp2 + 1);
bufp += strlen(bufp);
bufp2 = bufp;
}
@@ -468,9 +468,9 @@ static void analyze(struct header *h, unsigned short *p, fd_set * afds, fd_set *
}
if (nmea > 0) {
if (session.debug > 4)
- report(1, "%s", buf);
+ gpscli_report(1, "%s", buf);
- send_nmea(afds, nmea_fds, buf);
+ gps_send_NMEA(afds, nmea_fds, buf);
}
if (eminit)
@@ -538,7 +538,7 @@ static void em_eat(unsigned char c, fd_set * afds, fd_set * nmea_fds)
case EM_HUNT_CS:
if (!(byte = putword(&(h.csum), c, byte))) {
- if (h.csum == em_checksum((unsigned short *) &h, 4)) {
+ if (h.csum == em_gps_checksum((unsigned short *) &h, 4)) {
state = EM_HUNT_DATA;
data = (unsigned short *) malloc((h.ndata + 1) * 2);
words = 0;
diff --git a/gps.c b/gps.c
index d123f9c9..ec9e231b 100644
--- a/gps.c
+++ b/gps.c
@@ -94,11 +94,11 @@ extern void redraw();
void quit_cb()
{
- serial_close();
+ gps_close();
exit(0);
}
-void report(int errlevel, const char *fmt, ... )
+void gpscli_report(int errlevel, const char *fmt, ... )
/* assemble command in printf(3) style, use stderr or syslog */
{
char buf[BUFSIZ];
@@ -320,7 +320,7 @@ static void handle_input(XtPointer client_data, int *source, XtInputId * id)
if (buf[offset] == '\n') {
if (buf[offset - 1] == '\r')
buf[offset - 1] = '\0';
- nmea_handle_message(buf);
+ gps_NMEA_handle_message(buf);
update_display(buf);
offset = 0;
return;
@@ -399,7 +399,7 @@ static void open_input(XtAppContext app)
int input = 0;
XtInputId input_id;
- input = serial_open(device_name, device_speed);
+ input = gps_open(device_name, device_speed);
session.fdin = input;
session.fdout = input;
@@ -537,9 +537,9 @@ int main(int argc, char *argv[])
}
-void errexit(char *s)
+void gps_gpscli_errexit(char *s)
{
perror(s);
- serial_close();
+ gps_close();
exit(1);
}
diff --git a/gpsd.c b/gpsd.c
index c958a932..508ca4c0 100644
--- a/gpsd.c
+++ b/gpsd.c
@@ -67,9 +67,9 @@ static int handle_request(int fd, fd_set * fds);
static void onsig(int sig)
{
- serial_close();
+ gps_close();
close(dsock);
- report(1, "Received signal %d. Exiting...\n", sig);
+ gpscli_report(1, "Received signal %d. Exiting...\n", sig);
exit(10 + sig);
}
@@ -109,7 +109,7 @@ static int daemonize()
return 0;
}
-void report(int errlevel, const char *fmt, ... )
+void gpscli_report(int errlevel, const char *fmt, ... )
/* assemble command in printf(3) style, use stderr or syslog */
{
char buf[BUFSIZ];
@@ -207,11 +207,11 @@ static int handle_dgps()
if ((rtcmbytes=read(dsock,buf,BUFSIZE))>0 && (session.fdout!=-1))
{
if (session.device_type->rctm_writer(buf, rtcmbytes) <= 0)
- report(1, "Write to rtcm sink failed\n");
+ gpscli_report(1, "Write to rtcm sink failed\n");
}
else
{
- report(1, "Read from rtcm source failed\n");
+ gpscli_report(1, "Read from rtcm source failed\n");
}
return rtcmbytes;
@@ -221,10 +221,10 @@ static void deactivate()
{
session.fdin = -1;
session.fdout = -1;
- serial_close();
+ gps_close();
if (session.device_type->wrapup)
session.device_type->wrapup();
- report(1, "closed GPS\n");
+ gpscli_report(1, "closed GPS\n");
session.gNMEAdata.mode = 1;
session.gNMEAdata.status = 0;
}
@@ -233,10 +233,10 @@ static int activate()
{
int input;
- if ((input = serial_open(device_name, device_speed ? device_speed : session.device_type->baudrate)) < 0)
- errexit("Exiting - serial open\n");
+ if ((input = gps_open(device_name, device_speed ? device_speed : session.device_type->baudrate)) < 0)
+ gps_gpscli_errexit("Exiting - serial open\n");
- report(1, "opened GPS\n");
+ gpscli_report(1, "opened GPS\n");
session.fdin = input;
session.fdout = input;
@@ -342,9 +342,9 @@ int main(int argc, char *argv[])
signal(SIGPIPE, SIG_IGN);
openlog("gpsd", LOG_PID, LOG_USER);
- report(1, "gpsd started (Version %s)\n", VERSION);
- msock = passiveTCP(service, QLEN);
- report(1, "gpsd listening on port %s\n", service);
+ gpscli_report(1, "gpsd started (Version %s)\n", VERSION);
+ msock = netlib_passiveTCP(service, QLEN);
+ gpscli_report(1, "gpsd listening on port %s\n", service);
nfds = getdtablesize();
@@ -358,9 +358,9 @@ int main(int argc, char *argv[])
if (!getservbyname(dgpsport, "tcp"))
dgpsport = "2101";
- dsock = connectsock(dgpsserver, dgpsport, "tcp");
+ dsock = netlib_connectsock(dgpsserver, dgpsport, "tcp");
if (dsock < 0)
- errexit("Can't connect to dgps server");
+ gps_gpscli_errexit("Can't connect to dgps server");
gethostname(hn, sizeof(hn));
@@ -393,7 +393,7 @@ int main(int argc, char *argv[])
if (select(nfds, &rfds, NULL, NULL, &tv) < 0) {
if (errno == EINTR)
continue;
- errexit("select");
+ gps_gpscli_errexit("select");
}
need_gps = 0;
@@ -415,7 +415,7 @@ int main(int argc, char *argv[])
ssock = accept(msock, (struct sockaddr *) &fsin, &alen);
if (ssock < 0)
- errlog("accept");
+ gpscli_report(0, "accept: %s\n", strerror(errno));
else FD_SET(ssock, &afds);
}
@@ -465,7 +465,7 @@ static int validate(void)
{
if ((session.gNMEAdata.status == STATUS_NO_FIX) != (session.gNMEAdata.mode == MODE_NO_FIX))
{
- report(0, "GPS is confused about whether it has a fix (status=%d, mode=%d).\n", session.gNMEAdata.status, session.gNMEAdata.mode);
+ gpscli_report(0, "GPS is confused about whether it has a fix (status=%d, mode=%d).\n", session.gNMEAdata.status, session.gNMEAdata.mode);
return 0;
}
return 1;
@@ -486,10 +486,10 @@ static int handle_request(int fd, fd_set * fds)
buf[cc] = '\0';
if (session.debug >= 2)
- report(1, "<= client: %s", buf);
+ gpscli_report(1, "<= client: %s", buf);
cur_time = time(NULL);
-#define STALE_COMPLAINT(l, f) report(1, l " data is stale: %ld + %d >= %ld\n", session.gNMEAdata.f.last_refresh, session.gNMEAdata.f.time_to_live, cur_time)
+#define STALE_COMPLAINT(l, f) gpscli_report(1, l " data is stale: %ld + %d >= %ld\n", session.gNMEAdata.f.last_refresh, session.gNMEAdata.f.time_to_live, cur_time)
sprintf(reply, "GPSD");
p = buf;
@@ -660,23 +660,23 @@ static int handle_request(int fd, fd_set * fds)
strcat(reply, "\r\n");
if (session.debug >= 2)
- report(1, "=> client: %s", reply);
+ gpscli_report(1, "=> client: %s", reply);
if (cc && write(fd, reply, strlen(reply) + 1) < 0)
return 0;
return cc;
}
-void send_nmea(fd_set *afds, fd_set *nmea_fds, char *buf)
+void gps_send_NMEA(fd_set *afds, fd_set *nmea_fds, char *buf)
/* write to GPS */
{
int fd;
for (fd = 0; fd < nfds; fd++) {
if (FD_ISSET(fd, nmea_fds)) {
- report(1, "=> GPS: %s", buf);
+ gpscli_report(1, "=> GPS: %s", buf);
if (write(fd, buf, strlen(buf)) < 0) {
- report(1, "Raw write %s", strerror(errno));
+ gpscli_report(1, "Raw write %s", strerror(errno));
FD_CLR(fd, afds);
FD_CLR(fd, nmea_fds);
}
@@ -684,15 +684,10 @@ void send_nmea(fd_set *afds, fd_set *nmea_fds, char *buf)
}
}
-void errlog(char *s)
+void gps_gpscli_errexit(char *s)
{
- report(0, "%s: %s\n", s, strerror(errno));
-}
-
-void errexit(char *s)
-{
- report(0, "%s: %s\n", s, strerror(errno));
- serial_close();
+ gpscli_report(0, "%s: %s\n", s, strerror(errno));
+ gps_close();
close(dsock);
exit(2);
}
diff --git a/gpsd.h b/gpsd.h
index 3d62b955..d0e0428b 100644
--- a/gpsd.h
+++ b/gpsd.h
@@ -38,13 +38,16 @@ extern struct gps_type_t earthmate_a;
extern struct gps_type_t earthmate_b;
extern struct gps_type_t logfile;
-void send_nmea(fd_set *afds, fd_set *nmea_fds, char *buf);
-int serial_open(char *device_name, int device_speed);
-void serial_close();
-void errexit(char *s);
-void errlog(char *s);
-int passiveTCP(char *service, int qlen);
-int connectTCP(char *host, char *service);
-int connectsock(char *host, char *service, char *protocol);
+/* GPS library supplies these */
+void gps_send_NMEA(fd_set *afds, fd_set *nmea_fds, char *buf);
+int gps_open(char *device_name, int device_speed);
+void gps_close();
+int netlib_passiveTCP(char *service, int qlen);
+int netlib_connectTCP(char *host, char *service);
+int netlib_connectsock(char *host, char *service, char *protocol);
+
+/* caller must supply this */
+void gps_gpscli_errexit(char *s);
+
/* gpsd.h ends here */
diff --git a/netlib.c b/netlib.c
index 6083348f..c4c3674a 100644
--- a/netlib.c
+++ b/netlib.c
@@ -44,11 +44,11 @@ int passivesock(char *service, char *protocol, int qlen)
sin.sin_port = htons(ntohs((u_short) pse->s_port));
else if ((sin.sin_port = htons((u_short) atoi(service))) == 0) {
sprintf(mbuf, "Can't get \"%s\" service entry.\n", service);
- errexit(mbuf);
+ gps_gpscli_errexit(mbuf);
}
if ((ppe = getprotobyname(protocol)) == 0) {
sprintf(mbuf, "Can't get \"%s\" protocol entry.\n", protocol);
- errexit(mbuf);
+ gps_gpscli_errexit(mbuf);
}
if (strcmp(protocol, "udp") == 0)
type = SOCK_DGRAM;
@@ -57,30 +57,30 @@ int passivesock(char *service, char *protocol, int qlen)
s = socket(PF_INET, type, ppe->p_proto);
if (s < 0)
- errexit("Can't create socket:");
+ gps_gpscli_errexit("Can't create socket:");
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(one)) == -1) {
sprintf(mbuf, "%s", "Error: SETSOCKOPT SO_REUSEADDR");
- errexit(mbuf);
+ gps_gpscli_errexit(mbuf);
}
if (bind(s, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
sprintf(mbuf, "Can't bind to port %s", service);
- errexit(mbuf);
+ gps_gpscli_errexit(mbuf);
}
if (type == SOCK_STREAM && listen(s, qlen) < 0) {
sprintf(mbuf, "Can't listen on %s port:", service);
- errexit(mbuf);
+ gps_gpscli_errexit(mbuf);
}
return s;
}
-int passiveTCP(char *service, int qlen)
+int netlib_passiveTCP(char *service, int qlen)
{
return passivesock(service, "tcp", qlen);
}
-int connectsock(char *host, char *service, char *protocol)
+int netlib_connectsock(char *host, char *service, char *protocol)
{
struct hostent *phe;
struct servent *pse;
@@ -96,17 +96,17 @@ int connectsock(char *host, char *service, char *protocol)
sin.sin_port = htons(ntohs((u_short) pse->s_port));
else if ((sin.sin_port = htons((u_short) atoi(service))) == 0) {
sprintf(mbuf, "Can't get \"%s\" service entry.\n", service);
- errexit(mbuf);
+ gps_gpscli_errexit(mbuf);
}
if ( (phe = gethostbyname(host)) )
bcopy(phe->h_addr, (char *) &sin.sin_addr, phe->h_length);
else if ((sin.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE) {
sprintf(mbuf, "Can't get host entry: \"%s\".\n", host);
- errexit(mbuf);
+ gps_gpscli_errexit(mbuf);
}
if ((ppe = getprotobyname(protocol)) == 0) {
sprintf(mbuf, "Can't get \"%s\" protocol entry.\n", protocol);
- errexit(mbuf);
+ gps_gpscli_errexit(mbuf);
}
if (strcmp(protocol, "udp") == 0)
type = SOCK_DGRAM;
@@ -115,21 +115,21 @@ int connectsock(char *host, char *service, char *protocol)
s = socket(PF_INET, type, ppe->p_proto);
if (s < 0)
- errexit("Can't create socket:");
+ gps_gpscli_errexit("Can't create socket:");
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(one)) == -1) {
sprintf(mbuf, "%s", "Error: SETSOCKOPT SO_REUSEADDR");
- errexit(mbuf);
+ gps_gpscli_errexit(mbuf);
}
if (connect(s, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
sprintf(mbuf, "Can't connect to %s.%s", host, service);
- errexit(mbuf);
+ gps_gpscli_errexit(mbuf);
}
return s;
}
-int connectTCP(char *host, char *service)
+int netlib_connectTCP(char *host, char *service)
{
- return connectsock(host, service, "tcp");
+ return netlib_connectsock(host, service, "tcp");
}
diff --git a/nmea.h b/nmea.h
index 508032bc..1d0416e4 100644
--- a/nmea.h
+++ b/nmea.h
@@ -10,7 +10,7 @@
#define PMGNST "PMGNST"
/* prototypes */
-extern int process_NMEA_message(char *sentence, struct OUTDATA *outdata);
-extern void nmea_handle_message(char *sentence);
-extern void add_checksum(char *sentence);
-extern short checksum(char *sentence);
+extern int gps_process_NMEA_message(char *sentence, struct OUTDATA *outdata);
+extern void gps_NMEA_handle_message(char *sentence);
+extern void gps_add_checksum(char *sentence);
+extern short gps_checksum(char *sentence);
diff --git a/outdata.h b/outdata.h
index 38112efd..ac355108 100644
--- a/outdata.h
+++ b/outdata.h
@@ -81,4 +81,4 @@ struct OUTDATA {
int valid[12]; /* signal valid */
};
-void report(int d, const char *fmt, ...);
+void gpscli_report(int d, const char *fmt, ...);
diff --git a/send_nmea.c b/send_nmea.c
index cf921b10..48fcffda 100644
--- a/send_nmea.c
+++ b/send_nmea.c
@@ -4,10 +4,10 @@
#include "gpsd.h"
-void send_nmea(fd_set *afds, fd_set *nmea_fds, char *buf)
+void gps_send_NMEA(fd_set *afds, fd_set *nmea_fds, char *buf)
{
/* this is a stub. It will be used if the app does
- * not provide a real send_nmea()
+ * not provide a real gps_send_NMEA()
*/
}
diff --git a/serial.c b/serial.c
index b2ff9b16..b6ba0761 100644
--- a/serial.c
+++ b/serial.c
@@ -48,7 +48,7 @@ static int set_baud(long baud)
}
-int serial_open(char *device_name, int device_speed)
+int gps_open(char *device_name, int device_speed)
{
char *temp;
char *p;
@@ -57,27 +57,27 @@ int serial_open(char *device_name, int device_speed)
if ( (p = strchr(temp, ':')) ) {
char *port = DEFAULTPORT;
- report(1, "opening slave daemon at %s\n", device_name);
+ gpscli_report(1, "opening slave daemon at %s\n", device_name);
if (*(p + 1))
port = p + 1;
*p = '\0';
/* temp now holds the HOSTNAME portion and port the port number. */
- ttyfd = connectTCP(temp, port);
+ ttyfd = netlib_connectTCP(temp, port);
port = 0;
if (write(ttyfd, "r\n", 2) != 2)
- errexit("Can't write to socket");
+ gps_gpscli_errexit("Can't write to socket");
} else {
- report(1, "opening GPS data source at %s\n", device_name);
+ gpscli_report(1, "opening GPS data source at %s\n", device_name);
ttyfd = open(temp, O_RDWR | O_NONBLOCK);
if (ttyfd < 0)
return (-1);
if (isatty(ttyfd)) {
- report(1, "setting speed %d, 8 bits, no parity\n", device_speed);
+ gpscli_report(1, "setting speed %d, 8 bits, no parity\n", device_speed);
/* Save original terminal parameters */
if (tcgetattr(ttyfd,&ttyset_old) != 0)
return (-1);
@@ -100,7 +100,7 @@ int serial_open(char *device_name, int device_speed)
return ttyfd;
}
-void serial_close()
+void gps_close()
{
if (ttyfd != -1) {
if (isatty(ttyfd)) {
diff --git a/tm.c b/tm.c
index c6013572..b17ceb88 100644
--- a/tm.c
+++ b/tm.c
@@ -30,16 +30,16 @@ static void process_exception(char *sentence)
{
if (!strncmp("ASTRAL", sentence, 6) && isatty(session.fdout)) {
write(session.fdout, "$IIGPQ,ASTRAL*73\r\n", 18);
- report(1, "found a TripMate, initializing...");
+ gpscli_report(1, "found a TripMate, initializing...");
session.device_type = &tripmate;
tripmate.initializer();
} else if ((!strncmp("EARTHA", sentence, 6) && isatty(session.fdout))) {
write(session.fdout, "EARTHA\r\n", 8);
- report(1, "found an EarthMate (id).");
+ gpscli_report(1, "found an EarthMate (id).");
session.device_type = &earthmate_b;
earthmate_b.initializer();
} else if (session.debug > 1) {
- report(1, "unknown exception: \"%s\"", sentence);
+ gpscli_report(1, "unknown exception: \"%s\"", sentence);
}
}
@@ -50,19 +50,19 @@ static void process_exception(char *sentence)
*
**************************************************************************/
-void nmea_handle_message(char *sentence)
+void gps_NMEA_handle_message(char *sentence)
/* visible so the direct-connect clients can use it */
{
- report(2, "<= GPS: %s\n", sentence);
+ gpscli_report(2, "<= GPS: %s\n", sentence);
if (*sentence == '$')
{
- if (process_NMEA_message(sentence + 1, &session.gNMEAdata) < 0)
- report(2, "Unknown sentence: \"%s\"\n", sentence);
+ if (gps_process_NMEA_message(sentence + 1, &session.gNMEAdata) < 0)
+ gpscli_report(2, "Unknown sentence: \"%s\"\n", sentence);
}
else
process_exception(sentence);
- report(3,
+ gpscli_report(3,
"Lat: %f Lon: %f Alt: %f Sat: %d Mod: %d Time: %s\n",
session.gNMEAdata.latitude,
session.gNMEAdata.longitude,
@@ -84,9 +84,9 @@ static int nmea_handle_input(int input, fd_set *afds, fd_set *nmea_fds)
if (buf[offset] == '\n' || buf[offset] == '\r') {
buf[offset] = '\0';
if (strlen(buf)) {
- nmea_handle_message(buf);
+ gps_NMEA_handle_message(buf);
strcat(buf, "\r\n");
- send_nmea(afds, nmea_fds, buf);
+ gps_send_NMEA(afds, nmea_fds, buf);
}
offset = 0;
return 1;
@@ -147,10 +147,10 @@ void tripmate_initializer()
session.initpos.longitude, session.initpos.lond,
tm->tm_hour, tm->tm_min, tm->tm_sec,
tm->tm_mday, tm->tm_mon + 1, tm->tm_year);
- add_checksum(buf + 1); /* add c-sum + cr/lf */
+ gps_add_checksum(buf + 1); /* add c-sum + cr/lf */
if (session.fdout != -1) {
write(session.fdout, buf, strlen(buf));
- report(1, "=> GPS: %s", buf);
+ gpscli_report(1, "=> GPS: %s", buf);
}
}
}
diff --git a/xgpsspeed.c b/xgpsspeed.c
index 0f7ec86a..efa47489 100644
--- a/xgpsspeed.c
+++ b/xgpsspeed.c
@@ -61,13 +61,13 @@ static void open_input(XtAppContext app);
#undef Offset
-void errexit(char *s)
+void gps_gpscli_errexit(char *s)
{
perror(s);
exit(1);
}
-void report(int errlevel, const char *fmt, ... )
+void gpscli_report(int errlevel, const char *fmt, ... )
/* assemble command in printf(3) style, use stderr or syslog */
{
char buf[BUFSIZ];
@@ -190,7 +190,7 @@ static void handle_input(XtPointer client_data, int *source, XtInputId * id)
if (buf[offset] == '\n') {
if (buf[offset - 1] == '\r')
buf[offset - 1] = '\0';
- nmea_handle_message(buf);
+ gps_NMEA_handle_message(buf);
update_display();
offset = 0;
return;
@@ -199,7 +199,7 @@ static void handle_input(XtPointer client_data, int *source, XtInputId * id)
}
}
-int my_serial_open()
+int my_gps_open()
{
char *temp;
char *port = DEFAULTPORT;
@@ -210,12 +210,12 @@ int my_serial_open()
strcpy(temp, device_name);
/* temp now holds the HOSTNAME portion and port the port number. */
- ttyfd = connectTCP(temp, port);
+ ttyfd = netlib_connectTCP(temp, port);
free(temp);
port = 0;
if (write(ttyfd, "r\n", 2) != 2)
- errexit("Can't write to socket");
+ gps_gpscli_errexit("Can't write to socket");
return ttyfd;
}
@@ -224,7 +224,7 @@ static void open_input(XtAppContext app)
int input = 0;
XtInputId input_id;
- input = my_serial_open();
+ input = my_gps_open();
input_id = XtAppAddInput(app, input, (XtPointer) XtInputReadMask,
handle_input, NULL);