CCOS.Dev.Generator.Delta_50KCXAF.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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.IODevice.Detail.hpp"
  10. #include "CCOS.Dev.MSGMould.hpp"
  11. #include "CCOS.Dev.Generator.Mould.hpp"
  12. #include "DAP.BasicMoulds.hpp"
  13. // Linux版本:不再使用 DeliverModule
  14. // #include "DeliverModule.h"
  15. #include "LogicClient.h"
  16. #include "SCFWrapper.h"
  17. #define _CCOSDEVGENDelta_API __attribute__((visibility("default")))
  18. // Linux 兼容的数据类型定义
  19. #include <cstdint>
  20. #include <cstring>
  21. using DWORD = unsigned long;
  22. using LPVOID = void*;
  23. using BOOL = int;
  24. using HANDLE = void*;
  25. using HMODULE = void*;
  26. using UINT8 = uint8_t;
  27. using UINT16 = uint16_t;
  28. using UINT32 = uint32_t;
  29. using BYTE = uint8_t;
  30. using WORD = uint16_t;
  31. using CHAR = char;
  32. using UCHAR = unsigned char;
  33. using FLOAT = float;
  34. #define TRUE 1
  35. #define FALSE 0
  36. #define MAX_PATH 260
  37. // 睡眠函数(以毫秒为单位)
  38. inline void Sleep(unsigned int milliseconds) {
  39. std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
  40. }
  41. enum DELTA_MOBILE_ABNORMAL_LEVEL { //���ϵȼ�
  42. REG_ERRO,
  43. REG_WARN
  44. };
  45. enum TransToType
  46. {
  47. tochar = 0,
  48. toint,
  49. tohex
  50. };
  51. struct AECINFORM
  52. {
  53. int Chamber;
  54. int Field;
  55. int Density;
  56. int FilmScreenSpeed;
  57. };
  58. static const int TIMEOUTVALUE = 100;
  59. //-----------------------------------------------------------------------------
  60. // DeltaMobileDevice
  61. //-----------------------------------------------------------------------------
  62. namespace CCOS::Dev::Detail::Generator
  63. {
  64. namespace nDev = CCOS::Dev;
  65. namespace DevDAP = CCOS::Dev::Detail::DAP;
  66. class _CCOSDEVGENDelta_API DeltaMobileDevice : public IODeviceDetail,public GeneratorMould
  67. {
  68. using super = IODeviceDetail;
  69. using superGen = GeneratorMould;
  70. public:
  71. DeltaMobileDevice(std::shared_ptr <IOEventCenter> center, std::shared_ptr<SCFWrapper> SCF,string configfile);
  72. ~DeltaMobileDevice ();
  73. bool DecodeFrame(const char* strPackage, int nLength);
  74. virtual std::string GetGUID() const override;
  75. virtual RET_STATUS IncKV() override;
  76. virtual RET_STATUS DecKV() override;
  77. virtual RET_STATUS SetKV(float value) override;
  78. virtual RET_STATUS IncMA() override;
  79. virtual RET_STATUS DecMA() override;
  80. virtual RET_STATUS SetMA(float value) override;
  81. virtual RET_STATUS IncMS() override;
  82. virtual RET_STATUS DecMS() override;
  83. virtual RET_STATUS SetMS(float value) override;
  84. virtual RET_STATUS IncMAS() override;
  85. virtual RET_STATUS DecMAS() override;
  86. virtual RET_STATUS SetMAS(float value) override;
  87. virtual RET_STATUS SetTechmode(int value) override; //0x01--AEC mode 0x02--Ms mode 0x03--mAs mode
  88. virtual RET_STATUS SetFocus(int value) override; //0x01--large:0x02--small:0x03--auto
  89. virtual RET_STATUS SetAECDensity(int value) override;
  90. virtual RET_STATUS SetAECField(int value) override;
  91. virtual RET_STATUS SetAECFilm(int value) override;
  92. virtual RET_STATUS SetWS(const std::string value) override;
  93. virtual RET_STATUS SetAPR(const _tAPRArgs& t) override;
  94. virtual RET_STATUS QueryHE(int& value) override;
  95. virtual RET_STATUS QueryPostKV(float& value) override;
  96. virtual RET_STATUS QueryPostMA(float& value) override;
  97. virtual RET_STATUS QueryPostMS(float& value) override;
  98. virtual RET_STATUS QueryPostMAS(float& value) override;
  99. virtual RET_STATUS SetGenSynState(int value) override;
  100. virtual RET_STATUS SetGenState(int value) override;
  101. virtual RET_STATUS SetExpEnable() override;
  102. virtual RET_STATUS SetExpDisable()override;
  103. virtual RET_STATUS Reset()override;
  104. virtual RET_STATUS SetExpMode(std::string value) override;
  105. virtual RET_STATUS SetFrameRate(FLOAT frameRate) override;
  106. virtual RET_STATUS SetFLFMode(std::string value) override;
  107. virtual RET_STATUS SetEXAMMode(std::string value) override;
  108. virtual RET_STATUS ActiveSyncMode(_tSyncModeArgs value) override;
  109. virtual RET_STATUS ResetFluTimer(int ntype) override;
  110. virtual RET_STATUS SetPPS(float frameRate) override;
  111. static DeltaMobileDevice* g_GenDevice;
  112. int m_nCMDType_ACK{ 0 };
  113. int m_nCMDType_WaitTime{ 0 };
  114. int m_nCMDType_WaitACK{ 0 };
  115. int m_nCMDType_WaitSELF{ 0 };
  116. static void ProcessClientData(const char* pData, unsigned long DataLength, void* lparam);
  117. RET_STATUS HWSendWaitACKCMD(string strCommand, int headLengh = 1);
  118. //轮询处理
  119. static atomic<int> m_iLoopTime; //循环间隔时间(毫秒)
  120. static atomic<bool> m_bExtraFlag; // 使能标记
  121. std::mutex m_exitMutex;
  122. std::condition_variable m_exitCondition;
  123. bool m_bExitFlag{ false };
  124. bool StartHardwareStatusThread();
  125. static void HardwareStatusThread(DeltaMobileDevice* pParam);
  126. std::thread m_pHardwareStatusThread;
  127. bool m_nProcessXrayon{ false };
  128. std::atomic<int> m_nCountTimes{ 0 }; // 计数器(线程安全)
  129. private:
  130. void Register();
  131. RET_STATUS RefreshData();
  132. //发送消息
  133. RET_STATUS HWSend(const char * strCommand, int length = 0, bool reSend = false, int nTimeOut = TIMEOUTVALUE);
  134. void OnCallBack();
  135. std::shared_ptr<SCFWrapper> m_SCF;
  136. //上报消息
  137. void FireNotify(std::string key, std::string context);
  138. void FireErrorMessage(const bool Act, const int Code, const char* ResInfo = ""); //上报错误消息
  139. void FireWarnMessage(const bool Act, const int Code, const char* ResInfo = ""); //上报告警消息
  140. void GetConfData();
  141. _tSyncModeArgs m_cfgCurrentWSSYN; //当前选中的工作位和对应的同步模式
  142. _tAPRArgs m_tAPRdata; //保存服务传入的参数
  143. ResDataObject m_GenConfig; //driver's config file
  144. std::unique_ptr<DevDAP::DOSEMould> m_DAP; //DAP值
  145. std::unique_ptr<nsDetail::MSGUnit> m_MSGUnit; //错误消息处理对象
  146. string m_ErrorCode; //错误码,防止重复发送
  147. //lsy
  148. bool ChangeGenParam(int kv, float fma, float fms, float fmas);
  149. int FormatCommand(char* buf, int len);
  150. int GetFacFloatValue(vector<float> Index, float& value);
  151. string m_strCommand;
  152. string uint8ArrayToHexStr(const UINT8* array, size_t length);
  153. string m_strKV;
  154. vector<int> m_vecKV;
  155. string m_strMAS;
  156. vector<float> m_vecMAS;
  157. string m_strMA;
  158. vector<float> m_vecMA;
  159. string m_strMS;
  160. vector<float> m_vecMS;
  161. int m_nTubeMaSFMaxValue{ 160 };
  162. int m_nTubeMaBFMinValue{ 180 };
  163. bool m_nTableUsePanelAEC{ false };
  164. bool m_nWallUsePanelAEC{ false };
  165. bool m_nFreeUsePanelAEC{ false };
  166. bool m_nTableUsePanelDDR{ false };
  167. bool m_nWallUsePanelDDR{ false };
  168. bool m_nFreeUsePanelDDR{ false };
  169. bool SetDAECEnable(int enable);//打开关闭DAEC功能
  170. int m_nChamberIndex{ 1 };
  171. int m_nAecFiled{2};
  172. int m_nAecDensity{0};
  173. int m_nAecFilm{ 0 };
  174. bool SetDualEnergyCommand(const _tAPRArgs& t);
  175. bool m_bIsDualExp{ false };
  176. int m_nExposureNumber{ 0 };
  177. bool SetAPRForDual(int nWS, int nFO, int nET, int nAECFieldSel, int nAECFilmSel, float fAECDensity, float fKV, float fMA, float fMS, float fMAS);
  178. std::unordered_map<std::string, std::string> m_ErrorMessages;
  179. std::unordered_map<std::string, std::string> m_WarnMessages;
  180. std::unique_ptr<LogicClient> m_pDetectorClient;
  181. int m_nDEFrameRate{ 1 };
  182. //0x01--Low Level Reset Function 用于复位3开头的错误
  183. //0x02--Clear setup 清除所有曝光参数
  184. //0x03--High Level Reset Function 用于复位4开头的错误
  185. int m_nCurErrLevel{ 0 };
  186. bool m_bXronMsg{ false };
  187. void SeleckDetectorNumber(int detectorID);
  188. void SetNoDrMode();
  189. void SetSyncOutMode();
  190. void GetHE();
  191. //common
  192. string AnalysisCommand(int number, const char* chdigital, int type);
  193. //LSY
  194. void RetrieveFirewareVersion();
  195. void RetrieveModelName();
  196. void RetrieveSerialNumber();
  197. void RetrieveMaxRating();
  198. int m_nMaxKW{ 0 };
  199. int m_nMaxMA{ 0 };
  200. int m_nMaxMAS{ 0 };
  201. int m_nMaxKV{ 0 };
  202. void RetrieveGeneratroDerating();
  203. void RetrieveAECDAPFirmwareVersion();
  204. void RetrieveTubePartNumber();
  205. void RetrieveTubeMaxPower();
  206. void RetrieveTubeFilamentCurrent();
  207. void RetrieveTubeHULimit();
  208. void RetrieveTubeDeratingInformation();
  209. void RetrieveRunningMode();//AEC 1 MS 2 MAS 3
  210. void RetrieveDataAndTime();
  211. void RetrieveErrorCode();
  212. void RetrieveErrorParameters();//待补充
  213. void RetrieveExposureResult();//获取曝光后的参数
  214. void RetrieveRadioMode();//获取当前点片模式 单帧序列 单能双能
  215. void RetrieveFluMode();//获取当前透视模式
  216. void RetrieveAECInformation();//获取AEC信息
  217. //AEC相关
  218. void UpdataAECInformation(AECINFORM aec);//通过发生器返回的参数更新AEC数据
  219. AECINFORM m_AECinformation;
  220. //void RetrieveHU();
  221. void CheckGeneratorStatus();
  222. //曝光前的最后有效参数
  223. void ReportRadExposurePostParam();
  224. void ReportFluExposurePostParam();
  225. //
  226. void RetrieveFocalSpot();
  227. void RetrieveTubeID();
  228. //
  229. //void RetrieveFluStopTime();
  230. void SetRadMode(int radmode, int desmode);
  231. //void SetRunMode(int radmode, int desmode);
  232. bool SetRADKV_MA_MS(int kv, float ma, float ms);//设置rad模式的三点模式的KV MA MS
  233. bool SetRADKV_MAS(int kv, float mas);
  234. //
  235. string m_strFKV;
  236. vector<int> m_vecFKV;
  237. string m_strFMA;
  238. vector<float> m_vecFMA;
  239. string m_strFMAS;
  240. vector<float> m_vecFMAS;
  241. void SetFLUKV_MA_MAS(int fkv, float fma, float fmas);//设置flu模式下的曝光参数
  242. void SetTubeDeratingPower();
  243. //
  244. void RetrieveBucky();
  245. void SelectBucky(int bucky);
  246. //
  247. void SetGeneratorOperateStatus(int status);//不知道是啥
  248. void SelectTubeID(int TubeID);//不知道是啥
  249. //void TubeCalibrationCommand();
  250. //void TubeCalibrationDataReport();
  251. //void RestoreFactorySettings();
  252. //void TubeSeasoning();
  253. //void SetFluStopTime();
  254. //
  255. void RetrieveDAPValue();//5801
  256. //void RetrieveDAPRate();//5802
  257. //void ClearDAPValue();//58A1
  258. //void SetAECCalibrationStartAndStop();//F06A
  259. //void SetAECCalibrationDefaultPara();//F06A
  260. //void SetORRetrieveCurrentAECCurve();
  261. //
  262. //
  263. //
  264. //void RetrieveBatteryManuInformation();
  265. void RetrieveBatteryRunningInformation();
  266. void SetAECInformation(int chamber, int field, int density, int film);
  267. void SetAECKV_MA_MS(int kv, float ma, float ms);
  268. //ABS相关
  269. virtual RET_STATUS SetABSMode(int nMode) override; //设置自动亮度调节(ABS)模式
  270. virtual RET_STATUS SetABSCurve(int curveNum) override; //ABS曲线调节
  271. //设置线长短
  272. void SetCableLngth(int lenght);
  273. //Set or retrieve mask function 61A8
  274. //Set or retrieve mask function 61A9
  275. //获取版本号
  276. std::string GetFileVersion(std::string strFilePathName);
  277. static std::string GetDynamicLibraryPath();
  278. string m_strConfigPath{ "" };
  279. };
  280. }
  281. //-----------------------------------------------------------------------------
  282. // DeltaDriver
  283. //-----------------------------------------------------------------------------
  284. namespace CCOS::Dev::Detail::Generator
  285. {
  286. class _CCOSDEVGENDelta_API DeltaDriver : public DriverMould
  287. {
  288. using super = DriverMould;
  289. public:
  290. DeltaDriver ();
  291. virtual ~DeltaDriver ();
  292. public:
  293. //virtual bool DriverEntry (std::string CfgFileName); //设置配制文件路径,对外接口最先调用
  294. virtual void Prepare() override; //在 DriverEntry 之后执行;选择与物理设备通信方式(串口、TCP)
  295. virtual std::string DriverProbe() override; //在 Prepare 之后执行;读取配置文件模块参数,供上层创建驱动work路径
  296. virtual bool DATA_ACTION Connect() override; //在 DriverProbe 之后执行;根据通信方式与物理设备进行连接
  297. virtual auto CreateDevice(int index)->std::unique_ptr <IODevice> override; //在 Connect 之后执行;创建逻辑设备,供上层创建驱动树节点
  298. virtual bool isConnected() const override; //检查驱动与物理设备连接状态
  299. virtual std::string GetResource() override; //获取配置文件的值
  300. virtual std::string DeviceProbe() override; //读取配置文件模块参数,供上层创建设备work路径
  301. virtual void Disconnect() override; //断开驱动与物理设备连接状态
  302. virtual void Dequeue(const char* Packet, DWORD Length); //在super::Connect中轮询,调用 DecodeFrame:查找指令操作对照表,通过对应操作更新数据并调用FireNotify上报更新
  303. virtual void FireNotify(int code, std::string key, std::string content); //向监听者上报事件
  304. static PACKET_RET callbackPackageProcess(const char* RecData, uint32_t nLength, uint32_t& PacketLength); //判断从设备读到的数据有没有可用的数据包,有则最终调度到 Dequeue
  305. std::shared_ptr<SCFWrapper> m_scfWrapper;
  306. private:
  307. bool SaveConfigFile(bool bSendNotify);
  308. virtual bool GetDeviceConfig(std::string& Cfg) override;
  309. virtual bool SetDeviceConfig(std::string Cfg) override;
  310. bool GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue);
  311. bool SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue);
  312. bool m_bDemoMode;
  313. bool m_bDemoConnected; // 在 DEMO 模式下, 是否调用过 Connect
  314. ResDataObject m_DeviceConfig;
  315. ResDataObject m_ConfigAll; //存储当前的配置,用于修改配置时写回文件
  316. ResDataObject m_Configurations; //存储当前配置中“CONFIGURATION”节点的内容
  317. enum class ConnectionState {
  318. Disconnected,
  319. Connecting,
  320. Connected,
  321. Failed
  322. };
  323. enum class ConnectionType {
  324. Serial, // 串口
  325. Ethernet // 网口
  326. };
  327. std::atomic<ConnectionState> m_connectionState{ ConnectionState::Disconnected };
  328. std::chrono::steady_clock::time_point m_lastConnectionAttempt;
  329. std::mutex m_connectionMutex;
  330. const std::chrono::seconds RESET_RETRY_AFTER{ 60 };
  331. // 修改成员变量定义,添加mutable允许const函数修改
  332. mutable int m_connectionRetryCount{ 0 }; // 关键:用mutable修饰
  333. const int MAX_RETRY_COUNT = 3;
  334. const std::chrono::seconds RETRY_INTERVAL{ 5 };
  335. // 串口相关(固定支持的端口,可从配置扩展)
  336. std::vector<std::string> m_serialPorts{ "/dev/ttyUSB0", "/dev/ttyUSB1", "/dev/ttyUSB2", "/dev/ttyUSB3", "/dev/ttyUSB4" };
  337. int m_currentSerialPortIndex{ 0 }; // 当前尝试的串口端口索引
  338. ConnectionType m_currentConnType{ ConnectionType::Serial };
  339. //webconfigʹ��
  340. std::string m_SCFDllName;
  341. ResDataObject m_DeviceConfigSend;
  342. string g_strAppPath;
  343. std::unique_ptr <ResDataObject> m_pAttribute;
  344. std::unique_ptr <ResDataObject> m_pDescription;
  345. DeltaMobileDevice* m_pDevice{ nullptr };
  346. };
  347. }