Skip to content

File syn_bacnet.h

FileList > proto > syn_bacnet.h

Go to the source code of this file

Zero-malloc, cleanroom BACnet MS/TP & APDU protocol stack (ISO 16484-5). More...

  • #include "../common/syn_defs.h"
  • #include <stdbool.h>
  • #include <stddef.h>
  • #include <stdint.h>

Classes

Type Name
struct SYN_BACnet_MSTP_Frame
Decoded BACnet MS/TP Frame Structure.
struct SYN_BACnet_Node
BACnet MS/TP Node Context.
struct SYN_BACnet_Object
BACnet Object Instance Definition.

Public Types

Type Name
enum SYN_BACnet_MSTP_FrameType
BACnet MS/TP Frame Types (ISO 16484-5 Clause 9.2)
enum SYN_BACnet_ObjectType
BACnet Object Types (Clause 12)
enum SYN_BACnet_PropertyID
BACnet Property Identifiers.
enum SYN_BACnet_ServiceChoice
BACnet Service Choices (Clause 21)

Public Functions

Type Name
SYN_Status syn_bacnet_add_object (SYN_BACnet_Node * node, uint8_t object_type, uint32_t instance_id, float init_value, const char * name)
Register an Object in the BACnet Node database.
uint16_t syn_bacnet_crc16 (const uint8_t * data, size_t len)
Calculate BACnet MS/TP Data CRC-16.
uint8_t syn_bacnet_crc8 (const uint8_t * data, size_t len)
Calculate BACnet MS/TP Header CRC-8.
bool syn_bacnet_mstp_decode_frame (const uint8_t * buf, size_t len, SYN_BACnet_MSTP_Frame * frame)
Decode a raw byte buffer into a BACnet MS/TP Frame structure.
size_t syn_bacnet_mstp_encode_frame (uint8_t frame_type, uint8_t dest_mac, uint8_t src_mac, const uint8_t * payload, uint16_t payload_len, uint8_t * out_buf)
Encode a complete BACnet MS/TP Frame.
SYN_Status syn_bacnet_node_init (SYN_BACnet_Node * node, uint8_t mac_address, uint32_t device_id)
Initialize a BACnet MS/TP Node context.
SYN_Status syn_bacnet_node_process (SYN_BACnet_Node * node, const SYN_BACnet_MSTP_Frame * rx_frame, SYN_BACnet_MSTP_Frame * tx_frame, bool * has_tx)
Process an incoming BACnet MS/TP frame and generate a response if required.

Macros

Type Name
define SYN_BACNET_BROADCAST_MAC 0xFFU
define SYN_BACNET_MAX_OBJECTS 16
define SYN_BACNET_MSTP_PREAMBLE_1 0x55U
define SYN_BACNET_MSTP_PREAMBLE_2 0xFFU

Detailed Description

Provides a lightweight, non-blocking BACnet MS/TP (Master-Slave/Token-Passing) frame encoder/decoder, CRC-8 / CRC-16 verifiers, APDU parser (Who-Is, I-Am, ReadProperty, WriteProperty), and static Object Database engine for embedded targets.

Public Types Documentation

enum SYN_BACnet_MSTP_FrameType

BACnet MS/TP Frame Types (ISO 16484-5 Clause 9.2)

enum SYN_BACnet_MSTP_FrameType {
    SYN_BACNET_MSTP_FRAME_TOKEN = 0x00U,
    SYN_BACNET_MSTP_FRAME_POLL_FOR_MASTER = 0x01U,
    SYN_BACNET_MSTP_FRAME_REPLY_TO_POLL_FOR_MASTER = 0x02U,
    SYN_BACNET_MSTP_FRAME_TEST_REQUEST = 0x03U,
    SYN_BACNET_MSTP_FRAME_TEST_RESPONSE = 0x04U,
    SYN_BACNET_MSTP_FRAME_DATA_NOT_EXPECTING_REPLY = 0x05U,
    SYN_BACNET_MSTP_FRAME_DATA_EXPECTING_REPLY = 0x06U,
    SYN_BACNET_MSTP_FRAME_REPLY_POSTPONED = 0x07U
};


enum SYN_BACnet_ObjectType

BACnet Object Types (Clause 12)

enum SYN_BACnet_ObjectType {
    SYN_BACNET_OBJ_ANALOG_INPUT = 0U,
    SYN_BACNET_OBJ_ANALOG_OUTPUT = 1U,
    SYN_BACNET_OBJ_BINARY_INPUT = 3U,
    SYN_BACNET_OBJ_BINARY_OUTPUT = 4U,
    SYN_BACNET_OBJ_DEVICE = 8U
};


enum SYN_BACnet_PropertyID

BACnet Property Identifiers.

