Show the drone's locked home point on the fly-mode map
Adds MSP_WP (118) support to query the flightcontroller's stored home point (WP#0 is a special case for this in iNAV's getWaypoint(), per navigation.c) - the FC reports (0,0,0) rather than an error before one is set, so parseMspHomePoint() treats that pair as "unset". Rendered with a small pentagon house icon (design/homepoint-pentagon.svg, ported to a CustomPainter like the other map icons). Deliberately not polled continuously: a new home_point_provider.dart refreshes it only at the three moments the FC's home point can actually change - connect/reconnect, GPS fix acquired, and arming (iNAV's default reset_home_type=FIRST_ARM only freezes it at the first arm; before that it continuously follows the aircraft while disarmed). Mock's implementation offsets the point 25m from the anchor so it doesn't sit exactly under the drone marker during UI testing.
This commit is contained in:
@@ -21,6 +21,22 @@ abstract final class MspCommands {
|
||||
/// msp_waypoint_codec.dart. (`fc_msp.c`, `case MSP_WP_GETINFO`)
|
||||
static const int wpGetInfo = 20;
|
||||
|
||||
/// Request-Payload (1 Byte): u8 wp_no. Response (21 Byte): u8 wp_no, u8
|
||||
/// action, i32 lat(1e-7 deg), i32 lon(1e-7 deg), i32 alt(cm), i16 p1, i16
|
||||
/// p2, i16 p3, u8 flag (`fc_msp.c`, `mspFcWaypointOutCommand()`, `case
|
||||
/// MSP_WP`). Kein Batch-Kommando - ein Request pro Wegpunktnummer, analog
|
||||
/// zu [setWp]. `wp_no` kennt laut `navigation.c` `getWaypoint()` zwei
|
||||
/// Sonderwerte neben echten Missions-Wegpunktnummern: 0 = Homepoint
|
||||
/// (`GPS_home.lat/lon/alt`, nur gueltig wenn `STATE(GPS_FIX_HOME)` -
|
||||
/// sonst liefert der FC (0,0,0) statt eines Fehlers, siehe
|
||||
/// msp_waypoint_codec.dart `parseMspHomePoint`), 255 = aktuelle
|
||||
/// Ist-Position. Der Homepoint selbst wird vom FC NICHT beim ersten
|
||||
/// GPS-Fix eingefroren, sondern folgt der Drohne kontinuierlich, solange
|
||||
/// sie disarmed ist und noch nie armed war (`updateHomePosition()`) -
|
||||
/// gesperrt wird er erst beim ersten Armen (iNAV-Default
|
||||
/// `reset_home_type = FIRST_ARM`, `settings.yaml`).
|
||||
static const int getWp = 118;
|
||||
|
||||
/// Request-Payload (21 Byte, siehe msp_waypoint_codec.dart
|
||||
/// `encodeMspSetWaypoint`): u8 wp_no, u8 action, i32 lat(1e-7 deg),
|
||||
/// i32 lon(1e-7 deg), i32 alt(cm), i16 p1, i16 p2, i16 p3, u8 flag. Nur
|
||||
|
||||
@@ -142,4 +142,21 @@ class MspFlightControllerLink implements FlightControllerLink {
|
||||
await client.request(MspCommands.navStatus),
|
||||
);
|
||||
}
|
||||
|
||||
/// Fragt WP#0 (Homepoint, siehe `MspCommands.getWp`-Doku) gezielt per
|
||||
/// `MSP_WP` ab - bewusst kein Teil von [MspTelemetryPoller]s Zyklus (Doku:
|
||||
/// "Homepoint muss nicht kontinuierlich abgefragt werden"), Aufrufer ist
|
||||
/// home_point_provider.dart.
|
||||
@override
|
||||
Future<HomePoint?> readHomePoint() async {
|
||||
final client = _client;
|
||||
if (client == null) {
|
||||
throw StateError('readHomePoint() vor connect() aufgerufen.');
|
||||
}
|
||||
final payload = await client.request(
|
||||
MspCommands.getWp,
|
||||
payload: encodeMspGetWaypointRequest(mspWpNumberHome),
|
||||
);
|
||||
return parseMspHomePoint(payload);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import '../../domain/waypoint/flat_waypoint_list.dart';
|
||||
import '../flight_controller_link.dart';
|
||||
|
||||
/// `navWaypointActions_e` (Doku Kommunikationsschicht v2 Abschnitt 6,
|
||||
/// geprueft gegen den iNAV-9.1.0-Quellcode: `navigation.h`). Nur die vier
|
||||
@@ -136,3 +137,30 @@ MspWpGetInfo parseMspWpGetInfo(Uint8List payload) {
|
||||
waypointCount: payload[3],
|
||||
);
|
||||
}
|
||||
|
||||
/// Sonderwert fuer [encodeMspGetWaypointRequest]/`MspCommands.getWp`: WP#0
|
||||
/// ist laut `navigation.c` `getWaypoint()` der Homepoint, kein echter
|
||||
/// Missions-Wegpunkt.
|
||||
const int mspWpNumberHome = 0;
|
||||
|
||||
/// Kodiert den 1-Byte-Request-Payload fuer `MspCommands.getWp` (`MSP_WP`).
|
||||
Uint8List encodeMspGetWaypointRequest(int wpNumber) =>
|
||||
Uint8List.fromList([wpNumber]);
|
||||
|
||||
/// Parst die 21-Byte-Antwort auf `MspCommands.getWp` fuer `wp_no ==
|
||||
/// [mspWpNumberHome]` (siehe dortige Doku zu `getWaypoint()`/`GPS_home`).
|
||||
///
|
||||
/// Liefert `null`, wenn der FC noch keinen Homepoint gesetzt hat: dafuer
|
||||
/// gibt es kein eigenes Flag in der Antwort selbst, `getWaypoint()`
|
||||
/// initialisiert `lat`/`lon`/`alt` aber generell auf 0 und ueberschreibt
|
||||
/// das fuer WP#0 nur, wenn `STATE(GPS_FIX_HOME)` gesetzt ist - (0,0) ist
|
||||
/// also der FC-eigene "kein Homepoint"-Wert, nicht eine echte Koordinate
|
||||
/// am Nullmeridian/Aequator.
|
||||
HomePoint? parseMspHomePoint(Uint8List payload) {
|
||||
final d = ByteData.sublistView(payload);
|
||||
final lat = d.getInt32(2, Endian.little) / 1e7;
|
||||
final lon = d.getInt32(6, Endian.little) / 1e7;
|
||||
if (lat == 0 && lon == 0) return null;
|
||||
final altCm = d.getInt32(10, Endian.little);
|
||||
return HomePoint(lat: lat, lon: lon, altitudeM: altCm / 100);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user