|
@@ -1,4 +1,4 @@
|
|
|
-// CCOS.Dev.GEN.HaoWei.cpp : 定义 DLL 应用程序的导出函数。
|
|
|
+// CCOS.Dev.GEN.HaoWei.cpp : 瀹氫箟 DLL 搴旂敤绋嬪簭鐨勫�鍑哄嚱鏁般€�
|
|
|
//
|
|
|
|
|
|
#include <assert.h>
|
|
@@ -26,7 +26,7 @@ static const auto TCP_SCFDllName = "libTcpipSCF.so";
|
|
|
// HaoWeiDevice
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
-// 储存的点值
|
|
|
+// 鍌ㄥ瓨鐨勭偣鍊�
|
|
|
std::vector<int> R10_MA = { 100, 125, 160, 200, 250, 320, 400, 500, 630, 800, 1000, 1250, 1600, 2000, 2500, 3200, 4000, 5000, 6300, 8000, 10000 };
|
|
|
std::vector<int> R10_MS = { 10, 12, 16, 20, 25, 32, 40, 50, 63, 80, 100, 125, 160, 200, 250, 320, 400, 500, 630, 800, 1000, 1250, 1600, 2000, 2500, 3200, 4000, 5000, 6300, 8000, 10000, 12500, 16000, 20000, 25000, 32000, 40000, 50000, 63000, 80000, 100000 };
|
|
|
std::vector<int> R10_MAS = { 10, 12, 16, 20, 25, 32, 40, 50, 63, 80, 100, 125, 160, 200, 250, 320, 400, 500, 630, 800, 1000, 1250, 1600, 2000, 2500, 3200, 4000, 5000, 6300, 8000, 10000, 12500, 16000, 20000, 25000, 32000, 40000, 50000, 63000, 80000, 100000 };
|
|
@@ -35,8 +35,9 @@ std::vector<int> R20_MS = { 10, 11, 12, 14, 16, 18, 20, 22, 25, 28, 32, 36, 40,
|
|
|
std::vector<int> R20_MAS = { 10, 11, 12, 14, 16, 18, 20, 22, 25, 28, 32, 36, 40, 45, 50, 56, 63, 71, 80, 90, 100, 110, 125, 140, 160, 180, 200, 220, 250, 280, 320, 360, 400, 450, 500, 560, 630, 710, 800, 900, 1000, 1100, 1250, 1400, 1600, 1800, 2000, 2200, 2500, 2800, 3200, 3600, 4000, 4500, 5000, 5600, 6300, 7100, 8000, 9000, 10000, 11000, 12500, 14000, 16000, 18000, 20000, 22000, 25000, 28000, 32000, 36000, 40000, 45000, 50000, 56000, 63000, 71000, 80000, 90000, 100000 };
|
|
|
|
|
|
atomic<int> nsGEN::HaoWeiDevice::m_iLoopTime = HaoWei_LoopDefTime;
|
|
|
+atomic<bool> nsGEN::HaoWeiDevice::m_bExtraFlag = false; // 瀹氫箟闈欐€佹垚鍛樺彉閲�
|
|
|
std::atomic<std::chrono::steady_clock::time_point> lastValidResponse;
|
|
|
-constexpr auto TIMEOUT = std::chrono::seconds(12); // 超时阈值
|
|
|
+constexpr auto TIMEOUT = std::chrono::seconds(12); // 瓒呮椂闃堝€�
|
|
|
|
|
|
nsGEN::HaoWeiDevice::HaoWeiDevice(std::shared_ptr <IOEventCenter> center, std::shared_ptr<SCFWrapper> SCF, string configfile)
|
|
|
: super(center)
|
|
@@ -91,8 +92,8 @@ nsGEN::HaoWeiDevice::HaoWeiDevice(std::shared_ptr <IOEventCenter> center, std::s
|
|
|
m_DoseUnit.m_DoseLevel.reset(new FLUDoseLevelMould(0, 0, 2, 1));
|
|
|
m_DoseUnit.m_Curve.reset(new FLUCurveMould(0, 0, 3, 1));
|
|
|
|
|
|
- string strErrConfig = GetProcessDirectory() + R"(\OEMDrivers\Generator\HaoWei\ErrorWarnInfo.json)";
|
|
|
- m_DeviceErrorHandler.reset(new DeviceErrorHandler(center, nsGEN::GeneratorUnitType, strErrConfig));
|
|
|
+ /*string strErrConfig = GetProcessDirectory() + R"(\OEMDrivers\Generator\HaoWei\ErrorWarnInfo.json)";
|
|
|
+ m_DeviceErrorHandler.reset(new DeviceErrorHandler(center, nsGEN::GeneratorUnitType, strErrConfig));*/
|
|
|
|
|
|
OnCallBack();
|
|
|
|
|
@@ -195,11 +196,10 @@ RET_STATUS nsGEN::HaoWeiDevice::IncMA()
|
|
|
{
|
|
|
FINFO("MA value before calling IncMA: {$}\n", m_DoseUnit.m_MA->JSGet().c_str());
|
|
|
//if (!m_DoseUnit.m_MA->CanInc()) return RET_STATUS::RET_SUCCEED;
|
|
|
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
|
|
|
- {
|
|
|
- FINFO("\n Techmode is MAS, can't inc MA");
|
|
|
+
|
|
|
+ if (!IsMAMSOperationAllowed("inc MA"))
|
|
|
return RET_STATUS::RET_FAILED;
|
|
|
- }
|
|
|
+
|
|
|
return HWSend("MA+");
|
|
|
}
|
|
|
|
|
@@ -208,11 +208,9 @@ RET_STATUS nsGEN::HaoWeiDevice::DecMA()
|
|
|
FINFO("MA value before calling DecMA: {$}\n", m_DoseUnit.m_MA->JSGet().c_str());
|
|
|
//if (!m_DoseUnit.m_MA->CanDec()) return RET_STATUS::RET_SUCCEED;
|
|
|
|
|
|
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
|
|
|
- {
|
|
|
- FINFO("\n Techmode is MAS, can't dec MA");
|
|
|
+ if (!IsMAMSOperationAllowed("dec MA"))
|
|
|
return RET_STATUS::RET_FAILED;
|
|
|
- }
|
|
|
+
|
|
|
return HWSend("MA-");
|
|
|
}
|
|
|
|
|
@@ -238,17 +236,15 @@ RET_STATUS nsGEN::HaoWeiDevice::IncMS()
|
|
|
{
|
|
|
FINFO("MS value before calling IncMS: {$}\n", m_DoseUnit.m_MS->JSGet().c_str());
|
|
|
/*if (!m_DoseUnit.m_MS->CanInc())
|
|
|
- {
|
|
|
+ {
|
|
|
int Level = 1;
|
|
|
m_MSGUnit->AddWarnMessage("HaoWei_WARN", Level, "Generator MS Limit");
|
|
|
return RET_STATUS::RET_SUCCEED;
|
|
|
}*/
|
|
|
|
|
|
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
|
|
|
- {
|
|
|
- FINFO("\n Techmode is MAS, can't inc MS");
|
|
|
+ if (!IsMAMSOperationAllowed("inc MS"))
|
|
|
return RET_STATUS::RET_FAILED;
|
|
|
- }
|
|
|
+
|
|
|
return HWSend("MS+");
|
|
|
}
|
|
|
|
|
@@ -257,11 +253,9 @@ RET_STATUS nsGEN::HaoWeiDevice::DecMS()
|
|
|
FINFO("MS value before calling DecMS: {$}\n", m_DoseUnit.m_MS->JSGet().c_str());
|
|
|
//if (!m_DoseUnit.m_MS->CanDec()) return RET_STATUS::RET_SUCCEED;
|
|
|
|
|
|
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
|
|
|
- {
|
|
|
- FINFO("\n Techmode is MAS, can't dec MS");
|
|
|
+ if (!IsMAMSOperationAllowed("dec MS"))
|
|
|
return RET_STATUS::RET_FAILED;
|
|
|
- }
|
|
|
+
|
|
|
return HWSend("MS-");
|
|
|
}
|
|
|
|
|
@@ -287,17 +281,17 @@ RET_STATUS nsGEN::HaoWeiDevice::IncMAS()
|
|
|
{
|
|
|
FINFO("MAS value before calling IncMAS: {$}\n", m_DoseUnit.m_MAS->JSGet().c_str());
|
|
|
//if (!m_DoseUnit.m_MAS->CanInc()) return RET_STATUS::RET_SUCCEED;
|
|
|
+
|
|
|
if (!m_DoseUnit.m_MS->CanInc())
|
|
|
{
|
|
|
int Level = 1;
|
|
|
m_MSGUnit->AddWarnMessage("HaoWei_WARN", Level, "Generator MS Limit");
|
|
|
return RET_STATUS::RET_SUCCEED;
|
|
|
}
|
|
|
- if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS)
|
|
|
- {
|
|
|
- FINFO("\n Techmode is not MAS, can't inc MAS");
|
|
|
+
|
|
|
+ if (!IsMASOperationAllowed("inc MAS"))
|
|
|
return RET_STATUS::RET_FAILED;
|
|
|
- }
|
|
|
+
|
|
|
return HWSend("MX+");
|
|
|
}
|
|
|
|
|
@@ -306,11 +300,9 @@ RET_STATUS nsGEN::HaoWeiDevice::DecMAS()
|
|
|
FINFO("MAS value before calling DecMAS: {$}\n", m_DoseUnit.m_MAS->JSGet().c_str());
|
|
|
//if (!m_DoseUnit.m_MAS->CanDec()) return RET_STATUS::RET_SUCCEED;
|
|
|
|
|
|
- if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS)
|
|
|
- {
|
|
|
- FINFO("\n Techmode is not MAS, can't dec MAS");
|
|
|
+ if (!IsMASOperationAllowed("dec MAS"))
|
|
|
return RET_STATUS::RET_FAILED;
|
|
|
- }
|
|
|
+
|
|
|
return HWSend("MX-");
|
|
|
}
|
|
|
|
|
@@ -554,10 +546,10 @@ int CCOS::Dev::Detail::Generator::HaoWeiDevice::GetGenState()
|
|
|
int CCOS::Dev::Detail::Generator::HaoWeiDevice::LoadConfig(string configfile)
|
|
|
{
|
|
|
FINFO("=====================LoadConfig=========================");
|
|
|
- // 检查文件是否存在
|
|
|
+ // 妫€鏌ユ枃浠舵槸鍚﹀瓨鍦�
|
|
|
std::ifstream file(configfile);
|
|
|
if (!file) {
|
|
|
- // 文件不存在,直接返回空的Connection对象
|
|
|
+ // 鏂囦欢涓嶅瓨鍦�紝鐩存帴杩斿洖绌虹殑Connection瀵硅薄
|
|
|
FINFO("Config file does not exist: {$}", configfile.c_str());
|
|
|
return -1;
|
|
|
}
|
|
@@ -852,17 +844,17 @@ RET_STATUS nsGEN::HaoWeiDevice::GetABSCurve()
|
|
|
|
|
|
float nsGEN::HaoWeiDevice::GetFluIntTimer()
|
|
|
{
|
|
|
- return RET_STATUS::RET_SUCCEED;
|
|
|
+ return m_DoseUnit.m_FLIntTime->Get();
|
|
|
}
|
|
|
|
|
|
float nsGEN::HaoWeiDevice::GetFluAccTimer()
|
|
|
{
|
|
|
- return RET_STATUS::RET_SUCCEED;
|
|
|
+ return m_DoseUnit.m_FLAccTime->Get();
|
|
|
}
|
|
|
|
|
|
RET_STATUS nsGEN::HaoWeiDevice::ResetFluTimer(int ntype)
|
|
|
{
|
|
|
- FINFO("ReSetFluAccTimer:[{$}] \n", ntype);
|
|
|
+ FINFO("ReSetFluAccTimer锛歔{$}] \n", ntype);
|
|
|
return HWSend("FTC");
|
|
|
}
|
|
|
|
|
@@ -1000,41 +992,65 @@ RET_STATUS nsGEN::HaoWeiDevice::Reset()
|
|
|
{
|
|
|
m_bResetActive = true;
|
|
|
FINFO("RESET in...\n");
|
|
|
- return HWSend("CLR0");
|
|
|
+
|
|
|
+ // 娓呴櫎閿欒�鍜岃�鍛�
|
|
|
m_DeviceErrorHandler->ClearAllErrors();
|
|
|
m_DeviceErrorHandler->ClearAllWarnings();
|
|
|
- int level = 0;
|
|
|
-
|
|
|
+
|
|
|
+ // 鍙戦€佸�浣嶅懡浠�
|
|
|
+ return HWSend("CLR0");
|
|
|
+}
|
|
|
+
|
|
|
+// 杈呭姪鍑芥暟锛氬�鐞嗚繛鎺ラ敊璇�苟鏇存柊鍙戠敓鍣ㄧ姸鎬�
|
|
|
+RET_STATUS nsGEN::HaoWeiDevice::HandleConnectionError(const char* errorMsg)
|
|
|
+{
|
|
|
+ FERROR(errorMsg);
|
|
|
+ if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_SHUTDOWN))
|
|
|
+ {
|
|
|
+ FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
|
|
|
+ FINFO("Generator status updated to SHUTDOWN");
|
|
|
+ }
|
|
|
+ return RET_STATUS::RET_FAILED;
|
|
|
+}
|
|
|
+
|
|
|
+// 杈呭姪鍑芥暟锛氭�鏌�A/MS鎿嶄綔鏄�惁鍏佽�锛圡AS妯″紡涓嬩笉鍏佽�锛�
|
|
|
+bool nsGEN::HaoWeiDevice::IsMAMSOperationAllowed(const char* operationName)
|
|
|
+{
|
|
|
+ if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
|
|
|
+ {
|
|
|
+ FWARN("Techmode is MAS, cannot {$}", operationName);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+// 杈呭姪鍑芥暟锛氭�鏌�AS鎿嶄綔鏄�惁鍏佽�锛堥潪MAS妯″紡涓嬩笉鍏佽�锛�
|
|
|
+bool nsGEN::HaoWeiDevice::IsMASOperationAllowed(const char* operationName)
|
|
|
+{
|
|
|
+ if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS)
|
|
|
+ {
|
|
|
+ FWARN("Techmode is not MAS, cannot {$}", operationName);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
RET_STATUS nsGEN::HaoWeiDevice::HWSend(const char* strCommand, int lengh, bool reSend, int nTimeOut)
|
|
|
{
|
|
|
if (!m_SCF) {
|
|
|
- FINFO("Failed - Serial communication interface not initialized");
|
|
|
- if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_SHUTDOWN))
|
|
|
- {
|
|
|
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
|
|
|
- FINFO("Generator status updated to {$}", static_cast<int>(nsGEN::AttrKey::GENERATOR_STATUS_SHUTDOWN));
|
|
|
- }
|
|
|
- return RET_STATUS::RET_FAILED;
|
|
|
+ return HandleConnectionError("Failed - Serial communication interface not initialized");
|
|
|
}
|
|
|
|
|
|
if (!m_SCF->IsConnected())
|
|
|
{
|
|
|
- FERROR("Failed - Device not connected");
|
|
|
- if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_SHUTDOWN))
|
|
|
- {
|
|
|
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
|
|
|
- FINFO("Generator status updated to {$}", static_cast<int>(nsGEN::AttrKey::GENERATOR_STATUS_SHUTDOWN));
|
|
|
- }
|
|
|
- return RET_STATUS::RET_FAILED;
|
|
|
+ return HandleConnectionError("Failed - Device not connected");
|
|
|
}
|
|
|
|
|
|
- // 使用传入的lengh参数,如果为0则用strlen计算
|
|
|
+ // 浣跨敤浼犲叆鐨刲engh鍙傛暟锛屽�鏋滀负0鍒欑敤strlen璁$畻
|
|
|
int cmdLen = (lengh > 0) ? lengh : strlen(strCommand);
|
|
|
|
|
|
- // 检查缓冲区大小,数据包 = 命令 + ETX(1字节) + CheckSum(1字节)
|
|
|
- const int maxCmdLen = 256; // 增大缓冲区以支持更长的命令
|
|
|
+ // 妫€鏌ョ紦鍐插尯澶у皬锛屾暟鎹�寘 = 鍛戒护 + ETX(1瀛楄妭) + CheckSum(1瀛楄妭)
|
|
|
+ const int maxCmdLen = 256; // 澧炲ぇ缂撳啿鍖轰互鏀�寔鏇撮暱鐨勫懡浠�
|
|
|
if (cmdLen > maxCmdLen - 2)
|
|
|
{
|
|
|
FERROR("Command too long: {$} bytes, max allowed: {$} bytes\n", cmdLen, maxCmdLen - 2);
|
|
@@ -1043,7 +1059,7 @@ RET_STATUS nsGEN::HaoWeiDevice::HWSend(const char* strCommand, int lengh, bool r
|
|
|
|
|
|
char strSendCommand[maxCmdLen] = { 0 };
|
|
|
|
|
|
- // 计算校验和
|
|
|
+ // 璁$畻鏍¢獙鍜�
|
|
|
int tmpSum = 0;
|
|
|
for (int i = 0; i < cmdLen; i++)
|
|
|
{
|
|
@@ -1051,20 +1067,20 @@ RET_STATUS nsGEN::HaoWeiDevice::HWSend(const char* strCommand, int lengh, bool r
|
|
|
}
|
|
|
char checkSum = char(tmpSum + 3);
|
|
|
|
|
|
- // 构建数据包:命令 + ETX + CheckSum
|
|
|
+ // 鏋勫缓鏁版嵁鍖咃細鍛戒护 + ETX + CheckSum
|
|
|
memcpy(strSendCommand, strCommand, cmdLen);
|
|
|
strSendCommand[cmdLen] = 0x03;
|
|
|
strSendCommand[cmdLen + 1] = checkSum;
|
|
|
strSendCommand[cmdLen + 2] = 0x00;
|
|
|
- int totalLen = cmdLen + 3; // 实际发送的总长度
|
|
|
+ int totalLen = cmdLen + 3; // 瀹為檯鍙戦€佺殑鎬婚暱搴�
|
|
|
|
|
|
- // 打印完整数据包的十六进制和ASCII(含ETX和CheckSum)便于调试
|
|
|
+ // 鎵撳嵃瀹屾暣鏁版嵁鍖呯殑鍗佸叚杩涘埗鍜孉SCII锛堝惈ETX鍜孋heckSum锛変究浜庤皟璇�
|
|
|
std::string hexStr;
|
|
|
std::string asciiStr;
|
|
|
hexStr.reserve(totalLen * 3);
|
|
|
asciiStr.reserve(cmdLen + 10);
|
|
|
|
|
|
- int printLen = std::min(totalLen, 32); // 最多打印前32字节
|
|
|
+ int printLen = std::min(totalLen, 32); // 鏈€澶氭墦鍗板墠32瀛楄妭
|
|
|
for (int i = 0; i < printLen; i++) {
|
|
|
char buf[4];
|
|
|
snprintf(buf, sizeof(buf), "%02X ", (unsigned char)strSendCommand[i]);
|
|
@@ -1072,22 +1088,22 @@ RET_STATUS nsGEN::HaoWeiDevice::HWSend(const char* strCommand, int lengh, bool r
|
|
|
}
|
|
|
if (totalLen > 32) hexStr += "...";
|
|
|
|
|
|
- // 提取可打印的ASCII字符串(命令部分,不包括ETX和CheckSum)
|
|
|
+ // 鎻愬彇鍙�墦鍗扮殑ASCII瀛楃�涓诧紙鍛戒护閮ㄥ垎锛屼笉鍖呮嫭ETX鍜孋heckSum锛�
|
|
|
for (int i = 0; i < cmdLen; i++) {
|
|
|
char ch = strCommand[i];
|
|
|
- if (ch >= 32 && ch <= 126) { // 可打印字符
|
|
|
+ if (ch >= 32 && ch <= 126) { // 鍙�墦鍗板瓧绗�
|
|
|
asciiStr += ch;
|
|
|
}
|
|
|
else {
|
|
|
- asciiStr += '.'; // 不可打印字符用'.'表示
|
|
|
+ asciiStr += '.'; // 涓嶅彲鎵撳嵃瀛楃�鐢�'.'琛ㄧず
|
|
|
}
|
|
|
}
|
|
|
- asciiStr += " + ETX + CKS"; // 标注后面的控制字符
|
|
|
+ asciiStr += " + ETX + CKS"; // 鏍囨敞鍚庨潰鐨勬帶鍒跺瓧绗�
|
|
|
|
|
|
FINFO("==OUT== Packet[{$}]: HEX=[{$}] ASCII=[{$}]\n", totalLen, hexStr.c_str(), asciiStr.c_str());
|
|
|
|
|
|
- // 发送数据包,支持重发机制
|
|
|
- int maxRetry = reSend ? 2 : 1; // 如果reSend为true,最多重试2次
|
|
|
+ // 鍙戦€佹暟鎹�寘锛屾敮鎸侀噸鍙戞満鍒�
|
|
|
+ int maxRetry = reSend ? 2 : 1; // 濡傛灉reSend涓簍rue锛屾渶澶氶噸璇�2娆�
|
|
|
unsigned int retLength = 0;
|
|
|
|
|
|
for (int retry = 0; retry < maxRetry; retry++)
|
|
@@ -1095,12 +1111,12 @@ RET_STATUS nsGEN::HaoWeiDevice::HWSend(const char* strCommand, int lengh, bool r
|
|
|
if (retry > 0)
|
|
|
{
|
|
|
FWARN("Retry sending packet, attempt {$}/{$}\n", retry + 1, maxRetry);
|
|
|
- Sleep(100); // 重试前短暂延时
|
|
|
+ Sleep(100); // 閲嶈瘯鍓嶇煭鏆傚欢鏃�
|
|
|
}
|
|
|
|
|
|
if (m_SCF->Lock(1000) == WAIT_OBJECT_0)
|
|
|
{
|
|
|
- // 使用实际长度totalLen,而不是strlen
|
|
|
+ // 浣跨敤瀹為檯闀垮害totalLen锛岃€屼笉鏄痵trlen
|
|
|
int result = m_SCF->SendPacket(strSendCommand, totalLen, nTimeOut, retLength);
|
|
|
m_SCF->Unlock();
|
|
|
|
|
@@ -1138,7 +1154,7 @@ void nsGEN::HaoWeiDevice::FireNotify(std::string key, std::string content)
|
|
|
|
|
|
struct tFrameMapping
|
|
|
{
|
|
|
- static const int MaxLen = 5; // 前缀不能超超过 5 个字符 !
|
|
|
+ static const int MaxLen = 5; // 鍓嶇紑涓嶈兘瓒呰秴杩� 5 涓�瓧绗� !
|
|
|
using cbFun = std::function <void(const char*, int)>;
|
|
|
|
|
|
char strHead[MaxLen];
|
|
@@ -1147,9 +1163,9 @@ struct tFrameMapping
|
|
|
|
|
|
tFrameMapping(const char* str, int len, cbFun f)
|
|
|
{
|
|
|
- assert(len < MaxLen); //len最大只能是4
|
|
|
+ assert(len < MaxLen); //len鏈€澶у彧鑳芥槸4
|
|
|
//strHead[0] = 0x02; //STX ----------->note : no package header
|
|
|
- for (int i = 0; i < len; i++) //给strHead赋值
|
|
|
+ for (int i = 0; i < len; i++) //缁檚trHead璧嬪€�
|
|
|
strHead[i] = str[i];
|
|
|
NbOfCharOfHead = len;
|
|
|
fun = f;
|
|
@@ -1197,21 +1213,21 @@ void nsGEN::HaoWeiDevice::OnCallBack()
|
|
|
assert(value);
|
|
|
int genStatus = atoi(value);
|
|
|
|
|
|
- // 获取状态码的首位数字,用来判断阶段
|
|
|
+ // 鑾峰彇鐘舵€佺爜鐨勯�浣嶆暟瀛楋紝鐢ㄦ潵鍒ゆ柇闃舵�
|
|
|
int statusPrefix = genStatus / 10;
|
|
|
|
|
|
- // 根据阶段处理不同的状态
|
|
|
+ // 鏍规嵁闃舵�澶勭悊涓嶅悓鐨勭姸鎬�
|
|
|
switch (statusPrefix)
|
|
|
{
|
|
|
case 10:
|
|
|
- // 初始化阶段 (101, 102, 103)
|
|
|
+ // 鍒濆�鍖栭樁娈� (101, 102, 103)
|
|
|
FINFO("Get Gen Status:GENSTATE {$} -> (Initialization Phase)", m_DoseUnit.m_GenState->JSGet().c_str());
|
|
|
if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_INIT))
|
|
|
FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
|
|
|
break;
|
|
|
|
|
|
case 20:
|
|
|
- // 待机阶段 (200)
|
|
|
+ // 寰呮満闃舵� (200)
|
|
|
if (!m_bHasInitializedDevice)
|
|
|
{
|
|
|
InitDevice();
|
|
@@ -1223,59 +1239,59 @@ void nsGEN::HaoWeiDevice::OnCallBack()
|
|
|
break;
|
|
|
|
|
|
case 30:
|
|
|
- // 拍片准备阶段 (300)
|
|
|
+ // 鎷嶇墖鍑嗗�闃舵� (300)
|
|
|
FINFO("Get Gen Status:GENSTATE {$} -> (Film Prep Phase)", m_DoseUnit.m_GenState->JSGet().c_str());
|
|
|
break;
|
|
|
|
|
|
case 40:
|
|
|
- // 透视准备阶段 (400)
|
|
|
+ // 閫忚�鍑嗗�闃舵� (400)
|
|
|
FINFO("Get Gen Status:GENSTATE {$} -> (Fluoroscopy Prep Phase)", m_DoseUnit.m_GenState->JSGet().c_str());
|
|
|
break;
|
|
|
|
|
|
case 50:
|
|
|
- // 曝光阶段 (500)
|
|
|
+ // 鏇濆厜闃舵� (500)
|
|
|
FINFO("Get Gen Status:GENSTATE {$} -> (Exposure Phase)", m_DoseUnit.m_GenState->JSGet().c_str());
|
|
|
break;
|
|
|
|
|
|
case 60:
|
|
|
- // 透视阶段 (600)
|
|
|
+ // 閫忚�闃舵� (600)
|
|
|
FINFO("Get Gen Status:GENSTATE {$} -> (Fluoroscopy Phase)", m_DoseUnit.m_GenState->JSGet().c_str());
|
|
|
break;
|
|
|
|
|
|
case 70:
|
|
|
- // 点片曝光阶段 (700)
|
|
|
+ // 鐐圭墖鏇濆厜闃舵� (700)
|
|
|
FINFO("Get Gen Status:GENSTATE {$} -> (Spot Exposure Phase)", m_DoseUnit.m_GenState->JSGet().c_str());
|
|
|
break;
|
|
|
|
|
|
case 80:
|
|
|
- // 故障阶段 (800)
|
|
|
+ // 鏁呴殰闃舵� (800)
|
|
|
FINFO("Get Gen Status:GENSTATE {$} -> (Fault Phase)", m_DoseUnit.m_GenState->JSGet().c_str());
|
|
|
if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR))
|
|
|
FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
|
|
|
break;
|
|
|
|
|
|
case 90:
|
|
|
- // 灯丝自动校准阶段 (900)
|
|
|
+ // 鐏�笣鑷�姩鏍″噯闃舵� (900)
|
|
|
FINFO("Get Gen Status:GENSTATE {$} -> (Filament Auto Calibration Phase)", m_DoseUnit.m_GenState->JSGet().c_str());
|
|
|
break;
|
|
|
|
|
|
case 91:
|
|
|
- // 透视校准阶段 (910)
|
|
|
+ // 閫忚�鏍″噯闃舵� (910)
|
|
|
FINFO("Get Gen Status:GENSTATE {$} -> (Fluoroscopy Calibration Phase)", m_DoseUnit.m_GenState->JSGet().c_str());
|
|
|
break;
|
|
|
|
|
|
case 92:
|
|
|
- // 配置阶段 (920)
|
|
|
+ // 閰嶇疆闃舵� (920)
|
|
|
FINFO("Get Gen Status:GENSTATE {$} -> (Configuration Phase)", m_DoseUnit.m_GenState->JSGet().c_str());
|
|
|
break;
|
|
|
|
|
|
case 93:
|
|
|
- // 复位阶段 (930)
|
|
|
+ // 澶嶄綅闃舵� (930)
|
|
|
FINFO("Get Gen Status:GENSTATE {$} -> (Reset Phase)", m_DoseUnit.m_GenState->JSGet().c_str());
|
|
|
break;
|
|
|
|
|
|
case 94:
|
|
|
- // 升级阶段 (940)
|
|
|
+ // 鍗囩骇闃舵� (940)
|
|
|
FINFO("Get Gen Status:GENSTATE {$} -> (Upgrade Phase)", m_DoseUnit.m_GenState->JSGet().c_str());
|
|
|
break;
|
|
|
|
|
@@ -1409,7 +1425,7 @@ void nsGEN::HaoWeiDevice::OnCallBack()
|
|
|
int nValue = atoi(value);
|
|
|
if (nValue == 2)
|
|
|
{
|
|
|
- FINFO("The high voltage generator enters the exposure preparation stage。");
|
|
|
+ FINFO("The high voltage generator enters the exposure preparation stage銆�");
|
|
|
HWSend("PR2");
|
|
|
}
|
|
|
else if (nValue == 1)
|
|
@@ -1571,11 +1587,11 @@ void nsGEN::HaoWeiDevice::OnCallBack()
|
|
|
auto HWGR = [this](const char* value, int length)
|
|
|
{
|
|
|
assert(value);
|
|
|
- // 提取机器型号、功率版本和功能类型
|
|
|
- std::string version(value, 3); // 前3个字符为机器型号
|
|
|
- char functionalityChar = value[3]; // 第4个字符表示功能类型
|
|
|
+ // 鎻愬彇鏈哄櫒鍨嬪彿銆佸姛鐜囩増鏈�拰鍔熻兘绫诲瀷
|
|
|
+ std::string version(value, 3); // 鍓�3涓�瓧绗︿负鏈哄櫒鍨嬪彿
|
|
|
+ char functionalityChar = value[3]; // 绗�4涓�瓧绗﹁〃绀哄姛鑳界被鍨�
|
|
|
|
|
|
- // 功能类型的映射
|
|
|
+ // 鍔熻兘绫诲瀷鐨勬槧灏�
|
|
|
std::string functionality;
|
|
|
if (functionalityChar == '0') {
|
|
|
functionality = "PR (pet photography)";
|
|
@@ -1604,35 +1620,35 @@ void nsGEN::HaoWeiDevice::OnCallBack()
|
|
|
else {
|
|
|
functionality = "Unknown Functionality:"+ functionalityChar;
|
|
|
}
|
|
|
- // 日志打印输出
|
|
|
+ // 鏃ュ織鎵撳嵃杈撳嚭
|
|
|
FINFO("Version: {$}, Functionality: {$}", version, functionality.c_str());
|
|
|
};
|
|
|
|
|
|
auto HWGV = [this](const char* value, int length)
|
|
|
{
|
|
|
assert(value);
|
|
|
- // 打印原始值
|
|
|
+ // 鎵撳嵃鍘熷�鍊�
|
|
|
FINFO("value: {$}", value);
|
|
|
int versionNumber = atoi(value);
|
|
|
|
|
|
- // 拆解 versionNumber 为 4个部分(假设数字按版本号分割:10010 -> V1.0.0.10)
|
|
|
- int major = versionNumber / 10000; // 取高位,得到主版本号
|
|
|
- int minor = (versionNumber / 1000) % 10; // 取次高位,得到次版本号
|
|
|
- int patch = (versionNumber / 100) % 10; // 取中位,得到修补版本号
|
|
|
- int build = versionNumber % 100; // 取低位,得到构建版本号
|
|
|
+ // 鎷嗚В versionNumber 涓� 4涓�儴鍒嗭紙鍋囪�鏁板瓧鎸夌増鏈�彿鍒嗗壊锛�10010 -> V1.0.0.10锛�
|
|
|
+ int major = versionNumber / 10000; // 鍙栭珮浣嶏紝寰楀埌涓荤増鏈�彿
|
|
|
+ int minor = (versionNumber / 1000) % 10; // 鍙栨�楂樹綅锛屽緱鍒版�鐗堟湰鍙�
|
|
|
+ int patch = (versionNumber / 100) % 10; // 鍙栦腑浣嶏紝寰楀埌淇�ˉ鐗堟湰鍙�
|
|
|
+ int build = versionNumber % 100; // 鍙栦綆浣嶏紝寰楀埌鏋勫缓鐗堟湰鍙�
|
|
|
|
|
|
- // 格式化并打印详细版本信息
|
|
|
+ // 鏍煎紡鍖栧苟鎵撳嵃璇︾粏鐗堟湰淇℃伅
|
|
|
FINFO("Software Version: V{$}.{$}.{$}.{$}", major, minor, patch, build);
|
|
|
};
|
|
|
|
|
|
auto HWGU = [this](const char* value, int length)
|
|
|
{
|
|
|
assert(value);
|
|
|
- // 打印原始值
|
|
|
+ // 鎵撳嵃鍘熷�鍊�
|
|
|
FINFO("value: {$}", value);
|
|
|
std::string versionCode(value, 2);
|
|
|
|
|
|
- // 定义版本类型
|
|
|
+ // 瀹氫箟鐗堟湰绫诲瀷
|
|
|
std::string versionType;
|
|
|
if (versionCode == "00") {
|
|
|
versionType = "General Version";
|
|
@@ -1641,10 +1657,10 @@ void nsGEN::HaoWeiDevice::OnCallBack()
|
|
|
versionType = "Custom Version";
|
|
|
}
|
|
|
else {
|
|
|
- versionType = "Unknown Version"; // 处理其他情况,可以根据需求扩展
|
|
|
+ versionType = "Unknown Version"; // 澶勭悊鍏朵粬鎯呭喌锛屽彲浠ユ牴鎹�渶姹傛墿灞�
|
|
|
}
|
|
|
|
|
|
- // 输出详细的版本信息
|
|
|
+ // 杈撳嚭璇︾粏鐨勭増鏈�俊鎭�
|
|
|
FINFO("Software Version: {$}, Type: {$}", value, versionType.c_str());
|
|
|
};
|
|
|
|
|
@@ -1776,7 +1792,7 @@ void nsGEN::HaoWeiDevice::OnCallBack()
|
|
|
HWSend("FLP0");
|
|
|
if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_OFF))
|
|
|
{
|
|
|
- FINFO("脚闸抬起,发生器曝光流程状态{$};", "GENERATOR_FLU_OFF");
|
|
|
+ FINFO("鑴氶椄鎶�捣锛屽彂鐢熷櫒鏇濆厜娴佺▼鐘舵€亄$};", "GENERATOR_FLU_OFF");
|
|
|
FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
|
|
|
}
|
|
|
RefreshData();
|
|
@@ -1851,10 +1867,10 @@ void nsGEN::HaoWeiDevice::OnCallBack()
|
|
|
if (m_DoseUnit.m_FLAccTime->Update(tmpflt))
|
|
|
FireNotify(AttrKey::FLUAccTime, m_DoseUnit.m_FLAccTime->JSGet());
|
|
|
};
|
|
|
- // 有部分前缀是包含关系, 长的包含短的, 例如 KVS 包含了 KV.
|
|
|
- // 因此长的在前面, 短的在后面
|
|
|
- // !!! Device 是个短寿命对象, 而 arFrame 是静态变量 !!!
|
|
|
- // !!! 因此, 在添加到 arFrame 之前, 务必先清零 !!!
|
|
|
+ // 鏈夐儴鍒嗗墠缂€鏄�寘鍚�叧绯�, 闀跨殑鍖呭惈鐭�殑, 渚嬪� KVS 鍖呭惈浜� KV.
|
|
|
+ // 鍥犳�闀跨殑鍦ㄥ墠闈�, 鐭�殑鍦ㄥ悗闈�
|
|
|
+ // !!! Device 鏄�釜鐭��鍛藉�璞�, 鑰� arFrame 鏄�潤鎬佸彉閲� !!!
|
|
|
+ // !!! 鍥犳�, 鍦ㄦ坊鍔犲埌 arFrame 涔嬪墠, 鍔″繀鍏堟竻闆� !!!
|
|
|
arFrame.clear();
|
|
|
|
|
|
arFrame.push_back(tFrameMapping("KV", 2, HWKV));
|
|
@@ -1929,9 +1945,9 @@ void nsGEN::HaoWeiDevice::HardwareStatusThread(HaoWeiDevice* pParam)
|
|
|
FINFO("========================================");
|
|
|
|
|
|
HaoWeiDevice* pCurGen = pParam;
|
|
|
- if (pCurGen == NULL)
|
|
|
+ if (pCurGen == nullptr)
|
|
|
{
|
|
|
- FERROR("HardwareStatusThread: pParam is NULL, exiting thread");
|
|
|
+ FERROR("HardwareStatusThread: pParam is nullptr, exiting thread");
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -1941,22 +1957,28 @@ void nsGEN::HaoWeiDevice::HardwareStatusThread(HaoWeiDevice* pParam)
|
|
|
|
|
|
FINFO("Hardware status monitoring started");
|
|
|
FINFO("Initial loop time: {$} ms", currtTime);
|
|
|
- while (true)
|
|
|
+
|
|
|
+ while (pCurGen->m_bExtraFlag) // 娣诲姞閫€鍑烘潯浠�
|
|
|
{
|
|
|
auto now = std::chrono::steady_clock::now();
|
|
|
auto last = lastValidResponse.load();
|
|
|
-
|
|
|
- if (now - last > TIMEOUT && pCurGen->m_DoseUnit.m_GenState->Get() > 0) {
|
|
|
- FINFO("The timeout did not respond");
|
|
|
- pCurGen->m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_SHUTDOWN); // 超时未响应则重置状态
|
|
|
+ auto elapsed = std::chrono::duration_cast<std::chrono::seconds>(now - last);
|
|
|
+
|
|
|
+ // 妫€鏌ラ€氳�瓒呮椂
|
|
|
+ if (elapsed > TIMEOUT) {
|
|
|
+ int currentState = pCurGen->m_DoseUnit.m_GenState->Get();
|
|
|
+ if (currentState > 0) {
|
|
|
+ FWARN("Communication timeout: {$}s, shutting down generator", elapsed.count());
|
|
|
+ pCurGen->m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_SHUTDOWN); // 瓒呮椂鏈�搷搴斿垯閲嶇疆鐘舵€�
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
currtTime = pCurGen->m_iLoopTime;
|
|
|
- Sleep(currtTime);
|
|
|
- //获取消息
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(currtTime));
|
|
|
+ //鑾峰彇娑堟伅
|
|
|
//pCurGen->HWSend("ST?");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
FINFO("HardwareStatusThread stop");
|
|
|
}
|
|
|
|
|
@@ -1965,6 +1987,7 @@ void nsGEN::HaoWeiDevice::HardwareStatusThread(HaoWeiDevice* pParam)
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
nsGEN::HaoWeiDriver::HaoWeiDriver()
|
|
|
+ : m_scfWrapper(std::make_shared<SCFWrapper>())
|
|
|
{
|
|
|
}
|
|
|
|
|
@@ -1995,7 +2018,7 @@ void nsGEN::HaoWeiDriver::Prepare()
|
|
|
FINFO("Prepare() Starting...");
|
|
|
FINFO("========================================");
|
|
|
|
|
|
- // 初始化日志系统
|
|
|
+ // 鍒濆�鍖栨棩蹇楃郴缁�
|
|
|
std::string strLogPath = GetProcessDirectory() + R"(/Conf/log_config.xml)";
|
|
|
std::string LogHost = "DevHaoWei";
|
|
|
std::string moduleName = "DevHaoWei";
|
|
@@ -2006,10 +2029,10 @@ void nsGEN::HaoWeiDriver::Prepare()
|
|
|
FINFO("Module name: {$}", moduleName.c_str());
|
|
|
|
|
|
bool ret = initLogModule(
|
|
|
- LogHost, // 主机名(用于日志路径中的{host}占位符)
|
|
|
- moduleName, // 唯一模块名
|
|
|
- strLogPath, // 配置文件路径
|
|
|
- true // 是否输出到控制台(可选)
|
|
|
+ LogHost, // 涓绘満鍚嶏紙鐢ㄤ簬鏃ュ織璺�緞涓�殑{host}鍗犱綅绗︼級
|
|
|
+ moduleName, // 鍞�竴妯″潡鍚�
|
|
|
+ strLogPath, // 閰嶇疆鏂囦欢璺�緞
|
|
|
+ true // 鏄�惁杈撳嚭鍒版帶鍒跺彴锛堝彲閫夛級
|
|
|
);
|
|
|
|
|
|
if (!ret) {
|
|
@@ -2039,17 +2062,17 @@ bool DATA_ACTION nsGEN::HaoWeiDriver::Connect()
|
|
|
const auto currentState = m_connectionState.load();
|
|
|
auto now = std::chrono::steady_clock::now();
|
|
|
|
|
|
- // 1. 处理可重试的失败状态
|
|
|
+ // 1. 澶勭悊鍙�噸璇曠殑澶辫触鐘舵€�
|
|
|
if (currentState == ConnectionState::Failed) {
|
|
|
if ((now - m_lastConnectionAttempt) >= RETRY_INTERVAL && m_connectionRetryCount < MAX_RETRY_COUNT) {
|
|
|
m_connectionState = ConnectionState::Disconnected;
|
|
|
}
|
|
|
else {
|
|
|
- return false; // 不满足重试条件,直接返回
|
|
|
+ return false; // 涓嶆弧瓒抽噸璇曟潯浠讹紝鐩存帴杩斿洖
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 2. 检查无效状态(正在连接/已连接但实际有效)
|
|
|
+ // 2. 妫€鏌ユ棤鏁堢姸鎬侊紙姝e湪杩炴帴/宸茶繛鎺ヤ絾瀹為檯鏈夋晥锛�
|
|
|
if (currentState == ConnectionState::Connecting) {
|
|
|
FINFO("Already connecting (type: {$})",
|
|
|
m_currentConnType == ConnectionType::Serial ? "Serial" : "Ethernet");
|
|
@@ -2061,7 +2084,7 @@ bool DATA_ACTION nsGEN::HaoWeiDriver::Connect()
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- // 3. 检查重试间隔
|
|
|
+ // 3. 妫€鏌ラ噸璇曢棿闅�
|
|
|
if (m_connectionRetryCount > 0 && (now - m_lastConnectionAttempt) < RETRY_INTERVAL) {
|
|
|
FINFO("Retry in {$}s (type: {$})",
|
|
|
std::chrono::duration_cast<std::chrono::seconds>(RETRY_INTERVAL - (now - m_lastConnectionAttempt)).count(),
|
|
@@ -2071,41 +2094,41 @@ bool DATA_ACTION nsGEN::HaoWeiDriver::Connect()
|
|
|
|
|
|
ResDataObject connParam = GetConnectParam(m_ConfigFileName);
|
|
|
std::string connPortStr = "";
|
|
|
- std::string connTypeStr = (std::string)connParam["type"]; // 从配置读取type字段
|
|
|
+ std::string connTypeStr = (std::string)connParam["type"]; // 浠庨厤缃��鍙杢ype瀛楁�
|
|
|
m_currentConnType = (connTypeStr == "COM") ? ConnectionType::Serial : ConnectionType::Ethernet;
|
|
|
if (m_currentConnType == ConnectionType::Serial)
|
|
|
{
|
|
|
- connPortStr = (std::string)connParam["port"];// 从配置读取port字段
|
|
|
- // 查找配置端口在现有端口列表中的位置
|
|
|
+ connPortStr = (std::string)connParam["port"];// 浠庨厤缃��鍙杙ort瀛楁�
|
|
|
+ // 鏌ユ壘閰嶇疆绔�彛鍦ㄧ幇鏈夌�鍙e垪琛ㄤ腑鐨勪綅缃�
|
|
|
auto it = std::find(m_serialPorts.begin(), m_serialPorts.end(), connPortStr);
|
|
|
|
|
|
if (it == m_serialPorts.end()) {
|
|
|
- // 配置的端口不在列表中,添加到首位
|
|
|
+ // 閰嶇疆鐨勭�鍙d笉鍦ㄥ垪琛ㄤ腑锛屾坊鍔犲埌棣栦綅
|
|
|
FINFO("Configured serial port {$} not found, adding to front of port list", connPortStr);
|
|
|
m_serialPorts.insert(m_serialPorts.begin(), connPortStr);
|
|
|
}
|
|
|
else if (it != m_serialPorts.begin()) {
|
|
|
- // 配置的端口存在但不在首位,移动到首位
|
|
|
+ // 閰嶇疆鐨勭�鍙e瓨鍦ㄤ絾涓嶅湪棣栦綅锛岀Щ鍔ㄥ埌棣栦綅
|
|
|
FINFO("Moving configured serial port {$} to front of port list", connPortStr);
|
|
|
m_serialPorts.erase(it);
|
|
|
m_serialPorts.insert(m_serialPorts.begin(), connPortStr);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- // 4. 执行连接流程
|
|
|
+ // 4. 鎵ц�杩炴帴娴佺▼
|
|
|
m_connectionState = ConnectionState::Connecting;
|
|
|
m_lastConnectionAttempt = now;
|
|
|
|
|
|
std::string connInfo;
|
|
|
try {
|
|
|
if (m_currentConnType == ConnectionType::Serial) {
|
|
|
- // 串口连接:使用当前索引的端口
|
|
|
+ // 涓插彛杩炴帴锛氫娇鐢ㄥ綋鍓嶇储寮曠殑绔�彛
|
|
|
std::string currentPort = m_serialPorts[m_currentSerialPortIndex];
|
|
|
- connParam.update("port", currentPort.c_str()); // 将当前尝试的端口写入参数
|
|
|
+ connParam.update("port", currentPort.c_str()); // 灏嗗綋鍓嶅皾璇曠殑绔�彛鍐欏叆鍙傛暟
|
|
|
connInfo = "Serial (port: " + currentPort + ")";
|
|
|
}
|
|
|
else {
|
|
|
- // 网口连接:直接使用配置参数
|
|
|
+ // 缃戝彛杩炴帴锛氱洿鎺ヤ娇鐢ㄩ厤缃�弬鏁�
|
|
|
connInfo = "Ethernet (ip: " + std::string(connParam["ip"]) + ")";
|
|
|
}
|
|
|
|
|
@@ -2126,21 +2149,21 @@ bool DATA_ACTION nsGEN::HaoWeiDriver::Connect()
|
|
|
FINFO("Connect failed (code: {$}) for {$}", erCode, connInfo);
|
|
|
m_scfWrapper->Disconnect();
|
|
|
m_connectionState = ConnectionState::Failed;
|
|
|
- // 串口连接:未遍历完所有端口时,优先切换端口重试(不计入总重试次数)
|
|
|
+ // 涓插彛杩炴帴锛氭湭閬嶅巻瀹屾墍鏈夌�鍙f椂锛屼紭鍏堝垏鎹㈢�鍙i噸璇曪紙涓嶈�鍏ユ€婚噸璇曟�鏁帮級
|
|
|
if (m_currentConnType == ConnectionType::Serial) {
|
|
|
int nextIndex = (m_currentSerialPortIndex + 1) % m_serialPorts.size();
|
|
|
- // 判断是否已遍历所有端口(当前索引是最后一个时,nextIndex会回到0)
|
|
|
+ // 鍒ゆ柇鏄�惁宸查亶鍘嗘墍鏈夌�鍙o紙褰撳墠绱㈠紩鏄�渶鍚庝竴涓�椂锛宯extIndex浼氬洖鍒�0锛�
|
|
|
bool allPortsTried = (nextIndex == 0);
|
|
|
|
|
|
if (!allPortsTried) {
|
|
|
- // 未遍历完所有端口:切换到下一端口,不增加重试计数
|
|
|
+ // 鏈�亶鍘嗗畬鎵€鏈夌�鍙o細鍒囨崲鍒颁笅涓€绔�彛锛屼笉澧炲姞閲嶈瘯璁℃暟
|
|
|
m_currentSerialPortIndex = nextIndex;
|
|
|
m_connectionRetryCount = 0;
|
|
|
FINFO("Trying next serial port: {$}", m_serialPorts[nextIndex]);
|
|
|
- return false; // 触发外部线程立即尝试下一端口
|
|
|
+ return false; // 瑙﹀彂澶栭儴绾跨▼绔嬪嵆灏濊瘯涓嬩竴绔�彛
|
|
|
}
|
|
|
else {
|
|
|
- // 已遍历所有端口:重置到第一个端口,增加重试计数(进入间隔等待)
|
|
|
+ // 宸查亶鍘嗘墍鏈夌�鍙o細閲嶇疆鍒扮�涓€涓��鍙o紝澧炲姞閲嶈瘯璁℃暟锛堣繘鍏ラ棿闅旂瓑寰咃級
|
|
|
m_currentSerialPortIndex = 0;
|
|
|
m_connectionRetryCount++;
|
|
|
FINFO("All serial ports tried, retry count: {$}/{$}", m_connectionRetryCount, MAX_RETRY_COUNT);
|
|
@@ -2148,15 +2171,15 @@ bool DATA_ACTION nsGEN::HaoWeiDriver::Connect()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 所有端口失败(串口)或网口失败,才增加总重试计数
|
|
|
+ // 鎵€鏈夌�鍙eけ璐ワ紙涓插彛锛夋垨缃戝彛澶辫触锛屾墠澧炲姞鎬婚噸璇曡�鏁�
|
|
|
m_connectionRetryCount++;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- // 连接成功:重置状态
|
|
|
+ // 杩炴帴鎴愬姛锛氶噸缃�姸鎬�
|
|
|
m_connectionState = ConnectionState::Connected;
|
|
|
m_connectionRetryCount = 0;
|
|
|
- m_currentSerialPortIndex = 0; // 重置串口端口索引
|
|
|
+ m_currentSerialPortIndex = 0; // 閲嶇疆涓插彛绔�彛绱㈠紩
|
|
|
FINFO("Connected successfully ({$})", connInfo);
|
|
|
return true;
|
|
|
}
|
|
@@ -2197,25 +2220,25 @@ bool nsGEN::HaoWeiDriver::isConnected() const
|
|
|
{
|
|
|
const auto state = m_connectionState.load();
|
|
|
|
|
|
- // 1. 连接中/实际已连接:返回true(无需重连)
|
|
|
+ // 1. 杩炴帴涓�/瀹為檯宸茶繛鎺ワ細杩斿洖true锛堟棤闇€閲嶈繛锛�
|
|
|
if (state == ConnectionState::Connecting || (m_scfWrapper && m_scfWrapper->IsConnected())) {
|
|
|
//FINFO(state == ConnectionState::Connecting ? "Connecting in progress" : "Already connected");
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- // 2. 失败状态处理:判断是否允许重试
|
|
|
+ // 2. 澶辫触鐘舵€佸�鐞嗭細鍒ゆ柇鏄�惁鍏佽�閲嶈瘯
|
|
|
if (state == ConnectionState::Failed) {
|
|
|
auto now = std::chrono::steady_clock::now();
|
|
|
const auto timeSinceLast = now - m_lastConnectionAttempt;
|
|
|
|
|
|
- // 2.1 达到最大重试次数,但超过重置间隔:重置计数,允许重新重试
|
|
|
+ // 2.1 杈惧埌鏈€澶ч噸璇曟�鏁帮紝浣嗚秴杩囬噸缃�棿闅旓細閲嶇疆璁℃暟锛屽厑璁搁噸鏂伴噸璇�
|
|
|
if (m_connectionRetryCount >= MAX_RETRY_COUNT && timeSinceLast >= RESET_RETRY_AFTER) {
|
|
|
FINFO("Max retries reached, resetting count after {$}s",
|
|
|
std::chrono::duration_cast<std::chrono::seconds>(timeSinceLast).count());
|
|
|
- m_connectionRetryCount = 0; // 重置计数(因mutable修饰,const函数可修改)
|
|
|
+ m_connectionRetryCount = 0; // 閲嶇疆璁℃暟锛堝洜mutable淇�グ锛宑onst鍑芥暟鍙�慨鏀癸級
|
|
|
}
|
|
|
|
|
|
- // 2.2 不适合重连(时间未到 或 次数仍超限):返回true阻止重连
|
|
|
+ // 2.2 涓嶉€傚悎閲嶈繛锛堟椂闂存湭鍒� 鎴� 娆℃暟浠嶈秴闄愶級锛氳繑鍥瀟rue闃绘�閲嶈繛
|
|
|
if (timeSinceLast < RETRY_INTERVAL || m_connectionRetryCount >= MAX_RETRY_COUNT) {
|
|
|
FINFO(timeSinceLast < RETRY_INTERVAL ?
|
|
|
"Retry later ({$}s)" : "Max retries, waiting {$}s to reset",
|
|
@@ -2227,7 +2250,7 @@ bool nsGEN::HaoWeiDriver::isConnected() const
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 3. 其他情况(适合重连):返回false触发Connect()
|
|
|
+ // 3. 鍏朵粬鎯呭喌锛堥€傚悎閲嶈繛锛夛細杩斿洖false瑙﹀彂Connect()
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -2388,22 +2411,22 @@ PACKET_RET nsGEN::HaoWeiDriver::callbackPackageProcess(const char* RecData, uint
|
|
|
{
|
|
|
FINFO("==IN==11:[{:02X$}]\n", RecData);
|
|
|
|
|
|
- if (nLength < 1) // 最小有效包为0x03 + checksum + 0x00(3字节)
|
|
|
+ if (nLength < 1) // 鏈€灏忔湁鏁堝寘涓�0x03 + checksum + 0x00锛�3瀛楄妭锛�
|
|
|
{
|
|
|
return PACKET_USELESS;
|
|
|
}
|
|
|
|
|
|
- for (DWORD i = 0; i < nLength; ++i) // 遍历所有字节
|
|
|
+ for (DWORD i = 0; i < nLength; ++i) // 閬嶅巻鎵€鏈夊瓧鑺�
|
|
|
{
|
|
|
if (RecData[i] == 0x00)
|
|
|
{
|
|
|
- if (i < 2) { // 至少需要0x03、校验和和结束符
|
|
|
+ if (i < 2) { // 鑷冲皯闇€瑕�0x03銆佹牎楠屽拰鍜岀粨鏉熺�
|
|
|
return PACKET_USELESS;
|
|
|
}
|
|
|
|
|
|
size_t markerPos = i - 2;
|
|
|
- if (RecData[markerPos] != 0x03) { // 检查0x03标识符
|
|
|
- // 不是有效的起始符,继续查找下一个结束符
|
|
|
+ if (RecData[markerPos] != 0x03) { // 妫€鏌�0x03鏍囪瘑绗�
|
|
|
+ // 涓嶆槸鏈夋晥鐨勮捣濮嬬�锛岀户缁�煡鎵句笅涓€涓�粨鏉熺�
|
|
|
continue;
|
|
|
}
|
|
|
|
|
@@ -2414,11 +2437,11 @@ PACKET_RET nsGEN::HaoWeiDriver::callbackPackageProcess(const char* RecData, uint
|
|
|
|
|
|
//BYTE recvSum = RecData[i - 1];
|
|
|
//if (calcSum != recvSum) {
|
|
|
- // // 校验失败,继续查找后续可能的包
|
|
|
+ // // 鏍¢獙澶辫触锛岀户缁�煡鎵惧悗缁�彲鑳界殑鍖�
|
|
|
// continue;
|
|
|
//}
|
|
|
|
|
|
- PacketLength = static_cast<DWORD>(i - 2); //应该+2.才会把最后的checmsum也包含进来。FO1+03+sum.
|
|
|
+ PacketLength = static_cast<DWORD>(i - 2); //搴旇�+2.鎵嶄細鎶婃渶鍚庣殑checmsum涔熷寘鍚�繘鏉ャ€侳O1+03+sum.
|
|
|
char strtemp[100] = { 0 };
|
|
|
memcpy(strtemp, RecData, i);
|
|
|
strtemp[i + 1] = 0;
|
|
@@ -2466,12 +2489,12 @@ static bool DecodeFrame(const char* strFrame, int length)
|
|
|
|
|
|
static nsGEN::HaoWeiDriver gIODriver;
|
|
|
|
|
|
-extern "C" CCOS::Dev::IODriver * GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
|
|
|
+extern "C" CCOS::Dev::IODriver * GetIODriver() // 杩斿洖闈欐€佸�璞$殑寮曠敤, 璋冪敤鑰呬笉鑳藉垹闄� !
|
|
|
{
|
|
|
return &gIODriver;
|
|
|
}
|
|
|
|
|
|
-extern "C" CCOS::Dev::IODriver * CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
|
|
|
+extern "C" CCOS::Dev::IODriver * CreateIODriver() // 杩斿洖鏂板�璞�, 璋冪敤鑰呭繀椤昏嚜琛屽垹闄ゆ�瀵硅薄 !
|
|
|
{
|
|
|
return new nsGEN::HaoWeiDriver();
|
|
|
}
|