From f4a795105507799c5446657aa1b915ef70293af1 Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期一, 04 八月 2025 18:20:17 +0800
Subject: [PATCH] 1. 修改SGMeasurement工程文件,添加生成后事件和远程调试

---
 SourceCode/Bond/SGMeasurement/PLCSignalListener.h |   56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/SourceCode/Bond/SGMeasurement/PLCSignalListener.h b/SourceCode/Bond/SGMeasurement/PLCSignalListener.h
new file mode 100644
index 0000000..cce8782
--- /dev/null
+++ b/SourceCode/Bond/SGMeasurement/PLCSignalListener.h
@@ -0,0 +1,56 @@
+#pragma once
+
+#include "CCLinkIEControl.h"
+
+#include <thread>
+#include <atomic>
+#include <functional>
+#include <vector>
+
+using OutValuesArray = std::array<double, 4>;
+using Callback = std::function<void()>;
+using AnalyzeCallback = std::function<OutValuesArray()>;
+using LogCallback = std::function<void(const CString& strContent, int type)>;
+
+class CPLCSignalListener
+{
+public:
+    CPLCSignalListener();
+    ~CPLCSignalListener();
+
+    bool Initialize(StationIdentifier station, int nIntervalMs = 200);
+
+    void SetStartCallback(Callback cb);
+    void SetStopCallback(Callback cb);
+    void SetAnalyzeCallback(AnalyzeCallback cb);
+    void SetLogCallback(LogCallback cb);
+
+    bool Start();
+    void Stop();
+
+    bool WriteOutValues(const OutValuesArray& values);
+
+private:
+    void PulseBitDevice(DeviceType eDevType, short nBitNo, int nDelayMs = 50);
+    void HandleAckLife(int i, bool bCurrTriggerBit);
+    void ThreadProc();
+
+private:
+    std::unique_ptr<CCCLinkIEControl> m_pPlc;
+    StationIdentifier m_station;
+    int m_nIntervalMs = 200;
+
+    std::atomic<bool> m_bConnected{ false };
+    std::atomic<bool> m_bRunning{ false };
+    std::thread m_thread;
+    std::vector<bool> m_vecPrevBits;
+
+    std::array<bool, 2> m_vecAckSent = { false, false }; // 是否已发送 M10/M11
+    std::array<int, 2> m_vecAckCounter = { 0, 0 };       // 计数器,超时自动清除
+
+    Callback m_cbStart;
+    Callback m_cbStop;
+    AnalyzeCallback m_cbAnalyze;
+    LogCallback m_cbLog;
+};
+

--
Gitblit v1.9.3