Index: leahi_dialin/fp/modules/fp_test_configs.py =================================================================== diff -u -r5c7add17cecb0528db91b9c805c95f9372dc341b -r1f2bf6d939eb4033dbedb7d7005494cc12fccbc6 --- leahi_dialin/fp/modules/fp_test_configs.py (.../fp_test_configs.py) (revision 5c7add17cecb0528db91b9c805c95f9372dc341b) +++ leahi_dialin/fp/modules/fp_test_configs.py (.../fp_test_configs.py) (revision 1f2bf6d939eb4033dbedb7d7005494cc12fccbc6) @@ -7,49 +7,50 @@ # # @file fp_test_configs.py # -# @author (last) Jonny Paguio -# @date (last) 22-Aug-2025 +# @author (last) Zoltan Miskolci +# @date (last) 05-May-2026 # @author (original) Jonny Paguio # @date (original) 20-Aug-2025 # ############################################################################ +# Module imports from logging import Logger +# Project imports +from leahi_dialin.common.constants import NO_RESET from leahi_dialin.common.msg_defs import MsgIds, MsgFieldPositions +from leahi_dialin.common.override_templates import cmd_generic_override from leahi_dialin.common.test_config_defs import DDFPTestConfigOptions -from leahi_dialin.protocols.CAN import DenaliMessage, DenaliChannels -from .constants import NO_RESET +from leahi_dialin.protocols.CAN import CanMessenger, CanChannels +from leahi_dialin.utils.abstract_classes import AbstractSubSystem +from leahi_dialin.utils.base import publish from leahi_dialin.utils.conversions import integer_to_bytearray, bytearray_to_integer -from leahi_dialin.utils.base import AbstractSubSystem, publish class FPTestConfig(AbstractSubSystem): """ - FP Dialin API sub-class for setting and getting the test configurations. """ - def __init__(self, can_interface, logger: Logger): + def __init__(self, can_interface: CanMessenger, logger: Logger): """ - - @param can_interface: Denali CAN Messenger object + @param can_interface: Can Messenger object """ super().__init__() self.can_interface = can_interface self.logger = logger - self.fp_test_configs = dict() - self.fp_test_configs_response_timestamp = 0.0 - self._reset_test_configs_record() - if self.can_interface is not None: - channel_id = DenaliChannels.fp_to_dialin_ch_id - self.msg_id_fp_send_test_config = MsgIds.MSG_ID_FP_SEND_TEST_CONFIGURATION.value - self.can_interface.register_receiving_publication_function(channel_id, self.msg_id_fp_send_test_config, - self._handler_fp_test_config_sync) + self.can_interface.register_receiving_publication_function(channel_id = CanChannels.fp_to_dialin_ch_id, + message_id = MsgIds.MSG_ID_FP_SEND_TEST_CONFIGURATION.value, + function = self._handler_fp_test_config_sync) + self.fp_test_configs_response_timestamp = 0.0 #: The timestamp of the last message + self.fp_test_configs = dict() #: The Test Config data in dictionary format + + def cmd_get_test_config_status(self, config: int): """ Returns the status of a test config @@ -60,6 +61,25 @@ return self.fp_test_configs[DDFPTestConfigOptions(config).name] + @publish(['msg_id_fp_send_test_config', 'fp_test_configs', 'fp_test_configs_response_timestamp']) + def _handler_fp_test_config_sync(self, message, timestamp=0.0): + """ + Handles published test configuration status messages. + + @param message: published FP test configurations message + @return: None + """ + payload = message['message'] + index = MsgFieldPositions.START_POS_FIELD_1 + + for config in DDFPTestConfigOptions.__members__: + if 'NUM_OF_TEST_CONFIGS' not in config.name: + config_value, index = bytearray_to_integer(payload, index, False) + self.fp_test_configs[config.name] = config_value + + self.fp_test_configs_response_timestamp = timestamp + + def cmd_set_test_config(self, config: int, reset: int = NO_RESET): """ Constructs and sends the FP test config @@ -74,26 +94,21 @@ c = integer_to_bytearray(config) payload = reset_value + c - message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_fp_ch_id, - message_id=MsgIds.MSG_ID_FP_SET_TEST_CONFIGURATION.value, - payload=payload) + response = cmd_generic_override( + payload = payload, + reset = reset, + channel_id = CanChannels.dialin_to_fp_ch_id, + msg_id = MsgIds.MSG_ID_FP_SET_TEST_CONFIGURATION, + entity_name = f'FP {DDFPTestConfigOptions(config).name} Test Config', + override_text = 'Active', + logger = self.logger, + can_interface = self.can_interface) + + # Update the stored test configs from the FW + self.cmd_request_test_config_status_from_fw() + return response - if reset == NO_RESET: - self.logger.debug("Setting {}".format(DDFPTestConfigOptions(config).name)) - else: - self.logger.debug("Resetting {}".format(DDFPTestConfigOptions(config).name)) - # Send message - received_message = self.can_interface.send(message) - - # If there is no content... - if received_message is not None: - # response payload is OK or not OK - return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] - else: - self.logger.debug("Timeout!!!!") - return False - def cmd_request_test_config_status_from_fw(self): """ Constructs and sends the FP test configs request @@ -102,26 +117,17 @@ @return: 1 if successful, zero otherwise """ - message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_fp_ch_id, - message_id=MsgIds.MSG_ID_FP_GET_TEST_CONFIGURATION.value) + return cmd_generic_override( + payload = None, + reset = NO_RESET, + channel_id = CanChannels.dialin_to_fp_ch_id, + msg_id = MsgIds.MSG_ID_FP_GET_TEST_CONFIGURATION, + entity_name = f'Get FP Test Configuration Record', + override_text = 'Active', + logger = self.logger, + can_interface = self.can_interface) - self.logger.debug('Getting FP test configuration record') - # Reset the test configs regardless of whether the message has been acknowledged or not. The reset might be out - # sync and reset the test configuration while the latest data has been received. If the test configuration is - # reset in Dialin but the message was not acknowledged, the user shall send the request again - self._reset_test_configs_record() - received_message = self.can_interface.send(message) - - # If there is content... - if received_message is not None: - self.logger.debug("Received FW ACK after requesting FP test configuration record.") - # response payload is OK or not OK - return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] - else: - self.logger.debug("Timeout!!!!") - return False - def cmd_reset_all_test_configs(self): """ Constructs and sends the FP test configs reset all @@ -130,47 +136,16 @@ @return: 1 if successful, zero otherwise """ - message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_fp_ch_id, - message_id=MsgIds.MSG_ID_FP_RESET_ALL_TEST_CONFIGURATIONS.value) - - self.logger.debug("Resetting all FP test configurations") - - # Send message - received_message = self.can_interface.send(message) - - # If there is no content... - if received_message is not None: - # response payload is OK or not OK - return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] - else: - self.logger.debug("Timeout!!!!") - return False - - @publish(['msg_id_fp_send_test_config', 'fp_test_configs', 'fp_test_configs_response_timestamp']) - def _handler_fp_test_config_sync(self, message, timestamp=0.0): - """ - Handles published test configuration status messages. - - @param message: published FP test configurations message - @return: None - """ - payload = message['message'] - index = MsgFieldPositions.START_POS_FIELD_1 - - for config in DDFPTestConfigOptions.__members__: - if 'NUM_OF_TEST_CONFIGS' not in config: - config_value, index = bytearray_to_integer(payload, index, False) - self.fp_test_configs[config] = config_value - - self.fp_test_configs_response_timestamp = timestamp - - def _reset_test_configs_record(self): - """ - Resets the test configuration dictionary - - @return: None - """ - for config in DDFPTestConfigOptions.__members__: - # Loop through the list of the test configuration and set the values to 0xFFFFFFFF - if 'NUM_OF_TEST_CONFIGS' not in config: - self.fp_test_configs[config] = 0xFFFFFFFF \ No newline at end of file + response = cmd_generic_override( + payload = None, + reset = NO_RESET, + channel_id = CanChannels.dialin_to_fp_ch_id, + msg_id = MsgIds.MSG_ID_FP_RESET_ALL_TEST_CONFIGURATIONS, + entity_name = f'Reset all DD & FP Test Configurations', + override_text = 'Active', + logger = self.logger, + can_interface = self.can_interface) + + # Update the stored test configs from the FW + self.cmd_request_test_config_status_from_fw() + return response