The GO 4-style HUD needs far more live data than the bridge sent, and pushing every SDK callback straight to Dart would rebuild the screen dozens of times a second. This is the telemetry foundation (plan P1). On the Kotlin side, every source now writes into a TelemetryHub that emits one telemetry event per tick: flight-controller state, gimbal and vision at up to 10 Hz, battery, links, RC, storage and camera settings folded in at up to 2 Hz. Each event carries the full latest snapshot, so a consumer that drops packets never loses a slow group. New bridges cover batteries (every pack, cell voltages, warning thresholds), link quality and RC battery, diagnostics, and obstacle sensing per sensor. KeyBridge adds generic getKey/setKey/listenKey over KeyManager for the settings rows to come. The flight controller also gains smart-RTH confirmation and simulator start/stop. On the Dart side, FlightModel now owns one ChangeNotifier per subsystem (aircraft, battery, links, camera, gimbal, vision, alerts, mission), so a HUD widget can listen to just the one it draws. TelemetryReducer routes events into them, only notifies groups that changed, and gives FlightModel one notification per tick. Flat getters keep the existing screens working. Diagnostics become graded, de-duplicated alerts. Settings > About > Telemetry inspector shows every field live and can start the simulator. Battery no longer arrives as its own event, so the API Server reads the percentage from the telemetry snapshot (the old event is still accepted). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
166 lines
5.3 KiB
Dart
166 lines
5.3 KiB
Dart
/// Synthetic bridge events in the shape `TelemetryHub.kt` and the sub-bridges
|
|
/// emit, standing in for a simulator recording until one is captured (plan §4).
|
|
library;
|
|
|
|
/// A Phantom 4-like aircraft hovering at 32 m, all groups reported.
|
|
Map<String, dynamic> telemetryTick({
|
|
int battery = 64,
|
|
double altitude = 32.4,
|
|
double gimbalPitch = -30,
|
|
int uplink = 88,
|
|
double noseDistance = 6.5,
|
|
String? smartRTHState = 'IDLE',
|
|
}) =>
|
|
<String, dynamic>{
|
|
'type': 'telemetry',
|
|
'satelliteCount': 17,
|
|
'gpsSignalLevel': 5,
|
|
'isFlying': true,
|
|
'areMotorsOn': true,
|
|
'flightMode': 'P-GPS',
|
|
'flightModeEnum': 'GPS_ATTI',
|
|
'altitude': altitude,
|
|
'latitude': 55.6761,
|
|
'longitude': 12.5683,
|
|
'homeLatitude': 55.6760,
|
|
'homeLongitude': 12.5680,
|
|
'isHomeLocationSet': true,
|
|
'homeDistance': 21.3,
|
|
'horizontalSpeed': 0.2,
|
|
'verticalSpeed': -0.1,
|
|
'heading': 87.5,
|
|
'pitch': -1.2,
|
|
'roll': 0.4,
|
|
'yaw': 87.5,
|
|
'goHomeHeight': 60,
|
|
'velocityX': 0.1,
|
|
'velocityY': 0.15,
|
|
'velocityZ': 0.1,
|
|
'flightTimeSeconds': 245,
|
|
'ultrasonicHeight': double.nan,
|
|
'isUltrasonicBeingUsed': false,
|
|
'ultrasonicError': false,
|
|
'isVisionPositioningBeingUsed': false,
|
|
'isLandingConfirmationNeeded': false,
|
|
'isGoingHome': false,
|
|
'goHomeExecutionState': 'NOT_EXECUTING',
|
|
'isLowBattery': false,
|
|
'isSeriousLowBattery': false,
|
|
'batteryThresholdBehavior': 'FLY_NORMALLY',
|
|
'windWarning': 'LEVEL_0',
|
|
'reachedMaxHeight': false,
|
|
'reachedMaxRadius': false,
|
|
'isIMUPreheating': false,
|
|
'isFailsafe': false,
|
|
'orientationMode': 'AIRCRAFT_HEADING',
|
|
'goHome': <Object?, Object?>{
|
|
'remainingFlightTime': 780,
|
|
'timeNeededToGoHome': 40,
|
|
'timeNeededToLand': 22,
|
|
'batteryNeededToGoHome': 12,
|
|
'batteryNeededToLand': 6,
|
|
'maxRadiusCanFlyAndGoHome': 2400.0,
|
|
'smartRTHState': smartRTHState,
|
|
'smartRTHCountdown': 0,
|
|
},
|
|
'gimbal': <Object?, Object?>{'pitch': gimbalPitch, 'roll': 0.0, 'yaw': 87.0},
|
|
'vision': <Object?, Object?>{
|
|
'NOSE': <Object?, Object?>{
|
|
'isSensorBeingUsed': true,
|
|
'isDisabled': false,
|
|
'systemWarning': 'SAFE',
|
|
'distance': noseDistance,
|
|
'avoidAlertLevel': 0,
|
|
'sectors': <Object?>[
|
|
<Object?, Object?>{'distance': 9.0, 'warningLevel': 'LEVEL_1'},
|
|
<Object?, Object?>{'distance': noseDistance, 'warningLevel': 'LEVEL_2'},
|
|
<Object?, Object?>{'distance': 12.0, 'warningLevel': 'LEVEL_1'},
|
|
<Object?, Object?>{'distance': 15.0, 'warningLevel': 'INVALID'},
|
|
],
|
|
},
|
|
},
|
|
'battery': <Object?, Object?>{
|
|
'percent': battery,
|
|
'voltage': 15.6,
|
|
'temperature': 38.5,
|
|
'lowWarningThreshold': 30,
|
|
'seriousLowWarningThreshold': 15,
|
|
'packs': <Object?>[
|
|
<Object?, Object?>{
|
|
'index': 0,
|
|
'percent': battery,
|
|
'voltage': 15.6,
|
|
'current': -9.8,
|
|
'temperature': 38.5,
|
|
'chargeRemainingMah': 3500,
|
|
'fullChargeCapacityMah': 5350,
|
|
'designCapacityMah': 5870,
|
|
'discharges': 42,
|
|
'lifetimePercent': 91,
|
|
'isCharging': false,
|
|
'cellVoltages': <Object?>[3.91, 3.90, 3.92, 3.88],
|
|
'cellVoltageLevel': 'LEVEL_0',
|
|
'connectionState': 'NORMAL',
|
|
},
|
|
],
|
|
},
|
|
'links': <Object?, Object?>{'kind': 'lightbridge', 'uplinkQuality': uplink, 'downlinkQuality': 74},
|
|
'rc': <Object?, Object?>{'batteryPercent': 81, 'batteryMah': 4200, 'isCharging': false},
|
|
'storage': <Object?, Object?>{
|
|
'location': 'SDCARD',
|
|
'inserted': true,
|
|
'initializing': false,
|
|
'formatting': false,
|
|
'formatted': true,
|
|
'full': false,
|
|
'error': false,
|
|
'readOnly': false,
|
|
'invalidFormat': false,
|
|
'verified': true,
|
|
'totalMB': 61000,
|
|
'remainingMB': 48211,
|
|
'availableCaptureCount': 5400,
|
|
'availableRecordingSeconds': 7260,
|
|
},
|
|
'cameraSettings': <Object?, Object?>{
|
|
'aeLock': false,
|
|
'focusMode': 'AFC',
|
|
'photoAspectRatio': 'RATIO_3_2',
|
|
'photoFileFormat': 'RAW_AND_JPEG',
|
|
'videoResolution': 'RESOLUTION_3840x2160',
|
|
'videoFrameRate': 'FRAME_RATE_29_DOT_970_FPS',
|
|
'videoFileFormat': 'MOV',
|
|
'colorProfile': 'NONE',
|
|
},
|
|
};
|
|
|
|
Map<String, dynamic> diagnostics(List<Map<String, Object?>> items) => <String, dynamic>{
|
|
'type': 'diagnostics',
|
|
'items': items,
|
|
};
|
|
|
|
const Map<String, Object?> compassInterference = <String, Object?>{
|
|
'component': 'FLIGHT_CONTROLLER',
|
|
'code': 1004,
|
|
'subCode': 0,
|
|
'componentIndex': 0,
|
|
'reason': 'Compass interference.',
|
|
'solution': 'Move away from metal objects.',
|
|
};
|
|
|
|
const Map<String, Object?> motorBlocked = <String, Object?>{
|
|
'component': 'FLIGHT_CONTROLLER',
|
|
'code': 1301,
|
|
'componentIndex': 0,
|
|
'reason': 'Motor blocked.',
|
|
'solution': 'Land and check the propellers.',
|
|
};
|
|
|
|
const Map<String, Object?> sdSlow = <String, Object?>{
|
|
'component': 'CAMERA',
|
|
'code': 2010,
|
|
'componentIndex': 0,
|
|
'reason': 'SD card write speed slow.',
|
|
'solution': null,
|
|
};
|