@p2olab/pimad-core
Version:
PiMAd (Process-industry-Modular-Automation-description) High level access to automation of modular plants.
188 lines (185 loc) • 7.73 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommunicationInterfaceDataVendor = exports.CommunicationInterfaceDataEnum = exports.OPCUANodeCommunication = exports.OPCUAServerCommunication = void 0;
const NodeId_1 = require("./NodeId");
const Utils_1 = require("../Utils");
const ModuleAutomationObject_1 = require("./ModuleAutomationObject");
const pimad_types_1 = require("@p2olab/pimad-types");
/**
* Implements the {@link CommunicationInterfaceData}-Interface. Generalize variables, methods, etc. Reduce code
* duplication.
*/
class ACommunicationInterfaceData extends ModuleAutomationObject_1.AModuleAutomationObject {
constructor() {
super();
//this.macrocosm = 'macrocosm: undefined';
// this.microcosm = 'microcosm: undefined';
}
// TODO: Do we need these Getters?
/**
* @inheritDoc {@link CommunicationInterfaceData.getInterfaceDescription}
*!/
getInterfaceDescription(callback: (response: Backbone.PiMAdResponse, interfaceDescription: InterfaceDescription) => void): void {
this.genericPiMAdGetter<InterfaceDescription | undefined>({macrocosm: this.macrocosm, microcosm: this.microcosm}, callback);
}
/!**
* @inheritDoc {@link CommunicationInterfaceData.getMacrocosm}
*!/
getMacrocosm(callback: (response: Backbone.PiMAdResponse, macrocosm: string) => void): void {
// this.genericPiMAdGetter<string>(this.macrocosm, callback);
}
/!**
* @inheritDoc {@link CommunicationInterfaceData.getMicrocosm}
*!/
getMicrocosm(callback: (response: Backbone.PiMAdResponse, microcosm: string) => void): void {
//this.genericPiMAdGetter<string>(this.microcosm, callback);
}*/
/**
* Initialize this instance with interface description data. Caution: After a successful initialisation one cannot
* initialize it again. Spawn a new object instead.
* @param instructions - Most params a standard. In the context of opc-ua the macrocosm is the namespace and the
* microcosm is the identifier of the opc-ua-server.
*/
initialize(instructions) {
if (!this.initialized) {
this.macrocosm = instructions.interfaceDescription.macrocosm;
this.microcosm = instructions.interfaceDescription.microcosm;
this.initialized = (this.macrocosm === instructions.interfaceDescription.macrocosm
&& this.microcosm === instructions.interfaceDescription.microcosm
/* && this.moduleAutomationObjectInitialize({
dataSourceIdentifier: instructions.dataSourceIdentifier,
metaModelRef: instructions.metaModelRef,
name: instructions.name,
pimadIdentifier: instructions.pimadIdentifier
})*/
);
return this.initialized;
}
else {
return false;
}
}
}
/**
* This class models the interface description of opc-ua-servers.
*/
class OPCUAServerCommunication extends ACommunicationInterfaceData {
constructor() {
super();
}
}
exports.OPCUAServerCommunication = OPCUAServerCommunication;
/**
* This class models the interface description of opc-ua-nodes.
*/
class OPCUANodeCommunication extends ACommunicationInterfaceData {
constructor() {
super();
this.nodeId = {};
// this.access = 'access: undefined';
}
// protected access: string;
/**
* Getter. Maybe use a TODO: new interface
* @param callback
*/
getNodeId(callback) {
this.genericPiMAdGetter(this.nodeId, callback);
}
/**
* Initialize this instance with interface description data. Caution: After a successful initialisation one cannot
* initialize it again. Spawn a new object instead.
* @param instructions - Most params a standard. In the context of opc-ua the macrocosm is the namespace and the
* microcosm is the identifier of the opc-ua-node.
*/
initialize(instructions) {
if (!this.initialized) {
// TODO > The NodeId stuff is quick an dirty. It feels quit uncomfortable... Only supports String node id's so far...
const localNodeId = new NodeId_1.NodeIdVendor().buy(pimad_types_1.NodeIdTypeEnum.STRING);
this.initialized = (
/* this.moduleAutomationObjectInitialize({
dataSourceIdentifier: instructions.dataSourceIdentifier,
metaModelRef: instructions.metaModelRef,
name: instructions.name,
pimadIdentifier: instructions.pimadIdentifier
})*/
localNodeId.initialize({
namespaceIndex: instructions.interfaceDescription.macrocosm,
identifier: instructions.interfaceDescription.microcosm
}));
this.nodeId = localNodeId;
return this.initialized;
}
else {
return false;
}
}
}
exports.OPCUANodeCommunication = OPCUANodeCommunication;
/**
* Enum of different communication interface data classes.
*/
var CommunicationInterfaceDataEnum;
(function (CommunicationInterfaceDataEnum) {
/**
* {@link OPCUAServerCommunication}
*/
CommunicationInterfaceDataEnum[CommunicationInterfaceDataEnum["OPCUAServer"] = 0] = "OPCUAServer";
/**
* {@link OPCUANodeCommunication}
*/
CommunicationInterfaceDataEnum[CommunicationInterfaceDataEnum["OPCUANode"] = 1] = "OPCUANode";
})(CommunicationInterfaceDataEnum = exports.CommunicationInterfaceDataEnum || (exports.CommunicationInterfaceDataEnum = {}));
/**
* Actually no deeper purpose ...
*/
class ACommunicationInterfaceDataFactory {
}
/**
* Factory for instances of {@link OPCUANodeCommunication}.
*/
class OPCUANodeCommunicationFactory extends ACommunicationInterfaceDataFactory {
/**
* Create an instance of {@link OPCUANodeCommunication}.
*/
create() {
const communicationInterfaceData = new OPCUANodeCommunication();
Utils_1.logger.debug(this.constructor.name + ' creates a ' + communicationInterfaceData.constructor.name);
return communicationInterfaceData;
}
}
/**
* Factory for instances of {@link OPCUAServerCommunication}.
*/
class OPCUAServerCommunicationFactory extends ACommunicationInterfaceDataFactory {
/**
* Create an instance of {@link OPCUAServerCommunication}.
*/
create() {
const communicationInterfaceData = new OPCUAServerCommunication();
Utils_1.logger.debug(this.constructor.name + ' creates a ' + communicationInterfaceData.constructor.name);
return communicationInterfaceData;
}
}
/**
* This class allows you to purchase different instances of the {@link CommunicationInterfaceData} interface.
*/
class CommunicationInterfaceDataVendor {
constructor() {
this.opcuaNodeCommunicationFactory = new OPCUANodeCommunicationFactory();
this.opcuaServerCommunicationFactory = new OPCUAServerCommunicationFactory();
}
/**
* Buy a specific instance of CommunicationInterfaceData interface.
* @param interfaceDataClass - Define via parameter which interface you want to buy.
*/
buy(interfaceDataClass) {
switch (interfaceDataClass) {
case CommunicationInterfaceDataEnum.OPCUANode:
return this.opcuaNodeCommunicationFactory.create();
case CommunicationInterfaceDataEnum.OPCUAServer:
return this.opcuaServerCommunicationFactory.create();
}
}
}
exports.CommunicationInterfaceDataVendor = CommunicationInterfaceDataVendor;