summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6ca1473)
raw | patch | inline | side by side (parent: 6ca1473)
author | Nicolas JOURDEN <nicolas.jourden@laposte.net> | |
Fri, 20 Nov 2015 16:27:55 +0000 (17:27 +0100) | ||
committer | Nicolas JOURDEN <nicolas.jourden@laposte.net> | |
Fri, 20 Nov 2015 16:27:55 +0000 (17:27 +0100) |
src/gps.c | patch | blob | history |
diff --git a/src/gps.c b/src/gps.c
index e793cfa6c744d1920b1c7a0598d6892d5ee6022e..944932ab27c7b9a3f7e34ffa840858e8b0cb3250 100644 (file)
--- a/src/gps.c
+++ b/src/gps.c
#define GPS_DEFAULT_PORT "2947"
#define GPS_DEFAULT_TIMEOUT TIME_T_TO_CDTIME_T (15)
#define GPS_DEFAULT_PAUSE TIME_T_TO_CDTIME_T (1)
+#define GPS_MAX_ERROR 100
+#define GPS_CONFIG "?WATCH={\"enable\":true,\"json\":true,\"nmea\":false}\r\n"
#include <gps.h>
#include <pthread.h>
/**
* Thread reading from gpsd.
*/
-static void * gps_collectd_thread (void * pData)
+static void * cgps_thread (void * pData)
{
struct gps_data_t conn;
+ int err_count;
while (1)
{
+ err_count = 0;
+
int status = gps_open (config.host, config.port, &conn);
if (status < 0)
{
}
gps_stream (&conn, WATCH_ENABLE | WATCH_JSON | WATCH_NEWSTYLE, NULL);
- gps_send (&conn, "?WATCH={\"enable\":true,\"json\":true,\"nmea\":false}\r\n");
+ gps_send (&conn, GPS_CONFIG);
while (1)
{
- long timeout_us = CDTIME_T_TO_US (config.timeout);
- if (!gps_waiting (&conn, (int) timeout_us))
+ long timeout_ms = CDTIME_T_TO_MS (config.timeout);
+ if (!gps_waiting (&conn, (int) timeout_ms))
{
struct timespec pause_ns;
CDTIME_T_TO_TIMESPEC (config.pause, &pause_ns);
if (gps_read (&conn) == -1)
{
- WARNING ("gps plugin: incorrect data!");
+ WARNING ("gps plugin: incorrect data! (err_count: %d)", err_count);
+ err_count++;
+
+ if (err_count > GPS_MAX_ERROR)
+ {
+ // Server is not responding ...
+ if (gps_send (&conn, GPS_CONFIG) == -1)
+ {
+ WARNING ("gps plugin: gpsd seems to be done, reconnecting");
+ break;
+ }
+ // Server is responding ...
+ else
+ {
+ err_count = 0;
+ }
+ }
+
continue;
}
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);
+ status = plugin_thread_create (&connector, NULL, cgps_thread, NULL);
if (status != 0)
{
ERROR ("gps plugin: pthread_create() failed.");