From 3e6cf9d277d79b48915bacc40f5c9b2dcf624022 Mon Sep 17 00:00:00 2001 From: wangqiyang Date: Tue, 11 Aug 2026 10:05:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=B3=E9=97=AD=E5=AE=9E=E6=97=B6=E6=8A=A5?= =?UTF-8?q?=E8=AD=A6=E6=98=BE=E7=A4=BA=E6=97=B6=E5=B1=8F=E8=94=BD=E6=95=85?= =?UTF-8?q?=E9=9A=9C=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/module/m9zTtyApi/read.go | 12 +++++++----- internal/module/m9zTtyApi/scan_test.go | 5 +++++ 2 files changed, 12 insertions(+), 5 deletions(-) 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) + } + } }