pub struct MissionReceiver { /* private fields */ }Expand description
Requests a plan’s items in order and collects them, ending with an acknowledgement.
The receiver tracks the announced count and the next expected sequence number. It never
stores items; each accepted item is handed back to the caller from
on_item.
Implementations§
Source§impl MissionReceiver
impl MissionReceiver
Sourcepub fn request_list_frame(&self, header: Header) -> Result<Frame>
pub fn request_list_frame(&self, header: Header) -> Result<Frame>
Builds the frame that starts a download.
§Arguments
header- the addressing fields to stamp on the frame.
§Returns
The MISSION_REQUEST_LIST frame.
§Errors
Returns MavlinkError::PayloadTooLong if the
message does not fit a frame, which a request list never fails.
Sourcepub fn on_frame(
&mut self,
frame: &Frame,
header: Header,
) -> Result<Option<ReceiverStep>>
pub fn on_frame( &mut self, frame: &Frame, header: Header, ) -> Result<Option<ReceiverStep>>
Handles an incoming frame, if it is one this transfer is waiting for.
A MISSION_COUNT opens the transfer and a MISSION_ITEM_INT advances it; any other
message is not this machine’s to handle and is reported as such rather than refused,
so a caller can route one link’s traffic through several machines.
§Arguments
frame- the frame off the link.header- the addressing fields to stamp on the reply.
§Returns
The step taken, or None if the frame carries a message this transfer does not
handle.
§Errors
Returns an error only if the reply does not fit a frame, which no mission message can cause; a short or long payload decodes the way the message layer defines.
§Examples
use pamoja_mavlink::dialect::{encode_message, MissionCount, MissionItemInt};
use pamoja_mavlink::protocol::{MissionReceiver, ReceiverAction};
use pamoja_mavlink::Header;
let vehicle = Header::new(1, 1, 0);
let station = Header::new(255, 190, 0);
let mut download = MissionReceiver::new(1, 1, 0);
// The vehicle announces one item, and the receiver asks for it.
let count = MissionCount { count: 1, target_system: 255, target_component: 190, mission_type: 0, opaque_id: 0 };
let step = download
.on_frame(&encode_message(vehicle, &count)?, station)?
.expect("a count is handled");
assert!(matches!(step.action, ReceiverAction::Request(request) if request.seq == 0));
assert_eq!(step.reply.message_id(), 51); // MISSION_REQUEST_INT
// A frame for some other machine is passed over rather than refused.
let heartbeat = pamoja_mavlink::dialect::Heartbeat { custom_mode: 0, type_: 2, autopilot: 3, base_mode: 0, system_status: 4, mavlink_version: 3 };
assert!(download.on_frame(&encode_message(vehicle, &heartbeat)?, station)?.is_none());Source§impl MissionReceiver
impl MissionReceiver
Sourcepub fn new(target_system: u8, target_component: u8, mission_type: u8) -> Self
pub fn new(target_system: u8, target_component: u8, mission_type: u8) -> Self
Creates a receiver for a plan from a target vehicle.
§Arguments
target_system- the sending system’s id.target_component- the sending component’s id.mission_type- theMAV_MISSION_TYPEto transfer.
§Returns
The receiver, before any count is known.
Sourcepub fn request_list(&self) -> MissionRequestList
pub fn request_list(&self) -> MissionRequestList
Builds the MissionRequestList that starts a download.
Used when the receiver initiates the transfer (a ground station downloading a plan); a
receiver that is answering an unsolicited MissionCount does not send it.
§Returns
The request-list message.
Sourcepub fn on_count(&mut self, count: u16) -> ReceiverAction
pub fn on_count(&mut self, count: u16) -> ReceiverAction
Handles the announced item count and returns the first action.
§Arguments
count- the number of items the sender will provide.
§Returns
A ReceiverAction::Request for item 0, or a ReceiverAction::Ack straight away if
the plan is empty.
Sourcepub fn on_item(
&mut self,
item: &MissionItemInt,
) -> (Option<MissionItemInt>, ReceiverAction)
pub fn on_item( &mut self, item: &MissionItemInt, ) -> (Option<MissionItemInt>, ReceiverAction)
Handles an incoming item and returns the accepted item plus the next action.
An in-order item is accepted and returned, and the receiver advances to request the next one or to acknowledge the transfer if it was the last. An out-of-order item is not accepted, and the expected sequence number is re-requested.
§Arguments
item- the decoded item.
§Returns
A pair of the accepted item (Some only when in order) and the next
ReceiverAction.
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Reports whether the transfer has finished.
§Returns
true once every item has been received and the acknowledgement produced.