Index: leahi_dialin/dd/modules/dd_test_configs.py =================================================================== diff -u -rec8a2600b9e8cf6fe7e02c200a1c24221ca86863 -r0bdafdb1821e164a8416ea4b47be946f13239b5a --- leahi_dialin/dd/modules/dd_test_configs.py (.../dd_test_configs.py) (revision ec8a2600b9e8cf6fe7e02c200a1c24221ca86863) +++ leahi_dialin/dd/modules/dd_test_configs.py (.../dd_test_configs.py) (revision 0bdafdb1821e164a8416ea4b47be946f13239b5a) @@ -7,23 +7,25 @@ # # @file dd_test_configs.py # -# @author (last) Jonny Paguio -# @date (last) 20-Aug-2025 +# @author (last) Zoltan Miskolci +# @date (last) 07-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 DDTestConfigOptions -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 DDTestConfig(AbstractSubSystem): """ @@ -50,7 +52,7 @@ self.can_interface.register_receiving_publication_function(channel_id, self.msg_id_dd_send_test_config, self._handler_dd_test_config_sync) - def cmd_get_test_config_status(self, config: int): + def get_test_config_status(self, config: int): """ Returns the status of a test config @@ -59,6 +61,27 @@ """ return self.dd_test_configs[DDTestConfigOptions(config).name] + + @publish(['msg_id_dd_send_test_config', 'dd_test_configs', 'dd_test_configs_response_timestamp']) + def _handler_dd_test_config_sync(self, message, timestamp=0.0): + """ + Handles published test configuration status messages. + Triggered by: cmd_request_test_config_status_from_fw + + @param message: published DD test configurations message + @return: None + """ + payload = message['message'] + index = MsgFieldPositions.START_POS_FIELD_1 + + for config in DDTestConfigOptions.__members__: + if 'NUM_OF_TEST_CONFIGS' not in config: + config_value, index = bytearray_to_integer(payload, index, False) + self.dd_test_configs[config] = config_value + + self.dd_test_configs_response_timestamp = timestamp + + def cmd_set_test_config(self, config: int, reset: int = NO_RESET): """ Constructs and sends the DD test config @@ -73,26 +96,21 @@ c = integer_to_bytearray(config) payload = reset_value + c - message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_dd_ch_id, - message_id=MsgIds.MSG_ID_DD_SET_TEST_CONFIGURATION.value, - payload=payload) + response = cmd_generic_override( + payload = payload, + reset = reset, + channel_id = DenaliChannels.dialin_to_dd_ch_id, + msg_id = MsgIds.MSG_ID_DD_SET_TEST_CONFIGURATION, + entity_name = f'DD {DDTestConfigOptions(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(DDTestConfigOptions(config).name)) - else: - self.logger.debug("Resetting {}".format(DDTestConfigOptions(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 DD test configs request @@ -101,26 +119,18 @@ @return: 1 if successful, zero otherwise """ - message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_dd_ch_id, - message_id=MsgIds.MSG_ID_DD_GET_TEST_CONFIGURATION.value) - self.logger.debug('Getting DD 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() + return cmd_generic_override( + payload = None, + reset = NO_RESET, + channel_id = DenaliChannels.dialin_to_dd_ch_id, + msg_id = MsgIds.MSG_ID_DD_GET_TEST_CONFIGURATION, + entity_name = f'Get DD Test Configuration Record', + override_text = 'Active', + logger = self.logger, + can_interface = self.can_interface) - 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 DD 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 DD test configs reset all @@ -129,47 +139,17 @@ @return: 1 if successful, zero otherwise """ - message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_dd_ch_id, - message_id=MsgIds.MSG_ID_DD_RESET_ALL_TEST_CONFIGURATIONS.value) - self.logger.debug("Resetting all DD test configurations") + response = cmd_generic_override( + payload = None, + reset = NO_RESET, + channel_id = DenaliChannels.dialin_to_dd_ch_id, + msg_id = MsgIds.MSG_ID_DD_RESET_ALL_TEST_CONFIGURATIONS, + entity_name = f'Reset all Test Configurations', + override_text = 'Active', + logger = self.logger, + can_interface = self.can_interface) - # 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_dd_send_test_config', 'dd_test_configs', 'dd_test_configs_response_timestamp']) - def _handler_dd_test_config_sync(self, message, timestamp=0.0): - """ - Handles published test configuration status messages. - - @param message: published DD test configurations message - @return: None - """ - payload = message['message'] - index = MsgFieldPositions.START_POS_FIELD_1 - - for config in DDTestConfigOptions.__members__: - if 'NUM_OF_TEST_CONFIGS' not in config: - config_value, index = bytearray_to_integer(payload, index, False) - self.dd_test_configs[config] = config_value - - self.dd_test_configs_response_timestamp = timestamp - - def _reset_test_configs_record(self): - """ - Resets the test configuration dictionary - - @return: None - """ - for config in DDTestConfigOptions.__members__: - # Loop through the list of the test configuration and set the values to 0xFFFFFFFF - if 'NUM_OF_TEST_CONFIGS' not in config: - self.dd_test_configs[config] = 0xFFFFFFFF \ No newline at end of file + # Update the stored test configs from the FW + self.cmd_request_test_config_status_from_fw() + return response