Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
UAVariable.prototype._readMinimumSamplingInterval = function () {
// expect a Duration => Double
const options = {};
if (this.minimumSamplingInterval === undefined) {
options.statusCode = StatusCodes.BadAttributeIdInvalid;
} else {
options.value = {dataType: DataType.Double, value: this.minimumSamplingInterval};
options.statusCode = StatusCodes.Good;
}
return new DataValue(options);
};
const itemToMonitor = monitoredItemCreateRequest.itemToMonitor;
const node = addressSpace.findNode(itemToMonitor.nodeId);
if (!node) {
return handle_error(StatusCodes.BadNodeIdUnknown);
}
if (itemToMonitor.attributeId === AttributeIds.Value && !(node.nodeClass === NodeClass.Variable)) {
// AttributeIds.Value is only valid for monitoring value of UAVariables.
return handle_error(StatusCodes.BadAttributeIdInvalid);
}
if (itemToMonitor.attributeId === AttributeIds.INVALID) {
return handle_error(StatusCodes.BadAttributeIdInvalid);
}
if (!itemToMonitor.indexRange.isValid()) {
return handle_error(StatusCodes.BadIndexRangeInvalid);
}
// check dataEncoding applies only on Values
if (itemToMonitor.dataEncoding.name && itemToMonitor.attributeId !== AttributeIds.Value) {
return handle_error(StatusCodes.BadDataEncodingInvalid);
}
// check dataEncoding
if (!isValidDataEncoding(itemToMonitor.dataEncoding)) {
return handle_error(StatusCodes.BadDataEncodingUnsupported);
}
BaseNode.prototype.writeAttribute = function (context, writeValue, callback) {
assert(context instanceof SessionContext);
assert(_.isFunction(callback));
if (writeValue.attributeId <= 0 || writeValue.attributeId > AttributeIds.UserExecutable) {
return callback(null, StatusCodes.BadAttributeIdInvalid);
}
// by default Node is read-only,
// this method needs to be overridden to change the behavior
callback(null, StatusCodes.BadNotWritable);
};
public writeAttribute(
context: SessionContext,
writeValue: any,
callback: (err: Error | null, statusCode?: StatusCode) => void
) {
assert(context instanceof SessionContext);
assert(_.isFunction(callback));
if (writeValue.attributeId <= 0 || writeValue.attributeId > AttributeIds.UserExecutable) {
return callback(null, StatusCodes.BadAttributeIdInvalid);
}
// by default Node is read-only,
// this method needs to be overridden to change the behavior
callback(null, StatusCodes.BadNotWritable);
}
private _readMinimumSamplingInterval(): DataValue {
// expect a Duration => Double
const options: DataValueLike = {};
if (this.minimumSamplingInterval === undefined) {
options.statusCode = StatusCodes.BadAttributeIdInvalid;
} else {
options.value = { dataType: DataType.Double, value: this.minimumSamplingInterval };
options.statusCode = StatusCodes.Good;
}
return new DataValue(options);
}
assert(monitoredItemCreateRequest instanceof MonitoredItemCreateRequest);
function handle_error(statusCode: StatusCode): MonitoredItemCreateResult {
return new MonitoredItemCreateResult({ statusCode });
}
const itemToMonitor = monitoredItemCreateRequest.itemToMonitor;
const node = addressSpace.findNode(itemToMonitor.nodeId);
if (!node) {
return handle_error(StatusCodes.BadNodeIdUnknown);
}
if (itemToMonitor.attributeId === AttributeIds.Value && !(node.nodeClass === NodeClass.Variable)) {
// AttributeIds.Value is only valid for monitoring value of UAVariables.
return handle_error(StatusCodes.BadAttributeIdInvalid);
}
if (itemToMonitor.attributeId === AttributeIds.INVALID) {
return handle_error(StatusCodes.BadAttributeIdInvalid);
}
if (!itemToMonitor.indexRange.isValid()) {
return handle_error(StatusCodes.BadIndexRangeInvalid);
}
// check dataEncoding applies only on Values
if (itemToMonitor.dataEncoding.name && itemToMonitor.attributeId !== AttributeIds.Value) {
return handle_error(StatusCodes.BadDataEncodingInvalid);
}
// check dataEncoding
case AttributeIds.Description: // LocalizedText
options.value = {dataType: DataType.LocalizedText, value: this.description};
break;
case AttributeIds.WriteMask:
options.value = {dataType: DataType.UInt32, value: this.getWriteMask()};
break;
case AttributeIds.UserWriteMask:
options.value = {dataType: DataType.UInt32, value: this.getUserWriteMask()};
break;
default:
options.value = null;
//xx debugLog("class Name ", this.constructor.name, (" BaseNode : '" + this.browseName + "' nodeid=" + this.nodeId.toString()).yellow, " cannot get attribute ", AttributeNameById[attributeId], "(", attributeId, ")");
options.statusCode = StatusCodes.BadAttributeIdInvalid;
break;
}
//xx options.serverTimestamp = new Date();
return new DataValue(options);
};
case AttributeIds.Description: // LocalizedText
options.value = { dataType: DataType.LocalizedText, value: this.description };
break;
case AttributeIds.WriteMask:
options.value = { dataType: DataType.UInt32, value: this.getWriteMask() };
break;
case AttributeIds.UserWriteMask:
options.value = { dataType: DataType.UInt32, value: this.getUserWriteMask() };
break;
default:
options.value = null;
options.statusCode = StatusCodes.BadAttributeIdInvalid;
break;
}
// xx options.serverTimestamp = new Date();
return new DataValue(options);
}
const options: DataValueLike = {};
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:
options.value = { dataType: DataType.Int32, value: this.valueRank };
options.statusCode = StatusCodes.Good;
break;
case AttributeIds.ArrayDimensions:
assert(_.isArray(this.arrayDimensions) || this.arrayDimensions === null);
options.value = {
arrayType: VariantArrayType.Array,
dataType: DataType.UInt32,
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:
options.value = {dataType: DataType.Int32, value: this.valueRank};
options.statusCode = StatusCodes.Good;
break;
case AttributeIds.ArrayDimensions:
assert(_.isArray(this.arrayDimensions) || this.arrayDimensions === null);
options.value = {dataType: DataType.UInt32, arrayType: VariantArrayType.Array, value: this.arrayDimensions};
options.statusCode = StatusCodes.Good;
break;