From 3e91a18f75a75fbe8f646d73e4e68ba107b6750b Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期四, 08 一月 2026 21:04:26 +0800
Subject: [PATCH] 1.增加状态是否远程禁等逻辑;
---
SourceCode/Bond/Servo/HsmsPassive.cpp | 105 ++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 93 insertions(+), 12 deletions(-)
diff --git a/SourceCode/Bond/Servo/HsmsPassive.cpp b/SourceCode/Bond/Servo/HsmsPassive.cpp
index da6e106..6208112 100644
--- a/SourceCode/Bond/Servo/HsmsPassive.cpp
+++ b/SourceCode/Bond/Servo/HsmsPassive.cpp
@@ -12,6 +12,9 @@
#include <set>
#include <regex>
+// ControlState values (keep in sync with Model::ControlState / VariableList.txt)
+static constexpr uint8_t kControlStateOnlineRemote = 5;
+
const char ACK[2] = {0, 1};
const char* ACK0 = &ACK[0];
@@ -110,23 +113,35 @@
ASSERT(pParent);
ASSERT(pVariable);
+ std::string svNote("SV");
+ {
+ SERVO::CVariable* pDef = getVariable((int)pVariable->getVarialbleId());
+ if (pDef == nullptr) {
+ pDef = pVariable;
+ }
+ auto& name = pDef->getName();
+ if (!name.empty()) {
+ svNote += " -> ";
+ svNote += name;
+ }
+ }
ISECS2Item* pItemList;
SERVO::SVFromat format = pVariable->getFormat();
switch (format)
{
case SERVO::SVFromat::U1:
- pParent->addU1Item((unsigned char)pVariable->getIntValue(), "SV");
+ pParent->addU1Item((unsigned char)pVariable->getIntValue(), svNote.c_str());
break;
case SERVO::SVFromat::U2:
- pParent->addU2Item((unsigned char)pVariable->getIntValue(), "SV");
+ pParent->addU2Item((unsigned char)pVariable->getIntValue(), svNote.c_str());
break;
case SERVO::SVFromat::I2:
- pParent->addI2Item((unsigned char)pVariable->getIntValue(), "SV");
+ pParent->addI2Item((unsigned char)pVariable->getIntValue(), svNote.c_str());
break;
case SERVO::SVFromat::A20:
case SERVO::SVFromat::A50:
- pParent->addItem(pVariable->getValue().c_str(), "SV");
+ pParent->addItem(pVariable->getValue().c_str(), svNote.c_str());
break;
case SERVO::SVFromat::L:
pItemList = pParent->addItem();
@@ -430,6 +445,21 @@
}
return nullptr;
+}
+
+int CHsmsPassive::getCurrentControlState()
+{
+ auto v = getVariable("CurrentControlState");
+ if (v != nullptr) {
+ return static_cast<int>(v->getIntValue());
+ }
+ return 0;
+}
+
+bool CHsmsPassive::isHostCommandAllowed()
+{
+ // Only allow host control commands in OnlineRemote.
+ return getCurrentControlState() == kControlStateOnlineRemote;
}
void CHsmsPassive::clearAllVariabel()
@@ -1590,7 +1620,8 @@
ASSERT(pMessage);
m_pPassive->sendMessage(pMessage);
- LOGI("<HSMS> [SEND] SysByte=%u sessionId:%d", pMessage->getHeader()->systemBytes, pMessage->getHeader()->sessionId);
+ LOGI("<HSMS>[SEND]SysByte=%u sessionId:%d", pMessage->getHeader()->systemBytes, pMessage->getHeader()->sessionId);
+ LOGI("<HSMS>[SEND]%s", pMessage->toString());
int nRet = WaitForSingleObject(pAction->getEvent(), pAction->getTimeout() * 1000);
if (nRet == WAIT_TIMEOUT) {
@@ -1615,7 +1646,8 @@
ASSERT(pMessage);
m_pPassive->sendMessage(pMessage);
- LOGI("<HSMS> [SEND] SysByte=%u sessionId:%d", pMessage->getHeader()->systemBytes, pMessage->getHeader()->sessionId);
+ LOGI("<HSMS>[SEND]SysByte=%u sessionId:%d", pMessage->getHeader()->systemBytes, pMessage->getHeader()->sessionId);
+ LOGI("<HSMS>[SEND]%s", pMessage->toString());
}
}
@@ -1770,8 +1802,15 @@
goto MYREPLY;
}
if (!pBody->getSubItemU2(0, SVID)) {
- pMessage->getBody()->addU1Item(SVU1, "SV");
- goto MYREPLY;
+ // also accept I2 or U4 to be tolerant with host implementations
+ if (!pBody->getSubItemI2(0, (short&)SVID)) {
+ unsigned int svidU4 = 0;
+ if (!pBody->getSubItemU4(0, svidU4)) {
+ pMessage->getBody()->addU1Item(SVU1, "SV");
+ goto MYREPLY;
+ }
+ SVID = static_cast<unsigned short>(svidU4);
+ }
}
SERVO::CVariable* pVariable = getVariable((int)SVID);
@@ -2200,6 +2239,13 @@
goto MYREPLY;
}
+ if (!isHostCommandAllowed()) {
+ CAACK = CAACK_5;
+ ERRCODE = CAACK_5;
+ strError = "rejected - ControlState not OnlineRemote";
+ goto MYREPLY;
+ }
+
ISECS2Item* pBody = pRecv->getBody();
if (pBody == nullptr || pBody->getType() != SITYPE::L) ER_PARAM_ERROR;
@@ -2403,6 +2449,13 @@
ISECS2Item* pReplyItemAck = pReplyItemAcks->addU1Item(0, "OBJACK");
ISECS2Item* pReplyItemErrs = pReplyItemAcks->addItem();
+ if (!isHostCommandAllowed()) {
+ ISECS2Item* pItemError = pReplyItemErrs->addItem();
+ pItemError->addU4Item(2001, "ERRCODE");
+ pItemError->addItem("rejected - ControlState not OnlineRemote", "ERRTEXT");
+ goto MYREPLY;
+ }
+
// 褰撳墠鍙鐞嗙被鍚勪负ControlJob
if (_strcmpi(pszObjType, "ControlJob") == 0) {
@@ -2517,6 +2570,25 @@
ISECS2Item* pBody = pRecv->getBody();
if (pBody == nullptr || pBody->getType() != SITYPE::L) ER_PARAM_ERROR;
+ if (!isHostCommandAllowed()) {
+ IMessage* pMessage = NULL;
+ HSMS_Create1Message(pMessage, m_nSessionId, 16, 16, ++m_nSystemByte);
+ ASSERT(pMessage);
+ ISECS2Item* pItemPrjobIds = pMessage->getBody()->addItem();
+ ISECS2Item* pItemErrors = pMessage->getBody()->addItem();
+ pItemErrors->addBoolItem(false, "ACKA");
+ ISECS2Item* pItemErrors2 = pItemErrors->addItem();
+ auto err = pItemErrors2->addItem();
+ err->addU4Item(2001, "ERRCODE");
+ err->addItem("rejected - ControlState not OnlineRemote", "ERRTEXT");
+ m_pPassive->sendMessage(pMessage);
+ LOGI("<HSMS>[SEND]sessionId:%d, sType:%d systemBytes:%d",
+ pMessage->getHeader()->sessionId, pMessage->getHeader()->sType, pMessage->getHeader()->systemBytes);
+ LOGI("<HSMS>[SEND]%s", pMessage->toString());
+ HSMS_Destroy1Message(pMessage);
+ return 0;
+ }
+
// 瑙i噴鏁版嵁锛屽緱鍒癈ProcessJob
ISECS2Item* pItemPjs, * pItemPj,* pItemCarriers, * pItemCarrier, *pItemSlots, *pItemRecipes;
@@ -2569,9 +2641,6 @@
pjs.push_back(pj);
}
- ASSERT(m_listener.onPRJobMultiCreate != nullptr);
- int nRet = m_listener.onPRJobMultiCreate(this, pjs);
-
// 鍥炲鎶ユ枃
IMessage* pMessage = NULL;
@@ -2604,6 +2673,10 @@
pMessage->getHeader()->sessionId, pMessage->getHeader()->sType, pMessage->getHeader()->systemBytes);
LOGI("<HSMS>[SEND]%s", pMessage->toString());
HSMS_Destroy1Message(pMessage);
+
+
+ ASSERT(m_listener.onPRJobMultiCreate != nullptr);
+ int nRet = m_listener.onPRJobMultiCreate(this, pjs);
// 閲婃斁鏈夐棶棰�(鏈坊鍔犲埌master)鐨勫唴瀛�
@@ -2670,7 +2743,15 @@
ISECS2Item* pItem = pMessage->getBody();
// pItem->addU2Item(++DATAID, "DATAID"); // 鏍规嵁鍒殑鏃ュ織鏄剧ずDATAID鎭掍负0锛屾墍浠ユ垜浠厛鐓т娇鐢�0
pItem->addU2Item(0, "DATAID");
- pItem->addU4Item(CEID, "CEID");
+ std::string ceidNote("CEID");
+ if (pEvent != nullptr) {
+ auto& name = pEvent->getName();
+ if (!name.empty()) {
+ ceidNote += " -> ";
+ ceidNote += name;
+ }
+ }
+ pItem->addU4Item(CEID, ceidNote.c_str());
ISECS2Item* pItemList1 = pItem->addItem(); // L[n] reports
if (pReport != nullptr) {
ISECS2Item* pItemList2 = pItemList1->addItem();
--
Gitblit v1.9.3