修复无法调取数据包模型的问题
This commit is contained in:
parent
fefd229495
commit
b2e5036b2c
@ -169,6 +169,18 @@ public:
|
|||||||
*/
|
*/
|
||||||
void SetSetFreq(double setFreq);
|
void SetSetFreq(double setFreq);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 获取模型动态库路径
|
||||||
|
* @return const std::string&: 模型动态库路径
|
||||||
|
*/
|
||||||
|
const std::string &GetLibPath();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 设置模型动态库路径
|
||||||
|
* @param sLibPath: std::string类型,模型动态库路径
|
||||||
|
*/
|
||||||
|
void SetLibPath(const std::string &sLibPath);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 单步执行函数
|
* @brief 单步执行函数
|
||||||
* @details 模型默认的周期性执行函数
|
* @details 模型默认的周期性执行函数
|
||||||
|
@ -78,11 +78,12 @@ void XNModelManager::LoadModel(const std::string &modelPath, const std::string &
|
|||||||
model->SetFramework(GetFramework());
|
model->SetFramework(GetFramework());
|
||||||
model->SetInitializeType(initialType);
|
model->SetInitializeType(initialType);
|
||||||
model->SetThreadID(threadID);
|
model->SetThreadID(threadID);
|
||||||
|
std::filesystem::path parentPath = std::filesystem::path(modelPath).parent_path();
|
||||||
|
model->SetLibPath(parentPath.string());
|
||||||
if (initialType == 0) {
|
if (initialType == 0) {
|
||||||
// 使用std::filesystem处理路径
|
// 使用std::filesystem处理路径
|
||||||
std::filesystem::path configPath =
|
std::filesystem::path configPath =
|
||||||
std::filesystem::path(modelPath).parent_path()
|
parentPath / (className + "_V" + modelVersion + ".mcfg");
|
||||||
/ (className + "_V" + modelVersion + ".mcfg");
|
|
||||||
model->SetXmlPath(configPath.string());
|
model->SetXmlPath(configPath.string());
|
||||||
} else if (initialType == 1) {
|
} else if (initialType == 1) {
|
||||||
model->SetXmlPath(planeName + "," + className + "," + modelVersion);
|
model->SetXmlPath(planeName + "," + className + "," + modelVersion);
|
||||||
|
@ -192,6 +192,18 @@ void XNModelObject::SetSetFreq(double setFreq)
|
|||||||
d->_setFreq = setFreq;
|
d->_setFreq = setFreq;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string &XNModelObject::GetLibPath()
|
||||||
|
{
|
||||||
|
T_D();
|
||||||
|
return d->_sLibPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
void XNModelObject::SetLibPath(const std::string &sLibPath)
|
||||||
|
{
|
||||||
|
T_D();
|
||||||
|
d->_sLibPath = sLibPath;
|
||||||
|
}
|
||||||
|
|
||||||
// 初始化函数
|
// 初始化函数
|
||||||
void XNModelObject::Initialize()
|
void XNModelObject::Initialize()
|
||||||
{
|
{
|
||||||
|
@ -169,6 +169,18 @@ public:
|
|||||||
*/
|
*/
|
||||||
void SetSetFreq(double setFreq);
|
void SetSetFreq(double setFreq);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 获取模型动态库路径
|
||||||
|
* @return const std::string&: 模型动态库路径
|
||||||
|
*/
|
||||||
|
const std::string &GetLibPath();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 设置模型动态库路径
|
||||||
|
* @param sLibPath: std::string类型,模型动态库路径
|
||||||
|
*/
|
||||||
|
void SetLibPath(const std::string &sLibPath);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 单步执行函数
|
* @brief 单步执行函数
|
||||||
* @details 模型默认的周期性执行函数
|
* @details 模型默认的周期性执行函数
|
||||||
|
@ -124,7 +124,7 @@ bool XNScenarioManager::ParseScenarioXml(const std::string &XmlPath)
|
|||||||
std::string libName = service->Attribute("ClassName");
|
std::string libName = service->Attribute("ClassName");
|
||||||
std::string serviceVersion = service->Attribute("Version");
|
std::string serviceVersion = service->Attribute("Version");
|
||||||
libName = XNSim::getFileNameWithoutExt(libName);
|
libName = XNSim::getFileNameWithoutExt(libName);
|
||||||
std::string dynamicLibName = servicePath + "lib" + libName + ".so." + serviceVersion;
|
std::string dynamicLibName = servicePath + "/lib" + libName + ".so." + serviceVersion;
|
||||||
// 加载动态库
|
// 加载动态库
|
||||||
GetFramework()->GetServiceManager()->LoadService(dynamicLibName, libName,
|
GetFramework()->GetServiceManager()->LoadService(dynamicLibName, libName,
|
||||||
serviceVersion, 0);
|
serviceVersion, 0);
|
||||||
@ -177,7 +177,7 @@ bool XNScenarioManager::ParseScenarioXml(const std::string &XmlPath)
|
|||||||
std::string libName = model->Attribute("ClassName");
|
std::string libName = model->Attribute("ClassName");
|
||||||
std::string modelVersion = model->Attribute("Version");
|
std::string modelVersion = model->Attribute("Version");
|
||||||
libName = XNSim::getFileNameWithoutExt(libName);
|
libName = XNSim::getFileNameWithoutExt(libName);
|
||||||
std::string dynamicLibName = modelPath + "lib" + libName + ".so." + modelVersion;
|
std::string dynamicLibName = modelPath + "/lib" + libName + ".so." + modelVersion;
|
||||||
// 加载动态库
|
// 加载动态库
|
||||||
GetFramework()->GetModelManager()->LoadModel(dynamicLibName, libName, modelVersion,
|
GetFramework()->GetModelManager()->LoadModel(dynamicLibName, libName, modelVersion,
|
||||||
planeName, 0, threadID);
|
planeName, 0, threadID);
|
||||||
@ -195,12 +195,12 @@ bool XNScenarioManager::ParseConfig(const std::string &ConfigID)
|
|||||||
{
|
{
|
||||||
T_D();
|
T_D();
|
||||||
// 获取数据库路径
|
// 获取数据库路径
|
||||||
std::string dbPath = std::getenv("XNCore");
|
std::string XNCorePath = std::getenv("XNCore");
|
||||||
if (dbPath.empty()) {
|
if (XNCorePath.empty()) {
|
||||||
LOG_ERROR("0x1015 未设置XNCore环境变量, 引擎将退出!");
|
LOG_ERROR("0x1015 未设置XNCore环境变量, 引擎将退出!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
dbPath += "/database/XNSim.db";
|
std::string dbPath = XNCorePath + "/database/XNSim.db";
|
||||||
|
|
||||||
// 打开数据库
|
// 打开数据库
|
||||||
sqlite3 *db;
|
sqlite3 *db;
|
||||||
@ -239,15 +239,31 @@ bool XNScenarioManager::ParseConfig(const std::string &ConfigID)
|
|||||||
std::string version = XNSim::getStringFromSqlite3(stmt, 4);
|
std::string version = XNSim::getStringFromSqlite3(stmt, 4);
|
||||||
std::string kernel = XNSim::getStringFromSqlite3(stmt, 5);
|
std::string kernel = XNSim::getStringFromSqlite3(stmt, 5);
|
||||||
std::string rootPath = XNSim::getStringFromSqlite3(stmt, 7);
|
std::string rootPath = XNSim::getStringFromSqlite3(stmt, 7);
|
||||||
|
if (rootPath.empty()) {
|
||||||
|
LOG_WARNING("0x1020 未设置工作目录,使用默认工作目录: %1", XNCorePath);
|
||||||
|
rootPath = XNCorePath;
|
||||||
|
}
|
||||||
GetFramework()->SetWorkPath(rootPath);
|
GetFramework()->SetWorkPath(rootPath);
|
||||||
// 设置模型库目录
|
// 设置模型库目录
|
||||||
std::string modelPath = rootPath + XNSim::getStringFromSqlite3(stmt, 8);
|
std::string modelPath = rootPath + XNSim::getStringFromSqlite3(stmt, 8);
|
||||||
|
if (modelPath.empty()) {
|
||||||
|
LOG_WARNING("0x1020 未设置模型库目录,使用默认模型库目录: %1/Models", XNCorePath);
|
||||||
|
modelPath = XNCorePath + "/Models";
|
||||||
|
}
|
||||||
GetFramework()->SetModelPath(modelPath);
|
GetFramework()->SetModelPath(modelPath);
|
||||||
// 设置服务库目录
|
// 设置服务库目录
|
||||||
std::string servicePath = rootPath + XNSim::getStringFromSqlite3(stmt, 9);
|
std::string servicePath = rootPath + XNSim::getStringFromSqlite3(stmt, 9);
|
||||||
|
if (servicePath.empty()) {
|
||||||
|
LOG_WARNING("0x1020 未设置服务库目录,使用默认服务库目录: %1/Services", XNCorePath);
|
||||||
|
servicePath = XNCorePath + "/Services";
|
||||||
|
}
|
||||||
GetFramework()->SetServicePath(servicePath);
|
GetFramework()->SetServicePath(servicePath);
|
||||||
// 设置域ID
|
// 设置域ID
|
||||||
uint32_t domainID = std::stoul(XNSim::getStringFromSqlite3(stmt, 10));
|
uint32_t domainID = std::stoul(XNSim::getStringFromSqlite3(stmt, 10));
|
||||||
|
if (domainID == 0 || domainID > 225) {
|
||||||
|
LOG_WARNING("0x1020 域ID设置错误,使用默认域ID: 10");
|
||||||
|
domainID = 10;
|
||||||
|
}
|
||||||
GetFramework()->GetDDSManager()->SetDomainID(domainID);
|
GetFramework()->GetDDSManager()->SetDomainID(domainID);
|
||||||
// 读取CPU亲和性
|
// 读取CPU亲和性
|
||||||
std::string cpuAff = XNSim::getStringFromSqlite3(stmt, 6);
|
std::string cpuAff = XNSim::getStringFromSqlite3(stmt, 6);
|
||||||
@ -279,7 +295,7 @@ bool XNScenarioManager::ParseConfig(const std::string &ConfigID)
|
|||||||
std::string ServiceName = XNSim::getStringFromSqlite3(servicesStmt, 3);
|
std::string ServiceName = XNSim::getStringFromSqlite3(servicesStmt, 3);
|
||||||
|
|
||||||
ClassName = XNSim::getFileNameWithoutExt(ClassName);
|
ClassName = XNSim::getFileNameWithoutExt(ClassName);
|
||||||
std::string dynamicLibName = servicePath + "lib" + ClassName + ".so." + ServiceVersion;
|
std::string dynamicLibName = servicePath + "/lib" + ClassName + ".so." + ServiceVersion;
|
||||||
// 加载动态库
|
// 加载动态库
|
||||||
GetFramework()->GetServiceManager()->LoadService(dynamicLibName, ClassName, ServiceVersion,
|
GetFramework()->GetServiceManager()->LoadService(dynamicLibName, ClassName, ServiceVersion,
|
||||||
1);
|
1);
|
||||||
@ -373,7 +389,7 @@ bool XNScenarioManager::ParseConfig(const std::string &ConfigID)
|
|||||||
std::string ModelName = XNSim::getStringFromSqlite3(modelsStmt, 3);
|
std::string ModelName = XNSim::getStringFromSqlite3(modelsStmt, 3);
|
||||||
|
|
||||||
ClassName = XNSim::getFileNameWithoutExt(ClassName);
|
ClassName = XNSim::getFileNameWithoutExt(ClassName);
|
||||||
std::string dynamicLibName = modelPath + "lib" + ClassName + ".so." + ModelVersion;
|
std::string dynamicLibName = modelPath + "/lib" + ClassName + ".so." + ModelVersion;
|
||||||
// 加载动态库
|
// 加载动态库
|
||||||
LOG_INFO("0x1021 加载模型: %1", dynamicLibName);
|
LOG_INFO("0x1021 加载模型: %1", dynamicLibName);
|
||||||
GetFramework()->GetModelManager()->LoadModel(dynamicLibName, ClassName, ModelVersion,
|
GetFramework()->GetModelManager()->LoadModel(dynamicLibName, ClassName, ModelVersion,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user