1 /****************************************************************************
4 shared_json.c - move data between in-core and JSON structures
7 This module uses the generic JSON parser to get data from JSON
8 representations to gps.h structures. These functions are used in both
9 the daemon and the client library.
12 Written by Eric S. Raymond, 2009
13 This file is Copyright (c) 2010 by the GPSD project
14 BSD terms apply: see the file COPYING in the distribution root for details.
16 ***************************************************************************/
27 int json_device_read(const char *buf,
28 /*@out@*/ struct devconfig_t *dev,
29 /*@null@*/ const char **endptr)
31 /*@ -fullinitblock @*/
33 const struct json_attr_t json_attrs_device[] = {
34 {"class", t_check, .dflt.check = "DEVICE"},
36 {"path", t_string, .addr.string = dev->path,
37 .len = sizeof(dev->path)},
38 {"activated", t_real, .addr.real = &dev->activated},
39 {"flags", t_integer, .addr.integer = &dev->flags},
40 {"driver", t_string, .addr.string = dev->driver,
41 .len = sizeof(dev->driver)},
42 {"subtype", t_string, .addr.string = dev->subtype,
43 .len = sizeof(dev->subtype)},
44 {"native", t_integer, .addr.integer = &dev->driver_mode,
45 .dflt.integer = DEVDEFAULT_NATIVE},
46 {"bps", t_uinteger, .addr.uinteger = &dev->baudrate,
47 .dflt.uinteger = DEVDEFAULT_BPS},
48 {"parity", t_character, .addr.character = &dev->parity,
49 .dflt.character = DEVDEFAULT_PARITY},
50 {"stopbits", t_uinteger, .addr.uinteger = &dev->stopbits,
51 .dflt.uinteger = DEVDEFAULT_STOPBITS},
52 {"cycle", t_real, .addr.real = &dev->cycle,
54 {"mincycle", t_real, .addr.real = &dev->mincycle,
59 /*@ +fullinitblock @*/
62 status = json_read_object(buf, json_attrs_device, endptr);
69 int json_watch_read(const char *buf,
70 /*@out@*/ struct policy_t *ccp,
71 /*@null@*/ const char **endptr)
73 /*@ -fullinitblock @*/
75 struct json_attr_t chanconfig_attrs[] = {
76 {"class", t_check, .dflt.check = "WATCH"},
78 {"enable", t_boolean, .addr.boolean = &ccp->watcher,
79 .dflt.boolean = true},
80 {"json", t_boolean, .addr.boolean = &ccp->json,
82 {"raw", t_integer, .addr.integer = &ccp->raw,
84 {"nmea", t_boolean, .addr.boolean = &ccp->nmea,
86 {"scaled", t_boolean, .addr.boolean = &ccp->scaled},
87 {"timing", t_boolean, .addr.boolean = &ccp->timing},
88 {"device", t_string, .addr.string = ccp->devpath,
89 .len = sizeof(ccp->devpath)},
93 /*@ +fullinitblock @*/
96 status = json_read_object(buf, chanconfig_attrs, endptr);
100 /* shared_json.c ends here */