aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKing Kévin <kingkevin@cuvoodoo.info>2020-01-09 11:36:55 +0100
committerKing Kévin <kingkevin@cuvoodoo.info>2020-01-09 11:36:55 +0100
commit471e8dab205852c5e558b3e03ba4ee1145f3f57d (patch)
treee35152689b1636dd9ce07110ab4378d784b591b0
parenta52d5ed06947d1bfb2a70e39f7b9ad2c3ebee1a2 (diff)
u2_usb: add watchdog
-rw-r--r--u2_usb.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/u2_usb.c b/u2_usb.c
index e368051..0f26787 100644
--- a/u2_usb.c
+++ b/u2_usb.c
@@ -25,6 +25,8 @@
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
+#include <unistd.h>
+#include <signal.h>
#include <hidapi/hidapi.h>
#include <netdb.h>
@@ -39,6 +41,15 @@ static void die(const char* format, ...)
exit(1);
}
+/* watchdog called after alarm timeout
+ * @param[in] sig alarm signal
+ */
+static void watchdog(int sig)
+{
+ (void)sig; // argument not used
+ die("exiting due to inactivity\n");
+}
+
/* original trigger message from vendor software
"\xff\x55\x58\x8a\x13\x79\x06\x57\x1a\x01\x0a\x02\x00\x00\x00\x00" \
"\x5e\x00\x00\x00\xff\x55\x2f\xb2\x8b\xdc\x5a\xd4\x1a\x2c\xa4\x00" \
@@ -121,6 +132,9 @@ int main(int argc, char* argv[])
}
}
+ signal(SIGALRM, watchdog); // setup watchdog
+ alarm(5); // start watchdog (in case connecting to the U2 gets stuck)
+
// UDP socket to send data to influxdb
int influxdb_fd = 0;
struct addrinfo* res = 0;
@@ -200,8 +214,11 @@ int main(int argc, char* argv[])
if (debug) {
printf("trigger measurement\n");
}
+ continue;
}
+ alarm(5); // restart watchdog
+
// parse measurement values
meas.seconds = meas.payload[2];
meas.increment1 = meas.payload[3];