diff options
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | driver_geostar.c | 7 | ||||
-rw-r--r-- | drivers.c | 4 | ||||
-rw-r--r-- | gpsd.h-tail | 14 | ||||
-rw-r--r-- | packet.c | 91 | ||||
-rw-r--r-- | packet_states.h | 15 |
6 files changed, 128 insertions, 4 deletions
diff --git a/Makefile.am b/Makefile.am index 88f7b262..66a2cab6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -198,6 +198,7 @@ libgpsd_c_sources = \ driver_evermore.c \ driver_garmin.c \ driver_garmin_txt.c \ + driver_geostar.c \ driver_italk.c \ driver_navcom.c \ driver_nmea.c \ diff --git a/driver_geostar.c b/driver_geostar.c index 14710b79..3d3f7855 100644 --- a/driver_geostar.c +++ b/driver_geostar.c @@ -10,6 +10,9 @@ * BSD terms apply: see the file COPYING in the distribution root for details. */ +#include <sys/types.h> +#include <math.h> + #ifndef S_SPLINT_S #include <unistd.h> #endif /* S_SPLINT_S */ @@ -22,6 +25,10 @@ #include <sys/time.h> #endif +#include <string.h> + +#include "bits.h" +#include "gpsd.h" #ifdef GEOSTAR_ENABLE #define GEOSTAR_CHANNELS 24 @@ -1124,6 +1124,7 @@ static const struct gps_type_t aivdm = { #endif /* AIVDM_ENABLE */ extern const struct gps_type_t garmin_usb_binary, garmin_ser_binary; +extern const struct gps_type_t geostar_binary; extern const struct gps_type_t tsip_binary, oncore_binary; extern const struct gps_type_t evermore_binary, italk_binary; extern const struct gps_type_t navcom_binary, superstar2_binary; @@ -1173,6 +1174,9 @@ static const struct gps_type_t *gpsd_driver_array[] = { &garmin_usb_binary, &garmin_ser_binary, #endif /* GARMIN_ENABLE */ +#ifdef GEOSTAR_ENABLE + &geostar_binary, +#endif /* GEOSTAR_ENABLE */ #ifdef ITRAX_ENABLE &italk_binary, #endif /* ITRAX_ENABLE */ diff --git a/gpsd.h-tail b/gpsd.h-tail index 82bde51b..42ab204d 100644 --- a/gpsd.h-tail +++ b/gpsd.h-tail @@ -30,7 +30,7 @@ typedef unsigned int speed_t; #ifdef EARTHMATE_ENABLE #define ZODIAC_ENABLE #endif -#if defined(ZODIAC_ENABLE) || defined(SIRF_ENABLE) || defined(GARMIN_ENABLE) || defined(TSIP_ENABLE) || defined(EVERMORE_ENABLE) || defined(ITRAX_ENABLE) || defined(UBX_ENABLE) || defined(SUPERSTAR2_ENABLE) || defined(ONCORE_ENABLE) +#if defined(ZODIAC_ENABLE) || defined(SIRF_ENABLE) || defined(GARMIN_ENABLE) || defined(TSIP_ENABLE) || defined(EVERMORE_ENABLE) || defined(ITRAX_ENABLE) || defined(UBX_ENABLE) || defined(SUPERSTAR2_ENABLE) || defined(ONCORE_ENABLE) || defined(GEOSTAR_ENABLE) #define BINARY_ENABLE #endif #if defined(TRIPMATE_ENABLE) || defined(BINARY_ENABLE) @@ -89,9 +89,10 @@ struct gps_packet_t { #define UBX_PACKET 11 #define SUPERSTAR2_PACKET 12 #define ONCORE_PACKET 13 -#define MAX_PACKET_TYPE 13 /* increment this as necessary */ -#define RTCM2_PACKET 14 -#define RTCM3_PACKET 15 +#define GEOSTAR_PACKET 14 +#define MAX_PACKET_TYPE 14 /* increment this as necessary */ +#define RTCM2_PACKET 15 +#define RTCM3_PACKET 16 #define TEXTUAL_PACKET_TYPE(n) (((n)>=NMEA_PACKET) && ((n)<=MAX_TEXTUAL_TYPE)) #define GPS_PACKET_TYPE(n) (((n)>=NMEA_PACKET) && ((n)<=MAX_PACKET_TYPE)) #define LOSSLESS_PACKET_TYPE(n) (((n)>=RTCM2_PACKET) && ((n)<=RTCM3_PACKET)) @@ -367,6 +368,11 @@ struct gps_device_t { } garmintxt; #endif /* NMEA_ENABLE */ #ifdef BINARY_ENABLE +#ifdef GEOSTAR_ENABLE + struct { + unsigned int physical_port; + } geostar; +#endif /* GEOSTAR_ENABLE */ #ifdef SIRF_ENABLE struct { unsigned int driverstate; /* for private use */ @@ -220,6 +220,12 @@ static void nextstate(struct gps_packet_t *lexer, unsigned char c) break; } #endif /* NAVCOM_ENABLE */ +#ifdef GEOSTAR_ENABLE + if (c == 'P') { + lexer->state = GEOSTAR_LEADER_1; + break; + } +#endif /* GEOSTAR_ENABLE */ #ifdef RTCM104V2_ENABLE if ((isgpsstat = rtcm2_decode(lexer, c)) == ISGPS_SYNC) { lexer->state = RTCM2_SYNC_STATE; @@ -979,6 +985,66 @@ static void nextstate(struct gps_packet_t *lexer, unsigned char c) lexer->state = GROUND_STATE; break; #endif /* ITRAX_ENABLE */ +#ifdef GEOSTAR_ENABLE + case GEOSTAR_LEADER_1: + if (c == 'S') + lexer->state = GEOSTAR_LEADER_2; + else + lexer->state = GROUND_STATE; + break; + case GEOSTAR_LEADER_2: + if (c == 'G') + lexer->state = GEOSTAR_LEADER_3; + else + lexer->state = GROUND_STATE; + break; + case GEOSTAR_LEADER_3: + if (c == 'G') + lexer->state = GEOSTAR_LEADER_4; + else + lexer->state = GROUND_STATE; + break; + case GEOSTAR_LEADER_4: + lexer->state = GEOSTAR_MESSAGE_ID_1; + break; + case GEOSTAR_MESSAGE_ID_1: + lexer->state = GEOSTAR_MESSAGE_ID_2; + break; + case GEOSTAR_MESSAGE_ID_2: + lexer->length = (size_t)(c * 4); + lexer->state = GEOSTAR_LENGTH_1; + break; + case GEOSTAR_LENGTH_1: + lexer->length += (c << 8) * 4; + if (lexer->length <= MAX_PACKET_LENGTH) + lexer->state = GEOSTAR_LENGTH_2; + else + lexer->state = GROUND_STATE; + break; + case GEOSTAR_LENGTH_2: + lexer->state = GEOSTAR_PAYLOAD; + break; + case GEOSTAR_PAYLOAD: + if (--lexer->length == 0) + lexer->state = GEOSTAR_CHECKSUM_A; + /* else stay in payload state */ + break; + case GEOSTAR_CHECKSUM_A: + lexer->state = GEOSTAR_CHECKSUM_B; + break; + case GEOSTAR_CHECKSUM_B: + lexer->state = GEOSTAR_CHECKSUM_C; + break; + case GEOSTAR_CHECKSUM_C: + lexer->state = GEOSTAR_RECOGNIZED; + break; + case GEOSTAR_RECOGNIZED: + if (c == 'P') + lexer->state = GEOSTAR_LEADER_1; + else + lexer->state = GROUND_STATE; + break; +#endif /* GEOSTAR_ENABLE */ #ifdef TSIP_ENABLE case TSIP_LEADER: /* unused case */ @@ -1609,6 +1675,31 @@ void packet_parse(struct gps_packet_t *lexer) break; } #endif /* NAVCOM_ENABLE */ +#ifdef GEOSTAR_ENABLE + else if (lexer->state == GEOSTAR_RECOGNIZED) { + /* GeoStar uses a XOR 32bit checksum */ + int n, len; + unsigned int cs = 0L; + len = lexer->inbufptr - lexer->inbuffer; + + /* Calculate checksum */ + for (n = 0; n < len; n += sizeof(long)) { + cs ^= getleul(lexer->inbuffer, n); + } + + if (cs == 0) + packet_accept(lexer, GEOSTAR_PACKET); + else { + gpsd_report(LOG_IO, + "GeoStar checksum failed 0x%x over length %d\n", + cs, len); + packet_accept(lexer, BAD_PACKET); + lexer->state = GROUND_STATE; + } + packet_discard(lexer); + break; + } +#endif /* GEOSTAR_ENABLE */ #ifdef RTCM104V2_ENABLE else if (lexer->state == RTCM2_RECOGNIZED) { /* diff --git a/packet_states.h b/packet_states.h index 9f206b9a..2d426444 100644 --- a/packet_states.h +++ b/packet_states.h @@ -139,6 +139,21 @@ ONCORE_RECOGNIZED, /* closing LF */ #endif +#ifdef GEOSTAR_ENABLE + GEOSTAR_LEADER_1, /* first constant leader byte found */ + GEOSTAR_LEADER_2, /* second constant leader byte found */ + GEOSTAR_LEADER_3, /* third constant leader byte found */ + GEOSTAR_LEADER_4, /* forth constant leader byte found */ + GEOSTAR_MESSAGE_ID_1, /* first message id read */ + GEOSTAR_MESSAGE_ID_2, /* second message id read */ + GEOSTAR_LENGTH_1, /* first length byte read */ + GEOSTAR_LENGTH_2, /* second length byte read */ + GEOSTAR_PAYLOAD, /* payload eating */ + GEOSTAR_CHECKSUM_A, /* checksum A byte (xor checksum) */ + GEOSTAR_CHECKSUM_B, /* checksum B byte (xor checksum) */ + GEOSTAR_CHECKSUM_C, /* checksum C byte (xor checksum) */ + GEOSTAR_RECOGNIZED, /* this is also GEOSTAR_CHECKSUM_D */ +#endif /* * Packet formats without checksums start here. We list them last so |