DIOS.Dev.Generator.MERCURY.cpp 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069
  1. #include "stdafx.h"
  2. #include <assert.h>
  3. #include <functional>
  4. #include "LogicDevice.h"
  5. #include <unordered_map>
  6. #include "Helper.JSON.hpp"
  7. #include "CCOS.Dev.Generator.MERCURY.h"
  8. using namespace CCOS::Dev::Detail::Generator;
  9. namespace nsGEN = CCOS::Dev::Detail::Generator;
  10. using namespace std::placeholders;
  11. static nsGEN::MERCURYDriver* pIODriver = nullptr;
  12. //关闭无关警告
  13. #pragma warning (disable:4244) // warning C4244: “初始化”: 从“double”转换到“float”,可能丢失数据
  14. #pragma warning (disable:4305) // warning C4305: “参数”: 从“double”到“float”截断
  15. #pragma warning (disable:4267) // warning C4267 : “初始化”: 从“size_t”转换到“int”,可能丢失数据
  16. #pragma warning (disable:4805) // warning C4805: “!=”: 在操作中将类型“bool”与类型“int”混合不安全
  17. #define PSGHR_LARGE_POWER 5
  18. #define PSGHR_SMALL_POWER 1.1
  19. #define PSGHR_MAX_HEAT 225
  20. #define PSGHR_MIN_MA 1.0
  21. #define PSGHR_MAX_MA 1000.0
  22. #define PSGHR_MIN_MS 1.0
  23. #define PSGHR_MAX_MS 10001.0
  24. //设置相关常量
  25. #define PSGHR_LoopDefHBTime 1000
  26. #define PSGHR_LoopExpHBTime 500
  27. static const int msTimeOut_Lock = 500; //通讯接口锁定时间
  28. #define PSGHR_Com_NormalLen 150
  29. #define PSGHR_ETX 0x03
  30. #define PSGHR_RESOK "$"
  31. //设置对应通信接口库
  32. #ifdef _WIN64
  33. #ifdef _DEBUG
  34. static const auto COM_SCFDllName = "Ccos.Dev.SerialSCFX64D.dll";
  35. #else
  36. static const auto COM_SCFDllName = "Ccos.Dev.SerialSCFX64.dll";
  37. #endif
  38. #endif
  39. #ifdef _WIN64
  40. #ifdef _DEBUG
  41. static const auto TCP_SCFDllName = "Ccos.Dev.TcpipSCFX64D.dll";
  42. #else
  43. static const auto TCP_SCFDllName = "Ccos.Dev.TcpipSCFX64.dll";
  44. #endif
  45. #endif
  46. Log4CPP::Logger* mLog::gLogger = nullptr;
  47. struct tFrameMapping
  48. {
  49. static const int MaxLen = 5; // 前缀不能超超过 5 个字符 !
  50. using cbFun = std::function <void(const char*, int)>;
  51. char strHead[MaxLen];
  52. int NbOfCharOfHead;
  53. cbFun fun;
  54. tFrameMapping(char* str, int len, cbFun f)
  55. {
  56. assert(len < MaxLen); //len最大只能是4
  57. for (int i = 0; i < len; i++)
  58. strHead[i] = str[i];
  59. NbOfCharOfHead = len;
  60. fun = f;
  61. }
  62. };
  63. //响应操作对照表
  64. static std::list <tFrameMapping> arFrame;
  65. //查找响应操作对照表执行对应操作
  66. static bool DecodeFrame(const char* strFrame, int length)
  67. {
  68. auto pr = [strFrame, length](const tFrameMapping& Item)
  69. {
  70. for (int i = 0; i < Item.NbOfCharOfHead; i++)
  71. {
  72. if (strFrame[i] != Item.strHead[i])
  73. {
  74. return false;
  75. }
  76. }
  77. return true;
  78. };
  79. auto found = std::find_if(arFrame.begin(), arFrame.end(), pr);//此处pr,是上面定义的 lambda表达式,用来在list中找到对于的包头。
  80. if (found == arFrame.end())
  81. {
  82. return false;
  83. }
  84. const auto& Item = *found;
  85. auto pc = strFrame;
  86. char data[100] = { 0 };
  87. memcpy(data, strFrame + Item.NbOfCharOfHead, length - Item.NbOfCharOfHead);
  88. Item.fun(data, length - Item.NbOfCharOfHead);
  89. return true;
  90. }
  91. //-----------------------------------------------------------------------------
  92. // MERCURYDevice
  93. //-----------------------------------------------------------------------------
  94. atomic<int> nsGEN::MERCURYDevice::m_iLoopTime = PSGHR_LoopDefHBTime;
  95. atomic<bool> nsGEN::MERCURYDevice::m_bExtraFlag = false;
  96. static atomic<bool>HeartBeatFlag = false;
  97. nsGEN::MERCURYDevice::MERCURYDevice(std::shared_ptr <IOEventCenter> center, nsSCF::SCF SCF, string configfile) : super(center, SCF)
  98. {
  99. assert(EventCenter);
  100. m_bExtraFlag = true;
  101. //初始化
  102. ResDataObject temp;
  103. temp.loadFile(configfile.c_str());
  104. m_GenConfig = temp["CONFIGURATION"];
  105. TransJsonText(m_GenConfig);
  106. m_pHardwareStatusThread = NULL;
  107. m_pHardwareRsSendThread = NULL;
  108. m_bExpEnable = false;
  109. m_iHeartBeats = 0;
  110. m_bConnectFlag = true;
  111. m_bGenBusy = false;
  112. m_bReturnFlag = false;
  113. m_iLoopTime.store(PSGHR_LoopDefHBTime);
  114. for (int i = 0; i < 18; i++)
  115. {
  116. m_bFaultList[i] = false;
  117. };
  118. m_bMAS_MA_AEC = false;
  119. m_iMaxPower = PSGHR_LARGE_POWER; //KW
  120. MaxHeatContent = PSGHR_MAX_HEAT; //KJ
  121. if (m_GenConfig.GetKeyCount("loopEnable") > 0)
  122. {
  123. m_bExtraFlag = (int)m_GenConfig["loopEnable"];
  124. }
  125. string version;
  126. if(GetVersion(version, hMyModule))
  127. mLog::FINFO("\n===============log begin : version:{$} ===================\n", version.c_str());
  128. else
  129. mLog::FINFO("\n===============log begin : version:0.0.0.0 ===================\n");
  130. //设置发生器属性集合各个值的范围及精度
  131. m_DoseUnit.m_KV.reset(new KVMould(0.0, 39.0, 151.0, 1.0));
  132. m_DoseUnit.m_MA.reset(new MAMould(0.0, PSGHR_MIN_MA, PSGHR_MAX_MA, 0.1));
  133. m_DoseUnit.m_MS.reset(new MSMould(0.0, PSGHR_MIN_MS, PSGHR_MAX_MS, 0.01));
  134. m_DoseUnit.m_MAS.reset(new MASMould(0.0, 0.1, 1000.0, 0.01));
  135. m_DoseUnit.m_Techmode.reset(new TECHMODEMould(AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P, AttrKey::TECHMODE_NOAEC_3P, AttrKey::TECHMODE_AEC_MAS_MA, 1));
  136. m_DoseUnit.m_WS.reset(new WORKSTATIONMould(1, 0, 5, 1));
  137. m_DoseUnit.m_Focus.reset(new FOCUSMould(AttrKey::FOCUS_TYPE::FOCUS_LARGE, AttrKey::FOCUS_SMALL, AttrKey::FOCUS_LARGE, 1));
  138. m_DoseUnit.m_AECField.reset(new AECFIELDMould(0, 0, 111, 1));
  139. m_DoseUnit.m_AECFilm.reset(new AECFILMMould(0, 0, 2, 1));
  140. m_DoseUnit.m_AECDensity.reset(new AECDENSITYMould(0, -3, 3, 1));
  141. m_DoseUnit.m_GenHE.reset(new GENHEATMould(0, 0, 100, 1));
  142. m_DoseUnit.m_HE.reset(new TUBEHEATMould(0, 0, 100, 1));
  143. m_DoseUnit.m_GenSynState.reset(new GENSYNSTATEMould(AttrKey::GENERATOR_RAD_OFF, AttrKey::GENERATOR_SYNC_ERR, AttrKey::GENERATOR_SYNC_MAX, 1));
  144. m_DoseUnit.m_GenState.reset(new GENSTATEMould(0, AttrKey::GENERATOR_STATUS_SHUTDOWN, AttrKey::GENERATOR_STATUS_MAX, 1));
  145. m_DoseUnit.m_GenTotalExpNumber.reset(new TOTALEXPNUMMould(0, 0, 9999, 1));
  146. m_DoseUnit.m_GenTotalAcqTimes.reset(new TOTALACQTIMESMould(0, 0, 9999, 1));
  147. m_DoseUnit.m_GenTubeCoolWaitTimes.reset(new TUBECOOLTIMEMould(0, 0, 9999, 1));
  148. m_DoseUnit.m_GenTubeOverLoadNumber.reset(new TUBEOVERLOADNUMMould(0, 0, 9999, 1));
  149. m_DoseUnit.m_GenCurrentExpNumber.reset(new CUREXPNUMMould(0, 0, 9999, 1));
  150. m_DoseUnit.m_ExpMode.reset(new EXPMODEMould(AttrKey::EXPMODE_TYPE::Single));
  151. m_DoseUnit.m_FrameRate.reset(new FRAMERATEMould(0, 0, 16, 1));
  152. m_DoseUnit.m_TubeTargetMaterial.reset(new TUBETARGETMATERIALMould(AttrKey::TUBETARGETMATERIAL_TYPE::MO));
  153. m_DoseUnit.m_TubeAngle.reset(new TUBEANGLEMould(0, -45, 45, 1));
  154. m_DoseUnit.m_PPS.reset(new PPSMould(0.5,0.5, 30, 0.1));
  155. m_DoseUnit.m_DoseLevel.reset(new FLUDoseLevelMould(0, 0, 2, 1));
  156. //Actual exposure parameters 值
  157. m_DoseUnit.m_PostKV.reset(new POSTKVMould(0.0, 40.0, 120.0, 1.0));
  158. m_DoseUnit.m_PostMA.reset(new POSTMAMould(0.0, 1.0, 1000.0, 0.1));
  159. m_DoseUnit.m_PostMS.reset(new POSTMSMould(0.0, 1.0, 10000.0, 0.01));
  160. m_DoseUnit.m_PostMAS.reset(new POSTMASMould(0.0, 0.5, 1000.0, 0.01));
  161. //发生器告警及错误消息
  162. m_MSGUnit.reset(new nsDetail::MSGUnit(center, nsGEN::GeneratorUnitType));
  163. m_hGenPostEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  164. if (m_GenConfig.GetKeyCount(ConfKey::CcosTubeInfo) > 0)
  165. {
  166. string tempValue = m_GenConfig[ConfKey::CcosTubeInfo];
  167. m_DoseUnit.m_TubeInfo.reset(new TUBEINFOMould(tempValue));
  168. FireNotify(AttrKey::TUBEINFO, m_DoseUnit.m_TubeInfo->JSGet());
  169. }
  170. if (m_GenConfig.GetKeyCount(ConfKey::CcosFocusSmall) > 0)
  171. {
  172. float tempValue = (float)m_GenConfig[ConfKey::CcosFocusSmall];
  173. m_DoseUnit.m_FocusSmall = tempValue;
  174. }
  175. if (m_GenConfig.GetKeyCount(ConfKey::CcosFocusLarge) > 0)
  176. {
  177. float tempValue = (float)m_GenConfig[ConfKey::CcosFocusLarge];
  178. m_DoseUnit.m_FocusLarge = tempValue;
  179. }
  180. if (m_GenConfig.GetKeyCount("GenCtrlMode") > 0)
  181. {
  182. m_nCtlMode = (float)m_GenConfig["GenCtrlMode"];//default 2
  183. float tempValue = (float)m_GenConfig[ConfKey::CcosFocusLarge];
  184. }
  185. m_bDAPEnable = false;
  186. m_bSaveMSMA = true;
  187. InitCallBack();
  188. Register();
  189. ECHO();
  190. GetTechMode();
  191. GetST();
  192. //启动硬件状态轮询进程
  193. StartHardwareStatusThread();
  194. }
  195. nsGEN::MERCURYDevice::~MERCURYDevice()
  196. {
  197. m_bExtraFlag = false;
  198. mLog::FINFO("\n===============log end ===================\n");
  199. CloseHandle(m_hGenPostEvent);
  200. if (m_pHardwareRsSendThread != NULL)
  201. {
  202. WaitForSingleObject(m_pHardwareRsSendThread, INFINITE);
  203. CloseHandle(m_pHardwareRsSendThread);
  204. m_pHardwareRsSendThread = NULL;
  205. }
  206. if (m_pHardwareStatusThread != NULL)
  207. {
  208. WaitForSingleObject(m_pHardwareStatusThread, INFINITE);
  209. CloseHandle(m_pHardwareStatusThread);
  210. m_pHardwareStatusThread = NULL;
  211. }
  212. arFrame.clear();
  213. }
  214. std::string nsGEN::MERCURYDevice::GetGUID() const
  215. {
  216. mLog::FINFO("===============GetGUID : {$} ===================\n", GeneratorUnitType);
  217. return GeneratorUnitType;
  218. }
  219. void nsGEN::MERCURYDevice::Register()
  220. {
  221. auto Disp = &Dispatch;
  222. superGen::Register(Disp);
  223. superGen::RegisterRAD(Disp);
  224. superGen::RegisterExpEnable(Disp);
  225. superGen::RegisterGeneratortoSyncStatus(Disp);
  226. Disp->Get.Push(m_MSGUnit->GetKey().c_str(), [this](std::string& out) { out = m_MSGUnit->JSGet(); return RET_STATUS::RET_SUCCEED; });
  227. Disp->Get.Push(AttrKey::DENHEAT, [this](std::string& out) { out = m_DoseUnit.m_GenHE->JSGet(); return RET_STATUS::RET_SUCCEED; });
  228. auto fun_Clear_DAP = [this](auto in, auto& out)
  229. {
  230. return Clear_DAP();
  231. };
  232. Disp->Action.Push("Clear_DAP", fun_Clear_DAP);
  233. auto fun_GetValue_DAP = [this](auto in, auto& out)
  234. {
  235. float value = 0;
  236. RET_STATUS ret = GetValue_DAP(value);
  237. out = ToJSON(value);
  238. return ret;
  239. };
  240. Disp->Action.Push("GetValue_DAP", fun_GetValue_DAP);
  241. }
  242. RET_STATUS nsGEN::MERCURYDevice::SetKV(float value)
  243. {
  244. mLog::FINFO("{$}KV", value);
  245. if (!m_DoseUnit.m_KV->Verify(value)) return RET_STATUS::RET_SUCCEED;
  246. char temp[50] = { 0 };
  247. sprintf_s(temp, "KV%03d", (int)value);
  248. return HWSend(temp, strlen(temp));
  249. }
  250. RET_STATUS nsGEN::MERCURYDevice::IncKV()
  251. {
  252. mLog::FINFO("Inc KV");
  253. if (!m_DoseUnit.m_KV->CanInc()) return RET_STATUS::RET_SUCCEED;
  254. return HWSend("KV+", 3);
  255. }
  256. RET_STATUS nsGEN::MERCURYDevice::DecKV()
  257. {
  258. mLog::FINFO("Dec KV");
  259. if (!m_DoseUnit.m_KV->CanDec()) return RET_STATUS::RET_SUCCEED;
  260. return HWSend("KV-", 3);
  261. }
  262. RET_STATUS CCOS::Dev::Detail::Generator::MERCURYDevice::IncKVL()
  263. {
  264. mLog::FINFO("Inc KVL");
  265. if (!m_DoseUnit.m_KV->CanInc()) return RET_STATUS::RET_SUCCEED;
  266. return HWSend("KV++", 4);
  267. }
  268. RET_STATUS CCOS::Dev::Detail::Generator::MERCURYDevice::DecKVL()
  269. {
  270. mLog::FINFO("Dec KVL");
  271. if (!m_DoseUnit.m_KV->CanDec()) return RET_STATUS::RET_SUCCEED;
  272. return HWSend("KV--", 4);
  273. }
  274. RET_STATUS nsGEN::MERCURYDevice::IncMA()
  275. {
  276. mLog::FINFO("Inc MA");
  277. if (!m_DoseUnit.m_MA->CanInc()) return RET_STATUS::RET_SUCCEED;
  278. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  279. {
  280. mLog::FINFO("Techmode is MAS, can't inc MA");
  281. return RET_STATUS::RET_FAILED;
  282. }
  283. return HWSend("MA+",3);
  284. }
  285. RET_STATUS nsGEN::MERCURYDevice::DecMA()
  286. {
  287. mLog::FINFO("Dec MA");
  288. if (!m_DoseUnit.m_MA->CanDec()) return RET_STATUS::RET_SUCCEED;
  289. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  290. {
  291. mLog::FINFO("Techmode is MAS, can't dec MA");
  292. return RET_STATUS::RET_FAILED;
  293. }
  294. return HWSend("MA-", 3);
  295. }
  296. RET_STATUS nsGEN::MERCURYDevice::SetMA(float value)
  297. {
  298. mLog::FINFO("{$}MA", value);
  299. if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
  300. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  301. {
  302. mLog::FINFO("Techmode is MAS, can't set MA");
  303. return RET_STATUS::RET_FAILED;
  304. }
  305. char temp[50] = { 0 };
  306. sprintf_s(temp, "MA%05d", (int)(value * 10));
  307. return HWSend(temp, strlen(temp));
  308. }
  309. RET_STATUS nsGEN::MERCURYDevice::IncMS()
  310. {
  311. mLog::FINFO("Inc MS");
  312. if (!m_DoseUnit.m_MS->CanInc()) return RET_STATUS::RET_SUCCEED;
  313. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
  314. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  315. {
  316. mLog::FINFO("Techmode is 2Point, Cannot inc MS");
  317. return RET_STATUS::RET_FAILED;
  318. }
  319. return HWSend("MS+",3);
  320. }
  321. RET_STATUS nsGEN::MERCURYDevice::DecMS()
  322. {
  323. mLog::FINFO("Dec MS");
  324. if (!m_DoseUnit.m_MS->CanDec()) return RET_STATUS::RET_SUCCEED;
  325. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
  326. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  327. {
  328. mLog::FINFO("Techmode is 2Point, Cannot dec MS");
  329. return RET_STATUS::RET_FAILED;
  330. }
  331. return HWSend("MS-", 3);;
  332. }
  333. RET_STATUS nsGEN::MERCURYDevice::SetMS(float value)
  334. {
  335. mLog::FINFO("{$}MS", value);
  336. if (!m_DoseUnit.m_MS->Verify(value)) return RET_STATUS::RET_SUCCEED;
  337. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
  338. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  339. {
  340. mLog::FINFO("Techmode is 2Point, Cannot set MS");
  341. return RET_STATUS::RET_FAILED;
  342. }
  343. char temp[50] = { 0 };
  344. sprintf_s(temp, "MS%06d", (int)(value * 10));
  345. return HWSend(temp,strlen(temp));
  346. }
  347. RET_STATUS nsGEN::MERCURYDevice::IncMAS()
  348. {
  349. mLog::FINFO("Inc MAS");
  350. if (!m_DoseUnit.m_MAS->CanInc()) return RET_STATUS::RET_SUCCEED;
  351. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
  352. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
  353. {
  354. mLog::FINFO("Techmode is 3Point, Cannot inc MAS");
  355. return RET_STATUS::RET_FAILED;
  356. }
  357. return HWSend("MX+" , 3);
  358. }
  359. RET_STATUS nsGEN::MERCURYDevice::DecMAS()
  360. {
  361. mLog::FINFO("Dec MAS");
  362. if (!m_DoseUnit.m_MAS->CanDec()) return RET_STATUS::RET_SUCCEED;
  363. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
  364. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
  365. {
  366. mLog::FINFO("Techmode is 3Point, Cannot dec MAS");
  367. return RET_STATUS::RET_FAILED;
  368. }
  369. return HWSend("MX-", 3);
  370. }
  371. RET_STATUS nsGEN::MERCURYDevice::SetMAS(float value)
  372. {
  373. mLog::FINFO("{$}MAS", value);
  374. if (!m_DoseUnit.m_MAS->Verify(value)) return RET_STATUS::RET_SUCCEED;
  375. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
  376. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
  377. {
  378. mLog::FINFO("Techmode is 3Point, Cannot set MAS");
  379. return RET_STATUS::RET_FAILED;
  380. }
  381. char temp[50] = { 0 };
  382. sprintf_s(temp, "MX%06d", (int)(value * 100));
  383. return HWSend(temp, strlen(temp));
  384. }
  385. RET_STATUS nsGEN::MERCURYDevice::SetTechmode(int value)
  386. {
  387. mLog::FINFO("TechMode: {$}", value);
  388. if (!m_DoseUnit.m_Techmode->Verify(value)) return RET_STATUS::RET_SUCCEED;
  389. char temp[50] = { 0 };
  390. sprintf_s(temp, "ET%1d", (int)value);
  391. HWSend(temp, strlen(temp));
  392. }
  393. RET_STATUS nsGEN::MERCURYDevice::SetEXAMMode(std::string value)
  394. {
  395. mLog::FINFO("Exammode: {$}", value);
  396. if (value == AttrKey::EXAMMODE_TYPE::MANUAL)
  397. {
  398. SetTechmode(AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P);
  399. }
  400. else if (value == AttrKey::EXAMMODE_TYPE::SEMIAUTO)
  401. {
  402. SetTechmode(AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P);
  403. }
  404. else if (value == AttrKey::EXAMMODE_TYPE::AUTOMATIC)
  405. {
  406. SetTechmode(AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P);
  407. }
  408. return RET_STATUS::RET_SUCCEED;
  409. }
  410. RET_STATUS nsGEN::MERCURYDevice::SetAPR(const _tAPRArgs& t)
  411. {
  412. m_bGenBusy = true;
  413. mLog::FINFO("APR:KV: {$},MA: {$},MS: {$},MAS: {$},Focus: {$},Techmode: {$},WS: {$},AECDensity: {$},AECField: {$},AECFilm: {$}", t.fKV, t.fMA, t.fMS, t.fMAS, t.nFocus, t.nTechmode, t.nWS, t.nAECDensity, t.nAECField, t.nAECFilm);
  414. if (t.nFocus < 0)
  415. {
  416. mLog::FINFO("SetAPR: the focus value is amall than 0, set focus to small focus\n");
  417. SetFocus(0);
  418. }
  419. int nTempAECFilm = 1;
  420. switch (t.nAECFilm)
  421. {
  422. case 0:
  423. nTempAECFilm = 1;
  424. break;
  425. case 1:
  426. nTempAECFilm = 10;
  427. break;
  428. case 2:
  429. nTempAECFilm = 100;
  430. break;
  431. default:
  432. break;
  433. }
  434. GetTechMode();
  435. SetKV(t.fKV);
  436. SetFocus(t.nFocus);
  437. SetWS("Table");
  438. Sleep(50);
  439. SetTechmode(t.nTechmode);
  440. if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_AEC)
  441. {
  442. // aec
  443. Sleep(50);
  444. SetAECField(t.nAECField);
  445. Sleep(80);
  446. SetAECDensity(t.nAECDensity);
  447. Sleep(50);
  448. SetAECFilm(nTempAECFilm);
  449. Sleep(50);
  450. SetMA(t.fMA);
  451. Sleep(50);
  452. SetMS(t.fMS);
  453. }
  454. else if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  455. {
  456. // mas
  457. Sleep(50);
  458. const float EPSINON = 0.000001;
  459. if ((t.fMAS >= -EPSINON) && (t.fMAS <= EPSINON))
  460. {
  461. SetMAS(t.fMA * t.fMS / 1000);
  462. }
  463. else
  464. {
  465. SetMAS(t.fMAS);
  466. }
  467. }
  468. else if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_TIME)
  469. {
  470. // time
  471. Sleep(50);
  472. SetMA(t.fMA);
  473. Sleep(80);
  474. SetMS(t.fMS);
  475. }
  476. m_bGenBusy = false;
  477. return RET_STATUS::RET_SUCCEED;
  478. }
  479. RET_STATUS nsGEN::MERCURYDevice::SetFocus(int value)
  480. {
  481. mLog::FINFO("FOCUS: {$}", value);
  482. if (!m_DoseUnit.m_Focus->Verify(value)) return RET_STATUS::RET_SUCCEED;
  483. char temp[50] = { 0 };
  484. sprintf_s(temp, "FO%01d", (int)value);
  485. return HWSend(temp,strlen(temp));
  486. }
  487. RET_STATUS CCOS::Dev::Detail::Generator::MERCURYDevice::SetAECDensity(int value)
  488. {
  489. return RET_STATUS();
  490. }
  491. RET_STATUS CCOS::Dev::Detail::Generator::MERCURYDevice::SetAECField(int value)
  492. {
  493. return RET_STATUS();
  494. }
  495. RET_STATUS CCOS::Dev::Detail::Generator::MERCURYDevice::SetAECFilm(int value)
  496. {
  497. return RET_STATUS();
  498. }
  499. RET_STATUS nsGEN::MERCURYDevice::Reset()
  500. {
  501. mLog::FDEBUG("clear all errors \n");
  502. int level = 0;
  503. m_MSGUnit->DelErrorMessage("0", level, "clear all errors");
  504. m_MSGUnit->DelWarnMessage("0", level, "clear all Warning");
  505. HWSend("RE",2);//仅重置错误状态
  506. return RET_STATUS::RET_SUCCEED;
  507. }
  508. RET_STATUS nsGEN::MERCURYDevice::QueryHE(int& value)
  509. {
  510. if (!m_bGenBusy)
  511. return HWSend("HE?", 3);
  512. return RET_STATUS::RET_SUCCEED;
  513. }
  514. void nsGEN::MERCURYDevice::SubscribeSelf(ccos_mqtt_connection* conn)
  515. {
  516. //订阅GEN所有Action
  517. SubscribeTopic(conn, "CCOS/DEVICE/Generator/Action/#");
  518. }
  519. RET_STATUS nsGEN::MERCURYDevice::SetVibrationGrid(int value)//发生器暂无此设置
  520. {
  521. mLog::FINFO("Enter StartVibrationGrid:[{$}]", value);
  522. return RET_STATUS::RET_SUCCEED;
  523. }
  524. RET_STATUS nsGEN::MERCURYDevice::GetVibrationGridMS(int& value) //发生器暂无此设置
  525. {
  526. return RET_STATUS::RET_SUCCEED;
  527. }
  528. RET_STATUS nsGEN::MERCURYDevice::SetWS(const string value)
  529. {
  530. mLog::FINFO("WS: {$}", value);
  531. int tempws = 0;
  532. if (value == "Table") tempws = (int)m_GenConfig["WSTable"];
  533. else if (value == "Wall") tempws = (int)m_GenConfig["WSWall"];
  534. else if (value == "Direct") tempws = (int)m_GenConfig["WSConventional"];
  535. else if (value == "Free") tempws = (int)m_GenConfig["WSFree"];
  536. else if (value == "Tomo") tempws = (int)m_GenConfig["WSTomo"];
  537. m_DoseUnit.m_WS->Update(tempws);
  538. char temp[50] = { 0 };
  539. sprintf_s(temp, "WS%01d", tempws);
  540. return HWSend(temp, strlen(temp));
  541. }
  542. RET_STATUS CCOS::Dev::Detail::Generator::MERCURYDevice::SetGenSynState(int value)
  543. {
  544. return RET_STATUS();
  545. }
  546. RET_STATUS CCOS::Dev::Detail::Generator::MERCURYDevice::SetGenState(int value)
  547. {
  548. return RET_STATUS();
  549. }
  550. RET_STATUS nsGEN::MERCURYDevice::QueryPostKV(float& value)
  551. {
  552. m_DoseUnit.m_PostKV->Update(m_DoseUnit.m_KV->Get());
  553. value = m_DoseUnit.m_PostKV->Get();
  554. return HWSend("VP?",3);
  555. }
  556. RET_STATUS nsGEN::MERCURYDevice::QueryPostMA(float& value)
  557. {
  558. return HWSend("PA?", 3);
  559. }
  560. RET_STATUS nsGEN::MERCURYDevice::QueryPostMS(float& value)
  561. {
  562. return HWSend("AT?",3);
  563. }
  564. RET_STATUS nsGEN::MERCURYDevice::QueryPostMAS(float& value)
  565. {
  566. return HWSend("AP?", 3);
  567. }
  568. RET_STATUS nsGEN::MERCURYDevice::Clear_DAP()
  569. {
  570. if (m_bDAPEnable)
  571. {
  572. return HWSend("DZ",2);
  573. }
  574. return RET_STATUS::RET_SUCCEED;
  575. }
  576. RET_STATUS nsGEN::MERCURYDevice::GetValue_DAP(float& value)
  577. {
  578. return RET_STATUS::RET_SUCCEED;
  579. }
  580. RET_STATUS nsGEN::MERCURYDevice::SetExpMode(std::string value)
  581. {
  582. mLog::FINFO("Enter SetExpMode...{$} \n",value.c_str());
  583. m_DoseUnit.m_ExpMode->Update(value);
  584. //add for dcm iRF hard
  585. mLog::FINFO("SetExpMode:add for dcm iRF hard");
  586. FireNotify(m_DoseUnit.m_TubeTargetMaterial->GetKey(), m_DoseUnit.m_TubeTargetMaterial->JSGet());
  587. FireNotify(m_DoseUnit.m_TubeAngle->GetKey(), m_DoseUnit.m_TubeAngle->JSGet());
  588. return RET_STATUS::RET_SUCCEED;
  589. }
  590. RET_STATUS CCOS::Dev::Detail::Generator::MERCURYDevice::SetFrameRate(FLOAT frameRate)
  591. {
  592. return RET_STATUS();
  593. }
  594. RET_STATUS nsGEN::MERCURYDevice::SetExpEnable()
  595. {
  596. mLog::FINFO("SetExpEnable in\n");
  597. m_bExpEnable = true;
  598. if (m_DoseUnit.m_GenState->Get() != nsGEN::AttrKey::GENERATOR_STATUS_ERROR)
  599. {
  600. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
  601. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  602. }
  603. return RET_STATUS::RET_SUCCEED;
  604. }
  605. RET_STATUS nsGEN::MERCURYDevice::SetExpDisable()
  606. {
  607. if (m_DoseUnit.m_GenState->Get() != nsGEN::AttrKey::GENERATOR_STATUS_ERROR)
  608. {
  609. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_SLEEP);
  610. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  611. }
  612. mLog::FINFO("SetExpDisable in\n");
  613. m_bExpEnable = false;
  614. return RET_STATUS::RET_SUCCEED;
  615. }
  616. //-----------------------------------------------------------------------------
  617. // ProcessCmd
  618. //-----------------------------------------------------------------------------
  619. RET_STATUS nsGEN::MERCURYDevice::HWSend(const char* strCommand,int lengh, bool reSend, int nTimeOut)
  620. {
  621. if (!m_bConnectFlag)
  622. {
  623. mLog::FERROR("==OUT==: not Connect,[{$}] send failed \n", strCommand);
  624. return RET_STATUS::RET_FAILED;
  625. }
  626. if (!m_SCF) return RET_STATUS::RET_FAILED;
  627. char strSendCommand[100] = { 0 };
  628. int len = strlen(strCommand);
  629. int tmpSum = 0;
  630. for (int i = 0; i < len; i++)
  631. {
  632. tmpSum += (int)strCommand[i];
  633. }
  634. char checkSum = char(tmpSum + 3);
  635. memcpy(strSendCommand, strCommand, len);
  636. strSendCommand[len + 0] = 0x03;
  637. strSendCommand[len + 1] = checkSum;
  638. mLog::FINFO("==OUT==: [{$}] \n", strSendCommand);
  639. int retLength;
  640. m_SCF.Lock(msTimeOut_Lock)
  641. .SendPacket(strSendCommand, strlen(strSendCommand), nTimeOut, retLength);
  642. return RET_STATUS::RET_SUCCEED;
  643. }
  644. void nsGEN::MERCURYDevice::FireNotify(string key, int context)
  645. {
  646. char szInfo[64] = { 0 };
  647. sprintf_s(szInfo, "%d", context);
  648. std::string str = szInfo;
  649. EventCenter->OnNotify(1, key, str);
  650. }
  651. void nsGEN::MERCURYDevice::FireNotify(std::string key, float context)
  652. {
  653. char szInfo[16] = { 0 };
  654. sprintf_s(szInfo,15, "%.2f", context);
  655. std::string str = szInfo;
  656. mLog::FINFO("FireNotify(float):[{$}][{$}]", szInfo, str.c_str());
  657. EventCenter->OnNotify(1, key, str);
  658. }
  659. void nsGEN::MERCURYDevice::FireNotify(std::string key, std::string context)
  660. {
  661. EventCenter->OnNotify(1, key, context);
  662. }
  663. void nsGEN::MERCURYDevice::FireErrorMessage(const bool Act, const int Code, const char* ResInfo)
  664. {
  665. string ErrorCode("PSGHR_ERR_");
  666. ErrorCode += std::to_string(Code);
  667. int level = MERCURY_REGULATION_LEVEL::REG_ERRO;
  668. if (Act)
  669. {
  670. mLog::FERROR("add {$}:{$}", ErrorCode.c_str(), ResInfo);
  671. m_MSGUnit->AddErrorMessage(ErrorCode.c_str(), level, ResInfo);
  672. }
  673. else
  674. {
  675. mLog::FERROR("del {$}:{$}", ErrorCode.c_str(), ResInfo);
  676. m_MSGUnit->DelErrorMessage(ErrorCode.c_str(), level, ResInfo);
  677. }
  678. }
  679. void nsGEN::MERCURYDevice::FireWarnMessage(const bool Act, const int Code, const char* ResInfo)
  680. {
  681. string ErrorCode("PSGHR_WAR_");
  682. ErrorCode += std::to_string(Code);
  683. int level = MERCURY_REGULATION_LEVEL::REG_WARN;
  684. if (Act)
  685. {
  686. mLog::FERROR("add {$}:{$}", ErrorCode.c_str(), ResInfo);
  687. m_MSGUnit->AddWarnMessage(ErrorCode.c_str(), level, ResInfo);
  688. }
  689. else
  690. {
  691. mLog::FERROR("del {$}:{$}", ErrorCode.c_str(), ResInfo);
  692. m_MSGUnit->DelWarnMessage(ErrorCode.c_str(), level, ResInfo);
  693. }
  694. }
  695. void CCOS::Dev::Detail::Generator::MERCURYDevice::GetST()
  696. {
  697. mLog::FINFO("Get Generator Status");
  698. HWSend("ST?", 3);
  699. }
  700. void CCOS::Dev::Detail::Generator::MERCURYDevice::GetTechMode()
  701. {
  702. mLog::FINFO("Get TechMode");
  703. HWSend("ET?", 3);
  704. }
  705. void CCOS::Dev::Detail::Generator::MERCURYDevice::RefreshConData()
  706. {
  707. mLog::FINFO("ReFresh Con Data");
  708. HWSend("RR", 2);
  709. }
  710. void CCOS::Dev::Detail::Generator::MERCURYDevice::RespondPR0()
  711. {
  712. mLog::FINFO("Respond: PRO");
  713. HWSend("PR0", 3);
  714. }
  715. void CCOS::Dev::Detail::Generator::MERCURYDevice::RespondPR1()
  716. {
  717. mLog::FINFO("Respond: PR1");
  718. HWSend("PR1", 3);
  719. }
  720. void CCOS::Dev::Detail::Generator::MERCURYDevice::RespondPR2()
  721. {
  722. mLog::FINFO("Respond: PR2");
  723. HWSend("PR2", 3);
  724. }
  725. void CCOS::Dev::Detail::Generator::MERCURYDevice::RespondXR0()
  726. {
  727. mLog::FINFO("Respond: XR0");
  728. HWSend("XR0", 3);
  729. }
  730. void CCOS::Dev::Detail::Generator::MERCURYDevice::RespondXR1()
  731. {
  732. mLog::FINFO("Respond: XR1");
  733. HWSend("XR1", 3);
  734. }
  735. void nsGEN::MERCURYDevice::InitCallBack()
  736. {
  737. //无 操作
  738. auto HWNotProcess = [](const char* value, int length) -> void
  739. {
  740. mLog::FINFO("This commands[{$}] didn't need to process", value);
  741. };
  742. auto HWKV = [this](const char* value, int length) -> void
  743. {
  744. assert(value);
  745. int kv = atoi(value);
  746. if (m_DoseUnit.m_KV->Update(kv))
  747. FireNotify(AttrKey::KV, m_DoseUnit.m_KV->JSGet());
  748. };
  749. auto HWMAS = [this](const char* value, int length)
  750. {
  751. assert(value);
  752. float fmas = atof(value) / 100.0;
  753. if (m_DoseUnit.m_MAS->Update(fmas))
  754. FireNotify(AttrKey::MAS, m_DoseUnit.m_MAS->JSGet());
  755. };
  756. auto HWMA = [this](const char* value, int length)
  757. {
  758. assert(value);
  759. float fma = atof(value) / 10.0;
  760. if (m_DoseUnit.m_MA->Update(fma))
  761. FireNotify(AttrKey::MA, m_DoseUnit.m_MA->JSGet());
  762. };
  763. auto HWMS = [this](const char* value, int length)
  764. {
  765. assert(value);
  766. float fms = atof(value) / 10.0;
  767. if (m_DoseUnit.m_MS->Update(fms))
  768. FireNotify(AttrKey::MS, m_DoseUnit.m_MS->JSGet());
  769. };
  770. //after kv
  771. auto HWVP = [this](const char* value, int length)
  772. {
  773. assert(value);
  774. m_DoseUnit.m_PostKV->Update(atof(value));
  775. FireNotify(AttrKey::POSTKV, m_DoseUnit.m_PostKV->JSGet());
  776. mLog::FINFO("Actual exposure parameters KV:{$}", m_DoseUnit.m_PostKV->JSGet().c_str());
  777. };
  778. auto HWPA = [this](const char* value, int length)
  779. {
  780. assert(value);
  781. float fma = atof(value) / 10.0;
  782. m_DoseUnit.m_PostMA->Update(fma);
  783. FireNotify(AttrKey::POSTMA, m_DoseUnit.m_PostMA->JSGet());
  784. mLog::FINFO("Actual exposure parameters MA:{$}", m_DoseUnit.m_PostMA->JSGet().c_str());
  785. };
  786. //after mas
  787. auto HWAP = [this](const char* value, int length)
  788. {
  789. assert(value);
  790. float fmas = atof(value) / 10.0;
  791. m_DoseUnit.m_PostMAS->Update(fmas);
  792. FireNotify(AttrKey::POSTMAS, m_DoseUnit.m_PostMAS->JSGet());
  793. mLog::FINFO("Actual exposure parameters MAS:{$}", m_DoseUnit.m_PostMAS->JSGet().c_str());
  794. };
  795. //FOCUS
  796. auto HWFocus = [this](const char* value, int length)
  797. {
  798. assert(value);
  799. int nfous = atoi(value);
  800. if (m_DoseUnit.m_Focus->Update(nfous))
  801. FireNotify(AttrKey::FOCUS, m_DoseUnit.m_Focus->JSGet());
  802. mLog::FINFO("Current focus:{$}, FO={$}", atoi(m_DoseUnit.m_Focus->JSGet().c_str()) ? "large focus" : "small focus", m_DoseUnit.m_Focus->JSGet().c_str());
  803. };
  804. //TECHMODE
  805. auto HWTechmode = [this](const char* value, int length)
  806. {
  807. assert(value);
  808. int ntechmode = atoi(value);
  809. if (m_DoseUnit.m_Techmode->Update(ntechmode))
  810. FireNotify(AttrKey::TECHMODE, m_DoseUnit.m_Techmode->JSGet());
  811. switch (ntechmode)
  812. {
  813. case 0:
  814. mLog::FINFO("ET={$}", "mA/ms",m_DoseUnit.m_Techmode->JSGet().c_str());
  815. break;
  816. case 1:
  817. mLog::FINFO("ET={$}", "mAs", m_DoseUnit.m_Techmode->JSGet().c_str());
  818. break;
  819. case 2:
  820. mLog::FINFO("ET={$}", "AEC / mA", m_DoseUnit.m_Techmode->JSGet().c_str());
  821. break;
  822. case 3:
  823. mLog::FINFO("ET={$}", "mAs / ms", m_DoseUnit.m_Techmode->JSGet().c_str());
  824. break;
  825. case 4:
  826. mLog::FINFO("ET={$}", "AEC", m_DoseUnit.m_Techmode->JSGet().c_str());
  827. break;
  828. }
  829. };
  830. //WROKSTATION
  831. auto HWWS = [this](const char* value, int length)
  832. {
  833. assert(value);
  834. int nValue = atoi(value);
  835. if (m_DoseUnit.m_WS->Update(nValue))
  836. FireNotify(m_DoseUnit.m_WS->GetKey(), m_DoseUnit.m_WS->JSGet());
  837. };
  838. //PR
  839. auto HWPR = [this](const char* value, int length)
  840. {
  841. assert(value);
  842. int nValue = atoi(value);
  843. if (nValue == 2)
  844. {
  845. RespondPR2();
  846. //m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_READY);
  847. }
  848. else if (nValue == 1)
  849. {
  850. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_PREPARE);
  851. RespondPR1();
  852. }
  853. else if (nValue == 0)
  854. {
  855. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF);
  856. RespondPR0();
  857. m_bGenBusy = false;
  858. }
  859. mLog::FINFO("m_DoseUnit.m_GenSynState: {$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
  860. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  861. };
  862. //XR
  863. auto HWXR = [this](const char* value, int length)
  864. {
  865. assert(value);
  866. int nValue = atoi(value);
  867. if (nValue == 2)
  868. {
  869. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON);
  870. }
  871. else if (nValue == 1)
  872. {
  873. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_READY);
  874. RespondXR1();
  875. }
  876. else if (nValue == 0)
  877. {
  878. m_bGenBusy = false;
  879. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYOFF);
  880. RespondXR0();
  881. }
  882. mLog::FINFO("m_DoseUnit.m_GenSynState: {$}", m_DoseUnit.m_GenSynState->JSGet().c_str());
  883. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  884. };
  885. auto HWAPDOSE = [this](const char* value, int length)//post mas
  886. {
  887. assert(value);
  888. m_DoseUnit.m_PostMAS->Update(atof(value) / 100.0);
  889. FireNotify(m_DoseUnit.m_PostMAS->GetKey(), m_DoseUnit.m_PostMAS->JSGet());
  890. mLog::FINFO("Actual exposure parameters MAS: {$}", m_DoseUnit.m_PostMAS->JSGet().c_str());
  891. };
  892. auto HWATDOSE = [this](const char* value, int length)
  893. {
  894. assert(value);
  895. m_DoseUnit.m_PostMS->Update(atof(value) / 100.0);
  896. FireNotify(m_DoseUnit.m_PostMS->GetKey(), m_DoseUnit.m_PostMS->JSGet());
  897. mLog::FINFO("Actual exposure parameters MS: {$}", m_DoseUnit.m_PostMS->JSGet().c_str());
  898. };
  899. auto HWDAP = [this](const char* value, int length)
  900. {
  901. assert(value);
  902. mLog::FINFO("Recv DAP ={$}", atof(value) / 100.0);
  903. };
  904. auto HWEHE = [this](const char* value, int length)
  905. {
  906. m_iHeartBeats = 0;
  907. assert(value);
  908. int nhe = atoi(value);
  909. if (m_DoseUnit.m_HE->Update(nhe))
  910. FireNotify(m_DoseUnit.m_HE->GetKey(), m_DoseUnit.m_HE->JSGet());
  911. };
  912. auto HWHH = [this](const char* value, int length)
  913. {
  914. m_iHeartBeats = 0;
  915. assert(value);
  916. int nhe = atoi(value);
  917. if (m_DoseUnit.m_GenHE->Update(nhe))
  918. FireNotify(m_DoseUnit.m_GenHE->GetKey(), m_DoseUnit.m_GenHE->JSGet());
  919. };
  920. auto HWDS = [this](const char* value, int length)
  921. {
  922. assert(value);
  923. m_bDAPEnable = (bool)atoi(value);
  924. };
  925. auto HWFLD = [this](const char* value, int length)
  926. {
  927. assert(value);
  928. };
  929. auto HWER = [this](const char* value, int length)
  930. {
  931. assert(value);
  932. int nValue = atoi(value);
  933. char tmpbuf[4] = { 0,0,0,0 };
  934. tmpbuf[0] = value[0];
  935. tmpbuf[1] = value[1];
  936. tmpbuf[2] = value[2];
  937. if (nValue != 0)
  938. {
  939. std::unordered_map<std::string, std::string> errorMessages = {
  940. {"100", "AEC Back-up Timer - Exposure Terminated"},
  941. {"101", "AEC mAs Exceeded - Exposure Terminated"},
  942. {"102", "Door Interlock Error"},
  943. {"103", "Calibration Data Corrupt Error"},
  944. {"104", "AEC Data Corrupt Error"},
  945. {"105", "Receptor Data Corrupt Error"},
  946. {"106", "Tube Data Corrupt Error"},
  947. {"107", "Generator Limit Data Corrupt Error"},
  948. {"108", "mA Correction Data Corrupt Error"},
  949. {"109", "Not Enabled Error"},
  950. {"110", "AEC Feedback Error - No Feedback Signal Detected"},
  951. {"111", "EXP_SW Signal Active in Standby State"},
  952. {"112", "Calibration Error - No mA"},
  953. {"113", "Calibration Error - Maximum Filament Current Exceeded"},
  954. {"114", "MA During Exposure too High"},
  955. {"115", "MA During Exposure too Low"},
  956. {"116", "Generator KW Limit"},
  957. {"117", "Generator KV Limit"},
  958. {"118", "Generator MA Limit"},
  959. {"119", "Generator MS Limit"},
  960. {"120", "Generator MAS Limit"},
  961. {"121", "Tube KW Limit"},
  962. {"122", "Tube KV Limit"},
  963. {"123", "Tube MA Limit"},
  964. {"124", "Tube MAS Limit"},
  965. {"125", "Parameter Limit"},
  966. {"126", "Manually Terminated Exposure"},
  967. {"127", "Preparation Time-out Error prep time is over 30s or 60s"},
  968. {"128", "Prep Input Active During Initialization Phase"},
  969. {"129", "X-ray Input Active During Initialization Phase"},
  970. {"130", "No Fields Selected in AEC mode"},
  971. {"131", "Generator AEC Density Limit"},
  972. {"132", "Calibration Error - Manually Terminated"},
  973. {"133", "EEPROM Communication Error"},
  974. {"134", "RTC Communication Error"},
  975. {"135", "AEC Channel Error"},
  976. {"136", "Anode Communication Error"},
  977. {"137", "EXP_OK TimeOut"},
  978. {"138", "KV TimeOut"},
  979. {"139", "Mosfet Temperature Limit Exceeded"},
  980. {"140", "HU Power Limit"},
  981. {"141", "HU Power Warning"},
  982. {"142", "Small Focus Disable"},
  983. {"143", "Large Focus Disable"},
  984. {"144", "Low Speed Disable"},
  985. {"145", "High Speed Disable"},
  986. {"146", "Anode Heat Warning Exceeded"},
  987. {"147", "Anode Heat Limit Exceeded"},
  988. {"148", "KV Unbalance"},
  989. {"149", "Thermal Switch Interlock Error"},
  990. {"150", "Emergency Error"},
  991. {"151", "KV Correction Data Corrupt Error"},
  992. {"152", "Generator Tank Power Limit"},
  993. {"153", "AEC Standby Signal Error"},
  994. {"154", "DCBUS Calibration Data Corrupt Error"},
  995. {"155", "Fluoro Timer Terminated "},
  996. {"156", "Fluoro Timer Terminated "},
  997. {"157", "Power Off In X - Ray State"},
  998. {"158", "DAP Data Corrupt "},
  999. {"159", "Auto APR TimeOut "},
  1000. {"160", "ERR_FLUORO_ABSFDBNONE"},
  1001. {"200", "FLASH LOCK"},
  1002. {"201", "FLASH REVID_INVALID"},
  1003. {"202", "FLASH ADDR_INVALID"},
  1004. {"203", "FLASH INCORRECT_PARTID"},
  1005. {"204", "FLASH API_SILICON_MISMATCH"},
  1006. {"205", "FLASH ERASE ERROR"},
  1007. {"206", "FLASH FAIL_PROGRAM"},
  1008. {"207", "FLASH FAIL_ZERO_BIT_ERROR"},
  1009. {"208", "FLASH FAIL_VERIFY"},
  1010. {"209", "FLASH BUSY"},
  1011. {"210", "FLASH_PROGRM_ADDR_ERROR"},
  1012. {"211", "UPDATA_VERSION_ERROR"},
  1013. {"212", "UPDATA SN_ERROR"},
  1014. {"213", "UPDATA_BYTE_COUNT_ERROR"},
  1015. {"214", "UPDATA_CHECKSUM_ERROR"}
  1016. };
  1017. char ErrorCode[20];
  1018. sprintf_s(ErrorCode, "PSGHR_ER_%d", nValue);
  1019. char temp[50] = { 0 };
  1020. sprintf_s(temp, "ER%03d", nValue);
  1021. HWSend(temp, strlen(temp));
  1022. int level = 1;
  1023. auto it = errorMessages.find(tmpbuf);
  1024. if (it != errorMessages.end())
  1025. {
  1026. //m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR);
  1027. //FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1028. m_MSGUnit->AddWarnMessage(ErrorCode, level, it->second.c_str());
  1029. }
  1030. }
  1031. else
  1032. {
  1033. int level = 1;
  1034. char ErrorCode[20];
  1035. m_MSGUnit->DelWarnMessage(ErrorCode, level, "");
  1036. }
  1037. };
  1038. auto HWEL = [this](const char* value, int length)
  1039. {
  1040. assert(value);
  1041. int nValue = atoi(value);
  1042. char tmpbuf[3] = { 0,0,0 };
  1043. tmpbuf[0] = value[0];
  1044. tmpbuf[1] = value[1];
  1045. tmpbuf[2] = value[2];
  1046. if (nValue != 0)
  1047. {
  1048. std::unordered_map<std::string, std::string> errorMessages = {
  1049. {"001", "Generator CPU Real Time Clock Error"},
  1050. {"002", "Main Contactor Error"},
  1051. {"003", "Rotor Fault"},
  1052. {"004", "DC Bus Voltage too Low"},
  1053. {"005", "DC Bus Voltage too High"},
  1054. {"006", "Filament Adjust Error"},
  1055. {"007", "Filament PowerBoard Not Connected"},
  1056. {"008", "Filament Short Circuit"},
  1057. {"019", "Filament Overcurrent"},
  1058. {"010", "Anode Overcurrent"},
  1059. {"011", "Cathode Overcurrent"},
  1060. {"012", "Anode Overvoltage"},
  1061. {"013", "Cathode Overvoltage"},
  1062. {"014", "ARC"},
  1063. {"015", "Short Current 1"},
  1064. {"016", "Short Current 2"},
  1065. {"017", "Short Current A"},
  1066. {"018", "Short Current B"}
  1067. };
  1068. char ErrorCode[20];
  1069. sprintf_s(ErrorCode, "PSGHR_EL_%d", nValue);
  1070. char temp[50] = { 0 };
  1071. sprintf_s(temp, "EL%03d", nValue);
  1072. HWSend(temp, strlen(temp));
  1073. int level = 1;
  1074. auto it = errorMessages.find(tmpbuf);
  1075. if (it != errorMessages.end())
  1076. {
  1077. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR);
  1078. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1079. m_MSGUnit->AddErrorMessage(ErrorCode, level, it->second.c_str());
  1080. }
  1081. }
  1082. else
  1083. {
  1084. int level = 1;
  1085. char ErrorCode[20];
  1086. m_MSGUnit->DelErrorMessage(ErrorCode, level, "");
  1087. }
  1088. };
  1089. auto HWEI = [this](const char* value, int length)
  1090. {
  1091. assert(value);
  1092. int nValue = atoi(value);
  1093. char tmpbuf[3] = { 0,0,0 };
  1094. tmpbuf[0] = value[0];
  1095. tmpbuf[1] = value[1];
  1096. tmpbuf[2] = value[2];
  1097. if (nValue != 0)
  1098. {
  1099. std::unordered_map<std::string, std::string> errorMessages = {
  1100. {"400", "Enter the service mode"},
  1101. {"401", "Exit the service mode"},
  1102. {"402", "Resonance Overcurrent1"},
  1103. {"403", "Resonance Overcurrent2"},
  1104. {"404", "Resonance Overcurrent3"},
  1105. {"405", "Charging, Please Wait "},
  1106. {"406", "DAC Reset "},
  1107. {"407", "X-Rays State PowerOff "},
  1108. {"408", "Fluoro Disable "},
  1109. {"409", "Fluoro Timer Warning Level Exceeded"},
  1110. {"410", "Anode Heat Warning Exceeded "},
  1111. {"411", "MA Too Low "}
  1112. };
  1113. char ErrorCode[20];
  1114. sprintf_s(ErrorCode, "PSGHR_EI_%d", nValue);
  1115. char temp[50] = { 0 };
  1116. sprintf_s(temp, "EI%03d", nValue);
  1117. HWSend(temp, strlen(temp));
  1118. int level = 1;
  1119. auto it = errorMessages.find(tmpbuf);
  1120. if (it != errorMessages.end())
  1121. {
  1122. //m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR);
  1123. //FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1124. m_MSGUnit->AddWarnMessage(ErrorCode, level, it->second.c_str());
  1125. }
  1126. }
  1127. else
  1128. {
  1129. int level = 1;
  1130. char ErrorCode[20];
  1131. m_MSGUnit->DelWarnMessage(ErrorCode, level, "");
  1132. }
  1133. };
  1134. auto HWMSG = [this](const char* value, int length)
  1135. {
  1136. assert(value);
  1137. int nValue = atoi(value);
  1138. char tmpbuf[3] = { 0,0,0 };
  1139. tmpbuf[0] = value[0];
  1140. tmpbuf[1] = value[1];
  1141. tmpbuf[2] = value[2];
  1142. if (nValue != 0)
  1143. {
  1144. std::unordered_map<std::string, std::string> errorMessages = {
  1145. {"001", "Rotating anode protection parameters are incorrectly configured"},
  1146. {"002", "Press emergency stop of high voltage generator"},
  1147. {"003", "The first level hand brake is not triggered, and the second level hand brake is triggered"},
  1148. {"004", "The first level hand brake is pressed during the wake - up or startup process of the high - voltage generator."},
  1149. {"005", "The second level hand brake is pressed during the wake - up or startup process of the high - voltage generator."},
  1150. {"006", "Low battery power of the high - voltage generator, please recharge."},
  1151. {"007", "Anode thermal capacity exceeds the warning value."},
  1152. {"008", "Exposure time interval is too short, please wait for exposure."},
  1153. {"009", "Parameter adjustment is prohibited during exposure."},
  1154. {"010", "High - voltage generator is not ready, please confirm the status."},
  1155. {"011", "The oil tank temperature of the high - voltage generator exceeds the warning value."},
  1156. {"012", "Training cannot be conducted in this state."},
  1157. {"013", "The tube current of the high voltage generator is low."},
  1158. {"014", "The PFC module of the high voltage generator works abnormally."},
  1159. {"015", "Battery output power limits for high voltage generators."},
  1160. {"016", "The battery of the high voltage generator is charging."},
  1161. {"017", "The mA parameter of the high voltage generator exceeds the maximum tube value."},
  1162. {"018", "The kV parameter of the high voltage generator exceeds the limit value."},
  1163. {"019", "The mA parameter of the high voltage generator exceeds the limit value."},
  1164. {"020", "The ms parameter of the high voltage generator exceeds the limit value."},
  1165. {"021", "The mAs parameter of the high voltage generator exceeds the limit value."},
  1166. {"022", "Filament selection parameter exceeds the limit."},
  1167. {"023", "Anode rotation speed selection parameter exceeds the limit."},
  1168. {"024", "The exposure technical parameters of the high voltage generator exceed the limits."},
  1169. {"025", "AEC density parameter exceeds the limit."},
  1170. {"026", "AEC field selection parameter exceeds the limit."},
  1171. {"027", "AEC channel parameter exceeds the limit."},
  1172. {"028", "AEC sensitivity parameter exceeds the limit."},
  1173. {"029", "High - voltage generator power exceeds the limit."},
  1174. {"030", "Tube power exceeds the limit."},
  1175. {"031", "The frame rate parameter of the high voltage generator exceeds the limit value."},
  1176. {"032", "Exposure parameter exceeds the high - voltage generator energy storage limit."},
  1177. {"033", "High voltage generator battery pack alarm."},
  1178. {"035", "Foot brake signal is pressed during the wake - up or startup process of the high - voltage generator."},
  1179. {"036", "Cumulative fluoroscopy time alarm."},
  1180. {"037", "The console of the high voltage generator is not connected, please open the console."},
  1181. {"038", "Tube sleeve thermal capacity exceeds the warning value."},
  1182. {"049", "Bus voltage of the high - voltage generator exceeds the limit."},
  1183. {"050", "High - voltage generator does not support this exposure mode."},
  1184. {"051", "The rotation speed of the rotating anode does not meet the exposure requirements."},
  1185. {"052", "The second level hand brake is not pressed within the specified time."},
  1186. {"053", "Interlock 1 is effective during the exposure process of the high - voltage generator."},
  1187. {"054", "Timeout for feedback signal in flat panel mode."},
  1188. {"055", "The kV establishment timeout of the high voltage generator."},
  1189. {"056", "Anode thermal capacity exceeds the limit."},
  1190. {"057", "Filament calibration data abnormality."},
  1191. {"058", "Tube current is too low during training."},
  1192. {"059", "Release hand brake prematurely during exposure."},
  1193. {"060", "AEC feedback abnormality."},
  1194. {"061", "Inverter temperature of the high - voltage generator exceeds the limit."},
  1195. {"062", "kV is too low during exposure, exposure abnormality aborted."},
  1196. {"063", "kV is too high during exposure, exposure abnormality aborted."},
  1197. {"064", "Oil temperature of the high - voltage generator exceeds the limit."},
  1198. {"065", "Tube sleeve thermal capacity exceeds the limit."},
  1199. {"066", "The current exposure parameters of the high voltage generator exceed the heat capacity limit."},
  1200. {"068", "mA is too high during exposure, exposure abnormality aborted."},
  1201. {"069", "The DRVEN enable of the high voltage generator to establish a timeout."},
  1202. {"070", "Interruption in communication with the rotating anode."},
  1203. {"071", "Emergency stop is pressed during exposure."},
  1204. {"072", "The battery pack of the high voltage generator is faulty."},
  1205. {"073", "Resonant current exceeds the limit, exposure abnormality aborted(software)."},
  1206. {"074", "Anode kV exceeds the limit, exposure abnormality aborted(software)."},
  1207. {"075", "Cathode kV exceeds the limit, exposure abnormality aborted(software)."},
  1208. {"076", "Filament current exceeds the limit(software)."},
  1209. {"078", "Oil tank power limit of the high - voltage generator."},
  1210. {"080", "Deviation of anode kV and cathode kV exceeds the limit, exposure abnormality aborted."},
  1211. {"081", "Power exceeds the limit during exposure, exposure abnormality aborted."},
  1212. {"082", "The external synchronization signal of the high voltage generator has timed out."},
  1213. {"083", "Fan fault in high voltage generator."},
  1214. {"084", "High voltage generator InterLock1 effective."},
  1215. {"085", "High voltage generator InterLock2 effective."},
  1216. {"087", "Release foot brake prematurely during exposure."},
  1217. {"088", "Foot brake signal abnormality."},
  1218. {"089", "The DA chip of the high voltage generator is abnormal."},
  1219. {"090", "Timeout for cumulative fluoroscopy time."},
  1220. {"091", "The external discharge line of the high voltage generator enables the signal to timeout."},
  1221. {"092", "XRAYReady invalid."},
  1222. {"093", "High voltage generator during exposure interlock 2 effective."}
  1223. };
  1224. char ErrorCode[20];
  1225. sprintf_s(ErrorCode, "PSGHR_MSG_%d", nValue);
  1226. int level = 1;
  1227. /*char temp[50] = { 0 };
  1228. sprintf_s(temp, "MSG%03d", nValue);
  1229. HWSend(temp, strlen(temp));*/
  1230. auto it = errorMessages.find(tmpbuf);
  1231. if (it != errorMessages.end())
  1232. {
  1233. mLog::FINFO("WarnCode: {$}, Level: {$}, ResInfo: {$}\n", ErrorCode, level, it->second.c_str());
  1234. m_MSGUnit->AddWarnMessage(ErrorCode, level, it->second.c_str());
  1235. }
  1236. }
  1237. else
  1238. {
  1239. int level = 1;
  1240. char WarnCode[20]{ "" };
  1241. m_MSGUnit->DelWarnMessage(WarnCode, level, "");
  1242. }
  1243. };
  1244. auto HWST = [this](const char* value, int length)
  1245. {
  1246. assert(value);
  1247. int genStatus = atoi(value);
  1248. mLog::FINFO("genStatus={$}", genStatus);
  1249. switch (genStatus)
  1250. {
  1251. case MERCURY_PHASE_INI:
  1252. //初始化
  1253. mLog::FDEBUG("get Gen Status_1:GENSTATE {$} -> STATUS_INIT", m_DoseUnit.m_GenState->JSGet());
  1254. if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_INIT))
  1255. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1256. break;
  1257. case MERCURY_PHASE_STANDBY:
  1258. mLog::FDEBUG("get Gen Status_2:GENSTATE {$} -> STATUS_STANDBY", m_DoseUnit.m_GenState->JSGet());
  1259. if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY))
  1260. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1261. break;
  1262. default:
  1263. mLog::FDEBUG("get Gen Status:[{$}] unknown", genStatus);
  1264. break;
  1265. }
  1266. };
  1267. arFrame.clear();
  1268. arFrame.push_back(tFrameMapping("EL", 2, HWEL));
  1269. arFrame.push_back(tFrameMapping("EI", 2, HWEI));
  1270. arFrame.push_back(tFrameMapping("ER", 2, HWER));
  1271. arFrame.push_back(tFrameMapping("MSG", 3, HWMSG));
  1272. //arFrame.push_back(tFrameMapping("TU", 2, HWTU));
  1273. arFrame.push_back(tFrameMapping("EC", 2, HWNotProcess));
  1274. arFrame.push_back(tFrameMapping("PW", 2, HWNotProcess));
  1275. arFrame.push_back(tFrameMapping("KV", 2, HWKV));
  1276. arFrame.push_back(tFrameMapping("MX", 2, HWMAS));
  1277. arFrame.push_back(tFrameMapping("MA", 2, HWMA));
  1278. arFrame.push_back(tFrameMapping("MS", 2, HWMS));
  1279. arFrame.push_back(tFrameMapping("VP", 2, HWVP));
  1280. arFrame.push_back(tFrameMapping("PA", 2, HWPA));
  1281. arFrame.push_back(tFrameMapping("AP", 2, HWAPDOSE));
  1282. arFrame.push_back(tFrameMapping("ET", 2, HWTechmode));
  1283. arFrame.push_back(tFrameMapping("FO", 2, HWFocus));
  1284. arFrame.push_back(tFrameMapping("WS", 2, HWWS));
  1285. arFrame.push_back(tFrameMapping("PR", 2, HWPR));
  1286. arFrame.push_back(tFrameMapping("XR", 2, HWXR));
  1287. arFrame.push_back(tFrameMapping("AT", 2, HWATDOSE));
  1288. arFrame.push_back(tFrameMapping("HE", 2, HWEHE));
  1289. arFrame.push_back(tFrameMapping("HH", 2, HWHH));
  1290. arFrame.push_back(tFrameMapping("DA", 2, HWDAP));
  1291. arFrame.push_back(tFrameMapping("DV", 2, HWDAP));
  1292. arFrame.push_back(tFrameMapping("DS", 2, HWDS));
  1293. arFrame.push_back(tFrameMapping("ST", 2, HWST));
  1294. arFrame.push_back(tFrameMapping("PR", 2, HWPR));
  1295. }
  1296. bool nsGEN::MERCURYDevice::ReConnect()
  1297. {
  1298. mLog::FINFO("Enter PSG_reConnect");
  1299. m_SCF.Disconnect();
  1300. if (!pIODriver)
  1301. {
  1302. mLog::FINFO("PSG_reConnect:Driver null");
  1303. }
  1304. else if (pIODriver->ReConnection(m_SCF))
  1305. {
  1306. FireErrorMessage(false, 1, "lost Connect");
  1307. m_bConnectFlag = true;
  1308. mLog::FINFO("PSG_reConnect success");
  1309. return true;
  1310. }
  1311. else
  1312. {
  1313. mLog::FINFO("PSG_reConnect failed");
  1314. }
  1315. return false;
  1316. }
  1317. bool nsGEN::MERCURYDevice::EnableBucky(int nbucky)
  1318. {
  1319. char temp[50]{ 0 };
  1320. sprintf_s(temp, "BU%1d", nbucky);
  1321. return HWSend(temp, strlen(temp));
  1322. }
  1323. bool nsGEN::MERCURYDevice::ECHO(void)
  1324. {
  1325. mLog::FINFO("Echo");
  1326. return HWSend("EC9", 3);
  1327. }
  1328. bool nsGEN::MERCURYDevice::StartHardwareStatusThread()
  1329. {
  1330. mLog::FINFO("enter Start HardwareStatus Thread ");
  1331. if (m_pHardwareStatusThread == NULL)
  1332. {
  1333. DWORD m_HardwareStatusID;
  1334. m_pHardwareStatusThread = CreateThread(0, 0, HardwareStatusThread, this, 0, &m_HardwareStatusID);
  1335. if (m_pHardwareStatusThread == NULL)
  1336. {
  1337. mLog::FERROR("Start HardwareStatus Thread Failed");
  1338. return false;
  1339. }
  1340. }
  1341. return true;
  1342. }
  1343. DWORD nsGEN::MERCURYDevice::HardwareStatusThread(LPVOID pParam)
  1344. {
  1345. MERCURYDevice* pCurGen = (MERCURYDevice*)pParam;
  1346. if (pCurGen == NULL)
  1347. {
  1348. return false;
  1349. };
  1350. HeartBeatFlag = true;
  1351. int value = 1;
  1352. if ((int)pCurGen->m_GenConfig["loopTime"] >= 100)
  1353. {
  1354. pCurGen->m_iLoopTime = (int)pCurGen->m_GenConfig["loopTime"];
  1355. }
  1356. mLog::FINFO("loopTime = {$}", pCurGen->m_iLoopTime.load());
  1357. int currtTime = pCurGen->m_iLoopTime;
  1358. while (m_bExtraFlag)
  1359. {
  1360. currtTime = pCurGen->m_iLoopTime;
  1361. Sleep(currtTime);
  1362. pCurGen->GetST();
  1363. }
  1364. return true;
  1365. }
  1366. //-----------------------------------------------------------------------------
  1367. // MERCURYDriver
  1368. //-----------------------------------------------------------------------------
  1369. nsGEN::MERCURYDriver::MERCURYDriver()
  1370. {
  1371. m_pAttribute.reset(new ResDataObject());
  1372. m_pDescription.reset(new ResDataObject());
  1373. }
  1374. nsGEN::MERCURYDriver::~MERCURYDriver()
  1375. {
  1376. mLog::Close();
  1377. mLog::gLogger = nullptr;
  1378. }
  1379. void nsGEN::MERCURYDriver::Prepare()
  1380. {
  1381. string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Generator\Conf\Log4CPP.Config.GEN.xml)";
  1382. Log4CPP::GlobalContext::Map::Set(ECOM::Utility::Hash("LogFileName"), "GEN.MERCURY");
  1383. auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
  1384. mLog::gLogger = Log4CPP::LogManager::GetLogger("GEN.MERCURY");
  1385. m_SCFDllName = GetConnectDLL(m_ConfigFileName);
  1386. super::Prepare();
  1387. }
  1388. std::string nsGEN::MERCURYDriver::DriverProbe()
  1389. {
  1390. mLog::FINFO("DriverProbe in");
  1391. ResDataObject r_config, HardwareInfo;
  1392. if (r_config.loadFile(m_ConfigFileName.c_str()))
  1393. {
  1394. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  1395. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  1396. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  1397. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  1398. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  1399. }
  1400. else
  1401. {
  1402. HardwareInfo.add("MajorID", "Generator");
  1403. HardwareInfo.add("MinorID", "Dr");
  1404. HardwareInfo.add("VendorID", "MERCURY");
  1405. HardwareInfo.add("ProductID", "HF");
  1406. HardwareInfo.add("SerialID", "Drv");
  1407. }
  1408. string ret = HardwareInfo.encode();
  1409. return ret;
  1410. }
  1411. bool nsGEN::MERCURYDriver::ReConnection(nsSCF::SCF& DevSCF)
  1412. {
  1413. super::Disconnect();
  1414. mLog::FINFO("ReConnection:SCF Disconnect");
  1415. ResDataObject Connection = GetConnectParam(m_ConfigFileName);
  1416. mLog::FINFO("ReConnection: {$}", Connection.encode());
  1417. auto erCode = m_SCF.Connect(Connection.encode(), &nsGEN::MERCURYDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
  1418. if (erCode == SCF_ERR::SCF_SUCCEED)
  1419. {
  1420. Sleep(1000);
  1421. auto rc = super::Connect();
  1422. if (!rc)
  1423. {
  1424. mLog::FINFO("ReConnection:super Connect failed");
  1425. }
  1426. else
  1427. {
  1428. DevSCF = m_SCF;
  1429. return true;
  1430. }
  1431. }
  1432. else
  1433. {
  1434. mLog::FINFO("ReConnection failed");
  1435. }
  1436. return false;
  1437. }
  1438. bool nsGEN::MERCURYDriver::Connect()
  1439. {
  1440. ResDataObject Connection = GetConnectParam(m_ConfigFileName);
  1441. mLog::FINFO("connections: {$}", Connection.encode());
  1442. auto erCode = m_SCF.Connect(Connection.encode(), &nsGEN::MERCURYDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
  1443. if (erCode != SCF_ERR::SCF_SUCCEED)
  1444. return false;
  1445. auto rc = super::Connect();
  1446. if (!rc)
  1447. return false;
  1448. return true;
  1449. }
  1450. auto nsGEN::MERCURYDriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
  1451. {
  1452. mLog::FINFO("CreateDevice in");
  1453. if (!m_SCF.isConnected())
  1454. {
  1455. mLog::FERROR("CreateDevice:m_SCF is not Connected \n");
  1456. return nullptr;
  1457. }
  1458. auto dev = std::unique_ptr <IODevice>(new IODevice(new MERCURYDevice(EventCenter, m_SCF, m_ConfigFileName)));
  1459. mLog::FINFO("CreateDevice out");
  1460. return dev;
  1461. }
  1462. void nsGEN::MERCURYDriver::FireNotify(int code, std::string key, std::string content)
  1463. {
  1464. EventCenter->OnNotify(code, key, content);
  1465. }
  1466. bool nsGEN::MERCURYDriver::isConnected() const
  1467. {
  1468. if (super::isConnected())
  1469. {
  1470. return true;
  1471. }
  1472. else
  1473. {
  1474. if(HeartBeatFlag)
  1475. return true;
  1476. else
  1477. return false;
  1478. }
  1479. }
  1480. std::string nsGEN::MERCURYDriver::GetResource()
  1481. {
  1482. mLog::FDEBUG("GetResource");
  1483. ResDataObject r_config, temp;
  1484. if (!temp.loadFile(m_ConfigFileName.c_str()))
  1485. {
  1486. return "";
  1487. }
  1488. m_ConfigAll = temp;
  1489. r_config = temp["CONFIGURATION"];
  1490. m_Configurations = r_config;
  1491. ResDataObject DescriptionTemp;
  1492. ResDataObject DescriptionSend;
  1493. ResDataObject m_DescriptionSend;
  1494. ResDataObject ListTemp;
  1495. string strTemp = ""; //用于读取字符串配置信息
  1496. string strIndex = ""; //用于读取配置信息中的List项
  1497. int nTemp = -1; //用于读取整型配置信息
  1498. char sstream[10] = { 0 }; //用于转换值
  1499. string strValue = ""; //用于存储配置的值
  1500. string strType = ""; //用于存储配置的类型 int/float/string...
  1501. /***
  1502. * 1. 通过循环,将所有配置项写到pDeviceConfig
  1503. * 2. 记录配置项的内部key以及配置类型,类型对应了不同配置文件路径,用于读写真实值
  1504. ***/
  1505. try
  1506. {
  1507. //便利ConfigToolInfo 中 所有的AttributeInfo 属性段
  1508. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  1509. m_pAttribute->clear();
  1510. m_pDescription->clear();
  1511. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  1512. {
  1513. DescriptionTemp.clear();
  1514. DescriptionSend.clear();
  1515. ListTemp.clear();
  1516. //AttributeType
  1517. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Type"];
  1518. DescriptionTemp.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
  1519. DescriptionSend.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
  1520. strType = strTemp; //记录配置项的类型
  1521. //AttributeKey
  1522. //1. 根据AttributeType,内部key和配置路径,拿到当前的真实值
  1523. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  1524. nTemp = (int)m_Configurations["ConfigToolInfo"][nInfoIndex]["PathID"];
  1525. GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue); //得到strValue的值
  1526. //printf("********************************innerkey=%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
  1527. //2. 赋值
  1528. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  1529. if ("int" == strType)
  1530. {
  1531. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  1532. }
  1533. else if ("float" == strType)
  1534. {
  1535. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  1536. }
  1537. else //其它先按string类型处理
  1538. {
  1539. (*m_pAttribute).add(strTemp.c_str(), strValue.c_str());
  1540. }
  1541. //printf("********************************outkey =%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
  1542. //AttributeAccess
  1543. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Access"];
  1544. DescriptionTemp.add(ConfKey::CcosAccess, strTemp.c_str());
  1545. DescriptionSend.add(ConfKey::CcosAccess, strTemp.c_str());
  1546. /*
  1547. //AttributeRangeMin
  1548. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMin"];
  1549. if (strTemp != "") //不需要的配置项为空
  1550. {
  1551. DescriptionTemp.add(ConfKey::CcosRangeMin, strTemp.c_str());
  1552. }
  1553. //AttributeRangeMax
  1554. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMax"];
  1555. if (strTemp != "") //不需要的配置项为空
  1556. {
  1557. DescriptionTemp.add(ConfKey::CcosRangeMax, strTemp.c_str());
  1558. }
  1559. */
  1560. //AttributeList
  1561. nTemp = m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListNum"];
  1562. if (nTemp > 0) //ListNum不大于0时说明不需要list配置
  1563. {
  1564. for (int nListIndex = 0; nListIndex < nTemp; nListIndex++)
  1565. {
  1566. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListInfo"][nListIndex];
  1567. auto temKey = std::to_string(nListIndex);
  1568. ListTemp.add(temKey.c_str(), strTemp.c_str());
  1569. }
  1570. DescriptionTemp.add(ConfKey::CcosList, ListTemp);
  1571. DescriptionSend.add(ConfKey::CcosList, ListTemp.encode());
  1572. }
  1573. //AttributeRequired
  1574. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Required"];
  1575. DescriptionTemp.add(ConfKey::CcosRequired, strTemp.c_str());
  1576. DescriptionSend.add(ConfKey::CcosRequired, strTemp.c_str());
  1577. //AttributeDefaultValue
  1578. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["DefaultValue"];
  1579. if (strTemp != "") //不需要的配置项为空
  1580. {
  1581. DescriptionTemp.add(ConfKey::CcosDefaultValue, strTemp.c_str());
  1582. DescriptionSend.add(ConfKey::CcosDefaultValue, strTemp.c_str());
  1583. }
  1584. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  1585. (*m_pDescription).add(strTemp.c_str(), DescriptionTemp);
  1586. m_DescriptionSend.add(strTemp.c_str(), DescriptionSend.encode());
  1587. }
  1588. }
  1589. catch (ResDataObjectExption& e)
  1590. {
  1591. mLog::FERROR("Get config error: {$}", e.what());
  1592. return "";
  1593. }
  1594. ResDataObject resDeviceResource;
  1595. resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
  1596. resDeviceResource.add(ConfKey::CcosGeneratorDescription, (*m_pDescription));
  1597. ResDataObject DescriptionTempEx;
  1598. DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
  1599. m_DeviceConfig.clear();
  1600. m_DeviceConfig = DescriptionTempEx;
  1601. resDeviceResource.clear();
  1602. resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
  1603. resDeviceResource.add(ConfKey::CcosGeneratorDescription, m_DescriptionSend);
  1604. DescriptionTempEx.clear();
  1605. DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
  1606. m_DeviceConfigSend.clear();
  1607. m_DeviceConfigSend = DescriptionTempEx;
  1608. string res = m_DeviceConfigSend.encode();
  1609. return res;
  1610. }
  1611. std::string nsGEN::MERCURYDriver::DeviceProbe()
  1612. {
  1613. mLog::FINFO("DeviceProbe() in");
  1614. ResDataObject r_config, HardwareInfo;
  1615. if (r_config.loadFile(m_ConfigFileName.c_str()))
  1616. {
  1617. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  1618. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  1619. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  1620. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  1621. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  1622. }
  1623. else
  1624. {
  1625. HardwareInfo.add("MajorID", "Generator");
  1626. HardwareInfo.add("MinorID", "Dr");
  1627. HardwareInfo.add("VendorID", "PSGHR");
  1628. HardwareInfo.add("ProductID", "HF");
  1629. HardwareInfo.add("SerialID", "Dev");
  1630. }
  1631. string ret = HardwareInfo.encode();
  1632. mLog::FINFO("DeviceProbe() out");
  1633. return ret;
  1634. }
  1635. void nsGEN::MERCURYDriver::Disconnect()
  1636. {
  1637. super::Disconnect();
  1638. m_SCF.Disconnect();
  1639. mLog::Close();
  1640. mLog::gLogger = nullptr;
  1641. }
  1642. void nsGEN::MERCURYDriver::Dequeue(const char* Packet, DWORD Length)
  1643. {
  1644. DecodeFrame(Packet, Length);
  1645. }
  1646. PACKET_RET nsGEN::MERCURYDriver::callbackPackageProcess(const char* RecData, DWORD nLength, DWORD& PacketLength)
  1647. {
  1648. if (nLength < 1)
  1649. {
  1650. mLog::FINFO("nLength < 1, nLength=={$} \n", nLength);
  1651. return PACKET_USELESS;
  1652. }
  1653. for (DWORD i = 0; i < nLength - 1; i++)
  1654. {
  1655. //1 首先寻找包头
  1656. //if (RecData[i] == 0x02)
  1657. //{
  1658. // if (i != 0)
  1659. // {
  1660. // PacketLength = i; //i之前的数据,全部扔掉
  1661. // char strtemp[100] = { 0 };
  1662. // memcpy(strtemp, RecData, i);
  1663. // strtemp[PacketLength + 1] = 0;
  1664. // printf("==IN error data ==:%s,PacketLength=%d,nLength=%d\n", strtemp, PacketLength, nLength);
  1665. //
  1666. // return PACKET_USELESS;
  1667. // }
  1668. //}
  1669. if (RecData[i] == 0x03)
  1670. {
  1671. PacketLength = i + 2; //+2 because index + ETX + sum.
  1672. char strtemp[100] = { 0 };
  1673. memcpy(strtemp, RecData, i); //RKC005(not include 03 + sum); //only 复制 0x03之前的数据,这样解析时,后面的03 ,sum 都不要了。
  1674. strtemp[PacketLength + 1] = 0;
  1675. mLog::FINFO("==IN==:{$}\n", strtemp);
  1676. return PACKET_ISPACKET;
  1677. }
  1678. }
  1679. return PACKET_NOPACKET;
  1680. }
  1681. bool nsGEN::MERCURYDriver::GetDeviceConfig(std::string& Cfg)
  1682. {
  1683. Cfg = m_DeviceConfigSend.encode();
  1684. printf("GetDeviceConfig over , %s", Cfg.c_str());
  1685. return true;
  1686. }
  1687. bool nsGEN::MERCURYDriver::SetDeviceConfig(std::string Cfg)
  1688. {
  1689. mLog::FINFO("--Func-- SetDeviceConfig {$}", Cfg.c_str());
  1690. printf("\n--Func-- SetDeviceConfig %s\n", Cfg.c_str());
  1691. ResDataObject DeviceConfig;
  1692. DeviceConfig.decode(Cfg.c_str());
  1693. ResDataObject DescriptionTempEx;
  1694. DescriptionTempEx = DeviceConfig["DeviceConfig"]["Attribute"];
  1695. mLog::FDEBUG("Attribute:{$}", DescriptionTempEx.encode());
  1696. bool bSaveFile = false; //true:重新保存配置文件
  1697. string strAccess = "";
  1698. for (int i = 0; i < DescriptionTempEx.size(); i++)
  1699. {
  1700. string strKey = DescriptionTempEx.GetKey(i);
  1701. mLog::FINFO("{$}", strKey.c_str());
  1702. printf("%s\n", strKey.c_str());
  1703. try
  1704. {
  1705. if (m_pAttribute->GetFirstOf(strKey.c_str()) >= 0)
  1706. {
  1707. strAccess = (string)(*m_pDescription)[strKey.c_str()]["Access"];
  1708. if ("RW" == strAccess)
  1709. {
  1710. //修改对应配置,在其他单元的配置项要同时调用其修改函数修改真实值
  1711. //1. 修改内存中的值,用于给上层发消息
  1712. (*m_pAttribute)[strKey.c_str()] = DescriptionTempEx[i];
  1713. //2. 拿到Innerkey
  1714. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  1715. mLog::FINFO("nConfigInfoCount {$}", nConfigInfoCount);
  1716. string strTemp = ""; //存储AttributeKey
  1717. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  1718. {
  1719. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  1720. if (strTemp == strKey)
  1721. {
  1722. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  1723. break;
  1724. }
  1725. }
  1726. //3. 修改配置文件中的值
  1727. if (SetDeviceConfigValue(m_Configurations, strTemp.c_str(), 1, DescriptionTempEx[i]))
  1728. {
  1729. mLog::FDEBUG("SetDeviceConfigValue over");
  1730. bSaveFile = true;
  1731. }
  1732. }
  1733. else
  1734. {
  1735. mLog::FINFO("{$} is not a RW configuration item", strKey.c_str());
  1736. }
  1737. }
  1738. else
  1739. {
  1740. mLog::FINFO("without this attribute {$}", strKey.c_str());
  1741. }
  1742. }
  1743. catch (ResDataObjectExption& e)
  1744. {
  1745. printf("\nSetDriverConfig crashed: %s\n", e.what());
  1746. mLog::FERROR("SetDriverConfig crashed: {$}", e.what());
  1747. return false;
  1748. }
  1749. }
  1750. if (bSaveFile)
  1751. {
  1752. //3. 重新保存配置文件
  1753. SaveConfigFile(true);
  1754. }
  1755. return true;
  1756. }
  1757. bool nsGEN::MERCURYDriver::SaveConfigFile(bool bSendNotify)
  1758. {
  1759. m_ConfigAll["CONFIGURATION"] = m_Configurations;
  1760. bool bRt = m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
  1761. mLog::FINFO("SaveConfigFile over {$}", bRt);
  1762. return true;
  1763. }
  1764. bool nsGEN::MERCURYDriver::GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue)
  1765. {
  1766. strValue = "";
  1767. string strTemp = pInnerKey;
  1768. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  1769. {
  1770. int pos = 0;
  1771. ResDataObject resTemp = config;
  1772. while ((pos = strTemp.find_first_of(',')) != string::npos)
  1773. {
  1774. string Key = strTemp.substr(0, pos);
  1775. string TempValue = resTemp[Key.c_str()].encode();
  1776. resTemp.clear();
  1777. resTemp.decode(TempValue.c_str());
  1778. strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
  1779. }
  1780. if (strTemp != "")
  1781. {
  1782. strValue = (string)resTemp[strTemp.c_str()];
  1783. }
  1784. else
  1785. {
  1786. strValue = (string)resTemp;
  1787. }
  1788. }
  1789. return true;
  1790. }
  1791. bool nsGEN::MERCURYDriver::SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue)
  1792. {
  1793. string strTemp = pInnerKey;
  1794. mLog::FDEBUG("Begin to change {$} item value to {$}", pInnerKey, szValue);
  1795. printf("Begin to change {%s} item value to {%s}\n", pInnerKey, szValue);
  1796. if (1 == nPathID)
  1797. {
  1798. try {
  1799. int pos = 0;
  1800. ResDataObject* resTemp = &config;
  1801. while ((pos = strTemp.find_first_of(',')) != string::npos)
  1802. {
  1803. string Key = strTemp.substr(0, pos);
  1804. resTemp = &(*resTemp)[Key.c_str()];
  1805. strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
  1806. }
  1807. if (strTemp != "")
  1808. {
  1809. (*resTemp)[strTemp.c_str()] = szValue;
  1810. }
  1811. else
  1812. {
  1813. *resTemp = szValue;
  1814. }
  1815. }
  1816. catch (ResDataObjectExption& e)
  1817. {
  1818. mLog::FERROR("SetDriverConfigvalue crashed: {$}", e.what());
  1819. return false;
  1820. }
  1821. }
  1822. return true;
  1823. }
  1824. //-----------------------------------------------------------------------------
  1825. // GetIODriver & CreateIODriver
  1826. //-----------------------------------------------------------------------------
  1827. static nsGEN::MERCURYDriver gIODriver;
  1828. extern "C" CCOS::Dev::IODriver * __cdecl GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
  1829. {
  1830. return &gIODriver;
  1831. }
  1832. extern "C" CCOS::Dev::IODriver * __cdecl CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
  1833. {
  1834. pIODriver = new nsGEN::MERCURYDriver();
  1835. return pIODriver;
  1836. }