DIOS.Dev.Generator.V2Adapter.cpp 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915
  1. // CCOS.Dev.Generator.V2Adapter.cpp : 定义 DLL 应用程序的导出函数。
  2. //
  3. /*
  4. 使用本类注意事项
  5. 1 必须有这样一个配置文件路径 (pGenConfig.Load(strAppPath + "\\V2AdapterDriver\\conf\\GenOprConf.xml")) //GenOprConf.xml中的配置,跟V2 一样。
  6. 2 Device\DriverConfig中的配置文件 应该叫做 V2Adapter.xml 里面的配置。
  7. 3 首先上层createdevice之后,
  8. 4 使用gentest.exe 调试的时候,把所有的依赖都放在了V2AdapterDriver 文件夹中。包含conf,各种v2的dll。以及2.0的adatperx64.dll的各种依赖。
  9. 5 使用dmoc测试时,上层点击时,下层没反应。后来使用ccos-gen-device-test.exe测试的,一切ok。
  10. */
  11. //关闭无关警告
  12. #pragma warning (disable:4244) // warning C4244: “初始化”: 从“double”转换到“float”,可能丢失数据
  13. #pragma warning (disable:4305) // warning C4305: “参数”: 从“double”到“float”截断
  14. #pragma warning (disable:4267) // warning C4267 : “初始化”: 从“size_t”转换到“int”,可能丢失数据
  15. #pragma warning (disable:4805) // warning C4805: “!=”: 在操作中将类型“bool”与类型“int”混合不安全
  16. #include "stdafx.h"
  17. #include <assert.h>
  18. #include <functional>
  19. using namespace std::placeholders;
  20. #include "Helper.JSON.hpp"
  21. #include "scf.define.hpp"
  22. #include "CCOS.Dev.Generator.V2Adapter.h"
  23. using namespace CCOS::Dev::Detail::Generator;
  24. namespace nsGEN = CCOS::Dev::Detail::Generator;
  25. //V2静态头文件
  26. #include "appsettings.h"
  27. #include "markup.h"
  28. #include "GEN_i.h"
  29. #ifdef _WIN64
  30. #ifdef _DEBUG
  31. #pragma comment(lib, "GenOpr64.lib")
  32. //#pragma comment(lib, "DapOpr64.lib")
  33. //#pragma comment(lib, "SPROMEPS.LIB")
  34. #else
  35. #pragma comment(lib, "GenOpr64.lib")
  36. //#pragma comment(lib, "DapOpr64.lib")
  37. #endif
  38. #else
  39. #ifdef _DEBUG
  40. #pragma comment(lib, "GenOpr.lib")
  41. //#pragma comment(lib, "DapOpr.lib")
  42. #else
  43. #pragma comment(lib, "GenOpr.lib")
  44. //#pragma comment(lib, "DapOpr.lib")
  45. #endif
  46. #endif
  47. using namespace CCOS::Dev::Detail::Generator;
  48. namespace nsGEN = CCOS::Dev::Detail::Generator;
  49. Log4CPP::Logger* mLog::gLogger = nullptr;
  50. //device-----------------------------------------
  51. V2AdapterDevice::V2AdapterDevice(std::shared_ptr <IOEventCenter> center, UIObject* UIobj) : super(center)
  52. {
  53. mLog::Debug("Enter [{$}]", __FUNCTION__);
  54. string version;
  55. if (GetVersion(version, hMyModule))
  56. mLog::Debug("\n===============log begin : version:{$} ===================\n", version.c_str());
  57. else
  58. mLog::Debug("\n===============log begin : version:0.0.0.0 ===================\n");
  59. m_pUIOBJ = UIobj;
  60. m_bGenConnectState = false;
  61. m_bGetDensity = true;
  62. //设置发生器属性集合各个值的范围及精度
  63. m_DoseUnit.m_KV.reset(new KVMould(0.0, 0.0, 150.0, 1.0));
  64. m_DoseUnit.m_MA.reset(new MAMould(0.0, 0.0, 1000.0, 1.0));
  65. m_DoseUnit.m_MS.reset(new MSMould(0.0, 0.0, 10000.0, 1.0));
  66. m_DoseUnit.m_MAS.reset(new MASMould(0.0, 0.0, 1000.0, 1.0));
  67. m_DoseUnit.m_Techmode.reset(new TECHMODEMould(AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P, AttrKey::TECHMODE_NOAEC_3P, AttrKey::TECHMODE_AEC_MAS_MA, 1));
  68. m_DoseUnit.m_WS.reset(new WORKSTATIONMould(AttrKey::WALL, AttrKey::TABLE, AttrKey::FREE_WALL, 1));
  69. m_DoseUnit.m_Focus.reset(new FOCUSMould(AttrKey::FOCUS_SMALL, AttrKey::FOCUS_SMALL, AttrKey::FOCUS_AUTOMATIC, 1));
  70. m_DoseUnit.m_AECField.reset(new AECFIELDMould(0, 0, 111, 1));
  71. m_DoseUnit.m_AECFilm.reset(new AECFILMMould(0, 0, 2, 1));
  72. m_DoseUnit.m_AECDensity.reset(new AECDENSITYMould(0, -4, 4, 1));
  73. m_DoseUnit.m_HE.reset(new TUBEHEATMould(0, 0, 100, 1));
  74. m_DoseUnit.m_GenSynState.reset(new GENSYNSTATEMould(AttrKey::GENERATOR_RAD_OFF, AttrKey::GENERATOR_SYNC_ERR, AttrKey::GENERATOR_SYNC_MAX, 1));
  75. m_DoseUnit.m_GenState.reset(new GENSTATEMould(0, AttrKey::GENERATOR_STATUS_SHUTDOWN, AttrKey::GENERATOR_STATUS_MAX, 1));
  76. m_DoseUnit.m_GenTotalExpNumber.reset(new TOTALEXPNUMMould(0, 0, 9999, 1));
  77. m_DoseUnit.m_GenTotalAcqTimes.reset(new TOTALACQTIMESMould(0, 0, 9999, 1));
  78. m_DoseUnit.m_GenTubeCoolWaitTimes.reset(new TUBECOOLTIMEMould(0, 0, 9999, 1));
  79. m_DoseUnit.m_GenTubeOverLoadNumber.reset(new TUBEOVERLOADNUMMould(0, 0, 9999, 1));
  80. m_DoseUnit.m_GenCurrentExpNumber.reset(new CUREXPNUMMould(0, 0, 9999, 1));
  81. m_DoseUnit.m_ExpMode.reset(new EXPMODEMould(AttrKey::EXPMODE_TYPE::Single));
  82. m_DoseUnit.m_FrameRate.reset(new FRAMERATEMould(0, 0, 16, 1));
  83. m_DoseUnit.m_FLMode.reset(new FLUModeMould(AttrKey::GENERATOR_FLUMode::GENERATOR_FLMODE_NOTFLU));
  84. m_DoseUnit.m_BatteryChargeState.reset(new BATTERYCHARGSTATEMould(0, 0, 1, 1));
  85. m_DoseUnit.m_TubeTargetMaterial.reset(new TUBETARGETMATERIALMould(AttrKey::TUBETARGETMATERIAL_TYPE::MO));
  86. m_DoseUnit.m_TubeAngle.reset(new TUBEANGLEMould(0, -45, 45, 1));
  87. //实际曝光参数值
  88. m_DoseUnit.m_PostKV.reset(new POSTKVMould(0.0, 0.0, 150.0, 1.0));
  89. m_DoseUnit.m_PostMA.reset(new POSTMAMould(0.0, 0.0, 1000.0, 1));
  90. m_DoseUnit.m_PostMS.reset(new POSTMSMould(0.0, 0.0, 10000.0, 1));
  91. m_DoseUnit.m_PostMAS.reset(new POSTMASMould(0.0, 0.5, 1000.0, 1));
  92. //发生器告警及错误消息
  93. m_MSGUnit.reset(new nsDetail::MSGUnit(center, nsGEN::GeneratorUnitType));
  94. //DAP参数上报
  95. m_DAP.reset(new DevDAP::DOSEMould(0.0, 0.0, 1000.0, 0.01));
  96. OnRegister();
  97. m_pUIOBJ->Init(this,OnCallBack);
  98. mLog::Info("init:GENSTATE STATUS_SHUTDOWN -> STATUS_STANDBY");
  99. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
  100. Sleep(1000);
  101. GEN_GetST();
  102. }
  103. V2AdapterDevice::~V2AdapterDevice()
  104. {
  105. mLog::Debug("Enter [{$}]", __FUNCTION__);
  106. m_pUIOBJ->Destrory();
  107. }
  108. std::string nsGEN::V2AdapterDevice::GetGUID() const
  109. {
  110. mLog::Debug("Enter [{$}]", __FUNCTION__);
  111. mLog::Debug("\n===============GetGUID : [{$}] ===================", GeneratorUnitType);
  112. return GeneratorUnitType;
  113. }
  114. void nsGEN::V2AdapterDevice::OnRegister()
  115. {
  116. mLog::Debug("Enter [{$}]", __FUNCTION__);
  117. auto Disp = &Dispatch;
  118. superGen::Register(Disp);
  119. superGen::RegisterRAD(Disp);
  120. superGen::RegisterAEC(Disp);
  121. superGen::RegisterExpEnable(Disp);
  122. superGen::RegisterGeneratortoSyncStatus(Disp);
  123. Disp->Get.Push(m_MSGUnit->GetKey().c_str(), [this](std::string& out) { out = m_MSGUnit->JSGet(); return RET_STATUS::RET_SUCCEED; });
  124. auto fun_Clear_DAP = [this](auto a, auto&)
  125. {
  126. return Clear_DAP();
  127. };
  128. Disp->Action.Push("Clear_DAP", fun_Clear_DAP);
  129. auto fun_GetValue_DAP = [this](auto a, auto& b)
  130. {
  131. float value = 0;
  132. RET_STATUS ret = GetValue_DAP(value);
  133. b = ToJSON(value);
  134. return ret;
  135. };
  136. Disp->Action.Push("GetValue_DAP", fun_GetValue_DAP);
  137. }
  138. void nsGEN::V2AdapterDevice::FireNotify(std::string key, std::string content)
  139. {
  140. EventCenter->OnNotify(1, key, content);
  141. }
  142. RET_STATUS nsGEN::V2AdapterDevice::IncKV()
  143. {
  144. mLog::Debug("Enter [{$}]", __FUNCTION__);
  145. if (!m_DoseUnit.m_KV->CanInc()) return RET_STATUS::RET_SUCCEED;
  146. if (GEN_INCKV())
  147. {
  148. mLog::Debug("GEN_INCKV Succeed");
  149. return RET_STATUS::RET_SUCCEED;
  150. }
  151. return RET_STATUS::RET_FAILED;
  152. }
  153. RET_STATUS nsGEN::V2AdapterDevice::DecKV()
  154. {
  155. mLog::Debug("Enter [{$}]", __FUNCTION__);
  156. if (!m_DoseUnit.m_KV->CanDec()) return RET_STATUS::RET_SUCCEED;
  157. if (GEN_DECKV())
  158. {
  159. mLog::Debug("GEN_DECKV Succeed");
  160. return RET_STATUS::RET_SUCCEED;
  161. }
  162. return RET_STATUS::RET_FAILED;
  163. }
  164. RET_STATUS nsGEN::V2AdapterDevice::SetKV(float value)
  165. {
  166. mLog::Debug("Enter [{$}]:[{$}]", __FUNCTION__, value);
  167. if (!m_DoseUnit.m_KV->Verify(value)) return RET_STATUS::RET_SUCCEED;
  168. if ( GEN_SetKV(value))
  169. {
  170. mLog::Debug("GEN_SetKV Succeed[{$}]", value);
  171. return RET_STATUS::RET_SUCCEED;
  172. }
  173. return RET_STATUS::RET_FAILED;
  174. }
  175. RET_STATUS nsGEN::V2AdapterDevice::IncMA()
  176. {
  177. mLog::Debug("Enter [{$}]", __FUNCTION__);
  178. if (!m_DoseUnit.m_MA->CanInc()) return RET_STATUS::RET_SUCCEED;
  179. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  180. {
  181. mLog::Debug("Techmode is MAS, can't inc MA");
  182. return RET_STATUS::RET_FAILED;
  183. }
  184. if (GEN_INCMA())
  185. {
  186. mLog::Debug("GEN_INCMA Succeed");
  187. return RET_STATUS::RET_SUCCEED;
  188. }
  189. return RET_STATUS::RET_FAILED;
  190. }
  191. RET_STATUS nsGEN::V2AdapterDevice::DecMA()
  192. {
  193. mLog::Debug("Enter [{$}]", __FUNCTION__);
  194. if (!m_DoseUnit.m_MA->CanDec()) return RET_STATUS::RET_SUCCEED;
  195. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  196. {
  197. mLog::Debug("Techmode is MAS, can't dec MA");
  198. return RET_STATUS::RET_FAILED;
  199. }
  200. if (GEN_DECMA())
  201. {
  202. mLog::Debug("GEN_DECMA Succeed");
  203. return RET_STATUS::RET_SUCCEED;
  204. }
  205. return RET_STATUS::RET_FAILED;
  206. }
  207. RET_STATUS nsGEN::V2AdapterDevice::SetMA(float value)
  208. {
  209. mLog::Debug("Enter [{$}]:[{$}]", __FUNCTION__, value);
  210. if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
  211. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  212. {
  213. mLog::Debug("Techmode is MAS, can't set MA");
  214. return RET_STATUS::RET_FAILED;
  215. }
  216. if (GEN_SetMA(value))
  217. {
  218. mLog::Debug("GEN_SetMA Succeed[{$}]", value);
  219. return RET_STATUS::RET_SUCCEED;
  220. }
  221. return RET_STATUS::RET_FAILED;
  222. }
  223. RET_STATUS nsGEN::V2AdapterDevice::IncMS()
  224. {
  225. mLog::Debug("Enter [{$}]", __FUNCTION__);
  226. if (!m_DoseUnit.m_MS->CanInc()) return RET_STATUS::RET_SUCCEED;
  227. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  228. {
  229. mLog::Debug("Techmode is MAS, can't inc MS");
  230. return RET_STATUS::RET_FAILED;
  231. }
  232. if ( GEN_INCMS())
  233. {
  234. mLog::Debug("GEN_INCMS Succeed");
  235. return RET_STATUS::RET_SUCCEED;
  236. }
  237. return RET_STATUS::RET_FAILED;
  238. }
  239. RET_STATUS nsGEN::V2AdapterDevice::DecMS()
  240. {
  241. mLog::Debug("Enter [{$}]", __FUNCTION__);
  242. if (!m_DoseUnit.m_MS->CanDec()) return RET_STATUS::RET_SUCCEED;
  243. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  244. {
  245. mLog::Debug("Techmode is MAS, can't dec MS");
  246. return RET_STATUS::RET_FAILED;
  247. }
  248. if (GEN_DECMS())
  249. {
  250. mLog::Debug("GEN_DECMS Succeed");
  251. return RET_STATUS::RET_SUCCEED;
  252. }
  253. return RET_STATUS::RET_FAILED;
  254. }
  255. RET_STATUS nsGEN::V2AdapterDevice::SetMS(float value)
  256. {
  257. mLog::Debug("Enter [{$}]:[{$}]", __FUNCTION__, value);
  258. if (!m_DoseUnit.m_MS->Verify(value)) return RET_STATUS::RET_SUCCEED;
  259. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  260. {
  261. mLog::Debug("Techmode is MAS, can't set MS");
  262. return RET_STATUS::RET_FAILED;
  263. }
  264. if (GEN_SetMS(value))
  265. {
  266. mLog::Debug("GEN_SetMS Succeed[{$}]", value);
  267. return RET_STATUS::RET_SUCCEED;
  268. }
  269. return RET_STATUS::RET_FAILED;
  270. }
  271. RET_STATUS nsGEN::V2AdapterDevice::IncMAS()
  272. {
  273. mLog::Debug("Enter [{$}]", __FUNCTION__);
  274. if (!m_DoseUnit.m_MAS->CanInc()) return RET_STATUS::RET_SUCCEED;
  275. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS)
  276. {
  277. mLog::Debug("Techmode is not MAS, can't inc MAS");
  278. return RET_STATUS::RET_FAILED;
  279. }
  280. if ( GEN_INCMAS())
  281. {
  282. mLog::Debug("GEN_INCMAS Succeed");
  283. return RET_STATUS::RET_SUCCEED;
  284. }
  285. return RET_STATUS::RET_FAILED;
  286. }
  287. RET_STATUS nsGEN::V2AdapterDevice::DecMAS()
  288. {
  289. mLog::Debug("Enter [{$}]", __FUNCTION__);
  290. if (!m_DoseUnit.m_MAS->CanDec()) return RET_STATUS::RET_SUCCEED;
  291. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS)
  292. {
  293. mLog::Debug("Techmode is not MAS, can't dec MAS");
  294. return RET_STATUS::RET_FAILED;
  295. }
  296. if (GEN_DECMAS())
  297. {
  298. mLog::Debug("GEN_DECMAS Succeed");
  299. return RET_STATUS::RET_SUCCEED;
  300. }
  301. return RET_STATUS::RET_FAILED;
  302. }
  303. RET_STATUS nsGEN::V2AdapterDevice::SetMAS(float value)
  304. {
  305. mLog::Debug("Enter [{$}]:[{$}]", __FUNCTION__, value);
  306. if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
  307. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS)
  308. {
  309. mLog::Debug("Techmode is not MAS, can't set MAS");
  310. return RET_STATUS::RET_FAILED;
  311. }
  312. if (GEN_SetMAS(value))
  313. {
  314. mLog::Debug("GEN_SetMAS Succeed[{$}]", value);
  315. return RET_STATUS::RET_SUCCEED;
  316. }
  317. return RET_STATUS::RET_FAILED;
  318. }
  319. RET_STATUS nsGEN::V2AdapterDevice::SetTechmode(int techmode)
  320. {
  321. mLog::Debug("Enter [{$}]:[{$}]", __FUNCTION__, techmode);
  322. if (!m_DoseUnit.m_Techmode->Verify(techmode)) return RET_STATUS::RET_SUCCEED;
  323. if (GEN_SetTechMode(techmode))
  324. {
  325. mLog::Debug("GEN_SetTechMode Succeed");
  326. return RET_STATUS::RET_SUCCEED;
  327. }
  328. return RET_STATUS::RET_FAILED;
  329. }
  330. RET_STATUS nsGEN::V2AdapterDevice::SetFocus(int value)
  331. {
  332. mLog::Debug("Enter [{$}]:[{$}]", __FUNCTION__,value);
  333. if (!m_DoseUnit.m_Focus->Verify(value)) return RET_STATUS::RET_SUCCEED;
  334. if (GEN_SetFocusSel(value))
  335. {
  336. mLog::Debug("GEN_SetFocusSel Succeed");
  337. return RET_STATUS::RET_SUCCEED;
  338. }
  339. return RET_STATUS::RET_FAILED;
  340. }
  341. RET_STATUS nsGEN::V2AdapterDevice::SetAECDensity(int value)
  342. {
  343. mLog::Debug("Enter [{$}]:[{$}]", __FUNCTION__, value);
  344. if (!m_DoseUnit.m_AECDensity->Verify(value)) return RET_STATUS::RET_SUCCEED;
  345. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_AEC)
  346. {
  347. mLog::Debug("Techmode is not AEC, can't set AECDensity");
  348. return RET_STATUS::RET_FAILED;
  349. }
  350. if (GEN_SetAECDensity(value))
  351. {
  352. mLog::Debug("GEN_SetAECDensity Succeed[{$}]", value);
  353. return RET_STATUS::RET_SUCCEED;
  354. }
  355. return RET_STATUS::RET_FAILED;
  356. }
  357. RET_STATUS nsGEN::V2AdapterDevice::SetAECField(int value)
  358. {
  359. mLog::Debug("Enter [{$}]:[{$}]", __FUNCTION__,value);
  360. if (!m_DoseUnit.m_AECField->Verify(value)) return RET_STATUS::RET_SUCCEED;
  361. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_AEC)
  362. {
  363. mLog::Debug("Techmode is not AEC, can't set AECField");
  364. return RET_STATUS::RET_FAILED;
  365. }
  366. if (GEN_SetAECField(value))
  367. {
  368. mLog::Debug("GEN_SetAECField Succeed[{$}]", value);
  369. return RET_STATUS::RET_SUCCEED;
  370. }
  371. return RET_STATUS::RET_FAILED;
  372. }
  373. RET_STATUS nsGEN::V2AdapterDevice::SetAECFilm(int value)
  374. {
  375. mLog::Debug("Enter [{$}]:[{$}]", __FUNCTION__, value);
  376. if (!m_DoseUnit.m_AECFilm->Verify(value)) return RET_STATUS::RET_SUCCEED;
  377. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_AEC)
  378. {
  379. mLog::Debug("Techmode is not AEC, can't set AECFilm");
  380. return RET_STATUS::RET_FAILED;
  381. }
  382. if (value == 1)
  383. {
  384. //low
  385. return GEN_SetAECFilm(1) ? RET_STATUS::RET_SUCCEED : RET_STATUS::RET_FAILED;
  386. }
  387. else if (value == 2)
  388. {
  389. //mid
  390. return GEN_SetAECFilm(10) ? RET_STATUS::RET_SUCCEED : RET_STATUS::RET_FAILED;
  391. }
  392. else if (value == 3)
  393. {
  394. //high
  395. return GEN_SetAECFilm(100) ? RET_STATUS::RET_SUCCEED : RET_STATUS::RET_FAILED;
  396. }
  397. else
  398. {
  399. //do nothing...
  400. }
  401. return RET_STATUS::RET_FAILED;
  402. }
  403. RET_STATUS nsGEN::V2AdapterDevice::SetWS(const string value)
  404. {
  405. mLog::Debug("Enter [{$}]:[{$}]", __FUNCTION__,value.c_str());
  406. int tempws = 0;
  407. if (value == "Table") tempws = 0;
  408. else if (value == "Wall") tempws = 1;
  409. else if (value == "Direct") tempws = 2;
  410. else if (value == "Free") tempws = 3;
  411. m_DoseUnit.m_WS->Update(tempws);
  412. if (GEN_SetWorkStation(tempws))
  413. {
  414. mLog::Debug("GEN_SetWorkStation Succeed[{$}]", tempws);
  415. return RET_STATUS::RET_SUCCEED;
  416. }
  417. return RET_STATUS::RET_FAILED;
  418. }
  419. RET_STATUS nsGEN::V2AdapterDevice::SetAPR(const _tAPRArgs& t)
  420. {
  421. mLog::Debug("Enter [{$}]:KV={$},MA={$},MS={$},MAS={$},Focus={$},Techmode={$},WS={$},AECDensity={$},AECField={$},AECFilm={$}",
  422. __FUNCTION__, t.fKV, t.fMA, t.fMS, t.fMAS, t.nFocus, t.nTechmode, t.nWS, t.nAECDensity, t.nAECField, t.nAECFilm);
  423. float Dencity = t.nAECDensity;
  424. float kv = t.fKV;
  425. //正常的版本如下!!!!
  426. INT ws = m_DoseUnit.m_WS->Get();
  427. if (GEN_SetAPR(ws, t.nFocus, t.nTechmode,
  428. t.nAECField, t.nAECFilm, Dencity, kv, t.fMA, t.fMS, t.fMAS))
  429. {
  430. mLog::Debug("SetAPR Succeed");
  431. return RET_STATUS::RET_SUCCEED;
  432. }
  433. mLog::Debug("SetAPR Failed");
  434. return RET_STATUS::RET_FAILED;
  435. }
  436. RET_STATUS nsGEN::V2AdapterDevice::QueryHE(int& value)
  437. {
  438. mLog::Debug("Enter [{$}]", __FUNCTION__);
  439. GEN_GetHE();
  440. return RET_STATUS::RET_SUCCEED;
  441. }
  442. RET_STATUS nsGEN::V2AdapterDevice::QueryPostKV(float& value)
  443. {
  444. mLog::Debug("Enter [{$}]", __FUNCTION__);
  445. value = m_DoseUnit.m_PostKV->Get();
  446. return RET_STATUS::RET_SUCCEED;
  447. }
  448. RET_STATUS nsGEN::V2AdapterDevice::QueryPostMA(float& value)
  449. {
  450. mLog::Debug("Enter [{$}]", __FUNCTION__);
  451. value = m_DoseUnit.m_PostMA->Get();
  452. return RET_STATUS::RET_SUCCEED;
  453. }
  454. RET_STATUS nsGEN::V2AdapterDevice::QueryPostMS(float& value)
  455. {
  456. mLog::Debug("Enter [{$}]", __FUNCTION__);
  457. GEN_GetAT();
  458. value = m_DoseUnit.m_PostMS->Get();
  459. return RET_STATUS::RET_SUCCEED;
  460. }
  461. RET_STATUS nsGEN::V2AdapterDevice::QueryPostMAS(float& value)
  462. {
  463. mLog::Debug("Enter [{$}]", __FUNCTION__);
  464. GEN_GetAP();
  465. value = m_DoseUnit.m_PostMAS->Get();
  466. return RET_STATUS::RET_SUCCEED;
  467. }
  468. RET_STATUS nsGEN::V2AdapterDevice::Clear_DAP()
  469. {
  470. mLog::Debug("Enter [{$}]", __FUNCTION__);
  471. GEN_ClearDAP();
  472. return RET_STATUS::RET_SUCCEED;
  473. }
  474. RET_STATUS nsGEN::V2AdapterDevice::GetValue_DAP(float& value)
  475. {
  476. mLog::Debug("Enter [{$}]", __FUNCTION__);
  477. GEN_GetDAP();
  478. return RET_STATUS::RET_FAILED;
  479. }
  480. RET_STATUS nsGEN::V2AdapterDevice::SetGenSynState(int value)
  481. {
  482. mLog::Debug("Enter [{$}]:do noting", __FUNCTION__);
  483. //if (m_DoseUnit.m_GenSynState->Update(value))
  484. //{
  485. // FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  486. //}
  487. return RET_STATUS::RET_SUCCEED;
  488. }
  489. RET_STATUS nsGEN::V2AdapterDevice::SetGenState(int value)
  490. {
  491. mLog::Debug("Enter [{$}]:do noting", __FUNCTION__);
  492. //if (m_DoseUnit.m_GenState->Update(value))
  493. //{
  494. // FireNotify(m_DoseUnit.m_GenState->GetKey(), m_DoseUnit.m_GenState->JSGet());
  495. //}
  496. return RET_STATUS::RET_SUCCEED;
  497. }
  498. RET_STATUS nsGEN::V2AdapterDevice::SetExpEnable()
  499. {
  500. mLog::Debug("Enter [{$}]", __FUNCTION__);
  501. return GEN_EnableExp() ? RET_STATUS::RET_SUCCEED : RET_STATUS::RET_FAILED;
  502. }
  503. RET_STATUS nsGEN::V2AdapterDevice::SetExpDisable()
  504. {
  505. mLog::Debug("Enter [{$}]", __FUNCTION__);
  506. return GEN_DisableExp() ? RET_STATUS::RET_SUCCEED : RET_STATUS::RET_FAILED;
  507. }
  508. RET_STATUS nsGEN::V2AdapterDevice::Reset()
  509. {
  510. mLog::Debug("Enter [{$}]", __FUNCTION__);
  511. return GEN_SetRE(1) ? RET_STATUS::RET_SUCCEED : RET_STATUS::RET_FAILED;
  512. }
  513. RET_STATUS nsGEN::V2AdapterDevice::SetExpMode(std::string value)
  514. {
  515. mLog::Debug("Enter [{$}]", __FUNCTION__);
  516. if(m_DoseUnit.m_ExpMode->Update(value))
  517. FireNotify(m_DoseUnit.m_ExpMode->GetKey(), m_DoseUnit.m_ExpMode->JSGet());
  518. return RET_STATUS::RET_SUCCEED;
  519. }
  520. RET_STATUS nsGEN::V2AdapterDevice::SetFrameRate(FLOAT frameRate)
  521. {
  522. mLog::Debug("Enter [{$}]:do noting", __FUNCTION__);
  523. if (m_DoseUnit.m_FrameRate->Update(frameRate))
  524. FireNotify(m_DoseUnit.m_FrameRate->GetKey(), m_DoseUnit.m_FrameRate->JSGet());
  525. return RET_STATUS::RET_SUCCEED;
  526. }
  527. RET_STATUS nsGEN::V2AdapterDevice::SetModality(std::string value)
  528. {
  529. mLog::Debug("Enter [{$}]", __FUNCTION__);
  530. if(m_DoseUnit.m_Modality->Update(value))
  531. FireNotify(m_DoseUnit.m_Modality->GetKey(), m_DoseUnit.m_Modality->JSGet());
  532. return RET_STATUS::RET_SUCCEED;
  533. }
  534. RET_STATUS nsGEN::V2AdapterDevice::SetFLFMode(std::string value)
  535. {
  536. mLog::Debug("Enter [{$}]", __FUNCTION__);
  537. int mode = atoi(value.c_str());
  538. if (m_DoseUnit.m_FLMode->Update(mode))
  539. FireNotify(m_DoseUnit.m_FLMode->GetKey(), m_DoseUnit.m_FLMode->JSGet());
  540. return RET_STATUS::RET_SUCCEED;
  541. }
  542. RET_STATUS nsGEN::V2AdapterDevice::SetEXAMMode(std::string value)
  543. {
  544. mLog::Debug("Enter [{$}]", __FUNCTION__);
  545. if (m_DoseUnit.m_ExpMode->Update(value))
  546. FireNotify(m_DoseUnit.m_ExpMode->GetKey(), m_DoseUnit.m_ExpMode->JSGet());
  547. return RET_STATUS::RET_SUCCEED;
  548. }
  549. LRESULT CALLBACK nsGEN::V2AdapterDevice::OnCallBack(void* obj, UINT message, WPARAM wParam, LPARAM lParam)
  550. {
  551. V2AdapterDevice *unit = (V2AdapterDevice*)obj;
  552. if (unit == nullptr)
  553. {
  554. mLog::Info("Enter OnCallBack: V2AdapterDevice is null");
  555. return false;
  556. }
  557. int wmId, wmEvent;
  558. PAINTSTRUCT ps;
  559. HDC hdc;
  560. mLog::Debug("Enter OnCallBack: message[{$}],wParam[{$}],lParam[{$}]", (int)message, (int)wParam, (int)lParam);
  561. switch (message)
  562. {
  563. case WM_COMMAND:
  564. wmId = LOWORD(wParam);
  565. wmEvent = HIWORD(wParam);
  566. // 分析菜单选择:
  567. switch (wmId)
  568. {
  569. case 0:
  570. return DefWindowProc(unit->m_pUIOBJ->GetUI(), message, wParam, lParam);
  571. break;
  572. default:
  573. return DefWindowProc(unit->m_pUIOBJ->GetUI(), message, wParam, lParam);
  574. }
  575. break;
  576. case WM_CREATE:
  577. SetTimer(unit->m_pUIOBJ->GetUI(), 1, 5000, NULL);
  578. break;
  579. case WM_PAINT:
  580. hdc = BeginPaint(unit->m_pUIOBJ->GetUI(), &ps);
  581. // TODO: 在此添加任意绘图代码...
  582. EndPaint(unit->m_pUIOBJ->GetUI(), &ps);
  583. break;
  584. case WM_DESTROY:
  585. KillTimer(unit->m_pUIOBJ->GetUI(), 1);
  586. PostQuitMessage(0);
  587. break;
  588. case MSG_GEN_PARAM:
  589. mLog::Debug("recv MSG_GEN_PARAM into ONGenParam");
  590. return unit->ONGenParam(wParam, lParam);
  591. break;
  592. case MSG_GEN_INFO_DISEXP:
  593. mLog::Debug("recv MSG_GEN_INFO_DISEXP into ONGenExpDisable");
  594. return unit->ONGenExpDisable(wParam, lParam);
  595. break;
  596. case MSG_GEN_EXPOSURE:
  597. mLog::Debug("recv MSG_GEN_EXPOSURE into ONGenExp");
  598. return unit->ONGenExp(wParam, lParam);
  599. break;
  600. case MSG_GEN_ERR:
  601. mLog::Debug("recv MSG_GEN_ERR into ONGenError");
  602. return unit->ONGenError(wParam, lParam);
  603. break;
  604. case MSG_GEN_WARN:
  605. mLog::Debug("recv MSG_GEN_WARN into ONGenWarn");
  606. return unit->ONGenWarn(wParam, lParam);
  607. break;
  608. case WM_TIMER:
  609. mLog::Debug("recv WM_TIMER");
  610. GEN_GetHE();
  611. GEN_GetDAP();
  612. break;
  613. case MSG_SYN_FILTER:
  614. mLog::Debug("recv MSG_SYN_FILTER into MSG_SYN_FILTER");
  615. return unit->ONSyncParam(wParam, lParam);
  616. break;
  617. case MSG_SYN_COLLIMATOR:
  618. mLog::Debug("recv MSG_SYN_COLLIMATOR into ONSyncCollimatorParam");
  619. return unit->ONSyncCollimatorParam(wParam, lParam);
  620. break;
  621. case MSG_SYN_STATUS:
  622. mLog::Debug("recv MSG_SYN_STATUS into ONSyncStatusParam");
  623. return unit->ONSyncStatusParam(wParam, lParam);
  624. break;
  625. case MSG_SYN_GRID:
  626. mLog::Debug("recv MSG_SYN_GRID into ONGridStatusParam");
  627. return unit->ONGridStatusParam(wParam, lParam);
  628. case MSG_SYN_SID:
  629. mLog::Debug("recv MSG_SYN_SID into ONSyncSid");
  630. return unit->ONSyncSid(wParam, lParam);
  631. break;
  632. default:
  633. mLog::Debug("recv [{$}] unknown", (int)message);
  634. return DefWindowProc(unit->m_pUIOBJ->GetUI(), message, wParam, lParam);
  635. }
  636. return 0;
  637. }
  638. LRESULT nsGEN::V2AdapterDevice::ONGridStatusParam(WPARAM wParam, LPARAM lParam)
  639. {
  640. //MechV2 *pMech = GetMech();
  641. //if (pMech == 0)
  642. //{
  643. // mLog::Debug("no device exist on cmd[{$}]", wParam);
  644. // mLog::Debug("no device exist on cmd[{$}]", wParam);
  645. // return 0;
  646. //}
  647. //pMech->MechV2::SetGrid((int)wParam);
  648. return 0;
  649. }
  650. LRESULT nsGEN::V2AdapterDevice::ONSyncSid(WPARAM wParam, LPARAM lParam)
  651. {
  652. //CollimatorLogic *pColi = GetCollimator();
  653. //if (pColi == 0)
  654. //{
  655. // mLog::Debug("no device exist on cmd[{$}]", wParam);
  656. // mLog::Debug("no device exist on cmd[{$}]", wParam);
  657. // return 0;
  658. //}
  659. //WORD sid = (WORD)wParam;
  660. //pColi->CollimatorLogic::SetCollimatorSID(sid);
  661. return 0;
  662. }
  663. LRESULT nsGEN::V2AdapterDevice::ONSyncStatusParam(WPARAM wParam, LPARAM lParam)
  664. {
  665. switch (wParam)
  666. {
  667. case SYN_GEN_PREPARE:
  668. mLog::Debug("Gen EXPO status[RAD_PREPARE] PR1");
  669. if(m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_PREPARE))
  670. FireNotify(AttrKey::GENSYNSTATE, m_DoseUnit.m_GenSynState->JSGet());
  671. break;
  672. case SYN_GEN_READY:
  673. mLog::Debug("Gen EXPO status[RAD_READY] PR2");
  674. if(m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_READY))
  675. FireNotify(AttrKey::GENSYNSTATE, m_DoseUnit.m_GenSynState->JSGet());
  676. break;
  677. case SYN_GEN_OVER:
  678. mLog::Debug("Gen EXPO status[RAD_OFF] PR0");
  679. if(m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF))
  680. FireNotify(AttrKey::GENSYNSTATE, m_DoseUnit.m_GenSynState->JSGet());
  681. GEN_GetAP();
  682. break;
  683. case SYN_GEN_EIPON:
  684. mLog::Debug("Gen EXPO status[XRAYON] XR1");
  685. if(m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON))
  686. FireNotify(AttrKey::GENSYNSTATE, m_DoseUnit.m_GenSynState->JSGet());
  687. break;
  688. case SYN_GEN_EIPOFF:
  689. mLog::Debug("Gen EXPO status[XRAYOFF] XR0");
  690. if(m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYOFF))
  691. FireNotify(AttrKey::GENSYNSTATE, m_DoseUnit.m_GenSynState->JSGet());
  692. break;
  693. default:
  694. mLog::Debug("unknown cmd[{$}]", (int)wParam);
  695. return 0;
  696. break;
  697. }
  698. return 0;
  699. }
  700. LRESULT nsGEN::V2AdapterDevice::ONSyncCollimatorParam(WPARAM wParam, LPARAM lParam)
  701. {
  702. //CollimatorLogic *pDev = GetCollimator();
  703. //if (pDev == 0)
  704. //{
  705. // return 0;
  706. //}
  707. //ECOM_COLLIMATOR_INFO *pInfo = (ECOM_COLLIMATOR_INFO*)wParam;
  708. ////wparam
  709. //pDev->CollimatorLogic::SetCollimatorSize((WORD)pInfo->fWidth, (WORD)pInfo->fHeight);;
  710. return 0;
  711. }
  712. LRESULT nsGEN::V2AdapterDevice::ONSyncParam(WPARAM wParam, LPARAM lParam)
  713. {
  714. //CollimatorLogic *pDev = GetCollimator();
  715. //if (pDev == 0)
  716. //{
  717. // return 0;
  718. //}
  719. ////wparam
  720. //pDev->CollimatorLogic::SetCollimatorFilter((WORD)wParam);
  721. return 0;
  722. }
  723. //MSG_GEN_PARAM
  724. LRESULT nsGEN::V2AdapterDevice::ONGenParam(WPARAM wParam, LPARAM lParam)
  725. {
  726. switch (wParam)
  727. {
  728. case GEN_PARAM_KV:
  729. {
  730. int iKV = (int)lParam;
  731. mLog::Debug("GEN_PARAM_KV[{$}]", iKV);
  732. if (m_DoseUnit.m_KV->Update(iKV))
  733. {
  734. FireNotify(AttrKey::KV, m_DoseUnit.m_KV->JSGet());
  735. mLog::Debug("SetKV OnNotify[{$}]", iKV);
  736. }
  737. break;
  738. }
  739. case GEN_PARAM_KV_V2:
  740. {
  741. float fKV = *(float*)lParam;
  742. mLog::Debug("GEN_PARAM_KV_V2[{$}]", fKV);
  743. if (m_DoseUnit.m_KV->Update(fKV))
  744. {
  745. FireNotify(AttrKey::KV, m_DoseUnit.m_KV->JSGet());
  746. mLog::Debug("SetKV2 OnNotify[{$}]", fKV);
  747. }
  748. break;
  749. }
  750. case GEN_PARAM_AK:
  751. {
  752. float fKV = *(float*)lParam;
  753. mLog::Debug("GEN_PARAM_AK[{$}]", fKV);
  754. if (m_DoseUnit.m_PostKV->Update(fKV))
  755. {
  756. FireNotify(AttrKey::POSTKV, m_DoseUnit.m_PostKV->JSGet());
  757. mLog::Debug("postKV OnNotify[{$}]", fKV);
  758. }
  759. break;
  760. }
  761. case GEN_PARAM_FO:
  762. {
  763. int m_nFocus = (int)lParam;
  764. mLog::Debug("GEN_PARAM_FO[{$}]", m_nFocus);
  765. if (m_nFocus == GEN_SMALL_FOCUS)
  766. {
  767. if (m_DoseUnit.m_Focus->Update(AttrKey::FOCUS_TYPE::FOCUS_SMALL))
  768. {
  769. FireNotify(AttrKey::FOCUS, m_DoseUnit.m_Focus->JSGet());
  770. mLog::Debug("Focus notify[{$}]", m_nFocus);
  771. }
  772. }
  773. else if (m_nFocus == GEN_LARGE_FOCUS)
  774. {
  775. if (m_DoseUnit.m_Focus->Update(AttrKey::FOCUS_TYPE::FOCUS_LARGE))
  776. {
  777. FireNotify(AttrKey::FOCUS, m_DoseUnit.m_Focus->JSGet());
  778. mLog::Debug("Focus notify[{$}]", m_nFocus);
  779. }
  780. }
  781. else if (m_nFocus == GEN_AUTO_FOCUS)
  782. {
  783. if (m_DoseUnit.m_Focus->Update(AttrKey::FOCUS_TYPE::FOCUS_AUTOMATIC))
  784. {
  785. FireNotify(AttrKey::FOCUS, m_DoseUnit.m_Focus->JSGet());
  786. mLog::Debug("Focus notify[{$}]", m_nFocus);
  787. }
  788. }
  789. else
  790. {
  791. mLog::Debug("focus is wrong.[{$}]", m_nFocus);
  792. }
  793. }
  794. break;
  795. case GEN_PARAM_MA:
  796. {
  797. float m_fmA = *(float*)lParam;
  798. mLog::Debug("GEN_PARAM_MA[{$}]", m_fmA);
  799. if (m_DoseUnit.m_MA->Update(m_fmA))
  800. {
  801. FireNotify(AttrKey::MA, m_DoseUnit.m_MA->JSGet());
  802. }
  803. }
  804. break;
  805. case GEN_PARAM_AM:
  806. {
  807. float m_fmA = *(float*)lParam;
  808. mLog::Debug("GEN_PARAM_AM[{$}]", m_fmA);
  809. if (m_DoseUnit.m_PostMA->Update(m_fmA))
  810. {
  811. FireNotify(AttrKey::POSTMA, m_DoseUnit.m_PostMA->JSGet());
  812. }
  813. }
  814. break;
  815. case GEN_PARAM_MS:
  816. {
  817. float m_fms = *(float*)lParam;
  818. mLog::Debug("GEN_PARAM_MS[{$}]", m_fms);
  819. if (m_DoseUnit.m_MS->Update(m_fms))
  820. {
  821. FireNotify(AttrKey::MS, m_DoseUnit.m_MS->JSGet());
  822. }
  823. }
  824. break;
  825. case GEN_PARAM_AT:
  826. {
  827. float m_fms = *(float*)lParam;
  828. mLog::Debug("GEN_PARAM_AT[{$}]", m_fms);
  829. if (m_DoseUnit.m_PostMS->Update(m_fms))
  830. {
  831. FireNotify(AttrKey::POSTMS, m_DoseUnit.m_PostMS->JSGet());
  832. }
  833. }
  834. break;
  835. case GEN_PARAM_MAS:
  836. {
  837. float m_fmas = *(float*)lParam;
  838. mLog::Debug("GEN_PARAM_MAS[{$}]", m_fmas);
  839. if (m_DoseUnit.m_MAS->Update(m_fmas))
  840. {
  841. FireNotify(AttrKey::MAS, m_DoseUnit.m_MAS->JSGet());
  842. mLog::Debug("mas notify[{$}]", m_fmas);
  843. }
  844. }
  845. break;
  846. case GEN_PARAM_AP:
  847. {
  848. float m_fmAs = *(float*)lParam;
  849. mLog::Debug("GEN_PARAM_AP[{$}]", m_fmAs);
  850. if (m_DoseUnit.m_PostMAS->Update(m_fmAs))
  851. {
  852. FireNotify(AttrKey::POSTMAS, m_DoseUnit.m_PostMAS->JSGet());
  853. }
  854. }
  855. break;
  856. case GEN_PARAM_HE:
  857. {
  858. int m_nHE = (int)lParam;
  859. mLog::Debug("GEN_PARAM_HE[{$}]", m_nHE);
  860. if (m_DoseUnit.m_HE->Update(m_nHE))
  861. {
  862. FireNotify(AttrKey::TUBEHEAT, m_DoseUnit.m_HE->JSGet());
  863. }
  864. }
  865. break;
  866. case GEN_PARAM_DAP:
  867. {
  868. int dap = (int)lParam;
  869. mLog::Debug("GEN_PARAM_DAP : SetDAP OnNotify[{$}] dGycm^2", dap);
  870. if (m_DAP->Update(dap))
  871. {
  872. FireNotify(DevDAP::AttrKey::DAP, m_DAP->JSGet());
  873. mLog::Debug("GEN_PARAM_DAP[{$}]", dap);
  874. }
  875. break;
  876. }
  877. case GEN_PARAM_DAP_V2:
  878. {
  879. float fDAP = (*(float*)lParam);
  880. float fdap = (fDAP / 100.0);
  881. mLog::Debug("GEN_PARAM_DAP_V2[{$}]", fdap);
  882. mLog::Debug("SetDAP V2 OnNotify[{$}] dGycm^2", fdap);
  883. if (m_DAP->Update(fdap))
  884. {
  885. FireNotify(DevDAP::AttrKey::DAP, m_DAP->JSGet());
  886. mLog::Debug("GEN_PARAM_DAP_V2[{$}]", fdap);
  887. }
  888. break;
  889. }
  890. case GEN_PARAM_DRF:
  891. {
  892. float fDRF = (*(float*)lParam);
  893. mLog::Debug("SetDRF OnNotify[{$}] dGy*cm^2/s", fDRF);
  894. if (m_DAP->Update(fDRF))
  895. {
  896. FireNotify(DevDAP::AttrKey::DAP, m_DAP->JSGet());
  897. };
  898. break;
  899. }
  900. case GEN_PARAM_FS: //film
  901. {
  902. int m_nAECFilm = (int)lParam;
  903. mLog::Debug("GEN_PARAM_FS[{$}] ", m_nAECFilm);
  904. if (m_nAECFilm == 100)
  905. {
  906. //高
  907. if (m_DoseUnit.m_AECFilm->Update(2)) //FILM_FAST
  908. {
  909. FireNotify(AttrKey::AECFILM, m_DoseUnit.m_PostMA->JSGet());
  910. }
  911. }
  912. else if (m_nAECFilm == 10)
  913. {
  914. //中
  915. if (m_DoseUnit.m_AECFilm->Update(1)) //FILM_MEDIUM
  916. {
  917. FireNotify(AttrKey::AECFILM, m_DoseUnit.m_PostMA->JSGet());
  918. }
  919. }
  920. else
  921. {
  922. //低
  923. if (m_DoseUnit.m_AECFilm->Update(0)) //FILM_SLOW
  924. {
  925. FireNotify(AttrKey::AECFILM, m_DoseUnit.m_PostMA->JSGet());
  926. }
  927. }
  928. }
  929. break;
  930. case GEN_PARAM_FI: //fild
  931. {
  932. int m_nAECField = (int)lParam;
  933. mLog::Debug("GEN_PARAM_FI[{$}] ", m_nAECField);
  934. if (m_DoseUnit.m_AECField->Update(m_nAECField))
  935. {
  936. FireNotify(AttrKey::AECFIELD, m_DoseUnit.m_PostMA->JSGet());
  937. }
  938. }
  939. break;
  940. case GEN_PARAM_FN:
  941. {
  942. int m_nAECDensity = (int)lParam;
  943. mLog::Debug("GEN_PARAM_FN[{$}] ", m_nAECDensity);
  944. if (m_DoseUnit.m_AECDensity->Update(m_nAECDensity))
  945. {
  946. FireNotify(AttrKey::AECDENSITY, m_DoseUnit.m_AECDensity->JSGet());
  947. }
  948. break;
  949. }
  950. case GEN_PARAM_FN_V2:
  951. {
  952. int m_nAECDensity = (int)lParam;
  953. mLog::Debug("GEN_PARAM_FN_V2[{$}] ", m_nAECDensity);
  954. if (m_DoseUnit.m_AECDensity->Update(m_nAECDensity))
  955. {
  956. FireNotify(AttrKey::AECDENSITY, m_DoseUnit.m_AECDensity->JSGet());
  957. }
  958. break;
  959. }
  960. case GEN_PARAM_WS:
  961. {
  962. int m_nWorkStation = (int)lParam;
  963. mLog::Debug("GEN_PARAM_WS[{$}] ", m_nWorkStation);
  964. if (m_DoseUnit.m_WS->Update(m_nWorkStation))
  965. {
  966. FireNotify(AttrKey::WORKSTATION, m_DoseUnit.m_PostMA->JSGet());
  967. }
  968. if (m_nWorkStation == GEN_WS_TABLE)
  969. {
  970. if (m_DoseUnit.m_WS->Update(AttrKey::GENWS_TYPE::TABLE))
  971. {
  972. FireNotify(AttrKey::WORKSTATION, m_DoseUnit.m_WS->JSGet());
  973. }
  974. }
  975. else if (m_nWorkStation == GEN_WS_WALL)
  976. {
  977. if (m_DoseUnit.m_WS->Update(AttrKey::GENWS_TYPE::WALL))
  978. {
  979. FireNotify(AttrKey::WORKSTATION, m_DoseUnit.m_WS->JSGet());
  980. }
  981. }
  982. else if (m_nWorkStation == GEN_WS_CONVENTIONAL)
  983. {
  984. if (m_DoseUnit.m_WS->Update(AttrKey::GENWS_TYPE::CONVENTIONAL))
  985. {
  986. FireNotify(AttrKey::WORKSTATION, m_DoseUnit.m_WS->JSGet());
  987. }
  988. }
  989. else if (m_nWorkStation == GEN_WS_MOBILE)
  990. {
  991. if (m_DoseUnit.m_WS->Update(AttrKey::GENWS_TYPE::MOBILE))
  992. {
  993. FireNotify(AttrKey::WORKSTATION, m_DoseUnit.m_WS->JSGet());
  994. }
  995. }
  996. else if (m_nWorkStation == GEN_WS_TOMO)
  997. {
  998. if (m_DoseUnit.m_WS->Update(AttrKey::GENWS_TYPE::TOMO))
  999. {
  1000. FireNotify(AttrKey::WORKSTATION, m_DoseUnit.m_WS->JSGet());
  1001. }
  1002. }
  1003. else
  1004. {
  1005. if (m_DoseUnit.m_WS->Update(AttrKey::GENWS_TYPE::CONVENTIONAL))
  1006. {
  1007. FireNotify(AttrKey::WORKSTATION, m_DoseUnit.m_WS->JSGet());
  1008. }
  1009. }
  1010. }
  1011. break;
  1012. case GEN_PARAM_ET: //tech mode
  1013. {
  1014. int m_nET = (int)lParam;
  1015. mLog::Debug("GEN_PARAM_ET[{$}] ", m_nET);
  1016. if (m_DoseUnit.m_Techmode->Update(m_nET))
  1017. {
  1018. FireNotify(AttrKey::TECHMODE, m_DoseUnit.m_Techmode->JSGet());
  1019. }
  1020. }
  1021. break;
  1022. case GEN_PARAM_MAMMO_AE:
  1023. {
  1024. int AE = (int)lParam;
  1025. mLog::Debug("GEN_PARAM_MAMMO_AE[{$}] ", AE);
  1026. }
  1027. break;
  1028. case GEN_PARAM_MAMMO_FT:
  1029. {
  1030. int FT = (int)lParam;
  1031. mLog::Debug("GEN_PARAM_MAMMO_FT[{$}] ", FT);
  1032. }
  1033. break;
  1034. case GEN_PARAM_MAMMO_PRESSURESTATE:
  1035. {
  1036. int PS = (int)lParam;
  1037. mLog::Debug("GEN_PARAM_MAMMO_PRESSURESTATE[{$}] ", PS);
  1038. }
  1039. break;
  1040. case GEN_PARAM_MAMMO_MAMMOMECHNICALANGLE:
  1041. {
  1042. float Val = *(float*)lParam;
  1043. mLog::Debug("GEN_PARAM_MAMMO_MAMMOMECHNICALANGLE[{$}] ", Val);
  1044. }
  1045. break;
  1046. case GEN_PARAM_MAMMO_MAMMMECHNICALHEIGH:
  1047. {
  1048. float Val = *(float*)lParam;
  1049. mLog::Debug("GEN_PARAM_MAMMO_MAMMMECHNICALHEIGH[{$}] ", Val);
  1050. }
  1051. break;
  1052. case GEN_PARAM_MAMMO_MAMMOPRESSUREVALUE:
  1053. {
  1054. float Val = *(float*)lParam;
  1055. mLog::Debug("GEN_PARAM_MAMMO_MAMMOPRESSUREVALUE[{$}] ", Val);
  1056. }
  1057. break;
  1058. case GEN_PARAM_MAMMO_MAMMOAGD:
  1059. {
  1060. float Val = *(float*)lParam;
  1061. mLog::Debug("GEN_PARAM_MAMMO_MAMMOAGD[{$}] ", Val);
  1062. }
  1063. break;
  1064. case GEN_PARAM_MAMMO_MAG:
  1065. {
  1066. float Val = *(float*)lParam;
  1067. mLog::Debug("GEN_PARAM_MAMMO_MAG[{$}] ", Val);
  1068. break;
  1069. }
  1070. case GEN_PARAM_MAMMO_DEPRESS:
  1071. {
  1072. int Val = (int)lParam;
  1073. mLog::Debug("GEN_PARAM_MAMMO_DEPRESS[{$}] ", Val);
  1074. break;
  1075. }
  1076. case GEN_PARAM_MAMMO_POSITIONCODE:
  1077. {
  1078. int m_nPositionCode = (int)lParam;
  1079. mLog::Debug("GEN_PARAM_MAMMO_DEPRESS[{$}] ", m_nPositionCode);
  1080. break;
  1081. }
  1082. case GEN_TUBEHU_STATUS:
  1083. {
  1084. int nHU = (int)lParam;
  1085. mLog::Debug("GEN_TUBEHU_STATUS[{$}]", nHU);
  1086. break;
  1087. }
  1088. default:
  1089. mLog::Warn("ONGenParam default: wp[{$}], lp[{$}]", (int)wParam, (int)lParam);
  1090. break;
  1091. }
  1092. return 0L;
  1093. }
  1094. LRESULT nsGEN::V2AdapterDevice::ONGenExpDisable(WPARAM wParam, LPARAM lParam)
  1095. {
  1096. CString strNotify, ResInfo;
  1097. strNotify.Format(_T("ExpErrCode_%s"), *(CString*)wParam);
  1098. ResInfo.Format(_T("ExpErrInfo: %s"), *(CString*)lParam);
  1099. //exption
  1100. int level = 0;
  1101. if (strNotify == "ExpErrCode_")
  1102. {
  1103. int Level = 3;//error
  1104. mLog::Error("add {$}:{$}", strNotify.GetBuffer(), ResInfo.GetBuffer());
  1105. m_MSGUnit->DelErrorMessage("", level, ResInfo);
  1106. }
  1107. else
  1108. {
  1109. int Level = 3;//error
  1110. mLog::Error("add {$}:{$}", strNotify.GetBuffer(), ResInfo.GetBuffer());
  1111. m_MSGUnit->AddErrorMessage(strNotify, level, ResInfo);
  1112. }
  1113. return 0;
  1114. }
  1115. LRESULT nsGEN::V2AdapterDevice::ONGenExp(WPARAM wParam, LPARAM lParam)
  1116. {
  1117. switch (wParam)
  1118. {
  1119. case PREPRESS:
  1120. //1档
  1121. mLog::Debug("L1 HSW down");
  1122. if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_PREPARE))
  1123. {
  1124. FireNotify(AttrKey::GENSYNSTATE, m_DoseUnit.m_GenSynState->JSGet());
  1125. }
  1126. break;
  1127. case TUBEREADY:
  1128. //2档
  1129. mLog::Debug("L1 Tube ready");
  1130. if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_READY))
  1131. {
  1132. FireNotify(AttrKey::GENSYNSTATE, m_DoseUnit.m_GenSynState->JSGet());
  1133. }
  1134. break;
  1135. case XRAYON:
  1136. mLog::Debug("L1 HSW down and Xray on");
  1137. if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON))
  1138. {
  1139. FireNotify(AttrKey::GENSYNSTATE, m_DoseUnit.m_GenSynState->JSGet());
  1140. }
  1141. if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_EXP))
  1142. {
  1143. mLog::Info("init:GENSTATE STATUS_STANDBY -> STATUS_EXP");
  1144. FireNotify(AttrKey::GENSYNSTATE, m_DoseUnit.m_GenSynState->JSGet());
  1145. }
  1146. break;
  1147. case XRAYOFF:
  1148. mLog::Debug("Xray off");
  1149. if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYOFF))
  1150. {
  1151. FireNotify(AttrKey::GENSYNSTATE, m_DoseUnit.m_GenSynState->JSGet());
  1152. }
  1153. break;
  1154. case RELEASE:
  1155. //1,2松开
  1156. mLog::Debug("Hsw release");
  1157. if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF))
  1158. {
  1159. FireNotify(AttrKey::GENSYNSTATE, m_DoseUnit.m_GenSynState->JSGet());
  1160. }
  1161. if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY))
  1162. {
  1163. mLog::Info("init:GENSTATE STATUS_EXP -> STATUS_STANDBY");
  1164. FireNotify(AttrKey::GENSYNSTATE, m_DoseUnit.m_GenSynState->JSGet());
  1165. }
  1166. break;
  1167. case STANDBY://ignore
  1168. break;
  1169. case GEN_PARAM_ST://ignore
  1170. break;
  1171. case GEN_PARAM_RE://ignore
  1172. break;
  1173. default:
  1174. mLog::Warn("Enter ONGenExp default: wp[{$}], lp[{$}]", (int)wParam, (int)lParam);
  1175. break;
  1176. }
  1177. return 0L;
  1178. }
  1179. LRESULT nsGEN::V2AdapterDevice::ONGenError(WPARAM wParam, LPARAM lParam)
  1180. {
  1181. CString strNotify, ResInfo;
  1182. strNotify.Format(_T("ErrCode_%s"), *(CString*)wParam);
  1183. ResInfo.Format(_T("ErrInfo: %s"), *(CString*)lParam);
  1184. //exption
  1185. int level = 0;
  1186. if (strNotify == "ErrCode_")
  1187. {
  1188. int Level = 3;//error
  1189. mLog::Error("add {$}:{$}", strNotify.GetBuffer(), ResInfo.GetBuffer());
  1190. m_MSGUnit->DelErrorMessage("", level, ResInfo);
  1191. }
  1192. else
  1193. {
  1194. int Level = 3;//error
  1195. mLog::Error("add {$}:{$}", strNotify.GetBuffer(), ResInfo.GetBuffer());
  1196. m_MSGUnit->AddErrorMessage(strNotify, level, ResInfo);
  1197. }
  1198. return 0;
  1199. }
  1200. LRESULT nsGEN::V2AdapterDevice::ONGenWarn(WPARAM wParam, LPARAM lParam)
  1201. {
  1202. CString strNotify, ResInfo;
  1203. strNotify.Format(_T("WarCode_ % s"), *(CString*)wParam);
  1204. ResInfo.Format(_T("WarInfo: %s"), *(CString*)lParam);
  1205. //exption
  1206. int level = 0;
  1207. if (strNotify == "WarCode_")
  1208. {
  1209. int Level = 3;//error
  1210. mLog::Error("add {$}:{$}", strNotify.GetBuffer(), ResInfo.GetBuffer());
  1211. m_MSGUnit->DelErrorMessage("", level, ResInfo);
  1212. }
  1213. else
  1214. {
  1215. int Level = 3;//error
  1216. mLog::Error("add {$}:{$}", strNotify.GetBuffer(), ResInfo.GetBuffer());
  1217. m_MSGUnit->AddErrorMessage(strNotify, level, ResInfo);
  1218. }
  1219. return 0;
  1220. }
  1221. //driver-----------------------------------------
  1222. bool V2AdapterDriver::InitConfiguration()
  1223. {
  1224. //开启日志记录
  1225. string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Generator\Conf\Log4CPP.Config.GEN.xml)";
  1226. Log4CPP::GlobalContext::Map::Set(ECOM::Utility::Hash("LogFileName"), "GEN.V2ADAPTER");
  1227. auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
  1228. mLog::gLogger = Log4CPP::LogManager::GetLogger("GEN.V2ADAPTER");
  1229. mLog::Debug("Enter [{$}]", __FUNCTION__);
  1230. CAppSettings pGenConfig;
  1231. TCHAR FullPath[MAX_PATH];
  1232. CString strAppPath = "";
  1233. GetModuleFileName(hMyModule, FullPath, MAX_PATH);
  1234. strAppPath.Format("%s", FullPath);
  1235. int nPos = 1;
  1236. int nBackUpPos = 0;
  1237. while (nPos > 0) {
  1238. nPos = strAppPath.Find("\\", nPos + 1);
  1239. if (nPos > 0)
  1240. {
  1241. nBackUpPos = nPos;
  1242. }
  1243. }
  1244. strAppPath = strAppPath.Left(nBackUpPos);
  1245. mLog::Info("strapppath:[{$}]", strAppPath.GetBuffer());
  1246. if (pGenConfig.Load(strAppPath + "\\conf\\GenOprConf.xml"))
  1247. {
  1248. //m_bGenConnectReal = atoi(pGenConfig.GetValueByKey(_T("GenState")));
  1249. return true;
  1250. }
  1251. else if (pGenConfig.Load(strAppPath + "\\OEMDrivers\\Generator\\V2AdapterDriver\\conf\\GenOprConf.xml"))
  1252. {
  1253. //m_bGenConnectReal = atoi(pGenConfig.GetValueByKey(_T("GenState")));
  1254. return true;
  1255. }
  1256. else
  1257. mLog::Warn("load GenOprConf.xml failed");
  1258. return false;
  1259. }
  1260. nsGEN::V2AdapterDriver::V2AdapterDriver()
  1261. {
  1262. m_bDemoMode = false;
  1263. m_bDemoConnected = false;
  1264. m_bGenConnectReal = false;
  1265. m_pUIOBJ = nullptr;
  1266. m_pAttribute.reset(new ResDataObject());
  1267. m_pDescription.reset(new ResDataObject());
  1268. if (InitConfiguration())//read cfg ,and get m_bGenConnectState is <true or false>.
  1269. {
  1270. m_pUIOBJ = new UIObject();
  1271. mLog::Debug("Init Gen Configuration Succeed[{$}]",(int)m_pUIOBJ);
  1272. }
  1273. else
  1274. {
  1275. mLog::Error("Init Configuration Failed");
  1276. }
  1277. }
  1278. nsGEN::V2AdapterDriver::~V2AdapterDriver()
  1279. {
  1280. mLog::Debug("Enter [{$}]", __FUNCTION__);
  1281. mLog::Close();
  1282. m_pUIOBJ->Destrory();
  1283. delete m_pUIOBJ;
  1284. }
  1285. auto nsGEN::V2AdapterDriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
  1286. {
  1287. mLog::Debug("Enter [{$}]", __FUNCTION__);
  1288. if (m_bDemoMode)
  1289. {
  1290. if (!m_bDemoConnected) return nullptr;
  1291. mLog::Warn("CreateDevice:not suppert Demo mode");
  1292. return nullptr;
  1293. }
  1294. if (m_pUIOBJ)
  1295. {
  1296. V2AdapterDevice* pDevice = new V2AdapterDevice(EventCenter, m_pUIOBJ);
  1297. auto dev = std::unique_ptr <IODevice>(new IODevice(pDevice));
  1298. mLog::Debug("CreateDevice successful");
  1299. return dev;
  1300. }
  1301. return NULL;
  1302. }
  1303. bool nsGEN::V2AdapterDriver::DriverEntry(std::string CfgFileName)
  1304. {
  1305. mLog::Debug("Enter [{$}]", __FUNCTION__);
  1306. m_ConfigFileName = CfgFileName;
  1307. if (m_DeviceConfig.loadFile(m_ConfigFileName.c_str()))
  1308. {
  1309. return CCOS::Dev::IODriver::DriverEntry(CfgFileName);
  1310. }
  1311. return false;
  1312. }
  1313. void nsGEN::V2AdapterDriver::Prepare()
  1314. {
  1315. ResDataObject r_config;
  1316. if (r_config.loadFile(m_ConfigFileName.c_str()))
  1317. {
  1318. m_bDemoMode = (atoi)(((string)r_config["CONFIGURATION"]["IsDemo"]).c_str());
  1319. }
  1320. super::Prepare();
  1321. }
  1322. bool DATA_ACTION nsGEN::V2AdapterDriver::Connect()
  1323. {
  1324. mLog::Debug("Enter [{$}]", __FUNCTION__);
  1325. if (m_bDemoMode)
  1326. {
  1327. mLog::Debug("Ccos start as DEMO");
  1328. m_bDemoConnected = true;
  1329. return true;
  1330. }
  1331. if (m_pUIOBJ->Create())
  1332. {
  1333. m_bGenConnectReal = true;
  1334. mLog::Debug("Connect successful");
  1335. return true;
  1336. }
  1337. else
  1338. {
  1339. m_bGenConnectReal = false;
  1340. m_pUIOBJ->Destrory();
  1341. }
  1342. super::Connect();
  1343. return false;
  1344. }
  1345. void nsGEN::V2AdapterDriver::Disconnect()
  1346. {
  1347. mLog::Debug("Enter [{$}]", __FUNCTION__);
  1348. if (m_bDemoMode)
  1349. {
  1350. m_bDemoConnected = false;
  1351. }
  1352. else
  1353. {
  1354. if (isConnected())
  1355. {
  1356. m_pUIOBJ->Destrory();
  1357. super::Disconnect();
  1358. }
  1359. }
  1360. }
  1361. bool nsGEN::V2AdapterDriver::isConnected() const
  1362. {
  1363. mLog::Debug("Enter [{$}]", __FUNCTION__);
  1364. if (m_bDemoMode)
  1365. return m_bDemoConnected;
  1366. else
  1367. return m_bGenConnectReal;
  1368. }
  1369. std::string nsGEN::V2AdapterDriver::DriverProbe()
  1370. {
  1371. mLog::Debug("Enter [{$}]", __FUNCTION__);
  1372. ResDataObject r_config, HardwareInfo;
  1373. if (r_config.loadFile(m_ConfigFileName.c_str()))
  1374. {
  1375. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  1376. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  1377. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  1378. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  1379. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  1380. }
  1381. else
  1382. {
  1383. HardwareInfo.add("MajorID", "Generator");
  1384. HardwareInfo.add("MinorID", "Dr");
  1385. HardwareInfo.add("VendorID", "V2");
  1386. HardwareInfo.add("ProductID", "Adapter");
  1387. HardwareInfo.add("SerialID", "1234");
  1388. }
  1389. string ret = HardwareInfo.encode();
  1390. return ret;
  1391. }
  1392. std::string nsGEN::V2AdapterDriver::GetResource()
  1393. {
  1394. mLog::Debug("Enter [{$}]", __FUNCTION__);
  1395. ResDataObject temp, r_config;
  1396. if (!temp.loadFile(m_ConfigFileName.c_str()))
  1397. return std::string();
  1398. m_ConfigAll = temp;
  1399. r_config = temp["CONFIGURATION"];
  1400. m_Configurations = r_config;
  1401. ResDataObject DescriptionTemp;
  1402. ResDataObject DescriptionSend;
  1403. ResDataObject m_DescriptionSend;
  1404. ResDataObject ListTemp;
  1405. string strTemp = ""; //用于读取字符串配置信息
  1406. string strIndex = ""; //用于读取配置信息中的List项
  1407. int nTemp = -1; //用于读取整型配置信息
  1408. char sstream[10] = { 0 }; //用于转换值
  1409. string strValue = ""; //用于存储配置的值
  1410. string strType = ""; //用于存储配置的类型 int/float/string...
  1411. /***
  1412. * 1. 通过循环,将所有配置项写到pDeviceConfig
  1413. * 2. 记录配置项的内部key以及配置类型,类型对应了不同配置文件路径,用于读写真实值
  1414. ***/
  1415. try
  1416. {
  1417. //便利ConfigToolInfo 中 所有的AttributeInfo 属性段
  1418. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  1419. m_pAttribute->clear();
  1420. m_pDescription->clear();
  1421. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  1422. {
  1423. DescriptionTemp.clear();
  1424. DescriptionSend.clear();
  1425. ListTemp.clear();
  1426. //AttributeType
  1427. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Type"];
  1428. DescriptionTemp.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
  1429. DescriptionSend.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
  1430. strType = strTemp; //记录配置项的类型
  1431. //AttributeKey
  1432. //1. 根据AttributeType,内部key和配置路径,拿到当前的真实值
  1433. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  1434. nTemp = (int)m_Configurations["ConfigToolInfo"][nInfoIndex]["PathID"];
  1435. GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue); //得到strValue的值
  1436. //printf("********************************innerkey=%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
  1437. //2. 赋值
  1438. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  1439. if ("int" == strType)
  1440. {
  1441. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  1442. }
  1443. else if ("float" == strType)
  1444. {
  1445. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  1446. }
  1447. else //其它先按string类型处理
  1448. {
  1449. (*m_pAttribute).add(strTemp.c_str(), strValue.c_str());
  1450. }
  1451. //printf("********************************outkey =%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
  1452. //AttributeAccess
  1453. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Access"];
  1454. DescriptionTemp.add(ConfKey::CcosAccess, strTemp.c_str());
  1455. DescriptionSend.add(ConfKey::CcosAccess, strTemp.c_str());
  1456. /*
  1457. //AttributeRangeMin
  1458. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMin"];
  1459. if (strTemp != "") //不需要的配置项为空
  1460. {
  1461. DescriptionTemp.add(ConfKey::CcosRangeMin, strTemp.c_str());
  1462. }
  1463. //AttributeRangeMax
  1464. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMax"];
  1465. if (strTemp != "") //不需要的配置项为空
  1466. {
  1467. DescriptionTemp.add(ConfKey::CcosRangeMax, strTemp.c_str());
  1468. }
  1469. */
  1470. //AttributeList
  1471. nTemp = m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListNum"];
  1472. if (nTemp > 0) //ListNum不大于0时说明不需要list配置
  1473. {
  1474. for (int nListIndex = 0; nListIndex < nTemp; nListIndex++)
  1475. {
  1476. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListInfo"][nListIndex];
  1477. auto temKey = std::to_string(nListIndex);
  1478. ListTemp.add(temKey.c_str(), strTemp.c_str());
  1479. }
  1480. DescriptionTemp.add(ConfKey::CcosList, ListTemp);
  1481. DescriptionSend.add(ConfKey::CcosList, ListTemp.encode());
  1482. }
  1483. //AttributeRequired
  1484. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Required"];
  1485. DescriptionTemp.add(ConfKey::CcosRequired, strTemp.c_str());
  1486. DescriptionSend.add(ConfKey::CcosRequired, strTemp.c_str());
  1487. //AttributeDefaultValue
  1488. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["DefaultValue"];
  1489. if (strTemp != "") //不需要的配置项为空
  1490. {
  1491. DescriptionTemp.add(ConfKey::CcosDefaultValue, strTemp.c_str());
  1492. DescriptionSend.add(ConfKey::CcosDefaultValue, strTemp.c_str());
  1493. }
  1494. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  1495. (*m_pDescription).add(strTemp.c_str(), DescriptionTemp);
  1496. m_DescriptionSend.add(strTemp.c_str(), DescriptionSend.encode());
  1497. }
  1498. }
  1499. catch (ResDataObjectExption& e)
  1500. {
  1501. mLog::Error("Get config error: {$}", e.what());
  1502. return "";
  1503. }
  1504. ResDataObject resDeviceResource;
  1505. resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
  1506. resDeviceResource.add(ConfKey::CcosGeneratorDescription, (*m_pDescription));
  1507. ResDataObject DescriptionTempEx;
  1508. DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
  1509. m_DeviceConfig.clear();
  1510. m_DeviceConfig = DescriptionTempEx;
  1511. //mLog::Debug("local ************* get resource over {$}", DescriptionTempEx.encode());
  1512. printf("local ************* get resource over %s \n", DescriptionTempEx.encode());
  1513. resDeviceResource.clear();
  1514. resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
  1515. resDeviceResource.add(ConfKey::CcosGeneratorDescription, m_DescriptionSend);
  1516. DescriptionTempEx.clear();
  1517. DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
  1518. m_DeviceConfigSend.clear();
  1519. m_DeviceConfigSend = DescriptionTempEx;
  1520. string res = m_DeviceConfigSend.encode();
  1521. //printf("%s", res.c_str());
  1522. //mLog::Debug("get resource over {$}", DescriptionTempEx.encode());
  1523. printf("************* get resource over %s \n", DescriptionTempEx.encode());
  1524. return res;
  1525. }
  1526. std::string nsGEN::V2AdapterDriver::DeviceProbe()
  1527. {
  1528. mLog::Debug("Enter [{$}]", __FUNCTION__);
  1529. ResDataObject r_config, HardwareInfo;
  1530. if (r_config.loadFile(m_ConfigFileName.c_str()))
  1531. {
  1532. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  1533. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  1534. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  1535. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  1536. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  1537. }
  1538. else
  1539. {
  1540. HardwareInfo.add("MajorID", "Generator");
  1541. HardwareInfo.add("MinorID", "Dr");
  1542. HardwareInfo.add("VendorID", "Adapter");
  1543. HardwareInfo.add("ProductID", "HF");
  1544. HardwareInfo.add("SerialID", "1234");
  1545. }
  1546. string ret = HardwareInfo.encode();
  1547. return ret;
  1548. }
  1549. bool nsGEN::V2AdapterDriver::GetDeviceConfig(std::string& Cfg)
  1550. {
  1551. Cfg = m_DeviceConfigSend.encode();
  1552. printf("GetDeviceConfig over , %s", Cfg.c_str());
  1553. return true;
  1554. }
  1555. bool nsGEN::V2AdapterDriver::SetDeviceConfig(std::string Cfg)
  1556. {
  1557. mLog::Debug("--Func-- SetDeviceConfig {$}\n", Cfg.c_str());
  1558. printf("\n--Func-- SetDeviceConfig %s\n", Cfg.c_str());
  1559. ResDataObject DeviceConfig;
  1560. DeviceConfig.decode(Cfg.c_str());
  1561. ResDataObject DescriptionTempEx;
  1562. DescriptionTempEx = DeviceConfig["DeviceConfig"]["Attribute"];
  1563. mLog::Debug("Attribute:{$}", DescriptionTempEx.encode());
  1564. bool bSaveFile = false; //true:重新保存配置文件
  1565. string strAccess = "";
  1566. for (int i = 0; i < DescriptionTempEx.size(); i++)
  1567. {
  1568. string strKey = DescriptionTempEx.GetKey(i);
  1569. mLog::Debug("{$}", strKey.c_str());
  1570. printf("%s\n", strKey.c_str());
  1571. try
  1572. {
  1573. if (m_pAttribute->GetFirstOf(strKey.c_str()) >= 0)
  1574. {
  1575. strAccess = (string)(*m_pDescription)[strKey.c_str()]["Access"];
  1576. if ("RW" == strAccess)
  1577. {
  1578. //修改对应配置,在其他单元的配置项要同时调用其修改函数修改真实值
  1579. //1. 修改内存中的值,用于给上层发消息
  1580. (*m_pAttribute)[strKey.c_str()] = DescriptionTempEx[i];
  1581. //2. 拿到Innerkey
  1582. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  1583. mLog::Debug("nConfigInfoCount {$}", nConfigInfoCount);
  1584. string strTemp = ""; //存储AttributeKey
  1585. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  1586. {
  1587. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  1588. if (strTemp == strKey)
  1589. {
  1590. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  1591. break;
  1592. }
  1593. }
  1594. //3. 修改配置文件中的值
  1595. if (SetDeviceConfigValue(m_Configurations, strTemp.c_str(), 1, DescriptionTempEx[i]))
  1596. {
  1597. mLog::Debug("SetDeviceConfigValue over");
  1598. bSaveFile = true;
  1599. }
  1600. }
  1601. else
  1602. {
  1603. mLog::Debug("{$} is not a RW configuration item", strKey.c_str());
  1604. }
  1605. }
  1606. else
  1607. {
  1608. mLog::Debug("without this attribute {$}", strKey.c_str());
  1609. }
  1610. }
  1611. catch (ResDataObjectExption& e)
  1612. {
  1613. printf("\nSetDriverConfig crashed: %s\n", e.what());
  1614. mLog::Error("SetDriverConfig crashed: {$}", e.what());
  1615. return false;
  1616. }
  1617. }
  1618. if (bSaveFile)
  1619. {
  1620. //3. 重新保存配置文件
  1621. SaveConfigFile(true);
  1622. }
  1623. return true;
  1624. }
  1625. bool nsGEN::V2AdapterDriver::SaveConfigFile(bool bSendNotify)
  1626. {
  1627. m_ConfigAll["CONFIGURATION"] = m_Configurations;
  1628. bool bRt = m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
  1629. mLog::Debug("SaveConfigFile over {$}", bRt);
  1630. return true;
  1631. }
  1632. bool nsGEN::V2AdapterDriver::GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue)
  1633. {
  1634. strValue = "";
  1635. string strTemp = pInnerKey;
  1636. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  1637. {
  1638. int pos = 0;
  1639. ResDataObject resTemp = config;
  1640. while ((pos = strTemp.find_first_of(',')) != string::npos)
  1641. {
  1642. string Key = strTemp.substr(0, pos);
  1643. string TempValue = resTemp[Key.c_str()].encode();
  1644. // printf("-TempValue=== %s", TempValue.c_str());
  1645. resTemp.clear();
  1646. resTemp.decode(TempValue.c_str());
  1647. strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
  1648. //printf("-************--%s", strTemp.c_str());
  1649. }
  1650. if (strTemp != "")
  1651. {
  1652. strValue = (string)resTemp[strTemp.c_str()];
  1653. }
  1654. else
  1655. {
  1656. strValue = (string)resTemp;
  1657. }
  1658. }
  1659. //printf("------------%s", strValue.c_str());
  1660. return true;
  1661. }
  1662. bool nsGEN::V2AdapterDriver::SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue)
  1663. {
  1664. string strTemp = pInnerKey;
  1665. mLog::Debug("Begin to change {$} item value to {$}", pInnerKey, szValue);
  1666. printf("bBegin to change {%s} item value to {%s}", pInnerKey, szValue);
  1667. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  1668. {
  1669. try {
  1670. int pos = 0;
  1671. ResDataObject* resTemp = &config;
  1672. while ((pos = strTemp.find_first_of(',')) != string::npos)
  1673. {
  1674. string Key = strTemp.substr(0, pos);
  1675. resTemp = &(*resTemp)[Key.c_str()];
  1676. strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
  1677. }
  1678. if (strTemp != "")
  1679. {
  1680. //if ((strTemp.compare("WSTable") == 0) ||
  1681. // (strTemp.compare("WSWall") == 0) ||
  1682. // (strTemp.compare("WSFree") == 0) ||
  1683. // (strTemp.compare("WSTomo") == 0) ||
  1684. // (strTemp.compare("WSConventional") == 0)
  1685. // )
  1686. //{
  1687. // int sum = (*szValue) + 1;
  1688. // (*resTemp)[strTemp.c_str()] = (char*)(&sum);
  1689. //}
  1690. //else
  1691. // (*resTemp)[strTemp.c_str()] = szValue;
  1692. (*resTemp)[strTemp.c_str()] = szValue;
  1693. }
  1694. else
  1695. {
  1696. *resTemp = szValue;
  1697. }
  1698. }
  1699. catch (ResDataObjectExption& e)
  1700. {
  1701. mLog::Error("SetDriverConfigvalue crashed: {$}", e.what());
  1702. return false;
  1703. }
  1704. }
  1705. return true;
  1706. }
  1707. //-----------------------------------------------------------------------------
  1708. // GetIODriver & CreateIODriver
  1709. //-----------------------------------------------------------------------------
  1710. static nsGEN::V2AdapterDriver gIODriver;
  1711. CCOSDEVGENERATORV2ADAPTER_C_API CCOS::Dev::IODriver * GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
  1712. {
  1713. return &gIODriver;
  1714. }
  1715. CCOSDEVGENERATORV2ADAPTER_C_API CCOS::Dev::IODriver * CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
  1716. {
  1717. return new nsGEN::V2AdapterDriver();
  1718. }