Skip to content

Fix ADSB altitude integer overflow and add on-ground indicator - #3275

Merged
gullradriel merged 3 commits into
nextfrom
copilot/fix-adsb-altitude-overflow
Jul 22, 2026
Merged

Fix ADSB altitude integer overflow and add on-ground indicator#3275
gullradriel merged 3 commits into
nextfrom
copilot/fix-adsb-altitude-overflow

Conversation

Copilot AI commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Per ICAO Annex 10 Vol IV §3.1.2.6.5.4, barometric altitude is decoded as 25N − 1000 ft, yielding valid negative values down to −1000 ft. Landing aircraft were hitting an unsigned cast overflow and a hard-clamp-to-zero, producing junk displays like 294967294 (screenshot above shows ANZ199L with this bug).

Changes

Integer overflow fix (ui_adsb_rx.cpp)

  • Replace to_string_dec_uint((unsigned int)(entry.pos.altitude / 100), 4) with to_string_dec_int((int32_t)(entry.pos.altitude / 100), 4) — negative altitudes now display correctly (e.g. -1 for −100 ft) instead of wrapping to ~4 billion
  • Remove the erroneous if (altitude < 0) altitude = 0; clamp in the DF 0/4/20 AC altitude decoder

On-ground indicator (ui_adsb_rx.cpp, ui_adsb_rx.hpp)

  • Add bool on_ground{false} to AircraftRecentEntry
  • Handle previously-ignored TC 5–8 (surface position) messages in DF 17: set on_ground = true, zero and invalidate the altitude field
  • Clear on_ground when TC 9–22 (airborne position) is received
  • Display GND (4 chars, matching column width) in the altitude column when on ground, and use altitude 0 for map color calculation to avoid stale airborne color after landing

Proof that your changes work

🖥️ Proof it compiles

Pending — build log to be attached.

📱 Proof of testing on a real device

Pending — to be tested at an airfield with aircraft landing near/below sea level.

📡 Proof against a real emitter/receiver (if applicable)

Applicable — ADSB RX decoding. Pending real-device ADSB capture showing corrected altitude values for low-altitude aircraft.


📚 Wiki documentation commitment

  • I will (or already) create(d) wiki document for my newly added feature

Checklist

  • Kept changes minimal and limited to necessary files
  • Verified functionality remains intact and code compiles
  • Attached proof that the code compiles successfully (or marked N/A as a trusted contributor)
  • Attached proof of testing on real PortaPack hardware (or marked N/A as a trusted contributor)
  • Attached proof of testing against a real emitter/receiver (if RF-related), or marked N/A with justification
  • I understand that by getting this PR merged, I am implicitly agreeing to create or update the corresponding wiki page (including a main-screen screenshot, description, controls, and limitations)
  • I own all rights to this code (i.e., all code contained in this PR), including compliant usage rights for third-party libraries, and I agree that this code is licensed under the license of this project (GPL-3.0).
  • If any third-party libraries are used, I confirm that their licenses comply with the requirements for contributing to this repository.
  • Reviewed the Contributing Guidelines

Copilot AI linked an issue Jul 22, 2026 that may be closed by this pull request
- 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
Copilot AI changed the title [WIP] Fix integer overflow in ADSB altitude calculations Fix ADSB altitude integer overflow and add on-ground indicator Jul 22, 2026
Copilot finished work on behalf of zxkmm July 22, 2026 03:26
Copilot AI requested a review from zxkmm July 22, 2026 03:26
Comment thread firmware/application/apps/ui_adsb_rx.hpp Outdated
Comment thread firmware/application/apps/ui_adsb_rx.cpp Outdated

@zxkmm zxkmm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot no need to have all these and just for showing a GND. I don’t need “GND” and idk why you came up with this idea. Just prevent overflow, display data as is, even negative data.

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
Copilot finished work on behalf of zxkmm July 22, 2026 03:36
Copilot AI requested a review from zxkmm July 22, 2026 03:36

@zxkmm zxkmm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

@zxkmm
zxkmm marked this pull request as ready for review July 22, 2026 03:43
@zxkmm
zxkmm requested a review from gullradriel July 22, 2026 03:44

@gullradriel gullradriel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to go, thanks @zxkmm for the review ;-)

@gullradriel
gullradriel merged commit 483a100 into next Jul 22, 2026
3 checks passed
@gullradriel
gullradriel deleted the copilot/fix-adsb-altitude-overflow branch July 22, 2026 23:16
@zxkmm

zxkmm commented Jul 23, 2026

Copy link
Copy Markdown
Member

Np, sorry for pinging, no idea why but I cannot approve this, maybe it’s because I asked copilot to make PR

@gullradriel

Copy link
Copy Markdown
Member

That's it. You cannot review a PR you provided or contributed ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ADSB altitude integer overflow

3 participants