Skip to main content

CommandProtocol

Struct CommandProtocol 

Source
pub struct CommandProtocol { /* private fields */ }
Expand description

Tracks one command awaiting its acknowledgement: which command, the retransmission confirmation count, and the retries left.

Implementations§

Source§

impl CommandProtocol

Source

pub fn new(command: u16, max_retries: u8) -> Self

Starts tracking a command, allowing max_retries retransmissions.

§Arguments
  • command - the MAV_CMD id being sent.
  • max_retries - how many times the command may be resent after a timeout before the caller gives up.
§Returns

The protocol tracker, with confirmation at zero.

Source

pub fn command(&self) -> u16

Returns the command id being tracked.

§Returns

The command id.

Source

pub fn confirmation(&self) -> u8

Returns the confirmation count to stamp on the command being sent.

It is zero for the first transmission and increments on each retransmission, which is how an autopilot distinguishes a resend from a new command.

§Returns

The current confirmation count.

Source

pub fn on_ack(&self, ack: &CommandAck) -> AckOutcome

Classifies an incoming acknowledgement against the command in flight.

§Arguments
  • ack - the decoded acknowledgement.
§Returns

AckOutcome::Unrelated if the ack is for another command, AckOutcome::InProgress if the command is still running, or AckOutcome::Final with the result otherwise.

Source

pub fn on_timeout(&mut self) -> Option<u8>

Records a timeout and reports whether the command may be resent.

On a resend the confirmation count is incremented so the next call to confirmation stamps the new value.

§Returns

Some(confirmation) with the new count if a retry remains, or None once the retry budget is exhausted.

Source§

impl CommandProtocol

Source

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

Classifies an incoming frame against the command in flight, if it is an acknowledgement.

§Arguments
  • frame - the frame off the link.
§Returns

The outcome, or None if the frame is not a COMMAND_ACK.

§Errors

Never fails in practice; the Result mirrors the message layer, which zero-extends a short payload and ignores the tail of a long one rather than refusing either.

§Examples
use pamoja_mavlink::dialect::{encode_message, mav_cmd, mav_result, CommandAck};
use pamoja_mavlink::protocol::{AckOutcome, CommandProtocol};
use pamoja_mavlink::Header;

let arm = CommandProtocol::new(mav_cmd::COMPONENT_ARM_DISARM, 3);
let ack = CommandAck { command: mav_cmd::COMPONENT_ARM_DISARM, result: mav_result::ACCEPTED, ..CommandAck::zeroed() };
let outcome = arm.on_frame(&encode_message(Header::new(1, 1, 0), &ack)?)?;
assert_eq!(outcome, Some(AckOutcome::Final(mav_result::ACCEPTED)));

Trait Implementations§

Source§

impl Clone for CommandProtocol

Source§

fn clone(&self) -> CommandProtocol

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for CommandProtocol

Source§

impl Debug for CommandProtocol

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.