From 186406623b3a4f54df3c199854bf7157f09677cb Mon Sep 17 00:00:00 2001 From: Nicolai Buchwitz Date: Tue, 12 Jan 2021 19:10:13 +0100 Subject: [PATCH 1/2] feature: make export flag configurable for StructIO replaceable IOs should also allow the configuration of the export flag --- revpimodio2/io.py | 2 +- revpimodio2/modio.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/revpimodio2/io.py b/revpimodio2/io.py index 7ab7f98..c2cf210 100644 --- a/revpimodio2/io.py +++ b/revpimodio2/io.py @@ -1197,7 +1197,7 @@ class StructIO(IOBase): kwargs.get("defaultvalue", None), bitlength, parentio._slc_address.start, - False, + kwargs.get('export', parentio.export), str(parentio._slc_address.start).rjust(4, "0"), kwargs.get("bmk", ""), bitaddress diff --git a/revpimodio2/modio.py b/revpimodio2/modio.py index 492fd8e..c086684 100644 --- a/revpimodio2/modio.py +++ b/revpimodio2/modio.py @@ -388,6 +388,16 @@ class RevPiModIO(object): "".format(io, creplaceio[io]["bit"]) ) + if "export" in creplaceio[io]: + try: + dict_replace["export"] = creplaceio[io].getboolean("export") + except Exception: + raise ValueError( + "replace_io_file: could not convert '{0}' " + "export '{1}' to bool" + "".format(io, creplaceio[io]["export"]) + ) + # Convert defaultvalue from config file if "defaultvalue" in creplaceio[io]: if dict_replace["frm"] == "?": @@ -845,6 +855,8 @@ class RevPiModIO(object): cp[io.name]["defaultvalue"] = str(io.defaultvalue) if io.bmk != "": cp[io.name]["bmk"] = io.bmk + if io.export is not None: + cp[io.name]["export"] = io.export try: with open(filename, "w") as fh: From cc9b4521e92992507e34f31cb80ca8d804b3273b Mon Sep 17 00:00:00 2001 From: Sven Sager Date: Wed, 13 Jan 2021 10:36:36 +0100 Subject: [PATCH 2/2] Only write export flag to replace_io_file, if the value was set during runtime --- revpimodio2/io.py | 26 ++++++++++++++++++++++---- revpimodio2/modio.py | 4 ++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/revpimodio2/io.py b/revpimodio2/io.py index c2cf210..96fca1d 100644 --- a/revpimodio2/io.py +++ b/revpimodio2/io.py @@ -291,8 +291,8 @@ class IOBase(object): __slots__ = "__bit_ioctl_off", "__bit_ioctl_on", "_bitaddress", \ "_bitshift", "_bitlength", "_byteorder", "_defaultvalue", \ - "_iotype", "_length", "_name", "_parentdevice", \ - "_read_only_io", "_signed", "_slc_address", "bmk", "export" + "_export", "_iotype", "_length", "_name", "_parentdevice", \ + "_read_only_io", "_signed", "_slc_address", "bmk" def __init__(self, parentdevice, valuelist: list, iotype: int, byteorder: str, signed: bool): """ @@ -325,7 +325,7 @@ class IOBase(object): self._name = valuelist[0] self._signed = signed self.bmk = valuelist[6] - self.export = bool(valuelist[4]) + self._export = int(valuelist[4]) & 1 int_startaddress = int(valuelist[3]) if self._bitshift: @@ -514,6 +514,10 @@ class IOBase(object): """ return self._byteorder + def _get_export(self) -> bool: + """Return value of export flag.""" + return bool(self._export & 1) + def _get_iotype(self) -> int: """ Gibt io type zurueck. @@ -522,6 +526,12 @@ class IOBase(object): """ return self._iotype + def _set_export(self, value: bool) -> None: + """Set value of export flag and remember this change for export.""" + if type(value) != bool: + raise ValueError("Value must be ") + self._export = 2 + int(value) + def get_defaultvalue(self): """ Gibt die Defaultvalue von piCtory zurueck. @@ -850,6 +860,7 @@ class IOBase(object): address = property(_get_address) byteorder = property(_get_byteorder) defaultvalue = property(get_defaultvalue) + export = property(_get_export, _set_export) length = property(__len__) name = property(__str__) type = property(_get_iotype) @@ -1197,7 +1208,7 @@ class StructIO(IOBase): kwargs.get("defaultvalue", None), bitlength, parentio._slc_address.start, - kwargs.get('export', parentio.export), + False, str(parentio._slc_address.start).rjust(4, "0"), kwargs.get("bmk", ""), bitaddress @@ -1217,6 +1228,13 @@ class StructIO(IOBase): frm == frm.lower() ) self.__frm = bofrm + frm + if "export" in kwargs: + # Use export property to remember given value for export + self.export = kwargs["export"] + else: + # User could change parent IO settings before replace to force + # export, so use parent settings for the new IO + self._export = parentio._export # Platz für neuen IO prüfen if not (self._slc_address.start >= diff --git a/revpimodio2/modio.py b/revpimodio2/modio.py index c086684..c189347 100644 --- a/revpimodio2/modio.py +++ b/revpimodio2/modio.py @@ -855,8 +855,8 @@ class RevPiModIO(object): cp[io.name]["defaultvalue"] = str(io.defaultvalue) if io.bmk != "": cp[io.name]["bmk"] = io.bmk - if io.export is not None: - cp[io.name]["export"] = io.export + if io._export & 2: + cp[io.name]["export"] = str(io._export & 1) try: with open(filename, "w") as fh: