-
-
Notifications
You must be signed in to change notification settings - Fork 480
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
factor out node-opcua-alarm-condition module
- Loading branch information
1 parent
1cba6e9
commit ee7b7e3
Showing
32 changed files
with
616 additions
and
418 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
out/ | ||
out1/ | ||
out2/ | ||
documentation/ | ||
test/ | ||
test_to_fix/ | ||
test_fixtures/ | ||
certificates/ | ||
.vscode/ | ||
_test_generated/ | ||
schemas/ | ||
pki/ | ||
tmp/ | ||
test/ | ||
tsconfig.json | ||
*.tsbuildinfo | ||
pnpm-lock.yaml | ||
tslint.* | ||
.mocharc.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2022-2023 Sterfive SAS - 833264583 RCS ORLEANS - France (https://www.sterfive.com) | ||
|
||
Copyright (c) 2014-2022 Etienne Rossignon | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"name": "node-opcua-alarm-condition", | ||
"version": "2.118.0", | ||
"description": "pure nodejs OPCUA SDK - module pseudo-session", | ||
"scripts": { | ||
"clean": "npx rimraf node_modules dist *.tsbuildinfo", | ||
"build": "tsc -b", | ||
"lint": "eslint source/**/*.ts", | ||
"test": "echo mocha test" | ||
}, | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"dependencies": { | ||
"node-opcua-assert": "2.105.0", | ||
"node-opcua-basic-types": "2.118.0", | ||
"node-opcua-data-model": "2.118.0", | ||
"node-opcua-debug": "2.118.0", | ||
"node-opcua-nodeid": "2.118.0", | ||
"node-opcua-pseudo-session": "2.118.0", | ||
"node-opcua-service-filter": "2.118.0", | ||
"node-opcua-service-read": "2.118.0", | ||
"node-opcua-service-browse": "2.118.0", | ||
"node-opcua-service-subscription": "2.118.0", | ||
"node-opcua-service-translate-browse-path": "2.118.0", | ||
"node-opcua-status-code": "2.117.0", | ||
"node-opcua-types": "2.118.0", | ||
"node-opcua-utils": "2.117.0", | ||
"node-opcua-variant": "2.118.0", | ||
"thenify": "^3.3.1" | ||
}, | ||
"author": "Etienne Rossignon", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/node-opcua/node-opcua.git" | ||
}, | ||
"keywords": [ | ||
"OPCUA", | ||
"opcua", | ||
"m2m", | ||
"iot", | ||
"opc ua", | ||
"internet of things" | ||
], | ||
"homepage": "http://node-opcua.github.io/", | ||
"gitHead": "50cfa07779d4c07b299176ac9c27527fcd97d079", | ||
"files": [ | ||
"dist", | ||
"source" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
packages/node-opcua-alarm-condition/source/call_condition_refresh.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import assert from "node-opcua-assert"; | ||
import { DataType, StatusCode, StatusCodes } from "node-opcua-basic-types"; | ||
import { resolveNodeId } from "node-opcua-nodeid"; | ||
import { makeBrowsePath } from "node-opcua-service-translate-browse-path"; | ||
import { CallMethodRequest } from "node-opcua-types"; | ||
import { Variant } from "node-opcua-variant"; | ||
import { make_debugLog, make_warningLog } from "node-opcua-debug"; | ||
import { IBasicSessionAsync, CallMethodRequestLike } from "node-opcua-pseudo-session"; | ||
|
||
const doDebug = false; | ||
const debugLog = make_debugLog("A&E"); | ||
const warningLog = make_warningLog("A&E"); | ||
|
||
export async function callConditionRefresh(session: IBasicSessionAsync, subscriptionId: number): Promise<StatusCode> { | ||
assert(isFinite(subscriptionId), "May be subscription is not yet initialized"); | ||
const conditionTypeNodeId = resolveNodeId("ConditionType"); | ||
let conditionRefreshId = resolveNodeId("ConditionType_ConditionRefresh"); | ||
// find conditionRefreshId | ||
const browsePath = makeBrowsePath(conditionTypeNodeId, ".ConditionRefresh"); | ||
const translateResult = await session.translateBrowsePath(browsePath); | ||
|
||
// istanbul ignore next | ||
if (translateResult.targets && translateResult.targets.length > 0) { | ||
conditionRefreshId = translateResult.targets[0].targetId; | ||
} else { | ||
// cannot find conditionRefreshId | ||
return StatusCodes.BadInternalError; | ||
} | ||
const methodToCall: CallMethodRequestLike = { | ||
inputArguments: [new Variant({ dataType: DataType.UInt32, value: subscriptionId })], | ||
methodId: conditionRefreshId, | ||
objectId: conditionTypeNodeId | ||
}; | ||
|
||
doDebug && debugLog("Calling method ", new CallMethodRequest(methodToCall).toString()); | ||
const callResult = await session.call(methodToCall); | ||
// istanbul ignore next | ||
if (callResult.statusCode.isNotGood()) { | ||
warningLog(new CallMethodRequest(methodToCall).toString()); | ||
} | ||
return callResult.statusCode; | ||
} |
64 changes: 64 additions & 0 deletions
64
packages/node-opcua-alarm-condition/source/call_method_condition.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import assert from "node-opcua-assert"; | ||
import { LocalizedText, LocalizedTextLike } from "node-opcua-data-model"; | ||
import { NodeId, NodeIdLike, coerceNodeId } 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"; | ||
|
||
|
||
export async function callMethodCondition( | ||
session: IBasicSessionAsync, | ||
methodName: string, | ||
conditionId: NodeIdLike, | ||
eventId: Buffer, | ||
comment: LocalizedTextLike, | ||
|
||
): Promise<StatusCode> | ||
{ | ||
conditionId = coerceNodeId(conditionId); | ||
assert(conditionId instanceof NodeId); | ||
assert(eventId instanceof Buffer); | ||
assert(typeof comment === "string" || comment instanceof LocalizedText); | ||
|
||
comment = LocalizedText.coerce(comment) || new LocalizedText(); | ||
const r = await findMethodId(session, conditionId, methodName); | ||
if (!r.methodId) { | ||
return StatusCodes.BadNodeIdUnknown; | ||
} | ||
const methodId = r.methodId; | ||
const methodToCalls = []; | ||
|
||
methodToCalls.push( | ||
new CallMethodRequest({ | ||
inputArguments: [ | ||
/* eventId */ new Variant({ dataType: "ByteString", value: eventId }), | ||
/* comment */ new Variant({ dataType: "LocalizedText", value: comment }) | ||
], | ||
methodId, | ||
objectId: conditionId | ||
}) | ||
); | ||
|
||
const results = await session.call(methodToCalls); | ||
const statusCode = results![0].statusCode; | ||
return statusCode; | ||
} | ||
|
||
|
||
export async function acknowledgeCondition( | ||
session: IBasicSessionAsync, | ||
conditionId: NodeIdLike, | ||
eventId: Buffer, | ||
comment: LocalizedTextLike | ||
): Promise<StatusCode> { | ||
return await callMethodCondition(session, "Acknowledge", conditionId, eventId, comment); | ||
} | ||
export async function confirmCondition( | ||
session: IBasicSessionAsync, | ||
conditionId: NodeIdLike, | ||
eventId: Buffer, | ||
comment: LocalizedTextLike | ||
): Promise<StatusCode> { | ||
return await callMethodCondition(session, "Confirm", conditionId, eventId, comment); | ||
} |
Oops, something went wrong.