From 829fe6c6bc33d53fda9c31fd45a37e1df87befff Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期五, 30 一月 2026 11:16:24 +0800
Subject: [PATCH] Merge branch 'clh' into liuyang

---
 SourceCode/Bond/Servo/CEquipmentPage1.cpp |  201 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 201 insertions(+), 0 deletions(-)

diff --git a/SourceCode/Bond/Servo/CEquipmentPage1.cpp b/SourceCode/Bond/Servo/CEquipmentPage1.cpp
index 30aa397..684c23b 100644
--- a/SourceCode/Bond/Servo/CEquipmentPage1.cpp
+++ b/SourceCode/Bond/Servo/CEquipmentPage1.cpp
@@ -9,12 +9,20 @@
 
 // CEquipmentPage1 瀵硅瘽妗�
 
+#define SIGNAL_GRID_ROWS 8
+#define SIGNAL_GRID_COLS 8
+#define SIGNAL_GRID_SIZE (SIGNAL_GRID_ROWS * SIGNAL_GRID_COLS)
+
+#define TIMER_ID_SIGNAL_UPDATE  1001
+#define TIMER_INTERVAL_MS       1000  // 姣� 1 绉掓洿鏂颁竴娆�
+
 IMPLEMENT_DYNAMIC(CEquipmentPage1, CHMPropertyPage)
 
 CEquipmentPage1::CEquipmentPage1(CWnd* pParent /*=nullptr*/)
 	: CHMPropertyPage(IDD_PAGE_EQUIPMENT1, pParent)
 {
 	m_pEquipment = nullptr;
+	m_nCurrentDeviceID = 0;
 }
 
 CEquipmentPage1::~CEquipmentPage1()
@@ -31,6 +39,7 @@
 	ON_WM_CTLCOLOR()
 	ON_WM_DESTROY()
 	ON_WM_SIZE()
+	ON_WM_TIMER()
 END_MESSAGE_MAP()
 
 
