Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tFCDA: Get instantiated description for an FCDA #21

Open
danyill opened this issue Jun 4, 2023 · 1 comment
Open

tFCDA: Get instantiated description for an FCDA #21

danyill opened this issue Jun 4, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@danyill
Copy link
Collaborator

danyill commented Jun 4, 2023

I have a helper function which I think may be of general use to get an FCDA's description by concatenating the instantiated element's description.

Is this of general use and worthy of scl-lib? If so I'm happy to add it with some tests.

function getFcdaInstDesc(fcda: Element, includeDai: boolean): string[] {
  const [doName, daName] = ['doName', 'daName'].map(attr =>
    fcda.getAttribute(attr)
  );

  const ied = fcda.closest('IED');

  const anyLn = Array.from(
    ied?.querySelectorAll(
      `LDevice[inst="${fcda.getAttribute(
        'ldInst'
      )}"] > LN, LDevice[inst="${fcda.getAttribute('ldInst')}"] LN0`
    ) ?? []
  ).find(
    lN =>
      (lN.getAttribute('prefix') ?? '') ===
        (fcda.getAttribute('prefix') ?? '') &&
      (lN.getAttribute('lnClass') ?? '') ===
        (fcda.getAttribute('lnClass') ?? '') &&
      (lN.getAttribute('inst') ?? '') === (fcda.getAttribute('lnInst') ?? '')
  );

  if (!anyLn) return [];

  const descs: (string | null | undefined)[] = [];

  descs.push(anyLn.closest('LDevice')?.getAttribute('desc'));
  descs.push(anyLn.getAttribute('desc'));

  const doNames = doName!.split('.');

  const doi = anyLn.querySelector(`DOI[name="${doNames[0]}"`);

  if (!doi) return descs.filter(d => d !== null && d !== undefined) as string[];

  descs.push(doi?.getAttribute('desc'));

  let previousDI: Element = doi;
  doNames.slice(1).forEach(sdiName => {
    const sdi = previousDI.querySelector(`SDI[name="${sdiName}"]`);
    if (sdi) previousDI = sdi;
    descs.push(sdi?.getAttribute('desc'));
  });

  if (!includeDai || !daName)
    return descs.filter(d => d !== null && d !== undefined) as string[];

  const daNames = daName?.split('.');
  const dai = previousDI.querySelector(`DAI[name="${daNames[0]}"]`);
  descs.push(dai?.getAttribute('desc'));

  return descs.filter(d => d !== null && d !== undefined) as string[];
}
@danyill danyill self-assigned this Apr 16, 2024
@danyill danyill added the enhancement New feature or request label Apr 16, 2024
@danyill danyill changed the title (tDataSet) Get instantiated description for an FCDA tFCDA: Get instantiated description for an FCDA Apr 16, 2024
@danyill
Copy link
Collaborator Author

danyill commented Apr 16, 2024

I'd like to work on this.

I realise this is a helper method but I think it would be worth having.

How about the following signature?

export type fcdaDesc = {
  LDevice: string | null;
  LN: string | null;
  DOI?: string | null;
  SDI?: string[];
  DAI?: string | null;
};

export function getFcdaInstDesc(fcda: Element): fcdaDesc {
}

If that seems worthwhile I shall prepare a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant