Index: dialin/ui/hd_simulator.py =================================================================== diff -u -r6b32185c35ac0a95013189cc3bf77c08ed4b6a96 -r0f182516739bda0dde1e69f62d31a107d154a3fc --- dialin/ui/hd_simulator.py (.../hd_simulator.py) (revision 6b32185c35ac0a95013189cc3bf77c08ed4b6a96) +++ dialin/ui/hd_simulator.py (.../hd_simulator.py) (revision 0f182516739bda0dde1e69f62d31a107d154a3fc) @@ -15,6 +15,7 @@ ############################################################################ import enum from time import sleep +from typing import Callable from . import messageBuilder from ..common import * @@ -54,6 +55,7 @@ super().__init__() HDSimulator.instance_count = HDSimulator.instance_count + 1 + self.auto_response = auto_response self._log_manager = LogManager(log_level=log_level, log_filepath=self.__class__.__name__ + ".log") self.logger = self._log_manager.logger self.console_out = console_out @@ -103,6 +105,24 @@ # initialize variables that will be populated by UI version response self.ui_version = None + def add_publication(self, channel_id: DenaliChannels, message_id: MsgIds, function_ptr: Callable) -> None: + """ + Allows later addition of publication to the HDSimulator + @param channel_id: (DenaliChannels) the channel id of the message + @param message_id: (MsgIds) the message id + @param function_ptr: (Callable) the pointer to the message handler function + @return: None + """ + if self.auto_response: + if channel_id > 0 and message_id != MsgIds.MSG_ID_UNUSED and function_ptr is not None: + self.can_interface.register_receiving_publication_function(channel_id, + message_id, + function_ptr) + else: + self.logger.debug("rejected publication registration {0}, {1}, {2}".format(channel_id, + message_id, + function_ptr)) + def get_ui_version(self): """ Gets the ui version @@ -304,31 +324,6 @@ self.cmd_send_uf_treatment_response(1, 0, uf_volume) - def _handler_ui_first_check_in(self, message) -> None: - """ - Handler function to first check in to start the post - @param message: the check-in message - @return: None - """ - now = time.time() - # if the application is not checking-in (the simulator ) within 2 sec it means it has been stopped, - # so do the check-in again. - if now - self.checked_in_last > 5: - self.checked_in = False - - self.checked_in_last = now - - if self.checked_in: - return - - self.cmd_send_power_on_self_test_version_request() - for i in range(20): - self.cmd_send_hd_post(i, True, False) - sleep(0.1) - self.cmd_send_hd_post(0, True, True) - self.cmd_send_hd_operation_mode(4, 0) - self.checked_in = True - def _handler_ui_initiate_treatment(self, message): """ Handler function to start a treatment Index: dialin/ui/unittests.py =================================================================== diff -u -radae506afce35a0063c6c2baf7e8580986f3bee7 -r0f182516739bda0dde1e69f62d31a107d154a3fc --- dialin/ui/unittests.py (.../unittests.py) (revision adae506afce35a0063c6c2baf7e8580986f3bee7) +++ dialin/ui/unittests.py (.../unittests.py) (revision 0f182516739bda0dde1e69f62d31a107d154a3fc) @@ -14,9 +14,9 @@ # ############################################################################ -import test import sys +from squish import * from dialin.ui import crc from dialin.ui.utils import check_can0