123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799 |
- // CCOS.Dev.GEN.RYGEN.cpp : 定义 DLL 应用程序的导出函数。
- //
- #include "stdafx.h"
- #include <assert.h>
- #include <functional>
- #include "LogicDevice.h"
- #include "Helper.JSON.hpp"
- #include <unordered_map>
- #include "CCOS.Dev.Generator.RYGEN.h"
- #include <fstream>
- using namespace std::placeholders;
- using namespace CCOS::Dev::Detail::Generator;
- namespace nsGEN = CCOS::Dev::Detail::Generator;
- #pragma warning (disable:4244)
- #pragma warning (disable:4305)
- #pragma warning (disable:4267)
- static const int msTimeOut_Lock = 500;
- #ifdef _WIN64
- #ifdef _DEBUG
- static const auto COM_SCFDllName = "Ccos.Dev.SerialSCFX64D.dll";
- #else
- static const auto COM_SCFDllName = "Ccos.Dev.SerialSCFX64.dll";
- #endif
- #endif
- #ifdef _WIN64
- #ifdef _DEBUG
- static const auto TCP_SCFDllName = "Ccos.Dev.TcpipSCFX64D.dll";
- #else
- static const auto TCP_SCFDllName = "Ccos.Dev.TcpipSCFX64.dll";
- #endif
- #endif
- //-----------------------------------------------------------------------------
- // RYGENDevice
- //-----------------------------------------------------------------------------
- IMPLEMENT_DYNAMIC(RYGENDevice, CWnd)
- BEGIN_MESSAGE_MAP(RYGENDevice, CWnd)
- ON_MESSAGE(WM_HV_TABLE_IO_MESSAGE, RYAPIMSG)
- END_MESSAGE_MAP()
- float g_MA_List[] = { 8, 10, 12.5, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640 };
- float g_MAS_List[] = { 1, 1.25, 1.6, 2, 2.5, 3.2, 4, 5, 6.4, 8, 10, 12.5, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640, 800, 1000 };
- float g_MS_List[] = { 1, 2, 3, 4, 5, 6, 8, 10, 12, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640, 800, 1000, 1250, 1600, 2000, 2500, 3200, 4000, 5000, 6400, 8000, 10000 };
- int g_AECFIELD_List[] = { 1, 10, 100, 11, 101, 111 };
- std::vector <float> gf_MA_List = { 8, 10, 12.5, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640 };
- atomic<int> nsGEN::RYGENDevice::m_iLoopTime = RYGEN_LoopDefTime;
- string GetProcessDirectory()
- {
- string ret = "";
- char szFilename[MAX_PATH] = { 0 };
- DWORD res = GetModuleFileNameA(0, szFilename, MAX_PATH);
- if (res == 0)
- {
- return ret;
- }
- string fullpath = szFilename;
- string::size_type firstHit = fullpath.find_last_of('\\');
- if (firstHit == string::npos || firstHit == 0)
- {
- return ret;
- }
- ret = fullpath.substr(0, firstHit);//kick last
- return ret;
- }
- nsGEN::RYGENDevice::RYGENDevice(std::shared_ptr <IOEventCenter> center, UIObject* UIobj, string configfile) : super(center)
- {
- m_pUIOBJ = UIobj;
- m_pUIOBJ->Init(this, OnCallBack);
- assert(EventCenter);
- FINFO("version:3.0.1.0");
- m_DoseUnit.m_KV.reset(new KVMould(0.0, 40.0, 120.0, 1.0));
- m_DoseUnit.m_MA.reset(new MAMould(0.0, 10.0, 1000.0, 0.1));
- m_DoseUnit.m_MS.reset(new MSMould(0.0, 1.0, 10000.0, 0.01));
- m_DoseUnit.m_MAS.reset(new MASMould(0.0, 0.1, 1000.0, 0.01));
- m_DoseUnit.m_Techmode.reset(new TECHMODEMould(0, 0, 2, 1));
- m_DoseUnit.m_WS.reset(new WORKSTATIONMould(1, 0, 5, 1));
- m_DoseUnit.m_Focus.reset(new FOCUSMould(1, 0, 1, 1));
- m_DoseUnit.m_AECField.reset(new AECFIELDMould(0, 0, 111, 1));
- m_DoseUnit.m_AECFilm.reset(new AECFILMMould(0, 0, 2, 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(0.0, 40.0, 120.0, 1.0));
- m_DoseUnit.m_PostMA.reset(new POSTMAMould(0.0, 10.0, 1000.0, 0.1));
- m_DoseUnit.m_PostMS.reset(new POSTMSMould(0.0, 1.0, 10000.0, 0.01));
- m_DoseUnit.m_PostMAS.reset(new POSTMASMould(0.0, 0.5, 1000.0, 0.01));
- m_DoseUnit.m_GenSynState.reset(new GENSYNSTATEMould(0, AttrKey::GENERATOR_SYNC_ERR, AttrKey::GENERATOR_SYNC_MAX, 1));
- m_DoseUnit.m_GenState.reset(new GENSTATEMould(0, 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, 16, 1));
- m_MSGUnit.reset(new nsDetail::MSGUnit(center, nsGEN::GeneratorUnitType));
- m_DAP.reset(new DevDAP::DOSEMould(0.0, 0.0, 1000.0, 0.01));
- m_DoseUnit.m_FLMode.reset(new FLUModeMould(AttrKey::GENERATOR_FLUMode::GENERATOR_FLMODE_NOTFLU));
- m_DoseUnit.m_FLIntTime.reset(new FLUIntTimeMould(0.0, 0.0, 100.0, 0.1));
- m_DoseUnit.m_FLAccTime.reset(new FLAccTimeMould(0.0, 0.0, 999.0, 0.1));
- m_DoseUnit.m_FLKV.reset(new FLUKVMould(0, 40, 125, 1));
- m_DoseUnit.m_FLMS.reset(new FLUMSMould(10.0, 10.0, 999999.0, 0.01));
- m_DoseUnit.m_FLMA.reset(new FLUMAMould(0.1, 0.1, 99.0, 0.1));
- m_DoseUnit.m_ABSStatus.reset(new FLUABSStatusMould(0, 0, 2, 1));
- m_DoseUnit.m_PPS.reset(new PPSMould(0.5, 0.5, 30, 0.1));
- m_DoseUnit.m_DoseLevel.reset(new FLUDoseLevelMould(0, 0, 2, 1));
- m_DoseUnit.m_Curve.reset(new FLUCurveMould(0, 0, 3, 1));
- m_hGenPostEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
- m_pHardwareStatusThread = NULL;
- m_DoseUnit.m_FLAccTimeUnit = "s";
- m_nPreWS = 0;
- m_nPreFO = 1;
- m_nPreET = 0;
- m_nPreAECFieldSel = 0;
- m_nPreAECFilmSel = 0;
- m_nPreAECDensity = 0;
- m_nPreKV = 50;
- m_fPreMA = 200;
- m_fPreMS = 50;
- m_fPreMAS = 10;
- m_strFLFMode = "PF";
- m_fpps = 15;
- m_bError = false;
- m_bIsConfigLoaded = false;
- m_bResetActive = false;
- m_hWnd = NULL;
- Register();
- InitGen();
- }
- nsGEN::RYGENDevice::~RYGENDevice()
- {
- CloseHandle(m_hGenPostEvent);
- if (HV_ClearCanBuffer())
- {
- FINFO("HV_ClearCanBuffer success!");
- }
- else
- {
- FINFO("HV_ClearCanBuffer failed!");
- }
- HV_CloseCanDriver();
- m_pUIOBJ->Destrory();
- }
- std::string nsGEN::RYGENDevice::GetGUID() const
- {
- FINFO("\n===============GetGUID : {$} ===================\n", GeneratorUnitType);
- return GeneratorUnitType;
- }
- void nsGEN::RYGENDevice::Register()
- {
- auto Disp = &Dispatch;
- superGen::Register(Disp);
- superGen::RegisterRAD(Disp);
- superGen::RegisterAEC(Disp);
- superGen::RegisterExpEnable(Disp);
- superGen::RegisterGeneratortoSyncStatus(Disp);
- superGen::RegisterFluoro(Disp);
- Disp->Get.Push(m_MSGUnit->GetKey().c_str(), [this](std::string& out) { out = m_MSGUnit->JSGet(); return RET_STATUS::RET_SUCCEED; });
- auto fun_Clear_DAP = [this](auto a, auto&)
- {
- return Clear_DAP();
- };
- Disp->Action.Push("Clear_DAP", fun_Clear_DAP);
- auto fun_GetValue_DAP = [this](auto a, auto& b)
- {
- float value = 0;
- RET_STATUS ret = GetValue_DAP(value);
- b = ToJSON(value);
- return ret;
- };
- Disp->Action.Push("GetValue_DAP", fun_GetValue_DAP);
- auto fun_StartMove = [this](auto a,auto& b)
- {
- return StartMove();
- };
- Disp->Action.Push("StartMove", fun_StartMove);
- auto fun_EndMove = [this](auto a, auto& b)
- {
- return EndMove();
- };
- Disp->Action.Push("EndMove", fun_EndMove);
- }
- RET_STATUS nsGEN::RYGENDevice::IncKV()
- {
- if (!m_DoseUnit.m_KV->CanInc()) return RET_STATUS::RET_SUCCEED;
- BYTE ucMode = 0x01;
- int nKV = HV_Handle_KV(ucMode, 0, 0);// kv increase 1
- if (-1 != nKV)
- {
- if (m_DoseUnit.m_KV->Update(nKV))
- FireNotify("KV", m_DoseUnit.m_KV->JSGet());
- FINFO("INCKV success!");
- }
- else
- {
- FINFO("INCKV failed!");
- ucMode = 0x04;
- int nKV = HV_Handle_KV(ucMode, 0, 0);// get current kv
- if (nKV != -1)
- {
- if (m_DoseUnit.m_KV->Update(nKV))
- FireNotify("KV", m_DoseUnit.m_KV->JSGet());
- FINFO("get KV success!");
- }
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::DecKV()
- {
- if (!m_DoseUnit.m_KV->CanDec()) return RET_STATUS::RET_SUCCEED;
- BYTE ucMode = 0x03;
- int nKV = HV_Handle_KV(ucMode, 0, 0);// kv decrease 1
- if (-1 != nKV)
- {
- if (m_DoseUnit.m_KV->Update(nKV))
- FireNotify("KV", m_DoseUnit.m_KV->JSGet());
- FINFO("DECKV success!");
- }
- else
- {
- FINFO("DECKV failed!");
- ucMode = 0x04;
- int nKV = HV_Handle_KV(ucMode, 0, 0);// get current kv
- if (nKV != -1)
- {
- if (m_DoseUnit.m_KV->Update(nKV))
- FireNotify("KV", m_DoseUnit.m_KV->JSGet());
- FINFO("get KV success!");
- }
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::SetKV(float value)
- {
- if (!m_DoseUnit.m_KV->Verify(value)) return RET_STATUS::RET_SUCCEED;
- BYTE ucMode = 0x05;
- int nCurrentKV = HV_Handle_KV(ucMode, (int)value, 0); // set kv
- if (nCurrentKV != -1)
- {
- if (nCurrentKV != value)
- {
- return RET_FAILED;
- }
- m_DoseUnit.m_KV->Update(value);
- FireNotify("KV", m_DoseUnit.m_KV->JSGet());
- FINFO("SetKV success!");
- }
- else
- {
- FINFO("SetKV failed!");
- return RET_FAILED;
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::IncMA()
- {
- if (!m_DoseUnit.m_MA->CanInc()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- FINFO("\n Techmode is MAS, can't inc MA");
- return RET_STATUS::RET_FAILED;
- }
- BYTE ucMode = 0x01;
- int nCurrentMA = HV_Handle_MA(ucMode, 0, 0); // MA increase 1
- if (nCurrentMA != -1)
- {
- float fCurrentMA = (float)nCurrentMA;
- if (m_DoseUnit.m_MA->Update(fCurrentMA / 10.0f))
- FireNotify("MA", m_DoseUnit.m_MA->JSGet());
- FINFO("INCMA success!");
- GetMAS();
- }
- else
- {
- FINFO("INCMA failed!");
- ucMode = 0x04;
- int nCurrentMA = HV_Handle_MA(ucMode, 0, 0); // get current MA
- if (nCurrentMA != -1)
- {
- float fCurrentMA = (float)nCurrentMA;
- if (m_DoseUnit.m_MA->Update(fCurrentMA / 10.0f))
- FireNotify("MA", m_DoseUnit.m_MA->JSGet());
- FINFO("GetMA success!");
- }
- else
- {
- FINFO("GetMA failed!");
- }
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::DecMA()
- {
- if (!m_DoseUnit.m_MA->CanDec()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- FINFO("\n Techmode is MAS, can't dec MA");
- return RET_STATUS::RET_FAILED;
- }
- BYTE ucMode = 0x03;
- int nCurrentMA = HV_Handle_MA(ucMode, 0, 0); // MA decrease 1
- if (nCurrentMA != -1)
- {
- float fCurrentMA = (float)nCurrentMA;
- if (m_DoseUnit.m_MA->Update(fCurrentMA / 10.0f))
- FireNotify("MA", m_DoseUnit.m_MA->JSGet());
- FINFO("DECMA success!");
- GetMAS();
- }
- else
- {
- FINFO("DECMA failed!");
- ucMode = 0x04;
- int nCurrentMA = HV_Handle_MA(ucMode, 0, 0); // get current MA
- if (nCurrentMA != -1)
- {
- float fCurrentMA = (float)nCurrentMA;
- if (m_DoseUnit.m_MA->Update(fCurrentMA / 10.0f))
- FireNotify("MA", m_DoseUnit.m_MA->JSGet());
- FINFO("GetMA success!");
- }
- else
- {
- FINFO("GetMA failed!");
- }
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::SetMA(float fMA)
- {
- if (!m_DoseUnit.m_MA->Verify(fMA)) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- FINFO("\n Techmode is MAS, can't set MA");
- return RET_STATUS::RET_FAILED;
- }
- int nMA = (int)(fMA * 10);
- BYTE ucMode = 0x05;
- int nCurrentMA = HV_Handle_MA(ucMode, nMA, 0); // set MA
- if (nCurrentMA != -1)
- {
- float fCurrentMA = (float)nCurrentMA;
- m_DoseUnit.m_MA->Update(fCurrentMA / 10.0f);
- FireNotify("MA", m_DoseUnit.m_MA->JSGet());
- FINFO("SetMA success!");
- GetMAS();
- }
- else
- {
- FINFO("SetMA failed!");
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::IncMS()
- {
- if (!m_DoseUnit.m_MS->CanInc()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- FINFO("\n Techmode is MAS, can't inc MS");
- return RET_STATUS::RET_FAILED;
- }
- BYTE ucMode = 0x01;
- int nCurrentMS = HV_Handle_MS(ucMode, 0, 0); // MS increase 1
- if (nCurrentMS != -1)
- {
- float fCurrentMS = (float)nCurrentMS;
- if (m_DoseUnit.m_MS->Update(fCurrentMS / 100.0f))
- FireNotify("MS", m_DoseUnit.m_MS->JSGet());
-
- FINFO("INCMS success!");
- GetMAS();
- }
- else
- {
- FINFO("INCMS failed!");
- ucMode = 0x04;
- int nCurrentMS = HV_Handle_MS(ucMode, 0, 0); // get current MS
- if (nCurrentMS != -1)
- {
- float fCurrentMS = (float)nCurrentMS;
- if (m_DoseUnit.m_MS->Update(fCurrentMS / 100.0f))
- FireNotify("MS", m_DoseUnit.m_MS->JSGet());
- FINFO("GetMS success!");
- }
- else
- {
- FINFO("GetMS failed!");
- }
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::DecMS()
- {
- if (!m_DoseUnit.m_MS->CanDec()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- FINFO("\n Techmode is MAS, can't dec MS");
- return RET_STATUS::RET_FAILED;
- }
- BYTE ucMode = 0x03;
- int nCurrentMS = HV_Handle_MS(ucMode, 0, 0); // MS decrease 1
- if (nCurrentMS != -1)
- {
- float fCurrentMS = (float)nCurrentMS;
- if (m_DoseUnit.m_MS->Update(fCurrentMS / 100.0f))
- FireNotify("MS", m_DoseUnit.m_MS->JSGet());
- FINFO("DECMS success!");
- GetMAS();
- }
- else
- {
- FINFO("DECMS failed!");
- ucMode = 0x04;
- int nCurrentMS = HV_Handle_MS(ucMode, 0, 0); // get current MS
- if (nCurrentMS != -1)
- {
- float fCurrentMS = (float)nCurrentMS;
- if (m_DoseUnit.m_MS->Update(fCurrentMS / 100.0f))
- FireNotify("MS", m_DoseUnit.m_MS->JSGet());
- FINFO("GetMS success!");
- }
- else
- {
- FINFO("GetMS failed!");
- }
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::SetMS(float fMS)
- {
- if (!m_DoseUnit.m_MA->Verify(fMS)) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- FINFO("\n Techmode is MAS, can't set MS");
- return RET_STATUS::RET_FAILED;
- }
- int nMS = (int)(fMS * 100);
- BYTE ucMode = 0x05;
- int nCurrentMS = HV_Handle_MS(ucMode, nMS, 0); // set MS
- if (nCurrentMS != -1)
- {
- float fCurrentMS = (float)nCurrentMS;
- m_DoseUnit.m_MS->Update(fCurrentMS / 100.0f);
- FireNotify("MS", m_DoseUnit.m_MS->JSGet());
- FINFO("SetMS success!");
- GetMAS();
- }
- else
- {
- FINFO("SetMS failed!");
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::IncMAS()
- {
- if (!m_DoseUnit.m_MAS->CanInc()) return RET_STATUS::RET_SUCCEED;
-
- if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- FINFO("\n Techmode is not MAS, can't inc MAS");
- return RET_STATUS::RET_FAILED;
- }
- BYTE ucMode = 0x01;
- int nCurrentMAS = HV_Handle_MX(ucMode, 0, 0); // MAS increase 1
- if (nCurrentMAS != -1)
- {
- float fCurrentMAS = (float)nCurrentMAS;
- if (m_DoseUnit.m_MAS->Update(fCurrentMAS / 1000.0f))
- //FireNotify("MAS", m_DoseUnit.m_MAS->JSGet());
- FINFO("INCMAS success!");
- GetMA();
- GetMS();
- }
- else
- {
- FINFO("INCMAS failed!");
- ucMode = 0x04;
- nCurrentMAS = HV_Handle_MX(ucMode, 0, 0); // get current MAS
- if (nCurrentMAS != -1)
- {
- FINFO("GetMAS success!");
- }
- else
- {
- FINFO("GetMAS failed!");
- }
- }
- GetMAS();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::DecMAS()
- {
- if (!m_DoseUnit.m_MAS->CanDec()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- FINFO("\n Techmode is not MAS, can't dec MAS");
- return RET_STATUS::RET_FAILED;
- }
- BYTE ucMode = 0x03;
- int nCurrentMAS = HV_Handle_MX(ucMode, 0, 0); // MAS decrease 1
- if (nCurrentMAS != -1)
- {
- float fCurrentMAS = (float)nCurrentMAS;
- if (m_DoseUnit.m_MAS->Update(fCurrentMAS / 1000.0f))
- //FireNotify("MAS", m_DoseUnit.m_MAS->JSGet());
- FINFO("DECMAS success!");
- GetMA();
- GetMS();
- }
- else
- {
- FINFO("DECMAS failed!");
- ucMode = 0x04;
- nCurrentMAS = HV_Handle_MX(ucMode, 0, 0); // get current MAS
- if (nCurrentMAS != -1)
- {
- FINFO("GetMAS success!");
- }
- else
- {
- FINFO("GetMAS failed!");
- }
- }
- GetMAS();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::SetMAS(float fMAS)
- {
- if (!m_DoseUnit.m_MA->Verify(fMAS)) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- FINFO("\n Techmode is not MAS, can't set MAS");
- return RET_STATUS::RET_FAILED;
- }
- int nMAS = (int)(fMAS * 1000);
- BYTE ucMode = 0x05;
- int nCurrentMAS = HV_Handle_MX(ucMode, nMAS, 0); // set MAS
- if (nCurrentMAS != -1)
- {
- float fCurrentMAS = (float)nCurrentMAS;
- if (m_DoseUnit.m_MAS->Update(fCurrentMAS / 1000.0f))
- FireNotify("MAS", m_DoseUnit.m_MAS->JSGet());
- FINFO("SetMAS success!");
- }
- else
- {
- FINFO("SetMAS failed!");
- }
- GetMA();
- GetMS();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::SetTechmode(int nET)
- {
- if (!m_DoseUnit.m_Techmode->Verify(nET)) return RET_STATUS::RET_SUCCEED;
- FINFO("Select Tech mode: {$}, current mode: {$}", nET, m_DoseUnit.m_Techmode->Get());
- int count = 3;
- int tempET = 0;
- while (count--)
- {
- tempET = HV_Handle_TE(0, nET, 0);
- if (tempET == nET)
- {
- FINFO("SetTechMode succeed!");
- break;
- }
- Sleep(50);
- }
- if (m_DoseUnit.m_Techmode->Update(tempET))
- FireNotify(AttrKey::TECHMODE, m_DoseUnit.m_Techmode->JSGet());
- if (m_DoseUnit.m_Techmode->Get() == 0) //Ma,MS
- {
- SetAECField(0);
- }
- else if (m_DoseUnit.m_Techmode->Get() == 1) //MAS
- {
- SetAECField(0);
- }
- else if (m_DoseUnit.m_Techmode->Get() == 2) //AEC
- {
- SetAECField(m_DoseUnit.m_AECField->Get());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::SetFocus(int nFO)
- {
- if (!m_DoseUnit.m_Focus->Verify(nFO)) return RET_STATUS::RET_SUCCEED;
- FINFO("SetFocusSel to {$}", nFO);
- BYTE ucMode = 0x00;
- int nCurrentFO = HV_Handle_FO(ucMode, nFO, 0); // set FO
- if (nCurrentFO != -1)
- {
- if (m_DoseUnit.m_Focus->Update(nCurrentFO))
- {
- FireNotify(AttrKey::FOCUS, m_DoseUnit.m_Focus->JSGet());
- FINFO("焦点:{$}, FO={$}", atoi(m_DoseUnit.m_Focus->JSGet().c_str()) ? "大焦点" : "小焦点", m_DoseUnit.m_Focus->JSGet().c_str());
- FINFO("SetFocusSel success!");
- }
- GetKV();
- GetMA();
- GetMS();
- GetMAS();
- }
- else
- {
- FINFO("SetFocusSel failed!");
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::SetAECDensity(int nAECDensity)
- {
- if (!m_DoseUnit.m_AECDensity->Verify(nAECDensity)) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_AEC)
- return RET_STATUS::RET_FAILED;
- FINFO("SetAECDensity = {$} ", nAECDensity);
- int nRet = HV_Handle_FN(0, nAECDensity, 0);
- if (nRet == nAECDensity)
- {
- if (m_DoseUnit.m_AECDensity->Update(nAECDensity))
- FireNotify(AttrKey::AECDENSITY, m_DoseUnit.m_AECDensity->JSGet());
- FINFO("set AED density {$} succeed", m_DoseUnit.m_AECDensity->JSGet().c_str());
- }
- else
- {
- FINFO("set AED density return {$} != {$} ,failed!", nRet, nAECDensity);
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::SetAECField(int nAECFieldSel)
- {
- if (!m_DoseUnit.m_AECField->Verify(nAECFieldSel)) return RET_STATUS::RET_SUCCEED;
- int ret = true;
- int count = 3;
- if (m_DoseUnit.m_AECField->Get() != 2) // not AEC mode
- {
- FINFO("not in AEC mode");
- int nCurrentFiled = 0;
- while (count--)
- {
- nCurrentFiled = HV_Handle_FI(0, 0, 0);
- if (nCurrentFiled == 0) break;
- Sleep(10);
- }
- FireNotify(AttrKey::AECFIELD, "0");
- return RET_STATUS::RET_SUCCEED;
- }
- int SetAECFieldSel = nAECFieldSel;
- FINFO("SetAECField is {$}", SetAECFieldSel);
- int nCurrentAECFieldSel = 0;
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::SetAECFilm(int value)
- {
- if (!m_DoseUnit.m_AECFilm->Verify(value)) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS)
- return RET_STATUS::RET_FAILED;
- char temp[50] = { 0 };
- sprintf_s(temp, "FS%03d", (int)value);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::RYGENDevice::SetWS(const string value)
- {
- int tempws = 0;
- if (value == "Table") tempws = (int)m_GenConfig["WSTable"];
- else if (value == "Wall") tempws = (int)m_GenConfig["WSWall"];
- else if (value == "Direct") tempws = (int)m_GenConfig["WSConventional"];
- else if (value == "Free") tempws = (int)m_GenConfig["WSFree"];
- else if (value == "Tomo") tempws = (int)m_GenConfig["WSTomo"];
- /*char temp[50] = { 0 };
- sprintf_s(temp, "WS%01d", tempws);
- return HWSend(temp);*/
- return RET_STATUS::RET_SUCCEED;
- }
- string nsGEN::RYGENDevice::WSUI2Gen(int nUIWS)
- {
- string strWS = "";
- try
- {
- if (nUIWS == AttrKey::GENWS_TYPE::TABLE) //lying: cross mode
- {
- strWS = m_GenConfig["WSTable"].encode();
- }
- else if (nUIWS == AttrKey::GENWS_TYPE::WALL) //standing mode
- {
- strWS = m_GenConfig["WSWall"].encode();
- }
- else if (nUIWS == AttrKey::GENWS_TYPE::FREE_TABLE) //standing mode
- {
- strWS = m_GenConfig["WSFree"].encode();
- }
- else if (nUIWS == AttrKey::GENWS_TYPE::TOMO) //standing mode
- {
- strWS = m_GenConfig["WSTOMO"].encode();
- }
- else if (nUIWS == AttrKey::GENWS_TYPE::CONVENTIONAL) //standing mode
- {
- strWS = m_GenConfig["WSConventional"].encode();
- }
- }
- catch (ResDataObjectExption& exp)
- {
- FERROR("Get configuration failed, {$}\n", exp.what());
- }
- FINFO("Set WS: {$},Generator workstaion: {$}\n", nUIWS, strWS);
- if (strWS == "")
- {
- strWS = "Table";
- }
- return strWS;
- }
- RET_STATUS nsGEN::RYGENDevice::SetAPR(const _tAPRArgs& t)
- {
- m_t = t;
- FINFO("*********************Enter SetAPR*********************");
- FINFO("t.ws={$},t.fKV={$},t.fMA={$},t.fMAS={$},t.nAECDensity={$},t.nAECField={$},t.nAECFilm={$},t.nFocus={$},t.nTechmode={$}", t.nWS,t.fKV, t.fMA, t.fMAS, t.nAECDensity, t.nAECField, t.nAECFilm, t.nFocus, t.nTechmode);
- m_nPreWS = t.nWS;
- m_nPreFO = t.nFocus;
- m_nPreET = t.nTechmode;
- m_nPreAECFieldSel = t.nAECField;
- m_nPreAECFilmSel = t.nAECFilm;
- m_nPreAECDensity = t.nAECDensity;
- m_nPreKV = t.fKV;
- m_fPreMA = t.fMA;
- m_fPreMS = t.fMS;
- m_fPreMAS = t.fMAS;
- //SetWS("Table");
- //2
- SetKV(t.fKV);
- //3
- SetFocus(t.nFocus);
- //4
- if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_AEC)//aec
- {
- SetTechmode(t.nTechmode);
- SetAECField(t.nAECField);
- SetAECDensity(t.nAECDensity);
- SetMA(t.fMA);
- SetMS(t.fMS);
- }
- else if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_MAS)//2p
- {
- SetTechmode(t.nTechmode);
- const float EPSINON = 0.000001;
- SetMAS(t.fMAS);
- }
- else if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_TIME)//3p
- {
- SetTechmode(t.nTechmode);
- SetMA(t.fMA);
- SetMS(t.fMS);
- }
- UpdateGenParamter();
- FINFO("*********************Leave SetAPR*********************");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::QueryHE(int& value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::QueryPostKV(float& value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::QueryPostMA(float& value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::QueryPostMS(float& value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::QueryPostMAS(float& value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::Clear_DAP()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::GetValue_DAP(float& value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::StartMove()
- {
- FINFO("Enter startMove");
- FINFO("end startmove");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::EndMove()
- {
- FINFO("Enter endmove");
- FINFO("end EndMove");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::ActiveSyncMode(_tSyncModeArgs value)
- {
- return RET_STATUS();
- }
- int nsGEN::RYGENDevice::LoadConfig(string configfile)
- {
- FINFO("=====================LoadConfig=========================");
- // 检查文件是否存在
- std::ifstream file(configfile);
- if (!file) {
- // 文件不存在,直接返回空的Connection对象
- FINFO("Config file does not exist: {$}", configfile.c_str());
- return -1;
- }
- if (m_bIsConfigLoaded)
- {
- FINFO("Configuration already loaded.");
- return 0;
- }
- m_strConfigPath = configfile;
- ResDataObject temp;
- temp.loadFile(m_strConfigPath.c_str());
- m_GenConfig = temp["CONFIGURATION"];
- TransJsonText(m_GenConfig);
- m_bIsConfigLoaded = true;
- return 0;
- }
- RET_STATUS nsGEN::RYGENDevice::SetGenSynState(int value)
- {
- FINFO("Enter SetGenSynState...{$} \n", value);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::SetGenState(int value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::SetExpMode(std::string value)
- {
- //note: when time the func be called?
- FINFO("Enter SetExpMode...{$}",value);
- m_DoseUnit.m_ExpMode->Update(value);
- int nStatus = HV_GetST();
- if (nStatus == 200)
- {
- m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
- }
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::SetFLFMode(std::string value)
- {
- FINFO("Enter SetFLFMode...{$} \n", value.c_str());
- m_strFLFMode = value;
- int nMode = 0;
- if (value == "CF")
- {
- nMode = 1;
- }
- else if (value == "PF")
- {
- nMode = 2;
- }
- if (nMode == 1 || nMode == 2) // currently RYGEN just support 0, 1, 2
- {
- m_DoseUnit.m_FLMode->Update(nMode);
- nMode--;
- FINFO("SetFlMode {$}!", nMode);
- int i = 3;
- while (i--)
- {
- int nCurrentMode = HV_Handle_PF(5, nMode, 0); // set current FL mode
- if (nCurrentMode != -1)
- {
- FINFO("SetFlMode success, return {$}!", nCurrentMode);
- if (nCurrentMode != nMode)
- {
- Sleep(100);
- continue;
- }
- else
- {
- break;
- }
- }
- else
- {
- FINFO("SetFlMode failed!");
- break;
- }
- }
- }
- else
- {
- FINFO("Don't supported fluoro mode");
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::SetAPF(const _tAPFArgs& t)
- {
- FINFO("APF:FLKV={$},FLMA={$},PPS={$},WS={$},FLuType={$},ABSMode={$},DoseLever={$}", t.nFLKV, t.fFLMA, t.nPPS, t.nWS, t.nFluMode, t.nABSMode, t.nDoseLever);
-
- int j = 3;
- while (j--)
- {
- if (SetABSMode(t.nABSMode))
- {
- break;
- }
- else
- {
- Sleep(100);
- }
- }
- Sleep(150);
- //SetFLFMode(to_string(t.nFluMode));
- //Sleep(50);
- //SetFluDoseLever(t.nDoseLever);
- //Sleep(50);
-
- for (int i = 0; i < 2; i++)
- {
- if (SetFluKV(t.nFLKV))
- {
- break;
- }
- Sleep(100);
- }
- SetFluMA(t.fFLMA);
- GetFluKV();
- GetFluMA();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::IncFluKV()
- {
- FINFO("Enter IncFLKV()\n");
- if (!m_DoseUnit.m_FLKV->CanInc()) return RET_STATUS::RET_SUCCEED;
- BYTE ucMode = 0x01;
- int nFLKV = HV_Handle_FLK(ucMode, 0, 0);// FLkv increase 1
- if (-1 != nFLKV)
- {
- if (m_DoseUnit.m_FLKV->Update(nFLKV))
- FireNotify(AttrKey::FLUKV, m_DoseUnit.m_FLKV->JSGet());
- FINFO("INCFLKV success!");
- }
- else
- {
- FINFO("INCFLKV failed!");
- ucMode = 0x04;
- int nFLKV = HV_Handle_FLK(ucMode, 0, 0);// get current FLkv
- if (nFLKV != -1)
- {
- if (m_DoseUnit.m_FLKV->Update(nFLKV))
- FireNotify(AttrKey::FLUKV, m_DoseUnit.m_FLKV->JSGet());
- FINFO("get FLKV success!");
- }
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::DecFluKV()
- {
- if (!m_DoseUnit.m_FLKV->CanDec()) return RET_STATUS::RET_SUCCEED;
- BYTE ucMode = 0x03;
- int nFLKV = HV_Handle_FLK(ucMode, 0, 0);// FLkv decrease 1
- if (-1 != nFLKV)
- {
- if (m_DoseUnit.m_FLKV->Update(nFLKV))
- FireNotify(AttrKey::FLUKV, m_DoseUnit.m_FLKV->JSGet());
- FINFO("DECFLKV success!");
- }
- else
- {
- FINFO("DECFLKV failed!");
- ucMode = 0x04;
- int nKV = HV_Handle_FLK(ucMode, 0, 0);// get current FLkv
- if (nKV != -1)
- {
- if (m_DoseUnit.m_FLKV->Update(nKV))
- FireNotify(AttrKey::FLUKV, m_DoseUnit.m_FLKV->JSGet());
- FINFO("get FLKV success!");
- }
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::SetFluKV(float nFLKV)
- {
- if (!m_DoseUnit.m_FLKV->Verify(nFLKV)) return RET_STATUS::RET_SUCCEED;
- BYTE ucMode = 0x05;
- FINFO("SetFLKV {$} begin!", nFLKV);
- int nCurrentFKV = HV_Handle_FLK(ucMode, (int)nFLKV, 0); // set FLKV
- if (nCurrentFKV != -1)
- {
- m_DoseUnit.m_FLKV->Update(nCurrentFKV);
- FireNotify(AttrKey::FLUKV, m_DoseUnit.m_FLKV->JSGet());
- FINFO("SetFLKV {$} success!", nCurrentFKV);
- }
- else
- {
- FINFO("SetFLKV failed!");
- return RET_STATUS::RET_SUCCEED;
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::IncFluMA()
- {
- if (!m_DoseUnit.m_FLMA->CanInc()) return RET_STATUS::RET_SUCCEED;
- BYTE ucMode = 0x01;
- int nCurrentMA = HV_Handle_FLM(ucMode, 0, 0); // FLMA increase 1
- if (nCurrentMA != -1)
- {
- if (m_DoseUnit.m_FLMA->Update(nCurrentMA))
- FireNotify(AttrKey::FLUMA, m_DoseUnit.m_FLMA->JSGet());
- FINFO("INCFLMA success!");
- }
- else
- {
- FINFO("INCFLMA failed!");
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::DecFluMA()
- {
- if (!m_DoseUnit.m_FLMA->CanDec()) return RET_STATUS::RET_SUCCEED;
- BYTE ucMode = 0x03;
- int nCurrentMA = HV_Handle_FLM(ucMode, 0, 0); // FLMA decrease 1
- if (nCurrentMA != -1)
- {
- if (m_DoseUnit.m_FLMA->Update(nCurrentMA))
- FireNotify(AttrKey::FLUMA, m_DoseUnit.m_FLMA->JSGet());
- FINFO("DECFLMA success!");
- }
- else
- {
- FINFO("DECFLMA failed!");
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::SetFluMA(float fFLMA)
- {
- if (!m_DoseUnit.m_FLMA->Verify(fFLMA)) return RET_STATUS::RET_SUCCEED;
- int nMA = (int)(fFLMA * 10);
- FINFO("SetFLKA {$} begin!", nMA);
- BYTE ucMode = 0x05;
- for (int i = 0; i < 3; i++)
- {
- int nCurrentMA = HV_Handle_FLM(ucMode, nMA, 0); // set FLMA
- if (nCurrentMA == nMA)
- {
- FINFO("SetFLKA {$} success!", nCurrentMA);
- break;
- }
- else
- {
- FINFO("SetFLKA failed!");
- Sleep(100);
- }
- }
- GetFluMA();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::INCPPS()
- {
- if (!m_DoseUnit.m_PPS->CanInc()) return RET_STATUS::RET_SUCCEED;
- BYTE ucMode = 0x01;
- float nFLPPS = HV_Handle_FLS(ucMode, 0, 0);// FLPPS increase 1
- if (-1 != nFLPPS)
- {
- if (m_DoseUnit.m_PPS->Update(nFLPPS))
- FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
- FINFO("INCPPS success!");
- }
- else
- {
- FINFO("INCPPS failed!");
- ucMode = 0x04;
- int nFLPPS = HV_Handle_FLS(ucMode, 0, 0);// get current FLPPS
- if (nFLPPS != -1)
- {
- if (m_DoseUnit.m_PPS->Update((float)nFLPPS))
- FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
- FINFO("get FLPPS success!");
- }
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::DECPPS()
- {
- if (!m_DoseUnit.m_PPS->CanDec()) return RET_STATUS::RET_SUCCEED;
- BYTE ucMode = 0x03;
- int nFLPPS = HV_Handle_FLS(ucMode, 0, 0);// FLPPS decrease 1
- if (-1 != nFLPPS)
- {
- if (m_DoseUnit.m_PPS->Update((float)nFLPPS))
- FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
- FINFO("DECPPS success!");
- }
- else
- {
- FINFO("DECPPS failed!");
- ucMode = 0x04;
- int nFLPPS = HV_Handle_FLS(ucMode, 0, 0);// get current FLkv
- if (nFLPPS != -1)
- {
- if (m_DoseUnit.m_PPS->Update((float)nFLPPS))
- FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
- FINFO("get FLPPS success!");
- }
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::SetPPS(float pps)
- {
- if (!m_DoseUnit.m_PPS->Verify(pps)) return RET_STATUS::RET_SUCCEED;
- m_fpps = pps;
- BYTE ucMode = 0x05;
- int npps = pps * 10;
- int nFLPPS = HV_Handle_FLS(ucMode, npps, 0);
- if (-1 != nFLPPS)
- {
- if (m_DoseUnit.m_PPS->Update((float)nFLPPS))
- FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
- FINFO("SetPPS success!");
- }
- else
- {
- FINFO("SetPPS failed!");
- ucMode = 0x04;
- int nFLPPS = HV_Handle_FLS(ucMode, 0, 0);// get current FLPPS
- if (nFLPPS != -1)
- {
- if (m_DoseUnit.m_PPS->Update((float)nFLPPS))
- FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
- FINFO("get FLPPS success!");
- }
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::SetABSMode(int nMode)
- {
- if (!m_DoseUnit.m_ABSStatus->Verify(nMode)) return RET_STATUS::RET_SUCCEED;
- if (nMode == 0 || nMode == 1 || nMode == 2) // currently RYGEN just support 0, 1, 2
- {
- int sendMode = 1;
- if (nMode == 0)
- {
- sendMode = 1;
- }
- else
- {
- sendMode = 3;
- }
- int nCurrentMode = HV_Handle_FLF(5, sendMode, 0); // set current FL mode
- if (nCurrentMode != -1)
- {
- FINFO("SetABSMode success!");
-
- if (nCurrentMode == 3)
- if (m_DoseUnit.m_ABSStatus->Update(1))
- FireNotify(AttrKey::FLUABSStatus, m_DoseUnit.m_ABSStatus->JSGet());
- else
- if (m_DoseUnit.m_ABSStatus->Update(0))
- FireNotify(AttrKey::FLUABSStatus, m_DoseUnit.m_ABSStatus->JSGet());
- FINFO("ABSMode:{$},nCurrentMode:{$} ", nMode, nCurrentMode);
- FINFO("m_nABSMode:{$},m_nDoseLevel:{$}", m_DoseUnit.m_ABSStatus->Get(), m_DoseUnit.m_DoseLevel->Get());
- }
- else
- {
- FINFO("SetABSMode failed!");
- }
- }
- else
- {
- FINFO("Don't supported ABS mode");
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::SetABSCurve(int curveNum)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::IncABSCurve()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::DecABSCurve()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::GetABSCurve()
- {
- return HWSend("FLA?", 4);
- }
- float nsGEN::RYGENDevice::GetFluIntTimer()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- float nsGEN::RYGENDevice::GetFluAccTimer()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::ResetFluTimer(int ntype)
- {
- if (ntype == 1)
- {
- int ret = HV_Handle_FLR(1, 0, 0);
- if (ret != -1)
- {
- FINFO("ResetTimer success!");
- if (m_DoseUnit.m_FLAccTime->Update(0.0f))
- FireNotify(AttrKey::FLUAccTime, m_DoseUnit.m_FLAccTime->JSGet());
- }
- else
- {
- FINFO("ResetTimer failed!");
- }
- }
- FINFO("ReSetFluAccTimer[{$}] \n", ntype);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::SetFluPre(int value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::SetFluEXP(int value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::SetFluMode(std::string value)
- {
- FINFO("Enter SetFLFMode...{$} \n", value.c_str());
- int nMode = 0;
- if (value == "CF")
- {
- nMode = 1;
- }
- else if (value == "PF")
- {
- nMode = 2;
- }
- if (nMode == 1 || nMode == 2) // currently RYGEN just support 0, 1, 2
- {
- m_DoseUnit.m_FLMode->Update(nMode);
- nMode--;
- FINFO("SetFlMode {$}!", nMode);
- int i = 3;
- while (i--)
- {
- int nCurrentMode = HV_Handle_PF(5, nMode, 0); // set current FL mode
- if (nCurrentMode != -1)
- {
- FINFO("SetFlMode success, return {$}!", nCurrentMode);
- if (nCurrentMode != nMode)
- {
- Sleep(100);
- continue;
- }
- else
- {
- break;
- }
- }
- else
- {
- FINFO("SetFlMode failed!");
- break;
- }
- }
- }
- else
- {
- FINFO("Don't supported fluoro mode");
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::SetFluDoseLever(int value)
- {
- FINFO("Enter SetFluDoseLever...{$} \n", value);
- // 提取当前剂量级别
- int currentDoseLevel = m_DoseUnit.m_DoseLevel->Get();
- // 只有在剂量级别发生变化时才继续处理
- if (currentDoseLevel == value) {
- return RET_STATUS::RET_SUCCEED;
- }
- float fma;
- // 计算新的FLMA值
- if (value == 1) {
- fma = 2 * m_DoseUnit.m_FLMA->Get();
- }
- else if (value == 0) {
- fma = 0.5 * m_DoseUnit.m_FLMA->Get();
- }
- else {
- FINFO("Invalid value:{$} \n", value);
- return RET_STATUS::RET_FAILED; // 非法值处理
- }
- // 更新剂量级别
- m_DoseUnit.m_DoseLevel->Update(value);
- return SetFluMA(fma);
- }
- RET_STATUS nsGEN::RYGENDevice::SetEXAMMode(std::string value)
- {
- //EXAMMODE_TYPE::MANUAL
- return RET_STATUS::RET_SUCCEED;
- }
- float nsGEN::RYGENDevice::GetKV()
- {
- BYTE ucMode = 0x04;
- int nKV = HV_Handle_KV(ucMode, 0, 0);
- m_DoseUnit.m_KV->Update(nKV);
- FireNotify("KV", m_DoseUnit.m_KV->JSGet());
- return true;
- }
- float nsGEN::RYGENDevice::GetMA()
- {
- BYTE ucMode = 0x04;
- int nCurrentMA = HV_Handle_MA(ucMode, 0, 0); // get current MA
- float fCurrentMA = (float)nCurrentMA;
- m_DoseUnit.m_MA->Update(fCurrentMA / 10.0f);
- FireNotify("MA", m_DoseUnit.m_MA->JSGet());
- return true;
- }
- float nsGEN::RYGENDevice::GetMS()
- {
- BYTE ucMode = 0x04;
- int nCurrentMS = HV_Handle_MS(ucMode, 0, 0); // get current MS
- float fCurrentMS = (float)nCurrentMS;
- m_DoseUnit.m_MS->Update(fCurrentMS / 100.0f);
- FireNotify("MS", m_DoseUnit.m_MS->JSGet());
- return true;
- }
- float nsGEN::RYGENDevice::GetMAS()
- {
- BYTE ucMode = 0x04;
- int nCurrentMAS = HV_Handle_MX(ucMode, 0, 0); // get current MAS
- if (nCurrentMAS != -1)
- {
- float fCurrentMAS = (float)nCurrentMAS;
- m_DoseUnit.m_MAS->Update(fCurrentMAS / 1000.0f);
- FireNotify("MAS", m_DoseUnit.m_MAS->JSGet());
- }
- return true;
- }
- float nsGEN::RYGENDevice::GetFluKV()
- {
- BYTE ucMode = 0x04;
- int nKV = HV_Handle_FLK(ucMode, 0, 0);// get current FLkv
- if (nKV != -1)
- {
- m_DoseUnit.m_FLKV->Update(nKV);
- FireNotify(AttrKey::FLUKV, m_DoseUnit.m_FLKV->JSGet());
- FINFO("get FLKV success!");
- }
- else
- {
- FINFO("get FLKV failed!");
- }
- return true;
- }
- float nsGEN::RYGENDevice::GetFluMA()
- {
- BYTE ucMode = 0x04;
- CString strlog;
- int nCurrentMA = HV_Handle_FLM(ucMode, 0, 0); // get current FLMA
- if (nCurrentMA != -1)
- {
- float fCurrentMA = (float)nCurrentMA;
- m_DoseUnit.m_FLMA->Update(fCurrentMA / 10.0f);
- FireNotify(AttrKey::FLUMA, m_DoseUnit.m_FLMA->JSGet());
- FINFO("GetFLMA success! nCurrentMA={$} m_fFLMA={$}", nCurrentMA, m_DoseUnit.m_FLMA->Get());
- }
- else
- {
- FINFO("GetFLMA failed!");
- }
- return true;
- }
- float nsGEN::RYGENDevice::GetFluMS()
- {
- return 0.0f;
- }
- bool nsGEN::RYGENDevice::GetABSMode()
- {
- int nCurrentMode = HV_Handle_FLF(4, 0, 0); // set current FL mode
- if (nCurrentMode != -1)
- {
- FINFO("GetABSMode success!");
- if (nCurrentMode == 3)
- {
- if (m_DoseUnit.m_ABSStatus->Update(1))
- FireNotify(AttrKey::FLUABSStatus, m_DoseUnit.m_ABSStatus->JSGet());
- }
- else
- {
- if (m_DoseUnit.m_ABSStatus->Update(0))
- FireNotify(AttrKey::FLUABSStatus, m_DoseUnit.m_ABSStatus->JSGet());
- }
- }
- return true;
- }
- bool nsGEN::RYGENDevice::GetAECDensityBuff(void)
- {
- int nRet = HV_Handle_FN(2, 0, 0);
- if (m_DoseUnit.m_AECDensity->Update(nRet))
- FireNotify(AttrKey::AECDENSITY, m_DoseUnit.m_AECDensity->JSGet());
- return true;
- }
- bool nsGEN::RYGENDevice::GetAECFieldBuff(void)
- {
- int nCurrentFiled = HV_Handle_FI(2, 0, 0);
- int nCurrentAECFieldSel = 0;
- if (nCurrentFiled & (0x01))
- {
- nCurrentAECFieldSel += 100;
- }
- if (nCurrentFiled & (0x02))
- {
- nCurrentAECFieldSel += 10;
- }
- if (nCurrentFiled & (0x04))
- {
- nCurrentAECFieldSel += 1;
- }
- FDEBUG("GetAECFieldBuff={$},nCurrentFiled={$}", nCurrentAECFieldSel, nCurrentFiled);
- if (m_DoseUnit.m_AECField->Update(nCurrentFiled))
- FireNotify(AttrKey::AECFIELD, m_DoseUnit.m_AECField->JSGet());
- return true;
- }
- RET_STATUS nsGEN::RYGENDevice::SetFrameRate(FLOAT frameRate)
- {
- m_DoseUnit.m_FrameRate->Update(frameRate); //this variable should be set when in oncallback.
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::SetRPS(int rps)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::RefreshData()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::SetExpEnable()
- {
- FINFO("SetExpEnable in ...\n");
- int nStatus = HV_GetST();
- if (nStatus == 200)
- {
- m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
- }
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::SetExpDisable()
- {
- FINFO("SetExpDisable in...\n");
- int nStatus = HV_GetST();
- if (nStatus == 200)
- {
- m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
- }
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- FINFO("SetExpDisable... {$}\n", m_DoseUnit.m_GenState->JSGet().c_str());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::RYGENDevice::Reset()
- {
- m_bResetActive = true;
- FINFO("RESET in...\n");
- int level = 0;
- if (m_bError)
- {
- m_MSGUnit->DelErrorMessage("0", level, "clear all errors");
- m_MSGUnit->DelWarnMessage("0", level, "clear all Warning");
- if (HV_Handle_CLR(0, 1, 0))
- {
- m_bError = false;
- FINFO("ReSet generator success, Clear Error,set apr command");
- }
- else
- {
- FINFO("ReSet generator fail");
- }
- }
- return RET_STATUS::RET_SUCCEED;
- }
- LRESULT nsGEN::RYGENDevice::RYAPIMSG(WPARAM wParam, LPARAM lParam)
- {
- int nMessageType = (int)wParam;
- switch (nMessageType)
- {
- case OBM_WPM_PR: //曝光曝光准备/结束
- {
- HandlePRMsg(int(lParam));
- }
- break;
- case OBM_WPM_XR: //曝光开始/结束
- {
- HandleXRMsg(int(lParam));
- }
- break;
- case OBM_WPM_ST: //系统状态反馈
- {
- HandleSTMsg(int(lParam));
- }
- break;
- case OBM_WPM_AT: //系统状态反馈
- {
- HandleATMsg(int(lParam));
- }
- break;
- case OBM_WPM_SV: //界面模式切换反馈
- {
- HandleSVMsg(int(lParam));
- }
- break;
- case OBM_WPM_TE: //技术参数反馈
- {
- HandleTEMsg(int(lParam));
- }
- break;
- case OBM_WPM_ER: //不可清错误反馈
- {
- HandleERMsg(int(lParam));
- }
- break;
- case OBM_WPM_EL: //可清错误反馈
- {
- HandleELMsg(int(lParam));
- }
- break;
- case OBM_WPM_COK: //本轮自动校管结束
- {
- HandleCOKMsg(int(lParam));
- }
- break;
- case OBM_WPM_CLR: //清除CLR状态
- {
- HandleCLRMsg(int(lParam));
- }
- break;
- case OBM_WPM_HE: //热容量模式
- {
- HandleHEMsg(int(lParam));
- }
- break;
- case OBM_WPM_FLP: //fluoro prepare
- {
- HandleFLPMsg(int(lParam));
- }
- break;
- case OBM_WPM_FLX: //fluoro exposure
- {
- HandleFLXMsg(int(lParam));
- }
- break;
- case OBM_WPM_FLK: //fluoro kv
- {
- HandleFLKMsg(int(lParam));
- }
- break;
- case OBM_WPM_FLM: //fluoro ma
- {
- HandleFLMMsg(int(lParam));
- }
- break;
- case OBM_WPM_FLF: //fluoro mode
- {
- HandleFLFMsg(int(lParam));
- }
- break;
- case OBM_WPM_FLI: //透视定时器累加时间
- {
- HandleFLIMsg(int(lParam));
- }
- break;
- case OBM_WPM_FLR: //透视定时器已清零
- {
- HandleFLRMsg(int(lParam));
- }
- break;
- case OBM_WPM_FLIW:
- {
- HandleFLIWMsg(int(lParam));
- }
- break;
- case OBM_WPM_KV:
- {
- FINFO("Enter OBM_WPM_KV lParam is {$}", int(lParam));
- int nKV = int(lParam);
- if (nKV >= 40) //曾经出现过kv0的情况,所以添加限制。
- {
- if (m_DoseUnit.m_KV->Update(nKV))
- FireNotify("KV", m_DoseUnit.m_KV->JSGet());
- }
- }
- break;
- case OBM_WPM_MS:
- {
- FINFO("Enter OBM_WPM_MS lParam is {$}", int(lParam));
- int nMS = int(lParam);
- if (m_DoseUnit.m_MS->Update(nMS))
- FireNotify("MS", m_DoseUnit.m_MS->JSGet());
- }
- break;
- case OBM_WPM_MA:
- {
- FINFO("Enter OBM_WPM_MA lParam is {$}", int(lParam));
- int nMA = int(lParam);
- if (m_DoseUnit.m_MA->Update(nMA))
- FireNotify("MA", m_DoseUnit.m_MA->JSGet());
- }
- break;
- }
- return 0;
- }
- RET_STATUS nsGEN::RYGENDevice::HWSend(char* strCommand, int nTimeOut)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- //-----------------------------------------------------------------------------
- // ProcessCmd
- //-----------------------------------------------------------------------------
- void nsGEN::RYGENDevice::FireNotify(std::string key, std::string content)
- {
- EventCenter->OnNotify(1, key, content);
- }
- struct tFrameMapping
- {
- static const int MaxLen = 5; // 前缀不能超超过 5 个字符 !
- using cbFun = std::function <void(const char*, int)>;
- char strHead[MaxLen];
- int NbOfCharOfHead;
- cbFun fun;
- tFrameMapping(char* str, int len, cbFun f)
- {
- assert(len < MaxLen); //len最大只能是4
- //strHead[0] = 0x02; //STX ----------->note : no package header
- for (int i = 0; i < len; i++) //给strHead赋值
- strHead[i] = str[i];
- NbOfCharOfHead = len;
- fun = f;
- }
- };
- static std::list <tFrameMapping> arFrame;
- static bool DecodeFrame(const char* strFrame, int length);
- LRESULT CALLBACK nsGEN::RYGENDevice::OnCallBack(void* obj, UINT message, WPARAM wParam, LPARAM lParam)
- {
- RYGENDevice* unit = (RYGENDevice*)obj;
- if (unit == nullptr)
- {
- FINFO("Enter OnCallBack: RYGENDevice is null");
- return false;
- }
- int wmId, wmEvent;
- PAINTSTRUCT ps;
- HDC hdc;
- FDEBUG("Enter OnCallBack: message[{$}],wParam[{$}],lParam[{$}]", (int)message, (int)wParam, (int)lParam);
- switch (message)
- {
- case WM_COMMAND:
- wmId = LOWORD(wParam);
- wmEvent = HIWORD(wParam);
- // 分析菜单选择:
- switch (wmId)
- {
- case 0:
- break;
- }
- switch (wmId)
- {
- case 0:
-
- break;
- default:
-
- break;
- }
- case WM_HV_TABLE_IO_MESSAGE:
- unit->RYAPIMSG(wParam, lParam);
- break;
-
- }
- return 0;
- }
- bool nsGEN::RYGENDevice::StartHardwareStatusThread()
- {
- FINFO("enter Start HardwareStatus Thread ");
- if (m_pHardwareStatusThread == NULL)
- {
- DWORD m_HardwareStatusID;
- m_pHardwareStatusThread = CreateThread(0, 0, HardwareStatusThread, this, 0, &m_HardwareStatusID);
- if (m_pHardwareStatusThread == NULL)
- {
- Fatal("Start HardwareStatus Thread Failed");
- return false;
- }
- }
- return true;
- }
- DWORD nsGEN::RYGENDevice::HardwareStatusThread(LPVOID pParam)
- {
- RYGENDevice* pCurGen = (RYGENDevice*)pParam;
- if (pCurGen == NULL)
- {
- return false;
- }
- if ((int)pCurGen->m_GenConfig["loopTime"] >= 100)
- {
- pCurGen->m_iLoopTime = (int)pCurGen->m_GenConfig["loopTime"];
- }
- FDEBUG("loopTime = {$}", pCurGen->m_iLoopTime.load());
- int currtTime = pCurGen->m_iLoopTime;
- FINFO("HardwareStatusThread start");
- while (false)
- {
- if (pCurGen->m_iLoopTime!= currtTime)
- {
- FINFO("pCurGen->m_iLoopTime");
- }
- currtTime = pCurGen->m_iLoopTime;
- Sleep(currtTime);
- }
-
- FINFO("HardwareStatusThread stop");
- return true;
- }
- void nsGEN::RYGENDevice::HandlePRMsg(int nMessageValue)
- {
- FINFO("Enter HandlePRMsg lParam is {$}", nMessageValue);
- if (LPM_CONSOLE_PR1 == nMessageValue)
- {
- m_iLoopTime = RYGEN_LoopExpTime;
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_PREPARE);
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- else if (LPM_CONSOLE_PR2 == nMessageValue)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_READY);
- ResetEvent(m_hGenPostEvent);
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- else if (LPM_CONSOLE_PR0 == nMessageValue)
- {
- if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF));
- {
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- }
- }
- void nsGEN::RYGENDevice::HandleXRMsg(int nMessageValue)
- {
- FINFO("Enter HandleXRMsg lParam is {$}", nMessageValue);
- if (nMessageValue == LPM_CONSOLE_XR1)
- {
- if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_EXP))
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
-
- if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON))
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- else if (nMessageValue == LPM_CONSOLE_XR0)
- {
- if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYOFF))
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
-
- }
- }
- void nsGEN::RYGENDevice::HandleSTMsg(int nMessageValue)
- {
- FINFO("Enter HandleSTMsg lParam is {$}", nMessageValue);
- switch (nMessageValue)
- {
- case LPM_CONSOLE_ST000:
- {
- }
- break;
- case LPM_CONSOLE_ST001:
- {
- }
- break;
- case LPM_CONSOLE_ST100:
- case LPM_CONSOLE_ST101:
- case LPM_CONSOLE_ST102:
- case LPM_CONSOLE_ST103:
- case LPM_CONSOLE_ST104:
- case LPM_CONSOLE_ST105:
- case LPM_CONSOLE_ST106:
- {
- }
- break;
- case LPM_CONSOLE_ST200:
- {
- int nVal = HV_Handle_SV(1, 0, 0);
- int nRet = -1;
- if (nVal != 0)
- {
- nRet = HV_Handle_SV(0, 0, 0); // enter work mode
- if (nRet == -1)
- {
- FINFO("HV_Handle_SV work failed");
- }
- }
- nVal = HV_Handle_EM(4, 0, 0);
- if (nVal != 1)
- {
- nRet = HV_Handle_EM(5, 1, 0);
- if (nRet == -1)
- {
- FINFO("HV_Handle_EM work failed");
- }
- }
- UpdateGenParamter();
- GetFluKV();
- GetFluMA();
- GetABSMode();
- if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY))
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- }
- break;
- }
- }
- void nsGEN::RYGENDevice::HandleATMsg(int nMessageValue)
- {
- FINFO("Enter HandleATMsg lParam is {$}", nMessageValue);
- }
- void nsGEN::RYGENDevice::HandleSVMsg(int nMessageValue)
- {
- FINFO("Enter HandleSVMsg lParam is {$}", nMessageValue);
- if (nMessageValue == LPM_CONSOLE_SV0)
- {
- int nRet = HV_Handle_EM(5, 1, 0);
- if (nRet == -1)
- {
- FINFO("HV_Handle_EM work failed");
- }
- SetFLFMode(m_strFLFMode);
- SetPPS(m_fpps);
- SetTechmode(m_nPreET);
- _tAPRArgs t;
- t.nWS = m_nPreWS;
- t.fKV = m_nPreKV;
- t.fMA = m_fPreMA;
- t.fMS = m_fPreMS;
- t.fMAS = m_fPreMAS;
- t.nAECDensity = m_nPreAECDensity;
- t.nAECField = m_nPreAECFieldSel;
- t.nAECFilm = m_nPreAECFilmSel;
- t.nFocus = m_nPreFO;
- t.nTechmode = m_nPreET;
- SetAPR(t);
- int nABSMode = m_DoseUnit.m_ABSStatus->Get();
- int nFLF = m_DoseUnit.m_FLMode->Get();
- _tAPFArgs tf;
- tf.nFluMode = m_DoseUnit.m_FLMode->Get();
- tf.nABSMode = m_DoseUnit.m_ABSStatus->Get();
- tf.nFLKV= m_DoseUnit.m_FLKV->Get();
- tf.fFLMA = m_DoseUnit.m_FLMA->Get();
- SetAPF(tf);
- }
- }
- void nsGEN::RYGENDevice::HandleTEMsg(int nMessageValue)
- {
- if (m_DoseUnit.m_Techmode->Update(nMessageValue))
- FireNotify(AttrKey::TECHMODE, m_DoseUnit.m_Techmode->JSGet());
- if (m_DoseUnit.m_Techmode->Get() != 2)
- {
- if (m_DoseUnit.m_AECField->Get() != 0)
- {
- FireNotify(AttrKey::AECFIELD, "0");
- }
- }
- FINFO("Enter HandleTEMsg lParam is {$}", nMessageValue);
- }
- void nsGEN::RYGENDevice::HandleERMsg(int nMessageValue)
- {
- m_bError = true;
- char ErrorCode[20]; // Adjust size as needed
- sprintf_s(ErrorCode, sizeof(ErrorCode), "RYGEN_ERR_%d", nMessageValue);
- FINFO("error code:{$}", ErrorCode); // Logging the error code
- // Error message initialization
- std::string errorMsg;
- // Switch statement to assign the correct error message based on nMessageValue
- switch (nMessageValue) {
- case 0: errorMsg = "Communication failure between main control and console."; break;
- case 1: errorMsg = "Stage 1 brake engagement detected during self-test."; break;
- case 2: errorMsg = "Stage 2 brake engagement detected during self-test."; break;
- case 3: errorMsg = "Main control issued a soft start signal; PHVOK signal from power board not received within 2 seconds."; break;
- case 4: errorMsg = "Bus voltage AD feedback value too high during soft start."; break;
- case 5: errorMsg = "Bus voltage AD feedback value too low during soft start."; break;
- case 6: errorMsg = "SAMFAULT signal low level detected during self-test on the main control board."; break;
- case 7: errorMsg = "Bus voltage AD feedback value too high after main contactor engagement."; break;
- case 8: errorMsg = "Bus voltage AD feedback value too low after main contactor engagement."; break;
- case 9: errorMsg = "SLINK high level detected during self-test, possibly KV/MA feedback line not connected to tank."; break;
- case 10: errorMsg = "STLOW low output detected during self-test on the start board."; break;
- case 11: errorMsg = "Filament board FLIAFAULT hard signal low level detected before heating filament during self-test."; break;
- case 12: errorMsg = "Small filament current AD feedback fault detected after heating small filament during self-test."; break;
- case 13: errorMsg = "FLIAFAULT hard signal low level detected after heating large filament during self-test."; break;
- case 14: errorMsg = "Large filament AD feedback fault detected after heating during self-test."; break;
- case 15: errorMsg = "PHVOK signal detected high during standby."; break;
- case 16: errorMsg = "High bus voltage AD feedback value detected during standby."; break;
- case 17: errorMsg = "Low bus voltage AD feedback value detected during standby."; break;
- case 18: errorMsg = "Tube temperature control signal fault detected during standby."; break;
- case 19: errorMsg = "Main control to tank KV/MA feedback line not connected detected during standby."; break;
- case 20: errorMsg = "Fault detected during read/write of 2864."; break;
- case 21: errorMsg = "Stage 1 brake pressed under configuration interface."; break;
- case 22: errorMsg = "Low filament current AD feedback value detected during standby filament pre-heating."; break;
- case 23: errorMsg = "High filament current AD feedback value detected during standby filament pre-heating."; break;
- case 24: errorMsg = "Filament current exceeds maximum value, FILAFAULT hard signal interrupts."; break;
- case 25: errorMsg = "SAMFAULT interrupts."; break;
- case 26: errorMsg = "Interrupts caused by other signals."; break;
- case 28: errorMsg = "FILIAFAULT signal low level detected during filament rapid heating process."; break;
- case 29: errorMsg = "STLOW low level detected after tube starts during post-self-test."; break;
- case 30: errorMsg = "Communication failure between main control and console during exposure preparation."; break;
- case 33: errorMsg = "No signal detected for stage 2 brake during self-test."; break;
- case 34: errorMsg = "Communication failure; no signal return from console within 1 second after sending XR1."; break;
- case 35: errorMsg = "KVAD feedback too low fault; KV not rising to 75% of set value within 1ms after exposure starts."; break;
- case 38: errorMsg = "Hand 2 not released more than 8 seconds after exposure ends."; break;
- case 39: errorMsg = "Hand 1 not released more than 10 seconds after exposure ends."; break;
- case 40: errorMsg = "AECEND signal fault detected just as automatic exposure starts."; break;
- case 41: errorMsg = "Door switch fault."; break;
- case 42: errorMsg = "FILIAFAULT signal low level detected during filament rapid heating process."; break;
- case 43: errorMsg = "STLOW low level detected after tube starts."; break;
- case 44: errorMsg = "Communication failure during preparation process."; break;
- case 45: errorMsg = "Hand 2 not received more than 6 seconds after tube is ready."; break;
- case 47: errorMsg = "KVAD feedback too low fault; KV not rising to 75% of set value within 1ms after exposure starts."; break;
- case 48: errorMsg = "AECEND not received, stage 2 brake released prematurely."; break;
- case 49: errorMsg = "Hand 1 not released more than 10 seconds after exposure ends."; break;
- case 50: errorMsg = "Door switch fault."; break;
- case 51: errorMsg = "FILAFAULT fault."; break;
- case 52: errorMsg = "STLOW fault detected during first start-up."; break;
- case 53: errorMsg = "Communication failure during exposure preparation."; break;
- case 54: errorMsg = "Hand 2 signal not received more than 6 seconds."; break;
- case 55: errorMsg = "Stage 2 brake released prematurely."; break;
- case 56: errorMsg = "Communication fault during exposure."; break;
- case 57: errorMsg = "KVAD feedback too low fault; KV not rising to 75 % of set value within 1ms after exposure starts."; break;
- case 58: errorMsg = "Hand brake released prematurely."; break;
- case 61: errorMsg = "Small focus filament value too high, exceeding 2350."; break;
- case 62: errorMsg = "Large focus filament value too high, exceeding 2100."; break;
- case 63: errorMsg = "Continuous two - point calibration failure, automatic tube training fails."; break;
- case 64: errorMsg = "Filament current AD feedback value detected below 20 % of set value after filament heating."; break;
- case 65: errorMsg = "Filament current AD feedback value detected above 20 % of set value after filament heating."; break;
- case 66: errorMsg = "Filament current AD feedback value detected below 20 % of set value after filament heating."; break;
- case 67: errorMsg = "Filament current AD feedback value detected above 20 % of set value after filament heating."; break;
- case 70: errorMsg = "PHVOK high level detected by main control 3 seconds after main contactor powers up."; break;
- case 73: errorMsg = "High anode auxiliary winding current AD feedback value detected during tube start(dual - speed board)."; break;
- case 74: errorMsg = "Low anode main winding current AD feedback value detected during tube start(dual - speed board)."; break;
- case 75: errorMsg = "Low anode main winding current AD feedback value detected during tube start(dual - speed board)."; break;
- case 82: errorMsg = "High anode main winding current AD feedback value detected during tube start."; break;
- case 83: errorMsg = "Low anode main winding current AD feedback value detected during tube start."; break;
- case 84: errorMsg = "Low anode auxiliary winding current AD feedback value detected during tube start."; break;
- case 85: errorMsg = "High anode auxiliary winding current AD feedback value detected during tube start."; break;
- case 86: errorMsg = "Hand 2 not released more than 5 seconds after exposure ends."; break;
- case 160: errorMsg = "High filament value detected."; break;
- case 207: errorMsg = "Communication fault during exposure."; break;
- case 214: errorMsg = "Encountered unsuitable parameters."; break;
- default: errorMsg = "HandleERMsg:unknown error."; break; // Default case for unknown error codes
- }
- int level = 1; // Assuming error level 1 for all cases, adjust as needed
- m_MSGUnit->AddErrorMessage(ErrorCode, level, errorMsg.c_str());
- m_localErrorlist.push_back(ErrorCode); // Adding error code to local error list
- }
- void nsGEN::RYGENDevice::HandleELMsg(int nMessageValue)
- {
- m_bError = true;
- char ErrorCode[20]; // 根据需要调整数组大小
- sprintf_s(ErrorCode, sizeof(ErrorCode), "RYGEN_EL_%d", nMessageValue);
- FINFO("error code:{$} \n", ErrorCode);
- std::string errorMsg;
- // Switch statement to assign the correct error message based on nMessageValue
- switch (nMessageValue) {
- case 12: errorMsg = "Small filament current AD feedback fault detected after heating small filament during self - test."; break;
- case 14: errorMsg = "Large filament AD feedback fault detected after heating large filament during self - test."; break;
- case 17: errorMsg = "timeout_prpe."; break;
- case 25: errorMsg = "SAMFAULT interrupts."; break;
- case 27: errorMsg = "Stage 1 brake pressed, enters normal photography program, high - level door switch signal detected."; break;
- case 29: errorMsg = "STLOW low level detected after tube starts during post - self - test."; break;
- case 31: errorMsg = "Hand 2 signal not received more than 9 seconds after tube is ready."; break;
- case 32: errorMsg = "High - level door switch detected."; break;
- case 33: errorMsg = "No signal detected for stage 2 brake during self - test."; break;
- case 46: errorMsg = "Door switch fault."; break;
- case 60: errorMsg = "High tube heat capacity HEVALUE error."; break;
- case 103: errorMsg = "No feedback signal received from tablet."; break;
- case 160: errorMsg = "High filament value detected."; break;
- case 200: errorMsg = "AEC feature used in spot filming mode."; break;
- case 207: errorMsg = "Communication fault during exposure."; break;
- default: errorMsg = "HandleELMsg:unknown error."; break; // Default case for unknown error codes
- }
- int level = 1;
- m_MSGUnit->AddErrorMessage(ErrorCode, level, errorMsg.c_str());
- m_localErrorlist.push_back(ErrorCode);
- }
- void nsGEN::RYGENDevice::HandleCOKMsg(int nMessageValue)
- {
- FINFO("Enter HandleCOKMsg lParam is {$}", nMessageValue);
- }
- void nsGEN::RYGENDevice::HandleCLRMsg(int nMessageValue)
- {
- FINFO("Enter HandleCLRMsg lParam is {$}", nMessageValue);
-
- if (nMessageValue == LPM_CONSOLE_CLR1)
- FINFO("清除CLR有效");
- }
- void nsGEN::RYGENDevice::HandleHEMsg(int nMessageValue)
- {
- FINFO("Enter HandleHEMsg lParam is {$}", nMessageValue);
- if (m_DoseUnit.m_HE->Update(nMessageValue))
- FireNotify(m_DoseUnit.m_HE->GetKey(), m_DoseUnit.m_HE->JSGet());
- }
- void nsGEN::RYGENDevice::HandleFIMsg(int nMessageValue)
- {
- FINFO("Enter HandleFIMsg lParam is {$}", nMessageValue);
- }
- void nsGEN::RYGENDevice::HandleFNMsg(int nMessageValue)
- {
- FINFO("Enter HandleFNMsg lParam is {$}", nMessageValue);
- }
- void nsGEN::RYGENDevice::HandleFSMsg(int nMessageValue)
- {
- FINFO("Enter HandleFSMsg lParam is {$}", nMessageValue);
- }
- void nsGEN::RYGENDevice::HandleFLPMsg(int nMessageValue)
- {
- FINFO("Enter HandleFLPMsg lParam is {$}", nMessageValue);
- if (nMessageValue == LPM_CONSOLE_FLP0)
- {
- if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_OFF))
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
-
- FINFO("The foot brake up!!!");
- }
- else if (nMessageValue == LPM_CONSOLE_FLP1)
- {
- if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_READY))
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- FINFO("Foot brake down!!!");
- }
- else
- {
- FINFO("Wrong message");
- }
- }
- void nsGEN::RYGENDevice::HandleFLXMsg(int nMessageValue)
- {
- FINFO("Enter HandleFLXMsg lParam is{$}", nMessageValue);
- if (nMessageValue == LPM_CONSOLE_FLX0)
- {
- if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_XRAYOFF))
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- //UpdateGenParamter();
- FINFO("The generator is off line!!!");
- }
- else if (nMessageValue == LPM_CONSOLE_FLX1)
- {
- if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_XRAYON))
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_EXP))
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- FINFO("The generator is out of line!!!");
- }
- else
- {
- FINFO("Wrong message");
- }
- }
- void nsGEN::RYGENDevice::HandleFLKMsg(int nMessageValue)
- {
- FINFO("Enter HandleFLKMsg lParam is {$}", nMessageValue);
- if (m_DoseUnit.m_FLKV->Update(nMessageValue))
- FireNotify(AttrKey::FLUKV, m_DoseUnit.m_FLKV->JSGet());
- }
- void nsGEN::RYGENDevice::HandleFLMMsg(int nMessageValue)
- {
- FINFO("Enter HandleFLMMsg lParam is {$}", nMessageValue);
- if (nMessageValue + 5 <= 200)
- {
- if (m_DoseUnit.m_FLMA->Update((float)(nMessageValue + 5) / 10.0f))
- FireNotify(AttrKey::FLUMA, m_DoseUnit.m_FLMA->JSGet());
- }
- else
- {
- if (m_DoseUnit.m_FLMA->Update(20 + (nMessageValue - 195)))
- FireNotify(AttrKey::FLUMA, m_DoseUnit.m_FLMA->JSGet());
- }
- }
- void nsGEN::RYGENDevice::HandleFLFMsg(int nMessageValue)
- {
- FINFO("Enter HandleFLFMsg lParam is {$}", nMessageValue);
- int nABSMode = 0;
- if (nMessageValue == 3)
- {
- nABSMode = 1;
- }
- else
- {
- nABSMode = 0;
- }
- if (m_DoseUnit.m_ABSStatus->Update(nABSMode))
- {
- FireNotify(AttrKey::FLUABSStatus, m_DoseUnit.m_ABSStatus->JSGet());
- FINFO("m_nABSMode = {$}", m_DoseUnit.m_ABSStatus->JSGet().c_str());
- }
- }
- void nsGEN::RYGENDevice::HandleFLIMsg(int nMessageValue)
- {
- FINFO("Enter HandleFLIMsg lParam is {$}", nMessageValue);
- if (m_DoseUnit.m_FLAccTime->Update(nMessageValue))
- {
- std::string strFlAccTime = m_DoseUnit.m_FLAccTime->JSGet() + "s";
- FireNotify(AttrKey::FLUAccTime, m_DoseUnit.m_FLAccTime->JSGet());
- }
- FINFO("callback: m_fFLAccTime = {$}", m_DoseUnit.m_FLAccTime->JSGet().c_str());
- }
- void nsGEN::RYGENDevice::HandleFLRMsg(int nMessageValue)
- {
- FINFO("Enter HandleFLRMsg lParam is {$}", nMessageValue);
- }
- void nsGEN::RYGENDevice::HandleFLIWMsg(int nMessageValue)
- {
- FINFO("Enter HandleFLIWMsg lParam is {$}", nMessageValue);
- }
- bool nsGEN::RYGENDevice::UpdateGenParamter()
- {
- BYTE ucMode = 0x03;
- int iRrValue = 0;
- iRrValue = HV_Handle_RR(0, 0);
- if (1 == iRrValue)
- {
- FINFO("HV_Handle_RR success");
- GetKV();
- GetMA();
- GetMS();
- GetMAS();
- GetAECDensityBuff();
- GetAECFieldBuff();
- //GetFlMode();
- return true;
- }
- else
- {
- FINFO("HV_Handle_RR failed");
- }
- return true;
- }
- //-----------------------------------------------------------------------------
- // RYGENDriver
- //-----------------------------------------------------------------------------
- nsGEN::RYGENDriver::RYGENDriver()
- {
- m_bDemoMode = false;
- m_bDemoConnected = false;
- m_bGenConnectReal = false;
- m_pUIOBJ = nullptr;
- m_pUIOBJ = new UIObject();
- FDEBUG("Init Gen Configuration Succeed[{$}]", (int)m_pUIOBJ);
- }
- nsGEN::RYGENDriver::~RYGENDriver()
- {
- m_pUIOBJ->Destrory();
- delete m_pUIOBJ;
- }
- auto nsGEN::RYGENDriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
- {
- FINFO("CreateDevice in\n");
- if (m_pUIOBJ->Create())
- {
- m_bGenConnectReal = true;
- FDEBUG("Connect successful");
- }
- else
- {
- m_bGenConnectReal = false;
- m_pUIOBJ->Destrory();
- }
- if (m_pUIOBJ)
- {
- m_pDevice = new RYGENDevice(EventCenter, m_pUIOBJ, m_ConfigFileName);
- auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDevice));
- FINFO("CreateDevice out\n");
- return dev;
- }
- return NULL;
- }
- void nsGEN::RYGENDriver::FireNotify(int code, std::string key, std::string content)
- {
- EventCenter->OnNotify(code, key, content);
- }
- Log4CPP::Logger* gLogger = nullptr;
- void nsGEN::RYGENDriver::Prepare()
- {
- string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Generator\Conf\Log4CPP.Config.GEN.xml)";
- Log4CPP::GlobalContext::Map::Set(ECOM::Utility::Hash("LogFileName"), "GEN.RYGEN");
- auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
- gLogger = Log4CPP::LogManager::GetLogger("GEN.RYGEN");
- FINFO("Enter Prepare.");
- ResDataObject r_config;
- if (r_config.loadFile(m_ConfigFileName.c_str()))
- {
- m_bDemoMode = (atoi)(((string)r_config["CONFIGURATION"]["IsDemo"]).c_str());
- }
- super::Prepare();
- }
- bool nsGEN::RYGENDevice::InitGen()
- {
- if (m_pUIOBJ->GetUI() == nullptr) {
- FINFO("The window handle is empty!");
- }
- if (!HV_SetMsghWnd(m_pUIOBJ->GetUI())) {
- FINFO("HV_SetMsghWnd:UNConnect");
- return false;
- }
- FINFO("API_HV_SetMsghWnd success!");
- HV_SetCanConfig();
- FINFO("API_HV_SetCanConfig success!");
- if (!HV_AddCanID(0x420, 0x401, 0)) {
- FINFO("HV_AddCanID:UNConnect");
- return false;
- }
- FINFO("API_HV_AddCanID success!");
- HV_Init_ST();
- FINFO("API_HV_Init_ST success!");
- if (!HV_OpenCanDriver()) {
- FINFO("HV_OpenCanDriver:UNConnect");
- return false;
- }
- FINFO("API_HV_OpenCanDriver success!");
- if (!HV_StartCanDriver()) {
- FINFO("HV_StartCanDriver:UNConnect");
- return false;
- }
- FINFO("API_HV_StartCanDriver success!");
- if (!HV_ClearCanBuffer()) {
- FINFO("HV_ClearCanBuffer:UNConnect");
- return false;
- }
- FINFO("HV_ClearCanBuffer success!");
- // 最终处理函数
- int nStatus = HV_Handle_ST(0, 0, 0);
- //HandleSTMsg(nStatus);
- FINFO("GEN STATUS :{$}!", nStatus);
- return SCF_ERR::SCF_SUCCEED; // 确保只有全部成功才返回
- }
- bool DATA_ACTION nsGEN::RYGENDriver::Connect()
- {
- FINFO("Enter {$},configlef={$}\n", __FUNCTION__, m_ConfigFileName.c_str());
- return m_bGenConnectReal;
- }
- void nsGEN::RYGENDriver::Disconnect()
- {
- FDEBUG("Enter [{$}]", __FUNCTION__);
- Close();
- gLogger = nullptr;
- }
- bool nsGEN::RYGENDriver::isConnected() const
- {
- if (m_pDevice == NULL)
- {
- return false; //return 0;
- }
- if (m_pDevice->LoadConfig(m_ConfigFileName) == -1)
- {
- return false; //return 0;
- }
- return m_bGenConnectReal;
- }
- std::string nsGEN::RYGENDriver::DriverProbe()
- {
- FDEBUG("Enter [{$}]", __FUNCTION__);
- 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", "RYGEN");
- HardwareInfo.add("ProductID", "HF");
- HardwareInfo.add("SerialID", "Drv");
- }
- string ret = HardwareInfo.encode();
- return ret;
- }
- std::string nsGEN::RYGENDriver::GetResource()
- {
- ResDataObject temp;
- if (!temp.loadFile(m_ConfigFileName.c_str()))
- return std::string();
- auto r_config = temp["CONFIGURATION"];
- for (auto& Item : m_ConfigInfo)
- {
- string key = Item.GetKey();
- if (key == ConfKey::CcosGeneratorType)
- {
- Item.SetCurrentValue(((string)r_config["VendorID"]).c_str());
- }
- else if (key == ConfKey::CcosGeneratorModel)
- {
- Item.SetCurrentValue(((string)r_config["ProductID"]).c_str());
- }
- else if (key == ConfKey::CcosWSTable || key == ConfKey::CcosWSWall || key == ConfKey::CcosWSFree
- || key == ConfKey::CcosWSTomo || key == ConfKey::CcosWSConventional)
- {
- Item.SetCurrentValue(((string)r_config[key.c_str()]).c_str());
- }
- else if (key == ConfKey::CcosSynTable || key == ConfKey::CcosSynWall || key == ConfKey::CcosSynFree
- || key == ConfKey::CcosSynTomo || key == ConfKey::CcosSynConventional)
- {
- Item.SetCurrentValue(((string)r_config[key.c_str()]).c_str());
- }
- else if (key == ConfKey::CcosSCFType)
- {
- Item.SetCurrentValue(((string)r_config["connections"][0]["type"]).c_str());
- }
- else if (key == ConfKey::CcosSCFPort || key == ConfKey::CcosSCFBaudrate || key == ConfKey::CcosSCFBytesize
- || key == ConfKey::CcosSCFParity || key == ConfKey::CcosSCFStopbits || key == ConfKey::CcosSCFIP)
- {
- if (r_config["connections"][0].GetFirstOf(key.c_str()) >= 0)
- {
- Item.SetCurrentValue(((string)r_config["connections"][0][key.c_str()]).c_str());
- }
- }
- }
- ResDataObject resAttr, resDescription;
- for (auto Item : m_ConfigInfo)
- {
- resAttr.add(Item.GetKey(), Item.GetCurrentValue());
- resDescription.add(Item.GetKey(), Item.GetDescription());
- }
- ResDataObject resDeviceResource;
- resDeviceResource.add(ConfKey::CcosGeneratorAttribute, resAttr);
- resDeviceResource.add(ConfKey::CcosGeneratorDescription, resDescription);
- string res = resDeviceResource.encode();
- //printf("resDeviceResource :%s \n", resDeviceResource.encode());
- FINFO("resDeviceResource :{$} \n", resDeviceResource.encode());
- ResDataObject DescriptionTempEx;
- DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
- m_DeviceConfig.clear();
- m_DeviceConfig = DescriptionTempEx;
- return res;
- }
- bool nsGEN::RYGENDriver::GetDeviceConfig(std::string& Cfg)
- {
- //Cfg = m_DeviceConfigSend.encode();
- Cfg = m_DeviceConfig.encode();
- //printf("GetDeviceConfig over");
- printf("GetDeviceConfig over , %s", Cfg.c_str());
- return true;
- }
- bool nsGEN::RYGENDriver::SetDeviceConfig(std::string Cfg)
- {
- FINFO("--Func-- SetDeviceConfig {$}\n", Cfg.c_str());
- return true;
- #if 0
- ResDataObject DeviceConfig;
- DeviceConfig.decode(Cfg.c_str());
- ResDataObject DescriptionTempEx;
- DescriptionTempEx = DeviceConfig["DeviceConfig"]["Attribute"];
- FDEBUG("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]))
- {
- FDEBUG("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);
- }
- #endif // 0
- return true;
- }
- bool nsGEN::RYGENDriver::SaveConfigFile(bool bSendNotify)
- {
- m_ConfigAll["CONFIGURATION"] = m_Configurations;
- bool bRt = m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
- FINFO("SaveConfigFile over {$}", bRt);
- return true;
- }
- std::string nsGEN::RYGENDriver::DeviceProbe()
- {
- FDEBUG("Enter [{$}]", __FUNCTION__);
- 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", "RYGEN");
- HardwareInfo.add("ProductID", "HF");
- HardwareInfo.add("SerialID", "1234");
- }
- string ret = HardwareInfo.encode();
- FINFO("std::string nsGEN::PSGRFDriver::DeviceProbe() out\n");
- return ret;
- }
- void nsGEN::RYGENDriver::Dequeue(const char* Packet, DWORD Length)
- {
- DecodeFrame(Packet, Length);
- }
- PACKET_RET nsGEN::RYGENDriver::callbackPackageProcess(const char* RecData, DWORD nLength, DWORD& PacketLength)
- {
- return PACKET_ISPACKET;
- }
- //-----------------------------------------------------------------------------
- // DecodeFrame
- //-----------------------------------------------------------------------------
- static bool DecodeFrame(const char* strFrame, int length)
- {
- return true;
- }
- //-----------------------------------------------------------------------------
- // GetIODriver & CreateIODriver
- //-----------------------------------------------------------------------------
- static nsGEN::RYGENDriver gIODriver;
- extern "C" CCOS::Dev::IODriver * __cdecl GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
- {
- return &gIODriver;
- }
- extern "C" CCOS::Dev::IODriver * __cdecl CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
- {
- return new nsGEN::RYGENDriver();
- }
|