Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("should bind an xml-preloaded Extension Object Variable : ServerStatus ", function (done) {
// in this test, we verify that we can easily bind the Server_ServerStatus object
// the process shall automatically bind variables and substructures recursively
var VariableIds = require("node-opcua-constants").VariableIds;
var makeNodeId = require("node-opcua-nodeid").makeNodeId;
var serverStatus = addressSpace.findNode(makeNodeId(VariableIds.Server_ServerStatus));
serverStatus.browseName.toString().should.eql("ServerStatus");
// before bindExtensionObject is called, startTime property exists but is not bound
serverStatus.should.have.property("startTime");
serverStatus.startTime.readValue().value.dataType.should.eql(DataType.Null);
serverStatus.readValue().value.dataType.should.eql(DataType.Null);
//Xx value.startTime.should.eql(DataType.Null);
//xx debugLog("serverStatus.startTime =",serverStatus.startTime.readValue().value.toString());
serverStatus.bindExtensionObject();
serverStatus.readValue().value.value.startTime.toISOString().should.eql("1601-01-01T00:00:00.000Z");
serverStatus.startTime.readValue().value.value.toISOString().should.eql("1601-01-01T00:00:00.000Z");
serverStatus.readValue().value.value.startTime = new Date(Date.UTC(1800, 0, 1));
serverStatus.readValue().value.value.startTime.toISOString().should.eql("1800-01-01T00:00:00.000Z");
serverStatus.startTime.readValue().value.value.toISOString().should.eql("1800-01-01T00:00:00.000Z");
it("should bind an xml-preloaded Extension Object Variable : ServerStatus ", function (done) {
// in this test, we verify that we can easily bind the Server_ServerStatus object
// the process shall automatically bind variables and substructures recursively
var VariableIds = require("node-opcua-constants").VariableIds;
var makeNodeId = require("node-opcua-nodeid").makeNodeId;
var serverStatus = addressSpace.findNode(makeNodeId(VariableIds.Server_ServerStatus));
serverStatus.browseName.toString().should.eql("ServerStatus");
// before bindExtensionObject is called, startTime property exists but is not bound
serverStatus.should.have.property("startTime");
serverStatus.startTime.readValue().value.dataType.should.eql(DataType.Null);
serverStatus.readValue().value.dataType.should.eql(DataType.Null);
//Xx value.startTime.should.eql(DataType.Null);
//xx debugLog("serverStatus.startTime =",serverStatus.startTime.readValue().value.toString());
serverStatus.bindExtensionObject();
serverStatus.readValue().value.value.startTime.toISOString().should.eql("1601-01-01T00:00:00.000Z");
serverStatus.startTime.readValue().value.value.toISOString().should.eql("1601-01-01T00:00:00.000Z");
serverStatus.readValue().value.value.startTime = new Date(Date.UTC(1800, 0, 1));
serverStatus.readValue().value.value.startTime.toISOString().should.eql("1800-01-01T00:00:00.000Z");
serverStatus.startTime.readValue().value.value.toISOString().should.eql("1800-01-01T00:00:00.000Z");
serverStatus.startTime.setValueFromSource({dataType: DataType.DateTime, value: new Date(Date.UTC(2100, 0, 1))});
function _process_var(self,prefix,node) {
const lowerName =prefix + lowerFirstLetter(node.browseName.name);
// istanbul ignore next
if (doDebug) { console.log(" "+lowerName.toString()); }
visitedProperties[lowerName] = node;
if (data.hasOwnProperty(lowerName)) {
eventData.setValue(lowerName,node,data[lowerName]);
//xx eventData[lowerName] = _coerceVariant(data[lowerName]);
} else {
// add a property , but with a null variant
eventData.setValue(lowerName,node,{ dataType: DataType.Null});
if (doDebug) {
if (node.modellingRule === "Mandatory") {
console.log("ERROR : AddressSpace#constructEventData(eventType,options) cannot find property ".red
+ self.browseName.toString() + " => " + lowerName.cyan);
} else {
console.log("Warning : AddressSpace#constructEventData(eventType,options) cannot find property ".yellow
+ self.browseName.toString() + " => " + lowerName.cyan);
}
}
}
}
function makeDefaultVariant(
addressSpace: AddressSpacePublic,
dataTypeNode: NodeId,
valueRank: number
): VariantOptions | undefined {
let variant: VariantOptions = { dataType: DataType.Null };
const nodeDataType = addressSpace.findNode(dataTypeNode);
if (nodeDataType) {
const dataType = addressSpace.findCorrespondingBasicDataType(dataTypeNode);
if (dataType === DataType.ExtensionObject) {
// console.log("xxxxxxxxxx ", dataTypeNode.toString(addressSpace as any));
return variant;
}
const dv = findSimpleType(DataType[dataType]).defaultValue;
let arrayType: VariantArrayType = VariantArrayType.Scalar;
const value = (typeof dv === "function") ? dv() : dv;
// if (dataType === DataType.ByteString ) { value = Buffer.alloc(0) }
/*
* * n > 1 : the Value is an array with the specified number of dimensions.
* * OneDimension (1): The value is an array with one dimension.
public setState(toStateNode: string | State | null): void {
if (!toStateNode) {
this.currentStateNode = null;
this.currentState.setValueFromSource({ dataType: DataType.Null }, StatusCodes.BadStateNotActive);
return;
}
if (_.isString(toStateNode)) {
const state = this.getStateByName(toStateNode);
// istanbul ignore next
if (!state) {
throw new Error("Cannot find state with name " + toStateNode);
}
assert(state.browseName.name!.toString() === toStateNode);
toStateNode = state;
}
const fromStateNode = this.currentStateNode;
toStateNode = this._coerceNode(toStateNode) as any as State;
assert(toStateNode.nodeClass === NodeClass.Object);
public _onInputDataValueChange(dataValue: DataValue): void {
assert(dataValue instanceof DataValue);
if (dataValue.statusCode === StatusCodes.BadWaitingForInitialData
&& dataValue.statusCode === StatusCodes.UncertainInitialValue) {
// we are not ready yet to use the input node value
return;
}
if (dataValue.statusCode !== StatusCodes.Good) {
// what shall we do ?
this._signalNewCondition(null);
return;
}
if (dataValue.value.dataType === DataType.Null) {
// what shall we do ?
this._signalNewCondition(null);
return;
}
const value = dataValue.value.value;
this._setStateBasedOnInputValue(value);
}
return d;
},
timestamped_set: function (dataValue, callback) {
callback(null, StatusCodes.BadNotWritable);
}
}, true);
}
const components = self.getComponents();
// ------------------------------------------------------
// make sure we have a structure
// ------------------------------------------------------
const s = self.readValue();
if (s.value && s.value.dataType === DataType.Null) {
// create a structure and bind it
extensionObject_ = self.$extensionObject || addressSpace.constructExtensionObject(self.dataType);
extensionObject_ = new Proxy(extensionObject_, makeHandler(self));
self.$extensionObject = extensionObject_;
const theValue = new Variant({
dataType: DataType.ExtensionObject,
value: self.$extensionObject
});
self.setValueFromSource(theValue, StatusCodes.Good);
self.bindVariable({
timestamped_get: function () {
self._dataValue.value.value = self.$extensionObject;
const d = new DataValue(self._dataValue);
function getDataValue_EncodingByte(dataValue: DataValue): DataValueEncodingByte {
let encodingMask = 0;
if (dataValue.value && dataValue.value.dataType !== DataType.Null) {
encodingMask |= DataValueEncodingByte.Value;
}
// if (dataValue.statusCode !== null ) {
if (_.isObject(dataValue.statusCode) && dataValue.statusCode.value !== 0) {
encodingMask |= DataValueEncodingByte.StatusCode;
}
if (dataValue.sourceTimestamp && (dataValue.sourceTimestamp as any) !== "null") {
encodingMask |= DataValueEncodingByte.SourceTimestamp;
}
// the number of picoseconds that can be encoded are
// 100 nano * 10000;
// above this the value contains the excess in pico second to make the sourceTimestamp more accurate
if (dataValue.sourcePicoseconds ? dataValue.sourcePicoseconds % 100000 : false) {
encodingMask |= DataValueEncodingByte.SourcePicoseconds;
}
if (dataValue.serverTimestamp && (dataValue.serverTimestamp as any) !== "null") {
UALimitAlarm.prototype._onInputDataValueChange = function (dataValue) {
assert(dataValue instanceof DataValue);
const alarm = this;
if (dataValue.statusCode === StatusCodes.BadWaitingForInitialData) {
// we are not ready yet to use the input node value
return;
}
if (dataValue.statusCode !== StatusCodes.Good) {
// what shall we do ?
alarm._signalNewCondition(null);
return;
}
if (dataValue.value.dataType === DataType.Null) {
// what shall we do ?
alarm._signalNewCondition(null);
return;
}
const value = dataValue.value.value;
alarm._setStateBasedOnInputValue(value);
};
return function (oldData, callback) {
callback(null, new DataValue({
statusCode: StatusCodes.BadNodeIdUnknown,
value: {dataType: DataType.Null, value: 0}
}));
};
}