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<'_>
impl MissionSender<'_>
Sourcepub fn count_frame(&self, header: Header) -> Result<Frame>
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.
Sourcepub fn on_frame(
&self,
frame: &Frame,
header: Header,
) -> Result<Option<SenderStep>>
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>
impl<'a> MissionSender<'a>
Sourcepub fn new(
items: &'a [MissionItemInt],
target_system: u8,
target_component: u8,
mission_type: u8,
) -> Self
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- theMAV_MISSION_TYPEof the plan.
§Returns
The sender.