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

Freeze 0.1.0/rc #72

Merged
merged 6 commits into from
Aug 28, 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
2 changes: 1 addition & 1 deletion client/panduza/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
from .core import EnsureError

from .interfaces import Dio
from .interfaces import Bps
from .interfaces import Bpc
from .interfaces import Ammeter

4 changes: 2 additions & 2 deletions client/panduza/admin/writer_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def write(self):
"port": 1883,
"interfaces": [
{
"name": "fake_bps",
"driver": "py.bps.fake"
"name": "fake_bpc",
"driver": "py.bpc.fake"
}
]
}
Expand Down
25 changes: 23 additions & 2 deletions client/panduza/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,13 @@ def __store_scan_result(self, topic, payload):
# Process the payload
info = json.loads(payload.decode("utf-8"))
if info["info"]["type"] == "platform":
self.__scan_count_platform += info["info"]["interfaces"]
self.__scan_count_interfaces += 1

print(info)
if info["info"]["state"] == "init":
self.__scan_restart_cmd = True
else:
self.__scan_count_platform += info["info"]["interfaces"]
self.__scan_count_interfaces += 1
else:
self.__scan_count_interfaces += 1

Expand Down Expand Up @@ -303,6 +308,7 @@ def scan_interfaces(self, type_filter="*"):
self.__scan_count_platform = 0
self.__scan_count_interfaces = 0
self.__scan_type_filter = type_filter
self.__scan_restart_cmd = False

# Debug log
self.log.info("Start Interface Scanning...")
Expand All @@ -321,6 +327,21 @@ def scan_interfaces(self, type_filter="*"):
with self.__scan_mutex:
continue_scan = (self.__scan_count_platform == 0) or (self.__scan_count_platform != self.__scan_count_interfaces)


if self.__scan_restart_cmd:
print("restart")
continue_scan = True
self.__scan_restart_cmd = False
time.sleep(2)
start_scan_time = time.perf_counter()
self.__scan_count_platform = 0
self.__scan_count_interfaces = 0
self.__scan_results = {}
self.__scan_messages_logs = queue.Queue()
self.publish("pza", u"*", qos=0)
print("okkk")


# Debug logs from the mqtt client thread
while not self.__scan_messages_logs.empty():
msg = self.__scan_messages_logs.get()
Expand Down
2 changes: 1 addition & 1 deletion client/panduza/interfaces/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .dio import Dio
from .bps import Bps
from .bpc import Bpc
from .relay import Relay
from .ammeter import Ammeter
# from .serial_ import Serial
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from ..core import Interface, Attribute, RoField, RwField

@dataclass
class Bps(Interface):
class Bpc(Interface):
"""Interface to manage power supplies
"""

Expand All @@ -29,13 +29,13 @@ def __post_init__(self):
RwField( name = "value" )
)

# === VOLTS ===
# === VOLTAGE ===
self.add_attribute(
Attribute( name = "volts" )
Attribute( name = "voltage" )
).add_field(
RoField( name = "real" )
).add_field(
RwField( name = "goal" )
RwField( name = "value" )
).add_field(
RoField( name = "min" )
).add_field(
Expand All @@ -46,13 +46,13 @@ def __post_init__(self):
RwField( name = "polling_cycle" )
)

