From d2c1409306568465b069105beb64527cb4d2f004 Mon Sep 17 00:00:00 2001 From: SWS-Chipkin Date: Tue, 15 Sep 2026 00:33:12 -0700 Subject: [PATCH 1/2] build: pin the CAS BACnet Stack at 6.x @ abd4cee1 (6.0.21) Co-Authored-By: Claude --- .gitmodules | 1 + submodules/cas-bacnet-stack | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index b1c92c8..c02c14f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,4 @@ [submodule "submodules/cas-bacnet-stack"] path = submodules/cas-bacnet-stack url = https://github.com/chipkin/cas-bacnet-stack.git + branch = 6.x diff --git a/submodules/cas-bacnet-stack b/submodules/cas-bacnet-stack index 756371c..abd4cee 160000 --- a/submodules/cas-bacnet-stack +++ b/submodules/cas-bacnet-stack @@ -1 +1 @@ -Subproject commit 756371c1de656c30c85c6eeb875cdd49c93481ca +Subproject commit abd4cee1c7f28ca8e1af4720849c4081082bbe82 From aa23c354bc50219ee2271b8fee70074cb80c1637 Mon Sep 17 00:00:00 2001 From: SWS-Chipkin Date: Tue, 15 Sep 2026 01:12:27 -0700 Subject: [PATCH 2/2] feat: update to CAS BACnet Stack 6.x (abd4cee1), STATIC link, common/ 2.1.0 - Pin the stack to 6.x @ abd4cee1 (6.0.21), tracking the 6.x branch. - Link the CAS BACnet Stack as a prebuilt STATIC library (CAS_BACNET_STACK_LINK=STATIC, built by tools/build-stack-static.sh) instead of SOURCE mode; forces the /MT static MSVC runtime. No DLL mode documented or shipped. - Every GetProperty* callback gains a trailing uint32_t* errorCode out-parameter (stack issue #974); State_Text with an out-of-range array index now answers Error(property, invalid-array-index) instead of an empty string. Every other catch-all `return false` deliberately leaves errorCode alone, per the stack's decline-and-fabricate fallback for properties this device does not serve. - BACnetStack_AddNetworkPortObjectWithNetworkNumber() renamed to BACnetStack_AddNetworkPortObject() (same arguments). - CASExampleHelper::SetNetworkPortInstance() is now called before RegisterCommonCallbacks(), since links are identified by Network Port object instance rather than network type. - common/ replaced wholesale with the series-wide vendored copy at 2.1.0 (up from 1.5.1), byte-identical to BACnetProfileExample-B-SS-CPP/common/. - APP_VERSION bumped to 1.2.0 (MINOR). - Docs regenerated: docs/objects.json (new) + the generated Objects and properties README block (zero warning rows), the series profile table synced into README, CHANGELOG unreleased entry, AGENTS.md rewritten to the 8-section template, .github/workflows/release.yml replaced with the proven Wave 0 STATIC-library template (names substituted only). Verified: local build is STATIC (CAS_BACNET_STACK_LINK:STRING=STATIC in CMakeCache.txt, /MT forced), zero warnings from main.cpp/common/. Smoke test prints CAS BACnet Stack version 6.0.21.0, common/ 2.1.0, binds UDP, sends a broadcast I-Am, and stays up; --help/--version exit 0; --deviceID overrides the announced instance. F-DCC (DM-DCC-B) verified on the wire with a real BACnet client (bacpypes3, confirmed-service round trip against the running executable): DeviceCommunicationControl disable-initiation with a wrong password -> Error(security, password-failure); the same with the right password -> SimpleAck (stops initiating); enable with the right password -> SimpleAck (restores); plain disable (deprecated at Protocol_Revision >= 20) -> Error(services, service-request-denied). tools/check-series.sh BACnetProfileExample-B-ASC-CPP -> SERIES CHECK PASSED. Co-Authored-By: Claude --- .github/workflows/release.yml | 154 +++++---- AGENTS.md | 27 +- CHANGELOG.md | 68 ++++ CMakeLists.txt | 20 +- README.md | 411 ++++++++++++++++++------ common/CASBACnetStackExampleConstants.h | 12 +- common/CASExampleHelper.cpp | 45 ++- common/CASExampleHelper.h | 28 +- common/CHANGELOG.md | 47 +++ common/README.md | 2 +- docs/objects.json | 89 +++++ main.cpp | 68 +++- 12 files changed, 774 insertions(+), 197 deletions(-) create mode 100644 docs/objects.json diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 82106d3..7513475 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,26 +1,20 @@ -# Build the B-ASC example and publish a GitHub Release when a vX.Y.Z tag is pushed. +# Build the B-ASC example against the CAS BACnet Stack STATIC library and publish a GitHub +# Release (binaries + metrics.json) when a vX.Y.Z tag is pushed. PRs and pushes to main run +# the same build + smoke test without publishing. # -# The CAS BACnet Stack is a PRIVATE git submodule. GitHub Actions' default token -# cannot read another private repo, so set a repository secret named -# CAS_STACK_PAT to a Personal Access Token that has read access to -# chipkin/cas-bacnet-stack. Without it the submodule checkout will fail. +# The CAS BACnet Stack is a PRIVATE git submodule: the repository secret CAS_STACK_PAT must +# hold a PAT with read access to chipkin/cas-bacnet-stack. name: build-and-release on: - # Guard, not just publish. Without a pull_request trigger this workflow only - # ever fired on a version tag - so a commit that broke main.cpp stayed green - # until someone cut a release, and then the RELEASE failed. That is the most - # expensive moment to find out. The build + smoke test below are the same - # either way; only the `release` job is gated on the tag - a PR builds and smoke-tests, it does not publish. pull_request: push: branches: [main] - tags: - - "v*.*.*" # e.g. v1.0.0 - workflow_dispatch: # also allow manual runs + tags: ["v*.*.*"] + workflow_dispatch: permissions: - contents: write # needed to create the Release + contents: write jobs: build: @@ -30,16 +24,19 @@ jobs: fail-fast: false matrix: include: - - os: windows-latest + # windows-2022, not windows-latest: the stack's vcxproj names the v143 (VS 2022) + # toolset; newer images may not carry it. + - os: windows-2022 artifact: BACnetExampleBASC-windows-x64 exe: build/Release/BACnetExampleBASC.exe + lib: submodules/cas-bacnet-stack/bin/CASBACnetStack_x64_Release.lib + metrics: metrics-windows.json - os: ubuntu-latest artifact: BACnetExampleBASC-linux-x64 exe: build/BACnetExampleBASC + lib: submodules/cas-bacnet-stack/bin/libCASBACnetStack_x64_Release.a + metrics: metrics-linux.json steps: - # The CAS BACnet Stack submodule has deeply-nested paths (googletest - # packages) that exceed Windows' 260-char MAX_PATH; enable long paths so - # the submodule checkout succeeds. - name: Enable git long paths (Windows) if: runner.os == 'Windows' run: git config --system core.longpaths true @@ -48,60 +45,108 @@ jobs: uses: actions/checkout@v4 with: submodules: recursive - # PAT with read access to the private stack repo; falls back to the - # default token (which only works if the stack is made accessible). token: ${{ secrets.CAS_STACK_PAT || github.token }} - # Published binaries are built with CAS_BACNET_STACK_LINK=SOURCE - the stack is - # compiled from source straight into the executable. Stated EXPLICITLY rather than - # relying on it being the CMake default, because what we publish must not change if - # that default ever moves. - # - # Why SOURCE for a release: the artifact is a single self-contained executable. STATIC - # would need a prebuilt library built and matched here first, and DLL would require - # shipping CASBACnetStack_x64_Release.dll alongside the exe and would fail at start-up - # for anyone who downloaded only the binary. Those two modes are for integrators - # choosing them deliberately in their own build, not for a downloadable demo. - - name: Configure (SOURCE link mode - self-contained binary) - run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DCAS_BACNET_STACK_LINK=SOURCE + - name: Stack commit (cache key) + id: stack + shell: bash + run: echo "sha=$(git -C submodules/cas-bacnet-stack rev-parse HEAD)" >> "$GITHUB_OUTPUT" + + # The static library depends only on the stack commit, so it is cached on that SHA. + # A moved pin therefore always rebuilds it - a stale library against a new header is + # an ABI mismatch that links and misbehaves. + - name: Restore the prebuilt static library + id: libcache + uses: actions/cache@v4 + with: + path: submodules/cas-bacnet-stack/bin + key: cas-stack-static-${{ runner.os }}-${{ steps.stack.outputs.sha }} + + - name: Build the CAS BACnet Stack static library (ReleaseLib, customer surface only) + if: steps.libcache.outputs.cache-hit != 'true' + shell: bash + run: | + set -e + if [ "$RUNNER_OS" = "Windows" ]; then + # microsoft/setup-msbuild's PATH update does not reach this Git-Bash step + # (msbuild: command not found even after that step ran), so resolve it + # directly the same way tools/build-stack-static.sh does locally. + vswhere='/c/Program Files (x86)/Microsoft Visual Studio/Installer/vswhere.exe' + MSBUILD=$("$vswhere" -latest -requires Microsoft.Component.MSBuild -find 'MSBuild\**\Bin\MSBuild.exe' | head -1) + # The vcxproj names PlatformToolset=v145; windows-2022 only carries the VS 2022 + # v143 build tools, so force v143 (MSB8020 otherwise: "build tools for v145 ... + # cannot be found"). CMake's own "Visual Studio 17 2022" generator resolves to + # the same v143 toolset on this runner, so the two stay compiler-matched. + "$MSBUILD" submodules/cas-bacnet-stack/projects/msvs/CASBACnetStack/CASBACnetStack.vcxproj -p:Configuration=ReleaseLib -p:Platform=x64 -p:PlatformToolset=v143 -m -v:minimal + else + make -C submodules/cas-bacnet-stack/projects/linux/Release/x64 -j"$(nproc)" all + make -C submodules/cas-bacnet-stack/projects/linux/Release/x64 install + fi + ls -l "${{ matrix.lib }}" + + - name: Configure (STATIC link mode) + run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DCAS_BACNET_STACK_LINK=STATIC - name: Confirm the link mode CMake actually used shell: bash run: | - # Fail loudly if the cache does not say SOURCE - a published binary that silently - # needs a DLL beside it is the failure we are guarding against. - # Anchor on the colon: without it this also matches the - # CAS_BACNET_STACK_LINK-STRINGS:INTERNAL=SOURCE;STATIC;DLL helper entry and the - # comparison below never matches. mode=$(grep -E '^CAS_BACNET_STACK_LINK:' build/CMakeCache.txt | cut -d= -f2) echo "CAS_BACNET_STACK_LINK=$mode" - [ "$mode" = "SOURCE" ] || { echo "FAIL: expected SOURCE, got '$mode'"; exit 1; } + [ "$mode" = "STATIC" ] || { echo "FAIL: expected STATIC, got '$mode'"; exit 1; } - name: Build run: cmake --build build --config Release - - name: Smoke test (starts, binds, and stays up) + - name: Smoke test + metrics (starts, binds, stays up; measures time to 'ready') shell: bash run: | - # Non-default port: runbook 5.0 / gotcha 2 - 47808 may already be in use on - # the runner or by another BACnet device, which would make a healthy - # device look broken. + start=$(date +%s%3N) "${{ matrix.exe }}" --port 47821 > smoke.log 2>&1 & PID=$! - sleep 3 - if kill -0 "$PID" 2>/dev/null; then - kill "$PID" 2>/dev/null || true - else - echo "FAIL: device exited early"; cat smoke.log; exit 1 - fi - grep -q "ready" smoke.log || { echo "FAIL: no 'ready' line"; cat smoke.log; exit 1; } - echo "OK:"; cat smoke.log + ready_ms="" + for i in $(seq 1 100); do + if grep -q "ready" smoke.log; then ready_ms=$(( $(date +%s%3N) - start )); break; fi + sleep 0.1 + done + sleep 2 + if kill -0 "$PID" 2>/dev/null; then kill "$PID" 2>/dev/null || true; else echo "FAIL: device exited early"; cat smoke.log; exit 1; fi + [ -n "$ready_ms" ] || { echo "FAIL: no 'ready' line"; cat smoke.log; exit 1; } + cat smoke.log + bytes=$(stat -c %s "${{ matrix.exe }}" 2>/dev/null || wc -c < "${{ matrix.exe }}") + sha=$(sha256sum "${{ matrix.exe }}" | cut -c1-16) + stackver=$(grep -oE 'CAS BACnet Stack version: [0-9.]+' smoke.log | head -1 | grep -oE '[0-9.]+' || true) + appver=$(grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+' smoke.log | head -1 || true) + # CMAKE_CXX_COMPILER is not a CMakeCache.txt entry under the multi-config Visual + # Studio generator (only single-config generators like the Linux Unix Makefiles + # one cache it directly) - grep finding nothing here is expected on Windows, and + # with pipefail that makes the pipeline's exit status non-zero, so `|| true` keeps + # a genuinely missing compiler string from aborting the whole metrics step. + compiler=$(grep -E '^CMAKE_CXX_COMPILER_VERSION|^CMAKE_CXX_COMPILER:' build/CMakeCache.txt | head -2 | tr '\n' ' ' || true) + [ -n "$compiler" ] || compiler="$(grep -E '^CMAKE_GENERATOR:' build/CMakeCache.txt | cut -d= -f2 || true) ${{ matrix.os }}" + cat > "${{ matrix.metrics }}" <> "$GITHUB_STEP_SUMMARY" - name: Package shell: bash run: | mkdir -p dist - cp "${{ matrix.exe }}" dist/ + cp "${{ matrix.exe }}" "${{ matrix.metrics }}" dist/ cp README.md LICENSE dist/ 2>/dev/null || true - name: Upload build artifact @@ -116,13 +161,10 @@ jobs: if: startsWith(github.ref, 'refs/tags/v') runs-on: ubuntu-latest steps: - - name: Download all build artifacts - uses: actions/download-artifact@v4 + - uses: actions/download-artifact@v4 with: path: artifacts - - - name: Create GitHub Release - uses: softprops/action-gh-release@v2 + - uses: softprops/action-gh-release@v2 with: name: ${{ github.ref_name }} generate_release_notes: true diff --git a/AGENTS.md b/AGENTS.md index 92c16db..a716aa7 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -18,22 +18,29 @@ cleverness. This repository is self-contained: - `main.cpp` - the example device. -- `common/` - the shared helper (vendored). +- `common/` - the shared helper, vendored in-repo (not referenced via a path + outside the repository). - `submodules/cas-bacnet-stack/` - the **CAS BACnet Stack** as a git submodule - (private; compiled from source). After cloning, run - `git submodule update --init --recursive`. + (private). After cloning, run `git submodule update --init --recursive`. ## Build +This example links the CAS BACnet Stack as a prebuilt **STATIC** library - build +the library once from the pinned submodule commit, then configure and build: + ```bash git submodule update --init --recursive # once, if not cloned with --recursive -cmake -B build -S . +tools/build-stack-static.sh BACnetProfileExample-B-ASC-CPP # from the series root +cmake -B build -S . -DCAS_BACNET_STACK_LINK=STATIC cmake --build build --config Release ``` -The first build compiles the whole stack (~600 files) and takes a few minutes; -later incremental builds are fast. Use `-D CAS_STACK_DIR=...` only if your stack -lives outside the bundled submodule. +The stack library build compiles the whole stack (~600 files) once and takes a +few minutes; the example itself then builds in seconds, and later incremental +rebuilds are fast. Use `-D CAS_STACK_DIR=...` only if your stack lives outside +the bundled submodule. The adapter also offers a SOURCE mode (compiles the +stack straight into the executable, no library build); this example builds and +ships STATIC only. ## Run @@ -57,6 +64,12 @@ Interactive keys while running: `h` help, `q` quit, up/down nudge Analog Input 1 machine; the `DeviceCommunicationControl` callback just validates `DCC_PASSWORD` and logs. The deprecated plain `disable` (1) is rejected by the stack at Protocol_Revision >= 20 - only `enable` (0) and `disable-initiation` (2) apply. + This callback has no fallback error code: it must set `*errorCode` on every + `false` return. +- Every `GetProperty*` callback ends with `uint32_t* errorCode`. Leave it alone + on a catch-all decline (the stack's decline-and-fabricate default answers + required properties this app does not serve); set it only where this device + knows the read is wrong (`State_Text` out of range is the one case here). - Match the surrounding code style: `const`-correct parameters, check every stack return value, keep `main.cpp` linear and well-commented. - **Never edit `common/` in this repo alone** - it is a vendored copy shared by diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fc762a..3aff8ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,73 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.2.0] - unreleased + +### Changed — STATIC link, generated README blocks + +- **Stack re-pinned to `6.x` @ `abd4cee1` (reports itself as 6.0.21), tracking the + `6.x` branch** (`.gitmodules` `branch = 6.x`), up from `6.x-TestTool` @ + `756371c1`. +- **Links the CAS BACnet Stack as a prebuilt STATIC library** + (`CAS_BACNET_STACK_LINK=STATIC`, built by `tools/build-stack-static.sh` from the + stack's own project files) instead of compiling the stack from `source/` into + this project. `CMakeLists.txt`, the README "Link mode" section and + `AGENTS.md` now describe STATIC only; the adapter's SOURCE mode gets one + line noting it exists. No DLL mode is documented or shipped. +- **`.github/workflows/release.yml` rewritten**: builds the STATIC library (cached + on the submodule SHA), asserts `CAS_BACNET_STACK_LINK=STATIC` from + `CMakeCache.txt`, and publishes `metrics-windows.json` / `metrics-linux.json` + (binary size, SHA-256 prefix, start-up time to `ready`, stack commit, link + mode, compiler) as release assets alongside the binaries. +- **README gained three generated/filled sections**: `## Objects and properties` + (from `docs/objects.json` via `tools/gen-objects-properties.py`), `## The + BACnet profile example series` (the series profile table, via + `tools/sync-profile-table.sh`), and `## Footprint` (filled from + `metrics-*.json` at release; currently the placeholder row). + +### Changed — updated to the current CAS BACnet Stack interface + +Three interface changes reach this example versus the prior `6.x-TestTool` pin +`756371c1`; the full list, with before/after signatures, is on cas-bacnet-stack +issue #1641. + +- **Every `GetProperty*` callback gained a trailing `uint32_t* errorCode`** + (stack issue #974). The stack presets it to `success` and reads it only on a + `false` return, so a declining callback can now name the BACnet error the + client receives. `main.cpp` uses it in exactly one place — `State_Text` with an + out-of-range array index now answers `Error(property, invalid-array-index)` + instead of an empty string — and deliberately leaves it alone on every + catch-all `return false`, because the stack's decline-and-fabricate fallback is + what answers required properties this application does not serve (the Device's + `Max_APDU_Length_Accepted`, `APDU_Timeout` and `Number_Of_APDU_Retries`). The + `DeviceCommunicationControl` callback is the one place in this file where + `*errorCode` has no fallback and must be set on every `false` return, as its + commentary explains. +- **`BACnetStack_AddNetworkPortObjectWithNetworkNumber()` is gone**, folded into + `BACnetStack_AddNetworkPortObject()`, which now always takes the network number + and its quality. Same arguments, one function. +- **Links are identified by Network Port object instance, not network type** + (stack issues #822/#556) — the transport callbacks and `SendIAm` all changed. + Handled in `common/`; `main.cpp` calls the new + `CASExampleHelper::SetNetworkPortInstance()` before + `RegisterCommonCallbacks()`. + +`common/` is replaced wholesale with the series-wide vendored copy at **2.1.0** +(up from `1.5.1`; see `common/CHANGELOG.md` for its full history) — identical +byte-for-byte across every example in the series. + +### Verified + +Built on Windows/MSVC (STATIC link) and exercised against a BACnet client: +Who-Is → I-Am (device 389003, vendor 389); ReadProperty of every required +property of all eight objects returns the expected value, `Protocol_Revision` +is 24 and `Object_List` lists all eight; WriteProperty to each commandable +output at two priorities followed by a NULL relinquish falls back correctly to +`Relinquish_Default`; DeviceCommunicationControl accepts `enable` and +`disable-initiation`, rejects the deprecated plain `disable` with +`service-request-denied`, and (with `DCC_PASSWORD` set) rejects a wrong +password with `password-failure`. + ## [1.1.0] - unreleased > Not tagged yet: `v1.0.0` is the only tag in this repository, so there is no @@ -136,5 +203,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - GitHub Actions workflow that builds Windows + Linux and publishes a release on a `vX.Y.Z` tag, with a smoke-test step before packaging. +[1.2.0]: https://github.com/chipkin/BACnetProfileExample-B-ASC-CPP/compare/v1.0.0...HEAD [1.1.0]: https://github.com/chipkin/BACnetProfileExample-B-ASC-CPP/compare/v1.0.0...HEAD [1.0.0]: https://github.com/chipkin/BACnetProfileExample-B-ASC-CPP/releases/tag/v1.0.0 diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a4d96a..cb06275 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,19 +3,17 @@ # # This example links the CAS BACnet Stack through the CASBACnetStack::Adapter CMake # target (submodules/cas-bacnet-stack/adapters/cpp) and calls the stack's C API -# (BACnetStack_*, via CASBACnetStackAdapter.h) directly - no fp* indirection, the same -# call in every link mode. CAS_BACNET_STACK_LINK picks the mode (see below); it defaults -# to SOURCE, which compiles every file in the stack's source/ folder straight into the -# executable - there is no DLL/.so to build, copy, or ship first. -# -# NOTE: the first SOURCE-mode build compiles the entire stack (~600 source files), so it -# takes a few minutes. Subsequent incremental builds are fast. +# (BACnetStack_*, via CASBACnetStackAdapter.h) directly. This example builds and +# ships in STATIC mode: CAS_BACNET_STACK_LINK=STATIC links a prebuilt +# CASBACnetStack_x64_Release.lib / libCASBACnetStack_x64_Release.a, built first by +# tools/build-stack-static.sh from the stack's own project files. (The adapter also +# offers a SOURCE mode that compiles the stack's source/ straight into the +# executable with no separate library build; this example is not built that way.) # # Build: -# cmake -B build -S . -# cmake --build build --config Release -# Build against a prebuilt DLL/.so instead of compiling from source: -# cmake -B build -S . -DCAS_BACNET_STACK_LINK=DLL +# tools/build-stack-static.sh BACnetProfileExample-B-ASC-CPP (from the series root) +# cmake -B build -S . -DCAS_BACNET_STACK_LINK=STATIC +# cmake --build build --config Release --parallel # Run (from the example folder): # ./build/BACnetExampleBASC (Linux/macOS) # .\build\Release\BACnetExampleBASC.exe (Windows) diff --git a/README.md b/README.md index 9e1f648..89ceebc 100644 --- a/README.md +++ b/README.md @@ -16,11 +16,11 @@ Sensor)](https://github.com/chipkin/BACnetProfileExample-B-SS-CPP) is the first series and [B-SA (Smart Actuator)](https://github.com/chipkin/BACnetProfileExample-B-SA-CPP) the second; this is the third and repeats everything it needs. -> **Versions:** this document describes **example v1.1.0**, built and verified -> against **CAS BACnet Stack 6.x** at **Protocol_Revision 24**, with the -> vendored `common/` helper at **v1.5.1**. Running the example prints all three — -> if what it prints disagrees with this line, trust the program and check -> `CHANGELOG.md`. +> **Versions:** this document describes **example v1.2.0**, built and verified +> against **CAS BACnet Stack 6.0.21** (`6.x` @ `abd4cee1`), linked as a static +> library, at **Protocol_Revision 24**, with the vendored `common/` helper at +> **v2.1.0**. Running the example prints all three - if what it prints +> disagrees with this line, trust the program and check `CHANGELOG.md`. > > **Protocol_Revision** is the revision of the ASHRAE 135 standard a device claims to conform > to. It is a number every BACnet device advertises, and it changes real behaviour: at revision @@ -36,13 +36,13 @@ Then: ```bash git clone --recursive https://github.com/chipkin/BACnetProfileExample-B-ASC-CPP.git cd BACnetProfileExample-B-ASC-CPP -cmake -B build -S . +tools/build-stack-static.sh BACnetProfileExample-B-ASC-CPP # from the series root; builds the static library +cmake -B build -S . -DCAS_BACNET_STACK_LINK=STATIC cmake --build build --config Release ./build/Release/BACnetExampleBASC.exe # Windows; drop Release/ on Linux ``` The device announces itself, answers Who-Is, and prints `Press 'h' for help`. -The first build compiles the whole stack (~600 files) and takes a few minutes. > **You will see one or more red `Error:` lines at start-up. The device is fine** — > it hears its own broadcast I-Am and the stack logs a benign decode cascade. See @@ -124,12 +124,37 @@ The CAS BACnet Stack runs the actual enable/disable state machine and the re-enable timer; this example's callback (`DeviceCommunicationControl` in `main.cpp`) just **validates the password** and logs what was asked. +Concretely, the callback: + +1. Rejects a request for any device instance other than this one, naming + `optional-functionality-not-supported` on the wire. +2. Compares the supplied password to `DCC_PASSWORD` by **length first, then + bytes** - never `strcmp`, because a BACnet CharacterString may legitimately + contain an embedded NUL that `strcmp` would silently stop at. A device with + no configured password (`DCC_PASSWORD == ""`, the shipped default) accepts + any request. A mismatch is rejected with `*errorCode = + ERROR_CODE_PASSWORD_FAILURE`, which the stack pairs with `Error Class = + SECURITY` (clause 16.1.1.3.1). +3. On a correct (or absent) password, accepts and logs the requested action - + `enable`, the deprecated `disable`, or `disable-initiation` - and the + optional time duration. +4. **Sets `*errorCode` on every `false` return, with no exception.** Unlike the + `SetProperty*` callbacks (which have a sensible `writeAccessDenied` + fallback), DeviceCommunicationControl has no default: the stack presets + `*errorCode` to `success` (84) and, on `false`, answers `Error Class = + SECURITY` when the code is `password-failure` or `Error Class = SERVICES` + otherwise. Returning `false` without setting `*errorCode` puts the literal + nonsense "Error Code = success(84)" on the wire - `main.cpp` never does + that. + > **Protocol_Revision >= 20 note:** the plain **`disable`** value (stop initiating > *and* responding) is **deprecated**. At Protocol_Revision 24 the stack rejects it > with `service-request-denied`; the modern choice is **`disable-initiation`** (the > device keeps answering reads but stops initiating). So in practice only > `enable` and `disable-initiation` take effect - the example demonstrates exactly -> this. +> this, and its callback still logs what the client asked for even on that +> deprecated path, since the rejection happens in the stack after the callback +> returns. The example ships with **no password** (`DCC_PASSWORD = ""`, accept any request). Set it to your device's secret to require one; a mismatch is rejected with @@ -257,25 +282,9 @@ This is a **self-contained** project. It ships: - `main.cpp` - the example device. - `common/` - the shared helper (UDP, callbacks, CLI, keyboard) vendored in. - `submodules/cas-bacnet-stack/` - the **CAS BACnet Stack as a git submodule** - (private; requires a license - see above). Compiled from source; no prebuilt - library or DLL is shipped. - -## Footprint & performance - -This example statically compiles the **entire** CAS BACnet Stack into one -executable (no external runtime/DLL). Release-build sizes of the whole -application (stack + example): - -| Platform | Binary | Size | -|----------|--------|------| -| Windows x64 (MSVC, Release) | `BACnetExampleBASC.exe` | ~3.0 MB | -| Linux x64 (GCC, Release) | `BACnetExampleBASC` | ~6 MB unstripped (`strip` cuts it substantially) | - -These are whole-application sizes. The stack's flash/RAM footprint on a -constrained MCU, CPU cost per `BACnetStack_Tick()`, request latency, and the -maximum number of objects depend on your target and configuration. For -embedded-sizing and benchmark figures, contact Chipkin - -. + (private; requires a license - see above). Built into a prebuilt **STATIC** + library by the stack's own project files (`tools/build-stack-static.sh`), + then linked - no DLL is shipped. ## Prerequisites @@ -309,13 +318,22 @@ git submodule update --init --recursive ## Build +This example links the CAS BACnet Stack as a prebuilt **STATIC** library. Build +the library once from the pinned submodule commit, then configure and build the +example against it: + ```bash -cmake -B build -S . +tools/build-stack-static.sh BACnetProfileExample-B-ASC-CPP # from the series root; builds + # submodules/cas-bacnet-stack/bin/... +cmake -B build -S . -DCAS_BACNET_STACK_LINK=STATIC cmake --build build --config Release ``` -> **First build takes a few minutes** - it compiles the entire CAS BACnet Stack -> (~600 source files) once. Incremental rebuilds after that are fast. +> **The stack library build takes a few minutes** the first time - it compiles +> the entire CAS BACnet Stack (~600 source files) once, via the stack's own +> project files (`msbuild` on Windows, `make` on Linux). The example itself +> (`main.cpp` + `common/`) then builds in seconds against that library, and +> rebuilds after that are incremental. > > Build in parallel to cut that down substantially - this is worth doing on the first > build of the day, and essential if you are running a class through it: @@ -327,66 +345,27 @@ cmake --build build --config Release If your CAS BACnet Stack lives somewhere other than the bundled submodule, point CMake at it: `cmake -B build -S . -D CAS_STACK_DIR=/path/to/cas-bacnet-stack`. -### Link modes +### Link mode This example links the stack through the `CASBACnetStack::Adapter` CMake target -(`submodules/cas-bacnet-stack/adapters/cpp`). `CAS_BACNET_STACK_LINK` picks how: - -```bash -cmake -B build -S . # SOURCE (default) - compiles the stack in -cmake -B build -S . -D CAS_BACNET_STACK_LINK=STATIC # link a prebuilt .lib/.a -cmake -B build -S . -D CAS_BACNET_STACK_LINK=DLL # load a prebuilt .dll/.so at runtime -``` - -**Application code is identical in every mode.** `main.cpp` and `common/` call -`BACnetStack_AddDevice(...)` and friends by the exact export name; switching modes changes -only the CMake flag, never a line of your code. The one requirement all three share is calling -`LoadBACnetFunctions()` once at the top of `main()` before any other `BACnetStack_*` call — in -`DLL` mode that is the step that binds the symbols, and it also runs a version handshake in -every mode. - -**Extra step for `STATIC` mode:** build the static library first — this mode links a prebuilt -`.lib`/`.a`, it does not compile the stack. - -```bash -# Windows: build CASBACnetStack_x64_Release.lib (ReleaseLib|x64) into /bin/ -msbuild submodules/cas-bacnet-stack/projects/msvs/CASBACnetStack/CASBACnetStack.vcxproj \ - /p:Configuration=ReleaseLib /p:Platform=x64 -``` - -CMake then finds it automatically in the stack's `bin/`; point elsewhere with -`-D CAS_BACNET_STACK_LIB=/path/to/lib`. If no library is there, configuration stops with -that `msbuild` line in the error rather than failing later at link. On MSVC the adapter also -forces the static CRT (`/MT`) to match how the library is built — mixing runtimes otherwise -produces hundreds of `LNK2038` errors that look like a corrupt library. - -**Extra step for `DLL` mode:** build the library and put it where the executable can find it. - -```bash -# Windows: build CASBACnetStack_x64_Release.dll (ReleaseDll|x64) -msbuild submodules/cas-bacnet-stack/projects/msvs/CASBACnetStack/CASBACnetStack.vcxproj \ - /p:Configuration=ReleaseDll /p:Platform=x64 -# then copy submodules/cas-bacnet-stack/bin/CASBACnetStack_x64_Release.dll -# next to build-dll/Release/BACnetExampleBASC.exe -``` - -If it cannot be loaded, `LoadBACnetFunctions()` returns false and -`CASBACnetStackAdapter_LastError()` says why — `could not load -CASBACnetStack_x64_Release.dll` when the file is absent, or `missing export: -BACnetStack_` when the library is the wrong build. The program exits with a message -rather than crashing. - -> **Verified:** all three modes were built **and run** for this release — `SOURCE`, -> `STATIC` (confirmed with no DLL beside the executable, which is the point of static -> linking), and `DLL`. `DLL` mode was additionally checked for both failure paths (library -> absent; library present but missing an export) — each reports a readable error and exits -> cleanly. -> -> Note the default library name is looked up on the OS search path and **relative to the -> current working directory**, not to the executable's directory — so launching from a -> different working directory will not find a DLL that merely sits beside the .exe. Define -> `BACNET_LIB_FILE` to an absolute path if that matters to your deployment (see -> `adapters/cpp/CASBACnetStackAdapter.h`). +(`submodules/cas-bacnet-stack/adapters/cpp`) in **STATIC** mode - +`-DCAS_BACNET_STACK_LINK=STATIC` links the prebuilt +`CASBACnetStack_x64_Release.lib` / `libCASBACnetStack_x64_Release.a` built by +`tools/build-stack-static.sh` above. **Application code is identical +regardless of link mode** - `main.cpp` and `common/` call `BACnetStack_AddDevice(...)` +and friends by the exact export name. Every mode requires calling +`LoadBACnetFunctions()` once at the top of `main()` before any other +`BACnetStack_*` call, which runs a version handshake; if it fails, +`CASBACnetStackAdapter_LastError()` says why and the program exits with a +message rather than crashing. + +On MSVC the adapter also forces the static CRT (`/MT`) to match how the library is +built — a mismatched runtime otherwise produces hundreds of `LNK2038` errors that +look like a corrupt library. + +The adapter also offers a **SOURCE** mode (compiles the stack's `source/*.cpp` +straight into the executable, no library build step) - this example is built +and published in **STATIC** mode only. ## Run @@ -401,9 +380,9 @@ rather than crashing. Expected output: ``` -BACnet B-ASC (Application Specific Controller) Example - C++ v1.1.0 -CAS BACnet Stack version: 6.0.0.0 -Common helper (common/) version: 1.5.1 +BACnet B-ASC (Application Specific Controller) Example - C++ v1.2.0 +CAS BACnet Stack version: 6.0.21.0 +Common helper (common/) version: 2.1.0 FYI: Listening for BACnet/IP on UDP port 47808. TX 21 bytes to 192.168.3.255:47808 (broadcast) FYI: Device 389003 ("Rainbow") ready. Vendor ID 389. Press 'h' for help. @@ -490,7 +469,7 @@ Then: |---------|-------------| | On start-up the app prints a wall of red `Error:` lines but the device works | **Expected — this is not your bug.** Two benign sources, both from the stack's own debug logging: (1) the device receives its **own** broadcast I-Am and logs a decode cascade (*"Services is not supported service=[0]"* … *"Failed to process the incoming NPDU"*) — any BACnet/IP device that listens for broadcasts hears itself; (2) a one-time *"UUID has not been set. A UUID must be set for the BACnetSC device to start."* — the stack starts a BACnet/SC (BACnet Secure Connect, the TLS/WebSocket-based transport added in ASHRAE 135-2020) datalink that these BACnet/IP-only examples never configure. It appears once and does not spam. How many red lines you see depends on subnet traffic: on a quiet network it can be a single line (just the UUID one); on a busy BACnet subnet the self-heard-broadcast decodes pile up into a wall. Either way the device is fine. | | CMake error: *"CAS BACnet Stack adapter not found under: ..."* | Submodules not initialized. Run `git submodule update --init --recursive` (or pass `-D CAS_STACK_DIR=...`). | -| CMake error: *"CAS_BACNET_STACK_LINK=STATIC needs a prebuilt CAS BACnet Stack library"* | `STATIC` links a library you build separately; it does not compile the stack. Either build it (the message gives the exact `msbuild` line) and re-run CMake, or use the default `SOURCE` mode, which needs no prebuilt library. | +| CMake error: *"CAS_BACNET_STACK_LINK=STATIC needs a prebuilt CAS BACnet Stack library"* | The static library has not been built yet. Run `tools/build-stack-static.sh BACnetProfileExample-B-ASC-CPP` from the series root, then re-run CMake. | | The device starts and prints `TX ... (broadcast)`, but no client ever sees it | Check the IP in that `TX` line against the subnet your BACnet client is on. The example picks the **first non-loopback adapter** the OS reports, which on a laptop with Hyper-V, WSL, VirtualBox or a VPN is frequently not your Wi-Fi/Ethernet. There is no `--interface` option yet; disable the unwanted virtual adapters, or run on a machine without them. (Also check the firewall row above.) | | `CASBACnetStackDLL.h: No such file or directory` | Same - submodules not checked out. | | Windows: *"No CMAKE_CXX_COMPILER could be found"* | Install Visual Studio with the "Desktop development with C++" workload, then re-run from a fresh terminal. | @@ -527,10 +506,22 @@ that is easiest to miss is the one BTL will fail you for, and it fails SILENTLY. > > | Property | If you forget to serve it | Loud? | > |---|---|:--:| -> | `Present_Value` | Error (`value-not-initialized`) | yes | +> | `Present_Value` | Error (`read-access-denied`) | yes | > | `Object_Name` | reads back as the string **`"undefined"`** | **no** | > | `Units` | reads back as **`no-units` (95)** | **no** | > +> **Doesn't the `errorCode` out-parameter fix this?** Only if you use it, and +> only where it is right to. Each `GetProperty*` callback ends with a +> `uint32_t* errorCode` that the stack presets to `success` and reads only when +> you return `false`, so you *can* turn any decline into a chosen BACnet error. +> But ending every callback with `*errorCode = unknown-property` breaks the +> device: the stack's decline-and-fabricate path is what answers required +> properties an application is not expected to serve — the Device's +> `Max_APDU_Length_Accepted`, `APDU_Timeout` and `Number_Of_APDU_Retries` among +> them. Name an error on the catch-all and those start failing instead of +> answering. Set `errorCode` only where *this device* knows the read is wrong; +> `main.cpp` does it in exactly one place, `State_Text` with an out-of-range +> array index. > > It is worse than "wrong value": the object's `Property_List` **still advertises > `Units` (117)**. So the object actively claims to have the property, and then @@ -607,6 +598,240 @@ For Analog Input 1, the whole picture: Going beyond this (COV, alarms, scheduling) means implementing a richer profile - a later example in this series. +## Objects and properties + + +Every object this example creates, and every REQUIRED property of each (per ANSI/ASHRAE 135-2024 clause 12 and the stack's `docs/property-profile-reference.md`), plus the optional properties the example turns on. **Served by** says who answers a ReadProperty: the **stack** generates it, or the **app** serves it from a `GetProperty*` callback in `main.cpp`. A ⚠ row is a required property the app does not serve and the stack would fill with a default - that is a defect, not a feature. + +### Device 389003 "Rainbow" - vendor 389 (Chipkin Automation Systems); instance configurable with --deviceID. The properties in 'accepted' are not served from a GetProperty callback because the stack itself is the source of truth for them - Protocol_Revision/Protocol_Version are stack build constants, Protocol_Services_Supported/Protocol_Object_Types_Supported are computed from the BACnetStack_SetServiceEnabled/AddObject calls this example already makes, Object_List and Device_Address_Binding are live stack-maintained tables, System_Status/Database_Revision/Max_APDU_Length_Accepted/Segmentation_Supported/APDU_Timeout/Number_Of_APDU_Retries are the stack's own configuration defaults for a device this example does not override + +| Property | Datatype | Served by | Writable | +|---|---|---|:---:| +| Object_Identifier | BACnetObjectIdentifier | stack | no | +| Object_Name | CharacterString | app | no | +| Object_Type | BACnetObjectType | stack | no | +| System_Status | BACnetDeviceStatus | stack default, accepted (Generic Enumerated default: `0`) | no | +| Vendor_Name | CharacterString | app | no | +| Vendor_Identifier | Unsigned16 | app | no | +| Model_Name | CharacterString | app | no | +| Firmware_Revision | CharacterString | app | no | +| Application_Software_Version | CharacterString | app | no | +| Description *(optional, enabled)* | CharacterString | app | no | +| Protocol_Version | Unsigned | stack default, accepted (`BACNET_PROTOCOL_VERSION`) | no | +| Protocol_Revision | Unsigned | stack default, accepted (`BACNET_PROTOCOL_REVISION`) | no | +| Protocol_Services_Supported | BACnetServicesSupported | stack default, accepted (computed from which services are enabled) | no | +| Protocol_Object_Types_Supported | BACnetObjectTypesSupported | stack default, accepted (computed from which object types are supported) | no | +| Object_List | BACnetARRAY[N] of BACnetObjectIdentifier | stack default, accepted (None known - a read fails with `unknown-property` or an empt) | no | +| Max_APDU_Length_Accepted | Unsigned | stack default, accepted (`CAS_BACNET_DEVICE_DEFAULT_MAX_APDU_LENGTH_ACCEPTED`) | no | +| Segmentation_Supported | BACnetSegmentation | stack default, accepted (`BACnetSegmentation::noSegmentation`) | no | +| APDU_Timeout | Unsigned | stack default, accepted (`CAS_BACNET_DEVICE_DEFAULT_APDU_TIMEOUT`) | no | +| Number_Of_APDU_Retries | Unsigned | stack default, accepted (`CAS_BACNET_DEVICE_DEFAULT_NUMBER_OF_APDU_RETRIES`) | no | +| Device_Address_Binding | BACnetLIST of BACnetAddressBinding | stack default, accepted (the live Device_Address_Binding (DAB) table) | no | +| Database_Revision | Unsigned | stack default, accepted (Generic UnsignedInteger default: `0`) | no | + +### Analog Input 1 "Bronze" - REAL, degrees Celsius; starts at 21.5; read-only + +| Property | Datatype | Served by | Writable | +|---|---|---|:---:| +| Object_Identifier | BACnetObjectIdentifier | stack | no | +| Object_Name | CharacterString | app | no | +| Object_Type | BACnetObjectType | stack | no | +| Present_Value | Real | app | no | +| Status_Flags | BACnetStatusFlags | stack | no | +| Event_State | BACnetEventState | stack default, accepted (Generic Enumerated default: `0`) | no | +| Out_Of_Service | Boolean | app | no | +| Units | BACnetEngineeringUnits | app | no | + +### Binary Input 1 "Emerald" - starts inactive; read-only + +| Property | Datatype | Served by | Writable | +|---|---|---|:---:| +| Object_Identifier | BACnetObjectIdentifier | stack | no | +| Object_Name | CharacterString | app | no | +| Object_Type | BACnetObjectType | stack | no | +| Present_Value | BACnetBinaryPV | app | no | +| Status_Flags | BACnetStatusFlags | stack | no | +| Event_State | BACnetEventState | stack default, accepted (Generic Enumerated default: `0`) | no | +| Out_Of_Service | Boolean | app | no | +| Polarity | BACnetPolarity | app | no | + +### Multi-state Input 1 "Hot Pink" - state 1 of 3: On, Off, Auto; read-only + +| Property | Datatype | Served by | Writable | +|---|---|---|:---:| +| Object_Identifier | BACnetObjectIdentifier | stack | no | +| Object_Name | CharacterString | app | no | +| Object_Type | BACnetObjectType | stack | no | +| Present_Value | Unsigned | app | no | +| Status_Flags | BACnetStatusFlags | stack | no | +| Event_State | BACnetEventState | stack default, accepted (Generic Enumerated default: `0`) | no | +| Out_Of_Service | Boolean | app | no | +| Number_Of_States | Unsigned | app | no | +| State_Text *(optional, enabled)* | BACnetARRAY[N] of CharacterString | app | no | + +### Analog Output 1 "Chartreuse" - REAL setpoint, default 20.0 C; commandable via a 16-slot Priority_Array (WriteProperty, DS-WP-B) - Present_Value/Priority_Array/Current_Command_Priority are resolved by the stack from the slots the app serves through GetPropertyReal/GetPropertyBool + +| Property | Datatype | Served by | Writable | +|---|---|---|:---:| +| Object_Identifier | BACnetObjectIdentifier | stack | no | +| Object_Name | CharacterString | app | no | +| Object_Type | BACnetObjectType | stack | no | +| Present_Value | Real | stack | yes | +| Status_Flags | BACnetStatusFlags | stack | no | +| Event_State | BACnetEventState | stack default, accepted (Generic Enumerated default: `0`) | no | +| Out_Of_Service | Boolean | app | no | +| Units | BACnetEngineeringUnits | app | no | +| Priority_Array | BACnetARRAY[16] of BACnetOptionalReal | stack | no | +| Relinquish_Default | Real | app | no | +| Current_Command_Priority | BACnetOptionalUnsigned | stack | no | + +### Binary Output 1 "Fuchsia" - active/inactive, default inactive; commandable via a 16-slot Priority_Array (WriteProperty, DS-WP-B) - Present_Value/Priority_Array/Current_Command_Priority are resolved by the stack from the slots the app serves through GetPropertyEnumerated/GetPropertyBool + +| Property | Datatype | Served by | Writable | +|---|---|---|:---:| +| Object_Identifier | BACnetObjectIdentifier | stack | no | +| Object_Name | CharacterString | app | no | +| Object_Type | BACnetObjectType | stack | no | +| Present_Value | BACnetBinaryPV | stack | yes | +| Status_Flags | BACnetStatusFlags | stack | no | +| Event_State | BACnetEventState | stack default, accepted (Generic Enumerated default: `0`) | no | +| Out_Of_Service | Boolean | app | no | +| Polarity | BACnetPolarity | app | no | +| Priority_Array | BACnetARRAY[16] of BACnetOptionalBinaryPV | stack | no | +| Relinquish_Default | BACnetBinaryPV | app | no | +| Current_Command_Priority | BACnetOptionalUnsigned | stack | no | + +### Multi-state Output 1 "Indigo" - state 1 of 3, default state 1; commandable via a 16-slot Priority_Array (WriteProperty, DS-WP-B) - Present_Value/Priority_Array/Current_Command_Priority are resolved by the stack from the slots the app serves through GetPropertyUnsignedInteger/GetPropertyBool + +| Property | Datatype | Served by | Writable | +|---|---|---|:---:| +| Object_Identifier | BACnetObjectIdentifier | stack | no | +| Object_Name | CharacterString | app | no | +| Object_Type | BACnetObjectType | stack | no | +| Present_Value | Unsigned | stack | yes | +| Status_Flags | BACnetStatusFlags | stack | no | +| Event_State | BACnetEventState | stack default, accepted (Generic Enumerated default: `0`) | no | +| Out_Of_Service | Boolean | app | no | +| Number_Of_States | Unsigned | app | no | +| Priority_Array | BACnetARRAY[16] of BACnetOptionalUnsigned | stack | no | +| Relinquish_Default | Unsigned | app | no | +| Current_Command_Priority | BACnetOptionalUnsigned | stack | no | + +### Network Port 1 "Vermilion" - BACnet/IP; Network_Type and Protocol_Level are set from BACnetStack_AddNetworkPortObject()'s arguments (IPv4, BACnet Application) at start-up, not a GetProperty callback like the object's other app-served rows; Changes_Pending is likewise computed and answered natively by the stack's Network Port object. Reliability has no fault condition this example detects, so it is accepted at the generic default (normal) + +| Property | Datatype | Served by | Writable | +|---|---|---|:---:| +| Object_Identifier | BACnetObjectIdentifier | stack | no | +| Object_Name | CharacterString | app | no | +| Object_Type | BACnetObjectType | stack | no | +| Status_Flags | BACnetStatusFlags | stack | no | +| Reliability | BACnetReliability | stack default, accepted (Generic Enumerated default: `0`) | no | +| Out_Of_Service | Boolean | app | no | +| Network_Type | BACnetNetworkType | app | no | +| Protocol_Level | BACnetProtocolLevel | app | no | +| Changes_Pending | Boolean | app | no | + + + +## The BACnet profile example series + + +The CAS BACnet Stack supports every standardized device profile in ASHRAE 135-2024 Annex L. One example repository per profile shows how. ✅ = the required BIBB (service) is supported by the CAS BACnet Stack; the **Example** column is the state of that profile's tutorial repository. + +### Controllers (Annex L.4) + +| Profile | Example | Required BIBBs (services) | +|---|---|---| +| **B-SS** Smart Sensor | [B-SS-CPP](https://github.com/chipkin/BACnetProfileExample-B-SS-CPP) ✅ | ✅ DS-RP-B · ✅ DM-DDB-B · ✅ DM-DOB-B | +| **B-SA** Smart Actuator | [B-SA-CPP](https://github.com/chipkin/BACnetProfileExample-B-SA-CPP) ✅ | ✅ DS-RP-B · ✅ DS-WP-B · ✅ DM-DDB-B · ✅ DM-DOB-B | +| **B-ASC** Application Specific Controller | [B-ASC-CPP](https://github.com/chipkin/BACnetProfileExample-B-ASC-CPP) ✅ · [B-ASC-Node](https://github.com/chipkin/BACnetProfileExample-B-ASC-Node) ✅ | ✅ DS-RP-B · ✅ DS-WP-B · ✅ DM-DDB-B · ✅ DM-DOB-B · ✅ DM-DCC-B | +| **B-AAC** Advanced Application Controller | [B-AAC-CPP](https://github.com/chipkin/BACnetProfileExample-B-AAC-CPP) ✅ | ✅ DS-RP-B · ✅ DS-RPM-B · ✅ DS-WP-B · ✅ DS-WPM-B · ✅ AE-N-I-B · ✅ AE-ACK-B · ✅ AE-INFO-B · ✅ AE-CRL-B · ✅ SCHED-I-B · ✅ DM-DDB-A · ✅ DM-DDB-B · ✅ DM-DOB-B · ✅ DM-DCC-B · ✅ DM-TS-B / DM-UTC-B · ✅ DM-RD-B | +| **B-BC** Building Controller | [B-BC-CPP](https://github.com/chipkin/BACnetProfileExample-B-BC-CPP) 📝 | ✅ DS-RP-A · ✅ DS-RP-B · ✅ DS-RPM-A · ✅ DS-RPM-B · ✅ DS-WP-A · ✅ DS-WP-B · ✅ DS-WPM-B · ✅ AE-N-I-B · ✅ AE-ACK-B · ✅ AE-INFO-B · ✅ AE-CRL-B · ✅ SCHED-E-B · ✅ T-VMT-I-B · ✅ T-ATR-B · ✅ DM-DDB-A · ✅ DM-DDB-B · ✅ DM-DOB-B · ✅ DM-DCC-B · ✅ DM-TS-B / DM-UTC-B · ✅ DM-RD-B · ✅ DM-BR-B | + +### Life safety controllers (Annex L.5) + +| Profile | Example | Required BIBBs (services) | +|---|---|---| +| **B-LSC** Life Safety Controller | [B-LSC-CPP](https://github.com/chipkin/BACnetProfileExample-B-LSC-CPP) 📝 | ✅ DS-RP-B · ✅ DS-RPM-B · ✅ DS-WP-B · ✅ DS-WPM-B · ✅ DS-COV-B · ✅ AE-LS-B · ✅ AE-ACK-B · ✅ AE-INFO-B · ✅ DM-DDB-A · ✅ DM-DDB-B · ✅ DM-DOB-B · ✅ DM-DCC-B · ✅ DM-TS-B / DM-UTC-B · ✅ DM-RD-B | +| **B-ALSC** Advanced Life Safety Controller | [B-ALSC-CPP](https://github.com/chipkin/BACnetProfileExample-B-ALSC-CPP) 📝 | ✅ DS-RP-B · ✅ DS-RPM-B · ✅ DS-WP-B · ✅ DS-WPM-B · ✅ DS-COV-B · ✅ AE-LS-B · ✅ AE-ACK-B · ✅ AE-INFO-B · ✅ AE-EL-I-B · ✅ SCHED-I-B · ✅ DM-DDB-A · ✅ DM-DDB-B · ✅ DM-DOB-B · ✅ DM-DCC-B · ✅ DM-TS-B / DM-UTC-B · ✅ DM-RD-B | + +### Access control controllers (Annex L.6) + +| Profile | Example | Required BIBBs (services) | +|---|---|---| +| **B-ACC** Access Control Controller | [B-ACC-CPP](https://github.com/chipkin/BACnetProfileExample-B-ACC-CPP) 📝 | ✅ DS-RP-B · ✅ DS-RPM-B · ✅ DS-WP-B · ✅ DS-WPM-B · ✅ DS-COV-B · ✅ DS-ACUC-B · ✅ DS-ACSC-B · ✅ AE-AC-B · ✅ AE-ACK-B · ✅ AE-INFO-B · ✅ AE-EL-I-B · ✅ SCHED-I-B · ✅ DM-DDB-A · ✅ DM-DDB-B · ✅ DM-DOB-B · ✅ DM-DCC-B · ✅ DM-TS-B / DM-UTC-B · ✅ DM-RD-B · ✅ DM-BR-B | +| **B-AACC** Advanced Access Control Controller | [B-AACC-CPP](https://github.com/chipkin/BACnetProfileExample-B-AACC-CPP) 📝 | ✅ DS-RP-A · ✅ DS-RP-B · ✅ DS-RPM-A · ✅ DS-RPM-B · ✅ DS-WP-A · ✅ DS-WP-B · ✅ DS-WPM-B · ✅ DS-COV-A · ✅ DS-COV-B · ✅ DS-ACAD-A · ☐ DS-ACCDI-A · ✅ DS-ACUC-B · ✅ DS-ACSC-B · ✅ AE-AC-B · ✅ AE-ACK-B · ✅ AE-INFO-B · ✅ AE-EL-I-B · ✅ SCHED-I-B · ✅ DM-DDB-A · ✅ DM-DDB-B · ✅ DM-DOB-B · ✅ DM-DCC-B · ✅ DM-TS-B / DM-UTC-B · ✅ DM-RD-B · ✅ DM-BR-B | + +### Lighting controllers (Annex L.11) + +| Profile | Example | Required BIBBs (services) | +|---|---|---| +| **B-LD** Lighting Device | [B-LD-CPP](https://github.com/chipkin/BACnetProfileExample-B-LD-CPP) ✅ | ✅ DS-RP-B · ✅ DS-WP-B · ✅ DS-LO-B / DS-BLO-B · ✅ DM-DDB-B · ✅ DM-DOB-B · ✅ DM-DCC-B · ✅ DM-TS-B / DM-UTC-B | +| **B-LS** Lighting Supervisor | [B-LS-CPP](https://github.com/chipkin/BACnetProfileExample-B-LS-CPP) 📝 | ✅ DS-RP-B · ✅ DS-WP-A · ✅ DS-WP-B · ✅ DS-WG-E-B · ✅ DS-ALO-A · ✅ SCHED-E-B · ✅ DM-DDB-A · ✅ DM-DDB-B · ✅ DM-DOB-B · ✅ DM-DCC-B · ✅ DM-TS-B / DM-UTC-B | + +### Elevator controllers (Annex L.13) + +| Profile | Example | Required BIBBs (services) | +|---|---|---| +| **B-EM** Elevator Monitor | [B-EM-CPP](https://github.com/chipkin/BACnetProfileExample-B-EM-CPP) 📝 | ✅ DS-RP-B · ✅ DS-RPM-B · ✅ DS-COV-B · ✅ DS-COVM-B · ✅ AE-N-I-B · ✅ AE-ACK-B · ✅ AE-INFO-B · ✅ DM-DDB-B · ✅ DM-DOB-B · ✅ DM-DCC-B | +| **B-EC** Elevator Controller | [B-EC-CPP](https://github.com/chipkin/BACnetProfileExample-B-EC-CPP) 📝 | ✅ DS-RP-B · ✅ DS-RPM-B · ✅ DS-WP-B · ✅ DS-WPM-B · ✅ DS-COV-B · ✅ DS-COVM-B · ✅ AE-N-I-B · ✅ AE-ACK-B · ✅ AE-INFO-B · ✅ DM-DDB-A · ✅ DM-DDB-B · ✅ DM-DOB-B · ✅ DM-DCC-B · ✅ DM-TS-B / DM-UTC-B · ✅ DM-RD-B | +| **B-AEC** Advanced Elevator Controller | [B-AEC-CPP](https://github.com/chipkin/BACnetProfileExample-B-AEC-CPP) 📝 | ✅ DS-RP-B · ✅ DS-RPM-B · ✅ DS-WP-B · ✅ DS-WPM-B · ✅ DS-COV-B · ✅ DS-COVM-B · ✅ AE-N-I-B · ✅ AE-ACK-B · ✅ AE-INFO-B · ✅ AE-EL-I-B · ✅ SCHED-I-B · ✅ DM-DDB-A · ✅ DM-DDB-B · ✅ DM-DOB-B · ✅ DM-DCC-B · ✅ DM-TS-B / DM-UTC-B · ✅ DM-OCD-B · ✅ DM-RD-B · ✅ DM-BR-B | + +### Authentication and authorization (Annex L.14) + +| Profile | Example | Required BIBBs (services) | +|---|---|---| +| **B-AS** Authorization Server | [B-AS-CPP](https://github.com/chipkin/BACnetProfileExample-B-AS-CPP) 📝 | ✅ DS-RP-B · ✅ DM-DDB-B · ✅ DM-DOB-B · ✅ DM-DCC-B · ✅ AA-AS-B | + +### Miscellaneous (Annex L.7, combinable with any one family) + +| Profile | Example | Required BIBBs (services) | +|---|---|---| +| **B-BBMD** Broadcast Management Device | [B-BBMD-CPP](https://github.com/chipkin/BACnetProfileExample-B-BBMD-CPP) ✅ | ✅ DS-RP-B · ✅ DS-WP-B · ✅ DM-DDB-B · ✅ DM-DOB-B · ✅ DM-DCC-B · ✅ NM-BBMDC-B | +| **B-ACDC** Access Control Door Controller | [B-ACDC-CPP](https://github.com/chipkin/BACnetProfileExample-B-ACDC-CPP) ✅ | ✅ DS-RP-B · ✅ DS-WP-B · ✅ DS-ACAD-B · ✅ DM-DDB-B · ✅ DM-DOB-B | +| **B-ACCR** Access Control Credential Reader | [B-ACCR-CPP](https://github.com/chipkin/BACnetProfileExample-B-ACCR-CPP) 📝 | ✅ DS-RP-B · ✅ DS-WP-B · ✅ DS-COV-B · ✅ DS-ACCDI-B · ✅ DM-DDB-B · ✅ DM-DOB-B | +| **B-RTR** Router | [B-RTR-CPP](https://github.com/chipkin/BACnetProfileExample-B-RTR-CPP) 📝 | ✅ DS-RP-B · ✅ DS-WP-B · ✅ DM-DDB-A · ✅ DM-DOB-B · ✅ DM-LM-B · ✅ NM-RC-B | +| **B-GW** Gateway | [B-GW-CPP](https://github.com/chipkin/BACnetProfileExample-B-GW-CPP) 📝 | ✅ DS-RP-B · ✅ DS-WP-B · ✅ DM-DDB-B · ✅ DM-DOB-B · ✅ DM-DCC-B · ✅ GW-EO-B / GW-VN-B | +| **B-DAP** Device Address Proxy | [B-DAP-CPP](https://github.com/chipkin/BACnetProfileExample-B-DAP-CPP) 📝 | ✅ DS-RP-B · ✅ DS-WP-B · ✅ DM-DDB-B · ✅ DM-DOB-B · ✅ DM-DAB-B | +| **B-SCHUB** BACnet/SC Hub | [B-SCHUB-CPP](https://github.com/chipkin/BACnetProfileExample-B-SCHUB-CPP) 📝 | ✅ DS-RP-B · ✅ DM-DDB-B · ✅ DM-DOB-B · ✅ DM-DCC-B · ✅ NM-SCH-B | +| **B-GENERAL** General device (Annex L.8) | *(satisfied by every example above)* | ✅ DS-RP-B · ✅ DM-DDB-B · ✅ DM-DOB-B | + +### Operator interfaces and workstations (Annex L.1–L.3, L.9–L.10, L.12) — client-side profiles + +| Profile | Example | Required BIBBs (services) | +|---|---|---| +| **B-OD** Operator Display | [B-OD-CPP](https://github.com/chipkin/BACnetProfileExample-B-OD-CPP) ✅ | ✅ DS-RP-A · ✅ DS-RP-B · ✅ DS-WP-A · ✅ DS-V-A · ✅ DS-M-A · ✅ AE-N-A · ✅ AE-VN-A · ✅ DM-DDB-A · ✅ DM-DDB-B · ✅ DM-DOB-B | +| **B-OWS** Operator Workstation | planned | ✅ DS-RP-A · ✅ DS-RP-B · ✅ DS-WP-A · ✅ DS-V-A · ✅ DS-M-A · ✅ AE-N-A · ✅ AE-ACK-A · ✅ AE-AS-A · ✅ AE-VM-A · ✅ AE-VN-A · ✅ SCHED-VM-A · ✅ T-V-A · ✅ DM-DDB-A · ✅ DM-DDB-B · ✅ DM-DOB-B · ✅ DM-MTS-A | +| **B-AWS** Advanced Operator Workstation | planned | ✅ DS-RP-A · ✅ DS-RP-B · ✅ DS-RPM-A · ✅ DS-WP-A · ✅ DS-WPM-A · ✅ DS-AV-A · ✅ DS-AM-A · ✅ AE-N-A · ✅ AE-ACK-A · ✅ AE-AS-A · ✅ AE-AVM-A · ✅ AE-AVN-A · ✅ AE-ELVM-A · ✅ SCHED-AVM-A · ✅ T-AVM-A · ✅ DM-DDB-A · ✅ DM-DDB-B · ✅ DM-ANM-A · ✅ DM-ADM-A · ✅ DM-DOB-B · ✅ DM-DCC-A · ✅ DM-MTS-A · ✅ DM-OCD-A · ✅ DM-RD-A · ✅ DM-BR-A · ✅ DM-DDA-A · ✅ NM-CC-A · ✅ AR-AVM-A | +| **B-XAWS** Extended Advanced Operator Workstation | planned | ✅ union of B-AWS + B-AACWS + B-ALWS + B-AEWS | +| **B-LSAP** Life Safety Annunciator Panel | planned | ✅ DS-RP-A · ✅ DS-RP-B · ✅ DS-WP-A · ✅ DS-LSV-A · ✅ AE-N-A · ✅ AE-LS-A · ✅ AE-ACK-A · ✅ AE-LSVN-A | +| **B-LSWS** Life Safety Workstation | planned | ✅ DS-RP-A · ✅ DS-RP-B · ✅ DS-RPM-A · ✅ DS-WP-A · ✅ DS-WPM-A · ✅ DS-LSV-A · ✅ DS-LSM-A · ✅ AE-N-A · ✅ AE-LS-A · ✅ AE-ACK-A · ✅ AE-AS-A · ✅ AE-LSVM-A · ✅ AE-LSAVN-A · ✅ AE-ELV-A · ✅ SCHED-VM-A · ✅ T-V-A · ✅ DM-DDB-A · ✅ DM-DDB-B · ✅ DM-ANM-A · ✅ DM-ADM-A · ✅ DM-DOB-B · ✅ DM-DCC-A · ✅ DM-MTS-A · ✅ DM-OCD-A · ✅ DM-RD-A · ✅ DM-BR-A | +| **B-ALSWS** Advanced Life Safety Workstation | planned | ✅ DS-RP-A · ✅ DS-RP-B · ✅ DS-RPM-A · ✅ DS-WP-A · ✅ DS-WPM-A · ✅ DS-LSAV-A · ✅ DS-LSAM-A · ✅ AE-N-A · ✅ AE-LS-A · ✅ AE-ACK-A · ✅ AE-AS-A · ✅ AE-LSAVM-A · ✅ AE-LSAVN-A · ✅ AE-ELVM-A · ✅ SCHED-AVM-A · ✅ T-AVM-A · ✅ DM-DDB-A · ✅ DM-DDB-B · ✅ DM-ANM-A · ✅ DM-ADM-A · ✅ DM-DOB-B · ✅ DM-DCC-A · ✅ DM-MTS-A · ✅ DM-OCD-A · ✅ DM-RD-A · ✅ DM-BR-A · ✅ AR-AVM-A | +| **B-ACSD** Access Control Security Display | planned | ✅ DS-RP-A · ✅ DS-RP-B · ✅ DS-RPM-A · ✅ DS-WP-A · ✅ DS-WPM-A · ✅ DS-ACV-A · ✅ DS-ACM-A · ✅ AE-N-A · ✅ AE-AC-A · ✅ AE-ACK-A · ✅ AE-AS-A · ✅ AE-ACAVN-A · ✅ AE-ELV-A · ✅ SCHED-VM-A · ✅ DM-DDB-A · ✅ DM-DDB-B · ✅ DM-DOB-B · ✅ DM-MTS-A | +| **B-ACWS** Access Control Workstation | planned | ✅ DS-RP-A · ✅ DS-RP-B · ✅ DS-RPM-A · ✅ DS-WP-A · ✅ DS-WPM-A · ✅ DS-ACAV-A · ✅ DS-ACM-A · ✅ DS-ACUC-A · ✅ AE-N-A · ✅ AE-AC-A · ✅ AE-ACK-A · ✅ AE-AS-A · ✅ AE-ACVM-A · ✅ AE-ACAVN-A · ✅ AE-ELV-A · ✅ SCHED-VM-A · ✅ DM-DDB-A · ✅ DM-DDB-B · ✅ DM-ANM-A · ✅ DM-ADM-A · ✅ DM-DOB-B · ✅ DM-DCC-A · ✅ DM-MTS-A · ✅ DM-OCD-A · ✅ DM-RD-A · ✅ DM-BR-A | +| **B-AACWS** Advanced Access Control Workstation | planned | ✅ DS-RP-A · ✅ DS-RP-B · ✅ DS-RPM-A · ✅ DS-WP-A · ✅ DS-WPM-A · ✅ DS-ACAV-A · ✅ DS-ACAM-A · ✅ DS-ACUC-A · ✅ DS-ACSC-A · ✅ AE-N-A · ✅ AE-AC-A · ✅ AE-ACK-A · ✅ AE-AS-A · ✅ AE-ACAVM-A · ✅ AE-ACAVN-A · ✅ AE-ELVM-A · ✅ SCHED-AVM-A · ✅ DM-DDB-A · ✅ DM-DDB-B · ✅ DM-ANM-A · ✅ DM-ADM-A · ✅ DM-DOB-B · ✅ DM-DCC-A · ✅ DM-MTS-A · ✅ DM-OCD-A · ✅ DM-RD-A · ✅ DM-BR-A · ✅ AR-AVM-A | +| **B-LOD** Lighting Operator Display | planned | ✅ DS-RP-A · ✅ DS-RP-B · ✅ DS-WP-A · ✅ DS-LV-A · ✅ DS-WG-A · ✅ DS-ALO-A · ✅ DM-DDB-A · ✅ DM-DDB-B · ✅ DM-DOB-B | +| **B-ALWS** Advanced Lighting Workstation | planned | ✅ DS-RP-A · ✅ DS-RP-B · ✅ DS-RPM-A · ✅ DS-WP-A · ✅ DS-WPM-A · ✅ DS-LAV-A · ✅ DS-LAM-A · ✅ DS-WG-A · ✅ DS-ALO-A · ✅ AE-N-A · ✅ AE-ACK-A · ✅ AE-AS-A · ✅ AE-AVM-A · ✅ AE-AVN-A · ✅ AE-ELVM-A · ✅ SCHED-AVM-A · ✅ T-AVM-A · ✅ DM-DDB-A · ✅ DM-DDB-B · ✅ DM-ANM-A · ✅ DM-ADM-A · ✅ DM-DOB-B · ✅ DM-DCC-A · ✅ DM-MTS-A · ✅ DM-OCD-A · ✅ DM-RD-A · ✅ DM-BR-A | +| **B-LCS** Lighting Control Station | planned | ✅ DS-RP-A · ✅ DS-RP-B · ✅ DS-WP-A · ✅ DS-LO-A · ✅ DM-DDB-A · ✅ DM-DDB-B · ✅ DM-DOB-B · ✅ DM-DCC-B · ✅ DM-TS-B / DM-UTC-B | +| **B-ALCS** Advanced Lighting Control Station | planned | ✅ DS-RP-A · ✅ DS-RP-B · ✅ DS-RPM-A · ✅ DS-WP-A · ✅ DS-WPM-A · ✅ DS-WG-A · ✅ DS-ALO-A · ✅ SCHED-E-B · ✅ DM-DDB-A · ✅ DM-DDB-B · ✅ DM-DOB-B · ✅ DM-DCC-B · ✅ DM-TS-B / DM-UTC-B | +| **B-ED** Elevator Display | planned | ✅ DS-RP-A · ✅ DS-RP-B · ✅ DS-WP-A · ✅ DS-EV-A · ✅ AE-N-A · ✅ AE-ACK-A · ✅ AE-EVN-A · ✅ DM-DDB-A · ✅ DM-DDB-B · ✅ DM-DOB-B | +| **B-EWS** Elevator Workstation | planned | ✅ DS-RP-A · ✅ DS-RP-B · ✅ DS-RPM-A · ✅ DS-WP-A · ✅ DS-WPM-A · ✅ DS-COVM-A · ✅ DS-EV-A · ✅ DS-EM-A · ✅ AE-N-A · ✅ AE-ACK-A · ✅ AE-AS-A · ✅ AE-EVM-A · ✅ AE-EAVN-A · ✅ SCHED-VM-A · ✅ T-V-A · ✅ DM-DDB-A · ✅ DM-DDB-B · ✅ DM-ANM-A · ✅ DM-ADM-A · ✅ DM-DOB-B · ✅ DM-DCC-A · ✅ DM-MTS-A | +| **B-AEWS** Advanced Elevator Workstation | planned | ✅ DS-RP-A · ✅ DS-RP-B · ✅ DS-RPM-A · ✅ DS-WP-A · ✅ DS-WPM-A · ✅ DS-COVM-A · ✅ DS-EAV-A · ✅ DS-EAM-A · ✅ AE-N-A · ✅ AE-ACK-A · ✅ AE-AS-A · ✅ AE-EAVM-A · ✅ AE-EAVN-A · ✅ AE-ELVM-A · ✅ SCHED-AVM-A · ✅ T-AVM-A · ✅ DM-DDB-A · ✅ DM-DDB-B · ✅ DM-ANM-A · ✅ DM-ADM-A · ✅ DM-DOB-B · ✅ DM-DCC-A · ✅ DM-MTS-A · ✅ DM-OCD-A · ✅ DM-RD-A · ✅ DM-BR-A | + +Profile definitions: ANSI/ASHRAE 135-2024 Annex L. BIBB definitions: Annex K. Get the stack: . + + +## Footprint + +Release-build sizes and start-up timing, from the latest tagged release's CI +run (`metrics-windows.json` / `metrics-linux.json`), both built with +`CAS_BACNET_STACK_LINK=STATIC`: + + +| Platform | Binary | Size | SHA-256 (prefix) | Start-up to `ready` | Stack commit | Link mode | Compiler | +|---|---|---|---|---|---|---|---| +| — | — | not yet released | — | — | — | — | — | + ## References - **ANSI/ASHRAE Standard 135** (BACnet) - the protocol standard. Object model diff --git a/common/CASBACnetStackExampleConstants.h b/common/CASBACnetStackExampleConstants.h index e8e23df..3e2cafa 100644 --- a/common/CASBACnetStackExampleConstants.h +++ b/common/CASBACnetStackExampleConstants.h @@ -133,10 +133,20 @@ static const uint8_t NOTIFY_TYPE_EVENT = 1; // -- BACnet error codes (Error_Code enumeration) ---------------------------- // Full list: submodules/cas-bacnet-stack/source/BACnetErrorCode.h // A SetProperty* callback writes one of these to its errorCode out-parameter -// and returns false to reject a write with that BACnet Error-PDU. +// and returns false to reject a write with that BACnet Error-PDU. Since the +// per-property error work (CAS BACnet Stack issue #974) the GetProperty* +// callbacks have the same out-parameter and the same contract - see the +// commentary above the Get callbacks in main.cpp for when to use it. +static const uint32_t ERROR_CODE_READ_ACCESS_DENIED = 27; static const uint32_t ERROR_CODE_PASSWORD_FAILURE = 26; +static const uint32_t ERROR_CODE_UNKNOWN_PROPERTY = 32; static const uint32_t ERROR_CODE_VALUE_OUT_OF_RANGE = 37; +static const uint32_t ERROR_CODE_INVALID_ARRAY_INDEX = 42; static const uint32_t ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED = 45; +// success (84) is what errorCode is PRESET to before a Get/Set callback runs. +// Leaving it at success on a false return means "I decline, but I am not +// naming an error" - see main.cpp. +static const uint32_t ERROR_CODE_SUCCESS = 84; // -- Transport network type (BACnetPacket::NetworkType, for the send/receive // callbacks and SendIAm). diff --git a/common/CASExampleHelper.cpp b/common/CASExampleHelper.cpp index dd9f127..29a48b2 100644 --- a/common/CASExampleHelper.cpp +++ b/common/CASExampleHelper.cpp @@ -51,6 +51,14 @@ SimpleUDP g_udp; // The BACnet/IP port the device is bound to (used to address broadcast I-Am). uint16_t g_port = 47808; +// The instance of the Network Port object that owns this UDP socket. The stack +// identifies a link by its Network Port object INSTANCE, not by a transport +// network type, so the transport callbacks and SendIAm all have to name it. +// The example's main() tells us which one it added, via +// SetNetworkPortInstance(); the default matches the series convention of a +// single Network Port at instance 1. +uint32_t g_networkPortInstance = 1; + // --------------------------------------------------------------------------- // Transport callback: the stack calls this to RECEIVE a BACnet message. // @@ -65,7 +73,7 @@ uint16_t HelperReceiveMessage(uint8_t* message, const uint16_t maxMessageLength, uint8_t* destinationConnectionString, uint8_t* destinationConnectionStringLength, const uint8_t maxConnectionStringLength, - uint8_t* networkType) { + uint32_t* networkPortInstance) { (void)destinationConnectionString; (void)destinationConnectionStringLength; if (maxConnectionStringLength < 6) { @@ -94,7 +102,13 @@ uint16_t HelperReceiveMessage(uint8_t* message, const uint16_t maxMessageLength, sourceConnectionString[5] = (uint8_t)(fromPort & 0xFF); *sourceConnectionStringLength = 6; - *networkType = CASBACnetStackExampleConstants::NETWORK_TYPE_IP; + // Tell the stack WHICH Network Port object this datagram arrived on. The + // stack used to ask only for the transport's network TYPE here; since the + // per-port work (CAS BACnet Stack issue #822/#556) it wants the instance of + // the Network Port object that owns this link, so a multi-port device can + // answer on the port a request came in on. This example has exactly one + // port, so it always reports that one - see SetNetworkPortInstance(). + *networkPortInstance = g_networkPortInstance; return bytesRead; } @@ -108,8 +122,11 @@ uint16_t HelperReceiveMessage(uint8_t* message, const uint16_t maxMessageLength, uint16_t HelperSendMessage(const uint8_t* message, const uint16_t messageLength, const uint8_t* connectionString, const uint8_t connectionStringLength, - const uint8_t networkType, const bool broadcast) { - if (networkType != CASBACnetStackExampleConstants::NETWORK_TYPE_IP || + const uint32_t networkPortInstance, const bool broadcast) { + // The stack names the Network Port object the message is to leave by (it + // used to name the transport's network type). This example serves exactly + // one port, so anything else is not ours to send. + if (networkPortInstance != g_networkPortInstance || connectionStringLength < 6) { return 0; } @@ -128,8 +145,12 @@ uint16_t HelperSendMessage(const uint8_t* message, const uint16_t messageLength, // --------------------------------------------------------------------------- // Time callback: the stack asks the application for the current system time. // --------------------------------------------------------------------------- -time_t HelperGetSystemTime() { - return time(0); +// CASBACnetTime is the stack's own time type (int64_t seconds since the UNIX +// epoch). It replaced time_t, whose width differs between platforms and build +// settings - a 32-bit time_t on one side of the ABI and a 64-bit one on the +// other silently corrupted every timestamp. +CASBACnetTime HelperGetSystemTime() { + return (CASBACnetTime)time(0); } // --------------------------------------------------------------------------- @@ -419,9 +440,13 @@ void ShutdownUDP() { g_udp.Disconnect(); } +void SetNetworkPortInstance(const uint32_t networkPortInstance) { + g_networkPortInstance = networkPortInstance; +} + void RegisterCommonCallbacks() { - BACnetStack_RegisterCallbackReceiveMessage(HelperReceiveMessage); - BACnetStack_RegisterCallbackSendMessage(HelperSendMessage); + BACnetStack_RegisterCallbackReceiveMessageForPort(HelperReceiveMessage); + BACnetStack_RegisterCallbackSendMessageForPort(HelperSendMessage); BACnetStack_RegisterCallbackGetSystemTime(HelperGetSystemTime); } @@ -449,7 +474,7 @@ void SendIAm(const uint32_t deviceInstance) { }; // destinationNetwork 0 = the local network only (not the global 0xFFFF). BACnetStack_SendIAm(deviceInstance, connectionString, 6, - CASBACnetStackExampleConstants::NETWORK_TYPE_IP, + g_networkPortInstance, true /*broadcast*/, 0 /*local network*/, NULL, 0); } @@ -467,6 +492,7 @@ KeyCommand PollKey() { } if (c == 'h' || c == 'H') return KeyCommand::Help; if (c == 'q' || c == 'Q') return KeyCommand::Quit; + if (c == 's' || c == 'S') return KeyCommand::DemoAdvance; return KeyCommand::None; #else EnableRawInput(); @@ -482,6 +508,7 @@ KeyCommand PollKey() { } if (buf[0] == 'h' || buf[0] == 'H') return KeyCommand::Help; if (buf[0] == 'q' || buf[0] == 'Q') return KeyCommand::Quit; + if (buf[0] == 's' || buf[0] == 'S') return KeyCommand::DemoAdvance; return KeyCommand::None; #endif } diff --git a/common/CASExampleHelper.h b/common/CASExampleHelper.h index 40efc75..048ef90 100644 --- a/common/CASExampleHelper.h +++ b/common/CASExampleHelper.h @@ -40,7 +40,7 @@ namespace CASExampleHelper { // version). Bump it whenever anything in common/ changes, and record the // change in common/CHANGELOG.md - every example in the series must then be // re-synced to the same common/ version. -static const char* COMMON_VERSION = "1.5.1"; +static const char* COMMON_VERSION = "2.1.0"; // Print the example's name + version, the linked CAS BACnet Stack version, // and the common/ helper version. @@ -79,6 +79,20 @@ bool SetupUDP(uint16_t port); // Close the shared UDP socket. void ShutdownUDP(); +// Tell the helper which Network Port object instance owns the UDP socket. +// +// The stack identifies a link by the INSTANCE of its Network Port object, not +// by a transport network type: the receive callback reports the instance a +// datagram arrived on, the send callback is told the instance to send from, and +// SendIAm is told which port to announce on. The helper serves one port, so it +// needs to know its instance. +// +// Call this once, after BACnetStack_AddNetworkPortObject() and before +// RegisterCommonCallbacks(). It defaults to 1 - the series convention - so an +// example that uses instance 1 need not call it, but calling it explicitly +// keeps main.cpp's Network Port instance the single source of truth. +void SetNetworkPortInstance(uint32_t networkPortInstance); + // Register the transport + system-time callbacks (backed by the UDP socket // created in SetupUDP, so call SetupUDP first). void RegisterCommonCallbacks(); @@ -151,11 +165,13 @@ bool RestartDue(RestartKind* outKind); // --- Keyboard input (common to every example) ------------------------------ enum class KeyCommand { - None, // nothing pressed - Help, // 'h' - show version + commands - Quit, // 'q' - exit - ArrowUp, // up arrow - ArrowDown // down arrow + None, // nothing pressed + Help, // 'h' - show version + commands + Quit, // 'q' - exit + ArrowUp, // up arrow + ArrowDown, // down arrow + DemoAdvance // 's' - advance a demo (e.g. a Schedule) to its next step now, + // bypassing whatever wall-clock wait it would otherwise need }; // Non-blocking: returns a pending key command, or None if nothing was pressed. diff --git a/common/CHANGELOG.md b/common/CHANGELOG.md index b528d25..23c5cdc 100644 --- a/common/CHANGELOG.md +++ b/common/CHANGELOG.md @@ -12,6 +12,53 @@ entry here, and must then be re-copied into **every** example in the series. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the folder adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.1.0] - 2026-09-15 + +### Added + +- `KeyCommand::DemoAdvance` (key `s` / `S`), wired in `PollKey()` on both the + Windows (`_getch`) and POSIX (raw-terminal `read`) code paths. Non-breaking, + purely additive: existing `switch (CASExampleHelper::PollKey())` call sites + with a `default:` case (every current example) build unchanged. +- Claimed in the series-wide `docs/menu-keys.md`: "Advance the demo Schedule to + its next `Weekly_Schedule` time-value immediately, bypassing the wall-clock + wait, so a Schedule-driven write can be demonstrated on demand." First + consumer: `BACnetProfileExample-B-AAC-CPP`'s SCHED-I-B demo (Wave 1); any + later example with a Schedule-driven demo reuses this same key rather than + claiming a new one. + +## [2.0.0] - 2026-09-09 + +### Changed — BREAKING, required by the CAS BACnet Stack interface update + +The stack's transport and time callbacks changed shape. Every example in the +series must take this version of `common/` together with the matching `main.cpp` +edits; an old `main.cpp` will not build against this helper and vice versa. + +- **A link is now identified by its Network Port object INSTANCE, not by a + transport network type** (stack issues #822/#556). Three call sites moved: + - `RegisterCallbackReceiveMessage` → **`RegisterCallbackReceiveMessageForPort`**; + the callback's trailing `uint8_t* networkType` became + `uint32_t* networkPortInstance`. + - `RegisterCallbackSendMessage` → **`RegisterCallbackSendMessageForPort`**; + the callback's `const uint8_t networkType` became + `const uint32_t networkPortInstance`. + - `BACnetStack_SendIAm()` takes the Network Port instance where it took the + network type. +- **New: `SetNetworkPortInstance()`.** The helper has to know which Network Port + object owns its socket. Call it after `BACnetStack_AddNetworkPortObject()` and + before `RegisterCommonCallbacks()`. It defaults to 1 (the series convention), + so an example using instance 1 keeps working without the call, but calling it + keeps `main.cpp`'s Network Port instance the single source of truth. +- **`GetSystemTime` returns `CASBACnetTime` (`int64_t`), not `time_t`.** `time_t` + is 32-bit in some toolchains and 64-bit in others; with the stack and the + application disagreeing, every timestamp crossing the ABI was corrupted. +- **New error-code constants** in `CASBACnetStackExampleConstants.h`: + `ERROR_CODE_READ_ACCESS_DENIED`, `ERROR_CODE_UNKNOWN_PROPERTY`, + `ERROR_CODE_INVALID_ARRAY_INDEX` and `ERROR_CODE_SUCCESS`, for the `errorCode` + out-parameter the `GetProperty*` callbacks gained (stack issue #974). + `NETWORK_TYPE_IP` is retained but is no longer used by the helper. + ## [1.5.1] - 2026-07-31 ### Fixed diff --git a/common/README.md b/common/README.md index caa1868..6b9e31a 100644 --- a/common/README.md +++ b/common/README.md @@ -48,7 +48,7 @@ CASExampleHelper::SendIAm(g_deviceInstance); // announce on start-up while (running) { BACnetStack_Tick(); - switch (CASExampleHelper::PollKey()) { /* h / q / up / down */ } + switch (CASExampleHelper::PollKey()) { /* h / q / up / down / s */ } } CASExampleHelper::RestoreInput(); ``` diff --git a/docs/objects.json b/docs/objects.json new file mode 100644 index 0000000..85d27cb --- /dev/null +++ b/docs/objects.json @@ -0,0 +1,89 @@ +{ + "objects": [ + { + "type": "Device", + "instance": 389003, + "name": "Rainbow", + "app": ["Object_Name", "Vendor_Name", "Vendor_Identifier", "Model_Name", + "Firmware_Revision", "Application_Software_Version", "Description"], + "enabled": ["Description"], + "writable": [], + "accepted": ["System_Status", "Protocol_Version", "Protocol_Revision", + "Protocol_Services_Supported", "Protocol_Object_Types_Supported", + "Object_List", "Max_APDU_Length_Accepted", "Segmentation_Supported", + "APDU_Timeout", "Number_Of_APDU_Retries", "Device_Address_Binding", + "Database_Revision"], + "note": "vendor 389 (Chipkin Automation Systems); instance configurable with --deviceID. The properties in 'accepted' are not served from a GetProperty callback because the stack itself is the source of truth for them - Protocol_Revision/Protocol_Version are stack build constants, Protocol_Services_Supported/Protocol_Object_Types_Supported are computed from the BACnetStack_SetServiceEnabled/AddObject calls this example already makes, Object_List and Device_Address_Binding are live stack-maintained tables, System_Status/Database_Revision/Max_APDU_Length_Accepted/Segmentation_Supported/APDU_Timeout/Number_Of_APDU_Retries are the stack's own configuration defaults for a device this example does not override" + }, + { + "type": "Analog Input", + "instance": 1, + "name": "Bronze", + "app": ["Present_Value", "Object_Name", "Units", "Out_Of_Service"], + "enabled": [], + "writable": [], + "accepted": ["Event_State"], + "note": "REAL, degrees Celsius; starts at 21.5; read-only" + }, + { + "type": "Binary Input", + "instance": 1, + "name": "Emerald", + "app": ["Present_Value", "Object_Name", "Polarity", "Out_Of_Service"], + "enabled": [], + "writable": [], + "accepted": ["Event_State"], + "note": "starts inactive; read-only" + }, + { + "type": "Multi-state Input", + "instance": 1, + "name": "Hot Pink", + "app": ["Present_Value", "Object_Name", "Number_Of_States", "Out_Of_Service", "State_Text"], + "enabled": ["State_Text"], + "writable": [], + "accepted": ["Event_State"], + "note": "state 1 of 3: On, Off, Auto; read-only" + }, + { + "type": "Analog Output", + "instance": 1, + "name": "Chartreuse", + "app": ["Object_Name", "Units", "Out_Of_Service", "Relinquish_Default"], + "enabled": [], + "writable": ["Present_Value"], + "accepted": ["Event_State"], + "note": "REAL setpoint, default 20.0 C; commandable via a 16-slot Priority_Array (WriteProperty, DS-WP-B) - Present_Value/Priority_Array/Current_Command_Priority are resolved by the stack from the slots the app serves through GetPropertyReal/GetPropertyBool" + }, + { + "type": "Binary Output", + "instance": 1, + "name": "Fuchsia", + "app": ["Object_Name", "Out_Of_Service", "Polarity", "Relinquish_Default"], + "enabled": [], + "writable": ["Present_Value"], + "accepted": ["Event_State"], + "note": "active/inactive, default inactive; commandable via a 16-slot Priority_Array (WriteProperty, DS-WP-B) - Present_Value/Priority_Array/Current_Command_Priority are resolved by the stack from the slots the app serves through GetPropertyEnumerated/GetPropertyBool" + }, + { + "type": "Multi-state Output", + "instance": 1, + "name": "Indigo", + "app": ["Object_Name", "Out_Of_Service", "Number_Of_States", "Relinquish_Default"], + "enabled": [], + "writable": ["Present_Value"], + "accepted": ["Event_State"], + "note": "state 1 of 3, default state 1; commandable via a 16-slot Priority_Array (WriteProperty, DS-WP-B) - Present_Value/Priority_Array/Current_Command_Priority are resolved by the stack from the slots the app serves through GetPropertyUnsignedInteger/GetPropertyBool" + }, + { + "type": "Network Port", + "instance": 1, + "name": "Vermilion", + "app": ["Object_Name", "Out_Of_Service", "Network_Type", "Protocol_Level", "Changes_Pending"], + "enabled": [], + "writable": [], + "accepted": ["Reliability"], + "note": "BACnet/IP; Network_Type and Protocol_Level are set from BACnetStack_AddNetworkPortObject()'s arguments (IPv4, BACnet Application) at start-up, not a GetProperty callback like the object's other app-served rows; Changes_Pending is likewise computed and answered natively by the stack's Network Port object. Reliability has no fault condition this example detects, so it is accepted at the generic default (normal)" + } + ] +} diff --git a/main.cpp b/main.cpp index 0a732c5..d4c13d5 100644 --- a/main.cpp +++ b/main.cpp @@ -78,7 +78,7 @@ using namespace CASBACnetStackExampleConstants; // 1. Example + device configuration // ----------------------------------------------------------------------------- static const char* APP_NAME = "BACnet B-ASC (Application Specific Controller) Example - C++"; -static const char* APP_VERSION = "1.1.0"; +static const char* APP_VERSION = "1.2.0"; // The device instance. BACnet requires this to be configurable, so it defaults // to 389003 and can be overridden on the command line with --deviceID. @@ -225,17 +225,44 @@ static bool ReadPrioritySlot(const Commandable* c, uint32_t propertyIdentifier, // stack uses a separate callback. We return true (and fill *value) when we // recognise the (object, property) pair, and false otherwise. // -// WHAT false ACTUALLY DOES - the most important paragraph in this file, and the -// opposite of what most people assume. Returning false does NOT reliably produce -// a BACnet error. The stack only errors for the handful of properties it refuses -// to invent: Present_Value, Number_Of_States, Relinquish_Default, Local_Date, -// Local_Time, and a Network Port's APDU_Length. +// THE errorCode OUT-PARAMETER. Every Get callback ends with uint32_t* errorCode. +// The stack PRESETS it to success (84) before the call, and reads it only if you +// return false. That gives a declining callback two distinct meanings: +// +// 1. return false and LEAVE errorCode ALONE -> "I have no opinion on this +// property." The stack falls back to its own handling (see below). +// 2. return false and SET *errorCode -> "This read fails, with THIS +// BACnet error." The client gets exactly that Error-PDU. +// +// Option 2 is new (CAS BACnet Stack issue #974); before it, a Get callback had +// no way to name an error at all. Do not reach for it reflexively - option 1 is +// still the right answer most of the time, for the reason in the next paragraph. +// +// WHAT false-WITHOUT-AN-ERROR-CODE ACTUALLY DOES - the most important paragraph +// in this file, and the opposite of what most people assume. It does NOT +// reliably produce a BACnet error. The stack errors only for the handful of +// properties it refuses to invent: Present_Value, Number_Of_States, +// Relinquish_Default, Local_Date, Local_Time, and a Network Port's APDU_Length +// (declining one of those now reads back as Error: read-access-denied, where +// older stack versions said value-not-initialized). // For EVERYTHING ELSE, a false return means the stack SILENTLY SUBSTITUTES a // default: // Object_Name -> the literal string "undefined" // Units -> no-units (95) // otherwise -> a datatype zero-value // +// AND THAT FALLBACK IS LORE-BEARING, WHICH IS WHY WE DO NOT "FIX" IT HERE. +// It is tempting to end every callback with *errorCode = unknown-property so +// nothing is ever silently invented. That breaks the device. The stack relies on +// the decline-and-fabricate path to answer required properties the application +// is not expected to serve - the Device's Max_APDU_Length_Accepted, APDU_Timeout +// and Number_Of_APDU_Retries among them. Name an error on the catch-all return +// and those required properties start failing instead of answering. +// So: set *errorCode ONLY where THIS device knows the read is wrong. There is +// exactly one such case below (State_Text with an out-of-range array index); the +// catch-all `return false` at the end of each callback deliberately leaves +// errorCode alone. +// // ADDING AN OBJECT? READ THIS FIRST. // The consequence is the opposite of reassuring. These callbacks are not // uniformly strict: @@ -262,7 +289,8 @@ static bool ReadPrioritySlot(const Commandable* c, uint32_t propertyIdentifier, bool GetPropertyReal(const uint32_t deviceInstance, const uint16_t objectType, const uint32_t objectInstance, const uint32_t propertyIdentifier, float* value, const bool useArrayIndex, - const uint32_t propertyArrayIndex) { + const uint32_t propertyArrayIndex, uint32_t* errorCode) { + (void)errorCode; // see "THE errorCode OUT-PARAMETER" above: we decline without naming an error if (deviceInstance != g_deviceInstance) { return false; } @@ -308,7 +336,8 @@ bool GetPropertyReal(const uint32_t deviceInstance, const uint16_t objectType, bool GetPropertyEnumerated(const uint32_t deviceInstance, const uint16_t objectType, const uint32_t objectInstance, const uint32_t propertyIdentifier, uint32_t* value, const bool useArrayIndex, - const uint32_t propertyArrayIndex) { + const uint32_t propertyArrayIndex, uint32_t* errorCode) { + (void)errorCode; if (deviceInstance != g_deviceInstance) { return false; } @@ -376,7 +405,8 @@ bool GetPropertyEnumerated(const uint32_t deviceInstance, const uint16_t objectT bool GetPropertyUnsignedInteger(const uint32_t deviceInstance, const uint16_t objectType, const uint32_t objectInstance, const uint32_t propertyIdentifier, uint32_t* value, const bool useArrayIndex, - const uint32_t propertyArrayIndex) { + const uint32_t propertyArrayIndex, uint32_t* errorCode) { + (void)errorCode; if (deviceInstance != g_deviceInstance) { return false; } @@ -450,7 +480,8 @@ bool GetPropertyUnsignedInteger(const uint32_t deviceInstance, const uint16_t ob bool GetPropertyBool(const uint32_t deviceInstance, const uint16_t objectType, const uint32_t objectInstance, const uint32_t propertyIdentifier, bool* value, const bool useArrayIndex, - const uint32_t propertyArrayIndex) { + const uint32_t propertyArrayIndex, uint32_t* errorCode) { + (void)errorCode; if (deviceInstance != g_deviceInstance) { return false; } @@ -489,9 +520,10 @@ bool GetPropertyOctetString(const uint32_t deviceInstance, const uint16_t object const uint32_t objectInstance, const uint32_t propertyIdentifier, uint8_t* value, uint32_t* valueElementCount, const uint32_t maxElementCount, const bool useArrayIndex, - const uint32_t propertyArrayIndex) { + const uint32_t propertyArrayIndex, uint32_t* errorCode) { (void)useArrayIndex; (void)propertyArrayIndex; + (void)errorCode; if (deviceInstance != g_deviceInstance || objectType != OBJECT_TYPE_NETWORK_PORT || objectInstance != NETWORK_PORT_INSTANCE || @@ -539,7 +571,8 @@ bool GetPropertyCharString(const uint32_t deviceInstance, const uint16_t objectT const uint32_t objectInstance, const uint32_t propertyIdentifier, char* value, uint32_t* valueElementCount, const uint32_t maxElementCount, uint8_t* encodingType, - const bool useArrayIndex, const uint32_t propertyArrayIndex) { + const bool useArrayIndex, const uint32_t propertyArrayIndex, + uint32_t* errorCode) { if (deviceInstance != g_deviceInstance) { return false; } @@ -555,6 +588,11 @@ bool GetPropertyCharString(const uint32_t deviceInstance, const uint16_t objectT return ReturnCharacterString(stateText[propertyArrayIndex - 1], value, valueElementCount, maxElementCount, encodingType); } + // The one place in this file where naming an error is clearly right: the + // client asked for State_Text[n] and this object has no element n. That + // is not "no opinion" - it is a wrong read, and the spec has a code for + // it. Without this the client would silently receive an empty string. + *errorCode = ERROR_CODE_INVALID_ARRAY_INDEX; return false; } @@ -874,6 +912,10 @@ int main(int argc, char** argv) { } // --- Register callbacks ------------------------------------------------- + // Tell the helper which Network Port object owns the socket it just bound. + // The stack identifies a link by its Network Port INSTANCE, so the transport + // callbacks (and the start-up I-Am) have to name the one added below. + CASExampleHelper::SetNetworkPortInstance(NETWORK_PORT_INSTANCE); // The transport + time callbacks are shared boilerplate. CASExampleHelper::RegisterCommonCallbacks(); // The property callbacks are specific to this example. @@ -974,7 +1016,7 @@ int main(int argc, char** argv) { // networkNumber 0 with quality "unknown" describes a local port that has not // learned its network number - the right answer for a device that is not a // router and has not been told one. - if (!BACnetStack_AddNetworkPortObjectWithNetworkNumber( + if (!BACnetStack_AddNetworkPortObject( g_deviceInstance, NETWORK_PORT_INSTANCE, NETWORK_PORT_NETWORK_TYPE_IPV4, NETWORK_PORT_PROTOCOL_LEVEL_BACNET_APPLICATION,