From 44387e59c83a76f3a753d8cabe5d9913416c1f6f Mon Sep 17 00:00:00 2001 From: su530201 <olivier.kaufmann@umons.ac.be> Date: Wed, 11 Oct 2023 00:10:50 +0200 Subject: [PATCH] Improve code consistency --- dev/test_mb_2024_0_mux_2024.py | 4 ++-- ohmpi/hardware_components/mb_2023_0_X.py | 6 ++---- ohmpi/hardware_components/mb_2024_0_2.py | 4 ++-- ohmpi/hardware_components/mux_2023_0_X.py | 2 +- ohmpi/hardware_components/mux_2024_0_X.py | 2 +- ohmpi/hardware_components/pwr_batt.py | 2 +- ohmpi/hardware_components/pwr_dps5005.py | 4 +++- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/dev/test_mb_2024_0_mux_2024.py b/dev/test_mb_2024_0_mux_2024.py index 1b2270d8..aea5472e 100644 --- a/dev/test_mb_2024_0_mux_2024.py +++ b/dev/test_mb_2024_0_mux_2024.py @@ -7,9 +7,9 @@ import time import logging from ohmpi.config import HARDWARE_CONFIG -stand_alone = False # True +stand_alone = True part_of_hardware_system = False -within_ohmpi = True +within_ohmpi = False # Stand alone if stand_alone: diff --git a/ohmpi/hardware_components/mb_2023_0_X.py b/ohmpi/hardware_components/mb_2023_0_X.py index c7f03e05..43772755 100644 --- a/ohmpi/hardware_components/mb_2023_0_X.py +++ b/ohmpi/hardware_components/mb_2023_0_X.py @@ -74,7 +74,7 @@ class Tx(TxAbstract): subclass_init = True super().__init__(**kwargs) if not subclass_init: - self.exec_logger.event(f'{self.model}\ttx_init\tstart\t{datetime.datetime.utcnow()}') + self.exec_logger.event(f'{self.model}\ttx_init\tbegin\t{datetime.datetime.utcnow()}') assert isinstance(self.connection, I2C) kwargs.update({'pwr': kwargs.pop('pwr', SPECS['tx']['compatible_power_sources']['default'])}) if (kwargs['pwr'] != SPECS['tx']['compatible_power_sources']['default'] @@ -221,11 +221,9 @@ class Rx(RxAbstract): subclass_init = True super().__init__(**kwargs) if not subclass_init: - self.exec_logger.event(f'{self.model}\trx_init\tstart\t{datetime.datetime.utcnow()}') + self.exec_logger.event(f'{self.model}\trx_init\tbegin\t{datetime.datetime.utcnow()}') assert isinstance(self.connection, I2C) - self.exec_logger.event(f'{self.model}\trx_init\tbegin\t{datetime.datetime.utcnow()}') - # ADS1115 for voltage measurement (MN) self._ads_voltage_address = kwargs['ads_address'] self._adc_gain = 2/3 diff --git a/ohmpi/hardware_components/mb_2024_0_2.py b/ohmpi/hardware_components/mb_2024_0_2.py index 61472e2a..5ba2ed86 100644 --- a/ohmpi/hardware_components/mb_2024_0_2.py +++ b/ohmpi/hardware_components/mb_2024_0_2.py @@ -74,7 +74,7 @@ class Tx(Tx_mb_2023): subclass_init = True super().__init__(**kwargs) if not subclass_init: - self.exec_logger.event(f'{self.model}\ttx_init\tstart\t{datetime.datetime.utcnow()}') + self.exec_logger.event(f'{self.model}\ttx_init\tbegin\t{datetime.datetime.utcnow()}') # Initialize LEDs self.pin4 = self.mcp_board.get_pin(4) # Ohmpi_run self.pin4.direction = Direction.OUTPUT @@ -102,7 +102,7 @@ class Rx(Rx_mb_2023): subclass_init = True super().__init__(**kwargs) if not subclass_init: - self.exec_logger.event(f'{self.model}\trx_init\tstart\t{datetime.datetime.utcnow()}') + self.exec_logger.event(f'{self.model}\trx_init\tbegin\t{datetime.datetime.utcnow()}') # I2C connection to MCP23008, for voltage self.mcp_board = MCP23008(self.connection, address=kwargs['mcp_address']) # ADS1115 for voltage measurement (MN) diff --git a/ohmpi/hardware_components/mux_2023_0_X.py b/ohmpi/hardware_components/mux_2023_0_X.py index b3fd4247..140ab180 100644 --- a/ohmpi/hardware_components/mux_2023_0_X.py +++ b/ohmpi/hardware_components/mux_2023_0_X.py @@ -68,7 +68,7 @@ class Mux(MuxAbstract): kwargs.update({'cabling': kwargs.pop('cabling', default_mux_cabling)}) super().__init__(**kwargs) if not subclass_init: - self.exec_logger.event(f'{self.model}{self.board_id}\tmux_init\tstart\t{datetime.datetime.utcnow()}') + self.exec_logger.event(f'{self.model}{self.board_id}\tmux_init\tbegin\t{datetime.datetime.utcnow()}') assert isinstance(self.connection, I2C) self.exec_logger.debug(f'configuration: {kwargs}') self._roles = kwargs.pop('roles', None) diff --git a/ohmpi/hardware_components/mux_2024_0_X.py b/ohmpi/hardware_components/mux_2024_0_X.py index f6e642a9..c7cfce2c 100644 --- a/ohmpi/hardware_components/mux_2024_0_X.py +++ b/ohmpi/hardware_components/mux_2024_0_X.py @@ -66,7 +66,7 @@ class Mux(MuxAbstract): subclass_init = True super().__init__(**kwargs) if not subclass_init: - self.exec_logger.event(f'{self.model}{self.board_id}\tmux_init\tstart\t{datetime.datetime.utcnow()}') + self.exec_logger.event(f'{self.model}{self.board_id}\tmux_init\tbegin\t{datetime.datetime.utcnow()}') assert isinstance(self.connection, I2C) self.exec_logger.debug(f'configuration: {kwargs}') tca_address = kwargs.pop('tca_address', None) diff --git a/ohmpi/hardware_components/pwr_batt.py b/ohmpi/hardware_components/pwr_batt.py index 614e4fde..c949675b 100644 --- a/ohmpi/hardware_components/pwr_batt.py +++ b/ohmpi/hardware_components/pwr_batt.py @@ -5,7 +5,7 @@ import os class Pwr(PwrAbstract): def __init__(self, **kwargs): - kwargs.update({'board_name': os.path.basename(__file__).rstrip('.py')}) + kwargs.update({'model': os.path.basename(__file__).rstrip('.py')}) voltage = kwargs.pop('voltage', 12.) super().__init__(**kwargs) self.voltage_adjustable = False diff --git a/ohmpi/hardware_components/pwr_dps5005.py b/ohmpi/hardware_components/pwr_dps5005.py index 50a92e43..b1cd7180 100644 --- a/ohmpi/hardware_components/pwr_dps5005.py +++ b/ohmpi/hardware_components/pwr_dps5005.py @@ -11,6 +11,8 @@ SPECS = {'model': {'default': os.path.basename(__file__).rstrip('.py')}, 'current_max': {'default': 100.}, } +# TODO: Complete this code... handle modbus connection + class Pwr(PwrAbstract): def __init__(self, **kwargs): @@ -20,9 +22,9 @@ class Pwr(PwrAbstract): subclass_init = False else: subclass_init = True + super().__init__(**kwargs) if not subclass_init: self.exec_logger.event(f'{self.model}\tpwr_init\tstart\t{datetime.datetime.utcnow()}') - super().__init__(**kwargs) # if a controller is passed in kwargs, it will be instantiated #if self.ctl is None: # self.ctl = ctl_module.Ctl(**CTL_CONFIG) -- GitLab