Kaynağa Gözat

1.优化PSG-HD的解析逻辑和发送模块
2.新增发生器PSG-HR

lwk 2 hafta önce
ebeveyn
işleme
f50a8d9acc
26 değiştirilmiş dosya ile 618 ekleme ve 929 silme
  1. 18 14
      Generator/CCOS.Dev.Generator.Mould/CCOS.Dev.Generator.Mould.cpp
  2. 1 0
      Generator/CCOS.Dev.Generator.Mould/CCOS.Dev.Generator.Mould.hpp
  3. 6 0
      Generator/ECOM/CCOS.Dev.Generator.Demo/CCOS.Dev.Generator.Demo.cpp
  4. 1 0
      Generator/ECOM/CCOS.Dev.Generator.Demo/CCOS.Dev.Generator.Demo.hpp
  5. 205 89
      Generator/PSG/CCOS.Dev.Generator.PSG_HD/CCOS.Dev.Generator.PSG_HD.cpp
  6. 17 3
      Generator/PSG/CCOS.Dev.Generator.PSG_HD/CCOS.Dev.Generator.PSG_HD.h
  7. 2 0
      Generator/PSG/CCOS.Dev.Generator.PSG_HD/CMakeLists.txt
  8. 19 0
      Generator/PSG/CCOS.Dev.Generator.PSG_HD/LogLocalHelper.cpp
  9. 28 0
      Generator/PSG/CCOS.Dev.Generator.PSG_HD/LogLocalHelper.h
  10. BIN
      Generator/PSG/CCOS.Dev.Generator.PSG_HR/CCOS.Dev.Generator.PSG_HR.aps
  11. 241 318
      Generator/PSG/CCOS.Dev.Generator.PSG_HR/CCOS.Dev.Generator.PSG_HR.cpp
  12. 29 0
      Generator/PSG/CCOS.Dev.Generator.PSG_HR/CCOS.Dev.Generator.PSG_HR.h
  13. 0 100
      Generator/PSG/CCOS.Dev.Generator.PSG_HR/CCOS.Dev.Generator.PSG_HR.rc
  14. 0 214
      Generator/PSG/CCOS.Dev.Generator.PSG_HR/CCOS.Dev.Generator.PSG_HR.vcxproj
  15. 0 76
      Generator/PSG/CCOS.Dev.Generator.PSG_HR/CCOS.Dev.Generator.PSG_HR.vcxproj.filters
  16. 0 4
      Generator/PSG/CCOS.Dev.Generator.PSG_HR/CCOS.Dev.Generator.PSG_HR.vcxproj.user
  17. 6 0
      Generator/PSG/CCOS.Dev.Generator.PSG_HR/CMakeLists.txt
  18. 17 0
      Generator/PSG/CCOS.Dev.Generator.PSG_HR/LogLocalHelper.cpp
  19. 28 0
      Generator/PSG/CCOS.Dev.Generator.PSG_HR/LogLocalHelper.h
  20. 0 5
      Generator/PSG/CCOS.Dev.Generator.PSG_HR/ReleaseNote.txt
  21. 0 20
      Generator/PSG/CCOS.Dev.Generator.PSG_HR/dllmain.cpp
  22. 0 18
      Generator/PSG/CCOS.Dev.Generator.PSG_HR/framework.h
  23. 0 15
      Generator/PSG/CCOS.Dev.Generator.PSG_HR/resource.h
  24. 0 6
      Generator/PSG/CCOS.Dev.Generator.PSG_HR/stdafx.cpp
  25. 0 39
      Generator/PSG/CCOS.Dev.Generator.PSG_HR/stdafx.h
  26. 0 8
      Generator/PSG/CCOS.Dev.Generator.PSG_HR/targetver.h

+ 18 - 14
Generator/CCOS.Dev.Generator.Mould/CCOS.Dev.Generator.Mould.cpp

