From f342e56dc83d419ad530ff0bb58473730ffb0bb0 Mon Sep 17 00:00:00 2001 From: "Herr, Dominik" Date: Mon, 24 Jun 2024 22:42:49 +0200 Subject: [PATCH] SKA-543: Fixed array export in vCDL Exporter * Fixed incorrect export of array variables by the vCDL Exporter (did not detect array variables correctly and exported them as scalars before) --- CHANGELOG.md | 15 +++++++------ VcdlExporter/VcdlExporter/FmuExporter.cs | 28 ++++++++++++------------ 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b18ba3c..add84a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) @@ -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) --- diff --git a/VcdlExporter/VcdlExporter/FmuExporter.cs b/VcdlExporter/VcdlExporter/FmuExporter.cs index 24a138f..336c010 100644 --- a/VcdlExporter/VcdlExporter/FmuExporter.cs +++ b/VcdlExporter/VcdlExporter/FmuExporter.cs @@ -147,6 +147,11 @@ 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; @@ -154,22 +159,16 @@ private void ParseFmi3(ModelDescription modelDescription, StringBuilder interfac // 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() @@ -177,6 +176,7 @@ private void ParseFmi3(ModelDescription modelDescription, StringBuilder interfac Name = vValue.Name, Type = typeString }; + switch (vValue.Causality) { case Variable.Causalities.Input: