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 | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 51 insertions(+), 0 deletions(-)
diff --git a/SourceCode/Bond/Servo/HsmsPassive.cpp b/SourceCode/Bond/Servo/HsmsPassive.cpp
index fb419c0..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];
@@ -442,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()
@@ -2221,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;
@@ -2424,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) {
@@ -2538,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;
--
Gitblit v1.9.3