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