pub struct NetworkLayer<T: TransportPort> { /* private fields */ }Expand description
Non-router BACnet network layer.
Wraps a TransportPort and provides APDU-level send/receive by handling
NPDU framing. This layer does not act as a router (it does not forward
messages between networks), but it can send to remote devices through
local routers using NPDU destination addressing.
Implementations§
Source§impl<T: TransportPort + 'static> NetworkLayer<T>
impl<T: TransportPort + 'static> NetworkLayer<T>
Sourcepub fn enable_network_control_receiver(
&mut self,
) -> Result<Receiver<ReceivedNetworkControl>, Error>
pub fn enable_network_control_receiver( &mut self, ) -> Result<Receiver<ReceivedNetworkControl>, Error>
Enable the one-consumer decoded network-control stream.
This must be called before Self::start and at most once. Dropping
the returned receiver disables control delivery without affecting APDU
ingress.
Sourcepub async fn start(&mut self) -> Result<Receiver<ReceivedApdu>, Error>
pub async fn start(&mut self) -> Result<Receiver<ReceivedApdu>, Error>
Start the network layer. Returns a receiver for incoming APDUs.
This starts the underlying transport and spawns a dispatch task that decodes incoming NPDUs and extracts APDUs.
Sourcepub async fn send_apdu(
&self,
apdu: &[u8],
destination_mac: &[u8],
expecting_reply: bool,
priority: NetworkPriority,
) -> Result<(), Error>
pub async fn send_apdu( &self, apdu: &[u8], destination_mac: &[u8], expecting_reply: bool, priority: NetworkPriority, ) -> Result<(), Error>
Send an APDU to a specific local destination by MAC address.
Sourcepub async fn send_apdu_with_data_attributes(
&self,
apdu: &[u8],
destination_mac: &[u8],
expecting_reply: bool,
priority: NetworkPriority,
data_attributes: &[DataAttribute],
) -> Result<(), Error>
pub async fn send_apdu_with_data_attributes( &self, apdu: &[u8], destination_mac: &[u8], expecting_reply: bool, priority: NetworkPriority, data_attributes: &[DataAttribute], ) -> Result<(), Error>
Send an APDU with data attributes to a specific local destination.
Sourcepub async fn broadcast_apdu(
&self,
apdu: &[u8],
expecting_reply: bool,
priority: NetworkPriority,
) -> Result<(), Error>
pub async fn broadcast_apdu( &self, apdu: &[u8], expecting_reply: bool, priority: NetworkPriority, ) -> Result<(), Error>
Broadcast an APDU on the local network.
Sourcepub async fn broadcast_apdu_with_data_attributes(
&self,
apdu: &[u8],
expecting_reply: bool,
priority: NetworkPriority,
data_attributes: &[DataAttribute],
) -> Result<(), Error>
pub async fn broadcast_apdu_with_data_attributes( &self, apdu: &[u8], expecting_reply: bool, priority: NetworkPriority, data_attributes: &[DataAttribute], ) -> Result<(), Error>
Broadcast an APDU with data attributes on the local network.
Sourcepub async fn broadcast_global_apdu(
&self,
apdu: &[u8],
expecting_reply: bool,
priority: NetworkPriority,
) -> Result<(), Error>
pub async fn broadcast_global_apdu( &self, apdu: &[u8], expecting_reply: bool, priority: NetworkPriority, ) -> Result<(), Error>
Broadcast an APDU globally (DNET=0xFFFF, hop_count=255).
Unlike broadcast_apdu() which only reaches the local subnet, this
sets DNET=0xFFFF so routers will forward to all reachable networks.
Sourcepub async fn broadcast_global_apdu_with_data_attributes(
&self,
apdu: &[u8],
expecting_reply: bool,
priority: NetworkPriority,
data_attributes: &[DataAttribute],
) -> Result<(), Error>
pub async fn broadcast_global_apdu_with_data_attributes( &self, apdu: &[u8], expecting_reply: bool, priority: NetworkPriority, data_attributes: &[DataAttribute], ) -> Result<(), Error>
Broadcast an APDU globally with data attributes (DNET=0xFFFF, hop_count=255).
Sourcepub async fn broadcast_to_network(
&self,
apdu: &[u8],
dest_network: u16,
expecting_reply: bool,
priority: NetworkPriority,
) -> Result<(), Error>
pub async fn broadcast_to_network( &self, apdu: &[u8], dest_network: u16, expecting_reply: bool, priority: NetworkPriority, ) -> Result<(), Error>
Broadcast an APDU to a specific remote network via routers.
Like broadcast_global_apdu() but targets a single network number
instead of all networks (DNET=0xFFFF).
Sourcepub async fn broadcast_to_network_with_data_attributes(
&self,
apdu: &[u8],
dest_network: u16,
expecting_reply: bool,
priority: NetworkPriority,
data_attributes: &[DataAttribute],
) -> Result<(), Error>
pub async fn broadcast_to_network_with_data_attributes( &self, apdu: &[u8], dest_network: u16, expecting_reply: bool, priority: NetworkPriority, data_attributes: &[DataAttribute], ) -> Result<(), Error>
Broadcast an APDU with data attributes to a specific remote network via routers.
Sourcepub async fn send_apdu_routed(
&self,
apdu: &[u8],
dest_network: u16,
dest_mac: &[u8],
router_mac: &[u8],
expecting_reply: bool,
priority: NetworkPriority,
) -> Result<(), Error>
pub async fn send_apdu_routed( &self, apdu: &[u8], dest_network: u16, dest_mac: &[u8], router_mac: &[u8], expecting_reply: bool, priority: NetworkPriority, ) -> Result<(), Error>
Send an APDU to a remote device through a local router.
The NPDU is sent via unicast to router_mac (the next-hop router on
the local network), but the NPDU header addresses the final destination
with dest_network / dest_mac.
Sourcepub async fn send_apdu_routed_with_data_attributes(
&self,
apdu: &[u8],
dest_network: u16,
dest_mac: &[u8],
router_mac: &[u8],
expecting_reply: bool,
priority: NetworkPriority,
data_attributes: &[DataAttribute],
) -> Result<(), Error>
pub async fn send_apdu_routed_with_data_attributes( &self, apdu: &[u8], dest_network: u16, dest_mac: &[u8], router_mac: &[u8], expecting_reply: bool, priority: NetworkPriority, data_attributes: &[DataAttribute], ) -> Result<(), Error>
Send an APDU with data attributes to a remote device through a local router.
Sourcepub async fn send_apdu_routed_via_local_broadcast(
&self,
apdu: &[u8],
dest_network: u16,
dest_mac: &[u8],
expecting_reply: bool,
priority: NetworkPriority,
) -> Result<(), Error>
pub async fn send_apdu_routed_via_local_broadcast( &self, apdu: &[u8], dest_network: u16, dest_mac: &[u8], expecting_reply: bool, priority: NetworkPriority, ) -> Result<(), Error>
Send a routed APDU with a broadcast link DA, for when the next-hop router’s MAC is unknown.
Clause 6.5.3: the data link DA “shall be the MAC address of the BACnet router corresponding to the DNET parameter or the appropriate broadcast DA if the address of the router is initially unknown”. The NPDU still addresses one device via DNET/DADR, which is why Clause 6.3’s broadcast restriction does not bite: “a MAC layer multicast or broadcast address may be used for other PDU types when the network layer address restricts the destination to a single device”.
Sourcepub async fn send_apdu_routed_via_local_broadcast_with_data_attributes(
&self,
apdu: &[u8],
dest_network: u16,
dest_mac: &[u8],
expecting_reply: bool,
priority: NetworkPriority,
data_attributes: &[DataAttribute],
) -> Result<(), Error>
pub async fn send_apdu_routed_via_local_broadcast_with_data_attributes( &self, apdu: &[u8], dest_network: u16, dest_mac: &[u8], expecting_reply: bool, priority: NetworkPriority, data_attributes: &[DataAttribute], ) -> Result<(), Error>
Send a routed APDU with data attributes and a broadcast link DA.
Sourcepub fn transport(&self) -> &T
pub fn transport(&self) -> &T
Access the underlying transport.
Useful for transport-specific operations like BBMD registration after the network layer has been started.
Sourcepub fn network_control_ingress_sequence(&self) -> u64
pub fn network_control_ingress_sequence(&self) -> u64
Sequence assigned to the most recently decoded network-control ingress.
The value is updated before the control is queued for its opt-in
consumer. At counter exhaustion it remains at u64::MAX, which makes
sequence-based consumers fail closed rather than accepting an alias.