Skip to main content

NetworkLayer

Struct NetworkLayer 

Source
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>

Source

pub fn new(transport: T) -> Self

Create a new network layer wrapping the given transport.

Source

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.

Source

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.

Source

pub async fn broadcast_apdu( &self, apdu: &[u8], expecting_reply: bool, priority: NetworkPriority, ) -> Result<(), Error>

Broadcast an APDU on the local network.

Source

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.

Source

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).

Source

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.

Source

pub fn transport(&self) -> &T

Access the underlying transport.

Useful for transport-specific operations like BBMD registration after the network layer has been started.

Source

pub fn local_mac(&self) -> &[u8]

Get the transport’s local MAC address.

Source

pub async fn stop(&mut self) -> Result<(), Error>

Stop the network layer and underlying transport.

Auto Trait Implementations§

§

impl<T> Freeze for NetworkLayer<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for NetworkLayer<T>
where T: RefUnwindSafe,

§

impl<T> Send for NetworkLayer<T>

§

impl<T> Sync for NetworkLayer<T>

§

impl<T> Unpin for NetworkLayer<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for NetworkLayer<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for NetworkLayer<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more