IRayCtrl.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. #pragma once
  2. #include <map>
  3. //转存文件内容使用
  4. #include <shellapi.h>
  5. #include "CcosLock.h"
  6. #include "ResDataObject.h"
  7. #include "IRayDefinition.h"
  8. #include "CCOS.Dev.FPD.iRay.h"
  9. #include "ZSKKCalibration.h"
  10. //SDK头文件
  11. #include "IRaySDK/include/IRayFpdSys.h"
  12. #include "IRaySDK/include/IRayFpdSysEx.h"
  13. #include "IRaySDK/include/IRayCmdDef.h"
  14. #define IRAY_SCAN_NUM 5
  15. namespace nsDPC = CCOS::Dev::Detail::Detector;
  16. namespace CCOS::Dev::Detail::Detector
  17. {
  18. class IRayCtrl : public CcosLock
  19. {
  20. class _AutoLocker
  21. {
  22. CcosLock* m_lockObj;
  23. public:
  24. _AutoLocker(CcosLock *lockObj,DWORD timeout = INFINITE)
  25. :m_lockObj(lockObj)
  26. {
  27. m_lockObj->Thread_Lock(timeout);
  28. }
  29. ~_AutoLocker()
  30. {
  31. if (m_lockObj)
  32. {
  33. m_lockObj->Thread_UnLock();
  34. }
  35. }
  36. };
  37. public:
  38. IRayCtrl();
  39. ~IRayCtrl();
  40. bool Init(string strAppPath);
  41. void ProcessEvent(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, int nParam2, int nPtrParamLen, void* pParam);
  42. bool ScanResult(DetectorProfile* pDetectorProfile);
  43. bool AddDPCs(nsDPC::FPDDeviceIRay* pDrvDPC, ResDataObject& Configuration, DeviceIndexStruct& DeviceStruct );
  44. bool DelDPCs(nsDPC::FPDDeviceIRay* pDrvDPC);
  45. bool ActivePanel(nsDPC::FPDDeviceIRay* pDrvDPC, bool bActive);
  46. bool SwithPanel(int nPanelId);
  47. bool EnterExam(APP_STATUS eStatus);
  48. bool Connect(string strAppPath, nsDPC::FPDDeviceIRay* pDrvDPC);
  49. bool DisConnect(nsDPC::FPDDeviceIRay* pDrvDPC);
  50. bool ResetFPD(nsDPC::FPDDeviceIRay* pDrvDPC);
  51. RET_STATUS SetSyncMode(SYNC_MODE nSyncMode, HARDWARE_TRIGGER_MODE TriggerMode);
  52. bool SelectExamMode(int nLogicMode, nsDPC::FPDDeviceIRay* pDrvDPC);
  53. RET_STATUS PrepareAcquisition(nsDPC::FPDDeviceIRay* pDrvDPC);
  54. RET_STATUS StartAcquisition(nsDPC::FPDDeviceIRay* pDrvDPC);
  55. RET_STATUS StopAcquisition(nsDPC::FPDDeviceIRay* pDrvDPC);
  56. bool InitCalibration();
  57. bool GetiRayPanelCalibItem();
  58. RET_STATUS ActiveCalibration(CCOS_CALIBRATION_TYPE Type, nsDPC::FPDDeviceIRay* pDrvDPC);
  59. RET_STATUS PrepareCalibration(nsDPC::FPDDeviceIRay* pDrvDPC);
  60. RET_STATUS StartCalibration(nsDPC::FPDDeviceIRay* pDrvDPC);
  61. RET_STATUS CompleteCalibration(nsDPC::FPDDeviceIRay* pDrvDPC);
  62. RET_STATUS AbortCalibration(nsDPC::FPDDeviceIRay* pDrvDPC);
  63. RET_STATUS OnUpdateFirmware(nsDPC::FPDDeviceIRay* pDrvDPC);
  64. bool ConfirmCalibration();
  65. bool AcceptCalibration();
  66. bool RejectCalibration();
  67. bool CreateCalibrationFile();
  68. void OnEndCalibraion();
  69. bool GetCalibrationStep(int nCalibCurrentCalibrationRound, int nCalibrationRounds, int nCalibCurrentExposureIndex, int nExposureNumCurrentRound);
  70. bool SaveCalibrationFile();
  71. bool SetReferenceNum(int nReferenceNum);
  72. bool UploadCalibrationFiles(nsDPC::FPDDeviceIRay* pDrvDPC, string strFileName);
  73. bool SetLTEMode(bool bEnable);
  74. bool RecoverLastImage();
  75. bool RecoverLastImageAuto();
  76. bool SaveFailedCalibFiles(int nDetectorID, bool bExpMode);
  77. bool CopyFile2Folder(string strSrcPath, string strDstPath);
  78. bool WriteCumstomFile(int nDetectorID);
  79. bool CancelImageRecover();
  80. bool ActiveSyncMode(nsDPC::FPDDeviceIRay* pDrvDPC, int nSyncMode);
  81. bool CancelOperation();
  82. public:
  83. //WORD *m_pImageBuffer; //SDK所需的一个大的图像buffer
  84. ResDataObject m_ModeConfig;
  85. bool m_bCalibResultFailed;
  86. string m_strWorkPath; //工作路径
  87. APP_STATUS m_eAppStatus; //记录当前软件的工作状态(界面)
  88. int m_nCurrentMode; //记录探测器当前application mode
  89. int m_nImageWidth;
  90. int m_nImageHeight;
  91. int m_nHeightOffset;
  92. int m_nBottomOffset;
  93. int m_nWidthOffset;
  94. int m_nRightOffset;
  95. int m_nRawImgWidth; //图像原始宽
  96. int m_nRawImgHeight; //图像原始高
  97. int m_nImgBits;
  98. int m_nPixelPitch;
  99. bool m_bPreviewEnable;
  100. float m_fFactorEXI2UGY; //探测器EXI -> UGY 转换系数
  101. int m_nPreviewWidth;
  102. int m_nPreviewHeight;
  103. CCOS_CALIBRATION_TYPE m_eCaliType; // 记录当前校正模式
  104. float m_fCurrentDose; // 记录当前的Dose要求
  105. int m_nCaliFailedCount; //记录增益校正失败次数,超过一定次数自动停止校正
  106. bool m_bGainPreparing; //true: 正在进入增益校正状态
  107. bool m_bGainProcess; //true: 处于增益曝光的一次小循环当中(WindowOn ~ SDK返回当前曝光结果)
  108. bool m_bConfirmCaliRst; //true: 接受当前增益校正曝光结果
  109. int m_nSaveRaw; //0:不存; 1:预览图; 2:raw图; 4:实际尺寸图像;
  110. //int m_nGainNodeCount; //校正曝光的总节点个数
  111. //int m_nGainNodeIndex; //校正曝光的节点Index
  112. //int m_nGainExpCount; //校正曝光节点需要曝光的次数
  113. //int m_nGainExpIndex; //校正曝光节点已曝光的次数
  114. bool m_bUpdateFirmwareDirect; //true: 直接升级固件
  115. int m_nUpdateFPDID; //记录要固件升级的探测器ID
  116. bool m_bIsImageRecovering; //是否处于图像恢复流程
  117. int m_nStatusPeriod; //状态间隔
  118. private:
  119. bool LoadIRayDLL(string strWorkPath);
  120. void FreeIRayDLL();
  121. FPDRESULT IrayFnInvoke(int nDetectorID, int nCommandID, IRayCmdParam pars[], int nParCount);
  122. void StartInitFPDThread();
  123. static DWORD _stdcall onInitPanel(void* pParam); //初始化线程
  124. void Action_Init();
  125. bool DetectorInitProcess(int nPanelIndex, bool bFDAttach = false);
  126. bool RetryConnect(int nPanelIndex);
  127. bool OnInitStatus(int nPanelIndex, ENUM_PANEL_EVENT_STATE ePanelState);
  128. void iRayScanEventThread(); //辅助子线程
  129. static DWORD __stdcall onScanEvent(void* pParam); //初始化线程
  130. static DWORD __stdcall onUpdateFWThread(PVOID pvoid);
  131. void ConfFeedback(int nEventID, int nDetectorID = -1, const char* pszMsg = "", int nParam1 = 0, float fParam2 = 0, int nPtrParamLen = 0, void* pParam = NULL);
  132. void InfoFeedback(int nEventID, int nDetectorID = -1, int nParam1 = 0, float fParam2 = 0, const char* pszMsg = "", int nPtrParamLen = 0, void* pParam = NULL);
  133. void StatusFeedback(int nEventID, int nParam1 = 0, const char* pszMsg = "", int nDetectorID = -1, float fParam2 = 0, int nPtrParamLen = 0, void* pParam = NULL);
  134. void DataFeedback(int nEventID, void* pParam = NULL, int nParam1 = 0, float fParam2 = 0, const char* pszMsg = "", int nPtrParamLen = 0, int nDetectorID = -1);
  135. void WarnFeedback(int nEventID, const char* pszMsg = "", int nParam1 = 0, float fParam2 = 0, int nPtrParamLen = 0, void* pParam = NULL, int nDetectorID = -1);
  136. void ErrorFeedback(int nEventID, const char* pszMsg = "", int nDetectorID = -1, int nParam1 = 0, float fParam2 = 0, int nPtrParamLen = 0, void* pParam = NULL);
  137. void OnProcessTaskResult(int nDetectorID, int nParam1, int nParam2, bool bResult);
  138. void OnProcessTaskResult2(int nDetectorID, int nParam1, int nParam2, bool bResult); //用此函数单独处理task_start & tast_canceled
  139. bool ClearCorrection(int nPanelIndex);
  140. bool SetMarsCorrection(int nPanelIndex);
  141. bool SetDetectorCorrection(int nDetectorID, int nCorrectionType);
  142. bool SetPrepCapMode(int nDetectorID, int nPrepCapMode);
  143. bool SetSelfCapEnable(int nDetectorID, int nSelfCapEnable);
  144. bool SetSelfClearEnable(int nDetectorID, int nSelfClearEnable);
  145. bool SetDynaOffsetGapTime(int nDetectorID, int nDynaOffsetGapTime);
  146. bool SetInnerSubFlowAttr(int nDetectorID, int nInnerSubFlow);
  147. bool SetXWindowDelay(int nDetectorID, int nXWidnowTime);
  148. bool GetExpWindowTime(int nDetectorID, int& nExpWindowTime);
  149. bool SetExpWindowTime(int nDetectorID, int nExpWindow);
  150. bool GetDetectorStatus(int nDetectorID, int& state);
  151. bool GetAttr(int nDetectorID, int nAttrID, int& nValue);
  152. bool GetAttr(int nDetectorID, int nAttrID, float& fValue);
  153. bool GetAttr(int nDetectorID, int nAttrID, char* pszAttr);
  154. bool SetAttr(int nDetectorID, int nAttrID, int nValue);
  155. bool TestError(int nDetectorID, int nErrorStatus, bool bPopUp = true);
  156. bool ReadBatteryStatus(int nPanelIndex);
  157. bool CheckBattery(int nPanelIndex, bool bLog = true);
  158. bool GetBatterySN(int nDetectorID, char* inoutSN);
  159. bool GetBatteryExist(int nDetectorID, int& nExist);
  160. bool GetBatteryRemaining(int nDetectorID, int& nRemaining);
  161. bool GetBatteryChargingStatus(int nDetectorID, int& nStatus);
  162. bool GetFPDTempT1(int nDetectorID, float& fTempT1);
  163. bool GetHallSensor(int nDetectorID, int& nPosition);
  164. bool GetLifeTime(int nDetectorID, int& nLifeTime);
  165. bool GetPowerOnCount(int nDetectorID, int& nPowerOnCount);
  166. bool GetCorrectionOption(int nDetectorID, int& nOption);
  167. bool GetFWUpdateProgress(int nDetectorID, int& nOption);
  168. bool ReadWifiStatus(int nPanelIndex);
  169. bool CheckWiFi(int nPanelIndex, bool bLog = true);
  170. bool CheckTemperature(int nPanelIndex);
  171. bool ReadTempStatus(int nPanelIndex);
  172. bool ReadLivingTime(int nDetectorID);
  173. bool CheckLivingTime(int nDetectorID);
  174. bool GetProductNo(int nDetectorID, int&);
  175. bool GetSrcIP(int nDetectorID, char* pszUROM_SrcIP);
  176. bool GetSerialNo(int nDetectorID, char* pszUROM_SerialNo);
  177. bool GetMainVersion(int nDetectorID, char* pszMainVersion);
  178. bool GetReadVersion(int nDetectorID, char* pszReadVersion);
  179. bool GetMcuVersion(int nDetectorID, char* pszMcuVersion);
  180. bool GetArmVersion(int nDetectorID, char* pszArmVersion);
  181. bool GetSyncMode(int nDetectorID, int& nTriggerMode);
  182. bool GetKernelVersion(int nDetectorID, char* pszKernelVersion);
  183. bool GetDelayTime(int nDetectorID, int& nDelayTime);
  184. bool SetDelayTime(int nDetectorID, int nDelayTime);
  185. bool SetAppMode(int nDetectorID);
  186. bool SetCorrectFile();
  187. bool GetCorrectFileIndex(int& nGainMapIndex, int& nDefectMapIndex);
  188. bool GetWifiLinkQuality(int nDetectorID, int& nQuality);
  189. bool GetROMInfo(int nPanelIndex);
  190. bool GetXWindowDelay(int nDetectorID, int& nXWidnowTime);
  191. bool GetPrepCapMode(int nDetectorID, int& nPrepCapMode);
  192. bool GetConnState(int nDetectorID, int& nConnState);
  193. bool GetSelfCapEnable(int nDetectorID, int& nSelfCapEnable);
  194. bool GetSelfClearEnable(int nDetectorID, int& nSelfClearEnable);
  195. bool GetDynaOffsetGapTime(int nDetectorID, int& nDynOffsetGapTime);
  196. bool GetInnerSubFlow(int nDetectorID, int& nInnerSubFlow);
  197. bool WriteRom(int nDetectorID);
  198. int SetSyncMode(int nPanelIndex, int nSetSyncMode);
  199. int SetInnerSubFlow(int nDetectorID, int nInnerSubFlow);
  200. int SetCapModeFunc(int nDetectorID, int nSetCapMode);
  201. int SetFPDCalParam(int nDetectorID, int nSetSelfCapEnable, int nSetSelfClearEnable);
  202. bool SyncTimePC2FD(int nDetectorID);
  203. bool SetDetectorWorkMode(int nDetectorID, string strFPDType, int nTriggerMode);
  204. bool SetDetectorXWindow(int nDetectorID, int nDelayTime, int nXWindowTime, int nClearAcqTime);
  205. bool OffsetProcess();
  206. bool WaitRespond(int nTimeOut);
  207. void SendNotify();
  208. void ResetLock();
  209. void Pausetime(DWORD dwSpan);
  210. bool WaitReady(int nPanelIndex, int nMs);
  211. bool StartXWindowOffThread();
  212. static DWORD XWindowOffThread(LPVOID pParam);
  213. void DisconnectFD(int nDetectorID);
  214. bool IsFWNeedUpdate(int nDetectorID);
  215. bool UpdateFirmware(int nPanelIndex, bool bUpdate);
  216. bool UploadCalibFileFromFD(int nDetectorID, int nIndex, string strFileName, bool bGain);
  217. bool DownloadCalibrationFileToFD(bool bGainFile, bool bExpMode);
  218. bool DownloadUserDefectFileToFD(bool bLTE);
  219. bool ReadCumstomFile(int nDetectorID);
  220. bool DownloadfromDetector(int nDetectorID);
  221. bool BackupCalibFiles(int nDetectorID, bool bDownload, bool bExpMode);
  222. bool DeleteOneFolder(string strSourceFolder);
  223. bool CleanCalibFiles(int nDetectorID, bool bExpMode);
  224. bool CleanCalibReport(int nDetectorID, bool bExpMode);
  225. bool RestoreSensitivity(int nDetectorID);
  226. bool RestoreCalibReport(int nDetectorID, bool bExpMode);
  227. bool CheckLastImageStatus(int nDetectorID);
  228. bool RecoverImage();
  229. bool OnEXIT();
  230. void DeleteHandle();
  231. bool GetCalibrationTime(int nDetectorID, bool bExpMode);
  232. void GetFwName(string strFirmPath, string& strFirmwareName);
  233. bool FlipX(WORD* pData, int nWidth, int nHeight);
  234. bool FlipXRotate90(WORD* pData, int nWidth, int nHeight);
  235. bool IsConnected(string strIP);
  236. void OnProcessPreImg();
  237. void OnProcessImg();
  238. bool GetEffectiveImage(WORD* pOutImg, WORD* pInImg, int nInWidth);
  239. HANDLE m_pHardwareStatusThread;
  240. HANDLE m_hEndHWStatusThreadEvent;
  241. HANDLE m_hHWStatusThreadEndEvent;
  242. bool StartHardwareStatusThread();
  243. static DWORD HardwareStatusThread(LPVOID pParam);
  244. bool GetHardwareStatus();
  245. bool GetConnectionStatus(int nDetectorID);
  246. int ParseDefectFile(int nPanelIndex, bool bExpMode, bool bManual = false);
  247. bool CloseDefectTemplateFile(void* pHandler);
  248. bool SaveRawImage(const char* pImgName, const WORD* pRawImg, int nWidth, int nHeight);
  249. private:
  250. //句柄
  251. HMODULE m_hIRayModule;
  252. FnCreate m_fpCreate;
  253. FnDestroy m_fpDestroy;
  254. FnGetAttr m_fpGetAttr;
  255. FnSetAttr m_fpSetAttr;
  256. FnInvoke m_fpInvoke;
  257. FnRegisterScanNotify m_pRegisterScanNotify;
  258. FnScanOnce m_pScanOnce;
  259. FnGetErrInfo m_pFnGetErrorInfo;
  260. FnAbort m_pfAbort;
  261. FnOpenDefectTemplateFile m_pfOpenDefectTemplateFile;
  262. FnCloseDefectTemplateFile m_pfCloseDefectTemplateFile;
  263. HANDLE m_hArrayEvent[IRAY_SCAN_NUM];
  264. HANDLE m_hExitEvent;
  265. HANDLE m_hRecoverImage;
  266. HANDLE m_hOffsetEvent;
  267. HANDLE m_hCofirmCalib;
  268. HANDLE m_hEndCalibEvent;
  269. HANDLE m_hIRayScanEnd;
  270. HANDLE m_hSharedEvent; //等待SDK回调句柄
  271. HANDLE m_hWindowOffEvent;
  272. HANDLE m_pXWindowoffThread;
  273. HANDLE m_hScanEventThread;
  274. HANDLE m_hInitThread;
  275. string g_strAppPath;
  276. int m_nPanelCount;
  277. int m_nDetectorID; //SDK探测器ID(1,2,3)
  278. int m_nDetectorIndex; //当前激活探测器的index(0,1,2)
  279. void* m_pCurrentDPC;
  280. map<FPDDeviceIRay*, int>* m_pDPC2PanelID;
  281. map<int, FPDDeviceIRay*>* m_pPanelID2DPC;
  282. DeviceIndexStruct m_stDeviceIndex[3]; //配置的探测器列表//不超过三块板
  283. ResDataObject m_ObjFPDsInfo[3]; //存储探测器数量和类型
  284. WORD* m_pImgBuffer;
  285. WORD* m_pwRawImageData; //原始图像内存
  286. WORD* m_pwPreviewImg; //preview内存
  287. int m_nCmdConnectResult;
  288. ENUM_PANEL_STATUS m_ePanelStatus; //探测器的状态 PARPARE READY WINDOWON OFF
  289. DeviceErrorInfor m_WarnRes; //warn配置文件列表
  290. DeviceErrorInfor m_ErrRes; //error配置文件列表
  291. DeviceErrorList m_ErrList; //当前错误列表
  292. DeviceErrorList m_ErrListTemp; //初始化时未发送到UI的ERROR
  293. DeviceErrorList m_WarnList; //当前错误列表
  294. bool m_bInitialing; //是否在初始化过程中
  295. bool m_bBatteryCharging; //电池充电与否的状态
  296. bool m_bRecoveringImage;//是否在恢复图像的流程中;若是,屏蔽其他错误,以防止干扰恢复图像的界面流程
  297. bool m_bAbortRecover; //放弃恢复图像(状态),恢复图像过程中中止,恢复图像失败的提示不再往上发送;目前不起作用
  298. bool m_bSetCorrectFile;
  299. bool m_bForceGridSuppress;
  300. bool m_bInCalibrating;
  301. bool m_bInExposure;
  302. bool m_bDetectorReady;
  303. bool m_bFDAttaching;
  304. bool m_bModuleConnecting;
  305. bool m_bFirmwareUpdating;
  306. string m_strCalibTime;
  307. int m_nDoseParam;// 校正用的曝光计量,发送到UI 且本地记录
  308. int m_nRequireTimer; //查询WIFI电量的周期,Patient界面 10分钟检查一次
  309. int m_nRecoverImageTimes; // 恢复图像失败的次数,每2次提示用户一次
  310. int m_nCalibDueSetting; // 校正文件的保质期天数
  311. int m_nOldDay; //校正日期定期检查的上次时间(某一天)
  312. int m_nCalibStatus;
  313. int m_nSID; //SID值
  314. int m_nBatteryCapacity;
  315. int m_nBatteryCharges;
  316. int m_nGridLicense;
  317. float m_fCalibTemperature1;
  318. float m_fCalibTemperature2;
  319. float m_fCalibTemperature;
  320. float m_fBatteryTemperature;
  321. float m_fTemperatureMin;
  322. float m_fTemperatureMax;
  323. float m_fGradientMean;
  324. float m_fGradientStdDev;
  325. bool m_bImageRecoverBeCanceled;
  326. //iRay校正相关变量
  327. list<RefrenceCal> m_listCalibItem;
  328. list<RefrenceCal>::iterator m_iterCalibDose;
  329. int m_nDefectExpTimes;
  330. int m_nDefectTotalTimes;
  331. int m_nGainExpTimes;
  332. int m_nGainTotalFrames;
  333. int m_nDefectTotalFrames;
  334. int m_nLastExpFDIndex;
  335. //ZSKK校正
  336. CCOS_CALIBRATION_MODE m_nCalibrationMode;
  337. CZSKKCalibrationCtrl* m_pZSKKCalib;
  338. int m_nCalibCurrentCalibrationRound;
  339. int m_nCalibrationRounds;
  340. int m_nCalibCurrentExposureIndex;
  341. int m_nExposureNumCurrentRound;
  342. bool m_bSaveCalibrationRaw;
  343. };
  344. }