DIOS.Dev.FPD.PZMedicalDM.cpp 89 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911
  1. #include "stdafx.h"
  2. #include "FileVersion.hpp"
  3. #include "CCOS.Dev.FPD.PZMedicalDM.h"
  4. #include "common_api.h"
  5. #include "DICOMImageHeadKey.h"
  6. #include "PZMedicalCtrl.h"
  7. #include <sys/stat.h>
  8. namespace nsFPD = CCOS::Dev::Detail::Detector;
  9. //-----------------------------------------------------------------------------
  10. // FPDDevicePZMedical
  11. //-----------------------------------------------------------------------------
  12. extern PZMedicalCtrl* g_pDetector;
  13. //-----------------------------------------------------------------------------
  14. // GetIODriver & CreateIODriver
  15. //-----------------------------------------------------------------------------
  16. static nsFPD::PZMedicalDriver gIODriver;
  17. Log4CPP::Logger* gLogger = nullptr;
  18. extern const char* g_szMouldPath;
  19. /// <summary>
  20. /// [DONE.CHECKED.]
  21. /// </summary>
  22. /// <returns></returns>
  23. extern "C" CCOS::Dev::IODriver * __cdecl GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
  24. {
  25. return &gIODriver;
  26. }
  27. /// <summary>
  28. /// [DONE.TO BE TESTED.]
  29. /// </summary>
  30. /// <returns></returns>
  31. extern "C" CCOS::Dev::IODriver * __cdecl CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
  32. {
  33. return new nsFPD::PZMedicalDriver();
  34. }
  35. /// <summary>
  36. /// 驱动构造函数
  37. /// [DONE.CHECKED.]
  38. /// </summary>
  39. nsFPD::PZMedicalDriver::PZMedicalDriver()
  40. {
  41. m_pObjDev = nullptr;
  42. m_bDriverConnect = false; //缺省为false
  43. m_pAttribute.reset(new ResDataObject());
  44. m_pDescription.reset(new ResDataObject());
  45. }
  46. /// <summary>
  47. /// [DONE.TO BE TESTED.]
  48. /// </summary>
  49. nsFPD::PZMedicalDriver::~PZMedicalDriver()
  50. {
  51. if(m_pObjDev != nullptr)
  52. {
  53. delete m_pObjDev;
  54. m_pObjDev = nullptr;
  55. }
  56. Close();
  57. Log4CPP::ThreadContext::Map::Clear();
  58. gLogger = nullptr;
  59. }
  60. /// <summary>
  61. /// 驱动的准备,可以做一些特殊的操作
  62. /// [DONE.CHECKED.] TBD.
  63. /// </summary>
  64. void nsFPD::PZMedicalDriver::Prepare()
  65. {
  66. printf("--Driver-- prepare \r\n");
  67. string strLogPath = GetProcessDirectory() + R"(\Conf\Log4CPP.Config.xml)";
  68. auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
  69. gLogger = Log4CPP::LogManager::GetLogger("Module");
  70. FINFO("Code Build datetime [{$} {$}]", __DATE__, __TIME__);
  71. #ifdef _WIN64
  72. FINFO("=============================Version: {$} (64-bit)==================================", FileVersion(g_szMouldPath).GetVersionString());
  73. #else
  74. FINFO("=============================Version: {$} (32-bit)==================================", FileVersion(g_szMouldPath).GetVersionString());
  75. #endif
  76. FINFO("Driver Prepare get logger");
  77. }
  78. /// <summary>
  79. /// 驱动的连接,创建设备对象
  80. /// [DONE.CHECKED.]
  81. /// </summary>
  82. /// <returns></returns>
  83. bool nsFPD::PZMedicalDriver::Connect()
  84. {
  85. printf("PZMedical driver module: Connect \r\n");
  86. FINFO("--Func-- driver connect");
  87. m_pObjDev = new FPDDevicePZMedical(EventCenter, m_ConfigFileName);
  88. m_bDriverConnect = true; //connect执行完毕,置为true
  89. printf("PZMedical driver module: Connect over\r\n");
  90. return true;
  91. }
  92. /// <summary>
  93. /// 驱动断开连接,释放设备对象
  94. /// </summary>
  95. void nsFPD::PZMedicalDriver::Disconnect()
  96. {
  97. printf("PZMedical driver module: Disconnect \r\n");
  98. FINFO("--Func-- driver disconnect");
  99. if (m_pObjDev != nullptr)
  100. {
  101. delete m_pObjDev;
  102. m_pObjDev = nullptr;
  103. }
  104. m_bDriverConnect = false; //disconnect置为false
  105. }
  106. bool nsFPD::PZMedicalDriver::isConnected() const
  107. {
  108. return m_bDriverConnect;
  109. }
  110. /// <summary>
  111. /// 驱动创建设备丢下,然后 给 上层返回 IODevice 对象指针
  112. /// [DONE.CHECKED.]
  113. /// </summary>
  114. /// <param name="index"></param>
  115. /// <returns></returns>
  116. auto nsFPD::PZMedicalDriver::CreateDevice(int index)->std::unique_ptr <IODevice>
  117. {
  118. printf("PZMedical driver module: CreateDevice \r\n");
  119. FINFO("--Func-- driver createdevice");
  120. auto Device = std::unique_ptr<IODevice>(new IODevice(m_pObjDev));
  121. m_pObjDev->CreateDevice();
  122. m_pObjDev->Register();
  123. return Device;
  124. }
  125. /// <summary>
  126. /// 驱动信息检索 TODO : 需要重新定义
  127. /// </summary>
  128. /// <returns></returns>
  129. std::string nsFPD::PZMedicalDriver::DriverProbe()
  130. {
  131. printf("PZMedical driver module: Driver Probe \r\n");
  132. ResDataObject r_config, HardwareInfo;
  133. if (r_config.loadFile(m_ConfigFileName.c_str()))
  134. {
  135. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  136. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  137. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  138. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  139. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  140. }
  141. else
  142. {
  143. HardwareInfo.add("MajorID", "Detector");
  144. HardwareInfo.add("MinorID", "DM");
  145. HardwareInfo.add("VendorID", "PZMedical");
  146. HardwareInfo.add("ProductID", "PZMedical");
  147. HardwareInfo.add("SerialID", "Driver");
  148. }
  149. string str = HardwareInfo.encode();
  150. return str;
  151. }
  152. /// <summary>
  153. /// 从配置文件中返回给上层 配置对象
  154. /// 标准代码
  155. /// [DONE.CHECKED.]
  156. /// </summary>
  157. /// <returns></returns>
  158. std::string nsFPD::PZMedicalDriver::GetResource()
  159. {
  160. printf("PZMedical driver: GetResource \r\n");
  161. FINFO("PZMedical driver: GetResource");
  162. printf("m_ConfigFileName:%s\n", m_ConfigFileName.c_str());
  163. FINFO("m_ConfigFileName:{$}", m_ConfigFileName);
  164. ResDataObject r_config, temp;
  165. if (!temp.loadFile(m_ConfigFileName.c_str()))
  166. {
  167. return "";
  168. }
  169. m_ConfigAll = temp;
  170. r_config = temp["CONFIGURATION"];
  171. m_Configurations = r_config;
  172. ResDataObject DescriptionTemp;
  173. ResDataObject ListTemp;
  174. string strTemp = ""; //用于读取字符串配置信息
  175. string strIndex = ""; //用于读取配置信息中的List项
  176. int nTemp = -1; //用于读取整型配置信息
  177. char sstream[10] = { 0 }; //用于转换值
  178. string strValue = ""; //用于存储配置的值
  179. string strType = ""; //用于存储配置的类型 int/float/string...
  180. string strAccess = ""; //用于存储权限的类型 R/W/RW
  181. string strRequired = ""; // TRUE/FALSE
  182. string strDefaultValue = "";
  183. string strRangeMin = "";
  184. string strRangeMax = "";
  185. try
  186. {
  187. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  188. //FINFO(g_pFPDCtrlLog, "ConfigInfo Count: {$}", nConfigInfoCount);
  189. m_pAttribute->clear();
  190. m_pDescription->clear();
  191. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  192. {
  193. DescriptionTemp.clear();
  194. ListTemp.clear();
  195. //AttributeType
  196. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Type"];
  197. DescriptionTemp.add(AttributeType, strTemp.c_str());
  198. //FINFO("DescriptionTemp--> {$}: {$}", AttributeType, strTemp.c_str());
  199. strType = strTemp; //记录配置项的类型
  200. //AttributeKey
  201. //1. 根据AttributeType,内部key和配置路径,拿到当前的真实值
  202. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  203. nTemp = (int)m_Configurations["ConfigToolInfo"][nInfoIndex]["PathID"];
  204. GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue);
  205. //2. 赋值
  206. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  207. if ("int" == strType)
  208. {
  209. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  210. }
  211. else if ("float" == strType)
  212. {
  213. (*m_pAttribute).add(strTemp.c_str(), atof(strValue.c_str()));
  214. }
  215. else //其它先按string类型处理
  216. {
  217. (*m_pAttribute).add(strTemp.c_str(), strValue.c_str());
  218. }
  219. //AttributeAccess
  220. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Access"];
  221. DescriptionTemp.add(AttributeAccess, strTemp.c_str());
  222. //AttributeRangeMin
  223. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMin"];
  224. if (strTemp != "") //不需要的配置项为空
  225. {
  226. DescriptionTemp.add(AttributeRangeMin, strTemp.c_str());
  227. }
  228. //AttributeRangeMax
  229. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMax"];
  230. if (strTemp != "") //不需要的配置项为空
  231. {
  232. DescriptionTemp.add(AttributeRangeMax, strTemp.c_str());
  233. }
  234. //AttributeList
  235. nTemp = m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListNum"];
  236. if (nTemp > 0) //ListNum不大于0时说明不需要list配置
  237. {
  238. for (int nListIndex = 0; nListIndex < nTemp; nListIndex++)
  239. {
  240. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListInfo"][nListIndex];
  241. //sprintf_s(sstream, "{$}", nListIndex);
  242. auto temKey = std::to_string(nListIndex);
  243. ListTemp.add(temKey.c_str(), strTemp.c_str());
  244. }
  245. DescriptionTemp.add(AttributeList, ListTemp);
  246. }
  247. //AttributeRequired
  248. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Required"];
  249. DescriptionTemp.add(AttributeRequired, strTemp.c_str());
  250. //AttributeDefaultValue
  251. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["DefaultValue"];
  252. if (strTemp != "") //不需要的配置项为空
  253. {
  254. DescriptionTemp.add(AttributeDefaultValue, strTemp.c_str());
  255. }
  256. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  257. (*m_pDescription).add(strTemp.c_str(), DescriptionTemp);
  258. }
  259. }
  260. catch (ResDataObjectExption& e)
  261. {
  262. FERROR("Get config error: {$}", e.what());
  263. return "";
  264. }
  265. ResDataObject resDeviceResource;
  266. resDeviceResource.add(ConfKey::CcosDetectorAttribute, (*m_pAttribute));
  267. resDeviceResource.add(ConfKey::CcosDetectorDescription, (*m_pDescription));
  268. ResDataObject DescriptionTempEx;
  269. DescriptionTempEx.add(ConfKey::CcosDetectorConfig, resDeviceResource);
  270. m_DeviceConfig = DescriptionTempEx;
  271. string res = DescriptionTempEx.encode();
  272. printf("PZMedical driver module: get resource over \r\n");
  273. return res;
  274. }
  275. /// <summary>
  276. /// 设备信息检索 TODO : 需要重新定义,TBD.
  277. /// </summary>
  278. /// <returns></returns>
  279. std::string nsFPD::PZMedicalDriver::DeviceProbe()
  280. {
  281. printf("PZMedical driver module: Device Probe \r\n");
  282. ResDataObject r_config, HardwareInfo;
  283. if (r_config.loadFile(m_ConfigFileName.c_str()))
  284. {
  285. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  286. HardwareInfo.add("MinorID", "Device");
  287. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  288. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  289. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  290. }
  291. else
  292. {
  293. HardwareInfo.add("MajorID", "Detector");
  294. HardwareInfo.add("MinorID", "Device");
  295. HardwareInfo.add("VendorID", "PZMedical");
  296. HardwareInfo.add("ProductID", "PZMedical");
  297. HardwareInfo.add("SerialID", "1234");
  298. }
  299. string str = HardwareInfo.encode();
  300. return str;
  301. }
  302. /// <summary>
  303. /// 设备配置读取接口
  304. /// [DONE.CHECKED.]
  305. /// </summary>
  306. /// <param name="Cfg"></param>
  307. /// <returns></returns>
  308. bool nsFPD::PZMedicalDriver::GetDeviceConfig(std::string& Cfg)
  309. {
  310. Cfg = m_DeviceConfig.encode();
  311. FINFO("GetDeviceConfig over");
  312. return true;
  313. }
  314. /// <summary>
  315. /// 提供给web配置中心的 配置写入接口
  316. /// [DONE.CHECKED.]
  317. /// </summary>
  318. /// <param name="Cfg"></param>
  319. /// <returns></returns>
  320. bool nsFPD::PZMedicalDriver::SetDeviceConfig(std::string Cfg)
  321. {
  322. FINFO("--Func-- SetDeviceConfig {$}\n", Cfg.c_str());
  323. ResDataObject DeviceConfig;
  324. DeviceConfig.decode(Cfg.c_str());
  325. ResDataObject DescriptionTempEx;
  326. DescriptionTempEx = DeviceConfig["DeviceConfig"];
  327. bool bSaveFile = false; //true:重新保存配置文件
  328. string strAccess = "";
  329. for (int i = 0; i < DescriptionTempEx.size(); i++)
  330. {
  331. ResDataObject temp = DescriptionTempEx[i];
  332. FINFO("{$}", temp.encode());
  333. for (int j = 0; j < temp.size(); j++)
  334. {
  335. string strKey = temp.GetKey(j);
  336. FINFO("{$}", strKey.c_str());
  337. try
  338. {
  339. if (m_pAttribute->GetFirstOf(strKey.c_str()) >= 0)
  340. {
  341. strAccess = (string)(*m_pDescription)[strKey.c_str()]["Access"];
  342. if ("RW" == strAccess || "rw" == strAccess)
  343. {
  344. //修改对应配置,在其他单元的配置项要同时调用其修改函数修改真实值
  345. //1. 修改内存中的值,用于给上层发消息
  346. (*m_pAttribute)[strKey.c_str()] = temp[j];
  347. //2. 拿到Innerkey
  348. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  349. FINFO("ConfigInfo Count: {$}", nConfigInfoCount);
  350. string strTemp = ""; //存储AttributeKey
  351. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  352. {
  353. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  354. if (strTemp == strKey)
  355. {
  356. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  357. break;
  358. }
  359. }
  360. //3. 修改配置文件中的值
  361. if (SetDeviceConfigValue(m_Configurations, strTemp.c_str(), 1, temp[j]))
  362. {
  363. bSaveFile = true;
  364. }
  365. }
  366. else
  367. {
  368. FINFO("{$} is not a RW configuration item", strKey.c_str());
  369. }
  370. }
  371. }
  372. catch (ResDataObjectExption& e)
  373. {
  374. FERROR("SetDriverConfig crashed: {$}", e.what());
  375. return false;
  376. }
  377. }
  378. }
  379. if (bSaveFile)
  380. {
  381. //4. 重新保存配置文件
  382. SaveConfigFile(true);
  383. }
  384. return true;
  385. }
  386. /// <summary>
  387. /// 保存配置到文件
  388. /// [DONE.TO BE TESTED.]
  389. /// </summary>
  390. /// <param name="bSendNotify"></param>
  391. /// <returns></returns>
  392. bool nsFPD::PZMedicalDriver::SaveConfigFile(bool bSendNotify)
  393. {
  394. m_ConfigAll["CONFIGURATION"] = m_Configurations;
  395. m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
  396. FINFO("SaveConfigFile over, m_ConfigAll:{$}", m_ConfigAll.encode());
  397. return true;
  398. }
  399. /// <summary>
  400. /// 读取当前配置项
  401. /// TBD. 审视参数列表
  402. /// </summary>
  403. /// <param name="config"></param>
  404. /// <param name="pInnerKey"></param>
  405. /// <param name="nPathID"></param>
  406. /// <param name="strValue"></param>
  407. /// <returns></returns>
  408. bool nsFPD::PZMedicalDriver::GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue)
  409. {
  410. strValue = "";
  411. string strTemp = pInnerKey;
  412. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  413. {
  414. if (WiredIP == strTemp || WirelessIP == strTemp || LocalIP == strTemp)
  415. {
  416. strValue = (string)config["connections"][pInnerKey];
  417. }
  418. else if (DetectorVender == strTemp || DetectorModel == strTemp ||
  419. DetectorDescription == strTemp || DetectorSerialNumber == strTemp)
  420. {
  421. strValue = (string)config[pInnerKey];
  422. }
  423. else if (SyncType == strTemp || FPDWorkStation == strTemp || ImageWidth == strTemp || IsSaveRaw == strTemp
  424. || ImageHeight == strTemp || RawImgWidth == strTemp || RawImgHeight == strTemp || WidthOffset == strTemp || HeightOffset == strTemp)
  425. {
  426. strValue = (string)config["ModeTable"]["DetectorMode"][pInnerKey];
  427. }
  428. else if (TempMaxLimit == strTemp || TempMinLimit == strTemp || TempUpperLimit == strTemp
  429. || TempLowerLimit == strTemp || ReConnect == strTemp || BatLowerLimit == strTemp
  430. || BatMiniLimit == strTemp || BatLowerLimitInCali == strTemp || WifiLowerLimit == strTemp
  431. || WifiMiniLimit == strTemp || HighPowerTimeout == strTemp
  432. || ShowTemperature == strTemp || ShowWifi == strTemp
  433. || ShowBattery == strTemp || ShowBluetooth == strTemp
  434. || FPDExamMode == strTemp || FPDAcqMode == strTemp || FPDModeMatch == strTemp
  435. || CcosDetectorAttachedFlag == strTemp)
  436. {
  437. strValue = (string)config[pInnerKey];
  438. }
  439. else
  440. {
  441. strValue = "";
  442. FERROR("Error Configuration item: {$}", pInnerKey);
  443. }
  444. }
  445. return true;
  446. }
  447. /// <summary>
  448. /// 设置写入设备参数实现,这里过滤需要设置本探测器接受的参数
  449. /// 参数项和内容来源于 探测器配置文件 <ConfigToolInfo> <AttributeInfo>
  450. /// TBD. 具体内容
  451. /// comment by chenggw 2023.2.7
  452. /// </summary>
  453. /// <param name="config"></param>
  454. /// <param name="pInnerKey"></param>
  455. /// <param name="nPathID"></param>
  456. /// <param name="szValue"></param>
  457. /// <returns></returns>
  458. bool nsFPD::PZMedicalDriver::SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey,
  459. int nPathID, const char* szValue)
  460. {
  461. string strTemp = pInnerKey;
  462. FINFO("Begin to change {$} item value to {$}", pInnerKey, szValue);
  463. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  464. {
  465. if (WiredIP == strTemp || WirelessIP == strTemp || LocalIP == strTemp)
  466. {
  467. config["connections"][pInnerKey] = szValue;
  468. }
  469. else if (DetectorVender == strTemp || DetectorModel == strTemp ||
  470. DetectorDescription == strTemp || DetectorSerialNumber == strTemp)
  471. {
  472. config[pInnerKey] = szValue;
  473. }
  474. else if (SyncType == strTemp || FPDWorkStation == strTemp || ImageWidth == strTemp || IsSaveRaw == strTemp
  475. || ImageHeight == strTemp || RawImgWidth == strTemp || RawImgHeight == strTemp || WidthOffset == strTemp || HeightOffset == strTemp)
  476. {
  477. config["ModeTable"]["DetectorMode"][pInnerKey] = szValue;
  478. }
  479. else if (TempMaxLimit == strTemp || TempMinLimit == strTemp || TempUpperLimit == strTemp
  480. || TempLowerLimit == strTemp || ReConnect == strTemp || BatLowerLimit == strTemp
  481. || BatMiniLimit == strTemp || BatLowerLimitInCali == strTemp || WifiLowerLimit == strTemp
  482. || WifiMiniLimit == strTemp || HighPowerTimeout == strTemp
  483. || ShowTemperature == strTemp || ShowWifi == strTemp
  484. || ShowBattery == strTemp || ShowBluetooth == strTemp
  485. || FPDExamMode == strTemp || FPDAcqMode == strTemp || FPDModeMatch == strTemp
  486. || CcosDetectorAttachedFlag == strTemp)
  487. {
  488. config[pInnerKey] = szValue;
  489. }
  490. else
  491. {
  492. FERROR("Error Configuration item: {$}", pInnerKey);
  493. return false;
  494. }
  495. }
  496. return true;
  497. }
  498. nsFPD::FPDDevicePZMedical::FPDDevicePZMedical(std::shared_ptr<IOEventCenter> center, std::string strConfigPath)
  499. : m_nCalibTotalExposureNum(0),
  500. m_nCalibCurrentCalibrationRound(0),
  501. m_nCalibCurrentExposureIndex(0),
  502. m_nCalibCurrentExposureNum(0),
  503. m_bImagePendingOrNot(false),
  504. m_bResetDetector(false)
  505. {
  506. m_bConnect = false;
  507. m_nFullImageHeight = 0;
  508. m_nFullImageWidth = 0;
  509. m_nImageBits = 0;
  510. m_nPixelSpacing = 0;
  511. m_pwFullImageData = nullptr;
  512. m_pwPreviewImg = nullptr;
  513. m_nSensitivity = 0;
  514. m_nRotateAngle = 180;
  515. m_eAppStatus = APP_STATUS_IDLE;
  516. m_eSyncMode = SYNC_SOFTWARE;
  517. m_nShockCounts = 0;
  518. m_strWorkPath = GetProcessDirectory();
  519. m_DetectorCtrlUnit.reset(new PZMedicalCtrlUnit(center, this));
  520. m_AcqUnit.reset(new PZMedicalAcq(center, this));
  521. m_SyncUnit.reset(new PZMedicalSync(center, this));
  522. m_CalibUnit.reset(new PZMedicalCalib(center, this));
  523. m_DetectorConfiguration.reset(new DetectorConfiguration(strConfigPath));
  524. //探测器告警及错误消息
  525. m_WarnAndError.reset(new FPDErrorWarning(center, DetectorUnitType, m_strWorkPath));
  526. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_INIT));
  527. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY));
  528. m_WaitCalibDoseEvt = CreateEvent(NULL, FALSE, FALSE, NULL);
  529. m_PauseCalibrationEvt = CreateEvent(NULL, FALSE, FALSE, NULL);
  530. m_UploadCalibMapOver = CreateEvent(NULL, FALSE, FALSE, NULL);
  531. m_pFullImageHead = nullptr;
  532. m_pPreviewImageHead = nullptr;
  533. EventCenter = center;
  534. m_strCurrentAcqMode = "";
  535. }
  536. nsFPD::FPDDevicePZMedical::~FPDDevicePZMedical()
  537. {
  538. if (m_pwFullImageData)
  539. {
  540. delete[]m_pwFullImageData;
  541. m_pwFullImageData = nullptr;
  542. }
  543. if (m_pwPreviewImg)
  544. {
  545. delete[]m_pwPreviewImg;
  546. m_pwPreviewImg = nullptr;
  547. }
  548. if (m_WaitCalibDoseEvt)
  549. {
  550. CloseHandle(m_WaitCalibDoseEvt);
  551. m_WaitCalibDoseEvt = nullptr;
  552. }
  553. if (m_PauseCalibrationEvt)
  554. {
  555. CloseHandle(m_PauseCalibrationEvt);
  556. m_PauseCalibrationEvt = nullptr;
  557. }
  558. if (m_UploadCalibMapOver)
  559. {
  560. CloseHandle(m_UploadCalibMapOver);
  561. m_UploadCalibMapOver = nullptr;
  562. }
  563. }
  564. std::string nsFPD::FPDDevicePZMedical::GetGUID() const
  565. {
  566. printf("--Func-- GetGUID \r\n");
  567. FINFO("--Func-- GetGUID");
  568. return DetectorUnitType;
  569. }
  570. bool nsFPD::FPDDevicePZMedical::Prepare()
  571. {
  572. printf("--Func-- Prepare \r\n");
  573. FINFO("--Func-- device prepare");
  574. EventCenter->OnMaxBlockSize("PZDmQue", 4000 * 4000 * 2, 3, 1500 * 1500 * 2, 1);
  575. Connect();
  576. return true;
  577. }
  578. bool nsFPD::FPDDevicePZMedical::CreateDevice()
  579. {
  580. printf("--Func-- CreateDevice \r\n");
  581. FINFO("--Func-- CreateDevice");
  582. if (!LoadConfig())
  583. {
  584. return false;
  585. }
  586. if (nullptr == g_pDetector)
  587. {
  588. g_pDetector = new PZMedicalCtrl();
  589. FINFO("Create PZMedicalCtrl");
  590. }
  591. else
  592. {
  593. FERROR("PZMedicalCtrl Already exit");
  594. }
  595. g_pDetector->DriverEntry(this, m_DetectorConfiguration->m_Configurations);
  596. return true;
  597. }
  598. void nsFPD::FPDDevicePZMedical::Register()
  599. {
  600. auto Disp = &Dispatch;
  601. RegisterCtrl(Disp);
  602. RegisterAcq(Disp);
  603. RegisterSync(Disp);
  604. RegisterCalib(Disp);
  605. RegisterOthers(Disp);
  606. }
  607. RET_STATUS nsFPD::FPDDevicePZMedical::Connect()
  608. {
  609. printf("--Func-- Connect \r\n");
  610. FINFO("--Func-- Connect");
  611. RET_STATUS ret = RET_STATUS::RET_FAILED;
  612. FINFO("Connect m_strWorkPath:{$}", m_strWorkPath.c_str());
  613. if (g_pDetector->Connect(this, m_strWorkPath.c_str()))
  614. {
  615. ret = RET_STATUS::RET_SUCCEED;
  616. }
  617. return ret;
  618. }
  619. RET_STATUS nsFPD::FPDDevicePZMedical::EnterExam(int nExamMode)
  620. {
  621. FINFO("--Func-- EnterExam {$}", nExamMode);
  622. switch (nExamMode)
  623. {
  624. case APP_STATUS_WORK_BEGIN:
  625. FINFO("Enter into Exam Windows");
  626. m_eAppStatus = APP_STATUS_WORK_BEGIN;
  627. break;
  628. case APP_STATUS_WORK_END:
  629. FINFO("Quit Exam Windows");
  630. m_eAppStatus = APP_STATUS_WORK_END;
  631. break;
  632. case APP_STATUS_DETSHARE_BEGIN:
  633. FINFO("Enter into Detector Share Windows");
  634. m_eAppStatus = APP_STATUS_DETSHARE_BEGIN;
  635. break;
  636. case APP_STATUS_DETSHAR_END:
  637. m_eAppStatus = APP_STATUS_IDLE;
  638. FINFO("Quit Detector Share Windows");
  639. m_eAppStatus = APP_STATUS_DETSHAR_END;
  640. break;
  641. case APP_STATUS_CAL_BEGIN:
  642. FINFO("Enter into Calibration Windows");
  643. m_eAppStatus = APP_STATUS_CAL_BEGIN;
  644. break;
  645. case APP_STATUS_CAL_END:
  646. FINFO("Quit Calibration Windows");
  647. m_eAppStatus = APP_STATUS_CAL_END;
  648. break;
  649. case APP_STATUS_WORK_IN_SENSITIVITY:
  650. FINFO("Enter into sensitivity test interface");
  651. m_eAppStatus = APP_STATUS_WORK_IN_SENSITIVITY;
  652. break;
  653. default:
  654. break;
  655. }
  656. g_pDetector->EnterExamMode(nExamMode);
  657. return RET_STATUS::RET_SUCCEED;
  658. }
  659. /***
  660. * 这是切换探测器的接口
  661. ***/
  662. RET_STATUS nsFPD::FPDDevicePZMedical::ActiveDetector(int nDetectorIndex, bool bActive)
  663. {
  664. printf("--Func-- ActiveDetector(%d) to (%d) \r\n", nDetectorIndex, bActive);
  665. FINFO("--Func-- ActiveDetector {$} to {$}", nDetectorIndex, bActive);
  666. RET_STATUS ret = RET_STATUS::RET_SUCCEED;
  667. if (g_pDetector == nullptr)
  668. {
  669. printf("PZMedicalCtrl object is not exist, return RET_FAILED\n");
  670. FERROR("PZMedicalCtrl object is not exist, return RET_FAILED");
  671. return RET_STATUS::RET_FAILED;
  672. }
  673. return ret;
  674. }
  675. //品臻板目前不支持AEC
  676. bool nsFPD::FPDDevicePZMedical::GetLogicMode(string& strAcqMode, int& nLogicMode)
  677. {
  678. if (strAcqMode == "RAD")
  679. {
  680. nLogicMode = RAD;
  681. }
  682. else if (strAcqMode == "AEC")
  683. {
  684. nLogicMode = AEC;
  685. }
  686. else if (strAcqMode == "1")
  687. {
  688. nLogicMode = RAD;
  689. }
  690. else if (strAcqMode == "2")
  691. {
  692. nLogicMode = AEC;
  693. }
  694. else
  695. {
  696. FERROR("Not support mode!");
  697. return false;
  698. }
  699. return true;
  700. }
  701. //设置采集模式 1-RAD 2-AEC
  702. RET_STATUS nsFPD::FPDDevicePZMedical::SetAcqMode(string strAcqMode)
  703. {
  704. printf("--Func-- SetAcqMode %s \n", strAcqMode.c_str());
  705. FINFO("--Func-- SetAcqMode {$}", strAcqMode);
  706. RET_STATUS ret = RET_STATUS::RET_FAILED;
  707. //如果没连接则返回
  708. if (!m_bConnect)
  709. {
  710. FERROR("Detector not connected, return");
  711. return ret;
  712. }
  713. if (m_strCurrentAcqMode == strAcqMode)
  714. {
  715. FINFO("Same acq mode, return true");
  716. return RET_STATUS::RET_SUCCEED;
  717. }
  718. int nMode = RAD;
  719. bool bRet = GetLogicMode(strAcqMode, nMode);
  720. if (!bRet)
  721. {
  722. return ret;
  723. }
  724. try
  725. {
  726. ResDataObject objModeConfig = m_DetectorConfiguration->m_Configurations;
  727. int nModeCount = (int)objModeConfig["ModeTable"].size();
  728. for (int i = 0; i < nModeCount; i++)
  729. {
  730. int nLogicMode = (int)objModeConfig["ModeTable"][i]["LogicMode"];
  731. if (nLogicMode == nMode)
  732. {
  733. FINFO("find LogicMode == AcqMode");
  734. //由于3025ZF出图的宽高不定,所以宽高不从配置文件读取,上图之前调用接口查询宽高然后再推图
  735. //m_nFullImageWidth = (int)objModeConfig["ModeTable"][i]["ImageWidth"];
  736. //m_nFullImageHeight = (int)objModeConfig["ModeTable"][i]["ImageHeight"];
  737. m_nImageBits = (int)objModeConfig["ModeTable"][i]["PhySizeInfoBit"];
  738. m_nPixelSpacing = (int)objModeConfig["ModeTable"][i]["PixelPitch"];
  739. m_nSensitivity = (int)objModeConfig["ModeTable"][i]["Sensitivity"];
  740. m_eSyncMode = (SYNC_MODE)(int)objModeConfig["ModeTable"][i]["SyncType"];
  741. m_nRotateAngle = (int)objModeConfig["ModeTable"][i]["RotateAngle"];
  742. FINFO("m_nImageBits:{$},m_nPixelSpacing:{$},m_nSensitivity:{$},m_eSyncMode:{$},RotateAngle:{$}",
  743. m_nImageBits, m_nPixelSpacing, m_nSensitivity, (int)m_eSyncMode, m_nRotateAngle);
  744. string strSensitivity = to_string(m_nSensitivity);
  745. m_DetectorCtrlUnit->SetFPDSensitivity(strSensitivity);
  746. m_fFactorEXI2UGY = 100.0f / (float)atof(strSensitivity.c_str()) * 1.0f;//子系统将UI的TargetEXI 乘以 FPDSensitivity再传给imagesave,用作计算EXI和DI并填写ecm头
  747. FINFO("m_fFactorEXI2UGY = {$}", m_fFactorEXI2UGY);
  748. //读取DetectorMode配置,并为imagebuffer申请内存空间
  749. if (g_pDetector->SetAcqMode(nLogicMode, this))
  750. {
  751. ret = RET_STATUS::RET_SUCCEED;
  752. }
  753. break;
  754. }
  755. }
  756. }
  757. catch (ResDataObjectExption& e)
  758. {
  759. FERROR("Read configuration failed, Error code: {$}", e.what());
  760. }
  761. return ret;
  762. }
  763. RET_STATUS nsFPD::FPDDevicePZMedical::PrepareAcquisition()
  764. {
  765. printf("--Func-- PrepareAcquisition \n");
  766. FINFO("--Func-- PrepareAcquisition");
  767. RET_STATUS ret = RET_STATUS::RET_FAILED;
  768. if (!m_bConnect)
  769. {
  770. FERROR("Detector not connected, return");
  771. return ret;
  772. }
  773. if ((m_CalibUnit->GetCalibrationStatus() == CCOS_CALIBRATION_STATUS_RUNNING) ||
  774. (m_CalibUnit->GetCalibrationStatus() == CCOS_CALIBRATION_STATUS_ACTIVE))
  775. {
  776. printf("PrepareAcquisition failed. Detector at Calibration status.\n");
  777. FERROR("PrepareAcquisition failed. Detector at Calibration status");
  778. return ret;
  779. }
  780. if (DETECTOR_STATUS_ACQ == m_DetectorCtrlUnit->GetDetectorStatus())
  781. {
  782. printf("Detector already at Acq status.\n");
  783. FERROR("Detector already at Acq status");
  784. ret = RET_STATUS::RET_SUCCEED; //进检查后退检查,如果再次调用prepare,在这里防护
  785. }
  786. if (g_pDetector->PrepareAcquisition(this))
  787. {
  788. ret = RET_STATUS::RET_SUCCEED;
  789. }
  790. FINFO("--Func-- PrepareAcquisition over");
  791. return ret;
  792. }
  793. RET_STATUS nsFPD::FPDDevicePZMedical::StartAcquisition(string in)
  794. {
  795. printf("--Func-- StartAcquisition \n");
  796. FINFO("--Func-- StartAcquisition");
  797. RET_STATUS ret = RET_STATUS::RET_FAILED;
  798. if (!m_bConnect)
  799. {
  800. FERROR("Detector not connected, return");
  801. return ret;
  802. }
  803. if (DETECTOR_STATUS_STANDBY != m_DetectorCtrlUnit->GetDetectorStatus())
  804. {
  805. if ((m_CalibUnit->GetCalibrationStatus() == CCOS_CALIBRATION_STATUS_RUNNING) ||
  806. (m_CalibUnit->GetCalibrationStatus() == CCOS_CALIBRATION_STATUS_ACTIVE))
  807. {
  808. printf("PrepareAcquisition failed. Detector at Calibration status.\n");
  809. FERROR("PrepareAcquisition failed. Detector at Calibration status.");
  810. }
  811. if (DETECTOR_STATUS_ACQ == m_DetectorCtrlUnit->GetDetectorStatus())
  812. {
  813. printf("Detector already at Acq status.\n");
  814. FERROR("Detector already at Acq status.");
  815. }
  816. }
  817. else
  818. {
  819. if (g_pDetector->StartAcquisition(this))
  820. {
  821. ret = RET_STATUS::RET_SUCCEED;
  822. }
  823. else
  824. {
  825. printf("StartAcquisition fail!\n");
  826. FINFO("StartAcquisition fail!");
  827. }
  828. }
  829. FINFO("--Func-- StartAcquisition over");
  830. return ret;
  831. }
  832. RET_STATUS nsFPD::FPDDevicePZMedical::StopAcquisition()
  833. {
  834. printf("--Func-- StopAcquisition \n");
  835. FINFO("--Func-- StopAcquisition");
  836. RET_STATUS ret = RET_STATUS::RET_FAILED;
  837. if (!m_bConnect)
  838. {
  839. FERROR("Detector not connected, return");
  840. return ret;
  841. }
  842. if (DETECTOR_STATUS_STANDBY == m_DetectorCtrlUnit->GetDetectorStatus())
  843. {
  844. printf("Detector status already is standby\n");
  845. FINFO("Detector status already is standby");
  846. ret = RET_STATUS::RET_SUCCEED;
  847. }
  848. else
  849. {
  850. printf("StopAcquisition 111\n");
  851. FINFO("StopAcquisition 111");
  852. if (g_pDetector->StopAcquisition(this))
  853. {
  854. ret = RET_STATUS::RET_SUCCEED;
  855. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));//StopAcquisition
  856. }
  857. }
  858. FINFO("--Func-- StopAcquisition over");
  859. return ret;
  860. }
  861. RET_STATUS nsFPD::FPDDevicePZMedical::ActiveCalibration(CCOS_CALIBRATION_TYPE eType)
  862. {
  863. printf("--Func-- ActiveCalibration %d \n", eType);
  864. FINFO("--Func-- ActiveCalibration type {$}", (int)eType);
  865. RET_STATUS ret = RET_STATUS::RET_FAILED;
  866. if (!m_bConnect)
  867. {
  868. printf("Detector not connected, return\n");
  869. FERROR("Detector not connected, return");
  870. return ret;
  871. }
  872. if (eType == CCOS_CALIBRATION_TYPE_NONE || eType == CCOS_CALIBRATION_TYPE_MAX)
  873. {
  874. return RET_STATUS::RET_INVALID;
  875. }
  876. if (DETECTOR_STATUS_STANDBY != m_DetectorCtrlUnit->GetDetectorStatus())
  877. {
  878. printf("detector status is not standby!\n");
  879. FERROR("detector status is not standby!");
  880. if (DETECTOR_STATUS_ACQ == m_DetectorCtrlUnit->GetDetectorStatus())
  881. {
  882. printf("ActiveCalibration->Detector at Acq status need stop acquisition\n");
  883. FERROR("ActiveCalibration->Detector at Acq status need stop acquisition");
  884. printf("ActiveCalibration stop acquisition\n");
  885. FERROR("ActiveCalibration stop acquisition");
  886. ret = StopAcquisition();
  887. if (ret != RET_STATUS::RET_SUCCEED)
  888. {
  889. printf("stop acquisition error\n");
  890. FERROR("stop acquisition error");
  891. return ret;
  892. }
  893. }
  894. }
  895. m_eAppStatus = APP_STATUS_CAL_BEGIN;
  896. if (eType == CCOS_CALIBRATION_TYPE_XRAY)
  897. {
  898. printf("calibration type: CCOS_CALIBRATION_TYPE_XRAY\n");
  899. FINFO("calibration type: CCOS_CALIBRATION_TYPE_XRAY");
  900. int nCalibrationRounds = (int)m_CalibDoseList.size();
  901. g_pDetector->SetReferenceNum(nCalibrationRounds);
  902. }
  903. if (g_pDetector->ActiveCalibration(this, eType))
  904. {
  905. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_ACTIVE));
  906. m_CalibUnit->SetCalibrationProgress("0");
  907. if (eType == CCOS_CALIBRATION_TYPE_XRAY)
  908. {
  909. FINFO("start to waitting CalibDoseEvt");
  910. printf("start to waitting CalibDoseEvt\n");
  911. DWORD nRet = WaitForSingleObject(m_WaitCalibDoseEvt, INFINITE);
  912. }
  913. m_nXrayCalibNum = 0;
  914. }
  915. else
  916. {
  917. printf("Active calibration failed!\n");
  918. FERROR("Active calibration failed!");
  919. }
  920. //重置校正流程参数
  921. m_nCalibCurrentCalibrationRound = 1;
  922. m_nCalibCurrentExposureIndex = 1;
  923. m_nCalibCurrentExposureNum = 0;
  924. ret = RET_STATUS::RET_SUCCEED;
  925. printf("ActiveCalibration over\n");
  926. FINFO("--Func-- ActiveCalibration over");
  927. return ret;
  928. }
  929. RET_STATUS nsFPD::FPDDevicePZMedical::PrepareCalibration()
  930. {
  931. printf("--Func-- PrepareCalibration------ \n");
  932. FINFO("--Func-- PrepareCalibration");
  933. RET_STATUS ret = RET_STATUS::RET_FAILED;
  934. if (!m_bConnect)
  935. {
  936. printf("Detector not connected, return\n");
  937. FERROR("Detector not connected, return");
  938. return ret;
  939. }
  940. if (g_pDetector->PrepareCalibration(this))
  941. {
  942. ret = RET_STATUS::RET_SUCCEED;
  943. }
  944. else
  945. {
  946. FERROR("Prepare calibration failed");
  947. }
  948. FINFO("--Func-- PrepareCalibration over");
  949. return ret;
  950. }
  951. RET_STATUS nsFPD::FPDDevicePZMedical::GetRequestedDose(std::string& strDose)
  952. {
  953. printf("--Func-- GetRequestedDose------ \n");
  954. FINFO("--Func-- GetRequestedDose");
  955. if (!m_bConnect)
  956. {
  957. return RET_STATUS::RET_THREAD_INVALID;
  958. }
  959. RET_STATUS Ret = RET_STATUS::RET_SUCCEED;
  960. bool bGetDoseInfo = false;
  961. ResDataObject out;
  962. CCOS_CALIBRATION_TYPE nCalibrationType = m_CalibUnit->GetCalibrationType();
  963. FINFO("GetRequestedDose calib type is {$}",(int)nCalibrationType);
  964. printf("GetRequestedDose calib type is %d\n",nCalibrationType);
  965. if (CCOS_CALIBRATION_TYPE_DARK == nCalibrationType)
  966. {
  967. out.add("Dose", 0.0f);
  968. out.add("kV", 0.0f);
  969. out.add("mA", 0.0f);
  970. out.add("ms", 0.0f);
  971. out.add("mAs", 0.0f);
  972. bGetDoseInfo = true;
  973. }
  974. else if (CCOS_CALIBRATION_TYPE_XRAY == nCalibrationType)
  975. {
  976. FINFO("calib dose list size is {$}",m_CalibDoseList.size());
  977. printf("calib dose list size is %d\n",(int)m_CalibDoseList.size());
  978. for (int i = 0; i < m_CalibDoseList.size(); i++)
  979. {
  980. ResDataObject temp = m_CalibDoseList[i];
  981. int nDose = temp["Dose"];
  982. int nDoseParem = (int)(m_fDoseParam * 1000);
  983. if (nDoseParem == nDose)
  984. {
  985. out.add("Dose", nDoseParem);
  986. out.add("kV", temp["kV"]);
  987. out.add("mA", temp["mA"]);
  988. out.add("ms", temp["ms"]);
  989. out.add("mAs", temp["mAs"]);
  990. bGetDoseInfo = true;
  991. FINFO("Find target dose parameter");
  992. break;
  993. }
  994. }
  995. }
  996. else
  997. {
  998. FERROR("Can not support CalibrationType($)", (int)nCalibrationType);
  999. Ret = RET_STATUS::RET_FAILED;
  1000. }
  1001. if (bGetDoseInfo)
  1002. {
  1003. strDose = out.encode();
  1004. FINFO("GetRequestedDose:{$}", strDose.c_str());
  1005. }
  1006. else
  1007. {
  1008. FERROR("GetRequestedDose failed");
  1009. }
  1010. FINFO("--Func-- GetRequestedDose over");
  1011. return Ret;
  1012. }
  1013. RET_STATUS nsFPD::FPDDevicePZMedical::StartCalibration()
  1014. {
  1015. printf("--Func-- StartCalibration------ \n");
  1016. FINFO("--Func-- StartCalibration");
  1017. RET_STATUS Ret = RET_STATUS::RET_FAILED;
  1018. if (!m_bConnect)
  1019. {
  1020. Ret = RET_STATUS::RET_THREAD_INVALID;
  1021. FERROR("detector is not connected");
  1022. return Ret;
  1023. }
  1024. if (DETECTOR_STATUS_STANDBY != m_DetectorCtrlUnit->GetDetectorStatus())
  1025. {
  1026. if (DETECTOR_STATUS_ACQ == m_DetectorCtrlUnit->GetDetectorStatus())
  1027. {
  1028. FERROR("ActiveCalibration failed. Detector at Acq status");
  1029. }
  1030. Ret = RET_STATUS::RET_FAILED;
  1031. return Ret;
  1032. }
  1033. if (g_pDetector->StartCalibration(this))
  1034. {
  1035. printf("start calibration success set detector status\n");
  1036. FINFO("start calibration success set detector status");
  1037. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_RUNNING));
  1038. Ret = RET_STATUS::RET_SUCCEED;
  1039. }
  1040. else
  1041. {
  1042. Ret = RET_STATUS::RET_FAILED;
  1043. }
  1044. printf("StartCalibration over\n");
  1045. FINFO("--Func-- StartCalibration over");
  1046. return Ret;
  1047. }
  1048. RET_STATUS nsFPD::FPDDevicePZMedical::StopCalibration()
  1049. {
  1050. printf("--Func-- StopCalibration------ \n");
  1051. FINFO("--Func-- StopCalibration");
  1052. RET_STATUS Ret = RET_STATUS::RET_FAILED;
  1053. if (!m_bConnect)
  1054. {
  1055. FERROR("Detector not connected, return");
  1056. return Ret;
  1057. }
  1058. m_eAppStatus = APP_STATUS_CAL_END;
  1059. if (RET_STATUS::RET_SUCCEED == g_pDetector->AbortCalibration(this))
  1060. {
  1061. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY));
  1062. Ret = RET_STATUS::RET_SUCCEED;
  1063. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));//AbortCalibration
  1064. }
  1065. else
  1066. {
  1067. Ret = RET_STATUS::RET_FAILED;
  1068. }
  1069. FINFO("--Func-- StopCalibration over");
  1070. return Ret;
  1071. }
  1072. //create device 时调用
  1073. bool nsFPD::FPDDevicePZMedical::LoadConfig()
  1074. {
  1075. printf("--Func-- LoadConfig \r\n");
  1076. FINFO("--Func-- LoadConfig");
  1077. if (!m_DetectorConfiguration->LoadConfigurations(m_stDeviceConfig, m_ACQMODElist))
  1078. {
  1079. FERROR("Load configuration file failed!!!");
  1080. return false;
  1081. }
  1082. if (!m_DetectorConfiguration->LoadCalibrationDose(m_strWorkPath, m_CalibDoseList, m_nCalibTotalExposureNum))
  1083. {
  1084. FERROR("Load Calibration Dose failed!!!");
  1085. return false;
  1086. }
  1087. if (m_stDeviceConfig.nForceGridSuppress > 0)
  1088. {
  1089. m_bForceGridSuppress = true;
  1090. }
  1091. else
  1092. {
  1093. m_bForceGridSuppress = false;
  1094. }
  1095. int nAttached = (int)m_DetectorConfiguration->m_Configurations[CcosDetectorAttachedFlag];
  1096. if (nAttached == 1)
  1097. {
  1098. m_DetectorCtrlUnit->SetAttachStatus("1");
  1099. }
  1100. else
  1101. {
  1102. m_DetectorCtrlUnit->SetAttachStatus("0");
  1103. }
  1104. string strTemp = (string)m_DetectorConfiguration->m_Configurations[DetectorModel];
  1105. m_DetectorCtrlUnit->SetDetectorType(strTemp);
  1106. strTemp = (string)m_DetectorConfiguration->m_Configurations[DetectorDescription];
  1107. m_DetectorCtrlUnit->SetDescription(strTemp);
  1108. m_DetectorCtrlUnit->SetTargetEXI("5000");
  1109. m_Battery.reset(new DeviceBatteryMould("GetRemainPowerValue", 0,
  1110. m_stDeviceConfig.nBatteryLimit,
  1111. m_stDeviceConfig.nBatteryWarning,
  1112. 100, 0, 100, 100,
  1113. 0, EventCenter));
  1114. m_Temperature.reset(new DeviceTemperatureMould("GetTemperatureValue", 0.0f,
  1115. m_stDeviceConfig.fTemperatureMin,
  1116. m_stDeviceConfig.fTemperLowLimit,
  1117. m_stDeviceConfig.fTemperatureMax,
  1118. m_stDeviceConfig.fTemperMaxLimit,
  1119. 0.0f, 0.0f, 0.0f, EventCenter));
  1120. m_Wifi.reset(new DeviceWifiMould("GetWifiStrengthValue", 0,
  1121. m_stDeviceConfig.nWifiLimit,
  1122. m_stDeviceConfig.nWifiWarning,
  1123. 100, 0, 100, 100,
  1124. 0, EventCenter));
  1125. return true;
  1126. }
  1127. void nsFPD::FPDDevicePZMedical::RegisterCtrl(nsDetail::Dispatch* Dispatch)
  1128. {
  1129. Dispatch->Action.Push(ActionKey::ActiveDetector, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSActiveDetector);
  1130. Dispatch->Action.Push(ActionKey::AttachConnect, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSAttachConnect);
  1131. Dispatch->Action.Push(ActionKey::CancelAttach, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSCancelAttach);
  1132. Dispatch->Action.Push(ActionKey::ResetConnect, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSResetConnect);
  1133. Dispatch->Action.Push(ActionKey::DisConnectFPD, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSDisConnectFPD);
  1134. Dispatch->Action.Push(ActionKey::UpdateFirmware, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSUpdateFirmware);
  1135. Dispatch->Action.Push(ActionKey::GetFPDinformation, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDetectorInfo);
  1136. Dispatch->Action.Push(ActionKey::EnterExam, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSEnterExam);
  1137. Dispatch->Action.Push(ActionKey::RecoverImage, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSRecoverImage);
  1138. Dispatch->Action.Push(ActionKey::SaveSensitivity, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSSaveSensitivity);
  1139. Dispatch->Action.Push(ActionKey::RESET, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSRESET);
  1140. Dispatch->Get.Push(AttrKey::DetectorConnectStatus, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetConnectStatus);
  1141. Dispatch->Get.Push(AttrKey::DetectorInitialStatus, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetInitialStatus);
  1142. Dispatch->Get.Push(AttrKey::DetectorUpdateFWStatus, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetUpdateFWStatus);
  1143. Dispatch->Get.Push(AttrKey::FPDShockSensorInfo, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetShockSensorInfo);
  1144. Dispatch->Get.Push(AttrKey::DetectorStatus, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetFPDStatus);
  1145. Dispatch->Get.Push(AttrKey::FPDAttached, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetAttachStatus);
  1146. Dispatch->Get.Push(AttrKey::DetectorAttach, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetAttachResult);
  1147. Dispatch->Get.Push(AttrKey::FieldofViewShape, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetFieldofViewShape);
  1148. Dispatch->Get.Push(AttrKey::FieldofViewDimension, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetFieldofViewDimension);
  1149. Dispatch->Get.Push(AttrKey::DetectorType, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDetectorType);
  1150. Dispatch->Get.Push(AttrKey::Description, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDescription);
  1151. Dispatch->Get.Push(AttrKey::DetectorID, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDetectorID);
  1152. Dispatch->Get.Push(AttrKey::DateofLastDetectorCalibration, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDateofLastDetectorCalibration);
  1153. Dispatch->Get.Push(AttrKey::TimeofLastDetectorCalibration, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetTimeofLastDetectorCalibration);
  1154. Dispatch->Get.Push(AttrKey::DetectorConditionsNominalFlag, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDetectorConditionsNominalFlag);
  1155. Dispatch->Get.Push(AttrKey::FPDSensitivity, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetFPDSensitivity);
  1156. Dispatch->Get.Push(AttrKey::PixelData, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetPixelData);
  1157. Dispatch->Get.Push(AttrKey::TargetEXI, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetTargetEXI);
  1158. }
  1159. void nsFPD::FPDDevicePZMedical::RegisterAcq(nsDetail::Dispatch* Dispatch)
  1160. {
  1161. Dispatch->Action.Push(ActionKey::SetAcqMode, m_AcqUnit.get(), &AcqUnit::JSSetAcqMode);
  1162. Dispatch->Get.Push(AttrKey::ZskkFPDState, m_AcqUnit.get(), &AcqUnit::JSGetZskkFPDState);
  1163. Dispatch->Get.Push(AttrKey::NoNeedWaitImage, m_AcqUnit.get(), &AcqUnit::JSGetNoNeedWaitImage);
  1164. Dispatch->Get.Push(AttrKey::ImgDataInfo, m_AcqUnit.get(), &AcqUnit::JSGetLastImage);
  1165. Dispatch->Get.Push(AttrKey::AutonumousMapFinish, m_AcqUnit.get(), &AcqUnit::JSAutonumousMapFinish);
  1166. }
  1167. void nsFPD::FPDDevicePZMedical::RegisterSync(nsDetail::Dispatch* Dispatch)
  1168. {
  1169. Dispatch->Action.Push(ActionKey::SetSyncMode, m_SyncUnit.get(), &SyncUnit::JSSetSyncMode);
  1170. Dispatch->Action.Push(ActionKey::SetXwindowSize, m_SyncUnit.get(), &SyncUnit::JSSetXwindowSize);
  1171. Dispatch->Action.Push(ActionKey::PrepareAcquisition, m_SyncUnit.get(), &SyncUnit::JSPrepareAcquisition);
  1172. Dispatch->Action.Push(ActionKey::StartAcquisition, m_SyncUnit.get(), &SyncUnit::JSStartAcquisition);
  1173. Dispatch->Action.Push(ActionKey::StopAcquisition, m_SyncUnit.get(), &SyncUnit::JSStopAcquisition);
  1174. Dispatch->Get.Push(AttrKey::FPDReadyStatus, m_SyncUnit.get(), &SyncUnit::JSGetFPDReady);
  1175. Dispatch->Get.Push(AttrKey::XwindowStatus, m_SyncUnit.get(), &SyncUnit::JSGetXWindowStatus);
  1176. Dispatch->Get.Push(AttrKey::ImageReadingStatus, m_SyncUnit.get(), &SyncUnit::JSGetImageReadingStatus);
  1177. Dispatch->Get.Push(AttrKey::XrayON, m_SyncUnit.get(), &SyncUnit::JSGetXrayON);
  1178. Dispatch->Get.Push(AttrKey::SyncMode, m_SyncUnit.get(), &SyncUnit::JSGetSyncMode);
  1179. }
  1180. void nsFPD::FPDDevicePZMedical::RegisterCalib(nsDetail::Dispatch* Dispatch)
  1181. {
  1182. Dispatch->Action.Push(ActionKey::ActiveCalibration, m_CalibUnit.get(), &CalibUnit::JSActiveCalibration);
  1183. Dispatch->Action.Push(ActionKey::GetRequestedDose, m_CalibUnit.get(), &CalibUnit::JSGetRequestedDose);
  1184. Dispatch->Action.Push(ActionKey::SetRequestedDose, m_CalibUnit.get(), &CalibUnit::JSSetRequestedDose);
  1185. Dispatch->Action.Push(ActionKey::PrepareCalibration, m_CalibUnit.get(), &CalibUnit::JSPrepareCalibration);
  1186. Dispatch->Action.Push(ActionKey::StartCalibration, m_CalibUnit.get(), &CalibUnit::JSStartCalibration);
  1187. Dispatch->Action.Push(ActionKey::StopCalibration, m_CalibUnit.get(), &CalibUnit::JSStopCalibration);
  1188. Dispatch->Action.Push(ActionKey::SetCorrectionType, m_CalibUnit.get(), &CalibUnit::JSSetCorrectionType);
  1189. Dispatch->Action.Push(ActionKey::AcceptCalibration, m_CalibUnit.get(), &CalibUnit::JSAcceptCalibration);
  1190. Dispatch->Action.Push(ActionKey::RejectCalibration, m_CalibUnit.get(), &CalibUnit::JSRejectCalibration);
  1191. Dispatch->Action.Push(ActionKey::SaveCalibrationFile, m_CalibUnit.get(), &CalibUnit::JSSaveCalibrationFile);
  1192. Dispatch->Action.Push(ActionKey::GetCalibrationStep, m_CalibUnit.get(), &CalibUnit::JSGetCalibrationStep);
  1193. Dispatch->Get.Push(AttrKey::CalibrationStatus, m_CalibUnit.get(), &CalibUnit::JSGetCalibStatus);
  1194. Dispatch->Get.Push(AttrKey::CalibrationProgress, m_CalibUnit.get(), &CalibUnit::JSGetCalibProgress);
  1195. Dispatch->Get.Push(AttrKey::HaveImgCalibration, m_CalibUnit.get(), &CalibUnit::JSGetHaveImgCalibration);
  1196. Dispatch->Get.Push(AttrKey::UploadCalibrationFilesResult, m_CalibUnit.get(), &CalibUnit::JSGetUploadCalibrationFilesResult);
  1197. Dispatch->Get.Push(AttrKey::SaveCalibrationFileFinish, m_CalibUnit.get(), &CalibUnit::JSGetSaveCalibrationFileFinish);
  1198. }
  1199. void nsFPD::FPDDevicePZMedical::RegisterOthers(nsDetail::Dispatch* Dispatch)
  1200. {
  1201. Dispatch->Get.Push(AttrKey::Temperature_Value, m_Temperature.get(), &DeviceTemperatureMould::JSGetCurrentTemperatureValue);
  1202. Dispatch->Get.Push(AttrKey::Remain_Power_Value, m_Battery.get(), &DeviceBatteryMould::JSGetCurrentBatteryValue);
  1203. Dispatch->Get.Push(AttrKey::Wifi_Strength_Value, m_Wifi.get(), &DeviceWifiMould::JSGetCurrentSignalValue);
  1204. }
  1205. void nsFPD::FPDDevicePZMedical::SendTemperatureValue(float fValue)
  1206. {
  1207. int nStatus = 0;
  1208. m_Temperature->SetTemperature(fValue, nStatus);
  1209. FINFO("SendTemperatureValue: {$}, status {$}", fValue, nStatus);
  1210. }
  1211. void nsFPD::FPDDevicePZMedical::SendWifiValue(int nValue)
  1212. {
  1213. int nStatus = 0;
  1214. m_Wifi->SetSignalValue(nValue, nStatus);
  1215. FINFO("SendWifiValue: {$}, status {$}", nValue, nStatus);
  1216. }
  1217. void nsFPD::FPDDevicePZMedical::SendBatteryValue(int nValue)
  1218. {
  1219. int nStatus = 0;
  1220. m_Battery->SetRemainPowerValue(nValue, nStatus);
  1221. FINFO("SendBatteryValue: {$}, status {$}", nValue, nStatus);
  1222. }
  1223. /// <summary>
  1224. /// 探测器设备 所有 事件处理入口 @PZ_FPD
  1225. /// conf/info/status/data/warning/error
  1226. /// </summary>
  1227. /// <param name="nDetectorID"></param>
  1228. /// <param name="nEventID"></param>
  1229. /// <param name="nEventLevel"></param>
  1230. /// <param name="pszMsg"></param>
  1231. /// <param name="nParam1"></param>
  1232. /// <param name="fParam2"></param>
  1233. /// <param name="nPtrParamLen"></param>
  1234. /// <param name="pParam"></param>
  1235. void nsFPD::FPDDevicePZMedical::OnFPDCallback(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1236. {
  1237. switch (nEventLevel)
  1238. {
  1239. case EVT_LEVEL_CONFIGURATION:
  1240. {
  1241. OnEventProcessConf(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1242. break;
  1243. }
  1244. case EVT_LEVEL_INFORMATOION:
  1245. {
  1246. OnEventProcessInfo(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1247. break;
  1248. }
  1249. case EVT_LEVEL_STATUS:
  1250. {
  1251. OnEventProcessStatus(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1252. break;
  1253. }
  1254. case EVT_LEVEL_DATA:
  1255. {
  1256. OnEventProcessData(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1257. break;
  1258. }
  1259. case EVT_LEVEL_WARNING:
  1260. {
  1261. OnEventProcessWarning(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1262. break;
  1263. }
  1264. case EVT_LEVEL_ERROR:
  1265. {
  1266. OnEventProcessError(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1267. break;
  1268. }
  1269. default:
  1270. break;
  1271. }
  1272. }
  1273. int nsFPD::FPDDevicePZMedical::GetGainExposureNum()
  1274. {
  1275. return m_nCalibTotalExposureNum;
  1276. }
  1277. WORD* nsFPD::FPDDevicePZMedical::GetFullImageData()
  1278. {
  1279. return m_pwFullImageData;
  1280. }
  1281. /// <summary>
  1282. /// 探测器设备 配置 事件处理 @PZ_FPD
  1283. /// 暂不支持 配置
  1284. /// </summary>
  1285. /// <param name="nDetectorID"></param>
  1286. /// <param name="nEventID"></param>
  1287. /// <param name="nEventLevel"></param>
  1288. /// <param name="pszMsg"></param>
  1289. /// <param name="nParam1"></param>
  1290. /// <param name="fParam2"></param>
  1291. /// <param name="nPtrParamLen"></param>
  1292. /// <param name="pParam"></param>
  1293. void nsFPD::FPDDevicePZMedical::OnEventProcessConf(int nDetectorID, int nEventID, int nEventLevel,
  1294. const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1295. {
  1296. switch (nEventID)
  1297. {
  1298. case EVT_CONF_PANEL_SERIAL:
  1299. {
  1300. m_stDeviceConfig.strPanelSerial = pszMsg;
  1301. FINFO("Detector ID:{$}, SN {$}", nDetectorID, pszMsg);
  1302. m_DetectorCtrlUnit->SetDetectorID(m_stDeviceConfig.strPanelSerial);
  1303. break;
  1304. }
  1305. case EVT_CONF_RAW_WIDTH:
  1306. {
  1307. m_nFullImageWidth = nParam1;
  1308. m_stDeviceConfig.nFullImageWidth = nParam1;
  1309. FINFO("Call back Detector ID:{$}, Image Width:{$}", nDetectorID, m_nFullImageWidth);
  1310. break;
  1311. }
  1312. case EVT_CONF_RAW_HIGHT:
  1313. {
  1314. m_nFullImageHeight = nParam1;
  1315. m_stDeviceConfig.nFullImageHeight = nParam1;
  1316. FINFO("Call back Detector ID:{$}, Image Height:{$}", nDetectorID, m_nFullImageHeight);
  1317. break;
  1318. }
  1319. case EVT_CONF_RAW_BITS:
  1320. {
  1321. m_nImageBits = nParam1;
  1322. m_stDeviceConfig.nImageBits = nParam1;
  1323. FINFO("Detector ID:{$}, Image Bit:{$}", nDetectorID, m_nImageBits);
  1324. break;
  1325. }
  1326. case EVT_CONF_PIXELSPACE:
  1327. {
  1328. m_nPixelSpacing = (int)fParam2;;
  1329. m_stDeviceConfig.nPixelSpace = (int)fParam2;
  1330. FINFO("Detector ID:{$}, nPixelSpace:{$}", nDetectorID, m_nPixelSpacing);
  1331. break;
  1332. }
  1333. case EVT_CONF_PREVIEW_WIDTH:
  1334. {
  1335. if (m_stDeviceConfig.nPreviewWidth != nParam1)
  1336. {
  1337. m_stDeviceConfig.nPreviewWidth = nParam1;
  1338. }
  1339. FINFO("Detector ID:{$}, nPreviewWidth:{$}", nDetectorID, m_stDeviceConfig.nPreviewWidth);
  1340. break;
  1341. }
  1342. case EVT_CONF_PREVIEW_HIGHT:
  1343. {
  1344. if (m_stDeviceConfig.nPreviewHeight != nParam1)
  1345. {
  1346. m_stDeviceConfig.nPreviewHeight = nParam1;
  1347. }
  1348. FINFO("Detector ID:{$}, nPreviewHeight:{$}", nDetectorID, m_stDeviceConfig.nPreviewHeight);
  1349. break;
  1350. }
  1351. case EVT_CONF_MODULE_TYPE:
  1352. {
  1353. //m_strModuleType = pszMsg;
  1354. FINFO("Detector ID:{$}, ModuleType {$}", nDetectorID, pszMsg);
  1355. break;
  1356. }
  1357. case EVT_CONF_MODULE_IP:
  1358. {
  1359. //m_strModuleIP = pszMsg;
  1360. FINFO("Detector ID:{$}, ModuleIP {$}", nDetectorID, pszMsg);
  1361. break;
  1362. }
  1363. case EVT_CONF_MODULE_SN:
  1364. {
  1365. //m_strModuleSN = pszMsg;
  1366. FINFO("Detector ID:{$}, ModuleSN {$}", nDetectorID, pszMsg);
  1367. break;
  1368. }
  1369. case EVT_CONF_FIRWARE_UPDATE:
  1370. {
  1371. m_stDeviceConfig.nFirmwareStatus = nParam1;
  1372. FINFO("Detector ID:{$}, FirmwareUpdate:{$}", nDetectorID, m_stDeviceConfig.nFirmwareStatus);
  1373. break;
  1374. }
  1375. case EVT_CONF_PART_NUMBER:
  1376. {
  1377. m_stDeviceConfig.strPartNumber = pszMsg;
  1378. FINFO("Detector ID:{$}, PartNumber:{$}", nDetectorID, pszMsg);
  1379. break;
  1380. }
  1381. case EVT_CONF_BATTERY_SN:
  1382. {
  1383. //m_strBatterySN = pszMsg;
  1384. FINFO("Detector ID:{$}, Battery SN:{$}", nDetectorID, pszMsg);
  1385. break;
  1386. }
  1387. case EVT_CONF_WIFI_SSID:
  1388. {
  1389. m_stDeviceConfig.strWifiSSID = pszMsg;
  1390. FINFO("Detector ID:{$}, WifiSSID:{$}", nDetectorID, pszMsg);
  1391. break;
  1392. }
  1393. case EVT_CONF_IFBOARD:
  1394. {
  1395. m_stDeviceConfig.strInterfaceBoard = pszMsg;
  1396. FINFO("Detector ID:{$}, InterfaceBoard:{$}", nDetectorID, pszMsg);
  1397. break;
  1398. }
  1399. case EVT_CONF_DATECODE:
  1400. {
  1401. m_stDeviceConfig.strDateCode = pszMsg;
  1402. FINFO("Detector ID:{$}, DateCode:{$}", nDetectorID, pszMsg);
  1403. break;
  1404. }
  1405. case EVT_CONF_LIFETIME:
  1406. {
  1407. int nLifeTime = nParam1;
  1408. if ((nLifeTime != m_stDeviceConfig.nLifeTime))
  1409. {
  1410. FINFO("LifeTime:{$}", nLifeTime);
  1411. m_stDeviceConfig.nLifeTime = nLifeTime;
  1412. }
  1413. break;
  1414. }
  1415. default:
  1416. break;
  1417. }
  1418. }
  1419. /// <summary>
  1420. /// 探测器设备 Info 事件处理 @PZ_FPD
  1421. /// 暂不支持 Info
  1422. /// </summary>
  1423. /// <param name="nDetectorID"></param>
  1424. /// <param name="nEventID"></param>
  1425. /// <param name="nEventLevel"></param>
  1426. /// <param name="pszMsg"></param>
  1427. /// <param name="nParam1"></param>
  1428. /// <param name="fParam2"></param>
  1429. /// <param name="nPtrParamLen"></param>
  1430. /// <param name="pParam"></param>
  1431. void nsFPD::FPDDevicePZMedical::OnEventProcessInfo(int nDetectorID, int nEventID, int nEventLevel,
  1432. const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1433. {
  1434. int nID = nDetectorID;
  1435. switch (nEventID)
  1436. {
  1437. case EVT_INFO_POWER_ON:
  1438. {
  1439. int nPowerOn = nParam1;
  1440. FINFO("Detector {$} PowerOn:{$}", nID, nPowerOn);
  1441. if ((nPowerOn != m_stDeviceConfig.nPowerOn) /*&& (m_strBatterySN != "")*/)
  1442. {
  1443. m_stDeviceConfig.nPowerOn = nPowerOn;
  1444. }
  1445. break;
  1446. }
  1447. case EVT_INFO_BATTERY_CAPACITY:
  1448. {
  1449. int nBatteryCapacity = nParam1;
  1450. if ((nBatteryCapacity != m_nBatteryCapacity) /*&& (m_strBatterySN != "")*/)
  1451. {
  1452. FINFO("{$}", nBatteryCapacity);
  1453. m_nBatteryCapacity = nBatteryCapacity;
  1454. }
  1455. break;
  1456. }
  1457. case EVT_INFO_BATTERY_TEMPERATURE:
  1458. {
  1459. float fBatteryTemper = fParam2;
  1460. if (((fBatteryTemper - m_fBatteryTemperature) >= 0.1f) /*&& (m_strBatterySN != "")*/)
  1461. {
  1462. FINFO("temperature:%.2f", fBatteryTemper);
  1463. m_fBatteryTemperature = fBatteryTemper;
  1464. }
  1465. break;
  1466. }
  1467. case EVT_INFO_BATTERY_CHARGES:
  1468. {
  1469. int nBatteryCharges = nParam1;
  1470. if ((nBatteryCharges != m_nBatteryCharges)/* && (m_strBatterySN != "")*/)
  1471. {
  1472. FINFO("Charge number:{$}", nBatteryCharges);
  1473. m_nBatteryCharges = nBatteryCharges;
  1474. }
  1475. break;
  1476. }
  1477. case EVT_INFO_WIFI_DATARATE:
  1478. {
  1479. m_stDeviceConfig.nWifiDataRate = nParam1;
  1480. FINFO("Detector {$} WifiDataRate:{$}", nID, m_stDeviceConfig.nWifiDataRate);
  1481. break;
  1482. }
  1483. case EVT_INFO_WIFI_CHANNEL:
  1484. {
  1485. m_stDeviceConfig.nWifiChannel = nParam1;
  1486. FINFO("Panel {$} WifiChannel:{$}", nID, m_stDeviceConfig.nWifiChannel);
  1487. break;
  1488. }
  1489. case EVT_INFO_WIFI_SIGNALPOWER:
  1490. {
  1491. m_stDeviceConfig.nWifiSignalPower = nParam1;
  1492. break;
  1493. }
  1494. case EVT_INFO_WIFI_NOISEPOWER:
  1495. {
  1496. m_stDeviceConfig.nWifiNoisePower = nParam1;
  1497. FINFO("Panel {$} WifiNoisePower:{$}", nID, m_stDeviceConfig.nWifiNoisePower);
  1498. break;
  1499. }
  1500. case EVT_INFO_FIRMWARE:
  1501. {
  1502. m_stDeviceConfig.strFirmware = pszMsg;
  1503. FINFO("Panel {$} Firmware:{$}", nID, pszMsg);
  1504. break;
  1505. }
  1506. case EVT_INFO_SHOCKSENSOR_INFO:
  1507. {
  1508. FINFO("Receive ShockSensor Info");
  1509. //m_strShockSensor = pszMsg;
  1510. //m_DetectorCtrlUnit->SetShockSensorInfo(m_strShockSensor);
  1511. break;
  1512. }
  1513. case EVT_INFO_CALIBRATIOIN_TIME:
  1514. {
  1515. m_stDeviceConfig.strCalibrationDate = pszMsg;
  1516. FINFO("Panel {$} Calibration Time:{$}", nID, pszMsg);
  1517. m_DetectorCtrlUnit->SetDateofLastDetectorCalibration(m_stDeviceConfig.strCalibrationDate);
  1518. m_DetectorCtrlUnit->SetTimeofLastDetectorCalibration("");
  1519. break;
  1520. }
  1521. case EVT_INFO_CALIBRATIOIN_TIMEL:
  1522. {
  1523. m_stDeviceConfig.strCalibrationLTEDate = pszMsg;
  1524. FINFO("Panel {$} Calibration LTE Time:{$}", nID, pszMsg);
  1525. break;
  1526. }
  1527. case EVT_INFO_FPVOLTAGE:
  1528. {
  1529. //m_strVoltage = pszMsg;
  1530. break;
  1531. }
  1532. default:
  1533. break;
  1534. }
  1535. }
  1536. /// <summary>
  1537. /// 探测器设备状态事件 处理@PZ_FPD
  1538. /// </summary>
  1539. /// <param name="nDetectorID"></param>
  1540. /// <param name="nEventID"></param>
  1541. /// <param name="nEventLevel"></param>
  1542. /// <param name="pszMsg"></param>
  1543. /// <param name="nParam1"></param>
  1544. /// <param name="fParam2"></param>
  1545. /// <param name="nPtrParamLen"></param>
  1546. /// <param name="pParam"></param>
  1547. void nsFPD::FPDDevicePZMedical::OnEventProcessStatus(int nDetectorID, int nEventID, int nEventLevel,
  1548. const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1549. {
  1550. switch (nEventID)
  1551. {
  1552. case EVT_STATUS_INIT:
  1553. {
  1554. if (PANEL_EVENT_END_OK == nParam1)
  1555. {
  1556. FINFO("EVT_STATUS_INIT PANEL_EVENT_END_OK");
  1557. m_DetectorCtrlUnit->SetInitialStatus(to_string(DETECTOR_INI_SUCCESS));
  1558. }
  1559. else if (PANEL_EVENT_END_ERROR == nParam1)
  1560. {
  1561. m_DetectorCtrlUnit->SetInitialStatus(to_string(DETECTOR_INI_FAILED));
  1562. }
  1563. else if (PANEL_EVENT_END == nParam1) //未连接探测器
  1564. {
  1565. m_DetectorCtrlUnit->SetInitialStatus(to_string(DETECTOR_INI_SUCCESS));
  1566. }
  1567. else if (PANEL_EVENT_START == nParam1)
  1568. {
  1569. m_DetectorCtrlUnit->SetInitialStatus(to_string(DETECTOR_INI_START));
  1570. }
  1571. break;
  1572. }
  1573. case EVT_STATUS_MOTION:
  1574. {
  1575. //m_strMotionStatus = pszMsg;
  1576. break;
  1577. }
  1578. case EVT_STATUS_UPDATE_FIRMWARE:
  1579. {
  1580. if (PANEL_EVENT_START == nParam1)
  1581. {
  1582. FINFO("Start update firmware");
  1583. m_DetectorCtrlUnit->SetUpdateFWStatus(to_string(DETECTOR_UFW_START));
  1584. }
  1585. else if (PANEL_EVENT_BEGIN == nParam1)
  1586. {
  1587. FINFO("Update firmware begin");
  1588. m_stDeviceConfig.bConnectStatus = false;
  1589. m_bConnect = false;
  1590. }
  1591. else if (PANEL_EVENT_END_ERROR == nParam1)
  1592. {
  1593. FINFO("Update firmware failed");
  1594. //SendDetectorInfo(); //更新探测器状态图标
  1595. m_DetectorCtrlUnit->SetUpdateFWStatus(to_string(DETECTOR_UFW_ERROR));
  1596. }
  1597. else if (PANEL_EVENT_SUCCESS == nParam1) //
  1598. {
  1599. FINFO("update firmware success");
  1600. //SendDetectorInfo();
  1601. m_DetectorCtrlUnit->SetUpdateFWStatus(to_string(DETECTOR_UFW_SUCCESS));
  1602. }
  1603. break;
  1604. }
  1605. case EVT_STATUS_SELFTEST:
  1606. {
  1607. break;
  1608. }
  1609. case EVT_STATUS_DETECTORSHARE:
  1610. {
  1611. ENUM_PANEL_EVENT_STATE eStatus = (ENUM_PANEL_EVENT_STATE)nParam1;
  1612. switch (eStatus)
  1613. {
  1614. case PANEL_ATTACH_START:
  1615. m_DetectorCtrlUnit->SetConnectStatus(to_string(PANEL_ATTACH_START)); //重置status,避免服务判重,两次attach失败时,不将第二次的失败信息发送给客户端
  1616. FINFO("New Detector Attach start");
  1617. break;
  1618. case PANEL_ATTACH_OVER:
  1619. {
  1620. FINFO("New Detector Attach Over,Prepare to Connecting");
  1621. //m_DetectorCtrlUnit->SetAttachResult(true, m_stDeviceConfig.strDeviceName.c_str(), m_strModuleSN.c_str());
  1622. }
  1623. break;
  1624. case PANEL_ATTACH_FAILED: //UI显示Failed
  1625. {
  1626. FERROR("New Detector Attach failed\n");
  1627. m_DetectorCtrlUnit->SetConnectStatus(to_string(PANEL_ATTACH_FAILED));
  1628. break;
  1629. }
  1630. case PANEL_CONNECT_OK:
  1631. {
  1632. FINFO("EVT_STATUS_DETECTORSHARE PANEL_CONNECT_OK");
  1633. m_DetectorCtrlUnit->SetConnectStatus(to_string(PANEL_CONNECT_OK));
  1634. break;
  1635. }
  1636. case PANEL_CONNECT_ERROR:
  1637. {
  1638. m_DetectorCtrlUnit->SetConnectStatus(to_string(PANEL_CONNECT_ERROR));
  1639. break;
  1640. }
  1641. case PANEL_DISCONNECT_SUCCESS:
  1642. {
  1643. m_nBatteryCapacity = 0;
  1644. //m_strBatterySN = "";
  1645. m_stDeviceConfig.bExisted = false;
  1646. m_stDeviceConfig.bConnectStatus = false;
  1647. m_bConnect = false;
  1648. m_DetectorCtrlUnit->SetConnectStatus(to_string(PANEL_DISCONNECT_SUCCESS));
  1649. break;
  1650. }
  1651. case PANEL_DISCONNECT_ERROR:
  1652. m_DetectorCtrlUnit->SetConnectStatus(to_string(PANEL_DISCONNECT_ERROR));
  1653. break;
  1654. default:
  1655. break;
  1656. }
  1657. break;
  1658. }
  1659. case EVT_STATUS_SINGLEINIT:
  1660. {
  1661. break;
  1662. }
  1663. case EVT_STATUS_SELECTPANEL:
  1664. {
  1665. break;
  1666. }
  1667. case EVT_STATUS_PANEL:
  1668. {
  1669. ENUM_PANEL_STATUS m_ePanelStatus = (ENUM_PANEL_STATUS)nParam1;
  1670. if (PANEL_XWINDOW_ON == nParam1)
  1671. {
  1672. m_SystemTime = { 0 };
  1673. GetLocalTime(&m_SystemTime);
  1674. FINFO("XWindow on time {$}:{$}:{$}:{$}", m_SystemTime.wHour, m_SystemTime.wMinute, m_SystemTime.wSecond, m_SystemTime.wMilliseconds);
  1675. m_SyncUnit->XWindowOnNotify();
  1676. }
  1677. else if (PANEL_XWINDOW_OFF == nParam1)
  1678. {
  1679. m_SystemTime = { 0 };
  1680. GetLocalTime(&m_SystemTime);
  1681. FINFO("XWindow off time {$}:{$}:{$}:{$}", m_SystemTime.wHour, m_SystemTime.wMinute, m_SystemTime.wSecond, m_SystemTime.wMilliseconds);
  1682. m_SyncUnit->XWindowOffNotify();
  1683. }
  1684. else if (PANEL_READY_EXP == nParam1)
  1685. {
  1686. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));//PANEL_READY_EXP
  1687. }
  1688. else if (PANEL_XRAY_ON == nParam1)
  1689. {
  1690. m_SyncUnit->XrayOnNotify();
  1691. }
  1692. else if (PANEL_XRAY_OFF == nParam1)
  1693. {
  1694. m_SyncUnit->XrayOffNotify();
  1695. }
  1696. else if (PANEL_START_ACQ == nParam1)
  1697. {
  1698. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_ACQ));
  1699. }
  1700. break;
  1701. }
  1702. case EVT_STATUS_CALIBRATIOIN:
  1703. {
  1704. ENUM_PANEL_EVENT_STATE eStatus = (ENUM_PANEL_EVENT_STATE)nParam1;
  1705. switch (eStatus)
  1706. {
  1707. case PANEL_EVENT_END_OK:
  1708. FINFO("Calibration process end ok");
  1709. CompleteCalibration();
  1710. break;
  1711. case PANEL_EVENT_END_ERROR:
  1712. FINFO("Calibration process end error");
  1713. break;
  1714. case PANEL_EVENT_START:
  1715. FINFO("Calibration process start");
  1716. break;
  1717. case PANEL_EVENT_SUCCESS:
  1718. FINFO("Calibration process success");
  1719. break;
  1720. case PANEL_EVENT_END:
  1721. FINFO("Calibration process end");
  1722. break;
  1723. case PANEL_EVENT_BEGIN:
  1724. FINFO("Calibration process begin");
  1725. break;
  1726. case PANEL_EVENT_TIMEOUT:
  1727. FINFO("Calibration timeout");
  1728. break;
  1729. default:
  1730. break;
  1731. }
  1732. break;
  1733. }
  1734. case EVT_STATUS_SAVECALIB:
  1735. {
  1736. if (PANEL_EVENT_START == nParam1)
  1737. {
  1738. FINFO("Begin to Save Calibration Files");
  1739. }
  1740. else if (PANEL_EVENT_END_ERROR == nParam1)
  1741. {
  1742. FINFO("Save Calibration Files failed");
  1743. SetEvent(m_UploadCalibMapOver);
  1744. }
  1745. else if (PANEL_EVENT_END == nParam1)
  1746. {
  1747. FINFO("Save Calibration Files Success");
  1748. SetEvent(m_UploadCalibMapOver);
  1749. }
  1750. break;
  1751. }
  1752. case EVT_STATUS_SAVEDEFECT:
  1753. {
  1754. if (PANEL_EVENT_START == nParam1)
  1755. {
  1756. FINFO("Begin to Save Defect Files");
  1757. }
  1758. else if (PANEL_EVENT_END_ERROR == nParam1)
  1759. {
  1760. FINFO("Save Defect Files failed");
  1761. SetEvent(m_UploadCalibMapOver);
  1762. }
  1763. else if (PANEL_EVENT_END == nParam1)
  1764. {
  1765. FINFO("Save Defect Files Success");
  1766. m_stDeviceConfig.bTaskEnd = true;
  1767. SetEvent(m_UploadCalibMapOver);
  1768. }
  1769. break;
  1770. }
  1771. case EVT_STATUS_ACQUISITION:
  1772. {
  1773. ENUM_PANEL_EVENT_STATE eStatus = (ENUM_PANEL_EVENT_STATE)nParam1;
  1774. switch (eStatus)
  1775. {
  1776. case PANEL_EVENT_START:
  1777. FINFO("Acquisition start");
  1778. break;
  1779. case PANEL_EVENT_END_OK:
  1780. FINFO("Acquisition end");
  1781. break;
  1782. case PANEL_EVENT_END_ERROR: //目前不会报错,不会走到这里
  1783. break;
  1784. default:
  1785. break;
  1786. }
  1787. break;
  1788. }
  1789. case EVT_STATUS_SINGLEEXP:
  1790. {
  1791. if (DOSE_TOO_HIGH == nParam1)
  1792. {
  1793. FINFO("Dose too high");
  1794. StopCalibration();
  1795. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY));
  1796. m_CalibUnit->SetCalibrationProgress("100");//make progress
  1797. m_AcqUnit->SendNoNeedWaitImage(true);
  1798. }
  1799. else if (DOSE_TOO_LOW == nParam1)
  1800. {
  1801. FINFO("Dose too low");
  1802. StopCalibration();
  1803. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY));
  1804. m_CalibUnit->SetCalibrationProgress("100");//make progress
  1805. m_AcqUnit->SendNoNeedWaitImage(true);
  1806. }
  1807. else if (DOSE_OBJECT == nParam1)
  1808. {
  1809. FINFO("Dose object");
  1810. StopCalibration();
  1811. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY));
  1812. //m_CalibUnit->SetCalibrationProgress(100);//make progress
  1813. m_AcqUnit->SendNoNeedWaitImage(true);
  1814. }
  1815. else if (DOSE_ACCEPT == nParam1)
  1816. {
  1817. FINFO("Calibration Result is acceptable");
  1818. //m_WarnAndError->OnErrorX("ERR_FPD_DOSE_INVALID");
  1819. SetEvent(m_PauseCalibrationEvt);
  1820. }
  1821. else if (EVT_STATUS_LASTERROR == nParam1)
  1822. {
  1823. //m_strLastError = pszMsg;
  1824. //FINFO("Panel {$} LastError {{$}}", nID, pszMsg);
  1825. }
  1826. break;
  1827. }
  1828. case EVT_STATUS_IMAGEPENDING:
  1829. {
  1830. string strTemp = pszMsg;
  1831. if (strTemp.find("true") != std::string::npos)
  1832. {
  1833. m_bImagePendingOrNot = true;
  1834. }
  1835. else
  1836. {
  1837. m_bImagePendingOrNot = false;
  1838. }
  1839. break;
  1840. }
  1841. case EVT_STATUS_TEMPERATURE:
  1842. {
  1843. float fTemperature = fParam2;
  1844. OnProcessTemperature(nDetectorID, fTemperature);
  1845. m_stDeviceConfig.fCurrentTemperValue = fTemperature;
  1846. //FINFO("Detector {$} Temperature Value:{$}", nDetectorID, fTemperature);
  1847. SendTemperatureValue(m_stDeviceConfig.fCurrentTemperValue);
  1848. break;
  1849. }
  1850. case EVT_STATUS_WIFI:
  1851. {
  1852. int nWifiLevel = nParam1;
  1853. if (m_stDeviceConfig.strDeviceName.find("PZMEDICAL") >= 0 || m_stDeviceConfig.strDeviceName.find("PZMedical") >= 0)
  1854. {
  1855. nWifiLevel = int(nWifiLevel / 0.75);
  1856. if (nWifiLevel > 100)
  1857. {
  1858. nWifiLevel = 100;
  1859. }
  1860. }
  1861. FINFO("Detector {$} Wifi Value:{$}", nDetectorID, nWifiLevel);
  1862. if (nWifiLevel == 0) //WIFI值为0 表明是有线连接,不报错
  1863. {
  1864. FINFO("nWifiLevel == 0, wired connection");
  1865. }
  1866. else if (nWifiLevel < m_stDeviceConfig.nWifiLimit)
  1867. {
  1868. //达到wifi最低值限制
  1869. }
  1870. else if (nWifiLevel <= m_stDeviceConfig.nWifiWarning)
  1871. {
  1872. //达到wifi警告值
  1873. }
  1874. FINFO("detector wifi level:%d", nWifiLevel);
  1875. if (nWifiLevel != m_stDeviceConfig.nCurrentWifiValue)
  1876. {
  1877. FINFO("Channel:{$},SignalPower:{$},NoisePower:{$},DataRate:{$}", m_stDeviceConfig.nWifiChannel, m_stDeviceConfig.nWifiSignalPower, m_stDeviceConfig.nWifiNoisePower, m_stDeviceConfig.nWifiDataRate);
  1878. }
  1879. m_stDeviceConfig.nCurrentWifiValue = nWifiLevel;
  1880. SendWifiValue(m_stDeviceConfig.nCurrentWifiValue);
  1881. break;
  1882. }
  1883. case EVT_STATUS_BATTERY_VALUE:
  1884. {
  1885. int nBatteryValue = nParam1;
  1886. m_stDeviceConfig.nCurrentBatteryValue = nBatteryValue;
  1887. FINFO("Detector {$} Battery Value:{$}", nDetectorID, nBatteryValue);
  1888. SendBatteryValue(m_stDeviceConfig.nCurrentBatteryValue);
  1889. break;
  1890. }
  1891. case EVT_STATUS_BATTERY_CHARGING:
  1892. {
  1893. break;
  1894. }
  1895. case EVT_STATUS_SHOCK_SENSOR:
  1896. {
  1897. break;
  1898. }
  1899. case EVT_STATUS_HALL_SENSOR:
  1900. {
  1901. break;
  1902. }
  1903. case EVT_STATUS_PING:
  1904. {
  1905. break;
  1906. }
  1907. case EVT_STATUS_PMSNOTOPEN:
  1908. {
  1909. string strTemp = pszMsg;
  1910. if (strTemp.find("true") != std::string::npos)
  1911. {
  1912. FINFO("PMS isn't open");
  1913. }
  1914. break;
  1915. }
  1916. case EVT_STATUS_RESTOREFILES:
  1917. {
  1918. break;
  1919. }
  1920. case EVT_STATUS_LASTERROR:
  1921. {
  1922. break;
  1923. }
  1924. case EVT_STATUS_RESET:
  1925. {
  1926. int nStatus = nParam1;
  1927. if (PANEL_RESET_BEGIN == nStatus)
  1928. {
  1929. //弹出滚动条
  1930. }
  1931. else if (PANEL_RESET_OK == nStatus)
  1932. {
  1933. m_bResetDetector = false;
  1934. }
  1935. else if (PANEL_RESET_ERROR == nStatus)
  1936. {
  1937. // //OnError(nID,ERR_FPD_RESET,L"");
  1938. }
  1939. break;
  1940. }
  1941. case EVT_AUTONUMOUS_STATUS:
  1942. {
  1943. ENUM_PANEL_EVENT_STATE eStatus = (ENUM_PANEL_EVENT_STATE)nParam1;
  1944. switch (eStatus)
  1945. {
  1946. case PANEL_CONNECT_ERROR:
  1947. {
  1948. m_DetectorCtrlUnit->SetConnectStatus(to_string(PANEL_CONNECT_ERROR));
  1949. break;
  1950. }
  1951. case PANEL_CONNECT_OK:
  1952. {
  1953. FINFO("EVT_AUTONUMOUS_STATUS PANEL_CONNECT_OK");
  1954. m_DetectorCtrlUnit->SetConnectStatus(to_string(PANEL_CONNECT_OK));
  1955. m_stDeviceConfig.bConnectStatus = true;
  1956. m_bConnect = true;//EVT_AUTONUMOUS_STATUS
  1957. break;
  1958. }
  1959. case PANEL_DISCONNECT_SUCCESS:
  1960. {
  1961. m_nBatteryCapacity = 0;
  1962. m_stDeviceConfig.bExisted = false;
  1963. m_stDeviceConfig.bConnectStatus = false;
  1964. m_bConnect = false;
  1965. m_DetectorCtrlUnit->SetConnectStatus(to_string(PANEL_DISCONNECT_SUCCESS));
  1966. break;
  1967. }
  1968. case PANEL_DISCONNECT_ERROR:
  1969. {
  1970. m_DetectorCtrlUnit->SetConnectStatus(to_string(PANEL_DISCONNECT_ERROR));
  1971. break;
  1972. }
  1973. case PANEL_START_STOREDIMAGE:
  1974. {
  1975. FINFO("Send start autonumous to server");
  1976. m_AcqUnit->SendAutonumousMapFinish(0);
  1977. break;
  1978. }
  1979. case PANEL_END_STOREDIMAGE:
  1980. {
  1981. FINFO("Send finish autonumous to server");
  1982. m_AcqUnit->SendAutonumousMapFinish(1);
  1983. break;
  1984. }
  1985. case PANEL_EXPORT_AUTONUMOUS_FINISH:
  1986. {
  1987. FINFO("Send finish export local autonumous to server");
  1988. m_AcqUnit->SendAutonumousMapFinish(2);
  1989. break;
  1990. }
  1991. default:
  1992. break;
  1993. }
  1994. break;
  1995. }
  1996. default:
  1997. break;
  1998. }
  1999. }
  2000. /// <summary>
  2001. /// 探测器设备图像数据事件 处理 @PZ_FPD
  2002. /// </summary>
  2003. /// <param name="nDetectorID"></param>
  2004. /// <param name="nEventID"></param>
  2005. /// <param name="nEventLevel"></param>
  2006. /// <param name="pszMsg"></param>
  2007. /// <param name="nParam1"></param>
  2008. /// <param name="fParam2"></param>
  2009. /// <param name="nPtrParamLen"></param>
  2010. /// <param name="pParam"></param>
  2011. void nsFPD::FPDDevicePZMedical::OnEventProcessData(int nDetectorID, int nEventID, int nEventLevel,
  2012. const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  2013. {
  2014. switch (nEventID)
  2015. {
  2016. case EVT_DATA_RAW_IMAGE:
  2017. {
  2018. FINFO("Image Arrived Width:{$},Image Height:{$}", m_nFullImageWidth, m_nFullImageHeight);
  2019. if (m_nRotateAngle == 90 || m_nRotateAngle == 270)
  2020. {
  2021. m_AcqUnit->SetFulImageInfo(m_nFullImageWidth, m_nFullImageHeight, m_nImageBits, false);
  2022. }
  2023. else
  2024. {
  2025. m_AcqUnit->SetFulImageInfo(m_nFullImageHeight, m_nFullImageWidth, m_nImageBits, false);
  2026. }
  2027. m_AcqUnit->ImagerPixelSpacingNotify(m_nPixelSpacing);
  2028. if (nullptr != m_pwFullImageData)
  2029. {
  2030. delete m_pwFullImageData;
  2031. m_pwFullImageData = nullptr;
  2032. }
  2033. m_pwFullImageData = new WORD[m_nFullImageWidth * m_nFullImageHeight];
  2034. memcpy(m_pwFullImageData, pParam, m_nFullImageWidth * m_nFullImageHeight * sizeof(WORD));
  2035. if (0 != m_nRotateAngle)
  2036. {
  2037. FINFO("rotate image, m_nRotateAngle:{$}", m_nRotateAngle);
  2038. m_AcqUnit->RotateImage(m_pwFullImageData, m_nFullImageHeight, m_nFullImageWidth, m_nRotateAngle);
  2039. }
  2040. OnProcessImage(m_pwFullImageData);
  2041. break;
  2042. }
  2043. case EVT_DATA_PREVIEW_IMAGE:
  2044. {
  2045. FINFO("Preview Image Arrved");
  2046. FINFO("Current FPD preview image width: %d, height: %d", m_stDeviceConfig.nPreviewWidth, m_stDeviceConfig.nPreviewHeight);
  2047. m_SyncUnit->ImageReadingNotify();
  2048. if (NULL == m_pwPreviewImg)
  2049. {
  2050. m_pwPreviewImg = new WORD[m_stDeviceConfig.nPreviewWidth * m_stDeviceConfig.nPreviewHeight];
  2051. }
  2052. memcpy(m_pwPreviewImg, pParam, m_stDeviceConfig.nPreviewWidth * m_stDeviceConfig.nPreviewHeight * sizeof(WORD));
  2053. OnProcessPreviewImage(m_pwPreviewImg, m_stDeviceConfig.nPreviewWidth, m_stDeviceConfig.nPreviewHeight);
  2054. break;
  2055. }
  2056. case EVT_DATA_DOSEPARAM:
  2057. {
  2058. m_fDoseParam = fParam2;
  2059. SetEvent(m_WaitCalibDoseEvt);
  2060. break;
  2061. }
  2062. default:
  2063. FERROR("Not support this eventID (%d)", nEventID);
  2064. break;
  2065. }
  2066. }
  2067. /// <summary>
  2068. /// 探测器设备 ERROR 事件处理 @PZ_FPD
  2069. /// </summary>
  2070. /// <param name="nDetectorID"></param>
  2071. /// <param name="nEventID"></param>
  2072. /// <param name="nEventLevel"></param>
  2073. /// <param name="pszMsg"></param>
  2074. /// <param name="nParam1"></param>
  2075. /// <param name="fParam2"></param>
  2076. /// <param name="nPtrParamLen"></param>
  2077. /// <param name="pParam"></param>
  2078. void nsFPD::FPDDevicePZMedical::OnEventProcessError(int nDetectorID, int nEventID, int nEventLevel,
  2079. const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  2080. {
  2081. switch (nEventID)
  2082. {
  2083. case EVT_ERR_COMMUNICATE:
  2084. {
  2085. string strTemp = pszMsg;
  2086. if (strTemp.find("true") != std::string::npos)
  2087. {
  2088. m_stDeviceConfig.nWorkstation = -1;
  2089. m_stDeviceConfig.bConnectStatus = false;
  2090. m_bConnect = false;
  2091. m_nBatteryCapacity = 0;
  2092. m_stDeviceConfig.fCurrentTemperValue = 0.0f;
  2093. m_stDeviceConfig.nCurrentWifiValue = 0;
  2094. m_stDeviceConfig.nCurrentBatteryValue = 0;
  2095. SendWifiValue(m_stDeviceConfig.nCurrentWifiValue);
  2096. SendBatteryValue(m_stDeviceConfig.nCurrentBatteryValue);
  2097. SendTemperatureValue(m_stDeviceConfig.fCurrentTemperValue);
  2098. m_AcqUnit->SetZskkFPDState(to_string(ZSKK_FPD_STATE_SHUTDOWN));
  2099. m_DetectorCtrlUnit->SetConnectStatus(to_string(PANEL_DISCONNECT_SUCCESS));
  2100. }
  2101. else if (strTemp.find("false") != std::string::npos)
  2102. {
  2103. FINFO("EVT_ERR_COMMUNICATE false");
  2104. m_stDeviceConfig.bConnectStatus = true;
  2105. m_bConnect = true;//EVT_ERR_COMMUNICATE
  2106. m_AcqUnit->SetZskkFPDState(to_string(ZSKK_FPD_STATE_READY));
  2107. m_DetectorCtrlUnit->SetConnectStatus(to_string(PANEL_CONNECT_OK));
  2108. }
  2109. break;
  2110. }
  2111. case EVT_ERR_EXP_REQUEST:
  2112. FERROR("OnEventProcessError EVT_ERR_EXP_REQUEST");
  2113. break;
  2114. case EVT_ERR_GET_IMAGE:
  2115. FERROR("OnEventProcessError EVT_ERR_GET_IMAGE");
  2116. break;
  2117. case EVT_ERR_MAX_NUMBER:
  2118. FERROR("OnEventProcessError EVT_ERR_MAX_NUMBER");
  2119. break;
  2120. case EVT_ERR_SN_NOTINLIST:
  2121. FERROR("OnEventProcessError EVT_ERR_SN_NOTINLIST");
  2122. break;
  2123. case EVT_ERR_POWER_OFF:
  2124. FERROR("OnEventProcessError EVT_ERR_POWER_OFF");
  2125. break;
  2126. case EVT_ERR_INIT_FAILED:
  2127. {
  2128. string strTemp = pszMsg;
  2129. if (strTemp.find("true") != std::string::npos)
  2130. {
  2131. //AddErrMsg("6", "initialize error");
  2132. }
  2133. else if (strTemp.find("false") != std::string::npos)
  2134. {
  2135. //一般不可恢复
  2136. }
  2137. break;
  2138. }
  2139. default:
  2140. FERROR("Not support this error(%d)", nEventID);
  2141. break;
  2142. }
  2143. }
  2144. /// <summary>
  2145. /// 探测器设备 WARNING 事件 处理 @PZ_FPD
  2146. /// 当前版本不支持,TBD.
  2147. /// </summary>
  2148. /// <param name="nDetectorID"></param>
  2149. /// <param name="nEventID"></param>
  2150. /// <param name="nEventLevel"></param>
  2151. /// <param name="pszMsg"></param>
  2152. /// <param name="nParam1"></param>
  2153. /// <param name="fParam2"></param>
  2154. /// <param name="nPtrParamLen"></param>
  2155. /// <param name="pParam"></param>
  2156. void nsFPD::FPDDevicePZMedical::OnEventProcessWarning(int nDetectorID, int nEventID, int nEventLevel,
  2157. const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  2158. {
  2159. FERROR("Not support this warn(%d)", nEventID);
  2160. }
  2161. bool nsFPD::FPDDevicePZMedical::OnProcessPreviewImage(WORD* pwRawImage, int nWidth, int nHeight)
  2162. {
  2163. FINFO("--Func-- OnProcessPreviewImage Width:{$},Height:{$}", m_stDeviceConfig.nPreviewWidth, m_stDeviceConfig.nPreviewHeight);
  2164. PrevImageDateArrived(pwRawImage);
  2165. return true;
  2166. }
  2167. void nsFPD::FPDDevicePZMedical::PrevImageDateArrived(WORD* pImg)
  2168. {
  2169. AddFrameWithRawHead(IMAGE_PREVIEW, pImg, m_stDeviceConfig.nPreviewWidth * m_stDeviceConfig.nPreviewHeight);
  2170. }
  2171. RET_STATUS nsFPD::FPDDevicePZMedical::AddFrameWithRawHead(IMAGE_VIEW_TYPE Type, WORD* pFrameBuff, DWORD FrameSize)
  2172. {
  2173. string strImageHead = MakeImageHead(Type);
  2174. FINFO("str image head:{$}",strImageHead);
  2175. return m_AcqUnit->AddFrameWithRawHead(Type, strImageHead, pFrameBuff, FrameSize);
  2176. }
  2177. string nsFPD::FPDDevicePZMedical::MakeImageHead(IMAGE_VIEW_TYPE Type)
  2178. {
  2179. if (m_pFullImageHead != NULL)
  2180. {
  2181. delete m_pFullImageHead;
  2182. m_pFullImageHead = nullptr;
  2183. }
  2184. m_SystemTime = { 0 };
  2185. GetLocalTime(&m_SystemTime);
  2186. if (Type == IMAGE_FULL)
  2187. {
  2188. if (m_pFullImageHead == NULL)
  2189. {
  2190. m_pFullImageHead = new ResDataObject;
  2191. ResDataObject json;
  2192. json.add(SM_IMAGE_TYPE, (int)Type);
  2193. json.add(SM_IMAGE_BIT, 16);
  2194. json.add(SM_IMAGE_TAG, 1);
  2195. json.add(SM_IMAGE_INDEX, 1);
  2196. json.add(SM_IMAGE_YEAR, m_SystemTime.wYear);
  2197. json.add(SM_IMAGE_MONTH, m_SystemTime.wMonth);
  2198. json.add(SM_IMAGE_DAY, m_SystemTime.wDay);
  2199. json.add(SM_IMAGE_HOUR, m_SystemTime.wHour);
  2200. json.add(SM_IMAGE_MINUTE, m_SystemTime.wMinute);
  2201. json.add(SM_IMAGE_SEC, m_SystemTime.wSecond);
  2202. json.add(SM_IMAGE_MILLSEC, m_SystemTime.wMilliseconds);
  2203. json.add(SM_IMAGE_LSB, "5000");
  2204. json.add(SM_IMAGE_DOSE, m_nSensitivity);
  2205. json.add(SM_IMAGE_PIXELREPRESENTATION, "1");
  2206. json.add(SM_IMAGE_PIXELSPACING, m_nPixelSpacing);
  2207. json.add(SM_IMAGE_FLIP, "No");
  2208. json.add(SM_IMAGE_ORIGINX, "0");
  2209. json.add(SM_IMAGE_ORIGINY, "0");
  2210. json.add(SM_IMAGE_EXI2UGY, m_fFactorEXI2UGY);
  2211. json.add(SM_IMAGE_TEMP, 0.0f);
  2212. if (90 == m_nRotateAngle || 270 == m_nRotateAngle)
  2213. {
  2214. json.add(SM_IMAGE_WIDTH, m_nFullImageHeight);
  2215. json.add(SM_IMAGE_HEIGHT, m_nFullImageWidth);
  2216. json.add(SM_IMAGE_ROTATION, "Yes");
  2217. }
  2218. else if (180 == m_nRotateAngle)
  2219. {
  2220. json.add(SM_IMAGE_WIDTH, m_nFullImageWidth);
  2221. json.add(SM_IMAGE_HEIGHT, m_nFullImageHeight);
  2222. json.add(SM_IMAGE_ROTATION, "Yes");
  2223. }
  2224. else
  2225. {
  2226. json.add(SM_IMAGE_WIDTH, m_nFullImageWidth);
  2227. json.add(SM_IMAGE_HEIGHT, m_nFullImageHeight);
  2228. json.add(SM_IMAGE_ROTATION, "No");
  2229. }
  2230. m_pFullImageHead->add(SM_IMAGE_HEAD, json);
  2231. }
  2232. else
  2233. {
  2234. (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_YEAR] = m_SystemTime.wYear;
  2235. (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_MONTH] = m_SystemTime.wMonth;
  2236. (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_DAY] = m_SystemTime.wDay;
  2237. (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_HOUR] = m_SystemTime.wHour;
  2238. (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_MINUTE] = m_SystemTime.wMinute;
  2239. (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_SEC] = m_SystemTime.wSecond;
  2240. (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_MILLSEC] = m_SystemTime.wMilliseconds;
  2241. (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_TEMP] = m_stDeviceConfig.fCurrentTemperValue;
  2242. }
  2243. return (*m_pFullImageHead).encode();
  2244. }
  2245. else
  2246. {
  2247. if (m_pPreviewImageHead == NULL)
  2248. {
  2249. m_pPreviewImageHead = new ResDataObject;
  2250. ResDataObject json;
  2251. json.add(SM_IMAGE_TYPE, (int)Type);
  2252. json.add(SM_IMAGE_WIDTH, m_stDeviceConfig.nPreviewWidth);
  2253. json.add(SM_IMAGE_HEIGHT, m_stDeviceConfig.nPreviewHeight);
  2254. json.add(SM_IMAGE_BIT, 16);
  2255. json.add(SM_IMAGE_TAG, 1);
  2256. json.add(SM_IMAGE_INDEX, 1);
  2257. json.add(SM_IMAGE_YEAR, m_SystemTime.wYear);
  2258. json.add(SM_IMAGE_MONTH, m_SystemTime.wMonth);
  2259. json.add(SM_IMAGE_DAY, m_SystemTime.wDay);
  2260. json.add(SM_IMAGE_HOUR, m_SystemTime.wHour);
  2261. json.add(SM_IMAGE_MINUTE, m_SystemTime.wMinute);
  2262. json.add(SM_IMAGE_SEC, m_SystemTime.wSecond);
  2263. json.add(SM_IMAGE_MILLSEC, m_SystemTime.wMilliseconds);
  2264. json.add(SM_IMAGE_LSB, "5000");
  2265. json.add(SM_IMAGE_DOSE, m_nSensitivity);
  2266. json.add(SM_IMAGE_ROTATION, "No");
  2267. json.add(SM_IMAGE_FLIP, "No");
  2268. json.add(SM_IMAGE_ORIGINX, "0");
  2269. json.add(SM_IMAGE_ORIGINY, "0");
  2270. json.add(SM_IMAGE_PIXELSPACING, m_nPixelSpacing);
  2271. json.add(SM_IMAGE_PIXELREPRESENTATION, "1");
  2272. json.add(SM_IMAGE_TEMP, m_stDeviceConfig.fCurrentTemperValue);
  2273. m_pPreviewImageHead->add(SM_IMAGE_HEAD, json);
  2274. }
  2275. else
  2276. {
  2277. (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_YEAR] = m_SystemTime.wYear;
  2278. (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_MONTH] = m_SystemTime.wMonth;
  2279. (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_DAY] = m_SystemTime.wDay;
  2280. (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_HOUR] = m_SystemTime.wHour;
  2281. (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_MINUTE] = m_SystemTime.wMinute;
  2282. (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_SEC] = m_SystemTime.wSecond;
  2283. (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_MILLSEC] = m_SystemTime.wMilliseconds;
  2284. (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_TEMP] = m_stDeviceConfig.fCurrentTemperValue;
  2285. }
  2286. return (*m_pPreviewImageHead).encode();
  2287. }
  2288. }
  2289. bool nsFPD::FPDDevicePZMedical::OnProcessImage(WORD* pwRawImage)
  2290. {
  2291. FINFO("--Func-- OnProcessImage");
  2292. if (pwRawImage == NULL)
  2293. {
  2294. FERROR("pwRawImage is null!");
  2295. return false;
  2296. }
  2297. FullImageDateArrived(pwRawImage);
  2298. FINFO("OnProcessImage Write Frame Over");
  2299. return true;
  2300. }
  2301. RET_STATUS nsFPD::FPDDevicePZMedical::AcceptCalibration()
  2302. {
  2303. printf("--func-- AcceptCalibration\n");
  2304. FINFO("--Func-- AcceptCalibration");
  2305. RET_STATUS Ret = RET_STATUS::RET_SUCCEED;
  2306. if (g_pDetector->AcceptCalibration())
  2307. {
  2308. FINFO("AcceptCalibration over");
  2309. Ret = RET_STATUS::RET_SUCCEED;
  2310. }
  2311. else
  2312. {
  2313. FERROR("AcceptCalibration error");
  2314. Ret = RET_STATUS::RET_FAILED;
  2315. }
  2316. int nExposureNumCurrentRound = (int)m_CalibDoseList[m_nCalibCurrentCalibrationRound - 1]["ExpNum"];
  2317. //完成校正条件:轮数够了,曝光次数够了
  2318. if ((m_nCalibCurrentCalibrationRound == (int)m_CalibDoseList.size()) && (m_nCalibCurrentExposureIndex == nExposureNumCurrentRound))
  2319. {
  2320. FINFO("Calibration Round: {$}, Exposure Index: {$}, Finished", m_nCalibCurrentCalibrationRound, m_nCalibCurrentExposureIndex);
  2321. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));//expose over
  2322. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY));
  2323. m_CalibUnit->SetCalibrationProgress("100");
  2324. return Ret;
  2325. }
  2326. if (m_nCalibCurrentExposureIndex >= nExposureNumCurrentRound) //跳到下一轮校正参数
  2327. {
  2328. m_nCalibCurrentCalibrationRound++;
  2329. m_nCalibCurrentExposureIndex = 1;
  2330. ResDataObject temp = m_CalibDoseList[m_nCalibCurrentCalibrationRound - 1];
  2331. int nDose = temp["Dose"];
  2332. m_fDoseParam = nDose / 1000.0f;
  2333. }
  2334. else
  2335. {
  2336. m_nCalibCurrentExposureIndex++;
  2337. }
  2338. m_nCalibCurrentExposureNum++;
  2339. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));//AcceptCalibration
  2340. FINFO("--func-- AcceptCalibration over");
  2341. return Ret;
  2342. }
  2343. RET_STATUS nsFPD::FPDDevicePZMedical::RejectCalibration()
  2344. {
  2345. printf("--Func-- RejectCalibration \n");
  2346. FINFO("--func-- RejectCalibration");
  2347. RET_STATUS Ret = RET_STATUS::RET_SUCCEED;
  2348. if (g_pDetector->RejectCalibration())
  2349. {
  2350. Ret = RET_STATUS::RET_SUCCEED;
  2351. }
  2352. else
  2353. {
  2354. FERROR("RejectCalibration error");
  2355. Ret = RET_STATUS::RET_FAILED;
  2356. }
  2357. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));//RejectCalibration
  2358. FINFO("--func-- RejectCalibration over");
  2359. return Ret;
  2360. }
  2361. RET_STATUS nsFPD::FPDDevicePZMedical::SaveCalibrationFile(bool bSaveFlag)
  2362. {
  2363. printf("--Func-- SaveCalibrationFile \n");
  2364. FINFO("--func-- SaveCalibrationFile");
  2365. RET_STATUS Ret = RET_STATUS::RET_SUCCEED;
  2366. FINFO("SaveCalibrationFile by user: {$}", bSaveFlag);
  2367. if (!bSaveFlag)
  2368. {
  2369. FERROR("Not save calibration file");
  2370. return Ret;
  2371. }
  2372. if (g_pDetector->SaveCalibrationFile())
  2373. {
  2374. FINFO("SaveCalibrationFile over");
  2375. m_CalibUnit->SetSaveCalibrationFileFinish(true);
  2376. Ret = RET_STATUS::RET_SUCCEED;
  2377. }
  2378. else
  2379. {
  2380. FERROR("SaveCalibrationFile error");
  2381. m_CalibUnit->SetSaveCalibrationFileFinish(false);
  2382. Ret = RET_STATUS::RET_FAILED;
  2383. }
  2384. FINFO("--func-- SaveCalibrationFile over");
  2385. return Ret;
  2386. }
  2387. void nsFPD::FPDDevicePZMedical::FullImageDateArrived(WORD* pImg)
  2388. {
  2389. FINFO("--func-- FullImageDateArrived");
  2390. AddFrameWithRawHead(IMAGE_FULL, pImg, m_nFullImageWidth * m_nFullImageHeight);
  2391. }
  2392. RET_STATUS nsFPD::FPDDevicePZMedical::SetRequestedDose(std::string strDose)
  2393. {
  2394. FINFO("--func-- SetRequestedDose");
  2395. RET_STATUS Ret = RET_STATUS::RET_SUCCEED;
  2396. return Ret;
  2397. }
  2398. RET_STATUS nsFPD::FPDDevicePZMedical::GetCalibrationStep(int nDetectorID, string& strCalibrationStepInfo)
  2399. {
  2400. printf("--func-- GetCalibrationStep\n");
  2401. FINFO("--func-- GetCalibrationStep");
  2402. RET_STATUS Ret = RET_STATUS::RET_SUCCEED;
  2403. FINFO("Calibration DetectorID: {$}", nDetectorID);
  2404. ResDataObject out;
  2405. int nCalibrationRounds = (int)m_CalibDoseList.size();
  2406. int nExposureNumCurrentRound = (int)m_CalibDoseList[m_nCalibCurrentCalibrationRound - 1]["ExpNum"];
  2407. if (g_pDetector->GetCalibrationStep(m_nCalibCurrentCalibrationRound, nCalibrationRounds, m_nCalibCurrentExposureIndex, nExposureNumCurrentRound))
  2408. {
  2409. FINFO("PZMedicalCtrl GetCalibrationStep success");
  2410. Ret = RET_STATUS::RET_SUCCEED;
  2411. }
  2412. else
  2413. {
  2414. FERROR("GetCalibrationStep error");
  2415. Ret = RET_STATUS::RET_FAILED;
  2416. }
  2417. out.add("CalibrationRounds", (int)m_CalibDoseList.size());
  2418. out.add("TotalExposureNum", m_nCalibTotalExposureNum);
  2419. out.add("CurrentCalibrationRound", m_nCalibCurrentCalibrationRound);
  2420. out.add("ExposureNumCurrentRound", (int)m_CalibDoseList[m_nCalibCurrentCalibrationRound - 1]["ExpNum"]);
  2421. out.add("CurrentExposureIndex", m_nCalibCurrentExposureIndex);
  2422. out.add("CurrentExposureNum", m_nCalibCurrentExposureNum);
  2423. strCalibrationStepInfo = out.encode();
  2424. FINFO("GetCalibrationStep over,strCalibrationStepInfo: {$}", strCalibrationStepInfo.c_str());
  2425. return Ret;
  2426. }
  2427. RET_STATUS nsFPD::FPDDevicePZMedical::PauseCalibration()
  2428. {
  2429. printf("--Func-- PauseCalibration\n");
  2430. FINFO("--func-- PauseCalibration");
  2431. RET_STATUS Ret = RET_STATUS::RET_SUCCEED;
  2432. m_nXrayCalibNum++;
  2433. int nDose = (int)m_fDoseParam;
  2434. if (nDose == 25 && m_nXrayCalibNum == m_nCalibTotalExposureNum)
  2435. {
  2436. FINFO("start to waitting CalibDoseEvt");
  2437. DWORD nRet = WaitForSingleObject(m_WaitCalibDoseEvt, INFINITE);
  2438. //m_nXrayCalibNum = 0;
  2439. }
  2440. else if (nDose != 25)
  2441. {
  2442. if (m_nXrayCalibNum != m_nCalibTotalExposureNum)
  2443. {
  2444. FINFO("start to waitting CalibDoseEvt");
  2445. DWORD nRet = WaitForSingleObject(m_WaitCalibDoseEvt, INFINITE);
  2446. }
  2447. }
  2448. if (m_nXrayCalibNum != m_nCalibTotalExposureNum)
  2449. {
  2450. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));//PauseCalibration
  2451. m_CalibUnit->PauseCalibration();
  2452. }
  2453. FINFO("Driver PauseCalibration over,m_nXrayCalibNum {$}", m_nXrayCalibNum);
  2454. FINFO("--func-- PauseCalibration over");
  2455. return Ret;
  2456. }
  2457. bool nsFPD::FPDDevicePZMedical::CompleteCalibration()
  2458. {
  2459. printf("--func-- CompleteCalibration \n");
  2460. FINFO("--func-- CompleteCalibration");
  2461. m_stDeviceConfig.fCalibTemperature2 = m_stDeviceConfig.fCurrentTemperValue;
  2462. m_stDeviceConfig.fCalibTemperature = (m_stDeviceConfig.fCalibTemperature1 + m_stDeviceConfig.fCalibTemperature2) / 2;
  2463. g_pDetector->CompleteCalibration(this);
  2464. if (g_pDetector->GetPZMedicalCtrlCalibType() == CCOS_CALIBRATION_TYPE_DARK)
  2465. {
  2466. FINFO("CompleteCalibration get Calibration Type:{$}", (int)CCOS_CALIBRATION_TYPE_DARK);
  2467. printf("CompleteCalibration get Calibration Type: dark\n");
  2468. }
  2469. else if (g_pDetector->GetPZMedicalCtrlCalibType() == CCOS_CALIBRATION_TYPE_XRAY)
  2470. {
  2471. FINFO("PZMedical Ctrl Calibration Type:{$}", (int)CCOS_CALIBRATION_TYPE_XRAY);
  2472. printf("CompleteCalibration get Calibration Type: xray\n");
  2473. DWORD nRet = WaitForSingleObject(m_UploadCalibMapOver, 60000);
  2474. if (WAIT_OBJECT_0 == nRet)
  2475. {
  2476. FINFO("got event m_UploadCalibMapOver");
  2477. }
  2478. else if (WAIT_TIMEOUT == nRet)
  2479. {
  2480. FINFO("wait event m_UploadCalibMapOver timeout");
  2481. }
  2482. else
  2483. {
  2484. FINFO("wait event m_UploadCalibMapOver error");
  2485. }
  2486. }
  2487. printf("CompleteCalibration set detector status standby\n");
  2488. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));//CompleteCalibration
  2489. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY));
  2490. //通知子系统结束暗场校正太快了,导致后边的服务通知app的消息混乱了(不是一个进程的原因)acqservice,故此处延时1s
  2491. printf("Sleep 1s,then send progress 100\n");
  2492. FINFO("Sleep 1s,then send progress 100");
  2493. Sleep(1000);
  2494. m_CalibUnit->SetCalibrationProgress("100");
  2495. FINFO("--func-- CompleteCalibration over");
  2496. return true;
  2497. }
  2498. void nsFPD::FPDDevicePZMedical::AbortCalibration()
  2499. {
  2500. printf("--func-- AbortCalibration\n");
  2501. FINFO("--func--AbortCalibration");
  2502. CCOS_CALIBRATION_TYPE nCalibrationType = m_CalibUnit->GetCalibrationType();
  2503. if (CCOS_CALIBRATION_TYPE_DARK == nCalibrationType)
  2504. {
  2505. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));//AbortCalibration dark
  2506. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY));
  2507. m_CalibUnit->SetCalibrationProgress("100");
  2508. FINFO("--func-- AbortCalibration over");
  2509. return;
  2510. }
  2511. m_eAppStatus = APP_STATUS_CAL_END;
  2512. g_pDetector->AbortCalibration(this);
  2513. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));//AbortCalibration gain
  2514. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY));
  2515. m_CalibUnit->SetCalibrationProgress("100");
  2516. m_AcqUnit->SendNoNeedWaitImage(true);
  2517. FINFO("--func-- AbortCalibration over");
  2518. }
  2519. void nsFPD::FPDDevicePZMedical::OnProcessTemperature(int nID, float fTemperature)
  2520. {
  2521. string strWarnErrorCode = "";
  2522. float fMaxTempGap = 6.0f;
  2523. if (m_stDeviceConfig.strDeviceName.find("PZMEDICAL") >= 0 || m_stDeviceConfig.strDeviceName.find("PZMedical") >= 0)
  2524. {
  2525. fMaxTempGap = 12.0f;
  2526. }
  2527. if (fTemperature >= m_stDeviceConfig.fTemperMaxLimit)
  2528. {
  2529. FINFO("Exceed Max Temperature");
  2530. m_stDeviceConfig.nTemperatureStatus = TEMP_TOO_HIGH;
  2531. if (m_stDeviceConfig.bActived)
  2532. {
  2533. strWarnErrorCode = "ERR_FPD_TEMPHIGH_NOT_ACQ";
  2534. }
  2535. }
  2536. else if (fTemperature <= m_stDeviceConfig.fTemperMinLimit)
  2537. {
  2538. m_stDeviceConfig.nTemperatureStatus = TEMP_TOO_LOW;
  2539. if (m_stDeviceConfig.bActived)
  2540. {
  2541. FINFO("Exceed Min Temperature");
  2542. strWarnErrorCode = "ERR_FPD_TEMPLOW_NOT_ACQ";
  2543. }
  2544. }
  2545. else if (fTemperature <= m_stDeviceConfig.fTemperLowLimit)
  2546. {
  2547. m_stDeviceConfig.nTemperatureStatus = TEMP_WARNING;
  2548. FINFO("Exceed Temperature Low Warning");
  2549. strWarnErrorCode = "WAR_FPD_TEMPERTURE_LOW";
  2550. }
  2551. else if (fTemperature > m_stDeviceConfig.fTemperUpperLimit)
  2552. {
  2553. FINFO("Exceed Temperature High Warning");
  2554. m_stDeviceConfig.nTemperatureStatus = TEMP_WARNING;
  2555. strWarnErrorCode = "WAR_FPD_TEMPERATURE_HIGH";
  2556. }
  2557. else if ((m_stDeviceConfig.fCalibTemperature > 1.0f) && (abs(fTemperature - m_stDeviceConfig.fCalibTemperature) >= fMaxTempGap))
  2558. {
  2559. FINFO("Exceed Calibration Temperature");
  2560. m_stDeviceConfig.nTemperatureStatus = TEMP_WARNING;
  2561. strWarnErrorCode = "WAR_FPD_EXCEED_CALB_TEMPER";
  2562. }
  2563. else if ((fTemperature <= m_stDeviceConfig.fTemperUpperLimit) && (fTemperature > m_stDeviceConfig.fTemperLowLimit))
  2564. {
  2565. //FINFO("Temperature Normal");
  2566. }
  2567. }
  2568. //慎重调用,可能会导致板出问题,硬reset需要很长时间
  2569. RET_STATUS nsFPD::FPDDevicePZMedical::Reset()
  2570. {
  2571. printf("--Func-- Reset\n");
  2572. FINFO("--func-- Reset");
  2573. RET_STATUS Ret = RET_STATUS::RET_SUCCEED;
  2574. if (g_pDetector->ResetDetector(this))
  2575. {
  2576. Ret = RET_STATUS::RET_SUCCEED;
  2577. }
  2578. else
  2579. {
  2580. Ret = RET_STATUS::RET_FAILED;
  2581. }
  2582. FINFO("--func-- Reset over");
  2583. return Ret;
  2584. }
  2585. /***
  2586. * 客户端获取探测器信息
  2587. ***/
  2588. RET_STATUS nsFPD::FPDDevicePZMedical::GetDetectorInfo(string& strFDI)
  2589. {
  2590. ResDataObject strDetectorInfo;
  2591. FINFO("GetDetectorInfo m_stDeviceConfig.strPanelSerial:{$}", m_stDeviceConfig.strPanelSerial);
  2592. if (m_stDeviceConfig.strPanelSerial == "")
  2593. {
  2594. FERROR("strPanelSerial is null!!! Send Default Info");
  2595. strDetectorInfo.add("DetectorName", "Simulator");
  2596. strDetectorInfo.add("DetectorSN", "Simulator");
  2597. strDetectorInfo.add("Firmware", " ");
  2598. strDetectorInfo.add("APFirmware", " ");
  2599. strDetectorInfo.add("Software", m_stDeviceConfig.strSoftware.c_str());
  2600. strDetectorInfo.add("SSID", " ");
  2601. strDetectorInfo.add("LifeTime", "0");
  2602. strDetectorInfo.add("PowerOn", "0");
  2603. strDetectorInfo.add("DateCode", " ");
  2604. strDetectorInfo.add("PartNumber", " ");
  2605. strDetectorInfo.add("WifiDataRate", " ");
  2606. strDetectorInfo.add("WifiChannel", "0");
  2607. strDetectorInfo.add("DetectorExist", "0");
  2608. strDetectorInfo.add("SystemAS", "0");
  2609. strDetectorInfo.add("CalibrationDate", "0");
  2610. strDetectorInfo.add("CalibrationDue", "0");
  2611. strDetectorInfo.add("CalibrationExist", "0");
  2612. strDetectorInfo.add("CommunicationStatus", "0");
  2613. strDetectorInfo.add("DetectorTemperature", "0");
  2614. strDetectorInfo.add("FDCalibrationTemperature", "0");
  2615. strDetectorInfo.add("TemperatureStatus", "0");
  2616. strDetectorInfo.add("WaitTime", "0");
  2617. strDetectorInfo.add("DetectorWifiSignal", "0");
  2618. strDetectorInfo.add("DetectorBattery", "0");
  2619. strDetectorInfo.add("ShockSensor", "NULL");
  2620. strDetectorInfo.add("FirmwareUpdate", "0");
  2621. strFDI = strDetectorInfo.encode();
  2622. return RET_STATUS::RET_SUCCEED;
  2623. }
  2624. strDetectorInfo.add("DetectorName", m_stDeviceConfig.strDeviceName.c_str());
  2625. strDetectorInfo.add("DetectorSN", m_stDeviceConfig.strPanelSerial.c_str());
  2626. strDetectorInfo.add("Firmware", m_stDeviceConfig.strFirmware.c_str());
  2627. strDetectorInfo.add("APFirmware", "NULL");
  2628. strDetectorInfo.add("Software", m_stDeviceConfig.strSoftware.c_str());
  2629. strDetectorInfo.add("SSID", m_stDeviceConfig.strWifiSSID.c_str());
  2630. strDetectorInfo.add("LifeTime", m_stDeviceConfig.nLifeTime);
  2631. strDetectorInfo.add("PowerOn", m_stDeviceConfig.nPowerOn);
  2632. strDetectorInfo.add("DateCode", m_stDeviceConfig.strDateCode.c_str());
  2633. strDetectorInfo.add("PartNumber", m_stDeviceConfig.strPartNumber.c_str());
  2634. strDetectorInfo.add("WifiDataRate", m_stDeviceConfig.nWifiDataRate);
  2635. strDetectorInfo.add("WifiChannel", m_stDeviceConfig.nWifiChannel);
  2636. strDetectorInfo.add("DetectorExist", m_stDeviceConfig.bExisted);
  2637. //System Workstation
  2638. if (m_stDeviceConfig.strDeviceName.find("PZMEDICAL") >= 0 || m_stDeviceConfig.strDeviceName.find("PZMedical") >= 0)
  2639. {
  2640. strDetectorInfo.add("SystemAS", 3);
  2641. }
  2642. else
  2643. {
  2644. strDetectorInfo.add("SystemAS", 3);
  2645. }
  2646. //DetectorCalibrationDate
  2647. if (m_stDeviceConfig.strCalibrationDate != " ")
  2648. {
  2649. if (m_stDeviceConfig.strCalibrationDate.find("19700101") != std::string::npos)
  2650. {
  2651. strDetectorInfo.add("CalibrationDate", "0");
  2652. strDetectorInfo.add("CalibrationDue", "0");
  2653. strDetectorInfo.add("CalibrationExist", 0);
  2654. }
  2655. else
  2656. {
  2657. strDetectorInfo.add("CalibrationDate", m_stDeviceConfig.strCalibrationDate.c_str()/*"20210610"*/);
  2658. strDetectorInfo.add("CalibrationDue", m_stDeviceConfig.strCalibrationDue.c_str()/*"20210610"*/);
  2659. strDetectorInfo.add("CalibrationExist", 1);
  2660. }
  2661. }
  2662. else
  2663. {
  2664. strDetectorInfo.add("CalibrationDate", "0");
  2665. strDetectorInfo.add("CalibrationDue", "0");
  2666. strDetectorInfo.add("CalibrationExist", 0);
  2667. }
  2668. if (m_stDeviceConfig.bConnectStatus)
  2669. {
  2670. strDetectorInfo.add("CommunicationStatus", 1);
  2671. }
  2672. else
  2673. {
  2674. strDetectorInfo.add("CommunicationStatus", 0);
  2675. }
  2676. strDetectorInfo.add("FDCalibrationTemperature", m_stDeviceConfig.fCalibTemperature);
  2677. strDetectorInfo.add("ShockSensor", m_nShockCounts);
  2678. strDetectorInfo.add("FirmwareUpdate", 0);
  2679. strFDI = strDetectorInfo.encode();
  2680. return RET_STATUS::RET_SUCCEED;
  2681. }
  2682. RET_STATUS nsFPD::FPDDevicePZMedical::ResetConnect()
  2683. {
  2684. FINFO("--Func-- ResetConnect");
  2685. g_pDetector->Disconnect();
  2686. g_pDetector->Connect(this,m_strWorkPath.c_str());
  2687. return RET_STATUS::RET_SUCCEED;
  2688. }