pub struct Acu<T: Transport, C: Clock> {
pub reply_delay_ms: u32,
pub retry: RetryConfig,
/* private fields */
}Expand description
ACU driver.
Fields§
§reply_delay_ms: u32Reply-delay budget per attempt, in milliseconds.
retry: RetryConfigRetry policy applied by Acu::exchange.
Implementations§
Source§impl<T: Transport, C: Clock> Acu<T, C>
impl<T: Transport, C: Clock> Acu<T, C>
Sourcepub fn new(transport: T, clock: C) -> Self
pub fn new(transport: T, clock: C) -> Self
New driver with default reply delay and retry policy.
Sourcepub fn send_to(
&mut self,
pd_addr: u8,
pd: &mut PdState,
command: &Command,
) -> Result<Vec<u8>, Error>
pub fn send_to( &mut self, pd_addr: u8, pd: &mut PdState, command: &Command, ) -> Result<Vec<u8>, Error>
Encode and send command to pd_addr once. Returns the bytes written.
Sourcepub fn receive(&mut self, pd: &mut PdState) -> Result<Reply, Error>
pub fn receive(&mut self, pd: &mut PdState) -> Result<Reply, Error>
Drain whatever bytes the transport has, then attempt to parse one
reply. Returns Err(Error::Timeout) once the per-attempt
reply-delay budget elapses without a complete packet.
The loop reads up to a small fixed number of times per call to
drain a transport that may return short reads. When the underlying
transport returns Ok(0) (no more bytes immediately ready), we
check the deadline and either return Timeout or immediately
return — the caller is expected to call us again later.
Sourcepub fn exchange(
&mut self,
pd_addr: u8,
pd: &mut PdState,
command: &Command,
) -> Result<ExchangeOutcome, Error>
pub fn exchange( &mut self, pd_addr: u8, pd: &mut PdState, command: &Command, ) -> Result<ExchangeOutcome, Error>
Run a command/reply round-trip with full retry & off-line policy.
- On a clean reply, returns
ExchangeOutcome::Reply. - On
osdp_BUSY, returnsExchangeOutcome::Busywithout bumping SQN (per Annex A.2: BUSY’s SQN is always 0). The caller decides whether to retry now or service other PDs first. - On timeout, retries up to
RetryConfig::max_retriesadditional times re-using the same SQN — that asks the PD to repeat its prior reply, per §5.7 / Table 2. - When the PD has been silent for ≥
crate::OFFLINE_THRESHOLD_MS, returnsExchangeOutcome::Offline.
flowchart TD
enter([exchange]) --> off{is_offline?}
off -- yes --> O[Offline]
off -- no --> send[send_with_sqn]
send --> recv[recv_one_with_sqn]
recv --> kind{reply?}
kind -- BUSY --> bu["Busy<br/>(SQN unchanged)"]
kind -- typed --> ok["Reply<br/>(bump_sqn)"]
kind -- Timeout --> retry{"retries left?<br/>budget left?<br/>not offline?"}
retry -- yes --> send
retry -- no --> T[Timeout]