u2_usb: add watchdog
This commit is contained in:
parent
a52d5ed069
commit
471e8dab20
17
u2_usb.c
17
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];
|
||||
|
|
Loading…
Reference in New Issue