#include "stdafx.h" #include "Detector_CareRayDR.h" #include "CCOS.Dev.FPD.CareRayDR.h" #include "MyPingip.h" Detector_CareRayDR* g_pDetector = nullptr; extern Log4CPP::Logger* gLogger; #define LOAD_PROC_ADDRESS(handle,func) \ if ((API_##func = (Func_##func)GetProcAddress(handle, #func)) == NULL) { printf("Error occurs while loading entry point!!! \r\n'%s'\n", #func); }\ #define RAD_HEADER_SIZE 65536 const int nBuffSize = 1088 * 1088 * 64; const int FLUORO_IMAGE_HEADER_SIZE = 256; void __stdcall CREventCallback(int eventID, CrEvent * eventData) { if (nullptr != g_pDetector) { g_pDetector->ProcessCREvent(eventID, eventData); } } Detector_CareRayDR::Detector_CareRayDR() { m_pDPC2PanelID = new map(); m_pPanelID2DPC = new map(); m_nPanelCount = 0; m_nCurrentPanelID = 0; m_hCareRayDRModule = nullptr; m_nSyncMode = SYNC_SOFTWARE; m_nTriggerType = CR_RAD_EXT_SYNC; m_pRawImgBuffer = nullptr; m_pImgBuffer = nullptr; m_nImageWidth = 0; m_nImageHeight = 0; m_nWidthOffset = 0; m_nHeightOffset = 0; m_nRawImgWidth = 0; m_nRawImgHeight = 0; m_bSaveRaw = false; m_eCaliType = CCOS_CALIBRATION_TYPE_NONE; m_nCurrentLogicMode = AcqMode::RAD; m_nCalibrationMode = CCOS_CALIBRATION_MODE_ZSKK; m_pFluFrameData = nullptr; m_nCalibrationRounds = 0; m_nCalibCurrentCalibrationRound = 0; m_nCalibCurrentExposureIndex = 0; m_nExposureNumCurrentRound = 0; m_pZSKKCalib = nullptr; m_strDetectorType = ""; m_bOnlyHaveFpd = false; m_nGainImg = 0; m_nGainExposureNum = 0; m_nDetectorNum = 1; m_hRespond = CreateEvent(NULL, FALSE, FALSE, NULL); m_hInitEvent = CreateEvent(NULL, FALSE, FALSE, NULL); m_hExitEvent = CreateEvent(NULL, FALSE, FALSE, NULL); m_hReConnectEvent = CreateEvent(NULL, FALSE, FALSE, NULL); m_hSwitchEvent = CreateEvent(NULL, FALSE, FALSE, NULL); m_hRadEvent = CreateEvent(NULL, FALSE, FALSE, NULL); m_hDualEnergyEvent = CreateEvent(NULL, FALSE, FALSE, NULL); m_hOffsetEvent = CreateEvent(NULL, FALSE, FALSE, NULL); m_hGainEvent = CreateEvent(NULL, FALSE, FALSE, NULL); m_hArrayEvent[0] = m_hInitEvent; m_hArrayEvent[1] = m_hExitEvent; m_hArrayEvent[2] = m_hReConnectEvent; m_hArrayEvent[3] = m_hSwitchEvent; m_hArrayEvent[4] = m_hRadEvent; m_hArrayEvent[5] = m_hDualEnergyEvent; m_hArrayEvent[6] = m_hOffsetEvent; m_hArrayEvent[7] = m_hGainEvent; m_hToggleEvent = CreateEvent(NULL, FALSE, FALSE, NULL); InitSdkInterface(); } void Detector_CareRayDR::InitSdkInterface() { API_CrInitializeLibrary = nullptr; API_CrDeinitializeLibrary = nullptr; API_CrGetLastIntlMsg = nullptr; API_CrGetConfigItemValue = nullptr; API_CrSetConfigItemValue = nullptr; API_CrRegisterEventCallbackFun = nullptr; API_CrGetDetectorIndexAndIPAddress = nullptr; API_CrConnect = nullptr; API_CrResetDetector = nullptr; API_CrDisconnect = nullptr; API_CrGetSystemInformation = nullptr; API_CrGetApplicationMode = nullptr; API_CrRegisterApplicationMode = nullptr; API_CrSetFrameFilter = nullptr; API_CrGetModeInfoByAppModeKey = nullptr; API_CrGetRegedInfoByAppModeKey = nullptr; API_CrGetModeInfoByModeId = nullptr; API_CrLoadReference = nullptr; API_CrUnloadReference = nullptr; API_CrStartAcquisition = nullptr; API_CrStartDarkAcquisition = nullptr; API_CrStartDarkAcquisitionWithCorrOpt = nullptr; API_CrStopAcquisition = nullptr; API_CrStartDarkCalibration = nullptr; API_CrStartGainCalibration = nullptr; API_CrStopCalibration = nullptr; API_CrGetAcquisitionStatInfo = nullptr; API_CrQueryCalibrationStatus = nullptr; API_CrQueryReferenceStatus = nullptr; API_CrGetDefectInfo = nullptr; API_CrGetPositionDefectInfo = nullptr; API_CrQueryAcquisitionStatus = nullptr; API_CrQueryAedExposureProgress = nullptr; API_CrPermitExposure = nullptr; API_CrRequestExposure = nullptr; API_CrGetImage = nullptr; API_CrGetNoHeaderImage = nullptr; API_CrGetDetrStatus = nullptr; API_CrGetConnectionStatus = nullptr; API_CrStartAcquisitionWithCorrOpt = nullptr; API_CrGetDaecActiveAreas = nullptr; API_CrSetDaecActiveAreas = nullptr; API_CrGetBatteryInfos = nullptr; API_CrGetWirelessStatus = nullptr; } Detector_CareRayDR::~Detector_CareRayDR() { CloseStatusMonitor(); CloseDetectorScan(); if (m_pRawImgBuffer) { delete[]m_pRawImgBuffer; m_pRawImgBuffer = nullptr; } if (m_pImgBuffer) { delete[]m_pImgBuffer; m_pImgBuffer = nullptr; } if (m_pDarkImage) { delete[]m_pDarkImage; m_pDarkImage = nullptr; } if (m_pFluFrameData) { delete[] m_pFluFrameData; m_pFluFrameData = nullptr; } if (m_pZSKKCalib) { delete m_pZSKKCalib; m_pZSKKCalib = nullptr; } } bool Detector_CareRayDR::DriverEntry(FPDDeviceCareRay* pDrvDPC, ResDataObject& Configuration) { printf("--Func-- DriverEntry %p\n", pDrvDPC); Info("--Func-- DriverEntry {$}", pDrvDPC); map::iterator DPCsIter = m_pDPC2PanelID->find(pDrvDPC); if (DPCsIter != m_pDPC2PanelID->end()) { printf("This DPC already exist\n"); Error("This DPC already exist"); return false; } CPanelStatus* p = new CPanelStatus(); m_pStPanelStatus[m_nPanelCount] = p; m_pDPC2PanelID->insert(pair(pDrvDPC, m_nPanelCount)); m_pPanelID2DPC->insert(pair(m_nPanelCount, pDrvDPC)); m_nPanelCount++; m_ModeConfig = Configuration; //记录配置 --目前只有一个平板,多板时应该分别存储 Info("Config: {$}", m_ModeConfig.encode()); return true; } bool Detector_CareRayDR::Connect(FPDDeviceCareRay* pDrvDPC, const char* szWorkPath) { Info("Connect detector begin"); printf("Connect detector begin \r\n"); if ((*m_pDPC2PanelID)[pDrvDPC] != m_nCurrentPanelID) { Info("Not current DPC, return true"); printf("Not current DPC, return true \r\n"); return true; } if (!m_pZSKKCalib) { m_pZSKKCalib = new CZSKKCalibrationCtrl(); } m_strWorkPath = szWorkPath; if (nullptr == m_hFPDScanThread) { unsigned uThreadId; _beginthreadex(NULL, 0, onFPDScanThread, this, 0, &uThreadId); m_hFPDScanThread = OpenThread(THREAD_ALL_ACCESS, TRUE, uThreadId); } SetEvent(m_hInitEvent); Info("Connect over"); printf("Connect over \r\n"); return true; } bool Detector_CareRayDR::Disconnect() { int ret = CR_OK; Info("Disconnect detector begin \r\n"); SetEvent(m_hExitEvent); //关闭Scan线程 DWORD result = WaitForSingleObject(m_hToggleEvent, 65000); if (result == WAIT_OBJECT_0) { Info("Leave scan thread over"); } else if (result == WAIT_TIMEOUT) { Error("Till time out"); } Info("Call CrUnloadReference"); ret = API_CrUnloadReference(m_nDetectorID, m_nAppModeKey); if (!TestError(ret)) { Error("Unload Calibration Data Failed"); return false; } Info("Call CrDisconnect"); ret = API_CrDisconnect(m_nDetectorID); if (!TestError(ret)) { Error("disconnect detector fail!"); return false; } Info("Disconnect over"); return true; } void Detector_CareRayDR::EnterExamMode(int nExamMode) { switch (nExamMode) { case APP_STATUS_WORK_BEGIN: Info("Enter into Exam Windows"); break; case APP_STATUS_WORK_END: Info("Quit Exam Windows"); break; case APP_STATUS_DETSHARE_BEGIN: Info("Enter into Detector Share Windows"); break; case APP_STATUS_DETSHAR_END: Info("Quit Detector Share Windows"); break; case APP_STATUS_CAL_BEGIN: Info("Enter into Calibration Windows"); break; case APP_STATUS_CAL_END: Info("Quit Calibration Windows"); break; case APP_STATUS_WORK_IN_SENSITIVITY: Info("Enter into sensitivity test interface"); break; default: break; } if (APP_STATUS_WORK_END == nExamMode || APP_STATUS_CAL_END == nExamMode) { } } /*** ** 根据采集模式申请图像buffer ***/ bool Detector_CareRayDR::SetAcqMode(int nMode) { Info("Detector_CareRayDR::SetAcqMode mode:{$}", nMode); //if (m_nCurrentLogicMode == nMode) //{ // Info("Same acq mode,return"); // return true; //} if (!m_pStPanelStatus[m_nCurrentPanelID]->bConnectState) { Error("Detector not connected, return"); return false; } try { int nModeCount = (int)m_ModeConfig["ModeTable"].GetKeyCount("DetectorMode"); for (int i = 0; i < nModeCount; i++) { int nAppModeID = (int)m_ModeConfig["ModeTable"][i]["LogicMode"]; if (nAppModeID == nMode) { //设置采集模式,根据不同的场景设置不同的采集模式 m_nAppModeKey = (int)m_ModeConfig["ModeTable"][i]["AppModeKey"]; m_nModeID = (int)m_ModeConfig["ModeTable"][i]["ModeID"]; m_nFrameRate = (int)m_ModeConfig["ModeTable"][i]["FrameRate"]; m_nExtIntegrationTime = (int)m_ModeConfig["ModeTable"][i]["ExtIntegrationTime"]; m_nGainLevel = (int)m_ModeConfig["ModeTable"][i]["GainLevel"]; m_nImageWidth = (int)m_ModeConfig["ModeTable"][i]["ImageWidth"]; m_nImageHeight = (int)m_ModeConfig["ModeTable"][i]["ImageHeight"]; m_nWidthOffset = (int)m_ModeConfig["ModeTable"][i]["WidthOffset"]; m_nHeightOffset = (int)m_ModeConfig["ModeTable"][i]["HeightOffset"]; Info("After crop image width: {$}, height: {$}, WidthOffset: {$}, HeightOffset: {$}", m_nImageWidth, m_nImageHeight, m_nWidthOffset, m_nHeightOffset); m_nSyncMode = (int)m_ModeConfig["ModeTable"][i]["SyncType"]; m_bSaveRaw = (int)m_ModeConfig["ModeTable"][i]["IsSaveRaw"]; Info("m_nSyncMode:{$},m_nSaveRaw:{$}", m_nSyncMode, m_bSaveRaw); GetTriggerType(m_nSyncMode); m_pStPanelStatus[m_nCurrentPanelID]->eSyncMode = (SYNC_MODE)m_nSyncMode; m_nCurrentLogicMode = nMode; if (m_nCurrentLogicMode == AcqMode::RAD) { if (nullptr != m_pImgBuffer) { delete[] m_pImgBuffer; m_pImgBuffer = nullptr; } m_pImgBuffer = new WORD[(size_t)m_nImageWidth * (size_t)m_nImageHeight]; } else if (m_nCurrentLogicMode == AcqMode::DAEC) { if (nullptr != m_pImgBuffer) { delete[] m_pImgBuffer; m_pImgBuffer = nullptr; } m_pImgBuffer = new WORD[(size_t)m_nImageWidth * (size_t)m_nImageHeight]; } else if (m_nCurrentLogicMode == AcqMode::DUAL_ENERGY) { if (nullptr != m_pImgBuffer) { delete[] m_pImgBuffer; m_pImgBuffer = nullptr; } m_pImgBuffer = new WORD[(size_t)m_nImageWidth * (size_t)m_nImageHeight]; } else if (m_nCurrentLogicMode == DDR) { if (nullptr != m_pFluFrameData) { delete[] m_pFluFrameData; m_pFluFrameData = nullptr; } m_pFluFrameData = new WORD[(size_t)m_nImageWidth * (size_t)m_nImageHeight]; memset(m_pFluFrameData, 0, (size_t)m_nImageWidth * (size_t)m_nImageHeight); } break; } } } catch (ResDataObjectExption& e) { Error("Get config error: {$}", e.what()); return false; } StatusFeedback(EVT_STATUS_PANEL, PANEL_SLEEP); return true; } bool Detector_CareRayDR::PrepareAcquisition(FPDDeviceCareRay* pDrvDPC) { Info("PrepareAcquisition start"); if ((*m_pDPC2PanelID)[pDrvDPC] != m_nCurrentPanelID) { printf("Not current DPC, return\n"); Error("Not current DPC, return"); return false; } //未初始化、未连接 不执行 if (!m_pStPanelStatus[m_nCurrentPanelID]->bConnectState) { Error("Detector not connected, return"); return false; } Info("PrepareAcquisition m_nTriggerType:{$}", m_nTriggerType); if (!SetApplicationMode()) { return false; } if (!ShowModeInfo()) { return false; } //Careray not have Calibration for dual energy,so don't load Calibration File if (m_nCurrentLogicMode != AcqMode::DUAL_ENERGY) { //LoadCalibrationFiles(); } int nRet = CR_OK; if (m_nCurrentLogicMode == AcqMode::RAD) { SetEvent(m_hRadEvent); } else if (m_nCurrentLogicMode == AcqMode::DAEC) { SetEvent(m_hRadEvent); } else if (m_nCurrentLogicMode == AcqMode::DUAL_ENERGY) { SetEvent(m_hDualEnergyEvent); } else if (m_nCurrentLogicMode == AcqMode::DDR) { if (m_nTriggerType == CrTrigType::CR_FLUORO_INT_SYNC) { Info("DDR use flu mode of Inner Trigger"); Info("Call CrStartAcquisition"); nRet = API_CrStartAcquisition(m_nDetectorID, m_nAppModeKey, -1); if (!TestError(nRet)) { Error("Failed to start DDR acquisition"); return false; } } } Sleep(5000); StatusFeedback(EVT_STATUS_PANEL, PANEL_STANDBY); Info("PrepareAcquisition end"); return true; } bool Detector_CareRayDR::StartAcquisition(FPDDeviceCareRay* pDrvDPC) { int nRes = CR_OK; Info("StartAcquisition start"); if ((*m_pDPC2PanelID)[pDrvDPC] != m_nCurrentPanelID) { printf("Not current DPC, return\n"); Error("Not current DPC, return"); return false; } //未初始化、未连接 不执行 if (!m_pStPanelStatus[m_nCurrentPanelID]->bConnectState) { Error("Detector not connected, return"); return false; } if (m_nCurrentLogicMode == AcqMode::RAD && m_nTriggerType == CrTrigType::CR_RAD_SOFT_SYNC) { Info("Rad Soft Trigger RequestExposure!!!!"); StatusFeedback(EVT_STATUS_PANEL, PANEL_XWINDOW_ON); nRes = API_CrRequestExposure(m_nDetectorID); if (!TestError(nRes)) { Error("RequestExposure Failed"); } } if (m_nCurrentLogicMode == AcqMode::DUAL_ENERGY) { Info("Dual Energy RequestExposure!!!"); StatusFeedback(EVT_STATUS_PANEL, PANEL_START_ACQ); int nRes = CR_OK; nRes = API_CrRequestExposure(m_nDetectorID); if (!TestError(nRes)) { Error("RequestExposure Failed"); return false; } Info("RequestExposure Successed!!"); } Info("StartAcquisition end"); return true; } bool Detector_CareRayDR::StopAcquisition(FPDDeviceCareRay* pDrvDPC) { if ((*m_pDPC2PanelID)[pDrvDPC] != m_nCurrentPanelID) { printf("Not current DPC, return\n"); Error("Not current DPC, return"); return false; } if (!m_pStPanelStatus[m_nCurrentPanelID]->bConnectState) { Error("Detector not connected, return"); return false; } Info("## Stop Acquisition ##"); int nRet = CR_OK; Info("Call CrStopAcquisition"); nRet = API_CrStopAcquisition(m_nDetectorID); if (!TestError(nRet)) { Error("Stop Acquisition Failed"); return false; } SetCareRayDPCStatus(eDetStatus::DetStatus_Standby); //停止采集 return true; } bool Detector_CareRayDR::RequestXray(FPDDeviceCareRay* pDrvDPC) { Info("Dual Energy Request Exposure!!"); int nRes = CR_OK; nRes = API_CrRequestExposure(m_nDetectorID); if (!TestError(nRes)) { Error("RequestExposure Failed"); return false; } Info("RequestExposure Successed!!"); return true; } bool Detector_CareRayDR::ActiveCalibration(FPDDeviceCareRay* pDrvDPC, CCOS_CALIBRATION_TYPE eType) { if ((*m_pDPC2PanelID)[pDrvDPC] != m_nCurrentPanelID) { printf("Not current DPC, return\n"); Error("Not current DPC, return"); return false; } if (!m_pStPanelStatus[m_nCurrentPanelID]->bConnectState) { Error("Detector not connected, return"); return false; } StatusFeedback(EVT_STATUS_CALIBRATIOIN, PANEL_EVENT_START); m_eCaliType = eType; m_nGainImg = 0; if (CCOS_CALIBRATION_TYPE_DARK == m_eCaliType) { Info("Active Dark Calibration"); } if (CCOS_CALIBRATION_TYPE_XRAY == m_eCaliType) { Info("Active Xray Calibration"); if (m_nCalibrationMode) //厂商校正 { } else //ZSKK校正 { if (!m_pZSKKCalib) { Error("ZSKK Calibration object is undefined"); } else { //反馈Dose信息 DataFeedback(EVT_DATA_DOSEPARAM, NULL, 0, 2.5); //加载ZSKK的校正文件 m_pZSKKCalib->m_strRawImgPath = m_strWorkPath + "\\rawdata\\"; m_pZSKKCalib->m_strRefFilePath = m_strWorkPath + "\\references\\"; m_pZSKKCalib->m_nFullImgWidth = m_nImageWidth; m_pZSKKCalib->m_nFullImgHeight = m_nImageHeight; m_pZSKKCalib->m_nReferenceNum = m_nCalibrationRounds; m_pZSKKCalib->m_nSaturationValue = 50000; m_pZSKKCalib->LoadZSKKGainMap(false, m_strDetectorType); m_pZSKKCalib->LoadZSKKPixelMap(false, m_strDetectorType); Info("Load ZSKK Gain map success!"); Info("references file path: {$}", m_pZSKKCalib->m_strRefFilePath); } } } return true; } /*** * 接受曝光图像 ***/ bool Detector_CareRayDR::AcceptCalibration() { Info("Accept calibration exposure result"); if (m_nCalibrationMode)//厂商校正 { //不做处理 } else //ZSKK校正 { if (m_nCalibCurrentExposureIndex == 1) { m_pZSKKCalib->AddImageToPixMap(m_pImgBuffer); m_pZSKKCalib->AverageZSKKGainMap(m_pImgBuffer, m_nCalibCurrentCalibrationRound - 1, true); } else { m_pZSKKCalib->AverageZSKKGainMap(m_pImgBuffer, m_nCalibCurrentCalibrationRound - 1, false); //曝光第几轮 } } return true; } /*** * 拒绝曝光图像 ***/ bool Detector_CareRayDR::RejectCalibration() { Info("Reject calibration exposure result"); return true; } /*** * 设置校正轮数 ***/ bool Detector_CareRayDR::SetCalibRounds(int nCalibRounds) { m_nCalibrationRounds = nCalibRounds; Info("Set reference number: {$}", m_nCalibrationRounds); return true; } bool Detector_CareRayDR::GetCalibrationStep(int nCalibCurrentCalibrationRound, int nCalibrationRounds, int nCalibCurrentExposureIndex, int nExposureNumCurrentRound) { m_nCalibCurrentCalibrationRound = nCalibCurrentCalibrationRound; m_nCalibrationRounds = nCalibrationRounds; m_nCalibCurrentExposureIndex = nCalibCurrentExposureIndex; m_nExposureNumCurrentRound = nExposureNumCurrentRound; Info("Calibration Step===Round: {$}/{$}, ExposureNum: {$}/{$}", nCalibCurrentCalibrationRound, nCalibrationRounds, nCalibCurrentExposureIndex, nExposureNumCurrentRound); return true; } //使探测器ready bool Detector_CareRayDR::PrepareCalibration(FPDDeviceCareRay* pDrvDPC) { if ((*m_pDPC2PanelID)[pDrvDPC] != m_nCurrentPanelID) { printf("Not current DPC, return\n"); Error("Not current DPC, return"); return false; } if (!m_pStPanelStatus[m_nCurrentPanelID]->bConnectState) { Error("Detector not connected, return"); return false; } if (CCOS_CALIBRATION_TYPE_DARK == m_eCaliType) { Info("PrepareCalibration CCOS_CALIBRATION_TYPE_DARK == m_eCaliType"); //由于前端没有测试过暗场校正上图的情况,故此处不进行暗场上图 //DarkAcquisition(); } else if (CCOS_CALIBRATION_TYPE_XRAY == m_eCaliType) { Info("PrepareCalibration CCOS_CALIBRATION_TYPE_XRAY == m_eCaliType"); SetCareRayDPCStatus(eDetStatus::DetStatus_Standby); bool ret = PrepareAcquisition(pDrvDPC); if (ret) { Info("PrepareCalibration PrepareAcquisition success!"); } else { Error("PrepareCalibration PrepareAcquisition fail!"); return false; } } return true; } //软同步调用接口,其它同步模式没有动作 bool Detector_CareRayDR::StartCalibration(FPDDeviceCareRay* pDrvDPC) { if ((*m_pDPC2PanelID)[pDrvDPC] != m_nCurrentPanelID) { printf("Not current DPC, return\n"); Error("Not current DPC, return"); return false; } //未初始化、未连接 不执行 if (!m_pStPanelStatus[m_nCurrentPanelID]->bConnectState) { Error("Detector not connected, return"); return false; } if (CCOS_CALIBRATION_TYPE_DARK == m_eCaliType) { //SetEvent(m_hDarkEvent); Info("StartCalibration DARK"); OnProcessDarkEnd(); } else if (CCOS_CALIBRATION_TYPE_XRAY == m_eCaliType) { Info("StartCalibration XRAY"); SetEvent(m_hRadEvent); //StartCalibration } return true; } /*** ** 说明:处理dark校正完成流程 ***/ void Detector_CareRayDR::OnProcessDarkEnd() { Info("Refresh offset over"); StatusFeedback(EVT_STATUS_CALIBRATIOIN, PANEL_EVENT_END_OK); } /*** ** 说明:终止校正 ***/ RET_STATUS Detector_CareRayDR::AbortCalibration(FPDDeviceCareRay* pDrvDPC) { Info("AbortCalibration"); printf("AbortCalibration\n"); m_eCaliType = CCOS_CALIBRATION_TYPE_NONE; //恢复初值 RET_STATUS Ret = RET_STATUS::RET_FAILED; if (m_nCalibrationMode) //厂商校正 { } else { Info("Abort ZSKK calibration"); m_pZSKKCalib->LoadZSKKGainMap(true, m_strDetectorType); //重新加载增益校正文件 m_pZSKKCalib->AbortZSKKPixMap(m_strDetectorType); //放弃坏点校正并重新加载原来的坏点校正文件 } Info("AbortCalibration over"); return RET_STATUS::RET_SUCCEED; } bool Detector_CareRayDR::StopCalibration(FPDDeviceCareRay* pDrvDPC) { if ((*m_pDPC2PanelID)[pDrvDPC] != m_nCurrentPanelID) { printf("Not current DPC, return\n"); Error("Not current DPC, return"); return false; } if (!m_pStPanelStatus[m_nCurrentPanelID]->bConnectState) { Error("Detector not connected, return"); return false; } Info("StopCalibration StopAcquisition"); if (!StopAcquisition(pDrvDPC)) { Error("StopCalibration StopAcquisition failed"); return false; } return true; } /*** ** 说明:获取校正时间 ** 连接成功后,校正完成后 获取 ***/ bool Detector_CareRayDR::GetCalibrationTime(int nDetectorID) { if (nDetectorID == -1) { nDetectorID = m_nCurrentPanelID; } else { InfoFeedback(EVT_INFO_CALIBRATIOIN_TIME, nDetectorID, 0, 0, "0"); InfoFeedback(EVT_INFO_CALIBRATIOIN_TIMEL, nDetectorID, 0, 0, "0"); } return true; } /*** ** 说明:结束校正 ** DPC处理完校正报告后调用,此处上传map、报告等文件 ***/ bool Detector_CareRayDR::CompleteCalibration(FPDDeviceCareRay* pDrvDPC) { Info("CompleteCalibration calib type {$}", (int)m_eCaliType); if (m_eCaliType == CCOS_CALIBRATION_TYPE_DARK) { printf("DARK DARK Calib over \r\n"); Info("DARK Calib over"); } else if (m_eCaliType == CCOS_CALIBRATION_TYPE_XRAY) { printf("XRAY Calib over \r\n"); Info("XRAY Calib over"); GetCalibrationTime(); StatusFeedback(EVT_STATUS_SAVECALIB, PANEL_EVENT_START); StatusFeedback(EVT_STATUS_SAVECALIB, PANEL_EVENT_END); } return true; } bool Detector_CareRayDR::SaveCalibrationFile() { Info("Save Calibration File"); if (m_nCalibrationMode)//厂商校正 { //不做处理 } else { Info("Save ZSKK Calibration File"); m_pZSKKCalib->StoreZSKKGainMap(m_strDetectorType); m_pZSKKCalib->StoreZSKKPixMap(m_strDetectorType); } //更新配置文件中校正日期和时间 SYSTEMTIME stCurrentTime = { 0 }; GetLocalTime(&stCurrentTime); Info("Current time: {$04d}/{$02d}/{$02d} {$02d}:{$02d}:{$02d}:{$03d}", stCurrentTime.wYear, stCurrentTime.wMonth, stCurrentTime.wDay, stCurrentTime.wHour, stCurrentTime.wMinute, stCurrentTime.wSecond, stCurrentTime.wMilliseconds); Info("Save Calibration File over"); return true; } CCOS_CALIBRATION_TYPE Detector_CareRayDR::GetCalibType() { Info("Get Calib Type {$}", (int)m_eCaliType); return m_eCaliType; } bool Detector_CareRayDR::ConfirmCalExposure() { bool bRet = false; return true; } void Detector_CareRayDR::RejectCalExposure() { //暂时什么都不处理 } bool Detector_CareRayDR::LoadDll(string strWorkPath) { Info("Start Load CareRay DLL"); string strSDKPath = ""; try { strSDKPath = (string)m_ModeConfig["SDKPath"]; } catch (ResDataObjectExption& e) { Error("Read configuration failed! reason: {$}", e.what()); return false; } string workpath = strWorkPath + strSDKPath; string drvpath = workpath + "\\CareRayApi.dll"; Info("SDK path:{$}", drvpath); SetDllDirectory(workpath.c_str()); m_hCareRayDRModule = LoadLibrary(drvpath.c_str()); if (m_hCareRayDRModule == nullptr) { DWORD dw = GetLastError(); Error("Load {$} failed! error code: {$}", drvpath.c_str(), dw); return false; } LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrInitializeLibrary); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrDeinitializeLibrary); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetLastIntlMsg); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetConfigItemValue); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrSetConfigItemValue); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrRegisterEventCallbackFun); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetDetectorIndexAndIPAddress); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrConnect); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrResetDetector); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrDisconnect); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetSystemInformation); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetApplicationMode); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrRegisterApplicationMode); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrSetFrameFilter); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetModeInfoByAppModeKey); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetRegedInfoByAppModeKey); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetModeInfoByModeId); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrLoadReference); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrUnloadReference); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrStartAcquisition); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrStartDarkAcquisition); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrStartDarkAcquisitionWithCorrOpt); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrStopAcquisition); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrStartDarkCalibration); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrStartGainCalibration); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrStopCalibration); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetAcquisitionStatInfo); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrQueryCalibrationStatus); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrQueryReferenceStatus); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetDefectInfo); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetPositionDefectInfo); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrQueryAcquisitionStatus); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrQueryAedExposureProgress); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrPermitExposure); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrRequestExposure); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetImage); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetNoHeaderImage); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetDetrStatus); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetConnectionStatus); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrStartAcquisitionWithCorrOpt); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetDaecActiveAreas); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrSetDaecActiveAreas); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetBatteryInfos); LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetWirelessStatus); Info("Load CareRay API end"); return true; } bool Detector_CareRayDR::ReleaseDll() { Info("Release Careray dll"); if (m_hCareRayDRModule != nullptr) { ::FreeLibrary(m_hCareRayDRModule); m_hCareRayDRModule = nullptr; } API_CrInitializeLibrary = nullptr; API_CrDeinitializeLibrary = nullptr; API_CrGetLastIntlMsg = nullptr; API_CrGetConfigItemValue = nullptr; API_CrSetConfigItemValue = nullptr; API_CrRegisterEventCallbackFun = nullptr; API_CrGetDetectorIndexAndIPAddress = nullptr; API_CrConnect = nullptr; API_CrResetDetector = nullptr; API_CrDisconnect = nullptr; API_CrGetSystemInformation = nullptr; API_CrGetApplicationMode = nullptr; API_CrRegisterApplicationMode = nullptr; API_CrSetFrameFilter = nullptr; API_CrGetModeInfoByAppModeKey = nullptr; API_CrGetRegedInfoByAppModeKey = nullptr; API_CrGetModeInfoByModeId = nullptr; API_CrLoadReference = nullptr; API_CrUnloadReference = nullptr; API_CrStartAcquisition = nullptr; API_CrStartDarkAcquisition = nullptr; API_CrStartDarkAcquisitionWithCorrOpt = nullptr; API_CrStopAcquisition = nullptr; API_CrStartDarkCalibration = nullptr; API_CrStartGainCalibration = nullptr; API_CrStopCalibration = nullptr; API_CrGetAcquisitionStatInfo = nullptr; API_CrQueryCalibrationStatus = nullptr; API_CrQueryReferenceStatus = nullptr; API_CrGetDefectInfo = nullptr; API_CrGetPositionDefectInfo = nullptr; API_CrQueryAcquisitionStatus = nullptr; API_CrQueryAedExposureProgress = nullptr; API_CrPermitExposure = nullptr; API_CrRequestExposure = nullptr; API_CrGetImage = nullptr; API_CrGetNoHeaderImage = nullptr; API_CrGetDetrStatus = nullptr; API_CrGetConnectionStatus = nullptr; API_CrStartAcquisitionWithCorrOpt = nullptr; API_CrGetDaecActiveAreas = nullptr; API_CrSetDaecActiveAreas = nullptr; API_CrGetBatteryInfos = nullptr; API_CrGetWirelessStatus = nullptr; return true; } /*** ** 连接探测器 ***/ bool Detector_CareRayDR::OpenDetector() { Info("OpenDetector start"); int nRet = -1; CrDetrIdxAndIPAddr DetectorArray[8]; int nValidDetectorNum = 0; int nActiveDetectorID = 0; Info("Call CrGetDetectorIndexAndIPAddress"); nRet = API_CrGetDetectorIndexAndIPAddress(DetectorArray, &nValidDetectorNum); if (!TestError(nRet)) { Error("Get detector index and IP address failed"); } if (nValidDetectorNum <= 0) { Info("System did not found detector"); } Info("System found detector number: {$}", nValidDetectorNum); m_nDetectorID = DetectorArray[0].index; Info("DetectorArray[0].index : {$}", m_nDetectorID); int nDetectorIndex = m_nDetectorID - 1; Info("API get detector number: {$}", nValidDetectorNum); Info("Call CrConnect"); nRet = API_CrConnect(m_nDetectorID); if (!TestError(nRet)) { Error("Connect Failed"); return false; } m_pStPanelStatus[m_nCurrentPanelID]->bConnectState = true; Info("m_pStPanelStatus[m_nCurrentPanelID]->bConnectState = true"); StatusFeedback(EVT_STATUS_PANEL, PANEL_CONNECT); Info("Connect detector({$}) success", m_nDetectorID); CrSystemInfo stSystemInfo; Info("Call CrGetSystemInformation"); nRet = API_CrGetSystemInformation(m_nDetectorID, &stSystemInfo); if (!TestError(nRet)) { Info("Get Detector Information Failed"); } Info("S/W version: {$}; F/W version: {$}; Detector SN: {$}; Machine ID: {$}; Raw image: [{$}, {$}]", stSystemInfo.software_version, stSystemInfo.firmware_version, stSystemInfo.serial_number, stSystemInfo.detr_machine_id, stSystemInfo.raw_img_height, stSystemInfo.raw_img_width); m_nRawImgHeight = stSystemInfo.raw_img_height; m_nRawImgWidth = stSystemInfo.raw_img_width; if (m_pRawImgBuffer == nullptr) { m_pRawImgBuffer = new WORD[(size_t)m_nRawImgHeight * (size_t)m_nRawImgWidth]; } CrModeInfo AppModeInfo[8]; int nModeNum = 0; Info("Call CrGetApplicationMode"); nRet = API_CrGetApplicationMode(m_nDetectorID, AppModeInfo, &nModeNum); if (!TestError(nRet)) { Error("Load Application Mode Failed"); } for (int i = 0; i < nModeNum; i++) { Info("AppMode({$}): mode_id({$}), max_frame_rate({$}), max_exp_time({$}), default_trig_type({$}), default_gain_level({$})", i, AppModeInfo[i].mode_id, AppModeInfo[i].max_frame_rate, AppModeInfo[i].max_exposure_time, AppModeInfo[i].default_trigger_type, AppModeInfo[i].default_gain_level); } OpenStatusMonitor(); SetCareRayDPCStatus(eDetStatus::DetStatus_Standby); Info("OpenDetector end"); return true; } /*** ** 初始化探测器 ***/ bool Detector_CareRayDR::InitDetector() { Info("InitDetector start"); int nRet = -1; //初始化时先reset,恢复缺省状态 Info("Call reset detector"); nRet = API_CrResetDetector(m_nDetectorID, false); if (!TestError(nRet)) { Error("Reset detector failed"); } //获取实际的探测器类型 Info("Call get detector type"); //连接上探测器后获取gain校正曝光的总次数 m_nGainExposureNum = ((FPDDeviceCareRay*)(*m_pPanelID2DPC)[m_nCurrentPanelID])->GetGainExposureNum(); Info("Gain Exposure Num:{$}", m_nGainExposureNum); m_bOnlyHaveFpd = ((FPDDeviceCareRay*)(*m_pPanelID2DPC)[m_nCurrentPanelID])->GetOnlyHaveFpd(); if (m_bOnlyHaveFpd) { Info("Current system only have FPD other is demo!"); } Info("InitDetector end"); return true; } bool Detector_CareRayDR::OpenStatusMonitor() { Info("---Open Status Monitor Thread---"); if (nullptr == m_hStatusMonitorThread) { unsigned uThreadId; _beginthreadex(NULL, 0, CareRayStatusMonitorThread, this, 0, &uThreadId); m_hStatusMonitorThread = OpenThread(THREAD_ALL_ACCESS, TRUE, uThreadId); } return false; } unsigned __stdcall Detector_CareRayDR::CareRayStatusMonitorThread(PVOID pvoid) { Detector_CareRayDR* pCurrentPanelOpr = (Detector_CareRayDR*)pvoid; if (pCurrentPanelOpr == nullptr) { Error("Careray Status Monitor parameter Error"); } bool bExitFlag = false; DWORD dwStatusCheckTime = 5000; while (!bExitFlag) { DWORD dwRet = WaitForSingleObject(pCurrentPanelOpr->m_hExitStatusMonitorEvent, dwStatusCheckTime); switch (dwRet) { case WAIT_OBJECT_0: Info("[Get ExitStatusMonitor Event]"); bExitFlag = true; break; case WAIT_TIMEOUT: pCurrentPanelOpr->StatusMonitor(); break; default: break; } } SetEvent(pCurrentPanelOpr->m_hStatusMonitorToggleEvent); return 0; } bool Detector_CareRayDR::StatusMonitor() { int ret = CR_OK; std::string strLog; if (!m_pStPanelStatus[m_nCurrentPanelID]->bConnectState) { Error("Detector not connected, return"); ErrorFeedback(EVT_ERR_COMMUNICATE, "true"); return false; } CrConnectionStatus stConnectionStatus; ret = API_CrGetConnectionStatus(m_nDetectorID, &stConnectionStatus); if (!TestError(ret)) { Warn("Get Detector connection status failed"); } CrDetrStatus stDetectorStatus; ret = API_CrGetDetrStatus(m_nDetectorID, &stDetectorStatus); if (!TestError(ret)) { Warn("Get Detector Status Failed"); } float fCPUTemperature = stDetectorStatus.detr_temperature.cpu - 20; float fAverageTemperature = stDetectorStatus.detr_temperature.avg; StatusFeedback(EVT_STATUS_TEMPERATURE, 0, "", m_nCurrentPanelID, fCPUTemperature); CrBatteryInfo stDetectorBattery; int batNum = 0; ret = API_CrGetBatteryInfos(m_nDetectorID, &stDetectorBattery, &batNum); if (!TestError(ret)) { Warn("Get Detector Battery Failed"); } unsigned short BatteryStatus; BatteryStatus = stDetectorBattery.relative_state_of_charge; StatusFeedback(EVT_STATUS_BATTERY_VALUE, BatteryStatus * 100, "", m_nCurrentPanelID); int WirelessStatus = 100; CrWirelessStatus stDetectorWireless; ret = API_CrGetWirelessStatus(m_nDetectorID, &stDetectorWireless); if (!TestError(ret)) { Warn("Get Detector Wireless Failed"); } WirelessStatus = stDetectorWireless.quality; StatusFeedback(EVT_STATUS_WIFI, WirelessStatus, "", m_nCurrentPanelID); return true; } bool Detector_CareRayDR::CloseStatusMonitor() { SetEvent(m_hExitStatusMonitorEvent); DWORD dwResult = WaitForSingleObject(m_hStatusMonitorToggleEvent, 5000); if (WAIT_TIMEOUT == dwResult) { ::TerminateThread(m_hStatusMonitorThread, 0); Warn("Kill Status Monitor Thread"); } if (m_hExitStatusMonitorEvent != nullptr) { CloseHandle(m_hExitStatusMonitorEvent); m_hExitStatusMonitorEvent = nullptr; } if (m_hStatusMonitorToggleEvent != nullptr) { CloseHandle(m_hStatusMonitorToggleEvent); m_hStatusMonitorToggleEvent = nullptr; } m_hStatusMonitorThread = nullptr; Info("---Close Status Monitor Thread---"); return true; } bool Detector_CareRayDR::CloseDetectorScan() { SetEvent(m_hExitEvent); DWORD dwResult = WaitForSingleObject(m_hDetectorScanToggleEvnet, 65000); if (WAIT_TIMEOUT == dwResult) { Error("Exit Scan Thread Failed. Time Out!"); } else if (WAIT_OBJECT_0 == dwResult) { Info("Exit Scan Thread Successful"); } if (m_hInitEvent != nullptr) { CloseHandle(m_hInitEvent); m_hInitEvent = nullptr; } if (m_hExitEvent != nullptr) { CloseHandle(m_hExitEvent); m_hExitEvent = nullptr; } if (m_hReConnectEvent != nullptr) { CloseHandle(m_hReConnectEvent); m_hReConnectEvent = nullptr; } if (m_hSwitchEvent != nullptr) { CloseHandle(m_hSwitchEvent); m_hSwitchEvent = nullptr; } if (m_hRadEvent != nullptr) { CloseHandle(m_hRadEvent); m_hRadEvent = nullptr; } if (m_hDualEnergyEvent != nullptr) { CloseHandle(m_hDualEnergyEvent); m_hDualEnergyEvent = nullptr; } if (m_hOffsetEvent != nullptr) { CloseHandle(m_hOffsetEvent); m_hOffsetEvent = nullptr; } if (m_hGainEvent != nullptr) { CloseHandle(m_hGainEvent); m_hGainEvent = nullptr; } if (m_hDetectorScanToggleEvnet != nullptr) { CloseHandle(m_hDetectorScanToggleEvnet); m_hDetectorScanToggleEvnet = nullptr; } return false; } /*** ** 显示当前采集模式的图像信息 ***/ int Detector_CareRayDR::ShowModeInfo() { CrModeInfo AppModeInfo[8]; int ret = CR_OK; Info("Call CrGetModeInfoByAppModeKey"); ret = API_CrGetModeInfoByAppModeKey(m_nDetectorID, m_nAppModeKey, AppModeInfo); if (!TestError(ret)) { Error("Load application mode by key({$}) failed", m_nAppModeKey); return false; } Info("AppMode({$}): mode_id({$}), max_frame_rate({$}), max_exp_time({$}), default_trig_type({$}), default_gain_level({$})", m_nAppModeKey, AppModeInfo[0].mode_id, AppModeInfo[0].max_frame_rate, AppModeInfo[0].max_exposure_time, AppModeInfo[0].default_trigger_type, AppModeInfo[0].default_gain_level); return true; } /*** ** 设置同步模式、采集窗口 ***/ bool Detector_CareRayDR::SetApplicationMode() { Info("SetApplicationMode"); int ret = CR_OK; Info("Set Application Mode: AppModeKey({$}), AppModeID({$}), frame_rate({$}), exposure_time({$}), trigger_type({$}), gain_level({$})", m_nAppModeKey, m_nModeID, m_nFrameRate, m_nExtIntegrationTime, m_nTriggerType, m_nGainLevel); Info("Call CrStopAcquisition"); ret = API_CrStopAcquisition(m_nDetectorID); if (!TestError(ret)) { Error("Stop Acquisition Failed"); return false; } Info("Call CrRegisterApplicationMode"); float temp_FrameRate = (float)m_nFrameRate; float temp_ExposureTime = (float)m_nExtIntegrationTime; ret = API_CrRegisterApplicationMode(m_nDetectorID, m_nAppModeKey, m_nModeID, &temp_FrameRate, &temp_ExposureTime, m_nTriggerType, m_nGainLevel, 0, 0); if (!TestError(ret)) { Error("Register application mode failed"); return false; } Info("Register application mode successful"); return true; } bool Detector_CareRayDR::LoadCalibrationFiles() { Info("## LoadCalibrationFiles ##"); int ret = CR_OK; Info("Call CrLoadReference"); ret = API_CrLoadReference(m_nDetectorID, m_nAppModeKey); if (!TestError(ret)) { Error("Load Reference failed"); return false; } return true; } unsigned __stdcall Detector_CareRayDR::onFPDScanThread(PVOID pvoid) { Detector_CareRayDR* pOpr = (Detector_CareRayDR*)pvoid; Info("Enter scan thread"); printf("Enter scan thread \r\n"); bool bExit = false; DWORD dwTimeOut = INFINITE; while (!bExit) { //Info("Waiting for signal..."); DWORD dwRet = WaitForMultipleObjects(8, pOpr->m_hArrayEvent, FALSE, dwTimeOut); if (WAIT_OBJECT_0 == dwRet) //m_hInitEvent { pOpr->OnProcessInitFPD(); } else if (WAIT_OBJECT_0 + 1 == dwRet) //m_hExitEvent { bExit = true; } else if (WAIT_OBJECT_0 + 2 == dwRet) //m_hReConnectEvent { } else if (WAIT_OBJECT_0 + 3 == dwRet) //m_hSwitchEvent { } else if (WAIT_OBJECT_0 + 4 == dwRet) //m_hRadEvent { Info("[Get Rad Event]"); pOpr->OpenRadAcquisition(); } else if (WAIT_OBJECT_0 + 5 == dwRet) //m_hDualEnergyEvent { Info("[Get Dual Energy Event]"); pOpr->OpenDualEnergyAcquisition(); } else if (WAIT_OBJECT_0 + 6 == dwRet) // { } else if (WAIT_TIMEOUT == dwRet) { pOpr->OnReconnectFPD(); } } SetEvent(pOpr->m_hToggleEvent); Info("Leave scan thread"); printf("Leave scan thread \r\n"); return 0; } void Detector_CareRayDR::OnStartDarkCalibration() { Info("dark calibration start"); int nRet = -1; Info("Call stop cal procedure(FALSE)"); Info("dark calibration end"); } void Detector_CareRayDR::OnAcquireGainImage() { Info("OnAcquireGainImage start"); Info("OnAcquireGainImage end"); } void Detector_CareRayDR::OnProcessInitFPD() { int ret; Info("OnProcessInitFPD start"); StatusFeedback(EVT_STATUS_INIT, PANEL_EVENT_START); if (!LoadDll(m_strWorkPath)) { ErrorFeedback(EVT_ERR_INIT_FAILED, "true"); StatusFeedback(EVT_STATUS_INIT, PANEL_EVENT_END_ERROR); //初始化失败 return; } Info("Call CrRegisterEventCallbackFun"); ret = API_CrRegisterEventCallbackFun(CREventCallback); if (!TestError(ret)) { ErrorFeedback(EVT_ERR_INIT_FAILED, "true"); StatusFeedback(EVT_STATUS_INIT, PANEL_EVENT_END_ERROR); } if (!OpenDetector()) { printf("Open detector failed, Connect failed \r\n"); Info("Open detector failed, Connect failed"); ErrorFeedback(EVT_ERR_COMMUNICATE, "true"); StatusFeedback(EVT_STATUS_INIT, PANEL_EVENT_END); //初始化时连接失败 } else { m_pStPanelStatus[m_nCurrentPanelID]->bInitOver = true; StatusFeedback(EVT_STATUS_INIT, PANEL_EVENT_END_OK); } Info("OnProcessInitFPD end"); } void Detector_CareRayDR::OnReconnectFPD() { Info("OnReconnectFPD start"); //初始化完成后 if (!m_pStPanelStatus[m_nCurrentPanelID]->bInitOver) { string strIP = ""; try { strIP = (string)m_ModeConfig["connections"]["WiredIP"]; } catch (ResDataObjectExption& e) { Error("Read configuration failed, Error code: {$}", e.what()); return; } if (IsConnected(strIP)) { StatusFeedback(EVT_STATUS_INIT, PANEL_EVENT_START); if (OpenDetector()) { if (InitDetector()) { m_pStPanelStatus[m_nCurrentPanelID]->bInitOver = true; ErrorFeedback(EVT_ERR_COMMUNICATE, "false"); StatusFeedback(EVT_STATUS_INIT, PANEL_EVENT_END_OK); } else { ErrorFeedback(EVT_ERR_INIT_FAILED, "true"); StatusFeedback(EVT_STATUS_INIT, PANEL_EVENT_END_ERROR); //重新初始化失败 } } else { StatusFeedback(EVT_STATUS_INIT, PANEL_EVENT_END); //重新初始化时连接失败 } } } Info("OnReconnectFPD end"); } /*** ** 获取一帧暗场图 ***/ int Detector_CareRayDR::DarkAcquisition() { int nRet = -1; int printOver = 0, awaitOver = 0; Info("Call set normal power"); return nRet; } /*** ** 轮询Manual(SDK的半aed模式)、aed模式采集状态 ***/ int Detector_CareRayDR::QueryAutoProgInfo(bool bIsAED) { Info("Begin query auto exposure progress info"); return CR_NO_ERR; } /*** ** 轮询硬同步模式采集状态 ***/ int Detector_CareRayDR::QueryRadProgInfo() { Info("Begin query rad exposure progress info"); return CR_NO_ERR; } void Detector_CareRayDR::SaveRawFunc(WORD* pInImg, int nImgWidth, int nImgHeight, string strFrameID) { FILE* fp; string strFileName = ""; if (strFrameID == "") { strFileName = m_strWorkPath + "\\Image\\Raw.raw"; } else { strFileName = m_strWorkPath + "\\Image\\Frame" + strFrameID + ".raw"; } Info("image file name:{$}", strFileName); if ((fp = fopen(strFileName.c_str(), "wb")) == NULL) { DWORD dw = GetLastError(); Error("fopen {$} failed, error code:{$}", strFileName, dw); return; } fwrite(pInImg, sizeof(WORD), (size_t)nImgWidth * (size_t)nImgHeight, fp); fclose(fp); Info("Save image over"); } /*** ** 裁剪图像 ** pOutImg: 裁剪后图像; pInImg: 裁剪前图像; nInWidth: 裁剪前图像宽度 ***/ bool Detector_CareRayDR::GetEffectiveImage(WORD* pOutImg, WORD* pInImg, int nInWidth) { if (pOutImg == NULL || pInImg == NULL || nInWidth < 0) { Error("Illegal parameter, can not get effective image"); return false; } try { for (int i = 0; i < m_nImageHeight; i++) { memcpy(pOutImg + i * m_nImageWidth, pInImg + (i + m_nHeightOffset) * nInWidth + m_nWidthOffset, m_nImageWidth * sizeof(WORD)); } } catch (...) { Error("Get effective image crashed"); return false; } return true; } //设置校正选项,选择是否加载校正文件 bool Detector_CareRayDR::SetUserCorrection(bool bLoad) { return true; } /*** ** 计算一键校正曝光的图像灰度 ***/ double Detector_CareRayDR::GetMean(WORD* imgNoHeader, int pixelNum) { double imgMean = 0; for (int i = 0; i < pixelNum; i++) { imgMean += imgNoHeader[i]; } imgMean = imgMean / pixelNum; return imgMean; } Detector_CareRayDR::eDetStatus Detector_CareRayDR::GetCareRayDPCStatus(int nDetectorIndex) { if (-1 == nDetectorIndex) { nDetectorIndex = m_nCurrentPanelID; } string strStatus = "Unknown"; switch (m_pStPanelStatus[nDetectorIndex]->eFPDStatus) { case eDetStatus::DetStatus_NotIni: strStatus = "NotIni"; break; case eDetStatus::DetStatus_NotConn: strStatus = "NotConn"; break; case eDetStatus::DetStatus_Sleep: strStatus = "Sleep"; break; case eDetStatus::DetStatus_Standby: strStatus = "Standby"; break; case eDetStatus::DetStatus_Work: strStatus = "Work"; break; case eDetStatus::DetStatus_Acquire: strStatus = "Acquire"; break; case eDetStatus::DetStatus_Offset: strStatus = "Offset"; break; case eDetStatus::DetStatus_XrayCalibration: strStatus = "XrayCalibration"; break; default: break; } Info("Driver status: {$}", strStatus.c_str()); return m_pStPanelStatus[nDetectorIndex]->eFPDStatus; } bool Detector_CareRayDR::SetCareRayDPCStatus(eDetStatus status, int nDetectorIndex) { if (-1 == nDetectorIndex) { nDetectorIndex = m_nCurrentPanelID; } string strStatus = "Unknown"; bool bSetStatus = true; switch (status) { case eDetStatus::DetStatus_NotIni: strStatus = "NotIni"; break; case eDetStatus::DetStatus_NotConn: strStatus = "NotConn"; break; case eDetStatus::DetStatus_Sleep: strStatus = "Sleep"; break; case eDetStatus::DetStatus_Standby: strStatus = "Standby"; break; case eDetStatus::DetStatus_Work: strStatus = "Work"; break; case eDetStatus::DetStatus_Acquire: strStatus = "Acquire"; break; case eDetStatus::DetStatus_Offset: strStatus = "Offset"; break; case eDetStatus::DetStatus_XrayCalibration: strStatus = "XrayCalibration"; break; default: bSetStatus = false; break; } if (bSetStatus) { m_pStPanelStatus[nDetectorIndex]->eFPDStatus = status; Info("Set driver status: {$}", strStatus.c_str()); } else { Error("{$} {$} is a illegal status", strStatus, (int)status); } return bSetStatus; } bool Detector_CareRayDR::IsConnected(string strIP) { Info("Check ping {$}", strIP); CMyPingip obPingIp; //StatusFeedback(EVT_STATUS_PING, 0, "true"); if (!obPingIp.PingFunction(strIP.c_str())) { Info("ping {$} Failed", strIP); //StatusFeedback(EVT_STATUS_PING, 0, "false"); return false; } return true; } bool Detector_CareRayDR::GetTriggerType(int nTriggerModeID) { Info("Get TriggerType"); switch (nTriggerModeID) { case 0: m_nTriggerType = CrTrigType::CR_RAD_MANUAL_SYNC; Info("TriggerType is CR_RAD_MANUAL_SYNC"); break; case 1: m_nTriggerType = CrTrigType::CR_RAD_SOFT_SYNC; Info("TriggerType is CR_RAD_SOFT_SYNC"); break; case 2: m_nTriggerType = CrTrigType::CR_RAD_EXT_SYNC; Info("TriggerType is CR_RAD_EXT_SYNC"); break; case 3: m_nTriggerType = CrTrigType::CR_RAD_AED_SYNC; Info("TriggerType is CR_RAD_AED_SYNC"); break; case 4: m_nTriggerType = CrTrigType::CR_RAD_AUTO_SYNC; Info("TriggerType is CR_RAD_AUTO_SYNC"); break; case 5: m_nTriggerType = CrTrigType::CR_RAD_DAEC_SYNC; Info("TriggerType is CR_RAD_DAEC_SYNC"); break; case 6: m_nTriggerType = CrTrigType::CR_RAD_DAEC_FLIP_SYNC; Info("TriggerType is CR_RAD_DAEC_FLIP_SYNC"); break; case 7: m_nTriggerType = CrTrigType::CR_FLUORO_EXT_SYNC; Info("TriggerType is CR_FLUORO_EXT_SYNC"); break; case 8: m_nTriggerType = CrTrigType::CR_FLUORO_INT_SYNC; Info("TriggerType is CR_FLUORO_INT_SYNC"); break; default: break; } return true; } bool Detector_CareRayDR::CheckConnection() { return false; } bool Detector_CareRayDR::ReConnectFPD() { CloseStatusMonitor(); return true; } bool Detector_CareRayDR::OpenRadAcquisition() { Info("---Begin Rad Acquisition Thread---"); m_bExitRadAcqStatus = false; if (nullptr == m_hRadAcquisitionThread) { unsigned uThreadId; _beginthreadex(NULL, 0, RadAcquisitionThread, this, 0, &uThreadId); m_hRadAcquisitionThread = OpenThread(THREAD_ALL_ACCESS, TRUE, uThreadId); } return true; } UINT Detector_CareRayDR::RadAcquisitionThread(LPVOID pParam) { Detector_CareRayDR* pCurrentPanelOpr = reinterpret_cast(pParam); if (pCurrentPanelOpr == nullptr) { Error("Query Acq Status Thread parameter error"); } pCurrentPanelOpr->PerformRadAcquisition(); pCurrentPanelOpr->CloseRadAcquisition(); return 0; } bool Detector_CareRayDR::PerformRadAcquisition() { Info("## PerformRadAcquisition ##"); int nRes = CR_OK; int nWaitPermissionHint = 0; Info("Call CrStartAcquisition"); Info("DetectorID: {$}, AppModeKey: {$}", m_nDetectorID, m_nAppModeKey); nRes = API_CrStartAcquisition(m_nDetectorID, m_nAppModeKey, 0); if (!TestError(nRes)) { Error("Failed to start Acquisition"); return false; } //if (m_nTriggerType != CR_RAD_SOFT_SYNC || m_nTriggerType != CR_RAD_AED_SYNC) //{ // StatusFeedback(EVT_STATUS_PANEL, PANEL_XWINDOW_ON); //} CrExpProgress progress; memset(&progress, 0, sizeof(progress)); bool bRepeatReady = false; bool bRepeatXWindowOn = false; bool bRepeatInit = false; bool bPromptPressHandSwitch = true; while (true) { if (m_nTriggerType != CR_RAD_AED_SYNC) { nRes = API_CrQueryAcquisitionStatus(m_nDetectorID, &progress); if (!TestError(nRes)) { Error("Query acquisition status failed"); break; } switch (progress.exposure_status) { case CR_EXP_ERROR: Error("Acquisition status: exposure error"); m_bExitRadAcqStatus = true; break; case CR_EXP_INIT: if (!bRepeatInit) { Info("Acquisition status: init"); bRepeatInit = true; } break; case CR_EXP_READY: if (!bRepeatReady) { StatusFeedback(EVT_STATUS_PANEL, PANEL_READY_EXP); Info("Acquisition status: ready"); bRepeatReady = true; } if (!bRepeatXWindowOn) { Info("Acquisition status: expose"); bRepeatXWindowOn = true; } case CR_EXP_WAIT_PERMISSION: if (m_nTriggerType == CrTrigType::CR_RAD_EXT_SYNC) { Info("Acquisition status: wait permission"); if (0 == nWaitPermissionHint) { nRes = API_CrPermitExposure(m_nDetectorID); Info("CrPermitExposure Result: {$}", nRes); if (nRes != CR_OK) { break; } nWaitPermissionHint++; } } break; case CR_EXP_PERMITTED: Info("Acquisition status: permitted"); break; case CR_EXP_EXPOSE: if (!bRepeatXWindowOn) { Info("Acquisition status: expose"); bRepeatXWindowOn = true; } break; case CR_EXP_COMPLETE: Info("Acquisition status: complete"); break; default: break; } if (progress.is_fetchable) { Info("Image Arrive"); if (m_nTriggerType == CR_RAD_SOFT_SYNC) { StatusFeedback(EVT_STATUS_PANEL, PANEL_XWINDOW_OFF); } StatusFeedback(EVT_STATUS_PANEL, PANEL_START_TRANSMIT); Info("## Get Image ##"); int ret = CR_OK; Info("Call CrGetNoHeaderImage, DetectorID: {$}, width: {$}, height: {$}", m_nDetectorID, m_nRawImgWidth, m_nRawImgHeight); ret = API_CrGetNoHeaderImage(m_nDetectorID, (char*)m_pImgBuffer, m_nRawImgHeight * m_nRawImgWidth * 2, 9000); if (!TestError(ret)) { Error("Get image raw data failed"); } if (m_bSaveRaw) { std::string strFileName = m_strWorkPath + "\\rawdata"; strFileName += "\\Image.raw"; std::filesystem::path file_path{ strFileName.c_str() }; std::ofstream file_stream(file_path, std::ios::binary); if (!file_stream.is_open()) { Error("Open Save File Failed"); } unsigned int nTempSize = m_nRawImgHeight * m_nRawImgWidth * 2; file_stream.write(reinterpret_cast(m_pImgBuffer), nTempSize); file_stream.close(); } DataFeedback(EVT_DATA_RAW_IMAGE, m_pImgBuffer); m_bExitRadAcqStatus = true; } if (m_bExitRadAcqStatus) { Info("Exit Rad Acq Status"); int nRes = CR_OK; Info("Call CrStopAcquisition"); nRes = API_CrStopAcquisition(m_nDetectorID); if (!TestError(nRes)) { Error("Stop Acquisition Failed"); } StatusFeedback(EVT_STATUS_PANEL, PANEL_STANDBY); break; } } else { nRes = API_CrQueryAcquisitionStatus(m_nDetectorID, &progress); if (!TestError(nRes)) { Error("Query acquisition status failed"); break; } if (CR_EXP_READY == progress.exposure_status) { if (bPromptPressHandSwitch) { Info("Press hand switch now!"); StatusFeedback(EVT_STATUS_PANEL, PANEL_READY_EXP); bPromptPressHandSwitch = false; } } else { if (!bPromptPressHandSwitch) { Info("Don't press hand switch now!"); bPromptPressHandSwitch = true; } } if (progress.is_fetchable) { Info("Radiographic image is available now"); StatusFeedback(EVT_STATUS_PANEL, PANEL_XWINDOW_ON); StatusFeedback(EVT_STATUS_PANEL, PANEL_START_TRANSMIT); Info("## Get Image ##"); int ret = CR_OK; Info("Call CrGetNoHeaderImage, DetectorID: {$}, width: {$}, height: {$}", m_nDetectorID, m_nRawImgWidth, m_nRawImgHeight); ret = API_CrGetNoHeaderImage(m_nDetectorID, (char*)m_pImgBuffer, m_nRawImgHeight * m_nRawImgWidth * 2, 9000); if (!TestError(ret)) { Error("Get image raw data failed"); } if (m_bSaveRaw) { std::string strFileName = m_strWorkPath + "\\rawdata"; strFileName += "\\Image.raw"; std::filesystem::path file_path{ strFileName.c_str() }; std::ofstream file_stream(file_path, std::ios::binary); if (!file_stream.is_open()) { Error("Open Save File Failed"); } unsigned int nTempSize = m_nRawImgHeight * m_nRawImgWidth * 2; file_stream.write(reinterpret_cast(m_pImgBuffer), nTempSize); file_stream.close(); } DataFeedback(EVT_DATA_RAW_IMAGE, m_pImgBuffer); m_bExitRadAcqStatus = true; } if (m_bExitRadAcqStatus) { Info("Exit Rad Acq Status"); int nRes = CR_OK; Info("Call CrStopAcquisition"); nRes = API_CrStopAcquisition(m_nDetectorID); if (!TestError(nRes)) { Error("Stop Acquisition Failed"); } StatusFeedback(EVT_STATUS_PANEL, PANEL_STANDBY); break; } } } SetEvent(m_hExitRadAcqStatus); Info("PerformRadAcquisition Over"); return true; } bool Detector_CareRayDR::CloseRadAcquisition() { m_bExitRadAcqStatus = true; DWORD dwResult = WaitForSingleObject(m_hExitRadAcqStatus, 1000); if (dwResult == WAIT_OBJECT_0) { Info("[Get ExitRadAcqStatus Event]"); } else if (dwResult == WAIT_TIMEOUT) { ::TerminateThread(m_hRadAcquisitionThread, 0); Warn("Kill QueryAcqStatus Thread"); } if (m_hExitRadAcqStatus != nullptr) { CloseHandle(m_hExitRadAcqStatus); m_hExitRadAcqStatus = nullptr; } m_hRadAcquisitionThread = nullptr; Info("---Exit Rad Acq Status Thread---"); return true; } bool Detector_CareRayDR::OpenDualEnergyAcquisition() { Info("---Begin DualEnergy Acquisition Thread---"); m_bExitDualAcqStatus = false; if (nullptr == m_hDualEnergyAcquisitionThread) { unsigned uThreadId; _beginthreadex(NULL, 0, DualEnergyAcquisitionThread, this, 0, &uThreadId); m_hDualEnergyAcquisitionThread = OpenThread(THREAD_ALL_ACCESS, TRUE, uThreadId); } return true; } UINT Detector_CareRayDR::DualEnergyAcquisitionThread(LPVOID pParam) { Detector_CareRayDR* pCurrentPanelOpr = reinterpret_cast(pParam); if (pCurrentPanelOpr == nullptr) { Error("Query Acq Status Thread parameter error"); } pCurrentPanelOpr->PerformDualEnergyAcquisition(); pCurrentPanelOpr->CloseDualEnergyAcquisition(); return 0; } bool Detector_CareRayDR::PerformDualEnergyAcquisition() { Info("[PerformDualEnergyAcquisition]"); int nDualEnergyExpNum = 0; int nDualEnergyExp = 0; m_bDualEnergyFirstExpEnableDone = false; m_bDualEnergySecondExpEnable = false; int nRet = CR_OK; int nWaitPermissionHint = 0; int nLoop = 0; int nDualFlag = 0; Info("Call CrStartAcquisition"); nRet = API_CrStartAcquisition(m_nDetectorID, m_nAppModeKey, 0); Info("m_nDetectorID: {$}, m_nAppModeKey: {$}", m_nDetectorID, m_nAppModeKey); if (!TestError(nRet)) { Error("Failed to start acquisition"); } CrExpProgress progress; memset(&progress, 0, sizeof(progress)); bool bRepeatReady = false; bool bRepeatXWindowOn = false; bool bRepeatInit = false; while (true) { nRet = API_CrQueryAcquisitionStatus(m_nDetectorID, &progress); if (!TestError(nRet)) { Error("Query acquisition status failed"); break; } switch (progress.exposure_status) { case CR_EXP_ERROR: Error("Acquisition status: exposure error"); m_bExitRadAcqStatus = true; case CR_EXP_INIT: if (!bRepeatInit) { Info("Acquisition status: init"); bRepeatInit = true; } break; case CR_EXP_READY: if (nDualEnergyExpNum == 0 && CR_RAD_SOFT_SYNC == m_nTriggerType) { Info("Detector is ready for dual energy Acquisition, press x-ray hand switch now..."); if (!bRepeatReady) { //StatusFeedback(EVT_STATUS_PANEL, PANEL_START_ACQ); //StatusFeedback(EVT_STATUS_PANEL, PANEL_READY_EXP); Info("Acquisition status: ready"); bRepeatReady = true; } nDualEnergyExpNum++; } break; case CR_EXP_EXPOSE: if (nDualEnergyExp == 0) { Info("exp expose"); Info("Status Polled >> Detector is in EXPOSE state, emit X-Ray now..."); StatusFeedback(EVT_STATUS_PANEL, PANEL_XWINDOW_ON); int nRes = CR_OK; nRes = API_CrRequestExposure(m_nDetectorID); if (!TestError(nRes)) { Error("RequestExposure Failed"); return false; } nDualEnergyExp++; nDualFlag++; nLoop = 0; } break; case CR_EXP_COMPLETE: if (nLoop < 1) { Info("exp complete"); bRepeatReady = false; StatusFeedback(EVT_STATUS_PANEL, PANEL_XWINDOW_OFF); nLoop++; } nDualEnergyExp = 0; break; default: break; } if (progress.is_fetchable && nDualFlag == 2) { Info("Image Arrive"); StatusFeedback(EVT_STATUS_PANEL, PANEL_START_TRANSMIT); for (size_t i = 0; i < 2; i++) { Info("Call CrGetNoHeaderImage, DetectorID: {$}, width:{$}, height: {$}", m_nDetectorID, m_nRawImgWidth, m_nRawImgHeight); nRet = API_CrGetNoHeaderImage(m_nDetectorID, (char*)m_pRawImgBuffer, m_nRawImgHeight * m_nRawImgWidth * 2, 9000); if (!TestError(nRet)) { Error("Get Image Raw Data Failed"); } if (m_bSaveRaw) { char szTemp[30] = { 0 }; std::string strFileName = m_strWorkPath + "\\rawdata"; sprintf_s(szTemp, "\\DualImage_%d.raw", i + 1); strFileName += szTemp; std::filesystem::path file_path{ strFileName.c_str() }; std::ofstream file_stream(file_path, std::ios::binary); if (!file_stream.is_open()) { Error("Open Save File Failed"); } unsigned int nTempSize = m_nRawImgHeight * m_nRawImgWidth * 2; file_stream.write(reinterpret_cast(m_pRawImgBuffer), nTempSize); file_stream.close(); } DataFeedback(EVT_DATA_RAW_IMAGE, m_pRawImgBuffer); if (i == 1) { m_bExitDualAcqStatus = true; } if (i == 0) { Sleep(5000); } } } if (m_bExitDualAcqStatus) { Info("Exit Dual Acq Status"); int nRes = CR_OK; Info("Call CrStopAcquisition"); nRes = API_CrStopAcquisition(m_nDetectorID); if (!TestError(nRes)) { Error("Stop Acquisition Failed"); } StatusFeedback(EVT_STATUS_PANEL, PANEL_STANDBY); break; } } SetEvent(m_hExitDualAcqStatus); Info("PerformDualAcquisition Over"); return true; } bool Detector_CareRayDR::CloseDualEnergyAcquisition() { m_bExitDualAcqStatus = true; DWORD dwResult = WaitForSingleObject(m_hExitDualAcqStatus, 1000); if (dwResult == WAIT_OBJECT_0) { Info("[Get ExitDualAcqStatus Event]"); } else if (dwResult == WAIT_TIMEOUT) { ::TerminateThread(m_hDualEnergyAcquisitionThread, 0); Warn("Kill DualEnergyAcquisition Thread"); } if (m_hExitDualAcqStatus != nullptr) { CloseHandle(m_hExitDualAcqStatus); m_hExitDualAcqStatus = nullptr; } m_hDualEnergyAcquisitionThread = nullptr; Info("---Exit Dual Acq Status Thread---"); return true; } /*** ** 等待探测器操作执行完毕 ***/ bool Detector_CareRayDR::WaitRespond(int nTimeOut, const char* szAction) { Info("--- WaitRespond({$}), {$}ms ---", szAction, nTimeOut); DWORD dwRet = WaitForSingleObject(m_hRespond, nTimeOut); if (dwRet == WAIT_TIMEOUT) { Error("time out in wait response, action:{$}", szAction); return false; } return true; } void Detector_CareRayDR::StopWaiting(const char* szAction) { Info("--- Stop waiting respond, {$} ---", szAction); SetEvent(m_hRespond); } /*** ** 检测接口是否有错误,true:有错;false:没错 ***/ bool Detector_CareRayDR::TestError(int nErrorCode) { if (nErrorCode == CR_OK) { return true; } else { std::string strLog; char szMsgBuf[256]; API_CrGetLastIntlMsg(szMsgBuf, 256); Info("ErrorCode : {$}, Description: {$}", nErrorCode, szMsgBuf); return false; } } void Detector_CareRayDR::ProcessCREvent(int eventID, CrEvent* eventData) { switch (eventID) { case CR_EVT_NEW_FRAME: Info("Flu Mode New Frame"); memcpy(m_pFluFrameData, (reinterpret_cast(eventData->data) + 256), m_nImageWidth * m_nImageHeight * 2); DataFeedback(EVT_DATA_RAW_IMAGE, m_pFluFrameData); break; case CR_EVT_CALIBRATION_IN_PROGRESS: { Info("Get CR_EVT_CALIBRATION_IN_PROGRESS"); CrCalibrationInfo* calib_info = reinterpret_cast(eventData->data); if (0 == calib_info->total_frame_num) { Info("Callback >> Calibration is in the PRECHECK state."); } else { Info("Callback >> calibration progress: {$} / {$}, current frame mean = {$}", calib_info->current_frame_num, calib_info->total_frame_num, calib_info->current_frame_mean); switch (calib_info->exposure_status) { case CR_EXP_READY: Info("Callback >> Now you can press x-ray hand switch..."); break; case CR_EXP_WAIT_PERMISSION: Info("Callback >> Detector is waiting for exposure permission..."); break; default: Info("Callback >> Now you can't press x-ray hand switch..."); break; } } break; } case CR_EVT_CALIBRATION_FINISHED: { Info("Get CR_EVT_CALIBRATION_FINISHED"); CrCalibrationInfo* calib_info = reinterpret_cast(eventData->data); Info("Calibration progress: {$} / {$}, current frame mean: {$}", calib_info->current_frame_num, calib_info->total_frame_num, calib_info->current_frame_mean); Info("Calibration result: {$}", calib_info->result); break; } case CR_EVT_ACQ_STAT_INFO: { CrAcquisitionStatInfo* stat_info = reinterpret_cast(eventData->data); Info("Total frame: {$}", stat_info->total_frame_num); break; } case CR_EVT_RAD_ACQ_IN_PROGRESS: Info("Get CR_EVT_RAD_ACQ_IN_PROGRESS"); break; case CR_EVT_DETR_DISCONNECTED: break; default: Error("not support current event ID:{$}", eventID); break; } } void Detector_CareRayDR::ConfFeedback(int nEventID, int nDetectorID, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam) { if (-1 == nDetectorID) { nDetectorID = m_nCurrentPanelID; } ((FPDDeviceCareRay*)(*m_pPanelID2DPC)[nDetectorID])->OnFPDCallback(nDetectorID, nEventID, EVT_LEVEL_CONFIGURATION, pszMsg, nParam1, fParam2, nPtrParamLen, pParam); } void Detector_CareRayDR::InfoFeedback(int nEventID, int nDetectorID, int nParam1, float fParam2, const char* pszMsg, int nPtrParamLen, void* pParam) { if (-1 == nDetectorID) { nDetectorID = m_nCurrentPanelID; } ((FPDDeviceCareRay*)(*m_pPanelID2DPC)[nDetectorID])->OnFPDCallback(nDetectorID, nEventID, EVT_LEVEL_INFORMATOION, pszMsg, nParam1, fParam2, nPtrParamLen, pParam); } void Detector_CareRayDR::StatusFeedback(int nEventID, int nParam1, const char* pszMsg, int nDetectorID, float fParam2, int nPtrParamLen, void* pParam) { if (-1 == nDetectorID) { nDetectorID = m_nCurrentPanelID; } ((FPDDeviceCareRay*)(*m_pPanelID2DPC)[nDetectorID])->OnFPDCallback(nDetectorID, nEventID, EVT_LEVEL_STATUS, pszMsg, nParam1, fParam2, nPtrParamLen, pParam); } void Detector_CareRayDR::DataFeedback(int nEventID, void* pParam, int nParam1, float fParam2, const char* pszMsg, int nPtrParamLen, int nDetectorID) { if (-1 == nDetectorID) { nDetectorID = m_nCurrentPanelID; } ((FPDDeviceCareRay*)(*m_pPanelID2DPC)[nDetectorID])->OnFPDCallback(nDetectorID, nEventID, EVT_LEVEL_DATA, pszMsg, nParam1, fParam2, nPtrParamLen, pParam); } void Detector_CareRayDR::WarnFeedback(int nEventID, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam, int nDetectorID) { if (-1 == nDetectorID) { nDetectorID = m_nCurrentPanelID; } ((FPDDeviceCareRay*)(*m_pPanelID2DPC)[nDetectorID])->OnFPDCallback(nDetectorID, nEventID, EVT_LEVEL_WARNING, pszMsg, nParam1, fParam2, nPtrParamLen, pParam); } void Detector_CareRayDR::ErrorFeedback(int nEventID, const char* pszMsg, int nDetectorID, int nParam1, float fParam2, int nPtrParamLen, void* pParam) { if (-1 == nDetectorID) { nDetectorID = m_nCurrentPanelID; } ((FPDDeviceCareRay*)(*m_pPanelID2DPC)[nDetectorID])->OnFPDCallback(nDetectorID, nEventID, EVT_LEVEL_ERROR, pszMsg, nParam1, fParam2, nPtrParamLen, pParam); }