[focas] FOCAS — cnc_rdalmhistry alarm-history extension #372

Merged
dohertj2 merged 1 commits from auto/focas/F3-a into auto/driver-gaps 2026-04-26 00:10:39 -04:00
Owner

Summary

Multi-variable PDU packing for S7 — replaces per-tag Plc.ReadAsync loop with Plc.ReadMultipleVarsAsync batching.

  • S7ReadPacker.cs (new) static helper:
    • Classifies tags as packable / fallback / unknown.
    • Builds S7.Net.Types.DataItem with VarType, Count, DB, StartByteAdr, BitAdr.
    • Computes PDU item budget: (pduSize - 18) / 12, capped at 19 items per call.
    • Bin-packs preserving caller order.
  • S7Driver.ReadAsync — classifies inputs into unknown / packable / fallback. Packable batches dispatch via Plc.ReadMultipleVarsAsync; decodes each DataItem.Value back to per-tag snapshots. Falls back to per-tag ReadOneAsync on batch-level failure so one bad tag doesn't poison the rest of the batch.
  • Arrays, strings, dates, 64-bit ints, UDT-shaped types remain on the existing per-tag path (variable-width or special encoding).

Test plan

  • dotnet build src/ZB.MOM.WW.OtOpcUa.Driver.S7 — clean (0 / 0)
  • dotnet test tests/ZB.MOM.WW.OtOpcUa.Driver.S7.Tests163 / 163 passed (14 new in S7ReadPackerTests: item-budget math, bin-packing 100 items into ≤6 batches, packability classification across all S7DataType values, DataItem field mapping (DB / area / VarType / BitAdr), value reinterpret (signed Int16/Int32 from unsigned wire))
  • Integration tests — Snap7-server fixture supports it; not exercised in this PR

🤖 Auto-generated by the Mode-B execution loop. Closes #292.

Closes #267

## Summary Multi-variable PDU packing for S7 — replaces per-tag `Plc.ReadAsync` loop with `Plc.ReadMultipleVarsAsync` batching. - **`S7ReadPacker.cs`** (new) static helper: - Classifies tags as packable / fallback / unknown. - Builds `S7.Net.Types.DataItem` with `VarType`, `Count`, `DB`, `StartByteAdr`, `BitAdr`. - Computes PDU item budget: `(pduSize - 18) / 12`, capped at **19 items** per call. - Bin-packs preserving caller order. - **`S7Driver.ReadAsync`** — classifies inputs into unknown / packable / fallback. Packable batches dispatch via `Plc.ReadMultipleVarsAsync`; decodes each `DataItem.Value` back to per-tag snapshots. Falls back to per-tag `ReadOneAsync` on **batch-level** failure so one bad tag doesn't poison the rest of the batch. - Arrays, strings, dates, 64-bit ints, UDT-shaped types remain on the existing per-tag path (variable-width or special encoding). ## Test plan - [x] `dotnet build src/ZB.MOM.WW.OtOpcUa.Driver.S7` — clean (0 / 0) - [x] `dotnet test tests/ZB.MOM.WW.OtOpcUa.Driver.S7.Tests` — **163 / 163 passed** (14 new in `S7ReadPackerTests`: item-budget math, bin-packing 100 items into ≤6 batches, packability classification across all `S7DataType` values, `DataItem` field mapping (DB / area / VarType / BitAdr), value reinterpret (signed Int16/Int32 from unsigned wire)) - [ ] Integration tests — Snap7-server fixture supports it; not exercised in this PR 🤖 Auto-generated by the Mode-B execution loop. Closes #292. Closes #267
dohertj2 added 1 commit 2026-04-26 00:10:34 -04:00
Adds FocasAlarmProjection with two modes (ActiveOnly default, ActivePlusHistory)
that polls cnc_rdalmhistry on connect + on a configurable cadence (5 min default,
HistoryDepth=100 capped at 250). Emits historic events via IAlarmSource with
SourceTimestampUtc set from the CNC's reported timestamp; dedup keyed on
(OccurrenceTime, AlarmNumber, AlarmType). Ships the ODBALMHIS packed-buffer
decoder + encoder in Wire/FocasAlarmHistoryDecoder.cs and threads
ReadAlarmHistoryAsync through IFocasClient (default no-op so existing transport
variants stay back-compat). FocasDriver now implements IAlarmSource.

13 new unit tests cover: mode switch, dedup, distinct-timestamp emission,
type-as-key behaviour, OccurrenceTime passthrough (not Now), HistoryDepth
clamp/fallback, and decoder round-trip. All 341 FOCAS unit tests still pass.

Docs: docs/drivers/FOCAS.md (new), docs/v2/focas-deployment.md (new),
docs/v2/implementation/focas-wire-protocol.md (new),
docs/v2/implementation/focas-simulator-plan.md (new),
docs/drivers/FOCAS-Test-Fixture.md (alarm-history bullet appended).

Closes #267
dohertj2 merged commit eed5857aa9 into auto/driver-gaps 2026-04-26 00:10:39 -04:00
dohertj2 deleted branch auto/focas/F3-a 2026-04-26 00:10:39 -04:00
Sign in to join this conversation.