Skip to main content

Crate bacnet_rs

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

ComponentStatusNotes
Encoding/DecodingWorkingASN.1 application and context tags, all primitive types
BACnet/IP (Annex J)WorkingBVLC, BBMD, Foreign Device registration
MS/TP (Clause 9)WorkingFrame encoding, CRC, token-passing
Ethernet (Clause 7)Working802.3 frames, LLC headers
Who-Is / I-AmWorkingDevice discovery
Read PropertyWorkingSingle property read
Read Property MultipleWorkingBatch property reads
Write PropertyWorkingSingle property write
Subscribe COVWorkingChange-of-value subscriptions
Atomic File Read/WriteWorkingStream and record access
Time SynchronizationWorkingStandard and UTC
Analog ObjectsWorkingInput, Output, Value with priority arrays
Binary ObjectsWorkingInput, Output, Value with priority arrays
Multistate ObjectsWorkingInput, Output, Value
File / Device ObjectsWorkingBasic property support
Client APIPartialDiscovery and read-only via BACnet/IP only
SegmentationNot implementedLarge message segmentation/reassembly
Alarm & EventNot implementedIntrinsic and algorithmic reporting
TrendingNot implementedTrend log objects
SchedulingNot implementedSchedule and calendar objects
BACnet/SC (Annex AB)Not implementedSecure Connect

§Quick Start

Add this to your Cargo.toml:

[dependencies]
bacnet-rs = "0.2"

§Feature Flags

  • std (default): Standard library support with networking capabilities
  • async (default): Async/await support with Tokio runtime
  • serde (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::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