#include "..\..\..\..\Deliver\include\DIOS.Dev.Collimator.Mould.hpp" // #include "stdafx.h" #include #include "Helper.JSON.hpp" #include "DIOS.Dev.Collimator.Mould.hpp" #include "EasyJSONEncoder.hpp" #include "DIOSDICOMInfo.h" using namespace DIOS::Dev::Detail::Collimator; namespace nsGEN = DIOS::Dev::Detail::Collimator; //template //inline _Container& operator << (_Container& ar, const T& t) //{ // ar.push_back(t); // return ar; //} string nsGEN::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; } //获取配置文件中指定模块的版本号 bool nsGEN::GetVersion(string& version, HMODULE hMyModule) { try { char filename[MAX_PATH + 1] = { 0 }; if (GetModuleFileName(hMyModule, filename, MAX_PATH) == 0) { printf("dll HMODULEis null\n"); //mLog::Error("dll HMODULEis null\n"); return false; } printf("get Generator path:{$}\n", filename); //mLog::Info("get Generator path:{$}\n", filename); DWORD dummy; DWORD size = GetFileVersionInfoSize(filename, &dummy); if (size == 0) { return false; } auto data = make_unique(size); if (!GetFileVersionInfo(filename, 0, size, &data[0])) { return false; } UINT32 len = 0; VS_FIXEDFILEINFO* fixed_file_info = 0; if (!VerQueryValue(&data[0], TEXT("\\"), reinterpret_cast(&fixed_file_info), &len)) { return false; } // version 为版本号 UINT32 vBitNumber = 0; vBitNumber = HIWORD(fixed_file_info->dwProductVersionMS); version += to_string(vBitNumber); version += "."; vBitNumber = LOWORD(fixed_file_info->dwProductVersionMS); version += to_string(vBitNumber); version += "."; vBitNumber = HIWORD(fixed_file_info->dwProductVersionLS); version += to_string(vBitNumber); version += "."; vBitNumber = LOWORD(fixed_file_info->dwProductVersionLS); version += to_string(vBitNumber); return true; } catch (...) { printf("get Generator Mould version failed"); //mLog::Error("get Generator Mould version failed\n"); } return false; } bool nsGEN::GetVersion(string& version, ResDataObject& config) { try { string procdir = ""; char filename[MAX_PATH + 1] = { 0 }; procdir = nsGEN::GetProcessDirectory(); if (procdir.empty()) { if (GetModuleFileName(nullptr, filename, MAX_PATH) == 0) { return false; } } else { string oemdrvpath = (const char*)config["oemdriver"]; { string keystr = "%ROOT%"; string::size_type pos = 0; string::size_type keylen = keystr.size(); string::size_type replen = procdir.size(); while ((pos = oemdrvpath.find(keystr, pos)) != string::npos) { oemdrvpath.replace(pos, keylen, procdir); pos += replen; } } strncpy_s(filename, oemdrvpath.c_str(), MAX_PATH); } printf("get Generator path:{$}\n", filename); //mLog::Info("get Generator path:{$}\n", filename); DWORD dummy; DWORD size = GetFileVersionInfoSize(filename, &dummy); if (size == 0) { return false; } auto data = make_unique(size); if (!GetFileVersionInfo(filename, 0, size, &data[0])) { return false; } UINT32 len = 0; VS_FIXEDFILEINFO* fixed_file_info = 0; if (!VerQueryValue(&data[0], TEXT("\\"), reinterpret_cast(&fixed_file_info), &len)) { return false; } // version 为版本号 UINT32 vBitNumber = 0; vBitNumber = HIWORD(fixed_file_info->dwProductVersionMS); version += to_string(vBitNumber); version += "."; vBitNumber = LOWORD(fixed_file_info->dwProductVersionMS); version += to_string(vBitNumber); version += "."; vBitNumber = HIWORD(fixed_file_info->dwProductVersionLS); version += to_string(vBitNumber); version += "."; vBitNumber = LOWORD(fixed_file_info->dwProductVersionLS); version += to_string(vBitNumber); return true; } catch (...) { printf("get Generator Mould version failed"); //mLog::Error("get Generator Mould version failed\n"); } return false; } bool nsGEN::GetVersion(string& version) { try { char filename[MAX_PATH + 1] = { 0 }; if (GetModuleFileName(nullptr, filename, MAX_PATH) == 0) { return false; } printf("get Generator path:{$}\n", filename); //mLog::Info("get Generator path:{$}\n", filename); DWORD dummy; DWORD size = GetFileVersionInfoSize(filename, &dummy); if (size == 0) { return false; } auto data = make_unique(size); if (!GetFileVersionInfo(filename, 0, size, &data[0])) { return false; } UINT32 len = 0; VS_FIXEDFILEINFO* fixed_file_info = 0; if (!VerQueryValue(&data[0], TEXT("\\"), reinterpret_cast(&fixed_file_info), &len)) { return false; } // version 为版本号 UINT32 vBitNumber = 0; vBitNumber = HIWORD(fixed_file_info->dwProductVersionMS); version += to_string(vBitNumber); version += "."; vBitNumber = LOWORD(fixed_file_info->dwProductVersionMS); version += to_string(vBitNumber); version += "."; vBitNumber = HIWORD(fixed_file_info->dwProductVersionLS); version += to_string(vBitNumber); version += "."; vBitNumber = LOWORD(fixed_file_info->dwProductVersionLS); version += to_string(vBitNumber); return true; } catch (...) { printf("get Generator Mould version failed"); //mLog::Error("get Generator Mould version failed\n"); } return false; } //----------------------------------------------------------------------------- // nsGEN::ColliamtorMould //----------------------------------------------------------------------------- nsGEN::ColliamtorMould::ColliamtorMould() { } nsGEN::ColliamtorMould::~ColliamtorMould() { } void nsGEN::ColliamtorMould::Register (Dispatch* Dispatch) { Dispatch->Get.Push(AttrKey::XSIZE, this, &ColliamtorMould::JSGetCollimatorXSize); Dispatch->Get.Push(AttrKey::YSIZE, this, &ColliamtorMould::JSGetCollimatorYSize); Dispatch->Get.Push(AttrKey::XRatio, this, &ColliamtorMould::JSGetCollimatorXRatio); Dispatch->Get.Push(AttrKey::YRatio, this, &ColliamtorMould::JSGetCollimatorYRatio); Dispatch->Get.Push(AttrKey::MaxWidth, this, &ColliamtorMould::JSGetCollimatorMaxWidth); Dispatch->Get.Push(AttrKey::MaxHigh, this, &ColliamtorMould::JSGetCollimatorMaxHigh); Dispatch->Get.Push(AttrKey::ThresholdValue, this, &ColliamtorMould::JSGetCollimatorThresholdValue); Dispatch->Get.Push(AttrKey::SID, this, &ColliamtorMould::JSGetCollimatorSID); Dispatch->Get.Push(AttrKey::FILTER, this, &ColliamtorMould::JSGetCollimatorFilter); Dispatch->Get.Push(AttrKey::ANGLE, this, &ColliamtorMould::JSGetCollimatorAngle); Dispatch->Get.Push(AttrKey::MODE, this, &ColliamtorMould::JSGetCollimatorMode); Dispatch->Get.Push(AttrKey::LIGHT, this, &ColliamtorMould::JSGetCollimatorLight); Dispatch->Action.Push(ActionKey::SetCollimatorSize, this, &ColliamtorMould::JSSetCollimatorSize); Dispatch->Action.Push(ActionKey::SetCollimatorRatio, this, &ColliamtorMould::JSSetCollimatorRatio); Dispatch->Action.Push(ActionKey::SetCollimatorSID, this, &ColliamtorMould::JSSetCollimatorSID); Dispatch->Action.Push(ActionKey::SetCollimatorFilter, this, &ColliamtorMould::JSSetCollimatorFilter); Dispatch->Action.Push(ActionKey::SetCollimatorAngle, this, &ColliamtorMould::JSSetCollimatorAngle); Dispatch->Action.Push(ActionKey::SetCollimatorMode, this, &ColliamtorMould::JSSetCollimatorMode); Dispatch->Action.Push(ActionKey::SetTechParamsInfo, this, &ColliamtorMould::JSSetTechParamsInfo); Dispatch->Action.Push(ActionKey::SetCollimatorLight, this, &ColliamtorMould::JSSetCollimatorLight); Dispatch->Action.Push(ActionKey::SetHCollimatorOpen, this, &ColliamtorMould::JSSetHCollimatorOpen); Dispatch->Action.Push(ActionKey::SetHCollimatorClose, this, &ColliamtorMould::JSSetHCollimatorClose); Dispatch->Action.Push(ActionKey::SetVCollimatorOpen, this, &ColliamtorMould::JSSetVCollimatorOpen); Dispatch->Action.Push(ActionKey::SetVCollimatorClose, this, &ColliamtorMould::JSSetVCollimatorClose); Dispatch->Action.Push(ActionKey::Reset, this, &ColliamtorMould::JSReset); } //----------------------------------------------------------------------------- // 所有的消息响应函数 //----------------------------------------------------------------------------- RET_STATUS nsGEN::ColliamtorMould::JSSetCollimatorSize(std::string in, std::string& out) { ResDataObject json; json.decode(in.c_str()); int xvalue = atoi(((string)json[0]).c_str()); int yvalue = atoi(((string)json[1]).c_str()); return SetCollimatorSize(xvalue, yvalue); } RET_STATUS nsGEN::ColliamtorMould::JSSetCollimatorRatio(std::string in, std::string& out) { ResDataObject json; json.decode(in.c_str()); float xvalue = atof(((string)json[0]).c_str()); float yvalue = atof(((string)json[1]).c_str()); return SetCollimatorRatio(xvalue, yvalue); } RET_STATUS nsGEN::ColliamtorMould::JSSetCollimatorSID(std::string in, std::string& out) { auto value = JSONTo (in); return SetCollimatorSID(value); } RET_STATUS nsGEN::ColliamtorMould::JSSetCollimatorFilter(std::string in, std::string& out) { auto value = JSONTo (in); return SetCollimatorFilter(value); } RET_STATUS nsGEN::ColliamtorMould::JSSetCollimatorAngle(std::string in, std::string& out) { auto value = JSONTo (in); return SetCollimatorAngle(value); } RET_STATUS nsGEN::ColliamtorMould::JSSetCollimatorMode(std::string in, std::string& out) { auto value = JSONTo (in); return SetCollimatorMode(value); } RET_STATUS nsGEN::ColliamtorMould::JSSetCollimatorLight(std::string in, std::string& out) { auto value = JSONTo (in); return SetCollimatorLight(value); } RET_STATUS nsGEN::ColliamtorMould::JSSetHCollimatorOpen(std::string in, std::string& out) { auto value = JSONTo (in); return SetHCollimatorOpen(value); } RET_STATUS nsGEN::ColliamtorMould::JSSetHCollimatorClose(std::string in, std::string& out) { auto value = JSONTo (in); return SetHCollimatorClose(value); } RET_STATUS nsGEN::ColliamtorMould::JSSetVCollimatorOpen(std::string in, std::string& out) { auto value = JSONTo (in); return SetVCollimatorOpen(value); } RET_STATUS nsGEN::ColliamtorMould::JSSetVCollimatorClose(std::string in, std::string& out) { auto value = JSONTo (in); return SetVCollimatorClose(value); } RET_STATUS nsGEN::ColliamtorMould::JSSetTechParamsInfo(std::string in, std::string& out) { ResDataObject json; json.decode(in.c_str()); TECHPARAM_INFO info; info.SetVal(json[0].encode()); string strcollimatorwidth = info.m_CollimatorWidth; string strcollimatorheight = info.m_CollimatorHeight; string strcollimatorfilter = info.m_CollimatorFilter; string strSID = info.m_SID; DWORD Width = 0; DWORD Height = 0; DWORD dwFilter = 0; DWORD dwSID = 0; dwSID = (DWORD)atoi(strSID.c_str()); if (dwSID >= 0) { SetCollimatorSID(dwSID); } if (strcollimatorwidth.find("IN") != string::npos) { Width = (DWORD)(atof(strcollimatorwidth.substr(0, strcollimatorwidth.size() - 2).c_str()) * 2.54); } else { Width = (DWORD)(atoi(strcollimatorwidth.substr(0, strcollimatorwidth.size() - 2).c_str())); } if (strcollimatorheight.find("IN") != string::npos) { Height = (DWORD)(atof(strcollimatorheight.substr(0, strcollimatorheight.size() - 2).c_str()) * 2.54); } else { Height = (DWORD)(atoi(strcollimatorheight.substr(0, strcollimatorheight.size() - 2).c_str())); } if (Width != 0 && Height != 0) { SetCollimatorSize(Width, Height); } dwFilter = (DWORD)atoi(strcollimatorfilter.c_str()); if (dwFilter >= 0) { SetCollimatorFilter(dwFilter); } return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::ColliamtorMould::JSGetCollimatorXSize(std::string& out) { auto value = GetXSize(); out= ToJSON(value); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::ColliamtorMould::JSGetCollimatorYSize(std::string& out) { auto value = GetYSize(); out = ToJSON(value); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::ColliamtorMould::JSGetCollimatorXRatio(std::string& out) { auto value = GetXRatio(); out = ToJSON(value); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::ColliamtorMould::JSGetCollimatorYRatio(std::string& out) { auto value = GetYRatio(); out = ToJSON(value); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::ColliamtorMould::JSGetCollimatorMaxWidth(std::string& out) { auto value = m_fMaxWidth; out = ToJSON(value); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::ColliamtorMould::JSGetCollimatorMaxHigh(std::string& out) { auto value = m_fMaxHigh; out = ToJSON(value); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::ColliamtorMould::JSGetCollimatorThresholdValue(std::string& out) { auto value = m_fThresholdValue; out = ToJSON(value); return RET_STATUS(); } RET_STATUS nsGEN::ColliamtorMould::JSGetCollimatorSID(std::string& out) { auto value = GetSID(); out = ToJSON(value); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::ColliamtorMould::JSGetCollimatorFilter(std::string& out) { auto value = GetFilter(); out = ToJSON(value); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::ColliamtorMould::JSGetCollimatorAngle(std::string& out) { auto value = GetAngle(); out = ToJSON(value); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::ColliamtorMould::JSGetCollimatorMode(std::string& out) { auto value = GetMode(); out = ToJSON(value); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::ColliamtorMould::JSGetCollimatorLight(std::string& out) { auto value = GetCollimatorLight(); out = ToJSON(value); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::ColliamtorMould::JSReset(std::string in, std::string& out) { return Reset(); } RET_STATUS nsGEN::ColliamtorMould::Reset() { return RET_STATUS::RET_SUCCEED; } //----------------------------------------------------------------------------- // 所有的 GetXX 函数 //----------------------------------------------------------------------------- int nsGEN::ColliamtorMould::GetXSize() { return m_CollimatorUnit.m_XRatio->Get(); } int nsGEN::ColliamtorMould::GetYSize() { return m_CollimatorUnit.m_YRatio->Get(); } int nsGEN::ColliamtorMould::GetXRatio() { return m_CollimatorUnit.m_XSize->Get(); } int nsGEN::ColliamtorMould::GetYRatio() { return m_CollimatorUnit.m_YSize->Get(); } RET_STATUS nsGEN::ColliamtorMould::SetCollimatorRatio(float xproportion, float yproportion) { return RET_STATUS::RET_SUCCEED; } //int nsGEN::ColliamtorMould::GetMaxWidth(){ return m_CollimatorUnit.m_MaxWidth->Get();} //int nsGEN::ColliamtorMould::GetMaxHigh(){ return m_CollimatorUnit.m_MaxHigh->Get();} int nsGEN::ColliamtorMould::GetSID() { return m_CollimatorUnit.m_SID->Get(); } int nsGEN::ColliamtorMould::GetFilter() { return m_CollimatorUnit.m_Filter->Get(); } int nsGEN::ColliamtorMould::GetAngle() { return m_CollimatorUnit.m_Angle->Get(); } int nsGEN::ColliamtorMould::GetMode() { return m_CollimatorUnit.m_Mode->Get(); } int nsGEN::ColliamtorMould::GetCollimatorLight() { return m_CollimatorUnit.m_Light->Get(); } RET_STATUS nsGEN::ColliamtorMould::SetHCollimatorOpen(bool bStatus) { return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::ColliamtorMould::SetHCollimatorClose(bool bStatus) { return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::ColliamtorMould::SetVCollimatorOpen(bool bStatus) { return RET_STATUS::RET_SUCCEED; } RET_STATUS nsGEN::ColliamtorMould::SetVCollimatorClose(bool bStatus) { return RET_STATUS::RET_SUCCEED; } //----------------------------------------------------------------------------- // nsGEN::DriverMould //----------------------------------------------------------------------------- nsGEN::DriverMould::DriverMould () { ConfigInfo Vender (ConfKey::DiosType, "string", "R", "TRUE", ""); m_ConfigInfo.push_back(Vender); ConfigInfo Model (ConfKey::DiosModel, "string", "R", "TRUE", ""); m_ConfigInfo.push_back(Model); EasyJSONEncoder synList; synList.Set ("0", "1"); synList.Set ("1", "2"); ConfigInfo GenIsConnect (ConfKey::DiosIsConnect, "int", "RW", "FALSE", ""); GenIsConnect.SetList (synList.ToString ().c_str ()); m_ConfigInfo.push_back(GenIsConnect); ConfigInfo SCFType (ConfKey::DiosSCFType, "string", "R", "TRUE", ""); m_ConfigInfo.push_back(SCFType); EasyJSONEncoder COMList; COMList.Set ("0", "COM1"); COMList.Set ("1", "COM2"); COMList.Set ("2", "COM3"); COMList.Set ("3", "COM4"); COMList.Set ("4", "COM5"); COMList.Set ("5", "COM6"); COMList.Set ("6", "COM7"); COMList.Set ("7", "COM8"); COMList.Set ("8", "COM9"); COMList.Set ("9", "COM10"); COMList.Set ("10", "COM11"); COMList.Set ("11", "COM12"); ConfigInfo SCFPort (ConfKey::DiosSCFPort, "string", "RW", "TRUE", ""); SCFPort.SetList (COMList.ToString ().c_str ()); m_ConfigInfo.push_back(SCFPort); ConfigInfo SCFBaudrate (ConfKey::DiosSCFBaudrate, "int", "R", "FALSE", ""); m_ConfigInfo.push_back(SCFBaudrate); ConfigInfo SCFBytesize (ConfKey::DiosSCFBytesize, "int", "R", "FALSE", ""); m_ConfigInfo.push_back(SCFBytesize); ConfigInfo SCFParity (ConfKey::DiosSCFParity, "int", "R", "FALSE", ""); m_ConfigInfo.push_back(SCFParity); ConfigInfo SCFStopbits (ConfKey::DiosSCFStopbits, "int", "R", "FALSE", ""); m_ConfigInfo.push_back(SCFStopbits); } nsGEN::DriverMould::~DriverMould () { } #ifdef _WIN64 #ifdef _DEBUG static const auto COM_SCFDllName = "Dios.Dev.SerialSCFX64D.dll"; static const auto TCP_SCFDllName = "Dios.Dev.TcpipSCFX64D.dll"; #else static const auto COM_SCFDllName = "Dios.Dev.SerialSCFX64.dll"; static const auto TCP_SCFDllName = "Dios.Dev.TcpipSCFX64.dll"; #endif #endif std::string nsGEN::DriverMould::GetGUID () const { return DeviceDriverType; } string nsGEN::DriverMould::GetConnectDLL(string& ConfigFileName) { string ConnectDLL = COM_SCFDllName; ResDataObject r_config, Connection; if (!r_config.loadFile(ConfigFileName.c_str())) return ConnectDLL; if (r_config["CONFIGURATION"]["connections"].GetKeyCount("Value") > 0) { Connection = r_config["CONFIGURATION"]["connections"]["Value"]; } else { Connection = r_config["CONFIGURATION"]["connections"][0]; } if ((string)Connection["type"] == "COM") ConnectDLL = COM_SCFDllName; else ConnectDLL = TCP_SCFDllName; return ConnectDLL; } ResDataObject nsGEN::DriverMould::GetConnectParam(string& ConfigFileName) { ResDataObject r_config, Connection; if (!r_config.loadFile(ConfigFileName.c_str())) return Connection; if (r_config["CONFIGURATION"]["connections"].GetKeyCount("Value") > 0) { Connection = r_config["CONFIGURATION"]["connections"]["Value"]; } else { Connection = r_config["CONFIGURATION"]["connections"][0]; } return Connection; } void DIOS::Dev::Detail::Collimator::TransJsonText(ResDataObject& config) { for (int x = 0; x < config.size(); x++) { //如果有Value if (config[x].GetKeyCount("Value") > 0) { //mLog::FINFO("TRY COVERT [{$}] VALUE {$}", config.GetKey(x), config[x]["Value"].size() > 0 ? config[x]["Value"].encode() : (const char*)config[x]["Value"]); if (config[x]["Value"].size() <= 0) { string va = (const char*)config[x]["Value"]; config[x] = va.c_str(); } else { ResDataObject rest = config[x]["Value"]; config[x] = rest; //mLog::FINFO("convert object [{$}], object {$}", config.GetKey(x), rest.encode()); } } //mLog::FINFO("After Convert {$}", config.encode()); } }