Index: leahi_dialin/fp/modules/fp_test_configs.py =================================================================== diff -u -re27f157082335696e336c9d9952392bc62e3c8c8 -r03dc6c3ff80d7f76a5b6438ba067e02a37e2ce93 --- leahi_dialin/fp/modules/fp_test_configs.py (.../fp_test_configs.py) (revision e27f157082335696e336c9d9952392bc62e3c8c8) +++ leahi_dialin/fp/modules/fp_test_configs.py (.../fp_test_configs.py) (revision 03dc6c3ff80d7f76a5b6438ba067e02a37e2ce93) @@ -7,26 +7,26 @@ # # @file fp_test_configs.py # -# @author (last) Jonny Paguio -# @date (last) 22-Aug-2025 +# @author (last) Zoltan Miskolci +# @date (last) 08-Jan-2026 # @author (original) Jonny Paguio # @date (original) 20-Aug-2025 # ############################################################################ from logging import Logger +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.utils.conversions import integer_to_bytearray, bytearray_to_integer +from leahi_dialin.protocols.CAN import DenaliChannels from leahi_dialin.utils.base import AbstractSubSystem, publish +from leahi_dialin.utils.conversions import integer_to_bytearray, bytearray_to_integer class FPTestConfig(AbstractSubSystem): """ - FP Dialin API sub-class for setting and getting the test configurations. """ @@ -60,6 +60,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: + config_value, index = bytearray_to_integer(payload, index, False) + self.fp_test_configs[config] = 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 +93,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 = DenaliChannels.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 +116,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 = DenaliChannels.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 +135,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 + response = cmd_generic_override( + payload = None, + reset = NO_RESET, + channel_id = DenaliChannels.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