########################################################################### # # Copyright (c) 2023-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 dg_proxy.py # # @author (last) Micahel Garthwaite # @date (last) 15-Aug-2023 # @author (original) Micahel Garthwaite # @date (original) 15-Aug-2023 # ############################################################################ from logging import Logger from ..common.msg_defs import MsgIds from ..protocols.CAN import DenaliMessage, DenaliChannels from ..utils.base import AbstractSubSystem from ..utils.conversions import integer_to_bytearray, float_to_bytearray from ..dg import NO_RESET, RESET class HDDGProxy(AbstractSubSystem): """ Hemodialysis Device (HD) Dialin API sub-class for DG proxy 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 def cmd_dg_send_command_response(self, cmd_id: int = 0, rejected: bool = 0, rejection_code:int = 0): """ Constructs and sends a DG command response to the HD. @param: cmd_id: The DG command ID @param: rejected: 0 for acceptance, 1 for rejection @param: rejection_code: The rejection reason. @return: none """ cmd = integer_to_bytearray(cmd_id) rej = integer_to_bytearray(rejected) rec = integer_to_bytearray(rejection_code) payload = cmd + rej + rec message = DenaliMessage.build_message(channel_id=DenaliChannels.dg_to_hd_ch_id, message_id=MsgIds.MSG_ID_DG_COMMAND_RESPONSE.value, payload=payload) self.logger.debug("Sending DG command response to the HD.") self.can_interface.send(message, 0)