summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 293131a)
raw | patch | inline | side by side (parent: 293131a)
author | Florian Forster <octo@collectd.org> | |
Fri, 20 Nov 2015 13:57:07 +0000 (14:57 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Fri, 20 Nov 2015 13:57:07 +0000 (14:57 +0100) |
This allows to specify sub-second precision in the usual manner in the
config file.
config file.
src/gps.c | patch | blob | history | |
src/gps.pod | patch | blob | history |
diff --git a/src/gps.c b/src/gps.c
index b4a273ebc6aaaec28979ae1767abf16820c36118..cdbad791b9f4720c5078d014698c690d7ccf6001 100644 (file)
--- a/src/gps.c
+++ b/src/gps.c
#define GPS_DEFAULT_HOST "localhost"
#define GPS_DEFAULT_PORT "2947"
-#define GPS_DEFAULT_TIMEOUT 15
-#define GPS_DEFAULT_PAUSE 1
+#define GPS_DEFAULT_TIMEOUT TIME_T_TO_CDTIME_T (15)
+#define GPS_DEFAULT_PAUSE TIME_T_TO_CDTIME_T (1)
#include <gps.h>
#include <pthread.h>
typedef struct {
char *host;
char *port;
- int timeout;
- int pause;
+ cdtime_t timeout;
+ cdtime_t pause;
} cgps_config_t;
typedef struct {
gauge_t vdop;
} cgps_data_t;
-static const char *config_keys[] =
-{
- "Host",
- "Port",
- "Timeout",
- "Pause"
-};
-static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
-
// Thread items:
static pthread_t connector = (pthread_t) 0;
while (1)
{
- if (!gps_waiting (&conn, config.timeout))
+ long timeout_us = CDTIME_T_TO_US (config.timeout);
+ if (!gps_waiting (&conn, (int) timeout_us))
{
- sleep (config.pause);
+ struct timespec pause_ns;
+ CDTIME_T_TO_TIMESPEC (config.pause, &pause_ns);
+ nanosleep (&pause_ns, NULL);
continue;
}
/**
* Read configuration.
*/
-static int cgps_config (const char *key, const char *value)
+static int cgps_config (oconfig_item_t *ci)
{
- char *endptr = NULL;
+ int i;
- if (strcasecmp (key, "Host") == 0)
+ for (i = 0; i < ci->children_num; i++)
{
- free (config.host);
- config.host = sstrdup (value);
- }
- else if (strcasecmp (key, "Port") == 0)
- {
- free (config.port);
- config.port = sstrdup (value);
- }
- else if (strcasecmp (key, "Timeout") == 0)
- {
- config.timeout = (int) (strtod(value, &endptr) * 1000);
- }
- else if (strcasecmp (key, "Pause") == 0)
- {
- config.pause = (int) (strtod (value, &endptr));
+ oconfig_item_t *child = ci->children + i;
+
+ if (strcasecmp ("Host", child->key) == 0)
+ cf_util_get_string (child, &config.host);
+ else if (strcasecmp ("Port", child->key) == 0)
+ cf_util_get_string (child, &config.port);
+ else if (strcasecmp ("Timeout", child->key) == 0)
+ cf_util_get_cdtime (child, &config.timeout);
+ else if (strcasecmp ("Pause", child->key) == 0)
+ cf_util_get_cdtime (child, &config.pause);
+ else
+ WARNING ("gps plugin: Ignoring unknown config option \"%s\".", child->key);
}
- return (0);
+ return 0;
}
/**
{
int status;
- DEBUG ("gps plugin: config{host: \"%s\", port: \"%s\", timeout: %d, pause: %d}",
- config.host, config.port, config.timeout, config.pause);
+ DEBUG ("gps plugin: config{host: \"%s\", port: \"%s\", timeout: %.3f, pause: %.3f}",
+ config.host, config.port,
+ CDTIME_T_TO_DOUBLE (config.timeout), CDTIME_T_TO_DOUBLE (config.pause));
status = plugin_thread_create (&connector, NULL, gps_collectd_thread, NULL);
if (status != 0)
config.timeout = GPS_DEFAULT_TIMEOUT;
config.pause = GPS_DEFAULT_PAUSE;
- plugin_register_config ("gps", cgps_config, config_keys, config_keys_num);
+ plugin_register_complex_config ("gps", cgps_config);
plugin_register_init ("gps", cgps_init);
plugin_register_read ("gps", cgps_read);
plugin_register_shutdown ("gps", cgps_shutdown);
diff --git a/src/gps.pod b/src/gps.pod
index 540a1627a056ed61da8360a322d815ba2b788b32..3148299bde6fdd2f9b5254d547c821020ffca9bd 100644 (file)
--- a/src/gps.pod
+++ b/src/gps.pod
The C<gps plugin> connects to gpsd on the host machine.
The host, port, timeout and pause are configurable.
-This is useful if you run an NTP server using a GPS for source and you want to monitor it.
-
-Mind your GPS must send $--GSA for having the data reported !
+This is useful if you run an NTP server using a GPS for source and you want to
+monitor it.
+Mind your GPS must send $--GSA for having the data reported!
=head1 OPTIONS
=over 4
-=item B<Host>
+=item B<Host> I<Host>
-The host on which gpsd runs (default localhost).
+The host on which gpsd runs. Defaults to B<localhost>.
-=item B<Port>
+=item B<Port> I<Port>
-Port to connect to gpsd on the host machine (with quotes), (default 2947).
+Port to connect to gpsd on the host machine. Defaults to B<2947>.
-=item B<Timeout>
+=item B<Timeout> I<Seconds>
Timeout in seconds (default 15 sec).
-=item B<Pause>
+=item B<Pause> I<Seconds>
Pause to apply between readings in seconds (default 1 sec).
=item B<satellites>
-Number of satellites in view.
-0 means no GPS are visible.
+Number of satellites used for fix (type instance "used") and in view (type
+instance "visible"). 0 means no GPS satellites are visible.
=item B<dilution_of_precision>
-Vertical or horizontal dilution.
+Vertical and horizontal dilution.
It should be between 0 and 3.
Look at the documentaiton of your GPS to know more.
-
=head1 SEE ALSO
L<collectd(1)>,