|
| 1 | +import { Create } from "../../../foundation.js"; |
| 2 | + |
| 3 | +import {addPrefixAndNamespaceToDocument, createPrivateAddress, createPrivateElement} from "./private.js"; |
| 4 | + |
| 5 | +/** |
| 6 | + * List of supported Common Data Classes in the 104 protocol. |
| 7 | + */ |
| 8 | +export const supportedCdcTypes = ['ACT', 'ASG', 'BCR', 'CMV', 'DPS', 'ING', 'INS', 'MV', 'SEC', 'SPG', 'SPS'] as const; |
| 9 | +export type SupportedCdcType = typeof supportedCdcTypes[number]; |
| 10 | + |
| 11 | +type CreateFunction = (daiElement: Element, selectedTi: string) => Create[]; |
| 12 | + |
| 13 | +/** |
| 14 | + * Record with configuration information on how to create Address elements for the 104 protocol. |
| 15 | + * Per supported Common Data Class (CDC) two record sets can be configured, one for the monitoring part |
| 16 | + * and one for the control part. |
| 17 | + * Per set the key of the record will be the ti value, meaning the list of keys will be the supported |
| 18 | + * ti values allowed for the CDC. |
| 19 | + * For each supported ti value there is information on how to find the DAI Element to which to create |
| 20 | + * the Address element(s). |
| 21 | + */ |
| 22 | +export const cdcProcessings: Record< |
| 23 | + SupportedCdcType, |
| 24 | + { |
| 25 | + monitor: Record<string, { |
| 26 | + filter: string; |
| 27 | + create: CreateFunction; |
| 28 | + }>, |
| 29 | + control: Record<string, { |
| 30 | + filter: string; |
| 31 | + create: CreateFunction; |
| 32 | + }>, |
| 33 | + } |
| 34 | + > = { |
| 35 | + ACT: { |
| 36 | + monitor: { |
| 37 | + '30': { |
| 38 | + filter: 'DAI[name="general"], DAI[name="phsA"], DAI[name="phsB"], DAI[name="phsC"], DAI[name="neut"]', |
| 39 | + create: createSingleAddressAction |
| 40 | + }, |
| 41 | + '39': { |
| 42 | + filter: 'DAI[name="general"]', |
| 43 | + create: createSingleAddressAction |
| 44 | + } |
| 45 | + }, |
| 46 | + control: {} |
| 47 | + }, |
| 48 | + ASG: { |
| 49 | + monitor: { |
| 50 | + '63': { |
| 51 | + filter: 'SDI[name="setMag"] > DAI[name="f"]', |
| 52 | + create: createSingleAddressAction |
| 53 | + } |
| 54 | + }, |
| 55 | + control: {} |
| 56 | + }, |
| 57 | + BCR: { |
| 58 | + monitor: { |
| 59 | + '37': { |
| 60 | + filter: 'DAI[name="actVal"], DAI[name="frVal"]', |
| 61 | + create: createSingleAddressAction |
| 62 | + }, |
| 63 | + }, |
| 64 | + control: {} |
| 65 | + }, |
| 66 | + CMV: { |
| 67 | + monitor: { |
| 68 | + '35': { |
| 69 | + filter: 'SDI[name="mag"] > DAI[name="i"], SDI[name="ang"] > DAI[name="i"]', |
| 70 | + create: createSingleAddressAction |
| 71 | + }, |
| 72 | + '36': { |
| 73 | + filter: 'SDI[name="mag"] > DAI[name="f"], SDI[name="ang"] > DAI[name="f"]', |
| 74 | + create: createSingleAddressAction |
| 75 | + } |
| 76 | + }, |
| 77 | + control: {} |
| 78 | + }, |
| 79 | + DPS: { |
| 80 | + monitor: { |
| 81 | + '31': { |
| 82 | + filter: 'DAI[name="stVal"]', |
| 83 | + create: createSingleAddressAction |
| 84 | + } |
| 85 | + }, |
| 86 | + control: {} |
| 87 | + }, |
| 88 | + ING: { |
| 89 | + monitor: { |
| 90 | + '62': { |
| 91 | + filter: 'DAI[name="setVal"]', |
| 92 | + create: createSingleAddressAction |
| 93 | + } |
| 94 | + }, |
| 95 | + control: {} |
| 96 | + }, |
| 97 | + INS: { |
| 98 | + monitor: { |
| 99 | + '30': { |
| 100 | + filter: 'DAI[name="stVal"]', |
| 101 | + create: createInvertedAddressAction |
| 102 | + }, |
| 103 | + '33': { |
| 104 | + filter: 'DAI[name="stVal"]', |
| 105 | + create: createSingleAddressAction |
| 106 | + }, |
| 107 | + '35': { |
| 108 | + filter: 'DAI[name="stVal"]', |
| 109 | + create: createSingleAddressAction |
| 110 | + } |
| 111 | + }, |
| 112 | + control: {} |
| 113 | + }, |
| 114 | + MV: { |
| 115 | + monitor: { |
| 116 | + '35': { |
| 117 | + filter: 'SDI[name="mag"] > DAI[name="i"]', |
| 118 | + create: createSingleAddressAction |
| 119 | + }, |
| 120 | + '36': { |
| 121 | + filter: 'SDI[name="mag"] > DAI[name="f"]', |
| 122 | + create: createSingleAddressAction |
| 123 | + } |
| 124 | + }, |
| 125 | + control: {} |
| 126 | + }, |
| 127 | + SEC: { |
| 128 | + monitor: { |
| 129 | + '37': { |
| 130 | + filter: 'DAI[name="cnt"]', |
| 131 | + create: createSingleAddressAction |
| 132 | + } |
| 133 | + }, |
| 134 | + control: {} |
| 135 | + }, |
| 136 | + SPG: { |
| 137 | + monitor: { |
| 138 | + '58': { |
| 139 | + filter: 'DAI[name="setVal"]', |
| 140 | + create: createSingleAddressAction |
| 141 | + } |
| 142 | + }, |
| 143 | + control: {} |
| 144 | + }, |
| 145 | + SPS: { |
| 146 | + monitor: { |
| 147 | + '30': { |
| 148 | + filter: 'DAI[name="stVal"]', |
| 149 | + create: createSingleAddressAction |
| 150 | + } |
| 151 | + }, |
| 152 | + control: {} |
| 153 | + }, |
| 154 | +}; |
| 155 | + |
| 156 | +/** |
| 157 | + * Create a new SCL Private element and add one 104 Address element below this. |
| 158 | + * Set the attribute value of 'ti' to the passed ti value. |
| 159 | + * |
| 160 | + * @param daiElement - The DAI Element to use to set namespace on the root element and create new elements. |
| 161 | + * @param ti - The value to be set on the attribute 'ti'. |
| 162 | + */ |
| 163 | +function createSingleAddressAction(daiElement: Element, ti: string): Create[] { |
| 164 | + addPrefixAndNamespaceToDocument(daiElement); |
| 165 | + |
| 166 | + const privateElement = createPrivateElement(daiElement); |
| 167 | + createPrivateAddress(daiElement, privateElement, ti); |
| 168 | + return [{new: {parent: daiElement, element: privateElement}}]; |
| 169 | +} |
| 170 | + |
| 171 | +/** |
| 172 | + * Create a new SCL Private element and add two 104 Address elements, one without the attribute 'inverted' meaning |
| 173 | + * 'false' and the other element with the attribute 'inverted' to 'true'. |
| 174 | + * Also set the attribute value of 'ti' to the passed ti value. |
| 175 | + * |
| 176 | + * @param daiElement - The DAI Element to use to set namespace on the root element and create new elements. |
| 177 | + * @param ti - The value to be set on the attribute 'ti'. |
| 178 | + */ |
| 179 | +function createInvertedAddressAction(daiElement: Element, ti: string): Create[] { |
| 180 | + addPrefixAndNamespaceToDocument(daiElement); |
| 181 | + |
| 182 | + const privateElement = createPrivateElement(daiElement); |
| 183 | + createPrivateAddress(daiElement, privateElement, ti); |
| 184 | + const invertedAddressElement = createPrivateAddress(daiElement, privateElement, ti); |
| 185 | + invertedAddressElement.setAttribute('inverted', 'true'); |
| 186 | + return [{new: {parent: daiElement, element: privateElement}}]; |
| 187 | +} |
0 commit comments