From 5a8bbd2426aeacdbbb2fdb1a7f7a1adce0cac7f9 Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期五, 01 八月 2025 16:23:29 +0800
Subject: [PATCH] 1. 新增以下功能函数并集成: - InitStorage():初始化存储区域 - StartStorage():开始数据存储 - StopStorage():停止存储并自动提取、分析数据 - AnalyzeStoredData():分析指定端口数据,返回偏移量
---
SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp | 239 +++++++++++++++++++++++++++++++++++------------------------
1 files changed, 140 insertions(+), 99 deletions(-)
diff --git a/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp b/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp
index d6bc177..b946b61 100644
--- a/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp
+++ b/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp
@@ -520,6 +520,137 @@
return true;
}
+bool CSGMeasurementDlg::InitDataStorage()
+{
+ if (!m_bConnected) {
+ AppendLogLineRichStyled(_T("璁惧鏈繛鎺ワ紝璇峰厛杩炴帴璁惧銆�"), LOG_COLOR_WARNING);
+ return false;
+ }
+
+ if (m_bSaving) {
+ AppendLogLineRichStyled(_T("鏁版嵁瀛樺偍姝e湪杩涜涓紝璇峰厛鍋滄瀛樺偍銆�"), LOG_COLOR_WARNING);
+ return false;
+ }
+
+ RC nRet = SGIF_DataStorageInit(DeviceID);
+ if (nRet == RC_OK) {
+ AppendLogLineRichStyled(_T("鏁版嵁瀛樺偍宸叉竻闄ゃ��"), LOG_COLOR_SUCCESS);
+ return true;
+ }
+
+ CString strError;
+ strError.Format(_T("娓呴櫎鏁版嵁瀛樺偍澶辫触锛岄敊璇爜锛�%#X"), nRet);
+ AppendLogLineRichStyled(strError, LOG_COLOR_ERROR);
+ return false;
+}
+
+bool CSGMeasurementDlg::StartDataStorage()
+{
+ if (m_bSaving) {
+ AppendLogLineRichStyled(_T("鏁版嵁瀛樺偍宸插湪杩涜涓紝璇峰厛鍋滄瀛樺偍銆�"), LOG_COLOR_WARNING);
+ return false;
+ }
+
+ RC nRet = SGIF_DataStorageStart(DeviceID);
+ if (nRet == RC_OK) {
+ m_bSaving = TRUE;
+ AppendLogLineRichStyled(_T("鏁版嵁瀛樺偍宸插紑濮嬨��"), LOG_COLOR_SUCCESS);
+ return true;
+ }
+
+ CString strError;
+ strError.Format(_T("寮�濮嬫暟鎹瓨鍌ㄥけ璐ワ紝閿欒鐮侊細%#X"), nRet);
+ AppendLogLineRichStyled(strError, LOG_COLOR_ERROR);
+ return false;
+}
+
+bool CSGMeasurementDlg::StopDataStorage()
+{
+ if (!m_bSaving) {
+ AppendLogLineRichStyled(_T("鏁版嵁瀛樺偍鏈湪杩涜涓紝璇峰厛寮�濮嬪瓨鍌ㄣ��"), LOG_COLOR_WARNING);
+ return false;
+ }
+
+ RC nRet = SGIF_DataStorageStop(DeviceID);
+ if (nRet == RC_OK) {
+ m_bSaving = FALSE;
+ AppendLogLineRichStyled(_T("鏁版嵁瀛樺偍宸插仠姝€��"), LOG_COLOR_SUCCESS);
+ return true;
+ }
+
+ CString strError;
+ strError.Format(_T("鍋滄鏁版嵁瀛樺偍澶辫触锛岄敊璇爜锛�%#X"), nRet);
+ AppendLogLineRichStyled(strError, LOG_COLOR_ERROR);
+ return false;
+}
+
+float CSGMeasurementDlg::AnalyzeStoredData(int nOutNo)
+{
+ UpdateData(TRUE);
+
+ if (m_nUseTrigger) {
+ UpdateControlStatus(m_bConnected, m_bSaving);
+ AfxMessageBox(_T("褰撳墠鏄‖瑙﹀彂妯″紡锛岃妫�鏌ヨЕ鍙戝櫒鐘舵�併��"), MB_ICONINFORMATION);
+ return -1.0f;
+ }
+
+ if (!m_bConnected) {
+ AppendLogLineRichStyled(_T("璁惧鏈繛鎺ワ紝璇峰厛杩炴帴璁惧銆�"), LOG_COLOR_WARNING);
+ return -1.0f;
+ }
+
+ if (m_bSaving) {
+ AppendLogLineRichStyled(_T("鏁版嵁瀛樺偍姝e湪杩涜涓紝璇峰厛鍋滄瀛樺偍銆�"), LOG_COLOR_WARNING);
+ return -1.0f;
+ }
+
+ if (nOutNo < 1 || nOutNo > 4) {
+ AppendLogLineRichStyled(_T("杈撳嚭绔彛缂栧彿鏃犳晥锛屽繀椤诲湪 1 鍒� 4 涔嬮棿銆�"), LOG_COLOR_ERROR);
+ return -1.0f;
+ }
+
+ if (m_nSavePointCount < 0) {
+ AppendLogLineRichStyled(_T("鏁版嵁鐐规暟蹇呴』澶т簬 0銆�"), LOG_COLOR_ERROR);
+ return -1.0f;
+ }
+
+ std::vector<float> vecBuffer(m_nSavePointCount, 0.0f);
+ int nReceived = 0;
+
+ RC nRet = SGIF_DataStorageGetData(DeviceID, nOutNo, m_nSavePointCount, vecBuffer.data(), &nReceived);
+ if (nRet != RC_OK) {
+ CString strError;
+ strError.Format(_T("璇诲彇 OUT%d 鏁版嵁澶辫触锛岄敊璇爜锛�%#X"), nOutNo, nRet);
+ AppendLogLineRichStyled(strError, LOG_COLOR_ERROR);
+ return -1.0f;
+ }
+
+ vecBuffer.resize(nReceived);
+ CleanInvalidValuesInPlace(nOutNo, vecBuffer);
+
+ std::vector<float> vecGlass1, vecGlass2;
+ if (!SplitGlassSegments(nOutNo, vecBuffer, vecGlass1, vecGlass2, m_fJumpThreshold, m_nJumpWindow, m_nValleyMargin, m_nMinGlass1Count)) {
+ AppendLogLineRichStyled(_T("鏈兘璇嗗埆鍑轰袱鐗囩幓鐠冪殑鏁版嵁銆�"), LOG_COLOR_WARNING);
+ return -1.0f;
+ }
+
+ std::vector<float> vecStable1, vecStable2;
+ bool bStable1 = ExtractStableRegionFixed(nOutNo, vecGlass1, vecStable1, m_nFixedCount, m_fMaxDelta);
+ bool bStable2 = ExtractStableRegionFixed(nOutNo, vecGlass2, vecStable2, m_nFixedCount, m_fMaxDelta);
+
+ float fAvg1 = 0.0f, fAvg2 = 0.0f, fOffset = 0.0f;
+ if (bStable1 && bStable2) {
+ AppendLogLineRichStyled(_T("鎴愬姛鎻愬彇鍒颁袱鐗囩幓鐠冪殑绋冲畾鍖烘暟鎹��"), LOG_COLOR_SUCCESS);
+ CalcGlassOffset(vecStable1, vecStable2, fAvg1, fAvg2, fOffset);
+ }
+ else {
+ AppendLogLineRichStyled(_T("鏈兘鎻愬彇鍒扮ǔ瀹氬尯鏁版嵁锛屽皾璇曚娇鐢ㄥ師濮嬪垎娈垫暟鎹绠楀亸绉汇��"), LOG_COLOR_WARNING);
+ CalcGlassOffset(vecGlass1, vecGlass2, fAvg1, fAvg2, fOffset);
+ }
+
+ return fOffset;
+}
+
BEGIN_MESSAGE_MAP(CSGMeasurementDlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
@@ -827,120 +958,30 @@
void CSGMeasurementDlg::OnBnClickedButtonClearStore()
{
// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
- if (!m_bConnected) {
- AppendLogLineRichStyled(_T("璁惧鏈繛鎺ワ紝璇峰厛杩炴帴璁惧銆�"), LOG_COLOR_WARNING);
- return;
- }
-
- if (m_bSaving) {
- AppendLogLineRichStyled(_T("鏁版嵁瀛樺偍姝e湪杩涜涓紝璇峰厛鍋滄瀛樺偍銆�"), LOG_COLOR_WARNING);
- return;
- }
-
- RC nRet = SGIF_DataStorageInit(DeviceID);
- if (nRet == RC_OK) {
- AppendLogLineRichStyled(_T("鏁版嵁瀛樺偍宸叉竻闄ゃ��"), LOG_COLOR_SUCCESS);
- }
- else {
- CString strError;
- strError.Format(_T("娓呴櫎鏁版嵁瀛樺偍澶辫触锛岄敊璇爜锛�%#X"), nRet);
- AppendLogLineRichStyled(strError, LOG_COLOR_ERROR);
- }
+ InitDataStorage();
}
void CSGMeasurementDlg::OnBnClickedButtonStartStore()
{
// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
- if (m_bSaving) {
- AppendLogLineRichStyled(_T("鏁版嵁瀛樺偍宸插湪杩涜涓紝璇峰厛鍋滄瀛樺偍銆�"), LOG_COLOR_WARNING);
- return;
- }
-
- RC nRet = SGIF_DataStorageStart(DeviceID);
- if (nRet == RC_OK) {
- m_bSaving = TRUE;
- AppendLogLineRichStyled(_T("鏁版嵁瀛樺偍宸插紑濮嬨��"), LOG_COLOR_SUCCESS);
- }
- else {
- CString strError;
- strError.Format(_T("寮�濮嬫暟鎹瓨鍌ㄥけ璐ワ紝閿欒鐮侊細%#X"), nRet);
- AppendLogLineRichStyled(strError, LOG_COLOR_ERROR);
- }
-
+ StartDataStorage();
UpdateControlStatus(m_bConnected, m_bSaving);
}
void CSGMeasurementDlg::OnBnClickedButtonStopStore()
{
// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
- UpdateData(TRUE);
+ StopDataStorage();
+ UpdateControlStatus(m_bConnected, m_bSaving);
- if (!m_bSaving) {
- AppendLogLineRichStyled(_T("鏁版嵁瀛樺偍鏈湪杩涜涓紝璇峰厛寮�濮嬪瓨鍌ㄣ��"), LOG_COLOR_WARNING);
+ int nSel = m_comboOutputPort.GetCurSel();
+ if (CB_ERR == nSel) {
+ AppendLogLineRichStyled(_T("璇烽�夋嫨涓�涓湁鏁堢殑杈撳嚭绔彛銆�"), LOG_COLOR_WARNING);
return;
}
- RC nRet = SGIF_DataStorageStop(DeviceID);
- if (nRet == RC_OK) {
- m_bSaving = FALSE;
- AppendLogLineRichStyled(_T("鏁版嵁瀛樺偍宸插仠姝€��"), LOG_COLOR_SUCCESS);
-
- if (m_nUseTrigger) {
- UpdateControlStatus(m_bConnected, m_bSaving);
- AfxMessageBox(_T("褰撳墠鏄‖瑙﹀彂妯″紡锛岃妫�鏌ヨЕ鍙戝櫒鐘舵�併��"), MB_ICONINFORMATION);
- return;
- }
-
- int nReceived = 0;
- std::vector<float> vecBuffer(m_nSavePointCount, 0.0f);
-
- int nSel = m_comboOutputPort.GetCurSel();
- if (CB_ERR == nSel) {
- AppendLogLineRichStyled(_T("璇烽�夋嫨涓�涓湁鏁堢殑杈撳嚭绔彛銆�"), LOG_COLOR_WARNING);
- return;
- }
-
- int nOutNo = nSel + 1;
- nRet = SGIF_DataStorageGetData(DeviceID, nOutNo, m_nSavePointCount, vecBuffer.data(), &nReceived);
-
- CString strLog;
- if (nRet == RC_OK) {
- vecBuffer.resize(nReceived);
- CleanInvalidValuesInPlace(nOutNo, vecBuffer);
-
- std::vector<float> vecGlass1, vecGlass2;
- if (SplitGlassSegments(nOutNo, vecBuffer, vecGlass1, vecGlass2, m_fJumpThreshold, m_nJumpWindow, m_nValleyMargin, m_nMinGlass1Count)) {
-
- std::vector<float> vecStableGlass1, vecStableGlass2;
- bool bStable1 = ExtractStableRegionFixed(nOutNo, vecGlass1, vecStableGlass1, m_nFixedCount, m_fMaxDelta);
- bool bStable2 = ExtractStableRegionFixed(nOutNo, vecGlass2, vecStableGlass2, m_nFixedCount, m_fMaxDelta);
-
- float fAvg1 = 0.0f, fAvg2 = 0.0f, fOffset = 0.0f;
- if (bStable1 && bStable2) {
- AppendLogLineRichStyled(_T("鎴愬姛鎻愬彇鍒颁袱鐗囩幓鐠冪殑绋冲畾鍖烘暟鎹��"), LOG_COLOR_SUCCESS);
- CalcGlassOffset(vecStableGlass1, vecStableGlass2, fAvg1, fAvg2, fOffset);
- }
- else {
- AppendLogLineRichStyled(_T("鏈兘鎻愬彇鍒扮ǔ瀹氬尯鏁版嵁锛屾棤娉曟甯歌绠楀亸绉汇��"), LOG_COLOR_WARNING);
- CalcGlassOffset(vecGlass1, vecGlass2, fAvg1, fAvg2, fOffset);
- }
- }
- else {
- AppendLogLineRichStyled(_T("鏈兘璇嗗埆鍑轰袱鐗囩幓鐠冪殑鏁版嵁銆�"), LOG_COLOR_WARNING);
- }
- }
- else {
- strLog.Format(_T("璇诲彇 OUT%d 鏁版嵁澶辫触锛岄敊璇爜锛�%#X"), nOutNo, nRet);
- AppendLogLineRichStyled(strLog, LOG_COLOR_ERROR);
- }
- }
- else {
- CString strError;
- strError.Format(_T("鍋滄鏁版嵁瀛樺偍澶辫触锛岄敊璇爜锛�%#X"), nRet);
- AppendLogLineRichStyled(strError, LOG_COLOR_ERROR);
- }
-
- UpdateControlStatus(m_bConnected, m_bSaving);
+ int nOutNo = nSel + 1;
+ AnalyzeStoredData(nOutNo);
}
void CSGMeasurementDlg::OnBnClickedButtonClearLog()
--
Gitblit v1.9.3