12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534 |
- #include "stdafx.h"
- #include "Detector_CareRayDR.h"
- #include "CCOS.Dev.FPD.CareRayDR.h"
- #include "MyPingip.h"
- Detector_CareRayDR* g_pDetector = nullptr;
- extern Log4CPP::Logger* //mLog::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<FPDDeviceCareRay*, int>();
- m_pPanelID2DPC = new map<int, FPDDeviceCareRay*>();
- 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);
- //mLog::Info("--Func-- DriverEntry {$}", pDrvDPC);
- map<FPDDeviceCareRay*, int>::iterator DPCsIter = m_pDPC2PanelID->find(pDrvDPC);
- if (DPCsIter != m_pDPC2PanelID->end())
- {
- printf("This DPC already exist\n");
- //mLog::Error("This DPC already exist");
- return false;
- }
- CPanelStatus* p = new CPanelStatus();
- m_pStPanelStatus[m_nPanelCount] = p;
- m_pDPC2PanelID->insert(pair<FPDDeviceCareRay*, int>(pDrvDPC, m_nPanelCount));
- m_pPanelID2DPC->insert(pair<int, FPDDeviceCareRay*>(m_nPanelCount, pDrvDPC));
- m_nPanelCount++;
- m_ModeConfig = Configuration; //记录配置 --目前只有一个平板,多板时应该分别存储
- //mLog::Info("Config: {$}", m_ModeConfig.encode());
- return true;
- }
- bool Detector_CareRayDR::Connect(FPDDeviceCareRay* pDrvDPC, const char* szWorkPath)
- {
- //mLog::Info("Connect detector begin");
- printf("Connect detector begin \r\n");
- if ((*m_pDPC2PanelID)[pDrvDPC] != m_nCurrentPanelID)
- {
- //mLog::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);
- //mLog::Info("Connect over");
- printf("Connect over \r\n");
- return true;
- }
- bool Detector_CareRayDR::Disconnect()
- {
- int ret = CR_OK;
- //mLog::Info("Disconnect detector begin \r\n");
- SetEvent(m_hExitEvent); //关闭Scan线程
- DWORD result = WaitForSingleObject(m_hToggleEvent, 65000);
- if (result == WAIT_OBJECT_0)
- {
- //mLog::Info("Leave scan thread over");
- }
- else if (result == WAIT_TIMEOUT)
- {
- //mLog::Error("Till time out");
- }
- //mLog::Info("Call CrUnloadReference");
- ret = API_CrUnloadReference(m_nDetectorID, m_nAppModeKey);
- if (!TestError(ret))
- {
- //mLog::Error("Unload Calibration Data Failed");
- return false;
- }
- //mLog::Info("Call CrDisconnect");
- ret = API_CrDisconnect(m_nDetectorID);
- if (!TestError(ret))
- {
- //mLog::Error("disconnect detector fail!");
- return false;
- }
- //mLog::Info("Disconnect over");
- return true;
- }
- void Detector_CareRayDR::EnterExamMode(int nExamMode)
- {
- switch (nExamMode)
- {
- case APP_STATUS_WORK_BEGIN:
- //mLog::Info("Enter into Exam Windows");
- break;
- case APP_STATUS_WORK_END:
- //mLog::Info("Quit Exam Windows");
- break;
- case APP_STATUS_DETSHARE_BEGIN:
- //mLog::Info("Enter into Detector Share Windows");
- break;
- case APP_STATUS_DETSHAR_END:
- //mLog::Info("Quit Detector Share Windows");
- break;
- case APP_STATUS_CAL_BEGIN:
- //mLog::Info("Enter into Calibration Windows");
- break;
- case APP_STATUS_CAL_END:
- //mLog::Info("Quit Calibration Windows");
- break;
- case APP_STATUS_WORK_IN_SENSITIVITY:
- //mLog::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)
- {
- //mLog::Info("Detector_CareRayDR::SetAcqMode mode:{$}", nMode);
- //if (m_nCurrentLogicMode == nMode)
- //{
- // //mLog::Info("Same acq mode,return");
- // return true;
- //}
- if (!m_pStPanelStatus[m_nCurrentPanelID]->bConnectState)
- {
- //mLog::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"];
- //mLog::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"];
- //mLog::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)
- {
- //mLog::Error("Get config error: {$}", e.what());
- return false;
- }
- StatusFeedback(EVT_STATUS_PANEL, PANEL_SLEEP);
-
- return true;
- }
- bool Detector_CareRayDR::PrepareAcquisition(FPDDeviceCareRay* pDrvDPC)
- {
- //mLog::Info("PrepareAcquisition start");
- if ((*m_pDPC2PanelID)[pDrvDPC] != m_nCurrentPanelID)
- {
- printf("Not current DPC, return\n");
- //mLog::Error("Not current DPC, return");
- return false;
- }
- //未初始化、未连接 不执行
- if (!m_pStPanelStatus[m_nCurrentPanelID]->bConnectState)
- {
- //mLog::Error("Detector not connected, return");
- return false;
- }
- //mLog::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)
- {
- //mLog::Info("DDR use flu mode of Inner Trigger");
- //mLog::Info("Call CrStartAcquisition");
- nRet = API_CrStartAcquisition(m_nDetectorID, m_nAppModeKey, -1);
- if (!TestError(nRet))
- {
- //mLog::Error("Failed to start DDR acquisition");
- return false;
- }
- }
- }
- Sleep(5000);
- StatusFeedback(EVT_STATUS_PANEL, PANEL_STANDBY);
-
- //mLog::Info("PrepareAcquisition end");
- return true;
- }
- bool Detector_CareRayDR::StartAcquisition(FPDDeviceCareRay* pDrvDPC)
- {
- int nRes = CR_OK;
- //mLog::Info("StartAcquisition start");
- if ((*m_pDPC2PanelID)[pDrvDPC] != m_nCurrentPanelID)
- {
- printf("Not current DPC, return\n");
- //mLog::Error("Not current DPC, return");
- return false;
- }
- //未初始化、未连接 不执行
- if (!m_pStPanelStatus[m_nCurrentPanelID]->bConnectState)
- {
- //mLog::Error("Detector not connected, return");
- return false;
- }
- if (m_nCurrentLogicMode == AcqMode::RAD && m_nTriggerType == CrTrigType::CR_RAD_SOFT_SYNC)
- {
- //mLog::Info("Rad Soft Trigger RequestExposure!!!!");
- StatusFeedback(EVT_STATUS_PANEL, PANEL_XWINDOW_ON);
- nRes = API_CrRequestExposure(m_nDetectorID);
- if (!TestError(nRes))
- {
- //mLog::Error("RequestExposure Failed");
- }
- }
- if (m_nCurrentLogicMode == AcqMode::DUAL_ENERGY)
- {
- //mLog::Info("Dual Energy RequestExposure!!!");
- StatusFeedback(EVT_STATUS_PANEL, PANEL_START_ACQ);
- int nRes = CR_OK;
- nRes = API_CrRequestExposure(m_nDetectorID);
- if (!TestError(nRes))
- {
- //mLog::Error("RequestExposure Failed");
- return false;
- }
- //mLog::Info("RequestExposure Successed!!");
- }
- //mLog::Info("StartAcquisition end");
- return true;
- }
- bool Detector_CareRayDR::StopAcquisition(FPDDeviceCareRay* pDrvDPC)
- {
- if ((*m_pDPC2PanelID)[pDrvDPC] != m_nCurrentPanelID)
- {
- printf("Not current DPC, return\n");
- //mLog::Error("Not current DPC, return");
- return false;
- }
- if (!m_pStPanelStatus[m_nCurrentPanelID]->bConnectState)
- {
- //mLog::Error("Detector not connected, return");
- return false;
- }
- //mLog::Info("## Stop Acquisition ##");
- int nRet = CR_OK;
- //mLog::Info("Call CrStopAcquisition");
- nRet = API_CrStopAcquisition(m_nDetectorID);
- if (!TestError(nRet))
- {
- //mLog::Error("Stop Acquisition Failed");
- return false;
- }
- SetCareRayDPCStatus(eDetStatus::DetStatus_Standby); //停止采集
- return true;
- }
- bool Detector_CareRayDR::RequestXray(FPDDeviceCareRay* pDrvDPC)
- {
- //mLog::Info("Dual Energy Request Exposure!!");
- int nRes = CR_OK;
- nRes = API_CrRequestExposure(m_nDetectorID);
- if (!TestError(nRes))
- {
- //mLog::Error("RequestExposure Failed");
- return false;
- }
- //mLog::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");
- //mLog::Error("Not current DPC, return");
- return false;
- }
- if (!m_pStPanelStatus[m_nCurrentPanelID]->bConnectState)
- {
- //mLog::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)
- {
- //mLog::Info("Active Dark Calibration");
- }
- if (CCOS_CALIBRATION_TYPE_XRAY == m_eCaliType)
- {
- //mLog::Info("Active Xray Calibration");
- if (m_nCalibrationMode) //厂商校正
- {
- }
- else //ZSKK校正
- {
- if (!m_pZSKKCalib)
- {
- //mLog::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);
- //mLog::Info("Load ZSKK Gain map success!");
- //mLog::Info("references file path: {$}", m_pZSKKCalib->m_strRefFilePath);
- }
- }
- }
- return true;
- }
- /***
- * 接受曝光图像
- ***/
- bool Detector_CareRayDR::AcceptCalibration()
- {
- //mLog::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()
- {
- //mLog::Info("Reject calibration exposure result");
- return true;
- }
- /***
- * 设置校正轮数
- ***/
- bool Detector_CareRayDR::SetCalibRounds(int nCalibRounds)
- {
- m_nCalibrationRounds = nCalibRounds;
- //mLog::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;
- //mLog::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");
- //mLog::Error("Not current DPC, return");
- return false;
- }
- if (!m_pStPanelStatus[m_nCurrentPanelID]->bConnectState)
- {
- //mLog::Error("Detector not connected, return");
- return false;
- }
- if (CCOS_CALIBRATION_TYPE_DARK == m_eCaliType)
- {
- //mLog::Info("PrepareCalibration CCOS_CALIBRATION_TYPE_DARK == m_eCaliType");
- //由于前端没有测试过暗场校正上图的情况,故此处不进行暗场上图
- //DarkAcquisition();
- }
- else if (CCOS_CALIBRATION_TYPE_XRAY == m_eCaliType)
- {
- //mLog::Info("PrepareCalibration CCOS_CALIBRATION_TYPE_XRAY == m_eCaliType");
- SetCareRayDPCStatus(eDetStatus::DetStatus_Standby);
- bool ret = PrepareAcquisition(pDrvDPC);
- if (ret)
- {
- //mLog::Info("PrepareCalibration PrepareAcquisition success!");
- }
- else
- {
- //mLog::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");
- //mLog::Error("Not current DPC, return");
- return false;
- }
- //未初始化、未连接 不执行
- if (!m_pStPanelStatus[m_nCurrentPanelID]->bConnectState)
- {
- //mLog::Error("Detector not connected, return");
- return false;
- }
- if (CCOS_CALIBRATION_TYPE_DARK == m_eCaliType)
- {
- //SetEvent(m_hDarkEvent);
- //mLog::Info("StartCalibration DARK");
- OnProcessDarkEnd();
- }
- else if (CCOS_CALIBRATION_TYPE_XRAY == m_eCaliType)
- {
- //mLog::Info("StartCalibration XRAY");
- SetEvent(m_hRadEvent); //StartCalibration
- }
- return true;
- }
- /***
- ** 说明:处理dark校正完成流程
- ***/
- void Detector_CareRayDR::OnProcessDarkEnd()
- {
- //mLog::Info("Refresh offset over");
- StatusFeedback(EVT_STATUS_CALIBRATIOIN, PANEL_EVENT_END_OK);
- }
- /***
- ** 说明:终止校正
- ***/
- RET_STATUS Detector_CareRayDR::AbortCalibration(FPDDeviceCareRay* pDrvDPC)
- {
- //mLog::Info("AbortCalibration");
- printf("AbortCalibration\n");
- m_eCaliType = CCOS_CALIBRATION_TYPE_NONE; //恢复初值
- RET_STATUS Ret = RET_STATUS::RET_FAILED;
- if (m_nCalibrationMode) //厂商校正
- {
- }
- else
- {
- //mLog::Info("Abort ZSKK calibration");
- m_pZSKKCalib->LoadZSKKGainMap(true, m_strDetectorType); //重新加载增益校正文件
- m_pZSKKCalib->AbortZSKKPixMap(m_strDetectorType); //放弃坏点校正并重新加载原来的坏点校正文件
- }
- //mLog::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");
- //mLog::Error("Not current DPC, return");
- return false;
- }
- if (!m_pStPanelStatus[m_nCurrentPanelID]->bConnectState)
- {
- //mLog::Error("Detector not connected, return");
- return false;
- }
- //mLog::Info("StopCalibration StopAcquisition");
- if (!StopAcquisition(pDrvDPC))
- {
- //mLog::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)
- {
- //mLog::Info("CompleteCalibration calib type {$}", (int)m_eCaliType);
- if (m_eCaliType == CCOS_CALIBRATION_TYPE_DARK)
- {
- printf("DARK DARK Calib over \r\n");
- //mLog::Info("DARK Calib over");
- }
- else if (m_eCaliType == CCOS_CALIBRATION_TYPE_XRAY)
- {
- printf("XRAY Calib over \r\n");
- //mLog::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()
- {
- //mLog::Info("Save Calibration File");
- if (m_nCalibrationMode)//厂商校正
- {
- //不做处理
- }
- else
- {
- //mLog::Info("Save ZSKK Calibration File");
- m_pZSKKCalib->StoreZSKKGainMap(m_strDetectorType);
- m_pZSKKCalib->StoreZSKKPixMap(m_strDetectorType);
- }
- //更新配置文件中校正日期和时间
- SYSTEMTIME stCurrentTime = { 0 };
- GetLocalTime(&stCurrentTime);
- //mLog::Info("Current time: {$04d}/{$02d}/{$02d} {$02d}:{$02d}:{$02d}:{$03d}",
- stCurrentTime.wYear, stCurrentTime.wMonth, stCurrentTime.wDay,
- stCurrentTime.wHour, stCurrentTime.wMinute, stCurrentTime.wSecond, stCurrentTime.wMilliseconds);
- //mLog::Info("Save Calibration File over");
- return true;
- }
- CCOS_CALIBRATION_TYPE Detector_CareRayDR::GetCalibType()
- {
- //mLog::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)
- {
- //mLog::Info("Start Load CareRay DLL");
- string strSDKPath = "";
- try
- {
- strSDKPath = (string)m_ModeConfig["SDKPath"];
- }
- catch (ResDataObjectExption& e)
- {
- //mLog::Error("Read configuration failed! reason: {$}", e.what());
- return false;
- }
- string workpath = strWorkPath + strSDKPath;
- string drvpath = workpath + "\\CareRayApi.dll";
- //mLog::Info("SDK path:{$}", drvpath);
- SetDllDirectory(workpath.c_str());
- m_hCareRayDRModule = LoadLibrary(drvpath.c_str());
- if (m_hCareRayDRModule == nullptr)
- {
- DWORD dw = GetLastError();
- //mLog::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);
- //mLog::Info("Load CareRay API end");
- return true;
- }
- bool Detector_CareRayDR::ReleaseDll()
- {
- //mLog::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()
- {
- //mLog::Info("OpenDetector start");
- int nRet = -1;
- CrDetrIdxAndIPAddr DetectorArray[8];
- int nValidDetectorNum = 0;
- int nActiveDetectorID = 0;
- //mLog::Info("Call CrGetDetectorIndexAndIPAddress");
- nRet = API_CrGetDetectorIndexAndIPAddress(DetectorArray, &nValidDetectorNum);
- if (!TestError(nRet))
- {
- //mLog::Error("Get detector index and IP address failed");
- }
- if (nValidDetectorNum <= 0)
- {
- //mLog::Info("System did not found detector");
- }
- //mLog::Info("System found detector number: {$}", nValidDetectorNum);
- m_nDetectorID = DetectorArray[0].index;
- //mLog::Info("DetectorArray[0].index : {$}", m_nDetectorID);
- int nDetectorIndex = m_nDetectorID - 1;
- //mLog::Info("API get detector number: {$}", nValidDetectorNum);
- //mLog::Info("Call CrConnect");
- nRet = API_CrConnect(m_nDetectorID);
- if (!TestError(nRet))
- {
- //mLog::Error("Connect Failed");
- return false;
- }
- m_pStPanelStatus[m_nCurrentPanelID]->bConnectState = true;
- //mLog::Info("m_pStPanelStatus[m_nCurrentPanelID]->bConnectState = true");
- StatusFeedback(EVT_STATUS_PANEL, PANEL_CONNECT);
-
- //mLog::Info("Connect detector({$}) success", m_nDetectorID);
- CrSystemInfo stSystemInfo;
- //mLog::Info("Call CrGetSystemInformation");
- nRet = API_CrGetSystemInformation(m_nDetectorID, &stSystemInfo);
- if (!TestError(nRet))
- {
- //mLog::Info("Get Detector Information Failed");
- }
- //mLog::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;
- //mLog::Info("Call CrGetApplicationMode");
- nRet = API_CrGetApplicationMode(m_nDetectorID, AppModeInfo, &nModeNum);
- if (!TestError(nRet))
- {
- //mLog::Error("Load Application Mode Failed");
- }
- for (int i = 0; i < nModeNum; i++)
- {
- //mLog::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);
- //mLog::Info("OpenDetector end");
- return true;
- }
- /***
- ** 初始化探测器
- ***/
- bool Detector_CareRayDR::InitDetector()
- {
- //mLog::Info("InitDetector start");
- int nRet = -1;
- //初始化时先reset,恢复缺省状态
- //mLog::Info("Call reset detector");
- nRet = API_CrResetDetector(m_nDetectorID, false);
- if (!TestError(nRet))
- {
- //mLog::Error("Reset detector failed");
- }
- //获取实际的探测器类型
- //mLog::Info("Call get detector type");
- //连接上探测器后获取gain校正曝光的总次数
- m_nGainExposureNum = ((FPDDeviceCareRay*)(*m_pPanelID2DPC)[m_nCurrentPanelID])->GetGainExposureNum();
- //mLog::Info("Gain Exposure Num:{$}", m_nGainExposureNum);
- m_bOnlyHaveFpd = ((FPDDeviceCareRay*)(*m_pPanelID2DPC)[m_nCurrentPanelID])->GetOnlyHaveFpd();
- if (m_bOnlyHaveFpd)
- {
- //mLog::Info("Current system only have FPD other is demo!");
- }
- //mLog::Info("InitDetector end");
- return true;
- }
- bool Detector_CareRayDR::OpenStatusMonitor()
- {
- //mLog::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)
- {
- //mLog::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:
- //mLog::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)
- {
- //mLog::Error("Detector not connected, return");
- ErrorFeedback(EVT_ERR_COMMUNICATE, "true");
- return false;
- }
- CrConnectionStatus stConnectionStatus;
- ret = API_CrGetConnectionStatus(m_nDetectorID, &stConnectionStatus);
- if (!TestError(ret))
- {
- //mLog::Warn("Get Detector connection status failed");
- }
- CrDetrStatus stDetectorStatus;
- ret = API_CrGetDetrStatus(m_nDetectorID, &stDetectorStatus);
- if (!TestError(ret))
- {
- //mLog::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))
- {
- //mLog::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))
- {
- //mLog::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);
- //mLog::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;
- //mLog::Info("---Close Status Monitor Thread---");
- return true;
- }
- bool Detector_CareRayDR::CloseDetectorScan()
- {
- SetEvent(m_hExitEvent);
- DWORD dwResult = WaitForSingleObject(m_hDetectorScanToggleEvnet, 65000);
- if (WAIT_TIMEOUT == dwResult)
- {
- //mLog::Error("Exit Scan Thread Failed. Time Out!");
- }
- else if (WAIT_OBJECT_0 == dwResult)
- {
- //mLog::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;
- //mLog::Info("Call CrGetModeInfoByAppModeKey");
- ret = API_CrGetModeInfoByAppModeKey(m_nDetectorID, m_nAppModeKey, AppModeInfo);
- if (!TestError(ret))
- {
- //mLog::Error("Load application mode by key({$}) failed", m_nAppModeKey);
- return false;
- }
- //mLog::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()
- {
- //mLog::Info("SetApplicationMode");
- int ret = CR_OK;
- //mLog::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);
- //mLog::Info("Call CrStopAcquisition");
- ret = API_CrStopAcquisition(m_nDetectorID);
- if (!TestError(ret))
- {
- //mLog::Error("Stop Acquisition Failed");
- return false;
- }
- //mLog::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))
- {
- //mLog::Error("Register application mode failed");
- return false;
- }
- //mLog::Info("Register application mode successful");
- return true;
- }
- bool Detector_CareRayDR::LoadCalibrationFiles()
- {
- //mLog::Info("## LoadCalibrationFiles ##");
- int ret = CR_OK;
- //mLog::Info("Call CrLoadReference");
- ret = API_CrLoadReference(m_nDetectorID, m_nAppModeKey);
- if (!TestError(ret))
- {
- //mLog::Error("Load Reference failed");
- return false;
- }
- return true;
- }
- unsigned __stdcall Detector_CareRayDR::onFPDScanThread(PVOID pvoid)
- {
- Detector_CareRayDR* pOpr = (Detector_CareRayDR*)pvoid;
- //mLog::Info("Enter scan thread");
- printf("Enter scan thread \r\n");
- bool bExit = false;
- DWORD dwTimeOut = INFINITE;
- while (!bExit)
- {
- ////mLog::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
- {
- //mLog::Info("[Get Rad Event]");
- pOpr->OpenRadAcquisition();
- }
- else if (WAIT_OBJECT_0 + 5 == dwRet) //m_hDualEnergyEvent
- {
- //mLog::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);
- //mLog::Info("Leave scan thread");
- printf("Leave scan thread \r\n");
- return 0;
- }
- void Detector_CareRayDR::OnStartDarkCalibration()
- {
- //mLog::Info("dark calibration start");
-
- int nRet = -1;
- //mLog::Info("Call stop cal procedure(FALSE)");
-
- //mLog::Info("dark calibration end");
- }
- void Detector_CareRayDR::OnAcquireGainImage()
- {
- //mLog::Info("OnAcquireGainImage start");
- //mLog::Info("OnAcquireGainImage end");
- }
- void Detector_CareRayDR::OnProcessInitFPD()
- {
- int ret;
- //mLog::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;
- }
-
- //mLog::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");
- //mLog::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);
- }
- //mLog::Info("OnProcessInitFPD end");
- }
- void Detector_CareRayDR::OnReconnectFPD()
- {
- //mLog::Info("OnReconnectFPD start");
- //初始化完成后
- if (!m_pStPanelStatus[m_nCurrentPanelID]->bInitOver)
- {
- string strIP = "";
- try
- {
- strIP = (string)m_ModeConfig["connections"]["WiredIP"];
- }
- catch (ResDataObjectExption& e)
- {
- //mLog::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); //重新初始化时连接失败
- }
- }
- }
- //mLog::Info("OnReconnectFPD end");
- }
- /***
- ** 获取一帧暗场图
- ***/
- int Detector_CareRayDR::DarkAcquisition()
- {
- int nRet = -1;
- int printOver = 0, awaitOver = 0;
-
- //mLog::Info("Call set normal power");
-
- return nRet;
- }
- /***
- ** 轮询Manual(SDK的半aed模式)、aed模式采集状态
- ***/
- int Detector_CareRayDR::QueryAutoProgInfo(bool bIsAED)
- {
- //mLog::Info("Begin query auto exposure progress info");
-
- return CR_NO_ERR;
- }
- /***
- ** 轮询硬同步模式采集状态
- ***/
- int Detector_CareRayDR::QueryRadProgInfo()
- {
- //mLog::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";
- }
- //mLog::Info("image file name:{$}", strFileName);
- if ((fp = fopen(strFileName.c_str(), "wb")) == NULL)
- {
- DWORD dw = GetLastError();
- //mLog::Error("fopen {$} failed, error code:{$}", strFileName, dw);
- return;
- }
- fwrite(pInImg, sizeof(WORD), (size_t)nImgWidth * (size_t)nImgHeight, fp);
- fclose(fp);
- //mLog::Info("Save image over");
- }
- /***
- ** 裁剪图像
- ** pOutImg: 裁剪后图像; pInImg: 裁剪前图像; nInWidth: 裁剪前图像宽度
- ***/
- bool Detector_CareRayDR::GetEffectiveImage(WORD* pOutImg, WORD* pInImg, int nInWidth)
- {
- if (pOutImg == NULL || pInImg == NULL || nInWidth < 0)
- {
- //mLog::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 (...)
- {
- //mLog::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;
- }
- //mLog::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;
- //mLog::Info("Set driver status: {$}", strStatus.c_str());
- }
- else
- {
- //mLog::Error("{$} {$} is a illegal status", strStatus, (int)status);
- }
- return bSetStatus;
- }
- bool Detector_CareRayDR::IsConnected(string strIP)
- {
- //mLog::Info("Check ping {$}", strIP);
- CMyPingip obPingIp;
- //StatusFeedback(EVT_STATUS_PING, 0, "true");
- if (!obPingIp.PingFunction(strIP.c_str()))
- {
- //mLog::Info("ping {$} Failed", strIP);
- //StatusFeedback(EVT_STATUS_PING, 0, "false");
- return false;
- }
- return true;
- }
- bool Detector_CareRayDR::GetTriggerType(int nTriggerModeID)
- {
- //mLog::Info("Get TriggerType");
- switch (nTriggerModeID)
- {
- case 0:
- m_nTriggerType = CrTrigType::CR_RAD_MANUAL_SYNC;
- //mLog::Info("TriggerType is CR_RAD_MANUAL_SYNC");
- break;
- case 1:
- m_nTriggerType = CrTrigType::CR_RAD_SOFT_SYNC;
- //mLog::Info("TriggerType is CR_RAD_SOFT_SYNC");
- break;
- case 2:
- m_nTriggerType = CrTrigType::CR_RAD_EXT_SYNC;
- //mLog::Info("TriggerType is CR_RAD_EXT_SYNC");
- break;
- case 3:
- m_nTriggerType = CrTrigType::CR_RAD_AED_SYNC;
- //mLog::Info("TriggerType is CR_RAD_AED_SYNC");
- break;
- case 4:
- m_nTriggerType = CrTrigType::CR_RAD_AUTO_SYNC;
- //mLog::Info("TriggerType is CR_RAD_AUTO_SYNC");
- break;
- case 5:
- m_nTriggerType = CrTrigType::CR_RAD_DAEC_SYNC;
- //mLog::Info("TriggerType is CR_RAD_DAEC_SYNC");
- break;
- case 6:
- m_nTriggerType = CrTrigType::CR_RAD_DAEC_FLIP_SYNC;
- //mLog::Info("TriggerType is CR_RAD_DAEC_FLIP_SYNC");
- break;
- case 7:
- m_nTriggerType = CrTrigType::CR_FLUORO_EXT_SYNC;
- //mLog::Info("TriggerType is CR_FLUORO_EXT_SYNC");
- break;
- case 8:
- m_nTriggerType = CrTrigType::CR_FLUORO_INT_SYNC;
- //mLog::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()
- {
- //mLog::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<Detector_CareRayDR*>(pParam);
- if (pCurrentPanelOpr == nullptr)
- {
- //mLog::Error("Query Acq Status Thread parameter error");
- }
- pCurrentPanelOpr->PerformRadAcquisition();
- pCurrentPanelOpr->CloseRadAcquisition();
- return 0;
- }
- bool Detector_CareRayDR::PerformRadAcquisition()
- {
- //mLog::Info("## PerformRadAcquisition ##");
- int nRes = CR_OK;
- int nWaitPermissionHint = 0;
- //mLog::Info("Call CrStartAcquisition");
- //mLog::Info("DetectorID: {$}, AppModeKey: {$}", m_nDetectorID, m_nAppModeKey);
- nRes = API_CrStartAcquisition(m_nDetectorID, m_nAppModeKey, 0);
- if (!TestError(nRes))
- {
- //mLog::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))
- {
- //mLog::Error("Query acquisition status failed");
- break;
- }
- switch (progress.exposure_status)
- {
- case CR_EXP_ERROR:
- //mLog::Error("Acquisition status: exposure error");
- m_bExitRadAcqStatus = true;
- break;
- case CR_EXP_INIT:
- if (!bRepeatInit)
- {
- //mLog::Info("Acquisition status: init");
- bRepeatInit = true;
- }
- break;
- case CR_EXP_READY:
- if (!bRepeatReady)
- {
- StatusFeedback(EVT_STATUS_PANEL, PANEL_READY_EXP);
- //mLog::Info("Acquisition status: ready");
- bRepeatReady = true;
- }
- if (!bRepeatXWindowOn)
- {
- //mLog::Info("Acquisition status: expose");
- bRepeatXWindowOn = true;
- }
- case CR_EXP_WAIT_PERMISSION:
- if (m_nTriggerType == CrTrigType::CR_RAD_EXT_SYNC)
- {
- //mLog::Info("Acquisition status: wait permission");
- if (0 == nWaitPermissionHint)
- {
- nRes = API_CrPermitExposure(m_nDetectorID);
- //mLog::Info("CrPermitExposure Result: {$}", nRes);
- if (nRes != CR_OK)
- {
- break;
- }
- nWaitPermissionHint++;
- }
- }
- break;
- case CR_EXP_PERMITTED:
- //mLog::Info("Acquisition status: permitted");
- break;
- case CR_EXP_EXPOSE:
- if (!bRepeatXWindowOn)
- {
- //mLog::Info("Acquisition status: expose");
- bRepeatXWindowOn = true;
- }
- break;
- case CR_EXP_COMPLETE:
- //mLog::Info("Acquisition status: complete");
- break;
- default:
- break;
- }
- if (progress.is_fetchable)
- {
- //mLog::Info("Image Arrive");
- if (m_nTriggerType == CR_RAD_SOFT_SYNC)
- {
- StatusFeedback(EVT_STATUS_PANEL, PANEL_XWINDOW_OFF);
- }
- StatusFeedback(EVT_STATUS_PANEL, PANEL_START_TRANSMIT);
- //mLog::Info("## Get Image ##");
- int ret = CR_OK;
- //mLog::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))
- {
- //mLog::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())
- {
- //mLog::Error("Open Save File Failed");
- }
- unsigned int nTempSize = m_nRawImgHeight * m_nRawImgWidth * 2;
- file_stream.write(reinterpret_cast<const char*>(m_pImgBuffer), nTempSize);
- file_stream.close();
- }
- DataFeedback(EVT_DATA_RAW_IMAGE, m_pImgBuffer);
- m_bExitRadAcqStatus = true;
- }
- if (m_bExitRadAcqStatus)
- {
- //mLog::Info("Exit Rad Acq Status");
- int nRes = CR_OK;
- //mLog::Info("Call CrStopAcquisition");
- nRes = API_CrStopAcquisition(m_nDetectorID);
- if (!TestError(nRes))
- {
- //mLog::Error("Stop Acquisition Failed");
- }
- StatusFeedback(EVT_STATUS_PANEL, PANEL_STANDBY);
- break;
- }
- }
- else
- {
- nRes = API_CrQueryAcquisitionStatus(m_nDetectorID, &progress);
- if (!TestError(nRes))
- {
- //mLog::Error("Query acquisition status failed");
- break;
- }
- if (CR_EXP_READY == progress.exposure_status)
- {
- if (bPromptPressHandSwitch)
- {
- //mLog::Info("Press hand switch now!");
- StatusFeedback(EVT_STATUS_PANEL, PANEL_READY_EXP);
- bPromptPressHandSwitch = false;
- }
- }
- else
- {
- if (!bPromptPressHandSwitch)
- {
- //mLog::Info("Don't press hand switch now!");
- bPromptPressHandSwitch = true;
- }
- }
- if (progress.is_fetchable)
- {
- //mLog::Info("Radiographic image is available now");
- StatusFeedback(EVT_STATUS_PANEL, PANEL_XWINDOW_ON);
- StatusFeedback(EVT_STATUS_PANEL, PANEL_START_TRANSMIT);
- //mLog::Info("## Get Image ##");
- int ret = CR_OK;
- //mLog::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))
- {
- //mLog::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())
- {
- //mLog::Error("Open Save File Failed");
- }
- unsigned int nTempSize = m_nRawImgHeight * m_nRawImgWidth * 2;
- file_stream.write(reinterpret_cast<const char*>(m_pImgBuffer), nTempSize);
- file_stream.close();
- }
- DataFeedback(EVT_DATA_RAW_IMAGE, m_pImgBuffer);
- m_bExitRadAcqStatus = true;
- }
- if (m_bExitRadAcqStatus)
- {
- //mLog::Info("Exit Rad Acq Status");
- int nRes = CR_OK;
- //mLog::Info("Call CrStopAcquisition");
- nRes = API_CrStopAcquisition(m_nDetectorID);
- if (!TestError(nRes))
- {
- //mLog::Error("Stop Acquisition Failed");
- }
- StatusFeedback(EVT_STATUS_PANEL, PANEL_STANDBY);
- break;
- }
- }
- }
- SetEvent(m_hExitRadAcqStatus);
- //mLog::Info("PerformRadAcquisition Over");
-
- return true;
- }
- bool Detector_CareRayDR::CloseRadAcquisition()
- {
- m_bExitRadAcqStatus = true;
- DWORD dwResult = WaitForSingleObject(m_hExitRadAcqStatus, 1000);
- if (dwResult == WAIT_OBJECT_0)
- {
- //mLog::Info("[Get ExitRadAcqStatus Event]");
- }
- else if (dwResult == WAIT_TIMEOUT)
- {
- ::TerminateThread(m_hRadAcquisitionThread, 0);
- //mLog::Warn("Kill QueryAcqStatus Thread");
- }
- if (m_hExitRadAcqStatus != nullptr)
- {
- CloseHandle(m_hExitRadAcqStatus);
- m_hExitRadAcqStatus = nullptr;
- }
- m_hRadAcquisitionThread = nullptr;
- //mLog::Info("---Exit Rad Acq Status Thread---");
- return true;
- }
- bool Detector_CareRayDR::OpenDualEnergyAcquisition()
- {
- //mLog::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<Detector_CareRayDR*>(pParam);
- if (pCurrentPanelOpr == nullptr)
- {
- //mLog::Error("Query Acq Status Thread parameter error");
- }
- pCurrentPanelOpr->PerformDualEnergyAcquisition();
- pCurrentPanelOpr->CloseDualEnergyAcquisition();
- return 0;
- }
- bool Detector_CareRayDR::PerformDualEnergyAcquisition()
- {
- //mLog::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;
- //mLog::Info("Call CrStartAcquisition");
- nRet = API_CrStartAcquisition(m_nDetectorID, m_nAppModeKey, 0);
- //mLog::Info("m_nDetectorID: {$}, m_nAppModeKey: {$}", m_nDetectorID, m_nAppModeKey);
- if (!TestError(nRet))
- {
- //mLog::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))
- {
- //mLog::Error("Query acquisition status failed");
- break;
- }
- switch (progress.exposure_status)
- {
- case CR_EXP_ERROR:
- //mLog::Error("Acquisition status: exposure error");
- m_bExitRadAcqStatus = true;
- case CR_EXP_INIT:
- if (!bRepeatInit)
- {
- //mLog::Info("Acquisition status: init");
- bRepeatInit = true;
- }
- break;
- case CR_EXP_READY:
- if (nDualEnergyExpNum == 0 && CR_RAD_SOFT_SYNC == m_nTriggerType)
- {
- //mLog::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);
- //mLog::Info("Acquisition status: ready");
- bRepeatReady = true;
- }
- nDualEnergyExpNum++;
- }
- break;
- case CR_EXP_EXPOSE:
- if (nDualEnergyExp == 0)
- {
- //mLog::Info("exp expose");
- //mLog::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))
- {
- //mLog::Error("RequestExposure Failed");
- return false;
- }
- nDualEnergyExp++;
- nDualFlag++;
- nLoop = 0;
- }
- break;
- case CR_EXP_COMPLETE:
- if (nLoop < 1)
- {
- //mLog::Info("exp complete");
- bRepeatReady = false;
- StatusFeedback(EVT_STATUS_PANEL, PANEL_XWINDOW_OFF);
- nLoop++;
- }
- nDualEnergyExp = 0;
- break;
- default:
- break;
- }
- if (progress.is_fetchable && nDualFlag == 2)
- {
- //mLog::Info("Image Arrive");
- StatusFeedback(EVT_STATUS_PANEL, PANEL_START_TRANSMIT);
- for (size_t i = 0; i < 2; i++)
- {
- //mLog::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))
- {
- //mLog::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())
- {
- //mLog::Error("Open Save File Failed");
- }
- unsigned int nTempSize = m_nRawImgHeight * m_nRawImgWidth * 2;
- file_stream.write(reinterpret_cast<const char*>(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)
- {
- //mLog::Info("Exit Dual Acq Status");
- int nRes = CR_OK;
- //mLog::Info("Call CrStopAcquisition");
- nRes = API_CrStopAcquisition(m_nDetectorID);
- if (!TestError(nRes))
- {
- //mLog::Error("Stop Acquisition Failed");
- }
- StatusFeedback(EVT_STATUS_PANEL, PANEL_STANDBY);
- break;
- }
- }
- SetEvent(m_hExitDualAcqStatus);
- //mLog::Info("PerformDualAcquisition Over");
- return true;
- }
- bool Detector_CareRayDR::CloseDualEnergyAcquisition()
- {
- m_bExitDualAcqStatus = true;
- DWORD dwResult = WaitForSingleObject(m_hExitDualAcqStatus, 1000);
- if (dwResult == WAIT_OBJECT_0)
- {
- //mLog::Info("[Get ExitDualAcqStatus Event]");
- }
- else if (dwResult == WAIT_TIMEOUT)
- {
- ::TerminateThread(m_hDualEnergyAcquisitionThread, 0);
- //mLog::Warn("Kill DualEnergyAcquisition Thread");
- }
- if (m_hExitDualAcqStatus != nullptr)
- {
- CloseHandle(m_hExitDualAcqStatus);
- m_hExitDualAcqStatus = nullptr;
- }
- m_hDualEnergyAcquisitionThread = nullptr;
- //mLog::Info("---Exit Dual Acq Status Thread---");
- return true;
- }
- /***
- ** 等待探测器操作执行完毕
- ***/
- bool Detector_CareRayDR::WaitRespond(int nTimeOut, const char* szAction)
- {
- //mLog::Info("--- WaitRespond({$}), {$}ms ---", szAction, nTimeOut);
- DWORD dwRet = WaitForSingleObject(m_hRespond, nTimeOut);
- if (dwRet == WAIT_TIMEOUT)
- {
- //mLog::Error("time out in wait response, action:{$}", szAction);
- return false;
- }
- return true;
- }
- void Detector_CareRayDR::StopWaiting(const char* szAction)
- {
- //mLog::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);
- //mLog::Info("ErrorCode : {$}, Description: {$}", nErrorCode, szMsgBuf);
- return false;
- }
- }
- void Detector_CareRayDR::ProcessCREvent(int eventID, CrEvent* eventData)
- {
- switch (eventID)
- {
- case CR_EVT_NEW_FRAME:
- //mLog::Info("Flu Mode New Frame");
- memcpy(m_pFluFrameData, (reinterpret_cast<char*>(eventData->data) + 256), m_nImageWidth * m_nImageHeight * 2);
- DataFeedback(EVT_DATA_RAW_IMAGE, m_pFluFrameData);
- break;
- case CR_EVT_CALIBRATION_IN_PROGRESS:
- {
- //mLog::Info("Get CR_EVT_CALIBRATION_IN_PROGRESS");
- CrCalibrationInfo* calib_info = reinterpret_cast<CrCalibrationInfo*>(eventData->data);
- if (0 == calib_info->total_frame_num)
- {
- //mLog::Info("Callback >> Calibration is in the PRECHECK state.");
- }
- else
- {
- //mLog::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:
- //mLog::Info("Callback >> Now you can press x-ray hand switch...");
- break;
- case CR_EXP_WAIT_PERMISSION:
- //mLog::Info("Callback >> Detector is waiting for exposure permission...");
- break;
- default:
- //mLog::Info("Callback >> Now you can't press x-ray hand switch...");
- break;
- }
- }
- break;
- }
- case CR_EVT_CALIBRATION_FINISHED:
- {
- //mLog::Info("Get CR_EVT_CALIBRATION_FINISHED");
- CrCalibrationInfo* calib_info = reinterpret_cast<CrCalibrationInfo*>(eventData->data);
- //mLog::Info("Calibration progress: {$} / {$}, current frame mean: {$}", calib_info->current_frame_num, calib_info->total_frame_num, calib_info->current_frame_mean);
- //mLog::Info("Calibration result: {$}", calib_info->result);
- break;
- }
- case CR_EVT_ACQ_STAT_INFO:
- {
- CrAcquisitionStatInfo* stat_info = reinterpret_cast<CrAcquisitionStatInfo*>(eventData->data);
- //mLog::Info("Total frame: {$}", stat_info->total_frame_num);
- break;
- }
- case CR_EVT_RAD_ACQ_IN_PROGRESS:
- //mLog::Info("Get CR_EVT_RAD_ACQ_IN_PROGRESS");
- break;
- case CR_EVT_DETR_DISCONNECTED:
- break;
- default:
- //mLog::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);
- }
|