From a1d91dbeb180020e25ec093b19f0518cfa324139 Mon Sep 17 00:00:00 2001 From: Steve Karg Date: Tue, 6 Aug 2024 09:52:10 -0500 Subject: [PATCH] Updated B-SS profile sample build for Zephyr OS. (#711) --- src/bacnet/indtext.c | 26 +++++++++++++++- src/bacnet/indtext.h | 3 ++ zephyr/CMakeLists.txt | 13 +++++--- zephyr/Kconfig | 41 +++++++++++++++++++++---- zephyr/samples/profiles/b-ss/prj.conf | 2 +- zephyr/samples/profiles/b-ss/src/main.c | 31 +++++++++++++++++-- 6 files changed, 101 insertions(+), 15 deletions(-) diff --git a/src/bacnet/indtext.c b/src/bacnet/indtext.c index fa2c67ae..f7b2949b 100644 --- a/src/bacnet/indtext.c +++ b/src/bacnet/indtext.c @@ -7,9 +7,33 @@ */ #include #include +#include #include "bacnet/bacdef.h" #include "bacnet/indtext.h" +/** + * @brief Compare two strings, case insensitive + * @param a - first string + * @param b - second string + * @return 0 if the strings are equal, non-zero if not + * @note The stricmp() function is not included C standard. + */ +int indtext_stricmp(const char *a, const char *b) +{ + int twin_a, twin_b; + + do { + twin_a = *(unsigned char *)a; + twin_b = *(unsigned char *)b; + twin_a = tolower(toupper(twin_a)); + twin_b = tolower(toupper(twin_b)); + a++; + b++; + } while ((twin_a == twin_b) && (twin_a != '\0')); + + return twin_a - twin_b; +} + /** * @brief Search a list of strings to find a matching string * @param data_list - list of strings and indices @@ -56,7 +80,7 @@ bool indtext_by_istring( if (data_list && search_name) { while (data_list->pString) { - if (strcasecmp(data_list->pString, search_name) == 0) { + if (indtext_stricmp(data_list->pString, search_name) == 0) { index = data_list->index; found = true; break; diff --git a/src/bacnet/indtext.h b/src/bacnet/indtext.h index 4a1a023e..51b3c3cc 100644 --- a/src/bacnet/indtext.h +++ b/src/bacnet/indtext.h @@ -24,6 +24,9 @@ typedef const struct { extern "C" { #endif /* __cplusplus */ + BACNET_STACK_EXPORT + int indtext_stricmp(const char *a, const char *b); + /* Searches for a matching string and returns the index to the string in the parameter found_index. If the string is not found, false is returned diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index 34ee325c..ecb1787b 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -472,7 +472,7 @@ zephyr_compile_definitions( BACNET_STACK_DEPRECATED_DISABLE=1 # datalink API $<$:BACDL_NONE> - $<$:BACAPP_ALL> + $<$:BACAPP_ALL> $<$:BACDL_BIP> $<$:BACDL_BIP_PORT=${CONFIG_BACDL_BIP_PORT}> $<$:MAX_BBMD_ENTRIES=${CONFIG_MAX_BBMD_ENTRIES}> @@ -481,6 +481,8 @@ zephyr_compile_definitions( $<$:BACDL_ARCNET> $<$:BACDL_MSTP> $<$:BACDL_ETHERNET> + $<$:BACDL_CUSTOM> + # library features $<$:BACNET_BASIC_OBJECTS> $<$:BACNET_PROPERTY_LISTS=1> @@ -517,14 +519,17 @@ zephyr_compile_definitions( $<$:BACAPP_XY_COLOR> $<$:BACAPP_COLOR_COMMAND> $<$:BACAPP_WEEKLY_SCHEDULE> - $<$:BACAPP_CALENDAR_ENTRY> - $<$:BACAPP_SPECIAL_EVENT> $<$:BACAPP_HOST_N_PORT> $<$:BACAPP_DEVICE_OBJECT_PROPERTY_REFERENCE> $<$:BACAPP_DEVICE_OBJECT_REFERENCE> $<$:BACAPP_OBJECT_PROPERTY_REFERENCE> $<$:BACAPP_DESTINATION> + $<$:BACAPP_CALENDAR_ENTRY> + $<$:BACAPP_SPECIAL_EVENT> $<$:BACAPP_BDT_ENTRY> $<$:BACAPP_FDT_ENTRY> - ) + $<$:BACAPP_ACTION_COMMAND> + $<$:BACAPP_SCALE> + $<$:BACAPP_SHED_LEVEL> + ) \ No newline at end of file diff --git a/zephyr/Kconfig b/zephyr/Kconfig index 9c0404c8..c4c4ca25 100644 --- a/zephyr/Kconfig +++ b/zephyr/Kconfig @@ -76,11 +76,26 @@ config BACDL_BIP help Enable BACnet BIP datalink +config BACDL_BIP6 + bool "BACnet BIP6" + help + Enable BACnet BIP6 + config BACDL_NONE bool "BACnet without datalink" help Enable BACnet without datalink +config BACDL_CUSTOM + bool "BACnet with custom datalink enabled" + help + Enable BACnet with custom datalink enabled + +config BACDL_ALL + bool "BACnet with all datalinks enabled" + help + Enable BACnet with all datalinks enabled + config BACAPP_ALL bool "BACnet data types supported for WriteProperty: all = minimal + extra" default false @@ -104,7 +119,8 @@ config BACAPP_TYPES_EXTRA LIGHTING_COMMAND, XY_COLOR, COLOR_COMMAND, WEEKLY_SCHEDULE, CALENDAR_ENTRY, SPECIAL_EVENT, HOST_N_PORT, DEVICE_OBJECT_PROPERTY_REFERENCE, DEVICE_OBJECT_REFERENCE, - OBJECT_PROPERTY_REFERENCE, DESTINATION + OBJECT_PROPERTY_REFERENCE, DESTINATION, BDT_ENTRY, FDT_ENTRY, + ACTION_COMMAND, SCALE, SHED_LEVEL config BACAPP_NULL bool "BACnet data types supported for WriteProperty: NULL" @@ -274,6 +290,24 @@ config BACAPP_FDT_ENTRY help BACnet data types supported for WriteProperty: FDT_ENTRY +config BACAPP_ACTION_COMMAND + bool "BACnet data types supported for WriteProperty: BACAPP_ACTION_COMMAND" + default false + help + BACnet data types supported for WriteProperty: BACAPP_ACTION_COMMAND + +config BACAPP_SCALE + bool "BACnet data types supported for WriteProperty: BACAPP_SCALE" + default false + help + BACnet data types supported for WriteProperty: BACAPP_SCALE + +config BACAPP_SHED_LEVEL + bool "BACnet data types supported for WriteProperty: BACAPP_SHED_LEVEL" + default false + help + BACnet data types supported for WriteProperty: BACAPP_SHED_LEVEL + config BACAPP_PRINT_ENABLED bool "BACnet app print" default false @@ -314,11 +348,6 @@ config BACDL_BIP_ADDRESS_INDEX help Select IPv4 address -config BACDL_BIP6 - bool "BACnet BIP6" - help - Enable BACnet BIP6 - config BACDL_BIP6_ADDRESS_INDEX int "Unicast address index" depends on BACDL_BIP6 diff --git a/zephyr/samples/profiles/b-ss/prj.conf b/zephyr/samples/profiles/b-ss/prj.conf index feb334b6..57d098fd 100644 --- a/zephyr/samples/profiles/b-ss/prj.conf +++ b/zephyr/samples/profiles/b-ss/prj.conf @@ -128,4 +128,4 @@ CONFIG_BACNETSTACK_LOG_LEVEL_DBG=y #CONFIG_SETTINGS_SHELL=y CONFIG_TEST_RANDOM_GENERATOR=y - +CONFIG_TIMER_RANDOM_GENERATOR=y diff --git a/zephyr/samples/profiles/b-ss/src/main.c b/zephyr/samples/profiles/b-ss/src/main.c index d784b2bc..dcca05f1 100644 --- a/zephyr/samples/profiles/b-ss/src/main.c +++ b/zephyr/samples/profiles/b-ss/src/main.c @@ -5,12 +5,15 @@ */ #include +#include #include +#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack core API */ #include "bacnet/version.h" +#include "bacnet/basic/sys/mstimer.h" /* BACnet Stack basic device API - see bacnet_basic/device.c for details */ #include "bacnet/basic/object/device.h" /* BACnet Stack basic objects - also enable in prj.conf */ @@ -24,6 +27,11 @@ #include LOG_MODULE_DECLARE(bacnet, CONFIG_BACNETSTACK_LOG_LEVEL); +static const uint32_t Device_Instance = 260123; +static const uint32_t Sensor_Instance = 1; +/* timer for Sensor Update Interval */ +static struct mstimer Sensor_Update_Timer; + /** * @brief BACnet Project Initialization Handler * @param context [in] The context to pass to the callback function @@ -35,10 +43,14 @@ static void BACnet_Smart_Sensor_Init_Handler(void *context) LOG_INF("BACnet Stack Initialized"); /* initialize objects for this basic sample */ Device_Init(NULL); - Device_Set_Object_Instance_Number(260123); - Analog_Input_Create(1); - Analog_Input_Name_Set(1, "Sensor"); + Device_Set_Object_Instance_Number(Device_Instance); + Analog_Input_Create(Sensor_Instance); + Analog_Input_Name_Set(Sensor_Instance, "Sensor"); + Analog_Input_Present_Value_Set(Sensor_Instance, 25.0f); LOG_INF("BACnet Device ID: %u", Device_Object_Instance_Number()); + /* start the seconds cyclic timer */ + mstimer_set(&Sensor_Update_Timer, 1000); + srand(sys_rand32_get()); } /** @@ -48,7 +60,20 @@ static void BACnet_Smart_Sensor_Init_Handler(void *context) */ static void BACnet_Smart_Sensor_Task_Handler(void *context) { + float temperature = 0.0f, change = 0.0f; + (void)context; + if (mstimer_expired(&Sensor_Update_Timer)) { + mstimer_reset(&Sensor_Update_Timer); + /* simulate a sensor reading, and update the BACnet object values */ + if (Analog_Input_Out_Of_Service(Sensor_Instance)) { + return; + } + temperature = Analog_Input_Present_Value(Sensor_Instance); + change = -1.0f+2.0f*((float)rand())/RAND_MAX; + temperature += change; + Analog_Input_Present_Value_Set(Sensor_Instance, temperature); + } } int main(void)