Implement waypoint mission upload (MSP_SET_WP) and Fly-mode send button
Fills in MspFlightControllerLink.uploadMission(), which previously just threw UnimplementedError, plus a new verifyMission() (both now on the generic FlightControllerLink interface, protocol-neutral by signature - MAVLink/ArduPilot get their own implementation later without touching callers). All iNAV-specific encoding lives in the new msp_waypoint_codec.dart: - encodeMspSetWaypoint(): the 21-byte MSP_SET_WP payload. Action/P1/P2/P3 byte layout was checked against the actual iNAV 9.1.0 source (navigation.c/navigation.h), not guessed - notably our generic `loiter` action has no configurable duration, so it maps to NAV_WP_ACTION_HOLD_TIME with the max representable p1 (int16 max, not 0xFFFF - that would read as -1 and end the hold immediately instead of never). - parseMspWpGetInfo(): decodes MSP_WP_GETINFO's validity/count fields, used by verifyMission() to confirm the FC actually accepted the full mission (Doku 2.2/4.5 Ready-to-Fly-Gate: "upload + verified"). uploadMission() sends one MSP_SET_WP per waypoint in order (iNAV has no batch command - WP#1 resets the FC's mission list, every next number must follow immediately, only the last carries NAV_WP_FLAG_LAST) and rejects missions above NAV_MAX_WAYPOINTS upfront instead of silently truncating. MissionSyncService now calls the real verifyMission() instead of always confirming, throwing MissionVerificationException when the FC doesn't confirm the mission. FlyScreen's footer swaps the warnings button for a send button (Doku: "ersetze den warnings button mit einem wp send button", pink horizontal PaperPlaneIcon, matching the existing paper-plane drone iconography) - warnings/event log stay reachable via the drone status pill's Warnings tab. BottomStatsBar/MissionFooterBar gained onSendTap/sending in place of the old forceShowWarningsButton. Verified end to end on the Pixel_10a emulator: tapping send with WLAN as the active connection type triggers the real WifiNetworkSpecifier flow through MspFlightControllerLink (correctly reports "no devices found" - expected, no real mLRS bridge on the emulator); the actual MSP_SET_WP/ MSP_WP_GETINFO wire behavior is covered by tests against a fake FC responder over LoopbackTransport instead. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
5fa55ac67d
commit
13475cc4f3
@@ -5,6 +5,7 @@ import 'msp_client.dart';
|
||||
import 'msp_commands.dart';
|
||||
import 'msp_telemetry_codec.dart';
|
||||
import 'msp_telemetry_poller.dart';
|
||||
import 'msp_waypoint_codec.dart';
|
||||
|
||||
/// iNAV-Anbindung via MSP (Architektur-Doku 3.1), umgesetzt gegen den
|
||||
/// tatsaechlichen iNAV-9.1.0-Quellcode (Doku Kommunikationsschicht Abschnitt
|
||||
@@ -17,11 +18,11 @@ import 'msp_telemetry_poller.dart';
|
||||
/// oder spaeter WLAN/UDP steckt, ist fuer diese Klasse unsichtbar.
|
||||
///
|
||||
/// Setzt die in der Doku vorgegebene Reihenfolge um: Rahmen kodieren/
|
||||
/// dekodieren + Telemetrie lesen (dieser Schritt). Missionsupload,
|
||||
/// Flugmodus-Wechsel und Armen sind bewusst noch nicht umgesetzt (Doku 4,
|
||||
/// "Reihenfolge der Umsetzung": "Erst danach Missionsupload") - das sind
|
||||
/// eigene, sicherheitsrelevante Schritte (u.a. `MSP_SET_WP`), die eigene
|
||||
/// Sorgfalt brauchen.
|
||||
/// dekodieren, Telemetrie lesen, Missionsupload (`MSP_SET_WP`, siehe
|
||||
/// msp_waypoint_codec.dart fuer das Byte-Layout und die
|
||||
/// Aktions-P1/P2/P3-Belegung). Flugmodus-Wechsel und Armen sind weiterhin
|
||||
/// bewusst nicht umgesetzt - eigene, sicherheitsrelevante Schritte, die
|
||||
/// eigene Sorgfalt brauchen.
|
||||
class MspFlightControllerLink implements FlightControllerLink {
|
||||
MspFlightControllerLink({required this.transport});
|
||||
|
||||
@@ -35,9 +36,12 @@ class MspFlightControllerLink implements FlightControllerLink {
|
||||
supportsMultiMission: true,
|
||||
supportsInFlightUpload: false,
|
||||
// Konservativer iNAV-Default (navigation.h: NAV_MAX_WAYPOINTS = 15).
|
||||
// Viele Boards/Targets erlauben mehr; ohne eine MSP_WP_GETINFO-
|
||||
// Abfrage (Teil des noch nicht umgesetzten Missions-Uploads) nicht
|
||||
// praeziser bestimmbar.
|
||||
// Viele Boards/Targets erlauben mehr; uploadMission() fragt das nicht
|
||||
// live per MSP_WP_GETINFO ab (dessen maxWaypoints-Feld wird nur zur
|
||||
// Verifikation nach dem Upload gelesen, siehe verifyMission()) -
|
||||
// ein client-seitiger Vorab-Check gegen diesen Default verhindert
|
||||
// trotzdem, dass wir versuchen, mehr Wegpunkte zu senden, als der FC
|
||||
// WP-Nummern dafuer reserviert (WP#1..#15).
|
||||
maxWaypoints: 15,
|
||||
);
|
||||
|
||||
@@ -68,11 +72,46 @@ class MspFlightControllerLink implements FlightControllerLink {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> uploadMission(FlatWaypointList mission) =>
|
||||
throw UnimplementedError(
|
||||
'Missions-Upload (MSP_SET_WP) ist noch nicht umgesetzt - Doku '
|
||||
'Kommunikationsschicht 4 sieht das erst nach dem Telemetrie-Schritt vor.',
|
||||
Future<void> uploadMission(FlatWaypointList mission) async {
|
||||
final client = _client;
|
||||
if (client == null) {
|
||||
throw StateError('uploadMission() vor connect() aufgerufen.');
|
||||
}
|
||||
final waypoints = mission.waypoints;
|
||||
if (waypoints.isEmpty) {
|
||||
throw ArgumentError('Mission ohne Wegpunkte kann nicht hochgeladen werden.');
|
||||
}
|
||||
if (waypoints.length > capabilities.maxWaypoints) {
|
||||
throw ArgumentError(
|
||||
'Mission hat ${waypoints.length} Wegpunkte, iNAV erlaubt hier '
|
||||
'maximal ${capabilities.maxWaypoints} (NAV_MAX_WAYPOINTS).',
|
||||
);
|
||||
}
|
||||
|
||||
// MSP_SET_WP kennt kein Batch-Kommando - der FC nimmt WP-fuer-WP nur
|
||||
// entweder WP#1 (startet damit eine neue Mission, resetWaypointList())
|
||||
// oder direkt den naechsten erwarteten WP# an (navigation.c
|
||||
// setWaypoint()). Erst das NAV_WP_FLAG_LAST auf dem letzten Wegpunkt
|
||||
// macht die Mission fuer den FC gueltig, siehe verifyMission().
|
||||
for (var i = 0; i < waypoints.length; i++) {
|
||||
final payload = encodeMspSetWaypoint(
|
||||
waypoints[i],
|
||||
wireIndex: i + 1,
|
||||
isLast: i == waypoints.length - 1,
|
||||
);
|
||||
await client.request(MspCommands.setWp, payload: payload);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> verifyMission(FlatWaypointList mission) async {
|
||||
final client = _client;
|
||||
if (client == null) {
|
||||
throw StateError('verifyMission() vor connect() aufgerufen.');
|
||||
}
|
||||
final info = parseMspWpGetInfo(await client.request(MspCommands.wpGetInfo));
|
||||
return info.isValid && info.waypointCount == mission.waypoints.length;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> setFlightMode(FlightMode mode) => throw UnimplementedError(
|
||||
|
||||
Reference in New Issue
Block a user