diff --git a/internal/module/m9zTtyApi/read.go b/internal/module/m9zTtyApi/read.go index d8d62ad..6bce7db 100644 --- a/internal/module/m9zTtyApi/read.go +++ b/internal/module/m9zTtyApi/read.go @@ -158,8 +158,9 @@ func getDeviceStatus2Real(rpc towgo.JsonRpcConnection) { d.DeviceStatus = *read scanLoopCount := configuredLoopCount() displayLoopCount := monitorDisplayLoopCount() + alarmDisplayEnabled := scanConfigManager.GetAlarmDisplayEnabled() d.ScanDeviceCount = scanLoopCount - d.AlarmDisplayEnabled = scanConfigManager.GetAlarmDisplayEnabled() + d.AlarmDisplayEnabled = alarmDisplayEnabled loops := make([]DeviceStatusLoop, displayLoopCount) var wg sync.WaitGroup for i := 0; i < displayLoopCount; i++ { @@ -178,7 +179,7 @@ func getDeviceStatus2Real(rpc towgo.JsonRpcConnection) { loop.A = parametersRead.DCCurrent kw := float64(loop.V*loop.A) / 1000 loop.Kw = float32(math.Round(kw*1000) / 1000) - if idx < scanLoopCount { + if alarmDisplayEnabled && idx < scanLoopCount { loop.Faults = m9z.BuildLoopFaults(uint(idx+1), parametersRead.AlarmStatus, parametersRead.AlarmCode) loop.HasFault = len(loop.Faults) > 0 loop.FaultMsg = joinLoopFaultMessages(loop.Faults) @@ -196,7 +197,7 @@ func getDeviceStatus2Real(rpc towgo.JsonRpcConnection) { return d.Loops[i].Index < d.Loops[j].Index }) for _, loop := range d.Loops { - if loop.HasFault && loop.Index < scanLoopCount { + if alarmDisplayEnabled && loop.HasFault && loop.Index < scanLoopCount { recordLoopFaults(cuid, uint(loop.Index+1), loop.V, loop.Faults) } } @@ -207,9 +208,10 @@ func getDeviceStatus2Real(rpc towgo.JsonRpcConnection) { func buildDemoDeviceStatus2() *DeviceStatus { displayLoopCount := monitorDisplayLoopCount() scanLoopCount := configuredLoopCount() + alarmDisplayEnabled := scanConfigManager.GetAlarmDisplayEnabled() d := &DeviceStatus{ ScanDeviceCount: scanLoopCount, - AlarmDisplayEnabled: scanConfigManager.GetAlarmDisplayEnabled(), + AlarmDisplayEnabled: alarmDisplayEnabled, Loops: make([]DeviceStatusLoop, displayLoopCount), } d.Mode = 0 @@ -233,7 +235,7 @@ func buildDemoDeviceStatus2() *DeviceStatus { kw := float64(loop.V*loop.A) / 1000 loop.Kw = float32(math.Round(kw*1000) / 1000) - if i < scanLoopCount { + if alarmDisplayEnabled && i < scanLoopCount { switch i { case 0: loop.Faults = m9z.BuildLoopFaults(uint(i+1), 0x01, "01 00") diff --git a/internal/module/m9zTtyApi/scan_test.go b/internal/module/m9zTtyApi/scan_test.go index 1ddef15..ccd88a8 100644 --- a/internal/module/m9zTtyApi/scan_test.go +++ b/internal/module/m9zTtyApi/scan_test.go @@ -76,4 +76,9 @@ func TestBuildDemoDeviceStatus2IncludesAlarmDisplayConfig(t *testing.T) { if status.AlarmDisplayEnabled { t.Fatal("status.AlarmDisplayEnabled = true, want false") } + for _, loop := range status.Loops { + if loop.HasFault || loop.FaultMsg != "" || len(loop.Faults) > 0 { + t.Fatalf("loop %d still has fault data when alarm display disabled", loop.Index) + } + } }