@@ -71,26 +71,27 @@ _tAPFArgs JSONTo(const std::string& in)
 
 string nsGEN::GetProcessDirectory()
 {
-	string ret = "";
 	char szFilename[PATH_MAX] = { 0 };
-	// Linux 获取可执行文件路径
-	ssize_t res = readlink("/proc/self/exe", szFilename, PATH_MAX);
-	if (res <= 0 || res >= PATH_MAX) {
-		return ret;
+
+	// 读取当前进程可执行文件的路径
+	ssize_t res = readlink("/proc/self/exe", szFilename, PATH_MAX - 1);
+	if (res <= 0 || res >= PATH_MAX - 1) {
+		std::cerr << "获取进程路径失败,readlink返回值: " << res << std::endl;
+		return "";
 	}
-	szFilename[res] = '\0'; // readlink 不会添加终止符
+	szFilename[res] = '\0'; // 确保字符串终止
 
+	std::string fullpath = szFilename;
+	// Linux使用正斜杠'/'作为路径分隔符,而非反斜杠'\'
+	std::string::size_type lastSlash = fullpath.find_last_of('/');
 
-	string fullpath = szFilename;
-	string::size_type firstHit = fullpath.find_last_of('\\');
-	if (firstHit == string::npos || firstHit == 0)
-	{
-		return ret;
+	if (lastSlash == std::string::npos) {
+		// 没有找到路径分隔符,返回空
+		return "";
 	}
 
-	ret = fullpath.substr(0, firstHit);//kick last \
-
-	return ret;
+	// 截取到最后一个斜杠之前的部分,即进程所在目录
+	return fullpath.substr(0, lastSlash);
 }
 
 // 获取 ELF 文件中的 .note 段信息
@@ -523,6 +524,9 @@ void nsGEN::GeneratorMould::Register (Dispatch* Dispatch)
 	Dispatch->Action.Push(ActionKey::Reset, [this](std::string in, std::string& out) {
 		return Reset(); });
 
+	//准备曝光
+	Dispatch->Action.Push(ActionKey::PrepareAcquisition, [this](std::string in, std::string& out) {
+		return PrepareAcquisition(); });
 
 	//同步模式
 	Dispatch->Action.Push(ActionKey::ActiveSyncMode, [this](std::string in, std::string& out) {

+ 1 - 0
Generator/CCOS.Dev.Generator.Mould/CCOS.Dev.Generator.Mould.hpp

@@ -111,6 +111,7 @@ namespace CCOS::Dev::Detail::Generator
 
 	protected:
 		//É豸·½·¨
+		virtual RET_STATUS PrepareAcquisition() = 0;
 		virtual RET_STATUS Reset() = 0;
 		virtual RET_STATUS SetWS(const std::string value) = 0;
 		virtual RET_STATUS SetGenSynState(int value) = 0;

+ 6 - 0
Generator/ECOM/CCOS.Dev.Generator.Demo/CCOS.Dev.Generator.Demo.cpp

@@ -364,6 +364,12 @@ RET_STATUS nsGEN::DemoDevice::SetExpDisable()
 	//mLog::Debug("Enter SetExpDisable");
 	return RET_STATUS::RET_SUCCEED;
 }
+RET_STATUS CCOS::Dev::Detail::Generator::DemoDevice::PrepareAcquisition()
+{
+	m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
+	FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
+	return RET_STATUS::RET_SUCCEED;
+}
 RET_STATUS nsGEN::DemoDevice::Reset()
 {
 	//mLog::Debug("Enter Reset");

+ 1 - 0
Generator/ECOM/CCOS.Dev.Generator.Demo/CCOS.Dev.Generator.Demo.hpp

@@ -45,6 +45,7 @@ namespace CCOS::Dev::Detail::Generator
 		virtual RET_STATUS SetGenState(int value) override;
 		virtual RET_STATUS SetExpEnable() override;
 		virtual RET_STATUS SetExpDisable()override;
+		virtual RET_STATUS PrepareAcquisition()override;
 		virtual RET_STATUS Reset()override;
 		virtual RET_STATUS SetExpMode(std::string value) override;
 		virtual RET_STATUS QueryHE(int& value) override;

+ 205 - 89
Generator/PSG/CCOS.Dev.Generator.PSG_HD/CCOS.Dev.Generator.PSG_HD.cpp

@@ -10,6 +10,7 @@
 #include <algorithm>
 #include "LogicDevice.h"
 using namespace std::placeholders;
+#include "LogLocalHelper.h"       
 #include "Log4CPP.h"
 #include "Helper.JSON.hpp"
 #include "CCOS.Dev.Generator.PSG_HD.h"
@@ -41,8 +42,7 @@ static const int msTimeOut_Lock = 500; //通讯接口锁定时间
 static const auto COM_SCFDllName = "libSerialSCF.so";
 static const auto TCP_SCFDllName = "libTcpipSCF.so";
 static const float msSteps[] = {
-	40,  50,  60,  80,  100,  120,  160,
-	200,  250,  320,  400,  500,  630,  800,
+	100,  120,  160,  200,  250,  320,  400,  500,  630,  800,
 	1000,  1250,  1600,  2000
 };
 
@@ -149,14 +149,12 @@ static bool DecodeFrame(const char* data, int len) {
 
 atomic<int> nsGEN::PSGHDDevice::m_iLoopTime = PSGHD_LoopDefHBTime;
 atomic<bool> nsGEN::PSGHDDevice::m_bExtraFlag = false;
-static atomic<bool>HeartBeatFlag = false;
 
 nsGEN::PSGHDDevice::PSGHDDevice(std::shared_ptr <IOEventCenter> center, std::shared_ptr<SCFWrapper> SCF, string configfile)
 	: super(center)
 	, superGen()
 	,m_SCF(SCF)
 	, m_bConnectFlag(false)
-	, HeartBeatFlag(false)
 {
 	m_bExtraFlag = true;
 
@@ -477,6 +475,13 @@ RET_STATUS nsGEN::PSGHDDevice::SetFocus(int value)
 RET_STATUS nsGEN::PSGHDDevice::Reset()
 {
 	FINFO("clear all errors \n");
+	char errorCodeStr[20];
+	snprintf(errorCodeStr, sizeof(errorCodeStr), "PSGHD_FLT_0");
+	int level = 1;
+
+	m_MSGUnit->DelWarnMessage(errorCodeStr, level, "");
+	m_MSGUnit->DelErrorMessage(errorCodeStr, level, "");
+	FINFO("HWFLT: Fault cleared (fault code 0)");
 	return HWSend("CLR",3);//仅重置错误状态
 }
 
@@ -652,14 +657,18 @@ RET_STATUS nsGEN::PSGHDDevice::SetFrameRate(float frameRate)
 RET_STATUS nsGEN::PSGHDDevice::SetExpEnable() 
 {
 	FINFO("SetExpEnable in\n");
-	m_bExpEnable = true;
-	return HWSend("ENBL 1", 6);
+	return HWSend("DSW 1", 5);
 }
 RET_STATUS nsGEN::PSGHDDevice::SetExpDisable() 
 {
 	FINFO("SetExpDisable in\n");
-	m_bExpEnable = false;
-	return HWSend("ENBL 0", 6);
+	return HWSend("DSW 0", 5);
+}
+
+RET_STATUS nsGEN::PSGHDDevice::PrepareAcquisition()
+{
+	FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
+	return RET_STATUS::RET_SUCCEED;
 }
 
 //-----------------------------------------------------------------------------
@@ -684,32 +693,26 @@ RET_STATUS nsGEN::PSGHDDevice::HWSend(const char* strCommand, int length, bool r
 		FINFO("Failed - Device not connected");
 		return RET_STATUS::RET_FAILED;
 	}
-	// 构造协议格式:<STX>CMD<SP>ARG;<CS><CR><LF>
+	// 构造新协议格式:<Command><Data><ETX><Checksum>
 	char strSendCommand[100] = { 0 };
 	int len = 0;
-	strSendCommand[len++] = 0x02; // STX
 
 	// 复制命令部分
 	memcpy(strSendCommand + len, strCommand, length);
 	len += length;
 
-	// 添加分号
-	strSendCommand[len++] = ';';
+	// 添加ETX结束符(0x03)
+	strSendCommand[len++] = 0x03;
 
-	// 计算校验和(从STX后开始到分号';')
-	uint16_t sum = 0;
-	for (int i = 1; i < len; i++)
-	{
-		sum += (uint8_t)strSendCommand[i];
+	// 计算校验和:Command + Data + ETX的累加和取低位
+	uint8_t checksum = 0;
+	for (int i = 0; i < len; i++) {  // 从首字节到ETX全部参与计算
+		checksum += (uint8_t)strSendCommand[i];
 	}
-	uint8_t checksum = (uint8_t)(sum & 0xFF);
-	checksum = 0x100 - checksum;
-	checksum &= 0x7F;
-	checksum |= 0x40;
+	checksum &= 0xFF;  // 取累加和的低8位
 
+	// 添加校验和
 	strSendCommand[len++] = checksum;
-	strSendCommand[len++] = 0x0D; // CR
-	strSendCommand[len++] = 0x0A; // LF
 
 
 	// 打印数据包前16字节的十六进制(含控制字符)便于调试
@@ -929,16 +932,16 @@ void nsGEN::PSGHDDevice::OnCallBack()
 			if (faultCode != 0)
 			{
 				static const std::unordered_map<int, std::string> errorMessages = {
-					{2, "充电回路异常"}, {3, "存储芯片损坏"}, {136, "灯丝电流1超过限值"},
-					{140, "阳极kV超过限值,曝光异常中止"}, {142, "高压发生器或球管打火,曝光异常中止"},
-					{165, "高压发生器启动过程中,母线电压过低"}, {205, "高压发生器唤醒或启动过程中二级手闸被按下"},
-					{206, "高压发生器电池电量低,请充电"}, {208, "曝光时间间隔较短,请稍后曝光"},
-					{209, "曝光过程中禁止调节参数"}, {210, "一级手闸重复触发,请使用单一手闸执行曝光操作"},
-					{216, "电池充电中"}, {218, "kV参数超过限值"}, {219, "mA参数超过限值"},
-					{220, "ms参数超过限值"}, {229, "高压发生器功率超过限值"}, {230, "球管功率超过限值"},
-					{231, "帧频参数超过限值"}, {249, "高压发生器母线电压超过限值"}, {255, "kV建立超时"},
-					{259, "曝光过程中提前松开手闸"}, {260, "曝光过程中禁止调节参数"}, {263, "曝光过程中kV过高,曝光异常中止"},
-					{267, "曝光过程中mA过低,曝光异常中止"}, {268, "曝光过程中mA过高,曝光异常中止"}, {281, "曝光过程中功率超过限值,曝光异常中止"}
+				{2, "Charging circuit abnormal"}, {3, "Storage chip damaged"}, {136, "Filament current 1 exceeds limit"},
+				{140, "Anode kV exceeds limit, exposure aborted abnormally"}, {142, "High-voltage generator or tube arcing, exposure aborted abnormally"},
+				{165, "Bus voltage too low during high-voltage generator startup"}, {205, "Second-stage handswitch pressed during high-voltage generator wake-up or startup"},
+				{206, "High-voltage generator low battery, please charge"}, {208, "Exposure interval too short, please expose later"},
+				{209, "Parameter adjustment forbidden during exposure"}, {210, "First-stage handswitch repeated triggering, please use a single handswitch for exposure operation"},
+				{216, "Battery being charged"}, {218, "kV parameter exceeds limit"}, {219, "mA parameter exceeds limit"},
+				{220, "ms parameter exceeds limit"}, {229, "High-voltage generator power exceeds limit"}, {230, "Tube power exceeds limit"},
+				{231, "Frame rate parameter exceeds limit"}, {249, "High-voltage generator bus voltage exceeds limit"}, {255, "kV establishment timeout"},
+				{259, "Handswitch released in advance during exposure"}, {260, "Parameter adjustment forbidden during exposure"}, {263, "kV too high during exposure, exposure aborted abnormally"},
+				{267, "mA too low during exposure, exposure aborted abnormally"}, {268, "mA too high during exposure, exposure aborted abnormally"}, {281, "Power exceeds limit during exposure, exposure aborted abnormally"}
 				};
 				static const std::unordered_set<int> firstSixErrors = { 2, 3, 136, 140, 142, 165 };
 
@@ -975,7 +978,11 @@ void nsGEN::PSGHDDevice::OnCallBack()
 				FINFO("HWPhase: Invalid data length ({$} < 3), skip", length);
 				return;
 			}
-
+			// 设备首次连接时禁止曝光!
+			if (m_isFirstHWPhase) {
+				SetExpDisable();
+				m_isFirstHWPhase = false; 
+			}
 			char phaseCodeStr[4] = { 0 };
 			strncpy(phaseCodeStr, data, 3);
 			int phaseCode = atoi(phaseCodeStr);
@@ -1075,7 +1082,7 @@ void nsGEN::PSGHDDevice::OnCallBack()
 			{
 				if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY))
 				{
-					FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
+					//FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
 					FINFO("HWEOK: Device ready, status updated to STANDBY");
 				}
 			}
@@ -1083,12 +1090,35 @@ void nsGEN::PSGHDDevice::OnCallBack()
 			{
 				if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_SLEEP))
 				{
-					FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
+					//FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
 					FINFO("HWEOK: Device not ready, status updated to SLEEP");
 				}
 			}
 		};
 
+	auto HWDSW = [this](const char* data, int length) -> void
+		{
+			if (length < 1) { // 需1字节(X)
+				FINFO("HWDSW: Invalid data length ({$} < 1), skip", length);
+				return;
+			}
+
+			char eokStr = data[0]; // 直接取data[0]
+			bool isReady = (eokStr == '1');
+
+			if (isReady && m_DoseUnit.m_GenState->Get()== nsGEN::AttrKey::GENERATOR_STATUS_STANDBY)
+			{
+				FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
+				FINFO("HWDSW: Device ready, status updated to STANDBY");
+			}
+			else
+			{
+				m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_SLEEP);
+				FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
+				FINFO("HWDSW: Device not ready, status updated to SLEEP");
+			}
+		};
+
 	auto HWECD = [this](const char* data, int length) -> void
 		{
 			if (length < 3) { // 需3字节(XXX)
@@ -1381,7 +1411,6 @@ void PSGHDDevice::HardwareStatusThread(PSGHDDevice* pParam)
 	}
 
 	PSGHDDevice* pCurGen = pParam;
-	pCurGen->HeartBeatFlag = true;
 
 	int messageIndex = 0;
 
@@ -1392,7 +1421,7 @@ void PSGHDDevice::HardwareStatusThread(PSGHDDevice* pParam)
 		Sleep(currentLoopTime);
 
 		// 每5次循环发送状态查询命令
-		if (messageIndex % 5 == 0)
+		if (messageIndex % 5 == 0&& !pCurGen->m_bSleepState)
 		{
 			pCurGen->HWSend("RHE", 3);
 			Sleep(100);
@@ -1411,7 +1440,6 @@ void PSGHDDevice::HardwareStatusThread(PSGHDDevice* pParam)
 	}
 
 	// 线程退出时重置心跳标志
-	pCurGen->HeartBeatFlag = false;
 }
 
 //-----------------------------------------------------------------------------
@@ -1433,12 +1461,24 @@ nsGEN::PSGHDDriver::~PSGHDDriver()
 void nsGEN::PSGHDDriver::Prepare()
 {
 	// 初始化日志系统
-	string strLogPath = GetProcessDirectory() + R"(\Conf\log_config.xml)";
-	if (!Log4CPP::init("DevPSGHD", "GEN.PSG_HD", strLogPath, true)) {
-		std::cerr << "Failed to initialize log system! Using default configuration." << std::endl;
-		// 即使配置文件加载失败,也可以继续使用默认配置
+	std::string strLogPath = GetProcessDirectory() + R"(/Conf/log_config.xml)";
+	std::string LogHost = "DevPSGHD"; 
+	std::string moduleName = "DevPSGHD";
+	bool ret = initLogModule(
+		LogHost,       // 主机名(用于日志路径中的{host}占位符)
+		moduleName,        // 唯一模块名
+		strLogPath,  // 配置文件路径
+		true           // 是否输出到控制台(可选)
+	);
+	if (!ret) {
+		std::cerr << "Log init failed!" << std::endl;
+		return;
 	}
+	PSGHDSetLocalModuleName(moduleName);
+
 	m_SCFDllName = GetConnectDLL(m_ConfigFileName);
+
+	// 绑定当前动态库的模块名(调用自身实现的接口)
 	FINFO("Prepare is OK.SCFDllName is {$}", m_SCFDllName);
 }
 
@@ -1496,38 +1536,84 @@ bool nsGEN::PSGHDDriver::ReConnection()
 bool nsGEN::PSGHDDriver::Connect()
 {
 	std::lock_guard<std::mutex> lock(m_connectionMutex);
+	const auto currentState = m_connectionState.load();
+	auto now = std::chrono::steady_clock::now();
 
-	if (m_connectionState.load() == ConnectionState::Failed) {
-		auto now = std::chrono::steady_clock::now();
+	// 1. 处理可重试的失败状态
+	if (currentState == ConnectionState::Failed) {
 		if ((now - m_lastConnectionAttempt) >= RETRY_INTERVAL && m_connectionRetryCount < MAX_RETRY_COUNT) {
-			m_connectionState.store(ConnectionState::Disconnected); // 合法:非const函数
+			m_connectionState = ConnectionState::Disconnected;
+		}
+		else {
+			return false; // 不满足重试条件,直接返回
 		}
 	}
 
-	if (m_connectionState.load() == ConnectionState::Connected ||
-		m_connectionState.load() == ConnectionState::Connecting) {
-		FINFO("Already connected or connecting");
+	// 2. 检查无效状态(正在连接/已连接但实际有效)
+	if (currentState == ConnectionState::Connecting) {
+		FINFO("Already connecting (type: {$})",
+			m_currentConnType == ConnectionType::Serial ? "Serial" : "Ethernet");
+		return true;
+	}
+	if (currentState == ConnectionState::Connected && m_scfWrapper && m_scfWrapper->IsConnected()) {
+		FINFO("Already connected (type: {$})",
+			m_currentConnType == ConnectionType::Serial ? "Serial" : "Ethernet");
 		return true;
 	}
 
-	auto now = std::chrono::steady_clock::now();
-	if ((now - m_lastConnectionAttempt) < RETRY_INTERVAL && m_connectionRetryCount > 0) {
-		FINFO("Too soon to retry connection");
+	// 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(),
+			m_currentConnType == ConnectionType::Serial ? "Serial" : "Ethernet");
 		return false;
 	}
 
-	m_connectionState.store(ConnectionState::Connecting);
-	m_lastConnectionAttempt = now;
-	m_connectionRetryCount++;
+	ResDataObject connParam = GetConnectParam(m_ConfigFileName);
+	std::string connPortStr = "";
+	std::string connTypeStr = (std::string)connParam["type"];  // 从配置读取type字段
+	m_currentConnType = (connTypeStr == "COM") ? ConnectionType::Serial : ConnectionType::Ethernet;
+	if (m_currentConnType == ConnectionType::Serial)
+	{
+		connPortStr = (std::string)connParam["port"];// 从配置读取port字段
+		// 查找配置端口在现有端口列表中的位置
+		auto it = std::find(m_serialPorts.begin(), m_serialPorts.end(), connPortStr);
+
+		if (it == m_serialPorts.end()) {
+			// 配置的端口不在列表中,添加到首位
+			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()) {
+			// 配置的端口存在但不在首位,移动到首位
+			FINFO("Moving configured serial port {$} to front of port list", connPortStr);
+			m_serialPorts.erase(it);
+			m_serialPorts.insert(m_serialPorts.begin(), connPortStr);
+		}
 
-	FINFO("Enter {$},configlef={$}\n", __FUNCTION__, m_ConfigFileName.c_str());
-	ResDataObject Connection = GetConnectParam(m_ConfigFileName);
-	FINFO("connections:{$} \n", Connection.encode());
+	}
+	// 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());  // 将当前尝试的端口写入参数
+			connInfo = "Serial (port: " + currentPort + ")";
+		}
+		else {
+			// 网口连接:直接使用配置参数
+			connInfo = "Ethernet (ip: " + std::string(connParam["ip"]) + ")";
+		}
+
+		FINFO("Enter Connect ({$}), config: {$}", connInfo, connParam.encode());
+
 		if (!m_scfWrapper->Initialize(m_SCFDllName)) {
-			FINFO("Failed to initialize SCFWrapper: {$}", m_scfWrapper->GetLastError());
-			m_connectionState.store(ConnectionState::Failed);
+			FINFO("Init failed: {$}", m_scfWrapper->GetLastError());
+			m_connectionState = ConnectionState::Failed;
 			return false;
 		}
 
@@ -1535,27 +1621,49 @@ bool nsGEN::PSGHDDriver::Connect()
 			this->Dequeue(data, length);
 			});
 
-		auto erCode = m_scfWrapper->Connect(Connection, &PSGHDDriver::callbackPackageProcess, SCF_NORMAL_TRANSFER, 3000);
-		if (erCode != SCF_SUCCEED) {
-			FINFO("Connection failed with error code: {$}", erCode);
-			m_connectionState.store(ConnectionState::Failed);
-			return false;
-		}
+		auto erCode = m_scfWrapper->Connect(connParam, &PSGHDDriver::callbackPackageProcess, SCF_NORMAL_TRANSFER, 3000);
+		if (erCode != SCF_SUCCEED || !m_scfWrapper->StartAutoReceive()) {
+			FINFO("Connect failed (code: {$}) for {$}", erCode, connInfo);
+			m_scfWrapper->Disconnect();
+			m_connectionState = ConnectionState::Failed;
+			// 串口连接:未遍历完所有端口时,优先切换端口重试(不计入总重试次数)
+			if (m_currentConnType == ConnectionType::Serial) {
+				int nextIndex = (m_currentSerialPortIndex + 1) % m_serialPorts.size();
+				// 判断是否已遍历所有端口(当前索引是最后一个时,nextIndex会回到0)
+				bool allPortsTried = (nextIndex == 0);
+
+				if (!allPortsTried) {
+					// 未遍历完所有端口:切换到下一端口,不增加重试计数
+					m_currentSerialPortIndex = nextIndex;
+					m_connectionRetryCount = 0;
+					FINFO("Trying next serial port: {$}", m_serialPorts[nextIndex]);
+					return false; // 触发外部线程立即尝试下一端口
+				}
+				else {
+					// 已遍历所有端口:重置到第一个端口,增加重试计数(进入间隔等待)
+					m_currentSerialPortIndex = 0;
+					m_connectionRetryCount++;
+					FINFO("All serial ports tried, retry count: {$}/{$}", m_connectionRetryCount, MAX_RETRY_COUNT);
+					return false;
+				}
+			}
 
-		if (!m_scfWrapper->StartAutoReceive()) {
-			FINFO("Failed to start auto receive");
-			m_connectionState.store(ConnectionState::Failed);
+			// 所有端口失败(串口)或网口失败,才增加总重试计数
+			m_connectionRetryCount++;
 			return false;
 		}
 
-		m_connectionState.store(ConnectionState::Connected);
+		// 连接成功:重置状态
+		m_connectionState = ConnectionState::Connected;
 		m_connectionRetryCount = 0;
-		FINFO("Connection established successfully");
+		m_currentSerialPortIndex = 0;  // 重置串口端口索引
+		FINFO("Connected successfully ({$})", connInfo);
 		return true;
 	}
 	catch (const std::exception& e) {
-		FINFO("Exception during connection: {$}", e.what());
-		m_connectionState.store(ConnectionState::Failed);
+		FINFO("Exception for {$}: {$}", connInfo, e.what());
+		m_connectionState = ConnectionState::Failed;
+		m_connectionRetryCount++;
 		return false;
 	}
 }
