diff --git a/dump1090.h b/dump1090.h index 55bcedd..6cc0275 100644 --- a/dump1090.h +++ b/dump1090.h @@ -178,7 +178,7 @@ typedef enum { } airground_t; typedef enum { - SIL_INVALID, SIL_PER_SAMPLE, SIL_PER_HOUR + SIL_INVALID, SIL_UNKNOWN, SIL_PER_SAMPLE, SIL_PER_HOUR } sil_type_t; typedef enum { @@ -509,7 +509,6 @@ struct modesMessage { unsigned nic_baro_valid : 1; unsigned nac_p_valid : 1; unsigned nac_v_valid : 1; - unsigned sil_valid : 1; unsigned gva_valid : 1; unsigned sda_valid : 1; @@ -521,8 +520,8 @@ struct modesMessage { unsigned nac_p : 4; // if nac_p_valid unsigned nac_v : 3; // if nac_v_valid - unsigned sil : 2; // if sil_valid - sil_type_t sil_type; // if sil_valid + unsigned sil : 2; // if sil_type != SIL_INVALID + sil_type_t sil_type; unsigned gva : 2; // if gva_valid diff --git a/mode_s.c b/mode_s.c index 3f30c59..9e5f206 100644 --- a/mode_s.c +++ b/mode_s.c @@ -1103,9 +1103,8 @@ static void decodeESTargetStatus(struct modesMessage *mm, int check_imf) mm->accuracy.nic_baro = getbit(me, 44); // 45-46: SIL - mm->accuracy.sil_valid = 1; mm->accuracy.sil = getbits(me, 45, 46); - mm->accuracy.sil_type = SIL_INVALID; + mm->accuracy.sil_type = SIL_UNKNOWN; // 47-51: reserved @@ -1170,9 +1169,8 @@ static void decodeESTargetStatus(struct modesMessage *mm, int check_imf) mm->accuracy.nic_baro = getbit(me, 44); // 45-46: SIL - mm->accuracy.sil_valid = 1; mm->accuracy.sil = getbits(me, 45, 46); - mm->accuracy.sil_type = SIL_INVALID; + mm->accuracy.sil_type = SIL_UNKNOWN; // 47: mode bits validity if (getbit(me, 47)) { @@ -1241,7 +1239,7 @@ static void decodeESOperationalStatus(struct modesMessage *mm, int check_imf) mm->accuracy.nic_a = getbit(me, 44); mm->accuracy.nac_p_valid = 1; mm->accuracy.nac_p = getbits(me, 45, 48); - mm->accuracy.sil_valid = 1; + mm->accuracy.sil_type = SIL_UNKNOWN; mm->accuracy.sil = getbits(me, 51, 52); mm->opstatus.hrd = getbit(me, 54) ? HEADING_MAGNETIC : HEADING_TRUE; @@ -1291,7 +1289,6 @@ static void decodeESOperationalStatus(struct modesMessage *mm, int check_imf) mm->accuracy.nic_a = getbit(me, 44); mm->accuracy.nac_p_valid = 1; mm->accuracy.nac_p = getbits(me, 45, 48); - mm->accuracy.sil_valid = 1; mm->accuracy.sil = getbits(me, 51, 52); mm->accuracy.sil_type = getbit(me, 55) ? SIL_PER_SAMPLE : SIL_PER_HOUR; mm->opstatus.hrd = getbit(me, 54) ? HEADING_MAGNETIC : HEADING_TRUE; @@ -1583,6 +1580,16 @@ static const char *nav_modes_to_string(nav_modes_t flags) return buf; } +static const char *sil_type_to_string(sil_type_t type) +{ + switch (type) { + case SIL_UNKNOWN: return "unknown type"; + case SIL_PER_HOUR: return "per flight hour"; + case SIL_PER_SAMPLE: return "per sample"; + default: return "invalid type"; + } +} + static void print_hex_bytes(unsigned char *data, size_t len) { size_t i; for (i = 0; i < len; ++i) { @@ -1959,10 +1966,26 @@ void displayModesMessage(struct modesMessage *mm) { if (mm->accuracy.gva_valid) { printf(" GVA: %d\n", mm->accuracy.gva); } - if (mm->accuracy.sil_valid) { - printf(" SIL: %d (%s)\n", + if (mm->accuracy.sil_type != SIL_INVALID) { + const char *sil_description; + switch (mm->accuracy.sil) { + case 1: + sil_description = "p <= 0.1%"; + break; + case 2: + sil_description = "p <= 0.001%"; + break; + case 3: + sil_description = "p <= 0.00001%"; + break; + default: + sil_description = "p > 0.1%"; + break; + } + printf(" SIL: %d (%s, %s)\n", mm->accuracy.sil, - (mm->accuracy.sil_type == SIL_PER_HOUR ? "per hour" : "per sample")); + sil_description, + sil_type_to_string(mm->accuracy.sil_type)); } if (mm->accuracy.sda_valid) { printf(" SDA: %d\n", mm->accuracy.sda); diff --git a/track.c b/track.c index ecfd066..1f4ed8e 100644 --- a/track.c +++ b/track.c @@ -1000,9 +1000,9 @@ struct aircraft *trackUpdateFromMessage(struct modesMessage *mm) a->nac_v = mm->accuracy.nac_v; } - if (mm->accuracy.sil_valid && accept_data(&a->sil_valid, mm->source)) { + if (mm->accuracy.sil_type != SIL_INVALID && accept_data(&a->sil_valid, mm->source)) { a->sil = mm->accuracy.sil; - if (mm->accuracy.sil_type != SIL_INVALID) { + if (a->sil_type == SIL_INVALID || mm->accuracy.sil_type != SIL_UNKNOWN) { a->sil_type = mm->accuracy.sil_type; } }