From 6336611bc76a0b04911583cfbfa6f6911a65f86c Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Thu, 29 Dec 2016 17:56:32 +0000 Subject: [PATCH] Turn on mode A/C if a Beast connection asks for it. Add a --no-modeac-auto option to disable this. --- dump1090.c | 5 +++++ dump1090.h | 1 + net_io.c | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/dump1090.c b/dump1090.c index f943f05..60e79ae 100644 --- a/dump1090.c +++ b/dump1090.c @@ -144,6 +144,7 @@ void modesInitConfig(void) { Modes.json_interval = 1000; Modes.json_location_accuracy = 1; Modes.maxRange = 1852 * 300; // 300NM default max range + Modes.mode_ac_auto = 1; } // //========================================================================= @@ -666,6 +667,7 @@ void showHelp(void) { "--raw Show only messages hex values\n" "--net Enable networking\n" "--modeac Enable decoding of SSR Modes 3/A & 3/C\n" +"--no-modeac-auto Don't enable Mode A/C if requested by a Beast connection\n" "--net-only Enable just networking, no RTL device or file used\n" "--net-bind-address IP address to bind to (default: Any; Use 127.0.0.1 for private)\n" #ifdef ENABLE_WEBSERVER @@ -954,6 +956,9 @@ int main(int argc, char **argv) { Modes.net = 1; } else if (!strcmp(argv[j],"--modeac")) { Modes.mode_ac = 1; + Modes.mode_ac_auto = 0; + } else if (!strcmp(argv[j],"--no-modeac-auto")) { + Modes.mode_ac_auto = 0; } else if (!strcmp(argv[j],"--net-beast")) { fprintf(stderr, "--net-beast ignored, use --net-bo-port to control where Beast output is generated\n"); } else if (!strcmp(argv[j],"--net-only")) { diff --git a/dump1090.h b/dump1090.h index 5dab1ad..324d01d 100644 --- a/dump1090.h +++ b/dump1090.h @@ -313,6 +313,7 @@ struct { // Internal state int check_crc; // Only display messages with good CRC int raw; // Raw output format int mode_ac; // Enable decoding of SSR Modes A & C + int mode_ac_auto; // allow toggling of A/C by Beast commands int debug; // Debugging mode int net; // Enable networking int net_only; // Enable just networking diff --git a/net_io.c b/net_io.c index 64568de..4d2d88e 100644 --- a/net_io.c +++ b/net_io.c @@ -81,6 +81,8 @@ static void send_sbs_heartbeat(struct net_service *service); static void writeFATSVEvent(struct modesMessage *mm, struct aircraft *a); static void writeFATSVPositionUpdate(float lat, float lon, float alt); +static void autoset_modeac(); + // //========================================================================= // @@ -315,6 +317,8 @@ static void modesCloseClient(struct client *c) { c->fd = -1; c->service = NULL; c->modeac_requested = 0; + + autoset_modeac(); } // //========================================================================= @@ -788,6 +792,22 @@ static void handle_radarcape_position(float lat, float lon, float alt) } } +// recompute global Mode A/C setting +static void autoset_modeac() { + struct client *c; + + if (!Modes.mode_ac_auto) + return; + + Modes.mode_ac = 0; + for (c = Modes.clients; c; c = c->next) { + if (c->modeac_requested) { + Modes.mode_ac = 1; + break; + } + } +} + // Send some Beast settings commands to a client void sendBeastSettings(struct client *c, const char *settings) { @@ -826,6 +846,7 @@ static int handleBeastCommand(struct client *c, char *p) { break; } + autoset_modeac(); return 0; }