// CCOS.Dev.Generator.V2Adapter.cpp : 定义 DLL 应用程序的导出函数。 // /* 使用本类注意事项 1 必须有这样一个配置文件路径 (pGenConfig.Load(strAppPath + "\\V2AdapterDriver\\conf\\GenOprConf.xml")) //GenOprConf.xml中的配置,跟V2 一样。 2 Device\DriverConfig中的配置文件 应该叫做 V2Adapter.xml 里面的配置。 3 首先上层createdevice之后, 4 使用gentest.exe 调试的时候,把所有的依赖都放在了V2AdapterDriver 文件夹中。包含conf,各种v2的dll。以及2.0的adatperx64.dll的各种依赖。 5 使用dmoc测试时,上层点击时,下层没反应。后来使用ccos-gen-device-test.exe测试的,一切ok。 */ //关闭无关警告 #pragma warning (disable:4244) // warning C4244: “初始化”: 从“double”转换到“float”,可能丢失数据 #pragma warning (disable:4305) // warning C4305: “参数”: 从“double”到“float”截断 #pragma warning (disable:4267) // warning C4267 : “初始化”: 从“size_t”转换到“int”,可能丢失数据 #pragma warning (disable:4805) // warning C4805: “!=”: 在操作中将类型“bool”与类型“int”混合不安全 #include "stdafx.h" #include #include using namespace std::placeholders; #include "Helper.JSON.hpp" #include "scf.define.hpp" #include "CCOS.Dev.Generator.V2Adapter.h" using namespace CCOS::Dev::Detail::Generator; namespace nsGEN = CCOS::Dev::Detail::Generator; //V2静态头文件 #include "appsettings.h" #include "markup.h" #include "GEN_i.h" #ifdef _WIN64 #ifdef _DEBUG #pragma comment(lib, "GenOpr64.lib") //#pragma comment(lib, "DapOpr64.lib") //#pragma comment(lib, "SPROMEPS.LIB") #else #pragma comment(lib, "GenOpr64.lib") //#pragma comment(lib, "DapOpr64.lib") #endif #else #ifdef _DEBUG #pragma comment(lib, "GenOpr.lib") //#pragma comment(lib, "DapOpr.lib") #else #pragma comment(lib, "GenOpr.lib") //#pragma comment(lib, "DapOpr.lib") #endif #endif using namespace CCOS::Dev::Detail::Generator; namespace nsGEN = CCOS::Dev::Detail::Generator; Log4CPP::Logger* mLog::gLogger = nullptr; //device----------------------------------------- V2AdapterDevice::V2AdapterDevice(std::shared_ptr center, UIObject* UIobj) : super(center) { mLog::Debug("Enter [{$}]", __FUNCTION__); string version; if (GetVersion(version, hMyModule)) mLog::Debug("\n===============log begin : version:{$} ===================\n", version.c_str()); else mLog::Debug("\n===============log begin : version:0.0.0.0 ===================\n"); m_pUIOBJ = UIobj; m_bGenConnectState = false; m_bGetDensity = true; //设置发生器属性集合各个值的范围及精度 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, 1.0)); m_DoseUnit.m_MS.reset(new MSMould(0.0, 0.0, 10000.0, 1.0)); m_DoseUnit.m_MAS.reset(new MASMould(0.0, 0.0, 1000.0, 1.0)); m_DoseUnit.m_Techmode.reset(new TECHMODEMould(AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P, AttrKey::TECHMODE_NOAEC_3P, AttrKey::TECHMODE_AEC_MAS_MA, 1)); m_DoseUnit.m_WS.reset(new WORKSTATIONMould(AttrKey::WALL, AttrKey::TABLE, AttrKey::FREE_WALL, 1)); m_DoseUnit.m_Focus.reset(new FOCUSMould(AttrKey::FOCUS_SMALL, AttrKey::FOCUS_SMALL, AttrKey::FOCUS_AUTOMATIC, 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_GenSynState.reset(new GENSYNSTATEMould(AttrKey::GENERATOR_RAD_OFF, 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_DoseUnit.m_BatteryChargeState.reset(new BATTERYCHARGSTATEMould(0, 0, 1, 1)); m_DoseUnit.m_TubeTargetMaterial.reset(new TUBETARGETMATERIALMould(AttrKey::TUBETARGETMATERIAL_TYPE::MO)); m_DoseUnit.m_TubeAngle.reset(new TUBEANGLEMould(0, -45, 45, 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, 1)); m_DoseUnit.m_PostMS.reset(new POSTMSMould(0.0, 0.0, 10000.0, 1)); m_DoseUnit.m_PostMAS.reset(new POSTMASMould(0.0, 0.5, 1000.0, 1)); //发生器告警及错误消息 m_MSGUnit.reset(new nsDetail::MSGUnit(center, nsGEN::GeneratorUnitType)); //DAP参数上报 m_DAP.reset(new DevDAP::DOSEMould(0.0, 0.0, 1000.0, 0.01)); OnRegister(); m_pUIOBJ->Init(this,OnCallBack); mLog::Info("init:GENSTATE STATUS_SHUTDOWN -> STATUS_STANDBY"); m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY); Sleep(1000); GEN_GetST(); } V2AdapterDevice::~V2AdapterDevice() { mLog::Debug("Enter [{$}]", __FUNCTION__); m_pUIOBJ->Destrory(); } std::string nsGEN::V2AdapterDevice::GetGUID() const { mLog::Debug("Enter [{$}]", __FUNCTION__); mLog::Debug("\n===============GetGUID : [{$}] ===================", GeneratorUnitType); return GeneratorUnitType; } void nsGEN::V2AdapterDevice::OnRegister() { mLog::Debug("Enter [{$}]", __FUNCTION__); auto Disp = &Dispatch; superGen::Register(Disp); superGen::RegisterRAD(Disp); superGen::RegisterAEC(Disp); superGen::RegisterExpEnable(Disp); superGen::RegisterGeneratortoSyncStatus(Disp); Disp->Get.Push(m_MSGUnit->GetKey().c_str(), [this](std::string& out) { out = m_MSGUnit->JSGet(); return RET_STATUS::RET_SUCCEED; }); auto fun_Clear_DAP = [this](auto a, auto&) { return Clear_DAP(); }; Disp->Action.Push("Clear_DAP", fun_Clear_DAP); auto fun_GetValue_DAP = [this](auto a, auto& b) { float value = 0; RET_STATUS ret = GetValue_DAP(value); b = ToJSON(value); return ret; }; Disp->Action.Push("GetValue_DAP", fun_GetValue_DAP); } void nsGEN::V2AdapterDevice::FireNotify(std::string key, std::string content) { EventCenter->OnNotify(1, key, content); } RET_STATUS nsGEN::V2AdapterDevice::IncKV() { mLog::Debug("Enter [{$}]", __FUNCTION__); if (!m_DoseUnit.m_KV->CanInc()) return RET_STATUS::RET_SUCCEED; if (GEN_INCKV()) { mLog::Debug("GEN_INCKV Succeed"); return RET_STATUS::RET_SUCCEED; } return RET_STATUS::RET_FAILED; } RET_STATUS nsGEN::V2AdapterDevice::DecKV() { mLog::Debug("Enter [{$}]", __FUNCTION__); if (!m_DoseUnit.m_KV->CanDec()) return RET_STATUS::RET_SUCCEED; if (GEN_DECKV()) { mLog::Debug("GEN_DECKV Succeed"); return RET_STATUS::RET_SUCCEED; } return RET_STATUS::RET_FAILED; } RET_STATUS nsGEN::V2AdapterDevice::SetKV(float value) { mLog::Debug("Enter [{$}]:[{$}]", __FUNCTION__, value); if (!m_DoseUnit.m_KV->Verify(value)) return RET_STATUS::RET_SUCCEED; if ( GEN_SetKV(value)) { mLog::Debug("GEN_SetKV Succeed[{$}]", value); return RET_STATUS::RET_SUCCEED; } return RET_STATUS::RET_FAILED; } RET_STATUS nsGEN::V2AdapterDevice::IncMA() { mLog::Debug("Enter [{$}]", __FUNCTION__); if (!m_DoseUnit.m_MA->CanInc()) return RET_STATUS::RET_SUCCEED; if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS) { mLog::Debug("Techmode is MAS, can't inc MA"); return RET_STATUS::RET_FAILED; } if (GEN_INCMA()) { mLog::Debug("GEN_INCMA Succeed"); return RET_STATUS::RET_SUCCEED; } return RET_STATUS::RET_FAILED; } RET_STATUS nsGEN::V2AdapterDevice::DecMA() { mLog::Debug("Enter [{$}]", __FUNCTION__); if (!m_DoseUnit.m_MA->CanDec()) return RET_STATUS::RET_SUCCEED; if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS) { mLog::Debug("Techmode is MAS, can't dec MA"); return RET_STATUS::RET_FAILED; } if (GEN_DECMA()) { mLog::Debug("GEN_DECMA Succeed"); return RET_STATUS::RET_SUCCEED; } return RET_STATUS::RET_FAILED; } RET_STATUS nsGEN::V2AdapterDevice::SetMA(float value) { mLog::Debug("Enter [{$}]:[{$}]", __FUNCTION__, value); if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED; if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS) { mLog::Debug("Techmode is MAS, can't set MA"); return RET_STATUS::RET_FAILED; } if (GEN_SetMA(value)) { mLog::Debug("GEN_SetMA Succeed[{$}]", value); return RET_STATUS::RET_SUCCEED; } return RET_STATUS::RET_FAILED; } RET_STATUS nsGEN::V2AdapterDevice::IncMS() { mLog::Debug("Enter [{$}]", __FUNCTION__); if (!m_DoseUnit.m_MS->CanInc()) return RET_STATUS::RET_SUCCEED; if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS) { mLog::Debug("Techmode is MAS, can't inc MS"); return RET_STATUS::RET_FAILED; } if ( GEN_INCMS()) { mLog::Debug("GEN_INCMS Succeed"); return RET_STATUS::RET_SUCCEED; } return RET_STATUS::RET_FAILED; } RET_STATUS nsGEN::V2AdapterDevice::DecMS() { mLog::Debug("Enter [{$}]", __FUNCTION__); if (!m_DoseUnit.m_MS->CanDec()) return RET_STATUS::RET_SUCCEED; if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS) { mLog::Debug("Techmode is MAS, can't dec MS"); return RET_STATUS::RET_FAILED; } if (GEN_DECMS()) { mLog::Debug("GEN_DECMS Succeed"); return RET_STATUS::RET_SUCCEED; } return RET_STATUS::RET_FAILED; } RET_STATUS nsGEN::V2AdapterDevice::SetMS(float value) { mLog::Debug("Enter [{$}]:[{$}]", __FUNCTION__, value); if (!m_DoseUnit.m_MS->Verify(value)) return RET_STATUS::RET_SUCCEED; if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS) { mLog::Debug("Techmode is MAS, can't set MS"); return RET_STATUS::RET_FAILED; } if (GEN_SetMS(value)) { mLog::Debug("GEN_SetMS Succeed[{$}]", value); return RET_STATUS::RET_SUCCEED; } return RET_STATUS::RET_FAILED; } RET_STATUS nsGEN::V2AdapterDevice::IncMAS() { mLog::Debug("Enter [{$}]", __FUNCTION__); if (!m_DoseUnit.m_MAS->CanInc()) return RET_STATUS::RET_SUCCEED; if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS) { mLog::Debug("Techmode is not MAS, can't inc MAS"); return RET_STATUS::RET_FAILED; } if ( GEN_INCMAS()) { mLog::Debug("GEN_INCMAS Succeed"); return RET_STATUS::RET_SUCCEED; } return RET_STATUS::RET_FAILED; } RET_STATUS nsGEN::V2AdapterDevice::DecMAS() { mLog::Debug("Enter [{$}]", __FUNCTION__); if (!m_DoseUnit.m_MAS->CanDec()) return RET_STATUS::RET_SUCCEED; if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS) { mLog::Debug("Techmode is not MAS, can't dec MAS"); return RET_STATUS::RET_FAILED; } if (GEN_DECMAS()) { mLog::Debug("GEN_DECMAS Succeed"); return RET_STATUS::RET_SUCCEED; } return RET_STATUS::RET_FAILED; } RET_STATUS nsGEN::V2AdapterDevice::SetMAS(float value) { mLog::Debug("Enter [{$}]:[{$}]", __FUNCTION__, value); if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED; if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS) { mLog::Debug("Techmode is not MAS, can't set MAS"); return RET_STATUS::RET_FAILED; } if (GEN_SetMAS(value)) { mLog::Debug("GEN_SetMAS Succeed[{$}]", value); return RET_STATUS::RET_SUCCEED; } return RET_STATUS::RET_FAILED; } RET_STATUS nsGEN::V2AdapterDevice::SetTechmode(int techmode) { mLog::Debug("Enter [{$}]:[{$}]", __FUNCTION__, techmode); if (!m_DoseUnit.m_Techmode->Verify(techmode)) return RET_STATUS::RET_SUCCEED; if (GEN_SetTechMode(techmode)) { mLog::Debug("GEN_SetTechMode Succeed"); return RET_STATUS::RET_SUCCEED; } return RET_STATUS::RET_FAILED; } RET_STATUS nsGEN::V2AdapterDevice::SetFocus(int value) { mLog::Debug("Enter [{$}]:[{$}]", __FUNCTION__,value); if (!m_DoseUnit.m_Focus->Verify(value)) return RET_STATUS::RET_SUCCEED; if (GEN_SetFocusSel(value)) { mLog::Debug("GEN_SetFocusSel Succeed"); return RET_STATUS::RET_SUCCEED; } return RET_STATUS::RET_FAILED; } RET_STATUS nsGEN::V2AdapterDevice::SetAECDensity(int value) { mLog::Debug("Enter [{$}]:[{$}]", __FUNCTION__, value); if (!m_DoseUnit.m_AECDensity->Verify(value)) return RET_STATUS::RET_SUCCEED; if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_AEC) { mLog::Debug("Techmode is not AEC, can't set AECDensity"); return RET_STATUS::RET_FAILED; } if (GEN_SetAECDensity(value)) { mLog::Debug("GEN_SetAECDensity Succeed[{$}]", value); return RET_STATUS::RET_SUCCEED; } return RET_STATUS::RET_FAILED; } RET_STATUS nsGEN::V2AdapterDevice::SetAECField(int value) { mLog::Debug("Enter [{$}]:[{$}]", __FUNCTION__,value); if (!m_DoseUnit.m_AECField->Verify(value)) return RET_STATUS::RET_SUCCEED; if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_AEC) { mLog::Debug("Techmode is not AEC, can't set AECField"); return RET_STATUS::RET_FAILED; } if (GEN_SetAECField(value)) { mLog::Debug("GEN_SetAECField Succeed[{$}]", value); return RET_STATUS::RET_SUCCEED; } return RET_STATUS::RET_FAILED; } RET_STATUS nsGEN::V2AdapterDevice::SetAECFilm(int value) { mLog::Debug("Enter [{$}]:[{$}]", __FUNCTION__, value); if (!m_DoseUnit.m_AECFilm->Verify(value)) return RET_STATUS::RET_SUCCEED; if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_AEC) { mLog::Debug("Techmode is not AEC, can't set AECFilm"); return RET_STATUS::RET_FAILED; } if (value == 1) { //low return GEN_SetAECFilm(1) ? RET_STATUS::RET_SUCCEED : RET_STATUS::RET_FAILED; } else if (value == 2) { //mid return GEN_SetAECFilm(10) ? RET_STATUS::RET_SUCCEED : RET_STATUS::RET_FAILED; } else if (value == 3) { //high return GEN_SetAECFilm(100) ? RET_STATUS::RET_SUCCEED : RET_STATUS::RET_FAILED; } else { //do nothing... } return RET_STATUS::RET_FAILED; } RET_STATUS nsGEN::V2AdapterDevice::SetWS(const string value) { mLog::Debug("Enter [{$}]:[{$}]", __FUNCTION__,value.c_str()); int tempws = 0; if (value == "Table") tempws = 0; else if (value == "Wall") tempws = 1; else if (value == "Direct") tempws = 2; else if (value == "Free") tempws = 3; m_DoseUnit.m_WS->Update(tempws); if (GEN_SetWorkStation(tempws)) { mLog::Debug("GEN_SetWorkStation Succeed[{$}]", tempws); return RET_STATUS::RET_SUCCEED; } return RET_STATUS::RET_FAILED; } RET_STATUS nsGEN::V2AdapterDevice::SetAPR(const _tAPRArgs& t) { mLog::Debug("Enter [{$}]:KV={$},MA={$},MS={$},MAS={$},Focus={$},Techmode={$},WS={$},AECDensity={$},AECField={$},AECFilm={$}", __FUNCTION__, t.fKV, t.fMA, t.fMS, t.fMAS, t.nFocus, t.nTechmode, t.nWS, t.nAECDensity, t.nAECField, t.nAECFilm); float Dencity = t.nAECDensity; float kv = t.fKV; //正常的版本如下!!!! INT ws = m_DoseUnit.m_WS->Get(); if (GEN_SetAPR(ws, t.nFocus, t.nTechmode, t.nAECField, t.nAECFilm, Dencity, kv, t.fMA, t.fMS, t.fMAS)) { mLog::Debug("SetAPR Succeed"); return RET_STATUS::RET_SUCCEED; } mLog::Debug("SetAPR Failed"); return RET_STATUS::RET_FAILED; } RET_STATUS nsGEN::V2AdapterDevice::QueryHE(int& value) { mLog::Debug("Enter [{$}]", __FUNCTION__); GEN_GetHE(); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::V2AdapterDevice::QueryPostKV(float& value) { mLog::Debug("Enter [{$}]", __FUNCTION__); value = m_DoseUnit.m_PostKV->Get(); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::V2AdapterDevice::QueryPostMA(float& value) { mLog::Debug("Enter [{$}]", __FUNCTION__); value = m_DoseUnit.m_PostMA->Get(); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::V2AdapterDevice::QueryPostMS(float& value) { mLog::Debug("Enter [{$}]", __FUNCTION__); GEN_GetAT(); value = m_DoseUnit.m_PostMS->Get(); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::V2AdapterDevice::QueryPostMAS(float& value) { mLog::Debug("Enter [{$}]", __FUNCTION__); GEN_GetAP(); value = m_DoseUnit.m_PostMAS->Get(); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::V2AdapterDevice::Clear_DAP() { mLog::Debug("Enter [{$}]", __FUNCTION__); GEN_ClearDAP(); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::V2AdapterDevice::GetValue_DAP(float& value) { mLog::Debug("Enter [{$}]", __FUNCTION__); GEN_GetDAP(); return RET_STATUS::RET_FAILED; } RET_STATUS nsGEN::V2AdapterDevice::SetGenSynState(int value) { mLog::Debug("Enter [{$}]:do noting", __FUNCTION__); //if (m_DoseUnit.m_GenSynState->Update(value)) //{ // FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet()); //} return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::V2AdapterDevice::SetGenState(int value) { mLog::Debug("Enter [{$}]:do noting", __FUNCTION__); //if (m_DoseUnit.m_GenState->Update(value)) //{ // FireNotify(m_DoseUnit.m_GenState->GetKey(), m_DoseUnit.m_GenState->JSGet()); //} return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::V2AdapterDevice::SetExpEnable() { mLog::Debug("Enter [{$}]", __FUNCTION__); return GEN_EnableExp() ? RET_STATUS::RET_SUCCEED : RET_STATUS::RET_FAILED; } RET_STATUS nsGEN::V2AdapterDevice::SetExpDisable() { mLog::Debug("Enter [{$}]", __FUNCTION__); return GEN_DisableExp() ? RET_STATUS::RET_SUCCEED : RET_STATUS::RET_FAILED; } RET_STATUS nsGEN::V2AdapterDevice::Reset() { mLog::Debug("Enter [{$}]", __FUNCTION__); return GEN_SetRE(1) ? RET_STATUS::RET_SUCCEED : RET_STATUS::RET_FAILED; } RET_STATUS nsGEN::V2AdapterDevice::SetExpMode(std::string value) { mLog::Debug("Enter [{$}]", __FUNCTION__); if(m_DoseUnit.m_ExpMode->Update(value)) FireNotify(m_DoseUnit.m_ExpMode->GetKey(), m_DoseUnit.m_ExpMode->JSGet()); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::V2AdapterDevice::SetFrameRate(FLOAT frameRate) { mLog::Debug("Enter [{$}]:do noting", __FUNCTION__); if (m_DoseUnit.m_FrameRate->Update(frameRate)) FireNotify(m_DoseUnit.m_FrameRate->GetKey(), m_DoseUnit.m_FrameRate->JSGet()); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::V2AdapterDevice::SetModality(std::string value) { mLog::Debug("Enter [{$}]", __FUNCTION__); if(m_DoseUnit.m_Modality->Update(value)) FireNotify(m_DoseUnit.m_Modality->GetKey(), m_DoseUnit.m_Modality->JSGet()); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::V2AdapterDevice::SetFLFMode(std::string value) { mLog::Debug("Enter [{$}]", __FUNCTION__); int mode = atoi(value.c_str()); if (m_DoseUnit.m_FLMode->Update(mode)) FireNotify(m_DoseUnit.m_FLMode->GetKey(), m_DoseUnit.m_FLMode->JSGet()); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::V2AdapterDevice::SetEXAMMode(std::string value) { mLog::Debug("Enter [{$}]", __FUNCTION__); if (m_DoseUnit.m_ExpMode->Update(value)) FireNotify(m_DoseUnit.m_ExpMode->GetKey(), m_DoseUnit.m_ExpMode->JSGet()); return RET_STATUS::RET_SUCCEED; } LRESULT CALLBACK nsGEN::V2AdapterDevice::OnCallBack(void* obj, UINT message, WPARAM wParam, LPARAM lParam) { V2AdapterDevice *unit = (V2AdapterDevice*)obj; if (unit == nullptr) { mLog::Info("Enter OnCallBack: V2AdapterDevice is null"); return false; } int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; mLog::Debug("Enter OnCallBack: message[{$}],wParam[{$}],lParam[{$}]", (int)message, (int)wParam, (int)lParam); switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // 分析菜单选择: switch (wmId) { case 0: return DefWindowProc(unit->m_pUIOBJ->GetUI(), message, wParam, lParam); break; default: return DefWindowProc(unit->m_pUIOBJ->GetUI(), message, wParam, lParam); } break; case WM_CREATE: SetTimer(unit->m_pUIOBJ->GetUI(), 1, 5000, NULL); break; case WM_PAINT: hdc = BeginPaint(unit->m_pUIOBJ->GetUI(), &ps); // TODO: 在此添加任意绘图代码... EndPaint(unit->m_pUIOBJ->GetUI(), &ps); break; case WM_DESTROY: KillTimer(unit->m_pUIOBJ->GetUI(), 1); PostQuitMessage(0); break; case MSG_GEN_PARAM: mLog::Debug("recv MSG_GEN_PARAM into ONGenParam"); return unit->ONGenParam(wParam, lParam); break; case MSG_GEN_INFO_DISEXP: mLog::Debug("recv MSG_GEN_INFO_DISEXP into ONGenExpDisable"); return unit->ONGenExpDisable(wParam, lParam); break; case MSG_GEN_EXPOSURE: mLog::Debug("recv MSG_GEN_EXPOSURE into ONGenExp"); return unit->ONGenExp(wParam, lParam); break; case MSG_GEN_ERR: mLog::Debug("recv MSG_GEN_ERR into ONGenError"); return unit->ONGenError(wParam, lParam); break; case MSG_GEN_WARN: mLog::Debug("recv MSG_GEN_WARN into ONGenWarn"); return unit->ONGenWarn(wParam, lParam); break; case WM_TIMER: mLog::Debug("recv WM_TIMER"); GEN_GetHE(); GEN_GetDAP(); break; case MSG_SYN_FILTER: mLog::Debug("recv MSG_SYN_FILTER into MSG_SYN_FILTER"); return unit->ONSyncParam(wParam, lParam); break; case MSG_SYN_COLLIMATOR: mLog::Debug("recv MSG_SYN_COLLIMATOR into ONSyncCollimatorParam"); return unit->ONSyncCollimatorParam(wParam, lParam); break; case MSG_SYN_STATUS: mLog::Debug("recv MSG_SYN_STATUS into ONSyncStatusParam"); return unit->ONSyncStatusParam(wParam, lParam); break; case MSG_SYN_GRID: mLog::Debug("recv MSG_SYN_GRID into ONGridStatusParam"); return unit->ONGridStatusParam(wParam, lParam); case MSG_SYN_SID: mLog::Debug("recv MSG_SYN_SID into ONSyncSid"); return unit->ONSyncSid(wParam, lParam); break; default: mLog::Debug("recv [{$}] unknown", (int)message); return DefWindowProc(unit->m_pUIOBJ->GetUI(), message, wParam, lParam); } return 0; } LRESULT nsGEN::V2AdapterDevice::ONGridStatusParam(WPARAM wParam, LPARAM lParam) { //MechV2 *pMech = GetMech(); //if (pMech == 0) //{ // mLog::Debug("no device exist on cmd[{$}]", wParam); // mLog::Debug("no device exist on cmd[{$}]", wParam); // return 0; //} //pMech->MechV2::SetGrid((int)wParam); return 0; } LRESULT nsGEN::V2AdapterDevice::ONSyncSid(WPARAM wParam, LPARAM lParam) { //CollimatorLogic *pColi = GetCollimator(); //if (pColi == 0) //{ // mLog::Debug("no device exist on cmd[{$}]", wParam); // mLog::Debug("no device exist on cmd[{$}]", wParam); // return 0; //} //WORD sid = (WORD)wParam; //pColi->CollimatorLogic::SetCollimatorSID(sid); return 0; } LRESULT nsGEN::V2AdapterDevice::ONSyncStatusParam(WPARAM wParam, LPARAM lParam) { switch (wParam) { case SYN_GEN_PREPARE: mLog::Debug("Gen EXPO status[RAD_PREPARE] PR1"); if(m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_PREPARE)) FireNotify(AttrKey::GENSYNSTATE, m_DoseUnit.m_GenSynState->JSGet()); break; case SYN_GEN_READY: mLog::Debug("Gen EXPO status[RAD_READY] PR2"); if(m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_READY)) FireNotify(AttrKey::GENSYNSTATE, m_DoseUnit.m_GenSynState->JSGet()); break; case SYN_GEN_OVER: mLog::Debug("Gen EXPO status[RAD_OFF] PR0"); if(m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF)) FireNotify(AttrKey::GENSYNSTATE, m_DoseUnit.m_GenSynState->JSGet()); GEN_GetAP(); break; case SYN_GEN_EIPON: mLog::Debug("Gen EXPO status[XRAYON] XR1"); if(m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON)) FireNotify(AttrKey::GENSYNSTATE, m_DoseUnit.m_GenSynState->JSGet()); break; case SYN_GEN_EIPOFF: mLog::Debug("Gen EXPO status[XRAYOFF] XR0"); if(m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYOFF)) FireNotify(AttrKey::GENSYNSTATE, m_DoseUnit.m_GenSynState->JSGet()); break; default: mLog::Debug("unknown cmd[{$}]", (int)wParam); return 0; break; } return 0; } LRESULT nsGEN::V2AdapterDevice::ONSyncCollimatorParam(WPARAM wParam, LPARAM lParam) { //CollimatorLogic *pDev = GetCollimator(); //if (pDev == 0) //{ // return 0; //} //ECOM_COLLIMATOR_INFO *pInfo = (ECOM_COLLIMATOR_INFO*)wParam; ////wparam //pDev->CollimatorLogic::SetCollimatorSize((WORD)pInfo->fWidth, (WORD)pInfo->fHeight);; return 0; } LRESULT nsGEN::V2AdapterDevice::ONSyncParam(WPARAM wParam, LPARAM lParam) { //CollimatorLogic *pDev = GetCollimator(); //if (pDev == 0) //{ // return 0; //} ////wparam //pDev->CollimatorLogic::SetCollimatorFilter((WORD)wParam); return 0; } //MSG_GEN_PARAM LRESULT nsGEN::V2AdapterDevice::ONGenParam(WPARAM wParam, LPARAM lParam) { switch (wParam) { case GEN_PARAM_KV: { int iKV = (int)lParam; mLog::Debug("GEN_PARAM_KV[{$}]", iKV); if (m_DoseUnit.m_KV->Update(iKV)) { FireNotify(AttrKey::KV, m_DoseUnit.m_KV->JSGet()); mLog::Debug("SetKV OnNotify[{$}]", iKV); } break; } case GEN_PARAM_KV_V2: { float fKV = *(float*)lParam; mLog::Debug("GEN_PARAM_KV_V2[{$}]", fKV); if (m_DoseUnit.m_KV->Update(fKV)) { FireNotify(AttrKey::KV, m_DoseUnit.m_KV->JSGet()); mLog::Debug("SetKV2 OnNotify[{$}]", fKV); } break; } case GEN_PARAM_AK: { float fKV = *(float*)lParam; mLog::Debug("GEN_PARAM_AK[{$}]", fKV); if (m_DoseUnit.m_PostKV->Update(fKV)) { FireNotify(AttrKey::POSTKV, m_DoseUnit.m_PostKV->JSGet()); mLog::Debug("postKV OnNotify[{$}]", fKV); } break; } case GEN_PARAM_FO: { int m_nFocus = (int)lParam; mLog::Debug("GEN_PARAM_FO[{$}]", m_nFocus); if (m_nFocus == GEN_SMALL_FOCUS) { if (m_DoseUnit.m_Focus->Update(AttrKey::FOCUS_TYPE::FOCUS_SMALL)) { FireNotify(AttrKey::FOCUS, m_DoseUnit.m_Focus->JSGet()); mLog::Debug("Focus notify[{$}]", m_nFocus); } } else if (m_nFocus == GEN_LARGE_FOCUS) { if (m_DoseUnit.m_Focus->Update(AttrKey::FOCUS_TYPE::FOCUS_LARGE)) { FireNotify(AttrKey::FOCUS, m_DoseUnit.m_Focus->JSGet()); mLog::Debug("Focus notify[{$}]", m_nFocus); } } else if (m_nFocus == GEN_AUTO_FOCUS) { if (m_DoseUnit.m_Focus->Update(AttrKey::FOCUS_TYPE::FOCUS_AUTOMATIC)) { FireNotify(AttrKey::FOCUS, m_DoseUnit.m_Focus->JSGet()); mLog::Debug("Focus notify[{$}]", m_nFocus); } } else { mLog::Debug("focus is wrong.[{$}]", m_nFocus); } } break; case GEN_PARAM_MA: { float m_fmA = *(float*)lParam; mLog::Debug("GEN_PARAM_MA[{$}]", m_fmA); if (m_DoseUnit.m_MA->Update(m_fmA)) { FireNotify(AttrKey::MA, m_DoseUnit.m_MA->JSGet()); } } break; case GEN_PARAM_AM: { float m_fmA = *(float*)lParam; mLog::Debug("GEN_PARAM_AM[{$}]", m_fmA); if (m_DoseUnit.m_PostMA->Update(m_fmA)) { FireNotify(AttrKey::POSTMA, m_DoseUnit.m_PostMA->JSGet()); } } break; case GEN_PARAM_MS: { float m_fms = *(float*)lParam; mLog::Debug("GEN_PARAM_MS[{$}]", m_fms); if (m_DoseUnit.m_MS->Update(m_fms)) { FireNotify(AttrKey::MS, m_DoseUnit.m_MS->JSGet()); } } break; case GEN_PARAM_AT: { float m_fms = *(float*)lParam; mLog::Debug("GEN_PARAM_AT[{$}]", m_fms); if (m_DoseUnit.m_PostMS->Update(m_fms)) { FireNotify(AttrKey::POSTMS, m_DoseUnit.m_PostMS->JSGet()); } } break; case GEN_PARAM_MAS: { float m_fmas = *(float*)lParam; mLog::Debug("GEN_PARAM_MAS[{$}]", m_fmas); if (m_DoseUnit.m_MAS->Update(m_fmas)) { FireNotify(AttrKey::MAS, m_DoseUnit.m_MAS->JSGet()); mLog::Debug("mas notify[{$}]", m_fmas); } } break; case GEN_PARAM_AP: { float m_fmAs = *(float*)lParam; mLog::Debug("GEN_PARAM_AP[{$}]", m_fmAs); if (m_DoseUnit.m_PostMAS->Update(m_fmAs)) { FireNotify(AttrKey::POSTMAS, m_DoseUnit.m_PostMAS->JSGet()); } } break; case GEN_PARAM_HE: { int m_nHE = (int)lParam; mLog::Debug("GEN_PARAM_HE[{$}]", m_nHE); if (m_DoseUnit.m_HE->Update(m_nHE)) { FireNotify(AttrKey::TUBEHEAT, m_DoseUnit.m_HE->JSGet()); } } break; case GEN_PARAM_DAP: { int dap = (int)lParam; mLog::Debug("GEN_PARAM_DAP : SetDAP OnNotify[{$}] dGycm^2", dap); if (m_DAP->Update(dap)) { FireNotify(DevDAP::AttrKey::DAP, m_DAP->JSGet()); mLog::Debug("GEN_PARAM_DAP[{$}]", dap); } break; } case GEN_PARAM_DAP_V2: { float fDAP = (*(float*)lParam); float fdap = (fDAP / 100.0); mLog::Debug("GEN_PARAM_DAP_V2[{$}]", fdap); mLog::Debug("SetDAP V2 OnNotify[{$}] dGycm^2", fdap); if (m_DAP->Update(fdap)) { FireNotify(DevDAP::AttrKey::DAP, m_DAP->JSGet()); mLog::Debug("GEN_PARAM_DAP_V2[{$}]", fdap); } break; } case GEN_PARAM_DRF: { float fDRF = (*(float*)lParam); mLog::Debug("SetDRF OnNotify[{$}] dGy*cm^2/s", fDRF); if (m_DAP->Update(fDRF)) { FireNotify(DevDAP::AttrKey::DAP, m_DAP->JSGet()); }; break; } case GEN_PARAM_FS: //film { int m_nAECFilm = (int)lParam; mLog::Debug("GEN_PARAM_FS[{$}] ", m_nAECFilm); if (m_nAECFilm == 100) { //高 if (m_DoseUnit.m_AECFilm->Update(2)) //FILM_FAST { FireNotify(AttrKey::AECFILM, m_DoseUnit.m_PostMA->JSGet()); } } else if (m_nAECFilm == 10) { //中 if (m_DoseUnit.m_AECFilm->Update(1)) //FILM_MEDIUM { FireNotify(AttrKey::AECFILM, m_DoseUnit.m_PostMA->JSGet()); } } else { //低 if (m_DoseUnit.m_AECFilm->Update(0)) //FILM_SLOW { FireNotify(AttrKey::AECFILM, m_DoseUnit.m_PostMA->JSGet()); } } } break; case GEN_PARAM_FI: //fild { int m_nAECField = (int)lParam; mLog::Debug("GEN_PARAM_FI[{$}] ", m_nAECField); if (m_DoseUnit.m_AECField->Update(m_nAECField)) { FireNotify(AttrKey::AECFIELD, m_DoseUnit.m_PostMA->JSGet()); } } break; case GEN_PARAM_FN: { int m_nAECDensity = (int)lParam; mLog::Debug("GEN_PARAM_FN[{$}] ", m_nAECDensity); if (m_DoseUnit.m_AECDensity->Update(m_nAECDensity)) { FireNotify(AttrKey::AECDENSITY, m_DoseUnit.m_AECDensity->JSGet()); } break; } case GEN_PARAM_FN_V2: { int m_nAECDensity = (int)lParam; mLog::Debug("GEN_PARAM_FN_V2[{$}] ", m_nAECDensity); if (m_DoseUnit.m_AECDensity->Update(m_nAECDensity)) { FireNotify(AttrKey::AECDENSITY, m_DoseUnit.m_AECDensity->JSGet()); } break; } case GEN_PARAM_WS: { int m_nWorkStation = (int)lParam; mLog::Debug("GEN_PARAM_WS[{$}] ", m_nWorkStation); if (m_DoseUnit.m_WS->Update(m_nWorkStation)) { FireNotify(AttrKey::WORKSTATION, m_DoseUnit.m_PostMA->JSGet()); } if (m_nWorkStation == GEN_WS_TABLE) { if (m_DoseUnit.m_WS->Update(AttrKey::GENWS_TYPE::TABLE)) { FireNotify(AttrKey::WORKSTATION, m_DoseUnit.m_WS->JSGet()); } } else if (m_nWorkStation == GEN_WS_WALL) { if (m_DoseUnit.m_WS->Update(AttrKey::GENWS_TYPE::WALL)) { FireNotify(AttrKey::WORKSTATION, m_DoseUnit.m_WS->JSGet()); } } else if (m_nWorkStation == GEN_WS_CONVENTIONAL) { if (m_DoseUnit.m_WS->Update(AttrKey::GENWS_TYPE::CONVENTIONAL)) { FireNotify(AttrKey::WORKSTATION, m_DoseUnit.m_WS->JSGet()); } } else if (m_nWorkStation == GEN_WS_MOBILE) { if (m_DoseUnit.m_WS->Update(AttrKey::GENWS_TYPE::MOBILE)) { FireNotify(AttrKey::WORKSTATION, m_DoseUnit.m_WS->JSGet()); } } else if (m_nWorkStation == GEN_WS_TOMO) { if (m_DoseUnit.m_WS->Update(AttrKey::GENWS_TYPE::TOMO)) { FireNotify(AttrKey::WORKSTATION, m_DoseUnit.m_WS->JSGet()); } } else { if (m_DoseUnit.m_WS->Update(AttrKey::GENWS_TYPE::CONVENTIONAL)) { FireNotify(AttrKey::WORKSTATION, m_DoseUnit.m_WS->JSGet()); } } } break; case GEN_PARAM_ET: //tech mode { int m_nET = (int)lParam; mLog::Debug("GEN_PARAM_ET[{$}] ", m_nET); if (m_DoseUnit.m_Techmode->Update(m_nET)) { FireNotify(AttrKey::TECHMODE, m_DoseUnit.m_Techmode->JSGet()); } } break; case GEN_PARAM_MAMMO_AE: { int AE = (int)lParam; mLog::Debug("GEN_PARAM_MAMMO_AE[{$}] ", AE); } break; case GEN_PARAM_MAMMO_FT: { int FT = (int)lParam; mLog::Debug("GEN_PARAM_MAMMO_FT[{$}] ", FT); } break; case GEN_PARAM_MAMMO_PRESSURESTATE: { int PS = (int)lParam; mLog::Debug("GEN_PARAM_MAMMO_PRESSURESTATE[{$}] ", PS); } break; case GEN_PARAM_MAMMO_MAMMOMECHNICALANGLE: { float Val = *(float*)lParam; mLog::Debug("GEN_PARAM_MAMMO_MAMMOMECHNICALANGLE[{$}] ", Val); } break; case GEN_PARAM_MAMMO_MAMMMECHNICALHEIGH: { float Val = *(float*)lParam; mLog::Debug("GEN_PARAM_MAMMO_MAMMMECHNICALHEIGH[{$}] ", Val); } break; case GEN_PARAM_MAMMO_MAMMOPRESSUREVALUE: { float Val = *(float*)lParam; mLog::Debug("GEN_PARAM_MAMMO_MAMMOPRESSUREVALUE[{$}] ", Val); } break; case GEN_PARAM_MAMMO_MAMMOAGD: { float Val = *(float*)lParam; mLog::Debug("GEN_PARAM_MAMMO_MAMMOAGD[{$}] ", Val); } break; case GEN_PARAM_MAMMO_MAG: { float Val = *(float*)lParam; mLog::Debug("GEN_PARAM_MAMMO_MAG[{$}] ", Val); break; } case GEN_PARAM_MAMMO_DEPRESS: { int Val = (int)lParam; mLog::Debug("GEN_PARAM_MAMMO_DEPRESS[{$}] ", Val); break; } case GEN_PARAM_MAMMO_POSITIONCODE: { int m_nPositionCode = (int)lParam; mLog::Debug("GEN_PARAM_MAMMO_DEPRESS[{$}] ", m_nPositionCode); break; } case GEN_TUBEHU_STATUS: { int nHU = (int)lParam; mLog::Debug("GEN_TUBEHU_STATUS[{$}]", nHU); break; } default: mLog::Warn("ONGenParam default: wp[{$}], lp[{$}]", (int)wParam, (int)lParam); break; } return 0L; } LRESULT nsGEN::V2AdapterDevice::ONGenExpDisable(WPARAM wParam, LPARAM lParam) { CString strNotify, ResInfo; strNotify.Format(_T("ExpErrCode_%s"), *(CString*)wParam); ResInfo.Format(_T("ExpErrInfo: %s"), *(CString*)lParam); //exption int level = 0; if (strNotify == "ExpErrCode_") { int Level = 3;//error mLog::Error("add {$}:{$}", strNotify.GetBuffer(), ResInfo.GetBuffer()); m_MSGUnit->DelErrorMessage("", level, ResInfo); } else { int Level = 3;//error mLog::Error("add {$}:{$}", strNotify.GetBuffer(), ResInfo.GetBuffer()); m_MSGUnit->AddErrorMessage(strNotify, level, ResInfo); } return 0; } LRESULT nsGEN::V2AdapterDevice::ONGenExp(WPARAM wParam, LPARAM lParam) { switch (wParam) { case PREPRESS: //1档 mLog::Debug("L1 HSW down"); if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_PREPARE)) { FireNotify(AttrKey::GENSYNSTATE, m_DoseUnit.m_GenSynState->JSGet()); } break; case TUBEREADY: //2档 mLog::Debug("L1 Tube ready"); if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_READY)) { FireNotify(AttrKey::GENSYNSTATE, m_DoseUnit.m_GenSynState->JSGet()); } break; case XRAYON: mLog::Debug("L1 HSW down and Xray on"); if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON)) { FireNotify(AttrKey::GENSYNSTATE, m_DoseUnit.m_GenSynState->JSGet()); } if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_EXP)) { mLog::Info("init:GENSTATE STATUS_STANDBY -> STATUS_EXP"); FireNotify(AttrKey::GENSYNSTATE, m_DoseUnit.m_GenSynState->JSGet()); } break; case XRAYOFF: mLog::Debug("Xray off"); if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYOFF)) { FireNotify(AttrKey::GENSYNSTATE, m_DoseUnit.m_GenSynState->JSGet()); } break; case RELEASE: //1,2松开 mLog::Debug("Hsw release"); if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF)) { FireNotify(AttrKey::GENSYNSTATE, m_DoseUnit.m_GenSynState->JSGet()); } if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY)) { mLog::Info("init:GENSTATE STATUS_EXP -> STATUS_STANDBY"); FireNotify(AttrKey::GENSYNSTATE, m_DoseUnit.m_GenSynState->JSGet()); } break; case STANDBY://ignore break; case GEN_PARAM_ST://ignore break; case GEN_PARAM_RE://ignore break; default: mLog::Warn("Enter ONGenExp default: wp[{$}], lp[{$}]", (int)wParam, (int)lParam); break; } return 0L; } LRESULT nsGEN::V2AdapterDevice::ONGenError(WPARAM wParam, LPARAM lParam) { CString strNotify, ResInfo; strNotify.Format(_T("ErrCode_%s"), *(CString*)wParam); ResInfo.Format(_T("ErrInfo: %s"), *(CString*)lParam); //exption int level = 0; if (strNotify == "ErrCode_") { int Level = 3;//error mLog::Error("add {$}:{$}", strNotify.GetBuffer(), ResInfo.GetBuffer()); m_MSGUnit->DelErrorMessage("", level, ResInfo); } else { int Level = 3;//error mLog::Error("add {$}:{$}", strNotify.GetBuffer(), ResInfo.GetBuffer()); m_MSGUnit->AddErrorMessage(strNotify, level, ResInfo); } return 0; } LRESULT nsGEN::V2AdapterDevice::ONGenWarn(WPARAM wParam, LPARAM lParam) { CString strNotify, ResInfo; strNotify.Format(_T("WarCode_ % s"), *(CString*)wParam); ResInfo.Format(_T("WarInfo: %s"), *(CString*)lParam); //exption int level = 0; if (strNotify == "WarCode_") { int Level = 3;//error mLog::Error("add {$}:{$}", strNotify.GetBuffer(), ResInfo.GetBuffer()); m_MSGUnit->DelErrorMessage("", level, ResInfo); } else { int Level = 3;//error mLog::Error("add {$}:{$}", strNotify.GetBuffer(), ResInfo.GetBuffer()); m_MSGUnit->AddErrorMessage(strNotify, level, ResInfo); } return 0; } //driver----------------------------------------- bool V2AdapterDriver::InitConfiguration() { //开启日志记录 string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Generator\Conf\Log4CPP.Config.GEN.xml)"; Log4CPP::GlobalContext::Map::Set(ECOM::Utility::Hash("LogFileName"), "GEN.V2ADAPTER"); auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str()); mLog::gLogger = Log4CPP::LogManager::GetLogger("GEN.V2ADAPTER"); mLog::Debug("Enter [{$}]", __FUNCTION__); CAppSettings pGenConfig; TCHAR FullPath[MAX_PATH]; CString strAppPath = ""; GetModuleFileName(hMyModule, FullPath, MAX_PATH); strAppPath.Format("%s", FullPath); int nPos = 1; int nBackUpPos = 0; while (nPos > 0) { nPos = strAppPath.Find("\\", nPos + 1); if (nPos > 0) { nBackUpPos = nPos; } } strAppPath = strAppPath.Left(nBackUpPos); mLog::Info("strapppath:[{$}]", strAppPath.GetBuffer()); if (pGenConfig.Load(strAppPath + "\\conf\\GenOprConf.xml")) { //m_bGenConnectReal = atoi(pGenConfig.GetValueByKey(_T("GenState"))); return true; } else if (pGenConfig.Load(strAppPath + "\\OEMDrivers\\Generator\\V2AdapterDriver\\conf\\GenOprConf.xml")) { //m_bGenConnectReal = atoi(pGenConfig.GetValueByKey(_T("GenState"))); return true; } else mLog::Warn("load GenOprConf.xml failed"); return false; } nsGEN::V2AdapterDriver::V2AdapterDriver() { m_bDemoMode = false; m_bDemoConnected = false; m_bGenConnectReal = false; m_pUIOBJ = nullptr; m_pAttribute.reset(new ResDataObject()); m_pDescription.reset(new ResDataObject()); if (InitConfiguration())//read cfg ,and get m_bGenConnectState is . { m_pUIOBJ = new UIObject(); mLog::Debug("Init Gen Configuration Succeed[{$}]",(int)m_pUIOBJ); } else { mLog::Error("Init Configuration Failed"); } } nsGEN::V2AdapterDriver::~V2AdapterDriver() { mLog::Debug("Enter [{$}]", __FUNCTION__); mLog::Close(); m_pUIOBJ->Destrory(); delete m_pUIOBJ; } auto nsGEN::V2AdapterDriver::CreateDevice(int index) -> std::unique_ptr { mLog::Debug("Enter [{$}]", __FUNCTION__); if (m_bDemoMode) { if (!m_bDemoConnected) return nullptr; mLog::Warn("CreateDevice:not suppert Demo mode"); return nullptr; } if (m_pUIOBJ) { V2AdapterDevice* pDevice = new V2AdapterDevice(EventCenter, m_pUIOBJ); auto dev = std::unique_ptr (new IODevice(pDevice)); mLog::Debug("CreateDevice successful"); return dev; } return NULL; } bool nsGEN::V2AdapterDriver::DriverEntry(std::string CfgFileName) { mLog::Debug("Enter [{$}]", __FUNCTION__); m_ConfigFileName = CfgFileName; if (m_DeviceConfig.loadFile(m_ConfigFileName.c_str())) { return CCOS::Dev::IODriver::DriverEntry(CfgFileName); } return false; } void nsGEN::V2AdapterDriver::Prepare() { ResDataObject r_config; if (r_config.loadFile(m_ConfigFileName.c_str())) { m_bDemoMode = (atoi)(((string)r_config["CONFIGURATION"]["IsDemo"]).c_str()); } super::Prepare(); } bool DATA_ACTION nsGEN::V2AdapterDriver::Connect() { mLog::Debug("Enter [{$}]", __FUNCTION__); if (m_bDemoMode) { mLog::Debug("Ccos start as DEMO"); m_bDemoConnected = true; return true; } if (m_pUIOBJ->Create()) { m_bGenConnectReal = true; mLog::Debug("Connect successful"); return true; } else { m_bGenConnectReal = false; m_pUIOBJ->Destrory(); } super::Connect(); return false; } void nsGEN::V2AdapterDriver::Disconnect() { mLog::Debug("Enter [{$}]", __FUNCTION__); if (m_bDemoMode) { m_bDemoConnected = false; } else { if (isConnected()) { m_pUIOBJ->Destrory(); super::Disconnect(); } } } bool nsGEN::V2AdapterDriver::isConnected() const { mLog::Debug("Enter [{$}]", __FUNCTION__); if (m_bDemoMode) return m_bDemoConnected; else return m_bGenConnectReal; } std::string nsGEN::V2AdapterDriver::DriverProbe() { mLog::Debug("Enter [{$}]", __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", "V2"); HardwareInfo.add("ProductID", "Adapter"); HardwareInfo.add("SerialID", "1234"); } string ret = HardwareInfo.encode(); return ret; } std::string nsGEN::V2AdapterDriver::GetResource() { mLog::Debug("Enter [{$}]", __FUNCTION__); ResDataObject temp, r_config; if (!temp.loadFile(m_ConfigFileName.c_str())) return std::string(); 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::V2AdapterDriver::DeviceProbe() { mLog::Debug("Enter [{$}]", __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", "Adapter"); HardwareInfo.add("ProductID", "HF"); HardwareInfo.add("SerialID", "1234"); } string ret = HardwareInfo.encode(); return ret; } bool nsGEN::V2AdapterDriver::GetDeviceConfig(std::string& Cfg) { Cfg = m_DeviceConfigSend.encode(); printf("GetDeviceConfig over , %s", Cfg.c_str()); return true; } bool nsGEN::V2AdapterDriver::SetDeviceConfig(std::string Cfg) { mLog::Debug("--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::Debug("{$}", 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::Debug("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::Debug("{$} is not a RW configuration item", strKey.c_str()); } } else { mLog::Debug("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::V2AdapterDriver::SaveConfigFile(bool bSendNotify) { m_ConfigAll["CONFIGURATION"] = m_Configurations; bool bRt = m_ConfigAll.SaveFile(m_ConfigFileName.c_str()); mLog::Debug("SaveConfigFile over {$}", bRt); return true; } bool nsGEN::V2AdapterDriver::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::V2AdapterDriver::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("bBegin to change {%s} item value to {%s}", 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; } //----------------------------------------------------------------------------- // GetIODriver & CreateIODriver //----------------------------------------------------------------------------- static nsGEN::V2AdapterDriver gIODriver; CCOSDEVGENERATORV2ADAPTER_C_API CCOS::Dev::IODriver * GetIODriver() // 返回静态对象的引用, 调用者不能删除 ! { return &gIODriver; } CCOSDEVGENERATORV2ADAPTER_C_API CCOS::Dev::IODriver * CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 ! { return new nsGEN::V2AdapterDriver(); }