Skip to content

Commit

Permalink
osfv_cli/rte: normalize on/off PSU states strings
Browse files Browse the repository at this point in the history
Sonoff returns capital ON/OFF, while relay returned on/off.
We define relay strings here, so can be changed here to
unify the reponses, no matter which power control method
was used at the time.

The more proper solution would be to implement:
#77

Signed-off-by: Maciej Pijanowski <[email protected]>
  • Loading branch information
macpijan committed Dec 1, 2024
1 parent 743891d commit c7a007e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion osfv_cli/src/osfv/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def relay_get(rte, args):

def power_on(rte, args):
state = rte.psu_get()
if state != "on" or state != "ON":
if state != rte.PSU_STATE_ON:
print(f"Power supply state: {state} !")
print(
'If you wanted to power on the DUT, you need to enable power supply first ("pwr psu on"), pushing the power button is not enough!'
Expand Down
17 changes: 10 additions & 7 deletions osfv_cli/src/osfv/libs/rte.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class RTE(rtectrl):

GPIO_CMOS = 12

PSU_STATE_ON = "ON"
PSU_STATE_OFF = "OFF"

SSH_USER = "root"
SSH_PWD = "meta-rte"
FW_PATH_WRITE = "/data/write.rom"
Expand Down Expand Up @@ -147,9 +150,9 @@ def relay_get(self):
gpio_state = self.gpio_get(self.GPIO_RELAY)
relay_state = None
if gpio_state == "high":
relay_state = "on"
relay_state = self.PSU_STATE_ON
if gpio_state == "low":
relay_state = "off"
relay_state = self.PSU_STATE_OFF
return relay_state

def relay_set(self, relay_state):
Expand All @@ -161,9 +164,9 @@ def relay_set(self, relay_state):
or "off" (sets GPIO pin to "low").
"""
gpio_state = None
if relay_state == "on":
if relay_state == self.PSU_STATE_ON:
gpio_state = "high"
if relay_state == "off":
if relay_state == self.PSU_STATE_OFF:
gpio_state = "low"
self.gpio_set(self.GPIO_RELAY, gpio_state)

Expand Down Expand Up @@ -226,12 +229,12 @@ def psu_off(self):
if self.dut_data["pwr_ctrl"]["sonoff"] is True:
self.sonoff.turn_off()
state = self.sonoff.get_state()
if state != "OFF":
if state != self.PSU_STATE_OFF:
raise Exception("Failed to power control OFF")
elif self.dut_data["pwr_ctrl"]["relay"] is True:
self.relay_set("off")
self.relay_set(self.PSU_STATE_OFF)
state = self.relay_get()
if state != "off":
if state != self.PSU_STATE_OFF:
raise Exception("Failed to power control OFF")
time.sleep(2)

Expand Down

0 comments on commit c7a007e

Please sign in to comment.