From bff18ed4a5cd8b7633a157d1ecf148036dd2eb28 Mon Sep 17 00:00:00 2001 From: Jens Kleintje Date: Fri, 15 Sep 2023 11:38:11 +0200 Subject: [PATCH 1/2] driver/power: add support for Robot Electronics ETH008 use HTTP-GET API defined at https://www.robot-electronics.co.uk/htm/eth008tech.htm Signed-off-by: Jens Kleintje --- doc/configuration.rst | 3 +++ labgrid/driver/power/eth008.py | 41 ++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 labgrid/driver/power/eth008.py diff --git a/doc/configuration.rst b/doc/configuration.rst index 6afab1b01..83214bc6a 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -174,6 +174,9 @@ Currently available are: interface, this module deliberately uses the standard password '1' and is not compatible with a different password. +``eth008`` + Controls a Robot-Electronics eth008 via a simple HTTP API. + ``gude`` Controls a Gude PDU via a simple HTTP API. diff --git a/labgrid/driver/power/eth008.py b/labgrid/driver/power/eth008.py new file mode 100644 index 000000000..6a4450953 --- /dev/null +++ b/labgrid/driver/power/eth008.py @@ -0,0 +1,41 @@ +""" +This driver implements a power port for the robot electronics 8 relay +outputs board. + +Driver has been tested with: +* ETH008 - 8 relay outputs +""" + +import requests +from ..exception import ExecutionError + +PORT = 80 + +def power_set(host, port, index, value): + index = int(index) + assert 1 <= index <= 8 + # access the web interface... + value_str = "A" if value else "I" + response = requests.get( + f"http://{host}:{port}/io.cgi?DO{value_str}{index}" + ) + response.raise_for_status() + + # Check, that the port is in the desired state + state = get_state(response, index) + if state != value: + raise ExecutionError(f"failed to set port {index} to status {value}") + +def power_get(host, port, index): + index = int(index) + assert 1 <= index <= 8 + # get the contents of the main page + response = requests.get(f"http://{host}:{port}/io.cgi?relay") + + response.raise_for_status() + state = get_state(response, index) + return state + +def get_state(request, index): + value = request.text.split()[1][index-1] + return bool(int(value)) From 5a8acba7479646059c90baceb17bbb5b9c5f8b2b Mon Sep 17 00:00:00 2001 From: Jens Kleintje Date: Thu, 28 Sep 2023 10:15:48 +0200 Subject: [PATCH 2/2] tests/test_powerdriver: add eth008 import Signed-off-by: Jens Kleintje --- tests/test_powerdriver.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_powerdriver.py b/tests/test_powerdriver.py index 3c7b3dbab..7afcdfb33 100644 --- a/tests/test_powerdriver.py +++ b/tests/test_powerdriver.py @@ -244,6 +244,7 @@ def test_import_backends(self): import labgrid.driver.power.apc import labgrid.driver.power.digipower import labgrid.driver.power.digitalloggers_http + import labgrid.driver.power.eth008 import labgrid.driver.power.gude import labgrid.driver.power.gude24 import labgrid.driver.power.netio