Index: dialin/ui/hd_simulator.py =================================================================== diff -u -r9f86c313a673e05e82c6b82fc8b6d60c78a94f67 -r37713699423a2fb9343fca8f1fdf2ccdfe50a16d --- dialin/ui/hd_simulator.py (.../hd_simulator.py) (revision 9f86c313a673e05e82c6b82fc8b6d60c78a94f67) +++ dialin/ui/hd_simulator.py (.../hd_simulator.py) (revision 37713699423a2fb9343fca8f1fdf2ccdfe50a16d) @@ -15,6 +15,7 @@ ############################################################################ import enum from time import sleep +from typing import Callable from . import messageBuilder from ..common import * @@ -54,8 +55,7 @@ super().__init__() HDSimulator.instance_count = HDSimulator.instance_count + 1 - self.checked_in = False - self.checked_in_last = 0 + 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 @@ -109,6 +109,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 @@ -310,31 +328,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 @@ -1328,6 +1321,7 @@ payload = float_to_bytearray(target) payload += float_to_bytearray(current) + payload += float_to_bytearray(0) message = DenaliMessage.build_message(channel_id=DenaliChannels.hd_to_ui_ch_id, message_id=MsgIds.MSG_ID_HD_BLOOD_PRIME_PROGRESS.value,