Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace ftime() with gettimeofday() #82

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ frames.js
*~
*.rej
*.orig
untrackedDeveloperSettings.js
untrackedDeveloperSettings.js
view1090
6 changes: 3 additions & 3 deletions dump1090.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;}

Expand Down Expand Up @@ -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;}

Expand Down Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions dump1090.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
#include <unistd.h>
#include <math.h>
#include <sys/time.h>
#include <sys/timeb.h>
#include <signal.h>
#include <fcntl.h>
#include <ctype.h>
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
20 changes: 10 additions & 10 deletions net_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -348,32 +348,32 @@ 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;
}

// 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);}
Expand Down
1 change: 0 additions & 1 deletion ppup1090.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#include <unistd.h>
#include <math.h>
#include <sys/time.h>
#include <sys/timeb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
Expand Down
1 change: 0 additions & 1 deletion view1090.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#include <unistd.h>
#include <math.h>
#include <sys/time.h>
#include <sys/timeb.h>
#include <signal.h>
#include <fcntl.h>
#include <ctype.h>
Expand Down
1 change: 0 additions & 1 deletion winstubs.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ typedef int socklen_t;

#include <stdio.h>
#include <time.h>
#include <sys/timeb.h>
#include <sys/stat.h>
#include <signal.h>
#include <io.h>
Expand Down