DIOS.Dev.Generator.RYGEN.cpp 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799
  1. // CCOS.Dev.GEN.RYGEN.cpp : 定义 DLL 应用程序的导出函数。
  2. //
  3. #include "stdafx.h"
  4. #include <assert.h>
  5. #include <functional>
  6. #include "LogicDevice.h"
  7. #include "Helper.JSON.hpp"
  8. #include <unordered_map>
  9. #include "CCOS.Dev.Generator.RYGEN.h"
  10. #include <fstream>
  11. using namespace std::placeholders;
  12. using namespace CCOS::Dev::Detail::Generator;
  13. namespace nsGEN = CCOS::Dev::Detail::Generator;
  14. #pragma warning (disable:4244)
  15. #pragma warning (disable:4305)
  16. #pragma warning (disable:4267)
  17. static const int msTimeOut_Lock = 500;
  18. #ifdef _WIN64
  19. #ifdef _DEBUG
  20. static const auto COM_SCFDllName = "Ccos.Dev.SerialSCFX64D.dll";
  21. #else
  22. static const auto COM_SCFDllName = "Ccos.Dev.SerialSCFX64.dll";
  23. #endif
  24. #endif
  25. #ifdef _WIN64
  26. #ifdef _DEBUG
  27. static const auto TCP_SCFDllName = "Ccos.Dev.TcpipSCFX64D.dll";
  28. #else
  29. static const auto TCP_SCFDllName = "Ccos.Dev.TcpipSCFX64.dll";
  30. #endif
  31. #endif
  32. //-----------------------------------------------------------------------------
  33. // RYGENDevice
  34. //-----------------------------------------------------------------------------
  35. IMPLEMENT_DYNAMIC(RYGENDevice, CWnd)
  36. BEGIN_MESSAGE_MAP(RYGENDevice, CWnd)
  37. ON_MESSAGE(WM_HV_TABLE_IO_MESSAGE, RYAPIMSG)
  38. END_MESSAGE_MAP()
  39. float g_MA_List[] = { 8, 10, 12.5, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640 };
  40. float g_MAS_List[] = { 1, 1.25, 1.6, 2, 2.5, 3.2, 4, 5, 6.4, 8, 10, 12.5, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640, 800, 1000 };
  41. float g_MS_List[] = { 1, 2, 3, 4, 5, 6, 8, 10, 12, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640, 800, 1000, 1250, 1600, 2000, 2500, 3200, 4000, 5000, 6400, 8000, 10000 };
  42. int g_AECFIELD_List[] = { 1, 10, 100, 11, 101, 111 };
  43. std::vector <float> gf_MA_List = { 8, 10, 12.5, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640 };
  44. atomic<int> nsGEN::RYGENDevice::m_iLoopTime = RYGEN_LoopDefTime;
  45. string GetProcessDirectory()
  46. {
  47. string ret = "";
  48. char szFilename[MAX_PATH] = { 0 };
  49. DWORD res = GetModuleFileNameA(0, szFilename, MAX_PATH);
  50. if (res == 0)
  51. {
  52. return ret;
  53. }
  54. string fullpath = szFilename;
  55. string::size_type firstHit = fullpath.find_last_of('\\');
  56. if (firstHit == string::npos || firstHit == 0)
  57. {
  58. return ret;
  59. }
  60. ret = fullpath.substr(0, firstHit);//kick last
  61. return ret;
  62. }
  63. nsGEN::RYGENDevice::RYGENDevice(std::shared_ptr <IOEventCenter> center, UIObject* UIobj, string configfile) : super(center)
  64. {
  65. m_pUIOBJ = UIobj;
  66. m_pUIOBJ->Init(this, OnCallBack);
  67. assert(EventCenter);
  68. FINFO("version:3.0.1.0");
  69. m_DoseUnit.m_KV.reset(new KVMould(0.0, 40.0, 120.0, 1.0));
  70. m_DoseUnit.m_MA.reset(new MAMould(0.0, 10.0, 1000.0, 0.1));
  71. m_DoseUnit.m_MS.reset(new MSMould(0.0, 1.0, 10000.0, 0.01));
  72. m_DoseUnit.m_MAS.reset(new MASMould(0.0, 0.1, 1000.0, 0.01));
  73. m_DoseUnit.m_Techmode.reset(new TECHMODEMould(0, 0, 2, 1));
  74. m_DoseUnit.m_WS.reset(new WORKSTATIONMould(1, 0, 5, 1));
  75. m_DoseUnit.m_Focus.reset(new FOCUSMould(1, 0, 1, 1));
  76. m_DoseUnit.m_AECField.reset(new AECFIELDMould(0, 0, 111, 1));
  77. m_DoseUnit.m_AECFilm.reset(new AECFILMMould(0, 0, 2, 1));
  78. m_DoseUnit.m_AECDensity.reset(new AECDENSITYMould(0, -4, 4, 1));
  79. m_DoseUnit.m_HE.reset(new TUBEHEATMould(0, 0, 100, 1));
  80. m_DoseUnit.m_PostKV.reset(new POSTKVMould(0.0, 40.0, 120.0, 1.0));
  81. m_DoseUnit.m_PostMA.reset(new POSTMAMould(0.0, 10.0, 1000.0, 0.1));
  82. m_DoseUnit.m_PostMS.reset(new POSTMSMould(0.0, 1.0, 10000.0, 0.01));
  83. m_DoseUnit.m_PostMAS.reset(new POSTMASMould(0.0, 0.5, 1000.0, 0.01));
  84. m_DoseUnit.m_GenSynState.reset(new GENSYNSTATEMould(0, AttrKey::GENERATOR_SYNC_ERR, AttrKey::GENERATOR_SYNC_MAX, 1));
  85. m_DoseUnit.m_GenState.reset(new GENSTATEMould(0, AttrKey::GENERATOR_STATUS_SHUTDOWN, AttrKey::GENERATOR_STATUS_MAX, 1));
  86. m_DoseUnit.m_GenTotalExpNumber.reset(new TOTALEXPNUMMould(0, 0, 9999, 1));
  87. m_DoseUnit.m_GenTotalAcqTimes.reset(new TOTALACQTIMESMould(0, 0, 9999, 1));
  88. m_DoseUnit.m_GenTubeCoolWaitTimes.reset(new TUBECOOLTIMEMould(0, 0, 9999, 1));
  89. m_DoseUnit.m_GenTubeOverLoadNumber.reset(new TUBEOVERLOADNUMMould(0, 0, 9999, 1));
  90. m_DoseUnit.m_GenCurrentExpNumber.reset(new CUREXPNUMMould(0, 0, 9999, 1));
  91. m_DoseUnit.m_ExpMode.reset(new EXPMODEMould(AttrKey::EXPMODE_TYPE::Single));
  92. m_DoseUnit.m_FrameRate.reset(new FRAMERATEMould(0, 0, 16, 1));
  93. m_MSGUnit.reset(new nsDetail::MSGUnit(center, nsGEN::GeneratorUnitType));
  94. m_DAP.reset(new DevDAP::DOSEMould(0.0, 0.0, 1000.0, 0.01));
  95. m_DoseUnit.m_FLMode.reset(new FLUModeMould(AttrKey::GENERATOR_FLUMode::GENERATOR_FLMODE_NOTFLU));
  96. m_DoseUnit.m_FLIntTime.reset(new FLUIntTimeMould(0.0, 0.0, 100.0, 0.1));
  97. m_DoseUnit.m_FLAccTime.reset(new FLAccTimeMould(0.0, 0.0, 999.0, 0.1));
  98. m_DoseUnit.m_FLKV.reset(new FLUKVMould(0, 40, 125, 1));
  99. m_DoseUnit.m_FLMS.reset(new FLUMSMould(10.0, 10.0, 999999.0, 0.01));
  100. m_DoseUnit.m_FLMA.reset(new FLUMAMould(0.1, 0.1, 99.0, 0.1));
  101. m_DoseUnit.m_ABSStatus.reset(new FLUABSStatusMould(0, 0, 2, 1));
  102. m_DoseUnit.m_PPS.reset(new PPSMould(0.5, 0.5, 30, 0.1));
  103. m_DoseUnit.m_DoseLevel.reset(new FLUDoseLevelMould(0, 0, 2, 1));
  104. m_DoseUnit.m_Curve.reset(new FLUCurveMould(0, 0, 3, 1));
  105. m_hGenPostEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  106. m_pHardwareStatusThread = NULL;
  107. m_DoseUnit.m_FLAccTimeUnit = "s";
  108. m_nPreWS = 0;
  109. m_nPreFO = 1;
  110. m_nPreET = 0;
  111. m_nPreAECFieldSel = 0;
  112. m_nPreAECFilmSel = 0;
  113. m_nPreAECDensity = 0;
  114. m_nPreKV = 50;
  115. m_fPreMA = 200;
  116. m_fPreMS = 50;
  117. m_fPreMAS = 10;
  118. m_strFLFMode = "PF";
  119. m_fpps = 15;
  120. m_bError = false;
  121. m_bIsConfigLoaded = false;
  122. m_bResetActive = false;
  123. m_hWnd = NULL;
  124. Register();
  125. InitGen();
  126. }
  127. nsGEN::RYGENDevice::~RYGENDevice()
  128. {
  129. CloseHandle(m_hGenPostEvent);
  130. if (HV_ClearCanBuffer())
  131. {
  132. FINFO("HV_ClearCanBuffer success!");
  133. }
  134. else
  135. {
  136. FINFO("HV_ClearCanBuffer failed!");
  137. }
  138. HV_CloseCanDriver();
  139. m_pUIOBJ->Destrory();
  140. }
  141. std::string nsGEN::RYGENDevice::GetGUID() const
  142. {
  143. FINFO("\n===============GetGUID : {$} ===================\n", GeneratorUnitType);
  144. return GeneratorUnitType;
  145. }
  146. void nsGEN::RYGENDevice::Register()
  147. {
  148. auto Disp = &Dispatch;
  149. superGen::Register(Disp);
  150. superGen::RegisterRAD(Disp);
  151. superGen::RegisterAEC(Disp);
  152. superGen::RegisterExpEnable(Disp);
  153. superGen::RegisterGeneratortoSyncStatus(Disp);
  154. superGen::RegisterFluoro(Disp);
  155. Disp->Get.Push(m_MSGUnit->GetKey().c_str(), [this](std::string& out) { out = m_MSGUnit->JSGet(); return RET_STATUS::RET_SUCCEED; });
  156. auto fun_Clear_DAP = [this](auto a, auto&)
  157. {
  158. return Clear_DAP();
  159. };
  160. Disp->Action.Push("Clear_DAP", fun_Clear_DAP);
  161. auto fun_GetValue_DAP = [this](auto a, auto& b)
  162. {
  163. float value = 0;
  164. RET_STATUS ret = GetValue_DAP(value);
  165. b = ToJSON(value);
  166. return ret;
  167. };
  168. Disp->Action.Push("GetValue_DAP", fun_GetValue_DAP);
  169. auto fun_StartMove = [this](auto a,auto& b)
  170. {
  171. return StartMove();
  172. };
  173. Disp->Action.Push("StartMove", fun_StartMove);
  174. auto fun_EndMove = [this](auto a, auto& b)
  175. {
  176. return EndMove();
  177. };
  178. Disp->Action.Push("EndMove", fun_EndMove);
  179. }
  180. RET_STATUS nsGEN::RYGENDevice::IncKV()
  181. {
  182. if (!m_DoseUnit.m_KV->CanInc()) return RET_STATUS::RET_SUCCEED;
  183. BYTE ucMode = 0x01;
  184. int nKV = HV_Handle_KV(ucMode, 0, 0);// kv increase 1
  185. if (-1 != nKV)
  186. {
  187. if (m_DoseUnit.m_KV->Update(nKV))
  188. FireNotify("KV", m_DoseUnit.m_KV->JSGet());
  189. FINFO("INCKV success!");
  190. }
  191. else
  192. {
  193. FINFO("INCKV failed!");
  194. ucMode = 0x04;
  195. int nKV = HV_Handle_KV(ucMode, 0, 0);// get current kv
  196. if (nKV != -1)
  197. {
  198. if (m_DoseUnit.m_KV->Update(nKV))
  199. FireNotify("KV", m_DoseUnit.m_KV->JSGet());
  200. FINFO("get KV success!");
  201. }
  202. }
  203. return RET_STATUS::RET_SUCCEED;
  204. }
  205. RET_STATUS nsGEN::RYGENDevice::DecKV()
  206. {
  207. if (!m_DoseUnit.m_KV->CanDec()) return RET_STATUS::RET_SUCCEED;
  208. BYTE ucMode = 0x03;
  209. int nKV = HV_Handle_KV(ucMode, 0, 0);// kv decrease 1
  210. if (-1 != nKV)
  211. {
  212. if (m_DoseUnit.m_KV->Update(nKV))
  213. FireNotify("KV", m_DoseUnit.m_KV->JSGet());
  214. FINFO("DECKV success!");
  215. }
  216. else
  217. {
  218. FINFO("DECKV failed!");
  219. ucMode = 0x04;
  220. int nKV = HV_Handle_KV(ucMode, 0, 0);// get current kv
  221. if (nKV != -1)
  222. {
  223. if (m_DoseUnit.m_KV->Update(nKV))
  224. FireNotify("KV", m_DoseUnit.m_KV->JSGet());
  225. FINFO("get KV success!");
  226. }
  227. }
  228. return RET_STATUS::RET_SUCCEED;
  229. }
  230. RET_STATUS nsGEN::RYGENDevice::SetKV(float value)
  231. {
  232. if (!m_DoseUnit.m_KV->Verify(value)) return RET_STATUS::RET_SUCCEED;
  233. BYTE ucMode = 0x05;
  234. int nCurrentKV = HV_Handle_KV(ucMode, (int)value, 0); // set kv
  235. if (nCurrentKV != -1)
  236. {
  237. if (nCurrentKV != value)
  238. {
  239. return RET_FAILED;
  240. }
  241. m_DoseUnit.m_KV->Update(value);
  242. FireNotify("KV", m_DoseUnit.m_KV->JSGet());
  243. FINFO("SetKV success!");
  244. }
  245. else
  246. {
  247. FINFO("SetKV failed!");
  248. return RET_FAILED;
  249. }
  250. return RET_STATUS::RET_SUCCEED;
  251. }
  252. RET_STATUS nsGEN::RYGENDevice::IncMA()
  253. {
  254. if (!m_DoseUnit.m_MA->CanInc()) return RET_STATUS::RET_SUCCEED;
  255. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  256. {
  257. FINFO("\n Techmode is MAS, can't inc MA");
  258. return RET_STATUS::RET_FAILED;
  259. }
  260. BYTE ucMode = 0x01;
  261. int nCurrentMA = HV_Handle_MA(ucMode, 0, 0); // MA increase 1
  262. if (nCurrentMA != -1)
  263. {
  264. float fCurrentMA = (float)nCurrentMA;
  265. if (m_DoseUnit.m_MA->Update(fCurrentMA / 10.0f))
  266. FireNotify("MA", m_DoseUnit.m_MA->JSGet());
  267. FINFO("INCMA success!");
  268. GetMAS();
  269. }
  270. else
  271. {
  272. FINFO("INCMA failed!");
  273. ucMode = 0x04;
  274. int nCurrentMA = HV_Handle_MA(ucMode, 0, 0); // get current MA
  275. if (nCurrentMA != -1)
  276. {
  277. float fCurrentMA = (float)nCurrentMA;
  278. if (m_DoseUnit.m_MA->Update(fCurrentMA / 10.0f))
  279. FireNotify("MA", m_DoseUnit.m_MA->JSGet());
  280. FINFO("GetMA success!");
  281. }
  282. else
  283. {
  284. FINFO("GetMA failed!");
  285. }
  286. }
  287. return RET_STATUS::RET_SUCCEED;
  288. }
  289. RET_STATUS nsGEN::RYGENDevice::DecMA()
  290. {
  291. if (!m_DoseUnit.m_MA->CanDec()) return RET_STATUS::RET_SUCCEED;
  292. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  293. {
  294. FINFO("\n Techmode is MAS, can't dec MA");
  295. return RET_STATUS::RET_FAILED;
  296. }
  297. BYTE ucMode = 0x03;
  298. int nCurrentMA = HV_Handle_MA(ucMode, 0, 0); // MA decrease 1
  299. if (nCurrentMA != -1)
  300. {
  301. float fCurrentMA = (float)nCurrentMA;
  302. if (m_DoseUnit.m_MA->Update(fCurrentMA / 10.0f))
  303. FireNotify("MA", m_DoseUnit.m_MA->JSGet());
  304. FINFO("DECMA success!");
  305. GetMAS();
  306. }
  307. else
  308. {
  309. FINFO("DECMA failed!");
  310. ucMode = 0x04;
  311. int nCurrentMA = HV_Handle_MA(ucMode, 0, 0); // get current MA
  312. if (nCurrentMA != -1)
  313. {
  314. float fCurrentMA = (float)nCurrentMA;
  315. if (m_DoseUnit.m_MA->Update(fCurrentMA / 10.0f))
  316. FireNotify("MA", m_DoseUnit.m_MA->JSGet());
  317. FINFO("GetMA success!");
  318. }
  319. else
  320. {
  321. FINFO("GetMA failed!");
  322. }
  323. }
  324. return RET_STATUS::RET_SUCCEED;
  325. }
  326. RET_STATUS nsGEN::RYGENDevice::SetMA(float fMA)
  327. {
  328. if (!m_DoseUnit.m_MA->Verify(fMA)) return RET_STATUS::RET_SUCCEED;
  329. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  330. {
  331. FINFO("\n Techmode is MAS, can't set MA");
  332. return RET_STATUS::RET_FAILED;
  333. }
  334. int nMA = (int)(fMA * 10);
  335. BYTE ucMode = 0x05;
  336. int nCurrentMA = HV_Handle_MA(ucMode, nMA, 0); // set MA
  337. if (nCurrentMA != -1)
  338. {
  339. float fCurrentMA = (float)nCurrentMA;
  340. m_DoseUnit.m_MA->Update(fCurrentMA / 10.0f);
  341. FireNotify("MA", m_DoseUnit.m_MA->JSGet());
  342. FINFO("SetMA success!");
  343. GetMAS();
  344. }
  345. else
  346. {
  347. FINFO("SetMA failed!");
  348. }
  349. return RET_STATUS::RET_SUCCEED;
  350. }
  351. RET_STATUS nsGEN::RYGENDevice::IncMS()
  352. {
  353. if (!m_DoseUnit.m_MS->CanInc()) return RET_STATUS::RET_SUCCEED;
  354. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  355. {
  356. FINFO("\n Techmode is MAS, can't inc MS");
  357. return RET_STATUS::RET_FAILED;
  358. }
  359. BYTE ucMode = 0x01;
  360. int nCurrentMS = HV_Handle_MS(ucMode, 0, 0); // MS increase 1
  361. if (nCurrentMS != -1)
  362. {
  363. float fCurrentMS = (float)nCurrentMS;
  364. if (m_DoseUnit.m_MS->Update(fCurrentMS / 100.0f))
  365. FireNotify("MS", m_DoseUnit.m_MS->JSGet());
  366. FINFO("INCMS success!");
  367. GetMAS();
  368. }
  369. else
  370. {
  371. FINFO("INCMS failed!");
  372. ucMode = 0x04;
  373. int nCurrentMS = HV_Handle_MS(ucMode, 0, 0); // get current MS
  374. if (nCurrentMS != -1)
  375. {
  376. float fCurrentMS = (float)nCurrentMS;
  377. if (m_DoseUnit.m_MS->Update(fCurrentMS / 100.0f))
  378. FireNotify("MS", m_DoseUnit.m_MS->JSGet());
  379. FINFO("GetMS success!");
  380. }
  381. else
  382. {
  383. FINFO("GetMS failed!");
  384. }
  385. }
  386. return RET_STATUS::RET_SUCCEED;
  387. }
  388. RET_STATUS nsGEN::RYGENDevice::DecMS()
  389. {
  390. if (!m_DoseUnit.m_MS->CanDec()) return RET_STATUS::RET_SUCCEED;
  391. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  392. {
  393. FINFO("\n Techmode is MAS, can't dec MS");
  394. return RET_STATUS::RET_FAILED;
  395. }
  396. BYTE ucMode = 0x03;
  397. int nCurrentMS = HV_Handle_MS(ucMode, 0, 0); // MS decrease 1
  398. if (nCurrentMS != -1)
  399. {
  400. float fCurrentMS = (float)nCurrentMS;
  401. if (m_DoseUnit.m_MS->Update(fCurrentMS / 100.0f))
  402. FireNotify("MS", m_DoseUnit.m_MS->JSGet());
  403. FINFO("DECMS success!");
  404. GetMAS();
  405. }
  406. else
  407. {
  408. FINFO("DECMS failed!");
  409. ucMode = 0x04;
  410. int nCurrentMS = HV_Handle_MS(ucMode, 0, 0); // get current MS
  411. if (nCurrentMS != -1)
  412. {
  413. float fCurrentMS = (float)nCurrentMS;
  414. if (m_DoseUnit.m_MS->Update(fCurrentMS / 100.0f))
  415. FireNotify("MS", m_DoseUnit.m_MS->JSGet());
  416. FINFO("GetMS success!");
  417. }
  418. else
  419. {
  420. FINFO("GetMS failed!");
  421. }
  422. }
  423. return RET_STATUS::RET_SUCCEED;
  424. }
  425. RET_STATUS nsGEN::RYGENDevice::SetMS(float fMS)
  426. {
  427. if (!m_DoseUnit.m_MA->Verify(fMS)) return RET_STATUS::RET_SUCCEED;
  428. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  429. {
  430. FINFO("\n Techmode is MAS, can't set MS");
  431. return RET_STATUS::RET_FAILED;
  432. }
  433. int nMS = (int)(fMS * 100);
  434. BYTE ucMode = 0x05;
  435. int nCurrentMS = HV_Handle_MS(ucMode, nMS, 0); // set MS
  436. if (nCurrentMS != -1)
  437. {
  438. float fCurrentMS = (float)nCurrentMS;
  439. m_DoseUnit.m_MS->Update(fCurrentMS / 100.0f);
  440. FireNotify("MS", m_DoseUnit.m_MS->JSGet());
  441. FINFO("SetMS success!");
  442. GetMAS();
  443. }
  444. else
  445. {
  446. FINFO("SetMS failed!");
  447. }
  448. return RET_STATUS::RET_SUCCEED;
  449. }
  450. RET_STATUS nsGEN::RYGENDevice::IncMAS()
  451. {
  452. if (!m_DoseUnit.m_MAS->CanInc()) return RET_STATUS::RET_SUCCEED;
  453. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS)
  454. {
  455. FINFO("\n Techmode is not MAS, can't inc MAS");
  456. return RET_STATUS::RET_FAILED;
  457. }
  458. BYTE ucMode = 0x01;
  459. int nCurrentMAS = HV_Handle_MX(ucMode, 0, 0); // MAS increase 1
  460. if (nCurrentMAS != -1)
  461. {
  462. float fCurrentMAS = (float)nCurrentMAS;
  463. if (m_DoseUnit.m_MAS->Update(fCurrentMAS / 1000.0f))
  464. //FireNotify("MAS", m_DoseUnit.m_MAS->JSGet());
  465. FINFO("INCMAS success!");
  466. GetMA();
  467. GetMS();
  468. }
  469. else
  470. {
  471. FINFO("INCMAS failed!");
  472. ucMode = 0x04;
  473. nCurrentMAS = HV_Handle_MX(ucMode, 0, 0); // get current MAS
  474. if (nCurrentMAS != -1)
  475. {
  476. FINFO("GetMAS success!");
  477. }
  478. else
  479. {
  480. FINFO("GetMAS failed!");
  481. }
  482. }
  483. GetMAS();
  484. return RET_STATUS::RET_SUCCEED;
  485. }
  486. RET_STATUS nsGEN::RYGENDevice::DecMAS()
  487. {
  488. if (!m_DoseUnit.m_MAS->CanDec()) return RET_STATUS::RET_SUCCEED;
  489. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS)
  490. {
  491. FINFO("\n Techmode is not MAS, can't dec MAS");
  492. return RET_STATUS::RET_FAILED;
  493. }
  494. BYTE ucMode = 0x03;
  495. int nCurrentMAS = HV_Handle_MX(ucMode, 0, 0); // MAS decrease 1
  496. if (nCurrentMAS != -1)
  497. {
  498. float fCurrentMAS = (float)nCurrentMAS;
  499. if (m_DoseUnit.m_MAS->Update(fCurrentMAS / 1000.0f))
  500. //FireNotify("MAS", m_DoseUnit.m_MAS->JSGet());
  501. FINFO("DECMAS success!");
  502. GetMA();
  503. GetMS();
  504. }
  505. else
  506. {
  507. FINFO("DECMAS failed!");
  508. ucMode = 0x04;
  509. nCurrentMAS = HV_Handle_MX(ucMode, 0, 0); // get current MAS
  510. if (nCurrentMAS != -1)
  511. {
  512. FINFO("GetMAS success!");
  513. }
  514. else
  515. {
  516. FINFO("GetMAS failed!");
  517. }
  518. }
  519. GetMAS();
  520. return RET_STATUS::RET_SUCCEED;
  521. }
  522. RET_STATUS nsGEN::RYGENDevice::SetMAS(float fMAS)
  523. {
  524. if (!m_DoseUnit.m_MA->Verify(fMAS)) return RET_STATUS::RET_SUCCEED;
  525. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS)
  526. {
  527. FINFO("\n Techmode is not MAS, can't set MAS");
  528. return RET_STATUS::RET_FAILED;
  529. }
  530. int nMAS = (int)(fMAS * 1000);
  531. BYTE ucMode = 0x05;
  532. int nCurrentMAS = HV_Handle_MX(ucMode, nMAS, 0); // set MAS
  533. if (nCurrentMAS != -1)
  534. {
  535. float fCurrentMAS = (float)nCurrentMAS;
  536. if (m_DoseUnit.m_MAS->Update(fCurrentMAS / 1000.0f))
  537. FireNotify("MAS", m_DoseUnit.m_MAS->JSGet());
  538. FINFO("SetMAS success!");
  539. }
  540. else
  541. {
  542. FINFO("SetMAS failed!");
  543. }
  544. GetMA();
  545. GetMS();
  546. return RET_STATUS::RET_SUCCEED;
  547. }
  548. RET_STATUS nsGEN::RYGENDevice::SetTechmode(int nET)
  549. {
  550. if (!m_DoseUnit.m_Techmode->Verify(nET)) return RET_STATUS::RET_SUCCEED;
  551. FINFO("Select Tech mode: {$}, current mode: {$}", nET, m_DoseUnit.m_Techmode->Get());
  552. int count = 3;
  553. int tempET = 0;
  554. while (count--)
  555. {
  556. tempET = HV_Handle_TE(0, nET, 0);
  557. if (tempET == nET)
  558. {
  559. FINFO("SetTechMode succeed!");
  560. break;
  561. }
  562. Sleep(50);
  563. }
  564. if (m_DoseUnit.m_Techmode->Update(tempET))
  565. FireNotify(AttrKey::TECHMODE, m_DoseUnit.m_Techmode->JSGet());
  566. if (m_DoseUnit.m_Techmode->Get() == 0) //Ma,MS
  567. {
  568. SetAECField(0);
  569. }
  570. else if (m_DoseUnit.m_Techmode->Get() == 1) //MAS
  571. {
  572. SetAECField(0);
  573. }
  574. else if (m_DoseUnit.m_Techmode->Get() == 2) //AEC
  575. {
  576. SetAECField(m_DoseUnit.m_AECField->Get());
  577. }
  578. return RET_STATUS::RET_SUCCEED;
  579. }
  580. RET_STATUS nsGEN::RYGENDevice::SetFocus(int nFO)
  581. {
  582. if (!m_DoseUnit.m_Focus->Verify(nFO)) return RET_STATUS::RET_SUCCEED;
  583. FINFO("SetFocusSel to {$}", nFO);
  584. BYTE ucMode = 0x00;
  585. int nCurrentFO = HV_Handle_FO(ucMode, nFO, 0); // set FO
  586. if (nCurrentFO != -1)
  587. {
  588. if (m_DoseUnit.m_Focus->Update(nCurrentFO))
  589. {
  590. FireNotify(AttrKey::FOCUS, m_DoseUnit.m_Focus->JSGet());
  591. FINFO("焦点:{$}, FO={$}", atoi(m_DoseUnit.m_Focus->JSGet().c_str()) ? "大焦点" : "小焦点", m_DoseUnit.m_Focus->JSGet().c_str());
  592. FINFO("SetFocusSel success!");
  593. }
  594. GetKV();
  595. GetMA();
  596. GetMS();
  597. GetMAS();
  598. }
  599. else
  600. {
  601. FINFO("SetFocusSel failed!");
  602. }
  603. return RET_STATUS::RET_SUCCEED;
  604. }
  605. RET_STATUS nsGEN::RYGENDevice::SetAECDensity(int nAECDensity)
  606. {
  607. if (!m_DoseUnit.m_AECDensity->Verify(nAECDensity)) return RET_STATUS::RET_SUCCEED;
  608. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_AEC)
  609. return RET_STATUS::RET_FAILED;
  610. FINFO("SetAECDensity = {$} ", nAECDensity);
  611. int nRet = HV_Handle_FN(0, nAECDensity, 0);
  612. if (nRet == nAECDensity)
  613. {
  614. if (m_DoseUnit.m_AECDensity->Update(nAECDensity))
  615. FireNotify(AttrKey::AECDENSITY, m_DoseUnit.m_AECDensity->JSGet());
  616. FINFO("set AED density {$} succeed", m_DoseUnit.m_AECDensity->JSGet().c_str());
  617. }
  618. else
  619. {
  620. FINFO("set AED density return {$} != {$} ,failed!", nRet, nAECDensity);
  621. }
  622. return RET_STATUS::RET_SUCCEED;
  623. }
  624. RET_STATUS nsGEN::RYGENDevice::SetAECField(int nAECFieldSel)
  625. {
  626. if (!m_DoseUnit.m_AECField->Verify(nAECFieldSel)) return RET_STATUS::RET_SUCCEED;
  627. int ret = true;
  628. int count = 3;
  629. if (m_DoseUnit.m_AECField->Get() != 2) // not AEC mode
  630. {
  631. FINFO("not in AEC mode");
  632. int nCurrentFiled = 0;
  633. while (count--)
  634. {
  635. nCurrentFiled = HV_Handle_FI(0, 0, 0);
  636. if (nCurrentFiled == 0) break;
  637. Sleep(10);
  638. }
  639. FireNotify(AttrKey::AECFIELD, "0");
  640. return RET_STATUS::RET_SUCCEED;
  641. }
  642. int SetAECFieldSel = nAECFieldSel;
  643. FINFO("SetAECField is {$}", SetAECFieldSel);
  644. int nCurrentAECFieldSel = 0;
  645. return RET_STATUS::RET_SUCCEED;
  646. }
  647. RET_STATUS nsGEN::RYGENDevice::SetAECFilm(int value)
  648. {
  649. if (!m_DoseUnit.m_AECFilm->Verify(value)) return RET_STATUS::RET_SUCCEED;
  650. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS)
  651. return RET_STATUS::RET_FAILED;
  652. char temp[50] = { 0 };
  653. sprintf_s(temp, "FS%03d", (int)value);
  654. return HWSend(temp);
  655. }
  656. RET_STATUS nsGEN::RYGENDevice::SetWS(const string value)
  657. {
  658. int tempws = 0;
  659. if (value == "Table") tempws = (int)m_GenConfig["WSTable"];
  660. else if (value == "Wall") tempws = (int)m_GenConfig["WSWall"];
  661. else if (value == "Direct") tempws = (int)m_GenConfig["WSConventional"];
  662. else if (value == "Free") tempws = (int)m_GenConfig["WSFree"];
  663. else if (value == "Tomo") tempws = (int)m_GenConfig["WSTomo"];
  664. /*char temp[50] = { 0 };
  665. sprintf_s(temp, "WS%01d", tempws);
  666. return HWSend(temp);*/
  667. return RET_STATUS::RET_SUCCEED;
  668. }
  669. string nsGEN::RYGENDevice::WSUI2Gen(int nUIWS)
  670. {
  671. string strWS = "";
  672. try
  673. {
  674. if (nUIWS == AttrKey::GENWS_TYPE::TABLE) //lying: cross mode
  675. {
  676. strWS = m_GenConfig["WSTable"].encode();
  677. }
  678. else if (nUIWS == AttrKey::GENWS_TYPE::WALL) //standing mode
  679. {
  680. strWS = m_GenConfig["WSWall"].encode();
  681. }
  682. else if (nUIWS == AttrKey::GENWS_TYPE::FREE_TABLE) //standing mode
  683. {
  684. strWS = m_GenConfig["WSFree"].encode();
  685. }
  686. else if (nUIWS == AttrKey::GENWS_TYPE::TOMO) //standing mode
  687. {
  688. strWS = m_GenConfig["WSTOMO"].encode();
  689. }
  690. else if (nUIWS == AttrKey::GENWS_TYPE::CONVENTIONAL) //standing mode
  691. {
  692. strWS = m_GenConfig["WSConventional"].encode();
  693. }
  694. }
  695. catch (ResDataObjectExption& exp)
  696. {
  697. FERROR("Get configuration failed, {$}\n", exp.what());
  698. }
  699. FINFO("Set WS: {$},Generator workstaion: {$}\n", nUIWS, strWS);
  700. if (strWS == "")
  701. {
  702. strWS = "Table";
  703. }
  704. return strWS;
  705. }
  706. RET_STATUS nsGEN::RYGENDevice::SetAPR(const _tAPRArgs& t)
  707. {
  708. m_t = t;
  709. FINFO("*********************Enter SetAPR*********************");
  710. FINFO("t.ws={$},t.fKV={$},t.fMA={$},t.fMAS={$},t.nAECDensity={$},t.nAECField={$},t.nAECFilm={$},t.nFocus={$},t.nTechmode={$}", t.nWS,t.fKV, t.fMA, t.fMAS, t.nAECDensity, t.nAECField, t.nAECFilm, t.nFocus, t.nTechmode);
  711. m_nPreWS = t.nWS;
  712. m_nPreFO = t.nFocus;
  713. m_nPreET = t.nTechmode;
  714. m_nPreAECFieldSel = t.nAECField;
  715. m_nPreAECFilmSel = t.nAECFilm;
  716. m_nPreAECDensity = t.nAECDensity;
  717. m_nPreKV = t.fKV;
  718. m_fPreMA = t.fMA;
  719. m_fPreMS = t.fMS;
  720. m_fPreMAS = t.fMAS;
  721. //SetWS("Table");
  722. //2
  723. SetKV(t.fKV);
  724. //3
  725. SetFocus(t.nFocus);
  726. //4
  727. if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_AEC)//aec
  728. {
  729. SetTechmode(t.nTechmode);
  730. SetAECField(t.nAECField);
  731. SetAECDensity(t.nAECDensity);
  732. SetMA(t.fMA);
  733. SetMS(t.fMS);
  734. }
  735. else if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_MAS)//2p
  736. {
  737. SetTechmode(t.nTechmode);
  738. const float EPSINON = 0.000001;
  739. SetMAS(t.fMAS);
  740. }
  741. else if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_TIME)//3p
  742. {
  743. SetTechmode(t.nTechmode);
  744. SetMA(t.fMA);
  745. SetMS(t.fMS);
  746. }
  747. UpdateGenParamter();
  748. FINFO("*********************Leave SetAPR*********************");
  749. return RET_STATUS::RET_SUCCEED;
  750. }
  751. RET_STATUS nsGEN::RYGENDevice::QueryHE(int& value)
  752. {
  753. return RET_STATUS::RET_SUCCEED;
  754. }
  755. RET_STATUS nsGEN::RYGENDevice::QueryPostKV(float& value)
  756. {
  757. return RET_STATUS::RET_SUCCEED;
  758. }
  759. RET_STATUS nsGEN::RYGENDevice::QueryPostMA(float& value)
  760. {
  761. return RET_STATUS::RET_SUCCEED;
  762. }
  763. RET_STATUS nsGEN::RYGENDevice::QueryPostMS(float& value)
  764. {
  765. return RET_STATUS::RET_SUCCEED;
  766. }
  767. RET_STATUS nsGEN::RYGENDevice::QueryPostMAS(float& value)
  768. {
  769. return RET_STATUS::RET_SUCCEED;
  770. }
  771. RET_STATUS nsGEN::RYGENDevice::Clear_DAP()
  772. {
  773. return RET_STATUS::RET_SUCCEED;
  774. }
  775. RET_STATUS nsGEN::RYGENDevice::GetValue_DAP(float& value)
  776. {
  777. return RET_STATUS::RET_SUCCEED;
  778. }
  779. RET_STATUS nsGEN::RYGENDevice::StartMove()
  780. {
  781. FINFO("Enter startMove");
  782. FINFO("end startmove");
  783. return RET_STATUS::RET_SUCCEED;
  784. }
  785. RET_STATUS nsGEN::RYGENDevice::EndMove()
  786. {
  787. FINFO("Enter endmove");
  788. FINFO("end EndMove");
  789. return RET_STATUS::RET_SUCCEED;
  790. }
  791. RET_STATUS nsGEN::RYGENDevice::ActiveSyncMode(_tSyncModeArgs value)
  792. {
  793. return RET_STATUS();
  794. }
  795. int nsGEN::RYGENDevice::LoadConfig(string configfile)
  796. {
  797. FINFO("=====================LoadConfig=========================");
  798. // 检查文件是否存在
  799. std::ifstream file(configfile);
  800. if (!file) {
  801. // 文件不存在,直接返回空的Connection对象
  802. FINFO("Config file does not exist: {$}", configfile.c_str());
  803. return -1;
  804. }
  805. if (m_bIsConfigLoaded)
  806. {
  807. FINFO("Configuration already loaded.");
  808. return 0;
  809. }
  810. m_strConfigPath = configfile;
  811. ResDataObject temp;
  812. temp.loadFile(m_strConfigPath.c_str());
  813. m_GenConfig = temp["CONFIGURATION"];
  814. TransJsonText(m_GenConfig);
  815. m_bIsConfigLoaded = true;
  816. return 0;
  817. }
  818. RET_STATUS nsGEN::RYGENDevice::SetGenSynState(int value)
  819. {
  820. FINFO("Enter SetGenSynState...{$} \n", value);
  821. return RET_STATUS::RET_SUCCEED;
  822. }
  823. RET_STATUS nsGEN::RYGENDevice::SetGenState(int value)
  824. {
  825. return RET_STATUS::RET_SUCCEED;
  826. }
  827. RET_STATUS nsGEN::RYGENDevice::SetExpMode(std::string value)
  828. {
  829. //note: when time the func be called?
  830. FINFO("Enter SetExpMode...{$}",value);
  831. m_DoseUnit.m_ExpMode->Update(value);
  832. int nStatus = HV_GetST();
  833. if (nStatus == 200)
  834. {
  835. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
  836. }
  837. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  838. return RET_STATUS::RET_SUCCEED;
  839. }
  840. RET_STATUS nsGEN::RYGENDevice::SetFLFMode(std::string value)
  841. {
  842. FINFO("Enter SetFLFMode...{$} \n", value.c_str());
  843. m_strFLFMode = value;
  844. int nMode = 0;
  845. if (value == "CF")
  846. {
  847. nMode = 1;
  848. }
  849. else if (value == "PF")
  850. {
  851. nMode = 2;
  852. }
  853. if (nMode == 1 || nMode == 2) // currently RYGEN just support 0, 1, 2
  854. {
  855. m_DoseUnit.m_FLMode->Update(nMode);
  856. nMode--;
  857. FINFO("SetFlMode {$}!", nMode);
  858. int i = 3;
  859. while (i--)
  860. {
  861. int nCurrentMode = HV_Handle_PF(5, nMode, 0); // set current FL mode
  862. if (nCurrentMode != -1)
  863. {
  864. FINFO("SetFlMode success, return {$}!", nCurrentMode);
  865. if (nCurrentMode != nMode)
  866. {
  867. Sleep(100);
  868. continue;
  869. }
  870. else
  871. {
  872. break;
  873. }
  874. }
  875. else
  876. {
  877. FINFO("SetFlMode failed!");
  878. break;
  879. }
  880. }
  881. }
  882. else
  883. {
  884. FINFO("Don't supported fluoro mode");
  885. }
  886. return RET_STATUS::RET_SUCCEED;
  887. }
  888. RET_STATUS nsGEN::RYGENDevice::SetAPF(const _tAPFArgs& t)
  889. {
  890. FINFO("APF:FLKV={$},FLMA={$},PPS={$},WS={$},FLuType={$},ABSMode={$},DoseLever={$}", t.nFLKV, t.fFLMA, t.nPPS, t.nWS, t.nFluMode, t.nABSMode, t.nDoseLever);
  891. int j = 3;
  892. while (j--)
  893. {
  894. if (SetABSMode(t.nABSMode))
  895. {
  896. break;
  897. }
  898. else
  899. {
  900. Sleep(100);
  901. }
  902. }
  903. Sleep(150);
  904. //SetFLFMode(to_string(t.nFluMode));
  905. //Sleep(50);
  906. //SetFluDoseLever(t.nDoseLever);
  907. //Sleep(50);
  908. for (int i = 0; i < 2; i++)
  909. {
  910. if (SetFluKV(t.nFLKV))
  911. {
  912. break;
  913. }
  914. Sleep(100);
  915. }
  916. SetFluMA(t.fFLMA);
  917. GetFluKV();
  918. GetFluMA();
  919. return RET_STATUS::RET_SUCCEED;
  920. }
  921. RET_STATUS nsGEN::RYGENDevice::IncFluKV()
  922. {
  923. FINFO("Enter IncFLKV()\n");
  924. if (!m_DoseUnit.m_FLKV->CanInc()) return RET_STATUS::RET_SUCCEED;
  925. BYTE ucMode = 0x01;
  926. int nFLKV = HV_Handle_FLK(ucMode, 0, 0);// FLkv increase 1
  927. if (-1 != nFLKV)
  928. {
  929. if (m_DoseUnit.m_FLKV->Update(nFLKV))
  930. FireNotify(AttrKey::FLUKV, m_DoseUnit.m_FLKV->JSGet());
  931. FINFO("INCFLKV success!");
  932. }
  933. else
  934. {
  935. FINFO("INCFLKV failed!");
  936. ucMode = 0x04;
  937. int nFLKV = HV_Handle_FLK(ucMode, 0, 0);// get current FLkv
  938. if (nFLKV != -1)
  939. {
  940. if (m_DoseUnit.m_FLKV->Update(nFLKV))
  941. FireNotify(AttrKey::FLUKV, m_DoseUnit.m_FLKV->JSGet());
  942. FINFO("get FLKV success!");
  943. }
  944. }
  945. return RET_STATUS::RET_SUCCEED;
  946. }
  947. RET_STATUS nsGEN::RYGENDevice::DecFluKV()
  948. {
  949. if (!m_DoseUnit.m_FLKV->CanDec()) return RET_STATUS::RET_SUCCEED;
  950. BYTE ucMode = 0x03;
  951. int nFLKV = HV_Handle_FLK(ucMode, 0, 0);// FLkv decrease 1
  952. if (-1 != nFLKV)
  953. {
  954. if (m_DoseUnit.m_FLKV->Update(nFLKV))
  955. FireNotify(AttrKey::FLUKV, m_DoseUnit.m_FLKV->JSGet());
  956. FINFO("DECFLKV success!");
  957. }
  958. else
  959. {
  960. FINFO("DECFLKV failed!");
  961. ucMode = 0x04;
  962. int nKV = HV_Handle_FLK(ucMode, 0, 0);// get current FLkv
  963. if (nKV != -1)
  964. {
  965. if (m_DoseUnit.m_FLKV->Update(nKV))
  966. FireNotify(AttrKey::FLUKV, m_DoseUnit.m_FLKV->JSGet());
  967. FINFO("get FLKV success!");
  968. }
  969. }
  970. return RET_STATUS::RET_SUCCEED;
  971. }
  972. RET_STATUS nsGEN::RYGENDevice::SetFluKV(float nFLKV)
  973. {
  974. if (!m_DoseUnit.m_FLKV->Verify(nFLKV)) return RET_STATUS::RET_SUCCEED;
  975. BYTE ucMode = 0x05;
  976. FINFO("SetFLKV {$} begin!", nFLKV);
  977. int nCurrentFKV = HV_Handle_FLK(ucMode, (int)nFLKV, 0); // set FLKV
  978. if (nCurrentFKV != -1)
  979. {
  980. m_DoseUnit.m_FLKV->Update(nCurrentFKV);
  981. FireNotify(AttrKey::FLUKV, m_DoseUnit.m_FLKV->JSGet());
  982. FINFO("SetFLKV {$} success!", nCurrentFKV);
  983. }
  984. else
  985. {
  986. FINFO("SetFLKV failed!");
  987. return RET_STATUS::RET_SUCCEED;
  988. }
  989. return RET_STATUS::RET_SUCCEED;
  990. }
  991. RET_STATUS nsGEN::RYGENDevice::IncFluMA()
  992. {
  993. if (!m_DoseUnit.m_FLMA->CanInc()) return RET_STATUS::RET_SUCCEED;
  994. BYTE ucMode = 0x01;
  995. int nCurrentMA = HV_Handle_FLM(ucMode, 0, 0); // FLMA increase 1
  996. if (nCurrentMA != -1)
  997. {
  998. if (m_DoseUnit.m_FLMA->Update(nCurrentMA))
  999. FireNotify(AttrKey::FLUMA, m_DoseUnit.m_FLMA->JSGet());
  1000. FINFO("INCFLMA success!");
  1001. }
  1002. else
  1003. {
  1004. FINFO("INCFLMA failed!");
  1005. }
  1006. return RET_STATUS::RET_SUCCEED;
  1007. }
  1008. RET_STATUS nsGEN::RYGENDevice::DecFluMA()
  1009. {
  1010. if (!m_DoseUnit.m_FLMA->CanDec()) return RET_STATUS::RET_SUCCEED;
  1011. BYTE ucMode = 0x03;
  1012. int nCurrentMA = HV_Handle_FLM(ucMode, 0, 0); // FLMA decrease 1
  1013. if (nCurrentMA != -1)
  1014. {
  1015. if (m_DoseUnit.m_FLMA->Update(nCurrentMA))
  1016. FireNotify(AttrKey::FLUMA, m_DoseUnit.m_FLMA->JSGet());
  1017. FINFO("DECFLMA success!");
  1018. }
  1019. else
  1020. {
  1021. FINFO("DECFLMA failed!");
  1022. }
  1023. return RET_STATUS::RET_SUCCEED;
  1024. }
  1025. RET_STATUS nsGEN::RYGENDevice::SetFluMA(float fFLMA)
  1026. {
  1027. if (!m_DoseUnit.m_FLMA->Verify(fFLMA)) return RET_STATUS::RET_SUCCEED;
  1028. int nMA = (int)(fFLMA * 10);
  1029. FINFO("SetFLKA {$} begin!", nMA);
  1030. BYTE ucMode = 0x05;
  1031. for (int i = 0; i < 3; i++)
  1032. {
  1033. int nCurrentMA = HV_Handle_FLM(ucMode, nMA, 0); // set FLMA
  1034. if (nCurrentMA == nMA)
  1035. {
  1036. FINFO("SetFLKA {$} success!", nCurrentMA);
  1037. break;
  1038. }
  1039. else
  1040. {
  1041. FINFO("SetFLKA failed!");
  1042. Sleep(100);
  1043. }
  1044. }
  1045. GetFluMA();
  1046. return RET_STATUS::RET_SUCCEED;
  1047. }
  1048. RET_STATUS nsGEN::RYGENDevice::INCPPS()
  1049. {
  1050. if (!m_DoseUnit.m_PPS->CanInc()) return RET_STATUS::RET_SUCCEED;
  1051. BYTE ucMode = 0x01;
  1052. float nFLPPS = HV_Handle_FLS(ucMode, 0, 0);// FLPPS increase 1
  1053. if (-1 != nFLPPS)
  1054. {
  1055. if (m_DoseUnit.m_PPS->Update(nFLPPS))
  1056. FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
  1057. FINFO("INCPPS success!");
  1058. }
  1059. else
  1060. {
  1061. FINFO("INCPPS failed!");
  1062. ucMode = 0x04;
  1063. int nFLPPS = HV_Handle_FLS(ucMode, 0, 0);// get current FLPPS
  1064. if (nFLPPS != -1)
  1065. {
  1066. if (m_DoseUnit.m_PPS->Update((float)nFLPPS))
  1067. FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
  1068. FINFO("get FLPPS success!");
  1069. }
  1070. }
  1071. return RET_STATUS::RET_SUCCEED;
  1072. }
  1073. RET_STATUS nsGEN::RYGENDevice::DECPPS()
  1074. {
  1075. if (!m_DoseUnit.m_PPS->CanDec()) return RET_STATUS::RET_SUCCEED;
  1076. BYTE ucMode = 0x03;
  1077. int nFLPPS = HV_Handle_FLS(ucMode, 0, 0);// FLPPS decrease 1
  1078. if (-1 != nFLPPS)
  1079. {
  1080. if (m_DoseUnit.m_PPS->Update((float)nFLPPS))
  1081. FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
  1082. FINFO("DECPPS success!");
  1083. }
  1084. else
  1085. {
  1086. FINFO("DECPPS failed!");
  1087. ucMode = 0x04;
  1088. int nFLPPS = HV_Handle_FLS(ucMode, 0, 0);// get current FLkv
  1089. if (nFLPPS != -1)
  1090. {
  1091. if (m_DoseUnit.m_PPS->Update((float)nFLPPS))
  1092. FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
  1093. FINFO("get FLPPS success!");
  1094. }
  1095. }
  1096. return RET_STATUS::RET_SUCCEED;
  1097. }
  1098. RET_STATUS nsGEN::RYGENDevice::SetPPS(float pps)
  1099. {
  1100. if (!m_DoseUnit.m_PPS->Verify(pps)) return RET_STATUS::RET_SUCCEED;
  1101. m_fpps = pps;
  1102. BYTE ucMode = 0x05;
  1103. int npps = pps * 10;
  1104. int nFLPPS = HV_Handle_FLS(ucMode, npps, 0);
  1105. if (-1 != nFLPPS)
  1106. {
  1107. if (m_DoseUnit.m_PPS->Update((float)nFLPPS))
  1108. FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
  1109. FINFO("SetPPS success!");
  1110. }
  1111. else
  1112. {
  1113. FINFO("SetPPS failed!");
  1114. ucMode = 0x04;
  1115. int nFLPPS = HV_Handle_FLS(ucMode, 0, 0);// get current FLPPS
  1116. if (nFLPPS != -1)
  1117. {
  1118. if (m_DoseUnit.m_PPS->Update((float)nFLPPS))
  1119. FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
  1120. FINFO("get FLPPS success!");
  1121. }
  1122. }
  1123. return RET_STATUS::RET_SUCCEED;
  1124. }
  1125. RET_STATUS nsGEN::RYGENDevice::SetABSMode(int nMode)
  1126. {
  1127. if (!m_DoseUnit.m_ABSStatus->Verify(nMode)) return RET_STATUS::RET_SUCCEED;
  1128. if (nMode == 0 || nMode == 1 || nMode == 2) // currently RYGEN just support 0, 1, 2
  1129. {
  1130. int sendMode = 1;
  1131. if (nMode == 0)
  1132. {
  1133. sendMode = 1;
  1134. }
  1135. else
  1136. {
  1137. sendMode = 3;
  1138. }
  1139. int nCurrentMode = HV_Handle_FLF(5, sendMode, 0); // set current FL mode
  1140. if (nCurrentMode != -1)
  1141. {
  1142. FINFO("SetABSMode success!");
  1143. if (nCurrentMode == 3)
  1144. if (m_DoseUnit.m_ABSStatus->Update(1))
  1145. FireNotify(AttrKey::FLUABSStatus, m_DoseUnit.m_ABSStatus->JSGet());
  1146. else
  1147. if (m_DoseUnit.m_ABSStatus->Update(0))
  1148. FireNotify(AttrKey::FLUABSStatus, m_DoseUnit.m_ABSStatus->JSGet());
  1149. FINFO("ABSMode:{$},nCurrentMode:{$} ", nMode, nCurrentMode);
  1150. FINFO("m_nABSMode:{$},m_nDoseLevel:{$}", m_DoseUnit.m_ABSStatus->Get(), m_DoseUnit.m_DoseLevel->Get());
  1151. }
  1152. else
  1153. {
  1154. FINFO("SetABSMode failed!");
  1155. }
  1156. }
  1157. else
  1158. {
  1159. FINFO("Don't supported ABS mode");
  1160. }
  1161. return RET_STATUS::RET_SUCCEED;
  1162. }
  1163. RET_STATUS nsGEN::RYGENDevice::SetABSCurve(int curveNum)
  1164. {
  1165. return RET_STATUS::RET_SUCCEED;
  1166. }
  1167. RET_STATUS nsGEN::RYGENDevice::IncABSCurve()
  1168. {
  1169. return RET_STATUS::RET_SUCCEED;
  1170. }
  1171. RET_STATUS nsGEN::RYGENDevice::DecABSCurve()
  1172. {
  1173. return RET_STATUS::RET_SUCCEED;
  1174. }
  1175. RET_STATUS nsGEN::RYGENDevice::GetABSCurve()
  1176. {
  1177. return HWSend("FLA?", 4);
  1178. }
  1179. float nsGEN::RYGENDevice::GetFluIntTimer()
  1180. {
  1181. return RET_STATUS::RET_SUCCEED;
  1182. }
  1183. float nsGEN::RYGENDevice::GetFluAccTimer()
  1184. {
  1185. return RET_STATUS::RET_SUCCEED;
  1186. }
  1187. RET_STATUS nsGEN::RYGENDevice::ResetFluTimer(int ntype)
  1188. {
  1189. if (ntype == 1)
  1190. {
  1191. int ret = HV_Handle_FLR(1, 0, 0);
  1192. if (ret != -1)
  1193. {
  1194. FINFO("ResetTimer success!");
  1195. if (m_DoseUnit.m_FLAccTime->Update(0.0f))
  1196. FireNotify(AttrKey::FLUAccTime, m_DoseUnit.m_FLAccTime->JSGet());
  1197. }
  1198. else
  1199. {
  1200. FINFO("ResetTimer failed!");
  1201. }
  1202. }
  1203. FINFO("ReSetFluAccTimer[{$}] \n", ntype);
  1204. return RET_STATUS::RET_SUCCEED;
  1205. }
  1206. RET_STATUS nsGEN::RYGENDevice::SetFluPre(int value)
  1207. {
  1208. return RET_STATUS::RET_SUCCEED;
  1209. }
  1210. RET_STATUS nsGEN::RYGENDevice::SetFluEXP(int value)
  1211. {
  1212. return RET_STATUS::RET_SUCCEED;
  1213. }
  1214. RET_STATUS nsGEN::RYGENDevice::SetFluMode(std::string value)
  1215. {
  1216. FINFO("Enter SetFLFMode...{$} \n", value.c_str());
  1217. int nMode = 0;
  1218. if (value == "CF")
  1219. {
  1220. nMode = 1;
  1221. }
  1222. else if (value == "PF")
  1223. {
  1224. nMode = 2;
  1225. }
  1226. if (nMode == 1 || nMode == 2) // currently RYGEN just support 0, 1, 2
  1227. {
  1228. m_DoseUnit.m_FLMode->Update(nMode);
  1229. nMode--;
  1230. FINFO("SetFlMode {$}!", nMode);
  1231. int i = 3;
  1232. while (i--)
  1233. {
  1234. int nCurrentMode = HV_Handle_PF(5, nMode, 0); // set current FL mode
  1235. if (nCurrentMode != -1)
  1236. {
  1237. FINFO("SetFlMode success, return {$}!", nCurrentMode);
  1238. if (nCurrentMode != nMode)
  1239. {
  1240. Sleep(100);
  1241. continue;
  1242. }
  1243. else
  1244. {
  1245. break;
  1246. }
  1247. }
  1248. else
  1249. {
  1250. FINFO("SetFlMode failed!");
  1251. break;
  1252. }
  1253. }
  1254. }
  1255. else
  1256. {
  1257. FINFO("Don't supported fluoro mode");
  1258. }
  1259. return RET_STATUS::RET_SUCCEED;
  1260. }
  1261. RET_STATUS nsGEN::RYGENDevice::SetFluDoseLever(int value)
  1262. {
  1263. FINFO("Enter SetFluDoseLever...{$} \n", value);
  1264. // 提取当前剂量级别
  1265. int currentDoseLevel = m_DoseUnit.m_DoseLevel->Get();
  1266. // 只有在剂量级别发生变化时才继续处理
  1267. if (currentDoseLevel == value) {
  1268. return RET_STATUS::RET_SUCCEED;
  1269. }
  1270. float fma;
  1271. // 计算新的FLMA值
  1272. if (value == 1) {
  1273. fma = 2 * m_DoseUnit.m_FLMA->Get();
  1274. }
  1275. else if (value == 0) {
  1276. fma = 0.5 * m_DoseUnit.m_FLMA->Get();
  1277. }
  1278. else {
  1279. FINFO("Invalid value:{$} \n", value);
  1280. return RET_STATUS::RET_FAILED; // 非法值处理
  1281. }
  1282. // 更新剂量级别
  1283. m_DoseUnit.m_DoseLevel->Update(value);
  1284. return SetFluMA(fma);
  1285. }
  1286. RET_STATUS nsGEN::RYGENDevice::SetEXAMMode(std::string value)
  1287. {
  1288. //EXAMMODE_TYPE::MANUAL
  1289. return RET_STATUS::RET_SUCCEED;
  1290. }
  1291. float nsGEN::RYGENDevice::GetKV()
  1292. {
  1293. BYTE ucMode = 0x04;
  1294. int nKV = HV_Handle_KV(ucMode, 0, 0);
  1295. m_DoseUnit.m_KV->Update(nKV);
  1296. FireNotify("KV", m_DoseUnit.m_KV->JSGet());
  1297. return true;
  1298. }
  1299. float nsGEN::RYGENDevice::GetMA()
  1300. {
  1301. BYTE ucMode = 0x04;
  1302. int nCurrentMA = HV_Handle_MA(ucMode, 0, 0); // get current MA
  1303. float fCurrentMA = (float)nCurrentMA;
  1304. m_DoseUnit.m_MA->Update(fCurrentMA / 10.0f);
  1305. FireNotify("MA", m_DoseUnit.m_MA->JSGet());
  1306. return true;
  1307. }
  1308. float nsGEN::RYGENDevice::GetMS()
  1309. {
  1310. BYTE ucMode = 0x04;
  1311. int nCurrentMS = HV_Handle_MS(ucMode, 0, 0); // get current MS
  1312. float fCurrentMS = (float)nCurrentMS;
  1313. m_DoseUnit.m_MS->Update(fCurrentMS / 100.0f);
  1314. FireNotify("MS", m_DoseUnit.m_MS->JSGet());
  1315. return true;
  1316. }
  1317. float nsGEN::RYGENDevice::GetMAS()
  1318. {
  1319. BYTE ucMode = 0x04;
  1320. int nCurrentMAS = HV_Handle_MX(ucMode, 0, 0); // get current MAS
  1321. if (nCurrentMAS != -1)
  1322. {
  1323. float fCurrentMAS = (float)nCurrentMAS;
  1324. m_DoseUnit.m_MAS->Update(fCurrentMAS / 1000.0f);
  1325. FireNotify("MAS", m_DoseUnit.m_MAS->JSGet());
  1326. }
  1327. return true;
  1328. }
  1329. float nsGEN::RYGENDevice::GetFluKV()
  1330. {
  1331. BYTE ucMode = 0x04;
  1332. int nKV = HV_Handle_FLK(ucMode, 0, 0);// get current FLkv
  1333. if (nKV != -1)
  1334. {
  1335. m_DoseUnit.m_FLKV->Update(nKV);
  1336. FireNotify(AttrKey::FLUKV, m_DoseUnit.m_FLKV->JSGet());
  1337. FINFO("get FLKV success!");
  1338. }
  1339. else
  1340. {
  1341. FINFO("get FLKV failed!");
  1342. }
  1343. return true;
  1344. }
  1345. float nsGEN::RYGENDevice::GetFluMA()
  1346. {
  1347. BYTE ucMode = 0x04;
  1348. CString strlog;
  1349. int nCurrentMA = HV_Handle_FLM(ucMode, 0, 0); // get current FLMA
  1350. if (nCurrentMA != -1)
  1351. {
  1352. float fCurrentMA = (float)nCurrentMA;
  1353. m_DoseUnit.m_FLMA->Update(fCurrentMA / 10.0f);
  1354. FireNotify(AttrKey::FLUMA, m_DoseUnit.m_FLMA->JSGet());
  1355. FINFO("GetFLMA success! nCurrentMA={$} m_fFLMA={$}", nCurrentMA, m_DoseUnit.m_FLMA->Get());
  1356. }
  1357. else
  1358. {
  1359. FINFO("GetFLMA failed!");
  1360. }
  1361. return true;
  1362. }
  1363. float nsGEN::RYGENDevice::GetFluMS()
  1364. {
  1365. return 0.0f;
  1366. }
  1367. bool nsGEN::RYGENDevice::GetABSMode()
  1368. {
  1369. int nCurrentMode = HV_Handle_FLF(4, 0, 0); // set current FL mode
  1370. if (nCurrentMode != -1)
  1371. {
  1372. FINFO("GetABSMode success!");
  1373. if (nCurrentMode == 3)
  1374. {
  1375. if (m_DoseUnit.m_ABSStatus->Update(1))
  1376. FireNotify(AttrKey::FLUABSStatus, m_DoseUnit.m_ABSStatus->JSGet());
  1377. }
  1378. else
  1379. {
  1380. if (m_DoseUnit.m_ABSStatus->Update(0))
  1381. FireNotify(AttrKey::FLUABSStatus, m_DoseUnit.m_ABSStatus->JSGet());
  1382. }
  1383. }
  1384. return true;
  1385. }
  1386. bool nsGEN::RYGENDevice::GetAECDensityBuff(void)
  1387. {
  1388. int nRet = HV_Handle_FN(2, 0, 0);
  1389. if (m_DoseUnit.m_AECDensity->Update(nRet))
  1390. FireNotify(AttrKey::AECDENSITY, m_DoseUnit.m_AECDensity->JSGet());
  1391. return true;
  1392. }
  1393. bool nsGEN::RYGENDevice::GetAECFieldBuff(void)
  1394. {
  1395. int nCurrentFiled = HV_Handle_FI(2, 0, 0);
  1396. int nCurrentAECFieldSel = 0;
  1397. if (nCurrentFiled & (0x01))
  1398. {
  1399. nCurrentAECFieldSel += 100;
  1400. }
  1401. if (nCurrentFiled & (0x02))
  1402. {
  1403. nCurrentAECFieldSel += 10;
  1404. }
  1405. if (nCurrentFiled & (0x04))
  1406. {
  1407. nCurrentAECFieldSel += 1;
  1408. }
  1409. FDEBUG("GetAECFieldBuff={$},nCurrentFiled={$}", nCurrentAECFieldSel, nCurrentFiled);
  1410. if (m_DoseUnit.m_AECField->Update(nCurrentFiled))
  1411. FireNotify(AttrKey::AECFIELD, m_DoseUnit.m_AECField->JSGet());
  1412. return true;
  1413. }
  1414. RET_STATUS nsGEN::RYGENDevice::SetFrameRate(FLOAT frameRate)
  1415. {
  1416. m_DoseUnit.m_FrameRate->Update(frameRate); //this variable should be set when in oncallback.
  1417. return RET_STATUS::RET_SUCCEED;
  1418. }
  1419. RET_STATUS nsGEN::RYGENDevice::SetRPS(int rps)
  1420. {
  1421. return RET_STATUS::RET_SUCCEED;
  1422. }
  1423. RET_STATUS nsGEN::RYGENDevice::RefreshData()
  1424. {
  1425. return RET_STATUS::RET_SUCCEED;
  1426. }
  1427. RET_STATUS nsGEN::RYGENDevice::SetExpEnable()
  1428. {
  1429. FINFO("SetExpEnable in ...\n");
  1430. int nStatus = HV_GetST();
  1431. if (nStatus == 200)
  1432. {
  1433. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
  1434. }
  1435. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1436. return RET_STATUS::RET_SUCCEED;
  1437. }
  1438. RET_STATUS nsGEN::RYGENDevice::SetExpDisable()
  1439. {
  1440. FINFO("SetExpDisable in...\n");
  1441. int nStatus = HV_GetST();
  1442. if (nStatus == 200)
  1443. {
  1444. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
  1445. }
  1446. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1447. FINFO("SetExpDisable... {$}\n", m_DoseUnit.m_GenState->JSGet().c_str());
  1448. return RET_STATUS::RET_SUCCEED;
  1449. }
  1450. RET_STATUS nsGEN::RYGENDevice::Reset()
  1451. {
  1452. m_bResetActive = true;
  1453. FINFO("RESET in...\n");
  1454. int level = 0;
  1455. if (m_bError)
  1456. {
  1457. m_MSGUnit->DelErrorMessage("0", level, "clear all errors");
  1458. m_MSGUnit->DelWarnMessage("0", level, "clear all Warning");
  1459. if (HV_Handle_CLR(0, 1, 0))
  1460. {
  1461. m_bError = false;
  1462. FINFO("ReSet generator success, Clear Error,set apr command");
  1463. }
  1464. else
  1465. {
  1466. FINFO("ReSet generator fail");
  1467. }
  1468. }
  1469. return RET_STATUS::RET_SUCCEED;
  1470. }
  1471. LRESULT nsGEN::RYGENDevice::RYAPIMSG(WPARAM wParam, LPARAM lParam)
  1472. {
  1473. int nMessageType = (int)wParam;
  1474. switch (nMessageType)
  1475. {
  1476. case OBM_WPM_PR: //曝光曝光准备/结束
  1477. {
  1478. HandlePRMsg(int(lParam));
  1479. }
  1480. break;
  1481. case OBM_WPM_XR: //曝光开始/结束
  1482. {
  1483. HandleXRMsg(int(lParam));
  1484. }
  1485. break;
  1486. case OBM_WPM_ST: //系统状态反馈
  1487. {
  1488. HandleSTMsg(int(lParam));
  1489. }
  1490. break;
  1491. case OBM_WPM_AT: //系统状态反馈
  1492. {
  1493. HandleATMsg(int(lParam));
  1494. }
  1495. break;
  1496. case OBM_WPM_SV: //界面模式切换反馈
  1497. {
  1498. HandleSVMsg(int(lParam));
  1499. }
  1500. break;
  1501. case OBM_WPM_TE: //技术参数反馈
  1502. {
  1503. HandleTEMsg(int(lParam));
  1504. }
  1505. break;
  1506. case OBM_WPM_ER: //不可清错误反馈
  1507. {
  1508. HandleERMsg(int(lParam));
  1509. }
  1510. break;
  1511. case OBM_WPM_EL: //可清错误反馈
  1512. {
  1513. HandleELMsg(int(lParam));
  1514. }
  1515. break;
  1516. case OBM_WPM_COK: //本轮自动校管结束
  1517. {
  1518. HandleCOKMsg(int(lParam));
  1519. }
  1520. break;
  1521. case OBM_WPM_CLR: //清除CLR状态
  1522. {
  1523. HandleCLRMsg(int(lParam));
  1524. }
  1525. break;
  1526. case OBM_WPM_HE: //热容量模式
  1527. {
  1528. HandleHEMsg(int(lParam));
  1529. }
  1530. break;
  1531. case OBM_WPM_FLP: //fluoro prepare
  1532. {
  1533. HandleFLPMsg(int(lParam));
  1534. }
  1535. break;
  1536. case OBM_WPM_FLX: //fluoro exposure
  1537. {
  1538. HandleFLXMsg(int(lParam));
  1539. }
  1540. break;
  1541. case OBM_WPM_FLK: //fluoro kv
  1542. {
  1543. HandleFLKMsg(int(lParam));
  1544. }
  1545. break;
  1546. case OBM_WPM_FLM: //fluoro ma
  1547. {
  1548. HandleFLMMsg(int(lParam));
  1549. }
  1550. break;
  1551. case OBM_WPM_FLF: //fluoro mode
  1552. {
  1553. HandleFLFMsg(int(lParam));
  1554. }
  1555. break;
  1556. case OBM_WPM_FLI: //透视定时器累加时间
  1557. {
  1558. HandleFLIMsg(int(lParam));
  1559. }
  1560. break;
  1561. case OBM_WPM_FLR: //透视定时器已清零
  1562. {
  1563. HandleFLRMsg(int(lParam));
  1564. }
  1565. break;
  1566. case OBM_WPM_FLIW:
  1567. {
  1568. HandleFLIWMsg(int(lParam));
  1569. }
  1570. break;
  1571. case OBM_WPM_KV:
  1572. {
  1573. FINFO("Enter OBM_WPM_KV lParam is {$}", int(lParam));
  1574. int nKV = int(lParam);
  1575. if (nKV >= 40) //曾经出现过kv0的情况,所以添加限制。
  1576. {
  1577. if (m_DoseUnit.m_KV->Update(nKV))
  1578. FireNotify("KV", m_DoseUnit.m_KV->JSGet());
  1579. }
  1580. }
  1581. break;
  1582. case OBM_WPM_MS:
  1583. {
  1584. FINFO("Enter OBM_WPM_MS lParam is {$}", int(lParam));
  1585. int nMS = int(lParam);
  1586. if (m_DoseUnit.m_MS->Update(nMS))
  1587. FireNotify("MS", m_DoseUnit.m_MS->JSGet());
  1588. }
  1589. break;
  1590. case OBM_WPM_MA:
  1591. {
  1592. FINFO("Enter OBM_WPM_MA lParam is {$}", int(lParam));
  1593. int nMA = int(lParam);
  1594. if (m_DoseUnit.m_MA->Update(nMA))
  1595. FireNotify("MA", m_DoseUnit.m_MA->JSGet());
  1596. }
  1597. break;
  1598. }
  1599. return 0;
  1600. }
  1601. RET_STATUS nsGEN::RYGENDevice::HWSend(char* strCommand, int nTimeOut)
  1602. {
  1603. return RET_STATUS::RET_SUCCEED;
  1604. }
  1605. //-----------------------------------------------------------------------------
  1606. // ProcessCmd
  1607. //-----------------------------------------------------------------------------
  1608. void nsGEN::RYGENDevice::FireNotify(std::string key, std::string content)
  1609. {
  1610. EventCenter->OnNotify(1, key, content);
  1611. }
  1612. struct tFrameMapping
  1613. {
  1614. static const int MaxLen = 5; // 前缀不能超超过 5 个字符 !
  1615. using cbFun = std::function <void(const char*, int)>;
  1616. char strHead[MaxLen];
  1617. int NbOfCharOfHead;
  1618. cbFun fun;
  1619. tFrameMapping(char* str, int len, cbFun f)
  1620. {
  1621. assert(len < MaxLen); //len最大只能是4
  1622. //strHead[0] = 0x02; //STX ----------->note : no package header
  1623. for (int i = 0; i < len; i++) //给strHead赋值
  1624. strHead[i] = str[i];
  1625. NbOfCharOfHead = len;
  1626. fun = f;
  1627. }
  1628. };
  1629. static std::list <tFrameMapping> arFrame;
  1630. static bool DecodeFrame(const char* strFrame, int length);
  1631. LRESULT CALLBACK nsGEN::RYGENDevice::OnCallBack(void* obj, UINT message, WPARAM wParam, LPARAM lParam)
  1632. {
  1633. RYGENDevice* unit = (RYGENDevice*)obj;
  1634. if (unit == nullptr)
  1635. {
  1636. FINFO("Enter OnCallBack: RYGENDevice is null");
  1637. return false;
  1638. }
  1639. int wmId, wmEvent;
  1640. PAINTSTRUCT ps;
  1641. HDC hdc;
  1642. FDEBUG("Enter OnCallBack: message[{$}],wParam[{$}],lParam[{$}]", (int)message, (int)wParam, (int)lParam);
  1643. switch (message)
  1644. {
  1645. case WM_COMMAND:
  1646. wmId = LOWORD(wParam);
  1647. wmEvent = HIWORD(wParam);
  1648. // 分析菜单选择:
  1649. switch (wmId)
  1650. {
  1651. case 0:
  1652. break;
  1653. }
  1654. switch (wmId)
  1655. {
  1656. case 0:
  1657. break;
  1658. default:
  1659. break;
  1660. }
  1661. case WM_HV_TABLE_IO_MESSAGE:
  1662. unit->RYAPIMSG(wParam, lParam);
  1663. break;
  1664. }
  1665. return 0;
  1666. }
  1667. bool nsGEN::RYGENDevice::StartHardwareStatusThread()
  1668. {
  1669. FINFO("enter Start HardwareStatus Thread ");
  1670. if (m_pHardwareStatusThread == NULL)
  1671. {
  1672. DWORD m_HardwareStatusID;
  1673. m_pHardwareStatusThread = CreateThread(0, 0, HardwareStatusThread, this, 0, &m_HardwareStatusID);
  1674. if (m_pHardwareStatusThread == NULL)
  1675. {
  1676. Fatal("Start HardwareStatus Thread Failed");
  1677. return false;
  1678. }
  1679. }
  1680. return true;
  1681. }
  1682. DWORD nsGEN::RYGENDevice::HardwareStatusThread(LPVOID pParam)
  1683. {
  1684. RYGENDevice* pCurGen = (RYGENDevice*)pParam;
  1685. if (pCurGen == NULL)
  1686. {
  1687. return false;
  1688. }
  1689. if ((int)pCurGen->m_GenConfig["loopTime"] >= 100)
  1690. {
  1691. pCurGen->m_iLoopTime = (int)pCurGen->m_GenConfig["loopTime"];
  1692. }
  1693. FDEBUG("loopTime = {$}", pCurGen->m_iLoopTime.load());
  1694. int currtTime = pCurGen->m_iLoopTime;
  1695. FINFO("HardwareStatusThread start");
  1696. while (false)
  1697. {
  1698. if (pCurGen->m_iLoopTime!= currtTime)
  1699. {
  1700. FINFO("pCurGen->m_iLoopTime");
  1701. }
  1702. currtTime = pCurGen->m_iLoopTime;
  1703. Sleep(currtTime);
  1704. }
  1705. FINFO("HardwareStatusThread stop");
  1706. return true;
  1707. }
  1708. void nsGEN::RYGENDevice::HandlePRMsg(int nMessageValue)
  1709. {
  1710. FINFO("Enter HandlePRMsg lParam is {$}", nMessageValue);
  1711. if (LPM_CONSOLE_PR1 == nMessageValue)
  1712. {
  1713. m_iLoopTime = RYGEN_LoopExpTime;
  1714. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_PREPARE);
  1715. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1716. }
  1717. else if (LPM_CONSOLE_PR2 == nMessageValue)
  1718. {
  1719. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_READY);
  1720. ResetEvent(m_hGenPostEvent);
  1721. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1722. }
  1723. else if (LPM_CONSOLE_PR0 == nMessageValue)
  1724. {
  1725. if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF));
  1726. {
  1727. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1728. }
  1729. }
  1730. }
  1731. void nsGEN::RYGENDevice::HandleXRMsg(int nMessageValue)
  1732. {
  1733. FINFO("Enter HandleXRMsg lParam is {$}", nMessageValue);
  1734. if (nMessageValue == LPM_CONSOLE_XR1)
  1735. {
  1736. if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_EXP))
  1737. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1738. if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON))
  1739. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1740. }
  1741. else if (nMessageValue == LPM_CONSOLE_XR0)
  1742. {
  1743. if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYOFF))
  1744. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1745. }
  1746. }
  1747. void nsGEN::RYGENDevice::HandleSTMsg(int nMessageValue)
  1748. {
  1749. FINFO("Enter HandleSTMsg lParam is {$}", nMessageValue);
  1750. switch (nMessageValue)
  1751. {
  1752. case LPM_CONSOLE_ST000:
  1753. {
  1754. }
  1755. break;
  1756. case LPM_CONSOLE_ST001:
  1757. {
  1758. }
  1759. break;
  1760. case LPM_CONSOLE_ST100:
  1761. case LPM_CONSOLE_ST101:
  1762. case LPM_CONSOLE_ST102:
  1763. case LPM_CONSOLE_ST103:
  1764. case LPM_CONSOLE_ST104:
  1765. case LPM_CONSOLE_ST105:
  1766. case LPM_CONSOLE_ST106:
  1767. {
  1768. }
  1769. break;
  1770. case LPM_CONSOLE_ST200:
  1771. {
  1772. int nVal = HV_Handle_SV(1, 0, 0);
  1773. int nRet = -1;
  1774. if (nVal != 0)
  1775. {
  1776. nRet = HV_Handle_SV(0, 0, 0); // enter work mode
  1777. if (nRet == -1)
  1778. {
  1779. FINFO("HV_Handle_SV work failed");
  1780. }
  1781. }
  1782. nVal = HV_Handle_EM(4, 0, 0);
  1783. if (nVal != 1)
  1784. {
  1785. nRet = HV_Handle_EM(5, 1, 0);
  1786. if (nRet == -1)
  1787. {
  1788. FINFO("HV_Handle_EM work failed");
  1789. }
  1790. }
  1791. UpdateGenParamter();
  1792. GetFluKV();
  1793. GetFluMA();
  1794. GetABSMode();
  1795. if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY))
  1796. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1797. }
  1798. break;
  1799. }
  1800. }
  1801. void nsGEN::RYGENDevice::HandleATMsg(int nMessageValue)
  1802. {
  1803. FINFO("Enter HandleATMsg lParam is {$}", nMessageValue);
  1804. }
  1805. void nsGEN::RYGENDevice::HandleSVMsg(int nMessageValue)
  1806. {
  1807. FINFO("Enter HandleSVMsg lParam is {$}", nMessageValue);
  1808. if (nMessageValue == LPM_CONSOLE_SV0)
  1809. {
  1810. int nRet = HV_Handle_EM(5, 1, 0);
  1811. if (nRet == -1)
  1812. {
  1813. FINFO("HV_Handle_EM work failed");
  1814. }
  1815. SetFLFMode(m_strFLFMode);
  1816. SetPPS(m_fpps);
  1817. SetTechmode(m_nPreET);
  1818. _tAPRArgs t;
  1819. t.nWS = m_nPreWS;
  1820. t.fKV = m_nPreKV;
  1821. t.fMA = m_fPreMA;
  1822. t.fMS = m_fPreMS;
  1823. t.fMAS = m_fPreMAS;
  1824. t.nAECDensity = m_nPreAECDensity;
  1825. t.nAECField = m_nPreAECFieldSel;
  1826. t.nAECFilm = m_nPreAECFilmSel;
  1827. t.nFocus = m_nPreFO;
  1828. t.nTechmode = m_nPreET;
  1829. SetAPR(t);
  1830. int nABSMode = m_DoseUnit.m_ABSStatus->Get();
  1831. int nFLF = m_DoseUnit.m_FLMode->Get();
  1832. _tAPFArgs tf;
  1833. tf.nFluMode = m_DoseUnit.m_FLMode->Get();
  1834. tf.nABSMode = m_DoseUnit.m_ABSStatus->Get();
  1835. tf.nFLKV= m_DoseUnit.m_FLKV->Get();
  1836. tf.fFLMA = m_DoseUnit.m_FLMA->Get();
  1837. SetAPF(tf);
  1838. }
  1839. }
  1840. void nsGEN::RYGENDevice::HandleTEMsg(int nMessageValue)
  1841. {
  1842. if (m_DoseUnit.m_Techmode->Update(nMessageValue))
  1843. FireNotify(AttrKey::TECHMODE, m_DoseUnit.m_Techmode->JSGet());
  1844. if (m_DoseUnit.m_Techmode->Get() != 2)
  1845. {
  1846. if (m_DoseUnit.m_AECField->Get() != 0)
  1847. {
  1848. FireNotify(AttrKey::AECFIELD, "0");
  1849. }
  1850. }
  1851. FINFO("Enter HandleTEMsg lParam is {$}", nMessageValue);
  1852. }
  1853. void nsGEN::RYGENDevice::HandleERMsg(int nMessageValue)
  1854. {
  1855. m_bError = true;
  1856. char ErrorCode[20]; // Adjust size as needed
  1857. sprintf_s(ErrorCode, sizeof(ErrorCode), "RYGEN_ERR_%d", nMessageValue);
  1858. FINFO("error code:{$}", ErrorCode); // Logging the error code
  1859. // Error message initialization
  1860. std::string errorMsg;
  1861. // Switch statement to assign the correct error message based on nMessageValue
  1862. switch (nMessageValue) {
  1863. case 0: errorMsg = "Communication failure between main control and console."; break;
  1864. case 1: errorMsg = "Stage 1 brake engagement detected during self-test."; break;
  1865. case 2: errorMsg = "Stage 2 brake engagement detected during self-test."; break;
  1866. case 3: errorMsg = "Main control issued a soft start signal; PHVOK signal from power board not received within 2 seconds."; break;
  1867. case 4: errorMsg = "Bus voltage AD feedback value too high during soft start."; break;
  1868. case 5: errorMsg = "Bus voltage AD feedback value too low during soft start."; break;
  1869. case 6: errorMsg = "SAMFAULT signal low level detected during self-test on the main control board."; break;
  1870. case 7: errorMsg = "Bus voltage AD feedback value too high after main contactor engagement."; break;
  1871. case 8: errorMsg = "Bus voltage AD feedback value too low after main contactor engagement."; break;
  1872. case 9: errorMsg = "SLINK high level detected during self-test, possibly KV/MA feedback line not connected to tank."; break;
  1873. case 10: errorMsg = "STLOW low output detected during self-test on the start board."; break;
  1874. case 11: errorMsg = "Filament board FLIAFAULT hard signal low level detected before heating filament during self-test."; break;
  1875. case 12: errorMsg = "Small filament current AD feedback fault detected after heating small filament during self-test."; break;
  1876. case 13: errorMsg = "FLIAFAULT hard signal low level detected after heating large filament during self-test."; break;
  1877. case 14: errorMsg = "Large filament AD feedback fault detected after heating during self-test."; break;
  1878. case 15: errorMsg = "PHVOK signal detected high during standby."; break;
  1879. case 16: errorMsg = "High bus voltage AD feedback value detected during standby."; break;
  1880. case 17: errorMsg = "Low bus voltage AD feedback value detected during standby."; break;
  1881. case 18: errorMsg = "Tube temperature control signal fault detected during standby."; break;
  1882. case 19: errorMsg = "Main control to tank KV/MA feedback line not connected detected during standby."; break;
  1883. case 20: errorMsg = "Fault detected during read/write of 2864."; break;
  1884. case 21: errorMsg = "Stage 1 brake pressed under configuration interface."; break;
  1885. case 22: errorMsg = "Low filament current AD feedback value detected during standby filament pre-heating."; break;
  1886. case 23: errorMsg = "High filament current AD feedback value detected during standby filament pre-heating."; break;
  1887. case 24: errorMsg = "Filament current exceeds maximum value, FILAFAULT hard signal interrupts."; break;
  1888. case 25: errorMsg = "SAMFAULT interrupts."; break;
  1889. case 26: errorMsg = "Interrupts caused by other signals."; break;
  1890. case 28: errorMsg = "FILIAFAULT signal low level detected during filament rapid heating process."; break;
  1891. case 29: errorMsg = "STLOW low level detected after tube starts during post-self-test."; break;
  1892. case 30: errorMsg = "Communication failure between main control and console during exposure preparation."; break;
  1893. case 33: errorMsg = "No signal detected for stage 2 brake during self-test."; break;
  1894. case 34: errorMsg = "Communication failure; no signal return from console within 1 second after sending XR1."; break;
  1895. case 35: errorMsg = "KVAD feedback too low fault; KV not rising to 75% of set value within 1ms after exposure starts."; break;
  1896. case 38: errorMsg = "Hand 2 not released more than 8 seconds after exposure ends."; break;
  1897. case 39: errorMsg = "Hand 1 not released more than 10 seconds after exposure ends."; break;
  1898. case 40: errorMsg = "AECEND signal fault detected just as automatic exposure starts."; break;
  1899. case 41: errorMsg = "Door switch fault."; break;
  1900. case 42: errorMsg = "FILIAFAULT signal low level detected during filament rapid heating process."; break;
  1901. case 43: errorMsg = "STLOW low level detected after tube starts."; break;
  1902. case 44: errorMsg = "Communication failure during preparation process."; break;
  1903. case 45: errorMsg = "Hand 2 not received more than 6 seconds after tube is ready."; break;
  1904. case 47: errorMsg = "KVAD feedback too low fault; KV not rising to 75% of set value within 1ms after exposure starts."; break;
  1905. case 48: errorMsg = "AECEND not received, stage 2 brake released prematurely."; break;
  1906. case 49: errorMsg = "Hand 1 not released more than 10 seconds after exposure ends."; break;
  1907. case 50: errorMsg = "Door switch fault."; break;
  1908. case 51: errorMsg = "FILAFAULT fault."; break;
  1909. case 52: errorMsg = "STLOW fault detected during first start-up."; break;
  1910. case 53: errorMsg = "Communication failure during exposure preparation."; break;
  1911. case 54: errorMsg = "Hand 2 signal not received more than 6 seconds."; break;
  1912. case 55: errorMsg = "Stage 2 brake released prematurely."; break;
  1913. case 56: errorMsg = "Communication fault during exposure."; break;
  1914. case 57: errorMsg = "KVAD feedback too low fault; KV not rising to 75 % of set value within 1ms after exposure starts."; break;
  1915. case 58: errorMsg = "Hand brake released prematurely."; break;
  1916. case 61: errorMsg = "Small focus filament value too high, exceeding 2350."; break;
  1917. case 62: errorMsg = "Large focus filament value too high, exceeding 2100."; break;
  1918. case 63: errorMsg = "Continuous two - point calibration failure, automatic tube training fails."; break;
  1919. case 64: errorMsg = "Filament current AD feedback value detected below 20 % of set value after filament heating."; break;
  1920. case 65: errorMsg = "Filament current AD feedback value detected above 20 % of set value after filament heating."; break;
  1921. case 66: errorMsg = "Filament current AD feedback value detected below 20 % of set value after filament heating."; break;
  1922. case 67: errorMsg = "Filament current AD feedback value detected above 20 % of set value after filament heating."; break;
  1923. case 70: errorMsg = "PHVOK high level detected by main control 3 seconds after main contactor powers up."; break;
  1924. case 73: errorMsg = "High anode auxiliary winding current AD feedback value detected during tube start(dual - speed board)."; break;
  1925. case 74: errorMsg = "Low anode main winding current AD feedback value detected during tube start(dual - speed board)."; break;
  1926. case 75: errorMsg = "Low anode main winding current AD feedback value detected during tube start(dual - speed board)."; break;
  1927. case 82: errorMsg = "High anode main winding current AD feedback value detected during tube start."; break;
  1928. case 83: errorMsg = "Low anode main winding current AD feedback value detected during tube start."; break;
  1929. case 84: errorMsg = "Low anode auxiliary winding current AD feedback value detected during tube start."; break;
  1930. case 85: errorMsg = "High anode auxiliary winding current AD feedback value detected during tube start."; break;
  1931. case 86: errorMsg = "Hand 2 not released more than 5 seconds after exposure ends."; break;
  1932. case 160: errorMsg = "High filament value detected."; break;
  1933. case 207: errorMsg = "Communication fault during exposure."; break;
  1934. case 214: errorMsg = "Encountered unsuitable parameters."; break;
  1935. default: errorMsg = "HandleERMsg:unknown error."; break; // Default case for unknown error codes
  1936. }
  1937. int level = 1; // Assuming error level 1 for all cases, adjust as needed
  1938. m_MSGUnit->AddErrorMessage(ErrorCode, level, errorMsg.c_str());
  1939. m_localErrorlist.push_back(ErrorCode); // Adding error code to local error list
  1940. }
  1941. void nsGEN::RYGENDevice::HandleELMsg(int nMessageValue)
  1942. {
  1943. m_bError = true;
  1944. char ErrorCode[20]; // 根据需要调整数组大小
  1945. sprintf_s(ErrorCode, sizeof(ErrorCode), "RYGEN_EL_%d", nMessageValue);
  1946. FINFO("error code:{$} \n", ErrorCode);
  1947. std::string errorMsg;
  1948. // Switch statement to assign the correct error message based on nMessageValue
  1949. switch (nMessageValue) {
  1950. case 12: errorMsg = "Small filament current AD feedback fault detected after heating small filament during self - test."; break;
  1951. case 14: errorMsg = "Large filament AD feedback fault detected after heating large filament during self - test."; break;
  1952. case 17: errorMsg = "timeout_prpe."; break;
  1953. case 25: errorMsg = "SAMFAULT interrupts."; break;
  1954. case 27: errorMsg = "Stage 1 brake pressed, enters normal photography program, high - level door switch signal detected."; break;
  1955. case 29: errorMsg = "STLOW low level detected after tube starts during post - self - test."; break;
  1956. case 31: errorMsg = "Hand 2 signal not received more than 9 seconds after tube is ready."; break;
  1957. case 32: errorMsg = "High - level door switch detected."; break;
  1958. case 33: errorMsg = "No signal detected for stage 2 brake during self - test."; break;
  1959. case 46: errorMsg = "Door switch fault."; break;
  1960. case 60: errorMsg = "High tube heat capacity HEVALUE error."; break;
  1961. case 103: errorMsg = "No feedback signal received from tablet."; break;
  1962. case 160: errorMsg = "High filament value detected."; break;
  1963. case 200: errorMsg = "AEC feature used in spot filming mode."; break;
  1964. case 207: errorMsg = "Communication fault during exposure."; break;
  1965. default: errorMsg = "HandleELMsg:unknown error."; break; // Default case for unknown error codes
  1966. }
  1967. int level = 1;
  1968. m_MSGUnit->AddErrorMessage(ErrorCode, level, errorMsg.c_str());
  1969. m_localErrorlist.push_back(ErrorCode);
  1970. }
  1971. void nsGEN::RYGENDevice::HandleCOKMsg(int nMessageValue)
  1972. {
  1973. FINFO("Enter HandleCOKMsg lParam is {$}", nMessageValue);
  1974. }
  1975. void nsGEN::RYGENDevice::HandleCLRMsg(int nMessageValue)
  1976. {
  1977. FINFO("Enter HandleCLRMsg lParam is {$}", nMessageValue);
  1978. if (nMessageValue == LPM_CONSOLE_CLR1)
  1979. FINFO("清除CLR有效");
  1980. }
  1981. void nsGEN::RYGENDevice::HandleHEMsg(int nMessageValue)
  1982. {
  1983. FINFO("Enter HandleHEMsg lParam is {$}", nMessageValue);
  1984. if (m_DoseUnit.m_HE->Update(nMessageValue))
  1985. FireNotify(m_DoseUnit.m_HE->GetKey(), m_DoseUnit.m_HE->JSGet());
  1986. }
  1987. void nsGEN::RYGENDevice::HandleFIMsg(int nMessageValue)
  1988. {
  1989. FINFO("Enter HandleFIMsg lParam is {$}", nMessageValue);
  1990. }
  1991. void nsGEN::RYGENDevice::HandleFNMsg(int nMessageValue)
  1992. {
  1993. FINFO("Enter HandleFNMsg lParam is {$}", nMessageValue);
  1994. }
  1995. void nsGEN::RYGENDevice::HandleFSMsg(int nMessageValue)
  1996. {
  1997. FINFO("Enter HandleFSMsg lParam is {$}", nMessageValue);
  1998. }
  1999. void nsGEN::RYGENDevice::HandleFLPMsg(int nMessageValue)
  2000. {
  2001. FINFO("Enter HandleFLPMsg lParam is {$}", nMessageValue);
  2002. if (nMessageValue == LPM_CONSOLE_FLP0)
  2003. {
  2004. if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_OFF))
  2005. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  2006. FINFO("The foot brake up!!!");
  2007. }
  2008. else if (nMessageValue == LPM_CONSOLE_FLP1)
  2009. {
  2010. if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_READY))
  2011. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  2012. FINFO("Foot brake down!!!");
  2013. }
  2014. else
  2015. {
  2016. FINFO("Wrong message");
  2017. }
  2018. }
  2019. void nsGEN::RYGENDevice::HandleFLXMsg(int nMessageValue)
  2020. {
  2021. FINFO("Enter HandleFLXMsg lParam is{$}", nMessageValue);
  2022. if (nMessageValue == LPM_CONSOLE_FLX0)
  2023. {
  2024. if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_XRAYOFF))
  2025. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  2026. //UpdateGenParamter();
  2027. FINFO("The generator is off line!!!");
  2028. }
  2029. else if (nMessageValue == LPM_CONSOLE_FLX1)
  2030. {
  2031. if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_XRAYON))
  2032. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  2033. if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_EXP))
  2034. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  2035. FINFO("The generator is out of line!!!");
  2036. }
  2037. else
  2038. {
  2039. FINFO("Wrong message");
  2040. }
  2041. }
  2042. void nsGEN::RYGENDevice::HandleFLKMsg(int nMessageValue)
  2043. {
  2044. FINFO("Enter HandleFLKMsg lParam is {$}", nMessageValue);
  2045. if (m_DoseUnit.m_FLKV->Update(nMessageValue))
  2046. FireNotify(AttrKey::FLUKV, m_DoseUnit.m_FLKV->JSGet());
  2047. }
  2048. void nsGEN::RYGENDevice::HandleFLMMsg(int nMessageValue)
  2049. {
  2050. FINFO("Enter HandleFLMMsg lParam is {$}", nMessageValue);
  2051. if (nMessageValue + 5 <= 200)
  2052. {
  2053. if (m_DoseUnit.m_FLMA->Update((float)(nMessageValue + 5) / 10.0f))
  2054. FireNotify(AttrKey::FLUMA, m_DoseUnit.m_FLMA->JSGet());
  2055. }
  2056. else
  2057. {
  2058. if (m_DoseUnit.m_FLMA->Update(20 + (nMessageValue - 195)))
  2059. FireNotify(AttrKey::FLUMA, m_DoseUnit.m_FLMA->JSGet());
  2060. }
  2061. }
  2062. void nsGEN::RYGENDevice::HandleFLFMsg(int nMessageValue)
  2063. {
  2064. FINFO("Enter HandleFLFMsg lParam is {$}", nMessageValue);
  2065. int nABSMode = 0;
  2066. if (nMessageValue == 3)
  2067. {
  2068. nABSMode = 1;
  2069. }
  2070. else
  2071. {
  2072. nABSMode = 0;
  2073. }
  2074. if (m_DoseUnit.m_ABSStatus->Update(nABSMode))
  2075. {
  2076. FireNotify(AttrKey::FLUABSStatus, m_DoseUnit.m_ABSStatus->JSGet());
  2077. FINFO("m_nABSMode = {$}", m_DoseUnit.m_ABSStatus->JSGet().c_str());
  2078. }
  2079. }
  2080. void nsGEN::RYGENDevice::HandleFLIMsg(int nMessageValue)
  2081. {
  2082. FINFO("Enter HandleFLIMsg lParam is {$}", nMessageValue);
  2083. if (m_DoseUnit.m_FLAccTime->Update(nMessageValue))
  2084. {
  2085. std::string strFlAccTime = m_DoseUnit.m_FLAccTime->JSGet() + "s";
  2086. FireNotify(AttrKey::FLUAccTime, m_DoseUnit.m_FLAccTime->JSGet());
  2087. }
  2088. FINFO("callback: m_fFLAccTime = {$}", m_DoseUnit.m_FLAccTime->JSGet().c_str());
  2089. }
  2090. void nsGEN::RYGENDevice::HandleFLRMsg(int nMessageValue)
  2091. {
  2092. FINFO("Enter HandleFLRMsg lParam is {$}", nMessageValue);
  2093. }
  2094. void nsGEN::RYGENDevice::HandleFLIWMsg(int nMessageValue)
  2095. {
  2096. FINFO("Enter HandleFLIWMsg lParam is {$}", nMessageValue);
  2097. }
  2098. bool nsGEN::RYGENDevice::UpdateGenParamter()
  2099. {
  2100. BYTE ucMode = 0x03;
  2101. int iRrValue = 0;
  2102. iRrValue = HV_Handle_RR(0, 0);
  2103. if (1 == iRrValue)
  2104. {
  2105. FINFO("HV_Handle_RR success");
  2106. GetKV();
  2107. GetMA();
  2108. GetMS();
  2109. GetMAS();
  2110. GetAECDensityBuff();
  2111. GetAECFieldBuff();
  2112. //GetFlMode();
  2113. return true;
  2114. }
  2115. else
  2116. {
  2117. FINFO("HV_Handle_RR failed");
  2118. }
  2119. return true;
  2120. }
  2121. //-----------------------------------------------------------------------------
  2122. // RYGENDriver
  2123. //-----------------------------------------------------------------------------
  2124. nsGEN::RYGENDriver::RYGENDriver()
  2125. {
  2126. m_bDemoMode = false;
  2127. m_bDemoConnected = false;
  2128. m_bGenConnectReal = false;
  2129. m_pUIOBJ = nullptr;
  2130. m_pUIOBJ = new UIObject();
  2131. FDEBUG("Init Gen Configuration Succeed[{$}]", (int)m_pUIOBJ);
  2132. }
  2133. nsGEN::RYGENDriver::~RYGENDriver()
  2134. {
  2135. m_pUIOBJ->Destrory();
  2136. delete m_pUIOBJ;
  2137. }
  2138. auto nsGEN::RYGENDriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
  2139. {
  2140. FINFO("CreateDevice in\n");
  2141. if (m_pUIOBJ->Create())
  2142. {
  2143. m_bGenConnectReal = true;
  2144. FDEBUG("Connect successful");
  2145. }
  2146. else
  2147. {
  2148. m_bGenConnectReal = false;
  2149. m_pUIOBJ->Destrory();
  2150. }
  2151. if (m_pUIOBJ)
  2152. {
  2153. m_pDevice = new RYGENDevice(EventCenter, m_pUIOBJ, m_ConfigFileName);
  2154. auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDevice));
  2155. FINFO("CreateDevice out\n");
  2156. return dev;
  2157. }
  2158. return NULL;
  2159. }
  2160. void nsGEN::RYGENDriver::FireNotify(int code, std::string key, std::string content)
  2161. {
  2162. EventCenter->OnNotify(code, key, content);
  2163. }
  2164. Log4CPP::Logger* gLogger = nullptr;
  2165. void nsGEN::RYGENDriver::Prepare()
  2166. {
  2167. string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Generator\Conf\Log4CPP.Config.GEN.xml)";
  2168. Log4CPP::GlobalContext::Map::Set(ECOM::Utility::Hash("LogFileName"), "GEN.RYGEN");
  2169. auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
  2170. gLogger = Log4CPP::LogManager::GetLogger("GEN.RYGEN");
  2171. FINFO("Enter Prepare.");
  2172. ResDataObject r_config;
  2173. if (r_config.loadFile(m_ConfigFileName.c_str()))
  2174. {
  2175. m_bDemoMode = (atoi)(((string)r_config["CONFIGURATION"]["IsDemo"]).c_str());
  2176. }
  2177. super::Prepare();
  2178. }
  2179. bool nsGEN::RYGENDevice::InitGen()
  2180. {
  2181. if (m_pUIOBJ->GetUI() == nullptr) {
  2182. FINFO("The window handle is empty!");
  2183. }
  2184. if (!HV_SetMsghWnd(m_pUIOBJ->GetUI())) {
  2185. FINFO("HV_SetMsghWnd:UNConnect");
  2186. return false;
  2187. }
  2188. FINFO("API_HV_SetMsghWnd success!");
  2189. HV_SetCanConfig();
  2190. FINFO("API_HV_SetCanConfig success!");
  2191. if (!HV_AddCanID(0x420, 0x401, 0)) {
  2192. FINFO("HV_AddCanID:UNConnect");
  2193. return false;
  2194. }
  2195. FINFO("API_HV_AddCanID success!");
  2196. HV_Init_ST();
  2197. FINFO("API_HV_Init_ST success!");
  2198. if (!HV_OpenCanDriver()) {
  2199. FINFO("HV_OpenCanDriver:UNConnect");
  2200. return false;
  2201. }
  2202. FINFO("API_HV_OpenCanDriver success!");
  2203. if (!HV_StartCanDriver()) {
  2204. FINFO("HV_StartCanDriver:UNConnect");
  2205. return false;
  2206. }
  2207. FINFO("API_HV_StartCanDriver success!");
  2208. if (!HV_ClearCanBuffer()) {
  2209. FINFO("HV_ClearCanBuffer:UNConnect");
  2210. return false;
  2211. }
  2212. FINFO("HV_ClearCanBuffer success!");
  2213. // 最终处理函数
  2214. int nStatus = HV_Handle_ST(0, 0, 0);
  2215. //HandleSTMsg(nStatus);
  2216. FINFO("GEN STATUS :{$}!", nStatus);
  2217. return SCF_ERR::SCF_SUCCEED; // 确保只有全部成功才返回
  2218. }
  2219. bool DATA_ACTION nsGEN::RYGENDriver::Connect()
  2220. {
  2221. FINFO("Enter {$},configlef={$}\n", __FUNCTION__, m_ConfigFileName.c_str());
  2222. return m_bGenConnectReal;
  2223. }
  2224. void nsGEN::RYGENDriver::Disconnect()
  2225. {
  2226. FDEBUG("Enter [{$}]", __FUNCTION__);
  2227. Close();
  2228. gLogger = nullptr;
  2229. }
  2230. bool nsGEN::RYGENDriver::isConnected() const
  2231. {
  2232. if (m_pDevice == NULL)
  2233. {
  2234. return false; //return 0;
  2235. }
  2236. if (m_pDevice->LoadConfig(m_ConfigFileName) == -1)
  2237. {
  2238. return false; //return 0;
  2239. }
  2240. return m_bGenConnectReal;
  2241. }
  2242. std::string nsGEN::RYGENDriver::DriverProbe()
  2243. {
  2244. FDEBUG("Enter [{$}]", __FUNCTION__);
  2245. ResDataObject r_config, HardwareInfo;
  2246. if (r_config.loadFile(m_ConfigFileName.c_str()))
  2247. {
  2248. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  2249. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  2250. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  2251. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  2252. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  2253. }
  2254. else
  2255. {
  2256. HardwareInfo.add("MajorID", "Generator");
  2257. HardwareInfo.add("MinorID", "Dr");
  2258. HardwareInfo.add("VendorID", "RYGEN");
  2259. HardwareInfo.add("ProductID", "HF");
  2260. HardwareInfo.add("SerialID", "Drv");
  2261. }
  2262. string ret = HardwareInfo.encode();
  2263. return ret;
  2264. }
  2265. std::string nsGEN::RYGENDriver::GetResource()
  2266. {
  2267. ResDataObject temp;
  2268. if (!temp.loadFile(m_ConfigFileName.c_str()))
  2269. return std::string();
  2270. auto r_config = temp["CONFIGURATION"];
  2271. for (auto& Item : m_ConfigInfo)
  2272. {
  2273. string key = Item.GetKey();
  2274. if (key == ConfKey::CcosGeneratorType)
  2275. {
  2276. Item.SetCurrentValue(((string)r_config["VendorID"]).c_str());
  2277. }
  2278. else if (key == ConfKey::CcosGeneratorModel)
  2279. {
  2280. Item.SetCurrentValue(((string)r_config["ProductID"]).c_str());
  2281. }
  2282. else if (key == ConfKey::CcosWSTable || key == ConfKey::CcosWSWall || key == ConfKey::CcosWSFree
  2283. || key == ConfKey::CcosWSTomo || key == ConfKey::CcosWSConventional)
  2284. {
  2285. Item.SetCurrentValue(((string)r_config[key.c_str()]).c_str());
  2286. }
  2287. else if (key == ConfKey::CcosSynTable || key == ConfKey::CcosSynWall || key == ConfKey::CcosSynFree
  2288. || key == ConfKey::CcosSynTomo || key == ConfKey::CcosSynConventional)
  2289. {
  2290. Item.SetCurrentValue(((string)r_config[key.c_str()]).c_str());
  2291. }
  2292. else if (key == ConfKey::CcosSCFType)
  2293. {
  2294. Item.SetCurrentValue(((string)r_config["connections"][0]["type"]).c_str());
  2295. }
  2296. else if (key == ConfKey::CcosSCFPort || key == ConfKey::CcosSCFBaudrate || key == ConfKey::CcosSCFBytesize
  2297. || key == ConfKey::CcosSCFParity || key == ConfKey::CcosSCFStopbits || key == ConfKey::CcosSCFIP)
  2298. {
  2299. if (r_config["connections"][0].GetFirstOf(key.c_str()) >= 0)
  2300. {
  2301. Item.SetCurrentValue(((string)r_config["connections"][0][key.c_str()]).c_str());
  2302. }
  2303. }
  2304. }
  2305. ResDataObject resAttr, resDescription;
  2306. for (auto Item : m_ConfigInfo)
  2307. {
  2308. resAttr.add(Item.GetKey(), Item.GetCurrentValue());
  2309. resDescription.add(Item.GetKey(), Item.GetDescription());
  2310. }
  2311. ResDataObject resDeviceResource;
  2312. resDeviceResource.add(ConfKey::CcosGeneratorAttribute, resAttr);
  2313. resDeviceResource.add(ConfKey::CcosGeneratorDescription, resDescription);
  2314. string res = resDeviceResource.encode();
  2315. //printf("resDeviceResource :%s \n", resDeviceResource.encode());
  2316. FINFO("resDeviceResource :{$} \n", resDeviceResource.encode());
  2317. ResDataObject DescriptionTempEx;
  2318. DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
  2319. m_DeviceConfig.clear();
  2320. m_DeviceConfig = DescriptionTempEx;
  2321. return res;
  2322. }
  2323. bool nsGEN::RYGENDriver::GetDeviceConfig(std::string& Cfg)
  2324. {
  2325. //Cfg = m_DeviceConfigSend.encode();
  2326. Cfg = m_DeviceConfig.encode();
  2327. //printf("GetDeviceConfig over");
  2328. printf("GetDeviceConfig over , %s", Cfg.c_str());
  2329. return true;
  2330. }
  2331. bool nsGEN::RYGENDriver::SetDeviceConfig(std::string Cfg)
  2332. {
  2333. FINFO("--Func-- SetDeviceConfig {$}\n", Cfg.c_str());
  2334. return true;
  2335. #if 0
  2336. ResDataObject DeviceConfig;
  2337. DeviceConfig.decode(Cfg.c_str());
  2338. ResDataObject DescriptionTempEx;
  2339. DescriptionTempEx = DeviceConfig["DeviceConfig"]["Attribute"];
  2340. FDEBUG("Attribute:{$}", DescriptionTempEx.encode());
  2341. bool bSaveFile = false; //true:重新保存配置文件
  2342. string strAccess = "";
  2343. for (int i = 0; i < DescriptionTempEx.size(); i++)
  2344. {
  2345. string strKey = DescriptionTempEx.GetKey(i);
  2346. FINFO("{$}", strKey.c_str());
  2347. try
  2348. {
  2349. if (m_pAttribute->GetFirstOf(strKey.c_str()) >= 0)
  2350. {
  2351. strAccess = (string)(*m_pDescription)[strKey.c_str()]["Access"];
  2352. if ("RW" == strAccess)
  2353. {
  2354. //修改对应配置,在其他单元的配置项要同时调用其修改函数修改真实值
  2355. //1. 修改内存中的值,用于给上层发消息
  2356. (*m_pAttribute)[strKey.c_str()] = DescriptionTempEx[i];
  2357. //2. 拿到Innerkey
  2358. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  2359. FINFO("nConfigInfoCount {$}", nConfigInfoCount);
  2360. string strTemp = ""; //存储AttributeKey
  2361. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  2362. {
  2363. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  2364. if (strTemp == strKey)
  2365. {
  2366. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  2367. break;
  2368. }
  2369. }
  2370. //3. 修改配置文件中的值
  2371. if (SetDeviceConfigValue(m_Configurations, strTemp.c_str(), 1, DescriptionTempEx[i]))
  2372. {
  2373. FDEBUG("SetDeviceConfigValue over");
  2374. bSaveFile = true;
  2375. }
  2376. }
  2377. else
  2378. {
  2379. FINFO("{$} is not a RW configuration item", strKey.c_str());
  2380. }
  2381. }
  2382. else
  2383. {
  2384. FINFO("without this attribute {$}", strKey.c_str());
  2385. }
  2386. }
  2387. catch (ResDataObjectExption& e)
  2388. {
  2389. FERROR("SetDriverConfig crashed: {$}", e.what());
  2390. return false;
  2391. }
  2392. }
  2393. if (bSaveFile)
  2394. {
  2395. //3. 重新保存配置文件
  2396. SaveConfigFile(true);
  2397. }
  2398. #endif // 0
  2399. return true;
  2400. }
  2401. bool nsGEN::RYGENDriver::SaveConfigFile(bool bSendNotify)
  2402. {
  2403. m_ConfigAll["CONFIGURATION"] = m_Configurations;
  2404. bool bRt = m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
  2405. FINFO("SaveConfigFile over {$}", bRt);
  2406. return true;
  2407. }
  2408. std::string nsGEN::RYGENDriver::DeviceProbe()
  2409. {
  2410. FDEBUG("Enter [{$}]", __FUNCTION__);
  2411. ResDataObject r_config, HardwareInfo;
  2412. if (r_config.loadFile(m_ConfigFileName.c_str()))
  2413. {
  2414. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  2415. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  2416. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  2417. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  2418. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  2419. }
  2420. else
  2421. {
  2422. HardwareInfo.add("MajorID", "Generator");
  2423. HardwareInfo.add("MinorID", "Dr");
  2424. HardwareInfo.add("VendorID", "RYGEN");
  2425. HardwareInfo.add("ProductID", "HF");
  2426. HardwareInfo.add("SerialID", "1234");
  2427. }
  2428. string ret = HardwareInfo.encode();
  2429. FINFO("std::string nsGEN::PSGRFDriver::DeviceProbe() out\n");
  2430. return ret;
  2431. }
  2432. void nsGEN::RYGENDriver::Dequeue(const char* Packet, DWORD Length)
  2433. {
  2434. DecodeFrame(Packet, Length);
  2435. }
  2436. PACKET_RET nsGEN::RYGENDriver::callbackPackageProcess(const char* RecData, DWORD nLength, DWORD& PacketLength)
  2437. {
  2438. return PACKET_ISPACKET;
  2439. }
  2440. //-----------------------------------------------------------------------------
  2441. // DecodeFrame
  2442. //-----------------------------------------------------------------------------
  2443. static bool DecodeFrame(const char* strFrame, int length)
  2444. {
  2445. return true;
  2446. }
  2447. //-----------------------------------------------------------------------------
  2448. // GetIODriver & CreateIODriver
  2449. //-----------------------------------------------------------------------------
  2450. static nsGEN::RYGENDriver gIODriver;
  2451. extern "C" CCOS::Dev::IODriver * __cdecl GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
  2452. {
  2453. return &gIODriver;
  2454. }
  2455. extern "C" CCOS::Dev::IODriver * __cdecl CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
  2456. {
  2457. return new nsGEN::RYGENDriver();
  2458. }