CCOS.Dev.Generator.Demo.cpp 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275
  1. #include <assert.h>
  2. #include "Helper.JSON.hpp"
  3. #include "CCOS.Dev.Generator.Demo.hpp"
  4. #include "LogLocalHelper.h"
  5. #include "Log4CPP.h"
  6. using namespace CCOS::Dev::Detail::Generator;
  7. namespace nsGEN = CCOS::Dev::Detail::Generator;
  8. #pragma warning (disable:4305)
  9. #define DEMO_DAEC_Flag 1
  10. //-----------------------------------------------------------------------------
  11. // DemoDevice
  12. //-----------------------------------------------------------------------------
  13. 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 };
  14. 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 };
  15. 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 };
  16. float g_KV_List[] = { 400, 405, 410, 415, 420, 430, 440, 450, 460, 470, 480, 490, 500, 510, 520, 535, 550, 560, 570, 585, 600, 615, 630, 645, 660, 680, 700, 715, 730, 750, 770, 790, 810, 830, 850, 875, 900, 930, 960, 1000, 1020, 1050, 1090, 1130, 1170, 1210, 1250, 1290, 1330, 1370, 1410, 1450, 1500 };//<!--KV * 10-->
  17. int g_AECFIELD_List[] = { 1, 10, 100, 11, 101, 110, 111 };
  18. 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 };
  19. std::unique_ptr<OemCollimator> nsGEN::DemoDevice::m_pCollDev = nullptr; //遮光器逻辑实体指针
  20. std::unique_ptr<OemMechanical> nsGEN::DemoDevice::m_pMechDev = nullptr; //机架逻辑实体指针
  21. template<typename T>
  22. int FindPositon(T* pList, int nListSize, T& value)
  23. {
  24. if (pList == NULL || nListSize == 0) return -1;
  25. if (value <= pList[0])
  26. {
  27. value = pList[0];
  28. return 0;
  29. }
  30. if (value >= pList[nListSize - 1])
  31. {
  32. value = pList[nListSize - 1];
  33. return nListSize - 1;
  34. }
  35. for (int i = 0; i < nListSize - 1; i++)
  36. {
  37. if (value >= pList[i] && value <= pList[i + 1])
  38. {
  39. int npos = 0;
  40. if (abs(value - pList[i]) >= abs(value - pList[i + 1]))
  41. {
  42. value = pList[i + 1];
  43. npos = i + 1;
  44. }
  45. else
  46. {
  47. value = pList[i];
  48. npos = i;
  49. }
  50. return npos;
  51. }
  52. }
  53. return -1;
  54. }
  55. nsGEN::DemoDevice::DemoDevice(std::shared_ptr <IOEventCenter> center, string configfile) : super(center), superGen()
  56. {
  57. //FINFO("DEMO ver 3.0.0.1");
  58. if (!configfile.empty())
  59. {
  60. ResDataObject Conftemp;
  61. Conftemp.loadFile(configfile.c_str());
  62. m_GenConfig = Conftemp["CONFIGURATION"];
  63. TransJsonText(m_GenConfig);
  64. string version;
  65. void* hMyModule;
  66. if (GetVersion(version, hMyModule))
  67. FINFO("\n===============log begin : DEMO version:{$} ===================\n", version.c_str());
  68. else
  69. FINFO("\n===============log begin : DEMO version:0.0.0.0 ===================\n");
  70. m_iStateChangeInterval = (int)m_GenConfig["StateChangeInterval"];
  71. m_iAutoExpActWaitTime = (int)m_GenConfig["AutoExpActWaitTime"];
  72. m_bIsDemo = ((int)m_GenConfig["IsDemo"]);
  73. FINFO("Config:StateChangeInterval[{$}],AutoExpActWaitTime[{$}],IsDemo[{$}]",
  74. m_iStateChangeInterval, m_iAutoExpActWaitTime, m_bIsDemo);
  75. }
  76. else
  77. {
  78. FINFO("\n===============log begin : DEMO version:3.0.0.1 ===================\n");
  79. m_iStateChangeInterval = 500;
  80. m_iAutoExpActWaitTime = 5;
  81. m_bIsDemo = true;
  82. FINFO("default:StateChangeInterval[{$}],AutoExpActWaitTime[{$}],IsDemo[{$}]",
  83. m_iStateChangeInterval, m_iAutoExpActWaitTime, m_bIsDemo);
  84. }
  85. //通用
  86. m_DoseUnit.m_GenSynState.reset(new GENSYNSTATEMould(AttrKey::GENERATOR_RAD_OFF, AttrKey::GENERATOR_RAD_OFF, AttrKey::GENERATOR_RAD_XRAYOFF, 1));
  87. m_DoseUnit.m_GenState.reset(new GENSTATEMould(4, AttrKey::GENERATOR_STATUS_SHUTDOWN, AttrKey::GENERATOR_STATUS_MAX, 1));
  88. m_DoseUnit.m_GenTotalExpNumber.reset(new TOTALEXPNUMMould(0, 0, 9999, 1));
  89. m_DoseUnit.m_GenTotalAcqTimes.reset(new TOTALACQTIMESMould(0, 0, 9999, 1));
  90. m_DoseUnit.m_GenTubeCoolWaitTimes.reset(new TUBECOOLTIMEMould(0, 0, 9999, 1));
  91. m_DoseUnit.m_GenTubeOverLoadNumber.reset(new TUBEOVERLOADNUMMould(0, 0, 9999, 1));
  92. m_DoseUnit.m_GenCurrentExpNumber.reset(new CUREXPNUMMould(0, 0, 9999, 1));
  93. m_DoseUnit.m_ExpMode.reset(new EXPMODEMould(AttrKey::EXPMODE_TYPE::Single));
  94. m_DoseUnit.m_WS.reset(new WORKSTATIONMould(1, 0, 5, 1));
  95. m_DoseUnit.m_HE.reset(new TUBEHEATMould(0, 0, 100, 1));
  96. m_DoseUnit.m_TubeTargetMaterial.reset(new TUBETARGETMATERIALMould(AttrKey::TUBETARGETMATERIAL_TYPE::MO));
  97. m_DoseUnit.m_TubeAngle.reset(new TUBEANGLEMould(0, 0, 360, 1));
  98. //点片
  99. m_DoseUnit.m_KV.reset(new KVMould(0.0, 0.0, 150.0, 1.0));
  100. m_DoseUnit.m_MA.reset(new MAMould(0.0, 0.0, 1000.0, 0.1));
  101. m_DoseUnit.m_MS.reset(new MSMould(0.0, 0.0, 10000.0, 0.01));
  102. m_DoseUnit.m_MAS.reset(new MASMould(0.0, 0.0, 1000.0, 0.01));
  103. m_DoseUnit.m_Techmode.reset(new TECHMODEMould(AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P, AttrKey::TECHMODE_NOAEC_3P, AttrKey::TECHMODE_AEC_2P, 1));
  104. m_DoseUnit.m_Focus.reset(new FOCUSMould(AttrKey::FOCUS_TYPE::FOCUS_LARGE, AttrKey::FOCUS_SMALL, AttrKey::FOCUS_LARGE, 1));
  105. m_DoseUnit.m_AECField.reset(new AECFIELDMould(0, 0, 111, 1));
  106. m_DoseUnit.m_AECFilm.reset(new AECFILMMould(0, 0, 2, 1));
  107. m_DoseUnit.m_AECDensity.reset(new AECDENSITYMould(0, -4, 4, 1));
  108. m_DoseUnit.m_PostKV.reset(new POSTKVMould(0.0, 0.0, 150.0, 1.0));
  109. m_DoseUnit.m_PostMA.reset(new POSTMAMould(0.0, 0.0, 1000.0, 0.1));
  110. m_DoseUnit.m_PostMS.reset(new POSTMSMould(0.0, 0.0, 10000.0, 0.01));
  111. m_DoseUnit.m_PostMAS.reset(new POSTMASMould(0.0, 0.0, 1000.0, 0.01));
  112. //透视
  113. m_DoseUnit.m_FLKV.reset(new FLUKVMould(0.0, 40.0, 150.0, 1));
  114. m_DoseUnit.m_FLMA.reset(new FLUMAMould(0.0, 0.5, 800.0, 0.1));
  115. m_DoseUnit.m_FLMS.reset(new FLUMSMould(0.0, 1.0, 10000.0, 0.01));
  116. m_DoseUnit.m_FLAccTime.reset(new FLAccTimeMould(0.0, 0.0, 300.0, 1));
  117. m_DoseUnit.m_FLIntTime.reset(new FLUIntTimeMould(0.0, 0.0, 1000.0, 1));
  118. m_DoseUnit.m_PPS.reset(new PPSMould(0.0, 0.0, 60.0, 1));
  119. m_DoseUnit.m_FLMode.reset(new FLUModeMould(AttrKey::GENERATOR_FLUMode::GENERATOR_FLMODE_NOTFLU));
  120. m_DoseUnit.m_ABSStatus.reset(new FLUABSStatusMould(AttrKey::GENERATOR_ABSStatus::GENERATOR_ABS_OFF));
  121. m_DoseUnit.m_MagSize.reset(new FLUMagMould(0, 0, 3, 1));
  122. m_DoseUnit.m_DoseLevel.reset(new FLUDoseLevelMould(AttrKey::GENERATOR_DoseLevel::GENERATOR_DOSE_LOW));
  123. m_DoseUnit.m_Curve.reset(new FLUCurveMould(0, 1, 3, 1));
  124. //other
  125. m_MSGUnit.reset(new nsDetail::MSGUnit(center, GeneratorUnitType));
  126. OnRegister();
  127. GetConfData();
  128. //add by wxx:for 品臻3025ZF测试
  129. m_iAutoExpFlag = 0;
  130. m_pHardwareStatusThread = 0;
  131. StartHardwareStatusThread();
  132. }
  133. nsGEN::DemoDevice::~DemoDevice()
  134. {
  135. FINFO("\n===============log end ===================\n");
  136. if (m_pHardwareStatusThread != 0) {
  137. pthread_cancel(m_pHardwareStatusThread); // 请求取消线程
  138. pthread_join(m_pHardwareStatusThread, nullptr); // 等待线程结束
  139. m_pHardwareStatusThread = 0;
  140. }
  141. m_pCollDev.release();
  142. m_pCollDev = nullptr;
  143. m_pMechDev.release();
  144. m_pMechDev = nullptr;
  145. }
  146. void nsGEN::DemoDevice::OnRegister()
  147. {
  148. auto Disp = m_Dispatch.Lock().As();
  149. superGen::Register(Disp);
  150. superGen::RegisterRAD(Disp);
  151. superGen::RegisterAEC(Disp);
  152. superGen::RegisterExpEnable(Disp);
  153. superGen::RegisterGeneratortoSyncStatus(Disp);
  154. superGen::RegisterFluoro(Disp);
  155. Disp->Get.Push(m_MSGUnit->GetKey().c_str(), [this](std::string& out) { out = m_MSGUnit->JSGet(); return RET_STATUS::RET_SUCCEED; });
  156. auto fun_StartMove = [this](auto in, auto& out)
  157. {
  158. return StartMove();
  159. };
  160. Disp->Action.Push("StartMove", fun_StartMove);
  161. auto fun_EndMove = [this](auto in, auto& out)
  162. {
  163. return EndMove();
  164. };
  165. Disp->Action.Push("EndMove", fun_EndMove);
  166. auto fun_DirectlyNotify = [this](auto in, auto& out)
  167. {
  168. return DirectlyNotify(in);
  169. };
  170. Disp->Action.Push("DirectlyNotify", fun_DirectlyNotify);
  171. auto fun_DirectlyCMD = [this](auto in, auto& out)
  172. {
  173. return DirectlyCMD(in);
  174. };
  175. Disp->Action.Push("DirectlyCMD", fun_DirectlyCMD);
  176. }
  177. //设备方法
  178. std::string nsGEN::DemoDevice::GetGUID() const
  179. {
  180. printf("\n===============GetGUID : %s ===================\n", GeneratorUnitType);
  181. return GeneratorUnitType;
  182. }
  183. RET_STATUS nsGEN::DemoDevice::SetWS(std::string value)
  184. {
  185. FDEBUG("Enter SetWS:[{$}]", value.c_str());
  186. int tempws = 1;
  187. string strWS = "";
  188. cfgWorkStationKey trWS = cfgWorkStationKey(value.c_str());
  189. if (m_arrWSMap.find(trWS) != m_arrWSMap.end())
  190. {
  191. m_strCurrentWSName = trWS;
  192. tempws = m_arrWSMap[m_strCurrentWSName].nWSNamber;
  193. strWS = m_arrWSMap[m_strCurrentWSName].strWSNAme;
  194. FDEBUG("Set WS number [{$}][{$}]", strWS.c_str(), tempws);
  195. }
  196. else
  197. {
  198. FDEBUG("Set WS number default 1");
  199. m_strCurrentWSName = cfgWorkStationKey(1);
  200. }
  201. m_DoseUnit.m_WS->Update(atoi(value.c_str()));
  202. FireNotify(m_DoseUnit.m_WS->GetKey(), m_DoseUnit.m_WS->JSGet());
  203. return RET_STATUS::RET_SUCCEED;
  204. }
  205. RET_STATUS nsGEN::DemoDevice::QueryHE(int& value)
  206. {
  207. return RET_STATUS::RET_SUCCEED;
  208. }
  209. RET_STATUS nsGEN::DemoDevice::StartMove() //发生器无此设置
  210. {
  211. return RET_STATUS::RET_SUCCEED;
  212. }
  213. RET_STATUS nsGEN::DemoDevice::EndMove() //发生器无此设置
  214. {
  215. return RET_STATUS::RET_SUCCEED;
  216. }
  217. RET_STATUS nsGEN::DemoDevice::DirectlyNotify(string& value)
  218. {
  219. ResDataObject json;
  220. json.decode(value.c_str());
  221. FDEBUG("Enter DirectlyNotify:[{$}]", json.encode());
  222. string strKey = (string)json["NotifyKey"];
  223. string strValue = (string)json["NotifyValue"];
  224. FireNotify(strKey, strValue);
  225. return RET_STATUS::RET_SUCCEED;
  226. }
  227. RET_STATUS nsGEN::DemoDevice::DirectlyCMD(string& value)
  228. {
  229. ResDataObject json;
  230. json.decode(value.c_str());
  231. FDEBUG("Enter DirectlyCMD:[{$}]", json.encode());
  232. string strCMD = (string)json["CMDText"];
  233. return RET_STATUS::RET_SUCCEED;
  234. }
  235. RET_STATUS nsGEN::DemoDevice::SetGenSynState(int value)
  236. {
  237. FDEBUG("Enter SetGenSynState:[{$}]", value);
  238. switch (value)
  239. {
  240. case AttrKey::GENERATOR_RAD_OFF:
  241. {
  242. }break;
  243. case AttrKey::GENERATOR_RAD_PREPARE:
  244. {
  245. }break;
  246. case AttrKey::GENERATOR_RAD_READY:
  247. {
  248. }break;
  249. case AttrKey::GENERATOR_RAD_XRAYON:
  250. {
  251. if (m_DoseUnit.m_ExpMode->JSGet() == AttrKey::EXPMODE_TYPE::Stitch)
  252. {
  253. if (!m_APRarray.empty())
  254. {
  255. int aprnum = m_DoseUnit.m_GenCurrentExpNumber->Get();
  256. SetAPR(m_APRarray[aprnum]);
  257. m_DoseUnit.m_GenCurrentExpNumber->Update(++aprnum);
  258. FDEBUG("SetAPRArray:[totalEXP:{$}, currentEXP:{$}]", m_DoseUnit.m_GenTotalExpNumber->Get(), m_DoseUnit.m_GenCurrentExpNumber->Get());
  259. }
  260. else
  261. {
  262. FWARN("APRarray is empty");
  263. }
  264. }
  265. else if (m_DoseUnit.m_ExpMode->JSGet() == AttrKey::EXPMODE_TYPE::PulseSerial ||
  266. m_DoseUnit.m_ExpMode->JSGet() == AttrKey::EXPMODE_TYPE::CoutineSerial)
  267. {
  268. value = AttrKey::GENERATOR_FLU_XRAYON;
  269. }
  270. }break;
  271. case AttrKey::GENERATOR_RAD_XRAYOFF:
  272. {
  273. FINFO("SetGenSynState:4 exp Status value:POSTKV[{$}],POSTMA[{$}],POSTMS[{$}],POSTMAS[{$}]",
  274. m_DoseUnit.m_PostKV->Get(), m_DoseUnit.m_PostMA->Get(), m_DoseUnit.m_PostMS->Get(), m_DoseUnit.m_PostMAS->Get());
  275. std::cout << "SetGenSynState:4 exp Status value:POSTKV["
  276. << m_DoseUnit.m_PostKV->Get()
  277. << "],POSTMA[" << m_DoseUnit.m_PostMA->Get()
  278. << "],POSTMS[" << m_DoseUnit.m_PostMS->Get()
  279. << "],POSTMAS[" << m_DoseUnit.m_PostMAS->Get()
  280. << "]" << std::endl;
  281. FireNotify(AttrKey::POSTKV, m_DoseUnit.m_PostKV->JSGet());
  282. FireNotify(AttrKey::POSTMA, m_DoseUnit.m_PostMA->JSGet());
  283. #if DEMO_DAEC_Flag
  284. int temp = m_DoseUnit.m_PostMS->Get();
  285. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P ||
  286. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P ||
  287. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_1P)
  288. {
  289. temp /= 2;
  290. }
  291. FireNotify(AttrKey::POSTMS, temp);
  292. #else
  293. FireNotify(AttrKey::POSTMS, m_DoseUnit.m_PostMS->JSGet());
  294. #endif // DEMO_DAEC_Flag
  295. FireNotify(AttrKey::POSTMAS, m_DoseUnit.m_PostMAS->JSGet());
  296. if (m_DoseUnit.m_ExpMode->JSGet() == AttrKey::EXPMODE_TYPE::PulseSerial ||
  297. m_DoseUnit.m_ExpMode->JSGet() == AttrKey::EXPMODE_TYPE::CoutineSerial)
  298. {
  299. value = AttrKey::GENERATOR_FLU_XRAYOFF;
  300. }
  301. }break;
  302. case AttrKey::GENERATOR_FLU_READY:
  303. {
  304. }break;
  305. case AttrKey::GENERATOR_FLU_XRAYON:
  306. {
  307. }break;
  308. case AttrKey::GENERATOR_FLU_XRAYOFF:
  309. {
  310. }break;
  311. default:
  312. break;
  313. }
  314. m_DoseUnit.m_GenSynState->Update(value);
  315. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), value);
  316. return RET_STATUS::RET_SUCCEED;
  317. }
  318. RET_STATUS nsGEN::DemoDevice::SetGenState(int value)
  319. {
  320. FDEBUG("Enter SetGenState:[{$}]", value);
  321. return RET_STATUS::RET_SUCCEED;
  322. }
  323. RET_STATUS nsGEN::DemoDevice::SetExpEnable()
  324. {
  325. FDEBUG("Enter SetExpEnable");
  326. FINFO("Request Fault Status:GENSTATE STATUS_SHUTDOWN -> STATUS_STANDBY");
  327. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
  328. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  329. FireNotify(m_DoseUnit.m_KVList->GetKey(), m_DoseUnit.m_KVList->JSGet());
  330. return RET_STATUS::RET_SUCCEED;
  331. }
  332. RET_STATUS nsGEN::DemoDevice::SetExpDisable()
  333. {
  334. FDEBUG("Enter SetExpDisable");
  335. return RET_STATUS::RET_SUCCEED;
  336. }
  337. RET_STATUS CCOS::Dev::Detail::Generator::DemoDevice::PrepareAcquisition()
  338. {
  339. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
  340. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  341. return RET_STATUS::RET_SUCCEED;
  342. }
  343. RET_STATUS nsGEN::DemoDevice::Reset()
  344. {
  345. FDEBUG("Enter Reset");
  346. //FireErrorMessage(false, 0, "clear all Gen error");
  347. return RET_STATUS::RET_SUCCEED;
  348. }
  349. RET_STATUS nsGEN::DemoDevice::SetExpMode(std::string value)
  350. {
  351. //add for dcm img hard
  352. FDEBUG("Enter SetExpMode:[{$}]", value.c_str());
  353. if (m_DoseUnit.m_ExpMode->Update(value))
  354. {
  355. FireNotify(AttrKey::EXPMODE, m_DoseUnit.m_ExpMode->JSGet());
  356. }
  357. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  358. m_DoseUnit.m_GenTotalExpNumber->Update(0);
  359. m_DoseUnit.m_GenCurrentExpNumber->Update(0);
  360. //add for dcm img hard
  361. FireNotify(m_DoseUnit.m_TubeTargetMaterial->GetKey(), m_DoseUnit.m_TubeTargetMaterial->JSGet());
  362. FireNotify(m_DoseUnit.m_TubeAngle->GetKey(), m_DoseUnit.m_TubeAngle->JSGet());
  363. if (m_pCollDev != nullptr)
  364. {
  365. FINFO("act CollDev ReportMessageToDicom");
  366. m_pCollDev->ReportMessageToDicom();
  367. }
  368. if (m_pMechDev != nullptr)
  369. {
  370. FINFO("act MechDev ReportMessageToDicom");
  371. m_pMechDev->ReportMessageToDicom();
  372. }
  373. return RET_STATUS::RET_SUCCEED;
  374. }
  375. RET_STATUS nsGEN::DemoDevice::SetEXAMMode(std::string value)
  376. {
  377. FDEBUG("Enter SetEXAMMode:[{$}]", value.c_str());
  378. return RET_STATUS::RET_SUCCEED;
  379. }
  380. RET_STATUS nsGEN::DemoDevice::ActiveSyncMode(_tSyncModeArgs value)
  381. {
  382. FDEBUG("Enter ActiveSyncMode:Sync[{$},{$}],WS[{$}]", value.strSyncMode.c_str(), value.strSyncValue.c_str(), value.strWS.c_str());
  383. return RET_STATUS::RET_SUCCEED;
  384. }
  385. //点片
  386. RET_STATUS nsGEN::DemoDevice::IncKV()
  387. {
  388. FDEBUG("Enter IncKV");
  389. if (m_bIsDemo)
  390. {
  391. if (!m_DoseUnit.m_KV->CanInc()) return RET_STATUS::RET_SUCCEED;
  392. m_DoseUnit.m_KV->Inc();
  393. FireNotify(m_DoseUnit.m_KV->GetKey(), m_DoseUnit.m_KV->JSGet());
  394. m_DoseUnit.m_PostKV->Update(m_DoseUnit.m_KV->Get());
  395. }
  396. return RET_STATUS::RET_SUCCEED;
  397. }
  398. RET_STATUS nsGEN::DemoDevice::DecKV()
  399. {
  400. FDEBUG("Enter DecKV");
  401. if (m_bIsDemo)
  402. {
  403. if (!m_DoseUnit.m_KV->CanDec()) return RET_STATUS::RET_SUCCEED;
  404. m_DoseUnit.m_KV->Dec();
  405. m_DoseUnit.m_PostKV->Update(m_DoseUnit.m_KV->Get());
  406. FireNotify(m_DoseUnit.m_KV->GetKey(), m_DoseUnit.m_KV->JSGet());
  407. }
  408. return RET_STATUS::RET_SUCCEED;
  409. }
  410. RET_STATUS nsGEN::DemoDevice::SetKV(float value)
  411. {
  412. FDEBUG("Enter SetKV:[{$}]", value);
  413. if (m_bIsDemo)
  414. {
  415. m_DoseUnit.m_KV->Update(value);
  416. m_DoseUnit.m_PostKV->Update(value);
  417. FireNotify(m_DoseUnit.m_KV->GetKey(), m_DoseUnit.m_KV->JSGet());
  418. }
  419. return RET_STATUS::RET_SUCCEED;
  420. }
  421. RET_STATUS nsGEN::DemoDevice::IncKVL()
  422. {
  423. FDEBUG("Enter IncKVL");
  424. if (m_bIsDemo)
  425. {
  426. float tempKV = m_DoseUnit.m_KV->Get();
  427. tempKV += 4;
  428. if (m_DoseUnit.m_KV->Update(tempKV))
  429. {
  430. FDEBUG("IncKVL:[{$}] ok", tempKV);
  431. FireNotify(m_DoseUnit.m_KV->GetKey(), m_DoseUnit.m_KV->JSGet());
  432. return RET_STATUS::RET_SUCCEED;
  433. }
  434. else
  435. {
  436. FDEBUG("IncKVL:[{$}] failed,Exceeding limit", tempKV);
  437. return RET_STATUS::RET_FAILED;
  438. }
  439. }
  440. return RET_STATUS::RET_SUCCEED;
  441. }
  442. RET_STATUS nsGEN::DemoDevice::DecKVL()
  443. {
  444. FDEBUG("Enter DecKVL");
  445. if (m_bIsDemo)
  446. {
  447. float tempKV = m_DoseUnit.m_KV->Get();
  448. tempKV -= 4;
  449. if (m_DoseUnit.m_KV->Update(tempKV))
  450. {
  451. FDEBUG("DecKVL:[{$}] ok", tempKV);
  452. FireNotify(m_DoseUnit.m_KV->GetKey(), m_DoseUnit.m_KV->JSGet());
  453. return RET_STATUS::RET_SUCCEED;
  454. }
  455. else
  456. {
  457. FDEBUG("DecKVL:[{$}] failed,Exceeding limit", tempKV);
  458. return RET_STATUS::RET_FAILED;
  459. }
  460. }
  461. return RET_STATUS::RET_SUCCEED;
  462. }
  463. RET_STATUS nsGEN::DemoDevice::IncMA()
  464. {
  465. FDEBUG("Enter IncMA");
  466. if (m_bIsDemo)
  467. {
  468. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P &&
  469. m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
  470. {
  471. FWARN("Techmode is not 3P, can't IncMA");
  472. return RET_STATUS::RET_SUCCEED;
  473. }
  474. float value = m_DoseUnit.m_MA->Get();
  475. int npos = FindPositon(g_MA_List, sizeof(g_MA_List) / sizeof(float), value);
  476. if (npos < 0)
  477. {
  478. return RET_STATUS::RET_FAILED;
  479. }
  480. else if (npos == sizeof(g_MA_List) / sizeof(float) - 1)
  481. {
  482. return RET_STATUS::RET_SUCCEED;
  483. }
  484. npos += 1;
  485. float temp = g_MA_List[npos];
  486. m_DoseUnit.m_MA->Update(temp);
  487. m_DoseUnit.m_PostMA->Update(temp);
  488. FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet());
  489. ComputeMAS();
  490. }
  491. return RET_STATUS::RET_SUCCEED;
  492. }
  493. RET_STATUS nsGEN::DemoDevice::DecMA()
  494. {
  495. FDEBUG("Enter DecMA");
  496. if (m_bIsDemo)
  497. {
  498. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P &&
  499. m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
  500. {
  501. FWARN("Techmode is not 3P, can't DecMA");
  502. return RET_STATUS::RET_FAILED;
  503. }
  504. float value = m_DoseUnit.m_MA->Get();
  505. int npos = FindPositon(g_MA_List, sizeof(g_MA_List) / sizeof(float), value);
  506. if (npos < 0)
  507. {
  508. return RET_STATUS::RET_FAILED;
  509. }
  510. else if (npos == 0)
  511. {
  512. return RET_STATUS::RET_SUCCEED;
  513. }
  514. npos -= 1;
  515. float temp = g_MA_List[npos];
  516. m_DoseUnit.m_MA->Update(temp);
  517. m_DoseUnit.m_PostMA->Update(temp);
  518. FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet());
  519. ComputeMAS();
  520. }
  521. return RET_STATUS::RET_SUCCEED;
  522. }
  523. RET_STATUS nsGEN::DemoDevice::SetMA(float value)
  524. {
  525. FDEBUG("Enter SetMA:[{$}]", value);
  526. if (m_bIsDemo)
  527. {
  528. //if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P &&
  529. // m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
  530. //{
  531. // FWARN("Techmode is not 3P, can't SetMA");
  532. // return RET_STATUS::RET_FAILED;
  533. //}
  534. int npos = FindPositon(g_MA_List, sizeof(g_MA_List) / sizeof(float), value);
  535. if (npos < 0)
  536. {
  537. return RET_STATUS::RET_FAILED;
  538. }
  539. float temp = g_MA_List[npos];
  540. m_DoseUnit.m_MA->Update(temp);
  541. m_DoseUnit.m_PostMA->Update(temp);
  542. FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet());
  543. }
  544. return RET_STATUS::RET_SUCCEED;
  545. }
  546. RET_STATUS nsGEN::DemoDevice::IncMS()
  547. {
  548. FDEBUG("Enter IncMS");
  549. if (m_bIsDemo)
  550. {
  551. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P &&
  552. m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
  553. {
  554. FWARN("Techmode is not 3P, can't IncMAS");
  555. return RET_STATUS::RET_FAILED;
  556. }
  557. float value = m_DoseUnit.m_MS->Get();
  558. int npos = FindPositon(g_MS_List, sizeof(g_MS_List) / sizeof(float), value);
  559. if (npos < 0)
  560. {
  561. return RET_STATUS::RET_FAILED;
  562. }
  563. else if (npos == sizeof(g_MS_List) / sizeof(float) - 1)
  564. {
  565. return RET_STATUS::RET_SUCCEED;
  566. }
  567. npos += 1;
  568. float temp = g_MS_List[npos];
  569. m_DoseUnit.m_MS->Update(temp);
  570. m_DoseUnit.m_PostMS->Update(temp);
  571. FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet());
  572. ComputeMAS();
  573. }
  574. return RET_STATUS::RET_SUCCEED;
  575. }
  576. RET_STATUS nsGEN::DemoDevice::DecMS()
  577. {
  578. FDEBUG("Enter DecMS");
  579. if (m_bIsDemo)
  580. {
  581. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P &&
  582. m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
  583. {
  584. FWARN("Techmode is not 3P, can't DecMS");
  585. return RET_STATUS::RET_FAILED;
  586. }
  587. float value = m_DoseUnit.m_MS->Get();
  588. int npos = FindPositon(g_MS_List, sizeof(g_MS_List) / sizeof(float), value);
  589. if (npos < 0)
  590. {
  591. return RET_STATUS::RET_FAILED;
  592. }
  593. else if (npos == 0)
  594. {
  595. return RET_STATUS::RET_SUCCEED;
  596. }
  597. npos -= 1;
  598. float temp = g_MS_List[npos];
  599. m_DoseUnit.m_MS->Update(temp);
  600. m_DoseUnit.m_PostMS->Update(temp);
  601. FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet());
  602. ComputeMAS();
  603. }
  604. return RET_STATUS::RET_SUCCEED;
  605. }
  606. RET_STATUS nsGEN::DemoDevice::SetMS(float value)
  607. {
  608. FDEBUG("Enter SetMS:[{$}]", value);
  609. if (m_bIsDemo)
  610. {
  611. //if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P &&
  612. // m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
  613. //{
  614. // FWARN("Techmode is not 3P, can't SetMS");
  615. // return RET_STATUS::RET_FAILED;
  616. //}
  617. int npos = FindPositon(g_MS_List, sizeof(g_MS_List) / sizeof(float), value);
  618. if (npos < 0)
  619. {
  620. return RET_STATUS::RET_FAILED;
  621. }
  622. float temp = g_MS_List[npos];
  623. m_DoseUnit.m_MS->Update(temp);
  624. m_DoseUnit.m_PostMS->Update(temp);
  625. FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet());
  626. }
  627. return RET_STATUS::RET_SUCCEED;
  628. }
  629. RET_STATUS nsGEN::DemoDevice::IncMAS()
  630. {
  631. FDEBUG("Enter IncMAS");
  632. if (m_bIsDemo)
  633. {
  634. /*if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P &&
  635. m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  636. {
  637. FWARN("Techmode is not 2P, can't IncMAS");
  638. return RET_STATUS::RET_NOSUPPORT;
  639. }*/
  640. float value = m_DoseUnit.m_MAS->Get();
  641. int npos = FindPositon(g_MAS_List, sizeof(g_MAS_List) / sizeof(float), value);
  642. if (npos < 0)
  643. {
  644. return RET_STATUS::RET_SUCCEED;
  645. }
  646. else if (npos == sizeof(g_MAS_List) / sizeof(float) - 1)
  647. {
  648. return RET_STATUS::RET_SUCCEED;
  649. }
  650. npos += 1;
  651. float temp = g_MAS_List[npos];
  652. m_DoseUnit.m_MAS->Update(temp);
  653. m_DoseUnit.m_PostMAS->Update(temp);
  654. FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet());
  655. }
  656. return RET_STATUS::RET_SUCCEED;
  657. }
  658. RET_STATUS nsGEN::DemoDevice::DecMAS()
  659. {
  660. FDEBUG("Enter DecMAS");
  661. if (m_bIsDemo)
  662. {
  663. /*if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P &&
  664. m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  665. {
  666. FWARN("Techmode is not 2P, can't DecMAS");
  667. return RET_STATUS::RET_NOSUPPORT;
  668. }*/
  669. float value = m_DoseUnit.m_MAS->Get();
  670. int npos = FindPositon(g_MAS_List, sizeof(g_MAS_List) / sizeof(float), value);
  671. if (npos < 0)
  672. {
  673. return RET_STATUS::RET_FAILED;
  674. }
  675. else if (npos == 0)
  676. {
  677. return RET_STATUS::RET_SUCCEED;
  678. }
  679. npos -= 1;
  680. float temp = g_MAS_List[npos];
  681. m_DoseUnit.m_MAS->Update(temp);
  682. m_DoseUnit.m_PostMAS->Update(temp);
  683. FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet());
  684. }
  685. return RET_STATUS::RET_SUCCEED;
  686. }
  687. RET_STATUS nsGEN::DemoDevice::SetMAS(float value)
  688. {
  689. FDEBUG("Enter SetMAS:[{$}]", value);
  690. if (m_bIsDemo)
  691. {
  692. //if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P &&
  693. // m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  694. //{
  695. // FWARN("Techmode is not 2P, can't SetMAS");
  696. // return RET_STATUS::RET_NOSUPPORT;
  697. //}
  698. int npos = FindPositon(g_MAS_List, sizeof(g_MAS_List) / sizeof(float), value);
  699. if (npos < 0)
  700. {
  701. return RET_STATUS::RET_FAILED;
  702. }
  703. float temp = g_MAS_List[npos];
  704. m_DoseUnit.m_MAS->Update(temp);
  705. m_DoseUnit.m_PostMAS->Update(temp);
  706. FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet());
  707. }
  708. return RET_STATUS::RET_SUCCEED;
  709. }
  710. RET_STATUS nsGEN::DemoDevice::IncMASL()
  711. {
  712. FDEBUG("Enter IncMASL");
  713. if (m_bIsDemo)
  714. {
  715. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P &&
  716. m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  717. {
  718. FWARN("Techmode is not 2P, can't IncMASL");
  719. return RET_STATUS::RET_NOSUPPORT;
  720. }
  721. float tempMAS = m_DoseUnit.m_MAS->Get();
  722. tempMAS += 4;
  723. if (m_DoseUnit.m_MAS->Update(tempMAS))
  724. {
  725. FDEBUG("IncMASL:[{$}] ok", tempMAS);
  726. FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet());
  727. return RET_STATUS::RET_SUCCEED;
  728. }
  729. else
  730. {
  731. FDEBUG("IncMASL:[{$}] failed,Exceeding limit", tempMAS);
  732. return RET_STATUS::RET_FAILED;
  733. }
  734. }
  735. return RET_STATUS::RET_SUCCEED;
  736. }
  737. RET_STATUS nsGEN::DemoDevice::DecMASL()
  738. {
  739. FDEBUG("Enter DecMASL");
  740. if (m_bIsDemo)
  741. {
  742. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P &&
  743. m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  744. {
  745. FWARN("Techmode is not 2P, can't DecMASL");
  746. return RET_STATUS::RET_NOSUPPORT;
  747. }
  748. float tempMAS = m_DoseUnit.m_MAS->Get();
  749. tempMAS -= 4;
  750. if (m_DoseUnit.m_MAS->Update(tempMAS))
  751. {
  752. FDEBUG("DecMASL:[{$}] ok", tempMAS);
  753. FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet());
  754. return RET_STATUS::RET_SUCCEED;
  755. }
  756. else
  757. {
  758. FDEBUG("DecMASL:[{$}] failed,Exceeding limit", tempMAS);
  759. return RET_STATUS::RET_FAILED;
  760. }
  761. }
  762. return RET_STATUS::RET_SUCCEED;
  763. }
  764. void nsGEN::DemoDevice::ComputeMAS()
  765. {
  766. float tempMa = m_DoseUnit.m_MA->Get();
  767. float tempMs = m_DoseUnit.m_MS->Get();
  768. float tempMAS = tempMa * tempMs / 1000.0f;
  769. //m_DoseUnit.m_MAS->Update(tempMAS);
  770. m_DoseUnit.m_PostMAS->Update(tempMAS);
  771. FDEBUG("ComputeMAS:MA[{$}] MS[{$}] tempMAS[{$}] MAS[{$}] postMAS[{$}]",
  772. tempMa, tempMs,tempMAS,m_DoseUnit.m_MAS->Get(), m_DoseUnit.m_PostMAS->Get());
  773. FireNotify(m_DoseUnit.m_MAS->GetKey(), tempMAS);
  774. }
  775. RET_STATUS nsGEN::DemoDevice::SetTechmode(int value)
  776. {
  777. FDEBUG("Enter SetTechmode:[{$}]", value);
  778. if (m_bIsDemo)
  779. {
  780. if (!m_DoseUnit.m_Techmode->Verify(value)) return RET_STATUS::RET_SUCCEED;
  781. m_DoseUnit.m_Techmode->Update(value);
  782. FireNotify(m_DoseUnit.m_Techmode->GetKey(), m_DoseUnit.m_Techmode->JSGet());
  783. switch (value)
  784. {
  785. case AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P:
  786. {
  787. FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet());
  788. FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet());
  789. ComputeMAS();
  790. }
  791. break;
  792. case AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P:
  793. {
  794. FireNotify(m_DoseUnit.m_MA->GetKey(), "0");
  795. FireNotify(m_DoseUnit.m_MS->GetKey(), "0");
  796. FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet());
  797. }
  798. break;
  799. case AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P:
  800. {
  801. FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet());
  802. FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet());
  803. ComputeMAS();
  804. }
  805. break;
  806. case AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P:
  807. {
  808. FireNotify(m_DoseUnit.m_MA->GetKey(), "0");
  809. FireNotify(m_DoseUnit.m_MS->GetKey(), "0");
  810. FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet());
  811. }
  812. break;
  813. }
  814. }
  815. return RET_STATUS::RET_SUCCEED;
  816. }
  817. RET_STATUS nsGEN::DemoDevice::SetFocus(int value)
  818. {
  819. FDEBUG("Enter SetFocus:[{$}]", value);
  820. if (m_bIsDemo)
  821. {
  822. if (!m_DoseUnit.m_Focus->Verify(value)) return RET_STATUS::RET_SUCCEED;
  823. m_DoseUnit.m_Focus->Update(value);
  824. FireNotify(m_DoseUnit.m_Focus->GetKey(), m_DoseUnit.m_Focus->JSGet());
  825. if (m_DoseUnit.m_Focus->Get() == AttrKey::FOCUS_SMALL)
  826. FireNotify(AttrKey::FOCUSSIZE, m_DoseUnit.m_FocusSmall);
  827. else
  828. FireNotify(AttrKey::FOCUSSIZE, m_DoseUnit.m_FocusLarge);
  829. }
  830. return RET_STATUS::RET_SUCCEED;
  831. }
  832. RET_STATUS nsGEN::DemoDevice::SetAECDensity(int value)
  833. {
  834. FDEBUG("Enter SetAECDensity:[{$}]", value);
  835. if (m_bIsDemo)
  836. {
  837. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_1P &&
  838. m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P &&
  839. m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
  840. {
  841. printf("\n Techmode is not AEC, can't SetAECDensity");
  842. return RET_STATUS::RET_NOSUPPORT;
  843. }
  844. if (!m_DoseUnit.m_AECDensity->Verify(value)) return RET_STATUS::RET_FAILED;
  845. m_DoseUnit.m_AECDensity->Update(value);
  846. FireNotify(m_DoseUnit.m_AECDensity->GetKey(), m_DoseUnit.m_AECDensity->JSGet());
  847. }
  848. return RET_STATUS::RET_SUCCEED;
  849. }
  850. RET_STATUS nsGEN::DemoDevice::IncAECDensity()
  851. {
  852. FDEBUG("Enter IncAECDensity");
  853. if (m_bIsDemo)
  854. {
  855. FDEBUG("Enter IncAECDensity");
  856. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_1P &&
  857. m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P &&
  858. m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
  859. {
  860. FWARN("Techmode is not AEC, can't IncAECDensity");
  861. return RET_STATUS::RET_NOSUPPORT;
  862. }
  863. if (m_DoseUnit.m_AECDensity->CanInc())
  864. {
  865. m_DoseUnit.m_AECDensity->Inc();
  866. FireNotify(m_DoseUnit.m_AECDensity->GetKey(), m_DoseUnit.m_AECDensity->JSGet());
  867. }
  868. }
  869. return RET_STATUS::RET_SUCCEED;
  870. }
  871. RET_STATUS nsGEN::DemoDevice::DecAECDensity()
  872. {
  873. FDEBUG("Enter DecAECDensity");
  874. if (m_bIsDemo)
  875. {
  876. FDEBUG("Enter DecAECDensity");
  877. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_1P &&
  878. m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P &&
  879. m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
  880. {
  881. FWARN("Techmode is not AEC, can't DecAECDensity");
  882. return RET_STATUS::RET_NOSUPPORT;
  883. }
  884. if (m_DoseUnit.m_AECDensity->CanDec())
  885. {
  886. m_DoseUnit.m_AECDensity->Dec();
  887. FireNotify(m_DoseUnit.m_AECDensity->GetKey(), m_DoseUnit.m_AECDensity->JSGet());
  888. }
  889. }
  890. return RET_STATUS::RET_SUCCEED;
  891. }
  892. RET_STATUS nsGEN::DemoDevice::SetAECField(int value)
  893. {
  894. FDEBUG("Enter SetAECField:[{$}]", value);
  895. if (m_bIsDemo)
  896. {
  897. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_AEC)
  898. {
  899. printf("\n Techmode is not AEC, can't set AEC");
  900. return RET_STATUS::RET_FAILED;
  901. }
  902. if (!m_DoseUnit.m_AECField->Verify(value)) return RET_STATUS::RET_SUCCEED;
  903. int npos = FindPositon(g_AECFIELD_List, sizeof(g_AECFIELD_List) / sizeof(int), value);
  904. if (npos < 0)
  905. {
  906. return RET_STATUS::RET_FAILED;
  907. }
  908. int temp = value;
  909. m_DoseUnit.m_AECField->Update(temp);
  910. FireNotify(m_DoseUnit.m_AECField->GetKey(), m_DoseUnit.m_AECField->JSGet());
  911. }
  912. return RET_STATUS::RET_SUCCEED;
  913. }
  914. RET_STATUS nsGEN::DemoDevice::SetAECFilm(int value)
  915. {
  916. FDEBUG("Enter SetAECFilm:[{$}]", value);
  917. if (m_bIsDemo)
  918. {
  919. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_AEC)
  920. {
  921. printf("\n Techmode is not AEC, can't set AEC");
  922. return RET_STATUS::RET_FAILED;
  923. }
  924. if (!m_DoseUnit.m_AECFilm->Verify(value)) return RET_STATUS::RET_SUCCEED;
  925. m_DoseUnit.m_AECFilm->Update(value);
  926. FireNotify(m_DoseUnit.m_AECFilm->GetKey(), m_DoseUnit.m_AECFilm->JSGet());
  927. }
  928. return RET_STATUS::RET_SUCCEED;
  929. }
  930. RET_STATUS nsGEN::DemoDevice::SetAPR(const _tAPRArgs& t)
  931. {
  932. FDEBUG("SetAPR:KV={$},MA={$},MS={$},MAS={$},Focus={$},Techmode={$},WS={$},AECDensity={$},AECField={$},AECFilm={$}",
  933. t.fKV, t.fMA, t.fMS, t.fMAS, t.nFocus, t.nTechmode, t.nWS, t.nAECDensity, t.nAECField, t.nAECFilm);
  934. if (m_bIsDemo)
  935. {
  936. //note:缺少WS
  937. SetTechmode(t.nTechmode);
  938. SetKV(t.fKV);
  939. SetMA(t.fMA);
  940. SetMS(t.fMS);
  941. SetMAS(t.fMAS);
  942. SetFocus(t.nFocus);
  943. SetAECDensity(t.nAECDensity);
  944. SetAECField(t.nAECField);
  945. SetAECFilm(t.nAECFilm);
  946. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
  947. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
  948. {
  949. ComputeMAS();
  950. }
  951. m_DoseUnit.m_HE->Update(50);
  952. FireNotify(m_DoseUnit.m_HE->GetKey(), m_DoseUnit.m_HE->JSGet());
  953. }
  954. else
  955. {
  956. FireNotify(m_DoseUnit.m_Techmode->GetKey(), t.nTechmode);
  957. FireNotify(m_DoseUnit.m_KV->GetKey(), t.fKV);
  958. FireNotify(m_DoseUnit.m_MA->GetKey(), t.fMA);
  959. FireNotify(m_DoseUnit.m_MS->GetKey(), t.fMS);
  960. FireNotify(m_DoseUnit.m_MAS->GetKey(), t.fMAS);
  961. FireNotify(m_DoseUnit.m_Focus->GetKey(), t.nFocus);
  962. FireNotify(m_DoseUnit.m_AECDensity->GetKey(), t.nAECDensity);
  963. FireNotify(m_DoseUnit.m_AECField->GetKey(), t.nAECField);
  964. FireNotify(m_DoseUnit.m_AECFilm->GetKey(), t.nAECFilm);
  965. }
  966. return RET_STATUS::RET_SUCCEED;
  967. }
  968. RET_STATUS nsGEN::DemoDevice::SetAPRArray(vector<_tAPRArgs>& APRarray)
  969. {
  970. FDEBUG("SetAPRArray:[size:{$}]", APRarray.size());
  971. if (m_bIsDemo)
  972. {
  973. m_APRarray = APRarray;
  974. for (int i = 0; i < m_APRarray.size(); i++)
  975. {
  976. FDEBUG("APRArray[{$}]:WS={$},Techmode={$},Focus={$},KV={$},MA={$},MS={$},MAS={$},AECDensity={$},AECField={$},AECFilm={$}",
  977. i, m_APRarray[i].nWS, m_APRarray[i].nTechmode, m_APRarray[i].nFocus,
  978. m_APRarray[i].fKV, m_APRarray[i].fMA, m_APRarray[i].fMS, m_APRarray[i].fMAS,
  979. m_APRarray[i].nAECDensity, m_APRarray[i].nAECField, m_APRarray[i].nAECFilm);
  980. }
  981. if (!m_APRarray.empty())
  982. {
  983. SetAPR(m_APRarray[0]);
  984. m_DoseUnit.m_GenTotalExpNumber->Update(m_APRarray.size());
  985. m_DoseUnit.m_GenCurrentExpNumber->Update(1);
  986. FDEBUG("SetAPRArray:[totalEXP:{$}, currentEXP:{$}]", m_DoseUnit.m_GenTotalExpNumber->Get(), m_DoseUnit.m_GenCurrentExpNumber->Get());
  987. }
  988. }
  989. return RET_STATUS::RET_SUCCEED;
  990. }
  991. RET_STATUS nsGEN::DemoDevice::QueryPostKV(float& value)
  992. {
  993. value = m_DoseUnit.m_KV->Get();
  994. return RET_STATUS::RET_SUCCEED;
  995. }
  996. RET_STATUS nsGEN::DemoDevice::QueryPostMA(float& value)
  997. {
  998. value = m_DoseUnit.m_MA->Get();
  999. return RET_STATUS::RET_SUCCEED;
  1000. }
  1001. RET_STATUS nsGEN::DemoDevice::QueryPostMS(float& value)
  1002. {
  1003. value = m_DoseUnit.m_MS->Get();
  1004. return RET_STATUS::RET_SUCCEED;
  1005. }
  1006. RET_STATUS nsGEN::DemoDevice::QueryPostMAS(float& value)
  1007. {
  1008. value = m_DoseUnit.m_MAS->Get();
  1009. return RET_STATUS::RET_SUCCEED;
  1010. }
  1011. RET_STATUS nsGEN::DemoDevice::SetFrameRate(float frameRate)
  1012. {
  1013. FDEBUG("Enter SetFrameRate:[{$}]", frameRate);
  1014. return RET_STATUS::RET_SUCCEED;
  1015. }
  1016. RET_STATUS nsGEN::DemoDevice::SetCollimatorDev(OemCollimator* dev)
  1017. {
  1018. FDEBUG("Enter SetCollimatorDev");
  1019. if (dev)
  1020. m_pCollDev.reset(dev);
  1021. return RET_STATUS::RET_SUCCEED;
  1022. }
  1023. RET_STATUS nsGEN::DemoDevice::SetMechDev(OemMechanical* dev)
  1024. {
  1025. FDEBUG("Enter SetMechDev");
  1026. if (dev)
  1027. m_pMechDev.reset(dev);
  1028. return RET_STATUS::RET_SUCCEED;
  1029. }
  1030. RET_STATUS nsGEN::DemoDevice::SetCollimatorSize(int xsize, int ysize)
  1031. {
  1032. FDEBUG("Enter SetCollimatorSize:[x:{$}, y:{$}]", xsize, ysize);
  1033. if (m_pCollDev)
  1034. {
  1035. m_pCollDev->UpdateCollimatorXSize(xsize);
  1036. m_pCollDev->UpdateCollimatorYSize(ysize);
  1037. }
  1038. return RET_STATUS::RET_SUCCEED;
  1039. }
  1040. RET_STATUS nsGEN::DemoDevice::SetCollimatorLight(unsigned short pParams)
  1041. {
  1042. FDEBUG("Enter SetCollimatorLight:[{$}]", (int)pParams);
  1043. //此处应该发送指令给GEN,并且该指令可以控制 coll 的LED
  1044. return RET_STATUS::RET_SUCCEED;
  1045. }
  1046. RET_STATUS nsGEN::DemoDevice::SetAutoTracking(int nAutoTracking)
  1047. {
  1048. FDEBUG("Enter SetAutoTracking:[{$}]", nAutoTracking);
  1049. if (m_pMechDev)
  1050. m_pMechDev->UpdateMammo_Depress(nAutoTracking);
  1051. return RET_STATUS::RET_SUCCEED;
  1052. }
  1053. RET_STATUS nsGEN::DemoDevice::SetFilter(int nFilterType)
  1054. {
  1055. FDEBUG("Enter SetFilter:[{$}]", nFilterType);
  1056. if (m_pMechDev)
  1057. {
  1058. m_pMechDev->UpdateMammo_FT(nFilterType);
  1059. }
  1060. if (m_pCollDev)
  1061. {
  1062. m_pCollDev->UpdateCollimatorFilter(nFilterType);
  1063. }
  1064. return RET_STATUS::RET_SUCCEED;
  1065. }
  1066. RET_STATUS nsGEN::DemoDevice::SetGrid(int nGridType)
  1067. {
  1068. FDEBUG("Enter SetGrid:[{$}]", nGridType);
  1069. if (m_pMechDev)
  1070. m_pMechDev->UpdateGrid(nGridType);
  1071. return RET_STATUS::RET_SUCCEED;
  1072. }
  1073. RET_STATUS nsGEN::DemoDevice::GetTomoResults(ResDataObject& resultAngle, ResDataObject& resultHeight)
  1074. {
  1075. RET_STATUS ret = RET_STATUS::RET_SUCCEED;
  1076. if (resultAngle.size() == 1 && resultHeight.size() == 1)
  1077. {
  1078. m_resultAngle.update(resultAngle.GetKey(0), (float)resultAngle[0]);
  1079. FINFO("GetTomoResults insert, key={$},value={$}", resultAngle.GetKey(0), (float)resultAngle[0]);
  1080. }
  1081. else
  1082. {
  1083. FINFO("GetTomoResults size={$}", m_resultAngle.size());
  1084. for (int i = 0; i < m_resultAngle.size(); i++)
  1085. {
  1086. resultAngle.update(m_resultAngle.GetKey(i), (float)m_resultAngle[i]);
  1087. FINFO("GetTomoResults ket={$} ,resule={$}", m_resultAngle.GetKey(i), (float)m_resultAngle[i]);
  1088. }
  1089. resultHeight.update("0", 63.71);
  1090. resultHeight.update("1", 63.97);
  1091. resultHeight.update("2", 64.21);
  1092. resultHeight.update("3", 64.41);
  1093. resultHeight.update("4", 64.59);
  1094. resultHeight.update("5", 64.73);
  1095. resultHeight.update("6", 64.84);
  1096. resultHeight.update("7", 64.92);
  1097. resultHeight.update("8", 64.97);
  1098. resultHeight.update("9", 64.99);
  1099. resultHeight.update("10", 64.98);
  1100. resultHeight.update("11", 64.94);
  1101. resultHeight.update("12", 64.87);
  1102. resultHeight.update("13", 64.72);
  1103. resultHeight.update("14", 64.63);
  1104. resultHeight.update("15", 64.47);
  1105. resultHeight.update("16", 64.28);
  1106. resultHeight.update("17", 64.05);
  1107. m_resultAngle.clear();
  1108. }
  1109. return ret;
  1110. }
  1111. //透视
  1112. RET_STATUS nsGEN::DemoDevice::IncFluKV()
  1113. {
  1114. FDEBUG("Enter IncFluKV");
  1115. float KV = m_DoseUnit.m_FLKV->Get()+1;
  1116. if (m_DoseUnit.m_FLKV->Update(KV))
  1117. {
  1118. FireNotify(m_DoseUnit.m_FLKV->GetKey(), m_DoseUnit.m_FLKV->JSGet());
  1119. }
  1120. return RET_STATUS::RET_SUCCEED;
  1121. }
  1122. RET_STATUS nsGEN::DemoDevice::DecFluKV()
  1123. {
  1124. FDEBUG("Enter DecFluKV");
  1125. float KV = m_DoseUnit.m_FLKV->Get() - 1;
  1126. if (m_DoseUnit.m_FLKV->Update(KV))
  1127. {
  1128. FireNotify(m_DoseUnit.m_FLKV->GetKey(), m_DoseUnit.m_FLKV->JSGet());
  1129. }
  1130. return RET_STATUS::RET_SUCCEED;
  1131. }
  1132. RET_STATUS nsGEN::DemoDevice::SetFluKV(float value)
  1133. {
  1134. FDEBUG("Enter SetFluKV:[{$}]", value);
  1135. if (m_DoseUnit.m_FLKV->Update(value))
  1136. {
  1137. FireNotify(m_DoseUnit.m_FLKV->GetKey(), m_DoseUnit.m_FLKV->JSGet());
  1138. }
  1139. return RET_STATUS::RET_SUCCEED;
  1140. }
  1141. RET_STATUS nsGEN::DemoDevice::IncFluMA()
  1142. {
  1143. FDEBUG("Enter IncFluKV");
  1144. float MA = m_DoseUnit.m_FLMA->Get()+1;
  1145. if (m_DoseUnit.m_FLMA->Update(MA))
  1146. {
  1147. FireNotify(m_DoseUnit.m_FLMA->GetKey(), m_DoseUnit.m_FLMA->JSGet());
  1148. }
  1149. return RET_STATUS::RET_SUCCEED;
  1150. }
  1151. RET_STATUS nsGEN::DemoDevice::DecFluMA()
  1152. {
  1153. FDEBUG("Enter DecFluKV");
  1154. float MA = m_DoseUnit.m_FLMA->Get() - 1;
  1155. if (m_DoseUnit.m_FLMA->Update(MA))
  1156. {
  1157. FireNotify(m_DoseUnit.m_FLMA->GetKey(), m_DoseUnit.m_FLMA->JSGet());
  1158. }
  1159. return RET_STATUS::RET_SUCCEED;
  1160. }
  1161. RET_STATUS nsGEN::DemoDevice::SetFluMA(float value)
  1162. {
  1163. FDEBUG("Enter SetFluMA:[{$}]", value);
  1164. if (m_DoseUnit.m_FLMA->Update(value))
  1165. {
  1166. FireNotify(m_DoseUnit.m_FLMA->GetKey(), m_DoseUnit.m_FLMA->JSGet());
  1167. }
  1168. return RET_STATUS::RET_SUCCEED;
  1169. }
  1170. RET_STATUS nsGEN::DemoDevice::IncFluMS()
  1171. {
  1172. return RET_STATUS::RET_SUCCEED;
  1173. }
  1174. RET_STATUS nsGEN::DemoDevice::DecFluMS()
  1175. {
  1176. return RET_STATUS::RET_SUCCEED;
  1177. }
  1178. RET_STATUS nsGEN::DemoDevice::SetFluMS(float value)
  1179. {
  1180. return RET_STATUS::RET_SUCCEED;
  1181. }
  1182. RET_STATUS nsGEN::DemoDevice::SetPPS(float frameRate)
  1183. {
  1184. FDEBUG("Enter SetPPS:[{$}]", frameRate);
  1185. if (m_DoseUnit.m_PPS->Update(frameRate))
  1186. {
  1187. FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
  1188. }
  1189. return RET_STATUS::RET_SUCCEED;
  1190. }
  1191. RET_STATUS nsGEN::DemoDevice::INCPPS()
  1192. {
  1193. FDEBUG("Enter INCPPS");
  1194. float PPS = m_DoseUnit.m_PPS->Get()+1;
  1195. if (m_DoseUnit.m_PPS->Update(PPS))
  1196. {
  1197. FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
  1198. }
  1199. return RET_STATUS::RET_SUCCEED;
  1200. }
  1201. RET_STATUS nsGEN::DemoDevice::DECPPS()
  1202. {
  1203. FDEBUG("Enter DECPPS");
  1204. float PPS = m_DoseUnit.m_PPS->Get() - 1;
  1205. if (m_DoseUnit.m_PPS->Update(PPS))
  1206. {
  1207. FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
  1208. }
  1209. return RET_STATUS::RET_SUCCEED;
  1210. }
  1211. RET_STATUS nsGEN::DemoDevice::SetPluseWidth(float fplusewidth)
  1212. {
  1213. return RET_STATUS::RET_SUCCEED;
  1214. }
  1215. RET_STATUS nsGEN::DemoDevice::SetABSMode(int nMode)
  1216. {
  1217. FDEBUG("Enter SetABSMode:[{$}]", nMode);
  1218. if (m_DoseUnit.m_ABSStatus->Update(nMode))
  1219. {
  1220. FireNotify(m_DoseUnit.m_ABSStatus->GetKey(), m_DoseUnit.m_ABSStatus->JSGet());
  1221. }
  1222. return RET_STATUS::RET_SUCCEED;
  1223. }
  1224. RET_STATUS nsGEN::DemoDevice::SetABSCurve(int curveNum)
  1225. {
  1226. return RET_STATUS::RET_SUCCEED;
  1227. }
  1228. RET_STATUS nsGEN::DemoDevice::IncABSCurve()
  1229. {
  1230. return RET_STATUS::RET_SUCCEED;
  1231. }
  1232. RET_STATUS nsGEN::DemoDevice::DecABSCurve()
  1233. {
  1234. return RET_STATUS::RET_SUCCEED;
  1235. }
  1236. RET_STATUS nsGEN::DemoDevice::SetABSValue(float fABSValue)
  1237. {
  1238. return RET_STATUS::RET_SUCCEED;
  1239. }
  1240. RET_STATUS nsGEN::DemoDevice::SetABSTargetEXI(float fEXIValue)
  1241. {
  1242. return RET_STATUS::RET_SUCCEED;
  1243. }
  1244. float nsGEN::DemoDevice::GetFluIntTimer()
  1245. {
  1246. return RET_STATUS::RET_SUCCEED;
  1247. }
  1248. float nsGEN::DemoDevice::GetFluAccTimer()
  1249. {
  1250. return RET_STATUS::RET_SUCCEED;
  1251. }
  1252. RET_STATUS nsGEN::DemoDevice::ResetFluTimer(int ntype)
  1253. {
  1254. FDEBUG("ReSetFluAccTimer:[{$}]", ntype);
  1255. return RET_STATUS::RET_SUCCEED;
  1256. }
  1257. RET_STATUS nsGEN::DemoDevice::SetFluPre(int bPrepare)
  1258. {
  1259. return RET_STATUS::RET_SUCCEED;
  1260. }
  1261. RET_STATUS nsGEN::DemoDevice::SetFluEXP(int bPrepare)
  1262. {
  1263. return RET_STATUS::RET_SUCCEED;
  1264. }
  1265. RET_STATUS nsGEN::DemoDevice::SetFLFMode(std::string value)
  1266. {
  1267. FDEBUG("Enter SetFLFMode:[{$}]", value.c_str());
  1268. if (value == "CF")
  1269. {
  1270. m_DoseUnit.m_FLMode->Update(AttrKey::GENERATOR_FLMODE_CF);
  1271. SetExpMode(AttrKey::EXPMODE_TYPE::CoutineSerial);
  1272. }
  1273. else if (value == "PF")
  1274. {
  1275. m_DoseUnit.m_FLMode->Update(AttrKey::GENERATOR_FLMODE_PF);
  1276. SetExpMode(AttrKey::EXPMODE_TYPE::PulseSerial);
  1277. }
  1278. FireNotify(AttrKey::FLUMode, m_DoseUnit.m_FLMode->JSGet());
  1279. return RET_STATUS::RET_SUCCEED;
  1280. }
  1281. RET_STATUS nsGEN::DemoDevice::SetFluMAG(int nsize)
  1282. {
  1283. return RET_STATUS::RET_SUCCEED;
  1284. }
  1285. RET_STATUS nsGEN::DemoDevice::DisableMAG()
  1286. {
  1287. return RET_STATUS::RET_SUCCEED;
  1288. }
  1289. RET_STATUS nsGEN::DemoDevice::SetFluDoseLever(int nlever)
  1290. {
  1291. FDEBUG("Enter SetFluDoseLever:[{$}]", nlever);
  1292. if (m_DoseUnit.m_DoseLevel->Update(nlever))
  1293. {
  1294. FireNotify(AttrKey::FLUDoseLevel, m_DoseUnit.m_DoseLevel->JSGet());
  1295. }
  1296. return RET_STATUS::RET_SUCCEED;
  1297. }
  1298. RET_STATUS nsGEN::DemoDevice::SetHalfDose(int nlever)
  1299. {
  1300. return RET_STATUS::RET_SUCCEED;
  1301. }
  1302. RET_STATUS nsGEN::DemoDevice::TransferRadCurve(int ncurve)
  1303. {
  1304. return RET_STATUS::RET_SUCCEED;
  1305. }
  1306. RET_STATUS nsGEN::DemoDevice::SetAPF(const _tAPFArgs& t)
  1307. {
  1308. FDEBUG("SetAPF: nWS={$}, Flu mode={$}, ABS mode={$}, DoseLever={$}, nFlkv={$}, FlMA={$}",
  1309. t.nWS, t.nFluMode, t.nABSMode, t.nDoseLever, t.nFLKV, t.fFLMA, t.nPPS);
  1310. if (m_DoseUnit.m_FLKV->Update(t.nFLKV))
  1311. {
  1312. FireNotify(m_DoseUnit.m_FLKV->GetKey(), m_DoseUnit.m_FLKV->JSGet());
  1313. }
  1314. if (m_DoseUnit.m_FLMA->Update(t.fFLMA))
  1315. {
  1316. FireNotify(m_DoseUnit.m_FLMA->GetKey(), m_DoseUnit.m_FLMA->JSGet());
  1317. }
  1318. if (m_DoseUnit.m_PPS->Update(t.nPPS))
  1319. {
  1320. FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
  1321. }
  1322. if (m_DoseUnit.m_DoseLevel->Update(t.nDoseLever))
  1323. {
  1324. FireNotify(AttrKey::FLUDoseLevel, m_DoseUnit.m_DoseLevel->JSGet());
  1325. }
  1326. if (m_DoseUnit.m_FLMode->Update(t.nFluMode))
  1327. {
  1328. FireNotify(AttrKey::FLUMode, m_DoseUnit.m_FLMode->JSGet());
  1329. }
  1330. if (m_DoseUnit.m_ABSStatus->Update(t.nABSMode))
  1331. {
  1332. FireNotify(m_DoseUnit.m_ABSStatus->GetKey(), m_DoseUnit.m_ABSStatus->JSGet());
  1333. }
  1334. return RET_STATUS::RET_SUCCEED;
  1335. }
  1336. //额外
  1337. void nsGEN::DemoDevice::FireNotify(string key, int context)
  1338. {
  1339. //std::unique_lock<std::mutex> uqeLock(m_MSGLock);
  1340. char szInfo[64] = { 0 };
  1341. sprintf(szInfo, "%d", context);
  1342. std::string str = szInfo;
  1343. EventCenter->OnNotify(1, key, str);//(int)ATTRACTION_SET 2
  1344. }
  1345. void nsGEN::DemoDevice::FireNotify(std::string key, float context)
  1346. {
  1347. //std::unique_lock<std::mutex> uqeLock(m_MSGLock);
  1348. char szInfo[64] = { 0 };
  1349. sprintf(szInfo, "%.2f", context);
  1350. std::string str = szInfo;
  1351. EventCenter->OnNotify(1, key, str);//(int)ATTRACTION_SET 2
  1352. }
  1353. void nsGEN::DemoDevice::FireNotify(std::string key, std::string context)
  1354. {
  1355. //std::unique_lock<std::mutex> uqeLock(m_MSGLock);
  1356. EventCenter->OnNotify(1, key, context);
  1357. }
  1358. int nsGEN::DemoDevice::GetConfData()
  1359. {
  1360. //灯丝大小
  1361. if (m_GenConfig.GetKeyCount(ConfKey::CcosTubeInfo) > 0)
  1362. {
  1363. string tempValue = m_GenConfig[ConfKey::CcosTubeInfo].encode();
  1364. m_DoseUnit.m_TubeInfo.reset(new TUBEINFOMould(tempValue));
  1365. }
  1366. if (m_GenConfig.GetKeyCount(ConfKey::CcosFocusSmall) > 0)
  1367. {
  1368. float tempValue = (float)m_GenConfig[ConfKey::CcosFocusSmall];
  1369. m_DoseUnit.m_FocusSmall = tempValue;
  1370. }
  1371. if (m_GenConfig.GetKeyCount(ConfKey::CcosFocusLarge) > 0)
  1372. {
  1373. float tempValue = (float)m_GenConfig[ConfKey::CcosFocusLarge];
  1374. m_DoseUnit.m_FocusLarge = tempValue;
  1375. }
  1376. //同步模式
  1377. if (m_GenConfig.GetKeyCount("WSTable") > 0)
  1378. {
  1379. int WSNamber = (int)m_GenConfig["WSTable"];
  1380. EnSYNMode WSSYN = (EnSYNMode)((int)m_GenConfig["SYNTable"]);
  1381. m_arrWSMap[cfgWorkStationKey("Table", AttrKey::TABLE)] = cfgWorkStationData("Table", WSNamber, WSSYN);
  1382. FDEBUG("cfg Table WS[{$}],SYN[{$}]", WSNamber, (int)WSSYN);
  1383. }
  1384. if (m_GenConfig.GetKeyCount("WSWall") > 0)
  1385. {
  1386. int WSNamber = (int)m_GenConfig["WSWall"];
  1387. EnSYNMode WSSYN = (EnSYNMode)((int)m_GenConfig["SYNWall"]);
  1388. m_arrWSMap[cfgWorkStationKey("Wall", AttrKey::WALL)] = cfgWorkStationData("Wall", WSNamber, WSSYN);
  1389. FDEBUG("cfg Wall WS[{$}],SYN[{$}]", WSNamber, (int)WSSYN);
  1390. }
  1391. if (m_GenConfig.GetKeyCount("WSFree") > 0)
  1392. {
  1393. int WSNamber = (int)m_GenConfig["WSFree"];
  1394. EnSYNMode WSSYN = (EnSYNMode)((int)m_GenConfig["SYNFree"]);
  1395. m_arrWSMap[cfgWorkStationKey("Free", AttrKey::MOBILE)] = cfgWorkStationData("Free", WSNamber, WSSYN);
  1396. FDEBUG("cfg Free WS[{$}],SYN[{$}]", WSNamber, (int)WSSYN);
  1397. }
  1398. if (m_GenConfig.GetKeyCount("WSTomo") > 0)
  1399. {
  1400. int WSNamber = (int)m_GenConfig["WSTomo"];
  1401. EnSYNMode WSSYN = (EnSYNMode)((int)m_GenConfig["SYNTomo"]);
  1402. m_arrWSMap[cfgWorkStationKey("Tomo", AttrKey::TOMO)] = cfgWorkStationData("Tomo", WSNamber, WSSYN);
  1403. FDEBUG("cfg Tomo WS[{$}],SYN[{$}]", WSNamber, (int)WSSYN);
  1404. }
  1405. if (m_GenConfig.GetKeyCount("WSConventional") > 0)
  1406. {
  1407. int WSNamber = (int)m_GenConfig["WSConventional"];
  1408. EnSYNMode WSSYN = (EnSYNMode)((int)m_GenConfig["SYNConventional"]);
  1409. m_arrWSMap[cfgWorkStationKey("Direct", AttrKey::CONVENTIONAL)] = cfgWorkStationData("Direct", WSNamber, WSSYN);
  1410. FDEBUG("cfg Conventional WS[{$}],SYN[{$}]", WSNamber, (int)WSSYN);
  1411. }
  1412. //参数初始化
  1413. ResDataObject temp;
  1414. temp.update("Max", 150);
  1415. temp.update("Min", 40);
  1416. temp.update("List", "");
  1417. for (int i = 0; i < sizeof(g_KV_List) / sizeof(g_KV_List[0]); i++)
  1418. {
  1419. char chindex[4] = { 0 };
  1420. sprintf(chindex, "%d", i);
  1421. temp["List"].add(chindex, g_KV_List[i] / 10.0f);
  1422. }
  1423. m_DoseUnit.m_KVList.reset(new KVLISTMould(temp.encode()));
  1424. temp.clear();
  1425. temp.update("Max", 1000);
  1426. temp.update("Min", 8);
  1427. temp.update("List", "");
  1428. for (int i = 0; i < sizeof(g_MAS_List) / sizeof(g_MAS_List[0]); i++)
  1429. {
  1430. char chindex[4] = { 0 };
  1431. sprintf(chindex, "%d", i);
  1432. temp["List"].add(chindex, g_MAS_List[i]);
  1433. }
  1434. m_DoseUnit.m_mAsList.reset(new MASLISTMould(temp.encode()));
  1435. //add by wxx for delworks:解决前端提出KV值太少的问题 20230913
  1436. FireNotify(m_DoseUnit.m_KVList->GetKey(), m_DoseUnit.m_KVList->JSGet());
  1437. return true;
  1438. }
  1439. void nsGEN::DemoDevice::FireErrorMessage(const bool Act, const int Code, const char* ResInfo)
  1440. {
  1441. string ErrorCode("Demo_ERR_");
  1442. ErrorCode += std::to_string(Code);
  1443. int level = Demo_REGULATION_LEVEL::REG_ERRO;
  1444. if (Act)
  1445. {
  1446. FERROR("add {$}:{$}", ErrorCode.c_str(), ResInfo);
  1447. m_MSGUnit->AddErrorMessage(ErrorCode.c_str(), level, ResInfo);
  1448. }
  1449. else
  1450. {
  1451. FERROR("del {$}:{$}", ErrorCode.c_str(), ResInfo);
  1452. if (Code == 0)
  1453. m_MSGUnit->DelErrorMessage("0", level, ResInfo);
  1454. else
  1455. m_MSGUnit->DelErrorMessage(ErrorCode.c_str(), level, ResInfo);
  1456. }
  1457. }
  1458. void nsGEN::DemoDevice::FireWarnMessage(const bool Act, const int Code, const char* ResInfo)
  1459. {
  1460. string ErrorCode("Demo_WAR_");
  1461. ErrorCode += std::to_string(Code);
  1462. int level = Demo_REGULATION_LEVEL::REG_WARN;
  1463. if (Act)
  1464. {
  1465. FERROR("add {$}:{$}", ErrorCode.c_str(), ResInfo);
  1466. m_MSGUnit->AddWarnMessage(ErrorCode.c_str(), level, ResInfo);
  1467. }
  1468. else
  1469. {
  1470. FERROR("del {$}:{$}", ErrorCode.c_str(), ResInfo);
  1471. m_MSGUnit->DelWarnMessage(ErrorCode.c_str(), level, ResInfo);
  1472. }
  1473. }
  1474. bool nsGEN::DemoDevice::StartHardwareStatusThread()
  1475. {
  1476. FINFO("enter Start HardwareStatus Thread ");
  1477. if (m_pHardwareStatusThread == 0) // Linux使用0表示无效线程ID
  1478. {
  1479. // 创建线程属性对象(可选)
  1480. pthread_attr_t attr;
  1481. pthread_attr_init(&attr);
  1482. pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
  1483. // 创建线程
  1484. int ret = pthread_create(&m_pHardwareStatusThread,
  1485. &attr,
  1486. HardwareStatusThread,
  1487. this);
  1488. pthread_attr_destroy(&attr); // 销毁属性对象
  1489. if (ret != 0)
  1490. {
  1491. FERROR("Start HardwareStatus Thread Failed");
  1492. return false;
  1493. }
  1494. }
  1495. return true;
  1496. }
  1497. void* nsGEN::DemoDevice::HardwareStatusThread(void* pParam)
  1498. {
  1499. DemoDevice* pCurGen = (DemoDevice*)pParam;
  1500. if (pCurGen == NULL)
  1501. {
  1502. return NULL;
  1503. }
  1504. usleep(1500000);
  1505. FINFO("HardwareStatusThread start");
  1506. bool bActExpFlag = false;
  1507. FINFO("m_iStateChangeInterval = {$},m_iAutoExpActWaitTime = {$}", pCurGen->m_iStateChangeInterval, pCurGen->m_iAutoExpActWaitTime);;
  1508. FINFO("Request Fault Status:GENSTATE STATUS_SHUTDOWN -> STATUS_STANDBY");
  1509. pCurGen->m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
  1510. pCurGen->FireNotify(AttrKey::GENSTATE, pCurGen->m_DoseUnit.m_GenState->JSGet());
  1511. while (true)
  1512. {
  1513. while (!bActExpFlag)
  1514. {
  1515. //FINFO("loopAction: begin \n");
  1516. if (pCurGen->m_iAutoExpFlag > 0)
  1517. {
  1518. pCurGen->m_iAutoExpFlag = 0;
  1519. usleep(pCurGen->m_iAutoExpActWaitTime*1000);
  1520. if (pCurGen->m_iAutoExpFlag == 0)
  1521. {
  1522. FINFO("loopAction: start Exp Workflow \n");
  1523. bActExpFlag = true;
  1524. break;
  1525. }
  1526. else
  1527. {
  1528. FINFO("loopAction: Exp param changed restart wait \n");
  1529. continue;
  1530. }
  1531. }
  1532. usleep(pCurGen->m_iAutoExpActWaitTime*1000);
  1533. }
  1534. while (bActExpFlag)
  1535. {
  1536. FINFO("loopAction: act exp Workflow \n");
  1537. switch (pCurGen->m_DoseUnit.m_GenSynState->Get())
  1538. {
  1539. case nsGEN::AttrKey::GENERATOR_RAD_OFF:
  1540. {
  1541. FINFO("exp Status change:RAD_OFF -> PREPARE(PR1)", pCurGen->m_DoseUnit.m_GenSynState->Get());
  1542. pCurGen->m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_PREPARE);
  1543. }break;
  1544. case nsGEN::AttrKey::GENERATOR_RAD_PREPARE:
  1545. {
  1546. FINFO("exp Status change:PREPARE(PR1) -> RAD_READY(PR2)", pCurGen->m_DoseUnit.m_GenSynState->Get());
  1547. pCurGen->m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_READY);
  1548. }break;
  1549. case nsGEN::AttrKey::GENERATOR_RAD_READY:
  1550. {
  1551. FINFO("exp Status change:RAD_READY(PR2) -> XRAYON(XR1)", pCurGen->m_DoseUnit.m_GenSynState->Get());
  1552. pCurGen->m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_XRAYON);
  1553. }break;
  1554. case nsGEN::AttrKey::GENERATOR_RAD_XRAYON:
  1555. {
  1556. FINFO("exp Status change:XRAYON(XR1) -> XRAYOFF(XR0)", pCurGen->m_DoseUnit.m_GenSynState->Get());
  1557. pCurGen->m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_XRAYOFF);
  1558. FDEBUG("Request Fault Status:GENSTATE STATUS_STANDBY -> STATUS_EXP");
  1559. pCurGen->m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_EXP);
  1560. pCurGen->FireNotify(AttrKey::GENSTATE, pCurGen->m_DoseUnit.m_GenState->JSGet());
  1561. FINFO("exp Status value:POSTKV[{$}],POSTMA[{$}],POSTMS[{$}],POSTMAS[{$}]",
  1562. pCurGen->m_DoseUnit.m_PostKV->Get(), pCurGen->m_DoseUnit.m_PostMA->Get(), pCurGen->m_DoseUnit.m_PostMS->Get(), pCurGen->m_DoseUnit.m_PostMAS->Get());
  1563. pCurGen->FireNotify(AttrKey::POSTKV, pCurGen->m_DoseUnit.m_PostKV->JSGet());
  1564. pCurGen->FireNotify(AttrKey::POSTMA, pCurGen->m_DoseUnit.m_PostMA->JSGet());
  1565. #if DEMO_DAEC_Flag
  1566. int temp = pCurGen->m_DoseUnit.m_PostMS->Get();
  1567. if (pCurGen->m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P ||
  1568. pCurGen->m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P ||
  1569. pCurGen->m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_1P)
  1570. {
  1571. temp /= 2;
  1572. }
  1573. pCurGen->FireNotify(AttrKey::POSTMS, temp);
  1574. #else
  1575. pCurGen->FireNotify(AttrKey::POSTMS, pCurGen->m_DoseUnit.m_PostMS->JSGet());
  1576. #endif // DEMO_DAEC_Flag
  1577. pCurGen->FireNotify(AttrKey::POSTMAS, pCurGen->m_DoseUnit.m_PostMAS->JSGet());
  1578. }break;
  1579. case nsGEN::AttrKey::GENERATOR_RAD_XRAYOFF:
  1580. {
  1581. FINFO("exp Status change:XRAYOFF(XR0) -> RAD_OFF", pCurGen->m_DoseUnit.m_GenSynState->Get());
  1582. pCurGen->m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_OFF);
  1583. FDEBUG("Request Fault Status:GENSTATE STATUS_EXP -> STATUS_STANDBY");
  1584. pCurGen->m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
  1585. pCurGen->FireNotify(AttrKey::GENSTATE, pCurGen->m_DoseUnit.m_GenState->JSGet());
  1586. }
  1587. default:
  1588. {
  1589. bActExpFlag = false;
  1590. }
  1591. }
  1592. pCurGen->FireNotify(pCurGen->m_DoseUnit.m_GenSynState->GetKey(), pCurGen->m_DoseUnit.m_GenSynState->JSGet());
  1593. usleep(pCurGen->m_iStateChangeInterval*1000);
  1594. }
  1595. }
  1596. FINFO("HardwareStatusThread stop");
  1597. return NULL;
  1598. }
  1599. //驱动
  1600. nsGEN::DemoDriver::DemoDriver()
  1601. {
  1602. m_bDemoMode = false;
  1603. m_bDemoConnected = false;
  1604. m_bDemoInitDataFlag = false;
  1605. m_pDriGenDev = nullptr;
  1606. //m_pDriCollDev = nullptr;
  1607. //m_pDriMechDev = nullptr;
  1608. m_pAttribute.reset(new ResDataObject());
  1609. m_pDescription.reset(new ResDataObject());
  1610. }
  1611. nsGEN::DemoDriver::~DemoDriver()
  1612. {
  1613. }
  1614. auto nsGEN::DemoDriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
  1615. {
  1616. std::cout << "Enter CreateDevice, index=" << index<< std::endl;
  1617. FINFO("Enter CreateDevice, index={$}", index);
  1618. if (index == 0)
  1619. {
  1620. m_pDriGenDev = new DemoDevice(EventCenter, m_ConfigFileName);
  1621. auto dev = std::unique_ptr<IODevice>(new IODevice(m_pDriGenDev));
  1622. return dev;
  1623. }
  1624. else if (index == 1)
  1625. {
  1626. std::cout << "Enter CreateDevice COLL" << std::endl;
  1627. FINFO("Enter CreateDevice COLL");
  1628. if (m_bDemoInitDataFlag)
  1629. {
  1630. int nXSize = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["XSize"]).c_str());
  1631. int nYSize = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["YSize"]).c_str());
  1632. int nFilter = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["Filter"]).c_str());
  1633. int nSID = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["SID"]).c_str());
  1634. int nAngle = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["Angle"]).c_str());
  1635. int nMode = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["Mode"]).c_str());
  1636. m_pDriCollDev = new OemCollimator(std::shared_ptr<IOEventCenter>(new IOEventCenter()), nXSize, nYSize, nFilter, nSID, nAngle, nMode);
  1637. }
  1638. else
  1639. m_pDriCollDev = new OemCollimator(std::shared_ptr<IOEventCenter>(new IOEventCenter()));
  1640. auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDriCollDev));
  1641. m_pDriCollDev->SetCtrlDev(m_pDriGenDev);
  1642. m_pDriGenDev->SetCollimatorDev(m_pDriCollDev);
  1643. FINFO("Leave CreateDevice COLL");
  1644. return dev;
  1645. }
  1646. else if (index == 2)
  1647. {
  1648. std::cout << "Enter CreateDevice Mech" << std::endl;
  1649. FINFO("Enter CreateDevice Mech");
  1650. if (m_bDemoInitDataFlag)
  1651. {
  1652. int nGrid = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["Grid"]).c_str());
  1653. int nAE = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["AE"]).c_str());
  1654. int nFT = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["FT"]).c_str());
  1655. int nPressureState = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["PressureState"]).c_str());
  1656. int nCompPressureDEC = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["CompPressureDEC"]).c_str());
  1657. int nDepress = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["Depress"]).c_str());
  1658. float fMechAngle = (atof)(((string)m_InitDataFile["CONFIGURATION"]["MechAngle"]).c_str());
  1659. float fMechHeight = (atof)(((string)m_InitDataFile["CONFIGURATION"]["MechHeight"]).c_str());
  1660. float fPressureValue = (atof)(((string)m_InitDataFile["CONFIGURATION"]["PressureValue"]).c_str());
  1661. float fAGD = (atof)(((string)m_InitDataFile["CONFIGURATION"]["AGD"]).c_str());
  1662. float fMAG = (atof)(((string)m_InitDataFile["CONFIGURATION"]["MAG"]).c_str());
  1663. m_pDriMechDev = new OemMechanical(std::shared_ptr<IOEventCenter>(new IOEventCenter()), nGrid, nAE, nFT, nPressureState, nCompPressureDEC, nDepress, fMechAngle, fMechHeight, fPressureValue, fAGD, fMAG);
  1664. }
  1665. else
  1666. m_pDriMechDev = new OemMechanical(std::shared_ptr<IOEventCenter>(new IOEventCenter()));
  1667. auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDriMechDev));
  1668. m_pDriMechDev->SetCtrlDev(m_pDriGenDev);
  1669. m_pDriGenDev->SetMechDev(m_pDriMechDev);
  1670. FINFO("Leave CreateDevice Mech");
  1671. return dev;
  1672. }
  1673. std::cout << "unknown index" << std::endl;
  1674. FERROR("unknown index");
  1675. unique_ptr <IODevice> dev;
  1676. return dev;
  1677. }
  1678. void nsGEN::DemoDriver::FireNotify(int code, std::string key, std::string content)
  1679. {
  1680. EventCenter->OnNotify(code, key, content);
  1681. }
  1682. //Log4CPP::Logger* mLog::gLogger = nullptr;
  1683. void nsGEN::DemoDriver::Prepare()
  1684. {
  1685. // 初始化日志系统
  1686. std::string strLogPath = GetProcessDirectory() + R"(/Conf/log_config.xml)";
  1687. std::string LogHost = "DemoGEN";
  1688. std::string moduleName = "DemoGEN";
  1689. bool ret = initLogModule(
  1690. LogHost, // 主机名(用于日志路径中的{host}占位符)
  1691. moduleName, // 唯一模块名
  1692. strLogPath, // 配置文件路径
  1693. true // 是否输出到控制台(可选)
  1694. );
  1695. if (!ret) {
  1696. std::cerr << "Log init failed!" << std::endl;
  1697. return;
  1698. }
  1699. GENDEMO_SetLocalModuleName(moduleName);
  1700. ResDataObject r_config;
  1701. if (r_config.loadFile(m_ConfigFileName.c_str()))
  1702. {
  1703. if(r_config["CONFIGURATION"].GetKeyCount("IsDemo")>0)
  1704. {
  1705. m_bDemoMode = (atoi)(((string)r_config["CONFIGURATION"]["IsDemo"]).c_str());
  1706. }
  1707. }
  1708. string strDataPath = GetProcessDirectory() + R"(/OEMDrivers/Generator/Demo/InitData.xml)";
  1709. try {
  1710. if (m_InitDataFile.loadFile(strDataPath.c_str()))
  1711. {
  1712. m_bDemoInitDataFlag = true;
  1713. FINFO("exist InitData");
  1714. }
  1715. //else
  1716. FINFO("can not open InitData[{$}]", strDataPath.c_str());
  1717. }
  1718. catch (const ResDataObjectExption&)
  1719. {
  1720. FERROR("open InitData failed");
  1721. }
  1722. }
  1723. bool nsGEN::DemoDriver::Connect()
  1724. {
  1725. m_bDemoConnected = true;
  1726. return true; //return SCF_ERR::SCF_SUCCEED;
  1727. }
  1728. void nsGEN::DemoDriver::Disconnect()
  1729. {
  1730. m_bDemoConnected = false;
  1731. }
  1732. bool nsGEN::DemoDriver::isConnected() const
  1733. {
  1734. return m_bDemoConnected;
  1735. }
  1736. std::string nsGEN::DemoDriver::DriverProbe()
  1737. {
  1738. printf("line= %d,%s %s\n", __LINE__, __FUNCTION__, m_ConfigFileName.c_str());
  1739. ResDataObject r_config, HardwareInfo;
  1740. if (r_config.loadFile(m_ConfigFileName.c_str()))
  1741. {
  1742. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  1743. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  1744. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  1745. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  1746. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  1747. }
  1748. else
  1749. {
  1750. HardwareInfo.add("MajorID", "Generator");
  1751. HardwareInfo.add("MinorID", "Dr");
  1752. HardwareInfo.add("VendorID", "DEMO");
  1753. HardwareInfo.add("ProductID", "HF");
  1754. HardwareInfo.add("SerialID", "1234");
  1755. }
  1756. string ret = HardwareInfo.encode();
  1757. printf("line= %d,%s %s\n", __LINE__, __FUNCTION__, m_ConfigFileName.c_str());
  1758. return ret;
  1759. }
  1760. bool nsGEN::DemoDriver::GetDeviceConfig(std::string& Cfg)
  1761. {
  1762. //printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  1763. //Cfg = m_GenConfig.encode();
  1764. //return true;
  1765. Cfg = m_DeviceConfigSend.encode();
  1766. printf("GetDeviceConfig over , %s", Cfg.c_str());
  1767. return true;
  1768. }
  1769. bool nsGEN::DemoDriver::SetDeviceConfig(std::string Cfg)
  1770. {
  1771. FINFO("--Func-- SetDeviceConfig {$}\n", Cfg.c_str());
  1772. printf("\n--Func-- SetDeviceConfig %s\n", Cfg.c_str());
  1773. ResDataObject DeviceConfig;
  1774. DeviceConfig.decode(Cfg.c_str());
  1775. ResDataObject DescriptionTempEx;
  1776. DescriptionTempEx = DeviceConfig["DeviceConfig"]["Attribute"];
  1777. FDEBUG("Attribute:{$}", DescriptionTempEx.encode());
  1778. bool bSaveFile = false; //true:重新保存配置文件
  1779. string strAccess = "";
  1780. for (int i = 0; i < DescriptionTempEx.size(); i++)
  1781. {
  1782. string strKey = DescriptionTempEx.GetKey(i);
  1783. FINFO("{$}", strKey.c_str());
  1784. printf("%s\n", strKey.c_str());
  1785. try
  1786. {
  1787. if (m_pAttribute->GetFirstOf(strKey.c_str()) >= 0)
  1788. {
  1789. strAccess = (string)(*m_pDescription)[strKey.c_str()]["Access"];
  1790. if ("RW" == strAccess)
  1791. {
  1792. //修改对应配置,在其他单元的配置项要同时调用其修改函数修改真实值
  1793. //1. 修改内存中的值,用于给上层发消息
  1794. (*m_pAttribute)[strKey.c_str()] = DescriptionTempEx[i];
  1795. //2. 拿到Innerkey
  1796. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  1797. FINFO("nConfigInfoCount {$}", nConfigInfoCount);
  1798. string strTemp = ""; //存储AttributeKey
  1799. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  1800. {
  1801. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  1802. if (strTemp == strKey)
  1803. {
  1804. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  1805. break;
  1806. }
  1807. }
  1808. //3. 修改配置文件中的值
  1809. if (SetDeviceConfigValue(m_Configurations, strTemp.c_str(), 1, DescriptionTempEx[i]))
  1810. {
  1811. FDEBUG("SetDeviceConfigValue over");
  1812. bSaveFile = true;
  1813. }
  1814. }
  1815. else
  1816. {
  1817. FINFO("{$} is not a RW configuration item", strKey.c_str());
  1818. }
  1819. }
  1820. else
  1821. {
  1822. FINFO("without this attribute {$}", strKey.c_str());
  1823. }
  1824. }
  1825. catch (ResDataObjectExption& e)
  1826. {
  1827. printf("\nSetDriverConfig crashed: %s\n", e.what());
  1828. FERROR("SetDriverConfig crashed: {$}", e.what());
  1829. return false;
  1830. }
  1831. }
  1832. if (bSaveFile)
  1833. {
  1834. //3. 重新保存配置文件
  1835. SaveConfigFile(true);
  1836. }
  1837. return true;
  1838. }
  1839. bool nsGEN::DemoDriver::SaveConfigFile(bool bSendNotify)
  1840. {
  1841. m_ConfigAll["CONFIGURATION"] = m_Configurations;
  1842. bool bRt = m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
  1843. FINFO("SaveConfigFile over {$}", bRt);
  1844. return true;
  1845. }
  1846. bool nsGEN::DemoDriver::GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue)
  1847. {
  1848. strValue = "";
  1849. string strTemp = pInnerKey;
  1850. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  1851. {
  1852. int pos = 0;
  1853. ResDataObject resTemp = config;
  1854. while ((pos = strTemp.find_first_of(',')) != string::npos)
  1855. {
  1856. string Key = strTemp.substr(0, pos);
  1857. string TempValue = resTemp[Key.c_str()].encode();
  1858. // printf("-TempValue=== %s", TempValue.c_str());
  1859. resTemp.clear();
  1860. resTemp.decode(TempValue.c_str());
  1861. strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
  1862. //printf("-************--%s", strTemp.c_str());
  1863. }
  1864. if (strTemp != "")
  1865. {
  1866. strValue = (string)resTemp[strTemp.c_str()];
  1867. }
  1868. else
  1869. {
  1870. strValue = (string)resTemp;
  1871. }
  1872. }
  1873. //printf("------------%s", strValue.c_str());
  1874. return true;
  1875. }
  1876. bool nsGEN::DemoDriver::SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue)
  1877. {
  1878. string strTemp = pInnerKey;
  1879. FDEBUG("Begin to change {$} item value to {$}", pInnerKey, szValue);
  1880. printf("\n Begin to change {%s} item value to {%s}\n", pInnerKey, szValue);
  1881. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  1882. {
  1883. try {
  1884. int pos = 0;
  1885. ResDataObject* resTemp = &config;
  1886. while ((pos = strTemp.find_first_of(',')) != string::npos)
  1887. {
  1888. string Key = strTemp.substr(0, pos);
  1889. resTemp = &(*resTemp)[Key.c_str()];
  1890. strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
  1891. }
  1892. if (strTemp != "")
  1893. {
  1894. //if ((strTemp.compare("WSTable") == 0) ||
  1895. // (strTemp.compare("WSWall") == 0) ||
  1896. // (strTemp.compare("WSFree") == 0) ||
  1897. // (strTemp.compare("WSTomo") == 0) ||
  1898. // (strTemp.compare("WSConventional") == 0)
  1899. // )
  1900. //{
  1901. // int sum = (*szValue) + 1;
  1902. // (*resTemp)[strTemp.c_str()] = (char*)(&sum);
  1903. //}
  1904. //else
  1905. // (*resTemp)[strTemp.c_str()] = szValue;
  1906. (*resTemp)[strTemp.c_str()] = szValue;
  1907. }
  1908. else
  1909. {
  1910. *resTemp = szValue;
  1911. }
  1912. }
  1913. catch (ResDataObjectExption& e)
  1914. {
  1915. FERROR("SetDriverConfigvalue crashed: {$}", e.what());
  1916. return false;
  1917. }
  1918. }
  1919. return true;
  1920. }
  1921. std::string nsGEN::DemoDriver::GetResource()
  1922. {
  1923. ResDataObject r_config, temp;
  1924. if (!temp.loadFile(m_ConfigFileName.c_str()))
  1925. {
  1926. return "";
  1927. }
  1928. m_ConfigAll = temp;
  1929. r_config = temp["CONFIGURATION"];
  1930. m_Configurations = r_config;
  1931. ResDataObject DescriptionTemp;
  1932. ResDataObject DescriptionSend;
  1933. ResDataObject m_DescriptionSend;
  1934. ResDataObject ListTemp;
  1935. string strTemp = ""; //用于读取字符串配置信息
  1936. string strIndex = ""; //用于读取配置信息中的List项
  1937. int nTemp = -1; //用于读取整型配置信息
  1938. char sstream[10] = { 0 }; //用于转换值
  1939. string strValue = ""; //用于存储配置的值
  1940. string strType = ""; //用于存储配置的类型 int/float/string...
  1941. /***
  1942. * 1. 通过循环,将所有配置项写到pDeviceConfig
  1943. * 2. 记录配置项的内部key以及配置类型,类型对应了不同配置文件路径,用于读写真实值
  1944. ***/
  1945. try
  1946. {
  1947. //便利ConfigToolInfo 中 所有的AttributeInfo 属性段
  1948. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  1949. m_pAttribute->clear();
  1950. m_pDescription->clear();
  1951. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  1952. {
  1953. DescriptionTemp.clear();
  1954. DescriptionSend.clear();
  1955. ListTemp.clear();
  1956. //AttributeType
  1957. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Type"];
  1958. DescriptionTemp.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
  1959. DescriptionSend.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
  1960. strType = strTemp; //记录配置项的类型
  1961. //AttributeKey
  1962. //1. 根据AttributeType,内部key和配置路径,拿到当前的真实值
  1963. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  1964. nTemp = (int)m_Configurations["ConfigToolInfo"][nInfoIndex]["PathID"];
  1965. GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue); //得到strValue的值
  1966. //printf("********************************innerkey=%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
  1967. //2. 赋值
  1968. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  1969. if ("int" == strType)
  1970. {
  1971. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  1972. }
  1973. else if ("float" == strType)
  1974. {
  1975. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  1976. }
  1977. else //其它先按string类型处理
  1978. {
  1979. (*m_pAttribute).add(strTemp.c_str(), strValue.c_str());
  1980. }
  1981. //printf("********************************outkey =%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
  1982. //AttributeAccess
  1983. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Access"];
  1984. DescriptionTemp.add(ConfKey::CcosAccess, strTemp.c_str());
  1985. DescriptionSend.add(ConfKey::CcosAccess, strTemp.c_str());
  1986. /*
  1987. //AttributeRangeMin
  1988. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMin"];
  1989. if (strTemp != "") //不需要的配置项为空
  1990. {
  1991. DescriptionTemp.add(ConfKey::CcosRangeMin, strTemp.c_str());
  1992. }
  1993. //AttributeRangeMax
  1994. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMax"];
  1995. if (strTemp != "") //不需要的配置项为空
  1996. {
  1997. DescriptionTemp.add(ConfKey::CcosRangeMax, strTemp.c_str());
  1998. }
  1999. */
  2000. //AttributeList
  2001. nTemp = m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListNum"];
  2002. if (nTemp > 0) //ListNum不大于0时说明不需要list配置
  2003. {
  2004. for (int nListIndex = 0; nListIndex < nTemp; nListIndex++)
  2005. {
  2006. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListInfo"][nListIndex];
  2007. auto temKey = std::to_string(nListIndex);
  2008. ListTemp.add(temKey.c_str(), strTemp.c_str());
  2009. }
  2010. DescriptionTemp.add(ConfKey::CcosList, ListTemp);
  2011. DescriptionSend.add(ConfKey::CcosList, ListTemp.encode());
  2012. }
  2013. //AttributeRequired
  2014. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Required"];
  2015. DescriptionTemp.add(ConfKey::CcosRequired, strTemp.c_str());
  2016. DescriptionSend.add(ConfKey::CcosRequired, strTemp.c_str());
  2017. //AttributeDefaultValue
  2018. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["DefaultValue"];
  2019. if (strTemp != "") //不需要的配置项为空
  2020. {
  2021. DescriptionTemp.add(ConfKey::CcosDefaultValue, strTemp.c_str());
  2022. DescriptionSend.add(ConfKey::CcosDefaultValue, strTemp.c_str());
  2023. }
  2024. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  2025. (*m_pDescription).add(strTemp.c_str(), DescriptionTemp);
  2026. m_DescriptionSend.add(strTemp.c_str(), DescriptionSend.encode());
  2027. }
  2028. }
  2029. catch (ResDataObjectExption& e)
  2030. {
  2031. FERROR("Get config error: {$}", e.what());
  2032. return "";
  2033. }
  2034. ResDataObject resDeviceResource;
  2035. resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
  2036. resDeviceResource.add(ConfKey::CcosGeneratorDescription, (*m_pDescription));
  2037. ResDataObject DescriptionTempEx;
  2038. DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
  2039. m_DeviceConfig.clear();
  2040. m_DeviceConfig = DescriptionTempEx;
  2041. //FDEBUG("local ************* get resource over {$}", DescriptionTempEx.encode());
  2042. //printf("local ************* get resource over %s \n", DescriptionTempEx.encode());
  2043. resDeviceResource.clear();
  2044. resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
  2045. resDeviceResource.add(ConfKey::CcosGeneratorDescription, m_DescriptionSend);
  2046. DescriptionTempEx.clear();
  2047. DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
  2048. m_DeviceConfigSend.clear();
  2049. m_DeviceConfigSend = DescriptionTempEx;
  2050. string res = m_DeviceConfigSend.encode();
  2051. //printf("%s", res.c_str());
  2052. //FDEBUG("get resource over {$}", DescriptionTempEx.encode());
  2053. //printf("************* get resource over %s \n", DescriptionTempEx.encode());
  2054. return res;
  2055. }
  2056. std::string nsGEN::DemoDriver::DeviceProbe()
  2057. {
  2058. printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  2059. ResDataObject r_config, HardwareInfo;
  2060. if (r_config.loadFile(m_ConfigFileName.c_str()))
  2061. {
  2062. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  2063. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  2064. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  2065. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  2066. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  2067. }
  2068. else
  2069. {
  2070. HardwareInfo.add("MajorID", "Generator");
  2071. HardwareInfo.add("MinorID", "Dr");
  2072. HardwareInfo.add("VendorID", "DEMO");
  2073. HardwareInfo.add("ProductID", "HF");
  2074. HardwareInfo.add("SerialID", "1234");
  2075. }
  2076. string ret = HardwareInfo.encode();
  2077. return ret;
  2078. }
  2079. void nsGEN::DemoDriver::Dequeue(const char* Packet, DWORD Length)
  2080. {
  2081. //DecodeFrame(Packet, Length); //无真实数据,此处直接空.
  2082. }
  2083. //In Demo mode ,will not enter here
  2084. int nsGEN::DemoDriver::callbackPackageProcess(const char* RecData, DWORD nLength, DWORD& PacketLength)
  2085. {
  2086. return 0;
  2087. }
  2088. //-----------------------------------------------------------------------------
  2089. // GetIODriver & CreateIODriver
  2090. //-----------------------------------------------------------------------------
  2091. static nsGEN::DemoDriver gIODriver;
  2092. extern "C" CCOS::Dev::IODriver * GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
  2093. {
  2094. return &gIODriver;
  2095. }
  2096. extern "C" CCOS::Dev::IODriver * CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
  2097. {
  2098. return new nsGEN::DemoDriver();
  2099. }