dds-fmu 0.5.1
DDS-FMU communication integration
|
Enumerations | |
enum class | ScalarVariableType { Real , Integer , Boolean , String , Unknown } |
Primitive type kinds in FMI. More... | |
Functions | |
std::string | generate_uuid (const std::vector< std::filesystem::path > &uuid_files, const std::vector< std::string > &strings=std::vector< std::string >()) |
Creates a uuid from a list of files and list of strings. More... | |
std::vector< std::filesystem::path > | get_uuid_files (const std::filesystem::path &fmu_root, bool skip_modelDescription=true) |
Given FMU root, returns a list of file paths to be used to generate uuid. More... | |
eprosima::xtypes::idl::Context | load_fmu_idls (const std::filesystem::path &resource_path, bool print=false, const std::string &main_idl="dds-fmu.idl") |
Load idl file and parse into xtypes context. More... | |
std::string | print_xml (const rapidxml::xml_document<> &doc) |
Prints xml document as string. More... | |
void | load_template_xml (rapidxml::xml_document<> &doc, const std::filesystem::path &template_xml, std::vector< char > &buffer) |
Loads template modelDescription.xml. More... | |
void | load_ddsfmu_mapping (rapidxml::xml_document<> &doc, const std::filesystem::path &ddsfmu_mapping, std::vector< char > &buffer) |
Loads mapping between dds topics and fmu signal references ddsfmu_mapping. More... | |
void | write_model_description (const rapidxml::xml_document<> &doc, const std::filesystem::path &fmu_root) |
Writes contents of xml document to modelDescription.xml. More... | |
void | name_generator (std::string &name, const eprosima::xtypes::DynamicData::ReadableNode &rnode) |
Finds structured name for a given node. More... | |
void | model_variable_generator (rapidxml::xml_document<> &doc, rapidxml::xml_node<> *model_variables_node, const std::string &name, const std::string &causality, const std::uint32_t &value_ref, const ddsfmu::config::ScalarVariableType &type) |
Constructs a <ScalarVariable> tag to be used in <ModelVariables> of the modelDescription.xml. More... | |
void | model_structure_outputs_generator (rapidxml::xml_document<> &doc, rapidxml::xml_node<> *root, const std::uint32_t &num_outputs) |
Create <Outputs> tag with necessary <Unknown> More... | |
Helper functions for loading and generating configuration files
|
strong |
std::string ddsfmu::config::generate_uuid | ( | const std::vector< std::filesystem::path > & | uuid_files, |
const std::vector< std::string > & | strings = std::vector< std::string >() |
||
) |
This functions loads the contents of each listed file and appends the list of strings also provided by the user. Next, it strips spaces, CR, LF, as well as the section: guid="<uuid>" found in modelDescription.xml. The resulting string buffer is then used to create a uuid, which is returned as a string.
[in] | uuid_files | List of files whose contents to be loaded |
[in] | strings | List of strings to be added |
std::vector< std::filesystem::path > ddsfmu::config::get_uuid_files | ( | const std::filesystem::path & | fmu_root, |
bool | skip_modelDescription = true |
||
) |
This function lists all files in "<fmu_root>/resources/config/" with file extensions [.xml, .idl, .yml]. In addition, optionally add "<fmu_root>/modelDescription.xml".
[in] | fmu_root | Root directory to search for files |
[in] | skip_modelDescription | Whether to skip model model description in the return list of paths |
void ddsfmu::config::load_ddsfmu_mapping | ( | rapidxml::xml_document<> & | doc, |
const std::filesystem::path & | ddsfmu_mapping, | ||
std::vector< char > & | buffer | ||
) |
Loads the mapping defined in ddsfmu_mapping file
[in,out] | doc | XML document being loaded |
[in] | ddsfmu_mapping | Path to ddsfmu_mapping XML file |
[in,out] | buffer | Buffer that the function uses to load file contents |
eprosima::xtypes::idl::Context ddsfmu::config::load_fmu_idls | ( | const std::filesystem::path & | resource_path, |
bool | print = false , |
||
const std::string & | main_idl = "dds-fmu.idl" |
||
) |
Loads the idl file, assumed to be located at "<resource_path>/config/idl/<main_idl>" and parses it into an xtypes context.
[in] | resource_path | Resource directory of the FMU: "<fmu_root>/resources" |
[in] | Whether to print parsing | |
[in] | main_idl | Name of the main idl file to load |
void ddsfmu::config::load_template_xml | ( | rapidxml::xml_document<> & | doc, |
const std::filesystem::path & | template_xml, | ||
std::vector< char > & | buffer | ||
) |
Loads the modelDescription template file whose contents is independent from the signal configuration, that is, before adding information from IDL and other configuration files.
[in,out] | doc | XML document being loaded |
[in] | template_xml | Path to modelDescription.xml |
[in,out] | buffer | Buffer that the function uses to load file contents |
void ddsfmu::config::model_structure_outputs_generator | ( | rapidxml::xml_document<> & | doc, |
rapidxml::xml_node<> * | root, | ||
const std::uint32_t & | num_outputs | ||
) |
Our implementation puts all outputs before inputs, so inferring indices are straightforward, namely one-indexed with the number of outputs, starting with 1.
[in,out] | doc | XML document to work on |
[in,out] | root | Node for which to attach <ModelStructure> |
[in] | num_outputs | Number of outputs |
void ddsfmu::config::model_variable_generator | ( | rapidxml::xml_document<> & | doc, |
rapidxml::xml_node<> * | model_variables_node, | ||
const std::string & | name, | ||
const std::string & | causality, | ||
const std::uint32_t & | value_ref, | ||
const ddsfmu::config::ScalarVariableType & | type | ||
) |
[in,out] | doc | XML document to work on |
[in,out] | model_variables_node | ModelVariables node to be appended |
[in] | name | Name attribute |
[in] | causality | Causality attribute input|output|parameter |
[in] | value_ref | valueReference attribute |
[in] | type | ScalarVariable type: Real|Integer|Boolean|String |
void ddsfmu::config::name_generator | ( | std::string & | name, |
const eprosima::xtypes::DynamicData::ReadableNode & | rnode | ||
) |
[out] | name | Variable name of node according to FMU structured naming convention |
[in] | rnode | Node to inspect |
Internally, this function recursively calls itself to find all ancestors of a node. The convention used is '.' for members and '[i]', with i being zero-indexed array notation.
std::string ddsfmu::config::print_xml | ( | const rapidxml::xml_document<> & | doc | ) |
void ddsfmu::config::write_model_description | ( | const rapidxml::xml_document<> & | doc, |
const std::filesystem::path & | fmu_root | ||
) |
The content is written to fmu_root / "modelDescription.xml", replacing the file if it exists.
[in] | doc | XML document to be dumped to file |
[in] | fmu_root | Path to FMU root directory, where the file will be written |