Index: leahi_dialin/td/treatment_delivery.py =================================================================== diff -u -r3f6c0e94db8379f00cb7fbc91daa189d6b06f379 -re45b20cdc5d4c5dcff8cef530b173ca94cb2e422 --- leahi_dialin/td/treatment_delivery.py (.../treatment_delivery.py) (revision 3f6c0e94db8379f00cb7fbc91daa189d6b06f379) +++ leahi_dialin/td/treatment_delivery.py (.../treatment_delivery.py) (revision e45b20cdc5d4c5dcff8cef530b173ca94cb2e422) @@ -8,7 +8,7 @@ # @file treatment_delivery.py # # @author (last) Zoltan Miskolci -# @date (last) 08-Jan-2026 +# @date (last) 05-May-2026 # @author (original) Peter Lucia # @date (original) 02-Apr-2020 # @@ -39,11 +39,14 @@ from .proxies.ui_proxy import UIProxy from ..common.constants import NO_RESET -from ..common.msg_defs import MsgIds, MsgFieldPositions, MsgFieldPositionsFWVersions +from ..common.msg_defs import MsgFieldPositions +from ..common.msg_ids import MsgIds from ..common import td_enum_repository +from ..common.generic_defs import DataTypes from ..common.override_templates import cmd_generic_broadcast_interval_override, cmd_generic_override -from ..protocols.CAN import DenaliMessage, DenaliCanMessenger, DenaliChannels -from ..utils.base import AbstractSubSystem, publish, LogManager +from ..protocols.CAN import CanMessage, CanMessenger, CanChannels +from ..utils.abstract_classes import AbstractSubSystem +from ..utils.base import publish, LogManager from ..utils.conversions import integer_to_bytearray, bytearray_to_byte @@ -78,31 +81,28 @@ self.logger = self._log_manager.logger # Create listener - self.can_interface = DenaliCanMessenger(can_interface=can_interface, + self.can_interface = CanMessenger(can_interface=can_interface, logger=self.logger) self.can_interface.start() self.callback_id = None # register handler for TD operation mode broadcast messages if self.can_interface is not None: - channel_id = DenaliChannels.td_sync_broadcast_ch_id - self.msg_id_td_op_mode_data = MsgIds.MSG_ID_TD_OP_MODE_DATA.value - self.can_interface.register_receiving_publication_function(channel_id, self.msg_id_td_op_mode_data, - self._handler_td_op_mode_sync) + self.can_interface.register_receiving_publication_function(channel_id = CanChannels.td_sync_broadcast_ch_id, + message_id = MsgIds.MSG_ID_TD_OP_MODE_DATA.value, + function = self._handler_td_op_mode_sync) - self.msg_id_td_debug_event = MsgIds.MSG_ID_TD_DEBUG_EVENT.value - self.can_interface.register_receiving_publication_function(channel_id, - self.msg_id_td_debug_event, - self._handler_td_debug_event_sync) + self.can_interface.register_receiving_publication_function(channel_id = CanChannels.td_sync_broadcast_ch_id, + message_id = MsgIds.MSG_ID_TD_DEBUG_EVENT.value, + function = self._handler_td_debug_event_sync) - self.msg_id_td_version_response = MsgIds.MSG_ID_TD_VERSION_RESPONSE.value - self.can_interface.register_receiving_publication_function(channel_id, - self.msg_id_td_version_response, - self._handler_td_version_response_sync) + self.can_interface.register_receiving_publication_function(channel_id = CanChannels.td_sync_broadcast_ch_id, + message_id = MsgIds.MSG_ID_TD_VERSION_RESPONSE.value, + function = self._handler_td_version_response_sync) - self.msg_id_ui_version_info_response = MsgIds.MSG_ID_UI_VERSION_INFO_RESPONSE.value - self.can_interface.register_receiving_publication_function(DenaliChannels.ui_to_td_ch_id, - self.msg_id_ui_version_info_response, - self._handler_ui_version_response_sync) + self.can_interface.register_receiving_publication_function(channel_id = CanChannels.td_sync_broadcast_ch_id, + message_id = MsgIds.MSG_ID_UI_VERSION_INFO_RESPONSE.value, + function = self._handler_ui_version_response_sync) + # Dialin will send a login message during construction. This is for the leahi subsystems to start # publishing CAN data when there is no UI connected as the UI typically does this job. self.cmd_log_in_to_td() @@ -187,13 +187,12 @@ @param message: published TD operation mode broadcast message @return: None """ - mode = struct.unpack('i', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_1:MsgFieldPositions.END_POS_FIELD_1])) - smode = struct.unpack('i', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_2:MsgFieldPositions.END_POS_FIELD_2])) + msg_list = [] + msg_list.append(('self.td_operation_mode', DataTypes.U32)) + msg_list.append(('self.td_operation_sub_mode', DataTypes.U32)) - self.td_operation_mode = mode[0] - self.td_operation_sub_mode = smode[0] + self.process_into_vars(decoder_list = msg_list, + message = message) self.td_op_mode_timestamp = timestamp @@ -206,33 +205,28 @@ @return: None if not successful, the version string if unpacked successfully """ - major = struct.unpack(' 0 for each in [major, minor, micro, build, compatibility]]): - self.td_version = f"v{major[0]}.{minor[0]}.{micro[0]}-{build[0]}.{compatibility[0]}" - self.logger.debug(f"TD VERSION: {self.td_version}") + result = self.process_into_vars(decoder_list = msg_list, + message = message) - if all([len(each) > 0 for each in [fpga_id, fpga_major, fpga_minor, fpga_lab]]): - self.td_fpga_version = f"v{fpga_id[0]}.{fpga_major[0]}.{fpga_minor[0]}-{fpga_lab[0]}" - self.logger.debug(f"TD FPGA VERSION: {self.td_fpga_version}") + if all([len(each) > 0 for each in [result['major'], result['minor'], result['micro'], result['build'], result['compatibility']]]): + self.td_version = f"v{result['major']}.{result['minor']}.{result['micro']}-{result['build']}.{result['compatibility']}" + self.logger.debug(f'TD VERSION: {self.td_version}') + if all([len(each) > 0 for each in [result['fpga_id'], result['fpga_major'], result['fpga_minor'], result['fpga_lab']]]): + self.td_fpga_version = f"v{result['fpga_id']}.{result['fpga_major']}.{result['fpga_minor']}-{result['fpga_lab']}" + self.logger.debug(f'TD FPGA VERSION: {self.td_fpga_version}') + self.td_version_response_timestamp = timestamp @@ -250,28 +244,24 @@ @return: None if not successful, the version string if unpacked successfully """ - major = struct.unpack(' 0 for each in [major, minor, micro, build, compatibility]]): - self.ui_version = f"v{major[0]}.{minor[0]}.{micro[0]}-{build[0]}.{compatibility[0]}" - self.logger.debug(f"UI VERSION: {self.ui_version}") - + if all([len(each) > 0 for each in [result['major'], result['minor'], result['micro'], result['build'], result['compatibility']]]): + self.ui_version = f"v{result['major']}.{result['minor']}.{result['micro']}-{result['build']}.{result['compatibility']}" + self.logger.debug(f'UI VERSION: {self.ui_version}') else: self.ui_version = None self.logger.debug("Failed to retrieve UI Version.") + self.ui_version_info_response_timestamp = timestamp - def cmd_op_mode_broadcast_interval_override(self, ms: int, reset: int = NO_RESET) -> int: """ Constructs and sends the measured op mode broadcast interval override command @@ -286,7 +276,7 @@ return cmd_generic_broadcast_interval_override( ms = ms, reset = reset, - channel_id = DenaliChannels.dialin_to_td_ch_id, + channel_id = CanChannels.dialin_to_td_ch_id, msg_id = MsgIds.MSG_ID_TD_OP_MODE_PUBLISH_INTERVAL_OVERRIDE_REQUEST, module_name = 'TD Operation Mode', logger = self.logger, @@ -301,7 +291,7 @@ @param resend: (bool) if False (default), try to login once. Otherwise, tries to login indefinitely @return: 1 if logged in, 0 if log in failed """ - message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_td_ch_id, + message = CanMessage.build_message(channel_id=CanChannels.dialin_to_td_ch_id, message_id=MsgIds.MSG_ID_TD_TESTER_LOGIN_REQUEST.value, payload=list(map(int, map(ord, self.TD_LOGIN_PASSWORD)))) @@ -311,14 +301,14 @@ received_message = self.can_interface.send(message, resend=resend) if received_message is not None: - if received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] == 1: + if received_message['message'][CanMessage.PAYLOAD_START_INDEX] == 1: self.logger.debug("Success: Logged In") self.td_set_logged_in_status(True) #self._send_td_checkin_message() # Timer starts interval first #self.can_interface.transmit_interval_dictionary[self.callback_id].start() else: self.logger.debug("Failure: Log In Failed.") - return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] + return received_message['message'][CanMessage.PAYLOAD_START_INDEX] else: self.logger.debug("Login Timeout!!!!") return False @@ -349,7 +339,7 @@ return cmd_generic_override( payload = payload, reset = NO_RESET, - channel_id = DenaliChannels.dialin_to_td_ch_id, + channel_id = CanChannels.dialin_to_td_ch_id, msg_id = MsgIds.MSG_ID_TD_OP_MODE_OVERRIDE_REQUEST, entity_name = 'TD Operation Mode', override_text = td_enum_repository.TDOpModes(new_mode).name, @@ -368,7 +358,7 @@ resp = cmd_generic_override( payload = None, reset = NO_RESET, - channel_id = DenaliChannels.dialin_to_td_ch_id, + channel_id = CanChannels.dialin_to_td_ch_id, msg_id = MsgIds.MSG_ID_TD_SOFTWARE_RESET_REQUEST, entity_name = 'TD Software Reset', override_text = '', @@ -397,7 +387,7 @@ return cmd_generic_override( payload = payload, reset = NO_RESET, - channel_id = DenaliChannels.dialin_to_td_ch_id, + channel_id = CanChannels.dialin_to_td_ch_id, msg_id = MsgIds.MSG_ID_TD_SAFETY_SHUTDOWN_OVERRIDE_REQUEST, entity_name = 'TD Safety Shutdown', override_text = str(active), @@ -411,7 +401,7 @@ @return: none """ - message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_td_ch_id, + message = CanMessage.build_message(channel_id=CanChannels.dialin_to_td_ch_id, message_id=MsgIds.MSG_ID_TD_UI_VERSION_INFO_REQUEST.value) self.logger.debug("Sending an UI version request to the TD.") @@ -433,7 +423,7 @@ return cmd_generic_override( payload = payload, reset = reset, - channel_id = DenaliChannels.dialin_to_td_ch_id, + channel_id = CanChannels.dialin_to_td_ch_id, msg_id = MsgIds.MSG_ID_TD_TRAINING_TEST_OVERRIDE_REQUEST, entity_name = 'TD Training Test Override', override_text = str(value),