Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// TimeZoneDataType
const timeZoneDataType = addressSpace.findDataType(resolveNodeId(DataTypeIds.TimeZoneDataType))!;
// xx console.log(timeZoneDataType.toString());
const timeZone = new TimeZoneDataType({
daylightSavingInOffset: /* boolean*/ false,
offset: /* int16 */ 0
});
bindStandardScalar(VariableIds.Server_LocalTime,
DataType.ExtensionObject, () => {
return timeZone;
});
bindStandardScalar(VariableIds.Server_ServiceLevel,
DataType.Byte, () => {
return 255;
});
bindStandardScalar(VariableIds.Server_Auditing,
DataType.Boolean, () => {
return engine.isAuditing;
});
function bindServerDiagnostics() {
bindStandardScalar(VariableIds.Server_ServerDiagnostics_EnabledFlag,
DataType.Boolean, () => {
return engine.serverDiagnosticsEnabled;
}, (newFlag: boolean) => {
engine.serverDiagnosticsEnabled = newFlag;
});
function adjustVariant(uaVariable, variant) {
const self = uaVariable;
// convert Variant( Scalar|ByteString) => Variant(Array|ByteArray)
const addressSpace = self.addressSpace;
const basicType = addressSpace.findCorrespondingBasicDataType(uaVariable.dataType);
if (basicType === DataType.Byte && uaVariable.valueRank === 1) {
if (variant.arrayType === VariantArrayType.Scalar && variant.dataType === DataType.ByteString) {
if ((uaVariable.dataType.value === DataType.Byte.value) && (self.dataType.namespace === 0)) { // Byte
variant.arrayType = VariantArrayType.Array;
variant.dataType = DataType.Byte;
assert(variant.dataType === DataType.Byte);
assert(!variant.value || variant.value instanceof Buffer);
}
}
}
if (basicType === DataType.ByteString && uaVariable.valueRank === -1 /* Scalar*/) {
if (variant.arrayType === VariantArrayType.Array && variant.dataType === DataType.Byte) {
if ((self.dataType.value === DataType.ByteString.value) && (self.dataType.namespace === 0)) { // Byte
variant.arrayType = VariantArrayType.Scalar;
variant.dataType = DataType.ByteString;
assert(variant.dataType === DataType.ByteString);
assert(!variant.value || variant.value instanceof Buffer);
}
}
}
function adjustVariant(uaVariable, variant) {
const self = uaVariable;
// convert Variant( Scalar|ByteString) => Variant(Array|ByteArray)
const addressSpace = self.addressSpace;
const basicType = addressSpace.findCorrespondingBasicDataType(uaVariable.dataType);
if (basicType === DataType.Byte && uaVariable.valueRank === 1) {
if (variant.arrayType === VariantArrayType.Scalar && variant.dataType === DataType.ByteString) {
if ((uaVariable.dataType.value === DataType.Byte.value) && (self.dataType.namespace === 0)) { // Byte
variant.arrayType = VariantArrayType.Array;
variant.dataType = DataType.Byte;
assert(variant.dataType === DataType.Byte);
assert(!variant.value || variant.value instanceof Buffer);
}
}
}
if (basicType === DataType.ByteString && uaVariable.valueRank === -1 /* Scalar*/) {
if (variant.arrayType === VariantArrayType.Array && variant.dataType === DataType.Byte) {
if ((self.dataType.value === DataType.ByteString.value) && (self.dataType.namespace === 0)) { // Byte
variant.arrayType = VariantArrayType.Scalar;
variant.dataType = DataType.ByteString;
bindVariableIfPresent(nodeId, {
get: function () {
const value = func();
assert(_.isArray(value));
return new Variant({
dataType: variantDataType,
arrayType: VariantArrayType.Array,
value: value
});
},
set: null // read only
});
}
bindStandardScalar(VariableIds.Server_ServiceLevel,
DataType.Byte, function () {
return 255;
});
bindStandardScalar(VariableIds.Server_Auditing,
DataType.Boolean, function () {
return engine.isAuditing;
});
function bindServerDiagnostics() {
bindStandardScalar(VariableIds.Server_ServerDiagnostics_EnabledFlag,
DataType.Boolean, function () {
return engine.serverDiagnosticsEnabled;
}, function (newFlag) {
engine.serverDiagnosticsEnabled = newFlag;
function adjustVariant(this: UAVariable, variant: Variant): Variant {
// convert Variant( Scalar|ByteString) => Variant(Array|ByteArray)
const addressSpace = this.addressSpace;
const basicType = addressSpace.findCorrespondingBasicDataType(this.dataType);
if (basicType === DataType.Byte && this.valueRank === 1) {
if (variant.arrayType === VariantArrayType.Scalar && variant.dataType === DataType.ByteString) {
if ((this.dataType.value === DataType.Byte) && (this.dataType.namespace === 0)) { // Byte
variant.arrayType = VariantArrayType.Array;
variant.dataType = DataType.Byte;
assert(variant.dataType === DataType.Byte);
assert(!variant.value || variant.value instanceof Buffer);
}
}
}
if (basicType === DataType.ByteString && this.valueRank === -1 /* Scalar*/) {
if (variant.arrayType === VariantArrayType.Array && variant.dataType === DataType.Byte) {
if ((this.dataType.value === DataType.ByteString) && (this.dataType.namespace === 0)) { // Byte
variant.arrayType = VariantArrayType.Scalar;
variant.dataType = DataType.ByteString;
function makeRange(dataTypeStr) {
assert(typeof dataTypeStr === "string");
const dataType = DataType[dataTypeStr];
let engineeringUnitsRange = { low: -200, high: 200 };
let instrumentRange = { low: -200, high: 200 };
if (DataType[dataType][0] === "U" || dataType === DataType.Byte) {
engineeringUnitsRange = { low: 10, high: 250 };
instrumentRange = { low: 10, high: 250 };
}
return { engineeringUnitsRange, instrumentRange };
}
function _addAnalogDataItem(localParentFolder, dataType, initialValue) {
UAObject.prototype.readAttribute = function (context, attributeId) {
assert(context instanceof SessionContext);
const now = getCurrentClock();
const options = {};
switch (attributeId) {
case AttributeIds.EventNotifier:
assert(ec.isValidByte(this.eventNotifier));
options.value = {dataType: DataType.Byte, value: this.eventNotifier};
options.serverTimestamp = now.timestamp;
options.serverPicoseconds = now.picoseconds;
options.statusCode = StatusCodes.Good;
break;
default:
return BaseNode.prototype.readAttribute.call(this, context, attributeId);
}
return new DataValue(options);
};
UAVariable.prototype._readAccessLevel = function (context) {
assert(context instanceof SessionContext);
const options = {
value: {dataType: DataType.Byte, value: AccessLevelFlag.toByte(this.accessLevel)},
statusCode: StatusCodes.Good
};
return new DataValue(options);
};
public async open(mode: OpenFileMode): Promise {
if (mode === null || mode === undefined) {
throw new Error("expecting a validMode " + OpenFileMode[mode]);
}
if (this.fileHandle) {
throw new Error("File has already be opened");
}
await this.ensureInitialized();
const result = await this.session.call({
inputArguments: [
{ dataType: DataType.Byte, value: mode as Byte }
],
methodId: this.openMethodNodeId,
objectId: this.fileNodeId
});
if (result.statusCode !== StatusCodes.Good) {
debugLog("Cannot open file : ");
throw new Error("cannot open file statusCode = " + result.statusCode.toString() + "mode = " + OpenFileMode[mode]);
}
this.fileHandle = result.outputArguments![0].value;
return this.fileHandle;
}
private _readUserAccessLevel(context: SessionContext): DataValue {
assert(context instanceof SessionContext);
const effectiveUserAccessLevel = _calculateEffectiveUserAccessLevelFromPermission(
this,
context,
this.userAccessLevel
);
const options = {
value: {
dataType: DataType.Byte,
statusCode: StatusCodes.Good,
value: convertAccessLevelFlagToByte(effectiveUserAccessLevel)
}
};
return new DataValue(options);
}