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

Big endian timestamp fixes #69

Open
wants to merge 4 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
11 changes: 5 additions & 6 deletions mode_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
//

#include "dump1090.h"

/* for PRIX64 */
#include <inttypes.h>

//
// ===================== Mode S detection and decoding ===================
//
Expand Down Expand Up @@ -1144,7 +1148,6 @@ void decodeModesMessage(struct modesMessage *mm, unsigned char *msg) {
//
void displayModesMessage(struct modesMessage *mm) {
int j;
unsigned char * pTimeStamp;

// Handle only addresses mode first.
if (Modes.onlyaddr) {
Expand All @@ -1154,11 +1157,7 @@ void displayModesMessage(struct modesMessage *mm) {

// Show the raw message.
if (Modes.mlat && mm->timestampMsg) {
printf("@");
pTimeStamp = (unsigned char *) &mm->timestampMsg;
for (j=5; j>=0;j--) {
printf("%02X",pTimeStamp[j]);
}
printf("@%012" PRIX64, mm->timestampMsg);
} else
printf("*");

Expand Down
43 changes: 26 additions & 17 deletions net_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
//

#include "dump1090.h"

/* for PRIX64 */
#include <inttypes.h>

//
// ============================= Networking =============================
//
Expand Down Expand Up @@ -220,7 +224,6 @@ void modesSendAllClients(int service, void *msg, int len) {
void modesSendBeastOutput(struct modesMessage *mm) {
char *p = &Modes.beastOut[Modes.beastOutUsed];
int msgLen = mm->msgbits / 8;
char * pTimeStamp;
char ch;
int j;
int iOutLen = msgLen + 9; // Escape, msgtype, timestamp, sigLevel, msg
Expand All @@ -235,11 +238,19 @@ void modesSendBeastOutput(struct modesMessage *mm) {
else
{return;}

pTimeStamp = (char *) &mm->timestampMsg;
for (j = 5; j >= 0; j--) {
*p++ = (ch = pTimeStamp[j]);
if (0x1A == ch) {*p++ = ch; iOutLen++;}
}
/* timestamp, big-endian */
*p++ = (ch = (mm->timestampMsg >> 40));
if (0x1A == ch) {*p++ = ch; iOutLen++;}
*p++ = (ch = (mm->timestampMsg >> 32));
if (0x1A == ch) {*p++ = ch; iOutLen++; }
*p++ = (ch = (mm->timestampMsg >> 24));
if (0x1A == ch) {*p++ = ch; iOutLen++;}
*p++ = (ch = (mm->timestampMsg >> 16));
if (0x1A == ch) {*p++ = ch; iOutLen++;}
*p++ = (ch = (mm->timestampMsg >> 8));
if (0x1A == ch) {*p++ = ch; iOutLen++;}
*p++ = (ch = (mm->timestampMsg));
if (0x1A == ch) {*p++ = ch; iOutLen++;}

*p++ = (ch = mm->signalLevel);
if (0x1A == ch) {*p++ = ch; iOutLen++;}
Expand All @@ -266,15 +277,12 @@ void modesSendRawOutput(struct modesMessage *mm) {
char *p = &Modes.rawOut[Modes.rawOutUsed];
int msgLen = mm->msgbits / 8;
int j;
unsigned char * pTimeStamp;

if (Modes.mlat && mm->timestampMsg) {
*p++ = '@';
pTimeStamp = (unsigned char *) &mm->timestampMsg;
for (j = 5; j >= 0; j--) {
sprintf(p, "%02X", pTimeStamp[j]);
p += 2;
}
/* timestamp, big-endian */
sprintf(p, "@%012" PRIX64,
mm->timestampMsg);
p += 13;
Modes.rawOutUsed += 12; // additional 12 characters for timestamp
} else
*p++ = '*';
Expand Down Expand Up @@ -486,7 +494,6 @@ int decodeBinMessage(struct client *c, char *p) {
int msgLen = 0;
int j;
char ch;
char * ptr;
unsigned char msg[MODES_LONG_MSG_BYTES];
struct modesMessage mm;
MODES_NOTUSED(c);
Expand All @@ -508,9 +515,11 @@ int decodeBinMessage(struct client *c, char *p) {
// pass them off as being received by this instance when forwarding them
mm.remote = 1;

ptr = (char*) &mm.timestampMsg;
for (j = 0; j < 6; j++) { // Grab the timestamp (big endian format)
ptr[5-j] = ch = *p++;
// Grab the timestamp (big endian format)
mm.timestampMsg = 0;
for (j = 0; j < 6; j++) {
ch = *p++;
mm.timestampMsg = mm.timestampMsg << 8 | (ch & 255);
if (0x1A == ch) {p++;}
}

Expand Down