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>
43 lines
1.4 KiB
Dart
43 lines
1.4 KiB
Dart
/// Lenient readers for bridge maps: the platform channel hands numbers over as
|
|
/// int or double depending on the Java type, and nested maps as `Map<Object?, Object?>`.
|
|
library;
|
|
|
|
double? asDouble(Object? v) => v is num ? v.toDouble() : null;
|
|
|
|
int? asInt(Object? v) => v is num ? v.toInt() : null;
|
|
|
|
bool? asBool(Object? v) => v is bool ? v : null;
|
|
|
|
String? asString(Object? v) => v is String ? v : null;
|
|
|
|
Map<String, dynamic>? asMap(Object? v) => v is Map ? Map<String, dynamic>.from(v) : null;
|
|
|
|
List<Map<String, dynamic>> asMapList(Object? v) =>
|
|
v is List ? <Map<String, dynamic>>[for (final Object? e in v) if (e is Map) Map<String, dynamic>.from(e)] : const <Map<String, dynamic>>[];
|
|
|
|
/// Doubles that are actually reported: the SDK fills unknown floats with NaN.
|
|
double? finite(Object? v) {
|
|
final double? d = asDouble(v);
|
|
return d == null || d.isNaN || d.isInfinite ? null : d;
|
|
}
|
|
|
|
/// Structural equality for decoded channel values (maps, lists, scalars).
|
|
bool deepEquals(Object? a, Object? b) {
|
|
if (identical(a, b)) return true;
|
|
if (a is Map && b is Map) {
|
|
if (a.length != b.length) return false;
|
|
for (final Object? k in a.keys) {
|
|
if (!b.containsKey(k) || !deepEquals(a[k], b[k])) return false;
|
|
}
|
|
return true;
|
|
}
|
|
if (a is List && b is List) {
|
|
if (a.length != b.length) return false;
|
|
for (int i = 0; i < a.length; i++) {
|
|
if (!deepEquals(a[i], b[i])) return false;
|
|
}
|
|
return true;
|
|
}
|
|
return a == b;
|
|
}
|