#pragma once #include #include "IODeviceWithSCF.tlh" #include "IODeviceWithSCF.tli" #include "CCOS.Dev.IODevice.Detail.hpp" #include "CCOS.Dev.MSGMould.hpp" #include "CCOS.Dev.Generator.Mould.hpp" #include "CCOS.Dev.Generator.Demo.hpp" #include "DeliverModule.h" #ifdef CCOSDEVGENAlmax_EXPORTS #define _CCOSDEVGENAlmax_API __declspec(dllexport) #else #define _CCOSDEVGENAlmax_API __declspec(dllimport) #endif namespace nsSerialGPM = CCOS::Dev::MODLE::SerialGPM; enum ContainerExample_REGULATION_LEVEL { //故障等级 REG_ERRO, REG_WARN }; namespace CCOS::Dev::Detail::Generator { using cbFun = std::function ; struct tFrameMapItem { cbFun m_fFun; //处理函数 tFrameMapItem(); tFrameMapItem(cbFun f); tFrameMapItem& operator =(const tFrameMapItem& value); }; static const int TIMEOUTVALUE = 100; //----------------------------------------------------------------------------- // AlmaxDevice //----------------------------------------------------------------------------- class _CCOSDEVGENAlmax_API AlmaxDevice : public IODeviceWithSCF ,public GeneratorMould { using super = IODeviceWithSCF ; using superGen = GeneratorMould; public: AlmaxDevice (std::shared_ptr center, nsSCF::SCF SCF, string configfile); ~AlmaxDevice (); //发生器支持的通用命令 virtual std::string GetGUID() const override; virtual RET_STATUS IncKV() override; virtual RET_STATUS DecKV() override; virtual RET_STATUS SetKV(float value) override; virtual RET_STATUS IncMA() override; virtual RET_STATUS DecMA() override; virtual RET_STATUS SetMA(float value) override; virtual RET_STATUS IncMS() override; virtual RET_STATUS DecMS() override; virtual RET_STATUS SetMS(float value) override; virtual RET_STATUS IncMAS() override; virtual RET_STATUS DecMAS() override; virtual RET_STATUS SetMAS(float value) override; virtual RET_STATUS SetTechmode(int value) override; virtual RET_STATUS SetEXAMMode(std::string value) override; virtual RET_STATUS SetFocus(int value) override; virtual RET_STATUS SetAPR(const _tAPRArgs& t) override; virtual RET_STATUS QueryHE(int& value) override; virtual RET_STATUS QueryPostKV(float& value) override; virtual RET_STATUS QueryPostMA(float& value) override; virtual RET_STATUS QueryPostMS(float& value) override; virtual RET_STATUS QueryPostMAS(float& value) override; virtual RET_STATUS SetExpEnable() override; virtual RET_STATUS SetExpDisable()override; virtual RET_STATUS Reset()override; virtual int GetGeneratorBatteryChargState() override; RET_STATUS RefreshData(); RET_STATUS SetRPS(int rps);//设置连续点片帧率,暂不使用 //发生器不支持的命令 virtual RET_STATUS SetAECDensity(int value) override; virtual RET_STATUS SetAECField(int value) override; virtual RET_STATUS SetAECFilm(int value) override; virtual RET_STATUS SetWS(const std::string value) override; virtual RET_STATUS SetGenSynState(int value) override; virtual RET_STATUS SetGenState(int value) override; virtual RET_STATUS SetExpMode(std::string value) override; virtual RET_STATUS SetFrameRate(FLOAT frameRate) override; virtual RET_STATUS SetFLFMode(std::string value) override; RET_STATUS Clear_DAP(); RET_STATUS GetValue_DAP(float& value); RET_STATUS StartMove(); RET_STATUS EndMove(); bool ReConnect(); //重连 //暂不对外提供的指令(ContainerExample特有指令) public: ResDataObject m_GenConfig; //driver's config file. //线程变量互斥锁 static atomic m_iLoopTime; //循环间隔时间(毫秒) atomic m_iHeartBeats; //心跳统计 atomic m_bConnectFlag; //连接标记 static atomic m_bExtraFlag; //轮询使用标记 //串口处理层 static nsSerialGPM::CDeliverModule m_tDelivermodule; int m_nCMDType_WaitTime{ 0 }; int m_nCMDType_HB{ 0 }; int m_nCMDType_WaitACK{ 0 }; static void __stdcall ProcessClientData(const char* pData, unsigned long DataLength, void* lparam); static void __stdcall WriteLog(const char* pData, nsSerialGPM::LOG_V2_LEVEL level); RET_STATUS HWSendWaittimeCMD(char* strCommand, int lengh, int headLengh = 3); RET_STATUS HWSendHBCMD(char* strCommand, int lengh, int headLengh = 3); RET_STATUS HWSendWaitACKCMD(char* strCommand, int lengh, int headLengh = 3); private: float m_DAP; //暂不使用 std::unique_ptr m_MSGUnit; //处理消息上报对象指针 HANDLE m_pHardwareStatusThread; //轮询线程句柄 atomic m_bExpEnable; //曝光使能 private: //bool FormatCommand(const char* oldCommand, int oldLengh, char* newCommand, int &newLengh); RET_STATUS HWSend(const char* strCommand, int lengh, bool reSend = false, int nTimeOut = TIMEOUTVALUE); //指令发送接口 void OnCallBack(); //处理指令回调函数 void Register(); //注册对外提供的属性、方法 bool StartHardwareStatusThread(); //启动轮询线程 static DWORD HardwareStatusThread(LPVOID pParam); //定时查询状态信息 static DWORD HardwareReSendThread(LPVOID pParam); //指令重发 void FireNotify(std::string key, int context);//向上层上报消息 void FireNotify(std::string key, float context); void FireNotify(std::string key, std::string context); void FireErrorMessage(const bool Act, const int Code, const char* ResInfo = ""); //上报错误消息 void FireWarnMessage(const bool Act, const int Code, const char* ResInfo = ""); //上报告警消息 }; } //----------------------------------------------------------------------------- // AlmaxDriver //----------------------------------------------------------------------------- namespace CCOS::Dev::Detail::Generator { class _CCOSDEVGENAlmax_API AlmaxDriver : public IODriverWithSCF { using super = IODriverWithSCF ; public: AlmaxDriver (); virtual ~AlmaxDriver (); public: //virtual bool DriverEntry (std::string CfgFileName); //设置配制文件路径,对外接口最先调用 virtual void Prepare () override; //在 DriverEntry 之后执行;选择与物理设备通信方式(串口、TCP) virtual std::string DriverProbe() override; //在 Prepare 之后执行;读取配置文件模块参数,供上层创建驱动work路径 bool ReConnection(nsSCF::SCF& DevSCF); virtual bool DATA_ACTION Connect () override; //在 DriverProbe 之后执行;根据通信方式与物理设备进行连接 virtual auto CreateDevice(int index)->std::unique_ptr override; //在 Connect 之后执行;创建逻辑设备,供上层创建驱动树节点 virtual bool isConnected() const override; //检查驱动与物理设备连接状态 virtual std::string GetResource() override; //获取配置文件的值 virtual std::string DeviceProbe() override; //读取配置文件模块参数,供上层创建设备work路径 virtual void Disconnect() override; //断开驱动与物理设备连接状态 virtual void Dequeue (const char * Packet, DWORD Length) override; //在super::Connect中轮询,调用 DecodeFrame:查找指令操作对照表,通过对应操作更新数据并调用FireNotify上报更新 virtual void FireNotify (int code, std::string key, std::string content) override; //向监听者上报事件 static PACKET_RET callbackPackageProcess(const char* RecData, DWORD nLength, DWORD& PacketLength); //判断从设备读到的数据有没有可用的数据包,有则最终调度到 Dequeue private: bool SaveConfigFile(bool bSendNotify); virtual bool GetDeviceConfig(std::string& Cfg) override; virtual bool SetDeviceConfig(std::string Cfg) override; bool GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue); bool SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue); ResDataObject m_DeviceConfig; ResDataObject m_ConfigAll; //存储当前的配置,用于修改配置时写回文件 ResDataObject m_Configurations; //存储当前配置中“CONFIGURATION”节点的内容 bool m_bDemoMode; // DEMO 模式 bool m_bDemoConnected; // 在 DEMO 模式下, 是否调用过 Connect //webconfig使用 ResDataObject m_DeviceConfigSend; string g_strAppPath; std::unique_ptr m_pAttribute; std::unique_ptr m_pDescription; }; }