Skip to content

fix: build Trend Log 1's Start_Time/Stop_Time window from UTC, not local time (#2051) - #9

Merged
sws-chipkin merged 1 commit into
mainfrom
fix/2051-trend-log-record-count
Sep 23, 2026
Merged

sws-chipkin merged 1 commit into
mainfrom
fix/2051-trend-log-record-count

Conversation

@sws-chipkin

Copy link
Copy Markdown
Collaborator

Summary

Fixes chipkin/cas-bacnet-stack#2051: Trend Log 1 ("Lilac")'s Record_Count never incremented.

  • HelperGetSystemTime() returns raw time(0) and this example serves no Device UTC_Offset, so the stack's own "now" (a BACnetDateTime built from GetSystemTime + UTC_Offset=0) is UTC wall-clock, not local wall-clock.
  • SetTrendLogStartStopTime's window was built with localtime_s/localtime_r — on any host not in UTC, the window no longer bracketed the clock the stack actually compares against, so ReadyToLog never passed.
  • Fixed by switching to gmtime_s/gmtime_r.
  • Removed TODO.md item 1 (resolved) and renumbered the rest; updated CHANGELOG.md, README.md, TUTORIAL.md, AGENTS.md, and docs/objects.json/docs/PICS.md to drop the "known gap" framing.

Note on docs/PICS.md

The OBJECTS-PROPERTIES generated block was hand-edited to match the docs/objects.json change exactly, since tools/gen-objects-properties.py lives in the series-root repo and wasn't available in this checkout. Please re-run python tools/gen-objects-properties.py BACnetProfileExample-B-BC-CPP --check to confirm the sync before merging.

Test plan

  • cmake --build build --config Release → succeeds, 0 errors
  • Live-verified with bacpypes3 against the running example: Record_Count climbs continuously (observed 14 → 29 → 44 over 30 seconds)
  • No crash or regression observed over a 90-second run

🤖 Generated with Claude Code

…cal time (#2051)

BACnetStack_SetTrendLogStartStopTime's window was built with
localtime_s/localtime_r, but HelperGetSystemTime() returns raw time(0) and
this example serves no Device UTC_Offset, so the stack's own "now" (a
BACnetDateTime built from GetSystemTime + UTC_Offset=0) is UTC wall-clock,
not local wall-clock.

On any host not in UTC, the local-time window no longer bracketed the clock
the stack actually compares against - west of UTC, Stop_Time landed BEFORE
the stack's "now" so ReadyToLog's stopTimeGood check never passed and
Record_Count stayed at 0 forever; east of UTC, Start_Time would fail the
same way instead.

Fixed by switching 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).

Removed TODO.md item 1 (resolved) and renumbered the rest. Updated
CHANGELOG.md, README.md, TUTORIAL.md, AGENTS.md and docs/objects.json /
docs/PICS.md to drop the "known gap" framing now that Lilac accumulates
records correctly. The docs/PICS.md OBJECTS-PROPERTIES block was hand-edited
to match the docs/objects.json change 1:1, since tools/gen-objects-
properties.py lives in the series-root repo and wasn't available in this
checkout - please re-run it to confirm the sync.

Fixes chipkin/cas-bacnet-stack#2051.
@sws-chipkin
sws-chipkin force-pushed the fix/2051-trend-log-record-count branch from 6d25d57 to 877ae90 Compare September 23, 2026 05:54
@sws-chipkin
sws-chipkin merged commit 466a0db into main Sep 23, 2026
3 checks passed
@sws-chipkin
sws-chipkin deleted the fix/2051-trend-log-record-count branch September 23, 2026 06:02
@sws-chipkin

Copy link
Copy Markdown
Collaborator Author

Rebased onto main (TODO.md conflict resolved: main's re-verification of the Lilac gap predates this fix, since main.cpp still used localtime) and merged after CI (ubuntu + windows-2022 green). Stack-side: the clock is now documented on BACnetStack_SetTrendLogStartStopTime (chipkin/cas-bacnet-stack#2344, IFC-044). Not changed here, worth a look: the SCHED-I-B DemoAdvance key (main.cpp, KeyCommand::DemoAdvance) also builds its Weekly_Schedule entry from localtime, while the schedule engine evaluates against the device's Local_Date/Local_Time - check it still fires on a non-UTC host.

sws-chipkin added a commit that referenced this pull request Sep 23, 2026
Conflicts resolved in favour of both sides:
- #9 showed #2051 was an example bug (window built from local time,
  stack compares UTC), not a stack defect. Dropped every "Lilac never
  records" claim this branch had carried forward; TODO.md item 1 stays
  removed and items are renumbered (tracking-issue list, cross-refs in
  AGENTS.md, TUTORIAL.md and docs/objects.json updated to match).
- Kept this branch's 6.0.22 / SCHED-E-B / #2340-#2343 content.
- Moved #9's CHANGELOG entry out of the 1.0.1 section into 1.0.6.
- Last #963 references -> #1758; PICS regenerated.

Re-verified live on the merged build (v1.0.6, stack 6.0.22):
Trend Log 1 Record_Count 20, Trend Log Multiple 1 21, 0 flood lines,
RPM(Device, ALL) ok, tests/sched_e_b_remote_peer.py PASS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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