node-opcua-status-code 2.55.0 → 2.63.0
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/LICENSE +20 -20
- package/dist/_generated_status_codes.js +1245 -250
- package/dist/_generated_status_codes.js.map +1 -1
- package/dist/opcua_status_code.d.ts +5 -3
- package/dist/opcua_status_code.js +3 -4
- package/dist/opcua_status_code.js.map +1 -1
- package/nyc.config.js +16 -16
- package/package.json +7 -5
- package/source/_generated_status_codes.ts +1521 -504
- package/source/callbacks.ts +11 -11
- package/source/index.ts +5 -5
- package/source/opcua_status_code.ts +391 -392
|
@@ -1,392 +1,391 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module node-opcua-status-code
|
|
3
|
-
*/
|
|
4
|
-
// tslint:disable:no-bitwise
|
|
5
|
-
|
|
6
|
-
import { assert } from "node-opcua-assert";
|
|
7
|
-
import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream";
|
|
8
|
-
|
|
9
|
-
function warnLog(...args: [any?, ...any[]]) {
|
|
10
|
-
/* istanbul ignore next */
|
|
11
|
-
// tslint:disable-next-line:no-console
|
|
12
|
-
console.warn
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* StatusCode Special bits
|
|
17
|
-
*/
|
|
18
|
-
export const extraStatusCodeBits: { [key: string]: number } = {
|
|
19
|
-
/**
|
|
20
|
-
* **StructureChanged** 15:15
|
|
21
|
-
* Indicates that the structure of the associated data value has changed since the last
|
|
22
|
-
* Notification.
|
|
23
|
-
* - Clients should not process the data value unless they re-read the metadata.
|
|
24
|
-
* - Servers shall set this bit if the DataTypeEncoding used for a Variable changes.
|
|
25
|
-
* - Servers shall also set this bit if the EnumStrings Property of the DataType of the Variable changes.
|
|
26
|
-
* - This bit is provided to warn Clients that parse complex data values that their parsing
|
|
27
|
-
* routines could fail because the serialized form of the data value has changed.
|
|
28
|
-
* - This bit has meaning only for StatusCodes returned as part of a data change Notification
|
|
29
|
-
* or the HistoryRead. StatusCodes used in other contexts shall always set this bit to zero.
|
|
30
|
-
*/
|
|
31
|
-
StructureChanged: 0x1 << 15,
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* **SemanticsChanged** 14:14 Semantics of the associated data value have changed. Clients should not process the data
|
|
35
|
-
* value until they re-read the metadata associated with the Variable.
|
|
36
|
-
* - Servers should set this bit if the metadata has changed in way that could cause application errors if the
|
|
37
|
-
* - Client does not re-read the metadata. For example, a change to the engineering units
|
|
38
|
-
* could create problems if the Client uses the value to perform calculations.
|
|
39
|
-
* - Part 8 defines the conditions where a Server shall set this bit for a DA Variable.
|
|
40
|
-
* - Other specifications may define additional conditions.
|
|
41
|
-
* - A Server may define other conditions that cause this bit to be set. This bit has meaning only for StatusCodes returned as part of a data change Notification
|
|
42
|
-
* or the HistoryRead. StatusCodes used in other contexts shall always set this bit to zero.
|
|
43
|
-
*/
|
|
44
|
-
SemanticChanged: 0x1 << 14,
|
|
45
|
-
|
|
46
|
-
// Reserved 12:13 Reserved for future use. Shall always be zero.
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* **InfoType** 10:11
|
|
50
|
-
* The type of information contained in the info bits. These bits have the following meanings:
|
|
51
|
-
*
|
|
52
|
-
* | Meaning |value | description|
|
|
53
|
-
* |-----------------------------------|------|----------------------------------------------------|
|
|
54
|
-
* | NotUsed | 00 | The info bits are not used and shall be set to zero. |
|
|
55
|
-
* | DataValue | 01 | The StatusCode and its info bits are associated with a data value returned from the Server. This flag is only used in combination with StatusCodes defined in Part 8. |
|
|
56
|
-
* | Reserved |1X | Reserved for future use. The info bits shall be ignored.|
|
|
57
|
-
*/
|
|
58
|
-
InfoTypeDataValue: 0x1 << 10, // 0x0400,
|
|
59
|
-
|
|
60
|
-
// InfoBits 0:9 Additional information bits that qualify the StatusCode.
|
|
61
|
-
// The structure of these bits depends on the Info Type field.
|
|
62
|
-
//
|
|
63
|
-
// LimitBits 8:9 The limit bits associated with the data value. The limits bits have the
|
|
64
|
-
// following meanings:
|
|
65
|
-
// Limit Bits Description
|
|
66
|
-
// None 00 The value is free to change.
|
|
67
|
-
// Low 01 The value is at the lower limit for the data source.
|
|
68
|
-
// High 10 The value is at the higher limit for the data source.
|
|
69
|
-
// Constant 11 The value is constant and cannot change.
|
|
70
|
-
LimitLow: 0x1 << 8,
|
|
71
|
-
|
|
72
|
-
LimitHigh: 0x2 << 8,
|
|
73
|
-
|
|
74
|
-
LimitConstant: 0x3 << 8,
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* **Overflow** 7:7
|
|
78
|
-
* - This bit shall only be set if the MonitoredItem queue size is greater than 1.
|
|
79
|
-
* - If this bit is set, not every detected change has been returned since the Server’s
|
|
80
|
-
* queue buffer for the MonitoredItem reached its limit and had to purge out data.
|
|
81
|
-
*
|
|
82
|
-
*/
|
|
83
|
-
Overflow: 0x1 << 7, // 1 << 7
|
|
84
|
-
|
|
85
|
-
// Reserved 5:6 Reserved for future use. Shall always be zero.
|
|
86
|
-
|
|
87
|
-
// HistorianBits 0:4 These bits are set only when reading historical data. They indicate where the data value
|
|
88
|
-
// came from and provide information that affects how the Client uses the data value.
|
|
89
|
-
// The historian bits have the following meaning:
|
|
90
|
-
// Raw XXX00 A raw data value.
|
|
91
|
-
// Calculated XXX01 A data value which was calculated.
|
|
92
|
-
// Interpolated XXX10 A data value which was interpolated.
|
|
93
|
-
// Reserved XXX11 Undefined.
|
|
94
|
-
// Partial XX1XX A data value which was calculated with an incomplete interval.
|
|
95
|
-
// Extra Data X1XXX A raw data value that hides other data at the same timestamp.
|
|
96
|
-
// Multi Value 1XXXX Multiple values match the Aggregate criteria (i.e. multiple
|
|
97
|
-
// minimum values at different timestamps within the same interval).
|
|
98
|
-
// Part 11 describes how these bits are used in more detail.
|
|
99
|
-
|
|
100
|
-
/** historical data contains a data value which was calculated. */
|
|
101
|
-
HistorianCalculated: 0x1 << 0,
|
|
102
|
-
|
|
103
|
-
/** historical data contains a data value which was interpolated. */
|
|
104
|
-
HistorianInterpolated: 0x2 << 0,
|
|
105
|
-
|
|
106
|
-
/** historical data contains a data value which was calculated with an incomplete interval. */
|
|
107
|
-
HistorianPartial: 0x1 << 2,
|
|
108
|
-
|
|
109
|
-
/** historical data contains a raw data value that hides other data at the same timestamp. */
|
|
110
|
-
HistorianExtraData: 0x1 << 3,
|
|
111
|
-
|
|
112
|
-
/** Multiple values match the Aggregate criteria (i.e. multiple minimum values at different timestamps within the same interval). */
|
|
113
|
-
HistorianMultiValue: 0x1 << 4
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* a particular StatusCode , with it's value , name and description
|
|
118
|
-
*/
|
|
119
|
-
|
|
120
|
-
export abstract class StatusCode {
|
|
121
|
-
/**
|
|
122
|
-
* returns a status code that can be modified
|
|
123
|
-
*/
|
|
124
|
-
public static makeStatusCode(statusCode: StatusCode | string, optionalBits: string | number): StatusCode {
|
|
125
|
-
const _base = coerceStatusCode(statusCode);
|
|
126
|
-
const tmp = new ModifiableStatusCode({ _base });
|
|
127
|
-
if (optionalBits || typeof optionalBits === "number") {
|
|
128
|
-
tmp.set(optionalBits);
|
|
129
|
-
}
|
|
130
|
-
return tmp;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* returns status code value in numerical form, including extra bits
|
|
135
|
-
*/
|
|
136
|
-
public abstract get value(): number;
|
|
137
|
-
|
|
138
|
-
/***
|
|
139
|
-
* status code by name, (including extra bits in textual forms)
|
|
140
|
-
*/
|
|
141
|
-
public abstract get name(): string;
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* return the long description of the status code
|
|
145
|
-
*/
|
|
146
|
-
public abstract get description(): string;
|
|
147
|
-
|
|
148
|
-
public valueOf(): number {
|
|
149
|
-
return this.value;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
public toString(): string {
|
|
153
|
-
return this.name + " (0x" + ("0000" + this.value.toString(16)).substr(-8) + ")";
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
public checkBit(mask: number): boolean {
|
|
157
|
-
return (this.value & mask) === mask;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/** returns true if the overflow bit is set */
|
|
161
|
-
public get hasOverflowBit(): boolean {
|
|
162
|
-
return this.checkBit(extraStatusCodeBits.Overflow);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/** returns true if the semanticChange bit is set */
|
|
166
|
-
public get hasSemanticChangedBit(): boolean {
|
|
167
|
-
return this.checkBit(extraStatusCodeBits.SemanticChanged);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/** returns true if the structureChange bit is set */
|
|
171
|
-
public get hasStructureChangedBit(): boolean {
|
|
172
|
-
return this.checkBit(extraStatusCodeBits.StructureChanged);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
public isNot(other: StatusCode): boolean {
|
|
176
|
-
assert(other instanceof StatusCode);
|
|
177
|
-
return this.value !== other.value;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
public equals(other: StatusCode): boolean {
|
|
181
|
-
assert(other instanceof StatusCode);
|
|
182
|
-
return this.value === other.value;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
public toJSON(): any {
|
|
186
|
-
return { value: this.value };
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
public toJSONFull(): any {
|
|
190
|
-
return { value: this.value, name: this.name, description: this.description };
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
Object.defineProperty(StatusCode.prototype, "value", { enumerable: true });
|
|
195
|
-
Object.defineProperty(StatusCode.prototype, "description", { enumerable: true });
|
|
196
|
-
Object.defineProperty(StatusCode.prototype, "name", { enumerable: true });
|
|
197
|
-
|
|
198
|
-
// tslint:disable:max-classes-per-file
|
|
199
|
-
export class ConstantStatusCode extends StatusCode {
|
|
200
|
-
private readonly _value: number;
|
|
201
|
-
private readonly _description: string;
|
|
202
|
-
private readonly _name: string;
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
*
|
|
206
|
-
* @param options
|
|
207
|
-
* @param options
|
|
208
|
-
* @param options.value
|
|
209
|
-
* @param options.description
|
|
210
|
-
* @param options.name
|
|
211
|
-
*
|
|
212
|
-
*/
|
|
213
|
-
constructor(options: { value: number; description: string; name: string }) {
|
|
214
|
-
super();
|
|
215
|
-
this._value = options.value;
|
|
216
|
-
this._description = options.description;
|
|
217
|
-
this._name = options.name;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
public get value(): number {
|
|
221
|
-
return this._value;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
public get name(): string {
|
|
225
|
-
return this._name;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
public get description(): string {
|
|
229
|
-
return this._description;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
Object.defineProperty(ConstantStatusCode.prototype, "_value", { enumerable: false, writable: true });
|
|
234
|
-
Object.defineProperty(ConstantStatusCode.prototype, "_description", { enumerable: false, writable: true });
|
|
235
|
-
Object.defineProperty(ConstantStatusCode.prototype, "_name", { enumerable: false, writable: true });
|
|
236
|
-
Object.defineProperty(ConstantStatusCode.prototype, "value", { enumerable: true });
|
|
237
|
-
Object.defineProperty(ConstantStatusCode.prototype, "description", { enumerable: true });
|
|
238
|
-
Object.defineProperty(ConstantStatusCode.prototype, "name", { enumerable: true });
|
|
239
|
-
|
|
240
|
-
export function encodeStatusCode(statusCode: StatusCode | ConstantStatusCode, stream: OutputBinaryStream) {
|
|
241
|
-
stream.writeUInt32(statusCode.value);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/** @internal construct status codes fast search indexes */
|
|
245
|
-
const statusCodesReversedMap: any = {};
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* returns the StatusCode corresponding to the provided value, if any
|
|
249
|
-
* @note: if code is not known , then StatusCodes.Bad will be returned
|
|
250
|
-
* @param code
|
|
251
|
-
*/
|
|
252
|
-
export function getStatusCodeFromCode(code: number) {
|
|
253
|
-
const codeWithoutInfoBits = (code & 0xffff0000) >>> 0;
|
|
254
|
-
const infoBits = code & 0x0000ffff;
|
|
255
|
-
let sc = statusCodesReversedMap[codeWithoutInfoBits];
|
|
256
|
-
|
|
257
|
-
/* istanbul ignore if */
|
|
258
|
-
if (!sc) {
|
|
259
|
-
sc = StatusCodes.Bad;
|
|
260
|
-
// tslint:disable-next-line: no-console
|
|
261
|
-
console.log(
|
|
262
|
-
"expecting a known StatusCode but got 0x" + codeWithoutInfoBits.toString(16),
|
|
263
|
-
" code was 0x" + code.toString(16)
|
|
264
|
-
);
|
|
265
|
-
warnLog("expecting a known StatusCode but got 0x" + codeWithoutInfoBits.toString(16), " code was 0x" + code.toString(16));
|
|
266
|
-
}
|
|
267
|
-
if (infoBits) {
|
|
268
|
-
const tmp = new ModifiableStatusCode({ _base: sc });
|
|
269
|
-
tmp.set(infoBits);
|
|
270
|
-
sc = tmp;
|
|
271
|
-
}
|
|
272
|
-
return sc;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
export function decodeStatusCode(stream: BinaryStream, _value?: StatusCode) {
|
|
276
|
-
const code = stream.readUInt32();
|
|
277
|
-
return getStatusCodeFromCode(code);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
export class ModifiableStatusCode extends StatusCode {
|
|
281
|
-
private readonly _base: StatusCode;
|
|
282
|
-
private _extraBits: number;
|
|
283
|
-
|
|
284
|
-
constructor(options: { _base: StatusCode }) {
|
|
285
|
-
super();
|
|
286
|
-
this._base = options._base;
|
|
287
|
-
this._extraBits = 0;
|
|
288
|
-
if (this._base instanceof ModifiableStatusCode) {
|
|
289
|
-
this._extraBits = this._base._extraBits;
|
|
290
|
-
this._base = this._base._base;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
public get value() {
|
|
295
|
-
return this._base.value + this._extraBits;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
public get name() {
|
|
299
|
-
return this._base.name + this._getExtraName();
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
public get description() {
|
|
303
|
-
return this._base.description;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
public set(bit: string | number): void {
|
|
307
|
-
if (typeof bit === "string") {
|
|
308
|
-
const bitsArray = bit.split(" | ");
|
|
309
|
-
if (bitsArray.length > 1) {
|
|
310
|
-
for (const bitArray of bitsArray) {
|
|
311
|
-
this.set(bitArray);
|
|
312
|
-
}
|
|
313
|
-
return;
|
|
314
|
-
}
|
|
315
|
-
const tmp = extraStatusCodeBits[bit as string];
|
|
316
|
-
|
|
317
|
-
/* istanbul ignore next */
|
|
318
|
-
if (!tmp) {
|
|
319
|
-
throw new Error("Invalid StatusCode Bit " + bit);
|
|
320
|
-
}
|
|
321
|
-
bit = tmp;
|
|
322
|
-
}
|
|
323
|
-
this._extraBits = this._extraBits | (bit as number);
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
public unset(bit: string | number): void {
|
|
327
|
-
if (typeof bit === "string") {
|
|
328
|
-
const bitsArray = bit.split(" | ");
|
|
329
|
-
if (bitsArray.length > 1) {
|
|
330
|
-
for (const bitArray of bitsArray) {
|
|
331
|
-
this.unset(bitArray);
|
|
332
|
-
}
|
|
333
|
-
return;
|
|
334
|
-
}
|
|
335
|
-
const tmp = extraStatusCodeBits[bit];
|
|
336
|
-
|
|
337
|
-
/* istanbul ignore next */
|
|
338
|
-
if (!tmp) {
|
|
339
|
-
throw new Error("Invalid StatusCode Bit " + bit);
|
|
340
|
-
}
|
|
341
|
-
bit = tmp;
|
|
342
|
-
}
|
|
343
|
-
this._extraBits = this._extraBits & (~bit >>> 0);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
private _getExtraName() {
|
|
347
|
-
const
|
|
348
|
-
const
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
Object.defineProperty(ModifiableStatusCode.prototype, "
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
(StatusCodes as any).makeStatusCode = StatusCode.makeStatusCode;
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-status-code
|
|
3
|
+
*/
|
|
4
|
+
// tslint:disable:no-bitwise
|
|
5
|
+
|
|
6
|
+
import { assert } from "node-opcua-assert";
|
|
7
|
+
import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream";
|
|
8
|
+
|
|
9
|
+
function warnLog(...args: [any?, ...any[]]) {
|
|
10
|
+
/* istanbul ignore next */
|
|
11
|
+
// tslint:disable-next-line:no-console
|
|
12
|
+
console.warn(...args);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* StatusCode Special bits
|
|
17
|
+
*/
|
|
18
|
+
export const extraStatusCodeBits: { [key: string]: number } = {
|
|
19
|
+
/**
|
|
20
|
+
* **StructureChanged** 15:15
|
|
21
|
+
* Indicates that the structure of the associated data value has changed since the last
|
|
22
|
+
* Notification.
|
|
23
|
+
* - Clients should not process the data value unless they re-read the metadata.
|
|
24
|
+
* - Servers shall set this bit if the DataTypeEncoding used for a Variable changes.
|
|
25
|
+
* - Servers shall also set this bit if the EnumStrings Property of the DataType of the Variable changes.
|
|
26
|
+
* - This bit is provided to warn Clients that parse complex data values that their parsing
|
|
27
|
+
* routines could fail because the serialized form of the data value has changed.
|
|
28
|
+
* - This bit has meaning only for StatusCodes returned as part of a data change Notification
|
|
29
|
+
* or the HistoryRead. StatusCodes used in other contexts shall always set this bit to zero.
|
|
30
|
+
*/
|
|
31
|
+
StructureChanged: 0x1 << 15,
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* **SemanticsChanged** 14:14 Semantics of the associated data value have changed. Clients should not process the data
|
|
35
|
+
* value until they re-read the metadata associated with the Variable.
|
|
36
|
+
* - Servers should set this bit if the metadata has changed in way that could cause application errors if the
|
|
37
|
+
* - Client does not re-read the metadata. For example, a change to the engineering units
|
|
38
|
+
* could create problems if the Client uses the value to perform calculations.
|
|
39
|
+
* - Part 8 defines the conditions where a Server shall set this bit for a DA Variable.
|
|
40
|
+
* - Other specifications may define additional conditions.
|
|
41
|
+
* - A Server may define other conditions that cause this bit to be set. This bit has meaning only for StatusCodes returned as part of a data change Notification
|
|
42
|
+
* or the HistoryRead. StatusCodes used in other contexts shall always set this bit to zero.
|
|
43
|
+
*/
|
|
44
|
+
SemanticChanged: 0x1 << 14,
|
|
45
|
+
|
|
46
|
+
// Reserved 12:13 Reserved for future use. Shall always be zero.
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* **InfoType** 10:11
|
|
50
|
+
* The type of information contained in the info bits. These bits have the following meanings:
|
|
51
|
+
*
|
|
52
|
+
* | Meaning |value | description|
|
|
53
|
+
* |-----------------------------------|------|----------------------------------------------------|
|
|
54
|
+
* | NotUsed | 00 | The info bits are not used and shall be set to zero. |
|
|
55
|
+
* | DataValue | 01 | The StatusCode and its info bits are associated with a data value returned from the Server. This flag is only used in combination with StatusCodes defined in Part 8. |
|
|
56
|
+
* | Reserved |1X | Reserved for future use. The info bits shall be ignored.|
|
|
57
|
+
*/
|
|
58
|
+
InfoTypeDataValue: 0x1 << 10, // 0x0400,
|
|
59
|
+
|
|
60
|
+
// InfoBits 0:9 Additional information bits that qualify the StatusCode.
|
|
61
|
+
// The structure of these bits depends on the Info Type field.
|
|
62
|
+
//
|
|
63
|
+
// LimitBits 8:9 The limit bits associated with the data value. The limits bits have the
|
|
64
|
+
// following meanings:
|
|
65
|
+
// Limit Bits Description
|
|
66
|
+
// None 00 The value is free to change.
|
|
67
|
+
// Low 01 The value is at the lower limit for the data source.
|
|
68
|
+
// High 10 The value is at the higher limit for the data source.
|
|
69
|
+
// Constant 11 The value is constant and cannot change.
|
|
70
|
+
LimitLow: 0x1 << 8,
|
|
71
|
+
|
|
72
|
+
LimitHigh: 0x2 << 8,
|
|
73
|
+
|
|
74
|
+
LimitConstant: 0x3 << 8,
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* **Overflow** 7:7
|
|
78
|
+
* - This bit shall only be set if the MonitoredItem queue size is greater than 1.
|
|
79
|
+
* - If this bit is set, not every detected change has been returned since the Server’s
|
|
80
|
+
* queue buffer for the MonitoredItem reached its limit and had to purge out data.
|
|
81
|
+
*
|
|
82
|
+
*/
|
|
83
|
+
Overflow: 0x1 << 7, // 1 << 7
|
|
84
|
+
|
|
85
|
+
// Reserved 5:6 Reserved for future use. Shall always be zero.
|
|
86
|
+
|
|
87
|
+
// HistorianBits 0:4 These bits are set only when reading historical data. They indicate where the data value
|
|
88
|
+
// came from and provide information that affects how the Client uses the data value.
|
|
89
|
+
// The historian bits have the following meaning:
|
|
90
|
+
// Raw XXX00 A raw data value.
|
|
91
|
+
// Calculated XXX01 A data value which was calculated.
|
|
92
|
+
// Interpolated XXX10 A data value which was interpolated.
|
|
93
|
+
// Reserved XXX11 Undefined.
|
|
94
|
+
// Partial XX1XX A data value which was calculated with an incomplete interval.
|
|
95
|
+
// Extra Data X1XXX A raw data value that hides other data at the same timestamp.
|
|
96
|
+
// Multi Value 1XXXX Multiple values match the Aggregate criteria (i.e. multiple
|
|
97
|
+
// minimum values at different timestamps within the same interval).
|
|
98
|
+
// Part 11 describes how these bits are used in more detail.
|
|
99
|
+
|
|
100
|
+
/** historical data contains a data value which was calculated. */
|
|
101
|
+
HistorianCalculated: 0x1 << 0,
|
|
102
|
+
|
|
103
|
+
/** historical data contains a data value which was interpolated. */
|
|
104
|
+
HistorianInterpolated: 0x2 << 0,
|
|
105
|
+
|
|
106
|
+
/** historical data contains a data value which was calculated with an incomplete interval. */
|
|
107
|
+
HistorianPartial: 0x1 << 2,
|
|
108
|
+
|
|
109
|
+
/** historical data contains a raw data value that hides other data at the same timestamp. */
|
|
110
|
+
HistorianExtraData: 0x1 << 3,
|
|
111
|
+
|
|
112
|
+
/** Multiple values match the Aggregate criteria (i.e. multiple minimum values at different timestamps within the same interval). */
|
|
113
|
+
HistorianMultiValue: 0x1 << 4
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* a particular StatusCode , with it's value , name and description
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
export abstract class StatusCode {
|
|
121
|
+
/**
|
|
122
|
+
* returns a status code that can be modified
|
|
123
|
+
*/
|
|
124
|
+
public static makeStatusCode(statusCode: StatusCode | string, optionalBits: string | number): StatusCode {
|
|
125
|
+
const _base = coerceStatusCode(statusCode);
|
|
126
|
+
const tmp = new ModifiableStatusCode({ _base });
|
|
127
|
+
if (optionalBits || typeof optionalBits === "number") {
|
|
128
|
+
tmp.set(optionalBits);
|
|
129
|
+
}
|
|
130
|
+
return tmp;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* returns status code value in numerical form, including extra bits
|
|
135
|
+
*/
|
|
136
|
+
public abstract get value(): number;
|
|
137
|
+
|
|
138
|
+
/***
|
|
139
|
+
* status code by name, (including extra bits in textual forms)
|
|
140
|
+
*/
|
|
141
|
+
public abstract get name(): string;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* return the long description of the status code
|
|
145
|
+
*/
|
|
146
|
+
public abstract get description(): string;
|
|
147
|
+
|
|
148
|
+
public valueOf(): number {
|
|
149
|
+
return this.value;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
public toString(): string {
|
|
153
|
+
return this.name + " (0x" + ("0000" + this.value.toString(16)).substr(-8) + ")";
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
public checkBit(mask: number): boolean {
|
|
157
|
+
return (this.value & mask) === mask;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** returns true if the overflow bit is set */
|
|
161
|
+
public get hasOverflowBit(): boolean {
|
|
162
|
+
return this.checkBit(extraStatusCodeBits.Overflow);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** returns true if the semanticChange bit is set */
|
|
166
|
+
public get hasSemanticChangedBit(): boolean {
|
|
167
|
+
return this.checkBit(extraStatusCodeBits.SemanticChanged);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** returns true if the structureChange bit is set */
|
|
171
|
+
public get hasStructureChangedBit(): boolean {
|
|
172
|
+
return this.checkBit(extraStatusCodeBits.StructureChanged);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
public isNot(other: StatusCode): boolean {
|
|
176
|
+
assert(other instanceof StatusCode);
|
|
177
|
+
return this.value !== other.value;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
public equals(other: StatusCode): boolean {
|
|
181
|
+
assert(other instanceof StatusCode);
|
|
182
|
+
return this.value === other.value;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
public toJSON(): any {
|
|
186
|
+
return { value: this.value };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
public toJSONFull(): any {
|
|
190
|
+
return { value: this.value, name: this.name, description: this.description };
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
Object.defineProperty(StatusCode.prototype, "value", { enumerable: true });
|
|
195
|
+
Object.defineProperty(StatusCode.prototype, "description", { enumerable: true });
|
|
196
|
+
Object.defineProperty(StatusCode.prototype, "name", { enumerable: true });
|
|
197
|
+
|
|
198
|
+
// tslint:disable:max-classes-per-file
|
|
199
|
+
export class ConstantStatusCode extends StatusCode {
|
|
200
|
+
private readonly _value: number;
|
|
201
|
+
private readonly _description: string;
|
|
202
|
+
private readonly _name: string;
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
*
|
|
206
|
+
* @param options
|
|
207
|
+
* @param options
|
|
208
|
+
* @param options.value
|
|
209
|
+
* @param options.description
|
|
210
|
+
* @param options.name
|
|
211
|
+
*
|
|
212
|
+
*/
|
|
213
|
+
constructor(options: { value: number; description: string; name: string }) {
|
|
214
|
+
super();
|
|
215
|
+
this._value = options.value;
|
|
216
|
+
this._description = options.description;
|
|
217
|
+
this._name = options.name;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
public get value(): number {
|
|
221
|
+
return this._value;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
public get name(): string {
|
|
225
|
+
return this._name;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
public get description(): string {
|
|
229
|
+
return this._description;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
Object.defineProperty(ConstantStatusCode.prototype, "_value", { enumerable: false, writable: true });
|
|
234
|
+
Object.defineProperty(ConstantStatusCode.prototype, "_description", { enumerable: false, writable: true });
|
|
235
|
+
Object.defineProperty(ConstantStatusCode.prototype, "_name", { enumerable: false, writable: true });
|
|
236
|
+
Object.defineProperty(ConstantStatusCode.prototype, "value", { enumerable: true });
|
|
237
|
+
Object.defineProperty(ConstantStatusCode.prototype, "description", { enumerable: true });
|
|
238
|
+
Object.defineProperty(ConstantStatusCode.prototype, "name", { enumerable: true });
|
|
239
|
+
|
|
240
|
+
export function encodeStatusCode(statusCode: StatusCode | ConstantStatusCode, stream: OutputBinaryStream): void {
|
|
241
|
+
stream.writeUInt32(statusCode.value);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** @internal construct status codes fast search indexes */
|
|
245
|
+
const statusCodesReversedMap: any = {};
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* returns the StatusCode corresponding to the provided value, if any
|
|
249
|
+
* @note: if code is not known , then StatusCodes.Bad will be returned
|
|
250
|
+
* @param code
|
|
251
|
+
*/
|
|
252
|
+
export function getStatusCodeFromCode(code: number): StatusCode {
|
|
253
|
+
const codeWithoutInfoBits = (code & 0xffff0000) >>> 0;
|
|
254
|
+
const infoBits = code & 0x0000ffff;
|
|
255
|
+
let sc = statusCodesReversedMap[codeWithoutInfoBits];
|
|
256
|
+
|
|
257
|
+
/* istanbul ignore if */
|
|
258
|
+
if (!sc) {
|
|
259
|
+
sc = StatusCodes.Bad;
|
|
260
|
+
// tslint:disable-next-line: no-console
|
|
261
|
+
console.log(
|
|
262
|
+
"expecting a known StatusCode but got 0x" + codeWithoutInfoBits.toString(16),
|
|
263
|
+
" code was 0x" + code.toString(16)
|
|
264
|
+
);
|
|
265
|
+
warnLog("expecting a known StatusCode but got 0x" + codeWithoutInfoBits.toString(16), " code was 0x" + code.toString(16));
|
|
266
|
+
}
|
|
267
|
+
if (infoBits) {
|
|
268
|
+
const tmp = new ModifiableStatusCode({ _base: sc });
|
|
269
|
+
tmp.set(infoBits);
|
|
270
|
+
sc = tmp;
|
|
271
|
+
}
|
|
272
|
+
return sc;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export function decodeStatusCode(stream: BinaryStream, _value?: StatusCode): StatusCode {
|
|
276
|
+
const code = stream.readUInt32();
|
|
277
|
+
return getStatusCodeFromCode(code);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export class ModifiableStatusCode extends StatusCode {
|
|
281
|
+
private readonly _base: StatusCode;
|
|
282
|
+
private _extraBits: number;
|
|
283
|
+
|
|
284
|
+
constructor(options: { _base: StatusCode }) {
|
|
285
|
+
super();
|
|
286
|
+
this._base = options._base;
|
|
287
|
+
this._extraBits = 0;
|
|
288
|
+
if (this._base instanceof ModifiableStatusCode) {
|
|
289
|
+
this._extraBits = this._base._extraBits;
|
|
290
|
+
this._base = this._base._base;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
public get value(): number {
|
|
295
|
+
return this._base.value + this._extraBits;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
public get name(): string {
|
|
299
|
+
return this._base.name + this._getExtraName();
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
public get description(): string {
|
|
303
|
+
return this._base.description;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
public set(bit: string | number): void {
|
|
307
|
+
if (typeof bit === "string") {
|
|
308
|
+
const bitsArray = bit.split(" | ");
|
|
309
|
+
if (bitsArray.length > 1) {
|
|
310
|
+
for (const bitArray of bitsArray) {
|
|
311
|
+
this.set(bitArray);
|
|
312
|
+
}
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
const tmp = extraStatusCodeBits[bit as string];
|
|
316
|
+
|
|
317
|
+
/* istanbul ignore next */
|
|
318
|
+
if (!tmp) {
|
|
319
|
+
throw new Error("Invalid StatusCode Bit " + bit);
|
|
320
|
+
}
|
|
321
|
+
bit = tmp;
|
|
322
|
+
}
|
|
323
|
+
this._extraBits = this._extraBits | (bit as number);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
public unset(bit: string | number): void {
|
|
327
|
+
if (typeof bit === "string") {
|
|
328
|
+
const bitsArray = bit.split(" | ");
|
|
329
|
+
if (bitsArray.length > 1) {
|
|
330
|
+
for (const bitArray of bitsArray) {
|
|
331
|
+
this.unset(bitArray);
|
|
332
|
+
}
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
const tmp = extraStatusCodeBits[bit];
|
|
336
|
+
|
|
337
|
+
/* istanbul ignore next */
|
|
338
|
+
if (!tmp) {
|
|
339
|
+
throw new Error("Invalid StatusCode Bit " + bit);
|
|
340
|
+
}
|
|
341
|
+
bit = tmp;
|
|
342
|
+
}
|
|
343
|
+
this._extraBits = this._extraBits & (~bit >>> 0);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
private _getExtraName() {
|
|
347
|
+
const str: string[] = [];
|
|
348
|
+
for (const [key, value] of Object.entries(extraStatusCodeBits)) {
|
|
349
|
+
if ((this._extraBits & value) === value) {
|
|
350
|
+
str.push(key);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/* istanbul ignore next */
|
|
355
|
+
if (str.length === 0) {
|
|
356
|
+
return "";
|
|
357
|
+
}
|
|
358
|
+
return "#" + str.join("|");
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// hide private properties
|
|
363
|
+
Object.defineProperty(ModifiableStatusCode.prototype, "_base", { enumerable: false, writable: true });
|
|
364
|
+
Object.defineProperty(ModifiableStatusCode.prototype, "_extraBits", { enumerable: false, writable: true });
|
|
365
|
+
|
|
366
|
+
import { StatusCodes } from "./_generated_status_codes";
|
|
367
|
+
export { StatusCodes } from "./_generated_status_codes";
|
|
368
|
+
|
|
369
|
+
export function coerceStatusCode(statusCode: StatusCode | number | string | { value: number }): StatusCode {
|
|
370
|
+
if (statusCode instanceof StatusCode) {
|
|
371
|
+
return statusCode;
|
|
372
|
+
}
|
|
373
|
+
if (Object.prototype.hasOwnProperty.call(statusCode, "value")) {
|
|
374
|
+
return getStatusCodeFromCode((statusCode as { value: number }).value);
|
|
375
|
+
}
|
|
376
|
+
if (typeof statusCode === "number") {
|
|
377
|
+
return getStatusCodeFromCode(statusCode);
|
|
378
|
+
}
|
|
379
|
+
const _StatusCodes = StatusCodes as any;
|
|
380
|
+
if (!_StatusCodes[statusCode as string]) {
|
|
381
|
+
throw new Error("Cannot find StatusCode " + statusCode);
|
|
382
|
+
}
|
|
383
|
+
return _StatusCodes[statusCode as string];
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
for (const name of Object.keys(StatusCodes)) {
|
|
387
|
+
const code = (StatusCodes as any)[name];
|
|
388
|
+
statusCodesReversedMap[code.value.toString()] = code;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
(StatusCodes as any).makeStatusCode = StatusCode.makeStatusCode;
|