Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const variant = new Variant({ dataType: DataType.Boolean, value });
this._map[idKey] = variant;
// also change varName with human readable text
const twoStateNode = this._node_index[hrKey];
if (!twoStateNode) {
throw new Error("Cannot find twoState Varaible with name " + varName);
}
if (!(twoStateNode instanceof UATwoStateVariable)) {
throw new Error("Cannot find twoState Varaible with name " + varName + " " + twoStateNode);
}
const txt = value ? twoStateNode._trueState : twoStateNode._falseState;
const hrValue = new Variant({
dataType: DataType.LocalizedText,
value: coerceLocalizedText(txt)
});
this._map[hrKey] = hrValue;
const node = this._node_index[idKey];
// also change ConditionNode if we are on currentBranch
if (this.isCurrentBranch()) {
assert(twoStateNode instanceof UATwoStateVariable);
twoStateNode.setValue(value);
// xx console.log("Is current branch", twoStateNode.toString(),variant.toString());
// xx console.log(" = ",twoStateNode.getValue());
}
this.emit("value_changed", node, variant);
}
export function encodeDataValue(dataValue: DataValue, stream: OutputBinaryStream): void {
const encodingMask = getDataValue_EncodingByte(dataValue);
assert(_.isFinite(encodingMask) && encodingMask >= 0 && encodingMask <= 0x3F);
// write encoding byte
encodeUInt8(encodingMask, stream);
// write value as Variant
if (encodingMask & DataValueEncodingByte.Value) {
if (!dataValue.value) {
dataValue.value = new Variant();
}
if (!dataValue.value.encode) {
// tslint:disable-next-line:no-console
console.log(" CANNOT FIND ENCODE METHOD ON VARIANT !!! HELP", JSON.stringify(dataValue, null, " "));
}
dataValue.value.encode(stream);
}
// write statusCode
if (encodingMask & DataValueEncodingByte.StatusCode) {
encodeStatusCode(dataValue.statusCode, stream);
}
// write sourceTimestamp
if ((encodingMask & DataValueEncodingByte.SourceTimestamp) && (dataValue.sourceTimestamp !== null)) {
encodeHighAccuracyDateTime(dataValue.sourceTimestamp, dataValue.sourcePicoseconds, stream);
}
// write sourcePicoseconds
if (options.hasOwnProperty("engineeringUnits")) {
const engineeringUnits = new EUInformation(options.engineeringUnits);
assert(engineeringUnits instanceof EUInformation, "expecting engineering units");
// EngineeringUnits specifies the units for the DataItem‟s value (e.g., DEGC, hertz, seconds). The
// EUInformation type is specified in 5.6.3.
const eu = namespace.addVariable({
propertyOf: variable,
typeDefinition: "PropertyType",
browseName: {name:"EngineeringUnits",namespaceIndex:0},
dataType: "EUInformation",
minimumSamplingInterval: 0,
accessLevel: "CurrentRead",
value: new Variant({
dataType: DataType.ExtensionObject, value: engineeringUnits
}),
modellingRule: options.modellingRule ? "Mandatory" : undefined
});
eu.on("value_changed",handler);
}
variable.install_extra_properties();
return variable;
};
};
function decodeDataValueInternal(dataValue: DataValue, stream: BinaryStream) {
const encodingMask = decodeUInt8(stream);
if (encodingMask & DataValueEncodingByte.Value) {
dataValue.value = new Variant();
dataValue.value.decode(stream);
}
// read statusCode
if (encodingMask & DataValueEncodingByte.StatusCode) {
dataValue.statusCode = decodeStatusCode(stream);
} else {
dataValue.statusCode = StatusCodes.Good;
}
dataValue.sourcePicoseconds = 0;
// read sourceTimestamp
if (encodingMask & DataValueEncodingByte.SourceTimestamp) {
dataValue.sourceTimestamp = decodeHighAccuracyDateTime(stream);
dataValue.sourcePicoseconds += (dataValue.sourceTimestamp as DateWithPicoseconds).picoseconds | 0;
}
// read sourcePicoseconds
"\n v2= " +
condition_value
);
}
self._node_index[key] = aggregate;
_ensure_condition_values_correctness(self, aggregate, prefix + name + ".", error);
}
}
if (displayError && error.length) {
throw new Error(error.join("\n"));
}
}
const disabledVar = new Variant({
dataType: "StatusCode",
value: StatusCodes.BadConditionDisabled
});
// list of Condition variables that should not be published as BadConditionDisabled when the condition
// is in a disabled state.
const _varTable = {
"branchId": 1,
"conditionClassId": 1,
"conditionClassName": 1,
"conditionName": 1,
"enabledState": 1,
"enabledState.effectiveDisplayName": 1,
"enabledState.id": 1,
"enabledState.transitionTime": 1,
"eventId": 1,
}) as UAVariable;
const handler = variable.handle_semantic_changed.bind(variable);
euRange.on("value_changed", handler);
if (options.hasOwnProperty("instrumentRange")) {
const instrumentRange = namespace.addVariable({
accessLevel: "CurrentRead | CurrentWrite",
browseName: { name: "InstrumentRange", namespaceIndex: 0 },
dataType: "Range",
minimumSamplingInterval: 0,
modellingRule: options.modellingRule ? "Mandatory" : undefined,
propertyOf: variable,
typeDefinition: "PropertyType",
value: new Variant({
dataType: DataType.ExtensionObject, value: new Range(options.instrumentRange)
})
});
instrumentRange.on("value_changed", handler);
}
if (options.hasOwnProperty("engineeringUnits")) {
const engineeringUnits = new EUInformation(options.engineeringUnits);
assert(engineeringUnits instanceof EUInformation, "expecting engineering units");
// EngineeringUnits specifies the units for the DataItem‟s value (e.g., DEGC, hertz, seconds). The
// EUInformation type is specified in 5.6.3.
Object.keys(data).forEach(function(key) {
const varNode = _getCompositeKey(conditionNode, key);
assert(varNode instanceof UAVariable);
const variant = new Variant(data[key]);
// check that Variant DataType is compatible with the UAVariable dataType
//xx var nodeDataType = addressSpace.findNode(varNode.dataType).browseName;
/* istanbul ignore next */
if (!varNode._validate_DataType(variant.dataType)) {
throw new Error(" Invalid variant dataType " + variant + " " + varNode.browseName.toString());
}
const value = new Variant(data[key]);
varNode.setValueFromSource(value);
});
public setSourceNode(node: NodeId | BaseNode): void {
const self = this;
self.sourceNode.setValueFromSource(
new Variant({
dataType: DataType.NodeId,
value: (node as any).nodeId ? (node as any).nodeId : node
})
);
}
}