From bdf0dc4cb183d3fec40e1d51b3bb94b7e53d0a55 Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期日, 04 一月 2026 10:45:07 +0800
Subject: [PATCH] 1.修复报文字段差异风险: S1F3:项目用 getSubItemU4(0) 取 SVID;日志里有 U2 的情况,可能导致解析失败后回退成 SV=0。 S6F11:项目发送 DATAID(U4) + CEID(U4);日志样例里第一个字段是 U2,可能存在类型/字段定义不一致。
---
SourceCode/Bond/Servo/HsmsPassive.cpp | 198 ++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 192 insertions(+), 6 deletions(-)
diff --git a/SourceCode/Bond/Servo/HsmsPassive.cpp b/SourceCode/Bond/Servo/HsmsPassive.cpp
index 722eacd..ae7ef22 100644
--- a/SourceCode/Bond/Servo/HsmsPassive.cpp
+++ b/SourceCode/Bond/Servo/HsmsPassive.cpp
@@ -734,6 +734,17 @@
return m_reports;
}
+unsigned int CHsmsPassive::getMaxReportId() const
+{
+ unsigned int maxId = 0;
+ for (auto item : m_reports) {
+ if (item && item->getReportId() > maxId) {
+ maxId = item->getReportId();
+ }
+ }
+ return maxId;
+}
+
SERVO::CReport* CHsmsPassive::getReport(int rptid)
{
for (auto item : m_reports) {
@@ -764,6 +775,41 @@
return -1;
}
return writeReportsToFile(m_strReportFilepath);
+}
+
+int CHsmsPassive::addReport(int rptid, const std::vector<unsigned int>& vids)
+{
+ if (getReport(rptid) != nullptr) {
+ return -1;
+ }
+ SERVO::CReport* pReport = new SERVO::CReport(rptid, vids);
+ for (auto vid : vids) {
+ SERVO::CVariable* pVariable = getVariable((int)vid);
+ if (pVariable != nullptr) {
+ pReport->addVariable(pVariable);
+ }
+ }
+ m_reports.push_back(pReport);
+ return writeReportsToFile(m_strReportFilepath);
+}
+
+int CHsmsPassive::updateReport(int rptid, const std::vector<unsigned int>& vids)
+{
+ for (auto iter = m_reports.begin(); iter != m_reports.end(); ++iter) {
+ if ((*iter)->getReportId() == rptid) {
+ delete (*iter);
+ SERVO::CReport* pReport = new SERVO::CReport(rptid, vids);
+ for (auto vid : vids) {
+ SERVO::CVariable* pVariable = getVariable((int)vid);
+ if (pVariable != nullptr) {
+ pReport->addVariable(pVariable);
+ }
+ }
+ *iter = pReport;
+ return writeReportsToFile(m_strReportFilepath);
+ }
+ }
+ return -1;
}
void CHsmsPassive::clearAllReport()
@@ -829,6 +875,9 @@
int CHsmsPassive::loadCollectionEvents(const char* pszFilepath)
{
+ m_strCollectionEventFilepath = pszFilepath;
+ m_bCollectionUtf8 = false;
+ m_bCollectionUtf8Bom = false;
CFile file;
if (!file.Open(pszFilepath, CFile::modeRead | CFile::shareDenyNone)) {
return -1;
@@ -851,6 +900,8 @@
// UTF-8 BOM
if (nLen >= 3 && bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF) {
offset = 3;
+ m_bCollectionUtf8 = true;
+ m_bCollectionUtf8Bom = true;
}
// UTF-16 LE BOM
@@ -880,6 +931,7 @@
MultiByteToWideChar(CP_UTF8, 0, buffer.data() + off,
static_cast<int>(buffer.size() - off), temp.data(), need);
content = temp.c_str();
+ m_bCollectionUtf8 = true;
return true;
};
@@ -968,6 +1020,64 @@
return m_collectionEvents;
}
+unsigned int CHsmsPassive::getMaxCollectionEventId() const
+{
+ unsigned int maxId = 0;
+ for (auto item : m_collectionEvents) {
+ if (item && item->getEventId() > maxId) {
+ maxId = item->getEventId();
+ }
+ }
+ return maxId;
+}
+
+int CHsmsPassive::deleteCollectionEvent(unsigned short CEID)
+{
+ for (auto iter = m_collectionEvents.begin(); iter != m_collectionEvents.end(); ++iter) {
+ if ((*iter)->getEventId() == CEID) {
+ delete (*iter);
+ m_collectionEvents.erase(iter);
+ return writeCollectionEventsToFile(m_strCollectionEventFilepath);
+ }
+ }
+ return -1;
+}
+
+int CHsmsPassive::addCollectionEvent(unsigned int CEID, const char* name, const char* desc, const std::vector<unsigned int>& rptids)
+{
+ if (getEvent((unsigned short)CEID) != nullptr) {
+ return -1;
+ }
+ auto* pEvent = new SERVO::CCollectionEvent(CEID, name, desc, const_cast<std::vector<unsigned int>&>(rptids));
+ for (auto rptid : rptids) {
+ SERVO::CReport* pReport = getReport((int)rptid);
+ if (pReport != nullptr) {
+ pEvent->addReport(pReport);
+ }
+ }
+ m_collectionEvents.push_back(pEvent);
+ return writeCollectionEventsToFile(m_strCollectionEventFilepath);
+}
+
+int CHsmsPassive::updateCollectionEvent(unsigned int CEID, const char* name, const char* desc, const std::vector<unsigned int>& rptids)
+{
+ for (auto iter = m_collectionEvents.begin(); iter != m_collectionEvents.end(); ++iter) {
+ if ((*iter)->getEventId() == CEID) {
+ delete (*iter);
+ auto* pEvent = new SERVO::CCollectionEvent(CEID, name, desc, const_cast<std::vector<unsigned int>&>(rptids));
+ for (auto rptid : rptids) {
+ SERVO::CReport* pReport = getReport((int)rptid);
+ if (pReport != nullptr) {
+ pEvent->addReport(pReport);
+ }
+ }
+ *iter = pEvent;
+ return writeCollectionEventsToFile(m_strCollectionEventFilepath);
+ }
+ }
+ return -1;
+}
+
void CHsmsPassive::clearAllCollectionEvent()
{
for (auto item : m_collectionEvents) {
@@ -1007,6 +1117,62 @@
}
return result;
+}
+
+int CHsmsPassive::writeCollectionEventsToFile(const std::string& filepath)
+{
+ if (filepath.empty()) return -1;
+
+ CFile file;
+ if (!file.Open(filepath.c_str(), CFile::modeCreate | CFile::modeWrite)) {
+ return -1;
+ }
+
+ if (m_bCollectionUtf8 && m_bCollectionUtf8Bom) {
+ const BYTE bom[3] = { 0xEF, 0xBB, 0xBF };
+ file.Write(bom, 3);
+ }
+
+ const std::string headerAnsi = "CEID,CE Name,Descriptions,Attached RPTID\r\n";
+ if (m_bCollectionUtf8) {
+ CStringA header = AnsiToUtf8(headerAnsi);
+ file.Write(header.GetString(), header.GetLength());
+ }
+ else {
+ file.Write(headerAnsi.data(), (UINT)headerAnsi.size());
+ }
+
+ for (auto ev : m_collectionEvents) {
+ if (ev == nullptr) continue;
+ std::string line;
+ line.reserve(128);
+ line += std::to_string(ev->getEventId());
+ line.push_back(',');
+ line += ev->getName();
+ line.push_back(',');
+ line += ev->getDescription();
+ line.push_back(',');
+ line.push_back('(');
+ auto rptIds = ev->getReportIds();
+ for (size_t i = 0; i < rptIds.size(); ++i) {
+ line += std::to_string(rptIds[i]);
+ if (i + 1 < rptIds.size()) {
+ line.push_back(',');
+ }
+ }
+ line += ")\r\n";
+
+ if (m_bCollectionUtf8) {
+ CStringA out = AnsiToUtf8(line);
+ file.Write(out.GetString(), out.GetLength());
+ }
+ else {
+ file.Write(line.data(), (UINT)line.size());
+ }
+ }
+
+ file.Close();
+ return 0;
}
int CHsmsPassive::init(CModel* pModel, const char* pszName, unsigned int port)
@@ -1451,18 +1617,18 @@
ASSERT(pMessage);
unsigned char SVU1 = 0;
- unsigned int SVID = 0;
+ unsigned short SVID = 0;
ISECS2Item* pBody = pRecv->getBody();
if (pBody == nullptr || pBody->getType() != SITYPE::L) {
pMessage->getBody()->addU1Item(SVU1, "SV");
goto MYREPLY;
}
- if (!pBody->getSubItemU4(0, SVID)) {
+ if (!pBody->getSubItemU2(0, SVID)) {
pMessage->getBody()->addU1Item(SVU1, "SV");
goto MYREPLY;
}
- SERVO::CVariable* pVariable = getVariable(SVID);
+ SERVO::CVariable* pVariable = getVariable((int)SVID);
if (pVariable == nullptr) {
pMessage->getBody()->addU1Item(SVU1, "SV");
goto MYREPLY;
@@ -2293,7 +2459,7 @@
}
// S6F11
-static unsigned int DATAID = 1;
+static unsigned short DATAID = 0;
int CHsmsPassive::requestEventReportSend(unsigned int CEID)
{
SERVO::CCollectionEvent* pEvent = getEvent(CEID);
@@ -2313,7 +2479,8 @@
HSMS_Create1Message(pMessage, m_nSessionId, 6 | REPLY, 11, ++m_nSystemByte);
ASSERT(pMessage);
ISECS2Item* pItem = pMessage->getBody();
- pItem->addU4Item(++DATAID, "DATAID");
+ // pItem->addU2Item(++DATAID, "DATAID"); // 鏍规嵁鍒殑鏃ュ織鏄剧ずDATAID鎭掍负0锛屾墍浠ユ垜浠厛鐓т娇鐢�0
+ pItem->addU2Item(0, "DATAID");
pItem->addU4Item(CEID, "CEID");
ISECS2Item* pItemList1 = pItem->addItem();
ISECS2Item* pItemList2 = pItemList1->addItem();
@@ -2357,6 +2524,21 @@
return requestEventReportSend("CarrierID_Readed");
}
+int CHsmsPassive::requestEventReportSend_CheckSlotMap()
+{
+ return requestEventReportSend("CheckSlotMap");
+}
+
+int CHsmsPassive::requestEventReportSend_SlotMapVerificationOK()
+{
+ return requestEventReportSend("SlotMapVerificationOK");
+}
+
+int CHsmsPassive::requestEventReportSend_SlotMapVerificationNG()
+{
+ return requestEventReportSend("SlotMapVerificationNG");
+}
+
int CHsmsPassive::requestEventReportSend_Port_Unload_Ready()
{
return requestEventReportSend("Port_Unload_Ready");
@@ -2365,6 +2547,11 @@
int CHsmsPassive::requestEventReportSend_Port_Load_Ready()
{
return requestEventReportSend("Port_Load_Ready");
+}
+
+int CHsmsPassive::requestEventReportSend_Port_Ready_To_Release()
+{
+ return requestEventReportSend("Port_Ready_To_Release");
}
int CHsmsPassive::requestEventReportSend_Port_Blocked()
@@ -2411,6 +2598,5 @@
{
return requestEventReportSend("OCR_PanelID_Read_OK");
}
-
--
Gitblit v1.9.3