123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430 |
- // CCOS.Dev.GEN.REMEDY.cpp : 定义 DLL 应用程序的导出函数。
- //
- #include "stdafx.h"
- #include <assert.h>
- #include <functional>
- #include "LogicDevice.h"
- #include "CCOS.Dev.Generator.REMEDY.h"
- #include "Helper.JSON.hpp"
- #include <unordered_map>
- #include <fstream>
- #include <set>
- using namespace std::placeholders;
- using namespace CCOS::Dev::Detail::Generator;
- namespace nsGEN = CCOS::Dev::Detail::Generator;
- #pragma warning (disable:4244)
- #pragma warning (disable:4305)
- #pragma warning (disable:4267)
- static const int msTimeOut_Lock = 500;
- #ifdef _WIN64
- #ifdef _DEBUG
- static const auto COM_SCFDllName = "Ccos.Dev.SerialSCFX64D.dll";
- #else
- static const auto COM_SCFDllName = "Ccos.Dev.SerialSCFX64.dll";
- #endif
- #endif
- #ifdef _WIN64
- #ifdef _DEBUG
- static const auto TCP_SCFDllName = "Ccos.Dev.TcpipSCFX64D.dll";
- #else
- static const auto TCP_SCFDllName = "Ccos.Dev.TcpipSCFX64.dll";
- #endif
- #endif
- //-----------------------------------------------------------------------------
- // REMEDYDevice
- //-----------------------------------------------------------------------------
- float g_MA_List[] = { 8, 10, 12.5, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640 };
- float g_MAS_List[] = { 1, 1.25, 1.6, 2, 2.5, 3.2, 4, 5, 6.4, 8, 10, 12.5, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640, 800, 1000 };
- float g_MS_List[] = { 1, 2, 3, 4, 5, 6, 8, 10, 12, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640, 800, 1000, 1250, 1600, 2000, 2500, 3200, 4000, 5000, 6400, 8000, 10000 };
- atomic<int> nsGEN::REMEDYDevice::m_iLoopTime = REMEDY_LoopDefTime;
- string GetProcessDirectory()
- {
- string ret = "";
- char szFilename[MAX_PATH] = { 0 };
- DWORD res = GetModuleFileNameA(0, szFilename, MAX_PATH);
- if (res == 0)
- {
- return ret;
- }
- string fullpath = szFilename;
- string::size_type firstHit = fullpath.find_last_of('\\');
- if (firstHit == string::npos || firstHit == 0)
- {
- return ret;
- }
- ret = fullpath.substr(0, firstHit);//kick last \
- return ret;
- }
- nsGEN::REMEDYDevice::REMEDYDevice(std::shared_ptr <IOEventCenter> center, nsSCF::SCF SCF, string configfile) : super(center, SCF)
- {
- assert(EventCenter);
- string version;
- if (GetVersion(version, hMyModule))
- FINFO("\n===============log begin : version:{$} ===================\n", version.c_str());
- else
- FINFO("\n===============log begin : version:0.0.0.0 ===================\n");
- m_DoseUnit.m_KV.reset(new KVMould(0.0, 40.0, 120.0, 1.0));
- m_DoseUnit.m_MA.reset(new MAMould(0.0, 0.1, 1000.0, 0.1));
- m_DoseUnit.m_MS.reset(new MSMould(0.0, 0.1, 10000.0, 0.01));
- m_DoseUnit.m_MAS.reset(new MASMould(0.0, 0.1, 1000.0, 0.01));
- m_DoseUnit.m_Techmode.reset(new TECHMODEMould(0, 0, 2, 1));
- m_DoseUnit.m_WS.reset(new WORKSTATIONMould(1, 0, 5, 1));
- m_DoseUnit.m_Focus.reset(new FOCUSMould(1, 0, 1, 1));
- m_DoseUnit.m_AECField.reset(new AECFIELDMould(0, 0, 111, 1));
- m_DoseUnit.m_AECFilm.reset(new AECFILMMould(0, 0, 2, 1));
- m_DoseUnit.m_AECDensity.reset(new AECDENSITYMould(0, -4, 4, 1));
- m_DoseUnit.m_HE.reset(new TUBEHEATMould(0, 0, 100, 1));
- m_DoseUnit.m_PostKV.reset(new POSTKVMould(0.0, 40.0, 120.0, 1.0));
- m_DoseUnit.m_PostMA.reset(new POSTMAMould(0.0, 10.0, 1000.0, 0.1));
- m_DoseUnit.m_PostMS.reset(new POSTMSMould(0.0, 1.0, 10000.0, 0.01));
- m_DoseUnit.m_PostMAS.reset(new POSTMASMould(0.0, 0.5, 1000.0, 0.01));
- m_DoseUnit.m_GenSynState.reset(new GENSYNSTATEMould(0, AttrKey::GENERATOR_SYNC_ERR, AttrKey::GENERATOR_SYNC_MAX, 1));
- m_DoseUnit.m_GenState.reset(new GENSTATEMould(0, AttrKey::GENERATOR_STATUS_SHUTDOWN, AttrKey::GENERATOR_STATUS_MAX, 1));
- m_DoseUnit.m_GenTotalExpNumber.reset(new TOTALEXPNUMMould(0, 0, 9999, 1));
- m_DoseUnit.m_GenTotalAcqTimes.reset(new TOTALACQTIMESMould(0, 0, 9999, 1));
- m_DoseUnit.m_GenTubeCoolWaitTimes.reset(new TUBECOOLTIMEMould(0, 0, 9999, 1));
- m_DoseUnit.m_GenTubeOverLoadNumber.reset(new TUBEOVERLOADNUMMould(0, 0, 9999, 1));
- m_DoseUnit.m_GenCurrentExpNumber.reset(new CUREXPNUMMould(0, 0, 9999, 1));
- m_DoseUnit.m_ExpMode.reset(new EXPMODEMould(AttrKey::EXPMODE_TYPE::Single));
- m_DoseUnit.m_FrameRate.reset(new FRAMERATEMould(0, 0, 16, 1));
- m_MSGUnit.reset(new nsDetail::MSGUnit(center, nsGEN::GeneratorUnitType));
- m_DAP.reset(new DevDAP::DOSEMould(0.0, 0.0, 1000.0, 0.01));
- m_DoseUnit.m_FLMode.reset(new FLUModeMould(AttrKey::GENERATOR_FLUMode::GENERATOR_FLMODE_NOTFLU));
- m_DoseUnit.m_FLIntTime.reset(new FLUIntTimeMould(0.0, 0.0, 100.0, 0.1));
- m_DoseUnit.m_FLAccTime.reset(new FLAccTimeMould(0.0, 0.0, 999.0, 0.1));
- m_DoseUnit.m_FLKV.reset(new FLUKVMould(0, 40, 125, 1));
- m_DoseUnit.m_FLMS.reset(new FLUMSMould(10.0, 10.0, 999999.0, 0.01));
- m_DoseUnit.m_FLMA.reset(new FLUMAMould(0.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_Curve.reset(new FLUCurveMould(0, 0, 3, 1));
- m_hGenPostEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
-
- string strErrConfig = GetProcessDirectory() + R"(\OEMDrivers\Generator\REMEDY\REMEDY_RF\ErrorWarnInfo.json)";
- m_DeviceErrorHandler.reset(new DeviceErrorHandler(center, nsGEN::GeneratorUnitType, strErrConfig));
- m_pHardwareStatusThread = NULL;
- m_pTrueParameterThread = NULL;
- m_strConfigPath = configfile;
- m_DoseUnit.m_FLAccTimeUnit = "m";
- m_bisNotDirectConnection = false;
- m_nReturnTime = 0;
- m_bMasR20 = 1;
- m_bUseEAcmd = 0;
- m_bResetActive = false;
- m_bIsConfigLoaded = false;
- OnCallBack();
- Register();
- HWSend("RE");
- Sleep(30);
- HWSend("WS1");
- Sleep(30);
- HWSend("FLA0");
- StartHardwareStatusThread();
- }
- nsGEN::REMEDYDevice::~REMEDYDevice()
- {
- CloseHandle(m_hGenPostEvent);
- }
- std::string nsGEN::REMEDYDevice::GetGUID() const
- {
- FINFO("\n===============GetGUID : {$} ===================\n", GeneratorUnitType);
- return GeneratorUnitType;
- }
- void nsGEN::REMEDYDevice::Register()
- {
- auto Disp = &Dispatch;
- superGen::Register(Disp);
- superGen::RegisterRAD(Disp);
- superGen::RegisterAEC(Disp);
- superGen::RegisterExpEnable(Disp);
- superGen::RegisterGeneratortoSyncStatus(Disp);
- superGen::RegisterFluoro(Disp);
- Disp->Get.Push(m_MSGUnit->GetKey().c_str(), [this](std::string& out) { out = m_MSGUnit->JSGet(); return RET_STATUS::RET_SUCCEED; });
- auto fun_Clear_DAP = [this](auto a, auto&)
- {
- return Clear_DAP();
- };
- Disp->Action.Push("Clear_DAP", fun_Clear_DAP);
- auto fun_GetValue_DAP = [this](auto a, auto& b)
- {
- float value = 0;
- RET_STATUS ret = GetValue_DAP(value);
- b = ToJSON(value);
- return ret;
- };
- Disp->Action.Push("GetValue_DAP", fun_GetValue_DAP);
- auto fun_StartMove = [this](auto a,auto& b)
- {
- return StartMove();
- };
- Disp->Action.Push("StartMove", fun_StartMove);
- auto fun_EndMove = [this](auto a, auto& b)
- {
- return EndMove();
- };
- Disp->Action.Push("EndMove", fun_EndMove);
- }
- RET_STATUS nsGEN::REMEDYDevice::IncKV()
- {
- FINFO("KV value before calling IncKV: {$}\n", m_DoseUnit.m_KV->JSGet().c_str());
- if (!m_DoseUnit.m_KV->CanInc()) return RET_STATUS::RET_SUCCEED;
- return HWSend("KV+");
- }
- RET_STATUS nsGEN::REMEDYDevice::DecKV()
- {
- FINFO("KV value before calling DecKV: {$}\n", m_DoseUnit.m_KV->JSGet().c_str());
- if (!m_DoseUnit.m_KV->CanDec()) return RET_STATUS::RET_SUCCEED;
- return HWSend("KV-");
- }
- RET_STATUS nsGEN::REMEDYDevice::SetKV(float value)
- {
- FINFO("KV value before calling SetKV: {$}\n", m_DoseUnit.m_KV->JSGet().c_str());
- if (!m_DoseUnit.m_KV->Verify(value)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- sprintf_s(temp, "KV%03d", (int)value);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::REMEDYDevice::IncMA()
- {
- FINFO("MA value before calling IncMA: {$}\n", m_DoseUnit.m_MA->JSGet().c_str());
- if (!m_DoseUnit.m_MA->CanInc()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- FINFO("\n Techmode is MAS, can't inc MA");
- return RET_STATUS::RET_FAILED;
- }
- return HWSend("MA+");
- }
- RET_STATUS nsGEN::REMEDYDevice::DecMA()
- {
- FINFO("MA value before calling DecMA: {$}\n", m_DoseUnit.m_MA->JSGet().c_str());
- if (!m_DoseUnit.m_MA->CanDec()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- FINFO("\n Techmode is MAS, can't dec MA");
- return RET_STATUS::RET_FAILED;
- }
- return HWSend("MA-");
-
- }
- RET_STATUS nsGEN::REMEDYDevice::SetMA(float value)
- {
- FINFO("MA value before calling SetMA: {$}\n", m_DoseUnit.m_MA->JSGet().c_str());
- if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- FINFO("\n Techmode is MAS, can't set MA");
- return RET_STATUS::RET_FAILED;
- }
- char temp[50] = { 0 };
- sprintf_s(temp, "MA%05d", (int)(value * 10));
- return HWSend(temp);
-
- }
- RET_STATUS nsGEN::REMEDYDevice::IncMS()
- {
- FINFO("MS value before calling IncMS: {$}\n", m_DoseUnit.m_MS->JSGet().c_str());
- if (!m_DoseUnit.m_MS->CanInc()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- FINFO("\n Techmode is MAS, can't inc MS");
- return RET_STATUS::RET_FAILED;
- }
- return HWSend("MS+");
- }
- RET_STATUS nsGEN::REMEDYDevice::DecMS()
- {
- FINFO("MS value before calling DecMS: {$}\n", m_DoseUnit.m_MS->JSGet().c_str());
- if (!m_DoseUnit.m_MS->CanDec()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- FINFO("\n Techmode is MAS, can't dec MS");
- return RET_STATUS::RET_FAILED;
- }
- return HWSend("MS-");
- }
- RET_STATUS nsGEN::REMEDYDevice::SetMS(float value)
- {
- FINFO("MS value before calling SetMS: {$}\n", m_DoseUnit.m_MS->JSGet().c_str());
- if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- FINFO("\n Techmode is MAS, can't set MS");
- return RET_STATUS::RET_FAILED;
- }
- char temp[50] { 0 };
- sprintf_s(temp, "MS%05d", (int)(value * 10));
- return HWSend(temp);
- }
- RET_STATUS nsGEN::REMEDYDevice::IncMAS()
- {
- FINFO("MAS value before calling IncMAS: {$}\n", m_DoseUnit.m_MAS->JSGet().c_str());
- if (!m_DoseUnit.m_MAS->CanInc()) return RET_STATUS::RET_SUCCEED;
-
- if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- FINFO("\n Techmode is not MAS, can't inc MAS");
- return RET_STATUS::RET_FAILED;
- }
- return HWSend("MX+");
- }
- RET_STATUS nsGEN::REMEDYDevice::DecMAS()
- {
- FINFO("MAS value before calling DecMAS: {$}\n", m_DoseUnit.m_MAS->JSGet().c_str());
- if (!m_DoseUnit.m_MAS->CanDec()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- FINFO("\n Techmode is not MAS, can't dec MAS");
- return RET_STATUS::RET_FAILED;
- }
- return HWSend("MX-");
- }
- RET_STATUS nsGEN::REMEDYDevice::SetMAS(float value)
- {
- FINFO("MAS value before calling SetMAS: {$}\n", m_DoseUnit.m_MAS->JSGet().c_str());
- if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- FINFO("\n Techmode is not MAS, can't set MAS");
- return RET_STATUS::RET_FAILED;
- }
- char temp[50] = { 0 };
- if (m_bMasR20)
- {
- sprintf_s(temp, "MX%06d", (int)(value * 100));
- }
- else
- {
- sprintf_s(temp, "MX%05d", (int)(value * 10));
- }
-
- return HWSend(temp);
- }
- RET_STATUS nsGEN::REMEDYDevice::SetTechmode(int value)
- {
- FINFO("Techmode value before calling SetTechmode: {$}\n", m_DoseUnit.m_Techmode->JSGet().c_str());
- if (!m_DoseUnit.m_Techmode->Verify(value)) return RET_STATUS::RET_SUCCEED;
- //if (value == AttrKey::TECHMODE_V2TYPE::ET_AEC)//if AEC, translate to time. why? i need reason.
- // value = AttrKey::TECHMODE_V2TYPE::ET_TIME;
- char temp[50] = { 0 };
- sprintf_s(temp, "ET%01d", (int)value);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::REMEDYDevice::SetFocus(int value)
- {
- FINFO("Focus value before calling SetFocus: {$}\n", m_DoseUnit.m_Focus->JSGet().c_str());
- if (!m_DoseUnit.m_Focus->Verify(value)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- sprintf_s(temp, "FO%01d", (int)value);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::REMEDYDevice::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;
- char temp[50] = { 0 };
- if (value >= 0)
- {
- sprintf_s(temp, "FN+%01d", (int)value);
- }
- else
- {
- sprintf_s(temp, "FN-%01d", (int)value);
- }
- return HWSend(temp);
- }
- RET_STATUS nsGEN::REMEDYDevice::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_AEC)
- return RET_STATUS::RET_FAILED;
- char temp[50] = { 0 };
- sprintf_s(temp, "FI%03d", (int)value);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::REMEDYDevice::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_AEC)
- return RET_STATUS::RET_FAILED;
- char temp[50] = { 0 };
- sprintf_s(temp, "FS%03d", (int)value);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::REMEDYDevice::SetWS(const string value)
- {
- int tempws = 0;
- if (value == "Table") tempws = (int)m_GenConfig["WSTable"];
- else if (value == "Wall") tempws = (int)m_GenConfig["WSWall"];
- else if (value == "Direct") tempws = (int)m_GenConfig["WSConventional"];
- else if (value == "Free") tempws = (int)m_GenConfig["WSFree"];
- else if (value == "Tomo") tempws = (int)m_GenConfig["WSTomo"];
- char temp[50] = { 0 };
- sprintf_s(temp, "WS%01d", tempws);
- return HWSend(temp);
- }
- string nsGEN::REMEDYDevice::WSUI2Gen(int nUIWS)
- {
- string strWS = "";
- try
- {
- if (nUIWS == AttrKey::GENWS_TYPE::TABLE) //lying: cross mode
- {
- strWS = m_GenConfig["WSTable"].encode();
- }
- else if (nUIWS == AttrKey::GENWS_TYPE::WALL) //standing mode
- {
- strWS = m_GenConfig["WSWall"].encode();
- }
- else if (nUIWS == AttrKey::GENWS_TYPE::FREE_TABLE) //standing mode
- {
- strWS = m_GenConfig["WSFree"].encode();
- }
- else if (nUIWS == AttrKey::GENWS_TYPE::TOMO) //standing mode
- {
- strWS = m_GenConfig["WSTOMO"].encode();
- }
- else if (nUIWS == AttrKey::GENWS_TYPE::CONVENTIONAL) //standing mode
- {
- strWS = m_GenConfig["WSConventional"].encode();
- }
- }
- catch (ResDataObjectExption& exp)
- {
- FERROR("Get configuration failed, {$}\n", exp.what());
- }
- FINFO("Set WS: {$},Generator workstaion: {$}\n", nUIWS, strWS);
- if (strWS == "")
- {
- strWS = "Table";
- }
- return strWS;
- }
- RET_STATUS nsGEN::REMEDYDevice::SetAPR(const _tAPRArgs& t)
- {
- m_t = t;
- FINFO("*********************Enter SetAPR*********************");
- FINFO("t.ws={$},t.fKV={$},t.fMA={$},t.fMAS={$},t.nAECDensity={$},t.nAECField={$},t.nAECFilm={$},t.nFocus={$},t.nTechmode={$}", t.nWS,t.fKV, t.fMA, t.fMAS, t.nAECDensity, t.nAECField, t.nAECFilm, t.nFocus, t.nTechmode);
- //2
- SetKV(t.fKV);
- //3
- SetFocus(t.nFocus);
- //4
- if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_AEC)//aec
- {
- SetTechmode(t.nTechmode);
- SetAECField(t.nAECField);
- SetAECDensity(t.nAECDensity);
- SetMA(t.fMA);
- SetMS(t.fMS);
- }
- else if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_MAS)//2p
- {
- SetTechmode(t.nTechmode);
- const float EPSINON = 0.000001;
- SetMAS(t.fMAS);
- }
- else if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_TIME)//3p
- {
- SetTechmode(t.nTechmode);
- SetMA(t.fMA);
- SetMS(t.fMS);
- }
- HWSend("RR");
- FINFO("*********************Leave SetAPR*********************");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYDevice::QueryHE(int& value)
- {
- return HWSend("HE?");
- }
- RET_STATUS nsGEN::REMEDYDevice::QueryPostKV(float& value)
- {
- m_DoseUnit.m_PostKV->Update(m_DoseUnit.m_KV->Get());
- value = m_DoseUnit.m_PostKV->Get();
- return HWSend("AP?");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYDevice::QueryPostMA(float& value)
- {
- return HWSend("AP?");
- }
- RET_STATUS nsGEN::REMEDYDevice::QueryPostMS(float& value)
- {
- return HWSend("AT?");
- }
- RET_STATUS nsGEN::REMEDYDevice::QueryPostMAS(float& value)
- {
- value = m_DoseUnit.m_PostMAS->Get();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYDevice::Clear_DAP()
- {
- if (m_bDAPEnable)
- {
- return HWSend("DZ");
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYDevice::GetValue_DAP(float& value)
- {
- if (m_bDAPEnable)
- {
- HWSend("DA");
- Sleep(300); //wait 300ms to get real dap value.
- value = m_DAP->Get();
- }
-
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYDevice::StartMove()
- {
- FINFO("Enter startMove");
- FINFO("end startmove");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYDevice::EndMove()
- {
- FINFO("Enter endmove");
- FINFO("end EndMove");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYDevice::SetGenSynState(int value)
- {
- FINFO("Enter SetGenSynState...{$} \n", value);
- //if (AttrKey::GENERATOR_RAD_XRAYON == value) //软同步,收到XR1时,子系统会变为XRAYON状态,并调用此处,然后我立刻回复XR1至发生器,然后才真正出线。
- //{
- // FINFO("SetGenSynState be call.this is soft syn mode.");
- // HWSend("XR1");
- // m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON);
- // FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- //}
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYDevice::SetGenState(int value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYDevice::SetExpMode(std::string value)
- {
- //note: when time the func be called?
- FINFO("Enter SetExpMode...{$}",value);
- m_DoseUnit.m_ExpMode->Update(value);
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYDevice::SetFLFMode(std::string value)
- {
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- FINFO("Enter SetFLFMode...,FLFMode:{$} \n", value.c_str());
- if (value == "CF")
- {
- m_DoseUnit.m_FLMode->Update(1);
- HWSend("FLF1");
- }
- else if (value == "PF")
- {
- m_DoseUnit.m_FLMode->Update(2);
- HWSend("FLF2");
- }
- else if (value == "HLF")
- {
- m_DoseUnit.m_FLMode->Update(2);
- HWSend("FLF2");
- }
- else
- {
- FINFO("other FluMode : {$}", value.c_str());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYDevice::SetAPF(const _tAPFArgs& t)
- {
- FINFO("APF:FLKV={$},FLMA={$},PPS={$},WS={$},FLuType={$},ABSMode={$},DoseLever={$}", t.nFLKV, t.fFLMA, t.nPPS, t.nWS, t.nFluMode, t.nABSMode, t.nDoseLever);
- //SetABSMode(t.nABSMode);
- //SetFLFMode(to_string(t.nFluMode));
- //SetFluDoseLever(t.nDoseLever);
- SetFluKV(t.nFLKV);
- SetFluMA(t.fFLMA);
- HWSend("RF");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYDevice::IncFluKV()
- {
- FINFO("FluKV value before calling IncFluKV: {$}\n", m_DoseUnit.m_FLKV->JSGet().c_str());
- if (!m_DoseUnit.m_FLKV->CanInc()) return RET_STATUS::RET_SUCCEED;
- return HWSend("FLK+");
- }
- RET_STATUS nsGEN::REMEDYDevice::DecFluKV()
- {
- FINFO("FluKV value before calling DecFluKV: {$}\n", m_DoseUnit.m_FLKV->JSGet().c_str());
- if (!m_DoseUnit.m_FLKV->CanDec()) return RET_STATUS::RET_SUCCEED;
- return HWSend("FLK-");
- }
- RET_STATUS nsGEN::REMEDYDevice::SetFluKV(float value)
- {
- FINFO("FluKV value before calling SetFluKV: {$}\n", m_DoseUnit.m_FLKV->JSGet().c_str());
- if (!m_DoseUnit.m_FLKV->Verify(value)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- sprintf_s(temp, "FLK%03d", (int)value);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::REMEDYDevice::IncFluMA()
- {
- FINFO("FluMA value before calling IncFluMA: {$}\n", m_DoseUnit.m_FLMA->JSGet().c_str());
- if (!m_DoseUnit.m_FLMA->CanInc()) return RET_STATUS::RET_SUCCEED;
- return HWSend("FLM+");
- }
- RET_STATUS nsGEN::REMEDYDevice::DecFluMA()
- {
- FINFO("FluMA value before calling DecFluMA: {$}\n", m_DoseUnit.m_FLMA->JSGet().c_str());
- if (!m_DoseUnit.m_FLMA->CanDec()) return RET_STATUS::RET_SUCCEED;
- return HWSend("FLM-");
- }
- RET_STATUS nsGEN::REMEDYDevice::SetFluMA(float value)
- {
- FINFO("FluMA value before calling SetFluMA: {$}\n", m_DoseUnit.m_FLMA->JSGet().c_str());
- if (!m_DoseUnit.m_FLMA->Verify(value)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- sprintf_s(temp, "FLM%03d", (int)(value * 10));
- return HWSend(temp);
- }
- RET_STATUS nsGEN::REMEDYDevice::INCPPS()
- {
- if (!m_DoseUnit.m_PPS->CanInc()) return RET_STATUS::RET_SUCCEED;
- return HWSend("FLS+");
- }
- RET_STATUS nsGEN::REMEDYDevice::DECPPS()
- {
- if (!m_DoseUnit.m_PPS->CanDec()) return RET_STATUS::RET_SUCCEED;
- return HWSend("FLS-");
- }
- RET_STATUS nsGEN::REMEDYDevice::SetPPS(float value)
- {
- if (!m_DoseUnit.m_PPS->Verify(value)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- sprintf_s(temp, "FLS%03d", (int)(value * 10));
- return HWSend(temp);
- }
- RET_STATUS nsGEN::REMEDYDevice::SetABSMode(int nMode)
- {
- if (!m_DoseUnit.m_ABSStatus->Verify(nMode)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- FINFO("SetABSMode[{$}] \n", nMode);
- sprintf_s(temp, "FLA%1d", (int)nMode);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::REMEDYDevice::SetABSCurve(int curveNum)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYDevice::IncABSCurve()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYDevice::DecABSCurve()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYDevice::GetABSCurve()
- {
- return HWSend("FLA?");
- }
- float nsGEN::REMEDYDevice::GetFluIntTimer()
- {
- return HWSend("FLI?");
- }
- float nsGEN::REMEDYDevice::GetFluAccTimer()
- {
- return HWSend("FLT?");
- }
- RET_STATUS nsGEN::REMEDYDevice::ResetFluTimer(int ntype)
- {
- char temp[50] = { 0 };
- sprintf_s(temp, "FLR%1d", (int)ntype);
- FINFO("ReSetFluAccTimer:[{$}] \n", ntype);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::REMEDYDevice::SetFluPre(int value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYDevice::SetFluEXP(int value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYDevice::SetFluMode(std::string value)
- {
- FINFO("Enter SetFLFMode...{$} \n", value.c_str());
- if (value == "CF")
- {
- m_DoseUnit.m_FLMode->Update(1);
- return HWSend("FLF1");
- }
- else if (value == "PF")
- {
- m_DoseUnit.m_FLMode->Update(2);
- return HWSend("FLF2");
- }
- else
- {
- FINFO("other FluMode : {$}", value.c_str());
- return RET_STATUS::RET_SUCCEED;
- }
- }
- RET_STATUS nsGEN::REMEDYDevice::SetFluDoseLever(int value)
- {
- FINFO("Enter SetFluDoseLever...{$} \n", value);
- // 提取当前剂量级别
- int currentDoseLevel = m_DoseUnit.m_DoseLevel->Get();
- // 只有在剂量级别发生变化时才继续处理
- if (currentDoseLevel == value) {
- return RET_STATUS::RET_SUCCEED;
- }
- float fma;
- // 计算新的FLMA值
- if (value == 1) {
- fma = 2 * m_DoseUnit.m_FLMA->Get();
- }
- else if (value == 0) {
- fma = 0.5 * m_DoseUnit.m_FLMA->Get();
- }
- else {
- FINFO("Invalid value:{$} \n", value);
- return RET_STATUS::RET_FAILED; // 非法值处理
- }
- // 更新剂量级别
- m_DoseUnit.m_DoseLevel->Update(value);
- // 验证FLMA值
- if (!m_DoseUnit.m_FLMA->Verify(fma)) {
- return RET_STATUS::RET_SUCCEED;
- }
- // 发送命令到硬件
- char temp[50] = { 0 };
- sprintf_s(temp, "FLM%03d", (int)(fma * 10));
- return HWSend(temp, strlen(temp));
- }
- void CCOS::Dev::Detail::Generator::REMEDYDevice::UpdateLimits(const std::string& key, float& currentValue, float defaultValue)
- {
- if (m_GenConfig.GetKeyCount(key.c_str()) > 0)
- {
- currentValue = static_cast<float>(m_GenConfig[key.c_str()]);
- }
- else
- {
- currentValue = defaultValue;
- }
- }
- void nsGEN::REMEDYDevice::UpdateLimitsInt(const std::string& key, int& currentValue, int defaultValue)
- {
- if (m_GenConfig.GetKeyCount(key.c_str()) > 0)
- {
- currentValue = static_cast<int>(m_GenConfig[key.c_str()]);
- }
- else
- {
- currentValue = defaultValue;
- }
- }
- int nsGEN::REMEDYDevice::GetGenState()
- {
- if (m_DoseUnit.m_GenState != NULL)
- {
- return m_DoseUnit.m_GenState->Get();
- }
- else
- {
- return 0;
- }
- }
- int nsGEN::REMEDYDevice::LoadConfig(string configfile)
- {
- FINFO("=====================LoadConfig=========================");
- // 检查文件是否存在
- std::ifstream file(configfile);
- if (!file) {
- // 文件不存在,直接返回空的Connection对象
- FINFO("Config file does not exist: {$}", configfile.c_str());
- return -1;
- }
- if (m_bIsConfigLoaded)
- {
- FINFO("Configuration already loaded.");
- return 0;
- }
- ResDataObject temp;
- temp.loadFile(m_strConfigPath.c_str());
- m_GenConfig = temp["CONFIGURATION"];
- TransJsonText(m_GenConfig);
- if (m_GenConfig.GetKeyCount("ReturnTime") > 0)
- {
- m_nReturnTime = (int)m_GenConfig["ReturnTime"];
- }
- if (m_GenConfig.GetKeyCount("R20Enable") > 0)
- {
- m_bMasR20 = (bool)m_GenConfig["R20Enable"];
- }
- if (m_GenConfig.GetKeyCount("USEEACMD") > 0)
- {
- m_bUseEAcmd = (bool)m_GenConfig["USEEACMD"];
- }
- UpdateLimits("PFMALimitMax", m_fPFLimitMaxMA, 40.0f);
- UpdateLimits("PFKVLimitMax", m_fPFLimitMaxKV, 80.0f);
- UpdateLimits("PFMALimitMin", m_fPFLimitMinMA, 1.0f);
- UpdateLimits("PFKVLimitMin", m_fPFLimitMinKV, 39.0f);
- // Update HLF limits
- UpdateLimits("HLFMALimitMax", m_fHLFLimitMaxMA, 99.0f);
- UpdateLimits("HLFKVLimitMax", m_fHLFLimitMaxKV, 151.0f);
- UpdateLimits("HLFMALimitMin", m_fHLFLimitMinMA, 40.0f);
- UpdateLimits("HLFKVLimitMin", m_fHLFLimitMinKV, 80.0f);
- if (!InitDevice())
- {
- FINFO("InitDevice succeed\n");
- }
- m_bIsConfigLoaded = true;
- return 0;
- }
- int nsGEN::REMEDYDevice::InitDevice()
- {
- HWSend("RE");
- Sleep(30);
- HWSend("WS1");
- Sleep(30);
- HWSend("FLA0");
- return 0;
- }
- RET_STATUS nsGEN::REMEDYDevice::SetEXAMMode(std::string value)
- {
- //EXAMMODE_TYPE::MANUAL
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS REMEDYDevice::REMEDYDevice::ActiveSyncMode(_tSyncModeArgs value)
- {
- 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 };
- sprintf_s(temp, "WS%01d", nSyncModeValue);
- return HWSend(temp);
- }
- void nsGEN::REMEDYDevice::HandleError(const char* value, const char* prefix, const std::string& type)
- {
- assert(value);
- int nValue = atoi(value);
- char temp[50] = { 0 };
- sprintf_s(temp, "%s%03d", type.c_str(), nValue);
- HWSend(temp);
- std::string errorCode = "Remedy_ER" + std::string(value);
- if (m_DeviceErrorHandler->ParseAndReport(errorCode) == "error")
- {
- if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR))
- {
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- }
- }
- }
- RET_STATUS nsGEN::REMEDYDevice::SetFrameRate(FLOAT frameRate)
- {
- m_DoseUnit.m_FrameRate->Update(frameRate); //this variable should be set when in oncallback.
-
- char temp[50]{ 0 };
- sprintf_s(temp, "FLS%03d", int(frameRate*10));
- return HWSend(temp);
- }
- RET_STATUS nsGEN::REMEDYDevice::SetRPS(int rps)
- {
- return RET_STATUS::RET_SUCCEED;
- //char temp[50]{ 0 };
- //sprintf_s(temp, "RPS%03d", rps * 10);
- //return HWSend(temp);
- }
- RET_STATUS nsGEN::REMEDYDevice::RefreshData()
- {
- HWSend("RR");
- HWSend("RS");
- HWSend("RF");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYDevice::SetExpEnable()
- {
- FINFO("SetExpEnable in ...\n");
-
- if (m_bUseEAcmd)
- {
- HWSend("EA111");
- }
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
-
- return RET_STATUS::RET_SUCCEED;
- //return HWSend("EXB1");
- }
- RET_STATUS nsGEN::REMEDYDevice::SetExpDisable()
- {
- FINFO("SetExpDisable in...\n");
- if (m_bUseEAcmd)
- {
- HWSend("EA000");
- }
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- FINFO("SetExpDisable... {$}\n", m_DoseUnit.m_GenState->JSGet().c_str());
- return RET_STATUS::RET_SUCCEED;
- //return HWSend("EXB0");
- }
- RET_STATUS nsGEN::REMEDYDevice::Reset()
- {
- m_bResetActive = true;
- FINFO("RESET in...\n");
- int level = 0;
- if (!m_localWarnlist.empty())
- {
- m_localWarnlist.clear();
- FINFO("Local warning list has been cleared.\n");
- m_MSGUnit->DelErrorMessage("0", level, "clear all errors");
- m_MSGUnit->DelWarnMessage("0", level, "clear all Warning");
- }
- return HWSend("RE");
- }
- RET_STATUS nsGEN::REMEDYDevice::HWSend(char* strCommand, int nTimeOut)
- {
- 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); //3 is ETX
- memcpy(strSendCommand, strCommand, len);
- strSendCommand[len + 0] = 0x03;
- strSendCommand[len + 1] = checkSum;
- FINFO("==OUT==: {$} \n", strSendCommand);
- int retLength;
- m_SCF.Lock(msTimeOut_Lock)
- .SendPacket(strSendCommand, strlen(strSendCommand), nTimeOut, retLength);
- //Sleep(nTimeOut);
-
- return RET_STATUS::RET_SUCCEED;
- }
- //-----------------------------------------------------------------------------
- // ProcessCmd
- //-----------------------------------------------------------------------------
- void nsGEN::REMEDYDevice::FireNotify(std::string key, std::string content)
- {
- EventCenter->OnNotify(1, key, content);
- }
- struct tFrameMapping
- {
- static const int MaxLen = 5; // 前缀不能超超过 5 个字符 !
- using cbFun = std::function <void(const char*, int)>;
- char strHead[MaxLen];
- int NbOfCharOfHead;
- cbFun fun;
- tFrameMapping(char* str, int len, cbFun f)
- {
- assert(len < MaxLen); //len最大只能是4
- //strHead[0] = 0x02; //STX ----------->note : no package header
- for (int i = 0; i < len; i++) //给strHead赋值
- strHead[i] = str[i];
- NbOfCharOfHead = len;
- fun = f;
- }
- };
- static std::list <tFrameMapping> arFrame;
- static bool DecodeFrame(const char* strFrame, int length);
- void nsGEN::REMEDYDevice::OnCallBack()
- {
- auto HWNotProcess = [](const char* value, int length) -> void
- {
- printf("\n This commands didn't need to process!\n");
- FINFO("\n This commands didn't need to process!\n");
- };
- //==IN==:KV070 MA00320 MS00063 MX00036 sometimes : this long str appear. so must deal with it
- auto HWKV = [this](const char* value, int length) -> void
- {
- assert(value);
- FINFO("hwkv={$},len={$}",value, length);
- if (length > 20) //if length more than 20, it must be a long string like :070 MA00320 MS00063 MX00036
- {
- //loop the long string to find kv ma ms mas
- int tmpkv;
- float tmpma, tmpms, tmpmx;
- char tmpbuf[5]{ 0,0,0,0,0 };
- //kv
- tmpbuf[0] = value[0];
- tmpbuf[1] = value[1];
- tmpbuf[2] = value[2];
- tmpkv = atoi(tmpbuf);
- m_DoseUnit.m_KV->Update(tmpkv);
- FireNotify(AttrKey::KV, m_DoseUnit.m_KV->JSGet());
- //ma
- tmpbuf[0] = value[6];
- tmpbuf[1] = value[7];
- tmpbuf[2] = value[8];
- tmpbuf[3] = value[9];
- tmpbuf[4] = value[10];
- tmpma = atof(tmpbuf)/10;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- m_DoseUnit.m_MA->Update(0);
- FireNotify(AttrKey::MA, m_DoseUnit.m_MA->JSGet());
- }
- else
- {
- 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];
- tmpms = atof(tmpbuf) / 10;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- m_DoseUnit.m_MS->Update(0);
- FireNotify(AttrKey::MS, m_DoseUnit.m_MS->JSGet());
- }
- else
- {
- m_DoseUnit.m_MS->Update(tmpms);
- FireNotify(AttrKey::MS, m_DoseUnit.m_MS->JSGet());
- }
- //mx
- tmpbuf[0] = value[22];
- tmpbuf[1] = value[23];
- tmpbuf[2] = value[24];
- tmpbuf[3] = value[25];
- tmpbuf[4] = value[26];
- tmpmx = atof(tmpbuf) / 10;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_TIME)
- {
- m_DoseUnit.m_MAS->Update(0);
- FireNotify(AttrKey::MAS, m_DoseUnit.m_MAS->JSGet());
- }
- else
- {
- m_DoseUnit.m_MAS->Update(tmpmx);
- FireNotify(AttrKey::MAS, m_DoseUnit.m_MAS->JSGet());
- }
- FINFO("tmpkv={$} tmpma={$}, tmpms={$}, tmpmx={$};", tmpkv, tmpma, tmpms, tmpmx);
- }
- else
- {
- int tmpkv = atoi(value);
- if (m_DoseUnit.m_KV->Get() != tmpkv && m_DoseUnit.m_KV->Update(tmpkv))
- FireNotify(AttrKey::KV, m_DoseUnit.m_KV->JSGet());
- }
- };
- //==IN==:TU0 WS1 FO0 ET0 FI010 FS001 FN 0 HE000
- auto HWTU = [this](const char* value, int length) -> void
- {
- assert(value);
- 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());
- 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());
- switch (tmpET)
- {
- case 0:
- FINFO("ET={$}", "mA/ms", m_DoseUnit.m_Techmode->JSGet().c_str());
- break;
- case 1:
- FINFO("ET={$}", "mAs", m_DoseUnit.m_Techmode->JSGet().c_str());
- break;
- case 2:
- FINFO("ET={$}", "AEC / mA", m_DoseUnit.m_Techmode->JSGet().c_str());
- break;
- case 3:
- FINFO("ET={$}", "mAs / ms", m_DoseUnit.m_Techmode->JSGet().c_str());
- break;
- case 4:
- FINFO("ET={$}", "AEC", m_DoseUnit.m_Techmode->JSGet().c_str());
- break;
- }
- //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);
- if (m_DoseUnit.m_HE->Update(tmpHE))
- FireNotify(m_DoseUnit.m_HE->GetKey(), m_DoseUnit.m_HE->JSGet());
- FINFO("parse tmpWS={$}, tmpFO={$}, tmpET={$}, tmpField={$}, tmpFilm={$}, tmpDensity={$}, tmpHE={$}", tmpWS, tmpFO, tmpET, tmpField, tmpFilm, tmpDensity, tmpHE);
- };
- auto HWEC = [this](const char* value, int length) -> void
- {
- assert(value);
- FINFO("recv EC{$}",value);
- };
- auto HWST = [this](const char* value, int length) -> void
- {
- assert(value);
- int genStatus = atoi(value);
- if (m_bResetActive)
- {
- m_bResetActive = false;
- //clear all error list
- int level = 1;
- for (auto errorStr : m_localErrorlist)
- {
- m_MSGUnit->DelErrorMessage(errorStr.c_str(), level, "");
- FINFO("clear error = {$}\n", errorStr);
- }
- m_localErrorlist.clear();
- }
- switch (genStatus)
- {
- case 1:
- FDEBUG("Get Gen Status_1:GENSTATE {$}", m_DoseUnit.m_GenState->JSGet());
- if (1 == m_bUseEAcmd)
- {
- static int nST001Count = 0;
- if (0 == nST001Count)//只执行一次。
- {
- FINFO("recv st001,and feedback EA000,just once");
- HWSend("EA000");
- nST001Count = 1;
- }
- }
- break;
- case 2:
- FDEBUG("Get Gen Status_2:GENSTATE {$} -> (Standby Phase)", 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 10:
- FDEBUG("Get Gen Status_10:GENSTATE {$} -> (GENERATOR_STATUS_EXP)", m_DoseUnit.m_GenSynState->JSGet());
- if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_EXP))
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- break;
- default:
- FDEBUG("Get Gen Status:[{$}] unknown", genStatus);
- break;
- }
- };
- auto HWMAS = [this](const char* value, int length)
- {
- assert(value);
- float fmas = 0.0f;
- if (m_bMasR20)
- {
- fmas = atof(value) / 100.0;
- }
- else
- {
- fmas = atof(value) / 10.0;
- }
-
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_TIME)
- {
- if (m_DoseUnit.m_MAS->Update(0))
- FireNotify(AttrKey::MAS, m_DoseUnit.m_MAS->JSGet());
- }
- else
- {
- 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_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- m_DoseUnit.m_MA->Update(0);
- FireNotify(AttrKey::MA, m_DoseUnit.m_MA->JSGet());
- }
- else
- {
- 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) / 10.0;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- m_DoseUnit.m_MS->Update(0);
- FireNotify(AttrKey::MS, m_DoseUnit.m_MS->JSGet());
- }
- else
- {
- m_DoseUnit.m_MS->Update(fms);
- FireNotify(AttrKey::MS, m_DoseUnit.m_MS->JSGet());
- }
- };
- 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());
- 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:
- {
- FINFO(" ET={$}", "mA/ms", m_DoseUnit.m_Techmode->JSGet().c_str());
- m_DoseUnit.m_MA->Update(0);
- FireNotify(AttrKey::MA, m_DoseUnit.m_MA->JSGet());
- }
- break;
- case 1:
- {
- FINFO(" ET={$}", "mAs", m_DoseUnit.m_Techmode->JSGet().c_str());
- m_DoseUnit.m_MS->Update(0);
- FireNotify(AttrKey::MS, m_DoseUnit.m_MS->JSGet());
- m_DoseUnit.m_MA->Update(0);
- FireNotify(AttrKey::MA, m_DoseUnit.m_MA->JSGet());
- }
- break;
- case 2:
- FINFO(" ET={$}", "AEC / mA", m_DoseUnit.m_Techmode->JSGet().c_str());
- break;
- case 3:
- FINFO(" ET={$}", "mAs / ms", m_DoseUnit.m_Techmode->JSGet().c_str());
- break;
- case 4:
- 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);
- int nvalue = atoi(value);
- if (m_DoseUnit.m_AECFilm->Update(nvalue))
- FireNotify(AttrKey::AECFILM, m_DoseUnit.m_AECFilm->JSGet());
- };
- auto HWAECDensity = [this](const char* value, int length)
- {
- assert(value);
- int nvalue = atoi(value);
- if (m_DoseUnit.m_AECDensity->Update(nvalue))
- 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)
- {
- FINFO("The high voltage generator enters the exposure preparation stage。");
- HWSend("PR2");
- }
- else if (nValue == 1)
- {
- HWSend("PR1");
- m_iLoopTime = REMEDY_LoopExpTime;
- if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_PREPARE))
- {
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- FINFO("Generator exposure process status:{$};", "GENERATOR_RAD_PREPARE");
- }
- }
- else if (nValue == 0)
- {
- HWSend("PR0");
- if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF));
- {
- Sleep(m_nReturnTime);
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- FINFO("Generator exposure process status:{$};", "GENERATOR_RAD_OFF");
- FINFO("HWPR m_DoseUnit.m_GenSynState->JSGet()={$}", m_DoseUnit.m_GenSynState->JSGet().c_str());
- FINFO("m_nReturnTimee={$};", m_nReturnTime);
- //RefreshData();
- }
- if (m_iLoopTime == REMEDY_LoopExpTime)
- {
- if ((int)m_GenConfig["loopTime"] >= 100)
- {
- m_iLoopTime = (int)m_GenConfig["loopTime"];
- }
- else
- m_iLoopTime = REMEDY_LoopDefTime;
- FDEBUG("reduction loopTime[{$}]->[{$}]", REMEDY_LoopExpTime, m_iLoopTime.load());
- }
-
- }
- };
- auto HWXR = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- if (nValue == 1)
- {
- HWSend("XR1");
- if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_READY))
- {
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- FINFO("Generator exposure process status:{$};", "GENERATOR_RAD_READY");
- ResetEvent(m_hGenPostEvent);
- }
- }
- else if (nValue == 2)
- {
- HWSend("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(AttrKey::GENERATOR_RAD_XRAYON))
- {
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- FINFO("Generator exposure process status:{$};", "GENERATOR_RAD_XRAYON");
- }
- }
- else if (nValue == 0)
- {
- HWSend("XR0");
- if(m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYOFF));
- {
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- FINFO("Generator exposure process status:{$};", "GENERATOR_RAD_XRAYOFF");
- FINFO("HWXR m_DoseUnit.m_GenSynState->JSGet()={$}", m_DoseUnit.m_GenSynState->JSGet().c_str());
- HWSend("AP?");
- Sleep(30);
- HWSend("AT?");
- Sleep(30);
- }
- }
- };
- auto HWVPDOSE = [this](const char* value, int length)//mas
- {
- assert(value);
- m_DoseUnit.m_PostKV->Update(atof(value));
- FireNotify(AttrKey::POSTKV, m_DoseUnit.m_PostKV->JSGet());
- FINFO("Actual exposure parametersKV:{$}", m_DoseUnit.m_PostKV->JSGet().c_str());
- };
- auto HWAPDOSE = [this](const char* value, int length)//mas
- {
- assert(value);
- m_DoseUnit.m_PostMAS->Update(atof(value) / 10.0);
- FireNotify(m_DoseUnit.m_PostMAS->GetKey(), m_DoseUnit.m_PostMAS->JSGet());
- m_DoseUnit.m_PostKV->Update(m_DoseUnit.m_KV->Get());
- FireNotify(AttrKey::POSTKV, m_DoseUnit.m_PostKV->JSGet());
- FINFO("Actual exposure parametersMAS:{$}", m_DoseUnit.m_PostMAS->JSGet().c_str());
- };
- auto HWATDOSE = [this](const char* value, int length)
- {
- assert(value);
- m_DoseUnit.m_PostMS->Update(atof(value) / 10.0);
- FireNotify(m_DoseUnit.m_PostMS->GetKey(), m_DoseUnit.m_PostMS->JSGet());
- m_DoseUnit.m_PostMA->Update(m_DoseUnit.m_PostMAS->Get() * 1000.0 / m_DoseUnit.m_PostMS->Get());
- FireNotify(m_DoseUnit.m_PostMA->GetKey(), m_DoseUnit.m_PostMA->JSGet());
- FINFO("Actual exposure parametersMS:{$}", m_DoseUnit.m_PostMS->JSGet().c_str());
- };
- auto HWDAPST = [this](const char* value, int length)
- {
- assert(value);
- int dapStatus = atoi(value);
- if (dapStatus == 1)
- {
- m_bDAPEnable = true;
- m_bAKEnable = false;
- }
- else if (dapStatus == 2)
- {
- m_bDAPEnable = false;
- m_bAKEnable = true;
- }
- else if (dapStatus == 3)
- {
- m_bDAPEnable = true;
- m_bAKEnable = true;
- }
- else
- {
- m_bDAPEnable = false;
- m_bAKEnable = false;
- }
- };
- auto HWDT = [this](const char* value, int length)
- {
- assert(value);
- int dapStatus = atoi(value);
- if (dapStatus == 0)
- {
- m_bDAPEnable = false;
- FINFO("DAP test failed");
- }
- else if (dapStatus == 1)
- {
- m_bDAPEnable = true;
- FINFO("DAP test passed");
- }
- else if (dapStatus == 2)
- {
- m_bDAPEnable = true;
- FINFO("DAP test in progress.");
- }
- };
- auto HWDAP = [this](const char* value, int length)
- {
- assert(value);
- //m_DoseUnit.->Update(atof(value));
- //FireNotify(m_DoseUnit.m_PostMS->GetKey(), m_DoseUnit.m_PostMS->JSGet());
- //SetEvent(m_hGenPostEvent);
- m_DAP->Update(atof(value)); //should push to subsystem.......
-
- };
- auto HWEL = [this](const char* value, int length)
- {
- HandleError(value, "REMEDY_EL_", "EL");
- };
- auto HWER = [this](const char* value, int length)
- {
- HandleError(value, "REMEDY_ER_", "ER");
- };
- auto HWWARN = [this](const char* value, int length)
- {
- HandleError(value, "REMEDY_WARN_", "EW");
- };
- auto HWEHE = [this](const char* value, int length)
- {
- assert(value);
- int nhe = atoi(value);
- FINFO("HE:{$}%", nhe);
- if (m_DoseUnit.m_HE->Update(nhe))
- FireNotify(m_DoseUnit.m_HE->GetKey(), m_DoseUnit.m_HE->JSGet());
- };
- //075 FLM100 FLI000 FLT006 FLF2 FLA0 FLS060 FLZ0 FLD0
- auto HWFLK = [this](const char* value, int length)
- {
- assert(value);
- if (length > 20) // Check if length is more than 20
- {
- FINFO("HWFLK={$}", value);
- int tmpflk, tmpflf, tmpfla, tmpfld, tmpflo;
- float tmpflm, tmpfli, tmpflt, tmpfls, tmpflw;
- char tmpbuf[3]{ 0, 0, 0 };
- //flk
- tmpbuf[0] = value[0];
- tmpbuf[1] = value[1];
- tmpbuf[2] = value[2];
- tmpflk = atoi(tmpbuf);
- 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];
- tmpflm = atof(tmpbuf) / 10.0;
- m_DoseUnit.m_FLMA->Update(tmpflm);
- FireNotify(AttrKey::FLUMA, m_DoseUnit.m_FLMA->JSGet());
- // fli
- tmpbuf[0] = value[14];
- tmpbuf[1] = value[15];
- tmpbuf[2] = value[16];
- tmpfli = atof(tmpbuf) / 10.0;
- m_DoseUnit.m_FLIntTime->Update(tmpfli);
- FireNotify(AttrKey::FLUIntTime, m_DoseUnit.m_FLIntTime->JSGet());
- // flt
- tmpbuf[0] = value[21];
- tmpbuf[1] = value[22];
- tmpbuf[2] = value[23];
- tmpflt = atof(tmpbuf) / 10.0;
- m_DoseUnit.m_FLAccTime->Update(tmpflt);
- FireNotify(AttrKey::FLUAccTime, m_DoseUnit.m_FLAccTime->JSGet());
- // flf
- tmpbuf[0] = value[28];
- tmpbuf[1] = 0;
- tmpbuf[2] = 0;
- tmpflf = atoi(tmpbuf);
- m_DoseUnit.m_FLMode->Update(tmpflf);
- FireNotify(AttrKey::FLUMode, m_DoseUnit.m_FLMode->JSGet());
- // fla
- tmpbuf[0] = value[33];
- tmpfla = atoi(tmpbuf);
- m_DoseUnit.m_ABSStatus->Update(tmpfla);
- FireNotify(AttrKey::FLUABSStatus, m_DoseUnit.m_ABSStatus->JSGet());
- // fls
- tmpbuf[0] = value[38];
- tmpbuf[1] = value[39];
- tmpbuf[2] = value[40];
- tmpfls = atof(tmpbuf) / 10.0;
- m_DoseUnit.m_PPS->Update(tmpfls);
- FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
- //// fld
- //tmpbuf[0] = value[50];
- //tmpbuf[1] = 0;
- //tmpbuf[2] = 0;
- //tmpfld = atoi(tmpbuf);
- //if (m_DoseUnit.m_DoseLevel->Get() != tmpfld && m_DoseUnit.m_DoseLevel->Update(tmpfld))
- // FireNotify(AttrKey::FLUDoseLevel, m_DoseUnit.m_DoseLevel->JSGet());
- FINFO("tmpflk={$}, tmpflf={$}, tmpfla={$}, tmpfld={$}, tmpflm={$}, tmpfli={$}, tmpflt={$}, tmpfls={$};", tmpflk, tmpflf, tmpfla, tmpfld, tmpflm, tmpfli, tmpflt, tmpfls);
- }
- else
- {
- m_DoseUnit.m_FLKV->Update(atof(value));
- FireNotify(AttrKey::FLUKV, m_DoseUnit.m_FLKV->JSGet());
- }
- };
- auto HWFLM = [this](const char* value, int length)
- {
- assert(value);
- float tmpflm = atof(value) / 10.0;
- m_DoseUnit.m_FLMA->Update(tmpflm);
- FireNotify(AttrKey::FLUMA, m_DoseUnit.m_FLMA->JSGet());
- };
- auto HWFLS = [this](const char* value, int length)
- {
- assert(value);
- FINFO("HWFLS={$}", value);
- float tmppps = atof(value) / 10.0;
- m_DoseUnit.m_PPS->Update(tmppps);
- FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
- };
- auto HWFLX = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- if (nValue == 0)
- {
- HWSend("FLX0");
- if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_XRAYOFF))
- {
- FINFO("Generator exposure process status{$};", "GENERATOR_FLU_XRAYOFF");
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- }
- else if (nValue == 1)
- {
- HWSend("FLX1");
- m_iLoopTime = REMEDY_LoopExpTime;
-
- if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_READY))
- {
- FINFO("Generator exposure process status{$};", "GENERATOR_FLU_READY");
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- }
- else if (nValue == 2)
- {
- HWSend("FLX2");
- if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_EXP))
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_XRAYON))
- {
- FINFO("Generator exposure process status{$};", "GENERATOR_FLU_XRAYON");
- 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 == 0)
- {
- HWSend("FLP0");
- if (m_iLoopTime == REMEDY_LoopExpTime)
- {
- if ((int)m_GenConfig["loopTime"] >= 100)
- {
- m_iLoopTime = (int)m_GenConfig["loopTime"];
- }
- else
- m_iLoopTime = REMEDY_LoopDefTime;
- FDEBUG("reduction loopTime[{$}]->[{$}]", REMEDY_LoopExpTime, m_iLoopTime.load());
- }
- if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_OFF))
- {
- FINFO("Generator exposure process status{$};", "GENERATOR_FLU_OFF");
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- RefreshData();
- }
- else
- {
- HWSend("FLP1");
- FINFO("FLP1 do nothing");
- }
- };
- auto HWFLF = [this](const char* value, int length)
- {
- assert(value);
- FINFO("HWFLF={$};", value);
- int tmpflf = atoi(value);
- m_DoseUnit.m_FLMode->Update(tmpflf);
- FireNotify(AttrKey::FLUMode, m_DoseUnit.m_FLMode->JSGet());
- };
- 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 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))
- {
- std::string strFlAccTime = m_DoseUnit.m_FLAccTime->JSGet() ;
- FINFO("HWFLT:{$};", strFlAccTime.c_str());
- FireNotify(AttrKey::FLUAccTime, strFlAccTime);
- }
- };
- // 有部分前缀是包含关系, 长的包含短的, 例如 KVS 包含了 KV.
- // 因此长的在前面, 短的在后面
- // !!! Device 是个短寿命对象, 而 arFrame 是静态变量 !!!
- // !!! 因此, 在添加到 arFrame 之前, 务必先清零 !!!
- arFrame.clear();
-
- arFrame.push_back(tFrameMapping("KV", 2, HWKV));
- arFrame.push_back(tFrameMapping("TU", 2, HWTU));
- 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("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("VP", 2, HWVPDOSE));
- arFrame.push_back(tFrameMapping("AP", 2, HWAPDOSE));
- arFrame.push_back(tFrameMapping("AT", 2, HWATDOSE));
- arFrame.push_back(tFrameMapping("EL", 2, HWEL));
- arFrame.push_back(tFrameMapping("ER", 2, HWER));
- arFrame.push_back(tFrameMapping("EW", 2, HWWARN));
- arFrame.push_back(tFrameMapping("HE", 2, HWEHE));
- arFrame.push_back(tFrameMapping("FLK", 3, HWFLK));
- arFrame.push_back(tFrameMapping("FLM", 3, HWFLM));
- 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("FLW", 3, HWFLW));
- arFrame.push_back(tFrameMapping("FLI", 3, HWFLI));
- arFrame.push_back(tFrameMapping("FLT", 3, HWFLT));
- 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("ST", 2, HWST));
- arFrame.push_back(tFrameMapping("EC", 2, HWEC));
- arFrame.push_back(tFrameMapping("DS", 2, HWDAPST)); //dap status
- arFrame.push_back(tFrameMapping("DA", 2, HWDAP)); //dap value
- arFrame.push_back(tFrameMapping("DT", 2, HWDT)); //test dap
- arFrame.push_back(tFrameMapping("P", 1, HWPR));
- }
- bool nsGEN::REMEDYDevice::StartHardwareStatusThread()
- {
- FINFO("enter Start HardwareStatus Thread ");
- if (m_pHardwareStatusThread == NULL)
- {
- DWORD m_HardwareStatusID;
- m_pHardwareStatusThread = CreateThread(0, 0, HardwareStatusThread, this, 0, &m_HardwareStatusID);
- if (m_pHardwareStatusThread == NULL)
- {
- Fatal("Start HardwareStatus Thread Failed");
- return false;
- }
- }
- return true;
- }
- bool nsGEN::REMEDYDevice::StartTrueParameterThread()
- {
- FINFO("enter Start TrueParameterThread Thread ");
- if (m_pTrueParameterThread == NULL)
- {
- DWORD m_pTrueParameterID;
- m_pTrueParameterThread = CreateThread(0, 0, TrueParameterThread, this, 0, &m_pTrueParameterID);
- if (m_pTrueParameterThread == NULL)
- {
- FERROR("Start TrueParameterThread Thread Failed");
- return false;
- }
- }
- return true;
- }
- DWORD nsGEN::REMEDYDevice::HardwareStatusThread(LPVOID pParam)
- {
- REMEDYDevice* pCurGen = (REMEDYDevice*)pParam;
- if (pCurGen == NULL)
- {
- return false;
- }
- FDEBUG("loopTime = {$}", pCurGen->m_iLoopTime.load());
- int currtTime = pCurGen->m_iLoopTime;
- int messageIndex = 0;
- FINFO("HardwareStatusThread start");
- while (true)
- {
- currtTime = pCurGen->m_iLoopTime;
- Sleep(currtTime);
- // 发送不同的消息,根据messageIndex循环
- switch (messageIndex)
- {
- case 0:
- pCurGen->HWSend("HE?");
- break;
- case 1:
- pCurGen->HWSend("ST");
- break;
- case 2:
- pCurGen->HWSend("FLT?");
- break;
- }
- // 更新messageIndex,以便下一轮发送不同的消息
- messageIndex = (messageIndex + 1) % 3;
- }
-
- FINFO("HardwareStatusThread stop");
- return true;
- }
- DWORD CCOS::Dev::Detail::Generator::REMEDYDevice::TrueParameterThread(LPVOID pParam)
- {
- REMEDYDevice* pCurGen = (REMEDYDevice*)pParam;
- if (pCurGen == NULL)
- {
- return false;
- };
- while (false)
- {
- Sleep(100);// 可以考虑继续Sleep(100)或者增加逻辑等待条件满足后再执行
- }
- return true;
- }
- //-----------------------------------------------------------------------------
- // REMEDYDriver
- //-----------------------------------------------------------------------------
- nsGEN::REMEDYDriver::REMEDYDriver()
- {
- }
- nsGEN::REMEDYDriver::~REMEDYDriver()
- {
- }
- auto nsGEN::REMEDYDriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
- {
- FINFO("CreateDevice in\n");
- m_pDevice = new REMEDYDevice(EventCenter, m_SCF, m_ConfigFileName);
- auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDevice));
- FINFO("CreateDevice out\n");
- return dev;
- }
- void nsGEN::REMEDYDriver::FireNotify(int code, std::string key, std::string content)
- {
- EventCenter->OnNotify(code, key, content);
- }
- Log4CPP::Logger* gLogger = nullptr;
- void nsGEN::REMEDYDriver::Prepare()
- {
- string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Generator\Conf\Log4CPP.Config.GEN.xml)";
- Log4CPP::GlobalContext::Map::Set(ECOM::Utility::Hash("LogFileName"), "GEN.REMEDY");
- auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
- gLogger = Log4CPP::LogManager::GetLogger("GEN.REMEDY");
- FINFO("Enter Prepare.");
- m_SCFDllName = GetConnectDLL(m_ConfigFileName);
- super::Prepare();
- }
- bool DATA_ACTION nsGEN::REMEDYDriver::Connect()
- {
- FINFO("Enter {$},configlef={$}\n", __FUNCTION__, m_ConfigFileName.c_str());
- super::Disconnect();
- m_SCF.Disconnect();
-
- ResDataObject Connection = GetConnectParam(m_ConfigFileName);
- FINFO("connections:{$} \n", Connection.encode());
- auto erCode = m_SCF.Connect(Connection.encode(), &nsGEN::REMEDYDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
- if (erCode != SCF_ERR::SCF_SUCCEED)
- {
- FINFO("SCF connection failed: erCode != SCF_ERR::SCF_SUCCEED\n");
- return false;
- }
- auto rc = super::Connect();
- if (!rc)
- {
- FINFO("super::Connect() failed\n");
- return false;
- }
- return true;
- }
- void nsGEN::REMEDYDriver::Disconnect()
- {
- super::Disconnect();
- m_SCF.Disconnect();
- }
- bool nsGEN::REMEDYDriver::isConnected() const
- {
- if (!super::isConnected())
- {
- FINFO("No valid connection!!!\n");
- return false;
- }
- if (m_pDevice == nullptr)
- {
- FINFO("m_pDevice == nullptr\n");
- return false;
- }
- if (m_pDevice->LoadConfig(m_ConfigFileName) == -1)
- {
- return false;
- }
- int genState = m_pDevice->GetGenState();
- FINFO("m_pDevice->GetGenState() == {$}\n", genState);
- return genState > 0; // 只有返回值大于 0 时才返回 true
- }
- std::string nsGEN::REMEDYDriver::DriverProbe()
- {
- 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", "REMEDY");
- HardwareInfo.add("ProductID", "HF");
- HardwareInfo.add("SerialID", "Drv");
- }
- string ret = HardwareInfo.encode();
- FINFO("DriverProbe out \n");
- return ret;
- }
- std::string nsGEN::REMEDYDriver::GetResource()
- {
- ResDataObject temp;
- if (!temp.loadFile(m_ConfigFileName.c_str()))
- return std::string();
- auto r_config = temp["CONFIGURATION"];
- for (auto& Item : m_ConfigInfo)
- {
- string key = Item.GetKey();
- if (key == ConfKey::CcosGeneratorType)
- {
- Item.SetCurrentValue(((string)r_config["VendorID"]).c_str());
- }
- else if (key == ConfKey::CcosGeneratorModel)
- {
- Item.SetCurrentValue(((string)r_config["ProductID"]).c_str());
- }
- else if (key == ConfKey::CcosWSTable || key == ConfKey::CcosWSWall || key == ConfKey::CcosWSFree
- || key == ConfKey::CcosWSTomo || key == ConfKey::CcosWSConventional)
- {
- Item.SetCurrentValue(((string)r_config[key.c_str()]).c_str());
- }
- else if (key == ConfKey::CcosSynTable || key == ConfKey::CcosSynWall || key == ConfKey::CcosSynFree
- || key == ConfKey::CcosSynTomo || key == ConfKey::CcosSynConventional)
- {
- Item.SetCurrentValue(((string)r_config[key.c_str()]).c_str());
- }
- else if (key == ConfKey::CcosSCFType)
- {
- Item.SetCurrentValue(((string)r_config["connections"][0]["type"]).c_str());
- }
- else if (key == ConfKey::CcosSCFPort || key == ConfKey::CcosSCFBaudrate || key == ConfKey::CcosSCFBytesize
- || key == ConfKey::CcosSCFParity || key == ConfKey::CcosSCFStopbits || key == ConfKey::CcosSCFIP)
- {
- if (r_config["connections"][0].GetFirstOf(key.c_str()) >= 0)
- {
- Item.SetCurrentValue(((string)r_config["connections"][0][key.c_str()]).c_str());
- }
- }
- }
- ResDataObject resAttr, resDescription;
- for (auto Item : m_ConfigInfo)
- {
- resAttr.add(Item.GetKey(), Item.GetCurrentValue());
- resDescription.add(Item.GetKey(), Item.GetDescription());
- }
- ResDataObject resDeviceResource;
- resDeviceResource.add(ConfKey::CcosGeneratorAttribute, resAttr);
- resDeviceResource.add(ConfKey::CcosGeneratorDescription, resDescription);
- string res = resDeviceResource.encode();
- //printf("resDeviceResource :%s \n", resDeviceResource.encode());
- FINFO("resDeviceResource :{$} \n", resDeviceResource.encode());
- ResDataObject DescriptionTempEx;
- DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
- m_DeviceConfig.clear();
- m_DeviceConfig = DescriptionTempEx;
- return res;
- }
- bool nsGEN::REMEDYDriver::GetDeviceConfig(std::string& Cfg)
- {
- //Cfg = m_DeviceConfigSend.encode();
- Cfg = m_DeviceConfig.encode();
- //printf("GetDeviceConfig over");
- printf("GetDeviceConfig over , %s", Cfg.c_str());
- return true;
- }
- bool nsGEN::REMEDYDriver::SetDeviceConfig(std::string Cfg)
- {
- FINFO("--Func-- SetDeviceConfig {$}\n", Cfg.c_str());
- return true;
- #if 0
- ResDataObject DeviceConfig;
- DeviceConfig.decode(Cfg.c_str());
- ResDataObject DescriptionTempEx;
- DescriptionTempEx = DeviceConfig["DeviceConfig"]["Attribute"];
- FDEBUG("Attribute:{$}", DescriptionTempEx.encode());
- bool bSaveFile = false; //true:重新保存配置文件
- string strAccess = "";
- for (int i = 0; i < DescriptionTempEx.size(); i++)
- {
- string strKey = DescriptionTempEx.GetKey(i);
- FINFO("{$}", strKey.c_str());
- try
- {
- if (m_pAttribute->GetFirstOf(strKey.c_str()) >= 0)
- {
- strAccess = (string)(*m_pDescription)[strKey.c_str()]["Access"];
- if ("RW" == strAccess)
- {
- //修改对应配置,在其他单元的配置项要同时调用其修改函数修改真实值
- //1. 修改内存中的值,用于给上层发消息
- (*m_pAttribute)[strKey.c_str()] = DescriptionTempEx[i];
- //2. 拿到Innerkey
- int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
- FINFO("nConfigInfoCount {$}", nConfigInfoCount);
- string strTemp = ""; //存储AttributeKey
- for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
- {
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
- if (strTemp == strKey)
- {
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
- break;
- }
- }
- //3. 修改配置文件中的值
- if (SetDeviceConfigValue(m_Configurations, strTemp.c_str(), 1, DescriptionTempEx[i]))
- {
- FDEBUG("SetDeviceConfigValue over");
- bSaveFile = true;
- }
- }
- else
- {
- FINFO("{$} is not a RW configuration item", strKey.c_str());
- }
- }
- else
- {
- FINFO("without this attribute {$}", strKey.c_str());
- }
- }
- catch (ResDataObjectExption& e)
- {
- FERROR("SetDriverConfig crashed: {$}", e.what());
- return false;
- }
- }
- if (bSaveFile)
- {
- //3. 重新保存配置文件
- SaveConfigFile(true);
- }
- #endif // 0
- return true;
- }
- bool nsGEN::REMEDYDriver::SaveConfigFile(bool bSendNotify)
- {
- m_ConfigAll["CONFIGURATION"] = m_Configurations;
- bool bRt = m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
- FINFO("SaveConfigFile over {$}", bRt);
- return true;
- }
- std::string nsGEN::REMEDYDriver::DeviceProbe()
- {
- FINFO("std::string nsGEN::PSGRFDriver::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", "REMEDY");
- HardwareInfo.add("ProductID", "HF");
- HardwareInfo.add("SerialID", "1234");
- }
- string ret = HardwareInfo.encode();
- FINFO("std::string nsGEN::PSGRFDriver::DeviceProbe() out\n");
- return ret;
- }
- void nsGEN::REMEDYDriver::Dequeue(const char* Packet, DWORD Length)
- {
- DecodeFrame(Packet, Length);
- }
- /*
- ==IN==:KV070 MA00320 MS00063 MX00036
- ==IN==:TU0 WS1 FO0 ET0 FI010 FS001 FN 0 HE000
- how to split the str like up.
- //command+03+sum
- */
- PACKET_RET nsGEN::REMEDYDriver::callbackPackageProcess(const char* RecData, DWORD nLength, DWORD& PacketLength)
- {
- if (nLength < 1)
- {
- printf("nLength < 1, nLength==%d \n", nLength);
- return PACKET_USELESS;
- }
- for (DWORD i = 0; i < nLength - 1; i++)
- {
- if (RecData[i] == 0x03)
- {
- PacketLength = i + 2; //应该+2.才会把最后的checmsum也包含进来。FO1+03+sum.
- char strtemp[100] = { 0 };
- memcpy(strtemp, RecData, i);
- strtemp[i + 1] = 0;
- FINFO("==IN==:{$}\n", strtemp);
- return PACKET_ISPACKET;
- }
- }
- return PACKET_NOPACKET;
- }
- //-----------------------------------------------------------------------------
- // DecodeFrame
- //-----------------------------------------------------------------------------
- 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);
- if (found == arFrame.end())
- {
- return false;
- }
- const auto& Item = *found;
- auto pc = strFrame;
- pc += Item.NbOfCharOfHead;
- Item.fun(pc, length - Item.NbOfCharOfHead);
- return true;
- }
- //-----------------------------------------------------------------------------
- // GetIODriver & CreateIODriver
- //-----------------------------------------------------------------------------
- static nsGEN::REMEDYDriver gIODriver;
- extern "C" CCOS::Dev::IODriver * __cdecl GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
- {
- return &gIODriver;
- }
- extern "C" CCOS::Dev::IODriver * __cdecl CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
- {
- return new nsGEN::REMEDYDriver();
- }
|