From f338d93c410f11d12bb8ee3c5383b2afe3608ffc Mon Sep 17 00:00:00 2001 From: su530201 <olivier.kaufmann@umons.ac.be> Date: Tue, 28 Nov 2023 16:37:35 +0100 Subject: [PATCH] Updates config files --- configs/config_default.py | 42 +++++-- configs/config_dummy.py | 117 ------------------ configs/config_mb_2023_3_mux_2024.py | 6 +- configs/config_mb_2023_4_mux_2023.py | 88 ++++++------- configs/config_mb_2023_4_mux_2024.py | 6 +- configs/config_mb_2023__3_mux_2024_dps5005.py | 4 - configs/config_mb_2023_mux_2024_2_roles_AB.py | 4 +- configs/config_mb_2023_mux_2024_2_roles_MN.py | 51 ++++---- configs/config_mb_2024_0_0.py | 112 ----------------- configs/config_mb_2024_0_2.py | 1 - configs/config_mb_2024_0_2__1_mux_2024.py | 3 - .../config_mb_2024_0_2__1_mux_2024_dps5005.py | 3 - .../config_mb_2024_0_2__2_mux_2024_dps5005.py | 3 - .../config_mb_2024_0_2__3_mux_2024_dps5005.py | 7 +- ...024_0_2__4_mux_2023__4_mux_2024_dps5005.py | 5 - .../config_mb_2024_0_2__4_mux_2023_dps5005.py | 1 - .../config_mb_2024_0_2__4_mux_2024_dps5005.py | 7 +- .../config_mb_2024_0_2__8_mux_2023_dps5005.py | 3 +- configs/config_tmp.py | 110 ---------------- dev/test_dummy.py | 13 -- .../abstract_hardware_components.py | 4 +- ohmpi/hardware_components/dummy_ctl.py | 10 -- ohmpi/hardware_components/dummy_mux.py | 21 ---- ohmpi/hardware_components/dummy_rx.py | 40 ------ ohmpi/hardware_components/dummy_tx.py | 113 ----------------- ohmpi/hardware_components/mb_2023_0_X.py | 2 +- ohmpi/hardware_components/pwr_dps5005.py | 9 +- ohmpi/logging_setup.py | 8 +- ohmpi/utils.py | 12 +- 29 files changed, 121 insertions(+), 684 deletions(-) delete mode 100644 configs/config_dummy.py delete mode 100644 configs/config_mb_2024_0_0.py delete mode 100644 configs/config_tmp.py delete mode 100644 dev/test_dummy.py delete mode 100644 ohmpi/hardware_components/dummy_ctl.py delete mode 100644 ohmpi/hardware_components/dummy_mux.py delete mode 100644 ohmpi/hardware_components/dummy_rx.py delete mode 100644 ohmpi/hardware_components/dummy_tx.py diff --git a/configs/config_default.py b/configs/config_default.py index 0763f48c..49e24ecf 100644 --- a/configs/config_default.py +++ b/configs/config_default.py @@ -1,7 +1,7 @@ import logging from ohmpi.utils import get_platform -from paho.mqtt.client import MQTTv31 +from paho.mqtt.client import MQTTv31 # noqa _, on_pi = get_platform() # DEFINE THE ID OF YOUR OhmPi @@ -17,22 +17,38 @@ OHMPI_CONFIG = { 'settings': 'ohmpi_settings.json', # INSERT YOUR FAVORITE SETTINGS FILE HERE } +r_shunt = 2. HARDWARE_CONFIG = { - 'ctl': {'model' : 'dummy_ctl' - }, - 'tx' : {'model' : 'dummy_tx', - 'current_max': 4800 / 50 / 2, # Maximum current mA - 'r_shunt': 2, # Shunt resistance in Ohms - 'low_battery': 12. # Volts + 'ctl': {'model': 'raspberry_pi'}, + 'pwr': {'model': 'pwr_batt', 'voltage': 12., 'interface_name': 'none'}, + 'tx': {'model': 'mb_2024_0_2', + 'voltage_max': 50., # Maximum voltage supported by the TX board [V] + 'current_max': 4.80/(50*r_shunt), # Maximum voltage read by the current ADC on the TX board [A] + 'r_shunt': r_shunt, # Shunt resistance in Ohms + 'interface_name': 'i2c' }, - 'rx' : {'model': 'dummy_rx', + 'rx': {'model': 'mb_2024_0_2', + 'latency': 0.010, # latency in seconds in continuous mode + 'sampling_rate': 50, # number of samples per second + 'interface_name': 'i2c' }, - 'mux': {'model' : 'dummy_mux', - 'max_elec': 64, - 'voltage_max' : 100, - 'current_max' : 3 + 'mux': {'boards': + {'mux_00': + {'model': 'mux_2024_0_X', + 'tca_address': None, + 'tca_channel': 0, + 'addr2': 'down', + 'addr1': 'down', + 'roles': {'A': 'X', 'B': 'Y', 'M': 'XX', 'N': 'YY'}, + 'cabling': {(i+0, j): ('mux_00', i) for j in ['A', 'B', 'M', 'N'] for i in range(1, 9)}, + 'voltage_max': 12.} + }, + 'default': {'interface_name': 'i2c_ext', + 'voltage_max': 100., + 'current_max': 3.} } -} + } + # SET THE LOGGING LEVELS, MQTT BROKERS AND MQTT OPTIONS ACCORDING TO YOUR NEEDS # Execution logging configuration EXEC_LOGGING_CONFIG = { diff --git a/configs/config_dummy.py b/configs/config_dummy.py deleted file mode 100644 index 1d2fc9f4..00000000 --- a/configs/config_dummy.py +++ /dev/null @@ -1,117 +0,0 @@ -import logging -from ohmpi.utils import get_platform - -from paho.mqtt.client import MQTTv31 - -_, on_pi = get_platform() -# DEFINE THE ID OF YOUR OhmPi -ohmpi_id = '0001' if on_pi else 'XXXX' -# DEFINE YOUR MQTT BROKER (DEFAULT: 'localhost') -mqtt_broker = 'localhost' if on_pi else 'NAME_YOUR_BROKER_WHEN_IN_SIMULATION_MODE_HERE' -# DEFINE THE SUFFIX TO ADD TO YOUR LOGS FILES -logging_suffix = '' - -# OhmPi configuration -OHMPI_CONFIG = { - 'id': ohmpi_id, # Unique identifier of the OhmPi board (string) - # 'R_shunt': 2, # Shunt resistance in Ohms - # 'Imax': 4800 / 50 / 2, # Maximum current - # 'coef_p2': 2.50, # slope for current conversion for ADS.P2, measurement in V/V - # 'nb_samples': 20, # Max value 10 # was named integer before... - # 'version': 2, # Is this still needed? - # 'max_elec': 64, - # 'board_addresses': {'A': 0x73, 'B': 0x72, 'M': 0x71, 'N': 0x70}, # CHECK IF YOUR BOARDS HAVE THESE ADDRESSES - 'settings': 'ohmpi_settings.json', # INSERT YOUR FAVORITE SETTINGS FILE HERE - # 'board_version': 'mb.2023.0.0',#,'22.10', - # 'mcp_board_address': 0x20 -} # TODO: add a dictionary with INA models and associated gain values - -HARDWARE_CONFIG = { - 'ctl': {'model' : 'dummy_ctl' - }, - 'pwr' : {'model': 'dummy_pwr'}, - 'tx' : {'model' : 'dummy_tx', - 'current_max': 4800 / 50 / 2, # Maximum current - 'R_shunt': 2 # Shunt resistance in Ohms - }, - 'rx' : {'model': 'dummy_rx', - }, - 'mux': {'model' : 'dummy_mux', - 'max_elec': 64, - 'voltage_max' : 100, - 'current_max' : 3 - } -} - -# SET THE LOGGING LEVELS, MQTT BROKERS AND MQTT OPTIONS ACCORDING TO YOUR NEEDS -# Execution logging configuration -EXEC_LOGGING_CONFIG = { - 'logging_level': logging.INFO, - 'log_file_logging_level': logging.DEBUG, - 'logging_to_console': True, - 'file_name': f'exec{logging_suffix}.log', - 'max_bytes': 262144, - 'backup_count': 30, - 'when': 'd', - 'interval': 1 -} - -# Data logging configuration -DATA_LOGGING_CONFIG = { - 'logging_level': logging.INFO, - 'logging_to_console': True, - 'file_name': f'data{logging_suffix}.log', - 'max_bytes': 16777216, - 'backup_count': 1024, - 'when': 'd', - 'interval': 1 -} - -# State of Health logging configuration (For a future release) -SOH_LOGGING_CONFIG = { - 'logging_level': logging.INFO, - 'log_file_logging_level': logging.DEBUG, - 'logging_to_console': True, - 'file_name': f'soh{logging_suffix}.log', - 'max_bytes': 16777216, - 'backup_count': 1024, - 'when': 'd', - 'interval': 1 -} - -# MQTT logging configuration parameters -MQTT_LOGGING_CONFIG = { - 'hostname': mqtt_broker, - 'port': 1883, - 'qos': 2, - 'retain': False, - 'keepalive': 60, - 'will': None, - 'auth': {'username': 'mqtt_user', 'password': 'mqtt_password'}, - 'tls': None, - 'protocol': MQTTv31, - 'transport': 'tcp', - 'client_id': f'{OHMPI_CONFIG["id"]}', - 'exec_topic': f'ohmpi_{OHMPI_CONFIG["id"]}/exec', - 'exec_logging_level': logging.DEBUG, - 'data_topic': f'ohmpi_{OHMPI_CONFIG["id"]}/data', - 'data_logging_level': DATA_LOGGING_CONFIG['logging_level'], - 'soh_topic': f'ohmpi_{OHMPI_CONFIG["id"]}/soh', - 'soh_logging_level': SOH_LOGGING_CONFIG['logging_level'] -} - -# MQTT control configuration parameters -MQTT_CONTROL_CONFIG = { - 'hostname': mqtt_broker, - 'port': 1883, - 'qos': 2, - 'retain': False, - 'keepalive': 60, - 'will': None, - 'auth': {'username': 'mqtt_user', 'password': 'mqtt_password'}, - 'tls': None, - 'protocol': MQTTv31, - 'transport': 'tcp', - 'client_id': f'{OHMPI_CONFIG["id"]}', - 'ctrl_topic': f'ohmpi_{OHMPI_CONFIG["id"]}/ctrl' -} diff --git a/configs/config_mb_2023_3_mux_2024.py b/configs/config_mb_2023_3_mux_2024.py index 8373edcb..d8adeb5d 100644 --- a/configs/config_mb_2023_3_mux_2024.py +++ b/configs/config_mb_2023_3_mux_2024.py @@ -1,7 +1,7 @@ import logging from ohmpi.utils import get_platform -from paho.mqtt.client import MQTTv31 +from paho.mqtt.client import MQTTv31 # noqa _, on_pi = get_platform() # DEFINE THE ID OF YOUR OhmPi @@ -43,8 +43,6 @@ HARDWARE_CONFIG = { 'tca_channel': 0, 'addr2': 'up', 'addr1': 'up', - # 'mcp_0': '0x26', - # 'mcp_1': '0x27', 'roles': {'A': 'X', 'B': 'Y', 'M': 'XX', 'N': 'YY'}, 'cabling': {(i + 8, j): ('mux_02', i) for j in ['A', 'B', 'M', 'N'] for i in range(1, 9)}, 'voltage_max': 50.}, @@ -54,8 +52,6 @@ HARDWARE_CONFIG = { 'tca_channel': 0, 'addr2': 'down', 'addr1': 'up', - # 'mcp_0': '0x26', - # 'mcp_1': '0x27', 'roles': {'A': 'X', 'B': 'Y', 'M': 'XX', 'N': 'YY'}, 'cabling': {(i + 16, j): ('mux_03', i) for j in ['A', 'B', 'M', 'N'] for i in range(1, 9)}, 'voltage_max': 50.}, diff --git a/configs/config_mb_2023_4_mux_2023.py b/configs/config_mb_2023_4_mux_2023.py index 40665972..54dd5b25 100644 --- a/configs/config_mb_2023_4_mux_2023.py +++ b/configs/config_mb_2023_4_mux_2023.py @@ -21,51 +21,51 @@ r_shunt = 2. HARDWARE_CONFIG = { 'ctl': {'model': 'raspberry_pi'}, 'pwr': {'model': 'pwr_batt', 'voltage': 12., 'interface_name': 'none'}, - 'tx': {'model': 'mb_2023_0_X', - 'voltage_max': 50., # Maximum voltage supported by the TX board [V] - 'current_max': 4.80/(50*r_shunt), # Maximum voltage read by the current ADC on the TX board [A] - 'r_shunt': r_shunt, # Shunt resistance in Ohms - 'interface_name': 'i2c' - }, - 'rx': {'model': 'mb_2023_0_X', - 'coef_p2': 2.50, # slope for conversion for ADS, measurement in V/V - 'sampling_rate': 50., # number of samples per second - 'interface_name': 'i2c', - }, + 'tx': {'model': 'mb_2023_0_X', + 'voltage_max': 50., # Maximum voltage supported by the TX board [V] + 'current_max': 4.80 / (50 * r_shunt), # Maximum voltage read by the current ADC on the TX board [A] + 'r_shunt': r_shunt, # Shunt resistance in Ohms + 'interface_name': 'i2c' + }, + 'rx': {'model': 'mb_2023_0_X', + 'coef_p2': 2.50, # slope for conversion for ADS, measurement in V/V + 'sampling_rate': 50., # number of samples per second + 'interface_name': 'i2c', + }, 'mux': # default properties given in config are system properties that will be - # overwritten by properties defined in each the board dict below. - # if defined in board specs, values out of specs will be bounded to remain in specs - # omitted properties in config will be set to board specs default values if they exist - {'boards': - {'mux_A': - {'model': 'mux_2023_0_X', - 'mux_tca_address': 0x70, - 'roles': {'A': 'X'}, - 'cabling': {(i, j): ('mux_A', i) for j in ['A'] for i in range(1, 65)}, - 'voltage_max': 12.}, - 'mux_B': - {'model': 'mux_2023_0_X', - 'mux_tca_address': 0x71, - 'roles': {'B': 'X'}, - 'cabling': {(i, j): ('mux_B', i) for j in ['B'] for i in range(1, 65)}, - 'voltage_max': 12.}, - 'mux_M': - {'model': 'mux_2023_0_X', - 'mux_tca_address': 0x72, - 'roles': {'M': 'X'}, - 'cabling': {(i, j): ('mux_M', i) for j in ['M'] for i in range(1, 65)}, - 'voltage_max': 12.}, - 'mux_N': - {'model': 'mux_2023_0_X', - 'mux_tca_address': 0x73, - 'roles': {'N': 'X'}, - 'cabling': {(i, j): ('mux_N', i) for j in ['N'] for i in range(1, 65)}, - 'voltage_max': 12.}, - }, - 'default': {'interface_name': 'i2c', - 'voltage_max': 12., - 'current_max': 3.} - } + # overwritten by properties defined in each the board dict below. + # if defined in board specs, values out of specs will be bounded to remain in specs + # omitted properties in config will be set to board specs default values if they exist + {'boards': + {'mux_A': + {'model': 'mux_2023_0_X', + 'mux_tca_address': 0x70, + 'roles': {'A': 'X'}, + 'cabling': {(i, j): ('mux_A', i) for j in ['A'] for i in range(1, 65)}, + 'voltage_max': 12.}, + 'mux_B': + {'model': 'mux_2023_0_X', + 'mux_tca_address': 0x71, + 'roles': {'B': 'X'}, + 'cabling': {(i, j): ('mux_B', i) for j in ['B'] for i in range(1, 65)}, + 'voltage_max': 12.}, + 'mux_M': + {'model': 'mux_2023_0_X', + 'mux_tca_address': 0x72, + 'roles': {'M': 'X'}, + 'cabling': {(i, j): ('mux_M', i) for j in ['M'] for i in range(1, 65)}, + 'voltage_max': 12.}, + 'mux_N': + {'model': 'mux_2023_0_X', + 'mux_tca_address': 0x73, + 'roles': {'N': 'X'}, + 'cabling': {(i, j): ('mux_N', i) for j in ['N'] for i in range(1, 65)}, + 'voltage_max': 12.}, + }, + 'default': {'interface_name': 'i2c', + 'voltage_max': 12., + 'current_max': 3.} + } } # SET THE LOGGING LEVELS, MQTT BROKERS AND MQTT OPTIONS ACCORDING TO YOUR NEEDS diff --git a/configs/config_mb_2023_4_mux_2024.py b/configs/config_mb_2023_4_mux_2024.py index f15f2af3..9f143bd8 100644 --- a/configs/config_mb_2023_4_mux_2024.py +++ b/configs/config_mb_2023_4_mux_2024.py @@ -38,19 +38,15 @@ HARDWARE_CONFIG = { 'tca_channel': 0, 'addr2': 'up', 'addr1': 'up', - # 'mcp_0': '0x26', - # 'mcp_1': '0x27', 'roles': {'A': 'X', 'B': 'Y', 'M': 'XX', 'N': 'YY'}, 'cabling': {(i+8, j): ('mux_02', i) for j in ['A', 'B', 'M', 'N'] for i in range(1, 9)}, 'voltage_max': 12.}, - 'mux_03': + 'mux_03': {'model': 'mux_2024_0_X', 'tca_address': None, 'tca_channel': 0, 'addr2': 'down', 'addr1': 'up', - # 'mcp_0': '0x26', - # 'mcp_1': '0x27', 'roles': {'A': 'X', 'B': 'Y', 'M': 'XX', 'N': 'YY'}, 'cabling': {(i+24, j): ('mux_03', i) for j in ['A', 'B', 'M', 'N'] for i in range(1, 9)}, 'voltage_max': 12.}, diff --git a/configs/config_mb_2023__3_mux_2024_dps5005.py b/configs/config_mb_2023__3_mux_2024_dps5005.py index b4d7d2cc..b94f2f04 100644 --- a/configs/config_mb_2023__3_mux_2024_dps5005.py +++ b/configs/config_mb_2023__3_mux_2024_dps5005.py @@ -42,8 +42,6 @@ HARDWARE_CONFIG = { 'tca_channel': 0, 'addr2': 'up', 'addr1': 'up', - # 'mcp_0': '0x26', - # 'mcp_1': '0x27', 'roles': {'A': 'X', 'B': 'Y', 'M': 'XX', 'N': 'YY'}, 'cabling': {(i+8, j): ('mux_02', i) for j in ['A', 'B', 'M', 'N'] for i in range(1, 9)}, 'voltage_max': 50.}, @@ -53,8 +51,6 @@ HARDWARE_CONFIG = { 'tca_channel': 0, 'addr2': 'down', 'addr1': 'up', - # 'mcp_0': '0x26', - # 'mcp_1': '0x27', 'roles': {'A': 'X', 'B': 'Y', 'M': 'XX', 'N': 'YY'}, 'cabling': {(i+16, j): ('mux_03', i) for j in ['A', 'B', 'M', 'N'] for i in range(1, 9)}, 'voltage_max': 50.}, diff --git a/configs/config_mb_2023_mux_2024_2_roles_AB.py b/configs/config_mb_2023_mux_2024_2_roles_AB.py index 42fe5c13..0ad83138 100644 --- a/configs/config_mb_2023_mux_2024_2_roles_AB.py +++ b/configs/config_mb_2023_mux_2024_2_roles_AB.py @@ -39,8 +39,8 @@ HARDWARE_CONFIG = { {'model': 'mux_2024_0_X', # 'ohmpi_i2c_mux64_v1.01', 'tca_address': None, 'tca_channel': 0, - 'mcp_0': '0x22', # TODO : Replace this with pos of jumper on MUX board (address doesn't mean anything for the average user... - 'mcp_1': '0x23', # TODO : Replace this with pos of jumper on MUX board (address doesn't mean anything for the average user...) + 'addr2': 'up', + 'addr1': 'up', 'roles': {'A': 'X', 'B': 'Y'}, 'voltage_max': 12. }}, diff --git a/configs/config_mb_2023_mux_2024_2_roles_MN.py b/configs/config_mb_2023_mux_2024_2_roles_MN.py index 6b911300..f957adfd 100644 --- a/configs/config_mb_2023_mux_2024_2_roles_MN.py +++ b/configs/config_mb_2023_mux_2024_2_roles_MN.py @@ -18,33 +18,34 @@ OHMPI_CONFIG = { } HARDWARE_CONFIG = { - 'ctl': {'model' : 'raspberry_pi'}, - 'pwr': {'model' : 'pwr_batt', 'voltage': 12.}, - 'tx' : {'model' : 'mb_2023_0_X', - 'mcp_board_address': 0x20, - 'voltage_max': 12., # Maximum voltage supported by the TX board [V] - 'current_max': 4800 / 50 / 2, # Maximum current supported by the TX board [mA] - 'r_shunt': 2 # Shunt resistance in Ohms - }, - 'rx' : {'model': 'mb_2023_0_X', - 'coef_p2': 2.50, # slope for current conversion for ADS.P2, measurement in V/V - 'sampling_rate': 100., # Hz - 'nb_samples': 20, # Max value 10 # was named integer before... - }, + 'ctl': {'model': 'raspberry_pi'}, + 'pwr': {'model': 'pwr_batt', 'voltage': 12.}, + 'tx': {'model': 'mb_2023_0_X', + 'mcp_board_address': 0x20, + 'voltage_max': 12., # Maximum voltage supported by the TX board [V] + 'current_max': 4800 / 50 / 2, # Maximum current supported by the TX board [mA] + 'r_shunt': 2 # Shunt resistance in Ohms + }, + 'rx': {'model': 'mb_2023_0_X', + 'coef_p2': 2.50, # slope for current conversion for ADS.P2, measurement in V/V + 'sampling_rate': 100., # Hz + 'nb_samples': 20, # Max value 10 # was named integer before... + }, 'mux': # default properties are system properties that will be - # overwritten by board properties defined at the board level within the board model file - # both will be overwritten by properties specified in the board dict below. Use with caution... + # overwritten by board properties defined at the board level within the board model file + # both will be overwritten by properties specified in the board dict below. Use with caution... {'boards': - {'mux_1': - {'model' : 'mux_2024_0_X', # 'ohmpi_i2c_mux64_v1.01', - 'tca_address': None, - 'tca_channel': 0, - 'mcp_0': '0x22', # TODO : Replace this with pos of jumper on MUX board (address doesn't mean anything for the average user... - 'mcp_1': '0x23', # TODO : Replace this with pos of jumper on MUX board (address doesn't mean anything for the average user...) - 'roles': {'M': 'X', 'N': 'Y'}, - 'voltage_max': 12. - }}, - 'default': {'voltage_max': 100., 'current_max': 3.}} + {'mux_1': + {'model': 'mux_2024_0_X', # 'ohmpi_i2c_mux64_v1.01', + 'tca_address': None, + 'tca_channel': 0, + 'addr2': 'up', + 'addr1': 'up', + 'roles': {'M': 'X', 'N': 'Y'}, + 'voltage_max': 12. + } + }, + 'default': {'voltage_max': 100., 'current_max': 3.}} } # SET THE LOGGING LEVELS, MQTT BROKERS AND MQTT OPTIONS ACCORDING TO YOUR NEEDS diff --git a/configs/config_mb_2024_0_0.py b/configs/config_mb_2024_0_0.py deleted file mode 100644 index 4df5c696..00000000 --- a/configs/config_mb_2024_0_0.py +++ /dev/null @@ -1,112 +0,0 @@ -import logging -from ohmpi.utils import get_platform - -from paho.mqtt.client import MQTTv31 - -_, on_pi = get_platform() -# DEFINE THE ID OF YOUR OhmPi -ohmpi_id = '0001' if on_pi else 'XXXX' -# DEFINE YOUR MQTT BROKER (DEFAULT: 'localhost') -mqtt_broker = 'localhost' if on_pi else 'NAME_YOUR_BROKER_WHEN_IN_SIMULATION_MODE_HERE' -# DEFINE THE SUFFIX TO ADD TO YOUR LOGS FILES -logging_suffix = '' - -# OhmPi configuration -OHMPI_CONFIG = { - 'id': ohmpi_id, # Unique identifier of the OhmPi board (string) - 'settings': 'ohmpi_settings.json', # INSERT YOUR FAVORITE SETTINGS FILE HERE -} - -HARDWARE_CONFIG = { - 'ctl': {'model' : 'raspberry_pi'}, - 'pwr': {'model' : 'DPS_5005', - 'voltage_adjustable': True}, - 'tx' : {'model' : 'mb_2024_rev_0_0', - 'mcp_board_address': 0x20, - 'current_max': 4800 / 50 / 2, # Maximum current - 'r_shunt': 2 # Shunt resistance in Ohms - }, - 'rx' : {'model': 'mb_2024_rev_0_0', - 'coef_p2': 2.50, # slope for current conversion for ADS.P2, measurement in V/V - 'nb_samples': 20, # Max value 10 # was named integer before... - }, - 'mux': {'model' : 'ohmpi_i2c_mux64_v1.01', - 'max_elec': 64, - 'board_addresses': {'A': 0x73, 'B': 0x72, 'M': 0x71, 'N': 0x70}, # CHECK IF YOUR BOARDS HAVE THESE ADDRESSES - 'voltage_max': 100, - 'current_max': 3 - } -} - -# SET THE LOGGING LEVELS, MQTT BROKERS AND MQTT OPTIONS ACCORDING TO YOUR NEEDS -# Execution logging configuration -EXEC_LOGGING_CONFIG = { - 'logging_level': logging.INFO, - 'log_file_logging_level': logging.DEBUG, - 'logging_to_console': True, - 'file_name': f'exec{logging_suffix}.log', - 'max_bytes': 262144, - 'backup_count': 30, - 'when': 'd', - 'interval': 1 -} - -# Data logging configuration -DATA_LOGGING_CONFIG = { - 'logging_level': logging.INFO, - 'logging_to_console': True, - 'file_name': f'data{logging_suffix}.log', - 'max_bytes': 16777216, - 'backup_count': 1024, - 'when': 'd', - 'interval': 1 -} - -# State of Health logging configuration (For a future release) -SOH_LOGGING_CONFIG = { - 'logging_level': logging.INFO, - 'logging_to_console': True, - 'log_file_logging_level': logging.DEBUG, - 'file_name': f'soh{logging_suffix}.log', - 'max_bytes': 16777216, - 'backup_count': 1024, - 'when': 'd', - 'interval': 1 -} - -# MQTT logging configuration parameters -MQTT_LOGGING_CONFIG = { - 'hostname': mqtt_broker, - 'port': 1883, - 'qos': 2, - 'retain': False, - 'keepalive': 60, - 'will': None, - 'auth': {'username': 'mqtt_user', 'password': 'mqtt_password'}, - 'tls': None, - 'protocol': MQTTv31, - 'transport': 'tcp', - 'client_id': f'{OHMPI_CONFIG["id"]}', - 'exec_topic': f'ohmpi_{OHMPI_CONFIG["id"]}/exec', - 'exec_logging_level': logging.DEBUG, - 'data_topic': f'ohmpi_{OHMPI_CONFIG["id"]}/data', - 'data_logging_level': DATA_LOGGING_CONFIG['logging_level'], - 'soh_topic': f'ohmpi_{OHMPI_CONFIG["id"]}/soh', - 'soh_logging_level': SOH_LOGGING_CONFIG['logging_level'] -} - -# MQTT control configuration parameters -MQTT_CONTROL_CONFIG = { - 'hostname': mqtt_broker, - 'port': 1883, - 'qos': 2, - 'retain': False, - 'keepalive': 60, - 'will': None, - 'auth': {'username': 'mqtt_user', 'password': 'mqtt_password'}, - 'tls': None, - 'protocol': MQTTv31, - 'transport': 'tcp', - 'client_id': f'{OHMPI_CONFIG["id"]}', - 'ctrl_topic': f'ohmpi_{OHMPI_CONFIG["id"]}/ctrl' -} diff --git a/configs/config_mb_2024_0_2.py b/configs/config_mb_2024_0_2.py index c73ecf41..e0516838 100644 --- a/configs/config_mb_2024_0_2.py +++ b/configs/config_mb_2024_0_2.py @@ -27,7 +27,6 @@ HARDWARE_CONFIG = { 'interface_name': 'i2c' }, 'rx': {'model': 'mb_2024_0_2', - 'coef_p2': 1.00, # slope for conversion for ADS, measurement in V/V 'latency': 0.010, # latency in seconds in continuous mode 'sampling_rate': 50, # number of samples per second 'interface_name': 'i2c' diff --git a/configs/config_mb_2024_0_2__1_mux_2024.py b/configs/config_mb_2024_0_2__1_mux_2024.py index ecc683c7..62274c84 100644 --- a/configs/config_mb_2024_0_2__1_mux_2024.py +++ b/configs/config_mb_2024_0_2__1_mux_2024.py @@ -27,7 +27,6 @@ HARDWARE_CONFIG = { 'interface_name': 'i2c' }, 'rx': {'model': 'mb_2024_0_2', - 'coef_p2': 1.00, # slope for conversion for ADS, measurement in V/V 'latency': 0.010, # latency in seconds in continuous mode 'sampling_rate': 50, # number of samples per second 'interface_name': 'i2c' @@ -39,8 +38,6 @@ HARDWARE_CONFIG = { 'tca_channel': 0, 'addr2': 'down', 'addr1': 'down', - # 'mcp_0': '0x26', - # 'mcp_1': '0x27', 'roles': {'A': 'X', 'B': 'Y', 'M': 'XX', 'N': 'YY'}, 'cabling': {(i+0, j): ('mux_03', i) for j in ['A', 'B', 'M', 'N'] for i in range(1, 9)}, 'voltage_max': 12.} diff --git a/configs/config_mb_2024_0_2__1_mux_2024_dps5005.py b/configs/config_mb_2024_0_2__1_mux_2024_dps5005.py index 60f5bfc0..f15eec54 100644 --- a/configs/config_mb_2024_0_2__1_mux_2024_dps5005.py +++ b/configs/config_mb_2024_0_2__1_mux_2024_dps5005.py @@ -27,7 +27,6 @@ HARDWARE_CONFIG = { 'interface_name': 'i2c' }, 'rx': {'model': 'mb_2024_0_2', - 'coef_p2': 1.00, # slope for conversion for ADS, measurement in V/V 'latency': 0.010, # latency in seconds in continuous mode 'sampling_rate': 50, # number of samples per second 'interface_name': 'i2c' @@ -39,8 +38,6 @@ HARDWARE_CONFIG = { 'tca_channel': 0, 'addr2': 'down', 'addr1': 'down', - # 'mcp_0': '0x26', - # 'mcp_1': '0x27', 'roles': {'A': 'X', 'B': 'Y', 'M': 'XX', 'N': 'YY'}, 'cabling': {(i+0, j): ('mux_03', i) for j in ['A', 'B', 'M', 'N'] for i in range(1, 9)}, 'voltage_max': 12.} diff --git a/configs/config_mb_2024_0_2__2_mux_2024_dps5005.py b/configs/config_mb_2024_0_2__2_mux_2024_dps5005.py index a0f08b79..222888d7 100644 --- a/configs/config_mb_2024_0_2__2_mux_2024_dps5005.py +++ b/configs/config_mb_2024_0_2__2_mux_2024_dps5005.py @@ -27,7 +27,6 @@ HARDWARE_CONFIG = { 'interface_name': 'i2c' }, 'rx': {'model': 'mb_2024_0_2', - 'coef_p2': 1.00, # slope for conversion for ADS, measurement in V/V 'latency': 0.010, # latency in seconds in continuous mode 'sampling_rate': 50, # number of samples per second 'interface_name': 'i2c' @@ -39,8 +38,6 @@ HARDWARE_CONFIG = { 'tca_channel': 0, 'addr2': 'up', 'addr1': 'up', - # 'mcp_0': '0x26', - # 'mcp_1': '0x27', 'roles': {'A': 'X', 'B': 'Y', 'M': 'XX', 'N': 'YY'}, 'cabling': {(i+0, j): ('mux_02', i) for j in ['A', 'B', 'M', 'N'] for i in range(1, 9)}, 'voltage_max': 12.}, diff --git a/configs/config_mb_2024_0_2__3_mux_2024_dps5005.py b/configs/config_mb_2024_0_2__3_mux_2024_dps5005.py index 8fa5f242..92f98a30 100644 --- a/configs/config_mb_2024_0_2__3_mux_2024_dps5005.py +++ b/configs/config_mb_2024_0_2__3_mux_2024_dps5005.py @@ -27,7 +27,6 @@ HARDWARE_CONFIG = { 'interface_name': 'i2c' }, 'rx': {'model': 'mb_2024_0_2', - 'coef_p2': 1.00, # slope for conversion for ADS, measurement in V/V 'latency': 0.010, # latency in seconds in continuous mode 'sampling_rate': 50, # number of samples per second 'interface_name': 'i2c' @@ -39,19 +38,15 @@ HARDWARE_CONFIG = { 'tca_channel': 0, 'addr2': 'up', 'addr1': 'up', - # 'mcp_0': '0x26', - # 'mcp_1': '0x27', 'roles': {'A': 'X', 'B': 'Y', 'M': 'XX', 'N': 'YY'}, 'cabling': {(i+8, j): ('mux_02', i) for j in ['A', 'B', 'M', 'N'] for i in range(1, 9)}, 'voltage_max': 50.}, - 'mux_03': + 'mux_03': {'model': 'mux_2024_0_X', 'tca_address': None, 'tca_channel': 0, 'addr2': 'down', 'addr1': 'up', - # 'mcp_0': '0x26', - # 'mcp_1': '0x27', 'roles': {'A': 'X', 'B': 'Y', 'M': 'XX', 'N': 'YY'}, 'cabling': {(i+16, j): ('mux_03', i) for j in ['A', 'B', 'M', 'N'] for i in range(1, 9)}, 'voltage_max': 50.}, diff --git a/configs/config_mb_2024_0_2__4_mux_2023__4_mux_2024_dps5005.py b/configs/config_mb_2024_0_2__4_mux_2023__4_mux_2024_dps5005.py index 103f537e..ff6fdaa1 100644 --- a/configs/config_mb_2024_0_2__4_mux_2023__4_mux_2024_dps5005.py +++ b/configs/config_mb_2024_0_2__4_mux_2023__4_mux_2024_dps5005.py @@ -27,7 +27,6 @@ HARDWARE_CONFIG = { 'interface_name': 'i2c' }, 'rx': {'model': 'mb_2024_0_2', - 'coef_p2': 1.00, # slope for conversion for ADS, measurement in V/V 'latency': 0.010, # latency in seconds in continuous mode 'sampling_rate': 50, # number of samples per second 'interface_name': 'i2c' @@ -67,8 +66,6 @@ HARDWARE_CONFIG = { 'tca_channel': 0, 'addr2': 'up', 'addr1': 'up', - # 'mcp_0': '0x26', - # 'mcp_1': '0x27', 'roles': {'A': 'X', 'B': 'Y', 'M': 'XX', 'N': 'YY'}, 'cabling': {(i+65+8, j): ('mux_02', i) for j in ['A', 'B', 'M', 'N'] for i in range(1, 9)}, 'voltage_max': 12.}, @@ -78,8 +75,6 @@ HARDWARE_CONFIG = { 'tca_channel': 0, 'addr2': 'down', 'addr1': 'up', - # 'mcp_0': '0x26', - # 'mcp_1': '0x27', 'roles': {'A': 'X', 'B': 'Y', 'M': 'XX', 'N': 'YY'}, 'cabling': {(i+65+24, j): ('mux_03', i) for j in ['A', 'B', 'M', 'N'] for i in range(1, 9)}, 'voltage_max': 12.}, diff --git a/configs/config_mb_2024_0_2__4_mux_2023_dps5005.py b/configs/config_mb_2024_0_2__4_mux_2023_dps5005.py index abba800a..d4cad9f9 100644 --- a/configs/config_mb_2024_0_2__4_mux_2023_dps5005.py +++ b/configs/config_mb_2024_0_2__4_mux_2023_dps5005.py @@ -27,7 +27,6 @@ HARDWARE_CONFIG = { 'interface_name': 'i2c' }, 'rx': {'model': 'mb_2024_0_2', - 'coef_p2': 1.00, # slope for conversion for ADS, measurement in V/V 'latency': 0.010, # latency in seconds in continuous mode 'sampling_rate': 50, # number of samples per second 'interface_name': 'i2c' diff --git a/configs/config_mb_2024_0_2__4_mux_2024_dps5005.py b/configs/config_mb_2024_0_2__4_mux_2024_dps5005.py index 07b11fd5..7a95a19e 100644 --- a/configs/config_mb_2024_0_2__4_mux_2024_dps5005.py +++ b/configs/config_mb_2024_0_2__4_mux_2024_dps5005.py @@ -27,7 +27,6 @@ HARDWARE_CONFIG = { 'vmn_hardware_offset': 2501. }, 'rx': {'model': 'mb_2024_0_2', - 'coef_p2': 1.00, # slope for conversion for ADS, measurement in V/V 'latency': 0.010, # latency in seconds in continuous mode 'sampling_rate': 50, # number of samples per second 'interface_name': 'i2c' @@ -39,19 +38,15 @@ HARDWARE_CONFIG = { 'tca_channel': 0, 'addr2': 'up', 'addr1': 'up', - # 'mcp_0': '0x26', - # 'mcp_1': '0x27', 'roles': {'A': 'X', 'B': 'Y', 'M': 'XX', 'N': 'YY'}, 'cabling': {(i+8, j): ('mux_02', i) for j in ['A', 'B', 'M', 'N'] for i in range(1, 9)}, 'voltage_max': 50.}, - 'mux_03': + 'mux_03': {'model': 'mux_2024_0_X', 'tca_address': None, 'tca_channel': 0, 'addr2': 'down', 'addr1': 'up', - # 'mcp_0': '0x26', - # 'mcp_1': '0x27', 'roles': {'A': 'X', 'B': 'Y', 'M': 'XX', 'N': 'YY'}, 'cabling': {(i+24, j): ('mux_03', i) for j in ['A', 'B', 'M', 'N'] for i in range(1, 9)}, 'voltage_max': 50.}, diff --git a/configs/config_mb_2024_0_2__8_mux_2023_dps5005.py b/configs/config_mb_2024_0_2__8_mux_2023_dps5005.py index c88c3bcd..7e05a44b 100644 --- a/configs/config_mb_2024_0_2__8_mux_2023_dps5005.py +++ b/configs/config_mb_2024_0_2__8_mux_2023_dps5005.py @@ -27,7 +27,6 @@ HARDWARE_CONFIG = { 'interface_name': 'i2c' }, 'rx': {'model': 'mb_2024_0_2', - 'coef_p2': 1.00, # slope for conversion for ADS, measurement in V/V 'latency': 0.010, # latency in seconds in continuous mode 'sampling_rate': 50, # number of samples per second 'interface_name': 'i2c' @@ -57,7 +56,7 @@ HARDWARE_CONFIG = { 'roles': {'N': 'X'}, 'cabling': {(i, j): ('mux_N', i) for j in ['N'] for i in range(1, 65)}, 'voltage_max': 12.}, - 'mux_A2': + 'mux_A2': {'model': 'mux_2023_0_X', 'mux_tca_address': 0x74, 'roles': {'A': 'X'}, diff --git a/configs/config_tmp.py b/configs/config_tmp.py deleted file mode 100644 index 26c4c561..00000000 --- a/configs/config_tmp.py +++ /dev/null @@ -1,110 +0,0 @@ -import logging -from ohmpi.utils import get_platform - -from paho.mqtt.client import MQTTv31 - -_, on_pi = get_platform() -# DEFINE THE ID OF YOUR OhmPi -ohmpi_id = '0001' if on_pi else 'XXXX' -# DEFINE YOUR MQTT BROKER (DEFAULT: 'localhost') -mqtt_broker = 'localhost' if on_pi else 'NAME_YOUR_BROKER_WHEN_IN_SIMULATION_MODE_HERE' -# DEFINE THE SUFFIX TO ADD TO YOUR LOGS FILES -logging_suffix = '' - -# OhmPi configuration -OHMPI_CONFIG = { - 'id': ohmpi_id, # Unique identifier of the OhmPi board (string) - 'settings': 'ohmpi_settings.json', # INSERT YOUR FAVORITE SETTINGS FILE HERE -} - -HARDWARE_CONFIG = { - 'ctl': {'model' : 'raspberry_pi'}, - 'tx' : {'model' : 'mb_2023_0_X', - 'mcp_board_address': 0x20, - 'current_max': 4800 / 50 / 2, # Maximum current - 'r_shunt': 2 # Shunt resistance in Ohms - }, - 'rx' : {'model': 'mb_2023_0_X', - 'coef_p2': 2.50, # slope for current conversion for ADS.P2, measurement in V/V - 'sampling_rate': 100., # Hz - 'nb_samples': 20, # Max value 10 # was named integer before... - }, - 'mux': {'model' : 'dummy_mux', # 'ohmpi_i2c_mux64_v1.01', - 'max_elec': 64, - 'board_addresses': {'A': 0x73, 'B': 0x72, 'M': 0x71, 'N': 0x70}, # CHECK IF YOUR BOARDS HAVE THESE ADDRESSES - 'voltage_max': 100, - 'current_max': 3 - } -} - -# SET THE LOGGING LEVELS, MQTT BROKERS AND MQTT OPTIONS ACCORDING TO YOUR NEEDS -# Execution logging configuration -EXEC_LOGGING_CONFIG = { - 'logging_level': logging.INFO, - 'log_file_logging_level': logging.DEBUG, - 'logging_to_console': True, - 'file_name': f'exec{logging_suffix}.log', - 'max_bytes': 262144, - 'backup_count': 30, - 'when': 'd', - 'interval': 1 -} - -# Data logging configuration -DATA_LOGGING_CONFIG = { - 'logging_level': logging.INFO, - 'logging_to_console': True, - 'file_name': f'data{logging_suffix}.log', - 'max_bytes': 16777216, - 'backup_count': 1024, - 'when': 'd', - 'interval': 1 -} - -# State of Health logging configuration (For a future release) -SOH_LOGGING_CONFIG = { - 'logging_level': logging.INFO, - 'logging_to_console': True, - 'file_name': f'soh{logging_suffix}.log', - 'max_bytes': 16777216, - 'backup_count': 1024, - 'when': 'd', - 'interval': 1 -} - -# MQTT logging configuration parameters -MQTT_LOGGING_CONFIG = { - 'hostname': mqtt_broker, - 'port': 1883, - 'qos': 2, - 'retain': False, - 'keepalive': 60, - 'will': None, - 'auth': {'username': 'mqtt_user', 'password': 'mqtt_password'}, - 'tls': None, - 'protocol': MQTTv31, - 'transport': 'tcp', - 'client_id': f'{OHMPI_CONFIG["id"]}', - 'exec_topic': f'ohmpi_{OHMPI_CONFIG["id"]}/exec', - 'exec_logging_level': logging.DEBUG, - 'data_topic': f'ohmpi_{OHMPI_CONFIG["id"]}/data', - 'data_logging_level': DATA_LOGGING_CONFIG['logging_level'], - 'soh_topic': f'ohmpi_{OHMPI_CONFIG["id"]}/soh', - 'soh_logging_level': SOH_LOGGING_CONFIG['logging_level'] -} - -# MQTT control configuration parameters -MQTT_CONTROL_CONFIG = { - 'hostname': mqtt_broker, - 'port': 1883, - 'qos': 2, - 'retain': False, - 'keepalive': 60, - 'will': None, - 'auth': {'username': 'mqtt_user', 'password': 'mqtt_password'}, - 'tls': None, - 'protocol': MQTTv31, - 'transport': 'tcp', - 'client_id': f'{OHMPI_CONFIG["id"]}', - 'ctrl_topic': f'ohmpi_{OHMPI_CONFIG["id"]}/ctrl' -} diff --git a/dev/test_dummy.py b/dev/test_dummy.py deleted file mode 100644 index 96d16d1a..00000000 --- a/dev/test_dummy.py +++ /dev/null @@ -1,13 +0,0 @@ -# import sys -# sys.path.extend(['/home/su530201/PycharmProjects/OhmPi']) -from ohmpi.hardware_components.dummy_tx import Tx -from ohmpi.hardware_components.dummy_rx import Rx -from ohmpi.logging_setup import create_stdout_logger - -exec_logger = create_stdout_logger(name='exec') -soh_logger = create_stdout_logger(name='soh') - -print('\nCreating TX...') -tx = Tx(exec_logger=exec_logger, soh_logger=soh_logger) -print('\nCreating RX...') -rx = Rx(exec_logger=exec_logger, soh_logger=soh_logger) diff --git a/ohmpi/hardware_components/abstract_hardware_components.py b/ohmpi/hardware_components/abstract_hardware_components.py index 85508200..74394fa2 100644 --- a/ohmpi/hardware_components/abstract_hardware_components.py +++ b/ohmpi/hardware_components/abstract_hardware_components.py @@ -55,7 +55,7 @@ class PwrAbstract(ABC): self._current_max = kwargs.pop('current_max', 0.) self._voltage_min = kwargs.pop('voltage_min', 0.) self._voltage_max = kwargs.pop('voltage_max', 0.) - self._switchable = False + self.switchable = False self.connection = kwargs.pop('connection', None) self._battery_voltage = np.nan @@ -435,7 +435,7 @@ class TxAbstract(ABC): def pwr_state(self, state): if state == 'on': self._pwr_state = 'on' - if not self.pwr._switchable: + if not self.pwr.switchable: self.exec_logger.debug(f'{self.model} cannot switch on power source') self.pwr.reload_settings() elif state == 'off': diff --git a/ohmpi/hardware_components/dummy_ctl.py b/ohmpi/hardware_components/dummy_ctl.py deleted file mode 100644 index 0045bd72..00000000 --- a/ohmpi/hardware_components/dummy_ctl.py +++ /dev/null @@ -1,10 +0,0 @@ -from ohmpi.config import HARDWARE_CONFIG -import os -from ohmpi.hardware_components import CtlAbstract -CTL_CONFIG = HARDWARE_CONFIG['ctl'] - - -class Ctl(CtlAbstract): - def __init__(self, **kwargs): - kwargs.update({'model': os.path.basename(__file__).rstrip('.py')}) - super().__init__(**kwargs) diff --git a/ohmpi/hardware_components/dummy_mux.py b/ohmpi/hardware_components/dummy_mux.py deleted file mode 100644 index bb8a5a7d..00000000 --- a/ohmpi/hardware_components/dummy_mux.py +++ /dev/null @@ -1,21 +0,0 @@ -from ohmpi.config import HARDWARE_CONFIG -import os -from ohmpi.hardware_components import MuxAbstract -MUX_CONFIG = HARDWARE_CONFIG['mux'].pop('default', {}) - - -class Mux(MuxAbstract): - def __init__(self, **kwargs): - super().__init__(**kwargs) - - def _get_addresses(self): - pass - - def reset(self): - pass - - def switch_one(self, *args): - MuxAbstract.switch_one(self, *args) - - def test(self, *args): - MuxAbstract.test(self, *args) \ No newline at end of file diff --git a/ohmpi/hardware_components/dummy_rx.py b/ohmpi/hardware_components/dummy_rx.py deleted file mode 100644 index 249a2e49..00000000 --- a/ohmpi/hardware_components/dummy_rx.py +++ /dev/null @@ -1,40 +0,0 @@ -from ohmpi.ohmpi.config import HARDWARE_CONFIG -import numpy as np -import os -from ohmpi.hardware_components import RxAbstract -RX_CONFIG = HARDWARE_CONFIG['rx'] - -# hardware characteristics and limitations -# ADC for voltage -voltage_adc_voltage_min = 10. # mV -voltage_adc_voltage_max = 4500. - -RX_CONFIG['voltage_min'] = np.min([voltage_adc_voltage_min, RX_CONFIG.pop('voltage_min', np.inf)]) # mV -RX_CONFIG['voltage_max'] = np.min([voltage_adc_voltage_max, RX_CONFIG.pop('voltage_max', np.inf)]) # mV - - -class Rx(RxAbstract): - def __init__(self, **kwargs): - super().__init__(**kwargs) - self._adc_gain = 1. - - @property - def adc_gain(self): - return self._adc_gain - - @adc_gain.setter - def adc_gain(self, value): - self.exec_logger.debug(f'Setting RX ADC gain to {value}') - - def adc_gain_auto(self): - gain = 1. - self.exec_logger.debug(f'Setting RX ADC gain automatically to {gain}') - self.adc_gain = gain - - @property - def voltage(self): - """ Gets the voltage VMN in Volts - """ - u = np.random.uniform(-.200,.200) # gets the max between u0 & u2 and set the sign - self.exec_logger.debug(f'Reading random voltage on RX. Returning {u} V') - return u \ No newline at end of file diff --git a/ohmpi/hardware_components/dummy_tx.py b/ohmpi/hardware_components/dummy_tx.py deleted file mode 100644 index cef80c8e..00000000 --- a/ohmpi/hardware_components/dummy_tx.py +++ /dev/null @@ -1,113 +0,0 @@ -from ohmpi.config import HARDWARE_CONFIG -import time -import os -import numpy as np -from ohmpi.hardware_components import TxAbstract - -TX_CONFIG = HARDWARE_CONFIG['tx'] - -# ADC for current -current_adc_voltage_min = 10. # mV -current_adc_voltage_max = 4500. # mV - -# DPS -dps_voltage_max = 50. # V -dps_default_voltage = 5. # V -dps_switch_on_warmup = 4. # seconds -tx_low_battery = 12. # V - -TX_CONFIG['current_min'] = np.min([current_adc_voltage_min / (TX_CONFIG['r_shunt'] * 50), TX_CONFIG.pop('current_min', np.inf)]) # mA -TX_CONFIG['current_max'] = np.min([current_adc_voltage_max / (TX_CONFIG['r_shunt'] * 50), TX_CONFIG.pop('current_max', np.inf)]) # mA -TX_CONFIG['voltage_max'] = np.min([dps_voltage_max, TX_CONFIG.pop('voltage_max', np.inf)]) # V -TX_CONFIG['default_voltage'] = np.min([TX_CONFIG.pop('default_voltage', dps_default_voltage), TX_CONFIG['voltage_max']]) # V -TX_CONFIG['dps_switch_on_warm_up'] = TX_CONFIG.pop('dps_switch_on_warmup', dps_switch_on_warmup) -TX_CONFIG['low_battery'] = TX_CONFIG.pop('low_battery', tx_low_battery) - -class Tx(TxAbstract): - def inject(self, state='on'): - pass - - def __init__(self, **kwargs): - super().__init__(**kwargs) - self._voltage = kwargs.pop('voltage', TX_CONFIG['default_voltage']) - - self._adc_gain = 1. - - self.polarity = 0 - self.turn_on() - time.sleep(TX_CONFIG['dps_switch_on_warm_up']) - self.exec_logger.info(f'TX battery: {self.tx_bat:.1f} V') - self.turn_off() - - - @property - def adc_gain(self): - return self._adc_gain - - @adc_gain.setter - def adc_gain(self, value): - self._adc_gain = value - self.exec_logger.debug(f'Setting TX ADC gain to {value}') - - def adc_gain_auto(self): - gain = 1. - self.exec_logger.debug(f'Setting TX ADC gain automatically to {gain}') - self.adc_gain = gain - - def current_pulse(self, **kwargs): - super().current_pulse(**kwargs) - self.exec_logger.warning(f'Current pulse is not implemented for the {TX_CONFIG["model"]} board') - - @property - def current(self): - """ Gets the current IAB in Amps - """ - current = np.abs(np.random.normal(0.7, 0.2)) - self.exec_logger.debug(f'Reading random current on TX. Returning {current} A') - return current - - @ current.setter - def current(self, value): - assert TX_CONFIG['current_min'] <= value <= TX_CONFIG['current_max'] - self.exec_logger.warning(f'Current pulse is not implemented for the {TX_CONFIG["model"]} board') - - @property - def voltage(self): - return self._voltage - @voltage.setter - def voltage(self, value): - if value > TX_CONFIG['voltage_max']: - self.exec_logger.warning(f'Sorry, cannot inject more than {TX_CONFIG["voltage_max"]} V, ' - f'set it back to {TX_CONFIG["default_voltage"]} V (default value).') - value = TX_CONFIG['default_voltage'] - if value < 0.: - self.exec_logger.warning(f'Voltage should be given as a positive number. ' - f'Set polarity to -1 to reverse voltage...') - value = np.abs(value) - self._voltage=value - - @property - def tx_bat(self): - tx_bat = np.random.uniform(10.9, 13.4) - if tx_bat < 12.: - self.soh_logger.debug(f'Low TX Battery: {tx_bat:.1f} V') - return tx_bat - - def voltage_pulse(self, voltage=TX_CONFIG['default_voltage'], length=None, polarity=None): - """ Generates a square voltage pulse - - Parameters - ---------- - voltage: float, optional - Voltage to apply in volts, tx_v_def is applied if omitted. - length: float, optional - Length of the pulse in seconds - polarity: 1,0,-1 - Polarity of the pulse - """ - kwargs = locals() - kwargs.pop('self') - kwargs.pop('__class__') - print(kwargs) - super().voltage_pulse(**kwargs) - diff --git a/ohmpi/hardware_components/mb_2023_0_X.py b/ohmpi/hardware_components/mb_2023_0_X.py index 7ba2a165..4fe1c0b6 100644 --- a/ohmpi/hardware_components/mb_2023_0_X.py +++ b/ohmpi/hardware_components/mb_2023_0_X.py @@ -242,7 +242,7 @@ class Rx(RxAbstract): self.exec_logger.event(f'{self.model}\trx_init\tend\t{datetime.datetime.utcnow()}') @property - def gain(self): #TODO: should be in abstract_hardware_components + def gain(self): # TODO: should be in abstract_hardware_components return self._adc_gain @gain.setter diff --git a/ohmpi/hardware_components/pwr_dps5005.py b/ohmpi/hardware_components/pwr_dps5005.py index cc12fc3e..55f83327 100644 --- a/ohmpi/hardware_components/pwr_dps5005.py +++ b/ohmpi/hardware_components/pwr_dps5005.py @@ -17,8 +17,6 @@ SPECS = {'model': {'default': os.path.basename(__file__).rstrip('.py')}, 'pwr_latency': {'default': .5} } -# TODO: Complete this code... handle modbus connection - class Pwr(PwrAbstract): def __init__(self, **kwargs): @@ -32,10 +30,6 @@ class Pwr(PwrAbstract): if not subclass_init: self.exec_logger.event(f'{self.model}\tpwr_init\tbegin\t{datetime.datetime.utcnow()}') assert isinstance(self.connection, Instrument) - # if a controller is passed in kwargs, it will be instantiated - #if self.ctl is None: - # self.ctl = ctl_module.Ctl(**CTL_CONFIG) - #self.connection = self.ctl.interfaces[kwargs.pop('connection', ctl_connection)] self._voltage = kwargs['voltage'] self._current_max = kwargs['current_max'] self.voltage_adjustable = True @@ -93,7 +87,7 @@ class Pwr(PwrAbstract): self.current_max(self._current_max) self._pwr_state = 'on' self.exec_logger.debug(f'{self.model} is on') - time.sleep(self._pwr_latency) # from pwr specs + time.sleep(self._pwr_latency) elif state == 'off': self.connection.write_register(0x09, 0) @@ -101,5 +95,4 @@ class Pwr(PwrAbstract): self.exec_logger.debug(f'{self.model} is off') def reload_settings(self): - # self.voltage(self._voltage) self.current_max(self._current_max) diff --git a/ohmpi/logging_setup.py b/ohmpi/logging_setup.py index 33927655..726a7d9f 100644 --- a/ohmpi/logging_setup.py +++ b/ohmpi/logging_setup.py @@ -1,6 +1,6 @@ import json -from ohmpi.config import EXEC_LOGGING_CONFIG, DATA_LOGGING_CONFIG, SOH_LOGGING_CONFIG,\ - MQTT_LOGGING_CONFIG, MQTT_CONTROL_CONFIG +from ohmpi.config import (EXEC_LOGGING_CONFIG, DATA_LOGGING_CONFIG, SOH_LOGGING_CONFIG, MQTT_LOGGING_CONFIG, + MQTT_CONTROL_CONFIG) from os import path, mkdir, statvfs from time import gmtime import logging @@ -12,7 +12,7 @@ from termcolor import colored def get_logging_levels(): """Gets a list of the logging levels loaded""" - return [logging.getLevelName(x) for x in range(1,101) if not logging.getLevelName(x).startswith('Level')] + return [logging.getLevelName(x) for x in range(1, 101) if not logging.getLevelName(x).startswith('Level')] def add_logging_level(level_name, level_num, method_name=None): @@ -227,7 +227,7 @@ def setup_loggers(mqtt=True): except Exception as err: msg += colored(f'\n\u26A0 ERROR: Could not initialize logging!\n{err}', 'red') finally: - return exec_logger, exec_log_filename, data_logger, data_log_filename, soh_logger, soh_log_filename,\ + return exec_logger, exec_log_filename, data_logger, data_log_filename, soh_logger, soh_log_filename, \ EXEC_LOGGING_CONFIG['logging_level'], msg diff --git a/ohmpi/utils.py b/ohmpi/utils.py index bc85aad6..653d112d 100644 --- a/ohmpi/utils.py +++ b/ohmpi/utils.py @@ -23,6 +23,7 @@ def enforce_specs(kwargs, specs, key): return kwargs + def update_dict(d, u): """Updates a dictionary by adding elements to collection items associated to existing keys @@ -113,17 +114,18 @@ def parse_log(log): session = np.array(session) return time, process_id, tag, msg, session + def mux_2024_to_mux_2023_takeouts(mux_boards): - """Updates cabling for mux v2024 so that takeouts are similar to takeouts from mux v2023. - This is only useful when replacing mux v2023 installations or re-using old test circuits." + """ Updates cabling for mux v2024 so that takeouts are similar to takeouts from mux v2023. + This is only useful when replacing mux v2023 installations or re-using old test circuits. Parameters ---------- mux_boards: list of class MUX objects. - Usage - ---------- + Example + ------- k = OhmPi() mux_2024_to_mux_2023_takeouts(k._hw.mux_boards) """ @@ -136,4 +138,4 @@ def mux_2024_to_mux_2023_takeouts(mux_boards): for k, v in mux.cabling.items(): print(k, v) new_cabling[k] = (mapper[v[0]], v[1]) - mux.cabling = new_cabling \ No newline at end of file + mux.cabling = new_cabling -- GitLab