Index: HemodialysisDevice.py =================================================================== diff -u -r9b0bd2dc63cb1bde596c194193119c5ed4fa8597 -r18637d43f1065ccc49a4cc67cfcf440874794cee --- HemodialysisDevice.py (.../HemodialysisDevice.py) (revision 9b0bd2dc63cb1bde596c194193119c5ed4fa8597) +++ HemodialysisDevice.py (.../HemodialysisDevice.py) (revision 18637d43f1065ccc49a4cc67cfcf440874794cee) @@ -256,6 +256,8 @@ MSG_ID_UF_SETTINGS_CHANGE_RESPONSE_FROM_HD = 0x0013 MSG_ID_UF_SETTINGS_CHANGE_CONFIRMED_BY_USER = 0x0015 MSG_ID_TREATMENT_DURATION_SETTING_CHANGE_REQUEST = 0x0016 + MSG_ID_BLOOD_DIALYSATE_FLOW_SETTING_CHANGE_REQUEST_BY_USER = 0x0017 + MSG_ID_BLOOD_DIALYSATE_FLOW_SETTING_CHANGE_RESPONSE_FROM_HD = 0x0018 LITER_TO_ML_CONVERSION_FACTOR = 1000.0 UF_CMD_PAUSE = 0 @@ -279,6 +281,16 @@ START_POS_UF_CHG_RSP_RATE_DIFF = END_POS_UF_CHG_RSP_TIME_DIFF END_POS_UF_CHG_RSP_RATE_DIFF = START_POS_UF_CHG_RSP_RATE_DIFF + 4 + # HD response to blood/dialysate flow change request message field positions + START_POS_BLD_DIAL_CHG_RSP_ACCEPTED = DenaliMessage.PAYLOAD_START_INDEX + END_POS_BLD_DIAL_CHG_RSP_ACCEPTED = START_POS_BLD_DIAL_CHG_RSP_ACCEPTED + 4 + START_POS_BLD_DIAL_CHG_RSP_REASON = END_POS_BLD_DIAL_CHG_RSP_ACCEPTED + END_POS_BLD_DIAL_CHG_RSP_REASON = START_POS_BLD_DIAL_CHG_RSP_REASON + 4 + START_POS_BLD_DIAL_CHG_RSP_BLD_RATE = END_POS_BLD_DIAL_CHG_RSP_REASON + END_POS_BLD_DIAL_CHG_RSP_BLD_RATE = START_POS_BLD_DIAL_CHG_RSP_BLD_RATE + 4 + START_POS_BLD_DIAL_CHG_RSP_DIAL_RATE = END_POS_BLD_DIAL_CHG_RSP_BLD_RATE + END_POS_BLD_DIAL_CHG_RSP_DIAL_RATE = START_POS_BLD_DIAL_CHG_RSP_DIAL_RATE + 4 + def __init__(self, outer_instance, can_interface=None): self.outer_instance = outer_instance """ @@ -293,17 +305,54 @@ # register function to handle HD response to UF change requests if can_interface is not None: channel_id = DenaliChannels.hd_to_ui_ch_id - msg_id = self.MSG_ID_UF_SETTINGS_CHANGE_RESPONSE_FROM_HD - can_interface.registerReceivingPublicationFunction(channel_id, msg_id, + can_interface.registerReceivingPublicationFunction(channel_id, self.MSG_ID_UF_SETTINGS_CHANGE_RESPONSE_FROM_HD, self.handlerUFChangeResponseFunction) + can_interface.registerReceivingPublicationFunction(channel_id, self.MSG_ID_BLOOD_DIALYSATE_FLOW_SETTING_CHANGE_RESPONSE_FROM_HD, + self.handlerBloodAndDialysateChangeResponseFunction) + # initialize variables that will be populated by response from HD to UF change request - self.UFChangeResponse = False + self.UFChangeSucceeded = False self.UFChangeVolumeMl = 0 self.UFChangeTimeMin = 0 self.UFChangeRateMlMin = 0.0 self.UFChangeTimeDiff = 0 self.UFChangeRateDiff = 0.0 + # initialize variables that will be populated by response from HD to blood & dialysate flow rate change request + self.TargetBloodFlowRate = 0 + self.TargetDialysateFlowRate = 0 + self.BloodAndDialysateFlowRateChangeSucceeded = False + self.BloodAndDialysateFlowRateChangeRejectReason = 0 + def handlerBloodAndDialysateChangeResponseFunction(self, message): + """ + Handler for response from HD regarding blood & dialysate flow rate change request. + + \param message: response message from HD regarding requested blood & dialysate flow rate settings change.\n + BOOL Accepted \n + U32 UF Volume (mL) - converted to Liters \n + U32 Treatment Time (min) \n + U32 UF Rate (mL/min) \n + + \returns none + """ + rsp = struct.unpack('i',bytearray( + message['message'][self.START_POS_BLD_DIAL_CHG_RSP_ACCEPTED:self.END_POS_BLD_DIAL_CHG_RSP_ACCEPTED])) + rea = struct.unpack('i',bytearray( + message['message'][self.START_POS_BLD_DIAL_CHG_RSP_REASON:self.END_POS_BLD_DIAL_CHG_RSP_REASON])) + bld = struct.unpack('i',bytearray( + message['message'][self.START_POS_BLD_DIAL_CHG_RSP_BLD_RATE:self.END_POS_BLD_DIAL_CHG_RSP_BLD_RATE])) + dil = struct.unpack('i',bytearray( + message['message'][self.START_POS_BLD_DIAL_CHG_RSP_DIAL_RATE:self.END_POS_BLD_DIAL_CHG_RSP_DIAL_RATE])) + + if rsp[0] == self.RESPONSE_REJECTED: + resp = False + else: + resp = True + self.BloodAndDialysateFlowRateChangeSucceeded = resp + self.BloodAndDialysateFlowRateChangeRejectReason = rea[0] + self.TargetBloodFlowRate = bld[0] / self.LITER_TO_ML_CONVERSION_FACTOR + self.TargetDialysateFlowRate = dil[0] + def handlerUFChangeResponseFunction(self, message): """ Handler for response from HD regarding UF change request. @@ -335,7 +384,7 @@ resp = False else: resp = True - self.UFChangeResponse = resp + self.UFChangeSucceeded = resp self.UFChangeVolumeL = vol[0] / self.LITER_TO_ML_CONVERSION_FACTOR self.UFChangeTimeMin = tim[0] self.UFChangeRateMlMin = rat[0] @@ -462,6 +511,30 @@ return 0 + def CmdUIBloodAndDialysateFlowSettingsChangeRequest(self, bloodFlow, dialFlow): + """ + Constructs and sends a UI blood & dialysate flow settings change request by user message + + \param bloodFlow (int): blood flow rate set point (in mL/min). + \param dialFlow (int): dialysate flow rate set point (in mL/min). + + \returns none + """ + + bld = self.outer_instance.integer2ByteArray(bloodFlow) + dial = self.outer_instance.integer2ByteArray(dialFlow) + payload = bld + dial + message = DenaliMessage.buildMessage(channel_id=DenaliChannels.dialin_to_hd_ch_id, + message_id=self.MSG_ID_BLOOD_DIALYSATE_FLOW_SETTING_CHANGE_REQUEST_BY_USER, + payload=payload) + + print("Sending blood & dialysate flow rate settings change request.") + + # Send message + received_message = self.outer_instance.can_interface.send(message, 0) + + return 0 + class HD_Watchdog: """ \class HD_Watchdog