Skip to content
This repository was archived by the owner on Sep 14, 2019. It is now read-only.

Commit

Permalink
Include timestamps on USB connect/disconnect logging.
Browse files Browse the repository at this point in the history
Fixes #21.
  • Loading branch information
mutability committed Feb 17, 2015
1 parent af4f81c commit 342eafd
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions dump1090.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,38 @@

#include "dump1090.h"

#include <stdarg.h>

static int verbose_device_search(char *s);

//
// ============================= Utility functions ==========================
//
void sigintHandler(int dummy) {

static void log_with_timestamp(const char *format, ...) __attribute__((format (printf, 1, 2) ));

static void log_with_timestamp(const char *format, ...)
{
char timebuf[128];
char msg[1024];
time_t now;
struct tm local;
va_list ap;

now = time(NULL);
localtime_r(&now, &local);
strftime(timebuf, 128, "%c %Z", &local);
timebuf[127] = 0;

va_start(ap, format);
vsnprintf(msg, 1024, format, ap);
va_end(ap);
msg[1023] = 0;

fprintf(stderr, "%s %s\n", timebuf, msg);
}

MODES_NOTUSED(dummy);
signal(SIGINT, SIG_DFL); // reset signal handler - bit extra safety
Modes.exit = 1; // Signal to threads that we are done
Expand Down Expand Up @@ -467,13 +493,13 @@ void *readerThreadEntryPoint(void *arg) {
MODES_ASYNC_BUF_SIZE);

if (!Modes.exit) {
fprintf(stderr, "Warning: lost the connection to the RTLSDR device.\n");
log_with_timestamp("Warning: lost the connection to the RTLSDR device.");
rtlsdr_close(Modes.dev);
Modes.dev = NULL;

do {
sleep(5);
fprintf(stderr, "Trying to reconnect to the RTLSDR device..\n");
log_with_timestamp("Trying to reconnect to the RTLSDR device..");
} while (!Modes.exit && modesInitRTLSDR() < 0);
}
}
Expand Down

0 comments on commit 342eafd

Please sign in to comment.