Index: firmware/App/Modes/StateTxBloodPrime.c =================================================================== diff -u -r3fe89449a8859b7567cdf524727ef0ff738a706f -r11e4ed249b13d1e8a4cccbe5b5440f35d5a6decb --- firmware/App/Modes/StateTxBloodPrime.c (.../StateTxBloodPrime.c) (revision 3fe89449a8859b7567cdf524727ef0ff738a706f) +++ firmware/App/Modes/StateTxBloodPrime.c (.../StateTxBloodPrime.c) (revision 11e4ed249b13d1e8a4cccbe5b5440f35d5a6decb) @@ -15,6 +15,8 @@ * ***************************************************************************/ + + #include "AirTrap.h" #include "BloodFlow.h" #include "Buttons.h" @@ -58,6 +60,7 @@ static BLOOD_PRIME_STATE_T bloodPrimeState; ///< Current state of the blood prime sub-mode. static BOOL pendingPauseRequest; ///< Flag indicating UI has requested blood prime pause. static BOOL pendingResumeRequest; ///< Flag indicating UI has requested blood prime resume. +static BOOL pendingFlowChangeRequest; ///< Flag indicating UI has requested blood prime flow change static F32 bloodPrimeRampFlowRate_mL_min; ///< Current blood pump ramp flow rate. static F32 bloodPrimeRampStep_mL; ///< Blood pump volume step size for ramping. @@ -66,6 +69,7 @@ static U32 bloodPrimeRampControlTimerCtr; ///< Timer counter for determining interval for controlling BP ramp. static U32 bloodPrimePublishTimerCtr; ///< Timer counter for determining interval for blood prime status to be published. +static U32 requestedBloodFlowRate_mL_min; ///< Requested blood flow rate from UI. /// Interval (in task intervals) at which to publish blood prime data to CAN bus. static OVERRIDE_U32_T bloodPrimePublishInterval = { BLOOD_PRIME_DATA_PUBLISH_INTERVAL, BLOOD_PRIME_DATA_PUBLISH_INTERVAL, BLOOD_PRIME_DATA_PUBLISH_INTERVAL, 0 }; @@ -167,6 +171,7 @@ { pendingPauseRequest = FALSE; pendingResumeRequest = FALSE; + pendingFlowChangeRequest = FALSE; } /*********************************************************************//** @@ -257,11 +262,17 @@ pendingPauseRequest = FALSE; lastBloodPrimeFlowRate_mL_min = getMeasuredBloodFlowRate(); setBloodPumpTargetFlowRate( 0, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); - // TODO close art/ven pinch valves? + // Close art/ven pinch valves + setValvePosition( H1_VALV, VALVE_POSITION_C_CLOSE ); + setValvePosition( H19_VALV, VALVE_POSITION_C_CLOSE ); result = BLOOD_PRIME_PAUSED_STATE; } - else if ( FALSE )//TODO - when UI changes blood flow rate + // When UI changes blood flow rate + else if ( TRUE == pendingFlowChangeRequest ) { + pendingFlowChangeRequest = FALSE; + bloodPrimeRampFlowRate_mL_min = (F32)requestedBloodFlowRate_mL_min; + setBloodPumpTargetFlowRate( requestedBloodFlowRate_mL_min, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); // TODO change BP rate to UI given rate result = BLOOD_PRIME_RUN_STATE; } @@ -310,8 +321,11 @@ // TODO close art/ven pinch valves? result = BLOOD_PRIME_PAUSED_STATE; } - else if ( FALSE )//TODO - when UI changes blood flow rate + // When UI changes blood flow rate + else if ( TRUE == pendingFlowChangeRequest ) { + pendingFlowChangeRequest = FALSE; + setBloodPumpTargetFlowRate( requestedBloodFlowRate_mL_min, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); // TODO change BP rate to UI given rate result = BLOOD_PRIME_RUN_STATE; } @@ -336,8 +350,11 @@ { pendingResumeRequest = FALSE; setBloodPumpTargetFlowRate( (U32)lastBloodPrimeFlowRate_mL_min, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); - // TODO open art/ven pinch valves? - result = 0; // TODO return to state prior to pause + // open art/ven pinch valves + setValvePosition( H1_VALV, VALVE_POSITION_B_OPEN ); + setValvePosition( H19_VALV, VALVE_POSITION_B_OPEN ); + // Return to state prior to pause + result = BLOOD_PRIME_RUN_STATE; } return result; @@ -395,13 +412,47 @@ } } - // TODO - send response + // Send response + { + U08 respPayload = (U08)rejReason; + sendMessage( MSG_ID_TD_BLOOD_PRIME_CMD_RESPONSE, COMM_BUFFER_OUT_CAN_TD_2_UI, &respPayload, sizeof(U08) ); + } return result; } - // TODO - handle MSG_ID_UI_TREATMENT_SET_POINT_BLOOD_FLOW_CHANGE_REQUEST and send response +/*********************************************************************//** +* @brief +* The bloodPrimeHandleBloodFlowChangeRequest function handles the UI +* treatment blood flow change request. +* @details \b Message \b Sent: MSG_ID_TD_TREATMENT_SET_POINT_BLOOD_FLOW_CHANGE_RESPONSE +* @details \b Inputs: message containing requested blood flow rate. +* @details \b Outputs: pendingFlowChangeRequest set if valid. +* @return TRUE if payload format valid, FALSE otherwise. +*************************************************************************/ +BOOL bloodPrimeHandleBloodFlowChangeRequest( MESSAGE_T *message ) +{ + BOOL result = FALSE; + REQUEST_REJECT_REASON_CODE_T rejReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + if ( sizeof(U32) == message->hdr.payloadLen ) + { + U32 requestedRate; + memcpy( &requestedRate, message->payload, sizeof(U32) ); + result = TRUE; + rejReason = REQUEST_REJECT_REASON_NONE; + requestedBloodFlowRate_mL_min = requestedRate; + pendingFlowChangeRequest = TRUE; + } + // Send response + { + U08 respPayload = (U08)rejReason; + sendMessage( MSG_ID_TD_TREATMENT_SET_POINT_BLOOD_FLOW_CHANGE_RESPONSE, COMM_BUFFER_OUT_CAN_TD_2_UI, &respPayload, sizeof(U08) ); + } + + return result; +} + /*********************************************************************//** * @brief * The publishBloodPrimeData function publishes blood prime data Index: firmware/App/Modes/StateTxBloodPrime.h =================================================================== diff -u -r3fe89449a8859b7567cdf524727ef0ff738a706f -r11e4ed249b13d1e8a4cccbe5b5440f35d5a6decb --- firmware/App/Modes/StateTxBloodPrime.h (.../StateTxBloodPrime.h) (revision 3fe89449a8859b7567cdf524727ef0ff738a706f) +++ firmware/App/Modes/StateTxBloodPrime.h (.../StateTxBloodPrime.h) (revision 11e4ed249b13d1e8a4cccbe5b5440f35d5a6decb) @@ -51,6 +51,7 @@ BLOOD_PRIME_STATE_T getCurrentBloodPrimeState( void ); // Get the current treatment sub-mode state BOOL bloodPrimeHandleCmdRequest( MESSAGE_T *message ); // Handle blood prime command from UI +BOOL bloodPrimeHandleBloodFlowChangeRequest( MESSAGE_T *message ); // Handle blood prime command from UI BOOL testBloodPrimePublishIntervalOverride( MESSAGE_T *message ); BOOL testBloodPrimeVolumeOverride( MESSAGE_T *message );