DIOS.Dev.FPD.TeledyneDalsa.cpp 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480
  1. #include "stdafx.h"
  2. #include "CCOS.Dev.FPD.TeledyneDalsa.h"
  3. #include "common_api.h"
  4. #include "DICOMImageHeadKey.h"
  5. #include "Detector_TeledyneDalsa.h"
  6. namespace nsFPD = CCOS::Dev::Detail::Detector;
  7. static nsFPD::TeledyneDalsaDriver gIODriver;
  8. Log4CPP::Logger* //mLog::gLogger = nullptr;
  9. extern "C" CCOS::Dev::IODriver * __cdecl GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
  10. {
  11. return &gIODriver;
  12. }
  13. extern "C" CCOS::Dev::IODriver * __cdecl CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
  14. {
  15. return new nsFPD::TeledyneDalsaDriver();
  16. }
  17. nsFPD::TeledyneDalsaDriver::TeledyneDalsaDriver()
  18. {
  19. pObjDev = nullptr;
  20. m_bConnect = false; //缺省为false
  21. m_pAttribute.reset(new ResDataObject());
  22. m_pDescription.reset(new ResDataObject());
  23. }
  24. nsFPD::TeledyneDalsaDriver::~TeledyneDalsaDriver()
  25. {
  26. //mLog::Close();
  27. Log4CPP::ThreadContext::Map::Clear();
  28. //mLog::gLogger = nullptr;
  29. }
  30. void nsFPD::TeledyneDalsaDriver::Prepare()
  31. {
  32. printf("TeledyneDalsa driver module: prepare \r\n");
  33. string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Detector\Conf\Log4CPP.Config.FPD.xml)";
  34. Log4CPP::GlobalContext::Map::Set(ZSKK::Utility::Hash("LogFileName"), "FPD.TeledyneDalsa");
  35. auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
  36. //mLog::gLogger = Log4CPP::LogManager::GetLogger("FPD.TeledyneDalsa");
  37. //mLog::Info("--Func-- driver prepare");
  38. }
  39. bool nsFPD::TeledyneDalsaDriver::Connect()
  40. {
  41. printf("--Func-- driver connect \r\n");
  42. //mLog::Info("--Func-- driver connect \n");
  43. pObjDev = new FPDDeviceTeledyneDalsa(EventCenter, m_ConfigFileName);
  44. m_bConnect = true; //connect执行完毕,置为true
  45. printf("TeledyneDalsa driver module: Connect over\r\n");
  46. return true;
  47. }
  48. void nsFPD::TeledyneDalsaDriver::Disconnect()
  49. {
  50. printf("--Func-- driver disconnect \r\n");
  51. //mLog::Info("--Func-- driver disconnect \n");
  52. m_bConnect = false; //disconnect置为false
  53. }
  54. bool nsFPD::TeledyneDalsaDriver::isConnected() const
  55. {
  56. return m_bConnect;
  57. }
  58. auto nsFPD::TeledyneDalsaDriver::CreateDevice(int index)->std::unique_ptr <IODevice>
  59. {
  60. printf("--Func-- driver createdevice \r\n");
  61. //mLog::Info("--Func-- driver createdevice \n");
  62. auto Device = std::unique_ptr<IODevice>(new IODevice(pObjDev));
  63. pObjDev->CreateDevice();
  64. pObjDev->Register();
  65. return Device;
  66. }
  67. std::string nsFPD::TeledyneDalsaDriver::DriverProbe()
  68. {
  69. printf("--Func-- driver DriverProbe \r\n");
  70. //mLog::Info("--Func-- driver DriverProbe \n");
  71. ResDataObject r_config, HardwareInfo;
  72. if (r_config.loadFile(m_ConfigFileName.c_str()))
  73. {
  74. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  75. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  76. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  77. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  78. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  79. }
  80. else
  81. {
  82. HardwareInfo.add("MajorID", "Detector");
  83. HardwareInfo.add("MinorID", "RF");
  84. HardwareInfo.add("VendorID", "TeledyneDalsa");
  85. HardwareInfo.add("ProductID", "TeledyneDalsa");
  86. HardwareInfo.add("SerialID", "Driver");
  87. }
  88. string str = HardwareInfo.encode();
  89. return str;
  90. }
  91. /***
  92. ** 获取ID和配置
  93. ***/
  94. std::string nsFPD::TeledyneDalsaDriver::GetResource()
  95. {
  96. printf("--Func-- driver GetResource \r\n");
  97. //mLog::Info("--Func-- driver GetResource");
  98. ResDataObject r_config, temp;
  99. if (!temp.loadFile(m_ConfigFileName.c_str()))
  100. {
  101. //mLog::Error("load file error! file name:{$}",m_ConfigFileName.c_str());
  102. return "";
  103. }
  104. m_ConfigAll = temp;
  105. r_config = temp["CONFIGURATION"];
  106. m_Configurations = r_config;
  107. ResDataObject DescriptionTemp;
  108. ResDataObject ListTemp;
  109. string strTemp = ""; //用于读取字符串配置信息
  110. string strIndex = ""; //用于读取配置信息中的List项
  111. int nTemp = -1; //用于读取整型配置信息
  112. char sstream[10] = { 0 }; //用于转换值
  113. string strValue = ""; //用于存储配置的值
  114. string strType = ""; //用于存储配置的类型 int/float/string...
  115. /***
  116. * 1. 通过循环,将所有配置项写到pDeviceConfig
  117. * 2. 记录配置项的内部key以及配置类型,类型对应了不同配置文件路径,用于读写真实值
  118. ***/
  119. try
  120. {
  121. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  122. ////mLog::Info(g_pFPDCtrlLog, "ConfigInfo Count: {$}", nConfigInfoCount);
  123. m_pAttribute->clear();
  124. m_pDescription->clear();
  125. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  126. {
  127. DescriptionTemp.clear();
  128. ListTemp.clear();
  129. //AttributeType
  130. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Type"];
  131. DescriptionTemp.add(AttributeType, strTemp.c_str());
  132. ////mLog::Info(g_pFPDCtrlLog, "--> {$}: {$}", AttributeType, strTemp.c_str());
  133. strType = strTemp; //记录配置项的类型
  134. //AttributeKey
  135. //1. 根据AttributeType,内部key和配置路径,拿到当前的真实值
  136. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  137. nTemp = (int)m_Configurations["ConfigToolInfo"][nInfoIndex]["PathID"];
  138. GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue);
  139. //2. 赋值
  140. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  141. if ("int" == strType)
  142. {
  143. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  144. ////mLog::Info(g_pFPDCtrlLog, "Key {$}: {$}", strTemp.c_str(), atoi(strValue.c_str()));
  145. }
  146. else if ("float" == strType)
  147. {
  148. (*m_pAttribute).add(strTemp.c_str(), atof(strValue.c_str()));
  149. ////mLog::Info(g_pFPDCtrlLog, "Key {$}: {$}", strTemp.c_str(), atof(strValue.c_str()));
  150. }
  151. else //其它先按string类型处理
  152. {
  153. (*m_pAttribute).add(strTemp.c_str(), strValue.c_str());
  154. ////mLog::Info(g_pFPDCtrlLog, "Key {$}: {$}", strTemp.c_str(), strValue.c_str());
  155. }
  156. //AttributeAccess
  157. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Access"];
  158. DescriptionTemp.add(AttributeAccess, strTemp.c_str());
  159. ////mLog::Info(g_pFPDCtrlLog, "{$}: {$}", AttributeAccess, strTemp.c_str());
  160. //AttributeRangeMin
  161. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMin"];
  162. if (strTemp != "") //不需要的配置项为空
  163. {
  164. DescriptionTemp.add(AttributeRangeMin, strTemp.c_str());
  165. ////mLog::Info(g_pFPDCtrlLog, "{$}: {$}", AttributeRangeMin, strTemp.c_str());
  166. }
  167. //AttributeRangeMax
  168. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMax"];
  169. if (strTemp != "") //不需要的配置项为空
  170. {
  171. DescriptionTemp.add(AttributeRangeMax, strTemp.c_str());
  172. ////mLog::Info(g_pFPDCtrlLog, "{$}: {$}", AttributeRangeMax, strTemp.c_str());
  173. }
  174. //AttributeList
  175. nTemp = m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListNum"];
  176. if (nTemp > 0) //ListNum不大于0时说明不需要list配置
  177. {
  178. for (int nListIndex = 0; nListIndex < nTemp; nListIndex++)
  179. {
  180. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListInfo"][nListIndex];
  181. //sprintf_s(sstream, "{$}", nListIndex);
  182. auto temKey = std::to_string(nListIndex);
  183. ListTemp.add(temKey.c_str(), strTemp.c_str());
  184. ////mLog::Info(g_pFPDCtrlLog, "list {$}: {$}", nListIndex, strTemp.c_str());
  185. }
  186. DescriptionTemp.add(AttributeList, ListTemp);
  187. }
  188. //AttributeRequired
  189. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Required"];
  190. DescriptionTemp.add(AttributeRequired, strTemp.c_str());
  191. ////mLog::Info(g_pFPDCtrlLog, "{$}: {$}", AttributeRequired, strTemp.c_str());
  192. //AttributeDefaultValue
  193. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["DefaultValue"];
  194. if (strTemp != "") //不需要的配置项为空
  195. {
  196. DescriptionTemp.add(AttributeDefaultValue, strTemp.c_str());
  197. ////mLog::Info(g_pFPDCtrlLog, "{$}: {$}", AttributeDefaultValue, strTemp.c_str());
  198. }
  199. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  200. (*m_pDescription).add(strTemp.c_str(), DescriptionTemp);
  201. }
  202. }
  203. catch (exception e)
  204. {
  205. //mLog::Error("Get config error: {$}", e.what());
  206. return "";
  207. }
  208. ResDataObject resDeviceResource;
  209. resDeviceResource.add(ConfKey::CcosDetectorAttribute, (*m_pAttribute));
  210. resDeviceResource.add(ConfKey::CcosDetectorDescription, (*m_pDescription));
  211. ResDataObject DescriptionTempEx;
  212. DescriptionTempEx.add(ConfKey::CcosDetectorConfig, resDeviceResource);
  213. m_DeviceConfig = DescriptionTempEx;
  214. string res = DescriptionTempEx.encode();
  215. printf("TeledyneDalsa driver module: get resource over \r\n");
  216. ////mLog::Info("get resource over {$}", res.c_str());//此处在调试读取配置的时候再放开,不然打印很长查日志不方便
  217. //mLog::Info("get resource over!");
  218. return res;
  219. }
  220. std::string nsFPD::TeledyneDalsaDriver::DeviceProbe()
  221. {
  222. printf("--Func-- driver DeviceProbe \r\n");
  223. //mLog::Info("--Func-- driver DeviceProbe \n");
  224. ResDataObject r_config, HardwareInfo;
  225. if (r_config.loadFile(m_ConfigFileName.c_str()))
  226. {
  227. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  228. HardwareInfo.add("MinorID", "Device");
  229. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  230. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  231. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  232. }
  233. else
  234. {
  235. HardwareInfo.add("MajorID", "Detector");
  236. HardwareInfo.add("MinorID", "Device");
  237. HardwareInfo.add("VendorID", "TeledyneDalsa");
  238. HardwareInfo.add("ProductID", "TeledyneDalsa");
  239. HardwareInfo.add("SerialID", "1234");
  240. }
  241. string str = HardwareInfo.encode();
  242. return str;
  243. }
  244. bool nsFPD::TeledyneDalsaDriver::GetDeviceConfig(std::string& Cfg)
  245. {
  246. printf("--Func-- driver GetDeviceConfig \r\n");
  247. //mLog::Info("--Func-- driver GetDeviceConfig \n");
  248. Cfg = m_DeviceConfig.encode();
  249. //mLog::Info("GetDeviceConfig over");
  250. return true;
  251. }
  252. bool nsFPD::TeledyneDalsaDriver::SetDeviceConfig(std::string Cfg)
  253. {
  254. printf("--Func-- driver SetDeviceConfig \r\n");
  255. //mLog::Info("--Func-- SetDeviceConfig {$}", Cfg.c_str());
  256. ResDataObject DeviceConfig;
  257. DeviceConfig.decode(Cfg.c_str());
  258. ResDataObject DescriptionTempEx;
  259. DescriptionTempEx = DeviceConfig["DeviceConfig"];
  260. bool bSaveFile = false; //true:重新保存配置文件
  261. string strAccess = "";
  262. for (int i = 0; i < DescriptionTempEx.size(); i++)
  263. {
  264. ResDataObject temp = DescriptionTempEx[i];
  265. //mLog::Info("{$}", temp.encode());
  266. for (int j = 0; j < temp.size(); j++)
  267. {
  268. string strKey = temp.GetKey(j);
  269. //mLog::Info("{$}", strKey.c_str());
  270. try
  271. {
  272. if (m_pAttribute->GetFirstOf(strKey.c_str()) >= 0)
  273. {
  274. strAccess = (string)(*m_pDescription)[strKey.c_str()]["Access"];
  275. if ("RW" == strAccess)
  276. {
  277. //修改对应配置,在其他单元的配置项要同时调用其修改函数修改真实值
  278. //1. 修改内存中的值,用于给上层发消息
  279. (*m_pAttribute)[strKey.c_str()] = temp[j];
  280. //2. 拿到Innerkey
  281. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  282. //mLog::Info("ConfigInfo Count: {$}", nConfigInfoCount);
  283. string strTemp = ""; //存储AttributeKey
  284. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  285. {
  286. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  287. if (strTemp == strKey)
  288. {
  289. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  290. break;
  291. }
  292. }
  293. //3. 修改配置文件中的值
  294. if (SetDeviceConfigValue(m_Configurations, strTemp.c_str(), 1, temp[j]))
  295. {
  296. bSaveFile = true;
  297. }
  298. }
  299. else
  300. {
  301. //mLog::Info("{$} is not a RW configuration item", strKey.c_str());
  302. }
  303. }
  304. }
  305. catch (ResDataObjectExption& e)
  306. {
  307. //mLog::Error("SetDriverConfig crashed: {$}", e.what());
  308. return false;
  309. }
  310. }
  311. }
  312. if (bSaveFile)
  313. {
  314. //3. 重新保存配置文件
  315. SaveConfigFile(true);
  316. }
  317. return true;
  318. }
  319. bool nsFPD::TeledyneDalsaDriver::SaveConfigFile(bool bSendNotify)
  320. {
  321. printf("--Func-- driver SaveConfigFile \r\n");
  322. m_ConfigAll["CONFIGURATION"] = m_Configurations;
  323. std::cout << " Write Config to xml " << m_ConfigFileName << " Content: " << m_Configurations.encode() << endl;
  324. m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
  325. //mLog::Info("SaveConfigFile over");
  326. return true;
  327. }
  328. bool nsFPD::TeledyneDalsaDriver::GetDeviceConfigValue(ResDataObject config, const char* pInnerKey,
  329. int nPathID, string& strValue)
  330. {
  331. strValue = "";
  332. string strTemp = pInnerKey;
  333. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  334. {
  335. if (WiredIP == strTemp || WirelessIP == strTemp || LocalIP == strTemp)
  336. {
  337. strValue = (string)config["connections"][pInnerKey];
  338. }
  339. else if (DetectorVender == strTemp || DetectorModel == strTemp ||
  340. DetectorDescription == strTemp || DetectorSerialNumber == strTemp)
  341. {
  342. strValue = (string)config[pInnerKey];
  343. }
  344. else if (SyncType == strTemp || FPDWorkStation == strTemp ||
  345. ImageWidth == strTemp || ImageHeight == strTemp || RawImgWidth == strTemp || RawImgHeight == strTemp)
  346. {
  347. strValue = (string)config["ModeTable"]["DetectorMode"][pInnerKey];
  348. }
  349. else if (TempMaxLimit == strTemp || ReConnect == strTemp ||
  350. TempUpperLimit == strTemp || TempLowerLimit == strTemp || "TempMinLimit" == strTemp ||
  351. BatLowerLimit == strTemp || BatMiniLimit == strTemp ||
  352. BatLowerLimitInCali == strTemp || WifiLowerLimit == strTemp ||
  353. WifiMiniLimit == strTemp || HighPowerTimeout == strTemp ||
  354. ShowTemperature == strTemp || ShowWifi == strTemp ||
  355. ShowBattery == strTemp || ShowBluetooth == strTemp ||
  356. FPDExamMode == strTemp || FPDAcqMode == strTemp || FPDModeMatch == strTemp || "Attached" == strTemp)
  357. {
  358. strValue = (string)config[pInnerKey];
  359. }
  360. else
  361. {
  362. strValue = "";
  363. //mLog::Warn("Error Configuration item: {$}", pInnerKey);
  364. }
  365. }
  366. return true;
  367. }
  368. bool nsFPD::TeledyneDalsaDriver::SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey,
  369. int nPathID, const char* szValue)
  370. {
  371. string strTemp = pInnerKey;
  372. //mLog::Trace("Begin to change {$} item value to {$}", pInnerKey, szValue);
  373. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  374. {
  375. if (WiredIP == strTemp || WirelessIP == strTemp || LocalIP == strTemp)
  376. {
  377. config["connections"][pInnerKey] = szValue;
  378. }
  379. else if (DetectorVender == strTemp || DetectorModel == strTemp ||
  380. DetectorDescription == strTemp || DetectorSerialNumber == strTemp)
  381. {
  382. config[pInnerKey] = szValue;
  383. }
  384. else if (SyncType == strTemp || FPDWorkStation == strTemp ||
  385. ImageWidth == strTemp || ImageHeight == strTemp)
  386. {
  387. config["ModeTable"]["DetectorMode"][pInnerKey] = szValue;
  388. }
  389. else if (TempMaxLimit == strTemp || ReConnect == strTemp ||
  390. TempUpperLimit == strTemp || TempLowerLimit == strTemp ||
  391. BatLowerLimit == strTemp || BatMiniLimit == strTemp ||
  392. BatLowerLimitInCali == strTemp || WifiLowerLimit == strTemp ||
  393. WifiMiniLimit == strTemp || HighPowerTimeout == strTemp ||
  394. ShowTemperature == strTemp || ShowWifi == strTemp ||
  395. ShowBattery == strTemp || ShowBluetooth == strTemp ||
  396. FPDExamMode == strTemp || FPDAcqMode == strTemp || FPDModeMatch == strTemp)
  397. {
  398. config[pInnerKey] = szValue;
  399. }
  400. else
  401. {
  402. //mLog::Warn("Error Configuration item: {$}", pInnerKey);
  403. return false;
  404. }
  405. }
  406. return true;
  407. }
  408. //-----------------------------------------------------------------------------
  409. // FPDDeviceTeledyneDalsa
  410. //-----------------------------------------------------------------------------
  411. extern Detector_TeledyneDalsa* g_pDetector;
  412. nsFPD::FPDDeviceTeledyneDalsa::FPDDeviceTeledyneDalsa(std::shared_ptr<IOEventCenter> center,std::string strConfigPath)
  413. {
  414. m_bConnect = false;
  415. m_pDetector = nullptr;
  416. m_nImageHeight = 0;
  417. m_nImageWidth = 0;
  418. /*m_nCropLeft = 0;
  419. m_nCropRight = 0;
  420. m_nCropTop = 0;
  421. m_nCropBottom = 0;
  422. m_nRawImgHeight = 0;
  423. m_nRawImgWidth = 0;*/
  424. m_pImgBuffer = nullptr;
  425. m_nImgBits = 0;
  426. m_nAngle = 0;
  427. m_nPixelSpacing = 0;
  428. m_nSensitivity = 0;
  429. m_strWorkPath = GetProcessDirectory();
  430. m_DetectorCtrlUnit.reset(new OemCtrl(center, this));
  431. m_AcqUnit.reset(new OemAcq(center, this));
  432. m_SyncUnit.reset(new OemSync(center, this));
  433. m_CalibUnit.reset(new OemCalib(center, this));
  434. m_DetectorConfiguration.reset(new DetectorConfiguration(strConfigPath));
  435. m_DetectorCtrlUnit->SetDetectorStatus(DETECTOR_STATUS_STANDBY);
  436. m_CalibUnit->SetCalibrationStatus(CCOS_CALIBRATION_STATUS_STANDBY);
  437. EventCenter = center;
  438. }
  439. nsFPD::FPDDeviceTeledyneDalsa::~FPDDeviceTeledyneDalsa()
  440. {
  441. if (nullptr != m_pDetector)
  442. {
  443. delete m_pDetector;
  444. m_pDetector = nullptr;
  445. }
  446. if (nullptr != m_pImgBuffer)
  447. {
  448. delete m_pImgBuffer;
  449. m_pImgBuffer = nullptr;
  450. }
  451. }
  452. std::string nsFPD::FPDDeviceTeledyneDalsa::GetGUID() const
  453. {
  454. return DetectorUnitType;
  455. }
  456. bool nsFPD::FPDDeviceTeledyneDalsa::Prepare()
  457. {
  458. printf("--Func-- device Prepare \r\n");
  459. //mLog::Info("--Func-- device prepare \n");
  460. EventCenter->OnMaxBlockSize("RfQue",
  461. m_stDeviceConfig.nMaxImgWidth * m_stDeviceConfig.nMaxImgHeight * 2,
  462. 20, 1500 * 1500 * 2, 1);
  463. //printf(("%d %d \r\n", m_stDeviceConfig.nMaxImgWidth, m_stDeviceConfig.nMaxImgHeight);
  464. Connect();
  465. return true;
  466. }
  467. bool nsFPD::FPDDeviceTeledyneDalsa::CreateDevice()
  468. {
  469. printf("--Func-- device CreateDevice \r\n");
  470. //mLog::Info("--Func-- device CreateDevice \n");
  471. if (!LoadConfig())
  472. {
  473. return false;
  474. }
  475. //bool bRet = false;
  476. if (nullptr == g_pDetector)
  477. {
  478. if (nullptr == m_pDetector)
  479. {
  480. m_pDetector = new Detector_TeledyneDalsa();
  481. g_pDetector = (Detector_TeledyneDalsa*)m_pDetector;
  482. }
  483. }
  484. else
  485. {
  486. m_pDetector = g_pDetector;
  487. }
  488. ((Detector_TeledyneDalsa*)m_pDetector)->DriverEntry(this, m_DetectorConfiguration->m_Configurations);
  489. return true;
  490. }
  491. bool nsFPD::FPDDeviceTeledyneDalsa::LoadConfig()
  492. {
  493. printf("--Func-- device LoadConfig \r\n");
  494. //mLog::Info("--Func-- device LoadConfig \n");
  495. if (!m_DetectorConfiguration->LoadConfigurations(m_stDeviceConfig, m_ACQMODElist))
  496. {
  497. //mLog::Error("Load configuration file failed!!! \n");
  498. return false;
  499. }
  500. //printf("m_ACQMODElist:\n {$}\n", m_ACQMODElist.encode()); //暂时用不到
  501. //不同采集模式可能会有不同的值,后面在考虑 --ys
  502. char szFDinfo[MAX_STRING] = { 0 };
  503. string strFPDinfo;
  504. sprintf_s(szFDinfo, "%d", m_nSensitivity);
  505. strFPDinfo = szFDinfo;
  506. m_DetectorCtrlUnit->SetFPDSensitivity(strFPDinfo);
  507. m_DetectorCtrlUnit->SetPixelData("");
  508. m_DetectorCtrlUnit->SetTargetEXI("5000");
  509. ResDataObject CalibDoseList;
  510. string strCalibDose = m_strWorkPath + R"(\OEMDrivers\Detector\TeledyneDalsaDetector\CalibrationDose_TeledyneDalsa.xml)";
  511. //mLog::Info("start load calibDose file: {$}", strCalibDose.c_str());
  512. try {
  513. CalibDoseList.loadFile(strCalibDose.c_str());
  514. m_CalibDoseList = CalibDoseList["List"];
  515. //mLog::Info("m_CalibDoseList: {$} ", m_CalibDoseList.encode());
  516. for (int i = 0; i < m_CalibDoseList.size(); i++)
  517. {
  518. ResDataObject temp = m_CalibDoseList[i];
  519. //mLog::Info("temp : {$} ", temp.encode());
  520. }
  521. }
  522. catch (exception e)
  523. {
  524. //mLog::Error("Get calibDose error: {$}", e.what());
  525. }
  526. return true;
  527. }
  528. void nsFPD::FPDDeviceTeledyneDalsa::Register()
  529. {
  530. auto Disp = &Dispatch;
  531. RegisterCtrl(Disp);
  532. RegisterAcq(Disp);
  533. RegisterSync(Disp);
  534. RegisterCalib(Disp);
  535. }
  536. RET_STATUS nsFPD::FPDDeviceTeledyneDalsa::Connect()
  537. {
  538. printf("--Func-- device Connect \r\n");
  539. //mLog::Info("--Func-- device Connect \n");
  540. RET_STATUS ret = RET_STATUS::RET_FAILED;
  541. if(((Detector_TeledyneDalsa*)m_pDetector)->Connect(this, m_strWorkPath.c_str()))
  542. {
  543. m_bConnect = true;
  544. ret = RET_STATUS::RET_SUCCEED;
  545. }
  546. return ret;
  547. }
  548. RET_STATUS nsFPD::FPDDeviceTeledyneDalsa::EnterExam(int nExamMode)
  549. {
  550. //mLog::Info("--Func-- EnterExam {$}", nExamMode);
  551. switch (nExamMode)
  552. {
  553. case APP_STATUS_WORK_BEGIN:
  554. //mLog::Info("Enter into Exam Windows");
  555. m_eAppStatus = APP_STATUS_WORK_BEGIN;
  556. break;
  557. case APP_STATUS_WORK_END:
  558. //mLog::Info("Quit Exam Windows");
  559. m_eAppStatus = APP_STATUS_WORK_END;
  560. break;
  561. case APP_STATUS_DETSHARE_BEGIN:
  562. //mLog::Info("Enter into Detector Share Windows");
  563. m_eAppStatus = APP_STATUS_DETSHARE_BEGIN;
  564. break;
  565. case APP_STATUS_DETSHAR_END:
  566. m_eAppStatus = APP_STATUS_IDLE;
  567. //mLog::Info("Quit Detector Share Windows");
  568. m_eAppStatus = APP_STATUS_DETSHAR_END;
  569. break;
  570. case APP_STATUS_CAL_BEGIN:
  571. //mLog::Info("Enter into Calibration Windows");
  572. m_eAppStatus = APP_STATUS_CAL_BEGIN;
  573. break;
  574. case APP_STATUS_CAL_END:
  575. //mLog::Info("Quit Calibration Windows");
  576. m_eAppStatus = APP_STATUS_CAL_END;
  577. break;
  578. case APP_STATUS_WORK_IN_SENSITIVITY:
  579. //mLog::Info("Enter into sensitivity test interface");
  580. m_eAppStatus = APP_STATUS_WORK_IN_SENSITIVITY;
  581. break;
  582. default:
  583. break;
  584. }
  585. g_pDetector->EnterExamMode(nExamMode);
  586. return RET_STATUS::RET_SUCCEED;
  587. }
  588. RET_STATUS nsFPD::FPDDeviceTeledyneDalsa::SetAcqMode(int nMode)
  589. {
  590. printf("TeledyneDalsa device module: SetAcqMode(%d) \r\n", nMode);
  591. //mLog::Info("--Func-- SetAcqMode({$})", nMode);
  592. RET_STATUS ret = RET_STATUS::RET_FAILED;
  593. //如果没连接,不执行
  594. try
  595. {
  596. if (nullptr != m_pImgBuffer)
  597. {
  598. delete m_pImgBuffer;
  599. m_pImgBuffer = nullptr;
  600. }
  601. ResDataObject objModeConfig = m_DetectorConfiguration->m_Configurations;
  602. int nModeCount = (int)objModeConfig["ModeTable"].GetKeyCount("DetectorMode");
  603. for (int i = 0; i < nModeCount; i++)
  604. {
  605. int nAppModeID = (int)objModeConfig["ModeTable"][i]["LogicMode"];
  606. if (nAppModeID == nMode)
  607. {
  608. m_nImageWidth = (int)objModeConfig["ModeTable"][i]["ImageWidth"];
  609. m_nImageHeight = (int)objModeConfig["ModeTable"][i]["ImageHeight"];
  610. /*m_nCropLeft = (int)objModeConfig["ModeTable"][i]["DeadLineLeft"];
  611. m_nCropRight = (int)objModeConfig["ModeTable"][i]["DeadLineRight"];
  612. m_nCropTop = (int)objModeConfig["ModeTable"][i]["DeadLineTop"];
  613. m_nCropBottom = (int)objModeConfig["ModeTable"][i]["DeadLineBottom"];
  614. m_nRawImgHeight = (int)objModeConfig["ModeTable"][i]["RawImgSizeY"];
  615. m_nRawImgWidth = (int)objModeConfig["ModeTable"][i]["RawImgSizeX"];*/
  616. m_nImgBits = (int)objModeConfig["ModeTable"][i]["PhySizeInfoBit"];
  617. m_nPixelSpacing = (int)objModeConfig["ModeTable"][i]["PixelPitch"];
  618. m_nSensitivity = (int)objModeConfig["ModeTable"][i]["Sensitivity"];
  619. m_nAngle = (int)objModeConfig["ModeTable"][i]["RotateAngle"];
  620. string strDose = (string)objModeConfig["ModeTable"][i]["CalibConfig"]["Dose"];
  621. m_fDose = stof(strDose.c_str());
  622. m_pImgBuffer = new WORD[(size_t)m_nImageWidth * (size_t)m_nImageHeight];
  623. if (m_nAngle == 90 || m_nAngle == 270)
  624. {
  625. m_AcqUnit->SetFulImageInfo(m_nImageWidth, m_nImageHeight, m_nImgBits, false);
  626. }
  627. else
  628. {
  629. m_AcqUnit->SetFulImageInfo(m_nImageHeight, m_nImageWidth, m_nImgBits, false);
  630. }
  631. m_AcqUnit->SetPrevImageInfo(false, 0, 0, false);
  632. break;
  633. }
  634. }
  635. //mLog::Info("Ratate angle: {$}", m_nAngle);
  636. if (nullptr == m_pImgBuffer)
  637. {
  638. //mLog::Error("Illegal mode!");
  639. }
  640. else
  641. {
  642. if (g_pDetector->SetAcqMode(nMode))
  643. {
  644. ret = RET_STATUS::RET_SUCCEED;
  645. }
  646. }
  647. }
  648. catch (ResDataObjectExption& e)
  649. {
  650. //mLog::Error("Read configuration failed, Error code: {$}", e.what());
  651. }
  652. return ret;
  653. }
  654. RET_STATUS nsFPD::FPDDeviceTeledyneDalsa::PrepareAcquisition()
  655. {
  656. printf("--Func-- PrepareAcquisition \r\n");
  657. //mLog::Info("--Func-- PrepareAcquisition");
  658. RET_STATUS ret = RET_STATUS::RET_FAILED;
  659. if (!m_bConnect)
  660. {
  661. //mLog::Error("Detector not connected, return");
  662. return ret;
  663. }
  664. if (DETECTOR_STATUS_STANDBY != m_DetectorCtrlUnit->GetDetectorStatus())
  665. {
  666. if ((m_CalibUnit->GetCalibrationStatus() == CCOS_CALIBRATION_STATUS_RUNNING) ||
  667. (m_CalibUnit->GetCalibrationStatus() == CCOS_CALIBRATION_STATUS_ACTIVE))
  668. {
  669. //printf(("PrepareAcquisition failed. Detector at Calibration status.\n");
  670. //mLog::Error("PrepareAcquisition failed. Detector at Calibration status");
  671. }
  672. if (DETECTOR_STATUS_ACQ == m_DetectorCtrlUnit->GetDetectorStatus())
  673. {
  674. //printf(("Detector already at Acq status.\n");
  675. //mLog::Warn("Detector already at Acq status");
  676. ret = RET_STATUS::RET_SUCCEED;
  677. }
  678. }
  679. else
  680. {
  681. m_SyncUnit->FPDReadyNotify(false); //prepare前置为初值
  682. if (g_pDetector->PrepareAcquisition(this))
  683. {
  684. ret = RET_STATUS::RET_SUCCEED;
  685. m_SyncUnit->FPDReadyNotify(true); //prepare succeed
  686. }
  687. }
  688. m_DetectorCtrlUnit->SetDetectorStatus(DETECTOR_STATUS_STANDBY);
  689. //mLog::Info("PrepareAcquisition over");
  690. return ret;
  691. }
  692. RET_STATUS nsFPD::FPDDeviceTeledyneDalsa::StartAcquisition()
  693. {
  694. printf("--Func-- StartAcquisition \r\n");
  695. //mLog::Info("--Func-- StartAcquisition");
  696. RET_STATUS ret = RET_STATUS::RET_FAILED;
  697. if (!m_bConnect)
  698. {
  699. //mLog::Error("Detector not connected, return");
  700. return ret;
  701. }
  702. if (DETECTOR_STATUS_STANDBY != m_DetectorCtrlUnit->GetDetectorStatus())
  703. {
  704. if ((m_CalibUnit->GetCalibrationStatus() == CCOS_CALIBRATION_STATUS_RUNNING) ||
  705. (m_CalibUnit->GetCalibrationStatus() == CCOS_CALIBRATION_STATUS_ACTIVE))
  706. {
  707. //printf(("PrepareAcquisition failed. Detector at Calibration status.\n");
  708. //mLog::Error("PrepareAcquisition failed. Detector at Calibration status.");
  709. }
  710. if (DETECTOR_STATUS_ACQ == m_DetectorCtrlUnit->GetDetectorStatus())
  711. {
  712. //printf(("Detector already at Acq status.\n");
  713. //mLog::Error("Detector already at Acq status.");
  714. }
  715. }
  716. else
  717. {
  718. if (g_pDetector->StartAcquisition(this))
  719. {
  720. ret = RET_STATUS::RET_SUCCEED;
  721. m_DetectorCtrlUnit->SetDetectorStatus(DETECTOR_STATUS_ACQ);
  722. }
  723. else
  724. {
  725. m_DetectorCtrlUnit->SetDetectorStatus(DETECTOR_STATUS_STANDBY);
  726. }
  727. }
  728. //mLog::Info("StartAcquisition over");
  729. return ret;
  730. }
  731. RET_STATUS nsFPD::FPDDeviceTeledyneDalsa::StopAcquisition()
  732. {
  733. printf("--Func-- StopAcquisition \r\n");
  734. //mLog::Info("--Func-- StopAcquisition");
  735. RET_STATUS ret = RET_STATUS::RET_FAILED;
  736. if (!m_bConnect)
  737. {
  738. //mLog::Error("Detector not connected, return");
  739. return ret;
  740. }
  741. if (DETECTOR_STATUS_STANDBY == m_DetectorCtrlUnit->GetDetectorStatus())
  742. {
  743. //printf(("Detector already at stanby status.\n");
  744. //mLog::Info("Detector already at stanby status.");
  745. ret = RET_STATUS::RET_SUCCEED;
  746. }
  747. else
  748. {
  749. if (g_pDetector->StopAcquisition(this))
  750. {
  751. ret = RET_STATUS::RET_SUCCEED;
  752. m_DetectorCtrlUnit->SetDetectorStatus(DETECTOR_STATUS_STANDBY);
  753. }
  754. }
  755. //mLog::Info("StopAcquisition over");
  756. return ret;
  757. }
  758. RET_STATUS nsFPD::FPDDeviceTeledyneDalsa::SetXrayOnNum()
  759. {
  760. //mLog::Info("--Func-- SetXrayOnNum");
  761. if (g_pDetector->SetXrayOnNum())
  762. {
  763. return RET_STATUS::RET_SUCCEED;
  764. }
  765. return RET_STATUS::RET_FAILED;
  766. }
  767. RET_STATUS nsFPD::FPDDeviceTeledyneDalsa::SetExposureTimes(int nTimes)
  768. {
  769. //mLog::Info("--Func-- SetExposureTimes({$})", nTimes);
  770. if (g_pDetector->SetExposureTimes(nTimes))
  771. {
  772. return RET_STATUS::RET_SUCCEED;
  773. }
  774. return RET_STATUS::RET_FAILED;
  775. }
  776. RET_STATUS nsFPD::FPDDeviceTeledyneDalsa::ActiveCalibration(CCOS_CALIBRATION_TYPE eType)
  777. {
  778. printf("--Func-- ActiveCalibration eType:%d \r\n", eType);
  779. //mLog::Info("--Func-- ActiveCalibration {$}", (int)eType);
  780. RET_STATUS ret = RET_STATUS::RET_FAILED;
  781. if (!m_bConnect)
  782. {
  783. //mLog::Error("Detector not connected, return");
  784. return ret;
  785. }
  786. if (eType == CCOS_CALIBRATION_TYPE_NONE || eType == CCOS_CALIBRATION_TYPE_MAX)
  787. {
  788. return RET_STATUS::RET_INVALID;
  789. }
  790. if (DETECTOR_STATUS_STANDBY != m_DetectorCtrlUnit->GetDetectorStatus())
  791. {
  792. if (DETECTOR_STATUS_ACQ == m_DetectorCtrlUnit->GetDetectorStatus())
  793. {
  794. //printf(("ActiveCalibration failed. Detector at Acq status\r\n");
  795. //mLog::Error("ActiveCalibration failed. Detector at Acq status");
  796. }
  797. return RET_STATUS::RET_FAILED;
  798. }
  799. if (g_pDetector->ActiveCalibration(this, eType))
  800. {
  801. ret = RET_STATUS::RET_SUCCEED;
  802. m_CalibUnit->SetCalibrationStatus(CCOS_CALIBRATION_STATUS_ACTIVE);
  803. m_CalibUnit->SetCalibrationProgress(0);
  804. }
  805. else
  806. {
  807. //mLog::Error("Active calibration failed");
  808. }
  809. //mLog::Info("ActiveCalibration over");
  810. return ret;
  811. }
  812. RET_STATUS nsFPD::FPDDeviceTeledyneDalsa::PrepareCalibration()
  813. {
  814. printf("--Func-- PrepareCalibration \r\n");
  815. //mLog::Info("--Func-- PrepareCalibration");
  816. RET_STATUS ret = RET_STATUS::RET_FAILED;
  817. if (!m_bConnect)
  818. {
  819. //mLog::Error("Detector not connected, return");
  820. return ret;
  821. }
  822. m_SyncUnit->FPDReadyNotify(false); //prepare前置为初值
  823. if (g_pDetector->PrepareCalibration(this))
  824. {
  825. ret = RET_STATUS::RET_SUCCEED;
  826. m_SyncUnit->FPDReadyNotify(true); //prepare succeed
  827. }
  828. else
  829. {
  830. //mLog::Error("Prepare calibration failed");
  831. }
  832. //mLog::Info("PrepareCalibration over");
  833. return ret;
  834. }
  835. RET_STATUS nsFPD::FPDDeviceTeledyneDalsa::GetRequestedDose(std::string& strDose)
  836. {
  837. printf("--Func-- GetRequestedDose \r\n");
  838. //mLog::Info("--Func-- GetRequestedDose");
  839. RET_STATUS Ret = RET_STATUS::RET_SUCCEED;
  840. bool bGetDoseInfo = false;
  841. ResDataObject out;
  842. CCOS_CALIBRATION_TYPE nCalibrationType = m_CalibUnit->GetCalibrationType();
  843. if (CCOS_CALIBRATION_TYPE_DARK == nCalibrationType)
  844. {
  845. out.add("Dose", 0.0f);
  846. out.add("kV", 0.0f);
  847. out.add("mA", 0.0f);
  848. out.add("ms", 0.0f);
  849. out.add("mAs", 0.0f);
  850. bGetDoseInfo = true;
  851. }
  852. else if (CCOS_CALIBRATION_TYPE_XRAY == nCalibrationType)
  853. {
  854. for (int i = 0; i < m_CalibDoseList.size(); i++)
  855. {
  856. ResDataObject temp = m_CalibDoseList[i];
  857. int nDose = temp["Dose"];
  858. int nDoseParem = (int)(m_fDose * 1000);
  859. if (nDoseParem == nDose)
  860. {
  861. out.add("Dose", nDoseParem);
  862. out.add("kV", temp["kV"]);
  863. out.add("mA", temp["mA"]);
  864. out.add("ms", temp["ms"]);
  865. out.add("mAs", temp["mAs"]);
  866. bGetDoseInfo = true;
  867. break;
  868. }
  869. }
  870. }
  871. else
  872. {
  873. Ret = RET_STATUS::RET_FAILED;
  874. }
  875. if (bGetDoseInfo)
  876. {
  877. strDose = out.encode();
  878. //mLog::Info("GetRequestedDose {$} over", strDose.c_str());
  879. }
  880. else
  881. {
  882. //mLog::Error("GetRequestedDose failed");
  883. }
  884. return Ret;
  885. }
  886. RET_STATUS nsFPD::FPDDeviceTeledyneDalsa::StartCalibration()
  887. {
  888. printf("--Func-- StartCalibration \r\n");
  889. //mLog::Info("--Func-- StartCalibration");
  890. RET_STATUS ret = RET_STATUS::RET_FAILED;
  891. if (!m_bConnect)
  892. {
  893. //mLog::Error("Detector not connected, return");
  894. return ret;
  895. }
  896. if ((m_CalibUnit->GetCalibrationStatus() != CCOS_CALIBRATION_STATUS_PAUSE) && (m_CalibUnit->GetCalibrationStatus() != CCOS_CALIBRATION_STATUS_ACTIVE))
  897. {
  898. //printf(("CCOS_CALIBRATION_STATUS = %d\r\n", (int)m_CalibUnit->GetCalibrationStatus());
  899. //mLog::Error("Start calibration failed, in {$} status", (int)m_CalibUnit->GetCalibrationStatus());
  900. return ret;
  901. }
  902. if (DETECTOR_STATUS_STANDBY != m_DetectorCtrlUnit->GetDetectorStatus())
  903. {
  904. if (DETECTOR_STATUS_ACQ == m_DetectorCtrlUnit->GetDetectorStatus())
  905. {
  906. //printf(("Start calibration failed. Detector at Acq status.\r\n");
  907. //mLog::Error("Start calibration failed. Detector at Acq status");
  908. }
  909. return ret;
  910. }
  911. if (m_CalibUnit->GetCalibrationStatus() == CCOS_CALIBRATION_STATUS_RUNNING)
  912. {
  913. //printf(("Detector already at calib status.\n");
  914. //mLog::Error("Detector already at calib status");
  915. return ret;
  916. }
  917. if (g_pDetector->StartCalibration(this))
  918. {
  919. m_DetectorCtrlUnit->SetDetectorStatus(DETECTOR_STATUS_ACQ);
  920. m_CalibUnit->SetCalibrationStatus(CCOS_CALIBRATION_STATUS_RUNNING);
  921. ret = RET_STATUS::RET_SUCCEED;
  922. }
  923. else
  924. {
  925. //mLog::Error("Start calibration failed");
  926. }
  927. //mLog::Info("StartCalibration over");
  928. return ret;
  929. }
  930. RET_STATUS nsFPD::FPDDeviceTeledyneDalsa::StopCalibration()
  931. {
  932. printf("--Func-- StopCalibration \r\n");
  933. //mLog::Info("--Func-- StopCalibration");
  934. RET_STATUS ret = RET_STATUS::RET_FAILED;
  935. if (!m_bConnect)
  936. {
  937. //mLog::Error("Detector not connected, return");
  938. return ret;
  939. }
  940. if (g_pDetector->StopCalibration(this))
  941. {
  942. ret = RET_STATUS::RET_SUCCEED;
  943. m_CalibUnit->SetCalibrationStatus(CCOS_CALIBRATION_STATUS_STANDBY);
  944. m_CalibUnit->SetCalibrationProgress(100);
  945. }
  946. else
  947. {
  948. //mLog::Error("Start calibration failed");
  949. }
  950. //mLog::Info("StopCalibration over");
  951. return ret;
  952. }
  953. bool nsFPD::FPDDeviceTeledyneDalsa::Support_DarkCalib()
  954. {
  955. return true;
  956. }
  957. bool nsFPD::FPDDeviceTeledyneDalsa::Support_XrayCalib()
  958. {
  959. return true;
  960. }
  961. void nsFPD::FPDDeviceTeledyneDalsa::RegisterCtrl(nsDetail::Dispatch* Dispatch)
  962. {
  963. //Dispatch->Get.Push(ActionKey::GetDetectorInfo, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDetectorInfo);
  964. Dispatch->Action.Push("ActiveDetector", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSActiveDetector);
  965. //Dispatch->Action.Push("RESET", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSRESET);
  966. Dispatch->Action.Push("EnterExam", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSEnterExam);
  967. Dispatch->Action.Push("ExitExam", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSExitExam);
  968. //Dispatch->Action.Push("AttachConnect", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSAttachConnect);
  969. //Dispatch->Action.Push("CancelAttach", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSCancelAttach);
  970. //Dispatch->Action.Push("RecoverImage", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSRecoverImage);
  971. //Dispatch->Action.Push("ResetConnect", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSResetConnect);
  972. //Dispatch->Action.Push("DisConnectFPD", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSDisConnectFPD);
  973. //Dispatch->Action.Push("UpdateFirmware", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSUpdateFirmware);
  974. //Dispatch->Action.Push("SaveSensitivity", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSSaveSensitivity);
  975. Dispatch->Get.Push(CcosDetectorStatus, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetFPDStatus);
  976. //Dispatch->Get.Push(CcosDetectorConnectStatus, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetConnectStatus);
  977. //Dispatch->Get.Push(CcosDetectorAttach, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetAttachResult);
  978. //Dispatch->Get.Push(CcosDetectorAttachedFlag, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetAttachStatus);
  979. //Dispatch->Get.Push(CcosDetectorInitialStatus, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetAttachStatus);
  980. //Dispatch->Get.Push(CcosDetectorUpdateFWStatus, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetUpdateFWStatus);
  981. //Dispatch->Get.Push("FPDShockSensorInfo", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetShockSensorInfo);
  982. //Dispatch->Get.Push("FieldofViewShape", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetFieldofViewShape);
  983. //Dispatch->Get.Push("FieldofViewDimension", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetFieldofViewDimension);
  984. Dispatch->Get.Push("DetectorType", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDetectorType);
  985. Dispatch->Get.Push("Description", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDescription);
  986. Dispatch->Get.Push("DetectorID", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDetectorID);
  987. //Dispatch->Get.Push("DateofLastDetectorCalibration", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDateofLastDetectorCalibration);
  988. //Dispatch->Get.Push("TimeofLastDetectorCalibration", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetTimeofLastDetectorCalibration);
  989. //Dispatch->Get.Push("DetectorConditionsNominalFlag", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDetectorConditionsNominalFlag);
  990. Dispatch->Get.Push("FPDSensitivity", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetFPDSensitivity);
  991. Dispatch->Get.Push("PixelData", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetPixelData);
  992. Dispatch->Get.Push("TargetEXI", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetTargetEXI);
  993. Dispatch->Action.Push("SetXrayOnNum", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSSetXrayOnNum);
  994. Dispatch->Action.Push("SetExposureTimes", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSSetExposureTimes);
  995. }
  996. void nsFPD::FPDDeviceTeledyneDalsa::RegisterAcq(nsDetail::Dispatch* Dispatch)
  997. {
  998. Dispatch->Action.Push("SetAcqMode", m_AcqUnit.get(), &AcqUnit::JSSetAcqMode);
  999. Dispatch->Get.Push(CcosZskkFPDState, m_AcqUnit.get(), &AcqUnit::JSGetZskkFPDState);
  1000. Dispatch->Get.Push("NoNeedWaitImage", m_AcqUnit.get(), &AcqUnit::JSGetNoNeedWaitImage);
  1001. Dispatch->Get.Push("ImgDataInfo", m_AcqUnit.get(), &AcqUnit::JSGetLastImage);
  1002. }
  1003. void nsFPD::FPDDeviceTeledyneDalsa::RegisterSync(nsDetail::Dispatch* Dispatch)
  1004. {
  1005. Dispatch->Action.Push("SetSyncMode", m_SyncUnit.get(), &SyncUnit::JSSetSyncMode);
  1006. Dispatch->Action.Push("SetXwindowSize", m_SyncUnit.get(), &SyncUnit::JSSetXwindowSize);
  1007. Dispatch->Action.Push("PrepareAcquisition", m_SyncUnit.get(), &SyncUnit::JSPrepareAcquisition);
  1008. Dispatch->Action.Push("StartAcquisition", m_SyncUnit.get(), &SyncUnit::JSStartAcquisition);
  1009. Dispatch->Action.Push("StopAcquisition", m_SyncUnit.get(), &SyncUnit::JSStopAcquisition);
  1010. Dispatch->Get.Push(CcosFPDReadyStatus, m_SyncUnit.get(), &SyncUnit::JSGetFPDReady);
  1011. Dispatch->Get.Push(CcosXwindowStatus, m_SyncUnit.get(), &SyncUnit::JSGetXWindowStatus);
  1012. Dispatch->Get.Push(CcosImageReadingStatus, m_SyncUnit.get(), &SyncUnit::JSGetImageReadingStatus);
  1013. }
  1014. void nsFPD::FPDDeviceTeledyneDalsa::RegisterCalib(nsDetail::Dispatch* Dispatch)
  1015. {
  1016. //Dispatch->Action.Push("UploadCalibrationFiles", m_CalibUnit.get(), &CalibUnit::JSUploadCalibrationFiles);
  1017. //Dispatch->Action.Push("SetSID", m_CalibUnit.get(), &CalibUnit::JSSetSID);
  1018. Dispatch->Action.Push("ActiveCalibration", m_CalibUnit.get(), &CalibUnit::JSActiveCalibration);
  1019. Dispatch->Action.Push("GetRequestedDose", m_CalibUnit.get(), &CalibUnit::JSGetRequestedDose);
  1020. Dispatch->Action.Push("PrepareCalibration", m_CalibUnit.get(), &CalibUnit::JSPrepareCalibration);
  1021. Dispatch->Action.Push("StartCalibration", m_CalibUnit.get(), &CalibUnit::JSStartCalibration);
  1022. Dispatch->Action.Push("StopCalibration", m_CalibUnit.get(), &CalibUnit::JSStopCalibration);
  1023. Dispatch->Action.Push("SetCorrectionType", m_CalibUnit.get(), &CalibUnit::JSSetCorrectionType);
  1024. Dispatch->Get.Push(AttrKey::CalibrationStatus, m_CalibUnit.get(), &CalibUnit::JSGetCalibStatus);
  1025. Dispatch->Get.Push(AttrKey::CalibrationProgress, m_CalibUnit.get(), &CalibUnit::JSGetCalibProgress);
  1026. Dispatch->Get.Push("UploadCalibrationFilesResult", m_CalibUnit.get(), &CalibUnit::JSGetUploadCalibrationFilesResult);
  1027. Dispatch->Get.Push("SupportCalibrationType", m_CalibUnit.get(), &CalibUnit::JSGetSupportCalibrationType);
  1028. }
  1029. void nsFPD::FPDDeviceTeledyneDalsa::OnFPDCallback(int nDetectorID, int nEventID, int nEventLevel,
  1030. const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1031. {
  1032. switch (nEventLevel)
  1033. {
  1034. case EVT_LEVEL_CONFIGURATION:
  1035. {
  1036. OnEventProcessConf(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1037. break;
  1038. }
  1039. case EVT_LEVEL_INFORMATOION:
  1040. {
  1041. OnEventProcessInfo(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1042. break;
  1043. }
  1044. case EVT_LEVEL_STATUS:
  1045. {
  1046. OnEventProcessStatus(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1047. break;
  1048. }
  1049. case EVT_LEVEL_DATA:
  1050. {
  1051. OnEventProcessData(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1052. break;
  1053. }
  1054. case EVT_LEVEL_WARNING:
  1055. {
  1056. OnEventProcessWarning(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1057. break;
  1058. }
  1059. case EVT_LEVEL_ERROR:
  1060. {
  1061. OnEventProcessError(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1062. break;
  1063. }
  1064. default:
  1065. break;
  1066. }
  1067. }
  1068. void nsFPD::FPDDeviceTeledyneDalsa::OnEventProcessConf(int nDetectorID, int nEventID, int nEventLevel,
  1069. const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1070. {
  1071. //mLog::Warn("Not support this conf({$})", nEventID);
  1072. }
  1073. void nsFPD::FPDDeviceTeledyneDalsa::OnEventProcessInfo(int nDetectorID, int nEventID, int nEventLevel,
  1074. const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1075. {
  1076. //mLog::Warn("Not support this info({$})", nEventID);
  1077. }
  1078. void nsFPD::FPDDeviceTeledyneDalsa::OnEventProcessStatus(int nDetectorID, int nEventID, int nEventLevel,
  1079. const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1080. {
  1081. switch (nEventID)
  1082. {
  1083. case EVT_STATUS_PANEL:
  1084. {
  1085. ENUM_PANEL_STATUS ePanelStatus = (ENUM_PANEL_STATUS)nParam1;
  1086. if (PANEL_END_ACQ == nParam1)
  1087. {
  1088. //mLog::Info("Panel Status: End acq");
  1089. if (g_pDetector->StopAcquisition(this))
  1090. {
  1091. m_DetectorCtrlUnit->SetDetectorStatus(DETECTOR_STATUS_STANDBY);
  1092. }
  1093. }
  1094. /*else if (PANEL_READY_EXP == nParam1)
  1095. {
  1096. //mLog::Info("Panel Status:READY");
  1097. ((OemSync*)m_pSync)->FPDReadyNotify();
  1098. }*/
  1099. else if (PANEL_XWINDOW_ON == nParam1) //Xwindow On
  1100. {
  1101. //mLog::Info("XWindowOnNotify");
  1102. m_SyncUnit->XWindowOnNotify();
  1103. }
  1104. else if (PANEL_XWINDOW_OFF == nParam1) // Xwindow Off
  1105. {
  1106. //mLog::Info("XWindowOffNotify");
  1107. m_SyncUnit->XWindowOffNotify();
  1108. }
  1109. }
  1110. break;
  1111. case EVT_STATUS_CALIBRATIOIN:
  1112. {
  1113. ENUM_PANEL_EVENT_STATE eStatus = (ENUM_PANEL_EVENT_STATE)nParam1;
  1114. switch (eStatus)
  1115. {
  1116. case PANEL_EVENT_START:
  1117. break;
  1118. case PANEL_EVENT_END_OK:
  1119. case PANEL_EVENT_END_ERROR:
  1120. m_DetectorCtrlUnit->SetDetectorStatus(DETECTOR_STATUS_STANDBY);
  1121. m_CalibUnit->SetCalibrationStatus(CCOS_CALIBRATION_STATUS_STANDBY);
  1122. m_CalibUnit->SetCalibrationProgress(100);//make progress
  1123. break;
  1124. case PANEL_EVENT_TIMEOUT:
  1125. break;
  1126. default:
  1127. break;
  1128. }
  1129. }
  1130. break;
  1131. //case EVT_STATUS_SINGLEEXP:
  1132. //{
  1133. // if (DOSE_ACCEPT == nParam1)
  1134. // {
  1135. // //mLog::Info("Calibration Result is acceptable");
  1136. // SetEvent(m_hPauseCaliEvt);
  1137. // }
  1138. // else
  1139. // {
  1140. // //mLog::Warn("Not support this param(%d)", nParam1);
  1141. // }
  1142. //}
  1143. //break;
  1144. //case EVT_STATUS_TEMPERATURE:
  1145. //{
  1146. // float fTemperature = fParam2;
  1147. // if (fTemperature > m_fTemperMaxLimit)
  1148. // {
  1149. // AddErrMsg("14", "temperature_toohigh");
  1150. // }
  1151. // else if (fTemperature >= m_fTemperWarning)
  1152. // {
  1153. // AddWarnMsg("14", "temperature_high");
  1154. // }
  1155. // else if (fTemperature < m_fTemperMinLimit)
  1156. // {
  1157. // AddErrMsg("14", "temperature_toolow");
  1158. // }
  1159. // else if (fTemperature <= m_fTemperLowLimit)
  1160. // {
  1161. // AddWarnMsg("14", "temperature_low");
  1162. // }
  1163. // else
  1164. // {
  1165. // DelErrMsg("14");
  1166. // }
  1167. // SendTemperatureValue(fTemperature);
  1168. //}
  1169. //break;
  1170. //case EVT_STATUS_WIFI:
  1171. //{
  1172. // int nWifiLevel = nParam1;
  1173. // if (nWifiLevel < m_nWifiLimit)
  1174. // {
  1175. // AddErrMsg("15", "wifi_toolow");
  1176. // }
  1177. // else if (nWifiLevel <= m_nWifiWarning)
  1178. // {
  1179. // AddWarnMsg("15", "wifi_low");
  1180. // }
  1181. // else
  1182. // {
  1183. // DelErrMsg("15");
  1184. // }
  1185. // SendWifiValue(nWifiLevel);
  1186. //}
  1187. //break;
  1188. //case EVT_STATUS_BATTERY_VALUE:
  1189. //{
  1190. // int nBatteryValue = nParam1;
  1191. // if (nBatteryValue < m_nBatteryLimit)
  1192. // {
  1193. // AddErrMsg("16", "battery_toolow");
  1194. // }
  1195. // else if (nBatteryValue <= m_nBatteryWarning)
  1196. // {
  1197. // AddWarnMsg("16", "battery_low");
  1198. // }
  1199. // else
  1200. // {
  1201. // DelErrMsg("16");
  1202. // }
  1203. // SendBatteryValue(nBatteryValue);
  1204. //}
  1205. //break;
  1206. default:
  1207. //mLog::Warn("Not support this status({$})", nEventID);
  1208. break;
  1209. }
  1210. }
  1211. void nsFPD::FPDDeviceTeledyneDalsa::OnEventProcessData(int nDetectorID, int nEventID, int nEventLevel,
  1212. const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1213. {
  1214. switch (nEventID)
  1215. {
  1216. case EVT_DATA_RAW_IMAGE:
  1217. {
  1218. //m_SyncUnit->XWindowOnNotify(); //add20220111 模拟发送窗口消息,使状态机可以跳转状态
  1219. //mLog::Info("Image Arrived");
  1220. memcpy(m_pImgBuffer, pParam, (size_t)m_nImageWidth * (size_t)m_nImageHeight * sizeof(WORD));
  1221. //暂时先用假值,有需要再改
  1222. SYSTEMTIME stImgCreateTime = { 0 };
  1223. GetLocalTime(&stImgCreateTime);
  1224. ResDataObject objImageHead, objTemp;
  1225. objTemp.add(SM_IMAGE_TYPE, (int)IMAGE_FULL);
  1226. objTemp.add(SM_IMAGE_BIT, 16);
  1227. objTemp.add(SM_IMAGE_TAG, 1);
  1228. objTemp.add(SM_IMAGE_INDEX, 1);
  1229. objTemp.add(SM_IMAGE_YEAR, stImgCreateTime.wYear);
  1230. objTemp.add(SM_IMAGE_MONTH, stImgCreateTime.wMonth);
  1231. objTemp.add(SM_IMAGE_DAY, stImgCreateTime.wDay);
  1232. objTemp.add(SM_IMAGE_HOUR, stImgCreateTime.wHour);
  1233. objTemp.add(SM_IMAGE_MINUTE, stImgCreateTime.wMinute);
  1234. objTemp.add(SM_IMAGE_SEC, stImgCreateTime.wSecond);
  1235. objTemp.add(SM_IMAGE_MILLSEC, stImgCreateTime.wMilliseconds);
  1236. objTemp.add(SM_IMAGE_LSB, "5000");
  1237. objTemp.add(SM_IMAGE_DOSE, m_nSensitivity);
  1238. objTemp.add(SM_IMAGE_PIXELSPACING, m_nPixelSpacing);
  1239. objTemp.add(SM_IMAGE_PIXELREPRESENTATION, "1");
  1240. objTemp.add(SM_IMAGE_FLIP, "No");
  1241. objTemp.add(SM_IMAGE_ORIGINX, "0");
  1242. objTemp.add(SM_IMAGE_ORIGINY, "0");
  1243. m_AcqUnit->RotateImage(m_pImgBuffer, m_nImageHeight, m_nImageWidth, m_nAngle);
  1244. if (90 == m_nAngle || 270 == m_nAngle)
  1245. {
  1246. objTemp.add(SM_IMAGE_WIDTH, m_nImageHeight);
  1247. objTemp.add(SM_IMAGE_HEIGHT, m_nImageWidth);
  1248. objTemp.add(SM_IMAGE_ROTATION, "Yes");
  1249. }
  1250. else
  1251. {
  1252. objTemp.add(SM_IMAGE_WIDTH, m_nImageWidth);
  1253. objTemp.add(SM_IMAGE_HEIGHT, m_nImageHeight);
  1254. objTemp.add(SM_IMAGE_ROTATION, "No");
  1255. }
  1256. objImageHead.add(SM_IMAGE_HEAD, objTemp);
  1257. //mLog::Trace("Full image head: {$}", objImageHead.encode());
  1258. RET_STATUS ret = RET_STATUS::RET_FAILED;
  1259. ret = m_AcqUnit->AddFrameWithRawHead(IMAGE_FULL, objImageHead.encode(), m_pImgBuffer, m_nImageWidth * m_nImageHeight);
  1260. //mLog::Info("Add image over");
  1261. //printf(("Add image over, %d \n", ret);
  1262. m_SyncUnit->XWindowOffNotify(); //add20220111 模拟发送窗口消息,使状态机可以跳转状态
  1263. }
  1264. break;
  1265. default:
  1266. //mLog::Warn("Not support this data({$})", nEventID);
  1267. break;
  1268. }
  1269. }
  1270. void nsFPD::FPDDeviceTeledyneDalsa::OnEventProcessError(int nDetectorID, int nEventID, int nEventLevel,
  1271. const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1272. {
  1273. switch (nEventID)
  1274. {
  1275. case EVT_ERR_COMMUNICATE:
  1276. //{
  1277. // string strTemp = pszMsg;
  1278. // if (strTemp.find("true") != std::string::npos)
  1279. // {
  1280. // AddErrMsg("0", "communication error");
  1281. // SendTemperatureValue(0);
  1282. // SendWifiValue(0);
  1283. // SendBatteryValue(0);
  1284. // }
  1285. // else if (strTemp.find("false") != std::string::npos)
  1286. // {
  1287. // DelErrMsg("0");
  1288. // }
  1289. //}
  1290. break;
  1291. case EVT_ERR_INIT_FAILED:
  1292. //{
  1293. // string strTemp = pszMsg;
  1294. // if (strTemp.find("true") != std::string::npos)
  1295. // {
  1296. // AddErrMsg("6", "initialize error");
  1297. // }
  1298. // else if (strTemp.find("false") != std::string::npos)
  1299. // {
  1300. // //一般不可恢复
  1301. // }
  1302. //}
  1303. break;
  1304. default:
  1305. //mLog::Warn("Not support this error({$})", nEventID);
  1306. break;
  1307. }
  1308. }
  1309. void nsFPD::FPDDeviceTeledyneDalsa::OnEventProcessWarning(int nDetectorID, int nEventID, int nEventLevel,
  1310. const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1311. {
  1312. //mLog::Warn("Not support this warn({$})", nEventID);
  1313. }