diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2005-05-26 03:31:10 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2005-05-26 03:31:10 +0000 |
commit | cfa56298e82f1a68f3f1e752fc26724cedd96b6a (patch) | |
tree | 811879f99f6075eb74e5b93de6ac9235d5ea2294 | |
parent | 358bb84f5e6e0c4b31a3085c4690cd7c3e633d2c (diff) | |
download | gpsd-cfa56298e82f1a68f3f1e752fc26724cedd96b6a.tar.gz |
Change API so raw_hook takes a length argument; supports dumping binary packets.
-rw-r--r-- | drivers.c | 2 | ||||
-rw-r--r-- | gps.h | 8 | ||||
-rw-r--r-- | gpsd.c | 9 | ||||
-rw-r--r-- | gpsd.h | 2 | ||||
-rw-r--r-- | gpsd.spec.in | 2 | ||||
-rw-r--r-- | gpsd.xml | 20 | ||||
-rw-r--r-- | libgps.c | 9 | ||||
-rw-r--r-- | libgpsd.xml | 3 | ||||
-rw-r--r-- | libgpsd_core.c | 22 | ||||
-rw-r--r-- | libgpsmm.cpp | 2 | ||||
-rw-r--r-- | libgpsmm.h | 2 | ||||
-rw-r--r-- | sirf.c | 5 | ||||
-rw-r--r-- | sirfmon.c | 57 | ||||
-rw-r--r-- | tsip.c | 10 | ||||
-rw-r--r-- | xgpsspeed.c | 2 | ||||
-rw-r--r-- | zodiac.c | 7 |
16 files changed, 72 insertions, 90 deletions
@@ -48,7 +48,7 @@ static int nmea_parse_input(struct gps_device_t *session) #endif /* NTPSHM_ENABLE */ /* also copy the sentence up to clients in raw mode */ - gpsd_raw_hook(session, session->outbuffer, 1); + gpsd_raw_hook(session,session->outbuffer,strlen(session->outbuffer), 1); return st; } else return 0; @@ -159,8 +159,8 @@ struct gps_data_t { /* these members are private */ int gps_fd; /* socket or file descriptor to GPS */ - void (*raw_hook)(struct gps_data_t *, char *, int level);/* Raw-mode hook for GPS data. */ - void (*thread_hook)(struct gps_data_t *, char *, int level);/* Thread-callback hook for GPS data. */ + void (*raw_hook)(struct gps_data_t *, char *, int len, int level);/* Raw-mode hook for GPS data. */ + void (*thread_hook)(struct gps_data_t *, char *, int len, int level);/* Thread-callback hook for GPS data. */ int seen_sentences; /* track which sentences have been seen */ #define GPRMC 0x01 #define GPGGA 0x02 @@ -179,8 +179,8 @@ extern struct gps_data_t *gps_open(const char *host, const char *port); int gps_close(struct gps_data_t *); int gps_query(struct gps_data_t *gpsdata, const char *requests); int gps_poll(struct gps_data_t *gpsdata); -void gps_set_raw_hook(struct gps_data_t *gpsdata, void (*hook)(struct gps_data_t *sentence, char *buf, int level)); -int gps_set_callback(struct gps_data_t *gpsdata, void (*callback)(struct gps_data_t *sentence, char *buf, int level), pthread_t *handler); + void gps_set_raw_hook(struct gps_data_t *gpsdata, void (*hook)(struct gps_data_t *sentence, char *buf, int len, int level)); + int gps_set_callback(struct gps_data_t *gpsdata, void (*callback)(struct gps_data_t *sentence, char *buf, int len, int level), pthread_t *handler); int gps_del_callback(struct gps_data_t *gpsdata, pthread_t *handler); /* some multipliers for interpreting GPS output */ @@ -259,7 +259,7 @@ static int throttled_write(int cfd, char *buf, int len) { int status; - gpsd_report(3, "=> client(%d): %s", cfd, buf); + gpsd_report(3, "=> client(%d): %s", cfd, isprint(buf[0]) ? buf : "UNPRINTABLE\n"); if ((status = write(cfd, buf, len)) > -1) return status; if (errno == EBADF) @@ -288,15 +288,16 @@ static void notify_watchers(struct gps_device_t *device, char *sentence, ...) throttled_write(cfd, buf, strlen(buf)); } -static void raw_hook(struct gps_data_t *ud UNUSED, char *sentence, int level) +static void raw_hook(struct gps_data_t *ud UNUSED, + char *sentence, int len, int level) /* hook to be executed on each incoming packet */ { int cfd; for (cfd = 0; cfd < FD_SETSIZE; cfd++) { /* copy raw NMEA sentences from GPS to clients in raw mode */ - if (subscribers[cfd].raw >= level && !strcmp(ud->gps_device, (subscribers[cfd].device->gpsdata.gps_device))) - throttled_write(cfd, sentence, strlen(sentence)); + if (subscribers[cfd].raw == level && !strcmp(ud->gps_device, (subscribers[cfd].device->gpsdata.gps_device))) + throttled_write(cfd, sentence, len); } } @@ -172,7 +172,7 @@ extern void gpsd_set_speed(struct gps_device_t *, unsigned int, unsigned int, un extern int gpsd_get_speed(struct termios *); extern void gpsd_close(struct gps_device_t *); -extern void gpsd_raw_hook(struct gps_device_t *, char *, int level); +extern void gpsd_raw_hook(struct gps_device_t *, char *, int len, int level); extern void gpsd_zero_satellites(struct gps_data_t *); extern void gpsd_binary_fix_dump(struct gps_device_t *, char *); extern void gpsd_binary_satellite_dump(struct gps_device_t *, char *); diff --git a/gpsd.spec.in b/gpsd.spec.in index 7e3c811b..a19554bd 100644 --- a/gpsd.spec.in +++ b/gpsd.spec.in @@ -129,7 +129,7 @@ cp gps.py "$RPM_BUILD_ROOT"%{_libdir}/python${PYVERSION}/site-packages library. Packet-sniffing on a new device no longer holds up incoming data on already-connected ones. There is now a super-raw mode (R=2) that dumps a hex-encoding of every binary packet received to the - client. + client. Support for Trimble TSIP GPSes merged. * Sat May 21 2005 Eric S. Raymond <esr@snark.thyrsus.com> - 2.25-1 - Various signedness and scaling fixes and an OpenBSD port patch for the @@ -48,11 +48,12 @@ protocol for it.</para> <para><application>gpsd</application> should be able to query any GPS that speaks either the standard textual NMEA 0183 protocol, or the -binary Rockwell protocol used by EarthMate and some other GPSes, or -the binary SiRF protocol used by SiRf-II and SiRF-Star chipsets, or -the Garmin binary protocol used by the USB version of the Garmin 18 -and other Garmin USB GPSes. <application>gpsd</application> -effectively hides the differences among these.</para> +binary Rockwell protocol used by EarthMate and some other GPSes, the +TSIP binary protocol used by Trimble GPSes, or the binary SiRF +protocol used by SiRf-II and SiRF-Star chipsets, or the Garmin binary +protocol used by the USB version of the Garmin 18 and other Garmin USB +GPSes. <application>gpsd</application> effectively hides the +differences among these.</para> <para>Optionally, <application>gpsd</application> may get differential-GPS corrections from a ground station running a RTCM-S104 @@ -404,8 +405,7 @@ GPS. (Non-NMEA GPSes get their communication format translated to NMEA on the fly.) The command 'r' immediately followed by the digit '1' or the plus sign '+' sets raw mode. The command 'r' immediately followed by the digit '2' sets super-raw mode; for non-NMEA (binary) GPSes this -dumps '=', followed by a hex encoding of the raw binary packet, then -dumps translated NMEA. The command 'r' followed by the digit '0' or +dumps the raw binary packet. The command 'r' followed by the digit '0' or the minus sign '-' clears raw mode. The command 'r' with neither suffix toggles raw mode.</para> @@ -751,6 +751,12 @@ than reported by the chip. The computation does not exactly match what SiRF chips do internally, which includes some satellite weighting using parameters <application>gpsd</application> cannot see.</para> +<para>Trimble (TSIP) receivers do not output satellite AZ/EL in any +normal packet, only in debug packets and raw measurement data packets +(which are quite large). Thus, the TSIP driver does not return Y +responses. Autobauding on the Trimble GPSes can take as long as +5 seconds if the device speed is not matched to the GPS speed.</para> + <para>If you are using an NMEA-only GPS (that is, not using SiRF or Garmin or Zodiac binary mode) and the GPS does not emit GPZDA at the start of its update cycle (which most consumer-grade NMEA GPSes do @@ -131,7 +131,8 @@ int gps_close(struct gps_data_t *gpsdata) return retval; } -void gps_set_raw_hook(struct gps_data_t *gpsdata, void (*hook)(struct gps_data_t *, char *, int level)) +void gps_set_raw_hook(struct gps_data_t *gpsdata, + void (*hook)(struct gps_data_t *, char *, int len, int level)) { gpsdata->raw_hook = hook; } @@ -425,9 +426,9 @@ static void gps_unpack(char *buf, struct gps_data_t *gpsdata) } if (gpsdata->raw_hook) - gpsdata->raw_hook(gpsdata, buf, 1); + gpsdata->raw_hook(gpsdata, buf, strlen(buf), 1); if (gpsdata->thread_hook) - gpsdata->thread_hook(gpsdata, buf, 1); + gpsdata->thread_hook(gpsdata, buf, strlen(buf), 1); } /* @@ -488,7 +489,7 @@ static void *poll_gpsd(void *args) } int gps_set_callback(struct gps_data_t *gpsdata, - void (*callback)(struct gps_data_t *sentence, char *buf, int level), + void (*callback)(struct gps_data_t *sentence, char *buf, int len, int level), pthread_t *handler) /* set an asynchronous callback and launch a thread for it */ { diff --git a/libgpsd.xml b/libgpsd.xml index 4452ccf6..242c4ac1 100644 --- a/libgpsd.xml +++ b/libgpsd.xml @@ -116,7 +116,8 @@ designate a speed to be tried at the front of the hunt queue</para> sentence or as it is read from the GPS. The data from non-NMEA GPSes like the EarthMate will be translated to an NMEA sentence before being passed to the hook. Parameters are a pointer to a gps_data structure -full of parsed data, the sentence, and a rawness level.</para> +full of parsed data, the sentence, the length of the sentence, +and a rawness level.</para> </listitem> </varlistentry> </variablelist> diff --git a/libgpsd_core.c b/libgpsd_core.c index 70f926a6..0624d31b 100644 --- a/libgpsd_core.c +++ b/libgpsd_core.c @@ -348,9 +348,13 @@ int gpsd_poll(struct gps_device_t *session) return ERROR_SET; } - if (packet_length) + if (packet_length) { + if (session->gpsdata.raw_hook) + session->gpsdata.raw_hook(&session->gpsdata, + session->outbuffer, + packet_length, 2); return handle_packet(session); - else + } else return ONLINE_SET; } } @@ -373,10 +377,10 @@ void gpsd_zero_satellites(struct gps_data_t *out) out->satellites = 0; } -void gpsd_raw_hook(struct gps_device_t *session, char *sentence, int level) +void gpsd_raw_hook(struct gps_device_t *session, char *sentence, int len, int level) { if (session->gpsdata.raw_hook) { - session->gpsdata.raw_hook(&session->gpsdata, sentence, level); + session->gpsdata.raw_hook(&session->gpsdata, sentence, len, level); } } @@ -437,7 +441,7 @@ void gpsd_binary_fix_dump(struct gps_device_t *session, char *bufp) strcat(bufp, (session->mag_var > 0) ? "E": "W"); } nmea_add_checksum(bufp); - gpsd_raw_hook(session, bufp, 1); + gpsd_raw_hook(session, bufp, strlen(bufp), 1); bufp += strlen(bufp); } sprintf(bufp, @@ -456,7 +460,7 @@ void gpsd_binary_fix_dump(struct gps_device_t *session, char *bufp) tm.tm_mon + 1, tm.tm_year % 100); nmea_add_checksum(bufp); - gpsd_raw_hook(session, bufp, 1); + gpsd_raw_hook(session, bufp, strlen(bufp), 1); } void gpsd_binary_satellite_dump(struct gps_device_t *session, char *bufp) @@ -483,7 +487,7 @@ void gpsd_binary_satellite_dump(struct gps_device_t *session, char *bufp) session->gpsdata.ss[i]); if (i % 4 == 3 || i == session->gpsdata.satellites-1) { nmea_add_checksum(bufp2); - gpsd_raw_hook(session, bufp2, 1); + gpsd_raw_hook(session, bufp2, strlen(bufp2), 1); } } } @@ -512,7 +516,7 @@ void gpsd_binary_quality_dump(struct gps_device_t *session, char *bufp) session->gpsdata.hdop, session->gpsdata.vdop); nmea_add_checksum(bufp2); - gpsd_raw_hook(session, bufp2, 1); + gpsd_raw_hook(session, bufp2, strlen(bufp2), 1); bufp += strlen(bufp); if ((session->gpsdata.fix.eph || session->gpsdata.fix.epv) && finite(session->gpsdata.fix.eph) @@ -526,7 +530,7 @@ void gpsd_binary_quality_dump(struct gps_device_t *session, char *bufp) session->gpsdata.fix.epv, session->gpsdata.epe); nmea_add_checksum(bufp); - gpsd_raw_hook(session, bufp, 1); + gpsd_raw_hook(session, bufp, strlen(bufp), 1); session->gpsdata.seen_sentences |= PGRME; } } diff --git a/libgpsmm.cpp b/libgpsmm.cpp index b63a12b6..eac58a60 100644 --- a/libgpsmm.cpp +++ b/libgpsmm.cpp @@ -38,7 +38,7 @@ struct gps_data_t* gpsmm::poll(void) { } } -int gpsmm::set_callback(void (*hook)(struct gps_data_t *sentence, char *buf, int level)) { +int gpsmm::set_callback(void (*hook)(struct gps_data_t *sentence, char *buf, int len, int level)) { handler = new pthread_t; return gps_set_callback(gps_data,hook,handler); } @@ -28,7 +28,7 @@ class gpsmm { struct gps_data_t* open(void); //open() with default values struct gps_data_t* query(const char *request); //put a command to gpsd and return the updated struct struct gps_data_t* poll(void); //block until gpsd returns new data, then return the updated struct - int set_callback(void (*hook)(struct gps_data_t *sentence, char *buf, int level)); //set a callback funcition, called each time new data arrives + int set_callback(void (*hook)(struct gps_data_t *sentence, char *buf, int len, int level)); //set a callback funcition, called each time new data arrives int del_callback(void); //delete the callback function void clear_fix(void); @@ -139,13 +139,10 @@ int sirf_parse(struct gps_device_t *session, unsigned char *buf, int len) if (len < 0) return 0; - buf2[0] = '='; - buf2[1] = '\0'; + buf2[0] = '\0'; for (i = 0; i < len; i++) sprintf(buf2+strlen(buf2), "%02x", buf[i]); strcat(buf2, "\n"); - if (session->gpsdata.raw_hook) - session->gpsdata.raw_hook(&session->gpsdata, buf2, 2); gpsd_report(5, "Raw SiRF packet type 0x%02x length %d: %s\n", buf[0],len,buf2); buf += 4; len -= 8; @@ -733,51 +733,36 @@ static int readword(void) return (byte1 << 8) | byte2; } -static int readpkt(unsigned char *buf, unsigned maxlen) +static int readpkt(unsigned char *buf) { int byte,len,csum,cnt; - if (!serial) { - len = read(devicefd, buf, maxlen); - if (buf[0] == '=') { - unsigned char *sp, *tp; - unsigned int c; - for (sp = buf+1, tp = buf; *sp; sp += 2) { - if (sscanf(sp, "%02x", &c)) - *tp++ = c; - } - *tp = '\0'; - len = tp - buf; - } - } else { - do { - while ((byte = readbyte()) != START1) - if (byte == EOF) - return EOF; - } while ((byte = readbyte()) != START2); - - if ((len = readword()) == EOF || len > BUFLEN) - return EOF; - - csum = 0; - cnt = len; - - while (cnt-- > 0) { - if ((byte = readbyte()) == EOF) + do { + while ((byte = readbyte()) != START1) + if (byte == EOF) return EOF; - *buf++ = byte; - csum += byte; - } + } while ((byte = readbyte()) != START2); - csum &= 0x7fff; + if ((len = readword()) == EOF || len > BUFLEN) + return EOF; - if (readword() != csum) - return EOF; + csum = 0; + cnt = len; - if (readbyte() != END1 || readbyte() != END2) + while (cnt-- > 0) { + if ((byte = readbyte()) == EOF) return EOF; + *buf++ = byte; + csum += byte; } + csum &= 0x7fff; + + if (readword() != csum) + return EOF; + + if (readbyte() != END1 || readbyte() != END2) + return EOF; return len; } @@ -1243,7 +1228,7 @@ int main (int argc, char **argv) } } - if ((len = readpkt(buf, sizeof(buf))) != EOF) { + if ((len = readpkt(buf)) != EOF) { decode_sirf(buf,len); } } @@ -41,7 +41,6 @@ static int tsip_write(int fd, unsigned int id, unsigned char *buf, int len) buf2[0] = '\0'; for (i = 0; i < len; i++) sprintf(buf2+strlen(buf2), "%02x", buf[i]); - gpsd_report(5, "Sent TSIP packet id 0x%02x: %s\n",id,buf2); buf2[0] = 0x10; @@ -126,15 +125,6 @@ static int tsip_analyze(struct gps_device_t *session) if (session->outbuflen < 4 || session->outbuffer[0] != 0x10) return 0; - if (session->gpsdata.raw_hook) { - buf2[0] = '='; - buf2[1] = '\0'; - for (i = 0; i < session->outbuflen; i++) - sprintf(buf2+strlen(buf2), "%02x", session->outbuffer[i]); - strcat(buf2, "\n"); - session->gpsdata.raw_hook(&session->gpsdata, buf2, 2); - } - /* remove DLE stuffing and put data part of message in buf */ buf2[0] = '\0'; diff --git a/xgpsspeed.c b/xgpsspeed.c index f74bce8e..f6488fa2 100644 --- a/xgpsspeed.c +++ b/xgpsspeed.c @@ -30,7 +30,7 @@ static double speedfactor; static Widget toplevel; static void update_display(struct gps_data_t *gpsdata, - char *buf UNUSED, int level UNUSED) + char *buf UNUSED, int len UNUSED, int level UNUSED) { TachometerSetValue(tacho, rint(gpsdata->fix.speed * speedfactor)); } @@ -332,13 +332,10 @@ static int zodiac_analyze(struct gps_device_t *session) return 0; } - buf2[0] = '='; - buf2[1] = '\0'; + buf2[0] = '\0'; for (i = 0; i < session->outbuflen; i++) sprintf(buf2+strlen(buf2), "%02x", session->outbuffer[i]); strcat(buf2, "\n"); - if (session->gpsdata.raw_hook) - session->gpsdata.raw_hook(&session->gpsdata, buf2, 2); gpsd_report(5, "Raw Zodiac packet type %d length %d: %s\n",id,session->outbuflen,buf2); if (session->outbuflen < 10) @@ -360,7 +357,7 @@ static int zodiac_analyze(struct gps_device_t *session) } strcat(buf, "*"); nmea_add_checksum(buf); - gpsd_raw_hook(session, buf, 1); + gpsd_raw_hook(session, buf, strlen(buf), 1); gpsd_binary_quality_dump(session, buf+strlen(buf)); gpsd_report(3, "<= GPS: %s", buf); break; |