A Log Record is the basic unit stored inside the buffer of a Trend Log or Event Log object. Every time a trend log collects a sample, or an event log records an event notification, a Log Record is appended to the circular buffer.
Each record carries a timestamp (which may be a full BACnet DateTime or a sequence number), a status field of the object, and then one of several possible value choices: a normal data value, a time change indication, a BACnet Error, or a special "log status" record.
Examples (Doc Test)
Basic real value record:
iex> record = %LogRecord{
...> timestamp: %BACnet.Protocol.BACnetTimestamp{type: :datetime, time: nil, sequence_number: nil, datetime: %BACnet.Protocol.BACnetDateTime{date: %BACnet.Protocol.BACnetDate{year: 2025, month: 1, day: 1, weekday: 3}, time: %BACnet.Protocol.BACnetTime{hour: 12, minute: 0, second: 0, hundredth: 0}}},
...> status_flags: %BACnet.Protocol.StatusFlags{in_alarm: false, fault: false, overridden: false, out_of_service: false},
...> log_datum: {:real, 23.4}
...> }
iex> record.log_datum
{:real, 23.4}Different log_datum CHOICE arms
# Log status record (buffer purged, etc.)
iex> status_rec = %LogRecord{
...> timestamp: %BACnet.Protocol.BACnetTimestamp{type: :sequence_number, sequence_number: 42, time: nil, datetime: nil},
...> status_flags: nil,
...> log_datum: %LogStatus{log_disabled: false, buffer_purged: true, log_interrupted: false}
...> }
iex> status_rec.log_datum.log_disabled
false
# Error record
iex> %LogRecord{
...> timestamp: %BACnet.Protocol.BACnetTimestamp{type: :datetime, time: nil, sequence_number: nil, datetime: %BACnet.Protocol.BACnetDateTime{date: %BACnet.Protocol.BACnetDate{year: 2025, month: 1, day: 1, weekday: 3}, time: %BACnet.Protocol.BACnetTime{hour: 0, minute: 0, second: 0, hundredth: 0}}},
...> status_flags: nil,
...> log_datum: %BACnet.Protocol.BACnetError{class: :services, code: :timeout}
...> }
# Time change indication
iex> %LogRecord{
...> timestamp: %BACnet.Protocol.BACnetTimestamp{type: :sequence_number, sequence_number: 100, time: nil, datetime: nil},
...> status_flags: nil,
...> log_datum: {:time_change, 3600.0}
...> }Note: Different arms are encoded with different context tags (0 for LogStatus, 8 for Error, 9 for time change, etc.). The higher-level encode/2 handles the tagging.
Summary
Functions
Encode a BACnet log record into application tag-encoded.
Parse a BACnet log record from application tags encoding.
Validates whether the given log record is in form valid.
Types
@type t() :: %BACnet.Protocol.LogRecord{ log_datum: BACnet.Protocol.LogStatus.t() | BACnet.Protocol.ApplicationTags.Encoding.t() | BACnet.Protocol.BACnetError.t() | {:time_change, float()} | nil, status_flags: BACnet.Protocol.StatusFlags.t() | nil, timestamp: BACnet.Protocol.BACnetDateTime.t() }
A single record in a Trend Log or Event Log.
Functions
@spec encode(t(), Keyword.t()) :: {:ok, BACnet.Protocol.ApplicationTags.encoding_list()} | {:error, term()}
Encode a BACnet log record into application tag-encoded.
@spec parse(BACnet.Protocol.ApplicationTags.encoding_list()) :: {:ok, {t(), rest :: BACnet.Protocol.ApplicationTags.encoding_list()}} | {:error, term()}
Parse a BACnet log record from application tags encoding.
Validates whether the given log record is in form valid.
It only validates the struct is valid as per type specification.