Changes to prevent stale output in SBS-1 format
The original code calculates Lat/Long only if it receives two DF-17 (subtype 9 or 18) within one second of each other. I have no idea why. It then caches the results in the aircrafts data structure for use in the --interactive display. When SBS-1 style ASCII output is selected (port 30003) the code does not attempt to calculate Lat/Long from the data just received - instead it picks it up from the cached information in the aircraft's data structure. However, if the data isn't being updated this results in stale Lat/Long being sent out. This is most likely to occur when the aircraft is at the extreme edge of the receivers range when it may be getting some DF-17s containing Lat/Long, but not 2 per second. The program will continue sending the stale data until the aircraft finally times out (default 60 seconds) I have modified the code to include a sbsflags variable in the aircraft data structure. When a new Lat/Long is decoded and put into the structure, a bit is set to indicate SBS_LAT_LONG_FRESH. Then, once the Lat/Long is output the first time, the bit is cleared. Thereafter the code will not populate the Lat/Long fields in the output message until SBS_LAT_LONG_FRESH is set again.
This commit is contained in:
parent
bbcf68cf11
commit
3d25f4bf1a
13
dump1090.c
13
dump1090.c
|
@ -91,6 +91,8 @@
|
||||||
#define MODES_UNIT_FEET 0
|
#define MODES_UNIT_FEET 0
|
||||||
#define MODES_UNIT_METERS 1
|
#define MODES_UNIT_METERS 1
|
||||||
|
|
||||||
|
#define MODES_SBS_LAT_LONG_FRESH (1<<0)
|
||||||
|
|
||||||
#define MODES_DEBUG_DEMOD (1<<0)
|
#define MODES_DEBUG_DEMOD (1<<0)
|
||||||
#define MODES_DEBUG_DEMODERR (1<<1)
|
#define MODES_DEBUG_DEMODERR (1<<1)
|
||||||
#define MODES_DEBUG_BADCRC (1<<2)
|
#define MODES_DEBUG_BADCRC (1<<2)
|
||||||
|
@ -142,6 +144,7 @@ struct aircraft {
|
||||||
int even_cprlat;
|
int even_cprlat;
|
||||||
int even_cprlon;
|
int even_cprlon;
|
||||||
double lat, lon; /* Coordinated obtained from CPR encoded data. */
|
double lat, lon; /* Coordinated obtained from CPR encoded data. */
|
||||||
|
int sbsflags;
|
||||||
uint64_t odd_cprtime, even_cprtime;
|
uint64_t odd_cprtime, even_cprtime;
|
||||||
int squawk;
|
int squawk;
|
||||||
struct aircraft *next; /* Next aircraft in our linked list. */
|
struct aircraft *next; /* Next aircraft in our linked list. */
|
||||||
|
@ -1749,6 +1752,7 @@ struct aircraft *interactiveCreateAircraft(uint32_t addr) {
|
||||||
a->even_cprtime = 0;
|
a->even_cprtime = 0;
|
||||||
a->lat = 0;
|
a->lat = 0;
|
||||||
a->lon = 0;
|
a->lon = 0;
|
||||||
|
a->sbsflags = 0;
|
||||||
a->seen = time(NULL);
|
a->seen = time(NULL);
|
||||||
a->messages = 0;
|
a->messages = 0;
|
||||||
a->squawk = 0;
|
a->squawk = 0;
|
||||||
|
@ -1895,6 +1899,7 @@ void decodeCPR(struct aircraft *a) {
|
||||||
a->lat = rlat1;
|
a->lat = rlat1;
|
||||||
}
|
}
|
||||||
if (a->lon > 180) a->lon -= 360;
|
if (a->lon > 180) a->lon -= 360;
|
||||||
|
a->sbsflags |= MODES_SBS_LAT_LONG_FRESH;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Receive new messages and populate the interactive mode with more info. */
|
/* Receive new messages and populate the interactive mode with more info. */
|
||||||
|
@ -2331,15 +2336,17 @@ void modesSendSBSOutput(struct modesMessage *mm, struct aircraft *a) {
|
||||||
p += sprintf(p, "MSG,1,%s,%s,,,,,,,,0,0,0,0", strCommon, mm->flight);
|
p += sprintf(p, "MSG,1,%s,%s,,,,,,,,0,0,0,0", strCommon, mm->flight);
|
||||||
|
|
||||||
} else if (mm->msgtype == 17 && mm->metype >= 9 && mm->metype <= 18) {
|
} else if (mm->msgtype == 17 && mm->metype >= 9 && mm->metype <= 18) {
|
||||||
if (a->lat == 0 && a->lon == 0)
|
if ( ((a->lat == 0) && (a->lon == 0)) || ((a->sbsflags & MODES_SBS_LAT_LONG_FRESH) == 0) ){
|
||||||
p += sprintf(p, "MSG,3,%s,,%d,,,,,,,0,0,0,0", strCommon, mm->altitude);
|
p += sprintf(p, "MSG,3,%s,,%d,,,,,,,0,0,0,0", strCommon, mm->altitude);
|
||||||
else
|
} else {
|
||||||
p += sprintf(p, "MSG,3,%s,,%d,,,%1.5f,%1.5f,,,0,0,0,0", strCommon, mm->altitude, a->lat, a->lon);
|
p += sprintf(p, "MSG,3,%s,,%d,,,%1.5f,%1.5f,,,0,0,0,0", strCommon, mm->altitude, a->lat, a->lon);
|
||||||
|
a->sbsflags &= ~MODES_SBS_LAT_LONG_FRESH;
|
||||||
|
}
|
||||||
|
|
||||||
} else if (mm->msgtype == 17 && mm->metype == 19 && mm->mesub == 1) {
|
} else if (mm->msgtype == 17 && mm->metype == 19 && mm->mesub == 1) {
|
||||||
int vr = (mm->vert_rate_sign==0?1:-1) * (mm->vert_rate-1) * 64;
|
int vr = (mm->vert_rate_sign==0?1:-1) * (mm->vert_rate-1) * 64;
|
||||||
|
|
||||||
p += sprintf(p, "MSG,4,%s,,,%d,%d,,,%i,,0,0,0,0", strCommon, a->speed, a->track, vr);
|
p += sprintf(p, "MSG,4,%s,,,%d,%d,,,%i,,0,0,0,0", strCommon, mm->velocity, mm->heading, vr);
|
||||||
|
|
||||||
} else if (mm->msgtype == 21) {
|
} else if (mm->msgtype == 21) {
|
||||||
p += sprintf(p, "MSG,6,%s,,,,,,,,%d,%d,%d,%d,%d", strCommon, mm->identity, alert, emergency, spi, ground);
|
p += sprintf(p, "MSG,6,%s,,,,,,,,%d,%d,%d,%d,%d", strCommon, mm->identity, alert, emergency, spi, ground);
|
||||||
|
|
Loading…
Reference in a new issue