|
| 1 | +import { expect } from "chai"; |
| 2 | +import { LN } from "./LN.js"; |
| 3 | +import { LNodeType, isLNodeTypeDescription } from "./LNodeType.js"; |
| 4 | +import { LN0 } from "./LN0.js"; |
| 5 | + |
| 6 | +const scl = new DOMParser().parseFromString( |
| 7 | + `<SCL xmlns="http://www.iec.ch/61850/2003/SCL" > |
| 8 | + <IED name="IED1"> |
| 9 | + <AccessPoint name="AP1"> |
| 10 | + <Server> |
| 11 | + <LDevice inst="lDevice1"> |
| 12 | + <LN0 lnClass="LLN0" inst="" lnType="LLN0"> |
| 13 | + <DataSet name="baseDataSet" > |
| 14 | + <FCDA iedName="IED1" ldInst="lDevice" lnClass="XCBR" lnInst="1" doName="Pos" daName="stVal" fc="ST" /> |
| 15 | + <FCDA iedName="IED1" ldInst="lDevice" prefix="" lnClass="XCBR" lnInst="1" doName="Pos" daName="q" fc="ST" /> |
| 16 | + <FCDA iedName="IED1" ldInst="lDevice" lnClass="LLN0" doName="Beh" daName="stVal" fc="ST" /> |
| 17 | + <FCDA iedName="IED1" ldInst="lDevice" prefix="" lnClass="LLN0" lnInst="" doName="Beh" fc="ST" /> |
| 18 | + </DataSet> |
| 19 | + <DOI name="Beh" > |
| 20 | + <DAI name="stVal"> |
| 21 | + <Val>on</Val> |
| 22 | + </DAI> |
| 23 | + </DOI> |
| 24 | + <GSEControl name="gse1" datSet="baseDataSet" /> |
| 25 | + <GSEControl name="gse2" /> |
| 26 | + <SampledValueControl name="smv1" datSet="baseDataSet" smpRate="80" nofASDU="1" > |
| 27 | + <SmvOpts /> |
| 28 | + </SampledValueControl> |
| 29 | + <SampledValueControl name="smv2" smpRate="80" nofASDU="1" > |
| 30 | + <SmvOpts /> |
| 31 | + </SampledValueControl> |
| 32 | + <LogControl name="anotherLog" logName="logName" /> |
| 33 | + <LogControl name="log" dataSet="baseDataSet" logName="logName" reasonCode="true" logEna="true" intgPd="0" bufTime="0" > |
| 34 | + <TrgOps dchg="false" qchg="false" dupd="false" period="false" gi="false" /> |
| 35 | + </LogControl> |
| 36 | + <ReportControl name="report" datSet="baseDataSet" intgPd="0" indexed="true" buffered="true" bufTime="0" confRev="0" > |
| 37 | + <TrgOps dchg="false" qchg="false" dupd="false" period="false" gi="false" /> |
| 38 | + <OptFields seqNum="false" timeStamp="false" dataSet="false" reasonCode="false" dataRef="false" entryID="false" configRef="false" bufOvfl="false" /> |
| 39 | + <RptEnabled max="0" /> |
| 40 | + </ReportControl> |
| 41 | + <ReportControl name="anotherReport" /> |
| 42 | + <Log name="someLog" /> |
| 43 | + <Log name="someOtherLog" /> |
| 44 | + <Inputs> |
| 45 | + <ExtRef intAddr="Beh.t" pLN="LLN0" pDO="Beh" pDA="t" pServT="GOOSE" /> |
| 46 | + </Inputs> |
| 47 | + <SettingControl numOfSGs="4" /> |
| 48 | + </LN0> |
| 49 | + </LDevice> |
| 50 | + <LDevice inst="lDevice2"> |
| 51 | + <LN0 lnClass="LLN0" inst="" lnType="LLN02" > |
| 52 | + <DataSet name="equalDataSet" > |
| 53 | + <FCDA iedName="IED1" ldInst="lDevice" prefix="" lnClass="XCBR" lnInst="1" doName="Pos" daName="stVal" fc="ST" /> |
| 54 | + <FCDA iedName="IED1" ldInst="lDevice" lnClass="XCBR" lnInst="1" doName="Pos" daName="q" fc="ST" /> |
| 55 | + <FCDA iedName="IED1" ldInst="lDevice" prefix="" lnClass="LLN0" lnInst="" doName="Beh" daName="stVal" fc="ST" /> |
| 56 | + <FCDA iedName="IED1" ldInst="lDevice" lnClass="LLN0" doName="Beh" fc="ST" /> |
| 57 | + </DataSet> |
| 58 | + <GSEControl name="gse2" /> |
| 59 | + <GSEControl name="gse1" datSet="equalDataSet" /> |
| 60 | + <SampledValueControl name="smv2" smpRate="80" nofASDU="1" > |
| 61 | + <SmvOpts /> |
| 62 | + </SampledValueControl> |
| 63 | + <SampledValueControl name="smv1" datSet="equalDataSet" smpRate="80" nofASDU="1" > |
| 64 | + <SmvOpts /> |
| 65 | + </SampledValueControl> |
| 66 | + <LogControl name="log" dataSet="equalDataSet" logName="logName" /> |
| 67 | + <LogControl name="anotherLog" logName="logName" /> |
| 68 | + <ReportControl name="anotherReport" /> |
| 69 | + <ReportControl name="report" datSet="equalDataSet" /> |
| 70 | + <Log name="someOtherLog" /> |
| 71 | + <Log name="someLog" /> |
| 72 | + <Inputs> |
| 73 | + <ExtRef intAddr="Beh.t" pLN="LLN0" pDO="Beh" pDA="t" pServT="GOOSE" /> |
| 74 | + </Inputs> |
| 75 | + <SettingControl numOfSGs="4" /> |
| 76 | + </LN0> |
| 77 | + </LDevice> |
| 78 | + <LDevice inst="lDevice3"> |
| 79 | + <LN0 lnClass="LLN0" inst="" lnType="LLN0" > |
| 80 | + <DOI name="Beh" > |
| 81 | + <DAI name="stVal"> |
| 82 | + <Val>test</Val> |
| 83 | + </DAI> |
| 84 | + </DOI> |
| 85 | + <Inputs> |
| 86 | + <ExtRef intAddr="A.phsA" pLN="MMXU" pDO="A.phsA" pDA="cVal.mag.f" pServT="SMV" /> |
| 87 | + </Inputs> |
| 88 | + </LN0> |
| 89 | + </LDevice> |
| 90 | + <LDevice inst="lDevice4" > |
| 91 | + <LN0 lnClass="LLN0" inst="" lnType="diffLLN0" /> |
| 92 | + </LDevice> |
| 93 | + <LDevice inst="lDevice5" > |
| 94 | + <LN0 lnClass="LLN0" /> |
| 95 | + </LDevice> |
| 96 | + <LDevice inst="lDevice6" > |
| 97 | + <LN0 lnClass="LLN0" lnType="invalidReference" /> |
| 98 | + </LDevice> |
| 99 | + <LDevice inst="lDevice7" > |
| 100 | + <LN0 lnClass="LLN0" lnType="invalidLLN0" /> |
| 101 | + </LDevice> |
| 102 | + </Server> |
| 103 | + </AccessPoint> |
| 104 | + </IED> |
| 105 | + <DataTypeTemplates> |
| 106 | + <LNodeType id="invalidLLN0" desc="desc" lnType="lnType" /> |
| 107 | + <LNodeType id="LLN0" desc="desc" lnClass="LLN0"> |
| 108 | + <DO name="Beh" type="BehENS"/> |
| 109 | + </LNodeType> |
| 110 | + <LNodeType id="LLN02" desc="desc" lnClass="LLN0"> |
| 111 | + <DO name="Beh" type="BehENS2"/> |
| 112 | + </LNodeType> |
| 113 | + <LNodeType id="diffLLN0" desc="desc" lnClass="LLN0"> |
| 114 | + <DO name="Beh" type="diffBehENS"/> |
| 115 | + </LNodeType> |
| 116 | + <DOType cdc="ENS" id="BehENS" > |
| 117 | + <DA name="stVal" bType="Enum" type="BehModKind" fc="ST" > |
| 118 | + <Val>off</Val> |
| 119 | + </DA> |
| 120 | + </DOType> |
| 121 | + <DOType cdc="ENS" id="BehENS2" > |
| 122 | + <DA name="stVal" bType="Enum" type="BehModKind" fc="ST" > |
| 123 | + <Val>on</Val> |
| 124 | + </DA> |
| 125 | + </DOType> |
| 126 | + <DOType id="diffBehENS" cdc="ENS" > |
| 127 | + <DA name="stVal" bType="Enum" type="BehModKind" fc="ST" > |
| 128 | + <Val>on</Val> |
| 129 | + </DA> |
| 130 | + <DA name="q" bType="Quality" fc="ST" /> |
| 131 | + </DOType> |
| 132 | + <EnumType id="BehModKind" > |
| 133 | + <EnumVal ord="1">on</EnumVal> |
| 134 | + <EnumVal ord="3">test</EnumVal> |
| 135 | + <EnumVal ord="5">off</EnumVal> |
| 136 | + </EnumType> |
| 137 | + <EnumType id="diffBehModKind" > |
| 138 | + <EnumVal ord="1">on</EnumVal> |
| 139 | + <EnumVal ord="3">test</EnumVal> |
| 140 | + </EnumType> |
| 141 | + </DataTypeTemplates> |
| 142 | + </SCL>`, |
| 143 | + "application/xml" |
| 144 | +); |
| 145 | + |
| 146 | +const missingLnType = scl.querySelector('LDevice[inst="lDevice5"] > LN0')!; |
| 147 | +const invalidLnType = scl.querySelector('LDevice[inst="lDevice6"] > LN0')!; |
| 148 | +const invalidLnTypeDescription = scl.querySelector( |
| 149 | + 'LDevice[inst="lDevice7"] > LN0' |
| 150 | +)!; |
| 151 | + |
| 152 | +const baseLLN0 = scl.querySelector(`LDevice[inst="lDevice1"] > LN0`)!; |
| 153 | +const equalLLN0 = scl.querySelector('LDevice[inst="lDevice2"] > LN0')!; |
| 154 | +const diffLLN0 = scl.querySelector('LDevice[inst="lDevice3"] > LN0')!; |
| 155 | +const diffEnumType = scl.querySelector('LDevice[inst="lDevice4"] > LN0')!; |
| 156 | + |
| 157 | +describe("Description for SCL schema type LN0", () => { |
| 158 | + it("returns undefined with missing lnType attribute", () => |
| 159 | + expect(LN0(missingLnType)).to.be.undefined); |
| 160 | + |
| 161 | + it("returns undefined with invalid lnType attribute", () => |
| 162 | + expect(LN0(invalidLnType)).to.be.undefined); |
| 163 | + |
| 164 | + it("returns undefined with invalid LNodeType description", () => |
| 165 | + expect(LN0(invalidLnTypeDescription)).to.be.undefined); |
| 166 | + |
| 167 | + it("return logical node structure in lnType key", () => |
| 168 | + expect(LN0(baseLLN0)?.lnType).to.satisfy(isLNodeTypeDescription)); |
| 169 | + |
| 170 | + it("returns same description with semantically equal LN0's", () => { |
| 171 | + expect(JSON.stringify(LN0(baseLLN0))).to.equal( |
| 172 | + JSON.stringify(LN0(equalLLN0)) |
| 173 | + ); |
| 174 | + }); |
| 175 | + |
| 176 | + it("returns different description with unequal LN0 elements", () => { |
| 177 | + expect(JSON.stringify(LN0(baseLLN0))).to.not.equal( |
| 178 | + JSON.stringify(LN0(diffLLN0)) |
| 179 | + ); |
| 180 | + expect(JSON.stringify(LN0(baseLLN0))).to.not.equal( |
| 181 | + JSON.stringify(LN0(diffEnumType)) |
| 182 | + ); |
| 183 | + }); |
| 184 | +}); |
0 commit comments