Index: firmware/App/Modes/ModeTreatment.c =================================================================== diff -u -rc539499ea2dee6d62194d573ac93b313d9e2936d -rfa356a2bce909141f45c6832659fa1ceea5bfbba --- firmware/App/Modes/ModeTreatment.c (.../ModeTreatment.c) (revision c539499ea2dee6d62194d573ac93b313d9e2936d) +++ firmware/App/Modes/ModeTreatment.c (.../ModeTreatment.c) (revision fa356a2bce909141f45c6832659fa1ceea5bfbba) @@ -26,9 +26,11 @@ #include "ModeTreatment.h" #include "ModeTreatmentParams.h" #include "OperationModes.h" +#include "Rinseback.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" #include "Timers.h" +#include "TreatmentRecirc.h" #include "TreatmentStop.h" #include "Utilities.h" #include "Valves.h" @@ -63,6 +65,9 @@ static TREATMENT_STATE_T currentTreatmentState; ///< Current state (sub-mode) of treatment mode. +static BOOL bloodIsPrimed; ///< Flag indicates whether blood-side circuit has been primed with blood. Set FALSE at init and start of rinseback. Set TRUE at end of blood prime. +static BOOL rinsebackDone; ///< Flag indicates whether a rinseback has been completed. Set FALSE at start of blood prime. Set TRUE at init and end of rinseback. + static U32 presTreatmentTimeSecs; ///< Prescribed treatment time (in minutes). static U32 presBloodFlowRate; ///< Prescribed blood flow rate (in mL/min). static U32 presDialysateFlowRate; ///< Prescribed dialysate flow rate (in mL/min). @@ -101,6 +106,9 @@ { currentTreatmentState = TREATMENT_START_STATE; + bloodIsPrimed = FALSE; + rinsebackDone = TRUE; + treatmentTimeMS = 0; lastTreatmentTimeStamp = 0; treatmentTimeBroadcastTimerCtr = 0; @@ -135,11 +143,9 @@ // Initialize treatment sub-modes each time we transition to treatment mode initDialysis(); initTreatmentStop(); - - // Set user alarm recovery actions allowed in this mode - setAlarmUserActionEnabled( ALARM_USER_ACTION_RESUME, TRUE ); - setAlarmUserActionEnabled( ALARM_USER_ACTION_RINSEBACK, TRUE ); - setAlarmUserActionEnabled( ALARM_USER_ACTION_END_TREATMENT, TRUE ); + initRinseback(); + initTreatmentRecirc(); + // TODO - init treatment end sub-mode } /*********************************************************************//** @@ -156,28 +162,64 @@ /*********************************************************************//** * @brief - * The userRequestEndTreatment function conveys a user request to end the - * treatment. - * @details Inputs: currentTreatmentState - * @details Outputs: response to user request sent - * @return TRUE if request accepted, FALSE if not + * The getRinsebackCompleted function determines whether a rinseback has been + * completed (indicating blood-side circuit should be primarily saline). + * @details Inputs: rinsebackDone + * @details Outputs: none + * @return rinsebackDone *************************************************************************/ -BOOL userRequestEndTreatment( void ) +BOOL getRinsebackCompleted( void ) { - BOOL result = FALSE; + return rinsebackDone; +} - if ( TREATMENT_STOP_STATE == currentTreatmentState ) - { - pendingUserEndTreatmentRequest = TRUE; - result = TRUE; - } - sendTreatmentEndResponseMsg( result ); +/*********************************************************************//** + * @brief + * The setRinsebackIsCompleted function sets that flag indicating whether a + * rinseback has been completed. Call this function with TRUE when rinseback + * operation is completed. Call this function with FALSE at start of blood + * prime operation. + * @details Inputs: none + * @details Outputs: rinsebackDone + * @param flag TRUE if rinseback has been completed, FALSE if not + * @return none + *************************************************************************/ +void setRinsebackIsCompleted( BOOL flag ) +{ + rinsebackDone = flag; +} - return result; +/*********************************************************************//** + * @brief + * The getBloodIsPrimed function determines whether the blood-side circuit + * has been primed with blood (indicating blood-side circuit should be primarily blood). + * @details Inputs: bloodIsPrimed + * @details Outputs: none + * @return bloodIsPrimed + *************************************************************************/ +BOOL getBloodIsPrimed( void ) // Determine whether the blood-side circuit of the dialyzer has been primed with blood +{ + return bloodIsPrimed; } /*********************************************************************//** * @brief + * The setBloodIsPrimed function sets that flag indicating whether the + * blood-side circuit has been primed with blood. Call this function with + * TRUE when blood prime operation is completed. Call this function with + * FALSE at start of treatment or start of rinseback operation. + * @details Inputs: none + * @details Outputs: bloodIsPrimed + * @param flag TRUE if blood side circuit is primed with blood, FALSE if not + * @return none + *************************************************************************/ +void setBloodIsPrimed( BOOL flag ) +{ + bloodIsPrimed = flag; +} + +/*********************************************************************//** + * @brief * The signalAlarmActionToTreatmentMode function executes the given alarm action * as appropriate while in Treatment Mode. * @details Inputs: none @@ -200,11 +242,11 @@ break; case TREATMENT_RINSEBACK_STATE: - // TODO - implement + signalStopRinseback(); break; case TREATMENT_RECIRC_STATE: - // TODO - implement + signalStopTreatmentRecirc(); break; default: @@ -223,12 +265,20 @@ currentTreatmentState = TREATMENT_DIALYSIS_STATE; break; - case TREATMENT_RINSEBACK_STATE: - // TODO - implement + default: + // Ignore break; + } + break; - case TREATMENT_RECIRC_STATE: - // TODO - implement + case ALARM_ACTION_RINSEBACK: + switch ( currentTreatmentState ) + { + case TREATMENT_STOP_STATE: + lastTreatmentTimeStamp = getMSTimerCount(); + startDialysis(); + transitionToDialysis(); + currentTreatmentState = TREATMENT_DIALYSIS_STATE; break; default: @@ -237,13 +287,17 @@ } break; - case ALARM_ACTION_RINSEBACK: - // TODO - implement - break; - case ALARM_ACTION_END_TREATMENT: - // TODO - temporary code - implement - currentTreatmentState = TREATMENT_END_STATE; + switch ( currentTreatmentState ) + { + case TREATMENT_STOP_STATE: + pendingUserEndTreatmentRequest = TRUE; + break; + + default: + // Ignore + break; + } break; case ALARM_ACTION_ACK: @@ -329,14 +383,17 @@ * @details Outputs: treatmentTimeMS, lastTreatmentTimeStamp * @return next treatment mode state *************************************************************************/ -static TREATMENT_STATE_T handleTreatmentStartState( void ) +static TREATMENT_STATE_T handleTreatmentStartState( void ) // TODO - we need a blood prime state between start and dialysis sub-modes { TREATMENT_STATE_T result = TREATMENT_DIALYSIS_STATE; // Initialize treatment time treatmentTimeMS = 0; lastTreatmentTimeStamp = getMSTimerCount(); + setRinsebackIsCompleted( FALSE ); + //setBloodIsPrimed( TRUE ); TODO - call when blood prime is completed + presTreatmentTimeSecs = SEC_PER_MIN * getTreatmentParameterU32( TREATMENT_PARAM_TREATMENT_DURATION ); presBloodFlowRate = getTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW ); presDialysateFlowRate = getTreatmentParameterU32( TREATMENT_PARAM_DIALYSATE_FLOW ); @@ -866,9 +923,14 @@ DIALYSIS_STATE_T dialysisState = getDialysisState(); UF_STATE_T uFState = getUltrafiltrationState(); SALINE_BOLUS_STATE_T salineBolusInProgress = getSalineBolusState(); + RINSEBACK_STATE_T rBState = getCurrentRinsebackState(); + TREATMENT_RECIRC_STATE_T rCState = getCurrentTreatmentRecircState(); + HEPARIN_STATE_T hepState = HEPARIN_STATE_OFF; // TODO - get Heparin state when implemented + broadcastTreatmentTime( presTreatmentTimeSecs, elapsedTreatmentTimeInSecs, timeRemaining ); - broadcastTreatmentState( currentTreatmentState, uFState, salineBolusInProgress ); + broadcastTreatmentState( (U32)currentTreatmentState, (U32)uFState, (U32)salineBolusInProgress, + (U32)hepState, (U32)rBState, (U32)rCState ); treatmentTimeBroadcastTimerCtr = 0; } }