summaryrefslogtreecommitdiff
path: root/test_libgps.c
diff options
context:
space:
mode:
authorRob Norris <rw_norris@hotmail.com>2016-02-21 11:53:13 +0000
committerEric S. Raymond <esr@thyrsus.com>2016-02-23 17:33:20 -0500
commit40c9a8703efd8850dc3fed44ad9cc91d37d03343 (patch)
tree49e42ebc89c310509f5db6d8509c46915de375f3 /test_libgps.c
parent777cb3737ae85b13642fff48eabb601c4d40f527 (diff)
downloadgpsd-40c9a8703efd8850dc3fed44ad9cc91d37d03343.tar.gz
Make the test_libgps program more useful by allowing to specify the server and port.
Use gpsd_source_spec() as per usage in cgps. Since this now uses the unnamed command line parameter, add new '-f' mode to forward (i.e. send) data specified on the command line to gpsd.
Diffstat (limited to 'test_libgps.c')
-rw-r--r--test_libgps.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/test_libgps.c b/test_libgps.c
index 36342acb..97ad107f 100644
--- a/test_libgps.c
+++ b/test_libgps.c
@@ -13,6 +13,7 @@
#define LIBGPS_DEBUG
#include "gpsd.h"
+#include "gpsdclient.h"
#include <unistd.h>
#include <getopt.h>
@@ -32,9 +33,12 @@ static struct gps_data_t gpsdata;
int main(int argc, char *argv[])
{
struct gps_data_t collect;
+ struct fixsource_t source;
char buf[BUFSIZ];
int option;
bool batchmode = false;
+ bool forwardmode = false;
+ char *fmsg = NULL;
#ifdef CLIENTDEBUG_ENABLE
int debug = 0;
#endif
@@ -42,11 +46,15 @@ int main(int argc, char *argv[])
(void)signal(SIGSEGV, onsig);
(void)signal(SIGBUS, onsig);
- while ((option = getopt(argc, argv, "bhsD:?")) != -1) {
+ while ((option = getopt(argc, argv, "bf:hsD:?")) != -1) {
switch (option) {
case 'b':
batchmode = true;
break;
+ case 'f':
+ forwardmode = true;
+ fmsg = optarg;
+ break;
case 's':
(void)
printf
@@ -66,11 +74,17 @@ int main(int argc, char *argv[])
case '?':
case 'h':
default:
- (void)fputs("usage: test_libgps [-b] [-D lvl] [-s]\n", stderr);
+ (void)fputs("usage: test_libgps [-b] [-f fwdmsg] [-D lvl] [-s] [server[:port:[device]]]\n", stderr);
exit(EXIT_FAILURE);
}
}
+ /* Grok the server, port, and device. */
+ if (optind < argc) {
+ gpsd_source_spec(argv[optind], &source);
+ } else
+ gpsd_source_spec(NULL, &source);
+
#ifdef CLIENTDEBUG_ENABLE
gps_enable_debug(debug, stdout);
#endif
@@ -83,13 +97,13 @@ int main(int argc, char *argv[])
}
}
#endif
- } else if (gps_open(NULL, 0, &collect) != 0) {
- (void)fputs("Daemon is not running.\n", stdout);
+ } else if (gps_open(source.server, source.port, &collect) != 0) {
+ (void)fprintf(stderr,
+ "test_libgps: no gpsd running or network error: %d, %s\n",
+ errno, gps_errstr(errno));
exit(EXIT_FAILURE);
- } else if (optind < argc) {
- (void)strlcpy(buf, argv[optind], sizeof(buf));
- (void)strlcat(buf, "\n", sizeof(buf));
- (void)gps_send(&collect, buf);
+ } else if (forwardmode) {
+ (void)gps_send(&collect, fmsg);
(void)gps_read(&collect);
#ifdef SOCKET_EXPORT_ENABLE
libgps_dump_state(&collect);