mirror of
https://github.com/naruxde/revpimodio2.git
synced 2025-11-08 22:03:53 +01:00
Merge pull request #9 from nbuchwitz/feature/structio-exportflag
feature: make export flag configurable for StructIO
This commit is contained in:
@@ -291,8 +291,8 @@ class IOBase(object):
|
|||||||
|
|
||||||
__slots__ = "__bit_ioctl_off", "__bit_ioctl_on", "_bitaddress", \
|
__slots__ = "__bit_ioctl_off", "__bit_ioctl_on", "_bitaddress", \
|
||||||
"_bitshift", "_bitlength", "_byteorder", "_defaultvalue", \
|
"_bitshift", "_bitlength", "_byteorder", "_defaultvalue", \
|
||||||
"_iotype", "_length", "_name", "_parentdevice", \
|
"_export", "_iotype", "_length", "_name", "_parentdevice", \
|
||||||
"_read_only_io", "_signed", "_slc_address", "bmk", "export"
|
"_read_only_io", "_signed", "_slc_address", "bmk"
|
||||||
|
|
||||||
def __init__(self, parentdevice, valuelist: list, iotype: int, byteorder: str, signed: bool):
|
def __init__(self, parentdevice, valuelist: list, iotype: int, byteorder: str, signed: bool):
|
||||||
"""
|
"""
|
||||||
@@ -325,7 +325,7 @@ class IOBase(object):
|
|||||||
self._name = valuelist[0]
|
self._name = valuelist[0]
|
||||||
self._signed = signed
|
self._signed = signed
|
||||||
self.bmk = valuelist[6]
|
self.bmk = valuelist[6]
|
||||||
self.export = bool(valuelist[4])
|
self._export = int(valuelist[4]) & 1
|
||||||
|
|
||||||
int_startaddress = int(valuelist[3])
|
int_startaddress = int(valuelist[3])
|
||||||
if self._bitshift:
|
if self._bitshift:
|
||||||
@@ -514,6 +514,10 @@ class IOBase(object):
|
|||||||
"""
|
"""
|
||||||
return self._byteorder
|
return self._byteorder
|
||||||
|
|
||||||
|
def _get_export(self) -> bool:
|
||||||
|
"""Return value of export flag."""
|
||||||
|
return bool(self._export & 1)
|
||||||
|
|
||||||
def _get_iotype(self) -> int:
|
def _get_iotype(self) -> int:
|
||||||
"""
|
"""
|
||||||
Gibt io type zurueck.
|
Gibt io type zurueck.
|
||||||
@@ -522,6 +526,12 @@ class IOBase(object):
|
|||||||
"""
|
"""
|
||||||
return self._iotype
|
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 <class 'bool'>")
|
||||||
|
self._export = 2 + int(value)
|
||||||
|
|
||||||
def get_defaultvalue(self):
|
def get_defaultvalue(self):
|
||||||
"""
|
"""
|
||||||
Gibt die Defaultvalue von piCtory zurueck.
|
Gibt die Defaultvalue von piCtory zurueck.
|
||||||
@@ -850,6 +860,7 @@ class IOBase(object):
|
|||||||
address = property(_get_address)
|
address = property(_get_address)
|
||||||
byteorder = property(_get_byteorder)
|
byteorder = property(_get_byteorder)
|
||||||
defaultvalue = property(get_defaultvalue)
|
defaultvalue = property(get_defaultvalue)
|
||||||
|
export = property(_get_export, _set_export)
|
||||||
length = property(__len__)
|
length = property(__len__)
|
||||||
name = property(__str__)
|
name = property(__str__)
|
||||||
type = property(_get_iotype)
|
type = property(_get_iotype)
|
||||||
@@ -1217,6 +1228,13 @@ class StructIO(IOBase):
|
|||||||
frm == frm.lower()
|
frm == frm.lower()
|
||||||
)
|
)
|
||||||
self.__frm = bofrm + frm
|
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
|
# Platz für neuen IO prüfen
|
||||||
if not (self._slc_address.start >=
|
if not (self._slc_address.start >=
|
||||||
|
|||||||
@@ -388,6 +388,16 @@ class RevPiModIO(object):
|
|||||||
"".format(io, creplaceio[io]["bit"])
|
"".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
|
# Convert defaultvalue from config file
|
||||||
if "defaultvalue" in creplaceio[io]:
|
if "defaultvalue" in creplaceio[io]:
|
||||||
if dict_replace["frm"] == "?":
|
if dict_replace["frm"] == "?":
|
||||||
@@ -845,6 +855,8 @@ class RevPiModIO(object):
|
|||||||
cp[io.name]["defaultvalue"] = str(io.defaultvalue)
|
cp[io.name]["defaultvalue"] = str(io.defaultvalue)
|
||||||
if io.bmk != "":
|
if io.bmk != "":
|
||||||
cp[io.name]["bmk"] = io.bmk
|
cp[io.name]["bmk"] = io.bmk
|
||||||
|
if io._export & 2:
|
||||||
|
cp[io.name]["export"] = str(io._export & 1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(filename, "w") as fh:
|
with open(filename, "w") as fh:
|
||||||
|
|||||||
Reference in New Issue
Block a user