Skip to content

Distinguish military planes - #61

Open
eightonegulf wants to merge 2 commits into
MatixYo:mainfrom
eightonegulf:DistinguishMilitaryPlanes
Open

Distinguish military planes#61
eightonegulf wants to merge 2 commits into
MatixYo:mainfrom
eightonegulf:DistinguishMilitaryPlanes

Conversation

@eightonegulf

Copy link
Copy Markdown

Retrieves whether a plane is military or civilian. Uses the DBFlags field to determine this.
Draws the military planes in a orange color so they are easily distinguished.

@Reid-n0rc

Copy link
Copy Markdown

Hardware & testing methodology: ESP32-C3 Super Mini (esp32-c3-devkitm-1, RISC-V, 320KB RAM), 1.28" round GC9A01 240×240 SPI display, USB-C native serial. Built with PlatformIO, espressif32@6.5.0 platform, Arduino core framework-arduinoespressif32@3.20014.231204, -std=gnu++17. Connected to a real WiFi AP with live ADS-B traffic from opendata.adsb.fi. Verified visually on the physical display that military-flagged aircraft render in the distinct color, plus reviewed the merged code path line-by-line during integration since it touched shared drawing code.

Results: two real bugs, fixed locally in my integration build (not yet upstreamed to this PR branch):

1. Wrong array indexed in the beyond-ring-dot color loop, src/ui/radar_display.cpp:

// Before (bug): iterates `dots[]` but indexes `items[]`
for (size_t d = 0; d < dot_count; ++d) {
  const size_t i = items[d].index;
  drawBeyondRingDot(dots[d].x, dots[d].y,
        planes[i].isMilitary ? radar::kColorMilitaryAircraft : radar::kColorAircraft);
}

// After (fix)
for (size_t d = 0; d < dot_count; ++d) {
  const size_t i = dots[d].index;
  drawBeyondRingDot(dots[d].x, dots[d].y,
        planes[i].isMilitary ? radar::kColorMilitaryAircraft : radar::kColorAircraft);
}

items[] and dots[] are populated independently for different subsets of aircraft (in-ring vs. beyond-ring), so this could read the wrong aircraft's military flag or go out of bounds when dot_count > draw_count.

2. dbFlags type check, src/services/adsb_client.cpp:

// Before (bug): dbFlags is an integer bitmask, not a bool
bool isMilitary(const JsonObject& plane) {
  return plane["dbFlags"].is<bool>() && plane["dbFlags"].as<bool>();
}

// After (fix): bit 0 marks military per the ADS-B feed's convention
bool isMilitary(const JsonObject& plane) {
  return plane["dbFlags"].is<int>() && (plane["dbFlags"].as<int>() & 1) != 0;
}

As written, is<bool>() would almost never match a numeric field, so the military check likely never fired.

After both fixes, military-flagged aircraft rendered in the distinct color correctly on hardware. Recommend applying these before merge.

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.

2 participants