#include #include "Helper.JSON.hpp" #include "CCOS.Dev.Generator.Demo.hpp" //#include "logger.temp.h" using namespace CCOS::Dev::Detail::Generator; namespace nsGEN = CCOS::Dev::Detail::Generator; #pragma warning (disable:4305) #define DEMO_DAEC_Flag 1 //----------------------------------------------------------------------------- // DemoDevice //----------------------------------------------------------------------------- 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 }; float g_KV_List[] = { 400, 405, 410, 415, 420, 430, 440, 450, 460, 470, 480, 490, 500, 510, 520, 535, 550, 560, 570, 585, 600, 615, 630, 645, 660, 680, 700, 715, 730, 750, 770, 790, 810, 830, 850, 875, 900, 930, 960, 1000, 1020, 1050, 1090, 1130, 1170, 1210, 1250, 1290, 1330, 1370, 1410, 1450, 1500 };// int g_AECFIELD_List[] = { 1, 10, 100, 11, 101, 110, 111 }; std::vector gf_MA_List = { 8, 10, 12.5, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640 }; std::unique_ptr nsGEN::DemoDevice::m_pCollDev = nullptr; //遮光器逻辑实体指针 std::unique_ptr nsGEN::DemoDevice::m_pMechDev = nullptr; //机架逻辑实体指针 template int FindPositon(T* pList, int nListSize, T& value) { if (pList == NULL || nListSize == 0) return -1; if (value <= pList[0]) { value = pList[0]; return 0; } if (value >= pList[nListSize - 1]) { value = pList[nListSize - 1]; return nListSize - 1; } for (int i = 0; i < nListSize - 1; i++) { if (value >= pList[i] && value <= pList[i + 1]) { int npos = 0; if (abs(value - pList[i]) >= abs(value - pList[i + 1])) { value = pList[i + 1]; npos = i + 1; } else { value = pList[i]; npos = i; } return npos; } } return -1; } nsGEN::DemoDevice::DemoDevice(std::shared_ptr center, string configfile) : super(center), superGen() { ////mLog::Info("DEMO ver 3.0.0.1"); if (!configfile.empty()) { ResDataObject Conftemp; Conftemp.loadFile(configfile.c_str()); m_GenConfig = Conftemp["CONFIGURATION"]; TransJsonText(m_GenConfig); string version; void* hMyModule; if (GetVersion(version, hMyModule)) //mLog::Info("\n===============log begin : DEMO version:{$} ===================\n", version.c_str()); ///else //mLog::Info("\n===============log begin : DEMO version:0.0.0.0 ===================\n"); m_iStateChangeInterval = (int)m_GenConfig["StateChangeInterval"]; m_iAutoExpActWaitTime = (int)m_GenConfig["AutoExpActWaitTime"]; m_bIsDemo = ((int)m_GenConfig["IsDemo"]); //mLog::Info("Config:StateChangeInterval[{$}],AutoExpActWaitTime[{$}],IsDemo[{$}]", //m_iStateChangeInterval, m_iAutoExpActWaitTime, m_bIsDemo); } else { //mLog::Info("\n===============log begin : DEMO version:3.0.0.1 ===================\n"); m_iStateChangeInterval = 500; m_iAutoExpActWaitTime = 5; m_bIsDemo = true; //mLog::Info("default:StateChangeInterval[{$}],AutoExpActWaitTime[{$}],IsDemo[{$}]", // m_iStateChangeInterval, m_iAutoExpActWaitTime, m_bIsDemo); } //通用 m_DoseUnit.m_GenSynState.reset(new GENSYNSTATEMould(AttrKey::GENERATOR_RAD_OFF, AttrKey::GENERATOR_RAD_OFF, AttrKey::GENERATOR_RAD_XRAYOFF, 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_ExpMode.reset(new EXPMODEMould(AttrKey::EXPMODE_TYPE::Single)); m_DoseUnit.m_WS.reset(new WORKSTATIONMould(1, 0, 5, 1)); m_DoseUnit.m_HE.reset(new TUBEHEATMould(0, 0, 100, 1)); m_DoseUnit.m_TubeTargetMaterial.reset(new TUBETARGETMATERIALMould(AttrKey::TUBETARGETMATERIAL_TYPE::MO)); m_DoseUnit.m_TubeAngle.reset(new TUBEANGLEMould(0, 0, 360, 1)); //点片 m_DoseUnit.m_KV.reset(new KVMould(0.0, 0.0, 150.0, 1.0)); m_DoseUnit.m_MA.reset(new MAMould(0.0, 0.0, 1000.0, 0.1)); m_DoseUnit.m_MS.reset(new MSMould(0.0, 0.0, 10000.0, 0.01)); m_DoseUnit.m_MAS.reset(new MASMould(0.0, 0.0, 1000.0, 0.01)); m_DoseUnit.m_Techmode.reset(new TECHMODEMould(AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P, AttrKey::TECHMODE_NOAEC_3P, AttrKey::TECHMODE_AEC_2P, 1)); m_DoseUnit.m_Focus.reset(new FOCUSMould(AttrKey::FOCUS_TYPE::FOCUS_LARGE, AttrKey::FOCUS_SMALL, AttrKey::FOCUS_LARGE, 1)); m_DoseUnit.m_AECField.reset(new AECFIELDMould(0, 0, 111, 1)); m_DoseUnit.m_AECFilm.reset(new AECFILMMould(0, 0, 2, 1)); m_DoseUnit.m_AECDensity.reset(new AECDENSITYMould(0, -4, 4, 1)); m_DoseUnit.m_PostKV.reset(new POSTKVMould(0.0, 0.0, 150.0, 1.0)); m_DoseUnit.m_PostMA.reset(new POSTMAMould(0.0, 0.0, 1000.0, 0.1)); m_DoseUnit.m_PostMS.reset(new POSTMSMould(0.0, 0.0, 10000.0, 0.01)); m_DoseUnit.m_PostMAS.reset(new POSTMASMould(0.0, 0.0, 1000.0, 0.01)); //透视 m_DoseUnit.m_FLKV.reset(new FLUKVMould(0.0, 40.0, 150.0, 1)); m_DoseUnit.m_FLMA.reset(new FLUMAMould(0.0, 0.5, 800.0, 0.1)); m_DoseUnit.m_FLMS.reset(new FLUMSMould(0.0, 1.0, 10000.0, 0.01)); m_DoseUnit.m_FLAccTime.reset(new FLAccTimeMould(0.0, 0.0, 300.0, 1)); m_DoseUnit.m_FLIntTime.reset(new FLUIntTimeMould(0.0, 0.0, 1000.0, 1)); m_DoseUnit.m_PPS.reset(new PPSMould(0.0, 0.0, 60.0, 1)); m_DoseUnit.m_FLMode.reset(new FLUModeMould(AttrKey::GENERATOR_FLUMode::GENERATOR_FLMODE_NOTFLU)); m_DoseUnit.m_ABSStatus.reset(new FLUABSStatusMould(AttrKey::GENERATOR_ABSStatus::GENERATOR_ABS_OFF)); m_DoseUnit.m_MagSize.reset(new FLUMagMould(0, 0, 3, 1)); m_DoseUnit.m_DoseLevel.reset(new FLUDoseLevelMould(AttrKey::GENERATOR_DoseLevel::GENERATOR_DOSE_LOW)); m_DoseUnit.m_Curve.reset(new FLUCurveMould(0, 1, 3, 1)); //other m_MSGUnit.reset(new nsDetail::MSGUnit(center, GeneratorUnitType)); OnRegister(); GetConfData(); //add by wxx:for 品臻3025ZF测试 m_iAutoExpFlag = 0; m_pHardwareStatusThread = 0; StartHardwareStatusThread(); } nsGEN::DemoDevice::~DemoDevice() { //mLog::Info("\n===============log end ===================\n"); if (m_pHardwareStatusThread != 0) { pthread_cancel(m_pHardwareStatusThread); // 请求取消线程 pthread_join(m_pHardwareStatusThread, nullptr); // 等待线程结束 m_pHardwareStatusThread = 0; } m_pCollDev.release(); m_pCollDev = nullptr; m_pMechDev.release(); m_pMechDev = nullptr; } void nsGEN::DemoDevice::OnRegister() { auto Disp = m_Dispatch.Lock().As(); superGen::Register(Disp); superGen::RegisterRAD(Disp); superGen::RegisterAEC(Disp); superGen::RegisterExpEnable(Disp); superGen::RegisterGeneratortoSyncStatus(Disp); superGen::RegisterFluoro(Disp); Disp->Get.Push(m_MSGUnit->GetKey().c_str(), [this](std::string& out) { out = m_MSGUnit->JSGet(); return RET_STATUS::RET_SUCCEED; }); auto fun_StartMove = [this](auto in, auto& out) { return StartMove(); }; Disp->Action.Push("StartMove", fun_StartMove); auto fun_EndMove = [this](auto in, auto& out) { return EndMove(); }; Disp->Action.Push("EndMove", fun_EndMove); auto fun_DirectlyNotify = [this](auto in, auto& out) { return DirectlyNotify(in); }; Disp->Action.Push("DirectlyNotify", fun_DirectlyNotify); auto fun_DirectlyCMD = [this](auto in, auto& out) { return DirectlyCMD(in); }; Disp->Action.Push("DirectlyCMD", fun_DirectlyCMD); } //设备方法 std::string nsGEN::DemoDevice::GetGUID() const { printf("\n===============GetGUID : %s ===================\n", GeneratorUnitType); return GeneratorUnitType; } RET_STATUS nsGEN::DemoDevice::SetWS(std::string value) { //mLog::Debug("Enter SetWS:[{$}]", value.c_str()); int tempws = 1; string strWS = ""; cfgWorkStationKey trWS = cfgWorkStationKey(value.c_str()); if (m_arrWSMap.find(trWS) != m_arrWSMap.end()) { m_strCurrentWSName = trWS; tempws = m_arrWSMap[m_strCurrentWSName].nWSNamber; strWS = m_arrWSMap[m_strCurrentWSName].strWSNAme; //mLog::Debug("Set WS number [{$}][{$}]", strWS.c_str(), tempws); } else { //mLog::Debug("Set WS number default 1"); m_strCurrentWSName = cfgWorkStationKey(1); } m_DoseUnit.m_WS->Update(atoi(value.c_str())); FireNotify(m_DoseUnit.m_WS->GetKey(), m_DoseUnit.m_WS->JSGet()); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::QueryHE(int& value) { return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::StartMove() //发生器无此设置 { return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::EndMove() //发生器无此设置 { return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::DirectlyNotify(string& value) { ResDataObject json; json.decode(value.c_str()); //mLog::Debug("Enter DirectlyNotify:[{$}]", json.encode()); string strKey = (string)json["NotifyKey"]; string strValue = (string)json["NotifyValue"]; FireNotify(strKey, strValue); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::DirectlyCMD(string& value) { ResDataObject json; json.decode(value.c_str()); //mLog::Debug("Enter DirectlyCMD:[{$}]", json.encode()); string strCMD = (string)json["CMDText"]; return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetGenSynState(int value) { //mLog::Debug("Enter SetGenSynState:[{$}]", value); switch (value) { case AttrKey::GENERATOR_RAD_OFF: { }break; case AttrKey::GENERATOR_RAD_PREPARE: { }break; case AttrKey::GENERATOR_RAD_READY: { }break; case AttrKey::GENERATOR_RAD_XRAYON: { if (m_DoseUnit.m_ExpMode->JSGet() == AttrKey::EXPMODE_TYPE::Stitch) { if (!m_APRarray.empty()) { int aprnum = m_DoseUnit.m_GenCurrentExpNumber->Get(); SetAPR(m_APRarray[aprnum]); m_DoseUnit.m_GenCurrentExpNumber->Update(++aprnum); //mLog::Debug("SetAPRArray:[totalEXP:{$}, currentEXP:{$}]", m_DoseUnit.m_GenTotalExpNumber->Get(), m_DoseUnit.m_GenCurrentExpNumber->Get()); } else { //mLog::Warn("APRarray is empty"); } } else if (m_DoseUnit.m_ExpMode->JSGet() == AttrKey::EXPMODE_TYPE::PulseSerial || m_DoseUnit.m_ExpMode->JSGet() == AttrKey::EXPMODE_TYPE::CoutineSerial) { value = AttrKey::GENERATOR_FLU_XRAYON; } }break; case AttrKey::GENERATOR_RAD_XRAYOFF: { //mLog::Info("SetGenSynState:4 exp Status value:POSTKV[{$}],POSTMA[{$}],POSTMS[{$}],POSTMAS[{$}]", // m_DoseUnit.m_PostKV->Get(), m_DoseUnit.m_PostMA->Get(), m_DoseUnit.m_PostMS->Get(), m_DoseUnit.m_PostMAS->Get()); std::cout << "SetGenSynState:4 exp Status value:POSTKV[" << m_DoseUnit.m_PostKV->Get() << "],POSTMA[" << m_DoseUnit.m_PostMA->Get() << "],POSTMS[" << m_DoseUnit.m_PostMS->Get() << "],POSTMAS[" << m_DoseUnit.m_PostMAS->Get() << "]" << std::endl; FireNotify(AttrKey::POSTKV, m_DoseUnit.m_PostKV->JSGet()); FireNotify(AttrKey::POSTMA, m_DoseUnit.m_PostMA->JSGet()); #if DEMO_DAEC_Flag int temp = m_DoseUnit.m_PostMS->Get(); if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P || m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P || m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_1P) { temp /= 2; } FireNotify(AttrKey::POSTMS, temp); #else FireNotify(AttrKey::POSTMS, m_DoseUnit.m_PostMS->JSGet()); #endif // DEMO_DAEC_Flag FireNotify(AttrKey::POSTMAS, m_DoseUnit.m_PostMAS->JSGet()); if (m_DoseUnit.m_ExpMode->JSGet() == AttrKey::EXPMODE_TYPE::PulseSerial || m_DoseUnit.m_ExpMode->JSGet() == AttrKey::EXPMODE_TYPE::CoutineSerial) { value = AttrKey::GENERATOR_FLU_XRAYOFF; } }break; case AttrKey::GENERATOR_FLU_READY: { }break; case AttrKey::GENERATOR_FLU_XRAYON: { }break; case AttrKey::GENERATOR_FLU_XRAYOFF: { }break; default: break; } m_DoseUnit.m_GenSynState->Update(value); FireNotify(m_DoseUnit.m_GenSynState->GetKey(), value); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetGenState(int value) { //mLog::Debug("Enter SetGenState:[{$}]", value); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetExpEnable() { //mLog::Debug("Enter SetExpEnable"); //mLog::Info("Request Fault Status:GENSTATE STATUS_SHUTDOWN -> STATUS_STANDBY"); m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY); FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet()); FireNotify(m_DoseUnit.m_KVList->GetKey(), m_DoseUnit.m_KVList->JSGet()); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetExpDisable() { //mLog::Debug("Enter SetExpDisable"); return RET_STATUS::RET_SUCCEED; } RET_STATUS CCOS::Dev::Detail::Generator::DemoDevice::PrepareAcquisition() { m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY); FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet()); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::Reset() { //mLog::Debug("Enter Reset"); //FireErrorMessage(false, 0, "clear all Gen error"); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetExpMode(std::string value) { //add for dcm img hard //mLog::Debug("Enter SetExpMode:[{$}]", value.c_str()); if (m_DoseUnit.m_ExpMode->Update(value)) { FireNotify(AttrKey::EXPMODE, m_DoseUnit.m_ExpMode->JSGet()); } FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet()); m_DoseUnit.m_GenTotalExpNumber->Update(0); m_DoseUnit.m_GenCurrentExpNumber->Update(0); //add for dcm img hard FireNotify(m_DoseUnit.m_TubeTargetMaterial->GetKey(), m_DoseUnit.m_TubeTargetMaterial->JSGet()); FireNotify(m_DoseUnit.m_TubeAngle->GetKey(), m_DoseUnit.m_TubeAngle->JSGet()); if (m_pCollDev != nullptr) { //mLog::Info("act CollDev ReportMessageToDicom"); m_pCollDev->ReportMessageToDicom(); } if (m_pMechDev != nullptr) { //mLog::Info("act MechDev ReportMessageToDicom"); m_pMechDev->ReportMessageToDicom(); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetEXAMMode(std::string value) { //mLog::Debug("Enter SetEXAMMode:[{$}]", value.c_str()); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::ActiveSyncMode(_tSyncModeArgs value) { //mLog::Debug("Enter ActiveSyncMode:Sync[{$},{$}],WS[{$}]", value.strSyncMode.c_str(), value.strSyncValue.c_str(), value.strWS.c_str()); return RET_STATUS::RET_SUCCEED; } //点片 RET_STATUS nsGEN::DemoDevice::IncKV() { //mLog::Debug("Enter IncKV"); if (m_bIsDemo) { if (!m_DoseUnit.m_KV->CanInc()) return RET_STATUS::RET_SUCCEED; m_DoseUnit.m_KV->Inc(); FireNotify(m_DoseUnit.m_KV->GetKey(), m_DoseUnit.m_KV->JSGet()); m_DoseUnit.m_PostKV->Update(m_DoseUnit.m_KV->Get()); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::DecKV() { //mLog::Debug("Enter DecKV"); if (m_bIsDemo) { if (!m_DoseUnit.m_KV->CanDec()) return RET_STATUS::RET_SUCCEED; m_DoseUnit.m_KV->Dec(); m_DoseUnit.m_PostKV->Update(m_DoseUnit.m_KV->Get()); FireNotify(m_DoseUnit.m_KV->GetKey(), m_DoseUnit.m_KV->JSGet()); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetKV(float value) { //mLog::Debug("Enter SetKV:[{$}]", value); if (m_bIsDemo) { m_DoseUnit.m_KV->Update(value); m_DoseUnit.m_PostKV->Update(value); FireNotify(m_DoseUnit.m_KV->GetKey(), m_DoseUnit.m_KV->JSGet()); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::IncKVL() { //mLog::Debug("Enter IncKVL"); if (m_bIsDemo) { float tempKV = m_DoseUnit.m_KV->Get(); tempKV += 4; if (m_DoseUnit.m_KV->Update(tempKV)) { //mLog::Debug("IncKVL:[{$}] ok", tempKV); FireNotify(m_DoseUnit.m_KV->GetKey(), m_DoseUnit.m_KV->JSGet()); return RET_STATUS::RET_SUCCEED; } else { //mLog::Debug("IncKVL:[{$}] failed,Exceeding limit", tempKV); return RET_STATUS::RET_FAILED; } } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::DecKVL() { //mLog::Debug("Enter DecKVL"); if (m_bIsDemo) { float tempKV = m_DoseUnit.m_KV->Get(); tempKV -= 4; if (m_DoseUnit.m_KV->Update(tempKV)) { //mLog::Debug("DecKVL:[{$}] ok", tempKV); FireNotify(m_DoseUnit.m_KV->GetKey(), m_DoseUnit.m_KV->JSGet()); return RET_STATUS::RET_SUCCEED; } else { //mLog::Debug("DecKVL:[{$}] failed,Exceeding limit", tempKV); return RET_STATUS::RET_FAILED; } } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::IncMA() { //mLog::Debug("Enter IncMA"); if (m_bIsDemo) { if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P && m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P) { //mLog::Warn("Techmode is not 3P, can't IncMA"); return RET_STATUS::RET_SUCCEED; } float value = m_DoseUnit.m_MA->Get(); int npos = FindPositon(g_MA_List, sizeof(g_MA_List) / sizeof(float), value); if (npos < 0) { return RET_STATUS::RET_FAILED; } else if (npos == sizeof(g_MA_List) / sizeof(float) - 1) { return RET_STATUS::RET_SUCCEED; } npos += 1; float temp = g_MA_List[npos]; m_DoseUnit.m_MA->Update(temp); m_DoseUnit.m_PostMA->Update(temp); FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet()); ComputeMAS(); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::DecMA() { //mLog::Debug("Enter DecMA"); if (m_bIsDemo) { if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P && m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P) { //mLog::Warn("Techmode is not 3P, can't DecMA"); return RET_STATUS::RET_FAILED; } float value = m_DoseUnit.m_MA->Get(); int npos = FindPositon(g_MA_List, sizeof(g_MA_List) / sizeof(float), value); if (npos < 0) { return RET_STATUS::RET_FAILED; } else if (npos == 0) { return RET_STATUS::RET_SUCCEED; } npos -= 1; float temp = g_MA_List[npos]; m_DoseUnit.m_MA->Update(temp); m_DoseUnit.m_PostMA->Update(temp); FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet()); ComputeMAS(); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetMA(float value) { //mLog::Debug("Enter SetMA:[{$}]", value); if (m_bIsDemo) { //if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P && // m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P) //{ // //mLog::Warn("Techmode is not 3P, can't SetMA"); // return RET_STATUS::RET_FAILED; //} int npos = FindPositon(g_MA_List, sizeof(g_MA_List) / sizeof(float), value); if (npos < 0) { return RET_STATUS::RET_FAILED; } float temp = g_MA_List[npos]; m_DoseUnit.m_MA->Update(temp); m_DoseUnit.m_PostMA->Update(temp); FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet()); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::IncMS() { //mLog::Debug("Enter IncMS"); if (m_bIsDemo) { if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P && m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P) { //mLog::Warn("Techmode is not 3P, can't IncMAS"); return RET_STATUS::RET_FAILED; } float value = m_DoseUnit.m_MS->Get(); int npos = FindPositon(g_MS_List, sizeof(g_MS_List) / sizeof(float), value); if (npos < 0) { return RET_STATUS::RET_FAILED; } else if (npos == sizeof(g_MS_List) / sizeof(float) - 1) { return RET_STATUS::RET_SUCCEED; } npos += 1; float temp = g_MS_List[npos]; m_DoseUnit.m_MS->Update(temp); m_DoseUnit.m_PostMS->Update(temp); FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet()); ComputeMAS(); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::DecMS() { //mLog::Debug("Enter DecMS"); if (m_bIsDemo) { if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P && m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P) { //mLog::Warn("Techmode is not 3P, can't DecMS"); return RET_STATUS::RET_FAILED; } float value = m_DoseUnit.m_MS->Get(); int npos = FindPositon(g_MS_List, sizeof(g_MS_List) / sizeof(float), value); if (npos < 0) { return RET_STATUS::RET_FAILED; } else if (npos == 0) { return RET_STATUS::RET_SUCCEED; } npos -= 1; float temp = g_MS_List[npos]; m_DoseUnit.m_MS->Update(temp); m_DoseUnit.m_PostMS->Update(temp); FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet()); ComputeMAS(); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetMS(float value) { //mLog::Debug("Enter SetMS:[{$}]", value); if (m_bIsDemo) { //if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P && // m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P) //{ // //mLog::Warn("Techmode is not 3P, can't SetMS"); // return RET_STATUS::RET_FAILED; //} int npos = FindPositon(g_MS_List, sizeof(g_MS_List) / sizeof(float), value); if (npos < 0) { return RET_STATUS::RET_FAILED; } float temp = g_MS_List[npos]; m_DoseUnit.m_MS->Update(temp); m_DoseUnit.m_PostMS->Update(temp); FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet()); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::IncMAS() { //mLog::Debug("Enter IncMAS"); if (m_bIsDemo) { if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P && m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P) { //mLog::Warn("Techmode is not 2P, can't IncMAS"); return RET_STATUS::RET_NOSUPPORT; } float value = m_DoseUnit.m_MAS->Get(); int npos = FindPositon(g_MAS_List, sizeof(g_MAS_List) / sizeof(float), value); if (npos < 0) { return RET_STATUS::RET_SUCCEED; } else if (npos == sizeof(g_MAS_List) / sizeof(float) - 1) { return RET_STATUS::RET_SUCCEED; } npos += 1; float temp = g_MAS_List[npos]; m_DoseUnit.m_MAS->Update(temp); m_DoseUnit.m_PostMAS->Update(temp); FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet()); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::DecMAS() { //mLog::Debug("Enter DecMAS"); if (m_bIsDemo) { if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P && m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P) { //mLog::Warn("Techmode is not 2P, can't DecMAS"); return RET_STATUS::RET_NOSUPPORT; } float value = m_DoseUnit.m_MAS->Get(); int npos = FindPositon(g_MAS_List, sizeof(g_MAS_List) / sizeof(float), value); if (npos < 0) { return RET_STATUS::RET_FAILED; } else if (npos == 0) { return RET_STATUS::RET_SUCCEED; } npos -= 1; float temp = g_MAS_List[npos]; m_DoseUnit.m_MAS->Update(temp); m_DoseUnit.m_PostMAS->Update(temp); FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet()); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetMAS(float value) { //mLog::Debug("Enter SetMAS:[{$}]", value); if (m_bIsDemo) { //if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P && // m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P) //{ // //mLog::Warn("Techmode is not 2P, can't SetMAS"); // return RET_STATUS::RET_NOSUPPORT; //} int npos = FindPositon(g_MAS_List, sizeof(g_MAS_List) / sizeof(float), value); if (npos < 0) { return RET_STATUS::RET_FAILED; } float temp = g_MAS_List[npos]; m_DoseUnit.m_MAS->Update(temp); m_DoseUnit.m_PostMAS->Update(temp); FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet()); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::IncMASL() { //mLog::Debug("Enter IncMASL"); if (m_bIsDemo) { if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P && m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P) { //mLog::Warn("Techmode is not 2P, can't IncMASL"); return RET_STATUS::RET_NOSUPPORT; } float tempMAS = m_DoseUnit.m_MAS->Get(); tempMAS += 4; if (m_DoseUnit.m_MAS->Update(tempMAS)) { //mLog::Debug("IncMASL:[{$}] ok", tempMAS); FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet()); return RET_STATUS::RET_SUCCEED; } else { //mLog::Debug("IncMASL:[{$}] failed,Exceeding limit", tempMAS); return RET_STATUS::RET_FAILED; } } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::DecMASL() { //mLog::Debug("Enter DecMASL"); if (m_bIsDemo) { if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P && m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P) { //mLog::Warn("Techmode is not 2P, can't DecMASL"); return RET_STATUS::RET_NOSUPPORT; } float tempMAS = m_DoseUnit.m_MAS->Get(); tempMAS -= 4; if (m_DoseUnit.m_MAS->Update(tempMAS)) { //mLog::Debug("DecMASL:[{$}] ok", tempMAS); FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet()); return RET_STATUS::RET_SUCCEED; } else { //mLog::Debug("DecMASL:[{$}] failed,Exceeding limit", tempMAS); return RET_STATUS::RET_FAILED; } } return RET_STATUS::RET_SUCCEED; } void nsGEN::DemoDevice::ComputeMAS() { float tempMa = m_DoseUnit.m_MA->Get(); float tempMs = m_DoseUnit.m_MS->Get(); float tempMAS = tempMa * tempMs / 1000.0f; //m_DoseUnit.m_MAS->Update(tempMAS); m_DoseUnit.m_PostMAS->Update(tempMAS); //mLog::Debug("ComputeMAS:MA[{$}] MS[{$}] tempMAS[{$}] MAS[{$}] postMAS[{$}]", //tempMa, tempMs,tempMAS,m_DoseUnit.m_MAS->Get(), m_DoseUnit.m_PostMAS->Get()); FireNotify(m_DoseUnit.m_MAS->GetKey(), tempMAS); } RET_STATUS nsGEN::DemoDevice::SetTechmode(int value) { //mLog::Debug("Enter SetTechmode:[{$}]", value); if (m_bIsDemo) { if (!m_DoseUnit.m_Techmode->Verify(value)) return RET_STATUS::RET_SUCCEED; m_DoseUnit.m_Techmode->Update(value); FireNotify(m_DoseUnit.m_Techmode->GetKey(), m_DoseUnit.m_Techmode->JSGet()); switch (value) { case AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P: { FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet()); FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet()); ComputeMAS(); } break; case AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P: { FireNotify(m_DoseUnit.m_MA->GetKey(), "0"); FireNotify(m_DoseUnit.m_MS->GetKey(), "0"); FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet()); } break; case AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P: { FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet()); FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet()); ComputeMAS(); } break; case AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P: { FireNotify(m_DoseUnit.m_MA->GetKey(), "0"); FireNotify(m_DoseUnit.m_MS->GetKey(), "0"); FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet()); } break; } } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetFocus(int value) { //mLog::Debug("Enter SetFocus:[{$}]", value); if (m_bIsDemo) { if (!m_DoseUnit.m_Focus->Verify(value)) return RET_STATUS::RET_SUCCEED; m_DoseUnit.m_Focus->Update(value); FireNotify(m_DoseUnit.m_Focus->GetKey(), m_DoseUnit.m_Focus->JSGet()); if (m_DoseUnit.m_Focus->Get() == AttrKey::FOCUS_SMALL) FireNotify(AttrKey::FOCUSSIZE, m_DoseUnit.m_FocusSmall); else FireNotify(AttrKey::FOCUSSIZE, m_DoseUnit.m_FocusLarge); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetAECDensity(int value) { //mLog::Debug("Enter SetAECDensity:[{$}]", value); if (m_bIsDemo) { if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_1P && m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P && m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P) { printf("\n Techmode is not AEC, can't SetAECDensity"); return RET_STATUS::RET_NOSUPPORT; } if (!m_DoseUnit.m_AECDensity->Verify(value)) return RET_STATUS::RET_FAILED; m_DoseUnit.m_AECDensity->Update(value); FireNotify(m_DoseUnit.m_AECDensity->GetKey(), m_DoseUnit.m_AECDensity->JSGet()); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::IncAECDensity() { //mLog::Debug("Enter IncAECDensity"); if (m_bIsDemo) { //mLog::Debug("Enter IncAECDensity"); if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_1P && m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P && m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P) { //mLog::Warn("Techmode is not AEC, can't IncAECDensity"); return RET_STATUS::RET_NOSUPPORT; } if (m_DoseUnit.m_AECDensity->CanInc()) { m_DoseUnit.m_AECDensity->Inc(); FireNotify(m_DoseUnit.m_AECDensity->GetKey(), m_DoseUnit.m_AECDensity->JSGet()); } } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::DecAECDensity() { //mLog::Debug("Enter DecAECDensity"); if (m_bIsDemo) { //mLog::Debug("Enter DecAECDensity"); if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_1P && m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P && m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P) { //mLog::Warn("Techmode is not AEC, can't DecAECDensity"); return RET_STATUS::RET_NOSUPPORT; } if (m_DoseUnit.m_AECDensity->CanDec()) { m_DoseUnit.m_AECDensity->Dec(); FireNotify(m_DoseUnit.m_AECDensity->GetKey(), m_DoseUnit.m_AECDensity->JSGet()); } } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetAECField(int value) { //mLog::Debug("Enter SetAECField:[{$}]", value); if (m_bIsDemo) { if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_AEC) { printf("\n Techmode is not AEC, can't set AEC"); return RET_STATUS::RET_FAILED; } if (!m_DoseUnit.m_AECField->Verify(value)) return RET_STATUS::RET_SUCCEED; int npos = FindPositon(g_AECFIELD_List, sizeof(g_AECFIELD_List) / sizeof(int), value); if (npos < 0) { return RET_STATUS::RET_FAILED; } int temp = value; m_DoseUnit.m_AECField->Update(temp); FireNotify(m_DoseUnit.m_AECField->GetKey(), m_DoseUnit.m_AECField->JSGet()); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetAECFilm(int value) { //mLog::Debug("Enter SetAECFilm:[{$}]", value); if (m_bIsDemo) { if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_AEC) { printf("\n Techmode is not AEC, can't set AEC"); return RET_STATUS::RET_FAILED; } if (!m_DoseUnit.m_AECFilm->Verify(value)) return RET_STATUS::RET_SUCCEED; m_DoseUnit.m_AECFilm->Update(value); FireNotify(m_DoseUnit.m_AECFilm->GetKey(), m_DoseUnit.m_AECFilm->JSGet()); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetAPR(const _tAPRArgs& t) { //mLog::Debug("SetAPR:KV={$},MA={$},MS={$},MAS={$},Focus={$},Techmode={$},WS={$},AECDensity={$},AECField={$},AECFilm={$}", //t.fKV, t.fMA, t.fMS, t.fMAS, t.nFocus, t.nTechmode, t.nWS, t.nAECDensity, t.nAECField, t.nAECFilm); if (m_bIsDemo) { //note:缺少WS SetTechmode(t.nTechmode); SetKV(t.fKV); SetMA(t.fMA); SetMS(t.fMS); SetMAS(t.fMAS); SetFocus(t.nFocus); SetAECDensity(t.nAECDensity); SetAECField(t.nAECField); SetAECFilm(t.nAECFilm); if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P || m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P) { ComputeMAS(); } m_DoseUnit.m_HE->Update(50); FireNotify(m_DoseUnit.m_HE->GetKey(), m_DoseUnit.m_HE->JSGet()); } else { FireNotify(m_DoseUnit.m_Techmode->GetKey(), t.nTechmode); FireNotify(m_DoseUnit.m_KV->GetKey(), t.fKV); FireNotify(m_DoseUnit.m_MA->GetKey(), t.fMA); FireNotify(m_DoseUnit.m_MS->GetKey(), t.fMS); FireNotify(m_DoseUnit.m_MAS->GetKey(), t.fMAS); FireNotify(m_DoseUnit.m_Focus->GetKey(), t.nFocus); FireNotify(m_DoseUnit.m_AECDensity->GetKey(), t.nAECDensity); FireNotify(m_DoseUnit.m_AECField->GetKey(), t.nAECField); FireNotify(m_DoseUnit.m_AECFilm->GetKey(), t.nAECFilm); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetAPRArray(vector<_tAPRArgs>& APRarray) { //mLog::Debug("SetAPRArray:[size:{$}]", APRarray.size()); if (m_bIsDemo) { m_APRarray = APRarray; for (int i = 0; i < m_APRarray.size(); i++) { //mLog::Debug("APRArray[{$}]:WS={$},Techmode={$},Focus={$},KV={$},MA={$},MS={$},MAS={$},AECDensity={$},AECField={$},AECFilm={$}", //i, m_APRarray[i].nWS, m_APRarray[i].nTechmode, m_APRarray[i].nFocus, //m_APRarray[i].fKV, m_APRarray[i].fMA, m_APRarray[i].fMS, m_APRarray[i].fMAS, //m_APRarray[i].nAECDensity, m_APRarray[i].nAECField, m_APRarray[i].nAECFilm); } if (!m_APRarray.empty()) { SetAPR(m_APRarray[0]); m_DoseUnit.m_GenTotalExpNumber->Update(m_APRarray.size()); m_DoseUnit.m_GenCurrentExpNumber->Update(1); //mLog::Debug("SetAPRArray:[totalEXP:{$}, currentEXP:{$}]", m_DoseUnit.m_GenTotalExpNumber->Get(), m_DoseUnit.m_GenCurrentExpNumber->Get()); } } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::QueryPostKV(float& value) { value = m_DoseUnit.m_KV->Get(); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::QueryPostMA(float& value) { value = m_DoseUnit.m_MA->Get(); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::QueryPostMS(float& value) { value = m_DoseUnit.m_MS->Get(); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::QueryPostMAS(float& value) { value = m_DoseUnit.m_MAS->Get(); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetFrameRate(float frameRate) { //mLog::Debug("Enter SetFrameRate:[{$}]", frameRate); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetCollimatorDev(OemCollimator* dev) { //mLog::Debug("Enter SetCollimatorDev"); if (dev) m_pCollDev.reset(dev); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetMechDev(OemMechanical* dev) { //mLog::Debug("Enter SetMechDev"); if (dev) m_pMechDev.reset(dev); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetCollimatorSize(int xsize, int ysize) { //mLog::Debug("Enter SetCollimatorSize:[x:{$}, y:{$}]", xsize, ysize); if (m_pCollDev) { m_pCollDev->UpdateCollimatorXSize(xsize); m_pCollDev->UpdateCollimatorYSize(ysize); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetCollimatorLight(unsigned short pParams) { //mLog::Debug("Enter SetCollimatorLight:[{$}]", (int)pParams); //此处应该发送指令给GEN,并且该指令可以控制 coll 的LED return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetAutoTracking(int nAutoTracking) { //mLog::Debug("Enter SetAutoTracking:[{$}]", nAutoTracking); if (m_pMechDev) m_pMechDev->UpdateMammo_Depress(nAutoTracking); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetFilter(int nFilterType) { //mLog::Debug("Enter SetFilter:[{$}]", nFilterType); if (m_pMechDev) { m_pMechDev->UpdateMammo_FT(nFilterType); } if (m_pCollDev) { m_pCollDev->UpdateCollimatorFilter(nFilterType); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetGrid(int nGridType) { //mLog::Debug("Enter SetGrid:[{$}]", nGridType); if (m_pMechDev) m_pMechDev->UpdateGrid(nGridType); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::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; } //透视 RET_STATUS nsGEN::DemoDevice::IncFluKV() { //mLog::Debug("Enter IncFluKV"); float KV = m_DoseUnit.m_FLKV->Get()+1; if (m_DoseUnit.m_FLKV->Update(KV)) { FireNotify(m_DoseUnit.m_FLKV->GetKey(), m_DoseUnit.m_FLKV->JSGet()); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::DecFluKV() { //mLog::Debug("Enter DecFluKV"); float KV = m_DoseUnit.m_FLKV->Get() - 1; if (m_DoseUnit.m_FLKV->Update(KV)) { FireNotify(m_DoseUnit.m_FLKV->GetKey(), m_DoseUnit.m_FLKV->JSGet()); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetFluKV(float value) { //mLog::Debug("Enter SetFluKV:[{$}]", value); if (m_DoseUnit.m_FLKV->Update(value)) { FireNotify(m_DoseUnit.m_FLKV->GetKey(), m_DoseUnit.m_FLKV->JSGet()); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::IncFluMA() { //mLog::Debug("Enter IncFluKV"); float MA = m_DoseUnit.m_FLMA->Get()+1; if (m_DoseUnit.m_FLMA->Update(MA)) { FireNotify(m_DoseUnit.m_FLMA->GetKey(), m_DoseUnit.m_FLMA->JSGet()); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::DecFluMA() { //mLog::Debug("Enter DecFluKV"); float MA = m_DoseUnit.m_FLMA->Get() - 1; if (m_DoseUnit.m_FLMA->Update(MA)) { FireNotify(m_DoseUnit.m_FLMA->GetKey(), m_DoseUnit.m_FLMA->JSGet()); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetFluMA(float value) { //mLog::Debug("Enter SetFluMA:[{$}]", value); if (m_DoseUnit.m_FLMA->Update(value)) { FireNotify(m_DoseUnit.m_FLMA->GetKey(), m_DoseUnit.m_FLMA->JSGet()); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::IncFluMS() { return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::DecFluMS() { return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetFluMS(float value) { return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetPPS(float frameRate) { //mLog::Debug("Enter SetPPS:[{$}]", frameRate); if (m_DoseUnit.m_PPS->Update(frameRate)) { FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet()); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::INCPPS() { //mLog::Debug("Enter INCPPS"); float PPS = m_DoseUnit.m_PPS->Get()+1; if (m_DoseUnit.m_PPS->Update(PPS)) { FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet()); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::DECPPS() { //mLog::Debug("Enter DECPPS"); float PPS = m_DoseUnit.m_PPS->Get() - 1; if (m_DoseUnit.m_PPS->Update(PPS)) { FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet()); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetPluseWidth(float fplusewidth) { return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetABSMode(int nMode) { //mLog::Debug("Enter SetABSMode:[{$}]", nMode); if (m_DoseUnit.m_ABSStatus->Update(nMode)) { FireNotify(m_DoseUnit.m_ABSStatus->GetKey(), m_DoseUnit.m_ABSStatus->JSGet()); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetABSCurve(int curveNum) { return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::IncABSCurve() { return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::DecABSCurve() { return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetABSValue(float fABSValue) { return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetABSTargetEXI(float fEXIValue) { return RET_STATUS::RET_SUCCEED; } float nsGEN::DemoDevice::GetFluIntTimer() { return RET_STATUS::RET_SUCCEED; } float nsGEN::DemoDevice::GetFluAccTimer() { return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::ResetFluTimer(int ntype) { //mLog::Debug("ReSetFluAccTimer:[{$}]", ntype); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetFluPre(int bPrepare) { return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetFluEXP(int bPrepare) { return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetFLFMode(std::string value) { //mLog::Debug("Enter SetFLFMode:[{$}]", value.c_str()); if (value == "CF") { m_DoseUnit.m_FLMode->Update(AttrKey::GENERATOR_FLMODE_CF); SetExpMode(AttrKey::EXPMODE_TYPE::CoutineSerial); } else if (value == "PF") { m_DoseUnit.m_FLMode->Update(AttrKey::GENERATOR_FLMODE_PF); SetExpMode(AttrKey::EXPMODE_TYPE::PulseSerial); } FireNotify(AttrKey::FLUMode, m_DoseUnit.m_FLMode->JSGet()); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetFluMAG(int nsize) { return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::DisableMAG() { return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetFluDoseLever(int nlever) { //mLog::Debug("Enter SetFluDoseLever:[{$}]", nlever); if (m_DoseUnit.m_DoseLevel->Update(nlever)) { FireNotify(AttrKey::FLUDoseLevel, m_DoseUnit.m_DoseLevel->JSGet()); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetHalfDose(int nlever) { return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::TransferRadCurve(int ncurve) { return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::DemoDevice::SetAPF(const _tAPFArgs& t) { //mLog::Debug("SetAPF: nWS={$}, Flu mode={$}, ABS mode={$}, DoseLever={$}, nFlkv={$}, FlMA={$}", //t.nWS, t.nFluMode, t.nABSMode, t.nDoseLever, t.nFLKV, t.fFLMA, t.nPPS); if (m_DoseUnit.m_FLKV->Update(t.nFLKV)) { FireNotify(m_DoseUnit.m_FLKV->GetKey(), m_DoseUnit.m_FLKV->JSGet()); } if (m_DoseUnit.m_FLMA->Update(t.fFLMA)) { FireNotify(m_DoseUnit.m_FLMA->GetKey(), m_DoseUnit.m_FLMA->JSGet()); } if (m_DoseUnit.m_PPS->Update(t.nPPS)) { FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet()); } if (m_DoseUnit.m_DoseLevel->Update(t.nDoseLever)) { FireNotify(AttrKey::FLUDoseLevel, m_DoseUnit.m_DoseLevel->JSGet()); } if (m_DoseUnit.m_FLMode->Update(t.nFluMode)) { FireNotify(AttrKey::FLUMode, m_DoseUnit.m_FLMode->JSGet()); } if (m_DoseUnit.m_ABSStatus->Update(t.nABSMode)) { FireNotify(m_DoseUnit.m_ABSStatus->GetKey(), m_DoseUnit.m_ABSStatus->JSGet()); } return RET_STATUS::RET_SUCCEED; } //额外 void nsGEN::DemoDevice::FireNotify(string key, int context) { //std::unique_lock uqeLock(m_MSGLock); char szInfo[64] = { 0 }; sprintf(szInfo, "%d", context); std::string str = szInfo; EventCenter->OnNotify(1, key, str);//(int)ATTRACTION_SET 2 } void nsGEN::DemoDevice::FireNotify(std::string key, float context) { //std::unique_lock uqeLock(m_MSGLock); char szInfo[64] = { 0 }; sprintf(szInfo, "%.2f", context); std::string str = szInfo; EventCenter->OnNotify(1, key, str);//(int)ATTRACTION_SET 2 } void nsGEN::DemoDevice::FireNotify(std::string key, std::string context) { //std::unique_lock uqeLock(m_MSGLock); EventCenter->OnNotify(1, key, context); } int nsGEN::DemoDevice::GetConfData() { //灯丝大小 if (m_GenConfig.GetKeyCount(ConfKey::CcosTubeInfo) > 0) { string tempValue = m_GenConfig[ConfKey::CcosTubeInfo].encode(); m_DoseUnit.m_TubeInfo.reset(new TUBEINFOMould(tempValue)); } if (m_GenConfig.GetKeyCount(ConfKey::CcosFocusSmall) > 0) { float tempValue = (float)m_GenConfig[ConfKey::CcosFocusSmall]; m_DoseUnit.m_FocusSmall = tempValue; } if (m_GenConfig.GetKeyCount(ConfKey::CcosFocusLarge) > 0) { float tempValue = (float)m_GenConfig[ConfKey::CcosFocusLarge]; m_DoseUnit.m_FocusLarge = tempValue; } //同步模式 if (m_GenConfig.GetKeyCount("WSTable") > 0) { int WSNamber = (int)m_GenConfig["WSTable"]; EnSYNMode WSSYN = (EnSYNMode)((int)m_GenConfig["SYNTable"]); m_arrWSMap[cfgWorkStationKey("Table", AttrKey::TABLE)] = cfgWorkStationData("Table", WSNamber, WSSYN); //mLog::Debug("cfg Table WS[{$}],SYN[{$}]", WSNamber, (int)WSSYN); } if (m_GenConfig.GetKeyCount("WSWall") > 0) { int WSNamber = (int)m_GenConfig["WSWall"]; EnSYNMode WSSYN = (EnSYNMode)((int)m_GenConfig["SYNWall"]); m_arrWSMap[cfgWorkStationKey("Wall", AttrKey::WALL)] = cfgWorkStationData("Wall", WSNamber, WSSYN); //mLog::Debug("cfg Wall WS[{$}],SYN[{$}]", WSNamber, (int)WSSYN); } if (m_GenConfig.GetKeyCount("WSFree") > 0) { int WSNamber = (int)m_GenConfig["WSFree"]; EnSYNMode WSSYN = (EnSYNMode)((int)m_GenConfig["SYNFree"]); m_arrWSMap[cfgWorkStationKey("Free", AttrKey::MOBILE)] = cfgWorkStationData("Free", WSNamber, WSSYN); //mLog::Debug("cfg Free WS[{$}],SYN[{$}]", WSNamber, (int)WSSYN); } if (m_GenConfig.GetKeyCount("WSTomo") > 0) { int WSNamber = (int)m_GenConfig["WSTomo"]; EnSYNMode WSSYN = (EnSYNMode)((int)m_GenConfig["SYNTomo"]); m_arrWSMap[cfgWorkStationKey("Tomo", AttrKey::TOMO)] = cfgWorkStationData("Tomo", WSNamber, WSSYN); //mLog::Debug("cfg Tomo WS[{$}],SYN[{$}]", WSNamber, (int)WSSYN); } if (m_GenConfig.GetKeyCount("WSConventional") > 0) { int WSNamber = (int)m_GenConfig["WSConventional"]; EnSYNMode WSSYN = (EnSYNMode)((int)m_GenConfig["SYNConventional"]); m_arrWSMap[cfgWorkStationKey("Direct", AttrKey::CONVENTIONAL)] = cfgWorkStationData("Direct", WSNamber, WSSYN); //mLog::Debug("cfg Conventional WS[{$}],SYN[{$}]", WSNamber, (int)WSSYN); } //参数初始化 ResDataObject temp; temp.update("Max", 150); temp.update("Min", 40); temp.update("List", ""); for (int i = 0; i < sizeof(g_KV_List) / sizeof(g_KV_List[0]); i++) { char chindex[4] = { 0 }; sprintf(chindex, "%d", i); temp["List"].add(chindex, g_KV_List[i] / 10.0f); } m_DoseUnit.m_KVList.reset(new KVLISTMould(temp.encode())); temp.clear(); temp.update("Max", 1000); temp.update("Min", 8); temp.update("List", ""); for (int i = 0; i < sizeof(g_MAS_List) / sizeof(g_MAS_List[0]); i++) { char chindex[4] = { 0 }; sprintf(chindex, "%d", i); temp["List"].add(chindex, g_MAS_List[i]); } m_DoseUnit.m_mAsList.reset(new MASLISTMould(temp.encode())); //add by wxx for delworks:解决前端提出KV值太少的问题 20230913 FireNotify(m_DoseUnit.m_KVList->GetKey(), m_DoseUnit.m_KVList->JSGet()); return true; } void nsGEN::DemoDevice::FireErrorMessage(const bool Act, const int Code, const char* ResInfo) { string ErrorCode("Demo_ERR_"); ErrorCode += std::to_string(Code); int level = Demo_REGULATION_LEVEL::REG_ERRO; if (Act) { //mLog::Error("add {$}:{$}", ErrorCode.c_str(), ResInfo); m_MSGUnit->AddErrorMessage(ErrorCode.c_str(), level, ResInfo); } else { //mLog::Error("del {$}:{$}", ErrorCode.c_str(), ResInfo); if (Code == 0) m_MSGUnit->DelErrorMessage("0", level, ResInfo); else m_MSGUnit->DelErrorMessage(ErrorCode.c_str(), level, ResInfo); } } void nsGEN::DemoDevice::FireWarnMessage(const bool Act, const int Code, const char* ResInfo) { string ErrorCode("Demo_WAR_"); ErrorCode += std::to_string(Code); int level = Demo_REGULATION_LEVEL::REG_WARN; if (Act) { //mLog::Error("add {$}:{$}", ErrorCode.c_str(), ResInfo); m_MSGUnit->AddWarnMessage(ErrorCode.c_str(), level, ResInfo); } else { //mLog::Error("del {$}:{$}", ErrorCode.c_str(), ResInfo); m_MSGUnit->DelWarnMessage(ErrorCode.c_str(), level, ResInfo); } } bool nsGEN::DemoDevice::StartHardwareStatusThread() { //mLog::Info("enter Start HardwareStatus Thread "); if (m_pHardwareStatusThread == 0) // Linux使用0表示无效线程ID { // 创建线程属性对象(可选) pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); // 创建线程 int ret = pthread_create(&m_pHardwareStatusThread, &attr, HardwareStatusThread, this); pthread_attr_destroy(&attr); // 销毁属性对象 if (ret != 0) { //mLog::Error("Start HardwareStatus Thread Failed"); return false; } } return true; } void* nsGEN::DemoDevice::HardwareStatusThread(void* pParam) { DemoDevice* pCurGen = (DemoDevice*)pParam; if (pCurGen == NULL) { return NULL; } usleep(1500000); //mLog::Info("HardwareStatusThread start"); bool bActExpFlag = false; //mLog::Info("m_iStateChangeInterval = {$},m_iAutoExpActWaitTime = {$}", pCurGen->m_iStateChangeInterval, pCurGen->m_iAutoExpActWaitTime);; //mLog::Info("Request Fault Status:GENSTATE STATUS_SHUTDOWN -> STATUS_STANDBY"); pCurGen->m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY); pCurGen->FireNotify(AttrKey::GENSTATE, pCurGen->m_DoseUnit.m_GenState->JSGet()); while (true) { while (!bActExpFlag) { ////mLog::Info("loopAction: begin \n"); if (pCurGen->m_iAutoExpFlag > 0) { pCurGen->m_iAutoExpFlag = 0; usleep(pCurGen->m_iAutoExpActWaitTime*1000); if (pCurGen->m_iAutoExpFlag == 0) { //mLog::Info("loopAction: start Exp Workflow \n"); bActExpFlag = true; break; } else { //mLog::Info("loopAction: Exp param changed restart wait \n"); continue; } } usleep(pCurGen->m_iAutoExpActWaitTime*1000); } while (bActExpFlag) { //mLog::Info("loopAction: act exp Workflow \n"); switch (pCurGen->m_DoseUnit.m_GenSynState->Get()) { case nsGEN::AttrKey::GENERATOR_RAD_OFF: { //mLog::Info("exp Status change:RAD_OFF -> PREPARE(PR1)", pCurGen->m_DoseUnit.m_GenSynState->Get()); pCurGen->m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_PREPARE); }break; case nsGEN::AttrKey::GENERATOR_RAD_PREPARE: { //mLog::Info("exp Status change:PREPARE(PR1) -> RAD_READY(PR2)", pCurGen->m_DoseUnit.m_GenSynState->Get()); pCurGen->m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_READY); }break; case nsGEN::AttrKey::GENERATOR_RAD_READY: { //mLog::Info("exp Status change:RAD_READY(PR2) -> XRAYON(XR1)", pCurGen->m_DoseUnit.m_GenSynState->Get()); pCurGen->m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_XRAYON); }break; case nsGEN::AttrKey::GENERATOR_RAD_XRAYON: { //mLog::Info("exp Status change:XRAYON(XR1) -> XRAYOFF(XR0)", pCurGen->m_DoseUnit.m_GenSynState->Get()); pCurGen->m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_XRAYOFF); //mLog::Debug("Request Fault Status:GENSTATE STATUS_STANDBY -> STATUS_EXP"); pCurGen->m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_EXP); pCurGen->FireNotify(AttrKey::GENSTATE, pCurGen->m_DoseUnit.m_GenState->JSGet()); //mLog::Info("exp Status value:POSTKV[{$}],POSTMA[{$}],POSTMS[{$}],POSTMAS[{$}]", // pCurGen->m_DoseUnit.m_PostKV->Get(), pCurGen->m_DoseUnit.m_PostMA->Get(), pCurGen->m_DoseUnit.m_PostMS->Get(), pCurGen->m_DoseUnit.m_PostMAS->Get()); pCurGen->FireNotify(AttrKey::POSTKV, pCurGen->m_DoseUnit.m_PostKV->JSGet()); pCurGen->FireNotify(AttrKey::POSTMA, pCurGen->m_DoseUnit.m_PostMA->JSGet()); #if DEMO_DAEC_Flag int temp = pCurGen->m_DoseUnit.m_PostMS->Get(); if (pCurGen->m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P || pCurGen->m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P || pCurGen->m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_1P) { temp /= 2; } pCurGen->FireNotify(AttrKey::POSTMS, temp); #else pCurGen->FireNotify(AttrKey::POSTMS, pCurGen->m_DoseUnit.m_PostMS->JSGet()); #endif // DEMO_DAEC_Flag pCurGen->FireNotify(AttrKey::POSTMAS, pCurGen->m_DoseUnit.m_PostMAS->JSGet()); }break; case nsGEN::AttrKey::GENERATOR_RAD_XRAYOFF: { //mLog::Info("exp Status change:XRAYOFF(XR0) -> RAD_OFF", pCurGen->m_DoseUnit.m_GenSynState->Get()); pCurGen->m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_OFF); //mLog::Debug("Request Fault Status:GENSTATE STATUS_EXP -> STATUS_STANDBY"); pCurGen->m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY); pCurGen->FireNotify(AttrKey::GENSTATE, pCurGen->m_DoseUnit.m_GenState->JSGet()); } default: { bActExpFlag = false; } } pCurGen->FireNotify(pCurGen->m_DoseUnit.m_GenSynState->GetKey(), pCurGen->m_DoseUnit.m_GenSynState->JSGet()); usleep(pCurGen->m_iStateChangeInterval*1000); } } //mLog::Info("HardwareStatusThread stop"); return NULL; } //驱动 nsGEN::DemoDriver::DemoDriver() { m_bDemoMode = false; m_bDemoConnected = false; m_bDemoInitDataFlag = false; m_pDriGenDev = nullptr; //m_pDriCollDev = nullptr; //m_pDriMechDev = nullptr; m_pAttribute.reset(new ResDataObject()); m_pDescription.reset(new ResDataObject()); } nsGEN::DemoDriver::~DemoDriver() { //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; //} //mLog::Close(); //mLog::gLogger = nullptr; } auto nsGEN::DemoDriver::CreateDevice(int index) -> std::unique_ptr { std::cout << "Enter CreateDevice, index=" << index<< std::endl; //mLog::Info("Enter CreateDevice, index={$}", index); if (index == 0) { m_pDriGenDev = new DemoDevice(EventCenter, m_ConfigFileName); auto dev = std::unique_ptr(new IODevice(m_pDriGenDev)); return dev; } else if (index == 1) { std::cout << "Enter CreateDevice COLL" << std::endl; //mLog::Info("Enter CreateDevice COLL"); if (m_bDemoInitDataFlag) { int nXSize = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["XSize"]).c_str()); int nYSize = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["YSize"]).c_str()); int nFilter = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["Filter"]).c_str()); int nSID = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["SID"]).c_str()); int nAngle = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["Angle"]).c_str()); int nMode = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["Mode"]).c_str()); m_pDriCollDev = new OemCollimator(std::shared_ptr(new IOEventCenter()), nXSize, nYSize, nFilter, nSID, nAngle, nMode); } else m_pDriCollDev = new OemCollimator(std::shared_ptr(new IOEventCenter())); auto dev = std::unique_ptr (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) { std::cout << "Enter CreateDevice Mech" << std::endl; //mLog::Info("Enter CreateDevice Mech"); if (m_bDemoInitDataFlag) { int nGrid = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["Grid"]).c_str()); int nAE = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["AE"]).c_str()); int nFT = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["FT"]).c_str()); int nPressureState = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["PressureState"]).c_str()); int nCompPressureDEC = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["CompPressureDEC"]).c_str()); int nDepress = (atoi)(((string)m_InitDataFile["CONFIGURATION"]["Depress"]).c_str()); float fMechAngle = (atof)(((string)m_InitDataFile["CONFIGURATION"]["MechAngle"]).c_str()); float fMechHeight = (atof)(((string)m_InitDataFile["CONFIGURATION"]["MechHeight"]).c_str()); float fPressureValue = (atof)(((string)m_InitDataFile["CONFIGURATION"]["PressureValue"]).c_str()); float fAGD = (atof)(((string)m_InitDataFile["CONFIGURATION"]["AGD"]).c_str()); float fMAG = (atof)(((string)m_InitDataFile["CONFIGURATION"]["MAG"]).c_str()); m_pDriMechDev = new OemMechanical(std::shared_ptr(new IOEventCenter()), nGrid, nAE, nFT, nPressureState, nCompPressureDEC, nDepress, fMechAngle, fMechHeight, fPressureValue, fAGD, fMAG); } else m_pDriMechDev = new OemMechanical(std::shared_ptr(new IOEventCenter())); auto dev = std::unique_ptr (new IODevice(m_pDriMechDev)); m_pDriMechDev->SetCtrlDev(m_pDriGenDev); m_pDriGenDev->SetMechDev(m_pDriMechDev); //mLog::Info("Leave CreateDevice Mech"); return dev; } std::cout << "unknown index" << std::endl; //mLog::Error("unknown index"); unique_ptr dev; return dev; } void nsGEN::DemoDriver::FireNotify(int code, std::string key, std::string content) { EventCenter->OnNotify(code, key, content); } //Log4CPP::Logger* mLog::gLogger = nullptr; void nsGEN::DemoDriver::Prepare() { //string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Generator\Conf\Log4CPP.Config.GEN.xml)"; //Log4CPP::GlobalContext::Map::Set(ECOM::Utility::Hash("LogFileName"), "GEN.Demo"); //auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str()); ////mLog::gLogger = Log4CPP::LogManager::GetLogger("GEN.Demo"); ResDataObject r_config; if (r_config.loadFile(m_ConfigFileName.c_str())) { if(r_config["CONFIGURATION"].GetKeyCount("IsDemo")>0) { m_bDemoMode = (atoi)(((string)r_config["CONFIGURATION"]["IsDemo"]).c_str()); } } string strDataPath = GetProcessDirectory() + R"(\OEMDrivers\Generator\Demo\InitData.xml)"; try { if (m_InitDataFile.loadFile(strDataPath.c_str())) { m_bDemoInitDataFlag = true; //mLog::Info("exist InitData"); } //else //mLog::Info("can not open InitData[{$}]", strDataPath.c_str()); } catch (const ResDataObjectExption&) { //mLog::Error("open InitData failed"); } } bool nsGEN::DemoDriver::Connect() { m_bDemoConnected = true; return true; //return SCF_ERR::SCF_SUCCEED; } void nsGEN::DemoDriver::Disconnect() { //super::Disconnect(); //m_SCF.Disconnect(); m_bDemoConnected = false; } bool nsGEN::DemoDriver::isConnected() const { return m_bDemoConnected; } std::string nsGEN::DemoDriver::DriverProbe() { printf("line= %d,%s %s\n", __LINE__, __FUNCTION__, m_ConfigFileName.c_str()); 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", "DEMO"); HardwareInfo.add("ProductID", "HF"); HardwareInfo.add("SerialID", "1234"); } string ret = HardwareInfo.encode(); printf("line= %d,%s %s\n", __LINE__, __FUNCTION__, m_ConfigFileName.c_str()); return ret; } bool nsGEN::DemoDriver::GetDeviceConfig(std::string& Cfg) { //printf("line= %d,%s\n", __LINE__, __FUNCTION__); //Cfg = m_GenConfig.encode(); //return true; Cfg = m_DeviceConfigSend.encode(); printf("GetDeviceConfig over , %s", Cfg.c_str()); return true; } bool nsGEN::DemoDriver::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::DemoDriver::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::DemoDriver::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::DemoDriver::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("\n Begin 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::DemoDriver::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::DemoDriver::DeviceProbe() { printf("line= %d,%s\n", __LINE__, __FUNCTION__); 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", "DEMO"); HardwareInfo.add("ProductID", "HF"); HardwareInfo.add("SerialID", "1234"); } string ret = HardwareInfo.encode(); return ret; } void nsGEN::DemoDriver::Dequeue(const char* Packet, DWORD Length) { //DecodeFrame(Packet, Length); //无真实数据,此处直接空. } //In Demo mode ,will not enter here int nsGEN::DemoDriver::callbackPackageProcess(const char* RecData, DWORD nLength, DWORD& PacketLength) { return 0; } //----------------------------------------------------------------------------- // GetIODriver & CreateIODriver //----------------------------------------------------------------------------- static nsGEN::DemoDriver gIODriver; extern "C" CCOS::Dev::IODriver * GetIODriver() // 返回静态对象的引用, 调用者不能删除 ! { return &gIODriver; } extern "C" CCOS::Dev::IODriver * CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 ! { return new nsGEN::DemoDriver(); }