diff --git a/osfv_cli/src/osfv/cli/cli.py b/osfv_cli/src/osfv/cli/cli.py index 0168b96..d882835 100755 --- a/osfv_cli/src/osfv/cli/cli.py +++ b/osfv_cli/src/osfv/cli/cli.py @@ -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!' diff --git a/osfv_cli/src/osfv/libs/rte.py b/osfv_cli/src/osfv/libs/rte.py index 410df1f..e54fbbb 100644 --- a/osfv_cli/src/osfv/libs/rte.py +++ b/osfv_cli/src/osfv/libs/rte.py @@ -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" @@ -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): @@ -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) @@ -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)