feat(layers): highlight aircraft broadcasting a transponder emergency

Flights and Military Flights tint aircraft red while the latest poll
carries squawk 7500/7600/7700 or an adsb.lol ADS-B emergency status
(general/unlawful/nordo/downed). Minimum-fuel and lifeguard priorities
are reported but not tinted. The Cockpit HUD aircraft-meta line names
the broadcast code in red. The status is not sticky: a cleared code
stops highlighting on the next refresh.

The analyst/voice query engine gains squawk, emergency and
emergencyKind fields. No new source or request: OpenSky state vectors
already carry the squawk and adsb.lol/readsb carries both fields.

Built by the Hex project (Crew Leo Agile dev team).

Co-Authored-By: Claude <[email protected]>
This commit is contained in:
Leo PechnickiandClaude authored and Mazeyar Moeini Feizabadi committed 2026-10-13 17:22:29 +02:00
1 parent 9beadbda63
commit eb7f059750
26 files changed
+1174 -107

No files matched your search

+118 -41
View File
@@ -10,6 +10,7 @@ import {
cockpitGroundSafeHeight,
cockpitSurfaceWaitExpired,
cockpitUiUpdateDue,
formatCockpitEmergency,
compassDivisions,
formatAltitudeRulerTick,
formatCockpitContextScope,
@@ -41,7 +42,11 @@ test('cockpit anchor correction cannot turn a forward step into a reversal', ()
const speedMps = 200;
const dtSec = 0.1;
const forwardStepM = speedMps * dtSec;
const backwardCorrectionM = cockpitAnchorCorrectionStep(1000, speedMps, dtSec);
const backwardCorrectionM = cockpitAnchorCorrectionStep(
1000,
speedMps,
dtSec,
);
assert.ok(backwardCorrectionM > 0);
assert.ok(backwardCorrectionM < forwardStepM);
});
@@ -77,10 +82,7 @@ test('cockpit Context scope distinguishes radius-complete feeds from viewport in
});
test('cockpit Context scope preserves zero and replaces missing values intentionally', () => {
assert.equal(
formatCockpitContextScope('', 0),
'— · 0 KM AIR/SEA WINDOW',
);
assert.equal(formatCockpitContextScope('', 0), '— · 0 KM AIR/SEA WINDOW');
assert.equal(
formatCockpitContextScope(undefined, Number.NaN, {}),
'— · — KM AIR/SEA WINDOW',
@@ -168,26 +170,29 @@ test('relative bearing stays on the shortest signed arc', () => {
});
test('HUD rail layout centers between intersecting upper and lower obstacles', () => {
assert.deepEqual(resolveHudRailLayout({
viewportHeight: 1000,
panelHeight: 200,
laneLeft: 50,
laneRight: 410,
baseTop: 280,
baseBottom: 940,
gap: 10,
obstacles: [
{ left: 40, right: 240, top: 320, bottom: 460 },
{ left: 300, right: 1000, top: 780, bottom: 930 },
{ left: 900, right: 1100, top: 300, bottom: 700 },
],
}), {
top: 520,
maxHeight: 300,
safeTop: 470,
safeBottom: 770,
constrained: false,
});
assert.deepEqual(
resolveHudRailLayout({
viewportHeight: 1000,
panelHeight: 200,
laneLeft: 50,
laneRight: 410,
baseTop: 280,
baseBottom: 940,
gap: 10,
obstacles: [
{ left: 40, right: 240, top: 320, bottom: 460 },
{ left: 300, right: 1000, top: 780, bottom: 930 },
{ left: 900, right: 1100, top: 300, bottom: 700 },
],
}),
{
top: 520,
maxHeight: 300,
safeTop: 470,
safeBottom: 770,
constrained: false,
},
);
});
test('HUD rail layout constrains an oversized panel to the safe corridor', () => {
@@ -241,7 +246,10 @@ function contextSnapshot(subject, extra = {}) {
}
test('Contact panel hides only when there is no snapshot at all', () => {
const readout = resolveCockpitContextReadout({ snapshot: null, info: TRACKED_INFO });
const readout = resolveCockpitContextReadout({
snapshot: null,
info: TRACKED_INFO,
});
assert.equal(readout.visible, false);
assert.equal(readout.mode, 'standby');
assert.equal(
@@ -257,14 +265,22 @@ test('Contact panel survives NEXT onto a vessel or installation subject', () =>
// camera: "click next... whole left panel disappears").
for (const subject of [
{ layerId: 'ais-live-vessels', id: '353136000', label: 'MAERSK DETROIT' },
{ layerId: 'military-installations', id: 'fort-hood', label: 'FORT CAVAZOS' },
{
layerId: 'military-installations',
id: 'fort-hood',
label: 'FORT CAVAZOS',
},
{ layerId: 'military', id: 'ae01ce', label: 'RCH451' },
]) {
const readout = resolveCockpitContextReadout({
snapshot: contextSnapshot(subject),
info: TRACKED_INFO,
});
assert.equal(readout.visible, true, `${subject.layerId} subject must keep the panel up`);
assert.equal(
readout.visible,
true,
`${subject.layerId} subject must keep the panel up`,
);
assert.equal(readout.mode, 'foreign');
assert.equal(readout.subjectMatchesTracked, false);
}
@@ -272,7 +288,11 @@ test('Contact panel survives NEXT onto a vessel or installation subject', () =>
test('a foreign subject dashes the aircraft-relative fields and keeps the rest live', () => {
const readout = resolveCockpitContextReadout({
snapshot: contextSnapshot({ layerId: 'ais-live-vessels', id: '353136000', label: 'MAERSK DETROIT' }),
snapshot: contextSnapshot({
layerId: 'ais-live-vessels',
id: '353136000',
label: 'MAERSK DETROIT',
}),
info: TRACKED_INFO,
});
assert.equal(readout.visible, true);
@@ -281,12 +301,20 @@ test('a foreign subject dashes the aircraft-relative fields and keeps the rest l
// frame while every other row value is measured from the subject; rendering
// both live would present one mixed-frame reading as a single measurement.
assert.equal(readout.aircraftRelative, false);
assert.equal(readout.contactLost, false, 'subject-frame values still refresh');
assert.equal(
readout.contactLost,
false,
'subject-frame values still refresh',
);
});
test('the tracked aircraft as subject keeps every field in its own frame', () => {
const readout = resolveCockpitContextReadout({
snapshot: contextSnapshot({ layerId: 'flights', id: 'aaa077', label: 'SWA1234' }),
snapshot: contextSnapshot({
layerId: 'flights',
id: 'aaa077',
label: 'SWA1234',
}),
info: TRACKED_INFO,
});
assert.equal(readout.visible, true);
@@ -305,7 +333,11 @@ test('a fast-culled subject keeps the panel up as CONTACT LOST instead of collap
snapshot: contextSnapshot(subject, { subjectPresent: false }),
info: TRACKED_INFO,
});
assert.equal(readout.visible, true, 'a lost contact must not take the panel down');
assert.equal(
readout.visible,
true,
'a lost contact must not take the panel down',
);
assert.equal(readout.mode, 'lost');
assert.equal(readout.contactLost, true, 'last-known values stay on screen');
}
@@ -313,7 +345,10 @@ test('a fast-culled subject keeps the panel up as CONTACT LOST instead of collap
test('an explicitly present subject is never reported lost', () => {
const present = resolveCockpitContextReadout({
snapshot: contextSnapshot({ layerId: 'flights', id: 'aaa077' }, { subjectPresent: true }),
snapshot: contextSnapshot(
{ layerId: 'flights', id: 'aaa077' },
{ subjectPresent: true },
),
info: TRACKED_INFO,
});
assert.equal(present.contactLost, false);
@@ -332,20 +367,36 @@ test('the tracked flight layer is resolved by normalized tracked identity', () =
// Both layers describe a tracked aircraft during a cross-layer handoff;
// civilian-first precedence would hand the cockpit the wrong aircraft.
assert.equal(
resolveTrackedAircraftInfo({ civilian, military, trackedId: 'military:ae01ce' }).layerId,
resolveTrackedAircraftInfo({
civilian,
military,
trackedId: 'military:ae01ce',
}).layerId,
'military',
);
assert.equal(
resolveTrackedAircraftInfo({ civilian, military, trackedId: 'military:ae01ce' }).icao24,
resolveTrackedAircraftInfo({
civilian,
military,
trackedId: 'military:ae01ce',
}).icao24,
'ae01ce',
);
assert.equal(
resolveTrackedAircraftInfo({ civilian, military, trackedId: 'flights:aaa077' }).layerId,
resolveTrackedAircraftInfo({
civilian,
military,
trackedId: 'flights:aaa077',
}).layerId,
'flights',
);
// Case-insensitive: layers stamp lowercase hex, callers may not.
assert.equal(
resolveTrackedAircraftInfo({ civilian, military, trackedId: 'MILITARY:AE01CE' }).layerId,
resolveTrackedAircraftInfo({
civilian,
military,
trackedId: 'MILITARY:AE01CE',
}).layerId,
'military',
);
});
@@ -355,12 +406,38 @@ test('tracked-identity resolution falls back to layer precedence', () => {
const military = { icao24: 'ae01ce' };
// No stamped identity (or one that matches neither layer) keeps the historic
// civilian-first order so tracking paths without gevTrackedId still work.
assert.equal(resolveTrackedAircraftInfo({ civilian, military }).layerId, 'flights');
assert.equal(
resolveTrackedAircraftInfo({ civilian, military, trackedId: 'satellites:25544' }).layerId,
resolveTrackedAircraftInfo({ civilian, military }).layerId,
'flights',
);
assert.equal(resolveTrackedAircraftInfo({ military, trackedId: '' }).layerId, 'military');
assert.equal(resolveTrackedAircraftInfo({ trackedId: 'flights:aaa077' }), null);
assert.equal(
resolveTrackedAircraftInfo({
civilian,
military,
trackedId: 'satellites:25544',
}).layerId,
'flights',
);
assert.equal(
resolveTrackedAircraftInfo({ military, trackedId: '' }).layerId,
'military',
);
assert.equal(
resolveTrackedAircraftInfo({ trackedId: 'flights:aaa077' }),
null,
);
assert.equal(resolveTrackedAircraftInfo(), null);
});
test('cockpit emergency wording states the broadcast code, not a conclusion', () => {
assert.equal(
formatCockpitEmergency({ label: 'General emergency', squawk: '7700' }),
'SQUAWK 7700 · GENERAL EMERGENCY',
);
assert.equal(
formatCockpitEmergency({ label: 'Minimum fuel', squawk: null }),
'MINIMUM FUEL',
);
assert.equal(formatCockpitEmergency(null), null);
assert.equal(formatCockpitEmergency({ label: '' }), null);
});