Fix endian issues in timestamp input/output.
This affected Beast input/output, and AVR output in --mlat mode. Works on a little-endian host, should work on a big-endian host but I don't have one to test with. Probably fixes #44.
This commit is contained in:
parent
ff094519a6
commit
e9378fb1c5
2
debian/changelog
vendored
2
debian/changelog
vendored
|
@ -10,6 +10,8 @@ dump1090-mutability (1.15~dev) UNRELEASED; urgency=medium
|
||||||
* Rearrangements to the receive thread. Magnitude conversion now happens
|
* Rearrangements to the receive thread. Magnitude conversion now happens
|
||||||
immediately when sample data is received, so there is no risk of newly
|
immediately when sample data is received, so there is no risk of newly
|
||||||
received data clobbering old data under CPU overload.
|
received data clobbering old data under CPU overload.
|
||||||
|
* Fix endian issues affecting big-endian hosts in Beast input/output
|
||||||
|
and avrmlat output. (github issue #44)
|
||||||
|
|
||||||
-- Oliver Jowett <oliver@mutability.co.uk> Thu, 19 Feb 2015 22:39:19 +0000
|
-- Oliver Jowett <oliver@mutability.co.uk> Thu, 19 Feb 2015 22:39:19 +0000
|
||||||
|
|
||||||
|
|
42
net_io.c
42
net_io.c
|
@ -49,6 +49,9 @@
|
||||||
|
|
||||||
#include "dump1090.h"
|
#include "dump1090.h"
|
||||||
|
|
||||||
|
/* for PRIx64 */
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -270,7 +273,6 @@ static void completeWrite(struct net_writer *writer, void *endptr) {
|
||||||
void modesSendBeastOutput(struct modesMessage *mm) {
|
void modesSendBeastOutput(struct modesMessage *mm) {
|
||||||
int msgLen = mm->msgbits / 8;
|
int msgLen = mm->msgbits / 8;
|
||||||
char *p = prepareWrite(&Modes.beast_out, 2 + 2 * (7 + msgLen));
|
char *p = prepareWrite(&Modes.beast_out, 2 + 2 * (7 + msgLen));
|
||||||
char * pTimeStamp;
|
|
||||||
char ch;
|
char ch;
|
||||||
int j;
|
int j;
|
||||||
unsigned char *msg = (Modes.net_verbatim ? mm->verbatim : mm->msg);
|
unsigned char *msg = (Modes.net_verbatim ? mm->verbatim : mm->msg);
|
||||||
|
@ -288,11 +290,19 @@ void modesSendBeastOutput(struct modesMessage *mm) {
|
||||||
else
|
else
|
||||||
{return;}
|
{return;}
|
||||||
|
|
||||||
pTimeStamp = (char *) &mm->timestampMsg;
|
/* timestamp, big-endian */
|
||||||
for (j = 5; j >= 0; j--) {
|
*p++ = (ch = (mm->timestampMsg >> 40));
|
||||||
*p++ = (ch = pTimeStamp[j]);
|
if (0x1A == ch) {*p++ = ch; }
|
||||||
if (0x1A == ch) {*p++ = ch; }
|
*p++ = (ch = (mm->timestampMsg >> 32));
|
||||||
}
|
if (0x1A == ch) {*p++ = ch; }
|
||||||
|
*p++ = (ch = (mm->timestampMsg >> 24));
|
||||||
|
if (0x1A == ch) {*p++ = ch; }
|
||||||
|
*p++ = (ch = (mm->timestampMsg >> 16));
|
||||||
|
if (0x1A == ch) {*p++ = ch; }
|
||||||
|
*p++ = (ch = (mm->timestampMsg >> 8));
|
||||||
|
if (0x1A == ch) {*p++ = ch; }
|
||||||
|
*p++ = (ch = (mm->timestampMsg));
|
||||||
|
if (0x1A == ch) {*p++ = ch; }
|
||||||
|
|
||||||
*p++ = ch = (char) round(sqrt(mm->signalLevel) * 255);
|
*p++ = ch = (char) round(sqrt(mm->signalLevel) * 255);
|
||||||
if (0x1A == ch) {*p++ = ch; }
|
if (0x1A == ch) {*p++ = ch; }
|
||||||
|
@ -314,19 +324,16 @@ void modesSendRawOutput(struct modesMessage *mm) {
|
||||||
int msgLen = mm->msgbits / 8;
|
int msgLen = mm->msgbits / 8;
|
||||||
char *p = prepareWrite(&Modes.raw_out, msgLen*2 + 15);
|
char *p = prepareWrite(&Modes.raw_out, msgLen*2 + 15);
|
||||||
int j;
|
int j;
|
||||||
unsigned char * pTimeStamp;
|
|
||||||
unsigned char *msg = (Modes.net_verbatim ? mm->verbatim : mm->msg);
|
unsigned char *msg = (Modes.net_verbatim ? mm->verbatim : mm->msg);
|
||||||
|
|
||||||
if (!p)
|
if (!p)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (Modes.mlat && mm->timestampMsg) {
|
if (Modes.mlat && mm->timestampMsg) {
|
||||||
*p++ = '@';
|
/* timestamp, big-endian */
|
||||||
pTimeStamp = (unsigned char *) &mm->timestampMsg;
|
sprintf(p, "@%012" PRIx64,
|
||||||
for (j = 5; j >= 0; j--) {
|
mm->timestampMsg);
|
||||||
sprintf(p, "%02X", pTimeStamp[j]);
|
p += 13;
|
||||||
p += 2;
|
|
||||||
}
|
|
||||||
} else
|
} else
|
||||||
*p++ = '*';
|
*p++ = '*';
|
||||||
|
|
||||||
|
@ -533,7 +540,6 @@ int decodeBinMessage(struct client *c, char *p) {
|
||||||
int msgLen = 0;
|
int msgLen = 0;
|
||||||
int j;
|
int j;
|
||||||
char ch;
|
char ch;
|
||||||
char * ptr;
|
|
||||||
unsigned char msg[MODES_LONG_MSG_BYTES];
|
unsigned char msg[MODES_LONG_MSG_BYTES];
|
||||||
struct modesMessage mm;
|
struct modesMessage mm;
|
||||||
MODES_NOTUSED(c);
|
MODES_NOTUSED(c);
|
||||||
|
@ -555,9 +561,11 @@ int decodeBinMessage(struct client *c, char *p) {
|
||||||
// pass them off as being received by this instance when forwarding them
|
// pass them off as being received by this instance when forwarding them
|
||||||
mm.remote = 1;
|
mm.remote = 1;
|
||||||
|
|
||||||
ptr = (char*) &mm.timestampMsg;
|
// Grab the timestamp (big endian format)
|
||||||
for (j = 0; j < 6; j++) { // Grab the timestamp (big endian format)
|
mm.timestampMsg = 0;
|
||||||
ptr[5-j] = ch = *p++;
|
for (j = 0; j < 6; j++) {
|
||||||
|
ch = *p++;
|
||||||
|
mm.timestampMsg = mm.timestampMsg << 8 | (ch & 255);
|
||||||
if (0x1A == ch) {p++;}
|
if (0x1A == ch) {p++;}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue