summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--driver_sirf.c2
-rw-r--r--driver_superstar2.c10
-rw-r--r--gps.h125
-rw-r--r--gps_json.h1
-rw-r--r--gpsctl.c12
-rw-r--r--libgps.c54
-rw-r--r--libgps_json.c7
7 files changed, 101 insertions, 110 deletions
diff --git a/driver_sirf.c b/driver_sirf.c
index 72e847cb..338b76ad 100644
--- a/driver_sirf.c
+++ b/driver_sirf.c
@@ -102,7 +102,7 @@ static gps_mask_t sirf_msg_ublox(struct gps_device_t *, unsigned char *, size_t
static gps_mask_t sirf_msg_ppstime(struct gps_device_t *, unsigned char *, size_t );
-bool sirf_write(int fd, unsigned char *msg) {
+static bool sirf_write(int fd, unsigned char *msg) {
unsigned int crc;
size_t i, len;
bool ok;
diff --git a/driver_superstar2.c b/driver_superstar2.c
index 45e13e09..d4a5a9b0 100644
--- a/driver_superstar2.c
+++ b/driver_superstar2.c
@@ -346,15 +346,15 @@ superstar2_msg_measurement(struct gps_device_t *session, unsigned char *buf, siz
n = (int)getub(buf, 6); /* number of measurements */
t = getled(buf, 7); /* measurement time */
for(i = 0; i < n; i++){
- session->gpsdata.mtime[i] = t;
+ session->gpsdata.raw.mtime[i] = t;
session->gpsdata.PRN[i] = getub(buf, 11*i + 15) & 0x1f;
session->gpsdata.ss[i] = getub(buf, 11*i * 15 +1 )/4.0;
- session->gpsdata.codephase[i] = (double)getleul(buf, 11*i * 15 + 2);
+ session->gpsdata.raw.codephase[i] = (double)getleul(buf, 11*i * 15 + 2);
ul = getleul(buf, 11*i * 15 + 6);
- session->gpsdata.satstat[i] = ul & 0x03L;
- session->gpsdata.carrierphase[i] = (ul >> 2) & 0x03ffL;
- session->gpsdata.pseudorange[i] = (ul >> 12);
+ session->gpsdata.raw.satstat[i] = ul & 0x03L;
+ session->gpsdata.raw.carrierphase[i] = (ul >> 2) & 0x03ffL;
+ session->gpsdata.raw.pseudorange[i] = (ul >> 12);
}
mask |= RAW_SET | ONLINE_SET;
diff --git a/gps.h b/gps.h
index ec59c3ee..db195872 100644
--- a/gps.h
+++ b/gps.h
@@ -772,6 +772,49 @@ struct ais_t
};
};
+#define MAXDEVICES_PER_USER 4
+
+struct device_t {
+ char path[PATH_MAX];
+};
+
+struct compass_t {
+ double magnetic_length; /* unitvector sqrt(x^2 + y^2 +z^2) */
+ double magnetic_field_x;
+ double magnetic_field_y;
+ double magnetic_field_z;
+ double acceleration_length; /* unitvector sqrt(x^2 + y^2 +z^2) */
+ double acceleration_field_x;
+ double acceleration_field_y;
+ double acceleration_field_z;
+ double gyro_output_x;
+ double gyro_output_y;
+ double temperature;
+ /* compass status -- TrueNorth (and any similar) devices only */
+ char headingStatus;
+ char pitchStatus;
+ char rollStatus;
+ double horzField; /* Magnitude of horizontal magnetic field */
+};
+
+struct rawdata_t {
+ /* raw measurement data */
+ double codephase[MAXCHANNELS]; /* meters */
+ double carrierphase[MAXCHANNELS]; /* meters */
+ double pseudorange[MAXCHANNELS]; /* meters */
+ double deltarange[MAXCHANNELS]; /* meters/sec */
+ double doppler[MAXCHANNELS]; /* Hz */
+ double mtime[MAXCHANNELS]; /* sec */
+ unsigned satstat[MAXCHANNELS]; /* tracking status */
+#define SAT_ACQUIRED 0x01 /* satellite acquired */
+#define SAT_CODE_TRACK 0x02 /* code-tracking loop acquired */
+#define SAT_CARR_TRACK 0x04 /* carrier-tracking loop acquired */
+#define SAT_DATA_SYNC 0x08 /* data-bit synchronization done */
+#define SAT_FRAME_SYNC 0x10 /* frame synchronization done */
+#define SAT_EPHEMERIS 0x20 /* ephemeris collected */
+#define SAT_FIX_USED 0x40 /* used for position fix */
+};
+
struct gps_data_t {
gps_mask_t set; /* has field been set since this was last cleared? */
#define ONLINE_SET 0x00000001u
@@ -811,12 +854,12 @@ struct gps_data_t {
#define FIX_SET (TIME_SET|MODE_SET|TIMERR_SET|LATLON_SET|HERR_SET|ALTITUDE_SET|VERR_SET|TRACK_SET|TRACKERR_SET|SPEED_SET|SPEEDERR_SET|CLIMB_SET|CLIMBERR_SET)
double online; /* NZ if GPS is on line, 0 if not.
*
- * Note: gpsd clears this flag when sentences
+ * Note: gpsd clears this time when sentences
* fail to show up within the GPS's normal
* send cycle time. If the host-to-GPS
* link is lossy enough to drop entire
- * sentences, this flag will be
- * prone to false negatives.
+ * sentences, this field will be
+ * prone to false zero values.
*/
struct gps_fix_t fix; /* accumulated PVT data */
@@ -845,19 +888,25 @@ struct gps_data_t {
double ss[MAXCHANNELS]; /* signal-to-noise ratio (dB) */
/* where and what gpsd thinks the device is */
- char gps_device[PATH_MAX]; /* only valid if non-null. */
- char *gps_id; /* only valid if non-null. */
+ char gps_device[PATH_MAX]; /* only valid if non-null. */
+ char *gps_id; /* only valid if non-null. */
unsigned int baudrate, parity, stopbits; /* RS232 link parameters */
- unsigned int driver_mode; /* whether driver is in native mode or not */
-
- /* RTCM-104 data */
- struct rtcm2_t rtcm2;
- struct rtcm3_t rtcm3;
+ double cycle, mincycle; /* refresh cycle time in seconds */
+ unsigned int driver_mode; /* is driver in native mode or not? */
- /* device list */
- double devicelist_time; /* time devicelist was reported */
- int ndevices; /* count of available devices */
- char **devicelist; /* list of pathnames */
+ /* pack things that are never reported together to reduce structure size */
+ union {
+ struct rtcm2_t rtcm2;
+ struct rtcm3_t rtcm3;
+ struct ais_t ais;
+ struct compass_t compass;
+ struct rawdata_t raw;
+ struct {
+ double time;
+ int ndevices;
+ struct device_t list[MAXDEVICES_PER_USER];
+ } devices;
+ };
/* profiling data for last sentence */
bool profiling; /* profiling enabled? */
@@ -872,58 +921,10 @@ struct gps_data_t {
double c_recv_time; /* client receipt time (-> T2) */
double c_decode_time; /* client end-of-decode time (-> D2) */
- /* reporting cycle time and minimum */
- double cycle, mincycle; /* refresh cycle time in seconds */
-
/* these members are private */
int gps_fd; /* socket or file descriptor to GPS */
void (*raw_hook)(struct gps_data_t *, char *, size_t len, int level);/* Raw-mode hook for GPS data. */
void (*thread_hook)(struct gps_data_t *, char *, size_t len, int level);/* Thread-callback hook for GPS data. */
-
- /*
- * Do not put any configuration-symbol-dependent members
- * above this point, as we need things to be at stable
- * offsets.
- */
-#ifdef OCEANSERVER_ENABLE
- double magnetic_length; /* unitvector sqrt(x^2 + y^2 +z^2) */
- double magnetic_field_x;
- double magnetic_field_y;
- double magnetic_field_z;
- double acceleration_length; /* unitvector sqrt(x^2 + y^2 +z^2) */
- double acceleration_field_x;
- double acceleration_field_y;
- double acceleration_field_z;
- double gyro_output_x;
- double gyro_output_y;
- double temperature;
-#endif
-
-#if defined(TNT_ENABLE) || defined(OCEANSERVER_ENABLE)
- /* compass status -- TrueNorth (and any similar) devices only */
- char headingStatus;
- char pitchStatus;
- char rollStatus;
- double horzField; /* Magnitude of horizontal magnetic field */
-#endif
-
-#ifdef RAW_ENABLE
- /* raw measurement data */
- double codephase[MAXCHANNELS]; /* meters */
- double carrierphase[MAXCHANNELS]; /* meters */
- double pseudorange[MAXCHANNELS]; /* meters */
- double deltarange[MAXCHANNELS]; /* meters/sec */
- double doppler[MAXCHANNELS]; /* Hz */
- double mtime[MAXCHANNELS]; /* sec */
- unsigned satstat[MAXCHANNELS]; /* tracking status */
-#define SAT_ACQUIRED 0x01 /* satellite acquired */
-#define SAT_CODE_TRACK 0x02 /* code-tracking loop acquired */
-#define SAT_CARR_TRACK 0x04 /* carrier-tracking loop acquired */
-#define SAT_DATA_SYNC 0x08 /* data-bit synchronization done */
-#define SAT_FRAME_SYNC 0x10 /* frame synchronization done */
-#define SAT_EPHEMERIS 0x20 /* ephemeris collected */
-#define SAT_FIX_USED 0x40 /* used for position fix */
-#endif /* RAW_ENABLE */
};
extern /*@null@*/ struct gps_data_t *gps_open(const char *host, const char *port);
diff --git a/gps_json.h b/gps_json.h
index de701e05..c91900cf 100644
--- a/gps_json.h
+++ b/gps_json.h
@@ -4,7 +4,6 @@
#define GPS_JSON_COMMAND_MAX 80
#define GPS_JSON_RESPONSE_MAX 1024
-#define GPS_JSON_DEVICES_MAX 4
struct devconfig_t {
char device[PATH_MAX];
diff --git a/gpsctl.c b/gpsctl.c
index 5203e30c..29f4c336 100644
--- a/gpsctl.c
+++ b/gpsctl.c
@@ -243,23 +243,23 @@ int main(int argc, char **argv)
assert(gpsdata != NULL);
// FIXME: Requires old protocol
(void)gps_query(gpsdata, "K\n");
- if (gpsdata->ndevices == 0) {
+ if (gpsdata->devices.ndevices == 0) {
gpsd_report(LOG_ERROR, "no devices connected.\n");
(void)gps_close(gpsdata);
exit(1);
- } else if (gpsdata->ndevices > 1 && device == NULL) {
+ } else if (gpsdata->devices.ndevices > 1 && device == NULL) {
gpsd_report(LOG_ERROR,
"multiple devices and no device specified.\n");
(void)gps_close(gpsdata);
exit(1);
}
- gpsd_report(LOG_PROG, "%d device(s) found.\n", gpsdata->ndevices);
+ gpsd_report(LOG_PROG, "%d device(s) found.\n", gpsdata->devices.ndevices);
- if (gpsdata->ndevices > 1) {
+ if (gpsdata->devices.ndevices > 1) {
int i;
assert(device != NULL);
- for (i = 0; i < gpsdata->ndevices; i++)
- if (strcmp(device, gpsdata->devicelist[i]) == 0)
+ for (i = 0; i < gpsdata->devices.ndevices; i++)
+ if (strcmp(device, gpsdata->devices.list[i].path) == 0)
goto foundit;
gpsd_report(LOG_ERROR, "specified device not found.\n");
(void)gps_close(gpsdata);
diff --git a/libgps.c b/libgps.c
index 49cfcf61..8b4e9be9 100644
--- a/libgps.c
+++ b/libgps.c
@@ -57,14 +57,6 @@ int gps_close(struct gps_data_t *gpsdata)
gpsdata->gps_id = NULL;
}
gpsdata->gps_device[0] = '\0';
- if (gpsdata->devicelist) {
- int i;
- for (i = 0; i < gpsdata->ndevices; i++)
- /*@i1@*/(void)free(gpsdata->devicelist[i]);
- (void)free(gpsdata->devicelist);
- gpsdata->devicelist = NULL;
- gpsdata->ndevices = -1;
- }
/*@i@*/(void)free(gpsdata);
return retval;
}
@@ -208,32 +200,23 @@ static void gps_unpack(char *buf, struct gps_data_t *gpsdata)
/*@ +mustfreeonly */
break;
case 'K':
- if (gpsdata->devicelist) {
- for (i = 0; i < gpsdata->ndevices; i++)
- /*@i1@*/(void)free(gpsdata->devicelist[i]);
- (void)free(gpsdata->devicelist);
- gpsdata->devicelist = NULL;
- gpsdata->ndevices = -1;
- gpsdata->set |= DEVICELIST_SET;
- }
if (sp[2] != '?') {
- /*@ -nullderef -nullpass -mustfreeonly -dependenttrans @*/
char *rc = strdup(sp);
char *sp2 = rc;
char *ns2 = ns;
- gpsdata->ndevices = (int)strtol(sp2+2, &sp2, 10);
- gpsdata->devicelist = (char **)calloc(
- (size_t)gpsdata->ndevices,
- sizeof(char **));
- /*@ -nullstate -mustfreefresh @*/
- gpsdata->devicelist[i=0] = strdup(strtok_r(sp2+1, " \r\n", &ns2));
+ memset(&gpsdata->devices, '\0', sizeof(gpsdata->devices));
+ gpsdata->devices.ndevices = (int)strtol(sp2+2, &sp2, 10);
+ strlcpy(gpsdata->devices.list[i=0].path,
+ strtok_r(sp2+1," \r\n", &ns2),
+ sizeof(gpsdata->devices.list[i=0].path));
while ((sp2 = strtok_r(NULL, " \r\n", &ns2)))
- gpsdata->devicelist[++i] = strdup(sp2);
+ if (i < MAXDEVICES_PER_USER-1)
+ (void)strlcpy(gpsdata->devices.list[++i].path,
+ sp2,
+ sizeof(gpsdata->devices.list[i=0].path));
free(rc);
- /*@ +nullstate +mustfreefresh @*/
- /*@ +nullderef +nullpass +dependenttrans +mustfreeonly @*/
gpsdata->set |= DEVICELIST_SET;
- gpsdata->devicelist_time = timestamp();
+ gpsdata->devices.time = timestamp();
}
break;
case 'M':
@@ -611,9 +594,9 @@ static void data_dump(struct gps_data_t *collect, time_t now)
printf("GPSD ID is %s\n", collect->gps_id);
if (collect->set & DEVICELIST_SET) {
int i;
- printf("%d devices:\n", collect->ndevices);
- for (i = 0; i < collect->ndevices; i++) {
- printf("%d: %s\n", collect->ndevices, collect->devicelist[i]);
+ printf("%d devices:\n", collect->devices.ndevices);
+ for (i = 0; i < collect->devices.ndevices; i++) {
+ printf("%d: %s\n", collect->devices.ndevices, collect->devices.list[i].path);
}
}
@@ -659,11 +642,20 @@ int main(int argc, char *argv[])
int option;
bool unpack_test = false;
- while ((option = getopt(argc, argv, "uh?")) != -1) {
+ while ((option = getopt(argc, argv, "uhs?")) != -1) {
switch (option) {
case 'u':
unpack_test = true;
break;
+ case 's':
+ (void)printf("Sizes: rtcm2=%zd rtcm3=%zd ais=%zd compass=%zd raw=%zd devices=%zd\n",
+ sizeof(struct rtcm2_t),
+ sizeof(struct rtcm3_t),
+ sizeof(struct ais_t),
+ sizeof(struct compass_t),
+ sizeof(struct rawdata_t),
+ sizeof(collect->devices));
+ break;
case '?':
case 'h':
default:
diff --git a/libgps_json.c b/libgps_json.c
index b862e114..a901c8c9 100644
--- a/libgps_json.c
+++ b/libgps_json.c
@@ -172,12 +172,11 @@ static int json_devicelist_read(const char *buf,
.addr.string.len = sizeof(gpsdata->gps_device)},
{NULL},
};
- // FIXME: Can we abolish the hard limit on the number of devices?
const struct json_attr_t json_attrs_devices[] = {
{"class", check, .dflt.check = "DEVICES"},
{"devices", array, .addr.array.element_type = object,
.addr.array.arr.subtype = json_attrs_subdevices,
- .addr.array.maxlen = GPS_JSON_DEVICES_MAX},
+ .addr.array.maxlen = MAXDEVICES_PER_USER},
{NULL},
};
int status;
@@ -186,9 +185,9 @@ static int json_devicelist_read(const char *buf,
if (status != 0)
return status;
- gpsdata->devicelist_time = timestamp();
+ gpsdata->devices.time = timestamp();
gpsdata->set |= DEVICELIST_SET;
- gpsdata->ndevices = *json_attrs_devices[0].addr.array.count;
+ gpsdata->devices.ndevices = *json_attrs_devices[0].addr.array.count;
return 0;
}
#endif