Detector_HaoBo.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #pragma once
  2. #include <pthread.h>
  3. #include <filesystem>
  4. #include <iostream>
  5. #include <fstream>
  6. #include <cstdint> // 用于uint64_t等类型
  7. #include <unistd.h>
  8. #include "CCOS.Dev.FPD.HaoBo.h"
  9. #include "HaoBoInterface.h"
  10. enum eDetStatus
  11. {
  12. DetStatus_NotIni,
  13. DetStatus_NotConn,
  14. DetStatus_Sleep,
  15. DetStatus_Standby,
  16. DetStatus_Acquire,
  17. DetStatus_OffsetCalibration,
  18. DetStatus_GainCalibration,
  19. };
  20. constexpr auto SCAN_EVENT_COUNT = 5;
  21. constexpr auto OFFSET_EVENT_COUNT = 4;
  22. class Detector_HaoBoRF
  23. {
  24. public:
  25. Detector_HaoBoRF();
  26. ~Detector_HaoBoRF();
  27. bool DriverEntry(void* pDrvDPC, ResDataObject& Configuration, const char* szWorkPath);
  28. bool Connect(void* pDrvDPC);
  29. void DisConnect();
  30. void EnterExamMode(int nExamMode);
  31. bool SetAcqMode(int nMode);
  32. bool SetExposureTimes(int nTimes);
  33. bool PrepareAcquisition(void* pDrvDPC);
  34. bool StartAcquisition(void* pDrvDPC);
  35. bool StopAcquisition(void* pDrvDPC);
  36. bool ActiveCalibration(void* pDrvDPC, CCOS_CALIBRATION_TYPE eType);
  37. bool PrepareCalibration(void* pDrvDPC);
  38. bool StartCalibration(void* pDrvDPC);
  39. bool StopCalibration(void* pDrvDPC);
  40. float SetFluPPS(float fPPS);
  41. void GetFluPPS(float& fFluPPS);
  42. bool RefreshAllOffset();
  43. void OnRefreshOffset();
  44. void AbortFreshOffset();
  45. void SetAbortOffsetEvent();
  46. void SetFreshAllOffsetEvent();
  47. void SetfreshOffsetEvent();
  48. void UpdateModeInRunning(int nMode,float fFrequency);
  49. void PrintDetectorCfg(RegCfgInfo* pCfg);
  50. bool GetPanelInfo();
  51. void* m_nFpdHandle;//SDK初始化后返回的句柄
  52. int m_nMaxImgWidth; //图像原始尺寸
  53. int m_nMaxImgHeight; //图像原始尺寸
  54. int m_nRawImageWidth; //实际出图尺寸
  55. int m_nRawImageHeight; //实际出图尺寸
  56. int m_nImageWidth; //裁剪后的尺寸
  57. int m_nImageHeight; //裁剪后的尺寸
  58. int m_nFrameID;
  59. WORD* m_pRawImgBuffer; //存储未裁剪的图像
  60. WORD* m_pFullImgBuffer; //存储裁剪后的图像
  61. //辅助线程事件
  62. static void* onFPDScanThread(void* pvoid);
  63. pthread_t m_hFPDScanThread;
  64. std::vector<std::shared_ptr<LinuxEvent>> m_hArrayEvent;
  65. std::shared_ptr<LinuxEvent> m_hStopScanEvent; //退出辅助线程事件
  66. std::shared_ptr<LinuxEvent> m_hAcqEvent; //开始Rad采集事件
  67. std::shared_ptr<LinuxEvent> m_hGainEvent; //开始Rad Gain事件
  68. std::shared_ptr<LinuxEvent> m_hDarkEvent; //开始dark校正
  69. std::shared_ptr<LinuxEvent> m_hProcessImgEvent; //处理图像
  70. static void* RefreshOffsetThread(void* pvoid);
  71. pthread_t m_hOffsetThread;
  72. std::vector<std::shared_ptr<LinuxEvent>> m_hOffsetEvent;
  73. std::shared_ptr<LinuxEvent> m_hStopOffsetEvent;
  74. std::shared_ptr<LinuxEvent> m_hStartAllOffset;
  75. std::shared_ptr<LinuxEvent> m_hStartOffset;
  76. std::shared_ptr<LinuxEvent> m_hAbortOffset;
  77. void ConfFeedback(int nEventID, int nDetectorID = -1, const char* pszMsg = "", int nParam1 = 0, float fParam2 = 0, int nPtrParamLen = 0, void* pParam = NULL);
  78. void InfoFeedback(int nEventID, int nDetectorID = -1, int nParam1 = 0, float fParam2 = 0, const char* pszMsg = "", int nPtrParamLen = 0, void* pParam = NULL);
  79. void StatusFeedback(int nEventID, int nParam1 = 0, const char* pszMsg = "", int nDetectorID = -1, float fParam2 = 0, int nPtrParamLen = 0, void* pParam = NULL);
  80. void DataFeedback(int nEventID, void* pParam = NULL, int nParam1 = 0, float fParam2 = 0, const char* pszMsg = "", int nPtrParamLen = 0, int nDetectorID = -1);
  81. void WarnFeedback(int nEventID, const char* pszMsg = "", int nParam1 = 0, float fParam2 = 0, int nPtrParamLen = 0, void* pParam = NULL, int nDetectorID = -1);
  82. void ErrorFeedback(int nEventID, const char* pszMsg = "", int nDetectorID = -1, int nParam1 = 0, float fParam2 = 0, int nPtrParamLen = 0, void* pParam = NULL);
  83. API_HBI_Init HBI_Init;//
  84. API_HBI_Destroy HBI_Destroy;//
  85. API_HBI_ConnectDetector HBI_ConnectDetector;//
  86. API_HBI_DisConnectDetector HBI_DisConnectDetector;//
  87. API_HBI_RegEventCallBackFun HBI_RegEventCallBackFun;//
  88. API_HBI_GetFPDSerialNumber HBI_GetFPDSerialNumber;//
  89. API_HBI_GetSDKVerion HBI_GetSDKVerion;//
  90. API_HBI_GetFirmareVerion HBI_GetFirmareVerion;//
  91. API_HBI_GetError HBI_GetError;//
  92. API_HBI_GetFpdCfgInfo HBI_GetFpdCfgInfo;//
  93. API_HBI_GetImageProperty HBI_GetImageProperty;//
  94. API_HBI_SinglePrepare HBI_SinglePrepare;
  95. API_HBI_SingleAcquisition HBI_SingleAcquisition;
  96. API_HBI_LiveAcquisition HBI_LiveAcquisition;//
  97. API_HBI_StopAcquisition HBI_StopAcquisition;//
  98. API_HBI_SetSelfDumpingTime HBI_SetSelfDumpingTime;//设置采集时间间隔(动态平板)(未使用)
  99. API_HBI_TriggerAndCorrectApplay HBI_TriggerAndCorrectApplay;//设置触发模式和图像校正使能(工作站)新版本(未使用)
  100. API_HBI_UpdateTriggerMode HBI_UpdateTriggerMode;
  101. API_HBI_UpdateCorrectEnable HBI_UpdateCorrectEnable;//更新图像固件校正使能 (未使用)
  102. API_HBI_SetBinning HBI_SetBinning;
  103. API_HBI_GenerateTemplate HBI_GenerateTemplate;//快速生成校正模板,可用于刷暗场
  104. API_HBI_TriggerBinningAcqTime HBI_TriggerBinningAcqTime;//设置触发模式、binning方式以及帧率(采集图像时间间隔)
  105. API_HBI_IsMutilMode HBI_IsMutilMode;//是否支持多mode
  106. API_HBI_RegProgressCallBack HBI_RegProgressCallBack;
  107. API_HBI_WaitForReadyStatus HBI_WaitForReadyStatus;
  108. API_HBI_SetPGALevel HBI_SetPGALevel;
  109. private:
  110. map<void*, int>* m_pDPC2PanelID;
  111. map<int, void*>* m_pPanelID2DPC;
  112. int m_nPanelCount; //探测器数量
  113. ResDataObject m_ModeConfig; //保存DPC模块下发的配置
  114. std::string m_strCtrlWorkPath; //保存工作路径,用于加载SDK和配置
  115. int m_nCurrentPanelID; //模块中探测器的ID
  116. bool m_bConnected; //true: 探测器连接成功
  117. int m_nCurrentLogicMode; //当前选中的LogicMode
  118. int m_nModeID;//自定义探测器采集模式ID
  119. int m_nGainLevel;//亮场增益值
  120. //CF时发送图片的帧率(以秒为单位,例 60/s)PF设置帧率后,由于探测器开窗信号是由外部触发的,故帧率由外部信号决定(当外部触发信号频率大于最大帧率时,由最大帧率决定)
  121. float m_fFrameRate; //采集帧率
  122. int m_nTriggerMode; //触发模式
  123. int m_nSaveRaw;
  124. CCOS_CALIBRATION_TYPE m_eCaliType; // 记录当前校正模式
  125. eDetStatus m_eStatus; // 探测器状态
  126. int m_nCropLeft;//左侧裁剪
  127. int m_nCropRight;//右侧裁剪
  128. int m_nCropTop;//上边裁剪
  129. int m_nCropBottom;//下边裁剪
  130. int m_nExiThreshold;//探测器上传的图像的阈值,只有大于这个阈值才认为是有射线照射后的图
  131. int m_nImageBits;
  132. int m_nDropImgNum; //曝光已经丢图张数
  133. int m_nDropImgCount; //曝光总丢图张数
  134. int m_nExamMode; //记录当前的工作界面
  135. unsigned long long m_dwBeginTime;
  136. unsigned long long m_dwEndTime;
  137. int m_nDelayTime; //从收到曝光信号到取图的延时时间
  138. bool m_bValidImage; //是否已经发送合适的点片图像
  139. bool m_bFirstImage;//是否是开始采集后探测器推的第一张图
  140. void* m_hSDKModule; //加载SDK动态库的句柄
  141. bool m_bLoaded;//SDK库文件是否加载
  142. int nPGALevel;
  143. int nBinning;
  144. int nPrepareTime;
  145. COMM_CFG commCfg;
  146. int nLiveAcqTime;//透视时的采集间隔,可以通过设置采集间隔控制上图时的帧率
  147. bool LoadDll(string strWorkPath);
  148. bool ConnectDetector();
  149. bool TestError(int nErrorCode, const char* szFuncName = "Func");
  150. void OnProcessImage(int nWidth, int nHeight, int nFrameID = -1);
  151. bool StartDarkCalibration();
  152. bool StartGainCalibration();
  153. void OnAcquireImage();
  154. void OnAcquireGainImage();
  155. void OnStartDarkCalibration();
  156. eDetStatus GetDpcStatus();
  157. bool SetDpcStatus(eDetStatus status);
  158. bool LoadCalibrationFiles();
  159. int CropImageMargin(void* pDstData, int& nDstWidth, int& nDstHeight,
  160. void* pScrData, int nSrcWidth, int nSrcHeight, int nBits,
  161. int nLeftMargin, int nTopMargin, int nRightMargin, int nBottomMargin);
  162. std::string saveProcessedImage(void* data, size_t size, const std::string& baseTimestamp);
  163. void cleanOldFiles(const std::string& dirPath, const std::string& filePrefix, size_t maxCount, bool checkSize);
  164. bool CheckTimeLimit(unsigned long long dwBeginTime, unsigned long long dwEndTime);
  165. bool CalculateEXI(WORD* pImgData, int nImgWidth, int nImgHeight, int nImageBit, int nThreshold);
  166. bool CheckImageExi(WORD* pImgData, int nImgWidth, int nImgHeight, WORD dwExiThrethold);
  167. void SaveImage(int nIndex,bool bImageCrop);
  168. int GetPGA(unsigned short usValue);
  169. };