From da2736b59a27593fdac0295a9e6606dbf3dc59db Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期二, 14 一月 2025 17:34:55 +0800
Subject: [PATCH] 1.secs部分单个通讯的回复;
---
SourceCode/Bond/Servo/SecsTestDlg.cpp | 20 +++++
SourceCode/Bond/HSMSSDK/Include/ISECS2Item.h | 12 ++
SourceCode/Bond/Servo/HsmsPassive.h | 11 ++
SourceCode/Bond/Servo/resource.h | 0
SourceCode/Bond/Servo/HsmsAction.h | 2
SourceCode/Bond/Servo/HsmsPassive.cpp | 157 +++++++++++++++++++++++++++++++++++++--
SourceCode/Bond/Servo/Servo.rc | 0
SourceCode/Bond/Servo/SecsTestDlg.h | 2
SourceCode/Bond/Servo/Model.cpp | 7 +
9 files changed, 199 insertions(+), 12 deletions(-)
diff --git a/SourceCode/Bond/HSMSSDK/Include/ISECS2Item.h b/SourceCode/Bond/HSMSSDK/Include/ISECS2Item.h
index 030deaf..638b3b3 100644
--- a/SourceCode/Bond/HSMSSDK/Include/ISECS2Item.h
+++ b/SourceCode/Bond/HSMSSDK/Include/ISECS2Item.h
@@ -26,12 +26,20 @@
virtual SITYPE getType() = 0;
virtual const char* toString() = 0;
virtual bool getString(char*& pszText) = 0;
+ virtual bool getBinary(BYTE& bin) = 0;
+ virtual bool getBool(bool& boolValue) = 0;
+ virtual bool getU4(unsigned int& value) = 0;
virtual int getSubItemSize() = 0;
virtual ISECS2Item* getSubItem(int index) = 0;
virtual bool getSubItemString(int index, char*& pszText) = 0;
+ virtual bool getSubItemBinary(int index, BYTE& bin) = 0;
+ virtual bool getSubItemBool(int index, bool& boolValue) = 0;
+ virtual bool getSubItemU4(int index, unsigned int& value) = 0;
virtual void reset() = 0;
virtual ISECS2Item* addItem(const char* pszText, const char* pszNote) = 0;
- virtual ISECS2Item* addBinaryItem(const char* pszData, int nDataLen, const char* pszNote) = 0;
- virtual void setBinary(const char* pszData, int nLen, const char* pszNote) = 0;
+ virtual ISECS2Item* addBinaryItem(BYTE bin, const char* pszNote) = 0;
+ virtual ISECS2Item* addBoolItem(bool boolValue, const char* pszNote) = 0;
+ virtual ISECS2Item* addU4Item(unsigned int value, const char* pszNote) = 0;
+ virtual void setBinary(BYTE bin, const char* pszNote) = 0;
virtual ISECS2Item* addItem() = 0;
};
diff --git a/SourceCode/Bond/Servo/HsmsAction.h b/SourceCode/Bond/Servo/HsmsAction.h
index 6defe08..e4f6910 100644
--- a/SourceCode/Bond/Servo/HsmsAction.h
+++ b/SourceCode/Bond/Servo/HsmsAction.h
@@ -4,7 +4,7 @@
#define ACTION_IDLE 0
#define ACTION_HELLO 1 /* S1F1 */
-
+#define ACTION_ALARM_REPORT 2 /* S5F1 */
class CHsmsAction
{
diff --git a/SourceCode/Bond/Servo/HsmsPassive.cpp b/SourceCode/Bond/Servo/HsmsPassive.cpp
index b0add83..ab08dae 100644
--- a/SourceCode/Bond/Servo/HsmsPassive.cpp
+++ b/SourceCode/Bond/Servo/HsmsPassive.cpp
@@ -4,10 +4,11 @@
#include "Model.h"
#include "Common.h"
#include <time.h>
+#include <iostream>
+#include <time.h>
+#include <stdlib.h>
+#include <string.h>
-
-char g_szAckOkData[] = { 0, 0, 0, 0 };
-char g_szAckNgData[] = { 1, 0, 0, 0 };
unsigned __stdcall CimWorkThreadFunction(LPVOID lpParam)
{
@@ -65,6 +66,23 @@
m_nActionTimeout = max(3, nSecond);
}
+void CHsmsPassive::setEquipmentModelType(const char* pszMode)
+{
+ m_strEquipmentModelType = pszMode;
+ if (m_strEquipmentModelType.length() > 20) {
+ m_strEquipmentModelType = m_strEquipmentModelType.substr(0, 20);
+ }
+}
+
+void CHsmsPassive::setSoftRev(const char* pszRev)
+{
+ m_strSoftRev = pszRev;
+ if (m_strSoftRev.length() > 20) {
+ m_strSoftRev = m_strSoftRev.substr(0, 20);
+ }
+
+}
+
void CHsmsPassive::OnTimer(UINT nTimerid)
{
// 所有已发送的Action自加1
@@ -84,6 +102,7 @@
int CHsmsPassive::onRecvMsg(IMessage* pMessage)
{
+ LOGI("onRecvMsg:%s", pMessage->toString());
Lock();
CHsmsAction* pAction = nullptr;
for (auto iter = m_listActionSent.begin(); iter != m_listActionSent.end(); iter++) {
@@ -165,6 +184,12 @@
}
else if (nStream == 2 && pHeader->function == 31) {
replyDatetime(pMessage);
+ }
+ else if (nStream == 2 && pHeader->function == 37) {
+ replyEanbleDisableEventReport(pMessage);
+ }
+ else if (nStream == 5 && pHeader->function == 3) {
+ replyEanbleDisableAlarmReport(pMessage);
}
};
@@ -321,7 +346,7 @@
ASSERT(pMessage);
ISECS2Item* pItem = pMessage->getBody();
- pItem->addBinaryItem(g_szAckOkData, 1, "COMMACK");
+ pItem->addBinaryItem(BYTE(0), "COMMACK");
ISECS2Item* pList = pItem->addItem();
pList->addItem(m_strEquipmentModelType.c_str(), "MDLN");
pList->addItem(m_strSoftRev.c_str(), "SOFTREV");
@@ -333,10 +358,6 @@
}
// S2F31
-#include <iostream>
-#include <time.h>
-#include <stdlib.h>
-#include <string.h>
int CHsmsPassive::replyDatetime(IMessage* pRecv)
{
if (m_pPassive == NULL || STATE::SELECTED != m_pPassive->getState()) {
@@ -372,10 +393,128 @@
ASSERT(pMessage);
ISECS2Item* pItem = pMessage->getBody();
- pItem->setBinary(g_szAckOkData, 1, "TIACK");
+ pItem->setBinary(BYTE(0), "TIACK");
m_pPassive->sendMessage(pMessage);
LOGI("<HSMS>[SECS Msg SEND]S2F32 (SysByte=%u)", pRecv->getHeader()->systemBytes);
HSMS_Destroy1Message(pMessage);
return 0;
}
+
+// S2F37
+int CHsmsPassive::replyEanbleDisableEventReport(IMessage* pRecv)
+{
+ if (m_pPassive == NULL || STATE::SELECTED != m_pPassive->getState()) {
+ return ER_NOTSELECT;
+ }
+ ISECS2Item* pBody = pRecv->getBody();
+ if (pBody == nullptr || pBody->getType() != SITYPE::A) ER_PARAM_ERROR;
+
+
+
+ BOOL bCheckData = FALSE;
+ bool bEnable;
+ std::vector<unsigned int> ids;
+ {
+ ISECS2Item* pItemIds;
+ ISECS2Item* pItem = pRecv->getBody();
+ if (pItem->getSubItemSize() < 2) goto MYREPLY;
+ if (!pItem->getSubItemBool(0, bEnable)) goto MYREPLY;
+ pItemIds = pItem->getSubItem(1);
+ if (pItemIds == nullptr || pItemIds->getType() != SITYPE::L) goto MYREPLY;
+ for (int i = 0; i < pItemIds->getSubItemSize(); i++) {
+ unsigned int id;
+ if (pItemIds->getSubItemU4(i, id)) {
+ ids.push_back(id);
+ }
+ }
+ bCheckData = TRUE;
+ LOGI("EanbleDisableAlarm bEnable:%s", bEnable ? _T("YES") : _T("NO"));
+ for (auto item : ids) {
+ LOGI("ID:%u", item);
+ }
+ }
+
+
+MYREPLY:
+ int s = 2;
+ int f = 38;
+ IMessage* pMessage = NULL;
+ HSMS_Create1Message(pMessage, m_nSessionId, s, f, pRecv->getHeader()->systemBytes);
+ ASSERT(pMessage);
+ ISECS2Item* pItem = pMessage->getBody();
+ pItem->setBinary(BYTE(0), "ERACK");
+ m_pPassive->sendMessage(pMessage);
+ LOGI("<HSMS>[SECS Msg SEND]S%dF%d (SysByte=%u)", s, f, pRecv->getHeader()->systemBytes);
+ HSMS_Destroy1Message(pMessage);
+
+
+ return 0;
+}
+
+// S5F3
+int CHsmsPassive::replyEanbleDisableAlarmReport(IMessage* pRecv)
+{
+ if (m_pPassive == NULL || STATE::SELECTED != m_pPassive->getState()) {
+ return ER_NOTSELECT;
+ }
+ ISECS2Item* pBody = pRecv->getBody();
+ if (pBody == nullptr || pBody->getType() != SITYPE::A) ER_PARAM_ERROR;
+
+
+
+ BOOL bCheckData = FALSE;
+ BYTE ALED;
+ unsigned int ALID;
+ {
+ ISECS2Item* pItem = pRecv->getBody();
+ if (pItem->getSubItemSize() < 2) goto MYREPLY;
+ if (!pItem->getSubItemBinary(0, ALED)) goto MYREPLY;
+ if (!pItem->getSubItemU4(1, ALID)) goto MYREPLY;
+ bCheckData = TRUE;
+ LOGI("EanbleDisableAlarmReport ALED:%d, ALID:%d", ALED, ALID);
+ }
+
+
+MYREPLY:
+ int s = 5;
+ int f = 4;
+ IMessage* pMessage = NULL;
+ HSMS_Create1Message(pMessage, m_nSessionId, s, f, pRecv->getHeader()->systemBytes);
+ ASSERT(pMessage);
+ ISECS2Item* pItem = pMessage->getBody();
+ pItem->setBinary(BYTE(0), "ACKC5");
+ m_pPassive->sendMessage(pMessage);
+ LOGI("<HSMS>[SECS Msg SEND]S%dF%d (SysByte=%u)", s, f, pRecv->getHeader()->systemBytes);
+ HSMS_Destroy1Message(pMessage);
+
+
+ return 0;
+}
+
+// S5F1
+int CHsmsPassive::requestAlarmReport(int ALCD, int ALID, const char* ALTX)
+{
+ if (m_pPassive == NULL || STATE::SELECTED != m_pPassive->getState()) {
+ return ER_NOTSELECT;
+ }
+
+ Lock();
+ CHsmsAction* pAction = new CHsmsAction(ACTION_ALARM_REPORT, TRUE, m_nActionTimeout);
+ m_listAction.push_back(pAction);
+ IMessage* pMessage = NULL;
+ HSMS_Create1Message(pMessage, m_nSessionId, 5 | REPLY, 1, ++m_nSystemByte);
+ ASSERT(pMessage);
+ ISECS2Item* pItem = pMessage->getBody();
+ pItem->addBinaryItem(BYTE(ALCD & 0xff), "ALCD");
+ pItem->addU4Item(ALID, "ALID");
+ pItem->addItem(ALTX, "ALTX");
+ pAction->setSendMessage(pMessage);
+
+ SetEvent(m_hCimWorkEvent);
+ Unlock();
+
+ return ER_NOERROR;
+}
+
+
diff --git a/SourceCode/Bond/Servo/HsmsPassive.h b/SourceCode/Bond/Servo/HsmsPassive.h
index cb3b047..ac820bb 100644
--- a/SourceCode/Bond/Servo/HsmsPassive.h
+++ b/SourceCode/Bond/Servo/HsmsPassive.h
@@ -17,6 +17,12 @@
~CHsmsPassive();
public:
+ /* 设置机器型号 最大长度 20 bytes */
+ void setEquipmentModelType(const char* pszMode);
+
+ /* 设置软件版本号 最大长度 20 bytes */
+ void setSoftRev(const char* pszRev);
+
unsigned OnCimWork();
void OnTimer(UINT nTimerid);
void setActionTimeout(int nSecond);
@@ -24,12 +30,17 @@
int term();
public:
+ /* request开头的函数为主动发送数据的函数 */
int requestAreYouThere();
+ int requestAlarmReport(int ALCD, int ALID, const char* ALTX);
private:
+ /* reply开头的函数为回复函数 */
int replyAreYouThere(unsigned int systemBytes);
int replyEstablishCommunications(unsigned int systemBytes);
int replyDatetime(IMessage* pRecv);
+ int replyEanbleDisableEventReport(IMessage* pRecv);
+ int replyEanbleDisableAlarmReport(IMessage* pRecv);
private:
inline void Lock() { EnterCriticalSection(&m_criticalSection); }
diff --git a/SourceCode/Bond/Servo/Model.cpp b/SourceCode/Bond/Servo/Model.cpp
index 548e170..c4e39d0 100644
--- a/SourceCode/Bond/Servo/Model.cpp
+++ b/SourceCode/Bond/Servo/Model.cpp
@@ -32,6 +32,11 @@
m_configuration.setFilepath((LPTSTR)(LPCTSTR)strIniFile);
m_configuration.getUnitId(strUnitId);
+ // 机器型号和软件版本号应从配置中读取,当前先固定值
+ CString strModeType = _T("Bond2860");
+ CString strSoftRev = _T("1.0.2");
+
+
// Log
CString strLogDir;
@@ -52,6 +57,8 @@
});
+ m_hsmsPassive.setEquipmentModelType((LPTSTR)(LPCTSTR)strModeType);
+ m_hsmsPassive.setSoftRev((LPTSTR)(LPCTSTR)strSoftRev);
m_hsmsPassive.init(this, "APP", 7000);
diff --git a/SourceCode/Bond/Servo/SecsTestDlg.cpp b/SourceCode/Bond/Servo/SecsTestDlg.cpp
index 441f2d2..2234ec3 100644
--- a/SourceCode/Bond/Servo/SecsTestDlg.cpp
+++ b/SourceCode/Bond/Servo/SecsTestDlg.cpp
@@ -30,6 +30,8 @@
BEGIN_MESSAGE_MAP(CSecsTestDlg, CDialogEx)
ON_BN_CLICKED(IDC_BUTTON_S1F13, &CSecsTestDlg::OnBnClickedButtonS1f13)
ON_BN_CLICKED(IDC_BUTTON_S1F1, &CSecsTestDlg::OnBnClickedButtonS1f1)
+ ON_BN_CLICKED(IDC_BUTTON_S5F1_A, &CSecsTestDlg::OnBnClickedButtonS5f1A)
+ ON_BN_CLICKED(IDC_BUTTON_S5F1_B, &CSecsTestDlg::OnBnClickedButtonS5f1B)
END_MESSAGE_MAP()
@@ -44,3 +46,21 @@
{
}
+
+
+void CSecsTestDlg::OnBnClickedButtonS5f1A()
+{
+ int ALCD, ALID;
+ ALCD = 0;
+ ALID = 1001;
+ theApp.m_model.m_hsmsPassive.requestAlarmReport(ALCD, ALID, "ABC EFG");
+}
+
+
+void CSecsTestDlg::OnBnClickedButtonS5f1B()
+{
+ int ALCD, ALID;
+ ALCD = 1;
+ ALID = 1001;
+ theApp.m_model.m_hsmsPassive.requestAlarmReport(ALCD, ALID, "ABCEFG");
+}
diff --git a/SourceCode/Bond/Servo/SecsTestDlg.h b/SourceCode/Bond/Servo/SecsTestDlg.h
index b8b92b4..76410b3 100644
--- a/SourceCode/Bond/Servo/SecsTestDlg.h
+++ b/SourceCode/Bond/Servo/SecsTestDlg.h
@@ -23,4 +23,6 @@
public:
afx_msg void OnBnClickedButtonS1f13();
afx_msg void OnBnClickedButtonS1f1();
+ afx_msg void OnBnClickedButtonS5f1A();
+ afx_msg void OnBnClickedButtonS5f1B();
};
diff --git a/SourceCode/Bond/Servo/Servo.rc b/SourceCode/Bond/Servo/Servo.rc
index 2411f2f..3fcb2f2 100644
--- a/SourceCode/Bond/Servo/Servo.rc
+++ b/SourceCode/Bond/Servo/Servo.rc
Binary files differ
diff --git a/SourceCode/Bond/Servo/resource.h b/SourceCode/Bond/Servo/resource.h
index 24dbeea..7126e89 100644
--- a/SourceCode/Bond/Servo/resource.h
+++ b/SourceCode/Bond/Servo/resource.h
Binary files differ
--
Gitblit v1.9.3