Skip to content

Commit

Permalink
Merge pull request #85 from WattRex/config_files
Browse files Browse the repository at this point in the history
Multiple changes
  • Loading branch information
mariuscrsn authored Dec 28, 2023
2 parents 98d8192 + 3c3bbba commit fcb62d4
Show file tree
Hide file tree
Showing 36 changed files with 162 additions and 131 deletions.
8 changes: 6 additions & 2 deletions code/cu_manager/src/wattrex_cycler_cu_manager/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@
DEFAULT_RX_CAN_NAME : str = 'RX_CAN_QUEUE' # Default rx_can system queue name
DEFAULT_DETECT_TIMEOUT : int = 2 # Default time to read asked devices answers
DEFAULT_DEV_PATH : str = '/dev/wattrex/' # Default path to the devices
DEFAULT_SCPI_QUEUE_PREFIX: str = 'DET_' # Default prefix for the scpi queues
DEFAULT_SCPI_QUEUE_PREFIX : str = 'DET_' # Default prefix for the scpi queues
DEFAULT_CU_ID_PATH : str = './config/cu_manager/.cu_id'
# Default path to credential file for rabbitmq
DEFAULT_CRED_PATH : str = './config/.cred.yaml'

CONSTANTS_NAMES = ('DEFAULT_TX_CAN_NAME', 'DEFAULT_TX_SCPI_NAME',
'DEFAULT_RX_CAN_NAME', 'DEFAULT_DETECT_TIMEOUT',
'DEFAULT_DEV_PATH', 'DEFAULT_SCPI_QUEUE_PREFIX')
'DEFAULT_DEV_PATH', 'DEFAULT_SCPI_QUEUE_PREFIX',
'DEFAULT_CU_ID_PATH', 'DEFAULT_CRED_PATH')

sys_conf_update_config_params(context=globals(),
constants_names=CONSTANTS_NAMES,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
####################### THIRD PARTY IMPORTS #######################

####################### SYSTEM ABSTRACTION IMPORTS #######################
from system_logger_tool import sys_log_logger_get_module_logger, SysLogLoggerC, Logger
from system_logger_tool import sys_log_logger_get_module_logger, Logger

####################### LOGGER CONFIGURATION #######################
if __name__ == '__main__':
cycler_logger = SysLogLoggerC(file_log_levels='../log_config.yaml')
log: Logger = sys_log_logger_get_module_logger(__name__)

####################### PROJECT IMPORTS #######################
Expand All @@ -26,6 +24,9 @@

####################### MODULE IMPORTS #######################

###################### CONSTANTS ######################
from .context import DEFAULT_CRED_PATH

####################### ENUMS #######################
_REGISTER_TOPIC = '/register'
_INFORM_TOPIC = '/inform_reg'
Expand All @@ -35,7 +36,6 @@
_SUFFIX_RX_LAUNCH = '/launch'



####################### CLASSES #######################

class BrokerClientC():
Expand All @@ -45,7 +45,7 @@ class BrokerClientC():
def __init__(self, error_callback : Callable, launch_callback : Callable,\
detect_callback : Callable, store_cu_info_cb : Callable) -> None:
self.mqtt : DrvMqttDriverC = DrvMqttDriverC(error_callback=error_callback,
cred_path='./devops/.cred.yaml')
cred_path=DEFAULT_CRED_PATH)
self.__launch_cb : Callable = launch_callback
self.__detect_cb : Callable = detect_callback
self.__store_cu_info_cb : Callable = store_cu_info_cb
Expand Down
11 changes: 6 additions & 5 deletions code/cu_manager/src/wattrex_cycler_cu_manager/cu_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/python3
"""
Cu Manager
Cum Manager
"""
####################### MANDATORY IMPORTS #######################

Expand All @@ -15,11 +15,9 @@
####################### THIRD PARTY IMPORTS #######################

####################### SYSTEM ABSTRACTION IMPORTS #######################
from system_logger_tool import sys_log_logger_get_module_logger, SysLogLoggerC, Logger
from system_logger_tool import sys_log_logger_get_module_logger, Logger

####################### LOGGER CONFIGURATION #######################
if __name__ == '__main__':
cycler_logger = SysLogLoggerC(file_log_levels='./log_config.yaml')
log: Logger = sys_log_logger_get_module_logger(__name__)

