Repository navigation
fix(WPF): instant IEC-101 live Trace and engineer-readable full line monitor #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
masarray
merged 2 commits into
master
from
fix/iec101-live-trace-ase2000-parity-20261029
Oct 28, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Live Trace recovery and IEC-101 interpretive line monitor — 2026-10-29 | ||
|
|
||
| ## Problem reproduced in screenshots | ||
| Active IEC-101 TX/RX counters and LED traffic are live, but the Trace workspace remains visually blank until changing tabs. The old UI retained Hold/selected-row freeze state across connections; first-batch range notifications to the still-mounted virtualized WPF ListBox could leave the initially cleared viewport unrealized. In addition, Balanced verbosity *silently omitted* routine polling when the Trace workspace was not active. | ||
|
|
||
| ## Corrected architecture | ||
| - **PrepareLiveTraceForConnect** resets selection, Hold and deferred view flags only at connection start (active, dual-link and passive), never on every frame. | ||
| - Exactly one dispatcher-priority initial evidence flush after Connect. Continuous traffic remains handled by the existing bounded 75ms timer, adaptive processing budget and deferred UI batch updates, without a per-frame `Dispatcher.Invoke`. | ||
| - The first Trace batch is materialized atomically from the authoritative 1200-row bounded ring and schedules one deferred layout invalidation. Subsequent batches append/trim only. Switching workspaces still snapshots that same ring; there is no separate tab-dependent decoder or storage. | ||
| - **Every TX/RX raw frame** is retained in the bounded Trace store regardless of which workspace is visible. Backpressure protection remains separately counted and does not silently discard raw bytes from the capture journal. | ||
| - Physical poll/reply interpretation uses the existing typed FT1.2 and ASDU decode; no regex/string guess of PRM, ACD, DFC or COT. IEC-101 Class 2 FC11 request, secondary FC9 no-data, FC8 user data with type/COT/CA/IOA/value/quality/time, link ACK/NACK and link reset are explained as engineer-readable lines. E5 remains contextual: never inferred as physical command success. | ||
| - Compact TX ➤ and RX ◀ markers; raw hex and selected-byte Inspector remain directly below/alongside the line. No heavy graphic controls/animations, wide grid columns, or per-frame WPF layout refreshes. | ||
|
|
||
| ## FAT acceptance | ||
| 1. Start IEC-101 Active Master on COM at 1200 bps with Trace already selected; first Reset Link TX and RX ACK must display **without switching tabs**. | ||
| 2. Keep Trace selected during GI, FC10/11 polls and FC8/9 replies; every raw frame has a direction, protocol meaning and selectable original HEX. | ||
| 3. Switch to Values/Events while polling, then back to Trace: ring snapshot must show recent traffic from the inactive period. | ||
| 4. In Trace select one row: deliberate Hold preserves inspection; choose Auto or new Connect to resume live. Prior session Hold must never freeze the next session. | ||
| 5. FC9 with ACD=1/DFC=0 prints that requested class has no data but Class 1 pending. Never conflate it with RTU application error. | ||
| 6. Run same capture alongside ASE2000 V2 and compare FC, COT, CA, IOA, quality and CP56Time2a. Verify linked selected raw field highlights and command lifecycle separately. | ||
| 7. Run stress 4-COM passive and long duration Windows integrated sessions; verify no unbounded RAM/GUI repaint. CI does not substitute real-device FAT. | ||
|
|
||
| ## Scope | ||
| This milestone corrects initial WPF Trace rendering and per-frame human-readable decoding for IEC-101. It does not redesign the rest of the GUI, implement a complete bidirectional byte-field highlight for every IEC-104/103 frame, or claim full ASE2000 V2 parity yet. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
src/ARIEC60870.Desktop/ViewModels/Iec101TraceNarrator.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| // Copyright 2026 Ari Sulistiono | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| using ARIEC60870.Core.Model; | ||
| using ARIEC60870.Master.Model; | ||
|
|
||
| namespace ARIEC60870.Desktop.ViewModels; | ||
|
|
||
| /// <summary> | ||
| /// One cheap, read-only interpretation of the already decoded FT1.2/ASDU evidence. | ||
| /// The line monitor must never infer an ACTTERM, process operation or queue content | ||
| /// from a link ACK, ACD, or an unrelated command. | ||
| /// </summary> | ||
| public static class Iec101TraceNarrator | ||
| { | ||
| public static (string Title, string Meaning) Describe(Iec103MasterEvidenceEvent item) | ||
| { | ||
| var direction = item.Direction == FrameDirection.MasterToSlave ? "➤ TX" : | ||
| item.Direction == FrameDirection.SlaveToMaster ? "◀ RX" : "• STATE"; | ||
| var link = item.Frame?.LinkControl; | ||
| var prefix = string.IsNullOrWhiteSpace(item.PhysicalSource) | ||
| ? direction : $"{direction} [{item.PhysicalSource}]"; | ||
| var dl = item.LinkAddress ?? item.Frame?.LinkAddress; | ||
| var dlText = dl.HasValue ? $"DL {dl.Value}" : "DL ?"; | ||
| var kind = string.IsNullOrWhiteSpace(item.DataClass) ? string.Empty : item.DataClass; | ||
| var className = kind.Contains("Class 1", StringComparison.OrdinalIgnoreCase) ? "CLASS 1" : | ||
| kind.Contains("Class 2", StringComparison.OrdinalIgnoreCase) ? "CLASS 2" : "REQUESTED CLASS"; | ||
| if (link is not null) | ||
| { | ||
| var flags = link.Prm | ||
| ? $"PRM=1, FCB={Bit(link.Fcb)}, FCV={Bit(link.Fcv)}, FC={link.FunctionCode}" | ||
| : $"PRM=0, ACD={Bit(link.Acd)}, DFC={Bit(link.Dfc)}, FC={link.FunctionCode}"; | ||
|
|
||
| if (link.Prm && link.FunctionCode is 10 or 11) | ||
| { | ||
| var requested = link.FunctionCode == 10 ? "CLASS 1" : "CLASS 2"; | ||
| return ($"{prefix} {requested} REQUEST · {dlText}", | ||
| $"Master requests {requested} queued data from RTU · [{flags}]."); | ||
| } | ||
|
|
||
| if (!link.Prm && link.FunctionCode == 9) | ||
| { | ||
| var classText = className == "REQUESTED CLASS" ? "REQUESTED DATA" : $"{className} DATA"; | ||
| var queued = link.Acd == true | ||
| ? "CLASS 1 AVAILABLE (ACD=1); master should request Class 1" | ||
| : "No Class 1 availability signaled by ACD"; | ||
| var busy = link.Dfc == true ? " · RTU flow control busy (DFC=1)" : string.Empty; | ||
| return ($"{prefix} {classText} NOT AVAILABLE · {dlText}", | ||
| $"No requested data returned · {queued}{busy} · [{flags}]. This is a link response, not a process failure."); | ||
| } | ||
|
|
||
| if (!link.Prm && link.FunctionCode == 8) | ||
| { | ||
| var asdu = item.AsduDetails; | ||
| var type = asdu?.TypeName ?? item.TypeName; | ||
| if (string.IsNullOrWhiteSpace(type)) type = "ASDU"; | ||
| var cause = asdu?.CotDisplay ?? (item.CauseOfTransmission.HasValue | ||
| ? $"{item.CauseOfTransmission.Value} · {item.CauseName}" : "COT unknown"); | ||
| var ca = asdu?.CommonAddress ?? item.CommonAddressNumber; | ||
| var first = item.InformationObjectDetails ?? asdu?.FirstObject; | ||
| var objectCount = asdu?.Objects.Count ?? item.ObjectCount ?? 0; | ||
| var details = $"ASDU Type {asdu?.TypeId ?? item.TypeId}: {type}; COT {cause}; CA={ca?.ToString() ?? "?"}; " + | ||
| $"objects={objectCount}; [{flags}]"; | ||
| if (first is not null) | ||
| { | ||
| details += $"; IOA {first.InformationObjectAddress}={first.ShortValue}"; | ||
| if (first.QualityDetails is not null) details += $"; Quality={first.QualityDetails.DisplayText}"; | ||
| if (!string.IsNullOrWhiteSpace(first.TimestampText)) details += $"; RTU time={first.TimestampText}"; | ||
| } | ||
| if (link.Acd == true) details += "; additional Class 1 data indicated"; | ||
| return ($"{prefix} RTU USER DATA · {type} · {dlText}", details + "."); | ||
| } | ||
|
|
||
| if (!link.Prm && link.FunctionCode == 0) | ||
| return ($"{prefix} LINK ACK · {dlText}", | ||
| $"RTU acknowledged the link-layer request · [{flags}]. This does not prove application or physical command success."); | ||
|
|
||
| if (!link.Prm && link.FunctionCode == 1) | ||
| return ($"{prefix} LINK NACK · {dlText}", | ||
| $"RTU reported negative link confirmation · [{flags}]. Check the preceding request and link state."); | ||
|
|
||
| if (link.Prm && link.FunctionCode == 0) | ||
| return ($"{prefix} RESET REMOTE LINK · {dlText}", | ||
| $"Master requests link reset · [{flags}]. Await RTU link response."); | ||
| if (link.Prm && link.FunctionCode == 9) | ||
| return ($"{prefix} LINK STATUS REQUEST · {dlText}", | ||
| $"Master requests link status · [{flags}]."); | ||
| if (!link.Prm && link.FunctionCode == 11) | ||
| return ($"{prefix} LINK STATUS RESPONSE · {dlText}", | ||
| $"RTU reports link status · [{flags}]."); | ||
| if (item.AsduDetails is not null) | ||
| { | ||
| var asdu = item.AsduDetails; | ||
| return ($"{prefix} {asdu.TypeName} · {dlText}", | ||
| $"ASDU Type {asdu.TypeId}, COT {asdu.CotDisplay}, CA={asdu.CommonAddress}, " + | ||
| $"objects={asdu.Objects.Count} · [{flags}]. {asdu.ShortMeaning}"); | ||
| } | ||
| return ($"{prefix} {link.FunctionName.ToUpperInvariant()} · {dlText}", | ||
| $"Link function FC={link.FunctionCode} · [{flags}]."); | ||
| } | ||
|
|
||
| if (item.Frame?.IsSingleCharacterAck == true) | ||
| return ($"{prefix} E5 SHORT RESPONSE", | ||
| "IEC-101 E5 short response: meaning depends on the matched link request. " + | ||
| "It must not be presented as proof that an application command succeeded."); | ||
|
|
||
| if (item.Frame?.IsSingleCharacterNack == true) | ||
| return ($"{prefix} A2 INVALID IEC-101 RESPONSE", | ||
| "A2 single-character response is not permitted in IEC-101. Keep original bytes for investigation."); | ||
|
|
||
| if (item.Frame is { IsChecksumValid: false }) | ||
| return ($"{prefix} INVALID FT1.2 FRAME", "Checksum/format invalid or incomplete; consult exact raw bytes."); | ||
|
|
||
| return ($"{prefix} IEC-101 FRAME", | ||
| string.IsNullOrWhiteSpace(item.ProtocolMeaning) ? item.Summary : item.ProtocolMeaning); | ||
| } | ||
|
|
||
| private static string Bit(bool? value) => value is null ? "?" : value.Value ? "1" : "0"; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For checksum-invalid IEC-101 frames that still have a decoded control byte, every path inside
if (link is not null)returns before this integrity check. BothFt12Parserand the passive monitor populateLinkControlfor such frames, so a corrupted FC0 or FC9 is now displayed as an ordinary LINK ACK or DATA NOT AVAILABLE response, replacing the previous quality warning inProtocolTraceMeaning. This hides relevant line-fault evidence during passive capture and replay. Check checksum and format validity before interpreting link functions, or explicitly retain the integrity warning alongside the tentative interpretation.Useful? React with 👍 / 👎.