########################################################################### # # Copyright (c) 2020-2025 Diality Inc. - All Rights Reserved. # # THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN # WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. # # @file fp_test_configs.py # # @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 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. """ def __init__(self, can_interface, logger: Logger): """ @param can_interface: Denali 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 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) def cmd_get_test_config_status(self, config: int): """ Returns the status of a test config @param config: (int) Test config to set @return: the status of a test config """ 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 Constraints: Must be logged into FP. @param config: (int) Test config to set @param reset: (int) 1 to reset a previous override, 0 to override @return: 1 if successful, zero otherwise """ reset_value = integer_to_bytearray(reset) c = integer_to_bytearray(config) payload = reset_value + c 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 def cmd_request_test_config_status_from_fw(self): """ Constructs and sends the FP test configs request Constraints: Must be logged into FP. @return: 1 if successful, zero otherwise """ 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) def cmd_reset_all_test_configs(self): """ Constructs and sends the FP test configs reset all Constraints: Must be logged into FP. @return: 1 if successful, zero otherwise """ 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