Skip to content

Commit

Permalink
WIP: generic device interface in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
wardru committed Jul 26, 2023
1 parent 8601d63 commit cf15296
Show file tree
Hide file tree
Showing 19 changed files with 225 additions and 181 deletions.
32 changes: 16 additions & 16 deletions platform/old_drivers_need_to_be_reworked/aimtti/driver_ql355p.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ def _PZA_DRV_loop_init(self, loop, tree):
self.amps = 0

# Constants Fields settings
self._PZA_DRV_BPS_update_volts_min_max(VOLTS_BOUNDS["min"], VOLTS_BOUNDS["max"])
self._PZA_DRV_BPS_update_amps_min_max(AMPS_BOUNDS["min"], AMPS_BOUNDS["max"])
self._PZA_DRV_BPS_CTRL_update_volts_min_max(VOLTS_BOUNDS["min"], VOLTS_BOUNDS["max"])
self._PZA_DRV_BPS_CTRL_update_amps_min_max(AMPS_BOUNDS["min"], AMPS_BOUNDS["max"])

# Misc
self._PZA_DRV_BPS_update_misc("model", "QL355P (AIM-TTI)")
self._PZA_DRV_BPS_CTRL_update_misc("model", "QL355P (AIM-TTI)")

# Call meta class BPS ini
super()._PZA_DRV_loop_init(tree)
Expand All @@ -113,70 +113,70 @@ def __write(self, *cmds):

# STATE #

def _PZA_DRV_BPS_read_enable_value(self):
def _PZA_DRV_BPS_CTRL_read_enable_value(self):
return self.state

# ---

def _PZA_DRV_BPS_write_enable_value(self, v):
def _PZA_DRV_BPS_CTRL_write_enable_value(self, v):
self.state = v
cmd = STATE_VALUE_ENUM[v]
self.__write(f"OP1 {int(cmd)}")

# VOLTS #

def _PZA_DRV_BPS_read_volts_goal(self):
def _PZA_DRV_BPS_CTRL_read_volts_goal(self):
return self.volts

# ---

def _PZA_DRV_BPS_read_volts_real(self):
def _PZA_DRV_BPS_CTRL_read_volts_real(self):
return 0

# ---

def _PZA_DRV_BPS_write_volts_goal(self, v):
def _PZA_DRV_BPS_CTRL_write_volts_goal(self, v):
self.volts = v
self.__write(f"V1 {v:.3f}")

# ---

def _PZA_DRV_BPS_volts_goal_min_max(self):
def _PZA_DRV_BPS_CTRL_volts_goal_min_max(self):
return VOLTS_BOUNDS
# ---

def _PZA_DRV_BPS_read_volts_decimals(self):
def _PZA_DRV_BPS_CTRL_read_volts_decimals(self):
return 2

# AMPS #

def _PZA_DRV_BPS_read_amps_goal(self):
def _PZA_DRV_BPS_CTRL_read_amps_goal(self):
return self.amps

# ---

def _PZA_DRV_BPS_write_amps_goal(self, v):
def _PZA_DRV_BPS_CTRL_write_amps_goal(self, v):
self.amps = v
self.__write(f"I1 {v:.3f}")

# ---

def _PZA_DRV_BPS_amps_goal_min_max(self):
def _PZA_DRV_BPS_CTRL_amps_goal_min_max(self):
return AMPS_BOUNDS

# ---

def _PZA_DRV_BPS_read_amps_real(self):
def _PZA_DRV_BPS_CTRL_read_amps_real(self):
return 0

# ---

def _PZA_DRV_BPS_read_amps_decimals(self):
def _PZA_DRV_BPS_CTRL_read_amps_decimals(self):
return 3

# SETTINGS #

