Expand description
The BACnet network-layer vocabulary (Clause 6), in one place, for every layer of rusty-bacnet and for firmware.
The crate is no_std, needs no allocator and has no dependencies. It
holds what the portable cores, the hosted transports and network layer,
and the owned codec of bacnet-encoding all speak, so each concept has
one definition:
Npdu: a borrowed view of an NPDU’s control information and its payload.Npdu::decodereads one in place, telling an address too long for any data link (DecodeError::AddressTooLong) apart from every other fault (Malformed);Npdu::encoded_lenandNpdu::encode_intowrite one into the caller’s buffer, refusing anything the decoder would refuse before writing an octet.NetworkMessageTypeandRejectMessageReason: the open sets of wire codes for network-layer messages and their reject reasons.RejectMessageToNetwork: a reject’s data, its reason and network, read and written in place, refused withRejectLengthErrorwhen it isn’t three octets.NetworkPriority: the closed, two-bit network priority.NpduLimits: the longest NPDU a link carries each way, andMAX_NPDU, the longest any data link here carries.Mac: a link-layer address of up toMAX_MAC_LENoctets, stored inline.
The other network-layer messages’ payloads, the routing table and the
router itself are bacnet-router-core’s.
§Example
use bacnet_npdu::{Address, Npdu, NetworkPriority};
// A confirmed request for station 5 on network 2, at urgent priority.
let mut request = Npdu::apdu(&[0x00, 0x05, 0x01, 0x0C]);
request.destination = Some(Address { network: 2, mac: &[5] });
request.expecting_reply = true;
request.priority = NetworkPriority::Urgent;
let mut frame = [0u8; 32];
let len = request.encode_into(&mut frame)?;
assert_eq!(len, request.encoded_len());
assert_eq!(&frame[..len], &[0x01, 0x25, 0x00, 0x02, 0x01, 0x05, 0xFF, 0x00, 0x05, 0x01, 0x0C]);
let decoded = Npdu::decode(&frame[..len]).expect("an NPDU");
assert_eq!(decoded.destination, request.destination);
assert_eq!(decoded.priority, NetworkPriority::Urgent);
assert_eq!(decoded.payload, request.payload);Structs§
- Address
- A network and a MAC on it: a DNET and DADR, or an SNET and SADR.
- Mac
- A link-layer address of up to
MAX_MAC_LENoctets, stored inline, so a route or a pending reply holds one without an allocator. - MacToo
Long - A MAC longer than
MAX_MAC_LENoctets was offered toMac. - Network
Message Type - A network-layer message type: the octet after an NPDU’s addresses that says which message it carries (Clause 6.2.4).
- Npdu
- An NPDU’s control information, with its payload, borrowed from a frame.
- Npdu
Limits - The longest NPDU a link carries, in octets, to one node and to every node on it (Table 6-1).
- Priority
Error - A value
NetworkPriority::try_fromrefuses: a network priority is two bits, 0 to 3. - Reject
Length Error - A Reject-Message-To-Network’s data isn’t
RejectMessageToNetwork::LENoctets: it ends inside the network, or goes on past it. - Reject
Message Reason - The reason a Reject-Message-To-Network gives (Clause 6.4.4).
- Reject
Message ToNetwork - What a Reject-Message-To-Network carries after its type (Clause 6.4.4): one reason octet, then the two-octet network the refused message was for.
Enums§
- Address
Field - Which address a
DecodeError::AddressTooLongconcerns. - Decode
Error - Why
Npdu::decoderefused a frame. - Encode
Error - Why
Npdu::encode_intorefused an NPDU. Nothing was written. - Malformed
- What made a frame malformed.
- Network
Priority - An NPDU’s network priority (Clause 6.2.2): the control octet’s two low bits, in increasing order of urgency.
Constants§
- GLOBAL_
NETWORK - The DNET of a global broadcast.
- MAX_
MAC_ LEN - The longest DADR, SADR or link MAC the stack accepts, in octets (#1141).
- MAX_
NPDU - The longest NPDU, in octets, that B/IP, B/IPv6, Ethernet and MS/TP with extended frames carry (Table 6-1; Clause 9.3 for MS/TP).
- VERSION
- The protocol version every NPDU starts with.