|
| 1 | +import { NamingDescription, describeNaming } from "./Naming.js"; |
| 2 | + |
| 3 | +function compareExtRefDescription( |
| 4 | + a: ExtRefDescription, |
| 5 | + b: ExtRefDescription, |
| 6 | +): number { |
| 7 | + const stringifiedA = JSON.stringify(a); |
| 8 | + const stringifiedB = JSON.stringify(b); |
| 9 | + |
| 10 | + if (stringifiedA < stringifiedB) return -1; |
| 11 | + if (stringifiedA > stringifiedB) return 1; |
| 12 | + return 0; |
| 13 | +} |
| 14 | + |
| 15 | +interface ExtRefDescription { |
| 16 | + /** Source IED name attribute */ |
| 17 | + iedName?: string; |
| 18 | + /** Source LDevice inst attribute */ |
| 19 | + ldInst?: string; |
| 20 | + /** Source AnyLn prefix attribute */ |
| 21 | + prefix?: string; |
| 22 | + /** Source AnyLn lnClass attribute */ |
| 23 | + lnClass?: string; |
| 24 | + /** Source AnyLn lnInst attribute */ |
| 25 | + lnInst?: string; |
| 26 | + /** Source data object(s) */ |
| 27 | + doName?: string; |
| 28 | + /** Source data attributes(s) */ |
| 29 | + daName?: string; |
| 30 | + /** ExtRef attribute instAddr attribute */ |
| 31 | + intAddr?: string; |
| 32 | + /** Source control block name attribute */ |
| 33 | + srcCBName?: string; |
| 34 | + /** Source control block parent LDevice inst attribute */ |
| 35 | + srcLDInst?: string; |
| 36 | + /** Source control block parent AnyLn prefix attribute */ |
| 37 | + srcPrefix?: string; |
| 38 | + /** Source control block parent AnyLn lnInst attribute */ |
| 39 | + srcLNClass?: string; |
| 40 | + /** Source control block parent AnyLn inst attribute */ |
| 41 | + srcLNInst?: string; |
| 42 | + /** Source control block type */ |
| 43 | + serviceType?: "GOOSE" | "Report" | "SMV" | "Poll"; |
| 44 | + /** Restriction logical node class */ |
| 45 | + pLN?: string; |
| 46 | + /** Restriction data object name(s) */ |
| 47 | + pDO?: string; |
| 48 | + /** Restriction data attribute name(s) */ |
| 49 | + pDA?: string; |
| 50 | + /** Restriction control block type */ |
| 51 | + pServT?: "GOOSE" | "Report" | "SMV" | "Poll"; |
| 52 | +} |
| 53 | + |
| 54 | +function describeExtRef(element: Element): ExtRefDescription { |
| 55 | + const extRefDesc: ExtRefDescription = {}; |
| 56 | + |
| 57 | + const [ |
| 58 | + iedName, |
| 59 | + ldInst, |
| 60 | + prefix, |
| 61 | + lnClass, |
| 62 | + lnInst, |
| 63 | + doName, |
| 64 | + daName, |
| 65 | + intAddr, |
| 66 | + srcCBName, |
| 67 | + srcLDInst, |
| 68 | + srcPrefix, |
| 69 | + srcLNClass, |
| 70 | + srcLNInst, |
| 71 | + serviceType, |
| 72 | + pLN, |
| 73 | + pDO, |
| 74 | + pDA, |
| 75 | + pServT, |
| 76 | + ] = [ |
| 77 | + "iedName", |
| 78 | + "ldInst", |
| 79 | + "prefix", |
| 80 | + "lnClass", |
| 81 | + "lnInst", |
| 82 | + "doName", |
| 83 | + "daName", |
| 84 | + "intAddr", |
| 85 | + "srcCBName", |
| 86 | + "srcLDInst", |
| 87 | + "srcPrefix", |
| 88 | + "srcLNClass", |
| 89 | + "srcLNInst", |
| 90 | + "serviceType", |
| 91 | + "pLN", |
| 92 | + "pDO", |
| 93 | + "pDA", |
| 94 | + "pServT", |
| 95 | + ].map((attr) => element.getAttribute(attr)); |
| 96 | + |
| 97 | + if (iedName) extRefDesc.iedName = iedName; |
| 98 | + if (ldInst) extRefDesc.ldInst = ldInst; |
| 99 | + if (prefix) extRefDesc.prefix = prefix; |
| 100 | + if (lnClass) extRefDesc.lnClass = lnClass; |
| 101 | + if (lnInst) extRefDesc.lnInst = lnInst; |
| 102 | + if (doName) extRefDesc.doName = doName; |
| 103 | + if (daName) extRefDesc.daName = daName; |
| 104 | + if (lnInst) extRefDesc.lnInst = lnInst; |
| 105 | + if (intAddr) extRefDesc.intAddr = intAddr; |
| 106 | + if (srcCBName) extRefDesc.srcCBName = srcCBName; |
| 107 | + if (srcLDInst) extRefDesc.srcLDInst = srcLDInst; |
| 108 | + if (srcPrefix) extRefDesc.srcPrefix = srcPrefix; |
| 109 | + if (srcLNClass) extRefDesc.srcLNClass = srcLNClass; |
| 110 | + if (srcLNInst) extRefDesc.srcLNInst = srcLNInst; |
| 111 | + if (serviceType && ["Report", "SMV", "GOOSE", "Poll"].includes(serviceType)) |
| 112 | + extRefDesc.serviceType = serviceType as "Report" | "SMV" | "GOOSE" | "Poll"; |
| 113 | + if (pLN) extRefDesc.pLN = pLN; |
| 114 | + if (pDO) extRefDesc.pDO = pDO; |
| 115 | + if (pDA) extRefDesc.pDA = pDA; |
| 116 | + if (pServT && ["Report", "SMV", "GOOSE", "Poll"].includes(pServT)) |
| 117 | + extRefDesc.pServT = pServT as "Report" | "SMV" | "GOOSE" | "Poll"; |
| 118 | + |
| 119 | + return extRefDesc; |
| 120 | +} |
| 121 | + |
| 122 | +export interface InputsDescription extends NamingDescription { |
| 123 | + extRefs: ExtRefDescription[]; |
| 124 | +} |
| 125 | + |
| 126 | +export function describeInputs(element: Element): InputsDescription { |
| 127 | + const inputsDesc: InputsDescription = { |
| 128 | + ...describeNaming(element), |
| 129 | + extRefs: [], |
| 130 | + }; |
| 131 | + |
| 132 | + inputsDesc.extRefs.push( |
| 133 | + ...Array.from(element.children) |
| 134 | + .filter((child) => child.tagName === "ExtRef") |
| 135 | + .map((extRef) => describeExtRef(extRef)) |
| 136 | + .sort(compareExtRefDescription), |
| 137 | + ); |
| 138 | + |
| 139 | + return inputsDesc; |
| 140 | +} |
0 commit comments