mirror of
https://github.com/OpenSquawk/OpenSquawk
synced 2026-08-04 08:06:26 +08:00
feat(live-atc): forward aircraft position, un-throttle bridge polling
- NormalizedTelemetry carries lat/lon (0/0 no-GPS guard, position in the change-detection signature) so the backend can derive distance triggers - bridge polling moves from setInterval to a Worker tick: with the sim in the foreground the /live-atc tab is backgrounded and Chrome throttles plain intervals to ~1/min — telemetry-driven ATC lagged behind the silence fallback Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,16 +7,22 @@ export function normalizeSimFreq(value: unknown): string | null {
|
||||
}
|
||||
|
||||
// Map the raw bridge telemetry (SimConnect-style field names) to the
|
||||
// sim-agnostic contract the backend understands. distance_to_*_nm are omitted
|
||||
// until pm.vue has a reliable airport-coordinate source to compute them from;
|
||||
// heading is currently true (bridge only reports true) — magnetic correction is
|
||||
// needed before any localizer/heading trigger can rely on it.
|
||||
// sim-agnostic contract the backend understands. The raw lat/lon position is
|
||||
// forwarded so the backend can derive distance_to_dep_nm / distance_to_dest_nm
|
||||
// (it has the airport coordinates via the session's ICAO codes); heading is
|
||||
// currently true (bridge only reports true) — magnetic correction is needed
|
||||
// before any localizer/heading trigger can rely on it.
|
||||
export function normalizeBridgeTelemetry(raw: any): NormalizedTelemetry | null {
|
||||
if (!raw || typeof raw !== 'object') return null
|
||||
const num = (v: unknown): number | undefined => {
|
||||
const n = typeof v === 'number' ? v : Number(v)
|
||||
return Number.isFinite(n) ? n : undefined
|
||||
}
|
||||
const lat = num(raw.PLANE_LATITUDE)
|
||||
const lon = num(raw.PLANE_LONGITUDE)
|
||||
// 0/0 is the bridge's "no GPS data" default — don't forward it as a position.
|
||||
const hasPosition =
|
||||
lat !== undefined && lon !== undefined && (Math.abs(lat) > 0.1 || Math.abs(lon) > 0.1)
|
||||
return {
|
||||
altitude_ft: num(raw.PLANE_ALTITUDE),
|
||||
ias_kts: num(raw.AIRSPEED_INDICATED),
|
||||
@@ -24,15 +30,19 @@ export function normalizeBridgeTelemetry(raw: any): NormalizedTelemetry | null {
|
||||
vs_fpm: num(raw.VERTICAL_SPEED),
|
||||
heading_deg: num(raw.PLANE_HEADING_DEGREES_TRUE),
|
||||
on_ground: typeof raw.SIM_ON_GROUND === 'boolean' ? raw.SIM_ON_GROUND : undefined,
|
||||
...(hasPosition ? { lat, lon } : {}),
|
||||
}
|
||||
}
|
||||
|
||||
// Only forward telemetry that meaningfully changed, so idle cruise doesn't POST
|
||||
// an identical tick every poll. Rounded so tiny jitter doesn't count as change.
|
||||
// Position rounds at ~0.01° (≈0.6 nm) so a moving aircraft keeps ticking the
|
||||
// backend's distance triggers without spamming while parked.
|
||||
export function telemetrySignature(t: NormalizedTelemetry): string {
|
||||
const r = (v: number | undefined, step: number) => (v === undefined ? '_' : Math.round(v / step))
|
||||
return [
|
||||
r(t.altitude_ft, 100), r(t.ias_kts, 5), r(t.gs_kts, 5),
|
||||
r(t.vs_fpm, 100), r(t.heading_deg, 5), t.on_ground ? 'G' : 'A',
|
||||
r(t.lat, 0.01), r(t.lon, 0.01),
|
||||
].join('|')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user