Commit b7bbd267 authored by Olivier Kaufmann's avatar Olivier Kaufmann
Browse files

Moves generate preset sequences in ohmpi.utils.py

Showing with 0 additions and 422 deletions
+0 -422
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
import logging
from ohmpi.utils import get_platform
from paho.mqtt.client import MQTTv31 # noqa
_, 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
}
r_shunt = 2.
HARDWARE_CONFIG = {
'ctl': {'model': 'raspberry_pi'},
'pwr': {'model': 'pwr_dps5005', 'voltage': 3., 'interface_name': 'modbus'},
'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': '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'
},
'mux': {'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_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 = {
'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'
}
configs_to_generate = ['config_mb_2023.py', 'config_mb_2023__4_mux_2023.py',
'config_mb_2023__1_mux_2024_4roles.py', 'config_mb_2023__2_mux_2024_4roles.py',
'config_mb_2023__3_mux_2024_4roles.py', 'config_mb_2023__4_mux_2024_4roles.py',
'config_mb_2023__2_mux_2024_2roles.py', 'config_mb_2023__4_mux_2024_2roles.py',
'config_mb_2024_0_2.py', 'config_mb_2024_0_2_dps5005.py',
'config_mb_2024_0_2__4_mux_2023.py', 'config_mb_2024_0_2__4_mux_2023_dps5005.py',
'config_mb_2024_0_2__1_mux_2024_4roles.py', 'config_mb_2024_0_2__1_mux_2024_4roles_dps5005.py',
'config_mb_2024_0_2__2_mux_2024_4roles.py', 'config_mb_2024_0_2__2_mux_2024_4roles_dps5005.py',
'config_mb_2024_0_2__2_mux_2024_2roles.py', 'config_mb_2024_0_2__2_mux_2024_2roles_dps5005.py',
'config_mb_2024_0_2__3_mux_2024_4roles.py', 'config_mb_2024_0_2__3_mux_2024_4roles_dps5005.py',
'config_mb_2024_0_2__4_mux_2024_4roles.py', 'config_mb_2024_0_2__4_mux_2024_4roles_dps5005.py',
'config_mb_2024_0_2__4_mux_2024_2roles.py', 'config_mb_2024_0_2__4_mux_2024_2roles_dps5005.py'
]
header = """import logging
from ohmpi.utils import get_platform
from paho.mqtt.client import MQTTv31 # noqa
_, 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
}
r_shunt = 2.
# default properties of system components that will be
# overwritten by properties defined in each the board dict below.
# if bounds are 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
HARDWARE_CONFIG = {
'ctl': {'model': 'raspberry_pi'},
'pwr': """
r_shunt = 2.
options = {'pwr': {'battery': """{'model': 'pwr_batt', 'voltage': 12., 'interface_name': 'none'},""",
'dps5005': """{'model': 'pwr_dps5005', 'voltage': 3., 'interface_name': 'modbus'},"""
},
'mb': {'mb_2024_0_2': {'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',
'vmn_hardware_offset': 2500.
}""",
'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',
}"""},
'mb_2023': {'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': {'mux_2023':
[""" 'mux_A':
{'model': 'mux_2023_0_X',
'mux_tca_address': 0x70,
'roles': 'A',
'electrodes': range(1, 65),
},""",
"""\n 'mux_B':
{'model': 'mux_2023_0_X',
'mux_tca_address': 0x71,
'roles': 'B',
'electrodes': range(1, 65),
},""",
"""\n 'mux_M':
{'model': 'mux_2023_0_X',
'mux_tca_address': 0x72,
'roles': 'M',
'electrodes': range(1, 65),
},""",
"""\n 'mux_N':
{'model': 'mux_2023_0_X',
'mux_tca_address': 0x73,
'roles': 'N',
'electrodes': range(1, 65),
}"""],
'mux_2024_2roles':
[""" 'mux_01':
{'model': 'mux_2024_0_X',
'roles': ['A', 'B'],
'electrodes': range(1, 17),
'addr1': 'down',
'addr2': 'up',
'tca_address': None,
'tca_channel': 0,
},""",
"""\n 'mux_02':
{'model': 'mux_2024_0_X',
'roles': ['M', 'N'],
'electrodes': range(1, 17),
'addr1': 'up',
'addr2': 'down',
'tca_address': None,
'tca_channel': 0,
},""",
"""\n 'mux_03':
{'model': 'mux_2024_0_X',
'roles': ['A', 'B'],
'electrodes': range(17, 33),
'addr1': 'up',
'addr2': 'down',
'tca_address': None,
'tca_channel': 0,},""",
"""\n 'mux_04':
{'model': 'mux_2024_0_X',
'roles': ['M', 'N'],
'electrodes': range(17, 33),
'addr1': 'down',
'addr2': 'down',
'tca_address': None,
'tca_channel': 0,
}"""],
'mux_2024_4roles': [
""" {'mux_01':
{'model': 'mux_2024_0_X',
'electrodes': range(1, 9),
'roles': ['A', 'B', 'M', 'N'],
'addr1': 'up',
'addr2': 'up',
'tca_address': None,
'tca_channel': 0,},""",
"""\n 'mux_02':
{'model': 'mux_2024_0_X',
'electrodes': range(9, 17),
'roles': ['A', 'B', 'M', 'N'],
'addr1': 'down',
'addr2': 'up',
'tca_address': None,
'tca_channel': 0,},""",
"""\n 'mux_03':
{'model': 'mux_2024_0_X',
'electrodes': range(17, 25),
'roles': ['A', 'B', 'M', 'N'],
'addr1': 'up',
'addr2': 'down',
'tca_address': None,
'tca_channel': 0,},""",
"""\n 'mux_04':
{'model': 'mux_2024_0_X',
'electrodes': range(25, 33),
'roles': ['A', 'B', 'M', 'N'],
'addr1': 'down',
'addr2': 'down',
'tca_address': None,
'tca_channel': 0,},"""]
}
}
mux_footer = {'mb_2023': """\n },
'default': {'interface_name': 'i2c',
'voltage_max': 50.,
'current_max': 3.}
}\n}\n""",
'mb_2024_0_2': """\n },
'default': {'interface_name': 'i2c_ext',
'voltage_max': 50.,
'current_max': 3.}
}\n}\n"""}
footer = """# 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'
}
"""
for mb, v_mb in options['mb'].items():
for n in range(0, 5):
for mux, v_mux in options['mux'].items():
for pwr, v_pwr in options['pwr'].items():
config_filename = f'config_{mb}'
if n > 0:
config_filename += f'__{n}_{mux}'
if pwr != 'battery':
config_filename += f'_{pwr}'
config_filename += '.py'
if config_filename in configs_to_generate:
s = header
s += v_pwr
s += f"\n 'tx': {v_mb['tx']},\n 'rx': {v_mb['rx']},\n"
if n > 0:
s += """ 'mux': {'boards':\n"""
for i in range(n):
print(n, i)
s += v_mux[i]
s += mux_footer[mb]
else:
s = s + """ 'mux': {'boards': {},
'default': {}
}\n}""" + '\n'
s += footer
print(f'*** Preparing {config_filename} ***')
print(f'\n{s}')
with open(f'configs/{config_filename}', mode='wt') as config_file:
config_file.write(s)
else:
print(f'### skipping {config_filename} ###')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment