# -*- coding: utf-8 -*- import names import can # plugin specific from leahi_dialin.common.msg_defs import MsgIds, MsgFieldPositions from leahi_dialin.protocols import CAN from leahi_dialin.ui import utils from configuration import utility,config,navigation from configuration import config from leahi_dialin.ui.td_messaging import TD_Messaging from leahi_dialin.common.ui_defs import TXStates from leahi_dialin.common.td_defs import TDOpModes,TDTreatmentStates from leahi_dialin.utils import conversions td =TD_Messaging() can_interface = td.can_interface rinsebackrequest = None request ="[1] Request is not allowed in the current operating mode" def change_treatmentstates(state): test.startSection("Change the treatment parameter") td.td_tx_state( state, 0 , 0 , 0 , 0 , TXStates.RINSEBACK_RUN_STATE , 0 , 0 , 0 , 0) test.endSection() def handle_rinseback_request( message, timestamp = 0.0): """ Called when the user requests to firmware from UI @return: None """ message = message['message'] index = MsgFieldPositions.START_POS_FIELD_1 state,index = conversions.bytearray_to_integer( message, index) global rinsebackrequest rinsebackrequest = state def main(): utils.tstStart(__file__) startApplication(config.AUT_NAME) if can_interface is not None: channel_id = CAN.DenaliChannels.ui_to_td_ch_id message_id = MsgIds.MSG_ID_UI_RINSEBACK_CMD_REQUEST.value can_interface.register_receiving_publication_function(channel_id, message_id, handle_rinseback_request) test.startSection("Verify the rinseback page") td.td_operation_mode(TDOpModes.MODE_STAN.value) change_treatmentstates(TDTreatmentStates.TREATMENT_RINSEBACK_STATE.value) td.td_pressure(H2_arterial_pressure = -151, H14_venous_pressure = -12, limit_state = 0, H2_arterial_min = -390, H2_arterial_max = 220 , H14_venous_min = -90 , H14_venous_max = 410 , H2_arterial_long = 0 , H14_venous_long = 0 , tmp_pressure = -100 , tmp_min = -500 , tmp_max = -50) value = waitForObject(names.o_EndTreatmentRinseback_arterialRangeBar_TreatmentPressureComponent,3000) arterial_rangeBar = utility.get_object_from_names(value, error_message="arterial rangeBar object is missing") arterial_low = arterial_rangeBar.lowerBound arterial_high = arterial_rangeBar.upperBound arterial_element = waitForObject(names.o_EndTreatmentRinseback_arterialRangeBar_TreatmentPressureComponent) arterial_value = utility.findObjectById(arterial_element, "_value") test.log(str(arterial_value)) venous_rangeBar = utility.get_object_from_names(names.o_EndTreatmentRinseback_venousRangeBar_TreatmentPressureComponent, error_message="venous rangeBar object is missing") venous_low = venous_rangeBar.lowerBound venous_high = venous_rangeBar.upperBound tmp_RangeBar = utility.get_object_from_names(names.o_EndTreatmentRinseback_tmpRangeBar_TreatmentPressureComponent, error_message="trancememberance rangeBar object is missing") trancememberance_low = tmp_RangeBar.lowerBound trancememberance_high = tmp_RangeBar.upperBound test.compare(arterial_low, -390, "Arterial low value should be '{}'".format(arterial_low)) test.compare(arterial_high, 220, "Arterial high value should be '{}'".format(arterial_high)) test.compare(venous_low, -90, "Venous low value should be '{}'".format(venous_low)) test.compare(venous_high, 410, "Venous high value should not be '{}'".format(venous_high)) test.compare(trancememberance_low, -500, "Trancememberance low value should be '{}'".format(trancememberance_low)) test.compare(trancememberance_high, -50, "Trancememberance high value should not be '{}'".format(trancememberance_high)) td.td_rinseback_progress( vTargetVolume = 32, vDeliveredVolume = 13, vFlowRate = 150, vTimeout = 0, vCountdown = 0, vIsCompleted = 0) delivered_volume = waitForObject(names.o_EndTreatmentRinseback_deliveredVolumeText_Text) delivered_volume_text = delivered_volume.text test.log(str(delivered_volume_text)) flow_rate = waitForObject(names.o_EndTreatmentRinseback_flowRateValue_Text) flow_rate_text =flow_rate.text test.log(str(flow_rate_text)) mouseClick(waitForObject(names.o_EndTreatmentRinseback_pauseResumeButton_TouchRect, 2000)) # handle_solution_infusion_request(MsgIds.MSG_ID_UI_RINSEBACK_CMD_REQUEST.value) global rinsebackrequest test.log(str(rinsebackrequest)) test.verify(waitFor( lambda: rinsebackrequest == 3, 5000), "Testing FW received Arterial Window Value") #test rejection td.td_rinseback_cmd_response(vRejectionReason = 1) rejectionReason = waitForObject(utility.setObjectText(text=request ,obj =names.o_EndTreatmentRinseback_NotificationBar_NotificationBarSmall)) test.compare(rejectionReason.text, "[1] Request is not allowed in the current operating mode", "Rejection Reason text should be :" + str(rejectionReason.text)) td.td_rinseback_cmd_response(vRejectionReason = 0) td.td_tx_state( TDTreatmentStates.TREATMENT_RINSEBACK_STATE.value, 0 , 0 , 0 , 0 , TXStates.RINSEBACK_PAUSED_STATE , 0 , 0 , 0 , 0) color = waitForObject(names.o_EndTreatmentRinseback_targetVolumeProgress_ProgressCircle).color.name test.log(str(color)) rinseback = waitForObject(utility.setObjectText(text="Rinseback Paused" ,obj =names.o_EndTreatmentRinseback)) test.log(str(rinseback.text)) td.td_rinseback_progress( vTargetVolume = 32, vDeliveredVolume = 13, vFlowRate = 150, vTimeout = 43, vCountdown = 84, vIsCompleted = 0) timeouttext = waitForObject(names.o_EndTreatmentRinseback_timeout_TimeText, 2000) test.log(str(timeouttext.time)) mouseClick(waitForObject(names.o_EndTreatmentRinseback_pauseResumeButton_TouchRect, 2000)) test.log(str(rinsebackrequest)) test.verify(waitFor( lambda: rinsebackrequest == 4, 5000), "Testing FW received Arterial Window Value") td.td_tx_state( TDTreatmentStates.TREATMENT_RINSEBACK_STATE.value, 0 , 0 , 0 , 0 , TXStates.RINSEBACK_RUN_STATE , 0 , 0 , 0 , 0) #Increment and decremenet Rinseback incrementButton = waitForObject(names.o_EndTreatmentRinseback_incrementFlowRateButton_ArrowButton) mouseClick(incrementButton) #Verify FW receives request with correct opmode decrementButton =waitForObject(names.o_EndTreatmentRinseback_decrementFlowRateButton_ArrowButton) mouseClick(decrementButton) #End Rinseback endRinseback = waitForObject(names.o_EndTreatmentRinseback_endButton_TouchRect) mouseClick(endRinseback) # verify fw gets request with correct opmode td.td_tx_state( TDTreatmentStates.TREATMENT_RINSEBACK_STATE.value, 0 , 0 , 0 , 0 , TXStates.RINSEBACK_STOP_STATE , 0 , 0 , 0 , 0) test.verify(waitForObjectExists(names.o_EndTreatmentRinsebackComplete_instructionView_InstructionView), "In Rinseback complete page")