Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ else()
patches/0005-Add-routed-analog-input-object-support.patch
patches/0006-Add-routed-multistate-input-object-support.patch
patches/0007-Allow-BACNET_PROTOCOL_REVISION-to-be-set-by-user.patch
patches/0008-Exclude-object-identifier-from-the-common-prop-list.patch)
patches/0008-Exclude-object-identifier-from-the-common-prop-list.patch
patches/0009-Set-description-and-name-when-creating-input-objs.patch)
endif()

CPMFindPackage(
Expand All @@ -61,6 +62,8 @@ set(SOURCES
src/log.c
src/main.c
src/port.c
src/object/binary_input.c
src/object/characterstring_value.c
src/object/command.c
src/protocol/decode_call.c
src/protocol/enum.c
Expand Down
133 changes: 118 additions & 15 deletions lib/bacnet/gateway/object.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,24 @@ defmodule BACNet.Gateway.Object do
- `device_id`: The ID of the BACnet device where the object will be created.
- `object_id`: The unique ID for the new analog input object.
- `name`: A unique name for the object.
- `description`: A short description for the analog input object.
- `unit`: The unit of measurement for the analog input, represented as an atom.
"""
@spec create_analog_input(
pid :: pid,
device_id :: integer,
object_id :: integer,
name :: String.t,
unit :: atom
pid :: pid,
device_id :: integer,
object_id :: integer,
name :: String.t,
description :: String.t,
unit :: atom
) :: :ok | {:error, term}
def create_analog_input(pid, device_id, object_id, name, unit) do
def create_analog_input(pid, device_id, object_id, name, description, unit) do
GenServer.call(pid, {
:create_routed_analog_input,
device_id,
object_id,
name,
description,
unit,
})
end
Expand All @@ -42,10 +45,10 @@ defmodule BACNet.Gateway.Object do
- `value`: The new present value to be set for the analog input.
"""
@spec set_analog_input_present_value(
pid :: pid,
pid :: pid,
device_id :: integer,
object_id :: integer,
value :: float
value :: float
) :: :ok | {:error, term}
def set_analog_input_present_value(pid, device_id, object_id, value) do
GenServer.call(pid, {
Expand All @@ -65,21 +68,24 @@ defmodule BACNet.Gateway.Object do
- `device_id`: The ID of the BACnet device where the object will be created.
- `object_id`: The unique ID for the new multistate input object.
- `name`: A unique name for the object.
- `description`: A short description for the multistate input object.
- `states`: A set of strings representing the object's states.
"""
@spec create_multistate_input(
pid :: pid,
device_id :: integer,
object_id :: integer,
name :: String.t,
states :: [String.t]
pid :: pid,
device_id :: integer,
object_id :: integer,
name :: String.t,
description :: String.t,
states :: [String.t]
) :: :ok | {:error, term}
def create_multistate_input(pid, device_id, object_id, name, states) do
def create_multistate_input(pid, device_id, object_id, name, description, states) do
GenServer.call(pid, {
:create_routed_multistate_input,
device_id,
object_id,
name,
description,
states,
})
end
Expand Down Expand Up @@ -119,6 +125,7 @@ defmodule BACNet.Gateway.Object do
- `object_id`: The unique ID for the new command object.
- `name`: A unique name for the object.
- `description`: A short description for the command object.
- `value`: Set the initial value when a value is provided.
"""
@spec create_command(
pid :: pid,
Expand Down Expand Up @@ -153,7 +160,7 @@ defmodule BACNet.Gateway.Object do
pid :: pid,
device_id :: integer,
object_id :: integer,
status :: :succeeded | :failed
status :: :succeeded | :failed
) :: :ok | {:error, term}
def set_command_status(pid, device_id, object_id, status) do
GenServer.call(pid, {
Expand All @@ -163,4 +170,100 @@ defmodule BACNet.Gateway.Object do
status
})
end

@doc """
Creates a new characterstring value object.

## Parameters

- `pid`: The PID of the GenServer managing BACnet communications.
- `device_id`: The ID of the BACnet device where the object will be created.
- `object_id`: The unique ID for the new characterstring value object.
- `name`: A unique name for the object.
- `description`: A short description for the characterstring value object.
- `value`: A utf-8 string.
"""
@spec create_characterstring_value(
pid :: pid,
device_id :: integer,
object_id :: integer,
name :: String.t,
description :: String.t,
value :: String.t
) :: :ok | {:error, term}
def create_characterstring_value(pid, device_id, object_id, name, description, value) do
GenServer.call(pid, {
:create_characterstring_value,
device_id,
object_id,
name,
description,
value
})
end

@doc """
Creates a new binary input object.

## Parameters

- `pid`: The PID of the GenServer managing BACnet communications.
- `device_id`: The ID of the BACnet device where the object will be created.
- `object_id`: The unique ID for the new binary input object.
- `name`: A unique name for the object.
- `description`: A short description for the binary input object.
- `active_test`: A short description representing the active state of value.
- `inactive_test`: A short description representing the inactive state of value.
- `polarity`: How the physical state of an input corresponds to the logical state of value.
- `value`: A binary input value represented as a boolean.
"""
@spec create_binary_input(
pid :: pid,
device_id :: integer,
object_id :: integer,
name :: String.t,
description :: String.t,
active_text :: String.t,
inactive_text :: String.t,
polarity :: :normal | :reverse | :max,
value :: boolean
) :: :ok | {:error, term}
def create_binary_input(pid, device_id, object_id, name, description, active_text, inactive_text, polarity, value) do
GenServer.call(pid, {
:create_binary_input,
device_id,
object_id,
name,
description,
active_text,
inactive_text,
polarity,
value
})
end

@doc """
Set the value of a binary input object.

## Parameters

- `pid`: The PID of the GenServer managing BACnet communications.
- `device_id`: The ID of the BACnet device where the object will be created.
- `object_id`: The unique ID for the new command object.
- `value`: A binary input value represented as a boolean.
"""
@spec set_binary_input_present_value(
pid :: pid,
device_id :: integer,
object_id :: integer,
value :: boolean
) :: :ok | {:error, term}
def set_binary_input_present_value(pid, device_id, object_id, value) do
GenServer.call(pid, {
:set_binary_input_value,
device_id,
object_id,
value
})
end
end
103 changes: 103 additions & 0 deletions patches/0009-Set-description-and-name-when-creating-input-objs.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
From d0bb51317816d9c3b4a0fc657e0bb7d5fcdc1150 Mon Sep 17 00:00:00 2001
From: abelino <abelino.romo@gmail.com>
Date: Thu, 10 Apr 2025 20:23:05 -0700
Subject: [PATCH] Set description and name when creating a msi and ai objects

---
src/bacnet/basic/object/routed_analog_input.c | 10 ++++++++--
src/bacnet/basic/object/routed_analog_input.h | 5 ++++-
src/bacnet/basic/object/routed_multistate_input.c | 10 ++++++++--
src/bacnet/basic/object/routed_multistate_input.h | 5 ++++-
4 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/src/bacnet/basic/object/routed_analog_input.c b/src/bacnet/basic/object/routed_analog_input.c
index 6064161e..d0cb3ff7 100644
--- a/src/bacnet/basic/object/routed_analog_input.c
+++ b/src/bacnet/basic/object/routed_analog_input.c
@@ -336,8 +336,11 @@ void Routed_Analog_Input_Change_Of_Value_Clear(uint32_t instance_number)
object->Changed = false;
}

-uint32_t Routed_Analog_Input_Create(uint32_t object_instance)
-{
+uint32_t Routed_Analog_Input_Create(
+ uint32_t object_instance,
+ char *name,
+ char *description
+) {
DEVICE_OBJECT_DATA *device = Get_Routed_Device_Object(-1);

if (object_instance >= BACNET_MAX_INSTANCE)
@@ -369,6 +372,9 @@ uint32_t Routed_Analog_Input_Create(uint32_t object_instance)
memset(object->Object_Name, 0, sizeof(object->Object_Name));
memset(object->Description, 0, sizeof(object->Description));

+ memcpy(object->Object_Name, name, strlen(name));
+ memcpy(object->Description, description, strlen(description));
+
if (Keylist_Data_Add(device->objects, object_instance, object) < 0) {
free(object);
return BACNET_MAX_INSTANCE;
diff --git a/src/bacnet/basic/object/routed_analog_input.h b/src/bacnet/basic/object/routed_analog_input.h
index 63ef9b16..399e4777 100644
--- a/src/bacnet/basic/object/routed_analog_input.h
+++ b/src/bacnet/basic/object/routed_analog_input.h
@@ -85,7 +85,10 @@ BACNET_STACK_EXPORT
void Routed_Analog_Input_Intrinsic_Reporting(uint32_t object_instance);

BACNET_STACK_EXPORT
-uint32_t Routed_Analog_Input_Create(uint32_t object_instance);
+uint32_t Routed_Analog_Input_Create(
+ uint32_t object_instance,
+ char *name,
+ char *description);

BACNET_STACK_EXPORT
bool Routed_Analog_Input_Delete(uint32_t object_instance);
diff --git a/src/bacnet/basic/object/routed_multistate_input.c b/src/bacnet/basic/object/routed_multistate_input.c
index 9df2251f..4301e0da 100644
--- a/src/bacnet/basic/object/routed_multistate_input.c
+++ b/src/bacnet/basic/object/routed_multistate_input.c
@@ -435,8 +435,11 @@ void Routed_Multistate_Input_Change_Of_Value_Clear(uint32_t instance_number)
object->Changed = false;
}

-uint32_t Routed_Multistate_Input_Create(uint32_t object_instance)
-{
+uint32_t Routed_Multistate_Input_Create(
+ uint32_t object_instance,
+ char *name,
+ char *description
+) {
DEVICE_OBJECT_DATA *device = Get_Routed_Device_Object(-1);

if (object_instance >= BACNET_MAX_INSTANCE)
@@ -465,6 +468,9 @@ uint32_t Routed_Multistate_Input_Create(uint32_t object_instance)
memset(object->Object_Name, 0, sizeof(object->Object_Name));
memset(object->Description, 0, sizeof(object->Description));

+ memcpy(object->Object_Name, name, strlen(name));
+ memcpy(object->Description, description, strlen(description));
+
if (Keylist_Data_Add(device->objects, object_instance, object) < 0) {
free(object);
return BACNET_MAX_INSTANCE;
diff --git a/src/bacnet/basic/object/routed_multistate_input.h b/src/bacnet/basic/object/routed_multistate_input.h
index d9a5725f..3e73b34d 100644
--- a/src/bacnet/basic/object/routed_multistate_input.h
+++ b/src/bacnet/basic/object/routed_multistate_input.h
@@ -81,7 +81,10 @@ BACNET_STACK_EXPORT
void Routed_Multistate_Input_Intrinsic_Reporting(uint32_t object_instance);

BACNET_STACK_EXPORT
-uint32_t Routed_Multistate_Input_Create(uint32_t object_instance);
+uint32_t Routed_Multistate_Input_Create(
+ uint32_t object_instance,
+ char *name,
+ char *description);

BACNET_STACK_EXPORT
bool Routed_Multistate_Input_Delete(uint32_t object_instance);
--
2.48.1

Loading
Loading