Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 14 additions & 43 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Build the B-BC 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.
# Build the B-BC example 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 build is exactly what README.md tells a customer to run: plain CMake in
# the adapter's default SOURCE mode, which compiles the stack into the executable.
#
# 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.
Expand Down Expand Up @@ -29,12 +30,10 @@ jobs:
- os: windows-2022
artifact: BACnetExampleBBC-windows-x64
exe: build/Release/BACnetExampleBBC.exe
lib: submodules/cas-bacnet-stack/bin/CASBACnetStack_x64_Release.lib
metrics: metrics-windows.json
- os: ubuntu-latest
artifact: BACnetExampleBBC-linux-x64
exe: build/BACnetExampleBBC
lib: submodules/cas-bacnet-stack/bin/libCASBACnetStack_x64_Release.a
metrics: metrics-linux.json
steps:
- name: Enable git long paths (Windows)
Expand All @@ -47,52 +46,23 @@ jobs:
submodules: recursive
token: ${{ secrets.CAS_STACK_PAT || github.token }}

- name: Stack commit (cache key)
- name: Stack commit (recorded in metrics.json)
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: Configure
run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Release

# The README documents `cmake -B build -S .` with no link-mode flag, so assert the
# adapter's default really is SOURCE. If that default ever changes, the documented
# build silently starts needing a prebuilt library and fails for customers first.
- name: Confirm the link mode CMake actually used
shell: bash
run: |
mode=$(grep -E '^CAS_BACNET_STACK_LINK:' build/CMakeCache.txt | cut -d= -f2)
echo "CAS_BACNET_STACK_LINK=$mode"
[ "$mode" = "STATIC" ] || { echo "FAIL: expected STATIC, got '$mode'"; exit 1; }
[ "$mode" = "SOURCE" ] || { echo "FAIL: expected SOURCE, got '$mode'"; exit 1; }

- name: Build
run: cmake --build build --config Release
Expand Down Expand Up @@ -128,7 +98,7 @@ jobs:
"example": "BACnetExampleBBC",
"app_version": "$appver",
"os": "${{ matrix.os }}",
"link_mode": "STATIC",
"link_mode": "SOURCE",
"stack_commit": "${{ steps.stack.outputs.sha }}",
"stack_version": "$stackver",
"binary_bytes": $bytes,
Expand All @@ -147,7 +117,8 @@ jobs:
run: |
mkdir -p dist
cp "${{ matrix.exe }}" "${{ matrix.metrics }}" dist/
cp README.md LICENSE dist/ 2>/dev/null || true
cp README.md TUTORIAL.md LICENSE dist/ 2>/dev/null || true
cp docs/PICS.md dist/ 2>/dev/null || true

- name: Upload build artifact
uses: actions/upload-artifact@v4
Expand Down
107 changes: 60 additions & 47 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,66 @@

Guidance for AI coding agents working in this repository. See
<https://agents.md/> for the format. Human contributors should read
[README.md](README.md) first.
[README.md](README.md) first, then [TUTORIAL.md](TUTORIAL.md).

## What this project is

A **tutorial** C++ example that implements **as much of** the BACnet **B-BC
(Building Controller)** profile as the standard CAS BACnet Stack supports. It
is the series **capstone** - one git repo per BACnet profile - grafting
together features already proven by six sibling examples (commandable
outputs, DeviceCommunicationControl, intrinsic alarming, a writable
event-recipient list, time synchronisation, ReinitializeDevice, Backup and
Restore, external-write scheduling) plus one genuinely new feature this
example defines: **trending** (Trend Log, Trend Log Multiple, ReadRange).
What B-BC requires but the stack cannot yet do, or a defect the stack has,
is documented in [TODO.md](TODO.md) - keep that file honest and current. The
top priority is that the code reads like a tutorial a customer can learn
from and copy-paste. Favour clarity over cleverness.
is the series' largest single example - combining commandable outputs,
DeviceCommunicationControl, intrinsic alarming, a writable event-recipient
list, time synchronisation, ReinitializeDevice, Backup and Restore, external-
write scheduling (SCHED-E-B), and trending (Trend Log, Trend Log Multiple,
ReadRange). What B-BC requires but the stack cannot yet do, or a defect the
stack has, is documented in [TODO.md](TODO.md) and [TUTORIAL.md](TUTORIAL.md)
- keep both honest and current. The top priority is that the code reads like
a tutorial a customer can learn from and copy-paste. Favour clarity over
cleverness.

