CCOS.Dev.Generator.PSG_HR.cpp 94 KB

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