Expand description
Pure-Rust, no_std-friendly implementation of the SIA OSDP v2.2 protocol.
§Crate features
std(default): enablesalloc, plus desktop convenience.alloc(default viastd): enablesalloc::vec::Vec-based codec paths.secure-channel(default): enables Annex D (AES-128, MAC, encryption).embedded-io/embedded-io-async: transport adapters.defmt: structured logging on embedded targets.
§Layering
See architecture for a rendered diagram of how these modules relate.
packet— wire framing (SOM, header, SCB, MAC, trailer)command/reply— typed messagesmultipart— RFC §5.10 multi-part assembly / disassemblysecure— Annex D secure channeltransport— byte-stream abstractiondriver— ACU and PD state machinescaps— Annex B function codes
§Quick start
Drive a PD at address 0x05 through one POLL exchange. The example uses
transport::VecTransport, so without a peer feeding bytes back the
exchange will end in driver::acu::ExchangeOutcome::Timeout — wire it
up to a real Transport (or another VecTransport, see
examples/loopback_poll.rs) for a successful round-trip.
use osdp::clock::SystemClock;
use osdp::command::{Command, Poll};
use osdp::driver::acu::{Acu, ExchangeOutcome, PdState};
use osdp::reply::Reply;
use osdp::transport::VecTransport;
let mut acu = Acu::new(VecTransport::new(), SystemClock::new());
let mut pd = PdState::default();
match acu.exchange(0x05, &mut pd, &Command::Poll(Poll))? {
ExchangeOutcome::Reply(Reply::Ack(_)) => { /* PD alive */ }
ExchangeOutcome::Busy => { /* PD asked us to back off */ }
ExchangeOutcome::Timeout => { /* no reply within budget */ }
ExchangeOutcome::Offline => { /* PD declared offline */ }
_ => {}
}For the secure-channel walk see examples/handshake.rs; for an end-to-end
loopback that exercises SQN cycling see examples/loopback_poll.rs.
§Specification cross-references
All spec citations refer to SIA OSDP v2.2 (©2020 Security Industry
Association). Where an item maps directly onto a spec section it is noted
in the docs as # Spec: §X.Y.
Re-exports§
pub use error::Error;pub use error::Result;pub use packet::Address;pub use packet::ControlByte;pub use packet::ParsedPacket;pub use packet::Sqn;pub use packet::Trailer;pub use packet::Packet;alloc
Modules§
- architecture
- Crate architecture diagram.
- caps
- PD capability function codes.
- clock
- Time abstraction. Drivers take a
Clockso that timing logic is testable fromno_stdtargets without pulling in a runtime. - command
alloc - Typed OSDP commands (ACU → PD).
- driver
alloc - Higher-level drivers built atop the codec and transport.
- error
- Crate-wide error type.
core::error::Error-compatible. - multipart
alloc - Multi-part message engine.
- packet
- Packet codec — framing, header, security control block, MAC, trailer.
- reply
alloc - Typed OSDP replies (PD → ACU). See sibling
crate::command. - secure
allocandsecure-channel - Secure Channel — Annex D.
- transport
- Transport abstraction. The driver works against any half-duplex byte
stream that exposes
Transport::write_allandTransport::read.
Constants§
- BROADCAST_
ADDR - Broadcast address.
- MAX_
BUS_ PACKET - Maximum packet length that any device must tolerate on the wire (even if addressed elsewhere).
- MAX_
PD_ ADDR - Largest legal PD unicast address.
- MIN_
RX_ SIZE - Minimum receive-buffer size every PD must support.
- OFFLINE_
THRESHOLD_ MS - Off-line declaration threshold.
- REPLY_
DELAY_ MS - Default ACU reply-delay budget.
- REPLY_
FLAG - Reply flag set in
Addresswhen sent from PD to ACU. - SOM
- Start of message marker — begins every OSDP packet header.