########################################################################### # # Copyright (c) 2019-2020 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 Treatment.py # # @date 31-Mar-2020 # @author P. Lucia # # @brief # # ############################################################################ from DialIn.CoreCANProtocol import (DenaliMessage, DenaliChannels) import struct class HDTreatment: """ \class HD_Treatment \brief Hemodialysis Device (HD) Dialin API sub-class for treatment related commands. """ # Treatment message IDs MSG_ID_HD_TREATMENT_TIME_PUBLISHED_DATA = 0x000D MSG_ID_HD_TREATMENT_STATE_PUBLISHED_DATA = 0X000F # Treatment time broadcast message field positions START_POS_TIME_PRES = DenaliMessage.PAYLOAD_START_INDEX END_POS_TIME_PRES = START_POS_TIME_PRES + 4 START_POS_TIME_ELAPSED = END_POS_TIME_PRES END_POS_TIME_ELAPSED = START_POS_TIME_ELAPSED + 4 START_POS_TIME_REMAINING = END_POS_TIME_ELAPSED END_POS_TIME_REMAINING = START_POS_TIME_REMAINING + 4 # Treatment state broadcast message field positions START_POS_TREATMENT_STATE = DenaliMessage.PAYLOAD_START_INDEX END_POS_TREATMENT_STATE = START_POS_TREATMENT_STATE + 4 START_POS_UF_STATE = END_POS_TREATMENT_STATE END_POS_UF_STATE = START_POS_UF_STATE + 4 START_POS_SALINE_BOLUS_IN_PROGRESS = END_POS_UF_STATE END_POS_SALINE_BOLUS_IN_PROGRESS = START_POS_SALINE_BOLUS_IN_PROGRESS + 4 def __init__(self, can_interface=None): """ HD_Treatment constructor """ self.can_interface = can_interface if self.can_interface is not None: channel_id = DenaliChannels.hd_sync_broadcast_ch_id msg_id = self.MSG_ID_HD_TREATMENT_TIME_PUBLISHED_DATA self.can_interface.register_receiving_publication_function(channel_id, msg_id, self.handlerTreatmentTimeSyncFunction) msg_id = self.MSG_ID_HD_TREATMENT_STATE_PUBLISHED_DATA self.can_interface.register_receiving_publication_function(channel_id, msg_id, self.handlerTreatmentStateSyncFunction) self.TreatmentTimePrescribed = 0 self.TreatmentTimeElapsed = 0 self.TreatmentTimeRemaining = 0 self.TreatmentState = 0 self.TreatmentUFState = 0 self.SalineBolusInProgress = False def handlerTreatmentTimeSyncFunction(self, message): """ Handles published treatment time data messages. Treatment time data are captured for reference. \param message: published treatment time data message \returns none """ tot = struct.unpack('i', bytearray( message['message'][self.START_POS_TIME_PRES:self.END_POS_TIME_PRES])) ela = struct.unpack('i', bytearray( message['message'][self.START_POS_TIME_ELAPSED:self.END_POS_TIME_ELAPSED])) rem = struct.unpack('i', bytearray( message['message'][self.START_POS_TIME_REMAINING:self.END_POS_TIME_REMAINING])) self.TreatmentTimePrescribed = tot[0] self.TreatmentTimeElapsed = ela[0] self.TreatmentTimeRemaining = rem[0] def handlerTreatmentStateSyncFunction(self, message): """ Handles published treatment state data messages. Treatment state data are captured for reference. \param message: published treatment state data message \returns none """ tst = struct.unpack('i', bytearray( message['message'][self.START_POS_TREATMENT_STATE:self.END_POS_TREATMENT_STATE])) ufs = struct.unpack('i', bytearray( message['message'][self.START_POS_UF_STATE:self.END_POS_UF_STATE])) bol = struct.unpack('i', bytearray( message['message'][self.START_POS_SALINE_BOLUS_IN_PROGRESS:self.END_POS_SALINE_BOLUS_IN_PROGRESS])) self.TreatmentState = tst[0] self.TreatmentUFState = ufs[0] if bol[0] == 1: self.SalineBolusInProgress = True else: self.SalineBolusInProgress = False