Added post-write notifications for channel, timer, and loop objects. (#1204)

This commit is contained in:
Steve Karg
2026-01-20 13:13:45 -06:00
committed by GitHub
parent 5802bd0ecc
commit 89cf25c2b2
10 changed files with 367 additions and 13 deletions
+63 -1
View File
@@ -26,6 +26,20 @@ static bool Write_Property_Internal(BACNET_WRITE_PROPERTY_DATA *wp_data)
return true;
}
static struct channel_write_property_notification Write_Property_Notification;
static BACNET_WRITE_PROPERTY_DATA Write_Property_Notification_Data;
static uint32_t Write_Property_Notification_Instance;
static bool Write_Property_Notification_Status;
static void Channel_Write_Property_Notification_Callback(
uint32_t instance, bool status, BACNET_WRITE_PROPERTY_DATA *wp_data)
{
Write_Property_Notification_Instance = instance;
Write_Property_Notification_Status = status;
memcpy(
&Write_Property_Notification_Data, wp_data,
sizeof(BACNET_WRITE_PROPERTY_DATA));
}
/**
* @brief Test
*/
@@ -38,15 +52,21 @@ static void test_Channel_Property_Read_Write(void)
const char *test_name = NULL;
uint32_t test_instance = 0;
bool status = false;
int len = 0;
const int32_t skip_fail_property_list[] = { -1 };
BACNET_CHANNEL_VALUE channel_value = { 0 };
BACNET_WRITE_PROPERTY_DATA wp_data = { 0 };
BACNET_WRITE_GROUP_DATA wg_data = { 0 };
BACNET_APPLICATION_DATA_VALUE value = { 0 };
BACNET_APPLICATION_DATA_VALUE test_value = { 0 };
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE member = { 0 };
Channel_Write_Property_Internal_Callback_Set(Write_Property_Internal);
Write_Property_Notification.callback =
Channel_Write_Property_Notification_Callback;
Write_Property_Notification.next = NULL;
Channel_Write_Property_Notification_Add(&Write_Property_Notification);
Channel_Init();
Channel_Create(instance);
status = Channel_Valid_Instance(instance);
@@ -162,6 +182,48 @@ static void test_Channel_Property_Read_Write(void)
bacapp_encode_application_data(wp_data.application_data, &value);
status = Channel_Write_Property(&wp_data);
zassert_true(status, NULL);
/* does the callback object property match the last member? */
zassert_equal(
Write_Property_Internal_Data.object_property, member.propertyIdentifier,
"%s:%d %s",
bactext_object_type_name(Write_Property_Internal_Data.object_type),
Write_Property_Internal_Data.object_instance,
bactext_property_name(Write_Property_Internal_Data.object_property));
zassert_equal(
Write_Property_Internal_Data.object_type, member.objectIdentifier.type,
"WriteProperty=%s:%d",
bactext_object_type_name(Write_Property_Internal_Data.object_type),
Write_Property_Internal_Data.object_instance);
zassert_equal(
Write_Property_Internal_Data.object_instance,
member.objectIdentifier.instance, "WriteProperty=%s:%d",
bactext_object_type_name(Write_Property_Internal_Data.object_type),
Write_Property_Internal_Data.object_instance);
len = bacapp_decode_application_data(
Write_Property_Internal_Data.application_data,
Write_Property_Internal_Data.application_data_len, &test_value);
zassert_true(len > 0, "len=%d", len);
/* does the notify callback object property match the last member? */
zassert_equal(Write_Property_Notification_Instance, instance, NULL);
zassert_equal(Write_Property_Notification_Status, true, NULL);
zassert_equal(
Write_Property_Notification_Data.object_property,
member.propertyIdentifier, NULL);
zassert_equal(
Write_Property_Notification_Data.object_type,
member.objectIdentifier.type, "WriteProperty=%s:%d",
bactext_object_type_name(Write_Property_Notification_Data.object_type),
Write_Property_Notification_Data.object_instance);
zassert_equal(
Write_Property_Notification_Data.object_instance,
member.objectIdentifier.instance, "WriteProperty=%s:%d",
bactext_object_type_name(Write_Property_Notification_Data.object_type),
Write_Property_Notification_Data.object_instance);
len = bacapp_decode_application_data(
Write_Property_Notification_Data.application_data,
Write_Property_Notification_Data.application_data_len, &test_value);
zassert_true(len > 0, "len=%d", len);
/* another coercion */
value.type.Channel_Value.tag = BACNET_APPLICATION_TAG_XY_COLOR;
value.type.Channel_Value.type.XY_Color.x_coordinate = 0.4590f;
value.type.Channel_Value.type.XY_Color.y_coordinate = 0.4101f;
+56
View File
@@ -35,6 +35,20 @@ static int Read_Property_Internal(BACNET_READ_PROPERTY_DATA *data)
return Read_Property_Internal_Length;
}
static struct loop_write_property_notification Write_Property_Notification;
static BACNET_WRITE_PROPERTY_DATA Write_Property_Notification_Data;
static uint32_t Write_Property_Notification_Instance;
static bool Write_Property_Notification_Status;
static void Loop_Write_Property_Notification_Callback(
uint32_t instance, bool status, BACNET_WRITE_PROPERTY_DATA *wp_data)
{
Write_Property_Notification_Instance = instance;
Write_Property_Notification_Status = status;
memcpy(
&Write_Property_Notification_Data, wp_data,
sizeof(BACNET_WRITE_PROPERTY_DATA));
}
static int Proprietary_Properties[] = { 512, 513, -1 };
static uint8_t Proprietary_Serial_Number[16];
@@ -369,6 +383,8 @@ static void test_Loop_Operation(void)
bool status = false;
uint32_t elapsed_time = 0;
BACNET_OBJECT_PROPERTY_REFERENCE reference = { 0 };
BACNET_APPLICATION_DATA_VALUE test_value = { 0 };
int len = 0;
/* init */
Loop_Init();
@@ -379,6 +395,10 @@ static void test_Loop_Operation(void)
/* connect the read and write property callbacks */
Loop_Write_Property_Internal_Callback_Set(Write_Property_Internal);
Loop_Read_Property_Internal_Callback_Set(Read_Property_Internal);
Write_Property_Notification.callback =
Loop_Write_Property_Notification_Callback;
Write_Property_Notification.next = NULL;
Loop_Write_Property_Notification_Add(&Write_Property_Notification);
/* run the PID loop */
Loop_Timer(instance, elapsed_time);
elapsed_time += 1000;
@@ -402,6 +422,42 @@ static void test_Loop_Operation(void)
Loop_Manipulated_Variable_Reference_Set(instance, &reference);
elapsed_time += 100;
Loop_Timer(instance, elapsed_time);
/* references - test by referencing another internal object */
reference.object_identifier.type = OBJECT_ANALOG_OUTPUT;
reference.property_identifier = PROP_PRESENT_VALUE;
Loop_Manipulated_Variable_Reference_Set(instance, &reference);
elapsed_time += 100;
Loop_Timer(instance, elapsed_time);
/* verify that the internal read/write property callbacks were used */
zassert_equal(
Write_Property_Internal_Data.object_type, OBJECT_ANALOG_OUTPUT,
"WriteProperty=%s:%d",
bactext_object_type_name(Write_Property_Internal_Data.object_type),
Write_Property_Internal_Data.object_instance);
zassert_equal(
Write_Property_Internal_Data.object_instance, instance,
"WriteProperty=%s:%d",
bactext_object_type_name(Write_Property_Internal_Data.object_type),
Write_Property_Internal_Data.object_instance);
zassert_equal(
Write_Property_Internal_Data.object_property, PROP_PRESENT_VALUE,
"WriteProperty=%s:%d %s",
bactext_object_type_name(Write_Property_Internal_Data.object_type),
Write_Property_Internal_Data.object_instance,
bactext_property_name(Write_Property_Internal_Data.object_property));
len = bacapp_decode_application_data(
Write_Property_Internal_Data.application_data,
Write_Property_Internal_Data.application_data_len, &test_value);
zassert_true(len > 0, "len=%d", len);
zassert_equal(Write_Property_Notification_Instance, instance, NULL);
zassert_equal(Write_Property_Notification_Status, true, NULL);
zassert_equal(
Write_Property_Notification_Data.object_property, PROP_PRESENT_VALUE,
NULL);
len = bacapp_decode_application_data(
Write_Property_Notification_Data.application_data,
Write_Property_Notification_Data.application_data_len, &test_value);
zassert_true(len > 0, "len=%d", len);
/* cleanup instance */
status = Loop_Delete(instance);
zassert_true(status, NULL);
+27
View File
@@ -26,6 +26,20 @@ static bool Write_Property_Internal(BACNET_WRITE_PROPERTY_DATA *wp_data)
return true;
}
static struct timer_write_property_notification Write_Property_Notification;
static BACNET_WRITE_PROPERTY_DATA Write_Property_Notification_Data;
static uint32_t Write_Property_Notification_Instance;
static bool Write_Property_Notification_Status;
static void Timer_Write_Property_Notification_Callback(
uint32_t instance, bool status, BACNET_WRITE_PROPERTY_DATA *wp_data)
{
Write_Property_Notification_Instance = instance;
Write_Property_Notification_Status = status;
memcpy(
&Write_Property_Notification_Data, wp_data,
sizeof(BACNET_WRITE_PROPERTY_DATA));
}
/**
* @brief Test
*/
@@ -544,6 +558,15 @@ static void test_Timer_Operation_Transition_Default(
Write_Property_Internal_Data.application_data,
Write_Property_Internal_Data.application_data_len, &test_value);
zassert_true(len > 0, "len=%d", len);
zassert_equal(Write_Property_Notification_Instance, instance, NULL);
zassert_equal(Write_Property_Notification_Status, true, NULL);
zassert_equal(
Write_Property_Notification_Data.object_property, PROP_PRESENT_VALUE,
NULL);
len = bacapp_decode_application_data(
Write_Property_Notification_Data.application_data,
Write_Property_Notification_Data.application_data_len, &test_value);
zassert_true(len > 0, "len=%d", len);
value = Timer_State_Change_Value(instance, test_transition);
zassert_equal(test_value.tag, value->tag, NULL);
zassert_equal(test_value.type.Enumerated, value->type.Enumerated, NULL);
@@ -576,6 +599,10 @@ static void test_Timer_Operation(void)
datetime_timesync(&bdatetime.date, &bdatetime.time, false);
/* configure the reference members and the write property values */
Timer_Write_Property_Internal_Callback_Set(Write_Property_Internal);
Write_Property_Notification.callback =
Timer_Write_Property_Notification_Callback;
Write_Property_Notification.next = NULL;
Timer_Write_Property_Notification_Add(&Write_Property_Notification);
members = Timer_Reference_List_Member_Capacity(instance);
for (i = 0; i < members; i++) {
member.deviceIdentifier.type = OBJECT_DEVICE;