Skip to content

Commit

Permalink
use AcknowledgeableConditionType_Acknowledge/Confirm when ConditionId…
Browse files Browse the repository at this point in the history
… is not an instance
  • Loading branch information
erossignon committed Nov 26, 2023
1 parent ee7b7e3 commit 9eeb81a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,24 @@ const errorLog = make_errorLog(__filename);
*/

async function acknowledgeConditionEV(session: IBasicSessionAsync, eventStuff: EventStuff, comment: string): Promise<StatusCode> {
const conditionId = eventStuff.conditionId?.value;
const eventId = eventStuff.eventId?.value;
try {
const conditionId = eventStuff.conditionId.value;
const eventId = eventStuff.eventId.value;
return await acknowledgeCondition(session, conditionId, eventId, comment);
} catch (err) {
errorLog(`conditionId: ${conditionId?.toString()}`);
errorLog("Acknowledging Condition has failed !", err);
return StatusCodes.BadInternalError;
}
}

async function confirmConditionEV(session: IBasicSessionAsync, eventStuff: EventStuff, comment: string): Promise<StatusCode> {
const conditionId = eventStuff.conditionId?.value;
const eventId = eventStuff.eventId?.value;
try {
const conditionId = eventStuff.conditionId.value;
const eventId = eventStuff.eventId.value;
return await confirmCondition(session, conditionId, eventId, comment);
} catch (err) {
errorLog(`conditionId: ${conditionId?.toString()}`);
errorLog("Confirming Condition has failed !", err);
return StatusCodes.BadInternalError;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import assert from "node-opcua-assert";
import { LocalizedText, LocalizedTextLike } from "node-opcua-data-model";
import { NodeId, NodeIdLike, coerceNodeId } from "node-opcua-nodeid";
import { NodeId, NodeIdLike, coerceNodeId, resolveNodeId } from "node-opcua-nodeid";
import { StatusCode, StatusCodes } from "node-opcua-status-code";
import { CallMethodRequest } from "node-opcua-types";
import { Variant } from "node-opcua-variant";
import { IBasicSessionAsync, findMethodId } from "node-opcua-pseudo-session";
import { MethodIds } from "node-opcua-constants";




export async function callMethodCondition(
Expand All @@ -23,10 +26,29 @@ export async function callMethodCondition(

comment = LocalizedText.coerce(comment) || new LocalizedText();
const r = await findMethodId(session, conditionId, methodName);
if (!r.methodId) {
return StatusCodes.BadNodeIdUnknown;

let methodId = r.methodId;
if (!methodId) {
// https://reference.opcfoundation.org/Core/Part9/v104/docs/5.7.3#_Ref224987672
// The Acknowledge Method is used to acknowledge an Event Notification for a Condition instance
// state where AckedState is False. Normally, the NodeId of the object instance is passed as the
// ObjectId to the Call Service. However, some Servers do not expose Condition instances in the AddressSpace.
// Therefore, Servers shall allow Clients to call the Acknowledge Method by specifying ConditionId as the ObjectId.
// The Method cannot be called with an ObjectId of the AcknowledgeableConditionType Node.
//
// The Confirm Method is used to confirm an Event Notifications for a Condition instance state where ConfirmedState is False.

switch (methodName) {
case "Acknowledge":
methodId = resolveNodeId(MethodIds.AcknowledgeableConditionType_Acknowledge);
break;
case "Confirm":
methodId = resolveNodeId(MethodIds.AcknowledgeableConditionType_Confirm);
break;
default:
return StatusCodes.BadNodeIdUnknown;
}
}
const methodId = r.methodId;
const methodToCalls = [];

methodToCalls.push(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const { perform_operation_on_subscription_async } = require("../../../test_helpe

const doDebug = false;

function ellipsys(a) {
function ellipsis(a) {
if (!a) {
return "";
return ""; ClientAlarm
}
return truncate(a, 10, { position: "middle" });
}
Expand Down Expand Up @@ -53,12 +53,12 @@ function displayAlarms(alarms /*: ClientAlarmList*/) {
alarm.eventType.toString({ addressSpace: alarms.addressSpace }),
alarm.conditionId.toString(),
fields.branchId.value.toString(),
ellipsys(alarm.eventId.toString("hex")),
ellipsis(alarm.eventId.toString("hex")),
fields.enabledState.id.value.toString(),
isEnabled ? fields.activeState.id.value : "-",
isEnabled ? ellipsys(fields.message.value.text) : "-",
isEnabled ? ellipsis(fields.message.value.text) : "-",
isEnabled ? fields.severity.value + " (" + fields.lastSeverity.value + ")" : "-",
isEnabled ? ellipsys(fields.comment.value.text) : "-",
isEnabled ? ellipsis(fields.comment.value.text) : "-",
isEnabled ? fields.ackedState.id.value.toString() : "-",
fields.confirmedState.id.value,
fields.retain.value
Expand All @@ -69,8 +69,8 @@ function displayAlarms(alarms /*: ClientAlarmList*/) {
}

// eslint-disable-next-line import/order
const describe = require("node-opcua-leak-detector").describeWithLeakDetector;
module.exports = function (test) {
const { describeWithLeakDetector: describe } = require("node-opcua-leak-detector");
module.exports = function(test) {
describe("A&C3 client side alarm monitoring", () => {
let client;
function resetConditions(test) {
Expand Down

0 comments on commit 9eeb81a

Please sign in to comment.