From 483a1001002e068300bb76ae796604439f23635f Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Thu, 23 Jul 2026 01:16:21 +0200 Subject: [PATCH] Fix ADSB altitude integer overflow and add on-ground indicator (#3275) * Initial plan * Fix ADSB altitude integer overflow and add on-ground indicator - Fix display overflow: use to_string_dec_int (signed) instead of to_string_dec_uint (unsigned) for altitude display - per ICAO Annex 10 Vol IV 3.1.2.6.5.4, altitude = 25N-1000 can be as low as -1000ft - Remove incorrect altitude clamp (altitude < 0 => 0) in DF 0/4/20 decoder - Add on_ground flag to AircraftRecentEntry; set from TC 5-8 (surface position) messages, cleared on TC 9-22 (airborne position) messages - Display 'GND' in altitude column when aircraft is on ground - Clear altitude to 0 when on_ground is set to prevent stale data in map color calculation Closes #3274 * Revert on-ground indicator; keep only the overflow and clamp fixes Remove on_ground field, TC 5-8 handling, and "GND" display per review feedback. Only keep the two minimal bug fixes: - Signed altitude display (to_string_dec_int vs to_string_dec_uint) - Remove erroneous altitude < 0 clamp; update comment to show the math --- firmware/application/apps/ui_adsb_rx.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/firmware/application/apps/ui_adsb_rx.cpp b/firmware/application/apps/ui_adsb_rx.cpp index 7248a9702..0adb8410a 100644 --- a/firmware/application/apps/ui_adsb_rx.cpp +++ b/firmware/application/apps/ui_adsb_rx.cpp @@ -75,7 +75,7 @@ void RecentEntriesTable::draw( uint8_t firstcolwidth = columns.at(0).second; ipc.resize(firstcolwidth, ' '); // Make sure this is always match the first column's width that is dynamic. - entry_string += ipc + to_string_dec_uint((unsigned int)(entry.pos.altitude / 100), 4); + entry_string += ipc + to_string_dec_int((int32_t)(entry.pos.altitude / 100), 4); if (entry.velo.type == SPD_IAS && entry.pos.alt_valid) { // IAS can be converted to TAS // It is generally accepted that for every thousand feet of altitude, @@ -668,9 +668,8 @@ void ADSBRxView::on_frame(const ADSBFrameMessage* message) { (raw_data[3] & 15); // The final altitude is due to the resulting number multiplied by 25, minus 1000. + // altitude = 25N - 1000 (ft); minimum is -1000 ft when N=0 (Q=1, M=0 per ICAO Annex 10). altitude = 25 * n - 1000; - if (altitude < 0) - altitude = 0; } // else N is an 11 bit Gillham coded altitude }