DIOS.Dev.Generator.ContainerExample.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #pragma once
  2. #include <atomic>
  3. #include "IODeviceWithSCF.tlh"
  4. #include "IODeviceWithSCF.tli"
  5. #include "CCOS.Dev.IODevice.Detail.hpp"
  6. #include "CCOS.Dev.MSGMould.hpp"
  7. #include "CCOS.Dev.Generator.Mould.hpp"
  8. #include "CCOS.Dev.Generator.Demo.hpp"
  9. #include "DeliverModule.h"
  10. #ifdef CCOSDEVGENAlmax_EXPORTS
  11. #define _CCOSDEVGENAlmax_API __declspec(dllexport)
  12. #else
  13. #define _CCOSDEVGENAlmax_API __declspec(dllimport)
  14. #endif
  15. namespace nsSerialGPM = CCOS::Dev::MODLE::SerialGPM;
  16. enum ContainerExample_REGULATION_LEVEL { //故障等级
  17. REG_ERRO,
  18. REG_WARN
  19. };
  20. namespace CCOS::Dev::Detail::Generator
  21. {
  22. using cbFun = std::function <void(char*, int)>;
  23. struct tFrameMapItem
  24. {
  25. cbFun m_fFun; //处理函数
  26. tFrameMapItem();
  27. tFrameMapItem(cbFun f);
  28. tFrameMapItem& operator =(const tFrameMapItem& value);
  29. };
  30. static const int TIMEOUTVALUE = 100;
  31. //-----------------------------------------------------------------------------
  32. // AlmaxDevice
  33. //-----------------------------------------------------------------------------
  34. class _CCOSDEVGENAlmax_API AlmaxDevice : public IODeviceWithSCF <IODeviceDetail>,public GeneratorMould
  35. {
  36. using super = IODeviceWithSCF <IODeviceDetail>;
  37. using superGen = GeneratorMould;
  38. public:
  39. AlmaxDevice (std::shared_ptr <IOEventCenter> center, nsSCF::SCF SCF, string configfile);
  40. ~AlmaxDevice ();
  41. //发生器支持的通用命令
  42. virtual std::string GetGUID() const override;
  43. virtual RET_STATUS IncKV() override;
  44. virtual RET_STATUS DecKV() override;
  45. virtual RET_STATUS SetKV(float value) override;
  46. virtual RET_STATUS IncMA() override;
  47. virtual RET_STATUS DecMA() override;
  48. virtual RET_STATUS SetMA(float value) override;
  49. virtual RET_STATUS IncMS() override;
  50. virtual RET_STATUS DecMS() override;
  51. virtual RET_STATUS SetMS(float value) override;
  52. virtual RET_STATUS IncMAS() override;
  53. virtual RET_STATUS DecMAS() override;
  54. virtual RET_STATUS SetMAS(float value) override;
  55. virtual RET_STATUS SetTechmode(int value) override;
  56. virtual RET_STATUS SetEXAMMode(std::string value) override;
  57. virtual RET_STATUS SetFocus(int value) override;
  58. virtual RET_STATUS SetAPR(const _tAPRArgs& t) override;
  59. virtual RET_STATUS QueryHE(int& value) override;
  60. virtual RET_STATUS QueryPostKV(float& value) override;
  61. virtual RET_STATUS QueryPostMA(float& value) override;
  62. virtual RET_STATUS QueryPostMS(float& value) override;
  63. virtual RET_STATUS QueryPostMAS(float& value) override;
  64. virtual RET_STATUS SetExpEnable() override;
  65. virtual RET_STATUS SetExpDisable()override;
  66. virtual RET_STATUS Reset()override;
  67. virtual int GetGeneratorBatteryChargState() override;
  68. RET_STATUS RefreshData();
  69. RET_STATUS SetRPS(int rps);//设置连续点片帧率,暂不使用
  70. //发生器不支持的命令
  71. virtual RET_STATUS SetAECDensity(int value) override;
  72. virtual RET_STATUS SetAECField(int value) override;
  73. virtual RET_STATUS SetAECFilm(int value) override;
  74. virtual RET_STATUS SetWS(const std::string value) override;
  75. virtual RET_STATUS SetGenSynState(int value) override;
  76. virtual RET_STATUS SetGenState(int value) override;
  77. virtual RET_STATUS SetExpMode(std::string value) override;
  78. virtual RET_STATUS SetFrameRate(FLOAT frameRate) override;
  79. virtual RET_STATUS SetFLFMode(std::string value) override;
  80. RET_STATUS Clear_DAP();
  81. RET_STATUS GetValue_DAP(float& value);
  82. RET_STATUS StartMove();
  83. RET_STATUS EndMove();
  84. bool ReConnect(); //重连
  85. //暂不对外提供的指令(ContainerExample特有指令)
  86. public:
  87. ResDataObject m_GenConfig; //driver's config file.
  88. //线程变量互斥锁
  89. static atomic<int> m_iLoopTime; //循环间隔时间(毫秒)
  90. atomic<int> m_iHeartBeats; //心跳统计
  91. atomic<bool> m_bConnectFlag; //连接标记
  92. static atomic<bool> m_bExtraFlag; //轮询使用标记
  93. //串口处理层
  94. static nsSerialGPM::CDeliverModule m_tDelivermodule;
  95. int m_nCMDType_WaitTime{ 0 };
  96. int m_nCMDType_HB{ 0 };
  97. int m_nCMDType_WaitACK{ 0 };
  98. static void __stdcall ProcessClientData(const char* pData, unsigned long DataLength, void* lparam);
  99. static void __stdcall WriteLog(const char* pData, nsSerialGPM::LOG_V2_LEVEL level);
  100. RET_STATUS HWSendWaittimeCMD(char* strCommand, int lengh, int headLengh = 3);
  101. RET_STATUS HWSendHBCMD(char* strCommand, int lengh, int headLengh = 3);
  102. RET_STATUS HWSendWaitACKCMD(char* strCommand, int lengh, int headLengh = 3);
  103. private:
  104. float m_DAP; //暂不使用
  105. std::unique_ptr<nsDetail::MSGUnit> m_MSGUnit; //处理消息上报对象指针
  106. HANDLE m_pHardwareStatusThread; //轮询线程句柄
  107. atomic<bool> m_bExpEnable; //曝光使能
  108. private:
  109. //bool FormatCommand(const char* oldCommand, int oldLengh, char* newCommand, int &newLengh);
  110. RET_STATUS HWSend(const char* strCommand, int lengh, bool reSend = false, int nTimeOut = TIMEOUTVALUE); //指令发送接口
  111. void OnCallBack(); //处理指令回调函数
  112. void Register(); //注册对外提供的属性、方法
  113. bool StartHardwareStatusThread(); //启动轮询线程
  114. static DWORD HardwareStatusThread(LPVOID pParam); //定时查询状态信息
  115. static DWORD HardwareReSendThread(LPVOID pParam); //指令重发
  116. void FireNotify(std::string key, int context);//向上层上报消息
  117. void FireNotify(std::string key, float context);
  118. void FireNotify(std::string key, std::string context);
  119. void FireErrorMessage(const bool Act, const int Code, const char* ResInfo = ""); //上报错误消息
  120. void FireWarnMessage(const bool Act, const int Code, const char* ResInfo = ""); //上报告警消息
  121. };
  122. }
  123. //-----------------------------------------------------------------------------
  124. // AlmaxDriver
  125. //-----------------------------------------------------------------------------
  126. namespace CCOS::Dev::Detail::Generator
  127. {
  128. class _CCOSDEVGENAlmax_API AlmaxDriver : public IODriverWithSCF <DriverMould>
  129. {
  130. using super = IODriverWithSCF <DriverMould>;
  131. public:
  132. AlmaxDriver ();
  133. virtual ~AlmaxDriver ();
  134. public:
  135. //virtual bool DriverEntry (std::string CfgFileName); //设置配制文件路径,对外接口最先调用
  136. virtual void Prepare () override; //在 DriverEntry 之后执行;选择与物理设备通信方式(串口、TCP)
  137. virtual std::string DriverProbe() override; //在 Prepare 之后执行;读取配置文件模块参数,供上层创建驱动work路径
  138. bool ReConnection(nsSCF::SCF& DevSCF);
  139. virtual bool DATA_ACTION Connect () override; //在 DriverProbe 之后执行;根据通信方式与物理设备进行连接
  140. virtual auto CreateDevice(int index)->std::unique_ptr <IODevice> override; //在 Connect 之后执行;创建逻辑设备,供上层创建驱动树节点
  141. virtual bool isConnected() const override; //检查驱动与物理设备连接状态
  142. virtual std::string GetResource() override; //获取配置文件的值
  143. virtual std::string DeviceProbe() override; //读取配置文件模块参数,供上层创建设备work路径
  144. virtual void Disconnect() override; //断开驱动与物理设备连接状态
  145. virtual void Dequeue (const char * Packet, DWORD Length) override; //在super::Connect中轮询,调用 DecodeFrame:查找指令操作对照表,通过对应操作更新数据并调用FireNotify上报更新
  146. virtual void FireNotify (int code, std::string key, std::string content) override; //向监听者上报事件
  147. static PACKET_RET callbackPackageProcess(const char* RecData, DWORD nLength, DWORD& PacketLength); //判断从设备读到的数据有没有可用的数据包,有则最终调度到 Dequeue
  148. private:
  149. bool SaveConfigFile(bool bSendNotify);
  150. virtual bool GetDeviceConfig(std::string& Cfg) override;
  151. virtual bool SetDeviceConfig(std::string Cfg) override;
  152. bool GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue);
  153. bool SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue);
  154. ResDataObject m_DeviceConfig;
  155. ResDataObject m_ConfigAll; //存储当前的配置,用于修改配置时写回文件
  156. ResDataObject m_Configurations; //存储当前配置中“CONFIGURATION”节点的内容
  157. bool m_bDemoMode; // DEMO 模式
  158. bool m_bDemoConnected; // 在 DEMO 模式下, 是否调用过 Connect
  159. //webconfig使用
  160. ResDataObject m_DeviceConfigSend;
  161. string g_strAppPath;
  162. std::unique_ptr <ResDataObject> m_pAttribute;
  163. std::unique_ptr <ResDataObject> m_pDescription;
  164. };
  165. }