node-opcua-data-value 2.71.0 → 2.72.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/DataValueEncodingByte_enum.d.ts +17 -17
- package/dist/DataValueEncodingByte_enum.js +18 -18
- package/dist/TimestampsToReturn_enum.d.ts +19 -19
- package/dist/TimestampsToReturn_enum.js +32 -32
- package/dist/datavalue.d.ts +74 -74
- package/dist/datavalue.js +558 -558
- package/dist/index.d.ts +5 -5
- package/dist/index.js +21 -21
- package/package.json +9 -9
package/dist/datavalue.js
CHANGED
|
@@ -1,559 +1,559 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DataValueT = exports.sameDataValue = exports.sameStatusCode = exports.timestampHasChanged = exports.serverTimestampHasChanged = exports.sourceTimestampHasChanged = exports.extractRange = exports.apply_timestamps_no_copy = exports.apply_timestamps = exports.DataValue = exports.decodeDataValue = exports.encodeDataValue = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* @module node-opcua-data-value
|
|
6
|
-
*/
|
|
7
|
-
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
8
|
-
const node_opcua_date_time_1 = require("node-opcua-date-time");
|
|
9
|
-
const node_opcua_factory_1 = require("node-opcua-factory");
|
|
10
|
-
const node_opcua_status_code_1 = require("node-opcua-status-code");
|
|
11
|
-
const node_opcua_variant_1 = require("node-opcua-variant");
|
|
12
|
-
const node_opcua_basic_types_1 = require("node-opcua-basic-types");
|
|
13
|
-
const node_opcua_data_model_1 = require("node-opcua-data-model");
|
|
14
|
-
const DataValueEncodingByte_enum_1 = require("./DataValueEncodingByte_enum");
|
|
15
|
-
const TimestampsToReturn_enum_1 = require("./TimestampsToReturn_enum");
|
|
16
|
-
// tslint:disable:no-bitwise
|
|
17
|
-
function getDataValue_EncodingByte(dataValue) {
|
|
18
|
-
let encodingMask = 0;
|
|
19
|
-
if (dataValue.value && dataValue.value.dataType !== node_opcua_variant_1.DataType.Null) {
|
|
20
|
-
encodingMask |= DataValueEncodingByte_enum_1.DataValueEncodingByte.Value;
|
|
21
|
-
}
|
|
22
|
-
// if (dataValue.statusCode !== null ) {
|
|
23
|
-
if (dataValue.statusCode !== null && typeof dataValue.statusCode === "object" && dataValue.statusCode.value !== 0) {
|
|
24
|
-
encodingMask |= DataValueEncodingByte_enum_1.DataValueEncodingByte.StatusCode;
|
|
25
|
-
}
|
|
26
|
-
if (dataValue.sourceTimestamp && dataValue.sourceTimestamp !== "null") {
|
|
27
|
-
encodingMask |= DataValueEncodingByte_enum_1.DataValueEncodingByte.SourceTimestamp;
|
|
28
|
-
}
|
|
29
|
-
// the number of picoseconds that can be encoded are
|
|
30
|
-
// 100 nano * 10000;
|
|
31
|
-
// above this the value contains the excess in pico second to make the sourceTimestamp more accurate
|
|
32
|
-
if (dataValue.sourcePicoseconds ? dataValue.sourcePicoseconds % 100000 : false) {
|
|
33
|
-
encodingMask |= DataValueEncodingByte_enum_1.DataValueEncodingByte.SourcePicoseconds;
|
|
34
|
-
}
|
|
35
|
-
if (dataValue.serverTimestamp && dataValue.serverTimestamp !== "null") {
|
|
36
|
-
encodingMask |= DataValueEncodingByte_enum_1.DataValueEncodingByte.ServerTimestamp;
|
|
37
|
-
}
|
|
38
|
-
if (dataValue.serverPicoseconds ? dataValue.serverPicoseconds % 100000 : false) {
|
|
39
|
-
encodingMask |= DataValueEncodingByte_enum_1.DataValueEncodingByte.ServerPicoseconds;
|
|
40
|
-
}
|
|
41
|
-
return encodingMask;
|
|
42
|
-
}
|
|
43
|
-
function encodeDataValue(dataValue, stream) {
|
|
44
|
-
const encodingMask = getDataValue_EncodingByte(dataValue);
|
|
45
|
-
(0, node_opcua_assert_1.assert)(isFinite(encodingMask) && encodingMask >= 0 && encodingMask <= 0x3f);
|
|
46
|
-
// write encoding byte
|
|
47
|
-
(0, node_opcua_basic_types_1.encodeUInt8)(encodingMask, stream);
|
|
48
|
-
// write value as Variant
|
|
49
|
-
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.Value) {
|
|
50
|
-
if (!dataValue.value) {
|
|
51
|
-
dataValue.value = new node_opcua_variant_1.Variant();
|
|
52
|
-
}
|
|
53
|
-
// istanbul ignore next
|
|
54
|
-
if (!dataValue.value.encode) {
|
|
55
|
-
// tslint:disable-next-line:no-console
|
|
56
|
-
console.log(" CANNOT FIND ENCODE METHOD ON VARIANT !!! HELP", JSON.stringify(dataValue, null, " "));
|
|
57
|
-
}
|
|
58
|
-
dataValue.value.encode(stream);
|
|
59
|
-
}
|
|
60
|
-
// write statusCode
|
|
61
|
-
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.StatusCode) {
|
|
62
|
-
(0, node_opcua_basic_types_1.encodeStatusCode)(dataValue.statusCode, stream);
|
|
63
|
-
}
|
|
64
|
-
// write sourceTimestamp
|
|
65
|
-
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.SourceTimestamp && dataValue.sourceTimestamp !== null) {
|
|
66
|
-
(0, node_opcua_basic_types_1.encodeHighAccuracyDateTime)(dataValue.sourceTimestamp, dataValue.sourcePicoseconds, stream);
|
|
67
|
-
}
|
|
68
|
-
// write sourcePicoseconds
|
|
69
|
-
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.SourcePicoseconds) {
|
|
70
|
-
(0, node_opcua_assert_1.assert)(dataValue.sourcePicoseconds !== null);
|
|
71
|
-
const sourcePicoseconds = Math.floor((dataValue.sourcePicoseconds % 100000) / 10);
|
|
72
|
-
(0, node_opcua_basic_types_1.encodeUInt16)(sourcePicoseconds, stream);
|
|
73
|
-
}
|
|
74
|
-
// write serverTimestamp
|
|
75
|
-
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.ServerTimestamp && dataValue.serverTimestamp !== null) {
|
|
76
|
-
(0, node_opcua_basic_types_1.encodeHighAccuracyDateTime)(dataValue.serverTimestamp, dataValue.serverPicoseconds, stream);
|
|
77
|
-
}
|
|
78
|
-
// write serverPicoseconds
|
|
79
|
-
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.ServerPicoseconds) {
|
|
80
|
-
(0, node_opcua_assert_1.assert)(dataValue.serverPicoseconds !== null);
|
|
81
|
-
const serverPicoseconds = Math.floor((dataValue.serverPicoseconds % 100000) / 10); // we encode 10-picoseconds
|
|
82
|
-
(0, node_opcua_basic_types_1.encodeUInt16)(serverPicoseconds, stream);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
exports.encodeDataValue = encodeDataValue;
|
|
86
|
-
function decodeDebugDataValue(dataValue, stream, options) {
|
|
87
|
-
const tracer = options.tracer;
|
|
88
|
-
let cur = stream.length;
|
|
89
|
-
const encodingMask = (0, node_opcua_basic_types_1.decodeUInt8)(stream);
|
|
90
|
-
(0, node_opcua_assert_1.assert)(encodingMask <= 0x3f);
|
|
91
|
-
tracer.trace("member", "encodingByte", "0x" + encodingMask.toString(16), cur, stream.length, "Mask");
|
|
92
|
-
tracer.encoding_byte(encodingMask, DataValueEncodingByte_enum_1.DataValueEncodingByte, cur, stream.length);
|
|
93
|
-
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.Value) {
|
|
94
|
-
dataValue.value = new node_opcua_variant_1.Variant();
|
|
95
|
-
dataValue.value.decodeDebug(stream, options);
|
|
96
|
-
}
|
|
97
|
-
// read statusCode
|
|
98
|
-
cur = stream.length;
|
|
99
|
-
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.StatusCode) {
|
|
100
|
-
dataValue.statusCode = (0, node_opcua_basic_types_1.decodeStatusCode)(stream);
|
|
101
|
-
tracer.trace("member", "statusCode", dataValue.statusCode, cur, stream.length, "StatusCode");
|
|
102
|
-
}
|
|
103
|
-
// read sourceTimestamp
|
|
104
|
-
cur = stream.length;
|
|
105
|
-
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.SourceTimestamp) {
|
|
106
|
-
dataValue.sourceTimestamp = (0, node_opcua_basic_types_1.decodeHighAccuracyDateTime)(stream);
|
|
107
|
-
dataValue.sourcePicoseconds = dataValue.sourceTimestamp.picoseconds;
|
|
108
|
-
tracer.trace("member", "sourceTimestamp", dataValue.sourceTimestamp, cur, stream.length, "DateTime");
|
|
109
|
-
}
|
|
110
|
-
// read sourcePicoseconds
|
|
111
|
-
cur = stream.length;
|
|
112
|
-
dataValue.sourcePicoseconds = 0;
|
|
113
|
-
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.SourcePicoseconds) {
|
|
114
|
-
const tenPico = (0, node_opcua_basic_types_1.decodeUInt16)(stream);
|
|
115
|
-
dataValue.sourcePicoseconds += tenPico * 10;
|
|
116
|
-
tracer.trace("member", "sourcePicoseconds", dataValue.sourcePicoseconds, cur, stream.length, "UInt16");
|
|
117
|
-
}
|
|
118
|
-
// read serverTimestamp
|
|
119
|
-
cur = stream.length;
|
|
120
|
-
dataValue.serverPicoseconds = 0;
|
|
121
|
-
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.ServerTimestamp) {
|
|
122
|
-
dataValue.serverTimestamp = (0, node_opcua_basic_types_1.decodeHighAccuracyDateTime)(stream);
|
|
123
|
-
dataValue.serverPicoseconds = dataValue.serverTimestamp.picoseconds | 0;
|
|
124
|
-
tracer.trace("member", "serverTimestamp", dataValue.serverTimestamp, cur, stream.length, "DateTime");
|
|
125
|
-
}
|
|
126
|
-
// read serverPicoseconds
|
|
127
|
-
cur = stream.length;
|
|
128
|
-
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.ServerPicoseconds) {
|
|
129
|
-
const tenPico = (0, node_opcua_basic_types_1.decodeUInt16)(stream);
|
|
130
|
-
dataValue.serverPicoseconds += tenPico * 10;
|
|
131
|
-
tracer.trace("member", "serverPicoseconds", dataValue.serverPicoseconds, cur, stream.length, "UInt16");
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
function decodeDataValueInternal(dataValue, stream) {
|
|
135
|
-
const encodingMask = (0, node_opcua_basic_types_1.decodeUInt8)(stream);
|
|
136
|
-
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.Value) {
|
|
137
|
-
dataValue.value = new node_opcua_variant_1.Variant();
|
|
138
|
-
dataValue.value.decode(stream);
|
|
139
|
-
}
|
|
140
|
-
// read statusCode
|
|
141
|
-
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.StatusCode) {
|
|
142
|
-
dataValue.statusCode = (0, node_opcua_basic_types_1.decodeStatusCode)(stream);
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
dataValue.statusCode = node_opcua_status_code_1.StatusCodes.Good;
|
|
146
|
-
}
|
|
147
|
-
dataValue.sourcePicoseconds = 0;
|
|
148
|
-
// read sourceTimestamp
|
|
149
|
-
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.SourceTimestamp) {
|
|
150
|
-
dataValue.sourceTimestamp = (0, node_opcua_basic_types_1.decodeHighAccuracyDateTime)(stream);
|
|
151
|
-
dataValue.sourcePicoseconds += dataValue.sourceTimestamp.picoseconds | 0;
|
|
152
|
-
}
|
|
153
|
-
// read sourcePicoseconds
|
|
154
|
-
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.SourcePicoseconds) {
|
|
155
|
-
dataValue.sourcePicoseconds += (0, node_opcua_basic_types_1.decodeUInt16)(stream) * 10;
|
|
156
|
-
}
|
|
157
|
-
// read serverTimestamp
|
|
158
|
-
dataValue.serverPicoseconds = 0;
|
|
159
|
-
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.ServerTimestamp) {
|
|
160
|
-
dataValue.serverTimestamp = (0, node_opcua_basic_types_1.decodeHighAccuracyDateTime)(stream);
|
|
161
|
-
dataValue.serverPicoseconds += dataValue.serverTimestamp.picoseconds | 0;
|
|
162
|
-
}
|
|
163
|
-
// read serverPicoseconds
|
|
164
|
-
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.ServerPicoseconds) {
|
|
165
|
-
dataValue.serverPicoseconds += (0, node_opcua_basic_types_1.decodeUInt16)(stream) * 10;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
function decodeDataValue(stream, dataValue) {
|
|
169
|
-
dataValue = dataValue || new DataValue();
|
|
170
|
-
decodeDataValueInternal(dataValue, stream);
|
|
171
|
-
return dataValue;
|
|
172
|
-
}
|
|
173
|
-
exports.decodeDataValue = decodeDataValue;
|
|
174
|
-
function isValidDataValue(self) {
|
|
175
|
-
if (self.value !== null && typeof self.value === "object") {
|
|
176
|
-
(0, node_opcua_assert_1.assert)(self.value);
|
|
177
|
-
return self.value.isValid();
|
|
178
|
-
}
|
|
179
|
-
else {
|
|
180
|
-
(0, node_opcua_assert_1.assert)(!self.value);
|
|
181
|
-
// in this case StatusCode shall not be Good
|
|
182
|
-
(0, node_opcua_assert_1.assert)(self.statusCode !== node_opcua_status_code_1.StatusCodes.Good);
|
|
183
|
-
}
|
|
184
|
-
return true;
|
|
185
|
-
}
|
|
186
|
-
// OPC-UA part 4 - $7.7
|
|
187
|
-
const schemaDataValue = (0, node_opcua_factory_1.buildStructuredType)({
|
|
188
|
-
baseType: "BaseUAObject",
|
|
189
|
-
name: "DataValue",
|
|
190
|
-
fields: [
|
|
191
|
-
{ name: "value", fieldType: "Variant", defaultValue: null },
|
|
192
|
-
{ name: "statusCode", fieldType: "StatusCode", defaultValue: node_opcua_status_code_1.StatusCodes.Good },
|
|
193
|
-
{ name: "sourceTimestamp", fieldType: "DateTime", defaultValue: null },
|
|
194
|
-
{ name: "sourcePicoseconds", fieldType: "UInt16", defaultValue: 0 },
|
|
195
|
-
{ name: "serverTimestamp", fieldType: "DateTime", defaultValue: null },
|
|
196
|
-
{ name: "serverPicoseconds", fieldType: "UInt16", defaultValue: 0 }
|
|
197
|
-
]
|
|
198
|
-
});
|
|
199
|
-
function toMicroNanoPico(picoseconds) {
|
|
200
|
-
return "" + w((picoseconds / 1000000) >> 0) + "." + w(((picoseconds % 1000000) / 1000) >> 0) + "." + w(picoseconds % 1000 >> 0);
|
|
201
|
-
// + " (" + picoseconds+ ")";
|
|
202
|
-
}
|
|
203
|
-
function d(timestamp, picoseconds) {
|
|
204
|
-
return timestamp ? timestamp.toISOString() + " $ " + toMicroNanoPico(picoseconds) : "null"; // + " " + (this.serverTimestamp ? this.serverTimestamp.getTime() :"-");
|
|
205
|
-
}
|
|
206
|
-
const emptyObject = {};
|
|
207
|
-
const defaultDate = node_opcua_date_time_1.minOPCUADate;
|
|
208
|
-
class DataValue extends node_opcua_factory_1.BaseUAObject {
|
|
209
|
-
/**
|
|
210
|
-
*
|
|
211
|
-
* @class DataValue
|
|
212
|
-
* @constructor
|
|
213
|
-
* @extends BaseUAObject
|
|
214
|
-
* @param options {Object}
|
|
215
|
-
*/
|
|
216
|
-
constructor(options) {
|
|
217
|
-
super();
|
|
218
|
-
if (options === null) {
|
|
219
|
-
this.statusCode = node_opcua_status_code_1.StatusCodes.Bad;
|
|
220
|
-
this.sourceTimestamp = null;
|
|
221
|
-
this.sourcePicoseconds = 0;
|
|
222
|
-
this.serverTimestamp = null;
|
|
223
|
-
this.serverPicoseconds = 0;
|
|
224
|
-
this.value = new node_opcua_variant_1.Variant(null);
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
options = options || emptyObject;
|
|
228
|
-
/* istanbul ignore next */
|
|
229
|
-
if (node_opcua_factory_1.parameters.debugSchemaHelper) {
|
|
230
|
-
const schema = schemaDataValue;
|
|
231
|
-
(0, node_opcua_factory_1.check_options_correctness_against_schema)(this, schema, options);
|
|
232
|
-
}
|
|
233
|
-
if (options.value === undefined || options.value === null) {
|
|
234
|
-
this.value = new node_opcua_variant_1.Variant({ dataType: node_opcua_variant_1.DataType.Null });
|
|
235
|
-
}
|
|
236
|
-
else {
|
|
237
|
-
this.value = options.value ? new node_opcua_variant_1.Variant(options.value) : new node_opcua_variant_1.Variant({ dataType: node_opcua_variant_1.DataType.Null });
|
|
238
|
-
}
|
|
239
|
-
this.statusCode = (0, node_opcua_status_code_1.coerceStatusCode)(options.statusCode || node_opcua_status_code_1.StatusCodes.Good);
|
|
240
|
-
this.sourceTimestamp = options.sourceTimestamp ? (0, node_opcua_date_time_1.coerceDateTime)(options.sourceTimestamp) : null;
|
|
241
|
-
this.sourcePicoseconds = options.sourcePicoseconds || 0;
|
|
242
|
-
this.serverTimestamp = options.serverTimestamp ? (0, node_opcua_date_time_1.coerceDateTime)(options.serverTimestamp) : null;
|
|
243
|
-
this.serverPicoseconds = options.serverPicoseconds || 0;
|
|
244
|
-
}
|
|
245
|
-
encode(stream) {
|
|
246
|
-
encodeDataValue(this, stream);
|
|
247
|
-
}
|
|
248
|
-
decode(stream) {
|
|
249
|
-
decodeDataValueInternal(this, stream);
|
|
250
|
-
}
|
|
251
|
-
decodeDebug(stream, options) {
|
|
252
|
-
decodeDebugDataValue(this, stream, options);
|
|
253
|
-
}
|
|
254
|
-
isValid() {
|
|
255
|
-
return isValidDataValue(this);
|
|
256
|
-
}
|
|
257
|
-
toString() {
|
|
258
|
-
let str = "{ /* DataValue */";
|
|
259
|
-
if (this.value) {
|
|
260
|
-
str += "\n" + " value: " + node_opcua_variant_1.Variant.prototype.toString.apply(this.value); // this.value.toString();
|
|
261
|
-
}
|
|
262
|
-
else {
|
|
263
|
-
str += "\n" + " value: <null>";
|
|
264
|
-
}
|
|
265
|
-
str += "\n" + " statusCode: " + (this.statusCode ? this.statusCode.toString() : "null");
|
|
266
|
-
str += "\n" + " serverTimestamp: " + d(this.serverTimestamp, this.serverPicoseconds);
|
|
267
|
-
str += "\n" + " sourceTimestamp: " + d(this.sourceTimestamp, this.sourcePicoseconds);
|
|
268
|
-
str += "\n" + "}";
|
|
269
|
-
return str;
|
|
270
|
-
}
|
|
271
|
-
clone() {
|
|
272
|
-
return new DataValue({
|
|
273
|
-
serverPicoseconds: this.serverPicoseconds,
|
|
274
|
-
serverTimestamp: this.serverTimestamp,
|
|
275
|
-
sourcePicoseconds: this.sourcePicoseconds,
|
|
276
|
-
sourceTimestamp: this.sourceTimestamp,
|
|
277
|
-
statusCode: this.statusCode,
|
|
278
|
-
value: this.value ? this.value.clone() : undefined
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
exports.DataValue = DataValue;
|
|
283
|
-
DataValue.possibleFields = [
|
|
284
|
-
"value",
|
|
285
|
-
"statusCode",
|
|
286
|
-
"sourceTimestamp",
|
|
287
|
-
"sourcePicoseconds",
|
|
288
|
-
"serverTimestamp",
|
|
289
|
-
"serverPicoseconds"
|
|
290
|
-
];
|
|
291
|
-
DataValue.schema = schemaDataValue;
|
|
292
|
-
DataValue.prototype.schema = DataValue.schema;
|
|
293
|
-
(0, node_opcua_factory_1.registerSpecialVariantEncoder)(DataValue);
|
|
294
|
-
function w(n) {
|
|
295
|
-
return n.toString().padStart(3, "0");
|
|
296
|
-
}
|
|
297
|
-
function _partial_clone(dataValue) {
|
|
298
|
-
const cloneDataValue = new DataValue({ value: undefined });
|
|
299
|
-
cloneDataValue.value = dataValue.value;
|
|
300
|
-
cloneDataValue.statusCode = dataValue.statusCode;
|
|
301
|
-
return cloneDataValue;
|
|
302
|
-
}
|
|
303
|
-
function apply_timestamps(dataValue, timestampsToReturn, attributeId) {
|
|
304
|
-
let cloneDataValue = null;
|
|
305
|
-
let now = null;
|
|
306
|
-
// apply timestamps
|
|
307
|
-
switch (timestampsToReturn) {
|
|
308
|
-
case TimestampsToReturn_enum_1.TimestampsToReturn.Neither:
|
|
309
|
-
cloneDataValue = cloneDataValue || _partial_clone(dataValue);
|
|
310
|
-
break;
|
|
311
|
-
case TimestampsToReturn_enum_1.TimestampsToReturn.Server:
|
|
312
|
-
cloneDataValue = cloneDataValue || _partial_clone(dataValue);
|
|
313
|
-
cloneDataValue.serverTimestamp = dataValue.serverTimestamp;
|
|
314
|
-
cloneDataValue.serverPicoseconds = dataValue.serverPicoseconds;
|
|
315
|
-
// xx if (!cloneDataValue.serverTimestamp) {
|
|
316
|
-
now = now || (0, node_opcua_date_time_1.getCurrentClock)();
|
|
317
|
-
cloneDataValue.serverTimestamp = now.timestamp;
|
|
318
|
-
cloneDataValue.serverPicoseconds = now.picoseconds;
|
|
319
|
-
// xx }
|
|
320
|
-
break;
|
|
321
|
-
case TimestampsToReturn_enum_1.TimestampsToReturn.Source:
|
|
322
|
-
cloneDataValue = cloneDataValue || _partial_clone(dataValue);
|
|
323
|
-
cloneDataValue.sourceTimestamp = dataValue.sourceTimestamp;
|
|
324
|
-
cloneDataValue.sourcePicoseconds = dataValue.sourcePicoseconds;
|
|
325
|
-
break;
|
|
326
|
-
case TimestampsToReturn_enum_1.TimestampsToReturn.Both:
|
|
327
|
-
default:
|
|
328
|
-
(0, node_opcua_assert_1.assert)(timestampsToReturn === TimestampsToReturn_enum_1.TimestampsToReturn.Both);
|
|
329
|
-
cloneDataValue = cloneDataValue || _partial_clone(dataValue);
|
|
330
|
-
cloneDataValue.serverTimestamp = dataValue.serverTimestamp;
|
|
331
|
-
cloneDataValue.serverPicoseconds = dataValue.serverPicoseconds;
|
|
332
|
-
// xx if (!cloneDataValue.serverTimestamp) {
|
|
333
|
-
now = now || (0, node_opcua_date_time_1.getCurrentClock)();
|
|
334
|
-
cloneDataValue.serverTimestamp = now.timestamp;
|
|
335
|
-
cloneDataValue.serverPicoseconds = now.picoseconds;
|
|
336
|
-
// xx }
|
|
337
|
-
cloneDataValue.sourceTimestamp = dataValue.sourceTimestamp;
|
|
338
|
-
cloneDataValue.sourcePicoseconds = dataValue.sourcePicoseconds;
|
|
339
|
-
break;
|
|
340
|
-
}
|
|
341
|
-
// unset sourceTimestamp unless AttributeId is Value
|
|
342
|
-
if (attributeId !== node_opcua_data_model_1.AttributeIds.Value) {
|
|
343
|
-
cloneDataValue.sourceTimestamp = null;
|
|
344
|
-
}
|
|
345
|
-
return cloneDataValue;
|
|
346
|
-
}
|
|
347
|
-
exports.apply_timestamps = apply_timestamps;
|
|
348
|
-
function apply_timestamps_no_copy(dataValue, timestampsToReturn, attributeId, now) {
|
|
349
|
-
switch (timestampsToReturn) {
|
|
350
|
-
case TimestampsToReturn_enum_1.TimestampsToReturn.Neither:
|
|
351
|
-
dataValue.sourceTimestamp = null;
|
|
352
|
-
dataValue.sourcePicoseconds = 0;
|
|
353
|
-
dataValue.serverTimestamp = null;
|
|
354
|
-
dataValue.serverPicoseconds = 0;
|
|
355
|
-
break;
|
|
356
|
-
case TimestampsToReturn_enum_1.TimestampsToReturn.Server:
|
|
357
|
-
now = now || (0, node_opcua_date_time_1.getCurrentClock)();
|
|
358
|
-
dataValue.serverTimestamp = now.timestamp;
|
|
359
|
-
dataValue.serverPicoseconds = now.picoseconds;
|
|
360
|
-
dataValue.sourceTimestamp = null;
|
|
361
|
-
dataValue.sourcePicoseconds = 0;
|
|
362
|
-
break;
|
|
363
|
-
case TimestampsToReturn_enum_1.TimestampsToReturn.Source:
|
|
364
|
-
break;
|
|
365
|
-
case TimestampsToReturn_enum_1.TimestampsToReturn.Both:
|
|
366
|
-
default:
|
|
367
|
-
(0, node_opcua_assert_1.assert)(timestampsToReturn === TimestampsToReturn_enum_1.TimestampsToReturn.Both);
|
|
368
|
-
now = now || (0, node_opcua_date_time_1.getCurrentClock)();
|
|
369
|
-
dataValue.serverTimestamp = now.timestamp;
|
|
370
|
-
dataValue.serverPicoseconds = now.picoseconds;
|
|
371
|
-
break;
|
|
372
|
-
}
|
|
373
|
-
// unset sourceTimestamp unless AttributeId is Value
|
|
374
|
-
if (attributeId !== node_opcua_data_model_1.AttributeIds.Value) {
|
|
375
|
-
dataValue.sourceTimestamp = null;
|
|
376
|
-
}
|
|
377
|
-
return dataValue;
|
|
378
|
-
}
|
|
379
|
-
exports.apply_timestamps_no_copy = apply_timestamps_no_copy;
|
|
380
|
-
function apply_timestamps2(dataValue, timestampsToReturn, attributeId) {
|
|
381
|
-
(0, node_opcua_assert_1.assert)(attributeId > 0);
|
|
382
|
-
(0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(dataValue, "serverTimestamp"));
|
|
383
|
-
(0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(dataValue, "sourceTimestamp"));
|
|
384
|
-
const cloneDataValue = new DataValue({});
|
|
385
|
-
cloneDataValue.value = dataValue.value;
|
|
386
|
-
cloneDataValue.statusCode = dataValue.statusCode;
|
|
387
|
-
const now = (0, node_opcua_date_time_1.getCurrentClock)();
|
|
388
|
-
// apply timestamps
|
|
389
|
-
switch (timestampsToReturn) {
|
|
390
|
-
case TimestampsToReturn_enum_1.TimestampsToReturn.Server:
|
|
391
|
-
cloneDataValue.serverTimestamp = dataValue.serverTimestamp;
|
|
392
|
-
cloneDataValue.serverPicoseconds = dataValue.serverPicoseconds;
|
|
393
|
-
cloneDataValue.serverTimestamp = now.timestamp;
|
|
394
|
-
cloneDataValue.serverPicoseconds = now.picoseconds;
|
|
395
|
-
break;
|
|
396
|
-
case TimestampsToReturn_enum_1.TimestampsToReturn.Source:
|
|
397
|
-
cloneDataValue.sourceTimestamp = dataValue.sourceTimestamp;
|
|
398
|
-
cloneDataValue.sourcePicoseconds = dataValue.sourcePicoseconds;
|
|
399
|
-
break;
|
|
400
|
-
case TimestampsToReturn_enum_1.TimestampsToReturn.Both:
|
|
401
|
-
cloneDataValue.serverTimestamp = dataValue.serverTimestamp;
|
|
402
|
-
cloneDataValue.serverPicoseconds = dataValue.serverPicoseconds;
|
|
403
|
-
cloneDataValue.serverTimestamp = now.timestamp;
|
|
404
|
-
cloneDataValue.serverPicoseconds = now.picoseconds;
|
|
405
|
-
cloneDataValue.sourceTimestamp = dataValue.sourceTimestamp;
|
|
406
|
-
cloneDataValue.sourcePicoseconds = dataValue.sourcePicoseconds;
|
|
407
|
-
break;
|
|
408
|
-
}
|
|
409
|
-
// unset sourceTimestamp unless AttributeId is Value
|
|
410
|
-
if (attributeId !== node_opcua_data_model_1.AttributeIds.Value) {
|
|
411
|
-
cloneDataValue.sourceTimestamp = null;
|
|
412
|
-
}
|
|
413
|
-
return cloneDataValue;
|
|
414
|
-
}
|
|
415
|
-
/*
|
|
416
|
-
* @method _clone_with_array_replacement
|
|
417
|
-
* @param dataValue
|
|
418
|
-
* @param result
|
|
419
|
-
* @return {DataValue}
|
|
420
|
-
* @private
|
|
421
|
-
* @static
|
|
422
|
-
*/
|
|
423
|
-
function _clone_with_array_replacement(dataValue, result) {
|
|
424
|
-
const statusCode = result.statusCode === node_opcua_status_code_1.StatusCodes.Good ? dataValue.statusCode : result.statusCode;
|
|
425
|
-
const clonedDataValue = new DataValue({
|
|
426
|
-
statusCode,
|
|
427
|
-
serverTimestamp: dataValue.serverTimestamp,
|
|
428
|
-
serverPicoseconds: dataValue.serverPicoseconds,
|
|
429
|
-
sourceTimestamp: dataValue.sourceTimestamp,
|
|
430
|
-
sourcePicoseconds: dataValue.sourcePicoseconds,
|
|
431
|
-
value: {
|
|
432
|
-
dataType: node_opcua_variant_1.DataType.Null
|
|
433
|
-
}
|
|
434
|
-
});
|
|
435
|
-
clonedDataValue.value.dataType = dataValue.value.dataType;
|
|
436
|
-
clonedDataValue.value.arrayType = dataValue.value.arrayType;
|
|
437
|
-
clonedDataValue.value.dimensions = result.dimensions;
|
|
438
|
-
clonedDataValue.value.value = result.array;
|
|
439
|
-
return clonedDataValue;
|
|
440
|
-
}
|
|
441
|
-
function canRange(dataValue) {
|
|
442
|
-
return (dataValue.value &&
|
|
443
|
-
(dataValue.value.arrayType !== node_opcua_variant_1.VariantArrayType.Scalar ||
|
|
444
|
-
(dataValue.value.arrayType === node_opcua_variant_1.VariantArrayType.Scalar && dataValue.value.dataType === node_opcua_variant_1.DataType.ByteString) ||
|
|
445
|
-
(dataValue.value.arrayType === node_opcua_variant_1.VariantArrayType.Scalar && dataValue.value.dataType === node_opcua_variant_1.DataType.String)));
|
|
446
|
-
}
|
|
447
|
-
/**
|
|
448
|
-
* return a deep copy of the dataValue by applying indexRange if necessary on Array/Matrix
|
|
449
|
-
* @param dataValue {DataValue}
|
|
450
|
-
* @param indexRange {NumericalRange}
|
|
451
|
-
* @return {DataValue}
|
|
452
|
-
*/
|
|
453
|
-
function extractRange(dataValue, indexRange) {
|
|
454
|
-
const variant = dataValue.value;
|
|
455
|
-
if (indexRange && canRange(dataValue)) {
|
|
456
|
-
if (!indexRange.isValid()) {
|
|
457
|
-
return new DataValue({ statusCode: node_opcua_status_code_1.StatusCodes.BadIndexRangeInvalid });
|
|
458
|
-
}
|
|
459
|
-
// let's extract an array of elements corresponding to the indexRange
|
|
460
|
-
const result = indexRange.extract_values(variant.value, variant.dimensions);
|
|
461
|
-
dataValue = _clone_with_array_replacement(dataValue, result);
|
|
462
|
-
}
|
|
463
|
-
else {
|
|
464
|
-
// clone the whole data Value
|
|
465
|
-
dataValue = dataValue.clone();
|
|
466
|
-
}
|
|
467
|
-
return dataValue;
|
|
468
|
-
}
|
|
469
|
-
exports.extractRange = extractRange;
|
|
470
|
-
function sameDate(date1, date2) {
|
|
471
|
-
if (date1 === date2) {
|
|
472
|
-
return true;
|
|
473
|
-
}
|
|
474
|
-
if (date1 && date2 === null) {
|
|
475
|
-
return false;
|
|
476
|
-
}
|
|
477
|
-
if (date1 === null && date2) {
|
|
478
|
-
return false;
|
|
479
|
-
}
|
|
480
|
-
if (date1 === null || date2 === null) {
|
|
481
|
-
return false;
|
|
482
|
-
}
|
|
483
|
-
return date1.getTime() === date2.getTime();
|
|
484
|
-
}
|
|
485
|
-
function sourceTimestampHasChanged(dataValue1, dataValue2) {
|
|
486
|
-
return (!sameDate(dataValue1.sourceTimestamp, dataValue2.sourceTimestamp) ||
|
|
487
|
-
dataValue1.sourcePicoseconds !== dataValue2.sourcePicoseconds);
|
|
488
|
-
}
|
|
489
|
-
exports.sourceTimestampHasChanged = sourceTimestampHasChanged;
|
|
490
|
-
function serverTimestampHasChanged(dataValue1, dataValue2) {
|
|
491
|
-
return (!sameDate(dataValue1.serverTimestamp, dataValue2.serverTimestamp) ||
|
|
492
|
-
dataValue1.serverPicoseconds !== dataValue2.serverPicoseconds);
|
|
493
|
-
}
|
|
494
|
-
exports.serverTimestampHasChanged = serverTimestampHasChanged;
|
|
495
|
-
function timestampHasChanged(dataValue1, dataValue2, timestampsToReturn) {
|
|
496
|
-
// TODO: timestampsToReturn = timestampsToReturn || { key: "Neither"};
|
|
497
|
-
if (timestampsToReturn === undefined) {
|
|
498
|
-
return sourceTimestampHasChanged(dataValue1, dataValue2); // || serverTimestampHasChanged(dataValue1, dataValue2);
|
|
499
|
-
}
|
|
500
|
-
switch (timestampsToReturn) {
|
|
501
|
-
case TimestampsToReturn_enum_1.TimestampsToReturn.Neither:
|
|
502
|
-
return false;
|
|
503
|
-
case TimestampsToReturn_enum_1.TimestampsToReturn.Both:
|
|
504
|
-
return sourceTimestampHasChanged(dataValue1, dataValue2) || serverTimestampHasChanged(dataValue1, dataValue2);
|
|
505
|
-
case TimestampsToReturn_enum_1.TimestampsToReturn.Source:
|
|
506
|
-
return sourceTimestampHasChanged(dataValue1, dataValue2);
|
|
507
|
-
default:
|
|
508
|
-
(0, node_opcua_assert_1.assert)(timestampsToReturn === TimestampsToReturn_enum_1.TimestampsToReturn.Server);
|
|
509
|
-
return serverTimestampHasChanged(dataValue1, dataValue2);
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
exports.timestampHasChanged = timestampHasChanged;
|
|
513
|
-
function sameStatusCode(statusCode1, statusCode2) {
|
|
514
|
-
return statusCode1.value === statusCode2.value;
|
|
515
|
-
}
|
|
516
|
-
exports.sameStatusCode = sameStatusCode;
|
|
517
|
-
/**
|
|
518
|
-
* @method sameDataValue
|
|
519
|
-
* @param v1 {DataValue}
|
|
520
|
-
* @param v2 {DataValue}
|
|
521
|
-
* @param [timestampsToReturn {TimestampsToReturn}]
|
|
522
|
-
* @return {boolean} true if data values are identical
|
|
523
|
-
*/
|
|
524
|
-
function sameDataValue(v1, v2, timestampsToReturn) {
|
|
525
|
-
if (v1 === v2) {
|
|
526
|
-
return true;
|
|
527
|
-
}
|
|
528
|
-
if (v1 && !v2) {
|
|
529
|
-
return false;
|
|
530
|
-
}
|
|
531
|
-
if (v2 && !v1) {
|
|
532
|
-
return false;
|
|
533
|
-
}
|
|
534
|
-
if (!sameStatusCode(v1.statusCode, v2.statusCode)) {
|
|
535
|
-
return false;
|
|
536
|
-
}
|
|
537
|
-
/*
|
|
538
|
-
//
|
|
539
|
-
// For performance reason, sourceTimestamp is
|
|
540
|
-
// used to determine if a dataValue has changed.
|
|
541
|
-
// if sourceTimestamp and sourcePicoseconds are identical
|
|
542
|
-
// then we make the assumption that Variant value is identical too.
|
|
543
|
-
// This will prevent us to deep compare potential large arrays.
|
|
544
|
-
// but before this is possible, we need to implement a mechanism
|
|
545
|
-
// that ensure that date() is always strictly increasing
|
|
546
|
-
if ((v1.sourceTimestamp && v2.sourceTimestamp) && !sourceTimestampHasChanged(v1, v2)) {
|
|
547
|
-
return true;
|
|
548
|
-
}
|
|
549
|
-
*/
|
|
550
|
-
if (timestampHasChanged(v1, v2, timestampsToReturn)) {
|
|
551
|
-
return false;
|
|
552
|
-
}
|
|
553
|
-
return (0, node_opcua_variant_1.sameVariant)(v1.value, v2.value);
|
|
554
|
-
}
|
|
555
|
-
exports.sameDataValue = sameDataValue;
|
|
556
|
-
class DataValueT extends DataValue {
|
|
557
|
-
}
|
|
558
|
-
exports.DataValueT = DataValueT;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataValueT = exports.sameDataValue = exports.sameStatusCode = exports.timestampHasChanged = exports.serverTimestampHasChanged = exports.sourceTimestampHasChanged = exports.extractRange = exports.apply_timestamps_no_copy = exports.apply_timestamps = exports.DataValue = exports.decodeDataValue = exports.encodeDataValue = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module node-opcua-data-value
|
|
6
|
+
*/
|
|
7
|
+
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
8
|
+
const node_opcua_date_time_1 = require("node-opcua-date-time");
|
|
9
|
+
const node_opcua_factory_1 = require("node-opcua-factory");
|
|
10
|
+
const node_opcua_status_code_1 = require("node-opcua-status-code");
|
|
11
|
+
const node_opcua_variant_1 = require("node-opcua-variant");
|
|
12
|
+
const node_opcua_basic_types_1 = require("node-opcua-basic-types");
|
|
13
|
+
const node_opcua_data_model_1 = require("node-opcua-data-model");
|
|
14
|
+
const DataValueEncodingByte_enum_1 = require("./DataValueEncodingByte_enum");
|
|
15
|
+
const TimestampsToReturn_enum_1 = require("./TimestampsToReturn_enum");
|
|
16
|
+
// tslint:disable:no-bitwise
|
|
17
|
+
function getDataValue_EncodingByte(dataValue) {
|
|
18
|
+
let encodingMask = 0;
|
|
19
|
+
if (dataValue.value && dataValue.value.dataType !== node_opcua_variant_1.DataType.Null) {
|
|
20
|
+
encodingMask |= DataValueEncodingByte_enum_1.DataValueEncodingByte.Value;
|
|
21
|
+
}
|
|
22
|
+
// if (dataValue.statusCode !== null ) {
|
|
23
|
+
if (dataValue.statusCode !== null && typeof dataValue.statusCode === "object" && dataValue.statusCode.value !== 0) {
|
|
24
|
+
encodingMask |= DataValueEncodingByte_enum_1.DataValueEncodingByte.StatusCode;
|
|
25
|
+
}
|
|
26
|
+
if (dataValue.sourceTimestamp && dataValue.sourceTimestamp !== "null") {
|
|
27
|
+
encodingMask |= DataValueEncodingByte_enum_1.DataValueEncodingByte.SourceTimestamp;
|
|
28
|
+
}
|
|
29
|
+
// the number of picoseconds that can be encoded are
|
|
30
|
+
// 100 nano * 10000;
|
|
31
|
+
// above this the value contains the excess in pico second to make the sourceTimestamp more accurate
|
|
32
|
+
if (dataValue.sourcePicoseconds ? dataValue.sourcePicoseconds % 100000 : false) {
|
|
33
|
+
encodingMask |= DataValueEncodingByte_enum_1.DataValueEncodingByte.SourcePicoseconds;
|
|
34
|
+
}
|
|
35
|
+
if (dataValue.serverTimestamp && dataValue.serverTimestamp !== "null") {
|
|
36
|
+
encodingMask |= DataValueEncodingByte_enum_1.DataValueEncodingByte.ServerTimestamp;
|
|
37
|
+
}
|
|
38
|
+
if (dataValue.serverPicoseconds ? dataValue.serverPicoseconds % 100000 : false) {
|
|
39
|
+
encodingMask |= DataValueEncodingByte_enum_1.DataValueEncodingByte.ServerPicoseconds;
|
|
40
|
+
}
|
|
41
|
+
return encodingMask;
|
|
42
|
+
}
|
|
43
|
+
function encodeDataValue(dataValue, stream) {
|
|
44
|
+
const encodingMask = getDataValue_EncodingByte(dataValue);
|
|
45
|
+
(0, node_opcua_assert_1.assert)(isFinite(encodingMask) && encodingMask >= 0 && encodingMask <= 0x3f);
|
|
46
|
+
// write encoding byte
|
|
47
|
+
(0, node_opcua_basic_types_1.encodeUInt8)(encodingMask, stream);
|
|
48
|
+
// write value as Variant
|
|
49
|
+
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.Value) {
|
|
50
|
+
if (!dataValue.value) {
|
|
51
|
+
dataValue.value = new node_opcua_variant_1.Variant();
|
|
52
|
+
}
|
|
53
|
+
// istanbul ignore next
|
|
54
|
+
if (!dataValue.value.encode) {
|
|
55
|
+
// tslint:disable-next-line:no-console
|
|
56
|
+
console.log(" CANNOT FIND ENCODE METHOD ON VARIANT !!! HELP", JSON.stringify(dataValue, null, " "));
|
|
57
|
+
}
|
|
58
|
+
dataValue.value.encode(stream);
|
|
59
|
+
}
|
|
60
|
+
// write statusCode
|
|
61
|
+
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.StatusCode) {
|
|
62
|
+
(0, node_opcua_basic_types_1.encodeStatusCode)(dataValue.statusCode, stream);
|
|
63
|
+
}
|
|
64
|
+
// write sourceTimestamp
|
|
65
|
+
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.SourceTimestamp && dataValue.sourceTimestamp !== null) {
|
|
66
|
+
(0, node_opcua_basic_types_1.encodeHighAccuracyDateTime)(dataValue.sourceTimestamp, dataValue.sourcePicoseconds, stream);
|
|
67
|
+
}
|
|
68
|
+
// write sourcePicoseconds
|
|
69
|
+
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.SourcePicoseconds) {
|
|
70
|
+
(0, node_opcua_assert_1.assert)(dataValue.sourcePicoseconds !== null);
|
|
71
|
+
const sourcePicoseconds = Math.floor((dataValue.sourcePicoseconds % 100000) / 10);
|
|
72
|
+
(0, node_opcua_basic_types_1.encodeUInt16)(sourcePicoseconds, stream);
|
|
73
|
+
}
|
|
74
|
+
// write serverTimestamp
|
|
75
|
+
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.ServerTimestamp && dataValue.serverTimestamp !== null) {
|
|
76
|
+
(0, node_opcua_basic_types_1.encodeHighAccuracyDateTime)(dataValue.serverTimestamp, dataValue.serverPicoseconds, stream);
|
|
77
|
+
}
|
|
78
|
+
// write serverPicoseconds
|
|
79
|
+
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.ServerPicoseconds) {
|
|
80
|
+
(0, node_opcua_assert_1.assert)(dataValue.serverPicoseconds !== null);
|
|
81
|
+
const serverPicoseconds = Math.floor((dataValue.serverPicoseconds % 100000) / 10); // we encode 10-picoseconds
|
|
82
|
+
(0, node_opcua_basic_types_1.encodeUInt16)(serverPicoseconds, stream);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.encodeDataValue = encodeDataValue;
|
|
86
|
+
function decodeDebugDataValue(dataValue, stream, options) {
|
|
87
|
+
const tracer = options.tracer;
|
|
88
|
+
let cur = stream.length;
|
|
89
|
+
const encodingMask = (0, node_opcua_basic_types_1.decodeUInt8)(stream);
|
|
90
|
+
(0, node_opcua_assert_1.assert)(encodingMask <= 0x3f);
|
|
91
|
+
tracer.trace("member", "encodingByte", "0x" + encodingMask.toString(16), cur, stream.length, "Mask");
|
|
92
|
+
tracer.encoding_byte(encodingMask, DataValueEncodingByte_enum_1.DataValueEncodingByte, cur, stream.length);
|
|
93
|
+
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.Value) {
|
|
94
|
+
dataValue.value = new node_opcua_variant_1.Variant();
|
|
95
|
+
dataValue.value.decodeDebug(stream, options);
|
|
96
|
+
}
|
|
97
|
+
// read statusCode
|
|
98
|
+
cur = stream.length;
|
|
99
|
+
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.StatusCode) {
|
|
100
|
+
dataValue.statusCode = (0, node_opcua_basic_types_1.decodeStatusCode)(stream);
|
|
101
|
+
tracer.trace("member", "statusCode", dataValue.statusCode, cur, stream.length, "StatusCode");
|
|
102
|
+
}
|
|
103
|
+
// read sourceTimestamp
|
|
104
|
+
cur = stream.length;
|
|
105
|
+
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.SourceTimestamp) {
|
|
106
|
+
dataValue.sourceTimestamp = (0, node_opcua_basic_types_1.decodeHighAccuracyDateTime)(stream);
|
|
107
|
+
dataValue.sourcePicoseconds = dataValue.sourceTimestamp.picoseconds;
|
|
108
|
+
tracer.trace("member", "sourceTimestamp", dataValue.sourceTimestamp, cur, stream.length, "DateTime");
|
|
109
|
+
}
|
|
110
|
+
// read sourcePicoseconds
|
|
111
|
+
cur = stream.length;
|
|
112
|
+
dataValue.sourcePicoseconds = 0;
|
|
113
|
+
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.SourcePicoseconds) {
|
|
114
|
+
const tenPico = (0, node_opcua_basic_types_1.decodeUInt16)(stream);
|
|
115
|
+
dataValue.sourcePicoseconds += tenPico * 10;
|
|
116
|
+
tracer.trace("member", "sourcePicoseconds", dataValue.sourcePicoseconds, cur, stream.length, "UInt16");
|
|
117
|
+
}
|
|
118
|
+
// read serverTimestamp
|
|
119
|
+
cur = stream.length;
|
|
120
|
+
dataValue.serverPicoseconds = 0;
|
|
121
|
+
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.ServerTimestamp) {
|
|
122
|
+
dataValue.serverTimestamp = (0, node_opcua_basic_types_1.decodeHighAccuracyDateTime)(stream);
|
|
123
|
+
dataValue.serverPicoseconds = dataValue.serverTimestamp.picoseconds | 0;
|
|
124
|
+
tracer.trace("member", "serverTimestamp", dataValue.serverTimestamp, cur, stream.length, "DateTime");
|
|
125
|
+
}
|
|
126
|
+
// read serverPicoseconds
|
|
127
|
+
cur = stream.length;
|
|
128
|
+
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.ServerPicoseconds) {
|
|
129
|
+
const tenPico = (0, node_opcua_basic_types_1.decodeUInt16)(stream);
|
|
130
|
+
dataValue.serverPicoseconds += tenPico * 10;
|
|
131
|
+
tracer.trace("member", "serverPicoseconds", dataValue.serverPicoseconds, cur, stream.length, "UInt16");
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function decodeDataValueInternal(dataValue, stream) {
|
|
135
|
+
const encodingMask = (0, node_opcua_basic_types_1.decodeUInt8)(stream);
|
|
136
|
+
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.Value) {
|
|
137
|
+
dataValue.value = new node_opcua_variant_1.Variant();
|
|
138
|
+
dataValue.value.decode(stream);
|
|
139
|
+
}
|
|
140
|
+
// read statusCode
|
|
141
|
+
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.StatusCode) {
|
|
142
|
+
dataValue.statusCode = (0, node_opcua_basic_types_1.decodeStatusCode)(stream);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
dataValue.statusCode = node_opcua_status_code_1.StatusCodes.Good;
|
|
146
|
+
}
|
|
147
|
+
dataValue.sourcePicoseconds = 0;
|
|
148
|
+
// read sourceTimestamp
|
|
149
|
+
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.SourceTimestamp) {
|
|
150
|
+
dataValue.sourceTimestamp = (0, node_opcua_basic_types_1.decodeHighAccuracyDateTime)(stream);
|
|
151
|
+
dataValue.sourcePicoseconds += dataValue.sourceTimestamp.picoseconds | 0;
|
|
152
|
+
}
|
|
153
|
+
// read sourcePicoseconds
|
|
154
|
+
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.SourcePicoseconds) {
|
|
155
|
+
dataValue.sourcePicoseconds += (0, node_opcua_basic_types_1.decodeUInt16)(stream) * 10;
|
|
156
|
+
}
|
|
157
|
+
// read serverTimestamp
|
|
158
|
+
dataValue.serverPicoseconds = 0;
|
|
159
|
+
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.ServerTimestamp) {
|
|
160
|
+
dataValue.serverTimestamp = (0, node_opcua_basic_types_1.decodeHighAccuracyDateTime)(stream);
|
|
161
|
+
dataValue.serverPicoseconds += dataValue.serverTimestamp.picoseconds | 0;
|
|
162
|
+
}
|
|
163
|
+
// read serverPicoseconds
|
|
164
|
+
if (encodingMask & DataValueEncodingByte_enum_1.DataValueEncodingByte.ServerPicoseconds) {
|
|
165
|
+
dataValue.serverPicoseconds += (0, node_opcua_basic_types_1.decodeUInt16)(stream) * 10;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function decodeDataValue(stream, dataValue) {
|
|
169
|
+
dataValue = dataValue || new DataValue();
|
|
170
|
+
decodeDataValueInternal(dataValue, stream);
|
|
171
|
+
return dataValue;
|
|
172
|
+
}
|
|
173
|
+
exports.decodeDataValue = decodeDataValue;
|
|
174
|
+
function isValidDataValue(self) {
|
|
175
|
+
if (self.value !== null && typeof self.value === "object") {
|
|
176
|
+
(0, node_opcua_assert_1.assert)(self.value);
|
|
177
|
+
return self.value.isValid();
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
(0, node_opcua_assert_1.assert)(!self.value);
|
|
181
|
+
// in this case StatusCode shall not be Good
|
|
182
|
+
(0, node_opcua_assert_1.assert)(self.statusCode !== node_opcua_status_code_1.StatusCodes.Good);
|
|
183
|
+
}
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
// OPC-UA part 4 - $7.7
|
|
187
|
+
const schemaDataValue = (0, node_opcua_factory_1.buildStructuredType)({
|
|
188
|
+
baseType: "BaseUAObject",
|
|
189
|
+
name: "DataValue",
|
|
190
|
+
fields: [
|
|
191
|
+
{ name: "value", fieldType: "Variant", defaultValue: null },
|
|
192
|
+
{ name: "statusCode", fieldType: "StatusCode", defaultValue: node_opcua_status_code_1.StatusCodes.Good },
|
|
193
|
+
{ name: "sourceTimestamp", fieldType: "DateTime", defaultValue: null },
|
|
194
|
+
{ name: "sourcePicoseconds", fieldType: "UInt16", defaultValue: 0 },
|
|
195
|
+
{ name: "serverTimestamp", fieldType: "DateTime", defaultValue: null },
|
|
196
|
+
{ name: "serverPicoseconds", fieldType: "UInt16", defaultValue: 0 }
|
|
197
|
+
]
|
|
198
|
+
});
|
|
199
|
+
function toMicroNanoPico(picoseconds) {
|
|
200
|
+
return "" + w((picoseconds / 1000000) >> 0) + "." + w(((picoseconds % 1000000) / 1000) >> 0) + "." + w(picoseconds % 1000 >> 0);
|
|
201
|
+
// + " (" + picoseconds+ ")";
|
|
202
|
+
}
|
|
203
|
+
function d(timestamp, picoseconds) {
|
|
204
|
+
return timestamp ? timestamp.toISOString() + " $ " + toMicroNanoPico(picoseconds) : "null"; // + " " + (this.serverTimestamp ? this.serverTimestamp.getTime() :"-");
|
|
205
|
+
}
|
|
206
|
+
const emptyObject = {};
|
|
207
|
+
const defaultDate = node_opcua_date_time_1.minOPCUADate;
|
|
208
|
+
class DataValue extends node_opcua_factory_1.BaseUAObject {
|
|
209
|
+
/**
|
|
210
|
+
*
|
|
211
|
+
* @class DataValue
|
|
212
|
+
* @constructor
|
|
213
|
+
* @extends BaseUAObject
|
|
214
|
+
* @param options {Object}
|
|
215
|
+
*/
|
|
216
|
+
constructor(options) {
|
|
217
|
+
super();
|
|
218
|
+
if (options === null) {
|
|
219
|
+
this.statusCode = node_opcua_status_code_1.StatusCodes.Bad;
|
|
220
|
+
this.sourceTimestamp = null;
|
|
221
|
+
this.sourcePicoseconds = 0;
|
|
222
|
+
this.serverTimestamp = null;
|
|
223
|
+
this.serverPicoseconds = 0;
|
|
224
|
+
this.value = new node_opcua_variant_1.Variant(null);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
options = options || emptyObject;
|
|
228
|
+
/* istanbul ignore next */
|
|
229
|
+
if (node_opcua_factory_1.parameters.debugSchemaHelper) {
|
|
230
|
+
const schema = schemaDataValue;
|
|
231
|
+
(0, node_opcua_factory_1.check_options_correctness_against_schema)(this, schema, options);
|
|
232
|
+
}
|
|
233
|
+
if (options.value === undefined || options.value === null) {
|
|
234
|
+
this.value = new node_opcua_variant_1.Variant({ dataType: node_opcua_variant_1.DataType.Null });
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
this.value = options.value ? new node_opcua_variant_1.Variant(options.value) : new node_opcua_variant_1.Variant({ dataType: node_opcua_variant_1.DataType.Null });
|
|
238
|
+
}
|
|
239
|
+
this.statusCode = (0, node_opcua_status_code_1.coerceStatusCode)(options.statusCode || node_opcua_status_code_1.StatusCodes.Good);
|
|
240
|
+
this.sourceTimestamp = options.sourceTimestamp ? (0, node_opcua_date_time_1.coerceDateTime)(options.sourceTimestamp) : null;
|
|
241
|
+
this.sourcePicoseconds = options.sourcePicoseconds || 0;
|
|
242
|
+
this.serverTimestamp = options.serverTimestamp ? (0, node_opcua_date_time_1.coerceDateTime)(options.serverTimestamp) : null;
|
|
243
|
+
this.serverPicoseconds = options.serverPicoseconds || 0;
|
|
244
|
+
}
|
|
245
|
+
encode(stream) {
|
|
246
|
+
encodeDataValue(this, stream);
|
|
247
|
+
}
|
|
248
|
+
decode(stream) {
|
|
249
|
+
decodeDataValueInternal(this, stream);
|
|
250
|
+
}
|
|
251
|
+
decodeDebug(stream, options) {
|
|
252
|
+
decodeDebugDataValue(this, stream, options);
|
|
253
|
+
}
|
|
254
|
+
isValid() {
|
|
255
|
+
return isValidDataValue(this);
|
|
256
|
+
}
|
|
257
|
+
toString() {
|
|
258
|
+
let str = "{ /* DataValue */";
|
|
259
|
+
if (this.value) {
|
|
260
|
+
str += "\n" + " value: " + node_opcua_variant_1.Variant.prototype.toString.apply(this.value); // this.value.toString();
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
str += "\n" + " value: <null>";
|
|
264
|
+
}
|
|
265
|
+
str += "\n" + " statusCode: " + (this.statusCode ? this.statusCode.toString() : "null");
|
|
266
|
+
str += "\n" + " serverTimestamp: " + d(this.serverTimestamp, this.serverPicoseconds);
|
|
267
|
+
str += "\n" + " sourceTimestamp: " + d(this.sourceTimestamp, this.sourcePicoseconds);
|
|
268
|
+
str += "\n" + "}";
|
|
269
|
+
return str;
|
|
270
|
+
}
|
|
271
|
+
clone() {
|
|
272
|
+
return new DataValue({
|
|
273
|
+
serverPicoseconds: this.serverPicoseconds,
|
|
274
|
+
serverTimestamp: this.serverTimestamp,
|
|
275
|
+
sourcePicoseconds: this.sourcePicoseconds,
|
|
276
|
+
sourceTimestamp: this.sourceTimestamp,
|
|
277
|
+
statusCode: this.statusCode,
|
|
278
|
+
value: this.value ? this.value.clone() : undefined
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
exports.DataValue = DataValue;
|
|
283
|
+
DataValue.possibleFields = [
|
|
284
|
+
"value",
|
|
285
|
+
"statusCode",
|
|
286
|
+
"sourceTimestamp",
|
|
287
|
+
"sourcePicoseconds",
|
|
288
|
+
"serverTimestamp",
|
|
289
|
+
"serverPicoseconds"
|
|
290
|
+
];
|
|
291
|
+
DataValue.schema = schemaDataValue;
|
|
292
|
+
DataValue.prototype.schema = DataValue.schema;
|
|
293
|
+
(0, node_opcua_factory_1.registerSpecialVariantEncoder)(DataValue);
|
|
294
|
+
function w(n) {
|
|
295
|
+
return n.toString().padStart(3, "0");
|
|
296
|
+
}
|
|
297
|
+
function _partial_clone(dataValue) {
|
|
298
|
+
const cloneDataValue = new DataValue({ value: undefined });
|
|
299
|
+
cloneDataValue.value = dataValue.value;
|
|
300
|
+
cloneDataValue.statusCode = dataValue.statusCode;
|
|
301
|
+
return cloneDataValue;
|
|
302
|
+
}
|
|
303
|
+
function apply_timestamps(dataValue, timestampsToReturn, attributeId) {
|
|
304
|
+
let cloneDataValue = null;
|
|
305
|
+
let now = null;
|
|
306
|
+
// apply timestamps
|
|
307
|
+
switch (timestampsToReturn) {
|
|
308
|
+
case TimestampsToReturn_enum_1.TimestampsToReturn.Neither:
|
|
309
|
+
cloneDataValue = cloneDataValue || _partial_clone(dataValue);
|
|
310
|
+
break;
|
|
311
|
+
case TimestampsToReturn_enum_1.TimestampsToReturn.Server:
|
|
312
|
+
cloneDataValue = cloneDataValue || _partial_clone(dataValue);
|
|
313
|
+
cloneDataValue.serverTimestamp = dataValue.serverTimestamp;
|
|
314
|
+
cloneDataValue.serverPicoseconds = dataValue.serverPicoseconds;
|
|
315
|
+
// xx if (!cloneDataValue.serverTimestamp) {
|
|
316
|
+
now = now || (0, node_opcua_date_time_1.getCurrentClock)();
|
|
317
|
+
cloneDataValue.serverTimestamp = now.timestamp;
|
|
318
|
+
cloneDataValue.serverPicoseconds = now.picoseconds;
|
|
319
|
+
// xx }
|
|
320
|
+
break;
|
|
321
|
+
case TimestampsToReturn_enum_1.TimestampsToReturn.Source:
|
|
322
|
+
cloneDataValue = cloneDataValue || _partial_clone(dataValue);
|
|
323
|
+
cloneDataValue.sourceTimestamp = dataValue.sourceTimestamp;
|
|
324
|
+
cloneDataValue.sourcePicoseconds = dataValue.sourcePicoseconds;
|
|
325
|
+
break;
|
|
326
|
+
case TimestampsToReturn_enum_1.TimestampsToReturn.Both:
|
|
327
|
+
default:
|
|
328
|
+
(0, node_opcua_assert_1.assert)(timestampsToReturn === TimestampsToReturn_enum_1.TimestampsToReturn.Both);
|
|
329
|
+
cloneDataValue = cloneDataValue || _partial_clone(dataValue);
|
|
330
|
+
cloneDataValue.serverTimestamp = dataValue.serverTimestamp;
|
|
331
|
+
cloneDataValue.serverPicoseconds = dataValue.serverPicoseconds;
|
|
332
|
+
// xx if (!cloneDataValue.serverTimestamp) {
|
|
333
|
+
now = now || (0, node_opcua_date_time_1.getCurrentClock)();
|
|
334
|
+
cloneDataValue.serverTimestamp = now.timestamp;
|
|
335
|
+
cloneDataValue.serverPicoseconds = now.picoseconds;
|
|
336
|
+
// xx }
|
|
337
|
+
cloneDataValue.sourceTimestamp = dataValue.sourceTimestamp;
|
|
338
|
+
cloneDataValue.sourcePicoseconds = dataValue.sourcePicoseconds;
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
341
|
+
// unset sourceTimestamp unless AttributeId is Value
|
|
342
|
+
if (attributeId !== node_opcua_data_model_1.AttributeIds.Value) {
|
|
343
|
+
cloneDataValue.sourceTimestamp = null;
|
|
344
|
+
}
|
|
345
|
+
return cloneDataValue;
|
|
346
|
+
}
|
|
347
|
+
exports.apply_timestamps = apply_timestamps;
|
|
348
|
+
function apply_timestamps_no_copy(dataValue, timestampsToReturn, attributeId, now) {
|
|
349
|
+
switch (timestampsToReturn) {
|
|
350
|
+
case TimestampsToReturn_enum_1.TimestampsToReturn.Neither:
|
|
351
|
+
dataValue.sourceTimestamp = null;
|
|
352
|
+
dataValue.sourcePicoseconds = 0;
|
|
353
|
+
dataValue.serverTimestamp = null;
|
|
354
|
+
dataValue.serverPicoseconds = 0;
|
|
355
|
+
break;
|
|
356
|
+
case TimestampsToReturn_enum_1.TimestampsToReturn.Server:
|
|
357
|
+
now = now || (0, node_opcua_date_time_1.getCurrentClock)();
|
|
358
|
+
dataValue.serverTimestamp = now.timestamp;
|
|
359
|
+
dataValue.serverPicoseconds = now.picoseconds;
|
|
360
|
+
dataValue.sourceTimestamp = null;
|
|
361
|
+
dataValue.sourcePicoseconds = 0;
|
|
362
|
+
break;
|
|
363
|
+
case TimestampsToReturn_enum_1.TimestampsToReturn.Source:
|
|
364
|
+
break;
|
|
365
|
+
case TimestampsToReturn_enum_1.TimestampsToReturn.Both:
|
|
366
|
+
default:
|
|
367
|
+
(0, node_opcua_assert_1.assert)(timestampsToReturn === TimestampsToReturn_enum_1.TimestampsToReturn.Both);
|
|
368
|
+
now = now || (0, node_opcua_date_time_1.getCurrentClock)();
|
|
369
|
+
dataValue.serverTimestamp = now.timestamp;
|
|
370
|
+
dataValue.serverPicoseconds = now.picoseconds;
|
|
371
|
+
break;
|
|
372
|
+
}
|
|
373
|
+
// unset sourceTimestamp unless AttributeId is Value
|
|
374
|
+
if (attributeId !== node_opcua_data_model_1.AttributeIds.Value) {
|
|
375
|
+
dataValue.sourceTimestamp = null;
|
|
376
|
+
}
|
|
377
|
+
return dataValue;
|
|
378
|
+
}
|
|
379
|
+
exports.apply_timestamps_no_copy = apply_timestamps_no_copy;
|
|
380
|
+
function apply_timestamps2(dataValue, timestampsToReturn, attributeId) {
|
|
381
|
+
(0, node_opcua_assert_1.assert)(attributeId > 0);
|
|
382
|
+
(0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(dataValue, "serverTimestamp"));
|
|
383
|
+
(0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(dataValue, "sourceTimestamp"));
|
|
384
|
+
const cloneDataValue = new DataValue({});
|
|
385
|
+
cloneDataValue.value = dataValue.value;
|
|
386
|
+
cloneDataValue.statusCode = dataValue.statusCode;
|
|
387
|
+
const now = (0, node_opcua_date_time_1.getCurrentClock)();
|
|
388
|
+
// apply timestamps
|
|
389
|
+
switch (timestampsToReturn) {
|
|
390
|
+
case TimestampsToReturn_enum_1.TimestampsToReturn.Server:
|
|
391
|
+
cloneDataValue.serverTimestamp = dataValue.serverTimestamp;
|
|
392
|
+
cloneDataValue.serverPicoseconds = dataValue.serverPicoseconds;
|
|
393
|
+
cloneDataValue.serverTimestamp = now.timestamp;
|
|
394
|
+
cloneDataValue.serverPicoseconds = now.picoseconds;
|
|
395
|
+
break;
|
|
396
|
+
case TimestampsToReturn_enum_1.TimestampsToReturn.Source:
|
|
397
|
+
cloneDataValue.sourceTimestamp = dataValue.sourceTimestamp;
|
|
398
|
+
cloneDataValue.sourcePicoseconds = dataValue.sourcePicoseconds;
|
|
399
|
+
break;
|
|
400
|
+
case TimestampsToReturn_enum_1.TimestampsToReturn.Both:
|
|
401
|
+
cloneDataValue.serverTimestamp = dataValue.serverTimestamp;
|
|
402
|
+
cloneDataValue.serverPicoseconds = dataValue.serverPicoseconds;
|
|
403
|
+
cloneDataValue.serverTimestamp = now.timestamp;
|
|
404
|
+
cloneDataValue.serverPicoseconds = now.picoseconds;
|
|
405
|
+
cloneDataValue.sourceTimestamp = dataValue.sourceTimestamp;
|
|
406
|
+
cloneDataValue.sourcePicoseconds = dataValue.sourcePicoseconds;
|
|
407
|
+
break;
|
|
408
|
+
}
|
|
409
|
+
// unset sourceTimestamp unless AttributeId is Value
|
|
410
|
+
if (attributeId !== node_opcua_data_model_1.AttributeIds.Value) {
|
|
411
|
+
cloneDataValue.sourceTimestamp = null;
|
|
412
|
+
}
|
|
413
|
+
return cloneDataValue;
|
|
414
|
+
}
|
|
415
|
+
/*
|
|
416
|
+
* @method _clone_with_array_replacement
|
|
417
|
+
* @param dataValue
|
|
418
|
+
* @param result
|
|
419
|
+
* @return {DataValue}
|
|
420
|
+
* @private
|
|
421
|
+
* @static
|
|
422
|
+
*/
|
|
423
|
+
function _clone_with_array_replacement(dataValue, result) {
|
|
424
|
+
const statusCode = result.statusCode === node_opcua_status_code_1.StatusCodes.Good ? dataValue.statusCode : result.statusCode;
|
|
425
|
+
const clonedDataValue = new DataValue({
|
|
426
|
+
statusCode,
|
|
427
|
+
serverTimestamp: dataValue.serverTimestamp,
|
|
428
|
+
serverPicoseconds: dataValue.serverPicoseconds,
|
|
429
|
+
sourceTimestamp: dataValue.sourceTimestamp,
|
|
430
|
+
sourcePicoseconds: dataValue.sourcePicoseconds,
|
|
431
|
+
value: {
|
|
432
|
+
dataType: node_opcua_variant_1.DataType.Null
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
clonedDataValue.value.dataType = dataValue.value.dataType;
|
|
436
|
+
clonedDataValue.value.arrayType = dataValue.value.arrayType;
|
|
437
|
+
clonedDataValue.value.dimensions = result.dimensions;
|
|
438
|
+
clonedDataValue.value.value = result.array;
|
|
439
|
+
return clonedDataValue;
|
|
440
|
+
}
|
|
441
|
+
function canRange(dataValue) {
|
|
442
|
+
return (dataValue.value &&
|
|
443
|
+
(dataValue.value.arrayType !== node_opcua_variant_1.VariantArrayType.Scalar ||
|
|
444
|
+
(dataValue.value.arrayType === node_opcua_variant_1.VariantArrayType.Scalar && dataValue.value.dataType === node_opcua_variant_1.DataType.ByteString) ||
|
|
445
|
+
(dataValue.value.arrayType === node_opcua_variant_1.VariantArrayType.Scalar && dataValue.value.dataType === node_opcua_variant_1.DataType.String)));
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* return a deep copy of the dataValue by applying indexRange if necessary on Array/Matrix
|
|
449
|
+
* @param dataValue {DataValue}
|
|
450
|
+
* @param indexRange {NumericalRange}
|
|
451
|
+
* @return {DataValue}
|
|
452
|
+
*/
|
|
453
|
+
function extractRange(dataValue, indexRange) {
|
|
454
|
+
const variant = dataValue.value;
|
|
455
|
+
if (indexRange && canRange(dataValue)) {
|
|
456
|
+
if (!indexRange.isValid()) {
|
|
457
|
+
return new DataValue({ statusCode: node_opcua_status_code_1.StatusCodes.BadIndexRangeInvalid });
|
|
458
|
+
}
|
|
459
|
+
// let's extract an array of elements corresponding to the indexRange
|
|
460
|
+
const result = indexRange.extract_values(variant.value, variant.dimensions);
|
|
461
|
+
dataValue = _clone_with_array_replacement(dataValue, result);
|
|
462
|
+
}
|
|
463
|
+
else {
|
|
464
|
+
// clone the whole data Value
|
|
465
|
+
dataValue = dataValue.clone();
|
|
466
|
+
}
|
|
467
|
+
return dataValue;
|
|
468
|
+
}
|
|
469
|
+
exports.extractRange = extractRange;
|
|
470
|
+
function sameDate(date1, date2) {
|
|
471
|
+
if (date1 === date2) {
|
|
472
|
+
return true;
|
|
473
|
+
}
|
|
474
|
+
if (date1 && date2 === null) {
|
|
475
|
+
return false;
|
|
476
|
+
}
|
|
477
|
+
if (date1 === null && date2) {
|
|
478
|
+
return false;
|
|
479
|
+
}
|
|
480
|
+
if (date1 === null || date2 === null) {
|
|
481
|
+
return false;
|
|
482
|
+
}
|
|
483
|
+
return date1.getTime() === date2.getTime();
|
|
484
|
+
}
|
|
485
|
+
function sourceTimestampHasChanged(dataValue1, dataValue2) {
|
|
486
|
+
return (!sameDate(dataValue1.sourceTimestamp, dataValue2.sourceTimestamp) ||
|
|
487
|
+
dataValue1.sourcePicoseconds !== dataValue2.sourcePicoseconds);
|
|
488
|
+
}
|
|
489
|
+
exports.sourceTimestampHasChanged = sourceTimestampHasChanged;
|
|
490
|
+
function serverTimestampHasChanged(dataValue1, dataValue2) {
|
|
491
|
+
return (!sameDate(dataValue1.serverTimestamp, dataValue2.serverTimestamp) ||
|
|
492
|
+
dataValue1.serverPicoseconds !== dataValue2.serverPicoseconds);
|
|
493
|
+
}
|
|
494
|
+
exports.serverTimestampHasChanged = serverTimestampHasChanged;
|
|
495
|
+
function timestampHasChanged(dataValue1, dataValue2, timestampsToReturn) {
|
|
496
|
+
// TODO: timestampsToReturn = timestampsToReturn || { key: "Neither"};
|
|
497
|
+
if (timestampsToReturn === undefined) {
|
|
498
|
+
return sourceTimestampHasChanged(dataValue1, dataValue2); // || serverTimestampHasChanged(dataValue1, dataValue2);
|
|
499
|
+
}
|
|
500
|
+
switch (timestampsToReturn) {
|
|
501
|
+
case TimestampsToReturn_enum_1.TimestampsToReturn.Neither:
|
|
502
|
+
return false;
|
|
503
|
+
case TimestampsToReturn_enum_1.TimestampsToReturn.Both:
|
|
504
|
+
return sourceTimestampHasChanged(dataValue1, dataValue2) || serverTimestampHasChanged(dataValue1, dataValue2);
|
|
505
|
+
case TimestampsToReturn_enum_1.TimestampsToReturn.Source:
|
|
506
|
+
return sourceTimestampHasChanged(dataValue1, dataValue2);
|
|
507
|
+
default:
|
|
508
|
+
(0, node_opcua_assert_1.assert)(timestampsToReturn === TimestampsToReturn_enum_1.TimestampsToReturn.Server);
|
|
509
|
+
return serverTimestampHasChanged(dataValue1, dataValue2);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
exports.timestampHasChanged = timestampHasChanged;
|
|
513
|
+
function sameStatusCode(statusCode1, statusCode2) {
|
|
514
|
+
return statusCode1.value === statusCode2.value;
|
|
515
|
+
}
|
|
516
|
+
exports.sameStatusCode = sameStatusCode;
|
|
517
|
+
/**
|
|
518
|
+
* @method sameDataValue
|
|
519
|
+
* @param v1 {DataValue}
|
|
520
|
+
* @param v2 {DataValue}
|
|
521
|
+
* @param [timestampsToReturn {TimestampsToReturn}]
|
|
522
|
+
* @return {boolean} true if data values are identical
|
|
523
|
+
*/
|
|
524
|
+
function sameDataValue(v1, v2, timestampsToReturn) {
|
|
525
|
+
if (v1 === v2) {
|
|
526
|
+
return true;
|
|
527
|
+
}
|
|
528
|
+
if (v1 && !v2) {
|
|
529
|
+
return false;
|
|
530
|
+
}
|
|
531
|
+
if (v2 && !v1) {
|
|
532
|
+
return false;
|
|
533
|
+
}
|
|
534
|
+
if (!sameStatusCode(v1.statusCode, v2.statusCode)) {
|
|
535
|
+
return false;
|
|
536
|
+
}
|
|
537
|
+
/*
|
|
538
|
+
//
|
|
539
|
+
// For performance reason, sourceTimestamp is
|
|
540
|
+
// used to determine if a dataValue has changed.
|
|
541
|
+
// if sourceTimestamp and sourcePicoseconds are identical
|
|
542
|
+
// then we make the assumption that Variant value is identical too.
|
|
543
|
+
// This will prevent us to deep compare potential large arrays.
|
|
544
|
+
// but before this is possible, we need to implement a mechanism
|
|
545
|
+
// that ensure that date() is always strictly increasing
|
|
546
|
+
if ((v1.sourceTimestamp && v2.sourceTimestamp) && !sourceTimestampHasChanged(v1, v2)) {
|
|
547
|
+
return true;
|
|
548
|
+
}
|
|
549
|
+
*/
|
|
550
|
+
if (timestampHasChanged(v1, v2, timestampsToReturn)) {
|
|
551
|
+
return false;
|
|
552
|
+
}
|
|
553
|
+
return (0, node_opcua_variant_1.sameVariant)(v1.value, v2.value);
|
|
554
|
+
}
|
|
555
|
+
exports.sameDataValue = sameDataValue;
|
|
556
|
+
class DataValueT extends DataValue {
|
|
557
|
+
}
|
|
558
|
+
exports.DataValueT = DataValueT;
|
|
559
559
|
//# sourceMappingURL=datavalue.js.map
|