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
154 changes: 98 additions & 56 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand All @@ -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 }}" <<EOF
{
"example": "BACnetExampleBASC",
"app_version": "$appver",
"os": "${{ matrix.os }}",
"link_mode": "STATIC",
"stack_commit": "${{ steps.stack.outputs.sha }}",
"stack_version": "$stackver",
"binary_bytes": $bytes,
"binary_sha256_prefix": "$sha",
"startup_ms_to_ready": $ready_ms,
"compiler": "$compiler",
"built_at": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
"git_ref": "${{ github.ref_name }}"
}
EOF
cat "${{ matrix.metrics }}"
{ echo '### metrics (${{ matrix.os }})'; echo '```json'; cat "${{ matrix.metrics }}"; echo '```'; } >> "$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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
27 changes: 20 additions & 7 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
68 changes: 68 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
20 changes: 9 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading
Loading