node-opcua-alarm-condition 2.119.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 +22 -0
- package/dist/acknowledge_all_conditions.d.ts +10 -0
- package/dist/acknowledge_all_conditions.js +173 -0
- package/dist/acknowledge_all_conditions.js.map +1 -0
- package/dist/call_condition_refresh.d.ts +3 -0
- package/dist/call_condition_refresh.js +46 -0
- package/dist/call_condition_refresh.js.map +1 -0
- package/dist/call_method_condition.d.ts +8 -0
- package/dist/call_method_condition.js +65 -0
- package/dist/call_method_condition.js.map +1 -0
- package/dist/client_alarm.d.ts +30 -0
- package/dist/client_alarm.js +54 -0
- package/dist/client_alarm.js.map +1 -0
- package/dist/client_alarm_list.d.ts +26 -0
- package/dist/client_alarm_list.js +98 -0
- package/dist/client_alarm_list.js.map +1 -0
- package/dist/client_alarm_tools_dump_event.d.ts +9 -0
- package/dist/client_alarm_tools_dump_event.js +60 -0
- package/dist/client_alarm_tools_dump_event.js.map +1 -0
- package/dist/event_stuff.d.ts +23 -0
- package/dist/event_stuff.js +48 -0
- package/dist/event_stuff.js.map +1 -0
- package/dist/extract_condition_fields.d.ts +3 -0
- package/dist/extract_condition_fields.js +15 -0
- package/dist/extract_condition_fields.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/package.json +52 -0
- package/source/acknowledge_all_conditions.ts +193 -0
- package/source/call_condition_refresh.ts +42 -0
- package/source/call_method_condition.ts +86 -0
- package/source/client_alarm.ts +73 -0
- package/source/client_alarm_list.ts +112 -0
- package/source/client_alarm_tools_dump_event.ts +66 -0
- package/source/event_stuff.ts +65 -0
- package/source/extract_condition_fields.ts +12 -0
- package/source/index.ts +8 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022-2023 Sterfive SAS - 833264583 RCS ORLEANS - France (https://www.sterfive.com)
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2014-2022 Etienne Rossignon
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
8
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
9
|
+
the Software without restriction, including without limitation the rights to
|
|
10
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
11
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
12
|
+
subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
19
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
20
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
21
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
22
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IBasicSessionEx } from "node-opcua-pseudo-session";
|
|
2
|
+
import { EventStuff } from "./event_stuff";
|
|
3
|
+
export type FindActiveConditions = () => Promise<EventStuff[]>;
|
|
4
|
+
/**
|
|
5
|
+
* Enumerate all events
|
|
6
|
+
* @param session
|
|
7
|
+
*/
|
|
8
|
+
export declare function findActiveConditions(session: IBasicSessionEx): Promise<EventStuff[]>;
|
|
9
|
+
export declare function acknowledgeAllConditions(session: IBasicSessionEx, message: string): Promise<void>;
|
|
10
|
+
export declare function confirmAllConditions(session: IBasicSessionEx, message: string): Promise<void>;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.confirmAllConditions = exports.acknowledgeAllConditions = exports.findActiveConditions = void 0;
|
|
4
|
+
const node_opcua_nodeid_1 = require("node-opcua-nodeid");
|
|
5
|
+
const node_opcua_service_filter_1 = require("node-opcua-service-filter");
|
|
6
|
+
const node_opcua_service_read_1 = require("node-opcua-service-read");
|
|
7
|
+
const node_opcua_status_code_1 = require("node-opcua-status-code");
|
|
8
|
+
const node_opcua_variant_1 = require("node-opcua-variant");
|
|
9
|
+
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
10
|
+
const event_stuff_1 = require("./event_stuff");
|
|
11
|
+
const extract_condition_fields_1 = require("./extract_condition_fields");
|
|
12
|
+
const call_method_condition_1 = require("./call_method_condition");
|
|
13
|
+
const call_condition_refresh_1 = require("./call_condition_refresh");
|
|
14
|
+
const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename);
|
|
15
|
+
const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
|
|
16
|
+
const errorLog = (0, node_opcua_debug_1.make_errorLog)(__filename);
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @param session
|
|
20
|
+
* @param eventStuff
|
|
21
|
+
* @param comment
|
|
22
|
+
*/
|
|
23
|
+
async function acknowledgeConditionEV(session, eventStuff, comment) {
|
|
24
|
+
const conditionId = eventStuff.conditionId?.value;
|
|
25
|
+
const eventId = eventStuff.eventId?.value;
|
|
26
|
+
try {
|
|
27
|
+
return await (0, call_method_condition_1.acknowledgeCondition)(session, conditionId, eventId, comment);
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
errorLog(`conditionId: ${conditionId?.toString()}`);
|
|
31
|
+
errorLog("Acknowledging Condition has failed !", err);
|
|
32
|
+
return node_opcua_status_code_1.StatusCodes.BadInternalError;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function confirmConditionEV(session, eventStuff, comment) {
|
|
36
|
+
const conditionId = eventStuff.conditionId?.value;
|
|
37
|
+
const eventId = eventStuff.eventId?.value;
|
|
38
|
+
try {
|
|
39
|
+
return await (0, call_method_condition_1.confirmCondition)(session, conditionId, eventId, comment);
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
errorLog(`conditionId: ${conditionId?.toString()}`);
|
|
43
|
+
errorLog("Confirming Condition has failed !", err);
|
|
44
|
+
return node_opcua_status_code_1.StatusCodes.BadInternalError;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Enumerate all events
|
|
49
|
+
* @param session
|
|
50
|
+
*/
|
|
51
|
+
async function findActiveConditions(session) {
|
|
52
|
+
const request = {
|
|
53
|
+
maxNotificationsPerPublish: 10000,
|
|
54
|
+
priority: 6,
|
|
55
|
+
publishingEnabled: true,
|
|
56
|
+
requestedLifetimeCount: 1000,
|
|
57
|
+
requestedMaxKeepAliveCount: 100,
|
|
58
|
+
requestedPublishingInterval: 100
|
|
59
|
+
};
|
|
60
|
+
const subscription = await session.createSubscription2(request);
|
|
61
|
+
const itemToMonitor = {
|
|
62
|
+
attributeId: node_opcua_service_read_1.AttributeIds.EventNotifier,
|
|
63
|
+
nodeId: (0, node_opcua_nodeid_1.resolveNodeId)("Server") // i=2253session
|
|
64
|
+
};
|
|
65
|
+
const fields = await (0, extract_condition_fields_1.extractConditionFields)(session, "AcknowledgeableConditionType");
|
|
66
|
+
// note: we may want to have this select clause
|
|
67
|
+
// Or(OfType("AcknowledgeableConditionType"), OfType("RefreshStartEventType"), OfType("RefreshEndEventType"))
|
|
68
|
+
const eventFilter = (0, node_opcua_service_filter_1.constructEventFilter)(fields);
|
|
69
|
+
const monitoringParameters = {
|
|
70
|
+
discardOldest: false,
|
|
71
|
+
filter: eventFilter,
|
|
72
|
+
queueSize: 100,
|
|
73
|
+
samplingInterval: 0
|
|
74
|
+
};
|
|
75
|
+
const event_monitoringItem = await subscription.monitor(itemToMonitor, monitoringParameters, node_opcua_service_read_1.TimestampsToReturn.Both);
|
|
76
|
+
const acknowledgeableConditions = [];
|
|
77
|
+
let refreshStartEventHasBeenReceived = false;
|
|
78
|
+
let RefreshEndEventHasBeenReceived = false;
|
|
79
|
+
const RefreshStartEventType = (0, node_opcua_nodeid_1.resolveNodeId)("RefreshStartEventType").toString();
|
|
80
|
+
const RefreshEndEventType = (0, node_opcua_nodeid_1.resolveNodeId)("RefreshEndEventType").toString();
|
|
81
|
+
await new Promise((resolve, reject) => {
|
|
82
|
+
// now create a event monitored Item
|
|
83
|
+
event_monitoringItem.on("changed", (_eventFields) => {
|
|
84
|
+
const eventFields = _eventFields;
|
|
85
|
+
try {
|
|
86
|
+
if (RefreshEndEventHasBeenReceived) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
// dumpEvent(session, fields, eventFields);
|
|
90
|
+
const pojo = (0, event_stuff_1.fieldsToJson)(fields, eventFields);
|
|
91
|
+
// make sure we only start recording event after the RefreshStartEvent has been received
|
|
92
|
+
if (!refreshStartEventHasBeenReceived) {
|
|
93
|
+
if (pojo.eventType.value.toString() === RefreshStartEventType) {
|
|
94
|
+
refreshStartEventHasBeenReceived = true;
|
|
95
|
+
}
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (pojo.eventType.value.toString() === RefreshEndEventType) {
|
|
99
|
+
RefreshEndEventHasBeenReceived = true;
|
|
100
|
+
resolve();
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (!pojo.conditionId.value) {
|
|
104
|
+
// not a Acknowledgeable condition
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (pojo.ackedState.id.dataType === node_opcua_variant_1.DataType.Boolean) {
|
|
108
|
+
acknowledgeableConditions.push(pojo);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
errorLog("Error !!", err);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
// async call without waiting !
|
|
116
|
+
try {
|
|
117
|
+
(0, call_condition_refresh_1.callConditionRefresh)(session, subscription.subscriptionId);
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
// it is possible that server do not implement conditionRefresh ...
|
|
121
|
+
errorLog("Server may not implement conditionRefresh", err.message);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
// now shut down subscription
|
|
125
|
+
await subscription.terminate();
|
|
126
|
+
return acknowledgeableConditions;
|
|
127
|
+
}
|
|
128
|
+
exports.findActiveConditions = findActiveConditions;
|
|
129
|
+
// let conditions = await findActiveConditions(session);
|
|
130
|
+
// if (conditions.length === 0) {
|
|
131
|
+
// debugLog("Warning: cannot find conditions ");
|
|
132
|
+
// }
|
|
133
|
+
async function acknowledgeAllConditions(session, message) {
|
|
134
|
+
try {
|
|
135
|
+
let conditions = await findActiveConditions(session);
|
|
136
|
+
// filter acknowledgeable conditions (no acked yet)
|
|
137
|
+
conditions = conditions.filter((pojo) => pojo.ackedState.id.value === false);
|
|
138
|
+
const promises = [];
|
|
139
|
+
for (const eventStuff of conditions) {
|
|
140
|
+
promises.push(acknowledgeConditionEV(session, eventStuff, message));
|
|
141
|
+
}
|
|
142
|
+
const result = await Promise.all(promises);
|
|
143
|
+
// istanbul ignore next
|
|
144
|
+
if (doDebug) {
|
|
145
|
+
debugLog("Acked all results: ", result.map((e) => e.toString()).join(" "));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
catch (err) {
|
|
149
|
+
errorLog("Error", err);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
exports.acknowledgeAllConditions = acknowledgeAllConditions;
|
|
153
|
+
async function confirmAllConditions(session, message) {
|
|
154
|
+
try {
|
|
155
|
+
let conditions = await findActiveConditions(session);
|
|
156
|
+
// filter acknowledgeable conditions (no acked yet)
|
|
157
|
+
conditions = conditions.filter((pojo) => pojo.confirmedState.id.value === false);
|
|
158
|
+
const promises = [];
|
|
159
|
+
for (const eventStuff of conditions) {
|
|
160
|
+
promises.push(confirmConditionEV(session, eventStuff, message));
|
|
161
|
+
}
|
|
162
|
+
const result = await Promise.all(promises);
|
|
163
|
+
// istanbul ignore next
|
|
164
|
+
if (doDebug) {
|
|
165
|
+
debugLog("Confirm all results: ", result.map((e) => e.toString()).join(" "));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
catch (err) {
|
|
169
|
+
errorLog("Error", err);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
exports.confirmAllConditions = confirmAllConditions;
|
|
173
|
+
//# sourceMappingURL=acknowledge_all_conditions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acknowledge_all_conditions.js","sourceRoot":"","sources":["../source/acknowledge_all_conditions.ts"],"names":[],"mappings":";;;AAAA,yDAAkD;AAClD,yEAAiE;AACjE,qEAA+F;AAE/F,mEAAiE;AACjE,2DAAuD;AACvD,uDAAgF;AAKhF,+CAAyD;AACzD,yEAAoE;AACpE,mEAAiF;AACjF,qEAAgE;AAEhE,MAAM,OAAO,GAAG,IAAA,iCAAc,EAAC,UAAU,CAAC,CAAC;AAC3C,MAAM,QAAQ,GAAG,IAAA,gCAAa,EAAC,UAAU,CAAC,CAAC;AAC3C,MAAM,QAAQ,GAAG,IAAA,gCAAa,EAAC,UAAU,CAAC,CAAC;AAE3C;;;;;GAKG;AAEH,KAAK,UAAU,sBAAsB,CAAC,OAA2B,EAAE,UAAsB,EAAE,OAAe;IACtG,MAAM,WAAW,GAAG,UAAU,CAAC,WAAW,EAAE,KAAK,CAAC;IAClD,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC;IAC1C,IAAI,CAAC;QACD,OAAO,MAAM,IAAA,4CAAoB,EAAC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAC9E,CAAC;IAAC,OAAO,GAAG,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uB;QACvB,IAAI,OAAO,EAAE,CAAC;YACV,QAAQ,CAAC,uBAAuB,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QACjF,CAAC;IACL,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACX,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IAC3B,CAAC;AACL,CAAC;AAlBD,oDAkBC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.callConditionRefresh = void 0;
|
|
7
|
+
const node_opcua_assert_1 = __importDefault(require("node-opcua-assert"));
|
|
8
|
+
const node_opcua_basic_types_1 = require("node-opcua-basic-types");
|
|
9
|
+
const node_opcua_nodeid_1 = require("node-opcua-nodeid");
|
|
10
|
+
const node_opcua_service_translate_browse_path_1 = require("node-opcua-service-translate-browse-path");
|
|
11
|
+
const node_opcua_types_1 = require("node-opcua-types");
|
|
12
|
+
const node_opcua_variant_1 = require("node-opcua-variant");
|
|
13
|
+
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
14
|
+
const doDebug = false;
|
|
15
|
+
const debugLog = (0, node_opcua_debug_1.make_debugLog)("A&E");
|
|
16
|
+
const warningLog = (0, node_opcua_debug_1.make_warningLog)("A&E");
|
|
17
|
+
async function callConditionRefresh(session, subscriptionId) {
|
|
18
|
+
(0, node_opcua_assert_1.default)(isFinite(subscriptionId), "May be subscription is not yet initialized");
|
|
19
|
+
const conditionTypeNodeId = (0, node_opcua_nodeid_1.resolveNodeId)("ConditionType");
|
|
20
|
+
let conditionRefreshId = (0, node_opcua_nodeid_1.resolveNodeId)("ConditionType_ConditionRefresh");
|
|
21
|
+
// find conditionRefreshId
|
|
22
|
+
const browsePath = (0, node_opcua_service_translate_browse_path_1.makeBrowsePath)(conditionTypeNodeId, ".ConditionRefresh");
|
|
23
|
+
const translateResult = await session.translateBrowsePath(browsePath);
|
|
24
|
+
// istanbul ignore next
|
|
25
|
+
if (translateResult.targets && translateResult.targets.length > 0) {
|
|
26
|
+
conditionRefreshId = translateResult.targets[0].targetId;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
// cannot find conditionRefreshId
|
|
30
|
+
return node_opcua_basic_types_1.StatusCodes.BadInternalError;
|
|
31
|
+
}
|
|
32
|
+
const methodToCall = {
|
|
33
|
+
inputArguments: [new node_opcua_variant_1.Variant({ dataType: node_opcua_basic_types_1.DataType.UInt32, value: subscriptionId })],
|
|
34
|
+
methodId: conditionRefreshId,
|
|
35
|
+
objectId: conditionTypeNodeId
|
|
36
|
+
};
|
|
37
|
+
doDebug && debugLog("Calling method ", new node_opcua_types_1.CallMethodRequest(methodToCall).toString());
|
|
38
|
+
const callResult = await session.call(methodToCall);
|
|
39
|
+
// istanbul ignore next
|
|
40
|
+
if (callResult.statusCode.isNotGood()) {
|
|
41
|
+
warningLog(new node_opcua_types_1.CallMethodRequest(methodToCall).toString());
|
|
42
|
+
}
|
|
43
|
+
return callResult.statusCode;
|
|
44
|
+
}
|
|
45
|
+
exports.callConditionRefresh = callConditionRefresh;
|
|
46
|
+
//# sourceMappingURL=call_condition_refresh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call_condition_refresh.js","sourceRoot":"","sources":["../source/call_condition_refresh.ts"],"names":[],"mappings":";;;;;;AAAA,0EAAuC;AACvC,mEAA2E;AAC3E,yDAAkD;AAClD,uGAA0E;AAC1E,uDAAqD;AACrD,2DAA6C;AAC7C,uDAAkE;AAGlE,MAAM,OAAO,GAAG,KAAK,CAAC;AACtB,MAAM,QAAQ,GAAG,IAAA,gCAAa,EAAC,KA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C,SAAS,EAAE,EAAE,CAAC;QACpC,UAAU,CAAC,IAAI,oCAAiB,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,UAAU,CAAC,UAAU,CAAC;AACjC,CAAC;AA5BD,oDA4BC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { LocalizedTextLike } from "node-opcua-data-model";
|
|
3
|
+
import { NodeIdLike } from "node-opcua-nodeid";
|
|
4
|
+
import { StatusCode } from "node-opcua-status-code";
|
|
5
|
+
import { IBasicSessionAsync } from "node-opcua-pseudo-session";
|
|
6
|
+
export declare function callMethodCondition(session: IBasicSessionAsync, methodName: string, conditionId: NodeIdLike, eventId: Buffer, comment: LocalizedTextLike): Promise<StatusCode>;
|
|
7
|
+
export declare function acknowledgeCondition(session: IBasicSessionAsync, conditionId: NodeIdLike, eventId: Buffer, comment: LocalizedTextLike): Promise<StatusCode>;
|
|
8
|
+
export declare function confirmCondition(session: IBasicSessionAsync, conditionId: NodeIdLike, eventId: Buffer, comment: LocalizedTextLike): Promise<StatusCode>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.confirmCondition = exports.acknowledgeCondition = exports.callMethodCondition = void 0;
|
|
7
|
+
const node_opcua_assert_1 = __importDefault(require("node-opcua-assert"));
|
|
8
|
+
const node_opcua_data_model_1 = require("node-opcua-data-model");
|
|
9
|
+
const node_opcua_nodeid_1 = require("node-opcua-nodeid");
|
|
10
|
+
const node_opcua_status_code_1 = require("node-opcua-status-code");
|
|
11
|
+
const node_opcua_types_1 = require("node-opcua-types");
|
|
12
|
+
const node_opcua_variant_1 = require("node-opcua-variant");
|
|
13
|
+
const node_opcua_pseudo_session_1 = require("node-opcua-pseudo-session");
|
|
14
|
+
const node_opcua_constants_1 = require("node-opcua-constants");
|
|
15
|
+
async function callMethodCondition(session, methodName, conditionId, eventId, comment) {
|
|
16
|
+
conditionId = (0, node_opcua_nodeid_1.coerceNodeId)(conditionId);
|
|
17
|
+
(0, node_opcua_assert_1.default)(conditionId instanceof node_opcua_nodeid_1.NodeId);
|
|
18
|
+
(0, node_opcua_assert_1.default)(eventId instanceof Buffer);
|
|
19
|
+
(0, node_opcua_assert_1.default)(typeof comment === "string" || comment instanceof node_opcua_data_model_1.LocalizedText);
|
|
20
|
+
comment = node_opcua_data_model_1.LocalizedText.coerce(comment) || new node_opcua_data_model_1.LocalizedText();
|
|
21
|
+
const r = await (0, node_opcua_pseudo_session_1.findMethodId)(session, conditionId, methodName);
|
|
22
|
+
let methodId = r.methodId;
|
|
23
|
+
if (!methodId) {
|
|
24
|
+
// https://reference.opcfoundation.org/Core/Part9/v104/docs/5.7.3#_Ref224987672
|
|
25
|
+
// The Acknowledge Method is used to acknowledge an Event Notification for a Condition instance
|
|
26
|
+
// state where AckedState is False. Normally, the NodeId of the object instance is passed as the
|
|
27
|
+
// ObjectId to the Call Service. However, some Servers do not expose Condition instances in the AddressSpace.
|
|
28
|
+
// Therefore, Servers shall allow Clients to call the Acknowledge Method by specifying ConditionId as the ObjectId.
|
|
29
|
+
// The Method cannot be called with an ObjectId of the AcknowledgeableConditionType Node.
|
|
30
|
+
//
|
|
31
|
+
// The Confirm Method is used to confirm an Event Notifications for a Condition instance state where ConfirmedState is False.
|
|
32
|
+
switch (methodName) {
|
|
33
|
+
case "Acknowledge":
|
|
34
|
+
methodId = (0, node_opcua_nodeid_1.resolveNodeId)(node_opcua_constants_1.MethodIds.AcknowledgeableConditionType_Acknowledge);
|
|
35
|
+
break;
|
|
36
|
+
case "Confirm":
|
|
37
|
+
methodId = (0, node_opcua_nodeid_1.resolveNodeId)(node_opcua_constants_1.MethodIds.AcknowledgeableConditionType_Confirm);
|
|
38
|
+
break;
|
|
39
|
+
default:
|
|
40
|
+
return node_opcua_status_code_1.StatusCodes.BadNodeIdUnknown;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const methodToCalls = [];
|
|
44
|
+
methodToCalls.push(new node_opcua_types_1.CallMethodRequest({
|
|
45
|
+
inputArguments: [
|
|
46
|
+
/* eventId */ new node_opcua_variant_1.Variant({ dataType: "ByteString", value: eventId }),
|
|
47
|
+
/* comment */ new node_opcua_variant_1.Variant({ dataType: "LocalizedText", value: comment })
|
|
48
|
+
],
|
|
49
|
+
methodId,
|
|
50
|
+
objectId: conditionId
|
|
51
|
+
}));
|
|
52
|
+
const results = await session.call(methodToCalls);
|
|
53
|
+
const statusCode = results[0].statusCode;
|
|
54
|
+
return statusCode;
|
|
55
|
+
}
|
|
56
|
+
exports.callMethodCondition = callMethodCondition;
|
|
57
|
+
async function acknowledgeCondition(session, conditionId, eventId, comment) {
|
|
58
|
+
return await callMethodCondition(session, "Acknowledge", conditionId, eventId, comment);
|
|
59
|
+
}
|
|
60
|
+
exports.acknowledgeCondition = acknowledgeCondition;
|
|
61
|
+
async function confirmCondition(session, conditionId, eventId, comment) {
|
|
62
|
+
return await callMethodCondition(session, "Confirm", conditionId, eventId, comment);
|
|
63
|
+
}
|
|
64
|
+
exports.confirmCondition = confirmCondition;
|
|
65
|
+
//# sourceMappingURL=call_method_condition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call_method_condition.js","sourceRoot":"","sources":["../source/call_method_condition.ts"],"names":[],"mappings":";;;;;;AAAA,0EAAuC;AACvC,iEAAyE;AACzE,yDAAoF;AACpF,mEAAiE;AACjE,uDAAqD;AACrD,2DAA6C;AAC7C,yEAA6E;AAC7E,+DAAiD;AAK1C,KAAK,UAAU,mBAAmB,CACrC,OAA2B,EAC3B,UAAkB,EAClB,WAAuB,EACvB,OAAe,EACf,OAA0B;IAI1B,WAAW,GAAG,IAAA,gCAAY,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AQ;QACR,QAAQ,EAAE,WAAW;KACxB,CAAC,CACL,CAAC;IAEH,MAAM,OAAO,GAAI,MAAM,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IACnD,MAAM,UAAU,GAAG,OAAQ,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;IAC1C,OAAO,UAAU,CAAC;AACpB,CAAC;AAvDF,kDAuDE;AAGM,KAAK,UAAU,oBAAoB,CACvC,OAA2B,EAC3B,WAAuB,EACvB,OAAe,EACf,OAA0B;IAE1B,OAAO,MAAM,mBAAmB,CAAC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAC5F,CAAC;AAPA,oDAOA;AACM,KAAK,UAAU,gBAAgB,CAClC,OAA2B,EAC3B,WAAuB,EACvB,OAAe,EACf,OAA0B;IAE1B,OAAO,MAAM,mBAAmB,CAAC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AACxF,CAAC;AAPD,4CAOC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { EventEmitter } from "events";
|
|
4
|
+
import { NodeId } from "node-opcua-nodeid";
|
|
5
|
+
import { StatusCode } from "node-opcua-status-code";
|
|
6
|
+
import { Variant } from "node-opcua-variant";
|
|
7
|
+
import { IBasicSessionAsync } from "node-opcua-pseudo-session";
|
|
8
|
+
import { EventStuff } from "./event_stuff";
|
|
9
|
+
export interface ClientAlarm {
|
|
10
|
+
conditionId: NodeId;
|
|
11
|
+
eventType: NodeId;
|
|
12
|
+
fields: EventStuff;
|
|
13
|
+
on(eventName: "changed", eventHandler: () => void): this;
|
|
14
|
+
acknowledge(session: IBasicSessionAsync, comment: string): Promise<StatusCode>;
|
|
15
|
+
confirm(session: IBasicSessionAsync, comment: string): Promise<StatusCode>;
|
|
16
|
+
getField(fieldName: string): Variant | null;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* describes a OPCUA Alarm as seen in the client side
|
|
20
|
+
*/
|
|
21
|
+
export declare class ClientAlarm extends EventEmitter {
|
|
22
|
+
conditionId: NodeId;
|
|
23
|
+
eventType: NodeId;
|
|
24
|
+
eventId: Buffer;
|
|
25
|
+
fields: EventStuff;
|
|
26
|
+
constructor(eventFields: EventStuff);
|
|
27
|
+
update(eventFields: EventStuff): void;
|
|
28
|
+
getRetain(): boolean;
|
|
29
|
+
toString(): string;
|
|
30
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientAlarm = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
6
|
+
const node_opcua_nodeid_1 = require("node-opcua-nodeid");
|
|
7
|
+
const node_opcua_variant_1 = require("node-opcua-variant");
|
|
8
|
+
const call_method_condition_1 = require("./call_method_condition");
|
|
9
|
+
/**
|
|
10
|
+
* describes a OPCUA Alarm as seen in the client side
|
|
11
|
+
*/
|
|
12
|
+
class ClientAlarm extends events_1.EventEmitter {
|
|
13
|
+
constructor(eventFields) {
|
|
14
|
+
super();
|
|
15
|
+
this.conditionId = (0, node_opcua_nodeid_1.resolveNodeId)(eventFields.conditionId.value);
|
|
16
|
+
this.eventType = (0, node_opcua_nodeid_1.resolveNodeId)(eventFields.eventType.value);
|
|
17
|
+
this.eventId = eventFields.eventId.value;
|
|
18
|
+
this.fields = eventFields;
|
|
19
|
+
this.update(eventFields);
|
|
20
|
+
}
|
|
21
|
+
async acknowledge(session, comment) {
|
|
22
|
+
return await (0, call_method_condition_1.acknowledgeCondition)(session, this.conditionId, this.eventId, comment);
|
|
23
|
+
}
|
|
24
|
+
async confirm(session, comment) {
|
|
25
|
+
return await (0, call_method_condition_1.confirmCondition)(session, this.conditionId, this.eventId, comment);
|
|
26
|
+
}
|
|
27
|
+
update(eventFields) {
|
|
28
|
+
(0, node_opcua_assert_1.assert)(this.conditionId.toString() === (0, node_opcua_nodeid_1.resolveNodeId)(eventFields.conditionId.value).toString());
|
|
29
|
+
(0, node_opcua_assert_1.assert)(this.eventType.toString() === (0, node_opcua_nodeid_1.resolveNodeId)(eventFields.eventType.value).toString());
|
|
30
|
+
this.eventId = eventFields.eventId.value;
|
|
31
|
+
this.fields = eventFields;
|
|
32
|
+
}
|
|
33
|
+
getRetain() {
|
|
34
|
+
return this.fields.retain.value;
|
|
35
|
+
}
|
|
36
|
+
toString() {
|
|
37
|
+
return (this.constructor.name +
|
|
38
|
+
": " +
|
|
39
|
+
this.conditionId.toString() +
|
|
40
|
+
" " +
|
|
41
|
+
this.eventType.toString() +
|
|
42
|
+
" " +
|
|
43
|
+
Object.entries(this.fields)
|
|
44
|
+
.filter(([key, value]) => value.dataType !== node_opcua_variant_1.DataType.Null)
|
|
45
|
+
.map(([key, value]) => key.padEnd(30) + "=" + value.toString())
|
|
46
|
+
.join("\n") +
|
|
47
|
+
"\n\n");
|
|
48
|
+
}
|
|
49
|
+
getField(fieldName) {
|
|
50
|
+
return this.fields[fieldName] || null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.ClientAlarm = ClientAlarm;
|
|
54
|
+
//# sourceMappingURL=client_alarm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client_alarm.js","sourceRoot":"","sources":["../source/client_alarm.ts"],"names":[],"mappings":";;;AAAA,mCAAsC;AACtC,yDAA2C;AAC3C,yDAA0D;AAE1D,2DAAuD;AAGvD,mEAAiF;AAcjF;;GAEG;AACH,MAAa,WAAY,SAAQ,qBAAY;IAMzC,YAAmB,WAAuB;QACtC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,WAAW,GAAG,IAAA,iCAAa,EAAC,WAAW,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAChE,IAAI,CAAC,SAAS,GAAG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AQ,EAAE;YAC3B,GAAG;YACH,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE;YACzB,GAAG;YACH,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;iBACtB,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,KAAK,6BAAQ,CAAC,IAAI,CAAC;iBAC1D,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,GAAG,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;iBAC9D,IAAI,CAAC,IAAI,CAAC;YACf,MAAM,CACT,CAAC;IACN,CAAC;IAEM,QAAQ,CAAC,SAAiB;QAC7B,OAAQ,IAAI,CAAC,MAAc,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC;IACnD,CAAC;CACJ;AAhDD,kCAgDC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from "events";
|
|
3
|
+
import { EventStuff } from "./event_stuff";
|
|
4
|
+
import { ClientAlarm } from "./client_alarm";
|
|
5
|
+
export interface ClientAlarmList {
|
|
6
|
+
on(eventName: "alarmChanged", handler: (alarm: ClientAlarm) => void): this;
|
|
7
|
+
on(eventName: "alarmDeleted", handler: (alarm: ClientAlarm) => void): this;
|
|
8
|
+
on(eventName: "newAlarm", handler: (alarm: ClientAlarm) => void): this;
|
|
9
|
+
emit(eventName: "alarmChanged", alarm: ClientAlarm): boolean;
|
|
10
|
+
emit(eventName: "newAlarm", alarm: ClientAlarm): boolean;
|
|
11
|
+
emit(eventName: "alarmDeleted", alarm: ClientAlarm): boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare class ClientAlarmList extends EventEmitter implements Iterable<ClientAlarm> {
|
|
14
|
+
private _map;
|
|
15
|
+
constructor();
|
|
16
|
+
[Symbol.iterator](): Iterator<ClientAlarm>;
|
|
17
|
+
alarms(): ClientAlarm[];
|
|
18
|
+
update(eventField: EventStuff): void;
|
|
19
|
+
removeAlarm(eventField: EventStuff): void;
|
|
20
|
+
get length(): number;
|
|
21
|
+
purgeUnusedAlarms(): void;
|
|
22
|
+
private _removeAlarm;
|
|
23
|
+
private makeKey;
|
|
24
|
+
private findAlarm;
|
|
25
|
+
private deleteAlarm;
|
|
26
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientAlarmList = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
6
|
+
const client_alarm_1 = require("./client_alarm");
|
|
7
|
+
// maintain a set of alarm list for a client
|
|
8
|
+
class ClientAlarmList extends events_1.EventEmitter {
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
this._map = {};
|
|
12
|
+
}
|
|
13
|
+
[Symbol.iterator]() {
|
|
14
|
+
let pointer = 0;
|
|
15
|
+
const components = Object.values(this._map);
|
|
16
|
+
return {
|
|
17
|
+
next() {
|
|
18
|
+
if (pointer >= components.length) {
|
|
19
|
+
return {
|
|
20
|
+
done: true,
|
|
21
|
+
value: components[pointer++]
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
return {
|
|
26
|
+
done: false,
|
|
27
|
+
value: components[pointer++]
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
alarms() {
|
|
34
|
+
return Object.values(this._map);
|
|
35
|
+
}
|
|
36
|
+
update(eventField) {
|
|
37
|
+
// Spec says:
|
|
38
|
+
// Clients shall check for multiple Event Notifications for a ConditionBranch to avoid
|
|
39
|
+
// overwriting a new state delivered together with an older state from the Refresh
|
|
40
|
+
// process.
|
|
41
|
+
const { conditionId, eventType } = eventField;
|
|
42
|
+
(0, node_opcua_assert_1.assert)(conditionId, "must have a valid conditionId ( verify that event is a acknowledgeable type");
|
|
43
|
+
const alarm = this.findAlarm(conditionId.value, eventType.value);
|
|
44
|
+
if (!alarm) {
|
|
45
|
+
const key = this.makeKey(conditionId.value, eventType.value);
|
|
46
|
+
const newAlarm = new client_alarm_1.ClientAlarm(eventField);
|
|
47
|
+
this._map[key] = newAlarm;
|
|
48
|
+
this.emit("newAlarm", newAlarm);
|
|
49
|
+
this.emit("alarmChanged", newAlarm);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
alarm.update(eventField);
|
|
53
|
+
this.emit("alarmChanged", alarm);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
removeAlarm(eventField) {
|
|
57
|
+
const { conditionId, eventType } = eventField;
|
|
58
|
+
const alarm = this.findAlarm(conditionId.value, eventType.value);
|
|
59
|
+
if (alarm) {
|
|
60
|
+
alarm.update(eventField);
|
|
61
|
+
this._removeAlarm(alarm);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
get length() {
|
|
65
|
+
return Object.keys(this._map).length;
|
|
66
|
+
}
|
|
67
|
+
purgeUnusedAlarms() {
|
|
68
|
+
const alarms = this.alarms();
|
|
69
|
+
for (const alarm of alarms) {
|
|
70
|
+
if (!alarm.getRetain()) {
|
|
71
|
+
this._removeAlarm(alarm);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
_removeAlarm(alarm) {
|
|
76
|
+
this.emit("alarmDeleted", alarm);
|
|
77
|
+
this.deleteAlarm(alarm.conditionId, alarm.eventType);
|
|
78
|
+
}
|
|
79
|
+
makeKey(conditionId, eventType) {
|
|
80
|
+
return conditionId.toString() + "|" + eventType.toString();
|
|
81
|
+
}
|
|
82
|
+
findAlarm(conditionId, eventType) {
|
|
83
|
+
const key = this.makeKey(conditionId, eventType);
|
|
84
|
+
const _c = this._map[key];
|
|
85
|
+
return _c || null;
|
|
86
|
+
}
|
|
87
|
+
deleteAlarm(conditionId, eventType) {
|
|
88
|
+
const key = this.makeKey(conditionId, eventType);
|
|
89
|
+
const _c = this._map[key];
|
|
90
|
+
if (_c) {
|
|
91
|
+
delete this._map[key];
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.ClientAlarmList = ClientAlarmList;
|
|
98
|
+
//# sourceMappingURL=client_alarm_list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client_alarm_list.js","sourceRoot":"","sources":["../source/client_alarm_list.ts"],"names":[],"mappings":";;;AAAA,mCAAsC;AACtC,yDAA2C;AAG3C,iDAA6C;AAW7C,4CAA4C;AAC5C,MAAa,eAAgB,SAAQ,qBAAY;IAG7C;QACI,KAAK,EAAE,CAAC;QAHJ,SAAI,GAAmC,EAAE,CAAC;IAIlD,CAAC;IAEM,CAAC,MAAM,CAAC,QAAQ,CAAC;QACpB,IAAI,OAAO,GAAG,CAAC,CAAC;QAChB,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC5C,OAAO;YACH,IAAI;gBACA,IAAI,OAAO,IAAI,UAAU,CAAC,MAAM,EAAE,CAAC;oBAC/B,OAAO;wBACH,IAAI,EAAE,IAAI;wBACV,KAAK,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC;qBAC/B,CAAC;gBACN,CAAC;qBAAM,CAAC;oBACJ,OAAO;wBACH,IAAI,EAAE,KAAK;wBACX,KAAK,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC;qBAC/B,CAAC;gBACN,CAAC;YACL,CAAC;SACJ,CAAC;IACN,CAAC;IAEM,MAAM;QACT,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAEM,MAAM,CAAC,UAAsB;QAChC,aAAa;QACb,sF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Simple } from "node-opcua-pseudo-session";
|
|
2
|
+
import { Variant } from "node-opcua-variant";
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param session
|
|
6
|
+
* @param fields
|
|
7
|
+
* @param eventFields
|
|
8
|
+
*/
|
|
9
|
+
export declare function dumpEvent(session: IBasicSessionReadAsyncSimple, fields: string[], eventFields: Variant[]): Promise<void>;
|