bacnet-bip-core
Portable BACnet/IP behaviour from Annex J of ASHRAE 135, for
rusty-bacnet. It sits above
bacnet-bip-codec, which has the wire format, and below a socket.
#![no_std], no allocator, no dependencies besidesbacnet-bip-codecandbacnet-time. The codec is re-exported asbacnet_bip_core::codec, since the API speaks its types.- Tables live in arrays whose size you pick with a const generic.
- Time is an
Instantyou pass to each call; the crate reads no clock. It isbacnet-time's, in nanoseconds, re-exported here, the same typebacnet-mstp-coreandbacnet-router-coretake, so firmware feeds them one clock. Anowearlier than the latest one passed in is taken as that latest one: time never runs backwards, so a clock that steps back holds the timers still instead of failing. - The types that may grow are
#[non_exhaustive]: build aDatagram, abbmd::Context, aLocalSubnetor abbmd::Registrationwithnew; start aLinkor aForeignfromnew, or theRegistrationLimitsfromDEFAULT, and set the fields to change; and give amatchon an error, a refusal, aDiscardor another of these enums a wildcard arm.
What it has
The node module is a sans-IO B/IP node in normal, foreign-device and BBMD
mode:
Link, its fixed configuration, decides what to do with each received datagram (the receive rules, own echoes, the NAKs a node that is not a BBMD owes, a Forwarded-NPDU's origin) and what to send for an NPDU, within a datagram budget. Its decisions are pure.Nodekeeps the rest: its own management exchanges, matched by peer and operation; a foreign device's registration, with backoff after a loss and a lease that never counts on the BBMD's grace period; broadcasts held until the first registration resolves; and the timers. You poll its actions after every call.
The bbmd module holds a BBMD's broadcast distribution table and foreign
device table, and decides where each broadcast goes:
- an Original-Broadcast-NPDU from the local subnet, to the peer subnets (one-hop or two-hop, from each BDT row's mask) and the foreign devices;
- a peer BBMD's Forwarded-NPDU, to the foreign devices and, when it came to this BBMD alone (its own BDT row is two-hop and it arrived by unicast), the local subnet;
- a registered foreign device's Distribute-Broadcast-To-Network;
- the BBMD's own broadcasts.
Each decision writes its destinations into storage you pass and returns the Forwarded-NPDU to send them. Foreign-device registration applies time-to-live limits, a per-address quota and reserved capacity, and asks your own admission check (an access list, a rate limit) in between. Registrations expire on your clock, with the 30-second grace period.
The Tokio B/IP transport in bacnet-transport runs its node and its BBMD on
this crate.
Example
use ;
use ;
use ;
use Instant;
let own = new;
let peer = new;
let mut tables: = new;
tables
.bdt
.set
.unwrap;
let cx = new;
let source = new;
let mut out = ;
let sent = tables.original_broadcast;
for in sent.transmissions
License
MIT