Added CreateObject and DeleteObject to Load Control object. (#713)

This commit is contained in:
Steve Karg
2024-08-11 19:14:27 -05:00
committed by GitHub
parent ebb8be067f
commit e5307e280c
12 changed files with 1749 additions and 986 deletions
+2 -4
View File
@@ -197,8 +197,7 @@ static void Init_Service_Handlers(uint32_t first_object_instance)
* @see Device_Set_Object_Instance_Number, dlenv_init, Send_I_Am, * @see Device_Set_Object_Instance_Number, dlenv_init, Send_I_Am,
* datalink_receive, npdu_handler, * datalink_receive, npdu_handler,
* dcc_timer_seconds, datalink_maintenance_timer, * dcc_timer_seconds, datalink_maintenance_timer,
* Load_Control_State_Machine_Handler, handler_cov_task, * handler_cov_task, tsm_timer_milliseconds
* tsm_timer_milliseconds
* *
* @param argc [in] Arg count. * @param argc [in] Arg count.
* @param argv [in] Takes one argument: the Device Instance #. * @param argv [in] Takes one argument: the Device Instance #.
@@ -274,12 +273,11 @@ int main(int argc, char *argv[])
dcc_timer_seconds(elapsed_seconds); dcc_timer_seconds(elapsed_seconds);
datalink_maintenance_timer(elapsed_seconds); datalink_maintenance_timer(elapsed_seconds);
dlenv_maintenance_timer(elapsed_seconds); dlenv_maintenance_timer(elapsed_seconds);
Load_Control_State_Machine_Handler();
elapsed_milliseconds = elapsed_seconds * 1000; elapsed_milliseconds = elapsed_seconds * 1000;
tsm_timer_milliseconds(elapsed_milliseconds); tsm_timer_milliseconds(elapsed_milliseconds);
Device_Timer(elapsed_milliseconds);
} }
handler_cov_task(); handler_cov_task();
/* output */
if (Routed_Device_Index < MAX_NUM_DEVICES) { if (Routed_Device_Index < MAX_NUM_DEVICES) {
Routed_Device_Index++; Routed_Device_Index++;
Get_Routed_Device_Object(Routed_Device_Index); Get_Routed_Device_Object(Routed_Device_Index);
+1 -3
View File
@@ -282,8 +282,7 @@ static void print_help(const char *filename)
* @see Device_Set_Object_Instance_Number, dlenv_init, Send_I_Am, * @see Device_Set_Object_Instance_Number, dlenv_init, Send_I_Am,
* datalink_receive, npdu_handler, * datalink_receive, npdu_handler,
* dcc_timer_seconds, datalink_maintenance_timer, * dcc_timer_seconds, datalink_maintenance_timer,
* Load_Control_State_Machine_Handler, handler_cov_task, * handler_cov_task, tsm_timer_milliseconds
* tsm_timer_milliseconds
* *
* @param argc [in] Arg count. * @param argc [in] Arg count.
* @param argv [in] Takes one argument: the Device Instance #. * @param argv [in] Takes one argument: the Device Instance #.
@@ -397,7 +396,6 @@ int main(int argc, char *argv[])
datalink_maintenance_timer(elapsed_seconds); datalink_maintenance_timer(elapsed_seconds);
dlenv_maintenance_timer(elapsed_seconds); dlenv_maintenance_timer(elapsed_seconds);
handler_cov_timer_seconds(elapsed_seconds); handler_cov_timer_seconds(elapsed_seconds);
Load_Control_State_Machine_Handler();
trend_log_timer(elapsed_seconds); trend_log_timer(elapsed_seconds);
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
Device_local_reporting(); Device_local_reporting();
+27
View File
@@ -1942,3 +1942,30 @@ const char *bactext_device_communications_name(unsigned index)
return indtext_by_index_default( return indtext_by_index_default(
bacnet_device_communications_names, index, ASHRAE_Reserved_String); bacnet_device_communications_names, index, ASHRAE_Reserved_String);
} }
INDTEXT_DATA bacnet_shed_state_names[] = {
{ BACNET_SHED_INACTIVE, "shed-inactive" },
{ BACNET_SHED_REQUEST_PENDING, "shed-request-pending" },
{ BACNET_SHED_COMPLIANT, "shed-compliant" },
{ BACNET_SHED_NON_COMPLIANT, "shed-non-compliant" },
{ 0, NULL }
};
const char *bactext_shed_state_name(unsigned index)
{
return indtext_by_index_default(
bacnet_shed_state_names, index, ASHRAE_Reserved_String);
}
INDTEXT_DATA bacnet_shed_level_type_names[] = {
{ BACNET_SHED_TYPE_PERCENT, "percent" },
{ BACNET_SHED_TYPE_LEVEL, "level" },
{ BACNET_SHED_TYPE_AMOUNT, "amount" },
{ 0, NULL }
};
const char *bactext_shed_level_type_name(unsigned index)
{
return indtext_by_index_default(
bacnet_shed_level_type_names, index, ASHRAE_Reserved_String);
}
+6
View File
@@ -206,6 +206,12 @@ extern "C" {
const char *bactext_color_operation_name( const char *bactext_color_operation_name(
unsigned index); unsigned index);
BACNET_STACK_EXPORT
const char *bactext_shed_state_name(unsigned index);
BACNET_STACK_EXPORT
const char *bactext_shed_level_type_name(unsigned index);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
+1 -1
View File
@@ -770,7 +770,7 @@ bool Binary_Input_Active_Text_Set(uint32_t object_instance, char *new_name)
#if defined(INTRINSIC_REPORTING) && (BINARY_INPUT_INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING) && (BINARY_INPUT_INTRINSIC_REPORTING)
/** /**
* @brief Encode a EventTimeStamps property element * @brief Encode a EventTimeStamps property element
* @param object_instance [in] BACnet network port object instance number * @param object_instance [in] BACnet object instance number
* @param index [in] array index requested: * @param index [in] array index requested:
* 0 to N for individual array members * 0 to N for individual array members
* @param apdu [out] Buffer in which the APDU contents are built, or NULL to * @param apdu [out] Buffer in which the APDU contents are built, or NULL to
+1 -1
View File
@@ -264,7 +264,7 @@ static object_functions_t My_Object_Table[] = {
NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */, NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */,
NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */, NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */,
NULL /* Add_List_Element */, NULL /* Remove_List_Element */, NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
NULL /* Create */, NULL /* Delete */, NULL /* Timer */ }, Load_Control_Create, Load_Control_Delete, Load_Control_Timer},
{ OBJECT_MULTI_STATE_INPUT, Multistate_Input_Init, Multistate_Input_Count, { OBJECT_MULTI_STATE_INPUT, Multistate_Input_Init, Multistate_Input_Count,
Multistate_Input_Index_To_Instance, Multistate_Input_Valid_Instance, Multistate_Input_Index_To_Instance, Multistate_Input_Valid_Instance,
Multistate_Input_Object_Name, Multistate_Input_Read_Property, Multistate_Input_Object_Name, Multistate_Input_Read_Property,
+1150 -670
View File
File diff suppressed because it is too large Load Diff
+129 -65
View File
@@ -16,83 +16,147 @@
#include "bacnet/rp.h" #include "bacnet/rp.h"
#include "bacnet/wp.h" #include "bacnet/wp.h"
typedef enum bacnet_load_control_state { typedef struct shed_level_data {
SHED_INACTIVE, /* Represents the shed levels for the LEVEL choice of
SHED_REQUEST_PENDING, BACnetShedLevel that have meaning for this particular
SHED_NON_COMPLIANT, Load Control object. We use 'percent' of baseline. */
SHED_COMPLIANT, float Value;
MAX_LOAD_CONTROL_STATE const char *Description;
} BACNET_LOAD_CONTROL_STATE; } BACNET_SHED_LEVEL_DATA;
/**
* @brief Callback for manipulated object controlled value write
* @param object_type - object type of the manipulated object
* @param object_instance - object-instance number of the object
* @param property_id - property identifier of the manipulated object
* @param priority - priority of the write
* @param value - value of the write
*/
typedef void (*load_control_manipulated_object_write_callback)(
BACNET_OBJECT_TYPE object_type,
uint32_t object_instance,
BACNET_PROPERTY_ID property_id,
uint8_t priority,
float value);
/**
* @brief Callback for manipulated object controlled value relinquish
* @param object_type - object type of the manipulated object
* @param object_instance - object-instance number of the object
* @param property_id - property identifier of the manipulated object
* @param priority - priority of the relinquish
*/
typedef void (*load_control_manipulated_object_relinquish_callback)(
BACNET_OBJECT_TYPE object_type,
uint32_t object_instance,
BACNET_PROPERTY_ID property_id,
uint8_t priority);
/**
* @brief Callback for manipulated object controlled value read
* @param object_type - object type of the manipulated object
* @param object_instance - object-instance number of the object
* @param property_id - property identifier of the manipulated object
* @param priority - present priority of the object property
* @param value - present value of the object property
*/
typedef void (*load_control_manipulated_object_read_callback)(
BACNET_OBJECT_TYPE object_type,
uint32_t object_instance,
BACNET_PROPERTY_ID property_id,
uint8_t *priority,
float *value);
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
BACNET_STACK_EXPORT BACNET_STACK_EXPORT
void Load_Control_Property_Lists( void Load_Control_Property_Lists(
const int **pRequired, const int **pRequired, const int **pOptional, const int **pProprietary);
const int **pOptional,
const int **pProprietary);
BACNET_STACK_EXPORT
void Load_Control_State_Machine_Handler(
void);
BACNET_STACK_EXPORT BACNET_STACK_DEPRECATED("Use Load_Control_Timer() instead")
bool Load_Control_Valid_Instance( BACNET_STACK_EXPORT
uint32_t object_instance); void Load_Control_State_Machine_Handler(void);
BACNET_STACK_EXPORT
unsigned Load_Control_Count(
void);
BACNET_STACK_EXPORT
uint32_t Load_Control_Index_To_Instance(
unsigned index);
BACNET_STACK_EXPORT
unsigned Load_Control_Instance_To_Index(
uint32_t object_instance);
BACNET_STACK_EXPORT BACNET_STACK_EXPORT
bool Load_Control_Object_Name( bool Load_Control_Valid_Instance(uint32_t object_instance);
uint32_t object_instance, BACNET_STACK_EXPORT
BACNET_CHARACTER_STRING * object_name); unsigned Load_Control_Count(void);
BACNET_STACK_EXPORT
uint32_t Load_Control_Index_To_Instance(unsigned index);
BACNET_STACK_EXPORT
unsigned Load_Control_Instance_To_Index(uint32_t object_instance);
BACNET_STACK_EXPORT BACNET_STACK_EXPORT
void Load_Control_Init( bool Load_Control_Object_Name(
void); uint32_t object_instance, BACNET_CHARACTER_STRING *object_name);
BACNET_STACK_EXPORT
bool Load_Control_Name_Set(uint32_t object_instance, char *new_name);
BACNET_STACK_EXPORT BACNET_STACK_EXPORT
unsigned Load_Control_Priority_For_Writing( BACNET_SHED_STATE Load_Control_Present_Value(uint32_t object_instance);
uint32_t object_instance);
BACNET_STACK_EXPORT
bool Load_Control_Priority_For_Writing_Set(
uint32_t object_instance, unsigned priority);
BACNET_STACK_EXPORT
bool Load_Control_Manipulated_Variable_Reference(
uint32_t object_instance,
BACNET_OBJECT_PROPERTY_REFERENCE * object_property_reference);
BACNET_STACK_EXPORT
bool Load_Control_Manipulated_Variable_Reference_Set(
uint32_t object_instance,
BACNET_OBJECT_PROPERTY_REFERENCE * object_property_reference);
BACNET_STACK_EXPORT BACNET_STACK_EXPORT
int Load_Control_Read_Property( bool Load_Control_Shed_Level_Array_Set(
BACNET_READ_PROPERTY_DATA * rpdata); uint32_t object_instance,
uint32_t array_index,
struct shed_level_data *value);
BACNET_STACK_EXPORT
bool Load_Control_Shed_Level_Array(
uint32_t object_instance,
uint32_t array_entry,
struct shed_level_data *value);
BACNET_STACK_EXPORT BACNET_STACK_EXPORT
bool Load_Control_Write_Property( uint32_t Load_Control_Create(uint32_t object_instance);
BACNET_WRITE_PROPERTY_DATA * wp_data); BACNET_STACK_EXPORT
bool Load_Control_Delete(uint32_t object_instance);
BACNET_STACK_EXPORT
void Load_Control_Cleanup(void);
/* functions used for unit testing */ BACNET_STACK_EXPORT
BACNET_STACK_EXPORT void Load_Control_Init(void);
void Load_Control_State_Machine(
int object_index, BACNET_STACK_EXPORT
BACNET_DATE_TIME *bdatetime); unsigned Load_Control_Priority_For_Writing(uint32_t object_instance);
BACNET_STACK_EXPORT BACNET_STACK_EXPORT
BACNET_LOAD_CONTROL_STATE Load_Control_State( bool Load_Control_Priority_For_Writing_Set(
int object_index); uint32_t object_instance, unsigned priority);
BACNET_STACK_EXPORT
BACNET_OBJECT_ID Load_Control_Object_ID( BACNET_STACK_EXPORT
int object_index); bool Load_Control_Manipulated_Variable_Reference(
uint32_t object_instance,
BACNET_OBJECT_PROPERTY_REFERENCE *object_property_reference);
BACNET_STACK_EXPORT
bool Load_Control_Manipulated_Variable_Reference_Set(
uint32_t object_instance,
BACNET_OBJECT_PROPERTY_REFERENCE *object_property_reference);
BACNET_STACK_EXPORT
void Load_Control_Manipulated_Object_Write_Callback_Set(
uint32_t object_instance,
load_control_manipulated_object_write_callback cb);
BACNET_STACK_EXPORT
void Load_Control_Manipulated_Object_Relinquish_Callback_Set(
uint32_t object_instance,
load_control_manipulated_object_relinquish_callback cb);
BACNET_STACK_EXPORT
void Load_Control_Manipulated_Object_Read_Callback_Set(
uint32_t object_instance, load_control_manipulated_object_read_callback cb);
BACNET_STACK_EXPORT
void Load_Control_Timer(uint32_t object_instance, uint16_t milliseconds);
BACNET_STACK_EXPORT
int Load_Control_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata);
BACNET_STACK_EXPORT
bool Load_Control_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data);
/* functions used for unit testing */
BACNET_STACK_EXPORT
void Load_Control_State_Machine(int object_index, BACNET_DATE_TIME *bdatetime);
#ifdef __cplusplus #ifdef __cplusplus
} }
+9 -9
View File
@@ -2385,20 +2385,20 @@ Lighting_Output_Ramp_Handler(uint32_t object_instance, uint16_t milliseconds)
debug_printf("LO[%u] Ramp Handler at target=%f tracking=%f\n", debug_printf("LO[%u] Ramp Handler at target=%f tracking=%f\n",
object_instance, (double)target_value, (double)old_value); object_instance, (double)target_value, (double)old_value);
/* stop ramping */ /* stop ramping */
step_value = target_value;
pObject->Lighting_Command.operation = BACNET_LIGHTS_STOP; pObject->Lighting_Command.operation = BACNET_LIGHTS_STOP;
} }
/* clamp target within min/max, if needed */
if (isgreater(step_value, max_value)) {
step_value = max_value;
}
if (isless(step_value, min_value)) {
step_value = min_value;
}
pObject->Tracking_Value = step_value;
if (pObject->Lighting_Command.operation == BACNET_LIGHTS_STOP) { if (pObject->Lighting_Command.operation == BACNET_LIGHTS_STOP) {
pObject->Tracking_Value = target_value;
pObject->In_Progress = BACNET_LIGHTING_IDLE; pObject->In_Progress = BACNET_LIGHTING_IDLE;
} else { } else {
/* clamp target within min/max, if needed */
if (isgreater(step_value, max_value)) {
step_value = max_value;
}
if (isless(step_value, min_value)) {
step_value = min_value;
}
pObject->Tracking_Value = step_value;
pObject->In_Progress = BACNET_LIGHTING_RAMP_ACTIVE; pObject->In_Progress = BACNET_LIGHTING_RAMP_ACTIVE;
} }
} }
+1 -1
View File
@@ -88,7 +88,7 @@ extern "C" {
OS_Keylist list, OS_Keylist list,
KEY key); KEY key);
/* returns the data specified by key */ /* returns the data specified by index */
BACNET_STACK_EXPORT BACNET_STACK_EXPORT
void *Keylist_Data_Index( void *Keylist_Data_Index(
OS_Keylist list, OS_Keylist list,
+1 -1
View File
@@ -19,7 +19,7 @@ if (CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "GNU")
add_compile_options(-Wall -Wextra -pedantic) add_compile_options(-Wall -Wextra -pedantic)
add_compile_options(-Wfloat-equal -Wconversion) add_compile_options(-Wfloat-equal -Wconversion)
add_compile_options(-Wredundant-decls -Wswitch-default) add_compile_options(-Wredundant-decls -Wswitch-default)
add_compile_options(-Wunused-variable) add_compile_options(-Wunused-variable -Wdouble-promotion)
# don't warn about conversion, sign, compares, long long and attributes # don't warn about conversion, sign, compares, long long and attributes
# since they are common in embedded # since they are common in embedded
add_compile_options(-Wno-sign-conversion -Wno-conversion) add_compile_options(-Wno-sign-conversion -Wno-conversion)
+420 -230
View File
@@ -31,27 +31,6 @@
* @brief Test * @brief Test
*/ */
#if defined(CONFIG_ZTEST_NEW_API)
ZTEST(lc_tests, test_Load_Control_Count)
#else
static void test_Load_Control_Count(void)
#endif
{
/* Verify the same value is returned on successive calls without init */
zassert_equal(Load_Control_Count(), MAX_LOAD_CONTROLS, NULL);
zassert_equal(Load_Control_Count(), MAX_LOAD_CONTROLS, NULL);
/* Verify the same value is returned on successive calls with init */
Load_Control_Init();
zassert_equal(Load_Control_Count(), MAX_LOAD_CONTROLS, NULL);
zassert_equal(Load_Control_Count(), MAX_LOAD_CONTROLS, NULL);
/* Verify the same value is returned on successive calls with re-init */
Load_Control_Init();
zassert_equal(Load_Control_Count(), MAX_LOAD_CONTROLS, NULL);
zassert_equal(Load_Control_Count(), MAX_LOAD_CONTROLS, NULL);
}
static void static void
Load_Control_WriteProperty_Request_Shed_Level(int instance, unsigned level) Load_Control_WriteProperty_Request_Shed_Level(int instance, unsigned level)
{ {
@@ -71,7 +50,7 @@ Load_Control_WriteProperty_Request_Shed_Level(int instance, unsigned level)
wp_data.object_property); wp_data.object_property);
zassert_true(wp_data.application_data_len > 0, NULL); zassert_true(wp_data.application_data_len > 0, NULL);
status = Load_Control_Write_Property(&wp_data); status = Load_Control_Write_Property(&wp_data);
zassert_true(status, NULL); zassert_true(status, "LC=%lu level=%u", instance, level);
} }
static void Load_Control_WriteProperty_Enable(int instance, bool enable) static void Load_Control_WriteProperty_Enable(int instance, bool enable)
@@ -200,248 +179,459 @@ static void Load_Control_WriteProperty_Start_Time(
zassert_true(status, NULL); zassert_true(status, NULL);
} }
/**
* Test object for the Load Control object manipulation
*/
struct object_data {
bool Relinquished[BACNET_MAX_PRIORITY];
float Priority_Array[BACNET_MAX_PRIORITY];
float Relinquish_Default;
} Test_Object_Data;
/**
* @brief For a given object instance-number, determines the present-value
* @param object_instance - object-instance number of the object
* @return present-value of the object
*/
static float Test_Present_Value(void)
{
float value;
uint8_t priority;
value = Test_Object_Data.Relinquish_Default;
for (priority = 0; priority < BACNET_MAX_PRIORITY; priority++) {
if (!Test_Object_Data.Relinquished[priority]) {
value = Test_Object_Data.Priority_Array[priority];
break;
}
}
return value;
}
/**
* @brief For a given object instance-number, determines the priority
* @param object_instance - object-instance number of the object
* @return active priority 1..16, or 0 if no priority is active
*/
static unsigned Test_Present_Value_Priority(void)
{
unsigned p = 0; /* loop counter */
unsigned priority = 0; /* return value */
for (p = 0; p < BACNET_MAX_PRIORITY; p++) {
if (!Test_Object_Data.Relinquished[p]) {
priority = p + 1;
break;
}
}
return priority;
}
/**
* @brief For a given object instance-number, sets the present-value
* @param object_instance - object-instance number of the object
* @param value - floating point analog value
* @param priority - priority-array index value 1..16
* @return true if values are within range and present-value is set.
*/
static bool Test_Present_Value_Priority_Set(float value, unsigned priority)
{
bool status = false;
if ((priority >= 1) && (priority <= BACNET_MAX_PRIORITY)) {
Test_Object_Data.Relinquished[priority - 1] = false;
Test_Object_Data.Priority_Array[priority - 1] = value;
status = true;
}
return status;
}
/**
* @brief For a given object instance-number, relinquishes the present-value
* @param object_instance - object-instance number of the object
* @param priority - priority-array index value 1..16
* @return true if values are within range and present-value is relinquished.
*/
static bool Test_Present_Value_Priority_Relinquish(
unsigned priority)
{
bool status = false;
if ((priority >= 1) && (priority <= BACNET_MAX_PRIORITY)) {
Test_Object_Data.Relinquished[priority - 1] = true;
Test_Object_Data.Priority_Array[priority - 1] = 0.0;
status = true;
}
return status;
}
static BACNET_OBJECT_PROPERTY_REFERENCE test_object_property_reference;
static void test_load_control_manipulated_object_read(
BACNET_OBJECT_TYPE object_type,
uint32_t object_instance,
BACNET_PROPERTY_ID property_id,
uint8_t *priority,
float *value)
{
zassert_equal(
test_object_property_reference.object_identifier.type, object_type,
NULL);
zassert_equal(
test_object_property_reference.object_identifier.instance,
object_instance, NULL);
zassert_equal(
test_object_property_reference.property_identifier, property_id, NULL);
if (priority) {
*priority = Test_Present_Value_Priority();
}
if (value) {
*value = Test_Present_Value();
}
}
/**
* @brief Callback for manipulated object controlled value write
* @param object_type - object type of the manipulated object
* @param object_instance - object-instance number of the object
* @param property_id - property identifier of the manipulated object
* @param priority - priority of the write
* @param value - value of the write
*/
static void test_load_control_manipulated_object_write(
BACNET_OBJECT_TYPE object_type,
uint32_t object_instance,
BACNET_PROPERTY_ID property_id,
uint8_t priority,
float value)
{
zassert_equal(
test_object_property_reference.object_identifier.type, object_type,
NULL);
zassert_equal(
test_object_property_reference.object_identifier.instance,
object_instance, NULL);
zassert_equal(
test_object_property_reference.property_identifier, property_id, NULL);
Test_Present_Value_Priority_Set(value, priority);
}
/**
* @brief Callback for manipulated object controlled value relinquish
* @param object_type - object type of the manipulated object
* @param object_instance - object-instance number of the object
* @param property_id - property identifier of the manipulated object
* @param priority - priority of the relinquish
*/
static void test_load_control_manipulated_object_relinquish(
BACNET_OBJECT_TYPE object_type,
uint32_t object_instance,
BACNET_PROPERTY_ID property_id,
uint8_t priority)
{
zassert_equal(
test_object_property_reference.object_identifier.type, object_type,
NULL);
zassert_equal(
test_object_property_reference.object_identifier.instance,
object_instance, NULL);
zassert_equal(
test_object_property_reference.property_identifier, property_id, NULL);
Test_Present_Value_Priority_Relinquish(priority);
}
static void test_setup(uint32_t object_instance)
{
uint32_t test_object_instance = 0;
unsigned priority = 0;
Load_Control_Init();
test_object_instance = Load_Control_Create(object_instance);
zassert_equal(test_object_instance, object_instance, NULL);
test_object_instance = Load_Control_Index_To_Instance(0);
zassert_equal(test_object_instance, object_instance, NULL);
/* manipulated object */
test_object_property_reference.object_identifier.type =
OBJECT_ANALOG_OUTPUT;
test_object_property_reference.object_identifier.instance = 1;
test_object_property_reference.property_identifier = PROP_PRESENT_VALUE;
Load_Control_Manipulated_Variable_Reference_Set(
object_instance, &test_object_property_reference);
Load_Control_Manipulated_Object_Write_Callback_Set(
object_instance, test_load_control_manipulated_object_write);
Load_Control_Manipulated_Object_Relinquish_Callback_Set(
object_instance, test_load_control_manipulated_object_relinquish);
Load_Control_Manipulated_Object_Read_Callback_Set(
object_instance, test_load_control_manipulated_object_read);
/* target object */
for (priority = 1; priority <= BACNET_MAX_PRIORITY; priority++) {
Test_Present_Value_Priority_Relinquish(priority);
}
Test_Present_Value_Priority_Set(0.0f, 16);
Load_Control_Priority_For_Writing_Set(object_instance, 4);
}
static void test_teardown(uint32_t object_instance)
{
bool status = false;
status = Load_Control_Delete(object_instance);
zassert_true(status, NULL);
Load_Control_Cleanup();
}
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST(lc_tests, testLoadControlStateMachine) ZTEST(lc_tests, testLoadControlStateMachine)
#else #else
static void testLoadControlStateMachine(void) static void testLoadControlStateMachine(void)
#endif #endif
{ {
unsigned i = 0, j = 0; unsigned j = 0, priority = 0;
float level = 0; float level = 0;
unsigned count = 0; unsigned count = 0;
BACNET_DATE_TIME bdatetime = { 0 }; BACNET_DATE_TIME bdatetime = { 0 };
uint32_t object_instance = 0; uint32_t object_index = 0;
uint32_t object_instance = 1234;
BACNET_OBJECT_PROPERTY_REFERENCE object_property_reference; BACNET_OBJECT_PROPERTY_REFERENCE object_property_reference;
bool status; bool status;
Analog_Output_Init(); test_setup(object_instance);
Load_Control_Init(); status = Load_Control_Valid_Instance(object_instance);
object_instance = Load_Control_Index_To_Instance(0); zassert_true(status, NULL);
/* validate the triggers for each state change */ Load_Control_Manipulated_Variable_Reference(
object_instance, &object_property_reference);
zassert_equal(
object_property_reference.object_identifier.type,
test_object_property_reference.object_identifier.type, NULL);
zassert_equal(
object_property_reference.object_identifier.instance,
test_object_property_reference.object_identifier.instance, NULL);
zassert_equal(
object_property_reference.property_identifier,
test_object_property_reference.property_identifier, NULL);
/* validate the state does not change - without any triggers */
for (j = 0; j < 20; j++) { for (j = 0; j < 20; j++) {
Load_Control_State_Machine(0, &bdatetime); Load_Control_State_Machine(object_index, &bdatetime);
count = Load_Control_Count(); count = Load_Control_Count();
for (i = 0; i < count; i++) { zassert_equal(count, 1, NULL);
zassert_equal(Load_Control_State(i), SHED_INACTIVE, NULL); zassert_equal(
} Load_Control_Present_Value(object_instance), BACNET_SHED_INACTIVE,
NULL);
} }
/* SHED_REQUEST_PENDING */ /* BACNET_SHED_REQUEST_PENDING */
/* CancelShed - Start time has wildcards */ /* CancelShed - Start time has wildcards */
Load_Control_WriteProperty_Enable(0, true); Load_Control_WriteProperty_Enable(object_instance, true);
Load_Control_WriteProperty_Shed_Duration(0, 60); Load_Control_WriteProperty_Shed_Duration(object_instance, 60);
Load_Control_WriteProperty_Start_Time_Wildcards(0); Load_Control_WriteProperty_Start_Time_Wildcards(object_instance);
Load_Control_State_Machine(0, &bdatetime); Load_Control_State_Machine(object_index, &bdatetime);
zassert_equal(Load_Control_State(0), SHED_REQUEST_PENDING, NULL); zassert_equal(
Load_Control_State_Machine(0, &bdatetime); Load_Control_Present_Value(object_instance),
zassert_equal(Load_Control_State(0), SHED_INACTIVE, NULL); BACNET_SHED_REQUEST_PENDING, NULL);
Load_Control_State_Machine(object_index, &bdatetime);
zassert_equal(
Load_Control_Present_Value(object_instance), BACNET_SHED_INACTIVE,
NULL);
test_teardown(object_instance);
/* CancelShed - Requested_Shed_Level equal to default value */ /* CancelShed - Requested_Shed_Level equal to default value */
Load_Control_Init(); test_setup(object_instance);
Load_Control_WriteProperty_Request_Shed_Level(0, 0); status = Load_Control_Valid_Instance(object_instance);
Load_Control_WriteProperty_Start_Time(0, 2007, 2, 27, 15, 0, 0, 0); zassert_true(status, NULL);
Load_Control_WriteProperty_Shed_Duration(0, 5); Load_Control_WriteProperty_Request_Shed_Level(object_instance, 0);
Load_Control_WriteProperty_Start_Time(
object_instance, 2007, 2, 27, 15, 0, 0, 0);
Load_Control_WriteProperty_Shed_Duration(object_instance, 5);
datetime_set_values(&bdatetime, 2007, 2, 27, 15, 0, 0, 0); datetime_set_values(&bdatetime, 2007, 2, 27, 15, 0, 0, 0);
Load_Control_State_Machine(0, &bdatetime); Load_Control_State_Machine(object_index, &bdatetime);
zassert_equal(Load_Control_State(0), SHED_REQUEST_PENDING, NULL); zassert_equal(
Load_Control_State_Machine(0, &bdatetime); Load_Control_Present_Value(object_instance),
zassert_equal(Load_Control_State(0), SHED_INACTIVE, NULL); BACNET_SHED_REQUEST_PENDING, NULL);
Load_Control_State_Machine(object_index, &bdatetime);
zassert_equal(
Load_Control_Present_Value(object_instance), BACNET_SHED_INACTIVE,
NULL);
test_teardown(object_instance);
/* CancelShed - Non-default values, but Start time is passed */ /* CancelShed - Non-default values, but Start time is passed */
Load_Control_Init(); test_setup(object_instance);
Load_Control_WriteProperty_Enable(0, true); status = Load_Control_Valid_Instance(object_instance);
Load_Control_WriteProperty_Request_Shed_Level(0, 1); zassert_true(status, NULL);
Load_Control_WriteProperty_Shed_Duration(0, 5); Load_Control_WriteProperty_Enable(object_instance, true);
Load_Control_WriteProperty_Start_Time(0, 2007, 2, 27, 15, 0, 0, 0); Load_Control_WriteProperty_Request_Shed_Level(object_instance, 1);
Load_Control_WriteProperty_Shed_Duration(object_instance, 5);
Load_Control_WriteProperty_Start_Time(
object_instance, 2007, 2, 27, 15, 0, 0, 0);
datetime_set_values(&bdatetime, 2007, 2, 28, 15, 0, 0, 0); datetime_set_values(&bdatetime, 2007, 2, 28, 15, 0, 0, 0);
Load_Control_State_Machine(0, &bdatetime); Load_Control_State_Machine(object_index, &bdatetime);
zassert_equal(Load_Control_State(0), SHED_REQUEST_PENDING, NULL); zassert_equal(
Load_Control_State_Machine(0, &bdatetime); Load_Control_Present_Value(object_instance),
zassert_equal(Load_Control_State(0), SHED_INACTIVE, NULL); BACNET_SHED_REQUEST_PENDING, NULL);
Load_Control_State_Machine(object_index, &bdatetime);
zassert_equal(
Load_Control_Present_Value(object_instance), BACNET_SHED_INACTIVE,
NULL);
test_teardown(object_instance);
/* ReconfigurePending - new write received while pending */ /* ReconfigurePending - new write received while pending */
Load_Control_Init(); test_setup(object_instance);
Load_Control_WriteProperty_Enable(0, true); status = Load_Control_Valid_Instance(object_instance);
Load_Control_WriteProperty_Request_Shed_Level(0, 1); zassert_true(status, NULL);
Load_Control_WriteProperty_Shed_Duration(0, 5); Load_Control_WriteProperty_Enable(object_instance, true);
Load_Control_WriteProperty_Start_Time(0, 2007, 2, 27, 15, 0, 0, 0); Load_Control_WriteProperty_Request_Shed_Level(object_instance, 1);
Load_Control_WriteProperty_Shed_Duration(object_instance, 5);
Load_Control_WriteProperty_Start_Time(
object_instance, 2007, 2, 27, 15, 0, 0, 0);
datetime_set_values(&bdatetime, 2007, 2, 27, 5, 0, 0, 0); datetime_set_values(&bdatetime, 2007, 2, 27, 5, 0, 0, 0);
Load_Control_State_Machine(0, &bdatetime); Load_Control_State_Machine(object_index, &bdatetime);
zassert_equal(Load_Control_State(0), SHED_REQUEST_PENDING, NULL); zassert_equal(
Load_Control_State_Machine(0, &bdatetime); Load_Control_Present_Value(object_instance),
zassert_equal(Load_Control_State(0), SHED_REQUEST_PENDING, NULL); BACNET_SHED_REQUEST_PENDING, NULL);
Load_Control_WriteProperty_Request_Shed_Level(0, 2); Load_Control_State_Machine(object_index, &bdatetime);
Load_Control_State_Machine(0, &bdatetime); zassert_equal(
zassert_equal(Load_Control_State(0), SHED_REQUEST_PENDING, NULL); Load_Control_Present_Value(object_instance),
Load_Control_WriteProperty_Shed_Duration(0, 6); BACNET_SHED_REQUEST_PENDING, NULL);
Load_Control_State_Machine(0, &bdatetime); Load_Control_WriteProperty_Request_Shed_Level(object_instance, 2);
zassert_equal(Load_Control_State(0), SHED_REQUEST_PENDING, NULL); Load_Control_State_Machine(object_index, &bdatetime);
Load_Control_WriteProperty_Duty_Window(0, 60); zassert_equal(
Load_Control_State_Machine(0, &bdatetime); Load_Control_Present_Value(object_instance),
zassert_equal(Load_Control_State(0), SHED_REQUEST_PENDING, NULL); BACNET_SHED_REQUEST_PENDING, NULL);
Load_Control_WriteProperty_Start_Time(0, 2007, 2, 27, 15, 0, 0, 1); Load_Control_WriteProperty_Shed_Duration(object_instance, 6);
Load_Control_State_Machine(0, &bdatetime); Load_Control_State_Machine(object_index, &bdatetime);
zassert_equal(Load_Control_State(0), SHED_REQUEST_PENDING, NULL); zassert_equal(
Load_Control_State_Machine(0, &bdatetime); Load_Control_Present_Value(object_instance),
zassert_equal(Load_Control_State(0), SHED_REQUEST_PENDING, NULL); BACNET_SHED_REQUEST_PENDING, NULL);
Load_Control_State_Machine(0, &bdatetime); Load_Control_WriteProperty_Duty_Window(object_instance, 60);
zassert_equal(Load_Control_State(0), SHED_REQUEST_PENDING, NULL); Load_Control_State_Machine(object_index, &bdatetime);
zassert_equal(
Load_Control_Present_Value(object_instance),
BACNET_SHED_REQUEST_PENDING, NULL);
Load_Control_WriteProperty_Start_Time(
object_instance, 2007, 2, 27, 15, 0, 0, 1);
Load_Control_State_Machine(object_index, &bdatetime);
zassert_equal(
Load_Control_Present_Value(object_instance),
BACNET_SHED_REQUEST_PENDING, NULL);
Load_Control_State_Machine(object_index, &bdatetime);
zassert_equal(
Load_Control_Present_Value(object_instance),
BACNET_SHED_REQUEST_PENDING, NULL);
Load_Control_State_Machine(object_index, &bdatetime);
zassert_equal(
Load_Control_Present_Value(object_instance),
BACNET_SHED_REQUEST_PENDING, NULL);
test_teardown(object_instance);
/* CannotMeetShed -> FinishedUnsuccessfulShed */ /* CannotMeetShed -> FinishedUnsuccessfulShed */
Load_Control_Init(); test_setup(object_instance);
Load_Control_WriteProperty_Enable(0, true); status = Load_Control_Valid_Instance(object_instance);
Load_Control_WriteProperty_Request_Shed_Level(0, 1); zassert_true(status, NULL);
Load_Control_WriteProperty_Shed_Duration(0, 120); Load_Control_WriteProperty_Enable(object_instance, true);
Load_Control_WriteProperty_Start_Time(0, 2007, 2, 27, 15, 0, 0, 0); Load_Control_WriteProperty_Request_Shed_Level(object_instance, 1);
Load_Control_WriteProperty_Shed_Duration(object_instance, 120);
Load_Control_WriteProperty_Start_Time(
object_instance, 2007, 2, 27, 15, 0, 0, 0);
datetime_set_values(&bdatetime, 2007, 2, 27, 5, 0, 0, 0); datetime_set_values(&bdatetime, 2007, 2, 27, 5, 0, 0, 0);
Load_Control_State_Machine(0, &bdatetime); Load_Control_State_Machine(object_index, &bdatetime);
zassert_equal(Load_Control_State(0), SHED_REQUEST_PENDING, NULL); zassert_equal(
Load_Control_State_Machine(0, &bdatetime); Load_Control_Present_Value(object_instance),
zassert_equal(Load_Control_State(0), SHED_REQUEST_PENDING, NULL); BACNET_SHED_REQUEST_PENDING, NULL);
Load_Control_State_Machine(object_index, &bdatetime);
zassert_equal(
Load_Control_Present_Value(object_instance),
BACNET_SHED_REQUEST_PENDING, NULL);
/* set to lowest value so we cannot meet the shed level */ /* set to lowest value so we cannot meet the shed level */
datetime_set_values(&bdatetime, 2007, 2, 27, 16, 0, 0, 0); datetime_set_values(&bdatetime, 2007, 2, 27, 16, 0, 0, 0);
Test_Present_Value_Priority_Set(0.0f, 16);
Load_Control_Manipulated_Variable_Reference( Load_Control_State_Machine(object_index, &bdatetime);
object_instance, &object_property_reference); zassert_equal(
if ((object_property_reference.object_identifier.type == Load_Control_Present_Value(object_instance), BACNET_SHED_NON_COMPLIANT,
OBJECT_ANALOG_OUTPUT) && NULL);
(object_property_reference.property_identifier == PROP_PRESENT_VALUE)) { Load_Control_State_Machine(object_index, &bdatetime);
status = Analog_Output_Present_Value_Set( zassert_equal(
object_property_reference.object_identifier.instance, 0.0f, Load_Control_Present_Value(object_instance), BACNET_SHED_NON_COMPLIANT,
BACNET_MAX_PRIORITY); NULL);
zassert_true(status, NULL);
} else {
zassert_true(false, NULL);
}
Load_Control_State_Machine(0, &bdatetime);
zassert_equal(Load_Control_State(0), SHED_NON_COMPLIANT, NULL);
Load_Control_State_Machine(0, &bdatetime);
zassert_equal(Load_Control_State(0), SHED_NON_COMPLIANT, NULL);
/* FinishedUnsuccessfulShed */ /* FinishedUnsuccessfulShed */
datetime_set_values(&bdatetime, 2007, 2, 27, 23, 0, 0, 0); datetime_set_values(&bdatetime, 2007, 2, 27, 23, 0, 0, 0);
Load_Control_State_Machine(0, &bdatetime); Load_Control_State_Machine(object_index, &bdatetime);
zassert_equal(Load_Control_State(0), SHED_INACTIVE, NULL); zassert_equal(
Load_Control_Present_Value(object_instance), BACNET_SHED_INACTIVE,
NULL);
test_teardown(object_instance);
/* CannotMeetShed -> UnsuccessfulShedReconfigured */ /* CannotMeetShed -> UnsuccessfulShedReconfigured */
Load_Control_Init(); test_setup(object_instance);
Load_Control_WriteProperty_Enable(0, true); status = Load_Control_Valid_Instance(object_instance);
Load_Control_WriteProperty_Request_Shed_Level(0, 1); zassert_true(status, NULL);
Load_Control_WriteProperty_Shed_Duration(0, 120); Load_Control_WriteProperty_Enable(object_instance, true);
Load_Control_WriteProperty_Start_Time(0, 2007, 2, 27, 15, 0, 0, 0); Load_Control_WriteProperty_Request_Shed_Level(object_instance, 1);
Load_Control_WriteProperty_Shed_Duration(object_instance, 120);
Load_Control_WriteProperty_Start_Time(
object_instance, 2007, 2, 27, 15, 0, 0, 0);
datetime_set_values(&bdatetime, 2007, 2, 27, 5, 0, 0, 0); datetime_set_values(&bdatetime, 2007, 2, 27, 5, 0, 0, 0);
Load_Control_State_Machine(0, &bdatetime); Load_Control_State_Machine(object_index, &bdatetime);
zassert_equal(Load_Control_State(0), SHED_REQUEST_PENDING, NULL); zassert_equal(
Load_Control_State_Machine(0, &bdatetime); Load_Control_Present_Value(object_instance),
zassert_equal(Load_Control_State(0), SHED_REQUEST_PENDING, NULL); BACNET_SHED_REQUEST_PENDING, NULL);
Load_Control_State_Machine(object_index, &bdatetime);
zassert_equal(
Load_Control_Present_Value(object_instance),
BACNET_SHED_REQUEST_PENDING, NULL);
/* set to lowest value so we cannot meet the shed level */ /* set to lowest value so we cannot meet the shed level */
datetime_set_values(&bdatetime, 2007, 2, 27, 16, 0, 0, 0); datetime_set_values(&bdatetime, 2007, 2, 27, 16, 0, 0, 0);
Load_Control_Manipulated_Variable_Reference( Test_Present_Value_Priority_Set(0.0f, 16);
object_instance, &object_property_reference); Load_Control_State_Machine(object_index, &bdatetime);
if ((object_property_reference.object_identifier.type == zassert_equal(
OBJECT_ANALOG_OUTPUT) && Load_Control_Present_Value(object_instance), BACNET_SHED_NON_COMPLIANT,
(object_property_reference.property_identifier == PROP_PRESENT_VALUE)) { NULL);
status = Analog_Output_Present_Value_Set( Load_Control_State_Machine(object_index, &bdatetime);
object_property_reference.object_identifier.instance, 0.0f, zassert_equal(
BACNET_MAX_PRIORITY); Load_Control_Present_Value(object_instance), BACNET_SHED_NON_COMPLIANT,
zassert_true(status, NULL); NULL);
} else {
zassert_true(false, NULL);
}
Load_Control_State_Machine(0, &bdatetime);
zassert_equal(Load_Control_State(0), SHED_NON_COMPLIANT, NULL);
Load_Control_State_Machine(0, &bdatetime);
zassert_equal(Load_Control_State(0), SHED_NON_COMPLIANT, NULL);
/* FinishedUnsuccessfulShed */ /* FinishedUnsuccessfulShed */
Load_Control_WriteProperty_Start_Time(0, 2007, 2, 27, 16, 0, 0, 0); Load_Control_WriteProperty_Start_Time(
Load_Control_State_Machine(0, &bdatetime); object_instance, 2007, 2, 27, 16, 0, 0, 0);
zassert_equal(Load_Control_State(0), SHED_REQUEST_PENDING, NULL); Load_Control_State_Machine(object_index, &bdatetime);
Load_Control_State_Machine(0, &bdatetime); zassert_equal(
zassert_equal(Load_Control_State(0), SHED_REQUEST_PENDING, NULL); Load_Control_Present_Value(object_instance),
BACNET_SHED_REQUEST_PENDING, NULL);
Load_Control_State_Machine(object_index, &bdatetime);
zassert_equal(
Load_Control_Present_Value(object_instance),
BACNET_SHED_REQUEST_PENDING, NULL);
datetime_set_values(&bdatetime, 2007, 2, 27, 16, 0, 1, 0); datetime_set_values(&bdatetime, 2007, 2, 27, 16, 0, 1, 0);
Load_Control_State_Machine(0, &bdatetime); Load_Control_State_Machine(object_index, &bdatetime);
zassert_equal(Load_Control_State(0), SHED_NON_COMPLIANT, NULL); zassert_equal(
Load_Control_Present_Value(object_instance), BACNET_SHED_NON_COMPLIANT,
NULL);
/* CanNowComplyWithShed */ /* CanNowComplyWithShed */
Load_Control_Manipulated_Variable_Reference( Test_Present_Value_Priority_Set(100.0f, 16);
object_instance, &object_property_reference);
if ((object_property_reference.object_identifier.type ==
OBJECT_ANALOG_OUTPUT) &&
(object_property_reference.property_identifier == PROP_PRESENT_VALUE)) {
status = Analog_Output_Present_Value_Set(
object_property_reference.object_identifier.instance, 100.0f,
BACNET_MAX_PRIORITY);
zassert_true(status, NULL);
} else {
zassert_true(false, NULL);
}
datetime_set_values(&bdatetime, 2007, 2, 27, 16, 0, 2, 0); datetime_set_values(&bdatetime, 2007, 2, 27, 16, 0, 2, 0);
Load_Control_State_Machine(0, &bdatetime); Load_Control_State_Machine(object_index, &bdatetime);
zassert_equal(Load_Control_State(0), SHED_COMPLIANT, NULL); zassert_equal(
Load_Control_Manipulated_Variable_Reference( Load_Control_Present_Value(object_instance), BACNET_SHED_COMPLIANT,
object_instance, &object_property_reference); NULL);
if ((object_property_reference.object_identifier.type == level = Test_Present_Value();
OBJECT_ANALOG_OUTPUT) && zassert_true(islessgreater(100.0f, level),
(object_property_reference.property_identifier == PROP_PRESENT_VALUE)) { "Present Value = %f", (double)level);
level = Analog_Output_Present_Value( priority = Test_Present_Value_Priority();
object_property_reference.object_identifier.instance); zassert_equal(
} else { Load_Control_Priority_For_Writing(object_instance), priority, NULL);
zassert_true(false, NULL);
}
zassert_false(islessgreater(90.0f, level), "AO Present Value = %f",
(double)level);
/* FinishedSuccessfulShed */ /* FinishedSuccessfulShed */
datetime_set_values(&bdatetime, 2007, 2, 27, 23, 0, 0, 0); datetime_set_values(&bdatetime, 2007, 2, 27, 23, 0, 0, 0);
Load_Control_State_Machine(0, &bdatetime); Load_Control_State_Machine(object_index, &bdatetime);
zassert_equal(Load_Control_State(0), SHED_INACTIVE, NULL);
if ((object_property_reference.object_identifier.type ==
OBJECT_ANALOG_OUTPUT) &&
(object_property_reference.property_identifier == PROP_PRESENT_VALUE)) {
level = Analog_Output_Present_Value(
object_property_reference.object_identifier.instance);
} else {
zassert_true(false, NULL);
}
zassert_false(islessgreater(100.0f, level), "AO Present Value = %f",
(double)level);
}
#ifndef MAX_LOAD_CONTROLS
#define MAX_LOAD_CONTROLS (4)
#endif
#if defined(CONFIG_ZTEST_NEW_API)
ZTEST(lc_tests, test_api_stubs)
#else
static void test_api_stubs(void)
#endif
{
BACNET_CHARACTER_STRING object_name_st = { 0 };
zassert_equal(Load_Control_Count(), MAX_LOAD_CONTROLS, NULL);
zassert_false(Load_Control_Valid_Instance(MAX_LOAD_CONTROLS), NULL);
zassert_equal( zassert_equal(
Load_Control_Index_To_Instance(MAX_LOAD_CONTROLS), Load_Control_Count(), Load_Control_Present_Value(object_instance), BACNET_SHED_INACTIVE,
NULL); NULL);
zassert_equal( level = Test_Present_Value();
Load_Control_Instance_To_Index(MAX_LOAD_CONTROLS), Load_Control_Count(), zassert_false(
NULL); islessgreater(100.0f, level), "Present Value = %f", (double)level);
priority = Test_Present_Value_Priority();
zassert_false(Load_Control_Valid_Instance(UINT32_MAX), NULL); zassert_equal(16, priority, NULL);
zassert_equal( test_teardown(object_instance);
Load_Control_Index_To_Instance(UINT32_MAX), Load_Control_Count(), NULL);
zassert_equal(
Load_Control_Instance_To_Index(UINT32_MAX), Load_Control_Count(), NULL);
zassert_true(Load_Control_Valid_Instance(0), NULL);
zassert_equal(Load_Control_Index_To_Instance(0), 0, NULL);
zassert_equal(Load_Control_Instance_To_Index(0), 0, NULL);
zassert_false(Load_Control_Object_Name(0, NULL), NULL);
zassert_false(Load_Control_Object_Name(UINT32_MAX, &object_name_st), NULL);
zassert_true(Load_Control_Object_Name(0, &object_name_st), NULL);
zassert_true(characterstring_valid(&object_name_st), NULL);
zassert_true(characterstring_printable(&object_name_st), NULL);
} }
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
@@ -451,19 +641,23 @@ static void test_Load_Control_Read_Write_Property(void)
#endif #endif
{ {
unsigned count = 0; unsigned count = 0;
uint32_t object_instance = BACNET_MAX_INSTANCE, test_object_instance = 0; uint32_t object_instance = 123;
unsigned index;
bool status = false;
const int skip_fail_property_list[] = { -1 }; const int skip_fail_property_list[] = { -1 };
object_instance = Load_Control_Index_To_Instance(0); test_setup(object_instance);
Load_Control_Init(); status = Load_Control_Valid_Instance(object_instance);
zassert_true(status, NULL);
index = Load_Control_Instance_To_Index(object_instance);
zassert_equal(index, 0, NULL);
count = Load_Control_Count(); count = Load_Control_Count();
zassert_true(count > 0, NULL); zassert_true(count == 1, NULL);
test_object_instance = Load_Control_Index_To_Instance(0);
zassert_equal(object_instance, test_object_instance, NULL);
bacnet_object_properties_read_write_test( bacnet_object_properties_read_write_test(
OBJECT_LOAD_CONTROL, object_instance, Load_Control_Property_Lists, OBJECT_LOAD_CONTROL, object_instance, Load_Control_Property_Lists,
Load_Control_Read_Property, Load_Control_Write_Property, Load_Control_Read_Property, Load_Control_Write_Property,
skip_fail_property_list); skip_fail_property_list);
test_teardown(object_instance);
} }
static bool init_wp_data_and_value( static bool init_wp_data_and_value(
@@ -510,7 +704,6 @@ static void test_ShedInactive_gets_RcvShedRequests(void)
/* Verify invalid parameter value of application_data_len cause failure */ /* Verify invalid parameter value of application_data_len cause failure */
zassert_true(init_wp_data_and_value(&wp_data, &value), NULL); zassert_true(init_wp_data_and_value(&wp_data, &value), NULL);
wp_data.application_data_len = -1; wp_data.application_data_len = -1;
zassert_false(Load_Control_Write_Property(&wp_data), NULL); zassert_false(Load_Control_Write_Property(&wp_data), NULL);
zassert_equal(wp_data.error_class, ERROR_CLASS_PROPERTY, NULL); zassert_equal(wp_data.error_class, ERROR_CLASS_PROPERTY, NULL);
zassert_equal(wp_data.error_code, ERROR_CODE_VALUE_OUT_OF_RANGE, NULL); zassert_equal(wp_data.error_code, ERROR_CODE_VALUE_OUT_OF_RANGE, NULL);
@@ -518,7 +711,6 @@ static void test_ShedInactive_gets_RcvShedRequests(void)
/* Verify invalid parameter value of application_data_len cause failure */ /* Verify invalid parameter value of application_data_len cause failure */
zassert_true(init_wp_data_and_value(&wp_data, &value), NULL); zassert_true(init_wp_data_and_value(&wp_data, &value), NULL);
wp_data.application_data_len = -1; wp_data.application_data_len = -1;
zassert_false(Load_Control_Write_Property(&wp_data), NULL); zassert_false(Load_Control_Write_Property(&wp_data), NULL);
zassert_equal(wp_data.error_class, ERROR_CLASS_PROPERTY, NULL); zassert_equal(wp_data.error_class, ERROR_CLASS_PROPERTY, NULL);
zassert_equal(wp_data.error_code, ERROR_CODE_VALUE_OUT_OF_RANGE, NULL); zassert_equal(wp_data.error_code, ERROR_CODE_VALUE_OUT_OF_RANGE, NULL);
@@ -534,9 +726,7 @@ ZTEST_SUITE(lc_tests, NULL, NULL, NULL, NULL, NULL);
void test_main(void) void test_main(void)
{ {
ztest_test_suite( ztest_test_suite(
lc_tests, ztest_unit_test(test_api_stubs), lc_tests, ztest_unit_test(test_Load_Control_Read_Write_Property),
ztest_unit_test(test_Load_Control_Count),
ztest_unit_test(test_Load_Control_Read_Write_Property),
ztest_unit_test(testLoadControlStateMachine), ztest_unit_test(testLoadControlStateMachine),
ztest_unit_test(test_ShedInactive_gets_RcvShedRequests)); ztest_unit_test(test_ShedInactive_gets_RcvShedRequests));