diff --git a/AGENTS.md b/AGENTS.md index ce0f692..bc838ca 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -75,7 +75,7 @@ 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. +- Device is named "Chipkin Example B-BC"; 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 @@ -90,18 +90,26 @@ Input 1, `s` advance Schedule 1 (Saffron) to a transition right now. against (UTC, via `gmtime`/`gmtime_s`) - not `localtime`/`localtime_s`, which silently blocks `Record_Count` from ever incrementing on any host not in UTC (fixed, [cas-bacnet-stack#2051](https://github.com/chipkin/cas-bacnet-stack/issues/2051)). - Also, `AddTrendLogObject` alone triggers a non-fatal internal log flood + Older stack pins also flooded the log from + `AddTrendLogObject` alone ([#2050](https://github.com/chipkin/cas-bacnet-stack/issues/2050), same - class as B-ACC's #2045 for Event Log) - do not treat flood output as a new - bug without checking #2050/#2045 first. + class as B-ACC's #2045 for Event Log). That's gone on 6.0.22; if it comes + back, check #2050/#2045 before treating it as a new bug. +- **Startup `UUID has not been set` error:** a single + `BACnetDataLinkSC::Loop() ... UUID has not been set` line at startup is a + harmless stack log defect + ([cas-bacnet-stack#2341](https://github.com/chipkin/cas-bacnet-stack/issues/2341)). + This example never uses BACnet/SC; don't set a UUID to silence it. - **SCHED-E-B:** `BACnetStack_AddScheduleObjectPropertyReference` APPENDS every call - pass a `refDeviceInstance` other than this device's own to add a REMOTE target (this starts the stack's Device Address Binding for that - instance). Cross-instance wire testing on one host needs either the same - UDP port shared across processes (impossible - one bind per port) or a - BBMD; two local instances on different ports cannot discover each other by - broadcast. See TODO.md item 3 before assuming a remote-write test failure - is a code bug. + instance). Two local instances on different ports can't discover each + other by broadcast. To wire-test the remote write on one host, run + `tests/sched_e_b_remote_peer.py`: it plays device 389002 and sends a + unicast I-Am so the DAB resolves it. The write skipped at startup, before + the peer is bound, is never re-sent. That's stack gap + [#2343](https://github.com/chipkin/cas-bacnet-stack/issues/2343), not a + code bug. See TODO.md item 2. - Outputs are **commandable**: store the 16-slot `Priority_Array` + `Relinquish_Default` in the app (the `Commandable` struct); let the stack resolve `Present_Value`. Writes land via the `SetProperty*` callbacks (value) @@ -155,7 +163,8 @@ There are no unit tests; verification is behavioural: 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). +Verification is manual (no in-repo test suite ships). `tests/` holds ad hoc +bacpypes3 helpers for checks that need a second device. ## Releasing diff --git a/CHANGELOG.md b/CHANGELOG.md index 5936f31..cd2f2a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,105 @@ 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.0.6] - 2026-09-22 + +### Fixed + +- Trend Log 1 ("Lilac")'s `Record_Count` now climbs as expected + ([#2051](https://github.com/chipkin/cas-bacnet-stack/issues/2051)). The + Start_Time/Stop_Time window passed to `BACnetStack_SetTrendLogStartStopTime` + was built with `localtime_s`/`localtime_r`, but the stack's own "now" (built + from `HelperGetSystemTime()`'s raw `time(0)` and this example's unserved + Device `UTC_Offset`, i.e. 0) is UTC wall-clock - on any host not in UTC, the + window no longer bracketed the clock the stack actually compares against, so + `ReadyToLog` never passed and no records were ever logged. Switched to + `gmtime_s`/`gmtime_r` so the window is built from the same clock the stack + uses. Live-verified with bacpypes3: `Record_Count` climbs continuously + (observed 14 -> 29 -> 44 over 30 seconds). This was a bug in the example, + not the stack, so TODO.md's old item 1 is removed and the remaining items + are renumbered. (merged from #9) + +### Changed + +- Stack issue links now point at open issues. The Calendar `Date_List` gap + moved from the closed cas-bacnet-stack #963 to + [#1758](https://github.com/chipkin/cas-bacnet-stack/issues/1758) in + `main.cpp`'s comments, `README.md` and `docs/objects.json`, and + `docs/PICS.md` was regenerated from it. +- The SCHED-E-B wording in `README.md`, `docs/PICS.md` and + `docs/objects.json` said the remote write was "not wire-verified". It now + says the write is wire-verified and links the startup-write gap + ([cas-bacnet-stack#2343](https://github.com/chipkin/cas-bacnet-stack/issues/2343)). + README's known-gaps summary no longer lists the #2050 log flood, which is + gone on 6.0.22. +- APP_VERSION bumped 1.0.5 -> 1.0.6. + +## [1.0.5] - 2026-09-22 + +### Changed + +- **CAS BACnet Stack moved to 6.0.22** (`6.x` @ `22ac3c98`), from 6.0.21 + (`issues/runbook` @ `a8d3b6bf`). The example is back on the `6.x` branch + that `.gitmodules` names. The early fixes the old pin existed for (#2163, + #2164, #2165) are all on `6.x` now. No `main.cpp` changes were needed. + If you already have a build tree, run `cmake -B build` again before + building. The stack added a new source file, and the adapter's + configure-time glob won't see it otherwise + ([cas-bacnet-stack#2342](https://github.com/chipkin/cas-bacnet-stack/issues/2342)). +- **TODO.md re-verified live on 6.0.22.** The Trend Log 1 `Record_Count` + gap (#2051) still reproduces. The `AddTrendLogObject` log flood (#2050) is + gone. Network Port 1's unreadable `Property_List` entries still reproduce + even though #2196 was closed, and are refiled as + [cas-bacnet-stack#2340](https://github.com/chipkin/cas-bacnet-stack/issues/2340). + New item 8 records the harmless startup BACnet/SC "UUID has not been set" + error + ([cas-bacnet-stack#2341](https://github.com/chipkin/cas-bacnet-stack/issues/2341)). + Every open item now links to its tracking issue in this repo. +- **SCHED-E-B remote fan-out verified on the wire** (#6). The new + `tests/sched_e_b_remote_peer.py` plays peer device 389002 and sends a + unicast I-Am, so the DAB binds it on one host without a BBMD. Schedule 1 + then writes the peer's AO 1 at priority 8, and the peer SimpleACKs. This + found one stack gap: the startup write, skipped while the peer isn't + bound yet, is never re-sent + ([cas-bacnet-stack#2343](https://github.com/chipkin/cas-bacnet-stack/issues/2343)). + TODO.md item 3, TUTORIAL.md and AGENTS.md are updated to match. +- TUTORIAL.md's `DEVICE_NAME` notes now say "Chipkin Example B-BC". The + 1.0.4 rename missed this file. +- APP_VERSION bumped 1.0.4 -> 1.0.5. + +## [1.0.4] - 2026-09-22 + +### Changed + +- **Device renamed from the series' colour placeholder "Rainbow" to "Chipkin + Example B-BC"** so devices from different examples in the series are + distinguishable from each other on the same BACnet network - every example + previously announced the identical Object_Name "Rainbow", which made two + examples on one subnet indistinguishable by name. Sub-object names (Analog + Input 1 "Bronze", etc.) are unchanged - only the Device object's name + changed. `docs/colour-table.md` (series root) updated to match. APP_VERSION + bumped 1.0.3 -> 1.0.4. + +## [1.0.3] - 2026-09-22 + +### Fixed + +- **`Application_Software_Version` (12) and `Firmware_Revision` (44) were + hardcoded and stale** - both served the literal `"1.0.0"` regardless of the + actual build, and `Firmware_Revision` was never meant to be this example's + own version at all; it names the underlying platform. Fixed: + `Application_Software_Version` now reads `APP_VERSION` directly (one + source of truth, can't drift from `--version`'s own banner again). + `Firmware_Revision` is now built at runtime from the CAS BACnet Stack's + own `BACnetStack_GetAPIMajorVersion()`/`GetAPIMinorVersion()`/ + `GetAPIPatchVersion()`/`GetAPIBuildVersion()` (the same 4 calls + `common/CASExampleHelper.cpp`'s `PrintVersion()` already uses for the + startup banner), populated once right after `LoadBACnetFunctions()` + succeeds. Verified with a real ReadProperty against the running device + (`bacpypes3`): `Application_Software_Version = "1.0.3"`, + `Firmware_Revision = "6.0.21.0"` - both now match the actual running build + instead of the stale hardcoded string. + ## [1.0.2] - 2026-09-18 ### Changed @@ -59,20 +158,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 a full XML block instead. See `common/CHANGELOG.md` for the decode details. -### Fixed - -- Trend Log 1 ("Lilac")'s `Record_Count` now climbs as expected - ([#2051](https://github.com/chipkin/cas-bacnet-stack/issues/2051)). The - Start_Time/Stop_Time window passed to `BACnetStack_SetTrendLogStartStopTime` - was built with `localtime_s`/`localtime_r`, but the stack's own "now" (built - from `HelperGetSystemTime()`'s raw `time(0)` and this example's unserved - Device `UTC_Offset`, i.e. 0) is UTC wall-clock - on any host not in UTC, the - window no longer bracketed the clock the stack actually compares against, so - `ReadyToLog` never passed and no records were ever logged. Switched to - `gmtime_s`/`gmtime_r` so the window is built from the same clock the stack - uses. Live-verified with bacpypes3: `Record_Count` climbs continuously - (observed 14 -> 29 -> 44 over 30 seconds). - ### Changed - Restructured documentation to match the series' shared shape: `README.md` diff --git a/README.md b/README.md index 2102150..a922d6a 100644 --- a/README.md +++ b/README.md @@ -18,22 +18,21 @@ and ReadRange). It listens on **BACnet/IP (UDP 47808)** and claims only B-BC. - **[docs/PICS.md](docs/PICS.md)** - the Protocol Implementation Conformance Statement: every object, every property, and who answers it. -> **Versions:** this document describes **example v1.0.2**, built and verified -> against **CAS BACnet Stack 6.0.21** (`issues/runbook` @ `a8d3b6bf`, ahead of `6.x` - see -> `TODO.md` for why), at -> **Protocol_Revision 26**, with the vendored `common/` helper at **v2.8.0**. +> **Versions:** this document describes **example v1.0.6**, built and verified +> against **CAS BACnet Stack 6.0.22** (`6.x` @ `22ac3c98`), at +> **Protocol_Revision 26**, with the vendored `common/` helper at **v3.0.0**. > Running the example prints all three - if what it prints disagrees with this > line, trust the program and check `CHANGELOG.md`. > **B-BC is not fully claimable with the standard stack yet.** This example > implements every B-BC capability the standard CAS BACnet Stack exposes, and > clearly marks what it cannot do - see [TUTORIAL.md](TUTORIAL.md) and -> [TODO.md](TODO.md). In summary: `AddTrendLogObject` causes a non-fatal -> internal log flood -> ([#2050](https://github.com/chipkin/cas-bacnet-stack/issues/2050)); Calendar 1 -> ("Cream")'s `Date_List` cannot be populated (issue #963); and Schedule 1's -> SCHED-E-B remote write is correctly wired but was not wire-verified -> cross-instance in a single-host test topology. +> [TODO.md](TODO.md). In summary: Calendar 1 +> ("Cream")'s `Date_List` cannot be populated +> ([#1758](https://github.com/chipkin/cas-bacnet-stack/issues/1758)). +> Schedule 1's SCHED-E-B remote write is verified on the wire, but the stack +> drops the write it makes at startup, before the remote device has been +> found ([#2343](https://github.com/chipkin/cas-bacnet-stack/issues/2343)). ## What is a B-BC (Building Controller) profile? @@ -50,7 +49,7 @@ deliberately omitted - it is not required at or above Protocol_Revision 13. ## The device this example creates ``` -Device 389005 "Rainbow" (instance configurable with --deviceID) +Device 389005 "Chipkin Example B-BC" (instance configurable with --deviceID) Analog Input 1 "Bronze" (REAL, degrees Celsius; read-only) Binary Input 1 "Emerald" (active / inactive; read-only) Multi-state Input 1 "Hot Pink" (state 1..3; read-only) @@ -84,7 +83,7 @@ Trend Log Multiple 1 "Magenta" (polls Bronze/Diamond/Chartreuse) | AE-ACK-B | Alarm and Event - ACK - B | ✅ | | AE-INFO-B | Alarm and Event - Information - B | ✅ | | AE-CRL-B | Alarm and Event - Recipient List - B | ✅ | -| SCHED-E-B | Scheduling - External - B | ✅ (wiring verified; remote write not cross-instance wire-tested - see [TUTORIAL.md](TUTORIAL.md)) | +| SCHED-E-B | Scheduling - External - B | ✅ (local and remote writes wire-verified; the stack drops the startup write made before the remote device is bound, [#2343](https://github.com/chipkin/cas-bacnet-stack/issues/2343) - see [TUTORIAL.md](TUTORIAL.md)) | | T-VMT-I-B | Trending - Viewing and Modifying Trends - Internal - B | ✅ (Trend Log Multiple; plain Trend Log has a known gap - see [TUTORIAL.md](TUTORIAL.md)) | | T-ATR-B | Trending - Automated Trend Retrieval - B | ✅ (via ReadRange on Trend Log Multiple) | | DM-DDB-A | Device Management - Dynamic Device Binding - A | ✅ | @@ -117,7 +116,7 @@ Trend Log Multiple 1 "Magenta" (polls Bronze/Diamond/Chartreuse) | Object type | Instance | Name | |-------------|:--------:|------| -| Device | 389005 | Rainbow | +| Device | 389005 | Chipkin Example B-BC | | Analog Input | 1 | Bronze | | Binary Input | 1 | Emerald | | Multi-state Input | 1 | Hot Pink | @@ -218,12 +217,12 @@ CMake at it: `cmake -B build -S . -D CAS_STACK_DIR=/path/to/cas-bacnet-stack`. Expected output: ``` -BACnet B-BC (Building Controller) Example - C++ v1.0.0 -CAS BACnet Stack version: 6.0.21.0 -Common helper (common/) version: 2.5.0 +BACnet B-BC (Building Controller) Example - C++ v1.0.6 +CAS BACnet Stack version: 6.0.22.0 +Common helper (common/) version: 3.0.0 FYI: Listening for BACnet/IP on UDP port 47808 (Network Port 1). TX 21 bytes to 192.168.3.255:47808 (broadcast) (Network Port 1) -FYI: Device 389005 ("Rainbow") ready. Vendor ID 389. Press 'h' for help. +FYI: Device 389005 ("Chipkin Example B-BC") ready. Vendor ID 389. Press 'h' for help. ``` The `TX` line is the start-up I-Am the device broadcasts to announce itself, to diff --git a/TODO.md b/TODO.md index 382e4aa..b3c67db 100644 --- a/TODO.md +++ b/TODO.md @@ -1,13 +1,16 @@ # TODO — known gaps (all verified against the pinned stack source and/or the wire, not assumed) -Stack pin: `a8d3b6bfa977f65719f0fe761b6b758acb9f941f` (`issues/runbook`, ahead of `6.x` @ -`986c48a6` — deliberately pinned past the branch `.gitmodules` names to pick up fixes for -[#2163](https://github.com/chipkin/cas-bacnet-stack/issues/2163), -[#2164](https://github.com/chipkin/cas-bacnet-stack/issues/2164) and -[#2165](https://github.com/chipkin/cas-bacnet-stack/issues/2165) before they land on `6.x`; move -back to a `6.x` commit once they do). Reports stack version 6.0.21. +Stack pin: `22ac3c986d3a1c46028527d356ddd80673715bf6` (`6.x`, release 6.0.22, merged 2026-09-22). +The example is back on the `6.x` branch named in `.gitmodules`. The previous pin (`a8d3b6bf` on +`issues/runbook`) was only there to pick up fixes for #2163, #2164 and #2165 early, and those +fixes are now on `6.x`. Every item below was re-checked live against `22ac3c98`. -## Fixed since the last pin (verified live against `a8d3b6bf`, not assumed from the closed issues) +Each open item has a tracking issue in this repo: +[#14](https://github.com/chipkin/BACnetProfileExample-B-BC-CPP/issues/14) (item 3), +[#15](https://github.com/chipkin/BACnetProfileExample-B-BC-CPP/issues/15) (item 6), +[#16](https://github.com/chipkin/BACnetProfileExample-B-BC-CPP/issues/16) (item 7). + +## Fixed on earlier pins (verified live against `a8d3b6bf`, re-checked on `22ac3c98`) - **[#2163](https://github.com/chipkin/cas-bacnet-stack/issues/2163)** (`Device_Address_Binding`'s misleading "not yet implemented" FYI) — gone. `ReadProperty(Device.Device_Address_Binding)` now @@ -21,24 +24,27 @@ back to a `6.x` commit once they do). Reports stack version 6.0.21. re-verified this pass (no easy way to distinguish its absence from "didn't trigger this test"), but the fix landed in the same batch as #2163/#2164 and touches the same call sites documented in that issue. -- **Bonus, not previously tracked here:** the `AddTrendLogObject` log flood (item 2 below, +- **Bonus, not previously tracked here:** the `AddTrendLogObject` log flood (item 1 below, `chipkin/cas-bacnet-stack#2050`) is also gone with this pin — 0 occurrences of "Failed to set the date/time" over a 12-second live run, where the old pin flooded from the very first tick. #2050 itself is still open upstream (likely fixed as a side effect of unrelated work in the same batch - of commits, not by a change that references the issue directly) - see item 2's update below. + of commits, not by a change that references the issue directly) - see item 1's update below. - **[#2178](https://github.com/chipkin/cas-bacnet-stack/issues/2178)** (`Schedule.Weekly_Schedule` and `Network_Port.IP_DNS_Server` both Aborting instead of returning a value/Error) — fixed, - closed. `IP_DNS_Server` no longer Aborts, but now surfaces a narrower gap of its own — see item 7 + closed. `IP_DNS_Server` no longer Aborts, but now surfaces a narrower gap of its own — see item 6 (`chipkin/cas-bacnet-stack#2196`). +- **[#2051](https://github.com/chipkin/cas-bacnet-stack/issues/2051)** (Trend Log 1 "Lilac"'s + `Record_Count` stuck at 0) — **not a stack defect.** The example built the + `SetTrendLogStartStopTime` window from local time, but the stack compares it against UTC, so + off-UTC hosts never logged. Fixed in this repo (`gmtime`, #9). Re-verified on `22ac3c98`. -## 1. `AddTrendLogObject` causes a continuous internal log flood (same class as #2045) — appears fixed as of `a8d3b6bf` +## 1. `AddTrendLogObject` causes a continuous internal log flood (same class as #2045) — fixed (regression note only) -**Update:** 0 occurrences of the flood over a 12-second live run against the current pin -(`a8d3b6bf`), where the previously pinned commit flooded from the very first `BACnetStack_Tick()`. -The issue below is still marked open upstream — likely fixed incidentally by unrelated work in the -same commit range rather than a change that names #2050 directly — so this is left filed rather -than closed from this side. Original report kept below for the reproduction steps, in case this -regresses on a future pin bump. +**Fixed.** 0 occurrences of the flood over a ~30-second live run against `22ac3c98` (6.0.22). It +was already gone on `a8d3b6bf`. #2050 is still open upstream (see the re-verification comment +there) because no single commit names it. Tracked to closure by +[#13](https://github.com/chipkin/BACnetProfileExample-B-BC-CPP/issues/13). The original report is +kept below in case it regresses on a future pin. Calling `BACnetStack_AddTrendLogObject` — by itself, independent of `SetTrendLogTypeToPolled`, `SetTrendLogStartStopTime`, or Trend Log Multiple — makes every `BACnetStack_Tick()` print: @@ -61,24 +67,33 @@ looks like noisy internal logging rather than a functional break, matching #2045 **Filed:** [chipkin/cas-bacnet-stack#2050](https://github.com/chipkin/cas-bacnet-stack/issues/2050). -## 2. SCHED-E-B remote fan-out — wired correctly, cross-instance wire test not possible on one host without BBMD - -Schedule 1 ("Saffron")'s `List_Of_Object_Property_References` has two entries: -`BACnetStack_AddScheduleObjectPropertyReference` is called once with `refDeviceInstance = -g_deviceInstance` (local, Chartreuse) and once with `refDeviceInstance = REMOTE_DEVICE_INSTANCE` -(389002, a peer's Analog Output 1) — each call APPENDS per the stack header's own doc comment, so -Saffron fans every transition out to both. The local reference's mechanism is proven (Schedule's -existing SCHED-I-B write to Chartreuse, inherited from B-AAC, works). The remote reference is -correct, documented API usage (`refDeviceInstance` other than the owning device is explicitly the -documented way to name a remote target, and the header states it starts the stack's own Device -Address Binding for that instance) but was **not** wire-verified end-to-end this session: this -example and a peer instance (`BACnetProfileExample-B-SA-CPP`) were each run on a different UDP -port on the same host to avoid a bind conflict (two processes cannot share one port), which means -their broadcast Who-Is/I-Am traffic does not reach each other (BACnet/IP broadcast is scoped to -the port it is sent to) — so Device Address Binding cannot resolve the peer in this topology. -Verifying this for real needs either two separate hosts (or containers/VMs) sharing port 47808, or -a BBMD relaying between the two ports — both out of scope for this session's time. Not a defect; -a test-topology limitation, recorded honestly rather than claimed as verified. +## 2. SCHED-E-B remote fan-out — wire-verified; the startup write is dropped before binding + +**Verified on the wire against `22ac3c98` (6.0.22)** — closes +[#6](https://github.com/chipkin/BACnetProfileExample-B-BC-CPP/issues/6). + +Schedule 1 ("Saffron")'s `List_Of_Object_Property_References` has two entries, a local one +(Chartreuse) and a remote one (`REMOTE_DEVICE_INSTANCE` 389002, Analog Output 1). Earlier sessions +couldn't wire-test the remote entry on one host: two instances on different UDP ports never see +each other's broadcast Who-Is/I-Am. `tests/sched_e_b_remote_peer.py` gets around that. It plays +device 389002 (bacpypes3, commandable AO 1, its own port) and sends B-BC a **unicast** I-Am, which +the stack's DAB accepts. It then writes Schedule 1's `Schedule_Default` to force a re-evaluation. +Result, from B-BC's own TX/RX log and the peer's state: + +``` +RX ... from 127.0.0.1:47902 - ConfirmedRequest: WriteProperty Schedule 1.Schedule_Default +WriteProperty: Analog Output 1 (Chartreuse) <- 42.50 @ priority 8 +TX 26 bytes to 127.0.0.1:47902 - ConfirmedRequest: WriteProperty Analog_Output 1.Present_Value +RX 9 bytes from 127.0.0.1:47902 - SimpleACK: WriteProperty +peer AO1 Priority_Array: [(8, 42.5)] -> RESULT: PASS +``` + +**Remaining stack gap:** the Schedule's first evaluation at startup happens before 389002 is +bound. The stack logs `SendExternalWriteProperty: device instance=[389002] not resolved in DAB - +skipping the external write`, starts the Who-Is only after that, and never re-sends the skipped +value once the I-Am arrives. The remote target only catches up at the next `Present_Value` change. +**Filed:** [chipkin/cas-bacnet-stack#2343](https://github.com/chipkin/cas-bacnet-stack/issues/2343). +Nothing to change on this side. This example's wiring is correct. ## 3. Calendar 1 ("Cream")'s `Date_List` — inherited, pre-existing gap @@ -113,7 +128,9 @@ Split from [#2178](https://github.com/chipkin/cas-bacnet-stack/issues/2178) (tha Abort-PDU bugs — `Schedule.Weekly_Schedule` and `Network_Port.IP_DNS_Server` both aborting — are fixed; re-verified live against this repo's current pin). What's left, filed as [chipkin/cas-bacnet-stack#2196](https://github.com/chipkin/cas-bacnet-stack/issues/2196) and -re-confirmed against `a8d3b6bf`: +re-confirmed against `a8d3b6bf`. **#2196 was then closed upstream, but both symptoms still +reproduce unchanged on `22ac3c98` (6.0.22)** — refiled as +[chipkin/cas-bacnet-stack#2340](https://github.com/chipkin/cas-bacnet-stack/issues/2340): | Property | ID | Read returns | |---|---:|---| @@ -124,3 +141,21 @@ Both are `Property_List`-generated by the stack (not app-controlled — this exa or serves either), so there's nothing to change on this side. `FD_Bbmd_Address` (418) returning `Error (property, value-not-initialized)` is NOT part of this gap — that's the correct answer for a device with no BBMD configured. + +## 7. A BACnet/SC "UUID has not been set" error is logged at startup + +Every start prints this line once, even though this example is BACnet/IP-only and never touches the +BACnet/SC API: + +``` +::CASBACnetStack::BACnetDataLinkSC::Loop() ... Error: UUID has not been set. A UUID must be set for the BACnetSC device to start. +``` + +`BACnetDataLinkLayer::Loop()` ticks SC data-link instance 0 whenever the stack is compiled with +`STACK_OPTION_DATA_LINK_LAYER_SC`, whether or not the application configured SC. The error latches +after one line and BACnet/IP keeps working normally (verified live on `22ac3c98`). It's harmless +noise in the same class as #2050. Don't set a Device UUID just to silence it: this example has no +SC port, and setting one would only move SC further through its startup checks. + +**Filed:** [chipkin/cas-bacnet-stack#2341](https://github.com/chipkin/cas-bacnet-stack/issues/2341). +Tracked here as [#16](https://github.com/chipkin/BACnetProfileExample-B-BC-CPP/issues/16). diff --git a/TUTORIAL.md b/TUTORIAL.md index d95c470..1c03722 100644 --- a/TUTORIAL.md +++ b/TUTORIAL.md @@ -31,11 +31,11 @@ per-field note on each saying what to change it to. That block is the authoritative checklist; it is in the source rather than here so it cannot be skipped by someone who only reads the code. -**THIS IS THE ONE THAT WILL BITE YOU.** `DEVICE_NAME` ("Rainbow") is a +**THIS IS THE ONE THAT WILL BITE YOU.** `DEVICE_NAME` ("Chipkin Example B-BC") is a **compile-time constant**, but `Object_Name` must be unique across the whole BACnet internetwork. The device instance is runtime-configurable with `--deviceID`, so it is easy to ship two units, configure their instances -correctly, and still have both announce `Object_Name` `"Rainbow"` - a spec +correctly, and still have both announce `Object_Name` `"Chipkin Example B-BC"` - a spec violation and a hard BTL failure. In a real product `Object_Name` must be per-unit configurable too: derive it from a serial number, DIP switches, a config file, or add a `--deviceName` argument. @@ -189,22 +189,26 @@ with reproduction steps. same class of defect as `AddEventLogObject`'s [#2045](https://github.com/chipkin/cas-bacnet-stack/issues/2045). Filed as [#2050](https://github.com/chipkin/cas-bacnet-stack/issues/2050). -2. **Schedule 1's SCHED-E-B remote write is wired correctly but not - cross-instance wire-verified.** `List_Of_Object_Property_References` has - two entries - each `AddScheduleObjectPropertyReference` call APPENDS - a - local one at Chartreuse and a remote one at a peer device's Analog Output 1 - (default instance 389002). The remote reference's mechanism (a - `refDeviceInstance` other than this device's own, which starts the stack's - Device Address Binding for that instance) is correct, documented API - usage. It was **not** wire-verified end-to-end: two example instances on - one host had to run on different UDP ports to avoid a bind conflict, and - BACnet/IP broadcast Who-Is/I-Am does not cross ports, so Device Address - Binding cannot resolve the peer in that topology. Verifying this for real - needs two hosts (or containers/VMs) sharing port 47808, or a BBMD relaying - between the two ports. + **Fixed on the current pin (6.0.22):** no flood in a live run. Kept here in + case it comes back on a future pin. +2. **Schedule 1's SCHED-E-B remote write works, but the first write can be + lost at startup.** `List_Of_Object_Property_References` has two entries, + because each `AddScheduleObjectPropertyReference` call APPENDS: a local one + at Chartreuse and a remote one at a peer device's Analog Output 1 (default + instance 389002). Verified on the wire on 6.0.22 with + `tests/sched_e_b_remote_peer.py`. The peer sends B-BC a unicast I-Am, so + Device Address Binding resolves it without a BBMD, even with both on one + host on different ports. It then changes Schedule 1's `Schedule_Default`, + and B-BC sends `WriteProperty Analog_Output 1.Present_Value` @ priority 8 + to the peer, which SimpleACKs. **Stack gap:** the very first evaluation at + startup runs before the peer is bound, so the stack logs *"not resolved in + DAB - skipping the external write"* and never re-sends that value once the + peer binds + ([#2343](https://github.com/chipkin/cas-bacnet-stack/issues/2343)). The + remote target catches up at the Schedule's next `Present_Value` change. 3. **Calendar 1 ("Cream")'s `Date_List` cannot be populated.** There is no customer-facing export or callback to populate a Calendar object's - `Date_List` (cas-bacnet-stack issue #963) - inherited from every prior + `Date_List` (cas-bacnet-stack issue #1758) - inherited from every prior example in the series that carries a Calendar. Schedule 1's one-off exception uses an inline calendar-date entry (`AddScheduleExceptionEventWithCalendarEntry`) instead of a reference to @@ -266,10 +270,10 @@ in `accepted`, comes out as a ⚠ row - that is a defect, not a feature. | Symptom | Cause / fix | |---------|-------------| -| On start-up the app prints a wall of red `Error:` lines but the device works | **Expected — mostly not your bug.** Three benign sources: (1) the device receives its **own** broadcast I-Am and logs a decode cascade - any BACnet/IP device that listens for broadcasts hears itself; (2) a one-time *"UUID has not been set..."* BACnet/SC notice, since these IP-only examples never configure that datalink; (3) once trending starts, a **continuous** `BACnetDateTime::operator =()` flood from `AddTrendLogObject` alone - [#2050](https://github.com/chipkin/cas-bacnet-stack/issues/2050), non-fatal, does not stop the device working. | +| On start-up the app prints a wall of red `Error:` lines but the device works | **Expected — mostly not your bug.** Three benign sources: (1) the device receives its **own** broadcast I-Am and logs a decode cascade - any BACnet/IP device that listens for broadcasts hears itself; (2) a one-time *"UUID has not been set..."* BACnet/SC notice, since these IP-only examples never configure that datalink - [#2341](https://github.com/chipkin/cas-bacnet-stack/issues/2341); (3) on stack pins older than 6.0.22 only, a **continuous** `BACnetDateTime::operator =()` flood from `AddTrendLogObject` alone - [#2050](https://github.com/chipkin/cas-bacnet-stack/issues/2050), non-fatal, does not stop the device working. | | A ReadProperty of `Log_Buffer` on either Trend Log returns `Error(OBJECT, READ_ACCESS_DENIED)` | **Expected — this property is ReadRange-only.** Use ReadRange (`RangeByPosition`), not ReadProperty. | -| Schedule 1's remote (SCHED-E-B) write never reaches the peer | Either no peer is running at `REMOTE_DEVICE_INSTANCE` (389002 by default), or the peer is on a different UDP port on the same host - broadcast Who-Is/I-Am does not cross ports, so Device Address Binding cannot resolve it. See [Known gaps item 2](#known-gaps-in-this-example). | -| Calendar 1 ("Cream")'s `Date_List` reads back empty and `Present_Value` is always `false` | **Expected — inherited stack gap #963.** See [Known gaps item 3](#known-gaps-in-this-example). | +| Schedule 1's remote (SCHED-E-B) write never reaches the peer | Either no peer is running at `REMOTE_DEVICE_INSTANCE` (389002 by default), or the peer is on a different UDP port on the same host - broadcast Who-Is/I-Am does not cross ports, so Device Address Binding cannot resolve it (`tests/sched_e_b_remote_peer.py` works around this with a unicast I-Am). Even when bound, the write made at startup, before binding, is dropped and never re-sent ([#2343](https://github.com/chipkin/cas-bacnet-stack/issues/2343)). See [Known gaps item 2](#known-gaps-in-this-example). | +| Calendar 1 ("Cream")'s `Date_List` reads back empty and `Present_Value` is always `false` | **Expected — inherited stack gap [#1758](https://github.com/chipkin/cas-bacnet-stack/issues/1758).** See [Known gaps item 3](#known-gaps-in-this-example). | | An optional property you added a callback branch for reads back `Error: unknown-property` | You served it in a `GetProperty*` callback but never called `BACnetStack_SetPropertyEnabled` for it. The stack checks whether a property is enabled *before* calling your callback. This example shipped exactly this bug for the Device's `Description` - see [Adding an object](#adding-an-object-read-this-before-you-copy-any-pattern-in-this-file). | | CMake error: *"CAS BACnet Stack adapter not found under: ..."* | Submodules not initialized. Run `git submodule update --init --recursive` (or pass `-D CAS_STACK_DIR=...`). | | `CASBACnetStackDLL.h: No such file or directory` | Same - submodules not checked out. | diff --git a/common/CASExampleHelper.cpp b/common/CASExampleHelper.cpp index 23043de..e1da0c3 100644 --- a/common/CASExampleHelper.cpp +++ b/common/CASExampleHelper.cpp @@ -1822,7 +1822,8 @@ void PrintHelp(const char* appName, const char* appVersion) { PrintInteractiveCommands(); } -bool HandleHelpAndVersionArgs(const int argc, char** argv, const char* appName, const char* appVersion) { +bool HandleHelpAndVersionArgs(const int argc, char** argv, const char* appName, const char* appVersion, + const bool showDccPasswordCliOption) { for (int i = 1; i < argc; ++i) { if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "/?") == 0) { @@ -1839,6 +1840,13 @@ bool HandleHelpAndVersionArgs(const int argc, char** argv, const char* appName, printf(" --port BACnet/IP UDP port (1..65535). Default 47808 (0xBAC0).\n"); printf(" Use a non-default port to avoid clashing with another\n"); printf(" BACnet device already on 47808 on this host.\n"); + if (showDccPasswordCliOption) { + printf(" --dcc-password \n"); + printf(" DeviceCommunicationControl password. Default \"\" (no\n"); + printf(" password required). Set to require a matching password on\n"); + printf(" DeviceCommunicationControl requests - see this example's own\n"); + printf(" DeviceCommunicationControl callback for how it is checked.\n"); + } printf(" --xml Print every RX/TX BACnet message as an indented XML\n"); printf(" block instead of a one-line summary. Off by default -\n"); printf(" very verbose, meant for deep protocol debugging.\n"); @@ -1854,6 +1862,15 @@ bool HandleHelpAndVersionArgs(const int argc, char** argv, const char* appName, return false; } +const char* ParseDccPasswordArg(const int argc, char** argv, const char* defaultPassword) { + for (int i = 1; i + 1 < argc; ++i) { + if (strcmp(argv[i], "--dcc-password") == 0) { + return argv[i + 1]; // argv's own storage outlives main() - safe to return directly + } + } + return defaultPassword; +} + // Parse a whole-number argument value. Returns true only if the ENTIRE token is // a valid non-negative integer. This exists because atoi()/atol() silently // return 0 on garbage - so `--deviceID abc` would parse as device 0, a valid @@ -2018,6 +2035,7 @@ KeyCommand PollKey() { if (c == 'w' || c == 'W') return KeyCommand::WriteGroupDemo; if (c == 'd' || c == 'D') return KeyCommand::DiscoverRemote; if (c == 'r' || c == 'R') return KeyCommand::RouterAnnounce; + if (c == 'm' || c == 'M') return KeyCommand::Metrics; return KeyCommand::None; #else EnableRawInput(); @@ -2037,6 +2055,7 @@ KeyCommand PollKey() { if (buf[0] == 'w' || buf[0] == 'W') return KeyCommand::WriteGroupDemo; if (buf[0] == 'd' || buf[0] == 'D') return KeyCommand::DiscoverRemote; if (buf[0] == 'r' || buf[0] == 'R') return KeyCommand::RouterAnnounce; + if (buf[0] == 'm' || buf[0] == 'M') return KeyCommand::Metrics; return KeyCommand::None; #endif } diff --git a/common/CASExampleHelper.h b/common/CASExampleHelper.h index 2d39d5e..b84f804 100644 --- a/common/CASExampleHelper.h +++ b/common/CASExampleHelper.h @@ -41,7 +41,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 = "2.9.0"; +static const char* COMMON_VERSION = "3.0.0"; // Print the example's name + version, the linked CAS BACnet Stack version, // and the common/ helper version. @@ -62,7 +62,20 @@ void PrintHelp(const char* appName, const char* appVersion); // Returns true if it printed something and the caller should exit(0); false to // carry on starting up. Every example in the series supports --help/--version, // so this lives here rather than in each main.cpp. -bool HandleHelpAndVersionArgs(int argc, char** argv, const char* appName, const char* appVersion); +// +// showDccPasswordCliOption (added common/ 2.7.0, default true so every +// EXISTING call site - one positional argument short - keeps printing the +// "--dcc-password " line exactly as before): pass false when an +// example does NOT accept --dcc-password on the command line (e.g. +// BACnetProfileExample-B-SCHUB-CPP as of its 2026-09 secrets-handling pass, +// which accepts the DCC password only via its --config file - see that +// repo's README.md "Configuration file" section for why: a CLI argument is +// visible in process listings/shell history). This is a non-breaking, +// default-valued addition - it does not remove ParseDccPasswordArg() (still +// here, still usable by any example that still wants --dcc-password) or +// change any existing 4-argument call site's behaviour. +bool HandleHelpAndVersionArgs(int argc, char** argv, const char* appName, const char* appVersion, + bool showDccPasswordCliOption = true); // Return the UDP port to use: the value after "--port" if present, else // defaultPort. Common to every example. @@ -73,6 +86,17 @@ uint16_t ParsePortArg(int argc, char** argv, uint16_t defaultPort); // Common to every example. uint32_t ParseDeviceIdArg(int argc, char** argv, uint32_t defaultDeviceId); +// Return the DeviceCommunicationControl (and ReinitializeDevice) password to +// require: the value after "--dcc-password" if present, else defaultPassword. +// Returns a pointer into argv (the "--dcc-password" case) or defaultPassword +// itself (the not-given case) - same "caller does not own the returned +// storage" contract an example already relies on for its own DCC_PASSWORD +// constant; NOT a callback-owned buffer, so do not free() or modify it. +// defaultPassword is conventionally "" (no password required, today's +// behaviour for every example that does not opt in) - see main.cpp's +// DeviceCommunicationControl callback for how the result is used. +const char* ParseDccPasswordArg(int argc, char** argv, const char* defaultPassword); + // --- Networking ------------------------------------------------------------ // Bind the UDP socket used by the CURRENT Network Port instance (the one last // named by SetNetworkPortInstance(), or instance 1 if that was never called - @@ -260,9 +284,16 @@ enum class KeyCommand { // triggers it normally DiscoverRemote, // 'd' - send a demo SendWhoIs to discover a remote device // this example writes to or reads from - RouterAnnounce // 'r' - manually (re-)send I-Am-Router-To-Network now, instead + RouterAnnounce, // 'r' - manually (re-)send I-Am-Router-To-Network now, instead // of waiting for the one sent at start-up, so routing // can be demonstrated on demand + Metrics // 'm' - print a health/metrics snapshot (uptime, connection + // counts, rate-limit rejections, RX/TX counters, etc.) + // to stdout. Added in common/ 2.7.0 for + // BACnetProfileExample-B-SCHUB-CPP's health/metrics + // keypress (Task 2); generic (not BACnet/SC-specific) + // so any example that later tracks its own + // connections/throughput can reuse it the same way. }; // Non-blocking: returns a pending key command, or None if nothing was pressed. diff --git a/common/CASExampleLog.cpp b/common/CASExampleLog.cpp new file mode 100644 index 0000000..864e017 --- /dev/null +++ b/common/CASExampleLog.cpp @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: CC0-1.0 +// Public-domain example code (CC0) - see ../LICENSE. +// CASExampleLog.cpp +// ============================================================================= +// Implementation of the shared example logging facility. See CASExampleLog.h. +// ============================================================================= + +#include "CASExampleLog.h" + +#include +#include +#include + +namespace { + +// Defaults to Info: Debug output is suppressed until an example explicitly +// calls CASExampleHelper::SetLogLevel(LogLevel::Debug) - see the header. +CASExampleHelper::LogLevel g_logLevel = CASExampleHelper::LogLevel::Info; + +const char* LevelName(const CASExampleHelper::LogLevel level) { + switch (level) { + case CASExampleHelper::LogLevel::Debug: return "DEBUG"; + case CASExampleHelper::LogLevel::Info: return "INFO"; + case CASExampleHelper::LogLevel::Warning: return "WARNING"; + case CASExampleHelper::LogLevel::Error: return "ERROR"; + default: return "UNKNOWN"; + } +} + +// A message this long already indicates something has gone wrong at the call +// site; vsnprintf still null-terminates and truncates cleanly within this, no +// heap allocation needed (same "small fixed buffer, no allocation" style as +// CASExampleHelper.cpp's own g_udpBindings table). +const size_t MAX_LOG_MESSAGE_LENGTH = 1024; + +} // namespace + +namespace CASExampleHelper { + +void SetLogLevel(const LogLevel level) { + g_logLevel = level; +} + +LogLevel GetLogLevel() { + return g_logLevel; +} + +void Log(const LogLevel level, const char* fmt, ...) { + if (static_cast(level) < static_cast(g_logLevel)) { + return; // below the current minimum - do not even format the message + } + + // UTC timestamp (YYYY-MM-DD HH:MM:SS), the same gmtime_s/gmtime_r pattern + // main.cpp already uses for the File objects' Modification_Date - UTC + // rather than localtime() so a log line means the same wall-clock instant + // regardless of the host's configured timezone (see main.cpp's + // GetPropertyDate/GetPropertyTime for the identical rationale). + const time_t now = time(NULL); + struct tm utc; +#if defined(_WIN32) + gmtime_s(&utc, &now); +#else + gmtime_r(&now, &utc); +#endif + char timestamp[32]; + snprintf(timestamp, sizeof(timestamp), "%04d-%02d-%02d %02d:%02d:%02d", + utc.tm_year + 1900, utc.tm_mon + 1, utc.tm_mday, + utc.tm_hour, utc.tm_min, utc.tm_sec); + + char message[MAX_LOG_MESSAGE_LENGTH]; + va_list args; + va_start(args, fmt); + vsnprintf(message, sizeof(message), fmt, args); + va_end(args); + + // Debug/Info -> stdout, Warning/Error -> stderr - see Log()'s own doc + // comment in CASExampleLog.h for why. + FILE* const stream = (level == LogLevel::Warning || level == LogLevel::Error) ? stderr : stdout; + fprintf(stream, "%s [%s] %s\n", timestamp, LevelName(level), message); +} + +} // namespace CASExampleHelper diff --git a/common/CASExampleLog.h b/common/CASExampleLog.h new file mode 100644 index 0000000..6112b03 --- /dev/null +++ b/common/CASExampleLog.h @@ -0,0 +1,75 @@ +// SPDX-License-Identifier: CC0-1.0 +// Public-domain example code (CC0) - see ../LICENSE. +#ifndef CAS_EXAMPLE_LOG_H +#define CAS_EXAMPLE_LOG_H + +// CASExampleLog.h +// ============================================================================= +// A minimal, dependency-free structured logging facility for the example +// series, added in common/ 2.6.0. +// +// Every example today (this repo included) logs via bare printf()/ +// fprintf(stderr, ...) calls scattered through main.cpp and its own transport +// code - no levels, no timestamps, and no way to turn the noise up or down. +// This is a drop-in REPLACEMENT for that pattern, not a new subsystem: +// +// * No external logging library - just //, the same +// headers CASExampleHelper.cpp already includes. +// * No file output or log rotation - out of scope for this pass. Output +// still goes to stdout/stderr, exactly like the printf/fprintf calls it +// replaces (see Log()'s own comment below for which stream each level +// uses and why). +// * Printf-style formatting (const char* fmt, ...), so converting an +// existing call site is a small, mechanical edit: +// +// printf("Warning: ignoring invalid --port \"%s\"\n", argv[i + 1]); +// // becomes: +// CASExampleHelper::Log(CASExampleHelper::LogLevel::Warning, +// "ignoring invalid --port \"%s\"", argv[i + 1]); +// +// This commit adds the facility itself, working and proven to compile, plus a +// FEW demonstrative call sites in main.cpp (see that file). It deliberately +// does NOT sweep every existing printf/fprintf call in this series over to +// it - that is a large, separate, mechanical change with real regression risk +// (this repo's RX/TX log line format, startup banner, etc. are matched +// byte-for-byte by scripts in tests/sc/) - see common/CHANGELOG.md's 2.6.0 +// entry. Any later example in the series can adopt it the same way this one +// did: a #include and a handful of converted call sites, at its own pace. +// ============================================================================= + +namespace CASExampleHelper { + +// Severity, lowest to highest. Debug is for verbose diagnostic output (e.g. +// the rate-limiting/audit-trail work planned for this repo) that must stay +// silent during normal operation unless explicitly turned on - see +// SetLogLevel below. +enum class LogLevel { + Debug, + Info, + Warning, + Error +}; + +// The minimum level that actually gets printed; anything below it is +// suppressed before any formatting or I/O happens. Defaults to Info, so +// Debug output stays off unless an example opts in with +// SetLogLevel(LogLevel::Debug) - typically from its own --verbose/--debug +// command-line flag. +void SetLogLevel(LogLevel level); +LogLevel GetLogLevel(); + +// Print one log line - " [] \n" - if level is +// at or above the current minimum (GetLogLevel()); otherwise this is a no-op +// (the message is not even formatted). Printf-style formatting: fmt and the +// varargs after it are passed straight to vsnprintf, same rules as printf. +// +// Debug/Info go to stdout, Warning/Error go to stderr - the same split +// sc_transport/ScTransport.cpp and ScTransportRouter.cpp already use for +// their own printf (FYI/status) vs fprintf(stderr, ...) (problem) calls; +// common/'s OWN printf calls (e.g. ParsePortArg's "Warning: ..." lines) predate +// this facility and are unchanged by it - see common/CHANGELOG.md. +void Log(LogLevel level, const char* fmt, ...); + +} // namespace CASExampleHelper + +#endif // CAS_EXAMPLE_LOG_H diff --git a/common/CHANGELOG.md b/common/CHANGELOG.md index 24fbcbd..bd644c3 100644 --- a/common/CHANGELOG.md +++ b/common/CHANGELOG.md @@ -12,7 +12,140 @@ 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.9.0] - 2026-09-17 +## [3.0.0] - 2026-09-22 + +### Added + +- **Reconciled two `common/` lines that had independently diverged from + 2.5.0 and both reused version numbers for different content**: + `BACnetProfileExample-B-BC-CPP` had carried its own 2.6.0-2.9.0 (RX/TX + service decode, object/property-naming `SummarizeBacnetFrame()`, the + `--xml` frame dump, `GetLocalLinkSpeedBitsPerSecond()`, and the Device + `Local_Date`/`Local_Time` property IDs) without those changes being + re-copied series-wide, while `BACnetProfileExample-B-SCHUB-CPP` separately + carried its own, differently-numbered 2.6.0-2.7.0 (the `CASExampleLog` + structured-logging facility, `ParseDccPasswordArg()`, the + `HandleHelpAndVersionArgs()` `showDccPasswordCliOption` parameter, and + `KeyCommand::Metrics`). The two lines touch disjoint code (confirmed by + diffing each against the shared 2.5.0 ancestor) and merge cleanly with no + functional conflicts. This version combines both: every symbol and file + from both lines is present, `COMMON_VERSION` moves to `3.0.0` (a new major + number precisely because this single version now carries two + independently-versioned change sets, not because anything is + backward-incompatible), and this is the version every example in the + series is re-synced to. + +## [2.7.0] - 2026-09-21 (from the BACnetProfileExample-B-SCHUB-CPP line, merged in 3.0.0) + +### Added + +- **`KeyCommand::Metrics` ('m'/'M')** - a generic "print a health/metrics + snapshot" interactive key command, added for + `BACnetProfileExample-B-SCHUB-CPP`'s health/metrics keypress (this batch's + Task 2: uptime, connection counts, rate-limit rejections, RX/TX counters). + `'h'`/`'q'`/arrows/`'s'`/`'w'`/`'d'`/`'r'` were already taken (see + `KeyCommand`'s own comment), so this is a new enum value, not a repurposed + one. `PollKey()` (both the Windows `_kbhit`/`_getch` branch and the POSIX + raw-input branch) now recognises `'m'`/`'M'` and returns it. This is a + purely additive, backward-compatible enum/switch change - existing + `switch (PollKey())` call sites elsewhere in the series that do not handle + `Metrics` are unaffected (an unhandled `default:`/no `case` simply does + nothing, same as any other key this repo's own `main.cpp` chooses not to + act on). Kept generic (not BACnet/SC-specific) so any other example that + later tracks its own connection/throughput counters can reuse the same key + rather than main.cpp inventing a parallel one. + +### Changed + +- **`HandleHelpAndVersionArgs()` gains an optional 5th parameter, + `showDccPasswordCliOption` (default `true`).** Added so + `BACnetProfileExample-B-SCHUB-CPP` can stop advertising `--dcc-password` in + its own `--help` output (this batch's Task 1: the CLI form of + `--dcc-password` was removed from that repo - config-file only now, since a + CLI argument is visible in process listings/shell history) without + affecting any other example's `--help` output. This is a **non-breaking** + change: every existing 4-argument call site (`HandleHelpAndVersionArgs(argc, + argv, APP_NAME, APP_VERSION)`) keeps compiling and keeps printing the + `--dcc-password` line exactly as before, because the new parameter defaults + to `true`. `ParseDccPasswordArg()` itself is UNCHANGED and NOT removed - + see that function's own entry in the 2.6.0 section below; any example + (including this one, previously) can still call it directly for a CLI + `--dcc-password` flag if it wants one. Evaluated and rejected: removing + `ParseDccPasswordArg()` outright, since (a) it was only added in 2.6.0 (this + same day) with no evidence any other example in the series has adopted it + yet, but (b) removing a just-published shared function the moment after + publishing it, rather than simply not using it in this one repo, is more + invasive than the problem calls for - see + `BACnetProfileExample-B-SCHUB-CPP`'s own `CHANGELOG.md` for the full + reasoning. + +## [2.6.0] - 2026-09-21 (from the BACnetProfileExample-B-SCHUB-CPP line, merged in 3.0.0) + +### Added + +- **`CASExampleLog.h` / `CASExampleLog.cpp` - a minimal, dependency-free + structured logging facility.** Every example in the series (this repo + included) has always logged via bare `printf()`/`fprintf(stderr, ...)` + calls scattered through `main.cpp` and its own transport code - no levels, + no timestamps, no way to turn the noise up or down. `CASExampleHelper::Log()` + is a drop-in replacement for that pattern, not a new subsystem: no external + logging library (just ``/``/``, already pulled in + elsewhere in `common/`), no file output or rotation (explicitly out of + scope for this pass), still stdout/stderr underneath. `LogLevel` - + `Debug`/`Info`/`Warning`/`Error` - matches the naming already used for + `CASExampleHelper::RestartKind`/`KeyCommand` in this same namespace. + `SetLogLevel()`/`GetLogLevel()` give a runtime-configurable minimum + (default `Info`, so `Debug` stays silent unless an example opts in) - this + is what the rate-limiting/audit-trail work planned for + `BACnetProfileExample-B-SCHUB-CPP` will use for verbose diagnostics without + spamming normal operation. `Log(level, fmt, ...)` is printf-style + (`const char* fmt, ...`) specifically to keep call-site conversions small: + an existing `printf("Warning: ...", x)` becomes + `CASExampleHelper::Log(CASExampleHelper::LogLevel::Warning, "...", x)` and + nothing else changes. Each line is ` [] `; + the timestamp uses the same `gmtime_s`/`gmtime_r` pattern + `BACnetProfileExample-B-SCHUB-CPP`'s own `main.cpp` already uses for its + File objects' `Modification_Date` (UTC, not `localtime()`, so a line means + the same instant regardless of the host's configured timezone). `Debug`/ + `Info` go to stdout, `Warning`/`Error` go to stderr, matching the split + `sc_transport/ScTransport.cpp`/`ScTransportRouter.cpp` already use for their + own `printf` (FYI/status) vs `fprintf(stderr, ...)` (problem) calls. + First consumer: `BACnetProfileExample-B-SCHUB-CPP`, which converts 3 + `main.cpp` call sites (the DeviceCommunicationControl password-failure + rejection, the "could not read a local IPv4 address" fallback, and the + BACnet/SC hub accept-URI failure) as a proof it compiles and works. This is + deliberately NOT a sweep of every `printf`/`fprintf` call in that repo - + that is a large, separate, mechanical change with real regression risk + (its RX/TX log line format, startup banner, etc. are read, though not + matched verbatim, by `tests/sc/*.py`) - left for a later, dedicated pass. + Any other example in the series can adopt the facility the same way, at its + own pace: a `#include "CASExampleLog.h"` and converting call sites as it + goes. +- **`ParseDccPasswordArg()` - `--dcc-password ` as a shared CLI + argument.** Every example that implements DM-DCC-B has, until now, hardcoded + its DeviceCommunicationControl password at compile time (e.g. + `BACnetProfileExample-B-SCHUB-CPP`'s `main.cpp` had + `static const char* DCC_PASSWORD = "";`) - there was no way to set or test a + non-empty password without rebuilding. `ParseDccPasswordArg(argc, argv, + defaultPassword)` follows the exact same shape as `ParsePortArg`/ + `ParseDeviceIdArg`: scan `argv` for the flag, return the following token if + present, else `defaultPassword`. It differs from those two only in return + type - `const char*` into `argv`'s own storage, not a parsed numeric value - + because a password is carried through verbatim, not converted; `argv` + outlives `main()`, so returning a pointer into it is safe, and the contract + matches an example's own (now non-`static const`) `DCC_PASSWORD`-equivalent + global. Default `""` (no password required) preserves today's behaviour for + every example that does not opt in - nothing that does not call this + function changes. Added to `HandleHelpAndVersionArgs()`'s `--help` output, + in the same option-list style as `--port`/`--deviceID`, so it is + discoverable series-wide once adopted. First consumer: + `BACnetProfileExample-B-SCHUB-CPP`, which parses it alongside `--port`/ + `--deviceID` in `main()` and renamed its own constant to `g_dccPassword` + (no longer `static const`, since it is now assigned at start-up) feeding the + existing `DeviceCommunicationControl` callback's password check - unchanged + otherwise. + +## [2.9.0] - 2026-09-17 (from the BACnetProfileExample-B-BC-CPP line, merged in 3.0.0) ### Added @@ -25,7 +158,7 @@ and the folder adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.h not a real "indeterminable" answer. `PROPERTY_IDENTIFIER_LINK_SPEED = 420` added to `CASBACnetStackExampleConstants.h` alongside it. -## [2.8.0] - 2026-09-17 +## [2.8.0] - 2026-09-17 (from the BACnetProfileExample-B-BC-CPP line, merged in 3.0.0) ### Added @@ -37,7 +170,7 @@ and the folder adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.h time sync took), not leave the stack's "callback declined, no default" `read-access-denied` fallback in place. -## [2.7.0] - 2026-09-17 +## [2.7.0] - 2026-09-17 (from the BACnetProfileExample-B-BC-CPP line, merged in 3.0.0) ### Added @@ -84,7 +217,7 @@ and the folder adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.h converts camelCase to `Title_Case`, sorts by value, and emits `{ id, "name" },` rows - see this entry's originating commit for the exact script. -## [2.6.0] - 2026-09-17 +## [2.6.0] - 2026-09-17 (from the BACnetProfileExample-B-BC-CPP line, merged in 3.0.0) ### Added diff --git a/common/README.md b/common/README.md index 6b9e31a..5ae9380 100644 --- a/common/README.md +++ b/common/README.md @@ -22,7 +22,8 @@ example repository. | File | Purpose | |------|---------| -| `CASExampleHelper.h` / `.cpp` | UDP socket on the BACnet/IP port + the transport/time callbacks; version/help printing; `--port` / `--deviceID` parsing; keyboard commands (h/q/up/down); local-IPv4 / broadcast helpers; broadcast I-Am on start-up. | +| `CASExampleHelper.h` / `.cpp` | UDP socket on the BACnet/IP port + the transport/time callbacks; version/help printing; `--port` / `--deviceID` / `--dcc-password` parsing; RX/TX frame summarizing and optional `--xml` frame dump; keyboard commands (h/q/up/down); local-IPv4 / broadcast / link-speed helpers; broadcast I-Am on start-up. | +| `CASExampleLog.h` / `.cpp` | A minimal, dependency-free structured logging facility (`Debug`/`Info`/`Warning`/`Error`, timestamped, runtime-configurable minimum level) - a drop-in replacement for bare `printf`/`fprintf(stderr, ...)` calls. | | `SimpleUDP.h` / `.cpp` | A tiny cross-platform UDP socket wrapper (Winsock on Windows, BSD sockets on Linux/macOS). | | `CASBACnetStackExampleConstants.h` | A self-contained, series-wide copy of the BACnet enumeration values the examples use (each section names the CAS BACnet Stack header that defines the full enumeration). Identical in every example — the union of what the series needs. | | `CHANGELOG.md` | The changelog of this folder itself (see Versioning above). | diff --git a/docs/PICS.md b/docs/PICS.md index 10afbb9..59946a5 100644 --- a/docs/PICS.md +++ b/docs/PICS.md @@ -57,7 +57,7 @@ is subsumption, not a second claim. | AE-ACK-B | Alarm and Event - ACK - B | Yes | | AE-INFO-B | Alarm and Event - Information - B | Yes | | AE-CRL-B | Alarm and Event - Recipient List - B | Yes | -| SCHED-E-B | Scheduling - External - B | Yes (local write live-verified; remote write correctly wired but not cross-instance wire-verified - see [TUTORIAL.md](../TUTORIAL.md)) | +| SCHED-E-B | Scheduling - External - B | Yes (local and remote writes wire-verified; the stack drops the startup write made before the remote device is bound, [#2343](https://github.com/chipkin/cas-bacnet-stack/issues/2343) - see [TUTORIAL.md](../TUTORIAL.md)) | | T-VMT-I-B | Trending - Viewing and Modifying Trends - Internal - B | Yes - proven live through both Trend Log 1 ("Lilac") and Trend Log Multiple 1 ("Magenta") | | T-ATR-B | Trending - Automated Trend Retrieval - B | Yes, via ReadRange - live-verified against Trend Log Multiple 1 ("Magenta") | | DM-DDB-A | Device Management - Dynamic Device Binding - A | Yes | @@ -115,7 +115,7 @@ No object is dynamically creatable or deletable. | Object type | Instance | Object_Name | Optional properties supported | |---|:---:|---|---| -| Device | 389005 | Rainbow | Description | +| Device | 389005 | Chipkin Example B-BC | Description | | Analog Input | 1 | Bronze | - | | Binary Input | 1 | Emerald | - | | Multi-state Input | 1 | Hot Pink | State_Text | @@ -167,7 +167,7 @@ handle data in all character sets. 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 389005 "Rainbow" - the device itself; the instance is configurable with --deviceID. The stack rows are device-wide facts only the stack knows - the protocol version and revision it implements, the services and object types it was configured with, the live object list and address-binding table. The accepted rows are the stack's configured defaults for APDU limits, segmentation, system status and database revision; an application that answered them from its own constants could contradict the stack, so this example does not +### Device 389005 "Chipkin Example B-BC" - the device itself; the instance is configurable with --deviceID. The stack rows are device-wide facts only the stack knows - the protocol version and revision it implements, the services and object types it was configured with, the live object list and address-binding table. The accepted rows are the stack's configured defaults for APDU limits, segmentation, system status and database revision; an application that answered them from its own constants could contradict the stack, so this example does not | Property | Datatype | Served by | Writable | |---|---|---|:---:| @@ -314,7 +314,7 @@ Every object this example creates, and every REQUIRED property of each (per ANSI | Recipient_List | BACnetLIST of BACnetDestination | stack default, accepted (None known - a read fails with `unknown-property` or an empt) | yes | | Property_List | BACnetARRAY[N] of BACnetPropertyIdentifier | 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) +### 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). Link_Speed is read once at start-up from the host's primary network interface (CASExampleHelper::GetLocalLinkSpeedBitsPerSecond) - 0.0 if the host OS can't report one, which is the spec-correct 'indeterminable' answer, not a bug | Property | Datatype | Served by | Writable | |---|---|---|:---:| @@ -329,7 +329,7 @@ Every object this example creates, and every REQUIRED property of each (per ANSI | Changes_Pending | Boolean | app | no | | Property_List | BACnetARRAY[N] of BACnetPropertyIdentifier | stack | no | -### Schedule 1 "Saffron" - SCHED-E-B. Present_Value, Effective_Period, Schedule_Default, List_Of_Object_Property_References, Priority_For_Writing and Status_Flags are NOT stack DEFAULTS - they are genuinely held and served by the stack's Schedule engine (BACnetStack_AddScheduleObject plus the BACnetStack_SetSchedule*/AddSchedule* configuration calls in main.cpp). List_Of_Object_Property_References has TWO entries (each BACnetStack_AddScheduleObjectPropertyReference call appends): a LOCAL one at Analog Output 1 (Chartreuse) Present_Value, and a REMOTE one at a peer device's (default instance 389002, e.g. a locally-built B-SA-CPP) Analog Output 1 Present_Value - the SCHED-E-B / F-EXTWRITE remote fan-out. The local write is proven (inherited from B-AAC's SCHED-I-B); the remote write is correct, documented API usage but was not wire-verified end-to-end this session because two example instances on different UDP ports on one host cannot discover each other by broadcast - see TODO.md item 3. One weekly transition (Monday 08:00) and one calendar-date exception (2026-12-25, via the inline calendar-entry form) are seeded at start-up; the 's' key (common/'s DemoAdvance) adds a transition for right now so the change can be observed without waiting for the wall clock +### Schedule 1 "Saffron" - SCHED-E-B. Present_Value, Effective_Period, Schedule_Default, List_Of_Object_Property_References, Priority_For_Writing and Status_Flags are NOT stack DEFAULTS - they are genuinely held and served by the stack's Schedule engine (BACnetStack_AddScheduleObject plus the BACnetStack_SetSchedule*/AddSchedule* configuration calls in main.cpp). List_Of_Object_Property_References has TWO entries (each BACnetStack_AddScheduleObjectPropertyReference call appends): a LOCAL one at Analog Output 1 (Chartreuse) Present_Value, and a REMOTE one at a peer device's (default instance 389002, e.g. a locally-built B-SA-CPP) Analog Output 1 Present_Value - the SCHED-E-B / F-EXTWRITE remote fan-out. Both writes are wire-verified: the local one is inherited from B-AAC's SCHED-I-B, and the remote one was checked with tests/sched_e_b_remote_peer.py on stack 6.0.22. The stack drops the startup write made before the peer is bound (cas-bacnet-stack issue #2343) - see TODO.md item 2. One weekly transition (Monday 08:00) and one calendar-date exception (2026-12-25, via the inline calendar-entry form) are seeded at start-up; the 's' key (common/'s DemoAdvance) adds a transition for right now so the change can be observed without waiting for the wall clock | Property | Datatype | Served by | Writable | |---|---|---|:---:| @@ -346,7 +346,7 @@ Every object this example creates, and every REQUIRED property of each (per ANSI | Out_Of_Service | Boolean | app | no | | Property_List | BACnetARRAY[N] of BACnetPropertyIdentifier | stack | no | -### Calendar 1 "Cream" - exists for SCHED-E-B completeness alongside Saffron's exception, but its Date_List cannot be populated through the customer API (cas-bacnet-stack issue #963 - no read path for a Calendar object's Date_List; the only generic constructed-property callback is test-tool-only). Present_Value therefore always answers false rather than evaluating a Date_List that is never populated - see TODO.md +### Calendar 1 "Cream" - exists for SCHED-E-B completeness alongside Saffron's exception, but its Date_List cannot be populated through the customer API (cas-bacnet-stack issue #1758 - no read path for a Calendar object's Date_List; the only generic constructed-property callback is test-tool-only). Present_Value therefore always answers false rather than evaluating a Date_List that is never populated - see TODO.md | Property | Datatype | Served by | Writable | |---|---|---|:---:| diff --git a/docs/objects.json b/docs/objects.json index 61ab455..531ae7e 100644 --- a/docs/objects.json +++ b/docs/objects.json @@ -3,7 +3,7 @@ { "type": "Device", "instance": 389005, - "name": "Rainbow", + "name": "Chipkin Example B-BC", "app": [ "Object_Name", "Description", @@ -131,7 +131,7 @@ "enabled": [], "writable": [], "accepted": ["Present_Value", "Effective_Period", "Priority_For_Writing"], - "note": "SCHED-E-B. Present_Value, Effective_Period, Schedule_Default, List_Of_Object_Property_References, Priority_For_Writing and Status_Flags are NOT stack DEFAULTS - they are genuinely held and served by the stack's Schedule engine (BACnetStack_AddScheduleObject plus the BACnetStack_SetSchedule*/AddSchedule* configuration calls in main.cpp). List_Of_Object_Property_References has TWO entries (each BACnetStack_AddScheduleObjectPropertyReference call appends): a LOCAL one at Analog Output 1 (Chartreuse) Present_Value, and a REMOTE one at a peer device's (default instance 389002, e.g. a locally-built B-SA-CPP) Analog Output 1 Present_Value - the SCHED-E-B / F-EXTWRITE remote fan-out. The local write is proven (inherited from B-AAC's SCHED-I-B); the remote write is correct, documented API usage but was not wire-verified end-to-end this session because two example instances on different UDP ports on one host cannot discover each other by broadcast - see TODO.md item 3. One weekly transition (Monday 08:00) and one calendar-date exception (2026-12-25, via the inline calendar-entry form) are seeded at start-up; the 's' key (common/'s DemoAdvance) adds a transition for right now so the change can be observed without waiting for the wall clock" + "note": "SCHED-E-B. Present_Value, Effective_Period, Schedule_Default, List_Of_Object_Property_References, Priority_For_Writing and Status_Flags are NOT stack DEFAULTS - they are genuinely held and served by the stack's Schedule engine (BACnetStack_AddScheduleObject plus the BACnetStack_SetSchedule*/AddSchedule* configuration calls in main.cpp). List_Of_Object_Property_References has TWO entries (each BACnetStack_AddScheduleObjectPropertyReference call appends): a LOCAL one at Analog Output 1 (Chartreuse) Present_Value, and a REMOTE one at a peer device's (default instance 389002, e.g. a locally-built B-SA-CPP) Analog Output 1 Present_Value - the SCHED-E-B / F-EXTWRITE remote fan-out. Both writes are wire-verified: the local one is inherited from B-AAC's SCHED-I-B, and the remote one was checked with tests/sched_e_b_remote_peer.py on stack 6.0.22. The stack drops the startup write made before the peer is bound (cas-bacnet-stack issue #2343) - see TODO.md item 2. One weekly transition (Monday 08:00) and one calendar-date exception (2026-12-25, via the inline calendar-entry form) are seeded at start-up; the 's' key (common/'s DemoAdvance) adds a transition for right now so the change can be observed without waiting for the wall clock" }, { "type": "Calendar", @@ -141,7 +141,7 @@ "enabled": [], "writable": [], "accepted": ["Date_List"], - "note": "exists for SCHED-E-B completeness alongside Saffron's exception, but its Date_List cannot be populated through the customer API (cas-bacnet-stack issue #963 - no read path for a Calendar object's Date_List; the only generic constructed-property callback is test-tool-only). Present_Value therefore always answers false rather than evaluating a Date_List that is never populated - see TODO.md" + "note": "exists for SCHED-E-B completeness alongside Saffron's exception, but its Date_List cannot be populated through the customer API (cas-bacnet-stack issue #1758 - no read path for a Calendar object's Date_List; the only generic constructed-property callback is test-tool-only). Present_Value therefore always answers false rather than evaluating a Date_List that is never populated - see TODO.md" }, { "type": "File", diff --git a/main.cpp b/main.cpp index 69c0663..3778355 100644 --- a/main.cpp +++ b/main.cpp @@ -37,7 +37,7 @@ // WHAT IS NOT IMPLEMENTED (see README.md "What this example does NOT do" + TODO.md): // - Calendar 1 "Cream"'s Date_List: there is no customer-facing export or // callback to populate a Calendar object's Date_List (cas-bacnet-stack -// issue #963), so Schedule 1 "Saffron"'s one-off exception uses an inline +// issue #1758), so Schedule 1 "Saffron"'s one-off exception uses an inline // calendar-date entry rather than a reference to Cream. Inherited from every // prior example that carries a Calendar (B-AAC, B-ACC, B-LS). // @@ -47,7 +47,7 @@ // a Trend Log and a Trend Log Multiple. Each object has a colour name (the // convention shared across this example series): // -// Device 389005 "Rainbow" (instance configurable with --deviceID) +// Device 389005 "Chipkin Example B-BC" (instance configurable with --deviceID) // Analog Input 1 "Bronze" (REAL, degrees Celsius; read-only) // Binary Input 1 "Emerald" (active / inactive; read-only) // Multi-State Input 1 "Hot Pink" (state 1..3; read-only) @@ -104,6 +104,7 @@ #include #include +#include #include // time(), localtime_[sr]() - the SCHED-I-B demo-advance key (see KeyCommand::DemoAdvance) #if defined(_WIN32) @@ -118,7 +119,7 @@ using namespace CASBACnetStackExampleConstants; // 1. Example + device configuration // ----------------------------------------------------------------------------- static const char* APP_NAME = "BACnet B-BC (Building Controller) Example - C++"; -static const char* APP_VERSION = "1.0.2"; +static const char* APP_VERSION = "1.0.6"; // The device instance. BACnet requires this to be configurable, so it defaults // to 389005 and can be overridden on the command line with --deviceID. Keep it @@ -148,10 +149,10 @@ static const uint32_t VENDOR_IDENTIFIER = 389; // whole BACnet internetwork, and here it is a COMPILE-TIME constant. The device // instance is runtime-configurable via --deviceID, so it is easy to ship two // units, configure their instances correctly, and still have BOTH announce -// Object_Name "Rainbow" - a spec violation, and a hard BTL failure. In a real +// Object_Name "Chipkin Example B-BC" - a spec violation, and a hard BTL failure. In a real // product Object_Name must be per-unit configurable too: derive it from a serial // number, DIP switches, a config file, or add a --deviceName argument. -static const char* DEVICE_NAME = "Rainbow"; +static const char* DEVICE_NAME = "Chipkin Example B-BC"; // The Device object's Description. Change it to what YOUR device actually is; // this string describes this tutorial. @@ -183,10 +184,16 @@ static const char* MODEL_NAME = "CAS BACnet Stack Example - B-BC"; // not a security boundary. static const char* DCC_PASSWORD = ""; // "" = no password required -// FIRMWARE_REVISION / APPLICATION_SOFTWARE_VERSION - your real versions. Wire -// them to your build rather than hard-coding a number that will go stale. -static const char* FIRMWARE_REVISION = "1.0.0"; -static const char* APPLICATION_SOFTWARE_VERSION = "1.0.0"; +// Firmware_Revision (Device object property 44) reflects the underlying CAS +// BACnet Stack's real version, not this example's own. It is populated once +// in main(), right after LoadBACnetFunctions() succeeds (the version getters +// it calls are themselves loaded by that call), from +// BACnetStack_GetAPIMajorVersion()/GetAPIMinorVersion()/GetAPIPatchVersion()/ +// GetAPIBuildVersion() - the same 4 calls common/CASExampleHelper.cpp's +// PrintVersion() uses for the startup banner. Application_Software_Version +// (property 12) is this example's own version and just returns APP_VERSION +// directly - see its use in the property-read switch below. +static std::string g_firmwareRevision; // The sensor objects (all instance 1) and their colour names. static const uint32_t ANALOG_INPUT_INSTANCE = 1; // "Bronze" @@ -286,7 +293,7 @@ static uint8_t RECIPIENT_IP[4] = { 0, 0, 0, 0 }; // used when not broadcasting // A weekly transition sets Chartreuse to SCHEDULE_DEMO_VALUE; outside any scheduled // window Schedule_Default applies instead. Calendar 1 "Cream" exists as a readable // object alongside the exception (see TODO.md for why it is not wired to the -// exception's period - cas-bacnet-stack issue #963). +// exception's period - cas-bacnet-stack issue #1758). static const uint32_t SCHEDULE_INSTANCE = 1; // "Saffron" static const uint32_t CALENDAR_INSTANCE = 1; // "Cream" static const uint8_t SCHEDULE_WRITE_PRIORITY = 8; // mid-range: below manual overrides at 1-7 @@ -718,7 +725,7 @@ bool GetPropertyBool(const uint32_t deviceInstance, const uint16_t objectType, } // Calendar 1 (Cream) Present_Value (required): true when today's date is in // Date_List. This example cannot populate a Calendar object's Date_List - // through the customer API (cas-bacnet-stack issue #963 - see TODO.md), so + // through the customer API (cas-bacnet-stack issue #1758 - see TODO.md), so // there is nothing to evaluate against; always answer false rather than // fabricate a match. if (objectType == OBJECT_TYPE_CALENDAR && objectInstance == CALENDAR_INSTANCE && @@ -926,9 +933,9 @@ bool GetPropertyCharString(const uint32_t deviceInstance, const uint16_t objectT case PROPERTY_IDENTIFIER_MODEL_NAME: return ReturnCharacterString(MODEL_NAME, value, valueElementCount, maxElementCount, encodingType); case PROPERTY_IDENTIFIER_FIRMWARE_REVISION: - return ReturnCharacterString(FIRMWARE_REVISION, value, valueElementCount, maxElementCount, encodingType); + return ReturnCharacterString(g_firmwareRevision.c_str(), value, valueElementCount, maxElementCount, encodingType); case PROPERTY_IDENTIFIER_APPLICATION_SOFTWARE_VERSION: - return ReturnCharacterString(APPLICATION_SOFTWARE_VERSION, value, valueElementCount, maxElementCount, encodingType); + return ReturnCharacterString(APP_VERSION, value, valueElementCount, maxElementCount, encodingType); default: break; } @@ -1526,6 +1533,19 @@ int main(int argc, char** argv) { return 1; } + // g_firmwareRevision (Device object property 44) - see its own doc comment + // above for why this is the STACK's version, not this example's own + // (that's Application_Software_Version/APP_VERSION instead). Must happen + // after LoadBACnetFunctions() (these getters ARE some of the functions it + // loads) and before the Device object is ever readable. + { + char buf[32]; + snprintf(buf, sizeof(buf), "%u.%u.%u.%u", + BACnetStack_GetAPIMajorVersion(), BACnetStack_GetAPIMinorVersion(), + BACnetStack_GetAPIPatchVersion(), BACnetStack_GetAPIBuildVersion()); + g_firmwareRevision = buf; + } + // --- Command line + version -------------------------------------------- // --help / --version print and exit, so handle them before we bind a socket // or touch the stack. @@ -1929,7 +1949,7 @@ int main(int argc, char** argv) { } // One exception: an inline calendar-date entry (periodType 0 = a single date, // here 2026-12-25) rather than a reference to Cream's Date_List - Cream's - // Date_List cannot be populated through the customer API yet (issue #963; + // Date_List cannot be populated through the customer API yet (cas-bacnet-stack issue #1758; // see TODO.md), so a calendar-REFERENCE exception would be stored but would // never actually match. The inline form has no such dependency. uint32_t exceptionIndex = 0; diff --git a/submodules/cas-bacnet-stack b/submodules/cas-bacnet-stack index a8d3b6b..22ac3c9 160000 --- a/submodules/cas-bacnet-stack +++ b/submodules/cas-bacnet-stack @@ -1 +1 @@ -Subproject commit a8d3b6bfa977f65719f0fe761b6b758acb9f941f +Subproject commit 22ac3c986d3a1c46028527d356ddd80673715bf6 diff --git a/tests/sched_e_b_remote_peer.py b/tests/sched_e_b_remote_peer.py new file mode 100644 index 0000000..e22ffba --- /dev/null +++ b/tests/sched_e_b_remote_peer.py @@ -0,0 +1,57 @@ +"""Issue #6: prove Schedule 1's REMOTE reference (device 389002, AO 1) is written on the wire. + +Acts as peer device 389002 with a commandable Analog Output 1 on its own UDP port, sends a +unicast I-Am to the B-BC example so its Device Address Binding can resolve 389002 without a +BBMD, then changes Schedule 1's Schedule_Default so the schedule re-evaluates and fans out. + +Usage (B-BC running on --port 47900 on this host): + python tests/sched_e_b_remote_peer.py --target-port 47900 +Prints RESULT: PASS when the peer's AO 1 Present_Value == --value at priority 8. +""" +import asyncio +from bacpypes3.argparse import SimpleArgumentParser +from bacpypes3.app import Application +from bacpypes3.local.analog import AnalogOutputObject +from bacpypes3.pdu import Address +from bacpypes3.primitivedata import ObjectIdentifier, Real + +async def main(): + p = SimpleArgumentParser() + p.set_defaults(address="127.0.0.1/32:47902", instance=389002, name="sched-peer-389002") + p.add_argument("--target-port", type=int, default=47900) + p.add_argument("--value", type=float, default=42.5) + a = p.parse_args() + app = Application.from_args(a) + ao = AnalogOutputObject( + objectIdentifier=("analog-output", 1), + objectName="peer AO 1", + presentValue=0.0, + units="degrees-celsius", + relinquishDefault=0.0, + ) + app.add_object(ao) + bbc = Address(f"127.0.0.1:{a.target_port}") + try: + for _ in range(3): + app.i_am(address=bbc) + await asyncio.sleep(0.5) + sched = ObjectIdentifier("schedule,1") + print("Schedule PV before:", await app.read_property(bbc, sched, "present-value")) + await app.write_property(bbc, sched, "schedule-default", Real(a.value)) + print("wrote Schedule_Default =", a.value) + for _ in range(20): + await asyncio.sleep(0.25) + if ao.presentValue == a.value: + break + print("Schedule PV after:", await app.read_property(bbc, sched, "present-value")) + print("peer AO1 Present_Value:", ao.presentValue) + print("peer AO1 Priority_Array:", + [(i + 1, pv.real if pv.real is not None else "null") + for i, pv in enumerate(ao.priorityArray) if pv.null is None]) + print("RESULT:", "PASS" if ao.presentValue == a.value else "FAIL") + finally: + app.close() + + +if __name__ == "__main__": + asyncio.run(main())