IRayCtrl.cpp 122 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312
  1. #include "stdafx.h"
  2. #include <tlhelp32.h>
  3. #include "sys\stat.h"
  4. #include <fstream> //文件流库函数
  5. #include <atlcomtime.h>
  6. #include "IRayCtrl.h"
  7. #include "common_api.h"
  8. #include "CiniFile.h"
  9. #include "MyPingip.h"
  10. #include "CiniFile.h"
  11. extern Log4CPP::Logger* gLogger;
  12. #include <shlwapi.h>
  13. #pragma comment(lib,"Shlwapi.lib")
  14. #pragma comment(lib, "Version.lib")
  15. const int nINIT_TIME = 50000;
  16. const int nCMD_TIME = 5000;
  17. IRayCtrl* g_pIRayCtrl = NULL;
  18. void SDKCallbackProxy(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, int nParam2, int nPtrParamLen, void* pParam)
  19. {
  20. g_pIRayCtrl->ProcessEvent(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, nParam2, nPtrParamLen, pParam);
  21. }
  22. #define MAX_STRING 1024
  23. IRayCtrl::IRayCtrl()
  24. : g_strAppPath("")
  25. , m_nPanelCount(0)
  26. , m_nDetectorID(1)
  27. , m_nDetectorIndex(0)
  28. , m_nCorrectionType(0)
  29. , m_hIRayModule(nullptr)
  30. , m_fpCreate(nullptr)
  31. , m_fpDestroy(nullptr)
  32. , m_fpGetAttr(nullptr)
  33. , m_fpSetAttr(nullptr)
  34. , m_fpInvoke(nullptr)
  35. , m_pRegisterScanNotify(nullptr)
  36. , m_pScanOnce(nullptr)
  37. , m_pFnGetErrorInfo(nullptr)
  38. , m_pfAbort(nullptr)
  39. , m_pfOpenDefectTemplateFile(nullptr)
  40. , m_pfCloseDefectTemplateFile(nullptr)
  41. , m_hInitThread(nullptr)
  42. , m_hExitEvent(nullptr)
  43. , m_hRecoverImage(nullptr)
  44. , m_hCofirmCalib(nullptr)
  45. , m_hEndCalibEvent(nullptr)
  46. , m_hIRayScanEnd(nullptr)
  47. , m_hSharedEvent(nullptr)
  48. , m_hWindowOffEvent(nullptr)
  49. , m_pXWindowoffThread(nullptr)
  50. , m_hScanEventThread(nullptr)
  51. , m_nCurrentMode(-1)
  52. , m_strCurrentExamType("")
  53. , m_bSaveRaw(false)
  54. , m_pwPreviewImg(nullptr)
  55. , m_pwRawImageData(nullptr)
  56. , m_nFrameID(0)
  57. , m_nExiThreshold(0)
  58. , m_bOffsetAll(false)
  59. , m_bGrabStatus(false)
  60. , m_nUpdateFPDID(-1)
  61. , m_fFrameRate(0.0f)
  62. {
  63. m_pDPC2PanelID = new map<nsDPC::FPDDeviceIRay*, int>();
  64. m_pPanelID2DPC = new map<int, nsDPC::FPDDeviceIRay*>();
  65. //m_pImageBuffer = NULL;
  66. m_strWorkPath = "";
  67. m_eAppStatus = APP_STATUS_IDLE;
  68. m_nImageWidth = 0;
  69. m_nImageHeight = 0;
  70. m_nRawImgWidth = 0;
  71. m_nRawImgHeight = 0;
  72. m_nWidthOffset = 0;
  73. m_nHeightOffset = 0;
  74. m_nImgBits = 16;
  75. m_nPixelPitch = 150;
  76. m_bPreviewEnable = false;
  77. m_nPreviewWidth = 0;
  78. m_nPreviewHeight = 0;
  79. m_eCaliType = CCOS_CALIBRATION_TYPE_NONE;
  80. m_nDoseParam = 0;
  81. m_fCurrentDose = 0;
  82. m_nCaliFailedCount = 0;
  83. m_bGainPreparing = false;
  84. m_bGainProcess = false;
  85. m_bConfirmCaliRst = false;
  86. m_bPreviewImg = false;
  87. //m_nGainNodeCount = 0;
  88. //m_nGainNodeIndex = 0;
  89. //m_nGainExpCount = 0;
  90. //m_nGainExpIndex = 0;
  91. m_bIsImageRecovering = false;
  92. m_bInCalibrating = false;
  93. m_bFDAttaching = false;
  94. m_pHardwareStatusThread = NULL;
  95. m_bFirmwareUpdating = false;
  96. m_bInExposure = false;
  97. m_bWindowOn = false;
  98. m_nRecoverImageTimes = 0;
  99. m_bImageRecoverBeCanceled = false;
  100. for (int i = 0; i < IRAY_SCAN_NUM; i++)
  101. {
  102. m_hArrayEvent[i] = nullptr;
  103. }
  104. m_bSetCorrectFile = false;
  105. m_mapLogicModeOperationMode.clear();
  106. }
  107. IRayCtrl::~IRayCtrl()
  108. {
  109. OnEXIT();
  110. delete m_pDPC2PanelID;
  111. m_pDPC2PanelID = NULL;
  112. delete m_pPanelID2DPC;
  113. m_pPanelID2DPC = NULL;
  114. m_mapLogicModeOperationMode.clear();
  115. }
  116. bool IRayCtrl::OnEXIT()
  117. {
  118. SetEvent(m_hEndHWStatusThreadEvent);
  119. Info("Waiting HWStatus Thread End");
  120. int nResult = WaitForSingleObject(m_hHWStatusThreadEndEvent, 10000);
  121. if (WAIT_TIMEOUT == nResult)
  122. {
  123. Error("iRay HWStatus Thread Quit Failed");
  124. }
  125. else
  126. {
  127. Info("iRay HWStatus Thread Quit Success");
  128. }
  129. for (int nDetectorID = 0; nDetectorID < m_nPanelCount; nDetectorID++)
  130. {
  131. DisconnectFD(nDetectorID); //两块板都断开,防止系统异常退出后,再次启动系统后没有释放socket的连接无法再次连接。
  132. }
  133. SetEvent(m_hExitEvent);
  134. Info("Waiting iRay ScanEvent Thread End");
  135. nResult = WaitForSingleObject(m_hIRayScanEnd, 2000);
  136. if (WAIT_TIMEOUT == nResult)
  137. {
  138. Error("iRay ScanEvent Thread Quit Failed");
  139. }
  140. else
  141. {
  142. Info("iRay ScanEvent Thread Quit Success");
  143. }
  144. DeleteHandle();
  145. Info("Free IRay DLL");
  146. FreeIRayDLL();
  147. return true;
  148. }
  149. void IRayCtrl::DeleteHandle()
  150. {
  151. if (m_hSharedEvent)
  152. {
  153. CloseHandle(m_hSharedEvent);
  154. m_hSharedEvent = nullptr;
  155. }
  156. if (m_hExitEvent)
  157. {
  158. CloseHandle(m_hExitEvent);
  159. m_hExitEvent = nullptr;
  160. }
  161. if (m_hRecoverImage)
  162. {
  163. CloseHandle(m_hRecoverImage);
  164. m_hRecoverImage = nullptr;
  165. }
  166. if (m_hCofirmCalib)
  167. {
  168. CloseHandle(m_hCofirmCalib);
  169. m_hCofirmCalib = nullptr;
  170. }
  171. if (m_hEndCalibEvent)
  172. {
  173. CloseHandle(m_hEndCalibEvent);
  174. m_hEndCalibEvent = nullptr;
  175. }
  176. if (m_hIRayScanEnd)
  177. {
  178. CloseHandle(m_hIRayScanEnd);
  179. m_hIRayScanEnd = nullptr;
  180. }
  181. if (m_hHWStatusThreadEndEvent)
  182. {
  183. CloseHandle(m_hHWStatusThreadEndEvent);
  184. m_hHWStatusThreadEndEvent = NULL;
  185. }
  186. if (m_pwPreviewImg)
  187. {
  188. delete[] m_pwPreviewImg;
  189. m_pwPreviewImg = NULL;
  190. }
  191. if (m_pwRawImageData)
  192. {
  193. delete[] m_pwRawImageData;
  194. m_pwRawImageData = NULL;
  195. }
  196. }
  197. FPDRESULT IRayCtrl::IrayFnInvoke(int nDetectorID, int nCommandID, IRayCmdParam pars[], int nParCount)
  198. {
  199. int trytimes = 0;
  200. FPDRESULT nResult = Err_OK;
  201. while (trytimes++ < 6)
  202. {
  203. nResult = m_fpInvoke(nDetectorID, nCommandID, pars, nParCount);
  204. if (Err_StateErr != nResult)
  205. return nResult;
  206. else
  207. Sleep(1000);
  208. }
  209. return nResult;
  210. }
  211. //SDK回调函数
  212. void IRayCtrl::ProcessEvent(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, int nParam2, int nPtrParamLen, void* pParam)
  213. {
  214. string strDescrip = pszMsg;
  215. Info("DetectorID:{$},Event:{$},Param1:{$},Param2:{$},Description:{$}", nDetectorID, nEventID, nParam1, nParam2, strDescrip.c_str());
  216. switch (nEventID)
  217. {
  218. case Evt_GeneralWarn:
  219. Warn("[ Evt_GeneralWarn ]");
  220. break;
  221. case Evt_OffsetAmassingTime:
  222. {
  223. Info("[ Evt_OffsetAmassingTime ]");
  224. }
  225. break;
  226. case Evt_Exp_Prohibit:
  227. {
  228. Info("[ Event:Evt_Exp_Prohibit ]");
  229. }
  230. break;
  231. case Evt_Exp_Enable:
  232. {
  233. Info("[ Event:Evt_Exp_Enable ]");
  234. m_bWindowOn = true;
  235. StatusFeedback(EVT_STATUS_PANEL, PANEL_XWINDOW_ON);
  236. }
  237. break;
  238. case Evt_TaskResult_Canceled:
  239. {
  240. Info("[ Evt_TaskResult_Canceled ]");
  241. OnProcessTaskResult2(nDetectorID, nParam1, nParam2, false);
  242. }
  243. break;
  244. case Evt_AutoTask_Started:
  245. {
  246. Info("[ Evt_AutoTask_Started ]");
  247. OnProcessTaskResult2(nDetectorID, nParam1, nParam2, true);
  248. }
  249. break;
  250. case Evt_TaskResult_Succeed:
  251. OnProcessTaskResult(nDetectorID, nParam1, nParam2, true);
  252. break;
  253. case Evt_TaskResult_Failed:
  254. OnProcessTaskResult(nDetectorID, nParam1, nParam2, false);
  255. break;
  256. case Evt_TemplateFileUpload_Result:
  257. break;
  258. case Evt_LivingTime:
  259. {
  260. Info("[ Event:Evt_LivingTime ]");
  261. break;
  262. }
  263. case Evt_Retransfer_Image:
  264. {
  265. Info("[ Event:Evt_Retransfer_Image ],Omit it");
  266. }
  267. break;
  268. case Evt_Image:
  269. {
  270. Info("[ Event:Evt_Image ]");
  271. IRayImage* pstImg = (IRayImage*)pParam;
  272. if (pstImg == NULL)
  273. {
  274. Fatal("Image Data is NULL");
  275. return;
  276. }
  277. if (!m_bGrabStatus)
  278. {
  279. Warn("Invalid image, omit");
  280. return;
  281. }
  282. int nRawImgHeight = pstImg->nHeight;
  283. int nRawImgWidth = pstImg->nWidth;
  284. Info("Image Height:{$},Width:{$}", nRawImgHeight, nRawImgWidth);
  285. memcpy(m_pwRawImageData, pstImg->pData, nRawImgHeight * nRawImgWidth * sizeof(WORD));
  286. OnProcessImg();
  287. }
  288. break;
  289. case Evt_Prev_Image:
  290. {
  291. Info("[ Event:Evt_Prev_Image ]");
  292. IRayImage* pstImg = (IRayImage*)pParam;
  293. m_stDeviceIndex[nDetectorID - 1].nImageBits = pstImg->nBytesPerPixel * 8;
  294. int nPreviewHeight = pstImg->nHeight;
  295. int nPreviewWidth = pstImg->nWidth;
  296. if (m_pwPreviewImg != NULL)
  297. {
  298. delete[] m_pwPreviewImg;
  299. m_pwPreviewImg = NULL;
  300. }
  301. if (m_pwPreviewImg == NULL)
  302. {
  303. m_pwPreviewImg = new WORD[nPreviewHeight * nPreviewWidth];
  304. if (m_pwPreviewImg == NULL)
  305. {
  306. Fatal("Allocate Preview Image Memery Failed");
  307. return;
  308. }
  309. }
  310. memcpy(m_pwPreviewImg, pstImg->pData, nPreviewHeight * nPreviewWidth * sizeof(WORD));
  311. if (m_stDeviceIndex[nDetectorID - 1].strDeviceName.find("1717X") >= 0)
  312. {
  313. FlipX(m_pwPreviewImg, nPreviewWidth, nPreviewHeight);
  314. }
  315. else
  316. {
  317. FlipXRotate90(m_pwPreviewImg, nPreviewWidth, nPreviewHeight);
  318. }
  319. OnProcessPreImg();
  320. }
  321. break;
  322. case Evt_LastImageID:
  323. {
  324. int nImageID = nParam1;
  325. bool bTranslatedSuccess = nParam2 ? true : false;
  326. Info("Last ImageID:{$},is Transfered:{$}", nParam1, bTranslatedSuccess);
  327. m_stDeviceIndex[nDetectorID - 1].nLastImageID = nParam1;
  328. m_stDeviceIndex[nDetectorID - 1].bImagePending = !bTranslatedSuccess;
  329. }
  330. break;
  331. case Evt_TemperatureHigh:
  332. {
  333. Info("[ Evt_TemperatureHigh ]");
  334. }
  335. break;
  336. case Evt_LowBattery:
  337. {
  338. Info("[ Evt_LowBattery ]");
  339. }
  340. break;
  341. case Evt_WaitImage_Timeout:
  342. {
  343. Info("[ Evt_WaitImage_Timeout ],Omit");
  344. }
  345. break;
  346. case Evt_Exp_Timeout:
  347. {
  348. Info("[ Evt_Exp_Timeout ]");
  349. }
  350. break;
  351. default:
  352. break;
  353. }
  354. }
  355. void IRayCtrl::OnProcessTaskResult2(int nDetectorID, int nParam1, int nParam2, bool bResult)
  356. {
  357. string strTaskResult = " Task Started";
  358. if (!bResult)
  359. {
  360. strTaskResult = " Task Canceled";
  361. }
  362. switch (nParam1)
  363. {
  364. case Cmd_GainInit:
  365. {
  366. Info("Cmd_GainInit {$}", strTaskResult.c_str());
  367. SendNotify();
  368. }
  369. break;
  370. case Cmd_DefectInit:
  371. {
  372. Info("Cmd_DefectInit {$}", strTaskResult.c_str());
  373. SendNotify();
  374. }
  375. break;
  376. case Cmd_OffsetGeneration:
  377. {
  378. Info("Cmd_OffsetGeneration{$}", strTaskResult.c_str());
  379. SendNotify();
  380. }
  381. break;
  382. }
  383. }
  384. void IRayCtrl::OnProcessTaskResult(int nDetectorID, int nParam1, int nParam2, bool bResult)
  385. {
  386. int nDetectorIndex = nDetectorID - 1;
  387. string strTaskResult = " Task Success";
  388. if (!bResult)
  389. {
  390. strTaskResult = " Task Failed";
  391. }
  392. switch (nParam1)
  393. {
  394. case 0:
  395. {
  396. TestError(nDetectorID, nParam2);
  397. if (Err_TemplateFileNotExist == nParam2) //暂时把该Error作为 Cmd_SetCorrectOption的返回
  398. {
  399. }
  400. }
  401. break;
  402. case Cmd_Disconnect:
  403. {
  404. Info("FPD {$} is Disconnected", nDetectorID);
  405. SendNotify();
  406. m_stDeviceIndex[nDetectorIndex].bConnectStatus = false;
  407. //SendDetectorInfo(nDetectorID); //状态栏图标更新状态
  408. }
  409. break;
  410. case Cmd_Connect:
  411. {
  412. Info("[ Cmd_Connect ]");
  413. if (bResult)
  414. {
  415. Info("FPD {$} is Connected", nDetectorID);
  416. m_stDeviceIndex[nDetectorIndex].bConnectStatus = true;
  417. m_stDeviceIndex[nDetectorIndex].bConnectChanged = true; //连接恢复之后,都要先查询一次有没有未传输成功的图像
  418. m_nCmdConnectResult = nParam2;
  419. ErrorFeedback(EVT_ERR_COMMUNICATE, "false", nDetectorID);
  420. }
  421. else
  422. {
  423. m_stDeviceIndex[nDetectorIndex].bConnectStatus = false;
  424. Fatal("FPD {$} connect failed", nDetectorID);
  425. ErrorFeedback(EVT_ERR_COMMUNICATE, "true", nDetectorID);
  426. m_nCmdConnectResult = nParam2;
  427. }
  428. SendNotify();
  429. }
  430. break;
  431. case Cmd_SetCaliSubset:
  432. {
  433. Info("Cmd_SetCaliSubset{$}", strTaskResult);
  434. SendNotify();
  435. }
  436. break;
  437. case Cmd_Acq2:
  438. Info("[ Cmd_Acq2 ]");
  439. break;
  440. case Cmd_SyncStart:
  441. Info("Cmd_SyncStart");
  442. break;
  443. case Cmd_SyncCancel:
  444. Info("Cmd_SyncCancel");
  445. break;
  446. case Cmd_SyncAcq:
  447. Info("Cmd_SyncAcq");
  448. break;
  449. case Cmd_ReadUserROM:
  450. Info("[ Cmd_ReadUserROM ]");
  451. break;
  452. case Cmd_WriteUserROM:
  453. {
  454. m_stDeviceIndex[nDetectorIndex].bWriteROM = bResult;
  455. Info("Cmd_WriteUserROM {$}", strTaskResult.c_str());
  456. SendNotify();
  457. }
  458. break;
  459. case Cmd_OffsetGeneration:
  460. {
  461. Info("Cmd_OffsetGeneration{$}", strTaskResult.c_str());
  462. SendNotify();
  463. }
  464. break;
  465. case Cmd_GainInit:
  466. {
  467. Info("Cmd_GainInit{$}", strTaskResult.c_str());
  468. SendNotify();
  469. }
  470. break;
  471. case Cmd_DefectInit:
  472. {
  473. Info("Cmd_DefectInit{$}", strTaskResult.c_str());
  474. SendNotify();
  475. }
  476. break;
  477. case Cmd_DefectSelectCurrent:
  478. {
  479. Info("Cmd_DefectSelectCurrent{$}", strTaskResult.c_str());
  480. SendNotify();
  481. }
  482. break;
  483. case Cmd_FinishGenerationProcess:
  484. {
  485. Info("Cmd_FinishGenerationProcess{$}", strTaskResult.c_str());
  486. SendNotify();
  487. }
  488. break;
  489. case Cmd_UpdateFirmware:
  490. {
  491. Info("Cmd_UpdateFirmware{$}", strTaskResult.c_str());
  492. m_stDeviceIndex[nDetectorIndex].bUpdateFirmware = bResult;
  493. if (TestError(nDetectorID, nParam2))
  494. {
  495. SendNotify();
  496. }
  497. }
  498. break;
  499. case Cmd_ReadTemperature:
  500. {
  501. Info("Cmd_ReadTemperature{$}", strTaskResult.c_str());
  502. SendNotify();
  503. }
  504. break;
  505. case Cmd_ReadBatteryStatus:
  506. {
  507. Info("Cmd_ReadBatteryStatus{$}", strTaskResult.c_str());
  508. SendNotify();
  509. }
  510. break;
  511. case Cmd_QueryLivingTime:
  512. {
  513. Info("Cmd_QueryLivingTime {$}", strTaskResult.c_str());
  514. SendNotify();
  515. }
  516. break;
  517. case Cmd_ReadWifiStatus:
  518. {
  519. Info("Cmd_ReadWifiStatus{$}", strTaskResult.c_str());
  520. SendNotify();
  521. }
  522. break;
  523. case Cmd_SetCorrectOption:
  524. {
  525. Info("Cmd_SetCorrectOption{$}", strTaskResult.c_str());
  526. m_stDeviceIndex[nDetectorIndex].bSetCorrection = bResult;
  527. SendNotify();
  528. }
  529. break;
  530. case Cmd_ReadHumidity:
  531. {
  532. Info("Cmd_ReadHumidity");
  533. }
  534. break;
  535. case Cmd_ReadWifiSettings:
  536. {
  537. Info("Cmd_ReadWifiSettings");
  538. }
  539. break;
  540. case Cmd_QueryLastImageID:
  541. {
  542. Info("Cmd_QueryLastImageID{$}", strTaskResult.c_str());
  543. SendNotify();
  544. }
  545. break;
  546. case Cmd_GetImageByImageID:
  547. {
  548. Info("Cmd_GetImageByImageID{$}", strTaskResult.c_str());
  549. m_stDeviceIndex[nDetectorIndex].bTaskEnd = true;
  550. }
  551. break;
  552. case Cmd_ReadHallSensor:
  553. {
  554. Info("Cmd_ReadHallSensor{$}", strTaskResult.c_str());
  555. SendNotify();
  556. }
  557. break;
  558. case Cmd_ClearAcq:
  559. {
  560. Info("Cmd_ClearAcq{$}", strTaskResult.c_str());
  561. m_bInExposure = false;
  562. m_stDeviceIndex[nDetectorIndex].bTaskEnd = true;
  563. if (m_bInCalibrating)
  564. {
  565. if (TestError(nDetectorID, nParam2))
  566. {
  567. StatusFeedback(EVT_STATUS_CALIBRATIOIN, PANEL_EVENT_END_ERROR);
  568. }
  569. return;
  570. }
  571. if (!bResult)
  572. {
  573. TestError(nDetectorID, nParam2, false); //Err_ImgChBreak 30 Err_DetectorRespTimeout 24
  574. switch (nParam2)
  575. {
  576. case Err_ImgChBreak:
  577. Fatal("Error Code 30:Err_ImgChBreak");
  578. break;
  579. case Err_DetectorRespTimeout:
  580. Fatal("Error Code 24:Err_DetectorRespTimeout");
  581. break;
  582. case Err_FPD_AcquisitionBlock:
  583. Fatal("Error Code 1040:Err_FPD_AcquisitionBlock");
  584. break;
  585. default:
  586. break;
  587. }
  588. if (m_bWindowOn)
  589. {
  590. Info("need Reocover image");
  591. //SetEvent(m_hRecoverImage);
  592. m_stDeviceIndex[nDetectorIndex].bImagePending = true;
  593. ErrorFeedback(EVT_ERR_GET_IMAGE, "true"); //图像没拿到
  594. }
  595. }
  596. }
  597. break;
  598. case Cmd_SetTimeByDiff:
  599. {
  600. Info("Cmd_SetTimeByDiff{$}", strTaskResult.c_str());
  601. SendNotify();
  602. }
  603. break;
  604. case Cmd_Clear:
  605. {
  606. Info("Cmd_Clear");
  607. }
  608. break;
  609. case Cmd_StartAcq:
  610. {
  611. Info("Cmd_StartAcq{$}", strTaskResult.c_str());
  612. }
  613. break;
  614. case Cmd_HwGeneratePreOffsetTemplate:
  615. {
  616. Info("Cmd_HwGeneratePreOffsetTemplate{$}", strTaskResult.c_str());
  617. SendNotify();
  618. }
  619. break;
  620. case Cmd_DownloadCaliFile:
  621. {
  622. Info("Cmd_DownloadCaliFile{$}", strTaskResult.c_str());
  623. SendNotify();
  624. }
  625. break;
  626. case Cmd_UploadCaliFile:
  627. {
  628. m_stDeviceIndex[nDetectorIndex].bUploadCalibFile = bResult;
  629. Info("Cmd_UploadCaliFile{$}", strTaskResult.c_str());
  630. SendNotify();
  631. break;
  632. }
  633. case Cmd_SelectCaliFile:
  634. {
  635. m_stDeviceIndex[nDetectorIndex].bUploadCalibFile = bResult;
  636. Info("Cmd_SelectCaliFile{$}", strTaskResult.c_str());
  637. SendNotify();
  638. }
  639. break;
  640. case Cmd_ProhibOutExp:
  641. {
  642. Info("Cmd_ProhibOutExp");
  643. }
  644. break;
  645. case Cmd_EnableOutExp:
  646. {
  647. Info("Cmd_EnableOutExp");
  648. }
  649. break;
  650. case Cmd_Wakeup:
  651. {
  652. Info("Cmd_Wakeup");
  653. }
  654. break;
  655. case Cmd_Sleep:
  656. {
  657. Info("Cmd_Sleep");
  658. }
  659. break;
  660. case Cmd_StopAcq:
  661. {
  662. Info("Cmd_StopAcq");
  663. SendNotify();
  664. }
  665. break;
  666. case Cmd_ReadCustomFile:
  667. {
  668. Info("Cmd_ReadCustomFile{$}", strTaskResult.c_str());
  669. m_stDeviceIndex[nDetectorIndex].bUploadCalibFile = bResult;
  670. SendNotify();
  671. }
  672. break;
  673. case Cmd_WriteCustomFile:
  674. {
  675. Info("Cmd_WriteCustomFile{$}", strTaskResult.c_str());
  676. m_stDeviceIndex[nDetectorIndex].bUploadCalibFile = bResult;
  677. SendNotify();
  678. }
  679. break;
  680. default:
  681. break;
  682. }
  683. }
  684. //等到SDK回调返回true, 超时返回false
  685. bool IRayCtrl::WaitRespond(int nTimeOut)
  686. {
  687. Info("---WaitRespond---:{$}", nTimeOut);
  688. DWORD nResult = WaitForSingleObject(m_hSharedEvent, nTimeOut);
  689. if (WAIT_TIMEOUT == nResult) //偶尔会出现EVT_HARDWARE太慢的情况
  690. {
  691. Warn("Lock TimeOut");//出现超时,肯定是有问题了
  692. ResetEvent(m_hSharedEvent);
  693. return false;
  694. }
  695. ResetEvent(m_hSharedEvent);
  696. return true;
  697. }
  698. void IRayCtrl::SendNotify()
  699. {
  700. Info("---SendNotify---");
  701. SetEvent(m_hSharedEvent);
  702. }
  703. void IRayCtrl::ResetLock()
  704. {
  705. ResetEvent(m_hSharedEvent);
  706. }
  707. void IRayCtrl::Pausetime(DWORD dwSpan)
  708. {
  709. DWORD dtstart = ::GetTickCount();
  710. while ((::GetTickCount() - dtstart) < dwSpan)
  711. {
  712. MSG msg;
  713. while (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  714. {
  715. ::TranslateMessage(&msg);
  716. ::DispatchMessage(&msg);
  717. }
  718. }
  719. }
  720. bool IRayCtrl::WaitReady(int nDetectorID, int nMs)
  721. {
  722. int nState = 0;
  723. int nWaitMs = 0;
  724. bool bResult = true;
  725. string strLog;
  726. do
  727. {
  728. bResult = GetDetectorStatus(nDetectorID, nState);
  729. if (nState == Enm_State_Ready)
  730. {
  731. return true;
  732. }
  733. else
  734. {
  735. nWaitMs += 100;
  736. Pausetime(100);
  737. Info("WaitReady has waited [{$}] ms", nWaitMs);
  738. }
  739. } while (nWaitMs < nMs);
  740. return false;
  741. }
  742. bool IRayCtrl::Init(string strAppPath)
  743. {
  744. g_strAppPath = strAppPath;
  745. m_strWorkPath = strAppPath + (string)m_ModeConfig["SDKPath"]; //"OEMDrivers\\Detector\\iRay\\iRayDF\\IRay"
  746. Info("IRayCtrl::Init {$}\n", m_strWorkPath.c_str());
  747. if (!LoadIRayDLL(m_strWorkPath))
  748. {
  749. Error("IRayCtrl::Init LoadIRayDLL failed\n");
  750. return false;
  751. }
  752. m_hSharedEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  753. m_hWindowOffEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  754. m_hHWStatusThreadEndEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  755. Info("IRayCtrl::Init over\n");
  756. return true;
  757. }
  758. //启动初始化线程
  759. void IRayCtrl::StartInitFPDThread()
  760. {
  761. if (m_hInitThread)
  762. {
  763. Warn("Init thread already exsit, omit");
  764. return;
  765. }
  766. Info("Start Init Thread");
  767. DWORD unThreadID = 0;
  768. m_hInitThread = CreateThread(0, 0, onInitPanel, this, 0, &unThreadID);
  769. if (m_hInitThread == nullptr)
  770. {
  771. Fatal("Start Init Thread Error");
  772. }
  773. return;
  774. }
  775. //初始化
  776. DWORD IRayCtrl::onInitPanel(void* pParam)
  777. {
  778. IRayCtrl* pInstance = (IRayCtrl*)pParam;
  779. pInstance->Action_Init();
  780. pInstance->m_hInitThread = nullptr;
  781. return true;
  782. }
  783. void IRayCtrl::Action_Init()
  784. {
  785. Info("IRayCtrl::Action_Init");
  786. m_bInitialing = true;
  787. for (int i = 0; i < m_nPanelCount; i++) //连接多板
  788. {
  789. string strWorkDir = m_stDeviceIndex[i].strWorkDir;
  790. Info("Start Register Detector: {$}", strWorkDir.c_str());
  791. int nDetectorID = 0;
  792. int nRet = m_fpCreate(strWorkDir.c_str(), SDKCallbackProxy, &nDetectorID);
  793. if (TestError(nDetectorID, nRet, false))
  794. {
  795. Error("Register Detector {$} Callback Failed", nDetectorID);
  796. continue;
  797. }
  798. Info("Register Detector {$} Callback Success", nDetectorID);
  799. if (!DetectorInitProcess(nDetectorID))
  800. {
  801. Error("Init process failed");
  802. }
  803. }
  804. iRayScanEventThread();
  805. StartHardwareStatusThread();
  806. m_bInitialing = false;
  807. Info("Action init over\n");
  808. }
  809. //初始化连接探测器
  810. bool IRayCtrl::DetectorInitProcess(int nDetectorID, bool bFetchCalibration)
  811. {
  812. OnInitStatus(nDetectorID, PANEL_EVENT_START);
  813. int nDetectorIndex = nDetectorID - 1;
  814. bool bPingSucces = false;
  815. int nPingTotalTime = 30; //ping不通,一次约2s,共30次,1分钟左右超时
  816. for (int nPingTimes = 0; nPingTimes < nPingTotalTime; nPingTimes++)
  817. {
  818. bPingSucces = IsConnected(m_stDeviceIndex[nDetectorIndex].strWiredIP);
  819. if (bPingSucces)
  820. {
  821. Info("Ping Detector successfully");
  822. break;
  823. }
  824. Sleep(2000);
  825. }
  826. //ping不通就不用连接了
  827. if (!bPingSucces)
  828. {
  829. Error("Ping detector failed, timeout!!!");
  830. return false;
  831. }
  832. Info("Call FnInvoke:Connect");
  833. int nRet = IrayFnInvoke(nDetectorID, Cmd_Connect, NULL, 0); //wait Cmd_Connect
  834. if (TestError(nDetectorID, nRet))
  835. {
  836. Error("Connect Detector {$} Failed", nDetectorID);
  837. if (m_stDeviceIndex[nDetectorIndex].bActived)
  838. {
  839. m_stDeviceIndex[nDetectorIndex].bExisted = true;
  840. m_stDeviceIndex[nDetectorIndex].bConnectStatus = false;
  841. }
  842. return false;
  843. }
  844. ResetLock();
  845. if (!WaitRespond(nINIT_TIME))
  846. {
  847. Error("Connect Detector {$} timeout", nDetectorID);
  848. }
  849. if (m_stDeviceIndex[nDetectorIndex].bConnectStatus)
  850. {
  851. Info("Connect Detector {$} Success", nDetectorID);
  852. }
  853. else
  854. {
  855. bool bRet = false;
  856. if (m_nCmdConnectResult == Err_GeneralSocketErr)
  857. {
  858. Info("first connect return error 32, retry connect one more time");
  859. Sleep(10000); //过10秒后再重新连接
  860. bRet = RetryConnect(nDetectorID);
  861. }
  862. if (!bRet)
  863. {
  864. if (m_stDeviceIndex[nDetectorIndex].bActived)
  865. {
  866. m_stDeviceIndex[nDetectorIndex].bExisted = true;
  867. }
  868. return false;
  869. }
  870. }
  871. //获取系统信息
  872. GetROMInfo(nDetectorID);
  873. //获取HVG信号状态
  874. GetHVGSignalStatus(nDetectorID);
  875. //设置工作模式
  876. //SetDetectorWorkMode();
  877. if (bFetchCalibration) //特殊需求,同步校正文件//正常初始化,不同步校正文件
  878. {
  879. DownloadfromDetector(nDetectorID);
  880. }
  881. //暗场的模式组成map<nLogicMode, nOperationMode>
  882. SetOffsetModeScope();
  883. //加载校正
  884. //SetDetectorCorrection(nDetectorID, m_nCorrectionType);
  885. //SetDetectorXWindow(nDetectorID, 500, m_stDeviceIndex[nDetectorIndex].nXWindow, m_stDeviceIndex[nDetectorIndex].nXWindow);
  886. m_stDeviceIndex[nDetectorIndex].bExisted = true;
  887. m_stDeviceIndex[nDetectorIndex].bInitOK = true;
  888. OnInitStatus(nDetectorID, PANEL_EVENT_END_OK);
  889. return true;
  890. }
  891. //重连接
  892. bool IRayCtrl::RetryConnect(int nDetectorID)
  893. {
  894. Info("RetryConnect start");
  895. int nPanelID = nDetectorID + 1;
  896. Info("Call Cmd_Disconnect");
  897. int nResult = IrayFnInvoke(nPanelID, Cmd_Disconnect, NULL, 0);
  898. if (TestError(nDetectorID, nResult))
  899. {
  900. Info("Disconnect Detector {$} Failed", nPanelID);
  901. }
  902. Sleep(500);
  903. int nRet = IrayFnInvoke(nPanelID, Cmd_Connect, NULL, 0);
  904. if (TestError(nDetectorID, nRet))
  905. {
  906. Info("RetryConnect Detector {$} Failed", nDetectorID);
  907. return false;
  908. }
  909. ResetLock();
  910. if (!WaitRespond(nINIT_TIME))
  911. {
  912. Error("Connect Detector {$} timeout", nPanelID);
  913. }
  914. if (m_stDeviceIndex[m_nDetectorIndex].bConnectStatus)
  915. {
  916. Info("RetryConnect Detector {$} Success", nDetectorID);
  917. return true;
  918. }
  919. else
  920. {
  921. Error("RetryConnect Detector {$} Failed", nDetectorID);
  922. }
  923. return false;
  924. }
  925. bool IRayCtrl::OnInitStatus(int nPanelIndex, ENUM_PANEL_EVENT_STATE ePanelState)
  926. {
  927. int nDetectorID = 0;
  928. if (PANEL_EVENT_START == ePanelState)
  929. {
  930. StatusFeedback(EVT_STATUS_INIT, PANEL_EVENT_START, "");
  931. }
  932. else if (PANEL_EVENT_END_OK == ePanelState)
  933. {
  934. StatusFeedback(EVT_STATUS_INIT, PANEL_EVENT_END_OK, "");
  935. }
  936. else if (PANEL_EVENT_END_ERROR == ePanelState)
  937. {
  938. StatusFeedback(EVT_STATUS_INIT, PANEL_EVENT_END_ERROR, "");
  939. }
  940. else if (PANEL_EVENT_END == ePanelState) //未连接探测器
  941. {
  942. StatusFeedback(EVT_STATUS_INIT, PANEL_EVENT_END, "");
  943. }//end if
  944. return true;
  945. }
  946. //辅助线程句柄
  947. void IRayCtrl::ScanAddHandle()
  948. {
  949. m_hExitEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  950. m_hRecoverImage = CreateEvent(NULL, FALSE, FALSE, NULL);
  951. m_hCofirmCalib = CreateEvent(NULL, FALSE, FALSE, NULL);
  952. m_hEndCalibEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  953. m_hOffsetEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  954. m_hArrayEvent[0] = m_hExitEvent;
  955. m_hArrayEvent[1] = m_hRecoverImage;
  956. m_hArrayEvent[2] = m_hCofirmCalib;
  957. m_hArrayEvent[3] = m_hEndCalibEvent;
  958. m_hArrayEvent[4] = m_hOffsetEvent;
  959. m_hIRayScanEnd = CreateEvent(NULL, FALSE, FALSE, NULL);
  960. return;
  961. }
  962. /************************************************************************************
  963. 功能:启动线程,处理一些异步消息
  964. ************************************************************************************/
  965. void IRayCtrl::iRayScanEventThread()
  966. {
  967. if (m_hScanEventThread)
  968. {
  969. Info("ScanEvent Thread already run\n");
  970. return;
  971. }
  972. Info("Start ScanEvent Thread");
  973. ScanAddHandle();
  974. DWORD unThreadID;
  975. m_hScanEventThread = (HANDLE)CreateThread(NULL, 0, onScanEvent, (LPVOID)this, 0, &unThreadID);
  976. if (m_hScanEventThread == NULL)
  977. {
  978. Fatal("Start Scan Event Error");
  979. }
  980. else
  981. {
  982. Info("Start ScanEvent Thread ok");
  983. }
  984. //endif
  985. }
  986. /************************************************************************************
  987. 功能:启动线程,处理一些异步消息
  988. m_hRecoverImage 异步,恢复图像
  989. m_hCofirmCalib 异步,确认每一次校正的结果,如剂量大了/小了/
  990. m_hReconnectFD 异步,初始化探测器
  991. ************************************************************************************/
  992. DWORD IRayCtrl::onScanEvent(void* pParam)
  993. {
  994. IRayCtrl* pInstance = (IRayCtrl*)pParam;
  995. if (pInstance == NULL)
  996. {
  997. return false;
  998. }
  999. bool bExitFlag = true;
  1000. while (bExitFlag)
  1001. {
  1002. Info("( Waiting for Signal...)");
  1003. DWORD dwResult = WaitForMultipleObjects(IRAY_SCAN_NUM, pInstance->m_hArrayEvent, FALSE, INFINITE);
  1004. if (WAIT_OBJECT_0 == dwResult) //m_hExitEvent
  1005. {
  1006. Info("Get Exit Event");
  1007. bExitFlag = false;
  1008. }
  1009. else if (WAIT_OBJECT_0 + 1 == dwResult) //m_hRecoverImage
  1010. {
  1011. if (pInstance->m_nRecoverImageTimes < 2)
  1012. {
  1013. Info("Get RecoverImage Event");
  1014. pInstance->m_nRecoverImageTimes++;
  1015. pInstance->RecoverLastImageAuto();
  1016. }
  1017. else
  1018. {
  1019. Info("Get RecoverImage Event already retry 2 times, omit it");
  1020. if (pInstance->m_bWindowOn)
  1021. {
  1022. pInstance->ErrorFeedback(EVT_ERR_GET_IMAGE, "true");
  1023. }
  1024. }
  1025. }
  1026. else if (WAIT_OBJECT_0 + 2 == dwResult) //m_hCofirmCalib
  1027. {
  1028. Info("Get Cofirm Calibration Event");
  1029. pInstance->ConfirmCalibration();
  1030. }
  1031. else if (WAIT_OBJECT_0 + 3 == dwResult) //m_hEndCalibEvent
  1032. {
  1033. Info("Get EndCalibraion Event");
  1034. pInstance->OnEndCalibraion();
  1035. }
  1036. else if (WAIT_OBJECT_0 + 4 == dwResult) //m_hOffsetEvent
  1037. {
  1038. Info("Get Offset Event");
  1039. pInstance->OffsetCalibration();
  1040. }
  1041. }
  1042. SetEvent(pInstance->m_hIRayScanEnd);
  1043. Info("iRay ScanEvent Thread End");
  1044. return true;
  1045. }
  1046. bool IRayCtrl::GetProductNo(int nDetectorID, int& nProductNo)
  1047. {
  1048. return GetAttr(nDetectorID, Attr_UROM_ProductNo, nProductNo);
  1049. }
  1050. bool IRayCtrl::GetSrcIP(int nDetectorID, char* pszUROM_SrcIP)
  1051. {
  1052. return GetAttr(nDetectorID, Attr_UROM_SrcIP, pszUROM_SrcIP);
  1053. }
  1054. bool IRayCtrl::GetSerialNo(int nDetectorID, char* pszUROM_SerialNo)
  1055. {
  1056. return GetAttr(nDetectorID, Attr_UROM_SerialNo, pszUROM_SerialNo);
  1057. }
  1058. bool IRayCtrl::GetMainVersion(int nDetectorID, char* pszMainVersion)
  1059. {
  1060. return GetAttr(nDetectorID, Attr_UROM_MainVersion, pszMainVersion);
  1061. }
  1062. bool IRayCtrl::GetReadVersion(int nDetectorID, char* pszReadVersion)
  1063. {
  1064. return GetAttr(nDetectorID, Attr_UROM_ReadVersion, pszReadVersion);
  1065. }
  1066. bool IRayCtrl::GetMcuVersion(int nDetectorID, char* pszMcuVersion)
  1067. {
  1068. return GetAttr(nDetectorID, Attr_UROM_McuVersion, pszMcuVersion);
  1069. }
  1070. bool IRayCtrl::GetBatterySN(int nDetectorID, char* inoutSN)
  1071. {
  1072. return GetAttr(nDetectorID, Attr_Battery_SN, inoutSN);
  1073. }
  1074. bool IRayCtrl::GetArmVersion(int nDetectorID, char* pszArmVersion)
  1075. {
  1076. return GetAttr(nDetectorID, Attr_UROM_ArmVersion, pszArmVersion);
  1077. }
  1078. bool IRayCtrl::GetSyncMode(int nDetectorID, int& nTriggerMode)
  1079. {
  1080. return GetAttr(nDetectorID, Attr_UROM_TriggerMode, nTriggerMode);
  1081. }
  1082. bool IRayCtrl::GetKernelVersion(int nDetectorID, char* pszKernelVersion)
  1083. {
  1084. return GetAttr(nDetectorID, Attr_UROM_KernelVersion, pszKernelVersion);
  1085. }
  1086. bool IRayCtrl::GetWifiLinkQuality(int nDetectorID, int& nQuality)
  1087. {
  1088. return GetAttr(nDetectorID, Attr_WifiStatu_WorkingLinkQuality, nQuality);
  1089. }
  1090. bool IRayCtrl::GetConnState(int nDetectorID, int& nConnState)
  1091. {
  1092. return GetAttr(nDetectorID, Attr_ConnState, nConnState);
  1093. }
  1094. //ClearAcq窗口时间(以毫秒为单位)
  1095. bool IRayCtrl::GetDelayTime(int nDetectorID, int& nDelayTime)
  1096. {
  1097. return GetAttr(nDetectorID, Cfg_ClearAcqParam_DelayTime, nDelayTime);
  1098. }
  1099. bool IRayCtrl::SetDelayTime(int nDetectorID, int nDelayTime)
  1100. {
  1101. return SetAttr(nDetectorID, Cfg_ClearAcqParam_DelayTime, nDelayTime);
  1102. }
  1103. //Acq2窗口时间(以毫秒为单位)
  1104. bool IRayCtrl::GetXWindowDelay(int nDetectorID, int& nXWidnowTime)
  1105. {
  1106. return GetAttr(nDetectorID, Attr_UROM_SetDelayTime, nXWidnowTime);
  1107. }
  1108. bool IRayCtrl::SetXWindowDelay(int nDetectorID, int nXWidnowTime)
  1109. {
  1110. if (SetAttr(nDetectorID, Attr_UROM_SetDelayTime_W, nXWidnowTime))
  1111. {
  1112. return WriteRom(nDetectorID);
  1113. }
  1114. return false;
  1115. }
  1116. //Clear+StartAcq窗口时间(以毫秒为单位)
  1117. bool IRayCtrl::GetExpWindowTime(int nDetectorID, int& nExpWindowTime)
  1118. {
  1119. return GetAttr(nDetectorID, Attr_UROM_ExpWindowTime, nExpWindowTime);
  1120. }
  1121. bool IRayCtrl::SetExpWindowTime(int nDetectorID, int nExpWindow)
  1122. {
  1123. if (SetAttr(nDetectorID, Attr_UROM_ExpWindowTime_W, nExpWindow))
  1124. {
  1125. return WriteRom(nDetectorID);
  1126. }
  1127. return false;
  1128. }
  1129. bool IRayCtrl::GetPrepCapMode(int nDetectorID, int& nPrepCapMode)
  1130. {
  1131. return GetAttr(nDetectorID, Attr_UROM_PrepCapMode, nPrepCapMode);
  1132. }
  1133. bool IRayCtrl::GetSelfCapEnable(int nDetectorID, int& nSelfCapEnable)
  1134. {
  1135. return GetAttr(nDetectorID, Attr_UROM_SelfCapEnable, nSelfCapEnable);
  1136. }
  1137. bool IRayCtrl::GetSelfClearEnable(int nDetectorID, int& nSelfClearEnable)
  1138. {
  1139. return GetAttr(nDetectorID, Attr_UROM_SelfClearEnable, nSelfClearEnable);
  1140. }
  1141. bool IRayCtrl::GetDynaOffsetGapTime(int nDetectorID, int& nDynOffsetGapTime)
  1142. {
  1143. return GetAttr(nDetectorID, Attr_UROM_DynaOffsetGapTime, nDynOffsetGapTime);
  1144. }
  1145. bool IRayCtrl::GetBatteryExist(int nDetectorID, int& nExist)
  1146. {
  1147. return GetAttr(nDetectorID, Attr_Battery_Exist, nExist);
  1148. }
  1149. bool IRayCtrl::GetBatteryRemaining(int nDetectorID, int& nRemaining)
  1150. {
  1151. return GetAttr(nDetectorID, Attr_Battery_Remaining, nRemaining);
  1152. }
  1153. bool IRayCtrl::GetBatteryChargingStatus(int nDetectorID, int& nStatus)
  1154. {
  1155. return GetAttr(nDetectorID, Attr_Battery_ChargingStatus, nStatus);
  1156. }
  1157. //静态板T1,动态板T2
  1158. bool IRayCtrl::GetFPDTempT1(int nDetectorID, float& fTempT1)
  1159. {
  1160. return GetAttr(nDetectorID, Attr_RdResult_T1, fTempT1);
  1161. }
  1162. bool IRayCtrl::GetFPDTempT2(int nDetectorID, float& fTempT2)
  1163. {
  1164. return GetAttr(nDetectorID, Attr_RdResult_T2, fTempT2);
  1165. }
  1166. bool IRayCtrl::GetHallSensor(int nDetectorID, int& nPosition)
  1167. {
  1168. return GetAttr(nDetectorID, Attr_HallSensorValue, nPosition);
  1169. }
  1170. bool IRayCtrl::GetLifeTime(int nDetectorID, int& nLifeTime)
  1171. {
  1172. return GetAttr(nDetectorID, Attr_FD_LifeTime, nLifeTime);
  1173. }
  1174. bool IRayCtrl::GetPowerOnCount(int nDetectorID, int& nCount)
  1175. {
  1176. return GetAttr(nDetectorID, Attr_FD_PowerOnCount, nCount);
  1177. }
  1178. bool IRayCtrl::GetDetectorStatus(int nDetectorID, int& state)
  1179. {
  1180. bool bResult = GetAttr(nDetectorID, Attr_State, state);
  1181. Info("FPD {$} Status is [{$}]", nDetectorID, DetectorState[state]);
  1182. return bResult;
  1183. }
  1184. bool IRayCtrl::GetCorrectionOption(int nDetectorID, int& nOption)
  1185. {
  1186. return GetAttr(nDetectorID, Attr_CurrentCorrectOption, nOption);
  1187. }
  1188. bool IRayCtrl::GetFWUpdateProgress(int nDetectorID, int& nOption)
  1189. {
  1190. return GetAttr(nDetectorID, Attr_FWUpdateProgress, nOption);
  1191. }
  1192. bool IRayCtrl::SetPrepCapMode(int nDetectorID, int nPrepCapMode)
  1193. {
  1194. if (SetAttr(nDetectorID, Attr_UROM_PrepCapMode_W, nPrepCapMode))
  1195. {
  1196. return true;
  1197. }
  1198. return false;
  1199. }
  1200. bool IRayCtrl::SetInnerSubFlowAttr(int nDetectorID, int nInnerSubFlow)
  1201. {
  1202. if (SetAttr(nDetectorID, Attr_UROM_InnerSubFlow_W, nInnerSubFlow))
  1203. {
  1204. return true;
  1205. }
  1206. return false;
  1207. }
  1208. bool IRayCtrl::SetSelfCapEnable(int nDetectorID, int nSelfCapEnable)
  1209. {
  1210. return SetAttr(nDetectorID, Attr_UROM_SelfCapEnable_W, nSelfCapEnable);
  1211. }
  1212. bool IRayCtrl::SetSelfClearEnable(int nDetectorID, int nSelfClearEnable)
  1213. {
  1214. return SetAttr(nDetectorID, Attr_UROM_SelfClearEnable_W, nSelfClearEnable);
  1215. }
  1216. bool IRayCtrl::SetDynaOffsetGapTime(int nDetectorID, int nDynaOffsetGapTime)
  1217. {
  1218. return SetAttr(nDetectorID, Attr_UROM_DynaOffsetGapTime_W, nDynaOffsetGapTime);
  1219. }
  1220. bool IRayCtrl::SetAppMode(int nDetectorID, int nMode)
  1221. {
  1222. Info("Set detector({$}) work mode: {$}", nDetectorID, nMode);
  1223. string strAppMode = "Mode" + std::to_string(nMode);
  1224. //先停止
  1225. m_pfAbort(nDetectorID);
  1226. Info("Abort detector");
  1227. if (!WaitReady(nDetectorID, 500))
  1228. {
  1229. Fatal("Detector status error");
  1230. return false;
  1231. }
  1232. IRayCmdParam param;
  1233. param.var.vt = IVT_STR;
  1234. strcpy_s(param.var.val.strVal, strAppMode.c_str());
  1235. ResetLock();
  1236. Info("Call Cmd_SetCaliSubset FPD {$}", nDetectorID);
  1237. FPDRESULT nResult = IrayFnInvoke(nDetectorID, Cmd_SetCaliSubset, &param, 1);
  1238. if (TestError(nDetectorID, nResult))
  1239. {
  1240. Fatal("Cmd_SetCaliSubset Failed");
  1241. return false;
  1242. }
  1243. if (!WaitRespond(nCMD_TIME))
  1244. {
  1245. Fatal("Cmd_SetCaliSubset Respond Failed. ");
  1246. return false;
  1247. }
  1248. return true;
  1249. }
  1250. bool IRayCtrl::GetAttr(int nDetectorID, int nAttrID, int& nValue)
  1251. {
  1252. IRayVariant var;
  1253. var.vt = IVT_INT;
  1254. var.val.nVal = 0;
  1255. FPDRESULT result = m_fpGetAttr(nDetectorID, nAttrID, &var);
  1256. if (TestError(nDetectorID - 1, result))
  1257. {
  1258. Fatal("Get Attribute Failed");
  1259. return false;
  1260. }
  1261. nValue = var.val.nVal;
  1262. return true;
  1263. }
  1264. bool IRayCtrl::GetAttr(int nDetectorID, int nAttrID, float& fValue)
  1265. {
  1266. float ftemp = 0.0f;
  1267. IRayVariant var;
  1268. var.vt = IVT_FLT;
  1269. var.val.fVal = ftemp;
  1270. FPDRESULT result = m_fpGetAttr(nDetectorID, nAttrID, &var);
  1271. if (TestError(nDetectorID - 1, result))
  1272. {
  1273. Fatal("Get Attribute Failed");
  1274. return false;
  1275. }
  1276. fValue = var.val.fVal;
  1277. return true;
  1278. }
  1279. bool IRayCtrl::GetAttr(int nDetectorID, int nAttrID, char* pszAttr)
  1280. {
  1281. IRayVariant var;
  1282. var.vt = IVT_STR;
  1283. memset(var.val.strVal, 0, IRAY_MAX_STR_LEN);
  1284. FPDRESULT result = m_fpGetAttr(nDetectorID, nAttrID, &var);
  1285. if (TestError(nDetectorID - 1, result))
  1286. {
  1287. Fatal("Get Attribute Failed");
  1288. return false;
  1289. }
  1290. size_t len = strlen(var.val.strVal);
  1291. strcpy_s(pszAttr, len + 1, var.val.strVal);
  1292. return true;
  1293. }
  1294. bool IRayCtrl::SetAttr(int nDetectorID, int nAttrID, int nValue)
  1295. {
  1296. IRayVariant var;
  1297. var.vt = IVT_INT;
  1298. var.val.nVal = nValue;
  1299. FPDRESULT result = m_fpSetAttr(nDetectorID, nAttrID, &var);
  1300. if (TestError(nDetectorID - 1, result))
  1301. {
  1302. Fatal("Get Attribute Failed");
  1303. return false;
  1304. }
  1305. return true;
  1306. }
  1307. //接口成功返回false,接口失败或有错返回true
  1308. bool IRayCtrl::TestError(int nDetectorID, int nErrorStatus, bool bPopUp)
  1309. {
  1310. string strLog = "";
  1311. switch (nErrorStatus)
  1312. {
  1313. case Err_OK:
  1314. return false;
  1315. case Err_TaskPending:
  1316. {
  1317. return false;
  1318. }
  1319. case Err_Unknown:
  1320. Fatal("Err_Unknown");
  1321. break;
  1322. case Err_NotInitialized:
  1323. Fatal("Err_NotInitialized");
  1324. break;
  1325. case Err_TemplateFileNotExist:
  1326. case Err_TemplateFileNotMatch:
  1327. {
  1328. //string strError = WAR_FPD_LOAD_CORRECT_FILE;
  1329. //OnWarn(nDetectorID, strError, "");
  1330. break;
  1331. }
  1332. case Err_InvalidPacketNo:
  1333. case Err_InvalidPacketFormat:
  1334. case Err_PacketDataCheckFailed:
  1335. Fatal("25/26/27 Transfering image not finished");
  1336. break;
  1337. case Err_ImgChBreak:
  1338. Fatal("Err_ImgChBreak");
  1339. break;
  1340. case Err_FPD_AcquisitionBlock:
  1341. Fatal("Err_FPD_AcquisitionBlock");
  1342. break;
  1343. case Err_GeneralSocketErr:
  1344. Fatal("Err_GeneralSocketErr");
  1345. break;
  1346. case Err_ApplyFirmwareFailed:
  1347. case Err_FPD_General_Detector_Error:
  1348. case Err_FPD_General_FirmwareUpgrade_Error:
  1349. case Err_FPD_FirmwareFallback:
  1350. case Err_FPD_Busy:
  1351. case Err_FPD_Busy_Initializing:
  1352. case Err_FPD_Busy_Last_Command_Suspending:
  1353. case Err_FPD_Busy_MCU_Busy:
  1354. case Err_FPD_Busy_FPGA_Busy:
  1355. case Err_FPD_Busy_FPGA_Timeout:
  1356. case Err_FPD_Busy_System_Error:
  1357. case Err_FPD_CmdExecuteTimeout:
  1358. case Err_TaskTimeOut:
  1359. case Err_DetectorRespTimeout:
  1360. {
  1361. if (bPopUp)
  1362. {
  1363. //string strError = ERR_FPD_RESTART;
  1364. //OnError(nDetectorID, strError, "");
  1365. }
  1366. break;
  1367. }
  1368. case Err_NotEnoughMemorySpace:
  1369. break;
  1370. case Err_ConfigFileNotExist:
  1371. default:
  1372. {
  1373. ErrorInfo info;
  1374. m_pFnGetErrorInfo(nErrorStatus, &info);
  1375. string strDes = (info.szDescription);
  1376. string strSolution = (info.szSolution);
  1377. Fatal("Get ErrCode:{$} Description:{$} Solution:{$}", nErrorStatus, strDes.c_str(), strSolution.c_str());
  1378. if (bPopUp)
  1379. {
  1380. //string strError = ERR_FPD_FATAL_ERROR;
  1381. //OnError(nDetectorID, strError, "");
  1382. }
  1383. }
  1384. break;
  1385. }
  1386. return true;
  1387. }
  1388. bool IRayCtrl::LoadIRayDLL(string strWorkPath)
  1389. {
  1390. string strDllDir = strWorkPath;
  1391. if (SetDllDirectory(strDllDir.c_str()) == 0)
  1392. {
  1393. DWORD dw = GetLastError();
  1394. Info("SetDllDirectory error,error code [{$}]", dw);
  1395. return false;
  1396. }
  1397. string strDllPath = strWorkPath + "\\FpdSys.dll";
  1398. Info("Load FpdSys.dll");
  1399. m_hIRayModule = LoadLibrary(strDllPath.c_str());
  1400. if (NULL == m_hIRayModule)
  1401. {
  1402. Fatal("Load FpdSys.DLL failed!");
  1403. return false;
  1404. }
  1405. m_fpCreate = (FnCreate)GetProcAddress(m_hIRayModule, IRAY_FPD_PROC_NAME_CREATE);
  1406. if (NULL == m_fpCreate)
  1407. {
  1408. Fatal("GetProcAddress:Create failed!");
  1409. return false;
  1410. }
  1411. m_fpDestroy = (FnDestroy)GetProcAddress(m_hIRayModule, IRAY_FPD_PROC_NAME_DESTROY);
  1412. if (NULL == m_fpDestroy)
  1413. {
  1414. Fatal("GetProcAddress:Destroy failed!");
  1415. return false;
  1416. }
  1417. m_fpGetAttr = (FnGetAttr)GetProcAddress(m_hIRayModule, IRAY_FPD_PROC_NAME_GETATTR);
  1418. if (NULL == m_fpGetAttr)
  1419. {
  1420. Fatal("GetProcAddress:GetAttr failed!");
  1421. return false;
  1422. }
  1423. m_fpSetAttr = (FnSetAttr)GetProcAddress(m_hIRayModule, IRAY_FPD_PROC_NAME_SETATTR);
  1424. if (NULL == m_fpSetAttr)
  1425. {
  1426. Fatal("GetProcAddress:SetAttr failed!");
  1427. return false;
  1428. }
  1429. m_fpInvoke = (FnInvoke)GetProcAddress(m_hIRayModule, IRAY_FPD_PROC_NAME_INVOKE);
  1430. if (NULL == m_fpInvoke)
  1431. {
  1432. Fatal("GetProcAddress:Invoke failed!");
  1433. return false;
  1434. }
  1435. m_pRegisterScanNotify = (FnRegisterScanNotify)GetProcAddress(m_hIRayModule, IRAY_FPD_PROC_NAME_REGISTER_SCANNotify);
  1436. if (NULL == m_pRegisterScanNotify)
  1437. {
  1438. Fatal(" GetProcAddress:RegisterScanNotify Failed!");
  1439. return false;
  1440. }
  1441. m_pScanOnce = (FnScanOnce)GetProcAddress(m_hIRayModule, IRAY_FPD_PROC_NAME_SCAN);
  1442. if (NULL == m_pScanOnce)
  1443. {
  1444. Fatal(" GetProcAddress:m_pScanOnce Failed!");
  1445. return false;
  1446. }
  1447. m_pFnGetErrorInfo = (FnGetErrInfo)GetProcAddress(m_hIRayModule, IRAY_FPD_PROC_NAME_GET_ERROR_INFO);
  1448. if (NULL == m_pFnGetErrorInfo)
  1449. {
  1450. Fatal(" GetProcAddress:GetErrInfo Failed!");
  1451. return false;
  1452. }
  1453. m_pfAbort = (FnAbort)GetProcAddress(m_hIRayModule, IRAY_FPD_PROC_NAME_ABORT);
  1454. if (NULL == m_pfAbort)
  1455. {
  1456. Fatal(" GetProcAddress:FnAbort Failed!");
  1457. return false;
  1458. }
  1459. m_pfOpenDefectTemplateFile = (FnOpenDefectTemplateFile)GetProcAddress(m_hIRayModule, IRAY_FPD_PROC_NAME_DEFECT_OPEN);
  1460. if (NULL == m_pfOpenDefectTemplateFile)
  1461. {
  1462. Fatal(" GetProcAddress:FnOpenDefectTemplateFile Failed!");
  1463. return false;
  1464. }
  1465. m_pfCloseDefectTemplateFile = (FnCloseDefectTemplateFile)GetProcAddress(m_hIRayModule, IRAY_FPD_PROC_NAME_DEFECT_CLOSE);
  1466. if (NULL == m_pfCloseDefectTemplateFile)
  1467. {
  1468. Fatal(" GetProcAddress:FnCloseDefectTemplateFile Failed!");
  1469. return false;
  1470. }
  1471. return true;
  1472. }
  1473. void IRayCtrl::FreeIRayDLL()
  1474. {
  1475. if (m_hIRayModule)
  1476. {
  1477. FreeLibrary(m_hIRayModule);
  1478. m_hIRayModule = NULL;
  1479. Info(" Free IRay DLL");
  1480. }
  1481. }
  1482. bool IRayCtrl::AddDPCs(nsDPC::FPDDeviceIRay* pDrvDPC, ResDataObject& Configuration, DeviceIndexStruct& DeviceStruct)
  1483. {
  1484. map<nsDPC::FPDDeviceIRay*, int>::iterator DPCsIter = m_pDPC2PanelID->find(pDrvDPC);
  1485. if (DPCsIter != m_pDPC2PanelID->end())
  1486. {
  1487. Warn("IRayCtrl::AddDPCs This DPC already exist\n");
  1488. return false;
  1489. }
  1490. Info("--Func-- AddDPCs {$}", pDrvDPC);
  1491. m_pCurrentDPC = pDrvDPC;
  1492. //拿到当前探测器的配置
  1493. m_stDeviceIndex[m_nPanelCount] = DeviceStruct;
  1494. m_ObjFPDsInfo[m_nPanelCount] = Configuration;
  1495. Info("AddDPCs, {$} {$} ", m_stDeviceIndex[m_nPanelCount].strDetectorModel, m_stDeviceIndex[m_nPanelCount].strDeviceName);
  1496. m_pDPC2PanelID->insert(pair<nsDPC::FPDDeviceIRay*, int>(pDrvDPC, m_nPanelCount));
  1497. m_pPanelID2DPC->insert(pair<int, nsDPC::FPDDeviceIRay*>(m_nPanelCount, pDrvDPC));
  1498. m_ModeConfig = Configuration;
  1499. m_bPreviewImg = m_stDeviceIndex[m_nDetectorIndex].bPreviewEnable;
  1500. m_nCorrectionType = m_stDeviceIndex[m_nDetectorIndex].AcqModeInfo.nCorrectionType;
  1501. m_nPanelCount++;
  1502. Info("IRayCtrl::AddDPCs ok {$}\n", m_nPanelCount);
  1503. return true;
  1504. }
  1505. bool IRayCtrl::DelDPCs(nsDPC::FPDDeviceIRay* pDrvDPC)
  1506. {
  1507. map<nsDPC::FPDDeviceIRay*, int>::iterator DPCsIter = m_pDPC2PanelID->find(pDrvDPC);
  1508. if (DPCsIter != m_pDPC2PanelID->end())
  1509. {
  1510. map<int, nsDPC::FPDDeviceIRay*>::iterator PanelIdIter = m_pPanelID2DPC->find(DPCsIter->second);
  1511. if (PanelIdIter != m_pPanelID2DPC->end())
  1512. {
  1513. m_pPanelID2DPC->erase(PanelIdIter);
  1514. }
  1515. m_stDeviceIndex[DPCsIter->second] = {};
  1516. m_ObjFPDsInfo[DPCsIter->second].clear();
  1517. m_pDPC2PanelID->erase(DPCsIter);
  1518. m_nPanelCount--;
  1519. Info("IRayCtrl::DelDPCs ok {$}\n", m_nPanelCount);
  1520. }
  1521. return true;
  1522. }
  1523. void IRayCtrl::ConfFeedback(int nEventID, int nDetectorID, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1524. {
  1525. if (-1 == nDetectorID)
  1526. {
  1527. nDetectorID = m_nDetectorIndex;
  1528. }
  1529. ((*m_pPanelID2DPC)[m_nDetectorIndex])->OnFPDCallback(nDetectorID,
  1530. nEventID, EVT_LEVEL_CONFIGURATION, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1531. }
  1532. void IRayCtrl::InfoFeedback(int nEventID, int nDetectorID, int nParam1, float fParam2, const char* pszMsg, int nPtrParamLen, void* pParam)
  1533. {
  1534. if (-1 == nDetectorID)
  1535. {
  1536. nDetectorID = m_nDetectorIndex;
  1537. }
  1538. ((*m_pPanelID2DPC)[m_nDetectorIndex])->OnFPDCallback(nDetectorID,
  1539. nEventID, EVT_LEVEL_INFORMATOION, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1540. }
  1541. void IRayCtrl::StatusFeedback(int nEventID, int nParam1, const char* pszMsg, int nDetectorID, float fParam2, int nPtrParamLen, void* pParam)
  1542. {
  1543. if (-1 == nDetectorID)
  1544. {
  1545. nDetectorID = m_nDetectorIndex;
  1546. }
  1547. ((*m_pPanelID2DPC)[m_nDetectorIndex])->OnFPDCallback(nDetectorID,
  1548. nEventID, EVT_LEVEL_STATUS, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1549. }
  1550. void IRayCtrl::DataFeedback(int nEventID, void* pParam, int nParam1, float fParam2, const char* pszMsg, int nPtrParamLen, int nDetectorID)
  1551. {
  1552. if (-1 == nDetectorID)
  1553. {
  1554. nDetectorID = m_nDetectorIndex;
  1555. }
  1556. ((*m_pPanelID2DPC)[m_nDetectorIndex])->OnFPDCallback(nDetectorID,
  1557. nEventID, EVT_LEVEL_DATA, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1558. }
  1559. void IRayCtrl::WarnFeedback(int nEventID, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam, int nDetectorID)
  1560. {
  1561. if (-1 == nDetectorID)
  1562. {
  1563. nDetectorID = m_nDetectorIndex;
  1564. }
  1565. ((*m_pPanelID2DPC)[m_nDetectorIndex])->OnFPDCallback(nDetectorID,
  1566. nEventID, EVT_LEVEL_WARNING, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1567. }
  1568. void IRayCtrl::ErrorFeedback(int nEventID, const char* pszMsg, int nDetectorID, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1569. {
  1570. if (-1 == nDetectorID)
  1571. {
  1572. nDetectorID = m_nDetectorIndex;
  1573. }
  1574. ((*m_pPanelID2DPC)[m_nDetectorIndex])->OnFPDCallback(nDetectorID,
  1575. nEventID, EVT_LEVEL_ERROR, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1576. }
  1577. /********************************************************************/
  1578. /*
  1579. 将文件删除
  1580. /********************************************************************/
  1581. bool IRayCtrl::DeleteOneFolder(string strSourceFolder)
  1582. {
  1583. Info("Delete {$}", strSourceFolder.c_str());
  1584. if (!PathFileExists(strSourceFolder.c_str()))
  1585. {
  1586. Info("SourceFolder don't exist");
  1587. return false;
  1588. }
  1589. char pFolderSource[MAX_STRING] = { 0 };
  1590. memset(pFolderSource, 0x00, MAX_STRING);
  1591. strcpy(pFolderSource, strSourceFolder.c_str()); // 第一个文件
  1592. SHFILEOPSTRUCT sfo;
  1593. memset(&sfo, 0, sizeof(SHFILEOPSTRUCT));
  1594. sfo.hwnd = NULL;
  1595. sfo.wFunc = FO_DELETE;//FO_MOVE;
  1596. sfo.pFrom = pFolderSource;
  1597. sfo.fFlags = FOF_SILENT | FOF_NOCONFIRMATION;// | FOF_ALLOWUNDO; //| FOF_NOCONFIRMMKDIR;
  1598. // FOF_ALLOWUNDO:保存UNDO信息,以便在回收站中恢复文件;
  1599. //FOF_NOCONFIRMATION:在出现目标文件已存在的时候,如果不设置此项,则它会出现确认是否覆盖的对话框,设置此项则自动确认,进行覆盖,不出现对话框。
  1600. SHFileOperation(&sfo);
  1601. Info("Delete File over");
  1602. return true;
  1603. }
  1604. //将strSrcPath文件拷贝到strDstPath目录
  1605. bool IRayCtrl::CopyFile2Folder(string strSrcPath, string strDstPath)
  1606. {
  1607. //MSDN: This string must be double-null terminated
  1608. strSrcPath += '\0';
  1609. strDstPath += '\0';
  1610. //上面两行代码非常重要,直接影响下面SHFileOperation的稳定性
  1611. Info("Copy {$} to {$}", strSrcPath.c_str(), strDstPath.c_str());
  1612. if (!PathFileExists(strSrcPath.c_str()))
  1613. {
  1614. Info("SourceFolder don't exist");
  1615. return false;
  1616. }
  1617. if (!PathFileExists(strDstPath.c_str()))
  1618. {
  1619. Info("DestFolder don't exist");
  1620. return false;
  1621. }
  1622. SHFILEOPSTRUCT sfo;
  1623. sfo.hwnd = NULL;
  1624. sfo.wFunc = FO_COPY;//FO_MOVE;
  1625. sfo.pFrom = strSrcPath.c_str();
  1626. sfo.pTo = strDstPath.c_str();
  1627. sfo.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_ALLOWUNDO; //| FOF_NOCONFIRMMKDIR;
  1628. // FOF_ALLOWUNDO:保存UNDO信息,以便在回收站中恢复文件;
  1629. //FOF_NOCONFIRMATION:在出现目标文件已存在的时候,如果不设置此项,则它会出现确认是否覆盖的对话框,设置此项则自动确认,进行覆盖,不出现对话框。
  1630. int nRet = SHFileOperation(&sfo);
  1631. Info("Copy File to Folder over, {$}", nRet);
  1632. return true;
  1633. }
  1634. bool IRayCtrl::SwithPanel(int nPanelId)
  1635. {
  1636. return true;
  1637. }
  1638. bool IRayCtrl::ActivePanel(nsDPC::FPDDeviceIRay* pDrvDPC, bool bActive)
  1639. {
  1640. Info("ActivePanel start: {$}, DetectorIndex {$}", pDrvDPC, m_nDetectorIndex);
  1641. map<nsDPC::FPDDeviceIRay*, int>::iterator DPCsIter = m_pDPC2PanelID->find(pDrvDPC);
  1642. if (DPCsIter != m_pDPC2PanelID->end())
  1643. {
  1644. if (m_nDetectorIndex != DPCsIter->second)
  1645. {
  1646. Info("DetectorIndex {$} != DPCsIter->second {$}", m_nDetectorIndex, DPCsIter->second);
  1647. if (!SwithPanel(DPCsIter->second))
  1648. {
  1649. return false;
  1650. }
  1651. m_nDetectorIndex = DPCsIter->second;
  1652. m_pCurrentDPC = pDrvDPC;
  1653. m_nCurrentMode = -1;
  1654. m_ModeConfig.clear();
  1655. m_ModeConfig = m_ObjFPDsInfo[m_nDetectorIndex];
  1656. m_bPreviewImg = m_stDeviceIndex[m_nDetectorIndex].bPreviewEnable;
  1657. Info("ActivePanel over: {$}, m_nDetectorIndex {$}", pDrvDPC, m_nDetectorIndex);
  1658. for (int i = 0; i < m_nPanelCount; i++)
  1659. {
  1660. ((nsDPC::FPDDeviceIRay*)(*m_pPanelID2DPC)[i])->UnactiveBySDK(pDrvDPC);
  1661. }
  1662. }
  1663. else
  1664. {
  1665. Info("DetectorIndex {$} == DPCsIter->second {$}", m_nDetectorIndex, DPCsIter->second);
  1666. }
  1667. }
  1668. else
  1669. {
  1670. Warn("Not find DPC in group");
  1671. return false;
  1672. }
  1673. return true;
  1674. }
  1675. bool IRayCtrl::EnterExam(APP_STATUS eStatus)
  1676. {
  1677. string strLog = "";
  1678. switch (eStatus)
  1679. {
  1680. case APP_STATUS_IDLE:
  1681. strLog = "APP_STATUS_IDLE";
  1682. break;
  1683. case APP_STATUS_WORK_BEGIN:
  1684. strLog = "APP_STATUS_WORK_BEGIN";
  1685. m_bInCalibrating = false;
  1686. break;
  1687. case APP_STATUS_WORK_END:
  1688. strLog = "APP_STATUS_WORK_END";
  1689. break;
  1690. case APP_STATUS_DETSHARE_BEGIN:
  1691. {
  1692. strLog = "APP_STATUS_DETSHARE_BEGIN";
  1693. break;
  1694. }
  1695. case APP_STATUS_DETSHAR_END:
  1696. {
  1697. strLog = "APP_STATUS_DETSHAR_END";
  1698. break;
  1699. }
  1700. case APP_STATUS_CAL_BEGIN:
  1701. strLog = "APP_STATUS_CAL_BEGIN";
  1702. break;
  1703. case APP_STATUS_CAL_END:
  1704. strLog = "APP_STATUS_CAL_END";
  1705. m_bInCalibrating = false;
  1706. break;
  1707. case APP_STATUS_WORK_IN_SENSITIVITY:
  1708. strLog = "APP_STATUS_WORK_IN_SENSITIVITY";
  1709. break;
  1710. default:
  1711. break;
  1712. }
  1713. Info("Enter exam: {$}", strLog.c_str());
  1714. m_eAppStatus = eStatus;
  1715. return true;
  1716. }
  1717. /***
  1718. ** 说明:连接
  1719. ** 加载SDK,初始化SDK,连接探测器等初始化操作
  1720. ** 参数:strWorkPath,初始化SDK必须的conf路径
  1721. ***/
  1722. bool IRayCtrl::Connect(string strAppPath, nsDPC::FPDDeviceIRay* pDrvDPC)
  1723. {
  1724. Info("--Func-- Connect");
  1725. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nDetectorIndex)
  1726. {
  1727. Warn("Not current DPC, return true");
  1728. return true;
  1729. }
  1730. StartInitFPDThread();
  1731. Info("=== Connect detector OK ===");
  1732. return true;
  1733. }
  1734. void IRayCtrl::DisconnectFD(int nDetectorID)
  1735. {
  1736. int nPanelID = nDetectorID + 1;
  1737. int nResult = 0;
  1738. Info("Call Cmd_Disconnect");
  1739. nResult = IrayFnInvoke(nPanelID, Cmd_Disconnect, NULL, 0);
  1740. if (TestError(nDetectorID, nResult))
  1741. {
  1742. Info("Disconnect Detector {$} Failed", nPanelID);
  1743. }
  1744. else
  1745. {
  1746. //fixbug: 8411 : disattach 探测器,断联后直接销毁,否正SDK会重新扫描添加该探测器
  1747. //bool bResult = WaitRespond(2000);
  1748. }
  1749. Info("Call Destroy");
  1750. nResult = m_fpDestroy(nPanelID);
  1751. TestError(nDetectorID, nResult);
  1752. Info("Destroy Over");
  1753. Info("disconnect FD {$} over\n", nPanelID);
  1754. }
  1755. /***
  1756. ** 说明:退出
  1757. ** 释放SDK
  1758. ***/
  1759. bool IRayCtrl::DisConnect(nsDPC::FPDDeviceIRay* pDrvDPC)
  1760. {
  1761. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nDetectorIndex)
  1762. {
  1763. Warn("Not current DPC, return");
  1764. return true;
  1765. }
  1766. Info("--Func-- DisConnect");
  1767. int nPanelID = m_nDetectorIndex + 1;
  1768. int nResult = IrayFnInvoke(nPanelID, Cmd_Disconnect, NULL, 0);
  1769. if (TestError(m_nDetectorIndex, nResult))
  1770. {
  1771. Info("Disconnect Detector {$} Failed", nPanelID);
  1772. }
  1773. else
  1774. {
  1775. //fixbug: 8411 : disattach 探测器,断联后直接销毁,否正SDK会重新扫描添加该探测器
  1776. //bool bResult = WaitRespond(2000);
  1777. }
  1778. Info("Call Destroy");
  1779. nResult = m_fpDestroy(nPanelID);
  1780. TestError(m_nDetectorIndex, nResult);
  1781. ErrorFeedback(EVT_ERR_MAX_NUMBER, "false", m_nDetectorIndex);
  1782. Info("DisConnect Over");
  1783. return true;
  1784. }
  1785. /********************************************************************/
  1786. /*
  1787. 功能:iRay没有曝光窗口关闭的消息,启动线程,等待500ms曝光窗口过后,模拟发送曝光窗口关闭的消息给HW层
  1788. /********************************************************************/
  1789. bool IRayCtrl::StartXWindowOffThread()
  1790. {
  1791. if (m_pXWindowoffThread == NULL)
  1792. {
  1793. DWORD m_NotifyThreadID;
  1794. m_pXWindowoffThread = CreateThread(0, 0, XWindowOffThread, this, 0, &m_NotifyThreadID);
  1795. if (m_pXWindowoffThread == NULL)
  1796. {
  1797. Fatal("Start Inner Exp Thread Failed");
  1798. return false;
  1799. }
  1800. }
  1801. return true;
  1802. }
  1803. /********************************************************************/
  1804. //
  1805. /*
  1806. 功能:iRay没有曝光窗口关闭的消息,启动线程,等待500ms曝光窗口过后,模拟发送曝光窗口关闭的消息给HW层
  1807. /********************************************************************/
  1808. DWORD IRayCtrl::XWindowOffThread(LPVOID pParam)
  1809. {
  1810. IRayCtrl* pCurPanel = (IRayCtrl*)pParam;
  1811. if (pCurPanel == NULL)
  1812. {
  1813. return false;
  1814. }
  1815. DWORD dwTimer = pCurPanel->m_stDeviceIndex[pCurPanel->m_nDetectorIndex].AcqModeInfo.nXwindow;
  1816. DWORD dwResult = WaitForSingleObject(pCurPanel->m_hWindowOffEvent, dwTimer);
  1817. Info("Simulate XWINDOW_OFF");
  1818. pCurPanel->StatusFeedback(EVT_STATUS_PANEL, PANEL_XWINDOW_OFF);
  1819. pCurPanel->m_pXWindowoffThread = NULL;
  1820. return true;
  1821. }
  1822. RET_STATUS IRayCtrl::SetSyncMode(SYNC_MODE nSyncMode, HARDWARE_TRIGGER_MODE TriggerMode)
  1823. {
  1824. return RET_STATUS::RET_SUCCEED;
  1825. }
  1826. bool IRayCtrl::SetAcqMode(nsDPC::FPDDeviceIRay* pDrvDPC, int nLogicMode, DetModeInfo& AcqModeInfo)
  1827. {
  1828. Info("## SetAcqMode ##({$})", nLogicMode);
  1829. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nDetectorIndex)
  1830. {
  1831. Warn("Not current DPC {$}, {$} != {$} ,return", pDrvDPC, (*m_pDPC2PanelID)[pDrvDPC], m_nDetectorIndex);
  1832. return false;
  1833. }
  1834. if (!SetAppMode(m_nDetectorID, AcqModeInfo.nOperationMode))
  1835. {
  1836. Error("Set application mode failed");
  1837. return false;
  1838. }
  1839. m_nCurrentMode = nLogicMode;
  1840. m_strCurrentExamType = AcqModeInfo.strExamType;
  1841. m_nRawImgWidth = AcqModeInfo.nRawImgWidth;
  1842. m_nRawImgHeight = AcqModeInfo.nRawImgHeight;
  1843. m_nImageWidth = AcqModeInfo.nImageWidth;
  1844. m_nImageHeight = AcqModeInfo.nImageHeight;
  1845. m_nImgBits = AcqModeInfo.nPhySizeInfoBit;
  1846. m_nPixelPitch = AcqModeInfo.nPixelPitch;
  1847. m_bSaveRaw = AcqModeInfo.bSaveRawEnable;
  1848. m_nCorrectionType = AcqModeInfo.nCorrectionType;
  1849. m_nExiThreshold = AcqModeInfo.nExiThreshold;
  1850. Info("RawImage({$}*{$}), Bits({$}), CorrectionType: {$}; SaveRaw({$})", m_nRawImgWidth, m_nRawImgHeight, m_nImgBits, m_nCorrectionType, m_bSaveRaw);
  1851. if (m_pwRawImageData)
  1852. {
  1853. delete[] m_pwRawImageData;
  1854. m_pwRawImageData = nullptr;
  1855. }
  1856. m_pwRawImageData = new WORD[m_nRawImgWidth * m_nRawImgHeight];
  1857. if (m_pwRawImageData == nullptr)
  1858. {
  1859. Fatal("Allocate Raw Image Failed");
  1860. return false;
  1861. }
  1862. //加载校正
  1863. SetDetectorCorrection(m_nDetectorID, m_nCorrectionType);
  1864. //设置触发方式
  1865. SetDetectorFluSync(m_nDetectorID, AcqModeInfo.nTriggerType);
  1866. Info("Set mode over");
  1867. return true;
  1868. }
  1869. /***
  1870. ** 说明:曝光前的准备流程
  1871. ***/
  1872. RET_STATUS IRayCtrl::PrepareAcquisition(nsDPC::FPDDeviceIRay* pDrvDPC)
  1873. {
  1874. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nDetectorIndex)
  1875. {
  1876. Warn("Not current DPC, return");
  1877. return RET_STATUS::RET_FAILED;
  1878. }
  1879. if (m_stDeviceIndex[m_nDetectorIndex].bConnectStatus == false)
  1880. {
  1881. Info("Current detector is not connect, return");
  1882. return RET_STATUS::RET_FAILED;
  1883. }
  1884. return RET_STATUS::RET_FAILED;
  1885. }
  1886. RET_STATUS IRayCtrl::StartAcquisition(nsDPC::FPDDeviceIRay* pDrvDPC)
  1887. {
  1888. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nDetectorIndex)
  1889. {
  1890. Warn("Not current DPC, return");
  1891. return RET_STATUS::RET_FAILED;
  1892. }
  1893. RET_STATUS Ret = RET_STATUS::RET_FAILED;
  1894. if (-1 == m_nCurrentMode)
  1895. {
  1896. Warn("Current mode({$}) is illegal, may not select exam mode successfully, return failed", m_nCurrentMode);
  1897. return Ret;
  1898. }
  1899. StatusFeedback(EVT_STATUS_ACQUISITION, PANEL_EVENT_START);
  1900. if (!WaitReady(m_nDetectorID, 1000))
  1901. {
  1902. Error("Detector isn't Ready");
  1903. return Ret;
  1904. }
  1905. FPDRESULT nResult = m_fpInvoke(m_nDetectorID, Cmd_StartAcq, NULL, 0);
  1906. if (TestError(m_nDetectorID, nResult))
  1907. {
  1908. Error("StartAcq Failed");
  1909. return Ret;
  1910. }
  1911. m_bInExposure = true;
  1912. m_bGrabStatus = true;
  1913. m_bWindowOn = false;
  1914. m_nFrameID = 0;
  1915. StatusFeedback(EVT_STATUS_PANEL, PANEL_XWINDOW_ON);
  1916. if (m_strCurrentExamType.find("RAD") != std::string::npos) //只有点片才发关窗终止Workflow
  1917. {
  1918. StartXWindowOffThread();
  1919. }
  1920. StatusFeedback(EVT_STATUS_ACQUISITION, PANEL_EVENT_END_OK);
  1921. return RET_STATUS::RET_SUCCEED;
  1922. }
  1923. RET_STATUS IRayCtrl::StopAcquisition(nsDPC::FPDDeviceIRay* pDrvDPC)
  1924. {
  1925. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nDetectorIndex)
  1926. {
  1927. Warn("Not current DPC, return");
  1928. return RET_STATUS::RET_FAILED;
  1929. }
  1930. Info("**StopAcquisition**");
  1931. RET_STATUS Ret = RET_STATUS::RET_FAILED;
  1932. FPDRESULT nResult = m_fpInvoke(m_nDetectorID, Cmd_StopAcq, NULL, 0);
  1933. if (TestError(m_nDetectorID, nResult))
  1934. {
  1935. Error("Stop Acq Error");
  1936. return Ret;
  1937. }
  1938. if (!WaitRespond(nCMD_TIME))
  1939. {
  1940. Error("Stop Acq Timeout");
  1941. }
  1942. Info("Stop Acq Success");
  1943. m_bInExposure = false;
  1944. m_bGrabStatus = false;
  1945. Ret = RET_STATUS::RET_SUCCEED;
  1946. return Ret;
  1947. }
  1948. bool IRayCtrl::GetiRayPanelCalibItem()
  1949. {
  1950. m_listCalibItem.clear();
  1951. try {
  1952. int nModeCount = (int)m_ModeConfig["ModeTable"].GetKeyCount("DetectorMode");
  1953. for (int i = 0; i < nModeCount; i++)
  1954. {
  1955. int nCalibModeCount = (int)m_ModeConfig["ModeTable"][i]["CalibConfig"].GetKeyCount("NodeInfo");
  1956. for (int j = 0; j < nCalibModeCount; j++)
  1957. {
  1958. RefrenceCal stRefCal;
  1959. stRefCal.nAvgNum = (int)m_ModeConfig["ModeTable"][i]["CalibConfig"][j]["ImgCount"];
  1960. stRefCal.nReferDose = (int)m_ModeConfig["ModeTable"][i]["CalibConfig"][j]["Dose"];
  1961. m_listCalibItem.push_back(stRefCal);
  1962. }
  1963. }
  1964. }
  1965. catch (...)
  1966. {
  1967. return false;
  1968. }
  1969. return true;
  1970. }
  1971. bool IRayCtrl::InitCalibration()
  1972. {
  1973. m_nDefectExpTimes = 0;
  1974. m_nDefectTotalTimes = 0;
  1975. m_nGainExpTimes = 0;
  1976. string strMode = "STE";
  1977. m_bCalibResultFailed = false;
  1978. m_bInCalibrating = true;
  1979. int nPanelID = m_nDetectorIndex + 1;
  1980. list<RefrenceCal>::iterator iter;
  1981. for (iter = m_listCalibItem.begin(); iter != m_listCalibItem.end(); iter++)
  1982. {
  1983. Info("Calibration dose:{$},Number:{$}", iter->nReferDose, iter->nAvgNum);
  1984. }
  1985. m_iterCalibDose = m_listCalibItem.begin();
  1986. m_nDoseParam = m_iterCalibDose->nReferDose;
  1987. DataFeedback(EVT_DATA_DOSEPARAM, NULL, m_nDoseParam);
  1988. Info("First Calibration dose:{$},Number:{$},m_nDoseParam = {$}", m_iterCalibDose->nReferDose, m_iterCalibDose->nAvgNum, m_nDoseParam);
  1989. if (!WaitReady(nPanelID, 1000))
  1990. {
  1991. Error("Detector isn't Ready");
  1992. return false;
  1993. }
  1994. m_nGainTotalFrames = 0;
  1995. if (!GetAttr(nPanelID, Attr_GainTotalFrames, m_nGainTotalFrames))
  1996. {
  1997. Error("Get GainTotalFrames failed");
  1998. }
  1999. m_nDefectTotalFrames = 0;
  2000. if (!GetAttr(nPanelID, Attr_DefectTotalFrames, m_nDefectTotalFrames))
  2001. {
  2002. Error("Get DefectTotalFrames failed");
  2003. }
  2004. Info("GainTotalFrames: {$},DefectTotalFrames: {$}", m_nGainTotalFrames, m_nDefectTotalFrames);
  2005. m_nCalibStatus = PANEL_GAIN_CAL;
  2006. ResetLock();
  2007. Info("Call Cmd_GainInit");
  2008. FPDRESULT nResult = IrayFnInvoke(nPanelID, Cmd_GainInit, NULL, 0);
  2009. if (!TestError(m_nDetectorIndex, nResult))
  2010. {
  2011. if (WaitRespond(5000))
  2012. {
  2013. Info("call Cmd_GainInit Success");
  2014. }
  2015. else
  2016. {
  2017. Error("call Cmd_GainInit Failed");
  2018. return false;
  2019. }
  2020. }
  2021. return true;
  2022. }
  2023. /***
  2024. ** 说明:激活校正
  2025. ** 增益校正(探测器采用post-offset,暗场校正基本没用了)时拿到dose回调,算作执行完毕
  2026. ***/
  2027. RET_STATUS IRayCtrl::ActiveCalibration(CCOS_CALIBRATION_TYPE Type, nsDPC::FPDDeviceIRay* pDrvDPC)
  2028. {
  2029. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nDetectorIndex)
  2030. {
  2031. Warn("Not current DPC, return");
  2032. return RET_STATUS::RET_FAILED;
  2033. }
  2034. RET_STATUS Ret = RET_STATUS::RET_SUCCEED;
  2035. if (CCOS_CALIBRATION_TYPE_DARK == Type)
  2036. {
  2037. Info("ActiveDarkCalibration");
  2038. }
  2039. else if (CCOS_CALIBRATION_TYPE_XRAY == Type)
  2040. {
  2041. Info("ActiveXrayCalibration");
  2042. StatusFeedback(EVT_STATUS_CALIBRATIOIN, PANEL_EVENT_START);
  2043. if (!InitCalibration())
  2044. {
  2045. StatusFeedback(EVT_STATUS_CALIBRATIOIN, PANEL_EVENT_END_ERROR);
  2046. return RET_STATUS::RET_FAILED;
  2047. }
  2048. }
  2049. else
  2050. {
  2051. Error("Active not supported calibration({$}), return! \n", (int)Type);
  2052. Ret = RET_STATUS::RET_NOSUPPORT;
  2053. return Ret;
  2054. }
  2055. m_eCaliType = Type;
  2056. return Ret;
  2057. }
  2058. /***
  2059. ** 说明:开始校正(状态机FrameStart)
  2060. ** Salmon项目只有普通rad模式,所以本接口基本没用
  2061. ***/
  2062. RET_STATUS IRayCtrl::StartCalibration(nsDPC::FPDDeviceIRay* pDrvDPC)
  2063. {
  2064. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nDetectorIndex)
  2065. {
  2066. Warn("Not current DPC, return");
  2067. return RET_STATUS::RET_FAILED;
  2068. }
  2069. RET_STATUS Ret = RET_STATUS::RET_FAILED;
  2070. if (CCOS_CALIBRATION_TYPE_DARK == m_eCaliType)
  2071. {
  2072. Info("StartDarkCalibration \n");
  2073. //SetEvent(m_hOffsetEvent);
  2074. Ret = RET_STATUS::RET_SUCCEED;
  2075. }
  2076. else
  2077. {
  2078. Info("StartXrayCalibration \n");
  2079. int nPanelID = m_nDetectorIndex + 1;
  2080. FPDRESULT nResult = IrayFnInvoke(nPanelID, Cmd_ClearAcq, NULL, 0);
  2081. if (TestError(m_nDetectorIndex, nResult))
  2082. {
  2083. Error("Invoke Cmd_ClearAcq Failed");
  2084. m_bInExposure = false;
  2085. StatusFeedback(EVT_STATUS_CALIBRATIOIN, PANEL_EVENT_END_ERROR);
  2086. return Ret;
  2087. }
  2088. else
  2089. {
  2090. m_stDeviceIndex[m_nDetectorIndex].bTaskEnd = false;
  2091. Info("Send BeginCapture message");
  2092. }
  2093. Ret = RET_STATUS::RET_SUCCEED;
  2094. }
  2095. return Ret;
  2096. }
  2097. bool IRayCtrl::ConfirmCalibration()
  2098. {
  2099. Info("confirm Calibration");
  2100. if (PANEL_GAIN_CAL == m_nCalibStatus)
  2101. {
  2102. IRayCmdParam param[2];
  2103. param[0].pt = IPT_VARIANT;
  2104. param[0].var.vt = IVT_INT;
  2105. param[0].var.val.nVal = 0;
  2106. param[1].pt = IPT_VARIANT;
  2107. param[1].var.vt = IVT_INT;
  2108. param[1].var.val.nVal = m_nGainExpTimes;
  2109. Info("Call Cmd_GainSelectCurrent:{$}", m_nGainExpTimes);
  2110. int nPanelID = m_nDetectorIndex + 1;
  2111. FPDRESULT nResult = IrayFnInvoke(nPanelID, Cmd_GainSelectCurrent, param, 2);
  2112. if (!TestError(m_nDetectorIndex, nResult, false))
  2113. {
  2114. Info("Cmd_GainSelectCurrent Success");
  2115. m_nGainExpTimes++;
  2116. StatusFeedback(EVT_STATUS_SINGLEEXP, DOSE_ACCEPT);
  2117. AcceptCalibration();
  2118. }
  2119. else
  2120. {
  2121. switch (nResult)
  2122. {
  2123. case Err_Cali_UnexpectImage_DoseOver://3007
  2124. {
  2125. Info("DOSE_TOO_HIGH");
  2126. StatusFeedback(EVT_STATUS_SINGLEEXP, DOSE_TOO_HIGH);
  2127. break;
  2128. }
  2129. case Err_Cali_UnexpectImage_DoseUnder://3008
  2130. {
  2131. Info("DOSE_TOO_LOW");
  2132. StatusFeedback(EVT_STATUS_SINGLEEXP, DOSE_TOO_LOW);
  2133. break;
  2134. }
  2135. case Err_Cali_UnexpectImage_ObjectDetected:// 3009
  2136. {
  2137. Info("DOSE_OBJECT");
  2138. StatusFeedback(EVT_STATUS_SINGLEEXP, DOSE_OBJECT);
  2139. break;
  2140. }
  2141. default:
  2142. break;
  2143. }
  2144. Error("Cmd_GainSelectCurrent Failed");
  2145. }
  2146. }
  2147. else if (PANEL_DEFECT_CAL == m_nCalibStatus)
  2148. {
  2149. IRayCmdParam param[1];
  2150. param[0].pt = IPT_VARIANT;
  2151. param[0].var.vt = IVT_INT;
  2152. param[0].var.val.nVal = m_nDefectTotalTimes;
  2153. Info("Call Cmd_DefectSelectCurrent ");
  2154. int nPanelID = m_nDetectorIndex + 1;
  2155. FPDRESULT nResult = IrayFnInvoke(nPanelID, Cmd_DefectSelectCurrent, param, 1);
  2156. if (!TestError(m_nDetectorIndex, nResult, false))
  2157. {
  2158. Info("Cmd_DefectSelectCurrent Success");
  2159. m_nDefectExpTimes++;
  2160. m_nDefectTotalTimes++;
  2161. StatusFeedback(EVT_STATUS_SINGLEEXP, DOSE_ACCEPT);
  2162. AcceptCalibration();
  2163. }
  2164. else
  2165. {
  2166. switch (nResult)
  2167. {
  2168. case Err_Cali_UnexpectImage_DoseOver://3007
  2169. {
  2170. StatusFeedback(EVT_STATUS_SINGLEEXP, DOSE_TOO_HIGH);
  2171. Info("DOSE_TOO_HIGH");
  2172. break;
  2173. }
  2174. case Err_Cali_UnexpectImage_DoseUnder://3008
  2175. {
  2176. StatusFeedback(EVT_STATUS_SINGLEEXP, DOSE_TOO_LOW);
  2177. Info("DOSE_TOO_LOW");
  2178. break;
  2179. }
  2180. case Err_Cali_UnexpectImage_ObjectDetected:// 3009
  2181. {
  2182. StatusFeedback(EVT_STATUS_SINGLEEXP, DOSE_OBJECT);
  2183. Info("DOSE_OBJECT");
  2184. break;
  2185. }
  2186. default:
  2187. break;
  2188. }
  2189. Error("Cmd_DefectSelectCurrent Failed");
  2190. }
  2191. }
  2192. return true;
  2193. }
  2194. bool IRayCtrl::AcceptCalibration()
  2195. {
  2196. if ((PANEL_GAIN_CAL == m_nCalibStatus) && (m_nGainExpTimes >= m_nGainTotalFrames))
  2197. {
  2198. Info("Gain exposure over");
  2199. if (CreateCalibrationFile())
  2200. {
  2201. m_iterCalibDose++;
  2202. m_nDoseParam = m_iterCalibDose->nReferDose;
  2203. Info("Next Gain Calibration dose:{$},Number:{$}", m_iterCalibDose->nReferDose, m_iterCalibDose->nAvgNum);
  2204. }
  2205. else
  2206. {
  2207. StatusFeedback(EVT_STATUS_SINGLEEXP, PANEL_EVENT_END_ERROR);
  2208. }
  2209. }
  2210. else if (PANEL_DEFECT_CAL == m_nCalibStatus)
  2211. {
  2212. int nAvgNum = m_iterCalibDose->nAvgNum;
  2213. if (m_nDefectExpTimes >= nAvgNum)
  2214. {
  2215. m_nDefectExpTimes = 0;
  2216. m_iterCalibDose++;
  2217. m_nDoseParam = m_iterCalibDose->nReferDose;
  2218. Info("Next Defect Calibration dose:{$},Number:{$}", m_iterCalibDose->nReferDose, m_iterCalibDose->nAvgNum);
  2219. }
  2220. if (m_nDefectTotalTimes >= m_nDefectTotalFrames)
  2221. {
  2222. Info("Defect exposure over");
  2223. StatusFeedback(EVT_STATUS_PREPARE_EDNCALIBRATION, 0);
  2224. if (CreateCalibrationFile())
  2225. {
  2226. StatusFeedback(EVT_STATUS_CALIBRATIOIN, PANEL_EVENT_END_OK);
  2227. }
  2228. else
  2229. {
  2230. StatusFeedback(EVT_STATUS_SINGLEEXP, PANEL_EVENT_END_ERROR);
  2231. }
  2232. return true;
  2233. }
  2234. }
  2235. DataFeedback(EVT_DATA_DOSEPARAM, NULL, m_nDoseParam);
  2236. return true;
  2237. }
  2238. bool IRayCtrl::CreateCalibrationFile()
  2239. {
  2240. int nPanelIndex = m_nDetectorIndex + 1;;
  2241. if (PANEL_GAIN_CAL == m_nCalibStatus)
  2242. {
  2243. Info("Call Cmd_GainGeneration");
  2244. FPDRESULT nResult = IrayFnInvoke(nPanelIndex, Cmd_GainGeneration, NULL, 0);
  2245. if (!TestError(m_nDetectorIndex, nResult))
  2246. {
  2247. Info("Cmd_GainGeneration Success");
  2248. }
  2249. else
  2250. {
  2251. Error("Cmd_GainGeneration Failed");
  2252. return false;
  2253. }
  2254. }
  2255. else
  2256. {
  2257. Info("Call Cmd_DefectGeneration");
  2258. FPDRESULT nResult = IrayFnInvoke(nPanelIndex, Cmd_DefectGeneration, NULL, 0);
  2259. if (!TestError(m_nDetectorIndex, nResult))
  2260. {
  2261. Info("Cmd_DefectGeneration Success");
  2262. }
  2263. else
  2264. {
  2265. Error("Cmd_DefectGeneration Failed");
  2266. return false;
  2267. }
  2268. }
  2269. //Clean up
  2270. Info("Call Cmd_FinishGenerationProcess");
  2271. FPDRESULT nResult = IrayFnInvoke(nPanelIndex, Cmd_FinishGenerationProcess, NULL, 0);
  2272. if (!TestError(m_nDetectorIndex, nResult))
  2273. {
  2274. if (WaitRespond(10000)) //defect finish慢,5,6秒左右
  2275. {
  2276. Info("call Cmd_FinishGenerationProcess Success");
  2277. }
  2278. else
  2279. {
  2280. Error("call Cmd_FinishGenerationProcess Failed");
  2281. return false;
  2282. }
  2283. }
  2284. if (PANEL_GAIN_CAL == m_nCalibStatus)
  2285. {
  2286. m_nCalibStatus = PANEL_DEFECT_CAL;
  2287. ResetLock();
  2288. Info("Call Cmd_DefectInit");
  2289. nResult = IrayFnInvoke(nPanelIndex, Cmd_DefectInit, NULL, 0);
  2290. if (!TestError(m_nDetectorIndex, nResult))
  2291. {
  2292. if (WaitRespond(10000))
  2293. {
  2294. Info("call Cmd_DefectInit Success");
  2295. }
  2296. else
  2297. {
  2298. Error("call Cmd_DefectInit Failed");
  2299. return false;
  2300. }
  2301. }
  2302. }
  2303. return true;
  2304. }
  2305. bool IRayCtrl::RejectCalibration()
  2306. {
  2307. Info("Reject Calibration");
  2308. return true;
  2309. }
  2310. /***
  2311. ** 说明:终止校正
  2312. ***/
  2313. RET_STATUS IRayCtrl::AbortCalibration(nsDPC::FPDDeviceIRay* pDrvDPC)
  2314. {
  2315. if (!m_bInCalibrating)
  2316. {
  2317. Warn("Not in calibration status,omit it.");
  2318. return RET_STATUS::RET_SUCCEED;
  2319. }
  2320. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nDetectorIndex)
  2321. {
  2322. Warn("Not current DPC, return");
  2323. return RET_STATUS::RET_FAILED;
  2324. }
  2325. Info("AbortCalibration \n");
  2326. m_eCaliType = CCOS_CALIBRATION_TYPE_NONE; //恢复初值
  2327. m_bConfirmCaliRst = false; //终止校正,恢复初值
  2328. RET_STATUS Ret = RET_STATUS::RET_FAILED;
  2329. if (m_nPanelCount < 0)
  2330. {
  2331. Info("No active detector");
  2332. return Ret;
  2333. }
  2334. bool bLTE = false;
  2335. if (m_bInCalibrating)
  2336. {
  2337. if (m_bInExposure)
  2338. {
  2339. bool bResult = WaitRespond(10000);
  2340. }
  2341. m_bInCalibrating = false;
  2342. Info("Call m_pfAbort");
  2343. int nPanelID = m_nDetectorIndex + 1;
  2344. int ret = m_pfAbort(nPanelID);
  2345. if (TestError(m_nDetectorIndex, ret, false))
  2346. {
  2347. Info("Abort Cmd Failed");
  2348. if (m_bCalibResultFailed)
  2349. {
  2350. SaveFailedCalibFiles(m_nDetectorIndex, bLTE);
  2351. m_bCalibResultFailed = false;
  2352. }
  2353. CleanCalibFiles(m_nDetectorIndex, bLTE);
  2354. return Ret;
  2355. }
  2356. bool bResult = WaitRespond(120 * 1000);
  2357. if (bResult)
  2358. {
  2359. Info("Abort Calibration Success");
  2360. //return true;
  2361. }
  2362. else
  2363. {
  2364. Error("Abort Calibration Timeout");
  2365. //return false;
  2366. }
  2367. }
  2368. else
  2369. {
  2370. Info("Omit Abort Calibration");
  2371. }
  2372. if (m_bCalibResultFailed)
  2373. {
  2374. SaveFailedCalibFiles(m_nDetectorIndex, bLTE);
  2375. m_bCalibResultFailed = false;
  2376. }
  2377. //恢复校正文件
  2378. CleanCalibFiles(m_nDetectorIndex, bLTE);
  2379. Ret = RET_STATUS::RET_SUCCEED;
  2380. return Ret;
  2381. }
  2382. /***
  2383. ** 说明:准备校正(状态机FramePrep)
  2384. ** 曝光使能过程,使探测器开窗
  2385. ***/
  2386. RET_STATUS IRayCtrl::PrepareCalibration(nsDPC::FPDDeviceIRay* pDrvDPC)
  2387. {
  2388. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nDetectorIndex)
  2389. {
  2390. Warn("Not current DPC, return");
  2391. return RET_STATUS::RET_FAILED;
  2392. }
  2393. Debug("PrepareCalibration Over");
  2394. return RET_STATUS::RET_SUCCEED;
  2395. }
  2396. /***
  2397. ** 说明:结束校正
  2398. ** DPC处理完校正报告后调用,此处上传map、报告等文件
  2399. ***/
  2400. RET_STATUS IRayCtrl::CompleteCalibration(nsDPC::FPDDeviceIRay* pDrvDPC)
  2401. {
  2402. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nDetectorIndex)
  2403. {
  2404. Warn("Not current DPC, return");
  2405. return RET_STATUS::RET_FAILED;
  2406. }
  2407. SetEvent(m_hEndCalibEvent);
  2408. Info("CompleteCalibration");
  2409. return RET_STATUS::RET_SUCCEED;
  2410. }
  2411. void IRayCtrl::OnEndCalibraion()
  2412. {
  2413. Info("OnEndCalibraion start");
  2414. m_fCalibTemperature2 = m_stDeviceIndex[m_nDetectorIndex].fCurrentTemperValue;
  2415. m_stDeviceIndex[m_nDetectorIndex].fCalibTemperature1 = m_fCalibTemperature1;
  2416. m_stDeviceIndex[m_nDetectorIndex].fCalibTemperature2 = m_fCalibTemperature2;
  2417. m_fCalibTemperature = (m_fCalibTemperature1 + m_fCalibTemperature2) / 2;
  2418. m_bInCalibrating = false;
  2419. bool bLTE = false;
  2420. bool bRet = true;
  2421. bool bResult = DownloadCalibrationFileToFD(true, bLTE);
  2422. bResult = DownloadCalibrationFileToFD(false, bLTE);
  2423. if (!bResult)
  2424. {
  2425. Info("UploadCalibrationFileToFD files");
  2426. }
  2427. GetCalibrationTime(m_nDetectorIndex, bLTE);
  2428. string szTemp;
  2429. szTemp = m_stDeviceIndex[m_nDetectorIndex].strCalibrationDate;
  2430. WriteCumstomFile(m_nDetectorIndex);//上传校正报告,sensitivity
  2431. if (bRet)
  2432. {
  2433. StatusFeedback(EVT_STATUS_SAVECALIB, PANEL_EVENT_END);
  2434. }
  2435. else
  2436. {
  2437. StatusFeedback(EVT_STATUS_SAVECALIB, PANEL_EVENT_END_ERROR);
  2438. }
  2439. Info("Calibration completed!");
  2440. return;
  2441. }
  2442. bool IRayCtrl::GetCorrectFileIndex(int& nGainMapIndex, int& nDefectMapIndex)
  2443. {
  2444. int nDetectorIdx = m_nDetectorIndex + 1;
  2445. if (!GetAttr(nDetectorIdx, Attr_HwTmpl_Gain_ValidIndex, nGainMapIndex))
  2446. {
  2447. Error("Get GainMapIndex failed");
  2448. return false;
  2449. }
  2450. else
  2451. {
  2452. Info("Current GainMapIndex is {$}", nGainMapIndex);
  2453. }
  2454. if (!GetAttr(nDetectorIdx, Attr_HwTmpl_Defect_ValidIndex, nDefectMapIndex))
  2455. {
  2456. Error("Get DefectMapIndex failed");
  2457. return false;
  2458. }
  2459. else
  2460. {
  2461. Info("Current DefectMapIndex is {$}", nDefectMapIndex);
  2462. }
  2463. return true;
  2464. }
  2465. bool IRayCtrl::SetCorrectFile()
  2466. {
  2467. bool bRet = true;
  2468. int nGainMapIndex = 0;
  2469. int nDefectMapIndex = 0;
  2470. if (GetCorrectFileIndex(nGainMapIndex, nDefectMapIndex))
  2471. {
  2472. if (nGainMapIndex == 10 && nDefectMapIndex == 10)
  2473. {
  2474. Info("Calibration files already is 10");
  2475. return bRet;
  2476. }
  2477. }
  2478. IRayCmdParam param[2];
  2479. param[0].pt = IPT_VARIANT;
  2480. param[0].var.vt = IVT_INT;
  2481. param[0].var.val.nVal = Enm_File_Gain;
  2482. param[1].pt = IPT_VARIANT;
  2483. param[1].var.vt = IVT_INT;
  2484. param[1].var.val.nVal = 1;
  2485. m_bSetCorrectFile = true;
  2486. int nPanelID = m_nDetectorIndex + 1;
  2487. if (nGainMapIndex != param[1].var.val.nVal)
  2488. {
  2489. Info("Active gain calibration files to {$}", param[1].var.val.nVal);
  2490. if (!WaitReady(nPanelID, 2000))
  2491. {
  2492. Error("Active gain calibration files Failed");
  2493. return false;
  2494. }
  2495. m_stDeviceIndex[m_nDetectorIndex].bUploadCalibFile = false;
  2496. FPDRESULT nResult = IrayFnInvoke(nPanelID, Cmd_SelectCaliFile, param, 2);
  2497. if (!TestError(nPanelID, nResult))
  2498. {
  2499. if (WaitRespond(16000))
  2500. {
  2501. if (m_stDeviceIndex[m_nDetectorIndex].bUploadCalibFile)
  2502. {
  2503. Info("Cmd_SelectCaliFile Success");
  2504. }
  2505. else
  2506. {
  2507. Info("Cmd_SelectCaliFile Failed");
  2508. bRet &= false;
  2509. }
  2510. }
  2511. else
  2512. {
  2513. Info("Cmd_SelectCaliFile timeout");
  2514. bRet &= false;
  2515. }
  2516. }
  2517. else
  2518. {
  2519. Info("Cmd_SelectCaliFile Failed");
  2520. bRet &= false;
  2521. }
  2522. }
  2523. else
  2524. {
  2525. Info("gain calibration files already in {$}", param[1].var.val.nVal);
  2526. }
  2527. if (nDefectMapIndex != param[1].var.val.nVal)
  2528. {
  2529. Info("Active defect calibration files to {$}", param[1].var.val.nVal);
  2530. param[0].var.val.nVal = Enm_File_Defect;
  2531. if (!WaitReady(nPanelID, 2000))
  2532. {
  2533. Error("Active defect calibration files Failed");
  2534. return false;
  2535. }
  2536. m_stDeviceIndex[m_nDetectorIndex].bUploadCalibFile = false;
  2537. FPDRESULT nResult = IrayFnInvoke(nPanelID, Cmd_SelectCaliFile, param, 2);
  2538. if (!TestError(nPanelID, nResult))
  2539. {
  2540. if (WaitRespond(16000))
  2541. {
  2542. if (m_stDeviceIndex[m_nDetectorIndex].bUploadCalibFile)
  2543. {
  2544. Info("Cmd_SelectCaliFile Success");
  2545. }
  2546. else
  2547. {
  2548. Info("Cmd_SelectCaliFile Failed");
  2549. bRet &= false;
  2550. }
  2551. }
  2552. else
  2553. {
  2554. Info("Cmd_SelectCaliFile timeout");
  2555. bRet &= false;
  2556. }
  2557. }
  2558. else
  2559. {
  2560. Info("Cmd_SelectCaliFile Failed");
  2561. bRet &= false;
  2562. }
  2563. }
  2564. else
  2565. {
  2566. Info("defect calibration files already in {$}", param[1].var.val.nVal);
  2567. }
  2568. if (bRet)
  2569. {
  2570. Info("Cmd_SelectCaliFile {$} Success", param[1].var.val.nVal);
  2571. }
  2572. m_bSetCorrectFile = false;
  2573. return bRet;
  2574. }
  2575. bool IRayCtrl::RecoverLastImage()
  2576. {
  2577. Info("Recover Last Image");
  2578. if (m_bIsImageRecovering)
  2579. {
  2580. Warn("Recover Image is processing, return");
  2581. return false;
  2582. }
  2583. return RecoverImage();
  2584. }
  2585. bool IRayCtrl::RecoverLastImageAuto()
  2586. {
  2587. Info("Recover Last Image Auto");
  2588. if (m_bIsImageRecovering)
  2589. {
  2590. Warn("Recover Image is processing, return");
  2591. return false;
  2592. }
  2593. if (m_bImageRecoverBeCanceled)
  2594. {
  2595. Info("Image Recover Be Canceled");
  2596. return false;
  2597. }
  2598. ResetLock();
  2599. Info("Call Cmd_QueryLastImageID");
  2600. m_stDeviceIndex[m_nLastExpFDIndex].bRecoveringImage = true;
  2601. m_stDeviceIndex[m_nLastExpFDIndex].nLastImageID = -1;
  2602. int nPanelID = m_nLastExpFDIndex + 1;
  2603. FPDRESULT nResult = IrayFnInvoke(nPanelID, Cmd_QueryLastImageID, NULL, 0);
  2604. if (TestError(m_nLastExpFDIndex, nResult))
  2605. {
  2606. Error("Invoke Cmd_QueryLastImageID Failed");
  2607. return false;
  2608. }
  2609. else
  2610. {
  2611. Info("Query LastImageID success");
  2612. }
  2613. bool bResult = false;
  2614. bResult = WaitRespond(5000); //Evt_LastImageID
  2615. if (!bResult)
  2616. {
  2617. Error("Evt_LastImageID timeout. ");
  2618. SetEvent(m_hRecoverImage);
  2619. return false;
  2620. }
  2621. if (!m_stDeviceIndex[m_nLastExpFDIndex].bImagePending)
  2622. {
  2623. Warn("this image already be Transfered");
  2624. return false;
  2625. }
  2626. if (-1 == m_stDeviceIndex[m_nLastExpFDIndex].nLastImageID)
  2627. {
  2628. Error("Evt_LastImageID timeout2 ");
  2629. SetEvent(m_hRecoverImage);
  2630. return false;
  2631. }
  2632. m_stDeviceIndex[m_nLastExpFDIndex].bConnectStatus = true;
  2633. IRayCmdParam param;
  2634. param.var.vt = IVT_INT;
  2635. param.var.val.nVal = m_stDeviceIndex[m_nLastExpFDIndex].nLastImageID;
  2636. nResult = IrayFnInvoke(nPanelID, Cmd_GetImageByImageID, &param, 1);
  2637. Info("Call Cmd_GetImageByImageID , ID = {$} , result = {$}", m_stDeviceIndex[m_nLastExpFDIndex].nLastImageID, nResult);
  2638. if (TestError(m_nLastExpFDIndex, nResult))
  2639. {
  2640. Error("Invoke Cmd_GetImageByImageID Failed");
  2641. SetEvent(m_hRecoverImage);
  2642. return false;
  2643. }
  2644. else
  2645. {
  2646. m_stDeviceIndex[m_nLastExpFDIndex].bTaskEnd = false;
  2647. Info("Get Image ByImageID success");
  2648. }
  2649. return true;
  2650. }
  2651. /********************************************************************/
  2652. //
  2653. /*
  2654. 功能:1717VS固定板,需要对SDK输出的图像进行镜像,做到所见即所得。
  2655. */
  2656. /********************************************************************/
  2657. bool IRayCtrl::FlipX(WORD* pData, int nWidth, int nHeight)
  2658. {
  2659. int j = 0;
  2660. int i = 0;
  2661. Info("Flip Image Width:{$},Height:{$}", nWidth, nHeight);
  2662. WORD temp;
  2663. //修改翻转的判断,之前的代码会导致中央区域多翻转一个像素
  2664. for (i = 0; i < nHeight; i++)
  2665. {
  2666. for (j = 0; j < nWidth / 2; j++)
  2667. {
  2668. temp = pData[i * nWidth + j];
  2669. pData[i * nWidth + j] = pData[(i + 1) * nWidth - j - 1];
  2670. pData[(i + 1) * nWidth - j - 1] = temp;
  2671. }
  2672. }
  2673. Info("Flip Image Over");
  2674. return true;
  2675. }
  2676. /********************************************************************/
  2677. //
  2678. /*
  2679. 功能:1717VS固定板,需要对SDK输出的图像,先旋转90度,再做镜像,做到所见即所得。
  2680. */
  2681. /********************************************************************/
  2682. bool IRayCtrl::FlipXRotate90(WORD* pData, int nWidth, int nHeight)
  2683. {
  2684. Info("Rotate 270 angle");
  2685. WORD* ptempData = new WORD[nWidth * nHeight];
  2686. memcpy(ptempData, pData, nWidth * nHeight * sizeof(WORD));
  2687. for (int i = 0; i < nWidth; i++)
  2688. for (int j = 0; j < nHeight; j++)
  2689. pData[i * nWidth + j] = ptempData[j * nWidth + (nWidth - 1 - i)];
  2690. delete[]ptempData;
  2691. ptempData = NULL;
  2692. FlipX(pData, nWidth, nHeight);
  2693. return true;
  2694. }
  2695. //读取电池
  2696. bool IRayCtrl::ReadBatteryStatus(int nDetectorID)
  2697. {
  2698. if (!m_stDeviceIndex[m_nDetectorIndex].bBatteryEnable)
  2699. {
  2700. return false;
  2701. }
  2702. Debug("Begin to Read Battery");
  2703. if (!WaitReady(nDetectorID, 600))
  2704. {
  2705. Fatal("Read Battery Failed");
  2706. return false;
  2707. }
  2708. FPDRESULT nResult = IrayFnInvoke(nDetectorID, Cmd_ReadBatteryStatus, NULL, 0);
  2709. if (TestError(nDetectorID, nResult))
  2710. {
  2711. Fatal("Read Battery Failed");
  2712. return false;
  2713. }
  2714. if (!WaitRespond(nCMD_TIME))
  2715. {
  2716. Warn("Read Battery Timeout");
  2717. return false;
  2718. }
  2719. Debug("Read Battery Success");
  2720. return true;
  2721. }
  2722. bool IRayCtrl::CheckBattery(int nDetectorID)
  2723. {
  2724. int nPanelID = nDetectorID;
  2725. if (!m_stDeviceIndex[m_nDetectorIndex].bBatteryEnable)
  2726. {
  2727. return false;
  2728. }
  2729. int nExist = 0;
  2730. int nBatteryValue = 0;
  2731. int nChargingStatus = 0;
  2732. GetBatteryChargingStatus(nDetectorID, nChargingStatus);
  2733. if (nChargingStatus)
  2734. {
  2735. Debug("Detector is Charging");
  2736. m_stDeviceIndex[m_nDetectorIndex].bCharging = true;
  2737. }
  2738. else
  2739. {
  2740. m_stDeviceIndex[m_nDetectorIndex].bCharging = false;
  2741. }
  2742. if (GetBatteryExist(nDetectorID, nExist))
  2743. {
  2744. if (nExist == Enm_On)
  2745. {
  2746. GetBatteryRemaining(nPanelID, nBatteryValue);
  2747. m_nBatteryCapacity = nBatteryValue;
  2748. StatusFeedback(EVT_STATUS_BATTERY_VALUE, nBatteryValue, "", nDetectorID);
  2749. }
  2750. else
  2751. {
  2752. Info("Battery is not exist");
  2753. StatusFeedback(EVT_STATUS_BATTERY_VALUE, 0, "", nDetectorID);
  2754. }
  2755. }
  2756. else
  2757. {
  2758. Fatal("Get Battery Exist Fail");
  2759. StatusFeedback(EVT_STATUS_BATTERY_VALUE, 0, "", nDetectorID);
  2760. return false;
  2761. }
  2762. return true;
  2763. }
  2764. //读取探测器WIFI,SDK会将WIFI值写入Attr_WifiStatu_WorkingLinkQuality ,从该Attr读取WIFI值
  2765. bool IRayCtrl::ReadWifiStatus(int nDetectorID)
  2766. {
  2767. if (!m_stDeviceIndex[m_nDetectorIndex].bWifiEnable)
  2768. {
  2769. return false;
  2770. }
  2771. Debug("Read Wifi");
  2772. if (!WaitReady(nDetectorID, 500))
  2773. {
  2774. Fatal("Read Wifi Failed");
  2775. return false;
  2776. }
  2777. FPDRESULT nResult = IrayFnInvoke(nDetectorID, Cmd_ReadWifiStatus, NULL, 0);
  2778. if (TestError(nDetectorID, nResult))
  2779. {
  2780. Fatal("Read Wifi Failed");
  2781. return false;
  2782. }
  2783. if (WaitRespond(8000))
  2784. {
  2785. Info("Read Wifi success");
  2786. return true;
  2787. }
  2788. Warn("Read Wifi Timeout");
  2789. return false;
  2790. }
  2791. bool IRayCtrl::CheckWiFi(int nDetectorID)
  2792. {
  2793. int nPanelID = nDetectorID;
  2794. if (!m_stDeviceIndex[m_nDetectorIndex].bWifiEnable)
  2795. {
  2796. return false;
  2797. }
  2798. int nConnectInterface = -1;
  2799. int nWifiValue = 0;
  2800. if (GetAttr(nPanelID, Attr_NetworkInterface, nConnectInterface))
  2801. {
  2802. if (Enm_NetworkInterface_Wifi == nConnectInterface)
  2803. {
  2804. char szLinkedAP[64] = { 0 };
  2805. if (GetAttr(nPanelID, Attr_WifiStatu_LinkedAP, szLinkedAP))
  2806. {
  2807. string strFDAP = (szLinkedAP);
  2808. Info("Detector {$} WifiStatu_LinkedAP {$}", nPanelID, strFDAP.c_str());
  2809. m_stDeviceIndex[m_nDetectorIndex].strWifiSSID = strFDAP.c_str();
  2810. if (GetWifiLinkQuality(nPanelID, nWifiValue))
  2811. {
  2812. Info("Detector {$} Wifi {$}", nPanelID, nWifiValue);
  2813. StatusFeedback(EVT_STATUS_WIFI, nWifiValue, "", nDetectorID);
  2814. }
  2815. }
  2816. else
  2817. {
  2818. Fatal("Get WifiStatu_LinkedAP Failed");
  2819. }
  2820. }
  2821. else if (Enm_NetworkInterface_Cable == nConnectInterface)
  2822. {
  2823. StatusFeedback(EVT_STATUS_WIFI, 100, "", nDetectorID);
  2824. }
  2825. else
  2826. {
  2827. Fatal("Connection Status is Unknown");
  2828. return false;
  2829. }
  2830. }
  2831. return true;
  2832. }
  2833. //读取探测器温度,SDK会将温度值写入Attr_RdResult_T1(静态)/Attr_RdResult_T2(动态) ,从该Attr读取温度值
  2834. bool IRayCtrl::ReadTempStatus(int nDetectorID)
  2835. {
  2836. Debug("Read Temperture");
  2837. int nPanelID = nDetectorID;
  2838. if (!WaitReady(nPanelID, 500))
  2839. {
  2840. return false;
  2841. }
  2842. ResetLock();
  2843. Debug("Call Cmd_ReadTemperature");
  2844. FPDRESULT nResult = IrayFnInvoke(nPanelID, Cmd_ReadTemperature, NULL, 0);
  2845. if (TestError(nDetectorID, nResult))
  2846. {
  2847. Fatal("Read Temperture Failed");
  2848. return false;
  2849. }
  2850. if (!WaitRespond(3000))
  2851. {
  2852. Warn("Read Temperture Timeout");
  2853. return false;
  2854. }
  2855. Debug("Read Temperture Success");
  2856. return true;
  2857. }
  2858. bool IRayCtrl::CheckTemperature(int nDetectorID)
  2859. {
  2860. int nPanelID = nDetectorID;
  2861. float fTemperature1 = 0.0f;
  2862. if (GetFPDTempT2(nPanelID, fTemperature1))
  2863. {
  2864. StatusFeedback(EVT_STATUS_TEMPERATURE, 0, "", nDetectorID, fTemperature1);
  2865. m_stDeviceIndex[m_nDetectorIndex].fCurrentTemperValue = fTemperature1;
  2866. }
  2867. return true;
  2868. }
  2869. //让SDK将PowerOn LifeTime值读取到Attr_FD_LifeTime
  2870. bool IRayCtrl::ReadLivingTime(int nDetectorID)
  2871. {
  2872. if (!WaitReady(nDetectorID, 500))
  2873. {
  2874. return false;
  2875. }
  2876. ResetLock();
  2877. Info("Call Cmd_QueryLivingTime");
  2878. FPDRESULT nResult = IrayFnInvoke(nDetectorID, Cmd_QueryLivingTime, NULL, 0);
  2879. if (TestError(nDetectorID, nResult))
  2880. {
  2881. Fatal("Query LivingTime Failed");
  2882. return false;
  2883. }
  2884. if (!WaitRespond(nCMD_TIME))
  2885. {
  2886. Info("Query LivingTime Timeout");
  2887. return false;
  2888. }
  2889. Info("Query LivingTime Success");
  2890. return true;
  2891. }
  2892. //获取PowerOn LifeTime值
  2893. bool IRayCtrl::CheckLivingTime(int nDetectorID)
  2894. {
  2895. int nLifeTime = 0;
  2896. int nPanelID = nDetectorID;
  2897. int nPowerOnCount = 0;
  2898. Info("FD index:{$} LifeTime:{$},PowerOnCount:{$}", nPanelID, nLifeTime, nPowerOnCount);
  2899. return true;
  2900. }
  2901. //WriteROM前,需要清空板内校正的校正选项,否则写入参数可能会失败
  2902. bool IRayCtrl::ClearCorrection(int nDetectorID)
  2903. {
  2904. Info("Clear Correction Option");
  2905. int nPanelIndex = nDetectorID + 1;
  2906. if (!WaitReady(nPanelIndex, 1000))
  2907. {
  2908. return false;
  2909. }
  2910. int nOption = 0;
  2911. IRayCmdParam param[1];
  2912. param[0].var.vt = IVT_INT;
  2913. param[0].var.val.nVal = nOption;
  2914. FPDRESULT result = IrayFnInvoke(nPanelIndex, Cmd_SetCorrectOption, param, 1); //Cmd_SetCorrectOption
  2915. if (TestError(nDetectorID, result))
  2916. {
  2917. Fatal("Call SetCorrectionOption Failed");
  2918. return false;
  2919. }
  2920. bool bResult = WaitRespond(8000);
  2921. if (m_stDeviceIndex[m_nDetectorIndex].bSetCorrection)
  2922. {
  2923. Info("Clear Correction Success");
  2924. }
  2925. else
  2926. {
  2927. Fatal("Clear Correction Failed");
  2928. return false;
  2929. }
  2930. return true;
  2931. }
  2932. //设置探测器校正
  2933. bool IRayCtrl::SetDetectorCorrection(int nDetectorID, int nCorrectionType)
  2934. {
  2935. Info("Set Detector({$}) correction: {$}", nDetectorID, nCorrectionType);
  2936. std::string strOffsetType = "";
  2937. if (nCorrectionType & Enm_CorrectOp_HW_PreOffset)
  2938. {
  2939. strOffsetType = "HW_PreOffset";
  2940. }
  2941. else if (nCorrectionType & Enm_CorrectOp_HW_PostOffset)
  2942. {
  2943. strOffsetType = "HW_PostOffset";
  2944. }
  2945. else if (nCorrectionType & Enm_CorrectOp_SW_PreOffset)
  2946. {
  2947. strOffsetType = "SW_PreOffset";
  2948. }
  2949. else if (nCorrectionType & Enm_CorrectOp_SW_PostOffset)
  2950. {
  2951. strOffsetType = "SW_PostOffset";
  2952. }
  2953. else
  2954. {
  2955. strOffsetType = "Undefined Offset";
  2956. }
  2957. std::string strGainDefectType = "";
  2958. if ((nCorrectionType & Enm_CorrectOp_HW_Gain) && (nCorrectionType & Enm_CorrectOp_HW_Defect))
  2959. {
  2960. strGainDefectType = "HW_Gain + HW_Defect";
  2961. }
  2962. else if ((nCorrectionType & Enm_CorrectOp_SW_Gain) && (nCorrectionType & Enm_CorrectOp_SW_Defect))
  2963. {
  2964. strGainDefectType = "SW_Gain + SW_Defect";
  2965. }
  2966. else
  2967. {
  2968. strGainDefectType = "Undefined Gain, Undefined Defect";
  2969. }
  2970. Info("Detector correction type: {$}", strOffsetType + " + " + strGainDefectType);
  2971. if (!WaitReady(nDetectorID, 1000))
  2972. {
  2973. return false;
  2974. }
  2975. int nOldOption = 0;
  2976. GetCorrectionOption(nDetectorID, nOldOption);
  2977. if (nCorrectionType == nOldOption)
  2978. {
  2979. Info("Same Correction Option, Omit");
  2980. return true;
  2981. }
  2982. IRayCmdParam param[1];
  2983. param[0].var.vt = IVT_INT;
  2984. param[0].var.val.nVal = nCorrectionType;
  2985. FPDRESULT result = IrayFnInvoke(nDetectorID, Cmd_SetCorrectOption, param, 1); //等Cmd_SetCorrectOption
  2986. if (TestError(nDetectorID, result))
  2987. {
  2988. Fatal("Call SetCorrectionOption Failed");
  2989. return false;
  2990. }
  2991. bool bResult = WaitRespond(10000); //加载校正策略
  2992. if (m_stDeviceIndex[m_nDetectorIndex].bSetCorrection)
  2993. {
  2994. Info("SetCorrectionOption Success");
  2995. }
  2996. else
  2997. {
  2998. Fatal("SetCorrectionOption Failed");
  2999. return false;
  3000. }
  3001. return true;
  3002. }
  3003. //设置动态探测器内外触发方式
  3004. bool IRayCtrl::SetDetectorFluSync(int nDetectorID, int nFluSync)
  3005. {
  3006. Info("Set detector({$}) flu sync: {$}", nDetectorID, FluroSyncMode[nFluSync]);
  3007. if (!WaitReady(nDetectorID, 1000))
  3008. {
  3009. Info("Detector status error");
  3010. return false;
  3011. }
  3012. int nTempMode = 0;
  3013. if (GetSyncMode(nDetectorID, nTempMode))
  3014. {
  3015. Info("Current fluro sync mode: {$}", FluroSyncMode[nTempMode]);
  3016. }
  3017. else
  3018. {
  3019. Error("Get fluro sync mode Failed");
  3020. }
  3021. if (nTempMode != nFluSync)
  3022. {
  3023. if (SetAttr(nDetectorID, Attr_UROM_FluroSync_W, nFluSync))
  3024. {
  3025. return WriteRom(nDetectorID);
  3026. }
  3027. else
  3028. {
  3029. Error("Set fluro sync mode Failed");
  3030. return false;
  3031. }
  3032. }
  3033. else
  3034. {
  3035. Warn("Same fluro sync mode, Omit");
  3036. return true;
  3037. }
  3038. return true;
  3039. }
  3040. //将设置的各项参数,实际写入探测器端,生效
  3041. bool IRayCtrl::WriteRom(int nDetectorID)
  3042. {
  3043. Debug("Call Cmd_WriteUserROM");
  3044. int nPanelIndex = nDetectorID;
  3045. FPDRESULT nResult = IrayFnInvoke(nPanelIndex, Cmd_WriteUserROM, NULL, 0);
  3046. if (TestError(nDetectorID, nResult))
  3047. {
  3048. return false;
  3049. }
  3050. if (WaitRespond(80 * 1000))
  3051. {
  3052. Debug("WriteUserROM success");
  3053. }
  3054. else
  3055. {
  3056. Fatal("Cmd_WriteUserROM Timeout");
  3057. return false;
  3058. }
  3059. return true;
  3060. }
  3061. //获取系统信息
  3062. bool IRayCtrl::GetROMInfo(int nDetectorID)
  3063. {
  3064. int nDetectorIndex = nDetectorID - 1;
  3065. char szSerialNo[64] = { 0 };
  3066. string strSNo = "";
  3067. if (GetSerialNo(nDetectorID, szSerialNo))
  3068. {
  3069. strSNo = szSerialNo;
  3070. Info("Detector {$} SN: {$}", nDetectorID, strSNo.c_str());
  3071. m_stDeviceIndex[nDetectorIndex].strPanelSerial = strSNo.c_str();
  3072. ConfFeedback(EVT_CONF_PANEL_SERIAL, nDetectorID, strSNo.c_str());
  3073. }
  3074. else
  3075. {
  3076. Error("Get SN Failed");
  3077. }
  3078. int nProductNo = 0;
  3079. if (GetProductNo(nDetectorID, nProductNo))
  3080. {
  3081. Info("Detector {$} ProductNo: {$}", nDetectorID, nProductNo);
  3082. }
  3083. else
  3084. {
  3085. Error("Get ProductNo Failed");
  3086. }
  3087. char szMainVersion[256] = { 0 };
  3088. if (GetMainVersion(nDetectorID, szMainVersion))
  3089. {
  3090. string strMainV = szMainVersion;
  3091. Info("Detector {$} MainVersion: {$}", nDetectorID, strMainV.c_str());
  3092. }
  3093. else
  3094. {
  3095. Error("Get MainVersion Failed");
  3096. }
  3097. char szReadVersion[256] = { 0 };
  3098. if (GetReadVersion(nDetectorID, szReadVersion))
  3099. {
  3100. string strRV = (szReadVersion);
  3101. Info("Detector {$} ReadVersion: {$}", nDetectorID, strRV.c_str());
  3102. }
  3103. else
  3104. {
  3105. Error("Get ReadVersion Failed");
  3106. }
  3107. char szMcuVersion[256] = { 0 };
  3108. if (GetMcuVersion(nDetectorID, szMcuVersion))
  3109. {
  3110. string strMcuV = (szMcuVersion);
  3111. Info("Detector {$} McuVersion: {$}", nDetectorID, strMcuV.c_str());
  3112. }
  3113. else
  3114. {
  3115. Error("Get McuVersion Failed");
  3116. }
  3117. char szArmVersion[256] = { 0 };
  3118. if (GetArmVersion(nDetectorID, szArmVersion))
  3119. {
  3120. string strArmV = szArmVersion;
  3121. m_stDeviceIndex[nDetectorIndex].strFirmware = strArmV.c_str();
  3122. Info("Detector {$} ArmVersion: {$}", nDetectorID, strArmV.c_str());
  3123. InfoFeedback(EVT_INFO_FIRMWARE, nDetectorID, 0, 0, strArmV.c_str());
  3124. }
  3125. else
  3126. {
  3127. Error("Get ArmVersion Failed");
  3128. }
  3129. char szKernalVersion[256] = { 0 };
  3130. if (GetKernelVersion(nDetectorID, szKernalVersion))
  3131. {
  3132. string strKernalV = (szKernalVersion);
  3133. Info("Detector {$} KernelVersion: {$}", nDetectorID, strKernalV.c_str());
  3134. }
  3135. else
  3136. {
  3137. Error("Get KernelVersion Failed");
  3138. }
  3139. return true;
  3140. }
  3141. bool IRayCtrl::GetHVGSignalStatus(int nDetectorID)
  3142. {
  3143. int nXrayEnable = 0;
  3144. int nXrayOn = 0;
  3145. int nXraySyncOut = 0;
  3146. int nXraySyncIn = 0;
  3147. GetAttr(nDetectorID, Attr_UROM_HvgXRayEnable, nXrayEnable);
  3148. GetAttr(nDetectorID, Attr_UROM_HvgXRayOn, nXrayOn);
  3149. GetAttr(nDetectorID, Attr_UROM_HvgXRaySyncOut, nXraySyncOut);
  3150. GetAttr(nDetectorID, Attr_UROM_HvgXRaySyncIn, nXraySyncIn);
  3151. Info("XRayEnable signal level: {$}", (nXrayEnable == Enm_SignalLevel_Low) ? "Low" : "High");
  3152. Info("XRayOn signal level: {$}", (nXrayOn == Enm_SignalLevel_Low) ? "Low" : "High");
  3153. Info("XRaySyncOut signal level: {$}", (nXraySyncOut == Enm_SignalLevel_Low) ? "Low" : "High");
  3154. Info("XRaySyncIn signal level: {$}", (nXraySyncIn == Enm_SignalLevel_Low) ? "Low" : "High");
  3155. return true;
  3156. }
  3157. int IRayCtrl::SetSyncMode(int nDetectorID, int nSetSyncMode)
  3158. {
  3159. int nPanelID = nDetectorID;
  3160. if (!WaitReady(nPanelID, 1000))
  3161. {
  3162. return E_IRAY_SYNCMODE_SETFAILED;
  3163. }
  3164. int nTriggerMode = 0;
  3165. if (GetSyncMode(nPanelID, nTriggerMode))
  3166. {
  3167. Info("Current SyncMode is {$}", TriggerModeName[nTriggerMode]);
  3168. }
  3169. else
  3170. {
  3171. Error("Get Sync Mode Failed");
  3172. }
  3173. if (nTriggerMode != nSetSyncMode)
  3174. {
  3175. Info("Set Sync Mode:{$}", TriggerModeName[nSetSyncMode]);
  3176. if (SetAttr(nPanelID, Attr_UROM_TriggerMode_W, nSetSyncMode))
  3177. {
  3178. Info("Set Sync Mode Success");
  3179. return E_IRAY_SYNCMODE_CHANGED;
  3180. }
  3181. else
  3182. {
  3183. Error("Set Sync Mode Failed");
  3184. return E_IRAY_SYNCMODE_SETFAILED;
  3185. }
  3186. }
  3187. else
  3188. {
  3189. Warn("Same Sync Mode,Omit");
  3190. return E_IRAY_SYNCMODE_NOCHANGE;
  3191. }
  3192. }
  3193. int IRayCtrl::SetInnerSubFlow(int nDetectorID, int nSetInnerSubFlow)
  3194. {
  3195. int nPanelID = nDetectorID;
  3196. int nInnerSubFlow = 0;
  3197. Info("Current InnerSubFlow is {$}", InnerSubFlow[nInnerSubFlow]);
  3198. if (nInnerSubFlow != nSetInnerSubFlow)
  3199. {
  3200. Info("Set InnerSubFlow to {$}", InnerSubFlow[nSetInnerSubFlow]);
  3201. if (!WaitReady(nDetectorID, 500))
  3202. {
  3203. Fatal("Omit InnerSubFlow Setting");
  3204. return E_IRAY_SYNCMODE_SETFAILED;
  3205. }
  3206. if (!SetInnerSubFlowAttr(nPanelID, nSetInnerSubFlow))
  3207. {
  3208. Fatal("Set InnerSubFlow Failed");
  3209. return E_IRAY_SYNCMODE_SETFAILED;
  3210. }
  3211. }
  3212. else
  3213. {
  3214. return E_IRAY_SYNCMODE_NOCHANGE;
  3215. }
  3216. return E_IRAY_SYNCMODE_CHANGED;
  3217. }
  3218. int IRayCtrl::SetCapModeFunc(int nDetectorID, int nSetCapMode)
  3219. {
  3220. int nPanelID = nDetectorID;
  3221. int nPrepCapMode = 0;
  3222. if (GetPrepCapMode(nPanelID, nPrepCapMode))
  3223. {
  3224. Info("Current PrepCapMode is {$}", PrepCapMode[nPrepCapMode]);
  3225. if (nPrepCapMode != nSetCapMode)
  3226. {
  3227. Info("Set PrepCapMode to {$}", PrepCapMode[nSetCapMode]);
  3228. if (!SetPrepCapMode(nPanelID, nSetCapMode))
  3229. {
  3230. Error("Set PrepCapMode Failed");
  3231. return E_IRAY_SYNCMODE_SETFAILED;
  3232. }
  3233. else
  3234. {
  3235. return E_IRAY_SYNCMODE_NOCHANGE;
  3236. }
  3237. }
  3238. }
  3239. else
  3240. {
  3241. Error("Get PrepCapMode Failed");
  3242. return E_IRAY_SYNCMODE_SETFAILED;
  3243. }
  3244. return E_IRAY_SYNCMODE_CHANGED;
  3245. }
  3246. //设置iRay探测器该参数
  3247. int IRayCtrl::SetFPDCalParam(int nDetectorID, int nSetSelfCapEnable, int nSetSelfClearEnable)
  3248. {
  3249. bool bParamChanged = false;
  3250. int nPanelID = nDetectorID;
  3251. int nSelfCapEnable = 0;
  3252. if (GetSelfCapEnable(nPanelID, nSelfCapEnable))
  3253. {
  3254. Info("Current SelfCapEnable is {$}", Enm_Switch[nSelfCapEnable]);
  3255. if (nSelfCapEnable != nSetSelfCapEnable)
  3256. {
  3257. Info("Set SelfCapEnable to {$}", Enm_Switch[nSetSelfCapEnable]);
  3258. bParamChanged = true;
  3259. if (!SetSelfCapEnable(nPanelID, nSetSelfCapEnable))
  3260. {
  3261. Error("Set SelfCapEnable Failed");
  3262. return E_IRAY_SYNCMODE_SETFAILED;
  3263. }
  3264. }
  3265. }
  3266. else
  3267. {
  3268. Error("Get SelfCapEnable Failed");
  3269. return E_IRAY_SYNCMODE_SETFAILED;
  3270. }
  3271. int nSelfClearEnable = 0;
  3272. if (GetSelfClearEnable(nPanelID, nSelfClearEnable))
  3273. {
  3274. Info("Current SelfClearEnable is {$}", Enm_Switch[nSelfClearEnable]);
  3275. if (nSelfClearEnable != nSetSelfClearEnable)
  3276. {
  3277. bParamChanged = true;
  3278. Info("Set SelfClearEnable to {$}", Enm_Switch[nSetSelfClearEnable]);
  3279. if (!SetSelfClearEnable(nPanelID, nSetSelfClearEnable))
  3280. {
  3281. Error("Set SelfClearEnable Failed");
  3282. return E_IRAY_SYNCMODE_SETFAILED;
  3283. }
  3284. }
  3285. }
  3286. else
  3287. {
  3288. Error("Get SelfClearEnable Failed");
  3289. return E_IRAY_SYNCMODE_SETFAILED;
  3290. }
  3291. if (bParamChanged)
  3292. {
  3293. return E_IRAY_SYNCMODE_CHANGED;//WriteRom(nDetectorID);
  3294. }
  3295. return E_IRAY_SYNCMODE_NOCHANGE;
  3296. }
  3297. //设置探测器采集的工作模式
  3298. bool IRayCtrl::SetDetectorWorkMode(int nDetectorID, int nMode)
  3299. {
  3300. Info("Set detector({$}) work mode: {$}", nDetectorID, nMode);
  3301. string strWorkMode = "";
  3302. return true;
  3303. }
  3304. //设置探测器窗口和Delay窗口
  3305. bool IRayCtrl::SetDetectorXWindow(int nDetectorID, int nDelayTime, int nXWindowTime, int nClearAcqTime)
  3306. {
  3307. Info("Set detector {$} XWindow", nDetectorID);
  3308. int nRomDelayTime = 0;
  3309. if (GetXWindowDelay(nDetectorID, nRomDelayTime))
  3310. {
  3311. Info("Current DelayTime: {$}", nRomDelayTime);
  3312. if (nDelayTime != nRomDelayTime)
  3313. {
  3314. Info("Set DelayTime: {$}", nDelayTime);
  3315. WaitReady(nDetectorID, 3000);
  3316. if (SetXWindowDelay(nDetectorID, nDelayTime))
  3317. {
  3318. Info("Set DelayTime Success");
  3319. }
  3320. else
  3321. {
  3322. Error("Write DelayTime Failed");
  3323. return false;
  3324. }
  3325. }
  3326. else
  3327. {
  3328. Info("Same DelayTime, Omit it");
  3329. }
  3330. }
  3331. int nRomExpWindow = 0;
  3332. if (GetExpWindowTime(nDetectorID, nRomExpWindow))
  3333. {
  3334. Info("Current XWindow: {$}", nRomExpWindow);
  3335. if (nXWindowTime != nRomExpWindow)
  3336. {
  3337. Info("Set XWindow: {$}", nXWindowTime);
  3338. WaitReady(nDetectorID, 3000);
  3339. if (SetExpWindowTime(nDetectorID, nXWindowTime))
  3340. {
  3341. Info("Set XWindow Success");
  3342. }
  3343. else
  3344. {
  3345. Error("Write ExpWindow Failed");
  3346. return false;
  3347. }
  3348. }
  3349. else
  3350. {
  3351. Info("Same XWindow, Omit it");
  3352. }
  3353. }
  3354. int nCfgClearAcqTime = 0;
  3355. if (GetDelayTime(nDetectorID, nCfgClearAcqTime))
  3356. {
  3357. Info("Current ClearAcqTime: {$}", nCfgClearAcqTime);
  3358. if (nClearAcqTime != nCfgClearAcqTime)
  3359. {
  3360. Info("Set ClearAcqTime: {$}", nClearAcqTime);
  3361. WaitReady(nDetectorID, 3000);
  3362. if (SetExpWindowTime(nDetectorID, nClearAcqTime))
  3363. {
  3364. Info("Set ClearAcqTime Success");
  3365. }
  3366. else
  3367. {
  3368. Error("Set ClearAcqTime Failed");
  3369. return false;
  3370. }
  3371. }
  3372. else
  3373. {
  3374. Info("Same ClearAcqTime, Omit it");
  3375. }
  3376. }
  3377. return true;
  3378. }
  3379. void IRayCtrl::GetFwName(string strFirmPath, string& strFirmwareName)
  3380. {
  3381. WIN32_FIND_DATA lpFindFileData;
  3382. string strPath = strFirmPath + "\\*.ifrm";//查找指定目录下的所有格式的文件。
  3383. Info("{$}", strPath.c_str());
  3384. //string strPath1 = CCommonFun::wc2mb(strPath.GetBuffer());
  3385. HANDLE hFile = FindFirstFile(strPath.c_str(), &lpFindFileData);
  3386. if (INVALID_HANDLE_VALUE == hFile)
  3387. {
  3388. Info("Cannot find Firmware file");
  3389. strFirmwareName = "";
  3390. return;
  3391. }
  3392. strFirmwareName = lpFindFileData.cFileName;
  3393. FindClose(hFile);
  3394. Info("{$}", strFirmwareName.c_str());
  3395. }
  3396. bool IRayCtrl::IsFWNeedUpdate(int nDetectorID)
  3397. {
  3398. bool bNeed = false;
  3399. int nPanelIndex = nDetectorID + 1;
  3400. char szArmVersion[256] = { 0 };
  3401. if (GetArmVersion(nPanelIndex, szArmVersion))
  3402. {
  3403. string strArmV = (szArmVersion);
  3404. m_stDeviceIndex[m_nDetectorIndex].strFirmware = strArmV.c_str();
  3405. Info("Panel {$} ArmVersion:{$}", nPanelIndex, strArmV.c_str());
  3406. InfoFeedback(EVT_INFO_FIRMWARE, nDetectorID, 0, 0, strArmV.c_str());
  3407. }
  3408. else
  3409. {
  3410. Error("Get ArmVersion Failed");
  3411. return false;
  3412. }
  3413. string strFirmwareHistoryFiles = g_strAppPath + "FirmwaresHistory_";
  3414. strFirmwareHistoryFiles += (m_stDeviceIndex[m_nDetectorIndex].strDeviceName);
  3415. strFirmwareHistoryFiles += ".xml";
  3416. Info("{$}", strFirmwareHistoryFiles.c_str());
  3417. int nResult = 0;
  3418. if (FW_MANDATORY_UPDATE == nResult)
  3419. {
  3420. m_stDeviceIndex[m_nDetectorIndex].nFirmwareStatus = FW_MANDATORY_UPDATE;
  3421. ConfFeedback(EVT_CONF_FIRWARE_UPDATE, nDetectorID, "", FW_MANDATORY_UPDATE);
  3422. Info("This Firmware must be updated");
  3423. //UPDATE
  3424. bNeed = true;
  3425. }
  3426. else if (FW_NEW == nResult)
  3427. {
  3428. m_stDeviceIndex[m_nDetectorIndex].nFirmwareStatus = FW_NEW;
  3429. ConfFeedback(EVT_CONF_FIRWARE_UPDATE, nDetectorID, "", FW_NEW);
  3430. Info("This Firmware is New");
  3431. }
  3432. else if (FW_NEED_UPDATE == nResult)
  3433. {
  3434. m_stDeviceIndex[m_nDetectorIndex].nFirmwareStatus = FW_MANDATORY_UPDATE;
  3435. ConfFeedback(EVT_CONF_FIRWARE_UPDATE, nDetectorID, "", FW_MANDATORY_UPDATE);
  3436. Info("This Firmware need to be updated");
  3437. //UPDATE
  3438. bNeed = true;
  3439. }
  3440. else if (FW_NOT_SUPPORT == nResult)
  3441. {
  3442. m_stDeviceIndex[m_nDetectorIndex].nFirmwareStatus = FW_NOT_SUPPORT;
  3443. ConfFeedback(EVT_CONF_FIRWARE_UPDATE, nDetectorID, "", FW_NOT_SUPPORT);
  3444. Info("This Firmware is not supported");
  3445. }
  3446. else if (FW_GET_ERROR == nResult)
  3447. {
  3448. m_stDeviceIndex[m_nDetectorIndex].nFirmwareStatus = FW_NEW;
  3449. ConfFeedback(EVT_CONF_FIRWARE_UPDATE, nDetectorID, "", FW_NEW);
  3450. Info("Cannot get Firmware List");
  3451. }
  3452. return bNeed;
  3453. }
  3454. //-----------------------------------------------------------------------------
  3455. // 更新FW的指令
  3456. //
  3457. //-----------------------------------------------------------------------------
  3458. RET_STATUS IRayCtrl::OnUpdateFirmware(nsDPC::FPDDeviceIRay* pDrvDPC)
  3459. {
  3460. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nDetectorIndex)
  3461. {
  3462. Warn("Not current DPC, return");
  3463. return RET_STATUS::RET_FAILED;
  3464. }
  3465. Info("Update FPD {$} Firmware", m_stDeviceIndex[m_nDetectorIndex].strPanelSerial.c_str());
  3466. m_nUpdateFPDID = m_nDetectorID;
  3467. HANDLE hUpdateThread;
  3468. DWORD unThreadID;
  3469. hUpdateThread = CreateThread(NULL, 0, onUpdateFWThread, this, 0, &unThreadID);
  3470. if (hUpdateThread == NULL)
  3471. {
  3472. Error("Start Update Firmware Thread Error");
  3473. }
  3474. return RET_STATUS::RET_SUCCEED;
  3475. }
  3476. /***
  3477. ** 说明:升级固件线程
  3478. ***/
  3479. DWORD __stdcall IRayCtrl::onUpdateFWThread(PVOID pvoid)
  3480. {
  3481. IRayCtrl* pOpr = (IRayCtrl*)pvoid;
  3482. Info("Firmware update thread");
  3483. return pOpr->UpdateFirmware(pOpr->m_nUpdateFPDID, true);
  3484. ;
  3485. }
  3486. bool IRayCtrl::UpdateFirmware(int nDetectorID, bool bUpdate)
  3487. {
  3488. Info("Update FPD Firmware");
  3489. int nPanelIndex = nDetectorID + 1;
  3490. if (!IsFWNeedUpdate(nDetectorID))
  3491. {
  3492. return true;
  3493. }
  3494. if (!bUpdate)
  3495. {
  3496. Info("Omit update Firmware ");
  3497. return true;
  3498. }
  3499. if (!m_stDeviceIndex[m_nDetectorIndex].bConnectStatus)
  3500. {
  3501. Error("connection lost,Omit firmware update");
  3502. StatusFeedback(EVT_STATUS_UPDATE_FIRMWARE, PANEL_EVENT_FWU_ERROR_OMIT, "", m_nUpdateFPDID);
  3503. return false;
  3504. }
  3505. if (m_nBatteryCapacity < 50)
  3506. {
  3507. Error("Low battery,Omit firmware update Detector battery value<50");
  3508. StatusFeedback(EVT_STATUS_UPDATE_FIRMWARE, PANEL_EVENT_FWU_ERROR_BATTERY, "", m_nUpdateFPDID);
  3509. return false;
  3510. }
  3511. if (!WaitReady(nPanelIndex, 600))
  3512. {
  3513. Error("wait Ready Failed");
  3514. StatusFeedback(EVT_STATUS_UPDATE_FIRMWARE, PANEL_EVENT_FWU_ERROR_OMIT, "", m_nUpdateFPDID);
  3515. return false;
  3516. }
  3517. StatusFeedback(EVT_STATUS_UPDATE_FIRMWARE, PANEL_EVENT_START, "", m_nUpdateFPDID);
  3518. string strFWPath = g_strAppPath + "SW_Update\\Firmware\\";
  3519. strFWPath += m_stDeviceIndex[m_nDetectorIndex].strDeviceName;
  3520. string strFWName = "";
  3521. GetFwName(strFWPath, strFWName);
  3522. if (strFWPath == "")
  3523. {
  3524. Error("Update firmware failed");
  3525. StatusFeedback(EVT_STATUS_UPDATE_FIRMWARE, PANEL_EVENT_END_ERROR, "", m_nUpdateFPDID);
  3526. return false;
  3527. }
  3528. strFWPath = strFWPath + "\\" + strFWName;
  3529. string strFilePath = (strFWPath);
  3530. Info("Begain update FW : {$}", strFilePath.c_str());
  3531. IRayCmdParam param[2];
  3532. param[0].var.vt = IVT_INT;
  3533. param[0].var.val.nVal = Enm_FW_DeviceType_AllInOne;
  3534. param[1].var.vt = IVT_STR;
  3535. Info("{$}", strFilePath.length());
  3536. strcpy_s(param[1].var.val.strVal, strFilePath.c_str());
  3537. m_bFirmwareUpdating = true;
  3538. m_stDeviceIndex[m_nDetectorIndex].bUpdateFirmware = false;
  3539. ResetLock();
  3540. FPDRESULT nReturn = IrayFnInvoke(nPanelIndex, Cmd_UpdateFirmware, param, 2);
  3541. if (TestError(nDetectorID, nReturn))
  3542. {
  3543. Error("Call Cmd_UpdateFirmware failed");
  3544. StatusFeedback(EVT_STATUS_UPDATE_FIRMWARE, PANEL_EVENT_END_ERROR, "", m_nUpdateFPDID);
  3545. m_bFirmwareUpdating = false;
  3546. return false;
  3547. }
  3548. bool bResult = WaitRespond(1200000);//20 minutes //等待Cmd_UpdateFirmware 之后再次Cmd_Connect
  3549. if (bResult)
  3550. {
  3551. if (m_stDeviceIndex[m_nDetectorIndex].bUpdateFirmware)
  3552. {
  3553. Info("Update firmware Success");
  3554. IsFWNeedUpdate(nDetectorID);
  3555. StatusFeedback(EVT_STATUS_UPDATE_FIRMWARE, PANEL_EVENT_SUCCESS, "", m_nUpdateFPDID);
  3556. m_bFirmwareUpdating = false;
  3557. return true;
  3558. }
  3559. Info("Update firmware failed");
  3560. StatusFeedback(EVT_STATUS_UPDATE_FIRMWARE, PANEL_EVENT_END_ERROR, "", m_nUpdateFPDID);
  3561. m_bFirmwareUpdating = false;
  3562. return false;
  3563. }
  3564. m_bFirmwareUpdating = false;
  3565. StatusFeedback(EVT_STATUS_UPDATE_FIRMWARE, PANEL_EVENT_END_ERROR, "", m_nUpdateFPDID);
  3566. Info("Update firmware Timeout");
  3567. return true;
  3568. }
  3569. //从探测器端下载校正文件到本地
  3570. bool IRayCtrl::UploadCalibFileFromFD(int nDetectorID, int nIndex, string strFileName, bool bGain)
  3571. {
  3572. int nPanelID = nDetectorID + 1;
  3573. IRayCmdParam param[3];
  3574. param[0].var.vt = IVT_INT;
  3575. param[0].var.val.nVal = Enm_File_Defect;
  3576. if (bGain)
  3577. {
  3578. param[0].var.val.nVal = Enm_File_Gain;
  3579. }
  3580. param[1].var.vt = IVT_INT;
  3581. param[1].var.val.nVal = nIndex;
  3582. param[2].var.vt = IVT_STR;
  3583. strcpy_s(param[2].var.val.strVal, strFileName.c_str());//
  3584. Info("{$}", strFileName.c_str());
  3585. m_stDeviceIndex[m_nDetectorIndex].bUploadCalibFile = false;
  3586. FPDRESULT nResult = IrayFnInvoke(nPanelID, Cmd_UploadCaliFile, param, 3); //返回值 Evt_TemplateFileUpload_Result
  3587. if (TestError(nDetectorID, nResult))
  3588. {
  3589. Error("Upload CaliFile failed");
  3590. return false;
  3591. }
  3592. ResetLock();
  3593. bool bResult = WaitRespond(16000); //defect 6s ,gain 8s。 bug 9494 由10s增加到16s
  3594. if (bResult)
  3595. {
  3596. if (m_stDeviceIndex[m_nDetectorIndex].bUploadCalibFile)
  3597. {
  3598. Info("Upload CaliFile2 success");
  3599. return true;
  3600. }
  3601. else
  3602. {
  3603. Error("Upload CaliFile2 failed");
  3604. return false;
  3605. }
  3606. }
  3607. else
  3608. {
  3609. Error("Cmd_UploadCaliFile Timeout");
  3610. return false;
  3611. }
  3612. }
  3613. //上传校正文件到探测器端,gain或defect文件
  3614. bool IRayCtrl::DownloadCalibrationFileToFD(bool bGainFile, bool bExpMode)
  3615. {
  3616. IRayCmdParam param[4];
  3617. param[0].pt = IPT_VARIANT;
  3618. param[0].var.vt = IVT_INT;
  3619. int nPanelIndex = m_nDetectorIndex + 1;
  3620. string strExpMode = "STE";
  3621. if (bExpMode)
  3622. {
  3623. strExpMode = "LTE";
  3624. }
  3625. string strPath = (m_stDeviceIndex[m_nDetectorIndex].strWorkDir);
  3626. string strGainFilePath = strPath + "\\Correct\\" + strExpMode + "\\gain_2304x2844.gn";
  3627. string strDefectFilePath = strPath + "\\Correct\\" + strExpMode + "\\defect_2304x2844.dft";
  3628. string strCalibrationFile = "";
  3629. if (bGainFile)
  3630. {
  3631. param[0].var.val.nVal = Enm_File_Gain;
  3632. strCalibrationFile = strGainFilePath;
  3633. }
  3634. else
  3635. {
  3636. param[0].var.val.nVal = Enm_File_Defect;
  3637. strCalibrationFile = strDefectFilePath;
  3638. }
  3639. param[1].pt = IPT_VARIANT;
  3640. param[1].var.vt = IVT_INT;
  3641. param[1].var.val.nVal = 1;
  3642. if (bExpMode)
  3643. {
  3644. param[1].var.val.nVal = 4; //本地合并merge_defect 到FD defect文件中LTE index4
  3645. }
  3646. //else if (m_nSTEExpTime == 800)
  3647. //{
  3648. // param[1].var.val.nVal = 7;
  3649. //}
  3650. param[2].pt = IPT_VARIANT;
  3651. param[2].var.vt = IVT_STR;
  3652. strcpy_s(param[2].var.val.strVal, strCalibrationFile.c_str());
  3653. Info("{$}", strCalibrationFile.c_str());
  3654. param[3].pt = IPT_VARIANT;
  3655. param[3].var.vt = IVT_STR;
  3656. strcpy_s(param[3].var.val.strVal, "");
  3657. ResetLock();
  3658. Info("Call Cmd_DownloadCaliFile");
  3659. int nResult = IrayFnInvoke(nPanelIndex, Cmd_DownloadCaliFile, param, 4);
  3660. if (!TestError(m_nDetectorIndex, nResult))
  3661. {
  3662. if (WaitRespond(16000))//bug 9494 由10s增加到16s
  3663. {
  3664. Info("Cmd_DownloadCaliFile Success");
  3665. }
  3666. else
  3667. {
  3668. Error("Cmd_DownloadCaliFile Failed");
  3669. return false;
  3670. }
  3671. }
  3672. return true;
  3673. }
  3674. //上传user edit defect文件,到探测器端
  3675. bool IRayCtrl::DownloadUserDefectFileToFD(bool bLTE)
  3676. {
  3677. int nPanelIndex = m_nDetectorIndex + 1;
  3678. string strPath = (m_stDeviceIndex[m_nDetectorIndex].strWorkDir);
  3679. string strEM = "STE";
  3680. if (bLTE)
  3681. {
  3682. strEM = "LTE";
  3683. }
  3684. string strDefectFilePath = strPath + "\\Correct\\" + strEM + "\\Defect_2304x2844.dft";//useredit_d
  3685. IRayCmdParam param[4];
  3686. param[0].pt = IPT_VARIANT;
  3687. param[0].var.vt = IVT_INT;
  3688. param[0].var.val.nVal = Enm_File_Defect;
  3689. param[1].pt = IPT_VARIANT;
  3690. param[1].var.vt = IVT_INT;
  3691. param[1].var.val.nVal = 1; //本地合并merge_defect 到FD defect文件中STE index1
  3692. if (bLTE)
  3693. {
  3694. param[1].var.val.nVal = 4; //本地合并merge_defect 到FD defect文件中LTE index4
  3695. }
  3696. //else if (m_bSolefish && m_nSTEExpTime == 800)
  3697. //{
  3698. // param[1].var.val.nVal = 7;
  3699. //}
  3700. param[2].pt = IPT_VARIANT;
  3701. param[2].var.vt = IVT_STR;
  3702. strcpy_s(param[2].var.val.strVal, strDefectFilePath.c_str());
  3703. Info("{$}", strDefectFilePath.c_str());
  3704. param[3].pt = IPT_VARIANT;
  3705. param[3].var.vt = IVT_STR;
  3706. strcpy_s(param[3].var.val.strVal, "");
  3707. ResetLock();
  3708. Info("Call Cmd_DownloadCaliFile");
  3709. int nResult = IrayFnInvoke(nPanelIndex, Cmd_DownloadCaliFile, param, 4);
  3710. if (!TestError(m_nDetectorIndex, nResult))
  3711. {
  3712. if (WaitRespond(16000))//bug 9494 由10s增加到16s
  3713. {
  3714. Info("Cmd_DownloadCaliFile Success");
  3715. }
  3716. else
  3717. {
  3718. Error("Cmd_DownloadCaliFile Failed");
  3719. return false;
  3720. }
  3721. }
  3722. return true;
  3723. }
  3724. //上传校正报告和Sensitivity文件到FD端,
  3725. //Cmd_WriteCustomFile 的参数为文件所在的Folder
  3726. bool IRayCtrl::WriteCumstomFile(int nDetectorID)
  3727. {
  3728. int nPanelIndex = nDetectorID + 1;
  3729. if (!m_stDeviceIndex[m_nDetectorIndex].bWireless)
  3730. {
  3731. Error("Omit WriteCustomFile");
  3732. return false;
  3733. }
  3734. if (!WaitReady(nPanelIndex, 5000))
  3735. {
  3736. Error("Detector isn't Ready");
  3737. return false;
  3738. }
  3739. string strFilePath = g_strAppPath + "references\\" + m_stDeviceIndex[m_nDetectorIndex].strPanelSerial;
  3740. string strFileName = (strFilePath);
  3741. IRayCmdParam param[1];
  3742. param[0].var.vt = IVT_STR;
  3743. strcpy_s(param[0].var.val.strVal, strFileName.c_str());
  3744. Info("{$}", strFileName.c_str());
  3745. m_stDeviceIndex[m_nDetectorIndex].bUploadCalibFile = false;
  3746. FPDRESULT nResult = IrayFnInvoke(nPanelIndex, Cmd_WriteCustomFile, param, 1); //返回值
  3747. if (TestError(nDetectorID, nResult))
  3748. {
  3749. Error("Write CustomFile failed");
  3750. return false;
  3751. }
  3752. bool bResult = WaitRespond(30000);
  3753. if (bResult)
  3754. {
  3755. if (m_stDeviceIndex[m_nDetectorIndex].bUploadCalibFile)
  3756. {
  3757. Info("Write CustomFile2 success");
  3758. return true;
  3759. }
  3760. else
  3761. {
  3762. Error("Write CustomFile2 failed");
  3763. return false;
  3764. }
  3765. }
  3766. else
  3767. {
  3768. Error("Cmd_ReadCustomFile Timeout");
  3769. return false;
  3770. }
  3771. }
  3772. //从校正文件中读取校正日期
  3773. bool IRayCtrl::GetCalibrationTime(int nDetectorID, bool bExpMode)
  3774. {
  3775. return true;
  3776. }
  3777. //从探测器上下载文件:Gain文件,defect文件
  3778. bool IRayCtrl::DownloadfromDetector(int nDetectorID)
  3779. {
  3780. string strLog;
  3781. string strWorkDir = m_stDeviceIndex[m_nDetectorIndex].strWorkDir;
  3782. string strLocalPath = strWorkDir;
  3783. string strCreatePath = strWorkDir + "\\Correct\\STE";
  3784. if (!PathFileExists(strCreatePath.c_str()))
  3785. {
  3786. bool bRtn = CreateDirectory(strCreatePath.c_str(), NULL);
  3787. if (bRtn)
  3788. {
  3789. strLog = "create " + strCreatePath + " ok";
  3790. Info("{$}", strLog.c_str());
  3791. }
  3792. else
  3793. {
  3794. strLog = "create " + strCreatePath + " failed";
  3795. Error("{$}", strLog.c_str());
  3796. return false;
  3797. }
  3798. }
  3799. else
  3800. {
  3801. strLog = strCreatePath + " already exist";
  3802. Info("{$}", strLog.c_str());
  3803. }
  3804. strLocalPath += "\\Correct\\STE\\factory_defect_2304x2844.dft";
  3805. UploadCalibFileFromFD(nDetectorID, 2, strLocalPath, false);
  3806. strLocalPath = strWorkDir;
  3807. strLocalPath += "\\Correct\\STE\\defect_2304x2844.dft";
  3808. UploadCalibFileFromFD(nDetectorID, 1, strLocalPath, false);
  3809. strLocalPath = strWorkDir;
  3810. strLocalPath += "\\Correct\\STE\\gain_2304x2844.gn";
  3811. UploadCalibFileFromFD(nDetectorID, 1, strLocalPath, true);
  3812. return true;
  3813. }
  3814. // 从SDK指定目录拷贝失败的校正文件到CalibrationFailedData中
  3815. bool IRayCtrl::SaveFailedCalibFiles(int nDetectorID, bool bExpMode)
  3816. {
  3817. Info("SaveCalibrationFailedData");
  3818. Info("SaveCalibrationFailedData over");
  3819. return true;
  3820. }
  3821. bool IRayCtrl::CleanCalibFiles(int nDetectorID, bool bExpMode)
  3822. {
  3823. return true;
  3824. }
  3825. //-----------------------------------------------------------------------------
  3826. // 通过 Cmd_QueryLastImageID 检查探测器中是否有未传输成功的图像
  3827. //该指令,SDK会返回 Evt_LastImageID ,从该Event 知道图像是否传输成功
  3828. //-----------------------------------------------------------------------------
  3829. bool IRayCtrl::CheckLastImageStatus(int nDetectorID)
  3830. {
  3831. ResetLock();
  3832. int nPanelID = nDetectorID;
  3833. if (!WaitReady(nPanelID, 20000))
  3834. {
  3835. Error("CheckLastImageStatus Failed");
  3836. return false;
  3837. }
  3838. Info("Call Cmd_QueryLastImageID");
  3839. FPDRESULT nResult = IrayFnInvoke(nPanelID, Cmd_QueryLastImageID, NULL, 0);
  3840. if (TestError(nDetectorID, nResult))
  3841. {
  3842. Error("Invoke Cmd_QueryLastImageID Failed");
  3843. return false;
  3844. }
  3845. else
  3846. {
  3847. Info("Query LastImageID success");
  3848. }
  3849. bool bResult = false;
  3850. bResult = WaitRespond(5000); //Evt_LastImageID
  3851. if (!bResult)
  3852. {
  3853. Error("Evt_LastImageID timeout. ");
  3854. return false;
  3855. }
  3856. if (m_stDeviceIndex[m_nDetectorIndex].bImagePending)
  3857. {
  3858. if (m_bWindowOn)
  3859. {
  3860. Info("need Recover image");
  3861. //ErrorFeedback(EVT_ERR_GET_IMAGE, "true");//有图像没拿到,但只有曝光后才能UI弹窗//注释掉,因为连接恢复后多发一个状态给UI,造成多一个弹窗
  3862. if (m_bImageRecoverBeCanceled)
  3863. {
  3864. Info("Image Recover Be Canceled");
  3865. }
  3866. else
  3867. {
  3868. SetEvent(m_hRecoverImage);
  3869. }
  3870. }
  3871. StatusFeedback(EVT_STATUS_IMAGEPENDING, 0, "true");//有图像没拿到
  3872. }
  3873. else
  3874. {
  3875. StatusFeedback(EVT_STATUS_IMAGEPENDING, 0, "false");//没有图像没拿到
  3876. ErrorFeedback(EVT_ERR_GET_IMAGE, "false");//没有图像没拿到
  3877. }
  3878. return true;
  3879. }
  3880. bool IRayCtrl::CancelImageRecover()
  3881. {
  3882. Info("Cancel Image Recover");
  3883. m_bImageRecoverBeCanceled = true;
  3884. return true;
  3885. }
  3886. //-----------------------------------------------------------------------------
  3887. // 函数描述 : 恢复图像:将曝光未获取成功的图像,重新获取出来
  3888. /*
  3889. 1. 通过 Cmd_QueryLastImageID 查询到最后一个图像的ID
  3890. 2. 通过 Cmd_GetImageByImageID ,把这个ID对应的图像获取出来
  3891. */
  3892. // 返回类型 :
  3893. // 接口参数 :
  3894. //
  3895. //-----------------------------------------------------------------------------
  3896. bool IRayCtrl::RecoverImage()
  3897. {
  3898. int nTryTimes = 0;
  3899. while (!m_stDeviceIndex[m_nLastExpFDIndex].bConnectStatus && (nTryTimes < 5))
  3900. {
  3901. Info("Waiting detector reconnect");
  3902. Sleep(1000);
  3903. nTryTimes++;
  3904. }
  3905. ResetLock();
  3906. Info("Call Cmd_QueryLastImageID");
  3907. m_stDeviceIndex[m_nLastExpFDIndex].bRecoveringImage = true;//imagerecover 弹框不自动消失。只要走了此流程,后面上图都发一下RCI(Result=0)此消息对UI没有副作用。
  3908. m_stDeviceIndex[m_nLastExpFDIndex].nLastImageID = -1;
  3909. int nPanelID = 1;// m_vecFDRealID[m_nLastExpFDIndex];
  3910. FPDRESULT nResult = IrayFnInvoke(nPanelID, Cmd_QueryLastImageID, NULL, 0);
  3911. if (TestError(m_nLastExpFDIndex, nResult))
  3912. {
  3913. Error("Invoke Cmd_QueryLastImageID Failed");
  3914. //SetEvent(m_hRecoverImage);
  3915. return false;
  3916. }
  3917. else
  3918. {
  3919. Info("Query LastImageID success");
  3920. }
  3921. bool bResult = false;
  3922. bResult = WaitRespond(5000); //Evt_LastImageID
  3923. if (!bResult)
  3924. {
  3925. Error("Evt_LastImageID timeout. ");
  3926. //SetEvent(m_hRecoverImage);
  3927. return false;
  3928. }
  3929. if (!m_stDeviceIndex[m_nLastExpFDIndex].bImagePending)
  3930. {
  3931. Warn("this image already be Transfered");
  3932. return false;
  3933. }
  3934. if (-1 == m_stDeviceIndex[m_nLastExpFDIndex].nLastImageID)
  3935. {
  3936. Error("Evt_LastImageID timeout2 ");
  3937. //SetEvent(m_hRecoverImage);
  3938. return false;
  3939. }
  3940. m_stDeviceIndex[m_nLastExpFDIndex].bConnectStatus = true;
  3941. IRayCmdParam param;
  3942. param.var.vt = IVT_INT;
  3943. param.var.val.nVal = m_stDeviceIndex[m_nLastExpFDIndex].nLastImageID;
  3944. nResult = IrayFnInvoke(nPanelID, Cmd_GetImageByImageID, &param, 1);
  3945. Info("Call Cmd_GetImageByImageID , ID = {$} , result = {$}", m_stDeviceIndex[m_nLastExpFDIndex].nLastImageID, nResult);
  3946. if (TestError(m_nLastExpFDIndex, nResult))
  3947. {
  3948. Error("Invoke Cmd_GetImageByImageID Failed");
  3949. //SetEvent(m_hRecoverImage);
  3950. return false;
  3951. }
  3952. else
  3953. {
  3954. m_stDeviceIndex[m_nLastExpFDIndex].bTaskEnd = false;
  3955. Info("Get Image ByImageID success");
  3956. }
  3957. return true;
  3958. }
  3959. /********************************************************************/
  3960. /*
  3961. 功能:FD Attach过程中,根据有线获取的SN和IP地址,改写iRay SDK的配置文件;
  3962. 以便在OnConnectFPD时 SDK读取新的配置文件,连接上探测器
  3963. /********************************************************************/
  3964. bool IRayCtrl::ModifyConfigIni(string strIniPath, string strSN, string strIP)
  3965. {
  3966. Info("ModifyConfigIni {$}", strIniPath.c_str());
  3967. if (CIniFileCreat(strIniPath.c_str())) //m_IRayInfo.IRayConf[0].strWorkDir +
  3968. {
  3969. string strItemData = "Cfg_SN=";
  3970. strItemData += strSN;
  3971. Info("{$}", strItemData.c_str());
  3972. bool bFindIP = CIniFileSetItemByKey("System", "Cfg_SN", strItemData.c_str());
  3973. strItemData = "Cfg_RemoteIP=";
  3974. strItemData += strIP;
  3975. Info("{$}", strItemData.c_str());
  3976. bFindIP = CIniFileSetItemByKey("Connection", "Cfg_RemoteIP", strItemData.c_str());
  3977. CIniFileClose();
  3978. }
  3979. else
  3980. {
  3981. Error("Read Pixrad.ini file failed");
  3982. CIniFileCloseWithoutWrite();
  3983. return false;
  3984. }
  3985. Info("ModifyConfigIni ok");
  3986. return true;
  3987. }
  3988. bool IRayCtrl::IsConnected(string strIP)
  3989. {
  3990. Info("Check ping {$}", strIP);
  3991. CMyPingip obPingIp;
  3992. StatusFeedback(EVT_STATUS_PING, 0, "true");
  3993. if (!obPingIp.PingFunction(strIP.c_str()))
  3994. {
  3995. Info("ping {$} Failed", strIP);
  3996. StatusFeedback(EVT_STATUS_PING, 0, "false");
  3997. return false;
  3998. }
  3999. return true;
  4000. }
  4001. //-----------------------------------------------------------------------------
  4002. // Reconnect探测器(上层有button)
  4003. //
  4004. //-----------------------------------------------------------------------------
  4005. bool IRayCtrl::ResetFPD(nsDPC::FPDDeviceIRay* pDrvDPC)
  4006. {
  4007. Info("Reset FPD");
  4008. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nDetectorIndex)
  4009. {
  4010. Warn("Not current DPC, return");
  4011. return false;
  4012. }
  4013. Info("Panel Count {$}\n", m_nPanelCount);
  4014. for (int i = 0; i < m_nPanelCount; i++)
  4015. {
  4016. if (!m_stDeviceIndex[i].bWifiEnable)
  4017. {
  4018. Error("Omit reconnection in fixed FD");
  4019. }
  4020. else
  4021. {
  4022. DisconnectFD(i + 1);
  4023. StartInitFPDThread();
  4024. }
  4025. }
  4026. return true;
  4027. }
  4028. void IRayCtrl::OnProcessPreImg()
  4029. {
  4030. if (m_bPreviewEnable)
  4031. {
  4032. DataFeedback(EVT_DATA_PREVIEW_IMAGE, m_pwPreviewImg);
  4033. }
  4034. }
  4035. void IRayCtrl::OnProcessImg()
  4036. {
  4037. if (m_bSaveRaw)
  4038. {
  4039. string strImageName = "iRay_" + to_string(m_nFrameID) + ".raw";
  4040. SaveRawImage(strImageName.c_str(), m_pwRawImageData, m_nRawImgWidth, m_nRawImgHeight);
  4041. }
  4042. //暗场图挡图处理
  4043. if (!CheckImageEXI(m_pwRawImageData, m_nRawImgWidth, m_nRawImgHeight, m_nImgBits, m_nExiThreshold, 0.05f))
  4044. {
  4045. Warning("Current frame EXI too low, omit");
  4046. return;
  4047. }
  4048. m_nFrameID++;
  4049. DataFeedback(EVT_DATA_RAW_IMAGE, m_pwRawImageData);
  4050. }
  4051. // pOutImg: 裁剪后图像; pInImg: 裁剪前图像; nInWidth: 裁剪前图像宽度
  4052. bool IRayCtrl::GetEffectiveImage(WORD* pOutImg, WORD* pInImg, int nInWidth)
  4053. {
  4054. if (pOutImg == NULL || pInImg == NULL || nInWidth < 0)
  4055. {
  4056. Error("Illegal parameter, can not get effective image");
  4057. return false;
  4058. }
  4059. try
  4060. {
  4061. for (int i = 0; i < m_nImageHeight; i++)
  4062. {
  4063. memcpy(pOutImg + i * m_nImageWidth,
  4064. pInImg + (i + m_nHeightOffset) * nInWidth + m_nWidthOffset,
  4065. m_nImageWidth * sizeof(WORD));
  4066. }
  4067. }
  4068. catch (...)
  4069. {
  4070. Error("Get effective image crashed. m_nImageWidth {$},m_nImageHeight {$},m_nWidthOffset {$},m_nHeightOffset {$},m_nBottomOffset {$}\n",
  4071. m_nImageWidth, m_nImageHeight, m_nWidthOffset, m_nHeightOffset, m_nBottomOffset);
  4072. return false;
  4073. }
  4074. return true;
  4075. }
  4076. bool IRayCtrl::StartHardwareStatusThread()
  4077. {
  4078. if (m_pHardwareStatusThread == NULL)
  4079. {
  4080. m_hEndHWStatusThreadEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  4081. DWORD m_HardwareStatusID;
  4082. m_pHardwareStatusThread = CreateThread(0, 0, HardwareStatusThread, this, 0, &m_HardwareStatusID);
  4083. if (m_pHardwareStatusThread == NULL)
  4084. {
  4085. Fatal("Start HardwareStatus Thread Failed");
  4086. return false;
  4087. }
  4088. }
  4089. return true;
  4090. }
  4091. DWORD IRayCtrl::HardwareStatusThread(LPVOID pParam)
  4092. {
  4093. IRayCtrl* pCurPanel = (IRayCtrl*)pParam;
  4094. if (pCurPanel == NULL)
  4095. {
  4096. return false;
  4097. }
  4098. Info("HardwareStatusThread start");
  4099. DWORD dwTimer = 5000;
  4100. DWORD dwCounter = 0;
  4101. while (true)
  4102. {
  4103. DWORD dwResult = WaitForSingleObject(pCurPanel->m_hEndHWStatusThreadEvent, dwTimer);
  4104. if (dwResult == WAIT_OBJECT_0)
  4105. {
  4106. break;
  4107. }
  4108. else
  4109. {
  4110. if (dwCounter % 60 == 0) //五分钟查一次
  4111. {
  4112. pCurPanel->GetHardwareStatus();
  4113. dwCounter = 0;
  4114. }
  4115. dwCounter++;
  4116. }
  4117. }
  4118. CloseHandle(pCurPanel->m_hEndHWStatusThreadEvent);
  4119. SetEvent(pCurPanel->m_hHWStatusThreadEndEvent);
  4120. Info("HardwareStatusThread stop");
  4121. return true;
  4122. }
  4123. bool IRayCtrl::GetHardwareStatus()
  4124. {
  4125. if (m_bFirmwareUpdating)
  4126. {
  4127. int nProgress = 0;
  4128. int nPanelID = m_nDetectorIndex + 1;
  4129. GetFWUpdateProgress(nPanelID, nProgress);
  4130. Info("Firmware update progress:{$}", nProgress);
  4131. return true;
  4132. }
  4133. if (m_bInExposure)
  4134. {
  4135. Info("In Exposuring,omit check hw status");
  4136. return true;
  4137. }
  4138. for (int i = 0; i < m_nPanelCount; i++)
  4139. {
  4140. int nDetectorID = i + 1;
  4141. if (!GetConnectionStatus(nDetectorID)) // 如果检测到平板探测器失去连接,那么要通知DROC
  4142. {
  4143. Info("FD {$} is communication error", nDetectorID);
  4144. m_stDeviceIndex[i].bConnectStatus = false;
  4145. ErrorFeedback(EVT_ERR_COMMUNICATE, "true", nDetectorID);
  4146. }
  4147. else if (m_stDeviceIndex[i].bConnectStatus && !m_bInCalibrating && !m_bInExposure && !m_bSetCorrectFile)
  4148. {
  4149. Info("Check FPD {$} Status", nDetectorID);
  4150. bool bResult = true;
  4151. if (m_stDeviceIndex[i].bConnectChanged)
  4152. {
  4153. m_stDeviceIndex[i].bConnectChanged = false;
  4154. //CheckLastImageStatus(nDetectorID);
  4155. }
  4156. if (ReadTempStatus(nDetectorID))
  4157. {
  4158. CheckTemperature(nDetectorID);
  4159. }
  4160. /*if (ReadBatteryStatus(nDetectorID))
  4161. {
  4162. CheckBattery(nDetectorID);
  4163. }
  4164. if (ReadWifiStatus(nDetectorID))
  4165. {
  4166. CheckWiFi(nDetectorID);
  4167. }
  4168. if (ReadLivingTime(nDetectorID))
  4169. {
  4170. CheckLivingTime(nDetectorID);
  4171. }*/
  4172. }
  4173. else if (m_stDeviceIndex[i].bConnectStatus)
  4174. {
  4175. if (m_stDeviceIndex[i].bConnectChanged)
  4176. {
  4177. m_stDeviceIndex[i].bConnectChanged = false;
  4178. }
  4179. }
  4180. }
  4181. return true;
  4182. }
  4183. bool IRayCtrl::GetConnectionStatus(int nDetectorID)
  4184. {
  4185. int nConnStates = Enm_ConnState_Unknown;
  4186. if (GetConnState(nDetectorID, nConnStates))
  4187. {
  4188. switch (nConnStates)
  4189. {
  4190. case Enm_ConnState_OK:
  4191. {
  4192. return true;
  4193. }
  4194. break;
  4195. default:
  4196. {
  4197. Error("Other Connection Status: {$}", nConnStates);
  4198. }
  4199. break;
  4200. }
  4201. }
  4202. else
  4203. {
  4204. Error("Get connection state fail");
  4205. }
  4206. return false;
  4207. }
  4208. //-----------------------------------------------------------------------------
  4209. // 手动编辑完坏点坏线,将校正文件上传到探测器端,并重新生成校正报告
  4210. //
  4211. //-----------------------------------------------------------------------------
  4212. bool IRayCtrl::UploadCalibrationFiles(nsDPC::FPDDeviceIRay* pDrvDPC, string strFileName)
  4213. {
  4214. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nDetectorIndex)
  4215. {
  4216. Warn("Not current DPC, return");
  4217. return false;
  4218. }
  4219. string strExpMode = "STE";
  4220. bool bLTE = false;
  4221. if (!DownloadUserDefectFileToFD(bLTE))
  4222. {
  4223. return false;
  4224. }
  4225. StatusFeedback(EVT_STATUS_SAVEDEFECT, PANEL_EVENT_START);
  4226. if (WriteCumstomFile(m_nDetectorIndex))
  4227. {
  4228. StatusFeedback(EVT_STATUS_SAVEDEFECT, PANEL_EVENT_END);
  4229. }
  4230. else
  4231. {
  4232. StatusFeedback(EVT_STATUS_SAVEDEFECT, PANEL_EVENT_END_ERROR);
  4233. }
  4234. Info("UploadCalibrationFiles over");
  4235. return true;
  4236. }
  4237. /***
  4238. * 保存RAW图像
  4239. ***/
  4240. bool IRayCtrl::SaveRawImage(const char* pImgName, const WORD* pRawImg, int nWidth, int nHeight)
  4241. {
  4242. Info("Begin to Save {$} Image, width: {$}, height: {$}", pImgName, nWidth, nHeight);
  4243. if (pRawImg == NULL || pImgName == NULL)
  4244. {
  4245. return false;
  4246. }
  4247. string strImagePath = g_strAppPath + "\\Image\\" + pImgName;
  4248. FILE* fp;
  4249. if ((fp = fopen(strImagePath.c_str(), "wb")) == NULL)
  4250. {
  4251. DWORD dw = GetLastError();
  4252. Error("fopen {$} failed, {$}", strImagePath.c_str(), dw);
  4253. return false;
  4254. }
  4255. fwrite(pRawImg, sizeof(WORD), nWidth * nHeight, fp);
  4256. fclose(fp);
  4257. Info("End to Save Raw Image");
  4258. return true;
  4259. }
  4260. //刷新Offset
  4261. bool IRayCtrl::StartOffset(bool isAll)
  4262. {
  4263. if (!m_stDeviceIndex[m_nDetectorIndex].bConnectStatus)
  4264. {
  4265. Warn("Detector communication loss");
  4266. return false;
  4267. }
  4268. m_bOffsetAll = isAll;
  4269. Info("Offset mode: {$}", isAll ? "All" : "NoAll");
  4270. SetEvent(m_hOffsetEvent); //OffsetCalibration()
  4271. return true;
  4272. }
  4273. //如果是isAll=true, 则刷新全部模式,如果isAll=false, 则刷新当前模式和点片模式
  4274. bool IRayCtrl::OffsetCalibration()
  4275. {
  4276. Info("OffsetCalibration start");
  4277. bool bOffsetFailed = false;
  4278. StatusFeedback(PANEL_OFFSET_CAL, OFFSET_RUNNING);
  4279. if (m_bOffsetAll)
  4280. {
  4281. /*int nTotalMode = ((*m_pPanelID2DPC)[m_nDetectorIndex])->GetTotalAcqModeNum();
  4282. StatusFeedback(PANEL_OFFSET_COUNT, nTotalMode);
  4283. for (int i = 0; i < nTotalMode; i++)
  4284. {
  4285. StatusFeedback(PANEL_OFFSET_PROGRESS, i);
  4286. if (!OffsetProcess(m_nDetectorID, i + 1))
  4287. {
  4288. Error("Offset mode {$} failed");
  4289. bOffsetFailed = true;
  4290. break;
  4291. }
  4292. }*/
  4293. int nTotalMode = m_mapLogicModeOperationMode.size();
  4294. StatusFeedback(PANEL_OFFSET_COUNT, nTotalMode);
  4295. int nOffsetProgress = 0;
  4296. for (map<int, int>::iterator it = m_mapLogicModeOperationMode.begin(); it != m_mapLogicModeOperationMode.end(); it++)
  4297. {
  4298. StatusFeedback(PANEL_OFFSET_PROGRESS, nOffsetProgress);
  4299. if (!OffsetProcess(m_nDetectorID, it->second))
  4300. {
  4301. Error("Offset mode {$} failed");
  4302. bOffsetFailed = true;
  4303. break;
  4304. }
  4305. nOffsetProgress++;
  4306. }
  4307. }
  4308. else
  4309. {
  4310. StatusFeedback(PANEL_OFFSET_COUNT, 2);
  4311. Info("Refresh RAD");
  4312. if (!OffsetProcess(m_nDetectorID, 1))
  4313. {
  4314. Error("Offset mode rad failed");
  4315. bOffsetFailed = true;
  4316. }
  4317. StatusFeedback(PANEL_OFFSET_PROGRESS, 1);
  4318. Info("Refresh Mode({$})", 2);
  4319. if (!OffsetProcess(m_nDetectorID, 2))
  4320. {
  4321. Error("Offset mode flu failed");
  4322. bOffsetFailed = true;
  4323. }
  4324. StatusFeedback(PANEL_OFFSET_PROGRESS, 2);
  4325. }
  4326. if (bOffsetFailed)
  4327. {
  4328. StatusFeedback(PANEL_OFFSET_CAL, OFFSET_ERROR);
  4329. }
  4330. else
  4331. {
  4332. StatusFeedback(PANEL_OFFSET_CAL, OFFSET_IDLE);
  4333. }
  4334. Info("Offset FINISH");
  4335. return true;
  4336. }
  4337. //刷新暗场
  4338. bool IRayCtrl::OffsetProcess(int nDetectorID, int nMode)
  4339. {
  4340. Info("OffsetProcess start");
  4341. //先激活对应模式
  4342. if (!SetAppMode(nDetectorID, nMode))
  4343. {
  4344. Info("Active offset mode {$} failed");
  4345. return false;
  4346. }
  4347. if (m_stDeviceIndex[m_nDetectorIndex].nOffsetMode == 0) //SW_Offset
  4348. {
  4349. Info("SW_Offset");
  4350. FPDRESULT nResult = IrayFnInvoke(nDetectorID, Cmd_OffsetGeneration, NULL, 0);
  4351. if (TestError(nDetectorID, nResult))
  4352. {
  4353. Error("Cmd_OffsetGeneration Cmd Failed");
  4354. return false;
  4355. }
  4356. if (!WaitRespond(300000))
  4357. {
  4358. Error("Generate SW Offset Template failed");
  4359. }
  4360. else
  4361. {
  4362. Info("Generate SW Offset Template success");
  4363. }
  4364. }
  4365. else if (m_stDeviceIndex[m_nDetectorIndex].nOffsetMode == 1) //HW_Offset
  4366. {
  4367. Info("HW_Offset");
  4368. FPDRESULT nResult = IrayFnInvoke(nDetectorID, Cmd_HwGeneratePreOffsetTemplate, NULL, 0);
  4369. if (TestError(nDetectorID, nResult))
  4370. {
  4371. Error("Cmd_HwGeneratePreOffsetTemplate Cmd Failed");
  4372. return false;
  4373. }
  4374. if(!WaitRespond(300000))
  4375. {
  4376. Error("Generate HW Offset Template failed");
  4377. }
  4378. else
  4379. {
  4380. Info("Generate HW Offset Template success");
  4381. }
  4382. }
  4383. else
  4384. {
  4385. Warn("Undefined offset mode");
  4386. return false;
  4387. }
  4388. return true;
  4389. }
  4390. bool IRayCtrl::AbortOffset()
  4391. {
  4392. Info("Abort refresh offset");
  4393. m_pfAbort(m_nDetectorID);
  4394. Info("Abort detector");
  4395. StatusFeedback(PANEL_OFFSET_CAL, OFFSET_IDLE);
  4396. return true;
  4397. }
  4398. //检查图像EXI, 返回true: 有射线,返回false: 无射线
  4399. bool IRayCtrl::CheckImageEXI(WORD* pImage, int nWidth, int nHeight, int nImageBit, int nThreshold, float fArea)
  4400. {
  4401. if (nThreshold == 0)
  4402. {
  4403. Info("Omit check EXI");
  4404. return true;
  4405. }
  4406. Info("Check EXI");
  4407. if (!pImage)
  4408. {
  4409. Error("Buffer is null");
  4410. return false; //图像读入失败。
  4411. }
  4412. int N = 65536;
  4413. int* Histogram = NULL;
  4414. Histogram = new int[N];
  4415. if (Histogram == NULL)
  4416. {
  4417. Error("Alloc buffer failed");
  4418. return false; //内存分配失败。
  4419. }
  4420. memset(Histogram, 0, sizeof(int) * N);
  4421. unsigned long int nCount = 0;
  4422. unsigned long int temp = 0;
  4423. int nIdxI = 0;
  4424. int nIdxJ = 0;
  4425. for (nIdxJ = 30; nIdxJ < nHeight - 30; nIdxJ = nIdxJ + 4)
  4426. {
  4427. for (nIdxI = 30; nIdxI < nWidth - 30; nIdxI = nIdxI + 4)
  4428. {
  4429. temp = int(pImage[nIdxJ * nWidth + nIdxI]);
  4430. Histogram[temp]++;
  4431. nCount++;
  4432. }
  4433. }
  4434. float fCoe = 0.01f;
  4435. int nCoeCount = int(fCoe * nCount);
  4436. int nAreaCount = int((1 - fCoe) * nCount * fArea);
  4437. long int nIdx = 0;
  4438. long int nSum = 0;
  4439. for (nIdx = N - 1; nIdx >= 0; nIdx--)
  4440. {
  4441. nSum += Histogram[nIdx];
  4442. if (nSum >= nCoeCount)
  4443. break;
  4444. }
  4445. unsigned long int fMean = 0;
  4446. unsigned long int nflag = 0;
  4447. for (int i = nIdx; i >= 0; i--)
  4448. {
  4449. if (Histogram[nIdx] == 0)
  4450. {
  4451. continue;
  4452. }
  4453. fMean += nIdx * Histogram[nIdx];
  4454. nflag += Histogram[nIdx];
  4455. if (nflag >= nAreaCount)
  4456. {
  4457. break;
  4458. }
  4459. }
  4460. if (Histogram)
  4461. {
  4462. delete[] Histogram;
  4463. Histogram = NULL;
  4464. }
  4465. if (nflag == 0)
  4466. {
  4467. Warning("Not have Xray image");
  4468. return false; //无x射线
  4469. }
  4470. fMean = unsigned long int(fMean / nflag);
  4471. Info("Mean count({$})", fMean);
  4472. if (fMean >= nThreshold)
  4473. {
  4474. //LogInfo("Xray image");
  4475. return true;
  4476. }
  4477. else
  4478. {
  4479. //LogInfo("Not have Xray image");
  4480. return false;
  4481. }
  4482. }
  4483. bool IRayCtrl::SetOffsetModeScope()
  4484. {
  4485. Info("SetModeScope");
  4486. int nModeNum = m_pCurrentDPC->GetTotalAcqModeNum();
  4487. Info("Mode number: {$}", nModeNum);
  4488. int nLogicMode = 0;
  4489. int nOperationMode = 0;
  4490. for (int i = 0; i < nModeNum; i++)
  4491. {
  4492. if ((int)m_ModeConfig["ModeTable"][i]["OffsetEnable"] == 1)
  4493. {
  4494. nLogicMode = (int)m_ModeConfig["ModeTable"][i]["LogicMode"];
  4495. nOperationMode = (int)m_ModeConfig["ModeTable"][i]["OperationMode"];
  4496. m_mapLogicModeOperationMode.insert(pair<int, int>(nLogicMode, nOperationMode));
  4497. }
  4498. }
  4499. return true;
  4500. }
  4501. bool IRayCtrl::SetFluPPS(float fFluPPS)
  4502. {
  4503. if (fFluPPS <= 0.0f)
  4504. {
  4505. Warn("Current frame rate is Illegal");
  4506. return false;
  4507. }
  4508. m_fFrameRate = fFluPPS;
  4509. return true;
  4510. }
  4511. bool IRayCtrl::GetFluPPS(float& fFluPPS)
  4512. {
  4513. fFluPPS = m_fFrameRate;
  4514. return true;
  4515. }