Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private _set_timer() {
assert(this.samplingInterval >= MonitoredItem.minimumSamplingInterval);
assert(!this._samplingId);
if (useCommonTimer) {
this._samplingId = appendToTimer(this);
} else {
// settle periodic sampling
this._samplingId = setInterval(() => {
this._on_sampling_timer();
}, this.samplingInterval);
}
// xx console.log("MonitoredItem#_set_timer",this._samplingId);
}
private _getSubscriptionDiagnosticsArray() {
if (!this.addressSpace) {
if (doDebug) {
console.warn("ServerSession#_getSubscriptionDiagnosticsArray : no addressSpace");
}
return null; // no addressSpace
}
const subscriptionDiagnosticsArray = this.subscriptionDiagnosticsArray;
if (!subscriptionDiagnosticsArray) {
return null; // no subscriptionDiagnosticsArray
}
assert(subscriptionDiagnosticsArray.browseName.toString() === "SubscriptionDiagnosticsArray");
return subscriptionDiagnosticsArray;
}
private _preregisterChannel(channel: ServerSecureChannelLayer) {
// _preregisterChannel is used to keep track of channel for which
// that are in early stage of the hand shaking process.
// e.g HEL/ACK and OpenSecureChannel may not have been received yet
// as they will need to be interrupted when OPCUAServerEndPoint is closed
assert(this._started, "OPCUAServerEndPoint must be started");
assert(!this._channels.hasOwnProperty(channel.hashKey), " channel already preregistered!");
this._channels[channel.hashKey] = channel;
(channel as any)._unpreregisterChannelEvent = () => {
debugLog("Channel received an abort event during the preregistration phase");
this._un_pre_registerChannel(channel);
channel.dispose();
};
channel.on("abort", (channel as any)._unpreregisterChannelEvent);
}
// DeadbandType = PercentDeadband
// For this type of deadband the deadbandValue is defined as the percentage of the EURange. That is,
// it applies only to AnalogItems with an EURange Property that defines the typical value range for the
// item. This range shall be multiplied with the deadbandValue and then compared to the actual value change
// to determine the need for a data change notification. The following pseudo code shows how the deadband
// is calculated:
// DataChange if (absolute value of (last cached value - current value) >
// (deadbandValue/100.0) * ((high-low) of EURange)))
//
// Specifying a deadbandValue outside of this range will be rejected and reported with the
// StatusCode Bad_DeadbandFilterInvalid (see Table 27).
// If the Value of the MonitoredItem is an array, then the deadband calculation logic shall be applied to
// each element of the array. If an element that requires a DataChange is found, then no further
// deadband checking is necessary and the entire array shall be returned.
assert(self.node !== null, "expecting a valid address_space object here to get access the the EURange");
if (self.node.euRange) {
// double,double
const rangeVariant = self.node.euRange.readValue().value;
const range = rangeVariant.value.high - rangeVariant.value.high;
assert(_.isFinite(range));
return checkDeadBand(oldDataValue.value, newDataValue.value, DeadbandType.Percent, deadbandValue, range);
}
return true;
}
}
function _Variable_bind_with_simple_set(options) {
/* jshint validthis: true */
const self = this;
assert(self instanceof UAVariable);
assert(_.isFunction(options.set), "should specify set function");
assert(!options.timestamped_set, "should not specify a timestamped_set function");
assert(!self._timestamped_set_func);
assert(!self._set_func);
self._set_func = turn_sync_to_async(options.set, 1);
assert(self._set_func.length === 2, " set function must have 2 arguments ( variant, callback)");
self._timestamped_set_func = function (timestamped_value, indexRange, callback) {
assert(timestamped_value instanceof DataValue);
self._set_func(timestamped_value.value, function (err, statusCode) {
callback(err, statusCode, timestamped_value);
});
};
}
const self = this;
assert(!options.hasOwnProperty("arrayDimension"), "Do you mean ArrayDimensions ?");
// dataType
options.dataType = options.dataType || "Int32";
options.dataType = self.addressSpace._coerce_DataType(options.dataType);
// valueRank
options.valueRank = utils.isNullOrUndefined(options.valueRank) ? -1 : options.valueRank;
assert(_.isFinite(options.valueRank));
assert(typeof options.valueRank === "number");
// arrayDimensions
options.arrayDimensions = options.arrayDimensions || null;
assert(_.isArray(options.arrayDimensions) || options.arrayDimensions === null);
const variableType = self._addObjectOrVariableType(options, "BaseVariableType", NodeClass.VariableType);
variableType.dataType = options.dataType;
variableType.valueRank = options.valueRank;
variableType.arrayDimensions = options.arrayDimensions;
return variableType;
};
public registerTypeDictionary(nodeId: NodeId, typeDictionary: TypeDictionary) {
/* istanbul ignore next */
if (this.hasDataTypeDictionary(nodeId)) {
throw new Error("Dictionary already registered");
}
this.typeDictionaries[this.makeKey(nodeId)] = typeDictionary;
assert(nodeId.namespace !== 0,
"registerTypeDictionary cannot be used for namespace 0");
assert(!this.typeDictionariesByNamespace.hasOwnProperty(nodeId.namespace),
"already registered");
this.typeDictionariesByNamespace[nodeId.namespace] = typeDictionary;
}
public registerTypeDictionary(nodeId: NodeId, typeDictionary: TypeDictionary) {
/* istanbul ignore next */
if (this.hasDataTypeDictionary(nodeId)) {
throw new Error("Dictionary already registered");
}
this.typeDictionaries[this.makeKey(nodeId)] = typeDictionary;
assert(nodeId.namespace !== 0,
"registerTypeDictionary cannot be used for namespace 0");
assert(!this.typeDictionariesByNamespace.hasOwnProperty(nodeId.namespace),
"already registered");
this.typeDictionariesByNamespace[nodeId.namespace] = typeDictionary;
}
function getRandomFuncForType(dataType) {
assert(dataType);
const dataTypeName = DataType[dataType];
const f = ec["random" + dataTypeName];
if (f) {
return f;
}
//xx console.log("xxxx dataType ",dataType);
switch (dataTypeName) {
case "Variant":
return function() {
return new Variant();
};
case "QualifiedName":
return function() {
addressSpace.modelChangeTransaction(function () {
assert(isNonEmptyQualifiedName(options.browseName));
//xx assert(options.hasOwnProperty("browseName") && options.browseName.length > 0);
assert(options.hasOwnProperty("nodeClass"));
options.references = addressSpace.normalizeReferenceTypes(options.references);
const references = _copy_references(options.references);
_handle_hierarchy_parent(addressSpace, references, options);
_handle_event_hierarchy_parent(addressSpace, references, options);
UANamespace._process_modelling_rule(references, options.modellingRule);
options.references = references;
node = self._createNode(options);
assert(node.nodeId instanceof NodeId);
node.propagate_back_references();