CCOS.Dev.Generator.Demo.cpp 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337
  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. // Update MA and MS based on new MAS value
  656. ComputeMAMS();
  657. }
  658. return RET_STATUS::RET_SUCCEED;
  659. }
  660. RET_STATUS nsGEN::DemoDevice::DecMAS()
  661. {
  662. FDEBUG("Enter DecMAS");
  663. if (m_bIsDemo)
  664. {
  665. /*if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P &&
  666. m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  667. {
  668. FWARN("Techmode is not 2P, can't DecMAS");
  669. return RET_STATUS::RET_NOSUPPORT;
  670. }*/
  671. float value = m_DoseUnit.m_MAS->Get();
  672. int npos = FindPositon(g_MAS_List, sizeof(g_MAS_List) / sizeof(float), value);
  673. if (npos < 0)
  674. {
  675. return RET_STATUS::RET_FAILED;
  676. }
  677. else if (npos == 0)
  678. {
  679. return RET_STATUS::RET_SUCCEED;
  680. }
  681. npos -= 1;
  682. float temp = g_MAS_List[npos];
  683. m_DoseUnit.m_MAS->Update(temp);
  684. m_DoseUnit.m_PostMAS->Update(temp);
  685. FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet());
  686. // Update MA and MS based on new MAS value
  687. ComputeMAMS();
  688. }
  689. return RET_STATUS::RET_SUCCEED;
  690. }
  691. RET_STATUS nsGEN::DemoDevice::SetMAS(float value)
  692. {
  693. FDEBUG("Enter SetMAS:[{$}]", value);
  694. if (m_bIsDemo)
  695. {
  696. //if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P &&
  697. // m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  698. //{
  699. // FWARN("Techmode is not 2P, can't SetMAS");
  700. // return RET_STATUS::RET_NOSUPPORT;
  701. //}
  702. int npos = FindPositon(g_MAS_List, sizeof(g_MAS_List) / sizeof(float), value);
  703. if (npos < 0)
  704. {
  705. return RET_STATUS::RET_FAILED;
  706. }
  707. float temp = g_MAS_List[npos];
  708. m_DoseUnit.m_MAS->Update(temp);
  709. m_DoseUnit.m_PostMAS->Update(temp);
  710. FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet());
  711. // Update MA and MS based on new MAS value
  712. //ComputeMAMS();
  713. }
  714. return RET_STATUS::RET_SUCCEED;
  715. }
  716. RET_STATUS nsGEN::DemoDevice::IncMASL()
  717. {
  718. FDEBUG("Enter IncMASL");
  719. if (m_bIsDemo)
  720. {
  721. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P &&
  722. m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  723. {
  724. FWARN("Techmode is not 2P, can't IncMASL");
  725. return RET_STATUS::RET_NOSUPPORT;
  726. }
  727. float tempMAS = m_DoseUnit.m_MAS->Get();
  728. tempMAS += 4;
  729. if (m_DoseUnit.m_MAS->Update(tempMAS))
  730. {
  731. FDEBUG("IncMASL:[{$}] ok", tempMAS);
  732. FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet());
  733. return RET_STATUS::RET_SUCCEED;
  734. }
  735. else
  736. {
  737. FDEBUG("IncMASL:[{$}] failed,Exceeding limit", tempMAS);
  738. return RET_STATUS::RET_FAILED;
  739. }
  740. }
  741. return RET_STATUS::RET_SUCCEED;
  742. }
  743. RET_STATUS nsGEN::DemoDevice::DecMASL()
  744. {
  745. FDEBUG("Enter DecMASL");
  746. if (m_bIsDemo)
  747. {
  748. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P &&
  749. m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  750. {
  751. FWARN("Techmode is not 2P, can't DecMASL");
  752. return RET_STATUS::RET_NOSUPPORT;
  753. }
  754. float tempMAS = m_DoseUnit.m_MAS->Get();
  755. tempMAS -= 4;
  756. if (m_DoseUnit.m_MAS->Update(tempMAS))
  757. {
  758. FDEBUG("DecMASL:[{$}] ok", tempMAS);
  759. FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet());
  760. return RET_STATUS::RET_SUCCEED;
  761. }
  762. else
  763. {
  764. FDEBUG("DecMASL:[{$}] failed,Exceeding limit", tempMAS);
  765. return RET_STATUS::RET_FAILED;
  766. }
  767. }
  768. return RET_STATUS::RET_SUCCEED;
  769. }
  770. void nsGEN::DemoDevice::ComputeMAS()
  771. {
  772. float tempMa = m_DoseUnit.m_MA->Get();
  773. float tempMs = m_DoseUnit.m_MS->Get();
  774. float tempMAS = tempMa * tempMs / 1000.0f;
  775. // Find the closest MAS value in the list
  776. int npos = FindPositon(g_MAS_List, sizeof(g_MAS_List) / sizeof(float), tempMAS);
  777. if (npos >= 0 && npos < sizeof(g_MAS_List) / sizeof(float))
  778. {
  779. float adjustedMAS = g_MAS_List[npos];
  780. m_DoseUnit.m_MAS->Update(adjustedMAS);
  781. m_DoseUnit.m_PostMAS->Update(adjustedMAS);
  782. FDEBUG("ComputeMAS:MA[{$}] MS[{$}] calculatedMAS[{$}] adjustedMAS[{$}]",
  783. tempMa, tempMs, tempMAS, adjustedMAS);
  784. FireNotify(m_DoseUnit.m_MAS->GetKey(), adjustedMAS);
  785. }
  786. else
  787. {
  788. // Fallback to original behavior if position not found
  789. m_DoseUnit.m_PostMAS->Update(tempMAS);
  790. FDEBUG("ComputeMAS:MA[{$}] MS[{$}] tempMAS[{$}] (not in list)",
  791. tempMa, tempMs, tempMAS);
  792. FireNotify(m_DoseUnit.m_MAS->GetKey(), tempMAS);
  793. }
  794. }
  795. void nsGEN::DemoDevice::ComputeMAMS()
  796. {
  797. // When MAS changes, we need to update MA and MS accordingly
  798. // We keep MS constant and adjust MA to match the new MAS value
  799. // Formula: MAS = MA * MS / 1000
  800. // Therefore: MA = MAS * 1000 / MS
  801. float currentMAS = m_DoseUnit.m_MAS->Get();
  802. float currentMS = m_DoseUnit.m_MS->Get();
  803. if (currentMS > 0)
  804. {
  805. float newMA = currentMAS * 1000.0f / currentMS;
  806. // Find the closest MA value in the list
  807. int npos = FindPositon(g_MA_List, sizeof(g_MA_List) / sizeof(float), newMA);
  808. if (npos >= 0 && npos < sizeof(g_MA_List) / sizeof(float))
  809. {
  810. float adjustedMA = g_MA_List[npos];
  811. m_DoseUnit.m_MA->Update(adjustedMA);
  812. m_DoseUnit.m_PostMA->Update(adjustedMA);
  813. FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet());
  814. // Recalculate MS to maintain the exact MAS value if needed
  815. float adjustedMS = currentMAS * 1000.0f / adjustedMA;
  816. int msPos = FindPositon(g_MS_List, sizeof(g_MS_List) / sizeof(float), adjustedMS);
  817. if (msPos >= 0 && msPos < sizeof(g_MS_List) / sizeof(float))
  818. {
  819. float finalMS = g_MS_List[msPos];
  820. m_DoseUnit.m_MS->Update(finalMS);
  821. m_DoseUnit.m_PostMS->Update(finalMS);
  822. FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet());
  823. }
  824. FDEBUG("ComputeMAMS:MAS[{$}] -> MA[{$}] MS[{$}]",
  825. currentMAS, m_DoseUnit.m_MA->Get(), m_DoseUnit.m_MS->Get());
  826. }
  827. }
  828. }
  829. RET_STATUS nsGEN::DemoDevice::SetTechmode(int value)
  830. {
  831. FDEBUG("Enter SetTechmode:[{$}]", value);
  832. if (m_bIsDemo)
  833. {
  834. if (!m_DoseUnit.m_Techmode->Verify(value)) return RET_STATUS::RET_SUCCEED;
  835. m_DoseUnit.m_Techmode->Update(value);
  836. FireNotify(m_DoseUnit.m_Techmode->GetKey(), m_DoseUnit.m_Techmode->JSGet());
  837. switch (value)
  838. {
  839. case AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P:
  840. {
  841. FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet());
  842. FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet());
  843. ComputeMAS();
  844. }
  845. break;
  846. case AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P:
  847. {
  848. FireNotify(m_DoseUnit.m_MA->GetKey(), "0");
  849. FireNotify(m_DoseUnit.m_MS->GetKey(), "0");
  850. FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet());
  851. }
  852. break;
  853. case AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P:
  854. {
  855. FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet());
  856. FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet());
  857. ComputeMAS();
  858. }
  859. break;
  860. case AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P:
  861. {
  862. FireNotify(m_DoseUnit.m_MA->GetKey(), "0");
  863. FireNotify(m_DoseUnit.m_MS->GetKey(), "0");
  864. FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet());
  865. }
  866. break;
  867. }
  868. }
  869. return RET_STATUS::RET_SUCCEED;
  870. }
  871. RET_STATUS nsGEN::DemoDevice::SetFocus(int value)
  872. {
  873. FDEBUG("Enter SetFocus:[{$}]", value);
  874. if (m_bIsDemo)
  875. {
  876. if (!m_DoseUnit.m_Focus->Verify(value)) return RET_STATUS::RET_SUCCEED;
  877. m_DoseUnit.m_Focus->Update(value);
  878. FireNotify(m_DoseUnit.m_Focus->GetKey(), m_DoseUnit.m_Focus->JSGet());
  879. if (m_DoseUnit.m_Focus->Get() == AttrKey::FOCUS_SMALL)
  880. FireNotify(AttrKey::FOCUSSIZE, m_DoseUnit.m_FocusSmall);
  881. else
  882. FireNotify(AttrKey::FOCUSSIZE, m_DoseUnit.m_FocusLarge);
  883. }
  884. return RET_STATUS::RET_SUCCEED;
  885. }
  886. RET_STATUS nsGEN::DemoDevice::SetAECDensity(int value)
  887. {
  888. FDEBUG("Enter SetAECDensity:[{$}]", value);
  889. if (m_bIsDemo)
  890. {
  891. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_1P &&
  892. m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P &&
  893. m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
  894. {
  895. printf("\n Techmode is not AEC, can't SetAECDensity");
  896. return RET_STATUS::RET_NOSUPPORT;
  897. }
  898. if (!m_DoseUnit.m_AECDensity->Verify(value)) return RET_STATUS::RET_FAILED;
  899. m_DoseUnit.m_AECDensity->Update(value);
  900. FireNotify(m_DoseUnit.m_AECDensity->GetKey(), m_DoseUnit.m_AECDensity->JSGet());
  901. }
  902. return RET_STATUS::RET_SUCCEED;
  903. }
  904. RET_STATUS nsGEN::DemoDevice::IncAECDensity()
  905. {
  906. FDEBUG("Enter IncAECDensity");
  907. if (m_bIsDemo)
  908. {
  909. FDEBUG("Enter IncAECDensity");
  910. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_1P &&
  911. m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P &&
  912. m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
  913. {
  914. FWARN("Techmode is not AEC, can't IncAECDensity");
  915. return RET_STATUS::RET_NOSUPPORT;
  916. }
  917. if (m_DoseUnit.m_AECDensity->CanInc())
  918. {
  919. m_DoseUnit.m_AECDensity->Inc();
  920. FireNotify(m_DoseUnit.m_AECDensity->GetKey(), m_DoseUnit.m_AECDensity->JSGet());
  921. }
  922. }
  923. return RET_STATUS::RET_SUCCEED;
  924. }
  925. RET_STATUS nsGEN::DemoDevice::DecAECDensity()
  926. {
  927. FDEBUG("Enter DecAECDensity");
  928. if (m_bIsDemo)
  929. {
  930. FDEBUG("Enter DecAECDensity");
  931. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_1P &&
  932. m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P &&
  933. m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
  934. {
  935. FWARN("Techmode is not AEC, can't DecAECDensity");
  936. return RET_STATUS::RET_NOSUPPORT;
  937. }
  938. if (m_DoseUnit.m_AECDensity->CanDec())
  939. {
  940. m_DoseUnit.m_AECDensity->Dec();
  941. FireNotify(m_DoseUnit.m_AECDensity->GetKey(), m_DoseUnit.m_AECDensity->JSGet());
  942. }
  943. }
  944. return RET_STATUS::RET_SUCCEED;
  945. }
  946. RET_STATUS nsGEN::DemoDevice::SetAECField(int value)
  947. {
  948. FDEBUG("Enter SetAECField:[{$}]", value);
  949. if (m_bIsDemo)
  950. {
  951. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_AEC)
  952. {
  953. printf("\n Techmode is not AEC, can't set AEC");
  954. return RET_STATUS::RET_FAILED;
  955. }
  956. if (!m_DoseUnit.m_AECField->Verify(value)) return RET_STATUS::RET_SUCCEED;
  957. int npos = FindPositon(g_AECFIELD_List, sizeof(g_AECFIELD_List) / sizeof(int), value);
  958. if (npos < 0)
  959. {
  960. return RET_STATUS::RET_FAILED;
  961. }
  962. int temp = value;
  963. m_DoseUnit.m_AECField->Update(temp);
  964. FireNotify(m_DoseUnit.m_AECField->GetKey(), m_DoseUnit.m_AECField->JSGet());
  965. }
  966. return RET_STATUS::RET_SUCCEED;
  967. }
  968. RET_STATUS nsGEN::DemoDevice::SetAECFilm(int value)
  969. {
  970. FDEBUG("Enter SetAECFilm:[{$}]", value);
  971. if (m_bIsDemo)
  972. {
  973. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_AEC)
  974. {
  975. printf("\n Techmode is not AEC, can't set AEC");
  976. return RET_STATUS::RET_FAILED;
  977. }
  978. if (!m_DoseUnit.m_AECFilm->Verify(value)) return RET_STATUS::RET_SUCCEED;
  979. m_DoseUnit.m_AECFilm->Update(value);
  980. FireNotify(m_DoseUnit.m_AECFilm->GetKey(), m_DoseUnit.m_AECFilm->JSGet());
  981. }
  982. return RET_STATUS::RET_SUCCEED;
  983. }
  984. RET_STATUS nsGEN::DemoDevice::SetAPR(const _tAPRArgs& t)
  985. {
  986. FDEBUG("SetAPR:KV={$},MA={$},MS={$},MAS={$},Focus={$},Techmode={$},WS={$},AECDensity={$},AECField={$},AECFilm={$}",
  987. t.fKV, t.fMA, t.fMS, t.fMAS, t.nFocus, t.nTechmode, t.nWS, t.nAECDensity, t.nAECField, t.nAECFilm);
  988. if (m_bIsDemo)
  989. {
  990. //note:缺少WS
  991. m_DoseUnit.m_Techmode->Update(t.nTechmode);
  992. FireNotify(m_DoseUnit.m_Techmode->GetKey(), m_DoseUnit.m_Techmode->JSGet());
  993. SetKV(t.fKV);
  994. SetMA(t.fMA);
  995. SetMS(t.fMS);
  996. SetMAS(t.fMAS);
  997. SetFocus(t.nFocus);
  998. SetAECDensity(t.nAECDensity);
  999. SetAECField(t.nAECField);
  1000. SetAECFilm(t.nAECFilm);
  1001. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
  1002. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
  1003. {
  1004. ComputeMAS();
  1005. }
  1006. m_DoseUnit.m_HE->Update(50);
  1007. FireNotify(m_DoseUnit.m_HE->GetKey(), m_DoseUnit.m_HE->JSGet());
  1008. }
  1009. else
  1010. {
  1011. FireNotify(m_DoseUnit.m_Techmode->GetKey(), t.nTechmode);
  1012. FireNotify(m_DoseUnit.m_KV->GetKey(), t.fKV);
  1013. FireNotify(m_DoseUnit.m_MA->GetKey(), t.fMA);
  1014. FireNotify(m_DoseUnit.m_MS->GetKey(), t.fMS);
  1015. FireNotify(m_DoseUnit.m_MAS->GetKey(), t.fMAS);
  1016. FireNotify(m_DoseUnit.m_Focus->GetKey(), t.nFocus);
  1017. FireNotify(m_DoseUnit.m_AECDensity->GetKey(), t.nAECDensity);
  1018. FireNotify(m_DoseUnit.m_AECField->GetKey(), t.nAECField);
  1019. FireNotify(m_DoseUnit.m_AECFilm->GetKey(), t.nAECFilm);
  1020. }
  1021. return RET_STATUS::RET_SUCCEED;
  1022. }
  1023. RET_STATUS nsGEN::DemoDevice::SetAPRArray(vector<_tAPRArgs>& APRarray)
  1024. {
  1025. FDEBUG("SetAPRArray:[size:{$}]", APRarray.size());
  1026. if (m_bIsDemo)
  1027. {
  1028. m_APRarray = APRarray;
  1029. for (int i = 0; i < m_APRarray.size(); i++)
  1030. {
  1031. FDEBUG("APRArray[{$}]:WS={$},Techmode={$},Focus={$},KV={$},MA={$},MS={$},MAS={$},AECDensity={$},AECField={$},AECFilm={$}",
  1032. i, m_APRarray[i].nWS, m_APRarray[i].nTechmode, m_APRarray[i].nFocus,
  1033. m_APRarray[i].fKV, m_APRarray[i].fMA, m_APRarray[i].fMS, m_APRarray[i].fMAS,
  1034. m_APRarray[i].nAECDensity, m_APRarray[i].nAECField, m_APRarray[i].nAECFilm);
  1035. }
  1036. if (!m_APRarray.empty())
  1037. {
  1038. SetAPR(m_APRarray[0]);
  1039. m_DoseUnit.m_GenTotalExpNumber->Update(m_APRarray.size());
  1040. m_DoseUnit.m_GenCurrentExpNumber->Update(1);
  1041. FDEBUG("SetAPRArray:[totalEXP:{$}, currentEXP:{$}]", m_DoseUnit.m_GenTotalExpNumber->Get(), m_DoseUnit.m_GenCurrentExpNumber->Get());
  1042. }
  1043. }
  1044. return RET_STATUS::RET_SUCCEED;
  1045. }
  1046. RET_STATUS nsGEN::DemoDevice::QueryPostKV(float& value)
  1047. {
  1048. value = m_DoseUnit.m_KV->Get();
  1049. return RET_STATUS::RET_SUCCEED;
  1050. }
  1051. RET_STATUS nsGEN::DemoDevice::QueryPostMA(float& value)
  1052. {
  1053. value = m_DoseUnit.m_MA->Get();
  1054. return RET_STATUS::RET_SUCCEED;
  1055. }
  1056. RET_STATUS nsGEN::DemoDevice::QueryPostMS(float& value)
  1057. {
  1058. value = m_DoseUnit.m_MS->Get();
  1059. return RET_STATUS::RET_SUCCEED;
  1060. }
  1061. RET_STATUS nsGEN::DemoDevice::QueryPostMAS(float& value)
  1062. {
  1063. value = m_DoseUnit.m_MAS->Get();
  1064. return RET_STATUS::RET_SUCCEED;
  1065. }
  1066. RET_STATUS nsGEN::DemoDevice::SetFrameRate(float frameRate)
  1067. {
  1068. FDEBUG("Enter SetFrameRate:[{$}]", frameRate);
  1069. return RET_STATUS::RET_SUCCEED;
  1070. }
  1071. RET_STATUS nsGEN::DemoDevice::SetCollimatorDev(OemCollimator* dev)
  1072. {
  1073. FDEBUG("Enter SetCollimatorDev");
  1074. if (dev)
  1075. m_pCollDev.reset(dev);
  1076. return RET_STATUS::RET_SUCCEED;
  1077. }
  1078. RET_STATUS nsGEN::DemoDevice::SetMechDev(OemMechanical* dev)
  1079. {
  1080. FDEBUG("Enter SetMechDev");
  1081. if (dev)
  1082. m_pMechDev.reset(dev);
  1083. return RET_STATUS::RET_SUCCEED;
  1084. }
  1085. RET_STATUS nsGEN::DemoDevice::SetCollimatorSize(int xsize, int ysize)
  1086. {
  1087. FDEBUG("Enter SetCollimatorSize:[x:{$}, y:{$}]", xsize, ysize);
  1088. if (m_pCollDev)
  1089. {
  1090. m_pCollDev->UpdateCollimatorXSize(xsize);
  1091. m_pCollDev->UpdateCollimatorYSize(ysize);
  1092. }
  1093. return RET_STATUS::RET_SUCCEED;
  1094. }
  1095. RET_STATUS nsGEN::DemoDevice::SetCollimatorLight(unsigned short pParams)
  1096. {
  1097. FDEBUG("Enter SetCollimatorLight:[{$}]", (int)pParams);
  1098. //此处应该发送指令给GEN,并且该指令可以控制 coll 的LED
  1099. return RET_STATUS::RET_SUCCEED;
  1100. }
  1101. RET_STATUS nsGEN::DemoDevice::SetAutoTracking(int nAutoTracking)
  1102. {
  1103. FDEBUG("Enter SetAutoTracking:[{$}]", nAutoTracking);
  1104. if (m_pMechDev)
  1105. m_pMechDev->UpdateMammo_Depress(nAutoTracking);
  1106. return RET_STATUS::RET_SUCCEED;
  1107. }
  1108. RET_STATUS nsGEN::DemoDevice::SetFilter(int nFilterType)
  1109. {
  1110. FDEBUG("Enter SetFilter:[{$}]", nFilterType);
  1111. if (m_pMechDev)
  1112. {
  1113. m_pMechDev->UpdateMammo_FT(nFilterType);
  1114. }
  1115. if (m_pCollDev)
  1116. {
  1117. m_pCollDev->UpdateCollimatorFilter(nFilterType);
  1118. }
  1119. return RET_STATUS::RET_SUCCEED;
  1120. }
  1121. RET_STATUS nsGEN::DemoDevice::SetGrid(int nGridType)
  1122. {
  1123. FDEBUG("Enter SetGrid:[{$}]", nGridType);
  1124. if (m_pMechDev)
  1125. m_pMechDev->UpdateGrid(nGridType);
  1126. return RET_STATUS::RET_SUCCEED;
  1127. }
  1128. RET_STATUS nsGEN::DemoDevice::GetTomoResults(ResDataObject& resultAngle, ResDataObject& resultHeight)
  1129. {
  1130. RET_STATUS ret = RET_STATUS::RET_SUCCEED;
  1131. if (resultAngle.size() == 1 && resultHeight.size() == 1)
  1132. {
  1133. m_resultAngle.update(resultAngle.GetKey(0), (float)resultAngle[0]);
  1134. FINFO("GetTomoResults insert, key={$},value={$}", resultAngle.GetKey(0), (float)resultAngle[0]);
  1135. }
  1136. else
  1137. {
  1138. FINFO("GetTomoResults size={$}", m_resultAngle.size());
  1139. for (int i = 0; i < m_resultAngle.size(); i++)
  1140. {
  1141. resultAngle.update(m_resultAngle.GetKey(i), (float)m_resultAngle[i]);
  1142. FINFO("GetTomoResults ket={$} ,resule={$}", m_resultAngle.GetKey(i), (float)m_resultAngle[i]);
  1143. }
  1144. resultHeight.update("0", 63.71);
  1145. resultHeight.update("1", 63.97);
  1146. resultHeight.update("2", 64.21);
  1147. resultHeight.update("3", 64.41);
  1148. resultHeight.update("4", 64.59);
  1149. resultHeight.update("5", 64.73);
  1150. resultHeight.update("6", 64.84);
  1151. resultHeight.update("7", 64.92);
  1152. resultHeight.update("8", 64.97);
  1153. resultHeight.update("9", 64.99);
  1154. resultHeight.update("10", 64.98);
  1155. resultHeight.update("11", 64.94);
  1156. resultHeight.update("12", 64.87);
  1157. resultHeight.update("13", 64.72);
  1158. resultHeight.update("14", 64.63);
  1159. resultHeight.update("15", 64.47);
  1160. resultHeight.update("16", 64.28);
  1161. resultHeight.update("17", 64.05);
  1162. m_resultAngle.clear();
  1163. }
  1164. return ret;
  1165. }
  1166. //透视
  1167. RET_STATUS nsGEN::DemoDevice::IncFluKV()
  1168. {
  1169. FDEBUG("Enter IncFluKV");
  1170. float KV = m_DoseUnit.m_FLKV->Get()+1;
  1171. if (m_DoseUnit.m_FLKV->Update(KV))
  1172. {
  1173. FireNotify(m_DoseUnit.m_FLKV->GetKey(), m_DoseUnit.m_FLKV->JSGet());
  1174. }
  1175. return RET_STATUS::RET_SUCCEED;
  1176. }
  1177. RET_STATUS nsGEN::DemoDevice::DecFluKV()
  1178. {
  1179. FDEBUG("Enter DecFluKV");
  1180. float KV = m_DoseUnit.m_FLKV->Get() - 1;
  1181. if (m_DoseUnit.m_FLKV->Update(KV))
  1182. {
  1183. FireNotify(m_DoseUnit.m_FLKV->GetKey(), m_DoseUnit.m_FLKV->JSGet());
  1184. }
  1185. return RET_STATUS::RET_SUCCEED;
  1186. }
  1187. RET_STATUS nsGEN::DemoDevice::SetFluKV(float value)
  1188. {
  1189. FDEBUG("Enter SetFluKV:[{$}]", value);
  1190. if (m_DoseUnit.m_FLKV->Update(value))
  1191. {
  1192. FireNotify(m_DoseUnit.m_FLKV->GetKey(), m_DoseUnit.m_FLKV->JSGet());
  1193. }
  1194. return RET_STATUS::RET_SUCCEED;
  1195. }
  1196. RET_STATUS nsGEN::DemoDevice::IncFluMA()
  1197. {
  1198. FDEBUG("Enter IncFluKV");
  1199. float MA = m_DoseUnit.m_FLMA->Get()+1;
  1200. if (m_DoseUnit.m_FLMA->Update(MA))
  1201. {
  1202. FireNotify(m_DoseUnit.m_FLMA->GetKey(), m_DoseUnit.m_FLMA->JSGet());
  1203. }
  1204. return RET_STATUS::RET_SUCCEED;
  1205. }
  1206. RET_STATUS nsGEN::DemoDevice::DecFluMA()
  1207. {
  1208. FDEBUG("Enter DecFluKV");
  1209. float MA = m_DoseUnit.m_FLMA->Get() - 1;
  1210. if (m_DoseUnit.m_FLMA->Update(MA))
  1211. {
  1212. FireNotify(m_DoseUnit.m_FLMA->GetKey(), m_DoseUnit.m_FLMA->JSGet());
  1213. }
  1214. return RET_STATUS::RET_SUCCEED;
  1215. }
  1216. RET_STATUS nsGEN::DemoDevice::SetFluMA(float value)
  1217. {
  1218. FDEBUG("Enter SetFluMA:[{$}]", value);
  1219. if (m_DoseUnit.m_FLMA->Update(value))
  1220. {
  1221. FireNotify(m_DoseUnit.m_FLMA->GetKey(), m_DoseUnit.m_FLMA->JSGet());
  1222. }
  1223. return RET_STATUS::RET_SUCCEED;
  1224. }
  1225. RET_STATUS nsGEN::DemoDevice::IncFluMS()
  1226. {
  1227. return RET_STATUS::RET_SUCCEED;
  1228. }
  1229. RET_STATUS nsGEN::DemoDevice::DecFluMS()
  1230. {
  1231. return RET_STATUS::RET_SUCCEED;
  1232. }
  1233. RET_STATUS nsGEN::DemoDevice::SetFluMS(float value)
  1234. {
  1235. return RET_STATUS::RET_SUCCEED;
  1236. }
  1237. RET_STATUS nsGEN::DemoDevice::SetPPS(float frameRate)
  1238. {
  1239. FDEBUG("Enter SetPPS:[{$}]", frameRate);
  1240. if (m_DoseUnit.m_PPS->Update(frameRate))
  1241. {
  1242. FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
  1243. }
  1244. return RET_STATUS::RET_SUCCEED;
  1245. }
  1246. RET_STATUS nsGEN::DemoDevice::INCPPS()
  1247. {
  1248. FDEBUG("Enter INCPPS");
  1249. float PPS = m_DoseUnit.m_PPS->Get()+1;
  1250. if (m_DoseUnit.m_PPS->Update(PPS))
  1251. {
  1252. FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
  1253. }
  1254. return RET_STATUS::RET_SUCCEED;
  1255. }
  1256. RET_STATUS nsGEN::DemoDevice::DECPPS()
  1257. {
  1258. FDEBUG("Enter DECPPS");
  1259. float PPS = m_DoseUnit.m_PPS->Get() - 1;
  1260. if (m_DoseUnit.m_PPS->Update(PPS))
  1261. {
  1262. FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
  1263. }
  1264. return RET_STATUS::RET_SUCCEED;
  1265. }
  1266. RET_STATUS nsGEN::DemoDevice::SetPluseWidth(float fplusewidth)
  1267. {
  1268. return RET_STATUS::RET_SUCCEED;
  1269. }
  1270. RET_STATUS nsGEN::DemoDevice::SetABSMode(int nMode)
  1271. {
  1272. FDEBUG("Enter SetABSMode:[{$}]", nMode);
  1273. if (m_DoseUnit.m_ABSStatus->Update(nMode))
  1274. {
  1275. FireNotify(m_DoseUnit.m_ABSStatus->GetKey(), m_DoseUnit.m_ABSStatus->JSGet());
  1276. }
  1277. return RET_STATUS::RET_SUCCEED;
  1278. }
  1279. RET_STATUS nsGEN::DemoDevice::SetABSCurve(int curveNum)
  1280. {
  1281. return RET_STATUS::RET_SUCCEED;
  1282. }
  1283. RET_STATUS nsGEN::DemoDevice::IncABSCurve()
  1284. {
  1285. return RET_STATUS::RET_SUCCEED;
  1286. }
  1287. RET_STATUS nsGEN::DemoDevice::DecABSCurve()
  1288. {
  1289. return RET_STATUS::RET_SUCCEED;
  1290. }
  1291. RET_STATUS nsGEN::DemoDevice::SetABSValue(float fABSValue)
  1292. {
  1293. return RET_STATUS::RET_SUCCEED;
  1294. }
  1295. RET_STATUS nsGEN::DemoDevice::SetABSTargetEXI(float fEXIValue)
  1296. {
  1297. return RET_STATUS::RET_SUCCEED;
  1298. }
  1299. float nsGEN::DemoDevice::GetFluIntTimer()
  1300. {
  1301. return RET_STATUS::RET_SUCCEED;
  1302. }
  1303. float nsGEN::DemoDevice::GetFluAccTimer()
  1304. {
  1305. return RET_STATUS::RET_SUCCEED;
  1306. }
  1307. RET_STATUS nsGEN::DemoDevice::ResetFluTimer(int ntype)
  1308. {
  1309. FDEBUG("ReSetFluAccTimer:[{$}]", ntype);
  1310. return RET_STATUS::RET_SUCCEED;
  1311. }
  1312. RET_STATUS nsGEN::DemoDevice::SetFluPre(int bPrepare)
  1313. {
  1314. return RET_STATUS::RET_SUCCEED;
  1315. }
  1316. RET_STATUS nsGEN::DemoDevice::SetFluEXP(int bPrepare)
  1317. {
  1318. return RET_STATUS::RET_SUCCEED;
  1319. }
  1320. RET_STATUS nsGEN::DemoDevice::SetFLFMode(std::string value)
  1321. {
  1322. FDEBUG("Enter SetFLFMode:[{$}]", value.c_str());
  1323. if (value == "CF")
  1324. {
  1325. m_DoseUnit.m_FLMode->Update(AttrKey::GENERATOR_FLMODE_CF);
  1326. SetExpMode(AttrKey::EXPMODE_TYPE::CoutineSerial);
  1327. }
  1328. else if (value == "PF")
  1329. {
  1330. m_DoseUnit.m_FLMode->Update(AttrKey::GENERATOR_FLMODE_PF);
  1331. SetExpMode(AttrKey::EXPMODE_TYPE::PulseSerial);
  1332. }
  1333. FireNotify(AttrKey::FLUMode, m_DoseUnit.m_FLMode->JSGet());
  1334. return RET_STATUS::RET_SUCCEED;
  1335. }
  1336. RET_STATUS nsGEN::DemoDevice::SetFluMAG(int nsize)
  1337. {
  1338. return RET_STATUS::RET_SUCCEED;
  1339. }
  1340. RET_STATUS nsGEN::DemoDevice::DisableMAG()
  1341. {
  1342. return RET_STATUS::RET_SUCCEED;
  1343. }
  1344. RET_STATUS nsGEN::DemoDevice::SetFluDoseLever(int nlever)
  1345. {
  1346. FDEBUG("Enter SetFluDoseLever:[{$}]", nlever);
  1347. if (m_DoseUnit.m_DoseLevel->Update(nlever))
  1348. {
  1349. FireNotify(AttrKey::FLUDoseLevel, m_DoseUnit.m_DoseLevel->JSGet());
  1350. }
  1351. return RET_STATUS::RET_SUCCEED;
  1352. }
  1353. RET_STATUS nsGEN::DemoDevice::SetHalfDose(int nlever)
  1354. {
  1355. return RET_STATUS::RET_SUCCEED;
  1356. }
  1357. RET_STATUS nsGEN::DemoDevice::TransferRadCurve(int ncurve)
  1358. {
  1359. return RET_STATUS::RET_SUCCEED;
  1360. }
  1361. RET_STATUS nsGEN::DemoDevice::SetAPF(const _tAPFArgs& t)
  1362. {
  1363. FDEBUG("SetAPF: nWS={$}, Flu mode={$}, ABS mode={$}, DoseLever={$}, nFlkv={$}, FlMA={$}",
  1364. t.nWS, t.nFluMode, t.nABSMode, t.nDoseLever, t.nFLKV, t.fFLMA, t.nPPS);
  1365. if (m_DoseUnit.m_FLKV->Update(t.nFLKV))
  1366. {
  1367. FireNotify(m_DoseUnit.m_FLKV->GetKey(), m_DoseUnit.m_FLKV->JSGet());
  1368. }
  1369. if (m_DoseUnit.m_FLMA->Update(t.fFLMA))
  1370. {
  1371. FireNotify(m_DoseUnit.m_FLMA->GetKey(), m_DoseUnit.m_FLMA->JSGet());
  1372. }
  1373. if (m_DoseUnit.m_PPS->Update(t.nPPS))
  1374. {
  1375. FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
  1376. }
  1377. if (m_DoseUnit.m_DoseLevel->Update(t.nDoseLever))
  1378. {
  1379. FireNotify(AttrKey::FLUDoseLevel, m_DoseUnit.m_DoseLevel->JSGet());
  1380. }
  1381. if (m_DoseUnit.m_FLMode->Update(t.nFluMode))
  1382. {
  1383. FireNotify(AttrKey::FLUMode, m_DoseUnit.m_FLMode->JSGet());
  1384. }
  1385. if (m_DoseUnit.m_ABSStatus->Update(t.nABSMode))
  1386. {
  1387. FireNotify(m_DoseUnit.m_ABSStatus->GetKey(), m_DoseUnit.m_ABSStatus->JSGet());
  1388. }
  1389. return RET_STATUS::RET_SUCCEED;
  1390. }
  1391. //额外
  1392. void nsGEN::DemoDevice::FireNotify(string key, int context)
  1393. {
  1394. //std::unique_lock<std::mutex> uqeLock(m_MSGLock);
  1395. char szInfo[64] = { 0 };
  1396. sprintf(szInfo, "%d", context);
  1397. std::string str = szInfo;
  1398. EventCenter->OnNotify(1, key, str);//(int)ATTRACTION_SET 2
  1399. }
  1400. void nsGEN::DemoDevice::FireNotify(std::string key, float context)
  1401. {
  1402. //std::unique_lock<std::mutex> uqeLock(m_MSGLock);
  1403. char szInfo[64] = { 0 };
  1404. sprintf(szInfo, "%.2f", context);
  1405. std::string str = szInfo;
  1406. EventCenter->OnNotify(1, key, str);//(int)ATTRACTION_SET 2
  1407. }
  1408. void nsGEN::DemoDevice::FireNotify(std::string key, std::string context)
  1409. {
  1410. //std::unique_lock<std::mutex> uqeLock(m_MSGLock);
  1411. EventCenter->OnNotify(1, key, context);
  1412. }
  1413. int nsGEN::DemoDevice::GetConfData()
  1414. {
  1415. //灯丝大小
  1416. if (m_GenConfig.GetKeyCount(ConfKey::CcosTubeInfo) > 0)
  1417. {
  1418. string tempValue = m_GenConfig[ConfKey::CcosTubeInfo].encode();
  1419. m_DoseUnit.m_TubeInfo.reset(new TUBEINFOMould(tempValue));
  1420. }
  1421. if (m_GenConfig.GetKeyCount(ConfKey::CcosFocusSmall) > 0)
  1422. {
  1423. float tempValue = (float)m_GenConfig[ConfKey::CcosFocusSmall];
  1424. m_DoseUnit.m_FocusSmall = tempValue;
  1425. }
  1426. if (m_GenConfig.GetKeyCount(ConfKey::CcosFocusLarge) > 0)
  1427. {
  1428. float tempValue = (float)m_GenConfig[ConfKey::CcosFocusLarge];
  1429. m_DoseUnit.m_FocusLarge = tempValue;
  1430. }
  1431. //同步模式
  1432. if (m_GenConfig.GetKeyCount("WSTable") > 0)
  1433. {
  1434. int WSNamber = (int)m_GenConfig["WSTable"];
  1435. EnSYNMode WSSYN = (EnSYNMode)((int)m_GenConfig["SYNTable"]);
  1436. m_arrWSMap[cfgWorkStationKey("Table", AttrKey::TABLE)] = cfgWorkStationData("Table", WSNamber, WSSYN);
  1437. FDEBUG("cfg Table WS[{$}],SYN[{$}]", WSNamber, (int)WSSYN);
  1438. }
  1439. if (m_GenConfig.GetKeyCount("WSWall") > 0)
  1440. {
  1441. int WSNamber = (int)m_GenConfig["WSWall"];
  1442. EnSYNMode WSSYN = (EnSYNMode)((int)m_GenConfig["SYNWall"]);
  1443. m_arrWSMap[cfgWorkStationKey("Wall", AttrKey::WALL)] = cfgWorkStationData("Wall", WSNamber, WSSYN);
  1444. FDEBUG("cfg Wall WS[{$}],SYN[{$}]", WSNamber, (int)WSSYN);
  1445. }
  1446. if (m_GenConfig.GetKeyCount("WSFree") > 0)
  1447. {
  1448. int WSNamber = (int)m_GenConfig["WSFree"];
  1449. EnSYNMode WSSYN = (EnSYNMode)((int)m_GenConfig["SYNFree"]);
  1450. m_arrWSMap[cfgWorkStationKey("Free", AttrKey::MOBILE)] = cfgWorkStationData("Free", WSNamber, WSSYN);
  1451. FDEBUG("cfg Free WS[{$}],SYN[{$}]", WSNamber, (int)WSSYN);
  1452. }
  1453. if (m_GenConfig.GetKeyCount("WSTomo") > 0)
  1454. {
  1455. int WSNamber = (int)m_GenConfig["WSTomo"];
  1456. EnSYNMode WSSYN = (EnSYNMode)((int)m_GenConfig["SYNTomo"]);
  1457. m_arrWSMap[cfgWorkStationKey("Tomo", AttrKey::TOMO)] = cfgWorkStationData("Tomo", WSNamber, WSSYN);
  1458. FDEBUG("cfg Tomo WS[{$}],SYN[{$}]", WSNamber, (int)WSSYN);
  1459. }
  1460. if (m_GenConfig.GetKeyCount("WSConventional") > 0)
  1461. {
  1462. int WSNamber = (int)m_GenConfig["WSConventional"];
  1463. EnSYNMode WSSYN = (EnSYNMode)((int)m_GenConfig["SYNConventional"]);
  1464. m_arrWSMap[cfgWorkStationKey("Direct", AttrKey::CONVENTIONAL)] = cfgWorkStationData("Direct", WSNamber, WSSYN);
  1465. FDEBUG("cfg Conventional WS[{$}],SYN[{$}]", WSNamber, (int)WSSYN);
  1466. }
  1467. //参数初始化
  1468. ResDataObject temp;
  1469. temp.update("Max", 150);
  1470. temp.update("Min", 40);
  1471. temp.update("List", "");
  1472. for (int i = 0; i < sizeof(g_KV_List) / sizeof(g_KV_List[0]); i++)
  1473. {
  1474. char chindex[4] = { 0 };
  1475. sprintf(chindex, "%d", i);
  1476. temp["List"].add(chindex, g_KV_List[i] / 10.0f);
  1477. }
  1478. m_DoseUnit.m_KVList.reset(new KVLISTMould(temp.encode()));
  1479. temp.clear();
  1480. temp.update("Max", 1000);
  1481. temp.update("Min", 8);
  1482. temp.update("List", "");
  1483. for (int i = 0; i < sizeof(g_MAS_List) / sizeof(g_MAS_List[0]); i++)
  1484. {
  1485. char chindex[4] = { 0 };
  1486. sprintf(chindex, "%d", i);
  1487. temp["List"].add(chindex, g_MAS_List[i]);
  1488. }
  1489. m_DoseUnit.m_mAsList.reset(new MASLISTMould(temp.encode()));
  1490. //add by wxx for delworks:解决前端提出KV值太少的问题 20230913
  1491. FireNotify(m_DoseUnit.m_KVList->GetKey(), m_DoseUnit.m_KVList->JSGet());
  1492. return true;
  1493. }
  1494. void nsGEN::DemoDevice::FireErrorMessage(const bool Act, const int Code, const char* ResInfo)
  1495. {
  1496. string ErrorCode("Demo_ERR_");
  1497. ErrorCode += std::to_string(Code);
  1498. int level = Demo_REGULATION_LEVEL::REG_ERRO;
  1499. if (Act)
  1500. {
  1501. FERROR("add {$}:{$}", ErrorCode.c_str(), ResInfo);
  1502. m_MSGUnit->AddErrorMessage(ErrorCode.c_str(), level, ResInfo);
  1503. }
  1504. else
  1505. {
  1506. FERROR("del {$}:{$}", ErrorCode.c_str(), ResInfo);
  1507. if (Code == 0)
  1508. m_MSGUnit->DelErrorMessage("0", level, ResInfo);
  1509. else
  1510. m_MSGUnit->DelErrorMessage(ErrorCode.c_str(), level, ResInfo);
  1511. }
  1512. }
  1513. void nsGEN::DemoDevice::FireWarnMessage(const bool Act, const int Code, const char* ResInfo)
  1514. {
  1515. string ErrorCode("Demo_WAR_");
  1516. ErrorCode += std::to_string(Code);
  1517. int level = Demo_REGULATION_LEVEL::REG_WARN;
  1518. if (Act)
  1519. {
  1520. FERROR("add {$}:{$}", ErrorCode.c_str(), ResInfo);
  1521. m_MSGUnit->AddWarnMessage(ErrorCode.c_str(), level, ResInfo);
  1522. }
  1523. else
  1524. {
  1525. FERROR("del {$}:{$}", ErrorCode.c_str(), ResInfo);
  1526. m_MSGUnit->DelWarnMessage(ErrorCode.c_str(), level, ResInfo);
  1527. }
  1528. }
  1529. bool nsGEN::DemoDevice::StartHardwareStatusThread()
  1530. {
  1531. FINFO("enter Start HardwareStatus Thread ");
  1532. if (m_pHardwareStatusThread == 0) // Linux使用0表示无效线程ID
  1533. {
  1534. // 创建线程属性对象(可选)
  1535. pthread_attr_t attr;
  1536. pthread_attr_init(&attr);
  1537. pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
  1538. // 创建线程
  1539. int ret = pthread_create(&m_pHardwareStatusThread,
  1540. &attr,
  1541. HardwareStatusThread,
  1542. this);
  1543. pthread_attr_destroy(&attr); // 销毁属性对象
  1544. if (ret != 0)
  1545. {
  1546. FERROR("Start HardwareStatus Thread Failed");
  1547. return false;
  1548. }
  1549. }
  1550. return true;
  1551. }
  1552. void* nsGEN::DemoDevice::HardwareStatusThread(void* pParam)
  1553. {
  1554. DemoDevice* pCurGen = (DemoDevice*)pParam;
  1555. if (pCurGen == NULL)
  1556. {
  1557. return NULL;
  1558. }
  1559. usleep(1500000);
  1560. FINFO("HardwareStatusThread start");
  1561. bool bActExpFlag = false;
  1562. FINFO("m_iStateChangeInterval = {$},m_iAutoExpActWaitTime = {$}", pCurGen->m_iStateChangeInterval, pCurGen->m_iAutoExpActWaitTime);;
  1563. FINFO("Request Fault Status:GENSTATE STATUS_SHUTDOWN -> STATUS_STANDBY");
  1564. pCurGen->m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
  1565. pCurGen->FireNotify(AttrKey::GENSTATE, pCurGen->m_DoseUnit.m_GenState->JSGet());
  1566. while (true)
  1567. {
  1568. while (!bActExpFlag)
  1569. {
  1570. //FINFO("loopAction: begin \n");
  1571. if (pCurGen->m_iAutoExpFlag > 0)
  1572. {
  1573. pCurGen->m_iAutoExpFlag = 0;
  1574. usleep(pCurGen->m_iAutoExpActWaitTime*1000);
  1575. if (pCurGen->m_iAutoExpFlag == 0)
  1576. {
  1577. FINFO("loopAction: start Exp Workflow \n");
  1578. bActExpFlag = true;
  1579. break;
  1580. }
  1581. else
  1582. {
  1583. FINFO("loopAction: Exp param changed restart wait \n");
  1584. continue;
  1585. }
  1586. }
  1587. usleep(pCurGen->m_iAutoExpActWaitTime*1000);
  1588. }
  1589. while (bActExpFlag)
  1590. {
  1591. FINFO("loopAction: act exp Workflow \n");
  1592. switch (pCurGen->m_DoseUnit.m_GenSynState->Get())
  1593. {
  1594. case nsGEN::AttrKey::GENERATOR_RAD_OFF:
  1595. {
  1596. FINFO("exp Status change:RAD_OFF -> PREPARE(PR1)", pCurGen->m_DoseUnit.m_GenSynState->Get());
  1597. pCurGen->m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_PREPARE);
  1598. }break;
  1599. case nsGEN::AttrKey::GENERATOR_RAD_PREPARE:
  1600. {
  1601. FINFO("exp Status change:PREPARE(PR1) -> RAD_READY(PR2)", pCurGen->m_DoseUnit.m_GenSynState->Get());
  1602. pCurGen->m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_READY);
  1603. }break;
  1604. case nsGEN::AttrKey::GENERATOR_RAD_READY:
  1605. {
  1606. FINFO("exp Status change:RAD_READY(PR2) -> XRAYON(XR1)", pCurGen->m_DoseUnit.m_GenSynState->Get());
  1607. pCurGen->m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_XRAYON);
  1608. }break;
  1609. case nsGEN::AttrKey::GENERATOR_RAD_XRAYON:
  1610. {
  1611. FINFO("exp Status change:XRAYON(XR1) -> XRAYOFF(XR0)", pCurGen->m_DoseUnit.m_GenSynState->Get());
  1612. pCurGen->m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_XRAYOFF);
  1613. FDEBUG("Request Fault Status:GENSTATE STATUS_STANDBY -> STATUS_EXP");
  1614. pCurGen->m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_EXP);
  1615. pCurGen->FireNotify(AttrKey::GENSTATE, pCurGen->m_DoseUnit.m_GenState->JSGet());
  1616. FINFO("exp Status value:POSTKV[{$}],POSTMA[{$}],POSTMS[{$}],POSTMAS[{$}]",
  1617. pCurGen->m_DoseUnit.m_PostKV->Get(), pCurGen->m_DoseUnit.m_PostMA->Get(), pCurGen->m_DoseUnit.m_PostMS->Get(), pCurGen->m_DoseUnit.m_PostMAS->Get());
  1618. pCurGen->FireNotify(AttrKey::POSTKV, pCurGen->m_DoseUnit.m_PostKV->JSGet());
  1619. pCurGen->FireNotify(AttrKey::POSTMA, pCurGen->m_DoseUnit.m_PostMA->JSGet());
  1620. #if DEMO_DAEC_Flag
  1621. int temp = pCurGen->m_DoseUnit.m_PostMS->Get();
  1622. if (pCurGen->m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P ||
  1623. pCurGen->m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P ||
  1624. pCurGen->m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_1P)
  1625. {
  1626. temp /= 2;
  1627. }
  1628. pCurGen->FireNotify(AttrKey::POSTMS, temp);
  1629. #else
  1630. pCurGen->FireNotify(AttrKey::POSTMS, pCurGen->m_DoseUnit.m_PostMS->JSGet());
  1631. #endif // DEMO_DAEC_Flag
  1632. pCurGen->FireNotify(AttrKey::POSTMAS, pCurGen->m_DoseUnit.m_PostMAS->JSGet());
  1633. }break;
  1634. case nsGEN::AttrKey::GENERATOR_RAD_XRAYOFF:
  1635. {
  1636. FINFO("exp Status change:XRAYOFF(XR0) -> RAD_OFF", pCurGen->m_DoseUnit.m_GenSynState->Get());
  1637. pCurGen->m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_OFF);
  1638. FDEBUG("Request Fault Status:GENSTATE STATUS_EXP -> STATUS_STANDBY");
  1639. pCurGen->m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
  1640. pCurGen->FireNotify(AttrKey::GENSTATE, pCurGen->m_DoseUnit.m_GenState->JSGet());
  1641. }
  1642. default:
  1643. {
  1644. bActExpFlag = false;
  1645. }
  1646. }
  1647. pCurGen->FireNotify(pCurGen->m_DoseUnit.m_GenSynState->GetKey(), pCurGen->m_DoseUnit.m_GenSynState->JSGet());
  1648. usleep(pCurGen->m_iStateChangeInterval*1000);
  1649. }
  1650. }
  1651. FINFO("HardwareStatusThread stop");
  1652. return NULL;
  1653. }
  1654. //驱动
  1655. nsGEN::DemoDriver::DemoDriver()
  1656. {
  1657. m_bDemoMode = false;
  1658. m_bDemoConnected = false;
  1659. m_bDemoInitDataFlag = false;
  1660. m_pDriGenDev = nullptr;
  1661. //m_pDriCollDev = nullptr;
  1662. //m_pDriMechDev = nullptr;
  1663. m_pAttribute.reset(new ResDataObject());
  1664. m_pDescription.reset(new ResDataObject());
  1665. }
  1666. nsGEN::DemoDriver::~DemoDriver()
  1667. {
  1668. }
  1669. auto nsGEN::DemoDriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
  1670. {
  1671. std::cout << "Enter CreateDevice, index=" << index<< std::endl;
  1672. FINFO("Enter CreateDevice, index={$}", index);
  1673. if (index == 0)
  1674. {
  1675. m_pDriGenDev = new DemoDevice(EventCenter, m_ConfigFileName);
  1676. auto dev = std::unique_ptr<IODevice>(new IODevice(m_pDriGenDev));
  1677. return dev;
  1678. }
  1679. else if (index == 1)
  1680. {
  1681. std::cout << "Enter CreateDevice COLL" << std::endl;
  1682. FINFO("Enter CreateDevice COLL");
  1683. if (m_bDemoInitDataFlag)
  1684. {
  1685. int nXSize = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["XSize"]).c_str());
  1686. int nYSize = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["YSize"]).c_str());
  1687. int nFilter = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["Filter"]).c_str());
  1688. int nSID = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["SID"]).c_str());
  1689. int nAngle = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["Angle"]).c_str());
  1690. int nMode = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["Mode"]).c_str());
  1691. m_pDriCollDev = new OemCollimator(std::shared_ptr<IOEventCenter>(new IOEventCenter()), nXSize, nYSize, nFilter, nSID, nAngle, nMode);
  1692. }
  1693. else
  1694. m_pDriCollDev = new OemCollimator(std::shared_ptr<IOEventCenter>(new IOEventCenter()));
  1695. auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDriCollDev));
  1696. m_pDriCollDev->SetCtrlDev(m_pDriGenDev);
  1697. m_pDriGenDev->SetCollimatorDev(m_pDriCollDev);
  1698. FINFO("Leave CreateDevice COLL");
  1699. return dev;
  1700. }
  1701. else if (index == 2)
  1702. {
  1703. std::cout << "Enter CreateDevice Mech" << std::endl;
  1704. FINFO("Enter CreateDevice Mech");
  1705. if (m_bDemoInitDataFlag)
  1706. {
  1707. int nGrid = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["Grid"]).c_str());
  1708. int nAE = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["AE"]).c_str());
  1709. int nFT = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["FT"]).c_str());
  1710. int nPressureState = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["PressureState"]).c_str());
  1711. int nCompPressureDEC = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["CompPressureDEC"]).c_str());
  1712. int nDepress = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["Depress"]).c_str());
  1713. float fMechAngle = (atof)(((string)m_InitDataFile["CONFIGURATION"]["MechAngle"]).c_str());
  1714. float fMechHeight = (atof)(((string)m_InitDataFile["CONFIGURATION"]["MechHeight"]).c_str());
  1715. float fPressureValue = (atof)(((string)m_InitDataFile["CONFIGURATION"]["PressureValue"]).c_str());
  1716. float fAGD = (atof)(((string)m_InitDataFile["CONFIGURATION"]["AGD"]).c_str());
  1717. float fMAG = (atof)(((string)m_InitDataFile["CONFIGURATION"]["MAG"]).c_str());
  1718. m_pDriMechDev = new OemMechanical(std::shared_ptr<IOEventCenter>(new IOEventCenter()), nGrid, nAE, nFT, nPressureState, nCompPressureDEC, nDepress, fMechAngle, fMechHeight, fPressureValue, fAGD, fMAG);
  1719. }
  1720. else
  1721. m_pDriMechDev = new OemMechanical(std::shared_ptr<IOEventCenter>(new IOEventCenter()));
  1722. auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDriMechDev));
  1723. m_pDriMechDev->SetCtrlDev(m_pDriGenDev);
  1724. m_pDriGenDev->SetMechDev(m_pDriMechDev);
  1725. FINFO("Leave CreateDevice Mech");
  1726. return dev;
  1727. }
  1728. std::cout << "unknown index" << std::endl;
  1729. FERROR("unknown index");
  1730. unique_ptr <IODevice> dev;
  1731. return dev;
  1732. }
  1733. void nsGEN::DemoDriver::FireNotify(int code, std::string key, std::string content)
  1734. {
  1735. EventCenter->OnNotify(code, key, content);
  1736. }
  1737. //Log4CPP::Logger* gLogger = nullptr;
  1738. void nsGEN::DemoDriver::Prepare()
  1739. {
  1740. // 初始化日志系统
  1741. std::string strLogPath = GetProcessDirectory() + R"(/Conf/log_config.xml)";
  1742. std::string LogHost = "DemoGEN";
  1743. std::string moduleName = "DemoGEN";
  1744. bool ret = initLogModule(
  1745. LogHost, // 主机名(用于日志路径中的{host}占位符)
  1746. moduleName, // 唯一模块名
  1747. strLogPath, // 配置文件路径
  1748. true // 是否输出到控制台(可选)
  1749. );
  1750. if (!ret) {
  1751. std::cerr << "Log init failed!" << std::endl;
  1752. return;
  1753. }
  1754. GENDEMO_SetLocalModuleName(moduleName);
  1755. ResDataObject r_config;
  1756. if (r_config.loadFile(m_ConfigFileName.c_str()))
  1757. {
  1758. if(r_config["CONFIGURATION"].GetKeyCount("IsDemo")>0)
  1759. {
  1760. m_bDemoMode = (atoi)(((string)r_config["CONFIGURATION"]["IsDemo"]).c_str());
  1761. }
  1762. }
  1763. string strDataPath = GetProcessDirectory() + R"(/OEMDrivers/Generator/Demo/InitData.xml)";
  1764. try {
  1765. if (m_InitDataFile.loadFile(strDataPath.c_str()))
  1766. {
  1767. m_bDemoInitDataFlag = true;
  1768. FINFO("exist InitData");
  1769. }
  1770. else
  1771. FINFO("can not open InitData[{$}]", strDataPath.c_str());
  1772. }
  1773. catch (const ResDataObjectExption&)
  1774. {
  1775. FERROR("open InitData failed");
  1776. }
  1777. }
  1778. bool nsGEN::DemoDriver::Connect()
  1779. {
  1780. m_bDemoConnected = true;
  1781. return true; //return SCF_ERR::SCF_SUCCEED;
  1782. }
  1783. void nsGEN::DemoDriver::Disconnect()
  1784. {
  1785. m_bDemoConnected = false;
  1786. }
  1787. bool nsGEN::DemoDriver::isConnected() const
  1788. {
  1789. return m_bDemoConnected;
  1790. }
  1791. std::string nsGEN::DemoDriver::DriverProbe()
  1792. {
  1793. printf("line= %d,%s %s\n", __LINE__, __FUNCTION__, m_ConfigFileName.c_str());
  1794. ResDataObject r_config, HardwareInfo;
  1795. if (r_config.loadFile(m_ConfigFileName.c_str()))
  1796. {
  1797. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  1798. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  1799. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  1800. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  1801. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  1802. }
  1803. else
  1804. {
  1805. HardwareInfo.add("MajorID", "Generator");
  1806. HardwareInfo.add("MinorID", "Dr");
  1807. HardwareInfo.add("VendorID", "DEMO");
  1808. HardwareInfo.add("ProductID", "HF");
  1809. HardwareInfo.add("SerialID", "1234");
  1810. }
  1811. string ret = HardwareInfo.encode();
  1812. printf("line= %d,%s %s\n", __LINE__, __FUNCTION__, m_ConfigFileName.c_str());
  1813. return ret;
  1814. }
  1815. bool nsGEN::DemoDriver::GetDeviceConfig(std::string& Cfg)
  1816. {
  1817. //printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  1818. //Cfg = m_GenConfig.encode();
  1819. //return true;
  1820. Cfg = m_DeviceConfigSend.encode();
  1821. printf("GetDeviceConfig over , %s", Cfg.c_str());
  1822. return true;
  1823. }
  1824. bool nsGEN::DemoDriver::SetDeviceConfig(std::string Cfg)
  1825. {
  1826. FINFO("--Func-- SetDeviceConfig {$}\n", Cfg.c_str());
  1827. printf("\n--Func-- SetDeviceConfig %s\n", Cfg.c_str());
  1828. ResDataObject DeviceConfig;
  1829. DeviceConfig.decode(Cfg.c_str());
  1830. ResDataObject DescriptionTempEx;
  1831. DescriptionTempEx = DeviceConfig["DeviceConfig"]["Attribute"];
  1832. FDEBUG("Attribute:{$}", DescriptionTempEx.encode());
  1833. bool bSaveFile = false; //true:重新保存配置文件
  1834. string strAccess = "";
  1835. for (int i = 0; i < DescriptionTempEx.size(); i++)
  1836. {
  1837. string strKey = DescriptionTempEx.GetKey(i);
  1838. FINFO("{$}", strKey.c_str());
  1839. printf("%s\n", strKey.c_str());
  1840. try
  1841. {
  1842. if (m_pAttribute->GetFirstOf(strKey.c_str()) >= 0)
  1843. {
  1844. strAccess = (string)(*m_pDescription)[strKey.c_str()]["Access"];
  1845. if ("RW" == strAccess)
  1846. {
  1847. //修改对应配置,在其他单元的配置项要同时调用其修改函数修改真实值
  1848. //1. 修改内存中的值,用于给上层发消息
  1849. (*m_pAttribute)[strKey.c_str()] = DescriptionTempEx[i];
  1850. //2. 拿到Innerkey
  1851. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  1852. FINFO("nConfigInfoCount {$}", nConfigInfoCount);
  1853. string strTemp = ""; //存储AttributeKey
  1854. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  1855. {
  1856. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  1857. if (strTemp == strKey)
  1858. {
  1859. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  1860. break;
  1861. }
  1862. }
  1863. //3. 修改配置文件中的值
  1864. if (SetDeviceConfigValue(m_Configurations, strTemp.c_str(), 1, DescriptionTempEx[i]))
  1865. {
  1866. FDEBUG("SetDeviceConfigValue over");
  1867. bSaveFile = true;
  1868. }
  1869. }
  1870. else
  1871. {
  1872. FINFO("{$} is not a RW configuration item", strKey.c_str());
  1873. }
  1874. }
  1875. else
  1876. {
  1877. FINFO("without this attribute {$}", strKey.c_str());
  1878. }
  1879. }
  1880. catch (ResDataObjectExption& e)
  1881. {
  1882. printf("\nSetDriverConfig crashed: %s\n", e.what());
  1883. FERROR("SetDriverConfig crashed: {$}", e.what());
  1884. return false;
  1885. }
  1886. }
  1887. if (bSaveFile)
  1888. {
  1889. //3. 重新保存配置文件
  1890. SaveConfigFile(true);
  1891. }
  1892. return true;
  1893. }
  1894. bool nsGEN::DemoDriver::SaveConfigFile(bool bSendNotify)
  1895. {
  1896. m_ConfigAll["CONFIGURATION"] = m_Configurations;
  1897. bool bRt = m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
  1898. FINFO("SaveConfigFile over {$}", bRt);
  1899. return true;
  1900. }
  1901. bool nsGEN::DemoDriver::GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue)
  1902. {
  1903. strValue = "";
  1904. string strTemp = pInnerKey;
  1905. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  1906. {
  1907. int pos = 0;
  1908. ResDataObject resTemp = config;
  1909. while ((pos = strTemp.find_first_of(',')) != string::npos)
  1910. {
  1911. string Key = strTemp.substr(0, pos);
  1912. string TempValue = resTemp[Key.c_str()].encode();
  1913. // printf("-TempValue=== %s", TempValue.c_str());
  1914. resTemp.clear();
  1915. resTemp.decode(TempValue.c_str());
  1916. strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
  1917. //printf("-************--%s", strTemp.c_str());
  1918. }
  1919. if (strTemp != "")
  1920. {
  1921. strValue = (string)resTemp[strTemp.c_str()];
  1922. }
  1923. else
  1924. {
  1925. strValue = (string)resTemp;
  1926. }
  1927. }
  1928. //printf("------------%s", strValue.c_str());
  1929. return true;
  1930. }
  1931. bool nsGEN::DemoDriver::SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue)
  1932. {
  1933. string strTemp = pInnerKey;
  1934. FDEBUG("Begin to change {$} item value to {$}", pInnerKey, szValue);
  1935. printf("\n Begin to change {%s} item value to {%s}\n", pInnerKey, szValue);
  1936. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  1937. {
  1938. try {
  1939. int pos = 0;
  1940. ResDataObject* resTemp = &config;
  1941. while ((pos = strTemp.find_first_of(',')) != string::npos)
  1942. {
  1943. string Key = strTemp.substr(0, pos);
  1944. resTemp = &(*resTemp)[Key.c_str()];
  1945. strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
  1946. }
  1947. if (strTemp != "")
  1948. {
  1949. //if ((strTemp.compare("WSTable") == 0) ||
  1950. // (strTemp.compare("WSWall") == 0) ||
  1951. // (strTemp.compare("WSFree") == 0) ||
  1952. // (strTemp.compare("WSTomo") == 0) ||
  1953. // (strTemp.compare("WSConventional") == 0)
  1954. // )
  1955. //{
  1956. // int sum = (*szValue) + 1;
  1957. // (*resTemp)[strTemp.c_str()] = (char*)(&sum);
  1958. //}
  1959. //else
  1960. // (*resTemp)[strTemp.c_str()] = szValue;
  1961. (*resTemp)[strTemp.c_str()] = szValue;
  1962. }
  1963. else
  1964. {
  1965. *resTemp = szValue;
  1966. }
  1967. }
  1968. catch (ResDataObjectExption& e)
  1969. {
  1970. FERROR("SetDriverConfigvalue crashed: {$}", e.what());
  1971. return false;
  1972. }
  1973. }
  1974. return true;
  1975. }
  1976. std::string nsGEN::DemoDriver::GetResource()
  1977. {
  1978. ResDataObject r_config, temp;
  1979. if (!temp.loadFile(m_ConfigFileName.c_str()))
  1980. {
  1981. return "";
  1982. }
  1983. m_ConfigAll = temp;
  1984. r_config = temp["CONFIGURATION"];
  1985. m_Configurations = r_config;
  1986. ResDataObject DescriptionTemp;
  1987. ResDataObject DescriptionSend;
  1988. ResDataObject m_DescriptionSend;
  1989. ResDataObject ListTemp;
  1990. string strTemp = ""; //用于读取字符串配置信息
  1991. string strIndex = ""; //用于读取配置信息中的List项
  1992. int nTemp = -1; //用于读取整型配置信息
  1993. char sstream[10] = { 0 }; //用于转换值
  1994. string strValue = ""; //用于存储配置的值
  1995. string strType = ""; //用于存储配置的类型 int/float/string...
  1996. /***
  1997. * 1. 通过循环,将所有配置项写到pDeviceConfig
  1998. * 2. 记录配置项的内部key以及配置类型,类型对应了不同配置文件路径,用于读写真实值
  1999. ***/
  2000. try
  2001. {
  2002. //便利ConfigToolInfo 中 所有的AttributeInfo 属性段
  2003. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  2004. m_pAttribute->clear();
  2005. m_pDescription->clear();
  2006. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  2007. {
  2008. DescriptionTemp.clear();
  2009. DescriptionSend.clear();
  2010. ListTemp.clear();
  2011. //AttributeType
  2012. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Type"];
  2013. DescriptionTemp.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
  2014. DescriptionSend.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
  2015. strType = strTemp; //记录配置项的类型
  2016. //AttributeKey
  2017. //1. 根据AttributeType,内部key和配置路径,拿到当前的真实值
  2018. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  2019. nTemp = (int)m_Configurations["ConfigToolInfo"][nInfoIndex]["PathID"];
  2020. GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue); //得到strValue的值
  2021. //printf("********************************innerkey=%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
  2022. //2. 赋值
  2023. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  2024. if ("int" == strType)
  2025. {
  2026. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  2027. }
  2028. else if ("float" == strType)
  2029. {
  2030. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  2031. }
  2032. else //其它先按string类型处理
  2033. {
  2034. (*m_pAttribute).add(strTemp.c_str(), strValue.c_str());
  2035. }
  2036. //printf("********************************outkey =%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
  2037. //AttributeAccess
  2038. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Access"];
  2039. DescriptionTemp.add(ConfKey::CcosAccess, strTemp.c_str());
  2040. DescriptionSend.add(ConfKey::CcosAccess, strTemp.c_str());
  2041. /*
  2042. //AttributeRangeMin
  2043. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMin"];
  2044. if (strTemp != "") //不需要的配置项为空
  2045. {
  2046. DescriptionTemp.add(ConfKey::CcosRangeMin, strTemp.c_str());
  2047. }
  2048. //AttributeRangeMax
  2049. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMax"];
  2050. if (strTemp != "") //不需要的配置项为空
  2051. {
  2052. DescriptionTemp.add(ConfKey::CcosRangeMax, strTemp.c_str());
  2053. }
  2054. */
  2055. //AttributeList
  2056. nTemp = m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListNum"];
  2057. if (nTemp > 0) //ListNum不大于0时说明不需要list配置
  2058. {
  2059. for (int nListIndex = 0; nListIndex < nTemp; nListIndex++)
  2060. {
  2061. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListInfo"][nListIndex];
  2062. auto temKey = std::to_string(nListIndex);
  2063. ListTemp.add(temKey.c_str(), strTemp.c_str());
  2064. }
  2065. DescriptionTemp.add(ConfKey::CcosList, ListTemp);
  2066. DescriptionSend.add(ConfKey::CcosList, ListTemp.encode());
  2067. }
  2068. //AttributeRequired
  2069. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Required"];
  2070. DescriptionTemp.add(ConfKey::CcosRequired, strTemp.c_str());
  2071. DescriptionSend.add(ConfKey::CcosRequired, strTemp.c_str());
  2072. //AttributeDefaultValue
  2073. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["DefaultValue"];
  2074. if (strTemp != "") //不需要的配置项为空
  2075. {
  2076. DescriptionTemp.add(ConfKey::CcosDefaultValue, strTemp.c_str());
  2077. DescriptionSend.add(ConfKey::CcosDefaultValue, strTemp.c_str());
  2078. }
  2079. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  2080. (*m_pDescription).add(strTemp.c_str(), DescriptionTemp);
  2081. m_DescriptionSend.add(strTemp.c_str(), DescriptionSend.encode());
  2082. }
  2083. }
  2084. catch (ResDataObjectExption& e)
  2085. {
  2086. FERROR("Get config error: {$}", e.what());
  2087. return "";
  2088. }
  2089. ResDataObject resDeviceResource;
  2090. resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
  2091. resDeviceResource.add(ConfKey::CcosGeneratorDescription, (*m_pDescription));
  2092. ResDataObject DescriptionTempEx;
  2093. DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
  2094. m_DeviceConfig.clear();
  2095. m_DeviceConfig = DescriptionTempEx;
  2096. //FDEBUG("local ************* get resource over {$}", DescriptionTempEx.encode());
  2097. //printf("local ************* get resource over %s \n", DescriptionTempEx.encode());
  2098. resDeviceResource.clear();
  2099. resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
  2100. resDeviceResource.add(ConfKey::CcosGeneratorDescription, m_DescriptionSend);
  2101. DescriptionTempEx.clear();
  2102. DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
  2103. m_DeviceConfigSend.clear();
  2104. m_DeviceConfigSend = DescriptionTempEx;
  2105. string res = m_DeviceConfigSend.encode();
  2106. //printf("%s", res.c_str());
  2107. //FDEBUG("get resource over {$}", DescriptionTempEx.encode());
  2108. //printf("************* get resource over %s \n", DescriptionTempEx.encode());
  2109. return res;
  2110. }
  2111. std::string nsGEN::DemoDriver::DeviceProbe()
  2112. {
  2113. printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  2114. ResDataObject r_config, HardwareInfo;
  2115. if (r_config.loadFile(m_ConfigFileName.c_str()))
  2116. {
  2117. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  2118. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  2119. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  2120. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  2121. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  2122. }
  2123. else
  2124. {
  2125. HardwareInfo.add("MajorID", "Generator");
  2126. HardwareInfo.add("MinorID", "Dr");
  2127. HardwareInfo.add("VendorID", "DEMO");
  2128. HardwareInfo.add("ProductID", "HF");
  2129. HardwareInfo.add("SerialID", "1234");
  2130. }
  2131. string ret = HardwareInfo.encode();
  2132. return ret;
  2133. }
  2134. void nsGEN::DemoDriver::Dequeue(const char* Packet, DWORD Length)
  2135. {
  2136. //DecodeFrame(Packet, Length); //无真实数据,此处直接空.
  2137. }
  2138. //In Demo mode ,will not enter here
  2139. int nsGEN::DemoDriver::callbackPackageProcess(const char* RecData, DWORD nLength, DWORD& PacketLength)
  2140. {
  2141. return 0;
  2142. }
  2143. //-----------------------------------------------------------------------------
  2144. // GetIODriver & CreateIODriver
  2145. //-----------------------------------------------------------------------------
  2146. static nsGEN::DemoDriver gIODriver;
  2147. extern "C" CCOS::Dev::IODriver * GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
  2148. {
  2149. return &gIODriver;
  2150. }
  2151. extern "C" CCOS::Dev::IODriver * CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
  2152. {
  2153. return new nsGEN::DemoDriver();
  2154. }