// #pragma once #include #include using namespace std::chrono_literals; #include "SyncEvent.hpp" #include "DIOS.Dev.IODevice.Detail.hpp" #include "SCF.hpp" namespace nsSCF = DIOS::Dev::Communication; //----------------------------------------------------------------------------- // IODeviceWithSCF //----------------------------------------------------------------------------- namespace DIOS::Dev::Detail { template class IODeviceWithSCF : public T { using super = typename T; protected: nsSCF::SCF m_SCF; public: IODeviceWithSCF (std::shared_ptr center, nsSCF::SCF SCF) : super (center) { m_SCF = SCF; } }; } //----------------------------------------------------------------------------- // IODeviceWithSCF //----------------------------------------------------------------------------- namespace DIOS::Dev::Detail { template class IODriverWithSCF : public T { using super = typename T; public: IODriverWithSCF () { m_msWaitSCFTimeOut = 200; // 如果子类不重新设置, 默认就是 0.2 秒 } ~IODriverWithSCF () { std::this_thread::sleep_for (100ms); Disconnect (); } public: virtual void Prepare () override; virtual bool DATA_ACTION Connect () override; virtual void Disconnect () override; virtual bool isConnected () const override; bool DecodePack(bool action); void SetThread_Priority(int level); void SetThread_Affinity(const std::vector& cpus); protected: virtual void Dequeue (const char * Packet, DWORD Length) = 0; virtual void FireNotify (int Code, std::string Key, std::string Content) = 0; protected: nsSCF::SCF m_SCF; SyncEvent::Auto OnNewPacket; std::thread::id m_TID; std::string m_SCFDllName; int m_msWaitSCFTimeOut; bool isActDecodeFun{ true }; int m_nPriority{ 0 }; HANDLE m_ThreadHandle{ NULL }; static const int CMD_LEN_MAX = 1024; }; }