# -*- coding: utf-8 -*- # Python import os import can # plugin specific from leahi_dialin.common.msg_defs import MsgIds, MsgFieldPositions from leahi_dialin.protocols import CAN from leahi_dialin.utils import conversions from leahi_dialin.common.td_defs import TDOpModes, TDTreatmentStates # td Simulator from leahi_dialin.ui.td_messaging import TD_Messaging import names salineBolusStartState = "-1" def main(): td_interface = TD_Messaging() can_interface = td_interface.can_interface global salineBolusStartState # handle sent messages from UI if can_interface is not None: channel_id = CAN.DenaliChannels.ui_to_td_ch_id message_id = MsgIds.MSG_ID_UI_SOLUTION_INFUSION_REQUEST.value can_interface.register_receiving_publication_function(channel_id, message_id, handle_solution_infusion_request) startApplication("leahi") test.log("Starting leahi") td_interface.td_operation_mode( TDOpModes.MODE_STAN.value, 0 ) # verify standy screen test.verify(waitForObjectExists(names.standByScreen_MainHome), "In Standby") mouseClick(waitForObject(names.startTreatmentButton)) # verify main treatment screen test.verify(waitForObjectExists(names.mainTreatmentScreen), "In Main Treatment") # verify saline text salineTextObj = waitForObject(names.totalSalineDelivered_Text) test.compare(salineTextObj.text, "Total Saline Delivered") # verify send start bolus req message mouseClick(waitForObject(names.startFluidButton)) test.verify(waitFor("'salineBolusStartState == 1'", 5000)) td_interface.td_tx_state( TDTreatmentStates.TREATMENT_DIALYSIS_STATE.value , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 2 , # saline in progess 0 ) # verify isStarted property binding to vTDTreatmentStates.sbRunning treatmentSaline = waitForObject(names.treatmentSaline) test.compare(treatmentSaline.isStarted, True) # verify text salineDeliveryTextObj = waitForObject(names.deliveringSaline_Text) test.compare(salineDeliveryTextObj.text, "Delivering Saline") # verify saline data bolusValueInTest = 75 td_interface.td_saline( 100 , # target_volume 150 , # cumulative_volume bolusValueInTest, # bolus_volume 0 ) # verify saline text currentBolusTextObj = waitForObject(names.currentBolusVolume) test.compare(currentBolusTextObj.text, str(bolusValueInTest)) # verify progress bar progressBarObj = waitForObject(names.salineProgressBar) test.compare(progressBarObj.value, bolusValueInTest) # verify send stop bolus req message mouseClick(waitForObject(names.startFluidButton)) test.verify(waitFor("'salineBolusStartState == 0'", 5000)) td_interface.td_tx_state( TDTreatmentStates.TREATMENT_DIALYSIS_STATE.value , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , # saline in idle 0 ) # verify progress bar set off test.compare(progressBarObj.value, 0) # handler for messages from UI to FW def handle_solution_infusion_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 salineBolusStartState salineBolusStartState = str(state)