####################### PROJECT IMPORTS #######################
Expand All @@ -32,6 +30,9 @@
from .register import get_cu_info
from .detect import DetectorC

###################### CONSTANTS ######################
from .context import DEFAULT_CU_ID_PATH

####################### ENUMS #######################

####################### CLASSES #######################
Expand All @@ -42,7 +43,7 @@ class CuManagerNodeC(SysShdNodeC):
'''

def __init__(self, working_flag : Event, cycle_period : int,
cu_id_file_path : str = './devops/cu_manager/.cu_id') -> None:
cu_id_file_path : str = DEFAULT_CU_ID_PATH) -> None:
'''
Initialize the CU manager node.
'''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def execute_machine_status(self) -> None: #pylint: disable=too-many-branches, to
if self.state == AppManCoreStatusE.GET_EXP:
## Wait for cs status to continue
if self.__get_exp_status is _AppManCoreGetExpStatusE.GET_EXP:
log.info("Searching for new experiment")
self.__fetch_new_exp()
self.__request_cs_status()
self.__get_exp_status = _AppManCoreGetExpStatusE.WAIT_CS
Expand Down Expand Up @@ -288,7 +289,7 @@ def execute_machine_status(self) -> None: #pylint: disable=too-many-branches, to
log.debug("Executing experiment")
self.__execute_experiment()
## Check if the experiment has finish and try to get the next one
log.debug(f"Experiment status: {self.exp_status}")
log.info(f"Experiment status: {self.exp_status}")
if self.exp_status in (CyclerDataExpStatusE.FINISHED,
CyclerDataExpStatusE.ERROR):
self.experiment = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
###################### CONSTANTS ######################
# For further information check out README.md

DEFAULT_PERIOD_ELECT_MEAS: int = 25 # Express in centiseconds
DEFAULT_PERIOD_TEMP_MEAS: int = 25 # Express in centiseconds
DEFAULT_PERIOD_ELECT_MEAS : int = 25 # Express in centiseconds
DEFAULT_PERIOD_TEMP_MEAS : int = 25 # Express in centiseconds

CONSTANTS_NAMES = ('DEFAULT_PERIOD_ELECT_MEAS', 'DEFAULT_PERIOD_TEMP_MEAS')
sys_conf_update_config_params(context=globals(),
Expand Down
21 changes: 9 additions & 12 deletions code/cycler/src/wattrex_battery_cycler/mid/mid_dabs/mid_dabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

####################### THIRD PARTY IMPORTS #######################

from system_logger_tool import SysLogLoggerC, sys_log_logger_get_module_logger, Logger
if __name__ == '__main__':
cycler_logger = SysLogLoggerC(file_log_levels= 'log_config.yaml')
from system_logger_tool import sys_log_logger_get_module_logger, Logger
log: Logger = sys_log_logger_get_module_logger(__name__)

from scpi_sniffer import DrvScpiSerialConfC
Expand Down Expand Up @@ -110,15 +108,19 @@ class MidDabsPwrMeterC: #pylint: disable= too-many-instance-attributes
'''Instanciates an object enable to measure but are also power devices.
'''
def __init__(self, device: list [CyclerDataDeviceC]) -> None:
self.device_type: CyclerDataDeviceTypeE = device[0].device_type
self._dev_db_id: int = device[0].dev_db_id
pwr_devices: List[CyclerDataDeviceC] = device.copy()
for dev in pwr_devices:
if not dev.is_control:
pwr_devices.remove(dev)
self.device_type: CyclerDataDeviceTypeE = pwr_devices[0].device_type
self._dev_db_id: int = pwr_devices[0].dev_db_id
## Commented for first version
# self.bisource : DrvEaDeviceC | None = None
# self.source : DrvEaDeviceC | None = None
# self.load : DrvRsDeviceC | None = None
self.epc : DrvEpcDeviceC| None = None
try:
for dev in device:
for dev in pwr_devices:
if dev.device_type == CyclerDataDeviceTypeE.EPC:
can_id= 0
if not dev.iface_name.isnumeric(): # isinstance(dev.iface_name, str),
Expand Down Expand Up @@ -220,12 +222,7 @@ class MidDabsPwrDevC(MidDabsPwrMeterC):
"""Instanciates an object enable to control the devices.
"""
def _init__(self, device: List[CyclerDataDeviceC])->None:
pwr_devices: List[CyclerDataDeviceC] = device.copy()
for dev in pwr_devices:
if dev.device_type not in (CyclerDataDeviceTypeE.EPC, CyclerDataDeviceTypeE.SOURCE,
CyclerDataDeviceTypeE.LOAD, CyclerDataDeviceTypeE.BISOURCE):
pwr_devices.remove(dev)
super().__init__(pwr_devices)
super().__init__(device)

def set_cv_mode(self,volt_ref: int, limit_ref: int,
limit_type: CyclerDataPwrLimitE = None) -> CyclerDataDeviceStatusE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
from threading import Event
####################### THIRD PARTY IMPORTS #######################

from system_logger_tool import SysLogLoggerC, sys_log_logger_get_module_logger, Logger
if __name__ == '__main__':
cycler_logger = SysLogLoggerC(file_log_levels= 'log_config.yaml')
from system_logger_tool import sys_log_logger_get_module_logger, Logger
log: Logger = sys_log_logger_get_module_logger(__name__)

from system_shared_tool import (SysShdSharedObjC, SysShdNodeC, SysShdNodeParamsC, SysShdErrorC,
SysShdNodeStatusE)
from wattrex_cycler_datatypes.cycler_data import (CyclerDataDeviceC, CyclerDataGenMeasC,
CyclerDataDeviceTypeE, CyclerDataExtMeasC, CyclerDataAllStatusC, CyclerDataMergeTagsC)
CyclerDataExtMeasC, CyclerDataAllStatusC, CyclerDataMergeTagsC)

####################### MODULE IMPORTS #######################
from ..mid_dabs import MidDabsPwrMeterC, MidDabsExtraMeterC #pylint: disable= relative-beyond-top-level
Expand Down Expand Up @@ -54,8 +52,7 @@ def __init__(self,shared_gen_meas: SysShdSharedObjC, shared_ext_meas: SysShdShar
self.working_flag = working_flag
self.__extra_meter: List[MidDabsExtraMeterC] = []
for dev in devices:
if dev.device_type in (CyclerDataDeviceTypeE.BK, CyclerDataDeviceTypeE.BMS,
CyclerDataDeviceTypeE.FLOW):
if not dev.is_control:
self.__extra_meter.append(MidDabsExtraMeterC(dev))
devices.remove(dev)
self.__pwr_dev: MidDabsPwrMeterC = MidDabsPwrMeterC(devices)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
from time import time
####################### THIRD PARTY IMPORTS #######################

from system_logger_tool import SysLogLoggerC, sys_log_logger_get_module_logger, Logger
if __name__ == '__main__':
cycler_logger = SysLogLoggerC(file_log_levels= 'log_config.yaml')
from system_logger_tool import sys_log_logger_get_module_logger, Logger
log: Logger = sys_log_logger_get_module_logger(__name__)

####################### PROJECT IMPORTS #######################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
DEFAULT_TIMEOUT_CONNECTION: int = 5
DEFAULT_NODE_PERIOD: int = 250 # Express in milliseconds
DEFAULT_NODE_NAME: str = 'STR'
DEFAULT_CRED_FILEPATH : str = './devops/.cred.yaml' # Path to the location of the credential file
DEFAULT_CRED_FILEPATH : str = './config/.cred.yaml' # Path to the location of the credential file

CONSTANTS_NAMES = ('DEFAULT_TIMEOUT_CONNECTION', 'DEFAULT_NODE_PERIOD', 'DEFAULT_NODE_NAME',
'DEFAULT_CRED_FILEPATH')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
####################### THIRD PARTY IMPORTS #######################

####################### SYSTEM ABSTRACTION IMPORTS #######################
from system_logger_tool import sys_log_logger_get_module_logger, SysLogLoggerC, Logger
from system_logger_tool import sys_log_logger_get_module_logger, Logger

####################### LOGGER CONFIGURATION #######################
if __name__ == '__main__':
cycler_logger = SysLogLoggerC(file_log_levels='../log_config.yaml')
log: Logger = sys_log_logger_get_module_logger(__name__)

####################### MODULE IMPORTS #######################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ def get_start_queued_exp(self) -> Tuple[CyclerDataExperimentC|None, CyclerDataBa
filter( DrvDbMasterExperimentC.Status == DrvDbExpStatusE.QUEUED.value,
DrvDbMasterExperimentC.CSID == self.cs_id).order_by(
DrvDbMasterExperimentC.DateCreation.asc()).all()
log.critical(f"Experiment fetched: {exp_result}")
if len(exp_result) != 0:
exp_result: DrvDbMasterExperimentC = exp_result[0]
exp : CyclerDataExperimentC = CyclerDataExperimentC()
Expand All @@ -106,7 +105,6 @@ def get_start_queued_exp(self) -> Tuple[CyclerDataExperimentC|None, CyclerDataBa
log.debug(f"Experiment fetched: {exp.__dict__}, {battery.__dict__}, {profile.__dict__}")
else:
log.debug("No experiment found")
log.info(f"No experiment found {exp_result}")
return exp, battery, profile

## All methods that get information will gather the info from the master db
Expand Down Expand Up @@ -224,6 +222,7 @@ def get_cycler_station_info(self) -> CyclerDataCyclerStationC|None: #pylint: dis
for db_name, att_name in MAPPING_DEV_DB.items():
if att_name == "device_type":
setattr(device, att_name, CyclerDataDeviceTypeE(getattr(comp_dev_res,db_name)))
device.check_power_device()
elif db_name in detected_dev_res.__dict__:
setattr(device, att_name, getattr(detected_dev_res,db_name))
else:
Expand Down Expand Up @@ -323,7 +322,8 @@ def write_extended_measures(self, exp_id: int) -> None:
ext_meas.UsedMeasID = key.split('_')[-1]
ext_meas.MeasID = self.meas_id
ext_meas.Value = getattr(self.ext_meas,key)
self.__cache_db.session.add(ext_meas)
if ext_meas.Value is not None:
self.__cache_db.session.add(ext_meas)

def turn_cycler_station_deprecated(self, exp_id: int|None) -> None:
"""Method to turn a cycler station to deprecated.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __apply_command(self, command : MidStrCmdDataC) -> None: #pylint: disable= t
'''
#Check which type of command has been received and matchs the payload type
if command.cmd_type == MidStrReqCmdE.GET_NEW_EXP:
log.info('Getting new experiment info from database')
log.debug('Getting new experiment info from database')
exp_info, battery_info, profile_info = self.db_iface.get_start_queued_exp()
if exp_info is not None:
self.__actual_exp_id = exp_info.exp_id
Expand Down
2 changes: 1 addition & 1 deletion code/cycler/tests/prueba_mid_str_meas.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
####################### SYSTEM ABSTRACTION IMPORTS #######################
from system_logger_tool import Logger, SysLogLoggerC, sys_log_logger_get_module_logger

