A BACnet Error is the combination of an Error Class and an Error Code that explains why a service request or action could not be fulfilled. It is transmitted inside Error APDUs and also appears inside the result(-) parameter of many confirmed services (Read Property, Write Property, Create Object, etc.).
The standard defines a large but fixed set of error classes (object, property, resources, security, services, etc.) and, within each class, a set of codes. Vendors are permitted to extend the codes within the "proprietary" ranges. Because new codes are occasionally added in later revisions of the standard, robust implementations must be prepared to receive error codes they do not recognize and must not treat an unknown code as a protocol violation.
Proper interpretation of these values is essential for writing client code that can recover gracefully from the many different failure modes that can occur on a real building automation network.
Examples (Doc Test)
Basic error construction:
iex> error = %BACnetError{class: :property, code: :write_access_denied}
iex> error.class
:property
iex> error = %BACnetError{class: :services, code: 128}
iex> error.code
128CHOICE / Construction Gotchas
- Both
classandcodecan be atoms (from Constants) or raw integers for vendor extensions. - There is no runtime validation of the class+code pair in the struct itself (see the TODO in the module).
- When encoding, unknown integer codes are passed through.
iex> vendor_err = %BACnetError{class: 0, code: 999}
iex> BACnetError.valid?(vendor_err)
true
Summary
Functions
Encodes a BACnet error into BACnet application tags encoding.
Parses a BACnet error from BACnet application tags encoding.
Validates whether the given status flags is in form valid.
Types
@type t() :: %BACnet.Protocol.BACnetError{ class: BACnet.Protocol.Constants.error_class() | non_neg_integer(), code: BACnet.Protocol.Constants.error_code() | non_neg_integer() }
Represents a casual BACnet Error.
To allow forward compatibility, each field can be an integer.
Functions
@spec encode(t(), Keyword.t()) :: {:ok, BACnet.Protocol.ApplicationTags.encoding_list()} | {:error, term()}
Encodes a BACnet error into BACnet application tags encoding.
@spec parse(BACnet.Protocol.ApplicationTags.encoding_list()) :: {:ok, {t(), rest :: BACnet.Protocol.ApplicationTags.encoding_list()}} | {:error, term()}
Parses a BACnet error from BACnet application tags encoding.
Validates whether the given status flags is in form valid.
It only validates the struct is valid as per type specification.