Skip to content

Commit

Permalink
SKA-543: Fixed array export in vCDL Exporter
Browse files Browse the repository at this point in the history
* Fixed incorrect export of array variables by the vCDL Exporter (did not detect array variables correctly and exported them as scalars before)
  • Loading branch information
DominikHerr committed Jun 25, 2024
1 parent e6eddf0 commit f342e56
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
15 changes: 8 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ This version introduces a new feature to bundle several variables to structures

* Added an option 'AlwaysUseStructuredNamingConvention' to the configuration's root level (default: false).
If set, it activate the structured naming convention detection (and therefore the variable aggregation feature) even if it is not set in the FMU's model description.
* Added a new communication interface description format that must be provided via ``-i `` or ``--fmu-importer-communication-interface-file`` if variables shall be aggregated to structures.
* Added a new communication interface description format that must be provided via ``-i `` or ``--fmu-importer-communication-interface-file`` if variables shall be aggregated to structures
* Added support for optional data types.
Optional data types are used in SIL Kit to indicate if the provided data (e.g., a structure member) contains a payload or not.
Optional data types can be defined in the communication interface description and in the configuration file by appending a question mark at the end of the data type that should be optional.
* Added label support.
By default, the FMU Importer does not use any labels when creating Publish / Subscribe services.
The `Instance` and `Namespace` labels can be set by configuring PublisherInstance, SubscriberInstance, and Namespace in the root of the configuration file.
These labels allow to limit the communication between services with the same namespace / instance name (e.g., if multiple instances of the same FMU are participating in a simulation).
* Added a new tool (Communication Interface Exporter) to generate a communication interface from an FMU (see documentation for details, or use the --help argument when calling the exporter).
By default, the FMU Importer does not use any labels when creating publish / subscribe services
The `Instance` and `Namespace` labels can be set by configuring PublisherInstance, SubscriberInstance, and Namespace in the root of the configuration file
These labels allow to limit the communication between services with the same namespace / instance name (e.g., if multiple instances of the same FMU are participating in a simulation)
* Added a new tool (Communication Interface Exporter) to generate a communication interface from an FMU (see documentation for details, or use the --help argument when calling the exporter)

### Changed

* If the value of an enumeration-typed variable is set, strings are now considered referring to an enumerator's name, whereas integers refer to an enumerators' value.
* If the value of an enumeration-typed variable is set, strings are now considered referring to an enumerator's name, whereas integers refer to an enumerators' value
* Temporarily extracted FMUs are now deleted by default
* If there is a folder with the extracted FMU in the same directory as the FMU, this extracted content will be used and remains there after the FMU Importer stops.
* If there is a folder with the extracted FMU in the same directory as the FMU, this extracted content will be used and remains there after the FMU Importer stops
* Otherwise, the FMU is now extracted to a temporary directory. This directory and its contents are deleted after the simulation run.
* Reworked the vCDL Exporter
* New CLI (see documentation for details, or use the --help argument when calling the exporter)
Expand All @@ -36,6 +36,7 @@ These labels allow to limit the communication between services with the same nam

### Fixed
* If an error occurred while an FMU is loaded, its error will now be handled like other errors (was printed to console before)
* Fixed incorrect export of array variables by the vCDL Exporter (did not detect array variables correctly and exported them as scalars before)

---

Expand Down
28 changes: 14 additions & 14 deletions VcdlExporter/VcdlExporter/FmuExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,36 +147,36 @@ private void ParseFmi3(ModelDescription modelDescription, StringBuilder interfac

AddEnumerationDefinitions(modelDescription, interfaceSb);

foreach (var arrayVar in modelDescription.ArrayVariables.Values)
{
arrayVar.InitializeArrayLength(modelDescription.Variables);
}

foreach (var variable in modelDescription.Variables)
{
var vValue = variable.Value;
// Note that the direction is reversed compared to the model description
// input -> provided // CANoe _provides_ the _input_ value for an FMU
// output -> consumed // CANoe _consumes_ the _output_ value of an FMU
string typeString;
if (vValue.Dimensions == null || vValue.Dimensions.Length == 0)
{
// assume scalar
if (vValue.VariableType is VariableTypes.EnumFmi3)
{
typeString = vValue.TypeDefinition!.Name;
}
else
{
typeString = GetVarTypeString(vValue.VariableType);
}
}
else
// assume scalar
typeString = vValue.VariableType is VariableTypes.EnumFmi3
? vValue.TypeDefinition!.Name
: GetVarTypeString(vValue.VariableType);

// surround with list if more than one dimension is detected
if (vValue.Dimensions != null && vValue.Dimensions.Length > 0)
{
// assume array of scalar
typeString = $"list<{GetVarTypeString(vValue.VariableType)}> ";
typeString = $"list<{typeString}>";
}

var v = new VcdlVariable()
{
Name = vValue.Name,
Type = typeString
};

switch (vValue.Causality)
{
case Variable.Causalities.Input:
Expand Down

0 comments on commit f342e56

Please sign in to comment.