-
Notifications
You must be signed in to change notification settings - Fork 3
Fix FAT Clock Sync control and immediate TRUE evidence #150
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
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e7b7273
feat: add operator clock sync toggle lifecycle
masarray b68a684
feat: expose clock sync checkbox in FAT workspace
masarray dfe3354
fix: process FAT evidence before UI render
masarray c532777
test: guard immediate TRUE evidence publication
masarray 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,89 @@ | ||
| using System.Windows; | ||
| using System.Windows.Controls; | ||
| using System.Windows.Media; | ||
|
|
||
| namespace ArIED61850Tester; | ||
|
|
||
| public partial class IoListTestingWindow | ||
| { | ||
| private CheckBox? _clockSyncCheckBox; | ||
| private bool _clockSyncCheckBoxRefreshing; | ||
|
|
||
| protected override void OnInitialized(EventArgs e) | ||
| { | ||
| base.OnInitialized(e); | ||
| Loaded += ClockSyncUx_Loaded; | ||
| } | ||
|
|
||
| private void ClockSyncUx_Loaded(object sender, RoutedEventArgs e) | ||
| { | ||
| if (_clockSyncCheckBox != null) | ||
| { | ||
| RefreshClockSyncCheckBox(); | ||
| return; | ||
| } | ||
|
|
||
| if (WorkspacePreviewToggle.Parent is not Panel actionPanel) | ||
| return; | ||
|
|
||
| var previewIndex = actionPanel.Children.IndexOf(WorkspacePreviewToggle); | ||
| if (previewIndex < 0) | ||
| return; | ||
|
|
||
| var checkBox = new CheckBox | ||
| { | ||
| Name = "ClockSyncEnabledCheckBox", | ||
| Content = "Clock Sync", | ||
| VerticalAlignment = VerticalAlignment.Center, | ||
| Margin = new Thickness(0, 0, 12, 0), | ||
| Padding = new Thickness(2, 0, 2, 0), | ||
| FontSize = 11.2, | ||
| FontWeight = FontWeights.SemiBold, | ||
| Foreground = TryFindResource("Ink") as Brush ?? Brushes.DimGray, | ||
| Focusable = false, | ||
| ToolTip = "SNTP laptop → IED. Checked: ARSAS serves and broadcasts laptop time using the SIPROTEC compatibility profile (stratum 2). Unchecked: ARSAS stops its SNTP service. IEC 61850 monitoring is unaffected." | ||
| }; | ||
|
|
||
| _clockSyncCheckBox = checkBox; | ||
| RefreshClockSyncCheckBox(); | ||
| checkBox.Checked += ClockSyncCheckBox_Changed; | ||
| checkBox.Unchecked += ClockSyncCheckBox_Changed; | ||
| actionPanel.Children.Insert(previewIndex + 1, checkBox); | ||
| } | ||
|
|
||
| private void RefreshClockSyncCheckBox() | ||
| { | ||
| if (_clockSyncCheckBox == null || Owner is not MainWindow mainWindow) | ||
| return; | ||
|
|
||
| _clockSyncCheckBoxRefreshing = true; | ||
| try | ||
| { | ||
| _clockSyncCheckBox.IsChecked = mainWindow.IsClockSyncEnabled; | ||
| } | ||
| finally | ||
| { | ||
| _clockSyncCheckBoxRefreshing = false; | ||
| } | ||
| } | ||
|
|
||
| private async void ClockSyncCheckBox_Changed(object sender, RoutedEventArgs e) | ||
| { | ||
| if (_clockSyncCheckBoxRefreshing || | ||
| _clockSyncCheckBox == null || | ||
| Owner is not MainWindow mainWindow) | ||
| return; | ||
|
|
||
| var requested = _clockSyncCheckBox.IsChecked == true; | ||
| _clockSyncCheckBox.IsEnabled = false; | ||
| try | ||
| { | ||
| await mainWindow.SetClockSyncEnabledAsync(requested); | ||
| RefreshClockSyncCheckBox(); | ||
| } | ||
| finally | ||
| { | ||
| _clockSyncCheckBox.IsEnabled = true; | ||
| } | ||
| } | ||
| } |
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,53 @@ | ||
| using ArIED61850Tester.Models; | ||
|
|
||
| namespace ArIED61850Tester; | ||
|
|
||
| public partial class MainWindow | ||
| { | ||
| private bool _clockSyncEnabled = true; | ||
|
|
||
| internal bool IsClockSyncEnabled => _clockSyncEnabled; | ||
|
|
||
| internal async Task SetClockSyncEnabledAsync(bool enabled) | ||
| { | ||
| if (_clockSyncEnabled == enabled) | ||
| return; | ||
|
|
||
| _clockSyncEnabled = enabled; | ||
|
|
||
| if (!enabled) | ||
| { | ||
| Devices.CollectionChanged -= ClockSyncDevices_CollectionChanged; | ||
| foreach (var device in Devices) | ||
| device.PropertyChanged -= ClockSyncDevice_PropertyChanged; | ||
|
|
||
| await _clockSyncIntegrationGate.WaitAsync(); | ||
| try | ||
| { | ||
| await _sntpClockService.StopAsync(); | ||
| _clockSyncObservedClients.Clear(); | ||
| AddLog("INFO", "Clock Sync", | ||
| "Clock Sync disabled from the FAT workspace. IEC 61850 monitoring remains active."); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| AddLog("WARN", "Clock Sync", | ||
| $"Clock Sync disable requested, but the SNTP service reported: {ex.Message}"); | ||
| } | ||
| finally | ||
| { | ||
| _clockSyncIntegrationGate.Release(); | ||
| } | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| Devices.CollectionChanged -= ClockSyncDevices_CollectionChanged; | ||
| Devices.CollectionChanged += ClockSyncDevices_CollectionChanged; | ||
| foreach (var device in Devices) | ||
| AttachClockSyncDevice(device); | ||
|
|
||
| AddLog("INFO", "Clock Sync", | ||
| "Clock Sync enabled from the FAT workspace. ARSAS will advertise laptop time to connected IPv4 IEDs using the SIPROTEC-compatible SNTP profile."); | ||
| } | ||
| } | ||
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
64 changes: 64 additions & 0 deletions
64
tests/ARSAS.Tests/IoFatImmediateEvidenceRegressionTests.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,64 @@ | ||
| using System.ComponentModel; | ||
| using ArIED61850Tester.Models.IoTesting; | ||
| using ArIED61850Tester.Services.IoTesting; | ||
|
|
||
| namespace ARSAS.Tests; | ||
|
|
||
| public sealed class IoFatImmediateEvidenceRegressionTests | ||
| { | ||
| [Fact] | ||
| public void TrueEdge_PublishesOnTimestampBeforeFalseEdgeArrives() | ||
| { | ||
| var evaluator = new IoTestTransitionEvaluator(); | ||
| var point = CreatePoint(); | ||
| var onTimestampNotificationRaised = false; | ||
|
|
||
| point.Runtime.PropertyChanged += (_, args) => | ||
| { | ||
| if (args.PropertyName == nameof(IoTestPointRuntime.OnRelayTimestampText)) | ||
| onTimestampNotificationRaised = true; | ||
| }; | ||
|
|
||
| evaluator.StartAttempt(point, Observation(false, 1)); | ||
| var on = evaluator.Observe(point, Observation(true, 2)); | ||
|
|
||
| Assert.Equal(IoTestPointState.OnCaptured, on.State); | ||
| Assert.NotNull(point.Runtime.OnEvidence); | ||
| Assert.Null(point.Runtime.OffEvidence); | ||
| Assert.Equal( | ||
| point.Runtime.OnEvidence!.IedTimestamp?.ToString("yyyy-MM-dd HH:mm:ss.fff"), | ||
| point.Runtime.OnRelayTimestampText); | ||
| Assert.NotEqual("—", point.Runtime.OnRelayTimestampText); | ||
| Assert.True(onTimestampNotificationRaised); | ||
| } | ||
|
|
||
| private static IoTestPointPlan CreatePoint() | ||
| => new() | ||
| { | ||
| TestPointId = "TRUE-EVIDENCE-REGRESSION", | ||
| IedName = "SIPROTEC", | ||
| IpAddress = "192.168.1.10", | ||
| SignalName = "Protection pickup", | ||
| ObjectReference = "SIPROTEC/PROT.Op.general", | ||
| FunctionalConstraint = "ST", | ||
| ExpectedOnText = "true", | ||
| ExpectedOffText = "false", | ||
| ImportReady = true, | ||
| BindingStatus = "CID_DATASET_EXACT" | ||
| }; | ||
|
|
||
| private static IoTestObservation Observation(bool state, long sequence) | ||
| { | ||
| var captured = new DateTimeOffset(2026, 8, 13, 4, 55, 0, TimeSpan.Zero) | ||
| .AddMilliseconds(sequence * 100); | ||
| return new IoTestObservation( | ||
| state, | ||
| state ? "true" : "false", | ||
| captured, | ||
| captured.AddMilliseconds(-4), | ||
| "Good", | ||
| "BRCB", | ||
| sequence, | ||
| 1); | ||
| } | ||
| } |
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.
If
IsConnectedchanges on a runtime thread just before these handlers are removed,ClockSyncDevice_PropertyChangedmay already be enqueuingScheduleClockSyncReconcileon the dispatcher. While this method awaitsStopAsync, that queued reconcile can wait behind_clockSyncIntegrationGateand then restart the SNTP service after the stop completes, because neither scheduling norEnsureClockSyncForDeviceAsyncchecks_clockSyncEnabled. In that race, the unchecked control continues serving and broadcasting time; recheck the enabled state after dispatching and after acquiring the gate, or cancel pending reconciles.Useful? React with 👍 / 👎.