Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
console.log(" INVALID NODE ID , ", itemToMonitor.nodeId.toString());
dump(itemToMonitor);
return function (oldData, callback) {
callback(null, new DataValue({
statusCode: StatusCodes.BadNodeIdUnknown,
value: {dataType: DataType.Null, value: 0}
}));
};
}
/////!!monitoredItem.setNode(node);
if (itemToMonitor.attributeId === AttributeIds.Value) {
const monitoredItem_read_and_record_value_func =
(itemToMonitor.attributeId === AttributeIds.Value && _.isFunction(node.readValueAsync)) ?
monitoredItem_read_and_record_value_async :
monitoredItem_read_and_record_value;
return function (oldDataValue, callback) {
assert(this instanceof MonitoredItem);
assert(oldDataValue instanceof DataValue);
assert(_.isFunction(callback));
monitoredItem_read_and_record_value_func(this, context, oldDataValue, node, itemToMonitor, callback);
};
} else {
// Attributes, other than the Value Attribute, are only monitored for a change in value.
// The filter is not used for these Attributes. Any change in value for these Attributes
// causes a Notification to be generated.
// handle filter information
if (filter && filter instanceof EventFilter
&& itemToMonitor.attributeId !== AttributeIds.EventNotifier) {
// invalid filter on Event
return StatusCodes.BadFilterNotAllowed;
}
if (filter && filter instanceof DataChangeFilter
&& itemToMonitor.attributeId !== AttributeIds.Value) {
// invalid DataChange filter on non Value Attribute
return StatusCodes.BadFilterNotAllowed;
}
if (filter && itemToMonitor.attributeId !== AttributeIds.EventNotifier
&& itemToMonitor.attributeId !== AttributeIds.Value) {
return StatusCodes.BadFilterNotAllowed;
}
if (filter instanceof DataChangeFilter) {
return __validateDataChangeFilter(filter, itemToMonitor, node as UAVariable);
}
return StatusCodes.Good;
}
let selectClauses = browsePaths.map((browsePath) => {
return new SimpleAttributeOperand({
attributeId: AttributeIds.Value,
browsePath,
indexRange: undefined, // NumericRange
typeDefinitionId: makeNodeId(ObjectTypeIds.BaseEventType) // i=2041
});
});
UAVariable.prototype.writeAttribute = function (context, writeValue, callback) {
assert(context instanceof SessionContext);
assert(writeValue instanceof WriteValue);
assert(writeValue.value instanceof DataValue);
assert(writeValue.value.value instanceof Variant);
assert(_.isFunction(callback));
// Spec 1.0.2 Part 4 page 58
// If the SourceTimestamp or the ServerTimestamp is specified, the Server shall
// use these values.
//xx _apply_default_timestamps(writeValue.value);
switch (writeValue.attributeId) {
case AttributeIds.Value:
this.writeValue(context, writeValue.value, writeValue.indexRange, callback);
break;
case AttributeIds.Historizing:
if (!writeValue.value.value.dataType === DataType.Boolean) {
return callback(null, StatusCodes.BadNotSupported)
}
// if the uavariable has no historization in place reject
if (!this["hA Configuration"]) {
return callback(null, StatusCodes.BadNotSupported)
}
// check if user is allowed to do that !
// TODO
this.historizing = !!writeValue.value.value.value; // yes ! indeed !
return callback(null, StatusCodes.Good);
// OPC Unified Architecture 1.02, Part 4 5.12.1.2 Sampling interval page 64:
// "A Client shall define a sampling interval of 0 if it subscribes for Events."
// toDO
// note : the EventFilter is used when monitoring Events.
self.monitoringParameters.filter = self.monitoringParameters.filter || new subscription_service.EventFilter({});
const filter = self.monitoringParameters.filter;
if (filter._schema.name !== "EventFilter") {
return {
error: "Mismatch between attributeId and filter in monitoring parameters : " +
"Got a " + filter._schema.name + " but a EventFilter object is required when itemToMonitor.attributeId== AttributeIds.EventNotifier"
};
}
} else if (self.itemToMonitor.attributeId === AttributeIds.Value) {
// the DataChangeFilter and the AggregateFilter are used when monitoring Variable Values
// The Value Attribute is used when monitoring Variables. Variable values are monitored for a change
// in value or a change in their status. The filters defined in this standard (see 7.16.2) and in Part 8 are
// used to determine if the value change is large enough to cause a Notification to be generated for the
// to do : check 'DataChangeFilter' && 'AggregateFilter'
} else {
if (self.monitoringParameters.filter) {
return {
error: "Mismatch between attributeId and filter in monitoring parameters : " +
"no filter expected when attributeId is not Value or EventNotifier"
};
}
}
return {
error: null,
});
if (this.itemToMonitor.attributeId === AttributeIds.EventNotifier) {
// istanbul ignore next
if (doDebug) {
debugLog("xxxxxx monitoring EventNotifier on",
this.node.nodeId.toString(), this.node.browseName.toString());
}
// we are monitoring OPCUA Event
this._on_opcua_event_received_callback = this._on_opcua_event.bind(this);
this.node.on("event", this._on_opcua_event_received_callback);
return;
}
if (this.itemToMonitor.attributeId !== AttributeIds.Value) {
// sampling interval only applies to Value Attributes.
this.samplingInterval = 0; // turned to exception-based regardless of requested sampling interval
// non value attribute only react on value change
this._attribute_changed_callback = this._on_value_changed.bind(this);
const event_name = makeAttributeEventName(this.itemToMonitor.attributeId);
this.node.on(event_name, this._attribute_changed_callback);
if (recordInitialValue) {
// read initial value
const dataValue = this.node.readAttribute(context, this.itemToMonitor.attributeId);
this.recordValue(dataValue, true);
}
function read_accessLevels(clientObject, callback) {
const nodesToRead = [
{
nodeId: nodeId,
attributeId: AttributeIds.Value
},
{
nodeId: nodeId,
attributeId: AttributeIds.UserAccessLevel
},
{
nodeId: nodeId,
attributeId: AttributeIds.AccessLevel
}
];
session.read(nodesToRead, 1, function (err, dataValues) {
if (dataValues[0].statusCode === StatusCodes.Good) {
clientObject.dataValue = dataValues[0].value;
}
if (dataValues[1].statusCode === StatusCodes.Good) {
//xx console.log("AccessLevel ", results[3].value.toString())
UAVariableType.prototype.readAttribute = function (context, attributeId) {
assert(context instanceof SessionContext);
const options = {};
switch (attributeId) {
case AttributeIds.IsAbstract:
options.value = {dataType: DataType.Boolean, value: this.isAbstract ? true : false};
options.statusCode = StatusCodes.Good;
break;
case AttributeIds.Value:
if (this.hasOwnProperty("value") && this.value !== undefined) {
assert(this.value.schema.name === "Variant");
options.value = this.value;
options.statusCode = StatusCodes.Good;
} else {
debugLog(" warning Value not implemented");
options.value = {dataType: DataType.UInt32, value: 0};
options.statusCode = StatusCodes.BadAttributeIdInvalid;
}
break;
case AttributeIds.DataType:
assert(this.dataType instanceof NodeId);
options.value = {dataType: DataType.NodeId, value: this.dataType};
options.statusCode = StatusCodes.Good;
break;
case AttributeIds.ValueRank:
UAVariable.prototype.readAttribute = function (context, attributeId, indexRange, dataEncoding) {
if (!context) {
context = SessionContext.defaultContext;
}
assert(context instanceof SessionContext);
const options = {};
if (attributeId !== AttributeIds.Value) {
if (indexRange && indexRange.isDefined()) {
options.statusCode = StatusCodes.BadIndexRangeNoData;
return new DataValue(options);
}
if (is_dataEncoding(dataEncoding)) {
options.statusCode = StatusCodes.BadDataEncodingInvalid;
return new DataValue(options);
}
}
switch (attributeId) {
case AttributeIds.Value:
return this.readValue(context, indexRange, dataEncoding);
case AttributeIds.DataType:
return this._readDataType();
MonitoringParameters
} from "node-opcua-service-subscription";
import {
DataChangeFilter, DataChangeTrigger, DeadbandType,
isOutsideDeadbandAbsolute, isOutsideDeadbandNone, isOutsideDeadbandPercent,
PseudoRange
} from "node-opcua-service-subscription";
import { StatusCode, StatusCodes } from "node-opcua-status-code";
import { EventFieldList, MonitoringFilter, ReadValueIdOptions, SimpleAttributeOperand } from "node-opcua-types";
import { sameVariant, Variant } from "node-opcua-variant";
import { appendToTimer, removeFromTimer } from "./node_sampler";
import { validateFilter } from "./validate_filter";
const defaultItemToMonitor: ReadValueIdOptions = new ReadValueId({
attributeId: AttributeIds.Value,
indexRange: undefined,
});
const debugLog = make_debugLog(__filename);
const doDebug = checkDebugFlag(__filename);
function _adjust_sampling_interval(samplingInterval: number, node_minimumSamplingInterval: number): number {
assert(_.isNumber(node_minimumSamplingInterval), "expecting a number");
if (samplingInterval === 0) {
return (node_minimumSamplingInterval === 0)
? samplingInterval
: Math.max(MonitoredItem.minimumSamplingInterval, node_minimumSamplingInterval);
}
assert(samplingInterval >= 0, " this case should have been prevented outside");