summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cgps.c8
-rw-r--r--gps.h1
-rw-r--r--gpsmon.c4
-rw-r--r--libgps.c27
-rw-r--r--libgps.xml36
-rw-r--r--libgpsmm.cpp4
-rw-r--r--libgpsmm.h2
-rw-r--r--www/protocol-transition.txt10
8 files changed, 68 insertions, 24 deletions
diff --git a/cgps.c b/cgps.c
index b592e543..011ce149 100644
--- a/cgps.c
+++ b/cgps.c
@@ -227,7 +227,7 @@ static void update_probe(struct gps_data_t *gpsdata,
/* Send an 'i' once per second until we figure out what the GPS
device is. */
if(time(NULL)-misc_timer > 2) {
- (void)gps_query(gpsdata, "i\n");
+ (void)gps_send(gpsdata, "i\n");
(void)fprintf(stderr,"Probing...\n");
misc_timer=time(NULL);
}
@@ -764,14 +764,14 @@ int main(int argc, char *argv[])
/* If the user requested a specific device, try to change to it. */
if (source.device != NULL)
- (void)gps_query(gpsdata, "F=%s\n", source.device);
+ (void)gps_send(gpsdata, "F=%s\n", source.device);
/* Here's where updates go until we figure out what we're dealing
with. */
gps_set_raw_hook(gpsdata, update_probe);
/* Tell me what you are... */
- (void)gps_query(gpsdata, "i\n");
+ (void)gps_send(gpsdata, "i\n");
/* Loop for ten seconds looking for a device. If none found, give
up and assume "unknown" device type. */
@@ -805,7 +805,7 @@ int main(int argc, char *argv[])
}
/* Request "w+x" data from gpsd. */
- (void)gps_query(gpsdata, "w+x\n");
+ (void)gps_send(gpsdata, "w+x\n");
/* heart of the client */
for (;;) {
diff --git a/gps.h b/gps.h
index 0eea88a7..6e8b91e7 100644
--- a/gps.h
+++ b/gps.h
@@ -994,6 +994,7 @@ extern int gps_open_r(const char *host, const char *port,
/*@out@*/struct gps_data_t *gpsdata);
extern /*@null@*/struct gps_data_t *gps_open(const char *host,const char *port);
extern int gps_close(struct gps_data_t *);
+extern int gps_send(struct gps_data_t *gpsdata, const char *fmt, ... );
extern int gps_query(struct gps_data_t *gpsdata, const char *fmt, ... );
extern int gps_poll(struct gps_data_t *gpsdata);
extern int gps_stream(struct gps_data_t *gpsdata, unsigned int flags);
diff --git a/gpsmon.c b/gpsmon.c
index b11d6b06..f62cc212 100644
--- a/gpsmon.c
+++ b/gpsmon.c
@@ -486,9 +486,9 @@ int main (int argc, char **argv)
}
controlfd = open(controlsock, O_RDWR);
if (source.device != NULL)
- (void)gps_query(&session.gpsdata, "?WATCH={\"raw\":2,\"device\":\"%s\"}\r\n", source.device);
+ (void)gps_send(&session.gpsdata, "?WATCH={\"raw\":2,\"device\":\"%s\"}\r\n", source.device);
else
- (void)gps_query(&session.gpsdata, "?WATCH={\"raw\":2}\r\n");
+ (void)gps_send(&session.gpsdata, "?WATCH={\"raw\":2}\r\n");
serial = false;
} else {
(void)strlcpy(session.gpsdata.dev.path, argv[optind], PATH_MAX);
diff --git a/libgps.c b/libgps.c
index 9c0443bf..2e83c144 100644
--- a/libgps.c
+++ b/libgps.c
@@ -487,6 +487,23 @@ int gps_poll(struct gps_data_t *gpsdata)
return status;
}
+int gps_send(struct gps_data_t *gpsdata, const char *fmt, ... )
+/* query a gpsd instance for new data */
+{
+ char buf[BUFSIZ];
+ va_list ap;
+
+ va_start(ap, fmt);
+ (void)vsnprintf(buf, sizeof(buf)-2, fmt, ap);
+ va_end(ap);
+ if (buf[strlen(buf)-1] != '\n')
+ (void)strlcat(buf, "\n", BUFSIZ);
+ if (write(gpsdata->gps_fd, buf, strlen(buf)) == srlen(buf))
+ return 0;
+ else
+ return -1;
+}
+
int gps_query(struct gps_data_t *gpsdata, const char *fmt, ... )
/* query a gpsd instance for new data */
{
@@ -523,7 +540,7 @@ int gps_stream(struct gps_data_t *gpsdata, unsigned int flags)
(void)strlcat(buf, "\"scaled\":true", sizeof(buf));
(void)strlcat(buf, "};", sizeof(buf));
#endif
- return gps_query(gpsdata, buf);
+ return gps_send(gpsdata, buf);
} else if ((flags & WATCH_DISABLE) != 0) {
#ifdef OLDSTYLE_ENABLE
(void)strlcpy(buf, "w-", sizeof(buf));
@@ -539,7 +556,7 @@ int gps_stream(struct gps_data_t *gpsdata, unsigned int flags)
(void)strlcat(buf, "\"scaled\":true,", sizeof(buf));
(void)strlcat(buf, "};", sizeof(buf));
#endif
- return gps_query(gpsdata, buf);
+ return gps_send(gpsdata, buf);
}
return 0;
}
@@ -737,7 +754,8 @@ int main(int argc, char *argv[])
gps_set_raw_hook(collect, dumpline);
strlcpy(buf, argv[optind], BUFSIZ);
strlcat(buf,"\n", BUFSIZ);
- gps_query(collect, buf);
+ gps_send(collect, buf);
+ gps_poll(&collect);
data_dump(collect, time(NULL));
} else {
int tty = isatty(0);
@@ -754,7 +772,8 @@ int main(int argc, char *argv[])
break;
}
collect->set = 0;
- gps_query(collect, buf);
+ gps_send(collect, buf);
+ gps_poll(&collect);
data_dump(collect, time(NULL));
}
}
diff --git a/libgps.xml b/libgps.xml
index c59d258c..4d9426d5 100644
--- a/libgps.xml
+++ b/libgps.xml
@@ -34,6 +34,12 @@ C:
<paramdef>struct gps_data_t *<parameter>gpsdata</parameter></paramdef>
</funcprototype>
<funcprototype>
+<funcprototype>
+<funcdef>int <function>gps_send</function></funcdef>
+ <paramdef>struct gps_data_t *<parameter>gpsdata</parameter></paramdef>
+ <paramdef>char *<parameter>fmt</parameter>...</paramdef>
+</funcprototype>
+<funcprototype>
<funcdef>int <function>gps_query</function></funcdef>
<paramdef>struct gps_data_t *<parameter>gpsdata</parameter></paramdef>
<paramdef>char *<parameter>fmt</parameter>...</paramdef>
@@ -141,6 +147,18 @@ undefined behavior. Currently it will leak a thread, and in the
future might result in aborting the program.
</para>
+<para><function>gps_send()</function> writes a command to the
+daemon, accepts a one-line response, and updates parts of the GPS-data
+structure that correspond to data changed since the last call. The
+second argument must be a format string containing elements from the command
+set documented at
+<citerefentry><refentrytitle>gpsd</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
+It may have % elements as for
+<citerefentry><refentrytitle>sprintf</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
+which will be filled in from any following arguments.
+This function returns a -1 if there was a Unix-level write error,
+otherwise 0.</para>
+
<para><function>gps_poll()</function> accepts a response, or sequence
of responses, from the daemon and interprets it as though it were a
query response (the return value is as for a query).
@@ -149,17 +167,17 @@ received structure. This function does a blocking read waiting for
data from the daemon; it returns 0 for success, or -1 on a Unix-level
read error. </para>
-<para><function>gps_query()</function> writes a command to the
-daemon, accepts a one-line response, and updates parts of the GPS-data
+<para><function>gps_query()</function> writes a command to the daemon,
+accepts a one-line response, and updates parts of the GPS-data
structure that correspond to data changed since the last call. The
-second argument must be a format string containing letters from the command
-set documented at
+second argument must be a format string containing elements from the
+command set documented at
<citerefentry><refentrytitle>gpsd</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
-It may have % elements as for
+It may have % elements as for
<citerefentry><refentrytitle>sprintf</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
-which will be filled in from any following arguments.
-This function returns a 0 on success, or a -1 if there was a
-Unix-level read error.</para>
+which will be filled in from any following arguments. This function
+returns a 0 on success, or a -1 if there was a Unix-level read
+error.</para>
<para><function>gps_stream()</function> asks
<application>gpsd</application> to stream the reports it has at you,
@@ -249,7 +267,7 @@ code that calls gps_poll(gpsdata).
gps_set_raw_hook(gpsdata, update_panel);
- (void)gps_query(gpsdata, "w+x\n");
+ (void)gps_stream(gpsdata, WATCH_ENABLE);
(void)XtAppAddInput(app, gpsdata->gps_fd,
(XtPointer)XtInputReadMask, handle_input, NULL);
diff --git a/libgpsmm.cpp b/libgpsmm.cpp
index 8c2d90d9..7b2d7f92 100644
--- a/libgpsmm.cpp
+++ b/libgpsmm.cpp
@@ -34,8 +34,8 @@ struct gps_data_t* gpsmm::stream(int flags) {
}
}
-struct gps_data_t* gpsmm::query(const char *request) {
- if (gps_query(gps_data,request)==-1) {
+struct gps_data_t* gpsmm::send(const char *request) {
+ if (gps_send(gps_data,request)==-1) {
return NULL;
}
else {
diff --git a/libgpsmm.h b/libgpsmm.h
index 6ccaa9fc..b90ee619 100644
--- a/libgpsmm.h
+++ b/libgpsmm.h
@@ -18,7 +18,7 @@ class gpsmm {
virtual ~gpsmm();
struct gps_data_t* open(const char *host,const char *port); //opens the connection with gpsd, MUST call this before any other method
struct gps_data_t* open(void); //open() with default values
- struct gps_data_t* query(const char *request); //put a command to gpsd and return the updated struct
+ struct gps_data_t* send(const char *request); //put a command to gpsd and return the updated struct
struct gps_data_t* stream(int); //set watcher and policy flags
struct gps_data_t* poll(void); //block until gpsd returns new data, then return the updated struct
int set_callback(void (*hook)(struct gps_data_t *sentence, char *buf, size_t len)); //set a callback funcition, called each time new data arrives
diff --git a/www/protocol-transition.txt b/www/protocol-transition.txt
index eaccc907..e3dd6cf8 100644
--- a/www/protocol-transition.txt
+++ b/www/protocol-transition.txt
@@ -263,13 +263,14 @@ The old 'R' command has been replaced by an optional attribute in
gps_stream(), or set a raw hook before alling gps_stream().
The old 'W' command has been replaced by ?WATCH. Call gps_stream()
-with whatever option you want to set.
+with whatever options you want to set.
The old 'X' command is gone. Instead, you will see an object of
class DEVICE from the daemon whenever a device is opened or closed.
The old 'Z' and '$' commands, used by the developers for profiling,
-have equivalents, presently undocumented.
+have equivalents, which are presently considered unstable and thus
+are undocumented.
== How the gps_data_t structure has changed ==
@@ -301,3 +302,8 @@ space, it lives in a union with several other substructures.
The signature of the raw_hook member has changed. It no longer takes
the final 'leve' argument, which libgps had always set to 1.
+
+== Python client library changes ==
+
+There is a gps_stream() entry point like the one in the C library.
+gps_query() is deprecated.