| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278 |
- // CCOS.Dev.GEN.CPI.cpp : 定义 DLL 应用程序的导出函数。
- //
- #include <assert.h>
- #include <functional>
- #include <unordered_map>
- #include <fstream>
- #include <set>
- #include <unistd.h>
- #include <linux/limits.h>
- #include "LogicDevice.h"
- #include "CCOS.Dev.Generator.CPI.h"
- #include "Helper.JSON.hpp"
- #include "LogLocalHelper.h"
- #include "Log4CPP.h"
- using namespace std::placeholders;
- using namespace CCOS::Dev::Detail::Generator;
- namespace nsGEN = CCOS::Dev::Detail::Generator;
- static const int msTimeOut_Lock = 500;
- // Linux 环境下的 SCF 库文件名
- static const auto COM_SCFDllName = "libSerialSCF.so";
- static const auto TCP_SCFDllName = "libTcpipSCF.so";
- // 定义 Sleep 宏(如果头文件中没有定义)
- #ifndef Sleep
- #define Sleep(ms) std::this_thread::sleep_for(std::chrono::milliseconds(ms))
- #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()
- {
- char result[PATH_MAX] = { 0 };
- ssize_t count = readlink("/proc/self/exe", result, PATH_MAX);
- if (count == -1)
- {
- return "";
- }
- string fullpath = string(result, count);
- string::size_type lastSlash = fullpath.find_last_of('/');
- if (lastSlash == string::npos)
- {
- return "";
- }
- return fullpath.substr(0, lastSlash);
- }
- nsGEN::CPIDevice::CPIDevice(std::shared_ptr <IOEventCenter> center, std::shared_ptr<SCFWrapper> SCF, string configfile)
- : super(center)
- , superGen()
- , m_SCF(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 = LinuxEvent::CreateEvent(LinuxEvent::MANUAL_RESET, false);
- m_bExtraFlag = true; // 启用硬件状态查询线程
- 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()
- {
- FINFO("========================================");
- FINFO("CPIDevice Destructor Starting...");
- FINFO("========================================");
- FINFO("Stopping hardware status thread...");
- m_bExtraFlag = false;
- if (m_pHardwareStatusThread.joinable()) {
- FINFO("Waiting for hardware status thread to join...");
- m_pHardwareStatusThread.join();
- FINFO("Hardware status thread joined successfully");
- } else {
- FINFO("Hardware status thread not joinable, skipping join");
- }
- FINFO("========================================");
- FINFO("CPIDevice Destructor Completed");
- FINFO("========================================");
- }
- std::string nsGEN::CPIDevice::GetGUID() const
- {
- FINFO("\n===============GetGUID : {$} ===================\n", GeneratorUnitType);
- return GeneratorUnitType;
- }
- void nsGEN::CPIDevice::Register()
- {
- auto Disp = m_Dispatch.Lock().As();
- 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 };
- snprintf(temp, sizeof(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 };
- snprintf(temp, sizeof(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 };
- snprintf(temp, sizeof(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 };
- snprintf(temp, sizeof(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 };
- snprintf(temp, sizeof(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);
- //}
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::CPIDevice::SetFocus(int value)
- {
- if (!m_DoseUnit.m_Focus->Verify(value)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "FO%01d", (int)value);
- return HWSend(temp);
- }
- 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)
- {
- snprintf(temp, sizeof(temp), "FN+%01d", (int)nAECDensity);
- }
- else
- {
- snprintf(temp, sizeof(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 };
- snprintf(temp, sizeof(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 };
- snprintf(temp, sizeof(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 };
- snprintf(temp, sizeof(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 };
- snprintf(temp, sizeof(temp), "ACH%05d", (int)(height * 100));
- HWSend(temp);
- snprintf(temp, sizeof(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 };
- snprintf(temp, sizeof(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(const char* strCommand, int nTimeOut)
- {
- if (!m_SCF) {
- FINFO("Failed - Serial communication interface not initialized");
- if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_SHUTDOWN))
- {
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- FINFO("Generator status updated to {$}", static_cast<int>(nsGEN::AttrKey::GENERATOR_STATUS_SHUTDOWN));
- }
- return RET_STATUS::RET_FAILED;
- }
- if (!m_SCF->IsConnected())
- {
- FERROR("Failed - Device not connected");
- if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_SHUTDOWN))
- {
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- FINFO("Generator status updated to {$}", static_cast<int>(nsGEN::AttrKey::GENERATOR_STATUS_SHUTDOWN));
- }
- return RET_STATUS::RET_FAILED;
- }
- // 计算命令长度
- int cmdLen = strlen(strCommand);
- // 检查缓冲区大小,数据包 = 命令 + ETX(1字节) + CheckSum(1字节)
- const int maxCmdLen = 256; // 增大缓冲区以支持更长的命令
- if (cmdLen > maxCmdLen - 2)
- {
- FERROR("Command too long: {$} bytes, max allowed: {$} bytes\n", cmdLen, maxCmdLen - 2);
- return RET_STATUS::RET_FAILED;
- }
- char strSendCommand[maxCmdLen] = { 0 };
- // 计算校验和
- int tmpSum = 0;
- for (int i = 0; i < cmdLen; i++)
- {
- tmpSum += (unsigned char)strCommand[i];
- }
- char checkSum = char(tmpSum + 3);
- // 构建数据包:命令 + ETX + CheckSum
- memcpy(strSendCommand, strCommand, cmdLen);
- strSendCommand[cmdLen] = 0x03;
- strSendCommand[cmdLen + 1] = checkSum;
- int totalLen = cmdLen + 2; // 实际发送的总长度
- // 打印完整数据包的十六进制和ASCII(含ETX和CheckSum)便于调试
- FINFO("==OUT== CMD={$} LEN={$}", strCommand, totalLen);
- // 使用 SCFWrapper 发送数据
- unsigned int retLength = 0;
- if (m_SCF->Lock(1000) == WAIT_OBJECT_0)
- {
- int result = m_SCF->SendPacket(strSendCommand, (unsigned int)totalLen, (unsigned int)nTimeOut, retLength);
- m_SCF->Unlock();
- if (result != SCF_SUCCEED)
- {
- FERROR("SendPacket failed, result={$}", result);
- return RET_STATUS::RET_FAILED;
- }
- }
- else
- {
- FERROR("Failed to lock SCF");
- return RET_STATUS::RET_FAILED;
- }
- 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(const 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);
- m_hGenPostEvent->ResetEvent();
- 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());
- //m_hGenPostEvent->SetEvent();
- };
- 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());
- //m_hGenPostEvent->SetEvent();
- };
- 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]{ "" };
- snprintf(ErrorCode, sizeof(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[20]{ "" };
- snprintf(WarnCode, sizeof(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");
- }
- else if (nValue == 4)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_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 ");
- try {
- if (!m_pHardwareStatusThread.joinable()) {
- m_pHardwareStatusThread = std::thread(HardwareStatusThread, this);
- FINFO("Hardware status thread started successfully");
- return true;
- } else {
- FINFO("Hardware status thread already running");
- return true;
- }
- }
- catch (const std::exception& e) {
- FERROR("Start HardwareStatus Thread Failed: {$}", e.what());
- return false;
- }
- }
- void nsGEN::CPIDevice::HardwareStatusThread(CPIDevice* pParam)
- {
- if (pParam == NULL)
- {
- FERROR("HardwareStatusThread: Invalid parameter");
- return;
- }
- FINFO("HardwareStatusThread start");
- int cnt = 0;
- while (pParam->m_bExtraFlag)
- {
- Sleep(2000);
- if (!pParam->m_bExtraFlag) {
- break;
- }
- pParam->HWSend("HE?");
- if (pParam->m_bCheckATUStatus)
- {
- cnt++;
- if (cnt == 10)
- {
- pParam->HWSend("ATU?");
- cnt = 0;
- }
- }
- else
- {
- cnt = 0;
- }
- }
- FINFO("HardwareStatusThread stop");
- }
- //-----------------------------------------------------------------------------
- // 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 (index == 0)
- {
- m_pDriGenDev = new CPIDevice(EventCenter, m_scfWrapper, 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) //----------------------------------可能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;
- }
- // 处理所有未匹配的index,确保函数有返回值
- return nullptr;
- }
- void nsGEN::CPIDriver::FireNotify(int code, std::string key, std::string content)
- {
- EventCenter->OnNotify(code, key, content);
- }
- void nsGEN::CPIDriver::Prepare()
- {
- FINFO("========================================");
- FINFO("CPIDriver::Prepare() Starting...");
- FINFO("========================================");
- // 初始化日志系统
- std::string strLogPath = GetProcessDirectory() + R"(/Conf/log_config.xml)";
- std::string LogHost = "DevCPI";
- std::string moduleName = "DevCPI";
- FINFO("Initializing log module...");
- FINFO("Log config path: {$}", strLogPath.c_str());
- FINFO("Log host: {$}", LogHost.c_str());
- FINFO("Module name: {$}", moduleName.c_str());
- bool ret = initLogModule(
- LogHost, // 主机名(用于日志路径中的{host}占位符)
- moduleName, // 唯一模块名
- strLogPath, // 配置文件路径
- true // 是否输出到控制台(可选)
- );
- if (!ret) {
- std::cerr << "Log init failed!" << std::endl;
- FERROR("Failed to initialize log module");
- return;
- }
- FINFO("Log module initialized successfully");
- CPI_SetLocalModuleName(moduleName);
- FINFO("Getting connection DLL from config: {$}", m_ConfigFileName.c_str());
- m_SCFDllName = GetConnectDLL(m_ConfigFileName);
- FINFO("SCF DLL name: {$}", m_SCFDllName.c_str());
- FINFO("Calling parent Prepare()...");
- super::Prepare();
- FINFO("========================================");
- FINFO("CPIDriver::Prepare() Completed");
- FINFO("========================================");
- }
- bool DATA_ACTION nsGEN::CPIDriver::Connect()
- {
- FINFO("========================================");
- FINFO("CPIDriver::Connect() Starting...");
- FINFO("========================================");
- // 获取连接参数
- ResDataObject connParam = GetConnectParam(m_ConfigFileName);
- FINFO("Connection parameters: {$}", connParam.encode());
- // 创建 SCFWrapper 实例
- if (!m_scfWrapper) {
- try {
- // 创建 SCFWrapper
- m_scfWrapper = std::make_shared<SCFWrapper>();
- // 初始化 SCF 库
- if (!m_scfWrapper->Initialize(m_SCFDllName)) {
- FERROR("Failed to initialize SCF library: {$}", m_scfWrapper->GetLastError());
- return false;
- }
- FINFO("SCFWrapper initialized successfully");
- }
- catch (const std::exception& e) {
- FERROR("Exception creating SCFWrapper: {$}", e.what());
- return false;
- }
- }
- // 设置数据接收回调
- m_scfWrapper->SetDataReceivedCallback([this](const char* data, uint32_t length) {
- this->Dequeue(data, length);
- });
- // 连接 SCF
- FINFO("Connecting to device...");
- auto erCode = m_scfWrapper->Connect(
- connParam,
- &nsGEN::CPIDriver::callbackPackageProcess,
- SCF_PACKET_TRANSFER,
- 3000
- );
- if (erCode != SCF_SUCCEED || !m_scfWrapper->StartAutoReceive()) {
- FERROR("Failed to connect to device (error code: {$})", erCode);
- m_scfWrapper->Disconnect();
- return false;
- }
- FINFO("Device connected successfully");
- // 调用父类的 Connect
- FINFO("Calling parent Connect()...");
- auto rc = super::Connect();
- if (!rc) {
- FERROR("Parent Connect() failed");
- m_scfWrapper->Disconnect();
- return false;
- }
- FINFO("========================================");
- FINFO("CPIDriver::Connect() Completed Successfully");
- FINFO("========================================");
- return true;
- }
- void nsGEN::CPIDriver::Disconnect()
- {
- FINFO("========================================");
- FINFO("CPIDriver::Disconnect() Entry");
- if (m_scfWrapper) {
- FINFO("Stopping auto receive...");
- m_scfWrapper->StopAutoReceive();
- FINFO("Auto receive stopped");
- FINFO("Disconnecting SCF wrapper...");
- m_scfWrapper->Disconnect();
- FINFO("SCF wrapper disconnected");
- } else {
- FWARN("SCF wrapper is null, nothing to disconnect");
- }
- super::Disconnect();
- m_bDemoConnected = false;
- FINFO("CPIDriver::Disconnect() Completed");
- FINFO("========================================");
- }
- bool nsGEN::CPIDriver::isConnected() const
- {
- if (m_scfWrapper && m_scfWrapper->IsConnected()) {
- return true;
- }
- 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;
- 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)
- {
- (*m_pAttribute)[strKey.c_str()] = DescriptionTempEx[i];
- int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
- FINFO("nConfigInfoCount {$}", nConfigInfoCount);
- string strTemp = "";
- 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;
- }
- }
- 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)
- {
- 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)
- {
- 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 = "";
- int nTemp = -1;
- char sstream[10] = { 0 };
- string strValue = "";
- string strType = "";
- /***
- ***/
- try
- {
- 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
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
- nTemp = (int)m_Configurations["ConfigToolInfo"][nInfoIndex]["PathID"];
- GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue);
- //printf("********************************innerkey=%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
- 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
- {
- (*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)
- {
- 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, uint32_t nLength, uint32_t& PacketLength)
- {
- if (nLength < 1)
- {
- printf("nLength < 1, nLength==%d \n", nLength);
- FINFO("nLength < 1, nLength=={$} \n", nLength);
- return PACKET_USELESS;
- }
- for (uint32_t 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);
- 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 * GetIODriver()
- {
- return &gIODriver;
- }
- extern "C" CCOS::Dev::IODriver * CreateIODriver()
- {
- return new nsGEN::CPIDriver();
- }
|