Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public touchValue(optionalNow?: PreciseClock): void {
const variable = this;
const now = optionalNow || getCurrentClock();
variable._dataValue.sourceTimestamp = now.timestamp;
variable._dataValue.sourcePicoseconds = now.picoseconds;
variable._dataValue.serverTimestamp = now.timestamp;
variable._dataValue.serverPicoseconds = now.picoseconds;
variable._dataValue.statusCode = StatusCodes.Good;
if (variable.minimumSamplingInterval === 0) {
// xx console.log("xxx touchValue = ",variable.browseName.toString(),variable._dataValue.value.value);
if (variable.listenerCount("value_changed") > 0) {
const clonedDataValue = variable.readValue();
variable.emit("value_changed", clonedDataValue);
}
}
if (variable.parent && variable.parent.nodeClass === NodeClass.Variable) {
(variable.parent as UAVariable).touchValue(now);
assert(dataValue.hasOwnProperty("serverTimestamp"));
assert(dataValue.hasOwnProperty("sourceTimestamp"));
let cloneDataValue = null;
let now = null;
// apply timestamps
switch (timestampsToReturn) {
case TimestampsToReturn.Neither:
cloneDataValue = cloneDataValue || _partial_clone(dataValue);
break;
case TimestampsToReturn.Server:
cloneDataValue = cloneDataValue || _partial_clone(dataValue);
cloneDataValue.serverTimestamp = dataValue.serverTimestamp;
cloneDataValue.serverPicoseconds = dataValue.serverPicoseconds;
if (!cloneDataValue.serverTimestamp) {
now = now || getCurrentClock();
cloneDataValue.serverTimestamp = now.timestamp as DateTime;
cloneDataValue.serverPicoseconds = now.picoseconds;
}
break;
case TimestampsToReturn.Source:
cloneDataValue = cloneDataValue || _partial_clone(dataValue);
cloneDataValue.sourceTimestamp = dataValue.sourceTimestamp;
cloneDataValue.sourcePicoseconds = dataValue.sourcePicoseconds;
break;
default:
assert(timestampsToReturn === TimestampsToReturn.Both);
cloneDataValue = cloneDataValue || _partial_clone(dataValue);
cloneDataValue.serverTimestamp = dataValue.serverTimestamp;
cloneDataValue.serverPicoseconds = dataValue.serverPicoseconds;
if (!cloneDataValue.serverTimestamp) {
now = now || getCurrentClock();
function apply_timestamps2(
dataValue: DataValue,
timestampsToReturn: TimestampsToReturn,
attributeId: AttributeIds
): DataValue {
assert(attributeId > 0);
assert(dataValue.hasOwnProperty("serverTimestamp"));
assert(dataValue.hasOwnProperty("sourceTimestamp"));
const cloneDataValue = new DataValue({});
cloneDataValue.value = dataValue.value;
cloneDataValue.statusCode = dataValue.statusCode;
const now = getCurrentClock();
// apply timestamps
switch (timestampsToReturn) {
case TimestampsToReturn.Server:
cloneDataValue.serverTimestamp = dataValue.serverTimestamp;
cloneDataValue.serverPicoseconds = dataValue.serverPicoseconds;
cloneDataValue.serverTimestamp = now.timestamp as DateTime;
cloneDataValue.serverPicoseconds = now.picoseconds;
break;
case TimestampsToReturn.Source:
cloneDataValue.sourceTimestamp = dataValue.sourceTimestamp;
cloneDataValue.sourcePicoseconds = dataValue.sourcePicoseconds;
break;
case TimestampsToReturn.Both:
cloneDataValue.serverTimestamp = dataValue.serverTimestamp;
cloneDataValue.serverPicoseconds = dataValue.serverPicoseconds;
cloneDataValue.serverTimestamp = now.timestamp as DateTime;
UAVariable.prototype.writeValue = function (context, dataValue, indexRange, callback) {
const self = this;
if (!context) {
context = SessionContext.defaultContext;
}
if (!dataValue.sourceTimestamp) {
if (context.currentTime) {
dataValue.sourceTimestamp = context.currentTime;
dataValue.sourcePicoseconds = 0;
} else {
const clock = getCurrentClock();
dataValue.sourceTimestamp = clock.timestamp;
dataValue.sourcePicoseconds = clock.picoseconds;
}
}
if (context.currentTime && !dataValue.serverTimestamp) {
dataValue.serverTimestamp = context.currentTime;
dataValue.serverPicoseconds = 0;
}
assert(context instanceof SessionContext);
// adjust arguments if optional indexRange Parameter is not given
if (!_.isFunction(callback) && _.isFunction(indexRange)) {
callback = indexRange;
indexRange = new NumericRange();
function apply_timestamps2(dataValue, timestampsToReturn, attributeId) {
assert(attributeId > 0);
assert(timestampsToReturn.hasOwnProperty("key"));
assert(dataValue instanceof DataValue);
assert(dataValue.hasOwnProperty("serverTimestamp"));
assert(dataValue.hasOwnProperty("sourceTimestamp"));
const cloneDataValue = new DataValue({});
cloneDataValue.value = dataValue.value;
cloneDataValue.statusCode = dataValue.statusCode;
const now = getCurrentClock();
// apply timestamps
switch (timestampsToReturn) {
case TimestampsToReturn.Server:
cloneDataValue.serverTimestamp = dataValue.serverTimestamp;
cloneDataValue.serverPicoseconds = dataValue.serverPicoseconds;
//xxif (true || !cloneDataValue.serverTimestamp) {
cloneDataValue.serverTimestamp = now.timestamp;
cloneDataValue.serverPicoseconds = now.picoseconds;
//xx}
break;
case TimestampsToReturn.Source:
cloneDataValue.sourceTimestamp = dataValue.sourceTimestamp;
cloneDataValue.sourcePicoseconds = dataValue.sourcePicoseconds;
break;
case TimestampsToReturn.Both:
cloneDataValue.serverTimestamp = dataValue.serverTimestamp;
UAVariable.prototype.touchValue = function (optionalNow) {
const variable = this;
const now = optionalNow || getCurrentClock();
variable._dataValue.sourceTimestamp = now.timestamp;
variable._dataValue.sourcePicoseconds = now.picoseconds;
variable._dataValue.serverTimestamp = now.timestamp;
variable._dataValue.serverPicoseconds = now.picoseconds;
variable._dataValue.statusCode = StatusCodes.Good;
if (variable.minimumSamplingInterval === 0) {
//xx console.log("xxx touchValue = ",variable.browseName.toString(),variable._dataValue.value.value);
if (variable.listenerCount("value_changed") > 0) {
const clonedDataValue = variable.readValue();
variable.emit("value_changed", clonedDataValue);
}
}
if (variable.parent && variable.parent.nodeClass == NodeClass.Variable) {
variable.parent.touchValue(now);
function _apply_default_timestamps(dataValue: DataValue): void {
const now = getCurrentClock();
assert(dataValue instanceof DataValue);
if (!dataValue.sourceTimestamp) {
dataValue.sourceTimestamp = now.timestamp;
dataValue.sourcePicoseconds = now.picoseconds;
}
if (!dataValue.serverTimestamp) {
dataValue.serverTimestamp = now.timestamp;
dataValue.serverPicoseconds = now.picoseconds;
}
}
public readAttribute(context: SessionContext, attributeId: AttributeIds): DataValue {
const now = getCurrentClock();
const options: DataValueLike = {};
switch (attributeId) {
case AttributeIds.EventNotifier:
assert(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);
}
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);
};
function _apply_default_timestamps(dataValue) {
const now = getCurrentClock();
assert(dataValue instanceof DataValue);
if (!dataValue.sourceTimestamp) {
dataValue.sourceTimestamp = now.timestamp;
dataValue.sourcePicoseconds = now.picoseconds;
}
if (!dataValue.serverTimestamp) {
dataValue.serverTimestamp = now.timestamp;
dataValue.serverPicoseconds = now.picoseconds;
}
}