Skip to content

Commit

Permalink
SKA-551: Combine 'PublisherInstance' and 'SubscriberInstance' to 'Ins…
Browse files Browse the repository at this point in the history
…tance'
  • Loading branch information
DominikHerr committed Jun 26, 2024
1 parent f7d8185 commit 3a6d272
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 61 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Optional data types are used in SIL Kit to indicate if the provided data (e.g.,
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
The "Instance" and "Namespace" labels can be set by configuring `Instance` 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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class CommunicationInterface
[NullOrNotEmpty]
public List<SubscriberInternal>? Subscribers { get; set; }

public string? PublisherInstance { get; set; }
public string? SubscriberInstance { get; set; }
public string? Instance { get; set; }
public string? Namespace { get; set; }
}
3 changes: 1 addition & 2 deletions FmuImporter/FmuImporter.Models/Config/ConfigurationPublic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class ConfigurationPublic

public bool AlwaysUseStructuredNamingConvention { get; set; } = false;

public string? PublisherInstance { get; set; }
public string? SubscriberInstance { get; set; }
public string? Instance { get; set; }
public string? Namespace { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -344,23 +344,19 @@
"description": "If 'true', prevent synchronization of variables that are not listed in VariableMappings (including parameters).",
"default": false
},
"Namespace": {
"Instance": {
"type": "string",
"description": "Namespace for all publishers and subscribers (only use for disambiguation - do not use if not necessary)."
"description": "Instance name for all publishers and subscribers (only use for disambiguation - do not use if not necessary)."
},
"PublisherInstance": {
"Namespace": {
"type": "string",
"description": "Instance name for all publishers (only use to disambiguate publishers with the same name - do not use if not necessary)."
"description": "Namespace for all publishers and subscribers (only use for disambiguation - do not use if not necessary)."
},
"StepSize": {
"type": "integer",
"description": "Amount of time in nanoseconds between two simulation time steps. Defaults to the step size defined inside the FMU's model description if present, or 1 ms if not.",
"minimum": 1,
"default" : 1000000
},
"SubscriberInstance": {
"type": "string",
"description": "Instance name for all subscribers (only use to disambiguate publishers with the same name - do not use if not necessary)."
"default": 1000000
},
"VariableMappings": {
"type": "array",
Expand Down
10 changes: 5 additions & 5 deletions FmuImporter/FmuImporter/FmuImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ private void PrepareConfiguredVariables()
SilKitDataManager.CreateSubscriber(
configuredVariable.FmuVariableDefinition.Name,
configuredVariable.TopicName,
_fmuImporterConfig.SubscriberInstance,
_fmuImporterConfig.Instance,
_fmuImporterConfig.Namespace,
new IntPtr(configuredVariable.FmuVariableDefinition.ValueReference));
}
Expand All @@ -290,7 +290,7 @@ private void PrepareConfiguredVariables()
SilKitDataManager.CreateSubscriber(
configuredStructure.Name,
configuredStructure.Name,
_fmuImporterConfig.SubscriberInstance,
_fmuImporterConfig.Instance,
_fmuImporterConfig.Namespace,
new IntPtr(configuredStructure.StructureId));
}
Expand All @@ -312,7 +312,7 @@ or Variable.Causalities.Parameter
SilKitDataManager.CreatePublisher(
configuredVariable.FmuVariableDefinition.Name,
configuredVariable.TopicName,
_fmuImporterConfig.PublisherInstance,
_fmuImporterConfig.Instance,
_fmuImporterConfig.Namespace,
new IntPtr(configuredVariable.FmuVariableDefinition.ValueReference),
0);
Expand All @@ -324,7 +324,7 @@ or Variable.Causalities.Parameter
SilKitDataManager.CreatePublisher(
configuredStructure.Name,
configuredStructure.Name,
_fmuImporterConfig.PublisherInstance,
_fmuImporterConfig.Instance,
_fmuImporterConfig.Namespace,
new IntPtr(configuredStructure.StructureId),
0);
Expand All @@ -347,7 +347,7 @@ or Variable.Causalities.Parameter
SilKitDataManager.CreatePublisher(
configuredVariable.FmuVariableDefinition.Name,
configuredVariable.TopicName,
_fmuImporterConfig.PublisherInstance,
_fmuImporterConfig.Instance,
_fmuImporterConfig.Namespace,
new IntPtr(configuredVariable.FmuVariableDefinition.ValueReference),
0);
Expand Down
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,7 @@ The configuration file is expected to be a valid YAML file with the following ou
Namespace: MyNamespace
PublisherInstance: OneInstance
SubscriberInstance: AnotherInstance
Instance: MyInstanceName
```

To help write this file, you may use the schema named `FmuImporterConfiguration.schema.json` in the root directory of the release package.
Expand All @@ -445,10 +443,9 @@ For instance, if you use Visual Studio Code with the Red Hat YAML extension, you
| IgnoreUnmappedVariables | Boolean | Set to true to prevent synchronization of variables that are not listed in VariableMappings (including parameters). |
| StepSize | Integer | Simulation step size in ns. Overrides step size provided by FMU (if available). |
| Namespace | String | Namespace for all SIL Kit publishers and subscribers (only used for disambiguation - do not use if not necessary). |
| PublisherInstance | String | Instance name for all SIL Kit publishers (only use to disambiguate publishers with the same name - do not use if not necessary). |
| SubscriberInstance | String | Instance name for all SIL Kit subscribers (only use to disambiguate publishers with the same name - do not use if not necessary). |
| Instance | String | Instance name for all SIL Kit publishers and subscribers (only used for disambiguation - do not use if not necessary). |

The options `Namespace`, `PublisherInstance`, and `SubscriberInstance` help to disambiguate if multiple SIL Kit participants provide data with the same topic name.
The options `Namespace` and `Instance` help to disambiguate if multiple SIL Kit participants provide data with the same topic name.
Only Publishers / Subscribers with the same instance name and namespace will exchange data.
If the options are not set, all data will be received, and sent data will not be discernible.
> These options may negatively impact the performance of the SIL Kit simulation. If possible, disambiguation should be done by renaming the topic names via [transformations](#variablemappingstransformation)
Expand Down
40 changes: 4 additions & 36 deletions VcdlExporter/VcdlExporter/CommInterfaceExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,54 +72,22 @@ public void Export()
// Remove all variables that are already part of the provider list (feedback loops can only be observed)
vcdlConsumerVariables.ExceptWith(vcdlProviderVariables);

var pubSubSameInstance = commInterface.PublisherInstance == commInterface.SubscriberInstance;

// Add interface for providers
if (pubSubSameInstance)
{
AddInterfaceHeader(_interfaceName, null, sb);
}
else
{
AddInterfaceHeader(_interfaceName, VcdlCausality.Provider, sb);
}
AddInterfaceHeader(_interfaceName, null, sb);

AddInterfaceBody(vcdlProviderVariables, VcdlCausality.Provider, sb);

if (pubSubSameInstance)
if (vcdlProviderVariables.Count > 0 && vcdlConsumerVariables.Count > 0)
{
if (vcdlProviderVariables.Count > 0 && vcdlConsumerVariables.Count > 0)
{
sb.AppendLine();
}
}
else
{
AddInterfaceFooter(sb);

AddInterfaceHeader(_interfaceName, VcdlCausality.Consumer, sb);
sb.AppendLine();
}

AddInterfaceBody(vcdlConsumerVariables, VcdlCausality.Consumer, sb);

AddInterfaceFooter(sb);

// Add object instances
if (pubSubSameInstance)
{
AddObjectInstance(_interfaceName, commInterface.PublisherInstance ?? _defaultInstanceName, sb);
}
else
{
AddObjectInstance(
_interfaceName + "_Provider",
commInterface.PublisherInstance ?? _defaultInstanceName,
sb);
AddObjectInstance(
_interfaceName + "_Consumer",
commInterface.SubscriberInstance ?? _defaultInstanceName,
sb);
}
AddObjectInstance(_interfaceName, commInterface.Instance ?? _defaultInstanceName, sb);

// Add vCDL footer
AddVcdlFooter(sb);
Expand Down

0 comments on commit 3a6d272

Please sign in to comment.