diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ac1009..6fa8f8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,10 +15,18 @@ The git repository is hosted at the following site: ### Security ### Removed -* Removed BACnet basic objects and server framework into BACnet libraray - and removed zephyr version. +* Removed zephyr version of the BACnet basic objects and server framework + and placed them into BACnet Protocol Stack library. ### Fixed +* Fixed compile in BACnet/IP subsys using CONFIG_POSIX_API=y. (#47) +* Fixed missing const in bip6-init.c and used zsock API. + Replaced inet_ntoa with net_addr_ntop. Removed unnecessary select NET_SOCKETS_POSIX_NAMES. (#46) +* Fixed the BACnet light override clear shell command. (#44) +* Fixed our interface to Zephyr net manager API changes in v4.2.0. (#40) +* Fixed samples: subsys: nvs: stm32 overlays fixup. + Don't try to delete storage partitions that doesn't exist anymore. (#39) +* Fixed warning from using FD_ISSET instead of ZSOCK_FD_ISSET. (#37) * Fixed readme for sample projects. Fixed JSON for bacnet objects sub command in shell. (#31) * Fixed network port object all datalink builds. (#26) @@ -28,6 +36,8 @@ The git repository is hosted at the following site: to avoid stack overflow. ### Changed +* Change the settings restore to load only BACnet settings by using + bacnet_storage_handler.name feature. * Changed the number of sample board builds for twister to reduce minutes. * Changed pipeline to use container ghcr.io/zephyrproject-rtos/ci:v0.26-branch and build tests and samples using twister for Zephyr OS version 3.7 LTS @@ -38,8 +48,14 @@ The git repository is hosted at the following site: * Changed gitignore to ignore the build folder. ### Added +* Added BACnet Application Specific Control (B-ASC) sample. (#51) +* Added timer and audit-log objects to basic server. (#51) +* Added Model_Name config to the Kconfig for basic BACnet device. (#50) * Added KERNEL_VERSION_MAJOR check in samples DTS overlay files to handle - changes in Zephyr OS version 4 + changes in Zephyr OS version 4. (#48) +* Added shell command for lighting output overridden and tracking value. (#41) +* Added BACnet zephyr shell for device date, time, and lighting + output object. (#36) * Added BACDL ZIGBEE and BSC datalink defines to Kconfig & CMakeLists.txt (#35) * Added baclog, you-are, who-am-i, create-object, delete-object, write-group, bramfs, bsramfs, and color-rgb modules to cmake. (#35) diff --git a/README.md b/README.md index c0083ba..4c1822d 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,12 @@ A device application demonstrating configuration of a [BACnet Lighting Supervisor (B-LS) device profile](./zephyr/samples/profiles/b-ls/README.rst) that can be used with any supported boards. +### Device Profile - BACnet Application Specific Controller (B-ASC) + +A device application demonstrating configuration of a +[BACnet Application Specific Controller (B-ASC) device profile](./zephyr/samples/profiles/b-asc/README.rst) +that can be used with any supported boards. + # Coding Style and Guidelines See Zephyr Project [Coding Guidelines](https://docs.zephyrproject.org/latest/contribute/coding_guidelines/index.html) diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index 01b38c7..c7430fd 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -93,6 +93,8 @@ set(BACNETSTACK_SRCS ${BACNETSTACK_SRC}/bacnet/bacaddr.h ${BACNETSTACK_SRC}/bacnet/bacapp.c ${BACNETSTACK_SRC}/bacnet/bacapp.h + ${BACNETSTACK_SRC}/bacnet/bacaudit.c + ${BACNETSTACK_SRC}/bacnet/bacaudit.h ${BACNETSTACK_SRC}/bacnet/bacdcode.c ${BACNETSTACK_SRC}/bacnet/bacdcode.h ${BACNETSTACK_SRC}/bacnet/bacdef.h @@ -190,6 +192,7 @@ set(BACNETSTACK_SRCS ${BACNETSTACK_SRC}/bacnet/basic/object/schedule.h ${BACNETSTACK_SRC}/bacnet/basic/object/structured_view.h ${BACNETSTACK_SRC}/bacnet/basic/object/time_value.h + ${BACNETSTACK_SRC}/bacnet/basic/object/timer.h ${BACNETSTACK_SRC}/bacnet/basic/object/trendlog.h ${BACNETSTACK_SRC}/bacnet/basic/service/h_alarm_ack.h ${BACNETSTACK_SRC}/bacnet/basic/service/h_apdu.c @@ -407,6 +410,8 @@ set(BACNETSTACK_SRCS ${BACNETSTACK_SRC}/bacnet/secure_connect.h ${BACNETSTACK_SRC}/bacnet/special_event.c ${BACNETSTACK_SRC}/bacnet/special_event.h + ${BACNETSTACK_SRC}/bacnet/timer_value.c + ${BACNETSTACK_SRC}/bacnet/timer_value.h ${BACNETSTACK_SRC}/bacnet/timestamp.c ${BACNETSTACK_SRC}/bacnet/timestamp.h ${BACNETSTACK_SRC}/bacnet/timesync.c @@ -454,6 +459,7 @@ set(BACNETSTACK_BASIC_SRCS $<$:${BACNETSTACK_SRC}/bacnet/basic/object/ai.c> $<$:${BACNETSTACK_SRC}/bacnet/basic/object/ao.c> $<$:${BACNETSTACK_SRC}/bacnet/basic/object/av.c> + $<$:${BACNETSTACK_SRC}/bacnet/basic/object/auditlog.c> $<$:${BACNETSTACK_SRC}/bacnet/basic/object/bacfile.c> $<$:${BACNETSTACK_SRC}/bacnet/basic/object/bi.c> $<$:${BACNETSTACK_SRC}/bacnet/basic/object/bo.c> @@ -484,6 +490,7 @@ set(BACNETSTACK_BASIC_SRCS $<$:${BACNETSTACK_SRC}/bacnet/basic/object/schedule.c> $<$:${BACNETSTACK_SRC}/bacnet/basic/object/structured_view.c> $<$:${BACNETSTACK_SRC}/bacnet/basic/object/time_value.c> + $<$:${BACNETSTACK_SRC}/bacnet/basic/object/timer.c> $<$:${BACNETSTACK_SRC}/bacnet/basic/object/trendlog.c> ${BACNETSTACK_SRC}/bacnet/basic/service/h_alarm_ack.c ${BACNETSTACK_SRC}/bacnet/basic/service/h_arf_a.c diff --git a/zephyr/Kconfig b/zephyr/Kconfig index 5347203..509c6c1 100644 --- a/zephyr/Kconfig +++ b/zephyr/Kconfig @@ -655,12 +655,24 @@ config BACNET_BASIC_OBJECT_TIME_VALUE help Use the BACnet basic time value object +config BACNET_BASIC_OBJECT_TIMER + bool "Use the BACnet basic timer object" + default false + help + Use the BACnet basic timer + config BACNET_BASIC_OBJECT_TRENDLOG bool "Use the BACnet basic trendlog object" default false help Use the BACnet basic trendlog object +config BACNET_BASIC_OBJECT_AUDIT_LOG + bool "Use the BACnet basic audit log object" + default false + help + Use the BACnet basic audit log object + config BACNET_BASIC_DEVICE_OBJECT_VERSION string "BACnet Device default Object Version string" default "1.0.0" diff --git a/zephyr/samples/profiles/b-asc/CMakeLists.txt b/zephyr/samples/profiles/b-asc/CMakeLists.txt new file mode 100644 index 0000000..821c965 --- /dev/null +++ b/zephyr/samples/profiles/b-asc/CMakeLists.txt @@ -0,0 +1,13 @@ +# @brief CMake for BACnet basic sample +# @author Steve Karg +# @date November 2025 +# @copyright SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.13.1) + +get_filename_component(MY_PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(${MY_PROJECT_NAME}) + +target_sources(app PRIVATE src/main.c) diff --git a/zephyr/samples/profiles/b-asc/README.rst b/zephyr/samples/profiles/b-asc/README.rst new file mode 100644 index 0000000..270d852 --- /dev/null +++ b/zephyr/samples/profiles/b-asc/README.rst @@ -0,0 +1,101 @@ +.. _b-asc_sample: + +BACnet Profile B-ASC Sample +########################### + +Overview +******** + +This is a simple application demonstrating configuration of a +BACnet Application Specific Controller (B-ASC) device profile. + +L.4.3 BACnet Application Specific Controller (B-ASC) +**************************************************** + +A B-ASC is a controller with limited resources relative to an +Advanced Application Controller (B-AAC). +A B-ASC is intended for use in a specific application +and supports limited programmability. + +Data Sharing +************ + +* Ability to provide the values of any of its BACnet objects +* Ability to allow modification of some or all of its BACnet + objects by another device + +Device and Network Management +***************************** + +* Ability to respond to queries about its status +* Ability to respond to requests for information about any of its objects +* Ability to respond to communication control messages + +Requirements +************ + +* A board with Ethernet support, for instance: nucleo_f429zi + +Building and Running +******************** + +This sample can be found under :bacnet_file:`samples/profiles/b-asc` in +the BACnet tree. + +The sample can be built for several platforms - use `west boards` to +list the supported boards. + +Compile this sample for the `nucleo_f429zi` board: + + west build -b nucleo_f429zi -p always bacnet/zephyr/samples/profiles/b-asc/ + +Compile this sample for the `rpi_pico` board: + + west build -b rpi_pico -p always bacnet/zephyr/samples/profiles/b-asc/ + +Compile this sample for the `adafruit_grand_central_m4_express` board with + + west build -b adafruit_grand_central_m4_express -p always bacnet/zephyr/samples/profiles/b-asc/ + +Using the Shell +*************** + +The shell is available on some boards via virtual communication port: + + picocom --baud 115200 /dev/ttyACM0 + + Terminal ready + *** Booting Zephyr OS build v3.7.1 *** + uart:~$ + bacnet clear device devmem help history kernel net + rem resize retval shell stats + uart:~$ bacnet object list + {"object-list": [ + {"object-identifier":{"device":260127}}, + {"object-identifier":{"analog-input":1}}, + {"object-identifier":{"analog-output":1}}, + {"object-identifier":{"analog-value":1}}, + {"object-identifier":{"audit-log":1}}, + {"object-identifier":{"binary-input":1}}, + {"object-identifier":{"binary-output":1}}, + {"object-identifier":{"binary-value":1}}, + {"object-identifier":{"multi-state-input":1}}, + {"object-identifier":{"multi-state-output":1}}, + {"object-identifier":{"multi-state-value":1}}, + {"object-identifier":{"network-port":1}}, + {"object-identifier":{"calendar":1}}, + {"object-identifier":{"integer-value":1}}, + {"object-identifier":{"life-safety-point":1}}, + {"object-identifier":{"load-control":1}}, + {"object-identifier":{"lighting-output":1}}, + {"object-identifier":{"channel":1}}, + {"object-identifier":{"binary-lighting-output":1}}, + {"object-identifier":{"color":1}}, + {"object-identifier":{"color-temperature":1}}, + {"object-identifier":{"file":1}}, + {"object-identifier":{"structured-view":1}}, + {"object-identifier":{"characterstring-value":1}}, + {"object-identifier":{"time-value":1}}, + {"object-identifier":{"timer":1}}], + "object-list-size": 26} + uart:~$ \ No newline at end of file diff --git a/zephyr/samples/profiles/b-asc/boards/adafruit_grand_central_m4_express.overlay b/zephyr/samples/profiles/b-asc/boards/adafruit_grand_central_m4_express.overlay new file mode 100644 index 0000000..ddad688 --- /dev/null +++ b/zephyr/samples/profiles/b-asc/boards/adafruit_grand_central_m4_express.overlay @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2020 Google LLC. + * Copyright (c) 2024 Daikin Comfort Technologies North America, Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ +&flash0 { + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + boot_partition: partition@0 { + label = "uf2"; + reg = <0x00000000 DT_SIZE_K(16)>; + read-only; + }; + + code_partition: partition@4000 { + label = "code"; + reg = <0x4000 DT_SIZE_K(512-16-16)>; + read-only; + }; + + /* + * The final 16 KiB is reserved for the application. + * Storage partition will be used by FCB/LittleFS/NVS + * if enabled. + */ + storage_partition: partition@7c000 { + label = "storage"; + reg = <0x7c000 DT_SIZE_K(16)>; + }; + }; +}; diff --git a/zephyr/samples/profiles/b-asc/boards/nucleo_f429zi.overlay b/zephyr/samples/profiles/b-asc/boards/nucleo_f429zi.overlay new file mode 100644 index 0000000..6869691 --- /dev/null +++ b/zephyr/samples/profiles/b-asc/boards/nucleo_f429zi.overlay @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022 STMicroelectronics + * + * SPDX-License-Identifier: Apache-2.0 + */ +#if KERNEL_VERSION_MAJOR < 4 +/delete-node/ &storage_partition; +#endif + +&flash0 { + partitions { + /* Set 48KB of storage at the beginning of bank2 in order to have 3 sectors smaller than 32K + * (nvs.h: uint16_t sector_size) + */ + storage_partition: partition@100000 { + label = "storage"; + reg = <0x000100000 DT_SIZE_K(48)>; + }; + }; +}; diff --git a/zephyr/samples/profiles/b-asc/boards/rpi_pico.overlay b/zephyr/samples/profiles/b-asc/boards/rpi_pico.overlay new file mode 100644 index 0000000..f31a7e1 --- /dev/null +++ b/zephyr/samples/profiles/b-asc/boards/rpi_pico.overlay @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2021 Yonatan Schachter + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&flash0 { + reg = <0x10000000 DT_SIZE_M(2)>; + + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + /* Reserved memory for the second stage bootloader */ + second_stage_bootloader: partition@0 { + label = "second_stage_bootloader"; + reg = <0x00000000 0x100>; + read-only; + }; + + slot0_partition: partition@100 { + label = "image-0"; + reg = <0x100 (DT_SIZE_M(1) - 0xF000)>; + }; + + storage_partition: partition@1f9000 { + label = "storage"; + reg = <0x1F9000 0x00007000>; + }; + }; +}; diff --git a/zephyr/samples/profiles/b-asc/prj.conf b/zephyr/samples/profiles/b-asc/prj.conf new file mode 100644 index 0000000..6dc8a5a --- /dev/null +++ b/zephyr/samples/profiles/b-asc/prj.conf @@ -0,0 +1,169 @@ +# General config +#CONFIG_ASSERT=y +#CONFIG_ASSERT_LEVEL=2 +#CONFIG_ASSERT_VERBOSE=y + +# Compiler library config +#CONFIG_PICOLIBC=y +#CONFIG_PICOLIBC_USE_MODULE=y +#CONFIG_REQUIRES_FULL_LIBC=y +#CONFIG_MINIMAL_LIBC=y + +# system +CONFIG_KERNEL_MEM_POOL=y +CONFIG_HEAP_MEM_POOL_SIZE=8192 +CONFIG_MAIN_THREAD_PRIORITY=7 +#CONFIG_PICOLIBC=y +CONFIG_ISR_STACK_SIZE=8192 +CONFIG_MAIN_STACK_SIZE=16384 +CONFIG_IDLE_STACK_SIZE=2048 +CONFIG_INIT_STACKS=y +CONFIG_NET_TX_STACK_SIZE=8192 +CONFIG_NET_RX_STACK_SIZE=8192 +CONFIG_BACNET_BASIC_SERVER_KSLEEP=100 + +# BACnet Library +CONFIG_BACNETSTACK=y +# BACnet Library - shell +CONFIG_BACNETSTACK_BACNET_SHELL=y +CONFIG_BACNETSTACK_BACNET_BASIC_SHELL=y +# BACnet settings subsystem +CONFIG_BACNETSTACK_BACNET_SETTINGS=y +CONFIG_BACNET_SETTINGS_SHELL=y +# BACnet Library - options +CONFIG_BACNET_MAX_CHARACTER_STRING_BYTES=128 +# BACnet Library - enable example objects +CONFIG_BACNET_BASIC_OBJECT_NETWORK_PORT=y + +CONFIG_BACNET_BASIC_OBJECTS_ACCESS=y +CONFIG_BACNET_BASIC_OBJECT_ACCUMULATOR=y +CONFIG_BACNET_BASIC_OBJECT_ANALOG_INPUT=y +CONFIG_BACNET_BASIC_OBJECT_ANALOG_OUTPUT=y +CONFIG_BACNET_BASIC_OBJECT_ANALOG_VALUE=y +CONFIG_BACNET_BASIC_OBJECT_AUDIT_LOG=y +CONFIG_BACNET_BASIC_OBJECT_FILE=y +CONFIG_BACNET_BASIC_OBJECT_BINARY_INPUT=y +CONFIG_BACNET_BASIC_OBJECT_BINARY_OUTPUT=y +CONFIG_BACNET_BASIC_OBJECT_BINARY_VALUE=y +CONFIG_BACNET_BASIC_OBJECT_CALENDAR=y +CONFIG_BACNET_BASIC_OBJECT_CHANNEL=y +CONFIG_BACNET_BASIC_OBJECT_COMMAND=y +CONFIG_BACNET_BASIC_OBJECT_COLOR=y +CONFIG_BACNET_BASIC_OBJECT_COLOR_TEMPERATURE=y +CONFIG_BACNET_BASIC_OBJECTS_ACCESS=y +CONFIG_BACNET_BASIC_OBJECT_CHARACTERSTRING_VALUE=y +CONFIG_BACNET_BASIC_OBJECT_INTEGER_VALUE=y +CONFIG_BACNET_BASIC_OBJECT_LOAD_CONTROL=y +CONFIG_BACNET_BASIC_OBJECT_LIGHTING_OUTPUT=y +CONFIG_BACNET_BASIC_OBJECT_BINARY_LIGHTING_OUTPUT=y +CONFIG_BACNET_BASIC_OBJECT_LIFE_SAFETY_POINT=y +CONFIG_BACNET_BASIC_OBJECT_MULTISTATE_INPUT=y +CONFIG_BACNET_BASIC_OBJECT_MULTISTATE_OUTPUT=y +CONFIG_BACNET_BASIC_OBJECT_MULTISTATE_VALUE=y +CONFIG_BACNET_BASIC_OBJECT_NOTIFICATION_CLASS=y +CONFIG_BACNET_BASIC_OBJECT_OCTET_STRING_VALUE=y +CONFIG_BACNET_BASIC_OBJECT_POSITIVE_INTEGER_VALUE=y +CONFIG_BACNET_BASIC_OBJECT_SCHEDULE=y +CONFIG_BACNET_BASIC_OBJECT_STRUCTURED_VIEW=y +CONFIG_BACNET_BASIC_OBJECT_TIME_VALUE=y +CONFIG_BACNET_BASIC_OBJECT_TIMER=y +CONFIG_BACNET_BASIC_OBJECT_TRENDLOG=y + +# BACnet Library - server framework - includes device and ports +CONFIG_BACNET_BASIC_SERVER=y + +# BACnet Datalink Options +CONFIG_BACDL_BIP=y +CONFIG_BACDL_BIP_PORT=47808 +# don't define index if you want to use the default interface +# note: with DHCP and AutoIP enabled, index 0=AutoIP, 1=DHCP +# CONFIG_BACDL_BIP_ADDRESS_INDEX=1 + +# networking +CONFIG_NETWORKING=y +CONFIG_NET_L2_ETHERNET=y +CONFIG_NET_ARP=y +CONFIG_NET_UDP=y +CONFIG_NET_SHELL=y +CONFIG_NET_SOCKETS=y +CONFIG_NET_IPV4=y +CONFIG_NET_IPV4_LOG_LEVEL_DBG=n +CONFIG_NET_IF_MAX_IPV4_COUNT=2 +CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT=2 +CONFIG_NET_IF_MCAST_IPV4_ADDR_COUNT=2 +# Dynamic IP address +CONFIG_NET_DHCPV4=y +CONFIG_NET_DHCPV4_LOG_LEVEL_DBG=n +CONFIG_NET_IPV4_AUTO=n +CONFIG_NET_IPV4_AUTO_LOG_LEVEL_DBG=n +CONFIG_NET_ICMPV4_LOG_LEVEL_DBG=n +# read the MAC address from settings and set via net_mgmt() +CONFIG_NET_MGMT_EVENT=y +CONFIG_NET_L2_ETHERNET_MGMT=y +CONFIG_NET_CONNECTION_MANAGER=y + +# Static IP address pre-configuration +#CONFIG_NET_CONFIG_SETTINGS=y +#CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1" +#CONFIG_NET_CONFIG_MY_IPV4_NETMASK="255.255.255.0" +#CONFIG_NET_CONFIG_MY_IPV4_GW="192.0.2.2" +# Network debug config +CONFIG_NET_LOG=y +CONFIG_NET_SHELL=y + +#CONFIG_DNS_RESOLVER=y +#CONFIG_SLIP_STATISTICS=n + +# Enable Shell, Console, and Logging features +CONFIG_CONSOLE=y +CONFIG_PRINTK=y +CONFIG_SHELL=y +CONFIG_KERNEL_SHELL=y +CONFIG_THREAD_MONITOR=y +#CONFIG_BOOT_BANNER=n +CONFIG_THREAD_NAME=y +CONFIG_DEVICE_SHELL=y +#CONFIG_POSIX_CLOCK=y +#CONFIG_DATE_SHELL=y +CONFIG_LOG=y +CONFIG_LOG_BACKEND_UART=y +CONFIG_SHELL_LOG_BACKEND=n +#CONFIG_LOG_STRDUP_BUF_COUNT=4 +#CONFIG_LOG_STRDUP_MAX_STRING=96 +#CONFIG_NET_CONN_LOG_LEVEL_DEFAULT=n +#CONFIG_NET_CONN_LOG_LEVEL_DBG=y +#CONFIG_NET_IF_LOG_LEVEL_DEFAULT=n +CONFIG_NET_IF_LOG_LEVEL_DBG=n +CONFIG_NET_LOG=y + +# enable the thread, stack, and runtime stats +CONFIG_THREAD_ANALYZER=y +CONFIG_THREAD_STACK_INFO=y +CONFIG_THREAD_RUNTIME_STATS=y +#CONFIG_THREAD_RUNTIME_STATS_USE_TIMING_FUNCTIONS=n +#CONFIG_SCHED_THREAD_USAGE=y +#CONFIG_SCHED_THREAD_USAGE_ANALYSIS=y +CONFIG_STATS=y +CONFIG_STATS_SHELL=y + +# +# Storage +# +CONFIG_FLASH=y +CONFIG_FLASH_MAP=y +#CONFIG_FLASH_PAGE_LAYOUT=y +CONFIG_NVS=y +CONFIG_SETTINGS=y +CONFIG_SETTINGS_NVS=y +CONFIG_SETTINGS_RUNTIME=y +#CONFIG_SETTINGS_FILE=y +#CONFIG_SETTINGS_SHELL=y +# native_posix uses a simulated flash +#CONFIG_FLASH_SIMULATOR=y +#CONFIG_DISK_ACCESS=y. +#CONFIG_FILE_SYSTEM=y +#CONFIG_FILE_SYSTEM_LITTLEFS=y +#CONFIG_FILE_SYSTEM_SHELL=y + +CONFIG_TEST_RANDOM_GENERATOR=y +CONFIG_TIMER_RANDOM_GENERATOR=y diff --git a/zephyr/samples/profiles/b-asc/sample.yaml b/zephyr/samples/profiles/b-asc/sample.yaml new file mode 100644 index 0000000..880f864 --- /dev/null +++ b/zephyr/samples/profiles/b-asc/sample.yaml @@ -0,0 +1,34 @@ +sample: + name: BACnet Application Specific Controller (B-ASC) + +common: + platform_allow: + - nucleo_f429zi + build_only: true + +tests: + + bacnet-stack.sample.profile.b-asc.bacdl_none: + tags: bacnet + + bacnet-stack.sample.profile.b-asc.bacdl_mstp: + extra_configs: + - CONFIG_BACDL_MSTP=y + tags: introduction + + bacnet-stack.sample.profile.b-asc.bacdl_bip: + extra_configs: + - CONFIG_BACDL_BIP=y + tags: introduction + + bacnet-stack.sample.profile.b-asc.bacdl_bip6: + skip: true + extra_configs: + - CONFIG_BACDL_BIP6=y + tags: introduction + + bacnet-stack.sample.profile.b-asc.bacdl_ethernet: + skip: true + extra_configs: + - CONFIG_BACDL_ETHERNET=y + tags: introduction diff --git a/zephyr/samples/profiles/b-asc/src/main.c b/zephyr/samples/profiles/b-asc/src/main.c new file mode 100644 index 0000000..a4c1a11 --- /dev/null +++ b/zephyr/samples/profiles/b-asc/src/main.c @@ -0,0 +1,169 @@ +/** + * @file + * @brief BACnet Stack sample Application Specific Controller (B-ASC) main file + * @author Steve Karg + * @date November 2025 + * @copyright SPDX-License-Identifier: Apache-2.0 + */ +#include +#include +#include +#include + +/* BACnet Stack defines - first */ +#include "bacnet/bacdef.h" +/* BACnet Stack core API */ +#include "bacnet/version.h" +#include "bacnet/datetime.h" +#include "bacnet/bactext.h" +#include "bacnet/basic/services.h" +#include "bacnet/basic/sys/mstimer.h" +#include "bacnet/basic/sys/linear.h" +/* BACnet Stack basic device API - + see bacnet/basic/server/bacnet_device.c for details */ +#include "bacnet/basic/object/device.h" +/* BACnet Stack basic objects */ +#include "bacnet/basic/object/access_credential.h" +#include "bacnet/basic/object/access_door.h" +#include "bacnet/basic/object/access_point.h" +#include "bacnet/basic/object/access_rights.h" +#include "bacnet/basic/object/access_user.h" +#include "bacnet/basic/object/access_zone.h" +#include "bacnet/basic/object/acc.h" +#include "bacnet/basic/object/ai.h" +#include "bacnet/basic/object/ao.h" +#include "bacnet/basic/object/av.h" +#include "bacnet/basic/object/bacfile.h" +#include "bacnet/basic/object/bi.h" +#include "bacnet/basic/object/bitstring_value.h" +#include "bacnet/basic/object/blo.h" +#include "bacnet/basic/object/bo.h" +#include "bacnet/basic/object/bv.h" +#include "bacnet/basic/object/calendar.h" +#include "bacnet/basic/object/channel.h" +#include "bacnet/basic/object/color_object.h" +#include "bacnet/basic/object/color_temperature.h" +#include "bacnet/basic/object/command.h" +#include "bacnet/basic/object/credential_data_input.h" +#include "bacnet/basic/object/csv.h" +#include "bacnet/basic/object/iv.h" +#include "bacnet/basic/object/lc.h" +#include "bacnet/basic/object/lo.h" +#include "bacnet/basic/object/lsp.h" +#include "bacnet/basic/object/lsz.h" +#include "bacnet/basic/object/ms-input.h" +#include "bacnet/basic/object/mso.h" +#include "bacnet/basic/object/msv.h" +#include "bacnet/basic/object/nc.h" +#include "bacnet/basic/object/osv.h" +#include "bacnet/basic/object/piv.h" +#include "bacnet/basic/object/program.h" +#include "bacnet/basic/object/schedule.h" +#include "bacnet/basic/object/structured_view.h" +#include "bacnet/basic/object/time_value.h" +#include "bacnet/basic/object/timer.h" +#include "bacnet/basic/object/trendlog.h" +#include "bacnet/basic/object/netport.h" +#include "bacnet/basic/server/bacnet_basic.h" +#include "bacnet/basic/server/bacnet_port.h" +/* BACnet Stack Zephyr services */ +#include +/* Logging module registration is already done in ports/zephyr/main.c */ +#include +LOG_MODULE_DECLARE(bacnet, CONFIG_BACNETSTACK_LOG_LEVEL); + +/* Default values before we get the device instance and name from settings */ +static const uint32_t Device_Instance = 260127; +static const char *Device_Name = + "BACnet Application Specific Controller (B-ASC)"; + +/** + * @brief Callback data for WriteProperty restore iterator + * @param write_function The WriteProperty function to call + * @param context The context to pass to the WriteProperty function + * @return true if the WriteProperty succeeded + */ +static bool +Settings_Restore_Callback(BACNET_WRITE_PROPERTY_DATA *wp_data, void *context) +{ + (void)context; + return Device_Write_Property(wp_data); +} + +/** + * @brief BACnet Project Initialization Handler + * @param context [in] The context to pass to the callback function + * @note This is called from the BACnet task + */ +static void BACnet_Device_Init_Handler(void *context) +{ + BACNET_CREATE_OBJECT_DATA object_data = { 0 }; + unsigned int i = 0; + + (void)context; + LOG_INF("BACnet Stack Initialized"); + /* create some dynamically created objects as examples */ + object_data.object_instance = BACNET_MAX_INSTANCE; + for (i = 0; i <= BACNET_OBJECT_TYPE_RESERVED_MIN; i++) { + object_data.object_type = i; + if (Device_Create_Object(&object_data)) { + LOG_INF( + "Created object %s-%u\n", bactext_object_type_name(i), + (unsigned)object_data.object_instance); + } + } + /* initialize objects with default values for this basic sample */ + Device_Set_Object_Instance_Number(Device_Instance); + Device_Object_Name_ANSI_Init(Device_Name); + /* restore any property values previously stored via WriteProperty */ + bacnet_settings_init(); + bacnet_settings_write_property_restore(&Settings_Restore_Callback, NULL); + /* writable property values are stored with WriteProperty. + Set this callback after restore to prevent recursion. */ + bacnet_basic_store_callback_set(bacnet_settings_basic_store); + apdu_set_unconfirmed_handler( + SERVICE_UNCONFIRMED_WRITE_GROUP, handler_write_group); + /* initialize timesync callback function. */ + /* local time and date */ + apdu_set_unconfirmed_handler( + SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, handler_timesync); + handler_timesync_set_callback_set(datetime_timesync); + datetime_init(); + /* done */ + LOG_INF("BACnet Device ID: %u", Device_Object_Instance_Number()); + bacnet_basic_task_object_timer_set(1000UL); + srand(sys_rand32_get()); +} + +/** + * @brief BACnet Project Task Handler + * @param context [in] The context to pass to the callback function + * @note This is called from the BACnet task + */ +static void BACnet_Device_Task_Handler(void *context) +{ + (void)context; +} + +int main(void) +{ + bool port_initialized = false; + + LOG_INF("BACnet Device: %s", Device_Name); + LOG_INF("BACnet Stack Version " BACNET_VERSION_TEXT); + LOG_INF("BACnet Stack Max APDU: %d", MAX_APDU); + bacnet_basic_init_callback_set(BACnet_Device_Init_Handler, NULL); + bacnet_basic_task_callback_set(BACnet_Device_Task_Handler, NULL); + bacnet_basic_init(); + for (;;) { + k_sleep(K_MSEC(CONFIG_BACNET_BASIC_SERVER_KSLEEP)); + bacnet_basic_task(); + if (port_initialized) { + bacnet_port_task(); + } else { + port_initialized = bacnet_port_init(); + } + } + + return 0; +} diff --git a/zephyr/samples/profiles/b-ld/README.rst b/zephyr/samples/profiles/b-ld/README.rst index b488408..65e6931 100644 --- a/zephyr/samples/profiles/b-ld/README.rst +++ b/zephyr/samples/profiles/b-ld/README.rst @@ -1,4 +1,4 @@ -.. _b-ss_sample: +.. _b-ld_sample: BACnet Profile B-LD Sample ########################## diff --git a/zephyr/samples/profiles/b-ls/README.rst b/zephyr/samples/profiles/b-ls/README.rst index 2ac5896..c0eca10 100644 --- a/zephyr/samples/profiles/b-ls/README.rst +++ b/zephyr/samples/profiles/b-ls/README.rst @@ -1,4 +1,4 @@ -.. _b-ss_sample: +.. _b-ls_sample: BACnet Profile B-LS Sample ########################## @@ -83,4 +83,3 @@ The shell is available on some boards via virtual communication port: {"object-identifier":{"channel":1}}, {"object-identifier":{"binary-lighting-output":1}}], "object-list-size": 5} - diff --git a/zephyr/samples/profiles/b-sa/README.rst b/zephyr/samples/profiles/b-sa/README.rst index 7f13e86..5115534 100644 --- a/zephyr/samples/profiles/b-sa/README.rst +++ b/zephyr/samples/profiles/b-sa/README.rst @@ -1,4 +1,4 @@ -.. _b-ss_sample: +.. _b-sa_sample: BACnet Profile B-SA Sample ##########################