DIOS.Dev.FPD.iRay.cpp 114 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911
  1. // CCOS.Dev.FPD.iRay.cpp : 定义 DLL 的导出函数。
  2. //
  3. #include "stdafx.h"
  4. #include <stdio.h>
  5. #include <OleAuto.h>
  6. #include <sys/stat.h>
  7. #include "FileVersion.hpp"
  8. #include "common_api.h"
  9. #include "GridSuppression.h"
  10. #include "CalEXI.h"
  11. #include "TemperatureCheck.h"
  12. #include "DICOMImageHeadKey.h"
  13. #include "CCOS.Dev.FPD.iRay.h"
  14. #include "IRayCtrl.h"
  15. #pragma comment(lib, "Version.lib")
  16. namespace nsFPD = CCOS::Dev::Detail::Detector;
  17. Log4CPP::Logger* //mLog::gLogger = nullptr;
  18. static nsFPD::IRayDriver gIODriver;
  19. //-----------------------------------------------------------------------------
  20. // GetIODriver & CreateIODriver
  21. //-----------------------------------------------------------------------------
  22. extern "C" CCOS::Dev::IODriver * __cdecl GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
  23. {
  24. return &gIODriver;
  25. }
  26. extern "C" CCOS::Dev::IODriver * __cdecl CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
  27. {
  28. return new nsFPD::IRayDriver();
  29. }
  30. //-----------------------------------------------------------------------------
  31. // IRayDriver
  32. //-----------------------------------------------------------------------------
  33. nsFPD::IRayDriver::IRayDriver()
  34. {
  35. dev = NULL;
  36. m_bConnect = false;
  37. m_pAttribute.reset(new ResDataObject());
  38. m_pDescription.reset(new ResDataObject());
  39. }
  40. nsFPD::IRayDriver::~IRayDriver()
  41. {
  42. }
  43. extern const char* g_szMouldPath;
  44. void nsFPD::IRayDriver::Prepare()
  45. {
  46. //string strWorkPath = GetProcessDirectory();
  47. //string strLogPath = strWorkPath + DetectorLogPath; //GetProcessDirectory() + R"(\OEMDrivers\Detector\Conf\Log4CPP.Config.FPD.xml)";
  48. //Log4CPP::GlobalContext::Map::Set(ZSKK::Utility::Hash("LogFileName"), "FPD.iRayDR");
  49. //auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
  50. ////mLog::gLogger = Log4CPP::LogManager::GetLogger("FPD.iRayDR");
  51. string strLogPath = GetProcessDirectory() + R"(\Conf\Log4CPP.Config.xml)";
  52. auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
  53. //mLog::gLogger = Log4CPP::LogManager::GetLogger("Module");
  54. #ifdef _WIN64
  55. //mLog::Force("------------------------ Version: {$} (64-bit) ------------------------", FileVersion(g_szMouldPath).GetVersionString());
  56. #else
  57. //mLog::Force("------------------------ Version: {$} (32-bit)------------------------", FileVersion(g_szMouldPath).GetVersionString());
  58. #endif
  59. dev = new FPDDeviceIRay(EventCenter, m_ConfigFileName);
  60. //mLog::Info("new FPDDeviceIRay over");
  61. }
  62. bool nsFPD::IRayDriver::Connect()
  63. {
  64. //mLog::Info("IRayDriver Connect");
  65. m_bConnect = dev->m_stDeviceConfig.bConnectStatus;
  66. return m_bConnect;
  67. }
  68. void nsFPD::IRayDriver::Disconnect()
  69. {
  70. //mLog::Info("IRayDriver Disconnect");
  71. m_bConnect = false;
  72. }
  73. bool nsFPD::IRayDriver::isConnected() const
  74. {
  75. return m_bConnect;
  76. }
  77. auto nsFPD::IRayDriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
  78. {
  79. //mLog::Info("CreateDevice({$})", index);
  80. auto Driver = std::unique_ptr <IODevice>(new IODevice(dev));
  81. dev->CreateDevice();
  82. dev->Register();
  83. return Driver;
  84. }
  85. std::string nsFPD::IRayDriver::DriverProbe()
  86. {
  87. //mLog::Info("nsFPD::IRayDriver::Driver_Probe");
  88. ResDataObject r_config, HardwareInfo;
  89. if (r_config.loadFile(m_ConfigFileName.c_str()))
  90. {
  91. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  92. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  93. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  94. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  95. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  96. }
  97. else
  98. {
  99. HardwareInfo.add("MajorID", "Generator");
  100. HardwareInfo.add("MinorID", "Dr");
  101. HardwareInfo.add("VendorID", "iRay");
  102. HardwareInfo.add("ProductID", "Mars");
  103. HardwareInfo.add("SerialID", "Driver");
  104. }
  105. string ret = HardwareInfo.encode();
  106. return ret;
  107. }
  108. bool nsFPD::IRayDriver::GetDeviceConfig(std::string& Cfg)
  109. {
  110. Cfg = m_DeviceConfig.encode();
  111. //mLog::Info("GetDeviceConfig over");
  112. return true;
  113. }
  114. bool nsFPD::IRayDriver::SetDeviceConfig(std::string Cfg)
  115. {
  116. //mLog::Info("--Func-- SetDeviceConfig {$} ", Cfg.c_str());
  117. ResDataObject DeviceConfig;
  118. DeviceConfig.decode(Cfg.c_str());
  119. ResDataObject DescriptionTempEx;
  120. DescriptionTempEx = DeviceConfig["DeviceConfig"]["Attribute"];
  121. //mLog::Info("Attribute:{$}", DescriptionTempEx.encode());
  122. bool bSaveFile = false; //true:重新保存配置文件
  123. string strAccess = "";
  124. for (int i = 0; i < DescriptionTempEx.size(); i++)
  125. {
  126. string strKey = DescriptionTempEx.GetKey(i);
  127. //mLog::Info("{$}", strKey.c_str());
  128. try
  129. {
  130. if (m_pAttribute->GetFirstOf(strKey.c_str()) >= 0)
  131. {
  132. strAccess = (string)(*m_pDescription)[strKey.c_str()]["Access"];
  133. if ("rw" == strAccess)
  134. {
  135. //修改对应配置,在其他单元的配置项要同时调用其修改函数修改真实值
  136. //1. 修改内存中的值,用于给上层发消息
  137. (*m_pAttribute)[strKey.c_str()] = DescriptionTempEx[i];
  138. //2. 拿到Innerkey
  139. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  140. //mLog::Info("ConfigInfo Count: {$}", nConfigInfoCount);
  141. string strTemp = ""; //存储AttributeKey
  142. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  143. {
  144. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  145. if (strTemp == strKey)
  146. {
  147. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  148. break;
  149. }
  150. }
  151. //3. 修改配置文件中的值
  152. if (SetDeviceConfigValue(m_Configurations, strTemp.c_str(), 1, DescriptionTempEx[i]))
  153. {
  154. bSaveFile = true;
  155. }
  156. }
  157. else
  158. {
  159. //mLog::Info("{$} is not a RW configuration item", strKey.c_str());
  160. }
  161. }
  162. else
  163. {
  164. //mLog::Warn("without this attribute {$}", strKey.c_str());
  165. }
  166. }
  167. catch (...)
  168. {
  169. //mLog::Error("SetDriverConfig crashed");
  170. return false;
  171. }
  172. }
  173. if (bSaveFile)
  174. {
  175. //3. 重新保存配置文件
  176. SaveConfigFile(true);
  177. }
  178. //mLog::Info("SetDriverConfig over");
  179. return true;
  180. }
  181. bool nsFPD::IRayDriver::SaveConfigFile(bool bSendNotify)
  182. {
  183. m_ConfigAll["CONFIGURATION"] = m_Configurations;
  184. m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
  185. //mLog::Info("SaveConfigFile over");
  186. return true;
  187. }
  188. bool nsFPD::IRayDriver::GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue)
  189. {
  190. strValue = "";
  191. string strTemp = pInnerKey;
  192. ////mLog::Trace("Inner key: {$}", strTemp);
  193. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  194. {
  195. if (WiredIP == strTemp || WirelessIP == strTemp || LocalIP == strTemp)
  196. {
  197. strValue = (string)config["connections"][pInnerKey];
  198. }
  199. else if (DetectorVender == strTemp || DetectorModel == strTemp ||
  200. DetectorDescription == strTemp || DetectorSerialNumber == strTemp)
  201. {
  202. strValue = (string)config[pInnerKey];
  203. }
  204. else if (SyncType == strTemp || FPDWorkStation == strTemp ||
  205. ImageWidth == strTemp || ImageHeight == strTemp)
  206. {
  207. strValue = (string)config["ModeTable"]["RAD"][pInnerKey];
  208. }
  209. else if (TempMaxLimit == strTemp || ReConnect == strTemp ||
  210. TempUpperLimit == strTemp || TempLowerLimit == strTemp || "TempMinLimit" == strTemp ||
  211. BatLowerLimit == strTemp || BatMiniLimit == strTemp ||
  212. BatLowerLimitInCali == strTemp || WifiLowerLimit == strTemp ||
  213. WifiMiniLimit == strTemp || HighPowerTimeout == strTemp ||
  214. ShowTemperature == strTemp || ShowWifi == strTemp ||
  215. ShowBattery == strTemp || ShowBluetooth == strTemp ||
  216. FPDExamMode == strTemp || FPDAcqMode == strTemp || FPDModeMatch == strTemp || "Attached" == strTemp)
  217. {
  218. strValue = (string)config[pInnerKey];
  219. }
  220. else
  221. {
  222. strValue = "";
  223. //mLog::Warn("Error Configuration item: {$}", pInnerKey);
  224. }
  225. }
  226. return true;
  227. }
  228. /***
  229. ** 说明: 设置配置文件内容
  230. ***/
  231. bool nsFPD::IRayDriver::SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue)
  232. {
  233. string strTemp = pInnerKey;
  234. //mLog::Trace("Begin to change {$} item value to {$}", pInnerKey, szValue);
  235. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  236. {
  237. if (WiredIP == strTemp || WirelessIP == strTemp || LocalIP == strTemp)
  238. {
  239. config["connections"][pInnerKey] = szValue;
  240. }
  241. else if (DetectorVender == strTemp || DetectorModel == strTemp ||
  242. DetectorDescription == strTemp || DetectorSerialNumber == strTemp)
  243. {
  244. config[pInnerKey] = szValue;
  245. }
  246. else if (SyncType == strTemp || FPDWorkStation == strTemp ||
  247. ImageWidth == strTemp || ImageHeight == strTemp)
  248. {
  249. config["ModeTable"]["RAD"][pInnerKey] = szValue;
  250. }
  251. else if (TempMaxLimit == strTemp || ReConnect == strTemp ||
  252. TempUpperLimit == strTemp || TempLowerLimit == strTemp ||
  253. BatLowerLimit == strTemp || BatMiniLimit == strTemp ||
  254. BatLowerLimitInCali == strTemp || WifiLowerLimit == strTemp ||
  255. WifiMiniLimit == strTemp || HighPowerTimeout == strTemp ||
  256. ShowTemperature == strTemp || ShowWifi == strTemp ||
  257. ShowBattery == strTemp || ShowBluetooth == strTemp ||
  258. FPDExamMode == strTemp || FPDAcqMode == strTemp || FPDModeMatch == strTemp)
  259. {
  260. config[pInnerKey] = szValue;
  261. }
  262. else
  263. {
  264. //mLog::Warn("Error Configuration item: {$}", pInnerKey);
  265. return false;
  266. }
  267. }
  268. return true;
  269. }
  270. std::string nsFPD::IRayDriver::GetResource()
  271. {
  272. ResDataObject r_config, temp;
  273. if (!temp.loadFile(m_ConfigFileName.c_str()))
  274. {
  275. return "";
  276. }
  277. m_ConfigAll = temp;
  278. r_config = temp["CONFIGURATION"];
  279. m_Configurations = r_config;
  280. ResDataObject DescriptionTemp;
  281. ResDataObject ListTemp;
  282. string strTemp = ""; //用于读取字符串配置信息
  283. string strIndex = ""; //用于读取配置信息中的List项
  284. int nTemp = -1; //用于读取整型配置信息
  285. char sstream[10] = { 0 }; //用于转换值
  286. string strValue = ""; //用于存储配置的值
  287. string strType = ""; //用于存储配置的类型 int/float/string...
  288. /***
  289. * 1. 通过循环,将所有配置项写到pDeviceConfig
  290. * 2. 记录配置项的内部key以及配置类型,类型对应了不同配置文件路径,用于读写真实值
  291. ***/
  292. try
  293. {
  294. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  295. ////mLog::Trace(g_pFPDCtrlLog, "ConfigInfo Count: {$}", nConfigInfoCount);
  296. m_pAttribute->clear();
  297. m_pDescription->clear();
  298. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  299. {
  300. DescriptionTemp.clear();
  301. ListTemp.clear();
  302. //AttributeType
  303. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Type"];
  304. DescriptionTemp.add(AttributeType, strTemp.c_str());
  305. ////mLog::Trace(g_pFPDCtrlLog, "--> {$}: {$}", AttributeType, strTemp.c_str());
  306. strType = strTemp; //记录配置项的类型
  307. //AttributeKey
  308. //1. 根据AttributeType,内部key和配置路径,拿到当前的真实值
  309. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  310. nTemp = (int)m_Configurations["ConfigToolInfo"][nInfoIndex]["PathID"];
  311. GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue);
  312. //2. 赋值
  313. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  314. if ("int" == strType)
  315. {
  316. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  317. ////mLog::Trace(g_pFPDCtrlLog, "Key {$}: {$}", strTemp.c_str(), atoi(strValue.c_str()));
  318. }
  319. else if ("float" == strType)
  320. {
  321. (*m_pAttribute).add(strTemp.c_str(), atof(strValue.c_str()));
  322. ////mLog::Trace(g_pFPDCtrlLog, "Key {$}: {$}", strTemp.c_str(), atof(strValue.c_str()));
  323. }
  324. else //其它先按string类型处理
  325. {
  326. (*m_pAttribute).add(strTemp.c_str(), strValue.c_str());
  327. ////mLog::Trace(g_pFPDCtrlLog, "Key {$}: {$}", strTemp.c_str(), strValue.c_str());
  328. }
  329. //AttributeAccess
  330. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Access"];
  331. DescriptionTemp.add(AttributeAccess, strTemp.c_str());
  332. ////mLog::Trace(g_pFPDCtrlLog, "{$}: {$}", AttributeAccess, strTemp.c_str());
  333. //AttributeRangeMin
  334. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMin"];
  335. if (strTemp != "") //不需要的配置项为空
  336. {
  337. DescriptionTemp.add(AttributeRangeMin, strTemp.c_str());
  338. ////mLog::Trace(g_pFPDCtrlLog, "{$}: {$}", AttributeRangeMin, strTemp.c_str());
  339. }
  340. //AttributeRangeMax
  341. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMax"];
  342. if (strTemp != "") //不需要的配置项为空
  343. {
  344. DescriptionTemp.add(AttributeRangeMax, strTemp.c_str());
  345. ////mLog::Trace(g_pFPDCtrlLog, "{$}: {$}", AttributeRangeMax, strTemp.c_str());
  346. }
  347. //AttributeList
  348. nTemp = m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListNum"];
  349. if (nTemp > 0) //ListNum不大于0时说明不需要list配置
  350. {
  351. for (int nListIndex = 0; nListIndex < nTemp; nListIndex++)
  352. {
  353. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListInfo"][nListIndex];
  354. sprintf_s(sstream, "%d", nListIndex);
  355. ListTemp.add(sstream, strTemp.c_str());
  356. ////mLog::Trace(g_pFPDCtrlLog, "list {$}: {$}", nListIndex, strTemp.c_str());
  357. }
  358. DescriptionTemp.add(AttributeList, ListTemp);
  359. }
  360. //AttributeRequired
  361. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Required"];
  362. DescriptionTemp.add(AttributeRequired, strTemp.c_str());
  363. ////mLog::Trace(g_pFPDCtrlLog, "{$}: {$}", AttributeRequired, strTemp.c_str());
  364. //AttributeDefaultValue
  365. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["DefaultValue"];
  366. if (strTemp != "") //不需要的配置项为空
  367. {
  368. DescriptionTemp.add(AttributeDefaultValue, strTemp.c_str());
  369. ////mLog::Trace(g_pFPDCtrlLog, "{$}: {$}", AttributeDefaultValue, strTemp.c_str());
  370. }
  371. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  372. (*m_pDescription).add(strTemp.c_str(), DescriptionTemp);
  373. }
  374. }
  375. catch (exception e)
  376. {
  377. //mLog::Error("Get config error: {$}", e.what());
  378. return "";
  379. }
  380. ResDataObject resDeviceResource;
  381. resDeviceResource.add(ConfKey::CcosDetectorAttribute, (*m_pAttribute));
  382. resDeviceResource.add(ConfKey::CcosDetectorDescription, (*m_pDescription));
  383. ResDataObject DescriptionTempEx;
  384. DescriptionTempEx.add(ConfKey::CcosDetectorConfig, resDeviceResource);
  385. m_DeviceConfig = DescriptionTempEx;
  386. string res = DescriptionTempEx.encode();
  387. return res;
  388. }
  389. std::string nsFPD::IRayDriver::DeviceProbe()
  390. {
  391. ResDataObject r_config, HardwareInfo;
  392. if (r_config.loadFile(m_ConfigFileName.c_str()))
  393. {
  394. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  395. HardwareInfo.add("MinorID", "Device");
  396. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  397. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  398. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  399. }
  400. else
  401. {
  402. HardwareInfo.add("MajorID", "Detector");
  403. HardwareInfo.add("MinorID", "Device");
  404. HardwareInfo.add("VendorID", "iRay");
  405. HardwareInfo.add("ProductID", "Mars");
  406. HardwareInfo.add("SerialID", "1234");
  407. }
  408. string ret = HardwareInfo.encode();
  409. return ret;
  410. }
  411. extern IRayCtrl* g_pIRayCtrl;
  412. const float ABS_ZERO_TEMPERATURE = -273.15f; //绝对零度
  413. nsFPD::FPDDeviceIRay::FPDDeviceIRay(std::shared_ptr <IOEventCenter> center, string ConfigPath)
  414. :m_strSDKPath(""),
  415. m_nDeviceIndex(0),
  416. m_eAppStatus(APP_STATUS_WORK_END),
  417. m_nGridLicense(0),
  418. m_strModuleIP(""),
  419. m_strModuleSN(""),
  420. m_strShockSensor(""),
  421. m_strBatterySN(""),
  422. m_strMotionStatus(""),
  423. m_strSelfTest(""),
  424. m_strLastError(""),
  425. m_strCalibTime(""),
  426. m_bOpened(false),
  427. m_bBatteryCharging(false),
  428. m_bRecoveringImage(false),
  429. m_bAbortRecover(false),
  430. m_bImagePendingOrNot(false),
  431. m_bResetDetector(false),
  432. m_nBatteryCapacity(0),
  433. m_nBatteryCharges(0),
  434. m_nShockCounts(0),
  435. m_nWorkStation(0),
  436. m_nDoseParam(0),
  437. m_nRawImgWidth(0),
  438. m_nRawImgHeight(0),
  439. m_nFullImgWidth(0),
  440. m_nFullImgHeight(0),
  441. m_nTopOffset(0),
  442. m_nLeftOffset(0),
  443. m_nImageBits(0),
  444. m_fFactorEXI2UGY(0.0f),
  445. m_bPreviewEnable(false),
  446. m_bTestSensitivity(false),
  447. m_fBatteryTemperature(0.0f),
  448. m_nXrayCalibNum(0),
  449. m_pwFullImageData(nullptr),
  450. m_pwRawImageData(nullptr),
  451. m_pwPreviewImg(nullptr),
  452. m_pPreviewImageHead(nullptr),
  453. m_pFullImageHead(nullptr),
  454. m_pDetectors(nullptr),
  455. m_bDisConnected(false),
  456. m_ExitEvt(NULL),
  457. m_bAttached(false),
  458. m_hNotifyThread(NULL),
  459. m_bRecoverImageStatusInit(false),
  460. m_bSaveRaw(false),
  461. m_bUIConfirmRecover(false),
  462. m_nCalibrationType(CCOS_CALIBRATION_TYPE_MAX),
  463. m_CalTemperlowWarn(0.0f),
  464. m_CalTemperupWarn(0.0f),
  465. m_CalTemperWarnInitialed(false),
  466. m_bNotifyCalWarn(true)
  467. {
  468. super::EventCenter = center;
  469. g_strAppPath = GetProcessDirectory() + "\\";
  470. m_AcqUnit.reset(new OemAcq(center, this));
  471. m_SyncUnit.reset(new OemSync(center, this));
  472. m_CalibUnit.reset(new OemCalib(center, this));
  473. m_DetectorCtrlUnit.reset(new OemDetectorCtrl(center, this));
  474. m_Battery.reset(new DeviceBatteryMould("DetectorIRayBattery", 0, 10, 20, 30, 40, 100, 100, 0, center));
  475. m_Temperature.reset(new DeviceTemperatureMould("DetectorIRayTemperature", ABS_ZERO_TEMPERATURE, 0.0f, 10.0f, 60.0f, 20.0f, 40.0f, 70.0f, 0.0f, center));
  476. m_Wifi.reset(new DeviceWifiMould("DetectorIRayWifi", 0, 20, 30, 40, 50, 100, 100, 0, center));
  477. m_DetectorConfiguration.reset(new DetectorConfiguration(ConfigPath));
  478. m_WarnAndError.reset(new FPDErrorWarning(center, DetectorUnitType, g_strAppPath + "OEMDrivers\\Detector\\iRay\\iRayDR"));
  479. m_CalibProcess.reset(new CalibrationProcess());
  480. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  481. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY));
  482. m_WaitCalibDoseEvt = CreateEvent(0, 1, 0, 0);
  483. m_OffsetCalibrationEvt = CreateEvent(0, 0, 0, 0);
  484. m_PauseCalibrationEvt = CreateEvent(0, 1, 0, 0);
  485. m_CompleteCalibrationEvt = CreateEvent(0, 1, 0, 0);
  486. m_CrateCalibReportEvt = CreateEvent(0, 0, 0, 0);
  487. m_UploadCalibMapOver = CreateEvent(0, 1, 0, 0);
  488. m_ExitEvt = CreateEvent(0, 1, 0, 0);
  489. m_CalibGapEvt = CreateEvent(0, 1, 0, 0);
  490. m_WriteCumstomFileEvt = CreateEvent(0, 1, 0, 0);
  491. }
  492. nsFPD::FPDDeviceIRay::~FPDDeviceIRay()
  493. {
  494. SetEvent(m_ExitEvt);
  495. CloseHandle(m_WaitCalibDoseEvt);
  496. CloseHandle(m_OffsetCalibrationEvt);
  497. CloseHandle(m_PauseCalibrationEvt);
  498. CloseHandle(m_CompleteCalibrationEvt);
  499. CloseHandle(m_CrateCalibReportEvt);
  500. CloseHandle(m_WriteCumstomFileEvt);
  501. CloseHandle(m_UploadCalibMapOver);
  502. CloseHandle(m_CalibGapEvt);
  503. if (m_hNotifyThread != NULL)
  504. {
  505. CloseHandle(m_hNotifyThread);
  506. }
  507. }
  508. std::string nsFPD::FPDDeviceIRay::GetGUID() const
  509. {
  510. return DetectorUnitType;
  511. }
  512. bool nsFPD::FPDDeviceIRay::Prepare()
  513. {
  514. //SetMaxBlockSize(const char *pQueName, DWORD FullBlockSize, DWORD FullBlockCount, DWORD PrevBlockSize, DWORD PrevBlockCount)
  515. EventCenter->OnMaxBlockSize("DrQue", m_nRawImgWidth * m_nRawImgHeight * 2, 3, 1500 * 1500 * 2, 1);
  516. Connect();
  517. return true;
  518. }
  519. void nsFPD::FPDDeviceIRay::RegisterCtrl(nDetail::Dispatch* Dispatch)
  520. {
  521. Dispatch->Action.Push("GetFPDinformation", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDetectorInfo);
  522. Dispatch->Action.Push("ActiveDetector", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSActiveDetector);
  523. Dispatch->Action.Push("RESET", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSRESET);
  524. Dispatch->Action.Push("EnterExam", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSEnterExam);
  525. Dispatch->Action.Push("ExitExam", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSExitExam);
  526. Dispatch->Action.Push("AttachConnect", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSAttachConnect);
  527. Dispatch->Action.Push("CancelAttach", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSCancelAttach);
  528. Dispatch->Action.Push("RecoverImage", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSRecoverImage);
  529. Dispatch->Action.Push("ResetConnect", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSResetConnect);
  530. Dispatch->Action.Push("DisConnectFPD", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSDisConnectFPD);
  531. Dispatch->Action.Push("DisConnectFPDForce", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSDisConnectFPDForce);
  532. Dispatch->Action.Push("UpdateFirmware", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSUpdateFirmware);
  533. Dispatch->Action.Push("SaveSensitivity", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSSaveSensitivity);
  534. Dispatch->Action.Push("GetRecoverImageState", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetRecoverImageState);
  535. Dispatch->Get.Push("RecoverImageState", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetRecoverImageState);
  536. Dispatch->Get.Push("RecoverImageEvent", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetRecoverImageEvent);
  537. Dispatch->Get.Push("DetectorStatus", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetFPDStatus);
  538. Dispatch->Get.Push("DetectorConnectStatus", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetConnectStatus);
  539. Dispatch->Get.Push("DetectorAttach", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetAttachResult);
  540. Dispatch->Get.Push("Attached", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetAttachStatus);
  541. Dispatch->Get.Push("DetectorInitialStatus", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetInitialStatus);
  542. Dispatch->Get.Push("DetectorUpdateFWStatus", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetUpdateFWStatus);
  543. Dispatch->Get.Push("FPDShockSensorInfo", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetShockSensorInfo);
  544. Dispatch->Get.Push("FieldofViewShape", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetFieldofViewShape);
  545. Dispatch->Get.Push("FieldofViewDimension", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetFieldofViewDimension);
  546. Dispatch->Get.Push("DetectorType", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDetectorType);
  547. Dispatch->Get.Push("Description", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDescription);
  548. Dispatch->Get.Push("DetectorID", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDetectorID);
  549. Dispatch->Get.Push("DateofLastDetectorCalibration", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDateofLastDetectorCalibration);
  550. Dispatch->Get.Push("TimeofLastDetectorCalibration", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetTimeofLastDetectorCalibration);
  551. Dispatch->Get.Push("DetectorConditionsNominalFlag", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDetectorConditionsNominalFlag);
  552. Dispatch->Get.Push("FPDSensitivity", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetFPDSensitivity);
  553. Dispatch->Get.Push("FPDSensitivityResult", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetFPDSensitivityResult);
  554. Dispatch->Get.Push("PixelData", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetPixelData);
  555. Dispatch->Get.Push("TargetEXI", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetTargetEXI);
  556. Dispatch->Get.Push("FPDLastError", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetLastError);
  557. Dispatch->Get.Push("FirmwareStatus", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetFirmwareStatus);
  558. Dispatch->Update.Push(AttrKey::NotifyStatusTimePeriod, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSUpdateNotifyStatusTimePeriod);
  559. Dispatch->Update.Push(AttrKey::ReconnectTimePeriod, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSUpdateReconnectTimePeriod);
  560. }
  561. void nsFPD::FPDDeviceIRay::RegisterAcq(nDetail::Dispatch* Dispatch)
  562. {
  563. Dispatch->Action.Push("SetAcqMode", m_AcqUnit.get(), &AcqUnit::JSSetAcqMode);
  564. Dispatch->Get.Push("ZskkFPDState", m_AcqUnit.get(), &AcqUnit::JSGetZskkFPDState);
  565. Dispatch->Get.Push("NoNeedWaitImage", m_AcqUnit.get(), &AcqUnit::JSGetNoNeedWaitImage);
  566. Dispatch->Get.Push("ImgDataInfo", m_AcqUnit.get(), &AcqUnit::JSGetLastImage);
  567. }
  568. void nsFPD::FPDDeviceIRay::RegisterSync(nDetail::Dispatch* Dispatch)
  569. {
  570. Dispatch->Action.Push("SetSyncMode", m_SyncUnit.get(), &SyncUnit::JSSetSyncMode);
  571. Dispatch->Action.Push("SetXwindowSize", m_SyncUnit.get(), &SyncUnit::JSSetXwindowSize);
  572. Dispatch->Action.Push("PrepareAcquisition", m_SyncUnit.get(), &SyncUnit::JSPrepareAcquisition);
  573. Dispatch->Action.Push("StartAcquisition", m_SyncUnit.get(), &SyncUnit::JSStartAcquisition);
  574. Dispatch->Action.Push("StopAcquisition", m_SyncUnit.get(), &SyncUnit::JSStopAcquisition);
  575. Dispatch->Action.Push("ActiveSyncMode", m_SyncUnit.get(), &SyncUnit::JSActiveSyncMode);
  576. Dispatch->Get.Push("FPDReadyStatus", m_SyncUnit.get(), &SyncUnit::JSGetFPDReady);
  577. Dispatch->Get.Push("XwindowStatus", m_SyncUnit.get(), &SyncUnit::JSGetXWindowStatus);
  578. Dispatch->Get.Push("ImageReadingStatus", m_SyncUnit.get(), &SyncUnit::JSGetImageReadingStatus);
  579. Dispatch->Get.Push("SupportSyncMode", m_SyncUnit.get(), &SyncUnit::JSGetSupportSyncMode);
  580. }
  581. void nsFPD::FPDDeviceIRay::RegisterCalib(nDetail::Dispatch* Dispatch)
  582. {
  583. Dispatch->Action.Push("UploadCalibrationFiles", m_CalibUnit.get(), &CalibUnit::JSUploadCalibrationFiles);
  584. Dispatch->Action.Push("SetSID", m_CalibUnit.get(), &CalibUnit::JSSetSID);
  585. Dispatch->Action.Push("ActiveCalibration", m_CalibUnit.get(), &CalibUnit::JSActiveCalibration);
  586. Dispatch->Action.Push("GetRequestedDose", m_CalibUnit.get(), &CalibUnit::JSGetRequestedDose);
  587. Dispatch->Action.Push("SetRequestedDose", m_CalibUnit.get(), &CalibUnit::JSSetRequestedDose);
  588. Dispatch->Action.Push("PrepareCalibration", m_CalibUnit.get(), &CalibUnit::JSPrepareCalibration);
  589. Dispatch->Action.Push("StartCalibration", m_CalibUnit.get(), &CalibUnit::JSStartCalibration);
  590. Dispatch->Action.Push("StopCalibration", m_CalibUnit.get(), &CalibUnit::JSStopCalibration);
  591. Dispatch->Action.Push("SetCorrectionType", m_CalibUnit.get(), &CalibUnit::JSSetCorrectionType);
  592. Dispatch->Action.Push("GetCalibrationStep", m_CalibUnit.get(), &CalibUnit::JSGetCalibrationStep);
  593. Dispatch->Action.Push("SaveCalibrationFile", m_CalibUnit.get(), &CalibUnit::JSSaveCalibrationFile);
  594. Dispatch->Action.Push("AcceptCalibration", m_CalibUnit.get(), &CalibUnit::JSAcceptCalibration);
  595. Dispatch->Action.Push("RejectCalibration", m_CalibUnit.get(), &CalibUnit::JSRejectCalibration);
  596. Dispatch->Get.Push("HaveImgCalibration", m_CalibUnit.get(), &CalibUnit::JSGetHaveImgCalibration);
  597. Dispatch->Get.Push(AttrKey::CalibrationStatus, m_CalibUnit.get(), &CalibUnit::JSGetCalibStatus);
  598. Dispatch->Get.Push(AttrKey::CalibrationProgress, m_CalibUnit.get(), &CalibUnit::JSGetCalibProgress);
  599. Dispatch->Get.Push("UploadCalibrationFilesResult", m_CalibUnit.get(), &CalibUnit::JSGetUploadCalibrationFilesResult);
  600. Dispatch->Get.Push("SaveCalibrationFileFinish", m_CalibUnit.get(), &CalibUnit::JSGetSaveCalibrationFileFinish);
  601. Dispatch->Get.Push(AttrKey::CalibMode, m_CalibUnit.get(), &CalibUnit::JSGetCalibMode);
  602. Dispatch->Get.Push(AttrKey::LastCalibrationDate, m_CalibUnit.get(), &CalibUnit::JSGetLastCalibrationDate);
  603. Dispatch->Get.Push(AttrKey::CalibrationFileExpireTime, m_CalibUnit.get(), &CalibUnit::JSGetCalibrationFileExpireTime);
  604. Dispatch->Set.Push(AttrKey::LastCalibrationDate, m_CalibUnit.get(), &CalibUnit::SetLastCalibrationDate);
  605. Dispatch->Set.Push(AttrKey::CalibrationFileExpireTime, m_CalibUnit.get(), &CalibUnit::SetCalibrationFileExpireTime);
  606. Dispatch->Update.Push(AttrKey::CalibMode, m_CalibUnit.get(), &CalibUnit::JSUpdateCalibMode);
  607. Dispatch->Update.Push(AttrKey::LastCalibrationDate, m_CalibUnit.get(), &CalibUnit::JSUpdateLastCalibrationDate);
  608. Dispatch->Update.Push(AttrKey::CalibrationFileExpireTime, m_CalibUnit.get(), &CalibUnit::JSUpdateCalibrationFileExpireTime);
  609. Dispatch->Update.Push(AttrKey::CalibrationFileExpirationReminder,
  610. [this](std::string in, std::string& out) {out = in; this->m_bNotifyCalWarn = (in == "1")? true : false; return RET_STATUS::RET_SUCCEED; });
  611. }
  612. void nsFPD::FPDDeviceIRay::RegisterOthers(nDetail::Dispatch* Dispatch)
  613. {
  614. Dispatch->Get.Push(AttrKey::Temperature_Value, m_Temperature.get(), &DeviceTemperatureMould::JSGetCurrentTemperatureValue);
  615. Dispatch->Get.Push(AttrKey::Remain_Power_Value, m_Battery.get(), &DeviceBatteryMould::JSGetCurrentBatteryValue);
  616. Dispatch->Get.Push(AttrKey::Wifi_Strength_Value, m_Wifi.get(), &DeviceWifiMould::JSGetCurrentSignalValue);
  617. //Dispatch->Get.Push(m_WarnAndError->m_MSGUnit->GetKey().c_str(), [this](std::string& out) { out = m_WarnAndError->m_MSGUnit->JSGet(); return RET_STATUS::RET_SUCCEED; });
  618. Dispatch->Get.Push(nDetail::AttrKey::ErrorList, m_WarnAndError.get(), &FPDErrorWarning::JSGetErrorList);
  619. Dispatch->Get.Push(TempMaxLimit, m_Temperature.get(), &DeviceTemperatureMould::JSGetTemperatureErrorMax);
  620. Dispatch->Get.Push(TempMinLimit, m_Temperature.get(), &DeviceTemperatureMould::JSGetTemperatureErrorMin);
  621. Dispatch->Get.Push(TempUpperLimit, m_Temperature.get(), &DeviceTemperatureMould::JSGetTemperatureWarningMax);
  622. Dispatch->Get.Push(TempLowerLimit, m_Temperature.get(), &DeviceTemperatureMould::JSGetTemperatureWarningMin);
  623. Dispatch->Get.Push(BatMiniLimit, m_Battery.get(), &DeviceBatteryMould::JSGetBatteryErrorMin);
  624. Dispatch->Get.Push(BatLowerLimit, m_Battery.get(), &DeviceBatteryMould::JSGetBatteryWarningMin);
  625. Dispatch->Get.Push(WifiMiniLimit, m_Wifi.get(), &DeviceWifiMould::JSGetSignalErrorMin);
  626. Dispatch->Get.Push(WifiLowerLimit, m_Wifi.get(), &DeviceWifiMould::JSGetSignalWarningMin);
  627. Dispatch->Set.Push(TempMaxLimit, m_Temperature.get(), &DeviceTemperatureMould::SetTemperatureErrorMax);
  628. Dispatch->Set.Push(TempMinLimit, m_Temperature.get(), &DeviceTemperatureMould::SetTemperatureErrorMin);
  629. Dispatch->Set.Push(TempUpperLimit, m_Temperature.get(), &DeviceTemperatureMould::SetTemperatureWarningMax);
  630. Dispatch->Set.Push(TempLowerLimit, m_Temperature.get(), &DeviceTemperatureMould::SetTemperatureWarningMin);
  631. Dispatch->Set.Push(BatMiniLimit, m_Battery.get(), &DeviceBatteryMould::SetBatteryErrorMin);
  632. Dispatch->Set.Push(BatLowerLimit, m_Battery.get(), &DeviceBatteryMould::SetBatteryWarningMin);
  633. Dispatch->Set.Push(WifiMiniLimit, m_Wifi.get(), &DeviceWifiMould::SetSignalErrorMin);
  634. Dispatch->Set.Push(WifiLowerLimit, m_Wifi.get(), &DeviceWifiMould::SetSignalWarningMin);
  635. Dispatch->Update.Push(TempMaxLimit, m_Temperature.get(), &DeviceTemperatureMould::JSUpdateTemperatureErrorMax);
  636. Dispatch->Update.Push(TempMinLimit, m_Temperature.get(), &DeviceTemperatureMould::JSUpdateTemperatureErrorMin);
  637. Dispatch->Update.Push(TempUpperLimit, m_Temperature.get(), &DeviceTemperatureMould::JSUpdateTemperatureWarningMax);
  638. Dispatch->Update.Push(TempLowerLimit, m_Temperature.get(), &DeviceTemperatureMould::JSUpdateTemperatureWarningMin);
  639. Dispatch->Update.Push(TemperatureCalibUpWarn, [](std::string in, std::string& out) {out = in; return RET_STATUS::RET_SUCCEED; });
  640. Dispatch->Update.Push(TemperatureCalibLowWarn, [](std::string in, std::string& out) {out = in; return RET_STATUS::RET_SUCCEED; });
  641. Dispatch->Update.Push(BatMiniLimit, m_Battery.get(), &DeviceBatteryMould::JSUpdateBatteryErrorMin);
  642. Dispatch->Update.Push(BatLowerLimit, m_Battery.get(), &DeviceBatteryMould::JSUpdateBatteryWarningMin);
  643. Dispatch->Update.Push(WifiMiniLimit, m_Wifi.get(), &DeviceWifiMould::JSUpdateSignalErrorMin);
  644. Dispatch->Update.Push(WifiLowerLimit, m_Wifi.get(), &DeviceWifiMould::JSUpdateSignalWarningMin);
  645. }
  646. void nsFPD::FPDDeviceIRay::Register()
  647. {
  648. auto Disp = &Dispatch;
  649. RegisterCtrl(Disp);
  650. RegisterAcq(Disp);
  651. RegisterSync(Disp);
  652. RegisterCalib(Disp);
  653. RegisterOthers(Disp);
  654. }
  655. bool nsFPD::FPDDeviceIRay::LoadConfig()
  656. {
  657. if (!m_DetectorConfiguration->LoadConfigurations(m_stDeviceConfig))
  658. {
  659. //mLog::Fatal("Load configuration file failed!!! ");
  660. return false;
  661. }
  662. try
  663. {
  664. m_nRawImgWidth = m_stDeviceConfig.nRawWidth;
  665. m_nRawImgHeight = m_stDeviceConfig.nRawHeight;
  666. m_nFullImgWidth = m_stDeviceConfig.nFullImageWidth;
  667. m_nFullImgHeight = m_stDeviceConfig.nFullImageHeight;
  668. m_nImageBits = m_stDeviceConfig.nImageBits;
  669. m_nTopOffset = m_stDeviceConfig.nImageTopOffset;
  670. m_nBottomOffset = m_stDeviceConfig.nImageBottomOffset;
  671. m_nLeftOffset = m_stDeviceConfig.nImageLeftOffset;
  672. m_nRightOffset = m_stDeviceConfig.nImageRightOffset;
  673. m_bPreviewEnable = m_stDeviceConfig.bPreviewEnable;
  674. //mLog::Debug("PreviewEnable: {$} ", m_bPreviewEnable ? "true" : "false");
  675. m_bAttached = true;
  676. SetAttachStatus(1);
  677. m_bSaveRaw = m_stDeviceConfig.nSaveRaw ? true : false;
  678. //mLog::Debug("Set SaveRaw: {$} ", m_bSaveRaw ? "true" : "false");
  679. m_bForceGridSuppress = m_stDeviceConfig.nForceGridSuppress ? true : false;
  680. //mLog::Debug("Set ForceGridSuppress: {$}", m_bForceGridSuppress ? "true" : "false");
  681. //SDK目录
  682. m_strSDKPath = (string)m_DetectorConfiguration->m_Configurations["SDKPath"];
  683. //mLog::Info("SDKPath: {$}", m_strSDKPath);
  684. //SDK探测器工作目录
  685. m_stDeviceConfig.strWorkDir = g_strAppPath + m_strSDKPath + "\\work_dir\\" + m_stDeviceConfig.strDetectorModel;
  686. //mLog::Info("SDK work path: {$}", m_stDeviceConfig.strWorkDir);
  687. string strFPDinfo;
  688. strFPDinfo = (string)m_DetectorConfiguration->m_Configurations["FieldofViewShape"];
  689. m_DetectorCtrlUnit->SetFieldofViewShape(strFPDinfo);
  690. strFPDinfo = (string)m_DetectorConfiguration->m_Configurations["FieldofViewDimension"];
  691. m_DetectorCtrlUnit->SetFieldofViewDimension(strFPDinfo);
  692. m_DetectorCtrlUnit->SetDetectorType("SCINTILLATOR");
  693. strFPDinfo = (string)m_DetectorConfiguration->m_Configurations["Description"];
  694. m_DetectorCtrlUnit->SetDescription(strFPDinfo);
  695. m_DetectorCtrlUnit->SetDetectorConditionsNominalFlag("YES");
  696. auto szFDinfo = std::to_string(m_stDeviceConfig.nDoseOfEXI);
  697. m_fFactorEXI2UGY = 100.0f / (float)atof(szFDinfo.c_str()) * 1.0f; //统一使用IEC标准 呈现四角信息,无单位 ugy * 100 -ugy。所有Zskk探测器的FactorEXI2UGY均需*100
  698. //mLog::Info("FactorEXI2UGY: {$} ", m_fFactorEXI2UGY);
  699. auto strFPDcoef = std::to_string(m_fFactorEXI2UGY);
  700. m_DetectorCtrlUnit->SetFPDSensitivity(strFPDcoef);
  701. string strPixelData = std::to_string(m_stDeviceConfig.nImageBits);
  702. m_DetectorCtrlUnit->SetPixelData(strPixelData);
  703. m_DetectorCtrlUnit->SetTargetEXI("5000");
  704. m_CalibUnit->SetLastCalibrationDate(m_stDeviceConfig.strLastCalibrationDate);
  705. m_CalibUnit->SetCalibrationFileExpireTime(m_stDeviceConfig.strCalibrationFileExpireTime);
  706. m_bNotifyCalWarn = ((int)m_DetectorConfiguration->m_Configurations["CalibrationFileExpirationReminder"] == 1) ? true : false;
  707. //------------------------------------可支持的同步模式
  708. ResDataObject jsonSupportSyncType;
  709. jsonSupportSyncType = m_DetectorConfiguration->m_Configurations["SupportSyncMode"];
  710. //mLog::Debug("SupportSyncMode: {$}", jsonSupportSyncType.encode());
  711. m_SyncUnit->JSSetSupportSyncMode(jsonSupportSyncType.encode());
  712. //--------------------------------------------------------------------------------
  713. //加载校正配置
  714. m_stDeviceConfig.nCalibMode = (int)m_DetectorConfiguration->m_Configurations["CalibMode"];
  715. //mLog::Debug("Calibration mode: {$}", m_stDeviceConfig.nCalibMode);
  716. m_CalibDoseList = m_DetectorConfiguration->m_Configurations["CalibConfig"]["NodeInfo"];
  717. //mLog::Debug("CalibDoseList: {$} ", m_CalibDoseList.encode());
  718. }
  719. catch (exception e)
  720. {
  721. //mLog::Error("Get has exception error: {$}", e.what());
  722. }
  723. return true;
  724. }
  725. void nsFPD::FPDDeviceIRay::InitializeTemperatureConfigs()
  726. {
  727. auto temperuperror = m_stDeviceConfig.fTemperMaxLimit;
  728. auto temperupwarn = m_stDeviceConfig.fTemperUpLimit;
  729. auto temperlowwarn = m_stDeviceConfig.fTemperLowLimit;
  730. auto temperlowerror = m_stDeviceConfig.fTemperMinLimit;
  731. //Caliberation Temperature ranger
  732. m_CalTemperupWarn = m_stDeviceConfig.fCalibTemperUp;
  733. m_CalTemperlowWarn = m_stDeviceConfig.fCalibTemperLow;
  734. if (m_Temperature)
  735. {
  736. m_Temperature->SetTemperatureErrorMax(to_string(temperuperror));
  737. m_Temperature->SetTemperatureWarningMax(to_string(temperupwarn));
  738. m_Temperature->SetTemperatureCalibWarningMax(to_string(m_CalTemperupWarn));
  739. m_Temperature->SetTemperatureCalibWarningMin(to_string(m_CalTemperlowWarn));
  740. m_Temperature->SetTemperatureWarningMin(to_string(temperlowwarn));
  741. m_Temperature->SetTemperatureErrorMin(to_string(temperlowerror));
  742. }
  743. //mLog::Info("Temperature config initialize result {$}<{$}<{$}<{$}<{$}<{$}",
  744. temperlowerror, temperlowwarn, m_CalTemperlowWarn, m_CalTemperupWarn, temperupwarn, temperuperror);
  745. }
  746. bool nsFPD::FPDDeviceIRay::CreateDevice()
  747. {
  748. if (!LoadConfig())
  749. {
  750. //mLog::Info("Load configuration file failed!!! ");
  751. return false;
  752. }
  753. InitializeTemperatureConfigs();
  754. bool bDemo = false;
  755. int nDemo = (int)m_DetectorConfiguration->m_Configurations["DemoEnable"];
  756. if (nDemo != 0)
  757. {
  758. bDemo = true;
  759. }
  760. bool bRet = false;
  761. if (bDemo)
  762. {
  763. //mLog::Info("iRay Drive run in demo");
  764. }
  765. else
  766. {
  767. if (g_pIRayCtrl == NULL)
  768. {
  769. m_pDetectors = new IRayCtrl();
  770. g_pIRayCtrl = m_pDetectors;
  771. m_pDetectors->AddDPCs(this, m_DetectorConfiguration->m_Configurations, m_stDeviceConfig);
  772. bRet = m_pDetectors->Init(g_strAppPath);
  773. //mLog::Info("Create SDK ctrl ok ");
  774. }
  775. else
  776. {
  777. m_pDetectors = g_pIRayCtrl;
  778. //mLog::Info("SDK ctrl Already exit ");
  779. m_pDetectors->AddDPCs(this, m_DetectorConfiguration->m_Configurations, m_stDeviceConfig);
  780. }
  781. }
  782. return bRet;
  783. }
  784. RET_STATUS nsFPD::FPDDeviceIRay::Connect()
  785. {
  786. //mLog::Info("------------------------ FPD type {$}, Device {$} Start running. ------------------------ ", m_stDeviceConfig.strDeviceName.c_str(), this);
  787. string strPath = g_strAppPath + m_strSDKPath + "\\FpdSys.dll";
  788. m_stDeviceConfig.strSoftware = GetFileVersion(strPath);
  789. //mLog::Info("iRay SDK version: {$}", m_stDeviceConfig.strSoftware.c_str());
  790. if (m_stDeviceConfig.bConnectStatus)
  791. {
  792. //mLog::Info("Already Connected, return");
  793. return RET_STATUS::RET_SUCCEED;
  794. }
  795. if (m_bDisConnected)
  796. {
  797. //mLog::Info("Already DisConnected, just return");
  798. return RET_STATUS::RET_FAILED;
  799. }
  800. if (m_bOpened) //已经初始化连接设备
  801. {
  802. //mLog::Info("Already init, return");
  803. return RET_STATUS::RET_SUCCEED;
  804. }
  805. if (m_hNotifyThread == NULL)
  806. {
  807. m_hNotifyThread = CreateThread(0, 0, OnNotify, this, 0, &m_NotifyThreadID);
  808. if (m_hNotifyThread == NULL)
  809. {
  810. //mLog::Info("Start Exposure Thread Failed!");
  811. }
  812. else
  813. {
  814. //mLog::Info("Start Exposure Thread End");
  815. }
  816. }
  817. //g_strAppPath = "C:\\SVN\\Ccos\\CcosDriver_V2\\Deliver\\Bin\\ReleaseX64";
  818. bool bRet = m_pDetectors->Connect(g_strAppPath, this);
  819. if (!bRet)
  820. {
  821. //mLog::Error("Device connect failed!");
  822. return RET_STATUS::RET_FAILED;
  823. }
  824. m_bOpened = true;
  825. //mLog::Info("call connect detector over ");
  826. return RET_STATUS::RET_SUCCEED;
  827. }
  828. DWORD nsFPD::FPDDeviceIRay::OnNotify(LPVOID pParam)
  829. {
  830. //mLog::Info("OnNotify Loop Entry-----------");
  831. FPDDeviceIRay* pNotifyOpr = (FPDDeviceIRay*)pParam;
  832. HANDLE* pHandles = new HANDLE[6];
  833. pHandles[0] = pNotifyOpr->m_PauseCalibrationEvt;
  834. pHandles[1] = pNotifyOpr->m_CompleteCalibrationEvt;
  835. pHandles[2] = pNotifyOpr->m_OffsetCalibrationEvt;
  836. pHandles[3] = pNotifyOpr->m_CrateCalibReportEvt;
  837. pHandles[4] = pNotifyOpr->m_WriteCumstomFileEvt;
  838. pHandles[5] = pNotifyOpr->m_ExitEvt;
  839. int nHandlesNum = 6;
  840. DWORD nTimeOut = 5000;
  841. while (1)
  842. {
  843. DWORD dwResult = WaitForMultipleObjects(nHandlesNum, pHandles, FALSE, nTimeOut);
  844. if (dwResult == WAIT_TIMEOUT)
  845. {
  846. if (!pNotifyOpr->m_stDeviceConfig.bConnectStatus)
  847. {
  848. //mLog::Info("connect to FPD not finished");
  849. continue;
  850. }
  851. }
  852. if (dwResult == WAIT_OBJECT_0)//m_PauseCalibrationEvt
  853. {
  854. //mLog::Info("OnNotify get PauseCalibration evt");
  855. pNotifyOpr->PauseCalibration();
  856. }
  857. if (dwResult == WAIT_OBJECT_0 + 1)//m_CompleteCalibrationEvt
  858. {
  859. ResetEvent(pNotifyOpr->m_CompleteCalibrationEvt);
  860. //mLog::Info("OnNotify get CompleteCalibration evt");
  861. pNotifyOpr->CompleteCalibration();
  862. }
  863. else if (dwResult == WAIT_OBJECT_0 + 2)//m_OffsetCalibrationEvt
  864. {
  865. //mLog::Info("OnNotify get m_OffsetCalibrationEvt evt");
  866. }
  867. else if (dwResult == WAIT_OBJECT_0 + 3)//m_CrateCalibReportEvt
  868. {
  869. //mLog::Info("OnNotify get m_CrateCalibReportEvt evt");
  870. pNotifyOpr->SaveFailedCalibFile();
  871. break;
  872. }
  873. else if (dwResult == WAIT_OBJECT_0 + 4)//m_WriteCumstomFileEvt
  874. {
  875. //mLog::Info("OnNotify get m_WriteCumstomFileEvt evt");
  876. pNotifyOpr->m_pDetectors->WriteCumstomFile(pNotifyOpr->m_nDeviceIndex);
  877. break;
  878. }
  879. else if (dwResult == WAIT_OBJECT_0 + 5)//m_ExitEvt
  880. {
  881. //mLog::Info("Exit OnNotify Thread");
  882. break;
  883. }
  884. }
  885. delete[] pHandles;
  886. CloseHandle(pNotifyOpr->m_ExitEvt);
  887. return 0;
  888. }
  889. RET_STATUS nsFPD::FPDDeviceIRay::ActiveDetector(bool bActive)
  890. {
  891. if (bActive)
  892. {
  893. //mLog::Info("ActiveDetector");
  894. bool bRet = (m_pDetectors)->ActivePanel(this, bActive);
  895. if (!bRet)
  896. {
  897. return RET_STATUS::RET_FAILED;
  898. }
  899. //SendAllError();
  900. }
  901. else
  902. {
  903. //mLog::Info("UnActiveDetector");
  904. bool bRet = (m_pDetectors)->ActivePanel(this, bActive);
  905. if (!bRet)
  906. {
  907. return RET_STATUS::RET_FAILED;
  908. }
  909. //ClearAllError();
  910. }
  911. return RET_STATUS::RET_SUCCEED;
  912. }
  913. void nsFPD::FPDDeviceIRay::UnactiveBySDK(void* pActviedDPC)
  914. {
  915. if (pActviedDPC != this)
  916. {
  917. //goto Unactive status, clear errorlist
  918. }
  919. }
  920. RET_STATUS nsFPD::FPDDeviceIRay::PrepareAcquisition()
  921. {
  922. //mLog::Info("[PrepareAcquisition]");
  923. if (!m_stDeviceConfig.bConnectStatus)
  924. {
  925. return RET_STATUS::RET_THREAD_INVALID;
  926. }
  927. RET_STATUS Ret = RET_STATUS::RET_FAILED;
  928. if (RET_STATUS::RET_SUCCEED == m_pDetectors->PrepareAcquisition(this))
  929. {
  930. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  931. m_SyncUnit->FPDReadyNotify(true);
  932. Ret = RET_STATUS::RET_SUCCEED;
  933. }
  934. //mLog::Info("PrepareAcquisition over");
  935. return Ret;
  936. }
  937. RET_STATUS nsFPD::FPDDeviceIRay::StartAcquisition(string in)
  938. {
  939. //mLog::Info("[StartAcquisition]");
  940. if (!m_stDeviceConfig.bConnectStatus)
  941. {
  942. return RET_STATUS::RET_THREAD_INVALID;
  943. }
  944. m_bAbortRecover = false;//能执行StartAcq,说明没有错误可以ready曝光。不再影响abort后再次recoverimage功能
  945. RET_STATUS Ret = RET_STATUS::RET_FAILED;
  946. if (RET_STATUS::RET_SUCCEED == m_pDetectors->StartAcquisition(this))
  947. {
  948. Ret = RET_STATUS::RET_SUCCEED;
  949. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_ACQ));
  950. }
  951. else
  952. {
  953. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  954. //mLog::Error("StartAcquisition failed");
  955. }
  956. //mLog::Info("StartAcquisition over");
  957. return Ret;
  958. }
  959. RET_STATUS nsFPD::FPDDeviceIRay::StopAcquisition()
  960. {
  961. //mLog::Info("[StopAcquisition]");
  962. if (!m_stDeviceConfig.bConnectStatus)
  963. {
  964. return RET_STATUS::RET_THREAD_INVALID;
  965. }
  966. RET_STATUS Ret = RET_STATUS::RET_FAILED;
  967. if (RET_STATUS::RET_SUCCEED == m_pDetectors->StopAcquisition(this))
  968. {
  969. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  970. Ret = RET_STATUS::RET_SUCCEED;
  971. }
  972. //mLog::Info("StopAcquisition over ");
  973. return Ret;
  974. }
  975. string nsFPD::FPDDeviceIRay::GetFileVersion(string strFilePathName)
  976. {
  977. DWORD dwVerSize = GetFileVersionInfoSize(strFilePathName.c_str(), NULL);
  978. if (dwVerSize == 0)
  979. {
  980. return "";
  981. }
  982. LPVOID pVersionBuffer = malloc(dwVerSize);
  983. if (nullptr == pVersionBuffer)
  984. {
  985. return "";
  986. }
  987. GetFileVersionInfo(strFilePathName.c_str(), 0, dwVerSize, pVersionBuffer);
  988. VS_FIXEDFILEINFO* pInfo;
  989. UINT nInfoLen;
  990. char szValue[MAX_PATH] = { 0 };
  991. if (VerQueryValue(pVersionBuffer, ("\\"), (void**)&pInfo, &nInfoLen))
  992. {
  993. sprintf_s(szValue, ("%d.%d.%d.%d"),
  994. HIWORD(pInfo->dwFileVersionMS), LOWORD(pInfo->dwFileVersionMS),
  995. HIWORD(pInfo->dwFileVersionLS), LOWORD(pInfo->dwFileVersionLS));
  996. }
  997. string strVersion = szValue;
  998. return strVersion;
  999. }
  1000. void nsFPD::FPDDeviceIRay::SendTemperatureValue(float fTemp)
  1001. {
  1002. int nStatus = 0;
  1003. m_Temperature->SetTemperature(fTemp, nStatus);
  1004. //mLog::Info("SendTemperatureValue: {$}, status {$} ", fTemp, nStatus);
  1005. return;
  1006. }
  1007. void nsFPD::FPDDeviceIRay::SendWifiValue(int nWifi)
  1008. {
  1009. int nStatus = 0;
  1010. m_Wifi->SetSignalValue(nWifi, nStatus);
  1011. //mLog::Info("SendWifiValue: {$}, status {$} ", nWifi, nStatus);
  1012. return;
  1013. }
  1014. void nsFPD::FPDDeviceIRay::SendBatteryValue(int nBattery)
  1015. {
  1016. int nStatus = 0;
  1017. m_Battery->SetRemainPowerValue(nBattery, nStatus);
  1018. //mLog::Info("SendBatteryValue: {$}, status {$} ", nBattery, nStatus);
  1019. return;
  1020. }
  1021. RET_STATUS nsFPD::FPDDeviceIRay::XWindowOnNotify()
  1022. {
  1023. RET_STATUS Ret = RET_STATUS::RET_FAILED;
  1024. m_stImgCreateTime = { 0 };
  1025. GetLocalTime(&m_stImgCreateTime);
  1026. //mLog::Info("Full image create time-{$}:{$}:{$}:{$}", m_stImgCreateTime.wHour, m_stImgCreateTime.wMinute, m_stImgCreateTime.wSecond, m_stImgCreateTime.wMilliseconds);
  1027. //mLog::Info("WindowOn ");
  1028. m_SyncUnit->XWindowOnNotify();
  1029. return Ret;
  1030. }
  1031. RET_STATUS nsFPD::FPDDeviceIRay::XWindowOffNotify()
  1032. {
  1033. RET_STATUS Ret = RET_STATUS::RET_FAILED;
  1034. m_SyncUnit->XWindowOffNotify();
  1035. //mLog::Info("WindowOff ");
  1036. return Ret;
  1037. }
  1038. //--------------------------------------------------------------------------------------------------校正相关
  1039. RET_STATUS nsFPD::FPDDeviceIRay::ActiveCalibration(CCOS_CALIBRATION_TYPE eType)
  1040. {
  1041. //mLog::Info("==============================ActiveCalibration is {$}", (int)eType);
  1042. m_nCalibrationType = eType;
  1043. m_DetectorCtrlUnit->SetFPDSensitivity("100");
  1044. if (!m_stDeviceConfig.bConnectStatus)
  1045. {
  1046. return RET_STATUS::RET_THREAD_INVALID;
  1047. }
  1048. if (eType == CCOS_CALIBRATION_TYPE_NONE || eType == CCOS_CALIBRATION_TYPE_MAX)
  1049. {
  1050. //mLog::Error("type error {$} ", (int)eType);
  1051. return RET_STATUS::RET_INVALID;
  1052. }
  1053. m_eAppStatus = APP_STATUS_CAL_BEGIN;
  1054. if (eType == CCOS_CALIBRATION_TYPE_XRAY)
  1055. {
  1056. ResetEvent(m_WaitCalibDoseEvt);
  1057. int nCalibrationRounds = (int)m_CalibDoseList.size();
  1058. m_pDetectors->SetReferenceNum(nCalibrationRounds);
  1059. }
  1060. m_pDetectors->CancelOperation();
  1061. RET_STATUS Ret = m_pDetectors->ActiveCalibration(eType, this);
  1062. if (RET_STATUS::RET_SUCCEED == Ret)
  1063. {
  1064. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_ACTIVE));
  1065. m_CalibUnit->SetCalibrationProgress("0");
  1066. if (eType == CCOS_CALIBRATION_TYPE_XRAY)
  1067. {
  1068. //mLog::Info("start to waitting CalibDoseEvt");
  1069. DWORD nRet = WaitForSingleObject(m_WaitCalibDoseEvt, INFINITE);
  1070. }
  1071. m_nXrayCalibNum = 0;
  1072. }
  1073. //重置校正流程参数
  1074. m_nCalibCurrentCalibrationRound = 1;
  1075. m_nCalibCurrentExposureIndex = 1;
  1076. m_nCalibCurrentExposureNum = 0;
  1077. //mLog::Info("==============================ActiveCalibration over");
  1078. return Ret;
  1079. }
  1080. RET_STATUS nsFPD::FPDDeviceIRay::GetRequestedDose(std::string& strDose)
  1081. {
  1082. //mLog::Info("GetRequestedDose");
  1083. if (!m_stDeviceConfig.bConnectStatus)
  1084. {
  1085. return RET_STATUS::RET_THREAD_INVALID;
  1086. }
  1087. RET_STATUS Ret = RET_STATUS::RET_SUCCEED;
  1088. bool bGetDoseInfo = false;
  1089. ResDataObject out;
  1090. if (CCOS_CALIBRATION_TYPE_DARK == m_nCalibrationType)
  1091. {
  1092. out.add("Dose", 0.0f);
  1093. out.add("kV", 0.0f);
  1094. out.add("mA", 0.0f);
  1095. out.add("ms", 0.0f);
  1096. out.add("mAs", 0.0f);
  1097. bGetDoseInfo = true;
  1098. }
  1099. else if (CCOS_CALIBRATION_TYPE_XRAY == m_nCalibrationType)
  1100. {
  1101. for (int i = 0; i < m_CalibDoseList.size(); i++)
  1102. {
  1103. ResDataObject temp = m_CalibDoseList[i];
  1104. int nDose = temp["Dose"];
  1105. //mLog::Info("Target dose: {$}, config dose: {$}", m_nDoseParam, nDose);
  1106. if (m_nDoseParam == nDose)
  1107. {
  1108. out.add("Dose", nDose);
  1109. out.add("kV", temp["kV"]);
  1110. out.add("mA", temp["mA"]);
  1111. out.add("ms", temp["ms"]);
  1112. out.add("mAs", temp["mAs"]);
  1113. bGetDoseInfo = true;
  1114. break;
  1115. }
  1116. }
  1117. }
  1118. else
  1119. {
  1120. Ret = RET_STATUS::RET_FAILED;
  1121. }
  1122. if (bGetDoseInfo)
  1123. {
  1124. strDose = out.encode();
  1125. //mLog::Info("GetRequestedDose {$} over", strDose.c_str());
  1126. }
  1127. else
  1128. {
  1129. //mLog::Error("GetRequestedDose failed");
  1130. }
  1131. return Ret;
  1132. }
  1133. RET_STATUS nsFPD::FPDDeviceIRay::SetRequestedDose(std::string strDose)
  1134. {
  1135. //mLog::Info("==============================SetRequestedDose");
  1136. RET_STATUS Ret = RET_STATUS::RET_SUCCEED;
  1137. return Ret;
  1138. }
  1139. RET_STATUS nsFPD::FPDDeviceIRay::PrepareCalibration()
  1140. {
  1141. //mLog::Info("==============================PrepareCalibration");
  1142. if (!m_stDeviceConfig.bConnectStatus)
  1143. {
  1144. return RET_STATUS::RET_THREAD_INVALID;
  1145. }
  1146. m_SyncUnit->FPDReadyNotify(false);
  1147. RET_STATUS Ret = RET_STATUS::RET_FAILED;
  1148. if (RET_STATUS::RET_SUCCEED == m_pDetectors->PrepareCalibration(this))
  1149. {
  1150. m_SyncUnit->FPDReadyNotify(true);
  1151. Ret = RET_STATUS::RET_SUCCEED;
  1152. }
  1153. else
  1154. {
  1155. Ret = RET_STATUS::RET_FAILED;
  1156. }
  1157. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1158. //mLog::Info("==============================PrepareCalibration over");
  1159. return Ret;
  1160. }
  1161. RET_STATUS nsFPD::FPDDeviceIRay::StartCalibration()
  1162. {
  1163. //mLog::Info("==============================StartCalibration");
  1164. if (!m_stDeviceConfig.bConnectStatus)
  1165. {
  1166. return RET_STATUS::RET_THREAD_INVALID;
  1167. }
  1168. RET_STATUS Ret = RET_STATUS::RET_FAILED;
  1169. //暗场
  1170. if (m_nCalibrationType == CCOS_CALIBRATION_TYPE_DARK)
  1171. {
  1172. //mLog::Info("DarkCalibration start...");
  1173. m_pDetectors->StartCalibration(this);
  1174. return RET_STATUS::RET_SUCCEED;
  1175. }
  1176. //亮场
  1177. if (RET_STATUS::RET_SUCCEED == m_pDetectors->StartCalibration(this))
  1178. {
  1179. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_ACQ));
  1180. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_RUNNING));
  1181. Ret = RET_STATUS::RET_SUCCEED;
  1182. }
  1183. else
  1184. {
  1185. Ret = RET_STATUS::RET_FAILED;
  1186. }
  1187. //mLog::Info("==============================StartCalibration over");
  1188. return RET_STATUS::RET_SUCCEED;
  1189. }
  1190. RET_STATUS nsFPD::FPDDeviceIRay::PauseCalibration()
  1191. {
  1192. RET_STATUS Ret = RET_STATUS::RET_SUCCEED;
  1193. m_nXrayCalibNum++;
  1194. if (m_nXrayCalibNum != 20)
  1195. {
  1196. //mLog::Info("start to waitting CalibDoseEvt");
  1197. DWORD nRet = WaitForSingleObject(m_WaitCalibDoseEvt, INFINITE);
  1198. }
  1199. ResetEvent(m_PauseCalibrationEvt);
  1200. ResetEvent(m_WaitCalibDoseEvt);
  1201. m_AcqUnit->SendNoNeedWaitImage(true);
  1202. if (m_nXrayCalibNum != 20)
  1203. {
  1204. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1205. m_CalibUnit->PauseCalibration();
  1206. }
  1207. //mLog::Info("Driver PauseCalibration over,m_nXrayCalibNum {$}", m_nXrayCalibNum);
  1208. return Ret;
  1209. }
  1210. RET_STATUS nsFPD::FPDDeviceIRay::StopCalibration()
  1211. {
  1212. //mLog::Info("StopCalibration");
  1213. if (!m_stDeviceConfig.bConnectStatus)
  1214. {
  1215. return RET_STATUS::RET_THREAD_INVALID;
  1216. }
  1217. m_pDetectors->CancelOperation();
  1218. if (CCOS_CALIBRATION_TYPE_DARK == m_nCalibrationType)
  1219. {
  1220. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_BESTOPPED));
  1221. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1222. m_CalibUnit->SetCalibrationProgress("100");
  1223. //mLog::Info("StopDarkCalibration over");
  1224. return RET_STATUS::RET_SUCCEED;
  1225. }
  1226. RET_STATUS Ret = RET_STATUS::RET_FAILED;
  1227. m_eAppStatus = APP_STATUS_CAL_END;
  1228. /*if (RET_STATUS::RET_SUCCEED == m_pDetectors->AbortCalibration(this))
  1229. {
  1230. Ret = RET_STATUS::RET_SUCCEED;
  1231. }
  1232. else
  1233. {
  1234. Ret = RET_STATUS::RET_FAILED;
  1235. }*/
  1236. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_BESTOPPED));
  1237. m_CalibUnit->SetCalibrationProgress("100");
  1238. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1239. m_AcqUnit->SendNoNeedWaitImage(true);
  1240. //mLog::Info("StopXRAYCalibration over");
  1241. return RET_STATUS::RET_SUCCEED;
  1242. }
  1243. void nsFPD::FPDDeviceIRay::AbortCalibration()
  1244. {
  1245. //mLog::Info("AbortCalibration ");
  1246. if (CCOS_CALIBRATION_TYPE_DARK == m_nCalibrationType)
  1247. {
  1248. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_ERROR));
  1249. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1250. m_CalibUnit->SetCalibrationProgress("100");
  1251. //mLog::Info("AbortDarkCalibration over ");
  1252. return;
  1253. }
  1254. m_eAppStatus = APP_STATUS_CAL_END;
  1255. m_pDetectors->AbortCalibration(this);
  1256. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_ERROR));
  1257. m_CalibUnit->SetCalibrationProgress("100");
  1258. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1259. m_AcqUnit->SendNoNeedWaitImage(true);
  1260. //mLog::Info("AbortXrayCalibration over");
  1261. return;
  1262. }
  1263. void nsFPD::FPDDeviceIRay::StopCalibrationInside()
  1264. {
  1265. //mLog::Info("StopCalibrationInside");
  1266. if (CCOS_CALIBRATION_TYPE_DARK == m_nCalibrationType)
  1267. {
  1268. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY));
  1269. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1270. m_CalibUnit->SetCalibrationProgress("100");
  1271. //mLog::Info("StopCalibrationInside dark over");
  1272. return;
  1273. }
  1274. m_eAppStatus = APP_STATUS_CAL_END;
  1275. m_pDetectors->AbortCalibration(this);
  1276. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY));
  1277. m_CalibUnit->SetCalibrationProgress("100");
  1278. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1279. m_AcqUnit->SendNoNeedWaitImage(true);
  1280. //mLog::Info("StopCalibrationInside xray over");
  1281. return;
  1282. }
  1283. bool nsFPD::FPDDeviceIRay::CompleteCalibration()
  1284. {
  1285. m_stDeviceConfig.fCalibTemperature2 = m_stDeviceConfig.fCurrentTemperValue;
  1286. m_stDeviceConfig.fCalibTemperature = (m_stDeviceConfig.fCalibTemperature1 + m_stDeviceConfig.fCalibTemperature2) / 2;
  1287. ResetEvent(m_UploadCalibMapOver);
  1288. m_pDetectors->CompleteCalibration(this);
  1289. DWORD nRet = WaitForSingleObject(m_UploadCalibMapOver, 60000);
  1290. if (WAIT_OBJECT_0 == nRet)
  1291. {
  1292. //mLog::Info("got event m_UploadCalibMapOver");
  1293. }
  1294. else if (WAIT_TIMEOUT == nRet)
  1295. {
  1296. //mLog::Info("wait event m_UploadCalibMapOver timeout");
  1297. }
  1298. else
  1299. {
  1300. //mLog::Info("wait event m_UploadCalibMapOver error");
  1301. }
  1302. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1303. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY));
  1304. m_CalibUnit->SetCalibrationProgress("100");
  1305. return true;
  1306. }
  1307. void nsFPD::FPDDeviceIRay::SaveFailedCalibFile()
  1308. {
  1309. m_pDetectors->SaveFailedCalibFiles(m_nDeviceIndex, false);
  1310. }
  1311. RET_STATUS nsFPD::FPDDeviceIRay::GetCalibrationStep(int nDetectorID, string& strCalibrationStepInfo)
  1312. {
  1313. //mLog::Info("## GetCalibrationStep ##");
  1314. RET_STATUS Ret = RET_STATUS::RET_SUCCEED;
  1315. //mLog::Info("Calibration DetectorID: {$}", nDetectorID);
  1316. ResDataObject out;
  1317. int nCalibrationRounds = (int)m_CalibDoseList.size();
  1318. int nExposureNumCurrentRound = (int)m_CalibDoseList[m_nCalibCurrentCalibrationRound - 1]["ExpNum"];
  1319. if (m_pDetectors->GetCalibrationStep(m_nCalibCurrentCalibrationRound, nCalibrationRounds, m_nCalibCurrentExposureIndex, nExposureNumCurrentRound))
  1320. {
  1321. //mLog::Info("GetCalibrationStep over");
  1322. Ret = RET_STATUS::RET_SUCCEED;
  1323. }
  1324. else
  1325. {
  1326. //mLog::Error("GetCalibrationStep error");
  1327. Ret = RET_STATUS::RET_FAILED;
  1328. }
  1329. out.add("CalibrationRounds", (int)m_CalibDoseList.size());
  1330. out.add("TotalExposureNum", m_nCalibTotalExposureNum);
  1331. out.add("CurrentCalibrationRound", m_nCalibCurrentCalibrationRound);
  1332. out.add("ExposureNumCurrentRound", (int)m_CalibDoseList[m_nCalibCurrentCalibrationRound - 1]["ExpNum"]);
  1333. out.add("CurrentExposureIndex", m_nCalibCurrentExposureIndex);
  1334. out.add("CurrentExposureNum", m_nCalibCurrentExposureNum);
  1335. strCalibrationStepInfo = out.encode();
  1336. //mLog::Info("GetCalibrationStep over \n{$}", strCalibrationStepInfo.c_str());
  1337. return Ret;
  1338. }
  1339. RET_STATUS nsFPD::FPDDeviceIRay::AcceptCalibration()
  1340. {
  1341. //mLog::Info("## AcceptCalibration ##");
  1342. RET_STATUS Ret = RET_STATUS::RET_SUCCEED;
  1343. if (m_pDetectors->AcceptCalibration())
  1344. {
  1345. //mLog::Info("AcceptCalibration over");
  1346. Ret = RET_STATUS::RET_SUCCEED;
  1347. }
  1348. else
  1349. {
  1350. //mLog::Error("AcceptCalibration error");
  1351. Ret = RET_STATUS::RET_FAILED;
  1352. }
  1353. int nExposureNumCurrentRound = (int)m_CalibDoseList[m_nCalibCurrentCalibrationRound - 1]["ExpNum"];
  1354. //完成校正条件:轮数够了,曝光次数够了
  1355. if ((m_nCalibCurrentCalibrationRound == (int)m_CalibDoseList.size()) && (m_nCalibCurrentExposureIndex == nExposureNumCurrentRound))
  1356. {
  1357. //mLog::Info("Calibration Round: {$}, Exposure Index: {$}, Finished", m_nCalibCurrentCalibrationRound, m_nCalibCurrentExposureIndex);
  1358. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1359. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY));
  1360. m_CalibUnit->SetCalibrationProgress("100");
  1361. return Ret;
  1362. }
  1363. if (m_nCalibCurrentExposureIndex >= nExposureNumCurrentRound) //跳到下一轮校正参数
  1364. {
  1365. m_nCalibCurrentCalibrationRound++;
  1366. m_nCalibCurrentExposureIndex = 1;
  1367. ResDataObject temp = m_CalibDoseList[m_nCalibCurrentCalibrationRound - 1];
  1368. int nDose = temp["Dose"];
  1369. m_nDoseParam = nDose;
  1370. }
  1371. else
  1372. {
  1373. m_nCalibCurrentExposureIndex++;
  1374. }
  1375. m_nCalibCurrentExposureNum++;
  1376. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1377. return Ret;
  1378. }
  1379. RET_STATUS nsFPD::FPDDeviceIRay::RejectCalibration()
  1380. {
  1381. //mLog::Info("## RejectCalibration ##");
  1382. RET_STATUS Ret = RET_STATUS::RET_SUCCEED;
  1383. if (m_pDetectors->RejectCalibration())
  1384. {
  1385. //mLog::Info("RejectCalibration over");
  1386. Ret = RET_STATUS::RET_SUCCEED;
  1387. }
  1388. else
  1389. {
  1390. //mLog::Error("RejectCalibration error");
  1391. Ret = RET_STATUS::RET_FAILED;
  1392. }
  1393. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1394. return Ret;
  1395. }
  1396. RET_STATUS nsFPD::FPDDeviceIRay::SaveCalibrationFile(bool bSaveFlag)
  1397. {
  1398. //mLog::Info("## SaveCalibrationFile ##");
  1399. RET_STATUS Ret = RET_STATUS::RET_SUCCEED;
  1400. //mLog::Info("SaveCalibrationFile by user: {$}", bSaveFlag);
  1401. if (!bSaveFlag)
  1402. {
  1403. //mLog::Warn("Not save calibration file");
  1404. return Ret;
  1405. }
  1406. if (m_pDetectors->SaveCalibrationFile())
  1407. {
  1408. //mLog::Info("SaveCalibrationFile over");
  1409. m_CalibUnit->SetSaveCalibrationFileFinish(true);
  1410. Ret = RET_STATUS::RET_SUCCEED;
  1411. //更新配置文件中校正日期和时间
  1412. time_t localtime = time(NULL);
  1413. string strLocalTime = DatetimeToString(localtime);
  1414. //mLog::Info("strLocalTime:{$}", strLocalTime);
  1415. m_CalibUnit->SetLastCalibrationDate(strLocalTime);
  1416. //清除校正文件相关警告
  1417. m_WarnAndError->ClearWarn(ERR_FPD_CAL_FILE_NOT_EXIST);
  1418. m_WarnAndError->ClearWarn(ERR_FPD_CAL_FILE_OUTDATE);
  1419. }
  1420. else
  1421. {
  1422. //mLog::Error("SaveCalibrationFile error");
  1423. m_CalibUnit->SetSaveCalibrationFileFinish(false);
  1424. Ret = RET_STATUS::RET_FAILED;
  1425. }
  1426. return Ret;
  1427. }
  1428. //--------------------------------------------------------------------------------------------------------------------
  1429. RET_STATUS nsFPD::FPDDeviceIRay::ResetConnect()
  1430. {
  1431. //mLog::Info("Reset Connect");
  1432. m_pDetectors->ResetFPD(this);
  1433. //mLog::Info("FPDDeviceIRay::ResetConnect over ");
  1434. return RET_STATUS::RET_SUCCEED;
  1435. }
  1436. RET_STATUS nsFPD::FPDDeviceIRay::DisConnectFPD()
  1437. {
  1438. //mLog::Info("DisConnectFPD");
  1439. if (!m_pDetectors->DisConnect(this))
  1440. {
  1441. //mLog::Error("DisConnectFPD failed");
  1442. return RET_STATUS::RET_FAILED;
  1443. }
  1444. SendWifiValue(0);
  1445. SendBatteryValue(0);
  1446. SendTemperatureValue(ABS_ZERO_TEMPERATURE);
  1447. m_bDisConnected = true;
  1448. ResetAllError();
  1449. //mLog::Info("DisConnectFPD over");
  1450. return RET_STATUS::RET_SUCCEED;
  1451. }
  1452. RET_STATUS nsFPD::FPDDeviceIRay::UpdateFirmware()
  1453. {
  1454. m_pDetectors->OnUpdateFirmware(this);
  1455. return RET_STATUS::RET_SUCCEED;
  1456. }
  1457. RET_STATUS nsFPD::FPDDeviceIRay::AttachConnect()
  1458. {
  1459. m_DetectorCtrlUnit->SetConnectStatus(to_string(PANEL_ATTACH_START));
  1460. return RET_STATUS::RET_SUCCEED;
  1461. }
  1462. RET_STATUS nsFPD::FPDDeviceIRay::CancelAttach()
  1463. {
  1464. return RET_STATUS::RET_SUCCEED;
  1465. }
  1466. RET_STATUS nsFPD::FPDDeviceIRay::SetAttachStatus(int nStatus)
  1467. {
  1468. return m_DetectorCtrlUnit->SetAttachStatus(to_string(nStatus));
  1469. }
  1470. void nsFPD::FPDDeviceIRay::FullImageDateArrived(WORD* pImg)
  1471. {
  1472. AddFrameWithRawHead(IMAGE_FULL, pImg, m_stDeviceConfig.nFullImageWidth * m_stDeviceConfig.nFullImageHeight);
  1473. }
  1474. void nsFPD::FPDDeviceIRay::PrevImageDateArrived(WORD* pImg)
  1475. {
  1476. AddFrameWithRawHead(IMAGE_PREVIEW, pImg, m_stDeviceConfig.nPreviewWidth * m_stDeviceConfig.nPreviewHeight);
  1477. }
  1478. RET_STATUS nsFPD::FPDDeviceIRay::SetXwindow(float XwindowSize)
  1479. {
  1480. //mLog::Info("SetXwindowSize {$}", XwindowSize);
  1481. //mLog::Info("SetXwindowSize over");
  1482. return RET_STATUS::RET_SUCCEED;
  1483. }
  1484. RET_STATUS nsFPD::FPDDeviceIRay::EnterExam(int nExamStatus)
  1485. {
  1486. //mLog::Info("EnterExam");
  1487. switch (nExamStatus)
  1488. {
  1489. case APP_STATUS_WORK_BEGIN:
  1490. //mLog::Info("Enter into Exam Windows");
  1491. OnErrorX(ERR_FPD_DOSE_LOW);
  1492. OnErrorX(ERR_FPD_DOSE_HIGH);
  1493. OnErrorX(ERR_FPD_DOSE_OBJ);//清除之前校正的错误,如果有的话
  1494. CheckCalibartionDue();
  1495. break;
  1496. case APP_STATUS_WORK_END:
  1497. //mLog::Info("Quit Exam Windows");
  1498. m_bTestSensitivity = false;
  1499. m_WarnAndError->ClearWarn(ERR_FPD_CAL_FILE_NOT_EXIST);
  1500. m_WarnAndError->ClearWarn(ERR_FPD_CAL_FILE_OUTDATE);
  1501. break;
  1502. case APP_STATUS_DETSHARE_BEGIN:
  1503. //mLog::Info("Enter into Detector Share Windows");
  1504. break;
  1505. case APP_STATUS_DETSHAR_END:
  1506. //mLog::Info("Quit Detector Share Windows");
  1507. break;
  1508. case APP_STATUS_CAL_BEGIN:
  1509. //mLog::Info("Enter into Calibration Windows");
  1510. break;
  1511. case APP_STATUS_CAL_END:
  1512. //mLog::Info("Quit Calibration Windows");
  1513. break;
  1514. default:
  1515. //mLog::Warn("Undefined app status");
  1516. break;
  1517. }
  1518. m_eAppStatus = (APP_STATUS)nExamStatus;
  1519. m_pDetectors->EnterExam(m_eAppStatus);
  1520. return RET_STATUS::RET_SUCCEED;
  1521. }
  1522. RET_STATUS nsFPD::FPDDeviceIRay::SetAcqMode(int mode)
  1523. {
  1524. if (!m_stDeviceConfig.bConnectStatus)
  1525. {
  1526. //mLog::Error("Detector communication is error!");
  1527. return RET_STATUS::RET_FAILED;
  1528. }
  1529. if (nullptr == m_pwFullImageData)
  1530. {
  1531. m_pwFullImageData = new WORD[m_nFullImgWidth * m_nFullImgHeight];
  1532. }
  1533. m_AcqUnit->SetFulImageInfo(m_nFullImgWidth, m_nFullImgHeight, m_nImageBits, false);
  1534. m_AcqUnit->SetPrevImageInfo(m_stDeviceConfig.bPreviewEnable, m_stDeviceConfig.nPreviewHeight, m_stDeviceConfig.nPreviewWidth, false);
  1535. if (!m_pDetectors->SelectExamMode(1, this))
  1536. {
  1537. //mLog::Error("Set acqmode failed");
  1538. return RET_STATUS::RET_FAILED;
  1539. }
  1540. return RET_STATUS::RET_SUCCEED;
  1541. }
  1542. RET_STATUS nsFPD::FPDDeviceIRay::SetSyncMode(SYNC_MODE nSyncMode, HARDWARE_TRIGGER_MODE TriggerMode)
  1543. {
  1544. if (!m_stDeviceConfig.bConnectStatus)
  1545. {
  1546. return RET_STATUS::RET_THREAD_INVALID;
  1547. }
  1548. //return (m_pDetectors)->SetSyncMode(nSyncMode, TriggerMode);
  1549. return RET_STATUS::RET_SUCCEED;
  1550. }
  1551. void nsFPD::FPDDeviceIRay::OnFPDCallback(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1552. {
  1553. m_nDeviceIndex = nDetectorID;
  1554. switch (nEventLevel)
  1555. {
  1556. case EVT_LEVEL_CONFIGURATION:
  1557. {
  1558. OnEventProcessConf(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1559. break;
  1560. }
  1561. case EVT_LEVEL_INFORMATOION:
  1562. {
  1563. OnEventProcessInfo(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1564. break;
  1565. }
  1566. case EVT_LEVEL_STATUS:
  1567. {
  1568. OnEventProcessStatus(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1569. break;
  1570. }
  1571. case EVT_LEVEL_DATA:
  1572. {
  1573. OnEventProcessData(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1574. break;
  1575. }
  1576. case EVT_LEVEL_WARNING:
  1577. {
  1578. OnEventProcessWarning(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1579. break;
  1580. }
  1581. case EVT_LEVEL_ERROR:
  1582. {
  1583. OnEventProcessError(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1584. break;
  1585. }
  1586. default:
  1587. {
  1588. break;
  1589. }
  1590. }
  1591. }
  1592. void nsFPD::FPDDeviceIRay::OnEventProcessConf(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1593. {
  1594. switch (nEventID)
  1595. {
  1596. case EVT_CONF_PANEL_SERIAL:
  1597. {
  1598. m_stDeviceConfig.strPanelSerial = pszMsg;
  1599. //mLog::Info("Receive Panel {$} SN {$}", nDetectorID, pszMsg);
  1600. char cDetectorID[17] = { 0 };
  1601. memcpy(cDetectorID, m_stDeviceConfig.strPanelSerial.c_str(), 16);
  1602. string strDetectorID = cDetectorID;
  1603. m_DetectorCtrlUnit->SetDetectorID(strDetectorID);
  1604. //mLog::Info("SedDetectorID {$}", strDetectorID.c_str());
  1605. if (!m_bRecoverImageStatusInit)
  1606. {
  1607. m_RecoverImageStatus.add("DetectorName", m_stDeviceConfig.strDeviceName.c_str());
  1608. m_RecoverImageStatus.add("DetectorSN", m_stDeviceConfig.strPanelSerial.c_str());
  1609. m_RecoverImageStatus.add("DetectorWifiSignal", "1");
  1610. m_RecoverImageStatus.add("Result", "-1");
  1611. m_bRecoverImageStatusInit = true;
  1612. }
  1613. break;
  1614. }
  1615. case EVT_CONF_RAW_WIDTH:
  1616. {
  1617. if (m_stDeviceConfig.nFullImageWidth != nParam1)
  1618. {
  1619. m_stDeviceConfig.nFullImageWidth = nParam1;
  1620. }
  1621. //mLog::Info("Panel {$} nRawWidth:{$}", nDetectorID, m_stDeviceConfig.nRawWidth);
  1622. break;
  1623. }
  1624. case EVT_CONF_RAW_HIGHT:
  1625. {
  1626. if (m_stDeviceConfig.nFullImageHeight != nParam1)
  1627. {
  1628. m_stDeviceConfig.nFullImageHeight = nParam1;
  1629. }
  1630. //mLog::Info("Panel {$} nRawHeight:{$}", nDetectorID, m_stDeviceConfig.nRawHeight);
  1631. break;
  1632. }
  1633. case EVT_CONF_RAW_BITS:
  1634. {
  1635. if (m_stDeviceConfig.nImageBits != nParam1)
  1636. {
  1637. m_stDeviceConfig.nImageBits = nParam1;
  1638. }
  1639. m_stDeviceConfig.nImageBits = nParam1;
  1640. //mLog::Info("Panel {$} nImageBits:{$}", nDetectorID, m_stDeviceConfig.nImageBits);
  1641. break;
  1642. }
  1643. case EVT_CONF_PIXELSPACE:
  1644. {
  1645. m_stDeviceConfig.nPixelSpace = nParam1;
  1646. //mLog::Info("Panel {$} nPixelSpace:{$}", nDetectorID, m_stDeviceConfig.nPixelSpace);
  1647. break;
  1648. }
  1649. case EVT_CONF_PREVIEW_WIDTH:
  1650. {
  1651. if (m_stDeviceConfig.nPreviewWidth != nParam1)
  1652. {
  1653. m_stDeviceConfig.nPreviewWidth = nParam1;
  1654. }
  1655. //mLog::Info("Panel {$} nPreviewWidth:{$}", nDetectorID, m_stDeviceConfig.nPreviewWidth);
  1656. break;
  1657. }
  1658. case EVT_CONF_PREVIEW_HIGHT:
  1659. {
  1660. if (m_stDeviceConfig.nPreviewHeight != nParam1)
  1661. {
  1662. m_stDeviceConfig.nPreviewHeight = nParam1;
  1663. }
  1664. //mLog::Info("Panel {$} nPreviewHeight:{$}", nDetectorID, m_stDeviceConfig.nPreviewHeight);
  1665. break;
  1666. }
  1667. case EVT_CONF_MODULE_TYPE:
  1668. {
  1669. //mLog::Info("Receive Panel {$} ModuleType {$}", nDetectorID, pszMsg);
  1670. break;
  1671. }
  1672. case EVT_CONF_MODULE_IP:
  1673. {
  1674. m_strModuleIP = pszMsg;
  1675. //mLog::Info("Receive Panel {$} ModuleIP {$}", nDetectorID, pszMsg);
  1676. break;
  1677. }
  1678. case EVT_CONF_MODULE_SN:
  1679. {
  1680. m_strModuleSN = pszMsg;
  1681. //mLog::Info("Receive Panel {$} ModuleSN {$}", nDetectorID, pszMsg);
  1682. break;
  1683. }
  1684. case EVT_CONF_FIRWARE_UPDATE:
  1685. {
  1686. m_stDeviceConfig.nFirmwareStatus = nParam1;
  1687. m_DetectorCtrlUnit->SetFirmwareStatus(to_string(nParam1));
  1688. //mLog::Info("Panel {$} FirmwareUpdate:{$}", nDetectorID, m_stDeviceConfig.nFirmwareStatus);
  1689. break;
  1690. }
  1691. case EVT_CONF_PART_NUMBER:
  1692. {
  1693. m_stDeviceConfig.strPartNumber = pszMsg;
  1694. //mLog::Info("Panel {$} PartNumber:{$}", nDetectorID, pszMsg);
  1695. break;
  1696. }
  1697. case EVT_CONF_BATTERY_SN:
  1698. {
  1699. m_strBatterySN = pszMsg;
  1700. //mLog::Info("Panel {$} Battery SN:{$}", nDetectorID, pszMsg);
  1701. break;
  1702. }
  1703. case EVT_CONF_WIFI_SSID:
  1704. {
  1705. m_stDeviceConfig.strWifiSSID = pszMsg;
  1706. //mLog::Info("Panel {$} WifiSSID:{$}", nDetectorID, pszMsg);
  1707. break;
  1708. }
  1709. case EVT_CONF_IFBOARD:
  1710. {
  1711. //mLog::Info("Panel {$} InterfaceBoard:{$}", nDetectorID, pszMsg);
  1712. break;
  1713. }
  1714. case EVT_CONF_DATECODE:
  1715. {
  1716. m_stDeviceConfig.strDateCode = pszMsg;
  1717. //mLog::Info("Panel {$} DateCode:{$}", nDetectorID, pszMsg);
  1718. break;
  1719. }
  1720. case EVT_CONF_LIFETIME:
  1721. {
  1722. int nLifeTime = nParam1;
  1723. if (nLifeTime != m_stDeviceConfig.nLifeTime)
  1724. {
  1725. //mLog::Info("LifeTime:{$}", nLifeTime);
  1726. m_stDeviceConfig.nLifeTime = nLifeTime;
  1727. }
  1728. break;
  1729. }
  1730. default:
  1731. {
  1732. break;
  1733. }
  1734. }
  1735. }
  1736. void nsFPD::FPDDeviceIRay::OnEventProcessInfo(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1737. {
  1738. int nID = nDetectorID;
  1739. switch (nEventID)
  1740. {
  1741. case EVT_INFO_POWER_ON:
  1742. {
  1743. int nPowerOn = nParam1;
  1744. //mLog::Info("Detector {$} PowerOn:{$}", nID, nPowerOn);
  1745. m_stDeviceConfig.nPowerOn = nPowerOn;
  1746. if ((nPowerOn != m_stDeviceConfig.nPowerOn) && (m_strBatterySN != ""))
  1747. {
  1748. }
  1749. break;
  1750. }
  1751. case EVT_INFO_BATTERY_CAPACITY:
  1752. {
  1753. int nBatteryCapacity = nParam1;
  1754. if ((nBatteryCapacity != m_nBatteryCapacity) && (m_strBatterySN != ""))
  1755. {
  1756. //mLog::Info("{$},SN:{$}", nBatteryCapacity, m_strBatterySN);
  1757. m_nBatteryCapacity = nBatteryCapacity;
  1758. }
  1759. break;
  1760. }
  1761. case EVT_INFO_BATTERY_TEMPERATURE:
  1762. {
  1763. float fBatteryTemper = fParam2;
  1764. if (((fBatteryTemper - m_fBatteryTemperature) >= 0.1f) && (m_strBatterySN != ""))
  1765. {
  1766. //mLog::Info("SN:{$} ,temperature:{$}", m_strBatterySN, fBatteryTemper);
  1767. m_fBatteryTemperature = fBatteryTemper;
  1768. }
  1769. break;
  1770. }
  1771. case EVT_INFO_BATTERY_CHARGES:
  1772. {
  1773. int nBatteryCharges = nParam1;
  1774. if ((nBatteryCharges != m_nBatteryCharges) && (m_strBatterySN != ""))
  1775. {
  1776. //mLog::Info("SN:{$},Charge number:{$}", m_strBatterySN, nBatteryCharges);
  1777. m_nBatteryCharges = nBatteryCharges;
  1778. }
  1779. break;
  1780. }
  1781. case EVT_INFO_WIFI_DATARATE:
  1782. {
  1783. if (nParam1 != m_stDeviceConfig.nWifiDataRate)
  1784. {
  1785. }
  1786. m_stDeviceConfig.nWifiDataRate = nParam1;
  1787. //mLog::Info("Detector {$} WifiDataRate:{$}", nID, m_stDeviceConfig.nWifiDataRate);
  1788. break;
  1789. }
  1790. case EVT_INFO_WIFI_CHANNEL:
  1791. {
  1792. m_stDeviceConfig.nWifiChannel = nParam1;
  1793. //mLog::Info("Panel {$} WifiChannel:{$}", nID, m_stDeviceConfig.nWifiChannel);
  1794. break;
  1795. }
  1796. case EVT_INFO_WIFI_SIGNALPOWER:
  1797. {
  1798. m_stDeviceConfig.nWifiSignalPower = nParam1;
  1799. break;
  1800. }
  1801. case EVT_INFO_WIFI_NOISEPOWER:
  1802. {
  1803. m_stDeviceConfig.nWifiNoisePower = nParam1;
  1804. //mLog::Info("Panel {$} WifiNoisePower:{$}", nID, m_stDeviceConfig.nWifiNoisePower);
  1805. break;
  1806. }
  1807. case EVT_INFO_FIRMWARE:
  1808. {
  1809. m_stDeviceConfig.strFirmware = pszMsg;
  1810. //mLog::Info("Panel {$} Firmware:{$}", nID, pszMsg);
  1811. break;
  1812. }
  1813. case EVT_INFO_SHOCKSENSOR_INFO:
  1814. {
  1815. //mLog::Info("Receive ShockSensor Info");
  1816. m_strShockSensor = pszMsg;
  1817. m_DetectorCtrlUnit->SetShockSensorInfo(m_strShockSensor);
  1818. break;
  1819. }
  1820. case EVT_INFO_CALIBRATIOIN_DATE:
  1821. {
  1822. //m_stDeviceConfig.strCalibrationDate = pszMsg;
  1823. //mLog::Info("Panel {$} STE Calibration Date:{$}", nID, pszMsg);
  1824. //m_DetectorCtrlUnit->SetDateofLastDetectorCalibration(m_stDeviceConfig.strCalibrationDate);
  1825. //m_stDeviceConfig.strCalibrationDue = m_CalibProcess->GetCalibDueDate(m_stDeviceConfig, m_stDeviceConfig.strCalibrationDate);
  1826. break;
  1827. }
  1828. case EVT_INFO_CALIBRATIOIN_DATEL:
  1829. {
  1830. //m_stDeviceConfig.strCalibrationLTEDate = pszMsg;
  1831. //mLog::Info("Panel {$} LTE Calibration Date:{$}", nID, pszMsg);
  1832. //m_stDeviceConfig.strCalibrationLTEDue = m_CalibProcess->GetCalibDueDate(m_stDeviceConfig, m_stDeviceConfig.strCalibrationLTEDate);
  1833. break;
  1834. }
  1835. case EVT_INFO_CALIBRATIOIN_TIME:
  1836. {
  1837. //mLog::Info("Panel {$} STE Calibration Time:{$}", nID, pszMsg);
  1838. m_stDeviceConfig.strCalibrationTime = pszMsg;
  1839. m_DetectorCtrlUnit->SetTimeofLastDetectorCalibration(m_stDeviceConfig.strCalibrationTime);
  1840. break;
  1841. }
  1842. case EVT_INFO_CALIBRATIOIN_TIMEL:
  1843. {
  1844. m_stDeviceConfig.strCalibrationLTETime = pszMsg;
  1845. //mLog::Info("Panel {$} LTE Calibration Time:{$}", nID, pszMsg);
  1846. break;
  1847. }
  1848. default:
  1849. {
  1850. break;
  1851. }
  1852. }
  1853. }
  1854. void nsFPD::FPDDeviceIRay::OnEventProcessStatus(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1855. {
  1856. int nID = nDetectorID;
  1857. string strWarnErrorCode = "";
  1858. switch (nEventID)
  1859. {
  1860. case EVT_STATUS_INIT:
  1861. {
  1862. if (PANEL_EVENT_END_OK == nParam1)
  1863. {
  1864. OnInitResult(true);
  1865. m_DetectorCtrlUnit->SetInitialStatus(to_string(DETECTOR_INI_SUCCESS));
  1866. //mLog::Info("connect FPD ok. Start Status Polling");
  1867. }
  1868. else if (PANEL_EVENT_END_ERROR == nParam1)
  1869. {
  1870. OnInitResult(false);
  1871. m_DetectorCtrlUnit->SetInitialStatus(to_string(DETECTOR_INI_FAILED));
  1872. }
  1873. else if (PANEL_EVENT_END == nParam1) //未连接探测器
  1874. {
  1875. m_DetectorCtrlUnit->SetInitialStatus(to_string(DETECTOR_INI_SUCCESS));
  1876. }
  1877. else if (PANEL_EVENT_START == nParam1)
  1878. {
  1879. m_DetectorCtrlUnit->SetInitialStatus(to_string(DETECTOR_INI_START));
  1880. }
  1881. break;
  1882. }
  1883. case EVT_STATUS_MOTION:
  1884. {
  1885. m_strMotionStatus = pszMsg;
  1886. break;
  1887. }
  1888. case EVT_STATUS_UPDATE_FIRMWARE:
  1889. {
  1890. if (PANEL_EVENT_START == nParam1)
  1891. {
  1892. //mLog::Info("Start update firmware");
  1893. m_DetectorCtrlUnit->SetUpdateFWStatus(to_string(DETECTOR_UFW_START));
  1894. }
  1895. else if (PANEL_EVENT_BEGIN == nParam1)
  1896. {
  1897. //mLog::Info("Update firmware begin");
  1898. m_stDeviceConfig.bConnectStatus = false;
  1899. }
  1900. else if (PANEL_EVENT_END_ERROR == nParam1)
  1901. {
  1902. //mLog::Info("Update firmware failed");
  1903. m_DetectorCtrlUnit->SetUpdateFWStatus(to_string(DETECTOR_UFW_ERROR));
  1904. }
  1905. else if (PANEL_EVENT_SUCCESS == nParam1)
  1906. {
  1907. //mLog::Info("update firmware success");
  1908. m_DetectorCtrlUnit->SetUpdateFWStatus(to_string(DETECTOR_UFW_SUCCESS));
  1909. }
  1910. else if (PANEL_EVENT_FWU_ERROR_BATTERY == nParam1)
  1911. {
  1912. //mLog::Info("update firmware failed, battery < 50");
  1913. m_DetectorCtrlUnit->SetUpdateFWStatus(to_string(DETECTOR_UFW_ERROR_BATTERY));
  1914. }
  1915. else if (PANEL_EVENT_FWU_ERROR_OMIT == nParam1)
  1916. {
  1917. //mLog::Info("update firmware failed, Omit");
  1918. m_DetectorCtrlUnit->SetUpdateFWStatus(to_string(DETECTOR_UFW_ERROR_OMIT));
  1919. }
  1920. break;
  1921. }
  1922. case EVT_STATUS_SELFTEST:
  1923. {
  1924. bool bLTE = false;
  1925. if (nParam1 == 1)
  1926. {
  1927. bLTE = true;
  1928. }
  1929. break;
  1930. }
  1931. case EVT_STATUS_DETECTORSHARE:
  1932. {
  1933. ENUM_PANEL_EVENT_STATE eStatus = (ENUM_PANEL_EVENT_STATE)nParam1;
  1934. switch (eStatus)
  1935. {
  1936. case PANEL_ATTACH_START:
  1937. //mLog::Info("SetConnectStatus(PANEL_ATTACH_START)");
  1938. m_DetectorCtrlUnit->SetConnectStatus(to_string(PANEL_ATTACH_START)); //重置status,避免服务判重,两次attach失败时,不将第二次的失败信息发送给客户端
  1939. break;
  1940. case PANEL_ATTACH_OVER:
  1941. {
  1942. //mLog::Info("New Detector Attach Over,Prepare to Connecting");
  1943. }
  1944. break;
  1945. case PANEL_ATTACH_FAILED: //UI显示Failed
  1946. //mLog::Info("New Detector Attach failed");
  1947. //mLog::Info("SetConnectStatus(PANEL_ATTACH_FAILED)");
  1948. if (m_eAppStatus == APP_STATUS_DETSHARE_BEGIN)
  1949. {
  1950. m_DetectorCtrlUnit->SetConnectStatus(to_string(PANEL_ATTACH_FAILED));
  1951. }
  1952. break;
  1953. case PANEL_CONNECT_OK:
  1954. {
  1955. //mLog::Info("SetConnectStatus(PANEL_CONNECT_OK)");
  1956. m_DetectorCtrlUnit->SetConnectStatus(to_string(PANEL_CONNECT_OK));
  1957. m_stDeviceConfig.bConnectStatus = true;
  1958. SetAttachStatus(1);
  1959. m_bAttached = true;
  1960. break;
  1961. }
  1962. case PANEL_CONNECT_ERROR:
  1963. {
  1964. //mLog::Info("SetConnectStatus(PANEL_CONNECT_ERROR)");
  1965. m_DetectorCtrlUnit->SetConnectStatus(to_string(PANEL_CONNECT_ERROR));
  1966. }
  1967. break;
  1968. case PANEL_DISCONNECT_SUCCESS:
  1969. {
  1970. m_nBatteryCapacity = 0;
  1971. m_strBatterySN = "";
  1972. m_stDeviceConfig.bExisted = false;
  1973. m_stDeviceConfig.bConnectStatus = false;
  1974. //mLog::Info("SetConnectStatus(PANEL_DISCONNECT_SUCCESS)");
  1975. m_DetectorCtrlUnit->SetConnectStatus(to_string(PANEL_DISCONNECT_SUCCESS));
  1976. break;
  1977. }
  1978. case PANEL_DISCONNECT_ERROR:
  1979. //mLog::Info("SetConnectStatus(PANEL_DISCONNECT_ERROR)");
  1980. m_DetectorCtrlUnit->SetConnectStatus(to_string(PANEL_DISCONNECT_ERROR));
  1981. break;
  1982. default:
  1983. break;
  1984. }
  1985. break;
  1986. }
  1987. case EVT_STATUS_SINGLEINIT:
  1988. {
  1989. break;
  1990. }
  1991. case EVT_STATUS_SELECTPANEL:
  1992. {
  1993. break;
  1994. }
  1995. case EVT_STATUS_PANEL:
  1996. {
  1997. ENUM_PANEL_STATUS m_ePanelStatus = (ENUM_PANEL_STATUS)nParam1;
  1998. if (PANEL_STANDBY == nParam1)
  1999. {
  2000. //mLog::Info("Panel Status:PREPARE");
  2001. }
  2002. else if (PANEL_READY_EXP == nParam1)
  2003. {
  2004. //mLog::Info("Panel Status:READY");
  2005. Action_ExpReady();
  2006. }
  2007. else if (PANEL_OFFSET_CAL == nParam1)
  2008. {
  2009. //mLog::Info("Panel Status:PANEL_OFFSET_CAL");
  2010. }
  2011. else if (PANEL_OFFSET_FINISH == nParam1)
  2012. {
  2013. //mLog::Info("Panel Status:PANEL_OFFSET_FINISH");
  2014. StopCalibrationInside();
  2015. }
  2016. else if (PANEL_OFFSET_FAILED == nParam1)
  2017. {
  2018. //mLog::Info("Panel Status:PANEL_OFFSET_FAILED");
  2019. AbortCalibration();
  2020. }
  2021. else if (PANEL_XWINDOW_ON == nParam1) //Xwindow On
  2022. {
  2023. //mLog::Info("Panel Status:XWINDOW_ON");
  2024. XWindowOnNotify();
  2025. }
  2026. else if (PANEL_XWINDOW_OFF == nParam1) //Xwindow Off
  2027. {
  2028. //mLog::Info("Panel Status:XWINDOW_OFF");
  2029. XWindowOffNotify();
  2030. }
  2031. else if (PANEL_GAIN_FINISH == nParam1)
  2032. {
  2033. //mLog::Info("Panel Status:CALIBRATION_FINISH");
  2034. }
  2035. else if (PANEL_GAIN_PREPARE == nParam1)
  2036. {
  2037. //mLog::Info("Detector Notify Xray Prepare");
  2038. }
  2039. else if (PANEL_GAIN_READY_EXP == nParam1)
  2040. {
  2041. Action_ExpReady();
  2042. }
  2043. else if (PANEL_AED_XRAY_ON == nParam1)
  2044. {
  2045. //mLog::Info("AED or inner2 xray on");
  2046. m_SyncUnit->XrayOnNotify();
  2047. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_ACQ));
  2048. }
  2049. else if (PANEL_AED_XRAY_OFF == nParam1)
  2050. {
  2051. //mLog::Info("AED or inner2 xray off");
  2052. m_SyncUnit->XrayOffNotify();
  2053. }
  2054. else
  2055. {
  2056. //mLog::Info("Panel {$} Status is :{$}", nID, (int)m_ePanelStatus);
  2057. }
  2058. break;
  2059. }
  2060. case EVT_STATUS_CALIBRATIOIN:
  2061. {
  2062. ENUM_PANEL_EVENT_STATE eStatus = (ENUM_PANEL_EVENT_STATE)nParam1;
  2063. switch (eStatus)
  2064. {
  2065. case PANEL_EVENT_START:
  2066. break;
  2067. case PANEL_EVENT_END_OK:
  2068. //mLog::Info("Calibration process is success");
  2069. SetEvent(m_CompleteCalibrationEvt);
  2070. break;
  2071. case PANEL_EVENT_END_ERROR:
  2072. //mLog::Info("Calibration process is failed");
  2073. break;
  2074. case PANEL_EVENT_TIMEOUT:
  2075. //mLog::Error("Calibration timeout");
  2076. break;
  2077. case PANEL_EVENT_CALIB_REPORT:
  2078. //mLog::Info("Create Calibration Report failed");
  2079. SetEvent(m_CrateCalibReportEvt);
  2080. break;
  2081. default:
  2082. break;
  2083. }
  2084. break;
  2085. }
  2086. case EVT_STATUS_SAVECALIB:
  2087. {
  2088. if (PANEL_EVENT_START == nParam1)
  2089. {
  2090. //mLog::Info("Begin to Save Calibration Files");
  2091. }
  2092. else if (PANEL_EVENT_END_ERROR == nParam1)
  2093. {
  2094. SetEvent(m_UploadCalibMapOver);
  2095. //mLog::Info("Save Calibration Files failed");
  2096. }
  2097. else if (PANEL_EVENT_END == nParam1)
  2098. {
  2099. SetEvent(m_UploadCalibMapOver);
  2100. //mLog::Info("Save Calibration Files Success");
  2101. }
  2102. break;
  2103. }
  2104. case EVT_STATUS_SAVEDEFECT:
  2105. {
  2106. if (PANEL_EVENT_START == nParam1)
  2107. {
  2108. //mLog::Info("Begin to Save Defect Files");
  2109. }
  2110. else if (PANEL_EVENT_END_ERROR == nParam1)
  2111. {
  2112. SetEvent(m_UploadCalibMapOver);
  2113. //mLog::Info("Save Defect Files failed");
  2114. }
  2115. else if (PANEL_EVENT_END == nParam1)
  2116. {
  2117. m_stDeviceConfig.bTaskEnd = true;
  2118. //mLog::Info("Save Defect Files Success");
  2119. SetEvent(m_UploadCalibMapOver);
  2120. }
  2121. break;
  2122. }
  2123. case EVT_STATUS_ACQUISITION:
  2124. {
  2125. ENUM_PANEL_EVENT_STATE eStatus = (ENUM_PANEL_EVENT_STATE)nParam1;
  2126. switch (eStatus)
  2127. {
  2128. case PANEL_EVENT_START:
  2129. {
  2130. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_ACQ));
  2131. break;
  2132. }
  2133. case PANEL_EVENT_END_OK:
  2134. break;
  2135. case PANEL_EVENT_END_ERROR: //由于断线造成指令执行失败
  2136. {
  2137. string strWarnErrorCode = ERR_FPD_ACQ_FAILED;
  2138. OnError(strWarnErrorCode);
  2139. break;
  2140. }
  2141. default:
  2142. break;
  2143. }
  2144. break;
  2145. }
  2146. case EVT_STATUS_PREPARE_EDNCALIBRATION:
  2147. break;
  2148. case EVT_STATUS_SINGLEEXP:
  2149. {
  2150. if (DOSE_TOO_HIGH == nParam1)
  2151. {
  2152. //mLog::Info("Dose too high");
  2153. m_strLastError = "Current dose level is too high and beyond the tolerance interval";
  2154. OnError(ERR_FPD_DOSE_HIGH, m_strLastError);
  2155. AbortCalibration();
  2156. }
  2157. else if (DOSE_TOO_LOW == nParam1)
  2158. {
  2159. //mLog::Info("Dose too low");
  2160. m_strLastError = "Current dose level is too low and beyond the tolerance interval";
  2161. OnError(ERR_FPD_DOSE_LOW, m_strLastError);
  2162. AbortCalibration();
  2163. }
  2164. else if (DOSE_OBJECT == nParam1)
  2165. {
  2166. //mLog::Info("Dose object");
  2167. m_strLastError = "Calibration has failed. Please check emergency stop button or calibration switch, otherwise call service.";
  2168. OnError(ERR_FPD_DOSE_OBJ, m_strLastError);
  2169. AbortCalibration();
  2170. }
  2171. else if (DOSE_ACCEPT == nParam1)
  2172. {
  2173. //mLog::Info("Calibration Result is acceptable");
  2174. m_strLastError = "";
  2175. OnErrorX(ERR_FPD_DOSE_LOW);
  2176. OnErrorX(ERR_FPD_DOSE_HIGH);
  2177. OnErrorX(ERR_FPD_DOSE_OBJ);
  2178. SetEvent(m_PauseCalibrationEvt);
  2179. }
  2180. else if (PANEL_EVENT_END_OK == nParam1)
  2181. {
  2182. }
  2183. else if (PANEL_EVENT_END_ERROR == nParam1)
  2184. {
  2185. AbortCalibration();
  2186. }
  2187. //endif
  2188. break;
  2189. }
  2190. case EVT_STATUS_IMAGEPENDING:
  2191. {
  2192. string strTemp = pszMsg;
  2193. if (strTemp.find("true") != std::string::npos)
  2194. {
  2195. m_bImagePendingOrNot = true;
  2196. }
  2197. else
  2198. {
  2199. m_bImagePendingOrNot = false;
  2200. }
  2201. if (m_bImagePendingOrNot) // && !m_bResetDetector
  2202. {
  2203. OnError(ERR_FPD_IMAGE_PENDING);
  2204. }
  2205. else
  2206. {
  2207. m_bResetDetector = false;//可以再次reset
  2208. OnErrorX(ERR_FPD_IMAGE_PENDING);
  2209. }
  2210. break;
  2211. }
  2212. case EVT_STATUS_IMAGERECOVERAUTO:
  2213. {
  2214. OnErrorX(ERR_FPD_IMAGE_PENDING);
  2215. m_RecoverImageStatus["Result"] = "0";
  2216. //mLog::Info("m_RecoverImageStatus[Result] = 0 by auto");
  2217. m_DetectorCtrlUnit->SetRecoverImageState(m_RecoverImageStatus.encode());
  2218. m_bAbortRecover = false; //终止恢复图像的变量也要重置
  2219. m_bRecoveringImage = false; //不再恢复图像过程中
  2220. m_nRecoverImageTimes = 0; //下次恢复图像,重置
  2221. m_bSendRecoverMessage = false; //下次恢复图像仍需判断;
  2222. break;
  2223. }
  2224. case EVT_STATUS_TEMPERATURE:
  2225. {
  2226. float fTemperature = fParam2;
  2227. OnProcessTemperature(nID, fTemperature);
  2228. m_stDeviceConfig.fCurrentTemperValue = fTemperature;
  2229. //mLog::Info("Detector {$} Temperature Value:{$}", nID, fTemperature);
  2230. SendTemperatureValue(fTemperature);
  2231. break;
  2232. }
  2233. case EVT_STATUS_WIFI:
  2234. {
  2235. int nWifiLevel = nParam1;
  2236. //mLog::Info("Detector {$} Wifi Value:{$}", nID, nWifiLevel);
  2237. strWarnErrorCode = ERR_FPD_WIFI_LOW;
  2238. if (nWifiLevel == 0) //WIFI值为0 表明是有线连接,不报错
  2239. {
  2240. OnErrorX(strWarnErrorCode);
  2241. }
  2242. else if (nWifiLevel < m_stDeviceConfig.nWifiLimit)
  2243. {
  2244. //wifi error
  2245. OnWarnX(WAR_FPD_WIFI_LOW);
  2246. OnError(strWarnErrorCode);
  2247. }
  2248. else if (nWifiLevel <= m_stDeviceConfig.nWifiWarning)
  2249. {
  2250. //wifi error
  2251. OnErrorX(strWarnErrorCode);
  2252. strWarnErrorCode = WAR_FPD_WIFI_LOW;
  2253. OnWarn(nID, strWarnErrorCode);
  2254. }
  2255. else
  2256. {
  2257. OnErrorX(strWarnErrorCode);
  2258. strWarnErrorCode = WAR_FPD_WIFI_LOW;
  2259. OnWarnX(strWarnErrorCode);
  2260. }
  2261. if (nWifiLevel != m_stDeviceConfig.nCurrentWifiValue)
  2262. {
  2263. //mLog::Info("Channel:{$},SignalPower:{$},NoisePower:{$},DataRate:{$}",
  2264. m_stDeviceConfig.nWifiChannel, m_stDeviceConfig.nWifiSignalPower, m_stDeviceConfig.nWifiNoisePower, m_stDeviceConfig.nWifiDataRate);
  2265. }
  2266. m_stDeviceConfig.nCurrentWifiValue = nWifiLevel;
  2267. SendWifiValue(nWifiLevel);
  2268. break;
  2269. }
  2270. case EVT_STATUS_BATTERY_VALUE:
  2271. {
  2272. int nBatteryValue = nParam1;
  2273. //mLog::Info("Detector {$} Battery:{$}", nID, nParam1);
  2274. if (nBatteryValue < m_stDeviceConfig.nBatteryLimit)
  2275. {
  2276. if (!m_bBatteryCharging) //如果没有充电;
  2277. {
  2278. strWarnErrorCode = ERR_FPD_BATTERY_LOW;
  2279. OnError(strWarnErrorCode);
  2280. strWarnErrorCode = WAR_FPD_BATTERY_LOW;
  2281. OnWarnX(strWarnErrorCode);
  2282. }
  2283. }
  2284. else if (nBatteryValue < m_stDeviceConfig.nBatteryWarning)
  2285. {
  2286. //battery error
  2287. strWarnErrorCode = ERR_FPD_BATTERY_LOW;
  2288. OnErrorX(strWarnErrorCode);
  2289. strWarnErrorCode = WAR_FPD_BATTERY_LOW;
  2290. //这里需要滤波,如果2次以上都检测到低于告警值才上报该警告
  2291. OnWarn(nID, strWarnErrorCode);
  2292. }
  2293. else
  2294. {
  2295. strWarnErrorCode = ERR_FPD_BATTERY_LOW;
  2296. OnErrorX(strWarnErrorCode);
  2297. strWarnErrorCode = WAR_FPD_BATTERY_LOW;
  2298. OnWarnX(strWarnErrorCode);
  2299. }
  2300. m_stDeviceConfig.nCurrentBatteryValue = nBatteryValue;
  2301. //mLog::Info("Detector {$} Battery Value:{$}", nID, nBatteryValue);
  2302. if (nBatteryValue < m_stDeviceConfig.nBatteryWarning)
  2303. {
  2304. //防止探测器电池电量状态异常跳变
  2305. SendBatteryValue(nBatteryValue);
  2306. }
  2307. else
  2308. {
  2309. SendBatteryValue(nBatteryValue);
  2310. }
  2311. break;
  2312. }
  2313. case EVT_STATUS_BATTERY_CHARGING:
  2314. {
  2315. string strTemp = pszMsg;
  2316. if (strTemp.find("true") != std::string::npos)
  2317. {
  2318. m_bBatteryCharging = true;
  2319. }
  2320. else
  2321. {
  2322. m_bBatteryCharging = false;
  2323. }
  2324. break;
  2325. }
  2326. case EVT_STATUS_SHOCK_SENSOR:
  2327. {
  2328. m_nShockCounts = nParam1;
  2329. //mLog::Info("Panel {$} Shock Sensor Number:{$}", nID, m_nShockCounts);
  2330. m_stDeviceConfig.nShockTimes = m_nShockCounts;
  2331. break;
  2332. }
  2333. case EVT_STATUS_HALL_SENSOR:
  2334. {
  2335. int nWorkstaion = nParam1;
  2336. //mLog::Info("Update Hall Status : {$} ", nWorkstaion);
  2337. //mLog::Info("Panel {$} WS:{$},Current OGP WS:{$} ", nID, nWorkstaion, m_nWorkStation);
  2338. m_stDeviceConfig.nWorkstation = nWorkstaion;
  2339. break;
  2340. }
  2341. case EVT_STATUS_PING:
  2342. {
  2343. break;
  2344. }
  2345. case EVT_STATUS_PMSNOTOPEN:
  2346. {
  2347. break;
  2348. }
  2349. case EVT_STATUS_RESTOREFILES:
  2350. {
  2351. break;
  2352. }
  2353. case EVT_STATUS_LASTERROR:
  2354. {
  2355. m_strLastError = pszMsg;
  2356. //mLog::Info("Panel {$} LastError {$}", nID, pszMsg);
  2357. break;
  2358. }
  2359. case EVT_STATUS_RESET:
  2360. {
  2361. break;
  2362. }
  2363. default:
  2364. {
  2365. break;
  2366. }
  2367. }
  2368. }
  2369. //保存RAW图数据
  2370. void nsFPD::FPDDeviceIRay::SaveRawImage(const char* pImgName, const WORD* pRawImg, int nWidth, int nHeight)
  2371. {
  2372. //mLog::Info("Begin SaveRawImage: {$}, width: {$}, height: {$}", pImgName, nWidth, nHeight);
  2373. if (pRawImg == NULL || pImgName == NULL)
  2374. {
  2375. //mLog::Error("Undefined parameter");
  2376. return;
  2377. }
  2378. string strImagePath = g_strAppPath + "Image\\" + pImgName;
  2379. FILE* fp;
  2380. if ((fp = fopen(strImagePath.c_str(), "wb")) == NULL)
  2381. {
  2382. DWORD dw = GetLastError();
  2383. //mLog::Error("fopen {$} failed, {$}", strImagePath.c_str(), dw);
  2384. return;
  2385. }
  2386. fwrite(pRawImg, sizeof(WORD), nWidth * nHeight, fp);
  2387. fclose(fp);
  2388. //mLog::Info("End SaveRawImage");
  2389. return;
  2390. }
  2391. void nsFPD::FPDDeviceIRay::OnEventProcessData(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  2392. {
  2393. switch (nEventID)
  2394. {
  2395. case EVT_DATA_RAW_IMAGE:
  2396. {
  2397. //mLog::Info("Image Arrved");
  2398. if (APP_STATUS_IDLE == m_eAppStatus)
  2399. {
  2400. //mLog::Error("Omit Image in Idle Status");
  2401. return;
  2402. }
  2403. float fImageReferUGY = 2.5;
  2404. memcpy(m_pwFullImageData, pParam, m_nFullImgWidth * m_nFullImgHeight * sizeof(WORD));
  2405. OnProcessImage(m_pwFullImageData, m_nFullImgWidth, m_nFullImgHeight, fImageReferUGY);
  2406. break;
  2407. }
  2408. case EVT_DATA_PREVIEW_IMAGE:
  2409. {
  2410. //mLog::Info("Preview Image Arrved");
  2411. m_SyncUnit->ImageReadingNotify();
  2412. if (NULL == m_pwPreviewImg)
  2413. {
  2414. m_pwPreviewImg = new WORD[m_stDeviceConfig.nPreviewWidth * m_stDeviceConfig.nPreviewHeight];
  2415. }
  2416. memcpy(m_pwPreviewImg, pParam, m_stDeviceConfig.nPreviewWidth * m_stDeviceConfig.nPreviewHeight * sizeof(WORD));
  2417. OnProcessPreviewImage(m_pwPreviewImg, m_stDeviceConfig.nPreviewWidth, m_stDeviceConfig.nPreviewHeight);
  2418. break;
  2419. }
  2420. case EVT_DATA_DOSEPARAM:
  2421. {
  2422. m_nDoseParam = nParam1;
  2423. //mLog::Info("calibration dose->{$}", nParam1);
  2424. SetEvent(m_WaitCalibDoseEvt);
  2425. break;
  2426. }
  2427. default:
  2428. {
  2429. break;
  2430. }
  2431. }
  2432. }
  2433. void nsFPD::FPDDeviceIRay::OnEventProcessError(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  2434. {
  2435. string strErrorName = "";
  2436. switch (nEventID)
  2437. {
  2438. case EVT_ERR_COMMUNICATE:
  2439. {
  2440. string strTemp = pszMsg;
  2441. if (strTemp.find("true") != std::string::npos)
  2442. {
  2443. m_stDeviceConfig.nWorkstation = -1;
  2444. m_stDeviceConfig.bConnectStatus = false;
  2445. m_stDeviceConfig.nCurrentWifiValue = 0;
  2446. m_stDeviceConfig.nCurrentBatteryValue = 0;
  2447. SendWifiValue(0);
  2448. SendBatteryValue(0);
  2449. //断开连接时温度保留当前值,清除温度相关告警信息
  2450. ProcessTempreatureOnLostCommunicate();
  2451. OnError(ERR_FPD_DISCONNECT, "");
  2452. m_DetectorCtrlUnit->SetConnectStatus(to_string(PANEL_CONNECT_ERROR));
  2453. }
  2454. else if (strTemp.find("false") != std::string::npos)//成功时交给WIFI发送SendDetectorInfo
  2455. {
  2456. if (m_stDeviceConfig.nCurrentWifiValue != -1)
  2457. {
  2458. SendWifiValue(m_stDeviceConfig.nCurrentWifiValue);
  2459. SendBatteryValue(m_stDeviceConfig.nCurrentBatteryValue);
  2460. SendTemperatureValue(m_stDeviceConfig.fCurrentTemperValue);
  2461. }
  2462. m_stDeviceConfig.bConnectStatus = true;
  2463. OnErrorX(ERR_FPD_DISCONNECT);
  2464. OnErrorX(ERR_FPD_ACQ_FAILED);
  2465. m_DetectorCtrlUnit->SetConnectStatus(to_string(PANEL_CONNECT_OK));
  2466. }
  2467. break;
  2468. }
  2469. case EVT_ERR_EXP_REQUEST:
  2470. {
  2471. string strTemp = pszMsg;
  2472. if (strTemp.find("true") != std::string::npos)
  2473. {
  2474. //SendCmd(nID, Sequence_C, L"FRM", String_C, _T("00040000")); //帧曝光失败
  2475. }
  2476. else
  2477. {
  2478. return;
  2479. }
  2480. strErrorName = ERR_FPD_ACQ_FAILED;
  2481. break;
  2482. }
  2483. case EVT_ERR_GET_IMAGE:
  2484. {
  2485. string strTemp = pszMsg;
  2486. if (strTemp.find("true") != std::string::npos)
  2487. {
  2488. if (APP_STATUS_WORK_BEGIN != m_eAppStatus) //如果不在检查界面;
  2489. {
  2490. //mLog::Fatal("there are image exist in current detector,do you want to continue");
  2491. }
  2492. else //if (m_bSiemensCmd)
  2493. {
  2494. //mLog::Fatal("FPD has exposed Image!");
  2495. CallSiemensRecoverAction(true);
  2496. }
  2497. //endif
  2498. }
  2499. else if (strTemp.find("false") != std::string::npos)
  2500. {
  2501. if (m_bRecoveringImage)
  2502. {
  2503. CallSiemensRecoverAction(false);
  2504. }
  2505. else
  2506. {
  2507. m_bAbortRecover = false; //终止恢复图像的变量也要重置
  2508. m_bRecoveringImage = false; //不再恢复图像过程中
  2509. m_nRecoverImageTimes = 0; //下次恢复图像,重置
  2510. m_bSendRecoverMessage = false; //下次恢复图像仍需判断;
  2511. }
  2512. }
  2513. break;
  2514. }
  2515. case EVT_ERR_MAX_NUMBER:
  2516. {
  2517. break;
  2518. }
  2519. case EVT_ERR_SN_NOTINLIST:
  2520. {
  2521. break;
  2522. }
  2523. case EVT_ERR_POWER_OFF:
  2524. {
  2525. strErrorName = ERR_FPD_DISCONNECT;
  2526. string strTemp = pszMsg;
  2527. if (strTemp.find("true") != std::string::npos)
  2528. {
  2529. ProcessTempreatureOnLostCommunicate();
  2530. OnError(strErrorName);
  2531. m_stDeviceConfig.bConnectStatus = false;
  2532. }
  2533. else if (strTemp.find("false") != std::string::npos)
  2534. {
  2535. OnErrorX(strErrorName);
  2536. }
  2537. break;
  2538. }
  2539. case EVT_ERR_INIT_FAILED:
  2540. {
  2541. break;
  2542. }
  2543. default:
  2544. {
  2545. break;
  2546. }
  2547. }
  2548. }
  2549. void nsFPD::FPDDeviceIRay::OnEventProcessWarning(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  2550. {
  2551. string strWarnName = "";
  2552. }
  2553. bool nsFPD::FPDDeviceIRay::OnInitResult(bool bSuccess)
  2554. {
  2555. if (bSuccess)
  2556. {
  2557. m_stDeviceConfig.bConnectStatus = true;
  2558. m_stDeviceConfig.bInitOK = true;
  2559. }
  2560. else
  2561. {
  2562. m_stDeviceConfig.bConnectStatus = false;
  2563. }
  2564. m_stDeviceConfig.bExisted = true;
  2565. auto temperuperror = m_stDeviceConfig.fTemperMaxLimit;
  2566. auto temperlowerror = m_stDeviceConfig.fTemperMinLimit;
  2567. auto temperupwarn = m_stDeviceConfig.fTemperUpLimit;
  2568. auto temperlowwarn = m_stDeviceConfig.fTemperLowLimit;
  2569. if (m_Temperature)
  2570. {
  2571. m_Temperature->SetTemperatureErrorMax(to_string(temperuperror));
  2572. m_Temperature->SetTemperatureWarningMax(to_string(temperupwarn));
  2573. m_Temperature->SetTemperatureCalibWarningMax(to_string(m_CalTemperupWarn));
  2574. m_Temperature->SetTemperatureCalibWarningMin(to_string(m_CalTemperlowWarn));
  2575. m_Temperature->SetTemperatureWarningMin(to_string(temperlowwarn));
  2576. m_Temperature->SetTemperatureErrorMin(to_string(temperlowerror));
  2577. }
  2578. auto wifiWarning = m_stDeviceConfig.nWifiWarning;
  2579. auto wifiError = m_stDeviceConfig.nWifiLimit;
  2580. if (m_Wifi)
  2581. {
  2582. m_Wifi->SetSignalWarningMin(to_string(wifiWarning));
  2583. m_Wifi->SetSignalErrorMin(to_string(wifiError));
  2584. }
  2585. return true;
  2586. }
  2587. //-----------------------------------------------------------------------------
  2588. //
  2589. // 函数名称 : CheckCalibartionDue
  2590. // 函数描述 : 检查校正文件是否过期
  2591. // 返回类型 : 过期true or false
  2592. // 接口参数 :
  2593. //
  2594. //-----------------------------------------------------------------------------
  2595. bool nsFPD::FPDDeviceIRay::CheckCalibartionDue()
  2596. {
  2597. //mLog::Info("[Checking Calibration Date]");
  2598. //mLog::Info("LastCalibrationDate: {$}, DueDay: {$}", m_stDeviceConfig.strLastCalibrationDate, m_stDeviceConfig.strCalibrationFileExpireTime);
  2599. if (!m_bNotifyCalWarn)
  2600. {
  2601. //mLog::Info("skip notify calibration");
  2602. return true;
  2603. }
  2604. //进检查时判断当前校正文件是否过期,如果即将过期或者已过期都向上通知
  2605. if (m_stDeviceConfig.strLastCalibrationDate == "0000-00-00 00:00:00")
  2606. {
  2607. //没有做过校正
  2608. //mLog::Warn("No calibration file, please make a calibration!");
  2609. m_WarnAndError->SendWarn(ERR_FPD_CAL_FILE_NOT_EXIST, "");
  2610. }
  2611. else
  2612. {
  2613. time_t lastCalibDate = StringToDatetime(m_stDeviceConfig.strLastCalibrationDate);
  2614. int nExpireTime = std::stoi(m_stDeviceConfig.strCalibrationFileExpireTime);//单位:天
  2615. //mLog::Info("nExpireTime:{$}", nExpireTime);
  2616. time_t localtime = time(NULL);
  2617. //判断是否过期
  2618. if (localtime > lastCalibDate + nExpireTime * 24 * 3600)
  2619. {
  2620. //过期了报错
  2621. //mLog::Warn("Calibration file is expired! please make a calibration!");
  2622. m_WarnAndError->SendWarn(ERR_FPD_CAL_FILE_OUTDATE, "");
  2623. }
  2624. }
  2625. return true;
  2626. }
  2627. bool nsFPD::FPDDeviceIRay::LoadSensitivity()
  2628. {
  2629. //mLog::Info("Load Sensitivity.txt");
  2630. string strTemp = m_stDeviceConfig.strPanelSerial + "_Sensitivity.txt";
  2631. string strPath = g_strAppPath + "references\\" + strTemp;
  2632. char* pszSensitivity = NULL;
  2633. FILE* pFile;
  2634. if ((pFile = fopen(strPath.c_str(), "rb")) == NULL)
  2635. {
  2636. //mLog::Info("Read {$} File Error", strPath.c_str());
  2637. return false;
  2638. }
  2639. //mLog::Info("Open {$} over", strPath.c_str());
  2640. fseek(pFile, 0, SEEK_END); ///将文件指针移动文件结尾
  2641. long nLen = ftell(pFile); ///求出当前文件指针距离文件开始的字节数
  2642. //mLog::Info("Length is :{$}", nLen);
  2643. pszSensitivity = new char[nLen + 1];
  2644. memset(pszSensitivity, 0, nLen + 1);
  2645. fseek(pFile, 0, SEEK_SET); ///将文件指针移动文件头
  2646. size_t rLen = fread(pszSensitivity, (size_t)1, nLen, pFile);
  2647. //mLog::Info("read Length is :{$} {$}", rLen, pszSensitivity);
  2648. if (rLen != nLen)
  2649. {
  2650. delete[] pszSensitivity;
  2651. fclose(pFile);
  2652. //mLog::Info("Read Sensitivity info Error");
  2653. return false;
  2654. }
  2655. fclose(pFile);
  2656. m_fFactorEXI2UGY = (float)atof(pszSensitivity);
  2657. auto strSensitivity = std::to_string(m_fFactorEXI2UGY);
  2658. m_DetectorCtrlUnit->SetFPDSensitivity(strSensitivity);
  2659. //mLog::Info("Sensitivity is :{$}", m_fFactorEXI2UGY);
  2660. if (pszSensitivity)
  2661. {
  2662. delete[] pszSensitivity;
  2663. pszSensitivity = NULL;
  2664. }
  2665. //mLog::Info("Read Sensitivity Over");
  2666. return true;
  2667. }
  2668. RET_STATUS nsFPD::FPDDeviceIRay::SaveSensitivity()
  2669. {
  2670. //mLog::Info("Save Sensitivity");
  2671. ResetEvent(m_WriteCumstomFileEvt);
  2672. int nRawImageWidth = m_stDeviceConfig.nFullImageWidth;
  2673. int nRawImageHeight = m_stDeviceConfig.nFullImageHeight;
  2674. float fTargetEXI = 250.0f;
  2675. float fDoes = 2.5f;
  2676. float fSysDoesOrAECDoes = 2.5f;
  2677. float fROIMean = 0.0f;
  2678. //mLog::Info("Calculate EXI Coef");
  2679. int nResult = GetCoef(m_pwRawImageData, nRawImageWidth, nRawImageHeight, fTargetEXI, fDoes, fSysDoesOrAECDoes, m_fFactorEXI2UGY, fROIMean);
  2680. //mLog::Info("EXI Coef :{$},ROI mean value:{$}", m_fFactorEXI2UGY, fROIMean);
  2681. if (m_pFullImageHead != NULL)
  2682. {
  2683. (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_EXI2UGY] = m_fFactorEXI2UGY;
  2684. }
  2685. else
  2686. {
  2687. MakeImageHead(IMAGE_FULL);
  2688. }
  2689. auto strSensitivity = std::to_string(m_fFactorEXI2UGY);
  2690. // char strSensitivity[10];
  2691. // sprintf(strSensitivity, "%f", m_fFactorEXI2UGY);
  2692. string strTemp = m_stDeviceConfig.strPanelSerial + "_Sensitivity.txt";
  2693. string strPath = g_strAppPath + "references\\" + strTemp;
  2694. FILE* pFile;
  2695. if ((pFile = fopen(strPath.c_str(), "wb")) == NULL)
  2696. {
  2697. //mLog::Info("Read {$} File Error", strPath.c_str());
  2698. return RET_STATUS::RET_FAILED;
  2699. }
  2700. fwrite(strSensitivity.c_str(), 1, strSensitivity.size(), pFile);
  2701. fclose(pFile);
  2702. //mLog::Info("Save Sensitivity Success");
  2703. m_DetectorCtrlUnit->SetFPDSensitivity(strSensitivity);
  2704. string strDesPath = g_strAppPath + "references\\CalibrationData\\" + strTemp;
  2705. //上传到探测器端 ;
  2706. m_pDetectors->CopyFile2Folder(strPath, strDesPath);
  2707. string strLog;
  2708. strDesPath = g_strAppPath + "references\\" + m_stDeviceConfig.strPanelSerial;
  2709. if (!PathFileExists(strDesPath.c_str()))
  2710. {
  2711. bool bRtn = CreateDirectory(strDesPath.c_str(), NULL);
  2712. if (bRtn)
  2713. {
  2714. strLog = "create " + strDesPath + " ok";
  2715. //mLog::Info("{$}", strLog.c_str());
  2716. }
  2717. else
  2718. {
  2719. strLog = "create " + strDesPath + " failed";
  2720. //mLog::Info("{$}", strLog.c_str());
  2721. }
  2722. }
  2723. else
  2724. {
  2725. strLog = strPath + " already exist";
  2726. //mLog::Info("{$}", strLog.c_str());
  2727. }
  2728. strDesPath = g_strAppPath + "references\\" + m_stDeviceConfig.strPanelSerial + "\\" + strTemp;
  2729. m_pDetectors->CopyFile2Folder(strPath, strDesPath);
  2730. SetEvent(m_WriteCumstomFileEvt);
  2731. return RET_STATUS::RET_SUCCEED;
  2732. }
  2733. //预览图
  2734. bool nsFPD::FPDDeviceIRay::OnProcessPreviewImage(WORD* pwRawImage, int nWidth, int nHeight)
  2735. {
  2736. //mLog::Info("Currenct PreviewImage Width: {$}, Height: {$}", nWidth, nHeight);
  2737. if (m_stDeviceConfig.nSaveRaw > 1)
  2738. {
  2739. SaveRawImage("PreviewImage.raw", pwRawImage, nWidth, nHeight);
  2740. }
  2741. PrevImageDateArrived(pwRawImage);
  2742. //mLog::Info("Write PreviewImage Over");
  2743. return true;
  2744. }
  2745. //大图
  2746. bool nsFPD::FPDDeviceIRay::OnProcessImage(WORD* pwRawImage, int nImageWidth, int nImageHeight, float fImageReferUGY)
  2747. {
  2748. //mLog::Info("Process Full Image");
  2749. //mLog::Info("Image EXI2UGY factor:{$},Image Refer UGY: {$}", m_fFactorEXI2UGY, fImageReferUGY);
  2750. //mLog::Info("Grid {$} Setting:{$}", m_bForceGridSuppress, m_stDeviceConfig.nGridSuppressed);
  2751. if (m_bTestSensitivity)
  2752. {
  2753. try
  2754. {
  2755. float fROIMeanCal = 0.0f;
  2756. int nResult = GetCenterROIEXI(pwRawImage, m_nFullImgWidth, m_nFullImgHeight, m_fFactorEXI2UGY, fROIMeanCal);
  2757. if (nResult > 0)
  2758. {
  2759. auto strNote = std::to_string(m_fFactorEXI2UGY);
  2760. m_DetectorCtrlUnit->SetFPDSensitivity(strNote);
  2761. m_DetectorCtrlUnit->SetFPDSensitivityResult("1");
  2762. }
  2763. else
  2764. {
  2765. m_DetectorCtrlUnit->SetFPDSensitivityResult("2");
  2766. //mLog::Info("Get ROI EXI error result {$}. Width {$}, Height {$}, FactorEXI2UGY {$}", nResult, m_nFullImgWidth, m_nFullImgHeight, m_fFactorEXI2UGY);
  2767. FILE* fp;
  2768. string strFileName = g_strAppPath + "DemoImage\\EXIfailed.raw";
  2769. if ((fp = fopen(strFileName.c_str(), "wb")) == NULL)
  2770. {
  2771. DWORD dw = GetLastError();
  2772. //mLog::Error("fopen {$} failed, {$}", strFileName.c_str(), dw);
  2773. }
  2774. else
  2775. {
  2776. fwrite(pwRawImage, sizeof(WORD), m_nFullImgWidth * m_nFullImgHeight, fp);
  2777. fclose(fp);
  2778. }
  2779. }
  2780. }
  2781. catch (...)
  2782. {
  2783. //mLog::Info("Exception occur when cal ROIEXI");
  2784. auto strNote = std::to_string(m_fFactorEXI2UGY);
  2785. m_DetectorCtrlUnit->SetFPDSensitivity(strNote);
  2786. }
  2787. }
  2788. pwRawImage[0] = 65535;
  2789. //图像预处理完成
  2790. FullImageDateArrived(pwRawImage);
  2791. //mLog::Info("Write Frame Over");
  2792. return true;
  2793. }
  2794. int nsFPD::FPDDeviceIRay::NewGridSuppressed(int nHeight, int nWidth, int nImageBits, unsigned short* puImageData)
  2795. {
  2796. return 0;
  2797. }
  2798. void nsFPD::FPDDeviceIRay::OnProcessTemperature(int nID, float fTemperature)
  2799. {
  2800. string strWarnErrorCode = "";
  2801. auto lowerror = m_stDeviceConfig.fTemperMinLimit;
  2802. auto uperror = m_stDeviceConfig.fTemperMaxLimit;
  2803. auto lowwarn = m_stDeviceConfig.fTemperLowLimit;
  2804. auto upwarn = m_stDeviceConfig.fTemperUpLimit;
  2805. auto calupwarn = m_CalTemperupWarn;
  2806. auto callowwarn = m_CalTemperlowWarn;
  2807. //should be lowerror < lowwarn < callowwarn < calupwarn < upwarn < uperror
  2808. m_stDeviceConfig.nTemperatureStatus = TEMP_NORMAL;
  2809. if (fTemperature > callowwarn && fTemperature < calupwarn)
  2810. {
  2811. //normal,clear all warns&errors
  2812. OnWarnX(WAR_FPD_TEMPERATURE_HIGH);
  2813. OnErrorX(ERR_FPD_TEMPERATURE_HIGH);
  2814. OnErrorX(ERR_FPD_TEMPERATURE_LOW);
  2815. }
  2816. else if ((fTemperature <= callowwarn && fTemperature > lowwarn)
  2817. || (fTemperature >= calupwarn && fTemperature < upwarn)
  2818. )
  2819. {//out of cal range
  2820. //mLog::Info("Exceed Calibration Temperature");
  2821. m_stDeviceConfig.nTemperatureStatus = TEMP_WARNING;
  2822. OnWarnX(WAR_FPD_TEMPERATURE_HIGH);
  2823. OnErrorX(ERR_FPD_TEMPERATURE_HIGH);
  2824. OnErrorX(ERR_FPD_TEMPERATURE_LOW);
  2825. //OnWarn(nID, strWarnErrorCode);
  2826. }
  2827. else if (fTemperature > lowerror && fTemperature <= lowwarn)
  2828. {//low warn
  2829. //mLog::Info("Exceed Temperature Low Warning");
  2830. m_stDeviceConfig.nTemperatureStatus = TEMP_WARNING;
  2831. OnWarnX(WAR_FPD_TEMPERATURE_HIGH);
  2832. OnErrorX(ERR_FPD_TEMPERATURE_HIGH);
  2833. OnErrorX(ERR_FPD_TEMPERATURE_LOW);
  2834. /*strWarnErrorCode = WAR_FPD_TEMPERTURE_LOW;
  2835. OnWarn(nID, strWarnErrorCode);*/
  2836. }
  2837. else if (fTemperature <= lowerror)
  2838. {//low error
  2839. //mLog::Info("Exceed Min Temperature");
  2840. m_stDeviceConfig.nTemperatureStatus = TEMP_TOO_LOW;
  2841. if (m_stDeviceConfig.bActived)
  2842. {
  2843. OnWarnX(WAR_FPD_TEMPERATURE_HIGH);
  2844. OnErrorX(ERR_FPD_TEMPERATURE_HIGH);
  2845. /*strWarnErrorCode = ERR_FPD_TEMPERATURE_LOW;
  2846. OnError(strWarnErrorCode);*/
  2847. }
  2848. }
  2849. else if (fTemperature >= upwarn && fTemperature < uperror)
  2850. {//up warn
  2851. //mLog::Info("Exceed Temperature High Warning");
  2852. m_stDeviceConfig.nTemperatureStatus = TEMP_WARNING;
  2853. OnErrorX(ERR_FPD_TEMPERATURE_HIGH);
  2854. OnErrorX(ERR_FPD_TEMPERATURE_LOW);
  2855. OnWarn(nID, WAR_FPD_TEMPERATURE_HIGH);
  2856. }
  2857. else if (fTemperature >= uperror)
  2858. {//up error
  2859. //mLog::Info("Exceed Max Temperature");
  2860. m_stDeviceConfig.nTemperatureStatus = TEMP_TOO_HIGH;
  2861. OnWarnX(WAR_FPD_TEMPERATURE_HIGH);
  2862. OnErrorX(ERR_FPD_TEMPERATURE_LOW);
  2863. OnError(ERR_FPD_TEMPERATURE_HIGH);
  2864. }
  2865. }
  2866. void nsFPD::FPDDeviceIRay::Action_ExpReady()
  2867. {
  2868. m_SyncUnit->FPDReadyNotify(true);
  2869. }
  2870. bool nsFPD::FPDDeviceIRay::GetCalibrationTime(bool ExpMode)
  2871. {
  2872. string strValue = "";
  2873. m_strCalibTime = strValue;
  2874. //mLog::Info("CalibrationTime {$}", m_strCalibTime.c_str());
  2875. return true;
  2876. }
  2877. bool nsFPD::FPDDeviceIRay::SaveConfigFile(bool bSendNotify)
  2878. {
  2879. m_DetectorConfiguration->SaveConfig();
  2880. //mLog::Info("SaveConfigFile over");
  2881. return true;
  2882. }
  2883. RET_STATUS nsFPD::FPDDeviceIRay::SetSID(int nSID)
  2884. {
  2885. if (nSID < 0 || nSID > 200)
  2886. {
  2887. return RET_STATUS::RET_INVALID;
  2888. }
  2889. m_stDeviceConfig.nSID = nSID;
  2890. return RET_STATUS::RET_SUCCEED;
  2891. }
  2892. RET_STATUS nsFPD::FPDDeviceIRay::UploadCalibrationFiles(string strFileName)
  2893. {
  2894. RET_STATUS Ret = RET_STATUS::RET_SUCCEED;
  2895. //mLog::Info("Update Calibration Defect map:{$}", strFileName.c_str());
  2896. bool bLTEenable = false;
  2897. if ((strFileName.find("defect_") == string::npos) || (strFileName.find(".dft") == string::npos))
  2898. {
  2899. //mLog::Info("the defect map is invalid");
  2900. m_CalibUnit->SetUploadCalibrationFilesResult("false");
  2901. return RET_STATUS::RET_FAILED;
  2902. }
  2903. m_pDetectors->SetLTEMode(bLTEenable);
  2904. m_stDeviceConfig.bTaskEnd = false;
  2905. ResetEvent(m_UploadCalibMapOver);
  2906. bool bRet = m_pDetectors->UploadCalibrationFiles(this, strFileName);
  2907. if (!bRet)
  2908. {
  2909. //mLog::Info("UploadCalibrationFiles failed");
  2910. m_CalibUnit->SetUploadCalibrationFilesResult("false");
  2911. return RET_STATUS::RET_FAILED;
  2912. }
  2913. DWORD nRet = WaitForSingleObject(m_UploadCalibMapOver, 60000);
  2914. if (WAIT_OBJECT_0 == nRet)
  2915. {
  2916. m_CalibUnit->SetUploadCalibrationFilesResult("true");
  2917. //mLog::Info("got event m_UploadCalibMapOver");
  2918. }
  2919. else if (WAIT_TIMEOUT == nRet)
  2920. {
  2921. m_CalibUnit->SetUploadCalibrationFilesResult("false");
  2922. //mLog::Info("wait event m_UploadCalibMapOver timeout");
  2923. return RET_STATUS::RET_FAILED;
  2924. }
  2925. else
  2926. {
  2927. m_CalibUnit->SetUploadCalibrationFilesResult("false");
  2928. //mLog::Info("wait event m_UploadCalibMapOver error");
  2929. return RET_STATUS::RET_FAILED;
  2930. }
  2931. if (!m_stDeviceConfig.bTaskEnd)
  2932. {
  2933. m_CalibUnit->SetUploadCalibrationFilesResult("false");
  2934. //mLog::Info("the FPD UploadCalibrationFiles failed");
  2935. return RET_STATUS::RET_FAILED;
  2936. }
  2937. return Ret;
  2938. }
  2939. RET_STATUS nsFPD::FPDDeviceIRay::GetRecoverImageState(string& RCI)
  2940. {
  2941. //mLog::Info("GetRecoverImageState");
  2942. m_bSendRecoverMessage = true;
  2943. RCI = m_RecoverImageStatus.encode();
  2944. return RET_STATUS::RET_SUCCEED;
  2945. }
  2946. RET_STATUS nsFPD::FPDDeviceIRay::RecoverImage(bool bRecoverIt)
  2947. {
  2948. //mLog::Info("Recover Image {$}", bRecoverIt);
  2949. m_bUIConfirmRecover = true;
  2950. int nRecoverOrNot = 0;
  2951. if (bRecoverIt)
  2952. {
  2953. nRecoverOrNot = 1;
  2954. }
  2955. if (nRecoverOrNot != 0)
  2956. {
  2957. string strResult = (string)m_RecoverImageStatus["Result"];
  2958. if (strResult == "0")
  2959. {
  2960. //mLog::Info("already recover success,just return");
  2961. return RET_STATUS::RET_SUCCEED;
  2962. }
  2963. m_RecoverImageStatus["Result"] = "1";
  2964. m_DetectorCtrlUnit->SetRecoverImageState(m_RecoverImageStatus.encode());
  2965. if (!(m_pDetectors)->RecoverLastImage())
  2966. {
  2967. m_RecoverImageStatus["Result"] = "2";
  2968. m_DetectorCtrlUnit->SetRecoverImageState(m_RecoverImageStatus.encode());
  2969. m_bUIConfirmRecover = false;
  2970. }
  2971. m_nRecoverImageTimes++;
  2972. }
  2973. else
  2974. {
  2975. //mLog::Info("Abort Recovering Image");
  2976. m_bAbortRecover = true; //终止恢复图像的变量也要重置
  2977. m_bRecoveringImage = false; //不再恢复图像过程中
  2978. m_nRecoverImageTimes = 0; //下次恢复图像,重置
  2979. m_bSendRecoverMessage = false; //下次恢复图像仍需判断;
  2980. m_pDetectors->CancelImageRecover();
  2981. if (m_stDeviceConfig.bConnectStatus)
  2982. {
  2983. if (m_bImagePendingOrNot)
  2984. {
  2985. OnError(ERR_FPD_IMAGE_PENDING);
  2986. }
  2987. else
  2988. {
  2989. OnErrorX(ERR_FPD_IMAGE_PENDING);
  2990. }
  2991. }
  2992. else
  2993. {
  2994. OnError(ERR_FPD_IMAGE_PENDING);
  2995. OnError(ERR_FPD_DISCONNECT);
  2996. }
  2997. }
  2998. return RET_STATUS::RET_SUCCEED;
  2999. }
  3000. bool nsFPD::FPDDeviceIRay::CallSiemensRecoverAction(bool bErrorResult)
  3001. {
  3002. string strRecoverInfo = "";
  3003. if (bErrorResult)
  3004. {
  3005. if (m_bAbortRecover)
  3006. {
  3007. //mLog::Info("Recover Image is Cancelled");
  3008. return true;
  3009. }
  3010. SendWifiValue(0);
  3011. SendBatteryValue(0);
  3012. SendTemperatureValue(ABS_ZERO_TEMPERATURE);
  3013. if (!m_bRecoveringImage)
  3014. {
  3015. m_RecoverImageStatus["Result"] = "-1";//新的imagerecover流程开始,防止之前成功recover过,上层查询状态引发误解
  3016. m_DetectorCtrlUnit->SetRecoverImageEvent("0");
  3017. OnError(ERR_FPD_IMAGE_PENDING);
  3018. m_bRecoveringImage = true;
  3019. m_bUIConfirmRecover = false;
  3020. m_DetectorCtrlUnit->SetRecoverImageState(m_RecoverImageStatus.encode());
  3021. //mLog::Info("SetRecoverImageEvent");
  3022. return true;
  3023. }
  3024. m_RecoverImageStatus["Result"] = "2";
  3025. }
  3026. else
  3027. {
  3028. m_bAbortRecover = false; //终止恢复图像的变量也要重置
  3029. m_bRecoveringImage = false; //不再恢复图像过程中
  3030. m_nRecoverImageTimes = 0; //下次恢复图像,重置
  3031. m_bSendRecoverMessage = false; //下次恢复图像仍需判断;
  3032. if (m_bUIConfirmRecover)
  3033. {
  3034. //mLog::Info("Recover Image Success");
  3035. m_RecoverImageStatus["Result"] = "0";
  3036. //mLog::Info("m_RecoverImageStatus[Result] = 0");
  3037. m_DetectorCtrlUnit->SetRecoverImageState(m_RecoverImageStatus.encode());
  3038. m_bUIConfirmRecover = false;
  3039. //mLog::Info("send RecoverImageState over");
  3040. }
  3041. else
  3042. {
  3043. m_RecoverImageStatus["Result"] = "3";
  3044. //mLog::Info("m_RecoverImageStatus[Result] = 3");
  3045. m_DetectorCtrlUnit->SetRecoverImageState(m_RecoverImageStatus.encode());
  3046. //mLog::Warn("UI do not confirm, image have been abandoned");
  3047. m_RecoverImageStatus["Result"] = "0";
  3048. m_AcqUnit->SendNoNeedWaitImage(true);
  3049. }
  3050. return true;
  3051. }
  3052. //mLog::Info("CallSiemensRecoverAction {$}", m_RecoverImageStatus.encode());
  3053. if (m_bSendRecoverMessage)
  3054. {
  3055. if (m_bUIConfirmRecover)
  3056. {
  3057. m_DetectorCtrlUnit->SetRecoverImageState(m_RecoverImageStatus.encode());
  3058. m_bUIConfirmRecover = false;
  3059. //mLog::Info("send RecoverImageState over");
  3060. }
  3061. else
  3062. {
  3063. //mLog::Warn("UI do not confirm omit send result");
  3064. }
  3065. }
  3066. return true;
  3067. }
  3068. RET_STATUS nsFPD::FPDDeviceIRay::GetDetectorInfo(string& strFDI)
  3069. {
  3070. ResDataObject strDetectorInfo;
  3071. string strTempTemp = " ";
  3072. //mLog::Info("Get Detector Info");
  3073. if (m_stDeviceConfig.strPanelSerial == "")
  3074. {
  3075. //mLog::Info("Get Detector Info Failed");
  3076. strDetectorInfo.add("DetectorName", "Simulator");
  3077. strDetectorInfo.add("DetectorSN", "Simulator");
  3078. strDetectorInfo.add("Firmware", " ");
  3079. strDetectorInfo.add("APFirmware", " ");
  3080. strDetectorInfo.add("Software", m_stDeviceConfig.strSoftware.c_str());
  3081. strDetectorInfo.add("SSID", " ");
  3082. strDetectorInfo.add("LifeTime", "0");
  3083. strDetectorInfo.add("PowerOn", "0");
  3084. strDetectorInfo.add("DateCode", " ");
  3085. strDetectorInfo.add("PartNumber", " ");
  3086. strDetectorInfo.add("WifiDataRate", " ");
  3087. strDetectorInfo.add("WifiChannel", "0");
  3088. strDetectorInfo.add("DetectorExist", "0");
  3089. strDetectorInfo.add("SystemAS", "0");
  3090. strDetectorInfo.add("CalibrationDate", "0");
  3091. strDetectorInfo.add("CalibrationDue", "0");
  3092. strDetectorInfo.add("CalibrationExist", "0");
  3093. strDetectorInfo.add("CommunicationStatus", "0");
  3094. strDetectorInfo.add("DetectorTemperature", "0");
  3095. strDetectorInfo.add("FDCalibrationTemperature", "0");
  3096. strDetectorInfo.add("TemperatureStatus", "0");
  3097. strDetectorInfo.add("WaitTime", "0");
  3098. strDetectorInfo.add("DetectorWifiSignal", "0");
  3099. strDetectorInfo.add("DetectorBattery", "0");
  3100. strDetectorInfo.add("ShockSensor", "NULL");
  3101. strDetectorInfo.add("FirmwareUpdate", "0");
  3102. //encode
  3103. strFDI = strDetectorInfo.encode();
  3104. return RET_STATUS::RET_SUCCEED;
  3105. }
  3106. strDetectorInfo.add("DetectorName", m_stDeviceConfig.strDeviceName.c_str());
  3107. strDetectorInfo.add("DetectorSN", m_stDeviceConfig.strPanelSerial.c_str());
  3108. strDetectorInfo.add("Firmware", m_stDeviceConfig.strFirmware.c_str());
  3109. strDetectorInfo.add("APFirmware", "NULL");
  3110. strDetectorInfo.add("Software", m_stDeviceConfig.strSoftware.c_str());
  3111. strDetectorInfo.add("SSID", m_stDeviceConfig.strWifiSSID.c_str());
  3112. strDetectorInfo.add("LifeTime", m_stDeviceConfig.nLifeTime);
  3113. strDetectorInfo.add("PowerOn", m_stDeviceConfig.nPowerOn);
  3114. if (m_strSelfTest != "")
  3115. {
  3116. ResDataObject strDetectorSelfTest;
  3117. strDetectorSelfTest.decode(m_strSelfTest.c_str());
  3118. strDetectorInfo += strDetectorSelfTest;
  3119. }
  3120. strDetectorInfo.add("FD_Voltage_List1", "NULL");
  3121. strDetectorInfo.add("DateCode", m_stDeviceConfig.strDateCode.c_str());
  3122. strDetectorInfo.add("PartNumber", m_stDeviceConfig.strPartNumber.c_str());
  3123. strDetectorInfo.add("WifiDataRate", m_stDeviceConfig.nWifiDataRate);
  3124. strDetectorInfo.add("WifiChannel", m_stDeviceConfig.nWifiChannel);
  3125. strDetectorInfo.add("DetectorExist", m_stDeviceConfig.bExisted);
  3126. //System Workstation
  3127. strDetectorInfo.add("SystemAS", m_stDeviceConfig.nWorkstation);
  3128. //DetectorCalibrationDate
  3129. //mLog::Info("DetectorCalibrationDate {$}", m_stDeviceConfig.strCalibrationDate.c_str());
  3130. if (m_stDeviceConfig.strCalibrationDate != " ")
  3131. {
  3132. if (m_stDeviceConfig.strCalibrationDate.find("19700101") != std::string::npos)
  3133. {
  3134. //mLog::Info("find 19700101");
  3135. strDetectorInfo.add("CalibrationDate", "0");
  3136. strDetectorInfo.add("CalibrationDue", "0");
  3137. strDetectorInfo.add("CalibrationExist", 0);
  3138. }
  3139. else
  3140. {
  3141. strDetectorInfo.add("CalibrationDate", m_stDeviceConfig.strCalibrationDate.c_str()/*"20210610"*/);
  3142. strDetectorInfo.add("CalibrationDue", m_stDeviceConfig.strCalibrationDue.c_str()/*"20210610"*/);
  3143. strDetectorInfo.add("CalibrationExist", 1);
  3144. }
  3145. }
  3146. else
  3147. {
  3148. strDetectorInfo.add("CalibrationDate", "0");
  3149. strDetectorInfo.add("CalibrationDue", "0");
  3150. strDetectorInfo.add("CalibrationExist", 0);
  3151. }
  3152. if (m_stDeviceConfig.bConnectStatus)
  3153. {
  3154. strDetectorInfo.add("CommunicationStatus", 1);
  3155. }
  3156. else
  3157. {
  3158. strDetectorInfo.add("CommunicationStatus", 0);
  3159. }
  3160. strDetectorInfo.add("FDCalibrationTemperature", m_stDeviceConfig.fCalibTemperature);
  3161. strDetectorInfo.add("ShockSensor", m_nShockCounts);
  3162. if (FW_MANDATORY_UPDATE == m_stDeviceConfig.nFirmwareStatus && m_stDeviceConfig.bConnectStatus) //需要升级
  3163. {
  3164. strDetectorInfo.add("FirmwareUpdate", 1);
  3165. }
  3166. else
  3167. {
  3168. strDetectorInfo.add("FirmwareUpdate", 0);
  3169. }
  3170. //mLog::Trace("{$}", strDetectorInfo.encode());
  3171. strFDI = strDetectorInfo.encode();
  3172. return RET_STATUS::RET_SUCCEED;
  3173. }
  3174. string nsFPD::FPDDeviceIRay::MakeImageHead(IMAGE_VIEW_TYPE Type)
  3175. {
  3176. if (Type == IMAGE_FULL)
  3177. {
  3178. if (m_pFullImageHead == NULL)
  3179. {
  3180. m_pFullImageHead = new ResDataObject;
  3181. ResDataObject json;
  3182. json.add(SM_IMAGE_TYPE, (int)Type);
  3183. json.add(SM_IMAGE_WIDTH, m_stDeviceConfig.nFullImageWidth);
  3184. json.add(SM_IMAGE_HEIGHT, m_stDeviceConfig.nFullImageHeight);
  3185. json.add(SM_IMAGE_BIT, 16);
  3186. json.add(SM_IMAGE_TAG, 1);
  3187. json.add(SM_IMAGE_INDEX, 1);
  3188. json.add(SM_IMAGE_YEAR, m_stImgCreateTime.wYear);
  3189. json.add(SM_IMAGE_MONTH, m_stImgCreateTime.wMonth);
  3190. json.add(SM_IMAGE_DAY, m_stImgCreateTime.wDay);
  3191. json.add(SM_IMAGE_HOUR, m_stImgCreateTime.wHour);
  3192. json.add(SM_IMAGE_MINUTE, m_stImgCreateTime.wMinute);
  3193. json.add(SM_IMAGE_SEC, m_stImgCreateTime.wSecond);
  3194. json.add(SM_IMAGE_MILLSEC, m_stImgCreateTime.wMilliseconds);
  3195. json.add(SM_IMAGE_LSB, "5000");
  3196. json.add(SM_IMAGE_DOSE, m_stDeviceConfig.nDoseOfEXI);
  3197. json.add(SM_IMAGE_PIXELREPRESENTATION, "0");
  3198. json.add(SM_IMAGE_PIXELSPACING, m_stDeviceConfig.nPixelSpace);
  3199. json.add(SM_IMAGE_ROTATION, "No");
  3200. json.add(SM_IMAGE_FLIP, "No");
  3201. json.add(SM_IMAGE_ORIGINX, "0");
  3202. json.add(SM_IMAGE_ORIGINY, "0");
  3203. json.add(SM_IMAGE_EXI2UGY, m_fFactorEXI2UGY);
  3204. json.add(SM_IMAGE_TEMP, m_stDeviceConfig.fCurrentTemperValue);
  3205. m_pFullImageHead->add(SM_IMAGE_HEAD, json);
  3206. }
  3207. else
  3208. {
  3209. (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_YEAR] = m_stImgCreateTime.wYear;
  3210. (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_MONTH] = m_stImgCreateTime.wMonth;
  3211. (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_DAY] = m_stImgCreateTime.wDay;
  3212. (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_HOUR] = m_stImgCreateTime.wHour;
  3213. (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_MINUTE] = m_stImgCreateTime.wMinute;
  3214. (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_SEC] = m_stImgCreateTime.wSecond;
  3215. (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_MILLSEC] = m_stImgCreateTime.wMilliseconds;
  3216. (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_TEMP] = m_stDeviceConfig.fCurrentTemperValue;
  3217. }
  3218. return (*m_pFullImageHead).encode();
  3219. }
  3220. else
  3221. {
  3222. if (m_pPreviewImageHead == NULL)
  3223. {
  3224. m_pPreviewImageHead = new ResDataObject;
  3225. ResDataObject json;
  3226. json.add(SM_IMAGE_TYPE, (int)Type);
  3227. json.add(SM_IMAGE_WIDTH, m_stDeviceConfig.nPreviewWidth);
  3228. json.add(SM_IMAGE_HEIGHT, m_stDeviceConfig.nPreviewHeight);
  3229. json.add(SM_IMAGE_BIT, 16);
  3230. json.add(SM_IMAGE_TAG, 1);
  3231. json.add(SM_IMAGE_INDEX, 1);
  3232. json.add(SM_IMAGE_YEAR, m_stImgCreateTime.wYear);
  3233. json.add(SM_IMAGE_MONTH, m_stImgCreateTime.wMonth);
  3234. json.add(SM_IMAGE_DAY, m_stImgCreateTime.wDay);
  3235. json.add(SM_IMAGE_HOUR, m_stImgCreateTime.wHour);
  3236. json.add(SM_IMAGE_MINUTE, m_stImgCreateTime.wMinute);
  3237. json.add(SM_IMAGE_SEC, m_stImgCreateTime.wSecond);
  3238. json.add(SM_IMAGE_MILLSEC, m_stImgCreateTime.wMilliseconds);
  3239. json.add(SM_IMAGE_LSB, "5000");
  3240. json.add(SM_IMAGE_DOSE, m_stDeviceConfig.nDoseOfEXI);
  3241. json.add(SM_IMAGE_ROTATION, "No");
  3242. json.add(SM_IMAGE_FLIP, "No");
  3243. json.add(SM_IMAGE_ORIGINX, "0");
  3244. json.add(SM_IMAGE_ORIGINY, "0");
  3245. json.add(SM_IMAGE_PIXELSPACING, m_stDeviceConfig.nPixelSpace);
  3246. json.add(SM_IMAGE_PIXELREPRESENTATION, "0");
  3247. json.add(SM_IMAGE_TEMP, m_stDeviceConfig.fCurrentTemperValue);
  3248. m_pPreviewImageHead->add(SM_IMAGE_HEAD, json);
  3249. }
  3250. else
  3251. {
  3252. (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_YEAR] = m_stImgCreateTime.wYear;
  3253. (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_MONTH] = m_stImgCreateTime.wMonth;
  3254. (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_DAY] = m_stImgCreateTime.wDay;
  3255. (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_HOUR] = m_stImgCreateTime.wHour;
  3256. (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_MINUTE] = m_stImgCreateTime.wMinute;
  3257. (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_SEC] = m_stImgCreateTime.wSecond;
  3258. (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_MILLSEC] = m_stImgCreateTime.wMilliseconds;
  3259. (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_TEMP] = m_stDeviceConfig.fCurrentTemperValue;
  3260. }
  3261. return (*m_pPreviewImageHead).encode();
  3262. }
  3263. return "";
  3264. }
  3265. RET_STATUS nsFPD::FPDDeviceIRay::AddFrameWithRawHead(IMAGE_VIEW_TYPE Type, WORD* pFrameBuff, DWORD FrameSize)
  3266. {
  3267. string strImageHead = MakeImageHead(Type);
  3268. return m_AcqUnit->AddFrameWithRawHead(Type, strImageHead, pFrameBuff, FrameSize);
  3269. }
  3270. void nsFPD::FPDDeviceIRay::ClearAllError()
  3271. {
  3272. m_WarnAndError->ClearAllError();
  3273. }
  3274. void nsFPD::FPDDeviceIRay::SyncErrorList()
  3275. {
  3276. m_WarnAndError->SendAllError();
  3277. m_WarnAndError->SendAllWarn();
  3278. }
  3279. void nsFPD::FPDDeviceIRay::OnErrorX(string strErrCode)
  3280. {
  3281. m_WarnAndError->ClearError(strErrCode);
  3282. }
  3283. void nsFPD::FPDDeviceIRay::OnError(string strErrCode, string strErr)
  3284. {
  3285. m_WarnAndError->SendError(strErrCode, strErr);
  3286. }
  3287. void nsFPD::FPDDeviceIRay::OnWarn(int nIndex, string strWarnCode, string strWarn)
  3288. {
  3289. m_WarnAndError->SendWarn(strWarnCode, strWarn);
  3290. }
  3291. void nsFPD::FPDDeviceIRay::OnWarnX(string strWarnCode)
  3292. {
  3293. m_WarnAndError->ClearWarn(strWarnCode);
  3294. }
  3295. RET_STATUS nsFPD::FPDDeviceIRay::ResetError()
  3296. {
  3297. //mLog::Info("ResetError");
  3298. OnErrorX(ERR_FPD_DOSE_LOW);
  3299. OnErrorX(ERR_FPD_DOSE_HIGH);
  3300. OnErrorX(ERR_FPD_DOSE_OBJ); //清除之前的错误,如果有的话
  3301. return RET_STATUS::RET_SUCCEED;
  3302. }
  3303. void nsFPD::FPDDeviceIRay::SendAllError()
  3304. {
  3305. m_WarnAndError->SendAllError();
  3306. }
  3307. void nsFPD::FPDDeviceIRay::ProcessTempreatureOnLostCommunicate()
  3308. {
  3309. SendTemperatureValue(ABS_ZERO_TEMPERATURE);
  3310. OnWarnX(WAR_FPD_TEMPERATURE_HIGH);
  3311. OnErrorX(ERR_FPD_TEMPERATURE_HIGH);
  3312. OnErrorX(ERR_FPD_TEMPERATURE_LOW);
  3313. OnWarnX(WAR_FPD_WIFI_LOW);
  3314. OnWarnX(WAR_FPD_BATTERY_LOW);
  3315. OnErrorX(ERR_FPD_WIFI_LOW);
  3316. OnErrorX(ERR_FPD_BATTERY_LOW);
  3317. }
  3318. void nsFPD::FPDDeviceIRay::ResetAllError()
  3319. {
  3320. OnWarnX(WAR_FPD_TEMPERATURE_HIGH);
  3321. OnErrorX(ERR_FPD_TEMPERATURE_HIGH);
  3322. OnErrorX(ERR_FPD_TEMPERATURE_LOW);
  3323. OnWarnX(WAR_FPD_WIFI_LOW);
  3324. OnWarnX(WAR_FPD_BATTERY_LOW);
  3325. OnErrorX(ERR_FPD_WIFI_LOW);
  3326. OnErrorX(ERR_FPD_BATTERY_LOW);
  3327. OnErrorX(ERR_FPD_DISCONNECT);
  3328. OnErrorX(ERR_FPD_DISCONNECT);
  3329. OnErrorX(ERR_FPD_ACQ_FAILED);
  3330. OnErrorX(ERR_FPD_DOSE_LOW);
  3331. OnErrorX(ERR_FPD_DOSE_HIGH);
  3332. OnErrorX(ERR_FPD_DOSE_OBJ);
  3333. OnErrorX(ERR_FPD_IMAGE_PENDING);
  3334. }
  3335. RET_STATUS nsFPD::FPDDeviceIRay::SetCorrectionType(CCOS_CORRECTION_TYPE in)
  3336. {
  3337. return RET_STATUS::RET_SUCCEED;
  3338. }
  3339. //设置同步模式
  3340. RET_STATUS nsFPD::FPDDeviceIRay::ActiveSyncMode(int nSyncMode)
  3341. {
  3342. //mLog::Info("=====ActiveSyncMode: {$}", nSyncMode);
  3343. if (!m_stDeviceConfig.bConnectStatus)
  3344. {
  3345. return RET_STATUS::RET_FAILED;
  3346. }
  3347. RET_STATUS Ret = RET_STATUS::RET_FAILED;
  3348. if (m_pDetectors->ActiveSyncMode(this, nSyncMode))
  3349. {
  3350. Ret = RET_STATUS::RET_SUCCEED;
  3351. //mLog::Info("ActiveSyncMode success");
  3352. }
  3353. return Ret;
  3354. }
  3355. RET_STATUS nsFPD::FPDDeviceIRay::UpdateNotifyStatusTimePeriod(int nTime)
  3356. {
  3357. //mLog::Info("=====UpdateNotifyStatusTimePeriod: {$}", nTime);
  3358. if (!m_stDeviceConfig.bConnectStatus)
  3359. {
  3360. return RET_STATUS::RET_FAILED;
  3361. }
  3362. m_pDetectors->m_nStatusPeriod = nTime;
  3363. return RET_STATUS::RET_SUCCEED;
  3364. }