Index: dialin/ui/hd_simulator.py =================================================================== diff -u -rbe49f73b02ba10623fe07bfc8b6b310d37cac80b -r4fca777195e169106c4e032b11a7771727f4c6e5 --- dialin/ui/hd_simulator.py (.../hd_simulator.py) (revision be49f73b02ba10623fe07bfc8b6b310d37cac80b) +++ dialin/ui/hd_simulator.py (.../hd_simulator.py) (revision 4fca777195e169106c4e032b11a7771727f4c6e5) @@ -28,7 +28,8 @@ DenaliCanMessenger, DenaliChannels) from ..utils.base import _AbstractSubSystem, _LogManager -from ..utils.conversions import integer_to_bytearray, float_to_bytearray, byte_to_bytearray, short_to_bytearray +from ..utils.conversions import integer_to_bytearray, float_to_bytearray, byte_to_bytearray, \ + short_to_bytearray, unsigned_to_bytearray YES = 1 NO = 0 @@ -180,6 +181,8 @@ Acknow = 65535 AcknowGeneric = 0 # Generic Acknowledgment is not a unique message ID and inherits its Id from the actual message. Zero is a placeholder +class GuiActionTypeLength: + TREATMENT_LOG_LENGTH = 33 class HDSimulator(_AbstractSubSystem): NUM_TREATMENT_PARAMETERS = 18 @@ -1868,45 +1871,6 @@ self.can_interface.send(message, 0) - def cmd_send_general_response(self, message_id: int, accepted: int, reason: int, from_hd: bool = True, has_parameters: bool = False, parameters_payload: any = 0x00) -> None : - """ - a general method to send any standard response message, by it's id and list of paramters. - :param message_id: the id of the message - :param accepted: the standard accepted parameter of any response message - :param reason: the standard rejection reason parameter of any response message - :param from_hd: if the message shall be send fron hd channel the this needs to be true - :param has_parameters: if the message has parameter this needs to be true. - :param parameters_payload: the list of parameters pre-converted and ready to be concatenated to the payload. - :return: None - """ - payload = integer_to_bytearray(accepted) - payload += integer_to_bytearray(reason) - if has_parameters: - payload += parameters_payload - message = DenaliMessage.build_message(channel_id= DenaliChannels.hd_to_ui_ch_id if from_hd else DenaliChannels.dg_to_ui_ch_id, - message_id=message_id, - payload=payload) - - self.can_interface.send(message, 0) - - def cmd_send_general_progress_data(self, message_id: int, total: int, countdown: int, from_hd: bool = True) -> None: - """ - a general method t send any standard progress data message, by it's id - :param message_id: the id of the message - :param total: the total value of the progress data - :param countdown: the remaining or countdown value - :param from_hd: if the message shall be send fron hd channel the this needs to be true - :return: None - """ - payload = integer_to_bytearray(total) - payload += integer_to_bytearray(countdown) - - message = DenaliMessage.build_message(channel_id= DenaliChannels.hd_to_ui_ch_id if from_hd else DenaliChannels.dg_to_ui_ch_id, - message_id=message_id, - payload=payload) - - self.can_interface.send(message, 0) - def cmd_send_pre_treatment_filter_flush_progress_data(self, total, countdown): """ send the pretreatment filter flush progress data @@ -2054,11 +2018,11 @@ def cmd_send_post_treatment_disposable_removal_confirm_response(self, accepted, reason ): """ - send post treatment disposable removal confirm response - :param accepted: (U32) accept or reject - :param reason: (U32) rejection reason - :return: None - """ + send post treatment disposable removal confirm response + :param accepted: (U32) accept or reject + :param reason: (U32) rejection reason + :return: None + """ payload = integer_to_bytearray(accepted) payload += integer_to_bytearray(reason) @@ -2068,18 +2032,116 @@ self.can_interface.send(message, 0) - def cmd_send_post_treatment_log_response(self, accepted, reason, parameters): + def cmd_send_post_treatment_log_response(self, accepted, reason, + bood_flow_rate: int, + dialysate_flow_rate: int, + treatment_duration: int, + actual_treatment_duration: int, + acid_concentrate_type: int, + bicarbonate_concentrate_type: int, + potassium_concentration: int, + calcium_concentration: int, + bicarbonate_concentration: int, + sodium_concentration: int, + dialysate_temperature: float, + dialyzer_type: int, + treatment_date_time: int, + average_blood_flow: float, + average_dialysate_flow: float, + dialysate_volume_used: float, + average_dialysate_temp: float, + target_uf_volume: float, + actual_uf_volume: float, + target_uf_rate: float, + actual_uf_rate: float, + saline_bolus_volume: int, + heparin_type: int, + heparin_concentration: int, + heparin_bolus_volume: float, + heparin_dispense_rate: float, + heparin_pre_stop: int, + heparin_delivered_volume: float, + average_arterial_pressure: float, + average_venous_pressure: float, + end_treatment_early_alarm: int, + device_id: int, + water_sample_test_result: int + ): """ send post treatment log response - :param accepted: (U32) accept or reject - :param reason: (U32) rejection reason - :param parameters: (array of values) - :return: None + :param accepted: true if accpeted + :param reason: the rejection reason + :param bood_flow_rate: bood flow rate + :param dialysate_flow_rate: dialysate flow rate + :param treatment_duration: treatment duration + :param actual_treatment_duration: actual treatment duration + :param acid_concentrate_type: acid concentrate type + :param bicarbonate_concentrate_type: bicarbonate concentrate type + :param potassium_concentration: potassium concentration + :param calcium_concentration: calcium concentration + :param bicarbonate_concentration: bicarbonate concentration + :param sodium_concentration: sodium concentration + :param dialysate_temperature: dialysate temperature + :param dialyzer_type: dialyzer type + :param treatment_date_time: treatment date time + :param average_blood_flow: average blood flow + :param average_dialysate_flow: average dialysate flow + :param dialysate_volume_used: dialysate volume used + :param average_dialysate_temp: average dialysate temp + :param target_uf_volume: target uf volume + :param actual_uf_volume: actual uf volume + :param target_uf_rate: target uf rate + :param actual_uf_rate: actual uf rate + :param saline_bolus_volume: saline bolus volume + :param heparin_type: heparin type + :param heparin_concentration: heparin concentration + :param heparin_bolus_volume: heparin bolus volume + :param heparin_dispense_rate: heparin dispense rate + :param heparin_pre_stop: heparin pre stop + :param heparin_delivered_volume: heparin delivered volume + :param average_arterial_pressure: average arterial pressure + :param average_venous_pressure: average venous pressure + :param end_treatment_early_alarm: end treatment early alarm + :param device_id: device id + :param water_sample_test_result: water sample test result + :return: """ + payload = integer_to_bytearray(accepted) payload += integer_to_bytearray(reason) - for parameter in parameters: - payload += parameter + payload += unsigned_to_bytearray(int(bood_flow_rate)) + payload += unsigned_to_bytearray(int(dialysate_flow_rate)) + payload += unsigned_to_bytearray(int(treatment_duration)) + payload += unsigned_to_bytearray(int(actual_treatment_duration)) + payload += unsigned_to_bytearray(int(acid_concentrate_type)) + payload += unsigned_to_bytearray(int(bicarbonate_concentrate_type)) + payload += unsigned_to_bytearray(int(potassium_concentration)) + payload += unsigned_to_bytearray(int(calcium_concentration)) + payload += unsigned_to_bytearray(int(bicarbonate_concentration)) + payload += unsigned_to_bytearray(int(sodium_concentration)) + payload += float_to_bytearray(float(dialysate_temperature)) + payload += unsigned_to_bytearray(int(dialyzer_type)) + payload += unsigned_to_bytearray(int(treatment_date_time)) + payload += float_to_bytearray(float(average_blood_flow)) + payload += float_to_bytearray(float(average_dialysate_flow)) + payload += float_to_bytearray(float(dialysate_volume_used)) + payload += float_to_bytearray(float(average_dialysate_temp)) + payload += float_to_bytearray(float(target_uf_volume)) + payload += float_to_bytearray(float(actual_uf_volume)) + payload += float_to_bytearray(float(target_uf_rate)) + payload += float_to_bytearray(float(actual_uf_rate)) + payload += unsigned_to_bytearray(int(saline_bolus_volume)) + payload += unsigned_to_bytearray(int(heparin_type)) + payload += unsigned_to_bytearray(int(heparin_concentration)) + payload += float_to_bytearray(float(heparin_bolus_volume)) + payload += float_to_bytearray(float(heparin_dispense_rate)) + payload += unsigned_to_bytearray(int(heparin_pre_stop)) + payload += float_to_bytearray(float(heparin_delivered_volume)) + payload += float_to_bytearray(float(average_arterial_pressure)) + payload += float_to_bytearray(float(average_venous_pressure)) + payload += unsigned_to_bytearray(int(end_treatment_early_alarm)) + payload += unsigned_to_bytearray(int(device_id)) + payload += unsigned_to_bytearray(int(water_sample_test_result)) message = DenaliMessage.build_message(channel_id=DenaliChannels.hd_to_ui_ch_id, message_id=MsgIds.MSG_ID_HD_TREATMENT_LOG_DATA_RESPONSE.value, @@ -2163,3 +2225,121 @@ message_id=MsgIds.MSG_ID_DG_DISINFECT_STATE.value, payload=payload) self.can_interface.send(message, 0) + + # ------------------------------------------------ GENERAL MESSAGES ------------------------------------------------ + + def cmd_send_general_hd_response(self, message_id: int, accepted: int, reason: int, + is_pure_data: bool = False, + has_parameters: bool = False, + parameters_payload: any = 0x00) -> None: + """ + a general method to send any standard response message, by it's id and list of paramters. + :param message_id: the id of the message + :param accepted: the standard accepted parameter of any response message + :param reason: the standard rejection reason parameter of any response message + :param has_parameters: if the message has parameter this needs to be true. + :param parameters_payload: the list of parameters pre-converted and ready to be concatenated to the payload. + :return: None + """ + if not is_pure_data: + payload = integer_to_bytearray(accepted) + payload += integer_to_bytearray(reason) + + if has_parameters: + payload += parameters_payload + else: + if has_parameters: + payload = parameters_payload + + message = DenaliMessage.build_message(channel_id= DenaliChannels.hd_to_ui_ch_id, + message_id=message_id, + payload=payload) + + self.can_interface.send(message, 0) + + def cmd_send_general_hd_progress_data(self, message_id: int, total: int, countdown: int) -> None: + """ + a general method t send any standard progress data message, by it's id + :param message_id: the id of the message + :param total: the total value of the progress data + :param countdown: the remaining or countdown value + :return: None + """ + payload = integer_to_bytearray(total) + payload += integer_to_bytearray(countdown) + + message = DenaliMessage.build_message(channel_id= DenaliChannels.hd_to_ui_ch_id, + message_id=message_id, + payload=payload) + + self.can_interface.send(message, 0) + + def cmd_send_general_dg_response(self, message_id: int, accepted: int, reason: int, + is_pure_data: bool = False, + has_parameters: bool = False, + parameters_payload: any = 0x00) -> None: + """ + a general method to send any standard response message, by it's id and list of paramters. + :param message_id: the id of the message + :param accepted: the standard accepted parameter of any response message + :param reason: the standard rejection reason parameter of any response message + :param has_parameters: if the message has parameter this needs to be true. + :param parameters_payload: the list of parameters pre-converted and ready to be concatenated to the payload. + :return: None + """ + if not is_pure_data: + payload = integer_to_bytearray(accepted) + payload += integer_to_bytearray(reason) + + if has_parameters: + payload += parameters_payload + else: + if has_parameters: + payload = parameters_payload + + message = DenaliMessage.build_message(channel_id=DenaliChannels.dg_to_ui_ch_id, + message_id=message_id, + payload=payload) + + self.can_interface.send(message, 0) + + def cmd_send_general_dg_progress_data(self, message_id: int, total: int, countdown: int) -> None: + """ + a general method t send any standard progress data message, by it's id + :param message_id: the id of the message + :param total: the total value of the progress data + :param countdown: the remaining or countdown value + :return: None + """ + payload = integer_to_bytearray(total) + payload += integer_to_bytearray(countdown) + + message = DenaliMessage.build_message(channel_id=DenaliChannels.dg_to_ui_ch_id, + message_id=message_id, + payload=payload) + + self.can_interface.send(message, 0) + + def ack_send_hd(self, seq: int) -> None: + """ + sending hd ack message by the sequence seq + :param seq: the message sequence number + :return: None + """ + message = DenaliMessage.build_message(channel_id=DenaliChannels.hd_to_ui_ch_id, + message_id=GuiActionType.Acknow, + seq=seq) + + self.can_interface.send(message, 0) + + def ack_send_dg(self, seq: int) -> None: + """ + sending dg ack message by the sequence seq + :param seq: the message sequence number + :return: None + """ + message = DenaliMessage.build_message(channel_id=DenaliChannels.dg_to_ui_ch_id, + message_id=GuiActionType.Acknow, + seq=seq) + + self.can_interface.send(message, 0)