diff --git a/platform/old_drivers_need_to_be_reworked/aimtti/driver_ql355p.py b/platform/old_drivers_need_to_be_reworked/aimtti/driver_ql355p.py index c118219..1af9464 100644 --- a/platform/old_drivers_need_to_be_reworked/aimtti/driver_ql355p.py +++ b/platform/old_drivers_need_to_be_reworked/aimtti/driver_ql355p.py @@ -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) @@ -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, diff --git a/platform/old_drivers_need_to_be_reworked/rspro/driver_4303s.py b/platform/old_drivers_need_to_be_reworked/rspro/driver_4303s.py index 524e4ce..1623ab6 100644 --- a/platform/old_drivers_need_to_be_reworked/rspro/driver_4303s.py +++ b/platform/old_drivers_need_to_be_reworked/rspro/driver_4303s.py @@ -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) @@ -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}") diff --git a/platform/panduza_platform/core/platform.py b/platform/panduza_platform/core/platform.py index 9208cec..c734687 100644 --- a/platform/panduza_platform/core/platform.py +++ b/platform/panduza_platform/core/platform.py @@ -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) # -- @@ -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) diff --git a/platform/panduza_platform/core/platform_device_factory.py b/platform/panduza_platform/core/platform_device_factory.py index 182e8de..8e36211 100644 --- a/platform/panduza_platform/core/platform_device_factory.py +++ b/platform/panduza_platform/core/platform_device_factory.py @@ -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 @@ -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()}") @@ -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 diff --git a/platform/panduza_platform/core/platform_device_model.py b/platform/panduza_platform/core/platform_device_model.py index 23aab3f..dedb291 100644 --- a/platform/panduza_platform/core/platform_device_model.py +++ b/platform/panduza_platform/core/platform_device_model.py @@ -1,4 +1,5 @@ import abc +import sys class PlatformDeviceModel: """Mother class for device models @@ -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 \ No newline at end of file diff --git a/platform/panduza_platform/core/platform_driver.py b/platform/panduza_platform/core/platform_driver.py index b625ce8..668e2c6 100644 --- a/platform/panduza_platform/core/platform_driver.py +++ b/platform/panduza_platform/core/platform_driver.py @@ -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 diff --git a/platform/panduza_platform/core/platform_driver_factory.py b/platform/panduza_platform/core/platform_driver_factory.py index f7b6638..5564097 100644 --- a/platform/panduza_platform/core/platform_driver_factory.py +++ b/platform/panduza_platform/core/platform_driver_factory.py @@ -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: @@ -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}]") @@ -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}'") diff --git a/platform/panduza_platform/devices/hanmatek/__init__.py b/platform/panduza_platform/devices/hanmatek/__init__.py index 71edb36..8eb9d22 100644 --- a/platform/panduza_platform/devices/hanmatek/__init__.py +++ b/platform/panduza_platform/devices/hanmatek/__init__.py @@ -1,5 +1,5 @@ from .hm310t import DeviceHanmatekHm310t PZA_DEVICES_LIST= [ - DeviceHanmatekHm310t + #DeviceHanmatekHm310t ] diff --git a/platform/panduza_platform/devices/hanmatek/hm310t.py b/platform/panduza_platform/devices/hanmatek/hm310t.py index cda2ebd..68d7bc1 100644 --- a/platform/panduza_platform/devices/hanmatek/hm310t.py +++ b/platform/panduza_platform/devices/hanmatek/hm310t.py @@ -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, diff --git a/platform/panduza_platform/devices/panduza/__init__.py b/platform/panduza_platform/devices/panduza/__init__.py index fcfcca5..fb6e82e 100644 --- a/platform/panduza_platform/devices/panduza/__init__.py +++ b/platform/panduza_platform/devices/panduza/__init__.py @@ -3,7 +3,7 @@ from .fake_relay_controller import DevicePanduzaFakeRelayController PZA_DEVICES_LIST= [ - DevicePanduzaFakeDioController, + #DevicePanduzaFakeDioController, DevicePanduzaFakeBps, - DevicePanduzaFakeRelayController + #DevicePanduzaFakeRelayController ] diff --git a/platform/panduza_platform/devices/panduza/fake_bps_controller.py b/platform/panduza_platform/devices/panduza/fake_bps_controller.py index b491dbb..2dd31b2 100644 --- a/platform/panduza_platform/devices/panduza/fake_bps_controller.py +++ b/platform/panduza_platform/devices/panduza/fake_bps_controller.py @@ -1,29 +1,34 @@ from core.platform_device_model import PlatformDeviceModel +import sys class DevicePanduzaFakeBps(PlatformDeviceModel): - def _PZA_DEV_config(self): + def __init__(self, settings = {}) -> None: + """Constructor """ - """ - return { - "model": "Panduza.FakeBps", - } + super().__init__(settings) + + self._number_of_channel = int( self._initial_settings.get("number_of_channel", 1) ) + + super()._PZA_DEV_set_model("FakeBps") + super()._PZA_DEV_set_manufacturer("Panduza") + super()._PZA_DEV_set_characteristics({ + "number_of_channel": self._number_of_channel + }) def _PZA_DEV_interfaces(self): """ """ + super()._PZA_DEV_interfaces() - number_of_channel = int( self._initial_settings.get("number_of_channel", 1) ) - - interfaces = [] - for chan in range(0, number_of_channel): - interfaces.append( + for chan in range(0, self._number_of_channel): + self._interfaces.append( { - "name": f"channel_{chan}", - "driver": "panduza.fake.bps" + "name": f"channel_{chan}_ctrl", + "driver": "panduza.fake.bps_control" } ) - interfaces.append( + self._interfaces.append( { "name": f"channel_{chan}_am", "driver": "panduza.fake.ammeter", @@ -32,14 +37,14 @@ def _PZA_DEV_interfaces(self): } } ) - interfaces.append( + self._interfaces.append( { "name": f"channel_{chan}_vl", "driver": "panduza.fake.voltmeter", } ) - return interfaces + return self._interfaces diff --git a/platform/panduza_platform/drivers/bps/drv_hanmatek_hm310t_bps.py b/platform/panduza_platform/drivers/bps/drv_hanmatek_hm310t_bps.py index 3b10f94..8f36dc8 100644 --- a/platform/panduza_platform/drivers/bps/drv_hanmatek_hm310t_bps.py +++ b/platform/panduza_platform/drivers/bps/drv_hanmatek_hm310t_bps.py @@ -1,5 +1,5 @@ from hamcrest import assert_that, has_key, instance_of -from meta_drivers.bps import MetaDriverBps +from meta_drivers.bps_control import MetaDriverBpsControl from connectors.modbus_client_serial import ConnectorModbusClientSerial STATE_VALUE_ENUM = { True : 1, False: 0 } @@ -12,7 +12,7 @@ def int_to_state_string(v_int): position = val_list.index(v_int) return key_list[position] -class DrvHanmatekHm310tBps(MetaDriverBps): +class DrvHanmatekHm310tBps(MetaDriverBpsControl): """ Driver to manage the HM310T power supply """ @@ -21,11 +21,11 @@ class DrvHanmatekHm310tBps(MetaDriverBps): # --- - def _PZA_DRV_BPS_config(self): + def _PZA_DRV_BPS_CTRL_config(self): """ """ return { - "name": "hanmatek.hm310t.bps", + "name": "hanmatek.hm310t.bps_control", "description": "Power Supply HM310T from Hanmatek" } @@ -51,7 +51,7 @@ async def _PZA_DRV_loop_init(self, loop, tree): # self.modbus_unit = 1 - # Call meta class BPS ini + # Call meta class BPS init await super()._PZA_DRV_loop_init(loop, tree) ########################################################################### @@ -59,7 +59,7 @@ async def _PZA_DRV_loop_init(self, loop, tree): # STATE # - async def _PZA_DRV_BPS_read_enable_value(self): + async def _PZA_DRV_BPS_CTRL_read_enable_value(self): addr = 0x0001 regs = await self.modbus.read_holding_registers(addr, 1, self.modbus_unit) self.log.debug(f"read state addr={hex(addr)} regs={regs}") @@ -68,7 +68,7 @@ async def _PZA_DRV_BPS_read_enable_value(self): # --- - async def _PZA_DRV_BPS_write_enable_value(self, v): + async def _PZA_DRV_BPS_CTRL_write_enable_value(self, v): addr = 0x0001 int16_value = STATE_VALUE_ENUM[v] self.log.info(f"write state addr={hex(addr)} value={int16_value}") @@ -76,7 +76,7 @@ async def _PZA_DRV_BPS_write_enable_value(self, v): # VOLTS # - async def _PZA_DRV_BPS_read_volts_goal(self): + async def _PZA_DRV_BPS_CTRL_read_volts_goal(self): addr = 0x0030 regs = await self.modbus.read_holding_registers(addr, 1, self.modbus_unit) self.log.debug(f"read goal volts addr={hex(addr)} regs={regs}") @@ -85,7 +85,7 @@ async def _PZA_DRV_BPS_read_volts_goal(self): # --- - async def _PZA_DRV_BPS_write_volts_goal(self, v): + async def _PZA_DRV_BPS_CTRL_write_volts_goal(self, v): addr = 0x0030 int16_value = int(v * 100) self.log.info(f"write goal volts addr={hex(addr)} valuex100={int16_value}") @@ -93,17 +93,17 @@ async def _PZA_DRV_BPS_write_volts_goal(self, v): # --- - async def _PZA_DRV_BPS_volts_goal_min_max(self): + async def _PZA_DRV_BPS_CTRL_volts_goal_min_max(self): return VOLTS_BOUNDS # --- - async def _PZA_DRV_BPS_read_volts_decimals(self): + async def _PZA_DRV_BPS_CTRL_read_volts_decimals(self): return 2 # AMPS # - async def _PZA_DRV_BPS_read_amps_goal(self): + async def _PZA_DRV_BPS_CTRL_read_amps_goal(self): addr = 0x0031 regs = await self.modbus.read_holding_registers(addr, 1, self.modbus_unit) self.log.debug(f"read goal amps addr={hex(addr)} regs={regs}") @@ -112,7 +112,7 @@ async def _PZA_DRV_BPS_read_amps_goal(self): # --- - async def _PZA_DRV_BPS_write_amps_goal(self, v): + async def _PZA_DRV_BPS_CTRL_write_amps_goal(self, v): addr = 0x0031 int16_value = int(v * 1000.0) self.log.info(f"write goal amps addr={hex(addr)} valuex1000={int16_value}") @@ -120,11 +120,11 @@ async def _PZA_DRV_BPS_write_amps_goal(self, v): # --- - async def _PZA_DRV_BPS_amps_goal_min_max(self): + async def _PZA_DRV_BPS_CTRL_amps_goal_min_max(self): return AMPS_BOUNDS # --- - async def _PZA_DRV_BPS_read_amps_decimals(self): + async def _PZA_DRV_BPS_CTRL_read_amps_decimals(self): return 3 diff --git a/platform/panduza_platform/drivers/bps/drv_panduza_fake_bps.py b/platform/panduza_platform/drivers/bps/drv_panduza_fake_bps.py index 2761379..1291aba 100644 --- a/platform/panduza_platform/drivers/bps/drv_panduza_fake_bps.py +++ b/platform/panduza_platform/drivers/bps/drv_panduza_fake_bps.py @@ -1,8 +1,8 @@ import time from collections import ChainMap -from meta_drivers.bps import MetaDriverBps +from meta_drivers.bps_control import MetaDriverBpsControl -class DrvPanduzaFakeBps(MetaDriverBps): +class DrvPanduzaFakeBps(MetaDriverBpsControl): """Fake BPS driver """ @@ -11,11 +11,11 @@ class DrvPanduzaFakeBps(MetaDriverBps): # --- - def _PZA_DRV_BPS_config(self): + def _PZA_DRV_BPS_CTRL_config(self): """ """ return { - "name": "panduza.fake.bps", + "name": "panduza.fake.bps_control", "description": "Virtual BPS" } @@ -63,32 +63,32 @@ async def _PZA_DRV_loop_init(self, loop, tree): ########################################################################### - async def _PZA_DRV_BPS_read_enable_value(self): + async def _PZA_DRV_BPS_CTRL_read_enable_value(self): # self.log.debug(f"read enable !") return self.__fakes["enable"]["value"] # --- - async def _PZA_DRV_BPS_write_enable_value(self, v): + async def _PZA_DRV_BPS_CTRL_write_enable_value(self, v): self.log.info(f"write enable : {v}") self.__fakes["enable"]["value"] = v ########################################################################### - async def _PZA_DRV_BPS_read_volts_goal(self): + async def _PZA_DRV_BPS_CTRL_read_volts_goal(self): # self.log.debug(f"read volts goal !") return self.__fakes["volts"]["goal"] # --- - async def _PZA_DRV_BPS_write_volts_goal(self, v): + async def _PZA_DRV_BPS_CTRL_write_volts_goal(self, v): self.log.info(f"write volts : {v}") self.__fakes["volts"]["goal"] = v self.__fakes["volts"]["real"] = v # --- - async def _PZA_DRV_BPS_volts_goal_min_max(self): + async def _PZA_DRV_BPS_CTRL_volts_goal_min_max(self): return { "min": self.__fakes["volts"]["min"], "max": self.__fakes["volts"]["max"] @@ -96,25 +96,25 @@ async def _PZA_DRV_BPS_volts_goal_min_max(self): # --- - async def _PZA_DRV_BPS_read_volts_decimals(self): + async def _PZA_DRV_BPS_CTRL_read_volts_decimals(self): return self.__fakes["volts"]["decimals"] ########################################################################### - async def _PZA_DRV_BPS_read_amps_goal(self): + async def _PZA_DRV_BPS_CTRL_read_amps_goal(self): # self.log.debug(f"read amps goal !") return self.__fakes["amps"]["goal"] # --- - async def _PZA_DRV_BPS_write_amps_goal(self, v): + async def _PZA_DRV_BPS_CTRL_write_amps_goal(self, v): self.log.info(f"write amps : {v}") self.__fakes["amps"]["goal"] = v self.__fakes["amps"]["real"] = v # --- - async def _PZA_DRV_BPS_amps_goal_min_max(self): + async def _PZA_DRV_BPS_CTRL_amps_goal_min_max(self): return { "min": self.__fakes["amps"]["min"], "max": self.__fakes["amps"]["max"] @@ -122,6 +122,6 @@ async def _PZA_DRV_BPS_amps_goal_min_max(self): # --- - async def _PZA_DRV_BPS_read_amps_decimals(self): + async def _PZA_DRV_BPS_CTRL_read_amps_decimals(self): return self.__fakes["amps"]["decimals"] diff --git a/platform/panduza_platform/drivers/device/drv_hanmatek_hm310t_device.py b/platform/panduza_platform/drivers/device/drv_hanmatek_hm310t_device.py deleted file mode 100644 index 13412ab..0000000 --- a/platform/panduza_platform/drivers/device/drv_hanmatek_hm310t_device.py +++ /dev/null @@ -1,56 +0,0 @@ -import time -from hamcrest import assert_that, has_key, instance_of -from collections import ChainMap -from meta_drivers.bps import MetaDriverDevice -from connectors.modbus_client_serial import ConnectorModbusClientSerial - - - -class DrvHanmatekHm310tDevice(MetaDriverDevice): - """ Driver to manage the HM310T power supply - """ - - # ============================================================================= - # FROM MetaDriverBps - - # --- - - def _PZA_DRV_BPS_config(self): - """ - """ - return { - "name": "hanmatek.hm310t.device", - "description": "Device HM310T from Hanmatek" - } - - # --- - - def _PZA_DRV_loop_init(self, loop, tree): - """Driver initialization - """ - - # Load settings - assert_that(tree, has_key("settings")) - settings = tree["settings"] - assert_that(settings, instance_of(dict)) - - # Checks - assert_that(settings, has_key("vendor")) - assert_that(settings, has_key("model")) - assert_that(settings, has_key("baudrate")) - - # Get the gate - self.modbus = ConnectorModbusClientSerial.Get(**settings) - - # - self.modbus_unit = 1 - - # Misc - self.__misc = { - "model": "HM310T (Hanmatek)", - "modbus_slave_id": self.modbus_unit - } - - # Call meta class BPS ini - super()._PZA_DRV_loop_init(tree) - diff --git a/platform/panduza_platform/drivers/device/drv_panduza_fake_device.py b/platform/panduza_platform/drivers/device/drv_panduza_fake_device.py deleted file mode 100644 index e69de29..0000000 diff --git a/platform/panduza_platform/drivers/platform/__init__.py b/platform/panduza_platform/drivers/platform/__init__.py index c4967d8..218cfb7 100644 --- a/platform/panduza_platform/drivers/platform/__init__.py +++ b/platform/panduza_platform/drivers/platform/__init__.py @@ -1,6 +1,7 @@ from .drv_platform import DriverPlatform +from .drv_device import DriverDevice -PZA_DRIVERS_LIST= [DriverPlatform] +PZA_DRIVERS_LIST= [DriverPlatform, DriverDevice] diff --git a/platform/panduza_platform/drivers/platform/drv_device.py b/platform/panduza_platform/drivers/platform/drv_device.py new file mode 100644 index 0000000..ae1a234 --- /dev/null +++ b/platform/panduza_platform/drivers/platform/drv_device.py @@ -0,0 +1,41 @@ +import time +from core.platform_driver import PlatformDriver +import sys + +class DriverDevice(PlatformDriver): + """ + """ + + ########################################################################### + ########################################################################### + + def _PZA_DRV_config(self): + """From PlatformDriver + """ + return { + "name": "py.device", + "description": "Generic device interface", + "info": { + "type": "device", + "version": "0.0" + } + } + + ########################################################################### + ########################################################################### + + async def _PZA_DRV_loop_init(self, loop, tree): + """From PlatformDriver + """ + + print("DriverDevice: _PZA_DRV_loop_init", self.device) + await self._update_attributes_from_dict({ + "identify": { + "name": self.device._model, + "manufacturer": self.device._manufacturer, + } + }) + + # Tell the platform that the init state end sucessfuly + self._PZA_DRV_init_success() + diff --git a/platform/panduza_platform/meta_drivers/bps.py b/platform/panduza_platform/meta_drivers/bps_control.py similarity index 81% rename from platform/panduza_platform/meta_drivers/bps.py rename to platform/panduza_platform/meta_drivers/bps_control.py index 5ee1c69..ca0e203 100644 --- a/platform/panduza_platform/meta_drivers/bps.py +++ b/platform/panduza_platform/meta_drivers/bps_control.py @@ -4,8 +4,8 @@ from collections import ChainMap from core.platform_driver import PlatformDriver -class MetaDriverBps(PlatformDriver): - """ Abstract Driver with helper class to manage power supply interface +class MetaDriverBpsControl(PlatformDriver): + """ Abstract Driver with helper class to manage power supply control interface """ # ============================================================================= @@ -16,11 +16,11 @@ def _PZA_DRV_config(self): """ base = { "info": { - "type": "bps", + "type": "bps_control", "version": "0.0" } } - return ChainMap(base, self._PZA_DRV_BPS_config()) + return ChainMap(base, self._PZA_DRV_BPS_CTRL_config()) # ============================================================================= # TO OVERRIDE IN DRIVER @@ -28,63 +28,63 @@ def _PZA_DRV_config(self): # --- @abc.abstractmethod - def _PZA_DRV_BPS_config(self): + def _PZA_DRV_BPS_CTRL_config(self): """Driver base configuration """ pass # --- - async def _PZA_DRV_BPS_read_enable_value(self): + async def _PZA_DRV_BPS_CTRL_read_enable_value(self): """Must get the state value on the BPS and return it """ raise NotImplementedError("Must be implemented !") - async def _PZA_DRV_BPS_write_enable_value(self, v): + async def _PZA_DRV_BPS_CTRL_write_enable_value(self, v): """Must set *v* as the new state value on the BPS """ raise NotImplementedError("Must be implemented !") # --- - async def _PZA_DRV_BPS_read_volts_goal(self): + async def _PZA_DRV_BPS_CTRL_read_volts_goal(self): """Must get the volts goal value on the BPS and return it """ raise NotImplementedError("Must be implemented !") - async def _PZA_DRV_BPS_write_volts_goal(self, v): + async def _PZA_DRV_BPS_CTRL_write_volts_goal(self, v): """Must set *v* as the new volts goal value on the BPS """ raise NotImplementedError("Must be implemented !") - async def _PZA_DRV_BPS_volts_goal_min_max(self): + async def _PZA_DRV_BPS_CTRL_volts_goal_min_max(self): """Must return the voltage goal range of the power supply """ return {"min": 0, "max": 0 } - async def _PZA_DRV_BPS_read_volts_decimals(self): + async def _PZA_DRV_BPS_CTRL_read_volts_decimals(self): """Must return the number of decimals supported for the voltage """ raise NotImplementedError("Must be implemented !") # --- - async def _PZA_DRV_BPS_read_amps_goal(self): + async def _PZA_DRV_BPS_CTRL_read_amps_goal(self): """Must get the amps goal value on the BPS and return it """ raise NotImplementedError("Must be implemented !") - async def _PZA_DRV_BPS_write_amps_goal(self, v): + async def _PZA_DRV_BPS_CTRL_write_amps_goal(self, v): """Must set *v* as the new amps goal value on the BPS """ raise NotImplementedError("Must be implemented !") - async def _PZA_DRV_BPS_amps_goal_min_max(self): + async def _PZA_DRV_BPS_CTRL_amps_goal_min_max(self): """Must return the amps range of the power supply """ return {"min": 0, "max": 0 } - async def _PZA_DRV_BPS_read_amps_decimals(self): + async def _PZA_DRV_BPS_CTRL_read_amps_decimals(self): """Must return the number of decimals supported for the amperage """ raise NotImplementedError("Must be implemented !") @@ -171,7 +171,7 @@ async def __polling_task_att_enable(self): await asyncio.sleep(self.polling_ref["enable"]) await self._update_attributes_from_dict({ "enable": { - "value": await self._PZA_DRV_BPS_read_enable_value() + "value": await self._PZA_DRV_BPS_CTRL_read_enable_value() } }) @@ -184,7 +184,7 @@ async def __polling_task_att_volts(self): await asyncio.sleep(self.polling_ref["volts"]) await self._update_attributes_from_dict({ "volts": { - "goal": await self._PZA_DRV_BPS_read_volts_goal() + "goal": await self._PZA_DRV_BPS_CTRL_read_volts_goal() } }) @@ -197,7 +197,7 @@ async def __polling_task_att_amps(self): await asyncio.sleep(self.polling_ref["amps"]) await self._update_attributes_from_dict({ "amps": { - "goal": await self._PZA_DRV_BPS_read_amps_goal() + "goal": await self._PZA_DRV_BPS_CTRL_read_amps_goal() } }) @@ -219,8 +219,8 @@ async def __handle_cmds_set_enable(self, cmd_att): await self._prepare_update(update_obj, "enable", cmd_att, "value", [bool] - , self._PZA_DRV_BPS_write_enable_value - , self._PZA_DRV_BPS_read_enable_value) + , self._PZA_DRV_BPS_CTRL_write_enable_value + , self._PZA_DRV_BPS_CTRL_read_enable_value) await self._prepare_update(update_obj, "enable", cmd_att, "polling_cycle", [float, int] @@ -241,8 +241,8 @@ async def __handle_cmds_set_volts(self, cmd_att): await self._prepare_update(update_obj, "volts", cmd_att, "goal", [float, int] - , self._PZA_DRV_BPS_write_volts_goal - , self._PZA_DRV_BPS_read_volts_goal) + , self._PZA_DRV_BPS_CTRL_write_volts_goal + , self._PZA_DRV_BPS_CTRL_read_volts_goal) await self._prepare_update(update_obj, "volts", cmd_att, @@ -265,8 +265,8 @@ async def __handle_cmds_set_amps(self, cmd_att): await self._prepare_update(update_obj, "amps", cmd_att, "goal", [float, int] - , self._PZA_DRV_BPS_write_amps_goal - , self._PZA_DRV_BPS_read_amps_goal) + , self._PZA_DRV_BPS_CTRL_write_amps_goal + , self._PZA_DRV_BPS_CTRL_read_amps_goal) await self._prepare_update(update_obj, "amps", cmd_att, @@ -283,7 +283,7 @@ async def __att_enable_full_update(self): """ await self._update_attributes_from_dict({ "enable": { - "value": await self._PZA_DRV_BPS_read_enable_value(), + "value": await self._PZA_DRV_BPS_CTRL_read_enable_value(), "polling_cycle": 1 } }) @@ -293,13 +293,13 @@ async def __att_enable_full_update(self): async def __att_volts_full_update(self): """ """ - min_max = await self._PZA_DRV_BPS_volts_goal_min_max() + min_max = await self._PZA_DRV_BPS_CTRL_volts_goal_min_max() await self._update_attributes_from_dict({ "volts": { "min": min_max.get("min", 0), "max": min_max.get("max", 0), - "goal": await self._PZA_DRV_BPS_read_volts_goal(), - "decimals": await self._PZA_DRV_BPS_read_volts_decimals(), + "goal": await self._PZA_DRV_BPS_CTRL_read_volts_goal(), + "decimals": await self._PZA_DRV_BPS_CTRL_read_volts_decimals(), "polling_cycle": 1 } }) @@ -309,13 +309,13 @@ async def __att_volts_full_update(self): async def __att_amps_full_update(self): """ """ - min_max = await self._PZA_DRV_BPS_amps_goal_min_max() + min_max = await self._PZA_DRV_BPS_CTRL_amps_goal_min_max() await self._update_attributes_from_dict({ "amps": { "min": min_max.get("min", 0), "max": min_max.get("max", 0), - "goal": await self._PZA_DRV_BPS_read_amps_goal(), - "decimals": await self._PZA_DRV_BPS_read_amps_decimals(), + "goal": await self._PZA_DRV_BPS_CTRL_read_amps_goal(), + "decimals": await self._PZA_DRV_BPS_CTRL_read_amps_decimals(), "polling_cycle": 1 } }) diff --git a/platform/panduza_platform/meta_drivers/device.py b/platform/panduza_platform/meta_drivers/device.py deleted file mode 100644 index e69de29..0000000