From 447a4137a696299725e3dc9840efc1fb94a629e6 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Sun, 23 Aug 2009 14:56:04 +0000 Subject: Merge two structures that didn't need to exist separately. All regression tests pass. --- gps.h | 10 +++++----- gps_json.h | 8 -------- gpsd.c | 18 +++++++++++------- gpsd_json.c | 36 +++++++++++++++++++++++++++++------- libgps_json.c | 14 +++++++------- www/protocol-transition.txt | 4 ++-- 6 files changed, 54 insertions(+), 36 deletions(-) diff --git a/gps.h b/gps.h index e277bbd9..caff8bb9 100644 --- a/gps.h +++ b/gps.h @@ -821,7 +821,7 @@ struct version_t { int api_major, api_minor; /* API major and minor versions */ }; -struct device_t { +struct devconfig_t { char path[GPS_PATH_MAX]; int flags; #define SEEN_GPS 0x01 @@ -831,9 +831,9 @@ struct device_t { char driver[64]; char subtype[64]; double activated; - unsigned int baudrate, parity, stopbits; /* RS232 link parameters */ + int baudrate, parity, stopbits; /* RS232 link parameters */ double cycle, mincycle; /* refresh cycle time in seconds */ - unsigned int driver_mode; /* is driver in native mode or not? */ + int driver_mode; /* is driver in native mode or not? */ }; struct watch_t { @@ -916,7 +916,7 @@ struct gps_data_t { int azimuth[MAXCHANNELS]; /* azimuth */ double ss[MAXCHANNELS]; /* signal-to-noise ratio (dB) */ - struct device_t dev; /* device that shipped last update */ + struct devconfig_t dev; /* device that shipped last update */ /* pack things that are never reported together to reduce structure size */ union { @@ -931,7 +931,7 @@ struct gps_data_t { struct { double time; int ndevices; - struct device_t list[MAXDEVICES_PER_USER]; + struct devconfig_t list[MAXDEVICES_PER_USER]; } devices; }; diff --git a/gps_json.h b/gps_json.h index c91900cf..2a85a9f8 100644 --- a/gps_json.h +++ b/gps_json.h @@ -5,14 +5,6 @@ #define GPS_JSON_COMMAND_MAX 80 #define GPS_JSON_RESPONSE_MAX 1024 -struct devconfig_t { - char device[PATH_MAX]; - int native; - int bps; - char serialmode[4]; - double cycle; - double mincycle; -}; 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); void json_device_dump(struct gps_device_t *, char *, size_t); diff --git a/gpsd.c b/gpsd.c index 3b67f67f..ac739b4f 100644 --- a/gpsd.c +++ b/gpsd.c @@ -1660,7 +1660,7 @@ static void handle_newstyle_request(struct subscriber_t *sub, } else { struct channel_t *chp; struct devconfig_t devconf; - devconf.device[0] = '\0'; + devconf.path[0] = '\0'; if (*buf == '=') { int status; status = json_configdev_read(&devconf, buf+1, &end); @@ -1670,7 +1670,7 @@ static void handle_newstyle_request(struct subscriber_t *sub, (void)snprintf(reply, replylen, "{\"class\":ERROR\",\"message\":\"Invalid CONFIGDEV.\",\"error\":\"%s\"}\r\n", json_error_string(status)); - else if (chcount > 1 && devconf.device[0] == '\0') + else if (chcount > 1 && devconf.path[0] == '\0') (void)snprintf(reply+strlen(reply), replylen-strlen(reply), "{\"class\":ERROR\",\"message\":\"No path specified in CONFIGDEV, but multiple channels are subscribed.\"}\r\n"); else { @@ -1678,7 +1678,7 @@ static void handle_newstyle_request(struct subscriber_t *sub, for (chp = channels; chp < channels + NITEMS(channels); chp++) if (chp->subscriber != sub) continue; - else if (devconf.device[0] != '\0' && chp->device && strcmp(chp->device->gpsdata.dev.path, devconf.device)!=0) + else if (devconf.path[0] != '\0' && chp->device && strcmp(chp->device->gpsdata.dev.path, devconf.path)!=0) continue; else { channel = chp; @@ -1688,11 +1688,15 @@ static void handle_newstyle_request(struct subscriber_t *sub, (void)snprintf(reply+strlen(reply), replylen-strlen(reply), "{\"class\":ERROR\",\"message\":\"Multiple subscribers, cannot change control bits.\"}\r\n"); else { + char serialmode[3]; /* now that channel is selected, apply changes */ - if (devconf.native != channel->device->gpsdata.dev.driver_mode) - channel->device->device_type->mode_switcher(channel->device, devconf.native); + if (devconf.driver_mode != channel->device->gpsdata.dev.driver_mode) + channel->device->device_type->mode_switcher(channel->device, devconf.driver_mode); + serialmode[0] = devconf.parity; + serialmode[1] = '0' + devconf.stopbits; + serialmode[2] = '\0'; set_serial(channel->device, - (speed_t)devconf.bps, devconf.serialmode); + (speed_t)devconf.baudrate, serialmode); } } buf = end; @@ -1701,7 +1705,7 @@ static void handle_newstyle_request(struct subscriber_t *sub, for (chp = channels; chp < channels + NITEMS(channels); chp++) if (chp->subscriber != sub) continue; - else if (devconf.device[0] != '\0' && chp->device && strcmp(chp->device->gpsdata.dev.path, devconf.device)!=0) + else if (devconf.path[0] != '\0' && chp->device && strcmp(chp->device->gpsdata.dev.path, devconf.path)!=0) continue; else { json_configdev_dump(chp->device, diff --git a/gpsd_json.c b/gpsd_json.c index 0ed8d0cd..83fd0f5f 100644 --- a/gpsd_json.c +++ b/gpsd_json.c @@ -226,15 +226,17 @@ void json_watch_dump(struct policy_t *ccp, char *reply, size_t replylen) int json_configdev_read(struct devconfig_t *cdp, const char *buf, const char **endptr) { + int status; + char serialmode[4]; struct json_attr_t devconfig_attrs[] = { - {"device", string, .addr.string.ptr=cdp->device, - .addr.string.len=sizeof(cdp->device)}, - {"native", integer, .addr.integer = &cdp->native, + {"device", string, .addr.string.ptr=cdp->path, + .addr.string.len=sizeof(cdp->path)}, + {"native", integer, .addr.integer = &cdp->driver_mode, .dflt.integer = -1}, - {"bps", integer, .addr.integer = &cdp->bps, + {"bps", integer, .addr.integer = &cdp->baudrate, .dflt.integer = -1}, - {"serialmode", string, .addr.string.ptr=cdp->serialmode, - .addr.string.len=sizeof(cdp->serialmode)}, + {"serialmode", string, .addr.string.ptr=serialmode, + .addr.string.len=sizeof(serialmode)}, {"cycle", real, .addr.real = &cdp->cycle, .dflt.real = NAN}, {"mincycle", real, .addr.real = &cdp->mincycle, @@ -242,7 +244,27 @@ int json_configdev_read(struct devconfig_t *cdp, const char *buf, const char **e {NULL}, }; - return json_read_object(buf, devconfig_attrs, endptr); + status = json_read_object(buf, devconfig_attrs, endptr); + + if (status == 0) { + int wordsize = 8; + char *modestring = serialmode; + + if (strchr("78", *modestring)!= NULL) { + while (isspace(*modestring)) + modestring++; + wordsize = (int)(*modestring++ - '0'); + if (strchr("NOE", *modestring)!= NULL) { + cdp->parity = *modestring++; + while (isspace(*modestring)) + modestring++; + if (strchr("12", *modestring)!=NULL) + cdp->stopbits = (unsigned int)(*modestring - '0'); + } + } + } + + return status; } void json_configdev_dump(struct gps_device_t *devp, char *reply, size_t replylen) diff --git a/libgps_json.c b/libgps_json.c index ec5b76ed..11bd61da 100644 --- a/libgps_json.c +++ b/libgps_json.c @@ -142,7 +142,7 @@ static int json_sky_read(const char *buf, } static int json_device_read(const char *buf, - struct device_t *dev, const char **endptr) + struct devconfig_t *dev, const char **endptr) { const struct json_attr_t json_attrs_device[] = { {"class", check, .dflt.check = "DEVICE"}, @@ -171,13 +171,13 @@ static int json_devicelist_read(const char *buf, { const struct json_attr_t json_attrs_subdevices[] = { {"class", check, .dflt.check = "DEVICE"}, - {"path", string, .addr.offset = offsetof(struct device_t, path), + {"path", string, .addr.offset = offsetof(struct devconfig_t, path), .addr.string.len = sizeof(gpsdata->devices.list[0].path)}, - {"activated", real, .addr.offset = offsetof(struct device_t, activated)}, - {"flags", array, .addr.offset = offsetof(struct device_t, flags)}, - {"driver", string, .addr.offset = offsetof(struct device_t, driver), + {"activated", real, .addr.offset = offsetof(struct devconfig_t, activated)}, + {"flags", array, .addr.offset = offsetof(struct devconfig_t, flags)}, + {"driver", string, .addr.offset = offsetof(struct devconfig_t, driver), .addr.string.len = sizeof(gpsdata->devices.list[0].driver)}, - {"subtype", string, .addr.offset = offsetof(struct device_t, subtype), + {"subtype", string, .addr.offset = offsetof(struct devconfig_t, subtype), .addr.string.len = sizeof(gpsdata->devices.list[0].subtype)}, {NULL}, }; @@ -185,7 +185,7 @@ static int json_devicelist_read(const char *buf, {"class", check, .dflt.check = "DEVICES"}, {"devices", array, .addr.array.element_type = structobject, .addr.array.arr.objects.base = (char*)gpsdata->devices.list, - .addr.array.arr.objects.stride = sizeof(struct device_t), + .addr.array.arr.objects.stride = sizeof(struct devconfig_t), .addr.array.arr.objects.subtype = json_attrs_subdevices, .addr.array.count = &gpsdata->devices.ndevices, .addr.array.maxlen = NITEMS(gpsdata->devices.list)}, diff --git a/www/protocol-transition.txt b/www/protocol-transition.txt index 05bc7f32..ece728f3 100644 --- a/www/protocol-transition.txt +++ b/www/protocol-transition.txt @@ -260,7 +260,7 @@ have no equivalents. We'll implement them if we need them. == How the gps_data_t structure has changed == The client libary's reporting structure, struct gpsdata_t, has a new -substructure (struct device_t) named "dev" that groups together +substructure (struct devconfig_t) named "dev" that groups together information about the device that shipped the last update to the client. The members of this structure replace several top-level struct gpsdata members in older versions. @@ -279,6 +279,6 @@ considered valid only when DEVICE_SET is on in the top-level set member (note: this flag is not reliably set yet, work in progress). The top-level members ndevices and devicelist (used only on the client -side) have been replaced by an array of struct device_t structures. +side) have been replaced by an array of struct devconfig_t structures. Storage for pathnames is no longer dynamically allocated, but rather lives in a union with several other substructures. -- cgit v1.2.1