@@ -43,6 +52,149 @@
 void CEquipmentPage1::setEquipment(SERVO::CEquipment* pEquipment)
 {
 	m_pEquipment = pEquipment;
+
+	if (m_pEquipment != nullptr) {
+		InitSignalListForDevice(pEquipment->getID());
+	}
+	else {
+		ResetSignalPanel();
+	}
+}
+
+void CEquipmentPage1::LoadSignalListFromCSV(const CString& strFilePath)
+{
+	m_mapSignalListByID.clear();
+
+	CStdioFile file;
+	if (!file.Open(strFilePath, CFile::modeRead | CFile::typeText)) {
+		AfxMessageBox(_T("鏃犳硶鎵撳紑淇″彿瀹氫箟鏂囦欢: ") + strFilePath);
+		return;
+	}
+
+	CString strLine;
+	int nLineNum = 0;
+
+	while (file.ReadString(strLine)) {
+		++nLineNum;
+		strLine.Trim();
+		if (strLine.IsEmpty() || strLine.Left(1) == _T("#") || strLine.Left(2) == _T("//")) {
+			continue; // 璺宠繃娉ㄩ噴琛屾垨绌鸿
+		}
+
+		// 鍒嗗壊涓� tokens
+		std::vector<CString> tokens;
+		int curPos = 0;
+		CString token = strLine.Tokenize(_T(","), curPos);
+		while (!token.IsEmpty()) {
+			token.Trim(); // 鍘婚櫎姣忎釜瀛楁鐨勭┖鏍�
+			tokens.push_back(token);
+			token = strLine.Tokenize(_T(","), curPos);
+		}
+
+		// 鏍煎紡妫�鏌�
+		if (tokens.size() < 3) {
+			TRACE(_T("CSV 鏍煎紡閿欒 [琛� %d]锛氬瓧娈垫暟涓嶈冻銆俓n"), nLineNum);
+			continue;
+		}
+
+		// 瑙f瀽瀛楁
+		int nDeviceID = _ttoi(tokens[0]);
+		CString strSignalName = tokens[1];
+		bool bClickable = _ttoi(tokens[2]) ? TRUE : FALSE;
+
+		if (nDeviceID <= 0 || nDeviceID > 999 || strSignalName.IsEmpty()) {
+			TRACE(_T("CSV 琛� %d锛氭棤鏁堣澶嘔D=%d 鎴栦俊鍙峰悕涓虹┖\n"), nLineNum, nDeviceID);
+			continue;
+		}
+
+		SignalInfo info = { strSignalName, false, bClickable };
+		m_mapSignalListByID[nDeviceID].push_back(info);
+	}
+
+	file.Close();
+	TRACE(_T("淇″彿瀹氫箟鍔犺浇瀹屾垚锛屽叡 %d 涓澶囥�俓n"), (int)m_mapSignalListByID.size());
+}
+
+void CEquipmentPage1::InitSignalListForDevice(int nDeviceID)
+{
+	m_nCurrentDeviceID = nDeviceID;
+	m_vSignalList.clear();
+
+	auto it = m_mapSignalListByID.find(nDeviceID);
+	if (it != m_mapSignalListByID.end()) {
+		m_vSignalList = it->second;
+	}
+	else {
+		TRACE(_T("Warning: No signals found for DeviceID=%d\n"), nDeviceID);
+	}
+
+	// 琛ラ綈鍒� 64 椤�
+	while (m_vSignalList.size() < SIGNAL_GRID_SIZE) {
+		m_vSignalList.push_back({ _T(""), false, false });
+	}
+
+	InitSignalSlotTextAndClickable();
+	UpdateAllSignalStatesFromDevice();
+}
+
+void CEquipmentPage1::UpdateSignalState(int nRow, int nCol, bool bNewState)
+{
+	if (!::IsWindow(m_ctrlSignalPanel.GetSafeHwnd())) {
+		return;
+	}
+
+	int nIndex = nRow * SIGNAL_GRID_COLS + nCol;
+	if (nIndex < 0 || nIndex >= static_cast<int>(m_vSignalList.size())) {
+		return;
+	}
+
+	if (m_vSignalList[nIndex].bCurrentState != bNewState) {
+		m_vSignalList[nIndex].bCurrentState = bNewState;
+		m_ctrlSignalPanel.SetSlotStatus(nRow, nCol, bNewState);
+
+		TRACE(_T("[Device %d] UpdateSignalState: [%d, %d] = %d\n"), m_nCurrentDeviceID, nRow, nCol, bNewState);
+	}
+}
+
+void CEquipmentPage1::InitSignalSlotTextAndClickable()
+{
+	if (!::IsWindow(m_ctrlSignalPanel.GetSafeHwnd())) {
+		return;
+	}
+
+	for (int i = 0; i < SIGNAL_GRID_SIZE; ++i) {
+		int nRow = i / SIGNAL_GRID_COLS;
+		int nCol = i % SIGNAL_GRID_COLS;
+
+		const auto& signal = m_vSignalList[i];
+		m_ctrlSignalPanel.SetSlotText(nRow, nCol, signal.strName);
+		m_ctrlSignalPanel.SetSlotClickable(nRow, nCol, signal.bClickable);
+	}
+}
+
+void CEquipmentPage1::UpdateAllSignalStatesFromDevice()
+{
+	if (!m_pEquipment) {
+		return;
+	}
+
+	for (int nRow = 0; nRow < SIGNAL_GRID_ROWS; ++nRow) {
+		for (int nCol = 0; nCol < SIGNAL_GRID_COLS; ++nCol) {
+			BOOL bCurrentState = m_pEquipment->isLinkSignalUpstreamOn(nRow, nCol);
+			UpdateSignalState(nRow, nCol, bCurrentState);
+		}
+	}
+}
+
+void CEquipmentPage1::ResetSignalPanel()
+{
+	if (!::IsWindow(m_ctrlSignalPanel.GetSafeHwnd())) {
+		return;
+	}
+
+	m_ctrlSignalPanel.ClearAll();
+	m_vSignalList.clear();
+	m_nCurrentDeviceID = 0;
 }
 
 BOOL CEquipmentPage1::OnInitDialog()
