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
@@ -2,15 +2,19 @@ import 'dart:async';
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
|
||||
import '../../../app_mode/app_mode_cubit.dart';
|
||||
import '../../../domain/mission/mission_stats.dart';
|
||||
import '../../../domain/mission/mission_warnings.dart';
|
||||
import '../../../domain/mission/route_geometry.dart';
|
||||
import '../../../domain/telemetry/drone_status.dart';
|
||||
import '../../../domain/waypoint/flat_waypoint_list.dart';
|
||||
import '../../../domain/wind/wind_math.dart';
|
||||
import '../../../services/mission_sync_service.dart';
|
||||
import '../../../transport/flight_controller_link.dart';
|
||||
import '../../providers/active_drone_profile_provider.dart';
|
||||
import '../../providers/current_mission_provider.dart';
|
||||
@@ -43,6 +47,7 @@ class FlyScreen extends ConsumerStatefulWidget {
|
||||
class _FlyScreenState extends ConsumerState<FlyScreen> {
|
||||
late final MapController _mapController;
|
||||
StreamSubscription<MapEvent>? _mapEventSub;
|
||||
bool _sending = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -123,6 +128,36 @@ class _FlyScreenState extends ConsumerState<FlyScreen> {
|
||||
));
|
||||
}
|
||||
|
||||
/// Laedt die aktuelle Mission auf den Flightcontroller (Doku 2.2/4.5:
|
||||
/// Connect -> Upload -> Verify) - MissionSyncService kennt selbst kein
|
||||
/// UI, deshalb hier Ladezustand/Fehleranzeige. uploadMission() der
|
||||
/// jeweiligen FlightControllerLink-Implementierung verweigert den Versand
|
||||
/// bereits selbst im armed-Zustand (Doku 4.5); dieser Handler prueft nur
|
||||
/// den trivialen Fall (keine Wegpunkte), um nicht unnoetig einen
|
||||
/// Verbindungsversuch auszuloesen.
|
||||
Future<void> _onSendTap() async {
|
||||
final waypoints = ref.read(currentMissionProvider);
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
if (waypoints.isEmpty) {
|
||||
messenger.showSnackBar(const SnackBar(content: Text('No waypoints to send')));
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() => _sending = true);
|
||||
try {
|
||||
final service = MissionSyncService(
|
||||
ref.read(flightControllerLinkProvider),
|
||||
context.read<AppModeCubit>(),
|
||||
);
|
||||
await service.syncAndUpload(FlatWaypointList(waypoints));
|
||||
messenger.showSnackBar(const SnackBar(content: Text('Mission sent')));
|
||||
} catch (e) {
|
||||
messenger.showSnackBar(SnackBar(content: Text('Send failed: $e')));
|
||||
} finally {
|
||||
if (mounted) setState(() => _sending = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final waypoints = ref.watch(currentMissionProvider);
|
||||
@@ -132,8 +167,12 @@ class _FlyScreenState extends ConsumerState<FlyScreen> {
|
||||
// Beobachtet das Ereignis-Log dauerhaft ab dem ersten Eintritt in den
|
||||
// Fly-Modus (Doku: "log von kritischen ereignissen mit time stamp") -
|
||||
// haelt drone_event_log_provider.dart's Notifier am Leben, solange
|
||||
// dieser Screen existiert, siehe dessen Klassendoku.
|
||||
final droneEventLog = ref.watch(droneEventLogProvider);
|
||||
// dieser Screen existiert, siehe dessen Klassendoku. Der Rueckgabewert
|
||||
// selbst wird hier nicht mehr gebraucht (der Warnungs-Knopf, der ihn
|
||||
// frueher fuer forceShowWarningsButton auswertete, ist im Fly-Modus
|
||||
// durch den Sende-Knopf ersetzt, siehe onSendTap unten) - Warnungen/
|
||||
// Ereignis-Log bleiben ueber die Drohnen-Status-Pille erreichbar.
|
||||
ref.watch(droneEventLogProvider);
|
||||
|
||||
// Solange der ueber den GPS-Knopf in der Kopfleiste (FlyMapControls)
|
||||
// aktivierte Folgemodus aktiv ist, jede neue Telemetrie-Position
|
||||
@@ -301,7 +340,8 @@ class _FlyScreenState extends ConsumerState<FlyScreen> {
|
||||
warnings: warnings,
|
||||
showWarningsBanner: false,
|
||||
batteryPercent: telemetry?.batteryPercent,
|
||||
forceShowWarningsButton: droneEventLog.isNotEmpty,
|
||||
onSendTap: _onSendTap,
|
||||
sending: _sending,
|
||||
onDetailsTap: _openWaypointList,
|
||||
onWarningsTap: _openDroneStatusWarningsPanel,
|
||||
onSettingsTap: () => Navigator.of(context).push(MaterialPageRoute(
|
||||
|
||||
Reference in New Issue
Block a user