DIOS.Dev.Generator.VMIMAMMO.cpp 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017
  1. // CCOS.Dev.GEN.VMIMAMMO.cpp : 定义 DLL 应用程序的导出函数。
  2. //
  3. //所有jk++的地方,都是不确定,或者需修改的
  4. #include "stdafx.h"
  5. #include <assert.h>
  6. #include <functional>
  7. using namespace std::placeholders;
  8. //#include "logger.temp.h"
  9. #include "CCOS.Dev.Generator.VMIMAMMO.h"
  10. #include "Helper.JSON.hpp"
  11. using namespace CCOS::Dev::Detail::Generator;
  12. namespace nsGEN = CCOS::Dev::Detail::Generator;
  13. #pragma warning (disable:4244)
  14. #pragma warning (disable:4305)
  15. #pragma warning (disable:4267)
  16. static const int msTimeOut_Lock = 500;
  17. #ifdef _WIN64
  18. #ifdef _DEBUG
  19. static const auto COM_SCFDllName = "Ccos.Dev.SerialSCFX64D.dll";
  20. #else
  21. static const auto COM_SCFDllName = "Ccos.Dev.SerialSCFX64.dll";
  22. #endif
  23. #endif
  24. #ifdef _WIN64
  25. #ifdef _DEBUG
  26. static const auto TCP_SCFDllName = "Ccos.Dev.TcpipSCFX64D.dll";
  27. #else
  28. static const auto TCP_SCFDllName = "Ccos.Dev.TcpipSCFX64.dll";
  29. #endif
  30. #endif
  31. //-----------------------------------------------------------------------------
  32. // VMIMAMMODevice
  33. //-----------------------------------------------------------------------------
  34. float g_MA_List[] = { 8, 10, 12.5, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640 };
  35. float g_MAS_List[] = { 1, 1.25, 1.6, 2, 2.5, 3.2, 4, 5, 6.4, 8, 10, 12.5, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640, 800, 1000 };
  36. float g_MS_List[] = { 1, 2, 3, 4, 5, 6, 8, 10, 12, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640, 800, 1000, 1250, 1600, 2000, 2500, 3200, 4000, 5000, 6400, 8000, 10000 };
  37. int g_AECFIELD_List[] = { 1, 10, 100, 11, 101, 111 };
  38. std::vector <float> gf_MA_List = { 8, 10, 12.5, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640 };
  39. string GetProcessDirectory()
  40. {
  41. string ret = "";
  42. char szFilename[MAX_PATH] = { 0 };
  43. DWORD res = GetModuleFileNameA(0, szFilename, MAX_PATH);
  44. if (res == 0)
  45. {
  46. return ret;
  47. }
  48. string fullpath = szFilename;
  49. string::size_type firstHit = fullpath.find_last_of('\\');
  50. if (firstHit == string::npos || firstHit == 0)
  51. {
  52. return ret;
  53. }
  54. ret = fullpath.substr(0, firstHit);//kick last \
  55. return ret;
  56. }
  57. nsGEN::VMIMAMMODevice::VMIMAMMODevice(std::shared_ptr <IOEventCenter> center, nsSCF::SCF SCF) : super(center, SCF)
  58. {
  59. assert(EventCenter);
  60. //CreateLogger("VMIMAMMO");
  61. mLog::Info("VMIMAMMO ver 3.0.0.18");
  62. m_DoseUnit.m_KV.reset(new KVMould(0.0, 20.0, 49.0, 1.0));
  63. m_DoseUnit.m_MA.reset(new MAMould(0.0, 1.0, 1000.0, 0.1));
  64. m_DoseUnit.m_MS.reset(new MSMould(0.0, 1.0, 10000.0, 0.01));
  65. m_DoseUnit.m_MAS.reset(new MASMould(0.0, 0.1, 1000.0, 0.01));
  66. m_DoseUnit.m_Techmode.reset(new TECHMODEMould(1, 0, 11, 1));
  67. m_DoseUnit.m_WS.reset(new WORKSTATIONMould(1, 0, 5, 1));
  68. m_DoseUnit.m_Focus.reset(new FOCUSMould(1, 0, 1, 1));
  69. m_DoseUnit.m_AECField.reset(new AECFIELDMould(0, 0, 111, 1));
  70. m_DoseUnit.m_AECFilm.reset(new AECFILMMould(0, 0, 2, 1));
  71. m_DoseUnit.m_AECDensity.reset(new AECDENSITYMould(0, -4, 4, 1));
  72. m_DoseUnit.m_HE.reset(new TUBEHEATMould(0, 0, 100, 1));
  73. m_DoseUnit.m_PostKV.reset(new POSTKVMould(0.0, 20.0, 49.0, 1.0));
  74. m_DoseUnit.m_PostMA.reset(new POSTMAMould(0.0, 1.0, 1000.0, 0.1));
  75. m_DoseUnit.m_PostMS.reset(new POSTMSMould(0.0, 1.0, 10000.0, 0.01));
  76. m_DoseUnit.m_PostMAS.reset(new POSTMASMould(0.0, 0.1, 1000.0, 0.01));
  77. m_DoseUnit.m_GenSynState.reset(new GENSYNSTATEMould(0, AttrKey::GENERATOR_SYNC_ERR, AttrKey::GENERATOR_SYNC_MAX, 1));
  78. m_DoseUnit.m_GenState.reset(new GENSTATEMould(4, AttrKey::GENERATOR_STATUS_SHUTDOWN, AttrKey::GENERATOR_STATUS_MAX, 1));
  79. m_DoseUnit.m_GenTotalExpNumber.reset(new TOTALEXPNUMMould(0, 0, 9999, 1));
  80. m_DoseUnit.m_GenTotalAcqTimes.reset(new TOTALACQTIMESMould(0, 0, 9999, 1));
  81. m_DoseUnit.m_GenTubeCoolWaitTimes.reset(new TUBECOOLTIMEMould(0, 0, 9999, 1));
  82. m_DoseUnit.m_GenTubeOverLoadNumber.reset(new TUBEOVERLOADNUMMould(0, 0, 9999, 1));
  83. m_DoseUnit.m_GenCurrentExpNumber.reset(new CUREXPNUMMould(0, 0, 9999, 1));
  84. m_DoseUnit.m_FrameRate.reset(new FRAMERATEMould(0.0, 0.0, 16.0, 1.0));
  85. m_DoseUnit.m_ExpMode.reset(new EXPMODEMould(nsGEN::AttrKey::EXPMODE_TYPE::Single));
  86. m_DoseUnit.m_FLMode.reset(new FLUModeMould(nsGEN::AttrKey::GENERATOR_FLUMode::GENERATOR_FLMODE_NOTFLU));
  87. m_DoseUnit.m_EXAMMode.reset(new EXAMMODEMould(AttrKey::EXAMMODE_TYPE::MANUAL));
  88. m_DoseUnit.m_TubeTargetMaterial.reset(new TUBETARGETMATERIALMould(AttrKey::TUBETARGETMATERIAL_TYPE::MO));
  89. m_DoseUnit.m_TubeAngle.reset(new TUBEANGLEMould(0,0,360,1));
  90. m_MSGUnit.reset(new nsDetail::MSGUnit(center, nsGEN::GeneratorUnitType));
  91. m_DAP.reset(new DevDAP::DOSEMould(0.0, 0.0, 1000.0, 0.01));
  92. m_hGenPostEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  93. m_pHardwareStatusThread = NULL;
  94. m_SettingExamMode = AttrKey::EXAMMODE_TYPE::MANUAL; //default is Manual
  95. OnCallBack();
  96. Register();
  97. Reset();
  98. HWSend("RR?");
  99. m_bRREnable = true;
  100. m_strPreWKStatus = "WK0";
  101. //启动定时器,定时查询
  102. StartHardwareStatusThread();
  103. }
  104. nsGEN::VMIMAMMODevice::~VMIMAMMODevice()
  105. {
  106. CloseHandle(m_hGenPostEvent);
  107. }
  108. std::string nsGEN::VMIMAMMODevice::GetGUID() const
  109. {
  110. mLog::Info("\n===============GetGUID : {$} ===================\n", GeneratorUnitType);
  111. return GeneratorUnitType;
  112. }
  113. void nsGEN::VMIMAMMODevice::Register()
  114. {
  115. auto Disp = &Dispatch;
  116. superGen::Register(Disp);
  117. superGen::RegisterRAD(Disp);
  118. superGen::RegisterAEC(Disp);
  119. superGen::RegisterExpEnable(Disp);
  120. superGen::RegisterGeneratortoSyncStatus(Disp);
  121. Disp->Get.Push(m_MSGUnit->GetKey().c_str(), [this](std::string& out) { out = m_MSGUnit->JSGet(); return RET_STATUS::RET_SUCCEED; });
  122. auto fun_Clear_DAP = [this](auto a, auto&)
  123. {
  124. return Clear_DAP();
  125. };
  126. Disp->Action.Push("Clear_DAP", fun_Clear_DAP);
  127. auto fun_GetValue_DAP = [this](auto a, auto& b)
  128. {
  129. float value = 0;
  130. RET_STATUS ret = GetValue_DAP(value);
  131. b = ToJSON(value);
  132. return ret;
  133. };
  134. Disp->Action.Push("GetValue_DAP", fun_GetValue_DAP);
  135. auto fun_StartMove = [this](auto a,auto& b)
  136. {
  137. return StartMove();
  138. };
  139. Disp->Action.Push("StartMove", fun_StartMove);
  140. auto fun_EndMove = [this](auto a, auto& b)
  141. {
  142. return EndMove();
  143. };
  144. Disp->Action.Push("EndMove", fun_EndMove);
  145. auto fun_EnterExam = [this](auto a, auto& b)
  146. {
  147. return EnterExam();
  148. };
  149. Disp->Action.Push("EnterExam", fun_EnterExam);
  150. auto fun_ExitExam = [this](auto a, auto& b)
  151. {
  152. return ExitExam();
  153. };
  154. Disp->Action.Push("ExitExam", fun_ExitExam);
  155. }
  156. RET_STATUS nsGEN::VMIMAMMODevice::IncKV()
  157. {
  158. if (!m_DoseUnit.m_KV->CanInc()) return RET_STATUS::RET_SUCCEED;
  159. return HWSend("IV01");
  160. }
  161. RET_STATUS nsGEN::VMIMAMMODevice::DecKV()
  162. {
  163. if (!m_DoseUnit.m_KV->CanDec()) return RET_STATUS::RET_SUCCEED;
  164. return HWSend("DV01");
  165. }
  166. RET_STATUS nsGEN::VMIMAMMODevice::SetKV(float value)
  167. {
  168. if (!m_DoseUnit.m_KV->Verify(value)) return RET_STATUS::RET_SUCCEED;
  169. char temp[50] = { 0 };
  170. sprintf_s(temp, "KV%03d", (int)value);
  171. return HWSend(temp);
  172. }
  173. RET_STATUS nsGEN::VMIMAMMODevice::IncMA()
  174. {
  175. return RET_STATUS::RET_SUCCEED;
  176. }
  177. RET_STATUS nsGEN::VMIMAMMODevice::DecMA()
  178. {
  179. return RET_STATUS::RET_SUCCEED;
  180. }
  181. RET_STATUS nsGEN::VMIMAMMODevice::SetMA(float value)
  182. {
  183. return RET_STATUS::RET_SUCCEED;
  184. }
  185. RET_STATUS nsGEN::VMIMAMMODevice::IncMS()
  186. {
  187. return RET_STATUS::RET_SUCCEED;
  188. }
  189. RET_STATUS nsGEN::VMIMAMMODevice::DecMS()
  190. {
  191. return RET_STATUS::RET_SUCCEED;
  192. }
  193. RET_STATUS nsGEN::VMIMAMMODevice::SetMS(float value)
  194. {
  195. return RET_STATUS::RET_SUCCEED;
  196. }
  197. RET_STATUS nsGEN::VMIMAMMODevice::IncMAS()
  198. {
  199. if (!m_DoseUnit.m_MAS->CanInc()) return RET_STATUS::RET_SUCCEED;
  200. return HWSend("IS01");
  201. }
  202. RET_STATUS nsGEN::VMIMAMMODevice::DecMAS()
  203. {
  204. if (!m_DoseUnit.m_MAS->CanDec()) return RET_STATUS::RET_SUCCEED;
  205. return HWSend("DS01");
  206. }
  207. RET_STATUS nsGEN::VMIMAMMODevice::SetMAS(float value)
  208. {
  209. if (!m_DoseUnit.m_MAS->Verify(value)) return RET_STATUS::RET_SUCCEED;
  210. char temp[50] = { 0 };
  211. sprintf_s(temp, "MX%03d", (int)(value * 10));
  212. return HWSend(temp);
  213. }
  214. RET_STATUS nsGEN::VMIMAMMODevice::SetTechmode(int value)
  215. {
  216. mLog::Info("\n SetTechmode = {$}\n", value);
  217. if (!m_DoseUnit.m_Techmode->Verify(value)) return RET_STATUS::RET_SUCCEED;
  218. return RET_STATUS::RET_SUCCEED;
  219. }
  220. RET_STATUS nsGEN::VMIMAMMODevice::SetFocus(int value)
  221. {
  222. if (!m_DoseUnit.m_Focus->Verify(value)) return RET_STATUS::RET_SUCCEED;
  223. char temp[50] = { 0 };
  224. sprintf_s(temp, "FO%01d", (int)value);
  225. return HWSend(temp);
  226. }
  227. RET_STATUS nsGEN::VMIMAMMODevice::SetAECDensity(int value)
  228. {
  229. return RET_STATUS::RET_SUCCEED;//jk++
  230. if (!m_DoseUnit.m_AECDensity->Verify(value)) return RET_STATUS::RET_SUCCEED;
  231. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_AEC)
  232. return RET_STATUS::RET_FAILED;
  233. char temp[50] = { 0 };
  234. sprintf_s(temp, "AD%02d", (int)value);
  235. return HWSend(temp);
  236. }
  237. RET_STATUS nsGEN::VMIMAMMODevice::SetAECField(int value)
  238. {
  239. return RET_STATUS::RET_SUCCEED;//jk++
  240. }
  241. RET_STATUS nsGEN::VMIMAMMODevice::SetAECFilm(int value)
  242. {
  243. return RET_STATUS::RET_SUCCEED;//jk++
  244. }
  245. RET_STATUS nsGEN::VMIMAMMODevice::SetWS(const string value)
  246. {
  247. return RET_STATUS::RET_SUCCEED;//jk++
  248. }
  249. RET_STATUS nsGEN::VMIMAMMODevice::SetAPR(const _tAPRArgs& t)
  250. {
  251. m_t = t;
  252. m_DoseUnit.m_KV->Update(m_t.fKV);
  253. m_DoseUnit.m_MAS->Update(m_t.fMAS);
  254. m_DoseUnit.m_Focus->Update(m_t.nFocus);
  255. mLog::Info("Enter SetAPR,do nothing");
  256. mLog::Info("t.fKV={$},t.fMA={$},t.fMAS={$},t.nAECDensity={$},t.nAECField={$},t.nAECFilm={$},t.nFocus={$},t.nTechmode={$}", t.fKV, t.fMA, t.fMAS, t.nAECDensity, t.nAECField, t.nAECFilm, t.nFocus, t.nTechmode);
  257. return RET_STATUS::RET_SUCCEED;
  258. }
  259. RET_STATUS nsGEN::VMIMAMMODevice::QueryHE(int& value)
  260. {
  261. value = m_DoseUnit.m_HE->Get();
  262. return RET_STATUS::RET_SUCCEED;
  263. }
  264. RET_STATUS nsGEN::VMIMAMMODevice::QueryPostKV(float& value)
  265. {
  266. value = m_DoseUnit.m_KV->Get();
  267. mLog::Info("jk++:QueryPostKV= {$}",value);
  268. return RET_STATUS::RET_SUCCEED;
  269. }
  270. RET_STATUS nsGEN::VMIMAMMODevice::QueryPostMA(float& value)
  271. {
  272. value = m_DoseUnit.m_PostMA->Get(); //postMA默认是0.上层查询时,就取0.
  273. return RET_STATUS::RET_SUCCEED;
  274. }
  275. RET_STATUS nsGEN::VMIMAMMODevice::QueryPostMS(float& value)
  276. {
  277. value = m_DoseUnit.m_PostMS->Get();
  278. return RET_STATUS::RET_SUCCEED;
  279. }
  280. RET_STATUS nsGEN::VMIMAMMODevice::QueryPostMAS(float& value)
  281. {
  282. value = m_DoseUnit.m_PostMAS->Get();
  283. mLog::Info("jk++:QueryPostMAS= {$}", value);
  284. return RET_STATUS::RET_SUCCEED;
  285. }
  286. RET_STATUS nsGEN::VMIMAMMODevice::QueryDAP()
  287. {
  288. mLog::Info("jk++:QueryDAP");
  289. return HWSend("AG?");
  290. }
  291. RET_STATUS nsGEN::VMIMAMMODevice::Clear_DAP()
  292. {
  293. return RET_STATUS::RET_SUCCEED;
  294. }
  295. RET_STATUS nsGEN::VMIMAMMODevice::GetValue_DAP(float& value)
  296. {
  297. value = m_DAP->Get();
  298. return RET_STATUS::RET_SUCCEED;
  299. }
  300. RET_STATUS nsGEN::VMIMAMMODevice::StartMove()
  301. {
  302. mLog::Info("Enter startMove do nothing");
  303. return RET_STATUS::RET_SUCCEED;
  304. }
  305. RET_STATUS nsGEN::VMIMAMMODevice::EndMove()
  306. {
  307. mLog::Info("Enter endmove do nothing");
  308. return RET_STATUS::RET_SUCCEED;
  309. }
  310. RET_STATUS nsGEN::VMIMAMMODevice::EnterExam()
  311. {
  312. HWSend("EXB1");
  313. return RET_STATUS::RET_SUCCEED;
  314. }
  315. /*有的时候,exitexam并不会执行*/
  316. RET_STATUS nsGEN::VMIMAMMODevice::ExitExam()
  317. {
  318. HWSend("EXB0");
  319. return RET_STATUS::RET_SUCCEED;
  320. }
  321. RET_STATUS nsGEN::VMIMAMMODevice::SetGenSynState(int value)
  322. {
  323. return RET_STATUS::RET_SUCCEED;
  324. }
  325. RET_STATUS nsGEN::VMIMAMMODevice::SetGenState(int value)
  326. {
  327. return RET_STATUS::RET_SUCCEED;
  328. }
  329. RET_STATUS nsGEN::VMIMAMMODevice::SetExpMode(std::string value)
  330. {
  331. mLog::Info("Enter SetExpMode:{$},m_strPreWKStatus={$}",value, m_strPreWKStatus.c_str());
  332. m_DoseUnit.m_ExpMode->Update(value);
  333. if (m_DoseUnit.m_ExpMode->JSGet() == AttrKey::EXPMODE_TYPE::TOMO)
  334. {
  335. if (m_strPreWKStatus != "WK1")
  336. {
  337. HWSend("WK1");
  338. }
  339. }
  340. else
  341. {
  342. if (m_strPreWKStatus != "WK0")
  343. {
  344. HWSend("WK0");
  345. }
  346. }
  347. //必发,有点多余,但是可以防止设置WK返回错误ET值的问题
  348. if (m_SettingExamMode != m_DoseUnit.m_EXAMMode->JSGet())
  349. {
  350. mLog::Info("m_SettingExamMode={$}, m_DoseUnit.m_EXAMMode->JSGet()={$}", m_SettingExamMode, m_DoseUnit.m_EXAMMode->JSGet().c_str());
  351. if (m_SettingExamMode == AttrKey::EXAMMODE_TYPE::MANUAL)
  352. {
  353. HWSend("ET2");
  354. }
  355. else if (m_SettingExamMode == AttrKey::EXAMMODE_TYPE::SEMIAUTO)
  356. {
  357. HWSend("ET1");
  358. }
  359. else if (m_SettingExamMode == AttrKey::EXAMMODE_TYPE::AUTOMATIC)
  360. {
  361. HWSend("ET0");
  362. }
  363. }
  364. //SetKV(m_DoseUnit.m_KV->Get());
  365. //SetMAS(m_DoseUnit.m_MAS->Get());
  366. //SetFocus(m_DoseUnit.m_Focus->Get());
  367. return RET_STATUS::RET_SUCCEED;
  368. }
  369. RET_STATUS nsGEN::VMIMAMMODevice::SetFLFMode(std::string value)
  370. {
  371. return RET_STATUS::RET_SUCCEED;
  372. }
  373. /*由于发送WK指令,偶尔会返回错误的ET值,故在setexpmode中,发送WK的时候,主动发送ET2,后续不能固定,
  374. 需要再SetEXAMMode中,记录上层传入的exammode,然后在setexpmode中,再次设定。
  375. 需要确认,当手动切换至auto或semi时,退出,重进检查,此时exammode会不会冲突。
  376. */
  377. RET_STATUS nsGEN::VMIMAMMODevice::SetEXAMMode(std::string value)
  378. {
  379. //上层给我设置exam mode。(manual semi atuo)对应(2 1 0),
  380. mLog::Info("\nEnter setexammode func value = {$}\n", value);
  381. m_SettingExamMode = value;
  382. if (value == AttrKey::EXAMMODE_TYPE::MANUAL)
  383. {
  384. HWSend("ET2");
  385. }
  386. else if (value == AttrKey::EXAMMODE_TYPE::SEMIAUTO)
  387. {
  388. HWSend("ET1");
  389. }
  390. else if (value == AttrKey::EXAMMODE_TYPE::AUTOMATIC)
  391. {
  392. HWSend("ET0");
  393. }
  394. return RET_STATUS::RET_SUCCEED;
  395. }
  396. RET_STATUS nsGEN::VMIMAMMODevice::SetFrameRate(FLOAT frameRate)
  397. {
  398. return RET_STATUS::RET_SUCCEED;
  399. }
  400. RET_STATUS nsGEN::VMIMAMMODevice::SetRPS(int rps)
  401. {
  402. return RET_STATUS::RET_SUCCEED;
  403. }
  404. RET_STATUS nsGEN::VMIMAMMODevice::RefreshData()
  405. {
  406. return RET_STATUS::RET_SUCCEED;
  407. }
  408. RET_STATUS nsGEN::VMIMAMMODevice::SetExpEnable()
  409. {
  410. return HWSend("EXB1");
  411. }
  412. RET_STATUS nsGEN::VMIMAMMODevice::SetExpDisable()
  413. {
  414. return HWSend("EXB0");
  415. }
  416. RET_STATUS nsGEN::VMIMAMMODevice::Reset()
  417. {
  418. return HWSend("RE");
  419. }
  420. RET_STATUS nsGEN::VMIMAMMODevice::SetFilter(int nFilterType)
  421. {
  422. char temp[50]{ 0 };
  423. switch (nFilterType)
  424. {
  425. case 0:
  426. case 4:
  427. HWSend("FT0");
  428. break;
  429. case 1:
  430. case 5:
  431. HWSend("FT1");
  432. break;
  433. case 2:
  434. HWSend("FT2");
  435. break;
  436. default:
  437. break;
  438. }
  439. return RET_STATUS::RET_SUCCEED;
  440. }
  441. RET_STATUS nsGEN::VMIMAMMODevice::SetMammoDensity(int unMDensity)
  442. {
  443. char temp[50]{ 0 };
  444. sprintf_s(temp, "DE%01d", unMDensity);
  445. return HWSend(temp);
  446. }
  447. RET_STATUS nsGEN::VMIMAMMODevice::SetCollimatorDev(OemCollimator* dev)
  448. {
  449. if (dev)
  450. m_pCollDev.reset(dev);
  451. return RET_STATUS::RET_SUCCEED;
  452. }
  453. RET_STATUS nsGEN::VMIMAMMODevice::SetMechDev(OemMechanical* dev)
  454. {
  455. if (dev)
  456. m_pMechDev.reset(dev);
  457. return RET_STATUS::RET_SUCCEED;
  458. }
  459. RET_STATUS nsGEN::VMIMAMMODevice::SetDapDev(OemDap* dev)
  460. {
  461. if(dev)
  462. m_pDapDev.reset(dev);
  463. return RET_STATUS::RET_SUCCEED;
  464. }
  465. RET_STATUS nsGEN::VMIMAMMODevice::HWSend(char* strCommand, int nTimeOut)
  466. {
  467. if (!m_SCF) return RET_STATUS::RET_FAILED;
  468. unsigned char strSendCommand[100] = { 0 };
  469. int len = strlen(strCommand);
  470. int tmpSum = 0;
  471. for (int i = 0; i < len; i++)
  472. {
  473. tmpSum += (int)strCommand[i];
  474. }
  475. unsigned char checkSum = unsigned char(tmpSum + 3);
  476. memcpy(strSendCommand, strCommand, len);
  477. strSendCommand[len] = 0x03;
  478. strSendCommand[len + 1] = checkSum;
  479. mLog::Info("==OUT==: {$} \n", strSendCommand);
  480. int retLength;
  481. m_SCF.Lock(msTimeOut_Lock)
  482. .SendPacket((char*)strSendCommand, strlen((char*)strSendCommand), nTimeOut, retLength);
  483. Sleep(nTimeOut);
  484. return RET_STATUS::RET_SUCCEED;
  485. }
  486. //-----------------------------------------------------------------------------
  487. // ProcessCmd
  488. //-----------------------------------------------------------------------------
  489. void nsGEN::VMIMAMMODevice::FireNotify(std::string key, std::string content)
  490. {
  491. EventCenter->OnNotify(1, key, content);
  492. }
  493. struct tFrameMapping
  494. {
  495. static const int MaxLen = 5;
  496. using cbFun = std::function <void(const char*, int)>;
  497. char strHead[MaxLen];
  498. int NbOfCharOfHead;
  499. cbFun fun;
  500. tFrameMapping(char* str, int len, cbFun f)
  501. {
  502. assert(len < MaxLen);
  503. for (int i = 0; i < len; i++)
  504. strHead[i] = str[i];
  505. NbOfCharOfHead = len;
  506. fun = f;
  507. }
  508. };
  509. static std::list <tFrameMapping> arFrame;
  510. static bool DecodeFrame(const char* strFrame, int length);
  511. void nsGEN::VMIMAMMODevice::OnCallBack()
  512. {
  513. auto HWNotProcess = [](const char* value, int length) -> void
  514. {
  515. mLog::Info("\n This commands didn't need to process!\n");
  516. };
  517. auto HWKV = [this](const char* value, int length) -> void
  518. {
  519. mLog::Info("\n recv KV={$},m_DoseUnit.m_KV={$}\n", atoi(value), m_DoseUnit.m_KV->JSGet().c_str());
  520. if(m_DoseUnit.m_KV->Update(atof(value)))
  521. FireNotify(AttrKey::KV, m_DoseUnit.m_KV->JSGet());
  522. };
  523. auto HWMAS = [this](const char* value, int length)
  524. {
  525. assert(value);
  526. float fmas = atof(value) / 10.0;
  527. if (m_DoseUnit.m_MAS->Update(fmas))
  528. FireNotify(AttrKey::MAS, m_DoseUnit.m_MAS->JSGet()); //无论mas是否更新,都主动notify。
  529. };
  530. auto HWMA = [this](const char* value, int length)
  531. {
  532. assert(value);
  533. float fma = atof(value) / 100.0;
  534. if (m_DoseUnit.m_MA->Update(fma))
  535. FireNotify(AttrKey::MA, m_DoseUnit.m_MA->JSGet());
  536. };
  537. auto HWMS = [this](const char* value, int length)
  538. {
  539. assert(value);
  540. if (m_DoseUnit.m_MS->Update(atof(value) / 100.0))
  541. FireNotify(AttrKey::MS, m_DoseUnit.m_MS->JSGet());
  542. };
  543. auto HWFocus = [this](const char* value, int length)
  544. {
  545. assert(value);
  546. if (m_DoseUnit.m_Focus->Update(atoi(value)))
  547. FireNotify(AttrKey::FOCUS, m_DoseUnit.m_Focus->JSGet());
  548. };
  549. auto HWTechmode = [this](const char* value, int length)
  550. {
  551. assert(value);
  552. std::string strCurrentET = AttrKey::EXAMMODE_TYPE::MANUAL;
  553. if (2 == atoi(value))
  554. {
  555. strCurrentET = AttrKey::EXAMMODE_TYPE::MANUAL;
  556. }
  557. else if (1 == atoi(value))
  558. {
  559. strCurrentET = AttrKey::EXAMMODE_TYPE::SEMIAUTO;
  560. }
  561. else if (0 == atoi(value))
  562. {
  563. strCurrentET = AttrKey::EXAMMODE_TYPE::AUTOMATIC;
  564. }
  565. if (m_DoseUnit.m_EXAMMode->Update(strCurrentET))
  566. FireNotify(AttrKey::EXAMMODE, m_DoseUnit.m_EXAMMode->JSGet());
  567. };
  568. auto HWAECField = [this](const char* value, int length)
  569. {
  570. assert(value);
  571. int nvalue = atoi(value);
  572. if (m_DoseUnit.m_AECField->Update(nvalue))
  573. FireNotify(AttrKey::AECFIELD, m_DoseUnit.m_AECField->JSGet());
  574. };
  575. auto HWAECFilm = [this](const char* value, int length)
  576. {
  577. assert(value);
  578. if (m_DoseUnit.m_AECFilm->Update(atoi(value)))
  579. FireNotify(AttrKey::AECFILM, m_DoseUnit.m_AECFilm->JSGet());
  580. };
  581. auto HWAECDensity = [this](const char* value, int length)
  582. {
  583. assert(value);
  584. if (m_DoseUnit.m_AECDensity->Update(atoi(value)))
  585. FireNotify(AttrKey::AECDENSITY, m_DoseUnit.m_AECDensity->JSGet());
  586. };
  587. auto HWWS = [this](const char* value, int length)
  588. {
  589. assert(value);
  590. int nValue = atoi(value);
  591. if (m_DoseUnit.m_WS->Update(nValue))
  592. {
  593. FireNotify(m_DoseUnit.m_WS->GetKey(), m_DoseUnit.m_WS->JSGet());
  594. }
  595. };
  596. auto HWPR = [this](const char* value, int length)
  597. {
  598. };
  599. auto HWXR = [this](const char* value, int length)
  600. {
  601. };
  602. auto HWAPDOSE = [this](const char* value, int length)//mas
  603. {
  604. assert(value);
  605. if(m_DoseUnit.m_PostMAS->Update(atof(value) / 1000.0))
  606. FireNotify(m_DoseUnit.m_PostMAS->GetKey(), m_DoseUnit.m_PostMAS->JSGet());
  607. float fMS = atof(value) / m_DoseUnit.m_MA->Get();
  608. if (m_DoseUnit.m_PostMS->Update(fMS))
  609. FireNotify(m_DoseUnit.m_PostMS->GetKey(), m_DoseUnit.m_PostMS->JSGet());
  610. mLog::Info("\n post MAS={$} postMS={$}\n", m_DoseUnit.m_PostMAS->Get(), m_DoseUnit.m_PostMS->Get());
  611. };
  612. auto HWATDOSE = [this](const char* value, int length)
  613. {
  614. assert(value);
  615. if(m_DoseUnit.m_PostMS->Update(atof(value)))
  616. FireNotify(m_DoseUnit.m_PostMS->GetKey(), m_DoseUnit.m_PostMS->JSGet());
  617. };
  618. //note: AG<0000> 并不是dap的意思,是计量的意思
  619. auto HWAG = [this](const char* value, int length)
  620. {
  621. assert(value);
  622. if (m_pMechDev)
  623. {
  624. m_pMechDev->UpdateMammo_AGD(atof(value) / 10000.0);
  625. }
  626. };
  627. auto HWGS = [this](const char* value, int length)
  628. {
  629. assert(value);
  630. switch (atoi(value))
  631. {
  632. case 0:
  633. {
  634. if (this->m_bInExposurePeriod)
  635. {
  636. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF); //pr0
  637. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  638. }
  639. this->m_bInExposurePeriod = false;
  640. }
  641. break;
  642. case 1:
  643. {
  644. if (this->m_bInExposurePeriod)
  645. {
  646. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF); //pr0
  647. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  648. mLog::Info("\n recv GS1 ,and send GENERATOR_RAD_OFF out \n");
  649. }
  650. this->m_bInExposurePeriod = false;
  651. //char ErrorCode[10]{ "" };
  652. //sprintf_s(ErrorCode, "VMIMAMMO_GS_%d", 1);
  653. //int level = 1;
  654. //m_MSGUnit->AddWarnMessage(ErrorCode, level, "");
  655. }
  656. break;
  657. case 2:
  658. {
  659. if (!this->m_bInExposurePeriod)
  660. {
  661. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_PREPARE); //pr1
  662. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  663. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_READY); //pr2
  664. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  665. }
  666. this->m_bInExposurePeriod = true;
  667. }
  668. break;
  669. case 3:
  670. {
  671. if (this->m_bInExposurePeriod)
  672. {
  673. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF); //pr0
  674. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  675. mLog::Info("\n recv GS3 ,and send GENERATOR_RAD_OFF out \n");
  676. }
  677. this->m_bInExposurePeriod = false;
  678. //char ErrorCode[100]{ "" };
  679. //sprintf_s(ErrorCode, "Generator Blocked VMIMAMMO_GS_%d", 3);
  680. //int level = 1;
  681. //m_MSGUnit->AddWarnMessage(ErrorCode, level, "");
  682. }
  683. break;
  684. default:
  685. break;
  686. }
  687. };
  688. auto HWST = [this](const char* value, int length)
  689. {
  690. assert(value);
  691. switch (atoi(value))
  692. {
  693. case 4:
  694. {
  695. //读取配置文件,软同步or直连时,
  696. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON); //xr1
  697. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  698. this->m_bInExposurePeriod = true;
  699. #if 1
  700. //send post param
  701. m_DoseUnit.m_PostMAS->Update(m_DoseUnit.m_MAS->Get());
  702. FireNotify(m_DoseUnit.m_PostMAS->GetKey(), m_DoseUnit.m_PostMAS->JSGet());
  703. mLog::Info("\n recv ST4 post MAS={$}\n", m_DoseUnit.m_PostMAS->Get());
  704. mLog::Info("\n recv ST4 m_MAS={$}\n", m_DoseUnit.m_MAS->Get());
  705. //send post kv
  706. m_DoseUnit.m_PostKV->Update(m_DoseUnit.m_KV->Get());
  707. FireNotify(m_DoseUnit.m_PostKV->GetKey(), m_DoseUnit.m_PostKV->JSGet());
  708. mLog::Info("\n recv ST4 postkv={$},\n", m_DoseUnit.m_PostKV->Get());
  709. mLog::Info("\n recv ST4 kv={$},\n", m_DoseUnit.m_KV->Get());
  710. #endif // 0
  711. }
  712. break;
  713. case 5:
  714. {
  715. if (this->m_bInExposurePeriod)
  716. {
  717. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYOFF); //xr0
  718. #if 0
  719. //send post param
  720. m_DoseUnit.m_PostMAS->Update(m_DoseUnit.m_MAS->Get());
  721. FireNotify(m_DoseUnit.m_PostMAS->GetKey(), m_DoseUnit.m_PostMAS->JSGet());
  722. mLog::Info("\n recv ST5 post MAS={$}\n", m_DoseUnit.m_PostMAS->Get());
  723. mLog::Info("\n recv ST5 m_MAS={$}\n", m_DoseUnit.m_MAS->Get());
  724. //send post kv
  725. m_DoseUnit.m_PostKV->Update(m_DoseUnit.m_KV->Get());
  726. FireNotify(m_DoseUnit.m_PostKV->GetKey(), m_DoseUnit.m_PostKV->JSGet());
  727. mLog::Info("\n recv ST5 postkv={$},\n", m_DoseUnit.m_PostKV->Get());
  728. mLog::Info("\n recv ST5 kv={$},\n", m_DoseUnit.m_KV->Get());
  729. #endif // 0
  730. }
  731. this->m_bInExposurePeriod = false;
  732. }
  733. break;
  734. default:
  735. break;
  736. }
  737. };
  738. auto HWERROR = [this](const char* value, int length)
  739. {
  740. assert(value);
  741. int nValue = atoi(value);
  742. if (nValue != 0)
  743. {
  744. char ErrorCode[10]{ "" };
  745. sprintf_s(ErrorCode, "VMIMAMMO_ERR_%d", nValue);
  746. int level = 1;
  747. m_MSGUnit->AddErrorMessage(ErrorCode, level, ErrorCode);
  748. m_localErrorlist.push_back(ErrorCode);
  749. }
  750. else
  751. {
  752. int level = 1;
  753. //char ErrorCode[10]{ "" };
  754. //m_MSGUnit->DelErrorMessage(ErrorCode, level, "");
  755. for (auto errorStr : m_localErrorlist)
  756. {
  757. m_MSGUnit->DelErrorMessage(errorStr.c_str(), level, "");
  758. mLog::Info("clear error = {$}\n", errorStr);
  759. }
  760. m_localErrorlist.clear();
  761. }
  762. };
  763. auto HWWARN = [this](const char* value, int length)
  764. {
  765. assert(value);
  766. int nValue = atoi(value);
  767. if (nValue != 0)
  768. {
  769. char WarnCode[100]{ "" };
  770. sprintf_s(WarnCode, "VMIMAMMO_WARN_%d", nValue);
  771. int level = 1;
  772. m_MSGUnit->AddWarnMessage(WarnCode, level, WarnCode);
  773. mLog::Info("\n recv WN? ,and AddWarnMessage \n");
  774. m_localWarnlist.push_back(WarnCode);
  775. }
  776. else
  777. {
  778. int level = 1;
  779. //char WarnCode[100]{ "" };
  780. //m_MSGUnit->DelWarnMessage(WarnCode, level, "");
  781. //mLog::Info("\n recv WN0 ,and DelWarnMessage \n");
  782. for (auto warnStr : m_localWarnlist)
  783. {
  784. m_MSGUnit->DelWarnMessage(warnStr.c_str(), level, "");
  785. mLog::Info("clear warn = {$}\n", warnStr);
  786. }
  787. m_localWarnlist.clear();
  788. }
  789. };
  790. auto HWRE = [this](const char* value, int length) -> void
  791. {
  792. assert(value);
  793. int nValue = atoi(value);
  794. if (nValue == 1) //reset success
  795. {
  796. int level = 1;
  797. for (auto errorStr : m_localErrorlist)
  798. {
  799. m_MSGUnit->DelErrorMessage(errorStr.c_str(), level, "");
  800. mLog::Info("clear error = {$}\n", errorStr);
  801. }
  802. m_localErrorlist.clear();
  803. //char WarnCode[10]{ "" };
  804. //m_MSGUnit->DelErrorMessage(WarnCode, level, "");
  805. }
  806. };
  807. auto HWEHE = [this](const char* value, int length)
  808. {
  809. assert(value);
  810. if(m_DoseUnit.m_HE->Update(atoi(value)))
  811. FireNotify(m_DoseUnit.m_HE->GetKey(), m_DoseUnit.m_HE->JSGet());
  812. };
  813. //当前认为TGA就是球馆角度
  814. auto HWTG = [this](const char* value, int length)
  815. {
  816. assert(value);
  817. int tempnum = atoi(value);
  818. int nExpIndex = tempnum / 100000;
  819. int nSign = (tempnum % 100000) / 10000;
  820. int Angle = tempnum % 10000;
  821. if (nSign == 0)
  822. {
  823. Angle = Angle * -1;
  824. }
  825. float fAngle = (float)Angle;
  826. m_resultAngle_tmp.clear();
  827. char Key[4] = { 0 };
  828. sprintf_s(Key, "%d", nExpIndex);
  829. m_resultAngle_tmp.add(Key, fAngle / 10.0f);
  830. if (m_pMechDev)
  831. {
  832. GetTomoResults(m_resultAngle_tmp, m_resultAngle_tmp);
  833. }
  834. if (m_DoseUnit.m_TubeAngle->Update(fAngle/10))
  835. {
  836. FireNotify(m_DoseUnit.m_TubeAngle->GetKey(), m_DoseUnit.m_TubeAngle->JSGet());
  837. }
  838. };
  839. auto HWFS = [this](const char* value, int length) -> void
  840. {
  841. assert(value);
  842. if (length == 8)
  843. {
  844. int number = atoi(value); //aaabbb
  845. int xsize = number % 1000/10; //bbb -->转为cm
  846. int ysize = number / 1000/10; //aaa -->转为cm
  847. if (m_pCollDev)
  848. {
  849. m_pCollDev->UpdateCollimatorXSize(xsize);
  850. m_pCollDev->UpdateCollimatorYSize(ysize);
  851. }
  852. }
  853. };
  854. auto HWFY = [this](const char* value, int length) -> void
  855. {
  856. assert(value);
  857. //if (m_pCollDev)
  858. // m_pCollDev->UpdateCollimatorFilter(atoi(value));
  859. };
  860. auto HWWK = [this](const char* value, int length) -> void
  861. {
  862. assert(value);
  863. if (0 == atoi(value))
  864. {
  865. m_strPreWKStatus = "WK0";
  866. }
  867. else if (1 == atoi(value))
  868. {
  869. m_strPreWKStatus = "WK1";
  870. }
  871. };
  872. auto HWMG = [this](const char* value, int length) -> void
  873. {
  874. assert(value);
  875. int temp = atoi(value);
  876. float _fMag;
  877. if (2 == temp)
  878. {
  879. _fMag = 1.8f;
  880. }
  881. else if (1 == temp)
  882. {
  883. _fMag = 1.5f;
  884. }
  885. else
  886. {
  887. _fMag = 1.0f;
  888. }
  889. if (m_pMechDev)
  890. {
  891. m_pMechDev->UpdateMammo_MAG(_fMag);
  892. mLog::Info("\n get mag ={$}\n", _fMag);
  893. }
  894. else
  895. {
  896. mLog::Info("\n get mag ={$},but mechdev is null,so not send out.!!!!\n", _fMag);
  897. }
  898. };
  899. //UpdateMammo_CompressPaddle
  900. //关于压迫板信息,gen应该能收到相关信息,解析后,更新 UpdateMammo_CompressPaddle 属性,这样上层可以收到。
  901. auto HWMT = [this](const char* value, int length)
  902. {
  903. assert(value);
  904. int nValue = atoi(value);
  905. int direction = nValue / 1000;
  906. float angle = nValue % 1000;
  907. if (direction == 1)
  908. {
  909. angle = -1 * angle;
  910. }
  911. if (m_pMechDev)
  912. m_pMechDev->UpdateMammo_MechAngle(angle);
  913. };
  914. //原code中,PE 有两个含义。
  915. auto HWPE = [this](const char* value, int length) -> void
  916. {
  917. assert(value);
  918. if (m_pMechDev)
  919. m_pMechDev->UpdateMammo_PressureState(atoi(value));
  920. //GEN_PARAM_MAMMO_MAMMMECHNICALHEIGH
  921. if (m_pMechDev)
  922. m_pMechDev->UpdateMammo_MechHeight(atof(value));
  923. };
  924. auto HWPF = [this](const char* value, int length) -> void
  925. {
  926. assert(value);
  927. if (m_pMechDev)
  928. m_pMechDev->UpdateMammo_PressureValue(atof(value));
  929. };
  930. auto HWFT = [this](const char* value, int length) -> void
  931. {
  932. assert(value);
  933. if (m_pMechDev)
  934. {
  935. /*补充一项对应关系:(0--4,收到FT0,转为4,发给上层。),(1--5),(2--2,不变 发给上层)*/
  936. int nFilterType = atoi(value);
  937. if (0 == nFilterType)
  938. {
  939. m_pMechDev->UpdateMammo_FT(4);
  940. }
  941. else if (1 == nFilterType)
  942. {
  943. m_pMechDev->UpdateMammo_FT(5);
  944. }
  945. else if (2 == nFilterType)
  946. {
  947. m_pMechDev->UpdateMammo_FT(5);
  948. }
  949. }
  950. if (m_pCollDev)
  951. {
  952. /*补充一项对应关系:(0--4,收到FT0,转为4,发给上层。),(1--5),(2--2 不变, 发给上层)*/
  953. int nFilterType = atoi(value);
  954. if (0 == nFilterType)
  955. {
  956. m_pCollDev->UpdateCollimatorFilter(4);
  957. }
  958. else if (1 == nFilterType)
  959. {
  960. m_pCollDev->UpdateCollimatorFilter(5);
  961. }
  962. else if (2 == nFilterType)
  963. {
  964. m_pCollDev->UpdateCollimatorFilter(5);
  965. }
  966. }
  967. };
  968. auto HWGR = [this](const char* value, int length) -> void
  969. {
  970. assert(value);
  971. if (m_pMechDev)
  972. m_pMechDev->UpdateGrid(atoi(value));
  973. };
  974. auto HWDF = [this](const char* value, int length) -> void
  975. {
  976. assert(value);
  977. if (m_pMechDev)
  978. m_pMechDev->UpdateMammo_Depress(atoi(value));
  979. };
  980. // 有部分前缀是包含关系, 长的包含短的, 例如 KVS 包含了 KV.
  981. // 因此长的在前面, 短的在后面
  982. // !!! Device 是个短寿命对象, 而 arFrame 是静态变量 !!!
  983. // !!! 因此, 在添加到 arFrame 之前, 务必先清零 !!!
  984. arFrame.clear();
  985. arFrame.push_back(tFrameMapping("WK", 2, HWWK));
  986. arFrame.push_back(tFrameMapping("KV", 2, HWKV));
  987. arFrame.push_back(tFrameMapping("MX", 2, HWMAS));
  988. arFrame.push_back(tFrameMapping("ET", 2, HWTechmode));
  989. arFrame.push_back(tFrameMapping("FO", 2, HWFocus));
  990. arFrame.push_back(tFrameMapping("AD", 2, HWAECDensity));
  991. arFrame.push_back(tFrameMapping("AG", 2, HWAG));
  992. arFrame.push_back(tFrameMapping("GS", 2, HWGS));
  993. arFrame.push_back(tFrameMapping("MT", 2, HWMT));
  994. //MG -- 2 1 0 对应 1.8 1.5 1.0 ,GEN_PARAM_MAMMO_MAG 发送后者给上层
  995. arFrame.push_back(tFrameMapping("MG", 2, HWMG));
  996. arFrame.push_back(tFrameMapping("FY", 2, HWFY));//不知道何意
  997. arFrame.push_back(tFrameMapping("PE", 2, HWPE));
  998. arFrame.push_back(tFrameMapping("PF", 2, HWPF));
  999. arFrame.push_back(tFrameMapping("FT", 2, HWFT));
  1000. //FS -- 得到 长和宽 。(不知道啥啥的)
  1001. arFrame.push_back(tFrameMapping("FS", 2, HWFS));
  1002. arFrame.push_back(tFrameMapping("GR", 2, HWGR));
  1003. arFrame.push_back(tFrameMapping("DF", 2, HWDF));
  1004. arFrame.push_back(tFrameMapping("ST", 2, HWST));
  1005. arFrame.push_back(tFrameMapping("ERR", 3, HWERROR)); //==IN==:ERR003 客户反馈的log中第一次遇见
  1006. arFrame.push_back(tFrameMapping("WN", 2, HWWARN));
  1007. arFrame.push_back(tFrameMapping("HE", 2, HWEHE));
  1008. arFrame.push_back(tFrameMapping("TGA",3, HWTG));
  1009. arFrame.push_back(tFrameMapping("RE", 2, HWRE));
  1010. }
  1011. bool nsGEN::VMIMAMMODevice::StartHardwareStatusThread()
  1012. {
  1013. mLog::Info("enter Start HardwareStatus Thread ");
  1014. if (m_pHardwareStatusThread == NULL)
  1015. {
  1016. DWORD m_HardwareStatusID;
  1017. m_pHardwareStatusThread = CreateThread(0, 0, HardwareStatusThread, this, 0, &m_HardwareStatusID);
  1018. if (m_pHardwareStatusThread == NULL)
  1019. {
  1020. mLog::Fatal("Start HardwareStatus Thread Failed");
  1021. return false;
  1022. }
  1023. }
  1024. return true;
  1025. }
  1026. DWORD nsGEN::VMIMAMMODevice::HardwareStatusThread(LPVOID pParam)
  1027. {
  1028. VMIMAMMODevice* pCurGen = (VMIMAMMODevice*)pParam;
  1029. if (pCurGen == NULL)
  1030. {
  1031. return false;
  1032. }
  1033. mLog::Info("HardwareStatusThread start");
  1034. while (true)
  1035. {
  1036. if (pCurGen->m_bRREnable)
  1037. {
  1038. Sleep(1000);
  1039. pCurGen->HWSend("RR?"); //延迟发送,是因为,当时gen下面的设备还没创建完毕。但是也不能延迟太久,因为进入检查之前 最好能得到WK的状态。
  1040. pCurGen->m_bRREnable = false;
  1041. }
  1042. else
  1043. {
  1044. Sleep(2000);
  1045. pCurGen->HWSend("HE?");
  1046. //pCurGen->m_bRREnable = true;
  1047. }
  1048. }
  1049. mLog::Info("HardwareStatusThread stop");
  1050. return true;
  1051. }
  1052. RET_STATUS nsGEN::VMIMAMMODevice::SelectPP(int nPostionID)
  1053. {
  1054. char temp[50] = { 0 };
  1055. sprintf_s(temp, "PO%01d", nPostionID);
  1056. return HWSend(temp);
  1057. }
  1058. RET_STATUS nsGEN::VMIMAMMODevice::SetNeedleBiopsyEnable(unsigned int unNBEnable)
  1059. {
  1060. char temp[50] = { 0 };
  1061. sprintf_s(temp, "NB%01d", unNBEnable);
  1062. return HWSend(temp);
  1063. }
  1064. RET_STATUS nsGEN::VMIMAMMODevice::SetNeedleBiopsyDepth(unsigned int unNBDepth)
  1065. {
  1066. char temp[50] = { 0 };
  1067. sprintf_s(temp, "ND%01d", unNBDepth);
  1068. return HWSend(temp);
  1069. }
  1070. RET_STATUS nsGEN::VMIMAMMODevice::SetGrid(int nGridType)
  1071. {
  1072. char temp[50] = { 0 };
  1073. sprintf_s(temp, "GR%02d", nGridType);
  1074. return HWSend(temp);
  1075. }
  1076. RET_STATUS nsGEN::VMIMAMMODevice::SetCollimatorSize(int xsize, int ysize)
  1077. {
  1078. char temp[50] = { 0 };
  1079. sprintf_s(temp, "FS%03d%03d", xsize * 10, ysize * 10);
  1080. return HWSend(temp);
  1081. }
  1082. RET_STATUS nsGEN::VMIMAMMODevice::SetCollimatorLight(WORD pParams)
  1083. {
  1084. //此处应该发送指令给GEN,并且该指令可以控制 coll 的LED。
  1085. return RET_STATUS::RET_SUCCEED;
  1086. }
  1087. RET_STATUS nsGEN::VMIMAMMODevice::SetAutoTracking(int nAutoTracking)
  1088. {
  1089. char temp[50] = { 0 };
  1090. sprintf_s(temp, "DF%d", nAutoTracking);
  1091. return HWSend(temp);
  1092. }
  1093. RET_STATUS nsGEN::VMIMAMMODevice::GetTomoResults(ResDataObject& resultAngle, ResDataObject& resultHeight)
  1094. {
  1095. RET_STATUS ret = RET_STATUS::RET_SUCCEED;
  1096. if (resultAngle.size() == 1 && resultHeight.size() == 1)
  1097. {
  1098. m_resultAngle.update(resultAngle.GetKey(0), (float)resultAngle[0]);
  1099. mLog::Info("GetTomoResults insert, key={$},value={$}",resultAngle.GetKey(0), (float)resultAngle[0]);
  1100. }
  1101. else
  1102. {
  1103. mLog::Info("GetTomoResults size={$}", m_resultAngle.size());
  1104. for (int i = 0; i < m_resultAngle.size(); i++)
  1105. {
  1106. resultAngle.update(m_resultAngle.GetKey(i), (float)m_resultAngle[i]);
  1107. mLog::Info("GetTomoResults ket={$} ,resule={$}", m_resultAngle.GetKey(i), (float)m_resultAngle[i]);
  1108. }
  1109. resultHeight.update("0", 63.71);
  1110. resultHeight.update("1", 63.97);
  1111. resultHeight.update("2", 64.21);
  1112. resultHeight.update("3", 64.41);
  1113. resultHeight.update("4", 64.59);
  1114. resultHeight.update("5", 64.73);
  1115. resultHeight.update("6", 64.84);
  1116. resultHeight.update("7", 64.92);
  1117. resultHeight.update("8", 64.97);
  1118. resultHeight.update("9", 64.99);
  1119. resultHeight.update("10", 64.98);
  1120. resultHeight.update("11", 64.94);
  1121. resultHeight.update("12", 64.87);
  1122. resultHeight.update("13", 64.72);
  1123. resultHeight.update("14", 64.63);
  1124. resultHeight.update("15", 64.47);
  1125. resultHeight.update("16", 64.28);
  1126. resultHeight.update("17", 64.05);
  1127. m_resultAngle.clear();
  1128. }
  1129. return ret;
  1130. }
  1131. //-----------------------------------------------------------------------------
  1132. // VMIMAMMODriver
  1133. //-----------------------------------------------------------------------------
  1134. nsGEN::VMIMAMMODriver::VMIMAMMODriver()
  1135. {
  1136. m_pDriGenDev = nullptr;
  1137. m_pDriCollDev = nullptr;
  1138. m_pDriMechDev = nullptr;
  1139. m_pDriDapDev = nullptr;
  1140. m_bDemoConnected = false;
  1141. m_pAttribute.reset(new ResDataObject());
  1142. m_pDescription.reset(new ResDataObject());
  1143. }
  1144. nsGEN::VMIMAMMODriver::~VMIMAMMODriver()
  1145. {
  1146. if (m_pDriGenDev)
  1147. {
  1148. delete m_pDriGenDev;
  1149. m_pDriGenDev = nullptr;
  1150. }
  1151. if (m_pDriCollDev)
  1152. {
  1153. delete m_pDriCollDev;
  1154. m_pDriCollDev = nullptr;
  1155. }
  1156. if (m_pDriMechDev)
  1157. {
  1158. delete m_pDriMechDev;
  1159. m_pDriMechDev = nullptr;
  1160. }
  1161. if (m_pDriDapDev)
  1162. {
  1163. delete m_pDriDapDev;
  1164. m_pDriDapDev = nullptr;
  1165. }
  1166. }
  1167. auto nsGEN::VMIMAMMODriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
  1168. {
  1169. mLog::Info("Enter CreateDevice, index={$}", index);
  1170. if (!m_SCF.isConnected())
  1171. return nullptr;
  1172. if (index == 0)
  1173. {
  1174. m_pDriGenDev = new VMIMAMMODevice(EventCenter, m_SCF);
  1175. auto dev = std::unique_ptr<IODevice>(new IODevice(m_pDriGenDev));
  1176. return dev;
  1177. }
  1178. else if (index == 1)
  1179. {
  1180. mLog::Info("Enter CreateDevice COLL");
  1181. m_pDriCollDev = new OemCollimator(std::shared_ptr<IOEventCenter>(new IOEventCenter()));
  1182. auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDriCollDev));
  1183. m_pDriCollDev->SetCtrlDev(m_pDriGenDev);
  1184. m_pDriGenDev->SetCollimatorDev(m_pDriCollDev);
  1185. mLog::Info("Leave CreateDevice COLL");
  1186. return dev;
  1187. }
  1188. else if (index == 2)
  1189. {
  1190. mLog::Info("Enter CreateDevice Mech");
  1191. m_pDriMechDev = new OemMechanical(std::shared_ptr<IOEventCenter>(new IOEventCenter()));
  1192. auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDriMechDev));
  1193. m_pDriMechDev->SetCtrlDev(m_pDriGenDev);
  1194. m_pDriGenDev->SetMechDev(m_pDriMechDev);
  1195. mLog::Info("Leave CreateDevice Mech");
  1196. return dev;
  1197. }
  1198. else if (index == 3)
  1199. {
  1200. mLog::Info("Enter CreateDevice DAP");
  1201. m_pDriDapDev = new OemDap(std::shared_ptr<IOEventCenter>(new IOEventCenter()));
  1202. auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDriDapDev));
  1203. m_pDriDapDev->SetCtrlDev(m_pDriGenDev);
  1204. m_pDriGenDev->SetDapDev(m_pDriDapDev);
  1205. mLog::Info("Leave CreateDevice DAP");
  1206. return dev;
  1207. }
  1208. }
  1209. void nsGEN::VMIMAMMODriver::FireNotify(int code, std::string key, std::string content)
  1210. {
  1211. EventCenter->OnNotify(code, key, content);
  1212. }
  1213. Log4CPP::Logger* mLog::gLogger = nullptr;
  1214. void nsGEN::VMIMAMMODriver::Prepare()
  1215. {
  1216. string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Generator\Conf\Log4CPP.Config.GEN.xml)";
  1217. //Log4CPP::ThreadContext::Map::Set("LogFileName", "GEN.VMIMAMMO");
  1218. Log4CPP::GlobalContext::Map::Set(ECOM::Utility::Hash("LogFileName"), "GEN.PSG_MG");
  1219. auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
  1220. mLog::gLogger = Log4CPP::LogManager::GetLogger("GEN.VMIMAMMO");
  1221. m_SCFDllName = GetConnectDLL(m_ConfigFileName);
  1222. super::Prepare();
  1223. }
  1224. bool DATA_ACTION nsGEN::VMIMAMMODriver::Connect()
  1225. {
  1226. ResDataObject Connection = GetConnectParam(m_ConfigFileName);
  1227. mLog::Info("connections:{$} \n", Connection.encode());
  1228. auto erCode = m_SCF.Connect(Connection.encode(), &nsGEN::VMIMAMMODriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
  1229. if (erCode != SCF_ERR::SCF_SUCCEED)
  1230. return false;
  1231. auto rc = super::Connect();
  1232. if (!rc)
  1233. return false;
  1234. //return (erCode == SCF_ERR::SCF_SUCCEED);
  1235. return true;
  1236. }
  1237. void nsGEN::VMIMAMMODriver::Disconnect()
  1238. {
  1239. super::Disconnect();
  1240. m_SCF.Disconnect();
  1241. m_bDemoConnected = false;
  1242. }
  1243. bool nsGEN::VMIMAMMODriver::isConnected() const
  1244. {
  1245. return super::isConnected();
  1246. }
  1247. std::string nsGEN::VMIMAMMODriver::DriverProbe()
  1248. {
  1249. ResDataObject r_config, HardwareInfo;
  1250. if (r_config.loadFile(m_ConfigFileName.c_str()))
  1251. {
  1252. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  1253. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  1254. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  1255. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  1256. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  1257. }
  1258. else
  1259. {
  1260. HardwareInfo.add("MajorID", "Generator");
  1261. HardwareInfo.add("MinorID", "Dr");
  1262. HardwareInfo.add("VendorID", "VMIMAMMO");
  1263. HardwareInfo.add("ProductID", "HF");
  1264. HardwareInfo.add("SerialID", "Drv");
  1265. }
  1266. string ret = HardwareInfo.encode();
  1267. return ret;
  1268. }
  1269. /*
  1270. std::string nsGEN::VMIMAMMODriver::GetResource()
  1271. {
  1272. ResDataObject temp;
  1273. if (!temp.loadFile(m_ConfigFileName.c_str()))
  1274. return std::string();
  1275. auto r_config = temp["CONFIGURATION"];
  1276. for (auto& Item : m_ConfigInfo)
  1277. {
  1278. string key = Item.GetKey();
  1279. if (key == ConfKey::CcosGeneratorType)
  1280. {
  1281. Item.SetCurrentValue(((string)r_config["VendorID"]).c_str());
  1282. }
  1283. else if (key == ConfKey::CcosGeneratorModel)
  1284. {
  1285. Item.SetCurrentValue(((string)r_config["ProductID"]).c_str());
  1286. }
  1287. else if (key == ConfKey::CcosWSTable || key == ConfKey::CcosWSWall || key == ConfKey::CcosWSFree
  1288. || key == ConfKey::CcosWSTomo || key == ConfKey::CcosWSConventional)
  1289. {
  1290. Item.SetCurrentValue(((string)r_config[key.c_str()]).c_str());
  1291. }
  1292. else if (key == ConfKey::CcosSynTable || key == ConfKey::CcosSynWall || key == ConfKey::CcosSynFree
  1293. || key == ConfKey::CcosSynTomo || key == ConfKey::CcosSynConventional)
  1294. {
  1295. Item.SetCurrentValue(((string)r_config[key.c_str()]).c_str());
  1296. }
  1297. else if (key == ConfKey::CcosSCFType)
  1298. {
  1299. Item.SetCurrentValue(((string)r_config["connections"][0]["type"]).c_str());
  1300. }
  1301. else if (key == ConfKey::CcosSCFPort || key == ConfKey::CcosSCFBaudrate || key == ConfKey::CcosSCFBytesize
  1302. || key == ConfKey::CcosSCFParity || key == ConfKey::CcosSCFStopbits || key == ConfKey::CcosSCFIP)
  1303. {
  1304. if (r_config["connections"][0].GetFirstOf(key.c_str()) >= 0)
  1305. {
  1306. Item.SetCurrentValue(((string)r_config["connections"][0][key.c_str()]).c_str());
  1307. }
  1308. }
  1309. }
  1310. ResDataObject resAttr, resDescription;
  1311. for (auto Item : m_ConfigInfo)
  1312. {
  1313. resAttr.add(Item.GetKey(), Item.GetCurrentValue());
  1314. resDescription.add(Item.GetKey(), Item.GetDescription());
  1315. }
  1316. ResDataObject resDeviceResource;
  1317. resDeviceResource.add(ConfKey::CcosGeneratorAttribute, resAttr);
  1318. resDeviceResource.add(ConfKey::CcosGeneratorDescription, resDescription);
  1319. string res = resDeviceResource.encode();
  1320. mLog::Info("resDeviceResource :{$} \n", resDeviceResource.encode());
  1321. return res;
  1322. }
  1323. */
  1324. bool nsGEN::VMIMAMMODriver::GetDeviceConfig(std::string& Cfg)
  1325. {
  1326. Cfg = m_DeviceConfigSend.encode();
  1327. printf("GetDeviceConfig over , %s", Cfg.c_str());
  1328. return true;
  1329. }
  1330. bool nsGEN::VMIMAMMODriver::SetDeviceConfig(std::string Cfg)
  1331. {
  1332. mLog::Info("--Func-- SetDeviceConfig {$}\n", Cfg.c_str());
  1333. printf("\n--Func-- SetDeviceConfig %s\n", Cfg.c_str());
  1334. ResDataObject DeviceConfig;
  1335. DeviceConfig.decode(Cfg.c_str());
  1336. ResDataObject DescriptionTempEx;
  1337. DescriptionTempEx = DeviceConfig["DeviceConfig"]["Attribute"];
  1338. mLog::Debug("Attribute:{$}", DescriptionTempEx.encode());
  1339. bool bSaveFile = false; //true:重新保存配置文件
  1340. string strAccess = "";
  1341. for (int i = 0; i < DescriptionTempEx.size(); i++)
  1342. {
  1343. string strKey = DescriptionTempEx.GetKey(i);
  1344. mLog::Info("{$}", strKey.c_str());
  1345. printf("%s\n", strKey.c_str());
  1346. try
  1347. {
  1348. if (m_pAttribute->GetFirstOf(strKey.c_str()) >= 0)
  1349. {
  1350. strAccess = (string)(*m_pDescription)[strKey.c_str()]["Access"];
  1351. if ("RW" == strAccess)
  1352. {
  1353. //修改对应配置,在其他单元的配置项要同时调用其修改函数修改真实值
  1354. //1. 修改内存中的值,用于给上层发消息
  1355. (*m_pAttribute)[strKey.c_str()] = DescriptionTempEx[i];
  1356. //2. 拿到Innerkey
  1357. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  1358. mLog::Info("nConfigInfoCount {$}", nConfigInfoCount);
  1359. string strTemp = ""; //存储AttributeKey
  1360. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  1361. {
  1362. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  1363. if (strTemp == strKey)
  1364. {
  1365. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  1366. break;
  1367. }
  1368. }
  1369. //3. 修改配置文件中的值
  1370. if (SetDeviceConfigValue(m_Configurations, strTemp.c_str(), 1, DescriptionTempEx[i]))
  1371. {
  1372. mLog::Debug("SetDeviceConfigValue over");
  1373. bSaveFile = true;
  1374. }
  1375. }
  1376. else
  1377. {
  1378. mLog::Info("{$} is not a RW configuration item", strKey.c_str());
  1379. }
  1380. }
  1381. else
  1382. {
  1383. mLog::Info("without this attribute {$}", strKey.c_str());
  1384. }
  1385. }
  1386. catch (ResDataObjectExption& e)
  1387. {
  1388. printf("\nSetDriverConfig crashed: %s\n", e.what());
  1389. mLog::Error("SetDriverConfig crashed: {$}", e.what());
  1390. return false;
  1391. }
  1392. }
  1393. if (bSaveFile)
  1394. {
  1395. //3. 重新保存配置文件
  1396. SaveConfigFile(true);
  1397. }
  1398. return true;
  1399. }
  1400. bool nsGEN::VMIMAMMODriver::SaveConfigFile(bool bSendNotify)
  1401. {
  1402. m_ConfigAll["CONFIGURATION"] = m_Configurations;
  1403. bool bRt = m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
  1404. mLog::Info("SaveConfigFile over {$}", bRt);
  1405. return true;
  1406. }
  1407. bool nsGEN::VMIMAMMODriver::GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue)
  1408. {
  1409. strValue = "";
  1410. string strTemp = pInnerKey;
  1411. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  1412. {
  1413. int pos = 0;
  1414. ResDataObject resTemp = config;
  1415. while ((pos = strTemp.find_first_of(',')) != string::npos)
  1416. {
  1417. string Key = strTemp.substr(0, pos);
  1418. string TempValue = resTemp[Key.c_str()].encode();
  1419. // printf("-TempValue=== %s", TempValue.c_str());
  1420. resTemp.clear();
  1421. resTemp.decode(TempValue.c_str());
  1422. strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
  1423. //printf("-************--%s", strTemp.c_str());
  1424. }
  1425. if (strTemp != "")
  1426. {
  1427. strValue = (string)resTemp[strTemp.c_str()];
  1428. }
  1429. else
  1430. {
  1431. strValue = (string)resTemp;
  1432. }
  1433. }
  1434. //printf("------------%s", strValue.c_str());
  1435. return true;
  1436. }
  1437. bool nsGEN::VMIMAMMODriver::SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue)
  1438. {
  1439. string strTemp = pInnerKey;
  1440. mLog::Debug("Begin to change {$} item value to {$}", pInnerKey, szValue);
  1441. printf("\nbbbbbbbbbbbbbbBegin to change {%s} item value to {%s}\n", pInnerKey, szValue);
  1442. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  1443. {
  1444. try {
  1445. int pos = 0;
  1446. ResDataObject* resTemp = &config;
  1447. while ((pos = strTemp.find_first_of(',')) != string::npos)
  1448. {
  1449. string Key = strTemp.substr(0, pos);
  1450. resTemp = &(*resTemp)[Key.c_str()];
  1451. strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
  1452. }
  1453. if (strTemp != "")
  1454. {
  1455. //if ((strTemp.compare("WSTable") == 0) ||
  1456. // (strTemp.compare("WSWall") == 0) ||
  1457. // (strTemp.compare("WSFree") == 0) ||
  1458. // (strTemp.compare("WSTomo") == 0) ||
  1459. // (strTemp.compare("WSConventional") == 0)
  1460. // )
  1461. //{
  1462. // int sum = (*szValue) + 1;
  1463. // (*resTemp)[strTemp.c_str()] = (char*)(&sum);
  1464. //}
  1465. //else
  1466. // (*resTemp)[strTemp.c_str()] = szValue;
  1467. (*resTemp)[strTemp.c_str()] = szValue;
  1468. }
  1469. else
  1470. {
  1471. *resTemp = szValue;
  1472. }
  1473. }
  1474. catch (ResDataObjectExption& e)
  1475. {
  1476. mLog::Error("SetDriverConfigvalue crashed: {$}", e.what());
  1477. return false;
  1478. }
  1479. }
  1480. return true;
  1481. }
  1482. std::string nsGEN::VMIMAMMODriver::GetResource()
  1483. {
  1484. ResDataObject r_config, temp;
  1485. if (!temp.loadFile(m_ConfigFileName.c_str()))
  1486. {
  1487. return "";
  1488. }
  1489. m_ConfigAll = temp;
  1490. r_config = temp["CONFIGURATION"];
  1491. m_Configurations = r_config;
  1492. ResDataObject DescriptionTemp;
  1493. ResDataObject DescriptionSend;
  1494. ResDataObject m_DescriptionSend;
  1495. ResDataObject ListTemp;
  1496. string strTemp = ""; //用于读取字符串配置信息
  1497. string strIndex = ""; //用于读取配置信息中的List项
  1498. int nTemp = -1; //用于读取整型配置信息
  1499. char sstream[10] = { 0 }; //用于转换值
  1500. string strValue = ""; //用于存储配置的值
  1501. string strType = ""; //用于存储配置的类型 int/float/string...
  1502. /***
  1503. * 1. 通过循环,将所有配置项写到pDeviceConfig
  1504. * 2. 记录配置项的内部key以及配置类型,类型对应了不同配置文件路径,用于读写真实值
  1505. ***/
  1506. try
  1507. {
  1508. //便利ConfigToolInfo 中 所有的AttributeInfo 属性段
  1509. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  1510. m_pAttribute->clear();
  1511. m_pDescription->clear();
  1512. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  1513. {
  1514. DescriptionTemp.clear();
  1515. DescriptionSend.clear();
  1516. ListTemp.clear();
  1517. //AttributeType
  1518. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Type"];
  1519. DescriptionTemp.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
  1520. DescriptionSend.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
  1521. strType = strTemp; //记录配置项的类型
  1522. //AttributeKey
  1523. //1. 根据AttributeType,内部key和配置路径,拿到当前的真实值
  1524. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  1525. nTemp = (int)m_Configurations["ConfigToolInfo"][nInfoIndex]["PathID"];
  1526. GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue); //得到strValue的值
  1527. //printf("********************************innerkey=%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
  1528. //2. 赋值
  1529. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  1530. if ("int" == strType)
  1531. {
  1532. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  1533. }
  1534. else if ("float" == strType)
  1535. {
  1536. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  1537. }
  1538. else //其它先按string类型处理
  1539. {
  1540. (*m_pAttribute).add(strTemp.c_str(), strValue.c_str());
  1541. }
  1542. //printf("********************************outkey =%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
  1543. //AttributeAccess
  1544. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Access"];
  1545. DescriptionTemp.add(ConfKey::CcosAccess, strTemp.c_str());
  1546. DescriptionSend.add(ConfKey::CcosAccess, strTemp.c_str());
  1547. /*
  1548. //AttributeRangeMin
  1549. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMin"];
  1550. if (strTemp != "") //不需要的配置项为空
  1551. {
  1552. DescriptionTemp.add(ConfKey::CcosRangeMin, strTemp.c_str());
  1553. }
  1554. //AttributeRangeMax
  1555. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMax"];
  1556. if (strTemp != "") //不需要的配置项为空
  1557. {
  1558. DescriptionTemp.add(ConfKey::CcosRangeMax, strTemp.c_str());
  1559. }
  1560. */
  1561. //AttributeList
  1562. nTemp = m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListNum"];
  1563. if (nTemp > 0) //ListNum不大于0时说明不需要list配置
  1564. {
  1565. for (int nListIndex = 0; nListIndex < nTemp; nListIndex++)
  1566. {
  1567. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListInfo"][nListIndex];
  1568. auto temKey = std::to_string(nListIndex);
  1569. ListTemp.add(temKey.c_str(), strTemp.c_str());
  1570. }
  1571. DescriptionTemp.add(ConfKey::CcosList, ListTemp);
  1572. DescriptionSend.add(ConfKey::CcosList, ListTemp.encode());
  1573. }
  1574. //AttributeRequired
  1575. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Required"];
  1576. DescriptionTemp.add(ConfKey::CcosRequired, strTemp.c_str());
  1577. DescriptionSend.add(ConfKey::CcosRequired, strTemp.c_str());
  1578. //AttributeDefaultValue
  1579. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["DefaultValue"];
  1580. if (strTemp != "") //不需要的配置项为空
  1581. {
  1582. DescriptionTemp.add(ConfKey::CcosDefaultValue, strTemp.c_str());
  1583. DescriptionSend.add(ConfKey::CcosDefaultValue, strTemp.c_str());
  1584. }
  1585. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  1586. (*m_pDescription).add(strTemp.c_str(), DescriptionTemp);
  1587. m_DescriptionSend.add(strTemp.c_str(), DescriptionSend.encode());
  1588. }
  1589. }
  1590. catch (ResDataObjectExption& e)
  1591. {
  1592. mLog::Error("Get config error: {$}", e.what());
  1593. return "";
  1594. }
  1595. ResDataObject resDeviceResource;
  1596. resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
  1597. resDeviceResource.add(ConfKey::CcosGeneratorDescription, (*m_pDescription));
  1598. ResDataObject DescriptionTempEx;
  1599. DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
  1600. m_DeviceConfig.clear();
  1601. m_DeviceConfig = DescriptionTempEx;
  1602. mLog::Debug("local ************* get resource over {$}", DescriptionTempEx.encode());
  1603. printf("local ************* get resource over %s \n", DescriptionTempEx.encode());
  1604. resDeviceResource.clear();
  1605. resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
  1606. resDeviceResource.add(ConfKey::CcosGeneratorDescription, m_DescriptionSend);
  1607. DescriptionTempEx.clear();
  1608. DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
  1609. m_DeviceConfigSend.clear();
  1610. m_DeviceConfigSend = DescriptionTempEx;
  1611. string res = m_DeviceConfigSend.encode();
  1612. //printf("%s", res.c_str());
  1613. mLog::Debug("get resource over {$}", DescriptionTempEx.encode());
  1614. printf("************* get resource over %s \n", DescriptionTempEx.encode());
  1615. return res;
  1616. }
  1617. std::string nsGEN::VMIMAMMODriver::DeviceProbe()
  1618. {
  1619. ResDataObject r_config, HardwareInfo;
  1620. if (r_config.loadFile(m_ConfigFileName.c_str()))
  1621. {
  1622. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  1623. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  1624. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  1625. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  1626. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  1627. }
  1628. else
  1629. {
  1630. HardwareInfo.add("MajorID", "Generator");
  1631. HardwareInfo.add("MinorID", "Dr");
  1632. HardwareInfo.add("VendorID", "VMIMAMMO");
  1633. HardwareInfo.add("ProductID", "HF");
  1634. HardwareInfo.add("SerialID", "1234");
  1635. }
  1636. string ret = HardwareInfo.encode();
  1637. return ret;
  1638. }
  1639. void nsGEN::VMIMAMMODriver::Dequeue(const char* Packet, DWORD Length)
  1640. {
  1641. DecodeFrame(Packet, Length);
  1642. }
  1643. PACKET_RET nsGEN::VMIMAMMODriver::callbackPackageProcess(const char* RecData, DWORD nLength, DWORD& PacketLength)
  1644. {
  1645. if (nLength < 1)
  1646. {
  1647. mLog::Info("nLength < 1, nLength=={$} \n", nLength);
  1648. return PACKET_USELESS;
  1649. }
  1650. for (DWORD i = 0; i < nLength - 1; i++)
  1651. {
  1652. if (RecData[i] == 0x03)
  1653. {
  1654. PacketLength = i + 2; //data+etx+checksum
  1655. char strtemp[100] = { 0 };
  1656. memcpy(strtemp, RecData, i); // STX+RKC005(not include 03 + sum); //only 复制 0x03之前的数据,这样解析时,后面的03 ,sum 都不要了。
  1657. strtemp[PacketLength + 1] = 0;
  1658. mLog::Info("==IN==:{$}\n", strtemp);
  1659. return PACKET_ISPACKET;
  1660. }
  1661. }
  1662. return PACKET_NOPACKET;
  1663. }
  1664. //-----------------------------------------------------------------------------
  1665. // DecodeFrame
  1666. //-----------------------------------------------------------------------------
  1667. static bool DecodeFrame(const char* strFrame, int length)
  1668. {
  1669. auto pr = [strFrame, length](const tFrameMapping& Item)
  1670. {
  1671. for (int i = 0; i < Item.NbOfCharOfHead; i++)
  1672. {
  1673. if (strFrame[i] != Item.strHead[i])
  1674. {
  1675. return false;
  1676. }
  1677. }
  1678. return true;
  1679. };
  1680. auto found = std::find_if(arFrame.begin(), arFrame.end(), pr);
  1681. if (found == arFrame.end())
  1682. {
  1683. return false;
  1684. }
  1685. const auto& Item = *found;
  1686. auto pc = strFrame;
  1687. pc += Item.NbOfCharOfHead;
  1688. Item.fun(pc, length - Item.NbOfCharOfHead);
  1689. return true;
  1690. }
  1691. //-----------------------------------------------------------------------------
  1692. // GetIODriver & CreateIODriver
  1693. //-----------------------------------------------------------------------------
  1694. static nsGEN::VMIMAMMODriver gIODriver;
  1695. extern "C" CCOS::Dev::IODriver * __cdecl GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
  1696. {
  1697. return &gIODriver;
  1698. }
  1699. extern "C" CCOS::Dev::IODriver * __cdecl CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
  1700. {
  1701. return new nsGEN::VMIMAMMODriver();
  1702. }