From b78a202c2933d345e1983de26948dbdae5d72382 Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期四, 12 二月 2026 10:28:06 +0800
Subject: [PATCH] 1.加上限制条件,Port1必须配置Port2, Port3必须配Port4,且是同一ProcessJob

---
 SourceCode/Bond/Servo/HsmsPassive.cpp |  124 ++++++++++++++++++++++++++++++++++++-----
 1 files changed, 109 insertions(+), 15 deletions(-)

diff --git a/SourceCode/Bond/Servo/HsmsPassive.cpp b/SourceCode/Bond/Servo/HsmsPassive.cpp
index c2359b3..da0eb24 100644
--- a/SourceCode/Bond/Servo/HsmsPassive.cpp
+++ b/SourceCode/Bond/Servo/HsmsPassive.cpp
@@ -1736,9 +1736,15 @@
 			replySelectedEquipmentStatusData(pMessage);
 		}
 		else if (nStream == 1 && pHeader->function == 11) {
+			// [EAP_MAPPING][S1F11] Status Variable namelist request -> S1F12.
+			// If customer requires swapping SV/DV mapping, this is one of the two switch points.
+			// Swap target with S1F21 branch below.
 			replyStatusVariableNamelistRequest(pMessage);
 		}
 		else if (nStream == 1 && pHeader->function == 21) {
+			// [EAP_MAPPING][S1F21] Data Variable namelist request -> S1F22.
+			// If customer requires swapping SV/DV mapping, this is one of the two switch points.
+			// Swap target with S1F11 branch above.
 			replyDataVariableNamelistRequest(pMessage);
 		}
 		else if (nStream == 1 && pHeader->function == 23) {
@@ -1909,7 +1915,16 @@
 	if (pszBuffer == nullptr) {
 		index += sizeof(int);
 		for (auto item : m_listActionSpooling) {
-			index += item->serialize(pszBuffer, nBufferSize);
+			if (item == nullptr || item->getSendMessage() == nullptr) {
+				LOGE("<HSMS>skip spooling item: null send message");
+				continue;
+			}
+			int nRet = item->serialize(nullptr, 0);
+			if (nRet <= 0) {
+				LOGE("<HSMS>skip spooling item: serialize failed");
+				continue;
+			}
+			index += nRet;
 		}
 
 		index += calcSpoolCfgSize();
@@ -1917,15 +1932,31 @@
 		return index;
 	}
 	else {
-		int nTemp, nRet;
+		int nTemp = 0;
+		int nRet = 0;
 
-		nTemp = (int)m_listActionSpooling.size();
+		for (auto item : m_listActionSpooling) {
+			if (item == nullptr || item->getSendMessage() == nullptr) {
+				continue;
+			}
+			if (item->serialize(nullptr, 0) > 0) {
+				++nTemp;
+			}
+		}
+
 		memcpy(&pszBuffer[index], &nTemp, sizeof(int));
 		index += sizeof(int);
 
 		for (auto item : m_listActionSpooling) {
+			if (item == nullptr || item->getSendMessage() == nullptr) {
+				LOGE("<HSMS>skip spooling item: null send message");
+				continue;
+			}
 			nRet = item->serialize(&pszBuffer[index], nBufferSize);
-			if (nRet <= 0) break;
+			if (nRet <= 0) {
+				LOGE("<HSMS>skip spooling item: serialize failed");
+				continue;
+			}
 			index += nRet;
 		}
 
@@ -1971,7 +2002,10 @@
 	for (int i = 0; i < nTemp; i++) {
 		CHsmsAction* pAction = new CHsmsAction();
 		nRet = pAction->unserialize(&pszBuffer[index], nBufferSize - index);
-		if (nRet <= 0) break;
+		if (nRet <= 0 || pAction->getSendMessage() == nullptr) {
+			delete pAction;
+			break;
+		}
 		index += nRet;
 		m_listActionSpooling.push_back(pAction);
 	}
@@ -2052,6 +2086,11 @@
 			Unlock();
 			if (!selected) {
 				IMessage* pMsg = pAction->getSendMessage();
+				if (pMsg == NULL) {
+					LOGE("<HSMS>spooling drop: null send message");
+					delete pAction;
+					continue;
+				}
 				uint8_t streamId = 0;
 				uint8_t functionId = 0;
 				if (pMsg && pMsg->getHeader()) {
@@ -2073,9 +2112,14 @@
 
 			if (pAction->isNeedWaitReply()) {
 				// 濡傛灉闇�瑕佺瓑寰呭洖澶�
+				IMessage* pMessage = pAction->getSendMessage();
+				if (pMessage == NULL) {
+					LOGE("<HSMS>drop action: null send message");
+					delete pAction;
+					continue;
+				}
 				Lock();
 				m_pActiveAction = pAction;
-				IMessage* pMessage = pAction->getSendMessage();
 				Unlock();
 
 				ASSERT(pMessage);
@@ -2099,9 +2143,14 @@
 				Unlock();
 			}
 			else {
+				IMessage* pMessage = pAction->getSendMessage();
+				if (pMessage == NULL) {
+					LOGE("<HSMS>drop action: null send message");
+					delete pAction;
+					continue;
+				}
 				Lock();
 				m_listActionSent.push_back(pAction);
-				IMessage* pMessage = pAction->getSendMessage();
 				Unlock();
 
 				ASSERT(pMessage);
@@ -2144,11 +2193,15 @@
 
 	Lock();
 	CHsmsAction* pAction = new CHsmsAction(ACTION_HELLO, FALSE, m_nActionTimeout);
-	m_listAction.push_back(pAction);
 	IMessage* pMessage = NULL;
-	HSMS_Create1Message(pMessage, m_nSessionId, 1 | REPLY, 1, ++m_nSystemByte);
-	ASSERT(pMessage);
+	if (HSMS_Create1Message(pMessage, m_nSessionId, 1 | REPLY, 1, ++m_nSystemByte) != 0 || pMessage == NULL) {
+		LOGE("<HSMS>S1F1 create message failed");
+		delete pAction;
+		Unlock();
+		return ER_CREATED_MESSAGE;
+	}
 	pAction->setSendMessage(pMessage);
+	m_listAction.push_back(pAction);
 
 	SetEvent(m_hCimWorkEvent);
 	Unlock();
@@ -2295,6 +2348,10 @@
 // S1F11
 int CHsmsPassive::replyStatusVariableNamelistRequest(IMessage* pRecv)
 {
+	// [EAP_MAPPING][SV_HANDLER]
+	// Current behavior: handles S1F11 and replies S1F12 with SVID/SVNAME/UNITS.
+	// If customer requires SV/DV swap, this function body can be swapped with
+	// replyDataVariableNamelistRequest (or dispatch branches can be swapped instead).
 	if (m_pPassive == NULL || STATE::SELECTED != m_pPassive->getState()) {
 		return ER_NOTSELECT;
 	}
@@ -2404,6 +2461,10 @@
 // S1F21/S1F22 - Data Variable Namelist
 int CHsmsPassive::replyDataVariableNamelistRequest(IMessage* pRecv)
 {
+	// [EAP_MAPPING][DV_HANDLER]
+	// Current behavior: handles S1F21 and replies S1F22 with DVID/DVNAME/UNITS.
+	// If customer requires SV/DV swap, this function body can be swapped with
+	// replyStatusVariableNamelistRequest (or dispatch branches can be swapped instead).
 	if (m_pPassive == NULL || STATE::SELECTED != m_pPassive->getState()) {
 		return ER_NOTSELECT;
 	}
@@ -3536,8 +3597,12 @@
 	CHsmsAction* pAction = new CHsmsAction(ACTION_ALARM_REPORT, TRUE, m_nActionTimeout);
 
 	IMessage* pMessage = NULL;
-	HSMS_Create1Message(pMessage, m_nSessionId, 5 | REPLY, 1, ++m_nSystemByte);
-	ASSERT(pMessage);
+	if (HSMS_Create1Message(pMessage, m_nSessionId, 5 | REPLY, 1, ++m_nSystemByte) != 0 || pMessage == NULL) {
+		LOGE("<HSMS>S5F1 create message failed");
+		delete pAction;
+		Unlock();
+		return ER_CREATED_MESSAGE;
+	}
 	ISECS2Item* pItem = pMessage->getBody();
 	pItem->addBinaryItem(szALCD, 1, "ALCD");
 	pItem->addU4Item(ALID, "ALID");
@@ -3580,8 +3645,12 @@
 	Lock();
 	CHsmsAction* pAction = new CHsmsAction(ACTION_EVENT_REPORT, TRUE, m_nActionTimeout);
 	IMessage* pMessage = NULL;
-	HSMS_Create1Message(pMessage, m_nSessionId, 6 | REPLY, 11, ++m_nSystemByte);
-	ASSERT(pMessage);
+	if (HSMS_Create1Message(pMessage, m_nSessionId, 6 | REPLY, 11, ++m_nSystemByte) != 0 || pMessage == NULL) {
+		LOGE("<HSMS>S6F11 create message failed");
+		delete pAction;
+		Unlock();
+		return ER_CREATED_MESSAGE;
+	}
 	ISECS2Item* pItem = pMessage->getBody();
 	// pItem->addU2Item(++DATAID, "DATAID");		// 鏍规嵁鍒殑鏃ュ織鏄剧ずDATAID鎭掍负0锛屾墍浠ユ垜浠厛鐓т娇鐢�0
 	pItem->addU2Item(0, "DATAID");
@@ -3716,7 +3785,32 @@
 
 int CHsmsPassive::requestEventReportSend_OCR_PanelID_Read_OK()
 {
-	return requestEventReportSend("OCR_PanelID_Read_OK");
+	return requestEventReportSend_OCR_PanelID_Read(1);
+}
+
+int CHsmsPassive::requestEventReportSend_OCR_PanelID_Read(short vcrResult)
+{
+	const char* eventName = "OCR_PanelID_Read_OK";
+	switch (vcrResult) {
+	case 1: // OK & Match
+		eventName = "OCR_PanelID_Read_OK";
+		break;
+	case 2: // OK & Mismatch
+		eventName = "OCR_PanelID_Read_Mismatch";
+		break;
+	case 3: // Fail & KeyIn Match
+		eventName = "OCR_PanelID_Read_NG";
+		break;
+	case 4: // Fail & KeyIn Mismatch
+		eventName = "OCR_PanelID_Read_NG_Mismatch";
+		break;
+	default:
+		LOGE("<CHsmsPassive>Unknown VCR result=%d, fallback to OCR_PanelID_Read_OK", vcrResult);
+		eventName = "OCR_PanelID_Read_OK";
+		break;
+	}
+
+	return requestEventReportSend(eventName);
 }
 
 int CHsmsPassive::requestEventReportSend_LoadPortNotAssoc()

--
Gitblit v1.9.3