123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337 |
- #include <assert.h>
- #include "Helper.JSON.hpp"
- #include "CCOS.Dev.Generator.Demo.hpp"
- #include "LogLocalHelper.h"
- #include "Log4CPP.h"
- using namespace CCOS::Dev::Detail::Generator;
- namespace nsGEN = CCOS::Dev::Detail::Generator;
- #pragma warning (disable:4305)
- #define DEMO_DAEC_Flag 1
- //-----------------------------------------------------------------------------
- // DemoDevice
- //-----------------------------------------------------------------------------
- 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 };
- float g_KV_List[] = { 400, 405, 410, 415, 420, 430, 440, 450, 460, 470, 480, 490, 500, 510, 520, 535, 550, 560, 570, 585, 600, 615, 630, 645, 660, 680, 700, 715, 730, 750, 770, 790, 810, 830, 850, 875, 900, 930, 960, 1000, 1020, 1050, 1090, 1130, 1170, 1210, 1250, 1290, 1330, 1370, 1410, 1450, 1500 };//<!--KV * 10-->
- int g_AECFIELD_List[] = { 1, 10, 100, 11, 101, 110, 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 };
- std::unique_ptr<OemCollimator> nsGEN::DemoDevice::m_pCollDev = nullptr; //遮光器逻辑实体指针
- std::unique_ptr<OemMechanical> nsGEN::DemoDevice::m_pMechDev = nullptr; //机架逻辑实体指针
- template<typename T>
- int FindPositon(T* pList, int nListSize, T& value)
- {
- if (pList == NULL || nListSize == 0) return -1;
- if (value <= pList[0])
- {
- value = pList[0];
- return 0;
- }
- if (value >= pList[nListSize - 1])
- {
- value = pList[nListSize - 1];
- return nListSize - 1;
- }
- for (int i = 0; i < nListSize - 1; i++)
- {
- if (value >= pList[i] && value <= pList[i + 1])
- {
- int npos = 0;
- if (abs(value - pList[i]) >= abs(value - pList[i + 1]))
- {
- value = pList[i + 1];
- npos = i + 1;
- }
- else
- {
- value = pList[i];
- npos = i;
- }
- return npos;
- }
- }
- return -1;
- }
- nsGEN::DemoDevice::DemoDevice(std::shared_ptr <IOEventCenter> center, string configfile) : super(center), superGen()
- {
- //FINFO("DEMO ver 3.0.0.1");
- if (!configfile.empty())
- {
- ResDataObject Conftemp;
- Conftemp.loadFile(configfile.c_str());
- m_GenConfig = Conftemp["CONFIGURATION"];
- TransJsonText(m_GenConfig);
- string version;
- void* hMyModule;
- if (GetVersion(version, hMyModule))
- FINFO("\n===============log begin : DEMO version:{$} ===================\n", version.c_str());
- else
- FINFO("\n===============log begin : DEMO version:0.0.0.0 ===================\n");
- m_iStateChangeInterval = (int)m_GenConfig["StateChangeInterval"];
- m_iAutoExpActWaitTime = (int)m_GenConfig["AutoExpActWaitTime"];
- m_bIsDemo = ((int)m_GenConfig["IsDemo"]);
- FINFO("Config:StateChangeInterval[{$}],AutoExpActWaitTime[{$}],IsDemo[{$}]",
- m_iStateChangeInterval, m_iAutoExpActWaitTime, m_bIsDemo);
- }
- else
- {
- FINFO("\n===============log begin : DEMO version:3.0.0.1 ===================\n");
- m_iStateChangeInterval = 500;
- m_iAutoExpActWaitTime = 5;
- m_bIsDemo = true;
- FINFO("default:StateChangeInterval[{$}],AutoExpActWaitTime[{$}],IsDemo[{$}]",
- m_iStateChangeInterval, m_iAutoExpActWaitTime, m_bIsDemo);
- }
- //通用
- m_DoseUnit.m_GenSynState.reset(new GENSYNSTATEMould(AttrKey::GENERATOR_RAD_OFF, AttrKey::GENERATOR_RAD_OFF, AttrKey::GENERATOR_RAD_XRAYOFF, 1));
- m_DoseUnit.m_GenState.reset(new GENSTATEMould(4, 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_WS.reset(new WORKSTATIONMould(1, 0, 5, 1));
- m_DoseUnit.m_HE.reset(new TUBEHEATMould(0, 0, 100, 1));
- m_DoseUnit.m_TubeTargetMaterial.reset(new TUBETARGETMATERIALMould(AttrKey::TUBETARGETMATERIAL_TYPE::MO));
- m_DoseUnit.m_TubeAngle.reset(new TUBEANGLEMould(0, 0, 360, 1));
- //点片
- m_DoseUnit.m_KV.reset(new KVMould(0.0, 0.0, 150.0, 1.0));
- m_DoseUnit.m_MA.reset(new MAMould(0.0, 0.0, 1000.0, 0.1));
- m_DoseUnit.m_MS.reset(new MSMould(0.0, 0.0, 10000.0, 0.01));
- m_DoseUnit.m_MAS.reset(new MASMould(0.0, 0.0, 1000.0, 0.01));
- m_DoseUnit.m_Techmode.reset(new TECHMODEMould(AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P, AttrKey::TECHMODE_NOAEC_3P, AttrKey::TECHMODE_AEC_2P, 1));
- m_DoseUnit.m_Focus.reset(new FOCUSMould(AttrKey::FOCUS_TYPE::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, 2, 1));
- m_DoseUnit.m_AECDensity.reset(new AECDENSITYMould(0, -4, 4, 1));
- m_DoseUnit.m_PostKV.reset(new POSTKVMould(0.0, 0.0, 150.0, 1.0));
- m_DoseUnit.m_PostMA.reset(new POSTMAMould(0.0, 0.0, 1000.0, 0.1));
- m_DoseUnit.m_PostMS.reset(new POSTMSMould(0.0, 0.0, 10000.0, 0.01));
- m_DoseUnit.m_PostMAS.reset(new POSTMASMould(0.0, 0.0, 1000.0, 0.01));
- //透视
- m_DoseUnit.m_FLKV.reset(new FLUKVMould(0.0, 40.0, 150.0, 1));
- m_DoseUnit.m_FLMA.reset(new FLUMAMould(0.0, 0.5, 800.0, 0.1));
- m_DoseUnit.m_FLMS.reset(new FLUMSMould(0.0, 1.0, 10000.0, 0.01));
- m_DoseUnit.m_FLAccTime.reset(new FLAccTimeMould(0.0, 0.0, 300.0, 1));
- m_DoseUnit.m_FLIntTime.reset(new FLUIntTimeMould(0.0, 0.0, 1000.0, 1));
- m_DoseUnit.m_PPS.reset(new PPSMould(0.0, 0.0, 60.0, 1));
- m_DoseUnit.m_FLMode.reset(new FLUModeMould(AttrKey::GENERATOR_FLUMode::GENERATOR_FLMODE_NOTFLU));
- m_DoseUnit.m_ABSStatus.reset(new FLUABSStatusMould(AttrKey::GENERATOR_ABSStatus::GENERATOR_ABS_OFF));
- m_DoseUnit.m_MagSize.reset(new FLUMagMould(0, 0, 3, 1));
- m_DoseUnit.m_DoseLevel.reset(new FLUDoseLevelMould(AttrKey::GENERATOR_DoseLevel::GENERATOR_DOSE_LOW));
- m_DoseUnit.m_Curve.reset(new FLUCurveMould(0, 1, 3, 1));
- //other
- m_MSGUnit.reset(new nsDetail::MSGUnit(center, GeneratorUnitType));
- OnRegister();
- GetConfData();
- //add by wxx:for 品臻3025ZF测试
- m_iAutoExpFlag = 0;
- m_pHardwareStatusThread = 0;
- StartHardwareStatusThread();
- }
- nsGEN::DemoDevice::~DemoDevice()
- {
- FINFO("\n===============log end ===================\n");
- if (m_pHardwareStatusThread != 0) {
- pthread_cancel(m_pHardwareStatusThread); // 请求取消线程
- pthread_join(m_pHardwareStatusThread, nullptr); // 等待线程结束
- m_pHardwareStatusThread = 0;
- }
- m_pCollDev.release();
- m_pCollDev = nullptr;
- m_pMechDev.release();
- m_pMechDev = nullptr;
- }
- void nsGEN::DemoDevice::OnRegister()
- {
- auto Disp = m_Dispatch.Lock().As();
- 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_StartMove = [this](auto in, auto& out)
- {
- return StartMove();
- };
- Disp->Action.Push("StartMove", fun_StartMove);
- auto fun_EndMove = [this](auto in, auto& out)
- {
- return EndMove();
- };
- Disp->Action.Push("EndMove", fun_EndMove);
- auto fun_DirectlyNotify = [this](auto in, auto& out)
- {
- return DirectlyNotify(in);
- };
- Disp->Action.Push("DirectlyNotify", fun_DirectlyNotify);
- auto fun_DirectlyCMD = [this](auto in, auto& out)
- {
- return DirectlyCMD(in);
- };
- Disp->Action.Push("DirectlyCMD", fun_DirectlyCMD);
- }
- //设备方法
- std::string nsGEN::DemoDevice::GetGUID() const
- {
- printf("\n===============GetGUID : %s ===================\n", GeneratorUnitType);
- return GeneratorUnitType;
- }
- RET_STATUS nsGEN::DemoDevice::SetWS(std::string value)
- {
- FDEBUG("Enter SetWS:[{$}]", value.c_str());
- int tempws = 1;
- string strWS = "";
- cfgWorkStationKey trWS = cfgWorkStationKey(value.c_str());
- if (m_arrWSMap.find(trWS) != m_arrWSMap.end())
- {
- m_strCurrentWSName = trWS;
- tempws = m_arrWSMap[m_strCurrentWSName].nWSNamber;
- strWS = m_arrWSMap[m_strCurrentWSName].strWSNAme;
- FDEBUG("Set WS number [{$}][{$}]", strWS.c_str(), tempws);
- }
- else
- {
- FDEBUG("Set WS number default 1");
- m_strCurrentWSName = cfgWorkStationKey(1);
- }
- m_DoseUnit.m_WS->Update(atoi(value.c_str()));
- FireNotify(m_DoseUnit.m_WS->GetKey(), m_DoseUnit.m_WS->JSGet());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::QueryHE(int& value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::StartMove() //发生器无此设置
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::EndMove() //发生器无此设置
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::DirectlyNotify(string& value)
- {
- ResDataObject json;
- json.decode(value.c_str());
- FDEBUG("Enter DirectlyNotify:[{$}]", json.encode());
- string strKey = (string)json["NotifyKey"];
- string strValue = (string)json["NotifyValue"];
- FireNotify(strKey, strValue);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::DirectlyCMD(string& value)
- {
- ResDataObject json;
- json.decode(value.c_str());
- FDEBUG("Enter DirectlyCMD:[{$}]", json.encode());
- string strCMD = (string)json["CMDText"];
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetGenSynState(int value)
- {
- FDEBUG("Enter SetGenSynState:[{$}]", value);
- switch (value)
- {
- case AttrKey::GENERATOR_RAD_OFF:
- {
-
- }break;
- case AttrKey::GENERATOR_RAD_PREPARE:
- {
-
- }break;
- case AttrKey::GENERATOR_RAD_READY:
- {
-
- }break;
- case AttrKey::GENERATOR_RAD_XRAYON:
- {
- if (m_DoseUnit.m_ExpMode->JSGet() == AttrKey::EXPMODE_TYPE::Stitch)
- {
- if (!m_APRarray.empty())
- {
- int aprnum = m_DoseUnit.m_GenCurrentExpNumber->Get();
- SetAPR(m_APRarray[aprnum]);
- m_DoseUnit.m_GenCurrentExpNumber->Update(++aprnum);
- FDEBUG("SetAPRArray:[totalEXP:{$}, currentEXP:{$}]", m_DoseUnit.m_GenTotalExpNumber->Get(), m_DoseUnit.m_GenCurrentExpNumber->Get());
- }
- else
- {
- FWARN("APRarray is empty");
- }
- }
- else if (m_DoseUnit.m_ExpMode->JSGet() == AttrKey::EXPMODE_TYPE::PulseSerial ||
- m_DoseUnit.m_ExpMode->JSGet() == AttrKey::EXPMODE_TYPE::CoutineSerial)
- {
- value = AttrKey::GENERATOR_FLU_XRAYON;
- }
- }break;
- case AttrKey::GENERATOR_RAD_XRAYOFF:
- {
- FINFO("SetGenSynState:4 exp Status value:POSTKV[{$}],POSTMA[{$}],POSTMS[{$}],POSTMAS[{$}]",
- m_DoseUnit.m_PostKV->Get(), m_DoseUnit.m_PostMA->Get(), m_DoseUnit.m_PostMS->Get(), m_DoseUnit.m_PostMAS->Get());
- std::cout << "SetGenSynState:4 exp Status value:POSTKV["
- << m_DoseUnit.m_PostKV->Get()
- << "],POSTMA[" << m_DoseUnit.m_PostMA->Get()
- << "],POSTMS[" << m_DoseUnit.m_PostMS->Get()
- << "],POSTMAS[" << m_DoseUnit.m_PostMAS->Get()
- << "]" << std::endl;
- FireNotify(AttrKey::POSTKV, m_DoseUnit.m_PostKV->JSGet());
- FireNotify(AttrKey::POSTMA, m_DoseUnit.m_PostMA->JSGet());
- #if DEMO_DAEC_Flag
- int temp = m_DoseUnit.m_PostMS->Get();
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_1P)
- {
- temp /= 2;
- }
- FireNotify(AttrKey::POSTMS, temp);
- #else
- FireNotify(AttrKey::POSTMS, m_DoseUnit.m_PostMS->JSGet());
- #endif // DEMO_DAEC_Flag
- FireNotify(AttrKey::POSTMAS, m_DoseUnit.m_PostMAS->JSGet());
- if (m_DoseUnit.m_ExpMode->JSGet() == AttrKey::EXPMODE_TYPE::PulseSerial ||
- m_DoseUnit.m_ExpMode->JSGet() == AttrKey::EXPMODE_TYPE::CoutineSerial)
- {
- value = AttrKey::GENERATOR_FLU_XRAYOFF;
- }
- }break;
- case AttrKey::GENERATOR_FLU_READY:
- {
-
- }break;
- case AttrKey::GENERATOR_FLU_XRAYON:
- {
-
- }break;
- case AttrKey::GENERATOR_FLU_XRAYOFF:
- {
-
- }break;
- default:
- break;
- }
- m_DoseUnit.m_GenSynState->Update(value);
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), value);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetGenState(int value)
- {
- FDEBUG("Enter SetGenState:[{$}]", value);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetExpEnable()
- {
- FDEBUG("Enter SetExpEnable");
- FINFO("Request Fault Status:GENSTATE STATUS_SHUTDOWN -> STATUS_STANDBY");
- m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- FireNotify(m_DoseUnit.m_KVList->GetKey(), m_DoseUnit.m_KVList->JSGet());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetExpDisable()
- {
- FDEBUG("Enter SetExpDisable");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS CCOS::Dev::Detail::Generator::DemoDevice::PrepareAcquisition()
- {
- 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::DemoDevice::Reset()
- {
- FDEBUG("Enter Reset");
- //FireErrorMessage(false, 0, "clear all Gen error");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetExpMode(std::string value)
- {
- //add for dcm img hard
- FDEBUG("Enter SetExpMode:[{$}]", value.c_str());
- if (m_DoseUnit.m_ExpMode->Update(value))
- {
- FireNotify(AttrKey::EXPMODE, m_DoseUnit.m_ExpMode->JSGet());
- }
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- m_DoseUnit.m_GenTotalExpNumber->Update(0);
- m_DoseUnit.m_GenCurrentExpNumber->Update(0);
- //add for dcm img hard
- FireNotify(m_DoseUnit.m_TubeTargetMaterial->GetKey(), m_DoseUnit.m_TubeTargetMaterial->JSGet());
- FireNotify(m_DoseUnit.m_TubeAngle->GetKey(), m_DoseUnit.m_TubeAngle->JSGet());
- if (m_pCollDev != nullptr)
- {
- FINFO("act CollDev ReportMessageToDicom");
- m_pCollDev->ReportMessageToDicom();
- }
- if (m_pMechDev != nullptr)
- {
- FINFO("act MechDev ReportMessageToDicom");
- m_pMechDev->ReportMessageToDicom();
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetEXAMMode(std::string value)
- {
- FDEBUG("Enter SetEXAMMode:[{$}]", value.c_str());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::ActiveSyncMode(_tSyncModeArgs value)
- {
- FDEBUG("Enter ActiveSyncMode:Sync[{$},{$}],WS[{$}]", value.strSyncMode.c_str(), value.strSyncValue.c_str(), value.strWS.c_str());
- return RET_STATUS::RET_SUCCEED;
- }
- //点片
- RET_STATUS nsGEN::DemoDevice::IncKV()
- {
- FDEBUG("Enter IncKV");
- if (m_bIsDemo)
- {
- if (!m_DoseUnit.m_KV->CanInc()) return RET_STATUS::RET_SUCCEED;
- m_DoseUnit.m_KV->Inc();
- FireNotify(m_DoseUnit.m_KV->GetKey(), m_DoseUnit.m_KV->JSGet());
- m_DoseUnit.m_PostKV->Update(m_DoseUnit.m_KV->Get());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::DecKV()
- {
- FDEBUG("Enter DecKV");
- if (m_bIsDemo)
- {
- if (!m_DoseUnit.m_KV->CanDec()) return RET_STATUS::RET_SUCCEED;
- m_DoseUnit.m_KV->Dec();
- m_DoseUnit.m_PostKV->Update(m_DoseUnit.m_KV->Get());
- FireNotify(m_DoseUnit.m_KV->GetKey(), m_DoseUnit.m_KV->JSGet());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetKV(float value)
- {
- FDEBUG("Enter SetKV:[{$}]", value);
- if (m_bIsDemo)
- {
- m_DoseUnit.m_KV->Update(value);
- m_DoseUnit.m_PostKV->Update(value);
- FireNotify(m_DoseUnit.m_KV->GetKey(), m_DoseUnit.m_KV->JSGet());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::IncKVL()
- {
- FDEBUG("Enter IncKVL");
- if (m_bIsDemo)
- {
- float tempKV = m_DoseUnit.m_KV->Get();
- tempKV += 4;
- if (m_DoseUnit.m_KV->Update(tempKV))
- {
- FDEBUG("IncKVL:[{$}] ok", tempKV);
- FireNotify(m_DoseUnit.m_KV->GetKey(), m_DoseUnit.m_KV->JSGet());
- return RET_STATUS::RET_SUCCEED;
- }
- else
- {
- FDEBUG("IncKVL:[{$}] failed,Exceeding limit", tempKV);
- return RET_STATUS::RET_FAILED;
- }
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::DecKVL()
- {
- FDEBUG("Enter DecKVL");
- if (m_bIsDemo)
- {
- float tempKV = m_DoseUnit.m_KV->Get();
- tempKV -= 4;
- if (m_DoseUnit.m_KV->Update(tempKV))
- {
- FDEBUG("DecKVL:[{$}] ok", tempKV);
- FireNotify(m_DoseUnit.m_KV->GetKey(), m_DoseUnit.m_KV->JSGet());
- return RET_STATUS::RET_SUCCEED;
- }
- else
- {
- FDEBUG("DecKVL:[{$}] failed,Exceeding limit", tempKV);
- return RET_STATUS::RET_FAILED;
- }
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::IncMA()
- {
- FDEBUG("Enter IncMA");
- if (m_bIsDemo)
- {
- /*if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P &&
- m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
- {
- FWARN("Techmode is not 3P, can't IncMA");
- return RET_STATUS::RET_SUCCEED;
- }*/
- float value = m_DoseUnit.m_MA->Get();
- int npos = FindPositon(g_MA_List, sizeof(g_MA_List) / sizeof(float), value);
- if (npos < 0)
- {
- return RET_STATUS::RET_FAILED;
- }
- else if (npos == sizeof(g_MA_List) / sizeof(float) - 1)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- npos += 1;
- float temp = g_MA_List[npos];
- m_DoseUnit.m_MA->Update(temp);
- m_DoseUnit.m_PostMA->Update(temp);
- FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet());
- ComputeMAS();
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::DecMA()
- {
- FDEBUG("Enter DecMA");
- if (m_bIsDemo)
- {
- /*if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P &&
- m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
- {
- FWARN("Techmode is not 3P, can't DecMA");
- return RET_STATUS::RET_FAILED;
- }*/
- float value = m_DoseUnit.m_MA->Get();
- int npos = FindPositon(g_MA_List, sizeof(g_MA_List) / sizeof(float), value);
- if (npos < 0)
- {
- return RET_STATUS::RET_FAILED;
- }
- else if (npos == 0)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- npos -= 1;
- float temp = g_MA_List[npos];
- m_DoseUnit.m_MA->Update(temp);
- m_DoseUnit.m_PostMA->Update(temp);
- FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet());
- ComputeMAS();
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetMA(float value)
- {
- FDEBUG("Enter SetMA:[{$}]", value);
- if (m_bIsDemo)
- {
- //if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P &&
- // m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
- //{
- // FWARN("Techmode is not 3P, can't SetMA");
- // return RET_STATUS::RET_FAILED;
- //}
- int npos = FindPositon(g_MA_List, sizeof(g_MA_List) / sizeof(float), value);
- if (npos < 0)
- {
- return RET_STATUS::RET_FAILED;
- }
- float temp = g_MA_List[npos];
- m_DoseUnit.m_MA->Update(temp);
- m_DoseUnit.m_PostMA->Update(temp);
- FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::IncMS()
- {
- FDEBUG("Enter IncMS");
- if (m_bIsDemo)
- {
- /*if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P &&
- m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
- {
- FWARN("Techmode is not 3P, can't IncMAS");
- return RET_STATUS::RET_FAILED;
- }*/
- float value = m_DoseUnit.m_MS->Get();
- int npos = FindPositon(g_MS_List, sizeof(g_MS_List) / sizeof(float), value);
- if (npos < 0)
- {
- return RET_STATUS::RET_FAILED;
- }
- else if (npos == sizeof(g_MS_List) / sizeof(float) - 1)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- npos += 1;
- float temp = g_MS_List[npos];
- m_DoseUnit.m_MS->Update(temp);
- m_DoseUnit.m_PostMS->Update(temp);
- FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet());
- ComputeMAS();
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::DecMS()
- {
- FDEBUG("Enter DecMS");
- if (m_bIsDemo)
- {
- /*if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P &&
- m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
- {
- FWARN("Techmode is not 3P, can't DecMS");
- return RET_STATUS::RET_FAILED;
- }*/
- float value = m_DoseUnit.m_MS->Get();
- int npos = FindPositon(g_MS_List, sizeof(g_MS_List) / sizeof(float), value);
- if (npos < 0)
- {
- return RET_STATUS::RET_FAILED;
- }
- else if (npos == 0)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- npos -= 1;
- float temp = g_MS_List[npos];
- m_DoseUnit.m_MS->Update(temp);
- m_DoseUnit.m_PostMS->Update(temp);
- FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet());
- ComputeMAS();
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetMS(float value)
- {
- FDEBUG("Enter SetMS:[{$}]", value);
- if (m_bIsDemo)
- {
- //if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P &&
- // m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
- //{
- // FWARN("Techmode is not 3P, can't SetMS");
- // return RET_STATUS::RET_FAILED;
- //}
- int npos = FindPositon(g_MS_List, sizeof(g_MS_List) / sizeof(float), value);
- if (npos < 0)
- {
- return RET_STATUS::RET_FAILED;
- }
- float temp = g_MS_List[npos];
- m_DoseUnit.m_MS->Update(temp);
- m_DoseUnit.m_PostMS->Update(temp);
- FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::IncMAS()
- {
- FDEBUG("Enter IncMAS");
- if (m_bIsDemo)
- {
- /*if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P &&
- m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
- {
- FWARN("Techmode is not 2P, can't IncMAS");
- return RET_STATUS::RET_NOSUPPORT;
- }*/
- float value = m_DoseUnit.m_MAS->Get();
- int npos = FindPositon(g_MAS_List, sizeof(g_MAS_List) / sizeof(float), value);
- if (npos < 0)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- else if (npos == sizeof(g_MAS_List) / sizeof(float) - 1)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- npos += 1;
- float temp = g_MAS_List[npos];
- m_DoseUnit.m_MAS->Update(temp);
- m_DoseUnit.m_PostMAS->Update(temp);
- FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet());
- // Update MA and MS based on new MAS value
- ComputeMAMS();
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::DecMAS()
- {
- FDEBUG("Enter DecMAS");
- if (m_bIsDemo)
- {
- /*if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P &&
- m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
- {
- FWARN("Techmode is not 2P, can't DecMAS");
- return RET_STATUS::RET_NOSUPPORT;
- }*/
- float value = m_DoseUnit.m_MAS->Get();
- int npos = FindPositon(g_MAS_List, sizeof(g_MAS_List) / sizeof(float), value);
- if (npos < 0)
- {
- return RET_STATUS::RET_FAILED;
- }
- else if (npos == 0)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- npos -= 1;
- float temp = g_MAS_List[npos];
- m_DoseUnit.m_MAS->Update(temp);
- m_DoseUnit.m_PostMAS->Update(temp);
- FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet());
- // Update MA and MS based on new MAS value
- ComputeMAMS();
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetMAS(float value)
- {
- FDEBUG("Enter SetMAS:[{$}]", value);
- if (m_bIsDemo)
- {
- //if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P &&
- // m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
- //{
- // FWARN("Techmode is not 2P, can't SetMAS");
- // return RET_STATUS::RET_NOSUPPORT;
- //}
- int npos = FindPositon(g_MAS_List, sizeof(g_MAS_List) / sizeof(float), value);
- if (npos < 0)
- {
- return RET_STATUS::RET_FAILED;
- }
- float temp = g_MAS_List[npos];
- m_DoseUnit.m_MAS->Update(temp);
- m_DoseUnit.m_PostMAS->Update(temp);
- FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet());
- // Update MA and MS based on new MAS value
- //ComputeMAMS();
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::IncMASL()
- {
- FDEBUG("Enter IncMASL");
- if (m_bIsDemo)
- {
- if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P &&
- m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
- {
- FWARN("Techmode is not 2P, can't IncMASL");
- return RET_STATUS::RET_NOSUPPORT;
- }
- float tempMAS = m_DoseUnit.m_MAS->Get();
- tempMAS += 4;
- if (m_DoseUnit.m_MAS->Update(tempMAS))
- {
- FDEBUG("IncMASL:[{$}] ok", tempMAS);
- FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet());
- return RET_STATUS::RET_SUCCEED;
- }
- else
- {
- FDEBUG("IncMASL:[{$}] failed,Exceeding limit", tempMAS);
- return RET_STATUS::RET_FAILED;
- }
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::DecMASL()
- {
- FDEBUG("Enter DecMASL");
- if (m_bIsDemo)
- {
- if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P &&
- m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
- {
- FWARN("Techmode is not 2P, can't DecMASL");
- return RET_STATUS::RET_NOSUPPORT;
- }
- float tempMAS = m_DoseUnit.m_MAS->Get();
- tempMAS -= 4;
- if (m_DoseUnit.m_MAS->Update(tempMAS))
- {
- FDEBUG("DecMASL:[{$}] ok", tempMAS);
- FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet());
- return RET_STATUS::RET_SUCCEED;
- }
- else
- {
- FDEBUG("DecMASL:[{$}] failed,Exceeding limit", tempMAS);
- return RET_STATUS::RET_FAILED;
- }
- }
- return RET_STATUS::RET_SUCCEED;
- }
- void nsGEN::DemoDevice::ComputeMAS()
- {
- float tempMa = m_DoseUnit.m_MA->Get();
- float tempMs = m_DoseUnit.m_MS->Get();
- float tempMAS = tempMa * tempMs / 1000.0f;
- // Find the closest MAS value in the list
- int npos = FindPositon(g_MAS_List, sizeof(g_MAS_List) / sizeof(float), tempMAS);
- if (npos >= 0 && npos < sizeof(g_MAS_List) / sizeof(float))
- {
- float adjustedMAS = g_MAS_List[npos];
- m_DoseUnit.m_MAS->Update(adjustedMAS);
- m_DoseUnit.m_PostMAS->Update(adjustedMAS);
- FDEBUG("ComputeMAS:MA[{$}] MS[{$}] calculatedMAS[{$}] adjustedMAS[{$}]",
- tempMa, tempMs, tempMAS, adjustedMAS);
- FireNotify(m_DoseUnit.m_MAS->GetKey(), adjustedMAS);
- }
- else
- {
- // Fallback to original behavior if position not found
- m_DoseUnit.m_PostMAS->Update(tempMAS);
- FDEBUG("ComputeMAS:MA[{$}] MS[{$}] tempMAS[{$}] (not in list)",
- tempMa, tempMs, tempMAS);
- FireNotify(m_DoseUnit.m_MAS->GetKey(), tempMAS);
- }
- }
- void nsGEN::DemoDevice::ComputeMAMS()
- {
- // When MAS changes, we need to update MA and MS accordingly
- // We keep MS constant and adjust MA to match the new MAS value
- // Formula: MAS = MA * MS / 1000
- // Therefore: MA = MAS * 1000 / MS
- float currentMAS = m_DoseUnit.m_MAS->Get();
- float currentMS = m_DoseUnit.m_MS->Get();
- if (currentMS > 0)
- {
- float newMA = currentMAS * 1000.0f / currentMS;
- // Find the closest MA value in the list
- int npos = FindPositon(g_MA_List, sizeof(g_MA_List) / sizeof(float), newMA);
- if (npos >= 0 && npos < sizeof(g_MA_List) / sizeof(float))
- {
- float adjustedMA = g_MA_List[npos];
- m_DoseUnit.m_MA->Update(adjustedMA);
- m_DoseUnit.m_PostMA->Update(adjustedMA);
- FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet());
- // Recalculate MS to maintain the exact MAS value if needed
- float adjustedMS = currentMAS * 1000.0f / adjustedMA;
- int msPos = FindPositon(g_MS_List, sizeof(g_MS_List) / sizeof(float), adjustedMS);
- if (msPos >= 0 && msPos < sizeof(g_MS_List) / sizeof(float))
- {
- float finalMS = g_MS_List[msPos];
- m_DoseUnit.m_MS->Update(finalMS);
- m_DoseUnit.m_PostMS->Update(finalMS);
- FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet());
- }
- FDEBUG("ComputeMAMS:MAS[{$}] -> MA[{$}] MS[{$}]",
- currentMAS, m_DoseUnit.m_MA->Get(), m_DoseUnit.m_MS->Get());
- }
- }
- }
- RET_STATUS nsGEN::DemoDevice::SetTechmode(int value)
- {
- FDEBUG("Enter SetTechmode:[{$}]", value);
- if (m_bIsDemo)
- {
- if (!m_DoseUnit.m_Techmode->Verify(value)) return RET_STATUS::RET_SUCCEED;
- m_DoseUnit.m_Techmode->Update(value);
- FireNotify(m_DoseUnit.m_Techmode->GetKey(), m_DoseUnit.m_Techmode->JSGet());
- switch (value)
- {
- case AttrKey::TECHMODE_TYPE::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());
- ComputeMAS();
- }
- break;
- case AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P:
- {
- FireNotify(m_DoseUnit.m_MA->GetKey(), "0");
- FireNotify(m_DoseUnit.m_MS->GetKey(), "0");
- FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet());
- }
- break;
- case AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P:
- {
- FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet());
- FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet());
- ComputeMAS();
- }
- break;
- case AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P:
- {
- FireNotify(m_DoseUnit.m_MA->GetKey(), "0");
- FireNotify(m_DoseUnit.m_MS->GetKey(), "0");
- FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet());
- }
- break;
- }
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetFocus(int value)
- {
- FDEBUG("Enter SetFocus:[{$}]", value);
- if (m_bIsDemo)
- {
- if (!m_DoseUnit.m_Focus->Verify(value)) return RET_STATUS::RET_SUCCEED;
- m_DoseUnit.m_Focus->Update(value);
- FireNotify(m_DoseUnit.m_Focus->GetKey(), m_DoseUnit.m_Focus->JSGet());
- if (m_DoseUnit.m_Focus->Get() == AttrKey::FOCUS_SMALL)
- FireNotify(AttrKey::FOCUSSIZE, m_DoseUnit.m_FocusSmall);
- else
- FireNotify(AttrKey::FOCUSSIZE, m_DoseUnit.m_FocusLarge);
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetAECDensity(int value)
- {
- FDEBUG("Enter SetAECDensity:[{$}]", value);
- if (m_bIsDemo)
- {
- if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_1P &&
- m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P &&
- m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
- {
- printf("\n Techmode is not AEC, can't SetAECDensity");
- return RET_STATUS::RET_NOSUPPORT;
- }
- if (!m_DoseUnit.m_AECDensity->Verify(value)) return RET_STATUS::RET_FAILED;
- m_DoseUnit.m_AECDensity->Update(value);
- FireNotify(m_DoseUnit.m_AECDensity->GetKey(), m_DoseUnit.m_AECDensity->JSGet());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::IncAECDensity()
- {
- FDEBUG("Enter IncAECDensity");
- if (m_bIsDemo)
- {
- FDEBUG("Enter IncAECDensity");
- if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_1P &&
- m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P &&
- m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
- {
- FWARN("Techmode is not AEC, can't IncAECDensity");
- return RET_STATUS::RET_NOSUPPORT;
- }
- if (m_DoseUnit.m_AECDensity->CanInc())
- {
- m_DoseUnit.m_AECDensity->Inc();
- FireNotify(m_DoseUnit.m_AECDensity->GetKey(), m_DoseUnit.m_AECDensity->JSGet());
- }
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::DecAECDensity()
- {
- FDEBUG("Enter DecAECDensity");
- if (m_bIsDemo)
- {
- FDEBUG("Enter DecAECDensity");
- if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_1P &&
- m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P &&
- m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
- {
- FWARN("Techmode is not AEC, can't DecAECDensity");
- return RET_STATUS::RET_NOSUPPORT;
- }
- if (m_DoseUnit.m_AECDensity->CanDec())
- {
- m_DoseUnit.m_AECDensity->Dec();
- FireNotify(m_DoseUnit.m_AECDensity->GetKey(), m_DoseUnit.m_AECDensity->JSGet());
- }
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetAECField(int value)
- {
- FDEBUG("Enter SetAECField:[{$}]", value);
- if (m_bIsDemo)
- {
- if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_AEC)
- {
- printf("\n Techmode is not AEC, can't set AEC");
- return RET_STATUS::RET_FAILED;
- }
- if (!m_DoseUnit.m_AECField->Verify(value)) return RET_STATUS::RET_SUCCEED;
- int npos = FindPositon(g_AECFIELD_List, sizeof(g_AECFIELD_List) / sizeof(int), value);
- if (npos < 0)
- {
- return RET_STATUS::RET_FAILED;
- }
- int temp = value;
- m_DoseUnit.m_AECField->Update(temp);
- FireNotify(m_DoseUnit.m_AECField->GetKey(), m_DoseUnit.m_AECField->JSGet());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetAECFilm(int value)
- {
- FDEBUG("Enter SetAECFilm:[{$}]", value);
- if (m_bIsDemo)
- {
- if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_AEC)
- {
- printf("\n Techmode is not AEC, can't set AEC");
- return RET_STATUS::RET_FAILED;
- }
- if (!m_DoseUnit.m_AECFilm->Verify(value)) return RET_STATUS::RET_SUCCEED;
- m_DoseUnit.m_AECFilm->Update(value);
- FireNotify(m_DoseUnit.m_AECFilm->GetKey(), m_DoseUnit.m_AECFilm->JSGet());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetAPR(const _tAPRArgs& t)
- {
- FDEBUG("SetAPR:KV={$},MA={$},MS={$},MAS={$},Focus={$},Techmode={$},WS={$},AECDensity={$},AECField={$},AECFilm={$}",
- t.fKV, t.fMA, t.fMS, t.fMAS, t.nFocus, t.nTechmode, t.nWS, t.nAECDensity, t.nAECField, t.nAECFilm);
- if (m_bIsDemo)
- {
- //note:缺少WS
- m_DoseUnit.m_Techmode->Update(t.nTechmode);
- FireNotify(m_DoseUnit.m_Techmode->GetKey(), m_DoseUnit.m_Techmode->JSGet());
- SetKV(t.fKV);
- SetMA(t.fMA);
- SetMS(t.fMS);
- SetMAS(t.fMAS);
- SetFocus(t.nFocus);
- SetAECDensity(t.nAECDensity);
- SetAECField(t.nAECField);
- SetAECFilm(t.nAECFilm);
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
- {
- ComputeMAS();
- }
- m_DoseUnit.m_HE->Update(50);
- FireNotify(m_DoseUnit.m_HE->GetKey(), m_DoseUnit.m_HE->JSGet());
- }
- else
- {
- FireNotify(m_DoseUnit.m_Techmode->GetKey(), t.nTechmode);
- FireNotify(m_DoseUnit.m_KV->GetKey(), t.fKV);
- FireNotify(m_DoseUnit.m_MA->GetKey(), t.fMA);
- FireNotify(m_DoseUnit.m_MS->GetKey(), t.fMS);
- FireNotify(m_DoseUnit.m_MAS->GetKey(), t.fMAS);
- FireNotify(m_DoseUnit.m_Focus->GetKey(), t.nFocus);
- FireNotify(m_DoseUnit.m_AECDensity->GetKey(), t.nAECDensity);
- FireNotify(m_DoseUnit.m_AECField->GetKey(), t.nAECField);
- FireNotify(m_DoseUnit.m_AECFilm->GetKey(), t.nAECFilm);
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetAPRArray(vector<_tAPRArgs>& APRarray)
- {
- FDEBUG("SetAPRArray:[size:{$}]", APRarray.size());
- if (m_bIsDemo)
- {
- m_APRarray = APRarray;
- for (int i = 0; i < m_APRarray.size(); i++)
- {
- FDEBUG("APRArray[{$}]:WS={$},Techmode={$},Focus={$},KV={$},MA={$},MS={$},MAS={$},AECDensity={$},AECField={$},AECFilm={$}",
- i, m_APRarray[i].nWS, m_APRarray[i].nTechmode, m_APRarray[i].nFocus,
- m_APRarray[i].fKV, m_APRarray[i].fMA, m_APRarray[i].fMS, m_APRarray[i].fMAS,
- m_APRarray[i].nAECDensity, m_APRarray[i].nAECField, m_APRarray[i].nAECFilm);
- }
- if (!m_APRarray.empty())
- {
- SetAPR(m_APRarray[0]);
- m_DoseUnit.m_GenTotalExpNumber->Update(m_APRarray.size());
- m_DoseUnit.m_GenCurrentExpNumber->Update(1);
- FDEBUG("SetAPRArray:[totalEXP:{$}, currentEXP:{$}]", m_DoseUnit.m_GenTotalExpNumber->Get(), m_DoseUnit.m_GenCurrentExpNumber->Get());
- }
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::QueryPostKV(float& value)
- {
- value = m_DoseUnit.m_KV->Get();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::QueryPostMA(float& value)
- {
- value = m_DoseUnit.m_MA->Get();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::QueryPostMS(float& value)
- {
- value = m_DoseUnit.m_MS->Get();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::QueryPostMAS(float& value)
- {
- value = m_DoseUnit.m_MAS->Get();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetFrameRate(float frameRate)
- {
- FDEBUG("Enter SetFrameRate:[{$}]", frameRate);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetCollimatorDev(OemCollimator* dev)
- {
- FDEBUG("Enter SetCollimatorDev");
- if (dev)
- m_pCollDev.reset(dev);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetMechDev(OemMechanical* dev)
- {
- FDEBUG("Enter SetMechDev");
- if (dev)
- m_pMechDev.reset(dev);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetCollimatorSize(int xsize, int ysize)
- {
- FDEBUG("Enter SetCollimatorSize:[x:{$}, y:{$}]", xsize, ysize);
- if (m_pCollDev)
- {
- m_pCollDev->UpdateCollimatorXSize(xsize);
- m_pCollDev->UpdateCollimatorYSize(ysize);
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetCollimatorLight(unsigned short pParams)
- {
- FDEBUG("Enter SetCollimatorLight:[{$}]", (int)pParams);
- //此处应该发送指令给GEN,并且该指令可以控制 coll 的LED
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetAutoTracking(int nAutoTracking)
- {
- FDEBUG("Enter SetAutoTracking:[{$}]", nAutoTracking);
- if (m_pMechDev)
- m_pMechDev->UpdateMammo_Depress(nAutoTracking);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetFilter(int nFilterType)
- {
- FDEBUG("Enter SetFilter:[{$}]", nFilterType);
- if (m_pMechDev)
- {
- m_pMechDev->UpdateMammo_FT(nFilterType);
- }
- if (m_pCollDev)
- {
- m_pCollDev->UpdateCollimatorFilter(nFilterType);
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetGrid(int nGridType)
- {
- FDEBUG("Enter SetGrid:[{$}]", nGridType);
- if (m_pMechDev)
- m_pMechDev->UpdateGrid(nGridType);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::GetTomoResults(ResDataObject& resultAngle, ResDataObject& resultHeight)
- {
- RET_STATUS ret = RET_STATUS::RET_SUCCEED;
- if (resultAngle.size() == 1 && resultHeight.size() == 1)
- {
- m_resultAngle.update(resultAngle.GetKey(0), (float)resultAngle[0]);
- FINFO("GetTomoResults insert, key={$},value={$}", resultAngle.GetKey(0), (float)resultAngle[0]);
- }
- else
- {
- FINFO("GetTomoResults size={$}", m_resultAngle.size());
- for (int i = 0; i < m_resultAngle.size(); i++)
- {
- resultAngle.update(m_resultAngle.GetKey(i), (float)m_resultAngle[i]);
- FINFO("GetTomoResults ket={$} ,resule={$}", m_resultAngle.GetKey(i), (float)m_resultAngle[i]);
- }
- resultHeight.update("0", 63.71);
- resultHeight.update("1", 63.97);
- resultHeight.update("2", 64.21);
- resultHeight.update("3", 64.41);
- resultHeight.update("4", 64.59);
- resultHeight.update("5", 64.73);
- resultHeight.update("6", 64.84);
- resultHeight.update("7", 64.92);
- resultHeight.update("8", 64.97);
- resultHeight.update("9", 64.99);
- resultHeight.update("10", 64.98);
- resultHeight.update("11", 64.94);
- resultHeight.update("12", 64.87);
- resultHeight.update("13", 64.72);
- resultHeight.update("14", 64.63);
- resultHeight.update("15", 64.47);
- resultHeight.update("16", 64.28);
- resultHeight.update("17", 64.05);
- m_resultAngle.clear();
- }
- return ret;
- }
- //透视
- RET_STATUS nsGEN::DemoDevice::IncFluKV()
- {
- FDEBUG("Enter IncFluKV");
- float KV = m_DoseUnit.m_FLKV->Get()+1;
- if (m_DoseUnit.m_FLKV->Update(KV))
- {
- FireNotify(m_DoseUnit.m_FLKV->GetKey(), m_DoseUnit.m_FLKV->JSGet());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::DecFluKV()
- {
- FDEBUG("Enter DecFluKV");
- float KV = m_DoseUnit.m_FLKV->Get() - 1;
- if (m_DoseUnit.m_FLKV->Update(KV))
- {
- FireNotify(m_DoseUnit.m_FLKV->GetKey(), m_DoseUnit.m_FLKV->JSGet());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetFluKV(float value)
- {
- FDEBUG("Enter SetFluKV:[{$}]", value);
- if (m_DoseUnit.m_FLKV->Update(value))
- {
- FireNotify(m_DoseUnit.m_FLKV->GetKey(), m_DoseUnit.m_FLKV->JSGet());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::IncFluMA()
- {
- FDEBUG("Enter IncFluKV");
- float MA = m_DoseUnit.m_FLMA->Get()+1;
- if (m_DoseUnit.m_FLMA->Update(MA))
- {
- FireNotify(m_DoseUnit.m_FLMA->GetKey(), m_DoseUnit.m_FLMA->JSGet());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::DecFluMA()
- {
- FDEBUG("Enter DecFluKV");
- float MA = m_DoseUnit.m_FLMA->Get() - 1;
- if (m_DoseUnit.m_FLMA->Update(MA))
- {
- FireNotify(m_DoseUnit.m_FLMA->GetKey(), m_DoseUnit.m_FLMA->JSGet());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetFluMA(float value)
- {
- FDEBUG("Enter SetFluMA:[{$}]", value);
- if (m_DoseUnit.m_FLMA->Update(value))
- {
- FireNotify(m_DoseUnit.m_FLMA->GetKey(), m_DoseUnit.m_FLMA->JSGet());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::IncFluMS()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::DecFluMS()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetFluMS(float value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetPPS(float frameRate)
- {
- FDEBUG("Enter SetPPS:[{$}]", frameRate);
- if (m_DoseUnit.m_PPS->Update(frameRate))
- {
- FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::INCPPS()
- {
- FDEBUG("Enter INCPPS");
- float PPS = m_DoseUnit.m_PPS->Get()+1;
- if (m_DoseUnit.m_PPS->Update(PPS))
- {
- FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::DECPPS()
- {
- FDEBUG("Enter DECPPS");
- float PPS = m_DoseUnit.m_PPS->Get() - 1;
- if (m_DoseUnit.m_PPS->Update(PPS))
- {
- FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetPluseWidth(float fplusewidth)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetABSMode(int nMode)
- {
- FDEBUG("Enter SetABSMode:[{$}]", nMode);
- if (m_DoseUnit.m_ABSStatus->Update(nMode))
- {
- FireNotify(m_DoseUnit.m_ABSStatus->GetKey(), m_DoseUnit.m_ABSStatus->JSGet());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetABSCurve(int curveNum)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::IncABSCurve()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::DecABSCurve()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetABSValue(float fABSValue)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetABSTargetEXI(float fEXIValue)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- float nsGEN::DemoDevice::GetFluIntTimer()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- float nsGEN::DemoDevice::GetFluAccTimer()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::ResetFluTimer(int ntype)
- {
- FDEBUG("ReSetFluAccTimer:[{$}]", ntype);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetFluPre(int bPrepare)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetFluEXP(int bPrepare)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetFLFMode(std::string value)
- {
- FDEBUG("Enter SetFLFMode:[{$}]", value.c_str());
- if (value == "CF")
- {
- m_DoseUnit.m_FLMode->Update(AttrKey::GENERATOR_FLMODE_CF);
- SetExpMode(AttrKey::EXPMODE_TYPE::CoutineSerial);
- }
- else if (value == "PF")
- {
- m_DoseUnit.m_FLMode->Update(AttrKey::GENERATOR_FLMODE_PF);
- SetExpMode(AttrKey::EXPMODE_TYPE::PulseSerial);
- }
- FireNotify(AttrKey::FLUMode, m_DoseUnit.m_FLMode->JSGet());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetFluMAG(int nsize)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::DisableMAG()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetFluDoseLever(int nlever)
- {
- FDEBUG("Enter SetFluDoseLever:[{$}]", nlever);
- if (m_DoseUnit.m_DoseLevel->Update(nlever))
- {
- FireNotify(AttrKey::FLUDoseLevel, m_DoseUnit.m_DoseLevel->JSGet());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetHalfDose(int nlever)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::TransferRadCurve(int ncurve)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DemoDevice::SetAPF(const _tAPFArgs& t)
- {
- FDEBUG("SetAPF: nWS={$}, Flu mode={$}, ABS mode={$}, DoseLever={$}, nFlkv={$}, FlMA={$}",
- t.nWS, t.nFluMode, t.nABSMode, t.nDoseLever, t.nFLKV, t.fFLMA, t.nPPS);
- if (m_DoseUnit.m_FLKV->Update(t.nFLKV))
- {
- FireNotify(m_DoseUnit.m_FLKV->GetKey(), m_DoseUnit.m_FLKV->JSGet());
- }
- if (m_DoseUnit.m_FLMA->Update(t.fFLMA))
- {
- FireNotify(m_DoseUnit.m_FLMA->GetKey(), m_DoseUnit.m_FLMA->JSGet());
- }
- if (m_DoseUnit.m_PPS->Update(t.nPPS))
- {
- FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
- }
- if (m_DoseUnit.m_DoseLevel->Update(t.nDoseLever))
- {
- FireNotify(AttrKey::FLUDoseLevel, m_DoseUnit.m_DoseLevel->JSGet());
- }
- if (m_DoseUnit.m_FLMode->Update(t.nFluMode))
- {
- FireNotify(AttrKey::FLUMode, m_DoseUnit.m_FLMode->JSGet());
- }
- if (m_DoseUnit.m_ABSStatus->Update(t.nABSMode))
- {
- FireNotify(m_DoseUnit.m_ABSStatus->GetKey(), m_DoseUnit.m_ABSStatus->JSGet());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- //额外
- void nsGEN::DemoDevice::FireNotify(string key, int context)
- {
- //std::unique_lock<std::mutex> uqeLock(m_MSGLock);
- char szInfo[64] = { 0 };
- sprintf(szInfo, "%d", context);
- std::string str = szInfo;
- EventCenter->OnNotify(1, key, str);//(int)ATTRACTION_SET 2
- }
- void nsGEN::DemoDevice::FireNotify(std::string key, float context)
- {
- //std::unique_lock<std::mutex> uqeLock(m_MSGLock);
- char szInfo[64] = { 0 };
- sprintf(szInfo, "%.2f", context);
- std::string str = szInfo;
- EventCenter->OnNotify(1, key, str);//(int)ATTRACTION_SET 2
- }
- void nsGEN::DemoDevice::FireNotify(std::string key, std::string context)
- {
- //std::unique_lock<std::mutex> uqeLock(m_MSGLock);
- EventCenter->OnNotify(1, key, context);
- }
- int nsGEN::DemoDevice::GetConfData()
- {
- //灯丝大小
- if (m_GenConfig.GetKeyCount(ConfKey::CcosTubeInfo) > 0)
- {
- string tempValue = m_GenConfig[ConfKey::CcosTubeInfo].encode();
- m_DoseUnit.m_TubeInfo.reset(new TUBEINFOMould(tempValue));
- }
- if (m_GenConfig.GetKeyCount(ConfKey::CcosFocusSmall) > 0)
- {
- float tempValue = (float)m_GenConfig[ConfKey::CcosFocusSmall];
- m_DoseUnit.m_FocusSmall = tempValue;
- }
- if (m_GenConfig.GetKeyCount(ConfKey::CcosFocusLarge) > 0)
- {
- float tempValue = (float)m_GenConfig[ConfKey::CcosFocusLarge];
- m_DoseUnit.m_FocusLarge = tempValue;
- }
- //同步模式
- if (m_GenConfig.GetKeyCount("WSTable") > 0)
- {
- int WSNamber = (int)m_GenConfig["WSTable"];
- EnSYNMode WSSYN = (EnSYNMode)((int)m_GenConfig["SYNTable"]);
- m_arrWSMap[cfgWorkStationKey("Table", AttrKey::TABLE)] = cfgWorkStationData("Table", WSNamber, WSSYN);
- FDEBUG("cfg Table WS[{$}],SYN[{$}]", WSNamber, (int)WSSYN);
- }
- if (m_GenConfig.GetKeyCount("WSWall") > 0)
- {
- int WSNamber = (int)m_GenConfig["WSWall"];
- EnSYNMode WSSYN = (EnSYNMode)((int)m_GenConfig["SYNWall"]);
- m_arrWSMap[cfgWorkStationKey("Wall", AttrKey::WALL)] = cfgWorkStationData("Wall", WSNamber, WSSYN);
- FDEBUG("cfg Wall WS[{$}],SYN[{$}]", WSNamber, (int)WSSYN);
- }
- if (m_GenConfig.GetKeyCount("WSFree") > 0)
- {
- int WSNamber = (int)m_GenConfig["WSFree"];
- EnSYNMode WSSYN = (EnSYNMode)((int)m_GenConfig["SYNFree"]);
- m_arrWSMap[cfgWorkStationKey("Free", AttrKey::MOBILE)] = cfgWorkStationData("Free", WSNamber, WSSYN);
- FDEBUG("cfg Free WS[{$}],SYN[{$}]", WSNamber, (int)WSSYN);
- }
- if (m_GenConfig.GetKeyCount("WSTomo") > 0)
- {
- int WSNamber = (int)m_GenConfig["WSTomo"];
- EnSYNMode WSSYN = (EnSYNMode)((int)m_GenConfig["SYNTomo"]);
- m_arrWSMap[cfgWorkStationKey("Tomo", AttrKey::TOMO)] = cfgWorkStationData("Tomo", WSNamber, WSSYN);
- FDEBUG("cfg Tomo WS[{$}],SYN[{$}]", WSNamber, (int)WSSYN);
- }
- if (m_GenConfig.GetKeyCount("WSConventional") > 0)
- {
- int WSNamber = (int)m_GenConfig["WSConventional"];
- EnSYNMode WSSYN = (EnSYNMode)((int)m_GenConfig["SYNConventional"]);
- m_arrWSMap[cfgWorkStationKey("Direct", AttrKey::CONVENTIONAL)] = cfgWorkStationData("Direct", WSNamber, WSSYN);
- FDEBUG("cfg Conventional WS[{$}],SYN[{$}]", WSNamber, (int)WSSYN);
- }
- //参数初始化
- ResDataObject temp;
- temp.update("Max", 150);
- temp.update("Min", 40);
- temp.update("List", "");
- for (int i = 0; i < sizeof(g_KV_List) / sizeof(g_KV_List[0]); i++)
- {
- char chindex[4] = { 0 };
- sprintf(chindex, "%d", i);
- temp["List"].add(chindex, g_KV_List[i] / 10.0f);
- }
- m_DoseUnit.m_KVList.reset(new KVLISTMould(temp.encode()));
- temp.clear();
- temp.update("Max", 1000);
- temp.update("Min", 8);
- temp.update("List", "");
- for (int i = 0; i < sizeof(g_MAS_List) / sizeof(g_MAS_List[0]); i++)
- {
- char chindex[4] = { 0 };
- sprintf(chindex, "%d", i);
- temp["List"].add(chindex, g_MAS_List[i]);
- }
- m_DoseUnit.m_mAsList.reset(new MASLISTMould(temp.encode()));
- //add by wxx for delworks:解决前端提出KV值太少的问题 20230913
- FireNotify(m_DoseUnit.m_KVList->GetKey(), m_DoseUnit.m_KVList->JSGet());
- return true;
- }
- void nsGEN::DemoDevice::FireErrorMessage(const bool Act, const int Code, const char* ResInfo)
- {
- string ErrorCode("Demo_ERR_");
- ErrorCode += std::to_string(Code);
- int level = Demo_REGULATION_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);
- if (Code == 0)
- m_MSGUnit->DelErrorMessage("0", level, ResInfo);
- else
- m_MSGUnit->DelErrorMessage(ErrorCode.c_str(), level, ResInfo);
- }
- }
- void nsGEN::DemoDevice::FireWarnMessage(const bool Act, const int Code, const char* ResInfo)
- {
- string ErrorCode("Demo_WAR_");
- ErrorCode += std::to_string(Code);
- int level = Demo_REGULATION_LEVEL::REG_WARN;
- if (Act)
- {
- FERROR("add {$}:{$}", ErrorCode.c_str(), ResInfo);
- m_MSGUnit->AddWarnMessage(ErrorCode.c_str(), level, ResInfo);
- }
- else
- {
- FERROR("del {$}:{$}", ErrorCode.c_str(), ResInfo);
- m_MSGUnit->DelWarnMessage(ErrorCode.c_str(), level, ResInfo);
- }
- }
- bool nsGEN::DemoDevice::StartHardwareStatusThread()
- {
- FINFO("enter Start HardwareStatus Thread ");
- if (m_pHardwareStatusThread == 0) // Linux使用0表示无效线程ID
- {
- // 创建线程属性对象(可选)
- pthread_attr_t attr;
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
- // 创建线程
- int ret = pthread_create(&m_pHardwareStatusThread,
- &attr,
- HardwareStatusThread,
- this);
- pthread_attr_destroy(&attr); // 销毁属性对象
- if (ret != 0)
- {
- FERROR("Start HardwareStatus Thread Failed");
- return false;
- }
- }
- return true;
- }
- void* nsGEN::DemoDevice::HardwareStatusThread(void* pParam)
- {
- DemoDevice* pCurGen = (DemoDevice*)pParam;
- if (pCurGen == NULL)
- {
- return NULL;
- }
- usleep(1500000);
- FINFO("HardwareStatusThread start");
- bool bActExpFlag = false;
- FINFO("m_iStateChangeInterval = {$},m_iAutoExpActWaitTime = {$}", pCurGen->m_iStateChangeInterval, pCurGen->m_iAutoExpActWaitTime);;
- FINFO("Request Fault Status:GENSTATE STATUS_SHUTDOWN -> STATUS_STANDBY");
- pCurGen->m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
- pCurGen->FireNotify(AttrKey::GENSTATE, pCurGen->m_DoseUnit.m_GenState->JSGet());
- while (true)
- {
- while (!bActExpFlag)
- {
- //FINFO("loopAction: begin \n");
- if (pCurGen->m_iAutoExpFlag > 0)
- {
- pCurGen->m_iAutoExpFlag = 0;
- usleep(pCurGen->m_iAutoExpActWaitTime*1000);
- if (pCurGen->m_iAutoExpFlag == 0)
- {
- FINFO("loopAction: start Exp Workflow \n");
- bActExpFlag = true;
- break;
- }
- else
- {
- FINFO("loopAction: Exp param changed restart wait \n");
- continue;
- }
- }
- usleep(pCurGen->m_iAutoExpActWaitTime*1000);
- }
- while (bActExpFlag)
- {
- FINFO("loopAction: act exp Workflow \n");
- switch (pCurGen->m_DoseUnit.m_GenSynState->Get())
- {
- case nsGEN::AttrKey::GENERATOR_RAD_OFF:
- {
- FINFO("exp Status change:RAD_OFF -> PREPARE(PR1)", pCurGen->m_DoseUnit.m_GenSynState->Get());
- pCurGen->m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_PREPARE);
- }break;
- case nsGEN::AttrKey::GENERATOR_RAD_PREPARE:
- {
- FINFO("exp Status change:PREPARE(PR1) -> RAD_READY(PR2)", pCurGen->m_DoseUnit.m_GenSynState->Get());
- pCurGen->m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_READY);
- }break;
- case nsGEN::AttrKey::GENERATOR_RAD_READY:
- {
- FINFO("exp Status change:RAD_READY(PR2) -> XRAYON(XR1)", pCurGen->m_DoseUnit.m_GenSynState->Get());
- pCurGen->m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_XRAYON);
- }break;
- case nsGEN::AttrKey::GENERATOR_RAD_XRAYON:
- {
- FINFO("exp Status change:XRAYON(XR1) -> XRAYOFF(XR0)", pCurGen->m_DoseUnit.m_GenSynState->Get());
- pCurGen->m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_XRAYOFF);
- FDEBUG("Request Fault Status:GENSTATE STATUS_STANDBY -> STATUS_EXP");
- pCurGen->m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_EXP);
- pCurGen->FireNotify(AttrKey::GENSTATE, pCurGen->m_DoseUnit.m_GenState->JSGet());
- FINFO("exp Status value:POSTKV[{$}],POSTMA[{$}],POSTMS[{$}],POSTMAS[{$}]",
- pCurGen->m_DoseUnit.m_PostKV->Get(), pCurGen->m_DoseUnit.m_PostMA->Get(), pCurGen->m_DoseUnit.m_PostMS->Get(), pCurGen->m_DoseUnit.m_PostMAS->Get());
- pCurGen->FireNotify(AttrKey::POSTKV, pCurGen->m_DoseUnit.m_PostKV->JSGet());
- pCurGen->FireNotify(AttrKey::POSTMA, pCurGen->m_DoseUnit.m_PostMA->JSGet());
- #if DEMO_DAEC_Flag
- int temp = pCurGen->m_DoseUnit.m_PostMS->Get();
- if (pCurGen->m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P ||
- pCurGen->m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P ||
- pCurGen->m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_1P)
- {
- temp /= 2;
- }
- pCurGen->FireNotify(AttrKey::POSTMS, temp);
- #else
- pCurGen->FireNotify(AttrKey::POSTMS, pCurGen->m_DoseUnit.m_PostMS->JSGet());
- #endif // DEMO_DAEC_Flag
- pCurGen->FireNotify(AttrKey::POSTMAS, pCurGen->m_DoseUnit.m_PostMAS->JSGet());
- }break;
- case nsGEN::AttrKey::GENERATOR_RAD_XRAYOFF:
- {
- FINFO("exp Status change:XRAYOFF(XR0) -> RAD_OFF", pCurGen->m_DoseUnit.m_GenSynState->Get());
- pCurGen->m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_OFF);
- FDEBUG("Request Fault Status:GENSTATE STATUS_EXP -> STATUS_STANDBY");
- pCurGen->m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
- pCurGen->FireNotify(AttrKey::GENSTATE, pCurGen->m_DoseUnit.m_GenState->JSGet());
- }
- default:
- {
- bActExpFlag = false;
- }
- }
- pCurGen->FireNotify(pCurGen->m_DoseUnit.m_GenSynState->GetKey(), pCurGen->m_DoseUnit.m_GenSynState->JSGet());
- usleep(pCurGen->m_iStateChangeInterval*1000);
- }
- }
- FINFO("HardwareStatusThread stop");
- return NULL;
- }
- //驱动
- nsGEN::DemoDriver::DemoDriver()
- {
- m_bDemoMode = false;
- m_bDemoConnected = false;
- m_bDemoInitDataFlag = false;
- m_pDriGenDev = nullptr;
- //m_pDriCollDev = nullptr;
- //m_pDriMechDev = nullptr;
- m_pAttribute.reset(new ResDataObject());
- m_pDescription.reset(new ResDataObject());
- }
- nsGEN::DemoDriver::~DemoDriver()
- {
- }
- auto nsGEN::DemoDriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
- {
- std::cout << "Enter CreateDevice, index=" << index<< std::endl;
- FINFO("Enter CreateDevice, index={$}", index);
-
- if (index == 0)
- {
- m_pDriGenDev = new DemoDevice(EventCenter, m_ConfigFileName);
- auto dev = std::unique_ptr<IODevice>(new IODevice(m_pDriGenDev));
- return dev;
- }
- else if (index == 1)
- {
- std::cout << "Enter CreateDevice COLL" << std::endl;
- FINFO("Enter CreateDevice COLL");
- if (m_bDemoInitDataFlag)
- {
- int nXSize = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["XSize"]).c_str());
- int nYSize = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["YSize"]).c_str());
- int nFilter = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["Filter"]).c_str());
- int nSID = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["SID"]).c_str());
- int nAngle = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["Angle"]).c_str());
- int nMode = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["Mode"]).c_str());
- m_pDriCollDev = new OemCollimator(std::shared_ptr<IOEventCenter>(new IOEventCenter()), nXSize, nYSize, nFilter, nSID, nAngle, nMode);
- }
- else
- m_pDriCollDev = new OemCollimator(std::shared_ptr<IOEventCenter>(new IOEventCenter()));
- auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDriCollDev));
- m_pDriCollDev->SetCtrlDev(m_pDriGenDev);
- m_pDriGenDev->SetCollimatorDev(m_pDriCollDev);
- FINFO("Leave CreateDevice COLL");
- return dev;
- }
- else if (index == 2)
- {
- std::cout << "Enter CreateDevice Mech" << std::endl;
- FINFO("Enter CreateDevice Mech");
- if (m_bDemoInitDataFlag)
- {
- int nGrid = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["Grid"]).c_str());
- int nAE = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["AE"]).c_str());
- int nFT = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["FT"]).c_str());
- int nPressureState = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["PressureState"]).c_str());
- int nCompPressureDEC = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["CompPressureDEC"]).c_str());
- int nDepress = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["Depress"]).c_str());
- float fMechAngle = (atof)(((string)m_InitDataFile["CONFIGURATION"]["MechAngle"]).c_str());
- float fMechHeight = (atof)(((string)m_InitDataFile["CONFIGURATION"]["MechHeight"]).c_str());
- float fPressureValue = (atof)(((string)m_InitDataFile["CONFIGURATION"]["PressureValue"]).c_str());
- float fAGD = (atof)(((string)m_InitDataFile["CONFIGURATION"]["AGD"]).c_str());
- float fMAG = (atof)(((string)m_InitDataFile["CONFIGURATION"]["MAG"]).c_str());
- m_pDriMechDev = new OemMechanical(std::shared_ptr<IOEventCenter>(new IOEventCenter()), nGrid, nAE, nFT, nPressureState, nCompPressureDEC, nDepress, fMechAngle, fMechHeight, fPressureValue, fAGD, fMAG);
- }
- else
- m_pDriMechDev = new OemMechanical(std::shared_ptr<IOEventCenter>(new IOEventCenter()));
- auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDriMechDev));
- m_pDriMechDev->SetCtrlDev(m_pDriGenDev);
- m_pDriGenDev->SetMechDev(m_pDriMechDev);
- FINFO("Leave CreateDevice Mech");
- return dev;
- }
- std::cout << "unknown index" << std::endl;
- FERROR("unknown index");
- unique_ptr <IODevice> dev;
- return dev;
- }
- void nsGEN::DemoDriver::FireNotify(int code, std::string key, std::string content)
- {
- EventCenter->OnNotify(code, key, content);
- }
- //Log4CPP::Logger* gLogger = nullptr;
- void nsGEN::DemoDriver::Prepare()
- {
- // 初始化日志系统
- std::string strLogPath = GetProcessDirectory() + R"(/Conf/log_config.xml)";
- std::string LogHost = "DemoGEN";
- std::string moduleName = "DemoGEN";
- bool ret = initLogModule(
- LogHost, // 主机名(用于日志路径中的{host}占位符)
- moduleName, // 唯一模块名
- strLogPath, // 配置文件路径
- true // 是否输出到控制台(可选)
- );
- if (!ret) {
- std::cerr << "Log init failed!" << std::endl;
- return;
- }
- GENDEMO_SetLocalModuleName(moduleName);
- ResDataObject r_config;
- if (r_config.loadFile(m_ConfigFileName.c_str()))
- {
- if(r_config["CONFIGURATION"].GetKeyCount("IsDemo")>0)
- {
- m_bDemoMode = (atoi)(((string)r_config["CONFIGURATION"]["IsDemo"]).c_str());
- }
- }
- string strDataPath = GetProcessDirectory() + R"(/OEMDrivers/Generator/Demo/InitData.xml)";
- try {
- if (m_InitDataFile.loadFile(strDataPath.c_str()))
- {
- m_bDemoInitDataFlag = true;
- FINFO("exist InitData");
- }
- else
- FINFO("can not open InitData[{$}]", strDataPath.c_str());
- }
- catch (const ResDataObjectExption&)
- {
- FERROR("open InitData failed");
- }
- }
- bool nsGEN::DemoDriver::Connect()
- {
- m_bDemoConnected = true;
- return true; //return SCF_ERR::SCF_SUCCEED;
- }
- void nsGEN::DemoDriver::Disconnect()
- {
- m_bDemoConnected = false;
- }
- bool nsGEN::DemoDriver::isConnected() const
- {
- return m_bDemoConnected;
- }
- std::string nsGEN::DemoDriver::DriverProbe()
- {
- printf("line= %d,%s %s\n", __LINE__, __FUNCTION__, m_ConfigFileName.c_str());
- 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", "DEMO");
- HardwareInfo.add("ProductID", "HF");
- HardwareInfo.add("SerialID", "1234");
- }
- string ret = HardwareInfo.encode();
- printf("line= %d,%s %s\n", __LINE__, __FUNCTION__, m_ConfigFileName.c_str());
- return ret;
- }
- bool nsGEN::DemoDriver::GetDeviceConfig(std::string& Cfg)
- {
- //printf("line= %d,%s\n", __LINE__, __FUNCTION__);
- //Cfg = m_GenConfig.encode();
- //return true;
- Cfg = m_DeviceConfigSend.encode();
- printf("GetDeviceConfig over , %s", Cfg.c_str());
- return true;
- }
- bool nsGEN::DemoDriver::SetDeviceConfig(std::string Cfg)
- {
- FINFO("--Func-- SetDeviceConfig {$}\n", Cfg.c_str());
- printf("\n--Func-- SetDeviceConfig %s\n", Cfg.c_str());
- 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());
- printf("%s\n", 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)
- {
- printf("\nSetDriverConfig crashed: %s\n", e.what());
- FERROR("SetDriverConfig crashed: {$}", e.what());
- return false;
- }
- }
- if (bSaveFile)
- {
- //3. 重新保存配置文件
- SaveConfigFile(true);
- }
- return true;
- }
- bool nsGEN::DemoDriver::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::DemoDriver::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();
- // printf("-TempValue=== %s", TempValue.c_str());
- resTemp.clear();
- resTemp.decode(TempValue.c_str());
- strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
- //printf("-************--%s", strTemp.c_str());
- }
- if (strTemp != "")
- {
- strValue = (string)resTemp[strTemp.c_str()];
- }
- else
- {
- strValue = (string)resTemp;
- }
- }
- //printf("------------%s", strValue.c_str());
- return true;
- }
- bool nsGEN::DemoDriver::SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue)
- {
- string strTemp = pInnerKey;
- FDEBUG("Begin to change {$} item value to {$}", pInnerKey, szValue);
- printf("\n Begin to change {%s} item value to {%s}\n", 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 != "")
- {
- //if ((strTemp.compare("WSTable") == 0) ||
- // (strTemp.compare("WSWall") == 0) ||
- // (strTemp.compare("WSFree") == 0) ||
- // (strTemp.compare("WSTomo") == 0) ||
- // (strTemp.compare("WSConventional") == 0)
- // )
- //{
- // int sum = (*szValue) + 1;
- // (*resTemp)[strTemp.c_str()] = (char*)(&sum);
- //}
- //else
- // (*resTemp)[strTemp.c_str()] = szValue;
- (*resTemp)[strTemp.c_str()] = szValue;
- }
- else
- {
- *resTemp = szValue;
- }
- }
- catch (ResDataObjectExption& e)
- {
- FERROR("SetDriverConfigvalue crashed: {$}", e.what());
- return false;
- }
- }
- return true;
- }
- std::string nsGEN::DemoDriver::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的值
- //printf("********************************innerkey=%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
- //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());
- }
- //printf("********************************outkey =%s --strValue = %s\n", 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;
- //FDEBUG("local ************* get resource over {$}", DescriptionTempEx.encode());
- //printf("local ************* get resource over %s \n", 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();
- //printf("%s", res.c_str());
- //FDEBUG("get resource over {$}", DescriptionTempEx.encode());
- //printf("************* get resource over %s \n", DescriptionTempEx.encode());
- return res;
- }
- std::string nsGEN::DemoDriver::DeviceProbe()
- {
- printf("line= %d,%s\n", __LINE__, __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", "DEMO");
- HardwareInfo.add("ProductID", "HF");
- HardwareInfo.add("SerialID", "1234");
- }
- string ret = HardwareInfo.encode();
- return ret;
- }
- void nsGEN::DemoDriver::Dequeue(const char* Packet, DWORD Length)
- {
- //DecodeFrame(Packet, Length); //无真实数据,此处直接空.
- }
- //In Demo mode ,will not enter here
- int nsGEN::DemoDriver::callbackPackageProcess(const char* RecData, DWORD nLength, DWORD& PacketLength)
- {
- return 0;
- }
- //-----------------------------------------------------------------------------
- // GetIODriver & CreateIODriver
- //-----------------------------------------------------------------------------
- static nsGEN::DemoDriver gIODriver;
- extern "C" CCOS::Dev::IODriver * GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
- {
- return &gIODriver;
- }
- extern "C" CCOS::Dev::IODriver * CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
- {
- return new nsGEN::DemoDriver();
- }
|