From a56f790b3c41c4d15beb81c1c086b218813974db Mon Sep 17 00:00:00 2001 From: Stefan Tatschner Date: Thu, 24 Oct 2024 10:58:39 +0200 Subject: [PATCH] feat: Add support for RND power supplies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A very limited port of this: https://github.com/rumpelsepp/opennetzteil/blob/master/devices/rnd/rnd320.go However, these devices are so buggy that only switch on/off works reliably … (in most cases). --- contrib/rnd.rules | 5 ++ src/gallia/power_supply/devices/rnd.py | 67 ++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 contrib/rnd.rules create mode 100644 src/gallia/power_supply/devices/rnd.py diff --git a/contrib/rnd.rules b/contrib/rnd.rules new file mode 100644 index 000000000..18b4a3c92 --- /dev/null +++ b/contrib/rnd.rules @@ -0,0 +1,5 @@ +# SPDX-FileCopyrightText: AISEC Pentesting Team +# +# SPDX-License-Identifier: CC0-1.0 + +KERNEL=="ttyACM[0-9]*", SUBSYSTEM=="tty", SUBSYSTEMS=="usb", ATTRS{idVendor}=="0416", ATTRS{idProduct}=="5011", SYMLINK+="rnd-netzteil" diff --git a/src/gallia/power_supply/devices/rnd.py b/src/gallia/power_supply/devices/rnd.py new file mode 100644 index 000000000..a66cebef3 --- /dev/null +++ b/src/gallia/power_supply/devices/rnd.py @@ -0,0 +1,67 @@ +# SPDX-FileCopyrightText: AISEC Pentesting Team +# +# SPDX-License-Identifier: Apache-2.0 + +import asyncio +from pathlib import Path +from typing import Any + +from gallia.power_supply.base import BasePowerSupplyDriver +from gallia.power_supply.exceptions import OperationNotSupportedError + + +class RND320(BasePowerSupplyDriver): + PRODUCT_ID = "RND320" + + def _send(self, data: str) -> None: + with Path(self.target.path).open("w") as f: + f.write(data) + + async def get_ident(self) -> str: + raise OperationNotSupportedError + + async def get_master(self) -> bool: + raise OperationNotSupportedError + + async def set_master(self, enabled: bool) -> None: + cmd = "OUT1" if enabled else "OUT0" + await asyncio.to_thread(self._send, cmd) + + async def get_channels(self) -> int: + return 1 + + async def get_current(self, channel: int) -> float: + raise OperationNotSupportedError + + async def set_current(self, channel: int, value: float) -> None: + raise OperationNotSupportedError + + async def get_voltage(self, channel: int) -> float: + raise OperationNotSupportedError + + async def set_voltage(self, channel: int, value: float) -> None: + raise OperationNotSupportedError + + async def get_output(self, channel: int) -> bool: + raise OperationNotSupportedError + + async def set_output(self, channel: int, enabled: bool) -> None: + await self.set_master(enabled) + + async def status(self) -> dict[str, Any]: + raise OperationNotSupportedError + + async def get_ocp(self, channel: int) -> bool: + raise OperationNotSupportedError + + async def set_ocp(self, channel: int, enabled: bool) -> None: + raise OperationNotSupportedError + + async def get_ovp(self, channel: int) -> bool: + raise OperationNotSupportedError + + async def set_ovp(self, channel: int, enabled: bool) -> None: + raise OperationNotSupportedError + + async def set_beep(self, enabled: bool) -> None: + raise OperationNotSupportedError