CCOS.Dev.Generator.Demo.cpp 70 KB

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