Index: leahi_dialin/dd/modules/spent_chamber_fill.py =================================================================== diff -u -r1d437b93d4547966c5f4d0352b7e4eb74ff58547 -r1f2bf6d939eb4033dbedb7d7005494cc12fccbc6 --- leahi_dialin/dd/modules/spent_chamber_fill.py (.../spent_chamber_fill.py) (revision 1d437b93d4547966c5f4d0352b7e4eb74ff58547) +++ leahi_dialin/dd/modules/spent_chamber_fill.py (.../spent_chamber_fill.py) (revision 1f2bf6d939eb4033dbedb7d7005494cc12fccbc6) @@ -7,69 +7,74 @@ # # @file spent_chamber_fill.py # -# @author (last) Jonny Paguio -# @date (last) 26-Aug-2025 +# @author (last) Zoltan Miskolci +# @date (last) 04-May-2026 # @author (original) Jonny Paguio # @date (original) 26-Aug-2025 # ############################################################################ -import struct + +# Module imports from logging import Logger -from .constants import RESET, NO_RESET -from leahi_dialin.common.msg_defs import MsgIds, MsgFieldPositions -from leahi_dialin.protocols.CAN import DenaliMessage, DenaliChannels -from leahi_dialin.utils.base import AbstractSubSystem, publish, DialinEnum -from leahi_dialin.utils.checks import check_broadcast_interval_override_ms -from leahi_dialin.utils.conversions import integer_to_bytearray, float_to_bytearray +# Project imports +from leahi_dialin.common.constants import NO_RESET +from leahi_dialin.common.generic_defs import DataTypes +from leahi_dialin.common.msg_defs import MsgIds +from leahi_dialin.common.override_templates import cmd_generic_broadcast_interval_override +from leahi_dialin.protocols.CAN import CanMessenger, CanChannels +from leahi_dialin.utils.abstract_classes import AbstractSubSystem +from leahi_dialin.utils.base import publish + class DDSpentChamberFill(AbstractSubSystem): """ Spent Chamber Fill Dialysate Delivery (DD) Dialin API sub-class for Spent Chamber Fill related commands. """ - def __init__(self, can_interface, logger: Logger): + def __init__(self, can_interface: CanMessenger, logger: Logger): """ - @param can_interface: Denali Can Messenger object + @param can_interface: Can Messenger object """ super().__init__() self.can_interface = can_interface self.logger = logger if self.can_interface is not None: - channel_id = DenaliChannels.dd_sync_broadcast_ch_id - msg_id = MsgIds.MSG_ID_DD_SPENT_CHAMBER_FILL_DATA.value - self.can_interface.register_receiving_publication_function(channel_id, msg_id, - self._handler_spent_chamber_fill_sync) + self.can_interface.register_receiving_publication_function(channel_id = CanChannels.dd_sync_broadcast_ch_id, + message_id = MsgIds.MSG_ID_DD_SPENT_CHAMBER_FILL_DATA.value, + function = self._handler_spent_chamber_fill_sync) - self.execution_state = 0 - self.switching_period = 0 - self.total_spent_chamber_fill_counter = 0 - self.dd_spent_chamber_timestamp = 0 + self.dd_spent_chamber_timestamp = 0 #: The timestamp of the latest message + self.execution_state = 0 #: The execution state + self.switching_period = 0 #: The switching period + self.total_spent_chamber_fill_counter = 0 #: The total spent chamber fill counter - @publish(["dd_spent_chamber_timestamp", + + @publish(["msg_id_dd_spent_chamber_fill_data", "execution_state", "switching_period", - "total_spent_chamber_fill_counter"]) + "total_spent_chamber_fill_counter", + "dd_spent_chamber_timestamp",]) def _handler_spent_chamber_fill_sync(self, message, timestamp=0.0): """ Handles published spent chamber fill data messages. @param message: published spent chamber fill data message @return: None """ + msg_list =[] + msg_list.append(('self.execution_state', DataTypes.U32)) + msg_list.append(('self.switching_period', DataTypes.U32)) + msg_list.append(('self.total_spent_chamber_fill_counter', DataTypes.U32)) - self.execution_state = struct.unpack('I', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_1:MsgFieldPositions.END_POS_FIELD_1]))[0] - self.switching_period = struct.unpack('I', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_2:MsgFieldPositions.END_POS_FIELD_2]))[0] - self.total_spent_chamber_fill_counter = struct.unpack('I', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_3:MsgFieldPositions.END_POS_FIELD_3]))[0] - + self.process_into_vars(decoder_list = msg_list, + message = message) self.dd_spent_chamber_timestamp = timestamp + def cmd_spent_chamber_fill_broadcast_interval_override(self, ms: int, reset: int = NO_RESET) -> int: """ Constructs and sends the spent chamber fill data broadcast interval override command @@ -81,27 +86,11 @@ @param reset: integer - 1 to reset a previous override, 0 to override @return: 1 if successful, zero otherwise """ - - if not check_broadcast_interval_override_ms(ms): - return False - - reset_byte_array = integer_to_bytearray(reset) - ms_byte_array = integer_to_bytearray(ms) - payload = reset_byte_array + ms_byte_array - - message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_dd_ch_id, - message_id=MsgIds.MSG_ID_DD_SPENT_CHAMB_FILL_DATA_PUBLISH_OVERRIDE_REQUEST.value, - payload=payload) - - self.logger.debug("override DD Spent Chamber Fill data broadcast interval") - - # Send message - received_message = self.can_interface.send(message) - - # If there is content... - if received_message is not None: - # response payload is OK or not OK - return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] - else: - self.logger.error("Timeout!!!!") - return False \ No newline at end of file + return cmd_generic_broadcast_interval_override( + ms = ms, + reset = reset, + channel_id = CanChannels.dialin_to_dd_ch_id, + msg_id = MsgIds.MSG_ID_DD_SPENT_CHAMB_FILL_DATA_PUBLISH_OVERRIDE_REQUEST, + module_name = 'DD Spent Chamber Fill', + logger = self.logger, + can_interface = self.can_interface)