Turn on mode A/C if a Beast connection asks for it.

Add a --no-modeac-auto option to disable this.
This commit is contained in:
Oliver Jowett 2016-12-29 17:56:32 +00:00
parent cbdfd9dc5d
commit 6336611bc7
3 changed files with 27 additions and 0 deletions

View file

@ -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> 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")) {

View file

@ -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

View file

@ -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;
}