More work on lib

This commit is contained in:
Daniel Kluge
2023-10-20 10:14:53 +02:00
parent 99fd86ff95
commit 9836905de4
5 changed files with 80 additions and 34 deletions
+36 -17
View File
@@ -4,7 +4,7 @@ import { types, jsonization } from "@aas-core-works/aas-core3.0rc02-typescript";
export default class AASStore { export default class AASStore {
private static instance: AASStore; private static instance: AASStore;
private shells: Array<types.Environment> = []; private envs: Array<types.Environment> = [];
private constructor() { } private constructor() { }
@@ -17,17 +17,17 @@ export default class AASStore {
} }
public addAAS(aas: types.Environment): void { public addAAS(aas: types.Environment): void {
this.shells.push(aas); this.envs.push(aas);
} }
public getAll(): Array<types.Environment> { public getAll(): Array<types.Environment> {
return this.shells; return this.envs;
} }
public addAASByPath(path: string): void { public addAASByPath(path: string): void {
if (!path.endsWith(".json")) throw new Error("File must be a JSON file"); if (!path.endsWith(".json")) throw new Error("File must be a JSON file");
const file = getAASFileContent(path); const file = readFileSync(path, { encoding: "utf-8" });
const aas = JSON.parse(file); const aas = JSON.parse(file);
const aasJson = jsonization.environmentFromJsonable(aas); const aasJson = jsonization.environmentFromJsonable(aas);
@@ -39,7 +39,7 @@ export default class AASStore {
public addAllAASFromPath(path: string): void { public addAllAASFromPath(path: string): void {
const errors: any[] = []; const errors: any[] = [];
getAllAASFiles(path).forEach(file => { this.getAllAASFilePaths(path).forEach(file => {
try { try {
this.addAASByPath(file); this.addAASByPath(file);
} catch (e) { } catch (e) {
@@ -50,24 +50,43 @@ export default class AASStore {
throw errors; throw errors;
} }
} private getAllAASFilePaths(aasPath: string): string[] {
export function getAllAASFiles(aasPath: string): string[] {
const files = readdirSync(aasPath); const files = readdirSync(aasPath);
return files.filter(file => file.endsWith(".json")).map(file => `${aasPath}/${file}`); return files.filter(file => file.endsWith(".json")).map(file => `${aasPath}/${file}`);
} }
export function getAASFileContent(aasPath: string): string { public findAASById(id: string): types.AssetAdministrationShell | null {
const content = readFileSync(aasPath, { encoding: "utf-8" }); for (const env of this.envs) {
return content; if (env.assetAdministrationShells === null) continue;
for (const aas of env.assetAdministrationShells) {
if (aas.id === id) return aas;
}
} }
export function getAllAASFileContents(aasPath: string): string[] { return null;
const files = getAllAASFiles(aasPath)
const content = [];
for (const file of files) {
content.push(getAASFileContent(file));
} }
return content; public findSMById(id: string): types.Submodel | null {
for (const env of this.envs) {
if (env.submodels === null) continue;
for (const sm of env.submodels) {
if (sm.id === id) return sm;
}
}
return null;
}
public findElement(submodelId: string, elementIdShort: string): types.Class | null {
const sm = this.findSMById(submodelId);
if (!sm) return null;
for (const element of sm.descend()) {
if ((element as any).idShort === elementIdShort) return element;
}
return null;
}
} }
+2 -1
View File
@@ -6,13 +6,14 @@ export type OnResponseCallback = (response: any) => void
export default abstract class InterfaceConnectionObject<ConfigInterface> { export default abstract class InterfaceConnectionObject<ConfigInterface> {
protected abstract readonly name: string; protected abstract readonly name: string;
protected abstract readonly uriProtocol: string[]|string;
protected abstract readonly connectionType: ConnectionType; protected abstract readonly connectionType: ConnectionType;
protected abstract readonly supportsSubscriptions: boolean; protected abstract readonly supportsSubscriptions: boolean;
protected config: ConfigInterface; protected config: ConfigInterface;
private onResponseCallback: OnResponseCallback; private onResponseCallback: OnResponseCallback;
constructor(config: ConfigInterface, onResponseCallback: OnResponseCallback) { public constructor(config: ConfigInterface, onResponseCallback: OnResponseCallback) {
this.config = config; this.config = config;
this.onResponseCallback = onResponseCallback; this.onResponseCallback = onResponseCallback;
} }
+8 -4
View File
@@ -1,6 +1,6 @@
import { types } from "@aas-core-works/aas-core3.0rc02-typescript"; import { types } from "@aas-core-works/aas-core3.0rc02-typescript";
import type AASInterfaceServer from "server"; import type AASInterfaceServer from "server";
import type { PossibleRequests } from "server"; import type { Request } from "types/requests";
import type InterfaceConnectionObject from "interfaceConnectionObject"; import type InterfaceConnectionObject from "interfaceConnectionObject";
import AASStore from "aasStore"; import AASStore from "aasStore";
@@ -9,11 +9,11 @@ class MultiMessageBroker {
private serverInterfaces: Array<typeof AASInterfaceServer> = []; private serverInterfaces: Array<typeof AASInterfaceServer> = [];
private serverInterfaceConfigs: Array<any> = []; private serverInterfaceConfigs: Array<any> = [];
private serverInstances: Array<AASInterfaceServer<any>|null> = []; private serverInstances: Array<AASInterfaceServer<typeof this.serverInterfaceConfigs[keyof typeof this.serverInterfaceConfigs]>|null> = [];
private connectorInterfaces: Array<typeof InterfaceConnectionObject> = []; private connectorInterfaces: Array<typeof InterfaceConnectionObject> = [];
private connectorConfigs: Array<any> = []; private connectorConfigs: Array<any> = [];
private connectorInstances: Array<InterfaceConnectionObject<any>|null> = []; private connectorInstances: Array<InterfaceConnectionObject<typeof this.connectorConfigs[keyof typeof this.connectorConfigs]>|null> = [];
public constructor() {} public constructor() {}
@@ -51,7 +51,11 @@ class MultiMessageBroker {
}); });
} }
private onInterfaceRequest(request: PossibleRequests) { private connectorConfigsFromAAS(aas: types.Environment): void {
// TODO
}
private onInterfaceRequest(request: Request) {
// TODO // TODO
} }
+25 -6
View File
@@ -1,16 +1,16 @@
import { types } from "@aas-core-works/aas-core3.0rc02-typescript"; import { types } from "@aas-core-works/aas-core3.0rc02-typescript";
import type { Request, OnRequestCallback } from "types/requests";
export type PossibleRequests = "TODO";
export type OnRequestCallback = (request: PossibleRequests) => void
export default abstract class AASInterfaceServer<ConfigInterface> { export default abstract class AASInterfaceServer<ConfigInterface> {
protected abstract readonly name: string; protected abstract readonly name: string;
protected config: ConfigInterface; protected config: ConfigInterface;
private onRequestCallback: OnRequestCallback; protected abstract readonly supportsSubscriptions: boolean;
protected readonly aas: types.Environment;
private onRequestCallback: OnRequestCallback
constructor(config: ConfigInterface, aas: types.Environment, onRequestCallback: OnRequestCallback) { constructor(config: ConfigInterface, aas: types.Environment, onRequestCallback: OnRequestCallback) {
this.config = config; this.config = config;
this.aas = aas;
this.onRequestCallback = onRequestCallback; this.onRequestCallback = onRequestCallback;
} }
@@ -19,5 +19,24 @@ export default abstract class AASInterfaceServer<ConfigInterface> {
public abstract stop(): void; public abstract stop(): void;
public abstract notify(event: any): void; public abstract notify(event: any): void;
protected abstract findElementByRequest(request: PossibleRequests): any | null; protected abstract findElementByRequest(request: Request): any | null;
protected findElementBySemanticId(id: string): types.Class | null {
for (const element of this.aas.descend()) {
if ((element as any).semanticId === id) {
return element;
}
}
return null;
}
protected findElementByShortId(id: string): types.Class | null {
for (const element of this.aas.descend()) {
if ((element as any).idShort === id) {
return element;
}
}
return null;
}
} }
+3
View File
@@ -0,0 +1,3 @@
export type Request = "TODO"
export type OnRequestCallback = (request: Request) => void