Crate bacnet_rs

Source
Expand description

§BACnet-RS: A Complete BACnet Protocol Stack Implementation in Rust

BACnet-RS is a comprehensive implementation of the BACnet (Building Automation and Control Networks) protocol stack written in Rust. It provides a complete, standards-compliant BACnet implementation suitable for both embedded systems and full-featured applications.

§Features

  • Complete Protocol Stack: Full implementation of BACnet layers (Application, Network, Data Link)
  • Multiple Data Link Support: BACnet/IP, Ethernet, MS/TP, and more
  • Standards Compliant: Implements ASHRAE Standard 135-2020
  • No-std Compatible: Works in embedded environments without heap allocation
  • Async Support: Optional async/await support with Tokio integration
  • Comprehensive Services: Read/Write properties, Who-Is/I-Am, object discovery, and more
  • Debugging Tools: Built-in protocol analyzers and debug formatters
  • Performance Monitoring: Statistics collection and performance metrics

§Quick Start

use bacnet_rs::{client::BacnetClient, object::ObjectIdentifier, ObjectType};
 
// Create a BACnet client
let mut client = BacnetClient::new("0.0.0.0:47808").await?;
 
// Discover devices on the network
let devices = client.who_is_scan(std::time::Duration::from_secs(5)).await?;
println!("Found {} devices", devices.len());
 
// Read a property from a device
if let Some(device) = devices.first() {
    let object_id = ObjectIdentifier::new(ObjectType::Device, device.instance);
    let name = client.read_property_string(
        device.address.clone(),
        object_id,
        bacnet_rs::object::PropertyIdentifier::ObjectName
    ).await?;
    println!("Device name: {}", name);
}

§Architecture

The library is organized into several key modules:

  • datalink: Data link layer implementations (BACnet/IP, Ethernet, MS/TP)
  • network: Network layer for routing and addressing
  • transport: Transport layer with reliability and flow control
  • service: BACnet services (confirmed and unconfirmed)
  • object: BACnet object types and property handling
  • client: High-level client API for applications
  • util: Utilities for CRC, encoding, and debugging

BACnet-RS supports multiple data link layer protocols:

  • BACnet/IP: UDP-based communication over IP networks (most common)
  • BACnet/Ethernet: Direct Ethernet frame communication
  • MS/TP: Master-Slave Token Passing over RS-485 serial networks
  • Point-to-Point: Direct serial communication

§Examples

The crate includes comprehensive examples in the examples/ directory:

  • Basic Examples: Simple device creation and communication
  • Networking Examples: Who-Is scans, transport demonstrations
  • Object Examples: Device and object discovery, property reading
  • Debugging Examples: Protocol analysis and debug formatting

Run examples with:

cargo run --example whois_scan
cargo run --example device_objects

§Features

  • std (default): Enable standard library support
  • async (default): Enable async/await support with Tokio
  • serde (default): Enable serialization support
  • no-std: Disable standard library for embedded use

§License

Licensed under either of

at your option.

§BACnet-RS

A comprehensive BACnet (Building Automation and Control Networks) protocol stack implementation in Rust.

§Overview

This library provides a complete implementation of the BACnet protocol stack in Rust, designed as a modern alternative to the official C BACnet stack. It supports multiple data link layers, all standard BACnet services, and is suitable for both embedded and desktop applications.

§Features

  • Complete BACnet Implementation: All standard objects, services, and data types
  • Multiple Data Links: BACnet/IP, MS/TP, Ethernet support
  • No-std Compatible: Can run on embedded systems without standard library
  • Async Support: Optional async/await support for network operations
  • Type Safe: Leverages Rust’s type system to prevent protocol errors
  • High Performance: Zero-copy design with minimal allocations

§Quick Start

Add this to your Cargo.toml:

[dependencies]
bacnet-rs = "0.2"

§Architecture

The stack is organized into layered modules:

  • Encoding: BACnet data encoding/decoding
  • Datalink: Network transport implementations
  • Network: NPDU handling and routing
  • Service: BACnet service implementations
  • Object: Standard BACnet object types
  • Application: High-level API

§License

Licensed under either of

  • Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  • MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

at your option.

Re-exports§

pub use datalink::DataLinkAddress;
pub use datalink::DataLinkType;
pub use encoding::ApplicationTag;
pub use encoding::EncodingError;
pub use object::BacnetObject;
pub use object::ObjectType;
pub use object::PropertyIdentifier;
pub use service::ConfirmedServiceChoice;
pub use service::ServiceError;
pub use service::UnconfirmedServiceChoice;
pub use vendor::VendorInfo;
pub use vendor::get_vendor_name;
pub use vendor::get_vendor_info;
pub use vendor::format_vendor_display;

Modules§

app
Application layer protocol services and message handling BACnet Application Layer Module
client
High-level client API for BACnet communication (requires std feature) BACnet Client Utilities
datalink
Data link layer implementations for various BACnet physical networks BACnet Data Link Layer Module
encoding
BACnet encoding and decoding utilities for application tags and values BACnet Encoding and Decoding Utilities
network
Network layer for BACnet routing, addressing, and message forwarding BACnet Network Layer Module
object
BACnet object definitions, properties, and type system BACnet Object Types and Property Management
property
Property value decoders for various BACnet data types BACnet Property Value Decoders
service
BACnet service definitions for confirmed and unconfirmed operations BACnet Application Layer Services
transport
Transport layer providing reliability, segmentation, and flow control BACnet Transport Layer Module
util
Utility functions for CRC calculations, debugging, and performance monitoring BACnet Utility Functions and Debugging Tools
vendor
BACnet vendor identification and device information BACnet Vendor ID Lookup Module

Constants§

BACNET_MAX_APDU
Maximum Application Protocol Data Unit size in bytes This is the largest APDU that can be transmitted in a single BACnet message
BACNET_MAX_MPDU
Maximum Message Protocol Data Unit size in bytes
This includes the NPDU header and APDU payload
BACNET_PROTOCOL_VERSION
BACnet protocol version as defined in ASHRAE 135