#pragma once #include //转存文件内容使用 #include #include "ResDataObject.h" #include "IRayDefinition.h" #include "CCOS.Dev.FPD.iRay.h" //SDK头文件 #include "IRaySDK/include/IRayFpdSys.h" #include "IRaySDK/include/IRayFpdSysEx.h" #include "IRaySDK/include/IRayCmdDef.h" #define IRAY_SCAN_NUM 5 namespace nsDPC = CCOS::Dev::Detail::Detector; namespace CCOS::Dev::Detail::Detector { class IRayCtrl { public: IRayCtrl(); ~IRayCtrl(); bool Init(string strAppPath); void ProcessEvent(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, int nParam2, int nPtrParamLen, void* pParam); bool AddDPCs(nsDPC::FPDDeviceIRay* pDrvDPC, ResDataObject& Configuration, DeviceIndexStruct& DeviceStruct ); bool DelDPCs(nsDPC::FPDDeviceIRay* pDrvDPC); bool ActivePanel(nsDPC::FPDDeviceIRay* pDrvDPC, bool bActive); bool SwithPanel(int nPanelId); bool EnterExam(APP_STATUS eStatus); bool Connect(string strAppPath, nsDPC::FPDDeviceIRay* pDrvDPC); bool DisConnect(nsDPC::FPDDeviceIRay* pDrvDPC); bool ResetFPD(nsDPC::FPDDeviceIRay* pDrvDPC); RET_STATUS SetSyncMode(SYNC_MODE nSyncMode, HARDWARE_TRIGGER_MODE TriggerMode); bool SetAcqMode(nsDPC::FPDDeviceIRay* pDrvDPC, int nLogicMode, DetModeInfo& AcqModeInfo); RET_STATUS PrepareAcquisition(nsDPC::FPDDeviceIRay* pDrvDPC); RET_STATUS StartAcquisition(nsDPC::FPDDeviceIRay* pDrvDPC); RET_STATUS StopAcquisition(nsDPC::FPDDeviceIRay* pDrvDPC); bool InitCalibration(); bool GetiRayPanelCalibItem(); RET_STATUS ActiveCalibration(CCOS_CALIBRATION_TYPE Type, nsDPC::FPDDeviceIRay* pDrvDPC); RET_STATUS PrepareCalibration(nsDPC::FPDDeviceIRay* pDrvDPC); RET_STATUS StartCalibration(nsDPC::FPDDeviceIRay* pDrvDPC); RET_STATUS CompleteCalibration(nsDPC::FPDDeviceIRay* pDrvDPC); RET_STATUS AbortCalibration(nsDPC::FPDDeviceIRay* pDrvDPC); RET_STATUS OnUpdateFirmware(nsDPC::FPDDeviceIRay* pDrvDPC); bool ConfirmCalibration(); bool AcceptCalibration(); bool RejectCalibration(); bool CreateCalibrationFile(); void OnEndCalibraion(); bool UploadCalibrationFiles(nsDPC::FPDDeviceIRay* pDrvDPC, string strFileName); bool RecoverLastImage(); bool RecoverLastImageAuto(); bool SaveFailedCalibFiles(int nDetectorID, bool bExpMode); bool CopyFile2Folder(string strSrcPath, string strDstPath); bool WriteCumstomFile(int nDetectorID); bool CancelImageRecover(); bool SetFluPPS(float fFluPPS); bool GetFluPPS(float& fFluPPS); bool StartOffset(bool isAll); bool AbortOffset(); public: bool m_bCalibResultFailed; string m_strWorkPath; //工作路径 APP_STATUS m_eAppStatus; //记录当前软件的工作状态(界面) int m_nCurrentMode; //记录探测器当前application mode string m_strCurrentExamType; int m_nImageWidth; int m_nImageHeight; int m_nHeightOffset; int m_nBottomOffset; int m_nWidthOffset; int m_nRightOffset; int m_nRawImgWidth; //图像原始宽 int m_nRawImgHeight; //图像原始高 int m_nImgBits; int m_nPixelPitch; bool m_bPreviewEnable; float m_fFactorEXI2UGY; //探测器EXI -> UGY 转换系数 int m_nPreviewWidth; int m_nPreviewHeight; CCOS_CALIBRATION_TYPE m_eCaliType; // 记录当前校正模式 float m_fCurrentDose; // 记录当前的Dose要求 int m_nCaliFailedCount; //记录增益校正失败次数,超过一定次数自动停止校正 bool m_bGainPreparing; //true: 正在进入增益校正状态 bool m_bGainProcess; //true: 处于增益曝光的一次小循环当中(WindowOn ~ SDK返回当前曝光结果) bool m_bConfirmCaliRst; //true: 接受当前增益校正曝光结果 bool m_bSaveRaw; //false:不存; true:存原图; bool m_bPreviewImg; //false:不要预览图; true:要预览图 //int m_nGainNodeCount; //校正曝光的总节点个数 //int m_nGainNodeIndex; //校正曝光的节点Index //int m_nGainExpCount; //校正曝光节点需要曝光的次数 //int m_nGainExpIndex; //校正曝光节点已曝光的次数 int m_nUpdateFPDID; //记录要固件升级的探测器ID bool m_bIsImageRecovering; //是否处于图像恢复流程 bool m_bGrabStatus; //采集状态 int m_nFrameID; //动态图一次采集的ID int m_nExiThreshold; //EXI检测阈值 private: bool LoadIRayDLL(string strWorkPath); void FreeIRayDLL(); FPDRESULT IrayFnInvoke(int nDetectorID, int nCommandID, IRayCmdParam pars[], int nParCount); void StartInitFPDThread(); static DWORD _stdcall onInitPanel(void* pParam); //初始化线程 void Action_Init(); bool DetectorInitProcess(int nPanelIndex, bool bFetchCalibration = false); bool RetryConnect(int nPanelIndex); bool OnInitStatus(int nPanelIndex, ENUM_PANEL_EVENT_STATE ePanelState); void ScanAddHandle(); void iRayScanEventThread(); //监控线程 static DWORD __stdcall onScanEvent(void* pParam); //初始化线程 static DWORD __stdcall onUpdateFWThread(PVOID pvoid); void ConfFeedback(int nEventID, int nDetectorID = -1, const char* pszMsg = "", int nParam1 = 0, float fParam2 = 0, int nPtrParamLen = 0, void* pParam = NULL); void InfoFeedback(int nEventID, int nDetectorID = -1, int nParam1 = 0, float fParam2 = 0, const char* pszMsg = "", int nPtrParamLen = 0, void* pParam = NULL); void StatusFeedback(int nEventID, int nParam1 = 0, const char* pszMsg = "", int nDetectorID = -1, float fParam2 = 0, int nPtrParamLen = 0, void* pParam = NULL); void DataFeedback(int nEventID, void* pParam = NULL, int nParam1 = 0, float fParam2 = 0, const char* pszMsg = "", int nPtrParamLen = 0, int nDetectorID = -1); void WarnFeedback(int nEventID, const char* pszMsg = "", int nParam1 = 0, float fParam2 = 0, int nPtrParamLen = 0, void* pParam = NULL, int nDetectorID = -1); void ErrorFeedback(int nEventID, const char* pszMsg = "", int nDetectorID = -1, int nParam1 = 0, float fParam2 = 0, int nPtrParamLen = 0, void* pParam = NULL); void OnProcessTaskResult(int nDetectorID, int nParam1, int nParam2, bool bResult); void OnProcessTaskResult2(int nDetectorID, int nParam1, int nParam2, bool bResult); //用此函数单独处理task_start & tast_canceled bool ClearCorrection(int nPanelIndex); bool SetPrepCapMode(int nDetectorID, int nPrepCapMode); bool SetSelfCapEnable(int nDetectorID, int nSelfCapEnable); bool SetSelfClearEnable(int nDetectorID, int nSelfClearEnable); bool SetDynaOffsetGapTime(int nDetectorID, int nDynaOffsetGapTime); bool SetInnerSubFlowAttr(int nDetectorID, int nInnerSubFlow); bool SetXWindowDelay(int nDetectorID, int nXWidnowTime); bool GetExpWindowTime(int nDetectorID, int& nExpWindowTime); bool SetExpWindowTime(int nDetectorID, int nExpWindow); bool GetDetectorStatus(int nDetectorID, int& state); bool GetAttr(int nDetectorID, int nAttrID, int& nValue); bool GetAttr(int nDetectorID, int nAttrID, float& fValue); bool GetAttr(int nDetectorID, int nAttrID, char* pszAttr); bool SetAttr(int nDetectorID, int nAttrID, int nValue); bool TestError(int nDetectorID, int nErrorStatus, bool bPopUp = true); bool ReadBatteryStatus(int nPanelIndex); bool CheckBattery(int nPanelIndex); bool GetBatterySN(int nDetectorID, char* inoutSN); bool GetBatteryExist(int nDetectorID, int& nExist); bool GetBatteryRemaining(int nDetectorID, int& nRemaining); bool GetBatteryChargingStatus(int nDetectorID, int& nStatus); bool GetFPDTempT1(int nDetectorID, float& fTempT1); bool GetFPDTempT2(int nDetectorID, float& fTempT2); bool GetHallSensor(int nDetectorID, int& nPosition); bool GetLifeTime(int nDetectorID, int& nLifeTime); bool GetPowerOnCount(int nDetectorID, int& nPowerOnCount); bool GetCorrectionOption(int nDetectorID, int& nOption); bool GetFWUpdateProgress(int nDetectorID, int& nOption); bool ReadWifiStatus(int nPanelIndex); bool CheckWiFi(int nPanelIndex); bool CheckTemperature(int nPanelIndex); bool ReadTempStatus(int nPanelIndex); bool ReadLivingTime(int nDetectorID); bool CheckLivingTime(int nDetectorID); bool GetProductNo(int nDetectorID, int&); bool GetSrcIP(int nDetectorID, char* pszUROM_SrcIP); bool GetSerialNo(int nDetectorID, char* pszUROM_SerialNo); bool GetMainVersion(int nDetectorID, char* pszMainVersion); bool GetReadVersion(int nDetectorID, char* pszReadVersion); bool GetMcuVersion(int nDetectorID, char* pszMcuVersion); bool GetArmVersion(int nDetectorID, char* pszArmVersion); bool GetSyncMode(int nDetectorID, int& nTriggerMode); bool GetKernelVersion(int nDetectorID, char* pszKernelVersion); bool GetDelayTime(int nDetectorID, int& nDelayTime); bool SetDelayTime(int nDetectorID, int nDelayTime); bool SetCorrectFile(); bool GetCorrectFileIndex(int& nGainMapIndex, int& nDefectMapIndex); bool GetWifiLinkQuality(int nDetectorID, int& nQuality); bool GetROMInfo(int nPanelIndex); bool GetHVGSignalStatus(int nDetectorID); bool SetDetectorCorrection(int nDetectorID, int nCorrectionType); bool SetDetectorFluSync(int nDetectorID, int nFluSync); bool GetXWindowDelay(int nDetectorID, int& nXWidnowTime); bool GetPrepCapMode(int nDetectorID, int& nPrepCapMode); bool GetConnState(int nDetectorID, int& nConnState); bool GetSelfCapEnable(int nDetectorID, int& nSelfCapEnable); bool GetSelfClearEnable(int nDetectorID, int& nSelfClearEnable); bool GetDynaOffsetGapTime(int nDetectorID, int& nDynOffsetGapTime); bool WriteRom(int nDetectorID); int SetSyncMode(int nPanelIndex, int nSetSyncMode); int SetInnerSubFlow(int nDetectorID, int nInnerSubFlow); int SetCapModeFunc(int nDetectorID, int nSetCapMode); int SetFPDCalParam(int nDetectorID, int nSetSelfCapEnable, int nSetSelfClearEnable); bool SetDetectorWorkMode(int nDetectorID, int nMode); bool SetDetectorXWindow(int nDetectorID, int nDelayTime, int nXWindowTime, int nClearAcqTime); bool OffsetCalibration(); bool OffsetProcess(int nDetectorID, int nMode); bool SetAppMode(int nDetectorID, int nMode); bool WaitRespond(int nTimeOut); void SendNotify(); void ResetLock(); void Pausetime(DWORD dwSpan); bool WaitReady(int nPanelIndex, int nMs); bool StartXWindowOffThread(); static DWORD XWindowOffThread(LPVOID pParam); void DisconnectFD(int nDetectorID); bool IsFWNeedUpdate(int nDetectorID); bool UpdateFirmware(int nPanelIndex, bool bUpdate); bool UploadCalibFileFromFD(int nDetectorID, int nIndex, string strFileName, bool bGain); bool DownloadCalibrationFileToFD(bool bGainFile, bool bExpMode); bool DownloadUserDefectFileToFD(bool bLTE); bool DownloadfromDetector(int nDetectorID); bool DeleteOneFolder(string strSourceFolder); bool CleanCalibFiles(int nDetectorID, bool bExpMode); bool CheckLastImageStatus(int nDetectorID); bool RecoverImage(); bool OnEXIT(); void DeleteHandle(); bool GetCalibrationTime(int nDetectorID, bool bExpMode); void GetFwName(string strFirmPath, string& strFirmwareName); bool FlipX(WORD* pData, int nWidth, int nHeight); bool FlipXRotate90(WORD* pData, int nWidth, int nHeight); bool IsConnected(string strIP); bool ModifyConfigIni(string strIniPath, string strSN, string strIP); void OnProcessPreImg(); void OnProcessImg(); bool GetEffectiveImage(WORD* pOutImg, WORD* pInImg, int nInWidth); HANDLE m_pHardwareStatusThread; HANDLE m_hEndHWStatusThreadEvent; HANDLE m_hHWStatusThreadEndEvent; bool StartHardwareStatusThread(); static DWORD HardwareStatusThread(LPVOID pParam); bool GetHardwareStatus(); bool GetConnectionStatus(int nDetectorID); bool SaveRawImage(const char* pImgName, const WORD* pRawImg, int nWidth, int nHeight); bool CheckImageEXI(WORD* pImage, int nWidth, int nHeight, int nImageBit, int nThreshold, float fArea); bool SetOffsetModeScope(); private: //句柄 HMODULE m_hIRayModule; FnCreate m_fpCreate; FnDestroy m_fpDestroy; FnGetAttr m_fpGetAttr; FnSetAttr m_fpSetAttr; FnInvoke m_fpInvoke; FnRegisterScanNotify m_pRegisterScanNotify; FnScanOnce m_pScanOnce; FnGetErrInfo m_pFnGetErrorInfo; FnAbort m_pfAbort; FnOpenDefectTemplateFile m_pfOpenDefectTemplateFile; FnCloseDefectTemplateFile m_pfCloseDefectTemplateFile; HANDLE m_hInitThread; HANDLE m_hArrayEvent[IRAY_SCAN_NUM]; HANDLE m_hExitEvent; HANDLE m_hRecoverImage; HANDLE m_hCofirmCalib; HANDLE m_hEndCalibEvent; HANDLE m_hOffsetEvent; HANDLE m_hIRayScanEnd; HANDLE m_hSharedEvent; //等待SDK回调句柄 HANDLE m_hWindowOffEvent; HANDLE m_pXWindowoffThread; HANDLE m_hScanEventThread; string g_strAppPath; int m_nPanelCount; int m_nDetectorID; //SDK探测器ID(1,2,3) int m_nDetectorIndex; //当前激活探测器的index(0,1,2) FPDDeviceIRay* m_pCurrentDPC; map* m_pDPC2PanelID; map* m_pPanelID2DPC; DeviceIndexStruct m_stDeviceIndex[3]; //配置的探测器列表//不超过三块板 ResDataObject m_ObjFPDsInfo[3]; //存储探测器数量和类型 ResDataObject m_ModeConfig; WORD* m_pwRawImageData; //原始图像内存 WORD* m_pwPreviewImg; //preview内存 map m_mapLogicModeOperationMode; // int m_nCmdConnectResult; DeviceErrorInfor m_WarnRes; //warn配置文件列表 DeviceErrorInfor m_ErrRes; //error配置文件列表 DeviceErrorList m_ErrList; //当前错误列表 DeviceErrorList m_ErrListTemp; //初始化时未发送到UI的ERROR DeviceErrorList m_WarnList; //当前错误列表 bool m_bInitialing; //是否在初始化过程中 bool m_bBatteryCharging; //电池充电与否的状态 bool m_bRecoveringImage;//是否在恢复图像的流程中;若是,屏蔽其他错误,以防止干扰恢复图像的界面流程 bool m_bAbortRecover; //放弃恢复图像(状态),恢复图像过程中中止,恢复图像失败的提示不再往上发送;目前不起作用 bool m_bSetCorrectFile; bool m_bForceGridSuppress; bool m_bInCalibrating; bool m_bInExposure; bool m_bWindowOn; //曝光窗口是否打开了 bool m_bFDAttaching; bool m_bShowAttachInfo; bool m_bFirmwareUpdating; int m_nDoseParam;// 校正用的曝光计量,发送到UI 且本地记录 int m_nRequireTimer; //查询WIFI电量的周期,Patient界面 10分钟检查一次 int m_nRecoverImageTimes; // 恢复图像失败的次数,每2次提示用户一次 int m_nCalibDueSetting; // 校正文件的保质期天数 int m_nOldDay; //校正日期定期检查的上次时间(某一天) int m_nCalibStatus; int m_nSID; //SID值 int m_nBatteryCapacity; int m_nBatteryCharges; int m_nGridLicense; float m_fCalibTemperature1; float m_fCalibTemperature2; float m_fCalibTemperature; float m_fTemperatureMin; float m_fTemperatureMax; float m_fGradientMean; float m_fGradientStdDev; //校正相关变量 list m_listCalibItem; list::iterator m_iterCalibDose; int m_nCalibrationMode; //校正模式,ZSKK or Factory int m_nDefectExpTimes; int m_nDefectTotalTimes; int m_nGainExpTimes; int m_nGainTotalFrames; int m_nDefectTotalFrames; int m_nLastExpFDIndex; int m_nCorrectionType; //其他 bool m_bImageRecoverBeCanceled; bool m_bOffsetAll; float m_fFrameRate; }; }