node-opcua-address-space 2.113.1 → 2.113.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-opcua-address-space",
3
- "version": "2.113.1",
3
+ "version": "2.113.2",
4
4
  "description": "pure nodejs OPCUA SDK - module address-space",
5
5
  "main": "./dist/src/index_current.js",
6
6
  "types": "./dist/source/index.d.ts",
@@ -84,7 +84,7 @@
84
84
  "internet of things"
85
85
  ],
86
86
  "homepage": "http://node-opcua.github.io/",
87
- "gitHead": "5990ba93b03458f3d7304c36a99e5eb814bbcf3c",
87
+ "gitHead": "d72e73db4c07d27ea2da81ccbd258e63ad6c640b",
88
88
  "files": [
89
89
  "dist",
90
90
  "distHelpers",
@@ -13,6 +13,7 @@ export interface ConditionInfoOptions {
13
13
 
14
14
  time?: Date | null;
15
15
  receiveTime?: Date | null;
16
+
16
17
  }
17
18
 
18
19
  export interface ConditionInfo {
@@ -11,20 +11,24 @@ import { StatusCode } from "node-opcua-status-code";
11
11
  import { TimeZoneDataType } from "node-opcua-types";
12
12
  import { UtcTime } from "../state_machine/ua_state_machine_type";
13
13
  import { ISetStateOptions } from "../i_set_state_options";
14
+ import { IConditionVariableTypeSetterOptions } from "../i_condition_variable_type_setter_options";
14
15
 
15
16
  export interface ConditionSnapshot {
16
- on(eventName: "value_changed", eventHandler: (node: UAVariable, variant: Variant) => void): this;
17
+ on(
18
+ eventName: "valueChanged",
19
+ eventHandler: (node: UAVariable, variant: Variant, options: { sourceTimestamp: Date }) => void
20
+ ): this;
17
21
  }
18
22
 
19
-
20
23
  export interface ConditionSnapshot extends EventEmitter {
21
24
  // static normalizeName = normalizeName;
22
25
 
26
+ emit(eventName: "valueChanged", node: UAVariable, variant: Variant, options: { sourceTimestamp: Date }): boolean;
27
+ emit(eventName: string | symbol): boolean;
23
28
  condition: BaseNode;
24
29
  eventData: IEventData | null;
25
30
  branchId: NodeId | null;
26
31
 
27
-
28
32
  /**
29
33
  * @method getBrandId
30
34
  * @return {NodeId}
@@ -87,7 +91,7 @@ export interface ConditionSnapshot extends EventEmitter {
87
91
  * @method setComment
88
92
  * @param txtMessage {LocalizedText}
89
93
  */
90
- setComment(txtMessage: LocalizedTextLike): void;
94
+ setComment(txtMessage: LocalizedTextLike, options?: IConditionVariableTypeSetterOptions): void;
91
95
  /**
92
96
  *
93
97
  * @method setMessage
@@ -130,7 +134,7 @@ export interface ConditionSnapshot extends EventEmitter {
130
134
  * @method setQuality
131
135
  * @param quality {StatusCode}
132
136
  */
133
- setQuality(quality: StatusCode): void;
137
+ setQuality(quality: StatusCode, options?: IConditionVariableTypeSetterOptions): void;
134
138
  /**
135
139
  * @method getQuality
136
140
  * @return {StatusCode}
@@ -170,7 +174,7 @@ export interface ConditionSnapshot extends EventEmitter {
170
174
  * @method setSeverity
171
175
  * @param severity {UInt16}
172
176
  */
173
- setSeverity(severity: UInt16): void;
177
+ setSeverity(severity: UInt16, options?: IConditionVariableTypeSetterOptions): void;
174
178
 
175
179
  /**
176
180
  * @method getSeverity
@@ -189,7 +193,7 @@ export interface ConditionSnapshot extends EventEmitter {
189
193
  * @method setLastSeverity
190
194
  * @param severity {UInt16}
191
195
  */
192
- setLastSeverity(severity: UInt16): void;
196
+ setLastSeverity(severity: UInt16, options?: IConditionVariableTypeSetterOptions): void;
193
197
  /**
194
198
  * @method getLastSeverity
195
199
  * @return {UInt16}
@@ -0,0 +1,5 @@
1
+
2
+
3
+ export interface IConditionVariableTypeSetterOptions {
4
+ sourceTimestamp?: Date;
5
+ }
@@ -6,13 +6,15 @@ import { assert } from "node-opcua-assert";
6
6
  import { LocalizedText, LocalizedTextLike } from "node-opcua-data-model";
7
7
  import { minDate } from "node-opcua-basic-types";
8
8
  import { StatusCode, StatusCodes } from "node-opcua-status-code";
9
+ import { ISetStateOptions } from "../../source/interfaces/i_set_state_options";
9
10
  import { ConditionSnapshotImpl } from "./condition_snapshot_impl";
10
11
 
11
12
  export function _setAckedState(
12
13
  self: ConditionSnapshotImpl,
13
14
  requestedAckedState: boolean,
14
15
  conditionEventId?: Buffer,
15
- comment?: string | LocalizedText | LocalizedTextLike
16
+ comment?: string | LocalizedText | LocalizedTextLike,
17
+ options?: ISetStateOptions
16
18
  ): StatusCode {
17
19
  assert(self instanceof ConditionSnapshotImpl);
18
20
 
@@ -21,7 +23,7 @@ export function _setAckedState(
21
23
  if (ackedState && requestedAckedState) {
22
24
  return StatusCodes.BadConditionBranchAlreadyAcked;
23
25
  }
24
- self._set_twoStateVariable("AckedState", requestedAckedState,/* effective transition time will be now*/);
26
+ self._set_twoStateVariable("AckedState", requestedAckedState, options);
25
27
  return StatusCodes.Good;
26
28
  }
27
29
 
@@ -16,6 +16,7 @@ import { TimeZoneDataType } from "node-opcua-types";
16
16
  import { DataType, Variant } from "node-opcua-variant";
17
17
 
18
18
  import { ConditionSnapshot } from "../../source/interfaces/alarms_and_conditions/condition_snapshot";
19
+ import { IConditionVariableTypeSetterOptions } from "../../source/interfaces/i_condition_variable_type_setter_options";
19
20
  import { UtcTime } from "../../source/interfaces/state_machine/ua_state_machine_type";
20
21
  import { ISetStateOptions } from "../../source/interfaces/i_set_state_options";
21
22
  import { EventData } from "../event_data";
@@ -36,7 +37,6 @@ function _visit(self: any, node: BaseNode, prefix: string): void {
36
37
  for (const aggregate of aggregates) {
37
38
  if (aggregate.nodeClass === NodeClass.Variable) {
38
39
  const name = aggregate.browseName.toString();
39
-
40
40
  const key = prefix + name;
41
41
 
42
42
  // istanbul ignore next
@@ -65,7 +65,7 @@ function _installOnChangeEventHandlers(self: any, node: BaseNode, prefix: string
65
65
  for (const aggregate of aggregates) {
66
66
  if (aggregate.nodeClass === NodeClass.Variable) {
67
67
  const name = aggregate.browseName.toString();
68
-
68
+
69
69
  const key = prefix + name;
70
70
 
71
71
  // istanbul ignore next
@@ -92,7 +92,7 @@ function _ensure_condition_values_correctness(self: any, node: BaseNode, prefix:
92
92
  for (const aggregate of aggregates) {
93
93
  if (aggregate.nodeClass === NodeClass.Variable) {
94
94
  const name = aggregate.browseName.toString();
95
-
95
+
96
96
  const key = prefix + name;
97
97
 
98
98
  const snapshot_value = self._map[key].toString();
@@ -146,7 +146,6 @@ const _varTable = {
146
146
  Time: 1
147
147
  };
148
148
 
149
-
150
149
  type FullBrowsePath = string;
151
150
  export class ConditionSnapshotImpl extends EventEmitter implements ConditionSnapshot {
152
151
  public static normalizeName = normalizeName;
@@ -238,7 +237,7 @@ export class ConditionSnapshotImpl extends EventEmitter implements ConditionSnap
238
237
  return variant.value;
239
238
  }
240
239
 
241
- public _set_var(varName: string, dataType: DataType, value: unknown): void {
240
+ public _set_var(varName: string, dataType: DataType, value: unknown, options?: IConditionVariableTypeSetterOptions): void {
242
241
  const key = normalizeName(varName);
243
242
  // istanbul ignore next
244
243
  if (!Object.prototype.hasOwnProperty.call(this._map, key)) {
@@ -253,11 +252,21 @@ export class ConditionSnapshotImpl extends EventEmitter implements ConditionSnap
253
252
  value
254
253
  });
255
254
 
256
- if (this._map[key + ".SourceTimestamp"]) {
257
- this._map[key + ".SourceTimestamp"] = new Variant({
255
+ const sourceTimestamp = options?.sourceTimestamp || new Date();
256
+ const sourceTimestampKey = key + ".SourceTimestamp";
257
+ if (this._map[sourceTimestampKey]) {
258
+ // from spec 1.03 : 5.3 condition variables
259
+ // a condition VariableType has a sourceTimeStamp exposed property
260
+ // SourceTimestamp indicates the time of the last change of the Value of this ConditionVariable.
261
+ // It shall be the same time that would be returned from the Read Service inside the DataValue
262
+ // structure for the ConditionVariable Value Attribute.
263
+ const variant = new Variant({
258
264
  dataType: DataType.DateTime,
259
- value: new Date()
265
+ value: sourceTimestamp
260
266
  });
267
+ this._map[sourceTimestampKey] = variant;
268
+ const node = this._node_index[sourceTimestampKey];
269
+ this.emit("valueChanged", node, variant, { sourceTimestamp });
261
270
  }
262
271
 
263
272
  const variant = this._map[key];
@@ -268,7 +277,7 @@ export class ConditionSnapshotImpl extends EventEmitter implements ConditionSnap
268
277
  return;
269
278
  }
270
279
  assert(node.nodeClass === NodeClass.Variable);
271
- this.emit("value_changed", node, variant);
280
+ this.emit("valueChanged", node, variant, { sourceTimestamp });
272
281
  }
273
282
 
274
283
  /**
@@ -363,9 +372,9 @@ export class ConditionSnapshotImpl extends EventEmitter implements ConditionSnap
363
372
  * @method setComment
364
373
  * @param txtMessage {LocalizedText}
365
374
  */
366
- public setComment(txtMessage: LocalizedTextLike): void {
375
+ public setComment(txtMessage: LocalizedTextLike, options?: IConditionVariableTypeSetterOptions): void {
367
376
  const txtMessage1 = coerceLocalizedText(txtMessage);
368
- this._set_var("Comment", DataType.LocalizedText, txtMessage1);
377
+ this._set_var("Comment", DataType.LocalizedText, txtMessage1, options);
369
378
  }
370
379
 
371
380
  /**
@@ -416,8 +425,8 @@ export class ConditionSnapshotImpl extends EventEmitter implements ConditionSnap
416
425
  * @method setQuality
417
426
  * @param quality {StatusCode}
418
427
  */
419
- public setQuality(quality: StatusCode): void {
420
- this._set_var("Quality", DataType.StatusCode, quality);
428
+ public setQuality(quality: StatusCode, options?: IConditionVariableTypeSetterOptions): void {
429
+ this._set_var("Quality", DataType.StatusCode, quality, options);
421
430
  }
422
431
 
423
432
  /**
@@ -462,13 +471,15 @@ export class ConditionSnapshotImpl extends EventEmitter implements ConditionSnap
462
471
  * @method setSeverity
463
472
  * @param severity {UInt16}
464
473
  */
465
- public setSeverity(severity: UInt16): void {
474
+ public setSeverity(severity: UInt16, options?: IConditionVariableTypeSetterOptions): void {
466
475
  assert(isFinite(severity), "expecting a UInt16");
467
476
 
468
477
  // record automatically last severity
469
478
  const lastSeverity = this.getSeverity();
470
- this.setLastSeverity(lastSeverity);
471
- this._set_var("Severity", DataType.UInt16, severity);
479
+ const sourceTimestamp = this.getSeveritySourceTimestamp();
480
+ this.setLastSeverity(lastSeverity, { sourceTimestamp });
481
+
482
+ this._set_var("Severity", DataType.UInt16, severity, options);
472
483
  }
473
484
 
474
485
  /**
@@ -481,6 +492,10 @@ export class ConditionSnapshotImpl extends EventEmitter implements ConditionSnap
481
492
  const value = this._get_var("Severity");
482
493
  return +value;
483
494
  }
495
+ public getSeveritySourceTimestamp(): Date {
496
+ const c = this.condition as UAConditionImpl;
497
+ return c.severity.readValue().sourceTimestamp || new Date();
498
+ }
484
499
 
485
500
  /*
486
501
  * as per spec 1.0.3 - part 9:
@@ -493,9 +508,9 @@ export class ConditionSnapshotImpl extends EventEmitter implements ConditionSnap
493
508
  * @method setLastSeverity
494
509
  * @param severity {UInt16}
495
510
  */
496
- public setLastSeverity(severity: UInt16): void {
511
+ public setLastSeverity(severity: UInt16, options?: IConditionVariableTypeSetterOptions): void {
497
512
  severity = +severity;
498
- return this._set_var("LastSeverity", DataType.UInt16, severity);
513
+ return this._set_var("LastSeverity", DataType.UInt16, severity, options);
499
514
  }
500
515
 
501
516
  /**
@@ -527,8 +542,8 @@ export class ConditionSnapshotImpl extends EventEmitter implements ConditionSnap
527
542
  * @param time {Date} : UTCTime
528
543
  */
529
544
  public setReceiveTime(time: UtcTime): void {
530
- assert(time instanceof Date);
531
- return this._set_var("ReceiveTime", DataType.DateTime, time);
545
+ if (!(time instanceof Date)) { throw new Error("setReceiveTime expecting a Date")};
546
+ return this._set_var("ReceiveTime", DataType.DateTime, time, { sourceTimestamp: time });
532
547
  }
533
548
 
534
549
  /**
@@ -541,8 +556,7 @@ export class ConditionSnapshotImpl extends EventEmitter implements ConditionSnap
541
556
  * @param time {Date}
542
557
  */
543
558
  public setTime(time: Date): void {
544
- assert(time instanceof Date);
545
- return this._set_var("Time", DataType.DateTime, time);
559
+ return this._set_var("Time", DataType.DateTime, time, { sourceTimestamp: time });
546
560
  }
547
561
 
548
562
  /**
@@ -605,10 +619,9 @@ export class ConditionSnapshotImpl extends EventEmitter implements ConditionSnap
605
619
  return this._get_twoStateVariable("AckedState");
606
620
  }
607
621
 
608
- public setAckedState(ackedState: boolean): StatusCode {
622
+ public setAckedState(ackedState: boolean, options?: ISetStateOptions): StatusCode {
609
623
  ackedState = !!ackedState;
610
-
611
- return _setAckedState(this, ackedState);
624
+ return _setAckedState(this, ackedState, undefined, undefined, options);
612
625
  }
613
626
 
614
627
  public getConfirmedState(): boolean {
@@ -669,11 +682,30 @@ export class ConditionSnapshotImpl extends EventEmitter implements ConditionSnap
669
682
  return StatusCodes.Good;
670
683
  }
671
684
 
672
- // tslint:disable:no-empty
685
+ public setLatchedState(newLatchedState: boolean, options?: ISetStateOptions): StatusCode {
686
+ this._set_twoStateVariable("LatchedState", newLatchedState, options);
687
+ return StatusCodes.Good;
688
+ }
689
+ public getLatchedState(): boolean {
690
+ return this._get_twoStateVariable("LatchedState");
691
+ }
692
+ public setOutOfServiceState(newOutOfServiceState: boolean, options?: ISetStateOptions): StatusCode {
693
+ this._set_twoStateVariable("OutOfServiceState", newOutOfServiceState, options);
694
+ return StatusCodes.Good;
695
+ }
696
+ public getOutOfServiceState(): boolean {
697
+ return this._get_twoStateVariable("OutOfServiceState");
698
+ }
699
+ public setSilentState(newSilentState: boolean, options?: ISetStateOptions): StatusCode {
700
+ this._set_twoStateVariable("SilentState", newSilentState, options);
701
+ return StatusCodes.Good;
702
+ }
703
+ public getSilentState(): boolean {
704
+ return this._get_twoStateVariable("SilentState");
705
+ }
673
706
  public setShelvingState(): void {
674
- // todo
707
+ throw new Error("Method not implemented.");
675
708
  }
676
-
677
709
  public toString(): string {
678
710
  // public condition: any = null;
679
711
  // public eventData: any = null;
@@ -739,7 +771,8 @@ export class ConditionSnapshotImpl extends EventEmitter implements ConditionSnap
739
771
  assert(twoStateNode instanceof UATwoStateVariableImpl);
740
772
  twoStateNode.setValue(value as boolean, options);
741
773
  }
742
- this.emit("value_changed", node, variant);
774
+ const sourceTimestamp = options?.effectiveTransitionTime || new Date();
775
+ this.emit("valueChanged", node, variant, { sourceTimestamp });
743
776
  }
744
777
 
745
778
  protected _get_twoStateVariable(varName: string): any {
@@ -215,9 +215,8 @@ export class UAConditionImpl extends UABaseEventImpl implements UAConditionEx {
215
215
  // the implication of this convention is that interacting with the condition variable
216
216
  // shall be made by using branch0, any value change made
217
217
  // using the standard setValueFromSource mechanism will not be work properly.
218
- this._branch0.on("value_changed", (node: UAVariable, variant: Variant) => {
219
- assert(node.nodeClass === NodeClass.Variable);
220
- node.setValueFromSource(variant);
218
+ this._branch0.on("valueChanged", (node: UAVariable, variant: Variant, options: { sourceTimestamp: Date }) => {
219
+ node.setValueFromSource(variant, StatusCodes.Good, options.sourceTimestamp);
221
220
  });
222
221
  }
223
222
 
@@ -347,7 +346,7 @@ export class UAConditionImpl extends UABaseEventImpl implements UAConditionEx {
347
346
  * @param requestedEnabledState {Boolean}
348
347
  * @private
349
348
  */
350
- public setEnabledState(requestedEnabledState: boolean, options?:ISetStateOptions): StatusCode {
349
+ public setEnabledState(requestedEnabledState: boolean, options?: ISetStateOptions): StatusCode {
351
350
  return this._setEnabledState(requestedEnabledState, options);
352
351
  }
353
352
 
@@ -518,11 +517,11 @@ export class UAConditionImpl extends UABaseEventImpl implements UAConditionEx {
518
517
 
519
518
  if (Object.prototype.hasOwnProperty.call(conditionInfo, "severity") && conditionInfo.severity !== null) {
520
519
  assert(isFinite(conditionInfo.severity!));
521
- branch.setSeverity(conditionInfo.severity!);
520
+ branch.setSeverity(conditionInfo.severity!, { sourceTimestamp: time });
522
521
  }
523
522
  if (Object.prototype.hasOwnProperty.call(conditionInfo, "quality") && conditionInfo.quality !== null) {
524
523
  assert(conditionInfo.quality instanceof StatusCode);
525
- branch.setQuality(conditionInfo.quality!);
524
+ branch.setQuality(conditionInfo.quality!, { sourceTimestamp: time });
526
525
  }
527
526
  if (Object.prototype.hasOwnProperty.call(conditionInfo, "retain") && conditionInfo.retain !== null) {
528
527
  assert(typeof conditionInfo.retain === "boolean");
@@ -1209,12 +1208,6 @@ function _create_new_branch_id() {
1209
1208
  return makeNodeId(randomGuid(), 1);
1210
1209
  }
1211
1210
 
1212
- function _update_sourceTimestamp<T, DT extends DataType>(this: UAConditionVariable<T, DT>, dataValue: DataValue /*, indexRange*/) {
1213
- this.sourceTimestamp.setValueFromSource({
1214
- dataType: DataType.DateTime,
1215
- value: dataValue.sourceTimestamp
1216
- });
1217
- }
1218
1211
 
1219
1212
  // tslint:disable:no-console
1220
1213
  function _install_condition_variable_type<T, DT extends DataType>(node: UAConditionVariable<T, DT>) {
@@ -1228,15 +1221,6 @@ function _install_condition_variable_type<T, DT extends DataType>(node: UACondit
1228
1221
  }
1229
1222
  node.accessLevel = makeAccessLevelFlag("CurrentRead");
1230
1223
 
1231
- // from spec 1.03 : 5.3 condition variables
1232
- // a condition VariableType has a sourceTimeStamp exposed property
1233
- // SourceTimestamp indicates the time of the last change of the Value of this ConditionVariable.
1234
- // It shall be the same time that would be returned from the Read Service inside the DataValue
1235
- // structure for the ConditionVariable Value Attribute.
1236
-
1237
- assert(node.typeDefinitionObj.browseName.toString() === "ConditionVariableType");
1238
- assert(node.sourceTimestamp.browseName.toString() === "SourceTimestamp");
1239
- node.on("value_changed", _update_sourceTimestamp);
1240
1224
  }
1241
1225
 
1242
1226
  /**