Documentation should be done

This commit is contained in:
Daniel Kluge
2023-11-02 18:29:04 +01:00
parent 591cf6662b
commit 819a0b1a72
21 changed files with 571 additions and 29 deletions
+14
View File
@@ -3,6 +3,20 @@ import { MultiMessageBroker, FileImporter } from "aas-multimessagebroker";
import HTTPInterfaceServer from "./modules/httpInterfaceServer";
import MQTTConnector from "./modules/mqttConnector";
/**
* This is an example of how to use the MultiMessageBroker.
* It creates a sample interface and connector and registers them to the broker, then starts it.
*
* @remarks
* In this package a {@link HTTPInterfaceServer} is used to serve the Asset Administration Shell API interface.
* To connect to the asset a {@link MQTTConnector} was created.
* The asset is a Python script located outside of this repository which sends the current timestamp as two parameters.
* The AAS-Package is defined in the file ../owntest.json.
* It was created using the {@link https://github.com/admin-shell-io/aasx-package-explorer|aasx-package-explorer}.
*
* @packageDocumentation
*/
// First we need to import the AAS Package
// It was created using the aasx-package-explorer (https://github.com/admin-shell-io/aasx-package-explorer)
const aas = FileImporter.readAASByPath("../owntest.json");
+22 -2
View File
@@ -18,8 +18,20 @@ export type Config = {
* @see {@link aas-multimessagebroker#AbstractInterfaceServer|AbstractInterfaceServer}
*/
export default class HTTPInterfaceServer extends AbstractInterfaceServer<Config> {
public static serverInterfaceName: string = "HTTPInterfaceServer";
public static supportsSubscriptions: boolean = false; // TODO, longpolling?
/**
* Server name
* @override
* @readonly
* @alpha
*/
public static readonly serverInterfaceName: string = "HTTPInterfaceServer";
/**
* Whether the server supports subscriptions
* @override
* @readonly
* @alpha
*/
public static readonly supportsSubscriptions: boolean = false; // TODO, longpolling?
/**
* This is the {@link express#Express|express app}.
@@ -39,6 +51,8 @@ export default class HTTPInterfaceServer extends AbstractInterfaceServer<Config>
*
* @remarks
* This is called before the server is started.
* @override
* @public
*/
public prepare(): void {
this.app.use(express.json());
@@ -47,6 +61,8 @@ export default class HTTPInterfaceServer extends AbstractInterfaceServer<Config>
/**
* This should start the server.
* @override
* @public
*/
public run(): void {
this.server = this.app.listen(this.config.bindPort, this.config.bindAddress, () => {
@@ -56,6 +72,8 @@ export default class HTTPInterfaceServer extends AbstractInterfaceServer<Config>
/**
* This should stop the server.
* @override
* @public
*/
public stop(): void {
if (this.server && this.server.close) this.server.close();
@@ -63,6 +81,8 @@ export default class HTTPInterfaceServer extends AbstractInterfaceServer<Config>
/**
* This should call notify all observers
* @override
* @public
*/
public notify(event: any): void {
this.observers.forEach(observer => {
+50 -2
View File
@@ -11,9 +11,35 @@ import type { AASCoreTypes } from "aas-multimessagebroker";
* @see {@link aas-multimessagebroker#AbstractConnectionObject|AbstractConnectionObject}
*/
export default class MQTTConnector extends AbstractConnectionObject<mqtt.IClientOptions> {
/**
* A name for your connector. Not used yet.
* @override
* @public
* @readonly
* @alpha
*/
public static readonly connectorName: string = "MQTT Connector";
/**
* The protocol(s) your connector supports. Absolutely critical so the broker knows which connector to use.
* @override
* @public
*/
public static readonly uriProtocol: string[] = ["mqtt", "mqtts"];
/**
* The type of connection your connector uses. Either "ON_DEMAND" or "PERMANENT".
* @override
* @public
* @readonly
* @alpha
*/
public static readonly connectionType: "ON_DEMAND" | "PERMANENT" = "PERMANENT";
/**
* Whether your connector supports subscriptions.
* @override
* @public
* @readonly
* @alpha
*/
public static readonly supportsSubscriptions: boolean = true;
/**
@@ -26,13 +52,15 @@ export default class MQTTConnector extends AbstractConnectionObject<mqtt.IClient
*/
private readonly messageStore: Record<string, any> = {};
/**
* This should connect the Connector to the asset.
*
* @remarks For async connections like HTTP you can just return true and do the connection on demand.
* @remarks
* For async connections like HTTP you can just return true and do the connection on demand.
*
* @returns Whether the connection was successful.
* @override
* @public
*/
public connect(): boolean {
if (!this.client) this.client = mqtt.connect(this.endpointMetadata.base, this.connectionParameter);
@@ -51,6 +79,8 @@ export default class MQTTConnector extends AbstractConnectionObject<mqtt.IClient
/**
* This should disconnect the Connector from the asset (if it even is connected).
* @override
* @public
*/
public disconnect(): void {
if (this.client) this.client.end();
@@ -65,6 +95,8 @@ export default class MQTTConnector extends AbstractConnectionObject<mqtt.IClient
*
* @param prop Property
* @returns Value of property casted to the type it says it should be.
* @override
* @public
*/
public readProperty(prop: AASCoreTypes.Property): any {
const cc = this.mapper.get(prop);
@@ -94,6 +126,8 @@ export default class MQTTConnector extends AbstractConnectionObject<mqtt.IClient
* @param prop Property
* @param value Value
* @returns Whether the write was successful.
* @override
* @public
*/
public writeProperty(prop: AASCoreTypes.Property, value: any): boolean {
const cc = this.mapper.get(prop);
@@ -112,6 +146,8 @@ export default class MQTTConnector extends AbstractConnectionObject<mqtt.IClient
* @param prop Property
* @param callback Callback on change
* @returns Whether the observer was created successfully.
* @override
* @public
*/
public observeProperty(prop: AASCoreTypes.Property, callback: (value: any) => void): boolean {
const cc = this.mapper.get(prop);
@@ -130,6 +166,9 @@ export default class MQTTConnector extends AbstractConnectionObject<mqtt.IClient
* @param args Arguments
*
* @returns Return value of action.
* @override
* @public
* @alpha
*/
public callActionSync(action: AASCoreTypes.Operation, args: Record<string, any>): any {
// TODO
@@ -144,6 +183,9 @@ export default class MQTTConnector extends AbstractConnectionObject<mqtt.IClient
* @param args Arguments
*
* @returns Handle (uuid) for the result or null if it fails.
* @override
* @public
* @alpha
*/
public callActionAsync(action: AASCoreTypes.Operation, args: Record<string, any>): string | null {
// TODO
@@ -157,6 +199,9 @@ export default class MQTTConnector extends AbstractConnectionObject<mqtt.IClient
* @param event Event
* @param callback Callback onEvent
* @returns Whether the subscription was successful.
* @override
* @public
* @alpha
*/
public subscribeEvent(event: AASCoreTypes.BasicEventElement, callback: (event: AASCoreTypes.BasicEventElement) => void): boolean {
// TODO
@@ -168,6 +213,9 @@ export default class MQTTConnector extends AbstractConnectionObject<mqtt.IClient
/**
* Unsubscribe from an event.
* @param event Event
* @override
* @public
* @alpha
*/
public unsubscribeEvent(event: AASCoreTypes.BasicEventElement): void {
// TODO