Namespace MavNet.PX4.Missions

Classes

MissionClient

Implements the MAVLink mission-protocol upload and download state machines for one (target, MavNet.Protocol.Generated.Enums.MavMissionType) pair on top of an IMavlinkConnection. One MissionClient handles one mission type (waypoints, fence, or rally) — Vehicle owns one per type so the three transactions can run independently per spec.

Upload. Caller invokes UploadAsync(IReadOnlyList<MissionItem>, CancellationToken). We send MISSION_COUNT, then for each MISSION_REQUEST_INT (or its deprecated MISSION_REQUEST sibling that ArduPilot still emits) we reply with a MISSION_ITEM_INT. After the final item the vehicle answers with MISSION_ACK, which terminates the transaction.

Download. Caller invokes DownloadAsync(CancellationToken). We send MISSION_REQUEST_LIST, the vehicle responds with MISSION_COUNT (carrying the on-vehicle opaque_id), then we send a MISSION_REQUEST_INT per item in order and collect each MISSION_ITEM_INT reply. After the final item we send a final MISSION_ACK(MAV_MISSION_ACCEPTED) per spec to close the transaction.

Timing. Per the MAVLink spec: 1500 ms default timeout, 250 ms for the inner item loop, max 5 retries. Defaults are baked in but all three are constructor-injectable so tests stay sub-second.

Out-of-sequence is not an error. If the vehicle re-requests an earlier seq during upload, we re-answer with that item rather than abort. If the vehicle answers with an unexpected seq during download, we just ignore it and let the watchdog re-request. Per spec only timeout exhaustion and a non-Accepted MISSION_ACK cause a transaction to fail.

Threading. Inbound events fire on the connection's receive thread. All mutable state is guarded by an internal lock; the lock window only covers the state mutation, never the awaiter's continuation (the result Task uses RunContinuationsAsynchronously).

Single-flight. Only one transaction may be in flight per MissionClient, regardless of direction. A concurrent UploadAsync(IReadOnlyList<MissionItem>, CancellationToken) or DownloadAsync(CancellationToken) throws InvalidOperationException.

Structs

MissionClearResult

Terminal state of one mission-clear transaction.

MissionDownloadResult

Terminal state of one mission download transaction.

MissionItem

Protocol-shaped mission item — mirrors the MAVLink MISSION_ITEM_INT wire layout but without the per-transaction fields (Seq, TargetSystem, TargetComponent, MissionType). MissionClient stamps those in when it sends each item.

Coordinate scaling matches the spec: for global frames, X / Y are degrees × 1e7; for local frames, metres × 1e4. Z is always a float. Use the static factories (Waypoint, Takeoff, Land, ReturnToLaunch) to avoid hand-scaling.

The same record is used for waypoint, geofence, and rally-point missions — the Command field plus MAV_MISSION_TYPE (passed to the MissionClient) determine the semantics.

MissionUploadResult

Terminal state of one mission upload transaction.

Enums

MissionTransactionStatus

How a mission upload transaction terminated.