123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124 |
- // CCOS.Dev.GEN.CPI.cpp : 定义 DLL 应用程序的导出函数。
- //
- #include "stdafx.h"
- #include <assert.h>
- #include <functional>
- using namespace std::placeholders;
- //#include "logger.temp.h"
- #include "CCOS.Dev.Generator.CPI.h"
- #include "Helper.JSON.hpp"
- using namespace CCOS::Dev::Detail::Generator;
- namespace nsGEN = CCOS::Dev::Detail::Generator;
- #pragma warning (disable:4244 4305 4267 4838 4309 4715 26495 26812)
- 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
- //-----------------------------------------------------------------------------
- // CPIDevice
- //-----------------------------------------------------------------------------
- float g_MA_List[] = { 8, 10, 12.5, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640 };
- float g_MAS_List[] = { 1, 1.25, 1.6, 2, 2.5, 3.2, 4, 5, 6.4, 8, 10, 12.5, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640, 800, 1000 };
- float g_MS_List[] = { 1, 2, 3, 4, 5, 6, 8, 10, 12, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640, 800, 1000, 1250, 1600, 2000, 2500, 3200, 4000, 5000, 6400, 8000, 10000 };
- int g_AECFIELD_List[] = { 1, 10, 100, 11, 101, 111 };
- std::vector <float> gf_MA_List = { 8, 10, 12.5, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640 };
- 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::CPIDevice::CPIDevice(std::shared_ptr <IOEventCenter> center, nsSCF::SCF SCF, string configfile) : super(center, SCF)
- {
- assert(EventCenter);
-
- FINFO("version:3.0.0.5");
- m_DoseUnit.m_KV.reset(new KVMould(0.0, 40.0, 120.0, 1.0));
- m_DoseUnit.m_MA.reset(new MAMould(0.0, 1.0, 1000.0, 0.1));
- m_DoseUnit.m_MS.reset(new MSMould(0.0, 1.0, 10000.0, 0.01));
- m_DoseUnit.m_MAS.reset(new MASMould(0.0, 0.5, 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, 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_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_DoseUnit.m_FLMode.reset(new FLUModeMould(AttrKey::GENERATOR_FLUMode::GENERATOR_FLMODE_NOTFLU));
- m_MSGUnit.reset(new nsDetail::MSGUnit(center, nsGEN::GeneratorUnitType));
- m_DAP.reset(new DevDAP::DOSEMould(0.0, 0.0, 1000.0, 0.01));
- m_hGenPostEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
- m_pHardwareStatusThread = NULL;
- m_bWithCollimator = false;
- m_nDeviceType = 0;
-
- m_fMsLimit = 500;
- m_strConfigPath = configfile;
- ResDataObject temp;
- temp.loadFile(m_strConfigPath.c_str());
- m_GenConfig = temp["CONFIGURATION"];
- TransJsonText(m_GenConfig);
- m_nDeviceType = (int)(m_GenConfig["GenType"]);//默认设置为2. 带有coll的。
- if (m_nDeviceType == 2)
- {
- m_bWithCollimator = true;
- }
- m_nAECMode = (int)m_GenConfig["AECMODE"];
- m_fMsLimit = (float)m_GenConfig["LIMITMS"];//default 500
- m_nCtlMode = (int)m_GenConfig["GenCtrlMode"];//default 2
- char strStart1[6] = { 0x01,0x35,0x00,0x01,0x01,0x38 };
- char strStart2[7] = { 0x01,0x01,0x00,0x02,0x00,0x64,0x73 };
- char strStart0a[7] = { 0x01,0x06,0x00,0x02,0x01,0x00,0x0a };
- char strStart1b[7] = { 0x01,0x06,0x00,0x02,0x01,0x01,0x0b };
- char strStart2c[7] = { 0x01,0x06,0x00,0x02,0x01,0x02,0x0c };
- char strStart3d[7] = { 0x01,0x06,0x00,0x02,0x01,0x03,0x0d };
- char strStart4e[7] = { 0x01,0x06,0x00,0x02,0x01,0x04,0x0e };
- char strStart5f[7] = { 0x01,0x06,0x00,0x02,0x01,0x05,0x0f };
- char strStart00c[8] = { 0x01,0x07,0x00,0x03,0x01,0x00,0x00,0x0c };
- char strStart01d[8] = { 0x01,0x07,0x00,0x03,0x01,0x00,0x01,0x0d };
- char strStart02e[8] = { 0x01,0x07,0x00,0x03,0x01,0x00,0x02,0x0e };
- char strStart03f[8] = { 0x01,0x07,0x00,0x03,0x01,0x00,0x03,0x0f };
- char strStart040[8] = { 0x01,0x07,0x00,0x03,0x01,0x00,0x04,0x10 };
- char strEnd1[8] = { 0x43,0x41,0x30,0x03,0xb7,0x50,0x52,0x30 };
- char strEnd2[8] = { 0x03,0xd5,0x01,0x35,0x00,0x01,0x00,0x37 };
- if (m_nCtlMode == 2)
- {
- //SendCommands(strStart1, 6);
- HWSend(strStart1);
- //::Sleep(50);
- HWSend(strStart2);
- //::Sleep(50);
- HWSend(strStart0a);
- //::Sleep(50);
- HWSend(strStart1b);
- //::Sleep(50);
- HWSend(strStart2c);
- //::Sleep(50);
- HWSend(strStart3d);
- //::Sleep(50);
- HWSend(strStart4e);
- //::Sleep(50);
- HWSend(strStart5f);
- //::Sleep(50);
- HWSend(strStart0a);
- //::Sleep(50);
- HWSend(strStart00c);
- //::Sleep(50);
- HWSend(strStart01d);
- //::Sleep(50);
- HWSend(strStart02e);
- //::Sleep(50);
- HWSend(strStart03f);
- //::Sleep(50);
- HWSend(strStart040);
- //::Sleep(50);
- HWSend(strStart00c);
- //::Sleep(50);
- HWSend(strStart01d);
- //::Sleep(50);
- HWSend(strStart02e);
- //::Sleep(50);
- HWSend(strStart03f);
- //::Sleep(50);
- HWSend(strStart040);
- SetExpEnable();
- }
- m_bDAPEnable = false;
- m_bSaveMSMA = true;
- //SynMode default is what?
- OnCallBack();
- Register();
- Reset();
- Sleep(500);
- HWSend("DS");
- HWSend("ET?");
- HWSend("ST");
- RefreshData();
- HWSend("ATU?");//直到收到ATU1为止。
- m_bCheckATUStatus = true;
- StartHardwareStatusThread();
- }
- nsGEN::CPIDevice::~CPIDevice()
- {
- CloseHandle(m_hGenPostEvent);
- }
- std::string nsGEN::CPIDevice::GetGUID() const
- {
- FINFO("\n===============GetGUID : {$} ===================\n", GeneratorUnitType);
- return GeneratorUnitType;
- }
- void nsGEN::CPIDevice::Register()
- {
- auto Disp = &Dispatch;
- superGen::Register(Disp);
- superGen::RegisterRAD(Disp);
- superGen::RegisterAEC(Disp);
- superGen::RegisterExpEnable(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::CPIDevice::IncKV()
- {
- if (!m_DoseUnit.m_KV->CanInc()) return RET_STATUS::RET_SUCCEED;
- return HWSend("KV+");
- }
- RET_STATUS nsGEN::CPIDevice::DecKV()
- {
- if (!m_DoseUnit.m_KV->CanDec()) return RET_STATUS::RET_SUCCEED;
- return HWSend("KV-");
- }
- RET_STATUS nsGEN::CPIDevice::SetKV(float value)
- {
- 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::CPIDevice::IncMA()
- {
- if (!m_DoseUnit.m_MA->CanInc()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_AEC && m_nAECMode == 1)
- {
- FINFO("\n In AEC mode, do not allowed INCMA");
- return RET_STATUS::RET_FAILED;
- }
-
- return HWSend("MA+");
- }
- RET_STATUS nsGEN::CPIDevice::DecMA()
- {
- if (!m_DoseUnit.m_MA->CanDec()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_AEC && m_nAECMode == 1)
- {
- FINFO("\n In AEC mode, do not allowed DECMA");
- return RET_STATUS::RET_FAILED;
- }
-
- return HWSend("MA-");
- }
- RET_STATUS nsGEN::CPIDevice::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_AEC && m_nAECMode == 1)
- {
- //logfile->WriteLog("In AEC mode, do not allowed SetMA", LOG_INFORMATION, LOG_DEBUG, true);
- FINFO("\n In AEC mode, do not allowed SetMA");
- return RET_STATUS::RET_FAILED;
- }
-
- char temp[50] = { 0 };
- sprintf_s(temp, "MA%05d", (int)(value * 10));
- return HWSend(temp);
- }
- RET_STATUS nsGEN::CPIDevice::IncMS()
- {
- if (!m_DoseUnit.m_MS->CanInc()) return RET_STATUS::RET_SUCCEED;
- /*
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- PRINTA_INFO("\n Techmode is MAS, can't inc MS");
- return RET_STATUS::RET_FAILED;
- }
- */
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_AEC && m_nAECMode != 2)
- {
- //logfile->WriteLog("In AEC mode, do not allowed SetMA", LOG_INFORMATION, LOG_DEBUG, true);
- FINFO("\n In AEC mode, do not allowed INCMS");
- return RET_STATUS::RET_FAILED;
- }
- return HWSend("MS+");
- }
- RET_STATUS nsGEN::CPIDevice::DecMS()
- {
- if (!m_DoseUnit.m_MS->CanDec()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_AEC && m_nAECMode != 2)
- {
- FINFO("\n Techmode is MAS, can't dec MS");
- return RET_STATUS::RET_FAILED;
- }
- return HWSend("MS-");
- }
- RET_STATUS nsGEN::CPIDevice::SetMS(float value)
- {
- if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_AEC && m_nAECMode != 2)
- {
- FINFO("\n In AEC mode, do not allowed SetMS");
- return RET_STATUS::RET_FAILED;
- }
- char temp[50] { 0 };
- sprintf_s(temp, "MS%05d", (int)(value * 10));
- return HWSend(temp);
- }
- RET_STATUS nsGEN::CPIDevice::IncMAS()
- {
- if (!m_DoseUnit.m_MAS->CanInc()) return RET_STATUS::RET_SUCCEED;
-
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_AEC && m_nAECMode != 1)
- {
- FINFO("\n Techmode is not MAS, can't inc MAS");
- return RET_STATUS::RET_FAILED;
- }
- return HWSend("MX+");
- }
- RET_STATUS nsGEN::CPIDevice::DecMAS()
- {
- if (!m_DoseUnit.m_MAS->CanDec()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_AEC && m_nAECMode != 1)
- {
- FINFO("\n Techmode is not MAS, can't dec MAS");
- return RET_STATUS::RET_FAILED;
- }
- return HWSend("MX-");
- }
- RET_STATUS nsGEN::CPIDevice::SetMAS(float value)
- {
- if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_AEC && m_nAECMode != 1)
- {
- FINFO("\n Techmode is not MAS, can't set MAS");
- return RET_STATUS::RET_FAILED;
- }
- char temp[50] = { 0 };
- sprintf_s(temp, "MX%05d", (int)(value * 10));
- return HWSend(temp);
- }
- RET_STATUS nsGEN::CPIDevice::SetTechmode(int value)
- {
- if (!m_DoseUnit.m_Techmode->Verify(value)) return RET_STATUS::RET_SUCCEED;
-
- //char temp[50] = { 0 };
- //sprintf_s(temp, "ET%01d", (int)value);
- //return HWSend(temp);
- //CPI设置ET mode有点特殊
- float fms, fma;
- m_nPreET = m_DoseUnit.m_Techmode->Get();
- char temp[50] = { 0 };
- sprintf_s(temp, "ET%01d", (int)value);
- HWSend(temp);
- if (!m_bSaveMSMA)
- return RET_STATUS::RET_FAILED;
-
- if (value == AttrKey::TECHMODE_V2TYPE::ET_TIME)
- {
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)//NOTE: use m_DoseUnit.m_Techmode->Get() not accurate. m_nPreET more better.!!!!
- {
- // mas - time
- if ((m_fPreMA > 0.1))
- {
- Sleep(50);
- SetMA(m_fPreMA);
- }
- Sleep(50);
- SetMS(m_PrefMS);
- }
- else if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_AEC)
- {
- // aec - time
- if (m_bSaveMSMA)
- {
- fms = m_PrefMS;
- fma = m_fPreMA;
- Sleep(50);
- SetMS(fms);
- Sleep(50);
- SetMA(fma);
- }
- }
- }
- else if (value == AttrKey::TECHMODE_V2TYPE::ET_MAS) //mas
- {
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_TIME)
- {
- // time - mas save
- if (m_bSaveMSMA)
- {
- m_PrefMS = m_DoseUnit.m_MS->Get();
- m_fPreMA = m_DoseUnit.m_MA->Get();
- }
- }
- else if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_AEC)
- {
- // aec - mas
- if (m_bSaveMSMA)
- {
- fms = m_PrefMS;
- fma = m_fPreMA;
- }
- SetMAS(m_PrefMS * m_fPreMA / 1000); //mas mode : set dose to ma * ms
- }
- }
- else if (value == AttrKey::TECHMODE_V2TYPE::ET_AEC) //aec
- {
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_TIME)
- {
- // time - aec save
- if (m_bSaveMSMA)
- {
- m_PrefMS = m_DoseUnit.m_MS->Get();
- m_fPreMA = m_DoseUnit.m_MA->Get();
-
- }
- }
- else if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- // mas - aec
- if ((m_fPreMA > 0.1))
- {
- Sleep(50);
- if (m_nAECMode != 1)
- SetMA(m_fPreMA);
- }
- }
- Sleep(50);
- if (m_nAECMode == 2)
- SetMS(m_fMsLimit);
- //ysj++:不知道为什么要这么干,不过此处需要一个设置MS的语句
- //if (m_nWS == GEN_WS_TOMO)
- //{
- // if (m_nAECMode == 2)
- // SetMS(m_PrefMS);
- //}
- //else
- //{
- // if (m_nAECMode == 2)
- // SetMS(m_fMsLimit);
- //}
- }
- }
- RET_STATUS nsGEN::CPIDevice::SetFocus(int value)
- {
- 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::CPIDevice::SetAECDensity(int value)
- {
- FINFO("Enter SetAECDensity {$}", 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;
- }
- }
- char temp[50] = { 0 };
- if (nAECDensity >= 0)
- {
- sprintf_s(temp, "FN+%01d", (int)nAECDensity);
- }
- else
- {
- sprintf_s(temp, "FN-%01d", (int)nAECDensity);
- }
- return HWSend(temp);
- }
- RET_STATUS nsGEN::CPIDevice::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;
- char temp[50] = { 0 };
- sprintf_s(temp, "FI%03d", (int)value);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::CPIDevice::SetAECFilm(int value)
- {
- if (!m_DoseUnit.m_AECFilm->Verify(value)) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS) return RET_STATUS::RET_FAILED;
- char temp[50] = { 0 };
- sprintf_s(temp, "FS%03d", (int)value);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::CPIDevice::SetWS(const string value)
- {
- 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"];
- char temp[50] = { 0 };
- sprintf_s(temp, "WS%01d", tempws);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::CPIDevice::SetAPR(const _tAPRArgs& t)
- {
- m_t = t;
- FINFO("*********************Enter SetAPR**********************");
- FINFO("APR:t.fKV={$}, t.fMA={$}, t.fMAS={$}, t.fMS={$}, t.nAECDensity={$}, t.nAECField={$}, t.nAECFilm={$}, t.nFocus={$}, t.nTechmode={$}", t.fKV, t.fMA, t.fMAS, t.fMS, t.nAECDensity, t.nAECField, t.nAECFilm, t.nFocus, t.nTechmode);
- /// //////////////////////////////////////////////begin
- //SetWS(); //ysj++:缺少传递ws的apr结构体
- //GetTechMode(); //ysj++:理论上,init时,RR指令已经获取ET了。
- HWSend("ET?");
- if (m_DoseUnit.m_Focus->Get() == 0)
- {
- SetFocus(t.nFocus);
- }
- /*
- * //not add this logic: because struct _tAPRArgs ,not include WS item.
-
- if ((nWS != GEN_WS_TABLE) && (nWS != GEN_WS_WALL) && (nET == GEN_ET_AEC))
- {
- if (m_nET != GEN_ET_AEC)
- {
- nET = m_nET;
- }
- else
- {
- nET = GEN_ET_MATIME;
- }
- }
- */
- m_PrefMS = t.fMS;
- m_fPreMA = t.fMA;
- m_bSaveMSMA = false;
-
- if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_AEC)
- {
- // aec
- SetTechmode(t.nTechmode);
- SetAECField(t.nAECField);
- SetAECDensity(t.nAECDensity);
-
- if (t.nAECFilm == 0)
- {
- SetAECFilm(10);
- }
- else
- {
- SetAECFilm(t.nAECFilm);
- }
- if (m_nAECMode == 2)
- {
- if (t.fKV > m_DoseUnit.m_KV->Get())
- {
- SetMA(t.fMA);
- SetKV(t.fKV);
- }
- else
- {
- if (t.fMA < m_DoseUnit.m_MA->Get())
- {
- SetMA(t.fMA);
- SetKV(t.fKV);
- }
- else
- {
- SetKV(t.fKV);
- SetMA(t.fMA);
- }
- }
- Sleep(50);
- SetMS(m_fMsLimit);//int V2 mode.m_fMsLimit is set by UI.but in CCOS2.0 it set by config file.
- }
- else if (m_nAECMode == 1)
- {
- if (t.fKV > m_DoseUnit.m_KV->Get())
- {
- SetMA(t.fMA);
- Sleep(50);
- SetKV(t.fKV);
- }
- else
- {
- if (t.fMA < m_DoseUnit.m_MA->Get())
- {
- SetMA(t.fMA);
- Sleep(50);
- SetKV(t.fKV);
- }
- else
- {
- SetKV(t.fKV);
- Sleep(50);
- SetMA(t.fMA);
- }
- }
- Sleep(50);
- SetMAS(t.fMAS);
- }
- else
- {
- if (t.fMA < m_DoseUnit.m_MA->Get())
- {
- SetMA(t.fMA);
- Sleep(50);
- SetKV(t.fKV);
- }
- else
- {
- SetKV(t.fKV);
- Sleep(50);
- SetMA(t.fMA);
- }
- }
- }
- else if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- // mas
- SetTechmode(t.nTechmode);
- SetKV(t.fKV);
- 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);
- if (t.fKV > m_DoseUnit.m_KV->Get())
- {
- SetMA(t.fMA);
- Sleep(50);
- SetKV(t.fKV);
- }
- else
- {
- if (t.fMA < m_DoseUnit.m_MA->Get())
- {
- SetMA(t.fMA);
- Sleep(50);
- SetKV(t.fKV);
- }
- else
- {
- SetKV(t.fKV);
- Sleep(50);
- SetMA(t.fMA);
- }
- }
- Sleep(80);
- SetMS(t.fMS);
- }
- if (m_DoseUnit.m_Focus->Get() == 1)
- {
- SetFocus(t.nFocus);
- }
- m_bSaveMSMA = true;
- ///////////////////////end
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::CPIDevice::QueryDAP()
- {
- if (m_bDAPEnable)
- {
- return HWSend("DA");
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::CPIDevice::QueryHE(int& value)
- {
- value = m_DoseUnit.m_HE->Get();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::CPIDevice::QueryPostKV(float& value)
- {
- value = m_DoseUnit.m_PostKV->Get();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::CPIDevice::QueryPostMA(float& value)
- {
- value = m_DoseUnit.m_PostMA->Get();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::CPIDevice::QueryPostMS(float& value)
- {
- value = m_DoseUnit.m_PostMS->Get();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::CPIDevice::QueryPostMAS(float& value)
- {
- value = m_DoseUnit.m_PostMAS->Get();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::CPIDevice::Clear_DAP()
- {
- if (m_bDAPEnable)
- {
- return HWSend("DZ");
- }
- else
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::CPIDevice::GetValue_DAP(float& value)
- {
- value = m_DAP->Get();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::CPIDevice::StartMove()
- {
- FINFO("Enter startMove");
- FINFO("end startmove");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::CPIDevice::EndMove()
- {
- FINFO("Enter endmove");
- FINFO("end EndMove");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::CPIDevice::SetCollimatorSize(int height, int width)
- {
- if (!m_bWithCollimator)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- char temp[50] = { 0 };
- sprintf_s(temp, "ACH%05d", (int)(height * 100));
- HWSend(temp);
- sprintf_s(temp, "ACW%05d", (int)(width * 100));
- HWSend(temp);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::CPIDevice::SetFilter(int filterType)
- {
- if (!m_bWithCollimator)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- if (filterType > 3)
- {
- filterType -= 3;
- }
- char temp[50] = { 0 };
- sprintf_s(temp, "FIL%02d", (int)(filterType));
- return HWSend(temp);
- }
- RET_STATUS nsGEN::CPIDevice::SetGenSynState(int 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::CPIDevice::SetGenState(int value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::CPIDevice::SetExpMode(std::string value)
- {
- FINFO("Enter SetExpMode...{$}",value);
- m_DoseUnit.m_ExpMode->Update(value);
-
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::CPIDevice::SetFLFMode(std::string value)
- {
- return RET_STATUS::RET_SUCCEED;
- //char temp[50]{ 0 };
- //sprintf_s(temp, "RTS%s",value.c_str());
- //return HWSend(temp);
- }
- RET_STATUS nsGEN::CPIDevice::SetEXAMMode(std::string value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::CPIDevice::SetFrameRate(FLOAT frameRate)
- {
- m_DoseUnit.m_FrameRate->Update(frameRate);
-
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::CPIDevice::SetRPS(int rps)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::CPIDevice::RefreshData()
- {
- if (m_nDeviceType == 1)
- {
- HWSend("RRX");
- }
- else
- {
- //HWSend("RR");
- HWSend("KV?");
- HWSend("MA?");
- HWSend("MS?");
- HWSend("MX?");
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::CPIDevice::SetExpEnable()
- {
- m_bExpEnable = true;
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::CPIDevice::SetExpDisable()
- {
- m_bExpEnable = false;
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::CPIDevice::Reset()
- {
- return HWSend("RE");
- }
- RET_STATUS nsGEN::CPIDevice::SetCollimatorDev(OemCollimator* dev)
- {
- if (dev)
- m_pCollDev.reset(dev);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::CPIDevice::SetMechDev(OemMechanical* dev)
- {
- //if (dev)
- //m_pMechDev.reset(dev);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::CPIDevice::SetDapDev(OemDap* dev)
- {
- if (dev)
- m_pDapDev.reset(dev);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::CPIDevice::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);
- //strSendCommand[0] = 0x02;
- memcpy(strSendCommand , strCommand, len);
- strSendCommand[len + 0] = 0x03;
- strSendCommand[len + 1] = checkSum;
- printf("==OUT==: %s \n", strSendCommand);
- 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::CPIDevice::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
- //for (int i = 0; i < len; i++) //给strHead赋值
- // strHead[i + 1] = str[i];
- //NbOfCharOfHead = len + 1;
- //fun = f;
- //assert(len < MaxLen);
- 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);
- //KV075 MA05000 MS00800 MX00400
- // ==IN==:KV075 MA05000 MS00800 MX00400
- void nsGEN::CPIDevice::OnCallBack()
- {
- auto HWNotProcess = [](const char* value, int length) -> void
- {
- FINFO("\n This commands didn't need to process!\n");
- };
- auto HWKV = [this](const char* value, int length) -> void
- {
- assert(value);
- 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) / 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());
- //}
- 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);
- if (m_DoseUnit.m_MS->Update(atof(value) / 10.0))
- FireNotify(AttrKey::MS, m_DoseUnit.m_MS->JSGet());
- };
- auto HWFocus = [this](const char* value, int length)
- {
- assert(value);
- if (m_DoseUnit.m_Focus->Update(atoi(value)))
- FireNotify(AttrKey::FOCUS, m_DoseUnit.m_Focus->JSGet());
- };
- auto HWTechmode = [this](const char* value, int length)
- {
- assert(value);
- if (m_DoseUnit.m_Techmode->Update(atoi(value)))
- FireNotify(AttrKey::TECHMODE, m_DoseUnit.m_Techmode->JSGet());
- };
- 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);
- //ysj++:理论上 此处得到WS的值,需要转为对应的数字,转换后的数字,能给UI一致,从而得出正确的ws并显示出来。
- int nValue = atoi(value);
- if (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)
- {
- m_bInExpState = true;
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_READY);
- ResetEvent(m_hGenPostEvent);
- HWSend("PR2");
- }
- else if (nValue == 1)
- {
- m_bInExpState = true;
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_PREPARE);
- HWSend("PR1");
- }
- else if (nValue == 0)
- {
- m_bInExpState = false;;
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF);
- HWSend("PR0");
- }
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- };
- auto HWXR = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- if (nValue == 1)
- {
- if ((this->m_nCtlMode == 2) && m_bExpEnable)
- {
- if (EXPOSURE_SOFTWARE_NOSYNBOX == (int)m_GenConfig["SynMode"] || EXPOSURE_NOSYNBOX_DIRCETCONNECT_DETECTOR_GEN == (int)m_nCtlMode["SynMode"])
- {
- FINFO("recv XR1 ,in nosynbox or in derect mode ,do nothing,and wait invoke be call,then send XR1,and send XRAYON msg.");
- //m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON);// ysj++ 我们认为此处不应该发这个消息,准确的时机 应该是invoke被调用的时候,
- }
- if (EXPOSURE_SOFTWARE_NOSYNBOX != (int)m_GenConfig["SynMode"])
- {
- FINFO("recv XR1 ,in hardware or in derect mode ,so response XR1.");
- HWSend("XR1");
- }
- }
- else
- {
- if (2 != this->m_nCtlMode)
- {
- if (EXPOSURE_SOFTWARE_NOSYNBOX == (int)m_GenConfig["SynMode"] || EXPOSURE_NOSYNBOX_DIRCETCONNECT_DETECTOR_GEN == (int)m_nCtlMode["SynMode"])
- {
- //::SendMessage(this->m_hWnd, MSG_SYN_STATUS, SYN_GEN_EIPON, 1); //------------------------------------------------貌似没有软同步的消息
- FINFO("recv XR1 : ctrlmode !=2, in No SYNbox or in directly mode, Send Msg SYN_GEN_EIPON");
- }
- }
- }
- }
- else if (nValue == 0)
- {
-
- if (m_nCtlMode == 2)
- {
- HWSend("XR0");
- }
- HWSend("DA");
- HWSend("AP?");
- HWSend("AT?");
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF);
- }
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- };
- auto HWAPDOSE = [this](const char* value, int length)//post mas
- {
- assert(value);
- if(m_DoseUnit.m_PostMAS->Update(atof(value) / 10.0))
- FireNotify(m_DoseUnit.m_PostMAS->GetKey(), m_DoseUnit.m_PostMAS->JSGet());
- //SetEvent(m_hGenPostEvent);
- };
- auto HWKW = [this](const char* value, int length)
- {
- assert(value);
- FINFO("Recv KW={$}", atoi(value));
- };
- auto HWATDOSE = [this](const char* value, int length)
- {
- assert(value);
- if(m_DoseUnit.m_PostMS->Update(atof(value)/10.0))
- FireNotify(m_DoseUnit.m_PostMS->GetKey(), m_DoseUnit.m_PostMS->JSGet());
- //SetEvent(m_hGenPostEvent);
- };
- auto HWDAP = [this](const char* value, int length)
- {
- assert(value);
- FINFO("Recv DAP ={$}", atof(value) / 100.0);
- //ysj++:理论上此处应该调用DAP设备。
- if (m_pDapDev)
- {
- m_pDapDev->UpdateMammo_DAP(atof(value) / 100.0);
- }
- };
- auto HWERROR = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- if (nValue != 0)
- {
- char ErrorCode[10]{ "" };
- sprintf_s(ErrorCode, "CPI_ERR_%d", nValue);
- int level = 1;
- m_MSGUnit->AddErrorMessage(ErrorCode, level, "");
- //去配置文件中找error对应的信息
- }
- else
- {
- int level = 1;
- char ErrorCode[10]{ "" };
- m_MSGUnit->DelErrorMessage(ErrorCode, level, "");
- }
- };
- auto HWWARN = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- if (nValue != 0)
- {
- char WarnCode[10]{ "" };
- sprintf_s(WarnCode, "CPI_WARN_%d", nValue);
- int level = 1;
- m_MSGUnit->AddWarnMessage(WarnCode, level, "");
- }
- else
- {
- int level = 1;
- char WarnCode[10]{ "" };
- m_MSGUnit->AddWarnMessage(WarnCode, level, "");
- }
- };
- auto HWEHE = [this](const char* value, int length)
- {
- assert(value);
- if(m_DoseUnit.m_HE->Update(atoi(value)))
- FireNotify(m_DoseUnit.m_HE->GetKey(), m_DoseUnit.m_HE->JSGet());
- };
- auto HWFLK = [this](const char* value, int length)
- {
- assert(value);
- if (m_DoseUnit.m_KV->Update(atof(value)))
- FireNotify(AttrKey::KV, m_DoseUnit.m_KV->JSGet());
- };
- auto HWFLM = [this](const char* value, int length)
- {
- assert(value);
- if (m_DoseUnit.m_MA->Update(atof(value)/10.0))
- FireNotify(AttrKey::MA, m_DoseUnit.m_MA->JSGet());
- };
- auto HWFLS = [this](const char* value, int length)
- {
- assert(value);
- if (m_DoseUnit.m_FrameRate->Update(atof(value)/10.0))
- FireNotify(AttrKey::FRAMERATE, m_DoseUnit.m_FrameRate->JSGet());
- };
- auto HWFLX = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- if (nValue == 1)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_XRAYON);
- }
- else if (nValue == 0)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_XRAYOFF);
- }
- 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 == 1)
- {
- //PRINTA_INFO("\n recv FLP1\n"); //FLP1尚未真正的ready.
- }
- else if (nValue == 4)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_READY); //根据全新定义 FLP4 才表示 ready。
- }
- else if (nValue == 0)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_OFF);
- }
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- };
- auto HWACH = [this](const char* value, int length)
- {
- assert(value);
- if (m_pCollDev)
- {
- m_pCollDev->UpdateCollimatorXSize(atoi(value) / 100.0);
- }
-
- };
- auto HWACW = [this](const char* value, int length)
- {
- assert(value);
- if (m_pCollDev)
- {
- m_pCollDev->UpdateCollimatorYSize(atoi(value) / 100.0);
- }
- };
- auto HWFIL = [this](const char* value, int length)
- {
- assert(value);
- if (m_pCollDev)
- {
- m_pCollDev->SetCollimatorFilter(atoi(value));
- }
- };
- auto HWATU = [this](const char* value, int length)
- {
- assert(value);
- if (1 == atoi(value))
- {
- m_bCheckATUStatus = false;//not need continue check status
- }
- else if (0 == atoi(value))
- {
- m_bCheckATUStatus = true;
- }
- };
- auto HWDS = [this](const char* value, int length)
- {
- assert(value);
- m_bDAPEnable = (bool)atoi(value);
- };
- arFrame.clear();
- 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("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("AP", 2, HWAPDOSE));
- arFrame.push_back(tFrameMapping("AT", 2, HWATDOSE));
- arFrame.push_back(tFrameMapping("EL", 2, HWERROR));
- arFrame.push_back(tFrameMapping("ER", 2, HWWARN));
- arFrame.push_back(tFrameMapping("HE", 2, HWEHE));
- 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("ACH", 3, HWACH));
- arFrame.push_back(tFrameMapping("ACW", 3, HWACW));
- arFrame.push_back(tFrameMapping("FIL", 3, HWFIL));
- arFrame.push_back(tFrameMapping("ATU", 3, HWATU));
- }
- bool nsGEN::CPIDevice::StartHardwareStatusThread()
- {
- FINFO("enter Start HardwareStatus Thread ");
- if (m_pHardwareStatusThread == NULL)
- {
- DWORD m_HardwareStatusID;
- m_pHardwareStatusThread = CreateThread(0, 0, HardwareStatusThread, this, 0, &m_HardwareStatusID);
- if (m_pHardwareStatusThread == NULL)
- {
- Fatal("Start HardwareStatus Thread Failed");
- return false;
- }
- }
- return true;
- }
- DWORD nsGEN::CPIDevice::HardwareStatusThread(LPVOID pParam)
- {
- CPIDevice* pCurGen = (CPIDevice*)pParam;
- if (pCurGen == NULL)
- {
- return false;
- }
- FINFO("HardwareStatusThread start");
- while (true)
- {
- Sleep(2000);
- pCurGen->HWSend("HE?");
- static int cnt = 0;
- if (pCurGen->m_bCheckATUStatus)
- {
- cnt++;
- if (cnt == 10)
- {
- pCurGen->HWSend("ATU?");
- cnt = 0;
- }
- }
- else
- {
- cnt = 0;
- }
- }
- FINFO("HardwareStatusThread stop");
- return true;
- }
- //-----------------------------------------------------------------------------
- // CPIDriver
- //-----------------------------------------------------------------------------
- nsGEN::CPIDriver::CPIDriver()
- {
- m_bDemoConnected = false;
- m_pDriGenDev = nullptr;
- m_pDriCollDev = nullptr;
- m_pDriDapDev = nullptr;
- m_pAttribute.reset(new ResDataObject());
- m_pDescription.reset(new ResDataObject());
- }
- nsGEN::CPIDriver::~CPIDriver()
- {
- }
- auto nsGEN::CPIDriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
- {
- if (!m_SCF.isConnected())
- return nullptr;
- // auto dev = std::unique_ptr <IODevice>(new IODevice(new CPIDevice(EventCenter, m_SCF, m_ConfigFileName)));
-
- if (index == 0)
- {
- m_pDriGenDev = new CPIDevice(EventCenter, m_SCF, m_ConfigFileName);
- auto dev = std::unique_ptr<IODevice>(new IODevice(m_pDriGenDev));
- return dev;
- }
- else if (index == 1)
- {
- FINFO("Enter CreateDevice COLL");
- m_pDriCollDev = new OemCollimator(std::shared_ptr<IOEventCenter>(new IOEventCenter()));
- auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDriCollDev));
- m_pDriCollDev->SetCtrlDev(m_pDriGenDev);
- m_pDriGenDev->SetCollimatorDev(m_pDriCollDev);
- FINFO("Leave CreateDevice COLL");
- return dev;
- }
-
- //else if (index == 2) //------------------------------因为改发生器没有关于机架的信息,所以此处不必创建机架设备的对象
- //{
- // FINFO("Enter CreateDevice Mech");
- // m_pDriMechDev = new OemMechanical(std::shared_ptr<IOEventCenter>(new IOEventCenter()));
- // auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDriMechDev));
- // m_pDriMechDev->SetCtrlDev(m_pDriGenDev);
- // m_pDriGenDev->SetMechDev(m_pDriMechDev);
- // FINFO("Leave CreateDevice Mech");
- // return dev;
- //}
- else if (index == 2)//----------------------------------maybe DAP设备也不是必须的
- {
- FINFO("Enter CreateDevice DAP");
- m_pDriDapDev = new OemDap(std::shared_ptr<IOEventCenter>(new IOEventCenter()));
- auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDriDapDev));
- m_pDriDapDev->SetCtrlDev(m_pDriGenDev);
- m_pDriGenDev->SetDapDev(m_pDriDapDev);
- FINFO("Leave CreateDevice DAP");
- return dev;
- }
- }
- void nsGEN::CPIDriver::FireNotify(int code, std::string key, std::string content)
- {
- EventCenter->OnNotify(code, key, content);
- }
- Log4CPP::Logger* gLogger = nullptr;
- void nsGEN::CPIDriver::Prepare()
- {
- string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Generator\Conf\Log4CPP.Config.GEN.xml)";
- //Log4CPP::ThreadContext::Map::Set("LogFileName", "GEN.CPI");
- Log4CPP::GlobalContext::Map::Set(ECOM::Utility::Hash("LogFileName"), "GEN.CPI");
- auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
- gLogger = Log4CPP::LogManager::GetLogger("GEN.CPI");
- m_SCFDllName = GetConnectDLL(m_ConfigFileName);
- super::Prepare();
- }
- bool DATA_ACTION nsGEN::CPIDriver::Connect()
- {
- ResDataObject Connection = GetConnectParam(m_ConfigFileName);
- FINFO("connections:{$} \n", Connection.encode());
- auto erCode = m_SCF.Connect(Connection.encode(), &nsGEN::CPIDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
- if (erCode != SCF_ERR::SCF_SUCCEED)
- return false;
- auto rc = super::Connect();
- if (!rc)
- return false;
- //return (erCode == SCF_ERR::SCF_SUCCEED);
-
- return true;
- }
- void nsGEN::CPIDriver::Disconnect()
- {
- super::Disconnect();
- m_SCF.Disconnect();
- m_bDemoConnected = false;
- }
- bool nsGEN::CPIDriver::isConnected() const
- {
- return super::isConnected();
- }
- std::string nsGEN::CPIDriver::DriverProbe()
- {
- ResDataObject r_config, HardwareInfo;
- if (r_config.loadFile(m_ConfigFileName.c_str()))
- {
- HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
- HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
- HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
- HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
- HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
- }
- else
- {
- HardwareInfo.add("MajorID", "Generator");
- HardwareInfo.add("MinorID", "Dr");
- HardwareInfo.add("VendorID", "CPI");
- HardwareInfo.add("ProductID", "HF");
- HardwareInfo.add("SerialID", "Drv");
- }
- string ret = HardwareInfo.encode();
- return ret;
- }
- std::string nsGEN::CPIDriver::DeviceProbe()
- {
- ResDataObject r_config, HardwareInfo;
- if (r_config.loadFile(m_ConfigFileName.c_str()))
- {
- HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
- HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
- HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
- HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
- HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
- }
- else
- {
- HardwareInfo.add("MajorID", "Generator");
- HardwareInfo.add("MinorID", "Dr");
- HardwareInfo.add("VendorID", "CPI");
- HardwareInfo.add("ProductID", "HF");
- HardwareInfo.add("SerialID", "Drv");
- }
- string ret = HardwareInfo.encode();
- return ret;
- }
- bool nsGEN::CPIDriver::GetDeviceConfig(std::string& Cfg)
- {
- Cfg = m_DeviceConfigSend.encode();
- //printf("GetDeviceConfig over");
- printf("GetDeviceConfig over , %s", Cfg.c_str());
- return true;
- }
- bool nsGEN::CPIDriver::SetDeviceConfig(std::string Cfg)
- {
- FINFO("--Func-- SetDeviceConfig {$}\n", Cfg.c_str());
- ResDataObject DeviceConfig;
- DeviceConfig.decode(Cfg.c_str());
- ResDataObject DescriptionTempEx;
- DescriptionTempEx = DeviceConfig["DeviceConfig"]["Attribute"];
- FDEBUG("Attribute:{$}", DescriptionTempEx.encode());
- bool bSaveFile = false; //true:重新保存配置文件
- string strAccess = "";
- for (int i = 0; i < DescriptionTempEx.size(); i++)
- {
- string strKey = DescriptionTempEx.GetKey(i);
- FINFO("{$}", strKey.c_str());
- 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);
- }
- return true;
- }
- bool nsGEN::CPIDriver::SaveConfigFile(bool bSendNotify)
- {
- m_ConfigAll["CONFIGURATION"] = m_Configurations;
- bool bRt = m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
- FINFO("SaveConfigFile over {$}", bRt);
- return true;
- }
- bool nsGEN::CPIDriver::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::CPIDriver::SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue)
- {
- string strTemp = pInnerKey;
- FDEBUG("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;
- //if ((strTemp.compare("WSTable") == 0) ||
- // (strTemp.compare("WSWall") == 0) ||
- // (strTemp.compare("WSFree") == 0) ||
- // (strTemp.compare("WSTomo") == 0) ||
- // (strTemp.compare("WSConventional") == 0)
- // )
- //{
- // int sum = (*szValue) + 1;
- // (*resTemp)[strTemp.c_str()] = (char*)(&sum);
- //}
- //else
- // (*resTemp)[strTemp.c_str()] = szValue;
- }
- else
- {
- *resTemp = szValue;
- }
- }
- catch (ResDataObjectExption& e)
- {
- FERROR("SetDriverConfigvalue crashed: {$}", e.what());
- return false;
- }
- }
- return true;
- }
- std::string nsGEN::CPIDriver::GetResource()
- {
- ResDataObject r_config, temp;
- if (!temp.loadFile(m_ConfigFileName.c_str()))
- {
- return "";
- }
- m_ConfigAll = temp;
- r_config = temp["CONFIGURATION"];
- m_Configurations = r_config;
- ResDataObject DescriptionTemp;
- ResDataObject DescriptionSend;
- ResDataObject m_DescriptionSend;
- ResDataObject ListTemp;
- string strTemp = ""; //用于读取字符串配置信息
- string strIndex = ""; //用于读取配置信息中的List项
- int nTemp = -1; //用于读取整型配置信息
- char sstream[10] = { 0 }; //用于转换值
- string strValue = ""; //用于存储配置的值
- string strType = ""; //用于存储配置的类型 int/float/string...
- /***
- * 1. 通过循环,将所有配置项写到pDeviceConfig
- * 2. 记录配置项的内部key以及配置类型,类型对应了不同配置文件路径,用于读写真实值
- ***/
- try
- {
- //便利ConfigToolInfo 中 所有的AttributeInfo 属性段
- int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
- m_pAttribute->clear();
- m_pDescription->clear();
- for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
- {
- DescriptionTemp.clear();
- DescriptionSend.clear();
- ListTemp.clear();
- //AttributeType
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Type"];
- DescriptionTemp.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
- DescriptionSend.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
- strType = strTemp; //记录配置项的类型
- //AttributeKey
- //1. 根据AttributeType,内部key和配置路径,拿到当前的真实值
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
- nTemp = (int)m_Configurations["ConfigToolInfo"][nInfoIndex]["PathID"];
- GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue); //得到strValue的值
- //printf("********************************innerkey=%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
- //2. 赋值
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
- if ("int" == strType)
- {
- (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
- }
- else if ("float" == strType)
- {
- (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
- }
- else //其它先按string类型处理
- {
- (*m_pAttribute).add(strTemp.c_str(), strValue.c_str());
- }
- //printf("********************************outkey =%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
- //AttributeAccess
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Access"];
- DescriptionTemp.add(ConfKey::CcosAccess, strTemp.c_str());
- DescriptionSend.add(ConfKey::CcosAccess, strTemp.c_str());
- /*
- //AttributeRangeMin
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMin"];
- if (strTemp != "") //不需要的配置项为空
- {
- DescriptionTemp.add(ConfKey::CcosRangeMin, strTemp.c_str());
- }
- //AttributeRangeMax
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMax"];
- if (strTemp != "") //不需要的配置项为空
- {
- DescriptionTemp.add(ConfKey::CcosRangeMax, strTemp.c_str());
- }
- */
- //AttributeList
- nTemp = m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListNum"];
- if (nTemp > 0) //ListNum不大于0时说明不需要list配置
- {
- for (int nListIndex = 0; nListIndex < nTemp; nListIndex++)
- {
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListInfo"][nListIndex];
- auto temKey = std::to_string(nListIndex);
- ListTemp.add(temKey.c_str(), strTemp.c_str());
- }
- DescriptionTemp.add(ConfKey::CcosList, ListTemp);
- DescriptionSend.add(ConfKey::CcosList, ListTemp.encode());
- }
- //AttributeRequired
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Required"];
- DescriptionTemp.add(ConfKey::CcosRequired, strTemp.c_str());
- DescriptionSend.add(ConfKey::CcosRequired, strTemp.c_str());
- //AttributeDefaultValue
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["DefaultValue"];
- if (strTemp != "") //不需要的配置项为空
- {
- DescriptionTemp.add(ConfKey::CcosDefaultValue, strTemp.c_str());
- DescriptionSend.add(ConfKey::CcosDefaultValue, strTemp.c_str());
- }
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
- (*m_pDescription).add(strTemp.c_str(), DescriptionTemp);
- m_DescriptionSend.add(strTemp.c_str(), DescriptionSend.encode());
- }
- }
- catch (ResDataObjectExption& e)
- {
- FERROR("Get config error: {$}", e.what());
- return "";
- }
- ResDataObject resDeviceResource;
- resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
- resDeviceResource.add(ConfKey::CcosGeneratorDescription, (*m_pDescription));
- ResDataObject DescriptionTempEx;
- DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
- m_DeviceConfig.clear();
- m_DeviceConfig = DescriptionTempEx;
- FERROR("local ************* get resource over {$}", DescriptionTempEx.encode());
- printf("local ************* get resource over %s \n", DescriptionTempEx.encode());
- resDeviceResource.clear();
- resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
- resDeviceResource.add(ConfKey::CcosGeneratorDescription, m_DescriptionSend);
- DescriptionTempEx.clear();
- DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
- m_DeviceConfigSend.clear();
- m_DeviceConfigSend = DescriptionTempEx;
- string res = m_DeviceConfigSend.encode();
- //printf("%s", res.c_str());
- FDEBUG("get resource over {$}", DescriptionTempEx.encode());
- printf("************* get resource over %s \n", DescriptionTempEx.encode());
- return res;
- }
- void nsGEN::CPIDriver::Dequeue(const char* Packet, DWORD Length)
- {
- DecodeFrame(Packet, Length);
- }
- PACKET_RET nsGEN::CPIDriver::callbackPackageProcess(const char* RecData, DWORD nLength, DWORD& PacketLength)
- {
- if (nLength < 1)
- {
- printf("nLength < 1, nLength==%d \n", nLength);
- FINFO("nLength < 1, nLength=={$} \n", nLength);
- return PACKET_USELESS;
- }
- for (DWORD i = 0; i < nLength - 1; i++)
- {
- //1 首先寻找包头
- if (RecData[i]==0x02)
- {
- if (i!=0)
- {
- PacketLength = i; //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);
- //for test
- //for (int j = 0; j < nLength; j++)
- //{
- // printf("%2X,", RecData[j]);
- //}
- //printf("\n");
- return PACKET_USELESS;
- }
- }
- if (RecData[i] == 0x03)
- {
- PacketLength = i + 2; //+2 because index + ETX + sum.
- char strtemp[100] = { 0 };
- memcpy(strtemp, RecData, i); //RKC005(not include 03 + sum); //only 复制 0x03之前的数据,这样解析时,后面的03 ,sum 都不要了。
- strtemp[PacketLength + 1] = 0;
- printf("==IN==:%s\n", strtemp);
- 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);//此处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;
- }
- //-----------------------------------------------------------------------------
- // GetIODriver & CreateIODriver
- //-----------------------------------------------------------------------------
- static nsGEN::CPIDriver gIODriver;
- extern "C" CCOS::Dev::IODriver * __cdecl GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
- {
- return &gIODriver;
- }
- extern "C" CCOS::Dev::IODriver * __cdecl CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
- {
- return new nsGEN::CPIDriver();
- }
|