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

[feature] spe_switch: Add spe_switch power feature #1274

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ Currently available are:
``netio_kshell``
Controls a NETIO 4C PDU via a Telnet interface.

``phoenixcontact_fl_2300``
Controls a single-pair-ethernet powerswitch via telnet.
Tested on a FL SWITCH 2303-8SP1 with FW-version 3.27.01 BETA

``raritan``
Controls Raritan PDUs via SNMP.

Expand Down
74 changes: 74 additions & 0 deletions labgrid/driver/power/phoenixcontact_fl_2300.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
'''
This Driver was tested on a FL SWITCH 2303-8SP1 with FW-version 3.27.01 BETA
file phoenixcontact_fl_2300.py
author Raffael Krakau
date 2023-08-24

Copyright 2023 JUMO GmbH & Co. KG
'''
import pexpect

PORT = 23


def __login_telnet(tn):
"""
Login user with set credentials

@param tn : pyexpect-telnet-object
"""
username = "admin"
password = "private"

# login user with password
tn.expect(b'User: ')
tn.send(bytes(f'{username}\r\n', "utf-8"))
tn.expect(b'Password: ')
tn.send(bytes(f'{password}\r\n', "utf-8"))


def power_set(host, port, index: int, value: bool):
"""
Set power state by socket port number (e.g. 1 - 8) and an value {'enable', 'disable'}.

- values:
- disable(False): Turn OFF,
- enable(True): Turn ON
"""
action = "enable" if value else "disable"

with pexpect.spawn(f"telnet {host} {port}", timeout=1) as tn:
# login user with password
__login_telnet(tn)

# set value
tn.send(f'pse port {index} power {action}\r\n'.encode())

tn.expect(b'OK')

tn.send(b"quit\r\n")
tn.expect(pexpect.EOF)


def power_get(host, port, index: int) -> bool:
"""
Get current state of a given socket number.
- host: spe-switch-device adress
- port: standard is 23
- index: depends on spe-switch-device 1-n (n is the number of spe-switch-ports)
"""
status = None

with pexpect.spawn(f"telnet {host} {port}", timeout=1) as tn:
# login user with password
__login_telnet(tn)

# get value
tn.send(bytes(f'show pse port port-no {index}\r\n', "utf-8"))

status = tn.expect(['disable', 'enable'])

tn.send(b"quit\r\n")
tn.expect(pexpect.EOF)

return True if status == 1 else False