Added a basic creatable loop object with PID control (#1141)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -28,6 +28,8 @@ The git repositories are hosted at the following sites:
|
||||
|
||||
### Added
|
||||
|
||||
* Added a basic creatable Loop object with PID control. Integrated into
|
||||
the basic device object and server examples. (#1141)
|
||||
* Added defines for lighting output object present-value special values. (#1137)
|
||||
* Added get copy API to timer object for state-change-value (#1134)
|
||||
* Added Audit Log and Time Value objects to basic device and builds. (#1128)
|
||||
|
||||
@@ -387,6 +387,8 @@ add_library(${PROJECT_NAME}
|
||||
src/bacnet/basic/object/lc.h
|
||||
src/bacnet/basic/object/lo.c
|
||||
src/bacnet/basic/object/lo.h
|
||||
src/bacnet/basic/object/loop.c
|
||||
src/bacnet/basic/object/loop.h
|
||||
src/bacnet/basic/object/lsp.c
|
||||
src/bacnet/basic/object/lsp.h
|
||||
src/bacnet/basic/object/lsz.c
|
||||
|
||||
@@ -29,6 +29,7 @@ BACNET_OBJECT_SRC := \
|
||||
$(BACNET_OBJECT_DIR)/iv.c \
|
||||
$(BACNET_OBJECT_DIR)/lc.c \
|
||||
$(BACNET_OBJECT_DIR)/lo.c \
|
||||
$(BACNET_OBJECT_DIR)/loop.c \
|
||||
$(BACNET_OBJECT_DIR)/lsp.c \
|
||||
$(BACNET_OBJECT_DIR)/lsz.c \
|
||||
$(BACNET_OBJECT_DIR)/ms-input.c \
|
||||
|
||||
@@ -31,6 +31,7 @@ SRC = main.c \
|
||||
$(BACNET_OBJECT_DIR)/iv.c \
|
||||
$(BACNET_OBJECT_DIR)/lc.c \
|
||||
$(BACNET_OBJECT_DIR)/lo.c \
|
||||
$(BACNET_OBJECT_DIR)/loop.c \
|
||||
$(BACNET_OBJECT_DIR)/lsp.c \
|
||||
$(BACNET_OBJECT_DIR)/lsz.c \
|
||||
$(BACNET_OBJECT_DIR)/ms-input.c \
|
||||
|
||||
@@ -26,6 +26,7 @@ SRC = main.c \
|
||||
$(BACNET_OBJECT_DIR)/iv.c \
|
||||
$(BACNET_OBJECT_DIR)/lc.c \
|
||||
$(BACNET_OBJECT_DIR)/lo.c \
|
||||
$(BACNET_OBJECT_DIR)/loop.c \
|
||||
$(BACNET_OBJECT_DIR)/lsp.c \
|
||||
$(BACNET_OBJECT_DIR)/lsz.c \
|
||||
$(BACNET_OBJECT_DIR)/ms-input.c \
|
||||
|
||||
@@ -33,6 +33,7 @@ SRC = main.c \
|
||||
$(BACNET_OBJECT_DIR)/iv.c \
|
||||
$(BACNET_OBJECT_DIR)/lc.c \
|
||||
$(BACNET_OBJECT_DIR)/lo.c \
|
||||
$(BACNET_OBJECT_DIR)/loop.c \
|
||||
$(BACNET_OBJECT_DIR)/lsp.c \
|
||||
$(BACNET_OBJECT_DIR)/lsz.c \
|
||||
$(BACNET_OBJECT_DIR)/ms-input.c \
|
||||
|
||||
@@ -786,9 +786,11 @@
|
||||
"top">Yes</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#FFFFDD" width="75%" valign="top">Loop</td>
|
||||
<td bgcolor="#FFFFDD" width="75%" valign="top"><a href=
|
||||
"https://sourceforge.net/p/bacnet/src/ci/master/tree/src/bacnet/basic/object/loop.c">
|
||||
Loop</a></td>
|
||||
<td bgcolor="#FFFFDD" width="25%" align="center" valign=
|
||||
"top">-</td>
|
||||
"top">Yes</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#FFFFDD" width="75%" valign="top"><a href=
|
||||
|
||||
+1
@@ -191,6 +191,7 @@
|
||||
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\iv.c" />
|
||||
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\lc.c" />
|
||||
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\lo.c" />
|
||||
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\loop.c" />
|
||||
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\lsp.c" />
|
||||
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\ms-input.c" />
|
||||
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\mso.c" />
|
||||
|
||||
+3
@@ -57,6 +57,9 @@
|
||||
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\lo.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\loop.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\lsp.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
||||
@@ -74,6 +74,7 @@
|
||||
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\iv.c" />
|
||||
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\lc.c" />
|
||||
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\lo.c" />
|
||||
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\loop.c" />
|
||||
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\lsp.c" />
|
||||
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\lsz.c" />
|
||||
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\ms-input.c" />
|
||||
|
||||
@@ -363,6 +363,9 @@
|
||||
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\lo.c">
|
||||
<Filter>Source Files\src\bacnet\basic\object</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\loop.c">
|
||||
<Filter>Source Files\src\bacnet\basic\object</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\lsp.c">
|
||||
<Filter>Source Files\src\bacnet\basic\object</Filter>
|
||||
</ClCompile>
|
||||
|
||||
+6
-2
@@ -1232,6 +1232,7 @@ int bacapp_known_property_tag(
|
||||
|
||||
case PROP_MANIPULATED_VARIABLE_REFERENCE:
|
||||
case PROP_CONTROLLED_VARIABLE_REFERENCE:
|
||||
case PROP_SETPOINT_REFERENCE:
|
||||
case PROP_INPUT_REFERENCE:
|
||||
case PROP_EVENT_ALGORITHM_INHIBIT_REF:
|
||||
/* Properties using BACnetObjectPropertyReference */
|
||||
@@ -1321,8 +1322,11 @@ int bacapp_known_property_tag(
|
||||
/* BACnetLogRecord */
|
||||
return BACNET_APPLICATION_TAG_LOG_RECORD;
|
||||
case PROP_ACTION:
|
||||
/* BACnetActionCommand */
|
||||
return BACNET_APPLICATION_TAG_ACTION_COMMAND;
|
||||
if (object_type == OBJECT_COMMAND) {
|
||||
/* BACnetActionCommand */
|
||||
return BACNET_APPLICATION_TAG_ACTION_COMMAND;
|
||||
}
|
||||
return -1;
|
||||
case PROP_SCALE:
|
||||
/* BACnetScale */
|
||||
return BACNET_APPLICATION_TAG_SCALE;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <limits.h>
|
||||
#include <float.h>
|
||||
/* config is always first to allow developers to override */
|
||||
#include "bacnet/config.h"
|
||||
/* BACnet Stack core enumerations */
|
||||
|
||||
@@ -599,7 +599,8 @@ typedef enum {
|
||||
|
||||
typedef enum BACnetAction {
|
||||
ACTION_DIRECT = 0,
|
||||
ACTION_REVERSE = 1
|
||||
ACTION_REVERSE = 1,
|
||||
BACNET_ACTION_MAX = 2
|
||||
} BACNET_ACTION;
|
||||
|
||||
typedef enum BACnetBinaryPV {
|
||||
|
||||
@@ -57,6 +57,7 @@
|
||||
#include "bacnet/basic/object/iv.h"
|
||||
#include "bacnet/basic/object/osv.h"
|
||||
#include "bacnet/basic/object/piv.h"
|
||||
#include "bacnet/basic/object/loop.h"
|
||||
#include "bacnet/basic/object/time_value.h"
|
||||
#include "bacnet/basic/object/timer.h"
|
||||
#include "bacnet/basic/object/channel.h"
|
||||
@@ -386,6 +387,14 @@ static object_functions_t My_Object_Table[] = {
|
||||
NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */,
|
||||
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
|
||||
NULL /* Create */, NULL /* Delete */, NULL /* Timer */ },
|
||||
{ OBJECT_LOOP, Loop_Init, Loop_Count,
|
||||
Loop_Index_To_Instance, Loop_Valid_Instance,
|
||||
Loop_Object_Name, Loop_Read_Property,
|
||||
Loop_Write_Property, Loop_Property_Lists,
|
||||
NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */,
|
||||
NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */,
|
||||
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
|
||||
Loop_Create, Loop_Delete, Loop_Timer },
|
||||
{ OBJECT_PROGRAM, Program_Init, Program_Count,
|
||||
Program_Index_To_Instance, Program_Valid_Instance,
|
||||
Program_Object_Name, Program_Read_Property,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,214 @@
|
||||
/**
|
||||
* @file
|
||||
* @brief API for Loop object type
|
||||
* @author Steve Karg <skarg@users.sourceforge.net>
|
||||
* @date November 2025
|
||||
* @copyright SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#ifndef BACNET_BASIC_OBJECT_LOOP_H
|
||||
#define BACNET_BASIC_OBJECT_LOOP_H
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
/* BACnet Stack defines - first */
|
||||
#include "bacnet/bacdef.h"
|
||||
/* BACnet Stack API */
|
||||
#include "bacnet/bacerror.h"
|
||||
#include "bacnet/timer_value.h"
|
||||
#include "bacnet/wp.h"
|
||||
#include "bacnet/rp.h"
|
||||
#include "bacnet/list_element.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
void Loop_Property_Lists(
|
||||
const int **pRequired, const int **pOptional, const int **pProprietary);
|
||||
BACNET_STACK_EXPORT
|
||||
void Loop_Proprietary_Property_List_Set(const int *pProprietary);
|
||||
BACNET_STACK_EXPORT
|
||||
void Loop_Read_Property_Proprietary_Callback_Set(read_property_function cb);
|
||||
BACNET_STACK_EXPORT
|
||||
void Loop_Write_Property_Proprietary_Callback_Set(write_property_function cb);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Valid_Instance(uint32_t object_instance);
|
||||
BACNET_STACK_EXPORT
|
||||
unsigned Loop_Count(void);
|
||||
BACNET_STACK_EXPORT
|
||||
uint32_t Loop_Index_To_Instance(unsigned index);
|
||||
BACNET_STACK_EXPORT
|
||||
unsigned Loop_Instance_To_Index(uint32_t object_instance);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Object_Name(
|
||||
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Name_Set(uint32_t object_instance, const char *new_name);
|
||||
BACNET_STACK_EXPORT
|
||||
const char *Loop_Name_ASCII(uint32_t object_instance);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Description(
|
||||
uint32_t object_instance, BACNET_CHARACTER_STRING *description);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Description_Set(uint32_t instance, const char *new_name);
|
||||
BACNET_STACK_EXPORT
|
||||
const char *Loop_Description_ANSI(uint32_t object_instance);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Out_Of_Service(uint32_t instance);
|
||||
BACNET_STACK_EXPORT
|
||||
void Loop_Out_Of_Service_Set(uint32_t instance, bool oos_flag);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
BACNET_RELIABILITY Loop_Reliability(uint32_t object_instance);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Reliability_Set(uint32_t object_instance, BACNET_RELIABILITY value);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
float Loop_Present_Value(uint32_t object_instance);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Present_Value_Set(uint32_t object_instance, float value);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
uint32_t Loop_Update_Interval(uint32_t object_instance);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Update_Interval_Set(uint32_t object_instance, uint32_t value);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
uint16_t Loop_Output_Units(uint32_t instance);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Output_Units_Set(uint32_t instance, uint16_t units);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Manipulated_Variable_Reference(
|
||||
uint32_t object_instance, BACNET_OBJECT_PROPERTY_REFERENCE *value);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Manipulated_Variable_Reference_Set(
|
||||
uint32_t object_instance, BACNET_OBJECT_PROPERTY_REFERENCE *value);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Controlled_Variable_Reference(
|
||||
uint32_t object_instance, BACNET_OBJECT_PROPERTY_REFERENCE *value);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Controlled_Variable_Reference_Set(
|
||||
uint32_t object_instance, BACNET_OBJECT_PROPERTY_REFERENCE *value);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
float Loop_Controlled_Variable_Value(uint32_t object_instance);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Controlled_Variable_Value_Set(uint32_t object_instance, float value);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
uint16_t Loop_Controlled_Variable_Units(uint32_t instance);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Controlled_Variable_Units_Set(uint32_t instance, uint16_t units);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Setpoint_Reference(
|
||||
uint32_t instance, BACNET_OBJECT_PROPERTY_REFERENCE *value);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Setpoint_Reference_Set(
|
||||
uint32_t instance, BACNET_OBJECT_PROPERTY_REFERENCE *value);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
float Loop_Setpoint(uint32_t object_instance);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Setpoint_Set(uint32_t object_instance, float value);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
BACNET_ACTION Loop_Action(uint32_t object_instance);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Action_Set(uint32_t object_instance, BACNET_ACTION value);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
float Loop_Proportional_Constant(uint32_t object_instance);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Proportional_Constant_Set(uint32_t object_instance, float value);
|
||||
BACNET_STACK_EXPORT
|
||||
uint16_t Loop_Proportional_Constant_Units(uint32_t instance);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Proportional_Constant_Units_Set(uint32_t instance, uint16_t units);
|
||||
BACNET_STACK_EXPORT
|
||||
float Loop_Integral_Constant(uint32_t object_instance);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Integral_Constant_Set(uint32_t object_instance, float value);
|
||||
BACNET_STACK_EXPORT
|
||||
uint16_t Loop_Integral_Constant_Units(uint32_t instance);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Integral_Constant_Units_Set(uint32_t instance, uint16_t units);
|
||||
BACNET_STACK_EXPORT
|
||||
float Loop_Derivative_Constant(uint32_t object_instance);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Derivative_Constant_Set(uint32_t object_instance, float value);
|
||||
BACNET_STACK_EXPORT
|
||||
uint16_t Loop_Derivative_Constant_Units(uint32_t instance);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Derivative_Constant_Units_Set(uint32_t instance, uint16_t units);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
float Loop_Bias(uint32_t object_instance);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Bias_Set(uint32_t object_instance, float value);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
float Loop_Maximum_Output(uint32_t object_instance);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Maximum_Output_Set(uint32_t object_instance, float value);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
float Loop_Minimum_Output(uint32_t object_instance);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Minimum_Output_Set(uint32_t object_instance, float value);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
uint8_t Loop_Priority_For_Writing(uint32_t object_instance);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Priority_For_Writing_Set(uint32_t object_instance, uint8_t value);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
float Loop_COV_Increment(uint32_t instance);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_COV_Increment_Set(uint32_t instance, float value);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Reliability_Evaluation_Inhibit(uint32_t instance);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Reliability_Evaluation_Inhibit_Set(uint32_t instance, bool value);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
void Loop_Timer(uint32_t object_instance, uint16_t elapsed_milliseconds);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
void Loop_Write_Property_Internal_Callback_Set(write_property_function cb);
|
||||
BACNET_STACK_EXPORT
|
||||
void Loop_Read_Property_Internal_Callback_Set(read_property_function cb);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
int Loop_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
uint32_t Loop_Create(uint32_t object_instance);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Delete(uint32_t object_instance);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
void Loop_Cleanup(void);
|
||||
BACNET_STACK_EXPORT
|
||||
size_t Loop_Size(void);
|
||||
BACNET_STACK_EXPORT
|
||||
void Loop_Init(void);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
void *Loop_Context_Get(uint32_t object_instance);
|
||||
BACNET_STACK_EXPORT
|
||||
void Loop_Context_Set(uint32_t object_instance, void *context);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif
|
||||
@@ -55,6 +55,7 @@
|
||||
#include "bacnet/basic/object/iv.h"
|
||||
#include "bacnet/basic/object/time_value.h"
|
||||
#include "bacnet/basic/object/timer.h"
|
||||
#include "bacnet/basic/object/loop.h"
|
||||
#include "bacnet/basic/object/channel.h"
|
||||
#include "bacnet/basic/object/program.h"
|
||||
#include "bacnet/basic/object/lo.h"
|
||||
@@ -134,6 +135,7 @@
|
||||
defined(CONFIG_BACNET_BASIC_OBJECT_BITSTRING_VALUE) || \
|
||||
defined(CONFIG_BACNET_BASIC_OBJECT_TIME_VALUE) || \
|
||||
defined(CONFIG_BACNET_BASIC_OBJECT_TIMER) || \
|
||||
defined(CONFIG_BACNET_BASIC_OBJECT_LOOP) || \
|
||||
defined(CONFIG_BACNET_BASIC_OBJECT_PROGRAM) || \
|
||||
defined(CONFIG_BACNET_BASIC_OBJECT_CHARACTERSTRING_VALUE))
|
||||
#define CONFIG_BACNET_BASIC_OBJECT_ALL
|
||||
@@ -166,6 +168,7 @@
|
||||
#define CONFIG_BACNET_BASIC_OBJECT_BITSTRING_VALUE
|
||||
#define CONFIG_BACNET_BASIC_OBJECT_TIME_VALUE
|
||||
#define CONFIG_BACNET_BASIC_OBJECT_TIMER
|
||||
#define CONFIG_BACNET_BASIC_OBJECT_LOOP
|
||||
#define CONFIG_BACNET_BASIC_OBJECT_PROGRAM
|
||||
#define CONFIG_BACNET_BASIC_OBJECT_CHARACTERSTRING_VALUE
|
||||
#endif
|
||||
@@ -828,6 +831,28 @@ static object_functions_t My_Object_Table[] = {
|
||||
Timer_Delete,
|
||||
Timer_Task },
|
||||
#endif
|
||||
#if defined(CONFIG_BACNET_BASIC_OBJECT_LOOP)
|
||||
{ OBJECT_LOOP,
|
||||
Loop_Init,
|
||||
Loop_Count,
|
||||
Loop_Index_To_Instance,
|
||||
Loop_Valid_Instance,
|
||||
Loop_Object_Name,
|
||||
Loop_Read_Property,
|
||||
Loop_Write_Property,
|
||||
Loop_Property_Lists,
|
||||
NULL /* ReadRangeInfo */,
|
||||
NULL /* Iterator */,
|
||||
NULL /* Value_Lists */,
|
||||
NULL /* COV */,
|
||||
NULL /* COV Clear */,
|
||||
NULL /* Intrinsic Reporting */,
|
||||
NULL /* Add_List_Element */,
|
||||
NULL /* Remove_List_Element */,
|
||||
Loop_Create,
|
||||
Loop_Delete,
|
||||
Loop_Timer },
|
||||
#endif
|
||||
#if defined(CONFIG_BACNET_BASIC_OBJECT_PROGRAM)
|
||||
{ OBJECT_BITSTRING_VALUE,
|
||||
Program_Init,
|
||||
|
||||
@@ -1851,6 +1851,7 @@ static const int Loop_Properties_Optional[] = {
|
||||
/* unordered list of properties */
|
||||
PROP_DESCRIPTION,
|
||||
PROP_RELIABILITY,
|
||||
PROP_UPDATE_INTERVAL,
|
||||
PROP_PROPORTIONAL_CONSTANT,
|
||||
PROP_PROPORTIONAL_CONSTANT_UNITS,
|
||||
PROP_INTEGRAL_CONSTANT,
|
||||
|
||||
@@ -165,6 +165,7 @@ list(APPEND testdirs
|
||||
bacnet/basic/object/iv
|
||||
bacnet/basic/object/lc
|
||||
bacnet/basic/object/lo
|
||||
bacnet/basic/object/loop
|
||||
bacnet/basic/object/lsp
|
||||
bacnet/basic/object/lsz
|
||||
bacnet/basic/object/ms-input
|
||||
|
||||
@@ -68,6 +68,7 @@ add_executable(${PROJECT_NAME}
|
||||
${SRC_DIR}/bacnet/basic/object/iv.c
|
||||
${SRC_DIR}/bacnet/basic/object/lc.c
|
||||
${SRC_DIR}/bacnet/basic/object/lo.c
|
||||
${SRC_DIR}/bacnet/basic/object/loop.c
|
||||
${SRC_DIR}/bacnet/basic/object/lsp.c
|
||||
${SRC_DIR}/bacnet/basic/object/lsz.c
|
||||
${SRC_DIR}/bacnet/basic/object/ms-input.c
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
# 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}/bacnet/basic/object/test
|
||||
${TST_DIR}/ztest/include
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
# File(s) under test
|
||||
${SRC_DIR}/bacnet/basic/object/loop.c
|
||||
# Support files and stubs (pathname alphabetical)
|
||||
${SRC_DIR}/bacnet/access_rule.c
|
||||
${SRC_DIR}/bacnet/bacaction.c
|
||||
${SRC_DIR}/bacnet/bacaddr.c
|
||||
${SRC_DIR}/bacnet/bacapp.c
|
||||
${SRC_DIR}/bacnet/bacdcode.c
|
||||
${SRC_DIR}/bacnet/bacdest.c
|
||||
${SRC_DIR}/bacnet/bacdevobjpropref.c
|
||||
${SRC_DIR}/bacnet/bacint.c
|
||||
${SRC_DIR}/bacnet/baclog.c
|
||||
${SRC_DIR}/bacnet/bacreal.c
|
||||
${SRC_DIR}/bacnet/bacstr.c
|
||||
${SRC_DIR}/bacnet/bactext.c
|
||||
${SRC_DIR}/bacnet/bactimevalue.c
|
||||
${SRC_DIR}/bacnet/basic/sys/bigend.c
|
||||
${SRC_DIR}/bacnet/basic/sys/days.c
|
||||
${SRC_DIR}/bacnet/basic/sys/debug.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
|
||||
${SRC_DIR}/bacnet/property.c
|
||||
${SRC_DIR}/bacnet/proplist.c
|
||||
${SRC_DIR}/bacnet/timer_value.c
|
||||
${SRC_DIR}/bacnet/timestamp.c
|
||||
${SRC_DIR}/bacnet/wp.c
|
||||
${SRC_DIR}/bacnet/weeklyschedule.c
|
||||
${SRC_DIR}/bacnet/dailyschedule.c
|
||||
${SRC_DIR}/bacnet/calendar_entry.c
|
||||
${SRC_DIR}/bacnet/special_event.c
|
||||
${SRC_DIR}/bacnet/channel_value.c
|
||||
${SRC_DIR}/bacnet/secure_connect.c
|
||||
# Test and test library files
|
||||
./src/main.c
|
||||
${TST_DIR}/bacnet/basic/object/test/datetime_local.c
|
||||
${TST_DIR}/bacnet/basic/object/test/device_mock.c
|
||||
${TST_DIR}/bacnet/basic/object/test/property_test.c
|
||||
${ZTST_DIR}/ztest_mock.c
|
||||
${ZTST_DIR}/ztest.c
|
||||
)
|
||||
@@ -0,0 +1,429 @@
|
||||
/**
|
||||
* @file
|
||||
* @brief Unit test for Loop object
|
||||
* @author Steve Karg <skarg@users.sourceforge.net>
|
||||
* @date October 2025
|
||||
* @copyright SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#include <zephyr/ztest.h>
|
||||
#include <bacnet/basic/object/loop.h>
|
||||
#include <bacnet/bactext.h>
|
||||
#include <bacnet/list_element.h>
|
||||
#include <property_test.h>
|
||||
|
||||
/**
|
||||
* @addtogroup bacnet_tests
|
||||
* @{
|
||||
*/
|
||||
static BACNET_WRITE_PROPERTY_DATA Write_Property_Internal_Data;
|
||||
static bool Write_Property_Internal(BACNET_WRITE_PROPERTY_DATA *data)
|
||||
{
|
||||
memcpy(
|
||||
&Write_Property_Internal_Data, data,
|
||||
sizeof(BACNET_WRITE_PROPERTY_DATA));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static BACNET_READ_PROPERTY_DATA Read_Property_Internal_Data;
|
||||
static int Read_Property_Internal_Length;
|
||||
static int Read_Property_Internal(BACNET_READ_PROPERTY_DATA *data)
|
||||
{
|
||||
memcpy(
|
||||
&Read_Property_Internal_Data, data, sizeof(BACNET_READ_PROPERTY_DATA));
|
||||
|
||||
return Read_Property_Internal_Length;
|
||||
}
|
||||
|
||||
static int Proprietary_Properties[] = { 512, 513, -1 };
|
||||
static uint8_t Proprietary_Serial_Number[16];
|
||||
|
||||
/**
|
||||
* @brief WriteProperty handler for this objects proprietary properties.
|
||||
* For the given WriteProperty data, the application_data is loaded
|
||||
* or the error code and class are set and the return value is false.
|
||||
* @param data - BACNET_WRITE_PROPERTY_DATA data, including
|
||||
* requested data and space for the reply, or error response.
|
||||
* @return false if an error is loaded, true if no errors
|
||||
*/
|
||||
static bool Write_Property_Proprietary(BACNET_WRITE_PROPERTY_DATA *data)
|
||||
{
|
||||
bool status = false;
|
||||
int apdu_len = 0;
|
||||
uint8_t *apdu = NULL;
|
||||
size_t apdu_size = 0;
|
||||
BACNET_OCTET_STRING octet_value = { 0 };
|
||||
|
||||
switch ((int)data->object_property) {
|
||||
case 512:
|
||||
apdu_len = bacnet_octet_string_application_decode(
|
||||
apdu, apdu_size, &octet_value);
|
||||
if (apdu_len > 0) {
|
||||
octetstring_copy_value(
|
||||
Proprietary_Serial_Number,
|
||||
sizeof(Proprietary_Serial_Number), &octet_value);
|
||||
status = true;
|
||||
} else if (apdu_len == 0) {
|
||||
status = false;
|
||||
data->error_class = ERROR_CLASS_PROPERTY;
|
||||
data->error_code = ERROR_CODE_INVALID_DATA_TYPE;
|
||||
|
||||
} else {
|
||||
status = false;
|
||||
data->error_class = ERROR_CLASS_PROPERTY;
|
||||
data->error_code = ERROR_CODE_INVALID_DATA_ENCODING;
|
||||
}
|
||||
break;
|
||||
case 513:
|
||||
default:
|
||||
status = false;
|
||||
data->error_class = ERROR_CLASS_PROPERTY;
|
||||
data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ReadProperty handler for this objects proprietary properties.
|
||||
* For the given ReadProperty data, the application_data is loaded
|
||||
* or the error code and class are set and the return value is
|
||||
* BACNET_STATUS_ERROR.
|
||||
* @param data - BACNET_READ_PROPERTY_DATA data, including
|
||||
* requested data and space for the reply, or error response.
|
||||
* @return false if an error is loaded, true if no errors
|
||||
*/
|
||||
static int Read_Property_Proprietary(BACNET_READ_PROPERTY_DATA *data)
|
||||
{
|
||||
int apdu_len = 0;
|
||||
uint8_t *apdu = NULL;
|
||||
size_t apdu_size = 0;
|
||||
BACNET_OCTET_STRING octet_value = { 0 };
|
||||
BACNET_UNSIGNED_INTEGER unsigned_value = 0;
|
||||
|
||||
if ((data == NULL) || (data->application_data == NULL) ||
|
||||
(data->application_data_len == 0)) {
|
||||
return 0;
|
||||
}
|
||||
/* none of our proprietary properties are arrays */
|
||||
if (data->array_index != BACNET_ARRAY_ALL) {
|
||||
data->error_class = ERROR_CLASS_PROPERTY;
|
||||
data->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
|
||||
return BACNET_STATUS_ERROR;
|
||||
}
|
||||
apdu = data->application_data;
|
||||
apdu_size = data->application_data_len;
|
||||
switch ((int)data->object_property) {
|
||||
case 512:
|
||||
octetstring_init(
|
||||
&octet_value, Proprietary_Serial_Number,
|
||||
sizeof(Proprietary_Serial_Number));
|
||||
apdu_len = bacnet_octet_string_application_encode(
|
||||
apdu, apdu_size, &octet_value);
|
||||
break;
|
||||
case 513:
|
||||
unsigned_value = Loop_Size();
|
||||
apdu_len = bacnet_unsigned_application_encode(
|
||||
apdu, apdu_size, unsigned_value);
|
||||
break;
|
||||
default:
|
||||
data->error_class = ERROR_CLASS_PROPERTY;
|
||||
data->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
|
||||
apdu_len = BACNET_STATUS_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test
|
||||
*/
|
||||
static void test_Loop_Read_Write(void)
|
||||
{
|
||||
const uint32_t instance = 123;
|
||||
unsigned count = 0;
|
||||
unsigned index = 0;
|
||||
const char *sample_name = "Loop:0";
|
||||
char *sample_context = "context";
|
||||
const char *sample_description = "Loop Description";
|
||||
const char *test_name = NULL;
|
||||
uint32_t test_instance = 0;
|
||||
bool status = false;
|
||||
const int skip_fail_property_list[] = { -1 };
|
||||
BACNET_WRITE_PROPERTY_DATA wp_data = { 0 };
|
||||
BACNET_APPLICATION_DATA_VALUE value = { 0 };
|
||||
BACNET_CHARACTER_STRING cstring = { 0 };
|
||||
int32_t i = 0,
|
||||
units_properties[] = { PROP_OUTPUT_UNITS,
|
||||
PROP_CONTROLLED_VARIABLE_UNITS,
|
||||
PROP_PROPORTIONAL_CONSTANT_UNITS,
|
||||
PROP_INTEGRAL_CONSTANT_UNITS,
|
||||
PROP_DERIVATIVE_CONSTANT_UNITS,
|
||||
-1 },
|
||||
real_properties[] = { PROP_PRESENT_VALUE,
|
||||
PROP_CONTROLLED_VARIABLE_VALUE,
|
||||
PROP_SETPOINT,
|
||||
PROP_PROPORTIONAL_CONSTANT,
|
||||
PROP_INTEGRAL_CONSTANT,
|
||||
PROP_DERIVATIVE_CONSTANT,
|
||||
PROP_BIAS,
|
||||
PROP_MAXIMUM_OUTPUT,
|
||||
PROP_MINIMUM_OUTPUT,
|
||||
PROP_COV_INCREMENT,
|
||||
-1 };
|
||||
|
||||
Loop_Init();
|
||||
Loop_Create(instance);
|
||||
status = Loop_Valid_Instance(instance);
|
||||
zassert_true(status, NULL);
|
||||
status = Loop_Valid_Instance(instance - 1);
|
||||
zassert_false(status, NULL);
|
||||
index = Loop_Instance_To_Index(instance);
|
||||
zassert_equal(index, 0, NULL);
|
||||
test_instance = Loop_Index_To_Instance(index);
|
||||
zassert_equal(instance, test_instance, NULL);
|
||||
count = Loop_Count();
|
||||
zassert_true(count > 0, NULL);
|
||||
/* reliability and status flags */
|
||||
status = Loop_Reliability_Set(instance, RELIABILITY_PROCESS_ERROR);
|
||||
zassert_true(status, NULL);
|
||||
/* add some proprietary properties */
|
||||
Loop_Proprietary_Property_List_Set(Proprietary_Properties);
|
||||
Loop_Read_Property_Proprietary_Callback_Set(Read_Property_Proprietary);
|
||||
Loop_Write_Property_Proprietary_Callback_Set(Write_Property_Proprietary);
|
||||
/* perform a general test for RP/WP */
|
||||
bacnet_object_properties_read_write_test(
|
||||
OBJECT_LOOP, instance, Loop_Property_Lists, Loop_Read_Property,
|
||||
Loop_Write_Property, skip_fail_property_list);
|
||||
/* test the ASCII name get/set */
|
||||
status = Loop_Name_Set(instance, sample_name);
|
||||
zassert_true(status, NULL);
|
||||
test_name = Loop_Name_ASCII(instance);
|
||||
zassert_equal(test_name, sample_name, NULL);
|
||||
status = Loop_Object_Name(instance, &cstring);
|
||||
zassert_true(status, NULL);
|
||||
status = characterstring_ansi_same(&cstring, sample_name);
|
||||
zassert_true(status, NULL);
|
||||
status = Loop_Name_Set(instance, NULL);
|
||||
zassert_true(status, NULL);
|
||||
test_name = Loop_Name_ASCII(instance);
|
||||
zassert_equal(test_name, NULL, NULL);
|
||||
/* test specific WriteProperty values - common configuration */
|
||||
wp_data.object_type = OBJECT_LOOP;
|
||||
wp_data.object_instance = instance;
|
||||
wp_data.array_index = BACNET_ARRAY_ALL;
|
||||
wp_data.priority = BACNET_MAX_PRIORITY;
|
||||
zassert_true(status, NULL);
|
||||
/* out-of-service */
|
||||
wp_data.object_property = PROP_OUT_OF_SERVICE;
|
||||
value.tag = BACNET_APPLICATION_TAG_BOOLEAN;
|
||||
value.type.Boolean = true;
|
||||
wp_data.application_data_len =
|
||||
bacapp_encode_application_data(wp_data.application_data, &value);
|
||||
status = Loop_Write_Property(&wp_data);
|
||||
zassert_true(status, NULL);
|
||||
value.type.Boolean = false;
|
||||
wp_data.application_data_len =
|
||||
bacapp_encode_application_data(wp_data.application_data, &value);
|
||||
status = Loop_Write_Property(&wp_data);
|
||||
zassert_true(status, NULL);
|
||||
value.tag = BACNET_APPLICATION_TAG_UNSIGNED_INT;
|
||||
value.type.Unsigned_Int = 123;
|
||||
wp_data.application_data_len =
|
||||
bacapp_encode_application_data(wp_data.application_data, &value);
|
||||
status = Loop_Write_Property(&wp_data);
|
||||
zassert_false(status, NULL);
|
||||
/* write present-value */
|
||||
wp_data.object_property = PROP_PRESENT_VALUE;
|
||||
value.tag = BACNET_APPLICATION_TAG_REAL;
|
||||
value.type.Real = 1.0f;
|
||||
wp_data.application_data_len =
|
||||
bacapp_encode_application_data(wp_data.application_data, &value);
|
||||
status = Loop_Write_Property(&wp_data);
|
||||
zassert_true(status, NULL);
|
||||
/* write minimum-output and maximum-output */
|
||||
wp_data.object_property = PROP_MINIMUM_OUTPUT;
|
||||
value.tag = BACNET_APPLICATION_TAG_REAL;
|
||||
value.type.Real = 1.0f;
|
||||
wp_data.application_data_len =
|
||||
bacapp_encode_application_data(wp_data.application_data, &value);
|
||||
status = Loop_Write_Property(&wp_data);
|
||||
zassert_true(status, NULL);
|
||||
wp_data.object_property = PROP_MAXIMUM_OUTPUT;
|
||||
value.tag = BACNET_APPLICATION_TAG_REAL;
|
||||
value.type.Real = 100.0f;
|
||||
wp_data.application_data_len =
|
||||
bacapp_encode_application_data(wp_data.application_data, &value);
|
||||
status = Loop_Write_Property(&wp_data);
|
||||
zassert_true(status, NULL);
|
||||
/* action - out of range error */
|
||||
wp_data.object_property = PROP_ACTION;
|
||||
value.tag = BACNET_APPLICATION_TAG_ENUMERATED;
|
||||
value.type.Enumerated = BACNET_ACTION_MAX;
|
||||
wp_data.application_data_len =
|
||||
bacapp_encode_application_data(wp_data.application_data, &value);
|
||||
status = Loop_Write_Property(&wp_data);
|
||||
zassert_false(status, NULL);
|
||||
zassert_equal(wp_data.error_class, ERROR_CLASS_PROPERTY, NULL);
|
||||
zassert_equal(wp_data.error_code, ERROR_CODE_VALUE_OUT_OF_RANGE, NULL);
|
||||
/* units - out of range error */
|
||||
i = 0;
|
||||
while (units_properties[i] != -1) {
|
||||
wp_data.object_property = units_properties[i];
|
||||
value.tag = BACNET_APPLICATION_TAG_ENUMERATED;
|
||||
value.type.Enumerated = UINT16_MAX + 1UL;
|
||||
wp_data.application_data_len =
|
||||
bacapp_encode_application_data(wp_data.application_data, &value);
|
||||
status = Loop_Write_Property(&wp_data);
|
||||
zassert_false(status, NULL);
|
||||
zassert_equal(wp_data.error_class, ERROR_CLASS_PROPERTY, NULL);
|
||||
zassert_equal(wp_data.error_code, ERROR_CODE_VALUE_OUT_OF_RANGE, NULL);
|
||||
i++;
|
||||
}
|
||||
/* REAL - out of range error */
|
||||
i = 0;
|
||||
while (real_properties[i] != -1) {
|
||||
wp_data.object_property = real_properties[i];
|
||||
value.tag = BACNET_APPLICATION_TAG_REAL;
|
||||
value.type.Real = NAN;
|
||||
wp_data.application_data_len =
|
||||
bacapp_encode_application_data(wp_data.application_data, &value);
|
||||
status = Loop_Write_Property(&wp_data);
|
||||
zassert_false(status, NULL);
|
||||
zassert_equal(wp_data.error_class, ERROR_CLASS_PROPERTY, NULL);
|
||||
zassert_equal(wp_data.error_code, ERROR_CODE_VALUE_OUT_OF_RANGE, NULL);
|
||||
i++;
|
||||
}
|
||||
/* priority-for-writing - out of range error */
|
||||
wp_data.object_property = PROP_PRIORITY_FOR_WRITING;
|
||||
value.tag = BACNET_APPLICATION_TAG_UNSIGNED_INT;
|
||||
value.type.Unsigned_Int = BACNET_MIN_PRIORITY;
|
||||
wp_data.application_data_len =
|
||||
bacapp_encode_application_data(wp_data.application_data, &value);
|
||||
status = Loop_Write_Property(&wp_data);
|
||||
zassert_true(status, NULL);
|
||||
value.type.Unsigned_Int = BACNET_MAX_PRIORITY + 1ULL;
|
||||
wp_data.application_data_len =
|
||||
bacapp_encode_application_data(wp_data.application_data, &value);
|
||||
status = Loop_Write_Property(&wp_data);
|
||||
zassert_false(status, NULL);
|
||||
zassert_equal(wp_data.error_class, ERROR_CLASS_PROPERTY, NULL);
|
||||
zassert_equal(wp_data.error_code, ERROR_CODE_VALUE_OUT_OF_RANGE, NULL);
|
||||
value.type.Unsigned_Int = UINT8_MAX + 1ULL;
|
||||
wp_data.application_data_len =
|
||||
bacapp_encode_application_data(wp_data.application_data, &value);
|
||||
status = Loop_Write_Property(&wp_data);
|
||||
zassert_false(status, NULL);
|
||||
zassert_equal(wp_data.error_class, ERROR_CLASS_PROPERTY, NULL);
|
||||
zassert_equal(wp_data.error_code, ERROR_CODE_VALUE_OUT_OF_RANGE, NULL);
|
||||
/* read-only property */
|
||||
wp_data.object_property = PROP_OBJECT_TYPE;
|
||||
value.tag = BACNET_APPLICATION_TAG_ENUMERATED;
|
||||
value.type.Enumerated = OBJECT_ANALOG_INPUT;
|
||||
wp_data.array_index = BACNET_ARRAY_ALL;
|
||||
wp_data.priority = BACNET_MAX_PRIORITY;
|
||||
wp_data.application_data_len =
|
||||
bacapp_encode_application_data(wp_data.application_data, &value);
|
||||
status = Loop_Write_Property(&wp_data);
|
||||
zassert_equal(wp_data.error_class, ERROR_CLASS_PROPERTY, NULL);
|
||||
zassert_equal(wp_data.error_code, ERROR_CODE_WRITE_ACCESS_DENIED, NULL);
|
||||
zassert_false(status, NULL);
|
||||
/* == API testing where not already tested by read or write property == */
|
||||
/* reliability and status flags API */
|
||||
status = Loop_Reliability_Set(instance, RELIABILITY_PROCESS_ERROR);
|
||||
zassert_true(status, NULL);
|
||||
/* context API */
|
||||
Loop_Context_Set(instance, sample_context);
|
||||
zassert_true(sample_context == Loop_Context_Get(instance), NULL);
|
||||
zassert_true(NULL == Loop_Context_Get(instance + 1), NULL);
|
||||
/* description API */
|
||||
status = Loop_Description_Set(instance, sample_description);
|
||||
zassert_true(status, NULL);
|
||||
zassert_equal(sample_description, Loop_Description_ANSI(instance), NULL);
|
||||
status = Loop_Description(instance, &cstring);
|
||||
zassert_true(status, NULL);
|
||||
status = characterstring_ansi_same(&cstring, sample_description);
|
||||
zassert_true(status, NULL);
|
||||
status = Loop_Description_Set(instance, NULL);
|
||||
zassert_true(status, NULL);
|
||||
status = characterstring_init_ansi(&cstring, "");
|
||||
zassert_true(status, NULL);
|
||||
status =
|
||||
characterstring_ansi_same(&cstring, Loop_Description_ANSI(instance));
|
||||
zassert_true(status, NULL);
|
||||
/* cleanup */
|
||||
status = Loop_Delete(instance);
|
||||
zassert_true(status, NULL);
|
||||
Loop_Cleanup();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test
|
||||
*/
|
||||
static void test_Loop_Operation(void)
|
||||
{
|
||||
const uint32_t instance = 123;
|
||||
uint32_t test_instance = 0;
|
||||
bool status = false;
|
||||
uint32_t elapsed_time = 0;
|
||||
BACNET_OBJECT_PROPERTY_REFERENCE reference = { 0 };
|
||||
|
||||
/* init */
|
||||
Loop_Init();
|
||||
Loop_Create(instance);
|
||||
status = Loop_Valid_Instance(instance);
|
||||
zassert_true(status, NULL);
|
||||
/* set Kp, Ki, Kd, setpoint, etc */
|
||||
/* connect the read and write property callbacks */
|
||||
Loop_Write_Property_Internal_Callback_Set(Write_Property_Internal);
|
||||
Loop_Read_Property_Internal_Callback_Set(Read_Property_Internal);
|
||||
/* run the PID loop */
|
||||
Loop_Timer(instance, elapsed_time);
|
||||
elapsed_time += 1000;
|
||||
Loop_Timer(instance, elapsed_time);
|
||||
Loop_Update_Interval_Set(instance, 100);
|
||||
elapsed_time += 100;
|
||||
Loop_Timer(instance, elapsed_time);
|
||||
elapsed_time += 100;
|
||||
Loop_Timer(instance, elapsed_time);
|
||||
elapsed_time += 100;
|
||||
Loop_Timer(instance, elapsed_time);
|
||||
/* references - test by referencing self */
|
||||
reference.object_identifier.instance = instance;
|
||||
reference.object_identifier.type = OBJECT_LOOP;
|
||||
reference.property_array_index = BACNET_ARRAY_ALL;
|
||||
reference.property_identifier = PROP_CONTROLLED_VARIABLE_VALUE;
|
||||
Loop_Controlled_Variable_Reference_Set(instance, &reference);
|
||||
reference.property_identifier = PROP_SETPOINT;
|
||||
Loop_Setpoint_Reference_Set(instance, &reference);
|
||||
reference.property_identifier = PROP_PRESENT_VALUE;
|
||||
Loop_Manipulated_Variable_Reference_Set(instance, &reference);
|
||||
elapsed_time += 100;
|
||||
Loop_Timer(instance, elapsed_time);
|
||||
/* cleanup instance */
|
||||
status = Loop_Delete(instance);
|
||||
zassert_true(status, NULL);
|
||||
/* test create of next instance */
|
||||
test_instance = Loop_Create(BACNET_MAX_INSTANCE);
|
||||
zassert_not_equal(test_instance, BACNET_MAX_INSTANCE, NULL);
|
||||
test_instance = Loop_Create(test_instance);
|
||||
zassert_not_equal(test_instance, BACNET_MAX_INSTANCE, NULL);
|
||||
test_instance = Loop_Create(BACNET_MAX_INSTANCE + 1);
|
||||
zassert_equal(test_instance, BACNET_MAX_INSTANCE, NULL);
|
||||
/* cleanup all */
|
||||
Loop_Cleanup();
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(
|
||||
loop_tests, ztest_unit_test(test_Loop_Read_Write),
|
||||
ztest_unit_test(test_Loop_Operation));
|
||||
|
||||
ztest_run_test_suite(loop_tests);
|
||||
}
|
||||
@@ -216,6 +216,18 @@ int bacnet_object_property_read_test(
|
||||
/* test an array index that must be implemented */
|
||||
rpdata->array_index = 0;
|
||||
read_len = read_property(rpdata);
|
||||
if ((rpdata->object_property >= PROP_PROPRIETARY_RANGE_MIN) &&
|
||||
(rpdata->object_property <= PROP_PROPRIETARY_RANGE_MAX)) {
|
||||
/* all proprietary properties could be a BACnetARRAY */
|
||||
if (read_len == BACNET_STATUS_ERROR) {
|
||||
zassert_equal(
|
||||
rpdata->error_code, ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY,
|
||||
NULL);
|
||||
}
|
||||
is_array = false;
|
||||
}
|
||||
}
|
||||
if (is_array) {
|
||||
zassert_not_equal(
|
||||
read_len, BACNET_STATUS_ERROR,
|
||||
"property '%s' array_index=0: error code is %s.\n",
|
||||
@@ -319,8 +331,8 @@ void bacnet_object_properties_read_write_test(
|
||||
len, BACNET_STATUS_ERROR,
|
||||
"property '%s' array_index=ALL: Missing in property list.\n",
|
||||
bactext_property_name(rpdata.object_property));
|
||||
/* shrink the number space and skip proprietary range values */
|
||||
if (property == PROP_RESERVED_RANGE_MAX) {
|
||||
/* shrink the number space and skip most proprietary range values */
|
||||
if (property == (PROP_PROPRIETARY_RANGE_MIN + 1)) {
|
||||
property = PROP_RESERVED_RANGE_MIN2 - 1;
|
||||
}
|
||||
/* shrink the number space to known values */
|
||||
|
||||
@@ -73,6 +73,7 @@ add_executable(${PROJECT_NAME}
|
||||
${SRC_DIR}/bacnet/basic/object/iv.c
|
||||
${SRC_DIR}/bacnet/basic/object/lc.c
|
||||
${SRC_DIR}/bacnet/basic/object/lo.c
|
||||
${SRC_DIR}/bacnet/basic/object/loop.c
|
||||
${SRC_DIR}/bacnet/basic/object/lsp.c
|
||||
${SRC_DIR}/bacnet/basic/object/lsz.c
|
||||
${SRC_DIR}/bacnet/basic/object/ms-input.c
|
||||
|
||||
Reference in New Issue
Block a user