Store computed reception time in the message struct so we don't rely on
the message being emitted immediately. Fix computation of reception time so it's more sensible (the block timestamp is some time after reception of the _end_ of the block, not the start) - this means that message-emission times are always later than message-reception times in SBS output, which is a bit more sensible. Use clock_gettime in preference to ftime.
This commit is contained in:
parent
1584955080
commit
4e177c2d64
7 changed files with 76 additions and 31 deletions
41
net_io.c
41
net_io.c
|
|
@ -347,19 +347,19 @@ void modesSendRawOutput(struct modesMessage *mm) {
|
|||
// The message structure mm->bFlags tells us what has been updated by this message
|
||||
//
|
||||
void modesSendSBSOutput(struct modesMessage *mm) {
|
||||
char *p = prepareWrite(&Modes.sbs_out, 200);
|
||||
uint32_t offset;
|
||||
struct timeb epocTime_receive, epocTime_now;
|
||||
char *p;
|
||||
struct timespec now;
|
||||
struct tm stTime_receive, stTime_now;
|
||||
int msgType;
|
||||
|
||||
if (!p)
|
||||
return;
|
||||
|
||||
// For now, suppress non-ICAO addresses
|
||||
if (mm->addr & MODES_NON_ICAO_ADDRESS)
|
||||
return;
|
||||
|
||||
p = prepareWrite(&Modes.sbs_out, 200);
|
||||
if (!p)
|
||||
return;
|
||||
|
||||
//
|
||||
// SBS BS style output checked against the following reference
|
||||
// http://www.homepages.mcb.net/bones/SBS/Article/Barebones42_Socket_Data.htm - seems comprehensive
|
||||
|
|
@ -407,32 +407,19 @@ 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);
|
||||
clock_gettime(CLOCK_REALTIME, &now);
|
||||
localtime_r(&now.tv_sec, &stTime_now);
|
||||
|
||||
// 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
|
||||
}
|
||||
stTime_receive = *localtime(&epocTime_receive.time);
|
||||
} else {
|
||||
epocTime_receive = epocTime_now; // We don't have a usable reception time; use the current system time
|
||||
stTime_receive = stTime_now;
|
||||
}
|
||||
localtime_r(&mm->sysTimestampMsg.tv_sec, &stTime_receive);
|
||||
|
||||
// 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.%03u,", stTime_receive.tm_hour, stTime_receive.tm_min, stTime_receive.tm_sec, (unsigned) (mm->sysTimestampMsg.tv_nsec / 1000000U));
|
||||
|
||||
// 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.%03u", stTime_now.tm_hour, stTime_now.tm_min, stTime_now.tm_sec, (unsigned) (now.tv_nsec / 1000000U));
|
||||
|
||||
// Field 11 is the callsign (if we have it)
|
||||
if (mm->bFlags & MODES_ACFLAGS_CALLSIGN_VALID) {p += sprintf(p, ",%s", mm->flight);}
|
||||
|
|
@ -574,6 +561,9 @@ int decodeBinMessage(struct client *c, char *p) {
|
|||
if (0x1A == ch) {p++;}
|
||||
}
|
||||
|
||||
// record reception time as the time we read it.
|
||||
clock_gettime(CLOCK_REALTIME, &mm.sysTimestampMsg);
|
||||
|
||||
ch = *p++; // Grab the signal level
|
||||
mm.signalLevel = ((unsigned char)ch / 256.0);
|
||||
mm.signalLevel = mm.signalLevel * mm.signalLevel + 1e-5;
|
||||
|
|
@ -697,6 +687,9 @@ int decodeHexMessage(struct client *c, char *hex) {
|
|||
msg[j/2] = (high << 4) | low;
|
||||
}
|
||||
|
||||
// record reception time as the time we read it.
|
||||
clock_gettime(CLOCK_REALTIME, &mm.sysTimestampMsg);
|
||||
|
||||
if (l == (MODEAC_MSG_BYTES * 2)) { // ModeA or ModeC
|
||||
Modes.stats_current.remote_received_modeac++;
|
||||
decodeModeAMessage(&mm, ((msg[0] << 8) | msg[1]));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue