Fix several bugs in input/output fromat

Thanks to vk1et for these.

1) Correct for additional timestamp langth in raw output buffer when
using mlat mode

2) Don't output a timestamp when the message has been received from a
remote site (the internet). This is to avoid upsetting MLAT because
there is an indeterminate delay between reception at the remote site and
subsequent message arrival in the local dump1090 instance.

3) Allow @ character for raw data input with timestamp, and correctly
calculate the length.
This commit is contained in:
Malcolm Robb 2013-04-20 11:29:27 +01:00
parent 11265089b4
commit 39cb96f24b

View file

@ -56,7 +56,7 @@
// MinorVer changes when additional features are added, but not for bug fixes (range 00-99) // MinorVer changes when additional features are added, but not for bug fixes (range 00-99)
// DayDate & Year changes for all changes, including for bug fixes. It represent the release date of the update // DayDate & Year changes for all changes, including for bug fixes. It represent the release date of the update
// //
#define MODES_DUMP1090_VERSION "1.01.1924.13" #define MODES_DUMP1090_VERSION "1.01.2004.13"
#define MODES_DEFAULT_RATE 2000000 #define MODES_DEFAULT_RATE 2000000
#define MODES_DEFAULT_FREQ 1090000000 #define MODES_DEFAULT_FREQ 1090000000
@ -2265,6 +2265,7 @@ void modesSendRawOutput(struct modesMessage *mm) {
sprintf(p, "%02X", pTimeStamp[j]); sprintf(p, "%02X", pTimeStamp[j]);
p += 2; p += 2;
} }
Modes.rawOutUsed += 12; // additional 12 characters for timestamp
} else } else
*p++ = '*'; *p++ = '*';
@ -2307,16 +2308,21 @@ void modesSendSBSOutput(struct modesMessage *mm, struct aircraft *a) {
// ICAO address of the aircraft // ICAO address of the aircraft
pCommon += sprintf(pCommon, "111,11111,%02X%02X%02X,111111,", mm->aa1, mm->aa2, mm->aa3); pCommon += sprintf(pCommon, "111,11111,%02X%02X%02X,111111,", mm->aa1, mm->aa2, mm->aa3);
// Do the records' time and date now // Make sure the records' timestamp is valid before outputing it
epocTime = Modes.stSystemTimeBlk; // This is the time of the start of the Block we're processing if (mm->timestampMsg != (uint64_t)(-1)) {
offset = (int) (mm->timestampMsg - Modes.timestampBlk); // This is the time (in 12Mhz ticks) into the Block // Do the records' time and date now
offset = offset / 12000; // convert to milliseconds epocTime = Modes.stSystemTimeBlk; // This is the time of the start of the Block we're processing
epocTime.millitm += offset; // add on the offset time to the Block start time offset = (int) (mm->timestampMsg - Modes.timestampBlk); // This is the time (in 12Mhz ticks) into the Block
if (epocTime.millitm > 999) // if we've caused an overflow into the next second... offset = offset / 12000; // convert to milliseconds
{epocTime.millitm -= 1000; epocTime.time ++;} // ..correct the overflow epocTime.millitm += offset; // add on the offset time to the Block start time
stTime = *localtime(&epocTime.time); // convert the time to year, month day, hours, min, sec if (epocTime.millitm > 999) // if we've caused an overflow into the next second...
pCommon += sprintf(pCommon, "%04d/%02d/%02d,", (stTime.tm_year+1900),(stTime.tm_mon+1), stTime.tm_mday); {epocTime.millitm -= 1000; epocTime.time ++;} // ..correct the overflow
pCommon += sprintf(pCommon, "%02d:%02d:%02d.%03d,", stTime.tm_hour, stTime.tm_min, stTime.tm_sec, epocTime.millitm); stTime = *localtime(&epocTime.time); // convert the time to year, month day, hours, min, sec
pCommon += sprintf(pCommon, "%04d/%02d/%02d,", (stTime.tm_year+1900),(stTime.tm_mon+1), stTime.tm_mday);
pCommon += sprintf(pCommon, "%02d:%02d:%02d.%03d,", stTime.tm_hour, stTime.tm_min, stTime.tm_sec, epocTime.millitm);
} else {
pCommon += sprintf(pCommon, ",,");
}
// Do the current time and date now // Do the current time and date now
ftime(&epocTime); // get the current system time & date ftime(&epocTime); // get the current system time & date
@ -2402,8 +2408,12 @@ int decodeHexMessage(struct client *c) {
} }
/* Turn the message into binary. */ /* Turn the message into binary. */
if (l < 2 || hex[0] != '*' || hex[l-1] != ';') return 0; if (l < 2 || (hex[0] != '*' && hex[0] != '@') || hex[l-1] != ';') return 0;
hex++; l-=2; /* Skip * and ; */ if (hex[0] == '@') {
hex += 13; l -= 15; // Skip @, and timestamp, and ;
} else {
hex++; l-=2; // Skip * and ;
}
if (l > MODES_LONG_MSG_BYTES*2) return 0; /* Too long message... broken. */ if (l > MODES_LONG_MSG_BYTES*2) return 0; /* Too long message... broken. */
for (j = 0; j < l; j += 2) { for (j = 0; j < l; j += 2) {
int high = hexDigitVal(hex[j]); int high = hexDigitVal(hex[j]);
@ -2412,6 +2422,10 @@ int decodeHexMessage(struct client *c) {
if (high == -1 || low == -1) return 0; if (high == -1 || low == -1) return 0;
msg[j/2] = (high<<4) | low; msg[j/2] = (high<<4) | low;
} }
// Always mark the timestamp as invalid for packets received over the internet
// Mixing of data from two or more different receivers and publishing
// as coming from one would lead to corrupt mlat data
// Non timemarked internet data has indeterminate delay
mm.timestampMsg = -1; mm.timestampMsg = -1;
mm.signalLevel = -1; mm.signalLevel = -1;
decodeModesMessage(&mm,msg); decodeModesMessage(&mm,msg);