BACnet.Protocol.PropertyState (bacstack v0.1.0-dev.1)

Copy Markdown View Source

Property State is a large CHOICE used to carry the value of almost any property in event and fault algorithms (Change-of-State, Command-Failure, various fault detectors, etc.).

It exists because the event algorithms need a single, self-describing type that can hold any of the datatypes that standard properties can have.

BACnet Specification References

  • ASN.1 (Clause 21): BACnetPropertyStates ::= CHOICE { ... } (very large production with ~20+ arms).
  • Used inside BACnetEventParameter (Change of State, etc.) and several BACnetFaultParameter productions.
  • The outer tag makes the choice unambiguous even when the inner value is context-tagged or a primitive that would otherwise be ambiguous.

Examples (Doc Test)

Basic construction for common arms:

iex> state = %PropertyState{type: :boolean_value, value: true}
iex> state.type
:boolean_value
iex> state = %PropertyState{type: :event_type, value: :change_of_value}
iex> state.value
:change_of_value

CHOICE Gotchas

  • You must use the exact atom from Constants.property_state/0 as the type.
  • The value must match what that arm expects (the module validates this in valid?/1).
  • Many arms accept either atoms (from Constants) or raw integers for vendor extensions.
iex> state = %PropertyState{type: :reliability, value: :no_sensor}
iex> PropertyState.valid?(state)
true
iex> vendor = %PropertyState{type: :unsigned_value, value: 999}
iex> PropertyState.valid?(vendor)
true

When used inside event/fault parameters, this is usually wrapped in a tagged/constructed form by the higher-level encoder.

See Also

Summary

Types

t()

Represents a BACnet property state.

Represents the value type for property states.

Functions

Encodes a BACnet property state into application tags encoding.

Parses a BACnet property state from application tags encoding.

Validates whether the given property state is in form valid.

Types

t()

@type t() :: %BACnet.Protocol.PropertyState{
  type: BACnet.Protocol.Constants.property_state(),
  value: value()
}

Represents a BACnet property state.

value()

@type value() ::
  (boolean_value :: boolean())
  | (binary_value :: boolean())
  | (event_type :: BACnet.Protocol.Constants.event_type())
  | (polarity :: BACnet.Protocol.Constants.polarity())
  | (program_change :: BACnet.Protocol.Constants.program_request())
  | (program_state :: BACnet.Protocol.Constants.program_state())
  | (reason_for_halt :: BACnet.Protocol.Constants.program_error())
  | (reliability :: BACnet.Protocol.Constants.reliability())
  | (state :: BACnet.Protocol.Constants.event_state())
  | (system_status :: BACnet.Protocol.Constants.device_status())
  | (units :: BACnet.Protocol.Constants.engineering_unit())
  | (unsigned_value :: non_neg_integer())
  | (life_safety_mode :: BACnet.Protocol.Constants.life_safety_mode())
  | (life_safety_state :: BACnet.Protocol.Constants.life_safety_state())
  | (restart_reason :: BACnet.Protocol.Constants.restart_reason())
  | (door_alarm_state :: BACnet.Protocol.Constants.door_alarm_state())
  | (action :: BACnet.Protocol.Constants.action())
  | (door_secured_status :: BACnet.Protocol.Constants.door_secured_status())
  | (door_status :: BACnet.Protocol.Constants.door_status())
  | (door_value :: BACnet.Protocol.Constants.door_value())
  | (file_access_method :: BACnet.Protocol.Constants.file_access_method())
  | (lock_status :: BACnet.Protocol.Constants.lock_status())
  | (life_safety_operation :: BACnet.Protocol.Constants.life_safety_operation())
  | (maintenance :: BACnet.Protocol.Constants.maintenance())
  | (node_type :: BACnet.Protocol.Constants.node_type())
  | (notify_type :: BACnet.Protocol.Constants.notify_type())
  | (security_level :: BACnet.Protocol.Constants.security_level())
  | (shed_state :: BACnet.Protocol.Constants.shed_state())
  | (silenced_state :: BACnet.Protocol.Constants.silenced_state())
  | (backup_state :: BACnet.Protocol.Constants.backup_state())
  | (write_status :: BACnet.Protocol.Constants.write_status())
  | (lighting_in_progress :: BACnet.Protocol.Constants.lighting_in_progress())
  | (lighting_operation :: BACnet.Protocol.Constants.lighting_operation())
  | (lighting_transition :: BACnet.Protocol.Constants.lighting_transition())
  | (integer_value :: integer())

Represents the value type for property states.

The name for each value type represents the property state type (t:Constants.property_state/0).

Functions

encode(state, opts \\ [])

@spec encode(t(), Keyword.t()) ::
  {:ok, BACnet.Protocol.ApplicationTags.encoding_list()} | {:error, term()}

Encodes a BACnet property state into application tags encoding.

parse(tags)

Parses a BACnet property state from application tags encoding.

valid?(t)

@spec valid?(t()) :: boolean()

Validates whether the given property state is in form valid.

It only validates the struct is valid as per type specification.