Updated B-SS profile sample build for Zephyr OS. (#711)
This commit is contained in:
+25
-1
@@ -7,9 +7,33 @@
|
||||
*/
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -472,7 +472,7 @@ zephyr_compile_definitions(
|
||||
BACNET_STACK_DEPRECATED_DISABLE=1
|
||||
# datalink API
|
||||
$<$<BOOL:${CONFIG_BACDL_NONE}>:BACDL_NONE>
|
||||
$<$<BOOL:${CONFIG_BACDL_NONE}>:BACAPP_ALL>
|
||||
$<$<BOOL:${CONFIG_BACDL_ALL}>:BACAPP_ALL>
|
||||
$<$<BOOL:${CONFIG_BACDL_BIP}>:BACDL_BIP>
|
||||
$<$<BOOL:${CONFIG_BACDL_BIP_PORT}>:BACDL_BIP_PORT=${CONFIG_BACDL_BIP_PORT}>
|
||||
$<$<BOOL:${CONFIG_MAX_BBMD_ENTRIES}>:MAX_BBMD_ENTRIES=${CONFIG_MAX_BBMD_ENTRIES}>
|
||||
@@ -481,6 +481,8 @@ zephyr_compile_definitions(
|
||||
$<$<BOOL:${CONFIG_BACDL_ARCNET}>:BACDL_ARCNET>
|
||||
$<$<BOOL:${CONFIG_BACDL_MSTP}>:BACDL_MSTP>
|
||||
$<$<BOOL:${CONFIG_BACDL_ETHERNET}>:BACDL_ETHERNET>
|
||||
$<$<BOOL:${CONFIG_BACDL_CUSTOM}>:BACDL_CUSTOM>
|
||||
|
||||
# library features
|
||||
$<$<BOOL:${CONFIG_BACNET_BASIC_OBJECTS}>:BACNET_BASIC_OBJECTS>
|
||||
$<$<BOOL:${CONFIG_BACNET_PROPERTY_LISTS}>:BACNET_PROPERTY_LISTS=1>
|
||||
@@ -517,14 +519,17 @@ zephyr_compile_definitions(
|
||||
$<$<BOOL:${CONFIG_BACAPP_XY_COLOR}>:BACAPP_XY_COLOR>
|
||||
$<$<BOOL:${CONFIG_BACAPP_COLOR_COMMAND}>:BACAPP_COLOR_COMMAND>
|
||||
$<$<BOOL:${CONFIG_BACAPP_WEEKLY_SCHEDULE}>:BACAPP_WEEKLY_SCHEDULE>
|
||||
$<$<BOOL:${CONFIG_BACAPP_CALENDAR_ENTRY}>:BACAPP_CALENDAR_ENTRY>
|
||||
$<$<BOOL:${CONFIG_BACAPP_SPECIAL_EVENT}>:BACAPP_SPECIAL_EVENT>
|
||||
$<$<BOOL:${CONFIG_BACAPP_HOST_N_PORT}>:BACAPP_HOST_N_PORT>
|
||||
$<$<BOOL:${CONFIG_BACAPP_DEVICE_OBJECT_PROPERTY_REFERENCE}>:BACAPP_DEVICE_OBJECT_PROPERTY_REFERENCE>
|
||||
$<$<BOOL:${CONFIG_BACAPP_DEVICE_OBJECT_REFERENCE}>:BACAPP_DEVICE_OBJECT_REFERENCE>
|
||||
$<$<BOOL:${CONFIG_BACAPP_OBJECT_PROPERTY_REFERENCE}>:BACAPP_OBJECT_PROPERTY_REFERENCE>
|
||||
$<$<BOOL:${CONFIG_BACAPP_DESTINATION}>:BACAPP_DESTINATION>
|
||||
$<$<BOOL:${CONFIG_BACAPP_CALENDAR_ENTRY}>:BACAPP_CALENDAR_ENTRY>
|
||||
$<$<BOOL:${CONFIG_BACAPP_SPECIAL_EVENT}>:BACAPP_SPECIAL_EVENT>
|
||||
$<$<BOOL:${CONFIG_BACAPP_BDT_ENTRY}>:BACAPP_BDT_ENTRY>
|
||||
$<$<BOOL:${CONFIG_BACAPP_FDT_ENTRY}>:BACAPP_FDT_ENTRY>
|
||||
)
|
||||
$<$<BOOL:${CONFIG_BACAPP_ACTION_COMMAND}>:BACAPP_ACTION_COMMAND>
|
||||
$<$<BOOL:${CONFIG_BACAPP_SCALE}>:BACAPP_SCALE>
|
||||
$<$<BOOL:${CONFIG_BACAPP_SHED_LEVEL}>:BACAPP_SHED_LEVEL>
|
||||
)
|
||||
|
||||
+35
-6
@@ -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
|
||||
|
||||
@@ -128,4 +128,4 @@ CONFIG_BACNETSTACK_LOG_LEVEL_DBG=y
|
||||
#CONFIG_SETTINGS_SHELL=y
|
||||
|
||||
CONFIG_TEST_RANDOM_GENERATOR=y
|
||||
|
||||
CONFIG_TIMER_RANDOM_GENERATOR=y
|
||||
|
||||
@@ -5,12 +5,15 @@
|
||||
*/
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/random/random.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* 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 <zephyr/logging/log.h>
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user