enum SYN_BACnet_PropertyID {
    SYN_BACNET_PROP_PRESENT_VALUE = 85U,
    SYN_BACNET_PROP_STATUS_FLAGS = 111U,
    SYN_BACNET_PROP_OBJECT_IDENTIFIER = 75U,
    SYN_BACNET_PROP_OBJECT_NAME = 77U,
    SYN_BACNET_PROP_OBJECT_TYPE = 79U,
    SYN_BACNET_PROP_VENDOR_ID = 121U
};


enum SYN_BACnet_ServiceChoice

BACnet Service Choices (Clause 21)

enum SYN_BACnet_ServiceChoice {
    SYN_BACNET_SERVICE_UNCONFIRMED_I_AM = 0U,
    SYN_BACNET_SERVICE_UNCONFIRMED_WHO_IS = 8U,
    SYN_BACNET_SERVICE_CONFIRMED_READ_PROPERTY = 12U,
    SYN_BACNET_SERVICE_CONFIRMED_WRITE_PROPERTY = 15U
};


Public Functions Documentation

function syn_bacnet_add_object

Register an Object in the BACnet Node database.

SYN_Status syn_bacnet_add_object (
    SYN_BACnet_Node * node,
    uint8_t object_type,
    uint32_t instance_id,
    float init_value,
    const char * name
) 

Parameters:

  • node Node handle.
  • object_type SYN_BACnet_ObjectType (AI, AO, BI, BO).
  • instance_id Instance ID.
  • init_value Initial Present Value.
  • name Object Name string.

Returns:

SYN_OK on success, SYN_ERROR if database full.


function syn_bacnet_crc16

Calculate BACnet MS/TP Data CRC-16.

uint16_t syn_bacnet_crc16 (
    const uint8_t * data,
    size_t len
) 

Parameters:

  • data Data buffer.
  • len Byte count.

Returns:

CRC-16 checksum value.


function syn_bacnet_crc8

Calculate BACnet MS/TP Header CRC-8.

uint8_t syn_bacnet_crc8 (
    const uint8_t * data,
    size_t len
) 

Parameters:

  • data Data buffer.
  • len Byte count.

Returns:

CRC-8 checksum value.


function syn_bacnet_mstp_decode_frame

Decode a raw byte buffer into a BACnet MS/TP Frame structure.

bool syn_bacnet_mstp_decode_frame (
    const uint8_t * buf,
    size_t len,
    SYN_BACnet_MSTP_Frame * frame
) 

Parameters:

  • buf Input raw frame byte array.
  • len Input byte count.
  • frame [out] Decoded MS/TP Frame structure.

Returns:

true if valid MS/TP frame header and CRC-8/CRC-16 match.


function syn_bacnet_mstp_encode_frame

Encode a complete BACnet MS/TP Frame.

size_t syn_bacnet_mstp_encode_frame (
    uint8_t frame_type,
    uint8_t dest_mac,
    uint8_t src_mac,
    const uint8_t * payload,
    uint16_t payload_len,
    uint8_t * out_buf
) 

Parameters:

  • frame_type Frame Type enum.
  • dest_mac Destination MAC address.
  • src_mac Source MAC address.
  • payload Payload buffer (can be NULL if payload_len == 0).
  • payload_len Payload byte count.
  • out_buf Destination output buffer (must be >= payload_len + 10 bytes).

Returns:

Total encoded frame byte count.


function syn_bacnet_node_init

Initialize a BACnet MS/TP Node context.

SYN_Status syn_bacnet_node_init (
    SYN_BACnet_Node * node,
    uint8_t mac_address,
    uint32_t device_id
) 

Parameters:

  • node Node handle.
  • mac_address Local MAC address (0..127).
  • device_id BACnet Device Instance ID (0..4194302).

Returns:

SYN_OK on success.


function syn_bacnet_node_process

Process an incoming BACnet MS/TP frame and generate a response if required.

SYN_Status syn_bacnet_node_process (
    SYN_BACnet_Node * node,
    const SYN_BACnet_MSTP_Frame * rx_frame,
    SYN_BACnet_MSTP_Frame * tx_frame,
    bool * has_tx
) 

Parameters:

  • node Node context.
  • rx_frame Incoming received frame.
  • tx_frame [out] Outgoing response frame structure.
  • has_tx [out] Set to true if a response frame must be transmitted.

Returns:

SYN_OK on success.


Macro Definition Documentation

define SYN_BACNET_BROADCAST_MAC

#define SYN_BACNET_BROADCAST_MAC `0xFFU`

Broadcast MAC address (0xFF)


define SYN_BACNET_MAX_OBJECTS

#define SYN_BACNET_MAX_OBJECTS `16`

Maximum supported BACnet objects per node instance


define SYN_BACNET_MSTP_PREAMBLE_1

#define SYN_BACNET_MSTP_PREAMBLE_1 `0x55U`

First MS/TP preamble byte (0x55)


define SYN_BACNET_MSTP_PREAMBLE_2

#define SYN_BACNET_MSTP_PREAMBLE_2 `0xFFU`

Second MS/TP preamble byte (0xFF)



The documentation for this class was generated from the following file src/syntropic/proto/syn_bacnet.h