summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS3
-rw-r--r--gpsmon.c51
-rw-r--r--gpsmon.xml27
3 files changed, 62 insertions, 19 deletions
diff --git a/NEWS b/NEWS
index 1078e1de..72e4ee41 100644
--- a/NEWS
+++ b/NEWS
@@ -7,7 +7,8 @@ Repository head:
Some unusual AIS talker IDs (NMEA 4.0 station classes) are supported.
chrpath is no longer a dependency for building and testing, and
now defaults to 'no'. Full systemd support. Fixes for handling
- large PPS offsets. Improved recovery from device flakeouts.
+ large PPS offsets. Improved recovery from device flakeouts,
+ gpsmon argument parsing.
* Fri 22 Nov 2013 Eric S. Raymond <esr@snark.thyrsus.com> - 3.10
AIS: Adds gps2udp, an AIS data relay, split24 option supports
diff --git a/gpsmon.c b/gpsmon.c
index aea39d35..23cad0e8 100644
--- a/gpsmon.c
+++ b/gpsmon.c
@@ -27,6 +27,7 @@
#include "gpsd.h"
#include "gps_json.h"
#include "gpsmon.h"
+#include "gpsdclient.h"
#include "revision.h"
#define BUFLEN 2048
@@ -55,6 +56,7 @@ static WINDOW *statwin, *cmdwin;
static char *type_name;
static size_t promptlen = 0;
struct termios cooked, rare;
+struct fixsource_t source;
#ifdef PASSTHROUGH_ENABLE
/* no methods, it's all device window */
@@ -341,8 +343,13 @@ static /*@observer@*/ const char *promptgen(void)
9 - session.gpsdata.dev.stopbits,
session.gpsdata.dev.parity,
session.gpsdata.dev.stopbits);
- else
+ else {
(void)strlcpy(buf, session.gpsdata.dev.path, sizeof(buf));
+ if (source.device != NULL) {
+ (void) strlcat(buf, ":", sizeof(buf));
+ (void) strlcat(buf, source.device, sizeof(buf));
+ }
+ }
return buf;
}
@@ -1070,7 +1077,7 @@ static const char *cmdline;
int main(int argc, char **argv)
{
int option;
- char *explanation, *devicename;
+ char *explanation;
int bailout = 0, matches = 0;
bool nmea = false;
fd_set all_fds;
@@ -1180,19 +1187,30 @@ int main(int argc, char **argv)
gpsd_time_init(&context, time(NULL));
gpsd_init(&session, &context, NULL);
- if (optind >= argc)
- devicename = "gpsd://localhost:" DEFAULT_GPSD_PORT;
- else
- devicename = argv[optind];
+ /* Grok the server, port, and device. */
+ if (optind < argc) {
+ serial = (strncmp(argv[optind], "/dev", 4) == 0);
+ gpsd_source_spec(argv[optind], &source);
+ } else {
+ serial = false;
+ gpsd_source_spec(NULL, &source);
+ }
- /* backward compatibilty: accept a bare server name */
- if (strchr(devicename, ':') == NULL && devicename[0] != '/')
+ if (serial) {
(void) strlcpy(session.gpsdata.dev.path,
- "tcp://", sizeof(session.gpsdata.dev.path));
- else
- session.gpsdata.dev.path[0] = '\0';
- (void)strlcat(session.gpsdata.dev.path, devicename,
- sizeof(session.gpsdata.dev.path));
+ source.device,
+ sizeof(session.gpsdata.dev.path));
+ } else {
+ if (strstr(source.server, "//") == 0)
+ (void) strlcpy(session.gpsdata.dev.path,
+ "tcp://",
+ sizeof(session.gpsdata.dev.path));
+ else
+ session.gpsdata.dev.path[0] = '\0';
+ (void)snprintf(session.gpsdata.dev.path + strlen(session.gpsdata.dev.path),
+ sizeof(session.gpsdata.dev.path) - strlen(session.gpsdata.dev.path),
+ "%s:%s", source.server, source.port);
+ }
if (gpsd_activate(&session, O_PROBEONLY) == -1) {
(void)fprintf(stderr,
@@ -1201,7 +1219,6 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
- serial = (strncmp(devicename, "/dev", 4) == 0);
if (serial) {
#ifdef PPS_ENABLE
@@ -1210,8 +1227,10 @@ int main(int argc, char **argv)
#endif /* PPS_ENABLE */
}
else {
- /* FIXME: Also use WATCH*DEVICE here someday */
- (void)gps_send(&session.gpsdata, nmea ? WATCHNMEA : WATCHRAW);
+ if (source.device != NULL)
+ (void)gps_send(&session.gpsdata, nmea ? WATCHNMEADEVICE : WATCHRAWDEVICE, source.device);
+ else
+ (void)gps_send(&session.gpsdata, nmea ? WATCHNMEA : WATCHRAW);
}
/*
diff --git a/gpsmon.xml b/gpsmon.xml
index 559f47aa..1dc50464 100644
--- a/gpsmon.xml
+++ b/gpsmon.xml
@@ -76,14 +76,37 @@ version and exit.</para>
the <application>gpsd</application> daemon (and its associated control
socket) or directly connected to a specified serial device. When run
with no argument, it attempts to connect to the daemon. If the
-argument looks like a server:port specification it will also attempt
+argument begins with a server:port specification it will also attempt
to connect to the daemon. If the argument looks like a bare server
name it will attempt to connect to a daemon running on the default
gpsd port on that server. Only if the device argument contains
slashes but no colons will it be treated as a serial device for direct
connection. In direct-connect mode <application>gpsmon</application>
will hunt for a correct baud rate and lock on to it
-automatically.</para>
+automatically. Possible cases look like this:</para>
+
+<variablelist>
+<varlistentry>
+<term>localhost:/dev/ttyS1</term>
+<listitem><para>Look at the default port of localhost, trying both
+IPv4 and IPv6 and watching output from serial device 1.</para></listitem>
+</varlistentry>
+<varlistentry>
+<term>example.com:2317</term>
+<listitem><para>Look at port 2317 on example.com, trying both
+IPv4 and IPv6.</para></listitem>
+</varlistentry>
+<varlistentry>
+<term>71.162.241.5:2317:/dev/ttyS3</term>
+<listitem><para>Look at port 2317 at the specified IPv4
+address, collecting data from attached serial device 3.</para></listitem>
+</varlistentry>
+<varlistentry>
+<term>[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:2317:/dev/ttyS5</term>
+<listitem><para>Look at port 2317 at the specified IPv6
+address, collecting data from attached serial device 5.</para></listitem>
+</varlistentry>
+</variablelist>
<para>Unlike <application>gpsd</application>,
<application>gpsmon</application> run in direct mode does not do its