diff --git a/configs/config_default.py b/configs/config_default.py index 0763f48ca2240311e01b281a1eea9571c324defd..49e24ecf21e05b67d55dbc77de65e46ae3c216aa 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 1d2fc9f48b545244fdf52e61f1a897d420bb3968..0000000000000000000000000000000000000000 --- 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 8373edcbe9830a0d05fbbf0a8ce3ee02cb18ccda..d8adeb5db6afcf2d47bc5e35e292e13f811ec50d 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 40665972ec78fcbb165cf92d2b3b5fb2fe617836..54dd5b25f1f36fdce31e9d72b5f2009855105a3a 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 f15f2af3127ea11b8469d20e109fbcc6120954d0..9f143bd82682f81f0681e79aaa04ef81ef11fdff 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 b4d7d2cce647f725fe30c95e665f02f1e0c10f8c..b94f2f04deb7604b23bb165207cdd57c3d3e9a0f 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 42fe5c13e36a6ecce55e4cfda1a862b92cce04ba..0ad831386829a3a9504f722451d4606eef8a625b 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 6b911300ab4745a2585a6cbc0d6e20a73035112f..f957adfddb8e760c7ba96ba9c8002343141c7897 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 4df5c6963f504411cc4927e7af82322ee164da08..0000000000000000000000000000000000000000 --- 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 c73ecf4176c1b9f23935fe196370fb741ae89477..e0516838ee69444ee7862fd5d42a9337a99df8f5 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 ecc683c7d09c56a11ac44cbd4327784e40da45c4..62274c84f84be2d9da542b8c3cf23e3809fff8ac 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 60f5bfc061e71e10431b20ffb1dd670d37997604..f15eec54efae5a587a558eb050ca6a18cc927fd6 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 a0f08b7995d9f7e94ea552d787bda027094792fa..222888d78791de2d191eb30d14ef50d383be2010 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 8fa5f2421b868ae8638be841186eea7b6972a7e8..92f98a304b194bee1bd01cb67d1b30bd500355d5 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 103f537ed1488796a68bce96b2721c1ccba3199d..ff6fdaa14a75e55ae7ab7510adcbd49a5b98de8c 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 abba800afd622de78efddc9ff8fb62855863ab22..d4cad9f9851bbc5f283ff02f6430e2b44a6a20b4 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 07b11fd5e7ce4f9ad9759e9eaae7ffc4ad234d49..7a95a19e3e252b244cdb90a7c65866994f1a1e56 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 c88c3bcde37de0285136007b88a30b3d2e982f05..7e05a44ba03e804486adf12d5b16b23dfd9df134 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 26c4c561c5fc960449019bd6fa7901d724d34597..0000000000000000000000000000000000000000 --- 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 96d16d1acee8ed44dd37380417f592eb3636df2a..0000000000000000000000000000000000000000 --- 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 8550820046668cc1574f11cc762a0d8dc291980c..74394fa2a4775dfbd54f3eeea8d1abb49a439223 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 0045bd726c551db024d5362b75182eeaed327ad0..0000000000000000000000000000000000000000 --- 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 bb8a5a7d118aa5d132ffe6bb6aeaaba33066767c..0000000000000000000000000000000000000000 --- 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 249a2e49170661195662736ed2abe2f65a054345..0000000000000000000000000000000000000000 --- 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 cef80c8e7dfdfb386487add40f79e50579fda93c..0000000000000000000000000000000000000000 --- 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 7ba2a1652aa1d34523076bb589523293f70863d1..4fe1c0b62d9a524b45d35f12d4849191ed997a4c 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 cc12fc3e44d2f03343403a7c9b3551eccd991b29..55f833278b8bb56e9934a6e7b524dfcf28980e6c 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 33927655e620ea488ad99e3e05b1001cf0b6dbeb..726a7d9f8f0dc7f495e8b54a20595e1c632518b6 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 bc85aad678adecb99524d69c705230a90c650dfa..653d112d510474107f63d31a83f3be7946e2861c 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