pud: use gpsd fetch timer
authorFerry Huberts <ferry.huberts@pelagic.nl>
Fri, 29 Jul 2016 07:56:54 +0000 (09:56 +0200)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Fri, 29 Jul 2016 11:40:01 +0000 (13:40 +0200)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/pud/src/receiver.c

index 8926576..b4e1bc8 100644 (file)
@@ -450,6 +450,16 @@ static bool writePositionOutputFile(void) {
  * Timer Callbacks
  */
 
+/**
+ The gpsd fetch timer callback
+
+ @param context
+ unused
+ */
+static void pud_gpsd_fetch_timer_callback(void *context __attribute__ ((unused))) {
+  // FIXME
+}
+
 /**
  The OLSR tx timer callback
 
@@ -470,6 +480,19 @@ static void pud_uplink_timer_callback(void *context __attribute__ ((unused))) {
        txToAllOlsrInterfaces(TX_INTERFACE_UPLINK);
 }
 
+/**
+ Restart the gpsd fetch timer
+ */
+static void restartGpsdTimer(void) {
+  if (!getGpsd()) {
+    return;
+  }
+
+  if (!restartGpsdFetchTimer(&pud_gpsd_fetch_timer_callback)) {
+    pudError(0, "Could not restart gpsd fetch timer, no position information will be available");
+  }
+}
+
 /**
  Restart the OLSR tx timer
  */
@@ -994,6 +1017,11 @@ bool startReceiver(void) {
 
        initPositionAverageList(&positionAverageList, getAverageDepth());
 
+       if (!initGpsdFetchTimer()) {
+         stopReceiver();
+         return false;
+       }
+
        if (!initOlsrTxTimer()) {
                stopReceiver();
                return false;
@@ -1018,6 +1046,7 @@ bool startReceiver(void) {
        }
 
        externalState = getExternalState();
+       restartGpsdTimer();
        restartOlsrTimer(externalState);
        restartUplinkTimer(externalState);
        if (!restartGatewayTimer(getGatewayDeterminationInterval(), &pud_gateway_timer_callback)) {
@@ -1040,6 +1069,7 @@ void stopReceiver(void) {
        destroyGatewayTimer();
        destroyUplinkTxTimer();
        destroyOlsrTxTimer();
+       destroyGpsdFetchTimer();
 
        destroyPositionAverageList(&positionAverageList);