diff --git a/dump1090.h b/dump1090.h index a34e569..26abdae 100644 --- a/dump1090.h +++ b/dump1090.h @@ -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 diff --git a/mode_s.c b/mode_s.c index 5894fad..cd37b01 100644 --- a/mode_s.c +++ b/mode_s.c @@ -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"); diff --git a/net_io.c b/net_io.c index 951fae4..026df24 100644 --- a/net_io.c +++ b/net_io.c @@ -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, diff --git a/track.c b/track.c index 8a8b849..b858609 100644 --- a/track.c +++ b/track.c @@ -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; diff --git a/track.h b/track.h index 3cdef55..fdb3bbd 100644 --- a/track.h +++ b/track.h @@ -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