123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024 |
- // CCOS.Dev.GEN.PSGHR.cpp : 定义 DLL 应用程序的导出函数。
- #include <assert.h>
- #include <functional>
- #include <unordered_map>
- #include <fstream>
- #include "LogicDevice.h"
- using namespace std::placeholders;
- #include "Helper.JSON.hpp"
- #include "CCOS.Dev.Generator.PSG_HR.h"
- using namespace CCOS::Dev::Detail::Generator;
- namespace nsGEN = CCOS::Dev::Detail::Generator;
- static nsGEN::PSGHRDriver* pIODriver = nullptr;
- //关闭无关警告
- #pragma warning (disable:4244) // warning C4244: “初始化”: 从“double”转换到“float”,可能丢失数据
- #pragma warning (disable:4305) // warning C4305: “参数”: 从“double”到“float”截断
- #pragma warning (disable:4267) // warning C4267 : “初始化”: 从“size_t”转换到“int”,可能丢失数据
- #pragma warning (disable:4805) // warning C4805: “!=”: 在操作中将类型“bool”与类型“int”混合不安全
- #define PSGHR_LARGE_POWER 5
- #define PSGHR_SMALL_POWER 1.1
- #define PSGHR_MAX_HEAT 225
- #define PSGHR_MIN_MA 1.0
- #define PSGHR_MAX_MA 1000.0
- #define PSGHR_MIN_MS 1.0
- #define PSGHR_MAX_MS 10001.0
- //设置相关常量
- #define PSGHR_LoopDefHBTime 1000
- #define PSGHR_LoopExpHBTime 500
- static const int msTimeOut_Lock = 500; //通讯接口锁定时间
- #define PSGHR_Com_NormalLen 150
- #define PSGHR_ETX 0x03
- #define PSGHR_RESOK "$"
- #define Sleep(ms) std::this_thread::sleep_for(std::chrono::milliseconds(ms))
- /*
- <Command><Data><ETX><Checksum>
- 解释:
- <Command> = ASCII 字母数字命令
- <Data> = ASCII 数字数据
- <ETX> = ASCII 数字数据
- <Checksum> = 所有命令、数据和 ETX 字节的二进制 1 字节累加和
- */
- static const auto COM_SCFDllName = "libSerialSCF.so";
- static const auto TCP_SCFDllName = "libTcpipSCF.so";
- //Log4CPP::Logger* //mLog::gLogger = nullptr;
- struct tFrameMapping
- {
- static const int MaxLen = 5; // 前缀不能超过 5 个字符 !
- using cbFun = std::function <void(const char*, int)>;
- char strHead[MaxLen];
- int NbOfCharOfHead;
- cbFun fun;
- // 关键修改:将char*改为const char*,兼容字符串常量
- tFrameMapping(const char* str, int len, cbFun f)
- {
- assert(len < MaxLen); // len最大只能是4
- for (int i = 0; i < len; i++)
- strHead[i] = str[i];
- NbOfCharOfHead = len;
- fun = f;
- }
- };
- // 响应操作对照表
- static std::list <tFrameMapping> arFrame;
- //查找响应操作对照表执行对应操作
- static bool DecodeFrame(const char* strFrame, int length)
- {
- auto pr = [strFrame, length](const tFrameMapping& Item)
- {
- for (int i = 0; i < Item.NbOfCharOfHead; i++)
- {
- if (strFrame[i] != Item.strHead[i])
- {
- return false;
- }
- }
- return true;
- };
- auto found = std::find_if(arFrame.begin(), arFrame.end(), pr);//此处pr,是上面定义的 lambda表达式,用来在list中找到对于的包头。
- if (found == arFrame.end())
- {
- return false;
- }
- const auto& Item = *found;
- auto pc = strFrame;
- char data[100] = { 0 };
- memcpy(data, strFrame + Item.NbOfCharOfHead, length - Item.NbOfCharOfHead);
- Item.fun(data, length - Item.NbOfCharOfHead);
- return true;
- }
- //-----------------------------------------------------------------------------
- // PSGHRDevice
- //-----------------------------------------------------------------------------
- atomic<int> nsGEN::PSGHRDevice::m_iLoopTime = PSGHR_LoopDefHBTime;
- atomic<bool> nsGEN::PSGHRDevice::m_bExtraFlag = false;
- static atomic<bool>HeartBeatFlag = false;
- nsGEN::PSGHRDevice::PSGHRDevice(std::shared_ptr <IOEventCenter> center, std::shared_ptr<SCFWrapper> SCF, string configfile)
- : super(center)
- , superGen()
- , m_SCF(SCF)
- , m_bConnectFlag(false)
- , HeartBeatFlag(false)
- {
- assert(EventCenter);
- m_bExtraFlag = true;
- //初始化
- m_bExpEnable = false;
- m_bConnectFlag = true;
- m_iLoopTime.store(PSGHR_LoopDefHBTime);
- for (int i = 0; i < 18; i++)
- {
- m_bFaultList[i] = false;
- }
- m_iMaxPower = PSGHR_LARGE_POWER; //KW
- MaxHeatContent = PSGHR_MAX_HEAT; //KJ
- string version;
- //if(GetVersion(version, hMyModule))
- //mLog::FINFO("\n===============log begin : version:{$} ===================\n", version.c_str());
- //else
- //mLog::FINFO("\n===============log begin : version:0.0.0.0 ===================\n");
- //设置发生器属性集合各个值的范围及精度
- m_DoseUnit.m_KV.reset(new KVMould(0.0, 39.0, 151.0, 1.0));
- m_DoseUnit.m_MA.reset(new MAMould(0.0, PSGHR_MIN_MA, PSGHR_MAX_MA, 0.1));
- m_DoseUnit.m_MS.reset(new MSMould(0.0, PSGHR_MIN_MS, PSGHR_MAX_MS, 0.01));
- m_DoseUnit.m_MAS.reset(new MASMould(0.0, 0.1, 1000.0, 0.01));
- m_DoseUnit.m_Techmode.reset(new TECHMODEMould(AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P, AttrKey::TECHMODE_NOAEC_3P, AttrKey::TECHMODE_AEC_MAS_MA, 1));
- m_DoseUnit.m_WS.reset(new WORKSTATIONMould(1, 0, 5, 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, -3, 3, 1));
- m_DoseUnit.m_GenHE.reset(new GENHEATMould(0, 0, 100, 1));
- m_DoseUnit.m_HE.reset(new TUBEHEATMould(0, 0, 100, 1));
- m_DoseUnit.m_GenSynState.reset(new GENSYNSTATEMould(AttrKey::GENERATOR_RAD_OFF, AttrKey::GENERATOR_SYNC_ERR, AttrKey::GENERATOR_SYNC_MAX, 1));
- m_DoseUnit.m_GenState.reset(new GENSTATEMould(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_DoseUnit.m_FLMode.reset(new FLUModeMould(AttrKey::GENERATOR_FLUMode::GENERATOR_FLMODE_NOTFLU));
- m_DoseUnit.m_BatteryChargeState.reset(new BATTERYCHARGSTATEMould(0, 0, 1, 1));
- m_DoseUnit.m_TubeTargetMaterial.reset(new TUBETARGETMATERIALMould(AttrKey::TUBETARGETMATERIAL_TYPE::MO));
- m_DoseUnit.m_TubeAngle.reset(new TUBEANGLEMould(0, -45, 45, 1));
- 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.5, 0.5, 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_FLMode.reset(new FLUModeMould(0, 0, 4, 1));
- m_DoseUnit.m_Curve.reset(new FLUCurveMould(0, 0, 3, 1));
-
- //Actual exposure parameters 值
- m_DoseUnit.m_PostKV.reset(new POSTKVMould(0.0, 40.0, 120.0, 1.0));
- m_DoseUnit.m_PostMA.reset(new POSTMAMould(0.0, 1.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_MSGUnit.reset(new nsDetail::MSGUnit(center, nsGEN::GeneratorUnitType));
-
- m_hGenPostEvent = LinuxEvent::CreateEvent(LinuxEvent::MANUAL_RESET, false);
- //配置响应操作对照表 供发生器回传的数据触发相应的操作
- OnCallBack();
- //将发生器可以对外提供的指令注册集进行补充
- Register();
- LoadConfig(configfile);
- //重置发生器
- HWSend("RE", 2);
- //以下进行默认设置,需要注意默认值是否正确
- // HWSend("RR", 2);
- HWSend("RS", 2);
- HWSend("ET?", 3); //查询2、3点模式
- HWSend("ST?", 3);
-
- //启动硬件状态轮询进程
- StartHardwareStatusThread();
- }
- nsGEN::PSGHRDevice::~PSGHRDevice()
- {
- m_bExtraFlag = false;
- if (m_pHardwareStatusThread.joinable()) {
- m_pHardwareStatusThread.join();
- }
- //mLog::FINFO("\n===============log end ===================\n");
- arFrame.clear();
- }
- std::string nsGEN::PSGHRDevice::GetGUID() const
- {
- //mLog::FINFO("===============GetGUID : {$} ===================\n", GeneratorUnitType);
- return GeneratorUnitType;
- }
- void nsGEN::PSGHRDevice::Register()
- {
- 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; });
- Disp->Get.Push(AttrKey::DENHEAT, [this](std::string& out) { out = m_DoseUnit.m_GenHE->JSGet(); return RET_STATUS::RET_SUCCEED; });
- auto fun_Clear_DAP = [this](auto in, auto& out)
- {
- return Clear_DAP();
- };
- Disp->Action.Push("Clear_DAP", fun_Clear_DAP);
- auto fun_GetValue_DAP = [this](auto in, auto& out)
- {
- float value = 0;
- RET_STATUS ret = GetValue_DAP(value);
- out = ToJSON(value);
- return ret;
- };
- Disp->Action.Push("GetValue_DAP", fun_GetValue_DAP);
- }
- RET_STATUS nsGEN::PSGHRDevice::IncKV()
- {
- //mLog::FINFO("Enter PSGHRDevice::IncKV()\n");
- if (!m_DoseUnit.m_KV->CanInc()) return RET_STATUS::RET_SUCCEED;
- return HWSend("KV+", 3);
- }
- RET_STATUS nsGEN::PSGHRDevice::DecKV()
- {
- if (!m_DoseUnit.m_KV->CanDec()) return RET_STATUS::RET_SUCCEED;
- return HWSend("KV-", 3);
- }
- RET_STATUS nsGEN::PSGHRDevice::SetKV(float value)
- {
- if (!m_DoseUnit.m_KV->Verify(value)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "KV%03d", (int)value);
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::IncMA()
- {
- if (!m_DoseUnit.m_MA->CanInc()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- //mLog::FINFO("\n Techmode is MAS, can't inc MA");
- return RET_STATUS::RET_FAILED;
- }
- return HWSend("MA+",3);
- }
- RET_STATUS nsGEN::PSGHRDevice::DecMA()
- {
- if (!m_DoseUnit.m_MA->CanDec()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- //mLog::FINFO("\n Techmode is MAS, can't dec MA");
- return RET_STATUS::RET_FAILED;
- }
- return HWSend("MA-", 3);
- }
- RET_STATUS nsGEN::PSGHRDevice::SetMA(float value)
- {
- if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- //mLog::FINFO("\n Techmode is MAS, can't set MA");
- return RET_STATUS::RET_FAILED;
- }
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "MA%05d", (int)(value * 10));
- return HWSend(temp, strlen(temp));
-
- }
- RET_STATUS nsGEN::PSGHRDevice::IncMS()
- {
- //mLog::FINFO("nsGEN::PSGHRDevice::IncMS()\n");
- if (!m_DoseUnit.m_MS->CanInc()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
- {
- //mLog::FINFO("Techmode is 2Point, Cannot inc MS \n");
- return RET_STATUS::RET_FAILED;
- }
- return HWSend("MS+",3);
- }
- RET_STATUS nsGEN::PSGHRDevice::DecMS()
- {
- if (!m_DoseUnit.m_MS->CanDec()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
- {
- //mLog::FINFO("Techmode is 2Point, Cannot dec MS \n");
- return RET_STATUS::RET_FAILED;
- }
- return HWSend("MS-", 3);;
- }
- RET_STATUS nsGEN::PSGHRDevice::SetMS(float value)
- {
- if (!m_DoseUnit.m_MS->Verify(value)) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
- {
- //mLog::FINFO("Techmode is 2Point, Cannot set MS \n");
- return RET_STATUS::RET_FAILED;
- }
-
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "MS%07d", (int)(value * 100));
- return HWSend(temp,strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::IncMAS()
- {
- //mLog::FINFO("nsGEN::PSGHRDevice::IncMAS()\n");
- if (!m_DoseUnit.m_MAS->CanInc()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
- {
- //mLog::FINFO("Techmode is 3Point, Cannot inc MAS \n");
- return RET_STATUS::RET_FAILED;
- }
- return HWSend("MX+" , 3);
- }
- RET_STATUS nsGEN::PSGHRDevice::DecMAS()
- {
- if (!m_DoseUnit.m_MAS->CanDec()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
- {
- //mLog::FINFO("Techmode is 3Point, Cannot dec MAS \n");
- return RET_STATUS::RET_FAILED;
- }
- return HWSend("MX-", 3);
- }
- RET_STATUS nsGEN::PSGHRDevice::SetMAS(float value)
- {
- if (!m_DoseUnit.m_MAS->Verify(value)) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
- {
- //mLog::FINFO("Techmode is 3Point, Cannot set MAS \n");
- return RET_STATUS::RET_FAILED;
- }
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "MX%06d", (int)(value * 100));
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::SetTechmode(int value)
- {
- if (!m_DoseUnit.m_Techmode->Verify(value)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "ET%1d", (int)value);
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::SetEXAMMode(std::string value)
- {
- //上层给我设置exam mode(manual semiauto automatic)对应(NoAEC2Point AEC2Point AEC2Point)
- //mLog::FINFO("Enter setexammode func value = {$}\n", value);
- if (value == AttrKey::EXAMMODE_TYPE::MANUAL)
- {
- SetTechmode(AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P);
- }
- else if (value == AttrKey::EXAMMODE_TYPE::SEMIAUTO)
- {
- SetTechmode(AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P);
- }
- else if (value == AttrKey::EXAMMODE_TYPE::AUTOMATIC)
- {
- SetTechmode(AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P);
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::SetAPR(const _tAPRArgs& t)
- {
- m_bGenBusy = true;
- //mLog::FINFO("APR: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 (t.nFocus < 0)
- {
- //mLog::FINFO("SetAPR: the focus value is amall than 0, set focus to small focus\n");
- SetFocus(0);
- }
- int nTempAECFilm = 1;
- switch (t.nAECFilm)
- {
- case 0:
- nTempAECFilm = 1;
- break;
- case 1:
- nTempAECFilm = 10;
- break;
- case 2:
- nTempAECFilm = 100;
- break;
- default:
- break;
- }
- SetKV(t.fKV);
- SetFocus(t.nFocus);
- if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_AEC)
- {
- // aec
- SetTechmode(t.nTechmode);
- Sleep(50);
- SetAECField(t.nAECField);
- Sleep(80);
- SetAECDensity(t.nAECDensity);
- Sleep(50);
- SetAECFilm(nTempAECFilm);
- Sleep(50);
- SetMA(t.fMA);
- Sleep(50);
- SetMS(t.fMS);
- }
- else if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- // mas
- SetTechmode(t.nTechmode);
- Sleep(50);
- const float EPSINON = 0.000001;
- if ((t.fMAS >= -EPSINON) && (t.fMAS <= EPSINON))
- {
- SetMAS(t.fMA * t.fMS / 1000);
- }
- else
- {
- SetMAS(t.fMAS);
- }
- }
- else if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_TIME)
- {
- // time
- SetTechmode(t.nTechmode);
- Sleep(50);
- SetMA(t.fMA);
- Sleep(80);
- SetMS(t.fMS);
- }
- m_bGenBusy = false;
- HWSend("RR", 2);
- ///////////////////////end
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::RefreshData()
- {
- if (!m_bGenBusy)
- {
- HWSend("RR", 2);
- Sleep(50);
- HWSend("RS", 2);
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::SetFocus(int value)
- {
- if (!m_DoseUnit.m_Focus->Verify(value)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "FO%01d", (int)value);
- return HWSend(temp,strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::Reset()
- {
- //mLog::Debug("clear all errors \n");
- int level = 0;
- m_MSGUnit->DelErrorMessage("0", level, "clear all errors");
- m_MSGUnit->DelWarnMessage("0", level, "clear all Warning");
- HWSend("RE",2);//仅重置错误状态
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::ActiveSyncMode(_tSyncModeArgs value)
- {
- //mLog::FINFO("value.strSyncMode: {$}, value.strSyncValue: {$}, value.strWS: {$} \n", value.strSyncMode, value.strSyncValue, value.strWS);
- int nSyncModeValue = atoi(value.strSyncValue.c_str());
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "WS%01d", nSyncModeValue);
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::QueryHE(int& value)
- {
- if (!m_bGenBusy)
- return HWSend("HE?", 3);
- return RET_STATUS::RET_SUCCEED;
- }
- void nsGEN::PSGHRDevice::SubscribeSelf(ccos_mqtt_connection* conn)
- {
- //订阅GEN所有Action
- //SubscribeTopic(conn, "CCOS/DEVICE/Generator/Action/#"); Moduld层默认订阅了这个Action,如果这边也订阅的话就会执行两遍Action,可能会出问题
- }
- RET_STATUS nsGEN::PSGHRDevice::SetVibrationGrid(int value)//发生器暂无此设置
- {
- //mLog::FINFO("Enter StartVibrationGrid:[{$}]", value);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::GetVibrationGridMS(int& value) //发生器暂无此设置
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::SetAECDensity(int value)
- {
- if (!m_DoseUnit.m_AECDensity->Verify(value)) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_AEC) return RET_STATUS::RET_FAILED;
- int nAECDensity = m_DoseUnit.m_AECDensity->Get();
- if (value < m_DoseUnit.m_AECDensity->Get())
- {
- if (value < m_DoseUnit.m_AECDensity->Get() - 1)
- {
- nAECDensity = (int)value;
- }
- else
- {
- nAECDensity = nAECDensity - 1;
- }
- }
- else if (value > m_DoseUnit.m_AECDensity->Get())
- {
- if (value > m_DoseUnit.m_AECDensity->Get() + 1)
- {
- nAECDensity = (int)value;
- }
- else
- {
- nAECDensity = nAECDensity + 1;
- }
- }
- m_DoseUnit.m_AECDensity->Update(value);
- char temp[50] = { 0 };
- if (nAECDensity >= 0)
- {
- snprintf(temp, sizeof(temp), "FN+%01d", (int)nAECDensity);
- }
- else
- {
- snprintf(temp, sizeof(temp), "FN-%01d", (int)nAECDensity);
- }
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::SetAECField(int value)
- {
- if (!m_DoseUnit.m_AECField->Verify(value)) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS) return RET_STATUS::RET_FAILED;
- m_DoseUnit.m_AECField->Update(value);
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "FI%03d", (int)value);
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::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;
- m_DoseUnit.m_AECFilm->Update(value);
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "FS%03d", (int)value);
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::SetWS(const string value)
- {
- //mLog::FINFO("Enter SetWS {$}", 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"];
- m_DoseUnit.m_WS->Update(tempws);
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "WS%01d", tempws);
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::QueryPostKV(float& value)
- {
- m_DoseUnit.m_PostKV->Update(m_DoseUnit.m_KV->Get());
- value = m_DoseUnit.m_PostKV->Get();
- return HWSend("VP?",3);
- }
- RET_STATUS nsGEN::PSGHRDevice::QueryPostMA(float& value)
- {
- return HWSend("PA?", 3);
- }
- RET_STATUS nsGEN::PSGHRDevice::QueryPostMS(float& value)
- {
- return HWSend("AT?",3);
- }
- RET_STATUS nsGEN::PSGHRDevice::QueryPostMAS(float& value)
- {
- return HWSend("AP?", 3);
- }
- RET_STATUS nsGEN::PSGHRDevice::Clear_DAP()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::GetValue_DAP(float& value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::StartMove() //发生器无此设置
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::EndMove() //发生器无此设置
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::SetGenSynState(int value)
- {
- //mLog::FINFO("Enter SetGenSynState...{$} \n", value);
- //if (AttrKey::GENERATOR_RAD_XRAYON == value)
- //{
- // //mLog::FINFO("SetGenSynState be call.this is soft syn mode.");
- // HWSend("XR2",3);
- // m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON);
- // FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- //}
- //else if(AttrKey::GENERATOR_FLU_XRAYON == value)
- //{
- // //mLog::FINFO("SetGenSynState be call.this is soft syn mode.");
- // //HWSend("FLX2", 4);
- // //m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_XRAYON);
- // //FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- //}
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::SetGenState(int value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::SetExpMode(std::string value)
- {
- //mLog::FINFO("Enter SetExpMode...{$} \n",value.c_str());
- m_DoseUnit.m_ExpMode->Update(value);
- //add for dcm iRF hard
- //mLog::FINFO("SetExpMode:add for dcm iRF hard");
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- FireNotify(m_DoseUnit.m_TubeTargetMaterial->GetKey(), m_DoseUnit.m_TubeTargetMaterial->JSGet());
- FireNotify(m_DoseUnit.m_TubeAngle->GetKey(), m_DoseUnit.m_TubeAngle->JSGet());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::SetFLFMode(std::string value)
- {
- //mLog::FINFO("Enter SetFLFMode...{$} \n", value.c_str());
- if (value == "CF")
- {
- m_DoseUnit.m_FLMode->Update(1);
- HWSend("FLF1", 4);
- SetPPS(15);
- SetPluseWidth(15);
- }
- else if (value == "PF")
- {
- m_DoseUnit.m_FLMode->Update(2);
- HWSend("FLF2", 4);
- SetPPS(5);
- SetPluseWidth(5);
- }
- else
- {
- //mLog::FINFO("other FluMode : {$}", value.c_str());
- return RET_STATUS::RET_SUCCEED;
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::SetFLLever(float value)
- {
- //mLog::FINFO("Enter SetFLLever...{$} \n", value);
- m_DoseUnit.m_DoseLevel->Update(value);
- char temp[50]{ 0 };
- snprintf(temp, sizeof(temp), "FLD%f", value);
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::SetFrameRate(float frameRate)
- {
- //mLog::FINFO("SetFrameRate in\n");
- /*m_DoseUnit.m_FrameRate->Update(frameRate);
-
- char temp[50]{ 0 };
- snprintf(temp, sizeof(temp), "FLS%03d", int(frameRate * 10));
- return HWSend(temp, strlen(temp));*/
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::SetRPS(int rps) //发生器无此动态设置
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::SetAPF(const _tAPFArgs& t)
- {
- m_bGenBusy = true;
- //mLog::FINFO("APF:FLKV={$},FLMA={$},PPS={$},WS={$},FLuType={$},ABSMode={$},DoseLever={$}", t.nFLKV, t.fFLMA, t.nPPS, t.nWS, t.nFluMode, t.nABSMode, t.nDoseLever);
- SetABSMode(t.nABSMode);
- Sleep(50);
- SetFLFMode(to_string(t.nFluMode));
- Sleep(50);
- SetFluDoseLever(t.nDoseLever);
- Sleep(50);
- SetFluKV(t.nFLKV);
- Sleep(50);
- SetFluMA(t.fFLMA);
- m_bGenBusy = false;
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::IncFluKV()
- {
- //mLog::FINFO("nsGEN::PSGHRDevice::IncFLKV()\n");
- if (!m_DoseUnit.m_FLKV->CanInc()) return RET_STATUS::RET_SUCCEED;
- return HWSend("FLK+", 4);
- }
- RET_STATUS nsGEN::PSGHRDevice::DecFluKV()
- {
- if (!m_DoseUnit.m_FLKV->CanDec()) return RET_STATUS::RET_SUCCEED;
- return HWSend("FLK-", 4);
- }
- RET_STATUS nsGEN::PSGHRDevice::SetFluKV(float value)
- {
- if (!m_DoseUnit.m_FLKV->Verify(value)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "FLK%03d", (int)value);
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::IncFluMA()
- {
- if (!m_DoseUnit.m_FLMA->CanInc()) return RET_STATUS::RET_SUCCEED;
- return HWSend("FLM+", 4);
- }
- RET_STATUS nsGEN::PSGHRDevice::DecFluMA()
- {
- if (!m_DoseUnit.m_FLMA->CanDec()) return RET_STATUS::RET_SUCCEED;
- return HWSend("FLM-", 4);
- }
- RET_STATUS nsGEN::PSGHRDevice::SetFluMA(float value)
- {
- if (!m_DoseUnit.m_FLMA->Verify(value)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "FLM%03d", (int)(value * 10));
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::INCPPS()
- {
- if (!m_DoseUnit.m_PPS->CanInc()) return RET_STATUS::RET_SUCCEED;
- return HWSend("FLS+", 4);
- }
- RET_STATUS nsGEN::PSGHRDevice::DECPPS()
- {
- if (!m_DoseUnit.m_PPS->CanDec()) return RET_STATUS::RET_SUCCEED;
- return HWSend("FLS-", 4);
- }
- RET_STATUS nsGEN::PSGHRDevice::SetPPS(float value)
- {
- if (!m_DoseUnit.m_PPS->Verify(value)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "FLS%03d", (int)(value * 10));
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::SetABSMode(int nMode)
- {
- if (!m_DoseUnit.m_ABSStatus->Verify(nMode)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- //mLog::FINFO("SetABSMode[{$}] \n", nMode);
- snprintf(temp, sizeof(temp), "FLA%d", (int)nMode);
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::SetABSCurve(int curveNum)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::IncABSCurve()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::DecABSCurve()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::GetABSCurve()
- {
- return HWSend("FLA?", 4);
- }
- float nsGEN::PSGHRDevice::GetFluIntTimer()
- {
- return HWSend("FLI?", 4);
- }
- float nsGEN::PSGHRDevice::GetFluAccTimer()
- {
- return HWSend("FLT?", 4);
- }
- RET_STATUS nsGEN::PSGHRDevice::ResetFluTimer(int value)
- {
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "FLR%d", (int)value);
- //mLog::FINFO("ReSetFluAccTimer[{$}] \n", value);
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::SetFluPre(int value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::SetFluEXP(int value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::SetFluMode(std::string value)
- {
- //mLog::FINFO("Enter SetFLFMode...{$} \n", value.c_str());
- if (value == "CF")
- {
- m_DoseUnit.m_FLMode->Update(1);
- return HWSend("FLF1", 4);
- }
- else if (value == "PF")
- {
- m_DoseUnit.m_FLMode->Update(2);
- return HWSend("FLF2", 4);
- }
- else
- {
- //mLog::FINFO("other FluMode : {$}",value.c_str());
- return RET_STATUS::RET_SUCCEED;
- }
- }
- RET_STATUS nsGEN::PSGHRDevice::SetFluDoseLever(int value)
- {
- //mLog::FINFO("Enter SetFluDoseLever...{$} \n", value);
- m_DoseUnit.m_DoseLevel->Update(value);
- char temp[50]{ 0 };
- snprintf(temp, sizeof(temp), "FLD%d", value);
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::SetPluseWidth(float fplusewidth)
- {
- if (!m_DoseUnit.m_PPS->Verify(fplusewidth)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "FLW%05d", (int)(fplusewidth * 100));
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::SetExpEnable()
- {
- if (1 == m_bUseCECmd)
- {
- HWSend("CE1", 3);
- }
- HWSend("ST?", 3);
- //mLog::FINFO("SetExpEnable in\n");
- m_bExpEnable = true;
-
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
-
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::SetExpDisable()
- {
- if (1 == m_bUseCECmd)
- {
- HWSend("CE0", 3);
- }
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- //mLog::FINFO("SetExpDisable in\n");
- m_bExpEnable = false;
- return RET_STATUS::RET_SUCCEED;
- }
- void nsGEN::PSGHRDevice::SetSmartAEC(int value) //发生器暂无此设置
- {
- }
- //-----------------------------------------------------------------------------
- // ProcessCmd
- //-----------------------------------------------------------------------------
- void nsGEN::PSGHRDevice::ProcessClientData(const char* pData, unsigned long nDataLength, void* lparam)
- {
- PSGHRDevice* pCurGen = (PSGHRDevice*)lparam;
- pCurGen->HWSend(pData, nDataLength);
- }
- RET_STATUS nsGEN::PSGHRDevice::HWSend(const char* strCommand,int lengh, bool reSend, int nTimeOut)
- {
- if (!m_bConnectFlag)
- {
- //mLog::Error("==OUT==: not Connect,[{$}] send failed \n", strCommand);
- return RET_STATUS::RET_FAILED;
- }
- if (!m_SCF) return RET_STATUS::RET_FAILED;
- char strSendCommand[100] = { 0 };
- int len = strlen(strCommand);
- int tmpSum = 0;
- for (int i = 0; i < len; i++)
- {
- tmpSum += (int)strCommand[i];
- }
- char checkSum = char(tmpSum + 3);
- memcpy(strSendCommand, strCommand, len);
- strSendCommand[len + 0] = 0x03;
- strSendCommand[len + 1] = checkSum;
- //mLog::FINFO("==OUT==: [{$}] \n", strSendCommand);
- unsigned int retLength;
- if (m_SCF->Lock(1000) == WAIT_OBJECT_0) {
- int result = m_SCF->SendPacket(strSendCommand, strlen(strSendCommand), nTimeOut, retLength);
- m_SCF->Unlock();
- if (result != SCF_SUCCEED) {
- return RET_STATUS::RET_FAILED;
- }
- }
- else {
- return RET_STATUS::RET_FAILED;
- }
- return RET_STATUS::RET_SUCCEED;
- }
- void nsGEN::PSGHRDevice::FireNotify(string key, int context)
- {
- char szInfo[64] = { 0 };
- snprintf(szInfo, sizeof(szInfo), "%d", context); // Linux 标准函数
- std::string str = szInfo;
- EventCenter->OnNotify(1, key, str);
- }
- void nsGEN::PSGHRDevice::FireNotify(std::string key, float context)
- {
- char szInfo[16] = { 0 };
- snprintf(szInfo, sizeof(szInfo), "%.2f", context); // Linux 标准函数
- std::string str = szInfo;
- EventCenter->OnNotify(1, key, str);
- }
- void nsGEN::PSGHRDevice::FireNotify(std::string key, std::string context)
- {
- EventCenter->OnNotify(1, key, context);
- }
- void nsGEN::PSGHRDevice::FireErrorMessage(const bool Act, const int Code, const char* ResInfo)
- {
- string ErrorCode("PSGHR_ERR_");
- ErrorCode += std::to_string(Code);
- int level = PSG_HR_REGULATION_LEVEL::REG_ERRO;
- if (Act)
- {
- //mLog::Error("add {$}:{$}", ErrorCode.c_str(), ResInfo);
- m_MSGUnit->AddErrorMessage(ErrorCode.c_str(), level, ResInfo);
- }
- else
- {
- //mLog::Error("del {$}:{$}", ErrorCode.c_str(), ResInfo);
- m_MSGUnit->DelErrorMessage(ErrorCode.c_str(), level, ResInfo);
- }
- }
- void nsGEN::PSGHRDevice::FireWarnMessage(const bool Act, const int Code, const char* ResInfo)
- {
- string ErrorCode("PSGHR_WAR_");
- ErrorCode += std::to_string(Code);
- int level = PSG_HR_REGULATION_LEVEL::REG_WARN;
- if (Act)
- {
- //mLog::Error("add {$}:{$}", ErrorCode.c_str(), ResInfo);
- m_MSGUnit->AddWarnMessage(ErrorCode.c_str(), level, ResInfo);
- }
- else
- {
- //mLog::Error("del {$}:{$}", ErrorCode.c_str(), ResInfo);
- m_MSGUnit->DelWarnMessage(ErrorCode.c_str(), level, ResInfo);
- }
- }
- void nsGEN::PSGHRDevice::OnCallBack()
- {
- //无 操作
- auto HWNotProcess = [](const char* value, int length) -> void
- {
- //mLog::FINFO("This commands[{$}] didn't need to process", value);
- };
- auto HWKV = [this](const char* value, int length) -> void
- {
- assert(value);
- if (length > 20) //if length more than 20, it must be a long string like :070 MA00320 MS00063 MX00036
- {
- //mLog::FINFO("value:{$}", value);
- //loop the long string to find kv ma ms mas
- int tmpkv;
- float tmpma, tmpms, tmpmx;
- string strTemp = "";
- char tmpbuf[7] = { 0 };
- //kv
- tmpbuf[0] = '0';
- tmpbuf[1] = '0';
- tmpbuf[2] = '0';
- tmpbuf[3] = '0';
- tmpbuf[4] = value[0];
- tmpbuf[5] = value[1];
- tmpbuf[6] = value[2];
- tmpkv = atoi(tmpbuf);
- m_DoseUnit.m_KV->Update(tmpkv);
- FireNotify(AttrKey::KV, m_DoseUnit.m_KV->JSGet());
- //ma
- tmpbuf[0] = '0';
- tmpbuf[1] = '0';
- tmpbuf[2] = value[6];
- tmpbuf[3] = value[7];
- tmpbuf[4] = value[8];
- tmpbuf[5] = value[9];
- tmpbuf[6] = value[10];
- tmpma = atof(tmpbuf) / 10.0;
- m_DoseUnit.m_MA->Update(tmpma);
- FireNotify(AttrKey::MA, m_DoseUnit.m_MA->JSGet());
- //ms
- tmpbuf[0] = value[14];
- tmpbuf[1] = value[15];
- tmpbuf[2] = value[16];
- tmpbuf[3] = value[17];
- tmpbuf[4] = value[18];
- tmpbuf[5] = value[19];
- tmpbuf[6] = value[20];
- tmpms = atof(tmpbuf) / 100.0;
- m_DoseUnit.m_MS->Update(tmpms);
- FireNotify(AttrKey::MS, m_DoseUnit.m_MS->JSGet());
- //mx
-
- tmpbuf[0] = '0';
- tmpbuf[1] = value[24];
- tmpbuf[2] = value[25];
- tmpbuf[3] = value[26];
- tmpbuf[4] = value[27];
- tmpbuf[5] = value[28];
- tmpbuf[6] = value[29];
- tmpmx = atof(tmpbuf) / 100.0;
- m_DoseUnit.m_MAS->Update(tmpmx);
- FireNotify(AttrKey::MAS, m_DoseUnit.m_MAS->JSGet());
- //mLog::FINFO("tmpkv={$} tmpma={$}, tmpms={$}, tmpmx={$};", tmpkv, tmpma, tmpms, tmpmx);
- }
- else
- {
- if (m_DoseUnit.m_KV->Update(atof(value)))
- {
- FireNotify(AttrKey::KV, m_DoseUnit.m_KV->JSGet());
- }
- }
- };
- auto HWMAS = [this](const char* value, int length)
- {
- assert(value);
- float fmas = atof(value) / 100.0;
- if (m_DoseUnit.m_MAS->Update(fmas))
- FireNotify(AttrKey::MAS, m_DoseUnit.m_MAS->JSGet());
- };
- auto HWMA = [this](const char* value, int length)
- {
- assert(value);
- float fma = atof(value) / 10.0;
- if (m_DoseUnit.m_MA->Update(fma))
- {
- FireNotify(AttrKey::MA, m_DoseUnit.m_MA->JSGet());
- }
-
- };
- auto HWMS = [this](const char* value, int length)
- {
- assert(value);
- float fms = atof(value) / 100.0;
- if (m_DoseUnit.m_MS->Update(fms))
- FireNotify(AttrKey::MS, m_DoseUnit.m_MS->JSGet());
- };
- auto HWVP = [this](const char* value, int length)
- {
- assert(value);
- m_DoseUnit.m_PostKV->Update(atof(value));
- FireNotify(AttrKey::POSTKV, m_DoseUnit.m_PostKV->JSGet());
- //mLog::FINFO("Actual exposure parameters KV:{$}", m_DoseUnit.m_PostKV->JSGet().c_str());
- };
- auto HWPA = [this](const char* value, int length)
- {
- assert(value);
- float fma = atof(value) / 10.0;
- m_DoseUnit.m_PostMA->Update(fma);
- FireNotify(AttrKey::POSTMA, m_DoseUnit.m_PostMA->JSGet());
- //mLog::FINFO("Actual exposure parameters MA:{$}", m_DoseUnit.m_PostMA->JSGet().c_str());
- };
- auto HWAP = [this](const char* value, int length)
- {
- assert(value);
- float fmas = atof(value) / 100.0;
- m_DoseUnit.m_PostMAS->Update(fmas);
- FireNotify(AttrKey::POSTMAS, m_DoseUnit.m_PostMAS->JSGet());
- //mLog::FINFO("Actual exposure parameters MAS:{$}", m_DoseUnit.m_PostMAS->JSGet().c_str());
- };
- auto HWFocus = [this](const char* value, int length)
- {
- assert(value);
- int nfous = atoi(value);
- if (m_DoseUnit.m_Focus->Update(nfous))
- FireNotify(AttrKey::FOCUS, m_DoseUnit.m_Focus->JSGet());
- //mLog::FINFO("Current focus:{$}, FO={$}", atoi(m_DoseUnit.m_Focus->JSGet().c_str()) ? "large focus" : "small focus", m_DoseUnit.m_Focus->JSGet().c_str());
- };
- auto HWTechmode = [this](const char* value, int length)
- {
- assert(value);
- int ntechmode = atoi(value);
- m_DoseUnit.m_Techmode->Update(ntechmode);
- FireNotify(AttrKey::TECHMODE, m_DoseUnit.m_Techmode->JSGet());
- switch (ntechmode)
- {
- case 0:
- //mLog::FINFO("ET={$}", "mA/ms",m_DoseUnit.m_Techmode->JSGet().c_str());
- break;
- case 1:
- //mLog::FINFO("ET={$}", "mAs", m_DoseUnit.m_Techmode->JSGet().c_str());
- break;
- case 2:
- //mLog::FINFO("ET={$}", "AEC / mA", m_DoseUnit.m_Techmode->JSGet().c_str());
- break;
- case 3:
- //mLog::FINFO("ET={$}", "mAs / ms", m_DoseUnit.m_Techmode->JSGet().c_str());
- break;
- case 4:
- //mLog::FINFO("ET={$}", "AEC", m_DoseUnit.m_Techmode->JSGet().c_str());
- break;
- }
- };
- auto HWAECField = [this](const char* value, int length)
- {
- assert(value);
- int nvalue = atoi(value);
- if (m_DoseUnit.m_AECField->Update(nvalue))
- FireNotify(AttrKey::AECFIELD, m_DoseUnit.m_AECField->JSGet());
- };
- auto HWAECFilm = [this](const char* value, int length)
- {
- assert(value);
- if (m_DoseUnit.m_AECFilm->Update(atoi(value)))
- FireNotify(AttrKey::AECFILM, m_DoseUnit.m_AECFilm->JSGet());
- };
- auto HWAECDensity = [this](const char* value, int length)
- {
- assert(value);
- if (m_DoseUnit.m_AECDensity->Update(atoi(value)))
- FireNotify(AttrKey::AECDENSITY, m_DoseUnit.m_AECDensity->JSGet());
- };
- auto HWWS = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- m_DoseUnit.m_WS->Update(nValue);
- {
- FireNotify(m_DoseUnit.m_WS->GetKey(), m_DoseUnit.m_WS->JSGet());
- }
- };
- auto HWPR = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- if (nValue == 2)
- {
-
- }
- else if (nValue == 1)
- {
- if (m_iLoopTime != PSGHR_LoopExpHBTime)
- {
- //mLog::Debug("quicken loopTime[{$}]->[{$}]", m_iLoopTime.load(), PSGHR_LoopExpHBTime);
- m_iLoopTime = PSGHR_LoopExpHBTime;
- }
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_PREPARE);
- //mLog::FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- else if (nValue == 0)
- {
- if (m_iLoopTime == PSGHR_LoopExpHBTime)
- {
- if ((int)m_GenConfig["loopTime"] >= 100)
- {
- m_iLoopTime = (int)m_GenConfig["loopTime"];
- }
- else
- m_iLoopTime = PSGHR_LoopDefHBTime;
- //mLog::Debug("reduction loopTime[{$}]->[{$}]", PSGHR_LoopExpHBTime, m_iLoopTime.load());
- }
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF);
- //mLog::FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- m_bGenBusy = false;
- RefreshData();
- }
- };
- auto HWXR = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- if (nValue == 2)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON);
- //mLog::FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
- Sleep(50);
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- else if (nValue == 1)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_READY);
- m_hGenPostEvent->ResetEvent();
- //mLog::FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- else if (nValue == 0)
- {
- m_bGenBusy = false;
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYOFF);
- //mLog::FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- };
- auto HWAPDOSE = [this](const char* value, int length)//post mas
- {
- assert(value);
- m_DoseUnit.m_PostMAS->Update(atof(value) / 100.0);
- FireNotify(m_DoseUnit.m_PostMAS->GetKey(), m_DoseUnit.m_PostMAS->JSGet());
- //mLog::FINFO("Actual exposure parameters MAS:{$}", m_DoseUnit.m_PostMAS->JSGet().c_str());
- };
- auto HWATDOSE = [this](const char* value, int length)
- {
- assert(value);
- m_DoseUnit.m_PostMS->Update(atof(value) / 100.0);
- FireNotify(m_DoseUnit.m_PostMS->GetKey(), m_DoseUnit.m_PostMS->JSGet());
- //mLog::FINFO("Actual exposure parameters MS:{$}", m_DoseUnit.m_PostMS->JSGet().c_str());
- };
- auto HWDAP = [this](const char* value, int length)
- {
- assert(value);
- //mLog::FINFO("Recv DAP ={$}", atof(value) / 100.0);
- };
- auto HWEHE = [this](const char* value, int length)
- {
- m_iHeartBeats = 0;
- assert(value);
- int nhe = atoi(value);
- if (m_DoseUnit.m_HE->Update(nhe))
- FireNotify(m_DoseUnit.m_HE->GetKey(), m_DoseUnit.m_HE->JSGet());
- };
- auto HWHH = [this](const char* value, int length)
- {
- m_iHeartBeats = 0;
- assert(value);
- int nhe = atoi(value);
- if (m_DoseUnit.m_GenHE->Update(nhe))
- FireNotify(m_DoseUnit.m_GenHE->GetKey(), m_DoseUnit.m_GenHE->JSGet());
- };
- //04 FLM00010 FLI000 FLT000 FLF1 FLA0 FLS060 FLD0 FLO0 FLC1 FLW00400
- //040 FLM00010 FLI000 FLT000 FLF1 FLA0 FLS060 FLD0 FLO0 FLC1 FLW00400
- auto HWFLK = [this](const char* value, int length)
- {
- assert(value);
- if (length == 46) // Check if length is more than 20
- {
- int tmpflk, tmpflf, tmpfla, tmpfld, tmpflo;
- float tmpflm, tmpfli, tmpflt, tmpfls, tmpflw;
- char tmpbuf[5]{ 0, 0, 0, 0, 0 };
- //flk
- tmpbuf[0] = value[0];
- tmpbuf[1] = value[1];
- tmpbuf[2] = value[2];
- tmpflk = atoi(tmpbuf);
- if (m_DoseUnit.m_FLKV->Update(tmpflk))
- FireNotify(AttrKey::FLUKV, m_DoseUnit.m_FLKV->JSGet());
- // flm
- tmpbuf[0] = value[7];
- tmpbuf[1] = value[8];
- tmpbuf[2] = value[9];
- tmpbuf[3] = value[10];
- tmpbuf[4] = value[11];
- tmpflm = atof(tmpbuf) / 10.0;
- if (m_DoseUnit.m_FLMA->Update(tmpflm))
- FireNotify(AttrKey::FLUMA, m_DoseUnit.m_FLMA->JSGet());
- // fli
- tmpbuf[0] = value[16];
- tmpbuf[1] = value[17];
- tmpbuf[2] = value[18];
- tmpbuf[3] = 0;
- tmpbuf[4] = 0;
- tmpfli = atof(tmpbuf) / 10.0;
- if (m_DoseUnit.m_FLIntTime->Update(tmpfli))
- FireNotify(AttrKey::FLUIntTime, m_DoseUnit.m_FLIntTime->JSGet());
- // flt
- tmpbuf[0] = value[23];
- tmpbuf[1] = value[24];
- tmpbuf[2] = value[25];
- tmpbuf[3] = 0;
- tmpbuf[4] = 0;
- tmpflt = atof(tmpbuf) / 10.0;
- if (m_DoseUnit.m_FLAccTime->Update(tmpflt))
- FireNotify(AttrKey::FLUAccTime, m_DoseUnit.m_FLAccTime->JSGet());
- // flf
- tmpbuf[0] = value[30];
- tmpbuf[1] = 0;
- tmpbuf[2] = 0;
- tmpflf = atoi(tmpbuf);
- if (m_DoseUnit.m_FLMode->Update(tmpflf))
- FireNotify(AttrKey::FLUMode, m_DoseUnit.m_FLMode->JSGet());
- // fla
- tmpbuf[0] = value[35];
- tmpbuf[1] = 0;
- tmpbuf[2] = 0;
- tmpfla = atoi(tmpbuf);
- if (m_DoseUnit.m_ABSStatus->Update(tmpfla))
- FireNotify(AttrKey::FLUABSStatus, m_DoseUnit.m_ABSStatus->JSGet());
- // fls
- tmpbuf[0] = value[40];
- tmpbuf[1] = value[41];
- tmpbuf[2] = value[42];
- tmpfls = atof(tmpbuf) / 10.0;
- if (m_DoseUnit.m_PPS->Update(tmpfls))
- FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
- // fld
- tmpbuf[0] = value[47];
- tmpbuf[1] = 0;
- tmpbuf[2] = 0;
- tmpfld = atoi(tmpbuf);
- if (m_DoseUnit.m_DoseLevel->Update(tmpfld))
- FireNotify(AttrKey::FLUDoseLevel, m_DoseUnit.m_DoseLevel->JSGet());
- // flo
- tmpbuf[0] = value[52];
- tmpbuf[1] = 0;
- tmpbuf[2] = 0;
- tmpflo = atoi(tmpbuf);
- if (m_DoseUnit.m_Curve->Update(tmpflo))
- FireNotify(AttrKey::FLUCurve, m_DoseUnit.m_Curve->JSGet());
- // flw
- tmpbuf[0] = value[62];
- tmpbuf[1] = value[63];
- tmpbuf[2] = value[64];
- tmpbuf[3] = value[65];
- tmpbuf[4] = value[66];
- tmpflw = atof(tmpbuf) / 100.0;
- if (m_DoseUnit.m_FLMS->Update(tmpflw))
- FireNotify(AttrKey::FLUMS, m_DoseUnit.m_FLMS->JSGet());
- //mLog::FINFO("tmpflk={$}, tmpflf={$}, tmpfla={$}, tmpfld={$}, tmpflo={$}, tmpflm={$}, tmpfli={$}, tmpflt={$}, tmpfls={$}, tmpflw={$};", tmpflk, tmpflf, tmpfla, tmpfld, tmpflo, tmpflm, tmpfli, tmpflt, tmpfls, tmpflw);
- }
- else
- {
- int tmpflkv = atoi(value);
-
- if (m_DoseUnit.m_FLKV->Update(tmpflkv))
- {
- FireNotify(AttrKey::FLUKV, m_DoseUnit.m_FLKV->JSGet());
- }
- }
- };
- auto HWFLM = [this](const char* value, int length)
- {
- assert(value);
- float tmpflm = atof(value) / 10.0;
- if (m_DoseUnit.m_FLMA->Update(tmpflm))
- FireNotify(AttrKey::FLUMA, m_DoseUnit.m_FLMA->JSGet());
- };
- auto HWFLW = [this](const char* value, int length)
- {
- assert(value);
- float tmpflms = atof(value) / 100.0;
- if (m_DoseUnit.m_FLMS->Update(tmpflms))
- FireNotify(AttrKey::FLUMS, m_DoseUnit.m_FLMS->JSGet());
- };
- auto HWFLI = [this](const char* value, int length)
- {
- assert(value);
- float tmpfli = atof(value) / 10.0;
- if (m_DoseUnit.m_FLIntTime->Update(tmpfli))
- FireNotify(AttrKey::FLUIntTime, m_DoseUnit.m_FLIntTime->JSGet());
- };
- auto HWFLT = [this](const char* value, int length)
- {
- assert(value);
- float tmpflt = atof(value) / 10.0;
- if (m_DoseUnit.m_FLAccTime->Update(tmpflt))
- FireNotify(AttrKey::FLUAccTime, m_DoseUnit.m_FLAccTime->JSGet());
- };
- auto HWFLS = [this](const char* value, int length)
- {
- assert(value);
- float tmppps = atof(value) / 10.0;
- if (m_DoseUnit.m_PPS->Update(tmppps))
- FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
- };
- auto HWFLF = [this](const char* value, int length)
- {
- assert(value);
- //mLog::FINFO("m_FLMode={$};", value);
- int tmpflf = atoi(value);
- if (m_DoseUnit.m_FLMode->Update(tmpflf))
- FireNotify(AttrKey::FLUMode, m_DoseUnit.m_FLMode->JSGet());
- };
- auto HWFLX = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- if (nValue == 2)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_XRAYON);
- //mLog::FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- else if (nValue == 1)
- {
- //mLog::FINFO("Recv FLX1, do nothing");
- }
- else if (nValue == 0)
- {
- m_bGenBusy = false;
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_XRAYOFF);
- //mLog::FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- };
- auto HWFLP = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- if (nValue == 2)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_READY);
- //mLog::FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- else if (nValue == 1)
- {
- if (m_iLoopTime != PSGHR_LoopExpHBTime)
- {
- //mLog::Debug("quicken loopTime[{$}]->[{$}]", m_iLoopTime.load(), PSGHR_LoopExpHBTime);
- m_iLoopTime = PSGHR_LoopExpHBTime;
- }
- //mLog::FINFO("Recv FLP1, do nothing\n");
- }
- else if (nValue == 0)
- {
- if (m_iLoopTime == PSGHR_LoopExpHBTime)
- {
- if ((int)m_GenConfig["loopTime"] >= 100)
- {
- m_iLoopTime = (int)m_GenConfig["loopTime"];
- }
- else
- m_iLoopTime = PSGHR_LoopDefHBTime;
- //mLog::Debug("reduction loopTime[{$}]->[{$}]", PSGHR_LoopExpHBTime, m_iLoopTime.load());
- }
- int nFlFMode = atoi(m_DoseUnit.m_FLMode->JSGet().c_str());
- //mLog::FINFO("m_DoseUnit.m_FLMode={$}- number ={$};", m_DoseUnit.m_FLMode->JSGet().c_str(), nFlFMode);
- if (nFlFMode == 2)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_XRAYOFF);
- //mLog::FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_OFF);
- //mLog::FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- m_bGenBusy = false;
- RefreshData();
- }
- };
- auto HWDS = [this](const char* value, int length)
- {
- assert(value);
- };
- auto HWFLA = [this](const char* value, int length)
- {
- assert(value);
- int tmpfla = atoi(value);
- if ( m_DoseUnit.m_ABSStatus->Update(tmpfla))
- FireNotify(AttrKey::FLUABSStatus, m_DoseUnit.m_ABSStatus->JSGet());
- };
- auto HWFLD = [this](const char* value, int length)
- {
- assert(value);
- };
- auto HWFLC= [this](const char* value, int length)
- {
- assert(value);
- };
- auto HWFLO = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- if (m_DoseUnit.m_Curve->Update(nValue))
- FireNotify(AttrKey::FLUCurve, m_DoseUnit.m_Curve->JSGet());
- };
- auto HWER = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- char tmpbuf[4] = { 0,0,0,0 };
- tmpbuf[0] = value[0];
- tmpbuf[1] = value[1];
- tmpbuf[2] = value[2];
- if (nValue != 0)
- {
- std::unordered_map<std::string, std::string> errorMessages = {
- {"100", "AEC Back-up Timer - Exposure Terminated"},
- {"101", "AEC mAs Exceeded - Exposure Terminated"},
- {"102", "Door Interlock Error"},
- {"103", "Calibration Data Corrupt Error"},
- {"104", "AEC Data Corrupt Error"},
- {"105", "Receptor Data Corrupt Error"},
- {"106", "Tube Data Corrupt Error"},
- {"107", "Generator Limit Data Corrupt Error"},
- {"108", "mA Correction Data Corrupt Error"},
- {"109", "Not Enabled Error"},
- {"110", "AEC Feedback Error - No Feedback Signal Detected"},
- {"111", "EXP_SW Signal Active in Standby State"},
- {"112", "Calibration Error - No mA"},
- {"113", "Calibration Error - Maximum Filament Current Exceeded"},
- {"114", "MA During Exposure too High"},
- {"115", "MA During Exposure too Low"},
- {"116", "Generator KW Limit"},
- {"117", "Generator KV Limit"},
- {"118", "Generator MA Limit"},
- {"119", "Generator MS Limit"},
- {"120", "Generator MAS Limit"},
- {"121", "Tube KW Limit"},
- {"122", "Tube KV Limit"},
- {"123", "Tube MA Limit"},
- {"124", "Tube MAS Limit"},
- {"125", "Parameter Limit"},
- {"126", "Manually Terminated Exposure"},
- {"127", "Preparation Time-out Error prep time is over 30s or 60s"},
- {"128", "Prep Input Active During Initialization Phase"},
- {"129", "X-ray Input Active During Initialization Phase"},
- {"130", "No Fields Selected in AEC mode"},
- {"131", "Generator AEC Density Limit"},
- {"132", "Calibration Error - Manually Terminated"},
- {"133", "EEPROM Communication Error"},
- {"134", "RTC Communication Error"},
- {"135", "AEC Channel Error"},
- {"136", "Anode Communication Error"},
- {"137", "EXP_OK TimeOut"},
- {"138", "KV TimeOut"},
- {"139", "Mosfet Temperature Limit Exceeded"},
- {"140", "HU Power Limit"},
- {"141", "HU Power Warning"},
- {"142", "Small Focus Disable"},
- {"143", "Large Focus Disable"},
- {"144", "Low Speed Disable"},
- {"145", "High Speed Disable"},
- {"146", "Anode Heat Warning Exceeded"},
- {"147", "Anode Heat Limit Exceeded"},
- {"148", "KV Unbalance"},
- {"149", "Thermal Switch Interlock Error"},
- {"150", "Emergency Error"},
- {"151", "KV Correction Data Corrupt Error"},
- {"152", "Generator Tank Power Limit"},
- {"153", "AEC Standby Signal Error"},
- {"154", "DCBUS Calibration Data Corrupt Error"},
- {"155", "Fluoro Timer Terminated "},
- {"156", "Fluoro Timer Terminated "},
- {"157", "Power Off In X - Ray State"},
- {"158", "DAP Data Corrupt "},
- {"159", "Auto APR TimeOut "},
- {"160", "ERR_FLUORO_ABSFDBNONE"},
- {"200", "FLASH LOCK"},
- {"201", "FLASH REVID_INVALID"},
- {"202", "FLASH ADDR_INVALID"},
- {"203", "FLASH INCORRECT_PARTID"},
- {"204", "FLASH API_SILICON_MISMATCH"},
- {"205", "FLASH ERASE ERROR"},
- {"206", "FLASH FAIL_PROGRAM"},
- {"207", "FLASH FAIL_ZERO_BIT_ERROR"},
- {"208", "FLASH FAIL_VERIFY"},
- {"209", "FLASH BUSY"},
- {"210", "FLASH_PROGRM_ADDR_ERROR"},
- {"211", "UPDATA_VERSION_ERROR"},
- {"212", "UPDATA SN_ERROR"},
- {"213", "UPDATA_BYTE_COUNT_ERROR"},
- {"214", "UPDATA_CHECKSUM_ERROR"}
- };
- char ErrorCode[20];
- snprintf(ErrorCode, sizeof(ErrorCode), "PSGHR_ER_%d", nValue);
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "ER%03d", nValue);
- HWSend(temp, strlen(temp));
- int level = 1;
- auto it = errorMessages.find(tmpbuf);
- if (it != errorMessages.end())
- {
- m_MSGUnit->AddWarnMessage(ErrorCode, level, it->second.c_str());
- }
- }
- else
- {
- int level = 1;
- char ErrorCode[20];
- m_MSGUnit->DelWarnMessage(ErrorCode, level, "");
- }
- };
- auto HWEL = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- char tmpbuf[3] = { 0,0,0 };
- tmpbuf[0] = value[0];
- tmpbuf[1] = value[1];
- tmpbuf[2] = value[2];
- if (nValue != 0)
- {
- std::unordered_map<std::string, std::string> errorMessages = {
- {"001", "Generator CPU Real Time Clock Error"},
- {"002", "Main Contactor Error"},
- {"003", "Rotor Fault"},
- {"004", "DC Bus Voltage too Low"},
- {"005", "DC Bus Voltage too High"},
- {"006", "Filament Adjust Error"},
- {"007", "Filament PowerBoard Not Connected"},
- {"008", "Filament Short Circuit"},
- {"019", "Filament Overcurrent"},
- {"010", "Anode Overcurrent"},
- {"011", "Cathode Overcurrent"},
- {"012", "Anode Overvoltage"},
- {"013", "Cathode Overvoltage"},
- {"014", "ARC"},
- {"015", "Short Current 1"},
- {"016", "Short Current 2"},
- {"017", "Short Current A"},
- {"018", "Short Current B"}
- };
- char ErrorCode[20];
- snprintf(ErrorCode, sizeof(ErrorCode), "PSGHR_EL_%d", nValue);
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "EL%03d", nValue);
- HWSend(temp, strlen(temp));
- int level = 1;
- auto it = errorMessages.find(tmpbuf);
- if (it != errorMessages.end())
- {
- m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR);
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- m_MSGUnit->AddErrorMessage(ErrorCode, level, it->second.c_str());
- }
- }
- else
- {
- int level = 1;
- char ErrorCode[20];
- m_MSGUnit->DelErrorMessage(ErrorCode, level, "");
- }
- };
- auto HWEI = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- char tmpbuf[3] = { 0,0,0 };
- tmpbuf[0] = value[0];
- tmpbuf[1] = value[1];
- tmpbuf[2] = value[2];
- if (nValue != 0)
- {
- std::unordered_map<std::string, std::string> errorMessages = {
- {"400", "Enter the service mode"},
- {"401", "Exit the service mode"},
- {"402", "Resonance Overcurrent1"},
- {"403", "Resonance Overcurrent2"},
- {"404", "Resonance Overcurrent3"},
- {"405", "Charging, Please Wait "},
- {"406", "DAC Reset "},
- {"407", "X-Rays State PowerOff "},
- {"408", "Fluoro Disable "},
- {"409", "Fluoro Timer Warning Level Exceeded"},
- {"410", "Anode Heat Warning Exceeded "},
- {"411", "MA Too Low "}
- };
- char ErrorCode[20];
- snprintf(ErrorCode, sizeof(ErrorCode), "PSGHR_EI_%d", nValue);
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "EI%03d", nValue);
- HWSend(temp, strlen(temp));
- int level = 1;
- auto it = errorMessages.find(tmpbuf);
- if (it != errorMessages.end())
- {
- //m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR);
- //FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- m_MSGUnit->AddWarnMessage(ErrorCode, level, it->second.c_str());
- }
- }
- else
- {
- int level = 1;
- char ErrorCode[20];
- m_MSGUnit->DelWarnMessage(ErrorCode, level, "");
- }
- };
- auto HWMSG = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- char tmpbuf[3] = { 0,0,0 };
- tmpbuf[0] = value[0];
- tmpbuf[1] = value[1];
- tmpbuf[2] = value[2];
- if (nValue != 0)
- {
- std::unordered_map<std::string, std::string> errorMessages = {
- {"001", "Rotating anode protection parameters are incorrectly configured"},
- {"002", "Press emergency stop of high voltage generator"},
- {"003", "The first level hand brake is not triggered, and the second level hand brake is triggered"},
- {"004", "The first level hand brake is pressed during the wake - up or startup process of the high - voltage generator."},
- {"005", "The second level hand brake is pressed during the wake - up or startup process of the high - voltage generator."},
- {"006", "Low battery power of the high - voltage generator, please recharge."},
- {"007", "Anode thermal capacity exceeds the warning value."},
- {"008", "Exposure time interval is too short, please wait for exposure."},
- {"009", "Parameter adjustment is prohibited during exposure."},
- {"010", "High - voltage generator is not ready, please confirm the status."},
- {"011", "The oil tank temperature of the high - voltage generator exceeds the warning value."},
- {"012", "Training cannot be conducted in this state."},
- {"013", "The tube current of the high voltage generator is low."},
- {"014", "The PFC module of the high voltage generator works abnormally."},
- {"015", "Battery output power limits for high voltage generators."},
- {"016", "The battery of the high voltage generator is charging."},
- {"017", "The mA parameter of the high voltage generator exceeds the maximum tube value."},
- {"018", "The kV parameter of the high voltage generator exceeds the limit value."},
- {"019", "The mA parameter of the high voltage generator exceeds the limit value."},
- {"020", "The ms parameter of the high voltage generator exceeds the limit value."},
- {"021", "The mAs parameter of the high voltage generator exceeds the limit value."},
- {"022", "Filament selection parameter exceeds the limit."},
- {"023", "Anode rotation speed selection parameter exceeds the limit."},
- {"024", "The exposure technical parameters of the high voltage generator exceed the limits."},
- {"025", "AEC density parameter exceeds the limit."},
- {"026", "AEC field selection parameter exceeds the limit."},
- {"027", "AEC channel parameter exceeds the limit."},
- {"028", "AEC sensitivity parameter exceeds the limit."},
- {"029", "High - voltage generator power exceeds the limit."},
- {"030", "Tube power exceeds the limit."},
- {"031", "The frame rate parameter of the high voltage generator exceeds the limit value."},
- {"032", "Exposure parameter exceeds the high - voltage generator energy storage limit."},
- {"033", "High voltage generator battery pack alarm."},
- {"035", "Foot brake signal is pressed during the wake - up or startup process of the high - voltage generator."},
- {"036", "Cumulative fluoroscopy time alarm."},
- {"037", "The console of the high voltage generator is not connected, please open the console."},
- {"038", "Tube sleeve thermal capacity exceeds the warning value."},
- {"049", "Bus voltage of the high - voltage generator exceeds the limit."},
- {"050", "High - voltage generator does not support this exposure mode."},
- {"051", "The rotation speed of the rotating anode does not meet the exposure requirements."},
- {"052", "The second level hand brake is not pressed within the specified time."},
- {"053", "Interlock 1 is effective during the exposure process of the high - voltage generator."},
- {"054", "Timeout for feedback signal in flat panel mode."},
- {"055", "The kV establishment timeout of the high voltage generator."},
- {"056", "Anode thermal capacity exceeds the limit."},
- {"057", "Filament calibration data abnormality."},
- {"058", "Tube current is too low during training."},
- {"059", "Release hand brake prematurely during exposure."},
- {"060", "AEC feedback abnormality."},
- {"061", "Inverter temperature of the high - voltage generator exceeds the limit."},
- {"062", "kV is too low during exposure, exposure abnormality aborted."},
- {"063", "kV is too high during exposure, exposure abnormality aborted."},
- {"064", "Oil temperature of the high - voltage generator exceeds the limit."},
- {"065", "Tube sleeve thermal capacity exceeds the limit."},
- {"066", "The current exposure parameters of the high voltage generator exceed the heat capacity limit."},
- {"068", "mA is too high during exposure, exposure abnormality aborted."},
- {"069", "The DRVEN enable of the high voltage generator to establish a timeout."},
- {"070", "Interruption in communication with the rotating anode."},
- {"071", "Emergency stop is pressed during exposure."},
- {"072", "The battery pack of the high voltage generator is faulty."},
- {"073", "Resonant current exceeds the limit, exposure abnormality aborted(software)."},
- {"074", "Anode kV exceeds the limit, exposure abnormality aborted(software)."},
- {"075", "Cathode kV exceeds the limit, exposure abnormality aborted(software)."},
- {"076", "Filament current exceeds the limit(software)."},
- {"078", "Oil tank power limit of the high - voltage generator."},
- {"080", "Deviation of anode kV and cathode kV exceeds the limit, exposure abnormality aborted."},
- {"081", "Power exceeds the limit during exposure, exposure abnormality aborted."},
- {"082", "The external synchronization signal of the high voltage generator has timed out."},
- {"083", "Fan fault in high voltage generator."},
- {"084", "High voltage generator InterLock1 effective."},
- {"085", "High voltage generator InterLock2 effective."},
- {"087", "Release foot brake prematurely during exposure."},
- {"088", "Foot brake signal abnormality."},
- {"089", "The DA chip of the high voltage generator is abnormal."},
- {"090", "Timeout for cumulative fluoroscopy time."},
- {"091", "The external discharge line of the high voltage generator enables the signal to timeout."},
- {"092", "XRAYReady invalid."},
- {"093", "High voltage generator during exposure interlock 2 effective."}
- };
- char ErrorCode[20];
- snprintf(ErrorCode, sizeof(ErrorCode), "PSGHR_MSG_%d", nValue);
- int level = 1;
- /*char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "MSG%03d", nValue);
- HWSend(temp, strlen(temp));*/
- auto it = errorMessages.find(tmpbuf);
- if (it != errorMessages.end())
- {
- //mLog::FINFO("WarnCode: {$}, Level: {$}, ResInfo: {$}\n", ErrorCode, level, it->second.c_str());
- m_MSGUnit->AddWarnMessage(ErrorCode, level, it->second.c_str());
- }
- }
- else
- {
- int level = 1;
- char WarnCode[20]{ "" };
- m_MSGUnit->DelWarnMessage(WarnCode, level, "");
- }
- };
- //==IN==:TU0 WS1 FO0 ET0 FI010 FS001 FN0 HE000
- auto HWTU = [this](const char* value, int length) -> void
- {
- assert(value);
- //mLog::FINFO("recv TU={$},len={$}", value, length);
- char tmpbuf[3] = { 0,0,0 };
- int tmpWS, tmpFO, tmpET, tmpField, tmpFilm, tmpDensity, tmpHE;
- //ws
- tmpbuf[0] = value[4];
- tmpWS = atoi(tmpbuf);
- m_DoseUnit.m_WS->Update(tmpWS);
- {
- FireNotify(m_DoseUnit.m_WS->GetKey(), m_DoseUnit.m_WS->JSGet());
- }
- //FO
- tmpbuf[0] = value[8];
- tmpFO = atoi(tmpbuf);
- m_DoseUnit.m_Focus->Update(tmpFO);
- FireNotify(AttrKey::FOCUS, m_DoseUnit.m_Focus->JSGet());
- //mLog::FINFO("Current focus:{$}, FO={$}", atoi(m_DoseUnit.m_Focus->JSGet().c_str()) ? "large focus" : "small focus", m_DoseUnit.m_Focus->JSGet().c_str());
- //ET
- tmpbuf[0] = value[12];
- tmpET = atoi(tmpbuf);
- m_DoseUnit.m_Techmode->Update(tmpET);
- FireNotify(AttrKey::TECHMODE, m_DoseUnit.m_Techmode->JSGet());
- //FIELD
- tmpbuf[0] = value[16];
- tmpbuf[1] = value[17];
- tmpbuf[2] = value[18];
- tmpField = atoi(tmpbuf);
- if (m_DoseUnit.m_AECField->Update(tmpField))
- FireNotify(AttrKey::AECFIELD, m_DoseUnit.m_AECField->JSGet());
- //Film
- tmpbuf[0] = value[22];
- tmpbuf[1] = value[23];
- tmpbuf[2] = value[24];
- tmpFilm = atoi(tmpbuf);
- if (m_DoseUnit.m_AECFilm->Update(tmpFilm))
- FireNotify(AttrKey::AECFILM, m_DoseUnit.m_AECFilm->JSGet());
- //Density
- tmpbuf[0] = value[29];
- tmpbuf[1] = 0;
- tmpbuf[2] = 0;
- tmpDensity = atoi(tmpbuf);
- if (m_DoseUnit.m_AECDensity->Update(tmpDensity))
- FireNotify(AttrKey::AECDENSITY, m_DoseUnit.m_AECDensity->JSGet());
- //HE
- tmpbuf[0] = value[33];
- tmpbuf[1] = value[34];
- tmpbuf[2] = value[35];
- tmpHE = atoi(tmpbuf);
- m_DoseUnit.m_HE->Update(tmpHE);
- FireNotify(m_DoseUnit.m_HE->GetKey(), m_DoseUnit.m_HE->JSGet());
- //mLog::FINFO("parse tmpWS={$}, tmpFO={$}, tmpET={$}, tmpField={$}, tmpFilm={$}, tmpDensity={$}, tmpHE={$}", tmpWS, tmpFO, tmpET, tmpField, tmpFilm, tmpDensity, tmpHE);
- };
- auto HWST = [this](const char* value, int length)
- {
- assert(value);
- int genStatus = atoi(value);
- //mLog::FINFO("genStatus={$}", genStatus);
- switch (genStatus)
- {
- case 1:
- //初始化
- //mLog::Debug("get Gen Status_1:GENSTATE {$} -> STATUS_INIT", m_DoseUnit.m_GenState->JSGet());
- ///*if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_INIT))
- // FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());*/
- break;
- case 2:
- //mLog::Debug("get Gen Status_2:GENSTATE {$} -> STATUS_STANDBY", m_DoseUnit.m_GenState->JSGet());
- if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY))
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- break;
- case 3: // Rad Preparation Phase
- /*//mLog::Debug("get Gen Status_3:RAD_OFF(PR0) -> RAD_PREPARE(PR1)");
- if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_PREPARE))
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());*/
- if (m_iLoopTime != PSGHR_LoopExpHBTime) //加快查询时间
- {
- //mLog::Debug("get Gen Status_3:quicken loopTime[{$}]->[{$}]", m_iLoopTime.load(), PSGHR_LoopExpHBTime);
- m_iLoopTime = PSGHR_LoopExpHBTime;
- }
- break;
- case 4:
- //mLog::Debug("get Gen Status_4:PREPARE(PR1) -> RAD_READY(PR2)");
- /*if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_READY))
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());*/
- break;
- case 5:
- //mLog::Debug("get Gen Status_5:RAD_READY(PR2) -> X-Ray On(XR2)");
- 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(nsGEN::AttrKey::GENERATOR_RAD_XRAYON))
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());*/
- break;
- case 6:
- //mLog::Debug("get Gen Status_6:X-Ray On(XR2) -> X-Ray Off(XR0)");
- /*if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_XRAYOFF))
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());*/
- break;
- case 7:
- if (m_iLoopTime == PSGHR_LoopExpHBTime)
- {
- if ((int)m_GenConfig["loopTime"] >= 100)
- {
- m_iLoopTime = (int)m_GenConfig["loopTime"];
- }
- else
- m_iLoopTime = PSGHR_LoopDefHBTime;
- //mLog::Debug("reduction loopTime[{$}]->[{$}]", PSGHR_LoopExpHBTime, m_iLoopTime.load());
- }
- //mLog::Debug("get Gen Status_7:GENSTATE {$} -> STATUS_ERROR", m_DoseUnit.m_GenState->JSGet());
- if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR))
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- break;
- case 8:
- //mLog::Debug("get Gen Status_8:in Calibration");
- break;
- default:
- //mLog::Debug("get Gen Status:[{$}] unknown", genStatus);
- break;
- }
- };
- auto HWSR = [this](const char* value, int length)
- {
- assert(value);
- int stopReason = atoi(value);
- //mLog::FINFO("stopReason={$}", stopReason);
- switch (stopReason)
- {
- case 0:
- //mLog::Debug("Exposure stop reason:AEC feedback voltage is too low");
- break;
- case 5:
- //mLog::Debug("Exposure stop reason: Stop exposure manually");
- break;
- case 6:
- //mLog::Debug("Exposure stop reason: door lock open");
- break;
- case 7:
- //mLog::Debug("Exposure stop reason:Bulb tube anode ignition");
- break;
- case 8:
- //mLog::Debug("Exposure stop reason:Bulb cathode ignition");
- break;
- case 9:
- //mLog::Debug("Exposure stop reason:The pipe is lit");
- break;
- case 10:
- //mLog::Debug("Exposure stop reason:KV is too low or too high");
- break;
- case 11:
- //mLog::Debug("Exposure stop reason:Ma too low");
- break;
- case 12:
- //mLog::Debug("Exposure stop reason:Set ms reached");
- break;
- case 13:
- //mLog::Debug("Exposure stop reason:Set mAs reached");
- break;
- case 14:
- //mLog::Debug("Exposure stop reason:AEC dose reached");
- break;
- default:
- //mLog::Debug("Exposure stop reason:default");
- break;
- }
- };
- arFrame.clear();
- arFrame.push_back(tFrameMapping("EL", 2, HWEL));
- arFrame.push_back(tFrameMapping("EI", 2, HWEI));
- arFrame.push_back(tFrameMapping("ER", 2, HWER));
- arFrame.push_back(tFrameMapping("MSG", 3, HWMSG));
- arFrame.push_back(tFrameMapping("TU", 2, HWTU));
- arFrame.push_back(tFrameMapping("EC", 2, HWNotProcess));
- arFrame.push_back(tFrameMapping("PW", 2, HWNotProcess));
-
- arFrame.push_back(tFrameMapping("KV", 2, HWKV));
- arFrame.push_back(tFrameMapping("MX", 2, HWMAS));
- arFrame.push_back(tFrameMapping("MA", 2, HWMA));
- arFrame.push_back(tFrameMapping("MS", 2, HWMS));
- arFrame.push_back(tFrameMapping("VP", 2, HWVP));
- arFrame.push_back(tFrameMapping("PA", 2, HWPA));
- arFrame.push_back(tFrameMapping("AP", 2, HWAPDOSE));
- arFrame.push_back(tFrameMapping("ET", 2, HWTechmode));
- arFrame.push_back(tFrameMapping("FO", 2, HWFocus));
- arFrame.push_back(tFrameMapping("FI", 2, HWAECField));
- arFrame.push_back(tFrameMapping("FS", 2, HWAECFilm));
- arFrame.push_back(tFrameMapping("FN", 2, HWAECDensity));
- arFrame.push_back(tFrameMapping("WS", 2, HWWS));
- arFrame.push_back(tFrameMapping("PR", 2, HWPR));
- arFrame.push_back(tFrameMapping("XR", 2, HWXR));
- arFrame.push_back(tFrameMapping("AT", 2, HWATDOSE));
- arFrame.push_back(tFrameMapping("FLK", 3, HWFLK));
- arFrame.push_back(tFrameMapping("FLM", 3, HWFLM));
- arFrame.push_back(tFrameMapping("FLW", 3, HWFLW));
- arFrame.push_back(tFrameMapping("FLI", 3, HWFLI));
- arFrame.push_back(tFrameMapping("FLT", 3, HWFLT));
- arFrame.push_back(tFrameMapping("FLS", 3, HWFLS));
- arFrame.push_back(tFrameMapping("FLF", 3, HWFLF));
- arFrame.push_back(tFrameMapping("FLP", 3, HWFLP));
- arFrame.push_back(tFrameMapping("FLX", 3, HWFLX));
- arFrame.push_back(tFrameMapping("FLA", 3, HWFLA));
- arFrame.push_back(tFrameMapping("FLD", 3, HWFLD));
- arFrame.push_back(tFrameMapping("FLC", 3, HWFLD));
- arFrame.push_back(tFrameMapping("FLO", 3, HWFLO));
- arFrame.push_back(tFrameMapping("HE", 2, HWEHE));
- arFrame.push_back(tFrameMapping("HH", 2, HWHH));
- arFrame.push_back(tFrameMapping("DA", 2, HWDAP));
- arFrame.push_back(tFrameMapping("DV", 2, HWDAP));
- arFrame.push_back(tFrameMapping("DS", 2, HWDS));
- arFrame.push_back(tFrameMapping("ST", 2, HWST));
- arFrame.push_back(tFrameMapping("SR", 2, HWSR));
- arFrame.push_back(tFrameMapping("P", 1, HWPR));
- }
- bool nsGEN::PSGHRDevice::ReConnect()
- {
- //mLog::FINFO("Enter PSG_reConnect");
- m_SCF->Disconnect();
- if (!pIODriver)
- {
- //mLog::FINFO("PSG_reConnect:Driver null");
- }
- else
- {
- // 需要将 pIODriver 转换为 PSGHRDriver*
- PSGHRDriver* driver = dynamic_cast<PSGHRDriver*>(pIODriver.get());
- if (driver && driver->ReConnection())
- {
- FireErrorMessage(false, 1, "lost Connect");
- m_bConnectFlag = true;
- //mLog::FINFO("PSG_reConnect success");
- return true;
- }
- else
- {
- //mLog::FINFO("PSG_reConnect failed");
- }
- }
- return false;
- }
- int nsGEN::PSGHRDevice::GridMSMargin()//发生器暂无此设置
- {
- return 0;
- }
- bool nsGEN::PSGHRDevice::CalculateAppropriateMA(float& inoutMAS, float& inoutMA, float& inoutMS)
- {
- //mLog::FINFO("Enter CalculateAppropriateMA:MAS[{$}],MA[{$}],MS[{$}]", inoutMAS, inoutMA, inoutMS);
- if (m_DoseUnit.m_Focus->Get() == AttrKey::FOCUS_TYPE::FOCUS_LARGE)
- {
- m_iMaxPower = PSGHR_LARGE_POWER;
- }
- else
- {
- m_iMaxPower = PSGHR_SMALL_POWER;
- }
- int currKV = 0 , tempMA = 0, tempMS = 0;
- currKV = m_DoseUnit.m_KV->Get();
- tempMA = m_iMaxPower * 1000 / currKV;
- //mLog::Debug("power[{$}]*1000 / KV[{$}] = MAX_MA[{$}]", m_iMaxPower, currKV, tempMA);
- if (tempMA > PSGHR_MAX_MA)
- {
- tempMA = PSGHR_MAX_MA;
- //mLog::Debug(" MAX_MA too big,be close to range_right[{$}]", tempMA);
- }
- else if (tempMA < PSGHR_MIN_MA)
- {
- //mLog::Warn(" MAX_MA too small,compute failed");
- return false;
- }
- for (int i = tempMA;i >= PSGHR_MIN_MA; i--)
- {
- tempMS = inoutMAS * 1000.0 / i;
- //mLog::Debug("MAS[{$}]*1000 / temp_MA[{$}] = temp_MS[{$}]", inoutMAS, i, tempMS);
- }
-
- //mLog::Debug("can not use MAS[{$}]compute Appropriate MA MS", inoutMAS);
- return false;
- }
- void nsGEN::PSGHRDevice::ReSendFailedAction(string& cmdNum)//发生器暂无此设置
- {
- }
- int nsGEN::PSGHRDevice::GetGenState()
- {
- if (m_DoseUnit.m_GenState != NULL)
- {
- return m_DoseUnit.m_GenState->Get();
- }
- else
- {
- return 0;
- }
- }
- int nsGEN::PSGHRDevice::LoadConfig(string configfile)
- {
- //mLog::FINFO("=====================LoadConfig=========================");
- // 检查文件是否存在
- std::ifstream file(configfile);
- if (!file) {
- // 文件不存在,直接返回空的Connection对象
- //mLog::FINFO("Config file does not exist: {$}", configfile.c_str());
- return -1;
- }
- if (m_bIsConfigLoaded)
- {
- //mLog::FINFO("Configuration already loaded.");
- return 0;
- }
- ResDataObject temp;
- temp.loadFile(configfile.c_str());
- m_GenConfig = temp["CONFIGURATION"];
- TransJsonText(m_GenConfig);
- if (m_GenConfig.GetKeyCount("loopEnable") > 0)
- {
- m_bExtraFlag = (int)m_GenConfig["loopEnable"];
- }
- if (m_GenConfig.GetKeyCount(ConfKey::CcosTubeInfo) > 0)
- {
- string tempValue = (string)m_GenConfig[ConfKey::CcosTubeInfo];
- m_DoseUnit.m_TubeInfo.reset(new TUBEINFOMould(tempValue));
- FireNotify(AttrKey::TUBEINFO, m_DoseUnit.m_TubeInfo->JSGet());
- }
- 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("GenCtrlMode") > 0)
- {
- m_nCtlMode = (float)m_GenConfig["GenCtrlMode"];//default 2
- float tempValue = (float)m_GenConfig[ConfKey::CcosFocusLarge];
- }
- if (m_GenConfig.GetKeyCount("USECECMD") > 0)
- {
- m_bUseCECmd = (bool)m_GenConfig["USECECMD"];
- }
- m_bIsConfigLoaded = true;
- return 0;
- }
- bool nsGEN::PSGHRDevice::EnableBucky(int nbucky)
- {
- char temp[50]{ 0 };
- snprintf(temp, sizeof(temp), "BU%1d", nbucky);
- return HWSend(temp, strlen(temp));
- }
- bool nsGEN::PSGHRDevice::ECHO(void)
- {
- return HWSend("EC", 2);
- }
- bool nsGEN::PSGHRDevice::SetABSModeNative(int nMode)
- {
- char temp[50]{ 0 };
- snprintf(temp, sizeof(temp), "FLA%1d", nMode);
- return HWSend(temp, strlen(temp));
- }
- bool nsGEN::PSGHRDevice::StartHardwareStatusThread()
- {
- if (!m_pHardwareStatusThread.joinable())
- {
- m_pHardwareStatusThread = std::thread(HardwareStatusThread, this);
- return true;
- }
- return false;
- }
- void PSGHRDevice::HardwareStatusThread(PSGHRDevice* pParam)
- {
- PSGHRDevice* pCurGen = pParam;
- if (pCurGen == NULL)
- {
- return;
- }
- pCurGen->HeartBeatFlag = true;
- int messageIndex = 0;
- int currtTime = pCurGen->m_iLoopTime;
- while (pCurGen->m_bExtraFlag)
- {
- currtTime = pCurGen->m_iLoopTime;
- Sleep(currtTime);
- if (messageIndex % 5 == 0)
- {
- pCurGen->HWSend("HE?", 3);
- Sleep(100);
- pCurGen->HWSend("ST?", 3);
- }
- messageIndex++;
- }
- }
- //-----------------------------------------------------------------------------
- // PSGHRDriver
- //-----------------------------------------------------------------------------
- nsGEN::PSGHRDriver::PSGHRDriver()
- : m_scfWrapper(std::make_shared<SCFWrapper>())
- {
- m_pAttribute.reset(new ResDataObject());
- m_pDescription.reset(new ResDataObject());
- }
- nsGEN::PSGHRDriver::~PSGHRDriver()
- {
- Disconnect();
- //mLog::Close();
- //mLog::gLogger = nullptr;
- }
- void nsGEN::PSGHRDriver::Prepare()
- {
- //string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Generator\Conf\Log4CPP.Config.GEN.xml)";
- //Log4CPP::GlobalContext::Map::Set(ECOM::Utility::Hash("LogFileName"), "GEN.PSG_HR");
- //auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
- //mLog::gLogger = Log4CPP::LogManager::GetLogger("GEN.PSG_HR");
- m_SCFDllName = GetConnectDLL(m_ConfigFileName);
- //super::Prepare();
- //mLog::FINFO("OK.");
- }
- std::string nsGEN::PSGHRDriver::DriverProbe()
- {
- //mLog::FINFO("DriverProbe in \n");
- 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", "PSGHR");
- HardwareInfo.add("ProductID", "HF");
- HardwareInfo.add("SerialID", "Drv");
- }
- string ret = HardwareInfo.encode();
- return ret;
- }
- bool nsGEN::PSGHRDriver::ReConnection()
- {
- Disconnect();
- //mLog::FINFO("ReConnection:SCF Disconnect");
- ResDataObject Connection = GetConnectParam(m_ConfigFileName);
- //mLog::FINFO("ReConnection:{$} \n", Connection.encode());
- auto erCode = m_scfWrapper->Connect(Connection, &PSGHRDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
- if (erCode == SCF_SUCCEED)
- {
- Sleep(1000);
- // 重新设置数据接收回调
- m_scfWrapper->SetDataReceivedCallback([this](const char* data, uint32_t length) {
- this->Dequeue(data, length);
- });
- // 启动自动接收
- m_scfWrapper->StartAutoReceive();
- return true;
- }
- else
- {
- //mLog::FINFO("ReConnection failed");
- }
- return false;
- }
- bool nsGEN::PSGHRDriver::Connect()
- {
- //mLog::FINFO("Enter {$},configlef={$}\n", __FUNCTION__, m_ConfigFileName.c_str());
- ResDataObject Connection = GetConnectParam(m_ConfigFileName);
- //mLog::FINFO("connections:{$} \n", Connection.encode());
- if (!m_scfWrapper->Initialize(m_SCFDllName)) {
- //mLog::FINFO("Failed to initialize SCFWrapper: {}", m_scfWrapper->GetLastError());
- return false;
- }
- // 设置数据接收回调
- m_scfWrapper->SetDataReceivedCallback([this](const char* data, uint32_t length) {
- this->Dequeue(data, length);
- });
- auto erCode = m_scfWrapper->Connect(Connection, &PSGHRDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
- if (erCode != SCF_SUCCEED)
- return false;
- // 启动自动接收
- if (!m_scfWrapper->StartAutoReceive()) {
- //mLog::FINFO("Failed to start auto receive");
- return false;
- }
- return true;
- }
- auto nsGEN::PSGHRDriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
- {
- //mLog::FINFO("CreateDevice in\n");
- m_pDevice = new PSGHRDevice(EventCenter, m_scfWrapper, m_ConfigFileName);
- auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDevice));
- //mLog::FINFO("CreateDevice out\n");
- return dev;
- }
- void nsGEN::PSGHRDriver::FireNotify(int code, std::string key, std::string content)
- {
- EventCenter->OnNotify(code, key, content);
- }
- bool nsGEN::PSGHRDriver::isConnected() const
- {
- if (m_scfWrapper && m_scfWrapper->IsConnected())
- {
- return true;
- }
- if (m_pDevice == nullptr)
- {
- //mLog::FINFO("m_pDevice == nullptr\n");
- return false;
- }
- if (m_pDevice->LoadConfig(m_ConfigFileName) == -1)
- {
- return false; //return 0;
- }
- int genState = m_pDevice->GetGenState();
- //mLog::FINFO("m_pDevice->GetGenState() == {$}\n", genState);
- return genState > 0; // 只有返回值大于 0 时才返回 true
- }
- std::string nsGEN::PSGHRDriver::GetResource()
- {
- //mLog::Debug("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)
- {
- //mLog::Error("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;
- ////mLog::Debug("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());
- ////mLog::Debug("get resource over {$}", DescriptionTempEx.encode());
- //("************* get resource over %s \n", DescriptionTempEx.encode());
- return res;
- }
- std::string nsGEN::PSGHRDriver::DeviceProbe()
- {
- //mLog::FINFO("std::string nsGEN::PSGHRDriver::DeviceProbe() in\n");
- 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", "PSGHR");
- HardwareInfo.add("ProductID", "HF");
- HardwareInfo.add("SerialID", "Dev");
- }
- string ret = HardwareInfo.encode();
- //mLog::FINFO("std::string nsGEN::PSGHRDriver::DeviceProbe() out\n");
- return ret;
- }
- void nsGEN::PSGHRDriver::Disconnect()
- {
- if (m_scfWrapper) {
- m_scfWrapper->StopAutoReceive();
- m_scfWrapper->Disconnect();
- }
- //mLog::Close();
- //mLog::gLogger = nullptr;
- }
- void nsGEN::PSGHRDriver::Dequeue(const char* Packet, DWORD Length)
- {
- DecodeFrame(Packet, Length);
- }
- PACKET_RET nsGEN::PSGHRDriver::callbackPackageProcess(const char* RecData, uint32_t nLength, uint32_t& PacketLength)
- {
- if (nLength < 1)
- {
- //mLog::FINFO("nLength < 1, nLength=={} \n", nLength);
- return PACKET_USELESS;
- }
- for (DWORD i = 0; i < nLength - 1; i++)
- {
- if (RecData[i] == 0x02)
- {
- if (i != 0)
- {
- PacketLength = i;
- char strtemp[100] = { 0 };
- memcpy(strtemp, RecData, i);
- strtemp[PacketLength + 1] = 0;
- printf("==IN error data ==:%s,PacketLength=%d,nLength=%d\n", strtemp, PacketLength, nLength);
- return PACKET_USELESS;
- }
- }
- if (RecData[i] == 0x03)
- {
- PacketLength = i + 2;
- char strtemp[100] = { 0 };
- memcpy(strtemp, RecData, i);
- strtemp[PacketLength + 1] = 0;
- //mLog::FINFO("==IN==:{}\n", strtemp);
- return PACKET_ISPACKET;
- }
- }
- return PACKET_NOPACKET;
- }
- bool nsGEN::PSGHRDriver::GetDeviceConfig(std::string& Cfg)
- {
- Cfg = m_DeviceConfigSend.encode();
- printf("GetDeviceConfig over , %s", Cfg.c_str());
- return true;
- }
- bool nsGEN::PSGHRDriver::SetDeviceConfig(std::string Cfg)
- {
- //mLog::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"];
- //mLog::Debug("Attribute:{$}", DescriptionTempEx.encode());
- bool bSaveFile = false; //true:重新保存配置文件
- string strAccess = "";
- for (int i = 0; i < DescriptionTempEx.size(); i++)
- {
- string strKey = DescriptionTempEx.GetKey(i);
- //mLog::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");
- //mLog::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]))
- {
- //mLog::Debug("SetDeviceConfigValue over");
- bSaveFile = true;
- }
- }
- else
- {
- //mLog::FINFO("{$} is not a RW configuration item", strKey.c_str());
- }
- }
- else
- {
- //mLog::FINFO("without this attribute {$}", strKey.c_str());
- }
- }
- catch (ResDataObjectExption& e)
- {
- printf("\nSetDriverConfig crashed: %s\n", e.what());
- //mLog::Error("SetDriverConfig crashed: {$}", e.what());
- return false;
- }
- }
- if (bSaveFile)
- {
- //3. 重新保存配置文件
- SaveConfigFile(true);
- }
- return true;
- }
- bool nsGEN::PSGHRDriver::SaveConfigFile(bool bSendNotify)
- {
- m_ConfigAll["CONFIGURATION"] = m_Configurations;
- bool bRt = m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
- //mLog::FINFO("SaveConfigFile over {$}", bRt);
- return true;
- }
- bool nsGEN::PSGHRDriver::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::PSGHRDriver::SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue)
- {
- string strTemp = pInnerKey;
- //mLog::Debug("Begin to change {$} item value to {$}", pInnerKey, szValue);
- if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
- {
- try {
- int pos = 0;
- ResDataObject* resTemp = &config;
- while ((pos = strTemp.find_first_of(',')) != string::npos)
- {
- string Key = strTemp.substr(0, pos);
- resTemp = &(*resTemp)[Key.c_str()];
- strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
- }
- if (strTemp != "")
- {
- (*resTemp)[strTemp.c_str()] = szValue;
- }
- else
- {
- *resTemp = szValue;
- }
- }
- catch (ResDataObjectExption& e)
- {
- //mLog::Error("SetDriverConfigvalue crashed: {$}", e.what());
- return false;
- }
- }
- return true;
- }
- //-----------------------------------------------------------------------------
- // GetIODriver & CreateIODriver
- //-----------------------------------------------------------------------------
- static nsGEN::PSGHRDriver gIODriver;
- extern "C" CCOS::Dev::IODriver * GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
- {
- return &gIODriver;
- }
- extern "C" CCOS::Dev::IODriver * CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
- {
- pIODriver = new nsGEN::PSGHRDriver();
- return pIODriver;
- }
|