... | ... | @@ -329,4 +329,77 @@ Runtime.getRuntime().addShutdownHook(new Thread() { |
|
|
}
|
|
|
});
|
|
|
```
|
|
|
Lastly, we're adding a shutdown hook to the main process. This allows us to delete and deregister AAS and Submodel on shutdown, preventing inconsistencies in the overall system. |
|
|
\ No newline at end of file |
|
|
Lastly, we're adding a shutdown hook to the main process. This allows us to delete and deregister AAS and Submodel on shutdown, preventing inconsistencies in the overall system.
|
|
|
|
|
|
# AASX-Branch
|
|
|
On the [AASX-Branch](https://gitlab.hrz.tu-chemnitz.de/vws-demo/vws-spielwiese/-/tree/aasx), the Asset and AAS of the Light Controller are loaded from an AASX package. [The difference](https://gitlab.hrz.tu-chemnitz.de/vws-demo/vws-spielwiese/-/compare/main...aasx?from_project_id=10357) is explained in the following:
|
|
|
|
|
|
```java
|
|
|
AASXPackageManager packageManager = new AASXPackageManager("/home/pi/vws-spielwiese/basyx.lichterkette/aasx/lightController.aasx");
|
|
|
```
|
|
|
First, the AASX package Manager is created and given the path to our AASX to be loaded. An absolute path is used here to avoid problems with the [startup service](setup/Setting-up-a-Raspberry-Pi-for-the-demo#5-add-startup-service).
|
|
|
|
|
|
```java
|
|
|
AASBundle foundLightControllerBundle = null;
|
|
|
Set<AASBundle> bundles = null;
|
|
|
```
|
|
|
We initialize the Bundles, as the actual loading of the AASX will happen in the try block following, catching the various exceptions that may occur during load:
|
|
|
|
|
|
```java
|
|
|
try {
|
|
|
bundles = packageManager.retrieveAASBundles();
|
|
|
```
|
|
|
This tries to actually load the AASX file and parse it into AASBundles.
|
|
|
|
|
|
```java
|
|
|
for (AASBundle aasBundle : bundles) {
|
|
|
if (Objects.equals(aasBundle.getAAS().getIdShort(), "lightController")) {
|
|
|
foundLightControllerBundle = aasBundle;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
Here, we sift through all loaded AAS Bundles inside our AASX file (it should only be one) and assign the AAS Bundle containing the AAS and Asset description of the Light Controller.
|
|
|
|
|
|
```java
|
|
|
} catch (InvalidFormatException | IOException | ParserConfigurationException | SAXException e) {
|
|
|
logger.error("LightController aasx could not be loaded:");
|
|
|
e.printStackTrace();
|
|
|
logger.error("We can't continue with this asset.");
|
|
|
return;
|
|
|
}
|
|
|
```
|
|
|
Should we fail to load the AASX file and parse it into Bundles, we abort the start of the Light Controller, as we cannot continue without it. If an AASX without the Light Controller AAS would be loaded, we would fail with a `NullPointerException` soon after, too.
|
|
|
|
|
|
```java
|
|
|
final AASBundle lightControllerBundle = foundLightControllerBundle;
|
|
|
```
|
|
|
We then assign the hopefully found AASBundle for the light controller to a `final` variable.
|
|
|
|
|
|
Creation of the AAS and Asset object is removed, as these are loaded from the AASX
|
|
|
|
|
|
```java
|
|
|
lightControllerBundle.getSubmodels().add(lightControllerModel);
|
|
|
```
|
|
|
Then, we add the created Submodel to the list of submodels we may or may not have loaded from the AASX
|
|
|
|
|
|
```java
|
|
|
AASBundleHelper.integrate(new AASAggregatorProxy(AASSERVERPATH + "/shells"), bundles);
|
|
|
```
|
|
|
Upload all bundles inside the AASX to the AAS Server (note: not using the `ConnectedAssetAdministrationShellManager`)
|
|
|
|
|
|
```java
|
|
|
AASBundleHelper.register(registry, bundles, AASSERVERPATH);
|
|
|
```
|
|
|
and register them (note: again without the manager, but with the `AASBundleHelper`.
|
|
|
|
|
|
```java
|
|
|
registry.register(lightControllerBundle.getAAS().getIdentification(), lightControllerSMDescriptor);
|
|
|
```
|
|
|
lastly, we register our Submodel explicitly, going through the Bundle to get the ID of the AAS to add the Submodel to.
|
|
|
|
|
|
```java
|
|
|
registry.delete(lightControllerBundle.getAAS().getIdentification(),
|
|
|
lightControllerSMDescriptor.getIdentifier());
|
|
|
```
|
|
|
Finally, we add the relevant section to delete the active submodel from the registry again on shutdown. We don't delete the AAS as the AASX may have contained additional information, that may still be relevant, even if the actual Light Controller is shut down. |