IRayCtrl.cpp 138 KB

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