forked from openscd/open-scd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wizards/gsecontrol): add create wizards (openscd#654)
* refactor(wizards/address): change content input definition * refactor(wizards/gsecontrol): change content input definition * refactor(wizard/gsecontrol): better naming * refactor(wizards/address): change content function api * feat(wizards/foundation/scl): add function to get unique MAC and APPID * feat(wizards/foundation/scl): communication connection checks * feat(wizards/gsecontrol): add create wizards * test(wizards/gsecontrol): add unit tests * test(wizards/gsecontrol): update snapshot * test(wizards/gsecontrol): add integration tests * test(wiazrds/foundation/scl): increate timeout in critical tests * test(wiazrds/foundation/scl): remove time extensive tests * fix review commit * refactor(editors/gsecontrol): add warning message with missing communication connection * fix(src/translations/en): spelling error Co-authored-by: danyill <danyill@users.noreply.github.com> * test(test/unit/wizards/foundation/scl): spelling Co-authored-by: danyill <danyill@users.noreply.github.com> * fix(test/unit/wizards/foundation/scl): incorrect element tag Co-authored-by: danyill <danyill@users.noreply.github.com> * fix(test/unit/wizards/foundation/scl): incorrect element tag Co-authored-by: danyill <danyill@users.noreply.github.com> * test(test/unit/wizards/foundation/scl): fix spelling Co-authored-by: danyill <danyill@users.noreply.github.com> * test(test/unit/wizards/foundation/scl): fix spelling Co-authored-by: danyill <danyill@users.noreply.github.com> * test(test/unit/wizards/foundation/scl): fix spelling Co-authored-by: danyill <danyill@users.noreply.github.com> * refactor: triggered by review Co-authored-by: danyill <danyill@users.noreply.github.com>
- Loading branch information
1 parent
3689ef2
commit 887f46f
Showing
13 changed files
with
1,693 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
export function getConnectedAP(element: Element): Element | null { | ||
return element.ownerDocument.querySelector( | ||
`:root > Communication > SubNetwork > ConnectedAP[iedName="${element | ||
.closest('IED') | ||
?.getAttribute('name')}"][apName="${element | ||
.closest('AccessPoint') | ||
?.getAttribute('name')}"]` | ||
); | ||
} | ||
|
||
export function isAccessPointConnected(element: Element): boolean { | ||
return getConnectedAP(element) ? true : false; | ||
} | ||
|
||
function incrementMac(oldMac: string): string { | ||
const mac = oldMac.split('-').join(''); | ||
//destination MAC in IEC61850 always starts with 01:0C:CD:... | ||
const newMac = '0' + (parseInt(mac, 16) + 1).toString(16).toUpperCase(); | ||
return newMac.match(/.{1,2}/g)!.join('-'); | ||
} | ||
|
||
export function uniqueMacAddress( | ||
doc: XMLDocument, | ||
serviceType: 'SMV' | 'GOOSE' | ||
): string | null { | ||
const maxMac = | ||
serviceType === 'GOOSE' ? '01-0C-CD-01-01-FF' : '01-0C-CD-04-01-FF'; | ||
const startMac = | ||
serviceType === 'GOOSE' ? '01-0C-CD-01-00-00' : '01-0C-CD-04-00-00'; | ||
|
||
const givenMacs = Array.from(doc.querySelectorAll('Address > P')) | ||
.filter(pElement => pElement.getAttribute('type') === 'MAC-Address') | ||
.map(mac => mac.innerHTML.trim()); | ||
|
||
let mac = startMac; | ||
while (mac !== maxMac) { | ||
if (!givenMacs.includes(mac)) return mac; | ||
mac = incrementMac(mac); | ||
} | ||
|
||
return givenMacs.includes(mac) ? null : mac; | ||
} | ||
|
||
function incrementAppId(oldAppId: string): string { | ||
return (parseInt(oldAppId, 16) + 1) | ||
.toString(16) | ||
.toUpperCase() | ||
.padStart(4, '0'); | ||
} | ||
|
||
export function uniqueAppId(doc: XMLDocument): string | null { | ||
const maxAppId = 'FFFF'; | ||
const startAppId = '0001'; | ||
|
||
const givenAppIds = Array.from(doc.querySelectorAll('Address > P')) | ||
.filter(pElement => pElement.getAttribute('type') === 'APPID') | ||
.map(mac => mac.innerHTML.trim()); | ||
|
||
if (givenAppIds.length === 0) return null; | ||
|
||
let appId = startAppId; | ||
while (appId !== maxAppId) { | ||
if (!givenAppIds.includes(appId)) return appId; | ||
appId = incrementAppId(appId); | ||
} | ||
|
||
return givenAppIds.includes(appId) ? null : appId; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.