Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
value: number | boolean | null,
statusCode: StatusCode
): DataValue {
// setup data
const sourceTimestamp = makeDate(time);
if (value === undefined || value === null) {
return new DataValue({
sourceTimestamp,
statusCode,
value: undefined,
});
} else if (typeof value === "boolean") {
return new DataValue({
sourceTimestamp,
statusCode,
value: {dataType: DataType.Boolean, value},
});
} else {
return new DataValue({
sourceTimestamp,
statusCode,
value: {dataType: DataType.Float, value},
});
}
}
const indexRange = nodeToRead.indexRange;
const dataEncoding = nodeToRead.dataEncoding;
if (timestampsToReturn === TimestampsToReturn.Invalid) {
return new DataValue({ statusCode: StatusCodes.BadTimestampsToReturnInvalid });
}
timestampsToReturn = (timestampsToReturn !== undefined) ? timestampsToReturn : TimestampsToReturn.Neither;
const obj = engine.__findObject(nodeId!);
let dataValue;
if (!obj) {
// may be return BadNodeIdUnknown in dataValue instead ?
// Object Not Found
return new DataValue({ statusCode: StatusCodes.BadNodeIdUnknown });
} else {
// check access
// BadUserAccessDenied
// BadNotReadable
// invalid attributes : BadNodeAttributesInvalid
// invalid range : BadIndexRangeInvalid
try {
dataValue = obj.readAttribute(context, attributeId, indexRange, dataEncoding);
assert(dataValue.statusCode instanceof StatusCode);
if (!dataValue.isValid()) {
console.log("Invalid value for node ", obj.nodeId.toString(), obj.browseName.toString());
}
} catch (err) {
console.log(" Internal error reading NodeId ", obj.nodeId.toString());
}
}
// if (variant.hasOwnProperty("value")) {
// if (variant.dataType === DataType.UInt32) {
// if (!_.isFinite(variant.value)) {
// throw new Error("Expecting an number");
// }
// }
// }
variant = Variant.coerce(variant);
const now = coerceClock(sourceTimestamp, 0);
const dataValue = new DataValue({
sourceTimestamp: now.timestamp,
sourcePicoseconds: now.picoseconds,
serverTimestamp: now.timestamp,
serverPicoseconds: now.picoseconds,
statusCode: statusCode || StatusCodes.Good
});
dataValue.value = variant;
self._internal_set_dataValue(dataValue, null);
};
const steppedValue = (previousDataValue: DataValue): DataValue => {
if (!previousDataValue.statusCode) {
throw new Error("Expecting statusCode");
}
const interpValue = new DataValue({
sourceTimestamp: interval.startTime,
statusCode: StatusCodes.Bad,
value: previousDataValue.value,
});
interpValue.statusCode =
StatusCode.makeStatusCode(StatusCodes.UncertainDataSubNormal, "HistorianInterpolated");
return interpValue;
};
timestamped_get() {
const value = prepareVariantValue(dataTypeNodeId, self.$extensionObject[name]);
propertyNode._dataValue.statusCode = StatusCodes.Good;
propertyNode._dataValue.value.value = value;
return new DataValue(propertyNode._dataValue);
},
timestamped_set(dataValue, callback) {
public readAttribute(context: SessionContext | null, attributeId: AttributeIds): DataValue {
assert(!context || context instanceof SessionContext);
const options: DataValueLike = {};
switch (attributeId) {
case AttributeIds.IsAbstract:
options.statusCode = StatusCodes.Good;
options.value = { dataType: DataType.Boolean, value: !!this.isAbstract };
break;
default:
return super.readAttribute(context, attributeId);
}
return new DataValue(options);
}
private _readDataType(): DataValue {
assert(this.dataType instanceof NodeId);
const options = {
statusCode: StatusCodes.Good,
value: {
dataType: DataType.NodeId,
value: this.dataType
}
};
return new DataValue(options);
}
func = function (callback) {
const dataValue = new DataValue({statusCode: StatusCodes.BadUserAccessDenied});
callback(null, dataValue);
}
} else {
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);
};
const self = this;
const options = {};
switch (attributeId) {
case AttributeIds.Executable:
options.value = {dataType: DataType.Boolean, value: self.getExecutableFlag(context)};
options.statusCode = StatusCodes.Good;
break;
case AttributeIds.UserExecutable:
options.value = {dataType: DataType.Boolean, value: self.getExecutableFlag(context)};
options.statusCode = StatusCodes.Good;
break;
default:
return BaseNode.prototype.readAttribute.call(this, context, attributeId);
}
return new DataValue(options);
};