@@ -50,6 +202,34 @@
 	CHMPropertyPage::OnInitDialog();
 
 	// TODO:  鍦ㄦ娣诲姞棰濆鐨勫垵濮嬪寲
+	m_ctrlSignalPanel.Create(AfxRegisterWndClass(0), _T("SignalGrid"), WS_CHILD | WS_VISIBLE, CRect(0, 0, 100, 100), this, 1002);
+	m_ctrlSignalPanel.SetColors(RGB(0, 200, 0), RGB(220, 220, 220));
+	m_ctrlSignalPanel.SetGridSize(SIGNAL_GRID_ROWS, SIGNAL_GRID_COLS);
+	m_ctrlSignalPanel.SetTextFont(_T("Microsoft YaHei"), 10);
+	m_ctrlSignalPanel.SetSlotClickCallback([this](int nRow, int nCol) {
+		int index = nRow * SIGNAL_GRID_COLS + nCol;
+		if (index >= 0 && index < (int)m_vSignalList.size() && m_vSignalList[index].bClickable && m_pEquipment != nullptr) {
+			// 璇诲彇褰撳墠鐘舵�佸苟鍒囨崲
+			const BOOL bCurrentState = m_pEquipment->isLinkSignalUpstreamOn(nRow, nCol);
+			m_pEquipment->setLinkSignalUpstream(nRow, nCol, !bCurrentState);
+		}
+	});
+
+	{
+		TCHAR szPath[MAX_PATH] = {};
+		GetModuleFileName(nullptr, szPath, MAX_PATH);
+		PathRemoveFileSpec(szPath);
+		CString strCSVFile = CString(szPath) + _T("\\Config\\signals.csv");
+		LoadSignalListFromCSV(strCSVFile);
+	}
+
+	// 濡傛灉璁惧宸茶缃紝鍒欏垵濮嬪寲淇″彿鍒楄〃
+	if (m_pEquipment != nullptr) {
+		InitSignalListForDevice(m_pEquipment->getID());
+	}
+
+	KillTimer(TIMER_ID_SIGNAL_UPDATE);
+	SetTimer(TIMER_ID_SIGNAL_UPDATE, TIMER_INTERVAL_MS, nullptr);
 
 	return TRUE;  // return TRUE unless you set the focus to a control
 				  // 寮傚父: OCX 灞炴�ч〉搴旇繑鍥� FALSE
@@ -70,6 +250,10 @@
 	CHMPropertyPage::OnDestroy();
 
 	// TODO: 鍦ㄦ澶勬坊鍔犳秷鎭鐞嗙▼搴忎唬鐮�
+	KillTimer(TIMER_ID_SIGNAL_UPDATE);
+	if (::IsWindow(m_ctrlSignalPanel.GetSafeHwnd())) {
+		m_ctrlSignalPanel.DestroyWindow();
+	}
 }
 
 void CEquipmentPage1::OnSize(UINT nType, int cx, int cy)
@@ -77,4 +261,21 @@
 	CHMPropertyPage::OnSize(nType, cx, cy);
 
 	// TODO: 鍦ㄦ澶勬坊鍔犳秷鎭鐞嗙▼搴忎唬鐮�
+	if (::IsWindow(m_ctrlSignalPanel.GetSafeHwnd())) {
+		CRect rc;
+		GetClientRect(&rc);
+		rc.DeflateRect(10, 10);
+		m_ctrlSignalPanel.MoveWindow(rc);
+	}
 }
+
+void CEquipmentPage1::OnTimer(UINT_PTR nIDEvent)
+{
+	if (nIDEvent == TIMER_ID_SIGNAL_UPDATE) {
+		if (m_pEquipment && !m_vSignalList.empty()) {
+			UpdateAllSignalStatesFromDevice();
+		}
+	}
+
+	CHMPropertyPage::OnTimer(nIDEvent);
+}
\ No newline at end of file

--
Gitblit v1.9.3