node-opcua-data-value
Advanced tools
Comparing version
@@ -28,2 +28,9 @@ import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream"; | ||
serverPicoseconds: UInt16; | ||
/** | ||
* | ||
* @class DataValue | ||
* @constructor | ||
* @extends BaseUAObject | ||
* @param options {Object} | ||
*/ | ||
constructor(options?: DataValueOptions); | ||
@@ -39,2 +46,8 @@ encode(stream: OutputBinaryStream): void; | ||
export declare function apply_timestamps(dataValue: DataValue, timestampsToReturn: TimestampsToReturn, attributeId: AttributeIds): DataValue; | ||
/** | ||
* return a deep copy of the dataValue by applying indexRange if necessary on Array/Matrix | ||
* @param dataValue {DataValue} | ||
* @param indexRange {NumericalRange} | ||
* @return {DataValue} | ||
*/ | ||
export declare function extractRange(dataValue: DataValue, indexRange: NumericalRange): DataValue; | ||
@@ -45,2 +58,9 @@ export declare function sourceTimestampHasChanged(dataValue1: DataValue, dataValue2: DataValue): boolean; | ||
export declare function sameStatusCode(statusCode1: StatusCode, statusCode2: StatusCode): boolean; | ||
/** | ||
* @method sameDataValue | ||
* @param v1 {DataValue} | ||
* @param v2 {DataValue} | ||
* @param [timestampsToReturn {TimestampsToReturn}] | ||
* @return {boolean} true if data values are identical | ||
*/ | ||
export declare function sameDataValue(v1: DataValue, v2: DataValue, timestampsToReturn?: TimestampsToReturn): boolean; | ||
@@ -47,0 +67,0 @@ export interface DataValueT<T, DT extends DataType> extends DataValue { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.sameDataValue = exports.sameStatusCode = exports.timestampHasChanged = exports.serverTimestampHasChanged = exports.sourceTimestampHasChanged = exports.extractRange = exports.apply_timestamps = exports.DataValue = exports.decodeDataValue = exports.encodeDataValue = void 0; | ||
/** | ||
* @module node-opcua-data-value | ||
*/ | ||
const node_opcua_assert_1 = require("node-opcua-assert"); | ||
@@ -14,2 +17,3 @@ const node_opcua_date_time_1 = require("node-opcua-date-time"); | ||
const node_opcua_data_model_1 = require("node-opcua-data-model"); | ||
// tslint:disable:no-bitwise | ||
function getDataValue_EncodingByte(dataValue) { | ||
@@ -20,2 +24,3 @@ let encodingMask = 0; | ||
} | ||
// if (dataValue.statusCode !== null ) { | ||
if (_.isObject(dataValue.statusCode) && dataValue.statusCode.value !== 0) { | ||
@@ -27,2 +32,5 @@ encodingMask |= DataValueEncodingByte_enum_1.DataValueEncodingByte.StatusCode; | ||
} | ||
// 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) { | ||
@@ -42,3 +50,5 @@ encodingMask |= DataValueEncodingByte_enum_1.DataValueEncodingByte.SourcePicoseconds; | ||
node_opcua_assert_1.assert(_.isFinite(encodingMask) && encodingMask >= 0 && encodingMask <= 0x3F); | ||
// write encoding byte | ||
node_opcua_basic_types_1.encodeUInt8(encodingMask, stream); | ||
// write value as Variant | ||
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.Value) { | ||
@@ -49,2 +59,3 @@ if (!dataValue.value) { | ||
if (!dataValue.value.encode) { | ||
// tslint:disable-next-line:no-console | ||
console.log(" CANNOT FIND ENCODE METHOD ON VARIANT !!! HELP", JSON.stringify(dataValue, null, " ")); | ||
@@ -54,8 +65,11 @@ } | ||
} | ||
// write statusCode | ||
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.StatusCode) { | ||
node_opcua_basic_types_1.encodeStatusCode(dataValue.statusCode, stream); | ||
} | ||
// write sourceTimestamp | ||
if ((encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.SourceTimestamp) && (dataValue.sourceTimestamp !== null)) { | ||
node_opcua_basic_types_1.encodeHighAccuracyDateTime(dataValue.sourceTimestamp, dataValue.sourcePicoseconds, stream); | ||
} | ||
// write sourcePicoseconds | ||
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.SourcePicoseconds) { | ||
@@ -66,8 +80,10 @@ node_opcua_assert_1.assert(dataValue.sourcePicoseconds !== null); | ||
} | ||
// write serverTimestamp | ||
if ((encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.ServerTimestamp) && dataValue.serverTimestamp !== null) { | ||
node_opcua_basic_types_1.encodeHighAccuracyDateTime(dataValue.serverTimestamp, dataValue.serverPicoseconds, stream); | ||
} | ||
// write serverPicoseconds | ||
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.ServerPicoseconds) { | ||
node_opcua_assert_1.assert(dataValue.serverPicoseconds !== null); | ||
const serverPicoseconds = Math.floor((dataValue.serverPicoseconds % 100000) / 10); | ||
const serverPicoseconds = Math.floor((dataValue.serverPicoseconds % 100000) / 10); // we encode 10-pios | ||
node_opcua_basic_types_1.encodeUInt16(serverPicoseconds, stream); | ||
@@ -88,2 +104,3 @@ } | ||
} | ||
// read statusCode | ||
cur = stream.length; | ||
@@ -94,2 +111,3 @@ if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.StatusCode) { | ||
} | ||
// read sourceTimestamp | ||
cur = stream.length; | ||
@@ -101,2 +119,3 @@ if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.SourceTimestamp) { | ||
} | ||
// read sourcePicoseconds | ||
cur = stream.length; | ||
@@ -109,2 +128,3 @@ dataValue.sourcePicoseconds = 0; | ||
} | ||
// read serverTimestamp | ||
cur = stream.length; | ||
@@ -117,2 +137,3 @@ dataValue.serverPicoseconds = 0; | ||
} | ||
// read serverPicoseconds | ||
cur = stream.length; | ||
@@ -131,2 +152,3 @@ if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.ServerPicoseconds) { | ||
} | ||
// read statusCode | ||
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.StatusCode) { | ||
@@ -139,2 +161,3 @@ dataValue.statusCode = node_opcua_basic_types_1.decodeStatusCode(stream); | ||
dataValue.sourcePicoseconds = 0; | ||
// read sourceTimestamp | ||
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.SourceTimestamp) { | ||
@@ -144,5 +167,7 @@ dataValue.sourceTimestamp = node_opcua_basic_types_1.decodeHighAccuracyDateTime(stream); | ||
} | ||
// read sourcePicoseconds | ||
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.SourcePicoseconds) { | ||
dataValue.sourcePicoseconds += node_opcua_basic_types_1.decodeUInt16(stream) * 10; | ||
} | ||
// read serverTimestamp | ||
dataValue.serverPicoseconds = 0; | ||
@@ -153,2 +178,3 @@ if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.ServerTimestamp) { | ||
} | ||
// read serverPicoseconds | ||
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.ServerPicoseconds) { | ||
@@ -171,2 +197,3 @@ dataValue.serverPicoseconds += node_opcua_basic_types_1.decodeUInt16(stream) * 10; | ||
node_opcua_assert_1.assert(!self.value); | ||
// in this case StatusCode shall not be Good | ||
node_opcua_assert_1.assert(self.statusCode !== node_opcua_status_code_1.StatusCodes.Good); | ||
@@ -176,2 +203,3 @@ } | ||
} | ||
// OPC-UA part 4 - $7.7 | ||
const schemaDataValue = node_opcua_factory_1.buildStructuredType({ | ||
@@ -189,4 +217,11 @@ baseType: "BaseUAObject", | ||
}); | ||
let DataValue = (() => { | ||
let DataValue = /** @class */ (() => { | ||
class DataValue extends node_opcua_factory_1.BaseUAObject { | ||
/** | ||
* | ||
* @class DataValue | ||
* @constructor | ||
* @extends BaseUAObject | ||
* @param options {Object} | ||
*/ | ||
constructor(options) { | ||
@@ -196,2 +231,3 @@ super(); | ||
options = options || {}; | ||
/* istanbul ignore next */ | ||
if (node_opcua_factory_1.parameters.debugSchemaHelper) { | ||
@@ -203,2 +239,7 @@ node_opcua_factory_1.check_options_correctness_against_schema(this, schema, options); | ||
} | ||
/** | ||
* @property value | ||
* @type {Variant} | ||
* @default null | ||
*/ | ||
if (options.value === undefined || options.value === null) { | ||
@@ -210,6 +251,31 @@ this.value = new node_opcua_variant_1.Variant({ dataType: node_opcua_variant_1.DataType.Null }); | ||
} | ||
/** | ||
* @property statusCode | ||
* @type {StatusCode} | ||
* @default Good (0x00000) | ||
*/ | ||
this.statusCode = node_opcua_factory_1.initialize_field(schema.fields[1], options.statusCode); | ||
/** | ||
* @property sourceTimestamp | ||
* @type {DateTime} | ||
* @default null | ||
*/ | ||
this.sourceTimestamp = node_opcua_factory_1.initialize_field(schema.fields[2], options.sourceTimestamp); | ||
/** | ||
* @property sourcePicoseconds | ||
* @type {UInt16} | ||
* @default 0 | ||
*/ | ||
this.sourcePicoseconds = node_opcua_factory_1.initialize_field(schema.fields[3], options.sourcePicoseconds); | ||
/** | ||
* @property serverTimestamp | ||
* @type {DateTime} | ||
* @default null | ||
*/ | ||
this.serverTimestamp = node_opcua_factory_1.initialize_field(schema.fields[4], options.serverTimestamp); | ||
/** | ||
* @property serverPicoseconds | ||
* @type {UInt16} | ||
* @default 0 | ||
*/ | ||
this.serverPicoseconds = node_opcua_factory_1.initialize_field(schema.fields[5], options.serverPicoseconds); | ||
@@ -237,2 +303,3 @@ } | ||
+ w((picoseconds % 1000) >> 0); | ||
// + " (" + picoseconds+ ")"; | ||
} | ||
@@ -242,7 +309,7 @@ function d(timestamp, picoseconds) { | ||
+ " $ " + toMicroNanoPico(picoseconds) | ||
: "null"); | ||
: "null"); // + " " + (this.serverTimestamp ? this.serverTimestamp.getTime() :"-"); | ||
} | ||
let str = "{ /* DataValue */"; | ||
if (this.value) { | ||
str += "\n" + " value: " + node_opcua_variant_1.Variant.prototype.toString.apply(this.value); | ||
str += "\n" + " value: " + node_opcua_variant_1.Variant.prototype.toString.apply(this.value); // this.value.toString(); | ||
} | ||
@@ -298,2 +365,3 @@ else { | ||
let now = null; | ||
// apply timestamps | ||
switch (timestampsToReturn) { | ||
@@ -307,5 +375,7 @@ case TimestampsToReturn_enum_1.TimestampsToReturn.Neither: | ||
cloneDataValue.serverPicoseconds = dataValue.serverPicoseconds; | ||
// xx if (!cloneDataValue.serverTimestamp) { | ||
now = now || node_opcua_date_time_1.getCurrentClock(); | ||
cloneDataValue.serverTimestamp = now.timestamp; | ||
cloneDataValue.serverPicoseconds = now.picoseconds; | ||
// xx } | ||
break; | ||
@@ -323,5 +393,7 @@ case TimestampsToReturn_enum_1.TimestampsToReturn.Source: | ||
cloneDataValue.serverPicoseconds = dataValue.serverPicoseconds; | ||
//xx if (!cloneDataValue.serverTimestamp) { | ||
now = now || node_opcua_date_time_1.getCurrentClock(); | ||
cloneDataValue.serverTimestamp = now.timestamp; | ||
cloneDataValue.serverPicoseconds = now.picoseconds; | ||
//xx } | ||
cloneDataValue.sourceTimestamp = dataValue.sourceTimestamp; | ||
@@ -331,2 +403,3 @@ cloneDataValue.sourcePicoseconds = dataValue.sourcePicoseconds; | ||
} | ||
// unset sourceTimestamp unless AttributeId is Value | ||
if (attributeId !== node_opcua_data_model_1.AttributeIds.Value) { | ||
@@ -346,2 +419,3 @@ cloneDataValue.sourceTimestamp = null; | ||
const now = node_opcua_date_time_1.getCurrentClock(); | ||
// apply timestamps | ||
switch (timestampsToReturn) { | ||
@@ -367,2 +441,3 @@ case TimestampsToReturn_enum_1.TimestampsToReturn.Server: | ||
} | ||
// unset sourceTimestamp unless AttributeId is Value | ||
if (attributeId !== node_opcua_data_model_1.AttributeIds.Value) { | ||
@@ -373,2 +448,10 @@ cloneDataValue.sourceTimestamp = null; | ||
} | ||
/* | ||
* @method _clone_with_array_replacement | ||
* @param dataValue | ||
* @param result | ||
* @return {DataValue} | ||
* @private | ||
* @static | ||
*/ | ||
function _clone_with_array_replacement(dataValue, result) { | ||
@@ -398,2 +481,8 @@ const statusCode = result.statusCode === node_opcua_status_code_1.StatusCodes.Good ? dataValue.statusCode : result.statusCode; | ||
} | ||
/** | ||
* return a deep copy of the dataValue by applying indexRange if necessary on Array/Matrix | ||
* @param dataValue {DataValue} | ||
* @param indexRange {NumericalRange} | ||
* @return {DataValue} | ||
*/ | ||
function extractRange(dataValue, indexRange) { | ||
@@ -405,2 +494,3 @@ const variant = dataValue.value; | ||
} | ||
// let's extract an array of elements corresponding to the indexRange | ||
const result = indexRange.extract_values(variant.value, variant.dimensions); | ||
@@ -410,2 +500,3 @@ dataValue = _clone_with_array_replacement(dataValue, result); | ||
else { | ||
// clone the whole data Value | ||
dataValue = dataValue.clone(); | ||
@@ -442,4 +533,5 @@ } | ||
function timestampHasChanged(dataValue1, dataValue2, timestampsToReturn) { | ||
// TODO: timestampsToReturn = timestampsToReturn || { key: "Neither"}; | ||
if (timestampsToReturn === undefined) { | ||
return sourceTimestampHasChanged(dataValue1, dataValue2); | ||
return sourceTimestampHasChanged(dataValue1, dataValue2); // || serverTimestampHasChanged(dataValue1, dataValue2); | ||
} | ||
@@ -464,2 +556,9 @@ switch (timestampsToReturn) { | ||
exports.sameStatusCode = sameStatusCode; | ||
/** | ||
* @method sameDataValue | ||
* @param v1 {DataValue} | ||
* @param v2 {DataValue} | ||
* @param [timestampsToReturn {TimestampsToReturn}] | ||
* @return {boolean} true if data values are identical | ||
*/ | ||
function sameDataValue(v1, v2, timestampsToReturn) { | ||
@@ -478,2 +577,15 @@ if (v1 === v2) { | ||
} | ||
/* | ||
// | ||
// For performance reason, sourceTimestamp is | ||
// used to determine if a dataValue has changed. | ||
// if sourceTimestamp and sourcePicoseconds are identical | ||
// then we make the assumption that Variant value is identical too. | ||
// This will prevent us to deep compare potential large arrays. | ||
// but before this is possible, we need to implement a mechanism | ||
// that ensure that date() is always strictly increasing | ||
if ((v1.sourceTimestamp && v2.sourceTimestamp) && !sourceTimestampHasChanged(v1, v2)) { | ||
return true; | ||
} | ||
*/ | ||
if (timestampHasChanged(v1, v2, timestampsToReturn)) { | ||
@@ -480,0 +592,0 @@ return false; |
@@ -0,1 +1,4 @@ | ||
/** | ||
* @module node-opcua-data-value | ||
*/ | ||
import { Enum } from "node-opcua-enum"; | ||
@@ -2,0 +5,0 @@ export declare enum DataValueEncodingByte { |
@@ -0,2 +1,5 @@ | ||
/** | ||
* @module node-opcua-data-value | ||
*/ | ||
export * from "./datavalue"; | ||
export * from "./TimestampsToReturn_enum"; |
@@ -13,4 +13,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* @module node-opcua-data-value | ||
*/ | ||
__exportStar(require("./datavalue"), exports); | ||
__exportStar(require("./TimestampsToReturn_enum"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -0,1 +1,4 @@ | ||
/** | ||
* @module node-opcua-data-value | ||
*/ | ||
import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream"; | ||
@@ -2,0 +5,0 @@ export declare enum TimestampsToReturn { |
@@ -5,3 +5,3 @@ { | ||
"types": "./dist/index.d.ts", | ||
"version": "2.6.0-alpha.7", | ||
"version": "2.6.1", | ||
"description": "pure nodejs OPCUA SDK - module -data-value", | ||
@@ -14,20 +14,20 @@ "scripts": { | ||
"dependencies": { | ||
"node-opcua-assert": "^2.6.0-alpha.1", | ||
"node-opcua-basic-types": "^2.6.0-alpha.1", | ||
"node-opcua-binary-stream": "^2.6.0-alpha.1", | ||
"node-opcua-data-model": "^2.6.0-alpha.7", | ||
"node-opcua-date-time": "^2.6.0-alpha.1", | ||
"node-opcua-enum": "^2.6.0-alpha.1", | ||
"node-opcua-extension-object": "^2.6.0-alpha.7", | ||
"node-opcua-factory": "^2.6.0-alpha.7", | ||
"node-opcua-nodeid": "^2.6.0-alpha.1", | ||
"node-opcua-status-code": "^2.6.0-alpha.1", | ||
"node-opcua-utils": "^2.6.0-alpha.1", | ||
"node-opcua-variant": "^2.6.0-alpha.7", | ||
"node-opcua-assert": "^2.6.1", | ||
"node-opcua-basic-types": "^2.6.1", | ||
"node-opcua-binary-stream": "^2.6.1", | ||
"node-opcua-data-model": "^2.6.1", | ||
"node-opcua-date-time": "^2.6.1", | ||
"node-opcua-enum": "^2.6.1", | ||
"node-opcua-extension-object": "^2.6.1", | ||
"node-opcua-factory": "^2.6.1", | ||
"node-opcua-nodeid": "^2.6.1", | ||
"node-opcua-status-code": "^2.6.1", | ||
"node-opcua-utils": "^2.6.1", | ||
"node-opcua-variant": "^2.6.1", | ||
"underscore": "^1.10.2" | ||
}, | ||
"devDependencies": { | ||
"node-opcua-generator": "^2.6.0-alpha.7", | ||
"node-opcua-numeric-range": "^2.6.0-alpha.7", | ||
"node-opcua-packet-analyzer": "^2.6.0-alpha.7", | ||
"node-opcua-generator": "^2.6.1", | ||
"node-opcua-numeric-range": "^2.6.1", | ||
"node-opcua-packet-analyzer": "^2.6.1", | ||
"should": "^13.2.3" | ||
@@ -50,3 +50,3 @@ }, | ||
"homepage": "http://node-opcua.github.io/", | ||
"gitHead": "6af0c6f183dcb96ddc5a2befc98851d0960c5fd0" | ||
"gitHead": "15f0c0f83232fc63310dc04fea187048c7a01e4b" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
80931
6.8%1377
11.68%0
-100%Updated
Updated
Updated
Updated
Updated
Updated
Updated
Updated