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
impl CommandProtocol
Sourcepub fn confirmation(&self) -> u8
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.
Sourcepub fn on_ack(&self, ack: &CommandAck) -> AckOutcome
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.
Sourcepub fn on_timeout(&mut self) -> Option<u8>
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
impl CommandProtocol
Sourcepub fn on_frame(&self, frame: &Frame) -> Result<Option<AckOutcome>>
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
impl Clone for CommandProtocol
Source§fn clone(&self) -> CommandProtocol
fn clone(&self) -> CommandProtocol
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more