Index: firmware/App/Modes/StateTxBloodPrime.c =================================================================== diff -u -r837f6f8cde5a6902e6033d4097d42a4c34067182 -r3fe89449a8859b7567cdf524727ef0ff738a706f --- firmware/App/Modes/StateTxBloodPrime.c (.../StateTxBloodPrime.c) (revision 837f6f8cde5a6902e6033d4097d42a4c34067182) +++ firmware/App/Modes/StateTxBloodPrime.c (.../StateTxBloodPrime.c) (revision 3fe89449a8859b7567cdf524727ef0ff738a706f) @@ -50,10 +50,14 @@ /// Multiplier to convert flow (mL/min) into volume (mL) for period of general task interval. static const F32 BLOOD_PRIME_FLOW_INTEGRATOR = 1.0F / (F32)( SEC_PER_MIN * ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ); +/// Tubing portion of blood prime volume to prime the blood side circuit (in mL). +#define TUBING_BLOOD_PRIME_VOLUME_ML 106.6F + // ********** private data ********** static BLOOD_PRIME_STATE_T bloodPrimeState; ///< Current state of the blood prime sub-mode. -static REQUESTED_BLOOD_PRIME_USER_ACTIONS_T bloodPrimeRequestedAction = NUM_OF_REQUESTED_BLOOD_PRIME_USER_ACTIONS; ///< Number of requested blood prime user actions +static BOOL pendingPauseRequest; ///< Flag indicating UI has requested blood prime pause. +static BOOL pendingResumeRequest; ///< Flag indicating UI has requested blood prime resume. static F32 bloodPrimeRampFlowRate_mL_min; ///< Current blood pump ramp flow rate. static F32 bloodPrimeRampStep_mL; ///< Blood pump volume step size for ramping. @@ -98,7 +102,6 @@ bloodPrimeTargetVolume_mL = TUBING_BLOOD_PRIME_VOLUME_ML + (F32)( getDialyzerBloodVolume( getTreatmentParameterU32( TREATMENT_PARAM_DIALYZER_TYPE ) ) ); bloodPrimeRampFlowRate_mL_min = (F32)BLOOD_PRIME_INIT_BP_FLOW_RATE_ML_MIN; - bloodPrimeRequestedAction = NUM_OF_REQUESTED_BLOOD_PRIME_USER_ACTIONS; // Calculate BP ramp step size rampRateSpan = (F32)( setBPRate - BLOOD_PRIME_INIT_BP_FLOW_RATE_ML_MIN ); @@ -162,7 +165,8 @@ *************************************************************************/ static void resetBloodPrimeFlags( void ) { - // No flags for now + pendingPauseRequest = FALSE; + pendingResumeRequest = FALSE; } /*********************************************************************//** @@ -247,29 +251,28 @@ setBloodIsPrimed( TRUE ); signalBloodPrimeToDialysis(); } - // Soft pause from UI - else if ( bloodPrimeRequestedAction == REQUESTED_USER_ACTION_BLOOD_PRIME_PAUSE ) + else if ( TRUE == pendingPauseRequest ) { - bloodPrimeRequestedAction = NUM_OF_REQUESTED_BLOOD_PRIME_USER_ACTIONS; + pendingPauseRequest = FALSE; lastBloodPrimeFlowRate_mL_min = getMeasuredBloodFlowRate(); setBloodPumpTargetFlowRate( 0, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); + // TODO close art/ven pinch valves? result = BLOOD_PRIME_PAUSED_STATE; } - - else if ( getTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW ) != lastBloodPrimeFlowRate_mL_min ) + else if ( FALSE )//TODO - when UI changes blood flow rate { + // TODO change BP rate to UI given rate result = BLOOD_PRIME_RUN_STATE; } - else { // Continue ramping if ( ++bloodPrimeRampControlTimerCtr >= BLOOD_PRIME_RAMPING_INTERVAL ) { - U32 setBPRate = getTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW ); - setBloodPumpTargetFlowRate( setBPRate, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); bloodPrimeRampControlTimerCtr = 0; + bloodPrimeRampFlowRate_mL_min += bloodPrimeRampStep_mL; + setBloodPumpTargetFlowRate( (U32)bloodPrimeRampFlowRate_mL_min, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); } } @@ -291,26 +294,26 @@ // Update blood prime volume delivered so far cumulativeBloodPrimeVolume_mL.data += ( getMeasuredBloodFlowRate() * BLOOD_PRIME_FLOW_INTEGRATOR ); + // Volume reached to Dialysis if ( getBloodPrimeVolume() >= bloodPrimeTargetVolume_mL ) { initBloodPrime(); setBloodIsPrimed( TRUE ); signalBloodPrimeToDialysis(); } - - // Soft pause - else if ( bloodPrimeRequestedAction == REQUESTED_USER_ACTION_BLOOD_PRIME_PAUSE ) + // Soft pause from UI + else if ( TRUE == pendingPauseRequest ) { - bloodPrimeRequestedAction = NUM_OF_REQUESTED_BLOOD_PRIME_USER_ACTIONS; + pendingPauseRequest = FALSE; lastBloodPrimeFlowRate_mL_min = getMeasuredBloodFlowRate(); setBloodPumpTargetFlowRate( 0, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); + // TODO close art/ven pinch valves? result = BLOOD_PRIME_PAUSED_STATE; } - - else + else if ( FALSE )//TODO - when UI changes blood flow rate { - // Run continuously at requested rate - setBloodPumpTargetFlowRate( getTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW ), MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); + // TODO change BP rate to UI given rate + result = BLOOD_PRIME_RUN_STATE; } return result; @@ -328,32 +331,15 @@ { BLOOD_PRIME_STATE_T result = BLOOD_PRIME_PAUSED_STATE; - // Hard stop to exit blood prime - if ( TRUE == isStopButtonPressed() ) + // Soft resume from UI + if ( TRUE == pendingResumeRequest ) { - initBloodPrime(); - setBloodPumpTargetFlowRate( 0, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); - result = BLOOD_PRIME_RAMP_STATE; + 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 } - // Resume from UI - else if ( bloodPrimeRequestedAction == REQUESTED_USER_ACTION_BLOOD_PRIME_RESUME ) - { - bloodPrimeRequestedAction = NUM_OF_REQUESTED_BLOOD_PRIME_USER_ACTIONS; - setValvePosition( H1_VALV, VALVE_POSITION_B_OPEN ); - setValvePosition( H19_VALV, VALVE_POSITION_B_OPEN ); - setBloodPumpTargetFlowRate( lastBloodPrimeFlowRate_mL_min, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); - - if ( getMeasuredBloodFlowRate() < getTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW ) ) - { - result = BLOOD_PRIME_RAMP_STATE; - } - else - { - result = BLOOD_PRIME_RUN_STATE; - } - } - return result; } @@ -374,30 +360,48 @@ * @brief * The bloodPrimeHandleCmdRequest function handles the UI blood prime * command request. -* @details \b Message \b Sent: MSG_ID_UI_BLOOD_PRIME_CMD_REQUEST +* @details \b Message \b Sent: MSG_ID_UI_BLOOD_PRIME_CMD_RESPONSE * @details \b Inputs: message containing requested blood prime user action. * @details \b Outputs: bloodPrimeRequestedAction updated if valid. * @return TRUE if payload is valid, FALSE otherwise. *************************************************************************/ BOOL bloodPrimeHandleCmdRequest( MESSAGE_T *message ) { - REQUESTED_BLOOD_PRIME_USER_ACTIONS_T requestedAction; + BOOL result = FALSE; + REQUEST_REJECT_REASON_CODE_T rejReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; - if ( sizeof(requestedAction) == message->hdr.payloadLen ) - { - memcpy( &requestedAction, message->payload[0], sizeof( requestedAction ) ); + if ( sizeof(U32) == message->hdr.payloadLen ) + { + U32 action; - if ( requestedAction < NUM_OF_REQUESTED_BLOOD_PRIME_USER_ACTIONS ) - { - bloodPrimeRequestedAction = requestedAction; - } + memcpy( &action, message->payload[0], sizeof(U32) ); - return TRUE; - } + if ( action < NUM_OF_REQUESTED_BLOOD_PRIME_USER_ACTIONS ) + { + result = TRUE; + rejReason = REQUEST_REJECT_REASON_NONE; + if ( REQUESTED_USER_ACTION_BLOOD_PRIME_PAUSE == action ) + { + pendingPauseRequest = TRUE; + } + if ( REQUESTED_USER_ACTION_BLOOD_PRIME_RESUME == action ) + { + pendingResumeRequest = TRUE; + } + } + else + { + rejReason = REQUEST_REJECT_REASON_INVALID_COMMAND; + } + } - return FALSE; + // TODO - send response + + return result; } + // TODO - handle MSG_ID_UI_TREATMENT_SET_POINT_BLOOD_FLOW_CHANGE_REQUEST and send response + /*********************************************************************//** * @brief * The publishBloodPrimeData function publishes blood prime data