def _PZA_DRV_BPS_settings_capabilities(self):
def _PZA_DRV_BPS_CTRL_settings_capabilities(self):
return {
"ovp": False,
"ocp": False,
Expand Down
18 changes: 9 additions & 9 deletions platform/old_drivers_need_to_be_reworked/rspro/driver_4303s.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ def _PZA_DRV_loop_init(self, loop, tree):
self.amps = 0

# Constants Fields settings
self._PZA_DRV_BPS_update_volts_min_max(VOLTS_BOUNDS["min"], VOLTS_BOUNDS["max"])
self._PZA_DRV_BPS_update_amps_min_max(AMPS_BOUNDS["min"], AMPS_BOUNDS["max"])
self._PZA_DRV_BPS_CTRL_update_volts_min_max(VOLTS_BOUNDS["min"], VOLTS_BOUNDS["max"])
self._PZA_DRV_BPS_CTRL_update_amps_min_max(AMPS_BOUNDS["min"], AMPS_BOUNDS["max"])

# Misc
self._PZA_DRV_BPS_update_misc("model", "IPS4303S (RS Pro)")
self._PZA_DRV_BPS_CTRL_update_misc("model", "IPS4303S (RS Pro)")

# Call meta class BPS ini
super()._PZA_DRV_loop_init(tree)
Expand All @@ -115,25 +115,25 @@ def __write(self, *cmds):
###########################################################################
###########################################################################

def _PZA_DRV_BPS_read_enable_value(self):
def _PZA_DRV_BPS_CTRL_read_enable_value(self):
return self.state

def _PZA_DRV_BPS_write_enable_value(self, v):
def _PZA_DRV_BPS_CTRL_write_enable_value(self, v):
self.state = v
cmd = STATE_VALUE_ENUM[v]
self.__write(f"OUT{int(cmd)}")

def _PZA_DRV_BPS_read_volts_goal(self):
def _PZA_DRV_BPS_CTRL_read_volts_goal(self):
return self.volts

def _PZA_DRV_BPS_write_volts_goal(self, v):
def _PZA_DRV_BPS_CTRL_write_volts_goal(self, v):
self.volts = v
self.__write(f"VSET1:{v:.3f}")

def _PZA_DRV_BPS_read_amps_goal(self):
def _PZA_DRV_BPS_CTRL_read_amps_goal(self):
return self.amps

def _PZA_DRV_BPS_write_amps_goal(self, v):
def _PZA_DRV_BPS_CTRL_write_amps_goal(self, v):
self.amps = v
self.__write(f"ISET1:{v:.3f}")

Expand Down
8 changes: 4 additions & 4 deletions platform/panduza_platform/core/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,10 @@ def run(self):

# --

def load_interface(self, bench_name, device_name, interface_config):
def load_interface(self, bench_name, device_name, interface_config, device = None):
"""Load a new interface
"""
instance = self.driver_factory.produce_interface(bench_name, device_name, interface_config)
instance = self.driver_factory.produce_interface(bench_name, device_name, interface_config, device)
self.interfaces.append(instance)

# --
Expand Down Expand Up @@ -468,11 +468,11 @@ def __load_devices(self):
# device == class type for device
device = self.device_factory.produce_device(device_cfg)

device_name = device_cfg["model"].replace(".", "_")
device_name = device_cfg["name"].replace(".", "_")

interfaces = device._PZA_DEV_interfaces()
self.log.info(f"{device_name} => {interfaces}")
for interface_config in interfaces:
self.load_interface("default", device_name, interface_config)
self.load_interface("default", device_name, interface_config, device = device)


31 changes: 20 additions & 11 deletions platform/panduza_platform/core/platform_device_factory.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import traceback
from .platform_errors import InitializationError
from devices import PZA_DEVICES_LIST as INBUILT_DEVICES
import sys

class PlatformDeviceFactory:
"""Manage the factory of devices
Expand All @@ -21,17 +22,22 @@ def produce_device(self, config):
"""Try to produce the given device model
"""
# Get model name and control it exists in the config provided by the user
if not "model" in config:
raise InitializationError(f"\"model\" field is not provided in the config {config}")
model = config["model"]
if not "name" in config:
raise InitializationError(f"\"name\" field is not provided in the config {config}")
name = config["name"]

# Control the model exists in the database
if not model in self.__devices:
raise InitializationError(f"\"{model}\" is not found in this platform")
if not name in self.__devices:
raise InitializationError(f"\"{name}\" is not found in this platform")

# Produce the device
try:
return self.__devices[model](config.get("settings", {}))
dev = self.__devices[name](config.get("settings", {}))
self.__platform.load_interface("default", name.replace(".", "_"), {
"name": "device",
"driver": "py.device"
}, dev)
return dev

except Exception as e:
raise InitializationError(f"{traceback.format_exc()}")

Expand All @@ -48,10 +54,13 @@ def discover(self):
# ---

def register_device(self, dev):
"""Register a new device model
"""Register a new device
"""
model = dev()._PZA_DEV_config()['model']
self.__log.info(f"Register device model: '{model}'")
self.__devices[model] = dev
cfg = dev()._PZA_DEV_config()
model = cfg['model']
manufacturer = cfg['manufacturer']
name = manufacturer + "." + model
self.__log.info(f"Register device model {model} from {manufacturer}")
self.__devices[name] = dev


44 changes: 42 additions & 2 deletions platform/panduza_platform/core/platform_device_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import abc
import sys

class PlatformDeviceModel:
"""Mother class for device models
Expand All @@ -8,16 +9,55 @@ def __init__(self, settings = {}) -> None:
"""Constructor
"""
self._initial_settings = settings
self._interfaces = []
self._model = None
self._manufacturer = None
self._characteristics = {}
self.name = None

@abc.abstractmethod
def _PZA_DEV_config(self):
"""
"""
pass
if self._model == None:
raise Exception("Model is not set")
if self._manufacturer == None:
raise Exception("Manufacturer is not set")
if self._characteristics == None:
raise Warning("Characteristics is not set")

self._PZA_DEV_set_name()

return {
"model": self._model,
"manufacturer": self._manufacturer,
"characteristics": self._characteristics
}

@abc.abstractmethod
def _PZA_DEV_interfaces(self):

"""
"""
return {}

# set model
def _PZA_DEV_set_model(self, model):
"""
"""
self._model = model

def _PZA_DEV_set_name(self):
"""
"""
self._name = self._model + "_" + self._manufacturer

# set manufacturer
def _PZA_DEV_set_manufacturer(self, manufacturer):
"""
"""
self._manufacturer = manufacturer

def _PZA_DEV_set_characteristics(self, characteristics):
"""
"""
self._characteristics = characteristics
3 changes: 3 additions & 0 deletions platform/panduza_platform/core/platform_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def set_device_name(self, name):

# ---

def set_device(self, device):
self.device = device

def set_tree(self, tree):
self.tree = tree

Expand Down
5 changes: 3 additions & 2 deletions platform/panduza_platform/core/platform_driver_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, parent_platform):

# ---

def produce_interface(self, bench_name, device_name, interface_config):
def produce_interface(self, bench_name, device_name, interface_config, device = None):
"""
"""
try:
Expand All @@ -35,6 +35,7 @@ def produce_interface(self, bench_name, device_name, interface_config):
instance.set_platform(self.__platform)
instance.set_bench_name(bench_name)
instance.set_device_name(device_name)
instance.set_device(device)
instance.set_tree(interface_config)

self.__log.info(f"> {name} [{driver_name}]")
Expand Down Expand Up @@ -72,7 +73,7 @@ def register_driver(self, dev):
raise InitializationError(f"'name' field is not found in config of driver {dev} => config:{dev_config}")

# Register driver
name = dev()._PZA_DRV_config()['name']
name = dev_config['name']
self.__drivers[name] = dev
self.__log.info(f"Register driver: '{name}'")

Expand Down
2 changes: 1 addition & 1 deletion platform/panduza_platform/devices/hanmatek/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .hm310t import DeviceHanmatekHm310t

PZA_DEVICES_LIST= [
DeviceHanmatekHm310t
#DeviceHanmatekHm310t
]
4 changes: 2 additions & 2 deletions platform/panduza_platform/devices/hanmatek/hm310t.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def _PZA_DEV_interfaces(self):
pass
else:
interfaces.append({
"name": f"bps",
"driver": "hanmatek.hm310t.bps",
"name": f"psu",
"driver": "hanmatek.hm310t.psu",
"settings": {
"usb_vendor": USBID_VENDOR,
"usb_model": USBID_MODEL,
Expand Down
4 changes: 2 additions & 2 deletions platform/panduza_platform/devices/panduza/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .fake_relay_controller import DevicePanduzaFakeRelayController

PZA_DEVICES_LIST= [
DevicePanduzaFakeDioController,
#DevicePanduzaFakeDioController,
DevicePanduzaFakeBps,
DevicePanduzaFakeRelayController
#DevicePanduzaFakeRelayController
]
Loading

0 comments on commit cf15296

Please sign in to comment.