BACnet.Stack.EncoderProtocol protocol (bacstack v0.0.1)

View Source

This protocol is used inside the BACnet stack (transport modules) to encode APDU structs into binary BACnet APDUs, which then are sent through the transport layer.

Summary

Types

t()

All the types that implement this protocol.

Functions

Encodes the struct into a BACnet APDU binary packet.

Same as encode/1, but respects the APDU maximum size.

Whether the struct expects a reply (i.e. Confirmed Service Request).

Whether the struct is a request.

Whether the struct is a response.

Whether the struct can be segmented (supported by the BACnet protocol).

Types

t()

@type t() :: term()

All the types that implement this protocol.

Functions

encode(apdu)

@spec encode(t()) :: iodata()

Encodes the struct into a BACnet APDU binary packet.

Any information that is additionally required by the transport layer, must be added by the transport layer.

Any segmentation that needs to be applied, can not and will not be respected by this function.

encode_segmented(apdu, apdu_size)

@spec encode_segmented(t(), integer()) :: [iodata()]

Same as encode/1, but respects the APDU maximum size.

It will output a list of segmented binaries, that can be sent ordered to the transport layer. Rules around segmentation (such as Segment ACK) still apply for the transport layer.

Conventionally, this function simply takes the encoded body and splits it apart into individual segments and adds the header.

expects_reply(apdu)

@spec expects_reply(t()) :: boolean()

Whether the struct expects a reply (i.e. Confirmed Service Request).

This is useful for NPCI calculation.

is_request(apdu)

@spec is_request(t()) :: boolean()

Whether the struct is a request.

is_response(apdu)

@spec is_response(t()) :: boolean()

Whether the struct is a response.

supports_segmentation(apdu)

@spec supports_segmentation(t()) :: boolean()

Whether the struct can be segmented (supported by the BACnet protocol).