More example module work

This commit is contained in:
Daniel Kluge
2023-10-20 10:15:14 +02:00
parent 9836905de4
commit 1750ffdb7b
2 changed files with 66 additions and 8 deletions
+10 -7
View File
@@ -2,7 +2,7 @@ import type { Express } from "express";
import express from "express"; import express from "express";
import { jsonization, types } from "@aas-core-works/aas-core3.0rc02-typescript"; import { jsonization, types } from "@aas-core-works/aas-core3.0rc02-typescript";
import AASInterfaceServer from "../server"; import AASInterfaceServer from "../server";
import type { OnRequestCallback } from "../server"; import type { OnRequestCallback, Request } from "types/requests";
import AASStore from "../aasStore"; import AASStore from "../aasStore";
type Config = { type Config = {
@@ -11,7 +11,8 @@ type Config = {
} }
export default class HTTPInterfaceServer extends AASInterfaceServer<Config> { export default class HTTPInterfaceServer extends AASInterfaceServer<Config> {
public name: string = "HTTPInterfaceServer"; protected name: string = "HTTPInterfaceServer";
protected supportsSubscriptions: boolean = false; // TODO, longpolling?
private app: Express = express(); private app: Express = express();
private server: any = null; private server: any = null;
@@ -22,10 +23,9 @@ export default class HTTPInterfaceServer extends AASInterfaceServer<Config> {
} }
public prepare(): void { public prepare(): void {
const aas = AASStore.getInstance().getAll()[0];
this.app.use(express.json()); this.app.use(express.json());
this.app.get("/aas", (_, res) => { this.app.get("/aas", (_, res) => {
res.json(jsonization.toJsonable(aas)); res.json(jsonization.toJsonable(this.aas));
}); });
} }
@@ -40,10 +40,13 @@ export default class HTTPInterfaceServer extends AASInterfaceServer<Config> {
} }
public notify(event: any): void { public notify(event: any): void {
this.observers.forEach(observer => {
// TODO
// Notify long pollers
});
} }
protected findElementByRequest(request: string): any | null { protected findElementByRequest(request: Request) {
throw new Error("Method not implemented.");
}
} }
}
+55
View File
@@ -0,0 +1,55 @@
import * as mqtt from "mqtt";
import { Property, Operation, OperationVariable, BasicEventElement } from "@aas-core-works/aas-core3.0rc02-typescript/dist/types/types";
import InterfaceConnectionObject from "interfaceConnectionObject";
class MQTTConnector extends InterfaceConnectionObject<mqtt.IClientOptions> {
protected name: string = "MQTT Connector";
protected uriProtocol: string[] = ["mqtt", "mqtts"];
protected connectionType: "ON_DEMAND" | "PERMANENT" = "PERMANENT";
protected supportsSubscriptions: boolean = true;
private client: mqtt.MqttClient|null = null;
public connect(): boolean {
if (!this.client) this.client = mqtt.connect(this.config);
return this.client.connected;
}
public disconnect(): void {
if (this.client) this.client.end();
this.client = null;
}
public readProperty(prop: Property): void {
throw new Error("Method not implemented.");
}
public writeProperty(prop: Property, value: any): void {
throw new Error("Method not implemented.");
}
public observeProperty(prop: Property, callback: (value: any) => void): boolean {
throw new Error("Method not implemented.");
}
public callActionSync(action: Operation, args: OperationVariable[]) {
throw new Error("Method not implemented.");
}
public callActionAsync(action: Operation, args: OperationVariable[]): Promise<boolean> {
throw new Error("Method not implemented.");
}
public readAsyncActionResponse(action: Operation): Promise<any> {
throw new Error("Method not implemented.");
}
public subscribeEvent(callback: (event: BasicEventElement) => void): boolean {
throw new Error("Method not implemented.");
}
public unsubscribeEvent(): void {
throw new Error("Method not implemented.");
}
}