CCOS.Dev.Generator.Delta_80KAXB.cpp 110 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981
  1. // CCOS.Dev.GEN.Delta.cpp : 定义 DLL 应用程序的导出函数。
  2. //
  3. #include <assert.h>
  4. #include <functional>
  5. #include <fstream>
  6. #include <unordered_map>
  7. #include <set>
  8. #include <dlfcn.h>
  9. #include "LogicDevice.h"
  10. #include "CCOS.Dev.Generator.Delta_80KAXB.h"
  11. #include "Helper.JSON.hpp"
  12. #include "LogLocalHelper.h"
  13. #include "Log4CPP.h"
  14. using namespace std::placeholders;
  15. using namespace CCOS::Dev::Detail::Generator;
  16. namespace nsGEN = CCOS::Dev::Detail::Generator;
  17. static const int msTimeOut_Lock = 500;
  18. // Linux 环境下的 SCF 库文件名
  19. static const auto COM_SCFDllName = "libSerialSCF.so";
  20. static const auto TCP_SCFDllName = "libTcpipSCF.so";
  21. // 定义 Sleep 宏(如果头文件中没有定义)
  22. #ifndef Sleep
  23. #define Sleep(ms) std::this_thread::sleep_for(std::chrono::milliseconds(ms))
  24. #endif
  25. #define Delta_Com_NormalLen 20
  26. #define Delta_LoopDefTime 1500
  27. #define Delta_LoopExpTime 100
  28. #define KVP_MAX 150
  29. #define KVP_MIN 40
  30. #define WORD_HIGH(a) (a>>4)
  31. #define WORD_LOW(a) (( a & 0x0F))
  32. #define COMMANDHEAD 0xF0
  33. #define COMMANDEND 0x88
  34. #define HANDSWITCHCOMMAND 0x0D
  35. #define HANDSWITCHFIRST 0x52
  36. #define XRAYONCOMMAND 0x58
  37. #define XRAYOFFCOMMAND 0x4F
  38. /* Control characters */
  39. #define STX 0x02 /* Start of DATA */
  40. #define ETX 0x03 /* End of DATA */
  41. #define ACK 0x06 /* Acknowlage */
  42. #define NAK 0x15 /* not acknowlage */
  43. #define BYTE_1 1
  44. #define BYTE_2 2
  45. #define BYTE_4 4
  46. #define BYTE_6 6
  47. #define BYTE_10 10
  48. #define BYTE_12 12
  49. //-----------------------------------------------------------------------------
  50. // 计算校验码
  51. //-----------------------------------------------------------------------------
  52. UINT8 GetCRC8(char* pBuffer, UINT16 bufSize)
  53. {
  54. char High[16] = { 0x00, 0x70, 0xe0, 0x90, 0xc7, 0xb7, 0x27, 0x57, 0x89, 0xf9, 0x69, 0x19, 0x4e, 0x3e, 0xae, 0xde };
  55. char Low[16] = { 0x00, 0x07, 0x0e, 0x09, 0x1c, 0x1b, 0x12, 0x15, 0x38, 0x3f, 0x36, 0x31, 0x24, 0x23, 0x2a, 0x2d };
  56. UINT8 crc = 0;
  57. if (bufSize <= 0)
  58. return crc;
  59. for (int i = 0; i < bufSize; i++)
  60. {
  61. UINT8 result = (crc ^ pBuffer[i]);
  62. UINT8 high = WORD_HIGH(result);
  63. UINT8 low = WORD_LOW(result);
  64. crc = High[high] ^ Low[low];
  65. }
  66. return crc;
  67. }
  68. //-----------------------------------------------------------------------------
  69. // DeltaDevice
  70. //-----------------------------------------------------------------------------
  71. // 注释:DeliverModule已废弃,Linux下不再使用
  72. // nsSerialGPM::CDeliverModule nsGEN::DeltaDevice::m_tDelivermodule;
  73. nsGEN::DeltaDevice* nsGEN::DeltaDevice::g_GenDevice = NULL;
  74. atomic<int> nsGEN::DeltaDevice::m_iLoopTime = Delta_LoopDefTime;
  75. atomic<bool> nsGEN::DeltaDevice::m_bExtraFlag = false;
  76. nsGEN::DeltaDevice::DeltaDevice(std::shared_ptr <IOEventCenter> center, std::shared_ptr<SCFWrapper> SCF, string configfile)
  77. : super(center)
  78. , superGen()
  79. , m_SCF(SCF)
  80. {
  81. FINFO("========================================");
  82. FINFO("DeltaDevice Constructor Starting...");
  83. FINFO("Version: 0.0.1");
  84. FINFO("Config file: {$}", configfile.c_str());
  85. FINFO("========================================");
  86. assert(EventCenter);
  87. g_GenDevice = this;
  88. //初始化参数
  89. m_DoseUnit.m_KV.reset(new KVMould(70.0, 40.0, 150.0, 1.0));
  90. m_DoseUnit.m_MA.reset(new MAMould(20.0, 10.0, 1000.0, 1.0));
  91. m_DoseUnit.m_MS.reset(new MSMould(20.0, 1.0, 63000.0, 1.0));
  92. m_DoseUnit.m_MAS.reset(new MASMould(0.4, 0.4, 10000.0, 1.0));
  93. m_DoseUnit.m_Techmode.reset(new TECHMODEMould(AttrKey::TECHMODE_NOAEC_3P, AttrKey::TECHMODE_NOAEC_3P, AttrKey::TECHMODE_MAX, 1));
  94. m_DoseUnit.m_WS.reset(new WORKSTATIONMould(AttrKey::TABLE, AttrKey::TABLE, AttrKey::GENWS_MAX, 1));
  95. m_DoseUnit.m_Focus.reset(new FOCUSMould(AttrKey::FOCUS_LARGE, AttrKey::FOCUS_SMALL, AttrKey::FOCUS_LARGE, 1));
  96. m_DoseUnit.m_AECField.reset(new AECFIELDMould(0, 0, 111, 1));
  97. m_DoseUnit.m_AECFilm.reset(new AECFILMMould(0, 0, 3, 1));
  98. m_DoseUnit.m_AECDensity.reset(new AECDENSITYMould(0, -4, 4, 1));
  99. m_DoseUnit.m_HE.reset(new TUBEHEATMould(0, 0, 100, 1));
  100. m_DoseUnit.m_PostKV.reset(new POSTKVMould(40.0, 40.0, 150.0, 1.0));
  101. m_DoseUnit.m_PostMA.reset(new POSTMAMould(10.0, 10.0, 1000.0, 1.0));
  102. m_DoseUnit.m_PostMS.reset(new POSTMSMould(1.0, 1.0, 63000.0, 1.0));
  103. m_DoseUnit.m_PostMAS.reset(new POSTMASMould(0.4, 0.4, 10000.0, 1.0));
  104. m_DoseUnit.m_GenSynState.reset(new GENSYNSTATEMould(AttrKey::GENERATOR_RAD_OFF, AttrKey::GENERATOR_SYNC_ERR, AttrKey::GENERATOR_SYNC_MAX, 1));
  105. m_DoseUnit.m_GenState.reset(new GENSTATEMould(AttrKey::GENERATOR_STATUS_INIT, AttrKey::GENERATOR_STATUS_SHUTDOWN, AttrKey::GENERATOR_STATUS_MAX, 1));
  106. m_DoseUnit.m_GenTotalExpNumber.reset(new TOTALEXPNUMMould(0, 0, 9999, 1));
  107. m_DoseUnit.m_GenTotalAcqTimes.reset(new TOTALACQTIMESMould(0, 0, 9999, 1));
  108. m_DoseUnit.m_GenTubeCoolWaitTimes.reset(new TUBECOOLTIMEMould(0, 0, 9999, 1));
  109. m_DoseUnit.m_GenTubeOverLoadNumber.reset(new TUBEOVERLOADNUMMould(0, 0, 9999, 1));
  110. m_DoseUnit.m_GenCurrentExpNumber.reset(new CUREXPNUMMould(0, 0, 9999, 1));
  111. m_DoseUnit.m_ExpMode.reset(new EXPMODEMould(AttrKey::EXPMODE_TYPE::Single));
  112. m_DoseUnit.m_FrameRate.reset(new FRAMERATEMould(0, 0, 30, 1));
  113. m_DoseUnit.m_FLMode.reset(new FLUModeMould(AttrKey::GENERATOR_FLUMode::GENERATOR_FLMODE_NOTFLU));
  114. m_DAP.reset(new DevDAP::DOSEMould(0.0, 0.0, 1000.0, 0.01));
  115. m_MSGUnit.reset(new nsDetail::MSGUnit(center, nsGEN::GeneratorUnitType));
  116. FINFO("Dose unit moulds initialized successfully");
  117. m_bExtraFlag = true; // 启用硬件状态查询线程
  118. m_strConfigPath = configfile;
  119. FINFO("Loading configuration from file: {$}", configfile.c_str());
  120. bool loadResult = LoadConfig(configfile);
  121. if (!loadResult) {
  122. FERROR("Failed to load configuration file");
  123. } else {
  124. FINFO("Configuration loaded successfully");
  125. }
  126. FINFO("Registering device interfaces...");
  127. Register();
  128. FINFO("Device interfaces registered");
  129. // 注释:DeliverModule已废弃,Linux下不再使用
  130. //使用drivermodule类,处理ack命令
  131. // FINFO("Initializing deliver module...");
  132. // m_tDelivermodule.InitSendModle(this, &ProcessClientData, WriteLog);
  133. // m_nCMDType_ACK = m_tDelivermodule.SetPriority(false, true);
  134. // m_nCMDType_WaitTime = m_tDelivermodule.SetPriority(true, false, false, true, 100);
  135. // m_nCMDType_WaitACK = m_tDelivermodule.SetPriority(true, false, 0, false, 0, false, 0, true, 100);
  136. // m_nCMDType_WaitSELF = m_tDelivermodule.SetPriority(true, false, 3, false, 0, true, 1000);
  137. // char ackCMD[3] = {ACK ,ETX ,0};
  138. // m_tDelivermodule.SetACKCMDHead(ackCMD,2);
  139. // FINFO("Deliver module initialized");
  140. m_nCountTimes = 0;
  141. FINFO("Retrieving firmware version...");
  142. RetrieveFirewareVersion();
  143. //警告,错误信息
  144. m_ErrorMessages = {
  145. {"DELTA_ERR_0000", "LOST CONNECT"},
  146. {"DELTA_ERR_0001", "PC Invalid Command"},
  147. {"DELTA_ERR_0002", "Door Interlock"},
  148. {"DELTA_ERR_0003", "Interlock"},
  149. {"DELTA_ERR_0004", "Prep Timeout"},
  150. {"DELTA_ERR_0005", "Ready Timeout"},
  151. {"DELTA_ERR_0006", "Filament Timeout"},
  152. {"DELTA_ERR_0007", "No Library Data"},
  153. {"DELTA_ERR_0008", "No Calibration Data"},
  154. {"DELTA_ERR_0009", "SW Configuration File Empty"},
  155. {"DELTA_ERR_0010", "Calibration Manually Terminated"},
  156. {"DELTA_ERR_0011", "Manually Terminate Exposure"},
  157. {"DELTA_ERR_0012", "PREP Manually Terminate"},
  158. {"DELTA_ERR_0013", "Seasoning Manually Terminated"},
  159. {"DELTA_ERR_0014", "AC Voltage UVP"},
  160. {"DELTA_ERR_0015", "Bucky ready open"},
  161. {"DELTA_ERR_0017", "Not get AEC Ramp"},
  162. {"DELTA_ERR_0018", "AEC calibration over range"},
  163. {"DELTA_ERR_0019", "AEC exposure time out"},
  164. {"DELTA_ERR_0020", "Snap over power rating"},
  165. {"DELTA_ERR_1001", "SW OTP"},
  166. {"DELTA_ERR_1002", "Thermal Switch"},
  167. {"DELTA_ERR_1003", "XRAY Over HU"},
  168. {"DELTA_ERR_1004", "Aux Power Off"},
  169. {"DELTA_ERR_1005", "DR reset fail"},
  170. {"DELTA_ERR_1006", "DR ready fail"},
  171. {"DELTA_ERR_1007", "Battery communication loss"},
  172. {"DELTA_ERR_1008", "DAP communication loss"},
  173. {"DELTA_ERR_1009", "Fluoroscopic time out"},
  174. {"DELTA_ERR_1010", "DAP device error"},
  175. {"DELTA_ERR_1011", "Snap over time"},
  176. {"DELTA_ERR_2001", "SW Vout OVP"},
  177. {"DELTA_ERR_2002", "SW Vout UVP"},
  178. {"DELTA_ERR_2003", "SW Anode OCP"},
  179. {"DELTA_ERR_2004", "SW Anode UCP"},
  180. {"DELTA_ERR_2005", "Input Voltage OVP" },
  181. {"DELTA_ERR_2006", "Input Voltage UVP" },
  182. {"DELTA_ERR_2007", "24 VDC UVP" },
  183. {"DELTA_ERR_2008", "HW Vout OVP"},
  184. {"DELTA_ERR_2009", "Capacitive Protection"},
  185. {"DELTA_ERR_2010", "Primary OCP"},
  186. {"DELTA_ERR_2011", "HW Cathode OCP"},
  187. {"DELTA_ERR_2012", "HW Anode OCP"},
  188. {"DELTA_ERR_2013", "Charger OTP" },
  189. {"DELTA_ERR_2014", "PFC BUS UVP" },
  190. {"DELTA_ERR_2015", "Flow fault"},
  191. {"DELTA_ERR_2016", "PFC start fail"},
  192. {"DELTA_ERR_3001", "SW Thermal sense fault"},
  193. {"DELTA_ERR_3002", "Fan 1 Fault"},
  194. {"DELTA_ERR_3003", "Fan 2 Fault"},
  195. {"DELTA_ERR_3004", "Filament Power Fault"},
  196. {"DELTA_ERR_3005", "Soft Start Fail"},
  197. {"DELTA_ERR_3006", "MA Test Point Open"},
  198. {"DELTA_ERR_3007", "Tank Connect" },
  199. {"DELTA_ERR_3008", "Self-Test FERROR"},
  200. {"DELTA_ERR_3009", "Motor Short"},
  201. {"DELTA_ERR_3010", "Motor Invalid command"},
  202. {"DELTA_ERR_3011", "Motor OCP1"},
  203. {"DELTA_ERR_3012", "Motor OCP2"},
  204. {"DELTA_ERR_3013", "Motor Communication Loss"},
  205. {"DELTA_ERR_3014", "Motor Main Open"},
  206. {"DELTA_ERR_3015", "Motor Shift Open"},
  207. {"DELTA_ERR_3016", "Charger Fail"},
  208. {"DELTA_ERR_3017", "Bus UVP"},
  209. {"DELTA_ERR_3018", "Battery UVP"},
  210. {"DELTA_ERR_3019", "Cart UVP"},
  211. {"DELTA_ERR_3020", "Inverter error"},
  212. {"DELTA_ERR_3021", "Discharge Relay Fail" },
  213. {"DELTA_ERR_3022", "Battery OVP"},
  214. {"DELTA_ERR_3023", "Battery OCP" },
  215. {"DELTA_ERR_3024", "Battery OTP" },
  216. {"DELTA_ERR_3025", "Battery Fail"},
  217. {"DELTA_ERR_3026", "APS1 Fail"},
  218. {"DELTA_ERR_3027", "APS2 Fail"},
  219. {"DELTA_ERR_3028", "APS3 Fail"},
  220. {"DELTA_ERR_3029", "Capacitator error" },
  221. {"DELTA_ERR_3030", "Fan 3 Fault"},
  222. {"DELTA_ERR_3031", "Fan 4 Fault"},
  223. {"DELTA_ERR_3032", "PFC OTP and Brown out"},
  224. {"DELTA_ERR_4001", "SW Current Unbalance"},
  225. {"DELTA_ERR_4002", "SW Filament OCP"},
  226. {"DELTA_ERR_4003", "Shoot Inv1"},
  227. {"DELTA_ERR_4004", "Shoot Inv2"},
  228. {"DELTA_ERR_4005", "HW Filament Rms"},
  229. {"DELTA_ERR_4006", "FERROR Repeat 5 Times"},
  230. };
  231. m_WarnMessages = {
  232. {"DELTA_WARN_001", "mode inhibited"},
  233. {"DELTA_WARN_002", "out of tube rating"},
  234. {"DELTA_WARN_003", "out of power"},
  235. {"DELTA_WARN_004", "out of work"},
  236. {"DELTA_WARN_005", "out of voltage range"},
  237. {"DELTA_WARN_006", "out of current range"},
  238. {"DELTA_WARN_007", "out of time or FPS range"},
  239. {"DELTA_WARN_008", "out of mas range"},
  240. {"DELTA_WARN_009", "time too small"},
  241. {"DELTA_WARN_010", "parameter ok"},
  242. {"DELTA_WARN_011", "mas too small"},
  243. {"DELTA_WARN_012", "no cmd"},
  244. {"DELTA_WARN_013", "data not complete(reserved)"},
  245. {"DELTA_WARN_014", "out of tube HU"},
  246. {"DELTA_WARN_015", "out of filament current range"},
  247. {"DELTA_WARN_016", "no library data" },
  248. {"DELTA_WARN_017", "tube PN not match"},
  249. {"DELTA_WARN_018", "focal spot not support"},
  250. {"DELTA_WARN_019", "data break"},
  251. {"DELTA_WARN_020", "EEPROM BUSY"},
  252. {"DELTA_WARN_021", "exposure result empty"},
  253. {"DELTA_WARN_022", "tube calibration data empty" },
  254. {"DELTA_WARN_023", "XRAY interval time"},
  255. {"DELTA_WARN_024", "filament current limit"},
  256. {"DELTA_WARN_025", "out of generator HU"},
  257. {"DELTA_WARN_026", "out of motor HU"},
  258. {"DELTA_WARN_160", "invalid cmd"},
  259. };
  260. FINFO("Starting hardware status monitoring thread...");
  261. if (StartHardwareStatusThread()) {
  262. FINFO("Hardware status thread started successfully");
  263. } else {
  264. FERROR("Failed to start hardware status thread");
  265. }
  266. FINFO("========================================");
  267. FINFO("DeltaDevice Constructor Completed");
  268. FINFO("========================================");
  269. }
  270. std::string CCOS::Dev::Detail::Generator::DeltaDevice::GetDynamicLibraryPath()
  271. {
  272. // Linux下获取动态库路径
  273. // 使用this指针地址来获取所属动态库信息
  274. Dl_info dl_info;
  275. // 使用对象实例地址而不是成员函数指针
  276. if (dladdr(reinterpret_cast<void*>(this), &dl_info) == 0) {
  277. FERROR("Failed to get dynamic library path");
  278. return "";
  279. }
  280. std::string fullPath(dl_info.dli_fname);
  281. size_t pos = fullPath.find_last_of("/");
  282. FINFO("FullPath {$}", fullPath);
  283. if (pos == std::string::npos) {
  284. return ".";
  285. }
  286. return fullPath.substr(0, pos);
  287. }
  288. bool CCOS::Dev::Detail::Generator::DeltaDevice::GetConfData()
  289. {
  290. //暂时使用上面定义的数组,不用非要读取配置文件。
  291. int Num;
  292. if (m_GenConfig.GetKeyCount("RadKV") > 0)
  293. {
  294. if (m_GenConfig.GetKeyCount("RadKVSize") > 0)
  295. {
  296. Num = (int)m_GenConfig["RadKVSize"];
  297. for (int i = 0; i < Num; i++)
  298. {
  299. int nKV = (int)m_GenConfig["RadKV"][i];
  300. m_vecKV.push_back(nKV);
  301. }
  302. //m_DoseUnit.m_KVList->Update((string)m_GenConfig["RadKV"]);
  303. //FireNotify(m_DoseUnit.m_KVList->GetKey(), m_DoseUnit.m_KVList->JSGet());
  304. }
  305. FINFO("m_vecKV {$}", m_vecKV.size());
  306. }
  307. else
  308. {
  309. FINFO("no RadKV");
  310. }
  311. if (m_GenConfig.GetKeyCount("RadMAS") > 0)
  312. {
  313. if (m_GenConfig.GetKeyCount("RadMASSize") > 0)
  314. {
  315. Num = (int)m_GenConfig["RadMASSize"];
  316. for (int i = 0; i < Num; i++)
  317. {
  318. float fMAS = m_GenConfig["RadMAS"][i];
  319. m_vecMAS.push_back(fMAS);
  320. }
  321. //m_DoseUnit.m_mAsList->Update((string)m_GenConfig["RadMAS"]);
  322. //FireNotify(m_DoseUnit.m_mAsList->GetKey(), m_DoseUnit.m_mAsList->JSGet());
  323. }
  324. FINFO("m_vecMAS {$}", m_vecMAS.size());
  325. }
  326. else
  327. {
  328. FINFO("no RadMAS");
  329. }
  330. if (m_GenConfig.GetKeyCount("RadMA") > 0)
  331. {
  332. if (m_GenConfig.GetKeyCount("RadMASize") > 0)
  333. {
  334. Num = (int)m_GenConfig["RadMASize"];
  335. for (int i = 0; i < Num; i++)
  336. {
  337. float fMA = m_GenConfig["RadMA"][i];
  338. m_vecMA.push_back(fMA);
  339. }
  340. //m_DoseUnit.m_MAList->Update((string)m_GenConfig["RadMA"]);
  341. //FireNotify(m_DoseUnit.m_MAList->GetKey(), m_DoseUnit.m_MAList->JSGet());
  342. }
  343. FINFO("m_vecMA {$}", m_vecMA.size());
  344. }
  345. else
  346. {
  347. FINFO("no RadMA");
  348. }
  349. if (m_GenConfig.GetKeyCount("RadMS") > 0)
  350. {
  351. if (m_GenConfig.GetKeyCount("RadMSSize") > 0)
  352. {
  353. Num = (int)m_GenConfig["RadMSSize"];
  354. for (int i = 0; i < Num; i++)
  355. {
  356. float fMS = m_GenConfig["RadMS"][i];
  357. m_vecMS.push_back(fMS);
  358. }
  359. //m_DoseUnit.m_MSList->Update((string)m_GenConfig["RadMS"]);
  360. //FireNotify(m_DoseUnit.m_MSList->GetKey(), m_DoseUnit.m_MSList->JSGet());
  361. }
  362. FINFO("m_vecMS {$}", m_vecMS.size());
  363. }
  364. else
  365. {
  366. FINFO("no RadMS");
  367. }
  368. if (m_GenConfig.GetKeyCount("TableDAEC") > 0)
  369. {
  370. m_nTableUsePanelAEC = (int)(m_GenConfig["TableDAEC"]);
  371. FINFO("TableDAEC {$}", m_nTableUsePanelAEC);
  372. }
  373. else
  374. {
  375. FINFO("TableDAEC disable");
  376. }
  377. if (m_GenConfig.GetKeyCount("FreeDAEC") > 0)
  378. {
  379. m_nFreeUsePanelAEC = (int)(m_GenConfig["FreeDAEC"]);
  380. FINFO("FreeDAEC {$}", m_nFreeUsePanelAEC);
  381. }
  382. else
  383. {
  384. FINFO("FreeDAEC disable");
  385. }
  386. if (m_GenConfig.GetKeyCount("WallDAEC") > 0)
  387. {
  388. m_nWallUsePanelAEC = (int)(m_GenConfig["WallDAEC"]);
  389. FINFO("WallDAEC {$}", m_nWallUsePanelAEC);
  390. }
  391. else
  392. {
  393. FINFO("WallDAEC disable");
  394. }
  395. if (m_GenConfig.GetKeyCount("TableDDR") > 0)
  396. {
  397. m_nTableUsePanelDDR = (int)(m_GenConfig["TableDDR"]);
  398. FINFO("TableDDR {$}", m_nTableUsePanelDDR);
  399. }
  400. else
  401. {
  402. FINFO("TableDDR disable");
  403. }
  404. if (m_GenConfig.GetKeyCount("WallDDR") > 0)
  405. {
  406. m_nWallUsePanelDDR = (int)(m_GenConfig["WallDDR"]);
  407. FINFO("WallDDR {$}", m_nWallUsePanelDDR);
  408. }
  409. else
  410. {
  411. FINFO("WallDDR disable");
  412. }
  413. if (m_GenConfig.GetKeyCount("FreeDDR") > 0)
  414. {
  415. m_nFreeUsePanelDDR = (int)(m_GenConfig["FreeDDR"]);
  416. FINFO("FreeDDR {$}", m_nFreeUsePanelDDR);
  417. }
  418. else
  419. {
  420. FINFO("FreeDDR disable");
  421. }
  422. if (m_GenConfig.GetKeyCount("SendXwindowToDetector") > 0)
  423. {
  424. m_bSendXwindowToDector = ((int)m_GenConfig["SendXwindowToDetector"] > 1) ? true : false;
  425. FINFO("SendXwindowToDetector {$}", m_bSendXwindowToDector);
  426. }
  427. if (m_GenConfig.GetKeyCount("DEframeRate") > 0)
  428. {
  429. m_nDEFrameRate = (int)m_GenConfig["DEframeRate"];
  430. }
  431. FINFO("DEframeRate {$}", m_nDEFrameRate);
  432. return false;
  433. }
  434. nsGEN::DeltaDevice::~DeltaDevice()
  435. {
  436. FINFO("========================================");
  437. FINFO("DeltaDevice Destructor Starting...");
  438. FINFO("========================================");
  439. FINFO("Stopping hardware status thread...");
  440. m_bExtraFlag = false;
  441. if (m_pHardwareStatusThread.joinable()) {
  442. FINFO("Waiting for hardware status thread to join...");
  443. m_pHardwareStatusThread.join();
  444. FINFO("Hardware status thread joined successfully");
  445. } else {
  446. FINFO("Hardware status thread not joinable, skipping join");
  447. }
  448. g_GenDevice = nullptr;
  449. if (m_pDetectorClient)
  450. {
  451. if (!m_pDetectorClient->IsClosed())
  452. {
  453. m_pDetectorClient->Close();
  454. }
  455. delete m_pDetectorClient;
  456. m_pDetectorClient = NULL;
  457. }
  458. FINFO("========================================");
  459. FINFO("DeltaDevice Destructor Completed");
  460. FINFO("========================================");
  461. }
  462. std::string nsGEN::DeltaDevice::GetGUID() const
  463. {
  464. FINFO("\n===============GetGUID : {$} ===================\n", GeneratorUnitType);
  465. return GeneratorUnitType;
  466. }
  467. void nsGEN::DeltaDevice::Register()
  468. {
  469. auto Disp = m_Dispatch.Lock().As();
  470. superGen::Register(Disp);
  471. superGen::RegisterRAD(Disp);
  472. superGen::RegisterAEC(Disp);
  473. superGen::RegisterExpEnable(Disp);
  474. superGen::RegisterGeneratortoSyncStatus(Disp);
  475. Disp->Get.Push(m_MSGUnit->GetKey().c_str(), [this](std::string& out) { out = m_MSGUnit->JSGet(); return RET_STATUS::RET_SUCCEED; });
  476. }
  477. RET_STATUS nsGEN::DeltaDevice::IncKV()
  478. {
  479. if (!m_DoseUnit.m_KV->CanInc()) return RET_STATUS::RET_SUCCEED;
  480. m_DoseUnit.m_KV->Inc();
  481. SetKV(m_DoseUnit.m_KV->Get());
  482. return RET_STATUS::RET_SUCCEED;
  483. }
  484. RET_STATUS nsGEN::DeltaDevice::DecKV()
  485. {
  486. if (!m_DoseUnit.m_KV->CanDec()) return RET_STATUS::RET_SUCCEED;
  487. m_DoseUnit.m_KV->Dec();
  488. SetKV(m_DoseUnit.m_KV->Get());
  489. return RET_STATUS::RET_SUCCEED;
  490. }
  491. RET_STATUS nsGEN::DeltaDevice::SetKV(float value)
  492. {
  493. if (!m_DoseUnit.m_KV->Verify(value)) return RET_STATUS::RET_SUCCEED;
  494. FINFO("KV: {$}", value);
  495. ChangeGenParam((int)value, m_DoseUnit.m_MA->Get(), m_DoseUnit.m_MS->Get(), m_DoseUnit.m_MAS->Get());
  496. return RET_STATUS::RET_SUCCEED;
  497. }
  498. RET_STATUS nsGEN::DeltaDevice::IncMA()
  499. {
  500. if (!m_DoseUnit.m_MA->CanInc()) return RET_STATUS::RET_SUCCEED;
  501. float fMA = m_DoseUnit.m_MA->Get();
  502. int pos = GetFacFloatValue(m_vecMA, fMA);
  503. FINFO("Current ma: {$}, pos: {$}", fMA, pos);
  504. pos++;
  505. if (pos >= 0 && pos < m_vecMA.size())
  506. {
  507. if (m_vecMAS[pos] == (m_nTubeMaBFMinValue * 100))
  508. {
  509. SetFocus(AttrKey::FOCUS_LARGE);
  510. }
  511. fMA = m_vecMA[pos];
  512. FINFO("Inc to MA: {$}", fMA);
  513. ChangeGenParam(m_DoseUnit.m_KV->Get(), fMA, m_DoseUnit.m_MS->Get(), m_DoseUnit.m_MAS->Get());
  514. }
  515. return RET_STATUS::RET_SUCCEED;
  516. }
  517. RET_STATUS nsGEN::DeltaDevice::DecMA()
  518. {
  519. if (!m_DoseUnit.m_MA->CanDec()) return RET_STATUS::RET_SUCCEED;
  520. float fMA = m_DoseUnit.m_MA->Get();
  521. int pos = GetFacFloatValue(m_vecMA, fMA);
  522. FINFO("Current ma: {$}, pos: {$}", fMA, pos);
  523. pos--;
  524. if (pos >= 0 && pos < m_vecMA.size())
  525. {
  526. if (m_vecMA[pos] == (m_nTubeMaSFMaxValue * 100)) //small focus max value
  527. {
  528. SetFocus(AttrKey::FOCUS_TYPE::FOCUS_SMALL);//设置为小焦点
  529. }
  530. fMA = m_vecMA[pos];
  531. FINFO("Dec to MA: {$}", fMA);
  532. ChangeGenParam(m_DoseUnit.m_KV->Get(), fMA, m_DoseUnit.m_MS->Get(), m_DoseUnit.m_MAS->Get());
  533. }
  534. return RET_STATUS::RET_SUCCEED;
  535. }
  536. RET_STATUS nsGEN::DeltaDevice::SetMA(float value)
  537. {
  538. if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
  539. FINFO("MA: {$}", value);
  540. ChangeGenParam(m_DoseUnit.m_KV->Get(), value, m_DoseUnit.m_MS->Get(), m_DoseUnit.m_MAS->Get());
  541. return RET_STATUS::RET_SUCCEED;
  542. }
  543. RET_STATUS nsGEN::DeltaDevice::IncMS()
  544. {
  545. if (!m_DoseUnit.m_MS->CanInc()) return RET_STATUS::RET_SUCCEED;
  546. float fMS = m_DoseUnit.m_MS->Get();
  547. int pos = GetFacFloatValue(m_vecMS, fMS);
  548. FINFO("Current ms: {$}, pos: {$}", fMS, pos);
  549. pos++;
  550. if (pos >= 0 && pos < m_vecMS.size())
  551. {
  552. fMS = m_vecMS[pos];
  553. FINFO("Inc to MS: {$}", fMS);
  554. ChangeGenParam(m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MA->Get(), fMS, m_DoseUnit.m_MAS->Get());
  555. }
  556. return RET_STATUS::RET_SUCCEED;
  557. }
  558. RET_STATUS nsGEN::DeltaDevice::DecMS()
  559. {
  560. if (!m_DoseUnit.m_MS->CanDec()) return RET_STATUS::RET_SUCCEED;
  561. float fMS = m_DoseUnit.m_MS->Get();
  562. int pos = GetFacFloatValue(m_vecMS, fMS);
  563. FINFO("Current ms: {$}, pos: {$}", fMS, pos);
  564. pos--;
  565. if (pos >= 0 && pos < m_vecMS.size())
  566. {
  567. float fms = m_vecMS[pos];
  568. FINFO("Dec to MS: {$}", fms);
  569. ChangeGenParam(m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MA->Get(), fms, m_DoseUnit.m_MAS->Get());
  570. }
  571. return RET_STATUS::RET_SUCCEED;
  572. }
  573. RET_STATUS nsGEN::DeltaDevice::SetMS(float value)
  574. {
  575. if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
  576. FINFO("MS: {$}", value);
  577. ChangeGenParam(m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MA->Get(), value, m_DoseUnit.m_MAS->Get());
  578. return RET_STATUS::RET_SUCCEED;
  579. }
  580. RET_STATUS nsGEN::DeltaDevice::IncMAS()
  581. {
  582. if (!m_DoseUnit.m_MAS->CanInc()) return RET_STATUS::RET_SUCCEED;
  583. float fMAS = m_DoseUnit.m_MAS->Get();
  584. int pos = GetFacFloatValue(m_vecMAS, fMAS);
  585. FINFO("Current mas: {$}, pos: {$}", fMAS, pos);
  586. pos++;
  587. if (pos >= 0 && pos < m_vecMAS.size())
  588. {
  589. fMAS = m_vecMAS[pos];
  590. FINFO("Inc to MAS: {$}", fMAS);
  591. ChangeGenParam(m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MA->Get(), m_DoseUnit.m_MS->Get(), fMAS);
  592. }
  593. return RET_STATUS::RET_SUCCEED;
  594. }
  595. RET_STATUS nsGEN::DeltaDevice::DecMAS()
  596. {
  597. if (!m_DoseUnit.m_MAS->CanDec()) return RET_STATUS::RET_SUCCEED;
  598. float fMAS = m_DoseUnit.m_MAS->Get();
  599. int pos = GetFacFloatValue(m_vecMAS, fMAS);
  600. FINFO("Current mas: {$}, pos: {$}", fMAS, pos);
  601. pos--;
  602. if (pos >= 0 && pos < m_vecMAS.size())
  603. {
  604. fMAS = m_vecMAS[pos];
  605. FINFO("Dec to MAS: {$}", fMAS);
  606. ChangeGenParam(m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MA->Get(), m_DoseUnit.m_MS->Get(), fMAS);
  607. }
  608. return RET_STATUS::RET_SUCCEED;
  609. }
  610. RET_STATUS nsGEN::DeltaDevice::SetMAS(float value)
  611. {
  612. if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
  613. FINFO("MAS: {$}", value);
  614. ChangeGenParam(m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MA->Get(), m_DoseUnit.m_MS->Get(), value);
  615. return RET_STATUS::RET_SUCCEED;
  616. }
  617. RET_STATUS nsGEN::DeltaDevice::SetTechmode(int value)
  618. {
  619. //0 MS 1 MAS 2 AEC
  620. //if (!m_DoseUnit.m_Techmode->Verify(value)) return RET_STATUS::RET_SUCCEED;
  621. FINFO("[0xF0, 0x51, 0xA1, 0x0{$}]", value);
  622. char cmdbuf[20] = { 0xF0, 0x51, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7A, 0x00, 0x88 };
  623. m_DoseUnit.m_Techmode->Update(value);
  624. if (value == 0)
  625. {
  626. SetDAECEnable(0);//禁用DAEC
  627. cmdbuf[3] = 2;
  628. }
  629. else if (value == 1)
  630. {
  631. SetDAECEnable(0);//禁用DAEC
  632. cmdbuf[3] = 3;
  633. }
  634. else if (value == 2)
  635. {
  636. if (m_DoseUnit.m_WS->Get() == AttrKey::TABLE)
  637. {
  638. if (m_nTableUsePanelAEC == 1)
  639. {
  640. SetDAECEnable(1);
  641. cmdbuf[3] = 2;//time
  642. }
  643. else
  644. {
  645. SetDAECEnable(0);
  646. cmdbuf[3] = 1;//应用GEN的aec功能
  647. cmdbuf[4] = m_nChamberIndex;//chabmer index
  648. int nAECFieldSel = 2;
  649. switch (m_DoseUnit.m_AECField->Get())
  650. {
  651. case 100:
  652. nAECFieldSel = 1;
  653. break;
  654. case 10:
  655. nAECFieldSel = 2;
  656. break;
  657. case 110:
  658. nAECFieldSel = 3;
  659. break;
  660. case 1:
  661. nAECFieldSel = 4;
  662. break;
  663. case 101:
  664. nAECFieldSel = 5;
  665. break;
  666. case 11:
  667. nAECFieldSel = 6;
  668. break;
  669. case 111:
  670. nAECFieldSel = 7;
  671. break;
  672. default:
  673. nAECFieldSel = 2;
  674. break;
  675. }
  676. cmdbuf[5] = nAECFieldSel;//field
  677. cmdbuf[6] = 0;
  678. cmdbuf[7] = 0;
  679. SetAECInformation(m_nChamberIndex, m_DoseUnit.m_AECField->Get(), m_DoseUnit.m_AECDensity->Get(), m_DoseUnit.m_AECFilm->Get());
  680. }
  681. }
  682. else if (m_DoseUnit.m_WS->Get() == AttrKey::WALL)
  683. {
  684. if (m_nWallUsePanelAEC == 1)
  685. {
  686. SetDAECEnable(1);
  687. cmdbuf[3] = 2;//time
  688. }
  689. else
  690. {
  691. SetDAECEnable(0);
  692. cmdbuf[3] = 1;//应用GEN的aec功能
  693. cmdbuf[4] = m_nChamberIndex;//chabmer index
  694. int nAECFieldSel = 2;
  695. switch (m_DoseUnit.m_AECField->Get())
  696. {
  697. case 100:
  698. nAECFieldSel = 1;
  699. break;
  700. case 10:
  701. nAECFieldSel = 2;
  702. break;
  703. case 110:
  704. nAECFieldSel = 3;
  705. break;
  706. case 1:
  707. nAECFieldSel = 4;
  708. break;
  709. case 101:
  710. nAECFieldSel = 5;
  711. break;
  712. case 11:
  713. nAECFieldSel = 6;
  714. break;
  715. case 111:
  716. nAECFieldSel = 7;
  717. break;
  718. default:
  719. nAECFieldSel = 2;
  720. break;
  721. }
  722. cmdbuf[5] = nAECFieldSel;//field
  723. cmdbuf[6] = 0;
  724. cmdbuf[7] = 0;
  725. }
  726. }
  727. else if (m_DoseUnit.m_WS->Get() == AttrKey::MOBILE)
  728. {
  729. if (m_nFreeUsePanelAEC == 1)
  730. {
  731. SetDAECEnable(1);
  732. cmdbuf[3] = 2;//time
  733. }
  734. else
  735. {
  736. SetDAECEnable(0);
  737. cmdbuf[3] = 1;//应用GEN的aec功能
  738. cmdbuf[4] = m_nChamberIndex;//chabmer index
  739. int nAECFieldSel = 2;
  740. switch (m_DoseUnit.m_AECField->Get())
  741. {
  742. case 100:
  743. nAECFieldSel = 1;
  744. break;
  745. case 10:
  746. nAECFieldSel = 2;
  747. break;
  748. case 110:
  749. nAECFieldSel = 3;
  750. break;
  751. case 1:
  752. nAECFieldSel = 4;
  753. break;
  754. case 101:
  755. nAECFieldSel = 5;
  756. break;
  757. case 11:
  758. nAECFieldSel = 6;
  759. break;
  760. case 111:
  761. nAECFieldSel = 7;
  762. break;
  763. default:
  764. nAECFieldSel = 2;
  765. break;
  766. }
  767. cmdbuf[5] = nAECFieldSel;//field
  768. cmdbuf[6] = 0;
  769. cmdbuf[7] = 0;
  770. if (m_DoseUnit.m_AECFilm->Get() == 0)
  771. SetAECInformation(m_nChamberIndex, m_DoseUnit.m_AECField->Get(), m_DoseUnit.m_AECDensity->Get(), m_DoseUnit.m_AECFilm->Get());
  772. }
  773. }
  774. }
  775. FormatCommand(cmdbuf, 13);
  776. string temp(cmdbuf, 13);
  777. m_strCommand = temp;
  778. HWSend(m_strCommand.c_str(), m_strCommand.length());
  779. return RET_STATUS::RET_SUCCEED;
  780. }
  781. RET_STATUS nsGEN::DeltaDevice::SetFocus(int value)
  782. {
  783. if (!m_DoseUnit.m_Focus->Verify(value)) return RET_STATUS::RET_SUCCEED;
  784. FINFO("[0xF0, 0x5A, 0xA1, 0x00] focus: {$}", value);
  785. char cmdbuf[20] = { 0xF0, 0x5A, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7A, 0x00, 0x88 };
  786. if (value == 0)
  787. {
  788. cmdbuf[3] = 2;
  789. }
  790. else if (value == 1)
  791. {
  792. cmdbuf[3] = 1;
  793. }
  794. else
  795. {
  796. cmdbuf[3] = 3;
  797. }
  798. FormatCommand(cmdbuf, 13);
  799. string temp(cmdbuf, 13);
  800. m_strCommand = temp;
  801. HWSend(m_strCommand.c_str(), m_strCommand.length());
  802. return RET_STATUS::RET_SUCCEED;
  803. }
  804. RET_STATUS nsGEN::DeltaDevice::SetAECDensity(int value)
  805. {
  806. if (!m_DoseUnit.m_AECDensity->Verify(value)) return RET_STATUS::RET_SUCCEED;
  807. FINFO("AECDensity: {$}", value);
  808. if (value < -3)
  809. {
  810. value = -3;
  811. }
  812. else if (value > 3)
  813. {
  814. value = 3;
  815. }
  816. if (m_DoseUnit.m_AECDensity->Get() != value)
  817. {
  818. SetAECInformation(1, m_DoseUnit.m_AECField->Get(), value, m_DoseUnit.m_AECFilm->Get());
  819. }
  820. return RET_STATUS::RET_SUCCEED;
  821. }
  822. RET_STATUS nsGEN::DeltaDevice::SetAECField(int value)
  823. {
  824. if (!m_DoseUnit.m_AECField->Verify(value)) return RET_STATUS::RET_SUCCEED;
  825. FINFO("AECField: {$}", value);
  826. if (m_DoseUnit.m_AECField->Get() != value)
  827. {
  828. SetAECInformation(1, value, m_DoseUnit.m_AECDensity->Get(), m_DoseUnit.m_AECFilm->Get());
  829. }
  830. return RET_STATUS::RET_SUCCEED;
  831. }
  832. RET_STATUS nsGEN::DeltaDevice::SetAECFilm(int value)
  833. {
  834. if (!m_DoseUnit.m_AECFilm->Verify(value)) return RET_STATUS::RET_SUCCEED;
  835. FINFO("AECFilm: {$}", value);
  836. if (m_DoseUnit.m_AECFilm->Get() != value)
  837. {
  838. SetAECInformation(1, m_DoseUnit.m_AECField->Get(), m_DoseUnit.m_AECDensity->Get(), value);
  839. }
  840. return RET_STATUS::RET_SUCCEED;
  841. }
  842. RET_STATUS nsGEN::DeltaDevice::SetWS(const string value)
  843. {
  844. return RET_STATUS::RET_SUCCEED;
  845. }
  846. RET_STATUS nsGEN::DeltaDevice::SetAPR(const _tAPRArgs& t)
  847. {
  848. m_tAPRdata = t;
  849. FINFO("Focus: {$}, Techmode: {$}, AECField: {$}, AECFilm: {$}, AECDensity: {$}, KV: {$}, MA: {$}, MS: {$}, KV2: {$}, MA2: {$}, MS2: {$}, MAS: {$}",
  850. m_tAPRdata.nFocus, m_tAPRdata.nTechmode, m_tAPRdata.nAECField, m_tAPRdata.nAECFilm, m_tAPRdata.nAECDensity, m_tAPRdata.fKV, m_tAPRdata.fMA, m_tAPRdata.fMS, m_tAPRdata.fKV2, m_tAPRdata.fMA2, m_tAPRdata.fMS2, m_tAPRdata.fMAS);
  851. if (m_tAPRdata.fKV2 != 0)
  852. {
  853. SetDualEnergyCommand(m_tAPRdata);
  854. }
  855. else
  856. {
  857. SetRadMode(0, 0);
  858. if ((int)m_tAPRdata.fMA > m_nTubeMaSFMaxValue)
  859. {
  860. SetFocus(1);
  861. }
  862. else
  863. {
  864. SetFocus(0);
  865. }
  866. SetTechmode(m_tAPRdata.nTechmode);
  867. if (m_tAPRdata.nTechmode == AttrKey::TECHMODE_AEC_3P)
  868. {
  869. if (m_tAPRdata.nWS == AttrKey::TABLE)
  870. {
  871. if (m_nTableUsePanelAEC != 1)
  872. {
  873. if (m_DoseUnit.m_AECFilm->Get() == 0)
  874. m_DoseUnit.m_AECFilm->Update(1);
  875. SetAECInformation(m_nChamberIndex, m_tAPRdata.nAECField, m_tAPRdata.nAECDensity, m_tAPRdata.nAECFilm);
  876. SetAECKV_MA_MS((int)m_tAPRdata.fKV, m_tAPRdata.fMA, m_tAPRdata.fMS);
  877. }
  878. else
  879. {
  880. SetRADKV_MA_MS((int)m_tAPRdata.fKV, m_tAPRdata.fMA, m_tAPRdata.fMS);
  881. }
  882. }
  883. else if (m_tAPRdata.nWS == AttrKey::WALL)
  884. {
  885. if (m_nWallUsePanelAEC != 1)
  886. {
  887. if (m_tAPRdata.nAECFilm == 0)
  888. m_tAPRdata.nAECFilm = 1;
  889. SetAECInformation(m_nChamberIndex, m_tAPRdata.nAECField, m_tAPRdata.nAECDensity, m_tAPRdata.nAECFilm);
  890. SetAECKV_MA_MS((int)m_tAPRdata.fKV, m_tAPRdata.fMA, m_tAPRdata.fMS);
  891. }
  892. else
  893. {
  894. SetRADKV_MA_MS((int)m_tAPRdata.fKV, m_tAPRdata.fMA, m_tAPRdata.fMS);
  895. }
  896. }
  897. else if (m_tAPRdata.nWS == AttrKey::MOBILE)
  898. {
  899. if (m_nFreeUsePanelAEC != 1)
  900. {
  901. if (m_tAPRdata.nAECFilm == 0)
  902. m_tAPRdata.nAECFilm = 1;
  903. SetAECInformation(m_nChamberIndex, m_tAPRdata.nAECField, m_tAPRdata.nAECDensity, m_tAPRdata.nAECFilm);
  904. SetAECKV_MA_MS((int)m_tAPRdata.fKV, m_tAPRdata.fMA, m_tAPRdata.fMS);
  905. }
  906. else
  907. {
  908. SetRADKV_MA_MS((int)m_tAPRdata.fKV, m_tAPRdata.fMA, m_tAPRdata.fMS);
  909. }
  910. }
  911. }
  912. else if (m_tAPRdata.nTechmode == AttrKey::TECHMODE_NOAEC_2P)
  913. {
  914. SetRADKV_MAS((int)m_tAPRdata.fKV, m_tAPRdata.fMAS);
  915. }
  916. else
  917. {
  918. SetRADKV_MA_MS((int)m_tAPRdata.fKV, m_tAPRdata.fMA, m_tAPRdata.fMS);
  919. }
  920. }
  921. m_bSetAPR = true;
  922. return RET_STATUS::RET_SUCCEED;
  923. }
  924. bool nsGEN::DeltaDevice::SetDualEnergyCommand(const _tAPRArgs& t)
  925. {
  926. if (!m_bIsDualExp)
  927. SetRadMode(1, 1);
  928. if (m_nExposureNumber == 0)
  929. {
  930. FINFO("Dual Energy First APR KV: {$}, MA: {$}, MS: {$}, MAS: {$}", t.fKV, t.fMA, t.fMS, t.fMAS);
  931. m_bIsDualExp = true;
  932. //设置双能第一组曝光参数
  933. SetAPRForDual(t.nWS, t.nFocus, t.nTechmode, t.nAECField, t.nAECFilm, t.nAECDensity, t.fKV, t.fMA, t.fMS, t.fMAS);
  934. //双能是序列点片,是需要配置帧率的
  935. FINFO("Set de framerate[0xF0, 0x6D, 0xAD, 0xxx]");
  936. char cmdbuf[20] = { 0xF0, 0x6D, 0xAD, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0xDB, 0x00, 0x88 };
  937. cmdbuf[3] = m_nDEFrameRate * 10;
  938. FormatCommand(cmdbuf, 19);
  939. string temp(cmdbuf, 19);
  940. m_strCommand = temp;
  941. HWSend(m_strCommand.c_str(), m_strCommand.length());
  942. }
  943. else if (m_nExposureNumber == 1)
  944. {
  945. //2 set 2nd array param
  946. FINFO("Dual Energy Second APR KV: {$}, MA: {$}, MS: {$}", t.fKV2, t.fMA2, t.fMS2);
  947. //设置第二组参数
  948. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_AEC_3P)
  949. {
  950. SetAECInformation(m_nChamberIndex, t.nAECField, t.nAECDensity, 0);
  951. SetAECKV_MA_MS((int)t.fKV2, t.fMA2, t.fMS2);
  952. }
  953. else if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_NOAEC_2P)
  954. {
  955. SetRADKV_MAS((int)t.fKV2, t.fMA2 * t.fMS2 / 1000);
  956. }
  957. else
  958. {
  959. SetRADKV_MA_MS((int)t.fKV2, t.fMA2, t.fMS2);
  960. }
  961. //m_bIsDualExp = false; //第二次设定之后,主动false
  962. //m_nExposureNumber = 0;
  963. }
  964. return true;
  965. }
  966. bool nsGEN::DeltaDevice::SetAPRForDual(int nWS, int nFO, int nET, int nAECFieldSel, int nAECFilmSel, float fAECDensity, float fKV, float fMA, float fMS, float fMAS)
  967. {
  968. FINFO("Focus: {$}, Techmode: {$}, AECField: {$},AECFilm: {$}, AECDensity: {$}, KV: {$}, MA: {$}, MS: {$}, MAS: {$}",
  969. m_tAPRdata.nFocus, m_tAPRdata.nTechmode, m_tAPRdata.nAECField, m_tAPRdata.nAECFilm, m_tAPRdata.nAECDensity, m_tAPRdata.fKV, m_tAPRdata.fMA, m_tAPRdata.fMS, m_tAPRdata.fMAS);
  970. //客户说160是 small FO的最大值。 180是大焦点的最小值
  971. if ((int)fMA > m_nTubeMaSFMaxValue)
  972. {
  973. SetFocus(1);
  974. }
  975. else
  976. {
  977. SetFocus(0);
  978. }
  979. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_AEC_3P)
  980. {
  981. if (nAECFilmSel == 0)
  982. nAECFilmSel = 1;
  983. SetAECInformation(m_nChamberIndex, nAECFieldSel, fAECDensity, nAECFilmSel);
  984. SetAECKV_MA_MS((int)fKV, fMA, fMS);
  985. }
  986. else if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_NOAEC_2P)
  987. {
  988. SetRADKV_MAS((int)fKV, fMAS);
  989. }
  990. else
  991. {
  992. SetRADKV_MA_MS((int)fKV, fMA, fMS);
  993. }
  994. return true;
  995. }
  996. RET_STATUS nsGEN::DeltaDevice::QueryHE(int& value)
  997. {
  998. return RET_STATUS::RET_SUCCEED;
  999. }
  1000. RET_STATUS nsGEN::DeltaDevice::QueryPostKV(float& value)
  1001. {
  1002. m_DoseUnit.m_PostKV->Update(m_DoseUnit.m_KV->Get());
  1003. value = m_DoseUnit.m_PostKV->Get();
  1004. return RET_STATUS::RET_FAILED;
  1005. }
  1006. RET_STATUS nsGEN::DeltaDevice::QueryPostMA(float& value)
  1007. {
  1008. value = m_DoseUnit.m_PostMA->Get();
  1009. return RET_STATUS::RET_SUCCEED;
  1010. }
  1011. RET_STATUS nsGEN::DeltaDevice::QueryPostMS(float& value)
  1012. {
  1013. value = m_DoseUnit.m_PostMS->Get();
  1014. return RET_STATUS::RET_SUCCEED;
  1015. }
  1016. RET_STATUS nsGEN::DeltaDevice::QueryPostMAS(float& value)
  1017. {
  1018. value = m_DoseUnit.m_PostMAS->Get();
  1019. return RET_STATUS::RET_SUCCEED;
  1020. }
  1021. RET_STATUS nsGEN::DeltaDevice::SetGenSynState(int value)
  1022. {
  1023. FINFO("GenSynState: {$}", value);
  1024. return RET_STATUS::RET_SUCCEED;
  1025. }
  1026. RET_STATUS nsGEN::DeltaDevice::SetGenState(int value)
  1027. {
  1028. FINFO("GenState: {$}", value);
  1029. return RET_STATUS::RET_SUCCEED;
  1030. }
  1031. RET_STATUS nsGEN::DeltaDevice::SetExpMode(std::string value)
  1032. {
  1033. FINFO("ExpMode: {$}", value.c_str());
  1034. m_DoseUnit.m_ExpMode->Update(value);
  1035. return RET_STATUS::RET_SUCCEED;
  1036. }
  1037. RET_STATUS nsGEN::DeltaDevice::SetFLFMode(std::string value)
  1038. {
  1039. FINFO("FLFMode: {$}", value.c_str());
  1040. return RET_STATUS::RET_SUCCEED;
  1041. }
  1042. RET_STATUS nsGEN::DeltaDevice::SetEXAMMode(std::string value)
  1043. {
  1044. FINFO("EXAMMode: {$}", value.c_str());
  1045. return RET_STATUS::RET_SUCCEED;
  1046. }
  1047. RET_STATUS nsGEN::DeltaDevice::SetFrameRate(FLOAT frameRate)
  1048. {
  1049. if (m_DoseUnit.m_FrameRate->Verify(frameRate))
  1050. {
  1051. FINFO("[0xF0, 0x56, 0xA2, 0x00] FrameRate: {$}", frameRate);
  1052. char cmdbuf[13] = { 0xF0, 0x56, 0xA2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7A, 0x00, 0x88 };
  1053. int nPPS = (int)(frameRate * 10);
  1054. cmdbuf[3] = nPPS / 256;
  1055. cmdbuf[4] = nPPS % 256;
  1056. FormatCommand(cmdbuf, 13);
  1057. string temp(cmdbuf, 13);
  1058. m_strCommand = temp;
  1059. HWSend(m_strCommand.c_str(), m_strCommand.length());
  1060. }
  1061. return RET_STATUS::RET_SUCCEED;
  1062. }
  1063. //貌似最好有时间间隔
  1064. RET_STATUS nsGEN::DeltaDevice::RefreshData()
  1065. {
  1066. FINFO("RefreshData");
  1067. return RET_STATUS::RET_SUCCEED;
  1068. }
  1069. RET_STATUS nsGEN::DeltaDevice::SetExpEnable()
  1070. {
  1071. char cmdbuf[13] = { 0xF0, 0x5C, 0xA3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC5, 0x00, 0x88 };
  1072. FINFO("[0xF0, 0x5C, 0xA3, 0x00]");
  1073. FormatCommand(cmdbuf, 13);
  1074. string temp(cmdbuf, 13);
  1075. m_strCommand = temp;
  1076. HWSend(m_strCommand.c_str(), m_strCommand.length());
  1077. return RET_STATUS::RET_SUCCEED;
  1078. }
  1079. RET_STATUS nsGEN::DeltaDevice::SetExpDisable()
  1080. {
  1081. char cmdbuf[13] = { 0xF0, 0x5C, 0xA3, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86, 0x00, 0x88 };
  1082. FINFO("ExpEnable[0xF0, 0x5C, 0xA3, 0x01]");
  1083. FormatCommand(cmdbuf, 13);
  1084. string temp(cmdbuf, 13);
  1085. m_strCommand = temp;
  1086. HWSend(m_strCommand.c_str(), m_strCommand.length());
  1087. m_nProcessXrayon = false;
  1088. return RET_STATUS::RET_SUCCEED;
  1089. }
  1090. RET_STATUS nsGEN::DeltaDevice::Reset()
  1091. {
  1092. FINFO("[0xF0 ,0x59 ,0xA1 ,CurErrLevel{$}]", m_nCurErrLevel);
  1093. char cmdbuf[13] = { 0xF0 ,0x59 ,0xA1 ,0x01 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x88 };
  1094. cmdbuf[3] = m_nCurErrLevel;
  1095. FormatCommand(cmdbuf, 13);
  1096. string temp(cmdbuf, 13);
  1097. m_strCommand = temp;
  1098. HWSend(m_strCommand.c_str(), m_strCommand.length());
  1099. return RET_STATUS::RET_SUCCEED;
  1100. }
  1101. //-----------------------------------------------------------------------------
  1102. // ProcessCmd - 已废弃
  1103. //-----------------------------------------------------------------------------
  1104. // 注释:DeliverModule已废弃,Linux下不再使用
  1105. // void nsGEN::DeltaDevice::ProcessClientData(const char* pData, unsigned long nDataLength, void* lparam)
  1106. // {
  1107. // DeltaDevice* pCurGen = (DeltaDevice*)lparam;
  1108. // pCurGen->HWSend(pData, nDataLength);
  1109. // }
  1110. // void nsGEN::DeltaDevice::WriteLog(const char* pData, nsSerialGPM::LOG_V2_LEVEL level)
  1111. // {
  1112. // }
  1113. // RET_STATUS nsGEN::DeltaDevice::HWSendWaitACKCMD(string strCommand, int headLengh)
  1114. // {
  1115. // return m_tDelivermodule.ProcessCommand(strCommand, m_nCMDType_WaitACK, headLengh);
  1116. // }
  1117. RET_STATUS nsGEN::DeltaDevice::HWSend(const char* strCommand, int lengh, int nTimeOut)
  1118. {
  1119. // 参数校验
  1120. if (strCommand == nullptr || lengh <= 0)
  1121. {
  1122. FERROR("Invalid parameters: strCommand is null or length <= 0");
  1123. return RET_STATUS::RET_FAILED;
  1124. }
  1125. // 连接状态检查
  1126. if (!m_SCF || !m_SCF->IsConnected())
  1127. {
  1128. FWARN("SCF not connected, cannot send command");
  1129. return RET_STATUS::RET_FAILED;
  1130. }
  1131. // 构建日志输出的十六进制字符串
  1132. char strtemp[10] = { 0 };
  1133. string str = "";
  1134. for (int i = 0; i < lengh; i++)
  1135. {
  1136. snprintf(strtemp, sizeof(strtemp), "%02X", (BYTE)strCommand[i]);
  1137. str += strtemp;
  1138. str += ",";
  1139. }
  1140. FINFO("==OUT==: {$}, length: {$}, timeout: {$}ms", str, lengh, nTimeOut);
  1141. unsigned int retLength = 0;
  1142. // 使用Lock/Unlock保护SendPacket调用
  1143. if (m_SCF->Lock(1000) == WAIT_OBJECT_0)
  1144. {
  1145. int ret = m_SCF->SendPacket(strCommand, lengh, nTimeOut, retLength);
  1146. m_SCF->Unlock();
  1147. if (ret != 0)
  1148. {
  1149. FERROR("SendPacket failed, error code: {$}, sent length: {$}", ret, retLength);
  1150. return RET_STATUS::RET_FAILED;
  1151. }
  1152. FDEBUG("SendPacket succeeded, sent {$} bytes", retLength);
  1153. }
  1154. else
  1155. {
  1156. FERROR("Failed to lock SCF (timeout 1000ms) for sending command");
  1157. return RET_STATUS::RET_FAILED;
  1158. }
  1159. return RET_STATUS::RET_SUCCEED;
  1160. }
  1161. void nsGEN::DeltaDevice::FireErrorMessage(const bool Act, const int Code, const char* ResInfo)
  1162. {
  1163. string ErrorCode("DELTA_ERR_");
  1164. ErrorCode += std::to_string(Code);
  1165. int level = DELTA_ABNORMAL_LEVEL::REG_ERRO;
  1166. if (Act)
  1167. {
  1168. FERROR("add {$}:{$}", ErrorCode.c_str(), ResInfo);
  1169. m_MSGUnit->AddErrorMessage(ErrorCode.c_str(), level, ResInfo);
  1170. }
  1171. else
  1172. {
  1173. FERROR("del {$}:{$}", ErrorCode.c_str(), ResInfo);
  1174. m_MSGUnit->DelErrorMessage(ErrorCode.c_str(), level, ResInfo);
  1175. }
  1176. }
  1177. void nsGEN::DeltaDevice::FireWarnMessage(const bool Act, const int Code, const char* ResInfo)
  1178. {
  1179. string WarnCode("DELTA_WAR_");
  1180. WarnCode += std::to_string(Code);
  1181. int level = DELTA_ABNORMAL_LEVEL::REG_WARN;
  1182. if (Act)
  1183. {
  1184. FERROR("add {$}:{$}", WarnCode.c_str(), ResInfo);
  1185. m_MSGUnit->AddWarnMessage(WarnCode.c_str(), level, ResInfo);
  1186. }
  1187. else
  1188. {
  1189. FERROR("del {$}:{$}", WarnCode.c_str(), ResInfo);
  1190. m_MSGUnit->DelWarnMessage(WarnCode.c_str(), level, ResInfo);
  1191. }
  1192. }
  1193. //-----------------------------------------------------------------------------
  1194. // ProcessCmd
  1195. //-----------------------------------------------------------------------------
  1196. void nsGEN::DeltaDevice::FireNotify(std::string key, std::string content)
  1197. {
  1198. EventCenter->OnNotify(1, key, content);
  1199. }
  1200. void nsGEN::DeltaDevice::ProcessCommand(const char* strPackage, int Index, int End)
  1201. {
  1202. if ((BYTE)strPackage[Index] == 0xF0)
  1203. {
  1204. if (strPackage[End - 4] != 0x0A)
  1205. {
  1206. //GetLastExpParamenters();
  1207. char WarnCode[20];
  1208. snprintf(WarnCode, sizeof(WarnCode), "DELTA_WARN_%03d", (BYTE)strPackage[End - 4]);
  1209. int level = 1;
  1210. FINFO("{$}", WarnCode);
  1211. auto it = m_WarnMessages.find(WarnCode);
  1212. if (it != m_WarnMessages.end())
  1213. {
  1214. m_MSGUnit->AddWarnMessage(WarnCode, level, it->second.c_str());
  1215. //return false;
  1216. }
  1217. }
  1218. }
  1219. m_bReconnect = false;
  1220. const char* chdigital;
  1221. m_nCountTimes = 0;
  1222. if (UINT8(strPackage[Index]) != 0xF0)
  1223. {
  1224. FINFO("simple cmd:{$}", strPackage);
  1225. if (strPackage[Index] == 'C' && strPackage[Index + 1] == 'X' && strPackage[Index + 2] == 'L')
  1226. {
  1227. m_nProcessXrayon = false;
  1228. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF);
  1229. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1230. }
  1231. if (strPackage[Index] == 'E' && strPackage[Index + 1] == 'R' && strPackage[Index + 2] == 'R')
  1232. {
  1233. m_nProcessXrayon = false;
  1234. chdigital = strPackage + 3;
  1235. int errornumber = atoi(chdigital);
  1236. if (errornumber < 3000) //warn
  1237. {
  1238. char WarnCode[20];
  1239. snprintf(WarnCode, sizeof(WarnCode), "DELTA_WARN_%03d", (BYTE)strPackage[End - 4]);
  1240. int level = 1;
  1241. FINFO("{$}", WarnCode);
  1242. auto itwarn = m_WarnMessages.find(WarnCode);
  1243. if (itwarn != m_WarnMessages.end())
  1244. {
  1245. m_MSGUnit->AddWarnMessage(WarnCode, level, itwarn->second.c_str());
  1246. //return false;
  1247. }
  1248. //如果error=0012,那么表示一档松开。那么应该发送release,取消本次曝光,否则会出现超时的问题
  1249. if (errornumber == 12 || errornumber == 1006)
  1250. {
  1251. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF);
  1252. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1253. }
  1254. if (errornumber >= 4000)
  1255. {
  1256. m_nCurErrLevel = 3;
  1257. }
  1258. if (errornumber >= 3000)
  1259. {
  1260. m_nCurErrLevel = 1;
  1261. }
  1262. char ErrCode[20];
  1263. snprintf(ErrCode, sizeof(ErrCode), "DELTA_ERR_%04d", (BYTE)strPackage[3]);
  1264. FINFO("{$}", ErrCode);
  1265. auto iterr = m_ErrorMessages.find(ErrCode);
  1266. if (iterr != m_ErrorMessages.end())
  1267. {
  1268. m_MSGUnit->AddErrorMessage(ErrCode, level, iterr->second.c_str());
  1269. //return false;
  1270. }
  1271. }
  1272. }
  1273. if (strPackage[Index] == 'R' && strPackage[Index + 1] == 'O' && strPackage[Index + 2] == 'N')//RON RDY XON OFF
  1274. {
  1275. m_nProcessXrayon = true;
  1276. if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::CONVENTIONAL)
  1277. {
  1278. m_DoseUnit.m_Handswitch->Update(AttrKey::HANDSWITCH_STATUS::HANDSWITCH_STATUS_Release);
  1279. FireNotify(m_DoseUnit.m_Handswitch->GetKey(), m_DoseUnit.m_Handswitch->JSGet());
  1280. FINFO("Updata m_DoseUnit.m_Handswitch: {$}", m_DoseUnit.m_Handswitch->JSGet());
  1281. }
  1282. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_SYNC::GENERATOR_RAD_PREPARE);
  1283. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1284. FINFO("Updata m_DoseUnit.m_GenSynState: {$}", m_DoseUnit.m_GenSynState->JSGet());
  1285. }
  1286. if (strPackage[Index] == 'R' && strPackage[Index + 1] == 'D' && strPackage[Index + 2] == 'Y')//RON RDY XON OFF
  1287. {
  1288. m_nProcessXrayon = true;
  1289. if (m_DoseUnit.m_GenSynState->Get() != AttrKey::GENERATOR_SYNC::GENERATOR_RAD_PREPARE)
  1290. {
  1291. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_SYNC::GENERATOR_RAD_PREPARE);
  1292. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1293. FINFO("Updata m_DoseUnit.m_GenSynState: {$}", m_DoseUnit.m_GenSynState->JSGet());
  1294. }
  1295. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_SYNC::GENERATOR_RAD_READY);
  1296. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1297. FINFO("Updata m_DoseUnit.m_GenSynState: {$}", m_DoseUnit.m_GenSynState->JSGet());
  1298. Sleep(20);//此发生器RDY和XON有时消息会过快,导致工作流没反应过来。所以加个睡眠。
  1299. FINFO("m_bIsDualExp: {$} m_nExposureNumber: {$}", m_bIsDualExp, m_nExposureNumber);
  1300. if (m_bIsDualExp && (m_nExposureNumber == 1))
  1301. {
  1302. if (m_bSendXwindowToDector)
  1303. {
  1304. m_pDetectorClient = new LogicClient("DV3_Detector", "", "NSQ", false);
  1305. if (m_pDetectorClient->Open("CCOS/DEVICE/Detector", ALL_ACCESS)) //换成探测器的路径
  1306. {
  1307. FDEBUG("Ccos_V3 Create DV3_Detector Client success");
  1308. }
  1309. }
  1310. if (m_pDetectorClient != NULL)
  1311. {
  1312. if (!m_pDetectorClient->IsClosed())
  1313. {
  1314. FINFO("m_pDetectorClient is open");
  1315. ResDataObject Request, Response;
  1316. Request.add("P0", 1);
  1317. m_pDetectorClient->Action("DualSecondExpReady", Request, Response, 4993);
  1318. }
  1319. else
  1320. {
  1321. FINFO("DV3_Detector Client is Close");
  1322. }
  1323. }
  1324. else
  1325. {
  1326. FINFO("DV3_FullUCB Client is NULL");
  1327. }
  1328. m_bIsDualExp = false; //第二次设定之后,主动false
  1329. m_nExposureNumber = 0;
  1330. }
  1331. }
  1332. if (strPackage[Index] == 'X' && strPackage[Index + 1] == 'O' && strPackage[Index + 2] == 'N')//RON RDY XON OFF
  1333. {
  1334. m_nProcessXrayon = true;
  1335. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_SYNC::GENERATOR_RAD_XRAYON);
  1336. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1337. FINFO("Updata m_DoseUnit.m_GenSynState: {$}", m_DoseUnit.m_GenSynState->JSGet());
  1338. m_bXronMsg = true;
  1339. }
  1340. if (strPackage[Index] == 'O' && strPackage[Index + 1] == 'F' && strPackage[Index + 2] == 'F')//RON RDY XON OFF
  1341. {
  1342. if (m_bXronMsg == false)
  1343. {
  1344. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_SYNC::GENERATOR_RAD_XRAYON);
  1345. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1346. FINFO("Updata m_DoseUnit.m_GenSynState: {$}", m_DoseUnit.m_GenSynState->JSGet());
  1347. }
  1348. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_SYNC::GENERATOR_RAD_XRAYOFF);
  1349. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1350. FINFO("Updata m_DoseUnit.m_GenSynState: {$}", m_DoseUnit.m_GenSynState->JSGet());
  1351. GetLastExpParamenters();
  1352. if (m_bIsDualExp)
  1353. {
  1354. m_nExposureNumber = 1;
  1355. SetDualEnergyCommand(m_tAPRdata);
  1356. FINFO("dual: setapr 2nd.");
  1357. }
  1358. m_nProcessXrayon = false;
  1359. m_bXronMsg = false;
  1360. }
  1361. return;
  1362. }
  1363. switch (UINT8(strPackage[Index + 1]))
  1364. {
  1365. case 0x50:
  1366. {
  1367. switch (UINT8(strPackage[Index + 2]))
  1368. {
  1369. case 0xA1:
  1370. //50A1
  1371. FINFO("Restore factory settings successfully");
  1372. break;
  1373. default:
  1374. break;
  1375. }
  1376. break;
  1377. }
  1378. case 0x51:
  1379. {
  1380. switch (UINT8(strPackage[Index + 2]))
  1381. {
  1382. case 0x01:
  1383. {
  1384. //5101
  1385. int nET = (int)(strPackage[Index + 3]);
  1386. FINFO("ET{$}", nET);
  1387. if (nET == 1)//AEC
  1388. {
  1389. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_AEC_3P);
  1390. }
  1391. else if (nET == 2)//MS
  1392. {
  1393. if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::TABLE)
  1394. {
  1395. if (m_nTableUsePanelAEC == 1)
  1396. {
  1397. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_AEC_3P);
  1398. }
  1399. else
  1400. {
  1401. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_3P);
  1402. }
  1403. }
  1404. else if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::WALL)
  1405. {
  1406. if (m_nWallUsePanelAEC == 1)
  1407. {
  1408. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_AEC_3P);
  1409. }
  1410. else
  1411. {
  1412. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_3P);
  1413. }
  1414. }
  1415. else if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::MOBILE)
  1416. {
  1417. if (m_nFreeUsePanelAEC == 1)
  1418. {
  1419. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_AEC_3P);
  1420. }
  1421. else
  1422. {
  1423. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_3P);
  1424. }
  1425. }
  1426. else
  1427. {
  1428. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_3P);
  1429. }
  1430. }
  1431. else if (nET == 3)//MAS
  1432. {
  1433. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_2P);
  1434. }
  1435. FireNotify(m_DoseUnit.m_Techmode->GetKey(), m_DoseUnit.m_Techmode->JSGet());
  1436. FINFO("[51 01]: ET {$}", m_DoseUnit.m_Techmode->Get());
  1437. break;
  1438. }
  1439. case 0xA1:
  1440. {
  1441. //51A1
  1442. int nET = (int)(strPackage[Index + 3]);
  1443. if (nET == 1)//AEC
  1444. {
  1445. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P);
  1446. FireNotify(m_DoseUnit.m_Techmode->GetKey(), m_DoseUnit.m_Techmode->JSGet());
  1447. m_AECinformation.Chamber = (int)(strPackage[4]);
  1448. m_AECinformation.Field = (int)(strPackage[5]);
  1449. m_AECinformation.Density = (int)(strPackage[6]);
  1450. m_AECinformation.FilmScreenSpeed = (int)(strPackage[7]);
  1451. UpdataAECInformation(m_AECinformation);
  1452. }
  1453. else if (nET == 2)//如果当前是DAEC模式,那么返回的是time,但是可能需要选中 AEC 按钮
  1454. {
  1455. if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::TABLE)
  1456. {
  1457. if (m_nTableUsePanelAEC == 1)
  1458. {
  1459. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_AEC_3P);
  1460. }
  1461. else
  1462. {
  1463. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_3P);
  1464. }
  1465. }
  1466. else if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::WALL)
  1467. {
  1468. if (m_nWallUsePanelAEC == 1)
  1469. {
  1470. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_AEC_3P);
  1471. }
  1472. else
  1473. {
  1474. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_3P);
  1475. }
  1476. }
  1477. else if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::MOBILE)
  1478. {
  1479. if (m_nFreeUsePanelAEC == 1)
  1480. {
  1481. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_AEC_3P);
  1482. }
  1483. else
  1484. {
  1485. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_3P);
  1486. }
  1487. }
  1488. else
  1489. {
  1490. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_3P);
  1491. }
  1492. FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet());
  1493. FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet());
  1494. }
  1495. else if (nET == 3)
  1496. {
  1497. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_2P);
  1498. }
  1499. FireNotify(m_DoseUnit.m_Techmode->GetKey(), m_DoseUnit.m_Techmode->JSGet());
  1500. FINFO("[51 A1]: ET {$}", m_DoseUnit.m_Techmode->Get());
  1501. break;
  1502. }
  1503. default:
  1504. break;
  1505. }
  1506. break;
  1507. }
  1508. case 0x52:
  1509. {
  1510. switch (UINT8(strPackage[Index + 2]))
  1511. {
  1512. case 0x01:
  1513. {
  1514. //5201
  1515. FINFO("[52 01]");
  1516. break;
  1517. }
  1518. case 0xA1:
  1519. {
  1520. //52A1
  1521. FINFO("[52 A1]");
  1522. break;
  1523. }
  1524. default:
  1525. break;
  1526. }
  1527. break;
  1528. }
  1529. case 0x53:
  1530. {
  1531. switch (UINT8(strPackage[2]))
  1532. {
  1533. case 0x01:
  1534. {
  1535. //5301
  1536. FINFO("[53 01]");
  1537. break;
  1538. }
  1539. default:
  1540. break;
  1541. }
  1542. break;
  1543. }
  1544. case 0x54:
  1545. {
  1546. switch (UINT8(strPackage[Index + 2]))
  1547. {
  1548. case 0x01:
  1549. {
  1550. //5401
  1551. FINFO("[54 01]");
  1552. break;
  1553. }
  1554. case 0x02:
  1555. {
  1556. //5402
  1557. FINFO("[54 02]");
  1558. break;
  1559. }
  1560. case 0xA1:
  1561. {
  1562. //54A1
  1563. FINFO("[54 A1]");
  1564. break;
  1565. }
  1566. case 0xA2:
  1567. {
  1568. //54A2
  1569. FINFO("[54 A2]");
  1570. break;
  1571. }
  1572. default:
  1573. break;
  1574. }
  1575. break;
  1576. }
  1577. case 0x55:
  1578. {
  1579. switch (UINT8(strPackage[Index + 2]))
  1580. {
  1581. case 0x01:
  1582. case 0xA1:
  1583. {
  1584. //55A1
  1585. m_AECinformation.Chamber = (int)(strPackage[Index + 3]);
  1586. m_AECinformation.Field = (int)(strPackage[Index + 4]);
  1587. m_AECinformation.Density = (int)(strPackage[Index + 5]);
  1588. m_AECinformation.FilmScreenSpeed = (int)(strPackage[Index + 6]);
  1589. UpdataAECInformation(m_AECinformation);
  1590. FINFO("[55 A1]: AEC");
  1591. break;
  1592. }
  1593. case 0xA2:
  1594. {
  1595. //55A2
  1596. //kv
  1597. int nKv = (BYTE)(strPackage[Index + 3]);
  1598. m_DoseUnit.m_KV->Update(nKv);
  1599. FireNotify(m_DoseUnit.m_KV->GetKey(), m_DoseUnit.m_KV->JSGet());
  1600. //ma
  1601. float fMA = ((BYTE)(strPackage[Index + 4]) * 256 + (BYTE)strPackage[Index + 5]) / 10.0f;
  1602. m_DoseUnit.m_MA->Update(fMA);
  1603. FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet());
  1604. //aec reference kv
  1605. //not ms
  1606. float m_fMS = ((BYTE)strPackage[Index + 6] * 256 + (BYTE)strPackage[Index + 7]) / 10.0f;
  1607. m_DoseUnit.m_MS->Update(m_fMS);
  1608. FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet());
  1609. int hundred_aec_referenc_kv = (BYTE)strPackage[Index + 6] * 256 + (BYTE)strPackage[Index + 7];
  1610. float mas = m_DoseUnit.m_MA->Get() * m_DoseUnit.m_MS->Get() / 1000.0f;
  1611. GetFacFloatValue(m_vecMAS, mas);
  1612. m_DoseUnit.m_MAS->Update(mas);
  1613. FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet());
  1614. FINFO("[55 A2]: Updata: KV: {$}, MA: {$}, MS: {$}, MAS: {$}",
  1615. m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MA->Get(), m_DoseUnit.m_MS->Get(), m_DoseUnit.m_MAS->Get());
  1616. break;
  1617. }
  1618. default:
  1619. break;
  1620. }
  1621. break;
  1622. }
  1623. case 0x56:
  1624. {
  1625. switch (UINT8(strPackage[Index + 2]))
  1626. {
  1627. case 0x02:
  1628. {
  1629. //5602
  1630. //查询脉冲帧率,不用
  1631. FINFO("[56 02]: AEC.");
  1632. break;
  1633. }
  1634. case 0xA1:
  1635. {
  1636. //56A1
  1637. //kv
  1638. int nKv = (BYTE)(strPackage[Index + 3]);
  1639. m_DoseUnit.m_KV->Update(nKv);
  1640. FireNotify(m_DoseUnit.m_KV->GetKey(), m_DoseUnit.m_KV->JSGet());
  1641. //ma
  1642. float fMA = ((BYTE)(strPackage[Index + 4]) * 256 + (BYTE)strPackage[Index + 5]) / 10.0f;
  1643. m_DoseUnit.m_MA->Update(fMA);
  1644. FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet());
  1645. //ms
  1646. float fMS = ((BYTE)(strPackage[Index + 6]) * 65536 + (BYTE)strPackage[Index + 7] * 256 + (BYTE)strPackage[Index + 8]) / 10.0f;
  1647. m_DoseUnit.m_MS->Update(fMS);
  1648. FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet());
  1649. float mas = m_DoseUnit.m_MA->Get() * m_DoseUnit.m_MS->Get() / 1000.0f;
  1650. GetFacFloatValue(m_vecMAS, mas);
  1651. m_DoseUnit.m_MAS->Update(mas);
  1652. FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet());
  1653. FINFO("[56 A1]: Time mode: Updata: KV: {$}, MA: {$}, MS: {$}, MAS: {$}",
  1654. m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MA->Get(), m_DoseUnit.m_MS->Get(), m_DoseUnit.m_MAS->Get());
  1655. break;
  1656. }
  1657. case 0xA2:
  1658. {
  1659. //56A2设置脉冲帧率,暂时不用
  1660. FINFO("[56 A2]:");
  1661. break;
  1662. }
  1663. case 0xA3:
  1664. {
  1665. //56A3透视检查的kv ma mas,暂时用不到,不解析了。
  1666. FINFO("[56 A3]:");
  1667. break;
  1668. }
  1669. default:
  1670. break;
  1671. }
  1672. break;
  1673. }
  1674. case 0x57://-----------------------------------------------------------首次进入时,直接切换到mas,ma ms 没有消失****************bug
  1675. {
  1676. switch (UINT8(strPackage[Index + 2]))
  1677. {
  1678. case 0xA1:
  1679. {
  1680. //57A1mas模式下的 kv mas 解析
  1681. //kv
  1682. int nKv = (int)(strPackage[Index + 3]);
  1683. m_DoseUnit.m_KV->Update(nKv);
  1684. FireNotify(m_DoseUnit.m_KV->GetKey(), m_DoseUnit.m_KV->JSGet());
  1685. //ma
  1686. float fMA = ((BYTE)(strPackage[Index + 4]) * 256 + (BYTE)strPackage[Index + 5]) / 10.0f;
  1687. m_DoseUnit.m_MA->Update(fMA);
  1688. FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet());
  1689. //ms----MAS 模式下,返回的ms值。
  1690. float fMS = ((BYTE)(strPackage[Index + 6]) * 65536 + (BYTE)strPackage[Index + 7] * 256 + (BYTE)strPackage[Index + 8]) / 10.0f;
  1691. m_DoseUnit.m_MS->Update(fMS);
  1692. FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet());
  1693. float mas = m_DoseUnit.m_MA->Get() * m_DoseUnit.m_MS->Get() / 1000.0f;
  1694. GetFacFloatValue(m_vecMAS, mas);
  1695. m_DoseUnit.m_MAS->Update(mas);
  1696. FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet());
  1697. FINFO("[57 A1]: MAS mode: Updata: KV: {$}, MA: {$}, MS: {$}, MAS: {$}(calc)", m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MA->Get(), m_DoseUnit.m_MS->Get(), m_DoseUnit.m_MAS->Get());
  1698. break;
  1699. }
  1700. default:
  1701. break;
  1702. }
  1703. break;
  1704. }
  1705. case 0x58:
  1706. {
  1707. switch (UINT8(strPackage[Index + 2]))
  1708. {
  1709. case 1:
  1710. {
  1711. int dapStatus = (int)(strPackage[Index + 2]);
  1712. if (1 == dapStatus)
  1713. {
  1714. //dap enable
  1715. float fDap = 0;
  1716. UINT8 tmpBuf[4] = { 0 };
  1717. tmpBuf[0] = strPackage[Index + 7];
  1718. tmpBuf[1] = strPackage[Index + 6];
  1719. tmpBuf[2] = strPackage[Index + 5];
  1720. tmpBuf[3] = strPackage[Index + 4];
  1721. memcpy(&fDap, tmpBuf, 4);
  1722. int nDAP = (int)fDap;
  1723. }
  1724. else
  1725. {
  1726. //dap disable
  1727. }
  1728. break;
  1729. }
  1730. case 2:
  1731. {
  1732. //dap rate
  1733. float fDapRate = 0;
  1734. UINT8 tmpBuf[4] = { 0 };
  1735. tmpBuf[0] = strPackage[Index + 6];
  1736. tmpBuf[1] = strPackage[Index + 5];
  1737. tmpBuf[2] = strPackage[Index + 4];
  1738. tmpBuf[3] = strPackage[Index + 3];
  1739. memcpy(&fDapRate, tmpBuf, 4);
  1740. //mGycm^2/s
  1741. break;
  1742. }
  1743. case 0xA1:
  1744. {
  1745. FINFO("[58 A1]: clear dap and dap rate success!");
  1746. break;
  1747. }
  1748. default:
  1749. break;
  1750. }
  1751. break;
  1752. }
  1753. case 0x59:
  1754. {
  1755. switch (UINT8(strPackage[Index + 2]))
  1756. {
  1757. case 0xA1:
  1758. {
  1759. //59A1
  1760. int nResetLevel = (int)(strPackage[Index + 3]);
  1761. FINFO("[59 A1]:");
  1762. break;
  1763. }
  1764. default:
  1765. break;
  1766. }
  1767. break;
  1768. }
  1769. case 0x5A:
  1770. {
  1771. switch (UINT8(strPackage[Index + 2]))
  1772. {
  1773. case 0x01:
  1774. {
  1775. //5A01
  1776. FINFO("[5A 01]:");
  1777. break;
  1778. }
  1779. case 0xA1:
  1780. {
  1781. //5AA1
  1782. int nFo = (int)(strPackage[Index + 3]);
  1783. if (1 == nFo)
  1784. {
  1785. m_DoseUnit.m_Focus->Update(1);
  1786. }
  1787. else if (2 == nFo)
  1788. {
  1789. m_DoseUnit.m_Focus->Update(0);
  1790. }
  1791. else//auto
  1792. {
  1793. m_DoseUnit.m_Focus->Update(0);
  1794. }
  1795. FireNotify(m_DoseUnit.m_Focus->GetKey(), m_DoseUnit.m_Focus->JSGet());
  1796. //RetrieveGeneratroDerating();
  1797. FINFO("[5A A1]: FO= {$}", m_DoseUnit.m_Focus->Get());
  1798. break;
  1799. }
  1800. default:
  1801. break;
  1802. }
  1803. break;
  1804. }
  1805. case 0x5B:
  1806. {
  1807. switch (UINT8(strPackage[Index + 2]))
  1808. {
  1809. case 0x01:
  1810. {
  1811. //5B01
  1812. FINFO("[5B 01]");
  1813. break;
  1814. }
  1815. case 0xA1:
  1816. {
  1817. //5BA1
  1818. FINFO("[5B A1]");
  1819. break;
  1820. }
  1821. default:
  1822. break;
  1823. }
  1824. break;
  1825. }
  1826. case 0x5C:
  1827. {
  1828. switch (UINT8(strPackage[Index + 2]))
  1829. {
  1830. case 0xA1:
  1831. {
  1832. //5CA1
  1833. FINFO("[5C A1]:Gen Operate Status is Shutdown");
  1834. break;
  1835. }
  1836. case 0xA2:
  1837. {
  1838. //5CA2
  1839. FINFO("[5C A2]:Gen Operate Status is StandBy");
  1840. break;
  1841. }
  1842. case 0x03:
  1843. case 0xA3:
  1844. {
  1845. //5CA3
  1846. int nExpEnable = (int)(strPackage[Index + 3]);
  1847. FINFO("[5C A3/03]:m_bExpEnable");
  1848. break;
  1849. }
  1850. default:
  1851. break;
  1852. }
  1853. break;
  1854. }
  1855. case 0x5E:
  1856. {
  1857. switch (UINT8(strPackage[Index + 2]))
  1858. {
  1859. case 0x01:
  1860. {
  1861. FINFO("[5E 01]:tube id is 1");
  1862. break;
  1863. }
  1864. case 0x02:
  1865. {
  1866. FINFO("[5E 01]:tube id is 2");
  1867. break;
  1868. }
  1869. case 0x03:
  1870. {
  1871. FINFO("[5E 03]");
  1872. break;
  1873. }
  1874. default:
  1875. break;
  1876. }
  1877. break;
  1878. }
  1879. case 0x5F:
  1880. {
  1881. switch (UINT8(strPackage[Index + 2]))
  1882. {
  1883. case 0x01:
  1884. {
  1885. //5F01
  1886. int TenTubeHU = BYTE(strPackage[Index + 3]) * 256 + (BYTE)strPackage[Index + 4];
  1887. m_DoseUnit.m_HE->Update(TenTubeHU / 10);
  1888. FireNotify(m_DoseUnit.m_HE->GetKey(), m_DoseUnit.m_HE->JSGet());
  1889. ////::PostMessage(this->m_hWnd, MSG_GEN_PARAM, GEN_PARAM_HE, this->m_nTubeHeat);
  1890. //int TenGenHU = BYTE(strPackage[5]) * 256 + (BYTE)strPackage[6];
  1891. //m_nGenHeat = TenGenHU / 10;
  1892. ////GEN_PARAM_GENHEAT->侯雷确认 是温度。不应该用于这里
  1893. ////::PostMessage(this->m_hWnd, MSG_GEN_PARAM, GEN_PARAM_GENHEAT, this->m_nGenHeat);
  1894. ////GEN_TUBEHU_STATUS 是状态,协议中没有根据genhu的值来定义状态的规定。因此不用这段代码
  1895. ////::PostMessage(this->m_hWnd, MSG_GEN_PARAM, GEN_TUBEHU_STATUS, this->m_nGenHeat);
  1896. //int TenMotorHU = BYTE(strPackage[7]) * 256 + (BYTE)strPackage[8];
  1897. //strlog.Format("5F 01,tube HU = %d,gen HU*10=%d MotorHU*10=%d", m_nTubeHeat, TenGenHU, TenMotorHU);
  1898. //logfile->WriteLog(strlog, LOG_INFORMATION, LOG_DEBUG, true);
  1899. break;
  1900. }
  1901. default:
  1902. break;
  1903. }
  1904. break;
  1905. }
  1906. case 0x61:
  1907. {
  1908. switch (UINT8(strPackage[Index + 2]))
  1909. {
  1910. case 0x01:
  1911. {
  1912. string GenFirmwareVersion = AnalysisCommand(BYTE_6, chdigital, TransToType::tochar);
  1913. string ConsoleFirmwareVersion = AnalysisCommand(BYTE_6, chdigital, TransToType::tochar);
  1914. FINFO("[61 01]:Generator firmware version {$}, Console firmware version {$}", GenFirmwareVersion, ConsoleFirmwareVersion);
  1915. break;
  1916. }
  1917. case 0x02:
  1918. {
  1919. break;
  1920. }
  1921. case 0x03:
  1922. {
  1923. break;
  1924. }
  1925. case 0x04:
  1926. {
  1927. int maxKw = (int)(strPackage[Index + 3] << 8 | strPackage[Index + 4]);
  1928. int maxMa = (int)(strPackage[Index + 5] << 8 | strPackage[Index + 6]);
  1929. int maxMas = (int)(strPackage[Index + 7] << 8 | strPackage[Index + 8]);
  1930. int maxKv = (int)(strPackage[Index + 9]);
  1931. int nFo = (int)(strPackage[Index + 10]);
  1932. int nRotor = (int)(strPackage[Index + 11]);
  1933. int nMotorFirmwareVersion = (int)(strPackage[Index + 12] << 8 | strPackage[Index + 13]);
  1934. int nSWCfgFileVersion = (int)(strPackage[Index + 14]);
  1935. break;
  1936. }
  1937. case 0x05:
  1938. {
  1939. m_nMaxKW = (int)(strPackage[Index + 3] << 8 | strPackage[Index + 4]);
  1940. int maxDeratingMa = (int)(strPackage[Index + 5] << 8 | strPackage[Index + 6]);
  1941. int maxDeratingMas = (int)(strPackage[Index + 7] << 8 | strPackage[Index + 8]);
  1942. int maxDeratingKv = (int)(strPackage[Index + 9]);
  1943. int minDeratingMa = (int)(strPackage[Index + 10] << 8 | strPackage[Index + 11]);
  1944. int maxDeratingMs = (int)(strPackage[Index + 12] << 8 | strPackage[Index + 13]);
  1945. break;
  1946. }
  1947. case 0x06:
  1948. {
  1949. break;
  1950. }
  1951. case 0xA5:
  1952. {
  1953. break;
  1954. }
  1955. case 0x07:
  1956. case 0xA7:
  1957. {
  1958. int nAccuracy = (int)(strPackage[Index + 3]);
  1959. if (1 == nAccuracy)
  1960. {
  1961. //logfile->WriteLog("61 07 / A7 :now is R10' series.", LOG_INFORMATION, LOG_DEBUG, true);
  1962. }
  1963. else if (2 == nAccuracy)
  1964. {
  1965. //logfile->WriteLog("61 07 / A7 :now is R20' series.", LOG_INFORMATION, LOG_DEBUG, true);
  1966. }
  1967. break;
  1968. }
  1969. case 0xAC:
  1970. {
  1971. //DAEC enable status
  1972. int nDaecStatus = (int)(strPackage[Index + 3]);
  1973. //m_nDAECStatus = nDaecStatus;
  1974. //if (nDaecStatus == 1)
  1975. //{
  1976. // logfile->WriteLog("recv 6e AC: daec enable", LOG_INFORMATION, LOG_DEBUG, true);
  1977. //}
  1978. //else if (nDaecStatus == 2)
  1979. //{
  1980. // logfile->WriteLog("recv 6e AC: daec disable", LOG_INFORMATION, LOG_DEBUG, true);
  1981. //}
  1982. break;
  1983. }
  1984. default:
  1985. break;
  1986. }
  1987. break;
  1988. }
  1989. case 0x62:
  1990. {
  1991. switch (UINT8(strPackage[Index + 2]))
  1992. {
  1993. case 0x01:
  1994. {
  1995. break;
  1996. }
  1997. case 0x02:
  1998. {
  1999. chdigital = strPackage + 3;
  2000. int SF_LS_MaxPower = (int)(strPackage[Index + 3] << 8 | strPackage[Index + 4]);
  2001. int LF_LS_MaxPower = (int)(strPackage[Index + 5] << 8 | strPackage[Index + 6]);
  2002. int SF_HS_MaxPower = (int)(strPackage[Index + 7] << 8 | strPackage[Index + 8]);
  2003. int LF_HS_MaxPower = (int)(strPackage[Index + 9] << 8 | strPackage[Index + 10]);
  2004. break;
  2005. }
  2006. case 0x03:
  2007. {
  2008. int SF_standbycurrent = (int)(strPackage[Index + 3] << 8 | strPackage[Index + 4]);
  2009. int SF_maxcurrent = (int)(strPackage[Index + 5] << 8 | strPackage[Index + 6]);
  2010. int LF_standbycurrent = (int)(strPackage[Index + 7] << 8 | strPackage[Index + 8]);
  2011. int LF_maxcurrent = (int)(strPackage[Index + 9] << 8 | strPackage[Index + 10]);
  2012. break;
  2013. }
  2014. case 0x04:
  2015. {
  2016. int HUWarning = (int)(strPackage[Index + 3]);
  2017. int HULimit = (int)(strPackage[Index + 4]);
  2018. break;
  2019. }
  2020. case 0x05:
  2021. {
  2022. int maxTubeKv = (int)(strPackage[Index + 3]);
  2023. int max_SF_TubecurrentMA = (int)(strPackage[Index + 4] << 8 | strPackage[Index + 5]);
  2024. int max_LF_TubecurrentMA = (int)(strPackage[Index + 6] << 8 | strPackage[Index + 7]);
  2025. break;
  2026. }
  2027. case 0xA2:
  2028. {
  2029. int SF_LS_MaxPower = (int)(strPackage[Index + 3] << 8 | strPackage[Index + 4]);
  2030. int LF_LS_MaxPower = (int)(strPackage[Index + 5] << 8 | strPackage[Index + 6]);
  2031. int SF_HS_MaxPower = (int)(strPackage[Index + 7] << 8 | strPackage[Index + 8]);
  2032. int LF_HS_MaxPower = (int)(strPackage[Index + 9] << 8 | strPackage[Index + 10]);
  2033. break;
  2034. }
  2035. case 0xA3:
  2036. {
  2037. int SF_standbycurrent = (int)(strPackage[Index + 3] << 8 | strPackage[Index + 4]);
  2038. int SF_maxcurrent = (int)(strPackage[Index + 5] << 8 | strPackage[Index + 6]);
  2039. int LF_standbycurrent = (int)(strPackage[Index + 7] << 8 | strPackage[Index + 8]);
  2040. int LF_maxcurrent = (int)(strPackage[Index + 9] << 8 | strPackage[Index + 10]);
  2041. break;
  2042. }
  2043. case 0xA4:
  2044. {
  2045. int HUWarning = (int)(strPackage[Index + 3]);
  2046. int HULimit = (int)(strPackage[Index + 4]);
  2047. break;
  2048. }
  2049. case 0xA5:
  2050. {
  2051. break;
  2052. }
  2053. default:
  2054. break;
  2055. }
  2056. break;
  2057. }
  2058. case 0x63:
  2059. {
  2060. switch (UINT8(strPackage[Index + 2]))
  2061. {
  2062. case 0x01:
  2063. {
  2064. break;
  2065. }
  2066. case 0x02:
  2067. {
  2068. break;
  2069. }
  2070. default:
  2071. break;
  2072. }
  2073. break;
  2074. }
  2075. case 0x64:
  2076. {
  2077. switch (UINT8(strPackage[Index + 2]))
  2078. {
  2079. case 0x01:
  2080. {
  2081. /*
  2082. 0x00 = INITIAL
  2083. 0x01 = STANDBY
  2084. 0x02 = READY
  2085. 0x03 = OPERATE
  2086. 0x04 = SHUTDOWN
  2087. 0x05 = CALIBRATION
  2088. 0x06 = SEASON
  2089. */
  2090. //6401
  2091. int nGenStatus = (int)(strPackage[Index + 3]);
  2092. if (0 == nGenStatus)
  2093. {
  2094. FINFO("[64 01 01]:GENERATOR_STATUS_INIT");
  2095. m_DoseUnit.m_GenState->Update(AttrKey::GENERATOR_STATUS::GENERATOR_STATUS_INIT);
  2096. FireNotify(m_DoseUnit.m_GenState->GetKey(), m_DoseUnit.m_GenState->JSGet());
  2097. }
  2098. else if (1 == nGenStatus)
  2099. {
  2100. FINFO("[64 01 01]:GENERATOR_STATUS_STANDBY");
  2101. m_DoseUnit.m_GenState->Update(AttrKey::GENERATOR_STATUS::GENERATOR_STATUS_STANDBY);
  2102. FireNotify(m_DoseUnit.m_GenState->GetKey(), m_DoseUnit.m_GenState->JSGet());
  2103. }
  2104. else if (2 == nGenStatus)
  2105. {
  2106. FINFO("[64 01 02]: GENERATOR_STATUS_STANDBY");
  2107. m_DoseUnit.m_GenState->Update(AttrKey::GENERATOR_STATUS::GENERATOR_STATUS_STANDBY);
  2108. FireNotify(m_DoseUnit.m_GenState->GetKey(), m_DoseUnit.m_GenState->JSGet());
  2109. }
  2110. else if (3 == nGenStatus)
  2111. {
  2112. FINFO("[64 01 03]: GENERATOR_STATUS_EXP");
  2113. m_DoseUnit.m_GenState->Update(AttrKey::GENERATOR_STATUS::GENERATOR_STATUS_EXP);
  2114. FireNotify(m_DoseUnit.m_GenState->GetKey(), m_DoseUnit.m_GenState->JSGet());
  2115. }
  2116. else if (4 == nGenStatus)
  2117. {
  2118. FINFO("[64 01 04]: GENERATOR_STATUS_SHUTDOWN");
  2119. m_DoseUnit.m_GenState->Update(AttrKey::GENERATOR_STATUS::GENERATOR_STATUS_SHUTDOWN);
  2120. FireNotify(m_DoseUnit.m_GenState->GetKey(), m_DoseUnit.m_GenState->JSGet());
  2121. }
  2122. else if (5 == nGenStatus)
  2123. {
  2124. FINFO("[64 01 05]: GENERATOR_STATUS_CALIBRATION");
  2125. m_DoseUnit.m_GenState->Update(AttrKey::GENERATOR_STATUS::GENERATOR_STATUS_CALIBRATION);
  2126. FireNotify(m_DoseUnit.m_GenState->GetKey(), m_DoseUnit.m_GenState->JSGet());
  2127. }
  2128. else if (6 == nGenStatus)
  2129. {
  2130. FINFO("[64 01 06]: GENERATOR_STATUS_ERROR");
  2131. m_DoseUnit.m_GenState->Update(AttrKey::GENERATOR_STATUS::GENERATOR_STATUS_ERROR);
  2132. FireNotify(m_DoseUnit.m_GenState->GetKey(), m_DoseUnit.m_GenState->JSGet());
  2133. }
  2134. break;
  2135. }
  2136. case 0x02:
  2137. {
  2138. break;
  2139. }
  2140. case 0x03:
  2141. {
  2142. break;
  2143. }
  2144. default:
  2145. break;
  2146. }
  2147. break;
  2148. }
  2149. case 0x65:
  2150. {
  2151. switch (UINT8(strPackage[Index + 2]))
  2152. {
  2153. case 0x01:
  2154. {
  2155. //6501
  2156. //kv
  2157. int postKv = (BYTE)(strPackage[Index + 3]) << 8 + (BYTE)strPackage[Index + 4];
  2158. m_DoseUnit.m_PostKV->Update(postKv);
  2159. FireNotify(m_DoseUnit.m_PostKV->GetKey(), m_DoseUnit.m_PostKV->JSGet());
  2160. //ma
  2161. int nPostMa = (BYTE)(strPackage[Index + 5]) << 8 + (BYTE)strPackage[Index + 6];
  2162. float fpostMa = nPostMa / 10.0f;
  2163. m_DoseUnit.m_PostMA->Update(fpostMa);
  2164. FireNotify(m_DoseUnit.m_PostMA->GetKey(), m_DoseUnit.m_PostMA->JSGet());
  2165. //ap-postmas
  2166. int nPostMas = (BYTE)(strPackage[Index + 7]) << 16 + (BYTE)strPackage[Index + 8] << 8 + (BYTE)strPackage[Index + 9];
  2167. float fpostMAS = nPostMas / 100.0f;
  2168. m_DoseUnit.m_PostMAS->Update(fpostMAS);
  2169. FireNotify(m_DoseUnit.m_PostMAS->GetKey(), m_DoseUnit.m_PostMAS->JSGet());
  2170. //at-postms
  2171. int nPostMs = (BYTE)(strPackage[Index + 10]) << 16 + (BYTE)strPackage[Index + 11] << 8 + (BYTE)strPackage[Index + 12];
  2172. float fpostMS = nPostMs / 10.0f;
  2173. m_DoseUnit.m_PostMS->Update(fpostMS);
  2174. FireNotify(m_DoseUnit.m_PostMS->GetKey(), m_DoseUnit.m_PostMS->JSGet());
  2175. FINFO("[65 01]: post{$}kv, post{$}ma, post{$}mas, post{$}Ms", postKv, fpostMa, fpostMAS, fpostMS);
  2176. break;
  2177. }
  2178. default:
  2179. break;
  2180. }
  2181. break;
  2182. }
  2183. case 0x6B:
  2184. {
  2185. }
  2186. break;
  2187. case 0x6C:
  2188. {
  2189. int soc = (BYTE)(strPackage[Index + 3]) << 8 + (BYTE)strPackage[Index + 4];
  2190. int vol = (BYTE)(strPackage[Index + 5]) << 8 + (BYTE)strPackage[Index + 6];
  2191. int charge = (BYTE)(strPackage[Index + 7]) << 8 + (BYTE)strPackage[Index + 8];
  2192. int temperature = (BYTE)(strPackage[Index + 9]) << 8 + (BYTE)strPackage[Index + 10];
  2193. int ac = (BYTE)strPackage[Index + 11];
  2194. }
  2195. break;
  2196. case 0x6E:
  2197. {
  2198. switch (UINT8(strPackage[Index + 2]))
  2199. {
  2200. case 0x01:
  2201. case 0xA1:
  2202. {
  2203. //6EA1
  2204. break;
  2205. }
  2206. case 0x02:
  2207. case 0xA2:
  2208. {
  2209. //6EA2
  2210. //此命令比较特殊,切换为胶片模式,需要把下面俩值都设置为0.
  2211. int nDetector1SynMode = (int)(strPackage[Index + 3]);
  2212. int nDetector2SynMode = (int)(strPackage[Index + 4]);
  2213. if (nDetector1SynMode == 0 && nDetector2SynMode == 0)//no detector.
  2214. {
  2215. // m_nWS = WSGen2UI(m_DoseUnit.m_WS->Get());
  2216. //::PostMessage(this->m_hWnd, MSG_GEN_PARAM, GEN_PARAM_WS, m_nWS);//
  2217. //logfile->WriteLog("6E A2:ws convertion mode", LOG_INFORMATION, LOG_DEBUG, true);
  2218. }
  2219. break;
  2220. }
  2221. default:
  2222. break;
  2223. }
  2224. break;
  2225. }
  2226. default:
  2227. break;
  2228. }
  2229. }
  2230. bool nsGEN::DeltaDevice::DecodeFrame(const char* strPackage, int nLength)
  2231. {
  2232. if (strPackage == nullptr || nLength <= 0) {
  2233. FINFO("strPackage: nullptr, nLength: <= 0");
  2234. return false;
  2235. }
  2236. // 使用互斥锁保护缓冲区访问
  2237. std::lock_guard<std::mutex> lock(m_bufferMutex);
  2238. char strSendCommand[10] = { 0 };
  2239. string str = "";
  2240. int PacketLength = 0;
  2241. for (int i = 0; i < nLength; i++)
  2242. {
  2243. snprintf(strSendCommand, sizeof(strSendCommand), "%02X", (BYTE)strPackage[i]);
  2244. str += strSendCommand;
  2245. str += ",";
  2246. }
  2247. FINFO("==IN== {$}", str);
  2248. // 将新数据追加到缓冲区
  2249. if (m_bufferLength + nLength > sizeof(m_buffer)) {
  2250. FINFO("Buffer overflow, resetting buffer!");
  2251. m_bufferLength = 0;
  2252. return false;
  2253. }
  2254. std::memcpy(m_buffer + m_bufferLength, strPackage, nLength);
  2255. m_bufferLength += nLength;
  2256. int index = 0;
  2257. while (index < m_bufferLength) {
  2258. str = ""; // 清空 str 字符串
  2259. // 规则 1:F0 开头,88 结尾,长度为 13
  2260. if (index + 12 < m_bufferLength && static_cast<uint8_t>(m_buffer[index]) == 0xF0 && static_cast<uint8_t>(m_buffer[index + 12]) == 0x88) {
  2261. for (int i = 0; i < 13; ++i) {
  2262. snprintf(strSendCommand, sizeof(strSendCommand), "%02X", (BYTE)m_buffer[index + i]);
  2263. str += strSendCommand;
  2264. str += ",";
  2265. }
  2266. FINFO("Rule 1: ==IN== {$}", str);
  2267. ProcessCommand(strPackage, index, index + 13);
  2268. index += 13;
  2269. }
  2270. // 规则 2:F0 开头,88 结尾,长度为 19
  2271. else if (index + 18 < m_bufferLength && static_cast<uint8_t>(m_buffer[index]) == 0xF0 && static_cast<uint8_t>(m_buffer[index + 18]) == 0x88) {
  2272. for (int i = 0; i < 19; ++i) {
  2273. snprintf(strSendCommand, sizeof(strSendCommand), "%02X", (BYTE)m_buffer[index + i]);
  2274. str += strSendCommand;
  2275. str += ",";
  2276. }
  2277. FINFO("Rule 2: ==IN== {$}", str);
  2278. ProcessCommand(strPackage, index, index + 19);
  2279. index += 19;
  2280. }
  2281. // 规则 3:以 0D 结尾,指令包含 0D 和 0D 前面的三个字符
  2282. else if (index >= 3 && static_cast<uint8_t>(m_buffer[index]) == 0x0D) {
  2283. for (int i = 0; i < 4; ++i) {
  2284. snprintf(strSendCommand, sizeof(strSendCommand), "%02X", (BYTE)m_buffer[index - 3 + i]);
  2285. str += strSendCommand;
  2286. str += ",";
  2287. }
  2288. FINFO("Rule 3: ==IN== {$}", str);
  2289. ProcessCommand(strPackage, index - 3, index + 1);
  2290. index++;
  2291. }
  2292. else {
  2293. index++;
  2294. }
  2295. }
  2296. // 移除已处理的数据
  2297. int processedLength = index;
  2298. std::memmove(m_buffer, m_buffer + processedLength, m_bufferLength - processedLength);
  2299. m_bufferLength -= processedLength;
  2300. return true;
  2301. }
  2302. bool nsGEN::DeltaDevice::ChangeGenParam(int kv, float fma, float fms, float fmas)
  2303. {
  2304. FINFO("KV: {$}, MA: {$}, MS: {$}, MAS: {$}", kv, fma, fms, fmas);
  2305. if (m_DoseUnit.m_Techmode->Get() == 0)
  2306. {
  2307. SetRADKV_MA_MS(kv, fma, fms);
  2308. }
  2309. else if (m_DoseUnit.m_Techmode->Get() == 1)
  2310. {
  2311. SetRADKV_MAS(kv, fmas);
  2312. }
  2313. else if (m_DoseUnit.m_Techmode->Get() == 2)
  2314. {
  2315. if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::TABLE)
  2316. {
  2317. if (m_nTableUsePanelAEC == 1)
  2318. {
  2319. SetRADKV_MA_MS(kv, fma, fms);
  2320. }
  2321. else
  2322. {
  2323. SetAECKV_MA_MS(kv, fma, fms);
  2324. }
  2325. }
  2326. else if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::WALL)
  2327. {
  2328. if (m_nWallUsePanelAEC == 1)
  2329. {
  2330. SetRADKV_MA_MS(kv, fma, fms);
  2331. }
  2332. else
  2333. {
  2334. SetAECKV_MA_MS(kv, fma, fms);
  2335. }
  2336. }
  2337. else if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::MOBILE)
  2338. {
  2339. if (m_nFreeUsePanelAEC == 1)
  2340. {
  2341. SetRADKV_MA_MS(kv, fma, fms);
  2342. }
  2343. else
  2344. {
  2345. SetAECKV_MA_MS(kv, fma, fms);
  2346. }
  2347. }
  2348. }
  2349. return true;
  2350. }
  2351. //F0 6E A2 01 01 00 00 00 00 00 00 00 00 00 00 00 6C 00 88 发送消息
  2352. bool nsGEN::DeltaDevice::SetRADKV_MA_MS(int kv, float ma, float ms)
  2353. {
  2354. FINFO("[0xF0, 0x56, 0xA1]: KV: {$}, MA: {$}, MS: {$}", kv, ma, ms);
  2355. char cmdbuf[20] = { 0xF0, 0x56, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7A, 0x00, 0x88 };
  2356. cmdbuf[3] = kv;
  2357. //确保ma合理
  2358. int posMA = GetFacFloatValue(m_vecMA, ma);//找到之后,再缩小10倍,写入数据帧
  2359. int nTemp = ma * 10;
  2360. cmdbuf[4] = nTemp >> 8;
  2361. cmdbuf[5] = nTemp % 256;
  2362. //确保ms合理
  2363. int posMS = GetFacFloatValue(m_vecMS, ms);
  2364. nTemp = ms * 10;
  2365. cmdbuf[6] = nTemp >> 16;
  2366. cmdbuf[7] = nTemp >> 8;
  2367. cmdbuf[8] = nTemp % 256;
  2368. FormatCommand(cmdbuf, 13);
  2369. string temp(cmdbuf, 13);
  2370. m_strCommand = temp;
  2371. HWSend(m_strCommand.c_str(), m_strCommand.length());
  2372. return true;
  2373. }
  2374. bool nsGEN::DeltaDevice::SetRADKV_MAS(int kv, float mas)
  2375. {
  2376. //57A1
  2377. FINFO("[0xF0, 0x57, 0xA1]:KV: {$}, MAS: {$}", kv, mas);
  2378. char cmdbuf[13] = { 0xF0, 0x57, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7A, 0x00, 0x88 };
  2379. cmdbuf[3] = kv;
  2380. //确保mas合理
  2381. int posMAS = GetFacFloatValue(m_vecMAS, mas);
  2382. //设置mas指令中的数= 实际想要下发的数*100
  2383. int nTemp = mas * 100;
  2384. cmdbuf[6] = nTemp >> 16;
  2385. cmdbuf[7] = nTemp >> 8;
  2386. cmdbuf[8] = nTemp % 256;
  2387. FormatCommand(cmdbuf, 13);
  2388. string temp(cmdbuf, 13);
  2389. m_strCommand = temp;
  2390. HWSend(m_strCommand.c_str(), m_strCommand.length());
  2391. return true;
  2392. }
  2393. bool nsGEN::DeltaDevice::SetAECKV_MA_MS(int kv, float ma, float ms)
  2394. {
  2395. //55A2
  2396. FINFO("[0xF0, 0x55, 0xA2]: KV: {$}, MA; {$}, MS: {$}", kv, ma, ms);
  2397. char cmdbuf[13] = { 0xF0, 0x55, 0xA2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9C, 0x00, 0x88 };
  2398. cmdbuf[3] = kv;
  2399. //确保ma合理
  2400. int posMA = GetFacFloatValue(m_vecMA, ma);
  2401. int nTemp = ma *10;
  2402. cmdbuf[4] = nTemp >> 8;
  2403. cmdbuf[5] = nTemp % 256;
  2404. //确保ms合理
  2405. int posMS = GetFacFloatValue(m_vecMS, ms);
  2406. nTemp = ms * 10;
  2407. cmdbuf[6] = nTemp >> 16;
  2408. cmdbuf[7] = nTemp >> 8;
  2409. cmdbuf[8] = nTemp % 256;
  2410. FormatCommand(cmdbuf, 13);
  2411. string temp(cmdbuf, 13);
  2412. m_strCommand = temp;
  2413. HWSend(m_strCommand.c_str(), m_strCommand.length());
  2414. return true;
  2415. }
  2416. bool nsGEN::DeltaDevice::SetAECInformation(int chamber, int field, int density, int film)
  2417. {
  2418. FINFO("[0xF0, 0x55, 0xA1]: chamber: {$}, field: {$}, density: {$}, film: {$}", chamber, field, density, film);
  2419. char cmdbuf[13] = { 0xF0, 0x55, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9C, 0x00, 0x88 };
  2420. cmdbuf[3] = chamber;
  2421. //field转换
  2422. switch (field)
  2423. {
  2424. case 1:
  2425. cmdbuf[4] = 0x04;
  2426. break;
  2427. case 10:
  2428. cmdbuf[4] = 0x02;
  2429. break;
  2430. case 100:
  2431. cmdbuf[4] = 0x01;
  2432. break;
  2433. case 101:
  2434. cmdbuf[4] = 0x05;
  2435. break;
  2436. case 110:
  2437. cmdbuf[4] = 0x03;
  2438. break;
  2439. case 11:
  2440. cmdbuf[4] = 0x06;
  2441. break;
  2442. case 111:
  2443. cmdbuf[4] = 0x07;
  2444. break;
  2445. default:
  2446. break;
  2447. }
  2448. //density转换
  2449. switch (density)
  2450. {
  2451. case -3:
  2452. cmdbuf[5] = 0;
  2453. break;
  2454. case -2:
  2455. cmdbuf[5] = 1;
  2456. break;
  2457. case -1:
  2458. cmdbuf[5] = 2;
  2459. break;
  2460. case 0:
  2461. cmdbuf[5] = 3;
  2462. break;
  2463. case 1:
  2464. cmdbuf[5] = 4;
  2465. break;
  2466. case 2:
  2467. cmdbuf[5] = 5;
  2468. break;
  2469. case 3:
  2470. cmdbuf[5] = 6;
  2471. break;
  2472. default:
  2473. cmdbuf[5] = 0;
  2474. break;
  2475. }
  2476. if (film > 3)
  2477. {
  2478. film = 3;
  2479. }
  2480. cmdbuf[6] = 0;
  2481. FormatCommand(cmdbuf, 13);
  2482. string temp(cmdbuf, 13);
  2483. m_strCommand = temp;
  2484. HWSend(m_strCommand.c_str(), m_strCommand.length());
  2485. return true;
  2486. }
  2487. //int nsGEN::DeltaDevice::GetFacValue(vector<int> Index, int& value)
  2488. //{
  2489. // int nlength = static_cast <int>(Index.size());
  2490. // if (nlength == 0)
  2491. // {
  2492. // return -1;
  2493. // }
  2494. //
  2495. // int nPos = 0;
  2496. // int nValue = 0;
  2497. // for (int i = 0; i < nlength; i++)
  2498. // {
  2499. // if (value == Index[i])
  2500. // {
  2501. // nPos = i;
  2502. // break;
  2503. // }
  2504. // else if (i == nlength - 1)
  2505. // {
  2506. // nPos = i;
  2507. // break;
  2508. // }
  2509. // else if ((value > Index[i]) && (value < Index[i + 1]))
  2510. // {
  2511. // nPos = (abs(value - Index[i + 1]) > abs(value - Index[i])) ? i : (i + 1);//就近原则
  2512. // break;
  2513. // }
  2514. // else if (value < Index[0])
  2515. // {
  2516. // nPos = 0;
  2517. // break;
  2518. // }
  2519. // }
  2520. // value = Index[nPos];
  2521. // return nPos;
  2522. //}
  2523. int CCOS::Dev::Detail::Generator::DeltaDevice::GetFacFloatValue(vector<float> Index, float& value)
  2524. {
  2525. int nlength = static_cast <int>(Index.size());
  2526. if (nlength == 0)
  2527. {
  2528. return -1;
  2529. }
  2530. int nPos = 0;
  2531. int nValue = 0;
  2532. for (int i = 0; i < nlength; i++)
  2533. {
  2534. if (value == Index[i])
  2535. {
  2536. nPos = i;
  2537. break;
  2538. }
  2539. else if (i == nlength - 1)
  2540. {
  2541. nPos = i;
  2542. break;
  2543. }
  2544. else if ((value > Index[i]) && (value < Index[i + 1]))
  2545. {
  2546. nPos = (abs(value - Index[i + 1]) > abs(value - Index[i])) ? i : (i + 1);//就近原则
  2547. break;
  2548. }
  2549. else if (value < Index[0])
  2550. {
  2551. nPos = 0;
  2552. break;
  2553. }
  2554. }
  2555. value = Index[nPos];
  2556. return nPos;
  2557. }
  2558. bool nsGEN::DeltaDevice::SetRadMode(int radmode, int desmode)
  2559. {
  2560. FINFO("[0xF0, 0x54, 0xA1]: RadMode: {$}, desmode: {$}", radmode, desmode);
  2561. char cmdbuf[13] = { 0xF0, 0x54, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7A, 0x00, 0x88 };
  2562. cmdbuf[3] = radmode;
  2563. cmdbuf[4] = desmode;
  2564. FormatCommand(cmdbuf, 13);
  2565. string temp(cmdbuf, 13);
  2566. m_strCommand = temp;
  2567. HWSend(m_strCommand.c_str(), m_strCommand.length());
  2568. return true;
  2569. }
  2570. std::string nsGEN::DeltaDevice::uint8ArrayToHexStr(const UINT8* array, size_t length)
  2571. {
  2572. std::ostringstream ss;
  2573. ss << std::hex << std::setfill('0'); // 设置十六进制格式和填充字符
  2574. for (size_t i = 0; i < length; ++i) {
  2575. ss << std::setw(2) << static_cast<int>(array[i]) << ' '; // 转换为int以支持十六进制输出,并设置宽度为2
  2576. }
  2577. return ss.str(); // 返回转换后的字符串
  2578. }
  2579. bool nsGEN::DeltaDevice::SetDAECEnable(int enable)
  2580. {
  2581. if (enable)
  2582. {
  2583. FINFO("[0xF0, 0x61, 0xAC, 0x01]: DAECEnable: {$}", enable);
  2584. char cmdbuf[19] = { 0xF0, 0x61, 0xAC, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0xDB, 0x00, 0x88 };
  2585. FormatCommand(cmdbuf, 19);
  2586. string temp(cmdbuf, 19);
  2587. m_strCommand = temp;
  2588. HWSend(m_strCommand.c_str(), m_strCommand.length());
  2589. }
  2590. else
  2591. {
  2592. FINFO("[0xF0, 0x61, 0xAC, 0x02]: DAECEnable: {$}", enable);
  2593. char cmdbuf[19] = { 0xF0, 0x61, 0xAC, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0x00, 0x88 };
  2594. FormatCommand(cmdbuf, 19);
  2595. string temp(cmdbuf, 19);
  2596. m_strCommand = temp;
  2597. HWSend(m_strCommand.c_str(), m_strCommand.length());
  2598. }
  2599. return true;
  2600. }
  2601. int nsGEN::DeltaDevice::WSGen2UI(int InputWS)
  2602. {
  2603. int OutputWS = -1;
  2604. //if (m_nSettingWS == GEN_WS_TABLE) //table lying
  2605. //{
  2606. // if (InputWS == GenConfig.m_nGenWSLying)
  2607. // {
  2608. // OutputWS = GEN_WS_TABLE;
  2609. // }
  2610. //}
  2611. //else if (m_nSettingWS == GEN_WS_WALL) //table standing
  2612. //{
  2613. // if (InputWS == GenConfig.m_nGenWSStand)
  2614. // {
  2615. // OutputWS = GEN_WS_WALL;
  2616. // }
  2617. //}
  2618. //else if (m_nSettingWS == GEN_WS_CONVENTIONAL)
  2619. //{
  2620. // if (InputWS == GenConfig.m_nGenWSConventional)
  2621. // {
  2622. // OutputWS = GEN_WS_CONVENTIONAL;
  2623. // }
  2624. //}
  2625. //else if (m_nSettingWS == GEN_WS_MOBILE) //Free ws
  2626. //{
  2627. // if (InputWS == GenConfig.m_nGenWSFree)
  2628. // {
  2629. // OutputWS = GEN_WS_MOBILE;
  2630. // }
  2631. //}
  2632. //else if (m_nSettingWS == GEN_WS_TOMO)
  2633. //{
  2634. // if (InputWS == GenConfig.m_nGenWSTomo)
  2635. // {
  2636. // OutputWS = GEN_WS_TOMO;
  2637. // }
  2638. //}
  2639. //else
  2640. //{
  2641. // this->logfile->WriteLog("Input WS is wrong", LOG_INFORMATION, LOG_DEBUG, true);
  2642. //}
  2643. //if (OutputWS < 0)
  2644. //{
  2645. // this->logfile->WriteLog("Seting WS is different with Geting WS!", LOG_INFORMATION, LOG_DEBUG, true);
  2646. // if (InputWS == GenConfig.m_nGenWSLying)
  2647. // {
  2648. // OutputWS = GEN_WS_TABLE;
  2649. // }
  2650. // else if (InputWS == GenConfig.m_nGenWSStand)
  2651. // {
  2652. // OutputWS = GEN_WS_WALL;
  2653. // }
  2654. // else if (InputWS == GenConfig.m_nGenWSConventional)
  2655. // {
  2656. // OutputWS = GEN_WS_CONVENTIONAL;
  2657. // }
  2658. // else if (InputWS == GenConfig.m_nGenWSFree)
  2659. // {
  2660. // OutputWS = GEN_WS_MOBILE;
  2661. // }
  2662. // else if (InputWS == GenConfig.m_nGenWSTomo)
  2663. // {
  2664. // OutputWS = GEN_WS_TOMO;
  2665. // }
  2666. // else
  2667. // {
  2668. // //OutputWS = GEN_WS_TABLE;
  2669. // OutputWS = -1;
  2670. // this->logfile->WriteLog("Geting WS is wrong", LOG_INFORMATION, LOG_DEBUG, true);
  2671. // }
  2672. //}
  2673. return OutputWS;
  2674. }
  2675. //-----------------------------------------------------------------------------
  2676. // DecodeFrame
  2677. //-----------------------------------------------------------------------------
  2678. static bool DecodeFrame(const char* strFrame, int length)
  2679. {
  2680. if (nsGEN::DeltaDevice::g_GenDevice)
  2681. {
  2682. nsGEN::DeltaDevice::g_GenDevice->DecodeFrame(strFrame, length);
  2683. }
  2684. return true;
  2685. }
  2686. bool nsGEN::DeltaDevice::GetLastExpParamenters(void)
  2687. {
  2688. FINFO("[0xF0, 0x65, 0x01]");
  2689. char cmdbuf[19] = { 0xF0, 0x65, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCB, 0x00, 0x88 };
  2690. FormatCommand(cmdbuf, 19);
  2691. string temp(cmdbuf, 19);
  2692. m_strCommand = temp;
  2693. HWSend(m_strCommand.c_str(), m_strCommand.length());
  2694. return true;
  2695. }
  2696. int nsGEN::DeltaDevice::FormatCommand(char* buf, int len)
  2697. {
  2698. if (len < 4)
  2699. {
  2700. return -1;
  2701. }
  2702. UINT8 crc = GetCRC8(buf + 1, len - 4);
  2703. buf[len - 3] = crc;
  2704. return crc;
  2705. }
  2706. void nsGEN::DeltaDevice::RetrieveFirewareVersion()
  2707. {
  2708. FINFO("[0xF0, 0x61, 0x01, 0x00]");
  2709. char cmdbuf[19] = { 0xF0, 0x61, 0x01, 0x00, 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00, 0x00, 0x00, 0x00, 0x88 };
  2710. FormatCommand(cmdbuf, 19);
  2711. string temp(cmdbuf, 19);
  2712. m_strCommand = temp;
  2713. HWSend(m_strCommand.c_str(), m_strCommand.length());
  2714. }
  2715. std::string nsGEN::DeltaDevice::GetFileVersion(std::string strFilePathName)
  2716. {
  2717. // Linux下动态库没有Windows风格的版本资源
  2718. // 返回固定版本号或从CMake定义的宏获取
  2719. #ifdef PROJECT_VERSION
  2720. return PROJECT_VERSION;
  2721. #else
  2722. // 返回默认版本号
  2723. FINFO("Getting version for file: {$}", strFilePathName.c_str());
  2724. return "1.0.0";
  2725. #endif
  2726. }
  2727. //"HWS": "1",
  2728. //"CMD" : "2",
  2729. //"FRE" : "3"
  2730. RET_STATUS nsGEN::DeltaDevice::ActiveSyncMode(_tSyncModeArgs value)
  2731. {
  2732. m_cfgCurrentWSSYN = value;
  2733. FINFO("WS: {$}, SyncMode: {$}, SyncValue: {$}", m_cfgCurrentWSSYN.strWS, m_cfgCurrentWSSYN.strSyncMode, m_cfgCurrentWSSYN.strSyncValue);
  2734. if (m_cfgCurrentWSSYN.strWS == "Free")
  2735. {
  2736. SetNoDrMode();
  2737. }
  2738. else
  2739. {
  2740. if (m_cfgCurrentWSSYN.strSyncMode == "FRE")
  2741. {
  2742. SetNoDrMode();
  2743. }
  2744. else
  2745. {
  2746. SetSyncOutMode();
  2747. //if (m_cfgCurrentWSSYN.strWS == "Table")
  2748. //{
  2749. SeleckDetectorNumber(1);
  2750. //}
  2751. //else
  2752. //{
  2753. //SeleckDetectorNumber(2);
  2754. //}
  2755. }
  2756. }
  2757. return RET_STATUS::RET_SUCCEED;
  2758. }
  2759. void nsGEN::DeltaDevice::SetNoDrMode()
  2760. {
  2761. FINFO("[0xF0, 0x6E, 0xA2, 0x00]");
  2762. char cmdbuf[20] = { 0xF0, 0x6E, 0xA2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA5, 0x00, 0x88 };
  2763. FormatCommand(cmdbuf, 19);
  2764. string temp(cmdbuf, 19);
  2765. m_strCommand = temp;
  2766. HWSend(m_strCommand.c_str(), m_strCommand.length());
  2767. }
  2768. void nsGEN::DeltaDevice::SetSyncOutMode()
  2769. {
  2770. FINFO("[0xF0, 0x6E, 0xA2, 0x01]");
  2771. char cmdbuf[20] = { 0xF0, 0x6E, 0xA2, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6C, 0x00, 0x88 };
  2772. FormatCommand(cmdbuf, 19);
  2773. string temp(cmdbuf, 19);
  2774. m_strCommand = temp;
  2775. HWSend(m_strCommand.c_str(), m_strCommand.length());
  2776. }
  2777. void nsGEN::DeltaDevice::SeleckDetectorNumber(int detectorID)
  2778. {
  2779. FINFO("[0xF0, 0x6E, 0xA1, 0x0{$}]", detectorID);
  2780. char cmdbuf[20] = { 0xF0, 0x6E, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0x00, 0x88 };
  2781. cmdbuf[3] = detectorID;
  2782. FormatCommand(cmdbuf, 19);
  2783. string temp(cmdbuf, 19);
  2784. m_strCommand = temp;
  2785. HWSend(m_strCommand.c_str(), m_strCommand.length());
  2786. }
  2787. /*下面的线程函数,其实用来充当定时器功能。*/
  2788. bool nsGEN::DeltaDevice::StartHardwareStatusThread()
  2789. {
  2790. FDEBUG("Enter StartHardwareStatusThread");
  2791. try {
  2792. m_pHardwareStatusThread = std::thread(HardwareStatusThread, this);
  2793. FINFO("HardwareStatus Thread started successfully");
  2794. return true;
  2795. }
  2796. catch (const std::exception& e) {
  2797. FERROR("Start HardwareStatus Thread Failed: {$}", e.what());
  2798. return false;
  2799. }
  2800. }
  2801. void nsGEN::DeltaDevice::HardwareStatusThread(DeltaDevice* pParam)
  2802. {
  2803. FDEBUG("Enter HardwareStatusThread");
  2804. DeltaDevice* pCurGen = pParam;
  2805. if (pCurGen == NULL)
  2806. {
  2807. FERROR("HardwareStatusThread: pCurGen is NULL");
  2808. return;
  2809. }
  2810. if (pCurGen->m_GenConfig.GetFirstOf("loopTime") >= 0)
  2811. {
  2812. if ((int)pCurGen->m_GenConfig["loopTime"] >= 100)
  2813. {
  2814. pCurGen->m_iLoopTime = (int)pCurGen->m_GenConfig["loopTime"];
  2815. }
  2816. }
  2817. FINFO("loopTime = {$}", pCurGen->m_iLoopTime.load());
  2818. while (pCurGen->m_bExtraFlag)
  2819. {
  2820. int currtTime = pCurGen->m_iLoopTime;
  2821. Sleep(currtTime);
  2822. if (!pCurGen->m_bExtraFlag) break;
  2823. if (pCurGen->m_nProcessXrayon == false)
  2824. {
  2825. pCurGen->RetrieveHU();
  2826. pCurGen->CheckGeneratorStatus();
  2827. FINFO("ConnectStatus: {$}", pCurGen->m_bReconnect);
  2828. if (!pCurGen->m_bSetAPR)
  2829. {
  2830. pCurGen->m_tAPRdata.nWS = pCurGen->m_DoseUnit.m_WS->Get();
  2831. pCurGen->m_tAPRdata.nTechmode = pCurGen->m_DoseUnit.m_Techmode->Get();
  2832. pCurGen->m_tAPRdata.nFocus = pCurGen->m_DoseUnit.m_Focus->Get();
  2833. pCurGen->m_tAPRdata.fKV = pCurGen->m_DoseUnit.m_KV->Get();
  2834. pCurGen->m_tAPRdata.fMA = pCurGen->m_DoseUnit.m_MA->Get();
  2835. pCurGen->m_tAPRdata.fMS = pCurGen->m_DoseUnit.m_MS->Get();
  2836. pCurGen->m_tAPRdata.fMAS = pCurGen->m_DoseUnit.m_MAS->Get();
  2837. pCurGen->m_tAPRdata.nAECDensity = pCurGen->m_DoseUnit.m_AECDensity->Get();
  2838. pCurGen->m_tAPRdata.nAECFilm = pCurGen->m_DoseUnit.m_AECFilm->Get();
  2839. pCurGen->m_tAPRdata.nAECField = pCurGen->m_DoseUnit.m_AECField->Get();
  2840. pCurGen->SetAPR(pCurGen->m_tAPRdata);
  2841. }
  2842. m_nCountTimes++;
  2843. if (m_nCountTimes >= 25)
  2844. {
  2845. char ErrCode[20];
  2846. snprintf(ErrCode, sizeof(ErrCode), "DELTA_ERR_%04d", 0);
  2847. FINFO("{$}", ErrCode);
  2848. int level = DELTA_ABNORMAL_LEVEL::REG_ERRO;
  2849. auto iterr = pCurGen->m_ErrorMessages.find(ErrCode);
  2850. if (iterr != pCurGen->m_ErrorMessages.end())
  2851. {
  2852. pCurGen->m_bReconnect = true;
  2853. pCurGen->m_MSGUnit->AddErrorMessage(ErrCode, level, iterr->second.c_str());
  2854. FERROR("Critical error detected, exiting...");
  2855. // Note: 不建议在库代码中调用exit(),改为设置错误状态
  2856. // exit(0);
  2857. }
  2858. }
  2859. }
  2860. }
  2861. FINFO("HardwareStatusThread exiting...");
  2862. }
  2863. void CCOS::Dev::Detail::Generator::DeltaDevice::RetrieveHU()
  2864. {
  2865. if (!m_nProcessXrayon)
  2866. {
  2867. FINFO("[0xF0, 0x5F, 0x01]");
  2868. char cmdbuf[13] = { 0xF0, 0x5F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x25, 0x00, 0x88 };
  2869. FormatCommand(cmdbuf, 13);
  2870. string temp(cmdbuf, 13);
  2871. m_strCommand = temp;
  2872. HWSend(m_strCommand.c_str(), m_strCommand.length());
  2873. }
  2874. else
  2875. {
  2876. FINFO("Xrayon Processing Dont RetrieveHU");
  2877. }
  2878. }
  2879. void CCOS::Dev::Detail::Generator::DeltaDevice::CheckGeneratorStatus()
  2880. {
  2881. if (!m_nProcessXrayon)
  2882. {
  2883. FINFO("[0xF0, 0x64, 0x01]");
  2884. char cmdbuf[19] = { 0xF0, 0x64, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x88 };
  2885. FormatCommand(cmdbuf, 19);
  2886. string temp(cmdbuf, 19);
  2887. m_strCommand = temp;
  2888. HWSend(m_strCommand.c_str(), m_strCommand.length());
  2889. }
  2890. else
  2891. {
  2892. FINFO("Xrayon Processing Dont CheckGeneratorStatus");
  2893. }
  2894. }
  2895. void CCOS::Dev::Detail::Generator::DeltaDevice::RetrieveMaxRating()
  2896. {
  2897. //6104
  2898. FINFO("[0xF0, 0x61, 0x04]");
  2899. char cmdbuf[19] = { 0xF0, 0x61, 0x04, 0x00, 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00, 0x00, 0x00, 0x00, 0x88 };
  2900. FormatCommand(cmdbuf, 19);
  2901. string temp(cmdbuf, 19);
  2902. m_strCommand = temp;
  2903. HWSend(m_strCommand.c_str(), m_strCommand.length());
  2904. }
  2905. void CCOS::Dev::Detail::Generator::DeltaDevice::UpdataAECInformation(AECINFORM aec)
  2906. {
  2907. switch (aec.Field)
  2908. {
  2909. case 1:
  2910. m_DoseUnit.m_AECField->Update(AttrKey::AEC_100);
  2911. break;
  2912. case 2:
  2913. m_DoseUnit.m_AECField->Update(AttrKey::AEC_010);
  2914. break;
  2915. case 3:
  2916. m_DoseUnit.m_AECField->Update(AttrKey::AEC_110);
  2917. break;
  2918. case 4:
  2919. m_DoseUnit.m_AECField->Update(AttrKey::AEC_001);
  2920. break;
  2921. case 5:
  2922. m_DoseUnit.m_AECField->Update(AttrKey::AEC_101);
  2923. break;
  2924. case 6:
  2925. m_DoseUnit.m_AECField->Update(AttrKey::AEC_010);
  2926. break;
  2927. case 7:
  2928. m_DoseUnit.m_AECField->Update(AttrKey::AEC_111);
  2929. break;
  2930. default:
  2931. m_DoseUnit.m_AECField->Update(AttrKey::AEC_010);
  2932. break;
  2933. }
  2934. FireNotify(m_DoseUnit.m_AECField->GetKey(), m_DoseUnit.m_AECField->JSGet());
  2935. FINFO("AEC: field: {$}", m_DoseUnit.m_AECField->GetKey());
  2936. //density
  2937. switch (aec.Density)
  2938. {
  2939. case 0:
  2940. m_DoseUnit.m_AECDensity->Update(-3);
  2941. break;
  2942. case 1:
  2943. m_DoseUnit.m_AECDensity->Update(-2);
  2944. break;
  2945. case 2:
  2946. m_DoseUnit.m_AECDensity->Update(-1);
  2947. break;
  2948. case 3:
  2949. m_DoseUnit.m_AECDensity->Update(0);
  2950. break;
  2951. case 4:
  2952. m_DoseUnit.m_AECDensity->Update(1);
  2953. break;
  2954. case 5:
  2955. m_DoseUnit.m_AECDensity->Update(2);
  2956. break;
  2957. case 6:
  2958. m_DoseUnit.m_AECDensity->Update(3);
  2959. break;
  2960. default:
  2961. m_DoseUnit.m_AECDensity->Update(0);
  2962. break;
  2963. }
  2964. FireNotify(m_DoseUnit.m_AECDensity->GetKey(), m_DoseUnit.m_AECDensity->JSGet());
  2965. FINFO("AEC: Density: {$}", m_DoseUnit.m_AECDensity->GetKey());
  2966. //film --->ysj++ �Ƿ���Ҫת������
  2967. int nAECFilmSpeed = 0;
  2968. switch (aec.FilmScreenSpeed)
  2969. {
  2970. case 0:
  2971. nAECFilmSpeed = 100;
  2972. break;
  2973. case 1:
  2974. nAECFilmSpeed = 200;
  2975. break;
  2976. case 2:
  2977. nAECFilmSpeed = 400;
  2978. break;
  2979. case 3:
  2980. nAECFilmSpeed = 800;
  2981. break;
  2982. default:
  2983. break;
  2984. }
  2985. m_DoseUnit.m_AECFilm->Update(nAECFilmSpeed);
  2986. FireNotify(m_DoseUnit.m_AECFilm->GetKey(), m_DoseUnit.m_AECFilm->JSGet());
  2987. FINFO("AEC: Film: {$}", m_DoseUnit.m_AECFilm->GetKey());
  2988. }
  2989. void CCOS::Dev::Detail::Generator::DeltaDevice::RetrieveGeneratroDerating()
  2990. {
  2991. //6105
  2992. FINFO("[0xF0, 0x61, 0x05]");
  2993. char cmdbuf[19] = { 0xF0, 0x61, 0x05, 0x00, 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00, 0x00, 0x00, 0x00, 0x88 };
  2994. FormatCommand(cmdbuf, 19);
  2995. string temp(cmdbuf, 19);
  2996. m_strCommand = temp;
  2997. HWSend(m_strCommand.c_str(), m_strCommand.length());
  2998. }
  2999. bool CCOS::Dev::Detail::Generator::DeltaDevice::LoadConfig(string configfile)
  3000. {
  3001. std::ifstream file(configfile);
  3002. if (!file) {
  3003. FINFO("Config file does not exist: {$}", configfile.c_str());
  3004. return false;
  3005. }
  3006. if (m_bLoadConfigFile)
  3007. {
  3008. FINFO("Configuration already loaded");
  3009. return true;
  3010. }
  3011. m_strConfigPath = configfile;
  3012. ResDataObject temp;
  3013. temp.loadFile(m_strConfigPath.c_str());
  3014. m_GenConfig = temp["CONFIGURATION"];
  3015. TransJsonText(m_GenConfig);
  3016. GetConfData();
  3017. m_bLoadConfigFile = true;
  3018. return true;
  3019. }
  3020. int CCOS::Dev::Detail::Generator::DeltaDevice::GetGenState()
  3021. {
  3022. if (m_DoseUnit.m_GenState != NULL)
  3023. {
  3024. return m_DoseUnit.m_GenState->Get();
  3025. }
  3026. else
  3027. {
  3028. return 0;
  3029. }
  3030. }
  3031. string CCOS::Dev::Detail::Generator::DeltaDevice::AnalysisCommand(int number, const char* chdigital, int type)
  3032. {
  3033. string str = "";
  3034. char arrChar[BYTE_4] = { 0 };
  3035. for (int i = 0; i < number; i++)
  3036. {
  3037. if (type == TransToType::tochar)
  3038. {
  3039. //转成符号
  3040. snprintf(arrChar, sizeof(arrChar) / sizeof(arrChar[0]), "%c", (BYTE)chdigital[i]);
  3041. }
  3042. else if (type == TransToType::toint)
  3043. {
  3044. //转成int数
  3045. snprintf(arrChar, sizeof(arrChar) / sizeof(arrChar[0]), "%d", (BYTE)chdigital[i]);
  3046. }
  3047. else
  3048. {
  3049. //转成hex
  3050. snprintf(arrChar, sizeof(arrChar) / sizeof(arrChar[0]), "%X", (BYTE)chdigital[i]);
  3051. }
  3052. str += arrChar;
  3053. }
  3054. return str;
  3055. }
  3056. //-----------------------------------------------------------------------------
  3057. // DeltaDriver
  3058. //-----------------------------------------------------------------------------
  3059. nsGEN::DeltaDriver::DeltaDriver()
  3060. {
  3061. m_bDemoConnected = false;
  3062. m_pAttribute.reset(new ResDataObject);
  3063. m_pDescription.reset(new ResDataObject);
  3064. }
  3065. nsGEN::DeltaDriver::~DeltaDriver()
  3066. {
  3067. }
  3068. auto nsGEN::DeltaDriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
  3069. {
  3070. FINFO("CreateDevice:{$}", index);
  3071. try {
  3072. if (!m_scfWrapper) {
  3073. FERROR("SCFWrapper is null, cannot create device");
  3074. return nullptr;
  3075. }
  3076. if (EventCenter == nullptr) {
  3077. FERROR("EventCenter is null, cannot create device");
  3078. return nullptr;
  3079. }
  3080. m_pDevice = new DeltaDevice(EventCenter, m_scfWrapper, m_ConfigFileName);
  3081. if (!m_pDevice) {
  3082. FERROR("Failed to create DeltaDevice instance");
  3083. return nullptr;
  3084. }
  3085. auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDevice));
  3086. if (!dev) {
  3087. FERROR("Failed to create IODevice instance");
  3088. delete m_pDevice;
  3089. m_pDevice = nullptr;
  3090. return nullptr;
  3091. }
  3092. FINFO("Device created successfully");
  3093. return dev;
  3094. }
  3095. catch (const std::bad_alloc& e) {
  3096. FERROR("Memory allocation failed in CreateDevice: {$}", e.what());
  3097. if (m_pDevice) {
  3098. delete m_pDevice;
  3099. m_pDevice = nullptr;
  3100. }
  3101. return nullptr;
  3102. }
  3103. catch (const std::exception& e) {
  3104. FERROR("Exception in CreateDevice: {$}", e.what());
  3105. if (m_pDevice) {
  3106. delete m_pDevice;
  3107. m_pDevice = nullptr;
  3108. }
  3109. return nullptr;
  3110. }
  3111. }
  3112. void nsGEN::DeltaDriver::FireNotify(int code, std::string key, std::string content)
  3113. {
  3114. EventCenter->OnNotify(code, key, content);
  3115. }
  3116. void nsGEN::DeltaDriver::Prepare()
  3117. {
  3118. FINFO("========================================");
  3119. FINFO("DeltaDriver::Prepare() Starting...");
  3120. FINFO("========================================");
  3121. try {
  3122. // 初始化日志系统
  3123. std::string strLogPath = GetProcessDirectory() + R"(/Conf/log_config.xml)";
  3124. std::string LogHost = "DevDelta";
  3125. std::string moduleName = "DevDelta";
  3126. FINFO("Initializing log module...");
  3127. FINFO("Log config path: {$}", strLogPath.c_str());
  3128. FINFO("Log host: {$}", LogHost.c_str());
  3129. FINFO("Module name: {$}", moduleName.c_str());
  3130. bool ret = initLogModule(
  3131. LogHost, // 主机名(用于日志路径中的{host}占位符)
  3132. moduleName, // 唯一模块名
  3133. strLogPath, // 配置文件路径
  3134. true // 是否输出到控制台(可选)
  3135. );
  3136. if (!ret) {
  3137. std::cerr << "Log init failed!" << std::endl;
  3138. FERROR("Failed to initialize log module");
  3139. return;
  3140. }
  3141. FINFO("Log module initialized successfully");
  3142. Delta_SetLocalModuleName(moduleName);
  3143. FINFO("Getting connection DLL from config: {$}", m_ConfigFileName.c_str());
  3144. m_SCFDllName = GetConnectDLL(m_ConfigFileName);
  3145. FINFO("SCF DLL name: {$}", m_SCFDllName.c_str());
  3146. FINFO("Calling parent Prepare()...");
  3147. super::Prepare();
  3148. FINFO("========================================");
  3149. FINFO("DeltaDriver::Prepare() Completed");
  3150. FINFO("========================================");
  3151. }
  3152. catch (const std::exception& e) {
  3153. FERROR("Exception in Prepare: {$}", e.what());
  3154. std::cerr << "Fatal error in Prepare: " << e.what() << std::endl;
  3155. throw; // 重新抛出异常,因为Prepare失败应该阻止程序继续运行
  3156. }
  3157. }
  3158. bool nsGEN::DeltaDriver::Connect()
  3159. {
  3160. FINFO("Enter DeltaDriver::Connect()");
  3161. FINFO("ConfigFileName: {$}", m_ConfigFileName.c_str());
  3162. std::lock_guard<std::mutex> lock(m_connectionMutex);
  3163. const auto currentState = m_connectionState.load();
  3164. auto now = std::chrono::steady_clock::now();
  3165. // 1. 处理可重试的失败状态
  3166. if (currentState == ConnectionState::Failed) {
  3167. if ((now - m_lastConnectionAttempt) >= RETRY_INTERVAL && m_connectionRetryCount < MAX_RETRY_COUNT) {
  3168. m_connectionState = ConnectionState::Disconnected;
  3169. }
  3170. else {
  3171. return false; // 不满足重试条件,直接返回
  3172. }
  3173. }
  3174. // 2. 检查无效状态(正在连接/已连接但实际有效)
  3175. if (currentState == ConnectionState::Connecting) {
  3176. FINFO("Already connecting");
  3177. return true;
  3178. }
  3179. if (currentState == ConnectionState::Connected && m_scfWrapper && m_scfWrapper->IsConnected()) {
  3180. FINFO("Already connected");
  3181. return true;
  3182. }
  3183. // 3. 检查配置文件是否存在
  3184. std::ifstream file(m_ConfigFileName);
  3185. if (!file) {
  3186. FINFO("{$} does not exist", m_ConfigFileName.c_str());
  3187. return false;
  3188. }
  3189. ResDataObject connParam = GetConnectParam(m_ConfigFileName);
  3190. std::string connInfo;
  3191. try {
  3192. // 如果是串口连接,使用当前索引的端口
  3193. if (m_currentConnType == ConnectionType::Serial) {
  3194. std::string currentPort = m_serialPorts[m_currentSerialPortIndex];
  3195. connParam.update("port", currentPort.c_str());
  3196. connInfo = "Serial (port: " + currentPort + ")";
  3197. } else {
  3198. // 网口连接:直接使用配置参数
  3199. connInfo = "Ethernet (ip: " + std::string(connParam["ip"]) + ")";
  3200. }
  3201. FINFO("Enter Connect ({$}), config: {$}", connInfo, connParam.encode());
  3202. m_connectionState = ConnectionState::Connecting;
  3203. m_lastConnectionAttempt = now;
  3204. // 创建SCFWrapper对象(如果尚未创建)
  3205. if (!m_scfWrapper) {
  3206. m_scfWrapper = std::make_shared<SCFWrapper>();
  3207. }
  3208. // 初始化SCF
  3209. if (!m_scfWrapper->Initialize(m_SCFDllName)) {
  3210. FINFO("SCF Init failed: {$}", m_scfWrapper->GetLastError());
  3211. m_connectionState = ConnectionState::Failed;
  3212. // 串口连接失败处理:尝试下一个端口
  3213. if (m_currentConnType == ConnectionType::Serial) {
  3214. int nextIndex = (m_currentSerialPortIndex + 1) % m_serialPorts.size();
  3215. bool allPortsTried = (nextIndex == 0);
  3216. if (!allPortsTried) {
  3217. // 未遍历完所有端口:切换到下一端口,不增加重试计数
  3218. m_currentSerialPortIndex = nextIndex;
  3219. m_connectionRetryCount = 0;
  3220. FINFO("Trying next serial port: {$}", m_serialPorts[nextIndex]);
  3221. return false;
  3222. } else {
  3223. // 已遍历所有端口:重置到第一个端口,增加重试计数
  3224. m_currentSerialPortIndex = 0;
  3225. m_connectionRetryCount++;
  3226. FINFO("All serial ports tried, retry count: {$}/{$}", m_connectionRetryCount, MAX_RETRY_COUNT);
  3227. return false;
  3228. }
  3229. }
  3230. m_connectionRetryCount++;
  3231. return false;
  3232. }
  3233. // 设置数据接收回调
  3234. m_scfWrapper->SetDataReceivedCallback([this](const char* data, uint32_t length) {
  3235. this->Dequeue(data, length);
  3236. });
  3237. // 连接SCF
  3238. auto erCode = m_scfWrapper->Connect(connParam, &nsGEN::DeltaDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
  3239. if (erCode != SCF_SUCCEED || !m_scfWrapper->StartAutoReceive()) {
  3240. FINFO("Connect failed (code: {$}) for {$}", erCode, connInfo);
  3241. m_scfWrapper->Disconnect();
  3242. m_connectionState = ConnectionState::Failed;
  3243. // 串口连接失败处理:尝试下一个端口
  3244. if (m_currentConnType == ConnectionType::Serial) {
  3245. int nextIndex = (m_currentSerialPortIndex + 1) % m_serialPorts.size();
  3246. bool allPortsTried = (nextIndex == 0);
  3247. if (!allPortsTried) {
  3248. // 未遍历完所有端口:切换到下一端口,不增加重试计数
  3249. m_currentSerialPortIndex = nextIndex;
  3250. m_connectionRetryCount = 0;
  3251. FINFO("Trying next serial port: {$}", m_serialPorts[nextIndex]);
  3252. return false;
  3253. } else {
  3254. // 已遍历所有端口:重置到第一个端口,增加重试计数
  3255. m_currentSerialPortIndex = 0;
  3256. m_connectionRetryCount++;
  3257. FINFO("All serial ports tried, retry count: {$}/{$}", m_connectionRetryCount, MAX_RETRY_COUNT);
  3258. return false;
  3259. }
  3260. }
  3261. // 所有端口失败(串口)或网口失败,才增加总重试计数
  3262. m_connectionRetryCount++;
  3263. return false;
  3264. }
  3265. // 连接成功:重置状态
  3266. m_connectionState = ConnectionState::Connected;
  3267. m_connectionRetryCount = 0;
  3268. m_currentSerialPortIndex = 0; // 重置串口端口索引
  3269. FINFO("Connected successfully ({$})", connInfo);
  3270. return true;
  3271. }
  3272. catch (const std::exception& e) {
  3273. FINFO("Connect exception for {$}: {$}", connInfo, e.what());
  3274. m_connectionState = ConnectionState::Failed;
  3275. m_connectionRetryCount++;
  3276. return false;
  3277. }
  3278. }
  3279. void nsGEN::DeltaDriver::Disconnect()
  3280. {
  3281. FINFO("========================================");
  3282. FINFO("DeltaDriver::Disconnect() Entry");
  3283. try {
  3284. if (m_scfWrapper) {
  3285. FINFO("Stopping auto receive...");
  3286. m_scfWrapper->StopAutoReceive();
  3287. FINFO("Auto receive stopped");
  3288. FINFO("Disconnecting SCF wrapper...");
  3289. m_scfWrapper->Disconnect();
  3290. FINFO("SCF wrapper disconnected");
  3291. m_connectionState = ConnectionState::Disconnected;
  3292. FINFO("Connection state set to Disconnected");
  3293. } else {
  3294. FWARN("SCF wrapper is null, nothing to disconnect");
  3295. }
  3296. m_bDemoConnected = false;
  3297. }
  3298. catch (const std::exception& e) {
  3299. FERROR("Exception during disconnect: {$}", e.what());
  3300. // 即使发生异常,也要确保状态被重置
  3301. m_connectionState = ConnectionState::Disconnected;
  3302. m_bDemoConnected = false;
  3303. }
  3304. FINFO("DeltaDriver::Disconnect() Completed");
  3305. FINFO("========================================");
  3306. }
  3307. bool nsGEN::DeltaDriver::isConnected() const
  3308. {
  3309. const auto state = m_connectionState.load();
  3310. // 1. 连接中/实际已连接:返回true(无需重连)
  3311. if (state == ConnectionState::Connecting || (m_scfWrapper && m_scfWrapper->IsConnected())) {
  3312. return true;
  3313. }
  3314. // 2. 失败状态处理:判断是否允许重试
  3315. if (state == ConnectionState::Failed) {
  3316. auto now = std::chrono::steady_clock::now();
  3317. const auto timeSinceLast = now - m_lastConnectionAttempt;
  3318. // 2.1 达到最大重试次数,但超过重置间隔:重置计数,允许重新重试
  3319. if (m_connectionRetryCount >= MAX_RETRY_COUNT && timeSinceLast >= RESET_RETRY_AFTER) {
  3320. FINFO("Max retries reached, resetting count after {$}s",
  3321. std::chrono::duration_cast<std::chrono::seconds>(timeSinceLast).count());
  3322. m_connectionRetryCount = 0; // 重置计数(因mutable修饰,const函数可修改)
  3323. }
  3324. // 2.2 不适合重连(时间未到 或 次数仍超限):返回true阻止重连
  3325. if (timeSinceLast < RETRY_INTERVAL || m_connectionRetryCount >= MAX_RETRY_COUNT) {
  3326. return true;
  3327. }
  3328. }
  3329. // 3. 其他情况:返回false允许重连
  3330. return false;
  3331. }
  3332. std::string nsGEN::DeltaDriver::DriverProbe()
  3333. {
  3334. ResDataObject r_config, HardwareInfo;
  3335. if (r_config.loadFile(m_ConfigFileName.c_str()))
  3336. {
  3337. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  3338. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  3339. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  3340. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  3341. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  3342. }
  3343. else
  3344. {
  3345. HardwareInfo.add("MajorID", "Generator");
  3346. HardwareInfo.add("MinorID", "Dr");
  3347. HardwareInfo.add("VendorID", "Delta");
  3348. HardwareInfo.add("ProductID", "DMG80KAXB");
  3349. HardwareInfo.add("SerialID", "Drv");
  3350. }
  3351. string ret = HardwareInfo.encode();
  3352. return ret;
  3353. }
  3354. std::string nsGEN::DeltaDriver::GetResource()
  3355. {
  3356. ResDataObject r_config, temp;
  3357. if (!temp.loadFile(m_ConfigFileName.c_str()))
  3358. {
  3359. return "";
  3360. }
  3361. m_ConfigAll = temp;
  3362. r_config = temp["CONFIGURATION"];
  3363. m_Configurations = r_config;
  3364. ResDataObject DescriptionTemp;
  3365. ResDataObject DescriptionSend;
  3366. ResDataObject m_DescriptionSend;
  3367. ResDataObject ListTemp;
  3368. string strTemp = ""; //用于读取字符串配置信息
  3369. string strIndex = ""; //用于读取配置信息中的List项
  3370. int nTemp = -1; //用于读取整型配置信息
  3371. char sstream[10] = { 0 }; //用于转换值
  3372. string strValue = ""; //用于存储配置的值
  3373. string strType = ""; //用于存储配置的类型 int/float/string...
  3374. /***
  3375. * 1. 通过循环,将所有配置项写到pDeviceConfig
  3376. * 2. 记录配置项的内部key以及配置类型,类型对应了不同配置文件路径,用于读写真实值
  3377. ***/
  3378. try
  3379. {
  3380. //便利ConfigToolInfo 中 所有的AttributeInfo 属性段
  3381. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  3382. m_pAttribute->clear();
  3383. m_pDescription->clear();
  3384. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  3385. {
  3386. DescriptionTemp.clear();
  3387. DescriptionSend.clear();
  3388. ListTemp.clear();
  3389. //AttributeType
  3390. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Type"];
  3391. DescriptionTemp.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
  3392. DescriptionSend.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
  3393. strType = strTemp; //记录配置项的类型
  3394. //AttributeKey
  3395. //1. 根据AttributeType,内部key和配置路径,拿到当前的真实值
  3396. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  3397. nTemp = (int)m_Configurations["ConfigToolInfo"][nInfoIndex]["PathID"];
  3398. GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue); //得到strValue的值
  3399. //2. 赋值
  3400. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  3401. if ("int" == strType)
  3402. {
  3403. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  3404. }
  3405. else if ("float" == strType)
  3406. {
  3407. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  3408. }
  3409. else //其它先按string类型处理
  3410. {
  3411. (*m_pAttribute).add(strTemp.c_str(), strValue.c_str());
  3412. }
  3413. //AttributeAccess
  3414. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Access"];
  3415. DescriptionTemp.add(ConfKey::CcosAccess, strTemp.c_str());
  3416. DescriptionSend.add(ConfKey::CcosAccess, strTemp.c_str());
  3417. /*
  3418. //AttributeRangeMin
  3419. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMin"];
  3420. if (strTemp != "") //不需要的配置项为空
  3421. {
  3422. DescriptionTemp.add(ConfKey::CcosRangeMin, strTemp.c_str());
  3423. }
  3424. //AttributeRangeMax
  3425. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMax"];
  3426. if (strTemp != "") //不需要的配置项为空
  3427. {
  3428. DescriptionTemp.add(ConfKey::CcosRangeMax, strTemp.c_str());
  3429. }
  3430. */
  3431. //AttributeList
  3432. nTemp = m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListNum"];
  3433. if (nTemp > 0) //ListNum不大于0时说明不需要list配置
  3434. {
  3435. for (int nListIndex = 0; nListIndex < nTemp; nListIndex++)
  3436. {
  3437. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListInfo"][nListIndex];
  3438. auto temKey = std::to_string(nListIndex);
  3439. ListTemp.add(temKey.c_str(), strTemp.c_str());
  3440. }
  3441. DescriptionTemp.add(ConfKey::CcosList, ListTemp);
  3442. DescriptionSend.add(ConfKey::CcosList, ListTemp.encode());
  3443. }
  3444. //AttributeRequired
  3445. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Required"];
  3446. DescriptionTemp.add(ConfKey::CcosRequired, strTemp.c_str());
  3447. DescriptionSend.add(ConfKey::CcosRequired, strTemp.c_str());
  3448. //AttributeDefaultValue
  3449. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["DefaultValue"];
  3450. if (strTemp != "") //不需要的配置项为空
  3451. {
  3452. DescriptionTemp.add(ConfKey::CcosDefaultValue, strTemp.c_str());
  3453. DescriptionSend.add(ConfKey::CcosDefaultValue, strTemp.c_str());
  3454. }
  3455. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  3456. (*m_pDescription).add(strTemp.c_str(), DescriptionTemp);
  3457. m_DescriptionSend.add(strTemp.c_str(), DescriptionSend.encode());
  3458. }
  3459. }
  3460. catch (ResDataObjectExption& e)
  3461. {
  3462. FERROR("Get config error: {$}", e.what());
  3463. return "";
  3464. }
  3465. ResDataObject resDeviceResource;
  3466. resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
  3467. resDeviceResource.add(ConfKey::CcosGeneratorDescription, (*m_pDescription));
  3468. ResDataObject DescriptionTempEx;
  3469. DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
  3470. m_DeviceConfig.clear();
  3471. m_DeviceConfig = DescriptionTempEx;
  3472. FINFO("local ************* get resource over {$}", DescriptionTempEx.encode());
  3473. resDeviceResource.clear();
  3474. resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
  3475. resDeviceResource.add(ConfKey::CcosGeneratorDescription, m_DescriptionSend);
  3476. DescriptionTempEx.clear();
  3477. DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
  3478. m_DeviceConfigSend.clear();
  3479. m_DeviceConfigSend = DescriptionTempEx;
  3480. string res = m_DeviceConfigSend.encode();
  3481. FINFO("get resource over {$}", DescriptionTempEx.encode());
  3482. return res;
  3483. }
  3484. std::string nsGEN::DeltaDriver::DeviceProbe()
  3485. {
  3486. ResDataObject r_config, HardwareInfo;
  3487. if (r_config.loadFile(m_ConfigFileName.c_str()))
  3488. {
  3489. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  3490. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  3491. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  3492. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  3493. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  3494. }
  3495. else
  3496. {
  3497. HardwareInfo.add("MajorID", "Generator");
  3498. HardwareInfo.add("MinorID", "Dr");
  3499. HardwareInfo.add("VendorID", "Delta");
  3500. HardwareInfo.add("ProductID", "DMG80KAXB");
  3501. HardwareInfo.add("SerialID", "Dev");
  3502. }
  3503. string ret = HardwareInfo.encode();
  3504. return ret;
  3505. }
  3506. void nsGEN::DeltaDriver::Dequeue(const char* Packet, DWORD Length)
  3507. {
  3508. DecodeFrame(Packet, Length);
  3509. }
  3510. PACKET_RET nsGEN::DeltaDriver::callbackPackageProcess(const char* RecData, uint32_t nLength, uint32_t& PacketLength)
  3511. {
  3512. // 构建十六进制字符串用于日志输出
  3513. char strSendCommand[10] = { 0 };
  3514. string str = "";
  3515. for (int i = 0; i < nLength; i++)
  3516. {
  3517. snprintf(strSendCommand, sizeof(strSendCommand), "%02X", (BYTE)RecData[i]);
  3518. str += strSendCommand;
  3519. str += ",";
  3520. }
  3521. FINFO("==IN== {$}, nLength: {$}", str, nLength);
  3522. bool bHasHead = false;
  3523. for (uint32_t i = 0; i < nLength; i++)
  3524. {
  3525. //寻找包头
  3526. if ((UINT8)RecData[i] == COMMANDHEAD)
  3527. {
  3528. if ((i != 0) && (bHasHead == false)) //包头之前的数据格式不对,全部扔掉
  3529. {
  3530. PacketLength = i;
  3531. char strtemp[Delta_Com_NormalLen] = { 0 };
  3532. memcpy(strtemp, RecData, PacketLength);
  3533. FERROR("==IN unknown format data ==:{$},UselessDataLength={$},TotalLength={$} \n", strtemp, PacketLength, nLength);
  3534. return PACKET_USELESS;
  3535. }
  3536. else
  3537. {
  3538. bHasHead = true;
  3539. }
  3540. }
  3541. //寻找包尾
  3542. if (((UINT8)RecData[i] == COMMANDEND) && ((nLength - 1) == i))
  3543. {
  3544. if (bHasHead)
  3545. {
  3546. PacketLength = i + 1; //+1 because ETX
  3547. char strtemp[Delta_Com_NormalLen] = { 0 };
  3548. memcpy(strtemp, RecData, PacketLength); //只有ETX+数据,-2 排除 checkSum ETX。
  3549. FINFO("==IN==:[{$}]", strtemp);
  3550. // DeltaDevice::m_tDelivermodule.CheckReceive(strtemp, 2); // 已废弃
  3551. return PACKET_ISPACKET;
  3552. }
  3553. else //有包尾但无包头
  3554. {
  3555. PacketLength = i + 1;
  3556. char strtemp[Delta_Com_NormalLen] = { 0 };
  3557. memcpy(strtemp, RecData, PacketLength);
  3558. return PACKET_USELESS;
  3559. }
  3560. }
  3561. else if (((BYTE)RecData[i] == 0x0D) && (3 == i))
  3562. {
  3563. bHasHead = true;
  3564. PacketLength = i + 1; //+1 because ETX
  3565. char strtemp[Delta_Com_NormalLen] = { 0 };
  3566. memcpy(strtemp, RecData, PacketLength); //只有ETX+数据,-2 排除 checkSum ETX。
  3567. FINFO("==IN==:[{$}]", strtemp);
  3568. // DeltaDevice::m_tDelivermodule.CheckReceive(strtemp, 2); // 已废弃
  3569. return PACKET_ISPACKET;
  3570. }
  3571. }
  3572. if (bHasHead)
  3573. {
  3574. PacketLength = 0;
  3575. }
  3576. return PACKET_NOPACKET;
  3577. }
  3578. bool nsGEN::DeltaDriver::GetDeviceConfig(std::string& Cfg)
  3579. {
  3580. Cfg = m_DeviceConfigSend.encode();
  3581. return true;
  3582. }
  3583. bool nsGEN::DeltaDriver::SetDeviceConfig(std::string Cfg)
  3584. {
  3585. FINFO("--Func-- SetDeviceConfig {$}", Cfg.c_str());
  3586. ResDataObject DeviceConfig;
  3587. DeviceConfig.decode(Cfg.c_str());
  3588. ResDataObject DescriptionTempEx;
  3589. DescriptionTempEx = DeviceConfig["DeviceConfig"]["Attribute"];
  3590. FINFO("Attribute:{$}", DescriptionTempEx.encode());
  3591. bool bSaveFile = false; //true:重新保存配置文件
  3592. string strAccess = "";
  3593. for (int i = 0; i < DescriptionTempEx.size(); i++)
  3594. {
  3595. string strKey = DescriptionTempEx.GetKey(i);
  3596. FINFO("{$}", strKey.c_str());
  3597. try
  3598. {
  3599. if (m_pAttribute->GetFirstOf(strKey.c_str()) >= 0)
  3600. {
  3601. strAccess = (string)(*m_pDescription)[strKey.c_str()]["Access"];
  3602. if ("RW" == strAccess)
  3603. {
  3604. //修改对应配置,在其他单元的配置项要同时调用其修改函数修改真实值
  3605. //1. 修改内存中的值,用于给上层发消息
  3606. (*m_pAttribute)[strKey.c_str()] = DescriptionTempEx[i];
  3607. //2. 拿到Innerkey
  3608. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  3609. FINFO("nConfigInfoCount {$}", nConfigInfoCount);
  3610. string strTemp = ""; //存储AttributeKey
  3611. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  3612. {
  3613. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  3614. if (strTemp == strKey)
  3615. {
  3616. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  3617. break;
  3618. }
  3619. }
  3620. //3. 修改配置文件中的值
  3621. if (SetDeviceConfigValue(m_Configurations, strTemp.c_str(), 1, DescriptionTempEx[i]))
  3622. {
  3623. FINFO("SetDeviceConfigValue over");
  3624. bSaveFile = true;
  3625. }
  3626. }
  3627. else
  3628. {
  3629. FINFO("{$} is not a RW configuration item", strKey.c_str());
  3630. }
  3631. }
  3632. else
  3633. {
  3634. FINFO("without this attribute {$}", strKey.c_str());
  3635. }
  3636. }
  3637. catch (ResDataObjectExption& e)
  3638. {
  3639. FERROR("SetDriverConfig crashed: {$}", e.what());
  3640. return false;
  3641. }
  3642. }
  3643. if (bSaveFile)
  3644. {
  3645. //3. 重新保存配置文件
  3646. SaveConfigFile(true);
  3647. }
  3648. return true;
  3649. }
  3650. bool nsGEN::DeltaDriver::SaveConfigFile(bool bSendNotify)
  3651. {
  3652. m_ConfigAll["CONFIGURATION"] = m_Configurations;
  3653. bool bRt = m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
  3654. FINFO("SaveConfigFile over {$}", bRt);
  3655. return true;
  3656. }
  3657. bool nsGEN::DeltaDriver::GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue)
  3658. {
  3659. strValue = "";
  3660. string strTemp = pInnerKey;
  3661. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  3662. {
  3663. int pos = 0;
  3664. ResDataObject resTemp = config;
  3665. while ((pos = strTemp.find_first_of(',')) != string::npos)
  3666. {
  3667. string Key = strTemp.substr(0, pos);
  3668. string TempValue = resTemp[Key.c_str()].encode();
  3669. resTemp.clear();
  3670. resTemp.decode(TempValue.c_str());
  3671. strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
  3672. }
  3673. if (strTemp != "")
  3674. {
  3675. strValue = (string)resTemp[strTemp.c_str()];
  3676. }
  3677. else
  3678. {
  3679. strValue = (string)resTemp;
  3680. }
  3681. }
  3682. return true;
  3683. }
  3684. bool nsGEN::DeltaDriver::SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue)
  3685. {
  3686. string strTemp = pInnerKey;
  3687. FINFO("Begin to change {$} item value to {$}", pInnerKey, szValue);
  3688. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  3689. {
  3690. try {
  3691. int pos = 0;
  3692. ResDataObject* resTemp = &config;
  3693. while ((pos = strTemp.find_first_of(',')) != string::npos)
  3694. {
  3695. string Key = strTemp.substr(0, pos);
  3696. resTemp = &(*resTemp)[Key.c_str()];
  3697. strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
  3698. }
  3699. if (strTemp != "")
  3700. {
  3701. (*resTemp)[strTemp.c_str()] = szValue;
  3702. }
  3703. else
  3704. {
  3705. *resTemp = szValue;
  3706. }
  3707. }
  3708. catch (ResDataObjectExption& e)
  3709. {
  3710. FERROR("SetDriverConfigvalue crashed: {$}", e.what());
  3711. return false;
  3712. }
  3713. }
  3714. return true;
  3715. }
  3716. //-----------------------------------------------------------------------------
  3717. // GetIODriver & CreateIODriver
  3718. //-----------------------------------------------------------------------------
  3719. static nsGEN::DeltaDriver gIODriver;
  3720. extern "C" CCOS::Dev::IODriver * GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
  3721. {
  3722. return &gIODriver;
  3723. }
  3724. extern "C" CCOS::Dev::IODriver * CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
  3725. {
  3726. return new nsGEN::DeltaDriver();
  3727. }