changeset 83:c3e0cc003206

iothread: request device serial and version numbers every 30 mins This way we don't necessarily have to have the beginning of the log file to get info about which device was used to capture it. Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Sat, 29 Feb 2020 12:26:40 -0500
parents bbd273eb1075
children 14fb501082c9
files capture.c iothread.c iothread.h
diffstat 3 files changed, 35 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/capture.c	Sat Feb 29 11:22:48 2020 -0500
+++ b/capture.c	Sat Feb 29 12:26:40 2020 -0500
@@ -368,7 +368,7 @@
 		return 10;
 	}
 
-	ret = iothread_start(ifile, rfile, verbose);
+	ret = iothread_start(ifile, rfile, verbose, !input_readonly);
 	if (ret) {
 		fprintf(stderr, "Error: Failed to spawn I/O thread: %s\n",
 			xstrerror(ret));
--- a/iothread.c	Sat Feb 29 11:22:48 2020 -0500
+++ b/iothread.c	Sat Feb 29 12:26:40 2020 -0500
@@ -35,10 +35,13 @@
 #include "rfc1145.h"
 #include "frame.h"
 
+#define VERSION_POLL_INTERVAL (30 * 60 * 1000000000ull) /* 30 minutes */
+
 static pthread_t io_thread;
 static FILE *input_file;
 static FILE *log_file;
 static bool verbose;
+static bool poll_version;
 static uint32_t seq; /* message sequence number */
 
 /* read until we get the beginning of a NMEA or UBX message */
@@ -195,6 +198,7 @@
 
 static void *iothread_reader(void *data)
 {
+	uint64_t last_poll_time;
 	int ret;
 
 	ret = sync_reader();
@@ -204,6 +208,9 @@
 		return NULL;
 	}
 
+	/* setup already got it all */
+	last_poll_time = gettime();
+
 	/* read a NMEA or UBX message & process it */
 	for (;;) {
 		uint64_t start_tick;
@@ -240,16 +247,40 @@
 				xstrerror(ret));
 			return NULL;
 		}
+
+		if (poll_version &&
+		    ((start_time - last_poll_time) > VERSION_POLL_INTERVAL)) {
+			/* request the version and serial number */
+
+			/* request version info */
+			ret = send_ubx(input_file, UBX_MON_VER, NULL, 0);
+			if (ret) {
+				fprintf(stderr, "Failed to request periodic "
+					"version info: %s\n", xstrerror(ret));
+				return NULL;
+			}
+
+			/* request serial number */
+			ret = send_ubx(input_file, UBX_SEC_UNIQID, NULL, 0);
+			if (ret) {
+				fprintf(stderr, "Failed to request periodic "
+					"serial number: %s\n", xstrerror(ret));
+				return NULL;
+			}
+
+			last_poll_time = gettime();
+		}
 	}
 
 	return NULL;
 }
 
-int iothread_start(FILE *ifile, FILE *lfile, bool _verbose)
+int iothread_start(FILE *ifile, FILE *lfile, bool _verbose, bool _poll_version)
 {
 	input_file = ifile;
 	log_file = lfile;
 	verbose = _verbose;
+	poll_version = _poll_version;
 
 	return xthr_create(&io_thread, iothread_reader, NULL);
 }
--- a/iothread.h	Sat Feb 29 11:22:48 2020 -0500
+++ b/iothread.h	Sat Feb 29 12:26:40 2020 -0500
@@ -27,6 +27,7 @@
 
 #include <jeffpc/types.h>
 
-extern int iothread_start(FILE *ifile, FILE *lfile, bool verbose);
+extern int iothread_start(FILE *ifile, FILE *lfile, bool verbose,
+		          bool poll_version);
 
 #endif