-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathfoundation.ts
892 lines (824 loc) · 26.3 KB
/
foundation.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
import { css, html, LitElement, query } from 'lit-element';
import { nothing } from 'lit-html';
import {
cloneElement,
compareNames,
Create,
createElement,
Delete,
getSclSchemaVersion,
isPublic,
minAvailableLogicalNodeInstance,
} from '../../foundation.js';
import {
createTemplateStructure,
determineUninitializedStructure,
initializeElements,
} from '../../foundation/dai.js';
import { getFcdaReferences } from '../../foundation/ied.js';
import { SCL_NAMESPACE } from '../../schemas.js';
export enum View {
PUBLISHER,
SUBSCRIBER,
}
/**
* Enumeration stating the Subscribe status of a IED to a GOOSE or Sampled Value.
*/
export enum SubscribeStatus {
Full,
Partial,
None,
}
export interface ViewDetail {
view: View;
}
export type ViewEvent = CustomEvent<ViewDetail>;
export function newViewEvent(
view: View,
eventInitDict?: CustomEventInit<ViewDetail>
): ViewEvent {
return new CustomEvent<ViewDetail>('view', {
bubbles: true,
composed: true,
...eventInitDict,
detail: { view, ...eventInitDict?.detail },
});
}
export interface IEDSelectDetail {
ied: Element | undefined;
}
export type IEDSelectEvent = CustomEvent<IEDSelectDetail>;
export function newIEDSelectEvent(
ied: Element | undefined,
eventInitDict?: CustomEventInit<IEDSelectDetail>
): IEDSelectEvent {
return new CustomEvent<IEDSelectDetail>('ied-select', {
bubbles: true,
composed: true,
...eventInitDict,
detail: { ied, ...eventInitDict?.detail },
});
}
export interface FcdaSelectDetail {
control: Element | undefined;
fcda: Element | undefined;
}
export type FcdaSelectEvent = CustomEvent<FcdaSelectDetail>;
export function newFcdaSelectEvent(
control: Element | undefined,
fcda: Element | undefined,
eventInitDict?: CustomEventInit<FcdaSelectDetail>
): FcdaSelectEvent {
return new CustomEvent<FcdaSelectDetail>('fcda-select', {
bubbles: true,
composed: true,
...eventInitDict,
detail: { control, fcda, ...eventInitDict?.detail },
});
}
export interface SubscriptionChangedDetail {
control: Element | undefined;
fcda: Element | undefined;
}
export type SubscriptionChangedEvent = CustomEvent<SubscriptionChangedDetail>;
export function newSubscriptionChangedEvent(
control: Element | undefined,
fcda: Element | undefined,
eventInitDict?: CustomEventInit<SubscriptionChangedDetail>
): SubscriptionChangedEvent {
return new CustomEvent<SubscriptionChangedDetail>('subscription-changed', {
bubbles: true,
composed: true,
...eventInitDict,
detail: { control, fcda, ...eventInitDict?.detail },
});
}
export function getFcdaTitleValue(fcdaElement: Element): string {
return `${fcdaElement.getAttribute('doName')}${
fcdaElement.hasAttribute('doName') && fcdaElement.hasAttribute('daName')
? `.`
: ``
}${fcdaElement.getAttribute('daName')}`;
}
export function getFcdaSubtitleValue(fcdaElement: Element): string {
return `${fcdaElement.getAttribute('ldInst')} ${
fcdaElement.hasAttribute('ldInst') ? `/` : ''
}${
fcdaElement.getAttribute('prefix')
? ` ${fcdaElement.getAttribute('prefix')}`
: ''
} ${fcdaElement.getAttribute('lnClass')} ${fcdaElement.getAttribute(
'lnInst'
)}`;
}
export function existExtRef(
parentInputs: Element,
fcda: Element,
control: Element | undefined
): boolean {
return !!getExtRef(parentInputs, fcda, control);
}
export function getExtRef(
parentInputs: Element,
fcda: Element,
control: Element | undefined
): Element | undefined {
function createCriteria(attributeName: string, value: string | null): string {
if (value) {
return `[${attributeName}="${value}"]`;
}
return '';
}
const iedName = fcda.closest('IED')?.getAttribute('name');
if (!iedName) {
return undefined;
}
let controlCriteria = '';
if (control && getSclSchemaVersion(fcda.ownerDocument) !== '2003') {
controlCriteria = `[serviceType="${serviceTypes[control.tagName]!}"]`;
controlCriteria += createCriteria(
'srcLDInst',
control.closest('LDevice')?.getAttribute('inst') ?? null
);
controlCriteria += createCriteria(
'srcLNClass',
control.closest('LN0,LN')?.getAttribute('lnClass') ?? null
);
controlCriteria += createCriteria(
'srcLNInst',
control.closest('LN0,LN')?.getAttribute('inst') ?? null
);
controlCriteria += createCriteria(
'srcCBName',
control.getAttribute('name') ?? null
);
}
return Array.from(
parentInputs.querySelectorAll(
`ExtRef[iedName="${iedName}"]${getFcdaReferences(fcda)}${controlCriteria}`
)
).find(extRefElement => !extRefElement.hasAttribute('intAddr'));
}
export function canRemoveSubscriptionSupervision(
subscribedExtRef: Element
): boolean {
const [srcCBName, srcLDInst, srcLNClass, iedName, srcPrefix, srcLNInst] = [
'srcCBName',
'srcLDInst',
'srcLNClass',
'iedName',
'srcPrefix',
'srcLNInst',
].map(attr => subscribedExtRef.getAttribute(attr));
return !Array.from(
subscribedExtRef.closest('IED')?.getElementsByTagName('ExtRef') ?? []
)
.filter(isPublic)
.some(
extRef =>
(extRef.getAttribute('srcCBName') ?? '') === (srcCBName ?? '') &&
(extRef.getAttribute('srcLDInst') ?? '') === (srcLDInst ?? '') &&
(extRef.getAttribute('srcLNClass') ?? '') === (srcLNClass ?? '') &&
(extRef.getAttribute('iedName') ?? '') === (iedName ?? '') &&
(extRef.getAttribute('srcPrefix') ?? '') === (srcPrefix ?? '') &&
(extRef.getAttribute('srcLNInst') ?? '') === (srcLNInst ?? '') &&
extRef !== subscribedExtRef
);
}
/**
* Searches DataTypeTemplates for DOType>DA[valKind=Conf/RO][valImport=true] from an LN reference.
* @param lnElement - The LN Element to use for searching the starting DO Element.
* @returns - true if both conditions are found in the DA child element.
*/
function checksDataTypeTemplateConditions(lnElement: Element): boolean {
const rootNode = lnElement?.ownerDocument;
const lNodeType = lnElement.getAttribute('lnType');
const lnClass = lnElement.getAttribute('lnClass');
const dObj = rootNode.querySelector(
`DataTypeTemplates > LNodeType[id="${lNodeType}"][lnClass="${lnClass}"] > DO[name="${
lnClass === 'LGOS' ? 'GoCBRef' : 'SvCBRef'
}"]`
);
if (dObj) {
const dORef = dObj.getAttribute('type');
const daObj = rootNode.querySelector(
`DataTypeTemplates > DOType[id="${dORef}"] > DA[name="setSrcRef"]`
);
if (daObj) {
return (
(daObj.getAttribute('valKind') === 'Conf' ||
daObj.getAttribute('valKind') === 'RO') &&
daObj.getAttribute('valImport') === 'true'
);
}
}
// definition missing
return false;
}
/**
* Returns an array with a single Create action to create a new
* supervision element for the given GOOSE/SMV message and subscriber IED.
*
* @param controlBlock The GOOSE or SMV message element
* @param subscriberIED The subscriber IED
* @returns an empty array if instantiation is not possible or an array with a single Create action
*/
export function instantiateSubscriptionSupervision(
controlBlock: Element | undefined,
subscriberIED: Element | undefined
): Create[] {
const supervisionType =
controlBlock?.tagName === 'GSEControl' ? 'LGOS' : 'LSVS';
if (
!controlBlock ||
!subscriberIED ||
!isSupervisionAllowed(controlBlock, subscriberIED, supervisionType)
)
return [];
const availableLN = findOrCreateAvailableLNInst(
controlBlock,
subscriberIED,
supervisionType
);
if (!availableLN || !checksDataTypeTemplateConditions(availableLN)) return [];
// Then, create the templateStructure array
const templateStructure = createTemplateStructure(availableLN, [
controlBlock?.tagName === 'GSEControl' ? 'GoCBRef' : 'SvCBRef',
'setSrcRef',
]);
if (!templateStructure) return [];
// Determine where to start creating new elements (DOI/SDI/DAI)
const [parentElement, uninitializedTemplateStructure] =
determineUninitializedStructure(availableLN, templateStructure);
// // Next create all missing elements (DOI/SDI/DAI)
const newElement = initializeElements(uninitializedTemplateStructure);
newElement.querySelector('Val')!.textContent =
controlBlockReference(controlBlock);
const createActions: Create[] = [];
if (!availableLN.parentElement) {
const parent = subscriberIED.querySelector(
`LN[lnClass="${supervisionType}"]`
)?.parentElement;
if (parent)
createActions.push({
new: {
parent,
element: availableLN,
},
});
}
return createActions.concat([
{
new: {
parent: parentElement,
element: newElement,
},
},
]);
}
/**
* Return an array with a single Delete action to delete the supervision element
* for the given GOOSE/SMV message and subscriber IED.
*
* @param controlBlock The GOOSE or SMV message element
* @param subscriberIED The subscriber IED
* @returns an empty array if removing the supervision is not possible or an array
* with a single Delete action that removes the LN if it was created in OpenSCD
* or only the supervision structure DOI/DAI/Val if it was created by the user.
*/
export function removeSubscriptionSupervision(
controlBlock: Element | undefined,
subscriberIED: Element | undefined
): Delete[] {
if (!controlBlock || !subscriberIED) return [];
const supervisionType =
controlBlock?.tagName === 'GSEControl' ? 'LGOS' : 'LSVS';
const valElement = Array.from(
subscriberIED.querySelectorAll(
`LN[lnClass="${supervisionType}"]>DOI>DAI>Val,LN0[lnClass="${supervisionType}"]>DOI>DAI>Val`
)
).find(val => val.textContent == controlBlockReference(controlBlock));
if (!valElement) return [];
const lnElement = valElement.closest('LN0, LN');
if (!lnElement || !lnElement.parentElement) return [];
// Check if that one has been created by OpenSCD (private section exists)
const isOpenScdCreated = lnElement.querySelector(
'Private[type="OpenSCD.create"]'
);
return isOpenScdCreated
? [
{
old: {
parent: lnElement.parentElement,
element: lnElement,
},
},
]
: [
{
old: {
parent: lnElement,
element: valElement.closest('DOI')!,
},
},
];
}
/**
* Checks if the given combination of GOOSE/SMV message and subscriber IED
* allows for subscription supervision.
* @param controlBlock The GOOSE or SMV message element
* @param subscriberIED The subscriber IED
* @param supervisionType LSVS or LGOS
* @returns true if both controlBlock and subscriberIED meet the requirements for
* setting up a supervision for the specified supervision type or false if they don't
*/
function isSupervisionAllowed(
controlBlock: Element,
subscriberIED: Element,
supervisionType: string
): boolean {
if (getSclSchemaVersion(subscriberIED.ownerDocument) === '2003') return false;
if (subscriberIED.querySelector(`LN[lnClass="${supervisionType}"]`) === null)
return false;
if (
Array.from(
subscriberIED.querySelectorAll(
`LN[lnClass="${supervisionType}"]>DOI>DAI>Val`
)
).find(val => val.textContent == controlBlockReference(controlBlock))
)
return false;
if (
maxSupervisions(subscriberIED, controlBlock) <=
instantiatedSupervisionsCount(subscriberIED, controlBlock, supervisionType)
)
return false;
return true;
}
/** Returns an new or existing LN instance available for supervision instantiation
*
* @param controlBlock The GOOSE or SMV message element
* @param subscriberIED The subscriber IED
* @returns The LN instance or null if no LN instance could be found or created
*/
export function findOrCreateAvailableLNInst(
controlBlock: Element,
subscriberIED: Element,
supervisionType: string
): Element | null {
let availableLN = Array.from(
subscriberIED.querySelectorAll(`LN[lnClass="${supervisionType}"]`)
).find(
ln =>
ln.querySelector('DOI>DAI>Val') === null ||
ln.querySelector('DOI>DAI>Val')?.textContent === ''
);
if (!availableLN) {
availableLN = subscriberIED.ownerDocument.createElementNS(
SCL_NAMESPACE,
'LN'
);
const openScdTag = subscriberIED.ownerDocument.createElementNS(
SCL_NAMESPACE,
'Private'
);
openScdTag.setAttribute('type', 'OpenSCD.create');
availableLN.appendChild(openScdTag);
availableLN.setAttribute('lnClass', supervisionType);
const instantiatedSibling = subscriberIED
.querySelector(`LN[lnClass="${supervisionType}"]>DOI>DAI>Val`)
?.closest('LN');
if (!instantiatedSibling) return null;
availableLN.setAttribute(
'lnType',
instantiatedSibling.getAttribute('lnType') ?? ''
);
}
/* Before we return, we make sure that LN's inst is unique, non-empty
and also the minimum inst as the minimum of all available in the IED */
const inst = availableLN.getAttribute('inst') ?? '';
if (inst === '') {
const instNumber = minAvailableLogicalNodeInstance(
Array.from(
subscriberIED.querySelectorAll(`LN[lnClass="${supervisionType}"]`)
)
);
if (!instNumber) return null;
availableLN.setAttribute('inst', instNumber);
}
return availableLN;
}
/**
* Find the first ExtRef SCL element given a control and a subscribing IED
*
* @param publishedControlBlock - the control block SCL element in the publishing IED.
* @param subscribingIed - the subscribing IED SCL element.
* @returns The first ExtRef element associated with the subscribing IED and published control block.
*/
export function getFirstSubscribedExtRef(
publishedControlBlock: Element,
subscribingIed: Element
): Element | null {
const publishingIed = publishedControlBlock.closest('LN,LN0')!;
const dataSet = publishingIed.querySelector(
`DataSet[name="${publishedControlBlock.getAttribute('datSet')}"]`
);
let extRef: Element | undefined = undefined;
Array.from(
subscribingIed?.querySelectorAll('LN0 > Inputs, LN > Inputs')
).some(inputs => {
Array.from(dataSet!.querySelectorAll('FCDA')).some(fcda => {
const anExtRef = getExtRef(inputs, fcda, publishedControlBlock);
if (anExtRef) {
extRef = anExtRef;
return true;
}
return false;
});
return extRef !== undefined;
});
return extRef !== undefined ? extRef : null;
}
/** Returns the subscriber's supervision LN for a given control block and extRef element
*
* @param extRef - The extRef SCL element in the subscribing IED.
* @returns The supervision LN instance or null if not found
*/
export function getExistingSupervision(extRef: Element | null): Element | null {
if (extRef === null) return null;
const extRefValues = ['iedName', 'serviceType', 'srcPrefix', 'srcCBName'];
const [srcIedName, serviceType, srcPrefix, srcCBName] = extRefValues.map(
attr => extRef.getAttribute(attr) ?? ''
);
const supervisionType = serviceType === 'GOOSE' ? 'LGOS' : 'LSVS';
const refSelector =
supervisionType === 'LGOS' ? 'DOI[name="GoCBRef"]' : 'DOI[name="SvCBRef"]';
const srcLDInst =
extRef.getAttribute('srcLDInst') ?? extRef.getAttribute('ldInst');
const srcLNClass = extRef.getAttribute('srcLNClass') ?? 'LLN0';
const cbReference = `${srcIedName}${srcPrefix}${srcLDInst}/${srcLNClass}.${srcCBName}`;
const iedName = extRef.closest('IED')?.getAttribute('name');
const candidates = Array.from(
extRef.ownerDocument
.querySelector(`IED[name="${iedName}"]`)!
.querySelectorAll(
`LN[lnClass="${supervisionType}"]>${refSelector}>DAI[name="setSrcRef"]>Val`
)
).find(val => val.textContent === cbReference);
return candidates !== undefined ? candidates.closest('LN')! : null;
}
/**
* Counts the number of LN instances with proper supervision for the given control block set up.
*
* @param subscriberIED The subscriber IED
* @param controlBlock The GOOSE or SMV message element
* @returns The number of LN instances with a supervision set up
*/
export function instantiatedSupervisionsCount(
subscriberIED: Element,
controlBlock: Element,
supervisionType: string
): number {
const instantiatedValues = Array.from(
subscriberIED.querySelectorAll(
`LN[lnClass="${supervisionType}"]>DOI>DAI>Val`
)
).filter(val => val.textContent !== '');
return instantiatedValues.length;
}
/**
* Counts the max number of LN instances with supervision allowed for
* the given control block's type of message.
*
* @param subscriberIED The subscriber IED
* @param controlBlock The GOOSE or SMV message element
* @returns The max number of LN instances with supervision allowed
*/
export function maxSupervisions(
subscriberIED: Element,
controlBlock: Element
): number {
const maxAttr = controlBlock.tagName === 'GSEControl' ? 'maxGo' : 'maxSv';
const maxValues = parseInt(
subscriberIED
.querySelector('Services>SupSubscription')
?.getAttribute(maxAttr) ?? '0',
10
);
return isNaN(maxValues) ? 0 : maxValues;
}
/**
* Creates a string pointer to the control block element.
*
* @param controlBlock The GOOSE or SMV message element
* @returns null if the control block is undefined or a string pointer to the control block element
*/
export function controlBlockReference(
controlBlock: Element | undefined
): string | null {
if (!controlBlock) return null;
const anyLn = controlBlock.closest('LN,LN0');
const prefix = anyLn?.getAttribute('prefix') ?? '';
const lnClass = anyLn?.getAttribute('lnClass');
const lnInst = anyLn?.getAttribute('inst') ?? '';
const ldInst = controlBlock.closest('LDevice')?.getAttribute('inst');
const iedName = controlBlock.closest('IED')?.getAttribute('name');
const cbName = controlBlock.getAttribute('name');
if (!cbName && !iedName && !ldInst && !lnClass) return null;
return `${iedName}${ldInst}/${prefix}${lnClass}${lnInst}.${cbName}`;
}
export function canCreateValidExtRef(
fcda: Element,
controlBlock: Element | undefined
): boolean {
const iedName = fcda.closest('IED')?.getAttribute('name');
const [ldInst, lnClass, lnInst, doName] = [
'ldInst',
'lnClass',
'lnInst',
'doName',
].map(attr => fcda.getAttribute(attr));
if (!iedName || !ldInst || !lnClass || !lnInst || !doName) {
return false;
}
// For 2003 schema or serviceType `Poll`, the extra fields aren't needed.
if (
getSclSchemaVersion(fcda.ownerDocument) === '2003' ||
controlBlock === undefined
) {
return true;
}
const srcLDInst = controlBlock.closest('LDevice')?.getAttribute('inst');
const srcLNClass = controlBlock.closest('LN0,LN')?.getAttribute('lnClass');
const srcLNInst = controlBlock.closest('LN0,LN')?.getAttribute('inst');
const srcCBName = controlBlock.getAttribute('name');
// For srcLNInst an empty string is allowed in `LN0`
return !(
!srcLDInst ||
!srcLNClass ||
!srcCBName ||
typeof srcLNInst !== 'string'
);
}
export const serviceTypes: Partial<Record<string, string>> = {
ReportControl: 'Report',
GSEControl: 'GOOSE',
SampledValueControl: 'SMV',
};
/**
* Create a new ExtRef Element depending on the SCL Edition copy attributes from the Control Element,
* FCDA Element and related Elements.
*
* @param controlElement - `ReportControl`, `GSEControl` or `SampledValueControl` source element
* @param fcdaElement - The source data attribute element.
* @returns The new created ExtRef element, which can be added to the document.
*/
export function createExtRefElement(
controlElement: Element | undefined,
fcdaElement: Element
): Element {
const iedName = fcdaElement.closest('IED')?.getAttribute('name') ?? null;
const [ldInst, prefix, lnClass, lnInst, doName, daName] = [
'ldInst',
'prefix',
'lnClass',
'lnInst',
'doName',
'daName',
].map(attr => fcdaElement.getAttribute(attr));
if (getSclSchemaVersion(fcdaElement.ownerDocument) === '2003') {
// Edition 2003(1) does not define serviceType and its MCD attribute starting with src...
return createElement(fcdaElement.ownerDocument, 'ExtRef', {
iedName,
ldInst,
lnClass,
lnInst,
prefix,
doName,
daName,
});
}
if (!controlElement || !serviceTypes[controlElement.tagName]) {
//for invalid control block tag name assume polling
return createElement(fcdaElement.ownerDocument, 'ExtRef', {
iedName,
serviceType: 'Poll',
ldInst,
lnClass,
lnInst,
prefix,
doName,
daName,
});
}
// default is empty string as attributes are mandatory acc to IEC 61850-6 >Ed2
const srcLDInst =
controlElement.closest('LDevice')?.getAttribute('inst') ?? '';
const srcPrefix =
controlElement.closest('LN0,LN')?.getAttribute('prefix') ?? '';
const srcLNClass =
controlElement.closest('LN0,LN')?.getAttribute('lnClass') ?? '';
const srcLNInst = controlElement.closest('LN0,LN')?.getAttribute('inst');
const srcCBName = controlElement.getAttribute('name') ?? '';
return createElement(fcdaElement.ownerDocument, 'ExtRef', {
iedName,
serviceType: serviceTypes[controlElement.tagName]!,
ldInst,
lnClass,
lnInst,
prefix,
doName,
daName,
srcLDInst,
srcPrefix,
srcLNClass,
srcLNInst: srcLNInst ? srcLNInst : null,
srcCBName,
});
}
/**
* Create a clone of the passed ExtRefElement and updated or set the required attributes on the cloned element
* depending on the Edition and type of Control Element.
*
* @param extRefElement - The ExtRef Element to clone and update.
* @param controlElement - `ReportControl`, `GSEControl` or `SampledValueControl` source element
* @param fcdaElement - The source data attribute element.
* @returns A cloned ExtRef Element with updated information to be used for example in a Replace Action.
*/
export function updateExtRefElement(
extRefElement: Element,
controlElement: Element | undefined,
fcdaElement: Element
): Element {
const iedName = fcdaElement.closest('IED')?.getAttribute('name') ?? null;
const [ldInst, prefix, lnClass, lnInst, doName, daName] = [
'ldInst',
'prefix',
'lnClass',
'lnInst',
'doName',
'daName',
].map(attr => fcdaElement.getAttribute(attr));
if (getSclSchemaVersion(fcdaElement.ownerDocument) === '2003') {
// Edition 2003(1) does not define serviceType and its MCD attribute starting with src...
return cloneElement(extRefElement, {
iedName,
serviceType: null,
ldInst,
lnClass,
lnInst,
prefix,
doName,
daName,
srcLDInst: null,
srcPrefix: null,
srcLNClass: null,
srcLNInst: null,
srcCBName: null,
});
}
if (!controlElement || !serviceTypes[controlElement.tagName]) {
//for invalid control block tag name assume polling
return cloneElement(extRefElement, {
iedName,
serviceType: 'Poll',
ldInst,
lnClass,
lnInst,
prefix,
doName,
daName,
srcLDInst: null,
srcPrefix: null,
srcLNClass: null,
srcLNInst: null,
srcCBName: null,
});
}
const srcLDInst =
controlElement.closest('LDevice')?.getAttribute('inst') ?? '';
const srcPrefix =
controlElement.closest('LN0,LN')?.getAttribute('prefix') ?? '';
const srcLNClass =
controlElement.closest('LN0,LN')?.getAttribute('lnClass') ?? '';
const srcLNInst = controlElement.closest('LN0,LN')?.getAttribute('inst');
const srcCBName = controlElement.getAttribute('name') ?? '';
return cloneElement(extRefElement, {
iedName,
serviceType: serviceTypes[controlElement.tagName]!,
ldInst,
lnClass,
lnInst,
prefix,
doName,
daName,
srcLDInst,
srcPrefix,
srcLNClass,
srcLNInst: srcLNInst ? srcLNInst : null,
srcCBName,
});
}
export function getOrderedIeds(doc: XMLDocument): Element[] {
return doc
? Array.from(doc.querySelectorAll(':root > IED')).sort((a, b) =>
compareNames(a, b)
)
: [];
}
/**
* An element within this list has 2 properties:
* - The element itself, either a GSEControl or an IED at this point.
* - A 'partial' property indicating if the GOOSE is fully initialized or partially.
*/
export interface ListElement {
element: Element;
partial?: boolean;
}
export class SubscriberListContainer extends LitElement {
/** List holding all current subscribed Elements. */
subscribedElements: ListElement[] = [];
/** List holding all current available Elements which are not subscribed. */
availableElements: ListElement[] = [];
/** Current selected IED (when in Subscriber view) */
currentSelectedIed: Element | undefined;
/** The current used dataset for subscribing / unsubscribing */
currentUsedDataset: Element | undefined | null;
@query('div') subscriberWrapper!: Element;
protected updated(): void {
if (this.subscriberWrapper) {
this.subscriberWrapper.scrollTo(0, 0);
}
}
protected resetElements(): void {
this.subscribedElements = [];
this.availableElements = [];
}
}
/** Common `CSS` styles used by DataTypeTemplate subeditors */
export const styles = css`
:host(.moving) section {
opacity: 0.3;
}
section {
background-color: var(--mdc-theme-surface);
transition: all 200ms linear;
outline-color: var(--mdc-theme-primary);
outline-style: solid;
outline-width: 0px;
opacity: 1;
}
section:focus {
box-shadow: 0 8px 10px 1px rgba(0, 0, 0, 0.14),
0 3px 14px 2px rgba(0, 0, 0, 0.12), 0 5px 5px -3px rgba(0, 0, 0, 0.2);
}
section:focus-within {
outline-width: 2px;
transition: all 250ms linear;
}
h1,
h2,
h3 {
color: var(--mdc-theme-on-surface);
font-family: 'Roboto', sans-serif;
font-weight: 300;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
margin: 0px;
line-height: 48px;
padding-left: 0.3em;
transition: background-color 150ms linear;
}
section:focus-within > h1,
section:focus-within > h2,
section:focus-within > h3 {
color: var(--mdc-theme-surface);
background-color: var(--mdc-theme-primary);
transition: background-color 200ms linear;
}
h1 > nav,
h2 > nav,
h3 > nav,
h1 > abbr > mwc-icon-button,
h2 > abbr > mwc-icon-button,
h3 > abbr > mwc-icon-button {
float: right;
}
abbr[title] {
border-bottom: none !important;
cursor: inherit !important;
text-decoration: none !important;
}
mwc-list-item[noninteractive] {
font-weight: 500;
}
`;
declare global {
interface ElementEventMap {
['view']: ViewEvent;
['ied-select']: IEDSelectEvent;
['fcda-select']: FcdaSelectEvent;
['subscription-changed']: SubscriptionChangedEvent;
}
}