DIOS.Dev.Generator.PSG_RF.cpp 94 KB

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