CCOS.Dev.Generator.PSG_HR.cpp 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024
  1. // CCOS.Dev.GEN.PSGHR.cpp : 定义 DLL 应用程序的导出函数。
  2. #include <assert.h>
  3. #include <functional>
  4. #include <unordered_map>
  5. #include <fstream>
  6. #include "LogicDevice.h"
  7. using namespace std::placeholders;
  8. #include "Helper.JSON.hpp"
  9. #include "CCOS.Dev.Generator.PSG_HR.h"
  10. using namespace CCOS::Dev::Detail::Generator;
  11. namespace nsGEN = CCOS::Dev::Detail::Generator;
  12. static nsGEN::PSGHRDriver* pIODriver = nullptr;
  13. //关闭无关警告
  14. #pragma warning (disable:4244) // warning C4244: “初始化”: 从“double”转换到“float”,可能丢失数据
  15. #pragma warning (disable:4305) // warning C4305: “参数”: 从“double”到“float”截断
  16. #pragma warning (disable:4267) // warning C4267 : “初始化”: 从“size_t”转换到“int”,可能丢失数据
  17. #pragma warning (disable:4805) // warning C4805: “!=”: 在操作中将类型“bool”与类型“int”混合不安全
  18. #define PSGHR_LARGE_POWER 5
  19. #define PSGHR_SMALL_POWER 1.1
  20. #define PSGHR_MAX_HEAT 225
  21. #define PSGHR_MIN_MA 1.0
  22. #define PSGHR_MAX_MA 1000.0
  23. #define PSGHR_MIN_MS 1.0
  24. #define PSGHR_MAX_MS 10001.0
  25. //设置相关常量
  26. #define PSGHR_LoopDefHBTime 1000
  27. #define PSGHR_LoopExpHBTime 500
  28. static const int msTimeOut_Lock = 500; //通讯接口锁定时间
  29. #define PSGHR_Com_NormalLen 150
  30. #define PSGHR_ETX 0x03
  31. #define PSGHR_RESOK "$"
  32. #define Sleep(ms) std::this_thread::sleep_for(std::chrono::milliseconds(ms))
  33. /*
  34. <Command><Data><ETX><Checksum>
  35. 解释:
  36. <Command> = ASCII 字母数字命令
  37. <Data> = ASCII 数字数据
  38. <ETX> = ASCII 数字数据
  39. <Checksum> = 所有命令、数据和 ETX 字节的二进制 1 字节累加和
  40. */
  41. static const auto COM_SCFDllName = "libSerialSCF.so";
  42. static const auto TCP_SCFDllName = "libTcpipSCF.so";
  43. //Log4CPP::Logger* //mLog::gLogger = nullptr;
  44. struct tFrameMapping
  45. {
  46. static const int MaxLen = 5; // 前缀不能超过 5 个字符 !
  47. using cbFun = std::function <void(const char*, int)>;
  48. char strHead[MaxLen];
  49. int NbOfCharOfHead;
  50. cbFun fun;
  51. // 关键修改:将char*改为const char*,兼容字符串常量
  52. tFrameMapping(const char* str, int len, cbFun f)
  53. {
  54. assert(len < MaxLen); // len最大只能是4
  55. for (int i = 0; i < len; i++)
  56. strHead[i] = str[i];
  57. NbOfCharOfHead = len;
  58. fun = f;
  59. }
  60. };
  61. // 响应操作对照表
  62. static std::list <tFrameMapping> arFrame;
  63. //查找响应操作对照表执行对应操作
  64. static bool DecodeFrame(const char* strFrame, int length)
  65. {
  66. auto pr = [strFrame, length](const tFrameMapping& Item)
  67. {
  68. for (int i = 0; i < Item.NbOfCharOfHead; i++)
  69. {
  70. if (strFrame[i] != Item.strHead[i])
  71. {
  72. return false;
  73. }
  74. }
  75. return true;
  76. };
  77. auto found = std::find_if(arFrame.begin(), arFrame.end(), pr);//此处pr,是上面定义的 lambda表达式,用来在list中找到对于的包头。
  78. if (found == arFrame.end())
  79. {
  80. return false;
  81. }
  82. const auto& Item = *found;
  83. auto pc = strFrame;
  84. char data[100] = { 0 };
  85. memcpy(data, strFrame + Item.NbOfCharOfHead, length - Item.NbOfCharOfHead);
  86. Item.fun(data, length - Item.NbOfCharOfHead);
  87. return true;
  88. }
  89. //-----------------------------------------------------------------------------
  90. // PSGHRDevice
  91. //-----------------------------------------------------------------------------
  92. atomic<int> nsGEN::PSGHRDevice::m_iLoopTime = PSGHR_LoopDefHBTime;
  93. atomic<bool> nsGEN::PSGHRDevice::m_bExtraFlag = false;
  94. static atomic<bool>HeartBeatFlag = false;
  95. nsGEN::PSGHRDevice::PSGHRDevice(std::shared_ptr <IOEventCenter> center, std::shared_ptr<SCFWrapper> SCF, string configfile)
  96. : super(center)
  97. , superGen()
  98. , m_SCF(SCF)
  99. , m_bConnectFlag(false)
  100. , HeartBeatFlag(false)
  101. {
  102. assert(EventCenter);
  103. m_bExtraFlag = true;
  104. //初始化
  105. m_bExpEnable = false;
  106. m_bConnectFlag = true;
  107. m_iLoopTime.store(PSGHR_LoopDefHBTime);
  108. for (int i = 0; i < 18; i++)
  109. {
  110. m_bFaultList[i] = false;
  111. }
  112. m_iMaxPower = PSGHR_LARGE_POWER; //KW
  113. MaxHeatContent = PSGHR_MAX_HEAT; //KJ
  114. string version;
  115. //if(GetVersion(version, hMyModule))
  116. //mLog::FINFO("\n===============log begin : version:{$} ===================\n", version.c_str());
  117. //else
  118. //mLog::FINFO("\n===============log begin : version:0.0.0.0 ===================\n");
  119. //设置发生器属性集合各个值的范围及精度
  120. m_DoseUnit.m_KV.reset(new KVMould(0.0, 39.0, 151.0, 1.0));
  121. m_DoseUnit.m_MA.reset(new MAMould(0.0, PSGHR_MIN_MA, PSGHR_MAX_MA, 0.1));
  122. m_DoseUnit.m_MS.reset(new MSMould(0.0, PSGHR_MIN_MS, PSGHR_MAX_MS, 0.01));
  123. m_DoseUnit.m_MAS.reset(new MASMould(0.0, 0.1, 1000.0, 0.01));
  124. m_DoseUnit.m_Techmode.reset(new TECHMODEMould(AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P, AttrKey::TECHMODE_NOAEC_3P, AttrKey::TECHMODE_AEC_MAS_MA, 1));
  125. m_DoseUnit.m_WS.reset(new WORKSTATIONMould(1, 0, 5, 1));
  126. m_DoseUnit.m_Focus.reset(new FOCUSMould(AttrKey::FOCUS_TYPE::FOCUS_LARGE, AttrKey::FOCUS_SMALL, AttrKey::FOCUS_LARGE, 1));
  127. m_DoseUnit.m_AECField.reset(new AECFIELDMould(0, 0, 111, 1));
  128. m_DoseUnit.m_AECFilm.reset(new AECFILMMould(0, 0, 2, 1));
  129. m_DoseUnit.m_AECDensity.reset(new AECDENSITYMould(0, -3, 3, 1));
  130. m_DoseUnit.m_GenHE.reset(new GENHEATMould(0, 0, 100, 1));
  131. m_DoseUnit.m_HE.reset(new TUBEHEATMould(0, 0, 100, 1));
  132. m_DoseUnit.m_GenSynState.reset(new GENSYNSTATEMould(AttrKey::GENERATOR_RAD_OFF, AttrKey::GENERATOR_SYNC_ERR, AttrKey::GENERATOR_SYNC_MAX, 1));
  133. m_DoseUnit.m_GenState.reset(new GENSTATEMould(0, AttrKey::GENERATOR_STATUS_SHUTDOWN, AttrKey::GENERATOR_STATUS_MAX, 1));
  134. m_DoseUnit.m_GenTotalExpNumber.reset(new TOTALEXPNUMMould(0, 0, 9999, 1));
  135. m_DoseUnit.m_GenTotalAcqTimes.reset(new TOTALACQTIMESMould(0, 0, 9999, 1));
  136. m_DoseUnit.m_GenTubeCoolWaitTimes.reset(new TUBECOOLTIMEMould(0, 0, 9999, 1));
  137. m_DoseUnit.m_GenTubeOverLoadNumber.reset(new TUBEOVERLOADNUMMould(0, 0, 9999, 1));
  138. m_DoseUnit.m_GenCurrentExpNumber.reset(new CUREXPNUMMould(0, 0, 9999, 1));
  139. m_DoseUnit.m_ExpMode.reset(new EXPMODEMould(AttrKey::EXPMODE_TYPE::Single));
  140. m_DoseUnit.m_FrameRate.reset(new FRAMERATEMould(0, 0, 16, 1));
  141. m_DoseUnit.m_FLMode.reset(new FLUModeMould(AttrKey::GENERATOR_FLUMode::GENERATOR_FLMODE_NOTFLU));
  142. m_DoseUnit.m_BatteryChargeState.reset(new BATTERYCHARGSTATEMould(0, 0, 1, 1));
  143. m_DoseUnit.m_TubeTargetMaterial.reset(new TUBETARGETMATERIALMould(AttrKey::TUBETARGETMATERIAL_TYPE::MO));
  144. m_DoseUnit.m_TubeAngle.reset(new TUBEANGLEMould(0, -45, 45, 1));
  145. m_DoseUnit.m_FLIntTime.reset(new FLUIntTimeMould(0.0, 0.0, 100.0, 0.1));
  146. m_DoseUnit.m_FLAccTime.reset(new FLAccTimeMould(0.0, 0.0, 999.0, 0.1));
  147. m_DoseUnit.m_FLKV.reset(new FLUKVMould(0, 40, 125, 1));
  148. m_DoseUnit.m_FLMS.reset(new FLUMSMould(10.0, 10.0, 999999.0, 0.01));
  149. m_DoseUnit.m_FLMA.reset(new FLUMAMould(0.5, 0.5, 99.0, 0.1));
  150. m_DoseUnit.m_ABSStatus.reset(new FLUABSStatusMould(0, 0, 2, 1));
  151. m_DoseUnit.m_PPS.reset(new PPSMould(0.5,0.5, 30, 0.1));
  152. m_DoseUnit.m_DoseLevel.reset(new FLUDoseLevelMould(0, 0, 2, 1));
  153. m_DoseUnit.m_FLMode.reset(new FLUModeMould(0, 0, 4, 1));
  154. m_DoseUnit.m_Curve.reset(new FLUCurveMould(0, 0, 3, 1));
  155. //Actual exposure parameters 值
  156. m_DoseUnit.m_PostKV.reset(new POSTKVMould(0.0, 40.0, 120.0, 1.0));
  157. m_DoseUnit.m_PostMA.reset(new POSTMAMould(0.0, 1.0, 1000.0, 0.1));
  158. m_DoseUnit.m_PostMS.reset(new POSTMSMould(0.0, 1.0, 10000.0, 0.01));
  159. m_DoseUnit.m_PostMAS.reset(new POSTMASMould(0.0, 0.5, 1000.0, 0.01));
  160. //发生器告警及错误消息
  161. m_MSGUnit.reset(new nsDetail::MSGUnit(center, nsGEN::GeneratorUnitType));
  162. m_hGenPostEvent = LinuxEvent::CreateEvent(LinuxEvent::MANUAL_RESET, false);
  163. //配置响应操作对照表 供发生器回传的数据触发相应的操作
  164. OnCallBack();
  165. //将发生器可以对外提供的指令注册集进行补充
  166. Register();
  167. LoadConfig(configfile);
  168. //重置发生器
  169. HWSend("RE", 2);
  170. //以下进行默认设置,需要注意默认值是否正确
  171. // HWSend("RR", 2);
  172. HWSend("RS", 2);
  173. HWSend("ET?", 3); //查询2、3点模式
  174. HWSend("ST?", 3);
  175. //启动硬件状态轮询进程
  176. StartHardwareStatusThread();
  177. }
  178. nsGEN::PSGHRDevice::~PSGHRDevice()
  179. {
  180. m_bExtraFlag = false;
  181. if (m_pHardwareStatusThread.joinable()) {
  182. m_pHardwareStatusThread.join();
  183. }
  184. //mLog::FINFO("\n===============log end ===================\n");
  185. arFrame.clear();
  186. }
  187. std::string nsGEN::PSGHRDevice::GetGUID() const
  188. {
  189. //mLog::FINFO("===============GetGUID : {$} ===================\n", GeneratorUnitType);
  190. return GeneratorUnitType;
  191. }
  192. void nsGEN::PSGHRDevice::Register()
  193. {
  194. auto Disp = m_Dispatch.Lock().As();
  195. superGen::Register(Disp);
  196. superGen::RegisterRAD(Disp);
  197. superGen::RegisterAEC(Disp);
  198. superGen::RegisterExpEnable(Disp);
  199. superGen::RegisterGeneratortoSyncStatus(Disp);
  200. superGen::RegisterFluoro(Disp);
  201. Disp->Get.Push(m_MSGUnit->GetKey().c_str(), [this](std::string& out) { out = m_MSGUnit->JSGet(); return RET_STATUS::RET_SUCCEED; });
  202. Disp->Get.Push(AttrKey::DENHEAT, [this](std::string& out) { out = m_DoseUnit.m_GenHE->JSGet(); return RET_STATUS::RET_SUCCEED; });
  203. auto fun_Clear_DAP = [this](auto in, auto& out)
  204. {
  205. return Clear_DAP();
  206. };
  207. Disp->Action.Push("Clear_DAP", fun_Clear_DAP);
  208. auto fun_GetValue_DAP = [this](auto in, auto& out)
  209. {
  210. float value = 0;
  211. RET_STATUS ret = GetValue_DAP(value);
  212. out = ToJSON(value);
  213. return ret;
  214. };
  215. Disp->Action.Push("GetValue_DAP", fun_GetValue_DAP);
  216. }
  217. RET_STATUS nsGEN::PSGHRDevice::IncKV()
  218. {
  219. //mLog::FINFO("Enter PSGHRDevice::IncKV()\n");
  220. if (!m_DoseUnit.m_KV->CanInc()) return RET_STATUS::RET_SUCCEED;
  221. return HWSend("KV+", 3);
  222. }
  223. RET_STATUS nsGEN::PSGHRDevice::DecKV()
  224. {
  225. if (!m_DoseUnit.m_KV->CanDec()) return RET_STATUS::RET_SUCCEED;
  226. return HWSend("KV-", 3);
  227. }
  228. RET_STATUS nsGEN::PSGHRDevice::SetKV(float value)
  229. {
  230. if (!m_DoseUnit.m_KV->Verify(value)) return RET_STATUS::RET_SUCCEED;
  231. char temp[50] = { 0 };
  232. snprintf(temp, sizeof(temp), "KV%03d", (int)value);
  233. return HWSend(temp, strlen(temp));
  234. }
  235. RET_STATUS nsGEN::PSGHRDevice::IncMA()
  236. {
  237. if (!m_DoseUnit.m_MA->CanInc()) return RET_STATUS::RET_SUCCEED;
  238. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  239. {
  240. //mLog::FINFO("\n Techmode is MAS, can't inc MA");
  241. return RET_STATUS::RET_FAILED;
  242. }
  243. return HWSend("MA+",3);
  244. }
  245. RET_STATUS nsGEN::PSGHRDevice::DecMA()
  246. {
  247. if (!m_DoseUnit.m_MA->CanDec()) return RET_STATUS::RET_SUCCEED;
  248. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  249. {
  250. //mLog::FINFO("\n Techmode is MAS, can't dec MA");
  251. return RET_STATUS::RET_FAILED;
  252. }
  253. return HWSend("MA-", 3);
  254. }
  255. RET_STATUS nsGEN::PSGHRDevice::SetMA(float value)
  256. {
  257. if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
  258. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  259. {
  260. //mLog::FINFO("\n Techmode is MAS, can't set MA");
  261. return RET_STATUS::RET_FAILED;
  262. }
  263. char temp[50] = { 0 };
  264. snprintf(temp, sizeof(temp), "MA%05d", (int)(value * 10));
  265. return HWSend(temp, strlen(temp));
  266. }
  267. RET_STATUS nsGEN::PSGHRDevice::IncMS()
  268. {
  269. //mLog::FINFO("nsGEN::PSGHRDevice::IncMS()\n");
  270. if (!m_DoseUnit.m_MS->CanInc()) return RET_STATUS::RET_SUCCEED;
  271. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
  272. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  273. {
  274. //mLog::FINFO("Techmode is 2Point, Cannot inc MS \n");
  275. return RET_STATUS::RET_FAILED;
  276. }
  277. return HWSend("MS+",3);
  278. }
  279. RET_STATUS nsGEN::PSGHRDevice::DecMS()
  280. {
  281. if (!m_DoseUnit.m_MS->CanDec()) return RET_STATUS::RET_SUCCEED;
  282. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
  283. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  284. {
  285. //mLog::FINFO("Techmode is 2Point, Cannot dec MS \n");
  286. return RET_STATUS::RET_FAILED;
  287. }
  288. return HWSend("MS-", 3);;
  289. }
  290. RET_STATUS nsGEN::PSGHRDevice::SetMS(float value)
  291. {
  292. if (!m_DoseUnit.m_MS->Verify(value)) return RET_STATUS::RET_SUCCEED;
  293. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
  294. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  295. {
  296. //mLog::FINFO("Techmode is 2Point, Cannot set MS \n");
  297. return RET_STATUS::RET_FAILED;
  298. }
  299. char temp[50] = { 0 };
  300. snprintf(temp, sizeof(temp), "MS%07d", (int)(value * 100));
  301. return HWSend(temp,strlen(temp));
  302. }
  303. RET_STATUS nsGEN::PSGHRDevice::IncMAS()
  304. {
  305. //mLog::FINFO("nsGEN::PSGHRDevice::IncMAS()\n");
  306. if (!m_DoseUnit.m_MAS->CanInc()) return RET_STATUS::RET_SUCCEED;
  307. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
  308. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
  309. {
  310. //mLog::FINFO("Techmode is 3Point, Cannot inc MAS \n");
  311. return RET_STATUS::RET_FAILED;
  312. }
  313. return HWSend("MX+" , 3);
  314. }
  315. RET_STATUS nsGEN::PSGHRDevice::DecMAS()
  316. {
  317. if (!m_DoseUnit.m_MAS->CanDec()) return RET_STATUS::RET_SUCCEED;
  318. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
  319. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
  320. {
  321. //mLog::FINFO("Techmode is 3Point, Cannot dec MAS \n");
  322. return RET_STATUS::RET_FAILED;
  323. }
  324. return HWSend("MX-", 3);
  325. }
  326. RET_STATUS nsGEN::PSGHRDevice::SetMAS(float value)
  327. {
  328. if (!m_DoseUnit.m_MAS->Verify(value)) return RET_STATUS::RET_SUCCEED;
  329. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
  330. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
  331. {
  332. //mLog::FINFO("Techmode is 3Point, Cannot set MAS \n");
  333. return RET_STATUS::RET_FAILED;
  334. }
  335. char temp[50] = { 0 };
  336. snprintf(temp, sizeof(temp), "MX%06d", (int)(value * 100));
  337. return HWSend(temp, strlen(temp));
  338. }
  339. RET_STATUS nsGEN::PSGHRDevice::SetTechmode(int value)
  340. {
  341. if (!m_DoseUnit.m_Techmode->Verify(value)) return RET_STATUS::RET_SUCCEED;
  342. char temp[50] = { 0 };
  343. snprintf(temp, sizeof(temp), "ET%1d", (int)value);
  344. return HWSend(temp, strlen(temp));
  345. }
  346. RET_STATUS nsGEN::PSGHRDevice::SetEXAMMode(std::string value)
  347. {
  348. //上层给我设置exam mode(manual semiauto automatic)对应(NoAEC2Point AEC2Point AEC2Point)
  349. //mLog::FINFO("Enter setexammode func value = {$}\n", value);
  350. if (value == AttrKey::EXAMMODE_TYPE::MANUAL)
  351. {
  352. SetTechmode(AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P);
  353. }
  354. else if (value == AttrKey::EXAMMODE_TYPE::SEMIAUTO)
  355. {
  356. SetTechmode(AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P);
  357. }
  358. else if (value == AttrKey::EXAMMODE_TYPE::AUTOMATIC)
  359. {
  360. SetTechmode(AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P);
  361. }
  362. return RET_STATUS::RET_SUCCEED;
  363. }
  364. RET_STATUS nsGEN::PSGHRDevice::SetAPR(const _tAPRArgs& t)
  365. {
  366. m_bGenBusy = true;
  367. //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);
  368. if (t.nFocus < 0)
  369. {
  370. //mLog::FINFO("SetAPR: the focus value is amall than 0, set focus to small focus\n");
  371. SetFocus(0);
  372. }
  373. int nTempAECFilm = 1;
  374. switch (t.nAECFilm)
  375. {
  376. case 0:
  377. nTempAECFilm = 1;
  378. break;
  379. case 1:
  380. nTempAECFilm = 10;
  381. break;
  382. case 2:
  383. nTempAECFilm = 100;
  384. break;
  385. default:
  386. break;
  387. }
  388. SetKV(t.fKV);
  389. SetFocus(t.nFocus);
  390. if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_AEC)
  391. {
  392. // aec
  393. SetTechmode(t.nTechmode);
  394. Sleep(50);
  395. SetAECField(t.nAECField);
  396. Sleep(80);
  397. SetAECDensity(t.nAECDensity);
  398. Sleep(50);
  399. SetAECFilm(nTempAECFilm);
  400. Sleep(50);
  401. SetMA(t.fMA);
  402. Sleep(50);
  403. SetMS(t.fMS);
  404. }
  405. else if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  406. {
  407. // mas
  408. SetTechmode(t.nTechmode);
  409. Sleep(50);
  410. const float EPSINON = 0.000001;
  411. if ((t.fMAS >= -EPSINON) && (t.fMAS <= EPSINON))
  412. {
  413. SetMAS(t.fMA * t.fMS / 1000);
  414. }
  415. else
  416. {
  417. SetMAS(t.fMAS);
  418. }
  419. }
  420. else if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_TIME)
  421. {
  422. // time
  423. SetTechmode(t.nTechmode);
  424. Sleep(50);
  425. SetMA(t.fMA);
  426. Sleep(80);
  427. SetMS(t.fMS);
  428. }
  429. m_bGenBusy = false;
  430. HWSend("RR", 2);
  431. ///////////////////////end
  432. return RET_STATUS::RET_SUCCEED;
  433. }
  434. RET_STATUS nsGEN::PSGHRDevice::RefreshData()
  435. {
  436. if (!m_bGenBusy)
  437. {
  438. HWSend("RR", 2);
  439. Sleep(50);
  440. HWSend("RS", 2);
  441. }
  442. return RET_STATUS::RET_SUCCEED;
  443. }
  444. RET_STATUS nsGEN::PSGHRDevice::SetFocus(int value)
  445. {
  446. if (!m_DoseUnit.m_Focus->Verify(value)) return RET_STATUS::RET_SUCCEED;
  447. char temp[50] = { 0 };
  448. snprintf(temp, sizeof(temp), "FO%01d", (int)value);
  449. return HWSend(temp,strlen(temp));
  450. }
  451. RET_STATUS nsGEN::PSGHRDevice::Reset()
  452. {
  453. //mLog::Debug("clear all errors \n");
  454. int level = 0;
  455. m_MSGUnit->DelErrorMessage("0", level, "clear all errors");
  456. m_MSGUnit->DelWarnMessage("0", level, "clear all Warning");
  457. HWSend("RE",2);//仅重置错误状态
  458. return RET_STATUS::RET_SUCCEED;
  459. }
  460. RET_STATUS nsGEN::PSGHRDevice::ActiveSyncMode(_tSyncModeArgs value)
  461. {
  462. //mLog::FINFO("value.strSyncMode: {$}, value.strSyncValue: {$}, value.strWS: {$} \n", value.strSyncMode, value.strSyncValue, value.strWS);
  463. int nSyncModeValue = atoi(value.strSyncValue.c_str());
  464. char temp[50] = { 0 };
  465. snprintf(temp, sizeof(temp), "WS%01d", nSyncModeValue);
  466. return HWSend(temp, strlen(temp));
  467. }
  468. RET_STATUS nsGEN::PSGHRDevice::QueryHE(int& value)
  469. {
  470. if (!m_bGenBusy)
  471. return HWSend("HE?", 3);
  472. return RET_STATUS::RET_SUCCEED;
  473. }
  474. void nsGEN::PSGHRDevice::SubscribeSelf(ccos_mqtt_connection* conn)
  475. {
  476. //订阅GEN所有Action
  477. //SubscribeTopic(conn, "CCOS/DEVICE/Generator/Action/#"); Moduld层默认订阅了这个Action,如果这边也订阅的话就会执行两遍Action,可能会出问题
  478. }
  479. RET_STATUS nsGEN::PSGHRDevice::SetVibrationGrid(int value)//发生器暂无此设置
  480. {
  481. //mLog::FINFO("Enter StartVibrationGrid:[{$}]", value);
  482. return RET_STATUS::RET_SUCCEED;
  483. }
  484. RET_STATUS nsGEN::PSGHRDevice::GetVibrationGridMS(int& value) //发生器暂无此设置
  485. {
  486. return RET_STATUS::RET_SUCCEED;
  487. }
  488. RET_STATUS nsGEN::PSGHRDevice::SetAECDensity(int value)
  489. {
  490. if (!m_DoseUnit.m_AECDensity->Verify(value)) return RET_STATUS::RET_SUCCEED;
  491. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_AEC) return RET_STATUS::RET_FAILED;
  492. int nAECDensity = m_DoseUnit.m_AECDensity->Get();
  493. if (value < m_DoseUnit.m_AECDensity->Get())
  494. {
  495. if (value < m_DoseUnit.m_AECDensity->Get() - 1)
  496. {
  497. nAECDensity = (int)value;
  498. }
  499. else
  500. {
  501. nAECDensity = nAECDensity - 1;
  502. }
  503. }
  504. else if (value > m_DoseUnit.m_AECDensity->Get())
  505. {
  506. if (value > m_DoseUnit.m_AECDensity->Get() + 1)
  507. {
  508. nAECDensity = (int)value;
  509. }
  510. else
  511. {
  512. nAECDensity = nAECDensity + 1;
  513. }
  514. }
  515. m_DoseUnit.m_AECDensity->Update(value);
  516. char temp[50] = { 0 };
  517. if (nAECDensity >= 0)
  518. {
  519. snprintf(temp, sizeof(temp), "FN+%01d", (int)nAECDensity);
  520. }
  521. else
  522. {
  523. snprintf(temp, sizeof(temp), "FN-%01d", (int)nAECDensity);
  524. }
  525. return HWSend(temp, strlen(temp));
  526. }
  527. RET_STATUS nsGEN::PSGHRDevice::SetAECField(int value)
  528. {
  529. if (!m_DoseUnit.m_AECField->Verify(value)) return RET_STATUS::RET_SUCCEED;
  530. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS) return RET_STATUS::RET_FAILED;
  531. m_DoseUnit.m_AECField->Update(value);
  532. char temp[50] = { 0 };
  533. snprintf(temp, sizeof(temp), "FI%03d", (int)value);
  534. return HWSend(temp, strlen(temp));
  535. }
  536. RET_STATUS nsGEN::PSGHRDevice::SetAECFilm(int value)
  537. {
  538. if (!m_DoseUnit.m_AECFilm->Verify(value)) return RET_STATUS::RET_SUCCEED;
  539. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS) return RET_STATUS::RET_FAILED;
  540. m_DoseUnit.m_AECFilm->Update(value);
  541. char temp[50] = { 0 };
  542. snprintf(temp, sizeof(temp), "FS%03d", (int)value);
  543. return HWSend(temp, strlen(temp));
  544. }
  545. RET_STATUS nsGEN::PSGHRDevice::SetWS(const string value)
  546. {
  547. //mLog::FINFO("Enter SetWS {$}", value);
  548. int tempws = 0;
  549. if (value == "Table") tempws = (int)m_GenConfig["WSTable"];
  550. else if (value == "Wall") tempws = (int)m_GenConfig["WSWall"];
  551. else if (value == "Direct") tempws = (int)m_GenConfig["WSConventional"];
  552. else if (value == "Free") tempws = (int)m_GenConfig["WSFree"];
  553. else if (value == "Tomo") tempws = (int)m_GenConfig["WSTomo"];
  554. m_DoseUnit.m_WS->Update(tempws);
  555. char temp[50] = { 0 };
  556. snprintf(temp, sizeof(temp), "WS%01d", tempws);
  557. return HWSend(temp, strlen(temp));
  558. }
  559. RET_STATUS nsGEN::PSGHRDevice::QueryPostKV(float& value)
  560. {
  561. m_DoseUnit.m_PostKV->Update(m_DoseUnit.m_KV->Get());
  562. value = m_DoseUnit.m_PostKV->Get();
  563. return HWSend("VP?",3);
  564. }
  565. RET_STATUS nsGEN::PSGHRDevice::QueryPostMA(float& value)
  566. {
  567. return HWSend("PA?", 3);
  568. }
  569. RET_STATUS nsGEN::PSGHRDevice::QueryPostMS(float& value)
  570. {
  571. return HWSend("AT?",3);
  572. }
  573. RET_STATUS nsGEN::PSGHRDevice::QueryPostMAS(float& value)
  574. {
  575. return HWSend("AP?", 3);
  576. }
  577. RET_STATUS nsGEN::PSGHRDevice::Clear_DAP()
  578. {
  579. return RET_STATUS::RET_SUCCEED;
  580. }
  581. RET_STATUS nsGEN::PSGHRDevice::GetValue_DAP(float& value)
  582. {
  583. return RET_STATUS::RET_SUCCEED;
  584. }
  585. RET_STATUS nsGEN::PSGHRDevice::StartMove() //发生器无此设置
  586. {
  587. return RET_STATUS::RET_SUCCEED;
  588. }
  589. RET_STATUS nsGEN::PSGHRDevice::EndMove() //发生器无此设置
  590. {
  591. return RET_STATUS::RET_SUCCEED;
  592. }
  593. RET_STATUS nsGEN::PSGHRDevice::SetGenSynState(int value)
  594. {
  595. //mLog::FINFO("Enter SetGenSynState...{$} \n", value);
  596. //if (AttrKey::GENERATOR_RAD_XRAYON == value)
  597. //{
  598. // //mLog::FINFO("SetGenSynState be call.this is soft syn mode.");
  599. // HWSend("XR2",3);
  600. // m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON);
  601. // FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  602. //}
  603. //else if(AttrKey::GENERATOR_FLU_XRAYON == value)
  604. //{
  605. // //mLog::FINFO("SetGenSynState be call.this is soft syn mode.");
  606. // //HWSend("FLX2", 4);
  607. // //m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_XRAYON);
  608. // //FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  609. //}
  610. return RET_STATUS::RET_SUCCEED;
  611. }
  612. RET_STATUS nsGEN::PSGHRDevice::SetGenState(int value)
  613. {
  614. return RET_STATUS::RET_SUCCEED;
  615. }
  616. RET_STATUS nsGEN::PSGHRDevice::SetExpMode(std::string value)
  617. {
  618. //mLog::FINFO("Enter SetExpMode...{$} \n",value.c_str());
  619. m_DoseUnit.m_ExpMode->Update(value);
  620. //add for dcm iRF hard
  621. //mLog::FINFO("SetExpMode:add for dcm iRF hard");
  622. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  623. FireNotify(m_DoseUnit.m_TubeTargetMaterial->GetKey(), m_DoseUnit.m_TubeTargetMaterial->JSGet());
  624. FireNotify(m_DoseUnit.m_TubeAngle->GetKey(), m_DoseUnit.m_TubeAngle->JSGet());
  625. return RET_STATUS::RET_SUCCEED;
  626. }
  627. RET_STATUS nsGEN::PSGHRDevice::SetFLFMode(std::string value)
  628. {
  629. //mLog::FINFO("Enter SetFLFMode...{$} \n", value.c_str());
  630. if (value == "CF")
  631. {
  632. m_DoseUnit.m_FLMode->Update(1);
  633. HWSend("FLF1", 4);
  634. SetPPS(15);
  635. SetPluseWidth(15);
  636. }
  637. else if (value == "PF")
  638. {
  639. m_DoseUnit.m_FLMode->Update(2);
  640. HWSend("FLF2", 4);
  641. SetPPS(5);
  642. SetPluseWidth(5);
  643. }
  644. else
  645. {
  646. //mLog::FINFO("other FluMode : {$}", value.c_str());
  647. return RET_STATUS::RET_SUCCEED;
  648. }
  649. return RET_STATUS::RET_SUCCEED;
  650. }
  651. RET_STATUS nsGEN::PSGHRDevice::SetFLLever(float value)
  652. {
  653. //mLog::FINFO("Enter SetFLLever...{$} \n", value);
  654. m_DoseUnit.m_DoseLevel->Update(value);
  655. char temp[50]{ 0 };
  656. snprintf(temp, sizeof(temp), "FLD%f", value);
  657. return HWSend(temp, strlen(temp));
  658. }
  659. RET_STATUS nsGEN::PSGHRDevice::SetFrameRate(float frameRate)
  660. {
  661. //mLog::FINFO("SetFrameRate in\n");
  662. /*m_DoseUnit.m_FrameRate->Update(frameRate);
  663. char temp[50]{ 0 };
  664. snprintf(temp, sizeof(temp), "FLS%03d", int(frameRate * 10));
  665. return HWSend(temp, strlen(temp));*/
  666. return RET_STATUS::RET_SUCCEED;
  667. }
  668. RET_STATUS nsGEN::PSGHRDevice::SetRPS(int rps) //发生器无此动态设置
  669. {
  670. return RET_STATUS::RET_SUCCEED;
  671. }
  672. RET_STATUS nsGEN::PSGHRDevice::SetAPF(const _tAPFArgs& t)
  673. {
  674. m_bGenBusy = true;
  675. //mLog::FINFO("APF:FLKV={$},FLMA={$},PPS={$},WS={$},FLuType={$},ABSMode={$},DoseLever={$}", t.nFLKV, t.fFLMA, t.nPPS, t.nWS, t.nFluMode, t.nABSMode, t.nDoseLever);
  676. SetABSMode(t.nABSMode);
  677. Sleep(50);
  678. SetFLFMode(to_string(t.nFluMode));
  679. Sleep(50);
  680. SetFluDoseLever(t.nDoseLever);
  681. Sleep(50);
  682. SetFluKV(t.nFLKV);
  683. Sleep(50);
  684. SetFluMA(t.fFLMA);
  685. m_bGenBusy = false;
  686. return RET_STATUS::RET_SUCCEED;
  687. }
  688. RET_STATUS nsGEN::PSGHRDevice::IncFluKV()
  689. {
  690. //mLog::FINFO("nsGEN::PSGHRDevice::IncFLKV()\n");
  691. if (!m_DoseUnit.m_FLKV->CanInc()) return RET_STATUS::RET_SUCCEED;
  692. return HWSend("FLK+", 4);
  693. }
  694. RET_STATUS nsGEN::PSGHRDevice::DecFluKV()
  695. {
  696. if (!m_DoseUnit.m_FLKV->CanDec()) return RET_STATUS::RET_SUCCEED;
  697. return HWSend("FLK-", 4);
  698. }
  699. RET_STATUS nsGEN::PSGHRDevice::SetFluKV(float value)
  700. {
  701. if (!m_DoseUnit.m_FLKV->Verify(value)) return RET_STATUS::RET_SUCCEED;
  702. char temp[50] = { 0 };
  703. snprintf(temp, sizeof(temp), "FLK%03d", (int)value);
  704. return HWSend(temp, strlen(temp));
  705. }
  706. RET_STATUS nsGEN::PSGHRDevice::IncFluMA()
  707. {
  708. if (!m_DoseUnit.m_FLMA->CanInc()) return RET_STATUS::RET_SUCCEED;
  709. return HWSend("FLM+", 4);
  710. }
  711. RET_STATUS nsGEN::PSGHRDevice::DecFluMA()
  712. {
  713. if (!m_DoseUnit.m_FLMA->CanDec()) return RET_STATUS::RET_SUCCEED;
  714. return HWSend("FLM-", 4);
  715. }
  716. RET_STATUS nsGEN::PSGHRDevice::SetFluMA(float value)
  717. {
  718. if (!m_DoseUnit.m_FLMA->Verify(value)) return RET_STATUS::RET_SUCCEED;
  719. char temp[50] = { 0 };
  720. snprintf(temp, sizeof(temp), "FLM%03d", (int)(value * 10));
  721. return HWSend(temp, strlen(temp));
  722. }
  723. RET_STATUS nsGEN::PSGHRDevice::INCPPS()
  724. {
  725. if (!m_DoseUnit.m_PPS->CanInc()) return RET_STATUS::RET_SUCCEED;
  726. return HWSend("FLS+", 4);
  727. }
  728. RET_STATUS nsGEN::PSGHRDevice::DECPPS()
  729. {
  730. if (!m_DoseUnit.m_PPS->CanDec()) return RET_STATUS::RET_SUCCEED;
  731. return HWSend("FLS-", 4);
  732. }
  733. RET_STATUS nsGEN::PSGHRDevice::SetPPS(float value)
  734. {
  735. if (!m_DoseUnit.m_PPS->Verify(value)) return RET_STATUS::RET_SUCCEED;
  736. char temp[50] = { 0 };
  737. snprintf(temp, sizeof(temp), "FLS%03d", (int)(value * 10));
  738. return HWSend(temp, strlen(temp));
  739. }
  740. RET_STATUS nsGEN::PSGHRDevice::SetABSMode(int nMode)
  741. {
  742. if (!m_DoseUnit.m_ABSStatus->Verify(nMode)) return RET_STATUS::RET_SUCCEED;
  743. char temp[50] = { 0 };
  744. //mLog::FINFO("SetABSMode[{$}] \n", nMode);
  745. snprintf(temp, sizeof(temp), "FLA%d", (int)nMode);
  746. return HWSend(temp, strlen(temp));
  747. }
  748. RET_STATUS nsGEN::PSGHRDevice::SetABSCurve(int curveNum)
  749. {
  750. return RET_STATUS::RET_SUCCEED;
  751. }
  752. RET_STATUS nsGEN::PSGHRDevice::IncABSCurve()
  753. {
  754. return RET_STATUS::RET_SUCCEED;
  755. }
  756. RET_STATUS nsGEN::PSGHRDevice::DecABSCurve()
  757. {
  758. return RET_STATUS::RET_SUCCEED;
  759. }
  760. RET_STATUS nsGEN::PSGHRDevice::GetABSCurve()
  761. {
  762. return HWSend("FLA?", 4);
  763. }
  764. float nsGEN::PSGHRDevice::GetFluIntTimer()
  765. {
  766. return HWSend("FLI?", 4);
  767. }
  768. float nsGEN::PSGHRDevice::GetFluAccTimer()
  769. {
  770. return HWSend("FLT?", 4);
  771. }
  772. RET_STATUS nsGEN::PSGHRDevice::ResetFluTimer(int value)
  773. {
  774. char temp[50] = { 0 };
  775. snprintf(temp, sizeof(temp), "FLR%d", (int)value);
  776. //mLog::FINFO("ReSetFluAccTimer[{$}] \n", value);
  777. return HWSend(temp, strlen(temp));
  778. }
  779. RET_STATUS nsGEN::PSGHRDevice::SetFluPre(int value)
  780. {
  781. return RET_STATUS::RET_SUCCEED;
  782. }
  783. RET_STATUS nsGEN::PSGHRDevice::SetFluEXP(int value)
  784. {
  785. return RET_STATUS::RET_SUCCEED;
  786. }
  787. RET_STATUS nsGEN::PSGHRDevice::SetFluMode(std::string value)
  788. {
  789. //mLog::FINFO("Enter SetFLFMode...{$} \n", value.c_str());
  790. if (value == "CF")
  791. {
  792. m_DoseUnit.m_FLMode->Update(1);
  793. return HWSend("FLF1", 4);
  794. }
  795. else if (value == "PF")
  796. {
  797. m_DoseUnit.m_FLMode->Update(2);
  798. return HWSend("FLF2", 4);
  799. }
  800. else
  801. {
  802. //mLog::FINFO("other FluMode : {$}",value.c_str());
  803. return RET_STATUS::RET_SUCCEED;
  804. }
  805. }
  806. RET_STATUS nsGEN::PSGHRDevice::SetFluDoseLever(int value)
  807. {
  808. //mLog::FINFO("Enter SetFluDoseLever...{$} \n", value);
  809. m_DoseUnit.m_DoseLevel->Update(value);
  810. char temp[50]{ 0 };
  811. snprintf(temp, sizeof(temp), "FLD%d", value);
  812. return HWSend(temp, strlen(temp));
  813. }
  814. RET_STATUS nsGEN::PSGHRDevice::SetPluseWidth(float fplusewidth)
  815. {
  816. if (!m_DoseUnit.m_PPS->Verify(fplusewidth)) return RET_STATUS::RET_SUCCEED;
  817. char temp[50] = { 0 };
  818. snprintf(temp, sizeof(temp), "FLW%05d", (int)(fplusewidth * 100));
  819. return HWSend(temp, strlen(temp));
  820. }
  821. RET_STATUS nsGEN::PSGHRDevice::SetExpEnable()
  822. {
  823. if (1 == m_bUseCECmd)
  824. {
  825. HWSend("CE1", 3);
  826. }
  827. HWSend("ST?", 3);
  828. //mLog::FINFO("SetExpEnable in\n");
  829. m_bExpEnable = true;
  830. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  831. return RET_STATUS::RET_SUCCEED;
  832. }
  833. RET_STATUS nsGEN::PSGHRDevice::SetExpDisable()
  834. {
  835. if (1 == m_bUseCECmd)
  836. {
  837. HWSend("CE0", 3);
  838. }
  839. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  840. //mLog::FINFO("SetExpDisable in\n");
  841. m_bExpEnable = false;
  842. return RET_STATUS::RET_SUCCEED;
  843. }
  844. void nsGEN::PSGHRDevice::SetSmartAEC(int value) //发生器暂无此设置
  845. {
  846. }
  847. //-----------------------------------------------------------------------------
  848. // ProcessCmd
  849. //-----------------------------------------------------------------------------
  850. void nsGEN::PSGHRDevice::ProcessClientData(const char* pData, unsigned long nDataLength, void* lparam)
  851. {
  852. PSGHRDevice* pCurGen = (PSGHRDevice*)lparam;
  853. pCurGen->HWSend(pData, nDataLength);
  854. }
  855. RET_STATUS nsGEN::PSGHRDevice::HWSend(const char* strCommand,int lengh, bool reSend, int nTimeOut)
  856. {
  857. if (!m_bConnectFlag)
  858. {
  859. //mLog::Error("==OUT==: not Connect,[{$}] send failed \n", strCommand);
  860. return RET_STATUS::RET_FAILED;
  861. }
  862. if (!m_SCF) return RET_STATUS::RET_FAILED;
  863. char strSendCommand[100] = { 0 };
  864. int len = strlen(strCommand);
  865. int tmpSum = 0;
  866. for (int i = 0; i < len; i++)
  867. {
  868. tmpSum += (int)strCommand[i];
  869. }
  870. char checkSum = char(tmpSum + 3);
  871. memcpy(strSendCommand, strCommand, len);
  872. strSendCommand[len + 0] = 0x03;
  873. strSendCommand[len + 1] = checkSum;
  874. //mLog::FINFO("==OUT==: [{$}] \n", strSendCommand);
  875. unsigned int retLength;
  876. if (m_SCF->Lock(1000) == WAIT_OBJECT_0) {
  877. int result = m_SCF->SendPacket(strSendCommand, strlen(strSendCommand), nTimeOut, retLength);
  878. m_SCF->Unlock();
  879. if (result != SCF_SUCCEED) {
  880. return RET_STATUS::RET_FAILED;
  881. }
  882. }
  883. else {
  884. return RET_STATUS::RET_FAILED;
  885. }
  886. return RET_STATUS::RET_SUCCEED;
  887. }
  888. void nsGEN::PSGHRDevice::FireNotify(string key, int context)
  889. {
  890. char szInfo[64] = { 0 };
  891. snprintf(szInfo, sizeof(szInfo), "%d", context); // Linux 标准函数
  892. std::string str = szInfo;
  893. EventCenter->OnNotify(1, key, str);
  894. }
  895. void nsGEN::PSGHRDevice::FireNotify(std::string key, float context)
  896. {
  897. char szInfo[16] = { 0 };
  898. snprintf(szInfo, sizeof(szInfo), "%.2f", context); // Linux 标准函数
  899. std::string str = szInfo;
  900. EventCenter->OnNotify(1, key, str);
  901. }
  902. void nsGEN::PSGHRDevice::FireNotify(std::string key, std::string context)
  903. {
  904. EventCenter->OnNotify(1, key, context);
  905. }
  906. void nsGEN::PSGHRDevice::FireErrorMessage(const bool Act, const int Code, const char* ResInfo)
  907. {
  908. string ErrorCode("PSGHR_ERR_");
  909. ErrorCode += std::to_string(Code);
  910. int level = PSG_HR_REGULATION_LEVEL::REG_ERRO;
  911. if (Act)
  912. {
  913. //mLog::Error("add {$}:{$}", ErrorCode.c_str(), ResInfo);
  914. m_MSGUnit->AddErrorMessage(ErrorCode.c_str(), level, ResInfo);
  915. }
  916. else
  917. {
  918. //mLog::Error("del {$}:{$}", ErrorCode.c_str(), ResInfo);
  919. m_MSGUnit->DelErrorMessage(ErrorCode.c_str(), level, ResInfo);
  920. }
  921. }
  922. void nsGEN::PSGHRDevice::FireWarnMessage(const bool Act, const int Code, const char* ResInfo)
  923. {
  924. string ErrorCode("PSGHR_WAR_");
  925. ErrorCode += std::to_string(Code);
  926. int level = PSG_HR_REGULATION_LEVEL::REG_WARN;
  927. if (Act)
  928. {
  929. //mLog::Error("add {$}:{$}", ErrorCode.c_str(), ResInfo);
  930. m_MSGUnit->AddWarnMessage(ErrorCode.c_str(), level, ResInfo);
  931. }
  932. else
  933. {
  934. //mLog::Error("del {$}:{$}", ErrorCode.c_str(), ResInfo);
  935. m_MSGUnit->DelWarnMessage(ErrorCode.c_str(), level, ResInfo);
  936. }
  937. }
  938. void nsGEN::PSGHRDevice::OnCallBack()
  939. {
  940. //无 操作
  941. auto HWNotProcess = [](const char* value, int length) -> void
  942. {
  943. //mLog::FINFO("This commands[{$}] didn't need to process", value);
  944. };
  945. auto HWKV = [this](const char* value, int length) -> void
  946. {
  947. assert(value);
  948. if (length > 20) //if length more than 20, it must be a long string like :070 MA00320 MS00063 MX00036
  949. {
  950. //mLog::FINFO("value:{$}", value);
  951. //loop the long string to find kv ma ms mas
  952. int tmpkv;
  953. float tmpma, tmpms, tmpmx;
  954. string strTemp = "";
  955. char tmpbuf[7] = { 0 };
  956. //kv
  957. tmpbuf[0] = '0';
  958. tmpbuf[1] = '0';
  959. tmpbuf[2] = '0';
  960. tmpbuf[3] = '0';
  961. tmpbuf[4] = value[0];
  962. tmpbuf[5] = value[1];
  963. tmpbuf[6] = value[2];
  964. tmpkv = atoi(tmpbuf);
  965. m_DoseUnit.m_KV->Update(tmpkv);
  966. FireNotify(AttrKey::KV, m_DoseUnit.m_KV->JSGet());
  967. //ma
  968. tmpbuf[0] = '0';
  969. tmpbuf[1] = '0';
  970. tmpbuf[2] = value[6];
  971. tmpbuf[3] = value[7];
  972. tmpbuf[4] = value[8];
  973. tmpbuf[5] = value[9];
  974. tmpbuf[6] = value[10];
  975. tmpma = atof(tmpbuf) / 10.0;
  976. m_DoseUnit.m_MA->Update(tmpma);
  977. FireNotify(AttrKey::MA, m_DoseUnit.m_MA->JSGet());
  978. //ms
  979. tmpbuf[0] = value[14];
  980. tmpbuf[1] = value[15];
  981. tmpbuf[2] = value[16];
  982. tmpbuf[3] = value[17];
  983. tmpbuf[4] = value[18];
  984. tmpbuf[5] = value[19];
  985. tmpbuf[6] = value[20];
  986. tmpms = atof(tmpbuf) / 100.0;
  987. m_DoseUnit.m_MS->Update(tmpms);
  988. FireNotify(AttrKey::MS, m_DoseUnit.m_MS->JSGet());
  989. //mx
  990. tmpbuf[0] = '0';
  991. tmpbuf[1] = value[24];
  992. tmpbuf[2] = value[25];
  993. tmpbuf[3] = value[26];
  994. tmpbuf[4] = value[27];
  995. tmpbuf[5] = value[28];
  996. tmpbuf[6] = value[29];
  997. tmpmx = atof(tmpbuf) / 100.0;
  998. m_DoseUnit.m_MAS->Update(tmpmx);
  999. FireNotify(AttrKey::MAS, m_DoseUnit.m_MAS->JSGet());
  1000. //mLog::FINFO("tmpkv={$} tmpma={$}, tmpms={$}, tmpmx={$};", tmpkv, tmpma, tmpms, tmpmx);
  1001. }
  1002. else
  1003. {
  1004. if (m_DoseUnit.m_KV->Update(atof(value)))
  1005. {
  1006. FireNotify(AttrKey::KV, m_DoseUnit.m_KV->JSGet());
  1007. }
  1008. }
  1009. };
  1010. auto HWMAS = [this](const char* value, int length)
  1011. {
  1012. assert(value);
  1013. float fmas = atof(value) / 100.0;
  1014. if (m_DoseUnit.m_MAS->Update(fmas))
  1015. FireNotify(AttrKey::MAS, m_DoseUnit.m_MAS->JSGet());
  1016. };
  1017. auto HWMA = [this](const char* value, int length)
  1018. {
  1019. assert(value);
  1020. float fma = atof(value) / 10.0;
  1021. if (m_DoseUnit.m_MA->Update(fma))
  1022. {
  1023. FireNotify(AttrKey::MA, m_DoseUnit.m_MA->JSGet());
  1024. }
  1025. };
  1026. auto HWMS = [this](const char* value, int length)
  1027. {
  1028. assert(value);
  1029. float fms = atof(value) / 100.0;
  1030. if (m_DoseUnit.m_MS->Update(fms))
  1031. FireNotify(AttrKey::MS, m_DoseUnit.m_MS->JSGet());
  1032. };
  1033. auto HWVP = [this](const char* value, int length)
  1034. {
  1035. assert(value);
  1036. m_DoseUnit.m_PostKV->Update(atof(value));
  1037. FireNotify(AttrKey::POSTKV, m_DoseUnit.m_PostKV->JSGet());
  1038. //mLog::FINFO("Actual exposure parameters KV:{$}", m_DoseUnit.m_PostKV->JSGet().c_str());
  1039. };
  1040. auto HWPA = [this](const char* value, int length)
  1041. {
  1042. assert(value);
  1043. float fma = atof(value) / 10.0;
  1044. m_DoseUnit.m_PostMA->Update(fma);
  1045. FireNotify(AttrKey::POSTMA, m_DoseUnit.m_PostMA->JSGet());
  1046. //mLog::FINFO("Actual exposure parameters MA:{$}", m_DoseUnit.m_PostMA->JSGet().c_str());
  1047. };
  1048. auto HWAP = [this](const char* value, int length)
  1049. {
  1050. assert(value);
  1051. float fmas = atof(value) / 100.0;
  1052. m_DoseUnit.m_PostMAS->Update(fmas);
  1053. FireNotify(AttrKey::POSTMAS, m_DoseUnit.m_PostMAS->JSGet());
  1054. //mLog::FINFO("Actual exposure parameters MAS:{$}", m_DoseUnit.m_PostMAS->JSGet().c_str());
  1055. };
  1056. auto HWFocus = [this](const char* value, int length)
  1057. {
  1058. assert(value);
  1059. int nfous = atoi(value);
  1060. if (m_DoseUnit.m_Focus->Update(nfous))
  1061. FireNotify(AttrKey::FOCUS, m_DoseUnit.m_Focus->JSGet());
  1062. //mLog::FINFO("Current focus:{$}, FO={$}", atoi(m_DoseUnit.m_Focus->JSGet().c_str()) ? "large focus" : "small focus", m_DoseUnit.m_Focus->JSGet().c_str());
  1063. };
  1064. auto HWTechmode = [this](const char* value, int length)
  1065. {
  1066. assert(value);
  1067. int ntechmode = atoi(value);
  1068. m_DoseUnit.m_Techmode->Update(ntechmode);
  1069. FireNotify(AttrKey::TECHMODE, m_DoseUnit.m_Techmode->JSGet());
  1070. switch (ntechmode)
  1071. {
  1072. case 0:
  1073. //mLog::FINFO("ET={$}", "mA/ms",m_DoseUnit.m_Techmode->JSGet().c_str());
  1074. break;
  1075. case 1:
  1076. //mLog::FINFO("ET={$}", "mAs", m_DoseUnit.m_Techmode->JSGet().c_str());
  1077. break;
  1078. case 2:
  1079. //mLog::FINFO("ET={$}", "AEC / mA", m_DoseUnit.m_Techmode->JSGet().c_str());
  1080. break;
  1081. case 3:
  1082. //mLog::FINFO("ET={$}", "mAs / ms", m_DoseUnit.m_Techmode->JSGet().c_str());
  1083. break;
  1084. case 4:
  1085. //mLog::FINFO("ET={$}", "AEC", m_DoseUnit.m_Techmode->JSGet().c_str());
  1086. break;
  1087. }
  1088. };
  1089. auto HWAECField = [this](const char* value, int length)
  1090. {
  1091. assert(value);
  1092. int nvalue = atoi(value);
  1093. if (m_DoseUnit.m_AECField->Update(nvalue))
  1094. FireNotify(AttrKey::AECFIELD, m_DoseUnit.m_AECField->JSGet());
  1095. };
  1096. auto HWAECFilm = [this](const char* value, int length)
  1097. {
  1098. assert(value);
  1099. if (m_DoseUnit.m_AECFilm->Update(atoi(value)))
  1100. FireNotify(AttrKey::AECFILM, m_DoseUnit.m_AECFilm->JSGet());
  1101. };
  1102. auto HWAECDensity = [this](const char* value, int length)
  1103. {
  1104. assert(value);
  1105. if (m_DoseUnit.m_AECDensity->Update(atoi(value)))
  1106. FireNotify(AttrKey::AECDENSITY, m_DoseUnit.m_AECDensity->JSGet());
  1107. };
  1108. auto HWWS = [this](const char* value, int length)
  1109. {
  1110. assert(value);
  1111. int nValue = atoi(value);
  1112. m_DoseUnit.m_WS->Update(nValue);
  1113. {
  1114. FireNotify(m_DoseUnit.m_WS->GetKey(), m_DoseUnit.m_WS->JSGet());
  1115. }
  1116. };
  1117. auto HWPR = [this](const char* value, int length)
  1118. {
  1119. assert(value);
  1120. int nValue = atoi(value);
  1121. if (nValue == 2)
  1122. {
  1123. }
  1124. else if (nValue == 1)
  1125. {
  1126. if (m_iLoopTime != PSGHR_LoopExpHBTime)
  1127. {
  1128. //mLog::Debug("quicken loopTime[{$}]->[{$}]", m_iLoopTime.load(), PSGHR_LoopExpHBTime);
  1129. m_iLoopTime = PSGHR_LoopExpHBTime;
  1130. }
  1131. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_PREPARE);
  1132. //mLog::FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
  1133. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1134. }
  1135. else if (nValue == 0)
  1136. {
  1137. if (m_iLoopTime == PSGHR_LoopExpHBTime)
  1138. {
  1139. if ((int)m_GenConfig["loopTime"] >= 100)
  1140. {
  1141. m_iLoopTime = (int)m_GenConfig["loopTime"];
  1142. }
  1143. else
  1144. m_iLoopTime = PSGHR_LoopDefHBTime;
  1145. //mLog::Debug("reduction loopTime[{$}]->[{$}]", PSGHR_LoopExpHBTime, m_iLoopTime.load());
  1146. }
  1147. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF);
  1148. //mLog::FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
  1149. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1150. m_bGenBusy = false;
  1151. RefreshData();
  1152. }
  1153. };
  1154. auto HWXR = [this](const char* value, int length)
  1155. {
  1156. assert(value);
  1157. int nValue = atoi(value);
  1158. if (nValue == 2)
  1159. {
  1160. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON);
  1161. //mLog::FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
  1162. Sleep(50);
  1163. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1164. }
  1165. else if (nValue == 1)
  1166. {
  1167. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_READY);
  1168. m_hGenPostEvent->ResetEvent();
  1169. //mLog::FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
  1170. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1171. }
  1172. else if (nValue == 0)
  1173. {
  1174. m_bGenBusy = false;
  1175. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYOFF);
  1176. //mLog::FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
  1177. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1178. }
  1179. };
  1180. auto HWAPDOSE = [this](const char* value, int length)//post mas
  1181. {
  1182. assert(value);
  1183. m_DoseUnit.m_PostMAS->Update(atof(value) / 100.0);
  1184. FireNotify(m_DoseUnit.m_PostMAS->GetKey(), m_DoseUnit.m_PostMAS->JSGet());
  1185. //mLog::FINFO("Actual exposure parameters MAS:{$}", m_DoseUnit.m_PostMAS->JSGet().c_str());
  1186. };
  1187. auto HWATDOSE = [this](const char* value, int length)
  1188. {
  1189. assert(value);
  1190. m_DoseUnit.m_PostMS->Update(atof(value) / 100.0);
  1191. FireNotify(m_DoseUnit.m_PostMS->GetKey(), m_DoseUnit.m_PostMS->JSGet());
  1192. //mLog::FINFO("Actual exposure parameters MS:{$}", m_DoseUnit.m_PostMS->JSGet().c_str());
  1193. };
  1194. auto HWDAP = [this](const char* value, int length)
  1195. {
  1196. assert(value);
  1197. //mLog::FINFO("Recv DAP ={$}", atof(value) / 100.0);
  1198. };
  1199. auto HWEHE = [this](const char* value, int length)
  1200. {
  1201. m_iHeartBeats = 0;
  1202. assert(value);
  1203. int nhe = atoi(value);
  1204. if (m_DoseUnit.m_HE->Update(nhe))
  1205. FireNotify(m_DoseUnit.m_HE->GetKey(), m_DoseUnit.m_HE->JSGet());
  1206. };
  1207. auto HWHH = [this](const char* value, int length)
  1208. {
  1209. m_iHeartBeats = 0;
  1210. assert(value);
  1211. int nhe = atoi(value);
  1212. if (m_DoseUnit.m_GenHE->Update(nhe))
  1213. FireNotify(m_DoseUnit.m_GenHE->GetKey(), m_DoseUnit.m_GenHE->JSGet());
  1214. };
  1215. //04 FLM00010 FLI000 FLT000 FLF1 FLA0 FLS060 FLD0 FLO0 FLC1 FLW00400
  1216. //040 FLM00010 FLI000 FLT000 FLF1 FLA0 FLS060 FLD0 FLO0 FLC1 FLW00400
  1217. auto HWFLK = [this](const char* value, int length)
  1218. {
  1219. assert(value);
  1220. if (length == 46) // Check if length is more than 20
  1221. {
  1222. int tmpflk, tmpflf, tmpfla, tmpfld, tmpflo;
  1223. float tmpflm, tmpfli, tmpflt, tmpfls, tmpflw;
  1224. char tmpbuf[5]{ 0, 0, 0, 0, 0 };
  1225. //flk
  1226. tmpbuf[0] = value[0];
  1227. tmpbuf[1] = value[1];
  1228. tmpbuf[2] = value[2];
  1229. tmpflk = atoi(tmpbuf);
  1230. if (m_DoseUnit.m_FLKV->Update(tmpflk))
  1231. FireNotify(AttrKey::FLUKV, m_DoseUnit.m_FLKV->JSGet());
  1232. // flm
  1233. tmpbuf[0] = value[7];
  1234. tmpbuf[1] = value[8];
  1235. tmpbuf[2] = value[9];
  1236. tmpbuf[3] = value[10];
  1237. tmpbuf[4] = value[11];
  1238. tmpflm = atof(tmpbuf) / 10.0;
  1239. if (m_DoseUnit.m_FLMA->Update(tmpflm))
  1240. FireNotify(AttrKey::FLUMA, m_DoseUnit.m_FLMA->JSGet());
  1241. // fli
  1242. tmpbuf[0] = value[16];
  1243. tmpbuf[1] = value[17];
  1244. tmpbuf[2] = value[18];
  1245. tmpbuf[3] = 0;
  1246. tmpbuf[4] = 0;
  1247. tmpfli = atof(tmpbuf) / 10.0;
  1248. if (m_DoseUnit.m_FLIntTime->Update(tmpfli))
  1249. FireNotify(AttrKey::FLUIntTime, m_DoseUnit.m_FLIntTime->JSGet());
  1250. // flt
  1251. tmpbuf[0] = value[23];
  1252. tmpbuf[1] = value[24];
  1253. tmpbuf[2] = value[25];
  1254. tmpbuf[3] = 0;
  1255. tmpbuf[4] = 0;
  1256. tmpflt = atof(tmpbuf) / 10.0;
  1257. if (m_DoseUnit.m_FLAccTime->Update(tmpflt))
  1258. FireNotify(AttrKey::FLUAccTime, m_DoseUnit.m_FLAccTime->JSGet());
  1259. // flf
  1260. tmpbuf[0] = value[30];
  1261. tmpbuf[1] = 0;
  1262. tmpbuf[2] = 0;
  1263. tmpflf = atoi(tmpbuf);
  1264. if (m_DoseUnit.m_FLMode->Update(tmpflf))
  1265. FireNotify(AttrKey::FLUMode, m_DoseUnit.m_FLMode->JSGet());
  1266. // fla
  1267. tmpbuf[0] = value[35];
  1268. tmpbuf[1] = 0;
  1269. tmpbuf[2] = 0;
  1270. tmpfla = atoi(tmpbuf);
  1271. if (m_DoseUnit.m_ABSStatus->Update(tmpfla))
  1272. FireNotify(AttrKey::FLUABSStatus, m_DoseUnit.m_ABSStatus->JSGet());
  1273. // fls
  1274. tmpbuf[0] = value[40];
  1275. tmpbuf[1] = value[41];
  1276. tmpbuf[2] = value[42];
  1277. tmpfls = atof(tmpbuf) / 10.0;
  1278. if (m_DoseUnit.m_PPS->Update(tmpfls))
  1279. FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
  1280. // fld
  1281. tmpbuf[0] = value[47];
  1282. tmpbuf[1] = 0;
  1283. tmpbuf[2] = 0;
  1284. tmpfld = atoi(tmpbuf);
  1285. if (m_DoseUnit.m_DoseLevel->Update(tmpfld))
  1286. FireNotify(AttrKey::FLUDoseLevel, m_DoseUnit.m_DoseLevel->JSGet());
  1287. // flo
  1288. tmpbuf[0] = value[52];
  1289. tmpbuf[1] = 0;
  1290. tmpbuf[2] = 0;
  1291. tmpflo = atoi(tmpbuf);
  1292. if (m_DoseUnit.m_Curve->Update(tmpflo))
  1293. FireNotify(AttrKey::FLUCurve, m_DoseUnit.m_Curve->JSGet());
  1294. // flw
  1295. tmpbuf[0] = value[62];
  1296. tmpbuf[1] = value[63];
  1297. tmpbuf[2] = value[64];
  1298. tmpbuf[3] = value[65];
  1299. tmpbuf[4] = value[66];
  1300. tmpflw = atof(tmpbuf) / 100.0;
  1301. if (m_DoseUnit.m_FLMS->Update(tmpflw))
  1302. FireNotify(AttrKey::FLUMS, m_DoseUnit.m_FLMS->JSGet());
  1303. //mLog::FINFO("tmpflk={$}, tmpflf={$}, tmpfla={$}, tmpfld={$}, tmpflo={$}, tmpflm={$}, tmpfli={$}, tmpflt={$}, tmpfls={$}, tmpflw={$};", tmpflk, tmpflf, tmpfla, tmpfld, tmpflo, tmpflm, tmpfli, tmpflt, tmpfls, tmpflw);
  1304. }
  1305. else
  1306. {
  1307. int tmpflkv = atoi(value);
  1308. if (m_DoseUnit.m_FLKV->Update(tmpflkv))
  1309. {
  1310. FireNotify(AttrKey::FLUKV, m_DoseUnit.m_FLKV->JSGet());
  1311. }
  1312. }
  1313. };
  1314. auto HWFLM = [this](const char* value, int length)
  1315. {
  1316. assert(value);
  1317. float tmpflm = atof(value) / 10.0;
  1318. if (m_DoseUnit.m_FLMA->Update(tmpflm))
  1319. FireNotify(AttrKey::FLUMA, m_DoseUnit.m_FLMA->JSGet());
  1320. };
  1321. auto HWFLW = [this](const char* value, int length)
  1322. {
  1323. assert(value);
  1324. float tmpflms = atof(value) / 100.0;
  1325. if (m_DoseUnit.m_FLMS->Update(tmpflms))
  1326. FireNotify(AttrKey::FLUMS, m_DoseUnit.m_FLMS->JSGet());
  1327. };
  1328. auto HWFLI = [this](const char* value, int length)
  1329. {
  1330. assert(value);
  1331. float tmpfli = atof(value) / 10.0;
  1332. if (m_DoseUnit.m_FLIntTime->Update(tmpfli))
  1333. FireNotify(AttrKey::FLUIntTime, m_DoseUnit.m_FLIntTime->JSGet());
  1334. };
  1335. auto HWFLT = [this](const char* value, int length)
  1336. {
  1337. assert(value);
  1338. float tmpflt = atof(value) / 10.0;
  1339. if (m_DoseUnit.m_FLAccTime->Update(tmpflt))
  1340. FireNotify(AttrKey::FLUAccTime, m_DoseUnit.m_FLAccTime->JSGet());
  1341. };
  1342. auto HWFLS = [this](const char* value, int length)
  1343. {
  1344. assert(value);
  1345. float tmppps = atof(value) / 10.0;
  1346. if (m_DoseUnit.m_PPS->Update(tmppps))
  1347. FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
  1348. };
  1349. auto HWFLF = [this](const char* value, int length)
  1350. {
  1351. assert(value);
  1352. //mLog::FINFO("m_FLMode={$};", value);
  1353. int tmpflf = atoi(value);
  1354. if (m_DoseUnit.m_FLMode->Update(tmpflf))
  1355. FireNotify(AttrKey::FLUMode, m_DoseUnit.m_FLMode->JSGet());
  1356. };
  1357. auto HWFLX = [this](const char* value, int length)
  1358. {
  1359. assert(value);
  1360. int nValue = atoi(value);
  1361. if (nValue == 2)
  1362. {
  1363. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_XRAYON);
  1364. //mLog::FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
  1365. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1366. }
  1367. else if (nValue == 1)
  1368. {
  1369. //mLog::FINFO("Recv FLX1, do nothing");
  1370. }
  1371. else if (nValue == 0)
  1372. {
  1373. m_bGenBusy = false;
  1374. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_XRAYOFF);
  1375. //mLog::FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
  1376. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1377. }
  1378. };
  1379. auto HWFLP = [this](const char* value, int length)
  1380. {
  1381. assert(value);
  1382. int nValue = atoi(value);
  1383. if (nValue == 2)
  1384. {
  1385. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_READY);
  1386. //mLog::FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
  1387. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1388. }
  1389. else if (nValue == 1)
  1390. {
  1391. if (m_iLoopTime != PSGHR_LoopExpHBTime)
  1392. {
  1393. //mLog::Debug("quicken loopTime[{$}]->[{$}]", m_iLoopTime.load(), PSGHR_LoopExpHBTime);
  1394. m_iLoopTime = PSGHR_LoopExpHBTime;
  1395. }
  1396. //mLog::FINFO("Recv FLP1, do nothing\n");
  1397. }
  1398. else if (nValue == 0)
  1399. {
  1400. if (m_iLoopTime == PSGHR_LoopExpHBTime)
  1401. {
  1402. if ((int)m_GenConfig["loopTime"] >= 100)
  1403. {
  1404. m_iLoopTime = (int)m_GenConfig["loopTime"];
  1405. }
  1406. else
  1407. m_iLoopTime = PSGHR_LoopDefHBTime;
  1408. //mLog::Debug("reduction loopTime[{$}]->[{$}]", PSGHR_LoopExpHBTime, m_iLoopTime.load());
  1409. }
  1410. int nFlFMode = atoi(m_DoseUnit.m_FLMode->JSGet().c_str());
  1411. //mLog::FINFO("m_DoseUnit.m_FLMode={$}- number ={$};", m_DoseUnit.m_FLMode->JSGet().c_str(), nFlFMode);
  1412. if (nFlFMode == 2)
  1413. {
  1414. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_XRAYOFF);
  1415. //mLog::FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
  1416. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1417. }
  1418. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_OFF);
  1419. //mLog::FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
  1420. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1421. m_bGenBusy = false;
  1422. RefreshData();
  1423. }
  1424. };
  1425. auto HWDS = [this](const char* value, int length)
  1426. {
  1427. assert(value);
  1428. };
  1429. auto HWFLA = [this](const char* value, int length)
  1430. {
  1431. assert(value);
  1432. int tmpfla = atoi(value);
  1433. if ( m_DoseUnit.m_ABSStatus->Update(tmpfla))
  1434. FireNotify(AttrKey::FLUABSStatus, m_DoseUnit.m_ABSStatus->JSGet());
  1435. };
  1436. auto HWFLD = [this](const char* value, int length)
  1437. {
  1438. assert(value);
  1439. };
  1440. auto HWFLC= [this](const char* value, int length)
  1441. {
  1442. assert(value);
  1443. };
  1444. auto HWFLO = [this](const char* value, int length)
  1445. {
  1446. assert(value);
  1447. int nValue = atoi(value);
  1448. if (m_DoseUnit.m_Curve->Update(nValue))
  1449. FireNotify(AttrKey::FLUCurve, m_DoseUnit.m_Curve->JSGet());
  1450. };
  1451. auto HWER = [this](const char* value, int length)
  1452. {
  1453. assert(value);
  1454. int nValue = atoi(value);
  1455. char tmpbuf[4] = { 0,0,0,0 };
  1456. tmpbuf[0] = value[0];
  1457. tmpbuf[1] = value[1];
  1458. tmpbuf[2] = value[2];
  1459. if (nValue != 0)
  1460. {
  1461. std::unordered_map<std::string, std::string> errorMessages = {
  1462. {"100", "AEC Back-up Timer - Exposure Terminated"},
  1463. {"101", "AEC mAs Exceeded - Exposure Terminated"},
  1464. {"102", "Door Interlock Error"},
  1465. {"103", "Calibration Data Corrupt Error"},
  1466. {"104", "AEC Data Corrupt Error"},
  1467. {"105", "Receptor Data Corrupt Error"},
  1468. {"106", "Tube Data Corrupt Error"},
  1469. {"107", "Generator Limit Data Corrupt Error"},
  1470. {"108", "mA Correction Data Corrupt Error"},
  1471. {"109", "Not Enabled Error"},
  1472. {"110", "AEC Feedback Error - No Feedback Signal Detected"},
  1473. {"111", "EXP_SW Signal Active in Standby State"},
  1474. {"112", "Calibration Error - No mA"},
  1475. {"113", "Calibration Error - Maximum Filament Current Exceeded"},
  1476. {"114", "MA During Exposure too High"},
  1477. {"115", "MA During Exposure too Low"},
  1478. {"116", "Generator KW Limit"},
  1479. {"117", "Generator KV Limit"},
  1480. {"118", "Generator MA Limit"},
  1481. {"119", "Generator MS Limit"},
  1482. {"120", "Generator MAS Limit"},
  1483. {"121", "Tube KW Limit"},
  1484. {"122", "Tube KV Limit"},
  1485. {"123", "Tube MA Limit"},
  1486. {"124", "Tube MAS Limit"},
  1487. {"125", "Parameter Limit"},
  1488. {"126", "Manually Terminated Exposure"},
  1489. {"127", "Preparation Time-out Error prep time is over 30s or 60s"},
  1490. {"128", "Prep Input Active During Initialization Phase"},
  1491. {"129", "X-ray Input Active During Initialization Phase"},
  1492. {"130", "No Fields Selected in AEC mode"},
  1493. {"131", "Generator AEC Density Limit"},
  1494. {"132", "Calibration Error - Manually Terminated"},
  1495. {"133", "EEPROM Communication Error"},
  1496. {"134", "RTC Communication Error"},
  1497. {"135", "AEC Channel Error"},
  1498. {"136", "Anode Communication Error"},
  1499. {"137", "EXP_OK TimeOut"},
  1500. {"138", "KV TimeOut"},
  1501. {"139", "Mosfet Temperature Limit Exceeded"},
  1502. {"140", "HU Power Limit"},
  1503. {"141", "HU Power Warning"},
  1504. {"142", "Small Focus Disable"},
  1505. {"143", "Large Focus Disable"},
  1506. {"144", "Low Speed Disable"},
  1507. {"145", "High Speed Disable"},
  1508. {"146", "Anode Heat Warning Exceeded"},
  1509. {"147", "Anode Heat Limit Exceeded"},
  1510. {"148", "KV Unbalance"},
  1511. {"149", "Thermal Switch Interlock Error"},
  1512. {"150", "Emergency Error"},
  1513. {"151", "KV Correction Data Corrupt Error"},
  1514. {"152", "Generator Tank Power Limit"},
  1515. {"153", "AEC Standby Signal Error"},
  1516. {"154", "DCBUS Calibration Data Corrupt Error"},
  1517. {"155", "Fluoro Timer Terminated "},
  1518. {"156", "Fluoro Timer Terminated "},
  1519. {"157", "Power Off In X - Ray State"},
  1520. {"158", "DAP Data Corrupt "},
  1521. {"159", "Auto APR TimeOut "},
  1522. {"160", "ERR_FLUORO_ABSFDBNONE"},
  1523. {"200", "FLASH LOCK"},
  1524. {"201", "FLASH REVID_INVALID"},
  1525. {"202", "FLASH ADDR_INVALID"},
  1526. {"203", "FLASH INCORRECT_PARTID"},
  1527. {"204", "FLASH API_SILICON_MISMATCH"},
  1528. {"205", "FLASH ERASE ERROR"},
  1529. {"206", "FLASH FAIL_PROGRAM"},
  1530. {"207", "FLASH FAIL_ZERO_BIT_ERROR"},
  1531. {"208", "FLASH FAIL_VERIFY"},
  1532. {"209", "FLASH BUSY"},
  1533. {"210", "FLASH_PROGRM_ADDR_ERROR"},
  1534. {"211", "UPDATA_VERSION_ERROR"},
  1535. {"212", "UPDATA SN_ERROR"},
  1536. {"213", "UPDATA_BYTE_COUNT_ERROR"},
  1537. {"214", "UPDATA_CHECKSUM_ERROR"}
  1538. };
  1539. char ErrorCode[20];
  1540. snprintf(ErrorCode, sizeof(ErrorCode), "PSGHR_ER_%d", nValue);
  1541. char temp[50] = { 0 };
  1542. snprintf(temp, sizeof(temp), "ER%03d", nValue);
  1543. HWSend(temp, strlen(temp));
  1544. int level = 1;
  1545. auto it = errorMessages.find(tmpbuf);
  1546. if (it != errorMessages.end())
  1547. {
  1548. m_MSGUnit->AddWarnMessage(ErrorCode, level, it->second.c_str());
  1549. }
  1550. }
  1551. else
  1552. {
  1553. int level = 1;
  1554. char ErrorCode[20];
  1555. m_MSGUnit->DelWarnMessage(ErrorCode, level, "");
  1556. }
  1557. };
  1558. auto HWEL = [this](const char* value, int length)
  1559. {
  1560. assert(value);
  1561. int nValue = atoi(value);
  1562. char tmpbuf[3] = { 0,0,0 };
  1563. tmpbuf[0] = value[0];
  1564. tmpbuf[1] = value[1];
  1565. tmpbuf[2] = value[2];
  1566. if (nValue != 0)
  1567. {
  1568. std::unordered_map<std::string, std::string> errorMessages = {
  1569. {"001", "Generator CPU Real Time Clock Error"},
  1570. {"002", "Main Contactor Error"},
  1571. {"003", "Rotor Fault"},
  1572. {"004", "DC Bus Voltage too Low"},
  1573. {"005", "DC Bus Voltage too High"},
  1574. {"006", "Filament Adjust Error"},
  1575. {"007", "Filament PowerBoard Not Connected"},
  1576. {"008", "Filament Short Circuit"},
  1577. {"019", "Filament Overcurrent"},
  1578. {"010", "Anode Overcurrent"},
  1579. {"011", "Cathode Overcurrent"},
  1580. {"012", "Anode Overvoltage"},
  1581. {"013", "Cathode Overvoltage"},
  1582. {"014", "ARC"},
  1583. {"015", "Short Current 1"},
  1584. {"016", "Short Current 2"},
  1585. {"017", "Short Current A"},
  1586. {"018", "Short Current B"}
  1587. };
  1588. char ErrorCode[20];
  1589. snprintf(ErrorCode, sizeof(ErrorCode), "PSGHR_EL_%d", nValue);
  1590. char temp[50] = { 0 };
  1591. snprintf(temp, sizeof(temp), "EL%03d", nValue);
  1592. HWSend(temp, strlen(temp));
  1593. int level = 1;
  1594. auto it = errorMessages.find(tmpbuf);
  1595. if (it != errorMessages.end())
  1596. {
  1597. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR);
  1598. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1599. m_MSGUnit->AddErrorMessage(ErrorCode, level, it->second.c_str());
  1600. }
  1601. }
  1602. else
  1603. {
  1604. int level = 1;
  1605. char ErrorCode[20];
  1606. m_MSGUnit->DelErrorMessage(ErrorCode, level, "");
  1607. }
  1608. };
  1609. auto HWEI = [this](const char* value, int length)
  1610. {
  1611. assert(value);
  1612. int nValue = atoi(value);
  1613. char tmpbuf[3] = { 0,0,0 };
  1614. tmpbuf[0] = value[0];
  1615. tmpbuf[1] = value[1];
  1616. tmpbuf[2] = value[2];
  1617. if (nValue != 0)
  1618. {
  1619. std::unordered_map<std::string, std::string> errorMessages = {
  1620. {"400", "Enter the service mode"},
  1621. {"401", "Exit the service mode"},
  1622. {"402", "Resonance Overcurrent1"},
  1623. {"403", "Resonance Overcurrent2"},
  1624. {"404", "Resonance Overcurrent3"},
  1625. {"405", "Charging, Please Wait "},
  1626. {"406", "DAC Reset "},
  1627. {"407", "X-Rays State PowerOff "},
  1628. {"408", "Fluoro Disable "},
  1629. {"409", "Fluoro Timer Warning Level Exceeded"},
  1630. {"410", "Anode Heat Warning Exceeded "},
  1631. {"411", "MA Too Low "}
  1632. };
  1633. char ErrorCode[20];
  1634. snprintf(ErrorCode, sizeof(ErrorCode), "PSGHR_EI_%d", nValue);
  1635. char temp[50] = { 0 };
  1636. snprintf(temp, sizeof(temp), "EI%03d", nValue);
  1637. HWSend(temp, strlen(temp));
  1638. int level = 1;
  1639. auto it = errorMessages.find(tmpbuf);
  1640. if (it != errorMessages.end())
  1641. {
  1642. //m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR);
  1643. //FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1644. m_MSGUnit->AddWarnMessage(ErrorCode, level, it->second.c_str());
  1645. }
  1646. }
  1647. else
  1648. {
  1649. int level = 1;
  1650. char ErrorCode[20];
  1651. m_MSGUnit->DelWarnMessage(ErrorCode, level, "");
  1652. }
  1653. };
  1654. auto HWMSG = [this](const char* value, int length)
  1655. {
  1656. assert(value);
  1657. int nValue = atoi(value);
  1658. char tmpbuf[3] = { 0,0,0 };
  1659. tmpbuf[0] = value[0];
  1660. tmpbuf[1] = value[1];
  1661. tmpbuf[2] = value[2];
  1662. if (nValue != 0)
  1663. {
  1664. std::unordered_map<std::string, std::string> errorMessages = {
  1665. {"001", "Rotating anode protection parameters are incorrectly configured"},
  1666. {"002", "Press emergency stop of high voltage generator"},
  1667. {"003", "The first level hand brake is not triggered, and the second level hand brake is triggered"},
  1668. {"004", "The first level hand brake is pressed during the wake - up or startup process of the high - voltage generator."},
  1669. {"005", "The second level hand brake is pressed during the wake - up or startup process of the high - voltage generator."},
  1670. {"006", "Low battery power of the high - voltage generator, please recharge."},
  1671. {"007", "Anode thermal capacity exceeds the warning value."},
  1672. {"008", "Exposure time interval is too short, please wait for exposure."},
  1673. {"009", "Parameter adjustment is prohibited during exposure."},
  1674. {"010", "High - voltage generator is not ready, please confirm the status."},
  1675. {"011", "The oil tank temperature of the high - voltage generator exceeds the warning value."},
  1676. {"012", "Training cannot be conducted in this state."},
  1677. {"013", "The tube current of the high voltage generator is low."},
  1678. {"014", "The PFC module of the high voltage generator works abnormally."},
  1679. {"015", "Battery output power limits for high voltage generators."},
  1680. {"016", "The battery of the high voltage generator is charging."},
  1681. {"017", "The mA parameter of the high voltage generator exceeds the maximum tube value."},
  1682. {"018", "The kV parameter of the high voltage generator exceeds the limit value."},
  1683. {"019", "The mA parameter of the high voltage generator exceeds the limit value."},
  1684. {"020", "The ms parameter of the high voltage generator exceeds the limit value."},
  1685. {"021", "The mAs parameter of the high voltage generator exceeds the limit value."},
  1686. {"022", "Filament selection parameter exceeds the limit."},
  1687. {"023", "Anode rotation speed selection parameter exceeds the limit."},
  1688. {"024", "The exposure technical parameters of the high voltage generator exceed the limits."},
  1689. {"025", "AEC density parameter exceeds the limit."},
  1690. {"026", "AEC field selection parameter exceeds the limit."},
  1691. {"027", "AEC channel parameter exceeds the limit."},
  1692. {"028", "AEC sensitivity parameter exceeds the limit."},
  1693. {"029", "High - voltage generator power exceeds the limit."},
  1694. {"030", "Tube power exceeds the limit."},
  1695. {"031", "The frame rate parameter of the high voltage generator exceeds the limit value."},
  1696. {"032", "Exposure parameter exceeds the high - voltage generator energy storage limit."},
  1697. {"033", "High voltage generator battery pack alarm."},
  1698. {"035", "Foot brake signal is pressed during the wake - up or startup process of the high - voltage generator."},
  1699. {"036", "Cumulative fluoroscopy time alarm."},
  1700. {"037", "The console of the high voltage generator is not connected, please open the console."},
  1701. {"038", "Tube sleeve thermal capacity exceeds the warning value."},
  1702. {"049", "Bus voltage of the high - voltage generator exceeds the limit."},
  1703. {"050", "High - voltage generator does not support this exposure mode."},
  1704. {"051", "The rotation speed of the rotating anode does not meet the exposure requirements."},
  1705. {"052", "The second level hand brake is not pressed within the specified time."},
  1706. {"053", "Interlock 1 is effective during the exposure process of the high - voltage generator."},
  1707. {"054", "Timeout for feedback signal in flat panel mode."},
  1708. {"055", "The kV establishment timeout of the high voltage generator."},
  1709. {"056", "Anode thermal capacity exceeds the limit."},
  1710. {"057", "Filament calibration data abnormality."},
  1711. {"058", "Tube current is too low during training."},
  1712. {"059", "Release hand brake prematurely during exposure."},
  1713. {"060", "AEC feedback abnormality."},
  1714. {"061", "Inverter temperature of the high - voltage generator exceeds the limit."},
  1715. {"062", "kV is too low during exposure, exposure abnormality aborted."},
  1716. {"063", "kV is too high during exposure, exposure abnormality aborted."},
  1717. {"064", "Oil temperature of the high - voltage generator exceeds the limit."},
  1718. {"065", "Tube sleeve thermal capacity exceeds the limit."},
  1719. {"066", "The current exposure parameters of the high voltage generator exceed the heat capacity limit."},
  1720. {"068", "mA is too high during exposure, exposure abnormality aborted."},
  1721. {"069", "The DRVEN enable of the high voltage generator to establish a timeout."},
  1722. {"070", "Interruption in communication with the rotating anode."},
  1723. {"071", "Emergency stop is pressed during exposure."},
  1724. {"072", "The battery pack of the high voltage generator is faulty."},
  1725. {"073", "Resonant current exceeds the limit, exposure abnormality aborted(software)."},
  1726. {"074", "Anode kV exceeds the limit, exposure abnormality aborted(software)."},
  1727. {"075", "Cathode kV exceeds the limit, exposure abnormality aborted(software)."},
  1728. {"076", "Filament current exceeds the limit(software)."},
  1729. {"078", "Oil tank power limit of the high - voltage generator."},
  1730. {"080", "Deviation of anode kV and cathode kV exceeds the limit, exposure abnormality aborted."},
  1731. {"081", "Power exceeds the limit during exposure, exposure abnormality aborted."},
  1732. {"082", "The external synchronization signal of the high voltage generator has timed out."},
  1733. {"083", "Fan fault in high voltage generator."},
  1734. {"084", "High voltage generator InterLock1 effective."},
  1735. {"085", "High voltage generator InterLock2 effective."},
  1736. {"087", "Release foot brake prematurely during exposure."},
  1737. {"088", "Foot brake signal abnormality."},
  1738. {"089", "The DA chip of the high voltage generator is abnormal."},
  1739. {"090", "Timeout for cumulative fluoroscopy time."},
  1740. {"091", "The external discharge line of the high voltage generator enables the signal to timeout."},
  1741. {"092", "XRAYReady invalid."},
  1742. {"093", "High voltage generator during exposure interlock 2 effective."}
  1743. };
  1744. char ErrorCode[20];
  1745. snprintf(ErrorCode, sizeof(ErrorCode), "PSGHR_MSG_%d", nValue);
  1746. int level = 1;
  1747. /*char temp[50] = { 0 };
  1748. snprintf(temp, sizeof(temp), "MSG%03d", nValue);
  1749. HWSend(temp, strlen(temp));*/
  1750. auto it = errorMessages.find(tmpbuf);
  1751. if (it != errorMessages.end())
  1752. {
  1753. //mLog::FINFO("WarnCode: {$}, Level: {$}, ResInfo: {$}\n", ErrorCode, level, it->second.c_str());
  1754. m_MSGUnit->AddWarnMessage(ErrorCode, level, it->second.c_str());
  1755. }
  1756. }
  1757. else
  1758. {
  1759. int level = 1;
  1760. char WarnCode[20]{ "" };
  1761. m_MSGUnit->DelWarnMessage(WarnCode, level, "");
  1762. }
  1763. };
  1764. //==IN==:TU0 WS1 FO0 ET0 FI010 FS001 FN0 HE000
  1765. auto HWTU = [this](const char* value, int length) -> void
  1766. {
  1767. assert(value);
  1768. //mLog::FINFO("recv TU={$},len={$}", value, length);
  1769. char tmpbuf[3] = { 0,0,0 };
  1770. int tmpWS, tmpFO, tmpET, tmpField, tmpFilm, tmpDensity, tmpHE;
  1771. //ws
  1772. tmpbuf[0] = value[4];
  1773. tmpWS = atoi(tmpbuf);
  1774. m_DoseUnit.m_WS->Update(tmpWS);
  1775. {
  1776. FireNotify(m_DoseUnit.m_WS->GetKey(), m_DoseUnit.m_WS->JSGet());
  1777. }
  1778. //FO
  1779. tmpbuf[0] = value[8];
  1780. tmpFO = atoi(tmpbuf);
  1781. m_DoseUnit.m_Focus->Update(tmpFO);
  1782. FireNotify(AttrKey::FOCUS, m_DoseUnit.m_Focus->JSGet());
  1783. //mLog::FINFO("Current focus:{$}, FO={$}", atoi(m_DoseUnit.m_Focus->JSGet().c_str()) ? "large focus" : "small focus", m_DoseUnit.m_Focus->JSGet().c_str());
  1784. //ET
  1785. tmpbuf[0] = value[12];
  1786. tmpET = atoi(tmpbuf);
  1787. m_DoseUnit.m_Techmode->Update(tmpET);
  1788. FireNotify(AttrKey::TECHMODE, m_DoseUnit.m_Techmode->JSGet());
  1789. //FIELD
  1790. tmpbuf[0] = value[16];
  1791. tmpbuf[1] = value[17];
  1792. tmpbuf[2] = value[18];
  1793. tmpField = atoi(tmpbuf);
  1794. if (m_DoseUnit.m_AECField->Update(tmpField))
  1795. FireNotify(AttrKey::AECFIELD, m_DoseUnit.m_AECField->JSGet());
  1796. //Film
  1797. tmpbuf[0] = value[22];
  1798. tmpbuf[1] = value[23];
  1799. tmpbuf[2] = value[24];
  1800. tmpFilm = atoi(tmpbuf);
  1801. if (m_DoseUnit.m_AECFilm->Update(tmpFilm))
  1802. FireNotify(AttrKey::AECFILM, m_DoseUnit.m_AECFilm->JSGet());
  1803. //Density
  1804. tmpbuf[0] = value[29];
  1805. tmpbuf[1] = 0;
  1806. tmpbuf[2] = 0;
  1807. tmpDensity = atoi(tmpbuf);
  1808. if (m_DoseUnit.m_AECDensity->Update(tmpDensity))
  1809. FireNotify(AttrKey::AECDENSITY, m_DoseUnit.m_AECDensity->JSGet());
  1810. //HE
  1811. tmpbuf[0] = value[33];
  1812. tmpbuf[1] = value[34];
  1813. tmpbuf[2] = value[35];
  1814. tmpHE = atoi(tmpbuf);
  1815. m_DoseUnit.m_HE->Update(tmpHE);
  1816. FireNotify(m_DoseUnit.m_HE->GetKey(), m_DoseUnit.m_HE->JSGet());
  1817. //mLog::FINFO("parse tmpWS={$}, tmpFO={$}, tmpET={$}, tmpField={$}, tmpFilm={$}, tmpDensity={$}, tmpHE={$}", tmpWS, tmpFO, tmpET, tmpField, tmpFilm, tmpDensity, tmpHE);
  1818. };
  1819. auto HWST = [this](const char* value, int length)
  1820. {
  1821. assert(value);
  1822. int genStatus = atoi(value);
  1823. //mLog::FINFO("genStatus={$}", genStatus);
  1824. switch (genStatus)
  1825. {
  1826. case 1:
  1827. //初始化
  1828. //mLog::Debug("get Gen Status_1:GENSTATE {$} -> STATUS_INIT", m_DoseUnit.m_GenState->JSGet());
  1829. ///*if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_INIT))
  1830. // FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());*/
  1831. break;
  1832. case 2:
  1833. //mLog::Debug("get Gen Status_2:GENSTATE {$} -> STATUS_STANDBY", m_DoseUnit.m_GenState->JSGet());
  1834. if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY))
  1835. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1836. break;
  1837. case 3: // Rad Preparation Phase
  1838. /*//mLog::Debug("get Gen Status_3:RAD_OFF(PR0) -> RAD_PREPARE(PR1)");
  1839. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_PREPARE))
  1840. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());*/
  1841. if (m_iLoopTime != PSGHR_LoopExpHBTime) //加快查询时间
  1842. {
  1843. //mLog::Debug("get Gen Status_3:quicken loopTime[{$}]->[{$}]", m_iLoopTime.load(), PSGHR_LoopExpHBTime);
  1844. m_iLoopTime = PSGHR_LoopExpHBTime;
  1845. }
  1846. break;
  1847. case 4:
  1848. //mLog::Debug("get Gen Status_4:PREPARE(PR1) -> RAD_READY(PR2)");
  1849. /*if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_READY))
  1850. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());*/
  1851. break;
  1852. case 5:
  1853. //mLog::Debug("get Gen Status_5:RAD_READY(PR2) -> X-Ray On(XR2)");
  1854. if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_EXP))
  1855. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1856. /*if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_XRAYON))
  1857. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());*/
  1858. break;
  1859. case 6:
  1860. //mLog::Debug("get Gen Status_6:X-Ray On(XR2) -> X-Ray Off(XR0)");
  1861. /*if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_XRAYOFF))
  1862. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());*/
  1863. break;
  1864. case 7:
  1865. if (m_iLoopTime == PSGHR_LoopExpHBTime)
  1866. {
  1867. if ((int)m_GenConfig["loopTime"] >= 100)
  1868. {
  1869. m_iLoopTime = (int)m_GenConfig["loopTime"];
  1870. }
  1871. else
  1872. m_iLoopTime = PSGHR_LoopDefHBTime;
  1873. //mLog::Debug("reduction loopTime[{$}]->[{$}]", PSGHR_LoopExpHBTime, m_iLoopTime.load());
  1874. }
  1875. //mLog::Debug("get Gen Status_7:GENSTATE {$} -> STATUS_ERROR", m_DoseUnit.m_GenState->JSGet());
  1876. if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR))
  1877. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1878. break;
  1879. case 8:
  1880. //mLog::Debug("get Gen Status_8:in Calibration");
  1881. break;
  1882. default:
  1883. //mLog::Debug("get Gen Status:[{$}] unknown", genStatus);
  1884. break;
  1885. }
  1886. };
  1887. auto HWSR = [this](const char* value, int length)
  1888. {
  1889. assert(value);
  1890. int stopReason = atoi(value);
  1891. //mLog::FINFO("stopReason={$}", stopReason);
  1892. switch (stopReason)
  1893. {
  1894. case 0:
  1895. //mLog::Debug("Exposure stop reason:AEC feedback voltage is too low");
  1896. break;
  1897. case 5:
  1898. //mLog::Debug("Exposure stop reason: Stop exposure manually");
  1899. break;
  1900. case 6:
  1901. //mLog::Debug("Exposure stop reason: door lock open");
  1902. break;
  1903. case 7:
  1904. //mLog::Debug("Exposure stop reason:Bulb tube anode ignition");
  1905. break;
  1906. case 8:
  1907. //mLog::Debug("Exposure stop reason:Bulb cathode ignition");
  1908. break;
  1909. case 9:
  1910. //mLog::Debug("Exposure stop reason:The pipe is lit");
  1911. break;
  1912. case 10:
  1913. //mLog::Debug("Exposure stop reason:KV is too low or too high");
  1914. break;
  1915. case 11:
  1916. //mLog::Debug("Exposure stop reason:Ma too low");
  1917. break;
  1918. case 12:
  1919. //mLog::Debug("Exposure stop reason:Set ms reached");
  1920. break;
  1921. case 13:
  1922. //mLog::Debug("Exposure stop reason:Set mAs reached");
  1923. break;
  1924. case 14:
  1925. //mLog::Debug("Exposure stop reason:AEC dose reached");
  1926. break;
  1927. default:
  1928. //mLog::Debug("Exposure stop reason:default");
  1929. break;
  1930. }
  1931. };
  1932. arFrame.clear();
  1933. arFrame.push_back(tFrameMapping("EL", 2, HWEL));
  1934. arFrame.push_back(tFrameMapping("EI", 2, HWEI));
  1935. arFrame.push_back(tFrameMapping("ER", 2, HWER));
  1936. arFrame.push_back(tFrameMapping("MSG", 3, HWMSG));
  1937. arFrame.push_back(tFrameMapping("TU", 2, HWTU));
  1938. arFrame.push_back(tFrameMapping("EC", 2, HWNotProcess));
  1939. arFrame.push_back(tFrameMapping("PW", 2, HWNotProcess));
  1940. arFrame.push_back(tFrameMapping("KV", 2, HWKV));
  1941. arFrame.push_back(tFrameMapping("MX", 2, HWMAS));
  1942. arFrame.push_back(tFrameMapping("MA", 2, HWMA));
  1943. arFrame.push_back(tFrameMapping("MS", 2, HWMS));
  1944. arFrame.push_back(tFrameMapping("VP", 2, HWVP));
  1945. arFrame.push_back(tFrameMapping("PA", 2, HWPA));
  1946. arFrame.push_back(tFrameMapping("AP", 2, HWAPDOSE));
  1947. arFrame.push_back(tFrameMapping("ET", 2, HWTechmode));
  1948. arFrame.push_back(tFrameMapping("FO", 2, HWFocus));
  1949. arFrame.push_back(tFrameMapping("FI", 2, HWAECField));
  1950. arFrame.push_back(tFrameMapping("FS", 2, HWAECFilm));
  1951. arFrame.push_back(tFrameMapping("FN", 2, HWAECDensity));
  1952. arFrame.push_back(tFrameMapping("WS", 2, HWWS));
  1953. arFrame.push_back(tFrameMapping("PR", 2, HWPR));
  1954. arFrame.push_back(tFrameMapping("XR", 2, HWXR));
  1955. arFrame.push_back(tFrameMapping("AT", 2, HWATDOSE));
  1956. arFrame.push_back(tFrameMapping("FLK", 3, HWFLK));
  1957. arFrame.push_back(tFrameMapping("FLM", 3, HWFLM));
  1958. arFrame.push_back(tFrameMapping("FLW", 3, HWFLW));
  1959. arFrame.push_back(tFrameMapping("FLI", 3, HWFLI));
  1960. arFrame.push_back(tFrameMapping("FLT", 3, HWFLT));
  1961. arFrame.push_back(tFrameMapping("FLS", 3, HWFLS));
  1962. arFrame.push_back(tFrameMapping("FLF", 3, HWFLF));
  1963. arFrame.push_back(tFrameMapping("FLP", 3, HWFLP));
  1964. arFrame.push_back(tFrameMapping("FLX", 3, HWFLX));
  1965. arFrame.push_back(tFrameMapping("FLA", 3, HWFLA));
  1966. arFrame.push_back(tFrameMapping("FLD", 3, HWFLD));
  1967. arFrame.push_back(tFrameMapping("FLC", 3, HWFLD));
  1968. arFrame.push_back(tFrameMapping("FLO", 3, HWFLO));
  1969. arFrame.push_back(tFrameMapping("HE", 2, HWEHE));
  1970. arFrame.push_back(tFrameMapping("HH", 2, HWHH));
  1971. arFrame.push_back(tFrameMapping("DA", 2, HWDAP));
  1972. arFrame.push_back(tFrameMapping("DV", 2, HWDAP));
  1973. arFrame.push_back(tFrameMapping("DS", 2, HWDS));
  1974. arFrame.push_back(tFrameMapping("ST", 2, HWST));
  1975. arFrame.push_back(tFrameMapping("SR", 2, HWSR));
  1976. arFrame.push_back(tFrameMapping("P", 1, HWPR));
  1977. }
  1978. bool nsGEN::PSGHRDevice::ReConnect()
  1979. {
  1980. //mLog::FINFO("Enter PSG_reConnect");
  1981. m_SCF->Disconnect();
  1982. if (!pIODriver)
  1983. {
  1984. //mLog::FINFO("PSG_reConnect:Driver null");
  1985. }
  1986. else
  1987. {
  1988. // 需要将 pIODriver 转换为 PSGHRDriver*
  1989. PSGHRDriver* driver = dynamic_cast<PSGHRDriver*>(pIODriver.get());
  1990. if (driver && driver->ReConnection())
  1991. {
  1992. FireErrorMessage(false, 1, "lost Connect");
  1993. m_bConnectFlag = true;
  1994. //mLog::FINFO("PSG_reConnect success");
  1995. return true;
  1996. }
  1997. else
  1998. {
  1999. //mLog::FINFO("PSG_reConnect failed");
  2000. }
  2001. }
  2002. return false;
  2003. }
  2004. int nsGEN::PSGHRDevice::GridMSMargin()//发生器暂无此设置
  2005. {
  2006. return 0;
  2007. }
  2008. bool nsGEN::PSGHRDevice::CalculateAppropriateMA(float& inoutMAS, float& inoutMA, float& inoutMS)
  2009. {
  2010. //mLog::FINFO("Enter CalculateAppropriateMA:MAS[{$}],MA[{$}],MS[{$}]", inoutMAS, inoutMA, inoutMS);
  2011. if (m_DoseUnit.m_Focus->Get() == AttrKey::FOCUS_TYPE::FOCUS_LARGE)
  2012. {
  2013. m_iMaxPower = PSGHR_LARGE_POWER;
  2014. }
  2015. else
  2016. {
  2017. m_iMaxPower = PSGHR_SMALL_POWER;
  2018. }
  2019. int currKV = 0 , tempMA = 0, tempMS = 0;
  2020. currKV = m_DoseUnit.m_KV->Get();
  2021. tempMA = m_iMaxPower * 1000 / currKV;
  2022. //mLog::Debug("power[{$}]*1000 / KV[{$}] = MAX_MA[{$}]", m_iMaxPower, currKV, tempMA);
  2023. if (tempMA > PSGHR_MAX_MA)
  2024. {
  2025. tempMA = PSGHR_MAX_MA;
  2026. //mLog::Debug(" MAX_MA too big,be close to range_right[{$}]", tempMA);
  2027. }
  2028. else if (tempMA < PSGHR_MIN_MA)
  2029. {
  2030. //mLog::Warn(" MAX_MA too small,compute failed");
  2031. return false;
  2032. }
  2033. for (int i = tempMA;i >= PSGHR_MIN_MA; i--)
  2034. {
  2035. tempMS = inoutMAS * 1000.0 / i;
  2036. //mLog::Debug("MAS[{$}]*1000 / temp_MA[{$}] = temp_MS[{$}]", inoutMAS, i, tempMS);
  2037. }
  2038. //mLog::Debug("can not use MAS[{$}]compute Appropriate MA MS", inoutMAS);
  2039. return false;
  2040. }
  2041. void nsGEN::PSGHRDevice::ReSendFailedAction(string& cmdNum)//发生器暂无此设置
  2042. {
  2043. }
  2044. int nsGEN::PSGHRDevice::GetGenState()
  2045. {
  2046. if (m_DoseUnit.m_GenState != NULL)
  2047. {
  2048. return m_DoseUnit.m_GenState->Get();
  2049. }
  2050. else
  2051. {
  2052. return 0;
  2053. }
  2054. }
  2055. int nsGEN::PSGHRDevice::LoadConfig(string configfile)
  2056. {
  2057. //mLog::FINFO("=====================LoadConfig=========================");
  2058. // 检查文件是否存在
  2059. std::ifstream file(configfile);
  2060. if (!file) {
  2061. // 文件不存在,直接返回空的Connection对象
  2062. //mLog::FINFO("Config file does not exist: {$}", configfile.c_str());
  2063. return -1;
  2064. }
  2065. if (m_bIsConfigLoaded)
  2066. {
  2067. //mLog::FINFO("Configuration already loaded.");
  2068. return 0;
  2069. }
  2070. ResDataObject temp;
  2071. temp.loadFile(configfile.c_str());
  2072. m_GenConfig = temp["CONFIGURATION"];
  2073. TransJsonText(m_GenConfig);
  2074. if (m_GenConfig.GetKeyCount("loopEnable") > 0)
  2075. {
  2076. m_bExtraFlag = (int)m_GenConfig["loopEnable"];
  2077. }
  2078. if (m_GenConfig.GetKeyCount(ConfKey::CcosTubeInfo) > 0)
  2079. {
  2080. string tempValue = (string)m_GenConfig[ConfKey::CcosTubeInfo];
  2081. m_DoseUnit.m_TubeInfo.reset(new TUBEINFOMould(tempValue));
  2082. FireNotify(AttrKey::TUBEINFO, m_DoseUnit.m_TubeInfo->JSGet());
  2083. }
  2084. if (m_GenConfig.GetKeyCount(ConfKey::CcosFocusSmall) > 0)
  2085. {
  2086. float tempValue = (float)m_GenConfig[ConfKey::CcosFocusSmall];
  2087. m_DoseUnit.m_FocusSmall = tempValue;
  2088. }
  2089. if (m_GenConfig.GetKeyCount(ConfKey::CcosFocusLarge) > 0)
  2090. {
  2091. float tempValue = (float)m_GenConfig[ConfKey::CcosFocusLarge];
  2092. m_DoseUnit.m_FocusLarge = tempValue;
  2093. }
  2094. if (m_GenConfig.GetKeyCount("GenCtrlMode") > 0)
  2095. {
  2096. m_nCtlMode = (float)m_GenConfig["GenCtrlMode"];//default 2
  2097. float tempValue = (float)m_GenConfig[ConfKey::CcosFocusLarge];
  2098. }
  2099. if (m_GenConfig.GetKeyCount("USECECMD") > 0)
  2100. {
  2101. m_bUseCECmd = (bool)m_GenConfig["USECECMD"];
  2102. }
  2103. m_bIsConfigLoaded = true;
  2104. return 0;
  2105. }
  2106. bool nsGEN::PSGHRDevice::EnableBucky(int nbucky)
  2107. {
  2108. char temp[50]{ 0 };
  2109. snprintf(temp, sizeof(temp), "BU%1d", nbucky);
  2110. return HWSend(temp, strlen(temp));
  2111. }
  2112. bool nsGEN::PSGHRDevice::ECHO(void)
  2113. {
  2114. return HWSend("EC", 2);
  2115. }
  2116. bool nsGEN::PSGHRDevice::SetABSModeNative(int nMode)
  2117. {
  2118. char temp[50]{ 0 };
  2119. snprintf(temp, sizeof(temp), "FLA%1d", nMode);
  2120. return HWSend(temp, strlen(temp));
  2121. }
  2122. bool nsGEN::PSGHRDevice::StartHardwareStatusThread()
  2123. {
  2124. if (!m_pHardwareStatusThread.joinable())
  2125. {
  2126. m_pHardwareStatusThread = std::thread(HardwareStatusThread, this);
  2127. return true;
  2128. }
  2129. return false;
  2130. }
  2131. void PSGHRDevice::HardwareStatusThread(PSGHRDevice* pParam)
  2132. {
  2133. PSGHRDevice* pCurGen = pParam;
  2134. if (pCurGen == NULL)
  2135. {
  2136. return;
  2137. }
  2138. pCurGen->HeartBeatFlag = true;
  2139. int messageIndex = 0;
  2140. int currtTime = pCurGen->m_iLoopTime;
  2141. while (pCurGen->m_bExtraFlag)
  2142. {
  2143. currtTime = pCurGen->m_iLoopTime;
  2144. Sleep(currtTime);
  2145. if (messageIndex % 5 == 0)
  2146. {
  2147. pCurGen->HWSend("HE?", 3);
  2148. Sleep(100);
  2149. pCurGen->HWSend("ST?", 3);
  2150. }
  2151. messageIndex++;
  2152. }
  2153. }
  2154. //-----------------------------------------------------------------------------
  2155. // PSGHRDriver
  2156. //-----------------------------------------------------------------------------
  2157. nsGEN::PSGHRDriver::PSGHRDriver()
  2158. : m_scfWrapper(std::make_shared<SCFWrapper>())
  2159. {
  2160. m_pAttribute.reset(new ResDataObject());
  2161. m_pDescription.reset(new ResDataObject());
  2162. }
  2163. nsGEN::PSGHRDriver::~PSGHRDriver()
  2164. {
  2165. Disconnect();
  2166. //mLog::Close();
  2167. //mLog::gLogger = nullptr;
  2168. }
  2169. void nsGEN::PSGHRDriver::Prepare()
  2170. {
  2171. //string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Generator\Conf\Log4CPP.Config.GEN.xml)";
  2172. //Log4CPP::GlobalContext::Map::Set(ECOM::Utility::Hash("LogFileName"), "GEN.PSG_HR");
  2173. //auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
  2174. //mLog::gLogger = Log4CPP::LogManager::GetLogger("GEN.PSG_HR");
  2175. m_SCFDllName = GetConnectDLL(m_ConfigFileName);
  2176. //super::Prepare();
  2177. //mLog::FINFO("OK.");
  2178. }
  2179. std::string nsGEN::PSGHRDriver::DriverProbe()
  2180. {
  2181. //mLog::FINFO("DriverProbe in \n");
  2182. ResDataObject r_config, HardwareInfo;
  2183. if (r_config.loadFile(m_ConfigFileName.c_str()))
  2184. {
  2185. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  2186. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  2187. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  2188. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  2189. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  2190. }
  2191. else
  2192. {
  2193. HardwareInfo.add("MajorID", "Generator");
  2194. HardwareInfo.add("MinorID", "Dr");
  2195. HardwareInfo.add("VendorID", "PSGHR");
  2196. HardwareInfo.add("ProductID", "HF");
  2197. HardwareInfo.add("SerialID", "Drv");
  2198. }
  2199. string ret = HardwareInfo.encode();
  2200. return ret;
  2201. }
  2202. bool nsGEN::PSGHRDriver::ReConnection()
  2203. {
  2204. Disconnect();
  2205. //mLog::FINFO("ReConnection:SCF Disconnect");
  2206. ResDataObject Connection = GetConnectParam(m_ConfigFileName);
  2207. //mLog::FINFO("ReConnection:{$} \n", Connection.encode());
  2208. auto erCode = m_scfWrapper->Connect(Connection, &PSGHRDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
  2209. if (erCode == SCF_SUCCEED)
  2210. {
  2211. Sleep(1000);
  2212. // 重新设置数据接收回调
  2213. m_scfWrapper->SetDataReceivedCallback([this](const char* data, uint32_t length) {
  2214. this->Dequeue(data, length);
  2215. });
  2216. // 启动自动接收
  2217. m_scfWrapper->StartAutoReceive();
  2218. return true;
  2219. }
  2220. else
  2221. {
  2222. //mLog::FINFO("ReConnection failed");
  2223. }
  2224. return false;
  2225. }
  2226. bool nsGEN::PSGHRDriver::Connect()
  2227. {
  2228. //mLog::FINFO("Enter {$},configlef={$}\n", __FUNCTION__, m_ConfigFileName.c_str());
  2229. ResDataObject Connection = GetConnectParam(m_ConfigFileName);
  2230. //mLog::FINFO("connections:{$} \n", Connection.encode());
  2231. if (!m_scfWrapper->Initialize(m_SCFDllName)) {
  2232. //mLog::FINFO("Failed to initialize SCFWrapper: {}", m_scfWrapper->GetLastError());
  2233. return false;
  2234. }
  2235. // 设置数据接收回调
  2236. m_scfWrapper->SetDataReceivedCallback([this](const char* data, uint32_t length) {
  2237. this->Dequeue(data, length);
  2238. });
  2239. auto erCode = m_scfWrapper->Connect(Connection, &PSGHRDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
  2240. if (erCode != SCF_SUCCEED)
  2241. return false;
  2242. // 启动自动接收
  2243. if (!m_scfWrapper->StartAutoReceive()) {
  2244. //mLog::FINFO("Failed to start auto receive");
  2245. return false;
  2246. }
  2247. return true;
  2248. }
  2249. auto nsGEN::PSGHRDriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
  2250. {
  2251. //mLog::FINFO("CreateDevice in\n");
  2252. m_pDevice = new PSGHRDevice(EventCenter, m_scfWrapper, m_ConfigFileName);
  2253. auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDevice));
  2254. //mLog::FINFO("CreateDevice out\n");
  2255. return dev;
  2256. }
  2257. void nsGEN::PSGHRDriver::FireNotify(int code, std::string key, std::string content)
  2258. {
  2259. EventCenter->OnNotify(code, key, content);
  2260. }
  2261. bool nsGEN::PSGHRDriver::isConnected() const
  2262. {
  2263. if (m_scfWrapper && m_scfWrapper->IsConnected())
  2264. {
  2265. return true;
  2266. }
  2267. if (m_pDevice == nullptr)
  2268. {
  2269. //mLog::FINFO("m_pDevice == nullptr\n");
  2270. return false;
  2271. }
  2272. if (m_pDevice->LoadConfig(m_ConfigFileName) == -1)
  2273. {
  2274. return false; //return 0;
  2275. }
  2276. int genState = m_pDevice->GetGenState();
  2277. //mLog::FINFO("m_pDevice->GetGenState() == {$}\n", genState);
  2278. return genState > 0; // 只有返回值大于 0 时才返回 true
  2279. }
  2280. std::string nsGEN::PSGHRDriver::GetResource()
  2281. {
  2282. //mLog::Debug("GetResource");
  2283. ResDataObject r_config, temp;
  2284. if (!temp.loadFile(m_ConfigFileName.c_str()))
  2285. {
  2286. return "";
  2287. }
  2288. m_ConfigAll = temp;
  2289. r_config = temp["CONFIGURATION"];
  2290. m_Configurations = r_config;
  2291. ResDataObject DescriptionTemp;
  2292. ResDataObject DescriptionSend;
  2293. ResDataObject m_DescriptionSend;
  2294. ResDataObject ListTemp;
  2295. string strTemp = ""; //用于读取字符串配置信息
  2296. string strIndex = ""; //用于读取配置信息中的List项
  2297. int nTemp = -1; //用于读取整型配置信息
  2298. char sstream[10] = { 0 }; //用于转换值
  2299. string strValue = ""; //用于存储配置的值
  2300. string strType = ""; //用于存储配置的类型 int/float/string...
  2301. /***
  2302. * 1. 通过循环,将所有配置项写到pDeviceConfig
  2303. * 2. 记录配置项的内部key以及配置类型,类型对应了不同配置文件路径,用于读写真实值
  2304. ***/
  2305. try
  2306. {
  2307. //便利ConfigToolInfo 中 所有的AttributeInfo 属性段
  2308. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  2309. m_pAttribute->clear();
  2310. m_pDescription->clear();
  2311. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  2312. {
  2313. DescriptionTemp.clear();
  2314. DescriptionSend.clear();
  2315. ListTemp.clear();
  2316. //AttributeType
  2317. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Type"];
  2318. DescriptionTemp.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
  2319. DescriptionSend.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
  2320. strType = strTemp; //记录配置项的类型
  2321. //AttributeKey
  2322. //1. 根据AttributeType,内部key和配置路径,拿到当前的真实值
  2323. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  2324. nTemp = (int)m_Configurations["ConfigToolInfo"][nInfoIndex]["PathID"];
  2325. GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue); //得到strValue的值
  2326. //printf("********************************innerkey=%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
  2327. //2. 赋值
  2328. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  2329. if ("int" == strType)
  2330. {
  2331. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  2332. }
  2333. else if ("float" == strType)
  2334. {
  2335. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  2336. }
  2337. else //其它先按string类型处理
  2338. {
  2339. (*m_pAttribute).add(strTemp.c_str(), strValue.c_str());
  2340. }
  2341. //printf("********************************outkey =%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
  2342. //AttributeAccess
  2343. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Access"];
  2344. DescriptionTemp.add(ConfKey::CcosAccess, strTemp.c_str());
  2345. DescriptionSend.add(ConfKey::CcosAccess, strTemp.c_str());
  2346. /*
  2347. //AttributeRangeMin
  2348. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMin"];
  2349. if (strTemp != "") //不需要的配置项为空
  2350. {
  2351. DescriptionTemp.add(ConfKey::CcosRangeMin, strTemp.c_str());
  2352. }
  2353. //AttributeRangeMax
  2354. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMax"];
  2355. if (strTemp != "") //不需要的配置项为空
  2356. {
  2357. DescriptionTemp.add(ConfKey::CcosRangeMax, strTemp.c_str());
  2358. }
  2359. */
  2360. //AttributeList
  2361. nTemp = m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListNum"];
  2362. if (nTemp > 0) //ListNum不大于0时说明不需要list配置
  2363. {
  2364. for (int nListIndex = 0; nListIndex < nTemp; nListIndex++)
  2365. {
  2366. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListInfo"][nListIndex];
  2367. auto temKey = std::to_string(nListIndex);
  2368. ListTemp.add(temKey.c_str(), strTemp.c_str());
  2369. }
  2370. DescriptionTemp.add(ConfKey::CcosList, ListTemp);
  2371. DescriptionSend.add(ConfKey::CcosList, ListTemp.encode());
  2372. }
  2373. //AttributeRequired
  2374. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Required"];
  2375. DescriptionTemp.add(ConfKey::CcosRequired, strTemp.c_str());
  2376. DescriptionSend.add(ConfKey::CcosRequired, strTemp.c_str());
  2377. //AttributeDefaultValue
  2378. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["DefaultValue"];
  2379. if (strTemp != "") //不需要的配置项为空
  2380. {
  2381. DescriptionTemp.add(ConfKey::CcosDefaultValue, strTemp.c_str());
  2382. DescriptionSend.add(ConfKey::CcosDefaultValue, strTemp.c_str());
  2383. }
  2384. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  2385. (*m_pDescription).add(strTemp.c_str(), DescriptionTemp);
  2386. m_DescriptionSend.add(strTemp.c_str(), DescriptionSend.encode());
  2387. }
  2388. }
  2389. catch (ResDataObjectExption& e)
  2390. {
  2391. //mLog::Error("Get config error: {$}", e.what());
  2392. return "";
  2393. }
  2394. ResDataObject resDeviceResource;
  2395. resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
  2396. resDeviceResource.add(ConfKey::CcosGeneratorDescription, (*m_pDescription));
  2397. ResDataObject DescriptionTempEx;
  2398. DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
  2399. m_DeviceConfig.clear();
  2400. m_DeviceConfig = DescriptionTempEx;
  2401. ////mLog::Debug("local ************* get resource over {$}", DescriptionTempEx.encode());
  2402. //printf("local ************* get resource over %s \n", DescriptionTempEx.encode());
  2403. resDeviceResource.clear();
  2404. resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
  2405. resDeviceResource.add(ConfKey::CcosGeneratorDescription, m_DescriptionSend);
  2406. DescriptionTempEx.clear();
  2407. DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
  2408. m_DeviceConfigSend.clear();
  2409. m_DeviceConfigSend = DescriptionTempEx;
  2410. string res = m_DeviceConfigSend.encode();
  2411. //printf("%s", res.c_str());
  2412. ////mLog::Debug("get resource over {$}", DescriptionTempEx.encode());
  2413. //("************* get resource over %s \n", DescriptionTempEx.encode());
  2414. return res;
  2415. }
  2416. std::string nsGEN::PSGHRDriver::DeviceProbe()
  2417. {
  2418. //mLog::FINFO("std::string nsGEN::PSGHRDriver::DeviceProbe() in\n");
  2419. ResDataObject r_config, HardwareInfo;
  2420. if (r_config.loadFile(m_ConfigFileName.c_str()))
  2421. {
  2422. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  2423. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  2424. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  2425. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  2426. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  2427. }
  2428. else
  2429. {
  2430. HardwareInfo.add("MajorID", "Generator");
  2431. HardwareInfo.add("MinorID", "Dr");
  2432. HardwareInfo.add("VendorID", "PSGHR");
  2433. HardwareInfo.add("ProductID", "HF");
  2434. HardwareInfo.add("SerialID", "Dev");
  2435. }
  2436. string ret = HardwareInfo.encode();
  2437. //mLog::FINFO("std::string nsGEN::PSGHRDriver::DeviceProbe() out\n");
  2438. return ret;
  2439. }
  2440. void nsGEN::PSGHRDriver::Disconnect()
  2441. {
  2442. if (m_scfWrapper) {
  2443. m_scfWrapper->StopAutoReceive();
  2444. m_scfWrapper->Disconnect();
  2445. }
  2446. //mLog::Close();
  2447. //mLog::gLogger = nullptr;
  2448. }
  2449. void nsGEN::PSGHRDriver::Dequeue(const char* Packet, DWORD Length)
  2450. {
  2451. DecodeFrame(Packet, Length);
  2452. }
  2453. PACKET_RET nsGEN::PSGHRDriver::callbackPackageProcess(const char* RecData, uint32_t nLength, uint32_t& PacketLength)
  2454. {
  2455. if (nLength < 1)
  2456. {
  2457. //mLog::FINFO("nLength < 1, nLength=={} \n", nLength);
  2458. return PACKET_USELESS;
  2459. }
  2460. for (DWORD i = 0; i < nLength - 1; i++)
  2461. {
  2462. if (RecData[i] == 0x02)
  2463. {
  2464. if (i != 0)
  2465. {
  2466. PacketLength = i;
  2467. char strtemp[100] = { 0 };
  2468. memcpy(strtemp, RecData, i);
  2469. strtemp[PacketLength + 1] = 0;
  2470. printf("==IN error data ==:%s,PacketLength=%d,nLength=%d\n", strtemp, PacketLength, nLength);
  2471. return PACKET_USELESS;
  2472. }
  2473. }
  2474. if (RecData[i] == 0x03)
  2475. {
  2476. PacketLength = i + 2;
  2477. char strtemp[100] = { 0 };
  2478. memcpy(strtemp, RecData, i);
  2479. strtemp[PacketLength + 1] = 0;
  2480. //mLog::FINFO("==IN==:{}\n", strtemp);
  2481. return PACKET_ISPACKET;
  2482. }
  2483. }
  2484. return PACKET_NOPACKET;
  2485. }
  2486. bool nsGEN::PSGHRDriver::GetDeviceConfig(std::string& Cfg)
  2487. {
  2488. Cfg = m_DeviceConfigSend.encode();
  2489. printf("GetDeviceConfig over , %s", Cfg.c_str());
  2490. return true;
  2491. }
  2492. bool nsGEN::PSGHRDriver::SetDeviceConfig(std::string Cfg)
  2493. {
  2494. //mLog::FINFO("--Func-- SetDeviceConfig {$}\n", Cfg.c_str());
  2495. printf("\n--Func-- SetDeviceConfig %s\n", Cfg.c_str());
  2496. ResDataObject DeviceConfig;
  2497. DeviceConfig.decode(Cfg.c_str());
  2498. ResDataObject DescriptionTempEx;
  2499. DescriptionTempEx = DeviceConfig["DeviceConfig"]["Attribute"];
  2500. //mLog::Debug("Attribute:{$}", DescriptionTempEx.encode());
  2501. bool bSaveFile = false; //true:重新保存配置文件
  2502. string strAccess = "";
  2503. for (int i = 0; i < DescriptionTempEx.size(); i++)
  2504. {
  2505. string strKey = DescriptionTempEx.GetKey(i);
  2506. //mLog::FINFO("{$}", strKey.c_str());
  2507. printf("%s\n", strKey.c_str());
  2508. try
  2509. {
  2510. if (m_pAttribute->GetFirstOf(strKey.c_str()) >= 0)
  2511. {
  2512. strAccess = (string)(*m_pDescription)[strKey.c_str()]["Access"];
  2513. if ("RW" == strAccess)
  2514. {
  2515. //修改对应配置,在其他单元的配置项要同时调用其修改函数修改真实值
  2516. //1. 修改内存中的值,用于给上层发消息
  2517. (*m_pAttribute)[strKey.c_str()] = DescriptionTempEx[i];
  2518. //2. 拿到Innerkey
  2519. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  2520. //mLog::FINFO("nConfigInfoCount {$}", nConfigInfoCount);
  2521. string strTemp = ""; //存储AttributeKey
  2522. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  2523. {
  2524. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  2525. if (strTemp == strKey)
  2526. {
  2527. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  2528. break;
  2529. }
  2530. }
  2531. //3. 修改配置文件中的值
  2532. if (SetDeviceConfigValue(m_Configurations, strTemp.c_str(), 1, DescriptionTempEx[i]))
  2533. {
  2534. //mLog::Debug("SetDeviceConfigValue over");
  2535. bSaveFile = true;
  2536. }
  2537. }
  2538. else
  2539. {
  2540. //mLog::FINFO("{$} is not a RW configuration item", strKey.c_str());
  2541. }
  2542. }
  2543. else
  2544. {
  2545. //mLog::FINFO("without this attribute {$}", strKey.c_str());
  2546. }
  2547. }
  2548. catch (ResDataObjectExption& e)
  2549. {
  2550. printf("\nSetDriverConfig crashed: %s\n", e.what());
  2551. //mLog::Error("SetDriverConfig crashed: {$}", e.what());
  2552. return false;
  2553. }
  2554. }
  2555. if (bSaveFile)
  2556. {
  2557. //3. 重新保存配置文件
  2558. SaveConfigFile(true);
  2559. }
  2560. return true;
  2561. }
  2562. bool nsGEN::PSGHRDriver::SaveConfigFile(bool bSendNotify)
  2563. {
  2564. m_ConfigAll["CONFIGURATION"] = m_Configurations;
  2565. bool bRt = m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
  2566. //mLog::FINFO("SaveConfigFile over {$}", bRt);
  2567. return true;
  2568. }
  2569. bool nsGEN::PSGHRDriver::GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue)
  2570. {
  2571. strValue = "";
  2572. string strTemp = pInnerKey;
  2573. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  2574. {
  2575. int pos = 0;
  2576. ResDataObject resTemp = config;
  2577. while ((pos = strTemp.find_first_of(',')) != string::npos)
  2578. {
  2579. string Key = strTemp.substr(0, pos);
  2580. string TempValue = resTemp[Key.c_str()].encode();
  2581. // printf("-TempValue=== %s", TempValue.c_str());
  2582. resTemp.clear();
  2583. resTemp.decode(TempValue.c_str());
  2584. strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
  2585. //printf("-************--%s", strTemp.c_str());
  2586. }
  2587. if (strTemp != "")
  2588. {
  2589. strValue = (string)resTemp[strTemp.c_str()];
  2590. }
  2591. else
  2592. {
  2593. strValue = (string)resTemp;
  2594. }
  2595. }
  2596. //printf("------------%s", strValue.c_str());
  2597. return true;
  2598. }
  2599. bool nsGEN::PSGHRDriver::SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue)
  2600. {
  2601. string strTemp = pInnerKey;
  2602. //mLog::Debug("Begin to change {$} item value to {$}", pInnerKey, szValue);
  2603. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  2604. {
  2605. try {
  2606. int pos = 0;
  2607. ResDataObject* resTemp = &config;
  2608. while ((pos = strTemp.find_first_of(',')) != string::npos)
  2609. {
  2610. string Key = strTemp.substr(0, pos);
  2611. resTemp = &(*resTemp)[Key.c_str()];
  2612. strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
  2613. }
  2614. if (strTemp != "")
  2615. {
  2616. (*resTemp)[strTemp.c_str()] = szValue;
  2617. }
  2618. else
  2619. {
  2620. *resTemp = szValue;
  2621. }
  2622. }
  2623. catch (ResDataObjectExption& e)
  2624. {
  2625. //mLog::Error("SetDriverConfigvalue crashed: {$}", e.what());
  2626. return false;
  2627. }
  2628. }
  2629. return true;
  2630. }
  2631. //-----------------------------------------------------------------------------
  2632. // GetIODriver & CreateIODriver
  2633. //-----------------------------------------------------------------------------
  2634. static nsGEN::PSGHRDriver gIODriver;
  2635. extern "C" CCOS::Dev::IODriver * GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
  2636. {
  2637. return &gIODriver;
  2638. }
  2639. extern "C" CCOS::Dev::IODriver * CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
  2640. {
  2641. pIODriver = new nsGEN::PSGHRDriver();
  2642. return pIODriver;
  2643. }