@p2olab/pimad-core
Version:
PiMAd (Process-industry-Modular-Automation-description) High level access to automation of modular plants.
222 lines (221 loc) • 8.15 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NodeIdVendor = exports.GUIDNodeIdFactory = exports.QpaqueNodeIdFactory = exports.StringNodeIdFactory = exports.NumericNodeIdFactory = void 0;
const Utils_1 = require("../Utils");
const ModuleAutomationObject_1 = require("./ModuleAutomationObject");
const pimad_types_1 = require("@p2olab/pimad-types");
class ANodeId extends ModuleAutomationObject_1.AModuleAutomationObject {
constructor() {
super();
this.namespaceIndex = -1;
this.identifier = {};
}
/**
* A general but protected setter for the namespace index of the OPC-UA-NodeId. Main goal: reduce code duplication.
* @param namespaceIndex - The namespace index as number. Follows the rules of the standard and must be >= zero.
* @protected
*/
setNamespaceIndex(namespaceIndex) {
if (namespaceIndex < 0) {
return false;
}
else {
this.namespaceIndex = namespaceIndex;
return true;
}
}
/**
* @inheritDoc {@link NodeId.getNamespaceIndex}
*/
getNamespaceIndex(callback) {
this.genericPiMAdGetter(this.namespaceIndex, callback);
}
/**
* @inheritDoc {@link NodeId.getNodeIdIdentifier}
*/
getNodeIdIdentifier(callback) {
this.genericPiMAdGetter('' + this.identifier, callback);
}
/**
* @inheritDoc {@link NodeId.initialize}
*/
initialize(instructions) {
if (!this.initialized) {
this.identifier = instructions.identifier;
if (!this.setNamespaceIndex(instructions.namespaceIndex)) {
return false;
}
this.initialized = (this.identifier === instructions.identifier &&
this.namespaceIndex === instructions.namespaceIndex);
return this.initialized;
}
else {
return false;
}
}
}
/**
* Model for numeric OPC-UA-NodeId.
*/
class NumericNodeId extends ANodeId {
/**
* Get the nodeId as string. Like toString() ... , but via callback.
* @param callback - A callback function. The response object shows the status (success while object was initialized
* or error while not) of the request via the object-type, while the nodeId object the standard conform combination
* of namespace-index and identifier as a string. In case of a StringNodeId it's something like:
* ns=($namespace-index);i=($identifier)
*/
getNodeId(callback) {
this.genericPiMAdGetter('ns=' + this.namespaceIndex + ';i=' + this.identifier, callback);
}
/**
* Initialize the numeric NodeId object with namespace-index and identifier. Caution: The string identifier will be
* converted to a number and has to pass a validation process afterwards.
* @param instructions - Pass the namespace-index and identifier of OPC-UA-NodeIds to the instance.
*/
initialize(instructions) {
if (!this.initialized) {
if (isNaN(Number(instructions.identifier)) || (Number(instructions.identifier) <= 1)) {
return false;
}
else {
this.identifier = Number(instructions.identifier);
}
if (!this.setNamespaceIndex(instructions.namespaceIndex)) {
return false;
}
this.initialized = (String(this.identifier) === instructions.identifier &&
this.namespaceIndex === instructions.namespaceIndex);
return this.initialized;
}
else {
return false;
}
}
constructor() {
super();
this.identifier = -1;
}
}
/**
* Model for String-OPC-UA-NodeId.
*/
class StringNodeId extends ANodeId {
/**
* Get the nodeId as string. Like toString() ... , but via callback.
* @param callback - A callback function. The response object shows the status (success while object was initialized
* or error while not) of the request via the object-type, while the nodeId object the standard conform combination
* of namespace-index and identifier as a string. In case of a StringNodeId it's somthing like:
* ns=($namespace-index);s=($identifier)
*/
getNodeId(callback) {
this.genericPiMAdGetter('ns=' + this.namespaceIndex + ';s=' + this.identifier, callback);
}
constructor() {
super();
this.identifier = 'identifier: not initialized';
}
}
/**
* Model for Qpaque-OPC-UA-NodeId.
*/
class QpaqueNodeId extends StringNodeId {
/**
* Get the nodeId as string. Like toString() ... , but via callback.
* @param callback - A callback function. The response object shows the status (success while object was initialized
* or error while not) of the request via the object-type, while the nodeId object the standard conform combination
* of namespace-index and identifier as a string. In case of a StringNodeId it's something like:
* ns=($namespace-index);b=($identifier)
*/
getNodeId(callback) {
this.genericPiMAdGetter('ns=' + this.namespaceIndex + ';b=' + this.identifier, callback);
}
constructor() {
super();
}
}
/**
* Model for GUID-OPC-UA-NodeId.
*/
class GUIDNodeId extends StringNodeId {
/**
* Get the nodeId as string. Like toString() ... , but via callback.
* @param callback - A callback function. The response object shows the status (success while object was initialized
* or error while not) of the request via the object-type, while the nodeId object the standard conform combination
* of namespace-index and identifier as a string. In case of a StringNodeId it's something like:
* ns=($namespace-index);g=($identifier)
*/
getNodeId(callback) {
this.genericPiMAdGetter('ns=' + this.namespaceIndex + ';g=' + this.identifier, callback);
}
constructor() {
super();
}
}
class ANodeIdFactory {
}
/**
* This factory creates {@link NumericNodeId}s.
*/
class NumericNodeIdFactory extends ANodeIdFactory {
create() {
const nodeId = new NumericNodeId();
Utils_1.logger.debug(this.constructor.name + ' creates a ' + nodeId.constructor.name);
return nodeId;
}
}
exports.NumericNodeIdFactory = NumericNodeIdFactory;
/**
* This factory creates {@link StringNodeId}s.
*/
class StringNodeIdFactory extends ANodeIdFactory {
create() {
const nodeId = new StringNodeId();
Utils_1.logger.debug(this.constructor.name + ' creates a ' + nodeId.constructor.name);
return nodeId;
}
}
exports.StringNodeIdFactory = StringNodeIdFactory;
/**
* This factory creates {@link QpaqueNodeId}'s.
*/
class QpaqueNodeIdFactory {
create() {
const nodeId = new QpaqueNodeId();
Utils_1.logger.debug(this.constructor.name + ' creates a ' + nodeId.constructor.name);
return nodeId;
}
}
exports.QpaqueNodeIdFactory = QpaqueNodeIdFactory;
/**
* This factory creates {@link GUIDNodeId}'s.
*/
class GUIDNodeIdFactory {
create() {
const nodeId = new GUIDNodeId();
Utils_1.logger.debug(this.constructor.name + ' creates a ' + nodeId.constructor.name);
return nodeId;
}
}
exports.GUIDNodeIdFactory = GUIDNodeIdFactory;
class NodeIdVendor {
constructor() {
this.numericNodeIdFactory = new NumericNodeIdFactory();
this.stringNodeIdFactory = new StringNodeIdFactory();
this.qpaqueNodeIdFactory = new QpaqueNodeIdFactory();
this.gUIDNodeIdFactory = new GUIDNodeIdFactory();
}
buy(type) {
switch (type) {
case pimad_types_1.NodeIdTypeEnum.GUID:
return this.gUIDNodeIdFactory.create();
case pimad_types_1.NodeIdTypeEnum.NUMERIC:
return this.numericNodeIdFactory.create();
case pimad_types_1.NodeIdTypeEnum.OPAQUE:
return this.qpaqueNodeIdFactory.create();
case pimad_types_1.NodeIdTypeEnum.STRING:
return this.stringNodeIdFactory.create();
}
}
}
exports.NodeIdVendor = NodeIdVendor;