Index: dialin/ui/hd_simulator.py =================================================================== diff -u -rf990c9bb863683c74bbe78c71932a14d7cf35422 -r035e26e44bdb1ba5afa5c9a147941b9f91731ce7 --- dialin/ui/hd_simulator.py (.../hd_simulator.py) (revision f990c9bb863683c74bbe78c71932a14d7cf35422) +++ dialin/ui/hd_simulator.py (.../hd_simulator.py) (revision 035e26e44bdb1ba5afa5c9a147941b9f91731ce7) @@ -30,6 +30,18 @@ NUM_TREATMENT_PARAMETERS = 18 instanceCount = 0 + # UI version message field positions + START_POS_MAJOR = DenaliMessage.PAYLOAD_START_INDEX + END_POS_MAJOR = START_POS_MAJOR + 1 + START_POS_MINOR = END_POS_MAJOR + END_POS_MINOR = START_POS_MINOR + 1 + START_POS_MICRO = END_POS_MINOR + END_POS_MICRO = START_POS_MICRO + 1 + START_POS_BUILD = END_POS_MICRO + END_POS_BUILD = START_POS_BUILD + 2 + START_POS_COMPAT = END_POS_BUILD + END_POS_COMPAT = START_POS_COMPAT + 4 + def __init__(self, can_interface: str = "can0", log_level: bool = None, console_out: bool = False, @@ -83,10 +95,25 @@ self.can_interface.register_receiving_publication_function(DenaliChannels.ui_to_hd_ch_id, MsgIdsDialin.MSG_DIALIN_ID_UI_POST_REPORT_VERSION.value, self._handler_ui_post_ui_version_compatibility) + self.can_interface.register_receiving_publication_function(DenaliChannels.ui_to_hd_ch_id, + MsgIds.MSG_ID_HD_UI_VERSION_INFO_RESPONSE.value, + self._handler_ui_version) + self.alarms_simulator = HDAlarmsSimulator(self.can_interface, self.logger) self.treatment_parameter_rejections = TreatmentParameterRejections() + # initialize variables that will be populated by UI version response + self.ui_version = None + + def get_ui_version(self): + """ + Gets the ui version + + @return: The ui version + """ + return self.ui_version + def cmd_send_hd_post_single_result(self, result: int, test_num: int) -> None: """ Reports a single result for power on self test @@ -1857,6 +1884,40 @@ self.can_interface.send(message, 0) + @publish(["ui_version"]) + def _handler_ui_version(self, message) -> None: + """ + Handles the ui version response + @param message: The ui version response message + @return: None + """ + major = struct.unpack('B', bytearray( + message['message'][self.START_POS_MAJOR:self.END_POS_MAJOR])) + minor = struct.unpack('B', bytearray( + message['message'][self.START_POS_MINOR:self.END_POS_MINOR])) + micro = struct.unpack('B', bytearray( + message['message'][self.START_POS_MICRO:self.END_POS_MICRO])) + build = struct.unpack('H', bytearray( + message['message'][self.START_POS_BUILD:self.END_POS_BUILD])) + compatibility = struct.unpack('H', bytearray( + message['message'][self.START_POS_COMPAT:self.END_POS_COMPAT])) + + if all([len(each) > 0 for each in [major, minor, micro, build]]): + self.ui_version = f"v{major[0]}.{minor[0]}.{micro[0]}-{build[0]}-{compatibility[0]}" + self.logger.debug(f"UI VERSION: {self.ui_version}") + + def cmd_send_hd_request_ui_version(self) -> None: + """ + the HD response to the UI sending the user chimical disinfection steps confirm. + + @return: None + """ + message = DenaliMessage.build_message(channel_id=DenaliChannels.hd_to_ui_ch_id, + message_id=MsgIds.MSG_ID_HD_UI_VERSION_INFO_REQUEST.value, + payload=None) + + self.can_interface.send(message, 0) + # ------------------------------------------------ GENERAL MESSAGES ------------------------------------------------ def cmd_send_general_hd_response(self, message_id: int, accepted: int, reason: int,