Add option to exclude data types from alignment rules.
This commit is contained in:
@@ -10,7 +10,7 @@ desc: AuDaGe module for handling Schneider Electric ControlExpert XSY files.
|
||||
|
||||
import os
|
||||
import warnings
|
||||
from collections.abc import Collection, Iterable
|
||||
from collections.abc import Collection
|
||||
from dataclasses import dataclass
|
||||
from enum import IntEnum, StrEnum, auto
|
||||
from importlib import resources
|
||||
@@ -129,7 +129,7 @@ class Definitions(XSYBlock):
|
||||
path: Path,
|
||||
stylesheet_path: Path | None = None,
|
||||
name_ext: str = "Definitions",
|
||||
definition_paths: Iterable[Path] | None = None,
|
||||
definition_paths: Collection[Path] | None = None,
|
||||
include_builtins: bool = True,
|
||||
) -> Definitions:
|
||||
"""Read the DDTSource nodes of an XSY file into a DataFrame."""
|
||||
@@ -201,10 +201,18 @@ class Definitions(XSYBlock):
|
||||
cls,
|
||||
address: float,
|
||||
length: float,
|
||||
data_type: str,
|
||||
max_alignment: int = iec.DataUnit.DWORD,
|
||||
excluded_data_types: Collection[str] = ("STRING",),
|
||||
) -> float:
|
||||
# Return early if missing information.
|
||||
if pd.isna(address) or pd.isna(length) or length <= 0:
|
||||
if (
|
||||
pd.isna(address)
|
||||
or pd.isna(length)
|
||||
or pd.isna(data_type)
|
||||
or length <= 0
|
||||
or data_type in excluded_data_types
|
||||
):
|
||||
return address
|
||||
alignment = min(length, max_alignment)
|
||||
rem = address % alignment
|
||||
@@ -260,6 +268,7 @@ class Definitions(XSYBlock):
|
||||
row[XC.ADDRESS] = cls._calculate_padding(
|
||||
prev_row[XC.ADDRESS] + prev_row[XC.LENGTH],
|
||||
row[XC.LENGTH],
|
||||
row[XC.DATATYPE],
|
||||
)
|
||||
group_dict_calc.append(row)
|
||||
group_calc = frame.AuDaGeFrame(group_dict_calc)
|
||||
@@ -564,7 +573,7 @@ class XSYReader:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
definition_paths: Iterable[Path] | None = None,
|
||||
definition_paths: Collection[Path] | None = None,
|
||||
datablock_ss_path: Path | None = None,
|
||||
definitions_ss_path: Path | None = None,
|
||||
even_addresses: bool = True,
|
||||
@@ -574,7 +583,7 @@ class XSYReader:
|
||||
|
||||
Parameters
|
||||
----------
|
||||
definition_paths : iterable of pathlike (optional)
|
||||
definition_paths : collection of Path (optional)
|
||||
List of additional XSY files to read UDT (DDT) definitions from.
|
||||
datablock_ss_path: pathlike (optional)
|
||||
Path to XSLT stylesheet to flatten the XSY file and extract the
|
||||
|
||||
Reference in New Issue
Block a user