Exchange

Struct Exchange 

Source
pub struct Exchange<const REQUEST: usize> { /* private fields */ }
Expand description

One operation against one device.

Implementations§

Source§

impl<const REQUEST: usize> Exchange<REQUEST>

Source

pub fn new(frame: &[u8], seed: u16, now_ms: u64) -> Result<Self, Failure>

Begin an operation carrying frame.

seed picks the first token. A device retains its answer to every recent token against retransmission, and answers a reused token with the retained response instead of executing — so the seed must come from above Exchange::counter of every exchange the device may still remember: a counter carried across exchanges, itself seeded unpredictably.

Source

pub fn token(&self) -> Token

The token now outstanding. A response carrying any other token belongs to someone else’s exchange.

Source

pub fn counter(&self) -> u16

The counter behind the last token this exchange issued.

A continued read issues a fresh token per fragment, so an exchange consumes a caller-invisible stretch of the counter space. The next exchange’s seed must come from above this value: the device holds every answered token against retransmission, and a new request under any of them is answered with the old response instead of running.

Source

pub fn remaining(&self) -> Option<u32>

The device’s most recent estimate of octets not yet returned, advisory and present only during a continued read.

Source

pub fn deadline_ms(&self) -> Option<u64>

When the outstanding attempt stops waiting, or None once the exchange has finished.

Source

pub fn poll(&mut self, now_ms: u64, out: &mut [u8]) -> Step

What to do now: send an attempt, wait for the deadline, or stop.

The first call hands out the first attempt; later calls hand out retransmissions of the identical request under the identical token, which the device answers from its retained response rather than executing again.

Source

pub fn delivered(&mut self) -> Step

A reset-class command has been delivered — the MAC acknowledged it — and no response is coming.

Calling this for anything else discards a reply that may still arrive; the caller checks Exchange::expects_response first.

Source

pub fn expects_response(&self) -> bool

Whether a response is guaranteed. False for the reset-class commands, whose completion is observed by reading state in a later exchange rather than by a reply.

One that arrives anyway is still accepted — CMD_RESTORE on a device with no saved snapshot resets nothing and answers like any other command — so this says when to wait on the acknowledgment instead, not when to stop listening.

Source

pub fn receive( &mut self, payload: &[u8], reassembly: &mut Reassembly<'_>, now_ms: u64, out: &mut [u8], ) -> Option<Step>

Feed an arriving Node Management Response payload, the payload type byte already stripped.

A payload whose token does not match the outstanding one is not this exchange’s; the caller discards it with accounting. Returns None in that case, and otherwise what to do next — which for a fragmented read is the next continuation to send.

Auto Trait Implementations§

§

impl<const REQUEST: usize> Freeze for Exchange<REQUEST>

§

impl<const REQUEST: usize> RefUnwindSafe for Exchange<REQUEST>

§

impl<const REQUEST: usize> Send for Exchange<REQUEST>

§

impl<const REQUEST: usize> Sync for Exchange<REQUEST>

§

impl<const REQUEST: usize> Unpin for Exchange<REQUEST>

§

impl<const REQUEST: usize> UnwindSafe for Exchange<REQUEST>

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.