12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042 |
- #include "stdafx.h"
- #include "Detector_HaoBoRF.h"
- #include "CCOS.Dev.FPD.HaoBoRF.h"
- extern Log4CPP::Logger* gLogger;
- Detector_HaoBoRF* g_pDetector = nullptr;
- #define LOAD_PROC_ADDRESS(handle,func) \
- if ((func = (API_##func)GetProcAddress(handle, #func)) == NULL) { FERROR("loading entry point {$} error!!!", #func); }\
- #define BREAK_UINT32(var, ByteNum) \
- (unsigned char)((unsigned int)(((var) >> ((ByteNum)* 8)) & 0x00FF))
- #define BUILD_UINT32(Byte0, Byte1, Byte2, Byte3) \
- ((unsigned int)((unsigned int)((Byte0)& 0x00FF) \
- + ((unsigned int)((Byte1)& 0x00FF) << 8) \
- + ((unsigned int)((Byte2)& 0x00FF) << 16) \
- + ((unsigned int)((Byte3)& 0x00FF) << 24)))
- Detector_HaoBoRF::Detector_HaoBoRF()
- {
- m_pDPC2PanelID = new map<void*, int>();
- m_pPanelID2DPC = new map<int, void*>();
- m_nPanelCount = 0;
- m_nCurrentPanelID = 0;
- m_bConnected = false;
- m_nCurrentLogicMode = -1;
- m_pRawImgBuffer = nullptr;
- m_pFullImgBuffer = nullptr;
- m_nSaveRaw = 0;
- m_strCtrlWorkPath = "";
- m_eCaliType = CCOS_CALIBRATION_TYPE::CCOS_CALIBRATION_TYPE_NONE;
- m_eStatus = eDetStatus::DetStatus_NotIni;
- m_nMaxImgWidth = 0;
- m_nMaxImgHeight = 0;
- m_nRawImageWidth = 0;
- m_nRawImageHeight = 0;
- m_nCropLeft = 0;
- m_nCropRight = 0;
- m_nCropTop = 0;
- m_nCropBottom = 0;
- m_nImageWidth = 0;
- m_nImageHeight = 0;
- m_nFrameID = 0;
- m_nDropImgNum = 0;
- m_nDropImgCount = 0;
- m_nExamMode = APP_STATUS::APP_STATUS_MAX;
- m_hFPDScanThread = nullptr;
- m_fFrameRate = 10.0f; //缺省值,10帧每秒
- m_nDelayTime = 0;
- m_nExiThreshold = 200;//新增配置
- m_nImageBits = 16;
- m_bFirstImage = true;
- m_nModeID = 1;
- m_nGainLevel = 3;
- m_hSDKModule = nullptr;
- m_nFpdHandle = nullptr;
- m_bLoaded = false;
- nPGALevel = 0;
- nBinning = 0;
- nPrepareTime = 0;
- nLiveAcqTime = 0;
- m_hStopScanEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
- m_hAcqEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
- m_hGainEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
- m_hDarkEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
- m_hProcessImgEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
- m_hArrayEvent[0] = m_hStopScanEvent;
- m_hArrayEvent[1] = m_hAcqEvent;
- m_hArrayEvent[2] = m_hGainEvent;
- m_hArrayEvent[3] = m_hDarkEvent;
- m_hArrayEvent[4] = m_hProcessImgEvent;
-
- m_hStopOffsetEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
- m_hStartAllOffset = CreateEvent(NULL, FALSE, FALSE, NULL);
- m_hStartOffset = CreateEvent(NULL, FALSE, FALSE, NULL);
- m_hAbortOffset = CreateEvent(NULL, FALSE, FALSE, NULL);
- m_hOffsetEvent[0] = m_hStopOffsetEvent;
- m_hOffsetEvent[1] = m_hStartAllOffset;
- m_hOffsetEvent[2] = m_hStartOffset;
- m_hOffsetEvent[3] = m_hAbortOffset;
- }
- Detector_HaoBoRF::~Detector_HaoBoRF()
- {
- FINFO("~Detector_HaoBoRF");
- if (m_hStopScanEvent)
- {
- CloseHandle(m_hStopScanEvent);
- m_hStopScanEvent = nullptr;
- }
- if (m_hAcqEvent)
- {
- CloseHandle(m_hAcqEvent);
- m_hAcqEvent = nullptr;
- }
- if (m_hGainEvent)
- {
- CloseHandle(m_hGainEvent);
- m_hGainEvent = nullptr;
- }
- if (m_hDarkEvent)
- {
- CloseHandle(m_hDarkEvent);
- m_hDarkEvent = nullptr;
- }
- if (m_hProcessImgEvent)
- {
- CloseHandle(m_hProcessImgEvent);
- m_hProcessImgEvent = nullptr;
- }
- if (m_pRawImgBuffer)
- {
- delete[]m_pRawImgBuffer;
- m_pRawImgBuffer = nullptr;
- }
- if (m_pFullImgBuffer != nullptr)
- {
- delete[]m_pFullImgBuffer;
- m_pFullImgBuffer = nullptr;
- }
- FINFO("Call HBI_Destroy");
- HBI_Destroy(m_nFpdHandle);
- }
- //参数说明:
- // @USER_CALLBACK_HANDLE_ENVENT
- // @pContext:参数 1,上位机对象指针,可以为空(NULL)
- // @ufpdId:参数 2,例如平板id
- // @byteEventid:参数 3,事件 ID,参考HbiType.h 中 enumeCallbackEventCommType
- // @PVEventParam1:参数 4,配置指针或图像结构体指针
- // @nEventParam2:参数 5,例如datasize 或状态
- // @nEventParam3:参数 6,例如帧号 frameid
- // @nEventParam4:参数 7,例如帧率 framerate 或状态等
- int CallBackFunc(void* _contex, int nDevId, unsigned char byteEventId, void* param1, int param2, int param3, int param4)
- {
- FINFO("CallBackFunc nDevId:{$},byteEventId:{$},param2:{$},param3:{$},param4:{$}", nDevId, (int)byteEventId, param2, param3, param4);
- int ret = 0;
- ImageData* imagedata = NULL;
- RegCfgInfo* pRegCfg = NULL;
- int status = -1;
- switch (byteEventId)
- {
- case ECALLBACK_TYPE_INVALVE:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_INVALVE");
- break;
- }
- case ECALLBACK_TYPE_COMM_RIGHT:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_COMM_RIGHT");
- break;
- }
- case ECALLBACK_TYPE_COMM_WRONG:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_COMM_WRONG");
- break;
- }
- case ECALLBACK_TYPE_DUMMPLING:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_DUMMPLING");
- break;
- }
- case ECALLBACK_TYPE_ACQ_END:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_ACQ_END");
- break;
- }
- case ECALLBACK_TYPE_UPDATE_FIRMWARE:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_UPDATE_FIRMWARE");
- break;
- }
- case ECALLBACK_TYPE_ERASE_FIRMWARE:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_ERASE_FIRMWARE");
- break;
- }
- case ECALLBACK_TYPE_FPD_STATUS: // detetor status:connect/disconnect/ready/busy and so on
- {
- FINFO("Callback Type: ECALLBACK_TYPE_FPD_STATUS");
- if (param2 <= 0 && param2 >= -11)
- {
- if (param2 == 0)
- FERROR("ECALLBACK_TYPE_FPD_STATUS,Err:Network not connected!");
- else if (param2 == -1)
- FERROR("ECALLBACK_TYPE_FPD_STATUS,Err:Parameter exception!");
- else if (param2 == -2)
- FERROR("ECALLBACK_TYPE_FPD_STATUS,Err:Failed to return the number of ready descriptors!");
- else if (param2 == -3)
- FERROR("ECALLBACK_TYPE_FPD_STATUS,Err:Receive timeout!");
- else if (param2 == -4)
- FERROR("ECALLBACK_TYPE_FPD_STATUS,Err:Receive failed!");
- else if (param2 == -5)
- FERROR("ECALLBACK_TYPE_FPD_STATUS,Err:Socket-Port unreadable!");
- else if (param2 == -6)
- FERROR("ECALLBACK_TYPE_FPD_STATUS,Network card unusual!");
- else if (param2 == -7)
- FERROR("ECALLBACK_TYPE_FPD_STATUS,Network card ok!");
- else if (param2 == -8)
- FERROR("ECALLBACK_TYPE_FPD_STATUS:Update Firmware end!");
- else if (param2 == -9)
- FERROR("ECALLBACK_TYPE_FPD_STATUS:Light Fiber disconnected!");
- else if (param2 == -10)
- FERROR("ECALLBACK_TYPE_FPD_STATUS:Read ddr failed,try restarting the PCIe driver!");
- else /*if (param2 == -11)*/
- FERROR("ECALLBACK_TYPE_FPD_STATUS:is not jumb!");
- status = (int)FPD_DISCONN_STATUS;
- FERROR("Detector not connected!");
- g_pDetector->StatusFeedback(EVT_STATUS_PANEL, PANEL_CLOSE);
- }
- else if (param2 == FPD_CONN_SUCCESS) // connect
- {
- FINFO("Detector connected!");
- status = (int)FPD_CONN_SUCCESS;
- g_pDetector->StatusFeedback(EVT_STATUS_PANEL, PANEL_CONNECT);
- g_pDetector->GetPanelInfo();
- }
- else if (param2 == FPD_PREPARE_STATUS) // prepare
- {
- FINFO("Detector prepare!");
- status = (int)FPD_PREPARE_STATUS;
- g_pDetector->StatusFeedback(EVT_STATUS_PANEL, PANEL_STANDBY);
- }
- else if (param2 == FPD_READY_STATUS) // ready
- {
- FINFO("Detector ready!");
- status = (int)FPD_READY_STATUS;
- g_pDetector->StatusFeedback(EVT_STATUS_PANEL, PANEL_READY_EXP);
- }
- else if (param2 == FPD_DOOFFSET_TEMPLATE)// do offset template
- {
- FINFO("Detector do offset template!");
- status = (int)FPD_DOOFFSET_TEMPLATE;
- }
- else if (param2 == FPD_EXPOSE_STATUS) // busy expose
- {
- FINFO("Detector Exposing!");
- status = FPD_EXPOSE_STATUS;
- }
- else if (param2 == FPD_CONTINUE_READY) // continue ready
- {
- FINFO("Detector Continue ready!");
- status = FPD_CONTINUE_READY;
- g_pDetector->StatusFeedback(EVT_STATUS_PANEL, PANEL_READY_EXP);
- }
- else if (param2 == FPD_DWONLOAD_GAIN) // download gain template
- {
- FINFO("Detector Download gain template!");
- status = FPD_DWONLOAD_GAIN;
- }
- else if (param2 == FPD_DWONLOAD_DEFECT) // download defect template
- {
- FINFO("Detector Download defect template!");
- status = FPD_DWONLOAD_DEFECT;
- }
- else if (param2 == FPD_DWONLOAD_OFFSET)// download offset template
- {
- FINFO("Detector Download offset template!");
- status = FPD_DWONLOAD_OFFSET;
- }
- else if (param2 == FPD_UPDATE_FIRMARE)// update firmware
- {
- FINFO("Detector Update firmware!");
- status = FPD_UPDATE_FIRMARE;
- }
- else if (param2 == FPD_RETRANS_MISS)// Retrans mission
- {
- FINFO("Detector Retrans mission!");
- status = FPD_RETRANS_MISS;
- }
- else
- FERROR("Detector Other error:{$}", param2);
- if (status != -1)// error, diconnect detector
- {
- if (param2 <= 0 && param2 >= -10)
- {
- g_pDetector->HBI_DisConnectDetector(g_pDetector->m_nFpdHandle);
- }
- }
- break;
- }
- case ECALLBACK_TYPE_ROM_UPLOAD:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_ROM_UPLOAD");
- if (param1 == NULL || param2 == 0)
- {
- FERROR("Parameter exception!");
- return ret;
- }
- pRegCfg = new RegCfgInfo;
- if (pRegCfg != NULL)
- {
- memset(pRegCfg, 0x00, sizeof(RegCfgInfo));
- memcpy(pRegCfg, (unsigned char*)param1, sizeof(RegCfgInfo));
- g_pDetector->PrintDetectorCfg(pRegCfg);
- }
- break;
- }
- case ECALLBACK_TYPE_RAM_UPLOAD:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_RAM_UPLOAD");
- if (param1 == NULL || param2 == 0)
- {
- FERROR("Parameter exception!");
- return ret;
- }
- break;
- }
- case ECALLBACK_TYPE_FACTORY_UPLOAD:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_FACTORY_UPLOAD");
- if (param1 == NULL || param2 == 0)
- {
- printf("err:Parameter exception!\n");
- return ret;
- }
- break;
- }
- case ECALLBACK_TYPE_WLAN_BATTERY:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_WLAN_BATTERY");
- break;
- }
- case ECALLBACK_TYPE_BUFFER_WARNING:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_BUFFER_WARNING");
- break;
- }
- case ECALLBACK_TYPE_ILLEGAL_PACKAGE_NUM:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_ILLEGAL_PACKAGE_NUM");
- break;
- }
- case ECALLBACK_TYPE_USER_DDR_UPLOAD:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_USER_DDR_UPLOAD");
- break;
- }
- case ECALLBACK_TYPE_WIRELESS_NETWORK:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_WIRELESS_NETWORK");
- break;
- }
- case ECALLBACK_TYPE_WIRELESS_SETKEYOK:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_WIRELESS_SETKEYOK");
- break;
- }
- case ECALLBACK_FIRMWARE_TEMPLATE_STATUS:
- {
- FINFO("Callback Type: ECALLBACK_FIRMWARE_TEMPLATE_STATUS");
- break;
- }
- case ECALLBACK_TYPE_SINGLE_IMAGE:
- case ECALLBACK_TYPE_MULTIPLE_IMAGE:
- FINFO("Callback Type: ECALLBACK_TYPE_SINGLE_IMAGE or ECALLBACK_TYPE_MULTIPLE_IMAGE");
- if (param1 == NULL || param2 == 0)
- {
- FERROR("Parameter exception!");
- return ret;
- }
- imagedata = (ImageData*)param1;
- g_pDetector->m_nRawImageWidth = imagedata->uwidth;
- g_pDetector->m_nRawImageHeight = imagedata->uheight;
- g_pDetector->m_nFrameID = imagedata->uframeid;
- FINFO("Callback ImageWidth:{$},ImageHeight:{$},FrameID:{$},datalen:{$}", imagedata->uwidth, imagedata->uheight, imagedata->uframeid, imagedata->datalen);
- memcpy(g_pDetector->m_pRawImgBuffer, (unsigned char*)imagedata->databuff, imagedata->datalen);
- //获取图像后需要调用停止采集,所以改到子线程处理
- SetEvent(g_pDetector->m_hProcessImgEvent);
- break;
- case ECALLBACK_TYPE_PREVIEW_IMAGE:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_PREVIEW_IMAGE");
- if (param1 == NULL || param2 == 0)
- {
- FERROR("Parameter exception!");
- return ret;
- }
- imagedata = (ImageData*)param1;
- break;
- }
- case ECALLBACK_TYPE_LIVE_IMAGE:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_LIVE_IMAGE");
- if (param1 == NULL || param2 == 0)
- {
- FERROR("Parameter exception!");
- return ret;
- }
- imagedata = (ImageData*)param1;
- g_pDetector->m_nRawImageWidth = imagedata->uwidth;
- g_pDetector->m_nRawImageHeight = imagedata->uheight;
- g_pDetector->m_nFrameID = imagedata->uframeid;
- FINFO("Callback ImageWidth:{$},ImageHeight:{$},FrameID:{$},datalen:{$}", imagedata->uwidth, imagedata->uheight, imagedata->uframeid, imagedata->datalen);
- memcpy(g_pDetector->m_pRawImgBuffer, (unsigned char*)imagedata->databuff, imagedata->datalen);
- //获取图像后需要调用停止采集,所以改到子线程处理
- SetEvent(g_pDetector->m_hProcessImgEvent);
- break;
- }
- case ECALLBACK_TYPE_PACKET_MISS:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_PACKET_MISS");
- break;
- }
- case ECALLBACK_TYPE_OFFSET_TMP:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_OFFSET_TMP");
- if (param1 == NULL || param2 == 0)
- {
- FERROR("Parameter exception!");
- return ret;
- }
- imagedata = (ImageData*)param1;
- break;
- }
- case ECALLBACK_OVERLAY_NUMBER:
- {
- FINFO("Callback Type: ECALLBACK_OVERLAY_NUMBER");
- break;
- }
- case ECALLBACK_OVERLAY_16BIT_IMAGE:
- {
- FINFO("Callback Type: ECALLBACK_OVERLAY_16BIT_IMAGE");
- if (param1 == NULL || param2 == 0)
- {
- FERROR("Parameter exception!");
- return ret;
- }
- imagedata = (ImageData*)param1;
- break;
- }
- case ECALLBACK_OVERLAY_32BIT_IMAGE:
- {
- FINFO("Callback Type: ECALLBACK_OVERLAY_32BIT_IMAGE");
- if (param1 == NULL || param2 == 0)
- {
- FERROR("Parameter exception!");
- return ret;
- }
- imagedata = (ImageData*)param1;
- break;
- }
- case ECALLBACK_TYPE_8BIT_IMAGE:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_8BIT_IMAGE");
- break;
- }
- case ECALLBACK_TYPE_SENDTO_WIZARD:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_SENDTO_WIZARD");
- break;
- }
- case ECALLBACK_TYPE_PACKET_MISS_MSG:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_PACKET_MISS_MSG");
- break;
- }
- case ECALLBACK_TYPE_THREAD_EVENT:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_THREAD_EVENT");
- if (param2 == 100)
- FINFO("ECALLBACK_TYPE_THREAD_EVENT,start recv data!");
- else if (param2 == 101)
- FINFO("ECALLBACK_TYPE_THREAD_EVENT,end recv data!");
- else if (param2 == 104)
- FINFO("ECALLBACK_TYPE_THREAD_EVENT,Packet Retransmission:start recv data!");
- else if (param2 == 105)
- FINFO("ECALLBACK_TYPE_THREAD_EVENT,Frame Retransmission:start recv data!");
- else if (param2 == 106)
- FINFO("ECALLBACK_TYPE_THREAD_EVENT,Frame loss retransmission over,end recv data!");
- else if (param2 == 107)
- FINFO("ECALLBACK_TYPE_THREAD_EVENT,image buff is null:end recv data!");
- else if (param2 == 108)
- FINFO("ECALLBACK_TYPE_THREAD_EVENT,Generate Offset Template:start thread!");
- else if (param2 == 109)
- FINFO("ECALLBACK_TYPE_THREAD_EVENT,Generate Offset Template:end thread!");
- else if (param2 == 110)
- FINFO("ECALLBACK_TYPE_THREAD_EVENT,Generate Gain Template:start thread!");
- else if (param2 == 111)
- FINFO("ECALLBACK_TYPE_THREAD_EVENT,Generate Gain Template:end thread!");
- else if (param2 == 112)
- FINFO("ECALLBACK_TYPE_THREAD_EVENT,offset calibrate:success!");
- else if (param2 == 113)
- FINFO("ECALLBACK_TYPE_THREAD_EVENT,offset calibrate:failed!");
- else if (param2 == 114)
- FINFO("ECALLBACK_TYPE_THREAD_EVENT,gain calibrate:success!");
- else if (param2 == 115)
- FINFO("ECALLBACK_TYPE_THREAD_EVENT,gain calibrate:failed!");
- else if (param2 == 116)
- FINFO("ECALLBACK_TYPE_THREAD_EVENT,defect calibrate:success!");
- else if (param2 == 117)
- FINFO("ECALLBACK_TYPE_THREAD_EVENT,defect calibrate:failed!");
- else if (param2 == 118)
- FINFO("ECALLBACK_TYPE_THREAD_EVENT,InitGainTemplate:failed!");
- else if (param2 == 119)
- FINFO("ECALLBACK_TYPE_THREAD_EVENT,firmare offset calibrate:success!");
- else if (param2 == 120)
- FINFO("ECALLBACK_TYPE_THREAD_EVENT,Generate Defect Template:start thread!");
- else if (param2 == 121)
- FINFO("ECALLBACK_TYPE_THREAD_EVENT,Generate Defect Template:end thread!");
- else
- FERROR("ECALLBACK_TYPE_THREAD_EVENT,Err:other error [{$}]", param2);
- break;
- }
- case ECALLBACK_TYPE_ACQ_DISCARDDED:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_ACQ_DISCARDDED");
- break;
- }
- case ECALLBACK_TYPE_OFFSET_ERR_MSG:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_OFFSET_ERR_MSG");
- break;
- }
- case ECALLBACK_TYPE_GAIN_ERR_MSG:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_GAIN_ERR_MSG");
- break;
- }
- case ECALLBACK_TYPE_DEFECT_ERR_MSG:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_DEFECT_ERR_MSG");
- break;
- }
- case ECALLBACK_TYPE_NET_ERR_MSG:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_NET_ERR_MSG");
- break;
- }
- case ECALLBACK_TYPE_SET_CFG_OK:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_SET_CFG_OK set rom param succuss!");
- break;
- }
- case ECALLBACK_TYPE_SAVE_SUCCESS:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_SAVE_SUCCESS");
- break;
- }
- case ECALLBACK_TYPE_GENERATE_TEMPLATE:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_GENERATE_TEMPLATE");
- if (param2 == ECALLBACK_TEMPLATE_BEGIN)
- {
- FINFO("ECALLBACK_TEMPLATE_BEGIN");
- }
- else if (param2 == ECALLBACK_TEMPLATE_INVALVE_PARAM)
- {
- FINFO("ECALLBACK_TEMPLATE_INVALVE_PARAM:{$}", param3);
- }
- else if (param2 == ECALLBACK_TEMPLATE_MALLOC_FAILED)
- {
- FINFO("ECALLBACK_TEMPLATE_MALLOC_FAILED:{$}", param3);
- }
- else if (param2 == ECALLBACK_TEMPLATE_SEND_FAILED)
- {
- FINFO("ECALLBACK_TEMPLATE_SEND_FAILED:{$}", param3);
- }
- else if (param2 == ECALLBACK_TEMPLATE_STATUS_ABORMAL)
- {
- FINFO("ECALLBACK_TEMPLATE_STATUS_ABORMAL:{$}", param3);
- }
- else if (param2 == ECALLBACK_TEMPLATE_FRAME_NUM)
- {
- FINFO("ECALLBACK_TEMPLATE_FRAME_NUM:{$}", param3);
- }
- else if (param2 == ECALLBACK_TEMPLATE_TIMEOUT)
- {
- FINFO("ECALLBACK_TEMPLATE_TIMEOUT:{$}", param3);
- }
- else if (param2 == ECALLBACK_TEMPLATE_MEAN)
- {
- ECALLBACK_RAW_INFO* ptr = (ECALLBACK_RAW_INFO*)param1;
- if (ptr != NULL)
- {
- FINFO("ECALLBACK_TEMPLATE_MEAN:{$},dMean={$.2f}", ptr->szRawName, ptr->dMean);
- }
- }
- else if (param2 == ECALLBACK_TEMPLATE_GENERATE)
- {
- if (param3 == OFFSET_TMP)
- FINFO("ECALLBACK_TEMPLATE_GENERATE:OFFSET_TMP");
- else if (param3 == GAIN_TMP)
- FINFO("ECALLBACK_TEMPLATE_GENERATE:GAIN_TMP");
- else if (param3 == DEFECT_TMP)
- FINFO("ECALLBACK_TEMPLATE_GENERATE:DEFECT_TMP,bad point={$}", param2);
- else
- FINFO("ECALLBACK_TEMPLATE_GENERATE:nid={$}", param3);
- }
- else if (param2 == ECALLBACK_TEMPLATE_RESULT)
- {
- FINFO("ECALLBACK_TEMPLATE_RESULT:{$}", param3);
- }
- else
- {
- FINFO("other:len={$},nid={$}", param2, param3);
- }
- break;
- }
- case ECALLBACK_TYPE_FILE_NOTEXIST:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_FILE_NOTEXIST");
- if (param1 != NULL)
- FERROR("err:{$} not exist!", (char*)param1);
- break;
- }
- case ECALLBACK_TYPE_WORK_STATUS:
- {
- FINFO("Callback Type: ECALLBACK_TYPE_WORK_STATUS");
- break;
- }
- default:
- FINFO("default Callback Type[{$}]", (int)byteEventId);
- break;
- }
- if (pRegCfg)
- {
- delete pRegCfg;
- pRegCfg = nullptr;
- }
- return 0;
- }
- bool Detector_HaoBoRF::DriverEntry(void* pDrvDPC, ResDataObject& Configuration, const char* szWorkPath)
- {
- printf("========DriverEntry %p\n", pDrvDPC);
- FINFO("========DriverEntry {$}", pDrvDPC);
- map<void*, int>::iterator iter = m_pDPC2PanelID->find(pDrvDPC);
- if (iter != m_pDPC2PanelID->end())
- {
- FERROR("This DPC already exist");
- return false;
- }
- m_pDPC2PanelID->insert(pair<void*, int>(pDrvDPC, m_nPanelCount));
- m_pPanelID2DPC->insert(pair<int, void*>(m_nPanelCount, pDrvDPC));
- m_nPanelCount++;
- m_ModeConfig = Configuration; //记录配置 --目前只有一个平板,多板时应该分别存储
- FINFO("m_ModeConfig:{$}", m_ModeConfig.encode());
- if (nullptr == m_hFPDScanThread)
- {
- unsigned uThreadId;
- _beginthreadex(NULL, 0, onFPDScanThread, this, 0, &uThreadId);
- m_hFPDScanThread = OpenThread(THREAD_ALL_ACCESS, TRUE, uThreadId);
- }
- if (nullptr == m_hOffsetThread)
- {
- unsigned uThreadId;
- _beginthreadex(NULL, 0, RefreshOffsetThread, this, 0, &uThreadId);
- m_hOffsetThread = OpenThread(THREAD_ALL_ACCESS, TRUE, uThreadId);
- }
- m_strCtrlWorkPath = szWorkPath;
- if (!LoadDll(szWorkPath))
- {
- FERROR("Load dll failed!");
- return false;
- }
- if (m_bLoaded)
- {
- FINFO("Calling HBI_Init");
- m_nFpdHandle = HBI_Init(0);
- if (!m_nFpdHandle)
- {
- FERROR("HBI_Init error!");
- return false;
- }
- FINFO("Calling HBI_RegEventCallBackFun");
- int nRet = HBI_RegEventCallBackFun(m_nFpdHandle, CallBackFunc, NULL);
- if (TestError(nRet, "HBI_RegEventCallBackFun"))
- {
- FERROR("Register call back fun fail!");
- return false;
- }
- }
- return true;
- }
- bool Detector_HaoBoRF::Connect(void* pDrvDPC)
- {
- printf("========Connect detector begin \r\n");
- FINFO("========Connect detector begin \n");
- if ((*m_pDPC2PanelID)[pDrvDPC] != m_nCurrentPanelID)
- {
- FERROR("Not current DPC, return true");
- return true;
- }
- if (m_bLoaded)
- {
- if (!ConnectDetector())
- {
- return false;
- }
- }
- else
- {
- FERROR("DLL is not loaded!");
- return false;
- }
- FINFO("Connect over");
- printf("Connect over \n");
- return true;
- }
- void Detector_HaoBoRF::DisConnect()
- {
- printf("========DisConnect with detector \n");
- FINFO("========DisConnect");
- int nRet = HBI_SUCCSS;
-
- }
- void Detector_HaoBoRF::EnterExamMode(int nExamMode)
- {
- switch (nExamMode)
- {
- case APP_STATUS_WORK_BEGIN:
- FINFO("Enter into Exam Windows");
- m_nExamMode = APP_STATUS_WORK_BEGIN;
- break;
- case APP_STATUS_WORK_END:
- FINFO("Quit Exam Windows");
- m_nExamMode = APP_STATUS_WORK_END;
- break;
- case APP_STATUS_DETSHARE_BEGIN:
- FINFO("Enter into Detector Share Windows");
- m_nExamMode = APP_STATUS_DETSHARE_BEGIN;
- break;
- case APP_STATUS_DETSHAR_END:
- m_nExamMode = APP_STATUS_IDLE;
- FINFO("Quit Detector Share Windows");
- m_nExamMode = APP_STATUS_DETSHAR_END;
- break;
- case APP_STATUS_CAL_BEGIN:
- FINFO("Enter into Calibration Windows");
- m_nExamMode = APP_STATUS_CAL_BEGIN;
- break;
- case APP_STATUS_CAL_END:
- FINFO("Quit Calibration Windows");
- m_nExamMode = APP_STATUS_CAL_END;
- break;
- case APP_STATUS_WORK_IN_SENSITIVITY:
- FINFO("Enter into sensitivity test interface");
- m_nExamMode = APP_STATUS_WORK_IN_SENSITIVITY;
- break;
- default:
- break;
- }
- if (APP_STATUS_WORK_END == m_nExamMode)
- {
- if (DetStatus_Acquire == GetDpcStatus())
- {
- FINFO("quit exam but detector status is acquire,so stop acquire");
- StopAcquisition(nullptr);
- }
- }
- }
- bool Detector_HaoBoRF::SetAcqMode(int nMode)
- {
- printf("========SetAcqMode nMode:%d \n", nMode);
- FINFO("========SetAcqMode nMode:{$}",nMode);
- if (m_nCurrentLogicMode == nMode)
- {
- FINFO("Same mode, return");
- return true;
- }
- //只有RAD模式读取全部的配置文件,CF和PF不读取全部配置,只读取部分
- try
- {
- int nModeCount = (int)m_ModeConfig["ModeTable"].size();
- for (int i = 0; i < nModeCount; i++)
- {
- int logicMode = (int)m_ModeConfig["ModeTable"][i]["LogicMode"];//SetAcqMode
- if (logicMode == nMode)
- {
- //FINFO("ModeTable22 {$}, {$}", i, m_ModeConfig["ModeTable"][i].encode());
- FINFO("find LogicMode == nMode");
- if (logicMode == RAD)
- {
- m_nModeID = (int)m_ModeConfig["ModeTable"][i]["OperationMode"];//RAD 固定用1*1的Binning
- }
- m_nDelayTime = (int)m_ModeConfig["ModeTable"][i]["DelayTime"];
- m_nDropImgCount = (int)m_ModeConfig["ModeTable"][i]["DropImgCount"];
- m_nSaveRaw = (int)m_ModeConfig["ModeTable"][i]["IsSaveRaw"];
- m_nTriggerMode = (int)m_ModeConfig["ModeTable"][i]["ExamType"];
- FINFO("m_nDelayTime:{$}, m_nDropImgCount:{$}, m_nSaveRaw:{$}, m_nModeID:{$}, m_nTriggerMode:{$}",
- m_nDelayTime, m_nDropImgCount, m_nSaveRaw, m_nModeID, m_nTriggerMode);
- m_nCropLeft = (int)m_ModeConfig["ModeTable"][i]["CropLeft"];
- m_nCropRight = (int)m_ModeConfig["ModeTable"][i]["CropRight"];
- m_nCropTop = (int)m_ModeConfig["ModeTable"][i]["CropTop"];
- m_nCropBottom = (int)m_ModeConfig["ModeTable"][i]["CropBottom"];
- FINFO("Crop left:{$}, top:{$}, right:{$}, bottom:{$}", m_nCropLeft, m_nCropTop, m_nCropRight, m_nCropBottom);
- m_nImageBits = (int)m_ModeConfig["ModeTable"][i]["PhySizeInfoBit"];
- m_nGainLevel = (int)m_ModeConfig["ModeTable"][i]["GainValue"];
- FINFO("m_nImageBits:{$}, m_nGainLevel:{$}", m_nImageBits, m_nGainLevel);
- break;
- }
- }
- }
- catch (ResDataObjectExption& e)
- {
- FERROR("Read configuration failed, Error code: {$}", e.what());
- return false;
- }
-
- m_nCurrentLogicMode = nMode;
- return true;
- }
- bool Detector_HaoBoRF::SetExposureTimes(int nTimes)
- {
- FINFO("========SetExposureTimes({$})", nTimes);
- return true;
- }
- bool Detector_HaoBoRF::PrepareAcquisition(void* pDrvDPC)
- {
- printf("========PrepareAcquisition \n");
- FINFO("========PrepareAcquisition ");
- int nRet = HBI_SUCCSS;
- if ((*m_pDPC2PanelID)[pDrvDPC] != m_nCurrentPanelID)
- {
- FERROR("Not current DPC, return");
- return false;
- }
- if (-1 == m_nCurrentLogicMode)
- {
- FERROR("Illegal exam mode");
- return false;
- }
- eDetStatus detectorStatus = GetDpcStatus();
- if (detectorStatus == DetStatus_Acquire)
- {
- bool ret = StopAcquisition(pDrvDPC);
- if (!ret)
- {
- return false;
- }
- }
- //modeID 1->1*1 2->2*2
- FINFO("m_nTriggerMode:{$}, m_nModeID:{$}, acqTime:{$}", m_nTriggerMode, m_nModeID, 1 / (int)m_fFrameRate);
- FINFO("Call HBI_TriggerBinningAcqTime");
- nRet = HBI_TriggerBinningAcqTime(m_nFpdHandle, m_nTriggerMode, m_nModeID, 1 / (int)m_fFrameRate, 0);
- if (TestError(nRet,"HBI_TriggerBinningAcqTime"))
- {
- FERROR("HBI_TriggerBinningAcqTime fail!");
- return false;
- }
- return true;
- }
- bool Detector_HaoBoRF::StartAcquisition(void* pDrvDPC)
- {
- printf("========StartAcquisition \n");
- FINFO("========StartAcquisition ");
- int nRet = HBI_SUCCSS;
- if ((*m_pDPC2PanelID)[pDrvDPC] != m_nCurrentPanelID)
- {
- FERROR("Not current DPC, return");
- return false;
- }
- if (-1 == m_nCurrentLogicMode)
- {
- FERROR("Illegal exam mode");
- return false;
- }
- else
- {
- m_bValidImage = false; //开始采集,恢复初值
- m_nDropImgNum = 0; //开始采集,恢复初值
- m_bFirstImage = true;
- m_dwBeginTime = GetTickCount64();
- }
- FPD_AQC_MODE aqc_mode;
- FINFO("m_nCurrentLogicMode:{$}", m_nCurrentLogicMode);
- if (m_nCurrentLogicMode == RAD)
- {
- aqc_mode.nAcqnumber = 1;
- }
- else if (m_nCurrentLogicMode == CF || m_nCurrentLogicMode == PF)
- {
- aqc_mode.eAqccmd = EnumIMAGE_ACQ_CMD::LIVE_ACQ_DEFAULT_TYPE;
- aqc_mode.eLivetype = EnumLIVE_ACQUISITION::ONLY_IMAGE;
- }
- FINFO("Call HBI_LiveAcquisition");
- nRet = HBI_LiveAcquisition(m_nFpdHandle, aqc_mode);
- if (TestError(nRet,"HBI_LiveAcquisition"))
- {
- FERROR("HBI_LiveAcquisition fail!");
- return false;
- }
- SetDpcStatus(DetStatus_Acquire); //动态模式激活采集,设置状态
-
- return true;
- }
- bool Detector_HaoBoRF::StopAcquisition(void* pDrvDPC)
- {
- printf("========StopAcquisition \n");
- FINFO("========StopAcquisition ");
- int nRet = HBI_SUCCSS;
- if ((*m_pDPC2PanelID)[pDrvDPC] != m_nCurrentPanelID)
- {
- FERROR("Not current DPC, return");
- return false;
- }
- FINFO("Call HBI_StopAcquisition");
- nRet = HBI_StopAcquisition(m_nFpdHandle);
- if (TestError(nRet,"HBI_StopAcquisition"))
- {
- FERROR("Stop Acqusition fail!");
- return false;
- }
- return true;
- }
- bool Detector_HaoBoRF::ActiveCalibration(void* pDrvDPC, CCOS_CALIBRATION_TYPE eType)
- {
- printf("========ActiveCalibration \n");
- FINFO("========ActiveCalibration ");
- if ((*m_pDPC2PanelID)[pDrvDPC] != m_nCurrentPanelID)
- {
- //printf("Not current DPC, return\n");
- FERROR("Not current DPC, return");
- return false;
- }
- if (-1 == m_nCurrentLogicMode)
- {
- FERROR("Illegal exam mode");
- return false;
- }
- if (CCOS_CALIBRATION_TYPE_XRAY == eType)
- {
- SetDpcStatus(DetStatus_GainCalibration);
- }
- m_eCaliType = eType;
- return true;
- }
- bool Detector_HaoBoRF::PrepareCalibration(void* pDrvDPC)
- {
- printf("========PrepareCalibration \n");
- FINFO("========PrepareCalibration ");
- bool bRet = false;
- if ((*m_pDPC2PanelID)[pDrvDPC] != m_nCurrentPanelID)
- {
- FERROR("Not current DPC, return");
- return bRet;
- }
- if (GetDpcStatus() != DetStatus_GainCalibration)
- {
- FINFO("Current status is not XrayCalibration, return succeed");
- return true;
- }
- return bRet;
- }
- bool Detector_HaoBoRF::StartCalibration(void* pDrvDPC)
- {
- printf("========StartCalibration \n");
- FINFO("========StartCalibration ");
- bool bRet = false;
- if ((*m_pDPC2PanelID)[pDrvDPC] != m_nCurrentPanelID)
- {
- FERROR("Not current DPC, return");
- return bRet;
- }
- if (CCOS_CALIBRATION_TYPE_DARK == m_eCaliType)
- {
- SetEvent(m_hDarkEvent);
- bRet = true;
- }
- else if (CCOS_CALIBRATION_TYPE_XRAY == m_eCaliType)
- {
- bRet = StartGainCalibration();
- }
- return bRet;
- }
- bool Detector_HaoBoRF::StopCalibration(void* pDrvDPC)
- {
- printf("========StopCalibration \n");
- FINFO("========StopCalibration ");
- bool bRet = false;
- int nRet = HBI_SUCCSS;
- if ((*m_pDPC2PanelID)[pDrvDPC] != m_nCurrentPanelID)
- {
- //printf("Not current DPC, return\n");
- FERROR("Not current DPC, return");
- return bRet;
- }
- FINFO("StopCalibration Calling StopCalibration");
-
- return bRet;
- }
- bool Detector_HaoBoRF::LoadDll(string strWorkPath)
- {
- printf("========LoadDll \n");
- FINFO("========LoadDll start");
- string strSDKPath = "";
- try
- {
- strSDKPath = (string)m_ModeConfig["SDKPath"];
- }
- catch (ResDataObjectExption& e)
- {
- FERROR("Read configuration failed, Error code: {$}", e.what());
- return false;
- }
- string workpath = strWorkPath + strSDKPath;
- FINFO("workpath:{$}", workpath);
- string drvpath = workpath + "\\HBISDKApi.dll";
- SetDllDirectory(workpath.c_str());
- m_hSDKModule = LoadLibrary(drvpath.c_str());
- if (m_hSDKModule == nullptr)
- {
- DWORD dw = GetLastError();
- FERROR("Load {$} failed! error code:{$}", drvpath, dw);
- return false;
- }
- LOAD_PROC_ADDRESS(m_hSDKModule, HBI_Init);
- LOAD_PROC_ADDRESS(m_hSDKModule, HBI_Destroy);
- LOAD_PROC_ADDRESS(m_hSDKModule, HBI_ConnectDetector);
- LOAD_PROC_ADDRESS(m_hSDKModule, HBI_DisConnectDetector);
- LOAD_PROC_ADDRESS(m_hSDKModule, HBI_RegEventCallBackFun);
- LOAD_PROC_ADDRESS(m_hSDKModule, HBI_GetSDKVerion);
- LOAD_PROC_ADDRESS(m_hSDKModule, HBI_GetFirmareVerion);
- LOAD_PROC_ADDRESS(m_hSDKModule, HBI_GetError);
- LOAD_PROC_ADDRESS(m_hSDKModule, HBI_GetFpdCfgInfo);
- LOAD_PROC_ADDRESS(m_hSDKModule, HBI_GetImageProperty);
- LOAD_PROC_ADDRESS(m_hSDKModule, HBI_LiveAcquisition);
- LOAD_PROC_ADDRESS(m_hSDKModule, HBI_StopAcquisition);
- LOAD_PROC_ADDRESS(m_hSDKModule, HBI_SetSelfDumpingTime);
- LOAD_PROC_ADDRESS(m_hSDKModule, HBI_TriggerAndCorrectApplay);
- LOAD_PROC_ADDRESS(m_hSDKModule, HBI_UpdateTriggerMode);
- LOAD_PROC_ADDRESS(m_hSDKModule, HBI_UpdateCorrectEnable);
- LOAD_PROC_ADDRESS(m_hSDKModule, HBI_SetBinning);
- LOAD_PROC_ADDRESS(m_hSDKModule, HBI_GenerateTemplate);
- LOAD_PROC_ADDRESS(m_hSDKModule, HBI_TriggerBinningAcqTime);
- LOAD_PROC_ADDRESS(m_hSDKModule, HBI_IsMutilMode);
- m_bLoaded = true;
- FINFO("LoadDll end");
- return true;
- }
- int Detector_HaoBoRF::GetPGA(unsigned short usValue)
- {
- unsigned short gainMode = ((usValue & 0xff) << 8) | ((usValue >> 8) & 0xff);
- int nPGA = (gainMode >> 10) & 0x3f;
- if (nPGA == 0x02) return 1;
- else if (nPGA == 0x04) return 2;
- else if (nPGA == 0x08) return 3;
- else if (nPGA == 0x0c) return 4;
- else if (nPGA == 0x10) return 5;
- else if (nPGA == 0x18) return 6;
- else if (nPGA == 0x3e) return 7;
- else return 0;
- }
- void Detector_HaoBoRF::PrintDetectorCfg(RegCfgInfo* pCfg)
- {
- FINFO("========PrintDetectorCfg");
- if (pCfg == NULL)
- {
- FERROR("pCfg is NULL!");
- return;
- }
- FINFO("Xray sensor type:{$}", (int)pCfg->m_SysBaseInfo.m_byXRaySensorType);
- // detector type,width and hight
- if (pCfg->m_SysBaseInfo.m_byPanelSize == 0x01)
- FINFO("PanelSize:{$},fpd type:4343-140um", (int)pCfg->m_SysBaseInfo.m_byPanelSize);
- else if (pCfg->m_SysBaseInfo.m_byPanelSize == 0x02)
- FINFO("PanelSize:{$},fpd type:3543-140um", (int)pCfg->m_SysBaseInfo.m_byPanelSize);
- else if (pCfg->m_SysBaseInfo.m_byPanelSize == 0x03)
- FINFO("PanelSize:{$},fpd type:1613-125um", (int)pCfg->m_SysBaseInfo.m_byPanelSize);
- else if (pCfg->m_SysBaseInfo.m_byPanelSize == 0x04)
- FINFO("PanelSize:{$},fpd type:3030-140um", (int)pCfg->m_SysBaseInfo.m_byPanelSize);
- else if (pCfg->m_SysBaseInfo.m_byPanelSize == 0x05)
- FINFO("PanelSize:{$},fpd type:2530-85um", (int)pCfg->m_SysBaseInfo.m_byPanelSize);
- else if (pCfg->m_SysBaseInfo.m_byPanelSize == 0x06)
- FINFO("PanelSize:{$},fpd type:3025-140um", (int)pCfg->m_SysBaseInfo.m_byPanelSize);
- else if (pCfg->m_SysBaseInfo.m_byPanelSize == 0x07)
- FINFO("PanelSize:{$},fpd type:4343-100um", (int)pCfg->m_SysBaseInfo.m_byPanelSize);
- else if (pCfg->m_SysBaseInfo.m_byPanelSize == 0x08)
- FINFO("PanelSize:{$},fpd type:2530-75um", (int)pCfg->m_SysBaseInfo.m_byPanelSize);
- else if (pCfg->m_SysBaseInfo.m_byPanelSize == 0x09)
- FINFO("PanelSize:{$},fpd type:2121-200um", (int)pCfg->m_SysBaseInfo.m_byPanelSize);
- else if (pCfg->m_SysBaseInfo.m_byPanelSize == 0x0a)
- FINFO("PanelSize:{$},fpd type:1412-50um", (int)pCfg->m_SysBaseInfo.m_byPanelSize);
- else if (pCfg->m_SysBaseInfo.m_byPanelSize == 0x0b)
- FINFO("PanelSize:{$},fpd type:0606-50um", (int)pCfg->m_SysBaseInfo.m_byPanelSize);
- else
- FERROR("PanelSize:{$},invalid fpd type!", (int)pCfg->m_SysBaseInfo.m_byPanelSize);
- FINFO("PixelPitch:{$}", (int)pCfg->m_SysBaseInfo.m_byPixelPitch);
- m_nMaxImgWidth = pCfg->m_SysBaseInfo.m_sImageWidth;
- m_nMaxImgHeight = pCfg->m_SysBaseInfo.m_sImageHeight;
- FINFO("Detector Width={$},Hight={$}", m_nMaxImgWidth, m_nMaxImgHeight);
- ConfFeedback(EVT_CONF_MAX_IMAGESIZE, m_nCurrentPanelID, "", m_nMaxImgWidth * m_nMaxImgHeight);
- if (m_pRawImgBuffer)
- {
- delete[] m_pRawImgBuffer;
- m_pRawImgBuffer = nullptr;
- }
- m_pRawImgBuffer = new WORD[(size_t)m_nMaxImgWidth * (size_t)m_nMaxImgHeight];
- if (m_pFullImgBuffer)
- {
- delete[] m_pFullImgBuffer;
- m_pFullImgBuffer = nullptr;
- }
- m_pFullImgBuffer = new WORD[(size_t)m_nMaxImgWidth * (size_t)m_nMaxImgHeight];
- FINFO("Serial Number:{$}", pCfg->m_SysBaseInfo.m_cSnNumber);
- FINFO("MaxFPS:{$}", (int)pCfg->m_SysBaseInfo.m_cMaxFps);
-
- //ip and port
- unsigned short usValue = ((pCfg->m_EtherInfo.m_sDestUDPPort & 0xff) << 8) | ((pCfg->m_EtherInfo.m_sDestUDPPort >> 8) & 0xff);
- FINFO("SourceIP:{$}.{$}.{$}.{$}:{$}",
- pCfg->m_EtherInfo.m_byDestIP[0],
- pCfg->m_EtherInfo.m_byDestIP[1],
- pCfg->m_EtherInfo.m_byDestIP[2],
- pCfg->m_EtherInfo.m_byDestIP[3],
- usValue);
- usValue = ((pCfg->m_EtherInfo.m_sSourceUDPPort & 0xff) << 8) | ((pCfg->m_EtherInfo.m_sSourceUDPPort >> 8) & 0xff);
- FINFO("DestIP:{$}.{$}.{$}.{$}:{$}",
- pCfg->m_EtherInfo.m_bySourceIP[0],
- pCfg->m_EtherInfo.m_bySourceIP[1],
- pCfg->m_EtherInfo.m_bySourceIP[2],
- pCfg->m_EtherInfo.m_bySourceIP[3],
- usValue);
- //trigger mode
- if (pCfg->m_SysCfgInfo.m_byTriggerMode == 0x01)
- FINFO("static software trigger.[0x{$02X}]", pCfg->m_SysCfgInfo.m_byTriggerMode);
- else if (pCfg->m_SysCfgInfo.m_byTriggerMode == 0x03)
- FINFO("static hvg trigger.[0x{$02X}]", pCfg->m_SysCfgInfo.m_byTriggerMode);
- else if (pCfg->m_SysCfgInfo.m_byTriggerMode == 0x04)
- FINFO("Free AED trigger mode.[0x{$02X}]", pCfg->m_SysCfgInfo.m_byTriggerMode);
- else if (pCfg->m_SysCfgInfo.m_byTriggerMode == 0x05)
- FINFO("Dynamic:Hvg Sync mode.[0x{$02X}]", pCfg->m_SysCfgInfo.m_byTriggerMode);
- else if (pCfg->m_SysCfgInfo.m_byTriggerMode == 0x06)
- FINFO("Dynamic:Fpd Sync mode.[0x{$02X}]", pCfg->m_SysCfgInfo.m_byTriggerMode);
- else if (pCfg->m_SysCfgInfo.m_byTriggerMode == 0x07)
- FINFO("Dynamic:Fpd Continue mode.[0x{$02X}]", pCfg->m_SysCfgInfo.m_byTriggerMode);
- else if (pCfg->m_SysCfgInfo.m_byTriggerMode == 0x08)
- FINFO("Static:SAEC mode.[0x{$02X}]", pCfg->m_SysCfgInfo.m_byTriggerMode);
- else
- FINFO("other trigger mode.[0x{$02X}]", pCfg->m_SysCfgInfo.m_byTriggerMode);
- // Binning type
- nBinning = (int)pCfg->m_SysCfgInfo.m_byBinning;
- if (nBinning < 1 || nBinning > 4)
- {
- nBinning = 1;
- }
- FINFO("Binning type:{$}*{$}", nBinning, nBinning);
- // acq delay time
- FINFO("Pre Acquisition Delay Time:{$}ms", pCfg->m_SysCfgInfo.m_unPreAcquisitionDelayTime);
- // prepare delayed
- BYTE byte1 = 0, byte2 = 0, byte3 = 0, byte4 = 0;
- byte1 = BREAK_UINT32(pCfg->m_SysCfgInfo.m_unPreAcquisitionDelayTime, 0);
- byte2 = BREAK_UINT32(pCfg->m_SysCfgInfo.m_unPreAcquisitionDelayTime, 1);
- byte3 = BREAK_UINT32(pCfg->m_SysCfgInfo.m_unPreAcquisitionDelayTime, 2);
- byte4 = BREAK_UINT32(pCfg->m_SysCfgInfo.m_unPreAcquisitionDelayTime, 3);
- nPrepareTime = BUILD_UINT32(byte4, byte3, byte2, byte1);
- FINFO("nPrepareTime:{$}ms", nPrepareTime);
- FINFO("commCfg._type:{$}", (int)commCfg._type);
- // Continuous acquisition time interval and frame rate calculation
- if (commCfg._type == UDP_COMM_TYPE || commCfg._type == WALN_COMM_TYPE)
- {
- byte1 = BREAK_UINT32(pCfg->m_SysCfgInfo.m_unContinuousAcquisitionSpanTime, 0);
- byte2 = BREAK_UINT32(pCfg->m_SysCfgInfo.m_unContinuousAcquisitionSpanTime, 1);
- byte3 = BREAK_UINT32(pCfg->m_SysCfgInfo.m_unContinuousAcquisitionSpanTime, 2);
- byte4 = BREAK_UINT32(pCfg->m_SysCfgInfo.m_unContinuousAcquisitionSpanTime, 3);
- }
- else
- {
- byte1 = BREAK_UINT32(pCfg->m_SysCfgInfo.m_unSelfDumpingSpanTime, 0);
- byte2 = BREAK_UINT32(pCfg->m_SysCfgInfo.m_unSelfDumpingSpanTime, 1);
- byte3 = BREAK_UINT32(pCfg->m_SysCfgInfo.m_unSelfDumpingSpanTime, 2);
- byte4 = BREAK_UINT32(pCfg->m_SysCfgInfo.m_unSelfDumpingSpanTime, 3);
- }
- nLiveAcqTime = BUILD_UINT32(byte4, byte3, byte2, byte1);
- if (nLiveAcqTime <= 0)
- {
- FWARN("live aqc time:{$}ms", nLiveAcqTime);
- nLiveAcqTime = 1000;
- }
- FINFO("nLiveAcqTime:{$}ms", nLiveAcqTime);
- unsigned int nMaxFps = (unsigned int)(1000 / nLiveAcqTime);
- if (nMaxFps <= 0) nMaxFps = 1;
- FINFO("nMaxFps:{$}", nMaxFps);
- //correction enable
- if (pCfg->m_ImgCaliCfg.m_byOffsetCorrection == 0x01)
- FINFO("Firmware offset correction disenable.[0x{$02X}]", pCfg->m_ImgCaliCfg.m_byOffsetCorrection);
- else if (pCfg->m_ImgCaliCfg.m_byOffsetCorrection == 0x02)
- FINFO("Firmware offset correction enable.[0x{$02X}]", pCfg->m_ImgCaliCfg.m_byOffsetCorrection);
- else
- FINFO("Firmware other offset correction enable.[0x{$02X}]", pCfg->m_ImgCaliCfg.m_byOffsetCorrection);
- if (pCfg->m_ImgCaliCfg.m_byGainCorrection == 0x01)
- FINFO("Firmware gain correction disenable.[0x{$02X}]", pCfg->m_ImgCaliCfg.m_byGainCorrection);
- else if (pCfg->m_ImgCaliCfg.m_byGainCorrection == 0x02)
- FINFO("Firmware gain correction enable.[0x{$02X}]", pCfg->m_ImgCaliCfg.m_byGainCorrection);
- else
- FINFO("Firmware gain offset correction enable.[0x{$02X}]", pCfg->m_ImgCaliCfg.m_byGainCorrection);
- if (pCfg->m_ImgCaliCfg.m_byDefectCorrection == 0x01)
- FINFO("Firmware defect correction disenable.[0x{$02X}]", pCfg->m_ImgCaliCfg.m_byDefectCorrection);
- else if (pCfg->m_ImgCaliCfg.m_byDefectCorrection == 0x02)
- FINFO("Firmware defect correction enable.[0x{$02X}]", pCfg->m_ImgCaliCfg.m_byDefectCorrection);
- else
- FINFO("Firmware defect offset correction enable.[0x{$02X}]", pCfg->m_ImgCaliCfg.m_byDefectCorrection);
- if (pCfg->m_ImgCaliCfg.m_byDummyCorrection == 0x01)
- FINFO("Firmware Dummy correction disenable.[0x{$02X}]", pCfg->m_ImgCaliCfg.m_byDummyCorrection);
- else if (pCfg->m_ImgCaliCfg.m_byDummyCorrection == 0x02)
- FINFO("Firmware Dummy correction enable.[0x{$02X}]", pCfg->m_ImgCaliCfg.m_byDummyCorrection);
- else
- FINFO("Firmware Dummy offset correction enable.[0x{$02X}]", pCfg->m_ImgCaliCfg.m_byDummyCorrection);
- // PGA level
- nPGALevel = GetPGA(pCfg->m_TICOFCfg.m_sTICOFRegister[26]);
- FINFO("nPGALevel:{$}", nPGALevel);
- }
- bool Detector_HaoBoRF::ConnectDetector()
- {
- printf("========ConnectDetector \n");
- FINFO("========ConnectDetector ");
- int nRet = HBI_SUCCSS;
- commCfg._type = UDP_JUMBO_COMM_TYPE;//标准网口,支持jumbo类型
- commCfg._loacalPort = 32896;
- commCfg._remotePort = 32897;
- memset(commCfg._localip, 0, sizeof(commCfg._localip));
- memset(commCfg._remoteip,0, sizeof(commCfg._remoteip));
- sprintf(commCfg._localip, "%s", "192.168.10.20");//本机IP
- sprintf(commCfg._remoteip, "%s", "192.168.10.40");//探测器IP
- int dooffsetTemplate = 0;
- FINFO("Calling HBI_ConnectDetector");
- nRet = HBI_ConnectDetector(m_nFpdHandle, commCfg, dooffsetTemplate);
- if (TestError(nRet,"HBI_ConnectDetector"))
- {
- FERROR("Connect detector fail!");
- return false;
- }
- return true;
- }
- //True 有错 false 没错
- bool Detector_HaoBoRF::TestError(int nErrorCode, const char* szFuncName)
- {
- if (nErrorCode)
- {
- string strErrorInfo = HBI_GetError(CrErrStrList, 51, nErrorCode);
- if (strErrorInfo.size() == 0)
- {
- FERROR("HBI_GetError fail! error code:{$}", nErrorCode);
- }
- else
- {
- FERROR("{$} return error {$}, reason: {$}", szFuncName, nErrorCode, strErrorInfo);
- }
- return true;
- }
- else
- {
- FINFO("{$} executed successfully", szFuncName);
- return false;
- }
- }
- bool Detector_HaoBoRF::GetPanelInfo()
- {
- FINFO("======GetPanelInfo");
- int nRet = HBI_SUCCSS;
- char serialNumber[20] = { 0 };
- FINFO("Call HBI_GetFPDSerialNumber");
- nRet = HBI_GetFPDSerialNumber(m_nFpdHandle, serialNumber);
- if (TestError(nRet,"HBI_GetFPDSerialNumber"))
- {
- return false;
- }
- FINFO("Detector SN:{$}",serialNumber);
- char sdkVersion[100] = { 0 };
- FINFO("Call HBI_GetSDKVerion");
- nRet = HBI_GetSDKVerion(m_nFpdHandle, sdkVersion);
- if (TestError(nRet, "HBI_GetSDKVerion"))
- {
- return false;
- }
- FINFO("Detector sdk version:{$}", sdkVersion);
- char firmwareVersion[100] = { 0 };
- FINFO("Call HBI_GetFirmareVerion");
- nRet = HBI_GetFirmareVerion(m_nFpdHandle, firmwareVersion);
- if (TestError(nRet, "HBI_GetFirmareVerion"))
- {
- return false;
- }
- FINFO("Detector firmware version:{$}", firmwareVersion);
- RegCfgInfo* pCfgInfo = new RegCfgInfo;
- memset(pCfgInfo, 0x00, sizeof(RegCfgInfo));
- FINFO("Call HBI_GetFirmareVerion");
- nRet = HBI_GetFpdCfgInfo(m_nFpdHandle, pCfgInfo);
- if (TestError(nRet, "HBI_GetFirmareVerion"))
- {
- return false;
- }
- PrintDetectorCfg(pCfgInfo);
- if (pCfgInfo)
- {
- delete pCfgInfo;
- pCfgInfo = nullptr;
- }
- IMAGE_PROPERTY* imageProperty = new ImageProperty();
- FINFO("Call HBI_GetImageProperty");
- nRet = HBI_GetImageProperty(m_nFpdHandle, imageProperty);
- if (TestError(nRet, "HBI_GetImageProperty"))
- {
- return false;
- }
- FINFO("FPD num:{$}, ImageWidth:{$}, ImageHeight:{$}, DataType:{$}, ImageBit:{$}, Endian:{$}, PacketSize:{$}, \
- FrameSize:{$}, TailPacketSize:{$}, CapacitySize:{$}",
- imageProperty->nFpdNum, imageProperty->nwidth, imageProperty->nheight, imageProperty->datatype, imageProperty->ndatabit,
- imageProperty->nendian, imageProperty->packet_size, imageProperty->frame_size, imageProperty->tailPacketSize, imageProperty->frame_number);
- if (imageProperty)
- {
- delete imageProperty;
- imageProperty = nullptr;
- }
- FINFO("Call HBI_IsMutilMode");
- bool bRet = HBI_IsMutilMode(m_nFpdHandle);
- if (bRet)
- {
- FINFO("Detector support multi mode!");
- }
- else
- {
- FINFO("Detector doesn't support multi mode!");
- }
- return true;
- }
- bool Detector_HaoBoRF::CalculateEXI(WORD* pImgData, int nImgWidth, int nImgHeight, int nImageBit, int nThreshold)
- {
- int nROIXL = static_cast<int>(0.3 * nImgWidth);
- int nROIXR = static_cast<int>(0.7 * nImgWidth);
- int nROIYL = static_cast<int>(0.3 * nImgHeight);
- int nROIYR = static_cast<int>(0.7 * nImgHeight);
- WORD* pSrc = NULL;
- long nCount = 0;
- DWORD64 nSum = 0;
- int nEXI = 0;
- try
- {
- for (int i = nROIYL; i < nROIYR; i++)
- {
- pSrc = pImgData + (i * nImgWidth);
- for (int j = nROIXL; j < nROIXR; j++)
- {
- nSum += *(pSrc + j);
- nCount++;
- }
- }
- nEXI = (int)(nSum / nCount);
- }
- catch (...)
- {
- return false;
- }
- FINFO("Image EXI:{$}, Threshold:{$}", nEXI, nThreshold);
- if (nEXI >= nThreshold)
- {
- FINFO("Image has xray!");
- return true;//有x射线
- }
- return false;
- }
- bool Detector_HaoBoRF::CheckImageExi(WORD* pImgData, int nImgWidth, int nImgHeight, WORD dwExiThrethold)
- {
- if (dwExiThrethold <= 0)
- {
- return true;
- }
- FINFO("Check image exi...");
- bool bResult = CalculateEXI(pImgData, nImgWidth, nImgHeight, 16, dwExiThrethold);
- if (bResult)
- {
- return true;
- }
- FINFO("Check image exi---black Image");
- return false;
- }
- //nIndex 缺省-1
- void Detector_HaoBoRF::OnProcessImage(int nWidth, int nHeight, int nFrameID)
- {
- printf("========OnProcessImage \n");
- FINFO("========OnProcessImage nWidth:{$},nHeight:{$},nIndex:{$}", nWidth, nHeight, nFrameID);
- int ret = 0;
- bool bImageCrop = false;
- if (m_nCropLeft != 0 || m_nCropTop != 0 || m_nCropRight != 0 || m_nCropBottom != 0)
- {
- ret = CropImageMargin(m_pFullImgBuffer, m_nImageWidth, m_nImageHeight,
- m_pRawImgBuffer, m_nRawImageWidth, m_nRawImageHeight, m_nImageBits,
- m_nCropLeft, m_nCropTop, m_nCropRight, m_nCropBottom);
- if (ret)
- {
- FERROR("CropImageMargin fail!!");
- }
- else
- {
- FINFO("CropImageMargin success!");
- bImageCrop = true;
- }
- }
- //上图之前回调图像的宽高,使得上层在拷贝内存时是正确的图像大小
- if (bImageCrop)
- {
- ConfFeedback(EVT_CONF_RAW_WIDTH, m_nCurrentPanelID, "", m_nImageWidth);
- ConfFeedback(EVT_CONF_RAW_HIGHT, m_nCurrentPanelID, "", m_nImageHeight);
- }
- else
- {
- ConfFeedback(EVT_CONF_RAW_WIDTH, m_nCurrentPanelID, "", m_nRawImageWidth);
- ConfFeedback(EVT_CONF_RAW_HIGHT, m_nCurrentPanelID, "", m_nRawImageHeight);
- }
- if (!m_bValidImage && m_nDelayTime > 0)
- {
- m_dwEndTime = GetTickCount64();
- }
- FINFO("OnProcessImage m_nDropImgNum:{$} m_nDropImgCount:{$}", m_nDropImgNum, m_nDropImgCount);
- if (m_nDropImgNum < m_nDropImgCount)//配置为0时表示不丢图
- {
- m_nDropImgNum++;
- FINFO("Drop {$} image", m_nDropImgNum);
- }
- else if (!CheckTimeLimit(m_dwBeginTime, m_dwEndTime))//m_nDelayTime 配置为0时表示不延时
- {
- m_nDropImgNum++;
- FERROR("CheckTimeLimit Drop {$} image", m_nDropImgNum);
- }
- else
- {
- if (m_bFirstImage)
- {
- FINFO("m_bFirstImage is true");
- StatusFeedback(EVT_STATUS_PANEL, PANEL_XWINDOW_ON);
- m_bFirstImage = false;
- }
- FINFO("OnProcessImage m_nCurrentLogicMode:{$}", m_nCurrentLogicMode);
- //560RF动态模式做点片
- if (m_nCurrentLogicMode == AcqMode::RAD)
- {
- FINFO("RAD mode");
- if (m_bValidImage)
- {
- //RAD模式已经推过图了就不在推图了
- FINFO("RAD has send one image! return");
- return;
- }
- if (bImageCrop)
- {
- //计算图像EXI 不满足的不往上推
- if (!CheckImageExi(m_pFullImgBuffer, m_nImageWidth, m_nImageHeight, m_nExiThreshold)) //true 有射线 false 没射线
- {
- return;
- }
- }
- else
- {
- //计算图像EXI 不满足的不往上推
- if (!CheckImageExi(m_pRawImgBuffer, m_nRawImageWidth, m_nRawImageHeight, m_nExiThreshold)) //true 有射线 false 没射线
- {
- return;
- }
- }
- }
-
- if (bImageCrop)
- {
- DataFeedback(EVT_DATA_RAW_IMAGE, m_pFullImgBuffer);
- }
- else
- {
- DataFeedback(EVT_DATA_RAW_IMAGE, m_pRawImgBuffer);
- }
- m_bValidImage = true; //合法图像,不再判断时间间隔
- }
- if (m_nSaveRaw)
- {
- SaveImage(nFrameID, bImageCrop);
- }
- }
- void Detector_HaoBoRF::SaveImage(int nIndex, bool bImageCrop)
- {
- FINFO("========Begin save image");
- char szTemp[30] = { 0 };
- FILE* fp;
- string strFileName = m_strCtrlWorkPath + "\\rawdata";
- if (-1 == nIndex)
- {
- strFileName += "\\Image_Rad.raw";
- }
- else
- {
- sprintf_s(szTemp, "\\Image_%d.raw", nIndex);
- strFileName += szTemp;
- }
- if ((fp = fopen(strFileName.c_str(), "wb+")) == NULL)
- {
- DWORD dw = GetLastError();
- FERROR("fopen {$} failed, {$}", strFileName, dw);
- return;
- }
- if (bImageCrop)
- {
- fwrite(m_pFullImgBuffer, sizeof(WORD), (ULONGLONG)m_nImageWidth * m_nImageHeight, fp);
- }
- else
- {
- fwrite(m_pRawImgBuffer, sizeof(WORD), (ULONGLONG)m_nRawImageWidth * m_nRawImageHeight, fp);
- }
-
- fclose(fp);
- FINFO("Save {$} image over", strFileName);
- }
- // 说明:调用SDK接口,执行offset校正流程 dark校正、闲时offset刷新都会调用这个函数
- bool Detector_HaoBoRF::StartDarkCalibration()
- {
- printf("========StartDarkCalibration \n");
- FINFO("========StartDarkCalibration");
- FINFO("Call HBI_GenerateTemplate");
- int ret = HBI_GenerateTemplate(m_nFpdHandle, OFFSET_TEMPLATE_TYPE, 0);
- if (TestError(ret,"HBI_GenerateTemplate"))
- {
- return false;
- }
- return true;
- }
- bool Detector_HaoBoRF::StartGainCalibration()
- {
- printf("========StartGainCalibration \n");
- FINFO("========StartGainCalibration ");
- if (-1 == m_nCurrentLogicMode)
- {
- FERROR("Illegal exam mode");
- return false;
- }
-
- return true;
- }
- unsigned __stdcall Detector_HaoBoRF::onFPDScanThread(PVOID pvoid)
- {
- Detector_HaoBoRF* pOpr = (Detector_HaoBoRF*)pvoid;
- FINFO("Enter scan thread");
- bool bExit = false;
- while (!bExit)
- {
- DWORD dwRet = WaitForMultipleObjects(SCAN_EVENT_COUNT, pOpr->m_hArrayEvent, FALSE, INFINITE);
- if (WAIT_OBJECT_0 == dwRet) //m_hStopScanEvent
- {
- bExit = true;
- }
- else if (WAIT_OBJECT_0 + 1 == dwRet) //m_hAcqEvent
- {
- pOpr->OnAcquireImage();
- }
- else if (WAIT_OBJECT_0 + 2 == dwRet) //m_hGainEvent
- {
- pOpr->OnAcquireGainImage();
- }
- else if (WAIT_OBJECT_0 + 3 == dwRet) //m_hDarkEvent
- {
- pOpr->OnStartDarkCalibration();
- }
- else if (WAIT_OBJECT_0 + 4 == dwRet) //m_hProcessImgEvent
- {
- pOpr->OnProcessImage(pOpr->m_nRawImageWidth, pOpr->m_nRawImageHeight, pOpr->m_nFrameID);
- }
- }
- FINFO("Level scan thread");
- return 0;
- }
- unsigned __stdcall Detector_HaoBoRF::RefreshOffsetThread(PVOID pvoid)
- {
- Detector_HaoBoRF* pOpr = (Detector_HaoBoRF*)pvoid;
- FINFO("========Enter fresh offset thread");
- bool bExit = false;
- while (!bExit)
- {
- DWORD dwRet = WaitForMultipleObjects(OFFSET_EVENT_COUNT, pOpr->m_hOffsetEvent, FALSE, INFINITE);
- if (WAIT_OBJECT_0 == dwRet) //m_hStopOffsetEvent
- {
- bExit = true;
- }
- else if (WAIT_OBJECT_0 + 1 == dwRet) //m_hStartAllOffset
- {
- pOpr->RefreshAllOffset();
- }
- else if (WAIT_OBJECT_0 + 2 == dwRet) //m_hStartOffset
- {
- pOpr->OnRefreshOffset();
- }
- else if (WAIT_OBJECT_0 + 3 == dwRet) //m_hAbortOffset
- {
- pOpr->AbortFreshOffset();
- }
- }
- FINFO("Level fresh offset thread");
- return 0;
- }
- //1800RF支持单独的RAD模式
- void Detector_HaoBoRF::OnAcquireImage()
- {
- printf("========OnAcquireImage \n");
- FINFO("========OnAcquireImage ");
- SetDpcStatus(DetStatus_Acquire); //动态模式激活采集,设置状态
- SetDpcStatus(DetStatus_Standby); //rad采集失败,设置状态
- }
- //SDK Rad模式增益校正流程
- void Detector_HaoBoRF::OnAcquireGainImage()
- {
- printf("========OnAcquireGainImage \n");
- FINFO("========OnAcquireGainImage ");
- SetDpcStatus(DetStatus_Standby);
- StatusFeedback(EVT_STATUS_CALIBRATIOIN, PANEL_EVENT_END_OK);
- }
- //说明:开始暗场校正
- void Detector_HaoBoRF::OnStartDarkCalibration()
- {
- printf("========OnStartDarkCalibration \n");
- FINFO("========OnStartDarkCalibration ");
- SetDpcStatus(DetStatus_OffsetCalibration); //开始offset校正
- if (StartDarkCalibration())
- {
- StatusFeedback(EVT_STATUS_CALIBRATIOIN, PANEL_EVENT_END_OK);
- }
- else
- {
- StatusFeedback(EVT_STATUS_CALIBRATIOIN, PANEL_EVENT_END_ERROR);
- }
- SetDpcStatus(DetStatus_Standby); //offset校正完成,置回Standby
- }
- //获取只用于本DPC记录的探测器状态
- eDetStatus Detector_HaoBoRF::GetDpcStatus()
- {
- string strStatus = "Unknown";
- switch (m_eStatus)
- {
- case DetStatus_NotIni:
- strStatus = "NotIni";
- break;
- case DetStatus_NotConn:
- strStatus = "NotConn";
- break;
- case DetStatus_Sleep:
- strStatus = "Sleep";
- break;
- case DetStatus_Standby:
- strStatus = "Standby";
- break;
- case DetStatus_Acquire:
- strStatus = "Acquire";
- break;
- case DetStatus_OffsetCalibration:
- strStatus = "OffsetCalibration";
- break;
- case DetStatus_GainCalibration:
- strStatus = "GainCalibration";
- break;
- default:
- break;
- }
- FINFO("Driver status: {$}", strStatus.c_str());
- return m_eStatus;
- }
- //设置只用于本DPC的探测器状态
- bool Detector_HaoBoRF::SetDpcStatus(eDetStatus status)
- {
- string strStatus = "Unknown";
- bool bSetStatus = true;
- switch (status)
- {
- case DetStatus_NotIni:
- strStatus = "NotIni";
- break;
- case DetStatus_NotConn:
- strStatus = "NotConn";
- break;
- case DetStatus_Sleep:
- strStatus = "Sleep";
- break;
- case DetStatus_Standby:
- strStatus = "Standby";
- break;
- case DetStatus_Acquire:
- strStatus = "Acquire";
- break;
- case DetStatus_OffsetCalibration:
- strStatus = "OffsetCalibration";
- break;
- case DetStatus_GainCalibration:
- strStatus = "GainCalibration";
- break;
- default:
- bSetStatus = false;
- break;
- }
- if (bSetStatus)
- {
- m_eStatus = status;
- FINFO("Set driver status: {$}", strStatus.c_str());
- }
- else
- {
- FERROR("{$} {$} is a illegal status", strStatus.c_str(), (int)status);
- }
- return bSetStatus;
- }
- bool Detector_HaoBoRF::LoadCalibrationFiles()
- {
- FINFO("========LoadCalibrationFiles");
-
- return true;
- }
- //参照RFOC康众动态代码整理的图像裁剪功能
- int Detector_HaoBoRF::CropImageMargin(LPVOID pDstData, int& nDstWidth, int& nDstHeight,
- LPVOID pScrData, int nSrcWidth, int nSrcHeight, int nBits,
- int nLeftMargin, int nTopMargin, int nRightMargin, int nBottomMargin)
- {
- printf("========CropImageMargin \n");
- FINFO("========CropImageMargin ");
- if ((pDstData == NULL) || (pScrData == NULL) || (nSrcWidth <= 0) || (nSrcHeight <= 0) || (nBits <= 0))
- return -1;
- if ((nLeftMargin >= nSrcWidth) || (nTopMargin >= nSrcHeight))
- return -1;
- int nBitsToBYTE = (int)((nBits + 7) * 0.125);
- if (nBitsToBYTE < 1)
- return -1;
- int nXL, nXR, nYL, nYR;
- nXL = nLeftMargin;//32
- nYL = nTopMargin;
- if (nSrcWidth - nRightMargin < 0)
- return -1;
- nXR = nSrcWidth - nRightMargin - 1; //2783
- if (nXR < nXL)
- return -1;
- if (nSrcHeight - nBottomMargin < 0)
- return -1;
- nYR = nSrcHeight - nBottomMargin - 1;
- if (nYR < nYL)
- return -1;
- nDstWidth = nXR - nXL + 1;
- nDstHeight = nYR - nYL + 1;
- FINFO("TopCrop:{$};Bottom:{$},nDstWidth:{$},nDstHeight:{$},Bits:{$}", nYL, nYR, nDstWidth, nDstHeight, nBitsToBYTE);
- int i = 0;
- #pragma omp parallel private(i)
- {
- #pragma omp for
- for (i = nYL; i <= nYR; i++)
- {
- ::memcpy((WORD*)pDstData + (i - nYL) * nDstWidth, (WORD*)pScrData + (i * nSrcWidth + nXL), nDstWidth * nBitsToBYTE);
- }
- }
- return 0;
- }
- //说明:初始化时刷新所有模式的offset 配置文件的OffsetInterval配置为0时则不会运行此段代码
- bool Detector_HaoBoRF::RefreshAllOffset()
- {
- printf("========Refresh all mode offset begin \n");
- FINFO("========Refresh all mode offset begin");
- bool bRet = false;
- SetDpcStatus(DetStatus_OffsetCalibration); //开始全模式offset刷新
- StatusFeedback(EVT_STATUS_OFFSET, PANEL_EVENT_START);
- StatusFeedback(EVT_STATUS_OFFSET_PROGRESS, 0);
- bRet = StartDarkCalibration(); //当前mode失败,仍可以进行下一个mode的刷新
- if (!bRet)
- {
- FERROR("RefreshAllOffset StartDarkCalibration failed!");
- StatusFeedback(EVT_STATUS_OFFSET, PANEL_EVENT_END_ERROR);
- }
- StatusFeedback(EVT_STATUS_OFFSET_PROGRESS, 1);
- SetDpcStatus(DetStatus_Standby); //全模式offset刷新结束,置回Standby
- StatusFeedback(EVT_STATUS_OFFSET, PANEL_EVENT_END_OK);
- FINFO("Refresh all mode offset over");
- return bRet;
- }
- //说明:刷当前模式的offset,什么时候刷由前端控制
- void Detector_HaoBoRF::OnRefreshOffset()
- {
- FINFO("========OnRefreshOffset begin");
- bool bRet = false;
- SetDpcStatus(DetStatus_OffsetCalibration);
- StatusFeedback(EVT_STATUS_OFFSET_PROGRESS, 0);
- StatusFeedback(EVT_STATUS_OFFSET, PANEL_EVENT_START);
-
- bRet = StartDarkCalibration();
- if (bRet)
- {
- StatusFeedback(EVT_STATUS_OFFSET_PROGRESS, 1);
- }
- else
- {
- FERROR("OnRefreshOffset StartDarkCalibration failed!");
- StatusFeedback(EVT_STATUS_OFFSET, PANEL_EVENT_END_ERROR);
- }
- SetDpcStatus(DetStatus_Standby);
- StatusFeedback(EVT_STATUS_OFFSET, PANEL_EVENT_END_OK);
- FINFO("OnRefreshOffset over");
- }
- bool Detector_HaoBoRF::CheckTimeLimit(ULONGLONG dwBeginTime, ULONGLONG dwEndTime)
- {
- if (m_bValidImage) //合法图像,不再判断时间间隔,直接返回true
- {
- FINFO("CheckTimeLimit m_bValidImage is true!");
- return true;
- }
- if (m_nDelayTime == 0) //没有开启延时机制
- {
- FINFO("The delay time is invalid, return");
- return true;
- }
- if ((int)(dwEndTime - dwBeginTime) > m_nDelayTime)
- {
- FINFO("The interval({$}) is ok", dwEndTime - dwBeginTime);
- return true;
- }
- FERROR("The interval({$}) is shorter than the delay({$})",dwEndTime - dwBeginTime, m_nDelayTime);
- return false;
- }
- void Detector_HaoBoRF::ConfFeedback(int nEventID, int nDetectorID, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
- {
- if (-1 == nDetectorID)
- {
- nDetectorID = m_nCurrentPanelID;
- }
- ((FPDDeviceHaoBo*)(*m_pPanelID2DPC)[nDetectorID])->OnFPDCallback(nDetectorID,
- nEventID, EVT_LEVEL_CONFIGURATION, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
- }
- void Detector_HaoBoRF::InfoFeedback(int nEventID, int nDetectorID, int nParam1, float fParam2, const char* pszMsg, int nPtrParamLen, void* pParam)
- {
- if (-1 == nDetectorID)
- {
- nDetectorID = m_nCurrentPanelID;
- }
- ((FPDDeviceHaoBo*)(*m_pPanelID2DPC)[nDetectorID])->OnFPDCallback(nDetectorID,
- nEventID, EVT_LEVEL_INFORMATOION, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
- }
- void Detector_HaoBoRF::StatusFeedback(int nEventID, int nParam1, const char* pszMsg, int nDetectorID, float fParam2, int nPtrParamLen, void* pParam)
- {
- if (-1 == nDetectorID)
- {
- nDetectorID = m_nCurrentPanelID;
- }
- ((FPDDeviceHaoBo*)(*m_pPanelID2DPC)[nDetectorID])->OnFPDCallback(nDetectorID,
- nEventID, EVT_LEVEL_STATUS, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
- }
- void Detector_HaoBoRF::DataFeedback(int nEventID, void* pParam, int nParam1, float fParam2, const char* pszMsg, int nPtrParamLen, int nDetectorID)
- {
- if (-1 == nDetectorID)
- {
- nDetectorID = m_nCurrentPanelID;
- }
- ((FPDDeviceHaoBo*)(*m_pPanelID2DPC)[nDetectorID])->OnFPDCallback(nDetectorID,
- nEventID, EVT_LEVEL_DATA, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
- }
- void Detector_HaoBoRF::WarnFeedback(int nEventID, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam, int nDetectorID)
- {
- if (-1 == nDetectorID)
- {
- nDetectorID = m_nCurrentPanelID;
- }
- ((FPDDeviceHaoBo*)(*m_pPanelID2DPC)[nDetectorID])->OnFPDCallback(nDetectorID,
- nEventID, EVT_LEVEL_WARNING, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
- }
- void Detector_HaoBoRF::ErrorFeedback(int nEventID, const char* pszMsg, int nDetectorID, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
- {
- if (-1 == nDetectorID)
- {
- nDetectorID = m_nCurrentPanelID;
- }
- ((FPDDeviceHaoBo*)(*m_pPanelID2DPC)[nDetectorID])->OnFPDCallback(nDetectorID,
- nEventID, EVT_LEVEL_ERROR, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
- }
- float Detector_HaoBoRF::SetFluPPS(float fPPS)
- {
- FINFO("========SetFluPPS {$}", fPPS);
- m_fFrameRate = fPPS;
- return m_fFrameRate;
- }
- void Detector_HaoBoRF::GetFluPPS(float& fFluPPS)
- {
- fFluPPS = m_fFrameRate;
- FINFO("========GetFluPPS {$}", fFluPPS);
- }
- void Detector_HaoBoRF::AbortFreshOffset()
- {
- FINFO("========AbortFreshOffset");
- }
- void Detector_HaoBoRF::SetAbortOffsetEvent()
- {
- FINFO("========SetAbortOffsetEvent");
- SetEvent(m_hAbortOffset);
- }
- void Detector_HaoBoRF::SetFreshAllOffsetEvent()
- {
- FINFO("========SetFreshAllOffsetEvent");
- SetEvent(m_hStartAllOffset);
- }
- void Detector_HaoBoRF::SetfreshOffsetEvent()
- {
- FINFO("========SetfreshOffsetEvent");
- SetEvent(m_hStartOffset);
- }
- void Detector_HaoBoRF::UpdateModeInRunning(int nMode, float fFrequency)
- {
- FINFO("========UpdateModeInRunning ModeID:{$},Frequency:{$}", nMode, fFrequency);
- m_nModeID = nMode;
- m_fFrameRate = fFrequency;
- }
|