Add CreateObject and DeleteObject for Octet String and Positive Integer Values (#1246)

* Added CreateObject and DeleteObject for basic Octet String Value and Positive Integer Value objects.

* Changed PositiveInteger present-value datatype to BACNET_UNSIGNED_INTEGER.
This commit is contained in:
Steve Karg
2026-02-26 16:25:03 -06:00
committed by GitHub
parent 24587dfc27
commit 1437a68ce1
13 changed files with 599 additions and 234 deletions
+4 -1
View File
@@ -27,6 +27,7 @@ add_compile_definitions(
include_directories(
${SRC_DIR}
${TST_DIR}/bacnet/basic/object/test
${TST_DIR}/ztest/include
)
@@ -46,9 +47,10 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/basic/sys/keylist.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c
@@ -66,6 +68,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/secure_connect.c
# Test and test library files
./src/main.c
${TST_DIR}/bacnet/basic/object/test/property_test.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
+40 -38
View File
@@ -9,6 +9,7 @@
#include <zephyr/ztest.h>
#include <bacnet/basic/object/osv.h>
#include <bacnet/bactext.h>
#include <property_test.h>
/**
* @addtogroup bacnet_tests
@@ -24,46 +25,47 @@ ZTEST(osv_tests, testOctetString_Value)
static void testOctetString_Value(void)
#endif
{
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0, test_len = 0;
BACNET_READ_PROPERTY_DATA rpdata = { 0 };
BACNET_APPLICATION_DATA_VALUE value = { 0 };
const int32_t *required_property = NULL;
const uint32_t instance = 1;
bool status = false;
unsigned count = 0, index = 0;
uint32_t object_instance = 0, test_object_instance = 0;
const int32_t *writable_properties = NULL;
const int32_t skip_fail_property_list[] = { -1 };
OctetString_Value_Init();
rpdata.application_data = &apdu[0];
rpdata.application_data_len = sizeof(apdu);
rpdata.object_type = OBJECT_OCTETSTRING_VALUE;
rpdata.object_instance = instance;
rpdata.array_index = BACNET_ARRAY_ALL;
OctetString_Value_Property_Lists(&required_property, NULL, NULL);
while ((*required_property) >= 0) {
rpdata.object_property = *required_property;
len = OctetString_Value_Read_Property(&rpdata);
zassert_true(len >= 0, NULL);
if (len >= 0) {
test_len = bacapp_decode_known_property(
rpdata.application_data, len, &value, rpdata.object_type,
rpdata.object_property);
if (len != test_len) {
printf(
"property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property));
}
if (rpdata.object_property == PROP_PRIORITY_ARRAY) {
/* FIXME: known fail to decode */
len = test_len;
}
zassert_equal(len, test_len, NULL);
} else {
printf(
"property '%s': failed to read!\n",
bactext_property_name(rpdata.object_property));
}
required_property++;
}
test_object_instance = OctetString_Value_Create(BACNET_MAX_INSTANCE + 1);
zassert_equal(test_object_instance, BACNET_MAX_INSTANCE, NULL);
test_object_instance = OctetString_Value_Create(BACNET_MAX_INSTANCE);
zassert_not_equal(test_object_instance, BACNET_MAX_INSTANCE, NULL);
status = OctetString_Value_Delete(test_object_instance);
zassert_true(status, NULL);
count = OctetString_Value_Count();
zassert_true(count == 0, NULL);
test_object_instance = OctetString_Value_Create(object_instance);
zassert_equal(test_object_instance, object_instance, NULL);
status = OctetString_Value_Valid_Instance(object_instance);
zassert_true(status, NULL);
status = OctetString_Value_Valid_Instance(object_instance - 1);
zassert_false(status, NULL);
index = OctetString_Value_Instance_To_Index(object_instance);
zassert_equal(index, 0, NULL);
test_object_instance = OctetString_Value_Index_To_Instance(index);
zassert_equal(object_instance, test_object_instance, NULL);
count = OctetString_Value_Count();
zassert_true(count == 1, NULL);
test_object_instance = OctetString_Value_Index_To_Instance(0);
zassert_equal(object_instance, test_object_instance, NULL);
bacnet_object_properties_read_write_test(
OBJECT_OCTETSTRING_VALUE, object_instance,
OctetString_Value_Property_Lists, OctetString_Value_Read_Property,
OctetString_Value_Write_Property, skip_fail_property_list);
bacnet_object_name_ascii_test(
object_instance, OctetString_Value_Name_Set,
OctetString_Value_Name_ASCII);
OctetString_Value_Writable_Property_List(
object_instance, &writable_properties);
zassert_not_null(writable_properties, NULL);
status = OctetString_Value_Delete(object_instance);
zassert_true(status, NULL);
}
/**
* @}
+4 -1
View File
@@ -27,6 +27,7 @@ add_compile_definitions(
include_directories(
${SRC_DIR}
${TST_DIR}/bacnet/basic/object/test
${TST_DIR}/ztest/include
)
@@ -46,9 +47,10 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/basic/sys/keylist.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c
@@ -66,6 +68,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/secure_connect.c
# Test and test library files
./src/main.c
${TST_DIR}/bacnet/basic/object/test/property_test.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
+42 -34
View File
@@ -10,6 +10,7 @@
#include <zephyr/ztest.h>
#include <bacnet/basic/object/piv.h>
#include <bacnet/bactext.h>
#include <property_test.h>
/**
* @addtogroup bacnet_tests
@@ -25,42 +26,49 @@ ZTEST(piv_tests, testPositiveInteger_Value)
static void testPositiveInteger_Value(void)
#endif
{
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0, test_len = 0;
BACNET_READ_PROPERTY_DATA rpdata = { 0 };
BACNET_APPLICATION_DATA_VALUE value = { 0 };
const int32_t *required_property = NULL;
const uint32_t instance = 1;
bool status = false;
unsigned count = 0, index = 0;
uint32_t object_instance = 0, test_object_instance = 0;
const int32_t *writable_properties = NULL;
const int32_t skip_fail_property_list[] = { -1 };
PositiveInteger_Value_Init();
rpdata.application_data = &apdu[0];
rpdata.application_data_len = sizeof(apdu);
rpdata.object_type = OBJECT_POSITIVE_INTEGER_VALUE;
rpdata.object_instance = instance;
rpdata.array_index = BACNET_ARRAY_ALL;
PositiveInteger_Value_Property_Lists(&required_property, NULL, NULL);
while ((*required_property) >= 0) {
rpdata.object_property = *required_property;
len = PositiveInteger_Value_Read_Property(&rpdata);
zassert_true(len >= 0, NULL);
if (len >= 0) {
test_len = bacapp_decode_known_property(
rpdata.application_data, len, &value, rpdata.object_type,
rpdata.object_property);
if (len != test_len) {
printf(
"property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property));
}
if (rpdata.object_property == PROP_PRIORITY_ARRAY) {
/* FIXME: known fail to decode */
len = test_len;
}
zassert_equal(len, test_len, NULL);
}
required_property++;
}
test_object_instance =
PositiveInteger_Value_Create(BACNET_MAX_INSTANCE + 1);
zassert_equal(test_object_instance, BACNET_MAX_INSTANCE, NULL);
test_object_instance = PositiveInteger_Value_Create(BACNET_MAX_INSTANCE);
zassert_not_equal(test_object_instance, BACNET_MAX_INSTANCE, NULL);
status = PositiveInteger_Value_Delete(test_object_instance);
zassert_true(status, NULL);
count = PositiveInteger_Value_Count();
zassert_true(count == 0, NULL);
test_object_instance = PositiveInteger_Value_Create(object_instance);
zassert_equal(test_object_instance, object_instance, NULL);
status = PositiveInteger_Value_Valid_Instance(object_instance);
zassert_true(status, NULL);
status = PositiveInteger_Value_Valid_Instance(object_instance - 1);
zassert_false(status, NULL);
index = PositiveInteger_Value_Instance_To_Index(object_instance);
zassert_equal(index, 0, NULL);
test_object_instance = PositiveInteger_Value_Index_To_Instance(index);
zassert_equal(object_instance, test_object_instance, NULL);
count = PositiveInteger_Value_Count();
zassert_true(count == 1, NULL);
test_object_instance = PositiveInteger_Value_Index_To_Instance(0);
zassert_equal(object_instance, test_object_instance, NULL);
bacnet_object_properties_read_write_test(
OBJECT_POSITIVE_INTEGER_VALUE, object_instance,
PositiveInteger_Value_Property_Lists,
PositiveInteger_Value_Read_Property,
PositiveInteger_Value_Write_Property, skip_fail_property_list);
bacnet_object_name_ascii_test(
object_instance, PositiveInteger_Value_Name_Set,
PositiveInteger_Value_Name_ASCII);
PositiveInteger_Value_Writable_Property_List(
object_instance, &writable_properties);
zassert_not_null(writable_properties, NULL);
status = PositiveInteger_Value_Delete(object_instance);
zassert_true(status, NULL);
}
/**
* @}