From 9479a5c9bef8fa3f421d0bcfbdd7cde7abce5833 Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Fri, 1 Jan 2016 15:15:28 +0000 Subject: [PATCH] If --hae is passed, report altitudes as HAE where available, with a H suffix. This affects interactive mode and SBS output. --- dump1090.c | 3 +++ dump1090.h | 1 + interactive.c | 10 ++++++---- mode_s.c | 6 +++--- net_io.c | 14 ++++++++++---- net_io.h | 3 ++- 6 files changed, 25 insertions(+), 12 deletions(-) diff --git a/dump1090.c b/dump1090.c index b53a00b..a8e74f6 100644 --- a/dump1090.c +++ b/dump1090.c @@ -709,6 +709,7 @@ void showHelp(void) { "--stats-every Show and reset stats every seconds\n" "--onlyaddr Show only ICAO addresses (testing purposes)\n" "--metric Use metric units (meters, km/h, ...)\n" +"--hae Show altitudes as HAE (with H suffix) when available\n" "--snip Strip IQ file removing samples < level\n" "--debug Debug mode (verbose), see README for details\n" "--quiet Disable output to stdout. Use for daemon applications\n" @@ -1006,6 +1007,8 @@ int main(int argc, char **argv) { Modes.onlyaddr = 1; } else if (!strcmp(argv[j],"--metric")) { Modes.metric = 1; + } else if (!strcmp(argv[j],"--hae")) { + Modes.use_hae = 1; } else if (!strcmp(argv[j],"--aggressive")) { Modes.nfix_crc = MODES_MAX_BITERRORS; } else if (!strcmp(argv[j],"--interactive")) { diff --git a/dump1090.h b/dump1090.h index 6050348..d3748b6 100644 --- a/dump1090.h +++ b/dump1090.h @@ -323,6 +323,7 @@ struct { // Internal state int stats_range_histo; // Collect/show a range histogram? int onlyaddr; // Print only ICAO addresses int metric; // Use metric units + int use_hae; // Use HAE altitudes with H suffix when available int mlat; // Use Beast ascii format for raw data output, i.e. @...; iso *...; int interactive_rtl1090; // flight table in interactive mode is formatted like RTL1090 char *json_dir; // Path to json base directory, or NULL not to write json. diff --git a/interactive.c b/interactive.c index 871105b..41f4e64 100644 --- a/interactive.c +++ b/interactive.c @@ -118,7 +118,7 @@ void interactiveShowData(void) { || (((flags & (MODEAC_MSG_MODES_HIT | MODEAC_MSG_MODEC_OLD )) == 0 ) && (msgs > 127) ) ) { char strSquawk[5] = " "; - char strFl[6] = " "; + char strFl[7] = " "; char strTt[5] = " "; char strGs[5] = " "; @@ -164,12 +164,14 @@ void interactiveShowData(void) { } if (a->bFlags & MODES_ACFLAGS_AOG) { - snprintf(strFl, 6," grnd"); + snprintf(strFl, 7," grnd"); + } else if (Modes.use_hae && (a->bFlags & MODES_ACFLAGS_ALTITUDE_HAE_VALID)) { + snprintf(strFl, 7, "%5dH", convert_altitude(a->altitude_hae)); } else if (a->bFlags & MODES_ACFLAGS_ALTITUDE_VALID) { - snprintf(strFl, 6, "%5d", convert_altitude(a->altitude)); + snprintf(strFl, 7, "%5d ", convert_altitude(a->altitude)); } - printf("%s%06X %-4s %-4s %-8s %5s %3s %3s %7s %8s %5.1f %5d %2.0f\n", + printf("%s%06X %-4s %-4s %-8s %6s %3s %3s %7s %8s %5.1f %5d %2.0f\n", (a->addr & MODES_NON_ICAO_ADDRESS) ? "~" : " ", (a->addr & 0xffffff), strMode, strSquawk, a->flight, strFl, strGs, strTt, strLat, strLon, 10 * log10(signalAverage), msgs, (now - a->seen)/1000.0); diff --git a/mode_s.c b/mode_s.c index 07994dc..b53bd4f 100644 --- a/mode_s.c +++ b/mode_s.c @@ -1261,15 +1261,15 @@ void useModesMessage(struct modesMessage *mm) { if (Modes.net) { if (Modes.net_verbatim || mm->msgtype == 32) { // Unconditionally send - modesQueueOutput(mm); + modesQueueOutput(mm, a); } else if (a->messages > 1) { // If this is the second message, and we // squelched the first message, then re-emit the // first message now. if (!Modes.net_verbatim && a->messages == 2) { - modesQueueOutput(&a->first_message); + modesQueueOutput(&a->first_message, a); } - modesQueueOutput(mm); + modesQueueOutput(mm, a); } } } diff --git a/net_io.c b/net_io.c index 3c9374d..9a7eee9 100644 --- a/net_io.c +++ b/net_io.c @@ -460,7 +460,7 @@ static void send_raw_heartbeat(struct net_service *service) // Write SBS output to TCP clients // The message structure mm->bFlags tells us what has been updated by this message // -static void modesSendSBSOutput(struct modesMessage *mm) { +static void modesSendSBSOutput(struct modesMessage *mm, struct aircraft *a) { char *p; struct timespec now; struct tm stTime_receive, stTime_now; @@ -535,8 +535,14 @@ static void modesSendSBSOutput(struct modesMessage *mm) { // Field 12 is the altitude (if we have it) - force to zero if we're on the ground if ((mm->bFlags & MODES_ACFLAGS_AOG_GROUND) == MODES_ACFLAGS_AOG_GROUND) { p += sprintf(p, ",0"); + } else if (Modes.use_hae && (mm->bFlags & MODES_ACFLAGS_ALTITUDE_HAE_VALID)) { + p += sprintf(p, ",%dH", mm->altitude_hae); } else if (mm->bFlags & MODES_ACFLAGS_ALTITUDE_VALID) { - p += sprintf(p, ",%d", mm->altitude); + if (Modes.use_hae && (a->bFlags & MODES_ACFLAGS_HAE_DELTA_VALID)) { + p += sprintf(p, ",%dH", mm->altitude + a->hae_delta); + } else { + p += sprintf(p, ",%d", mm->altitude); + } } else { p += sprintf(p, ","); } @@ -636,11 +642,11 @@ static void send_sbs_heartbeat(struct net_service *service) // //========================================================================= // -void modesQueueOutput(struct modesMessage *mm) { +void modesQueueOutput(struct modesMessage *mm, struct aircraft *a) { if ((mm->bFlags & MODES_ACFLAGS_FROM_MLAT) && !Modes.forward_mlat) return; - modesSendSBSOutput(mm); + modesSendSBSOutput(mm, a); modesSendBeastOutput(mm); modesSendRawOutput(mm); } diff --git a/net_io.h b/net_io.h index 9097010..34632bc 100644 --- a/net_io.h +++ b/net_io.h @@ -22,6 +22,7 @@ // Describes a networking service (group of connections) +struct aircraft; struct modesMessage; struct client; struct net_service; @@ -71,7 +72,7 @@ struct net_service *makeBeastInputService(void); struct net_service *makeFatsvOutputService(void); void modesInitNet(void); -void modesQueueOutput(struct modesMessage *mm); +void modesQueueOutput(struct modesMessage *mm, struct aircraft *a); void modesNetPeriodicWork(void); // TODO: move these somewhere else