main_logger = SysLogLoggerC(file_log_levels="code/log_config.yaml")
main_logger = SysLogLoggerC(file_log_levels="config/cycler/log_config.yaml")
log: Logger = sys_log_logger_get_module_logger(name="test_mid_str")
from system_shared_tool import SysShdSharedObjC, SysShdChanC
####################### THIRD PARTY IMPORTS #######################
Expand Down
2 changes: 1 addition & 1 deletion code/cycler/tests/test_app_man.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from pytest import fixture, mark
####################### SYSTEM ABSTRACTION IMPORTS #######################
from system_logger_tool import Logger, SysLogLoggerC, sys_log_logger_get_module_logger
main_logger = SysLogLoggerC(file_log_levels="devops/cycler/log_config.yaml")
main_logger = SysLogLoggerC(file_log_levels="config/cycler/log_config.yaml")
log: Logger = sys_log_logger_get_module_logger(name="test_app_man")

####################### THIRD PARTY IMPORTS #######################
Expand Down
3 changes: 2 additions & 1 deletion code/cycler/tests/test_mid_dabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
####################### SYSTEM ABSTRACTION IMPORTS #######################

from system_logger_tool import Logger, SysLogLoggerC, sys_log_logger_get_module_logger
main_logger = SysLogLoggerC(file_log_levels="devops/cycler/log_config.yaml", output_sub_folder='tests')
main_logger = SysLogLoggerC(file_log_levels="config/cycler/log_config.yaml",
output_sub_folder='tests')
log: Logger = sys_log_logger_get_module_logger(name="test_mid_dabs")
from system_shared_tool import SysShdChanC
####################### THIRD PARTY IMPORTS #######################
Expand Down
2 changes: 1 addition & 1 deletion code/cycler/tests/test_mid_meas.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from pytest import fixture, mark
####################### SYSTEM ABSTRACTION IMPORTS #######################
from system_logger_tool import Logger, SysLogLoggerC, sys_log_logger_get_module_logger
main_logger = SysLogLoggerC(file_log_levels="devops/log_config.yaml")
main_logger = SysLogLoggerC(file_log_levels="config/cycler/log_config.yaml")
log: Logger = sys_log_logger_get_module_logger(name="test_mid_dabs")
from system_shared_tool import SysShdSharedObjC, SysShdNodeStatusE
####################### THIRD PARTY IMPORTS #######################
Expand Down
2 changes: 1 addition & 1 deletion code/cycler/tests/test_mid_pwr.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from pytest import fixture, mark
####################### SYSTEM ABSTRACTION IMPORTS #######################
from system_logger_tool import Logger, SysLogLoggerC, sys_log_logger_get_module_logger
main_logger = SysLogLoggerC(file_log_levels="devops/cycler/log_config.yaml",
main_logger = SysLogLoggerC(file_log_levels="config/cycler/log_config.yaml",
output_sub_folder='tests')
log: Logger = sys_log_logger_get_module_logger(name="test_mid_pwr")
from system_shared_tool import SysShdSharedObjC, SysShdNodeStatusE
Expand Down
2 changes: 1 addition & 1 deletion code/cycler/tests/test_mid_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
####################### SYSTEM ABSTRACTION IMPORTS #######################
from system_logger_tool import Logger, SysLogLoggerC, sys_log_logger_get_module_logger

main_logger = SysLogLoggerC(file_log_levels="devops/cycler/log_config.yaml",
main_logger = SysLogLoggerC(file_log_levels="config/cycler/log_config.yaml",
output_sub_folder='tests')
log: Logger = sys_log_logger_get_module_logger(name="test_mid_str")
from system_shared_tool import SysShdSharedObjC, SysShdChanC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def __init__(self, dev_db_id: int|None = None, manufacturer : str| None= None,
None.
"""
## Check if is initialized to none
self.is_control = False
if device_type is not None:
device_type = CyclerDataDeviceTypeE(device_type)
self.dev_db_id : int|None = dev_db_id
Expand All @@ -171,6 +172,19 @@ def __init__(self, dev_db_id: int|None = None, manufacturer : str| None= None,
self.mapping_names : Dict| None = mapping_names
self.link_conf: CyclerDataLinkConfC|None = link_configuration

def check_power_device(self) -> None:
"""
Checks if the device is a power device.
If the device type is one of the power device types (EPC, LOAD, SOURCE, BISOURCE),
sets the is_control attribute to True.
"""
list_pwr_devices: list[CyclerDataDeviceTypeE]= [CyclerDataDeviceTypeE.EPC,
CyclerDataDeviceTypeE.LOAD,
CyclerDataDeviceTypeE.SOURCE, CyclerDataDeviceTypeE.BISOURCE]
if self.device_type in list_pwr_devices:
self.is_control = True


class CyclerDataCyclerStationC:
'''
Cycler station information.
Expand Down
2 changes: 1 addition & 1 deletion code/db_sync/src/wattrex_cycler_db_sync/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

###################### CONSTANTS ######################
# For further information check out README.md
DEFAULT_CRED_FILEPATH : str = 'devops/.cred.yaml' # Max number of allowed message per chan
DEFAULT_CRED_FILEPATH : str = 'config/.cred.yaml' # Max number of allowed message per chan
DEFAULT_SYNC_NODE_NAME: str = 'SYNC'
DEFAULT_COMP_UNIT: int = 1
DEFAULT_NODE_PERIOD: int = 200 # ms # Period of the node
Expand Down
4 changes: 1 addition & 3 deletions code/db_sync/src/wattrex_cycler_db_sync/db_sync_fachade.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@

####################### SYSTEM ABSTRACTION IMPORTS #######################
path.append(os.getcwd())
from system_logger_tool import SysLogLoggerC, sys_log_logger_get_module_logger # pylint: disable=wrong-import-position
if __name__ == '__main__':
cycler_logger = SysLogLoggerC(file_log_levels='./log_config.yaml')
from system_logger_tool import sys_log_logger_get_module_logger # pylint: disable=wrong-import-position
log = sys_log_logger_get_module_logger(__name__)

####################### PROJECT IMPORTS #######################
Expand Down
Loading

0 comments on commit fcb62d4

Please sign in to comment.