Skip to content
Snippets Groups Projects
Commit 7213fa73 authored by Tim Übelhör's avatar Tim Übelhör
Browse files

Fixed loading Fmu modelDescription.

No crash on modeli load. Printing error to console instead.
parent 38f7177e
No related branches found
No related tags found
No related merge requests found
......@@ -15,12 +15,8 @@ namespace Files
// Unzip the fmu
_unzippedPath = CreateModelPath(controllerId, instanceName);
Unzipper::Unzip(path, _unzippedPath);
// Parse the model description
std::string xmlPath = _unzippedPath + "/modelDescription.xml";
pt::ptree desc;
pt::read_xml(xmlPath, desc);
_modelName = desc.get<std::string>("fmiModelDescription.CoSimulation.<xmlattr>.modelIdentifier");
_guid = desc.get<std::string>("fmiModelDescription.<xmlattr>.guid");
// Load the description
loadModelDescription();
}
FmuFile::FmuFile(const std::vector<unsigned char>& buffer, std::string controllerId, std::string instanceName) :
_instanceName(instanceName)
......@@ -28,6 +24,8 @@ namespace Files
// Path where the extracted Model is stored
_unzippedPath = CreateModelPath(controllerId, instanceName);
Unzipper::Unzip(buffer, _unzippedPath);
// Load the description
loadModelDescription();
}
FmuFile::~FmuFile()
......@@ -35,6 +33,16 @@ namespace Files
fs::remove_all(_unzippedPath);
}
void FmuFile::loadModelDescription()
{
// Parse the model description
std::string xmlPath = _unzippedPath + "/modelDescription.xml";
pt::ptree desc;
pt::read_xml(xmlPath, desc);
_modelName = desc.get<std::string>("fmiModelDescription.CoSimulation.<xmlattr>.modelIdentifier");
_guid = desc.get<std::string>("fmiModelDescription.<xmlattr>.guid");
}
std::string FmuFile::CreateModelPath(std::string controllerId, std::string instanceName)
{
fs::path dir(MODEL_DIR);
......
......@@ -13,6 +13,8 @@ namespace Files
std::string _instanceName;
std::string _modelName;
std::string _guid;
/// Loads the information from the modelDescription.xml
void loadModelDescription();
// Relative path to the dir where the modeles will be stored
const std::string MODEL_DIR = "MODELS";
// The path where the extracted fmu is stored
......
......@@ -40,6 +40,8 @@ int main(int argc, char *argv[])
auto fmuEngine = std::make_shared<Simulation::FmuEngine>(std::to_string(port));
// Load the modeli file into the engine
if (vm.count("modeli"))
{
try
{
Files::ModeliFile modeliFile(vm["modeli"].as<std::string>());
for (auto fmuFile : modeliFile.GetFmus())
......@@ -51,6 +53,11 @@ int main(int argc, char *argv[])
fmuEngine->AddChannelLink(channelLink);
}
}
catch (std::exception err)
{
std::cout << "Failed loading the modeli file: " << err.what() << std::endl;
}
}
// start the tcp server
Network::TcpServer server(port, fmuEngine);
std::thread serverThread([&server]() { server.Run(); });
......@@ -61,7 +68,7 @@ int main(int argc, char *argv[])
std::string cinString;
while (cinString != "exit")
{
// DEBUG std::cin >> cinString;
std::cin >> cinString;
std::this_thread::sleep_for(std::chrono::seconds(1));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment