From dad9adb852c5baf35675c527bafc1fb0fc0715f4 Mon Sep 17 00:00:00 2001 From: Jon Williams Date: Wed, 30 Mar 2016 17:21:56 -0400 Subject: [PATCH 1/2] replace ftime() with gettimeofday() --- .gitignore | 2 +- dump1090.c | 6 +++--- dump1090.h | 5 ++--- net_io.c | 20 ++++++++++---------- ppup1090.h | 1 - view1090.h | 1 - winstubs.h | 1 - 7 files changed, 16 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 67495f9db..f2588a80b 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,4 @@ frames.js *~ *.rej *.orig -untrackedDeveloperSettings.js \ No newline at end of file +untrackedDeveloperSettings.jsview1090 diff --git a/dump1090.c b/dump1090.c index 60882fc73..7927ddbb8 100644 --- a/dump1090.c +++ b/dump1090.c @@ -138,7 +138,7 @@ void modesInit(void) { {Modes.net_sndbuf_size = MODES_NET_SNDBUF_MAX;} // Initialise the Block Timers to something half sensible - ftime(&Modes.stSystemTimeBlk); + gettimeofday(&Modes.stSystemTimeBlk, NULL); for (i = 0; i < MODES_ASYNC_BUF_NUMBER; i++) {Modes.stSystemTimeRTL[i] = Modes.stSystemTimeBlk;} @@ -262,7 +262,7 @@ void rtlsdrCallback(unsigned char *buf, uint32_t len, void *ctx) { Modes.iDataIn &= (MODES_ASYNC_BUF_NUMBER-1); // Just incase!!! // Get the system time for this block - ftime(&Modes.stSystemTimeRTL[Modes.iDataIn]); + gettimeofday(&Modes.stSystemTimeRTL[Modes.iDataIn], NULL); if (len > MODES_ASYNC_BUF_SIZE) {len = MODES_ASYNC_BUF_SIZE;} @@ -330,7 +330,7 @@ void readDataFromFile(void) { Modes.iDataIn &= (MODES_ASYNC_BUF_NUMBER-1); // Just incase!!! // Get the system time for this block - ftime(&Modes.stSystemTimeRTL[Modes.iDataIn]); + gettimeofday(&Modes.stSystemTimeRTL[Modes.iDataIn], NULL); // Queue the new data Modes.pData[Modes.iDataIn] = Modes.pFileData; diff --git a/dump1090.h b/dump1090.h index 9ad4de037..f45b80805 100644 --- a/dump1090.h +++ b/dump1090.h @@ -51,7 +51,6 @@ #include #include #include - #include #include #include #include @@ -244,7 +243,7 @@ struct { // Internal state pthread_mutex_t data_mutex; // Mutex to synchronize buffer access pthread_cond_t data_cond; // Conditional variable associated uint16_t *pData [MODES_ASYNC_BUF_NUMBER]; // Raw IQ sample buffers from RTL - struct timeb stSystemTimeRTL[MODES_ASYNC_BUF_NUMBER]; // System time when RTL passed us this block + struct timeval stSystemTimeRTL[MODES_ASYNC_BUF_NUMBER]; // System time when RTL passed us this block int iDataIn; // Fifo input pointer int iDataOut; // Fifo output pointer int iDataReady; // Fifo content count @@ -253,7 +252,7 @@ struct { // Internal state uint16_t *pFileData; // Raw IQ samples buffer (from a File) uint16_t *magnitude; // Magnitude vector uint64_t timestampBlk; // Timestamp of the start of the current block - struct timeb stSystemTimeBlk; // System time when RTL passed us currently processing this block + struct timeval stSystemTimeBlk; // System time when RTL passed us currently processing this block int fd; // --ifile option file descriptor uint32_t *icao_cache; // Recently seen ICAO addresses cache uint16_t *maglut; // I/Q -> Magnitude lookup table diff --git a/net_io.c b/net_io.c index a979883f5..5e2d96bdb 100644 --- a/net_io.c +++ b/net_io.c @@ -304,7 +304,7 @@ void modesSendRawOutput(struct modesMessage *mm) { void modesSendSBSOutput(struct modesMessage *mm) { char msg[256], *p = msg; uint32_t offset; - struct timeb epocTime_receive, epocTime_now; + struct timeval epocTime_receive, epocTime_now; struct tm stTime_receive, stTime_now; int msgType; @@ -348,20 +348,20 @@ void modesSendSBSOutput(struct modesMessage *mm) { p += sprintf(p, "MSG,%d,111,11111,%06X,111111,", msgType, mm->addr); // Find current system time - ftime(&epocTime_now); // get the current system time & date - stTime_now = *localtime(&epocTime_now.time); + gettimeofday(&epocTime_now, NULL); // get the current system time & date + stTime_now = *localtime(&epocTime_now.tv_sec); // Find message reception time if (mm->timestampMsg && !mm->remote) { // Make sure the records' timestamp is valid before using it epocTime_receive = Modes.stSystemTimeBlk; // This is the time of the start of the Block we're processing offset = (int) (mm->timestampMsg - Modes.timestampBlk); // This is the time (in 12Mhz ticks) into the Block offset = offset / 12000; // convert to milliseconds - epocTime_receive.millitm += offset; // add on the offset time to the Block start time - if (epocTime_receive.millitm > 999) { // if we've caused an overflow into the next second... - epocTime_receive.millitm -= 1000; - epocTime_receive.time ++; // ..correct the overflow + epocTime_receive.tv_usec += offset; // add on the offset time to the Block start time + if (epocTime_receive.tv_usec > 999) { // if we've caused an overflow into the next second... + epocTime_receive.tv_usec -= 1000; + epocTime_receive.tv_sec ++; // ..correct the overflow } - stTime_receive = *localtime(&epocTime_receive.time); + stTime_receive = *localtime(&epocTime_receive.tv_sec); } else { epocTime_receive = epocTime_now; // We don't have a usable reception time; use the current system time stTime_receive = stTime_now; @@ -369,11 +369,11 @@ void modesSendSBSOutput(struct modesMessage *mm) { // Fields 7 & 8 are the message reception time and date p += sprintf(p, "%04d/%02d/%02d,", (stTime_receive.tm_year+1900),(stTime_receive.tm_mon+1), stTime_receive.tm_mday); - p += sprintf(p, "%02d:%02d:%02d.%03d,", stTime_receive.tm_hour, stTime_receive.tm_min, stTime_receive.tm_sec, epocTime_receive.millitm); + p += sprintf(p, "%02d:%02d:%02d.%03d,", stTime_receive.tm_hour, stTime_receive.tm_min, stTime_receive.tm_sec, epocTime_receive.tv_usec); // Fields 9 & 10 are the current time and date p += sprintf(p, "%04d/%02d/%02d,", (stTime_now.tm_year+1900),(stTime_now.tm_mon+1), stTime_now.tm_mday); - p += sprintf(p, "%02d:%02d:%02d.%03d", stTime_now.tm_hour, stTime_now.tm_min, stTime_now.tm_sec, epocTime_now.millitm); + p += sprintf(p, "%02d:%02d:%02d.%03d", stTime_now.tm_hour, stTime_now.tm_min, stTime_now.tm_sec, epocTime_now.tv_usec); // Field 11 is the callsign (if we have it) if (mm->bFlags & MODES_ACFLAGS_CALLSIGN_VALID) {p += sprintf(p, ",%s", mm->flight);} diff --git a/ppup1090.h b/ppup1090.h index 6d0756d8f..716f1e384 100644 --- a/ppup1090.h +++ b/ppup1090.h @@ -44,7 +44,6 @@ #include #include #include - #include #include #include #include diff --git a/view1090.h b/view1090.h index 03ad96d11..6b15c3bc1 100644 --- a/view1090.h +++ b/view1090.h @@ -44,7 +44,6 @@ #include #include #include - #include #include #include #include diff --git a/winstubs.h b/winstubs.h index f3ab63fe7..e6778200d 100644 --- a/winstubs.h +++ b/winstubs.h @@ -51,7 +51,6 @@ typedef int socklen_t; #include #include -#include #include #include #include From 47f5f42f4e878c4f689300ad0a02389eb14f53c3 Mon Sep 17 00:00:00 2001 From: Jon Williams Date: Wed, 30 Mar 2016 17:45:05 -0400 Subject: [PATCH 2/2] gitignore view1090 --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f2588a80b..35355ea8c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ frames.js *~ *.rej *.orig -untrackedDeveloperSettings.jsview1090 +untrackedDeveloperSettings.js +view1090