diff --git a/LFP_Manager/DataStructure/csDataStructure.cs b/LFP_Manager/DataStructure/csDataStructure.cs index b166057..b0a3ce7 100644 --- a/LFP_Manager/DataStructure/csDataStructure.cs +++ b/LFP_Manager/DataStructure/csDataStructure.cs @@ -23,7 +23,7 @@ namespace LFP_Manager.DataStructure public int UartModelIndex; public int UartProtocol; - public int CommFailTime; + public int CommFailMaxCount; public int DbLogPeriod; @@ -49,7 +49,7 @@ namespace LFP_Manager.DataStructure UartProtocol = 0; RecvWaitTime = 1500; // 1500ms - CommFailTime = 5000; // 5000ms + CommFailMaxCount = 5; // 5 times DbLogPeriod = 5; diff --git a/LFP_Manager/Function/csIniControlFunction.cs b/LFP_Manager/Function/csIniControlFunction.cs index 60914bb..470129b 100644 --- a/LFP_Manager/Function/csIniControlFunction.cs +++ b/LFP_Manager/Function/csIniControlFunction.cs @@ -106,7 +106,7 @@ namespace LFP_Manager.Function rConfig.RecvWaitTime = (int)csIniControlFunction.GetPrivateProfileInt("UART", "RECV_WAIT_TIME", 1500, InIPath); // COMM FAIL TIME OUT - rConfig.CommFailTime = (int)csIniControlFunction.GetPrivateProfileInt("UART", "COMM_FAIL_TIME", 5000, InIPath); + rConfig.CommFailMaxCount = (int)csIniControlFunction.GetPrivateProfileInt("UART", "COMM_FAIL_COUNT", 5, InIPath); // Etc. Config rConfig.DbLogPeriod = (int)csIniControlFunction.GetPrivateProfileInt("DATABASE", "LOG_PERIOD", 1, InIPath); @@ -147,7 +147,7 @@ namespace LFP_Manager.Function rConfig.UartProtocol= 0; rConfig.RecvWaitTime = 1500; - rConfig.CommFailTime = 5000; + rConfig.CommFailMaxCount = 5; rConfig.DbLogPeriod = 5; @@ -187,8 +187,8 @@ namespace LFP_Manager.Function // RECV_WAIT_TIME WritePrivateProfileString("UART", "RECV_WAIT_TIME", aConfig.RecvWaitTime.ToString(), InIPath); - // COMM_FAIL_TIME - WritePrivateProfileString("UART", "COMM_FAIL_TIME", aConfig.CommFailTime.ToString(), InIPath); + // COMM_FAIL_COUNT + WritePrivateProfileString("UART", "COMM_FAIL_COUNT", aConfig.CommFailMaxCount.ToString(), InIPath); // Etc Config WritePrivateProfileString("DATABASE", "LOG_PERIOD", aConfig.DbLogPeriod.ToString(), InIPath); diff --git a/LFP_Manager/Threads/CsUartThreadSB.cs b/LFP_Manager/Threads/CsUartThreadSB.cs index 28a063a..7fa93bf 100644 --- a/LFP_Manager/Threads/CsUartThreadSB.cs +++ b/LFP_Manager/Threads/CsUartThreadSB.cs @@ -463,8 +463,9 @@ namespace LFP_Manager.Threads private void uartCommThreadSB(CancellationToken token) { int RecvTimeout = Config.RecvWaitTime; - int COMM_TIMEOUT_MS = Config.CommFailTime; // 5초 동안 수신 없으면 Fail + int COMM_TIMEOUT_MAX_COUNT = (Config.CommFailMaxCount > 100) ? 5 : Config.CommFailMaxCount; // 5초 동안 수신 없으면 Fail DateTime[] LastReceiveTime = new DateTime[csConstData.SystemInfo.MAX_MODULE_SIZE]; + int[] RecvTimeoutCount = new int[csConstData.SystemInfo.MAX_MODULE_SIZE]; // ★ 마지막 수신 시간 초기화 (현재 시각 기준) var now = DateTime.UtcNow; @@ -532,8 +533,9 @@ namespace LFP_Manager.Threads { // 마지막 정상 업데이트 시간 기록 LastReceiveTime[mID] = DateTime.UtcNow; + RecvTimeoutCount[mID] = 0; - ModuleData[mID].CommFail = false; + ModuleData[mID].mNo = mID + 1; ModuleData[mID].ShelfCommFail = false; var rc = CsSerialCommFunctionDelta.SerialRxProcess( ReadBuf, RequestRegAddr, (ushort)rPosition, ref ModuleData[mID]); @@ -576,25 +578,26 @@ namespace LFP_Manager.Threads { int idx = csUtils.MathEx.Clamp(ModuleID - 1, 0, csConstData.SystemInfo.MAX_MODULE_SIZE - 1); + RecvTimeoutCount[idx]++; // 아직 한 번도 정상 수신한 적 없는 경우 MinValue일 수 있으므로, // 첫 타임아웃에서는 기준 시간을 현재로 초기화해 준다. if (LastReceiveTime[idx] == DateTime.MinValue) LastReceiveTime[idx] = DateTime.UtcNow; // 시간 차이 계산 - var elapsed = (DateTime.Now - LastReceiveTime[idx]).TotalMilliseconds; + var elapsed = (DateTime.UtcNow - LastReceiveTime[idx]).TotalMilliseconds; - if (elapsed >= COMM_TIMEOUT_MS) + if (RecvTimeoutCount[idx] >= COMM_TIMEOUT_MAX_COUNT) + //if (elapsed >= COMM_TIMEOUT_MS) { + RecvTimeoutCount[idx] = 5; // Fail 처리 if (!ModuleData[idx].ShelfCommFail) { ModuleData[idx].Reset(); + ModuleData[idx].mNo = ModuleID; ModuleData[idx].ShelfCommFail = true; } - - ModuleData[idx].CommFail = true; - ModuleData[idx].ShelfCommFail = true; } Thread.Sleep(100); } diff --git a/LFP_Manager/Threads/csDbThread.cs b/LFP_Manager/Threads/csDbThread.cs index 8b5c859..3681b97 100644 --- a/LFP_Manager/Threads/csDbThread.cs +++ b/LFP_Manager/Threads/csDbThread.cs @@ -492,11 +492,11 @@ namespace LFP_Manager.Threads DateTime now = DateTime.Now; // 시스템 통신 상태 변화 기록 - if (oModule.CommFail != nModule.CommFail) + if (oModule.ShelfCommFail != nModule.ShelfCommFail) { eventFlag |= BmsAlarmDataInsert(modelName, (int)DbConstData.Alarm.COMM_FAIL, - nModule.CommFail ? (int)DbConstData.Flag.WARNING : (int)DbConstData.Flag.RELEASE, nModule, now); - oModule.CommFail = nModule.CommFail; + nModule.ShelfCommFail ? (int)DbConstData.Flag.WARNING : (int)DbConstData.Flag.RELEASE, nModule, now); + oModule.ShelfCommFail = nModule.ShelfCommFail; } // 0..15 비트에 대한 경고/보호 엣지 검사 for (int i = 0; i < 16; i++)