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
61 changes: 16 additions & 45 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 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.
# Build the B-ASC 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 All @@ -24,17 +25,15 @@ jobs:
fail-fast: false
matrix:
include:
# windows-2022, not windows-latest: the stack's vcxproj names the v143 (VS 2022)
# toolset; newer images may not carry it.
# windows-2022 pins the VS 2022 (v143) toolset the released binaries are built
# with, so the published metrics stay comparable release to release.
- 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:
- 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": "BACnetExampleBASC",
"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
60 changes: 37 additions & 23 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,57 @@

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 the BACnet **B-ASC (Application Specific Controller)**
device profile using the CAS BACnet Stack. It is one of a series - one git repo
per BACnet profile - and builds on the B-SA (Smart Actuator) example by adding
DeviceCommunicationControl (DM-DCC-B). The top priority is that the code reads
like a tutorial a customer can learn from and copy-paste. Favour clarity over
cleverness.
A **tutorial** C++ example that implements the BACnet **B-ASC (Application
Specific Controller)** device profile using the CAS BACnet Stack. It is one of
a series - one git repo per BACnet profile - and adds
DeviceCommunicationControl (DM-DCC-B) and commandable outputs (DS-WP-B) on top
of the shared read-only sensor objects every example in the series carries.
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 in-repo (not referenced via a path
outside the repository).
- `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. 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.
- `submodules/cas-bacnet-stack/` - the **CAS BACnet Stack** as a git submodule
(private). After cloning, run `git submodule update --init --recursive`.
(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.

## 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:
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-ASC-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 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.
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 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 Down Expand Up @@ -93,6 +105,9 @@ There are no unit tests; verification is behavioural:
5. **DeviceCommunicationControl**: confirm `disable-initiation` and `enable`
SimpleACK, the deprecated `disable` is rejected (service-request-denied), and a
wrong password (if `DCC_PASSWORD` is set) is rejected (password-failure).
6. If you changed the objects or their properties, regenerate `docs/PICS.md`
(`python tools/gen-objects-properties.py BACnetProfileExample-B-ASC-CPP` from
the series root) and confirm no row comes out flagged with ⚠.

## Releasing

Expand All @@ -101,6 +116,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.
53 changes: 53 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,59 @@ 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 — documentation restructure, SOURCE link

- **README.md cut down to this example only.** Removed the series "start
here" framing, the generic device-profile explainer, the "What the profile
requires" prose (the BIBBs table already said this), "Before you ship" (its
per-field guidance moved into code comments in `main.cpp`, see below), "Get
the code", "Link mode", "Troubleshooting", "Extending the example", and
"Objects and properties" (now generated into `docs/PICS.md` instead).
Added a prebuilt-binary release link and pointers to the two new documents
near the top.
- **`TUTORIAL.md` added** - the extending/reviewing material that used to
bloat the README: the "Add a second analog input" silent-failure walk-through,
what each object type (including the three commandable outputs) needs the
app to serve, a Served-by breakdown for both a plain object (Analog Input 1)
and a commandable one (Analog Output 1), the DeviceCommunicationControl
`*errorCode` contract, "Reviewing your device", "Using this example as the
base for a real product" (what to copy out of `common/`, calling
`BACnetStack_Tick()` correctly), and Troubleshooting.
- **`docs/PICS.md` added** - an ANSI/ASHRAE 135 Annex A format Protocol
Implementation Conformance Statement, with the objects-and-properties table
generated from `docs/objects.json` (`tools/gen-objects-properties.py`,
zero ⚠ rows).
- **`docs/objects.json`'s Device entry gained a `stack` list** separate from
`accepted`, matching the shape the rest of the series uses: `Object_List`,
`Protocol_Version`, `Protocol_Revision`, `Protocol_Services_Supported`,
`Protocol_Object_Types_Supported` and `Device_Address_Binding` are
device-wide facts the stack computes (rendered as plain `stack`, not `stack
default, accepted`); `accepted` now holds only the stack's configured
defaults this example does not override (`System_Status`,
`Max_APDU_Length_Accepted`, `Segmentation_Supported`, `APDU_Timeout`,
`Number_Of_APDU_Retries`, `Database_Revision`).
- **Build switched from a prebuilt STATIC library to the adapter's default
SOURCE mode**: `cmake -B build -S .` / `cmake --build build --config
Release` compiles the stack straight into the executable, with no
`tools/build-stack-static.sh` pre-step and no `-DCAS_BACNET_STACK_LINK=...`
flag. `CMakeLists.txt`'s header comment, `AGENTS.md`, and
`.github/workflows/release.yml` (drops the static-library cache/build steps
and the matrix `lib:` entries, asserts `CAS_BACNET_STACK_LINK=SOURCE`, sets
`"link_mode": "SOURCE"` in the published metrics JSON, and packages
`TUTORIAL.md` / `docs/PICS.md` alongside the binaries) now match.
- **`main.cpp`'s `CHANGE ALL OF THIS BEFORE YOU SHIP` block absorbed the
README's "Before you ship" table** as per-field comments, including the
`DEVICE_NAME` internetwork-uniqueness warning and the DCC password
plaintext-on-the-wire note.
- **Footprint table left as-is with a refresh note added**: the published
v1.2.0 numbers were measured from a STATIC-linked binary; the next release
refreshes them from the SOURCE-mode build now documented.
- Corrected the README's "Expected output" sample, which had dropped the
`(Network Port 1)` suffix the binary actually prints on the `Listening for
BACnet/IP` and start-up `TX` lines.

## [1.2.0] - 2026-09-15

### Changed — STATIC link, generated README blocks
Expand Down
15 changes: 7 additions & 8 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-ASC-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/BACnetExampleBASC (Linux/macOS)
Expand Down
Loading
Loading