diff --git a/routes/acars.py b/routes/acars.py index 4bbb4b1..7d91464 100644 --- a/routes/acars.py +++ b/routes/acars.py @@ -49,6 +49,28 @@ def find_acarsdec(): return shutil.which('acarsdec') +def get_acarsdec_json_flag(acarsdec_path: str) -> str: + """Detect which JSON output flag acarsdec supports. + + Newer forks (TLeconte) use -j, older versions use -o 4. + """ + try: + result = subprocess.run( + [acarsdec_path, '-h'], + capture_output=True, + text=True, + timeout=5 + ) + help_text = result.stdout + result.stderr + # Check if -j flag is documented in help + if ' -j' in help_text or '\n-j' in help_text: + return '-j' + except Exception: + pass + # Default to older -o 4 syntax + return '-o' + + def stream_acars_output(process: subprocess.Popen, is_text_mode: bool = False) -> None: """Stream acarsdec JSON output to queue.""" global acars_message_count, acars_last_message_time @@ -179,10 +201,12 @@ def start_acars() -> Response: # acarsdec -j -g -p -r ... # Note: -j is JSON stdout (newer forks), -o 4 was the old syntax # gain/ppm must come BEFORE -r - cmd = [ - acarsdec_path, - '-j', # JSON output to stdout - ] + json_flag = get_acarsdec_json_flag(acarsdec_path) + cmd = [acarsdec_path] + if json_flag == '-j': + cmd.append('-j') # JSON output (newer TLeconte fork) + else: + cmd.extend(['-o', '4']) # JSON output (older versions) # Add gain if not auto (must be before -r) if gain and str(gain) != '0': diff --git a/templates/adsb_dashboard.html b/templates/adsb_dashboard.html index 3baaccd..7ba5025 100644 --- a/templates/adsb_dashboard.html +++ b/templates/adsb_dashboard.html @@ -540,7 +540,7 @@ const squawkInfo = checkSquawkCode(ac); const onWatchlist = isOnWatchlist(ac); - if (squawkInfo) { + if (squawkInfo && squawkInfo.type === 'emergency') { alertedAircraft[icao] = 'emergency'; playAlertSound('emergency'); showAlertBanner(`EMERGENCY: ${squawkInfo.name} - ${ac.callsign || icao}`, '#ff0000'); @@ -1905,7 +1905,7 @@ ACARS: ${r.statistics.acarsMessages} messages`; const squawkInfo = checkSquawkCode(ac); if (currentFilter === 'military') return militaryInfo.military; if (currentFilter === 'civil') return !militaryInfo.military; - if (currentFilter === 'emergency') return !!squawkInfo; + if (currentFilter === 'emergency') return squawkInfo && squawkInfo.type === 'emergency'; if (currentFilter === 'watchlist') return isOnWatchlist(ac); return true; }