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