Skip to content

Commit c047707

Browse files
author
Dennis Labordus
authored
Merge pull request openscd#804 from openscd/104-handle-inverted
feat(104/Address): Changed handling when/how Address with inverted attribute are created
2 parents 8381d52 + 76f227e commit c047707

File tree

6 files changed

+108
-83
lines changed

6 files changed

+108
-83
lines changed

src/editors/protocol104/foundation/cdc.ts

Lines changed: 49 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ export const supportedCdcTypes =
1111
'SEC', 'SPC', 'SPG', 'SPS'] as const;
1212
export type SupportedCdcType = typeof supportedCdcTypes[number];
1313

14-
export type CreateFunction = (daiElement: Element, selectedTi: string) => Create[];
14+
export type CreateFunction = (daiElement: Element, selectedTi: string, inverted: boolean) => Create[];
15+
export interface TiInformation {
16+
filter: string;
17+
create: CreateFunction;
18+
inverted?: boolean;
19+
}
1520

1621
/**
1722
* Record with configuration information on how to create Address elements for the 104 protocol.
@@ -25,14 +30,8 @@ export type CreateFunction = (daiElement: Element, selectedTi: string) => Create
2530
export const cdcProcessings: Record<
2631
SupportedCdcType,
2732
{
28-
monitor: Record<string, {
29-
filter: string;
30-
create: CreateFunction;
31-
}>,
32-
control: Record<string, {
33-
filter: string;
34-
create: CreateFunction;
35-
}>,
33+
monitor: Record<string, TiInformation>,
34+
control: Record<string, TiInformation>,
3635
}
3736
> = {
3837
ACT: {
@@ -43,11 +42,12 @@ export const cdcProcessings: Record<
4342
':scope > DAI[name="phsB"], ' +
4443
':scope > DAI[name="phsC"], ' +
4544
':scope > DAI[name="neut"]',
46-
create: createSingleAddressAction
45+
create: createAddressAction,
46+
inverted: true
4747
},
4848
'39': {
4949
filter: ':scope > DAI[name="general"]',
50-
create: createSingleAddressAction
50+
create: createAddressAction
5151
}
5252
},
5353
control: {}
@@ -56,21 +56,21 @@ export const cdcProcessings: Record<
5656
monitor: {
5757
'36': {
5858
filter: ':scope > SDI[name="mxVal"] > DAI[name="f"]',
59-
create: createSingleAddressAction
59+
create: createAddressAction
6060
},
6161
},
6262
control: {
6363
'63': {
6464
filter: ':scope > SDI[name="Oper"] > SDI[name="ctlVal"] > DAI[name="f"]',
65-
create: createSingleAddressAction
65+
create: createAddressAction
6666
},
6767
}
6868
},
6969
ASG: {
7070
monitor: {
7171
'63': {
7272
filter: ':scope > SDI[name="setMag"] > DAI[name="f"]',
73-
create: createSingleAddressAction
73+
create: createAddressAction
7474
}
7575
},
7676
control: {}
@@ -79,13 +79,13 @@ export const cdcProcessings: Record<
7979
monitor: {
8080
'36': {
8181
filter: ':scope > SDI[name="mxVal"] > DAI[name="f"]',
82-
create: createSingleAddressAction
82+
create: createAddressAction
8383
},
8484
},
8585
control: {
8686
'60': {
8787
filter: ':scope > SDI[name="Oper"] > DAI[name="ctlVal"]',
88-
create: createSingleAddressAction
88+
create: createAddressAction
8989
},
9090
}
9191
},
@@ -94,7 +94,7 @@ export const cdcProcessings: Record<
9494
'37': {
9595
filter: ':scope > DAI[name="actVal"], ' +
9696
':scope > DAI[name="frVal"]',
97-
create: createSingleAddressAction
97+
create: createAddressAction
9898
},
9999
},
100100
control: {}
@@ -103,13 +103,13 @@ export const cdcProcessings: Record<
103103
monitor: {
104104
'32': {
105105
filter: ':scope > SDI[name="valWTr"] > DAI[name="posVal"]',
106-
create: createSingleAddressAction
106+
create: createAddressAction
107107
},
108108
},
109109
control: {
110110
'60': {
111111
filter: ':scope > SDI[name="Oper"] > DAI[name=“ctlVal”]',
112-
create: createSingleAddressAction
112+
create: createAddressAction
113113
},
114114
}
115115
},
@@ -118,12 +118,12 @@ export const cdcProcessings: Record<
118118
'35': {
119119
filter: ':scope > SDI[name="mag"] > DAI[name="i"], ' +
120120
':scope > SDI[name="ang"] > DAI[name="i"]',
121-
create: createSingleAddressAction
121+
create: createAddressAction
122122
},
123123
'36': {
124124
filter: ':scope > SDI[name="mag"] > DAI[name="f"], ' +
125125
':scope > SDI[name="ang"] > DAI[name="f"]',
126-
create: createSingleAddressAction
126+
create: createAddressAction
127127
}
128128
},
129129
control: {}
@@ -132,21 +132,21 @@ export const cdcProcessings: Record<
132132
monitor: {
133133
'31': {
134134
filter: ':scope > DAI[name="stVal"]',
135-
create: createSingleAddressAction
135+
create: createAddressAction
136136
},
137137
},
138138
control: {
139139
'59': {
140140
filter: ':scope > SDI[name="Oper"] > DAI[name="ctlVal"]',
141-
create: createSingleAddressAction
141+
create: createAddressAction
142142
},
143143
}
144144
},
145145
DPS: {
146146
monitor: {
147147
'31': {
148148
filter: ':scope > DAI[name="stVal"]',
149-
create: createSingleAddressAction
149+
create: createAddressAction
150150
}
151151
},
152152
control: {}
@@ -155,21 +155,21 @@ export const cdcProcessings: Record<
155155
monitor: {
156156
'35': {
157157
filter: ':scope > DAI[name="stVal"]',
158-
create: createSingleAddressAction
158+
create: createAddressAction
159159
},
160160
},
161161
control: {
162162
'62': {
163163
filter: ':scope > SDI[name="Oper"] > DAI[name="ctlVal"]',
164-
create: createSingleAddressAction
164+
create: createAddressAction
165165
},
166166
}
167167
},
168168
ING: {
169169
monitor: {
170170
'62': {
171171
filter: ':scope > DAI[name="setVal"]',
172-
create: createSingleAddressAction
172+
create: createAddressAction
173173
}
174174
},
175175
control: {}
@@ -178,15 +178,16 @@ export const cdcProcessings: Record<
178178
monitor: {
179179
'30': {
180180
filter: ':scope > DAI[name="stVal"]',
181-
create: createInvertedAddressAction
181+
create: createAddressAction,
182+
inverted: true
182183
},
183184
'33': {
184185
filter: ':scope > DAI[name="stVal"]',
185-
create: createSingleAddressAction
186+
create: createAddressAction
186187
},
187188
'35': {
188189
filter: ':scope > DAI[name="stVal"]',
189-
create: createSingleAddressAction
190+
create: createAddressAction
190191
}
191192
},
192193
control: {}
@@ -195,25 +196,25 @@ export const cdcProcessings: Record<
195196
monitor: {
196197
'32': {
197198
filter: ':scope > SDI[name="valWTr"] > DAI[name="posVal"]',
198-
create: createSingleAddressAction
199+
create: createAddressAction
199200
},
200201
},
201202
control: {
202203
'62': {
203204
filter: ':scope > SDI[name="Oper"] > DAI[name="ctlVal"]',
204-
create: createSingleAddressAction
205+
create: createAddressAction
205206
},
206207
}
207208
},
208209
MV: {
209210
monitor: {
210211
'35': {
211212
filter: ':scope > SDI[name="mag"] > DAI[name="i"]',
212-
create: createSingleAddressAction
213+
create: createAddressAction
213214
},
214215
'36': {
215216
filter: ':scope > SDI[name="mag"] > DAI[name="f"]',
216-
create: createSingleAddressAction
217+
create: createAddressAction
217218
}
218219
},
219220
control: {}
@@ -222,7 +223,7 @@ export const cdcProcessings: Record<
222223
monitor: {
223224
'37': {
224225
filter: ':scope > DAI[name="cnt"]',
225-
create: createSingleAddressAction
226+
create: createAddressAction
226227
}
227228
},
228229
control: {}
@@ -231,21 +232,22 @@ export const cdcProcessings: Record<
231232
monitor: {
232233
'30': {
233234
filter: ':scope > DAI[name="stVal"]',
234-
create: createSingleAddressAction
235+
create: createAddressAction,
236+
inverted: true
235237
},
236238
},
237239
control: {
238240
'58': {
239241
filter: ':scope > SDI[name="Oper"] > DAI[name="ctlVal"]',
240-
create: createSingleAddressAction
242+
create: createAddressAction
241243
},
242244
}
243245
},
244246
SPG: {
245247
monitor: {
246248
'58': {
247249
filter: ':scope > DAI[name="setVal"]',
248-
create: createSingleAddressAction
250+
create: createAddressAction
249251
}
250252
},
251253
control: {}
@@ -254,42 +256,30 @@ export const cdcProcessings: Record<
254256
monitor: {
255257
'30': {
256258
filter: ':scope > DAI[name="stVal"]',
257-
create: createSingleAddressAction
259+
create: createAddressAction,
260+
inverted: true
258261
}
259262
},
260263
control: {}
261264
},
262265
};
263266

264267
/**
265-
* Create a new SCL Private element and add one 104 Address element below this.
268+
* Create a new SCL Private element and add 104 Address element(s) below this.
266269
* Set the attribute value of 'ti' to the passed ti value.
267270
*
268271
* @param daiElement - The DAI Element to use to set namespace on the root element and create new elements.
269272
* @param ti - The value to be set on the attribute 'ti'.
273+
* @param inverted - Indicates if extra Address Elements should be created with 'inverted=true'.
270274
*/
271-
function createSingleAddressAction(daiElement: Element, ti: string): Create[] {
272-
addPrefixAndNamespaceToDocument(daiElement);
273-
274-
const privateElement = createPrivateElement(daiElement);
275-
createPrivateAddress(daiElement, privateElement, ti);
276-
return [{new: {parent: daiElement, element: privateElement}}];
277-
}
278-
279-
/**
280-
* Create a new SCL Private element and add two 104 Address elements, one without the attribute 'inverted' meaning
281-
* 'false' and the other element with the attribute 'inverted' to 'true'.
282-
* Also set the attribute value of 'ti' to the passed ti value.
283-
*
284-
* @param daiElement - The DAI Element to use to set namespace on the root element and create new elements.
285-
* @param ti - The value to be set on the attribute 'ti'.
286-
*/
287-
function createInvertedAddressAction(daiElement: Element, ti: string): Create[] {
275+
function createAddressAction(daiElement: Element, ti: string, inverted: boolean): Create[] {
288276
addPrefixAndNamespaceToDocument(daiElement);
289277

290278
const privateElement = createPrivateElement(daiElement);
291279
createPrivateAddress(daiElement, privateElement, ti);
292-
const invertedAddressElement = createPrivateAddress(daiElement, privateElement, ti);
293-
invertedAddressElement.setAttribute('inverted', 'true');
280+
if (inverted) {
281+
const invertedAddressElement = createPrivateAddress(daiElement, privateElement, ti);
282+
invertedAddressElement.setAttribute('inverted', 'true');
283+
}
294284
return [{new: {parent: daiElement, element: privateElement}}];
295285
}

src/editors/protocol104/foundation/foundation.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
newWizardEvent
66
} from "../../../foundation.js";
77
import { editAddressWizard } from "../wizards/address.js";
8-
import { CreateFunction } from "./cdc.js";
8+
import {CreateFunction, TiInformation} from "./cdc.js";
99

