From d9c3fbc92d2a775674943d4ab882fbd77f0db688 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期二, 08 七月 2025 20:31:34 +0800
Subject: [PATCH] 1.增加日期时间同步功能和测试;
---
SourceCode/Bond/EAPSimulator/CHsmsActive.cpp | 18 ++++++++
SourceCode/Bond/EAPSimulator/Resource.h | 4 +-
SourceCode/Bond/HSMSSDK/Include/ISECS2Item.h | 1
SourceCode/Bond/Servo/HsmsPassive.h | 2 +
SourceCode/Bond/EAPSimulator/EAPSimulatorDlg.cpp | 7 +++
SourceCode/Bond/EAPSimulator/CHsmsActive.h | 3 +
SourceCode/Bond/EAPSimulator/EAPSimulatorDlg.h | 1
SourceCode/Bond/Servo/HsmsPassive.cpp | 9 ++--
SourceCode/Bond/EAPSimulator/EAPSimulator.rc | 0
SourceCode/Bond/Servo/CMaster.cpp | 8 ++++
SourceCode/Bond/Servo/CMaster.h | 3 +
SourceCode/Bond/Servo/Model.cpp | 5 ++
12 files changed, 52 insertions(+), 9 deletions(-)
diff --git a/SourceCode/Bond/EAPSimulator/CHsmsActive.cpp b/SourceCode/Bond/EAPSimulator/CHsmsActive.cpp
index ba8ccab..ac4fe04 100644
--- a/SourceCode/Bond/EAPSimulator/CHsmsActive.cpp
+++ b/SourceCode/Bond/EAPSimulator/CHsmsActive.cpp
@@ -25,7 +25,6 @@
{
m_strIp = pszIp;
m_nPort = port;
- ++m_nSessionId;
auto onStatusChanged = [&](void* pFrom, ACTIVESTATE state) -> void {
if (m_listener.onStateChanged != nullptr) {
@@ -130,3 +129,20 @@
return 0;
}
+
+int CHsmsActive::hsmsDatetimeSync()
+{
+ CTime time = CTime::GetCurrentTime();
+ char szTime[256];
+ sprintf_s(szTime, 256, _T("%4d%02d%02d%02d%02d%02d00"), time.GetYear(),
+ time.GetMonth(), time.GetDay(), time.GetHour(), time.GetMinute(), time.GetSecond());
+
+ IMessage* pMessage = nullptr;
+ int nRet = HSMS_Create1Message(pMessage, m_nSessionId, 2 | REPLY, 31, ++m_nSystemByte);
+ ISECS2Item* pItem = pMessage->getBody();
+ pItem->setString((const char*)szTime, _T("Date time"));
+ m_pActive->sendMessage(pMessage);
+ HSMS_Destroy1Message(pMessage);
+
+ return 0;
+}
diff --git a/SourceCode/Bond/EAPSimulator/CHsmsActive.h b/SourceCode/Bond/EAPSimulator/CHsmsActive.h
index 6e4b39e..e04bd53 100644
--- a/SourceCode/Bond/EAPSimulator/CHsmsActive.h
+++ b/SourceCode/Bond/EAPSimulator/CHsmsActive.h
@@ -31,6 +31,9 @@
// Are You There
int hsmsAreYouThere();
+ // Date time sync
+ int hsmsDatetimeSync();
+
private:
ACTIVEListener m_listener;
IActive* m_pActive;
diff --git a/SourceCode/Bond/EAPSimulator/EAPSimulator.rc b/SourceCode/Bond/EAPSimulator/EAPSimulator.rc
index e6d32a0..827856f 100644
--- a/SourceCode/Bond/EAPSimulator/EAPSimulator.rc
+++ b/SourceCode/Bond/EAPSimulator/EAPSimulator.rc
Binary files differ
diff --git a/SourceCode/Bond/EAPSimulator/EAPSimulatorDlg.cpp b/SourceCode/Bond/EAPSimulator/EAPSimulatorDlg.cpp
index e37d164..e67fa2c 100644
--- a/SourceCode/Bond/EAPSimulator/EAPSimulatorDlg.cpp
+++ b/SourceCode/Bond/EAPSimulator/EAPSimulatorDlg.cpp
@@ -74,6 +74,7 @@
ON_BN_CLICKED(IDC_BUTTON_CONNECT, &CEAPSimulatorDlg::OnBnClickedButtonConnect)
ON_BN_CLICKED(IDC_BUTTON_DISCONNECT, &CEAPSimulatorDlg::OnBnClickedButtonDisconnect)
ON_BN_CLICKED(IDC_BUTTON_ARE_YOU_THERE, &CEAPSimulatorDlg::OnBnClickedButtonAreYouThere)
+ ON_BN_CLICKED(IDC_BUTTON_DATETIME_SYNC, &CEAPSimulatorDlg::OnBnClickedButtonDatetimeSync)
END_MESSAGE_MAP()
@@ -250,6 +251,7 @@
{
GetDlgItem(IDC_BUTTON_DISCONNECT)->EnableWindow(enabled);
GetDlgItem(IDC_BUTTON_ARE_YOU_THERE)->EnableWindow(enabled);
+ GetDlgItem(IDC_BUTTON_DATETIME_SYNC)->EnableWindow(enabled);
}
void CEAPSimulatorDlg::OnBnClickedButtonConnect()
@@ -271,3 +273,8 @@
{
theApp.m_model.m_pHsmsActive->hsmsAreYouThere();
}
+
+void CEAPSimulatorDlg::OnBnClickedButtonDatetimeSync()
+{
+ theApp.m_model.m_pHsmsActive->hsmsDatetimeSync();
+}
diff --git a/SourceCode/Bond/EAPSimulator/EAPSimulatorDlg.h b/SourceCode/Bond/EAPSimulator/EAPSimulatorDlg.h
index 6ee81da..248d7d5 100644
--- a/SourceCode/Bond/EAPSimulator/EAPSimulatorDlg.h
+++ b/SourceCode/Bond/EAPSimulator/EAPSimulatorDlg.h
@@ -47,4 +47,5 @@
afx_msg void OnBnClickedButtonConnect();
afx_msg void OnBnClickedButtonDisconnect();
afx_msg void OnBnClickedButtonAreYouThere();
+ afx_msg void OnBnClickedButtonDatetimeSync();
};
diff --git a/SourceCode/Bond/EAPSimulator/Resource.h b/SourceCode/Bond/EAPSimulator/Resource.h
index 86f5d87..e4c682e 100644
--- a/SourceCode/Bond/EAPSimulator/Resource.h
+++ b/SourceCode/Bond/EAPSimulator/Resource.h
@@ -12,8 +12,8 @@
#define IDC_EDIT_PORT 1002
#define IDC_BUTTON_CONNECT 1003
#define IDC_BUTTON_DISCONNECT 1004
-#define IDC_BUTTON3 1005
#define IDC_BUTTON_ARE_YOU_THERE 1005
+#define IDC_BUTTON_DATETIME_SYNC 1006
// Next default values for new objects
//
@@ -21,7 +21,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 129
#define _APS_NEXT_COMMAND_VALUE 32771
-#define _APS_NEXT_CONTROL_VALUE 1006
+#define _APS_NEXT_CONTROL_VALUE 1007
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
diff --git a/SourceCode/Bond/HSMSSDK/Include/ISECS2Item.h b/SourceCode/Bond/HSMSSDK/Include/ISECS2Item.h
index 0d4a38e..805d2f2 100644
--- a/SourceCode/Bond/HSMSSDK/Include/ISECS2Item.h
+++ b/SourceCode/Bond/HSMSSDK/Include/ISECS2Item.h
@@ -68,5 +68,6 @@
virtual ISECS2Item* addU2Item(unsigned short value, const char* pszNote) = 0;
virtual ISECS2Item* addU1Item(unsigned char value, const char* pszNote) = 0;
virtual void setBinary(const char* pszData, unsigned int len, const char* pszNote) = 0;
+ virtual void setString(const char* pszText, const char* pszNote) = 0;
virtual ISECS2Item* addItem() = 0;
};
diff --git a/SourceCode/Bond/Servo/CMaster.cpp b/SourceCode/Bond/Servo/CMaster.cpp
index 752192c..11c7cc2 100644
--- a/SourceCode/Bond/Servo/CMaster.cpp
+++ b/SourceCode/Bond/Servo/CMaster.cpp
@@ -1577,4 +1577,12 @@
pPort->localSetTransferMode((SERVO::TransferMode)transferMode);
pPort->localAutoChangeEnable(autoChangeEnable);
}
+
+ void CMaster::datetimeSync(SYSTEMTIME& time)
+ {
+ for (auto item : m_listEquipment) {
+ item->setDateTime(time.wYear, time.wMonth, time.wDay,
+ time.wHour, time.wMinute, time.wSecond);
+ }
+ }
}
diff --git a/SourceCode/Bond/Servo/CMaster.h b/SourceCode/Bond/Servo/CMaster.h
index 37ff05b..f005d7c 100644
--- a/SourceCode/Bond/Servo/CMaster.h
+++ b/SourceCode/Bond/Servo/CMaster.h
@@ -69,6 +69,7 @@
int restoreCurrentTask();
void setPortType(unsigned int index, BOOL enable, int type, int mode,
int cassetteType, int transferMode, BOOL autoChangeEnable);
+ void datetimeSync(SYSTEMTIME& time);
private:
inline void lock() { EnterCriticalSection(&m_criticalSection); }
@@ -97,7 +98,7 @@
CRobotTask* createTransferTask_bake_to_cooling(CEquipment* pSrcEq);
CRobotTask* createTransferTask_bakecooling_to_measurement(CEquipment* pSrcEq, CEquipment* pTarEq);
CRobotTask* createTransferTask_restore(CEquipment* pEqSrc, CLoadPort** pPorts);
-
+
private:
CRITICAL_SECTION m_criticalSection;
MasterListener m_listener;
diff --git a/SourceCode/Bond/Servo/HsmsPassive.cpp b/SourceCode/Bond/Servo/HsmsPassive.cpp
index 7c53585..9e4a5ab 100644
--- a/SourceCode/Bond/Servo/HsmsPassive.cpp
+++ b/SourceCode/Bond/Servo/HsmsPassive.cpp
@@ -68,11 +68,7 @@
void CHsmsPassive::setListener(SECSListener listener)
{
- m_listener.onEQOffLine = listener.onEQOffLine;
- m_listener.onEQOnLine = listener.onEQOnLine;
- m_listener.onCommand = listener.onCommand;
- m_listener.onEQConstantRequest = listener.onEQConstantRequest;
- m_listener.onEQConstantSend = listener.onEQConstantSend;
+ m_listener = listener;
}
void CHsmsPassive::setActionTimeout(int nSecond)
@@ -623,6 +619,9 @@
time.wYear = atoi(&szBuffer[0]);
time.wMilliseconds = 0;
SetLocalTime(&time);
+ if (m_listener.onDatetimeSync != nullptr) {
+ m_listener.onDatetimeSync(this, time);
+ }
}
replyAck(2, 32, pRecv->getHeader()->systemBytes, BYTE(0), "TIACK");
diff --git a/SourceCode/Bond/Servo/HsmsPassive.h b/SourceCode/Bond/Servo/HsmsPassive.h
index 44ce52c..38ba909 100644
--- a/SourceCode/Bond/Servo/HsmsPassive.h
+++ b/SourceCode/Bond/Servo/HsmsPassive.h
@@ -60,6 +60,7 @@
typedef std::function<void(void* pFrom)> SECSEQOFFLINE;
typedef std::function<void(void* pFrom, std::vector<EQConstant>&)> SECSEQCONSTANTREQUEST;
typedef std::function<void(void* pFrom, const char*, std::vector<CommandParameter>&)> SECSCommand;
+typedef std::function<void(void* pFrom, SYSTEMTIME& time)> DATETIMESYNC;
typedef struct _SECSListener
{
SECSEQOFFLINE onEQOffLine;
@@ -67,6 +68,7 @@
SECSEQCONSTANTREQUEST onEQConstantRequest;
SECSEQCONSTANTREQUEST onEQConstantSend;
SECSCommand onCommand;
+ DATETIMESYNC onDatetimeSync;
} SECSListener;
diff --git a/SourceCode/Bond/Servo/Model.cpp b/SourceCode/Bond/Servo/Model.cpp
index 6c36c56..5d39e14 100644
--- a/SourceCode/Bond/Servo/Model.cpp
+++ b/SourceCode/Bond/Servo/Model.cpp
@@ -108,6 +108,11 @@
LOGI("onEQConstantRequest: %d, %s", item.id, item.szValue);
}
};
+ listener.onDatetimeSync = [&](void* pFrom, SYSTEMTIME& time) -> void {
+ LOGI("onDatetimeSync: %d%02d%02d%02d%02d%02d", time.wYear,
+ time.wMonth, time.wDay, time.wHour, time.wMinute, time.wSecond);
+ m_master.datetimeSync(time);
+ };
m_hsmsPassive.setListener(listener);
m_hsmsPassive.setEquipmentModelType((LPTSTR)(LPCTSTR)strModeType);
--
Gitblit v1.9.3