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;
use std::net::{SocketAddr, IpAddr, Ipv4Addr};
fn example() -> Result<(), Box<dyn std::error::Error>> {
// Create a BACnet client
let client = BacnetClient::new()?;
// Discover a device at a specific address
let target_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(192, 168, 1, 100)), 47808);
let device = client.discover_device(target_addr)?;
println!("Found device: {}", device.vendor_name);
// Read object list from the device
let objects = client.read_object_list(target_addr, device.device_id)?;
println!("Device has {} objects", objects.len());
Ok(())
}§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 addressingtransport: Transport layer with reliability and flow controlservice: BACnet services (confirmed and unconfirmed)object: BACnet object types and property handlingclient: High-level client API for applicationsutil: Utilities for CRC, encoding, and debugging
§Data Link Types
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 supportasync(default): Enable async/await support with Tokioserde(default): Enable serialization supportno-std: Disable standard library for embedded use
§License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.
§BACnet-RS
A BACnet (Building Automation and Control Networks) protocol stack implementation in Rust.
Note: This library is under active development and not yet production-ready. APIs may change between releases. Contributions and feedback are welcome.
§Overview
This library provides an implementation of the BACnet protocol stack in Rust, targeting compliance with ANSI/ASHRAE Standard 135-2024. It supports multiple data link layers, core BACnet services, and is designed for both embedded and desktop applications.
§Implementation Status
| Component | Status | Notes |
|---|---|---|
| Encoding/Decoding | Working | ASN.1 application and context tags, all primitive types |
| BACnet/IP (Annex J) | Working | BVLC, BBMD, Foreign Device registration |
| MS/TP (Clause 9) | Working | Frame encoding, CRC, token-passing |
| Ethernet (Clause 7) | Working | 802.3 frames, LLC headers |
| Who-Is / I-Am | Working | Device discovery |
| Read Property | Working | Single property read |
| Read Property Multiple | Working | Batch property reads |
| Write Property | Working | Single property write |
| Subscribe COV | Working | Change-of-value subscriptions |
| Atomic File Read/Write | Working | Stream and record access |
| Time Synchronization | Working | Standard and UTC |
| Analog Objects | Working | Input, Output, Value with priority arrays |
| Binary Objects | Working | Input, Output, Value with priority arrays |
| Multistate Objects | Working | Input, Output, Value |
| File / Device Objects | Working | Basic property support |
| Client API | Partial | Discovery and read-only via BACnet/IP only |
| Segmentation | Not implemented | Large message segmentation/reassembly |
| Alarm & Event | Not implemented | Intrinsic and algorithmic reporting |
| Trending | Not implemented | Trend log objects |
| Scheduling | Not implemented | Schedule and calendar objects |
| BACnet/SC (Annex AB) | Not implemented | Secure Connect |
§Quick Start
Add this to your Cargo.toml:
[dependencies]
bacnet-rs = "0.2"§Feature Flags
std(default): Standard library support with networking capabilitiesasync(default): Async/await support with Tokio runtimeserde(default): Serialization support for BACnet types
To use without async support:
bacnet-rs = { version = "0.2", default-features = false, features = ["std"] }§Architecture
The stack is organized into layered modules:
- Encoding (
src/encoding/): BACnet data encoding/decoding, ASN.1 tag handling - Datalink (
src/datalink/): BACnet/IP, MS/TP, Ethernet implementations - Network (
src/network/): NPDU handling and routing - Service (
src/service/): BACnet service request/response implementations - Object (
src/object/): Standard BACnet object types and database - Application (
src/app/): APDU handling and segmentation - Client (
src/client.rs): High-level BACnet client API
§Contributing
Contributions are welcome. Please open an issue or pull request.
§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::DataLink;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::format_vendor_display;pub use vendor::get_vendor_info;pub use vendor::get_vendor_name;pub use vendor::VendorInfo;
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
Macros§
- generate_
custom_ enum - Generates a Rust enum with a custom range of values, including variants for named values, custom values within a specified range, and reserved values outside that range.
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