node-opcua-server 2.53.0 → 2.56.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/LICENSE +20 -20
- package/dist/base_server.js +12 -14
- package/dist/base_server.js.map +1 -1
- package/dist/factory.d.ts +4 -2
- package/dist/factory.js.map +1 -1
- package/dist/history_server_capabilities.js.map +1 -1
- package/dist/i_server_side_publish_engine.d.ts +1 -1
- package/dist/i_server_side_publish_engine.js +1 -1
- package/dist/i_server_side_publish_engine.js.map +1 -1
- package/dist/monitored_item.d.ts +3 -0
- package/dist/monitored_item.js +7 -14
- package/dist/monitored_item.js.map +1 -1
- package/dist/node_sampler.js +1 -1
- package/dist/node_sampler.js.map +1 -1
- package/dist/opcua_server.d.ts +29 -44
- package/dist/opcua_server.js +218 -262
- package/dist/opcua_server.js.map +1 -1
- package/dist/queue.js +1 -0
- package/dist/queue.js.map +1 -1
- package/dist/register_server_manager.d.ts +4 -1
- package/dist/register_server_manager.js +5 -5
- package/dist/register_server_manager.js.map +1 -1
- package/dist/register_server_manager_hidden.d.ts +1 -1
- package/dist/register_server_manager_hidden.js.map +1 -1
- package/dist/register_server_manager_mdns_only.d.ts +4 -1
- package/dist/register_server_manager_mdns_only.js +1 -1
- package/dist/register_server_manager_mdns_only.js.map +1 -1
- package/dist/server_capabilities.js.map +1 -1
- package/dist/server_end_point.d.ts +4 -1
- package/dist/server_end_point.js +10 -11
- package/dist/server_end_point.js.map +1 -1
- package/dist/server_engine.d.ts +11 -7
- package/dist/server_engine.js +72 -74
- package/dist/server_engine.js.map +1 -1
- package/dist/server_publish_engine.d.ts +4 -1
- package/dist/server_publish_engine.js +5 -5
- package/dist/server_publish_engine.js.map +1 -1
- package/dist/server_publish_engine_for_orphan_subscriptions.d.ts +2 -2
- package/dist/server_publish_engine_for_orphan_subscriptions.js.map +1 -1
- package/dist/server_session.d.ts +1 -1
- package/dist/server_session.js +24 -29
- package/dist/server_session.js.map +1 -1
- package/dist/server_subscription.d.ts +3 -1
- package/dist/server_subscription.js +6 -6
- package/dist/server_subscription.js.map +1 -1
- package/dist/sessions_compatible_for_transfer.js +2 -1
- package/dist/sessions_compatible_for_transfer.js.map +1 -1
- package/dist/validate_filter.js +4 -7
- package/dist/validate_filter.js.map +1 -1
- package/package.json +45 -44
- package/source/base_server.ts +19 -22
- package/source/factory.ts +5 -2
- package/source/history_server_capabilities.ts +3 -4
- package/source/i_channel_data.ts +4 -8
- package/source/i_register_server_manager.ts +0 -3
- package/source/i_server_side_publish_engine.ts +5 -6
- package/source/i_socket_data.ts +1 -1
- package/source/index.ts +14 -14
- package/source/monitored_item.ts +32 -44
- package/source/node_sampler.ts +82 -82
- package/source/opcua_server.ts +326 -357
- package/source/queue.ts +6 -7
- package/source/register_server_manager.ts +35 -23
- package/source/register_server_manager_hidden.ts +8 -10
- package/source/register_server_manager_mdns_only.ts +8 -13
- package/source/server_capabilities.ts +0 -5
- package/source/server_end_point.ts +28 -30
- package/source/server_engine.ts +122 -122
- package/source/server_publish_engine.ts +24 -21
- package/source/server_publish_engine_for_orphan_subscriptions.ts +26 -26
- package/source/server_session.ts +44 -49
- package/source/server_subscription.ts +23 -23
- package/source/sessions_compatible_for_transfer.ts +26 -25
- package/source/validate_filter.ts +8 -22
- package/test_helpers/create_certificates.js +1 -1
package/source/base_server.ts
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* @module node-opcua-server
|
|
3
3
|
*/
|
|
4
4
|
// tslint:disable:no-console
|
|
5
|
-
import * as async from "async";
|
|
6
|
-
import * as chalk from "chalk";
|
|
7
5
|
import * as fs from "fs";
|
|
8
6
|
import * as path from "path";
|
|
9
7
|
import * as os from "os";
|
|
8
|
+
import * as async from "async";
|
|
9
|
+
import * as chalk from "chalk";
|
|
10
10
|
import { withLock } from "@ster5/global-mutex";
|
|
11
11
|
import { assert } from "node-opcua-assert";
|
|
12
12
|
import {
|
|
@@ -31,10 +31,10 @@ import { ApplicationDescriptionOptions } from "node-opcua-types";
|
|
|
31
31
|
import { EndpointDescription, GetEndpointsRequest } from "node-opcua-types";
|
|
32
32
|
import { matchUri } from "node-opcua-utils";
|
|
33
33
|
|
|
34
|
+
import { performCertificateSanityCheck } from "node-opcua-client";
|
|
34
35
|
import { OPCUAServerEndPoint } from "./server_end_point";
|
|
35
36
|
import { IChannelData } from "./i_channel_data";
|
|
36
37
|
import { ISocketData } from "./i_socket_data";
|
|
37
|
-
import { performCertificateSanityCheck } from "node-opcua-client";
|
|
38
38
|
|
|
39
39
|
const doDebug = checkDebugFlag(__filename);
|
|
40
40
|
const debugLog = make_debugLog(__filename);
|
|
@@ -175,9 +175,7 @@ export class OPCUABaseServer extends OPCUASecureObject {
|
|
|
175
175
|
|
|
176
176
|
const __applicationUri = serverInfo.applicationUri || "";
|
|
177
177
|
|
|
178
|
-
(this.serverInfo as any).__defineGetter__("applicationUri",
|
|
179
|
-
return resolveFullyQualifiedDomainName(__applicationUri);
|
|
180
|
-
});
|
|
178
|
+
(this.serverInfo as any).__defineGetter__("applicationUri", () => resolveFullyQualifiedDomainName(__applicationUri));
|
|
181
179
|
|
|
182
180
|
this._preInitTask.push(async () => {
|
|
183
181
|
const fqdn = await extractFullyQualifiedDomainName();
|
|
@@ -188,7 +186,7 @@ export class OPCUABaseServer extends OPCUASecureObject {
|
|
|
188
186
|
});
|
|
189
187
|
}
|
|
190
188
|
|
|
191
|
-
protected async createDefaultCertificate() {
|
|
189
|
+
protected async createDefaultCertificate(): Promise<void> {
|
|
192
190
|
if (fs.existsSync(this.certificateFile)) {
|
|
193
191
|
return;
|
|
194
192
|
}
|
|
@@ -225,7 +223,7 @@ export class OPCUABaseServer extends OPCUASecureObject {
|
|
|
225
223
|
* @async
|
|
226
224
|
* @param {callback} done
|
|
227
225
|
*/
|
|
228
|
-
public start(done: (err?: Error | null) => void) {
|
|
226
|
+
public start(done: (err?: Error | null) => void): void {
|
|
229
227
|
assert(typeof done === "function");
|
|
230
228
|
this.startAsync()
|
|
231
229
|
.then(() => done(null))
|
|
@@ -243,22 +241,22 @@ export class OPCUABaseServer extends OPCUASecureObject {
|
|
|
243
241
|
protected async startAsync(): Promise<void> {
|
|
244
242
|
await this.performPreInitialization();
|
|
245
243
|
|
|
246
|
-
const self = this;
|
|
247
244
|
assert(Array.isArray(this.endpoints));
|
|
248
245
|
assert(this.endpoints.length > 0, "We need at least one end point");
|
|
249
246
|
|
|
250
247
|
installPeriodicClockAdjustment();
|
|
251
|
-
|
|
248
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
249
|
+
const server = this;
|
|
252
250
|
const _on_new_channel = function (this: OPCUAServerEndPoint, channel: ServerSecureChannelLayer) {
|
|
253
|
-
|
|
251
|
+
server.emit("newChannel", channel, this);
|
|
254
252
|
};
|
|
255
253
|
|
|
256
254
|
const _on_close_channel = function (this: OPCUAServerEndPoint, channel: ServerSecureChannelLayer) {
|
|
257
|
-
|
|
255
|
+
server.emit("closeChannel", channel, this);
|
|
258
256
|
};
|
|
259
257
|
|
|
260
258
|
const _on_connectionRefused = function (this: OPCUAServerEndPoint, socketData: ISocketData) {
|
|
261
|
-
|
|
259
|
+
server.emit("connectionRefused", socketData, this);
|
|
262
260
|
};
|
|
263
261
|
|
|
264
262
|
const _on_openSecureChannelFailure = function (
|
|
@@ -266,7 +264,7 @@ export class OPCUABaseServer extends OPCUASecureObject {
|
|
|
266
264
|
socketData: ISocketData,
|
|
267
265
|
channelData: IChannelData
|
|
268
266
|
) {
|
|
269
|
-
|
|
267
|
+
server.emit("openSecureChannelFailure", socketData, channelData, this);
|
|
270
268
|
};
|
|
271
269
|
|
|
272
270
|
const promises: Promise<void>[] = [];
|
|
@@ -295,7 +293,7 @@ export class OPCUABaseServer extends OPCUASecureObject {
|
|
|
295
293
|
* shutdown all server endPoints
|
|
296
294
|
* @async
|
|
297
295
|
*/
|
|
298
|
-
public shutdown(done: (err?: Error) => void) {
|
|
296
|
+
public shutdown(done: (err?: Error) => void): void {
|
|
299
297
|
assert(typeof done === "function");
|
|
300
298
|
uninstallPeriodicClockAdjustment();
|
|
301
299
|
this.serverCertificateManager.dispose().then(() => {
|
|
@@ -346,7 +344,7 @@ export class OPCUABaseServer extends OPCUASecureObject {
|
|
|
346
344
|
/**
|
|
347
345
|
* @private
|
|
348
346
|
*/
|
|
349
|
-
public on_request(message: Message, channel: ServerSecureChannelLayer) {
|
|
347
|
+
public on_request(message: Message, channel: ServerSecureChannelLayer): void {
|
|
350
348
|
assert(message.request);
|
|
351
349
|
assert(message.requestId !== 0);
|
|
352
350
|
const request = message.request;
|
|
@@ -378,6 +376,7 @@ export class OPCUABaseServer extends OPCUASecureObject {
|
|
|
378
376
|
// handler must be named _on_ActionRequest()
|
|
379
377
|
const handler = (this as any)["_on_" + request.schema.name];
|
|
380
378
|
if (typeof handler === "function") {
|
|
379
|
+
// eslint-disable-next-line prefer-rest-params
|
|
381
380
|
handler.apply(this, arguments);
|
|
382
381
|
} else {
|
|
383
382
|
errMessage = "[NODE-OPCUA-W07] Unsupported Service : " + request.schema.name;
|
|
@@ -497,15 +496,14 @@ export class OPCUABaseServer extends OPCUASecureObject {
|
|
|
497
496
|
/**
|
|
498
497
|
* @private
|
|
499
498
|
*/
|
|
500
|
-
protected _on_GetEndpointsRequest(message: Message, channel: ServerSecureChannelLayer) {
|
|
501
|
-
const server = this;
|
|
499
|
+
protected _on_GetEndpointsRequest(message: Message, channel: ServerSecureChannelLayer): void {
|
|
502
500
|
const request = message.request as GetEndpointsRequest;
|
|
503
501
|
|
|
504
502
|
assert(request.schema.name === "GetEndpointsRequest");
|
|
505
503
|
|
|
506
504
|
const response = new GetEndpointsResponse({});
|
|
507
505
|
|
|
508
|
-
response.endpoints =
|
|
506
|
+
response.endpoints = this._get_endpoints(null);
|
|
509
507
|
|
|
510
508
|
response.endpoints = response.endpoints.filter((endpoint: EndpointDescription) => !(endpoint as any).restricted);
|
|
511
509
|
|
|
@@ -529,8 +527,7 @@ export class OPCUABaseServer extends OPCUASecureObject {
|
|
|
529
527
|
/**
|
|
530
528
|
* @private
|
|
531
529
|
*/
|
|
532
|
-
protected _on_FindServersRequest(message: Message, channel: ServerSecureChannelLayer) {
|
|
533
|
-
const server = this;
|
|
530
|
+
protected _on_FindServersRequest(message: Message, channel: ServerSecureChannelLayer): void {
|
|
534
531
|
// Release 1.02 13 OPC Unified Architecture, Part 4 :
|
|
535
532
|
// This Service can be used without security and it is therefore vulnerable to Denial Of Service (DOS)
|
|
536
533
|
// attacks. A Server should minimize the amount of processing required to send the response for this
|
|
@@ -545,7 +542,7 @@ export class OPCUABaseServer extends OPCUASecureObject {
|
|
|
545
542
|
throw new Error("Invalid request type");
|
|
546
543
|
}
|
|
547
544
|
|
|
548
|
-
let servers =
|
|
545
|
+
let servers = this.getServers(channel);
|
|
549
546
|
// apply filters
|
|
550
547
|
// TODO /
|
|
551
548
|
if (request.serverUris && request.serverUris.length > 0) {
|
package/source/factory.ts
CHANGED
|
@@ -7,10 +7,13 @@ import { ExtensionObject } from "node-opcua-extension-object";
|
|
|
7
7
|
import { constructObject } from "node-opcua-factory";
|
|
8
8
|
import { ExpandedNodeId } from "node-opcua-nodeid";
|
|
9
9
|
|
|
10
|
+
export interface EngineForFactory {
|
|
11
|
+
/** */
|
|
12
|
+
}
|
|
10
13
|
export class Factory {
|
|
11
|
-
public engine:
|
|
14
|
+
public engine: EngineForFactory;
|
|
12
15
|
|
|
13
|
-
constructor(engine:
|
|
16
|
+
constructor(engine: EngineForFactory) {
|
|
14
17
|
assert(engine !== null && typeof engine === "object");
|
|
15
18
|
this.engine = engine;
|
|
16
19
|
}
|
|
@@ -11,7 +11,7 @@ export interface HistoryServerCapabilitiesOptions {
|
|
|
11
11
|
insertDataCapability?: boolean;
|
|
12
12
|
replaceDataCapability?: boolean;
|
|
13
13
|
updateDataCapability?: boolean;
|
|
14
|
-
deleteRawCapability
|
|
14
|
+
deleteRawCapability?: boolean;
|
|
15
15
|
deleteAtTimeCapability?: boolean;
|
|
16
16
|
insertEventCapability?: boolean;
|
|
17
17
|
replaceEventCapability?: boolean;
|
|
@@ -22,7 +22,6 @@ export interface HistoryServerCapabilitiesOptions {
|
|
|
22
22
|
/**
|
|
23
23
|
*/
|
|
24
24
|
export class HistoryServerCapabilities {
|
|
25
|
-
|
|
26
25
|
public accessHistoryDataCapability: boolean;
|
|
27
26
|
public accessHistoryEventsCapability: boolean;
|
|
28
27
|
public maxReturnDataValues: number;
|
|
@@ -41,7 +40,7 @@ export class HistoryServerCapabilities {
|
|
|
41
40
|
constructor(options?: HistoryServerCapabilitiesOptions) {
|
|
42
41
|
options = options || {};
|
|
43
42
|
|
|
44
|
-
function coerceBool(value: boolean | undefined
|
|
43
|
+
function coerceBool(value: boolean | undefined, defaultValue: boolean): boolean {
|
|
45
44
|
if (undefined === value) {
|
|
46
45
|
return defaultValue;
|
|
47
46
|
}
|
|
@@ -49,7 +48,7 @@ export class HistoryServerCapabilities {
|
|
|
49
48
|
return value as boolean;
|
|
50
49
|
}
|
|
51
50
|
|
|
52
|
-
function coerceUInt32(value: number| undefined, defaultValue: number): number {
|
|
51
|
+
function coerceUInt32(value: number | undefined, defaultValue: number): number {
|
|
53
52
|
if (undefined === value) {
|
|
54
53
|
return defaultValue;
|
|
55
54
|
}
|
package/source/i_channel_data.ts
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AsymmetricAlgorithmSecurityHeader,
|
|
3
|
-
MessageSecurityMode,
|
|
4
|
-
SecurityPolicy
|
|
5
|
-
} from "node-opcua-secure-channel";
|
|
1
|
+
import { AsymmetricAlgorithmSecurityHeader, MessageSecurityMode, SecurityPolicy } from "node-opcua-secure-channel";
|
|
6
2
|
|
|
7
3
|
export interface IChannelData {
|
|
8
|
-
channelId: number| null;
|
|
4
|
+
channelId: number | null;
|
|
9
5
|
clientCertificate: Buffer | null;
|
|
10
|
-
clientNonce: Buffer |null
|
|
6
|
+
clientNonce: Buffer | null;
|
|
11
7
|
clientSecurityHeader: any;
|
|
12
|
-
securityHeader: AsymmetricAlgorithmSecurityHeader |null;
|
|
8
|
+
securityHeader: AsymmetricAlgorithmSecurityHeader | null;
|
|
13
9
|
securityMode: MessageSecurityMode;
|
|
14
10
|
securityPolicy: SecurityPolicy;
|
|
15
11
|
timeout: number;
|
|
@@ -4,9 +4,7 @@
|
|
|
4
4
|
import { EventEmitter } from "events";
|
|
5
5
|
import { ErrorCallback } from "node-opcua-status-code";
|
|
6
6
|
|
|
7
|
-
|
|
8
7
|
export interface IRegisterServerManager extends EventEmitter {
|
|
9
|
-
|
|
10
8
|
discoveryServerEndpointUrl: string;
|
|
11
9
|
|
|
12
10
|
start(callback: ErrorCallback): void;
|
|
@@ -20,5 +18,4 @@ export interface IRegisterServerManager extends EventEmitter {
|
|
|
20
18
|
on(eventName: "serverRegistered", eventHandler: () => void): this;
|
|
21
19
|
on(eventName: "serverRegistrationRenewed", eventHandler: () => void): this;
|
|
22
20
|
on(eventName: "serverUnregistered", eventHandler: () => void): this;
|
|
23
|
-
|
|
24
21
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { Subscription, InternalNotification } from "./server_subscription";
|
|
2
1
|
import { PublishResponseOptions, PublishResponse, StatusChangeNotification } from "node-opcua-types";
|
|
3
2
|
import assert from "node-opcua-assert";
|
|
4
|
-
import {
|
|
3
|
+
import { Subscription } from "./server_subscription";
|
|
5
4
|
|
|
6
5
|
export interface INotifMsg {
|
|
7
6
|
subscriptionId: number;
|
|
@@ -38,7 +37,7 @@ export class TransferredSubscription implements IClosedOrTransferredSubscription
|
|
|
38
37
|
return !!this._pending_notification;
|
|
39
38
|
}
|
|
40
39
|
dispose(): void {
|
|
41
|
-
this._pending_notification= undefined;
|
|
40
|
+
this._pending_notification = undefined;
|
|
42
41
|
this.publishEngine = null;
|
|
43
42
|
}
|
|
44
43
|
_publish_pending_notifications(): void {
|
|
@@ -51,13 +50,13 @@ export class TransferredSubscription implements IClosedOrTransferredSubscription
|
|
|
51
50
|
const response = new PublishResponse({
|
|
52
51
|
moreNotifications,
|
|
53
52
|
notificationMessage: {
|
|
54
|
-
notificationData: [notificationMessage
|
|
53
|
+
notificationData: [notificationMessage],
|
|
55
54
|
publishTime: new Date(),
|
|
56
|
-
sequenceNumber:
|
|
55
|
+
sequenceNumber: 0xffffffff
|
|
57
56
|
},
|
|
58
57
|
subscriptionId
|
|
59
58
|
});
|
|
60
|
-
|
|
59
|
+
|
|
61
60
|
// apply sequence number and store in sent_notifications queue
|
|
62
61
|
assert(response.notificationMessage.sequenceNumber === 0xffffffff);
|
|
63
62
|
response.notificationMessage.sequenceNumber = this._get_next_sequence_number();
|
package/source/i_socket_data.ts
CHANGED
package/source/index.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module node-opcua-server
|
|
3
|
-
*/
|
|
4
|
-
export * from "./base_server";
|
|
5
|
-
export * from "./server_end_point";
|
|
6
|
-
export * from "./register_server_manager";
|
|
7
|
-
export * from "./register_server_manager_mdns_only";
|
|
8
|
-
export * from "./server_publish_engine";
|
|
9
|
-
export * from "./server_subscription";
|
|
10
|
-
export * from "./server_session";
|
|
11
|
-
export * from "./server_capabilities";
|
|
12
|
-
export * from "./server_engine";
|
|
13
|
-
export * from "./opcua_server";
|
|
14
|
-
export * from "./monitored_item";
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-server
|
|
3
|
+
*/
|
|
4
|
+
export * from "./base_server";
|
|
5
|
+
export * from "./server_end_point";
|
|
6
|
+
export * from "./register_server_manager";
|
|
7
|
+
export * from "./register_server_manager_mdns_only";
|
|
8
|
+
export * from "./server_publish_engine";
|
|
9
|
+
export * from "./server_subscription";
|
|
10
|
+
export * from "./server_session";
|
|
11
|
+
export * from "./server_capabilities";
|
|
12
|
+
export * from "./server_engine";
|
|
13
|
+
export * from "./opcua_server";
|
|
14
|
+
export * from "./monitored_item";
|
package/source/monitored_item.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module node-opcua-server
|
|
3
3
|
*/
|
|
4
|
-
// tslint:disable:no-console
|
|
5
|
-
import * as chalk from "chalk";
|
|
6
4
|
import { EventEmitter } from "events";
|
|
5
|
+
import * as chalk from "chalk";
|
|
7
6
|
import { assert } from "node-opcua-assert";
|
|
8
|
-
|
|
9
7
|
import {
|
|
10
8
|
BaseNode,
|
|
11
9
|
IEventData,
|
|
@@ -102,8 +100,8 @@ function _adjust_queue_size(queueSize: number): number {
|
|
|
102
100
|
|
|
103
101
|
function _validate_parameters(monitoringParameters: any) {
|
|
104
102
|
// xx assert(options instanceof MonitoringParameters);
|
|
105
|
-
assert(
|
|
106
|
-
assert(
|
|
103
|
+
assert(Object.prototype.hasOwnProperty.call(monitoringParameters, "clientHandle"));
|
|
104
|
+
assert(Object.prototype.hasOwnProperty.call(monitoringParameters, "samplingInterval"));
|
|
107
105
|
assert(isFinite(monitoringParameters.clientHandle));
|
|
108
106
|
assert(isFinite(monitoringParameters.samplingInterval));
|
|
109
107
|
assert(typeof monitoringParameters.discardOldest === "boolean");
|
|
@@ -135,7 +133,7 @@ function valueHasChanged(
|
|
|
135
133
|
case DeadbandType.Absolute:
|
|
136
134
|
// AbsoluteDeadband
|
|
137
135
|
return isOutsideDeadbandAbsolute(oldDataValue.value, newDataValue.value, deadbandValue);
|
|
138
|
-
default:
|
|
136
|
+
default: {
|
|
139
137
|
// Percent_2 PercentDeadband (This type is specified in Part 8).
|
|
140
138
|
assert(deadbandType === DeadbandType.Percent);
|
|
141
139
|
|
|
@@ -172,6 +170,7 @@ function valueHasChanged(
|
|
|
172
170
|
console.log("EURange is not of type Variable");
|
|
173
171
|
}
|
|
174
172
|
return true;
|
|
173
|
+
}
|
|
175
174
|
}
|
|
176
175
|
}
|
|
177
176
|
|
|
@@ -258,7 +257,6 @@ function apply_dataChange_filter(this: MonitoredItem, newDataValue: DataValue, o
|
|
|
258
257
|
);
|
|
259
258
|
}
|
|
260
259
|
}
|
|
261
|
-
return false;
|
|
262
260
|
}
|
|
263
261
|
|
|
264
262
|
function apply_filter(this: MonitoredItem, newDataValue: DataValue) {
|
|
@@ -274,11 +272,6 @@ function apply_filter(this: MonitoredItem, newDataValue: DataValue) {
|
|
|
274
272
|
}
|
|
275
273
|
return !sameVariant(newDataValue.value, this.oldDataValue.value);
|
|
276
274
|
}
|
|
277
|
-
return true; // keep
|
|
278
|
-
// else {
|
|
279
|
-
// return !sameDataValue(newDataValue, this.oldDataValue, TimestampsToReturn.Neither);
|
|
280
|
-
// }
|
|
281
|
-
// return true; // keep
|
|
282
275
|
}
|
|
283
276
|
|
|
284
277
|
function setSemanticChangeBit(notification: QueueItem | DataValue): void {
|
|
@@ -377,7 +370,7 @@ export class MonitoredItem extends EventEmitter {
|
|
|
377
370
|
public static defaultSamplingInterval = 1500; // 1500 ms as a default sampling interval
|
|
378
371
|
public static maximumSamplingInterval = 1000 * 60 * 60; // 1 hour !
|
|
379
372
|
|
|
380
|
-
public samplingInterval
|
|
373
|
+
public samplingInterval = -1;
|
|
381
374
|
public monitoredItemId: number;
|
|
382
375
|
public overflow: boolean;
|
|
383
376
|
public oldDataValue?: DataValue;
|
|
@@ -385,8 +378,8 @@ export class MonitoredItem extends EventEmitter {
|
|
|
385
378
|
public timestampsToReturn: TimestampsToReturn;
|
|
386
379
|
public itemToMonitor: any;
|
|
387
380
|
public filter: MonitoringFilter | null;
|
|
388
|
-
public discardOldest
|
|
389
|
-
public queueSize
|
|
381
|
+
public discardOldest = true;
|
|
382
|
+
public queueSize = 0;
|
|
390
383
|
public clientHandle: UInt32;
|
|
391
384
|
public $subscription?: ISubscription;
|
|
392
385
|
public _samplingId?: TimerKey | string;
|
|
@@ -397,7 +390,7 @@ export class MonitoredItem extends EventEmitter {
|
|
|
397
390
|
private _node: BaseNode | null;
|
|
398
391
|
private queue: QueueItem[];
|
|
399
392
|
private _semantic_version: number;
|
|
400
|
-
private _is_sampling
|
|
393
|
+
private _is_sampling = false;
|
|
401
394
|
private _on_opcua_event_received_callback: any;
|
|
402
395
|
private _attribute_changed_callback: any;
|
|
403
396
|
private _value_changed_callback: any;
|
|
@@ -409,13 +402,13 @@ export class MonitoredItem extends EventEmitter {
|
|
|
409
402
|
constructor(options: MonitoredItemOptions) {
|
|
410
403
|
super();
|
|
411
404
|
|
|
412
|
-
assert(Object.prototype.hasOwnProperty.call(options,"monitoredItemId"));
|
|
405
|
+
assert(Object.prototype.hasOwnProperty.call(options, "monitoredItemId"));
|
|
413
406
|
assert(!options.monitoringMode, "use setMonitoring mode explicitly to activate the monitored item");
|
|
414
407
|
|
|
415
408
|
options.itemToMonitor = options.itemToMonitor || defaultItemToMonitor;
|
|
416
409
|
|
|
417
410
|
this._samplingId = undefined;
|
|
418
|
-
this.clientHandle = 0; // invalid
|
|
411
|
+
this.clientHandle = 0; // invalid
|
|
419
412
|
this.filter = null;
|
|
420
413
|
this._set_parameters(options);
|
|
421
414
|
|
|
@@ -445,7 +438,7 @@ export class MonitoredItem extends EventEmitter {
|
|
|
445
438
|
MonitoredItem.registry.register(this);
|
|
446
439
|
}
|
|
447
440
|
|
|
448
|
-
public setNode(node: BaseNode) {
|
|
441
|
+
public setNode(node: BaseNode): void {
|
|
449
442
|
assert(!this.node || this.node === node, "node already set");
|
|
450
443
|
this._node = node;
|
|
451
444
|
this._semantic_version = (node as any).semantic_version;
|
|
@@ -453,7 +446,7 @@ export class MonitoredItem extends EventEmitter {
|
|
|
453
446
|
this._node.on("dispose", this._on_node_disposed_listener);
|
|
454
447
|
}
|
|
455
448
|
|
|
456
|
-
public setMonitoringMode(monitoringMode: MonitoringMode) {
|
|
449
|
+
public setMonitoringMode(monitoringMode: MonitoringMode): void {
|
|
457
450
|
assert(monitoringMode !== MonitoringMode.Invalid);
|
|
458
451
|
|
|
459
452
|
if (monitoringMode === this.monitoringMode) {
|
|
@@ -492,12 +485,11 @@ export class MonitoredItem extends EventEmitter {
|
|
|
492
485
|
*
|
|
493
486
|
* This will stop the internal sampling timer.
|
|
494
487
|
*/
|
|
495
|
-
public terminate() {
|
|
488
|
+
public terminate(): void {
|
|
496
489
|
this._stop_sampling();
|
|
497
490
|
}
|
|
498
491
|
|
|
499
|
-
|
|
500
|
-
public dispose() {
|
|
492
|
+
public dispose(): void {
|
|
501
493
|
if (doDebug) {
|
|
502
494
|
debugLog("DISPOSING MONITORED ITEM", this._node!.nodeId.toString());
|
|
503
495
|
}
|
|
@@ -563,7 +555,7 @@ export class MonitoredItem extends EventEmitter {
|
|
|
563
555
|
* of the contain at the time recordValue was called.
|
|
564
556
|
*
|
|
565
557
|
*/
|
|
566
|
-
public recordValue(dataValue: DataValue, skipChangeTest: boolean, indexRange?: NumericRange) {
|
|
558
|
+
public recordValue(dataValue: DataValue, skipChangeTest: boolean, indexRange?: NumericRange): void {
|
|
567
559
|
assert(dataValue instanceof DataValue);
|
|
568
560
|
assert(dataValue !== this.oldDataValue, "recordValue expects different dataValue to be provided");
|
|
569
561
|
|
|
@@ -615,7 +607,6 @@ export class MonitoredItem extends EventEmitter {
|
|
|
615
607
|
setSemanticChangeBit(dataValue);
|
|
616
608
|
this._semantic_version = (this.node as UAVariable).semantic_version;
|
|
617
609
|
return this._enqueue_value(dataValue);
|
|
618
|
-
debugLog("_enqueue_value => because hasSemanticChanged 2");
|
|
619
610
|
}
|
|
620
611
|
|
|
621
612
|
const useIndexRange = this.itemToMonitor.indexRange && !this.itemToMonitor.indexRange.isEmpty();
|
|
@@ -726,14 +717,11 @@ export class MonitoredItem extends EventEmitter {
|
|
|
726
717
|
setImmediate(() => {
|
|
727
718
|
this._triggeredNotifications = this._triggeredNotifications || [];
|
|
728
719
|
const notifications = this.extractMonitoredItemNotifications(true);
|
|
729
|
-
this._triggeredNotifications = ([] as QueueItem[]).concat(
|
|
730
|
-
this._triggeredNotifications!,
|
|
731
|
-
notifications
|
|
732
|
-
);
|
|
720
|
+
this._triggeredNotifications = ([] as QueueItem[]).concat(this._triggeredNotifications!, notifications);
|
|
733
721
|
});
|
|
734
722
|
}
|
|
735
723
|
|
|
736
|
-
public extractMonitoredItemNotifications(bForce
|
|
724
|
+
public extractMonitoredItemNotifications(bForce = false): QueueItem[] {
|
|
737
725
|
if (!bForce && this.monitoringMode === MonitoringMode.Sampling && this._triggeredNotifications) {
|
|
738
726
|
const notifications1 = this._triggeredNotifications;
|
|
739
727
|
this._triggeredNotifications = undefined;
|
|
@@ -1029,13 +1017,13 @@ export class MonitoredItem extends EventEmitter {
|
|
|
1029
1017
|
// initiate first read
|
|
1030
1018
|
if (recordInitialValue) {
|
|
1031
1019
|
/* await */ new Promise<void>((resolve: () => void) => {
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1020
|
+
(this.node as UAVariable).readValueAsync(context, (err: Error | null, dataValue?: DataValue) => {
|
|
1021
|
+
if (!err && dataValue) {
|
|
1022
|
+
this.recordValue(dataValue, true);
|
|
1023
|
+
}
|
|
1024
|
+
resolve();
|
|
1025
|
+
});
|
|
1037
1026
|
});
|
|
1038
|
-
});
|
|
1039
1027
|
}
|
|
1040
1028
|
} else {
|
|
1041
1029
|
this._set_timer();
|
|
@@ -1051,9 +1039,9 @@ export class MonitoredItem extends EventEmitter {
|
|
|
1051
1039
|
_validate_parameters(monitoredParameters);
|
|
1052
1040
|
// only change clientHandle if it is valid (0<X<MAX)
|
|
1053
1041
|
if (monitoredParameters.clientHandle !== 0 && monitoredParameters.clientHandle !== 4294967295) {
|
|
1054
|
-
|
|
1042
|
+
this.clientHandle = monitoredParameters.clientHandle;
|
|
1055
1043
|
}
|
|
1056
|
-
|
|
1044
|
+
|
|
1057
1045
|
// The Server may support data that is collected based on a sampling model or generated based on an
|
|
1058
1046
|
// exception-based model. The fastest supported sampling interval may be equal to 0, which indicates
|
|
1059
1047
|
// that the data item is exception-based rather than being sampled at some period. An exception-based
|
|
@@ -1074,7 +1062,7 @@ export class MonitoredItem extends EventEmitter {
|
|
|
1074
1062
|
}
|
|
1075
1063
|
|
|
1076
1064
|
private _setOverflowBit(notification: any) {
|
|
1077
|
-
if (
|
|
1065
|
+
if (Object.prototype.hasOwnProperty.call(notification, "value")) {
|
|
1078
1066
|
assert(notification.value.statusCode.equals(StatusCodes.Good));
|
|
1079
1067
|
notification.value.statusCode = StatusCode.makeStatusCode(
|
|
1080
1068
|
notification.value.statusCode,
|
|
@@ -1191,11 +1179,11 @@ export class MonitoredItem extends EventEmitter {
|
|
|
1191
1179
|
) {
|
|
1192
1180
|
throw new Error(
|
|
1193
1181
|
"dataValue.value.value cannot be the same object twice! " +
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1182
|
+
this.node!.browseName.toString() +
|
|
1183
|
+
" " +
|
|
1184
|
+
dataValue.toString() +
|
|
1185
|
+
" " +
|
|
1186
|
+
chalk.cyan(this.oldDataValue.toString())
|
|
1199
1187
|
);
|
|
1200
1188
|
}
|
|
1201
1189
|
|