Skip to main content

MissionReceiver

Struct MissionReceiver 

Source
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

Source

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.

Source

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

Source

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 - the MAV_MISSION_TYPE to transfer.
§Returns

The receiver, before any count is known.

Source

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.

Source

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.

Source

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.

Source

pub fn is_complete(&self) -> bool

Reports whether the transfer has finished.

§Returns

true once every item has been received and the acknowledgement produced.

Source

pub fn expected(&self) -> u16

Returns the next sequence number the receiver expects.

§Returns

The expected sequence number.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.