#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;
|
};
|