########################################################################### # # 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) Micahel Garthwaite # @date (last) 07-Mar-2023 # @author (original) Micahel Garthwaite # @date (original) 29-Oct-2020 # ############################################################################ import struct from enum import unique 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 class DDGenDialysate(AbstractSubSystem): """ Gen Dialysate Dialysate Delivery (DD) Dialin API sub-class for gen dialysate related commands. """ def __init__(self, can_interface, logger: Logger): """ @param can_interface: Denali 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_POST_GEN_DIALYSATE_STATE_DATA.value self.can_interface.register_receiving_publication_function(channel_id, msg_id, self._handler_post_gen_dialysate_sync) self.execution_state = 0 self.post_gen_state_timestamp = 0 def _handler_post_gen_dialysate_sync(self, message, timestamp=0.0): """ Handles published gen dialysate data messages. @param message: published 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] post_gen_state_timestamp = timestamp