| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981 |
- // CCOS.Dev.GEN.Delta.cpp : 定义 DLL 应用程序的导出函数。
- //
- #include <assert.h>
- #include <functional>
- #include <fstream>
- #include <unordered_map>
- #include <set>
- #include <dlfcn.h>
- #include "LogicDevice.h"
- #include "CCOS.Dev.Generator.Delta_80KAXB.h"
- #include "Helper.JSON.hpp"
- #include "LogLocalHelper.h"
- #include "Log4CPP.h"
- using namespace std::placeholders;
- using namespace CCOS::Dev::Detail::Generator;
- namespace nsGEN = CCOS::Dev::Detail::Generator;
- static const int msTimeOut_Lock = 500;
- // Linux 环境下的 SCF 库文件名
- static const auto COM_SCFDllName = "libSerialSCF.so";
- static const auto TCP_SCFDllName = "libTcpipSCF.so";
- // 定义 Sleep 宏(如果头文件中没有定义)
- #ifndef Sleep
- #define Sleep(ms) std::this_thread::sleep_for(std::chrono::milliseconds(ms))
- #endif
- #define Delta_Com_NormalLen 20
- #define Delta_LoopDefTime 1500
- #define Delta_LoopExpTime 100
- #define KVP_MAX 150
- #define KVP_MIN 40
- #define WORD_HIGH(a) (a>>4)
- #define WORD_LOW(a) (( a & 0x0F))
- #define COMMANDHEAD 0xF0
- #define COMMANDEND 0x88
- #define HANDSWITCHCOMMAND 0x0D
- #define HANDSWITCHFIRST 0x52
- #define XRAYONCOMMAND 0x58
- #define XRAYOFFCOMMAND 0x4F
- /* Control characters */
- #define STX 0x02 /* Start of DATA */
- #define ETX 0x03 /* End of DATA */
- #define ACK 0x06 /* Acknowlage */
- #define NAK 0x15 /* not acknowlage */
- #define BYTE_1 1
- #define BYTE_2 2
- #define BYTE_4 4
- #define BYTE_6 6
- #define BYTE_10 10
- #define BYTE_12 12
- //-----------------------------------------------------------------------------
- // 计算校验码
- //-----------------------------------------------------------------------------
- UINT8 GetCRC8(char* pBuffer, UINT16 bufSize)
- {
- char High[16] = { 0x00, 0x70, 0xe0, 0x90, 0xc7, 0xb7, 0x27, 0x57, 0x89, 0xf9, 0x69, 0x19, 0x4e, 0x3e, 0xae, 0xde };
- char Low[16] = { 0x00, 0x07, 0x0e, 0x09, 0x1c, 0x1b, 0x12, 0x15, 0x38, 0x3f, 0x36, 0x31, 0x24, 0x23, 0x2a, 0x2d };
- UINT8 crc = 0;
- if (bufSize <= 0)
- return crc;
- for (int i = 0; i < bufSize; i++)
- {
- UINT8 result = (crc ^ pBuffer[i]);
- UINT8 high = WORD_HIGH(result);
- UINT8 low = WORD_LOW(result);
- crc = High[high] ^ Low[low];
- }
- return crc;
- }
- //-----------------------------------------------------------------------------
- // DeltaDevice
- //-----------------------------------------------------------------------------
- // 注释:DeliverModule已废弃,Linux下不再使用
- // nsSerialGPM::CDeliverModule nsGEN::DeltaDevice::m_tDelivermodule;
- nsGEN::DeltaDevice* nsGEN::DeltaDevice::g_GenDevice = NULL;
- atomic<int> nsGEN::DeltaDevice::m_iLoopTime = Delta_LoopDefTime;
- atomic<bool> nsGEN::DeltaDevice::m_bExtraFlag = false;
- nsGEN::DeltaDevice::DeltaDevice(std::shared_ptr <IOEventCenter> center, std::shared_ptr<SCFWrapper> SCF, string configfile)
- : super(center)
- , superGen()
- , m_SCF(SCF)
- {
- FINFO("========================================");
- FINFO("DeltaDevice Constructor Starting...");
- FINFO("Version: 0.0.1");
- FINFO("Config file: {$}", configfile.c_str());
- FINFO("========================================");
- assert(EventCenter);
- g_GenDevice = this;
- //初始化参数
- m_DoseUnit.m_KV.reset(new KVMould(70.0, 40.0, 150.0, 1.0));
- m_DoseUnit.m_MA.reset(new MAMould(20.0, 10.0, 1000.0, 1.0));
- m_DoseUnit.m_MS.reset(new MSMould(20.0, 1.0, 63000.0, 1.0));
- m_DoseUnit.m_MAS.reset(new MASMould(0.4, 0.4, 10000.0, 1.0));
- m_DoseUnit.m_Techmode.reset(new TECHMODEMould(AttrKey::TECHMODE_NOAEC_3P, AttrKey::TECHMODE_NOAEC_3P, AttrKey::TECHMODE_MAX, 1));
- m_DoseUnit.m_WS.reset(new WORKSTATIONMould(AttrKey::TABLE, AttrKey::TABLE, AttrKey::GENWS_MAX, 1));
- m_DoseUnit.m_Focus.reset(new FOCUSMould(AttrKey::FOCUS_LARGE, AttrKey::FOCUS_SMALL, AttrKey::FOCUS_LARGE, 1));
- m_DoseUnit.m_AECField.reset(new AECFIELDMould(0, 0, 111, 1));
- m_DoseUnit.m_AECFilm.reset(new AECFILMMould(0, 0, 3, 1));
- m_DoseUnit.m_AECDensity.reset(new AECDENSITYMould(0, -4, 4, 1));
- m_DoseUnit.m_HE.reset(new TUBEHEATMould(0, 0, 100, 1));
- m_DoseUnit.m_PostKV.reset(new POSTKVMould(40.0, 40.0, 150.0, 1.0));
- m_DoseUnit.m_PostMA.reset(new POSTMAMould(10.0, 10.0, 1000.0, 1.0));
- m_DoseUnit.m_PostMS.reset(new POSTMSMould(1.0, 1.0, 63000.0, 1.0));
- m_DoseUnit.m_PostMAS.reset(new POSTMASMould(0.4, 0.4, 10000.0, 1.0));
- m_DoseUnit.m_GenSynState.reset(new GENSYNSTATEMould(AttrKey::GENERATOR_RAD_OFF, AttrKey::GENERATOR_SYNC_ERR, AttrKey::GENERATOR_SYNC_MAX, 1));
- m_DoseUnit.m_GenState.reset(new GENSTATEMould(AttrKey::GENERATOR_STATUS_INIT, AttrKey::GENERATOR_STATUS_SHUTDOWN, AttrKey::GENERATOR_STATUS_MAX, 1));
- m_DoseUnit.m_GenTotalExpNumber.reset(new TOTALEXPNUMMould(0, 0, 9999, 1));
- m_DoseUnit.m_GenTotalAcqTimes.reset(new TOTALACQTIMESMould(0, 0, 9999, 1));
- m_DoseUnit.m_GenTubeCoolWaitTimes.reset(new TUBECOOLTIMEMould(0, 0, 9999, 1));
- m_DoseUnit.m_GenTubeOverLoadNumber.reset(new TUBEOVERLOADNUMMould(0, 0, 9999, 1));
- m_DoseUnit.m_GenCurrentExpNumber.reset(new CUREXPNUMMould(0, 0, 9999, 1));
- m_DoseUnit.m_ExpMode.reset(new EXPMODEMould(AttrKey::EXPMODE_TYPE::Single));
- m_DoseUnit.m_FrameRate.reset(new FRAMERATEMould(0, 0, 30, 1));
- m_DoseUnit.m_FLMode.reset(new FLUModeMould(AttrKey::GENERATOR_FLUMode::GENERATOR_FLMODE_NOTFLU));
- m_DAP.reset(new DevDAP::DOSEMould(0.0, 0.0, 1000.0, 0.01));
- m_MSGUnit.reset(new nsDetail::MSGUnit(center, nsGEN::GeneratorUnitType));
- FINFO("Dose unit moulds initialized successfully");
- m_bExtraFlag = true; // 启用硬件状态查询线程
- m_strConfigPath = configfile;
- FINFO("Loading configuration from file: {$}", configfile.c_str());
- bool loadResult = LoadConfig(configfile);
- if (!loadResult) {
- FERROR("Failed to load configuration file");
- } else {
- FINFO("Configuration loaded successfully");
- }
- FINFO("Registering device interfaces...");
- Register();
- FINFO("Device interfaces registered");
- // 注释:DeliverModule已废弃,Linux下不再使用
- //使用drivermodule类,处理ack命令
- // FINFO("Initializing deliver module...");
- // m_tDelivermodule.InitSendModle(this, &ProcessClientData, WriteLog);
- // m_nCMDType_ACK = m_tDelivermodule.SetPriority(false, true);
- // m_nCMDType_WaitTime = m_tDelivermodule.SetPriority(true, false, false, true, 100);
- // m_nCMDType_WaitACK = m_tDelivermodule.SetPriority(true, false, 0, false, 0, false, 0, true, 100);
- // m_nCMDType_WaitSELF = m_tDelivermodule.SetPriority(true, false, 3, false, 0, true, 1000);
- // char ackCMD[3] = {ACK ,ETX ,0};
- // m_tDelivermodule.SetACKCMDHead(ackCMD,2);
- // FINFO("Deliver module initialized");
- m_nCountTimes = 0;
- FINFO("Retrieving firmware version...");
- RetrieveFirewareVersion();
- //警告,错误信息
- m_ErrorMessages = {
- {"DELTA_ERR_0000", "LOST CONNECT"},
- {"DELTA_ERR_0001", "PC Invalid Command"},
- {"DELTA_ERR_0002", "Door Interlock"},
- {"DELTA_ERR_0003", "Interlock"},
- {"DELTA_ERR_0004", "Prep Timeout"},
- {"DELTA_ERR_0005", "Ready Timeout"},
- {"DELTA_ERR_0006", "Filament Timeout"},
- {"DELTA_ERR_0007", "No Library Data"},
- {"DELTA_ERR_0008", "No Calibration Data"},
- {"DELTA_ERR_0009", "SW Configuration File Empty"},
- {"DELTA_ERR_0010", "Calibration Manually Terminated"},
- {"DELTA_ERR_0011", "Manually Terminate Exposure"},
- {"DELTA_ERR_0012", "PREP Manually Terminate"},
- {"DELTA_ERR_0013", "Seasoning Manually Terminated"},
- {"DELTA_ERR_0014", "AC Voltage UVP"},
- {"DELTA_ERR_0015", "Bucky ready open"},
- {"DELTA_ERR_0017", "Not get AEC Ramp"},
- {"DELTA_ERR_0018", "AEC calibration over range"},
- {"DELTA_ERR_0019", "AEC exposure time out"},
- {"DELTA_ERR_0020", "Snap over power rating"},
- {"DELTA_ERR_1001", "SW OTP"},
- {"DELTA_ERR_1002", "Thermal Switch"},
- {"DELTA_ERR_1003", "XRAY Over HU"},
- {"DELTA_ERR_1004", "Aux Power Off"},
- {"DELTA_ERR_1005", "DR reset fail"},
- {"DELTA_ERR_1006", "DR ready fail"},
- {"DELTA_ERR_1007", "Battery communication loss"},
- {"DELTA_ERR_1008", "DAP communication loss"},
- {"DELTA_ERR_1009", "Fluoroscopic time out"},
- {"DELTA_ERR_1010", "DAP device error"},
- {"DELTA_ERR_1011", "Snap over time"},
- {"DELTA_ERR_2001", "SW Vout OVP"},
- {"DELTA_ERR_2002", "SW Vout UVP"},
- {"DELTA_ERR_2003", "SW Anode OCP"},
- {"DELTA_ERR_2004", "SW Anode UCP"},
- {"DELTA_ERR_2005", "Input Voltage OVP" },
- {"DELTA_ERR_2006", "Input Voltage UVP" },
- {"DELTA_ERR_2007", "24 VDC UVP" },
- {"DELTA_ERR_2008", "HW Vout OVP"},
- {"DELTA_ERR_2009", "Capacitive Protection"},
- {"DELTA_ERR_2010", "Primary OCP"},
- {"DELTA_ERR_2011", "HW Cathode OCP"},
- {"DELTA_ERR_2012", "HW Anode OCP"},
- {"DELTA_ERR_2013", "Charger OTP" },
- {"DELTA_ERR_2014", "PFC BUS UVP" },
- {"DELTA_ERR_2015", "Flow fault"},
- {"DELTA_ERR_2016", "PFC start fail"},
- {"DELTA_ERR_3001", "SW Thermal sense fault"},
- {"DELTA_ERR_3002", "Fan 1 Fault"},
- {"DELTA_ERR_3003", "Fan 2 Fault"},
- {"DELTA_ERR_3004", "Filament Power Fault"},
- {"DELTA_ERR_3005", "Soft Start Fail"},
- {"DELTA_ERR_3006", "MA Test Point Open"},
- {"DELTA_ERR_3007", "Tank Connect" },
- {"DELTA_ERR_3008", "Self-Test FERROR"},
- {"DELTA_ERR_3009", "Motor Short"},
- {"DELTA_ERR_3010", "Motor Invalid command"},
- {"DELTA_ERR_3011", "Motor OCP1"},
- {"DELTA_ERR_3012", "Motor OCP2"},
- {"DELTA_ERR_3013", "Motor Communication Loss"},
- {"DELTA_ERR_3014", "Motor Main Open"},
- {"DELTA_ERR_3015", "Motor Shift Open"},
- {"DELTA_ERR_3016", "Charger Fail"},
- {"DELTA_ERR_3017", "Bus UVP"},
- {"DELTA_ERR_3018", "Battery UVP"},
- {"DELTA_ERR_3019", "Cart UVP"},
- {"DELTA_ERR_3020", "Inverter error"},
- {"DELTA_ERR_3021", "Discharge Relay Fail" },
- {"DELTA_ERR_3022", "Battery OVP"},
- {"DELTA_ERR_3023", "Battery OCP" },
- {"DELTA_ERR_3024", "Battery OTP" },
- {"DELTA_ERR_3025", "Battery Fail"},
- {"DELTA_ERR_3026", "APS1 Fail"},
- {"DELTA_ERR_3027", "APS2 Fail"},
- {"DELTA_ERR_3028", "APS3 Fail"},
- {"DELTA_ERR_3029", "Capacitator error" },
- {"DELTA_ERR_3030", "Fan 3 Fault"},
- {"DELTA_ERR_3031", "Fan 4 Fault"},
- {"DELTA_ERR_3032", "PFC OTP and Brown out"},
- {"DELTA_ERR_4001", "SW Current Unbalance"},
- {"DELTA_ERR_4002", "SW Filament OCP"},
- {"DELTA_ERR_4003", "Shoot Inv1"},
- {"DELTA_ERR_4004", "Shoot Inv2"},
- {"DELTA_ERR_4005", "HW Filament Rms"},
- {"DELTA_ERR_4006", "FERROR Repeat 5 Times"},
- };
- m_WarnMessages = {
- {"DELTA_WARN_001", "mode inhibited"},
- {"DELTA_WARN_002", "out of tube rating"},
- {"DELTA_WARN_003", "out of power"},
- {"DELTA_WARN_004", "out of work"},
- {"DELTA_WARN_005", "out of voltage range"},
- {"DELTA_WARN_006", "out of current range"},
- {"DELTA_WARN_007", "out of time or FPS range"},
- {"DELTA_WARN_008", "out of mas range"},
- {"DELTA_WARN_009", "time too small"},
- {"DELTA_WARN_010", "parameter ok"},
- {"DELTA_WARN_011", "mas too small"},
- {"DELTA_WARN_012", "no cmd"},
- {"DELTA_WARN_013", "data not complete(reserved)"},
- {"DELTA_WARN_014", "out of tube HU"},
- {"DELTA_WARN_015", "out of filament current range"},
- {"DELTA_WARN_016", "no library data" },
- {"DELTA_WARN_017", "tube PN not match"},
- {"DELTA_WARN_018", "focal spot not support"},
- {"DELTA_WARN_019", "data break"},
- {"DELTA_WARN_020", "EEPROM BUSY"},
- {"DELTA_WARN_021", "exposure result empty"},
- {"DELTA_WARN_022", "tube calibration data empty" },
- {"DELTA_WARN_023", "XRAY interval time"},
- {"DELTA_WARN_024", "filament current limit"},
- {"DELTA_WARN_025", "out of generator HU"},
- {"DELTA_WARN_026", "out of motor HU"},
- {"DELTA_WARN_160", "invalid cmd"},
- };
- FINFO("Starting hardware status monitoring thread...");
- if (StartHardwareStatusThread()) {
- FINFO("Hardware status thread started successfully");
- } else {
- FERROR("Failed to start hardware status thread");
- }
- FINFO("========================================");
- FINFO("DeltaDevice Constructor Completed");
- FINFO("========================================");
- }
- std::string CCOS::Dev::Detail::Generator::DeltaDevice::GetDynamicLibraryPath()
- {
- // Linux下获取动态库路径
- // 使用this指针地址来获取所属动态库信息
- Dl_info dl_info;
- // 使用对象实例地址而不是成员函数指针
- if (dladdr(reinterpret_cast<void*>(this), &dl_info) == 0) {
- FERROR("Failed to get dynamic library path");
- return "";
- }
- std::string fullPath(dl_info.dli_fname);
- size_t pos = fullPath.find_last_of("/");
- FINFO("FullPath {$}", fullPath);
- if (pos == std::string::npos) {
- return ".";
- }
- return fullPath.substr(0, pos);
- }
- bool CCOS::Dev::Detail::Generator::DeltaDevice::GetConfData()
- {
- //暂时使用上面定义的数组,不用非要读取配置文件。
- int Num;
- if (m_GenConfig.GetKeyCount("RadKV") > 0)
- {
- if (m_GenConfig.GetKeyCount("RadKVSize") > 0)
- {
- Num = (int)m_GenConfig["RadKVSize"];
- for (int i = 0; i < Num; i++)
- {
- int nKV = (int)m_GenConfig["RadKV"][i];
- m_vecKV.push_back(nKV);
- }
- //m_DoseUnit.m_KVList->Update((string)m_GenConfig["RadKV"]);
- //FireNotify(m_DoseUnit.m_KVList->GetKey(), m_DoseUnit.m_KVList->JSGet());
- }
- FINFO("m_vecKV {$}", m_vecKV.size());
- }
- else
- {
- FINFO("no RadKV");
- }
- if (m_GenConfig.GetKeyCount("RadMAS") > 0)
- {
- if (m_GenConfig.GetKeyCount("RadMASSize") > 0)
- {
- Num = (int)m_GenConfig["RadMASSize"];
- for (int i = 0; i < Num; i++)
- {
- float fMAS = m_GenConfig["RadMAS"][i];
- m_vecMAS.push_back(fMAS);
- }
- //m_DoseUnit.m_mAsList->Update((string)m_GenConfig["RadMAS"]);
- //FireNotify(m_DoseUnit.m_mAsList->GetKey(), m_DoseUnit.m_mAsList->JSGet());
- }
- FINFO("m_vecMAS {$}", m_vecMAS.size());
- }
- else
- {
- FINFO("no RadMAS");
- }
- if (m_GenConfig.GetKeyCount("RadMA") > 0)
- {
- if (m_GenConfig.GetKeyCount("RadMASize") > 0)
- {
- Num = (int)m_GenConfig["RadMASize"];
- for (int i = 0; i < Num; i++)
- {
- float fMA = m_GenConfig["RadMA"][i];
- m_vecMA.push_back(fMA);
- }
- //m_DoseUnit.m_MAList->Update((string)m_GenConfig["RadMA"]);
- //FireNotify(m_DoseUnit.m_MAList->GetKey(), m_DoseUnit.m_MAList->JSGet());
- }
- FINFO("m_vecMA {$}", m_vecMA.size());
- }
- else
- {
- FINFO("no RadMA");
- }
- if (m_GenConfig.GetKeyCount("RadMS") > 0)
- {
- if (m_GenConfig.GetKeyCount("RadMSSize") > 0)
- {
- Num = (int)m_GenConfig["RadMSSize"];
- for (int i = 0; i < Num; i++)
- {
- float fMS = m_GenConfig["RadMS"][i];
- m_vecMS.push_back(fMS);
- }
- //m_DoseUnit.m_MSList->Update((string)m_GenConfig["RadMS"]);
- //FireNotify(m_DoseUnit.m_MSList->GetKey(), m_DoseUnit.m_MSList->JSGet());
- }
- FINFO("m_vecMS {$}", m_vecMS.size());
- }
- else
- {
- FINFO("no RadMS");
- }
- if (m_GenConfig.GetKeyCount("TableDAEC") > 0)
- {
- m_nTableUsePanelAEC = (int)(m_GenConfig["TableDAEC"]);
- FINFO("TableDAEC {$}", m_nTableUsePanelAEC);
- }
- else
- {
- FINFO("TableDAEC disable");
- }
- if (m_GenConfig.GetKeyCount("FreeDAEC") > 0)
- {
- m_nFreeUsePanelAEC = (int)(m_GenConfig["FreeDAEC"]);
- FINFO("FreeDAEC {$}", m_nFreeUsePanelAEC);
- }
- else
- {
- FINFO("FreeDAEC disable");
- }
- if (m_GenConfig.GetKeyCount("WallDAEC") > 0)
- {
- m_nWallUsePanelAEC = (int)(m_GenConfig["WallDAEC"]);
- FINFO("WallDAEC {$}", m_nWallUsePanelAEC);
- }
- else
- {
- FINFO("WallDAEC disable");
- }
- if (m_GenConfig.GetKeyCount("TableDDR") > 0)
- {
- m_nTableUsePanelDDR = (int)(m_GenConfig["TableDDR"]);
- FINFO("TableDDR {$}", m_nTableUsePanelDDR);
- }
- else
- {
- FINFO("TableDDR disable");
- }
- if (m_GenConfig.GetKeyCount("WallDDR") > 0)
- {
- m_nWallUsePanelDDR = (int)(m_GenConfig["WallDDR"]);
- FINFO("WallDDR {$}", m_nWallUsePanelDDR);
- }
- else
- {
- FINFO("WallDDR disable");
- }
- if (m_GenConfig.GetKeyCount("FreeDDR") > 0)
- {
- m_nFreeUsePanelDDR = (int)(m_GenConfig["FreeDDR"]);
- FINFO("FreeDDR {$}", m_nFreeUsePanelDDR);
- }
- else
- {
- FINFO("FreeDDR disable");
- }
- if (m_GenConfig.GetKeyCount("SendXwindowToDetector") > 0)
- {
- m_bSendXwindowToDector = ((int)m_GenConfig["SendXwindowToDetector"] > 1) ? true : false;
- FINFO("SendXwindowToDetector {$}", m_bSendXwindowToDector);
- }
- if (m_GenConfig.GetKeyCount("DEframeRate") > 0)
- {
- m_nDEFrameRate = (int)m_GenConfig["DEframeRate"];
- }
- FINFO("DEframeRate {$}", m_nDEFrameRate);
- return false;
- }
- nsGEN::DeltaDevice::~DeltaDevice()
- {
- FINFO("========================================");
- FINFO("DeltaDevice Destructor Starting...");
- FINFO("========================================");
- FINFO("Stopping hardware status thread...");
- m_bExtraFlag = false;
- if (m_pHardwareStatusThread.joinable()) {
- FINFO("Waiting for hardware status thread to join...");
- m_pHardwareStatusThread.join();
- FINFO("Hardware status thread joined successfully");
- } else {
- FINFO("Hardware status thread not joinable, skipping join");
- }
- g_GenDevice = nullptr;
- if (m_pDetectorClient)
- {
- if (!m_pDetectorClient->IsClosed())
- {
- m_pDetectorClient->Close();
- }
- delete m_pDetectorClient;
- m_pDetectorClient = NULL;
- }
- FINFO("========================================");
- FINFO("DeltaDevice Destructor Completed");
- FINFO("========================================");
- }
- std::string nsGEN::DeltaDevice::GetGUID() const
- {
- FINFO("\n===============GetGUID : {$} ===================\n", GeneratorUnitType);
- return GeneratorUnitType;
- }
- void nsGEN::DeltaDevice::Register()
- {
- auto Disp = m_Dispatch.Lock().As();
- superGen::Register(Disp);
- superGen::RegisterRAD(Disp);
- superGen::RegisterAEC(Disp);
- superGen::RegisterExpEnable(Disp);
- superGen::RegisterGeneratortoSyncStatus(Disp);
- Disp->Get.Push(m_MSGUnit->GetKey().c_str(), [this](std::string& out) { out = m_MSGUnit->JSGet(); return RET_STATUS::RET_SUCCEED; });
- }
- RET_STATUS nsGEN::DeltaDevice::IncKV()
- {
- if (!m_DoseUnit.m_KV->CanInc()) return RET_STATUS::RET_SUCCEED;
- m_DoseUnit.m_KV->Inc();
- SetKV(m_DoseUnit.m_KV->Get());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::DecKV()
- {
- if (!m_DoseUnit.m_KV->CanDec()) return RET_STATUS::RET_SUCCEED;
- m_DoseUnit.m_KV->Dec();
- SetKV(m_DoseUnit.m_KV->Get());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetKV(float value)
- {
- if (!m_DoseUnit.m_KV->Verify(value)) return RET_STATUS::RET_SUCCEED;
- FINFO("KV: {$}", value);
- ChangeGenParam((int)value, m_DoseUnit.m_MA->Get(), m_DoseUnit.m_MS->Get(), m_DoseUnit.m_MAS->Get());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::IncMA()
- {
- if (!m_DoseUnit.m_MA->CanInc()) return RET_STATUS::RET_SUCCEED;
- float fMA = m_DoseUnit.m_MA->Get();
- int pos = GetFacFloatValue(m_vecMA, fMA);
- FINFO("Current ma: {$}, pos: {$}", fMA, pos);
- pos++;
- if (pos >= 0 && pos < m_vecMA.size())
- {
- if (m_vecMAS[pos] == (m_nTubeMaBFMinValue * 100))
- {
- SetFocus(AttrKey::FOCUS_LARGE);
- }
- fMA = m_vecMA[pos];
- FINFO("Inc to MA: {$}", fMA);
- ChangeGenParam(m_DoseUnit.m_KV->Get(), fMA, m_DoseUnit.m_MS->Get(), m_DoseUnit.m_MAS->Get());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::DecMA()
- {
- if (!m_DoseUnit.m_MA->CanDec()) return RET_STATUS::RET_SUCCEED;
- float fMA = m_DoseUnit.m_MA->Get();
- int pos = GetFacFloatValue(m_vecMA, fMA);
- FINFO("Current ma: {$}, pos: {$}", fMA, pos);
- pos--;
- if (pos >= 0 && pos < m_vecMA.size())
- {
- if (m_vecMA[pos] == (m_nTubeMaSFMaxValue * 100)) //small focus max value
- {
- SetFocus(AttrKey::FOCUS_TYPE::FOCUS_SMALL);//设置为小焦点
- }
- fMA = m_vecMA[pos];
- FINFO("Dec to MA: {$}", fMA);
- ChangeGenParam(m_DoseUnit.m_KV->Get(), fMA, m_DoseUnit.m_MS->Get(), m_DoseUnit.m_MAS->Get());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetMA(float value)
- {
- if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
- FINFO("MA: {$}", value);
- ChangeGenParam(m_DoseUnit.m_KV->Get(), value, m_DoseUnit.m_MS->Get(), m_DoseUnit.m_MAS->Get());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::IncMS()
- {
- if (!m_DoseUnit.m_MS->CanInc()) return RET_STATUS::RET_SUCCEED;
- float fMS = m_DoseUnit.m_MS->Get();
- int pos = GetFacFloatValue(m_vecMS, fMS);
- FINFO("Current ms: {$}, pos: {$}", fMS, pos);
- pos++;
- if (pos >= 0 && pos < m_vecMS.size())
- {
- fMS = m_vecMS[pos];
- FINFO("Inc to MS: {$}", fMS);
- ChangeGenParam(m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MA->Get(), fMS, m_DoseUnit.m_MAS->Get());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::DecMS()
- {
- if (!m_DoseUnit.m_MS->CanDec()) return RET_STATUS::RET_SUCCEED;
- float fMS = m_DoseUnit.m_MS->Get();
- int pos = GetFacFloatValue(m_vecMS, fMS);
- FINFO("Current ms: {$}, pos: {$}", fMS, pos);
- pos--;
- if (pos >= 0 && pos < m_vecMS.size())
- {
- float fms = m_vecMS[pos];
- FINFO("Dec to MS: {$}", fms);
- ChangeGenParam(m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MA->Get(), fms, m_DoseUnit.m_MAS->Get());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetMS(float value)
- {
- if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
- FINFO("MS: {$}", value);
- ChangeGenParam(m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MA->Get(), value, m_DoseUnit.m_MAS->Get());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::IncMAS()
- {
- if (!m_DoseUnit.m_MAS->CanInc()) return RET_STATUS::RET_SUCCEED;
- float fMAS = m_DoseUnit.m_MAS->Get();
- int pos = GetFacFloatValue(m_vecMAS, fMAS);
- FINFO("Current mas: {$}, pos: {$}", fMAS, pos);
- pos++;
- if (pos >= 0 && pos < m_vecMAS.size())
- {
- fMAS = m_vecMAS[pos];
- FINFO("Inc to MAS: {$}", fMAS);
- ChangeGenParam(m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MA->Get(), m_DoseUnit.m_MS->Get(), fMAS);
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::DecMAS()
- {
- if (!m_DoseUnit.m_MAS->CanDec()) return RET_STATUS::RET_SUCCEED;
- float fMAS = m_DoseUnit.m_MAS->Get();
- int pos = GetFacFloatValue(m_vecMAS, fMAS);
- FINFO("Current mas: {$}, pos: {$}", fMAS, pos);
- pos--;
- if (pos >= 0 && pos < m_vecMAS.size())
- {
- fMAS = m_vecMAS[pos];
- FINFO("Dec to MAS: {$}", fMAS);
- ChangeGenParam(m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MA->Get(), m_DoseUnit.m_MS->Get(), fMAS);
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetMAS(float value)
- {
- if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
- FINFO("MAS: {$}", value);
- ChangeGenParam(m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MA->Get(), m_DoseUnit.m_MS->Get(), value);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetTechmode(int value)
- {
- //0 MS 1 MAS 2 AEC
- //if (!m_DoseUnit.m_Techmode->Verify(value)) return RET_STATUS::RET_SUCCEED;
- FINFO("[0xF0, 0x51, 0xA1, 0x0{$}]", value);
- char cmdbuf[20] = { 0xF0, 0x51, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7A, 0x00, 0x88 };
- m_DoseUnit.m_Techmode->Update(value);
- if (value == 0)
- {
- SetDAECEnable(0);//禁用DAEC
- cmdbuf[3] = 2;
- }
- else if (value == 1)
- {
- SetDAECEnable(0);//禁用DAEC
- cmdbuf[3] = 3;
- }
- else if (value == 2)
- {
- if (m_DoseUnit.m_WS->Get() == AttrKey::TABLE)
- {
- if (m_nTableUsePanelAEC == 1)
- {
- SetDAECEnable(1);
- cmdbuf[3] = 2;//time
- }
- else
- {
- SetDAECEnable(0);
- cmdbuf[3] = 1;//应用GEN的aec功能
- cmdbuf[4] = m_nChamberIndex;//chabmer index
- int nAECFieldSel = 2;
- switch (m_DoseUnit.m_AECField->Get())
- {
- case 100:
- nAECFieldSel = 1;
- break;
- case 10:
- nAECFieldSel = 2;
- break;
- case 110:
- nAECFieldSel = 3;
- break;
- case 1:
- nAECFieldSel = 4;
- break;
- case 101:
- nAECFieldSel = 5;
- break;
- case 11:
- nAECFieldSel = 6;
- break;
- case 111:
- nAECFieldSel = 7;
- break;
- default:
- nAECFieldSel = 2;
- break;
- }
- cmdbuf[5] = nAECFieldSel;//field
- cmdbuf[6] = 0;
- cmdbuf[7] = 0;
- SetAECInformation(m_nChamberIndex, m_DoseUnit.m_AECField->Get(), m_DoseUnit.m_AECDensity->Get(), m_DoseUnit.m_AECFilm->Get());
- }
- }
- else if (m_DoseUnit.m_WS->Get() == AttrKey::WALL)
- {
- if (m_nWallUsePanelAEC == 1)
- {
- SetDAECEnable(1);
- cmdbuf[3] = 2;//time
- }
- else
- {
- SetDAECEnable(0);
- cmdbuf[3] = 1;//应用GEN的aec功能
- cmdbuf[4] = m_nChamberIndex;//chabmer index
- int nAECFieldSel = 2;
- switch (m_DoseUnit.m_AECField->Get())
- {
- case 100:
- nAECFieldSel = 1;
- break;
- case 10:
- nAECFieldSel = 2;
- break;
- case 110:
- nAECFieldSel = 3;
- break;
- case 1:
- nAECFieldSel = 4;
- break;
- case 101:
- nAECFieldSel = 5;
- break;
- case 11:
- nAECFieldSel = 6;
- break;
- case 111:
- nAECFieldSel = 7;
- break;
- default:
- nAECFieldSel = 2;
- break;
- }
- cmdbuf[5] = nAECFieldSel;//field
- cmdbuf[6] = 0;
- cmdbuf[7] = 0;
- }
- }
- else if (m_DoseUnit.m_WS->Get() == AttrKey::MOBILE)
- {
- if (m_nFreeUsePanelAEC == 1)
- {
- SetDAECEnable(1);
- cmdbuf[3] = 2;//time
- }
- else
- {
- SetDAECEnable(0);
- cmdbuf[3] = 1;//应用GEN的aec功能
- cmdbuf[4] = m_nChamberIndex;//chabmer index
- int nAECFieldSel = 2;
- switch (m_DoseUnit.m_AECField->Get())
- {
- case 100:
- nAECFieldSel = 1;
- break;
- case 10:
- nAECFieldSel = 2;
- break;
- case 110:
- nAECFieldSel = 3;
- break;
- case 1:
- nAECFieldSel = 4;
- break;
- case 101:
- nAECFieldSel = 5;
- break;
- case 11:
- nAECFieldSel = 6;
- break;
- case 111:
- nAECFieldSel = 7;
- break;
- default:
- nAECFieldSel = 2;
- break;
- }
- cmdbuf[5] = nAECFieldSel;//field
- cmdbuf[6] = 0;
- cmdbuf[7] = 0;
- if (m_DoseUnit.m_AECFilm->Get() == 0)
- SetAECInformation(m_nChamberIndex, m_DoseUnit.m_AECField->Get(), m_DoseUnit.m_AECDensity->Get(), m_DoseUnit.m_AECFilm->Get());
- }
- }
- }
- FormatCommand(cmdbuf, 13);
- string temp(cmdbuf, 13);
- m_strCommand = temp;
- HWSend(m_strCommand.c_str(), m_strCommand.length());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetFocus(int value)
- {
- if (!m_DoseUnit.m_Focus->Verify(value)) return RET_STATUS::RET_SUCCEED;
- FINFO("[0xF0, 0x5A, 0xA1, 0x00] focus: {$}", value);
- char cmdbuf[20] = { 0xF0, 0x5A, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7A, 0x00, 0x88 };
- if (value == 0)
- {
- cmdbuf[3] = 2;
- }
- else if (value == 1)
- {
- cmdbuf[3] = 1;
- }
- else
- {
- cmdbuf[3] = 3;
- }
- FormatCommand(cmdbuf, 13);
- string temp(cmdbuf, 13);
- m_strCommand = temp;
- HWSend(m_strCommand.c_str(), m_strCommand.length());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetAECDensity(int value)
- {
- if (!m_DoseUnit.m_AECDensity->Verify(value)) return RET_STATUS::RET_SUCCEED;
- FINFO("AECDensity: {$}", value);
- if (value < -3)
- {
- value = -3;
- }
- else if (value > 3)
- {
- value = 3;
- }
- if (m_DoseUnit.m_AECDensity->Get() != value)
- {
- SetAECInformation(1, m_DoseUnit.m_AECField->Get(), value, m_DoseUnit.m_AECFilm->Get());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetAECField(int value)
- {
- if (!m_DoseUnit.m_AECField->Verify(value)) return RET_STATUS::RET_SUCCEED;
- FINFO("AECField: {$}", value);
- if (m_DoseUnit.m_AECField->Get() != value)
- {
- SetAECInformation(1, value, m_DoseUnit.m_AECDensity->Get(), m_DoseUnit.m_AECFilm->Get());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetAECFilm(int value)
- {
- if (!m_DoseUnit.m_AECFilm->Verify(value)) return RET_STATUS::RET_SUCCEED;
- FINFO("AECFilm: {$}", value);
- if (m_DoseUnit.m_AECFilm->Get() != value)
- {
- SetAECInformation(1, m_DoseUnit.m_AECField->Get(), m_DoseUnit.m_AECDensity->Get(), value);
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetWS(const string value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetAPR(const _tAPRArgs& t)
- {
- m_tAPRdata = t;
- FINFO("Focus: {$}, Techmode: {$}, AECField: {$}, AECFilm: {$}, AECDensity: {$}, KV: {$}, MA: {$}, MS: {$}, KV2: {$}, MA2: {$}, MS2: {$}, MAS: {$}",
- 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);
- if (m_tAPRdata.fKV2 != 0)
- {
- SetDualEnergyCommand(m_tAPRdata);
- }
- else
- {
- SetRadMode(0, 0);
- if ((int)m_tAPRdata.fMA > m_nTubeMaSFMaxValue)
- {
- SetFocus(1);
- }
- else
- {
- SetFocus(0);
- }
- SetTechmode(m_tAPRdata.nTechmode);
- if (m_tAPRdata.nTechmode == AttrKey::TECHMODE_AEC_3P)
- {
- if (m_tAPRdata.nWS == AttrKey::TABLE)
- {
- if (m_nTableUsePanelAEC != 1)
- {
- if (m_DoseUnit.m_AECFilm->Get() == 0)
- m_DoseUnit.m_AECFilm->Update(1);
- SetAECInformation(m_nChamberIndex, m_tAPRdata.nAECField, m_tAPRdata.nAECDensity, m_tAPRdata.nAECFilm);
- SetAECKV_MA_MS((int)m_tAPRdata.fKV, m_tAPRdata.fMA, m_tAPRdata.fMS);
- }
- else
- {
- SetRADKV_MA_MS((int)m_tAPRdata.fKV, m_tAPRdata.fMA, m_tAPRdata.fMS);
- }
- }
- else if (m_tAPRdata.nWS == AttrKey::WALL)
- {
- if (m_nWallUsePanelAEC != 1)
- {
- if (m_tAPRdata.nAECFilm == 0)
- m_tAPRdata.nAECFilm = 1;
- SetAECInformation(m_nChamberIndex, m_tAPRdata.nAECField, m_tAPRdata.nAECDensity, m_tAPRdata.nAECFilm);
- SetAECKV_MA_MS((int)m_tAPRdata.fKV, m_tAPRdata.fMA, m_tAPRdata.fMS);
- }
- else
- {
- SetRADKV_MA_MS((int)m_tAPRdata.fKV, m_tAPRdata.fMA, m_tAPRdata.fMS);
- }
- }
- else if (m_tAPRdata.nWS == AttrKey::MOBILE)
- {
- if (m_nFreeUsePanelAEC != 1)
- {
- if (m_tAPRdata.nAECFilm == 0)
- m_tAPRdata.nAECFilm = 1;
- SetAECInformation(m_nChamberIndex, m_tAPRdata.nAECField, m_tAPRdata.nAECDensity, m_tAPRdata.nAECFilm);
- SetAECKV_MA_MS((int)m_tAPRdata.fKV, m_tAPRdata.fMA, m_tAPRdata.fMS);
- }
- else
- {
- SetRADKV_MA_MS((int)m_tAPRdata.fKV, m_tAPRdata.fMA, m_tAPRdata.fMS);
- }
- }
- }
- else if (m_tAPRdata.nTechmode == AttrKey::TECHMODE_NOAEC_2P)
- {
- SetRADKV_MAS((int)m_tAPRdata.fKV, m_tAPRdata.fMAS);
- }
- else
- {
- SetRADKV_MA_MS((int)m_tAPRdata.fKV, m_tAPRdata.fMA, m_tAPRdata.fMS);
- }
- }
- m_bSetAPR = true;
- return RET_STATUS::RET_SUCCEED;
- }
- bool nsGEN::DeltaDevice::SetDualEnergyCommand(const _tAPRArgs& t)
- {
- if (!m_bIsDualExp)
- SetRadMode(1, 1);
- if (m_nExposureNumber == 0)
- {
- FINFO("Dual Energy First APR KV: {$}, MA: {$}, MS: {$}, MAS: {$}", t.fKV, t.fMA, t.fMS, t.fMAS);
- m_bIsDualExp = true;
- //设置双能第一组曝光参数
- SetAPRForDual(t.nWS, t.nFocus, t.nTechmode, t.nAECField, t.nAECFilm, t.nAECDensity, t.fKV, t.fMA, t.fMS, t.fMAS);
- //双能是序列点片,是需要配置帧率的
- FINFO("Set de framerate[0xF0, 0x6D, 0xAD, 0xxx]");
- char cmdbuf[20] = { 0xF0, 0x6D, 0xAD, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0xDB, 0x00, 0x88 };
- cmdbuf[3] = m_nDEFrameRate * 10;
- FormatCommand(cmdbuf, 19);
- string temp(cmdbuf, 19);
- m_strCommand = temp;
- HWSend(m_strCommand.c_str(), m_strCommand.length());
- }
- else if (m_nExposureNumber == 1)
- {
- //2 set 2nd array param
- FINFO("Dual Energy Second APR KV: {$}, MA: {$}, MS: {$}", t.fKV2, t.fMA2, t.fMS2);
- //设置第二组参数
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_AEC_3P)
- {
- SetAECInformation(m_nChamberIndex, t.nAECField, t.nAECDensity, 0);
- SetAECKV_MA_MS((int)t.fKV2, t.fMA2, t.fMS2);
- }
- else if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_NOAEC_2P)
- {
- SetRADKV_MAS((int)t.fKV2, t.fMA2 * t.fMS2 / 1000);
- }
- else
- {
- SetRADKV_MA_MS((int)t.fKV2, t.fMA2, t.fMS2);
- }
- //m_bIsDualExp = false; //第二次设定之后,主动false
- //m_nExposureNumber = 0;
- }
- return true;
- }
- bool nsGEN::DeltaDevice::SetAPRForDual(int nWS, int nFO, int nET, int nAECFieldSel, int nAECFilmSel, float fAECDensity, float fKV, float fMA, float fMS, float fMAS)
- {
- FINFO("Focus: {$}, Techmode: {$}, AECField: {$},AECFilm: {$}, AECDensity: {$}, KV: {$}, MA: {$}, MS: {$}, MAS: {$}",
- 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);
- //客户说160是 small FO的最大值。 180是大焦点的最小值
- if ((int)fMA > m_nTubeMaSFMaxValue)
- {
- SetFocus(1);
- }
- else
- {
- SetFocus(0);
- }
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_AEC_3P)
- {
- if (nAECFilmSel == 0)
- nAECFilmSel = 1;
- SetAECInformation(m_nChamberIndex, nAECFieldSel, fAECDensity, nAECFilmSel);
- SetAECKV_MA_MS((int)fKV, fMA, fMS);
- }
- else if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_NOAEC_2P)
- {
- SetRADKV_MAS((int)fKV, fMAS);
- }
- else
- {
- SetRADKV_MA_MS((int)fKV, fMA, fMS);
- }
- return true;
- }
- RET_STATUS nsGEN::DeltaDevice::QueryHE(int& value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::QueryPostKV(float& value)
- {
- m_DoseUnit.m_PostKV->Update(m_DoseUnit.m_KV->Get());
- value = m_DoseUnit.m_PostKV->Get();
- return RET_STATUS::RET_FAILED;
- }
- RET_STATUS nsGEN::DeltaDevice::QueryPostMA(float& value)
- {
- value = m_DoseUnit.m_PostMA->Get();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::QueryPostMS(float& value)
- {
- value = m_DoseUnit.m_PostMS->Get();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::QueryPostMAS(float& value)
- {
- value = m_DoseUnit.m_PostMAS->Get();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetGenSynState(int value)
- {
- FINFO("GenSynState: {$}", value);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetGenState(int value)
- {
- FINFO("GenState: {$}", value);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetExpMode(std::string value)
- {
- FINFO("ExpMode: {$}", value.c_str());
- m_DoseUnit.m_ExpMode->Update(value);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetFLFMode(std::string value)
- {
- FINFO("FLFMode: {$}", value.c_str());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetEXAMMode(std::string value)
- {
- FINFO("EXAMMode: {$}", value.c_str());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetFrameRate(FLOAT frameRate)
- {
- if (m_DoseUnit.m_FrameRate->Verify(frameRate))
- {
- FINFO("[0xF0, 0x56, 0xA2, 0x00] FrameRate: {$}", frameRate);
- char cmdbuf[13] = { 0xF0, 0x56, 0xA2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7A, 0x00, 0x88 };
- int nPPS = (int)(frameRate * 10);
- cmdbuf[3] = nPPS / 256;
- cmdbuf[4] = nPPS % 256;
- FormatCommand(cmdbuf, 13);
- string temp(cmdbuf, 13);
- m_strCommand = temp;
-
- HWSend(m_strCommand.c_str(), m_strCommand.length());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- //貌似最好有时间间隔
- RET_STATUS nsGEN::DeltaDevice::RefreshData()
- {
- FINFO("RefreshData");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetExpEnable()
- {
- char cmdbuf[13] = { 0xF0, 0x5C, 0xA3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC5, 0x00, 0x88 };
- FINFO("[0xF0, 0x5C, 0xA3, 0x00]");
- FormatCommand(cmdbuf, 13);
- string temp(cmdbuf, 13);
- m_strCommand = temp;
- HWSend(m_strCommand.c_str(), m_strCommand.length());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetExpDisable()
- {
- char cmdbuf[13] = { 0xF0, 0x5C, 0xA3, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86, 0x00, 0x88 };
- FINFO("ExpEnable[0xF0, 0x5C, 0xA3, 0x01]");
- FormatCommand(cmdbuf, 13);
- string temp(cmdbuf, 13);
- m_strCommand = temp;
-
- HWSend(m_strCommand.c_str(), m_strCommand.length());
- m_nProcessXrayon = false;
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::Reset()
- {
- FINFO("[0xF0 ,0x59 ,0xA1 ,CurErrLevel{$}]", m_nCurErrLevel);
- char cmdbuf[13] = { 0xF0 ,0x59 ,0xA1 ,0x01 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x88 };
- cmdbuf[3] = m_nCurErrLevel;
- FormatCommand(cmdbuf, 13);
- string temp(cmdbuf, 13);
- m_strCommand = temp;
- HWSend(m_strCommand.c_str(), m_strCommand.length());
- return RET_STATUS::RET_SUCCEED;
- }
- //-----------------------------------------------------------------------------
- // ProcessCmd - 已废弃
- //-----------------------------------------------------------------------------
- // 注释:DeliverModule已废弃,Linux下不再使用
- // void nsGEN::DeltaDevice::ProcessClientData(const char* pData, unsigned long nDataLength, void* lparam)
- // {
- // DeltaDevice* pCurGen = (DeltaDevice*)lparam;
- // pCurGen->HWSend(pData, nDataLength);
- // }
- // void nsGEN::DeltaDevice::WriteLog(const char* pData, nsSerialGPM::LOG_V2_LEVEL level)
- // {
- // }
- // RET_STATUS nsGEN::DeltaDevice::HWSendWaitACKCMD(string strCommand, int headLengh)
- // {
- // return m_tDelivermodule.ProcessCommand(strCommand, m_nCMDType_WaitACK, headLengh);
- // }
- RET_STATUS nsGEN::DeltaDevice::HWSend(const char* strCommand, int lengh, int nTimeOut)
- {
- // 参数校验
- if (strCommand == nullptr || lengh <= 0)
- {
- FERROR("Invalid parameters: strCommand is null or length <= 0");
- return RET_STATUS::RET_FAILED;
- }
- // 连接状态检查
- if (!m_SCF || !m_SCF->IsConnected())
- {
- FWARN("SCF not connected, cannot send command");
- return RET_STATUS::RET_FAILED;
- }
- // 构建日志输出的十六进制字符串
- char strtemp[10] = { 0 };
- string str = "";
- for (int i = 0; i < lengh; i++)
- {
- snprintf(strtemp, sizeof(strtemp), "%02X", (BYTE)strCommand[i]);
- str += strtemp;
- str += ",";
- }
- FINFO("==OUT==: {$}, length: {$}, timeout: {$}ms", str, lengh, nTimeOut);
- unsigned int retLength = 0;
- // 使用Lock/Unlock保护SendPacket调用
- if (m_SCF->Lock(1000) == WAIT_OBJECT_0)
- {
- int ret = m_SCF->SendPacket(strCommand, lengh, nTimeOut, retLength);
- m_SCF->Unlock();
- if (ret != 0)
- {
- FERROR("SendPacket failed, error code: {$}, sent length: {$}", ret, retLength);
- return RET_STATUS::RET_FAILED;
- }
- FDEBUG("SendPacket succeeded, sent {$} bytes", retLength);
- }
- else
- {
- FERROR("Failed to lock SCF (timeout 1000ms) for sending command");
- return RET_STATUS::RET_FAILED;
- }
- return RET_STATUS::RET_SUCCEED;
- }
- void nsGEN::DeltaDevice::FireErrorMessage(const bool Act, const int Code, const char* ResInfo)
- {
- string ErrorCode("DELTA_ERR_");
- ErrorCode += std::to_string(Code);
- int level = DELTA_ABNORMAL_LEVEL::REG_ERRO;
- if (Act)
- {
- FERROR("add {$}:{$}", ErrorCode.c_str(), ResInfo);
- m_MSGUnit->AddErrorMessage(ErrorCode.c_str(), level, ResInfo);
- }
- else
- {
- FERROR("del {$}:{$}", ErrorCode.c_str(), ResInfo);
- m_MSGUnit->DelErrorMessage(ErrorCode.c_str(), level, ResInfo);
- }
- }
- void nsGEN::DeltaDevice::FireWarnMessage(const bool Act, const int Code, const char* ResInfo)
- {
- string WarnCode("DELTA_WAR_");
- WarnCode += std::to_string(Code);
- int level = DELTA_ABNORMAL_LEVEL::REG_WARN;
- if (Act)
- {
- FERROR("add {$}:{$}", WarnCode.c_str(), ResInfo);
- m_MSGUnit->AddWarnMessage(WarnCode.c_str(), level, ResInfo);
- }
- else
- {
- FERROR("del {$}:{$}", WarnCode.c_str(), ResInfo);
- m_MSGUnit->DelWarnMessage(WarnCode.c_str(), level, ResInfo);
- }
- }
- //-----------------------------------------------------------------------------
- // ProcessCmd
- //-----------------------------------------------------------------------------
- void nsGEN::DeltaDevice::FireNotify(std::string key, std::string content)
- {
- EventCenter->OnNotify(1, key, content);
- }
- void nsGEN::DeltaDevice::ProcessCommand(const char* strPackage, int Index, int End)
- {
- if ((BYTE)strPackage[Index] == 0xF0)
- {
- if (strPackage[End - 4] != 0x0A)
- {
- //GetLastExpParamenters();
- char WarnCode[20];
- snprintf(WarnCode, sizeof(WarnCode), "DELTA_WARN_%03d", (BYTE)strPackage[End - 4]);
- int level = 1;
- FINFO("{$}", WarnCode);
- auto it = m_WarnMessages.find(WarnCode);
- if (it != m_WarnMessages.end())
- {
- m_MSGUnit->AddWarnMessage(WarnCode, level, it->second.c_str());
- //return false;
- }
- }
- }
- m_bReconnect = false;
- const char* chdigital;
- m_nCountTimes = 0;
- if (UINT8(strPackage[Index]) != 0xF0)
- {
- FINFO("simple cmd:{$}", strPackage);
- if (strPackage[Index] == 'C' && strPackage[Index + 1] == 'X' && strPackage[Index + 2] == 'L')
- {
- m_nProcessXrayon = false;
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF);
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- if (strPackage[Index] == 'E' && strPackage[Index + 1] == 'R' && strPackage[Index + 2] == 'R')
- {
- m_nProcessXrayon = false;
- chdigital = strPackage + 3;
- int errornumber = atoi(chdigital);
- if (errornumber < 3000) //warn
- {
- char WarnCode[20];
- snprintf(WarnCode, sizeof(WarnCode), "DELTA_WARN_%03d", (BYTE)strPackage[End - 4]);
- int level = 1;
- FINFO("{$}", WarnCode);
- auto itwarn = m_WarnMessages.find(WarnCode);
- if (itwarn != m_WarnMessages.end())
- {
- m_MSGUnit->AddWarnMessage(WarnCode, level, itwarn->second.c_str());
- //return false;
- }
- //如果error=0012,那么表示一档松开。那么应该发送release,取消本次曝光,否则会出现超时的问题
- if (errornumber == 12 || errornumber == 1006)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF);
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- if (errornumber >= 4000)
- {
- m_nCurErrLevel = 3;
- }
- if (errornumber >= 3000)
- {
- m_nCurErrLevel = 1;
- }
- char ErrCode[20];
- snprintf(ErrCode, sizeof(ErrCode), "DELTA_ERR_%04d", (BYTE)strPackage[3]);
- FINFO("{$}", ErrCode);
- auto iterr = m_ErrorMessages.find(ErrCode);
- if (iterr != m_ErrorMessages.end())
- {
- m_MSGUnit->AddErrorMessage(ErrCode, level, iterr->second.c_str());
- //return false;
- }
- }
- }
- if (strPackage[Index] == 'R' && strPackage[Index + 1] == 'O' && strPackage[Index + 2] == 'N')//RON RDY XON OFF
- {
- m_nProcessXrayon = true;
- if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::CONVENTIONAL)
- {
- m_DoseUnit.m_Handswitch->Update(AttrKey::HANDSWITCH_STATUS::HANDSWITCH_STATUS_Release);
- FireNotify(m_DoseUnit.m_Handswitch->GetKey(), m_DoseUnit.m_Handswitch->JSGet());
- FINFO("Updata m_DoseUnit.m_Handswitch: {$}", m_DoseUnit.m_Handswitch->JSGet());
- }
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_SYNC::GENERATOR_RAD_PREPARE);
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- FINFO("Updata m_DoseUnit.m_GenSynState: {$}", m_DoseUnit.m_GenSynState->JSGet());
- }
- if (strPackage[Index] == 'R' && strPackage[Index + 1] == 'D' && strPackage[Index + 2] == 'Y')//RON RDY XON OFF
- {
- m_nProcessXrayon = true;
- if (m_DoseUnit.m_GenSynState->Get() != AttrKey::GENERATOR_SYNC::GENERATOR_RAD_PREPARE)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_SYNC::GENERATOR_RAD_PREPARE);
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- FINFO("Updata m_DoseUnit.m_GenSynState: {$}", m_DoseUnit.m_GenSynState->JSGet());
- }
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_SYNC::GENERATOR_RAD_READY);
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- FINFO("Updata m_DoseUnit.m_GenSynState: {$}", m_DoseUnit.m_GenSynState->JSGet());
- Sleep(20);//此发生器RDY和XON有时消息会过快,导致工作流没反应过来。所以加个睡眠。
- FINFO("m_bIsDualExp: {$} m_nExposureNumber: {$}", m_bIsDualExp, m_nExposureNumber);
- if (m_bIsDualExp && (m_nExposureNumber == 1))
- {
- if (m_bSendXwindowToDector)
- {
- m_pDetectorClient = new LogicClient("DV3_Detector", "", "NSQ", false);
- if (m_pDetectorClient->Open("CCOS/DEVICE/Detector", ALL_ACCESS)) //换成探测器的路径
- {
- FDEBUG("Ccos_V3 Create DV3_Detector Client success");
- }
- }
- if (m_pDetectorClient != NULL)
- {
- if (!m_pDetectorClient->IsClosed())
- {
- FINFO("m_pDetectorClient is open");
- ResDataObject Request, Response;
- Request.add("P0", 1);
- m_pDetectorClient->Action("DualSecondExpReady", Request, Response, 4993);
- }
- else
- {
- FINFO("DV3_Detector Client is Close");
- }
- }
- else
- {
- FINFO("DV3_FullUCB Client is NULL");
- }
- m_bIsDualExp = false; //第二次设定之后,主动false
- m_nExposureNumber = 0;
- }
- }
- if (strPackage[Index] == 'X' && strPackage[Index + 1] == 'O' && strPackage[Index + 2] == 'N')//RON RDY XON OFF
- {
- m_nProcessXrayon = true;
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_SYNC::GENERATOR_RAD_XRAYON);
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- FINFO("Updata m_DoseUnit.m_GenSynState: {$}", m_DoseUnit.m_GenSynState->JSGet());
- m_bXronMsg = true;
- }
- if (strPackage[Index] == 'O' && strPackage[Index + 1] == 'F' && strPackage[Index + 2] == 'F')//RON RDY XON OFF
- {
- if (m_bXronMsg == false)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_SYNC::GENERATOR_RAD_XRAYON);
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- FINFO("Updata m_DoseUnit.m_GenSynState: {$}", m_DoseUnit.m_GenSynState->JSGet());
- }
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_SYNC::GENERATOR_RAD_XRAYOFF);
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- FINFO("Updata m_DoseUnit.m_GenSynState: {$}", m_DoseUnit.m_GenSynState->JSGet());
- GetLastExpParamenters();
- if (m_bIsDualExp)
- {
- m_nExposureNumber = 1;
- SetDualEnergyCommand(m_tAPRdata);
- FINFO("dual: setapr 2nd.");
- }
- m_nProcessXrayon = false;
- m_bXronMsg = false;
- }
- return;
- }
- switch (UINT8(strPackage[Index + 1]))
- {
- case 0x50:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0xA1:
- //50A1
- FINFO("Restore factory settings successfully");
- break;
- default:
- break;
- }
- break;
- }
- case 0x51:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x01:
- {
- //5101
- int nET = (int)(strPackage[Index + 3]);
- FINFO("ET{$}", nET);
- if (nET == 1)//AEC
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_AEC_3P);
- }
- else if (nET == 2)//MS
- {
- if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::TABLE)
- {
- if (m_nTableUsePanelAEC == 1)
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_AEC_3P);
- }
- else
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_3P);
- }
- }
- else if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::WALL)
- {
- if (m_nWallUsePanelAEC == 1)
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_AEC_3P);
- }
- else
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_3P);
- }
- }
- else if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::MOBILE)
- {
- if (m_nFreeUsePanelAEC == 1)
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_AEC_3P);
- }
- else
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_3P);
- }
- }
- else
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_3P);
- }
- }
- else if (nET == 3)//MAS
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_2P);
- }
- FireNotify(m_DoseUnit.m_Techmode->GetKey(), m_DoseUnit.m_Techmode->JSGet());
- FINFO("[51 01]: ET {$}", m_DoseUnit.m_Techmode->Get());
- break;
- }
- case 0xA1:
- {
- //51A1
- int nET = (int)(strPackage[Index + 3]);
- if (nET == 1)//AEC
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P);
- FireNotify(m_DoseUnit.m_Techmode->GetKey(), m_DoseUnit.m_Techmode->JSGet());
- m_AECinformation.Chamber = (int)(strPackage[4]);
- m_AECinformation.Field = (int)(strPackage[5]);
- m_AECinformation.Density = (int)(strPackage[6]);
- m_AECinformation.FilmScreenSpeed = (int)(strPackage[7]);
- UpdataAECInformation(m_AECinformation);
- }
- else if (nET == 2)//如果当前是DAEC模式,那么返回的是time,但是可能需要选中 AEC 按钮
- {
- if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::TABLE)
- {
- if (m_nTableUsePanelAEC == 1)
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_AEC_3P);
- }
- else
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_3P);
- }
- }
- else if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::WALL)
- {
- if (m_nWallUsePanelAEC == 1)
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_AEC_3P);
- }
- else
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_3P);
- }
- }
- else if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::MOBILE)
- {
- if (m_nFreeUsePanelAEC == 1)
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_AEC_3P);
- }
- else
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_3P);
- }
- }
- else
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_3P);
- }
- FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet());
- FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet());
- }
- else if (nET == 3)
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_2P);
- }
- FireNotify(m_DoseUnit.m_Techmode->GetKey(), m_DoseUnit.m_Techmode->JSGet());
- FINFO("[51 A1]: ET {$}", m_DoseUnit.m_Techmode->Get());
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x52:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x01:
- {
- //5201
- FINFO("[52 01]");
- break;
- }
- case 0xA1:
- {
- //52A1
- FINFO("[52 A1]");
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x53:
- {
- switch (UINT8(strPackage[2]))
- {
- case 0x01:
- {
- //5301
- FINFO("[53 01]");
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x54:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x01:
- {
- //5401
- FINFO("[54 01]");
- break;
- }
- case 0x02:
- {
- //5402
- FINFO("[54 02]");
- break;
- }
- case 0xA1:
- {
- //54A1
- FINFO("[54 A1]");
- break;
- }
- case 0xA2:
- {
- //54A2
- FINFO("[54 A2]");
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x55:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x01:
- case 0xA1:
- {
- //55A1
- m_AECinformation.Chamber = (int)(strPackage[Index + 3]);
- m_AECinformation.Field = (int)(strPackage[Index + 4]);
- m_AECinformation.Density = (int)(strPackage[Index + 5]);
- m_AECinformation.FilmScreenSpeed = (int)(strPackage[Index + 6]);
- UpdataAECInformation(m_AECinformation);
- FINFO("[55 A1]: AEC");
- break;
- }
- case 0xA2:
- {
- //55A2
- //kv
- int nKv = (BYTE)(strPackage[Index + 3]);
- m_DoseUnit.m_KV->Update(nKv);
- FireNotify(m_DoseUnit.m_KV->GetKey(), m_DoseUnit.m_KV->JSGet());
- //ma
- float fMA = ((BYTE)(strPackage[Index + 4]) * 256 + (BYTE)strPackage[Index + 5]) / 10.0f;
- m_DoseUnit.m_MA->Update(fMA);
- FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet());
- //aec reference kv
- //not ms
- float m_fMS = ((BYTE)strPackage[Index + 6] * 256 + (BYTE)strPackage[Index + 7]) / 10.0f;
- m_DoseUnit.m_MS->Update(m_fMS);
- FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet());
- int hundred_aec_referenc_kv = (BYTE)strPackage[Index + 6] * 256 + (BYTE)strPackage[Index + 7];
- float mas = m_DoseUnit.m_MA->Get() * m_DoseUnit.m_MS->Get() / 1000.0f;
- GetFacFloatValue(m_vecMAS, mas);
- m_DoseUnit.m_MAS->Update(mas);
- FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet());
- FINFO("[55 A2]: Updata: KV: {$}, MA: {$}, MS: {$}, MAS: {$}",
- m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MA->Get(), m_DoseUnit.m_MS->Get(), m_DoseUnit.m_MAS->Get());
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x56:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x02:
- {
- //5602
- //查询脉冲帧率,不用
- FINFO("[56 02]: AEC.");
- break;
- }
- case 0xA1:
- {
- //56A1
- //kv
- int nKv = (BYTE)(strPackage[Index + 3]);
- m_DoseUnit.m_KV->Update(nKv);
- FireNotify(m_DoseUnit.m_KV->GetKey(), m_DoseUnit.m_KV->JSGet());
- //ma
- float fMA = ((BYTE)(strPackage[Index + 4]) * 256 + (BYTE)strPackage[Index + 5]) / 10.0f;
- m_DoseUnit.m_MA->Update(fMA);
- FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet());
- //ms
- float fMS = ((BYTE)(strPackage[Index + 6]) * 65536 + (BYTE)strPackage[Index + 7] * 256 + (BYTE)strPackage[Index + 8]) / 10.0f;
- m_DoseUnit.m_MS->Update(fMS);
- FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet());
- float mas = m_DoseUnit.m_MA->Get() * m_DoseUnit.m_MS->Get() / 1000.0f;
- GetFacFloatValue(m_vecMAS, mas);
- m_DoseUnit.m_MAS->Update(mas);
- FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet());
- FINFO("[56 A1]: Time mode: Updata: KV: {$}, MA: {$}, MS: {$}, MAS: {$}",
- m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MA->Get(), m_DoseUnit.m_MS->Get(), m_DoseUnit.m_MAS->Get());
- break;
- }
- case 0xA2:
- {
- //56A2设置脉冲帧率,暂时不用
- FINFO("[56 A2]:");
- break;
- }
- case 0xA3:
- {
- //56A3透视检查的kv ma mas,暂时用不到,不解析了。
- FINFO("[56 A3]:");
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x57://-----------------------------------------------------------首次进入时,直接切换到mas,ma ms 没有消失****************bug
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0xA1:
- {
- //57A1mas模式下的 kv mas 解析
- //kv
- int nKv = (int)(strPackage[Index + 3]);
- m_DoseUnit.m_KV->Update(nKv);
- FireNotify(m_DoseUnit.m_KV->GetKey(), m_DoseUnit.m_KV->JSGet());
- //ma
- float fMA = ((BYTE)(strPackage[Index + 4]) * 256 + (BYTE)strPackage[Index + 5]) / 10.0f;
- m_DoseUnit.m_MA->Update(fMA);
- FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet());
- //ms----MAS 模式下,返回的ms值。
- float fMS = ((BYTE)(strPackage[Index + 6]) * 65536 + (BYTE)strPackage[Index + 7] * 256 + (BYTE)strPackage[Index + 8]) / 10.0f;
- m_DoseUnit.m_MS->Update(fMS);
- FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet());
- float mas = m_DoseUnit.m_MA->Get() * m_DoseUnit.m_MS->Get() / 1000.0f;
- GetFacFloatValue(m_vecMAS, mas);
- m_DoseUnit.m_MAS->Update(mas);
- FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet());
- 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());
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x58:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 1:
- {
- int dapStatus = (int)(strPackage[Index + 2]);
- if (1 == dapStatus)
- {
- //dap enable
- float fDap = 0;
- UINT8 tmpBuf[4] = { 0 };
- tmpBuf[0] = strPackage[Index + 7];
- tmpBuf[1] = strPackage[Index + 6];
- tmpBuf[2] = strPackage[Index + 5];
- tmpBuf[3] = strPackage[Index + 4];
- memcpy(&fDap, tmpBuf, 4);
- int nDAP = (int)fDap;
- }
- else
- {
- //dap disable
- }
- break;
- }
- case 2:
- {
- //dap rate
- float fDapRate = 0;
- UINT8 tmpBuf[4] = { 0 };
- tmpBuf[0] = strPackage[Index + 6];
- tmpBuf[1] = strPackage[Index + 5];
- tmpBuf[2] = strPackage[Index + 4];
- tmpBuf[3] = strPackage[Index + 3];
- memcpy(&fDapRate, tmpBuf, 4);
- //mGycm^2/s
- break;
- }
- case 0xA1:
- {
- FINFO("[58 A1]: clear dap and dap rate success!");
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x59:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0xA1:
- {
- //59A1
- int nResetLevel = (int)(strPackage[Index + 3]);
- FINFO("[59 A1]:");
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x5A:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x01:
- {
- //5A01
- FINFO("[5A 01]:");
- break;
- }
- case 0xA1:
- {
- //5AA1
- int nFo = (int)(strPackage[Index + 3]);
- if (1 == nFo)
- {
- m_DoseUnit.m_Focus->Update(1);
- }
- else if (2 == nFo)
- {
- m_DoseUnit.m_Focus->Update(0);
- }
- else//auto
- {
- m_DoseUnit.m_Focus->Update(0);
- }
- FireNotify(m_DoseUnit.m_Focus->GetKey(), m_DoseUnit.m_Focus->JSGet());
- //RetrieveGeneratroDerating();
- FINFO("[5A A1]: FO= {$}", m_DoseUnit.m_Focus->Get());
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x5B:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x01:
- {
- //5B01
- FINFO("[5B 01]");
- break;
- }
- case 0xA1:
- {
- //5BA1
- FINFO("[5B A1]");
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x5C:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0xA1:
- {
- //5CA1
- FINFO("[5C A1]:Gen Operate Status is Shutdown");
- break;
- }
- case 0xA2:
- {
- //5CA2
- FINFO("[5C A2]:Gen Operate Status is StandBy");
- break;
- }
- case 0x03:
- case 0xA3:
- {
- //5CA3
- int nExpEnable = (int)(strPackage[Index + 3]);
- FINFO("[5C A3/03]:m_bExpEnable");
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x5E:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x01:
- {
- FINFO("[5E 01]:tube id is 1");
- break;
- }
- case 0x02:
- {
- FINFO("[5E 01]:tube id is 2");
- break;
- }
- case 0x03:
- {
- FINFO("[5E 03]");
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x5F:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x01:
- {
- //5F01
- int TenTubeHU = BYTE(strPackage[Index + 3]) * 256 + (BYTE)strPackage[Index + 4];
- m_DoseUnit.m_HE->Update(TenTubeHU / 10);
- FireNotify(m_DoseUnit.m_HE->GetKey(), m_DoseUnit.m_HE->JSGet());
- ////::PostMessage(this->m_hWnd, MSG_GEN_PARAM, GEN_PARAM_HE, this->m_nTubeHeat);
- //int TenGenHU = BYTE(strPackage[5]) * 256 + (BYTE)strPackage[6];
- //m_nGenHeat = TenGenHU / 10;
- ////GEN_PARAM_GENHEAT->侯雷确认 是温度。不应该用于这里
- ////::PostMessage(this->m_hWnd, MSG_GEN_PARAM, GEN_PARAM_GENHEAT, this->m_nGenHeat);
- ////GEN_TUBEHU_STATUS 是状态,协议中没有根据genhu的值来定义状态的规定。因此不用这段代码
- ////::PostMessage(this->m_hWnd, MSG_GEN_PARAM, GEN_TUBEHU_STATUS, this->m_nGenHeat);
- //int TenMotorHU = BYTE(strPackage[7]) * 256 + (BYTE)strPackage[8];
- //strlog.Format("5F 01,tube HU = %d,gen HU*10=%d MotorHU*10=%d", m_nTubeHeat, TenGenHU, TenMotorHU);
- //logfile->WriteLog(strlog, LOG_INFORMATION, LOG_DEBUG, true);
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x61:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x01:
- {
- string GenFirmwareVersion = AnalysisCommand(BYTE_6, chdigital, TransToType::tochar);
- string ConsoleFirmwareVersion = AnalysisCommand(BYTE_6, chdigital, TransToType::tochar);
- FINFO("[61 01]:Generator firmware version {$}, Console firmware version {$}", GenFirmwareVersion, ConsoleFirmwareVersion);
- break;
- }
- case 0x02:
- {
- break;
- }
- case 0x03:
- {
- break;
- }
- case 0x04:
- {
- int maxKw = (int)(strPackage[Index + 3] << 8 | strPackage[Index + 4]);
- int maxMa = (int)(strPackage[Index + 5] << 8 | strPackage[Index + 6]);
- int maxMas = (int)(strPackage[Index + 7] << 8 | strPackage[Index + 8]);
- int maxKv = (int)(strPackage[Index + 9]);
- int nFo = (int)(strPackage[Index + 10]);
- int nRotor = (int)(strPackage[Index + 11]);
- int nMotorFirmwareVersion = (int)(strPackage[Index + 12] << 8 | strPackage[Index + 13]);
- int nSWCfgFileVersion = (int)(strPackage[Index + 14]);
- break;
- }
- case 0x05:
- {
- m_nMaxKW = (int)(strPackage[Index + 3] << 8 | strPackage[Index + 4]);
- int maxDeratingMa = (int)(strPackage[Index + 5] << 8 | strPackage[Index + 6]);
- int maxDeratingMas = (int)(strPackage[Index + 7] << 8 | strPackage[Index + 8]);
- int maxDeratingKv = (int)(strPackage[Index + 9]);
- int minDeratingMa = (int)(strPackage[Index + 10] << 8 | strPackage[Index + 11]);
- int maxDeratingMs = (int)(strPackage[Index + 12] << 8 | strPackage[Index + 13]);
- break;
- }
- case 0x06:
- {
- break;
- }
- case 0xA5:
- {
- break;
- }
- case 0x07:
- case 0xA7:
- {
- int nAccuracy = (int)(strPackage[Index + 3]);
- if (1 == nAccuracy)
- {
- //logfile->WriteLog("61 07 / A7 :now is R10' series.", LOG_INFORMATION, LOG_DEBUG, true);
- }
- else if (2 == nAccuracy)
- {
- //logfile->WriteLog("61 07 / A7 :now is R20' series.", LOG_INFORMATION, LOG_DEBUG, true);
- }
- break;
- }
- case 0xAC:
- {
- //DAEC enable status
- int nDaecStatus = (int)(strPackage[Index + 3]);
- //m_nDAECStatus = nDaecStatus;
- //if (nDaecStatus == 1)
- //{
- // logfile->WriteLog("recv 6e AC: daec enable", LOG_INFORMATION, LOG_DEBUG, true);
- //}
- //else if (nDaecStatus == 2)
- //{
- // logfile->WriteLog("recv 6e AC: daec disable", LOG_INFORMATION, LOG_DEBUG, true);
- //}
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x62:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x01:
- {
- break;
- }
- case 0x02:
- {
- chdigital = strPackage + 3;
- int SF_LS_MaxPower = (int)(strPackage[Index + 3] << 8 | strPackage[Index + 4]);
- int LF_LS_MaxPower = (int)(strPackage[Index + 5] << 8 | strPackage[Index + 6]);
- int SF_HS_MaxPower = (int)(strPackage[Index + 7] << 8 | strPackage[Index + 8]);
- int LF_HS_MaxPower = (int)(strPackage[Index + 9] << 8 | strPackage[Index + 10]);
- break;
- }
- case 0x03:
- {
- int SF_standbycurrent = (int)(strPackage[Index + 3] << 8 | strPackage[Index + 4]);
- int SF_maxcurrent = (int)(strPackage[Index + 5] << 8 | strPackage[Index + 6]);
- int LF_standbycurrent = (int)(strPackage[Index + 7] << 8 | strPackage[Index + 8]);
- int LF_maxcurrent = (int)(strPackage[Index + 9] << 8 | strPackage[Index + 10]);
- break;
- }
- case 0x04:
- {
- int HUWarning = (int)(strPackage[Index + 3]);
- int HULimit = (int)(strPackage[Index + 4]);
- break;
- }
- case 0x05:
- {
- int maxTubeKv = (int)(strPackage[Index + 3]);
- int max_SF_TubecurrentMA = (int)(strPackage[Index + 4] << 8 | strPackage[Index + 5]);
- int max_LF_TubecurrentMA = (int)(strPackage[Index + 6] << 8 | strPackage[Index + 7]);
- break;
- }
- case 0xA2:
- {
- int SF_LS_MaxPower = (int)(strPackage[Index + 3] << 8 | strPackage[Index + 4]);
- int LF_LS_MaxPower = (int)(strPackage[Index + 5] << 8 | strPackage[Index + 6]);
- int SF_HS_MaxPower = (int)(strPackage[Index + 7] << 8 | strPackage[Index + 8]);
- int LF_HS_MaxPower = (int)(strPackage[Index + 9] << 8 | strPackage[Index + 10]);
- break;
- }
- case 0xA3:
- {
- int SF_standbycurrent = (int)(strPackage[Index + 3] << 8 | strPackage[Index + 4]);
- int SF_maxcurrent = (int)(strPackage[Index + 5] << 8 | strPackage[Index + 6]);
- int LF_standbycurrent = (int)(strPackage[Index + 7] << 8 | strPackage[Index + 8]);
- int LF_maxcurrent = (int)(strPackage[Index + 9] << 8 | strPackage[Index + 10]);
- break;
- }
- case 0xA4:
- {
- int HUWarning = (int)(strPackage[Index + 3]);
- int HULimit = (int)(strPackage[Index + 4]);
- break;
- }
- case 0xA5:
- {
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x63:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x01:
- {
- break;
- }
- case 0x02:
- {
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x64:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x01:
- {
- /*
- 0x00 = INITIAL
- 0x01 = STANDBY
- 0x02 = READY
- 0x03 = OPERATE
- 0x04 = SHUTDOWN
- 0x05 = CALIBRATION
- 0x06 = SEASON
- */
- //6401
- int nGenStatus = (int)(strPackage[Index + 3]);
- if (0 == nGenStatus)
- {
- FINFO("[64 01 01]:GENERATOR_STATUS_INIT");
- m_DoseUnit.m_GenState->Update(AttrKey::GENERATOR_STATUS::GENERATOR_STATUS_INIT);
- FireNotify(m_DoseUnit.m_GenState->GetKey(), m_DoseUnit.m_GenState->JSGet());
- }
- else if (1 == nGenStatus)
- {
- FINFO("[64 01 01]:GENERATOR_STATUS_STANDBY");
- m_DoseUnit.m_GenState->Update(AttrKey::GENERATOR_STATUS::GENERATOR_STATUS_STANDBY);
- FireNotify(m_DoseUnit.m_GenState->GetKey(), m_DoseUnit.m_GenState->JSGet());
- }
- else if (2 == nGenStatus)
- {
- FINFO("[64 01 02]: GENERATOR_STATUS_STANDBY");
- m_DoseUnit.m_GenState->Update(AttrKey::GENERATOR_STATUS::GENERATOR_STATUS_STANDBY);
- FireNotify(m_DoseUnit.m_GenState->GetKey(), m_DoseUnit.m_GenState->JSGet());
- }
- else if (3 == nGenStatus)
- {
- FINFO("[64 01 03]: GENERATOR_STATUS_EXP");
- m_DoseUnit.m_GenState->Update(AttrKey::GENERATOR_STATUS::GENERATOR_STATUS_EXP);
- FireNotify(m_DoseUnit.m_GenState->GetKey(), m_DoseUnit.m_GenState->JSGet());
- }
- else if (4 == nGenStatus)
- {
- FINFO("[64 01 04]: GENERATOR_STATUS_SHUTDOWN");
- m_DoseUnit.m_GenState->Update(AttrKey::GENERATOR_STATUS::GENERATOR_STATUS_SHUTDOWN);
- FireNotify(m_DoseUnit.m_GenState->GetKey(), m_DoseUnit.m_GenState->JSGet());
- }
- else if (5 == nGenStatus)
- {
- FINFO("[64 01 05]: GENERATOR_STATUS_CALIBRATION");
- m_DoseUnit.m_GenState->Update(AttrKey::GENERATOR_STATUS::GENERATOR_STATUS_CALIBRATION);
- FireNotify(m_DoseUnit.m_GenState->GetKey(), m_DoseUnit.m_GenState->JSGet());
- }
- else if (6 == nGenStatus)
- {
- FINFO("[64 01 06]: GENERATOR_STATUS_ERROR");
- m_DoseUnit.m_GenState->Update(AttrKey::GENERATOR_STATUS::GENERATOR_STATUS_ERROR);
- FireNotify(m_DoseUnit.m_GenState->GetKey(), m_DoseUnit.m_GenState->JSGet());
- }
- break;
- }
- case 0x02:
- {
- break;
- }
- case 0x03:
- {
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x65:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x01:
- {
- //6501
- //kv
- int postKv = (BYTE)(strPackage[Index + 3]) << 8 + (BYTE)strPackage[Index + 4];
- m_DoseUnit.m_PostKV->Update(postKv);
- FireNotify(m_DoseUnit.m_PostKV->GetKey(), m_DoseUnit.m_PostKV->JSGet());
- //ma
- int nPostMa = (BYTE)(strPackage[Index + 5]) << 8 + (BYTE)strPackage[Index + 6];
- float fpostMa = nPostMa / 10.0f;
- m_DoseUnit.m_PostMA->Update(fpostMa);
- FireNotify(m_DoseUnit.m_PostMA->GetKey(), m_DoseUnit.m_PostMA->JSGet());
- //ap-postmas
- int nPostMas = (BYTE)(strPackage[Index + 7]) << 16 + (BYTE)strPackage[Index + 8] << 8 + (BYTE)strPackage[Index + 9];
- float fpostMAS = nPostMas / 100.0f;
- m_DoseUnit.m_PostMAS->Update(fpostMAS);
- FireNotify(m_DoseUnit.m_PostMAS->GetKey(), m_DoseUnit.m_PostMAS->JSGet());
- //at-postms
- int nPostMs = (BYTE)(strPackage[Index + 10]) << 16 + (BYTE)strPackage[Index + 11] << 8 + (BYTE)strPackage[Index + 12];
- float fpostMS = nPostMs / 10.0f;
- m_DoseUnit.m_PostMS->Update(fpostMS);
- FireNotify(m_DoseUnit.m_PostMS->GetKey(), m_DoseUnit.m_PostMS->JSGet());
- FINFO("[65 01]: post{$}kv, post{$}ma, post{$}mas, post{$}Ms", postKv, fpostMa, fpostMAS, fpostMS);
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x6B:
- {
- }
- break;
- case 0x6C:
- {
- int soc = (BYTE)(strPackage[Index + 3]) << 8 + (BYTE)strPackage[Index + 4];
- int vol = (BYTE)(strPackage[Index + 5]) << 8 + (BYTE)strPackage[Index + 6];
- int charge = (BYTE)(strPackage[Index + 7]) << 8 + (BYTE)strPackage[Index + 8];
- int temperature = (BYTE)(strPackage[Index + 9]) << 8 + (BYTE)strPackage[Index + 10];
- int ac = (BYTE)strPackage[Index + 11];
- }
- break;
- case 0x6E:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x01:
- case 0xA1:
- {
- //6EA1
- break;
- }
- case 0x02:
- case 0xA2:
- {
- //6EA2
- //此命令比较特殊,切换为胶片模式,需要把下面俩值都设置为0.
- int nDetector1SynMode = (int)(strPackage[Index + 3]);
- int nDetector2SynMode = (int)(strPackage[Index + 4]);
- if (nDetector1SynMode == 0 && nDetector2SynMode == 0)//no detector.
- {
- // m_nWS = WSGen2UI(m_DoseUnit.m_WS->Get());
- //::PostMessage(this->m_hWnd, MSG_GEN_PARAM, GEN_PARAM_WS, m_nWS);//
- //logfile->WriteLog("6E A2:ws convertion mode", LOG_INFORMATION, LOG_DEBUG, true);
- }
- break;
- }
- default:
- break;
- }
- break;
- }
- default:
- break;
- }
- }
- bool nsGEN::DeltaDevice::DecodeFrame(const char* strPackage, int nLength)
- {
- if (strPackage == nullptr || nLength <= 0) {
- FINFO("strPackage: nullptr, nLength: <= 0");
- return false;
- }
- // 使用互斥锁保护缓冲区访问
- std::lock_guard<std::mutex> lock(m_bufferMutex);
- char strSendCommand[10] = { 0 };
- string str = "";
- int PacketLength = 0;
- for (int i = 0; i < nLength; i++)
- {
- snprintf(strSendCommand, sizeof(strSendCommand), "%02X", (BYTE)strPackage[i]);
- str += strSendCommand;
- str += ",";
- }
- FINFO("==IN== {$}", str);
- // 将新数据追加到缓冲区
- if (m_bufferLength + nLength > sizeof(m_buffer)) {
- FINFO("Buffer overflow, resetting buffer!");
- m_bufferLength = 0;
- return false;
- }
- std::memcpy(m_buffer + m_bufferLength, strPackage, nLength);
- m_bufferLength += nLength;
- int index = 0;
- while (index < m_bufferLength) {
- str = ""; // 清空 str 字符串
- // 规则 1:F0 开头,88 结尾,长度为 13
- if (index + 12 < m_bufferLength && static_cast<uint8_t>(m_buffer[index]) == 0xF0 && static_cast<uint8_t>(m_buffer[index + 12]) == 0x88) {
- for (int i = 0; i < 13; ++i) {
- snprintf(strSendCommand, sizeof(strSendCommand), "%02X", (BYTE)m_buffer[index + i]);
- str += strSendCommand;
- str += ",";
- }
- FINFO("Rule 1: ==IN== {$}", str);
- ProcessCommand(strPackage, index, index + 13);
- index += 13;
- }
- // 规则 2:F0 开头,88 结尾,长度为 19
- else if (index + 18 < m_bufferLength && static_cast<uint8_t>(m_buffer[index]) == 0xF0 && static_cast<uint8_t>(m_buffer[index + 18]) == 0x88) {
- for (int i = 0; i < 19; ++i) {
- snprintf(strSendCommand, sizeof(strSendCommand), "%02X", (BYTE)m_buffer[index + i]);
- str += strSendCommand;
- str += ",";
- }
- FINFO("Rule 2: ==IN== {$}", str);
- ProcessCommand(strPackage, index, index + 19);
- index += 19;
- }
- // 规则 3:以 0D 结尾,指令包含 0D 和 0D 前面的三个字符
- else if (index >= 3 && static_cast<uint8_t>(m_buffer[index]) == 0x0D) {
- for (int i = 0; i < 4; ++i) {
- snprintf(strSendCommand, sizeof(strSendCommand), "%02X", (BYTE)m_buffer[index - 3 + i]);
- str += strSendCommand;
- str += ",";
- }
- FINFO("Rule 3: ==IN== {$}", str);
- ProcessCommand(strPackage, index - 3, index + 1);
- index++;
- }
- else {
- index++;
- }
- }
- // 移除已处理的数据
- int processedLength = index;
- std::memmove(m_buffer, m_buffer + processedLength, m_bufferLength - processedLength);
- m_bufferLength -= processedLength;
- return true;
- }
- bool nsGEN::DeltaDevice::ChangeGenParam(int kv, float fma, float fms, float fmas)
- {
- FINFO("KV: {$}, MA: {$}, MS: {$}, MAS: {$}", kv, fma, fms, fmas);
- if (m_DoseUnit.m_Techmode->Get() == 0)
- {
- SetRADKV_MA_MS(kv, fma, fms);
- }
- else if (m_DoseUnit.m_Techmode->Get() == 1)
- {
- SetRADKV_MAS(kv, fmas);
- }
- else if (m_DoseUnit.m_Techmode->Get() == 2)
- {
- if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::TABLE)
- {
- if (m_nTableUsePanelAEC == 1)
- {
- SetRADKV_MA_MS(kv, fma, fms);
- }
- else
- {
- SetAECKV_MA_MS(kv, fma, fms);
- }
- }
- else if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::WALL)
- {
- if (m_nWallUsePanelAEC == 1)
- {
- SetRADKV_MA_MS(kv, fma, fms);
- }
- else
- {
- SetAECKV_MA_MS(kv, fma, fms);
- }
- }
- else if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::MOBILE)
- {
- if (m_nFreeUsePanelAEC == 1)
- {
- SetRADKV_MA_MS(kv, fma, fms);
- }
- else
- {
- SetAECKV_MA_MS(kv, fma, fms);
- }
- }
- }
- return true;
- }
- //F0 6E A2 01 01 00 00 00 00 00 00 00 00 00 00 00 6C 00 88 发送消息
- bool nsGEN::DeltaDevice::SetRADKV_MA_MS(int kv, float ma, float ms)
- {
- FINFO("[0xF0, 0x56, 0xA1]: KV: {$}, MA: {$}, MS: {$}", kv, ma, ms);
- char cmdbuf[20] = { 0xF0, 0x56, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7A, 0x00, 0x88 };
- cmdbuf[3] = kv;
- //确保ma合理
- int posMA = GetFacFloatValue(m_vecMA, ma);//找到之后,再缩小10倍,写入数据帧
- int nTemp = ma * 10;
- cmdbuf[4] = nTemp >> 8;
- cmdbuf[5] = nTemp % 256;
- //确保ms合理
- int posMS = GetFacFloatValue(m_vecMS, ms);
- nTemp = ms * 10;
- cmdbuf[6] = nTemp >> 16;
- cmdbuf[7] = nTemp >> 8;
- cmdbuf[8] = nTemp % 256;
- FormatCommand(cmdbuf, 13);
- string temp(cmdbuf, 13);
- m_strCommand = temp;
- HWSend(m_strCommand.c_str(), m_strCommand.length());
- return true;
- }
- bool nsGEN::DeltaDevice::SetRADKV_MAS(int kv, float mas)
- {
- //57A1
- FINFO("[0xF0, 0x57, 0xA1]:KV: {$}, MAS: {$}", kv, mas);
- char cmdbuf[13] = { 0xF0, 0x57, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7A, 0x00, 0x88 };
- cmdbuf[3] = kv;
- //确保mas合理
- int posMAS = GetFacFloatValue(m_vecMAS, mas);
- //设置mas指令中的数= 实际想要下发的数*100
- int nTemp = mas * 100;
- cmdbuf[6] = nTemp >> 16;
- cmdbuf[7] = nTemp >> 8;
- cmdbuf[8] = nTemp % 256;
- FormatCommand(cmdbuf, 13);
- string temp(cmdbuf, 13);
- m_strCommand = temp;
- HWSend(m_strCommand.c_str(), m_strCommand.length());
- return true;
- }
- bool nsGEN::DeltaDevice::SetAECKV_MA_MS(int kv, float ma, float ms)
- {
- //55A2
- FINFO("[0xF0, 0x55, 0xA2]: KV: {$}, MA; {$}, MS: {$}", kv, ma, ms);
- char cmdbuf[13] = { 0xF0, 0x55, 0xA2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9C, 0x00, 0x88 };
- cmdbuf[3] = kv;
- //确保ma合理
- int posMA = GetFacFloatValue(m_vecMA, ma);
- int nTemp = ma *10;
- cmdbuf[4] = nTemp >> 8;
- cmdbuf[5] = nTemp % 256;
- //确保ms合理
- int posMS = GetFacFloatValue(m_vecMS, ms);
- nTemp = ms * 10;
- cmdbuf[6] = nTemp >> 16;
- cmdbuf[7] = nTemp >> 8;
- cmdbuf[8] = nTemp % 256;
- FormatCommand(cmdbuf, 13);
- string temp(cmdbuf, 13);
- m_strCommand = temp;
- HWSend(m_strCommand.c_str(), m_strCommand.length());
- return true;
- }
- bool nsGEN::DeltaDevice::SetAECInformation(int chamber, int field, int density, int film)
- {
- FINFO("[0xF0, 0x55, 0xA1]: chamber: {$}, field: {$}, density: {$}, film: {$}", chamber, field, density, film);
- char cmdbuf[13] = { 0xF0, 0x55, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9C, 0x00, 0x88 };
- cmdbuf[3] = chamber;
- //field转换
- switch (field)
- {
- case 1:
- cmdbuf[4] = 0x04;
- break;
- case 10:
- cmdbuf[4] = 0x02;
- break;
- case 100:
- cmdbuf[4] = 0x01;
- break;
- case 101:
- cmdbuf[4] = 0x05;
- break;
- case 110:
- cmdbuf[4] = 0x03;
- break;
- case 11:
- cmdbuf[4] = 0x06;
- break;
- case 111:
- cmdbuf[4] = 0x07;
- break;
- default:
- break;
- }
- //density转换
- switch (density)
- {
- case -3:
- cmdbuf[5] = 0;
- break;
- case -2:
- cmdbuf[5] = 1;
- break;
- case -1:
- cmdbuf[5] = 2;
- break;
- case 0:
- cmdbuf[5] = 3;
- break;
- case 1:
- cmdbuf[5] = 4;
- break;
- case 2:
- cmdbuf[5] = 5;
- break;
- case 3:
- cmdbuf[5] = 6;
- break;
- default:
- cmdbuf[5] = 0;
- break;
- }
- if (film > 3)
- {
- film = 3;
- }
- cmdbuf[6] = 0;
- FormatCommand(cmdbuf, 13);
- string temp(cmdbuf, 13);
- m_strCommand = temp;
- HWSend(m_strCommand.c_str(), m_strCommand.length());
- return true;
- }
- //int nsGEN::DeltaDevice::GetFacValue(vector<int> Index, int& value)
- //{
- // int nlength = static_cast <int>(Index.size());
- // if (nlength == 0)
- // {
- // return -1;
- // }
- //
- // int nPos = 0;
- // int nValue = 0;
- // for (int i = 0; i < nlength; i++)
- // {
- // if (value == Index[i])
- // {
- // nPos = i;
- // break;
- // }
- // else if (i == nlength - 1)
- // {
- // nPos = i;
- // break;
- // }
- // else if ((value > Index[i]) && (value < Index[i + 1]))
- // {
- // nPos = (abs(value - Index[i + 1]) > abs(value - Index[i])) ? i : (i + 1);//就近原则
- // break;
- // }
- // else if (value < Index[0])
- // {
- // nPos = 0;
- // break;
- // }
- // }
- // value = Index[nPos];
- // return nPos;
- //}
- int CCOS::Dev::Detail::Generator::DeltaDevice::GetFacFloatValue(vector<float> Index, float& value)
- {
- int nlength = static_cast <int>(Index.size());
- if (nlength == 0)
- {
- return -1;
- }
- int nPos = 0;
- int nValue = 0;
- for (int i = 0; i < nlength; i++)
- {
- if (value == Index[i])
- {
- nPos = i;
- break;
- }
- else if (i == nlength - 1)
- {
- nPos = i;
- break;
- }
- else if ((value > Index[i]) && (value < Index[i + 1]))
- {
- nPos = (abs(value - Index[i + 1]) > abs(value - Index[i])) ? i : (i + 1);//就近原则
- break;
- }
- else if (value < Index[0])
- {
- nPos = 0;
- break;
- }
- }
- value = Index[nPos];
- return nPos;
- }
- bool nsGEN::DeltaDevice::SetRadMode(int radmode, int desmode)
- {
- FINFO("[0xF0, 0x54, 0xA1]: RadMode: {$}, desmode: {$}", radmode, desmode);
- char cmdbuf[13] = { 0xF0, 0x54, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7A, 0x00, 0x88 };
- cmdbuf[3] = radmode;
- cmdbuf[4] = desmode;
- FormatCommand(cmdbuf, 13);
- string temp(cmdbuf, 13);
- m_strCommand = temp;
- HWSend(m_strCommand.c_str(), m_strCommand.length());
- return true;
- }
- std::string nsGEN::DeltaDevice::uint8ArrayToHexStr(const UINT8* array, size_t length)
- {
- std::ostringstream ss;
- ss << std::hex << std::setfill('0'); // 设置十六进制格式和填充字符
- for (size_t i = 0; i < length; ++i) {
- ss << std::setw(2) << static_cast<int>(array[i]) << ' '; // 转换为int以支持十六进制输出,并设置宽度为2
- }
- return ss.str(); // 返回转换后的字符串
- }
- bool nsGEN::DeltaDevice::SetDAECEnable(int enable)
- {
- if (enable)
- {
- FINFO("[0xF0, 0x61, 0xAC, 0x01]: DAECEnable: {$}", enable);
- char cmdbuf[19] = { 0xF0, 0x61, 0xAC, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0xDB, 0x00, 0x88 };
- FormatCommand(cmdbuf, 19);
- string temp(cmdbuf, 19);
- m_strCommand = temp;
- HWSend(m_strCommand.c_str(), m_strCommand.length());
- }
- else
- {
- FINFO("[0xF0, 0x61, 0xAC, 0x02]: DAECEnable: {$}", enable);
- char cmdbuf[19] = { 0xF0, 0x61, 0xAC, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0x00, 0x88 };
- FormatCommand(cmdbuf, 19);
- string temp(cmdbuf, 19);
- m_strCommand = temp;
- HWSend(m_strCommand.c_str(), m_strCommand.length());
- }
- return true;
- }
- int nsGEN::DeltaDevice::WSGen2UI(int InputWS)
- {
- int OutputWS = -1;
- //if (m_nSettingWS == GEN_WS_TABLE) //table lying
- //{
- // if (InputWS == GenConfig.m_nGenWSLying)
- // {
- // OutputWS = GEN_WS_TABLE;
- // }
- //}
- //else if (m_nSettingWS == GEN_WS_WALL) //table standing
- //{
- // if (InputWS == GenConfig.m_nGenWSStand)
- // {
- // OutputWS = GEN_WS_WALL;
- // }
- //}
- //else if (m_nSettingWS == GEN_WS_CONVENTIONAL)
- //{
- // if (InputWS == GenConfig.m_nGenWSConventional)
- // {
- // OutputWS = GEN_WS_CONVENTIONAL;
- // }
- //}
- //else if (m_nSettingWS == GEN_WS_MOBILE) //Free ws
- //{
- // if (InputWS == GenConfig.m_nGenWSFree)
- // {
- // OutputWS = GEN_WS_MOBILE;
- // }
- //}
- //else if (m_nSettingWS == GEN_WS_TOMO)
- //{
- // if (InputWS == GenConfig.m_nGenWSTomo)
- // {
- // OutputWS = GEN_WS_TOMO;
- // }
- //}
- //else
- //{
- // this->logfile->WriteLog("Input WS is wrong", LOG_INFORMATION, LOG_DEBUG, true);
- //}
- //if (OutputWS < 0)
- //{
- // this->logfile->WriteLog("Seting WS is different with Geting WS!", LOG_INFORMATION, LOG_DEBUG, true);
- // if (InputWS == GenConfig.m_nGenWSLying)
- // {
- // OutputWS = GEN_WS_TABLE;
- // }
- // else if (InputWS == GenConfig.m_nGenWSStand)
- // {
- // OutputWS = GEN_WS_WALL;
- // }
- // else if (InputWS == GenConfig.m_nGenWSConventional)
- // {
- // OutputWS = GEN_WS_CONVENTIONAL;
- // }
- // else if (InputWS == GenConfig.m_nGenWSFree)
- // {
- // OutputWS = GEN_WS_MOBILE;
- // }
- // else if (InputWS == GenConfig.m_nGenWSTomo)
- // {
- // OutputWS = GEN_WS_TOMO;
- // }
- // else
- // {
- // //OutputWS = GEN_WS_TABLE;
- // OutputWS = -1;
- // this->logfile->WriteLog("Geting WS is wrong", LOG_INFORMATION, LOG_DEBUG, true);
- // }
- //}
- return OutputWS;
- }
- //-----------------------------------------------------------------------------
- // DecodeFrame
- //-----------------------------------------------------------------------------
- static bool DecodeFrame(const char* strFrame, int length)
- {
- if (nsGEN::DeltaDevice::g_GenDevice)
- {
- nsGEN::DeltaDevice::g_GenDevice->DecodeFrame(strFrame, length);
- }
- return true;
- }
- bool nsGEN::DeltaDevice::GetLastExpParamenters(void)
- {
- FINFO("[0xF0, 0x65, 0x01]");
- char cmdbuf[19] = { 0xF0, 0x65, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCB, 0x00, 0x88 };
- FormatCommand(cmdbuf, 19);
- string temp(cmdbuf, 19);
- m_strCommand = temp;
- HWSend(m_strCommand.c_str(), m_strCommand.length());
- return true;
- }
- int nsGEN::DeltaDevice::FormatCommand(char* buf, int len)
- {
- if (len < 4)
- {
- return -1;
- }
- UINT8 crc = GetCRC8(buf + 1, len - 4);
- buf[len - 3] = crc;
- return crc;
- }
- void nsGEN::DeltaDevice::RetrieveFirewareVersion()
- {
- FINFO("[0xF0, 0x61, 0x01, 0x00]");
- char cmdbuf[19] = { 0xF0, 0x61, 0x01, 0x00, 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00, 0x00, 0x00, 0x00, 0x88 };
- FormatCommand(cmdbuf, 19);
- string temp(cmdbuf, 19);
- m_strCommand = temp;
- HWSend(m_strCommand.c_str(), m_strCommand.length());
- }
- std::string nsGEN::DeltaDevice::GetFileVersion(std::string strFilePathName)
- {
- // Linux下动态库没有Windows风格的版本资源
- // 返回固定版本号或从CMake定义的宏获取
- #ifdef PROJECT_VERSION
- return PROJECT_VERSION;
- #else
- // 返回默认版本号
- FINFO("Getting version for file: {$}", strFilePathName.c_str());
- return "1.0.0";
- #endif
- }
- //"HWS": "1",
- //"CMD" : "2",
- //"FRE" : "3"
- RET_STATUS nsGEN::DeltaDevice::ActiveSyncMode(_tSyncModeArgs value)
- {
- m_cfgCurrentWSSYN = value;
- FINFO("WS: {$}, SyncMode: {$}, SyncValue: {$}", m_cfgCurrentWSSYN.strWS, m_cfgCurrentWSSYN.strSyncMode, m_cfgCurrentWSSYN.strSyncValue);
- if (m_cfgCurrentWSSYN.strWS == "Free")
- {
- SetNoDrMode();
- }
- else
- {
- if (m_cfgCurrentWSSYN.strSyncMode == "FRE")
- {
- SetNoDrMode();
- }
- else
- {
- SetSyncOutMode();
- //if (m_cfgCurrentWSSYN.strWS == "Table")
- //{
- SeleckDetectorNumber(1);
- //}
- //else
- //{
- //SeleckDetectorNumber(2);
- //}
- }
- }
- return RET_STATUS::RET_SUCCEED;
- }
- void nsGEN::DeltaDevice::SetNoDrMode()
- {
- FINFO("[0xF0, 0x6E, 0xA2, 0x00]");
- char cmdbuf[20] = { 0xF0, 0x6E, 0xA2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA5, 0x00, 0x88 };
- FormatCommand(cmdbuf, 19);
- string temp(cmdbuf, 19);
- m_strCommand = temp;
- HWSend(m_strCommand.c_str(), m_strCommand.length());
- }
- void nsGEN::DeltaDevice::SetSyncOutMode()
- {
- FINFO("[0xF0, 0x6E, 0xA2, 0x01]");
- char cmdbuf[20] = { 0xF0, 0x6E, 0xA2, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6C, 0x00, 0x88 };
- FormatCommand(cmdbuf, 19);
- string temp(cmdbuf, 19);
- m_strCommand = temp;
- HWSend(m_strCommand.c_str(), m_strCommand.length());
- }
- void nsGEN::DeltaDevice::SeleckDetectorNumber(int detectorID)
- {
- FINFO("[0xF0, 0x6E, 0xA1, 0x0{$}]", detectorID);
- char cmdbuf[20] = { 0xF0, 0x6E, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0x00, 0x88 };
- cmdbuf[3] = detectorID;
- FormatCommand(cmdbuf, 19);
- string temp(cmdbuf, 19);
- m_strCommand = temp;
- HWSend(m_strCommand.c_str(), m_strCommand.length());
- }
- /*下面的线程函数,其实用来充当定时器功能。*/
- bool nsGEN::DeltaDevice::StartHardwareStatusThread()
- {
- FDEBUG("Enter StartHardwareStatusThread");
- try {
- m_pHardwareStatusThread = std::thread(HardwareStatusThread, this);
- FINFO("HardwareStatus Thread started successfully");
- return true;
- }
- catch (const std::exception& e) {
- FERROR("Start HardwareStatus Thread Failed: {$}", e.what());
- return false;
- }
- }
- void nsGEN::DeltaDevice::HardwareStatusThread(DeltaDevice* pParam)
- {
- FDEBUG("Enter HardwareStatusThread");
- DeltaDevice* pCurGen = pParam;
- if (pCurGen == NULL)
- {
- FERROR("HardwareStatusThread: pCurGen is NULL");
- return;
- }
- if (pCurGen->m_GenConfig.GetFirstOf("loopTime") >= 0)
- {
- if ((int)pCurGen->m_GenConfig["loopTime"] >= 100)
- {
- pCurGen->m_iLoopTime = (int)pCurGen->m_GenConfig["loopTime"];
- }
- }
- FINFO("loopTime = {$}", pCurGen->m_iLoopTime.load());
- while (pCurGen->m_bExtraFlag)
- {
- int currtTime = pCurGen->m_iLoopTime;
- Sleep(currtTime);
- if (!pCurGen->m_bExtraFlag) break;
- if (pCurGen->m_nProcessXrayon == false)
- {
- pCurGen->RetrieveHU();
- pCurGen->CheckGeneratorStatus();
- FINFO("ConnectStatus: {$}", pCurGen->m_bReconnect);
- if (!pCurGen->m_bSetAPR)
- {
- pCurGen->m_tAPRdata.nWS = pCurGen->m_DoseUnit.m_WS->Get();
- pCurGen->m_tAPRdata.nTechmode = pCurGen->m_DoseUnit.m_Techmode->Get();
- pCurGen->m_tAPRdata.nFocus = pCurGen->m_DoseUnit.m_Focus->Get();
- pCurGen->m_tAPRdata.fKV = pCurGen->m_DoseUnit.m_KV->Get();
- pCurGen->m_tAPRdata.fMA = pCurGen->m_DoseUnit.m_MA->Get();
- pCurGen->m_tAPRdata.fMS = pCurGen->m_DoseUnit.m_MS->Get();
- pCurGen->m_tAPRdata.fMAS = pCurGen->m_DoseUnit.m_MAS->Get();
- pCurGen->m_tAPRdata.nAECDensity = pCurGen->m_DoseUnit.m_AECDensity->Get();
- pCurGen->m_tAPRdata.nAECFilm = pCurGen->m_DoseUnit.m_AECFilm->Get();
- pCurGen->m_tAPRdata.nAECField = pCurGen->m_DoseUnit.m_AECField->Get();
- pCurGen->SetAPR(pCurGen->m_tAPRdata);
- }
- m_nCountTimes++;
- if (m_nCountTimes >= 25)
- {
- char ErrCode[20];
- snprintf(ErrCode, sizeof(ErrCode), "DELTA_ERR_%04d", 0);
- FINFO("{$}", ErrCode);
- int level = DELTA_ABNORMAL_LEVEL::REG_ERRO;
- auto iterr = pCurGen->m_ErrorMessages.find(ErrCode);
- if (iterr != pCurGen->m_ErrorMessages.end())
- {
- pCurGen->m_bReconnect = true;
- pCurGen->m_MSGUnit->AddErrorMessage(ErrCode, level, iterr->second.c_str());
- FERROR("Critical error detected, exiting...");
- // Note: 不建议在库代码中调用exit(),改为设置错误状态
- // exit(0);
- }
- }
- }
- }
- FINFO("HardwareStatusThread exiting...");
- }
- void CCOS::Dev::Detail::Generator::DeltaDevice::RetrieveHU()
- {
- if (!m_nProcessXrayon)
- {
- FINFO("[0xF0, 0x5F, 0x01]");
- char cmdbuf[13] = { 0xF0, 0x5F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x25, 0x00, 0x88 };
- FormatCommand(cmdbuf, 13);
- string temp(cmdbuf, 13);
- m_strCommand = temp;
- HWSend(m_strCommand.c_str(), m_strCommand.length());
- }
- else
- {
- FINFO("Xrayon Processing Dont RetrieveHU");
- }
- }
- void CCOS::Dev::Detail::Generator::DeltaDevice::CheckGeneratorStatus()
- {
- if (!m_nProcessXrayon)
- {
- FINFO("[0xF0, 0x64, 0x01]");
- char cmdbuf[19] = { 0xF0, 0x64, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x88 };
- FormatCommand(cmdbuf, 19);
- string temp(cmdbuf, 19);
- m_strCommand = temp;
- HWSend(m_strCommand.c_str(), m_strCommand.length());
- }
- else
- {
- FINFO("Xrayon Processing Dont CheckGeneratorStatus");
- }
- }
- void CCOS::Dev::Detail::Generator::DeltaDevice::RetrieveMaxRating()
- {
- //6104
- FINFO("[0xF0, 0x61, 0x04]");
- char cmdbuf[19] = { 0xF0, 0x61, 0x04, 0x00, 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00, 0x00, 0x00, 0x00, 0x88 };
- FormatCommand(cmdbuf, 19);
- string temp(cmdbuf, 19);
- m_strCommand = temp;
- HWSend(m_strCommand.c_str(), m_strCommand.length());
- }
- void CCOS::Dev::Detail::Generator::DeltaDevice::UpdataAECInformation(AECINFORM aec)
- {
- switch (aec.Field)
- {
- case 1:
- m_DoseUnit.m_AECField->Update(AttrKey::AEC_100);
- break;
- case 2:
- m_DoseUnit.m_AECField->Update(AttrKey::AEC_010);
- break;
- case 3:
- m_DoseUnit.m_AECField->Update(AttrKey::AEC_110);
- break;
- case 4:
- m_DoseUnit.m_AECField->Update(AttrKey::AEC_001);
- break;
- case 5:
- m_DoseUnit.m_AECField->Update(AttrKey::AEC_101);
- break;
- case 6:
- m_DoseUnit.m_AECField->Update(AttrKey::AEC_010);
- break;
- case 7:
- m_DoseUnit.m_AECField->Update(AttrKey::AEC_111);
- break;
- default:
- m_DoseUnit.m_AECField->Update(AttrKey::AEC_010);
- break;
- }
- FireNotify(m_DoseUnit.m_AECField->GetKey(), m_DoseUnit.m_AECField->JSGet());
- FINFO("AEC: field: {$}", m_DoseUnit.m_AECField->GetKey());
- //density
- switch (aec.Density)
- {
- case 0:
- m_DoseUnit.m_AECDensity->Update(-3);
- break;
- case 1:
- m_DoseUnit.m_AECDensity->Update(-2);
- break;
- case 2:
- m_DoseUnit.m_AECDensity->Update(-1);
- break;
- case 3:
- m_DoseUnit.m_AECDensity->Update(0);
- break;
- case 4:
- m_DoseUnit.m_AECDensity->Update(1);
- break;
- case 5:
- m_DoseUnit.m_AECDensity->Update(2);
- break;
- case 6:
- m_DoseUnit.m_AECDensity->Update(3);
- break;
- default:
- m_DoseUnit.m_AECDensity->Update(0);
- break;
- }
- FireNotify(m_DoseUnit.m_AECDensity->GetKey(), m_DoseUnit.m_AECDensity->JSGet());
- FINFO("AEC: Density: {$}", m_DoseUnit.m_AECDensity->GetKey());
- //film --->ysj++ �Ƿ���Ҫת������
- int nAECFilmSpeed = 0;
- switch (aec.FilmScreenSpeed)
- {
- case 0:
- nAECFilmSpeed = 100;
- break;
- case 1:
- nAECFilmSpeed = 200;
- break;
- case 2:
- nAECFilmSpeed = 400;
- break;
- case 3:
- nAECFilmSpeed = 800;
- break;
- default:
- break;
- }
- m_DoseUnit.m_AECFilm->Update(nAECFilmSpeed);
- FireNotify(m_DoseUnit.m_AECFilm->GetKey(), m_DoseUnit.m_AECFilm->JSGet());
- FINFO("AEC: Film: {$}", m_DoseUnit.m_AECFilm->GetKey());
- }
- void CCOS::Dev::Detail::Generator::DeltaDevice::RetrieveGeneratroDerating()
- {
- //6105
- FINFO("[0xF0, 0x61, 0x05]");
- char cmdbuf[19] = { 0xF0, 0x61, 0x05, 0x00, 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00, 0x00, 0x00, 0x00, 0x88 };
- FormatCommand(cmdbuf, 19);
- string temp(cmdbuf, 19);
- m_strCommand = temp;
- HWSend(m_strCommand.c_str(), m_strCommand.length());
- }
- bool CCOS::Dev::Detail::Generator::DeltaDevice::LoadConfig(string configfile)
- {
- std::ifstream file(configfile);
- if (!file) {
- FINFO("Config file does not exist: {$}", configfile.c_str());
- return false;
- }
- if (m_bLoadConfigFile)
- {
- FINFO("Configuration already loaded");
- return true;
- }
- m_strConfigPath = configfile;
- ResDataObject temp;
- temp.loadFile(m_strConfigPath.c_str());
- m_GenConfig = temp["CONFIGURATION"];
- TransJsonText(m_GenConfig);
- GetConfData();
- m_bLoadConfigFile = true;
- return true;
- }
- int CCOS::Dev::Detail::Generator::DeltaDevice::GetGenState()
- {
- if (m_DoseUnit.m_GenState != NULL)
- {
- return m_DoseUnit.m_GenState->Get();
- }
- else
- {
- return 0;
- }
- }
- string CCOS::Dev::Detail::Generator::DeltaDevice::AnalysisCommand(int number, const char* chdigital, int type)
- {
- string str = "";
- char arrChar[BYTE_4] = { 0 };
- for (int i = 0; i < number; i++)
- {
- if (type == TransToType::tochar)
- {
- //转成符号
- snprintf(arrChar, sizeof(arrChar) / sizeof(arrChar[0]), "%c", (BYTE)chdigital[i]);
- }
- else if (type == TransToType::toint)
- {
- //转成int数
- snprintf(arrChar, sizeof(arrChar) / sizeof(arrChar[0]), "%d", (BYTE)chdigital[i]);
- }
- else
- {
- //转成hex
- snprintf(arrChar, sizeof(arrChar) / sizeof(arrChar[0]), "%X", (BYTE)chdigital[i]);
- }
- str += arrChar;
- }
- return str;
- }
- //-----------------------------------------------------------------------------
- // DeltaDriver
- //-----------------------------------------------------------------------------
- nsGEN::DeltaDriver::DeltaDriver()
- {
- m_bDemoConnected = false;
- m_pAttribute.reset(new ResDataObject);
- m_pDescription.reset(new ResDataObject);
- }
- nsGEN::DeltaDriver::~DeltaDriver()
- {
- }
- auto nsGEN::DeltaDriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
- {
- FINFO("CreateDevice:{$}", index);
- try {
- if (!m_scfWrapper) {
- FERROR("SCFWrapper is null, cannot create device");
- return nullptr;
- }
- if (EventCenter == nullptr) {
- FERROR("EventCenter is null, cannot create device");
- return nullptr;
- }
- m_pDevice = new DeltaDevice(EventCenter, m_scfWrapper, m_ConfigFileName);
- if (!m_pDevice) {
- FERROR("Failed to create DeltaDevice instance");
- return nullptr;
- }
- auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDevice));
- if (!dev) {
- FERROR("Failed to create IODevice instance");
- delete m_pDevice;
- m_pDevice = nullptr;
- return nullptr;
- }
- FINFO("Device created successfully");
- return dev;
- }
- catch (const std::bad_alloc& e) {
- FERROR("Memory allocation failed in CreateDevice: {$}", e.what());
- if (m_pDevice) {
- delete m_pDevice;
- m_pDevice = nullptr;
- }
- return nullptr;
- }
- catch (const std::exception& e) {
- FERROR("Exception in CreateDevice: {$}", e.what());
- if (m_pDevice) {
- delete m_pDevice;
- m_pDevice = nullptr;
- }
- return nullptr;
- }
- }
- void nsGEN::DeltaDriver::FireNotify(int code, std::string key, std::string content)
- {
- EventCenter->OnNotify(code, key, content);
- }
- void nsGEN::DeltaDriver::Prepare()
- {
- FINFO("========================================");
- FINFO("DeltaDriver::Prepare() Starting...");
- FINFO("========================================");
- try {
- // 初始化日志系统
- std::string strLogPath = GetProcessDirectory() + R"(/Conf/log_config.xml)";
- std::string LogHost = "DevDelta";
- std::string moduleName = "DevDelta";
- FINFO("Initializing log module...");
- FINFO("Log config path: {$}", strLogPath.c_str());
- FINFO("Log host: {$}", LogHost.c_str());
- FINFO("Module name: {$}", moduleName.c_str());
- bool ret = initLogModule(
- LogHost, // 主机名(用于日志路径中的{host}占位符)
- moduleName, // 唯一模块名
- strLogPath, // 配置文件路径
- true // 是否输出到控制台(可选)
- );
- if (!ret) {
- std::cerr << "Log init failed!" << std::endl;
- FERROR("Failed to initialize log module");
- return;
- }
- FINFO("Log module initialized successfully");
- Delta_SetLocalModuleName(moduleName);
- FINFO("Getting connection DLL from config: {$}", m_ConfigFileName.c_str());
- m_SCFDllName = GetConnectDLL(m_ConfigFileName);
- FINFO("SCF DLL name: {$}", m_SCFDllName.c_str());
- FINFO("Calling parent Prepare()...");
- super::Prepare();
- FINFO("========================================");
- FINFO("DeltaDriver::Prepare() Completed");
- FINFO("========================================");
- }
- catch (const std::exception& e) {
- FERROR("Exception in Prepare: {$}", e.what());
- std::cerr << "Fatal error in Prepare: " << e.what() << std::endl;
- throw; // 重新抛出异常,因为Prepare失败应该阻止程序继续运行
- }
- }
- bool nsGEN::DeltaDriver::Connect()
- {
- FINFO("Enter DeltaDriver::Connect()");
- FINFO("ConfigFileName: {$}", m_ConfigFileName.c_str());
- std::lock_guard<std::mutex> lock(m_connectionMutex);
- const auto currentState = m_connectionState.load();
- auto now = std::chrono::steady_clock::now();
- // 1. 处理可重试的失败状态
- if (currentState == ConnectionState::Failed) {
- if ((now - m_lastConnectionAttempt) >= RETRY_INTERVAL && m_connectionRetryCount < MAX_RETRY_COUNT) {
- m_connectionState = ConnectionState::Disconnected;
- }
- else {
- return false; // 不满足重试条件,直接返回
- }
- }
- // 2. 检查无效状态(正在连接/已连接但实际有效)
- if (currentState == ConnectionState::Connecting) {
- FINFO("Already connecting");
- return true;
- }
- if (currentState == ConnectionState::Connected && m_scfWrapper && m_scfWrapper->IsConnected()) {
- FINFO("Already connected");
- return true;
- }
- // 3. 检查配置文件是否存在
- std::ifstream file(m_ConfigFileName);
- if (!file) {
- FINFO("{$} does not exist", m_ConfigFileName.c_str());
- return false;
- }
- ResDataObject connParam = GetConnectParam(m_ConfigFileName);
- std::string connInfo;
- try {
- // 如果是串口连接,使用当前索引的端口
- if (m_currentConnType == ConnectionType::Serial) {
- std::string currentPort = m_serialPorts[m_currentSerialPortIndex];
- connParam.update("port", currentPort.c_str());
- connInfo = "Serial (port: " + currentPort + ")";
- } else {
- // 网口连接:直接使用配置参数
- connInfo = "Ethernet (ip: " + std::string(connParam["ip"]) + ")";
- }
- FINFO("Enter Connect ({$}), config: {$}", connInfo, connParam.encode());
- m_connectionState = ConnectionState::Connecting;
- m_lastConnectionAttempt = now;
- // 创建SCFWrapper对象(如果尚未创建)
- if (!m_scfWrapper) {
- m_scfWrapper = std::make_shared<SCFWrapper>();
- }
- // 初始化SCF
- if (!m_scfWrapper->Initialize(m_SCFDllName)) {
- FINFO("SCF Init failed: {$}", m_scfWrapper->GetLastError());
- m_connectionState = ConnectionState::Failed;
- // 串口连接失败处理:尝试下一个端口
- if (m_currentConnType == ConnectionType::Serial) {
- int nextIndex = (m_currentSerialPortIndex + 1) % m_serialPorts.size();
- bool allPortsTried = (nextIndex == 0);
- if (!allPortsTried) {
- // 未遍历完所有端口:切换到下一端口,不增加重试计数
- m_currentSerialPortIndex = nextIndex;
- m_connectionRetryCount = 0;
- FINFO("Trying next serial port: {$}", m_serialPorts[nextIndex]);
- return false;
- } else {
- // 已遍历所有端口:重置到第一个端口,增加重试计数
- m_currentSerialPortIndex = 0;
- m_connectionRetryCount++;
- FINFO("All serial ports tried, retry count: {$}/{$}", m_connectionRetryCount, MAX_RETRY_COUNT);
- return false;
- }
- }
- m_connectionRetryCount++;
- return false;
- }
- // 设置数据接收回调
- m_scfWrapper->SetDataReceivedCallback([this](const char* data, uint32_t length) {
- this->Dequeue(data, length);
- });
- // 连接SCF
- auto erCode = m_scfWrapper->Connect(connParam, &nsGEN::DeltaDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
- if (erCode != SCF_SUCCEED || !m_scfWrapper->StartAutoReceive()) {
- FINFO("Connect failed (code: {$}) for {$}", erCode, connInfo);
- m_scfWrapper->Disconnect();
- m_connectionState = ConnectionState::Failed;
- // 串口连接失败处理:尝试下一个端口
- if (m_currentConnType == ConnectionType::Serial) {
- int nextIndex = (m_currentSerialPortIndex + 1) % m_serialPorts.size();
- bool allPortsTried = (nextIndex == 0);
- if (!allPortsTried) {
- // 未遍历完所有端口:切换到下一端口,不增加重试计数
- m_currentSerialPortIndex = nextIndex;
- m_connectionRetryCount = 0;
- FINFO("Trying next serial port: {$}", m_serialPorts[nextIndex]);
- return false;
- } else {
- // 已遍历所有端口:重置到第一个端口,增加重试计数
- m_currentSerialPortIndex = 0;
- m_connectionRetryCount++;
- FINFO("All serial ports tried, retry count: {$}/{$}", m_connectionRetryCount, MAX_RETRY_COUNT);
- return false;
- }
- }
- // 所有端口失败(串口)或网口失败,才增加总重试计数
- m_connectionRetryCount++;
- return false;
- }
- // 连接成功:重置状态
- m_connectionState = ConnectionState::Connected;
- m_connectionRetryCount = 0;
- m_currentSerialPortIndex = 0; // 重置串口端口索引
- FINFO("Connected successfully ({$})", connInfo);
- return true;
- }
- catch (const std::exception& e) {
- FINFO("Connect exception for {$}: {$}", connInfo, e.what());
- m_connectionState = ConnectionState::Failed;
- m_connectionRetryCount++;
- return false;
- }
- }
- void nsGEN::DeltaDriver::Disconnect()
- {
- FINFO("========================================");
- FINFO("DeltaDriver::Disconnect() Entry");
- try {
- if (m_scfWrapper) {
- FINFO("Stopping auto receive...");
- m_scfWrapper->StopAutoReceive();
- FINFO("Auto receive stopped");
- FINFO("Disconnecting SCF wrapper...");
- m_scfWrapper->Disconnect();
- FINFO("SCF wrapper disconnected");
- m_connectionState = ConnectionState::Disconnected;
- FINFO("Connection state set to Disconnected");
- } else {
- FWARN("SCF wrapper is null, nothing to disconnect");
- }
- m_bDemoConnected = false;
- }
- catch (const std::exception& e) {
- FERROR("Exception during disconnect: {$}", e.what());
- // 即使发生异常,也要确保状态被重置
- m_connectionState = ConnectionState::Disconnected;
- m_bDemoConnected = false;
- }
- FINFO("DeltaDriver::Disconnect() Completed");
- FINFO("========================================");
- }
- bool nsGEN::DeltaDriver::isConnected() const
- {
- const auto state = m_connectionState.load();
- // 1. 连接中/实际已连接:返回true(无需重连)
- if (state == ConnectionState::Connecting || (m_scfWrapper && m_scfWrapper->IsConnected())) {
- return true;
- }
- // 2. 失败状态处理:判断是否允许重试
- if (state == ConnectionState::Failed) {
- auto now = std::chrono::steady_clock::now();
- const auto timeSinceLast = now - m_lastConnectionAttempt;
- // 2.1 达到最大重试次数,但超过重置间隔:重置计数,允许重新重试
- if (m_connectionRetryCount >= MAX_RETRY_COUNT && timeSinceLast >= RESET_RETRY_AFTER) {
- FINFO("Max retries reached, resetting count after {$}s",
- std::chrono::duration_cast<std::chrono::seconds>(timeSinceLast).count());
- m_connectionRetryCount = 0; // 重置计数(因mutable修饰,const函数可修改)
- }
- // 2.2 不适合重连(时间未到 或 次数仍超限):返回true阻止重连
- if (timeSinceLast < RETRY_INTERVAL || m_connectionRetryCount >= MAX_RETRY_COUNT) {
- return true;
- }
- }
- // 3. 其他情况:返回false允许重连
- return false;
- }
- std::string nsGEN::DeltaDriver::DriverProbe()
- {
- ResDataObject r_config, HardwareInfo;
- if (r_config.loadFile(m_ConfigFileName.c_str()))
- {
- HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
- HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
- HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
- HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
- HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
- }
- else
- {
- HardwareInfo.add("MajorID", "Generator");
- HardwareInfo.add("MinorID", "Dr");
- HardwareInfo.add("VendorID", "Delta");
- HardwareInfo.add("ProductID", "DMG80KAXB");
- HardwareInfo.add("SerialID", "Drv");
- }
- string ret = HardwareInfo.encode();
- return ret;
- }
- std::string nsGEN::DeltaDriver::GetResource()
- {
- ResDataObject r_config, temp;
- if (!temp.loadFile(m_ConfigFileName.c_str()))
- {
- return "";
- }
- m_ConfigAll = temp;
- r_config = temp["CONFIGURATION"];
- m_Configurations = r_config;
- ResDataObject DescriptionTemp;
- ResDataObject DescriptionSend;
- ResDataObject m_DescriptionSend;
- ResDataObject ListTemp;
- string strTemp = ""; //用于读取字符串配置信息
- string strIndex = ""; //用于读取配置信息中的List项
- int nTemp = -1; //用于读取整型配置信息
- char sstream[10] = { 0 }; //用于转换值
- string strValue = ""; //用于存储配置的值
- string strType = ""; //用于存储配置的类型 int/float/string...
- /***
- * 1. 通过循环,将所有配置项写到pDeviceConfig
- * 2. 记录配置项的内部key以及配置类型,类型对应了不同配置文件路径,用于读写真实值
- ***/
- try
- {
- //便利ConfigToolInfo 中 所有的AttributeInfo 属性段
- int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
- m_pAttribute->clear();
- m_pDescription->clear();
- for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
- {
- DescriptionTemp.clear();
- DescriptionSend.clear();
- ListTemp.clear();
- //AttributeType
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Type"];
- DescriptionTemp.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
- DescriptionSend.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
- strType = strTemp; //记录配置项的类型
- //AttributeKey
- //1. 根据AttributeType,内部key和配置路径,拿到当前的真实值
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
- nTemp = (int)m_Configurations["ConfigToolInfo"][nInfoIndex]["PathID"];
- GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue); //得到strValue的值
- //2. 赋值
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
- if ("int" == strType)
- {
- (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
- }
- else if ("float" == strType)
- {
- (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
- }
- else //其它先按string类型处理
- {
- (*m_pAttribute).add(strTemp.c_str(), strValue.c_str());
- }
- //AttributeAccess
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Access"];
- DescriptionTemp.add(ConfKey::CcosAccess, strTemp.c_str());
- DescriptionSend.add(ConfKey::CcosAccess, strTemp.c_str());
- /*
- //AttributeRangeMin
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMin"];
- if (strTemp != "") //不需要的配置项为空
- {
- DescriptionTemp.add(ConfKey::CcosRangeMin, strTemp.c_str());
- }
- //AttributeRangeMax
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMax"];
- if (strTemp != "") //不需要的配置项为空
- {
- DescriptionTemp.add(ConfKey::CcosRangeMax, strTemp.c_str());
- }
- */
- //AttributeList
- nTemp = m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListNum"];
- if (nTemp > 0) //ListNum不大于0时说明不需要list配置
- {
- for (int nListIndex = 0; nListIndex < nTemp; nListIndex++)
- {
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListInfo"][nListIndex];
- auto temKey = std::to_string(nListIndex);
- ListTemp.add(temKey.c_str(), strTemp.c_str());
- }
- DescriptionTemp.add(ConfKey::CcosList, ListTemp);
- DescriptionSend.add(ConfKey::CcosList, ListTemp.encode());
- }
- //AttributeRequired
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Required"];
- DescriptionTemp.add(ConfKey::CcosRequired, strTemp.c_str());
- DescriptionSend.add(ConfKey::CcosRequired, strTemp.c_str());
- //AttributeDefaultValue
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["DefaultValue"];
- if (strTemp != "") //不需要的配置项为空
- {
- DescriptionTemp.add(ConfKey::CcosDefaultValue, strTemp.c_str());
- DescriptionSend.add(ConfKey::CcosDefaultValue, strTemp.c_str());
- }
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
- (*m_pDescription).add(strTemp.c_str(), DescriptionTemp);
- m_DescriptionSend.add(strTemp.c_str(), DescriptionSend.encode());
- }
- }
- catch (ResDataObjectExption& e)
- {
- FERROR("Get config error: {$}", e.what());
- return "";
- }
- ResDataObject resDeviceResource;
- resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
- resDeviceResource.add(ConfKey::CcosGeneratorDescription, (*m_pDescription));
- ResDataObject DescriptionTempEx;
- DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
- m_DeviceConfig.clear();
- m_DeviceConfig = DescriptionTempEx;
- FINFO("local ************* get resource over {$}", DescriptionTempEx.encode());
- resDeviceResource.clear();
- resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
- resDeviceResource.add(ConfKey::CcosGeneratorDescription, m_DescriptionSend);
- DescriptionTempEx.clear();
- DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
- m_DeviceConfigSend.clear();
- m_DeviceConfigSend = DescriptionTempEx;
- string res = m_DeviceConfigSend.encode();
- FINFO("get resource over {$}", DescriptionTempEx.encode());
- return res;
- }
- std::string nsGEN::DeltaDriver::DeviceProbe()
- {
- ResDataObject r_config, HardwareInfo;
- if (r_config.loadFile(m_ConfigFileName.c_str()))
- {
- HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
- HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
- HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
- HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
- HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
- }
- else
- {
- HardwareInfo.add("MajorID", "Generator");
- HardwareInfo.add("MinorID", "Dr");
- HardwareInfo.add("VendorID", "Delta");
- HardwareInfo.add("ProductID", "DMG80KAXB");
- HardwareInfo.add("SerialID", "Dev");
- }
- string ret = HardwareInfo.encode();
- return ret;
- }
- void nsGEN::DeltaDriver::Dequeue(const char* Packet, DWORD Length)
- {
- DecodeFrame(Packet, Length);
- }
- PACKET_RET nsGEN::DeltaDriver::callbackPackageProcess(const char* RecData, uint32_t nLength, uint32_t& PacketLength)
- {
- // 构建十六进制字符串用于日志输出
- char strSendCommand[10] = { 0 };
- string str = "";
- for (int i = 0; i < nLength; i++)
- {
- snprintf(strSendCommand, sizeof(strSendCommand), "%02X", (BYTE)RecData[i]);
- str += strSendCommand;
- str += ",";
- }
- FINFO("==IN== {$}, nLength: {$}", str, nLength);
- bool bHasHead = false;
- for (uint32_t i = 0; i < nLength; i++)
- {
- //寻找包头
- if ((UINT8)RecData[i] == COMMANDHEAD)
- {
- if ((i != 0) && (bHasHead == false)) //包头之前的数据格式不对,全部扔掉
- {
- PacketLength = i;
- char strtemp[Delta_Com_NormalLen] = { 0 };
- memcpy(strtemp, RecData, PacketLength);
- FERROR("==IN unknown format data ==:{$},UselessDataLength={$},TotalLength={$} \n", strtemp, PacketLength, nLength);
- return PACKET_USELESS;
- }
- else
- {
- bHasHead = true;
- }
- }
- //寻找包尾
- if (((UINT8)RecData[i] == COMMANDEND) && ((nLength - 1) == i))
- {
- if (bHasHead)
- {
- PacketLength = i + 1; //+1 because ETX
- char strtemp[Delta_Com_NormalLen] = { 0 };
- memcpy(strtemp, RecData, PacketLength); //只有ETX+数据,-2 排除 checkSum ETX。
- FINFO("==IN==:[{$}]", strtemp);
- // DeltaDevice::m_tDelivermodule.CheckReceive(strtemp, 2); // 已废弃
- return PACKET_ISPACKET;
- }
- else //有包尾但无包头
- {
- PacketLength = i + 1;
- char strtemp[Delta_Com_NormalLen] = { 0 };
- memcpy(strtemp, RecData, PacketLength);
- return PACKET_USELESS;
- }
- }
- else if (((BYTE)RecData[i] == 0x0D) && (3 == i))
- {
- bHasHead = true;
- PacketLength = i + 1; //+1 because ETX
- char strtemp[Delta_Com_NormalLen] = { 0 };
- memcpy(strtemp, RecData, PacketLength); //只有ETX+数据,-2 排除 checkSum ETX。
- FINFO("==IN==:[{$}]", strtemp);
- // DeltaDevice::m_tDelivermodule.CheckReceive(strtemp, 2); // 已废弃
- return PACKET_ISPACKET;
- }
- }
- if (bHasHead)
- {
- PacketLength = 0;
- }
- return PACKET_NOPACKET;
- }
- bool nsGEN::DeltaDriver::GetDeviceConfig(std::string& Cfg)
- {
- Cfg = m_DeviceConfigSend.encode();
- return true;
- }
- bool nsGEN::DeltaDriver::SetDeviceConfig(std::string Cfg)
- {
- FINFO("--Func-- SetDeviceConfig {$}", Cfg.c_str());
- ResDataObject DeviceConfig;
- DeviceConfig.decode(Cfg.c_str());
- ResDataObject DescriptionTempEx;
- DescriptionTempEx = DeviceConfig["DeviceConfig"]["Attribute"];
- FINFO("Attribute:{$}", DescriptionTempEx.encode());
- bool bSaveFile = false; //true:重新保存配置文件
- string strAccess = "";
- for (int i = 0; i < DescriptionTempEx.size(); i++)
- {
- string strKey = DescriptionTempEx.GetKey(i);
- FINFO("{$}", strKey.c_str());
- try
- {
- if (m_pAttribute->GetFirstOf(strKey.c_str()) >= 0)
- {
- strAccess = (string)(*m_pDescription)[strKey.c_str()]["Access"];
- if ("RW" == strAccess)
- {
- //修改对应配置,在其他单元的配置项要同时调用其修改函数修改真实值
- //1. 修改内存中的值,用于给上层发消息
- (*m_pAttribute)[strKey.c_str()] = DescriptionTempEx[i];
- //2. 拿到Innerkey
- int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
- FINFO("nConfigInfoCount {$}", nConfigInfoCount);
- string strTemp = ""; //存储AttributeKey
- for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
- {
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
- if (strTemp == strKey)
- {
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
- break;
- }
- }
- //3. 修改配置文件中的值
- if (SetDeviceConfigValue(m_Configurations, strTemp.c_str(), 1, DescriptionTempEx[i]))
- {
- FINFO("SetDeviceConfigValue over");
- bSaveFile = true;
- }
- }
- else
- {
- FINFO("{$} is not a RW configuration item", strKey.c_str());
- }
- }
- else
- {
- FINFO("without this attribute {$}", strKey.c_str());
- }
- }
- catch (ResDataObjectExption& e)
- {
- FERROR("SetDriverConfig crashed: {$}", e.what());
- return false;
- }
- }
- if (bSaveFile)
- {
- //3. 重新保存配置文件
- SaveConfigFile(true);
- }
- return true;
- }
- bool nsGEN::DeltaDriver::SaveConfigFile(bool bSendNotify)
- {
- m_ConfigAll["CONFIGURATION"] = m_Configurations;
- bool bRt = m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
- FINFO("SaveConfigFile over {$}", bRt);
- return true;
- }
- bool nsGEN::DeltaDriver::GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue)
- {
- strValue = "";
- string strTemp = pInnerKey;
- if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
- {
- int pos = 0;
- ResDataObject resTemp = config;
- while ((pos = strTemp.find_first_of(',')) != string::npos)
- {
- string Key = strTemp.substr(0, pos);
- string TempValue = resTemp[Key.c_str()].encode();
- resTemp.clear();
- resTemp.decode(TempValue.c_str());
- strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
- }
- if (strTemp != "")
- {
- strValue = (string)resTemp[strTemp.c_str()];
- }
- else
- {
- strValue = (string)resTemp;
- }
- }
- return true;
- }
- bool nsGEN::DeltaDriver::SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue)
- {
- string strTemp = pInnerKey;
- FINFO("Begin to change {$} item value to {$}", pInnerKey, szValue);
- if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
- {
- try {
- int pos = 0;
- ResDataObject* resTemp = &config;
- while ((pos = strTemp.find_first_of(',')) != string::npos)
- {
- string Key = strTemp.substr(0, pos);
- resTemp = &(*resTemp)[Key.c_str()];
- strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
- }
- if (strTemp != "")
- {
- (*resTemp)[strTemp.c_str()] = szValue;
- }
- else
- {
- *resTemp = szValue;
- }
- }
- catch (ResDataObjectExption& e)
- {
- FERROR("SetDriverConfigvalue crashed: {$}", e.what());
- return false;
- }
- }
- return true;
- }
- //-----------------------------------------------------------------------------
- // GetIODriver & CreateIODriver
- //-----------------------------------------------------------------------------
- static nsGEN::DeltaDriver gIODriver;
- extern "C" CCOS::Dev::IODriver * GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
- {
- return &gIODriver;
- }
- extern "C" CCOS::Dev::IODriver * CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
- {
- return new nsGEN::DeltaDriver();
- }
|