Skip to main content

MissionSender

Struct MissionSender 

Source
pub struct MissionSender<'a> { /* private fields */ }
Expand description

Holds a plan and answers a receiver’s requests for its items.

The sender borrows the items and stamps the target ids, the mission type, and the requested sequence number onto each one as it is handed out, so the caller supplies only the item content (command, frame, position, parameters).

Implementations§

Source§

impl MissionSender<'_>

Source

pub fn count_frame(&self, header: Header) -> Result<Frame>

Builds the frame that opens an upload.

§Arguments
  • header - the addressing fields to stamp on the frame.
§Returns

The MISSION_COUNT frame.

§Errors

Returns MavlinkError::PayloadTooLong if the message does not fit a frame, which a count never fails.

Source

pub fn on_frame( &self, frame: &Frame, header: Header, ) -> Result<Option<SenderStep>>

Handles an incoming frame, if it is one this transfer answers.

A MISSION_REQUEST_LIST is answered with the count, a MISSION_REQUEST_INT (or the older MISSION_REQUEST) with the item asked for, and a request past the end of the plan with a MISSION_ACK reporting an invalid sequence. A MISSION_ACK from the receiver ends the transfer. Any other message is reported as not handled.

§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, Message, MissionItemInt, MissionRequestInt};
use pamoja_mavlink::protocol::{MissionSender, SenderStep};
use pamoja_mavlink::Header;

let waypoint = MissionItemInt { command: 16, x: -338_567_800, y: 1_512_153_000, z: 50.0, ..MissionItemInt::zeroed() };
let plan = [waypoint];
let upload = MissionSender::new(&plan, 1, 1, 0);

// The vehicle asks for item 0 and gets it back, stamped with its sequence number.
let request = MissionRequestInt { seq: 0, target_system: 255, target_component: 190, mission_type: 0 };
let step = upload
    .on_frame(&encode_message(Header::new(1, 1, 0), &request)?, Header::new(255, 190, 0))?
    .expect("a request is handled");
let SenderStep::Reply(reply) = step else { panic!("an item is sent") };
assert_eq!(MissionItemInt::decode(reply.payload())?.seq, 0);
Source§

impl<'a> MissionSender<'a>

Source

pub fn new( items: &'a [MissionItemInt], target_system: u8, target_component: u8, mission_type: u8, ) -> Self

Creates a sender for a plan bound for a target vehicle.

§Arguments
  • items - the mission items, in sequence order.
  • target_system - the receiving system’s id.
  • target_component - the receiving component’s id.
  • mission_type - the MAV_MISSION_TYPE of the plan.
§Returns

The sender.

Source

pub fn len(&self) -> u16

Returns the number of items in the plan.

§Returns

The item count.

Source

pub fn is_empty(&self) -> bool

Reports whether the plan has no items.

§Returns

true if the plan is empty.

Source

pub fn count(&self) -> MissionCount

Builds the MissionCount that opens the transfer.

§Returns

The count message to send first.

Source

pub fn item(&self, seq: u16) -> Option<MissionItemInt>

Builds the item to answer a request for seq, stamped with the sequence number, the target ids, and the mission type.

§Arguments
  • seq - the requested sequence number.
§Returns

The item to send, or None if seq is past the end of the plan.

Auto Trait Implementations§

§

impl<'a> Freeze for MissionSender<'a>

§

impl<'a> RefUnwindSafe for MissionSender<'a>

§

impl<'a> Send for MissionSender<'a>

§

impl<'a> Sync for MissionSender<'a>

§

impl<'a> Unpin for MissionSender<'a>

§

impl<'a> UnsafeUnpin for MissionSender<'a>

§

impl<'a> UnwindSafe for MissionSender<'a>

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.