Skip to content

Commit

Permalink
think about interface direct initialization inside devices
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodriguez committed Oct 19, 2023
1 parent 7fd7a07 commit 73d86c3
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 75 deletions.
56 changes: 36 additions & 20 deletions platform/panduza_platform/core/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,42 @@ def __init__(self, run_dir="/etc"):

# ---

def run(self):
"""Starting point of the platform
"""

# First go into factories initialization
try:
self.driver_factory.discover()
self.device_factory.discover()
except InitializationError as e:
self.log.critical(f"Error during platform initialization: {e}")
sys.exit(-1)

# Run the operationnal mode and measure alive time
start_time = time.time()
self.__oper_mode()
alive_time = round(time.time()-start_time, 2)
self.log.info(f"Platform alive time {alive_time}s")

# ---

def mount_device(self, device_cfg):
pass

# device.attach_pclient(client)
# self.threads[0].attach_worker(interface)


# ---

def unmount_device(self):
pass



# ---



def get_number_of_device(self):
Expand Down Expand Up @@ -157,26 +193,6 @@ def panic(self):

# ---

def run(self):
"""Starting point of the platform
"""
try:
# First go into factories initialization
self.driver_factory.discover()
self.device_factory.discover()

except InitializationError as e:
self.log.critical(f"Error during platform initialization: {e}")
sys.exit(-1)

# Check if the hunt mode is enabled
start_time = time.time()
self.__oper_mode()
alive_time = round(time.time()-start_time, 2)
self.log.info(f"Platform alive time {alive_time}s")

# ---

def load_interface(self, bench_name, device, interface_config):
"""Load a new interface
"""
Expand Down
19 changes: 15 additions & 4 deletions platform/panduza_platform/core/platform_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
from .platform_errors import InitializationError

class PlatformDevice:
"""Represent a device
It can be instanciated with empty settings to provide only the _PZA_DEV_config
"""Represent a Device
"""

def __init__(self, name=None, settings = {}) -> None:
def __init__(self, platform=None, name=None, settings = {}) -> None:
"""Constructor
It can be instanciated with empty settings to provide only the _PZA_DEV_config
"""
# Custom name of the device
self.__name = name

# Settings json provided by the user with the tree.json
self.__platform = platform

# Settings json provided by the user with the tree.json
self.__settings = settings

Expand Down Expand Up @@ -110,6 +113,14 @@ def _PZA_DEV_config(self):

# ---

@abc.abstractmethod
def _PZA_DEV_mount_interfaces(self):
"""
"""
pass

# ---

@abc.abstractmethod
def _PZA_DEV_interfaces_generator(self):
"""Generate interface definitions from device settings
Expand Down
2 changes: 1 addition & 1 deletion platform/panduza_platform/core/platform_device_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def produce_device(self, config):

# Produce the device
try:
producted_device = self.__device_templates[ref](name, config.get("settings", {}))
producted_device = self.__device_templates[ref](platform=self.__platform, name=name, settings=config.get("settings", {}))
producted_device.initialize()
return producted_device
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion platform/panduza_platform/devices/panduza/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .fake_dio_controller import DevicePanduzaFakeDioController
from .fake_bps_controller import DevicePanduzaFakeBps
from .fake_bps.fake_bps import DevicePanduzaFakeBps
from .fake_relay_controller import DevicePanduzaFakeRelayController
from .machine import DevicePanduzaMachine

Expand Down
Empty file.
61 changes: 61 additions & 0 deletions platform/panduza_platform/devices/panduza/fake_bps/fake_bps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from core.platform_device import PlatformDevice



class DevicePanduzaFakeBps(PlatformDevice):

# ---

def _PZA_DEV_config(self):
"""
"""
return {
"family": "BPS",
"model": "FakeBps",
"manufacturer": "Panduza"
}

# ---

def _PZA_DEV_mount_interfaces(self):
"""
"""
pass

# ---

def _PZA_DEV_interfaces_generator(self):
"""
"""
return {}

# number_of_channel = int( self.get_settings().get("number_of_channel", 1) )

# interfaces = []
# for chan in range(0, number_of_channel):
# interfaces.append(
# {
# "name": f":channel_{chan}:_ctrl",
# "driver": "panduza.fake.bpc"
# }
# )
# interfaces.append(
# {
# "name": f":channel_{chan}:_am",
# "driver": "panduza.fake.ammeter",
# "settings": {
# "work_with_fake_bpc": f"!//:channel_{chan}:"
# }
# }
# )
# interfaces.append(
# {
# "name": f":channel_{chan}:_vm",
# "driver": "panduza.fake.voltmeter",
# }
# )

# return interfaces



47 changes: 0 additions & 47 deletions platform/panduza_platform/devices/panduza/fake_bps_controller.py

This file was deleted.

2 changes: 0 additions & 2 deletions platform/panduza_platform/drivers/bpc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from .drv_hanmatek_hm310t_bpc import DrvHanmatekHm310tBpc
from .drv_panduza_fake_bpc import DrvPanduzaFakeBpc
from .drv_tenma_722710_bpc import DrvTenma722710Bpc

PZA_DRIVERS_LIST= [
DrvHanmatekHm310tBpc,
DrvPanduzaFakeBpc,
DrvTenma722710Bpc
]

0 comments on commit 73d86c3

Please sign in to comment.