CCOS.Dev.Generator.CPI.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. #pragma once
  2. #include <thread>
  3. #include <mutex>
  4. #include <condition_variable>
  5. #include <atomic>
  6. #include <memory>
  7. #include <functional>
  8. #include <chrono>
  9. #include "CCOS.Dev.Generator.Mould.hpp"
  10. #include "DAP.BasicMoulds.hpp"
  11. #include "CCOS.Dev.MSGMould.hpp"
  12. #include "CCOS.Dev.IODevice.Detail.hpp"
  13. #include "SCFWrapper.h"
  14. #include "LinuxEvent.h"
  15. #include "OEM.Collimator.h"
  16. #include "OEM.Dap.h"
  17. #include "OEM.Mechanical.h"
  18. #define _CCOSDEVGENCPI_API __attribute__((visibility("default")))
  19. // Linux 兼容的数据类型定义
  20. using DWORD = unsigned long;
  21. using LPVOID = void*;
  22. using BOOL = int;
  23. using HANDLE = void*;
  24. #define TRUE 1
  25. #define FALSE 0
  26. // 睡眠函数(以毫秒为单位)
  27. inline void Sleep(unsigned int milliseconds) {
  28. std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
  29. }
  30. namespace CCOS::Dev::Detail::Generator
  31. {
  32. static const int TIMEOUTVALUE = 100;
  33. //-----------------------------------------------------------------------------
  34. // CPIDevice
  35. //-----------------------------------------------------------------------------
  36. namespace nDev = CCOS::Dev;
  37. namespace DevDAP = CCOS::Dev::Detail::DAP;
  38. class _CCOSDEVGENCPI_API CPIDevice : public IODeviceDetail,public GeneratorMould
  39. {
  40. using super = IODeviceDetail;
  41. using superGen = GeneratorMould;
  42. public:
  43. //CPIDevice (std::shared_ptr <IOEventCenter> center, nsSCF::SCF SCF);
  44. CPIDevice(std::shared_ptr <IOEventCenter> center, std::shared_ptr<SCFWrapper> SCF,string configfile);
  45. ~CPIDevice ();
  46. virtual std::string GetGUID() const override;
  47. private:
  48. RET_STATUS HWSend (const char * strCommand, int nTimeOut = TIMEOUTVALUE);
  49. void OnCallBack ();
  50. std::shared_ptr<SCFWrapper> m_SCF;
  51. std::unique_ptr<DevDAP::DOSEMould> m_DAP;
  52. std::unique_ptr<nsDetail::MSGUnit> m_MSGUnit;
  53. bool StartHardwareStatusThread();
  54. static void HardwareStatusThread(CPIDevice* pParam);
  55. std::thread m_pHardwareStatusThread;
  56. private:
  57. void Register();
  58. public:
  59. virtual RET_STATUS IncKV() override;
  60. virtual RET_STATUS DecKV() override;
  61. virtual RET_STATUS SetKV(float value) override;
  62. virtual RET_STATUS IncMA() override;
  63. virtual RET_STATUS DecMA() override;
  64. virtual RET_STATUS SetMA(float value) override;
  65. virtual RET_STATUS IncMS() override;
  66. virtual RET_STATUS DecMS() override;
  67. virtual RET_STATUS SetMS(float value) override;
  68. virtual RET_STATUS IncMAS() override;
  69. virtual RET_STATUS DecMAS() override;
  70. virtual RET_STATUS SetMAS(float value) override;
  71. virtual RET_STATUS SetTechmode(int value) override;
  72. virtual RET_STATUS SetFocus(int value) override;
  73. virtual RET_STATUS SetAECDensity(int value) override;
  74. virtual RET_STATUS SetAECField(int value) override;
  75. virtual RET_STATUS SetAECFilm(int value) override;
  76. virtual RET_STATUS SetWS(const std::string value) override;
  77. virtual RET_STATUS SetAPR(const _tAPRArgs& t) override;
  78. virtual RET_STATUS QueryHE(int& value) override;
  79. virtual RET_STATUS QueryPostKV(float& value) override;
  80. virtual RET_STATUS QueryPostMA(float& value) override;
  81. virtual RET_STATUS QueryPostMS(float& value) override;
  82. virtual RET_STATUS QueryPostMAS(float& value) override;
  83. virtual RET_STATUS SetGenSynState(int value) override;
  84. virtual RET_STATUS SetGenState(int value) override;
  85. virtual RET_STATUS SetExpEnable() override;
  86. virtual RET_STATUS SetExpDisable()override;
  87. virtual RET_STATUS Reset()override;
  88. virtual RET_STATUS SetExpMode(std::string value) override;
  89. virtual RET_STATUS SetFrameRate(float frameRate) override;
  90. virtual RET_STATUS SetFLFMode(std::string value) override;
  91. virtual RET_STATUS SetEXAMMode(std::string value) override;
  92. //SetGeneratortoSyncStatus
  93. //virtual RET_STATUS SetGeneratortoSyncStatus(std::string value) override;
  94. RET_STATUS Clear_DAP();
  95. RET_STATUS GetValue_DAP(float& value);
  96. RET_STATUS StartMove();
  97. RET_STATUS EndMove();
  98. RET_STATUS SetCollimatorSize(int height,int width);
  99. RET_STATUS SetFilter(int filterType);
  100. RET_STATUS QueryDAP();
  101. //为了将gen和其他设备对象联系起来相互调用接口
  102. RET_STATUS SetCollimatorDev(OemCollimator* dev);
  103. RET_STATUS SetMechDev(OemMechanical* dev);
  104. RET_STATUS SetDapDev(OemDap* dev);
  105. protected:
  106. RET_STATUS RefreshData ();
  107. RET_STATUS SetRPS(int rps);//连续曝光片帧率
  108. private:
  109. void FireNotify (std::string key, std::string context);
  110. std::shared_ptr<LinuxEvent> m_hGenPostEvent; //暂时不使用了.
  111. _tAPRArgs m_t; //放射曝光的参数
  112. string m_strConfigPath; //CPI generator confile.
  113. ResDataObject m_GenConfig; //driver's config file.
  114. /*
  115. GenType == "CPI Series SIS0040B") || (strGenType == "CPI SIS0040B")) 时为1.
  116. GenType == "CPI with positioner I/F"时,set为2
  117. 其它都是0. 一般情况为 GenType == ,CPI,
  118. */
  119. int m_nDeviceType;
  120. bool m_bWithCollimator; //有无coll,用于控制coll size 和 filter
  121. bool m_bExpEnable; //
  122. enum MyEnum
  123. {
  124. EXPOSURE_SOFTWARE_HARDWARE, //0
  125. EXPOSURE_NOSYNBOX_DIRCETCONNECT_DETECTOR_GEN, //1
  126. EXPOSURE_SOFTWARE_NOSYNBOX //2
  127. };
  128. //ysj++
  129. int m_nAECMode;//0 fix 1 mas 2 ms
  130. bool m_bSaveMSMA;//很难理解,但实质是表示 是否在setapr期间
  131. float m_PrefMS;
  132. float m_fPreMA;
  133. int m_nFO;
  134. float m_fMsLimit;
  135. int m_nPreET;
  136. bool m_bInExpState; //用来表示是否在曝光状态,因为在exp状态时,有些指令必须防止发送
  137. int m_nCtlMode;
  138. std::unique_ptr<OemCollimator> m_pCollDev;
  139. //std::unique_ptr<OemMechanical> m_pMechDev;
  140. std::unique_ptr<OemDap> m_pDapDev;
  141. bool m_bCheckATUStatus;//
  142. bool m_bDAPEnable;
  143. std::atomic<bool> m_bExtraFlag{true}; // 硬件状态查询线程使能标记
  144. };
  145. }
  146. //-----------------------------------------------------------------------------
  147. // CPIDriver
  148. //-----------------------------------------------------------------------------
  149. namespace CCOS::Dev::Detail::Generator
  150. {
  151. class _CCOSDEVGENCPI_API CPIDriver : public DriverMould
  152. {
  153. using super = DriverMould;
  154. public:
  155. CPIDriver ();
  156. virtual ~CPIDriver ();
  157. public:
  158. virtual void Prepare () override;
  159. virtual bool DATA_ACTION Connect () override;
  160. virtual void Disconnect() override;
  161. virtual bool isConnected() const override;
  162. virtual void Dequeue (const char * Packet, DWORD Length);
  163. virtual void FireNotify (int code, std::string key, std::string content);
  164. virtual auto CreateDevice (int index)->std::unique_ptr <IODevice> override;
  165. virtual std::string DriverProbe () override;
  166. virtual std::string GetResource () override;
  167. virtual std::string DeviceProbe () override;
  168. virtual bool GetDeviceConfig(std::string& Cfg) override;
  169. virtual bool SetDeviceConfig(std::string Cfg) override;
  170. std::shared_ptr<SCFWrapper> m_scfWrapper;
  171. private:
  172. static PACKET_RET callbackPackageProcess (const char* RecData, uint32_t nLength, uint32_t& PacketLength);
  173. bool m_bDemoConnected; // 在 DEMO 模式下, 调用过 Connect 吗?
  174. CPIDevice* m_pDriGenDev;
  175. OemCollimator* m_pDriCollDev;
  176. OemDap* m_pDriDapDev;
  177. ResDataObject m_DeviceConfig;
  178. ResDataObject m_DeviceConfigSend;
  179. string g_strAppPath;
  180. ResDataObject m_ConfigAll; //存储当前配置,如果修改配置时写入文件
  181. ResDataObject m_Configurations; //存储当前配置中,CONFIGURATION节点内容
  182. std::unique_ptr <ResDataObject> m_pAttribute;
  183. std::unique_ptr <ResDataObject> m_pDescription;
  184. bool SaveConfigFile(bool bSendNotify);
  185. bool GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue);
  186. bool SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue);
  187. //webconfig使用
  188. std::string m_SCFDllName;
  189. };
  190. }