1010
export const PRIVATE_TYPE_104 = "IEC_60870_5_104";
1111

@@ -183,22 +183,24 @@ export function getCtlModel(doiElement: Element): string | null {
183183
* @param doiElement - The DOI Element.
184184
* @param wizard - The Wizard to dispatch the Open Wizard event on.
185185
* @param ti - The TI Value set on the new Address Elements.
186-
* @param filter - The Filter used to find the DAI Elements.
187-
* @param createFunction - The Function used to create the new Private/Address Elements.
186+
* @param inverted - Indicates if the Engineer want to create inverted Address Elements, if applicable.
187+
* @param tiInformation - Information about how to create the Address Elements for the passed TI.
188188
* @returns A list of Create Action that will be added to the complex action.
189189
*/
190190
export function createActions(
191191
doiElement: Element,
192192
wizard: Element,
193193
ti: string,
194-
filter: string,
195-
createFunction: CreateFunction
194+
inverted: boolean,
195+
tiInformation: TiInformation
196196
): Create[] {
197197
const actions: Create[] = [];
198-
const daiMonitorElements = doiElement.querySelectorAll(filter);
198+
const daiMonitorElements = doiElement.querySelectorAll(tiInformation.filter);
199199
if (daiMonitorElements.length > 0) {
200200
daiMonitorElements.forEach(daiElement => {
201-
const createActions = createFunction(daiElement, ti);
201+
const createActions = tiInformation.create(daiElement, ti,
202+
(tiInformation.inverted ? inverted : false) // If the TI Allows it and the Engineer selected it, true will be passed.
203+
);
202204
actions.push(...createActions);
203205

204206
createActions.forEach(createAction => {

0 commit comments

Comments
 (0)