########################################################################### # # Copyright (c) 2020-2024 Diality Inc. - All Rights Reserved. # # THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN # WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. # # @file post_gen_dialysate.py # # @author (last) Zoltan Miskolci # @date (last) 07-Jan-2026 # @author (original) Micahel Garthwaite # @date (original) 29-Oct-2020 # ############################################################################ import struct from logging import Logger from leahi_dialin.common.constants import NO_RESET from leahi_dialin.common.msg_defs import MsgIds, MsgFieldPositions from leahi_dialin.common.override_templates import cmd_generic_broadcast_interval_override from leahi_dialin.protocols.CAN import DenaliChannels from leahi_dialin.utils.base import AbstractSubSystem, publish class DDPostGenDialysate(AbstractSubSystem): """ Post Gen Dialysate Dialysate Delivery (DD) Dialin API sub-class for post gen dialysate related commands. """ def __init__(self, can_interface, logger: Logger): """ @param can_interface: Leahi 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 self.msg_id_dd_post_gen_dialysate_state_data = MsgIds.MSG_ID_DD_POST_GEN_DIALYSATE_STATE_DATA.value self.can_interface.register_receiving_publication_function(channel_id, self.msg_id_dd_post_gen_dialysate_state_data, self._handler_post_gen_dialysate_sync) self.execution_state = 0 self.post_gen_state_timestamp = 0 @publish(["msg_id_dd_post_gen_dialysate_state_data", "execution_state", "post_gen_state_timestamp"]) def _handler_post_gen_dialysate_sync(self, message, timestamp=0.0): """ Handles published post gen dialysate data messages. @param message: published post gen dialysate data message @return: None """ self.execution_state = struct.unpack('I', bytearray( message['message'][MsgFieldPositions.START_POS_FIELD_1:MsgFieldPositions.END_POS_FIELD_1]))[0] self.post_gen_state_timestamp = timestamp def cmd_post_gen_broadcast_interval_override(self, ms: int, reset: int = NO_RESET) -> int: """ Constructs and sends the broadcast time interval override for post gen dialysate data. Constraints: Must be logged into DD. Given interval must be non-zero and a multiple of the DD general task interval (50 ms). @param ms: (int) Publish time interval in ms @param reset: (int) 1 to reset a previous override, 0 to override @returns 1 if successful, zero otherwise """ return cmd_generic_broadcast_interval_override( ms = ms, reset = reset, channel_id = DenaliChannels.dialin_to_dd_ch_id, msg_id = MsgIds.MSG_ID_DD_POST_GEND_MODE_DATA_PUBLISH_OVERRIDE_REQUEST, module_name = 'DD Post-Gen Dialysate', logger = self.logger, can_interface = self.can_interface)