Index: dialin/ui/hd_proxy.py =================================================================== diff -u -rf8e83b59e5f3b903abb1cb78969d858439420f59 -rc8bb93ad343033f2d0de5918c155a82281fe7102 --- dialin/ui/hd_proxy.py (.../hd_proxy.py) (revision f8e83b59e5f3b903abb1cb78969d858439420f59) +++ dialin/ui/hd_proxy.py (.../hd_proxy.py) (revision c8bb93ad343033f2d0de5918c155a82281fe7102) @@ -25,6 +25,8 @@ from ..common.msg_defs import RequestRejectReasons, MsgIds import struct +YES=1 +NO=0 class HDSimulator(_AbstractSubSystem): @@ -47,6 +49,9 @@ MsgIds.MSG_ID_UI_START_TREATMENT.value, self._handler_ui_start_treatment) 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_CONFIRM_TREATMENT.value, self._handler_ui_confirm_treatment) self.can_interface.register_receiving_publication_function(channel_id, @@ -83,6 +88,35 @@ return True + def cmd_send_treatment_parameter_manual_validation_response(self, rejections: int): + """ + Sends a manually built treatment parameter validation response + + @param rejections: A list of rejection code enums + @return: True if successful, False otherwise + """ + if len(rejections) != self.NUM_TREATMENT_PARAMETERS: + self.logger.error("Invalid number of treatment parameter enums provided.") + return False + + if not all([isinstance(each, int) for each in rejections]): + self.logger.error("Not all rejections are enums.") + return False + + payload = bytearray() + + for rejection in rejections: + payload += integer_to_bytearray(rejection) + + message = DenaliMessage.build_message(channel_id=DenaliChannels.hd_to_ui_ch_id, + message_id=MsgIds.MSG_ID_HD_NEW_TREATMENT_PARAMS_RESPONSE.value, + payload=payload) + + # Send message + self.can_interface.send(message, 0) + + return True + def cmd_send_poweroff_button_pressed(self): """ Broadcast that the poweroff button was pressed @@ -128,7 +162,6 @@ self.can_interface.send(message, 0) - def cmd_send_priming_time_remaining(self, state, seconds_remaining, seconds_total): """ Broadcasts the number of seconds remaining in priming to the UI @@ -149,17 +182,19 @@ def _handler_ui_confirm_treatment(self, message): """ + Handler function to detect when a treatment is confirmed - @param message: + @param message: the confirm treatment message @return: """ - self.logger.debug("Confirmed Treatment Parameters") + self.logger.debug("Received UI confirmation of Treatment Parameters. No FW response will be sent.") def _handler_ui_start_treatment(self, message): """ + Handler function to start a treatment - @param message: - @return: + @param message: the start treatment message + @return: None """ START_POS = DenaliMessage.PAYLOAD_START_INDEX END_POS = START_POS + 4 @@ -173,10 +208,58 @@ elif request == 2: self.logger.debug("Starting treatment") + self.cmd_send_start_treatment_response(YES, 0) + + def cmd_send_start_treatment_response(self, response, reason): + """ + Sends a start treatment response message + + @param response: 0=NO, 1=YES + @return: None + """ + print("Sending: {0}".format(response)) + + payload = integer_to_bytearray(response) + payload += integer_to_bytearray(reason) + + message = DenaliMessage.build_message(channel_id=DenaliChannels.hd_to_ui_ch_id, + message_id=MsgIds.MSG_ID_HD_START_TREATMENT_RESPONSE.value, + payload=payload) + + self.can_interface.send(message, 0) + def _handler_ui_end_treatment(self, message): """ @param message: @return: """ self.logger.debug("Ending Treatment") + + def _handler_ui_validate_parameters(self, message): + """ + + @param message: + @return: + """ + rejections = [ + RequestRejectReasons.REQUEST_REJECT_REASON_NONE, # requestValid + RequestRejectReasons.REQUEST_REJECT_REASON_NONE, # bloodFlowRate + RequestRejectReasons.REQUEST_REJECT_REASON_NONE, # dialysateFlowRate + RequestRejectReasons.REQUEST_REJECT_REASON_NONE, # duration + RequestRejectReasons.REQUEST_REJECT_REASON_NONE, # heparinStopTime + RequestRejectReasons.REQUEST_REJECT_REASON_NONE, # salineBolus + RequestRejectReasons.REQUEST_REJECT_REASON_NONE, # acidConcentrate + RequestRejectReasons.REQUEST_REJECT_REASON_NONE, # bicarbonateConcentrate + RequestRejectReasons.REQUEST_REJECT_REASON_NONE, # dialyzerType + RequestRejectReasons.REQUEST_REJECT_REASON_NONE, # bloodPressureMeasureInterval + RequestRejectReasons.REQUEST_REJECT_REASON_NONE, # rinsebackFlowRate + RequestRejectReasons.REQUEST_REJECT_REASON_NONE, # arterialPressureLimitLow + RequestRejectReasons.REQUEST_REJECT_REASON_NONE, # arterialPressureLimitHigh + RequestRejectReasons.REQUEST_REJECT_REASON_NONE, # venousPressureLimitLow + RequestRejectReasons.REQUEST_REJECT_REASON_NONE, # venousPressureLimitHigh + RequestRejectReasons.REQUEST_REJECT_REASON_NONE, # heparinDispensingRate + RequestRejectReasons.REQUEST_REJECT_REASON_NONE, # heparinBolusVolume + RequestRejectReasons.REQUEST_REJECT_REASON_NONE, # dialysateTemp + ] + self.cmd_send_treatment_parameter_validation_response(rejections) Index: tests/test_hd_simulator.py =================================================================== diff -u -rf8e83b59e5f3b903abb1cb78969d858439420f59 -rc8bb93ad343033f2d0de5918c155a82281fe7102 --- tests/test_hd_simulator.py (.../test_hd_simulator.py) (revision f8e83b59e5f3b903abb1cb78969d858439420f59) +++ tests/test_hd_simulator.py (.../test_hd_simulator.py) (revision c8bb93ad343033f2d0de5918c155a82281fe7102) @@ -21,6 +21,7 @@ from dialin.ui.hd_proxy_alarms import Alarms from dialin.hd.hemodialysis_device import HD from dialin.utils.base import AbstractObserver +from dialin.squish.denaliMessages import clear_all_alarms from time import sleep @@ -79,9 +80,14 @@ def test_clear_alarms(): hd_simulator = HDSimulator() - hd_simulator.alarms.cmd_activate_alarm(Alarms.ALARM_ID_TREATMENT_STOPPED_BY_USER) - sleep(1) + hd_simulator.alarms.cmd_activate_alarm(Alarms.ALARM_ID_COMM_TOO_MANY_BAD_CRCS) + sleep(3) hd_simulator.alarms.cmd_send_clear_alarms() + sleep(3) + hd_simulator.alarms.cmd_activate_alarm(Alarms.ALARM_ID_COMM_TOO_MANY_BAD_CRCS) + sleep(3) + hd_simulator.alarms.cmd_send_clear_alarms() + # clear_all_alarms() def test_valid_parameters(): hd_simulator = HDSimulator(log_level="DEBUG") @@ -108,6 +114,17 @@ ] hd_simulator.cmd_send_treatment_parameter_validation_response(rejections) +def test_invalid_parameters(): + hd_simulator = HDSimulator(log_level="DEBUG") + + param_count = 18 + + for i in range(param_count): + rejections = [0 for _ in range(param_count)] + rejections[i] = 1 + hd_simulator.cmd_send_treatment_parameter_manual_validation_response(rejections) + sleep(2) + def test_priming(): hd_simulator = HDSimulator(log_level="DEBUG") state = 0 @@ -118,6 +135,7 @@ hd_simulator.cmd_send_priming_time_remaining(state, seconds_remaining, total_seconds) sleep(0.05) + class StartTreatmentObserver(AbstractObserver): def __init__(self): self.received_response = False @@ -135,12 +153,13 @@ sleep(0.50) if __name__ == '__main__': - # test_clear_alarms() # sleep(1) # test_poweroff() # test_valid_parameters() # test_priming() test_start_confirm_end_treatment() + # test_invalid_parameters() + # test_clear_alarms()