DIOS.Dev.FPD.TrixellDR.cpp 100 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271
  1. #include "stdafx.h"
  2. #include "CCOS.Dev.FPD.TrixellDR.h"
  3. #include "TrixellCtrl.h"
  4. #include "common_api.h"
  5. #include "FileVersion.hpp"
  6. #include "GridSuppression.h"
  7. #include "DICOMImageHeadKey.h"
  8. #pragma comment(lib, "Version.lib")
  9. namespace nsFPD = CCOS::Dev::Detail::Detector;
  10. static nsFPD::TrixellDriver gIODriver;
  11. Log4CPP::Logger* gLogger = nullptr;
  12. extern const char* g_szMouldPath;
  13. extern "C" CCOS::Dev::IODriver * __cdecl GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
  14. {
  15. return &gIODriver;
  16. }
  17. extern "C" CCOS::Dev::IODriver * __cdecl CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
  18. {
  19. return new nsFPD::TrixellDriver();
  20. }
  21. nsFPD::TrixellDriver::TrixellDriver()
  22. {
  23. pObjDev = nullptr;
  24. m_bConnect = false; //缺省为false
  25. m_pAttribute.reset(new ResDataObject());
  26. m_pDescription.reset(new ResDataObject());
  27. }
  28. nsFPD::TrixellDriver::~TrixellDriver()
  29. {
  30. if (nullptr != pObjDev)
  31. {
  32. delete pObjDev;
  33. pObjDev = nullptr;
  34. }
  35. }
  36. /***
  37. ** 类似于重构前的DriverEntry(),多板时会顺序调用每个平板dpc的这个接口
  38. ** 之后的接口调用上层是多线程执行的,不能保证先后顺序
  39. ***/
  40. void nsFPD::TrixellDriver::Prepare()
  41. {
  42. /*string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Detector\Conf\Log4CPP.Config.FPD.xml)";
  43. Log4CPP::GlobalContext::Map::Set(ZSKK::Utility::Hash("LogFileName"), "FPD.TrixellDR");
  44. auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
  45. gLogger = Log4CPP::LogManager::GetLogger("FPD.TrixellDR");*/
  46. string strLogPath = GetProcessDirectory() + R"(\Conf\Log4CPP.Config.xml)";
  47. auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
  48. gLogger = Log4CPP::LogManager::GetLogger("Module");
  49. #ifdef _WIN64
  50. Force("=============================Version: {$} (64-bit)==================================", FileVersion(g_szMouldPath).GetVersionString());
  51. #else
  52. Force("=============================Version: {$} (32-bit)==================================", FileVersion(g_szMouldPath).GetVersionString());
  53. #endif
  54. pObjDev = new FPDDeviceTrixell(EventCenter, m_ConfigFileName);
  55. pObjDev->CreateDevice();
  56. pObjDev->Register();
  57. Info("driver prepare over");
  58. }
  59. bool nsFPD::TrixellDriver::Connect()
  60. {
  61. Info("--Func-- driver connect");
  62. m_bConnect = pObjDev->m_stDeviceConfig.bConnectStatus;
  63. return m_bConnect;
  64. }
  65. void nsFPD::TrixellDriver::Disconnect()
  66. {
  67. Info("--Func-- driver disconnect");
  68. m_bConnect = false;
  69. }
  70. bool nsFPD::TrixellDriver::isConnected() const
  71. {
  72. return m_bConnect;
  73. }
  74. auto nsFPD::TrixellDriver::CreateDevice(int index)->std::unique_ptr <IODevice>
  75. {
  76. Info("--Func-- driver createdevice");
  77. auto Device = std::unique_ptr<IODevice>(new IODevice(pObjDev));
  78. return Device;
  79. }
  80. std::string nsFPD::TrixellDriver::DriverProbe()
  81. {
  82. Trace("--Func-- Driver Probe");
  83. ResDataObject r_config, HardwareInfo;
  84. if (r_config.loadFile(m_ConfigFileName.c_str()))
  85. {
  86. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  87. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  88. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  89. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  90. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  91. }
  92. else
  93. {
  94. HardwareInfo.add("MajorID", "Detector");
  95. HardwareInfo.add("MinorID", "DR");
  96. HardwareInfo.add("VendorID", "Trixell");
  97. HardwareInfo.add("ProductID", "Trixell");
  98. HardwareInfo.add("SerialID", "Driver");
  99. }
  100. string str = HardwareInfo.encode();
  101. return str;
  102. }
  103. /***
  104. ** 获取ID和配置
  105. ***/
  106. std::string nsFPD::TrixellDriver::GetResource()
  107. {
  108. ResDataObject r_config, temp;
  109. if (!temp.loadFile(m_ConfigFileName.c_str()))
  110. {
  111. return "";
  112. }
  113. m_ConfigAll = temp;
  114. r_config = temp["CONFIGURATION"];
  115. m_Configurations = r_config;
  116. ResDataObject DescriptionTemp;
  117. ResDataObject ListTemp;
  118. string strTemp = ""; //用于读取字符串配置信息
  119. string strIndex = ""; //用于读取配置信息中的List项
  120. int nTemp = -1; //用于读取整型配置信息
  121. char sstream[10] = { 0 }; //用于转换值
  122. string strValue = ""; //用于存储配置的值
  123. string strType = ""; //用于存储配置的类型 int/float/string...
  124. /***
  125. * 1. 通过循环,将所有配置项写到pDeviceConfig
  126. * 2. 记录配置项的内部key以及配置类型,类型对应了不同配置文件路径,用于读写真实值
  127. ***/
  128. try
  129. {
  130. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  131. //Info(g_pFPDCtrlLog, "ConfigInfo Count: {$}", nConfigInfoCount);
  132. m_pAttribute->clear();
  133. m_pDescription->clear();
  134. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  135. {
  136. DescriptionTemp.clear();
  137. ListTemp.clear();
  138. //AttributeType
  139. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Type"];
  140. DescriptionTemp.add(AttributeType, strTemp.c_str());
  141. //Info(g_pFPDCtrlLog, "--> {$}: {$}", AttributeType, strTemp.c_str());
  142. strType = strTemp; //记录配置项的类型
  143. //AttributeKey
  144. //1. 根据AttributeType,内部key和配置路径,拿到当前的真实值
  145. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  146. nTemp = (int)m_Configurations["ConfigToolInfo"][nInfoIndex]["PathID"];
  147. GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue);
  148. //2. 赋值
  149. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  150. if ("int" == strType)
  151. {
  152. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  153. //Info(g_pFPDCtrlLog, "Key {$}: {$}", strTemp.c_str(), atoi(strValue.c_str()));
  154. }
  155. else if ("float" == strType)
  156. {
  157. (*m_pAttribute).add(strTemp.c_str(), atof(strValue.c_str()));
  158. //Info(g_pFPDCtrlLog, "Key {$}: {$}", strTemp.c_str(), atof(strValue.c_str()));
  159. }
  160. else //其它先按string类型处理
  161. {
  162. (*m_pAttribute).add(strTemp.c_str(), strValue.c_str());
  163. //Info(g_pFPDCtrlLog, "Key {$}: {$}", strTemp.c_str(), strValue.c_str());
  164. }
  165. //AttributeAccess
  166. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Access"];
  167. DescriptionTemp.add(AttributeAccess, strTemp.c_str());
  168. //Info(g_pFPDCtrlLog, "{$}: {$}", AttributeAccess, strTemp.c_str());
  169. //AttributeRangeMin
  170. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMin"];
  171. if (strTemp != "") //不需要的配置项为空
  172. {
  173. DescriptionTemp.add(AttributeRangeMin, strTemp.c_str());
  174. //Info(g_pFPDCtrlLog, "{$}: {$}", AttributeRangeMin, strTemp.c_str());
  175. }
  176. //AttributeRangeMax
  177. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMax"];
  178. if (strTemp != "") //不需要的配置项为空
  179. {
  180. DescriptionTemp.add(AttributeRangeMax, strTemp.c_str());
  181. //Info(g_pFPDCtrlLog, "{$}: {$}", AttributeRangeMax, strTemp.c_str());
  182. }
  183. //AttributeList
  184. nTemp = m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListNum"];
  185. if (nTemp > 0) //ListNum不大于0时说明不需要list配置
  186. {
  187. for (int nListIndex = 0; nListIndex < nTemp; nListIndex++)
  188. {
  189. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListInfo"][nListIndex];
  190. //sprintf_s(sstream, "{$}", nListIndex);
  191. auto temKey = std::to_string(nListIndex);
  192. ListTemp.add(temKey.c_str(), strTemp.c_str());
  193. //Info(g_pFPDCtrlLog, "list {$}: {$}", nListIndex, strTemp.c_str());
  194. }
  195. DescriptionTemp.add(AttributeList, ListTemp);
  196. }
  197. //AttributeRequired
  198. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Required"];
  199. DescriptionTemp.add(AttributeRequired, strTemp.c_str());
  200. //Info(g_pFPDCtrlLog, "{$}: {$}", AttributeRequired, strTemp.c_str());
  201. //AttributeDefaultValue
  202. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["DefaultValue"];
  203. if (strTemp != "") //不需要的配置项为空
  204. {
  205. DescriptionTemp.add(AttributeDefaultValue, strTemp.c_str());
  206. //Info(g_pFPDCtrlLog, "{$}: {$}", AttributeDefaultValue, strTemp.c_str());
  207. }
  208. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  209. (*m_pDescription).add(strTemp.c_str(), DescriptionTemp);
  210. }
  211. }
  212. catch (ResDataObjectExption& e)
  213. {
  214. Error("Get config error: {$}", e.what());
  215. return "";
  216. }
  217. ResDataObject resDeviceResource;
  218. resDeviceResource.add(ConfKey::CcosDetectorAttribute, (*m_pAttribute));
  219. resDeviceResource.add(ConfKey::CcosDetectorDescription, (*m_pDescription));
  220. ResDataObject DescriptionTempEx;
  221. DescriptionTempEx.add(ConfKey::CcosDetectorConfig, resDeviceResource);
  222. m_DeviceConfig.clear();
  223. m_DeviceConfig = DescriptionTempEx;
  224. string res = DescriptionTempEx.encode();
  225. Trace("get resource over {$}", DescriptionTempEx.encode());
  226. return res;
  227. }
  228. std::string nsFPD::TrixellDriver::DeviceProbe()
  229. {
  230. Trace("--Func-- Device Probe");
  231. ResDataObject r_config, HardwareInfo;
  232. if (r_config.loadFile(m_ConfigFileName.c_str()))
  233. {
  234. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  235. HardwareInfo.add("MinorID", "Device");
  236. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  237. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  238. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  239. }
  240. else
  241. {
  242. HardwareInfo.add("MajorID", "Detector");
  243. HardwareInfo.add("MinorID", "Device");
  244. HardwareInfo.add("VendorID", "Trixell");
  245. HardwareInfo.add("ProductID", "Trixell");
  246. HardwareInfo.add("SerialID", "1234");
  247. }
  248. string str = HardwareInfo.encode();
  249. return str;
  250. }
  251. bool nsFPD::TrixellDriver::GetDeviceConfig(std::string& Cfg)
  252. {
  253. Cfg = m_DeviceConfig.encode();
  254. Info("GetDeviceConfig over");
  255. return true;
  256. }
  257. bool nsFPD::TrixellDriver::SetDeviceConfig(std::string Cfg)
  258. {
  259. Info("--Func-- SetDeviceConfig {$}\n", Cfg.c_str());
  260. ResDataObject DeviceConfig;
  261. DeviceConfig.decode(Cfg.c_str());
  262. ResDataObject DescriptionTempEx;
  263. DescriptionTempEx = DeviceConfig["DeviceConfig"]["Attribute"];
  264. Trace("Attribute:{$}", DescriptionTempEx.encode());
  265. bool bSaveFile = false; //true:重新保存配置文件
  266. string strAccess = "";
  267. for (int i = 0; i < DescriptionTempEx.size(); i++)
  268. {
  269. string strKey = DescriptionTempEx.GetKey(i);
  270. Info("{$}", strKey.c_str());
  271. try
  272. {
  273. if (m_pAttribute->GetFirstOf(strKey.c_str()) >= 0)
  274. {
  275. strAccess = (string)(*m_pDescription)[strKey.c_str()]["Access"];
  276. if ("RW" == strAccess)
  277. {
  278. //修改对应配置,在其他单元的配置项要同时调用其修改函数修改真实值
  279. //1. 修改内存中的值,用于给上层发消息
  280. (*m_pAttribute)[strKey.c_str()] = DescriptionTempEx[i];
  281. //2. 拿到Innerkey
  282. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  283. Info("nConfigInfoCount {$}", nConfigInfoCount);
  284. string strTemp = ""; //存储AttributeKey
  285. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  286. {
  287. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  288. if (strTemp == strKey)
  289. {
  290. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  291. break;
  292. }
  293. }
  294. //3. 修改配置文件中的值
  295. if (SetDeviceConfigValue(m_Configurations, strTemp.c_str(), 1, DescriptionTempEx[i]))
  296. {
  297. Trace("SetDeviceConfigValue over");
  298. bSaveFile = true;
  299. }
  300. }
  301. else
  302. {
  303. Info("{$} is not a RW configuration item", strKey.c_str());
  304. }
  305. }
  306. else
  307. {
  308. Info("without this attribute {$}", strKey.c_str());
  309. }
  310. }
  311. catch (ResDataObjectExption& e)
  312. {
  313. Error("SetDriverConfig crashed: {$}", e.what());
  314. return false;
  315. }
  316. }
  317. if (bSaveFile)
  318. {
  319. //3. 重新保存配置文件
  320. SaveConfigFile(true);
  321. }
  322. return true;
  323. }
  324. bool nsFPD::TrixellDriver::SaveConfigFile(bool bSendNotify)
  325. {
  326. m_ConfigAll["CONFIGURATION"] = m_Configurations;
  327. bool bRt = m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
  328. Info("SaveConfigFile over {$}", bRt);
  329. return true;
  330. }
  331. bool nsFPD::TrixellDriver::GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue)
  332. {
  333. strValue = "";
  334. string strTemp = pInnerKey;
  335. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  336. {
  337. if (WiredIP == strTemp || WirelessIP == strTemp || LocalIP == strTemp)
  338. {
  339. strValue = (string)config["connections"][pInnerKey];
  340. }
  341. else if (DetectorVender == strTemp || DetectorModel == strTemp ||
  342. DetectorDescription == strTemp || DetectorSerialNumber == strTemp)
  343. {
  344. strValue = (string)config[pInnerKey];
  345. }
  346. else if (SyncType == strTemp || FPDWorkStation == strTemp ||
  347. ImageWidth == strTemp || ImageHeight == strTemp)
  348. {
  349. strValue = (string)config["ModeTable"]["DetectorMode"][pInnerKey];
  350. }
  351. else if (TempMaxLimit == strTemp || ReConnect == strTemp ||
  352. TempUpperLimit == strTemp || TempLowerLimit == strTemp || TempMinLimit == strTemp ||
  353. BatLowerLimit == strTemp || BatMiniLimit == strTemp ||
  354. BatLowerLimitInCali == strTemp || WifiLowerLimit == strTemp ||
  355. WifiMiniLimit == strTemp || HighPowerTimeout == strTemp ||
  356. ShowTemperature == strTemp || ShowWifi == strTemp ||
  357. ShowBattery == strTemp || ShowBluetooth == strTemp ||
  358. FPDExamMode == strTemp || FPDAcqMode == strTemp || FPDModeMatch == strTemp || CcosDetectorAttachedFlag == strTemp)
  359. {
  360. strValue = (string)config[pInnerKey];
  361. }
  362. else
  363. {
  364. strValue = "";
  365. Warn("Error Configuration item: {$}", pInnerKey);
  366. }
  367. }
  368. return true;
  369. }
  370. bool nsFPD::TrixellDriver::SetDeviceConfigValue(ResDataObject & config, const char* pInnerKey, int nPathID, const char* szValue)
  371. {
  372. string strTemp = pInnerKey;
  373. Trace("Begin to change {$} item value to {$}", pInnerKey, szValue);
  374. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  375. {
  376. try {
  377. if (WiredIP == strTemp || WirelessIP == strTemp || LocalIP == strTemp)
  378. {
  379. config["connections"][pInnerKey] = szValue;
  380. }
  381. else if (DetectorVender == strTemp || DetectorModel == strTemp ||
  382. DetectorDescription == strTemp || DetectorSerialNumber == strTemp)
  383. {
  384. config[pInnerKey] = szValue;
  385. }
  386. else if (SyncType == strTemp || FPDWorkStation == strTemp ||
  387. ImageWidth == strTemp || ImageHeight == strTemp)
  388. {
  389. config["ModeTable"]["DetectorMode"][pInnerKey] = szValue;
  390. }
  391. else if (TempMaxLimit == strTemp || ReConnect == strTemp ||
  392. TempUpperLimit == strTemp || TempLowerLimit == strTemp ||
  393. BatLowerLimit == strTemp || BatMiniLimit == strTemp ||
  394. BatLowerLimitInCali == strTemp || WifiLowerLimit == strTemp ||
  395. WifiMiniLimit == strTemp || HighPowerTimeout == strTemp ||
  396. ShowTemperature == strTemp || ShowWifi == strTemp ||
  397. ShowBattery == strTemp || ShowBluetooth == strTemp ||
  398. FPDExamMode == strTemp || FPDAcqMode == strTemp || FPDModeMatch == strTemp)
  399. {
  400. config[pInnerKey] = szValue;
  401. }
  402. else
  403. {
  404. Warn("Error Configuration item: {$}", pInnerKey);
  405. return false;
  406. }
  407. }
  408. catch (ResDataObjectExption& e)
  409. {
  410. Error("SetDriverConfigvalue crashed: {$}", e.what());
  411. return false;
  412. }
  413. }
  414. return true;
  415. }
  416. //-----------------------------------------------------------------------------
  417. // FPDDeviceTrixell
  418. //-----------------------------------------------------------------------------
  419. extern TrixellCtrl* g_pDetector;
  420. nsFPD::FPDDeviceTrixell::FPDDeviceTrixell(std::shared_ptr<IOEventCenter> center, std::string strConfigPath)
  421. : m_hNotifyThread(nullptr)
  422. , m_NotifyThreadID(0)
  423. , m_nDeviceIndex(-1)
  424. , m_eAppStatus(APP_STATUS_IDLE)
  425. , m_strLastError("")
  426. , m_bBatteryCharging(false)
  427. , m_bImagePendingOrNot(false)
  428. , m_bResetDetector(false)
  429. , m_nCalibTotalExposureNum(0)
  430. , m_nCalibCurrentCalibrationRound(0)
  431. , m_nCalibCurrentExposureIndex(0)
  432. , m_nCalibCurrentExposureNum(0)
  433. , m_bNotifyCalWarn(true)
  434. {
  435. m_pDetectors = nullptr;
  436. m_strWorkPath = GetProcessDirectory();
  437. m_AcqUnit.reset(new OemAcq(center, this));
  438. m_SyncUnit.reset(new OemSync(center, this));
  439. m_CalibUnit.reset(new OemCalib(center, this));
  440. m_DetectorCtrlUnit.reset(new OemCtrl(center, this));
  441. m_DetectorConfiguration.reset(new DetectorConfiguration(strConfigPath));
  442. m_WarnAndError.reset(new FPDErrorWarning(center, DetectorUnitType, m_strWorkPath + "\\OEMDrivers\\Detector\\Trixell\\TrixellDRDetector"));
  443. //m_CalibProcess.reset(new CalibrationProcess());
  444. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_SHUTDOWN));
  445. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY));
  446. m_WaitCalibDoseEvt = CreateEvent(NULL, FALSE, FALSE, NULL);
  447. m_PauseCalibrationEvt = CreateEvent(NULL, FALSE, FALSE, NULL);
  448. m_ExitEvt = CreateEvent(NULL, FALSE, FALSE, NULL);
  449. m_ConnectEvt = CreateEvent(NULL, FALSE, FALSE, NULL);
  450. EventCenter = center;
  451. }
  452. nsFPD::FPDDeviceTrixell::~FPDDeviceTrixell()
  453. {
  454. SetEvent(m_ExitEvt);
  455. if (m_PauseCalibrationEvt)
  456. {
  457. CloseHandle(m_PauseCalibrationEvt);
  458. m_PauseCalibrationEvt = nullptr;
  459. }
  460. if (m_ExitEvt)
  461. {
  462. CloseHandle(m_ExitEvt);
  463. m_ExitEvt = nullptr;
  464. }
  465. if (m_ConnectEvt)
  466. {
  467. CloseHandle(m_ConnectEvt);
  468. m_ConnectEvt = nullptr;
  469. }
  470. if (m_WaitCalibDoseEvt)
  471. {
  472. CloseHandle(m_WaitCalibDoseEvt);
  473. m_WaitCalibDoseEvt = nullptr;
  474. }
  475. }
  476. std::string nsFPD::FPDDeviceTrixell::GetGUID() const
  477. {
  478. return DetectorUnitType;
  479. }
  480. bool nsFPD::FPDDeviceTrixell::Prepare()
  481. {
  482. Info("--Func-- device prepare \n");
  483. EventCenter->OnMaxBlockSize("DrQue",m_stDeviceConfig.nFullImageWidth * m_stDeviceConfig.nFullImageHeight * 2, 3,
  484. m_stDeviceConfig.nPreviewWidth * m_stDeviceConfig.nPreviewHeight * 2, 1);
  485. m_hNotifyThread = CreateThread(0, 0, OnNotify, this, 0, &m_NotifyThreadID);
  486. if (m_hNotifyThread == NULL)
  487. {
  488. Info("Start Process Thread Failed!");
  489. }
  490. else
  491. {
  492. Info("Start Process Thread End");
  493. }
  494. SetEvent(m_ConnectEvt); //Connect();
  495. return true;
  496. }
  497. void nsFPD::FPDDeviceTrixell::RegisterCtrl(nsDetail::Dispatch* Dispatch)
  498. {
  499. Dispatch->Get.Push("DetectorConnectStatus", m_DetectorCtrlUnit.get (), &DetectorCtrlUnit::JSGetConnectStatus);
  500. Dispatch->Get.Push("DetectorInitialStatus", m_DetectorCtrlUnit.get (), &DetectorCtrlUnit::JSGetInitialStatus);
  501. Dispatch->Get.Push("DetectorUpdateFWStatus", m_DetectorCtrlUnit.get (), &DetectorCtrlUnit::JSGetUpdateFWStatus);
  502. Dispatch->Get.Push("FPDShockSensorInfo", m_DetectorCtrlUnit.get (), &DetectorCtrlUnit::JSGetShockSensorInfo);
  503. Dispatch->Get.Push("DetectorStatus", m_DetectorCtrlUnit.get (), &DetectorCtrlUnit::JSGetFPDStatus);
  504. Dispatch->Get.Push("FPDAttached", m_DetectorCtrlUnit.get (), &DetectorCtrlUnit::JSGetAttachStatus);
  505. Dispatch->Get.Push("DetectorAttach", m_DetectorCtrlUnit.get (), &DetectorCtrlUnit::JSGetAttachResult);//event
  506. Dispatch->Get.Push("RecoverImageState", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetRecoverImageState);//event
  507. Dispatch->Get.Push("RecoverImageEvent", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetRecoverImageEvent);//event
  508. Dispatch->Get.Push("FieldofViewShape", m_DetectorCtrlUnit.get (), &DetectorCtrlUnit::JSGetFieldofViewShape);
  509. Dispatch->Get.Push("FieldofViewDimension", m_DetectorCtrlUnit.get (), &DetectorCtrlUnit::JSGetFieldofViewDimension);
  510. Dispatch->Get.Push("DetectorType", m_DetectorCtrlUnit.get (), &DetectorCtrlUnit::JSGetDetectorType);
  511. Dispatch->Get.Push("Description", m_DetectorCtrlUnit.get (), &DetectorCtrlUnit::JSGetDescription);
  512. Dispatch->Get.Push("DetectorID", m_DetectorCtrlUnit.get (), &DetectorCtrlUnit::JSGetDetectorID);
  513. Dispatch->Get.Push("DateofLastDetectorCalibration", m_DetectorCtrlUnit.get (), &DetectorCtrlUnit::JSGetDateofLastDetectorCalibration);
  514. Dispatch->Get.Push("TimeofLastDetectorCalibration", m_DetectorCtrlUnit.get (), &DetectorCtrlUnit::JSGetTimeofLastDetectorCalibration);
  515. Dispatch->Get.Push("DetectorConditionsNominalFlag", m_DetectorCtrlUnit.get (), &DetectorCtrlUnit::JSGetDetectorConditionsNominalFlag);
  516. Dispatch->Get.Push("FPDSensitivity", m_DetectorCtrlUnit.get (), &DetectorCtrlUnit::JSGetFPDSensitivity);
  517. Dispatch->Get.Push("PixelData", m_DetectorCtrlUnit.get (), &DetectorCtrlUnit::JSGetPixelData);
  518. Dispatch->Get.Push("TargetEXI", m_DetectorCtrlUnit.get (), &DetectorCtrlUnit::JSGetTargetEXI);
  519. //Dispatch->Action.Push("SetFilterType", m_DetectorCtrlUnit.get (), &DetectorCtrlUnit::);
  520. Dispatch->Action.Push("ActiveDetector", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSActiveDetector);
  521. //Dispatch->Action.Push("SleepDetector", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::);
  522. //Dispatch->Action.Push("WakeupDetector", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::);
  523. Dispatch->Action.Push("AttachConnect", m_DetectorCtrlUnit.get (), &DetectorCtrlUnit::JSAttachConnect);
  524. Dispatch->Action.Push("CancelAttach", m_DetectorCtrlUnit.get (), &DetectorCtrlUnit::JSCancelAttach);
  525. Dispatch->Action.Push("ResetConnect", m_DetectorCtrlUnit.get (), &DetectorCtrlUnit::JSResetConnect);
  526. Dispatch->Action.Push("DisConnectFPD", m_DetectorCtrlUnit.get (), &DetectorCtrlUnit::JSDisConnectFPD);
  527. Dispatch->Action.Push("UpdateFirmware", m_DetectorCtrlUnit.get (), &DetectorCtrlUnit::JSUpdateFirmware);
  528. Dispatch->Action.Push(ActionKey::GetDetectorInfo, m_DetectorCtrlUnit.get (), &DetectorCtrlUnit::JSGetDetectorInfo);
  529. Dispatch->Action.Push("EnterExam", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSEnterExam);
  530. Dispatch->Action.Push("RecoverImage", m_DetectorCtrlUnit.get (), &DetectorCtrlUnit::JSRecoverImage);
  531. Dispatch->Action.Push("GetRecoverImageState", m_DetectorCtrlUnit.get (), &DetectorCtrlUnit::JSGetRecoverImageState);
  532. Dispatch->Action.Push("SaveSensitivity", m_DetectorCtrlUnit.get (), &DetectorCtrlUnit::JSSaveSensitivity);
  533. Dispatch->Action.Push("RESET", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSRESET);
  534. Dispatch->Action.Push("SaveRawDataMode", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSSaveRawDataMode);
  535. }
  536. void nsFPD::FPDDeviceTrixell::RegisterAcq(nsDetail::Dispatch* Dispatch)
  537. {
  538. Dispatch->Action.Push("SetAcqMode", m_AcqUnit.get(), &AcqUnit::JSSetAcqMode);
  539. Dispatch->Get.Push("ZskkFPDState", m_AcqUnit.get(), &AcqUnit::JSGetZskkFPDState);
  540. Dispatch->Get.Push("NoNeedWaitImage", m_AcqUnit.get(), &AcqUnit::JSGetNoNeedWaitImage);
  541. Dispatch->Get.Push("ImgDataInfo", m_AcqUnit.get(), &AcqUnit::JSGetLastImage);
  542. Dispatch->Get.Push("AutonumousMapFinish", m_AcqUnit.get(), &AcqUnit::JSAutonumousMapFinish);
  543. }
  544. void nsFPD::FPDDeviceTrixell::RegisterSync(nsDetail::Dispatch* Dispatch)
  545. {
  546. Dispatch->Action.Push("SetSyncMode", m_SyncUnit.get(), &SyncUnit::JSSetSyncMode);
  547. Dispatch->Action.Push("SetXwindowSize", m_SyncUnit.get(), &SyncUnit::JSSetXwindowSize);
  548. Dispatch->Action.Push("PrepareAcquisition", m_SyncUnit.get(), &SyncUnit::JSPrepareAcquisition);
  549. Dispatch->Action.Push("StartAcquisition", m_SyncUnit.get(), &SyncUnit::JSStartAcquisition);
  550. Dispatch->Action.Push("StopAcquisition", m_SyncUnit.get(), &SyncUnit::JSStopAcquisition);
  551. Dispatch->Action.Push("ActiveSyncMode", m_SyncUnit.get(), &SyncUnit::JSActiveSyncMode);
  552. Dispatch->Get.Push(CcosFPDReadyStatus, m_SyncUnit.get(), &SyncUnit::JSGetFPDReady);
  553. Dispatch->Get.Push(CcosXwindowStatus, m_SyncUnit.get(), &SyncUnit::JSGetXWindowStatus);
  554. Dispatch->Get.Push(CcosImageReadingStatus, m_SyncUnit.get(), &SyncUnit::JSGetImageReadingStatus);
  555. Dispatch->Get.Push("SupportSyncMode", m_SyncUnit.get(), &SyncUnit::JSGetSupportSyncMode);
  556. }
  557. void nsFPD::FPDDeviceTrixell::RegisterCalib(nsDetail::Dispatch* Dispatch)
  558. {
  559. //Dispatch->Action.Push("UploadCalibrationFiles", m_CalibUnit.get(), &CalibUnit::JSUploadCalibrationFiles);
  560. //Dispatch->Action.Push("SetSID", m_CalibUnit.get(), &CalibUnit::JSSetSID);
  561. Dispatch->Action.Push("ActiveCalibration", m_CalibUnit.get(), &CalibUnit::JSActiveCalibration);
  562. Dispatch->Action.Push("GetRequestedDose", m_CalibUnit.get(), &CalibUnit::JSGetRequestedDose);
  563. Dispatch->Action.Push("SetRequestedDose", m_CalibUnit.get(), &CalibUnit::JSSetRequestedDose);
  564. Dispatch->Action.Push("PrepareCalibration", m_CalibUnit.get(), &CalibUnit::JSPrepareCalibration);
  565. Dispatch->Action.Push("StartCalibration", m_CalibUnit.get(), &CalibUnit::JSStartCalibration);
  566. Dispatch->Action.Push("StopCalibration", m_CalibUnit.get(), &CalibUnit::JSStopCalibration);
  567. Dispatch->Action.Push("SetCorrectionType", m_CalibUnit.get(), &CalibUnit::JSSetCorrectionType);
  568. Dispatch->Action.Push("GetCalibrationStep", m_CalibUnit.get(), &CalibUnit::JSGetCalibrationStep);
  569. Dispatch->Action.Push("SaveCalibrationFile", m_CalibUnit.get(), &CalibUnit::JSSaveCalibrationFile);
  570. Dispatch->Action.Push("AcceptCalibration", m_CalibUnit.get(), &CalibUnit::JSAcceptCalibration);
  571. Dispatch->Action.Push("RejectCalibration", m_CalibUnit.get(), &CalibUnit::JSRejectCalibration);
  572. Dispatch->Get.Push("HaveImgCalibration", m_CalibUnit.get(), &CalibUnit::JSGetHaveImgCalibration);
  573. Dispatch->Get.Push(AttrKey::CalibrationStatus, m_CalibUnit.get(), &CalibUnit::JSGetCalibStatus);
  574. Dispatch->Get.Push(AttrKey::CalibrationProgress, m_CalibUnit.get(), &CalibUnit::JSGetCalibProgress);
  575. Dispatch->Get.Push("SaveCalibrationFileFinish", m_CalibUnit.get(), &CalibUnit::JSGetSaveCalibrationFileFinish);
  576. Dispatch->Get.Push(AttrKey::CalibMode, m_CalibUnit.get(), &CalibUnit::JSGetCalibMode);
  577. Dispatch->Get.Push(AttrKey::LastCalibrationDate, m_CalibUnit.get(), &CalibUnit::JSGetLastCalibrationDate);
  578. Dispatch->Get.Push(AttrKey::CalibrationFileExpireTime, m_CalibUnit.get(), &CalibUnit::JSGetCalibrationFileExpireTime);
  579. Dispatch->Set.Push(AttrKey::LastCalibrationDate, m_CalibUnit.get(), &CalibUnit::SetLastCalibrationDate);
  580. Dispatch->Set.Push(AttrKey::CalibrationFileExpireTime, m_CalibUnit.get(), &CalibUnit::SetCalibrationFileExpireTime);
  581. Dispatch->Update.Push(AttrKey::CalibMode, m_CalibUnit.get(), &CalibUnit::JSUpdateCalibMode);
  582. Dispatch->Update.Push(AttrKey::LastCalibrationDate, m_CalibUnit.get(), &CalibUnit::JSUpdateLastCalibrationDate);
  583. Dispatch->Update.Push(AttrKey::CalibrationFileExpireTime, m_CalibUnit.get(), &CalibUnit::JSUpdateCalibrationFileExpireTime);
  584. Dispatch->Update.Push(AttrKey::CalibrationFileExpirationReminder,
  585. [this](std::string in, std::string& out) {out = in; this->m_bNotifyCalWarn = (in == "1") ? true : false; return RET_STATUS::RET_SUCCEED; });
  586. }
  587. void nsFPD::FPDDeviceTrixell::RegisterOthers(nsDetail::Dispatch* Dispatch)
  588. {
  589. Dispatch->Get.Push(AttrKey::Temperature_Value, m_Temperature.get(), &DeviceTemperatureMould::JSGetCurrentTemperatureValue);
  590. Dispatch->Get.Push(AttrKey::Remain_Power_Value, m_Battery.get(), &DeviceBatteryMould::JSGetCurrentBatteryValue);
  591. Dispatch->Get.Push(AttrKey::Wifi_Strength_Value, m_Wifi.get(), &DeviceWifiMould::JSGetCurrentSignalValue);
  592. //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; });
  593. Dispatch->Get.Push(nDetail::AttrKey::ErrorList, m_WarnAndError.get(), &FPDErrorWarning::JSGetErrorList);
  594. Dispatch->Get.Push(TempMaxLimit, m_Temperature.get(), &DeviceTemperatureMould::JSGetTemperatureErrorMax);
  595. Dispatch->Get.Push(TempMinLimit, m_Temperature.get(), &DeviceTemperatureMould::JSGetTemperatureErrorMin);
  596. Dispatch->Get.Push(TempUpperLimit, m_Temperature.get(), &DeviceTemperatureMould::JSGetTemperatureWarningMax);
  597. Dispatch->Get.Push(TempLowerLimit, m_Temperature.get(), &DeviceTemperatureMould::JSGetTemperatureWarningMin);
  598. Dispatch->Get.Push(BatMiniLimit, m_Battery.get(), &DeviceBatteryMould::JSGetBatteryErrorMin);
  599. Dispatch->Get.Push(BatLowerLimit, m_Battery.get(), &DeviceBatteryMould::JSGetBatteryWarningMin);
  600. Dispatch->Get.Push(WifiMiniLimit, m_Wifi.get(), &DeviceWifiMould::JSGetSignalErrorMin);
  601. Dispatch->Get.Push(WifiLowerLimit, m_Wifi.get(), &DeviceWifiMould::JSGetSignalWarningMin);
  602. Dispatch->Set.Push(TempMaxLimit, m_Temperature.get(), &DeviceTemperatureMould::SetTemperatureErrorMax);
  603. Dispatch->Set.Push(TempMinLimit, m_Temperature.get(), &DeviceTemperatureMould::SetTemperatureErrorMin);
  604. Dispatch->Set.Push(TempUpperLimit, m_Temperature.get(), &DeviceTemperatureMould::SetTemperatureWarningMax);
  605. Dispatch->Set.Push(TempLowerLimit, m_Temperature.get(), &DeviceTemperatureMould::SetTemperatureWarningMin);
  606. Dispatch->Set.Push(BatMiniLimit, m_Battery.get(), &DeviceBatteryMould::SetBatteryErrorMin);
  607. Dispatch->Set.Push(BatLowerLimit, m_Battery.get(), &DeviceBatteryMould::SetBatteryWarningMin);
  608. Dispatch->Set.Push(WifiMiniLimit, m_Wifi.get(), &DeviceWifiMould::SetSignalErrorMin);
  609. Dispatch->Set.Push(WifiLowerLimit, m_Wifi.get(), &DeviceWifiMould::SetSignalWarningMin);
  610. Dispatch->Update.Push(TempMaxLimit, m_Temperature.get(), &DeviceTemperatureMould::JSUpdateTemperatureErrorMax);
  611. Dispatch->Update.Push(TempMinLimit, m_Temperature.get(), &DeviceTemperatureMould::JSUpdateTemperatureErrorMin);
  612. Dispatch->Update.Push(TempUpperLimit, m_Temperature.get(), &DeviceTemperatureMould::JSUpdateTemperatureWarningMax);
  613. Dispatch->Update.Push(TempLowerLimit, m_Temperature.get(), &DeviceTemperatureMould::JSUpdateTemperatureWarningMin);
  614. Dispatch->Update.Push(TemperatureCalibUpWarn, [](std::string in, std::string& out) {out = in; return RET_STATUS::RET_SUCCEED; });
  615. Dispatch->Update.Push(TemperatureCalibLowWarn, [](std::string in, std::string& out) {out = in; return RET_STATUS::RET_SUCCEED; });
  616. Dispatch->Update.Push(BatMiniLimit, m_Battery.get(), &DeviceBatteryMould::JSUpdateBatteryErrorMin);
  617. Dispatch->Update.Push(BatLowerLimit, m_Battery.get(), &DeviceBatteryMould::JSUpdateBatteryWarningMin);
  618. Dispatch->Update.Push(WifiMiniLimit, m_Wifi.get(), &DeviceWifiMould::JSUpdateSignalErrorMin);
  619. Dispatch->Update.Push(WifiLowerLimit, m_Wifi.get(), &DeviceWifiMould::JSUpdateSignalWarningMin);
  620. }
  621. //离线采集接口
  622. void nsFPD::FPDDeviceTrixell::RegisterAutonumous(nsDetail::Dispatch* Dispatch)
  623. {
  624. Dispatch->Action.Push("OfflineFPD", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSOfflineFPD);
  625. Dispatch->Action.Push("OnlineFPD", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSOnlineFPD);
  626. Dispatch->Action.Push("GetAutonumousImageList", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetAutonumousImageList);
  627. Dispatch->Action.Push("RemoveAutonumousImageList", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSRemoveAutonumousImageList);
  628. Dispatch->Action.Push("RemoveAutonumousAll", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSRemoveAutonumousAll);
  629. Dispatch->Action.Push("GetImageMetaData", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetImageMetaData);
  630. Dispatch->Action.Push("ExportAutonumousAll", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSExportAutonumousAll);
  631. }
  632. void nsFPD::FPDDeviceTrixell::Register()
  633. {
  634. auto Disp = &Dispatch;
  635. RegisterCtrl(Disp);
  636. RegisterAcq(Disp);
  637. RegisterSync(Disp);
  638. RegisterCalib(Disp);
  639. RegisterOthers(Disp);
  640. RegisterAutonumous(Disp);
  641. }
  642. bool nsFPD::FPDDeviceTrixell::LoadConfig()
  643. {
  644. if (!m_DetectorConfiguration->LoadConfigurations(m_stDeviceConfig))
  645. {
  646. Error("Load configuration file failed!!!");
  647. return false;
  648. }
  649. try
  650. {
  651. m_nFullImgWidth = m_stDeviceConfig.nFullImageWidth;
  652. m_nFullImgHeight = m_stDeviceConfig.nFullImageHeight;
  653. m_nLeftOffset = m_stDeviceConfig.nImageLeftOffset;
  654. m_nTopOffset = m_stDeviceConfig.nImageTopffset;
  655. m_bPreviewEnable = m_stDeviceConfig.bPreviewEnable;
  656. if (m_stDeviceConfig.nForceGridSuppress > 0)
  657. {
  658. m_bForceGridSuppress = true;
  659. }
  660. else
  661. {
  662. m_bForceGridSuppress = false;
  663. }
  664. int nAttached = (int)m_DetectorConfiguration->m_Configurations[CcosDetectorAttachedFlag];
  665. if (nAttached == 1)
  666. {
  667. m_bAttached = true;
  668. m_DetectorCtrlUnit->SetAttachStatus("1");
  669. }
  670. else
  671. {
  672. m_bAttached = false;
  673. m_stDeviceConfig.bConnectStatus = false;
  674. }
  675. string strFPDinfo;
  676. strFPDinfo = (string)m_DetectorConfiguration->m_Configurations["FieldofViewShape"];
  677. m_DetectorCtrlUnit->SetFieldofViewShape(strFPDinfo);
  678. strFPDinfo = (string)m_DetectorConfiguration->m_Configurations["FieldofViewDimension"];
  679. m_DetectorCtrlUnit->SetFieldofViewDimension(strFPDinfo);
  680. m_DetectorCtrlUnit->SetDetectorType("SCINTILLATOR");
  681. strFPDinfo = (string)m_DetectorConfiguration->m_Configurations["Description"];
  682. m_DetectorCtrlUnit->SetDescription(strFPDinfo);
  683. m_DetectorCtrlUnit->SetDetectorConditionsNominalFlag("YES");
  684. auto strFinfo = std::to_string(m_stDeviceConfig.nDoseOfEXI);
  685. m_DetectorCtrlUnit->SetFPDSensitivity(strFinfo);
  686. m_fFactorEXI2UGY = 100.0f / (float)atof(strFinfo.c_str()) * 1.0f;//子系统将UI的TargetEXI 乘以FPDSensitivity再传给imagesave,用作计算EXI和DI并填写ecm头。
  687. Info("FactorEXI2UGY = {$}", m_fFactorEXI2UGY);
  688. m_DetectorCtrlUnit->SetPixelData("");
  689. m_DetectorCtrlUnit->SetTargetEXI("5000");
  690. m_Battery.reset(new DeviceBatteryMould("DetectorTrixellBattery", 0, m_stDeviceConfig.nBatteryLimit,
  691. m_stDeviceConfig.nBatteryWarning, 100, 30, 100, 100, 0, EventCenter));
  692. m_Temperature.reset(new DeviceTemperatureMould("DetectorTrixellTemperature", 0.0f, m_stDeviceConfig.fTemperMinLimit,
  693. m_stDeviceConfig.fTemperLowLimit, m_stDeviceConfig.fTemperUpperLimit, 50.0f, 100.0f, m_stDeviceConfig.fTemperMaxLimit, 0.0f, EventCenter));
  694. m_Wifi.reset(new DeviceWifiMould("DetectorTrixellWifi", 0, m_stDeviceConfig.nWifiLimit, m_stDeviceConfig.nWifiWarning,
  695. 100, 50, 100, 100, 0, EventCenter));
  696. //------------------------------------可支持的同步模式
  697. ResDataObject jsonSupportSyncType;
  698. jsonSupportSyncType = m_DetectorConfiguration->m_Configurations["SupportSyncMode"];
  699. Debug("SupportSyncMode: {$}", jsonSupportSyncType.encode());
  700. m_SyncUnit->JSSetSupportSyncMode(jsonSupportSyncType.encode());
  701. //校正日期
  702. m_CalibUnit->SetLastCalibrationDate(m_stDeviceConfig.strLastCalibrationDate);
  703. m_CalibUnit->SetCalibrationFileExpireTime(m_stDeviceConfig.strCalibrationFileExpireTime);
  704. m_bNotifyCalWarn = ((int)m_DetectorConfiguration->m_Configurations["CalibrationFileExpirationReminder"] == 1) ? true : false;
  705. //校正参数
  706. ResDataObject CalibDoseList;
  707. string strCalibDose = m_strWorkPath + R"(\OEMDrivers\Detector\Trixell\TrixellDRDetector\CalibrationDose_Trixell.xml)";
  708. Info("start load calibDose file: {$}", strCalibDose.c_str());
  709. struct stat buffer;
  710. if (stat(strCalibDose.c_str(), &buffer) == 0)
  711. {
  712. CalibDoseList.loadFile(strCalibDose.c_str());
  713. m_CalibDoseList = CalibDoseList["List"];
  714. Info("m_CalibDoseList: {$} ", m_CalibDoseList.encode());
  715. for (int i = 0; i < m_CalibDoseList.size(); i++)
  716. {
  717. ResDataObject temp = m_CalibDoseList[i];
  718. int nExpNum = temp["ExpNum"];
  719. m_nCalibTotalExposureNum += nExpNum;
  720. //Info("temp: {$} ", temp.encode());
  721. }
  722. Info("CalibTotalExposureNum: {$}", m_nCalibTotalExposureNum);
  723. }
  724. else
  725. {
  726. Error("{$} file not exist!", strCalibDose);
  727. }
  728. }
  729. catch (exception e)
  730. {
  731. Error("Get calibDose error: {$}", e.what());
  732. }
  733. return true;
  734. }
  735. bool nsFPD::FPDDeviceTrixell::CreateDevice()
  736. {
  737. if (!LoadConfig())
  738. {
  739. return false;
  740. }
  741. if (nullptr == g_pDetector)
  742. {
  743. if (nullptr == m_pDetectors)
  744. {
  745. m_pDetectors = new TrixellCtrl();
  746. Info("Create SDK ctrl ok\n");
  747. g_pDetector = (TrixellCtrl*)m_pDetectors;
  748. }
  749. }
  750. else
  751. {
  752. m_pDetectors = g_pDetector;
  753. Info("SDK ctrl Already exit\n");
  754. }
  755. return ((TrixellCtrl*)m_pDetectors)->AddDPCs(this, m_DetectorConfiguration->m_Configurations, m_stDeviceConfig);
  756. }
  757. RET_STATUS nsFPD::FPDDeviceTrixell::Connect()
  758. {
  759. Info("------------------------ FPD {$} Start running ------------------------", m_stDeviceConfig.strDeviceName.c_str());
  760. bool bRet = m_pDetectors->Connect(m_strWorkPath.c_str(), this);
  761. if (!bRet)
  762. {
  763. Error("Connect detector failed!!!");
  764. return RET_STATUS::RET_FAILED;
  765. }
  766. Info("Connect detector success");
  767. return RET_STATUS::RET_SUCCEED;
  768. }
  769. DWORD nsFPD::FPDDeviceTrixell::OnNotify(LPVOID pParam)
  770. {
  771. Info("OnNotify Loop Entry-----------");
  772. FPDDeviceTrixell* pNotifyOpr = (FPDDeviceTrixell*)pParam;
  773. int nHandlesNum = 3;
  774. HANDLE* pHandles = new HANDLE[nHandlesNum];
  775. pHandles[0] = pNotifyOpr->m_PauseCalibrationEvt;
  776. pHandles[1] = pNotifyOpr->m_ExitEvt;
  777. pHandles[2] = pNotifyOpr->m_ConnectEvt;
  778. while (1)
  779. {
  780. DWORD dwResult = WaitForMultipleObjects(nHandlesNum, pHandles, FALSE, INFINITE);
  781. if (dwResult == WAIT_OBJECT_0) //m_PauseCalibrationEvt
  782. {
  783. Info("OnNotify get PauseCalibration evt");
  784. pNotifyOpr->PauseCalibration();
  785. }
  786. else if (dwResult == WAIT_OBJECT_0 + 1) //m_ExitEvt
  787. {
  788. Info("Exit OnNotify Thread");
  789. break;
  790. }
  791. else if (dwResult == WAIT_OBJECT_0 + 2) //m_ConnectEvt
  792. {
  793. Info("Get ConnectEVT");
  794. pNotifyOpr->Connect();
  795. ResetEvent(pNotifyOpr->m_ConnectEvt);
  796. }
  797. }
  798. delete[] pHandles;
  799. Info("Exit OnNotify Thread over");
  800. return 0;
  801. }
  802. RET_STATUS nsFPD::FPDDeviceTrixell::ActiveDetector(bool bActive)
  803. {
  804. if (!m_stDeviceConfig.bConnectStatus)
  805. {
  806. return RET_STATUS::RET_THREAD_INVALID;
  807. }
  808. if (bActive)
  809. {
  810. bool bRet = ((TrixellCtrl*)m_pDetectors)->ActivePanel(this);
  811. if (!bRet)
  812. {
  813. return RET_STATUS::RET_FAILED;
  814. }
  815. }
  816. return RET_STATUS::RET_SUCCEED;
  817. }
  818. RET_STATUS nsFPD::FPDDeviceTrixell::WakeupDetector()
  819. {
  820. Info("--Func-- Wakeup FPD {$}", m_nDeviceIndex);
  821. if (((TrixellCtrl*)m_pDetectors)->WakeupDetector(m_nDeviceIndex))
  822. {
  823. return RET_STATUS::RET_SUCCEED;
  824. }
  825. return RET_STATUS::RET_FAILED;
  826. }
  827. RET_STATUS nsFPD::FPDDeviceTrixell::PrepareAcquisition()
  828. {
  829. Info("==============================PrepareAcquisition");
  830. if (!m_stDeviceConfig.bConnectStatus || m_WarnAndError->IsErrorExist())
  831. {
  832. Error("Detector status is error. Disable Ready.");
  833. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_ERROR));
  834. return RET_STATUS::RET_FAILED;
  835. }
  836. auto strFinfo = std::to_string(m_stDeviceConfig.nDoseOfEXI);
  837. m_DetectorCtrlUnit->SetFPDSensitivity(strFinfo);
  838. m_SyncUnit->FPDReadyNotify(false);
  839. RET_STATUS Ret = RET_STATUS::RET_FAILED;
  840. if (RET_STATUS::RET_SUCCEED == m_pDetectors->PrepareAcquisition(this))
  841. {
  842. m_SyncUnit->FPDReadyNotify(true);
  843. Ret = RET_STATUS::RET_SUCCEED;
  844. }
  845. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  846. Info("==============================PrepareAcquisition over");
  847. return Ret;
  848. }
  849. RET_STATUS nsFPD::FPDDeviceTrixell::StartAcquisition(string in)
  850. {
  851. Info("==============================StartAcquisition");
  852. if (!m_stDeviceConfig.bConnectStatus)
  853. {
  854. return RET_STATUS::RET_THREAD_INVALID;
  855. }
  856. if (DETECTOR_STATUS_STANDBY != m_DetectorCtrlUnit->GetDetectorStatus())
  857. {
  858. if ((m_CalibUnit->GetCalibrationStatus() == CCOS_CALIBRATION_STATUS_RUNNING) ||
  859. (m_CalibUnit->GetCalibrationStatus() == CCOS_CALIBRATION_STATUS_ACTIVE))
  860. {
  861. Error("StartAcquisition failed. Detector at Calibration status");
  862. return RET_STATUS::RET_FAILED;
  863. }
  864. if (DETECTOR_STATUS_ACQ == m_DetectorCtrlUnit->GetDetectorStatus())
  865. {
  866. Warn("Detector already at Acq status");
  867. return RET_STATUS::RET_SUCCEED;
  868. }
  869. }
  870. RET_STATUS Ret = RET_STATUS::RET_FAILED;
  871. if (RET_STATUS::RET_SUCCEED == ((TrixellCtrl*)m_pDetectors)->StartAcquisition(this))
  872. {
  873. Ret = RET_STATUS::RET_SUCCEED;
  874. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_ACQ));
  875. }
  876. else
  877. {
  878. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  879. }
  880. Info("==============================StartAcquisition over");
  881. return Ret;
  882. }
  883. RET_STATUS nsFPD::FPDDeviceTrixell::StopAcquisition()
  884. {
  885. Info("==============================StopAcquisition");
  886. if (!m_stDeviceConfig.bConnectStatus)
  887. {
  888. return RET_STATUS::RET_THREAD_INVALID;
  889. }
  890. if (DETECTOR_STATUS_STANDBY == m_DetectorCtrlUnit->GetDetectorStatus())
  891. {
  892. Warn("Detector already at Standby status");
  893. return RET_STATUS::RET_SUCCEED;
  894. }
  895. RET_STATUS Ret = RET_STATUS::RET_FAILED;
  896. if (RET_STATUS::RET_SUCCEED == ((TrixellCtrl*)m_pDetectors)->StopAcquisition(this))
  897. {
  898. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  899. Ret = RET_STATUS::RET_SUCCEED;
  900. }
  901. Info("==============================StopAcquisition over");
  902. return Ret;
  903. }
  904. string nsFPD::FPDDeviceTrixell::GetFileVersion(string strFilePathName)
  905. {
  906. DWORD dwVerSize = GetFileVersionInfoSize(strFilePathName.c_str(), NULL);
  907. if (dwVerSize == 0)
  908. {
  909. return "null";
  910. }
  911. LPVOID pVersionBuffer = malloc(dwVerSize);
  912. if (pVersionBuffer == nullptr)
  913. {
  914. return "null";
  915. }
  916. GetFileVersionInfo(strFilePathName.c_str(), 0, dwVerSize, pVersionBuffer);
  917. VS_FIXEDFILEINFO* pInfo;
  918. UINT nInfoLen;
  919. char szValue[MAX_PATH] = { 0 };
  920. if (VerQueryValue(pVersionBuffer, ("\\"), (void**)&pInfo, &nInfoLen))
  921. {
  922. sprintf_s(szValue, ("%d.%d.%d.%d"), HIWORD(pInfo->dwFileVersionMS), LOWORD(pInfo->dwFileVersionMS), HIWORD(pInfo->dwFileVersionLS), LOWORD(pInfo->dwFileVersionLS));
  923. }
  924. string strVersion = szValue;
  925. return strVersion;
  926. }
  927. void nsFPD::FPDDeviceTrixell::SendTemperatureValue()
  928. {
  929. int nStatus = 0;
  930. m_Temperature->SetTemperature(m_stDeviceConfig.fCurrentTemperValue, nStatus);
  931. Info("SendTemperatureValue: {$}, status {$}\n", m_stDeviceConfig.fCurrentTemperValue, nStatus);
  932. }
  933. void nsFPD::FPDDeviceTrixell::SendWifiValue()
  934. {
  935. int nStatus = 0;
  936. m_Wifi->SetSignalValue(m_stDeviceConfig.nCurrentWifiValue, nStatus);
  937. Info("SendWifiValue: {$}, status {$}\n", m_stDeviceConfig.nCurrentWifiValue, nStatus);
  938. }
  939. void nsFPD::FPDDeviceTrixell::SendBatteryValue()
  940. {
  941. int nStatus = 0;
  942. m_Battery->SetRemainPowerValue(m_stDeviceConfig.nCurrentBatteryValue, nStatus);
  943. Info("SendBatteryValue: {$}, status {$}\n", m_stDeviceConfig.nCurrentBatteryValue, nStatus);
  944. }
  945. RET_STATUS nsFPD::FPDDeviceTrixell::XWindowOnNotify()
  946. {
  947. RET_STATUS Ret = RET_STATUS::RET_FAILED;
  948. m_SyncUnit->XWindowOnNotify();
  949. Info("WindowOn\n");
  950. m_stImgCreateTime = { 0 };
  951. GetLocalTime(&m_stImgCreateTime);
  952. Info("Full image create time-%02d:%02d:%02d:%03d", m_stImgCreateTime.wHour, m_stImgCreateTime.wMinute, m_stImgCreateTime.wSecond, m_stImgCreateTime.wMilliseconds);
  953. return Ret;
  954. }
  955. RET_STATUS nsFPD::FPDDeviceTrixell::XWindowOffNotify()
  956. {
  957. RET_STATUS Ret = RET_STATUS::RET_FAILED;
  958. m_SyncUnit->XWindowOffNotify();
  959. Info("WindowOff\n");
  960. return Ret;
  961. }
  962. RET_STATUS nsFPD::FPDDeviceTrixell::ActiveCalibration(CCOS_CALIBRATION_TYPE eType)
  963. {
  964. Info("==============================ActiveCalibration is {$}", (int)eType);
  965. m_DetectorCtrlUnit->SetFPDSensitivity("100");
  966. if (!m_stDeviceConfig.bConnectStatus)
  967. {
  968. return RET_STATUS::RET_THREAD_INVALID;
  969. }
  970. if (eType == CCOS_CALIBRATION_TYPE_NONE || eType == CCOS_CALIBRATION_TYPE_MAX)
  971. {
  972. return RET_STATUS::RET_INVALID;
  973. }
  974. /*if (DETECTOR_STATUS_STANDBY != m_DetectorCtrlUnit->GetDetectorStatus())
  975. {
  976. if (DETECTOR_STATUS_ACQ == m_DetectorCtrlUnit->GetDetectorStatus())
  977. {
  978. Error("ActiveCalibration {$} failed. Detector at Acq status", (int)eType);
  979. }
  980. return RET_STATUS::RET_FAILED;
  981. }*/
  982. m_eAppStatus = APP_STATUS_CAL_BEGIN;
  983. if (eType == CCOS_CALIBRATION_TYPE_XRAY)
  984. {
  985. ResetEvent(m_WaitCalibDoseEvt);
  986. int nCalibrationRounds = (int)m_CalibDoseList.size();
  987. ((TrixellCtrl*)m_pDetectors)->SetReferenceNum(nCalibrationRounds);
  988. }
  989. RET_STATUS Ret = ((TrixellCtrl*)m_pDetectors)->ActiveCalibration(eType);
  990. if (RET_STATUS::RET_SUCCEED == Ret)
  991. {
  992. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_ACTIVE));
  993. m_CalibUnit->SetCalibrationProgress("0");
  994. if (eType == CCOS_CALIBRATION_TYPE_XRAY)
  995. {
  996. Info("start to waitting CalibDoseEvt");
  997. DWORD nRet = WaitForSingleObject(m_WaitCalibDoseEvt, INFINITE);
  998. }
  999. m_nXrayCalibNum = 0;
  1000. }
  1001. //重置校正流程参数
  1002. m_nCalibCurrentCalibrationRound = 1;
  1003. m_nCalibCurrentExposureIndex = 1;
  1004. m_nCalibCurrentExposureNum = 0;
  1005. Info("==============================ActiveCalibration over");
  1006. return Ret;
  1007. }
  1008. RET_STATUS nsFPD::FPDDeviceTrixell::GetRequestedDose(std::string& strDose)
  1009. {
  1010. Info("==============================GetRequestedDose");
  1011. if (!m_stDeviceConfig.bConnectStatus)
  1012. {
  1013. return RET_STATUS::RET_THREAD_INVALID;
  1014. }
  1015. RET_STATUS Ret = RET_STATUS::RET_SUCCEED;
  1016. bool bGetDoseInfo = false;
  1017. ResDataObject out;
  1018. CCOS_CALIBRATION_TYPE nCalibrationType = m_CalibUnit->GetCalibrationType();
  1019. if (CCOS_CALIBRATION_TYPE_DARK == nCalibrationType)
  1020. {
  1021. out.add("Dose", 0.0f);
  1022. out.add("kV", 0.0f);
  1023. out.add("mA", 0.0f);
  1024. out.add("ms", 0.0f);
  1025. out.add("mAs", 0.0f);
  1026. bGetDoseInfo = true;
  1027. }
  1028. else if (CCOS_CALIBRATION_TYPE_XRAY == nCalibrationType)
  1029. {
  1030. for (int i = 0; i < m_CalibDoseList.size(); i++)
  1031. {
  1032. ResDataObject temp = m_CalibDoseList[i];
  1033. int nDose = temp["Dose"];
  1034. int nDoseParem = (int)(m_fDoseParam * 1000);
  1035. if (nDoseParem == nDose)
  1036. {
  1037. out.add("Dose", nDoseParem);
  1038. out.add("kV", temp["kV"]);
  1039. out.add("mA", temp["mA"]);
  1040. out.add("ms", temp["ms"]);
  1041. out.add("mAs", temp["mAs"]);
  1042. bGetDoseInfo = true;
  1043. Info("Find target dose parameter");
  1044. break;
  1045. }
  1046. }
  1047. }
  1048. else
  1049. {
  1050. Warn("Can not support CalibrationType({$})", (int)nCalibrationType);
  1051. Ret = RET_STATUS::RET_FAILED;
  1052. }
  1053. if (bGetDoseInfo)
  1054. {
  1055. strDose = out.encode();
  1056. Info("GetRequestedDose {$} over", strDose.c_str());
  1057. }
  1058. else
  1059. {
  1060. Error("GetRequestedDose failed");
  1061. }
  1062. return Ret;
  1063. }
  1064. RET_STATUS nsFPD::FPDDeviceTrixell::SetRequestedDose(std::string strDose)
  1065. {
  1066. Info("==============================SetRequestedDose");
  1067. RET_STATUS Ret = RET_STATUS::RET_SUCCEED;
  1068. return Ret;
  1069. }
  1070. RET_STATUS nsFPD::FPDDeviceTrixell::PrepareCalibration()
  1071. {
  1072. Info("==============================PrepareCalibration");
  1073. if (!m_stDeviceConfig.bConnectStatus)
  1074. {
  1075. return RET_STATUS::RET_THREAD_INVALID;
  1076. }
  1077. m_SyncUnit->FPDReadyNotify(false);
  1078. RET_STATUS Ret = RET_STATUS::RET_FAILED;
  1079. if (RET_STATUS::RET_SUCCEED == ((TrixellCtrl*)m_pDetectors)->PrepareCalibration(this))
  1080. {
  1081. m_SyncUnit->FPDReadyNotify(true);
  1082. Ret = RET_STATUS::RET_SUCCEED;
  1083. }
  1084. else
  1085. {
  1086. Ret = RET_STATUS::RET_FAILED;
  1087. }
  1088. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1089. Info("==============================PrepareCalibration over");
  1090. return Ret;
  1091. }
  1092. RET_STATUS nsFPD::FPDDeviceTrixell::StartCalibration()
  1093. {
  1094. Info("==============================StartCalibration");
  1095. if (!m_stDeviceConfig.bConnectStatus)
  1096. {
  1097. return RET_STATUS::RET_THREAD_INVALID;
  1098. }
  1099. /*if (DETECTOR_STATUS_STANDBY != m_DetectorCtrlUnit->GetDetectorStatus())
  1100. {
  1101. if (DETECTOR_STATUS_ACQ == m_DetectorCtrlUnit->GetDetectorStatus())
  1102. {
  1103. Error("ActiveCalibration failed. Detector at Acq status");
  1104. }
  1105. return RET_STATUS::RET_FAILED;
  1106. }*/
  1107. RET_STATUS Ret = RET_STATUS::RET_FAILED;
  1108. CCOS_CALIBRATION_TYPE eCalibrationType = m_CalibUnit->GetCalibrationType();
  1109. if (eCalibrationType == CCOS_CALIBRATION_TYPE_DARK)
  1110. {
  1111. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1112. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY));
  1113. m_CalibUnit->SetCalibrationProgress("100");
  1114. Info("DarkCalibration finish");
  1115. Info("==============================StartCalibration over");
  1116. return RET_STATUS::RET_SUCCEED;
  1117. }
  1118. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_ACQ));
  1119. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_RUNNING));
  1120. if (RET_STATUS::RET_SUCCEED == m_pDetectors->StartCalibration(this))
  1121. {
  1122. Ret = RET_STATUS::RET_SUCCEED;
  1123. }
  1124. else
  1125. {
  1126. Ret = RET_STATUS::RET_FAILED;
  1127. }
  1128. Info("==============================StartCalibration over");
  1129. return RET_STATUS::RET_SUCCEED;
  1130. }
  1131. RET_STATUS nsFPD::FPDDeviceTrixell::PauseCalibration()
  1132. {
  1133. RET_STATUS Ret = RET_STATUS::RET_SUCCEED;
  1134. m_nXrayCalibNum++;
  1135. int nDose = (int)m_fDoseParam;
  1136. if (nDose == 25 && m_nXrayCalibNum == 10)
  1137. {
  1138. Info("start to waitting CalibDoseEvt");
  1139. DWORD nRet = WaitForSingleObject(m_WaitCalibDoseEvt, INFINITE);
  1140. //m_nXrayCalibNum = 0;
  1141. }
  1142. else if (nDose != 25)
  1143. {
  1144. if (m_nXrayCalibNum != 13)
  1145. {
  1146. Info("start to waitting CalibDoseEvt");
  1147. DWORD nRet = WaitForSingleObject(m_WaitCalibDoseEvt, INFINITE);
  1148. }
  1149. }
  1150. ResetEvent(m_PauseCalibrationEvt);
  1151. ResetEvent(m_WaitCalibDoseEvt);
  1152. m_AcqUnit->SendNoNeedWaitImage(true);
  1153. if (m_nXrayCalibNum != 13)
  1154. {
  1155. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1156. m_CalibUnit->PauseCalibration();
  1157. }
  1158. Info("Driver PauseCalibration over,m_nXrayCalibNum {$}", m_nXrayCalibNum);
  1159. return Ret;
  1160. }
  1161. RET_STATUS nsFPD::FPDDeviceTrixell::StopCalibration()
  1162. {
  1163. Info("==============================StopCalibration");
  1164. if (!m_stDeviceConfig.bConnectStatus)
  1165. {
  1166. return RET_STATUS::RET_THREAD_INVALID;
  1167. }
  1168. /*if (m_CalibUnit->GetCalibrationStatus() != CCOS_CALIBRATION_STATUS_RUNNING && m_CalibUnit->GetCalibrationStatus() != CCOS_CALIBRATION_STATUS_PAUSE)
  1169. {
  1170. return RET_STATUS::RET_FAILED;
  1171. }*/
  1172. RET_STATUS Ret = RET_STATUS::RET_FAILED;
  1173. m_eAppStatus = APP_STATUS_CAL_END;
  1174. if (RET_STATUS::RET_SUCCEED == ((TrixellCtrl*)m_pDetectors)->AbortCalibration(this))
  1175. {
  1176. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY));
  1177. Ret = RET_STATUS::RET_SUCCEED;
  1178. }
  1179. else
  1180. {
  1181. Ret = RET_STATUS::RET_FAILED;
  1182. }
  1183. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1184. Info("==============================StopCalibration over");
  1185. return RET_STATUS::RET_SUCCEED;
  1186. }
  1187. bool nsFPD::FPDDeviceTrixell::CompleteCalibration()
  1188. {
  1189. m_stDeviceConfig.fCalibTemperature2 = m_stDeviceConfig.fCurrentTemperValue;
  1190. m_stDeviceConfig.fCalibTemperature = (m_stDeviceConfig.fCalibTemperature1 + m_stDeviceConfig.fCalibTemperature2) / 2;
  1191. ResetEvent(m_UploadCalibMapOver);
  1192. ((TrixellCtrl*)m_pDetectors)->CompleteCalibration(this);
  1193. DWORD nRet = WaitForSingleObject(m_UploadCalibMapOver, 60000);
  1194. if (WAIT_OBJECT_0 == nRet)
  1195. {
  1196. Info("got event m_UploadCalibMapOver");
  1197. }
  1198. else if (WAIT_TIMEOUT == nRet)
  1199. {
  1200. Info("wait event m_UploadCalibMapOver timeout");
  1201. }
  1202. else
  1203. {
  1204. Info("wait event m_UploadCalibMapOver error");
  1205. }
  1206. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1207. {
  1208. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY));
  1209. m_CalibUnit->SetCalibrationProgress("100");
  1210. }
  1211. return true;
  1212. }
  1213. void nsFPD::FPDDeviceTrixell::AbortCalibration()
  1214. {
  1215. Info("AbortCalibration");
  1216. CCOS_CALIBRATION_TYPE nCalibrationType = m_CalibUnit->GetCalibrationType();
  1217. if (CCOS_CALIBRATION_TYPE_DARK == nCalibrationType)
  1218. {
  1219. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1220. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_ERROR));
  1221. m_CalibUnit->SetCalibrationProgress("100");
  1222. Info("AbortDarkCalibration over");
  1223. return;
  1224. }
  1225. m_eAppStatus = APP_STATUS_CAL_END;
  1226. ((TrixellCtrl*)m_pDetectors)->AbortCalibration(this);
  1227. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1228. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_ERROR));
  1229. m_CalibUnit->SetCalibrationProgress("100");
  1230. m_AcqUnit->SendNoNeedWaitImage(true);
  1231. Info("AbortCalibration over");
  1232. }
  1233. RET_STATUS nsFPD::FPDDeviceTrixell::GetCalibrationStep(int nDetectorID, string& strCalibrationStepInfo)
  1234. {
  1235. Info("## GetCalibrationStep ##");
  1236. RET_STATUS Ret = RET_STATUS::RET_SUCCEED;
  1237. Info("Calibration DetectorID: {$}", nDetectorID);
  1238. ResDataObject out;
  1239. int nCalibrationRounds = (int)m_CalibDoseList.size();
  1240. int nExposureNumCurrentRound = (int)m_CalibDoseList[m_nCalibCurrentCalibrationRound - 1]["ExpNum"];
  1241. if (((TrixellCtrl*)m_pDetectors)->GetCalibrationStep(m_nCalibCurrentCalibrationRound, nCalibrationRounds, m_nCalibCurrentExposureIndex, nExposureNumCurrentRound))
  1242. {
  1243. Info("GetCalibrationStep over");
  1244. Ret = RET_STATUS::RET_SUCCEED;
  1245. }
  1246. else
  1247. {
  1248. Error("GetCalibrationStep error");
  1249. Ret = RET_STATUS::RET_FAILED;
  1250. }
  1251. out.add("CalibrationRounds", (int)m_CalibDoseList.size());
  1252. out.add("TotalExposureNum", m_nCalibTotalExposureNum);
  1253. out.add("CurrentCalibrationRound", m_nCalibCurrentCalibrationRound);
  1254. out.add("ExposureNumCurrentRound", (int)m_CalibDoseList[m_nCalibCurrentCalibrationRound - 1]["ExpNum"]);
  1255. out.add("CurrentExposureIndex", m_nCalibCurrentExposureIndex);
  1256. out.add("CurrentExposureNum", m_nCalibCurrentExposureNum);
  1257. strCalibrationStepInfo = out.encode();
  1258. Info("GetCalibrationStep over \n{$}", strCalibrationStepInfo.c_str());
  1259. return Ret;
  1260. }
  1261. RET_STATUS nsFPD::FPDDeviceTrixell::AcceptCalibration()
  1262. {
  1263. Info("## AcceptCalibration ##");
  1264. RET_STATUS Ret = RET_STATUS::RET_SUCCEED;
  1265. if (((TrixellCtrl*)m_pDetectors)->AcceptCalibration())
  1266. {
  1267. Info("AcceptCalibration over");
  1268. Ret = RET_STATUS::RET_SUCCEED;
  1269. }
  1270. else
  1271. {
  1272. Error("AcceptCalibration error");
  1273. Ret = RET_STATUS::RET_FAILED;
  1274. }
  1275. int nExposureNumCurrentRound = (int)m_CalibDoseList[m_nCalibCurrentCalibrationRound - 1]["ExpNum"];
  1276. //完成校正条件:轮数够了,曝光次数够了
  1277. if ((m_nCalibCurrentCalibrationRound == (int)m_CalibDoseList.size()) && (m_nCalibCurrentExposureIndex == nExposureNumCurrentRound))
  1278. {
  1279. Info("Calibration Round: {$}, Exposure Index: {$}, Finished", m_nCalibCurrentCalibrationRound, m_nCalibCurrentExposureIndex);
  1280. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1281. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY));
  1282. m_CalibUnit->SetCalibrationProgress("100");
  1283. return Ret;
  1284. }
  1285. if (m_nCalibCurrentExposureIndex >= nExposureNumCurrentRound) //跳到下一轮校正参数
  1286. {
  1287. m_nCalibCurrentCalibrationRound++;
  1288. m_nCalibCurrentExposureIndex = 1;
  1289. ResDataObject temp = m_CalibDoseList[m_nCalibCurrentCalibrationRound - 1];
  1290. int nDose = temp["Dose"];
  1291. m_fDoseParam = nDose / 1000.0f;
  1292. }
  1293. else
  1294. {
  1295. m_nCalibCurrentExposureIndex++;
  1296. }
  1297. m_nCalibCurrentExposureNum++;
  1298. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1299. return Ret;
  1300. }
  1301. RET_STATUS nsFPD::FPDDeviceTrixell::RejectCalibration()
  1302. {
  1303. Info("## RejectCalibration ##");
  1304. RET_STATUS Ret = RET_STATUS::RET_SUCCEED;
  1305. if (((TrixellCtrl*)m_pDetectors)->RejectCalibration())
  1306. {
  1307. Info("RejectCalibration over");
  1308. Ret = RET_STATUS::RET_SUCCEED;
  1309. }
  1310. else
  1311. {
  1312. Error("RejectCalibration error");
  1313. Ret = RET_STATUS::RET_FAILED;
  1314. }
  1315. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1316. return Ret;
  1317. }
  1318. RET_STATUS nsFPD::FPDDeviceTrixell::SaveCalibrationFile(bool bSaveFlag)
  1319. {
  1320. Info("## SaveCalibrationFile ##");
  1321. RET_STATUS Ret = RET_STATUS::RET_SUCCEED;
  1322. Info("SaveCalibrationFile by user: {$}", bSaveFlag);
  1323. if (!bSaveFlag)
  1324. {
  1325. Warn("Not save calibration file");
  1326. return Ret;
  1327. }
  1328. if (((TrixellCtrl*)m_pDetectors)->SaveCalibrationFile())
  1329. {
  1330. Info("SaveCalibrationFile over");
  1331. m_CalibUnit->SetSaveCalibrationFileFinish(true);
  1332. Ret = RET_STATUS::RET_SUCCEED;
  1333. //更新配置文件中校正日期和时间
  1334. time_t localtime = time(NULL);
  1335. string strLocalTime = DatetimeToString(localtime);
  1336. Info("strLocalTime:{$}", strLocalTime);
  1337. m_CalibUnit->SetLastCalibrationDate(strLocalTime);
  1338. //清除校正文件相关警告
  1339. m_WarnAndError->ClearWarn(ERR_FPD_CAL_FILE_NOT_EXIST);
  1340. m_WarnAndError->ClearWarn(ERR_FPD_CAL_FILE_OUTDATE);
  1341. }
  1342. else
  1343. {
  1344. Error("SaveCalibrationFile error");
  1345. m_CalibUnit->SetSaveCalibrationFileFinish(false);
  1346. Ret = RET_STATUS::RET_FAILED;
  1347. }
  1348. return Ret;
  1349. }
  1350. RET_STATUS nsFPD::FPDDeviceTrixell::GetDeviceDictionary(std::string& out)
  1351. {
  1352. ResDataObject m_DeviceDictionary;
  1353. ResDataObject FPDinfo;
  1354. //先用虚拟值
  1355. FPDinfo.add("SysVersion", "1.1");
  1356. FPDinfo.add("SubVersion", "1.1");
  1357. FPDinfo.add("FPGAVersion", "1.1");
  1358. m_DeviceDictionary.add("DriverType", "StaticDetector");
  1359. m_DeviceDictionary.add("DeviceName", "Trixell");
  1360. m_DeviceDictionary.add("DateOfManufacture", "2019.4.19");
  1361. m_DeviceDictionary.add("SoftwareVersion", "1.1");
  1362. m_DeviceDictionary.add("HardwareVersion", FPDinfo);
  1363. m_DeviceDictionary.add("Description", m_stDeviceConfig.strDeviceName.c_str());
  1364. m_DeviceDictionary.add("Model", "Pixium");
  1365. m_DeviceDictionary.add("SerialNumber", m_DetectorConfiguration->m_Configurations["SerialNumber"]);
  1366. out = m_DeviceDictionary.encode();
  1367. return RET_STATUS::RET_SUCCEED;
  1368. }
  1369. RET_STATUS nsFPD::FPDDeviceTrixell::ResetConnect()
  1370. {
  1371. ((TrixellCtrl*)m_pDetectors)->DisConnect(this);
  1372. ((TrixellCtrl*)m_pDetectors)->Connect(m_strWorkPath.c_str(), this);
  1373. return RET_STATUS::RET_SUCCEED;
  1374. }
  1375. RET_STATUS nsFPD::FPDDeviceTrixell::DisConnectFPD()
  1376. {
  1377. return RET_STATUS::RET_SUCCEED;
  1378. }
  1379. RET_STATUS nsFPD::FPDDeviceTrixell::DisConnectFPDForce()
  1380. {
  1381. return RET_STATUS::RET_SUCCEED;
  1382. }
  1383. void nsFPD::FPDDeviceTrixell::FullImageDateArrived(WORD* pImg)
  1384. {
  1385. AddFrameWithRawHead(IMAGE_FULL, pImg, m_stDeviceConfig.nFullImageWidth * m_stDeviceConfig.nFullImageHeight);
  1386. }
  1387. void nsFPD::FPDDeviceTrixell::PrevImageDateArrived(WORD* pImg)
  1388. {
  1389. AddFrameWithRawHead(IMAGE_PREVIEW, pImg, m_stDeviceConfig.nPreviewWidth * m_stDeviceConfig.nPreviewHeight);
  1390. }
  1391. RET_STATUS nsFPD::FPDDeviceTrixell::EnterExam(int nExamMode)
  1392. {
  1393. Info("EnterExam");
  1394. switch (nExamMode)
  1395. {
  1396. case APP_STATUS_WORK_BEGIN:
  1397. Info("Enter into Exam Windows");
  1398. m_eAppStatus = APP_STATUS_WORK_BEGIN;
  1399. ResetError();
  1400. CheckCalibrationDue();
  1401. break;
  1402. case APP_STATUS_WORK_END:
  1403. Info("Quit Exam Windows");
  1404. m_eAppStatus = APP_STATUS_WORK_END;
  1405. m_WarnAndError->ClearAllWarn();
  1406. break;
  1407. case APP_STATUS_DETSHARE_BEGIN:
  1408. Info("Enter into Detector Share Windows");
  1409. m_eAppStatus = APP_STATUS_DETSHARE_BEGIN;
  1410. break;
  1411. case APP_STATUS_DETSHAR_END:
  1412. m_eAppStatus = APP_STATUS_IDLE;
  1413. Info("Quit Detector Share Windows");
  1414. m_eAppStatus = APP_STATUS_DETSHAR_END;
  1415. break;
  1416. case APP_STATUS_CAL_BEGIN:
  1417. Info("Enter into Calibration Windows");
  1418. m_eAppStatus = APP_STATUS_CAL_BEGIN;
  1419. break;
  1420. case APP_STATUS_CAL_END:
  1421. Info("Quit Calibration Windows");
  1422. m_eAppStatus = APP_STATUS_CAL_END;
  1423. break;
  1424. case APP_STATUS_WORK_IN_SENSITIVITY:
  1425. Info("Enter into sensitivity test interface");
  1426. m_eAppStatus = APP_STATUS_WORK_IN_SENSITIVITY;
  1427. break;
  1428. default:
  1429. break;
  1430. }
  1431. m_pDetectors->EnterExam(m_eAppStatus);
  1432. return RET_STATUS::RET_SUCCEED;
  1433. }
  1434. bool nsFPD::FPDDeviceTrixell::GetLogicMode(string& strAcqMode, int& nLogicMode)
  1435. {
  1436. if (strAcqMode == "RAD")
  1437. {
  1438. nLogicMode = RAD;
  1439. }
  1440. else if (strAcqMode == "DDR")
  1441. {
  1442. nLogicMode = DDR;
  1443. }
  1444. else if (strAcqMode == "1")
  1445. {
  1446. nLogicMode = RAD;
  1447. }
  1448. else if (strAcqMode == "2")
  1449. {
  1450. nLogicMode = DDR;
  1451. }
  1452. else
  1453. {
  1454. Error("Not support mode!");
  1455. return false;
  1456. }
  1457. return true;
  1458. }
  1459. RET_STATUS nsFPD::FPDDeviceTrixell::SetAcqMode(string strAcqMode)
  1460. {
  1461. Info("nsFPD::FPDDeviceTrixell::SetAcqMode(string)");
  1462. if (!m_stDeviceConfig.bConnectStatus)
  1463. {
  1464. Error("m_stDeviceConfig.bConnectStatus = false");
  1465. return RET_STATUS::RET_FAILED;
  1466. }
  1467. int nAcqMode = 1;
  1468. int nWidth = m_stDeviceConfig.nFullImageWidth;
  1469. int nHeight = m_stDeviceConfig.nFullImageHeight;
  1470. int nBit = m_stDeviceConfig.nImageBits;
  1471. Info("ImageSize({$} {$}), bits({$})", nWidth, nHeight, nBit);
  1472. m_AcqUnit->SetFulImageInfo(nHeight, nWidth, nBit, false);
  1473. m_AcqUnit->SetPrevImageInfo(m_stDeviceConfig.bPreviewEnable, m_stDeviceConfig.nPreviewHeight, m_stDeviceConfig.nPreviewWidth, false);
  1474. if (m_pDetectors->SelectExamMode(nAcqMode, this))
  1475. {
  1476. return RET_STATUS::RET_SUCCEED;
  1477. }
  1478. return RET_STATUS::RET_FAILED;
  1479. }
  1480. //设置采集模式
  1481. RET_STATUS nsFPD::FPDDeviceTrixell::SetAcqMode(int nMode)
  1482. {
  1483. Info("nsFPD::FPDDeviceTrixell::SetAcqMode");
  1484. if (!m_stDeviceConfig.bConnectStatus)
  1485. {
  1486. Error("m_stDeviceConfig.bConnectStatus = false");
  1487. return RET_STATUS::RET_FAILED;
  1488. }
  1489. int nWidth = m_stDeviceConfig.nFullImageWidth;
  1490. int nHeight = m_stDeviceConfig.nFullImageHeight;
  1491. int nBit = m_stDeviceConfig.nImageBits;
  1492. Info("ImageSize({$} {$}), bits({$})", nWidth, nHeight, nBit);
  1493. m_AcqUnit->SetFulImageInfo(nHeight, nWidth, nBit, false);
  1494. m_AcqUnit->SetPrevImageInfo(m_stDeviceConfig.bPreviewEnable, m_stDeviceConfig.nPreviewHeight, m_stDeviceConfig.nPreviewWidth, false);
  1495. if (m_pDetectors->SelectExamMode(1, this))
  1496. {
  1497. return RET_STATUS::RET_SUCCEED;
  1498. }
  1499. return RET_STATUS::RET_FAILED;
  1500. }
  1501. void nsFPD::FPDDeviceTrixell::OnFPDCallback(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1502. {
  1503. switch (nEventLevel)
  1504. {
  1505. case EVT_LEVEL_CONFIGURATION:
  1506. {
  1507. OnEventProcessConf(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1508. break;
  1509. }
  1510. case EVT_LEVEL_INFORMATOION:
  1511. {
  1512. OnEventProcessInfo(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1513. break;
  1514. }
  1515. case EVT_LEVEL_STATUS:
  1516. {
  1517. OnEventProcessStatus(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1518. break;
  1519. }
  1520. case EVT_LEVEL_DATA:
  1521. {
  1522. OnEventProcessData(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1523. break;
  1524. }
  1525. case EVT_LEVEL_WARNING:
  1526. {
  1527. OnEventProcessWarning(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1528. break;
  1529. }
  1530. case EVT_LEVEL_ERROR:
  1531. {
  1532. OnEventProcessError(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1533. break;
  1534. }
  1535. default:
  1536. break;
  1537. }
  1538. }
  1539. void nsFPD::FPDDeviceTrixell::OnEventProcessConf(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1540. {
  1541. switch (nEventID)
  1542. {
  1543. case EVT_CONF_PANEL_SERIAL:
  1544. {
  1545. m_stDeviceConfig.strPanelSerial = pszMsg;
  1546. Info("Receive Panel {$} SN {$}", nDetectorID, pszMsg);
  1547. m_DetectorCtrlUnit->SetDetectorID(m_stDeviceConfig.strPanelSerial);
  1548. break;
  1549. }
  1550. case EVT_CONF_RAW_WIDTH:
  1551. {
  1552. if (m_stDeviceConfig.nFullImageWidth != nParam1)
  1553. {
  1554. m_stDeviceConfig.nFullImageWidth = nParam1;
  1555. }
  1556. Info("Panel {$} nRawWidth:{$}", nDetectorID, m_stDeviceConfig.nRawWidth);
  1557. break;
  1558. }
  1559. case EVT_CONF_RAW_HIGHT:
  1560. {
  1561. if (m_stDeviceConfig.nFullImageHeight != nParam1)
  1562. {
  1563. m_stDeviceConfig.nFullImageHeight = nParam1;
  1564. }
  1565. Info("Panel {$} nRawHeight:{$}", nDetectorID, m_stDeviceConfig.nRawHeight);
  1566. break;
  1567. }
  1568. case EVT_CONF_RAW_BITS:
  1569. {
  1570. m_stDeviceConfig.nImageBits = nParam1;
  1571. Info("Panel {$} nImageBits:{$}", nDetectorID, m_stDeviceConfig.nImageBits);
  1572. break;
  1573. }
  1574. case EVT_CONF_PIXELSPACE:
  1575. {
  1576. m_stDeviceConfig.nPixelSpace = (int)fParam2;
  1577. Info( "Panel {$} nPixelSpace:{$}", nDetectorID, m_stDeviceConfig.nPixelSpace);
  1578. break;
  1579. }
  1580. case EVT_CONF_PREVIEW_WIDTH:
  1581. {
  1582. if (m_stDeviceConfig.nPreviewWidth != nParam1)
  1583. {
  1584. m_stDeviceConfig.nPreviewWidth = nParam1;
  1585. }
  1586. Info("Panel {$} nPreviewWidth:{$}", nDetectorID, m_stDeviceConfig.nPreviewWidth);
  1587. break;
  1588. }
  1589. case EVT_CONF_PREVIEW_HIGHT:
  1590. {
  1591. if (m_stDeviceConfig.nPreviewHeight != nParam1)
  1592. {
  1593. m_stDeviceConfig.nPreviewHeight = nParam1;
  1594. }
  1595. Info("Panel {$} nPreviewHeight:{$}", nDetectorID, m_stDeviceConfig.nPreviewHeight);
  1596. break;
  1597. }
  1598. case EVT_CONF_MODULE_TYPE:
  1599. {
  1600. //m_strModuleType = pszMsg;
  1601. Info("Receive Panel {$} ModuleType {$}", nDetectorID, pszMsg);
  1602. break;
  1603. }
  1604. case EVT_CONF_MODULE_IP:
  1605. {
  1606. //m_strModuleIP = pszMsg;
  1607. Info("Receive Panel {$} ModuleIP {$}", nDetectorID, pszMsg);
  1608. break;
  1609. }
  1610. case EVT_CONF_MODULE_SN:
  1611. {
  1612. //m_strModuleSN = pszMsg;
  1613. Info("Receive Panel {$} ModuleSN {$}", nDetectorID, pszMsg);
  1614. break;
  1615. }
  1616. case EVT_CONF_FIRWARE_UPDATE:
  1617. {
  1618. m_stDeviceConfig.nFirmwareStatus = nParam1;
  1619. Info("Panel {$} FirmwareUpdate:{$}", nDetectorID, m_stDeviceConfig.nFirmwareStatus);
  1620. break;
  1621. }
  1622. case EVT_CONF_PART_NUMBER:
  1623. {
  1624. m_stDeviceConfig.strPartNumber = pszMsg;
  1625. Info("Panel {$} PartNumber:{$}", nDetectorID, pszMsg);
  1626. break;
  1627. }
  1628. case EVT_CONF_BATTERY_SN:
  1629. {
  1630. Info("Panel {$} Battery SN:{$}", nDetectorID, pszMsg);
  1631. break;
  1632. }
  1633. case EVT_CONF_WIFI_SSID:
  1634. {
  1635. m_stDeviceConfig.strWifiSSID = pszMsg;
  1636. Info("Panel {$} WifiSSID:{$}", nDetectorID, pszMsg);
  1637. break;
  1638. }
  1639. case EVT_CONF_IFBOARD:
  1640. {
  1641. Info("Panel {$} InterfaceBoard:{$}", nDetectorID, pszMsg);
  1642. break;
  1643. }
  1644. case EVT_CONF_DATECODE:
  1645. {
  1646. Info("Panel {$} DateCode:{$}", nDetectorID, pszMsg);
  1647. break;
  1648. }
  1649. case EVT_CONF_LIFETIME:
  1650. {
  1651. int nLifeTime = nParam1;
  1652. if ((nLifeTime != m_stDeviceConfig.nLifeTime))
  1653. {
  1654. Info("LifeTime:{$}", nLifeTime);
  1655. m_stDeviceConfig.nLifeTime = nLifeTime;
  1656. }
  1657. break;
  1658. }
  1659. default:
  1660. break;
  1661. }
  1662. }
  1663. void nsFPD::FPDDeviceTrixell::OnEventProcessInfo(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1664. {
  1665. int nID = nDetectorID;
  1666. switch (nEventID)
  1667. {
  1668. case EVT_INFO_POWER_ON:
  1669. {
  1670. int nPowerOn = nParam1;
  1671. Info("Detector {$} PowerOn:{$}", nID, nPowerOn);
  1672. if ((nPowerOn != m_stDeviceConfig.nPowerOn))
  1673. {
  1674. m_stDeviceConfig.nPowerOn = nPowerOn;
  1675. }
  1676. break;
  1677. }
  1678. case EVT_INFO_BATTERY_CAPACITY:
  1679. {
  1680. int nBatteryCapacity = nParam1;
  1681. if ((nBatteryCapacity != m_nBatteryCapacity))
  1682. {
  1683. Info("{$}", nBatteryCapacity);
  1684. m_nBatteryCapacity = nBatteryCapacity;
  1685. }
  1686. break;
  1687. }
  1688. case EVT_INFO_BATTERY_TEMPERATURE:
  1689. {
  1690. Info("Battery temperature: {$}", fParam2);
  1691. break;
  1692. }
  1693. case EVT_INFO_BATTERY_CHARGES:
  1694. {
  1695. int nBatteryCharges = nParam1;
  1696. if (nBatteryCharges != m_nBatteryCharges)
  1697. {
  1698. Info("Charge number:{$}", nBatteryCharges);
  1699. m_nBatteryCharges = nBatteryCharges;
  1700. }
  1701. break;
  1702. }
  1703. case EVT_INFO_WIFI_DATARATE:
  1704. {
  1705. m_stDeviceConfig.nWifiDataRate = nParam1;
  1706. Info("Detector {$} WifiDataRate:{$}", nID, m_stDeviceConfig.nWifiDataRate);
  1707. break;
  1708. }
  1709. case EVT_INFO_WIFI_CHANNEL:
  1710. {
  1711. m_stDeviceConfig.nWifiChannel = nParam1;
  1712. Info("Panel {$} WifiChannel:{$}", nID, m_stDeviceConfig.nWifiChannel);
  1713. break;
  1714. }
  1715. case EVT_INFO_WIFI_SIGNALPOWER:
  1716. {
  1717. m_stDeviceConfig.nWifiSignalPower = nParam1;
  1718. break;
  1719. }
  1720. case EVT_INFO_WIFI_NOISEPOWER:
  1721. {
  1722. m_stDeviceConfig.nWifiNoisePower = nParam1;
  1723. Info("Panel {$} WifiNoisePower:{$}", nID, m_stDeviceConfig.nWifiNoisePower);
  1724. break;
  1725. }
  1726. case EVT_INFO_FIRMWARE:
  1727. {
  1728. m_stDeviceConfig.strFirmware = pszMsg;
  1729. Info("Panel {$} Firmware:{$}", nID, pszMsg);
  1730. break;
  1731. }
  1732. case EVT_INFO_SHOCKSENSOR_INFO:
  1733. {
  1734. Info("Receive ShockSensor Info");
  1735. break;
  1736. }
  1737. case EVT_INFO_CALIBRATIOIN_TIME:
  1738. {
  1739. m_stDeviceConfig.strCalibrationDate = pszMsg;
  1740. Info("Panel {$} Calibration Time:{$}", nID, pszMsg);
  1741. m_DetectorCtrlUnit->SetDateofLastDetectorCalibration(m_stDeviceConfig.strCalibrationDate);
  1742. m_DetectorCtrlUnit->SetTimeofLastDetectorCalibration("");
  1743. break;
  1744. }
  1745. case EVT_INFO_CALIBRATIOIN_TIMEL:
  1746. {
  1747. Info("Panel {$} Calibration LTE Time:{$}", nID, pszMsg);
  1748. break;
  1749. }
  1750. case EVT_INFO_FPVOLTAGE:
  1751. {
  1752. break;
  1753. }
  1754. default:
  1755. break;
  1756. }
  1757. }
  1758. void nsFPD::FPDDeviceTrixell::OnEventProcessStatus(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1759. {
  1760. int nID = nDetectorID;
  1761. switch (nEventID)
  1762. {
  1763. case EVT_STATUS_INIT:
  1764. {
  1765. string strPath = m_strWorkPath + "\\OEMDrivers\\Detector\\Trixell\\TrixellDRDetector\\PIXIUMAPI\\pixrad.dll";
  1766. m_stDeviceConfig.strSoftware = GetFileVersion(strPath);
  1767. Info("pixrad.dll version : {$} init staus {$}", m_stDeviceConfig.strSoftware.c_str(), nParam1);
  1768. printf("-------- pixrad EVT_STATUS_INIT %d \n", nParam1);
  1769. if (PANEL_EVENT_END_OK == nParam1)
  1770. {
  1771. OnInitResult(true);
  1772. m_DetectorCtrlUnit->SetInitialStatus(to_string(DETECTOR_INI_SUCCESS));
  1773. Info("connect FPD ok. Start Status Polling");
  1774. }
  1775. else if (PANEL_EVENT_END_ERROR == nParam1)
  1776. {
  1777. OnInitResult(false);
  1778. m_DetectorCtrlUnit->SetInitialStatus(to_string(DETECTOR_INI_FAILED));
  1779. }
  1780. else if (PANEL_EVENT_END == nParam1) //未连接探测器
  1781. {
  1782. m_DetectorCtrlUnit->SetInitialStatus(to_string(DETECTOR_INI_SUCCESS));
  1783. }
  1784. else if (PANEL_EVENT_START == nParam1)
  1785. {
  1786. m_DetectorCtrlUnit->SetInitialStatus(to_string(DETECTOR_INI_START));
  1787. }
  1788. break;
  1789. }
  1790. case EVT_STATUS_MOTION:
  1791. {
  1792. break;
  1793. }
  1794. case EVT_STATUS_UPDATE_FIRMWARE:
  1795. {
  1796. if (PANEL_EVENT_START == nParam1)
  1797. {
  1798. Info("Start update firmware");
  1799. m_DetectorCtrlUnit->SetUpdateFWStatus(to_string(DETECTOR_UFW_START));
  1800. }
  1801. else if (PANEL_EVENT_BEGIN == nParam1)
  1802. {
  1803. Info("Update firmware begin");
  1804. m_stDeviceConfig.bConnectStatus = false;
  1805. }
  1806. else if (PANEL_EVENT_END_ERROR == nParam1)
  1807. {
  1808. Info("Update firmware failed");
  1809. //SendDetectorInfo(); //更新探测器状态图标
  1810. m_DetectorCtrlUnit->SetUpdateFWStatus(to_string(DETECTOR_UFW_ERROR));
  1811. }
  1812. else if (PANEL_EVENT_SUCCESS == nParam1)
  1813. {
  1814. Info("update firmware success");
  1815. //SendDetectorInfo();
  1816. m_DetectorCtrlUnit->SetUpdateFWStatus(to_string(DETECTOR_UFW_SUCCESS));
  1817. }
  1818. break;
  1819. }
  1820. case EVT_STATUS_SELFTEST:
  1821. {
  1822. break;
  1823. }
  1824. case EVT_STATUS_DETECTORSHARE:
  1825. {
  1826. break;
  1827. }
  1828. case EVT_STATUS_SINGLEINIT:
  1829. {
  1830. break;
  1831. }
  1832. case EVT_STATUS_SELECTPANEL:
  1833. {
  1834. break;
  1835. }
  1836. case EVT_STATUS_PANEL:
  1837. {
  1838. ENUM_PANEL_STATUS m_ePanelStatus = (ENUM_PANEL_STATUS)nParam1;
  1839. if (PANEL_STANDBY == nParam1)
  1840. {
  1841. Info("Panel Status:PREPARE");
  1842. }
  1843. else if (PANEL_READY_EXP == nParam1)
  1844. {
  1845. Info("Panel Status:READY");
  1846. Action_ExpReady();
  1847. }
  1848. else if (PANEL_OFFSET_CAL == nParam1)
  1849. {
  1850. Info("Panel Status:PANEL_OFFSET_CAL");
  1851. }
  1852. else if (PANEL_OFFSET_FINISH == nParam1)
  1853. {
  1854. Info("Panel Status:PANEL_OFFSET_FINISH");
  1855. }
  1856. else if (PANEL_XWINDOW_ON == nParam1) //Xwindow On
  1857. {
  1858. Info("Panel Status:XWINDOW_ON");
  1859. XWindowOnNotify();
  1860. }
  1861. else if (PANEL_XWINDOW_OFF == nParam1) // Xwindow Off
  1862. {
  1863. Info("Panel Status:XWINDOW_OFF");
  1864. XWindowOffNotify();
  1865. if (APP_STATUS_CAL_BEGIN == m_eAppStatus)
  1866. {
  1867. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1868. }
  1869. }
  1870. else if (PANEL_GET_IMAGE == nParam1)
  1871. {
  1872. Info("Panel Status: PANEL_GET_IMAGE");
  1873. }
  1874. else if (PANEL_GAIN_FINISH == nParam1)
  1875. {
  1876. Info("Panel Status:CALIBRATION_FINISH");
  1877. }
  1878. else if (PANEL_GAIN_PREPARE == nParam1)
  1879. {
  1880. Info("Detector Notify Xray Prepare");
  1881. }
  1882. else if (PANEL_GAIN_READY_EXP == nParam1)
  1883. {
  1884. Action_ExpReady();
  1885. }
  1886. else if (PANEL_AED_XRAY_ON == nParam1)
  1887. {
  1888. Info("AED xray on");
  1889. m_SyncUnit->XrayOnNotify();
  1890. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_ACQ));
  1891. }
  1892. else if (PANEL_AED_XRAY_OFF == nParam1)
  1893. {
  1894. Info("AED xray off");
  1895. m_SyncUnit->XrayOffNotify();
  1896. }
  1897. else
  1898. {
  1899. Info("Panel {$} Status is :{$}", nID, (int)m_ePanelStatus);
  1900. }
  1901. break;
  1902. }
  1903. case EVT_STATUS_CALIBRATIOIN:
  1904. {
  1905. ENUM_PANEL_EVENT_STATE eStatus = (ENUM_PANEL_EVENT_STATE)nParam1;
  1906. switch (eStatus)
  1907. {
  1908. case PANEL_EVENT_START:
  1909. break;
  1910. case PANEL_EVENT_END_OK:
  1911. Info("Calibration process is success");
  1912. CompleteCalibration();
  1913. break;
  1914. case PANEL_EVENT_END_ERROR:
  1915. Info("Calibration process is failed");
  1916. break;
  1917. case PANEL_EVENT_TIMEOUT:
  1918. Info("Calibration timeout");
  1919. Info("Calibration process is failed");
  1920. break;
  1921. default:
  1922. break;
  1923. }
  1924. break;
  1925. }
  1926. case EVT_STATUS_SAVECALIB:
  1927. {
  1928. if (PANEL_EVENT_START == nParam1)
  1929. {
  1930. Info("Begin to Save Calibration Files");
  1931. }
  1932. else if (PANEL_EVENT_END_ERROR == nParam1)
  1933. {
  1934. SetEvent(m_UploadCalibMapOver);
  1935. Info("Save Calibration Files failed");
  1936. }
  1937. else if (PANEL_EVENT_END == nParam1)
  1938. {
  1939. SetEvent(m_UploadCalibMapOver);
  1940. Info("Save Calibration Files Success");
  1941. }
  1942. break;
  1943. }
  1944. case EVT_STATUS_SAVEDEFECT:
  1945. {
  1946. if (PANEL_EVENT_START == nParam1)
  1947. {
  1948. Info("Begin to Save Defect Files");
  1949. }
  1950. else if (PANEL_EVENT_END_ERROR == nParam1)
  1951. {
  1952. SetEvent(m_UploadCalibMapOver);
  1953. Info("Save Defect Files failed");
  1954. }
  1955. else if (PANEL_EVENT_END == nParam1)
  1956. {
  1957. m_stDeviceConfig.bTaskEnd = true;
  1958. Info("Save Defect Files Success");
  1959. SetEvent(m_UploadCalibMapOver);
  1960. }
  1961. break;
  1962. }
  1963. case EVT_STATUS_ACQUISITION:
  1964. {
  1965. ENUM_PANEL_EVENT_STATE eStatus = (ENUM_PANEL_EVENT_STATE)nParam1;
  1966. switch (eStatus)
  1967. {
  1968. case PANEL_EVENT_START:
  1969. break;
  1970. case PANEL_EVENT_END_OK:
  1971. break;
  1972. case PANEL_EVENT_END_ERROR:
  1973. break;
  1974. default:
  1975. break;
  1976. }
  1977. break;
  1978. }
  1979. case EVT_STATUS_SINGLEEXP:
  1980. {
  1981. if (DOSE_TOO_HIGH == nParam1)
  1982. {
  1983. Info("Dose too high");
  1984. OnError(nID, "ERR_FPD_DOSE_INVALID", m_strLastError);
  1985. StopCalibration();
  1986. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY));
  1987. m_CalibUnit->SetCalibrationProgress("100");
  1988. m_AcqUnit->SendNoNeedWaitImage(true);
  1989. }
  1990. else if (DOSE_TOO_LOW == nParam1)
  1991. {
  1992. Info("Dose too low");
  1993. OnError(nID, "ERR_FPD_DOSE_INVALID", m_strLastError);
  1994. StopCalibration();
  1995. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY));
  1996. m_CalibUnit->SetCalibrationProgress("100");
  1997. m_AcqUnit->SendNoNeedWaitImage(true);
  1998. }
  1999. else if (DOSE_OBJECT == nParam1)
  2000. {
  2001. Info("Dose object");
  2002. OnError(nID, "ERR_FPD_DOSE_INVALID", m_strLastError);
  2003. StopCalibration();
  2004. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY));
  2005. m_AcqUnit->SendNoNeedWaitImage(true);
  2006. }
  2007. else if (DOSE_ACCEPT == nParam1)
  2008. {
  2009. Info("Calibration Result is acceptable");
  2010. SetEvent(m_PauseCalibrationEvt);
  2011. }
  2012. else if (EVT_STATUS_LASTERROR == nParam1)
  2013. {
  2014. m_strLastError = pszMsg;
  2015. Info("Panel {$} LastError {$}", nID, pszMsg);
  2016. }
  2017. //endif
  2018. break;
  2019. }
  2020. case EVT_STATUS_IMAGEPENDING:
  2021. {
  2022. string strTemp = pszMsg;
  2023. if (strTemp.find("true") != std::string::npos)
  2024. {
  2025. m_bImagePendingOrNot = true;
  2026. }
  2027. else
  2028. {
  2029. m_bImagePendingOrNot = false;
  2030. }
  2031. if (m_bImagePendingOrNot) // && !m_bResetDetector
  2032. {
  2033. OnError(nID, "ERR_FPD_IMAGE_PENDING");
  2034. }
  2035. else
  2036. {
  2037. m_bResetDetector = false;//可以再次reset
  2038. }
  2039. break;
  2040. }
  2041. case EVT_STATUS_TEMPERATURE:
  2042. {
  2043. float fTemperature = fParam2;
  2044. OnProcessTemperature(nID, fTemperature);
  2045. m_stDeviceConfig.fCurrentTemperValue = fTemperature;
  2046. SendTemperatureValue();
  2047. break;
  2048. }
  2049. case EVT_STATUS_WIFI:
  2050. {
  2051. int nWifiLevel = nParam1;
  2052. if (m_stDeviceConfig.strDeviceName.find("3543DR") >= 0)
  2053. {
  2054. nWifiLevel = int(nWifiLevel / 0.75);
  2055. if (nWifiLevel > 100)
  2056. {
  2057. nWifiLevel = 100;
  2058. }
  2059. }
  2060. Info("Detector {$} Wifi Value:{$}", nID, nWifiLevel);
  2061. if (nWifiLevel == 0) //WIFI值为0 表明是有线连接,不报错
  2062. {
  2063. ClearError(nID, ERR_FPD_WIFI_LOW);
  2064. ClearWarn(nID, WAR_FPD_WIFI_LOW);
  2065. }
  2066. else if (nWifiLevel < m_stDeviceConfig.nWifiLimit)
  2067. {
  2068. ClearWarn(nID, WAR_FPD_WIFI_LOW);
  2069. OnError(nID, ERR_FPD_WIFI_LOW);
  2070. }
  2071. else if (nWifiLevel <= m_stDeviceConfig.nWifiWarning)
  2072. {
  2073. ClearError(nID, ERR_FPD_WIFI_LOW);
  2074. OnWarn(nID, WAR_FPD_WIFI_LOW);
  2075. }
  2076. else
  2077. {
  2078. ClearWarn(nID, WAR_FPD_WIFI_LOW);
  2079. ClearError(nID, ERR_FPD_WIFI_LOW);
  2080. }
  2081. if (nWifiLevel != m_stDeviceConfig.nCurrentWifiValue)
  2082. {
  2083. Info("Channel:{$},SignalPower:{$},NoisePower:{$},DataRate:{$}", m_stDeviceConfig.nWifiChannel, m_stDeviceConfig.nWifiSignalPower, m_stDeviceConfig.nWifiNoisePower, m_stDeviceConfig.nWifiDataRate);
  2084. }
  2085. //endif
  2086. m_stDeviceConfig.nCurrentWifiValue = nWifiLevel;
  2087. SendWifiValue();
  2088. //SendDetectorInfo();
  2089. break;
  2090. }
  2091. case EVT_STATUS_BATTERY_VALUE:
  2092. {
  2093. int nBatteryValue = nParam1;
  2094. Info("Detector {$} Battery:{$}", nID, nParam1);
  2095. if (nBatteryValue < m_stDeviceConfig.nBatteryLimit)
  2096. {
  2097. //battery error
  2098. ClearWarn(nID, WAR_FPD_BATTERY_LOW);
  2099. OnError(nID, ERR_FPD_BATTERY_LOW);
  2100. }
  2101. else if (nBatteryValue < m_stDeviceConfig.nBatteryWarning)
  2102. {
  2103. //battery warning
  2104. ClearError(nID, ERR_FPD_BATTERY_LOW);
  2105. OnWarn(nID, WAR_FPD_BATTERY_LOW);
  2106. }
  2107. else
  2108. {
  2109. ClearWarn(nID, WAR_FPD_BATTERY_LOW);
  2110. ClearError(nID, ERR_FPD_BATTERY_LOW);
  2111. }
  2112. m_stDeviceConfig.nCurrentBatteryValue = nBatteryValue;
  2113. Info("Detector {$} Battery Value:{$}", nID, nBatteryValue);
  2114. SendBatteryValue();
  2115. break;
  2116. }
  2117. case EVT_STATUS_BATTERY_CHARGING:
  2118. {
  2119. string strTemp = pszMsg;
  2120. if (strTemp.find("true") != std::string::npos)
  2121. {
  2122. m_bBatteryCharging = true;
  2123. }
  2124. else
  2125. {
  2126. m_bBatteryCharging = false;
  2127. }
  2128. break;
  2129. }
  2130. case EVT_STATUS_SHOCK_SENSOR:
  2131. {
  2132. break;
  2133. }
  2134. case EVT_STATUS_HALL_SENSOR:
  2135. {
  2136. break;
  2137. }
  2138. case EVT_STATUS_PING:
  2139. {
  2140. break;
  2141. }
  2142. case EVT_STATUS_RESTOREFILES:
  2143. {
  2144. break;
  2145. }
  2146. case EVT_STATUS_LASTERROR:
  2147. {
  2148. m_strLastError = pszMsg;
  2149. Info("Panel {$} LastError {$}", nID, pszMsg);
  2150. break;
  2151. }
  2152. case EVT_STATUS_RESET:
  2153. {
  2154. Info("Detector reset status: {$}", nParam1);
  2155. break;
  2156. }
  2157. case EVT_AUTONUMOUS_STATUS:
  2158. {
  2159. ENUM_PANEL_EVENT_STATE eStatus = (ENUM_PANEL_EVENT_STATE)nParam1;
  2160. switch (eStatus)
  2161. {
  2162. case PANEL_CONNECT_ERROR:
  2163. {
  2164. break;
  2165. }
  2166. case PANEL_CONNECT_OK:
  2167. {
  2168. m_stDeviceConfig.bConnectStatus = true;
  2169. break;
  2170. }
  2171. case PANEL_DISCONNECT_SUCCESS:
  2172. {
  2173. m_nBatteryCapacity = 0;
  2174. m_stDeviceConfig.bExisted = false;
  2175. m_stDeviceConfig.bConnectStatus = false;
  2176. break;
  2177. }
  2178. case PANEL_DISCONNECT_ERROR:
  2179. {
  2180. break;
  2181. }
  2182. case PANEL_START_STOREDIMAGE:
  2183. {
  2184. Info("Send start autonumous to server");
  2185. m_AcqUnit->SendAutonumousMapFinish(0);
  2186. break;
  2187. }
  2188. case PANEL_END_STOREDIMAGE:
  2189. {
  2190. Info("Send finish autonumous to server");
  2191. m_AcqUnit->SendAutonumousMapFinish(1);
  2192. break;
  2193. }
  2194. case PANEL_EXPORT_AUTONUMOUS_FINISH:
  2195. {
  2196. Info("Send finish export local autonumous to server");
  2197. m_AcqUnit->SendAutonumousMapFinish(2);
  2198. break;
  2199. }
  2200. default:
  2201. break;
  2202. }
  2203. break;
  2204. }
  2205. default:
  2206. break;
  2207. }
  2208. }
  2209. void nsFPD::FPDDeviceTrixell::OnEventProcessData(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  2210. {
  2211. switch (nEventID)
  2212. {
  2213. case EVT_DATA_RAW_IMAGE:
  2214. {
  2215. Info("EVT_DATA_RAW_IMAGE");
  2216. Info("Currenct Image Width:{$}, Height:{$}", m_stDeviceConfig.nFullImageWidth, m_stDeviceConfig.nFullImageHeight);
  2217. float fImageReferUGY = 2.5;
  2218. if (APP_STATUS_WORK_BEGIN == m_eAppStatus) //如果是在检查中
  2219. {
  2220. fImageReferUGY = 2.5;
  2221. }
  2222. if (NULL == m_pwRawImageData)
  2223. {
  2224. m_pwRawImageData = new WORD[m_stDeviceConfig.nFullImageWidth * m_stDeviceConfig.nFullImageHeight];
  2225. }
  2226. memcpy(m_pwRawImageData, pParam, m_stDeviceConfig.nFullImageWidth * m_stDeviceConfig.nFullImageHeight * sizeof(WORD));
  2227. OnProcessImage(m_pwRawImageData, m_stDeviceConfig.nFullImageWidth, m_stDeviceConfig.nFullImageHeight, fImageReferUGY);
  2228. break;
  2229. }
  2230. case EVT_DATA_PREVIEW_IMAGE:
  2231. {
  2232. Info("Preview Image Arrved");
  2233. Info("Current FPD preview image width: {$}, height: {$}", m_stDeviceConfig.nPreviewWidth, m_stDeviceConfig.nPreviewHeight);
  2234. m_SyncUnit->ImageReadingNotify();
  2235. if (NULL == m_pwPreviewImg)
  2236. {
  2237. m_pwPreviewImg = new WORD[m_stDeviceConfig.nPreviewWidth * m_stDeviceConfig.nPreviewHeight];
  2238. }
  2239. memcpy(m_pwPreviewImg, pParam, m_stDeviceConfig.nPreviewWidth * m_stDeviceConfig.nPreviewHeight * sizeof(WORD));
  2240. OnProcessPreviewImage(m_pwPreviewImg, m_stDeviceConfig.nPreviewWidth, m_stDeviceConfig.nPreviewHeight);
  2241. break;
  2242. }
  2243. case EVT_DATA_DOSEPARAM:
  2244. {
  2245. m_fDoseParam = fParam2;
  2246. SetEvent(m_WaitCalibDoseEvt);
  2247. break;
  2248. }
  2249. default:
  2250. break;
  2251. }
  2252. }
  2253. void nsFPD::FPDDeviceTrixell::OnEventProcessError(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  2254. {
  2255. string strErrorName = "";
  2256. switch (nEventID)
  2257. {
  2258. case EVT_ERR_COMMUNICATE:
  2259. {
  2260. string strTemp = pszMsg;
  2261. if (strTemp.find("true") != std::string::npos)
  2262. {
  2263. m_stDeviceConfig.nWorkstation = -1;
  2264. m_stDeviceConfig.bConnectStatus = false;
  2265. m_nBatteryCapacity = 0;
  2266. m_stDeviceConfig.fCurrentTemperValue = 0.0f;
  2267. m_stDeviceConfig.nCurrentWifiValue = 0;
  2268. m_stDeviceConfig.nCurrentBatteryValue = 0;
  2269. SendWifiValue();
  2270. SendBatteryValue();
  2271. SendTemperatureValue();
  2272. OnError(nDetectorID, ERR_FPD_DISCONNECT, "");
  2273. m_DetectorCtrlUnit->SetConnectStatus(to_string(PANEL_CONNECT_ERROR));
  2274. }
  2275. else if (strTemp.find("false") != std::string::npos)//成功时交给WIFI发送SendDetectorInfo
  2276. {
  2277. m_stDeviceConfig.bConnectStatus = true;
  2278. ClearError(nDetectorID, ERR_FPD_DISCONNECT);
  2279. m_DetectorCtrlUnit->SetConnectStatus(to_string(PANEL_CONNECT_OK));
  2280. }
  2281. break;
  2282. }
  2283. case EVT_ERR_EXP_REQUEST:
  2284. {
  2285. string strTemp = pszMsg;
  2286. if (strTemp.find("true") != std::string::npos)
  2287. {
  2288. }
  2289. else
  2290. {
  2291. return;
  2292. }
  2293. strErrorName = "ERR_FPD_ACQ_FAILED";
  2294. break;
  2295. }
  2296. case EVT_ERR_GET_IMAGE:
  2297. {
  2298. string strTemp = pszMsg;
  2299. if (strTemp.find("true") != std::string::npos)
  2300. {
  2301. if (APP_STATUS_WORK_BEGIN != m_eAppStatus) //如果不在检查界面;
  2302. {
  2303. Fatal("there are image exist in current detector,do you want to continue");
  2304. }
  2305. else //if (m_bSiemensCmd)
  2306. {
  2307. Fatal("FPD has exposed Image!");
  2308. //CallSiemensRecoverAction(true);
  2309. }
  2310. //endif
  2311. }
  2312. else if (strTemp.find("false") != std::string::npos)
  2313. {
  2314. //CallSiemensRecoverAction(false);
  2315. }
  2316. break;
  2317. }
  2318. case EVT_ERR_MAX_NUMBER:
  2319. {
  2320. //strErrorName = ERR_FPD_MAX_NUMBER;
  2321. //string strTemp = pszMsg;
  2322. //if (strTemp.find("true") != std::string::npos)
  2323. //{
  2324. // Error("Exceed max number");
  2325. // OnError(nDetectorID, strErrorName);
  2326. //}
  2327. break;
  2328. }
  2329. case EVT_ERR_SN_NOTINLIST:
  2330. {
  2331. //strErrorName = ERR_FPD_SN_NOT_LIST;
  2332. //Error("Not in List");
  2333. //string strTemp = pszMsg;
  2334. //if (strTemp.find("true") != std::string::npos)
  2335. //{
  2336. // OnError(nDetectorID, strErrorName);
  2337. //}
  2338. break;
  2339. }
  2340. case EVT_ERR_POWER_OFF:
  2341. {
  2342. strErrorName = "ERR_FPD_POWEROFF";
  2343. string strTemp = pszMsg;
  2344. if (strTemp.find("true") != std::string::npos)
  2345. {
  2346. OnError(nDetectorID, strErrorName);
  2347. m_stDeviceConfig.bConnectStatus = false;
  2348. }
  2349. else if (strTemp.find("false") != std::string::npos)
  2350. {
  2351. m_WarnAndError->ClearError(strErrorName);
  2352. }
  2353. break;
  2354. }
  2355. case EVT_ERR_INIT_FAILED:
  2356. {
  2357. strErrorName = "ERR_FPD_FATAL_ERROR";
  2358. string strTemp = pszMsg;
  2359. if (strTemp.find("true") != std::string::npos)
  2360. {
  2361. OnError(nDetectorID, strErrorName);
  2362. m_stDeviceConfig.bConnectStatus = false;
  2363. }
  2364. else if (strTemp.find("false") != std::string::npos)
  2365. {
  2366. //m_WarnAndError->OnErrorX(strErrorName);
  2367. }
  2368. break;
  2369. }
  2370. default:
  2371. break;
  2372. }
  2373. }
  2374. void nsFPD::FPDDeviceTrixell::OnEventProcessWarning(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  2375. {
  2376. Warn("Not support this warn({$})", nEventID);
  2377. }
  2378. bool nsFPD::FPDDeviceTrixell::OnInitResult(bool bSuccess)
  2379. {
  2380. if (bSuccess)
  2381. {
  2382. m_stDeviceConfig.bConnectStatus = true;
  2383. //CheckCalibartionDue();
  2384. //LoadSensitivity();
  2385. }
  2386. else
  2387. {
  2388. m_stDeviceConfig.bConnectStatus = false;
  2389. }
  2390. m_stDeviceConfig.bExisted = true;
  2391. return true;
  2392. }
  2393. bool nsFPD::FPDDeviceTrixell::OnProcessPreviewImage(WORD* pwRawImage, int nWidth, int nHeight)
  2394. {
  2395. Info("Currenct PreviewImage Width:{$},Height:{$}", m_stDeviceConfig.nPreviewWidth, m_stDeviceConfig.nPreviewHeight);
  2396. PrevImageDateArrived(pwRawImage);
  2397. Info("Write PreviewImage Over");
  2398. return true;
  2399. }
  2400. bool nsFPD::FPDDeviceTrixell::OnProcessImage(WORD* pwRawImage, int nImageWidth, int nImageHeight, float fImageReferUGY)
  2401. {
  2402. Info("OnProcessImage start");
  2403. if (nImageWidth < m_nFullImgWidth + m_nLeftOffset)
  2404. {
  2405. Info("nImageWidth:{$},m_nFullImgWidth: {$},m_nLeftOffset:{$}", nImageWidth, m_nFullImgWidth, m_nLeftOffset);
  2406. m_nFullImgWidth = nImageWidth;
  2407. m_nLeftOffset = 0;
  2408. }
  2409. if (nImageHeight < m_nFullImgHeight + m_nTopOffset)
  2410. {
  2411. Info("nImageHeight:{$},m_nFullImgHeight: {$},m_nLeftOffset:{$}", nImageHeight, m_nFullImgHeight, m_nTopOffset);
  2412. m_nFullImgHeight = nImageHeight;
  2413. m_nTopOffset = 0;
  2414. }
  2415. /*bool bResult = GetEffectiveImage(pwRawImage, nImageWidth);
  2416. if (!bResult)
  2417. {
  2418. return true;
  2419. }*/
  2420. //m_pwFullImageData[0] = 65535;//坐标原点 bug 8164
  2421. //FullImageDateArrived(m_pwFullImageData);
  2422. FullImageDateArrived(pwRawImage);
  2423. Info("Write Frame Over");
  2424. Info("OnProcessImage end");
  2425. return true;
  2426. }
  2427. /***************************************************************
  2428. 功能:将原始尺寸的图像裁剪为有效尺寸的图像
  2429. [IN][OUT]:pOutImg 有效尺寸图像信息
  2430. [IN]:pInImgData 原始尺寸图像数据
  2431. [IN]:nInWidth 原始尺寸图像的宽度
  2432. [IN]:nUpHeightOffset 要裁剪的上边高度
  2433. [IN]:nLeftWidthOffset要裁剪的左边宽度
  2434. ************************************************************/
  2435. bool nsFPD::FPDDeviceTrixell::GetEffectiveImage(WORD* pwInImgData, int nRawImageWidth)
  2436. {
  2437. if (pwInImgData == NULL)
  2438. {
  2439. return false;
  2440. }
  2441. if (!m_pwFullImageData)
  2442. {
  2443. Info("Full ImgHeight:{$},Full ImgWidth:{$}", m_stDeviceConfig.nFullImageWidth, m_stDeviceConfig.nFullImageHeight);
  2444. m_pwFullImageData = new WORD[m_stDeviceConfig.nFullImageWidth * m_stDeviceConfig.nFullImageHeight];
  2445. }
  2446. memcpy(m_pwFullImageData, pwInImgData, m_stDeviceConfig.nFullImageWidth * m_stDeviceConfig.nFullImageHeight * sizeof(WORD));
  2447. return true;
  2448. try
  2449. {
  2450. Info("TopOffset:{$},LeftOffset:{$},RawImgWidth:{$}", m_nTopOffset, m_nLeftOffset, nRawImageWidth);
  2451. for (int i = 0; i < m_nFullImgHeight; i++)
  2452. {
  2453. memcpy(m_pwFullImageData + i * m_nFullImgWidth,
  2454. pwInImgData + (i + m_nTopOffset) * nRawImageWidth + m_nLeftOffset,
  2455. m_nFullImgWidth * sizeof(WORD));
  2456. }
  2457. }
  2458. catch (...)
  2459. {
  2460. Info("Get Effective Image Crash");
  2461. return false;
  2462. }
  2463. return true;
  2464. }
  2465. void nsFPD::FPDDeviceTrixell::OnProcessTemperature(int nID, float fTemperature)
  2466. {
  2467. if (fTemperature >= m_stDeviceConfig.fTemperMaxLimit)
  2468. {
  2469. Info("Exceed Max Temperature");
  2470. m_stDeviceConfig.nTemperatureStatus = TEMP_TOO_HIGH;
  2471. ClearWarn(nID, WAR_FPD_TEMPERATURE_HIGH);
  2472. ClearWarn(nID, WAR_FPD_TEMPERATURE_LOW);
  2473. ClearError(nID, ERR_FPD_TEMPERATURE_LOW);
  2474. OnError(nID, ERR_FPD_TEMPERATURE_HIGH);
  2475. }
  2476. else if (fTemperature <= m_stDeviceConfig.fTemperMinLimit)
  2477. {
  2478. Info("Exceed Min Temperature");
  2479. m_stDeviceConfig.nTemperatureStatus = TEMP_TOO_LOW;
  2480. ClearWarn(nID, WAR_FPD_TEMPERATURE_HIGH);
  2481. ClearWarn(nID, WAR_FPD_TEMPERATURE_LOW);
  2482. ClearError(nID, ERR_FPD_TEMPERATURE_HIGH);
  2483. OnError(nID, ERR_FPD_TEMPERATURE_LOW);
  2484. }
  2485. else if (fTemperature >= m_stDeviceConfig.fTemperUpperLimit)
  2486. {
  2487. Info("Exceed Temperature High Warning");
  2488. m_stDeviceConfig.nTemperatureStatus = TEMP_WARNING;
  2489. ClearError(nID, ERR_FPD_TEMPERATURE_LOW);
  2490. ClearError(nID, ERR_FPD_TEMPERATURE_HIGH);
  2491. ClearWarn(nID, WAR_FPD_TEMPERATURE_LOW);
  2492. OnWarn(nID, WAR_FPD_TEMPERATURE_HIGH);
  2493. }
  2494. else if (fTemperature <= m_stDeviceConfig.fTemperLowLimit)
  2495. {
  2496. Info("Exceed Temperature Low Warning");
  2497. m_stDeviceConfig.nTemperatureStatus = TEMP_WARNING;
  2498. ClearError(nID, ERR_FPD_TEMPERATURE_LOW);
  2499. ClearError(nID, ERR_FPD_TEMPERATURE_HIGH);
  2500. ClearWarn(nID, WAR_FPD_TEMPERATURE_HIGH);
  2501. OnWarn(nID, WAR_FPD_TEMPERATURE_LOW);
  2502. }
  2503. else if ((fTemperature < m_stDeviceConfig.fTemperUpperLimit) && (fTemperature > m_stDeviceConfig.fTemperLowLimit))
  2504. {
  2505. //Info("Temperature Normal");
  2506. m_stDeviceConfig.nTemperatureStatus = TEMP_NORMAL;
  2507. ClearError(nID, ERR_FPD_TEMPERATURE_LOW);
  2508. ClearError(nID, ERR_FPD_TEMPERATURE_HIGH);
  2509. ClearWarn(nID, WAR_FPD_TEMPERATURE_HIGH);
  2510. ClearWarn(nID, WAR_FPD_TEMPERATURE_LOW);
  2511. }//end if
  2512. }
  2513. void nsFPD::FPDDeviceTrixell::Action_ExpReady()
  2514. {
  2515. m_SyncUnit->FPDReadyNotify(true);
  2516. }
  2517. /***
  2518. * 客户端获取探测器信息
  2519. ***/
  2520. RET_STATUS nsFPD::FPDDeviceTrixell::GetDetectorInfo(string& strFDI)
  2521. {
  2522. ResDataObject strDetectorInfo;
  2523. string strTempTemp = " ";
  2524. Info("Get Detector Info");
  2525. if (m_stDeviceConfig.strPanelSerial == "")
  2526. {
  2527. Info("Get Detector Info Failed, Send Default Info");
  2528. strDetectorInfo.add("DetectorName", "Simulator");
  2529. strDetectorInfo.add("DetectorSN", "Simulator");
  2530. strDetectorInfo.add("Firmware", " ");
  2531. strDetectorInfo.add("APFirmware", " ");
  2532. strDetectorInfo.add("Software", m_stDeviceConfig.strSoftware.c_str());
  2533. strDetectorInfo.add("SSID", " ");
  2534. strDetectorInfo.add("LifeTime", "0");
  2535. strDetectorInfo.add("PowerOn", "0");
  2536. strDetectorInfo.add("DateCode", " ");
  2537. strDetectorInfo.add("PartNumber", " ");
  2538. strDetectorInfo.add("WifiDataRate", " ");
  2539. strDetectorInfo.add("WifiChannel", "0");
  2540. strDetectorInfo.add("DetectorExist", "0");
  2541. strDetectorInfo.add("SystemAS", "0");
  2542. strDetectorInfo.add("CalibrationDate", "0");
  2543. strDetectorInfo.add("CalibrationDue", "0");
  2544. strDetectorInfo.add("CalibrationExist", "0");
  2545. strDetectorInfo.add("CommunicationStatus", "0");
  2546. strDetectorInfo.add("DetectorTemperature", "0");
  2547. strDetectorInfo.add("FDCalibrationTemperature", "0");
  2548. strDetectorInfo.add("TemperatureStatus", "0");
  2549. strDetectorInfo.add("WaitTime", "0");
  2550. strDetectorInfo.add("DetectorWifiSignal", "0");
  2551. strDetectorInfo.add("DetectorBattery", "0");
  2552. strDetectorInfo.add("ShockSensor", "NULL");
  2553. strDetectorInfo.add("FirmwareUpdate", "0");
  2554. //encode
  2555. strFDI = strDetectorInfo.encode();
  2556. return RET_STATUS::RET_SUCCEED;
  2557. }
  2558. strDetectorInfo.add("DetectorName", m_stDeviceConfig.strDeviceName.c_str());
  2559. strDetectorInfo.add("DetectorSN", m_stDeviceConfig.strPanelSerial.c_str());
  2560. strDetectorInfo.add("Firmware", m_stDeviceConfig.strFirmware.c_str());
  2561. strDetectorInfo.add("APFirmware", "NULL");
  2562. strDetectorInfo.add("Software", m_stDeviceConfig.strSoftware.c_str());
  2563. strDetectorInfo.add("SSID", m_stDeviceConfig.strWifiSSID.c_str());
  2564. strDetectorInfo.add("LifeTime", m_stDeviceConfig.nLifeTime);
  2565. strDetectorInfo.add("PowerOn", m_stDeviceConfig.nPowerOn);
  2566. strDetectorInfo.add("DateCode", " ");
  2567. strDetectorInfo.add("PartNumber", m_stDeviceConfig.strPartNumber.c_str());
  2568. strDetectorInfo.add("WifiDataRate", m_stDeviceConfig.nWifiDataRate);
  2569. strDetectorInfo.add("WifiChannel", m_stDeviceConfig.nWifiChannel);
  2570. strDetectorInfo.add("DetectorExist", m_stDeviceConfig.bExisted);
  2571. //System Workstation
  2572. if (m_stDeviceConfig.strDeviceName.find("3543") != std::string::npos)
  2573. {
  2574. strDetectorInfo.add("SystemAS", /*m_stDeviceConfig.nWorkstation*/3);
  2575. }
  2576. else
  2577. {
  2578. strDetectorInfo.add("SystemAS", /*m_stDeviceConfig.nWorkstation*/3);
  2579. }
  2580. //DetectorCalibrationDate
  2581. if (m_stDeviceConfig.strCalibrationDate != " ")
  2582. {
  2583. if (m_stDeviceConfig.strCalibrationDate.find("19700101") != std::string::npos)
  2584. {
  2585. strDetectorInfo.add("CalibrationDate", "0");
  2586. strDetectorInfo.add("CalibrationDue", "0");
  2587. strDetectorInfo.add("CalibrationExist", 0);
  2588. }
  2589. else
  2590. {
  2591. strDetectorInfo.add("CalibrationDate", m_stDeviceConfig.strCalibrationDate.c_str()/*"20210610"*/);
  2592. strDetectorInfo.add("CalibrationDue", m_stDeviceConfig.strCalibrationDue.c_str()/*"20210610"*/);
  2593. strDetectorInfo.add("CalibrationExist", 1);
  2594. }
  2595. }
  2596. else
  2597. {
  2598. strDetectorInfo.add("CalibrationDate", "0");
  2599. strDetectorInfo.add("CalibrationDue", "0");
  2600. strDetectorInfo.add("CalibrationExist", 0);
  2601. }
  2602. if (m_stDeviceConfig.bConnectStatus)
  2603. {
  2604. strDetectorInfo.add("CommunicationStatus", 1);
  2605. }
  2606. else
  2607. {
  2608. strDetectorInfo.add("CommunicationStatus", 0);
  2609. }
  2610. strDetectorInfo.add("FDCalibrationTemperature", m_stDeviceConfig.fCalibTemperature);
  2611. strDetectorInfo.add("ShockSensor", m_nShockCounts);
  2612. strDetectorInfo.add("FirmwareUpdate", 0);
  2613. //Info( "{$}", strDetectorInfo.encode());
  2614. strFDI = strDetectorInfo.encode();
  2615. return RET_STATUS::RET_SUCCEED;
  2616. }
  2617. string nsFPD::FPDDeviceTrixell::MakeImageHead(IMAGE_VIEW_TYPE Type)
  2618. {
  2619. if (Type == IMAGE_FULL)
  2620. {
  2621. float fFactorEXI2UGY = 1.0f;
  2622. if (APP_STATUS_WORK_BEGIN == m_eAppStatus)
  2623. {
  2624. fFactorEXI2UGY = m_fFactorEXI2UGY;
  2625. }
  2626. if (m_pFullImageHead == NULL)
  2627. {
  2628. m_pFullImageHead = new ResDataObject;
  2629. ResDataObject json;
  2630. json.add(SM_IMAGE_TYPE, (int)Type);
  2631. json.add(SM_IMAGE_WIDTH, m_stDeviceConfig.nFullImageWidth);
  2632. json.add(SM_IMAGE_HEIGHT, m_stDeviceConfig.nFullImageHeight);
  2633. json.add(SM_IMAGE_BIT, 16);
  2634. json.add(SM_IMAGE_TAG, 1);
  2635. json.add(SM_IMAGE_INDEX, 1);
  2636. json.add(SM_IMAGE_YEAR, m_stImgCreateTime.wYear);
  2637. json.add(SM_IMAGE_MONTH, m_stImgCreateTime.wMonth);
  2638. json.add(SM_IMAGE_DAY, m_stImgCreateTime.wDay);
  2639. json.add(SM_IMAGE_HOUR, m_stImgCreateTime.wHour);
  2640. json.add(SM_IMAGE_MINUTE, m_stImgCreateTime.wMinute);
  2641. json.add(SM_IMAGE_SEC, m_stImgCreateTime.wSecond);
  2642. json.add(SM_IMAGE_MILLSEC, m_stImgCreateTime.wMilliseconds);
  2643. json.add(SM_IMAGE_LSB, "5000");
  2644. json.add(SM_IMAGE_DOSE, m_stDeviceConfig.nDoseOfEXI);
  2645. json.add(SM_IMAGE_PIXELREPRESENTATION, "1");
  2646. json.add(SM_IMAGE_PIXELSPACING, m_stDeviceConfig.nPixelSpace);
  2647. json.add(SM_IMAGE_ROTATION, "No");
  2648. json.add(SM_IMAGE_FLIP, "No");
  2649. json.add(SM_IMAGE_ORIGINX, "0");
  2650. json.add(SM_IMAGE_ORIGINY, "0");
  2651. json.add(SM_IMAGE_EXI2UGY, fFactorEXI2UGY);
  2652. json.add(SM_IMAGE_TEMP, 0.0f);
  2653. m_pFullImageHead->add(SM_IMAGE_HEAD, json);
  2654. }
  2655. else
  2656. {
  2657. (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_YEAR] = m_stImgCreateTime.wYear;
  2658. (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_MONTH] = m_stImgCreateTime.wMonth;
  2659. (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_DAY] = m_stImgCreateTime.wDay;
  2660. (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_HOUR] = m_stImgCreateTime.wHour;
  2661. (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_MINUTE] = m_stImgCreateTime.wMinute;
  2662. (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_SEC] = m_stImgCreateTime.wSecond;
  2663. (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_MILLSEC] = m_stImgCreateTime.wMilliseconds;
  2664. (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_TEMP] = m_stDeviceConfig.fCurrentTemperValue;
  2665. Info("Temperature in image is {$}", m_stDeviceConfig.fCurrentTemperValue);
  2666. }
  2667. return (*m_pFullImageHead).encode();
  2668. }
  2669. else
  2670. {
  2671. if (m_pPreviewImageHead == NULL)
  2672. {
  2673. m_pPreviewImageHead = new ResDataObject;
  2674. ResDataObject json;
  2675. json.add(SM_IMAGE_TYPE, (int)Type);
  2676. json.add(SM_IMAGE_WIDTH, m_stDeviceConfig.nPreviewWidth);
  2677. json.add(SM_IMAGE_HEIGHT, m_stDeviceConfig.nPreviewHeight);
  2678. json.add(SM_IMAGE_BIT, 16);
  2679. json.add(SM_IMAGE_TAG, 1);
  2680. json.add(SM_IMAGE_INDEX, 1);
  2681. json.add(SM_IMAGE_YEAR, m_stImgCreateTime.wYear);
  2682. json.add(SM_IMAGE_MONTH, m_stImgCreateTime.wMonth);
  2683. json.add(SM_IMAGE_DAY, m_stImgCreateTime.wDay);
  2684. json.add(SM_IMAGE_HOUR, m_stImgCreateTime.wHour);
  2685. json.add(SM_IMAGE_MINUTE, m_stImgCreateTime.wMinute);
  2686. json.add(SM_IMAGE_SEC, m_stImgCreateTime.wSecond);
  2687. json.add(SM_IMAGE_MILLSEC, m_stImgCreateTime.wMilliseconds);
  2688. json.add(SM_IMAGE_LSB, "5000");
  2689. json.add(SM_IMAGE_DOSE, m_stDeviceConfig.nDoseOfEXI);
  2690. json.add(SM_IMAGE_ROTATION, "No");
  2691. json.add(SM_IMAGE_FLIP, "No");
  2692. json.add(SM_IMAGE_ORIGINX, "0");
  2693. json.add(SM_IMAGE_ORIGINY, "0");
  2694. json.add(SM_IMAGE_PIXELSPACING, m_stDeviceConfig.nPixelSpace);
  2695. json.add(SM_IMAGE_PIXELREPRESENTATION, "1");
  2696. json.add(SM_IMAGE_TEMP, m_stDeviceConfig.fCurrentTemperValue);
  2697. m_pPreviewImageHead->add(SM_IMAGE_HEAD, json);
  2698. }
  2699. else
  2700. {
  2701. (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_YEAR] = m_stImgCreateTime.wYear;
  2702. (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_MONTH] = m_stImgCreateTime.wMonth;
  2703. (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_DAY] = m_stImgCreateTime.wDay;
  2704. (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_HOUR] = m_stImgCreateTime.wHour;
  2705. (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_MINUTE] = m_stImgCreateTime.wMinute;
  2706. (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_SEC] = m_stImgCreateTime.wSecond;
  2707. (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_MILLSEC] = m_stImgCreateTime.wMilliseconds;
  2708. (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_TEMP] = m_stDeviceConfig.fCurrentTemperValue;
  2709. }
  2710. return (*m_pPreviewImageHead).encode();
  2711. }
  2712. return "";
  2713. }
  2714. RET_STATUS nsFPD::FPDDeviceTrixell::AddFrameWithRawHead(IMAGE_VIEW_TYPE Type, WORD* pFrameBuff, DWORD FrameSize)
  2715. {
  2716. string strImageHead = MakeImageHead(Type);
  2717. return m_AcqUnit->AddFrameWithRawHead(Type, strImageHead, pFrameBuff, FrameSize);
  2718. }
  2719. void nsFPD::FPDDeviceTrixell::OnError(int nIndex, string strErrCode, string strErr)
  2720. {
  2721. m_WarnAndError->SendError(strErrCode, strErr);
  2722. }
  2723. void nsFPD::FPDDeviceTrixell::ClearError(int nDetectorID, std::string strErrorCode, std::string strErr)
  2724. {
  2725. m_WarnAndError->ClearError(strErrorCode);
  2726. }
  2727. void nsFPD::FPDDeviceTrixell::OnWarn(int nIndex, string strWarnCode, string strWarn)
  2728. {
  2729. m_WarnAndError->SendWarn(strWarnCode, strWarn);
  2730. }
  2731. void nsFPD::FPDDeviceTrixell::ClearWarn(int nDetectorID, std::string strWarnCode, std::string strWarn)
  2732. {
  2733. m_WarnAndError->ClearWarn(strWarnCode);
  2734. }
  2735. RET_STATUS nsFPD::FPDDeviceTrixell::ResetError()
  2736. {
  2737. m_WarnAndError->ClearAllError();
  2738. m_WarnAndError->ClearAllWarn();
  2739. return RET_STATUS::RET_SUCCEED;
  2740. }
  2741. void nsFPD::FPDDeviceTrixell::SendAllError()
  2742. {
  2743. m_WarnAndError->SendAllError();
  2744. }
  2745. RET_STATUS nsFPD::FPDDeviceTrixell::SetSaveRawDataMode(int nSaveRawDataMode)
  2746. {
  2747. Info("## SetSaveRawDataMode ##");
  2748. string strSaveMode = "";
  2749. switch (nSaveRawDataMode)
  2750. {
  2751. case CCOS_NO_SAVE_RAW:
  2752. strSaveMode = "No save raw image";
  2753. break;
  2754. case CCOS_SAVE_ORIGINAL:
  2755. strSaveMode = "Save original raw image";
  2756. break;
  2757. case CCOS_SAVE_AFTER_CROP:
  2758. strSaveMode = "Save after crop raw image";
  2759. break;
  2760. case CCOS_SAVE_AFTER_CALIB:
  2761. strSaveMode = "Save after calibration raw image";
  2762. break;
  2763. case CCOS_SAVE_AFTER_GRID_SUPPRESSION:
  2764. strSaveMode = "Save after GridSuppression raw image";
  2765. break;
  2766. case CCOS_SAVE_ALL:
  2767. strSaveMode = "Save all raw image";
  2768. break;
  2769. default:
  2770. strSaveMode = "Undefined";
  2771. break;
  2772. }
  2773. Info("Set SaveRawData Mode: {$}({$})", strSaveMode, nSaveRawDataMode);
  2774. m_pDetectors->SetSaveRawDataMode(nSaveRawDataMode);
  2775. return RET_STATUS::RET_SUCCEED;
  2776. }
  2777. RET_STATUS nsFPD::FPDDeviceTrixell::OfflineFPD(int nOfflineFPDMode)
  2778. {
  2779. Info("## OfflineFPD ##");
  2780. Info("Offline FPD mode: {$}", nOfflineFPDMode);
  2781. if (nOfflineFPDMode == 1)
  2782. {
  2783. m_pDetectors->DisconnectDetector(0);
  2784. }
  2785. else if (nOfflineFPDMode == 2)
  2786. {
  2787. m_pDetectors->OfflineFPD(0);
  2788. }
  2789. return RET_STATUS::RET_SUCCEED;
  2790. }
  2791. RET_STATUS nsFPD::FPDDeviceTrixell::OnlineFPD(int nOnlineFPDMode)
  2792. {
  2793. Info("## OnlineFPD ##");
  2794. Info("Online FPD mode: {$}", nOnlineFPDMode);
  2795. if (nOnlineFPDMode == 1)
  2796. {
  2797. m_pDetectors->ConnectDetector(false, 0);
  2798. }
  2799. else if (nOnlineFPDMode == 2)
  2800. {
  2801. m_pDetectors->OnlineFPD(0);
  2802. }
  2803. return RET_STATUS::RET_SUCCEED;
  2804. }
  2805. RET_STATUS nsFPD::FPDDeviceTrixell::GetAutonumousImageList(int nDetectorID, vector<string>& AutonumousList)
  2806. {
  2807. Info("## GetAutonumousImageList ##");
  2808. if (!m_pDetectors->GetAutonumousImageList(nDetectorID, AutonumousList))
  2809. {
  2810. Error("Get autonumous image list error");
  2811. return RET_STATUS::RET_FAILED;
  2812. }
  2813. Info("Get autonumous image list success");
  2814. return RET_STATUS::RET_SUCCEED;
  2815. }
  2816. RET_STATUS nsFPD::FPDDeviceTrixell::RemoveAutonumousImageList(string strMeta)
  2817. {
  2818. Info("## RemoveAutonumousImageList ##");
  2819. Info("Remove item: {$}", strMeta);
  2820. if (!m_pDetectors->RemoveAutonumousImageList(strMeta))
  2821. {
  2822. Error("Remove autonumous image error");
  2823. return RET_STATUS::RET_FAILED;
  2824. }
  2825. Error("Remove autonumous image success");
  2826. return RET_STATUS::RET_SUCCEED;
  2827. }
  2828. RET_STATUS nsFPD::FPDDeviceTrixell::RemoveAutonumousAll()
  2829. {
  2830. Info("## RemoveAutonumousAll ##");
  2831. if (!m_pDetectors->RemoveAutonumousAll())
  2832. {
  2833. Error("Remove autonumous all image error");
  2834. return RET_STATUS::RET_FAILED;
  2835. }
  2836. Info("Remove autonumous all image success");
  2837. return RET_STATUS::RET_SUCCEED;
  2838. }
  2839. RET_STATUS nsFPD::FPDDeviceTrixell::GetImageMetaData(string strMetaData)
  2840. {
  2841. Info("## GetImageMetaData ##");
  2842. if (!m_pDetectors->GetImageMetaData(strMetaData))
  2843. {
  2844. Error("Get autonumous Meta Data error");
  2845. return RET_STATUS::RET_FAILED;
  2846. }
  2847. Info("Get autonumous Meta Data success");
  2848. return RET_STATUS::RET_SUCCEED;
  2849. }
  2850. RET_STATUS nsFPD::FPDDeviceTrixell::ExportAutonumousAll()
  2851. {
  2852. Info("## ExportAutonumousAll ##");
  2853. if (!m_pDetectors->ExportAutonumousAll())
  2854. {
  2855. Error("Get autonumous all image error");
  2856. return RET_STATUS::RET_FAILED;
  2857. }
  2858. Info("Get autonumous all image success");
  2859. return RET_STATUS::RET_SUCCEED;
  2860. }
  2861. RET_STATUS nsFPD::FPDDeviceTrixell::ActiveSyncMode(int nSyncMode)
  2862. {
  2863. Info("ActiveSyncMode: {$}", nSyncMode);
  2864. if (!m_pDetectors->SetSyncMode(0, nSyncMode))
  2865. {
  2866. Error("Set sync mode failed");
  2867. }
  2868. Info("ActiveSyncMode success");
  2869. return RET_STATUS::RET_SUCCEED;
  2870. }
  2871. void nsFPD::FPDDeviceTrixell::CheckCalibrationDue()
  2872. {
  2873. Info("[Checking Calibration Date]");
  2874. if (!m_stDeviceConfig.bConnectStatus)
  2875. {
  2876. Error("m_stDeviceConfig.bConnectStatus = false");
  2877. return;
  2878. }
  2879. Info("LastCalibrationDate: {$}, DueDay: {$}", m_stDeviceConfig.strLastCalibrationDate, m_stDeviceConfig.strCalibrationFileExpireTime);
  2880. if (!m_bNotifyCalWarn)
  2881. {
  2882. Info("skip notify calibration");
  2883. return;
  2884. }
  2885. //进检查时判断当前校正文件是否过期,如果即将过期或者已过期都向上通知
  2886. if (m_stDeviceConfig.strLastCalibrationDate == "0000-00-00 00:00:00")
  2887. {
  2888. //没有做过校正
  2889. Warn("No calibration file, please make a calibration!");
  2890. m_WarnAndError->SendWarn(ERR_FPD_CAL_FILE_NOT_EXIST, "");
  2891. }
  2892. else
  2893. {
  2894. time_t lastCalibDate = StringToDatetime(m_stDeviceConfig.strLastCalibrationDate);
  2895. int nExpireTime = std::stoi(m_stDeviceConfig.strCalibrationFileExpireTime);//单位:天
  2896. Info("nExpireTime:{$}", nExpireTime);
  2897. time_t localtime = time(NULL);
  2898. //判断是否过期
  2899. if (localtime > lastCalibDate + nExpireTime * 24 * 3600)
  2900. {
  2901. //过期了报错
  2902. Warn("Calibration file is expired! please make a calibration!");
  2903. m_WarnAndError->SendWarn(ERR_FPD_CAL_FILE_OUTDATE, "");
  2904. }
  2905. }
  2906. return;
  2907. }