# === AMPS ===
# === CURRENT ===
self.add_attribute(
Attribute( name = "amps" )
Attribute( name = "current" )
).add_field(
RoField( name = "real" )
).add_field(
RwField( name = "goal" )
RwField( name = "value" )
).add_field(
RoField( name = "min" )
).add_field(
Expand Down
6 changes: 3 additions & 3 deletions client/panduza/interfaces/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ..core.interface import Interface

from .dio import Dio
from .bps import Bps
from .bpc import Bpc
from .ammeter import Ammeter

from .relay import Relay
Expand All @@ -19,7 +19,7 @@ def GenerateAllInterfacesFromAliases(connections):
#
type_gen = {
"dio": Dio,
"bps": Bps,
"bpc": Bpc,
"ammeter": Ammeter,
"relay": Relay,
"voltmeter": Voltmeter
Expand Down Expand Up @@ -51,7 +51,7 @@ def GenerateAllInterfacesFromAliases(connections):
assert t != "unknown", f"Error > {name} interface does not respond"
assert t in type_gen, f"Unmanaged interface type {t} by panduza robotF plugin for {name}"
typed_interfaces[name] = type_gen[t](interface=itf)
# typed_interfaces[name] = Bps(interface=itf)
# typed_interfaces[name] = Bpc(interface=itf)


return typed_interfaces
Expand Down
4 changes: 2 additions & 2 deletions client/panduza/robof/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from .ammeter import KeywordsAmmeter
from .client import KeywordsClient
from .bps import KeywordsBps
from .bpc import KeywordsBpc
from .dio import KeywordsDio
from .relay import KeywordsRelay
from .voltmeter import KeywordsVoltmeter
Expand All @@ -23,7 +23,7 @@ def __init__(self):
KeywordsAmmeter(),
KeywordsClient(),
KeywordsDio(),
KeywordsBps(),
KeywordsBpc(),
KeywordsRelay(),
KeywordsVoltmeter(),

Expand Down
104 changes: 52 additions & 52 deletions client/panduza/robof/bps.py → client/panduza/robof/bpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,159 +3,159 @@
from hamcrest import assert_that, equal_to, any_of
from .utils import boolean_str_to_boolean

class KeywordsBps(object):
class KeywordsBpc(object):

###########################################################################
# STATE
###########################################################################

@keyword
def turn_power_supply(self, bps_alias, state, ensure=True):
"""Turn the bps on the given state
def turn_power_supply(self, bpc_alias, state, ensure=True):
"""Turn the bpc on the given state
"""
pza = BuiltIn().get_variable_value("${__pza__}")
pza[bps_alias].enable.value.set(boolean_str_to_boolean(state), ensure)
pza[bpc_alias].enable.value.set(boolean_str_to_boolean(state), ensure)

# ---

@keyword
def turn_on_power_supply(self, bps_alias, ensure=True):
"""Turn on the bps
def turn_on_power_supply(self, bpc_alias, ensure=True):
"""Turn on the bpc
"""
pza = BuiltIn().get_variable_value("${__pza__}")
pza[bps_alias].enable.value.set(boolean_str_to_boolean("on"), ensure)
pza[bpc_alias].enable.value.set(boolean_str_to_boolean("on"), ensure)

# ---

@keyword
def turn_off_power_supply(self, bps_alias, ensure=True, teardown=False):
"""Turn off the bps
def turn_off_power_supply(self, bpc_alias, ensure=True, teardown=False):
"""Turn off the bpc
"""
pza = BuiltIn().get_variable_value("${__pza__}")

if pza == None:
# It is ok if panduza is not initialized, only if in the teardown process
assert not teardown
else:
pza[bps_alias].enable.value.set(boolean_str_to_boolean("off"), ensure)
pza[bpc_alias].enable.value.set(boolean_str_to_boolean("off"), ensure)

# ---

@keyword
def power_supply_should_be(self, bps_alias, state):
def power_supply_should_be(self, bpc_alias, state):
"""Check power supply state
"""
expected_state_bool = boolean_str_to_boolean(state)
pza = BuiltIn().get_variable_value("${__pza__}")
read_state = pza[bps_alias].enable.value.get()
read_state = pza[bpc_alias].enable.value.get()
assert_that(read_state, equal_to(expected_state_bool))

###########################################################################
# VOLTS
# VOLTAGE
###########################################################################

@keyword
def set_power_supply_voltage_goal(self, bps_alias, voltage, ensure=True):
"""Set the power supply voltage goal
def set_power_supply_voltage_value(self, bpc_alias, voltage, ensure=True):
"""Set the power supply voltage value
"""
pza = BuiltIn().get_variable_value("${__pza__}")
pza[bps_alias].volts.goal.set(float(voltage), ensure)
pza[bpc_alias].voltage.value.set(float(voltage), ensure)

@keyword
def set_power_supply_voltage_polling_cycle(self, bps_alias:str, cycle:float, ensure=True):
"""Set the power supply voltage goal
def set_power_supply_voltage_polling_cycle(self, bpc_alias:str, cycle:float, ensure=True):
"""Set the power supply voltage value
"""
pza = BuiltIn().get_variable_value("${__pza__}")
pza[bps_alias].volts.polling_cycle.set(float(cycle), ensure)
pza[bpc_alias].voltage.polling_cycle.set(float(cycle), ensure)

###########################################################################
# AMPS
# CURRENT
###########################################################################

@keyword
def set_power_supply_current_goal(self, bps_alias, current, ensure=True):
"""Set the power supply amps goal
def set_power_supply_current_value(self, bpc_alias, current, ensure=True):
"""Set the power supply current value
"""
pza = BuiltIn().get_variable_value("${__pza__}")
pza[bps_alias].amps.goal.set(float(current), ensure)
pza[bpc_alias].current.value.set(float(current), ensure)

@keyword
def set_power_supply_current_polling_cycle(self, bps_alias:str, cycle:float, ensure=True):
"""Set the power supply voltage goal
def set_power_supply_current_polling_cycle(self, bpc_alias:str, cycle:float, ensure=True):
"""Set the power supply voltage value
"""
pza = BuiltIn().get_variable_value("${__pza__}")
pza[bps_alias].amps.polling_cycle.set(float(cycle), ensure)
pza[bpc_alias].current.polling_cycle.set(float(cycle), ensure)

###########################################################################
# SETTINGS
###########################################################################

@keyword
def turn_power_supply_ovp_setting(self, bps_alias, value, ensure=True):
"""Turn bps setting ovp to the given state
def turn_power_supply_ovp_setting(self, bpc_alias, value, ensure=True):
"""Turn bpc setting ovp to the given state
"""
bool_val = boolean_str_to_boolean(value)
pza = BuiltIn().get_variable_value("${__pza__}")
pza[bps_alias].settings.ovp.set(bool_val, ensure)
pza[bpc_alias].settings.ovp.set(bool_val, ensure)

# ---

@keyword
def turn_power_supply_ocp_setting(self, bps_alias, value, ensure=True):
"""Turn bps setting ocp to the given state
def turn_power_supply_ocp_setting(self, bpc_alias, value, ensure=True):
"""Turn bpc setting ocp to the given state
"""
bool_val = boolean_str_to_boolean(value)
pza = BuiltIn().get_variable_value("${__pza__}")
pza[bps_alias].settings.ocp.set(bool_val, ensure)
pza[bpc_alias].settings.ocp.set(bool_val, ensure)

# ---

@keyword
def turn_power_supply_silent_setting(self, bps_alias, value, ensure=True):
"""Turn bps setting silent to the given state
def turn_power_supply_silent_setting(self, bpc_alias, value, ensure=True):
"""Turn bpc setting silent to the given state
"""
bool_val = boolean_str_to_boolean(value)
pza = BuiltIn().get_variable_value("${__pza__}")
pza[bps_alias].settings.silent.set(bool_val, ensure)
pza[bpc_alias].settings.silent.set(bool_val, ensure)

###########################################################################
# MISC
###########################################################################

@keyword
def read_power_supply_misc(self, bps_alias, misc_field, ensure=True):
def read_power_supply_misc(self, bpc_alias, misc_field, ensure=True):
"""Return the given misc_field
"""
# assert_that(value, any_of(equal_to(True), equal_to(False)))
pza = BuiltIn().get_variable_value("${__pza__}")
return pza[bps_alias].misc.get(misc_field)
return pza[bpc_alias].misc.get(misc_field)

###########################################################################
# FULL STANDART TESTS
###########################################################################

@keyword
def interface_bps_basic_controls(self, bps_alias):
def interface_bpc_basic_controls(self, bpc_alias):
"""Just test basic commands of a Power SUpply interface

Warning this test
"""
# Test voltage goal
BuiltIn().run_keyword("Set Power Supply Voltage Goal", bps_alias, 10)
BuiltIn().run_keyword("Set Power Supply Voltage Goal", bps_alias, 3.3)
# Test voltage value
BuiltIn().run_keyword("Set Power Supply Voltage value", bpc_alias, 10)
BuiltIn().run_keyword("Set Power Supply Voltage value", bpc_alias, 3.3)

# Test current limit
BuiltIn().run_keyword("Set Power Supply Current Goal", bps_alias, 2)
BuiltIn().run_keyword("Set Power Supply Current Goal", bps_alias, 0.1)
BuiltIn().run_keyword("Set Power Supply Current value", bpc_alias, 2)
BuiltIn().run_keyword("Set Power Supply Current value", bpc_alias, 0.1)

# Try to turn on and off
BuiltIn().run_keyword("Turn On Power Supply", bps_alias)
BuiltIn().run_keyword("Power Supply Should Be", bps_alias, "on")
BuiltIn().run_keyword("Turn Off Power Supply", bps_alias)
BuiltIn().run_keyword("Power Supply Should Be", bps_alias, "off")

BuiltIn().run_keyword("Turn Power Supply", bps_alias, "on")
BuiltIn().run_keyword("Power Supply Should Be", bps_alias, "on")
BuiltIn().run_keyword("Turn Power Supply", bps_alias, "off")
BuiltIn().run_keyword("Power Supply Should Be", bps_alias, "off")
BuiltIn().run_keyword("Turn On Power Supply", bpc_alias)
BuiltIn().run_keyword("Power Supply Should Be", bpc_alias, "on")
BuiltIn().run_keyword("Turn Off Power Supply", bpc_alias)
BuiltIn().run_keyword("Power Supply Should Be", bpc_alias, "off")

BuiltIn().run_keyword("Turn Power Supply", bpc_alias, "on")
BuiltIn().run_keyword("Power Supply Should Be", bpc_alias, "on")
BuiltIn().run_keyword("Turn Power Supply", bpc_alias, "off")
BuiltIn().run_keyword("Power Supply Should Be", bpc_alias, "off")

2 changes: 1 addition & 1 deletion client/panduza/robof/dio.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def change_dio_logic_active_low(self, dio_alias, active_low, ensure=True):
def test_basic_access_of_dio_interface(self, dio_alias):
"""Just test basic commands of a DIO interface
"""
# Test voltage goal
# Test voltage value
BuiltIn().run_keyword("Set Dio Direction", dio_alias, "in")
BuiltIn().run_keyword("Set Dio Direction", dio_alias, "out")

Expand Down
2 changes: 1 addition & 1 deletion client/tools/modbus_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Script to test bps on the given broker
"""Script to test bpc on the given broker

WARNING : !!! Make sur your Power Supply are not connected to any board !!!
"""
Expand Down
Loading
Loading