diff --git a/dump1090.h b/dump1090.h index b1cba8f..c3059c3 100644 --- a/dump1090.h +++ b/dump1090.h @@ -198,6 +198,10 @@ typedef enum { SIL_PER_SAMPLE, SIL_PER_HOUR } sil_type_t; +typedef enum { + CPR_SURFACE, CPR_AIRBORNE, CPR_COARSE +} cpr_type_t; + #define MODES_NON_ICAO_ADDRESS (1<<24) // Set on addresses to indicate they are not ICAO addresses #define MODES_DEBUG_DEMOD (1<<0) @@ -461,6 +465,7 @@ struct modesMessage { // valid if category_valid unsigned category; // A0 - D7 encoded as a single hex byte // valid if cpr_valid + cpr_type_t cpr_type; // The encoding type used (surface, airborne, coarse TIS-B) unsigned cpr_lat; // Non decoded latitude. unsigned cpr_lon; // Non decoded longitude. unsigned cpr_nucp; // NUCp/NIC value implied by message type diff --git a/mode_s.c b/mode_s.c index 1580ba0..2c61980 100644 --- a/mode_s.c +++ b/mode_s.c @@ -903,6 +903,7 @@ static void decodeESSurfacePosition(struct modesMessage *mm, int check_imf) mm->cpr_odd = getbit(me, 22); mm->cpr_nucp = (14 - mm->metype); mm->cpr_valid = 1; + mm->cpr_type = CPR_SURFACE; unsigned movement = getbits(me, 6, 12); if (movement > 0 && movement < 125) { @@ -948,6 +949,7 @@ static void decodeESAirbornePosition(struct modesMessage *mm, int check_imf) } else { // Otherwise, assume it's valid. mm->cpr_valid = 1; + mm->cpr_type = CPR_AIRBORNE; mm->cpr_odd = getbit(me, 22); if (mm->metype == 18 || mm->metype == 22) @@ -1386,6 +1388,19 @@ static const char *addrtype_to_string(addrtype_t type) { } } +static const char *cpr_type_to_string(cpr_type_t type) { + switch (type) { + case CPR_SURFACE: + return "Surface"; + case CPR_AIRBORNE: + return "Airborne"; + case CPR_COARSE: + return "TIS-B Coarse"; + default: + return "unknown CPR type"; + } +} + static void print_hex_bytes(unsigned char *data, size_t len) { size_t i; for (i = 0; i < len; ++i) { @@ -1676,12 +1691,11 @@ void displayModesMessage(struct modesMessage *mm) { mm->category); } - if (mm->msgtype == 17 || mm->msgtype == 18) { - } - if (mm->cpr_valid) { - printf(" CPR odd flag: %s\n" + printf(" CPR type: %s\n" + " CPR odd flag: %s\n" " CPR NUCp/NIC: %u\n", + cpr_type_to_string(mm->cpr_type), mm->cpr_odd ? "odd" : "even", mm->cpr_nucp); diff --git a/track.c b/track.c index 27172f8..cf8353a 100644 --- a/track.c +++ b/track.c @@ -260,7 +260,7 @@ static int doGlobalCPR(struct aircraft *a, struct modesMessage *mm, uint64_t now { int result; int fflag = mm->cpr_odd; - int surface = (mm->airground == AG_GROUND); + int surface = (mm->cpr_type == CPR_SURFACE); *nuc = (a->cpr_even_nuc < a->cpr_odd_nuc ? a->cpr_even_nuc : a->cpr_odd_nuc); // worst of the two positions @@ -341,7 +341,7 @@ static int doLocalCPR(struct aircraft *a, struct modesMessage *mm, uint64_t now, double range_limit = 0; int result; int fflag = mm->cpr_odd; - int surface = (mm->airground == AG_GROUND); + int surface = (mm->cpr_type == CPR_SURFACE); *nuc = mm->cpr_nucp; @@ -426,7 +426,7 @@ static void updatePosition(struct aircraft *a, struct modesMessage *mm, uint64_t unsigned new_nuc = 0; int surface; - surface = (mm->airground == AG_GROUND); + surface = (mm->cpr_type == CPR_SURFACE); if (surface) { ++Modes.stats_current.cpr_surface; @@ -446,7 +446,7 @@ static void updatePosition(struct aircraft *a, struct modesMessage *mm, uint64_t // If we have enough recent data, try global CPR if (trackDataValid(&a->cpr_odd_valid) && trackDataValid(&a->cpr_even_valid) && a->cpr_odd_valid.source == a->cpr_even_valid.source && - a->cpr_odd_airground == a->cpr_even_airground && + a->cpr_odd_type == a->cpr_even_type && time_between(a->cpr_odd_valid.updated, a->cpr_even_valid.updated) <= max_elapsed) { location_result = doGlobalCPR(a, mm, now, &new_lat, &new_lon, &new_nuc); @@ -607,7 +607,7 @@ struct aircraft *trackUpdateFromMessage(struct modesMessage *mm) // CPR, even if (mm->cpr_valid && !mm->cpr_odd && accept_data(&a->cpr_even_valid, mm->source, now)) { - a->cpr_even_airground = mm->airground; + a->cpr_even_type = mm->cpr_type; a->cpr_even_lat = mm->cpr_lat; a->cpr_even_lon = mm->cpr_lon; a->cpr_even_nuc = mm->cpr_nucp; @@ -615,7 +615,7 @@ struct aircraft *trackUpdateFromMessage(struct modesMessage *mm) // CPR, odd if (mm->cpr_valid && mm->cpr_odd && accept_data(&a->cpr_odd_valid, mm->source, now)) { - a->cpr_odd_airground = mm->airground; + a->cpr_odd_type = mm->cpr_type; a->cpr_odd_lat = mm->cpr_lat; a->cpr_odd_lon = mm->cpr_lon; a->cpr_odd_nuc = mm->cpr_nucp; diff --git a/track.h b/track.h index 9326f10..85db656 100644 --- a/track.h +++ b/track.h @@ -119,13 +119,13 @@ struct aircraft { airground_t airground; // air/ground status data_validity cpr_odd_valid; // Last seen even CPR message - airground_t cpr_odd_airground; + cpr_type_t cpr_odd_type; unsigned cpr_odd_lat; unsigned cpr_odd_lon; unsigned cpr_odd_nuc; data_validity cpr_even_valid; // Last seen odd CPR message - airground_t cpr_even_airground; + cpr_type_t cpr_even_type; unsigned cpr_even_lat; unsigned cpr_even_lon; unsigned cpr_even_nuc;