Skip to content

B-ASC example: adopt the CAS BACnet Stack C++ adapter (v6), verify all three link modes, and correct the docs - #3

Merged
ssmethurst merged 15 commits into
mainfrom
llm-auto-2026-july
Aug 1, 2026
Merged

ssmethurst merged 15 commits into
mainfrom
llm-auto-2026-july

Conversation

@sws-chipkin

Copy link
Copy Markdown
Contributor

Brings the B-ASC example onto CAS BACnet Stack v6 and its new C++ adapter, verifies every
supported link mode by actually running the binary, and fixes a batch of documentation defects
found by a five-persona review. The stack submodule moves 863a090e → 756371c1
(6.x-TestTool, containing cas-bacnet-stack PRs #267 and #268).

Squash note: this branch also carries two earlier commits by @funvill that predate the adapter
work — the v6 / Network Port migration and the common/ v1.4.0 sync (deferred restart, B-OD
re-sync). They are included here and described below.


What changed

1. Links the stack through CASBACnetStack::Adapter instead of hand-globbing its source

CMakeLists.txt now add_subdirectory()s the stack's adapters/cpp and links one target,
replacing the file(GLOB) over ~600 source/*.cpp that every example in the series repeats.

CAS_BACNET_STACK_LINK selects how the stack is linked — SOURCE (default; compiles in,
self-contained binary), STATIC (prebuilt .lib/.a), or DLL (loaded at runtime).
Switching is a CMake flag, not a code change.

2. Application code is unchanged — that is the point

main.cpp and common/ still call BACnetStack_AddDevice(...) and friends by the exact export
name. The adapter exposes the same names in all three modes (in DLL mode they are same-named
function-pointer variables bound at load). The only new requirement is one call:

if (!LoadBACnetFunctions()) {
    fprintf(stderr, "Error: failed to load the CAS BACnet Stack: %s\n",
            CASBACnetStackAdapter_LastError());
    return 1;
}

It is the first statement in main() — before --help/--version, because printing the
version calls into the stack. Mandatory in every mode: in DLL mode it binds the symbols, and in
all modes it runs a stack-version handshake.

3. All three link modes verified — built and run, not just configured

Mode Result
SOURCE Builds, runs, binds the port, broadcasts I-Am, answers a live client
STATIC Same, and confirmed with no DLL beside the executable
DLL Same, plus both failure paths — library absent, and library present but missing an export — each prints a readable error and exits cleanly, never crashes

STATIC needed a real fix to get there: the prebuilt library is built /MT while CMake defaults
consumers to /MD, which produced 562 LNK2038 errors that read like a corrupt library. The
adapter now forces the matching runtime (fixed upstream in #268).

4. Release CI pins the published link mode explicitly

release.yml passes -DCAS_BACNET_STACK_LINK=SOURCE rather than relying on the CMake default,
and asserts it back out of CMakeCache.txt. A published artifact must stay a single
self-contained executable even if that default ever moves; DLL mode would fail at start-up for
anyone who downloaded only the exe.

5. Documentation corrections (five-persona review, two rounds)

Reviewed as a lead developer, an educator, a junior integrator, a BACnet newcomer, and a staff
architect; average score 7.6 → 8.0 across rounds. Fixed here:

  • Version banner drift — docs claimed common/ v1.3.0 against a newer tree, in a project
    whose own docs teach "the printed versions are how you detect drift". Now matches the binary.
  • Jargon defined at first use — the BIBB -A/-B (initiator/responder) convention,
    Protocol_Revision, BACnet/SC, "BACnet internetwork", and a concrete answer to what a B-ASC
    device actually is (thermostat, VAV box, fan-coil controller).
  • A free verification path — YABE and Wireshark named alongside the commercial explorer, so
    evaluating the example costs nothing.
  • Troubleshooting rows corrected — one quoted a CMake error string that no longer exists
    (a reader pastes the real message into ctrl-F and finds nothing); another blamed
    SO_REUSEADDR where the code asks for SO_EXCLUSIVEADDRUSE on Windows. Added a row for the
    most likely silent failure on a dev laptop: the example picks the first non-loopback adapter,
    which with Hyper-V/WSL/VPN is often not the real NIC, so the device looks healthy and no
    client ever sees it.
  • Two new sections — what in common/ is demo-only vs production-worthy (per-packet
    printf, the keyboard loop, the IP guess), and the BACnetStack_Tick() contract: call
    regularly, callbacks run synchronously on the calling thread, and the stack contains no
    locking of any kind
    , so drive it from exactly one thread.
  • common/README.md no longer teaches a broken skeleton — its copyable main() omitted the
    now-mandatory LoadBACnetFunctions(), which in DLL mode is a null-pointer call.
  • Comments read as a snapshot, not a changelog — removed narration about earlier versions of
    the file ("an earlier version of this comment got it backwards", "this example shipped exactly
    that bug", "trust the code, not the comment"), and citations into stack internals
    (BACnetBusinessLogic.cpp, IsPropertyCommandable()) that a first-time reader cannot usefully
    open. Every technical claim is kept, restated as observable API behaviour.
  • Parallel-build guidance for the ~600-file first compile.

6. Included from earlier on this branch (not part of the adapter work)

  • v6 / Network Port migration — AddNetworkPortObjectWithNetworkNumber, plus the
    constants it needs.
  • common/ v1.4.0 — the deferred-restart helper for DM-RD-B (never restart inside the
    ReinitializeDevice callback; the SimpleACK does not reach the wire until a later Tick()),
    and a B-OD re-sync. common/ ends this branch at v1.5.1.

Verification

  • SOURCE, STATIC and DLL each built and run; DLL's two failure paths exercised.
  • --help / --version checked (they run before the socket binds, and --help no longer prints
    the version banner twice).
  • Upstream gates green at the pinned stack commit: full gtest suite 4312/4312, adapter
    drift + export-coverage gates, doc-lint.

Reviewer notes

  • common/ is vendored into all eight examples in the series. It ends at v1.5.1 here and
    the LoadBACnetFunctions() requirement is a contract change: every other example needs the
    same call added to its main() when it re-syncs. That propagation is deliberately not in
    this PR — one example at a time.
  • The migration steps are written up as a reusable checklist in the tool repo at
    docs/runbook-bacnet-profile.md (§3a), for the other seven profiles and for new-language ports.
  • No behaviour change to the BACnet device itself: same objects, same services, same profile.

🤖 Generated with Claude Code

ssmethurst and others added 15 commits July 18, 2026 13:51
Pin the stack submodule to 6.x-TestTool 92c91d74 (Sprint 261 P1-P5 public-interface review).

v6 removed BACnetStack_AddNetworkPortObject; migrated to BACnetStack_AddNetworkPortObjectWithNetworkNumber,
passing networkNumber 0 + NETWORK_NUMBER_QUALITY_UNKNOWN, which reproduce the old behaviour (a local port
that has not been configured with, or learned, a network number). Added the BACnetNetworkNumberQuality
constants (cl. 12.56.11) to the example constants header.

Builds clean against the pinned stack.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…D re-sync)

Vendoring sweep. common/ must be identical in every example of the series, so
this lands the v1.4.0 helper here even though this profile does not use it:

- Adds RequestRestart()/RestartDue(), the deferred-restart pattern for
  ReinitializeDevice (DM-RD-B). Inert unless an example calls it; only B-AAC
  does, since it is the only profile in the series with DM-RD-B.
- Re-syncs CASBACnetStackExampleConstants.h in B-OD, which had silently gone
  stale: it never received the NETWORK_NUMBER_QUALITY_* constants from the
  2026-07-17 item-16 migration because B-OD was the one example that did not
  itself need the migrated AddNetworkPortObjectWithNetworkNumber call. Nothing
  failed to compile there, so the folder's byte-identical guarantee broke
  silently. (No-op in the other six repos, which were already current.)

Verified: content-identical across all 8 repos; B-AAC and B-OD both build.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
38 commits ahead of the previous pin (92c91d74). Breaking API changes in
range (RegisterHookProperty* removal, DecodeAs fold, SetCOVMultipleSettings
rename, SetBackupAndRestoreEnabled signature, SetObjectTypeSupported
removal) verified unused by this example. Rebuilt Release, smoke-tested:
binds, broadcasts I-Am, device ready. One-time cosmetic BACnetSC 'UUID has
not been set' debug-log line at startup is new stack behavior, noted in
CHANGELOG.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…lobbing stack source

CMakeLists.txt now add_subdirectory()s submodules/cas-bacnet-stack/adapters/cpp and
links CASBACnetStack::Adapter, instead of file(GLOB)-ing every source/*.cpp itself.
CAS_BACNET_STACK_LINK (SOURCE default, or STATIC/DLL - set before configure) now
switches link modes without touching this file.

TEMPORARY submodule pin: submodules/cas-bacnet-stack now points at the tip of the
adapter-cpp-package branch (stacked on adapter-cpp-generate), not yet merged into
6.x-TestTool - see cas-bacnet-stack PRs #267 and #268. Re-pin to 6.x-TestTool once
both merge.

main.cpp/common/ still include CASBACnetStackDLL.h directly and call BACnetStack_*
unchanged (SOURCE mode exposes the same declarations via the adapter's transitive
include dirs) - the include-swap + LoadBACnetFunctions() adoption is the next commit.

Verified: fresh MSVC Release build, clean; smoke-run on --port 47899 identical to
pre-migration (binds, broadcasts I-Am, "Device 389003 (Rainbow) ready").

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…apter.h

main.cpp and common/CASExampleHelper.cpp now include CASBACnetStackAdapter.h
instead of CASBACnetStackDLL.h directly. All BACnetStack_* call sites are
UNCHANGED (34 in main.cpp, ~8 in common/) - the adapter exposes the exact same
names in every link mode, so this is purely an include swap plus one new call:
LoadBACnetFunctions() now runs as the very first thing in main(), before even
--help/--version (PrintVersion calls BACnetStack_GetAPIMajorVersion() etc., so
skipping the load step there would be a null-pointer call in DLL mode).

common/ -> v1.5.0 (CHANGELOG entry): this is a contract change for every example
in the series that vendors common/, not just B-ASC - each needs the same
LoadBACnetFunctions() call added to its main() when it re-syncs (Stage D,
out of scope here).

Verified: clean incremental MSVC rebuild; smoke-run identical to before (binds,
broadcasts I-Am, "Device 389003 (Rainbow) ready", RX 21 bytes from a real LAN
device - proving the adapter-mediated send/receive path both directions);
--version path also verified (exercises the pre-HandleHelpAndVersionArgs
LoadBACnetFunctions() placement specifically).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
README gets a new "Link modes" section under Build (SOURCE/STATIC/DLL,
CAS_BACNET_STACK_LINK cache var). CHANGELOG entry summarizes the CMake-target
migration across all 3 stages.

DLL-mode verification results (built the stack DLL via
submodules/cas-bacnet-stack/projects/msvs/BuildCASBACnetStack.sln,
ReleaseDll|x64, /p:PlatformToolset=v143 override - v145 isn't installed):

- FAILURE PATHS VERIFIED: DLL entirely absent -> clean
  "could not load the DLL" error, exit 1, no crash. DLL present but missing a
  required export -> clean "missing export: BACnetStack_X" error naming the
  exact symbol, exit 1, no crash. Both prove CASBACnetStackAdapter_LastError()
  and the all-or-nothing binding contract work correctly against a real DLL.
- SUCCESS PATH NOT ACHIEVED: the built DLL is missing 3 of 213 declared
  exports (BACnetStack_RegisterCallbackWriteGroupInhibitDelay, SendWhoAmI,
  SendYouAre) for reasons not fully root-caused (ruled out incremental-build
  staleness via a from-scratch clean rebuild; ruled out a source-level #ifdef
  miss for 2 of the 3, which are unguarded in source). Root-cause + fix is a
  stack-repo follow-up (task chip spawned) - two leads documented: the
  STACK_OPTION_TARGET_FULL preset not cascading to STACK_OPTION_WRITE_GROUP,
  and a possible LTCG/OPT:ICF interaction with __declspec(dllexport) for the
  unguarded pair. SOURCE and STATIC mode are unaffected (real function
  linkage, not runtime symbol lookup) and are fully verified end-to-end
  (Stage C1/C2 commits).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Submodule pin -> c22ac0ab, which carries the stack-side fix for the three
exports that were silently missing from every DLL build (option guards in
CASBACnetStackDLL.h evaluated before any options header was in scope). With
that fixed, DLL mode's SUCCESS path works for the first time: the example
loads the library, binds all 213 exports, passes the version handshake, and
runs - verified on port 47900. Both failure paths still degrade cleanly
(library absent -> "could not load ..."; wrong build -> "missing export: ...").
README's Link modes section rewritten accordingly, including the CWD-relative
library-lookup caveat and the BACNET_LIB_FILE override.

Documentation corrections from the five-persona review:
- Version banner and sample output said common/ v1.3.0 against a v1.5.0 tree -
  the exact drift the README teaches readers to detect. Now accurate, with a
  "trust the program" note.
- Defined at first use: the BIBB -A/-B (client/server side) convention,
  Protocol_Revision, BACnet/SC, "BACnet internetwork", and a concrete
  what-is-a-B-ASC anchor (thermostat / VAV / fan-coil).
- Verify section now names free clients (YABE, Wireshark) next to the
  commercial one, so evaluating costs nothing.
- Reading order no longer implies you must start at another repository.
- New: "What to copy, what to rewrite" - which parts of common/ are demo-only
  (per-packet printf, keyboard loop, first-adapter IP guess) versus worth
  keeping.
- New: "Calling BACnetStack_Tick() in a real product" - cadence, and the
  single-threaded contract (the stack contains no locking of any kind;
  callbacks run synchronously on the calling thread).

Verified: SOURCE mode rebuilt + smoke-run (binds, I-Am, RX from a live device);
DLL mode built, run, and both failure paths exercised.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
common/ 1.5.1:
- --help printed the version banner twice (the handler printed it, then
  PrintHelp printed it again). Split the interactive key list into its own
  helper; --help now prints banner / usage / keys once each.
- common/README.md was STALE in the way that matters most: it still said the
  stack "is compiled from source... there is no DLL to load at runtime", and
  its "How main.cpp uses it" skeleton - presented as a starting point to copy -
  omitted LoadBACnetFunctions(), which 1.5.0 had just made mandatory in every
  link mode. Copying it produced exactly the bug 1.5.0 exists to prevent (a
  null-pointer call in DLL mode). This was a regression from this arc's own
  work: CASExampleHelper.h/.cpp were updated and the folder's README was not.

README corrections (all reported by the review panel, each verified first):
- Troubleshooting named a CMake error string that no longer exists - CMake now
  says "CAS BACnet Stack adapter not found under:", so searching the README for
  the real message found nothing. Added the STATIC-mode configure error too.
- A troubleshooting row blamed SO_REUSEADDR for duplicate-device symptoms;
  common/SimpleUDP.cpp deliberately asks for SO_EXCLUSIVEADDRUSE on Windows so
  that case fails loudly at bind instead. Rewritten per-platform.
- New troubleshooting row for the most likely silent failure on a dev laptop:
  the example picks the first non-loopback adapter, which with Hyper-V/WSL/
  VirtualBox/VPN is often not the real NIC, so the device looks healthy and no
  client ever sees it. Says to check the IP in the TX line.
- Expected-output block listed the red Error line before "Device ready"; the
  real order is TX -> ready -> RX -> Error. Corrected, and noted that those
  lines are traffic-dependent.
- Added --parallel to the build instructions (the ~600-file first build is the
  single largest time cost, and matters most when running a class through it).
- Version banner in the sample output refreshed to common/ 1.5.1.

Verified: rebuilt, --help prints one banner, smoke-run on --port 47899 shows
the documented startup sequence with the banner matching the README.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Submodule -> 9f95ff2a (STATIC-mode MSVC runtime fix). STATIC previously
configured but could not link - the prebuilt library is built /MT and consumers
default to /MD, giving 562 LNK2038 errors that read like a corrupt library.

README now documents the ReleaseLib build step, the automatic library lookup
(and CAS_BACNET_STACK_LIB override), and the /MT forcing. The 'all three modes
verified' claim is now actually earned: SOURCE, STATIC and DLL were each built
AND run, with STATIC confirmed to need no DLL beside the executable.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…apshot

A customer opening main.cpp for the first time has no interest in what a
previous version of the file said. Several comments narrated this repo's own
review history at the reader, which undermines confidence in the thing they
are reading rather than building it.

Removed the self-referential framing while keeping every technical claim:
- 'the most important paragraph in the file, because an earlier version of
  this comment got it backwards' -> states the same warning directly.
- 'HONEST NOTE, because an earlier version of this comment was wrong and a
  reader would have found out the hard way' -> 'WORTH KNOWING BEFORE YOU
  COPY THIS'.
- 'This example shipped exactly that bug; it was caught by a reviewer tracing
  the stack source' -> explains the failure is invisible in code review, which
  is the part a reader can act on.
- 'Trust the code, not the comment - including this one: go read it' -> cut;
  a comment telling you not to trust comments is not guidance.
- 'this loop used to hardcode a literal 1' -> says what to do and why, without
  the archaeology.
- 'v6: the old AddNetworkPortObject was removed' -> describes what the current
  arguments mean; migration notes belong in the stack's own changelog.

Comment-only:  shows no non-comment line changed. Rebuilt and
smoke-tested to confirm identical behaviour.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
main.cpp cited stack source files by name (BACnetBusinessLogic.cpp,
BACnetDBDevice.cpp, BACnetDBPropertyProfile.cpp) and internal symbols
(valueShouldBeInitialized, IsPropertyCommandable, IsPropertyEnabled,
GetDefaultPropertyValue) as evidence for its claims. Those are ~600 files of
someone else's code that a first-time reader cannot usefully open, and citing
them invites the reader to go verify rather than to trust and move on.

Every claim is kept, stated as observable behaviour of the API instead:
'the stack substitutes a default for these properties', 'the stack treats
Present_Value as commandable unconditionally on output types', 'the stack
checks whether the property is enabled before reaching the callbacks'. What
the reader can act on is unchanged; the archaeology is gone.

Comment-only:  shows no non-comment line changed. Rebuilt and
smoke-tested.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Release artifacts are built with CAS_BACNET_STACK_LINK=SOURCE, now stated
explicitly rather than relying on it being the CMake default - what we publish
must not change if that default ever moves. Added a step that reads the value
back out of CMakeCache.txt and fails the build if it is not SOURCE.

Why SOURCE for a published binary: the artifact is a single self-contained
executable. STATIC would need a prebuilt library matched here first, and DLL
would require shipping CASBACnetStack_x64_Release.dll alongside and would fail
at start-up for anyone who downloaded only the exe. Those modes are for
integrators choosing them deliberately in their own build.

The cache assertion anchors its grep as '^CAS_BACNET_STACK_LINK:' - without the
colon it also matches the CAS_BACNET_STACK_LINK-STRINGS:INTERNAL helper entry,
and the comparison silently never matches. Verified against a real CMakeCache.txt
both ways before committing.

Also: README version banner said common/ v1.5.0 while the code ships v1.5.1 -
the same doc/code drift the review panel flagged, reintroduced by my own 1.5.1
bump. Fixed. Submodule -> f9e65559 (licence verbiage + debug-limit comment).

Rebuilt and smoke-tested: banner now matches the binary's output.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
PRs #267 and #268 are merged, so the pin moves off the adapter-cpp-package
branch tip and onto 6.x-TestTool, retiring the TEMPORARY note in the CHANGELOG.
Verified the adapter content is byte-identical to the branch-tip pin it
replaces (diff over adapters/cpp + CASBACnetStackDLL.{h,cpp} is empty), so this
is a provenance change, not a code change. Also corrects the common/ version
reference in that entry to 1.5.1.

Rebuilt and smoke-tested on the merged pin.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ssmethurst
ssmethurst merged commit 67c194a into main Aug 1, 2026
3 checks passed
@sws-chipkin
sws-chipkin deleted the llm-auto-2026-july branch October 21, 2026 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants