da2dc9841a
* 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>
151 lines
5.2 KiB
C
151 lines
5.2 KiB
C
/*
|
|
* Copyright (c) 2020 Legrand North America, LLC.
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
/* @file
|
|
* @brief test BACnet integer encode/decode APIs
|
|
*/
|
|
|
|
#include <zephyr/ztest.h>
|
|
#include <bacnet/bactext.h>
|
|
#include <bacnet/basic/object/lo.h>
|
|
|
|
/**
|
|
* @addtogroup bacnet_tests
|
|
* @{
|
|
*/
|
|
|
|
/**
|
|
* @brief Test
|
|
*/
|
|
#if defined(CONFIG_ZTEST_NEW_API)
|
|
ZTEST(lo_tests, testLightingOutput)
|
|
#else
|
|
static void testLightingOutput(void)
|
|
#endif
|
|
{
|
|
uint8_t apdu[MAX_APDU] = { 0 };
|
|
int len = 0, test_len = 0;
|
|
BACNET_READ_PROPERTY_DATA rpdata;
|
|
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;
|
|
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(&pRequired, &pOptional, &pProprietary);
|
|
while ((*pRequired) >= 0) {
|
|
rpdata.object_property = *pRequired;
|
|
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_known_property(rpdata.application_data,
|
|
len, &value, rpdata.object_type, rpdata.object_property);
|
|
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));
|
|
}
|
|
}
|
|
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;
|
|
}
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
|
|
#if defined(CONFIG_ZTEST_NEW_API)
|
|
ZTEST_SUITE(lo_tests, NULL, NULL, NULL, NULL, NULL);
|
|
#else
|
|
void test_main(void)
|
|
{
|
|
ztest_test_suite(lo_tests,
|
|
ztest_unit_test(testLightingOutput)
|
|
);
|
|
|
|
ztest_run_test_suite(lo_tests);
|
|
}
|
|
#endif
|