Index: dialin/ui/hd_simulator.py =================================================================== diff -u -rdb2b8f2dbb5876c6d02a9d2140b52322ae7dce4e -r57b6e85f4d6c2d07fee8a1710a41513a51bc09f2 --- dialin/ui/hd_simulator.py (.../hd_simulator.py) (revision db2b8f2dbb5876c6d02a9d2140b52322ae7dce4e) +++ dialin/ui/hd_simulator.py (.../hd_simulator.py) (revision 57b6e85f4d6c2d07fee8a1710a41513a51bc09f2) @@ -26,6 +26,7 @@ from random import random from copy import deepcopy import threading as threadsHere +#from math import isclose def catch_exception(f): @functools.wraps(f) @@ -150,62 +151,14 @@ self.can_interface.register_receiving_publication_function(channel_id, None, # MSG_ID_UNUSED, self._handler_ui_generic) + else: + self.logger.debug("can_interface not init ") - if auto_response: - self.can_interface.register_receiving_publication_function(channel_id, - MsgIds.MSG_ID_UI_INITIATE_TREATMENT_REQUEST.value, - self._handler_ui_initiate_treatment) - self.can_interface.register_receiving_publication_function(channel_id, - MsgIds.MSG_ID_UI_SET_UF_VOLUME_PARAMETER.value, - self._handler_ui_pre_treatment_uf_request) - self.can_interface.register_receiving_publication_function(channel_id, - MsgIds.MSG_ID_UI_NEW_TREATMENT_PARAMS.value, - self._handler_ui_validate_parameters) - self.can_interface.register_receiving_publication_function(channel_id, - MsgIds.MSG_ID_UI_USER_CONFIRM_TREATMENT_PARAMS.value, - self._handler_ui_confirm_treatment) - self.can_interface.register_receiving_publication_function(channel_id, - MsgIds.MSG_ID_UI_TX_END_CMD.value, - self._handler_ui_end_treatment) - self.can_interface.register_receiving_publication_function(channel_id, - MsgIds.MSG_ID_UI_HD_SET_RTC_REQUEST.value, - self._handler_set_rtc_request) - self.can_interface.register_receiving_publication_function(DenaliChannels.ui_sync_broadcast_ch_id, - MsgIds.MSG_ID_REQUEST_FW_VERSIONS.value, - self._handler_request_hd_version) - self.can_interface.register_receiving_publication_function(DenaliChannels.ui_sync_broadcast_ch_id, - MsgIds.MSG_ID_UI_REQUEST_SERVICE_INFO.value, - self._handler_system_usage_response) - self.can_interface.register_receiving_publication_function(DenaliChannels.ui_to_hd_ch_id, - MsgIds.MSG_ID_HD_UI_VERSION_INFO_RESPONSE.value, - self._handler_ui_post_ui_version_compatibility) - self.can_interface.register_receiving_publication_function(DenaliChannels.ui_to_hd_ch_id, - MsgIds.MSG_ID_HD_UI_VERSION_INFO_RESPONSE.value, - self._handler_ui_version) - self.treatment_parameter_rejections = TreatmentParameterRejections() # initialize variables that will be populated by UI version response self.ui_version = None - def add_publication(self, channel_id: DenaliChannels, message_id: MsgIds, function_ptr: Callable) -> None: - """ - Allows later addition of publication to the HDSimulator - @param channel_id: (DenaliChannels) the channel id of the message - @param message_id: (MsgIds) the message id - @param function_ptr: (Callable) the pointer to the message handler function - @return: None - """ - if self.auto_response: - if channel_id > 0 and message_id != MsgIds.MSG_ID_UNUSED and function_ptr is not None: - self.can_interface.register_receiving_publication_function(channel_id, - message_id, - function_ptr) - else: - self.logger.debug("rejected publication registration {0}, {1}, {2}".format(channel_id, - message_id, - function_ptr)) - def set_ui_all_publication(self, function_ptr: Callable) -> None: """ Allows later addition of publication to the HDSimulator @@ -350,10 +303,10 @@ sto = params.data_int[TreatmentParameters.TREATMENT_PARAM_HEPARIN_PRESTOP_MIN.value] hdr = params.data_float[TreatmentParameters.TREATMENT_PARAM_HEPARIN_DISPENSE_RATE_ML_HR.value] hbv = params.data_float[TreatmentParameters.TREATMENT_PARAM_HEPARIN_BOLUS_VOLUME_ML.value] - if math.isclose(sto, 430) and math.isclose(hdr, 0) and (hbv > 0.199): - self.demoSpeed = int(hbv * 10 + 0.5) - else: - self.demoSpeed = 1 + # if math.isclose(sto, 430) and math.isclose(hdr, 0) and (hbv > 0.199): + # self.demoSpeed = int(hbv * 10 + 0.5) + # else: + # self.demoSpeed = 1 self.treatment_time_sec = params.data_int[TreatmentParameters.TREATMENT_PARAM_TREATMENT_DURATION_MIN.value] * 60 self.uf_volume_set_l = params.data_int[TreatmentParameters.TREATMENT_PARAM_UF_VOLUME_L.value] @@ -528,7 +481,10 @@ else: self.demoSelection = 33 # Bolus Stop request - elif msg_id == MSG_ID_UI_PRESSURE_LIMITS_CHANGE_REQUEST.value: ## TBD! _70 x46? + elif msg_id == MsgIds.MSG_ID_UI_PRESSURE_LIMITS_CHANGE_REQUEST.value: ## TBD! _70 x46? + rsp_id = MsgIds.MSG_ID_HD_PRESSURE_LIMITS_CHANGE_RESPONSE + rsp_payload = integer_to_bytearray(EResponse.Accepted) + rsp_payload += integer_to_bytearray(RequestRejectReasons.REQUEST_REJECT_REASON_NONE.value) pass ## TBD! _70 x46? handle update: 4 params elif msg_id == MsgIds.MSG_ID_UI_RINSEBACK_CMD.value: # _82 x52 @@ -898,14 +854,15 @@ dialysate_outlet_pump_occlusion=0) # MSG_ID_RTC_EPOCH - self.uf_volume_l = min(self.uf_volume_l + self.uf_rate_l_per_sec, self.uf_volume_set_l) + # tbd! # MSG_ID_DIALYSATE_OUT_FLOW_DATA # TBD!! parameters seem swapped and off by 1000x ?? # self.cmd_set_treatment_ultrafiltration_outlet_flow_data(ref_uf_vol=self.uf_volume_set_l, # measured_uf_vol=self.uf_volume_l, # rot_speed=0.0, mot_speed=0.0, mc_speed=0.0, # mc_current=0.0, pwm=0.0) + self.uf_volume_l = min(self.uf_volume_l + self.uf_rate_l_per_sec, self.uf_volume_set_l) self.cmd_set_treatment_ultrafiltration_outlet_flow_data(ref_uf_vol=self.uf_volume_l * 1000.0, measured_uf_vol=self.uf_volume_set_l * 1000.0, rot_speed=0.0, mot_speed=0.0, mc_speed=0.0,