## Layout

This repository is self-contained:

- `main.cpp` - the example device.
- `common/` - the shared helper (vendored).
- `README.md` - what this example is. Keep it short and about THIS example
only.
- `TUTORIAL.md` - how to extend and review the example, including every
known silent-failure trap and this example's filed stack gaps. Long-form
material that would bloat the README belongs here.
- `docs/PICS.md` - the Protocol Implementation Conformance Statement. Its
objects-and-properties section is GENERATED from `docs/objects.json`; do
not hand-edit between the `OBJECTS-PROPERTIES` markers.
- `docs/objects.json` - the input to that generator. Update it in the same
change as any `main.cpp` change that adds an object or a `GetProperty*`
branch. The Device object's entry must stay first.
- `submodules/cas-bacnet-stack/` - the **CAS BACnet Stack** as a git submodule
(private; compiled from source). After cloning, run
`git submodule update --init --recursive`.

The `PROFILE-TABLE` block in README.md is also generated, from the
example-series repository's `docs/profile-table.md`. Edit it there, not here,
and re-sync with `./tools/sync-profile-table.sh BACnetProfileExample-B-BC-CPP`
(always with the repo argument - omitting it rewrites every sibling repo).

## Build

This example links the CAS BACnet Stack as a prebuilt **STATIC** library (the
only mode it ships in - see the README's "Link mode" section):
Plain CMake, identical on every platform, in the adapter's default SOURCE mode
(the stack's sources are compiled into the executable - no prebuilt library, no
DLL, no per-platform pre-step):

```bash
git submodule update --init --recursive # once, if not cloned with --recursive
tools/build-stack-static.sh BACnetProfileExample-B-BC-CPP # from the series root
cmake -B build -S . -DCAS_BACNET_STACK_LINK=STATIC
cmake -B build -S .
cmake --build build --config Release
```

The stack library build takes several minutes the first time - it compiles
the whole stack (~600 files) once, via the stack's own project files; the
example itself then builds in seconds against that library. Use
`-D CAS_STACK_DIR=...` only if your stack lives outside the bundled
submodule.

**Toolset note for a machine with multiple Visual Studio installs:** if
linking fails with `LINK : fatal error C1900: Il mismatch`, the stack
library and the example were built with different physical compiler copies.
Pass `TOOLSET=<PlatformToolset the pinned vcxproj declares>` and
`MSBUILD=<path to the matching msbuild.exe>` to `build-stack-static.sh` to
pin both builds to the same copy.
The first build compiles the whole stack (~600 files) and takes a few minutes;
rebuilds after that are incremental and fast. Use `-D CAS_STACK_DIR=...` only if
your stack lives outside the bundled submodule. Do not reintroduce a link-mode
flag, `tools/build-stack-static.sh`, or a series-root build script into the
documented build: a customer downloads this repository on its own and must be
able to build it with the two commands above.

## Run

Expand All @@ -61,27 +70,24 @@ pin both builds to the same copy.
.\build\Release\BACnetExampleBBC.exe [--port 47808] [--deviceID 389005] # Windows
```

Interactive keys while running: `h` help, `q` quit, up/down nudge Analog Input 1,
`s` advance Schedule 1 (Saffron) to a transition right now.
Interactive keys while running: `h` help, `q` quit, up/down nudge Analog
Input 1, `s` advance Schedule 1 (Saffron) to a transition right now.

## Conventions

- Device is named "Rainbow"; objects use the series' colour names; vendor id 389.
- Implement the B-BC services the stack supports; expose **every required
property** of each object for Protocol_Revision 24. Anything B-BC requires
that is NOT implemented must be listed in [TODO.md](TODO.md) and the README.
- Intrinsic alarming, commandable outputs, DeviceCommunicationControl, time
sync and ReinitializeDevice follow the same patterns as B-AAC (this
example's seed) - see its own AGENTS.md if working on those sections.
- **Trending (new in this example):** `BACnetStack_AddTrendLogObject` /
`AddTrendLogMultipleObject` + `AddLoggedObjectToTrendLogMultiple` +
`SetTrendLogTypeToPolled` create and drive a Trend Log; the stack stores
and serves almost everything (`Enable`, `Buffer_Size`, `Log_Buffer`,
`Record_Count`, etc.) - only `Object_Name` needs an app callback.
`Log_Buffer` is **ReadRange-only** (a plain ReadProperty is rejected).
**KNOWN STACK DEFECT:** calling `SetTrendLogStartStopTime` on a Trend Log
(not Trend Log Multiple) reproducibly blocks `Record_Count` from ever
incrementing - filed as
that is NOT implemented must be listed in [TODO.md](TODO.md) and
[TUTORIAL.md](TUTORIAL.md).
- **Trending:** `BACnetStack_AddTrendLogObject` / `AddTrendLogMultipleObject`
+ `AddLoggedObjectToTrendLogMultiple` + `SetTrendLogTypeToPolled` create and
drive a Trend Log; the stack stores and serves almost everything (`Enable`,
`Buffer_Size`, `Log_Buffer`, `Record_Count`, etc.) - only `Object_Name`
needs an app callback. `Log_Buffer` is **ReadRange-only** (a plain
ReadProperty is rejected). **KNOWN STACK DEFECT:** calling
`SetTrendLogStartStopTime` on a Trend Log (not Trend Log Multiple)
reproducibly blocks `Record_Count` from ever incrementing - filed as
[cas-bacnet-stack#2051](https://github.com/chipkin/cas-bacnet-stack/issues/2051).
Don't "fix" this by silently dropping the call from Lilac - it demonstrates
correct API usage on purpose; Magenta (which never calls it) is the working
Expand All @@ -106,8 +112,12 @@ Interactive keys while running: `h` help, `q` quit, up/down nudge Analog Input 1
the four Prepare/Complete Backup/Restore callbacks + `ReadFile`/`WriteFile`
callbacks on File 1 (Ivory); `ReinitializeDevice` must accept states 2-6
(STARTBACKUP..ABORTRESTORE) as well as COLDSTART/WARMSTART.
- Match the surrounding code style: `const`-correct parameters, check every stack
return value, keep `main.cpp` linear and well-commented.
- An OPTIONAL property needs `BACnetStack_SetPropertyEnabled`, not just a
`GetProperty*` callback branch - the stack checks whether a property is
enabled before it ever calls your callback. This example shipped that exact
bug once for the Device's `Description`. See TUTORIAL.md.
- 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
every example in the series, with its own version (`COMMON_VERSION`) and
changelog (`common/CHANGELOG.md`). To change it: edit, bump the version, add
Expand Down Expand Up @@ -142,6 +152,10 @@ There are no unit tests; verification is behavioural:
9. **Device management**: ReinitializeDevice WARMSTART SimpleACKs; DCC
`disable-initiation`/`enable` SimpleACK; a wrong password (if set) is
rejected.
10. If you changed the objects or their properties, regenerate
`docs/PICS.md` (`python tools/gen-objects-properties.py
BACnetProfileExample-B-BC-CPP` from the series root) and confirm no row
comes out flagged with ⚠.

Verification is manual (no in-repo test suite ships).

Expand All @@ -152,6 +166,5 @@ then tag `vX.Y.Z`. The GitHub Actions workflow builds and publishes the release.

## License

The example source code is dedicated to the public domain under
[CC0-1.0](LICENSE). The CAS BACnet Stack is a separate, commercially licensed
product and is not covered by that dedication.
See [LICENSE](LICENSE). The CAS BACnet Stack is a separate, commercially
licensed product and is not covered by it.
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,35 @@ 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).

## [Unreleased]

### Changed

- Restructured documentation to match the series' shared shape: `README.md`
is cut down to what this example is and how to build/run/verify it;
`TUTORIAL.md` (new) carries the extending/reviewing material and every
silent-failure trap and filed stack gap (SetTrendLogStartStopTime blocking
Lilac's Record_Count - #2051, the AddTrendLogObject log flood - #2050, the
SCHED-E-B remote-write test-topology limitation, and the Calendar Date_List
gap - #963); `docs/PICS.md` (new) is the ANSI/ASHRAE 135 Annex A conformance
statement, generated in part from `docs/objects.json`.
- `docs/objects.json` gained a `Device` entry (previously the generated tables
omitted the Device object).
- Build documentation switched from the prebuilt **STATIC** library
(`tools/build-stack-static.sh` + `-DCAS_BACNET_STACK_LINK=STATIC`) to the
adapter's default **SOURCE** mode: `cmake -B build -S .` then
`cmake --build build --config Release`, identical on every platform, no
series-root script or prebuilt library step. `.github/workflows/release.yml`
dropped the static-library cache/build steps and the matrix `lib:` entries,
configures without a link-mode flag, asserts `CAS_BACNET_STACK_LINK=SOURCE`,
records `"link_mode": "SOURCE"` in the published metrics, and packages
`TUTORIAL.md` / `docs/PICS.md` alongside the binary. The published v1.0.0
footprint numbers were measured under the STATIC build; the next release
refreshes them under the SOURCE build documented here.
- `main.cpp`'s `CHANGE ALL OF THIS BEFORE YOU SHIP` block gained a per-field
comment for every ship-checklist item, including the `DEVICE_NAME`
uniqueness warning.

## [1.0.0] - 2026-09-15

### Added
Expand Down
20 changes: 10 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
#
# 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. 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.)
# (BACnetStack_*, via CASBACnetStackAdapter.h) directly. It builds and ships in the
# adapter's default SOURCE mode: the stack's source/*.cpp are compiled straight into
# the executable, so there is no library or DLL to build, ship, or install first and
# the build is the same two commands on every platform. (The adapter also offers
# STATIC and DLL modes - see its CMakeLists.txt - but they need a prebuilt library
# and this example does not use them.)
#
# Build:
# tools/build-stack-static.sh BACnetProfileExample-B-BC-CPP (from the series root)
# cmake -B build -S . -DCAS_BACNET_STACK_LINK=STATIC
# cmake -B build -S .
# cmake --build build --config Release --parallel
# Run (from the example folder):
# ./build/BACnetExampleBBC (Linux/macOS)
Expand Down Expand Up @@ -60,8 +59,9 @@ endif()

# --- The CAS BACnet Stack, via its CMake adapter target ---------------------
# CAS_BACNET_STACK_LINK is the adapter's own cache variable (SOURCE/STATIC/DLL,
# default SOURCE) - set it BEFORE add_subdirectory() so the adapter target picks it up.
# See submodules/cas-bacnet-stack/adapters/cpp/CMakeLists.txt for what each mode does.
# default SOURCE, which is what this example builds with). To override it, set it
# BEFORE add_subdirectory() so the adapter target picks it up. See
# submodules/cas-bacnet-stack/adapters/cpp/CMakeLists.txt for what each mode does.
add_subdirectory("${CAS_STACK_DIR}/adapters/cpp" cas-bacnet-stack-adapter)

# --- The shared example helper ----------------------------------------------
Expand Down
Loading
Loading