From 986b52951e23ddb5d9f5af0417380f4a91cbfe0b Mon Sep 17 00:00:00 2001 From: Sven Sager Date: Mon, 13 Nov 2023 12:34:08 +0100 Subject: [PATCH 1/2] chore: Release 0.11.0rc2 Signed-off-by: Sven Sager --- src/revpipyload/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/revpipyload/__init__.py b/src/revpipyload/__init__.py index ff08a40..743751b 100644 --- a/src/revpipyload/__init__.py +++ b/src/revpipyload/__init__.py @@ -4,4 +4,4 @@ __author__ = "Sven Sager" __copyright__ = "Copyright (C) 2023 Sven Sager" __license__ = "GPLv2" __package__ = "revpipyload" -__version__ = "0.11.0rc1" +__version__ = "0.11.0rc2" From 2327c22cbdc4e36dec3eb40c3e778a5c48791ceb Mon Sep 17 00:00:00 2001 From: Sven Sager Date: Mon, 13 Nov 2023 15:39:25 +0100 Subject: [PATCH 2/2] feat: New XML-RPC function for async calls of piControl New XML-RPC functions are "ps_switching_cycles" and "ps_reset_counter" to reset the counters of an DI / DIO module and get the switching cycles of the new RO module. This needs RevPiModIO2 2.7.0rc2 as dependency, which is set in this commit, too. Signed-off-by: Sven Sager --- requirements.txt | 2 +- setup.py | 2 +- src/revpipyload/procimgserver.py | 40 ++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index eb92104..83ab5d9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,4 @@ setuptools>=58.0.4 wheel paho-mqtt>=1.4.0 -revpimodio2>=2.6.0 +revpimodio2>=2.7.0rc2 diff --git a/setup.py b/setup.py index ecb8f4a..cccac40 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ setup( install_requires=[ "paho-mqtt >= 1.4.0", - "revpimodio2 >= 2.6.0", + "revpimodio2 >= 2.7.0rc2", ], entry_points={ 'console_scripts': [ diff --git a/src/revpipyload/procimgserver.py b/src/revpipyload/procimgserver.py index 5a53b55..aa3af34 100644 --- a/src/revpipyload/procimgserver.py +++ b/src/revpipyload/procimgserver.py @@ -44,8 +44,10 @@ class ProcimgServer: "ps_inps": lambda: self.ios("inp"), "ps_outs": lambda: self.ios("out"), "ps_values": self.values, + "ps_switching_cycles": lambda io_name: self.async_call("ro_get_switching_cycles", io_name) } self.xmlwritefuncs = { + "ps_reset_counter": lambda io_name: self.async_call("di_reset", io_name), "ps_setvalue": self.setvalue, } @@ -59,6 +61,33 @@ class ProcimgServer: if self.rpi is not None: self.rpi.cleanup() + def async_call(self, call: str, *args): + """ + Call an async function (ioctl) of piControl. + + :param call: IOCTL call + :param args: Optional arguments to pass to async function + :return: Return value of async call + """ + proginit.logger.debug("ProcimgServer.async_call({0}, {1})".format(call, args)) + + if call == "ro_get_switching_cycles": + # args = [io_name] + io_name = args[0] + switching_cycles = self.rpi.io[io_name].get_switching_cycles() + if not isinstance(switching_cycles, tuple): + switching_cycles = (switching_cycles,) + + # int values will exceed XML-RPC limits, so we use str + return tuple(str(switching_cycle) for switching_cycle in switching_cycles) + + if call == "di_reset": + # args = [io_name] + io_name = args[0] + return self.rpi.io[io_name].reset() + + raise ValueError("Unknown async function name in call argument") + def devices(self): """Generiert Deviceliste mit Position und Namen. @return list() mit Tuple (pos, name)""" @@ -83,6 +112,16 @@ class ProcimgServer: lst_io = [] for io in lst_io: + lst_async_calls = [] + + if isinstance(io, revpimodio2.io.IntIOCounter): + # Counter IOs has a reset property + lst_async_calls.append("di_reset") + + if isinstance(io, revpimodio2.io.RelaisOutput): + # Relaisoutputs can read switching cycles + lst_async_calls.append("ro_get_switching_cycles") + dict_ios[dev.position].append([ io.name, 1 if io._bitlength == 1 else int(io._bitlength / 8), @@ -92,6 +131,7 @@ class ProcimgServer: io._byteorder, io._signed, getattr(io, "wordorder", "ignored"), + lst_async_calls, ]) return Binary(pickle.dumps(dict_ios))