Index: leahi_dialin/td/modules/switches.py =================================================================== diff -u -r20c821bd230fc7689a0275a2918981669ff5cc19 -re45b20cdc5d4c5dcff8cef530b173ca94cb2e422 --- leahi_dialin/td/modules/switches.py (.../switches.py) (revision 20c821bd230fc7689a0275a2918981669ff5cc19) +++ leahi_dialin/td/modules/switches.py (.../switches.py) (revision e45b20cdc5d4c5dcff8cef530b173ca94cb2e422) @@ -8,21 +8,24 @@ # @file switches.py # # @author (last) Zoltan Miskolci -# @date (last) 08-Jan-2026 +# @date (last) 05-May-2026 # @author (original) Dara Navaei # @date (original) 25-Jul-2021 # ############################################################################ -import struct +# Module imports from logging import Logger +# Project imports from leahi_dialin.common.constants import NO_RESET -from leahi_dialin.common.msg_defs import MsgIds, MsgFieldPositions +from leahi_dialin.common.generic_defs import DataTypes +from leahi_dialin.common.msg_ids import MsgIds from leahi_dialin.common.override_templates import cmd_generic_broadcast_interval_override, cmd_generic_override from leahi_dialin.common import td_enum_repository -from leahi_dialin.protocols.CAN import DenaliChannels -from leahi_dialin.utils.base import AbstractSubSystem, publish +from leahi_dialin.protocols.CAN import CanMessenger, CanChannels +from leahi_dialin.utils.abstract_classes import AbstractSubSystem +from leahi_dialin.utils.base import publish from leahi_dialin.utils.conversions import integer_to_bytearray @@ -31,7 +34,7 @@ @brief Treatment Device (TD) Dialin API sub-class for TD switches related commands. """ - def __init__(self, can_interface, logger: Logger): + def __init__(self, can_interface: CanMessenger, logger: Logger): """ TDSwitches constructor """ @@ -41,10 +44,9 @@ self.logger = logger if self.can_interface is not None: - channel_id = DenaliChannels.td_sync_broadcast_ch_id - self.msg_id_td_switches_data = MsgIds.MSG_ID_TD_SWITCHES_DATA.value - self.can_interface.register_receiving_publication_function(channel_id, self.msg_id_td_switches_data, - self._handler_switches_sync) + self.can_interface.register_receiving_publication_function(channel_id = CanChannels.td_sync_broadcast_ch_id, + message_id = MsgIds.MSG_ID_TD_SWITCHES_DATA.value, + function = self._handler_switches_sync) self.td_switches_timestamp = 0.0 #: The timestamp of the latest message @@ -60,10 +62,12 @@ @param message: published switches data message @return: none """ - front_door = struct.unpack('i', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_1:MsgFieldPositions.END_POS_FIELD_1]))[0] + sensor_list =[] + sensor_list.append((td_enum_repository.TDSwitchNames.H9_FRONT_DOOR.name, DataTypes.U32)) - self.td_switches_status[td_enum_repository.TDSwitchNames.H9_FRONT_DOOR.name] = td_enum_repository.TDSwitchStatus(front_door).value + self.process_into_dict(dict_to_update = self.td_switches_status, + decoder_list = sensor_list, + message = message) self.td_switches_timestamp = timestamp @@ -81,7 +85,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_SWITCHES_PUBLISH_INTERVAL_OVERRIDE_REQUEST, module_name = 'TD Switches', logger = self.logger, @@ -108,7 +112,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_SWITCH_STATE_OVERRIDE_REQUEST, entity_name = f'TD {switch_name} Switch status', override_text = f'{str(status)}',