DIOS.Dev.FPD.CareRayDR.cpp 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859
  1. #include "stdafx.h"
  2. #include "CCOS.Dev.FPD.CareRayDR.h"
  3. #include "common_api.h"
  4. #include "DICOMImageHeadKey.h"
  5. #include "Detector_CareRayDR.h"
  6. namespace nsFPD = CCOS::Dev::Detail::Detector;
  7. //-----------------------------------------------------------------------------
  8. // FPDDeviceCareRay
  9. //-----------------------------------------------------------------------------
  10. extern Detector_CareRayDR* g_pDetector;
  11. static nsFPD::CareRayDriver gIODriver;
  12. Log4CPP::Logger* gLogger = nullptr;
  13. extern "C" CCOS::Dev::IODriver * __cdecl GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
  14. {
  15. return &gIODriver;
  16. }
  17. extern "C" CCOS::Dev::IODriver * __cdecl CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
  18. {
  19. return new nsFPD::CareRayDriver();
  20. }
  21. nsFPD::CareRayDriver::CareRayDriver()
  22. {
  23. pObjDev = nullptr;
  24. m_bDriverConnect = false; //缺省为false
  25. m_pAttribute.reset(new ResDataObject());
  26. m_pDescription.reset(new ResDataObject());
  27. }
  28. nsFPD::CareRayDriver::~CareRayDriver()
  29. {
  30. if (pObjDev != nullptr)
  31. {
  32. delete pObjDev;
  33. pObjDev = nullptr;
  34. }
  35. }
  36. void nsFPD::CareRayDriver::Prepare()
  37. {
  38. printf("CareRayDR driver module: prepare \r\n");
  39. string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Detector\Conf\Log4CPP.Config.FPD.xml)";
  40. Log4CPP::GlobalContext::Map::Set(ZSKK::Utility::Hash("LogFileName"), "FPD.CareRayDR");
  41. auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
  42. gLogger = Log4CPP::LogManager::GetLogger("FPD.CareRayDR");
  43. Info("CareRayDriver::Prepare get logger FPD.CareRayDR");
  44. }
  45. bool nsFPD::CareRayDriver::Connect()
  46. {
  47. printf("CareRay driver module: Connect \r\n");
  48. Info("--Func-- driver connect \n");
  49. pObjDev = new FPDDeviceCareRay(EventCenter, m_ConfigFileName);
  50. m_bDriverConnect = true; //connect执行完毕,置为true
  51. printf("CareRay driver module: Connect over\r\n");
  52. return true;
  53. }
  54. void nsFPD::CareRayDriver::Disconnect()
  55. {
  56. printf("CareRay driver module: Disconnect \r\n");
  57. Info("--Func-- driver disconnect \n");
  58. m_bDriverConnect = false; //disconnect置为false
  59. }
  60. bool nsFPD::CareRayDriver::isConnected() const
  61. {
  62. return m_bDriverConnect;
  63. }
  64. auto nsFPD::CareRayDriver::CreateDevice(int index)->std::unique_ptr <IODevice>
  65. {
  66. printf("CareRay driver module: CreateDevice \r\n");
  67. Info("--Func-- driver createdevice \n");
  68. auto Device = std::unique_ptr<IODevice>(new IODevice(pObjDev));
  69. pObjDev->CreateDevice();
  70. pObjDev->Register();
  71. return Device;
  72. }
  73. std::string nsFPD::CareRayDriver::DriverProbe()
  74. {
  75. printf("CareRayDriver::DriverProbe \r\n");
  76. Info("CareRayDriver::DriverProbe config name:{$}", m_ConfigFileName);
  77. ResDataObject r_config, HardwareInfo;
  78. if (r_config.loadFile(m_ConfigFileName.c_str()))
  79. {
  80. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  81. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  82. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  83. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  84. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  85. }
  86. else
  87. {
  88. HardwareInfo.add("MajorID", "Detector");
  89. HardwareInfo.add("MinorID", "DR");
  90. HardwareInfo.add("VendorID", "CareRay");
  91. HardwareInfo.add("ProductID", "4343W");
  92. HardwareInfo.add("SerialID", "Driver");
  93. }
  94. string str = HardwareInfo.encode();
  95. return str;
  96. }
  97. /***
  98. ** 获取ID和配置
  99. ***/
  100. std::string nsFPD::CareRayDriver::GetResource()
  101. {
  102. ResDataObject r_config, temp;
  103. if (!temp.loadFile(m_ConfigFileName.c_str()))
  104. {
  105. Error("GetResource load {$} fail!", m_ConfigFileName);
  106. return "";
  107. }
  108. m_ConfigAll = temp;
  109. r_config = temp["CONFIGURATION"];
  110. m_Configurations = r_config;
  111. ResDataObject DescriptionTemp;
  112. ResDataObject ListTemp;
  113. string strTemp = ""; //用于读取字符串配置信息
  114. string strIndex = ""; //用于读取配置信息中的List项
  115. int nTemp = -1; //用于读取整型配置信息
  116. char sstream[10] = { 0 }; //用于转换值
  117. string strValue = ""; //用于存储配置的值
  118. string strType = ""; //用于存储配置的类型 int/float/string...
  119. string strAccess = ""; //用于存储权限的类型 R/W/RW
  120. string strRequired = ""; // TRUE/FALSE
  121. string strDefaultValue = "";
  122. string strRangeMin = "";
  123. string strRangeMax = "";
  124. try
  125. {
  126. string strFPD = (string)r_config["VendorID"];
  127. ConfigInfo FPDVender(ConfKey::CcosDetectorType, "string", "R", "TRUE", strFPD.c_str());
  128. AddConfig(FPDVender);
  129. strFPD = (string)r_config["ProductID"];
  130. ConfigInfo FPDModel(ConfKey::CcosDetectorModel, "string", "R", "TRUE", strFPD.c_str());
  131. AddConfig(FPDModel);
  132. int nConfigInfoCount = (int)r_config["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  133. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  134. {
  135. DescriptionTemp.clear();
  136. ListTemp.clear();
  137. //AttributeType
  138. strType = (string)r_config["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Type"];
  139. //AttributeAccess
  140. strAccess = (string)r_config["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Access"];
  141. //AttributeRequired
  142. strRequired = (string)r_config["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Required"];
  143. //AttributeDefaultValue
  144. strDefaultValue = (string)r_config["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["DefaultValue"];
  145. strTemp = (string)r_config["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  146. ConfigInfo FPDAttr(strTemp.c_str(), strType.c_str(), strAccess.c_str(), strRequired.c_str(), strDefaultValue.c_str());
  147. //AttributeKey
  148. //1. 根据AttributeType,内部key和配置路径,拿到当前的真实值
  149. strTemp = (string)r_config["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  150. nTemp = (int)r_config["ConfigToolInfo"][nInfoIndex]["PathID"];
  151. GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue);
  152. //2. 赋值
  153. FPDAttr.SetCurrentValue(strValue.c_str());
  154. //AttributeRangeMin
  155. strRangeMin = (string)r_config["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMin"];
  156. //AttributeRangeMax
  157. strRangeMax = (string)r_config["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMax"];
  158. if (strRangeMax != "" && strRangeMin != "") //不需要的配置项为空
  159. {
  160. FPDAttr.SetRange(strRangeMin.c_str(), strRangeMax.c_str());
  161. }
  162. //AttributeList
  163. nTemp = r_config["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListNum"];
  164. if (nTemp > 0) //ListNum不大于0时说明不需要list配置
  165. {
  166. for (int nListIndex = 0; nListIndex < nTemp; nListIndex++)
  167. {
  168. strTemp = (string)r_config["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListInfo"][nListIndex];
  169. sprintf_s(sstream, "%d", nListIndex);
  170. ListTemp.add(sstream, strTemp.c_str());
  171. }
  172. FPDAttr.SetList(ListTemp.encode());
  173. }
  174. AddConfig(FPDAttr);
  175. }
  176. }
  177. catch (ResDataObjectExption& e)
  178. {
  179. Error("Get config error: {$}", e.what());
  180. return "";
  181. }
  182. ResDataObject resAttr, resDescription;
  183. for (auto Item : m_ConfigInfo)
  184. {
  185. resAttr.add(Item.GetKey(), Item.GetCurrentValue());
  186. resDescription.add(Item.GetKey(), Item.GetDescription());
  187. }
  188. ResDataObject resDeviceResource;
  189. resDeviceResource.add(ConfKey::CcosDetectorAttribute, resAttr);
  190. resDeviceResource.add(ConfKey::CcosDetectorDescription, resDescription);
  191. ResDataObject DescriptionTempEx;
  192. DescriptionTempEx.add(ConfKey::CcosDetectorConfig, resDeviceResource);
  193. m_DeviceConfig = DescriptionTempEx;
  194. (*m_pAttribute) = resAttr;
  195. (*m_pDescription) = resDescription;
  196. string res = DescriptionTempEx.encode();
  197. printf("CareRay driver module: get resource over \r\n");
  198. return res;
  199. }
  200. std::string nsFPD::CareRayDriver::DeviceProbe()
  201. {
  202. printf("CareRay driver module: Device Probe \r\n");
  203. ResDataObject r_config, HardwareInfo;
  204. if (r_config.loadFile(m_ConfigFileName.c_str()))
  205. {
  206. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  207. HardwareInfo.add("MinorID", "Device");
  208. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  209. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  210. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  211. }
  212. else
  213. {
  214. HardwareInfo.add("MajorID", "Detector");
  215. HardwareInfo.add("MinorID", "Device");
  216. HardwareInfo.add("VendorID", "CareRay");
  217. HardwareInfo.add("ProductID", "4343W");
  218. HardwareInfo.add("SerialID", "1234");
  219. }
  220. string str = HardwareInfo.encode();
  221. return str;
  222. }
  223. bool nsFPD::CareRayDriver::GetDeviceConfig(std::string& Cfg)
  224. {
  225. Cfg = m_DeviceConfig.encode();
  226. Info("GetDeviceConfig over");
  227. return true;
  228. }
  229. bool nsFPD::CareRayDriver::SetDeviceConfig(std::string Cfg)
  230. {
  231. Info("--Func-- SetDeviceConfig {$}\n", Cfg.c_str());
  232. ResDataObject DeviceConfig;
  233. DeviceConfig.decode(Cfg.c_str());
  234. ResDataObject DescriptionTempEx;
  235. DescriptionTempEx = DeviceConfig["DeviceConfig"];
  236. bool bSaveFile = false; //true:重新保存配置文件
  237. string strAccess = "";
  238. for (int i = 0; i < DescriptionTempEx.size(); i++)
  239. {
  240. ResDataObject temp = DescriptionTempEx[i];
  241. Info("{$}", temp.encode());
  242. for (int j = 0; j < temp.size(); j++)
  243. {
  244. string strKey = temp.GetKey(j);
  245. Info("{$}", strKey.c_str());
  246. try
  247. {
  248. if (m_pAttribute->GetFirstOf(strKey.c_str()) >= 0)
  249. {
  250. strAccess = (string)(*m_pDescription)[strKey.c_str()]["Access"];
  251. if ("RW" == strAccess || "rw" == strAccess)
  252. {
  253. //修改对应配置,在其他单元的配置项要同时调用其修改函数修改真实值
  254. //1. 修改内存中的值,用于给上层发消息
  255. (*m_pAttribute)[strKey.c_str()] = temp[j];
  256. //2. 拿到Innerkey
  257. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  258. Info("ConfigInfo Count: {$}", nConfigInfoCount);
  259. string strTemp = ""; //存储AttributeKey
  260. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  261. {
  262. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  263. if (strTemp == strKey)
  264. {
  265. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  266. break;
  267. }
  268. }
  269. //3. 修改配置文件中的值
  270. if (SetDeviceConfigValue(m_Configurations, strTemp.c_str(), 1, temp[j]))
  271. {
  272. bSaveFile = true;
  273. }
  274. }
  275. else
  276. {
  277. Info("{$} is not a RW configuration item", strKey.c_str());
  278. }
  279. }
  280. }
  281. catch (ResDataObjectExption& e)
  282. {
  283. Error("SetDriverConfig crashed: {$}", e.what());
  284. return false;
  285. }
  286. }
  287. }
  288. if (bSaveFile)
  289. {
  290. //3. 重新保存配置文件
  291. SaveConfigFile(true);
  292. }
  293. return true;
  294. }
  295. bool nsFPD::CareRayDriver::SaveConfigFile(bool bSendNotify)
  296. {
  297. m_ConfigAll["CONFIGURATION"] = m_Configurations;
  298. bool ret = m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
  299. if (ret)
  300. {
  301. Info("SaveConfigFile Success!");
  302. return true;
  303. }
  304. else
  305. {
  306. Error("SaveConfigFile Fail!");
  307. return false;
  308. }
  309. }
  310. bool nsFPD::CareRayDriver::GetDeviceConfigValue(ResDataObject config, const char* pInnerKey,
  311. int nPathID, string& strValue)
  312. {
  313. strValue = "";
  314. string strTemp = pInnerKey;
  315. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  316. {
  317. if (WiredIP == strTemp || WirelessIP == strTemp || LocalIP == strTemp)
  318. {
  319. strValue = (string)config["connections"][pInnerKey];
  320. }
  321. else if (DetectorVender == strTemp || DetectorModel == strTemp ||
  322. DetectorDescription == strTemp || DetectorSerialNumber == strTemp)
  323. {
  324. strValue = (string)config[pInnerKey];
  325. }
  326. else if (SyncType == strTemp || FPDWorkStation == strTemp ||
  327. ImageWidth == strTemp || ImageHeight == strTemp)
  328. {
  329. strValue = (string)config["ModeTable"]["DetectorMode"][pInnerKey];
  330. }
  331. else if (TempMaxLimit == strTemp || ReConnect == strTemp ||
  332. TempUpperLimit == strTemp || TempLowerLimit == strTemp || TempMinLimit == strTemp ||
  333. BatLowerLimit == strTemp || BatMiniLimit == strTemp ||
  334. BatLowerLimitInCali == strTemp || WifiLowerLimit == strTemp ||
  335. WifiMiniLimit == strTemp || HighPowerTimeout == strTemp ||
  336. ShowTemperature == strTemp || ShowWifi == strTemp ||
  337. ShowBattery == strTemp || ShowBluetooth == strTemp ||
  338. FPDExamMode == strTemp || FPDAcqMode == strTemp || FPDModeMatch == strTemp ||
  339. CcosDetectorAttachedFlag == strTemp)
  340. {
  341. strValue = (string)config[pInnerKey];
  342. }
  343. else
  344. {
  345. strValue = "";
  346. Error("Error Configuration item: {$}", pInnerKey);
  347. }
  348. }
  349. return true;
  350. }
  351. bool nsFPD::CareRayDriver::SetDeviceConfigValue(ResDataObject &config, const char* pInnerKey,
  352. int nPathID, const char* szValue)
  353. {
  354. string strTemp = pInnerKey;
  355. Info("Begin to change {$} item value to {$}", pInnerKey, szValue);
  356. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  357. {
  358. if (WiredIP == strTemp || WirelessIP == strTemp || LocalIP == strTemp)
  359. {
  360. config["connections"][pInnerKey] = szValue;
  361. }
  362. else if (DetectorVender == strTemp || DetectorModel == strTemp ||
  363. DetectorDescription == strTemp || DetectorSerialNumber == strTemp)
  364. {
  365. config[pInnerKey] = szValue;
  366. }
  367. else if (SyncType == strTemp || FPDWorkStation == strTemp ||
  368. ImageWidth == strTemp || ImageHeight == strTemp)
  369. {
  370. config["ModeTable"]["DetectorMode"][pInnerKey] = szValue;
  371. }
  372. else if (TempMaxLimit == strTemp || ReConnect == strTemp ||
  373. TempUpperLimit == strTemp || TempLowerLimit == strTemp ||
  374. BatLowerLimit == strTemp || BatMiniLimit == strTemp ||
  375. BatLowerLimitInCali == strTemp || WifiLowerLimit == strTemp ||
  376. WifiMiniLimit == strTemp || HighPowerTimeout == strTemp ||
  377. ShowTemperature == strTemp || ShowWifi == strTemp ||
  378. ShowBattery == strTemp || ShowBluetooth == strTemp ||
  379. FPDExamMode == strTemp || FPDAcqMode == strTemp || FPDModeMatch == strTemp ||
  380. CcosDetectorAttachedFlag == strTemp)
  381. {
  382. config[pInnerKey] = szValue;
  383. }
  384. else
  385. {
  386. Error("Error Configuration item: {$}", pInnerKey);
  387. return false;
  388. }
  389. }
  390. return true;
  391. }
  392. nsFPD::FPDDeviceCareRay::FPDDeviceCareRay(std::shared_ptr<IOEventCenter> center,std::string strConfigPath)
  393. : m_nCalibTotalExposureNum(0),
  394. m_nCalibCurrentCalibrationRound(0),
  395. m_nCalibCurrentExposureIndex(0),
  396. m_nCalibCurrentExposureNum(0)
  397. {
  398. m_bDeviceConnect = false;
  399. m_nFullImageHeight = 0;
  400. m_nFullImageWidth = 0;
  401. m_pFullImgBuffer = nullptr;
  402. m_nImgBits = 0;
  403. m_nAngle = 0;
  404. m_nPixelSpacing = 0;
  405. m_nSensitivity = 0;
  406. m_fDose = 0;
  407. m_eSyncMode = SYNC_SOFTWARE;
  408. m_fFactorEXI2UGY = 0.0f;
  409. m_nFPDExpReadyTime = 1000;
  410. m_strWorkPath = GetProcessDirectory();
  411. m_DetectorCtrlUnit.reset(new OemCtrl(center, this));
  412. m_AcqUnit.reset(new OemAcq(center, this));
  413. m_SyncUnit.reset(new OemSync(center, this));
  414. m_CalibUnit.reset(new OemCalib(center, this));
  415. m_DetectorConfiguration.reset(new DetectorConfiguration(strConfigPath));
  416. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  417. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY));
  418. m_WaitCalibDoseEvt = CreateEvent(NULL, FALSE, FALSE, NULL);
  419. m_bOnlyHaveFpd = false;
  420. EventCenter = center;
  421. m_eAppStatus = APP_STATUS_IDLE;
  422. }
  423. nsFPD::FPDDeviceCareRay::~FPDDeviceCareRay()
  424. {
  425. if (nullptr != m_pFullImgBuffer)
  426. {
  427. delete[]m_pFullImgBuffer;
  428. m_pFullImgBuffer = nullptr;
  429. }
  430. if (m_WaitCalibDoseEvt)
  431. {
  432. CloseHandle(m_WaitCalibDoseEvt);
  433. m_WaitCalibDoseEvt = nullptr;
  434. }
  435. }
  436. std::string nsFPD::FPDDeviceCareRay::GetGUID() const
  437. {
  438. return DetectorUnitType;
  439. }
  440. bool nsFPD::FPDDeviceCareRay::Prepare()
  441. {
  442. printf("CareRay device module: Prepare \r\n");
  443. Info("--Func-- device prepare");
  444. EventCenter->OnMaxBlockSize("DrQue", m_stDeviceConfig.nMaxImageWidth * m_stDeviceConfig.nMaxImageWidth * 2, 3, 1500 * 1500 * 2, 1);
  445. Connect();
  446. return true;
  447. }
  448. bool nsFPD::FPDDeviceCareRay::CreateDevice()
  449. {
  450. Info("CreateDevice start");
  451. if (!LoadConfig())
  452. {
  453. return false;
  454. }
  455. if (nullptr == g_pDetector)
  456. {
  457. g_pDetector = new Detector_CareRayDR();
  458. }
  459. g_pDetector->DriverEntry(this, m_DetectorConfiguration->m_Configurations);
  460. Info("CreateDevice end");
  461. return true;
  462. }
  463. void nsFPD::FPDDeviceCareRay::Register()
  464. {
  465. auto Disp = &Dispatch;
  466. RegisterCtrl(Disp);
  467. RegisterAcq(Disp);
  468. RegisterSync(Disp);
  469. RegisterCalib(Disp);
  470. }
  471. RET_STATUS nsFPD::FPDDeviceCareRay::Connect()
  472. {
  473. printf("--Func-- device Connect \r\n");
  474. Info("--Func-- device Connect");
  475. m_DetectorCtrlUnit->SetAttachStatus(to_string(1)); //没有attach功能,直接上发1,使客户端显示探测器状态
  476. RET_STATUS ret = RET_STATUS::RET_FAILED;
  477. if (g_pDetector->Connect(this, m_strWorkPath.c_str()))
  478. {
  479. ret = RET_STATUS::RET_SUCCEED;
  480. }
  481. return ret;
  482. }
  483. RET_STATUS nsFPD::FPDDeviceCareRay::EnterExam(int nExamMode)
  484. {
  485. Info("--Func-- EnterExam {$}", nExamMode);
  486. switch (nExamMode)
  487. {
  488. case APP_STATUS_WORK_BEGIN:
  489. Info("Enter into Exam Windows");
  490. m_eAppStatus = APP_STATUS_WORK_BEGIN;
  491. break;
  492. case APP_STATUS_WORK_END:
  493. Info("Quit Exam Windows");
  494. m_eAppStatus = APP_STATUS_WORK_END;
  495. break;
  496. case APP_STATUS_DETSHARE_BEGIN:
  497. Info("Enter into Detector Share Windows");
  498. m_eAppStatus = APP_STATUS_DETSHARE_BEGIN;
  499. break;
  500. case APP_STATUS_DETSHAR_END:
  501. Info("Quit Detector Share Windows");
  502. m_eAppStatus = APP_STATUS_DETSHAR_END;
  503. break;
  504. case APP_STATUS_CAL_BEGIN:
  505. Info("Enter into Calibration Windows");
  506. m_eAppStatus = APP_STATUS_CAL_BEGIN;
  507. break;
  508. case APP_STATUS_CAL_END:
  509. Info("Quit Calibration Windows");
  510. m_eAppStatus = APP_STATUS_CAL_END;
  511. break;
  512. case APP_STATUS_WORK_IN_SENSITIVITY:
  513. Info("Enter into sensitivity test interface");
  514. m_eAppStatus = APP_STATUS_WORK_IN_SENSITIVITY;
  515. break;
  516. default:
  517. break;
  518. }
  519. g_pDetector->EnterExamMode(nExamMode);
  520. return RET_STATUS::RET_SUCCEED;
  521. }
  522. RET_STATUS nsFPD::FPDDeviceCareRay::SetAcqMode(string strMode)
  523. {
  524. printf("device module: SetAcqMode(%s) \r\n", strMode);
  525. Info("--Func-- SetAcqMode({$})", strMode);
  526. RET_STATUS ret = RET_STATUS::RET_FAILED;
  527. //如果没连接,不执行
  528. if (!m_bDeviceConnect)
  529. {
  530. Error("Detector not connected, return");
  531. return ret;
  532. }
  533. int tempID;
  534. if (strMode == "DUALENERGY")
  535. {
  536. tempID = 3;
  537. }
  538. try
  539. {
  540. ResDataObject objModeConfig = m_DetectorConfiguration->m_Configurations;
  541. int nModeCount = (int)objModeConfig["ModeTable"].GetKeyCount("DetectorMode");
  542. for (int i = 0; i < nModeCount; i++)
  543. {
  544. int nAppModeID = (int)objModeConfig["ModeTable"][i]["LogicMode"];
  545. if (nAppModeID == tempID)
  546. {
  547. m_nAcqMode = tempID;
  548. m_nFullImageWidth = (int)objModeConfig["ModeTable"][i]["ImageWidth"];
  549. m_nFullImageHeight = (int)objModeConfig["ModeTable"][i]["ImageHeight"];
  550. m_nImgBits = (int)objModeConfig["ModeTable"][i]["PhySizeInfoBit"];
  551. m_nAngle = (int)objModeConfig["ModeTable"][i]["RotateAngle"];
  552. m_nPixelSpacing = (int)objModeConfig["ModeTable"][i]["PixelPitch"];
  553. m_nSensitivity = (int)objModeConfig["ModeTable"][i]["Sensitivity"];
  554. m_eSyncMode = (SYNC_MODE)(int)objModeConfig["ModeTable"][i]["SyncType"];
  555. m_nFPDExpReadyTime = (int)objModeConfig["ModeTable"][i]["XWindow"];
  556. /*string strDose = (string)objModeConfig["ModeTable"][i]["CalibConfig"]["NodeInfo"]["Dose"];
  557. m_fDose = stof(strDose.c_str());*/
  558. if (nullptr != m_pFullImgBuffer)
  559. {
  560. delete[]m_pFullImgBuffer;
  561. m_pFullImgBuffer = nullptr;
  562. }
  563. m_pFullImgBuffer = new WORD[(size_t)m_nFullImageWidth * (size_t)m_nFullImageHeight];
  564. if (m_nAngle == 90 || m_nAngle == 270)
  565. {
  566. m_AcqUnit->SetFulImageInfo(m_nFullImageWidth, m_nFullImageHeight, m_nImgBits, false);
  567. }
  568. else
  569. {
  570. m_AcqUnit->SetFulImageInfo(m_nFullImageHeight, m_nFullImageWidth, m_nImgBits, false);
  571. }
  572. m_AcqUnit->SetPrevImageInfo(false, 0, 0, false);
  573. if (g_pDetector->SetAcqMode(tempID))
  574. {
  575. ret = RET_STATUS::RET_SUCCEED;
  576. }
  577. break;
  578. }
  579. }
  580. }
  581. catch (ResDataObjectExption& e)
  582. {
  583. Error("Read configuration failed, Error code: {$}", e.what());
  584. }
  585. return ret;
  586. }
  587. bool nsFPD::FPDDeviceCareRay::GetOnlyHaveFpd()
  588. {
  589. return m_bOnlyHaveFpd;
  590. }
  591. int nsFPD::FPDDeviceCareRay::GetGainExposureNum()
  592. {
  593. return m_nCalibTotalExposureNum;
  594. }
  595. RET_STATUS nsFPD::FPDDeviceCareRay::GetSyncMode(SYNC_MODE& eSyncMode)
  596. {
  597. eSyncMode = m_eSyncMode;
  598. return RET_STATUS::RET_SUCCEED;
  599. }
  600. RET_STATUS nsFPD::FPDDeviceCareRay::PrepareAcquisition()
  601. {
  602. printf("--Func-- PrepareAcquisition \r\n");
  603. Info("--Func-- PrepareAcquisition");
  604. RET_STATUS ret = RET_STATUS::RET_FAILED;
  605. if (!m_bDeviceConnect)
  606. {
  607. Error("Detector not connected, return");
  608. return ret;
  609. }
  610. if (DETECTOR_STATUS_STANDBY != m_DetectorCtrlUnit->GetDetectorStatus())
  611. {
  612. if ((m_CalibUnit->GetCalibrationStatus() == CCOS_CALIBRATION_STATUS_RUNNING) ||
  613. (m_CalibUnit->GetCalibrationStatus() == CCOS_CALIBRATION_STATUS_ACTIVE))
  614. {
  615. printf("PrepareAcquisition failed. Detector at Calibration status.\n");
  616. Error("PrepareAcquisition failed. Detector at Calibration status");
  617. }
  618. if (DETECTOR_STATUS_ACQ == m_DetectorCtrlUnit->GetDetectorStatus())
  619. {
  620. printf("Detector already at Acq status.\n");
  621. Error("Detector already at Acq status");
  622. ret = RET_STATUS::RET_SUCCEED;
  623. }
  624. }
  625. else
  626. {
  627. m_SyncUnit->FPDReadyNotify(false); //prepare前置为初值
  628. if (g_pDetector->PrepareAcquisition(this))
  629. {
  630. ret = RET_STATUS::RET_SUCCEED;
  631. //m_SyncUnit->FPDReadyNotify(true); //prepare succeed
  632. }
  633. }
  634. Info("PrepareAcquisition over");
  635. return ret;
  636. }
  637. RET_STATUS nsFPD::FPDDeviceCareRay::StartAcquisition(string in)
  638. {
  639. printf("--Func-- StartAcquisition \r\n");
  640. Info("--Func-- StartAcquisition");
  641. RET_STATUS ret = RET_STATUS::RET_FAILED;
  642. if (!m_bDeviceConnect)
  643. {
  644. Error("Detector not connected, return");
  645. return ret;
  646. }
  647. if (m_nAcqMode != AcqMode::DUAL_ENERGY)
  648. {
  649. if (DETECTOR_STATUS_STANDBY != m_DetectorCtrlUnit->GetDetectorStatus())
  650. {
  651. if ((m_CalibUnit->GetCalibrationStatus() == CCOS_CALIBRATION_STATUS_RUNNING) ||
  652. (m_CalibUnit->GetCalibrationStatus() == CCOS_CALIBRATION_STATUS_ACTIVE))
  653. {
  654. printf("PrepareAcquisition failed. Detector at Calibration status.\n");
  655. Error("PrepareAcquisition failed. Detector at Calibration status.");
  656. }
  657. if (DETECTOR_STATUS_ACQ == m_DetectorCtrlUnit->GetDetectorStatus())
  658. {
  659. printf("Detector already at Acq status.\n");
  660. Error("Detector already at Acq status.");
  661. }
  662. }
  663. else
  664. {
  665. if (g_pDetector->StartAcquisition(this))
  666. {
  667. ret = RET_STATUS::RET_SUCCEED;
  668. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_ACQ));
  669. }
  670. else
  671. {
  672. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  673. }
  674. }
  675. }
  676. else
  677. {
  678. if (g_pDetector->StartAcquisition(this))
  679. {
  680. ret = RET_STATUS::RET_SUCCEED;
  681. }
  682. else
  683. {
  684. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  685. }
  686. }
  687. Info("StartAcquisition over");
  688. return ret;
  689. }
  690. RET_STATUS CCOS::Dev::Detail::Detector::FPDDeviceCareRay::ToFrameAcq(string in)
  691. {
  692. //m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_ACQ));
  693. return RET_STATUS::RET_SUCCEED;
  694. }
  695. RET_STATUS CCOS::Dev::Detail::Detector::FPDDeviceCareRay::RequestXray(string in)
  696. {
  697. RET_STATUS ret = RET_STATUS::RET_FAILED;
  698. if (g_pDetector->RequestXray(this))
  699. {
  700. ret = RET_STATUS::RET_SUCCEED;
  701. }
  702. return ret;
  703. }
  704. RET_STATUS nsFPD::FPDDeviceCareRay::StopAcquisition()
  705. {
  706. printf("--Func-- StopAcquisition \r\n");
  707. Info("--Func-- StopAcquisition");
  708. RET_STATUS ret = RET_STATUS::RET_FAILED;
  709. if (!m_bDeviceConnect)
  710. {
  711. Error("Detector not connected, return");
  712. return ret;
  713. }
  714. if (DETECTOR_STATUS_STANDBY == m_DetectorCtrlUnit->GetDetectorStatus())
  715. {
  716. printf("Detector already at Acq status.\n");
  717. Info("Detector already at Acq status.");
  718. ret = RET_STATUS::RET_SUCCEED;
  719. }
  720. else
  721. {
  722. if (g_pDetector->StopAcquisition(this))
  723. {
  724. ret = RET_STATUS::RET_SUCCEED;
  725. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  726. }
  727. }
  728. Info("StopAcquisition over");
  729. return ret;
  730. }
  731. RET_STATUS nsFPD::FPDDeviceCareRay::ActiveCalibration(CCOS_CALIBRATION_TYPE eType)
  732. {
  733. printf("--Func-- ActiveCalibration %d \r\n", eType);
  734. Info("--Func-- ActiveCalibration {$}", (int)eType);
  735. RET_STATUS ret = RET_STATUS::RET_FAILED;
  736. if (!m_bDeviceConnect)
  737. {
  738. Error("Detector not connected, return");
  739. return ret;
  740. }
  741. if (eType == CCOS_CALIBRATION_TYPE_NONE || eType == CCOS_CALIBRATION_TYPE_MAX)
  742. {
  743. Error("calibration type is invalid!");
  744. return RET_STATUS::RET_INVALID;
  745. }
  746. if (DETECTOR_STATUS_STANDBY != m_DetectorCtrlUnit->GetDetectorStatus())
  747. {
  748. if (DETECTOR_STATUS_ACQ == m_DetectorCtrlUnit->GetDetectorStatus())
  749. {
  750. printf("ActiveCalibration failed. Detector at Acq status\r\n");
  751. Error("ActiveCalibration failed. Detector at Acq status");
  752. ret = StopAcquisition();
  753. if (ret != RET_STATUS::RET_SUCCEED)
  754. {
  755. printf("stop acquisition error\n");
  756. Error("stop acquisition error");
  757. return ret;
  758. }
  759. }
  760. return RET_STATUS::RET_FAILED;
  761. }
  762. m_eAppStatus = APP_STATUS_CAL_BEGIN;
  763. if (eType == CCOS_CALIBRATION_TYPE_XRAY)
  764. {
  765. printf("calibration type: CCOS_CALIBRATION_TYPE_XRAY\n");
  766. Info("calibration type: CCOS_CALIBRATION_TYPE_XRAY");
  767. int nCalibrationRounds = (int)m_CalibDoseList.size();
  768. g_pDetector->SetCalibRounds(nCalibrationRounds);
  769. }
  770. if (g_pDetector->ActiveCalibration(this, eType))
  771. {
  772. ret = RET_STATUS::RET_SUCCEED;
  773. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_ACTIVE));
  774. m_CalibUnit->SetCalibrationProgress(0);
  775. if (eType == CCOS_CALIBRATION_TYPE_XRAY)
  776. {
  777. Info("start to waitting CalibDoseEvt");
  778. printf("start to waitting CalibDoseEvt\n");
  779. DWORD nRet = WaitForSingleObject(m_WaitCalibDoseEvt, INFINITE);
  780. }
  781. }
  782. else
  783. {
  784. Error("Active calibration failed");
  785. ret = RET_STATUS::RET_FAILED;
  786. }
  787. //重置校正流程参数
  788. m_nCalibCurrentCalibrationRound = 1;
  789. m_nCalibCurrentExposureIndex = 1;
  790. m_nCalibCurrentExposureNum = 0;
  791. Info("ActiveCalibration over");
  792. return ret;
  793. }
  794. RET_STATUS nsFPD::FPDDeviceCareRay::PrepareCalibration()
  795. {
  796. printf("--Func-- PrepareCalibration------ \n");
  797. Info("==============================PrepareCalibration");
  798. RET_STATUS ret = RET_STATUS::RET_FAILED;
  799. if (!m_bDeviceConnect)
  800. {
  801. printf("Detector not connected, return\n");
  802. Error("Detector not connected, return");
  803. return ret;
  804. }
  805. m_SyncUnit->FPDReadyNotify(false); //prepare前置为初值
  806. if (g_pDetector->PrepareCalibration(this))
  807. {
  808. printf("FPD ready notify------------\n");
  809. ret = RET_STATUS::RET_SUCCEED;
  810. m_SyncUnit->FPDReadyNotify(true); //prepare succeed
  811. }
  812. else
  813. {
  814. printf("Prepare calibration failed\n");
  815. Error("Prepare calibration failed");
  816. }
  817. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  818. printf("PrepareCalibration over\n");
  819. Info("==============================PrepareCalibration over");
  820. return ret;
  821. }
  822. RET_STATUS nsFPD::FPDDeviceCareRay::GetRequestedDose(std::string& strDose)
  823. {
  824. Info("==============================GetRequestedDose");
  825. printf("--Func-- GetRequestedDose------ \n");
  826. RET_STATUS ret = RET_STATUS::RET_FAILED;
  827. bool bGetDoseInfo = false;
  828. ResDataObject out;
  829. if (!m_bDeviceConnect)
  830. {
  831. Error("Detector not connected, return");
  832. return ret;
  833. }
  834. CCOS_CALIBRATION_TYPE nCalibrationType = m_CalibUnit->GetCalibrationType();
  835. Info("GetRequestedDose calib type is {$}", (int)nCalibrationType);
  836. printf("GetRequestedDose calib type is %d\n", nCalibrationType);
  837. if (CCOS_CALIBRATION_TYPE_DARK == nCalibrationType)
  838. {
  839. out.add("Dose", 0.0f);
  840. out.add("kV", 0.0f);
  841. out.add("mA", 0.0f);
  842. out.add("ms", 0.0f);
  843. out.add("mAs", 0.0f);
  844. bGetDoseInfo = true;
  845. }
  846. else if (CCOS_CALIBRATION_TYPE_XRAY == nCalibrationType)
  847. {
  848. Info("calib dose list size is {$}", m_CalibDoseList.size());
  849. printf("calib dose list size is %d\n", (int)m_CalibDoseList.size());
  850. for (int i = 0; i < m_CalibDoseList.size(); i++)
  851. {
  852. ResDataObject temp = m_CalibDoseList[i];
  853. int nDose = temp["Dose"];
  854. int nDoseParem = (int)(m_fDoseParam * 1000);
  855. if (nDoseParem == nDose)
  856. {
  857. out.add("Dose", nDoseParem);
  858. out.add("kV", temp["kV"]);
  859. out.add("mA", temp["mA"]);
  860. out.add("ms", temp["ms"]);
  861. out.add("mAs", temp["mAs"]);
  862. bGetDoseInfo = true;
  863. Info("Find target dose parameter");
  864. break;
  865. }
  866. }
  867. }
  868. else
  869. {
  870. Warn("Can not support CalibrationType($)", (int)nCalibrationType);
  871. ret = RET_STATUS::RET_FAILED;
  872. }
  873. if (bGetDoseInfo)
  874. {
  875. strDose = out.encode();
  876. Info("GetRequestedDose:{$}", strDose.c_str());
  877. ret = RET_STATUS::RET_SUCCEED;
  878. }
  879. else
  880. {
  881. Error("GetRequestedDose failed");
  882. }
  883. Info("==============================GetRequestedDose over");
  884. return ret;
  885. }
  886. RET_STATUS nsFPD::FPDDeviceCareRay::GetCalibrationStep(int nDetectorID, string& strCalibrationStepInfo)
  887. {
  888. Info("==============================GetCalibrationStep");
  889. printf("--func-- GetCalibrationStep\n");
  890. Info("Calibration DetectorID: {$}", nDetectorID);
  891. RET_STATUS ret = RET_STATUS::RET_SUCCEED;
  892. ResDataObject out;
  893. int nCalibrationRounds = (int)m_CalibDoseList.size();
  894. int nExposureNumCurrentRound = (int)m_CalibDoseList[m_nCalibCurrentCalibrationRound - 1]["ExpNum"];
  895. if (g_pDetector->GetCalibrationStep(m_nCalibCurrentCalibrationRound, nCalibrationRounds, m_nCalibCurrentExposureIndex, nExposureNumCurrentRound))
  896. {
  897. Info("GetCalibrationStep success");
  898. }
  899. else
  900. {
  901. Error("GetCalibrationStep error");
  902. ret = RET_STATUS::RET_FAILED;
  903. return ret;
  904. }
  905. out.add("CalibrationRounds", (int)m_CalibDoseList.size());
  906. out.add("TotalExposureNum", m_nCalibTotalExposureNum);
  907. out.add("CurrentCalibrationRound", m_nCalibCurrentCalibrationRound);
  908. out.add("ExposureNumCurrentRound", (int)m_CalibDoseList[m_nCalibCurrentCalibrationRound - 1]["ExpNum"]);
  909. out.add("CurrentExposureIndex", m_nCalibCurrentExposureIndex);
  910. out.add("CurrentExposureNum", m_nCalibCurrentExposureNum);
  911. strCalibrationStepInfo = out.encode();
  912. Info("GetCalibrationStep over,strCalibrationStepInfo: {$}", strCalibrationStepInfo.c_str());
  913. return ret;
  914. }
  915. RET_STATUS nsFPD::FPDDeviceCareRay::StartCalibration()
  916. {
  917. printf("--Func-- StartCalibration \r\n");
  918. Info("--Func-- StartCalibration");
  919. RET_STATUS ret = RET_STATUS::RET_FAILED;
  920. if (!m_bDeviceConnect)
  921. {
  922. Error("Detector not connected, return");
  923. return ret;
  924. }
  925. if ((m_CalibUnit->GetCalibrationStatus() != CCOS_CALIBRATION_STATUS_PAUSE) &&
  926. (m_CalibUnit->GetCalibrationStatus() != CCOS_CALIBRATION_STATUS_ACTIVE))
  927. {
  928. printf("CCOS_CALIBRATION_STATUS = %d\r\n", (int)m_CalibUnit->GetCalibrationStatus());
  929. Error("Start calibration failed, in {$} status", (int)m_CalibUnit->GetCalibrationStatus());
  930. return ret;
  931. }
  932. if (DETECTOR_STATUS_STANDBY != m_DetectorCtrlUnit->GetDetectorStatus())
  933. {
  934. if (DETECTOR_STATUS_ACQ == m_DetectorCtrlUnit->GetDetectorStatus())
  935. {
  936. printf("Start calibration failed. Detector at Acq status.\r\n");
  937. Error("Start calibration failed. Detector at Acq status");
  938. }
  939. return ret;
  940. }
  941. if (m_CalibUnit->GetCalibrationStatus() == CCOS_CALIBRATION_STATUS_RUNNING)
  942. {
  943. printf("Detector already at calib status.\n");
  944. Error("Detector already at calib status");
  945. return ret;
  946. }
  947. if (g_pDetector->StartCalibration(this))
  948. {
  949. printf("start calibration success set detector status\n");
  950. Info("start calibration success set detector status");
  951. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_ACQ));
  952. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_RUNNING));
  953. ret = RET_STATUS::RET_SUCCEED;
  954. }
  955. else
  956. {
  957. Error("Start calibration failed");
  958. ret = RET_STATUS::RET_FAILED;
  959. }
  960. Info("StartCalibration over");
  961. return ret;
  962. }
  963. RET_STATUS nsFPD::FPDDeviceCareRay::StopCalibration()
  964. {
  965. printf("--Func-- StopCalibration \r\n");
  966. Info("--Func-- StopCalibration");
  967. RET_STATUS ret = RET_STATUS::RET_FAILED;
  968. if (!m_bDeviceConnect)
  969. {
  970. Error("Detector not connected, return");
  971. return ret;
  972. }
  973. m_eAppStatus = APP_STATUS_CAL_END;
  974. if (g_pDetector->StopCalibration(this))
  975. {
  976. ret = RET_STATUS::RET_SUCCEED;
  977. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY));
  978. m_CalibUnit->SetCalibrationProgress(to_string(100));
  979. }
  980. else
  981. {
  982. Error("Start calibration failed");
  983. }
  984. Info("StopCalibration over");
  985. return ret;
  986. }
  987. void nsFPD::FPDDeviceCareRay::ConfirmCalExposure()
  988. {
  989. printf("--Func-- ConfirmCalExposure \r\n");
  990. Info("--Func-- ConfirmCalExposure");
  991. g_pDetector->ConfirmCalExposure();
  992. }
  993. void nsFPD::FPDDeviceCareRay::AbortCalibration()
  994. {
  995. Info("==============================AbortCalibration");
  996. printf("--func-- AbortCalibration\n");
  997. CCOS_CALIBRATION_TYPE nCalibrationType = m_CalibUnit->GetCalibrationType();
  998. if (CCOS_CALIBRATION_TYPE_DARK == nCalibrationType)
  999. {
  1000. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1001. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_ERROR));
  1002. m_CalibUnit->SetCalibrationProgress(to_string(100));
  1003. Info("==============================AbortCalibration over");
  1004. return;
  1005. }
  1006. m_eAppStatus = APP_STATUS_CAL_END;
  1007. g_pDetector->AbortCalibration(this);
  1008. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1009. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_ERROR));
  1010. m_CalibUnit->SetCalibrationProgress(to_string(100));
  1011. m_AcqUnit->SendNoNeedWaitImage(true);
  1012. Info("==============================AbortCalibration over");
  1013. }
  1014. RET_STATUS nsFPD::FPDDeviceCareRay::AcceptCalibration()
  1015. {
  1016. Info("==============================AcceptCalibration");
  1017. printf("--func-- AcceptCalibration\n");
  1018. RET_STATUS Ret = RET_STATUS::RET_SUCCEED;
  1019. if (g_pDetector->AcceptCalibration())
  1020. {
  1021. Info("AcceptCalibration over");
  1022. Ret = RET_STATUS::RET_SUCCEED;
  1023. }
  1024. else
  1025. {
  1026. Error("AcceptCalibration error");
  1027. Ret = RET_STATUS::RET_FAILED;
  1028. }
  1029. int nExposureNumCurrentRound = (int)m_CalibDoseList[m_nCalibCurrentCalibrationRound - 1]["ExpNum"];
  1030. //完成校正条件:轮数够了,曝光次数够了
  1031. if ((m_nCalibCurrentCalibrationRound == (int)m_CalibDoseList.size()) && (m_nCalibCurrentExposureIndex == nExposureNumCurrentRound))
  1032. {
  1033. Info("Calibration Round: {$}, Exposure Index: {$}, Finished", m_nCalibCurrentCalibrationRound, m_nCalibCurrentExposureIndex);
  1034. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1035. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY));
  1036. m_CalibUnit->SetCalibrationProgress(to_string(100));
  1037. return Ret;
  1038. }
  1039. if (m_nCalibCurrentExposureIndex >= nExposureNumCurrentRound) //跳到下一轮校正参数
  1040. {
  1041. m_nCalibCurrentCalibrationRound++;
  1042. m_nCalibCurrentExposureIndex = 1;
  1043. ResDataObject temp = m_CalibDoseList[m_nCalibCurrentCalibrationRound - 1];
  1044. int nDose = temp["Dose"];
  1045. m_fDoseParam = nDose / 1000.0f;
  1046. }
  1047. else
  1048. {
  1049. m_nCalibCurrentExposureIndex++;
  1050. }
  1051. m_nCalibCurrentExposureNum++;
  1052. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1053. Info("==============================AcceptCalibration over");
  1054. return Ret;
  1055. }
  1056. void nsFPD::FPDDeviceCareRay::RejectCalExposure()
  1057. {
  1058. printf("--Func-- RejectCalExposure \r\n");
  1059. Info("--Func-- RejectCalExposure");
  1060. g_pDetector->RejectCalExposure();
  1061. }
  1062. RET_STATUS nsFPD::FPDDeviceCareRay::RejectCalibration()
  1063. {
  1064. printf("--Func-- RejectCalibration \n");
  1065. Info("==============================RejectCalibration");
  1066. RET_STATUS Ret = RET_STATUS::RET_SUCCEED;
  1067. if (g_pDetector->RejectCalibration())
  1068. {
  1069. Ret = RET_STATUS::RET_SUCCEED;
  1070. }
  1071. else
  1072. {
  1073. Error("RejectCalibration error");
  1074. Ret = RET_STATUS::RET_FAILED;
  1075. }
  1076. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1077. Info("==============================RejectCalibration over");
  1078. return Ret;
  1079. }
  1080. bool nsFPD::FPDDeviceCareRay::CompleteCalibration()
  1081. {
  1082. printf("--func-- CompleteCalibration \n");
  1083. Info("==============================CompleteCalibration");
  1084. if (!g_pDetector->CompleteCalibration(this))
  1085. {
  1086. Error("CompleteCalibration fail!");
  1087. return false;
  1088. }
  1089. if (g_pDetector->GetCalibType() == CCOS_CALIBRATION_TYPE_DARK)
  1090. {
  1091. printf("CompleteCalibration Calibration Type DARK\n");
  1092. Info("CompleteCalibration Calibration Type DARK");
  1093. }
  1094. else if (g_pDetector->GetCalibType() == CCOS_CALIBRATION_TYPE_XRAY)
  1095. {
  1096. printf("CompleteCalibration Calibration Type XRAY\n");
  1097. Info("CompleteCalibration Calibration Type XRAY");
  1098. m_eAppStatus = APP_STATUS_CAL_END;
  1099. }
  1100. Info("CompleteCalibration set detector status standby");
  1101. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1102. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY));
  1103. if (m_bOnlyHaveFpd)
  1104. {
  1105. //通知子系统结束暗场校正太快了,导致后边的服务通知app的消息混乱了(不是一个进程的原因)acqservice,故此处延时1s
  1106. printf("Sleep 1s,then send progress 100\n");
  1107. Info("Sleep 1s,then send progress 100");
  1108. Sleep(1000);
  1109. }
  1110. m_CalibUnit->SetCalibrationProgress(to_string(100));
  1111. Info("==============================CompleteCalibration over");
  1112. return true;
  1113. }
  1114. RET_STATUS nsFPD::FPDDeviceCareRay::SaveCalibrationFile(bool bSaveFlag)
  1115. {
  1116. printf("--Func-- SaveCalibrationFile \n");
  1117. Info("==============================SaveCalibrationFile");
  1118. RET_STATUS Ret = RET_STATUS::RET_SUCCEED;
  1119. Info("SaveCalibrationFile bSaveFlag: {$}", bSaveFlag);
  1120. if (!bSaveFlag)
  1121. {
  1122. Warn("Not save calibration file");
  1123. return Ret;
  1124. }
  1125. if (g_pDetector->SaveCalibrationFile())
  1126. {
  1127. Info("SaveCalibrationFile over");
  1128. m_CalibUnit->SetSaveCalibrationFileFinish(true);
  1129. Ret = RET_STATUS::RET_SUCCEED;
  1130. }
  1131. else
  1132. {
  1133. Error("SaveCalibrationFile error");
  1134. m_CalibUnit->SetSaveCalibrationFileFinish(false);
  1135. Ret = RET_STATUS::RET_FAILED;
  1136. }
  1137. Info("==============================SaveCalibrationFile over");
  1138. return Ret;
  1139. }
  1140. bool nsFPD::FPDDeviceCareRay::Support_DarkCalib()
  1141. {
  1142. return true;
  1143. }
  1144. bool nsFPD::FPDDeviceCareRay::Support_XrayCalib()
  1145. {
  1146. return true;
  1147. }
  1148. void nsFPD::FPDDeviceCareRay::SendTemperatureValue(float fValue)
  1149. {
  1150. int nStatus = 0;
  1151. m_Temperature->SetTemperature(fValue, nStatus);
  1152. Info("SendTemperatureValue: {$}, status {$}", fValue, nStatus);
  1153. return;
  1154. }
  1155. void nsFPD::FPDDeviceCareRay::SendWifiValue(int nValue)
  1156. {
  1157. int nStatus = 0;
  1158. m_Wifi->SetSignalValue(nValue, nStatus);
  1159. Info("SendWifiValue: {$}, status {$}", nValue, nStatus);
  1160. return;
  1161. }
  1162. void nsFPD::FPDDeviceCareRay::SendBatteryValue(int nValue)
  1163. {
  1164. int nStatus = 0;
  1165. m_Battery->SetRemainPowerValue(nValue, nStatus);
  1166. Info("SendBatteryValue: {$}, status {$}", nValue, nStatus);
  1167. return;
  1168. }
  1169. bool nsFPD::FPDDeviceCareRay::LoadConfig()
  1170. {
  1171. Info("LoadConfig start");
  1172. if (!m_DetectorConfiguration->LoadConfigurations(m_stDeviceConfig, m_ACQMODElist))
  1173. {
  1174. Error("Load configuration file failed!!!");
  1175. return false;
  1176. }
  1177. string strDoseOfExi = std::to_string(m_stDeviceConfig.nDoseOfEXI);
  1178. m_fFactorEXI2UGY = 100.0f / stof(strDoseOfExi) * 1.0f;//统一使用IEC标准 呈现四角信息,无单位 ugy * 100 -ugy。所有Zskk探测器的FactorEXI2UGY均需*100
  1179. Info("m_fFactorEXI2UGY = {$} ", m_fFactorEXI2UGY);
  1180. string strFPDcoef = std::to_string(m_fFactorEXI2UGY);
  1181. m_DetectorCtrlUnit->SetFPDSensitivity(strFPDcoef);//image process 重算ROIl的EXI需要此值
  1182. //string strFPDinfo = std::to_string(m_nSensitivity);
  1183. //m_DetectorCtrlUnit->SetFPDSensitivity(strFPDinfo);
  1184. m_DetectorCtrlUnit->SetPixelData("");
  1185. m_DetectorCtrlUnit->SetTargetEXI("5000");
  1186. //新增一个配置项代表当前系统中是否只有一个真是的平板探测器,其他设备没有或者是demo的
  1187. size_t keyCount = m_DetectorConfiguration->m_Configurations.GetKeyCount(OnlyHaveFpd);
  1188. Info("LoadConfig OnlyHaveFpd keyCount:{$}", keyCount);
  1189. if (keyCount)
  1190. {
  1191. m_bOnlyHaveFpd = (bool)m_DetectorConfiguration->m_Configurations[OnlyHaveFpd];
  1192. if (m_bOnlyHaveFpd)
  1193. Info("current system only have FPD!");
  1194. }
  1195. m_Battery.reset(new DeviceBatteryMould("DetectorBattery", 0,
  1196. m_stDeviceConfig.nBatteryLimit,
  1197. m_stDeviceConfig.nBatteryWarning,
  1198. 100, 100, 0,0,0, EventCenter));
  1199. m_Temperature.reset(new DeviceTemperatureMould("DetectorTemperature", 0.0f,
  1200. m_stDeviceConfig.fTemperatureMin,
  1201. m_stDeviceConfig.fTemperLowLimit,
  1202. m_stDeviceConfig.fTemperatureMax,
  1203. m_stDeviceConfig.fTemperMaxLimit,
  1204. 0.0f,0,0, EventCenter));
  1205. m_Wifi.reset(new DeviceWifiMould("DetectorWifi", 0,
  1206. m_stDeviceConfig.nWifiLimit,
  1207. m_stDeviceConfig.nWifiWarning,
  1208. 100, 100, 0,0,0, EventCenter));
  1209. if (!m_DetectorConfiguration->LoadCalibrationDose(m_strWorkPath, m_CalibDoseList, m_nCalibTotalExposureNum))
  1210. {
  1211. Error("Load Calibration Dose failed!!!");
  1212. return false;
  1213. }
  1214. Info("m_nCalibTotalExposureNum:{$}", m_nCalibTotalExposureNum);
  1215. Info("LoadConfig end");
  1216. return true;
  1217. }
  1218. void nsFPD::FPDDeviceCareRay::RegisterCtrl(nsDetail::Dispatch* Dispatch)
  1219. {
  1220. Dispatch->Action.Push(ActionKey::EnterExam, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSEnterExam);
  1221. Dispatch->Action.Push(ActionKey::ExitExam, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSExitExam);
  1222. Dispatch->Action.Push(ActionKey::SetExposureTimes, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSSetExposureTimes);
  1223. Dispatch->Action.Push(ActionKey::SetXrayOnNum, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSSetXrayOnNum);
  1224. Dispatch->Action.Push(ActionKey::CcosActiveDetector, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSActiveDetector);
  1225. Dispatch->Get.Push(AttrKey::DetectorStatus, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetFPDStatus);
  1226. Dispatch->Get.Push(AttrKey::DetectorType, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDetectorType);
  1227. Dispatch->Get.Push(AttrKey::Description, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDescription);
  1228. Dispatch->Get.Push(AttrKey::DetectorID, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDetectorID);
  1229. Dispatch->Get.Push(AttrKey::FPDSensitivity, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetFPDSensitivity);
  1230. Dispatch->Get.Push(AttrKey::PixelData, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetPixelData);
  1231. Dispatch->Get.Push(AttrKey::TargetEXI, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetTargetEXI);
  1232. Dispatch->Get.Push(CcosDetectorAttachedFlag, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetAttachStatus);//CcosDetectorAttachedFlag
  1233. Dispatch->Get.Push(SupportDDR, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetSupportDDR);
  1234. }
  1235. void nsFPD::FPDDeviceCareRay::RegisterAcq(nsDetail::Dispatch* Dispatch)
  1236. {
  1237. Dispatch->Action.Push(ActionKey::SetAcqMode, m_AcqUnit.get(), &AcqUnit::JSSetAcqMode);
  1238. Dispatch->Get.Push(AttrKey::AcqMode, m_AcqUnit.get(), &AcqUnit::JSGetAcqMode);
  1239. Dispatch->Get.Push(AttrKey::ZskkFPDState, m_AcqUnit.get(), &AcqUnit::JSGetZskkFPDState);
  1240. Dispatch->Get.Push(AttrKey::NoNeedWaitImage, m_AcqUnit.get(), &AcqUnit::JSGetNoNeedWaitImage);
  1241. Dispatch->Get.Push(AttrKey::ImgDataInfo, m_AcqUnit.get(), &AcqUnit::JSGetLastImage);
  1242. }
  1243. void nsFPD::FPDDeviceCareRay::RegisterSync(nsDetail::Dispatch* Dispatch)
  1244. {
  1245. Dispatch->Action.Push(ActionKey::SetSyncMode, m_SyncUnit.get(), &SyncUnit::JSSetSyncMode);
  1246. Dispatch->Action.Push(ActionKey::SetXwindowSize, m_SyncUnit.get(), &SyncUnit::JSSetXwindowSize);
  1247. Dispatch->Action.Push(ActionKey::PrepareAcquisition, m_SyncUnit.get(), &SyncUnit::JSPrepareAcquisition);
  1248. Dispatch->Action.Push(ActionKey::StartAcquisition, m_SyncUnit.get(), &SyncUnit::JSStartAcquisition);
  1249. Dispatch->Action.Push(ActionKey::ToFrameAcq, m_SyncUnit.get(), &SyncUnit::JSToFrameAcq);
  1250. Dispatch->Action.Push(ActionKey::RequestXray, m_SyncUnit.get(), &SyncUnit::JSRequestXray);
  1251. Dispatch->Action.Push(ActionKey::StopAcquisition, m_SyncUnit.get(), &SyncUnit::JSStopAcquisition);
  1252. Dispatch->Get.Push(AttrKey::FPDReadyStatus, m_SyncUnit.get(), &SyncUnit::JSGetFPDReady);
  1253. Dispatch->Get.Push(AttrKey::XwindowStatus, m_SyncUnit.get(), &SyncUnit::JSGetXWindowStatus);
  1254. Dispatch->Get.Push(AttrKey::ImageReadingStatus, m_SyncUnit.get(), &SyncUnit::JSGetImageReadingStatus);
  1255. Dispatch->Get.Push(AttrKey::FPDExpReady, m_SyncUnit.get(), &SyncUnit::JSGetExpReadyStatus);
  1256. Dispatch->Get.Push(AttrKey::SyncMode, m_SyncUnit.get(), &SyncUnit::JSGetSyncMode);
  1257. }
  1258. void nsFPD::FPDDeviceCareRay::RegisterCalib(nsDetail::Dispatch* Dispatch)
  1259. {
  1260. Dispatch->Action.Push(ActionKey::ActiveCalibration, m_CalibUnit.get(), &CalibUnit::JSActiveCalibration);
  1261. Dispatch->Action.Push(ActionKey::GetRequestedDose, m_CalibUnit.get(), &CalibUnit::JSGetRequestedDose);
  1262. Dispatch->Action.Push(ActionKey::SetRequestedDose, m_CalibUnit.get(), &CalibUnit::JSSetRequestedDose);
  1263. Dispatch->Action.Push(ActionKey::PrepareCalibration, m_CalibUnit.get(), &CalibUnit::JSPrepareCalibration);
  1264. Dispatch->Action.Push(ActionKey::StartCalibration, m_CalibUnit.get(), &CalibUnit::JSStartCalibration);
  1265. Dispatch->Action.Push(ActionKey::StopCalibration, m_CalibUnit.get(), &CalibUnit::JSStopCalibration);
  1266. Dispatch->Action.Push(ActionKey::SetCorrectionType, m_CalibUnit.get(), &CalibUnit::JSSetCorrectionType);
  1267. Dispatch->Action.Push(ActionKey::AcceptCalibration, m_CalibUnit.get(), &CalibUnit::JSAcceptCalibration);
  1268. Dispatch->Action.Push(ActionKey::RejectCalibration, m_CalibUnit.get(), &CalibUnit::JSRejectCalibration);
  1269. Dispatch->Action.Push(ActionKey::SaveCalibrationFile, m_CalibUnit.get(), &CalibUnit::JSSaveCalibrationFile);
  1270. Dispatch->Action.Push(ActionKey::GetCalibrationStep, m_CalibUnit.get(), &CalibUnit::JSGetCalibrationStep);
  1271. Dispatch->Get.Push(AttrKey::CalibrationStatus, m_CalibUnit.get(), &CalibUnit::JSGetCalibStatus);
  1272. Dispatch->Get.Push(AttrKey::CalibrationProgress, m_CalibUnit.get(), &CalibUnit::JSGetCalibProgress);
  1273. Dispatch->Get.Push(AttrKey::UploadCalibrationFilesResult, m_CalibUnit.get(), &CalibUnit::JSGetUploadCalibrationFilesResult);
  1274. Dispatch->Get.Push(AttrKey::SupportCalibrationType, m_CalibUnit.get(), &CalibUnit::JSGetSupportCalibrationType);
  1275. Dispatch->Get.Push(AttrKey::HaveImgCalibration, m_CalibUnit.get(), &CalibUnit::JSGetHaveImgCalibration);
  1276. Dispatch->Get.Push(AttrKey::SaveCalibrationFileFinish, m_CalibUnit.get(), &CalibUnit::JSGetSaveCalibrationFileFinish);
  1277. }
  1278. void nsFPD::FPDDeviceCareRay::RegisterOthers(nsDetail::Dispatch* Dispatch)
  1279. {
  1280. Dispatch->Get.Push(AttrKey::Temperature_Value, m_Temperature.get(), &DeviceTemperatureMould::JSGetCurrentTemperatureValue);
  1281. Dispatch->Get.Push(AttrKey::Remain_Power_Value, m_Battery.get(), &DeviceBatteryMould::JSGetCurrentBatteryValue);
  1282. Dispatch->Get.Push(AttrKey::Wifi_Strength_Value, m_Wifi.get(), &DeviceWifiMould::JSGetCurrentSignalValue);
  1283. Dispatch->Get.Push(TempUpperLimit, m_Temperature.get(), &DeviceTemperatureMould::JSGetTemperatureWarningMax);
  1284. Dispatch->Get.Push(TempLowerLimit, m_Temperature.get(), &DeviceTemperatureMould::JSGetTemperatureWarningMin);
  1285. Dispatch->Get.Push(TempMaxLimit, m_Temperature.get(), &DeviceTemperatureMould::JSGetTemperatureErrorMax);
  1286. Dispatch->Get.Push(TempMinLimit, m_Temperature.get(), &DeviceTemperatureMould::JSGetTemperatureErrorMin);
  1287. Dispatch->Get.Push(Temperature_CalibUpWarn, m_Temperature.get(), &DeviceTemperatureMould::JSGetTemperatureCalibWarningMax);
  1288. Dispatch->Get.Push(Temperature_CalibLowWarn, m_Temperature.get(), &DeviceTemperatureMould::JSGetTemperatureCalibWarningMin);
  1289. Dispatch->Get.Push(BatLowerLimit, m_Battery.get(), &DeviceBatteryMould::JSGetBatteryWarningMin);
  1290. Dispatch->Get.Push(BatMiniLimit, m_Battery.get(), &DeviceBatteryMould::JSGetBatteryErrorMin);
  1291. Dispatch->Get.Push(WifiLowerLimit, m_Wifi.get(), &DeviceWifiMould::JSGetSignalWarningMin);
  1292. Dispatch->Get.Push(WifiMiniLimit, m_Wifi.get(), &DeviceWifiMould::JSGetSignalErrorMin);
  1293. }
  1294. void nsFPD::FPDDeviceCareRay::OnFPDCallback(int nDetectorID, int nEventID, int nEventLevel,
  1295. const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1296. {
  1297. switch (nEventLevel)
  1298. {
  1299. case EVT_LEVEL_CONFIGURATION:
  1300. {
  1301. OnEventProcessConf(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1302. break;
  1303. }
  1304. case EVT_LEVEL_INFORMATOION:
  1305. {
  1306. OnEventProcessInfo(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1307. break;
  1308. }
  1309. case EVT_LEVEL_STATUS:
  1310. {
  1311. OnEventProcessStatus(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1312. break;
  1313. }
  1314. case EVT_LEVEL_DATA:
  1315. {
  1316. OnEventProcessData(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1317. break;
  1318. }
  1319. case EVT_LEVEL_WARNING:
  1320. {
  1321. OnEventProcessWarning(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1322. break;
  1323. }
  1324. case EVT_LEVEL_ERROR:
  1325. {
  1326. OnEventProcessError(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1327. break;
  1328. }
  1329. default:
  1330. break;
  1331. }
  1332. }
  1333. void nsFPD::FPDDeviceCareRay::OnEventProcessConf(int nDetectorID, int nEventID, int nEventLevel,
  1334. const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1335. {
  1336. Error("Not support this conf({$})", nEventID);
  1337. }
  1338. void nsFPD::FPDDeviceCareRay::OnEventProcessInfo(int nDetectorID, int nEventID, int nEventLevel,
  1339. const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1340. {
  1341. Error("Not support this info({$})", nEventID);
  1342. }
  1343. void nsFPD::FPDDeviceCareRay::OnEventProcessStatus(int nDetectorID, int nEventID, int nEventLevel,
  1344. const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1345. {
  1346. switch (nEventID)
  1347. {
  1348. case EVT_STATUS_INIT:
  1349. Info("EVT_STATUS_INIT nParam1:{$}", nParam1);
  1350. break;
  1351. case EVT_STATUS_PANEL:
  1352. {
  1353. ENUM_PANEL_STATUS m_ePanelStatus = (ENUM_PANEL_STATUS)nParam1;
  1354. if (PANEL_CLOSE == nParam1)
  1355. {
  1356. Info("EVT_STATUS_PANEL PANEL_CLOSE");
  1357. m_bDeviceConnect = false;
  1358. }
  1359. else if (PANEL_CONNECT == nParam1)
  1360. {
  1361. Info("EVT_STATUS_PANEL PANEL_CONNECT");
  1362. m_bDeviceConnect = true;
  1363. }
  1364. else if (PANEL_STANDBY == nParam1)
  1365. {
  1366. Info("EVT_STATUS_PANEL PANEL_STANDBY");
  1367. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1368. }
  1369. else if (PANEL_SLEEP == nParam1)
  1370. {
  1371. Info("EVT_STATUS_PANEL PANEL_NOT_READY");
  1372. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_WAKEUP));
  1373. }
  1374. else if (PANEL_READY_EXP == nParam1)
  1375. {
  1376. Info("EVT_STATUS_PANEL PANEL_READY_EXP");
  1377. /*string strTemp = pszMsg;
  1378. if (strTemp.find("true") != std::string::npos)
  1379. {
  1380. m_SyncUnit->ExpReadyNotify(m_nFPDExpReadyTime);
  1381. }
  1382. else
  1383. {
  1384. m_SyncUnit->ExpReadyNotify(0);
  1385. }*/
  1386. m_SyncUnit->FPDReadyNotify(true);
  1387. m_AcqUnit->SetZskkFPDState(to_string(ZSKK_FPD_STATE_READY));
  1388. }
  1389. else if (PANEL_XWINDOW_ON == nParam1) //Xwindow On
  1390. {
  1391. m_stImgCreateTime = { 0 };
  1392. GetLocalTime(&m_stImgCreateTime);
  1393. Info("XWindowOn at {$:d04}-{$:d02}-{$:d02} {$:d02}:{$:d02}:{$:d02}:{$:d03}", m_stImgCreateTime.wYear, m_stImgCreateTime.wMonth, m_stImgCreateTime.wDay,
  1394. m_stImgCreateTime.wHour, m_stImgCreateTime.wMinute, m_stImgCreateTime.wSecond, m_stImgCreateTime.wMilliseconds);
  1395. //if (SYNC_SOFTWARE == m_eSyncMode || SYNC_AED == m_eSyncMode)
  1396. //{
  1397. m_SyncUnit->XWindowOnNotify();
  1398. Info("m_SyncUnit XWindowOnNotify Finished!");
  1399. //}
  1400. }
  1401. else if (PANEL_XWINDOW_OFF == nParam1) // Xwindow Off
  1402. {
  1403. m_stImgCreateTime = { 0 };
  1404. GetLocalTime(&m_stImgCreateTime);
  1405. Info("XWindowOff at {$:d04}-{$:d02}-{$:d02} {$:d02}:{$:d02}:{$:d02}:{$:d03}", m_stImgCreateTime.wYear, m_stImgCreateTime.wMonth, m_stImgCreateTime.wDay,
  1406. m_stImgCreateTime.wHour, m_stImgCreateTime.wMinute, m_stImgCreateTime.wSecond, m_stImgCreateTime.wMilliseconds);
  1407. //if (SYNC_SOFTWARE == m_eSyncMode || SYNC_AED == m_eSyncMode) //探测器的关窗是模拟计算的,所以非软同步模式也没必要发送了
  1408. //{
  1409. m_SyncUnit->XWindowOffNotify();
  1410. //}
  1411. }
  1412. else if (PANEL_START_ACQ == nParam1)
  1413. {
  1414. Info("EVT_STATUS_PANEL PANEL_START_ACQ");
  1415. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_ACQ));
  1416. }
  1417. break;
  1418. }
  1419. case EVT_STATUS_CALIBRATIOIN:
  1420. {
  1421. Info("EVT_STATUS_PANEL EVT_STATUS_CALIBRATIOIN");
  1422. ENUM_PANEL_EVENT_STATE eStatus = (ENUM_PANEL_EVENT_STATE)nParam1;
  1423. switch (eStatus)
  1424. {
  1425. case PANEL_EVENT_START:
  1426. break;
  1427. case PANEL_EVENT_END_OK:
  1428. case PANEL_EVENT_END_ERROR:
  1429. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1430. m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY));
  1431. m_CalibUnit->SetCalibrationProgress(to_string(100));//make progress
  1432. break;
  1433. case PANEL_EVENT_TIMEOUT:
  1434. break;
  1435. default:
  1436. break;
  1437. }
  1438. break;
  1439. }
  1440. case EVT_STATUS_SINGLEEXP:
  1441. {
  1442. Info("EVT_STATUS_PANEL EVT_STATUS_SINGLEEXP");
  1443. if (DOSE_ACCEPT == nParam1)
  1444. {
  1445. Info("Calibration Result is acceptable");
  1446. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1447. m_CalibUnit->PauseCalibration();
  1448. }
  1449. else
  1450. {
  1451. Error("Not support this param({$})", nParam1);
  1452. }
  1453. break;
  1454. }
  1455. case EVT_STATUS_TEMPERATURE:
  1456. {
  1457. Info("EVT_STATUS_PANEL EVT_STATUS_TEMPERATURE");
  1458. float fTemperature = fParam2;
  1459. // if (fTemperature > m_fTemperMaxLimit)
  1460. // {
  1461. // AddErrMsg("14", "temperature_toohigh");
  1462. // }
  1463. // else if (fTemperature >= m_fTemperWarning)
  1464. // {
  1465. // AddWarnMsg("14", "temperature_high");
  1466. // }
  1467. // else if (fTemperature < m_fTemperMinLimit)
  1468. // {
  1469. // AddErrMsg("14", "temperature_toolow");
  1470. // }
  1471. // else if (fTemperature <= m_fTemperLowLimit)
  1472. // {
  1473. // AddWarnMsg("14", "temperature_low");
  1474. // }
  1475. // else
  1476. // {
  1477. // DelErrMsg("14");
  1478. // }
  1479. SendTemperatureValue(fTemperature);
  1480. break;
  1481. }
  1482. case EVT_STATUS_WIFI:
  1483. {
  1484. Info("EVT_STATUS_PANEL EVT_STATUS_WIFI");
  1485. int nWifiLevel = nParam1;
  1486. // if (nWifiLevel < m_nWifiLimit)
  1487. // {
  1488. // AddErrMsg("15", "wifi_toolow");
  1489. // }
  1490. // else if (nWifiLevel <= m_nWifiWarning)
  1491. // {
  1492. // AddWarnMsg("15", "wifi_low");
  1493. // }
  1494. // else
  1495. // {
  1496. // DelErrMsg("15");
  1497. // }
  1498. SendWifiValue(nWifiLevel);
  1499. break;
  1500. }
  1501. case EVT_STATUS_BATTERY_VALUE:
  1502. {
  1503. Info("EVT_STATUS_PANEL EVT_STATUS_BATTERY_VALUE");
  1504. int nBatteryValue = nParam1;
  1505. // if (nBatteryValue < m_nBatteryLimit)
  1506. // {
  1507. // AddErrMsg("16", "battery_toolow");
  1508. // }
  1509. // else if (nBatteryValue <= m_nBatteryWarning)
  1510. // {
  1511. // AddWarnMsg("16", "battery_low");
  1512. // }
  1513. // else
  1514. // {
  1515. // DelErrMsg("16");
  1516. // }
  1517. SendBatteryValue(nBatteryValue);
  1518. break;
  1519. }
  1520. default:
  1521. Error("Not support this event({$})", nEventID);
  1522. break;
  1523. }
  1524. }
  1525. void nsFPD::FPDDeviceCareRay::OnEventProcessData(int nDetectorID, int nEventID, int nEventLevel,
  1526. const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1527. {
  1528. switch (nEventID)
  1529. {
  1530. case EVT_DATA_RAW_IMAGE:
  1531. {
  1532. Info("EVT_DATA_RAW_IMAGE");
  1533. memcpy(m_pFullImgBuffer, pParam, (size_t)m_nFullImageWidth * (size_t)m_nFullImageHeight * sizeof(WORD));
  1534. //某些值暂时先用假值,有需要再改
  1535. ResDataObject objImageHead, objTemp;
  1536. objTemp.add(SM_IMAGE_TYPE, (int)IMAGE_FULL);
  1537. objTemp.add(SM_IMAGE_BIT, m_nImgBits);
  1538. objTemp.add(SM_IMAGE_TAG, 1);
  1539. objTemp.add(SM_IMAGE_INDEX, 1);
  1540. objTemp.add(SM_IMAGE_YEAR, m_stImgCreateTime.wYear);
  1541. objTemp.add(SM_IMAGE_MONTH, m_stImgCreateTime.wMonth);
  1542. objTemp.add(SM_IMAGE_DAY, m_stImgCreateTime.wDay);
  1543. objTemp.add(SM_IMAGE_HOUR, m_stImgCreateTime.wHour);
  1544. objTemp.add(SM_IMAGE_MINUTE, m_stImgCreateTime.wMinute);
  1545. objTemp.add(SM_IMAGE_SEC, m_stImgCreateTime.wSecond);
  1546. objTemp.add(SM_IMAGE_MILLSEC, m_stImgCreateTime.wMilliseconds);
  1547. objTemp.add(SM_IMAGE_LSB, "5000");
  1548. objTemp.add(SM_IMAGE_DOSE, m_nSensitivity);
  1549. objTemp.add(SM_IMAGE_PIXELSPACING, m_nPixelSpacing);
  1550. objTemp.add(SM_IMAGE_PIXELREPRESENTATION, "1");
  1551. objTemp.add(SM_IMAGE_FLIP, "No");
  1552. objTemp.add(SM_IMAGE_ORIGINX, "0");
  1553. objTemp.add(SM_IMAGE_ORIGINY, "0");
  1554. objTemp.add(SM_IMAGE_EXI2UGY, m_fFactorEXI2UGY);
  1555. if (0 != m_nAngle)
  1556. {
  1557. m_AcqUnit->RotateImage(m_pFullImgBuffer, m_nFullImageHeight, m_nFullImageWidth, m_nAngle);
  1558. }
  1559. if (90 == m_nAngle || 270 == m_nAngle)
  1560. {
  1561. objTemp.add(SM_IMAGE_WIDTH, m_nFullImageHeight);
  1562. objTemp.add(SM_IMAGE_HEIGHT, m_nFullImageWidth);
  1563. objTemp.add(SM_IMAGE_ROTATION, "Yes");
  1564. }
  1565. else
  1566. {
  1567. objTemp.add(SM_IMAGE_WIDTH, m_nFullImageWidth);
  1568. objTemp.add(SM_IMAGE_HEIGHT, m_nFullImageHeight);
  1569. objTemp.add(SM_IMAGE_ROTATION, "No");
  1570. }
  1571. objImageHead.add(SM_IMAGE_HEAD, objTemp);
  1572. Info("Full image head: {$}", objImageHead.encode());
  1573. //如果环境中只有探测器,那么这里增加一个推送状态
  1574. if (m_bOnlyHaveFpd)
  1575. {
  1576. Info("OnProcessImage OnlyHaveFpd Sleep 1s then set fpd standby(4)");
  1577. Sleep(1000);
  1578. m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
  1579. }
  1580. m_AcqUnit->AddFrameWithRawHead(IMAGE_FULL, objImageHead.encode(), m_pFullImgBuffer, m_nFullImageWidth * m_nFullImageHeight);
  1581. Info("Add image over");
  1582. printf("Add image over\n");
  1583. break;
  1584. }
  1585. case EVT_DATA_DOSEPARAM:
  1586. {
  1587. m_fDoseParam = fParam2;
  1588. SetEvent(m_WaitCalibDoseEvt);
  1589. break;
  1590. }
  1591. default:
  1592. Error("Not support this data({$})", nEventID);
  1593. break;
  1594. }
  1595. }
  1596. void nsFPD::FPDDeviceCareRay::OnEventProcessError(int nDetectorID, int nEventID, int nEventLevel,
  1597. const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1598. {
  1599. switch (nEventID)
  1600. {
  1601. case EVT_ERR_COMMUNICATE:
  1602. //{
  1603. // string strTemp = pszMsg;
  1604. // if (strTemp.find("true") != std::string::npos)
  1605. // {
  1606. // AddErrMsg("0", "communication error");
  1607. // SendTemperatureValue(0);
  1608. // SendWifiValue(0);
  1609. // SendBatteryValue(0);
  1610. // }
  1611. // else if (strTemp.find("false") != std::string::npos)
  1612. // {
  1613. // DelErrMsg("0");
  1614. // }
  1615. //}
  1616. break;
  1617. case EVT_ERR_INIT_FAILED:
  1618. //{
  1619. // string strTemp = pszMsg;
  1620. // if (strTemp.find("true") != std::string::npos)
  1621. // {
  1622. // AddErrMsg("6", "initialize error");
  1623. // }
  1624. // else if (strTemp.find("false") != std::string::npos)
  1625. // {
  1626. // //一般不可恢复
  1627. // }
  1628. //}
  1629. break;
  1630. default:
  1631. Error("Not support this error({$})", nEventID);
  1632. break;
  1633. }
  1634. }
  1635. void nsFPD::FPDDeviceCareRay::OnEventProcessWarning(int nDetectorID, int nEventID, int nEventLevel,
  1636. const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1637. {
  1638. Error("Not support this warn({$})", nEventID);
  1639. }