@@ -1578,31 +1686,39 @@ void nsGEN::PSGHDDriver::FireNotify(int code, std::string key, std::string conte
 
 bool nsGEN::PSGHDDriver::isConnected() const
 {
-	FINFO("isConnected in");
-	if (m_connectionState.load() == ConnectionState::Connecting) {
-		FINFO("Connection in progress, skipping additional connect attempts");
-		return true;
-	}
+	const auto state = m_connectionState.load();
 
-	if (m_scfWrapper && m_scfWrapper->IsConnected()) {
-		FINFO("m_scfWrapper->IsConnected()");
+	// 1. 连接中/实际已连接:返回true(无需重连)
+	if (state == ConnectionState::Connecting || (m_scfWrapper && m_scfWrapper->IsConnected())) {
+		FINFO(state == ConnectionState::Connecting ? "Connecting in progress" : "Already connected");
 		return true;
 	}
 
-	auto now = std::chrono::steady_clock::now();
-	auto timeSinceLastAttempt = now - m_lastConnectionAttempt;
+	// 2. 失败状态处理:判断是否允许重试
+	if (state == ConnectionState::Failed) {
+		auto now = std::chrono::steady_clock::now();
+		const auto timeSinceLast = now - m_lastConnectionAttempt;
 
-	if (m_connectionState.load() == ConnectionState::Failed) {
-		if (timeSinceLastAttempt < RETRY_INTERVAL) {
-			FINFO("Too soon to retry connection");
-			return false;
+		// 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函数可修改)
 		}
-		if (m_connectionRetryCount >= MAX_RETRY_COUNT) {
-			FINFO("Max connection retries exceeded");
-			return false;
+
+		// 2.2 不适合重连(时间未到 或 次数仍超限):返回true阻止重连
+		if (timeSinceLast < RETRY_INTERVAL || m_connectionRetryCount >= MAX_RETRY_COUNT) {
+			FINFO(timeSinceLast < RETRY_INTERVAL ?
+				"Retry later ({$}s)" : "Max retries, waiting {$}s to reset",
+				std::chrono::duration_cast<std::chrono::seconds>(
+					timeSinceLast < RETRY_INTERVAL ? RETRY_INTERVAL - timeSinceLast : RESET_RETRY_AFTER - timeSinceLast
+				).count()
+			);
+			return true;
 		}
 	}
 
+	// 3. 其他情况(适合重连):返回false触发Connect()
 	return false;
 }
 

+ 17 - 3
Generator/PSG/CCOS.Dev.Generator.PSG_HD/CCOS.Dev.Generator.PSG_HD.h

@@ -85,6 +85,7 @@ namespace CCOS::Dev::Detail::Generator
 		virtual RET_STATUS QueryPostMAS(float& value) override;
 		virtual RET_STATUS SetExpEnable() override;
 		virtual RET_STATUS SetExpDisable()override;
+		virtual RET_STATUS PrepareAcquisition()override;
 		virtual RET_STATUS Reset()override;
 		virtual RET_STATUS ActiveSyncMode(_tSyncModeArgs value) override;
 		virtual RET_STATUS SetCollimatorLight(unsigned short value) override;
@@ -127,7 +128,6 @@ namespace CCOS::Dev::Detail::Generator
 		ResDataObject m_GenConfig;  //driver's config file.
 		std::shared_ptr<SCFWrapper> m_SCF;
 		std::shared_ptr<IODeviceDetail> pIODriver;
-		bool HeartBeatFlag;
 		//线程变量互斥锁
 		atomic<int> m_iReSendCMD;	                  //初始命令重发次数
 		static atomic<int>  m_iLoopTime;	          //循环间隔时间(毫秒)
@@ -140,7 +140,7 @@ namespace CCOS::Dev::Detail::Generator
 		int                 m_iGridMSAECMargin;       //震动栅ms自动曝光误差(500-2000ms)
 		static atomic<bool> m_bExtraFlag;	          //使用标记
 
-		bool m_bSleepState{ false };
+		atomic<bool> m_bSleepState{ false };
 		bool m_bGenBusy;
 		int m_nCtlMode;
 		bool m_bUseCECmd;
@@ -160,6 +160,7 @@ namespace CCOS::Dev::Detail::Generator
 		std::thread m_pHardwareStatusThread;               //轮询线程句柄
 		std::thread m_pHardwareRsSendThread;               //重发线程句柄
 		std::shared_ptr<LinuxEvent> m_hGenPostEvent;
+		bool m_isFirstHWPhase = true;
 		atomic<bool> m_bExpEnable;	                  //曝光使能
 		atomic<bool> m_bInvalidKVMASSetupFlag;        //写入到设备的曝光设置无效
 		atomic<bool> m_bFaultList[18];	              //记录 主机请求固件报告故障命令 返回的故障记录
@@ -243,13 +244,26 @@ namespace CCOS::Dev::Detail::Generator
 			Failed
 		};
 
+		enum class ConnectionType {
+			Serial,       // 串口
+			Ethernet      // 网口
+		};
+
 		std::atomic<ConnectionState> m_connectionState{ ConnectionState::Disconnected };
 		std::chrono::steady_clock::time_point m_lastConnectionAttempt;
 		std::mutex m_connectionMutex;
-		int m_connectionRetryCount{ 0 };
+		const std::chrono::seconds RESET_RETRY_AFTER{ 60 };
+
+		// 修改成员变量定义,添加mutable允许const函数修改
+		mutable int m_connectionRetryCount{ 0 };  // 关键:用mutable修饰
 		const int MAX_RETRY_COUNT = 3;
 		const std::chrono::seconds RETRY_INTERVAL{ 5 };
 
+		// 串口相关(固定支持的端口,可从配置扩展)
+		std::vector<std::string> m_serialPorts{ "/dev/ttyUSB0", "/dev/ttyUSB1", "/dev/ttyUSB3", "/dev/ttyUSB4" };
+		int m_currentSerialPortIndex{ 0 };  // 当前尝试的串口端口索引
+		ConnectionType m_currentConnType{ ConnectionType::Serial };
+
 		//webconfig使用
 		ResDataObject m_DeviceConfigSend;
 		string g_strAppPath;

+ 2 - 0
Generator/PSG/CCOS.Dev.Generator.PSG_HD/CMakeLists.txt

@@ -43,6 +43,8 @@ message(STATUS "包含交付头文件目录: ${DELIVER_INCLUDE_DIR}")
 set(SRC_FILES
     CCOS.Dev.Generator.PSG_HD.cpp
     CCOS.Dev.Generator.PSG_HD.h
+    LogLocalHelper.cpp
+    LogLocalHelper.h
 	${PhysicalDevice_DELIVER_INCLUDE_DIR}/CCOS.Dev.MSGMould.hpp
 	${PhysicalDevice_DELIVER_INCLUDE_DIR}/CCOS.Dev.MSGMould.cpp
 	${PhysicalDevice_DELIVER_INCLUDE_DIR}/Base64.h

+ 19 - 0
Generator/PSG/CCOS.Dev.Generator.PSG_HD/LogLocalHelper.cpp

@@ -0,0 +1,19 @@
+// LogLocalHelper.cpp
+#include "LogLocalHelper.h"
+#include <string>
+#include <iostream>
+
+// 使用线程局部存储:确保每个动态库有独立的模块名副本
+static std::string s_localModuleName;
+
+// 初始化当前动态库的局部模块名(在调用initLogModule后立即调用)
+void PSGHDSetLocalModuleName(const std::string& moduleName) {
+    std::cout << "GEN setLocalModuleName" << moduleName << std::endl;
+    s_localModuleName = moduleName;
+}
+
+// 获取当前动态库的局部模块名(日志输出时调用)
+const std::string& PSGHDGetLocalModuleName() {
+    std::cout << "GEN getLocalModuleName" << s_localModuleName << std::endl;
+    return s_localModuleName;
+}

+ 28 - 0
Generator/PSG/CCOS.Dev.Generator.PSG_HD/LogLocalHelper.h

@@ -0,0 +1,28 @@
+// LogLocalHelper.h
+#ifndef LOG_LOCAL_HELPER_H
+#define LOG_LOCAL_HELPER_H
+#include <string>
+#include "Log4CPP.h"
+
+void PSGHDSetLocalModuleName(const std::string& moduleName);
+const std::string& PSGHDGetLocalModuleName();
+
+// 重定义日志宏:使用当前动态库的局部模块名getLocalModuleName()
+#define LOG(level, format, ...) \
+    do { \
+        const std::string& localModule = PSGHDGetLocalModuleName(); \
+        LogInstance* logger = LogManager::getInstance().getInstance(localModule); \
+        if (logger && logger->isInitialized()) { \
+            logger->log(log4cpp::Priority::level, __FILE__, __LINE__, __FUNCTION__, format, ##__VA_ARGS__); \
+        } else { \
+            std::cerr << "[" << localModule << "] PSGHD_Logger not initialized or module not found!" << std::endl; \
+        } \
+    } while(0)
+
+// 保留原有的级别宏(无需修改,依赖重定义后的LOG)
+#define FDEBUG(format, ...) LOG(DEBUG, format, ##__VA_ARGS__)
+#define FINFO(format, ...)  LOG(INFO,  format, ##__VA_ARGS__)
+#define FWARN(format, ...)  LOG(WARN,  format, ##__VA_ARGS__)
+#define FERROR(format, ...) LOG(ERROR, format, ##__VA_ARGS__)
+
+#endif // LOG_LOCAL_HELPER_H

BIN
Generator/PSG/CCOS.Dev.Generator.PSG_HR/CCOS.Dev.Generator.PSG_HR.aps


Dosya farkı çok büyük olduğundan ihmal edildi
+ 241 - 318
Generator/PSG/CCOS.Dev.Generator.PSG_HR/CCOS.Dev.Generator.PSG_HR.cpp


+ 29 - 0
Generator/PSG/CCOS.Dev.Generator.PSG_HR/CCOS.Dev.Generator.PSG_HR.h

@@ -84,6 +84,7 @@ namespace CCOS::Dev::Detail::Generator
 		virtual RET_STATUS QueryPostMAS(float& value) override;
 		virtual RET_STATUS SetExpEnable() override;
 		virtual RET_STATUS SetExpDisable()override;
+		virtual RET_STATUS PrepareAcquisition()override;
 		virtual RET_STATUS Reset()override;
 		virtual RET_STATUS ActiveSyncMode(_tSyncModeArgs value) override;
 		RET_STATUS RefreshData();
@@ -168,6 +169,7 @@ namespace CCOS::Dev::Detail::Generator
 		int                 m_iGridMSAECMargin;       //震动栅ms自动曝光误差(500-2000ms)
 		static atomic<bool> m_bExtraFlag;	          //使用标记
 
+		bool m_isFirstHWPhase = true;
 		bool m_bGenBusy;
 		int m_nCtlMode;
 		bool m_bUseCECmd;
@@ -263,6 +265,33 @@ namespace CCOS::Dev::Detail::Generator
 		ResDataObject m_ConfigAll; //存储当前的配置,用于修改配置时写回文件
 		ResDataObject m_Configurations; //存储当前配置中“CONFIGURATION”节点的内容
 
+		enum class ConnectionState {
+			Disconnected,
+			Connecting,
+			Connected,
+			Failed
+		};
+
+		enum class ConnectionType {
+			Serial,       // 串口
+			Ethernet      // 网口
+		};
+
+		std::atomic<ConnectionState> m_connectionState{ ConnectionState::Disconnected };
+		std::chrono::steady_clock::time_point m_lastConnectionAttempt;
+		std::mutex m_connectionMutex;
+		const std::chrono::seconds RESET_RETRY_AFTER{ 60 };
+
+		// 修改成员变量定义,添加mutable允许const函数修改
+		mutable int m_connectionRetryCount{ 0 };  // 关键:用mutable修饰
+		const int MAX_RETRY_COUNT = 3;
+		const std::chrono::seconds RETRY_INTERVAL{ 5 };
+
+		// 串口相关(固定支持的端口,可从配置扩展)
+		std::vector<std::string> m_serialPorts{ "/dev/ttyUSB0", "/dev/ttyUSB1", "/dev/ttyUSB3", "/dev/ttyUSB4" };
+		int m_currentSerialPortIndex{ 0 };  // 当前尝试的串口端口索引
+		ConnectionType m_currentConnType{ ConnectionType::Serial };
+
 		//webconfig使用
 		ResDataObject m_DeviceConfigSend;
 		string g_strAppPath;

+ 0 - 100
Generator/PSG/CCOS.Dev.Generator.PSG_HR/CCOS.Dev.Generator.PSG_HR.rc

@@ -1,100 +0,0 @@
-// Microsoft Visual C++ generated resource script.
-//
-#include "resource.h"
-
-#define APSTUDIO_READONLY_SYMBOLS
-/////////////////////////////////////////////////////////////////////////////
-//
-// Generated from the TEXTINCLUDE 2 resource.
-//
-#include "winres.h"
-
-/////////////////////////////////////////////////////////////////////////////
-#undef APSTUDIO_READONLY_SYMBOLS
-
-/////////////////////////////////////////////////////////////////////////////
-// 中文(简体,中国) resources
-
-#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
-LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
-#pragma code_page(936)
-
-#ifdef APSTUDIO_INVOKED
-/////////////////////////////////////////////////////////////////////////////
-//
-// TEXTINCLUDE
-//
-
-1 TEXTINCLUDE 
-BEGIN
-    "resource.h\0"
-END
-
-2 TEXTINCLUDE 
-BEGIN
-    "#include ""winres.h""\r\n"
-    "\0"
-END
-
-3 TEXTINCLUDE 
-BEGIN
-    "\r\n"
-    "\0"
-END
-
-#endif    // APSTUDIO_INVOKED
-
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// Version
-//
-
-VS_VERSION_INFO VERSIONINFO
- FILEVERSION 3,1,0,1
- PRODUCTVERSION 3,1,0,1
- FILEFLAGSMASK 0x3fL
-#ifdef _DEBUG
- FILEFLAGS 0x1L
-#else
- FILEFLAGS 0x0L
-#endif
- FILEOS 0x40004L
- FILETYPE 0x2L
- FILESUBTYPE 0x0L
-BEGIN
-    BLOCK "StringFileInfo"
-    BEGIN
-        BLOCK "080404b0"
-        BEGIN
-            VALUE "CompanyName", "E-COM Technology Ltd."
-            VALUE "FileDescription", "Ccos V3 Generator Device with Json"
-            VALUE "FileVersion", "3.1.0.1"
-            VALUE "InternalName", "Gen_PSG_HR  (Json and Module)"
-            VALUE "LegalCopyright", "Copyright (C) 2024"
-            VALUE "OriginalFilename", "CCOS.Dev.Generator.PSG_HR64.dll"
-            VALUE "ProductName", "Ccos V3 Generator.PSG_HR"
-            VALUE "ProductVersion", "3.1.0.1"
-        END
-    END
-    BLOCK "VarFileInfo"
-    BEGIN
-        VALUE "Translation", 0x804, 1200
-    END
-END
-
-#endif    // 中文(简体,中国) resources
-/////////////////////////////////////////////////////////////////////////////
-
-
-
-#ifndef APSTUDIO_INVOKED
-/////////////////////////////////////////////////////////////////////////////
-//
-// Generated from the TEXTINCLUDE 3 resource.
-//
-
-
-/////////////////////////////////////////////////////////////////////////////
-#endif    // not APSTUDIO_INVOKED
-

+ 0 - 214
Generator/PSG/CCOS.Dev.Generator.PSG_HR/CCOS.Dev.Generator.PSG_HR.vcxproj

@@ -1,214 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <ItemGroup Label="ProjectConfigurations">
-    <ProjectConfiguration Include="Debug|Win32">
-      <Configuration>Debug</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-    <ProjectConfiguration Include="Release|Win32">
-      <Configuration>Release</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-    <ProjectConfiguration Include="Debug|x64">
-      <Configuration>Debug</Configuration>
-      <Platform>x64</Platform>
-    </ProjectConfiguration>
-    <ProjectConfiguration Include="Release|x64">
-      <Configuration>Release</Configuration>
-      <Platform>x64</Platform>
-    </ProjectConfiguration>
-  </ItemGroup>
-  <PropertyGroup Label="Globals">
-    <VCProjectVersion>16.0</VCProjectVersion>
-    <Keyword>Win32Proj</Keyword>
-    <ProjectGuid>{F3556EEF-9B29-4729-8D4E-4A45E1291E19}</ProjectGuid>
-    <RootNamespace>CCOSDevGeneratorPSGHR</RootNamespace>
-    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
-    <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <UseDebugLibraries>true</UseDebugLibraries>
-    <PlatformToolset>v143</PlatformToolset>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
-    <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <UseDebugLibraries>false</UseDebugLibraries>
-    <PlatformToolset>v143</PlatformToolset>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
-    <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <UseDebugLibraries>true</UseDebugLibraries>
-    <PlatformToolset>v143</PlatformToolset>
-    <CharacterSet>MultiByte</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
-    <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <UseDebugLibraries>false</UseDebugLibraries>
-    <PlatformToolset>v143</PlatformToolset>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-    <CharacterSet>MultiByte</CharacterSet>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
-  <ImportGroup Label="ExtensionSettings">
-  </ImportGroup>
-  <ImportGroup Label="Shared">
-  </ImportGroup>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <PropertyGroup Label="UserMacros" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <LinkIncremental>true</LinkIncremental>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <LinkIncremental>false</LinkIncremental>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
-    <LinkIncremental>true</LinkIncremental>
-    <OutDir>$(SolutionDir)\BIN\</OutDir>
-    <IntDir>$(SolutionDir)\TEMP\$(Configuration).$(Platform)\$(ProjectName)\</IntDir>
-    <TargetName>$(ProjectName)64D</TargetName>
-    <IncludePath>..\..\..\deliver\include;$(VC_IncludePath);$(WindowsSDK_IncludePath)</IncludePath>
-    <LibraryPath>..\..\..\deliver\lib\$(Configuration)X64;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64)</LibraryPath>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
-    <LinkIncremental>false</LinkIncremental>
-    <TargetName>$(ProjectName)64</TargetName>
-    <OutDir>D:\产品\DROC\1.bin\DeviceV3\OEMDrivers\Generator\PSGHR</OutDir>
-    <IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);..\..\..\..\..\Deliver\Include\Log4CPP\Log.Include;..\..\..\..\..\Deliver\Include\Log4CPP\Common.Include;..\..\..\..\..\Deliver\include;..\..\..\Deliver\include;..\..\..\Deliver\include\fmt;..\..\..\..\Deliver\Include\Log4CPP\Log.Include;..\..\..\..\Deliver\include\Log4CPP\Common.Include</IncludePath>
-    <LibraryPath>$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);..\..\..\Deliver\lib\$(Configuration)X64;..\..\..\..\..\Deliver\lib\$(Configuration)X64;..\..\..\..\..\Deliver\lib\$(Configuration)X64\Log4CPP;..\..\..\Deliver\lib\$(Configuration)X64\fmt</LibraryPath>
-  </PropertyGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <SDLCheck>true</SDLCheck>
-      <PreprocessorDefinitions>WIN32;_DEBUG;CCOSDevGeneratorPSGHR_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <ConformanceMode>true</ConformanceMode>
-      <PrecompiledHeader>Use</PrecompiledHeader>
-      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
-      <LanguageStandard>stdcpp17</LanguageStandard>
-    </ClCompile>
-    <Link>
-      <SubSystem>Windows</SubSystem>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <EnableUAC>false</EnableUAC>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <SDLCheck>true</SDLCheck>
-      <PreprocessorDefinitions>WIN32;NDEBUG;CCOSDevGeneratorPSGHR_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <ConformanceMode>true</ConformanceMode>
-      <PrecompiledHeader>Use</PrecompiledHeader>
-      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
-    </ClCompile>
-    <Link>
-      <SubSystem>Windows</SubSystem>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <OptimizeReferences>true</OptimizeReferences>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <EnableUAC>false</EnableUAC>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <SDLCheck>true</SDLCheck>
-      <PreprocessorDefinitions>WIN32;_DEBUG;CCOSDEVGENEPSGHR_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <ConformanceMode>Default</ConformanceMode>
-      <PrecompiledHeader>Use</PrecompiledHeader>
-      <PrecompiledHeaderFile>stdafx.h</PrecompiledHeaderFile>
-      <LanguageStandard>stdcpp17</LanguageStandard>
-    </ClCompile>
-    <Link>
-      <SubSystem>Windows</SubSystem>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <EnableUAC>true</EnableUAC>
-      <AdditionalLibraryDirectories>..\BIN</AdditionalLibraryDirectories>
-    </Link>
-    <PostBuildEvent>
-      <Command>copy "$(OutDir)$(TargetName)$(TargetExt)" "..\..\..\deliver\bin\$(Configuration)X64" 
-copy "$(OutDir)$(TargetName).lib" "..\..\..\deliver\lib\$(Configuration)X64\" </Command>
-    </PostBuildEvent>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <SDLCheck>true</SDLCheck>
-      <PreprocessorDefinitions>WIN32;NDEBUG;CCOSDEVGENPSGHR_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <ConformanceMode>Default</ConformanceMode>
-      <PrecompiledHeader>Use</PrecompiledHeader>
-      <PrecompiledHeaderFile>stdafx.h</PrecompiledHeaderFile>
-      <LanguageStandard>stdcpp17</LanguageStandard>
-      <AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include</AdditionalIncludeDirectories>
-      <Optimization>Disabled</Optimization>
-    </ClCompile>
-    <Link>
-      <SubSystem>Windows</SubSystem>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <OptimizeReferences>true</OptimizeReferences>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <EnableUAC>true</EnableUAC>
-      <AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib</AdditionalLibraryDirectories>
-      <AdditionalDependencies>Version.lib;%(AdditionalDependencies)</AdditionalDependencies>
-    </Link>
-    <PostBuildEvent>
-      <Command>copy "$(OutDir)$(TargetName)$(TargetExt)" "..\..\..\deliver\bin\$(Configuration)X64" 
-copy "$(OutDir)$(TargetName).lib" "..\..\..\deliver\lib\$(Configuration)X64\" 
-copy "$(OutDir)$(TargetName).pdb" "..\..\..\deliver\bin\$(Configuration)X64\" </Command>
-    </PostBuildEvent>
-  </ItemDefinitionGroup>
-  <ItemGroup>
-    <ClInclude Include="..\..\..\..\..\Deliver\include\LogicDevice.h" />
-    <ClInclude Include="..\..\..\Deliver\Include\Base64.h" />
-    <ClInclude Include="..\..\..\Deliver\Include\DAP.BasicMoulds.hpp" />
-    <ClInclude Include="..\..\..\Deliver\Include\DeliverModule.h" />
-    <ClInclude Include="..\..\..\Deliver\Include\CCOS.Dev.MSGMould.hpp" />
-    <ClInclude Include="CCOS.Dev.Generator.PSG_HR.h" />
-    <ClInclude Include="stdafx.h" />
-    <ClInclude Include="resource.h" />
-  </ItemGroup>
-  <ItemGroup>
-    <ClCompile Include="..\..\..\Deliver\Include\Base64.cpp" />
-    <ClCompile Include="..\..\..\Deliver\Include\DAP.BasicMoulds.cpp" />
-    <ClCompile Include="..\..\..\Deliver\Include\DeliverModule.cpp">
-      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
-    </ClCompile>
-    <ClCompile Include="..\..\..\Deliver\Include\CCOS.Dev.MSGMould.cpp" />
-    <ClCompile Include="CCOS.Dev.Generator.PSG_HR.cpp" />
-    <ClCompile Include="dllmain.cpp" />
-    <ClCompile Include="stdafx.cpp">
-      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
-      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
-      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
-      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
-    </ClCompile>
-  </ItemGroup>
-  <ItemGroup>
-    <ResourceCompile Include="CCOS.Dev.Generator.PSG_HR.rc" />
-  </ItemGroup>
-  <ItemGroup>
-    <Text Include="ReleaseNote.txt" />
-  </ItemGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
-  <ImportGroup Label="ExtensionTargets">
-  </ImportGroup>
-</Project>

+ 0 - 76
Generator/PSG/CCOS.Dev.Generator.PSG_HR/CCOS.Dev.Generator.PSG_HR.vcxproj.filters

@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <ItemGroup>
-    <Filter Include="源文件">
-      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
-      <Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
-    </Filter>
-    <Filter Include="头文件">
-      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
-      <Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
-    </Filter>
-    <Filter Include="资源文件">
-      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
-      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
-    </Filter>
-  </ItemGroup>
-  <ItemGroup>
-    <ClInclude Include="stdafx.h">
-      <Filter>头文件</Filter>
-    </ClInclude>
-    <ClInclude Include="resource.h">
-      <Filter>头文件</Filter>
-    </ClInclude>
-    <ClInclude Include="..\..\..\Deliver\Include\Base64.h">
-      <Filter>头文件</Filter>
-    </ClInclude>
-    <ClInclude Include="..\..\..\Deliver\Include\DAP.BasicMoulds.hpp">
-      <Filter>头文件</Filter>
-    </ClInclude>
-    <ClInclude Include="..\..\..\Deliver\Include\CCOS.Dev.MSGMould.hpp">
-      <Filter>头文件</Filter>
-    </ClInclude>
-    <ClInclude Include="..\..\..\Deliver\Include\DeliverModule.h">
-      <Filter>头文件</Filter>
-    </ClInclude>
-    <ClInclude Include="..\..\..\..\..\Deliver\include\LogicDevice.h">
-      <Filter>头文件</Filter>
-    </ClInclude>
-    <ClInclude Include="CCOS.Dev.Generator.PSG_HR.h">
-      <Filter>头文件</Filter>
-    </ClInclude>
-  </ItemGroup>
-  <ItemGroup>
-    <ClCompile Include="dllmain.cpp">
-      <Filter>源文件</Filter>
-    </ClCompile>
-    <ClCompile Include="stdafx.cpp">
-      <Filter>源文件</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\Deliver\Include\DAP.BasicMoulds.cpp">
-      <Filter>源文件</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\Deliver\Include\CCOS.Dev.MSGMould.cpp">
-      <Filter>源文件</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\Deliver\Include\Base64.cpp">
-      <Filter>源文件</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\..\Deliver\Include\DeliverModule.cpp">
-      <Filter>源文件</Filter>
-    </ClCompile>
-    <ClCompile Include="CCOS.Dev.Generator.PSG_HR.cpp">
-      <Filter>源文件</Filter>
-    </ClCompile>
-  </ItemGroup>
-  <ItemGroup>
-    <ResourceCompile Include="CCOS.Dev.Generator.PSG_HR.rc">
-      <Filter>资源文件</Filter>
-    </ResourceCompile>
-  </ItemGroup>
-  <ItemGroup>
-    <Text Include="ReleaseNote.txt">
-      <Filter>源文件</Filter>
-    </Text>
-  </ItemGroup>
-</Project>

+ 0 - 4
Generator/PSG/CCOS.Dev.Generator.PSG_HR/CCOS.Dev.Generator.PSG_HR.vcxproj.user

@@ -1,4 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <PropertyGroup />
-</Project>

+ 6 - 0
Generator/PSG/CCOS.Dev.Generator.PSG_HR/CMakeLists.txt

@@ -43,6 +43,8 @@ message(STATUS "包含交付头文件目录: ${DELIVER_INCLUDE_DIR}")
 set(SRC_FILES
     CCOS.Dev.Generator.PSG_HR.cpp
     CCOS.Dev.Generator.PSG_HR.h
+    LogLocalHelper.cpp
+    LogLocalHelper.h
 	${PhysicalDevice_DELIVER_INCLUDE_DIR}/CCOS.Dev.MSGMould.hpp
 	${PhysicalDevice_DELIVER_INCLUDE_DIR}/CCOS.Dev.MSGMould.cpp
 	${PhysicalDevice_DELIVER_INCLUDE_DIR}/Base64.h
@@ -65,6 +67,10 @@ set_target_properties(CCOS.Dev.Generator.PSG_HR PROPERTIES
 target_link_libraries(CCOS.Dev.Generator.PSG_HR PRIVATE 
     CCOS.Dev.IODevice 
     SCF 
+    SCFWrapper
+    SerialSCF
+    TcpipSCF
+    log4cpp_wrapper
     CCOS.Dev.Generator.Mould
     pthread  # 添加POSIX线程库
     dl       # 添加动态链接库

+ 17 - 0
Generator/PSG/CCOS.Dev.Generator.PSG_HR/LogLocalHelper.cpp

@@ -0,0 +1,17 @@
+// LogLocalHelper.cpp
+#include "LogLocalHelper.h"
+#include <string>
+#include <iostream>
+
+// 使用线程局部存储:确保每个动态库有独立的模块名副本
+static std::string s_localModuleName;
+
+// 初始化当前动态库的局部模块名(在调用initLogModule后立即调用)
+void PSGHR_SetLocalModuleName(const std::string& moduleName) {
+    s_localModuleName = moduleName;
+}
+
+// 获取当前动态库的局部模块名(日志输出时调用)
+const std::string& PSGHR_GetLocalModuleName() {
+    return s_localModuleName;
+}

+ 28 - 0
Generator/PSG/CCOS.Dev.Generator.PSG_HR/LogLocalHelper.h

@@ -0,0 +1,28 @@
+// LogLocalHelper.h
+#ifndef LOG_LOCAL_HELPER_H
+#define LOG_LOCAL_HELPER_H
+#include <string>
+#include "Log4CPP.h"
+
+void PSGHR_SetLocalModuleName(const std::string& moduleName);
+const std::string& PSGHR_GetLocalModuleName();
+
+// 重定义日志宏:使用当前动态库的局部模块名getLocalModuleName()
+#define LOG(level, format, ...) \
+    do { \
+        const std::string& localModule = PSGHR_GetLocalModuleName(); \
+        LogInstance* logger = LogManager::getInstance().getInstance(localModule); \
+        if (logger && logger->isInitialized()) { \
+            logger->log(log4cpp::Priority::level, __FILE__, __LINE__, __FUNCTION__, format, ##__VA_ARGS__); \
+        } else { \
+            std::cerr << "[" << localModule << "] PSGHD_Logger not initialized or module not found!" << std::endl; \
+        } \
+    } while(0)
+
+// 保留原有的级别宏(无需修改,依赖重定义后的LOG)
+#define FDEBUG(format, ...) LOG(DEBUG, format, ##__VA_ARGS__)
+#define FINFO(format, ...)  LOG(INFO,  format, ##__VA_ARGS__)
+#define FWARN(format, ...)  LOG(WARN,  format, ##__VA_ARGS__)
+#define FERROR(format, ...) LOG(ERROR, format, ##__VA_ARGS__)
+
+#endif // LOG_LOCAL_HELPER_H

+ 0 - 5
Generator/PSG/CCOS.Dev.Generator.PSG_HR/ReleaseNote.txt

@@ -1,5 +0,0 @@
-更新模块:CCOS.Dev.Generator.PSG_RF.dll
-更新人员:柳文奎
-
-更新功能:
-1 集成项目 PSG-HR 发生器集成

+ 0 - 20
Generator/PSG/CCOS.Dev.Generator.PSG_HR/dllmain.cpp

@@ -1,20 +0,0 @@
-// dllmain.cpp : 定义 DLL 应用程序的入口点。
-#include "stdafx.h"
-
-BOOL APIENTRY DllMain( HMODULE hModule,
-                       DWORD  ul_reason_for_call,
-                       LPVOID lpReserved
-                     )
-{
-    hMyModule = hModule;
-    switch (ul_reason_for_call)
-    {
-    case DLL_PROCESS_ATTACH:
-    case DLL_THREAD_ATTACH:
-    case DLL_THREAD_DETACH:
-    case DLL_PROCESS_DETACH:
-        break;
-    }
-    return TRUE;
-}
-

+ 0 - 18
Generator/PSG/CCOS.Dev.Generator.PSG_HR/framework.h

@@ -1,18 +0,0 @@
-#pragma once
-
-#define WIN32_LEAN_AND_MEAN             // 从 Windows 头文件中排除极少使用的内容
-// Windows 头文件
-#include <windows.h>
-
-namespace CCOS
-{
-	namespace Dev
-	{
-		class IODriver;
-	}
-}
-
-
-extern "C"  __declspec(dllexport) CCOS::Dev::IODriver * __cdecl GetIODriver();
-extern "C"   __declspec(dllexport) CCOS::Dev::IODriver * __cdecl CreateIODriver();
-//extern "C"  __declspec(dllexport) int __cdecl GetDeviceManager ();

+ 0 - 15
Generator/PSG/CCOS.Dev.Generator.PSG_HR/resource.h

@@ -1,15 +0,0 @@
-//{{NO_DEPENDENCIES}}
-// Microsoft Visual C++ 生成的包含文件。
-// 供 CCOS.Dev.Generator.PSG_HR.rc 使用
-//
-
-// Next default values for new objects
-// 
-#ifdef APSTUDIO_INVOKED
-#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE        101
-#define _APS_NEXT_COMMAND_VALUE         40001
-#define _APS_NEXT_CONTROL_VALUE         1001
-#define _APS_NEXT_SYMED_VALUE           101
-#endif
-#endif

+ 0 - 6
Generator/PSG/CCOS.Dev.Generator.PSG_HR/stdafx.cpp

@@ -1,6 +0,0 @@
-// pch.cpp: 与预编译标头对应的源文件
-
-#include "stdafx.h"
-
-// 当使用预编译的头时,需要使用此源文件,编译才能成功。
-HMODULE hMyModule = NULL;

+ 0 - 39
Generator/PSG/CCOS.Dev.Generator.PSG_HR/stdafx.h

@@ -1,39 +0,0 @@
-// pch.h: 这是预编译标头文件。
-// 下方列出的文件仅编译一次,提高了将来生成的生成性能。
-// 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。
-// 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。
-// 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。
-
-#pragma once
-
-#ifndef PCH_H
-#define PCH_H
-
-// 添加要在此处预编译的标头
-#include "targetver.h"
-
-#define WIN32_LEAN_AND_MEAN             // 从 Windows 头文件中排除极少使用的内容
-// Windows 头文件
-#include <windows.h>
-#include <mutex>
-
-// TODO:  在此处引用程序需要的其他头文件
-#include "Log4CPP.Logger.hpp"
-#include "Log4CPP.TLSLog.Tracing.hpp"
-#include "mLog.Log4CPP.hpp"
-
-namespace CCOS
-{
-	namespace Dev
-	{
-		class IODriver;
-	}
-}
-
-extern HMODULE hMyModule;
-
-extern "C"  __declspec(dllexport) CCOS::Dev::IODriver * __cdecl GetIODriver();
-extern "C"   __declspec(dllexport) CCOS::Dev::IODriver * __cdecl CreateIODriver();
-//extern "C"  __declspec(dllexport) int __cdecl GetDeviceManager ();
-
-#endif //PCH_H

+ 0 - 8
Generator/PSG/CCOS.Dev.Generator.PSG_HR/targetver.h

@@ -1,8 +0,0 @@
-#pragma once
-
-// 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。
-
-// 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将
-// WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。
-
-#include <SDKDDKVer.h>

Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor