pub struct Exchange<const REQUEST: usize> { /* private fields */ }Expand description
One operation against one device.
Implementations§
Source§impl<const REQUEST: usize> Exchange<REQUEST>
impl<const REQUEST: usize> Exchange<REQUEST>
Sourcepub fn new(frame: &[u8], seed: u16, now_ms: u64) -> Result<Self, Failure>
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.
Sourcepub fn token(&self) -> Token
pub fn token(&self) -> Token
The token now outstanding. A response carrying any other token belongs to someone else’s exchange.
Sourcepub fn counter(&self) -> u16
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.
Sourcepub fn remaining(&self) -> Option<u32>
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.
Sourcepub fn deadline_ms(&self) -> Option<u64>
pub fn deadline_ms(&self) -> Option<u64>
When the outstanding attempt stops waiting, or None once the
exchange has finished.
Sourcepub fn poll(&mut self, now_ms: u64, out: &mut [u8]) -> Step
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.
Sourcepub fn delivered(&mut self) -> Step
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.
Sourcepub fn expects_response(&self) -> bool
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.
Sourcepub fn receive(
&mut self,
payload: &[u8],
reassembly: &mut Reassembly<'_>,
now_ms: u64,
out: &mut [u8],
) -> Option<Step>
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.