From da9947b545847988e42c1975eac36708a367fd0a Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Mon, 17 Aug 2009 21:07:21 +0000 Subject: Add cycle-time reporting and setting to new protocol. Steps towards making gpsctl work with new protocol. Incidentally, fixes a bug where min_cycle was not reported correctly in the C command. --- gps_json.c | 24 +++++++++++++++++------- gps_json.h | 3 ++- gpsctl.c | 34 +++++++++++++++++++++++++++++++--- gpsd.c | 15 ++------------- gpsd.xml | 14 ++++++++++++++ 5 files changed, 66 insertions(+), 24 deletions(-) diff --git a/gps_json.c b/gps_json.c index 16611349..b5e49a27 100644 --- a/gps_json.c +++ b/gps_json.c @@ -280,20 +280,30 @@ int json_configdev_read(struct devconfig_t *cdp, const char *buf, const char **e .dflt.integer = -1}, {"serialmode", string, .addr.string.ptr=cdp->serialmode, .addr.string.len=sizeof(cdp->serialmode)}, + {"cycle", real, .addr.real = &cdp->cycle, + .dflt.real = NAN}, {NULL}, }; return json_read_object(buf, devconfig_attrs, 0, endptr); } -void json_configdev_dump(struct devconfig_t *cdp, char *reply, size_t replylen) +void json_configdev_dump(struct gps_device_t *devp, char *reply, size_t replylen) { - (void)snprintf(reply, replylen-1, - "{\"class\":\"CONFIGDEV\",\"device\":\"%s\",\"native\":%d,\"bps\":%d,\"serialmode\":\"%s\",}", - cdp->device, - cdp->native, - cdp->bps, - cdp->serialmode); + (void)snprintf(reply, replylen, + "{\"class\":\"CONFIGDEV\",\"device\":\"%s\",\"native\":%d,\"bps\":%d,\"serialmode\":\"%u%c%u\",\"cycle\":%2.2f", + devp->gpsdata.gps_device, + devp->gpsdata.driver_mode, + (int)gpsd_get_speed(&devp->ttyset), + 9 - devp->gpsdata.stopbits, + (int)devp->gpsdata.parity, + devp->gpsdata.stopbits, + devp->gpsdata.cycle); + if (devp->device_type->rate_switcher != NULL) + (void)snprintf(reply+strlen(reply), replylen-strlen(reply), + ",\"mincycle\":%2.2f", + devp->device_type->min_cycle); + (void)strlcat(reply, "}", replylen); } /* gpsd_json.c ends here */ diff --git a/gps_json.h b/gps_json.h index 662256f6..ddcaa0e6 100644 --- a/gps_json.h +++ b/gps_json.h @@ -10,6 +10,7 @@ struct devconfig_t { int native; int bps; char serialmode[4]; + double cycle; }; void json_tpv_dump(struct gps_data_t *, struct gps_fix_t *, char *, size_t); void json_sky_dump(struct gps_data_t *, char *, size_t); @@ -18,6 +19,6 @@ int json_sky_read(const char *, struct gps_data_t *, const char **); int json_watch_read(struct policy_t *, const char *, const char **); void json_watch_dump(struct policy_t *, char *, size_t); int json_configdev_read(struct devconfig_t *, const char *, const char **); -void json_configdev_dump(struct devconfig_t *, char *, size_t); +void json_configdev_dump(struct gps_device_t *, char *, size_t); /* gps_json.h ends here */ diff --git a/gpsctl.c b/gpsctl.c index c9652fbf..5203e30c 100644 --- a/gpsctl.c +++ b/gpsctl.c @@ -241,6 +241,7 @@ int main(int argc, char **argv) if (!lowlevel) { /* OK, there's a daemon instance running. Do things the easy way */ assert(gpsdata != NULL); + // FIXME: Requires old protocol (void)gps_query(gpsdata, "K\n"); if (gpsdata->ndevices == 0) { gpsd_report(LOG_ERROR, "no devices connected.\n"); @@ -264,12 +265,14 @@ int main(int argc, char **argv) (void)gps_close(gpsdata); exit(1); foundit: + // FIXME: Requires old protocol (void)gps_query(gpsdata, "F=%s", device); } /* if no control operation was specified, just ID the device */ if (speed==NULL && rate == NULL && !to_nmea && !to_binary && !reset) { /* the O is to force a device binding */ + // FIXME: Requires old protocol (void)gps_query(gpsdata, "OFIB"); gpsd_report(LOG_SHOUT, "%s identified as %s at %d\n", gpsdata->gps_device,gpsdata->gps_id,gpsdata->baudrate); @@ -285,7 +288,11 @@ int main(int argc, char **argv) } if (to_nmea) { +#ifdef OLDSTYLE_ENABLE (void)gps_query(gpsdata, "N=0"); +#else + (void)gps_query(gpsdata, "?CONFIGDEV={\"mode\":0}\r\n"); +#endif /* OLDSTYLE_ENABLE */ if (gpsdata->driver_mode != MODE_NMEA) { gpsd_report(LOG_ERROR, "%s mode change to NMEA failed\n", gpsdata->gps_device); status = 1; @@ -293,7 +300,11 @@ int main(int argc, char **argv) gpsd_report(LOG_PROG, "%s mode change succeeded\n", gpsdata->gps_device); } else if (to_binary) { +#ifdef OLDSTYLE_ENABLE (void)gps_query(gpsdata, "N=1"); +#else + (void)gps_query(gpsdata, "?CONFIGDEV={\"mode\":1}\r\n"); +#endif /* OLDSTYLE_ENABLE */ if (gpsdata->driver_mode != MODE_BINARY) { gpsd_report(LOG_ERROR, "%s mode change to native mode failed\n", gpsdata->gps_device); status = 1; @@ -304,7 +315,13 @@ int main(int argc, char **argv) char parity = 'N'; char stopbits = '1'; if (strchr(speed, ':')==NULL) - (void)gps_query(gpsdata, "B=%s", speed); + (void)gps_query(gpsdata, "B=%s", +#ifdef OLDSTYLE_ENABLE + "B=%s", +#else + "?CONFIGDEV={\"bps\":%s}", +#endif /* OLDSTYLE_ENABLE */ + speed); else { char *modespec = strchr(speed, ':'); /*@ +charint @*/ @@ -327,7 +344,12 @@ int main(int argc, char **argv) } } if (status == 0) - (void)gps_query(gpsdata, "B=%s 8 %c %c", + (void)gps_query(gpsdata, +#ifdef OLDSTYLE_ENABLE + "B=%s 8 %c %c\n", +#else + "?CONFIGDEV={\"bps\":%s,\"serialmode\":\"8%c%c\"}\r\n", +#endif /* OLDSTYLE_ENABLE */ speed, parity, stopbits); } if (atoi(speed) != (int)gpsdata->baudrate) { @@ -341,7 +363,13 @@ int main(int argc, char **argv) speed, parity, stopbits); } if (rate != NULL) { - (void)gps_query(gpsdata, "C=%\n", rate); + (void)gps_query(gpsdata, +#ifdef OLDSTYLE_ENABLE + "C=%s\n", +#else + "?CONFIGDEV={\"cycle\":%s}\n", +#endif /* OLDSTYLE_ENABLE */ + rate); } #endif /* ALLOW_RECONFIGURE */ (void)gps_close(gpsdata); diff --git a/gpsd.c b/gpsd.c index 06f535c9..b581e09f 100644 --- a/gpsd.c +++ b/gpsd.c @@ -1088,7 +1088,7 @@ static bool handle_oldstyle(struct subscriber_t *sub, char *buf, ",C=%.2f", channel->device->gpsdata.cycle); else (void)snprintf(phrase, sizeof(phrase), ",C=%.2f %.2f", - channel->device->gpsdata.cycle, channel->device->gpsdata.cycle); + channel->device->gpsdata.cycle, channel->device->gpsdata.mincycle); } break; #endif /* ALLOW_RECONFIGURE */ @@ -1718,18 +1718,7 @@ static void handle_newstyle_request(struct subscriber_t *sub, else if (devconf.device[0] != '\0' && chp->device && strcmp(chp->device->gpsdata.gps_device, devconf.device)!=0) continue; else { - (void)strlcpy(devconf.device, - chp->device->gpsdata.gps_device, - sizeof(devconf.device)); - (void)snprintf(devconf.serialmode, - sizeof(devconf.serialmode), - "%u%c%u", - 9 - chp->device->gpsdata.stopbits, - (int)chp->device->gpsdata.parity, - chp->device->gpsdata.stopbits); - devconf.bps=(int)gpsd_get_speed(&chp->device->ttyset); - devconf.native = chp->device->gpsdata.driver_mode; - json_configdev_dump(&devconf, + json_configdev_dump(chp->device, reply + strlen(reply), replylen - strlen(reply)); (void)strlcat(reply, "\r\n", replylen); diff --git a/gpsd.xml b/gpsd.xml index 0864264c..6488435a 100644 --- a/gpsd.xml +++ b/gpsd.xml @@ -1381,6 +1381,20 @@ extreme cases) physically disconnecting the NVRAM backup battery. in particular). Attempting to set this mode on a non-GPS device will yield an error. + + cycle + No + real + Device cycle time in seconds. + + + min_cycle + No + real + Device minimum cycle time in seconds. Reported from + ?CONFIGDEV when (and only when) the rate is switchable. It is + read-only and not settable. + -- cgit v1.2.1