1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017 |
- // CCOS.Dev.GEN.VMIMAMMO.cpp : 定义 DLL 应用程序的导出函数。
- //
- //所有jk++的地方,都是不确定,或者需修改的
- #include "stdafx.h"
- #include <assert.h>
- #include <functional>
- using namespace std::placeholders;
- //#include "logger.temp.h"
- #include "CCOS.Dev.Generator.VMIMAMMO.h"
- #include "Helper.JSON.hpp"
- 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
- //-----------------------------------------------------------------------------
- // VMIMAMMODevice
- //-----------------------------------------------------------------------------
- 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::VMIMAMMODevice::VMIMAMMODevice(std::shared_ptr <IOEventCenter> center, nsSCF::SCF SCF) : super(center, SCF)
- {
- assert(EventCenter);
- //CreateLogger("VMIMAMMO");
- mLog::Info("VMIMAMMO ver 3.0.0.18");
- m_DoseUnit.m_KV.reset(new KVMould(0.0, 20.0, 49.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.1, 1000.0, 0.01));
- m_DoseUnit.m_Techmode.reset(new TECHMODEMould(1, 0, 11, 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, 20.0, 49.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.1, 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(4, AttrKey::GENERATOR_STATUS_SHUTDOWN, AttrKey::GENERATOR_STATUS_MAX, 1));
- m_DoseUnit.m_GenTotalExpNumber.reset(new TOTALEXPNUMMould(0, 0, 9999, 1));
- m_DoseUnit.m_GenTotalAcqTimes.reset(new TOTALACQTIMESMould(0, 0, 9999, 1));
- m_DoseUnit.m_GenTubeCoolWaitTimes.reset(new TUBECOOLTIMEMould(0, 0, 9999, 1));
- m_DoseUnit.m_GenTubeOverLoadNumber.reset(new TUBEOVERLOADNUMMould(0, 0, 9999, 1));
- m_DoseUnit.m_GenCurrentExpNumber.reset(new CUREXPNUMMould(0, 0, 9999, 1));
- m_DoseUnit.m_FrameRate.reset(new FRAMERATEMould(0.0, 0.0, 16.0, 1.0));
- m_DoseUnit.m_ExpMode.reset(new EXPMODEMould(nsGEN::AttrKey::EXPMODE_TYPE::Single));
- m_DoseUnit.m_FLMode.reset(new FLUModeMould(nsGEN::AttrKey::GENERATOR_FLUMode::GENERATOR_FLMODE_NOTFLU));
- m_DoseUnit.m_EXAMMode.reset(new EXAMMODEMould(AttrKey::EXAMMODE_TYPE::MANUAL));
- m_DoseUnit.m_TubeTargetMaterial.reset(new TUBETARGETMATERIALMould(AttrKey::TUBETARGETMATERIAL_TYPE::MO));
- m_DoseUnit.m_TubeAngle.reset(new TUBEANGLEMould(0,0,360,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_hGenPostEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
- m_pHardwareStatusThread = NULL;
- m_SettingExamMode = AttrKey::EXAMMODE_TYPE::MANUAL; //default is Manual
- OnCallBack();
- Register();
- Reset();
- HWSend("RR?");
-
- m_bRREnable = true;
- m_strPreWKStatus = "WK0";
- //启动定时器,定时查询
- StartHardwareStatusThread();
- }
- nsGEN::VMIMAMMODevice::~VMIMAMMODevice()
- {
- CloseHandle(m_hGenPostEvent);
- }
- std::string nsGEN::VMIMAMMODevice::GetGUID() const
- {
- mLog::Info("\n===============GetGUID : {$} ===================\n", GeneratorUnitType);
- return GeneratorUnitType;
- }
- void nsGEN::VMIMAMMODevice::Register()
- {
- auto Disp = &Dispatch;
- superGen::Register(Disp);
- superGen::RegisterRAD(Disp);
- superGen::RegisterAEC(Disp);
- superGen::RegisterExpEnable(Disp);
- superGen::RegisterGeneratortoSyncStatus(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);
- auto fun_EnterExam = [this](auto a, auto& b)
- {
- return EnterExam();
- };
- Disp->Action.Push("EnterExam", fun_EnterExam);
- auto fun_ExitExam = [this](auto a, auto& b)
- {
- return ExitExam();
- };
- Disp->Action.Push("ExitExam", fun_ExitExam);
- }
- RET_STATUS nsGEN::VMIMAMMODevice::IncKV()
- {
- if (!m_DoseUnit.m_KV->CanInc()) return RET_STATUS::RET_SUCCEED;
- return HWSend("IV01");
- }
- RET_STATUS nsGEN::VMIMAMMODevice::DecKV()
- {
- if (!m_DoseUnit.m_KV->CanDec()) return RET_STATUS::RET_SUCCEED;
- return HWSend("DV01");
- }
- RET_STATUS nsGEN::VMIMAMMODevice::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::VMIMAMMODevice::IncMA()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::DecMA()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::SetMA(float value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::IncMS()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::DecMS()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::SetMS(float value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::IncMAS()
- {
- if (!m_DoseUnit.m_MAS->CanInc()) return RET_STATUS::RET_SUCCEED;
-
- return HWSend("IS01");
- }
- RET_STATUS nsGEN::VMIMAMMODevice::DecMAS()
- {
- if (!m_DoseUnit.m_MAS->CanDec()) return RET_STATUS::RET_SUCCEED;
- return HWSend("DS01");
- }
- RET_STATUS nsGEN::VMIMAMMODevice::SetMAS(float value)
- {
- if (!m_DoseUnit.m_MAS->Verify(value)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- sprintf_s(temp, "MX%03d", (int)(value * 10));
- return HWSend(temp);
- }
- RET_STATUS nsGEN::VMIMAMMODevice::SetTechmode(int value)
- {
- mLog::Info("\n SetTechmode = {$}\n", value);
- if (!m_DoseUnit.m_Techmode->Verify(value)) return RET_STATUS::RET_SUCCEED;
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::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::VMIMAMMODevice::SetAECDensity(int value)
- {
- return RET_STATUS::RET_SUCCEED;//jk++
- 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 };
- sprintf_s(temp, "AD%02d", (int)value);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::VMIMAMMODevice::SetAECField(int value)
- {
- return RET_STATUS::RET_SUCCEED;//jk++
- }
- RET_STATUS nsGEN::VMIMAMMODevice::SetAECFilm(int value)
- {
- return RET_STATUS::RET_SUCCEED;//jk++
- }
- RET_STATUS nsGEN::VMIMAMMODevice::SetWS(const string value)
- {
- return RET_STATUS::RET_SUCCEED;//jk++
- }
- RET_STATUS nsGEN::VMIMAMMODevice::SetAPR(const _tAPRArgs& t)
- {
- m_t = t;
- m_DoseUnit.m_KV->Update(m_t.fKV);
- m_DoseUnit.m_MAS->Update(m_t.fMAS);
- m_DoseUnit.m_Focus->Update(m_t.nFocus);
- mLog::Info("Enter SetAPR,do nothing");
-
- mLog::Info("t.fKV={$},t.fMA={$},t.fMAS={$},t.nAECDensity={$},t.nAECField={$},t.nAECFilm={$},t.nFocus={$},t.nTechmode={$}", t.fKV, t.fMA, t.fMAS, t.nAECDensity, t.nAECField, t.nAECFilm, t.nFocus, t.nTechmode);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::QueryHE(int& value)
- {
- value = m_DoseUnit.m_HE->Get();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::QueryPostKV(float& value)
- {
- value = m_DoseUnit.m_KV->Get();
- mLog::Info("jk++:QueryPostKV= {$}",value);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::QueryPostMA(float& value)
- {
- value = m_DoseUnit.m_PostMA->Get(); //postMA默认是0.上层查询时,就取0.
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::QueryPostMS(float& value)
- {
- value = m_DoseUnit.m_PostMS->Get();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::QueryPostMAS(float& value)
- {
- value = m_DoseUnit.m_PostMAS->Get();
- mLog::Info("jk++:QueryPostMAS= {$}", value);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::QueryDAP()
- {
- mLog::Info("jk++:QueryDAP");
- return HWSend("AG?");
- }
- RET_STATUS nsGEN::VMIMAMMODevice::Clear_DAP()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::GetValue_DAP(float& value)
- {
- value = m_DAP->Get();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::StartMove()
- {
- mLog::Info("Enter startMove do nothing");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::EndMove()
- {
- mLog::Info("Enter endmove do nothing");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::EnterExam()
- {
- HWSend("EXB1");
- return RET_STATUS::RET_SUCCEED;
- }
- /*有的时候,exitexam并不会执行*/
- RET_STATUS nsGEN::VMIMAMMODevice::ExitExam()
- {
- HWSend("EXB0");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::SetGenSynState(int value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::SetGenState(int value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::SetExpMode(std::string value)
- {
- mLog::Info("Enter SetExpMode:{$},m_strPreWKStatus={$}",value, m_strPreWKStatus.c_str());
- m_DoseUnit.m_ExpMode->Update(value);
-
- if (m_DoseUnit.m_ExpMode->JSGet() == AttrKey::EXPMODE_TYPE::TOMO)
- {
- if (m_strPreWKStatus != "WK1")
- {
- HWSend("WK1");
- }
- }
- else
- {
- if (m_strPreWKStatus != "WK0")
- {
- HWSend("WK0");
- }
- }
- //必发,有点多余,但是可以防止设置WK返回错误ET值的问题
- if (m_SettingExamMode != m_DoseUnit.m_EXAMMode->JSGet())
- {
- mLog::Info("m_SettingExamMode={$}, m_DoseUnit.m_EXAMMode->JSGet()={$}", m_SettingExamMode, m_DoseUnit.m_EXAMMode->JSGet().c_str());
- if (m_SettingExamMode == AttrKey::EXAMMODE_TYPE::MANUAL)
- {
- HWSend("ET2");
- }
- else if (m_SettingExamMode == AttrKey::EXAMMODE_TYPE::SEMIAUTO)
- {
- HWSend("ET1");
- }
- else if (m_SettingExamMode == AttrKey::EXAMMODE_TYPE::AUTOMATIC)
- {
- HWSend("ET0");
- }
- }
- //SetKV(m_DoseUnit.m_KV->Get());
- //SetMAS(m_DoseUnit.m_MAS->Get());
- //SetFocus(m_DoseUnit.m_Focus->Get());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::SetFLFMode(std::string value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- /*由于发送WK指令,偶尔会返回错误的ET值,故在setexpmode中,发送WK的时候,主动发送ET2,后续不能固定,
- 需要再SetEXAMMode中,记录上层传入的exammode,然后在setexpmode中,再次设定。
- 需要确认,当手动切换至auto或semi时,退出,重进检查,此时exammode会不会冲突。
- */
- RET_STATUS nsGEN::VMIMAMMODevice::SetEXAMMode(std::string value)
- {
- //上层给我设置exam mode。(manual semi atuo)对应(2 1 0),
- mLog::Info("\nEnter setexammode func value = {$}\n", value);
- m_SettingExamMode = value;
- if (value == AttrKey::EXAMMODE_TYPE::MANUAL)
- {
- HWSend("ET2");
- }
- else if (value == AttrKey::EXAMMODE_TYPE::SEMIAUTO)
- {
- HWSend("ET1");
- }
- else if (value == AttrKey::EXAMMODE_TYPE::AUTOMATIC)
- {
- HWSend("ET0");
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::SetFrameRate(FLOAT frameRate)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::SetRPS(int rps)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::RefreshData()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::SetExpEnable()
- {
- return HWSend("EXB1");
- }
- RET_STATUS nsGEN::VMIMAMMODevice::SetExpDisable()
- {
- return HWSend("EXB0");
- }
- RET_STATUS nsGEN::VMIMAMMODevice::Reset()
- {
- return HWSend("RE");
- }
- RET_STATUS nsGEN::VMIMAMMODevice::SetFilter(int nFilterType)
- {
- char temp[50]{ 0 };
- switch (nFilterType)
- {
- case 0:
- case 4:
- HWSend("FT0");
- break;
- case 1:
- case 5:
- HWSend("FT1");
- break;
- case 2:
- HWSend("FT2");
- break;
- default:
- break;
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::SetMammoDensity(int unMDensity)
- {
- char temp[50]{ 0 };
- sprintf_s(temp, "DE%01d", unMDensity);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::VMIMAMMODevice::SetCollimatorDev(OemCollimator* dev)
- {
- if (dev)
- m_pCollDev.reset(dev);
-
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::SetMechDev(OemMechanical* dev)
- {
- if (dev)
- m_pMechDev.reset(dev);
-
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::SetDapDev(OemDap* dev)
- {
- if(dev)
- m_pDapDev.reset(dev);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::HWSend(char* strCommand, int nTimeOut)
- {
- if (!m_SCF) return RET_STATUS::RET_FAILED;
- unsigned char strSendCommand[100] = { 0 };
- int len = strlen(strCommand);
- int tmpSum = 0;
- for (int i = 0; i < len; i++)
- {
- tmpSum += (int)strCommand[i];
- }
- unsigned char checkSum = unsigned char(tmpSum + 3);
-
- memcpy(strSendCommand, strCommand, len);
- strSendCommand[len] = 0x03;
- strSendCommand[len + 1] = checkSum;
- mLog::Info("==OUT==: {$} \n", strSendCommand);
- int retLength;
- m_SCF.Lock(msTimeOut_Lock)
- .SendPacket((char*)strSendCommand, strlen((char*)strSendCommand), nTimeOut, retLength);
- Sleep(nTimeOut);
-
- return RET_STATUS::RET_SUCCEED;
- }
- //-----------------------------------------------------------------------------
- // ProcessCmd
- //-----------------------------------------------------------------------------
- void nsGEN::VMIMAMMODevice::FireNotify(std::string key, std::string content)
- {
- EventCenter->OnNotify(1, key, content);
- }
- struct tFrameMapping
- {
- static const int MaxLen = 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);
- 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);
- void nsGEN::VMIMAMMODevice::OnCallBack()
- {
- auto HWNotProcess = [](const char* value, int length) -> void
- {
- mLog::Info("\n This commands didn't need to process!\n");
- };
- auto HWKV = [this](const char* value, int length) -> void
- {
- mLog::Info("\n recv KV={$},m_DoseUnit.m_KV={$}\n", atoi(value), m_DoseUnit.m_KV->JSGet().c_str());
- 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_MAS->Update(fmas))
- FireNotify(AttrKey::MAS, m_DoseUnit.m_MAS->JSGet()); //无论mas是否更新,都主动notify。
-
- };
- auto HWMA = [this](const char* value, int length)
- {
- assert(value);
- float fma = atof(value) / 100.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) / 100.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);
- std::string strCurrentET = AttrKey::EXAMMODE_TYPE::MANUAL;
- if (2 == atoi(value))
- {
- strCurrentET = AttrKey::EXAMMODE_TYPE::MANUAL;
- }
- else if (1 == atoi(value))
- {
- strCurrentET = AttrKey::EXAMMODE_TYPE::SEMIAUTO;
- }
- else if (0 == atoi(value))
- {
- strCurrentET = AttrKey::EXAMMODE_TYPE::AUTOMATIC;
- }
- if (m_DoseUnit.m_EXAMMode->Update(strCurrentET))
- FireNotify(AttrKey::EXAMMODE, m_DoseUnit.m_EXAMMode->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);
- 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)
- {
-
- };
- auto HWXR = [this](const char* value, int length)
- {
-
- };
- auto HWAPDOSE = [this](const char* value, int length)//mas
- {
- assert(value);
- if(m_DoseUnit.m_PostMAS->Update(atof(value) / 1000.0))
- FireNotify(m_DoseUnit.m_PostMAS->GetKey(), m_DoseUnit.m_PostMAS->JSGet());
- float fMS = atof(value) / m_DoseUnit.m_MA->Get();
- if (m_DoseUnit.m_PostMS->Update(fMS))
- FireNotify(m_DoseUnit.m_PostMS->GetKey(), m_DoseUnit.m_PostMS->JSGet());
- mLog::Info("\n post MAS={$} postMS={$}\n", m_DoseUnit.m_PostMAS->Get(), m_DoseUnit.m_PostMS->Get());
- };
- auto HWATDOSE = [this](const char* value, int length)
- {
- assert(value);
- if(m_DoseUnit.m_PostMS->Update(atof(value)))
- FireNotify(m_DoseUnit.m_PostMS->GetKey(), m_DoseUnit.m_PostMS->JSGet());
- };
- //note: AG<0000> 并不是dap的意思,是计量的意思
- auto HWAG = [this](const char* value, int length)
- {
- assert(value);
- if (m_pMechDev)
- {
- m_pMechDev->UpdateMammo_AGD(atof(value) / 10000.0);
- }
- };
- auto HWGS = [this](const char* value, int length)
- {
- assert(value);
- switch (atoi(value))
- {
- case 0:
- {
- if (this->m_bInExposurePeriod)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF); //pr0
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- this->m_bInExposurePeriod = false;
- }
- break;
- case 1:
- {
- if (this->m_bInExposurePeriod)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF); //pr0
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- mLog::Info("\n recv GS1 ,and send GENERATOR_RAD_OFF out \n");
- }
- this->m_bInExposurePeriod = false;
- //char ErrorCode[10]{ "" };
- //sprintf_s(ErrorCode, "VMIMAMMO_GS_%d", 1);
- //int level = 1;
- //m_MSGUnit->AddWarnMessage(ErrorCode, level, "");
- }
- break;
- case 2:
- {
- if (!this->m_bInExposurePeriod)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_PREPARE); //pr1
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_READY); //pr2
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- this->m_bInExposurePeriod = true;
- }
- break;
- case 3:
- {
- if (this->m_bInExposurePeriod)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF); //pr0
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- mLog::Info("\n recv GS3 ,and send GENERATOR_RAD_OFF out \n");
- }
- this->m_bInExposurePeriod = false;
- //char ErrorCode[100]{ "" };
- //sprintf_s(ErrorCode, "Generator Blocked VMIMAMMO_GS_%d", 3);
- //int level = 1;
- //m_MSGUnit->AddWarnMessage(ErrorCode, level, "");
- }
- break;
- default:
- break;
- }
- };
- auto HWST = [this](const char* value, int length)
- {
- assert(value);
- switch (atoi(value))
- {
- case 4:
- {
- //读取配置文件,软同步or直连时,
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON); //xr1
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- this->m_bInExposurePeriod = true;
- #if 1
- //send post param
- m_DoseUnit.m_PostMAS->Update(m_DoseUnit.m_MAS->Get());
- FireNotify(m_DoseUnit.m_PostMAS->GetKey(), m_DoseUnit.m_PostMAS->JSGet());
- mLog::Info("\n recv ST4 post MAS={$}\n", m_DoseUnit.m_PostMAS->Get());
- mLog::Info("\n recv ST4 m_MAS={$}\n", m_DoseUnit.m_MAS->Get());
- //send post kv
- m_DoseUnit.m_PostKV->Update(m_DoseUnit.m_KV->Get());
- FireNotify(m_DoseUnit.m_PostKV->GetKey(), m_DoseUnit.m_PostKV->JSGet());
- mLog::Info("\n recv ST4 postkv={$},\n", m_DoseUnit.m_PostKV->Get());
- mLog::Info("\n recv ST4 kv={$},\n", m_DoseUnit.m_KV->Get());
- #endif // 0
- }
- break;
- case 5:
- {
- if (this->m_bInExposurePeriod)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYOFF); //xr0
- #if 0
- //send post param
- m_DoseUnit.m_PostMAS->Update(m_DoseUnit.m_MAS->Get());
- FireNotify(m_DoseUnit.m_PostMAS->GetKey(), m_DoseUnit.m_PostMAS->JSGet());
- mLog::Info("\n recv ST5 post MAS={$}\n", m_DoseUnit.m_PostMAS->Get());
- mLog::Info("\n recv ST5 m_MAS={$}\n", m_DoseUnit.m_MAS->Get());
-
- //send post kv
- m_DoseUnit.m_PostKV->Update(m_DoseUnit.m_KV->Get());
- FireNotify(m_DoseUnit.m_PostKV->GetKey(), m_DoseUnit.m_PostKV->JSGet());
- mLog::Info("\n recv ST5 postkv={$},\n", m_DoseUnit.m_PostKV->Get());
- mLog::Info("\n recv ST5 kv={$},\n", m_DoseUnit.m_KV->Get());
- #endif // 0
- }
- this->m_bInExposurePeriod = false;
- }
- break;
- default:
- break;
- }
- };
- auto HWERROR = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- if (nValue != 0)
- {
- char ErrorCode[10]{ "" };
- sprintf_s(ErrorCode, "VMIMAMMO_ERR_%d", nValue);
- int level = 1;
- m_MSGUnit->AddErrorMessage(ErrorCode, level, ErrorCode);
- m_localErrorlist.push_back(ErrorCode);
- }
- else
- {
- int level = 1;
- //char ErrorCode[10]{ "" };
- //m_MSGUnit->DelErrorMessage(ErrorCode, level, "");
- for (auto errorStr : m_localErrorlist)
- {
- m_MSGUnit->DelErrorMessage(errorStr.c_str(), level, "");
- mLog::Info("clear error = {$}\n", errorStr);
- }
- m_localErrorlist.clear();
- }
- };
- auto HWWARN = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- if (nValue != 0)
- {
- char WarnCode[100]{ "" };
- sprintf_s(WarnCode, "VMIMAMMO_WARN_%d", nValue);
- int level = 1;
- m_MSGUnit->AddWarnMessage(WarnCode, level, WarnCode);
- mLog::Info("\n recv WN? ,and AddWarnMessage \n");
- m_localWarnlist.push_back(WarnCode);
- }
- else
- {
- int level = 1;
- //char WarnCode[100]{ "" };
- //m_MSGUnit->DelWarnMessage(WarnCode, level, "");
- //mLog::Info("\n recv WN0 ,and DelWarnMessage \n");
- for (auto warnStr : m_localWarnlist)
- {
- m_MSGUnit->DelWarnMessage(warnStr.c_str(), level, "");
- mLog::Info("clear warn = {$}\n", warnStr);
- }
- m_localWarnlist.clear();
- }
- };
- auto HWRE = [this](const char* value, int length) -> void
- {
- assert(value);
- int nValue = atoi(value);
- if (nValue == 1) //reset success
- {
- int level = 1;
- for (auto errorStr : m_localErrorlist)
- {
- m_MSGUnit->DelErrorMessage(errorStr.c_str(), level, "");
- mLog::Info("clear error = {$}\n", errorStr);
- }
- m_localErrorlist.clear();
- //char WarnCode[10]{ "" };
- //m_MSGUnit->DelErrorMessage(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());
- };
- //当前认为TGA就是球馆角度
- auto HWTG = [this](const char* value, int length)
- {
- assert(value);
- int tempnum = atoi(value);
- int nExpIndex = tempnum / 100000;
- int nSign = (tempnum % 100000) / 10000;
- int Angle = tempnum % 10000;
- if (nSign == 0)
- {
- Angle = Angle * -1;
- }
- float fAngle = (float)Angle;
- m_resultAngle_tmp.clear();
- char Key[4] = { 0 };
- sprintf_s(Key, "%d", nExpIndex);
- m_resultAngle_tmp.add(Key, fAngle / 10.0f);
- if (m_pMechDev)
- {
- GetTomoResults(m_resultAngle_tmp, m_resultAngle_tmp);
- }
- if (m_DoseUnit.m_TubeAngle->Update(fAngle/10))
- {
- FireNotify(m_DoseUnit.m_TubeAngle->GetKey(), m_DoseUnit.m_TubeAngle->JSGet());
- }
- };
- auto HWFS = [this](const char* value, int length) -> void
- {
- assert(value);
- if (length == 8)
- {
- int number = atoi(value); //aaabbb
- int xsize = number % 1000/10; //bbb -->转为cm
- int ysize = number / 1000/10; //aaa -->转为cm
- if (m_pCollDev)
- {
- m_pCollDev->UpdateCollimatorXSize(xsize);
- m_pCollDev->UpdateCollimatorYSize(ysize);
- }
- }
- };
- auto HWFY = [this](const char* value, int length) -> void
- {
- assert(value);
- //if (m_pCollDev)
- // m_pCollDev->UpdateCollimatorFilter(atoi(value));
- };
- auto HWWK = [this](const char* value, int length) -> void
- {
- assert(value);
- if (0 == atoi(value))
- {
- m_strPreWKStatus = "WK0";
- }
- else if (1 == atoi(value))
- {
- m_strPreWKStatus = "WK1";
- }
- };
- auto HWMG = [this](const char* value, int length) -> void
- {
- assert(value);
- int temp = atoi(value);
- float _fMag;
- if (2 == temp)
- {
- _fMag = 1.8f;
- }
- else if (1 == temp)
- {
- _fMag = 1.5f;
- }
- else
- {
- _fMag = 1.0f;
- }
-
- if (m_pMechDev)
- {
- m_pMechDev->UpdateMammo_MAG(_fMag);
- mLog::Info("\n get mag ={$}\n", _fMag);
- }
- else
- {
- mLog::Info("\n get mag ={$},but mechdev is null,so not send out.!!!!\n", _fMag);
- }
- };
- //UpdateMammo_CompressPaddle
- //关于压迫板信息,gen应该能收到相关信息,解析后,更新 UpdateMammo_CompressPaddle 属性,这样上层可以收到。
- auto HWMT = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- int direction = nValue / 1000;
- float angle = nValue % 1000;
- if (direction == 1)
- {
- angle = -1 * angle;
- }
- if (m_pMechDev)
- m_pMechDev->UpdateMammo_MechAngle(angle);
- };
- //原code中,PE 有两个含义。
- auto HWPE = [this](const char* value, int length) -> void
- {
- assert(value);
- if (m_pMechDev)
- m_pMechDev->UpdateMammo_PressureState(atoi(value));
- //GEN_PARAM_MAMMO_MAMMMECHNICALHEIGH
- if (m_pMechDev)
- m_pMechDev->UpdateMammo_MechHeight(atof(value));
- };
- auto HWPF = [this](const char* value, int length) -> void
- {
- assert(value);
- if (m_pMechDev)
- m_pMechDev->UpdateMammo_PressureValue(atof(value));
- };
- auto HWFT = [this](const char* value, int length) -> void
- {
- assert(value);
- if (m_pMechDev)
- {
- /*补充一项对应关系:(0--4,收到FT0,转为4,发给上层。),(1--5),(2--2,不变 发给上层)*/
- int nFilterType = atoi(value);
- if (0 == nFilterType)
- {
- m_pMechDev->UpdateMammo_FT(4);
- }
- else if (1 == nFilterType)
- {
- m_pMechDev->UpdateMammo_FT(5);
- }
- else if (2 == nFilterType)
- {
- m_pMechDev->UpdateMammo_FT(5);
- }
- }
- if (m_pCollDev)
- {
- /*补充一项对应关系:(0--4,收到FT0,转为4,发给上层。),(1--5),(2--2 不变, 发给上层)*/
- int nFilterType = atoi(value);
- if (0 == nFilterType)
- {
- m_pCollDev->UpdateCollimatorFilter(4);
- }
- else if (1 == nFilterType)
- {
- m_pCollDev->UpdateCollimatorFilter(5);
- }
- else if (2 == nFilterType)
- {
- m_pCollDev->UpdateCollimatorFilter(5);
- }
- }
- };
- auto HWGR = [this](const char* value, int length) -> void
- {
- assert(value);
- if (m_pMechDev)
- m_pMechDev->UpdateGrid(atoi(value));
- };
- auto HWDF = [this](const char* value, int length) -> void
- {
- assert(value);
-
- if (m_pMechDev)
- m_pMechDev->UpdateMammo_Depress(atoi(value));
- };
- // 有部分前缀是包含关系, 长的包含短的, 例如 KVS 包含了 KV.
- // 因此长的在前面, 短的在后面
- // !!! Device 是个短寿命对象, 而 arFrame 是静态变量 !!!
- // !!! 因此, 在添加到 arFrame 之前, 务必先清零 !!!
- arFrame.clear();
- arFrame.push_back(tFrameMapping("WK", 2, HWWK));
- arFrame.push_back(tFrameMapping("KV", 2, HWKV));
- arFrame.push_back(tFrameMapping("MX", 2, HWMAS));
- arFrame.push_back(tFrameMapping("ET", 2, HWTechmode));
- arFrame.push_back(tFrameMapping("FO", 2, HWFocus));
- arFrame.push_back(tFrameMapping("AD", 2, HWAECDensity));
- arFrame.push_back(tFrameMapping("AG", 2, HWAG));
- arFrame.push_back(tFrameMapping("GS", 2, HWGS));
- arFrame.push_back(tFrameMapping("MT", 2, HWMT));
- //MG -- 2 1 0 对应 1.8 1.5 1.0 ,GEN_PARAM_MAMMO_MAG 发送后者给上层
- arFrame.push_back(tFrameMapping("MG", 2, HWMG));
- arFrame.push_back(tFrameMapping("FY", 2, HWFY));//不知道何意
- arFrame.push_back(tFrameMapping("PE", 2, HWPE));
- arFrame.push_back(tFrameMapping("PF", 2, HWPF));
- arFrame.push_back(tFrameMapping("FT", 2, HWFT));
- //FS -- 得到 长和宽 。(不知道啥啥的)
- arFrame.push_back(tFrameMapping("FS", 2, HWFS));
- arFrame.push_back(tFrameMapping("GR", 2, HWGR));
- arFrame.push_back(tFrameMapping("DF", 2, HWDF));
- arFrame.push_back(tFrameMapping("ST", 2, HWST));
- arFrame.push_back(tFrameMapping("ERR", 3, HWERROR)); //==IN==:ERR003 客户反馈的log中第一次遇见
- arFrame.push_back(tFrameMapping("WN", 2, HWWARN));
- arFrame.push_back(tFrameMapping("HE", 2, HWEHE));
- arFrame.push_back(tFrameMapping("TGA",3, HWTG));
- arFrame.push_back(tFrameMapping("RE", 2, HWRE));
- }
- bool nsGEN::VMIMAMMODevice::StartHardwareStatusThread()
- {
- mLog::Info("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)
- {
- mLog::Fatal("Start HardwareStatus Thread Failed");
- return false;
- }
- }
- return true;
- }
- DWORD nsGEN::VMIMAMMODevice::HardwareStatusThread(LPVOID pParam)
- {
- VMIMAMMODevice* pCurGen = (VMIMAMMODevice*)pParam;
- if (pCurGen == NULL)
- {
- return false;
- }
- mLog::Info("HardwareStatusThread start");
-
- while (true)
- {
- if (pCurGen->m_bRREnable)
- {
- Sleep(1000);
- pCurGen->HWSend("RR?"); //延迟发送,是因为,当时gen下面的设备还没创建完毕。但是也不能延迟太久,因为进入检查之前 最好能得到WK的状态。
- pCurGen->m_bRREnable = false;
- }
- else
- {
- Sleep(2000);
- pCurGen->HWSend("HE?");
- //pCurGen->m_bRREnable = true;
- }
- }
- mLog::Info("HardwareStatusThread stop");
- return true;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::SelectPP(int nPostionID)
- {
- char temp[50] = { 0 };
- sprintf_s(temp, "PO%01d", nPostionID);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::VMIMAMMODevice::SetNeedleBiopsyEnable(unsigned int unNBEnable)
- {
- char temp[50] = { 0 };
- sprintf_s(temp, "NB%01d", unNBEnable);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::VMIMAMMODevice::SetNeedleBiopsyDepth(unsigned int unNBDepth)
- {
- char temp[50] = { 0 };
- sprintf_s(temp, "ND%01d", unNBDepth);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::VMIMAMMODevice::SetGrid(int nGridType)
- {
- char temp[50] = { 0 };
- sprintf_s(temp, "GR%02d", nGridType);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::VMIMAMMODevice::SetCollimatorSize(int xsize, int ysize)
- {
- char temp[50] = { 0 };
- sprintf_s(temp, "FS%03d%03d", xsize * 10, ysize * 10);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::VMIMAMMODevice::SetCollimatorLight(WORD pParams)
- {
- //此处应该发送指令给GEN,并且该指令可以控制 coll 的LED。
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::VMIMAMMODevice::SetAutoTracking(int nAutoTracking)
- {
- char temp[50] = { 0 };
- sprintf_s(temp, "DF%d", nAutoTracking);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::VMIMAMMODevice::GetTomoResults(ResDataObject& resultAngle, ResDataObject& resultHeight)
- {
- RET_STATUS ret = RET_STATUS::RET_SUCCEED;
- if (resultAngle.size() == 1 && resultHeight.size() == 1)
- {
- m_resultAngle.update(resultAngle.GetKey(0), (float)resultAngle[0]);
- mLog::Info("GetTomoResults insert, key={$},value={$}",resultAngle.GetKey(0), (float)resultAngle[0]);
- }
- else
- {
- mLog::Info("GetTomoResults size={$}", m_resultAngle.size());
- for (int i = 0; i < m_resultAngle.size(); i++)
- {
- resultAngle.update(m_resultAngle.GetKey(i), (float)m_resultAngle[i]);
- mLog::Info("GetTomoResults ket={$} ,resule={$}", m_resultAngle.GetKey(i), (float)m_resultAngle[i]);
- }
- resultHeight.update("0", 63.71);
- resultHeight.update("1", 63.97);
- resultHeight.update("2", 64.21);
- resultHeight.update("3", 64.41);
- resultHeight.update("4", 64.59);
- resultHeight.update("5", 64.73);
- resultHeight.update("6", 64.84);
- resultHeight.update("7", 64.92);
- resultHeight.update("8", 64.97);
- resultHeight.update("9", 64.99);
- resultHeight.update("10", 64.98);
- resultHeight.update("11", 64.94);
- resultHeight.update("12", 64.87);
- resultHeight.update("13", 64.72);
- resultHeight.update("14", 64.63);
- resultHeight.update("15", 64.47);
- resultHeight.update("16", 64.28);
- resultHeight.update("17", 64.05);
- m_resultAngle.clear();
- }
- return ret;
- }
- //-----------------------------------------------------------------------------
- // VMIMAMMODriver
- //-----------------------------------------------------------------------------
- nsGEN::VMIMAMMODriver::VMIMAMMODriver()
- {
- m_pDriGenDev = nullptr;
- m_pDriCollDev = nullptr;
- m_pDriMechDev = nullptr;
- m_pDriDapDev = nullptr;
- m_bDemoConnected = false;
- m_pAttribute.reset(new ResDataObject());
- m_pDescription.reset(new ResDataObject());
- }
- nsGEN::VMIMAMMODriver::~VMIMAMMODriver()
- {
- if (m_pDriGenDev)
- {
- delete m_pDriGenDev;
- m_pDriGenDev = nullptr;
- }
- if (m_pDriCollDev)
- {
- delete m_pDriCollDev;
- m_pDriCollDev = nullptr;
- }
- if (m_pDriMechDev)
- {
- delete m_pDriMechDev;
- m_pDriMechDev = nullptr;
- }
- if (m_pDriDapDev)
- {
- delete m_pDriDapDev;
- m_pDriDapDev = nullptr;
- }
- }
- auto nsGEN::VMIMAMMODriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
- {
- mLog::Info("Enter CreateDevice, index={$}", index);
-
- if (!m_SCF.isConnected())
- return nullptr;
-
- if (index == 0)
- {
- m_pDriGenDev = new VMIMAMMODevice(EventCenter, m_SCF);
- auto dev = std::unique_ptr<IODevice>(new IODevice(m_pDriGenDev));
- return dev;
-
- }
- else if (index == 1)
- {
- mLog::Info("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);
- mLog::Info("Leave CreateDevice COLL");
- return dev;
- }
- else if (index == 2)
- {
- mLog::Info("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);
- mLog::Info("Leave CreateDevice Mech");
- return dev;
- }
- else if (index == 3)
- {
- mLog::Info("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);
- mLog::Info("Leave CreateDevice DAP");
- return dev;
- }
-
- }
- void nsGEN::VMIMAMMODriver::FireNotify(int code, std::string key, std::string content)
- {
- EventCenter->OnNotify(code, key, content);
- }
- Log4CPP::Logger* mLog::gLogger = nullptr;
- void nsGEN::VMIMAMMODriver::Prepare()
- {
- string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Generator\Conf\Log4CPP.Config.GEN.xml)";
- //Log4CPP::ThreadContext::Map::Set("LogFileName", "GEN.VMIMAMMO");
- Log4CPP::GlobalContext::Map::Set(ECOM::Utility::Hash("LogFileName"), "GEN.PSG_MG");
- auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
- mLog::gLogger = Log4CPP::LogManager::GetLogger("GEN.VMIMAMMO");
-
- m_SCFDllName = GetConnectDLL(m_ConfigFileName);
- super::Prepare();
- }
- bool DATA_ACTION nsGEN::VMIMAMMODriver::Connect()
- {
- ResDataObject Connection = GetConnectParam(m_ConfigFileName);
- mLog::Info("connections:{$} \n", Connection.encode());
- auto erCode = m_SCF.Connect(Connection.encode(), &nsGEN::VMIMAMMODriver::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::VMIMAMMODriver::Disconnect()
- {
- super::Disconnect();
- m_SCF.Disconnect();
- m_bDemoConnected = false;
- }
- bool nsGEN::VMIMAMMODriver::isConnected() const
- {
- return super::isConnected();
- }
- std::string nsGEN::VMIMAMMODriver::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", "VMIMAMMO");
- HardwareInfo.add("ProductID", "HF");
- HardwareInfo.add("SerialID", "Drv");
- }
- string ret = HardwareInfo.encode();
- return ret;
- }
- /*
- std::string nsGEN::VMIMAMMODriver::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();
- mLog::Info("resDeviceResource :{$} \n", resDeviceResource.encode());
- return res;
- }
- */
- bool nsGEN::VMIMAMMODriver::GetDeviceConfig(std::string& Cfg)
- {
- Cfg = m_DeviceConfigSend.encode();
- printf("GetDeviceConfig over , %s", Cfg.c_str());
- return true;
- }
- bool nsGEN::VMIMAMMODriver::SetDeviceConfig(std::string Cfg)
- {
- mLog::Info("--Func-- SetDeviceConfig {$}\n", Cfg.c_str());
- printf("\n--Func-- SetDeviceConfig %s\n", Cfg.c_str());
- ResDataObject DeviceConfig;
- DeviceConfig.decode(Cfg.c_str());
- ResDataObject DescriptionTempEx;
- DescriptionTempEx = DeviceConfig["DeviceConfig"]["Attribute"];
- mLog::Debug("Attribute:{$}", DescriptionTempEx.encode());
- bool bSaveFile = false; //true:重新保存配置文件
- string strAccess = "";
- for (int i = 0; i < DescriptionTempEx.size(); i++)
- {
- string strKey = DescriptionTempEx.GetKey(i);
- mLog::Info("{$}", strKey.c_str());
- printf("%s\n", strKey.c_str());
- try
- {
- if (m_pAttribute->GetFirstOf(strKey.c_str()) >= 0)
- {
- strAccess = (string)(*m_pDescription)[strKey.c_str()]["Access"];
- if ("RW" == strAccess)
- {
- //修改对应配置,在其他单元的配置项要同时调用其修改函数修改真实值
- //1. 修改内存中的值,用于给上层发消息
- (*m_pAttribute)[strKey.c_str()] = DescriptionTempEx[i];
- //2. 拿到Innerkey
- int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
- mLog::Info("nConfigInfoCount {$}", nConfigInfoCount);
- string strTemp = ""; //存储AttributeKey
- for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
- {
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
- if (strTemp == strKey)
- {
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
- break;
- }
- }
- //3. 修改配置文件中的值
- if (SetDeviceConfigValue(m_Configurations, strTemp.c_str(), 1, DescriptionTempEx[i]))
- {
- mLog::Debug("SetDeviceConfigValue over");
- bSaveFile = true;
- }
- }
- else
- {
- mLog::Info("{$} is not a RW configuration item", strKey.c_str());
- }
- }
- else
- {
- mLog::Info("without this attribute {$}", strKey.c_str());
- }
- }
- catch (ResDataObjectExption& e)
- {
- printf("\nSetDriverConfig crashed: %s\n", e.what());
- mLog::Error("SetDriverConfig crashed: {$}", e.what());
- return false;
- }
- }
- if (bSaveFile)
- {
- //3. 重新保存配置文件
- SaveConfigFile(true);
- }
- return true;
- }
- bool nsGEN::VMIMAMMODriver::SaveConfigFile(bool bSendNotify)
- {
- m_ConfigAll["CONFIGURATION"] = m_Configurations;
- bool bRt = m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
- mLog::Info("SaveConfigFile over {$}", bRt);
- return true;
- }
- bool nsGEN::VMIMAMMODriver::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::VMIMAMMODriver::SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue)
- {
- string strTemp = pInnerKey;
- mLog::Debug("Begin to change {$} item value to {$}", pInnerKey, szValue);
- printf("\nbbbbbbbbbbbbbbBegin to change {%s} item value to {%s}\n", pInnerKey, szValue);
- if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
- {
- try {
- int pos = 0;
- ResDataObject* resTemp = &config;
- while ((pos = strTemp.find_first_of(',')) != string::npos)
- {
- string Key = strTemp.substr(0, pos);
- resTemp = &(*resTemp)[Key.c_str()];
- strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
- }
- if (strTemp != "")
- {
- //if ((strTemp.compare("WSTable") == 0) ||
- // (strTemp.compare("WSWall") == 0) ||
- // (strTemp.compare("WSFree") == 0) ||
- // (strTemp.compare("WSTomo") == 0) ||
- // (strTemp.compare("WSConventional") == 0)
- // )
- //{
- // int sum = (*szValue) + 1;
- // (*resTemp)[strTemp.c_str()] = (char*)(&sum);
- //}
- //else
- // (*resTemp)[strTemp.c_str()] = szValue;
- (*resTemp)[strTemp.c_str()] = szValue;
- }
- else
- {
- *resTemp = szValue;
- }
- }
- catch (ResDataObjectExption& e)
- {
- mLog::Error("SetDriverConfigvalue crashed: {$}", e.what());
- return false;
- }
- }
- return true;
- }
- std::string nsGEN::VMIMAMMODriver::GetResource()
- {
- ResDataObject r_config, temp;
- if (!temp.loadFile(m_ConfigFileName.c_str()))
- {
- return "";
- }
- m_ConfigAll = temp;
- r_config = temp["CONFIGURATION"];
- m_Configurations = r_config;
- ResDataObject DescriptionTemp;
- ResDataObject DescriptionSend;
- ResDataObject m_DescriptionSend;
- ResDataObject ListTemp;
- string strTemp = ""; //用于读取字符串配置信息
- string strIndex = ""; //用于读取配置信息中的List项
- int nTemp = -1; //用于读取整型配置信息
- char sstream[10] = { 0 }; //用于转换值
- string strValue = ""; //用于存储配置的值
- string strType = ""; //用于存储配置的类型 int/float/string...
- /***
- * 1. 通过循环,将所有配置项写到pDeviceConfig
- * 2. 记录配置项的内部key以及配置类型,类型对应了不同配置文件路径,用于读写真实值
- ***/
- try
- {
- //便利ConfigToolInfo 中 所有的AttributeInfo 属性段
- int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
- m_pAttribute->clear();
- m_pDescription->clear();
- for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
- {
- DescriptionTemp.clear();
- DescriptionSend.clear();
- ListTemp.clear();
- //AttributeType
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Type"];
- DescriptionTemp.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
- DescriptionSend.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
- strType = strTemp; //记录配置项的类型
- //AttributeKey
- //1. 根据AttributeType,内部key和配置路径,拿到当前的真实值
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
- nTemp = (int)m_Configurations["ConfigToolInfo"][nInfoIndex]["PathID"];
- GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue); //得到strValue的值
- //printf("********************************innerkey=%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
- //2. 赋值
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
- if ("int" == strType)
- {
- (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
- }
- else if ("float" == strType)
- {
- (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
- }
- else //其它先按string类型处理
- {
- (*m_pAttribute).add(strTemp.c_str(), strValue.c_str());
- }
- //printf("********************************outkey =%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
- //AttributeAccess
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Access"];
- DescriptionTemp.add(ConfKey::CcosAccess, strTemp.c_str());
- DescriptionSend.add(ConfKey::CcosAccess, strTemp.c_str());
- /*
- //AttributeRangeMin
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMin"];
- if (strTemp != "") //不需要的配置项为空
- {
- DescriptionTemp.add(ConfKey::CcosRangeMin, strTemp.c_str());
- }
- //AttributeRangeMax
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMax"];
- if (strTemp != "") //不需要的配置项为空
- {
- DescriptionTemp.add(ConfKey::CcosRangeMax, strTemp.c_str());
- }
- */
- //AttributeList
- nTemp = m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListNum"];
- if (nTemp > 0) //ListNum不大于0时说明不需要list配置
- {
- for (int nListIndex = 0; nListIndex < nTemp; nListIndex++)
- {
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListInfo"][nListIndex];
- auto temKey = std::to_string(nListIndex);
- ListTemp.add(temKey.c_str(), strTemp.c_str());
- }
- DescriptionTemp.add(ConfKey::CcosList, ListTemp);
- DescriptionSend.add(ConfKey::CcosList, ListTemp.encode());
- }
- //AttributeRequired
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Required"];
- DescriptionTemp.add(ConfKey::CcosRequired, strTemp.c_str());
- DescriptionSend.add(ConfKey::CcosRequired, strTemp.c_str());
- //AttributeDefaultValue
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["DefaultValue"];
- if (strTemp != "") //不需要的配置项为空
- {
- DescriptionTemp.add(ConfKey::CcosDefaultValue, strTemp.c_str());
- DescriptionSend.add(ConfKey::CcosDefaultValue, strTemp.c_str());
- }
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
- (*m_pDescription).add(strTemp.c_str(), DescriptionTemp);
- m_DescriptionSend.add(strTemp.c_str(), DescriptionSend.encode());
- }
- }
- catch (ResDataObjectExption& e)
- {
- mLog::Error("Get config error: {$}", e.what());
- return "";
- }
- ResDataObject resDeviceResource;
- resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
- resDeviceResource.add(ConfKey::CcosGeneratorDescription, (*m_pDescription));
- ResDataObject DescriptionTempEx;
- DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
- m_DeviceConfig.clear();
- m_DeviceConfig = DescriptionTempEx;
- mLog::Debug("local ************* get resource over {$}", DescriptionTempEx.encode());
- printf("local ************* get resource over %s \n", DescriptionTempEx.encode());
- resDeviceResource.clear();
- resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
- resDeviceResource.add(ConfKey::CcosGeneratorDescription, m_DescriptionSend);
- DescriptionTempEx.clear();
- DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
- m_DeviceConfigSend.clear();
- m_DeviceConfigSend = DescriptionTempEx;
- string res = m_DeviceConfigSend.encode();
- //printf("%s", res.c_str());
- mLog::Debug("get resource over {$}", DescriptionTempEx.encode());
- printf("************* get resource over %s \n", DescriptionTempEx.encode());
- return res;
- }
- std::string nsGEN::VMIMAMMODriver::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", "VMIMAMMO");
- HardwareInfo.add("ProductID", "HF");
- HardwareInfo.add("SerialID", "1234");
- }
- string ret = HardwareInfo.encode();
- return ret;
- }
- void nsGEN::VMIMAMMODriver::Dequeue(const char* Packet, DWORD Length)
- {
- DecodeFrame(Packet, Length);
- }
- PACKET_RET nsGEN::VMIMAMMODriver::callbackPackageProcess(const char* RecData, DWORD nLength, DWORD& PacketLength)
- {
- if (nLength < 1)
- {
- mLog::Info("nLength < 1, nLength=={$} \n", nLength);
- return PACKET_USELESS;
- }
- for (DWORD i = 0; i < nLength - 1; i++)
- {
- if (RecData[i] == 0x03)
- {
- PacketLength = i + 2; //data+etx+checksum
- char strtemp[100] = { 0 };
- memcpy(strtemp, RecData, i); // STX+RKC005(not include 03 + sum); //only 复制 0x03之前的数据,这样解析时,后面的03 ,sum 都不要了。
- strtemp[PacketLength + 1] = 0;
- mLog::Info("==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::VMIMAMMODriver gIODriver;
- extern "C" CCOS::Dev::IODriver * __cdecl GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
- {
- return &gIODriver;
- }
- extern "C" CCOS::Dev::IODriver * __cdecl CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
- {
- return new nsGEN::VMIMAMMODriver();
- }
|