Feature/raspberry pi blinkt color objects (#503)
* fixed BACnetXYcolor and BACnetColorCommand encode and decoding and improved unit test coverage. Refactored BACnetXYcolor to/from ascii into lighting module. * added to the color, color temperature, and lighting output objects a fade/ramp/step engine. Added color and color command coercion into the channel object and enabled color temperature object coercion. Added CreateObject and DeleteObject service handling to the color, color temperature, lighting output, and channel objects. * added blinkt demo app for Raspberry Pi [WIP] * updated gitignore to simplify handling of apps folder contents * fixed piface demo build * added RaspiOS to pipeline for piface and blinkt! demo builds * added device object timer function for child object types into example Device object. Refactored device object to increment database revision for create or delete object services. Refactored example app/server to use mstimer library and device child object timers. --------- Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
@@ -136,6 +136,7 @@ list(APPEND testdirs
|
||||
bacnet/basic/sys/fifo
|
||||
bacnet/basic/sys/filename
|
||||
bacnet/basic/sys/keylist
|
||||
bacnet/basic/sys/linear
|
||||
bacnet/basic/sys/ringbuf
|
||||
bacnet/basic/sys/sbuf
|
||||
)
|
||||
|
||||
@@ -45,8 +45,9 @@ add_executable(${PROJECT_NAME}
|
||||
${SRC_DIR}/bacnet/bactext.c
|
||||
${SRC_DIR}/bacnet/bactimevalue.c
|
||||
${SRC_DIR}/bacnet/basic/sys/bigend.c
|
||||
${SRC_DIR}/bacnet/datetime.c
|
||||
${SRC_DIR}/bacnet/basic/sys/days.c
|
||||
${SRC_DIR}/bacnet/basic/sys/keylist.c
|
||||
${SRC_DIR}/bacnet/datetime.c
|
||||
${SRC_DIR}/bacnet/indtext.c
|
||||
${SRC_DIR}/bacnet/hostnport.c
|
||||
${SRC_DIR}/bacnet/lighting.c
|
||||
|
||||
@@ -24,22 +24,30 @@ static void test_Channel_ReadProperty(void)
|
||||
uint8_t apdu[MAX_APDU] = { 0 };
|
||||
int len = 0;
|
||||
int test_len = 0;
|
||||
BACNET_READ_PROPERTY_DATA rpdata;
|
||||
/* for decode value data */
|
||||
BACNET_APPLICATION_DATA_VALUE value;
|
||||
BACNET_READ_PROPERTY_DATA rpdata = { 0 };
|
||||
BACNET_APPLICATION_DATA_VALUE value = { 0 };
|
||||
BACNET_WRITE_PROPERTY_DATA wpdata = { 0 };
|
||||
const uint32_t instance = 123;
|
||||
const int *pRequired = NULL;
|
||||
const int *pOptional = NULL;
|
||||
const int *pProprietary = NULL;
|
||||
unsigned count = 0;
|
||||
bool status = false;
|
||||
unsigned index;
|
||||
|
||||
Channel_Init();
|
||||
Channel_Create(instance);
|
||||
status = Channel_Valid_Instance(instance);
|
||||
zassert_true(status, NULL);
|
||||
index = Channel_Instance_To_Index(instance);
|
||||
zassert_equal(index, 0, NULL);
|
||||
|
||||
count = Channel_Count();
|
||||
zassert_true(count > 0, NULL);
|
||||
rpdata.application_data = &apdu[0];
|
||||
rpdata.application_data_len = sizeof(apdu);
|
||||
rpdata.object_type = OBJECT_CHANNEL;
|
||||
rpdata.object_instance = Channel_Index_To_Instance(0);;
|
||||
rpdata.object_instance = Channel_Index_To_Instance(0);
|
||||
status = Channel_Valid_Instance(rpdata.object_instance);
|
||||
zassert_true(status, NULL);
|
||||
Channel_Property_Lists(&pRequired, &pOptional, &pProprietary);
|
||||
@@ -47,22 +55,37 @@ static void test_Channel_ReadProperty(void)
|
||||
rpdata.object_property = *pRequired;
|
||||
rpdata.array_index = BACNET_ARRAY_ALL;
|
||||
len = Channel_Read_Property(&rpdata);
|
||||
zassert_not_equal(len, BACNET_STATUS_ERROR, NULL);
|
||||
zassert_not_equal(len, BACNET_STATUS_ERROR,
|
||||
"property '%s': failed to ReadProperty!\n",
|
||||
bactext_property_name(rpdata.object_property));
|
||||
if (len > 0) {
|
||||
test_len = bacapp_decode_application_data(rpdata.application_data,
|
||||
(uint8_t)rpdata.application_data_len, &value);
|
||||
if (len != test_len) {
|
||||
printf("property '%s': failed to decode!\n",
|
||||
bactext_property_name(rpdata.object_property));
|
||||
}
|
||||
if (rpdata.object_property == PROP_PRIORITY_ARRAY) {
|
||||
if ((rpdata.object_property == PROP_PRIORITY_ARRAY) ||
|
||||
(rpdata.object_property == PROP_CONTROL_GROUPS) ||
|
||||
(rpdata.object_property ==
|
||||
PROP_LIST_OF_OBJECT_PROPERTY_REFERENCES)) {
|
||||
/* FIXME: known fail to decode */
|
||||
len = test_len;
|
||||
}
|
||||
zassert_true(test_len >= 0, NULL);
|
||||
} else {
|
||||
printf("property '%s': failed to read!\n",
|
||||
zassert_equal(len, test_len, "property '%s': failed to decode!\n",
|
||||
bactext_property_name(rpdata.object_property));
|
||||
/* check WriteProperty properties */
|
||||
wpdata.object_type = rpdata.object_type;
|
||||
wpdata.object_instance = rpdata.object_instance;
|
||||
wpdata.object_property = rpdata.object_property;
|
||||
wpdata.array_index = rpdata.array_index;
|
||||
memcpy(&wpdata.application_data, rpdata.application_data, MAX_APDU);
|
||||
wpdata.application_data_len = len;
|
||||
wpdata.error_code = ERROR_CODE_SUCCESS;
|
||||
status = Channel_Write_Property(&wpdata);
|
||||
if (!status) {
|
||||
/* verify WriteProperty property is known */
|
||||
zassert_not_equal(wpdata.error_code,
|
||||
ERROR_CODE_UNKNOWN_PROPERTY,
|
||||
"property '%s': WriteProperty Unknown!\n",
|
||||
bactext_property_name(rpdata.object_property));
|
||||
}
|
||||
}
|
||||
pRequired++;
|
||||
}
|
||||
@@ -70,21 +93,41 @@ static void test_Channel_ReadProperty(void)
|
||||
rpdata.object_property = *pOptional;
|
||||
rpdata.array_index = BACNET_ARRAY_ALL;
|
||||
len = Channel_Read_Property(&rpdata);
|
||||
zassert_not_equal(len, BACNET_STATUS_ERROR, NULL);
|
||||
zassert_not_equal(len, BACNET_STATUS_ERROR,
|
||||
"property '%s': failed to ReadProperty!\n",
|
||||
bactext_property_name(rpdata.object_property));
|
||||
if (len > 0) {
|
||||
test_len = bacapp_decode_application_data(rpdata.application_data,
|
||||
(uint8_t)rpdata.application_data_len, &value);
|
||||
if (len != test_len) {
|
||||
printf("property '%s': failed to decode!\n",
|
||||
zassert_equal(len, test_len, "property '%s': failed to decode!\n",
|
||||
bactext_property_name(rpdata.object_property));
|
||||
/* check WriteProperty properties */
|
||||
wpdata.object_type = rpdata.object_type;
|
||||
wpdata.object_instance = rpdata.object_instance;
|
||||
wpdata.object_property = rpdata.object_property;
|
||||
wpdata.array_index = rpdata.array_index;
|
||||
memcpy(&wpdata.application_data, rpdata.application_data, MAX_APDU);
|
||||
wpdata.application_data_len = len;
|
||||
wpdata.error_code = ERROR_CODE_SUCCESS;
|
||||
status = Channel_Write_Property(&wpdata);
|
||||
if (!status) {
|
||||
/* verify WriteProperty property is known */
|
||||
zassert_not_equal(wpdata.error_code,
|
||||
ERROR_CODE_UNKNOWN_PROPERTY,
|
||||
"property '%s': WriteProperty Unknown!\n",
|
||||
bactext_property_name(rpdata.object_property));
|
||||
}
|
||||
zassert_true(test_len >= 0, NULL);
|
||||
} else {
|
||||
printf("property '%s': failed to read!\n",
|
||||
bactext_property_name(rpdata.object_property));
|
||||
}
|
||||
pOptional++;
|
||||
}
|
||||
rpdata.object_property = PROP_ALL;
|
||||
len = Channel_Read_Property(&rpdata);
|
||||
zassert_equal(len, BACNET_STATUS_ERROR, NULL);
|
||||
wpdata.object_property = PROP_ALL;
|
||||
status = Channel_Write_Property(&wpdata);
|
||||
zassert_false(status, NULL);
|
||||
status = Channel_Delete(instance);
|
||||
zassert_true(status, NULL);
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
@@ -92,8 +135,7 @@ static void test_Channel_ReadProperty(void)
|
||||
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(channel_tests,
|
||||
ztest_unit_test(test_Channel_ReadProperty));
|
||||
ztest_test_suite(channel_tests, ztest_unit_test(test_Channel_ReadProperty));
|
||||
|
||||
ztest_run_test_suite(channel_tests);
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ add_executable(${PROJECT_NAME}
|
||||
${SRC_DIR}/bacnet/bactext.c
|
||||
${SRC_DIR}/bacnet/basic/sys/bigend.c
|
||||
${SRC_DIR}/bacnet/basic/sys/keylist.c
|
||||
${SRC_DIR}/bacnet/basic/sys/linear.c
|
||||
${SRC_DIR}/bacnet/cov.c
|
||||
${SRC_DIR}/bacnet/datetime.c
|
||||
${SRC_DIR}/bacnet/basic/sys/days.c
|
||||
|
||||
@@ -27,13 +27,22 @@ static void testColorObject(void)
|
||||
uint8_t apdu[MAX_APDU] = { 0 };
|
||||
int len = 0;
|
||||
int test_len = 0;
|
||||
BACNET_READ_PROPERTY_DATA rpdata = {0};
|
||||
BACNET_APPLICATION_DATA_VALUE value = {0};
|
||||
const int *required_property = NULL;
|
||||
BACNET_READ_PROPERTY_DATA rpdata = { 0 };
|
||||
BACNET_APPLICATION_DATA_VALUE value = { 0 };
|
||||
const int *pRequired = NULL;
|
||||
const int *pOptional = NULL;
|
||||
const int *pProprietary = NULL;
|
||||
const uint32_t instance = 123;
|
||||
BACNET_WRITE_PROPERTY_DATA wpdata = { 0 };
|
||||
bool status = false;
|
||||
unsigned index;
|
||||
|
||||
Color_Init();
|
||||
Color_Create(instance);
|
||||
status = Color_Valid_Instance(instance);
|
||||
zassert_true(status, NULL);
|
||||
index = Color_Instance_To_Index(instance);
|
||||
zassert_equal(index, 0, NULL);
|
||||
|
||||
rpdata.application_data = &apdu[0];
|
||||
rpdata.application_data_len = sizeof(apdu);
|
||||
@@ -41,23 +50,77 @@ static void testColorObject(void)
|
||||
rpdata.object_instance = instance;
|
||||
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
|
||||
|
||||
Color_Property_Lists(&required_property, NULL, NULL);
|
||||
while ((*required_property) >= 0) {
|
||||
rpdata.object_property = *required_property;
|
||||
Color_Property_Lists(&pRequired, &pOptional, &pProprietary);
|
||||
while ((*pRequired) >= 0) {
|
||||
rpdata.object_property = *pRequired;
|
||||
rpdata.array_index = BACNET_ARRAY_ALL;
|
||||
len = Color_Read_Property(&rpdata);
|
||||
zassert_true(len >= 0, NULL);
|
||||
zassert_not_equal(len, BACNET_STATUS_ERROR,
|
||||
"property '%s': failed to ReadProperty!\n",
|
||||
bactext_property_name(rpdata.object_property));
|
||||
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",
|
||||
zassert_equal(len, test_len, "property '%s': failed to decode!\n",
|
||||
bactext_property_name(rpdata.object_property));
|
||||
/* check WriteProperty properties */
|
||||
wpdata.object_type = rpdata.object_type;
|
||||
wpdata.object_instance = rpdata.object_instance;
|
||||
wpdata.object_property = rpdata.object_property;
|
||||
wpdata.array_index = rpdata.array_index;
|
||||
memcpy(&wpdata.application_data, rpdata.application_data, MAX_APDU);
|
||||
wpdata.application_data_len = len;
|
||||
wpdata.error_code = ERROR_CODE_SUCCESS;
|
||||
status = Color_Write_Property(&wpdata);
|
||||
if (!status) {
|
||||
/* verify WriteProperty property is known */
|
||||
zassert_not_equal(wpdata.error_code,
|
||||
ERROR_CODE_UNKNOWN_PROPERTY,
|
||||
"property '%s': WriteProperty Unknown!\n",
|
||||
bactext_property_name(rpdata.object_property));
|
||||
}
|
||||
zassert_equal(len, test_len, NULL);
|
||||
}
|
||||
required_property++;
|
||||
pRequired++;
|
||||
}
|
||||
while ((*pOptional) != -1) {
|
||||
rpdata.object_property = *pOptional;
|
||||
rpdata.array_index = BACNET_ARRAY_ALL;
|
||||
len = Color_Read_Property(&rpdata);
|
||||
zassert_not_equal(len, BACNET_STATUS_ERROR,
|
||||
"property '%s': failed to ReadProperty!\n",
|
||||
bactext_property_name(rpdata.object_property));
|
||||
if (len > 0) {
|
||||
test_len = bacapp_decode_application_data(rpdata.application_data,
|
||||
(uint8_t)rpdata.application_data_len, &value);
|
||||
zassert_equal(len, test_len, "property '%s': failed to decode!\n",
|
||||
bactext_property_name(rpdata.object_property));
|
||||
/* check WriteProperty properties */
|
||||
wpdata.object_type = rpdata.object_type;
|
||||
wpdata.object_instance = rpdata.object_instance;
|
||||
wpdata.object_property = rpdata.object_property;
|
||||
wpdata.array_index = rpdata.array_index;
|
||||
memcpy(&wpdata.application_data, rpdata.application_data, MAX_APDU);
|
||||
wpdata.application_data_len = len;
|
||||
wpdata.error_code = ERROR_CODE_SUCCESS;
|
||||
status = Color_Write_Property(&wpdata);
|
||||
if (!status) {
|
||||
/* verify WriteProperty property is known */
|
||||
zassert_not_equal(wpdata.error_code,
|
||||
ERROR_CODE_UNKNOWN_PROPERTY,
|
||||
"property '%s': WriteProperty Unknown!\n",
|
||||
bactext_property_name(rpdata.object_property));
|
||||
}
|
||||
}
|
||||
pOptional++;
|
||||
}
|
||||
rpdata.object_property = PROP_ALL;
|
||||
len = Color_Read_Property(&rpdata);
|
||||
zassert_equal(len, BACNET_STATUS_ERROR, NULL);
|
||||
wpdata.object_property = PROP_ALL;
|
||||
status = Color_Write_Property(&wpdata);
|
||||
zassert_false(status, NULL);
|
||||
status = Color_Delete(instance);
|
||||
zassert_true(status, NULL);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -65,15 +128,12 @@ static void testColorObject(void)
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
ZTEST_SUITE(color_object_tests, NULL, NULL, NULL, NULL, NULL);
|
||||
#else
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(color_object_tests,
|
||||
ztest_unit_test(testColorObject)
|
||||
);
|
||||
ztest_test_suite(color_object_tests, ztest_unit_test(testColorObject));
|
||||
|
||||
ztest_run_test_suite(color_object_tests);
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ add_executable(${PROJECT_NAME}
|
||||
${SRC_DIR}/bacnet/bactext.c
|
||||
${SRC_DIR}/bacnet/basic/sys/bigend.c
|
||||
${SRC_DIR}/bacnet/basic/sys/keylist.c
|
||||
${SRC_DIR}/bacnet/basic/sys/linear.c
|
||||
${SRC_DIR}/bacnet/cov.c
|
||||
${SRC_DIR}/bacnet/datetime.c
|
||||
${SRC_DIR}/bacnet/basic/sys/days.c
|
||||
|
||||
@@ -30,8 +30,12 @@ static void testColorTemperature(void)
|
||||
int test_len = 0;
|
||||
BACNET_READ_PROPERTY_DATA rpdata = {0};
|
||||
BACNET_APPLICATION_DATA_VALUE value = {0};
|
||||
const int *required_property = NULL;
|
||||
const int *pRequired = NULL;
|
||||
const int *pOptional = NULL;
|
||||
const int *pProprietary = NULL;
|
||||
const uint32_t instance = 123;
|
||||
BACNET_WRITE_PROPERTY_DATA wpdata = { 0 };
|
||||
bool status = false;
|
||||
|
||||
Color_Temperature_Init();
|
||||
Color_Temperature_Create(instance);
|
||||
@@ -42,23 +46,78 @@ static void testColorTemperature(void)
|
||||
rpdata.object_instance = instance;
|
||||
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
|
||||
|
||||
Color_Temperature_Property_Lists(&required_property, NULL, NULL);
|
||||
while ((*required_property) >= 0) {
|
||||
rpdata.object_property = *required_property;
|
||||
Color_Temperature_Property_Lists(&pRequired, &pOptional, &pProprietary);
|
||||
while ((*pRequired) >= 0) {
|
||||
rpdata.object_property = *pRequired;
|
||||
rpdata.array_index = BACNET_ARRAY_ALL;
|
||||
len = Color_Temperature_Read_Property(&rpdata);
|
||||
zassert_true(len >= 0, NULL);
|
||||
zassert_not_equal(len, BACNET_STATUS_ERROR,
|
||||
"property '%s': failed to ReadProperty!\n",
|
||||
bactext_property_name(rpdata.object_property));
|
||||
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",
|
||||
zassert_equal(len, test_len, "property '%s': failed to decode!\n",
|
||||
bactext_property_name(rpdata.object_property));
|
||||
/* check WriteProperty properties */
|
||||
wpdata.object_type = rpdata.object_type;
|
||||
wpdata.object_instance = rpdata.object_instance;
|
||||
wpdata.object_property = rpdata.object_property;
|
||||
wpdata.array_index = rpdata.array_index;
|
||||
memcpy(&wpdata.application_data, rpdata.application_data, MAX_APDU);
|
||||
wpdata.application_data_len = len;
|
||||
wpdata.error_code = ERROR_CODE_SUCCESS;
|
||||
status = Color_Temperature_Write_Property(&wpdata);
|
||||
if (!status) {
|
||||
/* verify WriteProperty property is known */
|
||||
zassert_not_equal(wpdata.error_code,
|
||||
ERROR_CODE_UNKNOWN_PROPERTY,
|
||||
"property '%s': WriteProperty Unknown!\n",
|
||||
bactext_property_name(rpdata.object_property));
|
||||
}
|
||||
zassert_equal(len, test_len, NULL);
|
||||
}
|
||||
required_property++;
|
||||
pRequired++;
|
||||
}
|
||||
while ((*pOptional) != -1) {
|
||||
rpdata.object_property = *pOptional;
|
||||
rpdata.array_index = BACNET_ARRAY_ALL;
|
||||
len = Color_Temperature_Read_Property(&rpdata);
|
||||
zassert_not_equal(len, BACNET_STATUS_ERROR,
|
||||
"property '%s': failed to ReadProperty!\n",
|
||||
bactext_property_name(rpdata.object_property));
|
||||
if (len > 0) {
|
||||
test_len = bacapp_decode_application_data(
|
||||
rpdata.application_data,
|
||||
(uint8_t)rpdata.application_data_len, &value);
|
||||
zassert_equal(len, test_len, "property '%s': failed to decode!\n",
|
||||
bactext_property_name(rpdata.object_property));
|
||||
/* check WriteProperty properties */
|
||||
wpdata.object_type = rpdata.object_type;
|
||||
wpdata.object_instance = rpdata.object_instance;
|
||||
wpdata.object_property = rpdata.object_property;
|
||||
wpdata.array_index = rpdata.array_index;
|
||||
memcpy(&wpdata.application_data, rpdata.application_data, MAX_APDU);
|
||||
wpdata.application_data_len = len;
|
||||
wpdata.error_code = ERROR_CODE_SUCCESS;
|
||||
status = Color_Temperature_Write_Property(&wpdata);
|
||||
if (!status) {
|
||||
/* verify WriteProperty property is known */
|
||||
zassert_not_equal(wpdata.error_code,
|
||||
ERROR_CODE_UNKNOWN_PROPERTY,
|
||||
"property '%s': WriteProperty Unknown!\n",
|
||||
bactext_property_name(rpdata.object_property));
|
||||
}
|
||||
}
|
||||
pOptional++;
|
||||
}
|
||||
rpdata.object_property = PROP_ALL;
|
||||
len = Color_Temperature_Read_Property(&rpdata);
|
||||
zassert_equal(len, BACNET_STATUS_ERROR, NULL);
|
||||
wpdata.object_property = PROP_ALL;
|
||||
status = Color_Temperature_Write_Property(&wpdata);
|
||||
zassert_false(status, NULL);
|
||||
status = Color_Temperature_Delete(instance);
|
||||
zassert_true(status, NULL);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -77,6 +77,7 @@ add_executable(${PROJECT_NAME}
|
||||
${SRC_DIR}/bacnet/basic/sys/bigend.c
|
||||
${SRC_DIR}/bacnet/basic/sys/debug.c
|
||||
${SRC_DIR}/bacnet/basic/sys/keylist.c
|
||||
${SRC_DIR}/bacnet/basic/sys/linear.c
|
||||
${SRC_DIR}/bacnet/basic/tsm/tsm.c
|
||||
${SRC_DIR}/bacnet/datalink/bvlc.c
|
||||
${SRC_DIR}/bacnet/cov.c
|
||||
|
||||
@@ -45,8 +45,11 @@ add_executable(${PROJECT_NAME}
|
||||
${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/days.c
|
||||
${SRC_DIR}/bacnet/basic/sys/color_rgb.c
|
||||
${SRC_DIR}/bacnet/basic/sys/keylist.c
|
||||
${SRC_DIR}/bacnet/basic/sys/linear.c
|
||||
${SRC_DIR}/bacnet/datetime.c
|
||||
${SRC_DIR}/bacnet/indtext.c
|
||||
${SRC_DIR}/bacnet/hostnport.c
|
||||
${SRC_DIR}/bacnet/lighting.c
|
||||
@@ -57,6 +60,10 @@ add_executable(${PROJECT_NAME}
|
||||
${SRC_DIR}/bacnet/dailyschedule.c
|
||||
# Test and test library files
|
||||
./src/main.c
|
||||
../mock/device_mock.c
|
||||
${ZTST_DIR}/ztest_mock.c
|
||||
${ZTST_DIR}/ztest.c
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||
m)
|
||||
|
||||
@@ -30,36 +30,104 @@ static void testLightingOutput(void)
|
||||
int len = 0, test_len = 0;
|
||||
BACNET_READ_PROPERTY_DATA rpdata;
|
||||
BACNET_APPLICATION_DATA_VALUE value = {0};
|
||||
const int *required_property = NULL;
|
||||
const uint32_t instance = 1;
|
||||
const int *pRequired = NULL;
|
||||
const int *pOptional = NULL;
|
||||
const int *pProprietary = NULL;
|
||||
const uint32_t instance = 123;
|
||||
BACNET_WRITE_PROPERTY_DATA wpdata = { 0 };
|
||||
bool status = false;
|
||||
unsigned index;
|
||||
uint16_t milliseconds = 10;
|
||||
|
||||
Lighting_Output_Init();
|
||||
Lighting_Output_Create(instance);
|
||||
status = Lighting_Output_Valid_Instance(instance);
|
||||
zassert_true(status, NULL);
|
||||
index = Lighting_Output_Instance_To_Index(instance);
|
||||
zassert_equal(index, 0, NULL);
|
||||
|
||||
rpdata.application_data = &apdu[0];
|
||||
rpdata.application_data_len = sizeof(apdu);
|
||||
rpdata.object_type = OBJECT_LIGHTING_OUTPUT;
|
||||
rpdata.object_instance = instance;
|
||||
rpdata.array_index = BACNET_ARRAY_ALL;
|
||||
|
||||
Lighting_Output_Property_Lists(&required_property, NULL, NULL);
|
||||
while ((*required_property) >= 0) {
|
||||
rpdata.object_property = *required_property;
|
||||
Lighting_Output_Property_Lists(&pRequired, &pOptional, &pProprietary);
|
||||
while ((*pRequired) >= 0) {
|
||||
rpdata.object_property = *pRequired;
|
||||
rpdata.array_index = BACNET_ARRAY_ALL;
|
||||
len = Lighting_Output_Read_Property(&rpdata);
|
||||
zassert_true(len >= 0, NULL);
|
||||
zassert_not_equal(len, BACNET_STATUS_ERROR,
|
||||
"property '%s': failed to ReadProperty!\n",
|
||||
bactext_property_name(rpdata.object_property));
|
||||
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",
|
||||
if (rpdata.object_property != PROP_PRIORITY_ARRAY) {
|
||||
zassert_equal(len, test_len, "property '%s': failed to decode!\n",
|
||||
bactext_property_name(rpdata.object_property));
|
||||
}
|
||||
/* check WriteProperty properties */
|
||||
wpdata.object_type = rpdata.object_type;
|
||||
wpdata.object_instance = rpdata.object_instance;
|
||||
wpdata.object_property = rpdata.object_property;
|
||||
wpdata.array_index = rpdata.array_index;
|
||||
memcpy(&wpdata.application_data, rpdata.application_data, MAX_APDU);
|
||||
wpdata.application_data_len = len;
|
||||
wpdata.error_code = ERROR_CODE_SUCCESS;
|
||||
status = Lighting_Output_Write_Property(&wpdata);
|
||||
if (!status) {
|
||||
/* verify WriteProperty property is known */
|
||||
zassert_not_equal(wpdata.error_code,
|
||||
ERROR_CODE_UNKNOWN_PROPERTY,
|
||||
"property '%s': WriteProperty Unknown!\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++;
|
||||
pRequired++;
|
||||
}
|
||||
while ((*pOptional) != -1) {
|
||||
rpdata.object_property = *pOptional;
|
||||
rpdata.array_index = BACNET_ARRAY_ALL;
|
||||
len = Lighting_Output_Read_Property(&rpdata);
|
||||
zassert_not_equal(len, BACNET_STATUS_ERROR,
|
||||
"property '%s': failed to ReadProperty!\n",
|
||||
bactext_property_name(rpdata.object_property));
|
||||
if (len > 0) {
|
||||
test_len = bacapp_decode_application_data(rpdata.application_data,
|
||||
(uint8_t)rpdata.application_data_len, &value);
|
||||
zassert_equal(len, test_len, "property '%s': failed to decode!\n",
|
||||
bactext_property_name(rpdata.object_property));
|
||||
/* check WriteProperty properties */
|
||||
wpdata.object_type = rpdata.object_type;
|
||||
wpdata.object_instance = rpdata.object_instance;
|
||||
wpdata.object_property = rpdata.object_property;
|
||||
wpdata.array_index = rpdata.array_index;
|
||||
memcpy(&wpdata.application_data, rpdata.application_data, MAX_APDU);
|
||||
wpdata.application_data_len = len;
|
||||
wpdata.error_code = ERROR_CODE_SUCCESS;
|
||||
status = Lighting_Output_Write_Property(&wpdata);
|
||||
if (!status) {
|
||||
/* verify WriteProperty property is known */
|
||||
zassert_not_equal(wpdata.error_code,
|
||||
ERROR_CODE_UNKNOWN_PROPERTY,
|
||||
"property '%s': WriteProperty Unknown!\n",
|
||||
bactext_property_name(rpdata.object_property));
|
||||
}
|
||||
}
|
||||
pOptional++;
|
||||
}
|
||||
/* check for unsupported property - use ALL */
|
||||
rpdata.object_property = PROP_ALL;
|
||||
len = Lighting_Output_Read_Property(&rpdata);
|
||||
zassert_equal(len, BACNET_STATUS_ERROR, NULL);
|
||||
status = Lighting_Output_Write_Property(&wpdata);
|
||||
zassert_false(status, NULL);
|
||||
/* check the dimming/ramping/stepping engine*/
|
||||
Lighting_Output_Timer(instance, milliseconds);
|
||||
/* check the delete function */
|
||||
status = Lighting_Output_Delete(instance);
|
||||
zassert_true(status, NULL);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <math.h>
|
||||
#include <zephyr/ztest.h>
|
||||
#include <bacnet/basic/sys/color_rgb.h>
|
||||
|
||||
@@ -16,34 +19,69 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief compare two floating point values to 3 decimal places
|
||||
*
|
||||
* @param x1 - first comparison value
|
||||
* @param x2 - second comparison value
|
||||
* @return true if the value is the same to 3 decimal points
|
||||
*/
|
||||
static bool is_float_equal(float x1, float x2)
|
||||
{
|
||||
return fabs(x1 - x2) < 0.001;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit Test for sRGB to CIE xy
|
||||
*/
|
||||
static void test_color_rgb_xy_unit(
|
||||
uint8_t red, uint8_t green, uint8_t blue,
|
||||
float x_coordinate, float y_coordinate,
|
||||
static void test_color_rgb_xy_gamma_unit(uint8_t red,
|
||||
uint8_t green,
|
||||
uint8_t blue,
|
||||
float x_coordinate,
|
||||
float y_coordinate,
|
||||
uint8_t brightness)
|
||||
{
|
||||
float test_x_coordinate = 0.0, test_y_coordinate = 0.0;
|
||||
uint8_t test_brightness = 0;
|
||||
uint8_t test_red = 0, test_green = 0, test_blue = 0;
|
||||
|
||||
/* functions with gamma correction */
|
||||
color_rgb_to_xy_gamma(red, green, blue, &test_x_coordinate,
|
||||
&test_y_coordinate, &test_brightness);
|
||||
color_rgb_from_xy_gamma(&test_red, &test_green, &test_blue, x_coordinate,
|
||||
y_coordinate, brightness);
|
||||
zassert_true(is_float_equal(x_coordinate, test_x_coordinate),
|
||||
"(x=%.3f,test_x=%.3f)", x_coordinate, test_x_coordinate);
|
||||
zassert_true(is_float_equal(y_coordinate, test_y_coordinate),
|
||||
"(y=%.3f,test_y=%.3f)", y_coordinate, test_y_coordinate);
|
||||
zassert_equal(brightness, test_brightness, "b=%u, test_b=%u", brightness,
|
||||
test_brightness);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit Test for sRGB to CIE xy
|
||||
*/
|
||||
static void test_color_rgb_xy_unit(uint8_t red,
|
||||
uint8_t green,
|
||||
uint8_t blue,
|
||||
float x_coordinate,
|
||||
float y_coordinate,
|
||||
uint8_t brightness)
|
||||
{
|
||||
float test_x_coordinate = 0.0, test_y_coordinate = 0.0;
|
||||
uint8_t test_brightness = 0;
|
||||
uint8_t test_red = 0, test_green = 0, test_blue = 0;
|
||||
|
||||
printf("test value:(%u,%u,%u)=(%.3f,%.3f,%u)\n",
|
||||
(unsigned)red, (unsigned)green, (unsigned)blue,
|
||||
x_coordinate, y_coordinate, (unsigned)brightness);
|
||||
color_rgb_to_xy(red, green, blue, &test_x_coordinate, &test_y_coordinate,
|
||||
&test_brightness);
|
||||
color_rgb_from_xy(&test_red, &test_green, &test_blue,
|
||||
x_coordinate, y_coordinate, brightness);
|
||||
printf("calculated:(%u,%u,%u)=(%.3f,%.3f,%u)\n",
|
||||
(unsigned)test_red, (unsigned)test_green, (unsigned)test_blue,
|
||||
test_x_coordinate, test_y_coordinate, (unsigned)test_brightness);
|
||||
//zassert_equal(x_coordinate, test_x_coordinate, NULL);
|
||||
//zassert_equal(y_coordinate, test_y_coordinate, NULL);
|
||||
//zassert_equal(brightness, test_brightness, NULL);
|
||||
//zassert_equal(red, test_red, NULL);
|
||||
//zassert_equal(green, test_green, NULL);
|
||||
//zassert_equal(blue, test_blue, NULL);
|
||||
color_rgb_from_xy(&test_red, &test_green, &test_blue, x_coordinate,
|
||||
y_coordinate, brightness);
|
||||
zassert_true(is_float_equal(x_coordinate, test_x_coordinate),
|
||||
"(x=%.3f,test_x=%.3f)", x_coordinate, test_x_coordinate);
|
||||
zassert_true(is_float_equal(y_coordinate, test_y_coordinate),
|
||||
"(y=%.3f,test_y=%.3f)", y_coordinate, test_y_coordinate);
|
||||
zassert_equal(brightness, test_brightness, "b=%u, test_b=%u", brightness,
|
||||
test_brightness);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,17 +93,40 @@ ZTEST(color_rgb_tests, test_color_rgb_xy)
|
||||
static void test_color_rgb_xy(void)
|
||||
#endif
|
||||
{
|
||||
test_color_rgb_xy_unit(0, 0, 0, 0.0, 0.0, 0);
|
||||
test_color_rgb_xy_unit(255, 255, 255, 0.323, 0.329, 255);
|
||||
test_color_rgb_xy_unit(0, 0, 255, 0.136, 0.04, 12);
|
||||
test_color_rgb_xy_unit(0, 255, 0, 0.172, 0.747, 170);
|
||||
test_color_rgb_xy_unit(255, 0, 0, 0.701, 0.299, 72);
|
||||
test_color_rgb_xy_unit(128, 0, 0, 0.701, 0.299, 16);
|
||||
uint8_t red, green, blue;
|
||||
|
||||
/* functions without gamma correction */
|
||||
color_rgb_from_ascii(&red, &green, &blue, "black");
|
||||
test_color_rgb_xy_unit(red, green, blue, 0.0, 0.0, 0);
|
||||
color_rgb_from_ascii(&red, &green, &blue, "white");
|
||||
test_color_rgb_xy_unit(red, green, blue, 0.313, 0.329, 255);
|
||||
color_rgb_from_ascii(&red, &green, &blue, "blue");
|
||||
test_color_rgb_xy_unit(red, green, blue, 0.157, 0.017, 5);
|
||||
color_rgb_from_ascii(&red, &green, &blue, "green");
|
||||
test_color_rgb_xy_unit(red, green, blue, 0.115, 0.826, 95);
|
||||
color_rgb_from_ascii(&red, &green, &blue, "red");
|
||||
test_color_rgb_xy_unit(red, green, blue, 0.735, 0.265, 59);
|
||||
color_rgb_from_ascii(&red, &green, &blue, "maroon");
|
||||
test_color_rgb_xy_unit(red, green, blue, 0.735, 0.265, 29);
|
||||
|
||||
/* functions with gamma correction */
|
||||
color_rgb_from_ascii(&red, &green, &blue, "black");
|
||||
test_color_rgb_xy_gamma_unit(red, green, blue, 0.0, 0.0, 0);
|
||||
color_rgb_from_ascii(&red, &green, &blue, "white");
|
||||
test_color_rgb_xy_gamma_unit(red, green, blue, 0.313, 0.329, 255);
|
||||
color_rgb_from_ascii(&red, &green, &blue, "blue");
|
||||
test_color_rgb_xy_gamma_unit(red, green, blue, 0.157, 0.017, 5);
|
||||
color_rgb_from_ascii(&red, &green, &blue, "green");
|
||||
test_color_rgb_xy_gamma_unit(red, green, blue, 0.115, 0.826, 40);
|
||||
color_rgb_from_ascii(&red, &green, &blue, "red");
|
||||
test_color_rgb_xy_gamma_unit(red, green, blue, 0.735, 0.265, 59);
|
||||
color_rgb_from_ascii(&red, &green, &blue, "maroon");
|
||||
test_color_rgb_xy_gamma_unit(red, green, blue, 0.735, 0.265, 12);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit Test for sRGB to CIE xy
|
||||
*/
|
||||
* Unit Test for sRGB to CIE xy
|
||||
*/
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
ZTEST(color_rgb_tests, test_color_rgb_ascii)
|
||||
#else
|
||||
@@ -85,8 +146,8 @@ static void test_color_rgb_ascii(void)
|
||||
for (unsigned i = 0; i < count; i++) {
|
||||
name = color_rgb_from_index(i, &red, &green, &blue);
|
||||
zassert_not_null(name, NULL);
|
||||
test_index = color_rgb_from_ascii(&test_red, &test_green, &test_blue,
|
||||
name);
|
||||
test_index =
|
||||
color_rgb_from_ascii(&test_red, &test_green, &test_blue, name);
|
||||
zassert_equal(i, test_index, NULL);
|
||||
zassert_equal(red, test_red, NULL);
|
||||
zassert_equal(green, test_green, NULL);
|
||||
@@ -100,16 +161,13 @@ static void test_color_rgb_ascii(void)
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
ZTEST_SUITE(color_rgb_tests, NULL, NULL, NULL, NULL, NULL);
|
||||
#else
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(color_rgb_tests,
|
||||
ztest_unit_test(test_color_rgb_ascii),
|
||||
ztest_unit_test(test_color_rgb_xy)
|
||||
);
|
||||
ztest_test_suite(color_rgb_tests, ztest_unit_test(test_color_rgb_ascii),
|
||||
ztest_unit_test(test_color_rgb_xy));
|
||||
|
||||
ztest_run_test_suite(color_rgb_tests);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
|
||||
|
||||
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
|
||||
project(test_${basename}
|
||||
VERSION 1.0.0
|
||||
LANGUAGES C)
|
||||
|
||||
|
||||
string(REGEX REPLACE
|
||||
"/test/bacnet/[a-zA-Z_/-]*$"
|
||||
"/src"
|
||||
SRC_DIR
|
||||
${CMAKE_CURRENT_SOURCE_DIR})
|
||||
string(REGEX REPLACE
|
||||
"/test/bacnet/[a-zA-Z_/-]*$"
|
||||
"/test"
|
||||
TST_DIR
|
||||
${CMAKE_CURRENT_SOURCE_DIR})
|
||||
set(ZTST_DIR "${TST_DIR}/ztest/src")
|
||||
|
||||
add_compile_definitions(
|
||||
BIG_ENDIAN=0
|
||||
CONFIG_ZTEST=1
|
||||
)
|
||||
|
||||
include_directories(
|
||||
${SRC_DIR}
|
||||
${TST_DIR}/ztest/include
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
# File(s) under test
|
||||
${SRC_DIR}/bacnet/basic/sys/linear.c
|
||||
# Support files and stubs (pathname alphabetical)
|
||||
# Test and test library files
|
||||
./src/main.c
|
||||
${ZTST_DIR}/ztest_mock.c
|
||||
${ZTST_DIR}/ztest.c
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||
m)
|
||||
@@ -0,0 +1,136 @@
|
||||
/**
|
||||
* @file
|
||||
* @brief test linear interpolation APIs
|
||||
* @date 2010
|
||||
*
|
||||
* @section LICENSE
|
||||
* Copyright (c) 2010 Steve Karg <skarg@users.sourceforge.net>
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#include <zephyr/ztest.h>
|
||||
#include <bacnet/basic/sys/linear.h>
|
||||
|
||||
/**
|
||||
* @addtogroup bacnet_tests
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Unit Test for linear interpolation of floating point values, rounded
|
||||
*/
|
||||
void testLinearInterpolateRound(void)
|
||||
{
|
||||
uint16_t x2 = 0;
|
||||
uint16_t y1 = 0;
|
||||
uint16_t y2 = 0;
|
||||
uint16_t y3 = 0;
|
||||
uint16_t x2_test = 0;
|
||||
|
||||
y2 = linear_interpolate_round(1, 1, 65535, 1, 100);
|
||||
zassert_equal(y2, 1, NULL);
|
||||
y2 = linear_interpolate_round(1, 1, 65535, 100, 1);
|
||||
zassert_equal(y2, 100, NULL);
|
||||
|
||||
y2 = linear_interpolate_round(1, 65535, 65535, 1, 100);
|
||||
zassert_equal(y2, 100, NULL);
|
||||
y2 = linear_interpolate_round(1, 65535, 65535, 100, 1);
|
||||
zassert_equal(y2, 1, NULL);
|
||||
|
||||
y2 = linear_interpolate_round(1, (65535 / 2), 65535, 1, 100);
|
||||
zassert_equal(y2, 50, NULL);
|
||||
|
||||
y2 = linear_interpolate_round(1, (65535 / 4), 65535, 1, 100);
|
||||
zassert_equal(y2, 26, NULL);
|
||||
|
||||
y2 = linear_interpolate_round(1, ((65535 * 3) / 4), 65535, 1, 100);
|
||||
zassert_equal(y2, 75, NULL);
|
||||
|
||||
y2 = linear_interpolate_round(1, 1, 100, 1, 65535);
|
||||
zassert_equal(y2, 1, NULL);
|
||||
|
||||
y2 = linear_interpolate_round(1, 100, 100, 1, 65535);
|
||||
zassert_equal(y2, 65535, NULL);
|
||||
|
||||
y2 = linear_interpolate_round(1, 100 / 2, 100, 1, 65535);
|
||||
zassert_equal(y2, 32437, NULL);
|
||||
|
||||
/* scaling from percent to steps and back */
|
||||
for (x2 = 1; x2 <= 100; x2++) {
|
||||
y2 = linear_interpolate_round(1, x2, 100, 1, 65535);
|
||||
x2_test = linear_interpolate_round(1, y2, 65535, 1, 100);
|
||||
zassert_equal(x2, x2_test, NULL);
|
||||
}
|
||||
|
||||
/* test for low-trim, high-trim and scaling from percent to steps */
|
||||
for (x2 = 1; x2 <= 100; x2++) {
|
||||
y1 = linear_interpolate_round(1, 20, 100, 1, 65535);
|
||||
y3 = linear_interpolate_round(1, 80, 100, 1, 65535);
|
||||
y2 = linear_interpolate_round(1, x2, 100, y1, y3);
|
||||
x2_test = linear_interpolate_round(y1, y2, y3, 1, 100);
|
||||
zassert_equal(x2, x2_test, "x2=%hu x2_test=%hu\n", x2, x2_test);
|
||||
}
|
||||
|
||||
y2 = linear_interpolate_round(1, 1, 65535, 20, 80);
|
||||
zassert_equal(y2, 20, NULL);
|
||||
y2 = linear_interpolate_round(1, 1, 65535, 80, 20);
|
||||
zassert_equal(y2, 80, NULL);
|
||||
y2 = linear_interpolate_round(1, 65535, 65535, 20, 80);
|
||||
zassert_equal(y2, 80, NULL);
|
||||
y2 = linear_interpolate_round(1, 65535, 65535, 80, 20);
|
||||
zassert_equal(y2, 20, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit Test for linear interpolation of integers
|
||||
*/
|
||||
void testLinearInterpolateInt(void)
|
||||
{
|
||||
uint16_t y2 = 0;
|
||||
|
||||
y2 = linear_interpolate_int(1, 1, 65535, 1, 100);
|
||||
zassert_equal(y2, 1, NULL);
|
||||
y2 = linear_interpolate_int(1, 1, 65535, 100, 1);
|
||||
zassert_equal(y2, 100, NULL);
|
||||
|
||||
y2 = linear_interpolate_int(1, 65535, 65535, 1, 100);
|
||||
zassert_equal(y2, 100, NULL);
|
||||
y2 = linear_interpolate_int(1, 65535, 65535, 100, 1);
|
||||
zassert_equal(y2, 1, NULL);
|
||||
|
||||
y2 = linear_interpolate_int(1, (65535 / 4), 65535, 1, 100);
|
||||
zassert_equal(y2, 25, NULL);
|
||||
|
||||
y2 = linear_interpolate_int(1, (65535 / 2), 65535, 1, 100);
|
||||
zassert_equal(y2, 50, NULL);
|
||||
|
||||
y2 = linear_interpolate_int(1, ((65535 * 3) / 4), 65535, 1, 100);
|
||||
zassert_equal(y2, 75, NULL);
|
||||
|
||||
y2 = linear_interpolate_int(1, 1, 100, 1, 65535);
|
||||
zassert_equal(y2, 1, NULL);
|
||||
|
||||
y2 = linear_interpolate_int(1, 100, 100, 1, 65535);
|
||||
zassert_equal(y2, 65535, NULL);
|
||||
|
||||
y2 = linear_interpolate_int(1, 100 / 2, 100, 1, 65535);
|
||||
zassert_equal(y2, 32437, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
ZTEST_SUITE(Linear_Interpolate, NULL, NULL, NULL, NULL, NULL);
|
||||
#else
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(Linear_Interpolate,
|
||||
ztest_unit_test(testLinearInterpolateRound),
|
||||
ztest_unit_test(testLinearInterpolateInt)
|
||||
);
|
||||
|
||||
ztest_run_test_suite(Linear_Interpolate);
|
||||
}
|
||||
#endif
|
||||
@@ -39,6 +39,8 @@ add_executable(${PROJECT_NAME}
|
||||
${SRC_DIR}/bacnet/bacreal.c
|
||||
${SRC_DIR}/bacnet/bacstr.c
|
||||
${SRC_DIR}/bacnet/basic/sys/bigend.c
|
||||
${SRC_DIR}/bacnet/bactext.c
|
||||
${SRC_DIR}/bacnet/indtext.c
|
||||
# Test and test library files
|
||||
./src/main.c
|
||||
${ZTST_DIR}/ztest_mock.c
|
||||
|
||||
+123
-42
@@ -10,6 +10,8 @@
|
||||
|
||||
#include <zephyr/ztest.h>
|
||||
#include <bacnet/bacdef.h>
|
||||
#include <bacnet/bactext.h>
|
||||
#include <bacnet/basic/sys/platform.h>
|
||||
#include <bacnet/lighting.h>
|
||||
|
||||
/**
|
||||
@@ -36,10 +38,16 @@ static void testBACnetLightingCommand(BACNET_LIGHTING_COMMAND *data)
|
||||
status = lighting_command_same(&test_data, data);
|
||||
zassert_true(status, NULL);
|
||||
len = lighting_command_encode(apdu, data);
|
||||
apdu_len = lighting_command_decode(apdu, sizeof(apdu), &test_data);
|
||||
zassert_true(len > 0, NULL);
|
||||
zassert_true(apdu_len > 0, NULL);
|
||||
apdu_len = lighting_command_decode(apdu, len, &test_data);
|
||||
zassert_true(len > 0, "lighting-command[%s] failed to encode!",
|
||||
bactext_lighting_operation_name(data->operation));
|
||||
zassert_true(apdu_len > 0, "lighting-command[%s] failed to decode!",
|
||||
bactext_lighting_operation_name(data->operation));
|
||||
status = lighting_command_same(&test_data, data);
|
||||
while (len) {
|
||||
len--;
|
||||
apdu_len = lighting_command_decode(apdu, len, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
@@ -48,27 +56,58 @@ ZTEST(lighting_tests, testBACnetLightingCommandAll)
|
||||
static void testBACnetLightingCommandAll(void)
|
||||
#endif
|
||||
{
|
||||
BACNET_LIGHTING_COMMAND data;
|
||||
/*
|
||||
BACNET_LIGHTING_OPERATION operation;
|
||||
bool use_target_level:1;
|
||||
bool use_ramp_rate:1;
|
||||
bool use_step_increment:1;
|
||||
bool use_fade_time:1;
|
||||
bool use_priority:1;
|
||||
float target_level;
|
||||
float ramp_rate;
|
||||
float step_increment;
|
||||
uint32_t fade_time;
|
||||
uint8_t priority;
|
||||
*/
|
||||
BACNET_LIGHTING_COMMAND test_data[] = {
|
||||
{ BACNET_LIGHTS_NONE, false, false, false, false, false, 0.0, 100.0,
|
||||
1.0, 100, 1 },
|
||||
{ BACNET_LIGHTS_FADE_TO, true, false, false, true, true, 100.0, 100.0,
|
||||
1.0, 100, 1 },
|
||||
{ BACNET_LIGHTS_FADE_TO, true, false, false, false, false, 0.0, 100.0,
|
||||
1.0, 100, 1 },
|
||||
{ BACNET_LIGHTS_RAMP_TO, true, true, false, false, true, 0.0, 100.0,
|
||||
1.0, 100, 1 },
|
||||
{ BACNET_LIGHTS_RAMP_TO, true, false, false, false, false, 100.0, 100.0,
|
||||
1.0, 100, 1 },
|
||||
{ BACNET_LIGHTS_STEP_UP, false, false, true, false, true, 100.0, 100.0,
|
||||
1.0, 100, 1 },
|
||||
{ BACNET_LIGHTS_STEP_UP, false, false, true, false, false, 100.0, 100.0,
|
||||
2.0, 100, 1 },
|
||||
{ BACNET_LIGHTS_STEP_DOWN, false, false, true, false, true, 100.0,
|
||||
100.0, 1.0, 100, 1 },
|
||||
{ BACNET_LIGHTS_STEP_DOWN, false, false, true, false, false, 100.0,
|
||||
100.0, 2.0, 100, 1 },
|
||||
{ BACNET_LIGHTS_STEP_ON, false, false, true, false, true, 100.0, 100.0,
|
||||
1.0, 100, 1 },
|
||||
{ BACNET_LIGHTS_STEP_ON, false, false, true, false, false, 100.0, 100.0,
|
||||
2.0, 100, 1 },
|
||||
{ BACNET_LIGHTS_STEP_OFF, false, false, true, false, true, 100.0, 100.0,
|
||||
1.0, 100, 1 },
|
||||
{ BACNET_LIGHTS_STEP_OFF, false, false, true, false, false, 100.0,
|
||||
100.0, 2.0, 100, 1 },
|
||||
{ BACNET_LIGHTS_STOP, false, false, false, false, true, 100.0, 100.0,
|
||||
1.0, 100, 1 },
|
||||
{ BACNET_LIGHTS_STOP, false, false, false, false, false, 100.0, 100.0,
|
||||
2.0, 100, 1 },
|
||||
};
|
||||
unsigned i;
|
||||
|
||||
data.operation = BACNET_LIGHTS_NONE;
|
||||
data.use_target_level = false;
|
||||
data.use_ramp_rate = false;
|
||||
data.use_step_increment = false;
|
||||
data.use_fade_time = false;
|
||||
data.use_priority = false;
|
||||
data.target_level = 0.0;
|
||||
data.ramp_rate = 100.0;
|
||||
data.step_increment = 1.0;
|
||||
data.fade_time = 100;
|
||||
data.priority = 1;
|
||||
testBACnetLightingCommand(&data);
|
||||
data.operation = BACNET_LIGHTS_STOP;
|
||||
data.use_target_level = true;
|
||||
data.use_ramp_rate = true;
|
||||
data.use_step_increment = true;
|
||||
data.use_fade_time = true;
|
||||
data.use_priority = true;
|
||||
testBACnetLightingCommand(&data);
|
||||
for (i = 0; i < ARRAY_SIZE(test_data); i++) {
|
||||
printf("test-lighting-command[%s]\n",
|
||||
bactext_lighting_operation_name(test_data[i].operation));
|
||||
testBACnetLightingCommand(&test_data[i]);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
@@ -94,11 +133,16 @@ static void testBACnetColorCommand(BACNET_COLOR_COMMAND *data)
|
||||
status = color_command_same(&test_data, data);
|
||||
zassert_true(status, NULL);
|
||||
len = color_command_encode(apdu, data);
|
||||
apdu_len = color_command_decode(apdu, sizeof(apdu), &error_code,
|
||||
&test_data);
|
||||
zassert_true(len > 0, NULL);
|
||||
zassert_true(apdu_len > 0, NULL);
|
||||
apdu_len = color_command_decode(apdu, len, &error_code, &test_data);
|
||||
zassert_true(len > 0, "color-command[%s] failed to encode!",
|
||||
bactext_color_operation_name(data->operation));
|
||||
zassert_true(apdu_len > 0, "color-command[%s] failed to decode!",
|
||||
bactext_color_operation_name(data->operation));
|
||||
status = color_command_same(&test_data, data);
|
||||
while (len) {
|
||||
len--;
|
||||
apdu_len = color_command_decode(apdu, len, NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
@@ -107,16 +151,51 @@ ZTEST(lighting_tests, testBACnetColorCommandAll)
|
||||
static void testBACnetColorCommandAll(void)
|
||||
#endif
|
||||
{
|
||||
BACNET_COLOR_COMMAND data = { 0 };
|
||||
BACNET_COLOR_COMMAND test_data[] = {
|
||||
{ .operation = BACNET_COLOR_OPERATION_NONE,
|
||||
.target.color_temperature = 0,
|
||||
.transit.fade_time = 0 },
|
||||
{ .operation = BACNET_COLOR_OPERATION_STOP,
|
||||
.target.color_temperature = 0,
|
||||
.transit.fade_time = 0 },
|
||||
{ .operation = BACNET_COLOR_OPERATION_FADE_TO_COLOR,
|
||||
.target.color.x_coordinate = 0.0,
|
||||
.target.color.y_coordinate = 0.0,
|
||||
.transit.fade_time = 0 },
|
||||
{ .operation = BACNET_COLOR_OPERATION_FADE_TO_COLOR,
|
||||
.target.color.x_coordinate = 0.0,
|
||||
.target.color.y_coordinate = 0.0,
|
||||
.transit.fade_time = 2000 },
|
||||
{ .operation = BACNET_COLOR_OPERATION_FADE_TO_CCT,
|
||||
.target.color_temperature = 1800,
|
||||
.transit.fade_time = 0 },
|
||||
{ .operation = BACNET_COLOR_OPERATION_FADE_TO_CCT,
|
||||
.target.color_temperature = 1800,
|
||||
.transit.fade_time = 2000 },
|
||||
{ .operation = BACNET_COLOR_OPERATION_RAMP_TO_CCT,
|
||||
.target.color_temperature = 1800,
|
||||
.transit.ramp_rate = 0 },
|
||||
{ .operation = BACNET_COLOR_OPERATION_RAMP_TO_CCT,
|
||||
.target.color_temperature = 1800,
|
||||
.transit.ramp_rate = 20 },
|
||||
{ .operation = BACNET_COLOR_OPERATION_STEP_UP_CCT,
|
||||
.target.color_temperature = 1800,
|
||||
.transit.step_increment = 0 },
|
||||
{ .operation = BACNET_COLOR_OPERATION_STEP_UP_CCT,
|
||||
.target.color_temperature = 1800,
|
||||
.transit.step_increment = 1 },
|
||||
{ .operation = BACNET_COLOR_OPERATION_STEP_DOWN_CCT,
|
||||
.target.color_temperature = 5000,
|
||||
.transit.step_increment = 0 },
|
||||
{ .operation = BACNET_COLOR_OPERATION_STEP_DOWN_CCT,
|
||||
.target.color_temperature = 5000,
|
||||
.transit.step_increment = 1 },
|
||||
};
|
||||
unsigned i;
|
||||
|
||||
data.operation = BACNET_COLOR_OPERATION_NONE;
|
||||
data.target.color_temperature = 0;
|
||||
data.transit.fade_time = 0;
|
||||
testBACnetColorCommand(&data);
|
||||
data.operation = BACNET_COLOR_OPERATION_STOP;
|
||||
data.target.color_temperature = 0;
|
||||
data.transit.fade_time = 0;
|
||||
testBACnetColorCommand(&data);
|
||||
for (i = 0; i < ARRAY_SIZE(test_data); i++) {
|
||||
testBACnetColorCommand(&test_data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
@@ -146,11 +225,14 @@ static void testBACnetXYColor(void)
|
||||
null_len = xy_color_context_encode(NULL, tag_number, &value);
|
||||
len = xy_color_context_encode(apdu, tag_number, &value);
|
||||
zassert_equal(null_len, len, NULL);
|
||||
test_len = xy_color_context_decode(apdu, sizeof(apdu), tag_number,
|
||||
&test_value);
|
||||
test_len = xy_color_context_decode(apdu, len, tag_number, &test_value);
|
||||
zassert_equal(test_len, len, NULL);
|
||||
status = xy_color_same(&value, &test_value);
|
||||
zassert_true(status, NULL);
|
||||
while (len) {
|
||||
len--;
|
||||
test_len = xy_color_context_decode(apdu, len, tag_number, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
@@ -159,10 +241,9 @@ ZTEST_SUITE(lighting_tests, NULL, NULL, NULL, NULL, NULL);
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(lighting_tests,
|
||||
ztest_unit_test(testBACnetLightingCommandAll),
|
||||
ztest_unit_test(testBACnetColorCommandAll),
|
||||
ztest_unit_test(testBACnetXYColor)
|
||||
);
|
||||
ztest_unit_test(testBACnetLightingCommandAll),
|
||||
ztest_unit_test(testBACnetColorCommandAll),
|
||||
ztest_unit_test(testBACnetXYColor));
|
||||
|
||||
ztest_run_test_suite(lighting_tests);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user