Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3086de3
commit 8571c54
Showing
4 changed files
with
23 additions
and
120 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
117 changes: 5 additions & 112 deletions
117
...de-opcua-client/source/alarms_and_conditions/client_alarm_tools_extractConditionFields.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 |
---|---|---|
@@ -1,119 +1,12 @@ | ||
import { BrowseDirection, NodeClassMask, QualifiedName } from "node-opcua-data-model"; | ||
import { NodeId, NodeIdLike, resolveNodeId } from "node-opcua-nodeid"; | ||
import { IBasicSession } from "node-opcua-pseudo-session"; | ||
import { BrowseDescriptionOptions } from "node-opcua-service-browse"; | ||
import { NodeClass } from "node-opcua-types"; | ||
import { NodeIdLike } from "node-opcua-nodeid"; | ||
import { IBasicSession, simpleBrowsePathsToString, extractFields } from "node-opcua-pseudo-session"; | ||
|
||
export async function extractConditionFields(session: IBasicSession, conditionNodeId: NodeIdLike): Promise<string[]> { | ||
// conditionNodeId could be a Object of type ConditionType | ||
// or it could be directly a ObjectType which is a subType of ConditionType | ||
|
||
const _duplicateMap: any = {}; | ||
const fields1: string[] = []; | ||
|
||
function addField(name: string) { | ||
if (!_duplicateMap[name]) { | ||
fields1.push(name); | ||
_duplicateMap[name] = name; | ||
} | ||
} | ||
interface S { | ||
browseName: QualifiedName; | ||
nodeToBrowse: BrowseDescriptionOptions; | ||
} | ||
const stack: any[] = []; | ||
function deferObjectOrVariableInvestigation(objectId: NodeId, browseName: string) { | ||
stack.push({ | ||
browseName, | ||
nodeId: objectId | ||
}); | ||
} | ||
async function _investigateObjectOrVariable() { | ||
if (stack.length === 0) { | ||
return; | ||
} | ||
|
||
const extracted = stack.splice(0); | ||
const nodesToBrowse = extracted.map((e: any) => { | ||
const b: BrowseDescriptionOptions = { | ||
browseDirection: BrowseDirection.Forward, | ||
includeSubtypes: true, | ||
// tslint:disable-next-line: no-bitwise | ||
nodeClassMask: NodeClassMask.Object | NodeClassMask.Variable, | ||
nodeId: e.nodeId, | ||
referenceTypeId: "HasChild", | ||
resultMask: 63 | ||
}; | ||
return b; | ||
}); | ||
const results = await session.browse(nodesToBrowse); | ||
|
||
let i = 0; | ||
for (const result of results) { | ||
const name = extracted[i].browseName.toString(); | ||
i++; | ||
|
||
if (!result.references) { | ||
continue; | ||
} | ||
|
||
for (const ref of result.references) { | ||
const n = name + "." + ref.browseName.toString(); | ||
if (ref.nodeClass === NodeClass.Variable) { | ||
addField(n); | ||
} | ||
deferObjectOrVariableInvestigation(ref.nodeId, n); | ||
} | ||
} | ||
await _investigateObjectOrVariable(); | ||
} | ||
|
||
// tslint:disable-next-line: no-shadowed-variable | ||
async function _investigateLevel(conditionNodeId: NodeIdLike) { | ||
const nodeToBrowse1: BrowseDescriptionOptions = { | ||
browseDirection: BrowseDirection.Inverse, | ||
includeSubtypes: true, | ||
nodeClassMask: NodeClassMask.ObjectType, | ||
nodeId: conditionNodeId, | ||
referenceTypeId: resolveNodeId("HasSubtype"), | ||
resultMask: 63 | ||
}; | ||
const nodeToBrowse2: BrowseDescriptionOptions = { | ||
browseDirection: BrowseDirection.Forward, | ||
includeSubtypes: true, | ||
|
||
// tslint:disable-next-line: no-bitwise | ||
nodeClassMask: NodeClassMask.Object | NodeClassMask.Variable, | ||
|
||
nodeId: conditionNodeId, | ||
referenceTypeId: resolveNodeId("HasChild"), | ||
resultMask: 63 | ||
}; | ||
const nodesToBrowse = [nodeToBrowse1, nodeToBrowse2]; | ||
const browseResults = await session.browse(nodesToBrowse); | ||
|
||
if (browseResults[1] && browseResults[1].references) { | ||
for (const ref of browseResults[1].references) { | ||
if (ref.nodeClass === NodeClass.Variable) { | ||
addField(ref.browseName.toString()); | ||
} | ||
deferObjectOrVariableInvestigation(ref.nodeId, ref.browseName.toString()); | ||
} | ||
} | ||
if (browseResults[0] && browseResults[0].references) { | ||
const promises = []; | ||
for (const reference of browseResults[0].references) { | ||
promises.push(_investigateLevel(reference.nodeId)); | ||
} | ||
await Promise.all(promises); | ||
} | ||
|
||
await _investigateObjectOrVariable(); | ||
} | ||
await _investigateLevel(conditionNodeId); | ||
|
||
const p = await extractFields(session, conditionNodeId); | ||
const fields1 = simpleBrowsePathsToString(p.map((a) => a.path)); | ||
// add this field which will always be added | ||
addField("ConditionId"); | ||
|
||
fields1.push("ConditionId"); | ||
return fields1; | ||
} |
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