dds-fmu 0.5.1
DDS-FMU communication integration
ddsfmu::config Namespace Reference

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...
 

Detailed Description

Helper functions for loading and generating configuration files

Enumeration Type Documentation

◆ ScalarVariableType

Enumerator
Real 
Integer 
Boolean 
String 
Unknown 

Function Documentation

◆ generate_uuid()

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.

Parameters
[in]uuid_filesList of files whose contents to be loaded
[in]stringsList of strings to be added
Returns
Generated uuid string

◆ get_uuid_files()

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".

Parameters
[in]fmu_rootRoot directory to search for files
[in]skip_modelDescriptionWhether to skip model model description in the return list of paths
Returns
List of paths to files.

◆ load_ddsfmu_mapping()

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

Parameters
[in,out]docXML document being loaded
[in]ddsfmu_mappingPath to ddsfmu_mapping XML file
[in,out]bufferBuffer that the function uses to load file contents

◆ load_fmu_idls()

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.

Parameters
[in]resource_pathResource directory of the FMU: "<fmu_root>/resources"
[in]printWhether to print parsing
[in]main_idlName of the main idl file to load

◆ load_template_xml()

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.

Parameters
[in,out]docXML document being loaded
[in]template_xmlPath to modelDescription.xml
[in,out]bufferBuffer that the function uses to load file contents

◆ model_structure_outputs_generator()

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.

Parameters
[in,out]docXML document to work on
[in,out]rootNode for which to attach <ModelStructure>
[in]num_outputsNumber of outputs

◆ model_variable_generator()

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 
)
Parameters
[in,out]docXML document to work on
[in,out]model_variables_nodeModelVariables node to be appended
[in]nameName attribute
[in]causalityCausality attribute input|output|parameter
[in]value_refvalueReference attribute
[in]typeScalarVariable type: Real|Integer|Boolean|String

◆ name_generator()

void ddsfmu::config::name_generator ( std::string &  name,
const eprosima::xtypes::DynamicData::ReadableNode &  rnode 
)
Parameters
[out]nameVariable name of node according to FMU structured naming convention
[in]rnodeNode 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.

◆ print_xml()

std::string ddsfmu::config::print_xml ( const rapidxml::xml_document<> &  doc)
Returns
XML file loaded as a string

◆ write_model_description()

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.

Parameters
[in]docXML document to be dumped to file
[in]fmu_rootPath to FMU root directory, where the file will be written