Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

power: add eth008 power backend #1275

Merged
merged 2 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
41 changes: 41 additions & 0 deletions labgrid/driver/power/eth008.py
Original file line number Diff line number Diff line change
@@ -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))
1 change: 1 addition & 0 deletions tests/test_powerdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down