Skip to content

Commit 12fe9ca

Browse files
author
CI
committed
Sync to GitHub
1 parent 1282587 commit 12fe9ca

2 files changed

Lines changed: 63 additions & 18 deletions

File tree

lib/bacnet/protocol/objects_utility.ex

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,26 @@ defmodule BACnet.Protocol.ObjectsUtility do
6969
ObjectTypes.TrendLogMultiple
7070
]
7171

72-
types_spec =
73-
@types
74-
|> Enum.map(fn type ->
75-
quote do
76-
unquote(type).t()
77-
end
78-
end)
79-
|> Enum.sort(:desc)
80-
|> Enum.reduce(fn field, acc ->
81-
{:|, [], [field, acc]}
82-
end)
72+
@types_commandable [
73+
ObjectTypes.AnalogOutput,
74+
ObjectTypes.AnalogValue,
75+
ObjectTypes.BinaryOutput,
76+
ObjectTypes.BinaryValue,
77+
ObjectTypes.BitstringValue,
78+
ObjectTypes.CharacterStringValue,
79+
ObjectTypes.DatePatternValue,
80+
ObjectTypes.DateTimePatternValue,
81+
ObjectTypes.DateTimeValue,
82+
ObjectTypes.DateValue,
83+
ObjectTypes.IntegerValue,
84+
ObjectTypes.LargeAnalogValue,
85+
ObjectTypes.MultistateOutput,
86+
ObjectTypes.MultistateValue,
87+
ObjectTypes.OctetStringValue,
88+
ObjectTypes.PositiveIntegerValue,
89+
ObjectTypes.TimePatternValue,
90+
ObjectTypes.TimeValue
91+
]
8392

8493
defmacrop get_fa_str() do
8594
{fun, arity} = __CALLER__.function
@@ -93,7 +102,36 @@ defmodule BACnet.Protocol.ObjectsUtility do
93102
@typedoc """
94103
BACnet object types that this module works with.
95104
"""
96-
@type bacnet_object :: unquote(types_spec)
105+
@type bacnet_object ::
106+
unquote(
107+
@types
108+
|> Enum.map(fn type ->
109+
quote do
110+
unquote(type).t()
111+
end
112+
end)
113+
|> Enum.sort(:desc)
114+
|> Enum.reduce(fn field, acc ->
115+
{:|, [], [field, acc]}
116+
end)
117+
)
118+
119+
@typedoc """
120+
Commandable BACnet object types that this module works with.
121+
"""
122+
@type bacnet_object_commandable ::
123+
unquote(
124+
@types_commandable
125+
|> Enum.map(fn type ->
126+
quote do
127+
unquote(type).t()
128+
end
129+
end)
130+
|> Enum.sort(:desc)
131+
|> Enum.reduce(fn field, acc ->
132+
{:|, [], [field, acc]}
133+
end)
134+
)
97135

98136
@typedoc """
99137
Valid options for `cast_property_to_value/4`.
@@ -135,6 +173,15 @@ defmodule BACnet.Protocol.ObjectsUtility do
135173
defguard is_object(object)
136174
when is_struct(object) and :erlang.map_get(:__struct__, object) in @types
137175

176+
@doc """
177+
Checks whether the given struct is a supported BACnet object (see `t:bacnet_object/0`)
178+
and whether it is commandable (see `t:bacnet_object_commandable/0`).
179+
180+
Note: This guard is not widely used by this module itself, but may be useful for others.
181+
"""
182+
defguard is_object_commandable(object)
183+
when is_struct(object) and :erlang.map_get(:__struct__, object) in @types_commandable
184+
138185
@doc """
139186
Checks whether the given BACnet object has Intrinsic Reporting enabled.
140187
@@ -433,16 +480,16 @@ defmodule BACnet.Protocol.ObjectsUtility do
433480
This function also updates the present value.
434481
435482
This function calls to the object module directly, as such it enforces the `t:bacnet_object/0` contract,
436-
and additionally only objects with a priority array can be used.
483+
and additionally only objects with a priority array can be used (commandable objects).
437484
"""
438-
@spec set_priority(bacnet_object(), 1..16, term()) ::
439-
{:ok, bacnet_object()} | {:error, term()}
485+
@spec set_priority(bacnet_object_commandable(), 1..16, term()) ::
486+
{:ok, bacnet_object_commandable()} | {:error, term()}
440487
def set_priority(%{priority_array: nil} = _object, _priority, _value) do
441488
{:error, {:unknown_property, :priority_array}}
442489
end
443490

444491
def set_priority(%bac{priority_array: %PriorityArray{} = _pa} = object, priority, value)
445-
when is_object(object) do
492+
when is_object_commandable(object) do
446493
bac.set_priority(object, priority, value)
447494
end
448495

lib/bacnet/stack/transport/mstp_transport/receive_fsm.ex

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ if Code.ensure_loaded?(Circuits.UART) do
66
# and as such receives transport data directly.
77

88
alias __MODULE__.StateData
9-
alias BACnet.Protocol.Constants
109
alias BACnet.Stack.Transport.MstpTransport
1110
alias BACnet.Stack.Transport.MstpTransport.EncodingTools
1211
alias Circuits.UART
1312

1413
import BACnet.Internal, only: [log_debug: 1]
1514

16-
require Constants
1715
require Logger
1816

1917
@behaviour :gen_statem

0 commit comments

Comments
 (0)