Decode aircraft category, export in aircraft.json.

Closes #2.
This commit is contained in:
Oliver Jowett 2015-02-22 12:15:26 +00:00
parent 8fabfcb94f
commit 8f3be2cd79
5 changed files with 16 additions and 2 deletions

View file

@ -157,6 +157,7 @@
#define MODES_ACFLAGS_NSEWSPD_VALID (1<<14) // Aircraft EW and NS Speed is known
#define MODES_ACFLAGS_LATLON_REL_OK (1<<15) // Indicates it's OK to do a relative CPR
#define MODES_ACFLAGS_REL_CPR_USED (1<<16) // Lat/lon derived from relative CPR
#define MODES_ACFLAGS_CATEGORY_VALID (1<<17) // Aircraft category is known
#define MODES_ACFLAGS_LLEITHER_VALID (MODES_ACFLAGS_LLEVEN_VALID | MODES_ACFLAGS_LLODD_VALID)
#define MODES_ACFLAGS_LLBOTH_VALID (MODES_ACFLAGS_LLEVEN_VALID | MODES_ACFLAGS_LLODD_VALID)
@ -385,6 +386,7 @@ struct modesMessage {
int ns_velocity; // N/S velocity.
int vert_rate; // Vertical rate.
int velocity; // Reported by aircraft, or computed from from EW and NS velocity
unsigned category; // A0 - D7 encoded as a single hex byte
// DF 18
int cf; // Control Field

View file

@ -753,6 +753,9 @@ static void decodeExtendedSquitter(struct modesMessage *mm)
mm->flight[8] = '\0';
}
mm->category = ((0x0E - metype) << 4) | mesub;
mm->bFlags |= MODES_ACFLAGS_CATEGORY_VALID;
break;
}
@ -973,8 +976,8 @@ static void displayExtendedSquitter(struct modesMessage *mm) {
// Decode the extended squitter message
if (mm->metype >= 1 && mm->metype <= 4) { // Aircraft identification
printf(" Aircraft Type : %c%d\n", ('A' + 4 - mm->metype), mm->mesub);
printf(" Identification : %s\n", mm->flight);
printf(" Aircraft Type : %02X\n", mm->category);
printf(" Identification : %s\n", (mm->bFlags & MODES_ACFLAGS_CALLSIGN_VALID) ? mm->flight : "invalid");
} else if (mm->metype == 19) { // Airborne Velocity
if (mm->mesub == 1 || mm->mesub == 2) {
printf(" EW status : %s\n", (mm->bFlags & MODES_ACFLAGS_EWSPEED_VALID) ? "Valid" : "Unavailable");

View file

@ -787,6 +787,8 @@ char *generateAircraftJson(const char *url_path, int *len) {
p += snprintf(p, end-p, ",\"track\":%d", a->track);
if (a->bFlags & MODES_ACFLAGS_SPEED_VALID)
p += snprintf(p, end-p, ",\"speed\":%d", a->speed);
if (a->bFlags & MODES_ACFLAGS_CATEGORY_VALID)
p += snprintf(p, end-p, ",\"category\":\"%02X\"", a->category);
p += snprintf(p, end-p, ",\"messages\":%ld,\"seen\":%.1f,\"rssi\":%.1f}",
a->messages, (now - a->seen)/1000.0,

View file

@ -495,6 +495,11 @@ struct aircraft *trackUpdateFromMessage(struct modesMessage *mm)
a->vert_rate = mm->vert_rate;
}
// If a (new) category has been received, copy it to the aircraft structure
if (mm->bFlags & MODES_ACFLAGS_CATEGORY_VALID) {
a->category = mm->category;
}
// Update the aircrafts a->bFlags to reflect the newly received mm->bFlags;
a->bFlags |= mm->bFlags;

View file

@ -95,6 +95,8 @@ struct aircraft {
double lat, lon; // Coordinated obtained from CPR encoded data
unsigned pos_nuc; // NUCp of last computed position
unsigned category; // Aircraft category A0 - D7 encoded as a single hex byte
int bFlags; // Flags related to valid fields in this structure
struct aircraft *next; // Next aircraft in our linked list