Index: firmware/App/Modes/StateTxBloodPrime.c =================================================================== diff -u -r11e4ed249b13d1e8a4cccbe5b5440f35d5a6decb -r82a7dfcafb8524efb11a5e92bcd97945802a0180 --- firmware/App/Modes/StateTxBloodPrime.c (.../StateTxBloodPrime.c) (revision 11e4ed249b13d1e8a4cccbe5b5440f35d5a6decb) +++ firmware/App/Modes/StateTxBloodPrime.c (.../StateTxBloodPrime.c) (revision 82a7dfcafb8524efb11a5e92bcd97945802a0180) @@ -15,11 +15,10 @@ * ***************************************************************************/ - - #include "AirTrap.h" #include "BloodFlow.h" #include "Buttons.h" +#include "Messaging.h" #include "ModeTreatment.h" #include "TxParams.h" #include "OperationModes.h" @@ -58,17 +57,18 @@ // ********** private data ********** static BLOOD_PRIME_STATE_T bloodPrimeState; ///< Current state of the blood prime sub-mode. +static BLOOD_PRIME_STATE_T bloodPrimeResumeState; ///< Blood prime sub-state prior to pause. 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. static F32 bloodPrimeTargetVolume_mL; ///< Calculated target blood prime volume (based on selected dialyzer and fixed tubing volume). -static F32 lastBloodPrimeFlowRate_mL_min; ///< Timer counter for determining for last blood prime status. 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 lastBloodPrimeFlowRate_mL_min; ///< Timer counter for determining for last blood prime status. 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. @@ -99,6 +99,7 @@ F32 estRampSeconds = 0.0F; bloodPrimeState = BLOOD_PRIME_RAMP_STATE; + bloodPrimeResumeState = BLOOD_PRIME_RAMP_STATE; bloodPrimeRampControlTimerCtr = 0; bloodPrimePublishTimerCtr = BLOOD_PRIME_DATA_PUBLISH_INTERVAL - 2; // setup so publish will occur time after next cumulativeBloodPrimeVolume_mL.data = 0.0; @@ -150,12 +151,15 @@ startAirTrapControl(); // Ensure Heparin pump is stopped - //stopSyringePump(); + //stopSyringePump(); // TODO // start blood pump setBloodPumpTargetFlowRate( (U32)bloodPrimeRampFlowRate_mL_min, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); - // TODO - direct DD to bypass dialysate and perform no ultrafiltration + // Direct DD to bypass dialysate and perform no ultrafiltration + cmdBypassDialyzer( TRUE ); + cmdChangeQd( getTreatmentParameterU32( TREATMENT_PARAM_DIALYSATE_FLOW ) ); + cmdChangeQuf( 0.0F ); setCurrentSubState( (U32)bloodPrimeState ); } @@ -260,7 +264,7 @@ else if ( TRUE == pendingPauseRequest ) { pendingPauseRequest = FALSE; - lastBloodPrimeFlowRate_mL_min = getMeasuredBloodFlowRate(); + lastBloodPrimeFlowRate_mL_min = getTargetBloodFlowRate(); setBloodPumpTargetFlowRate( 0, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); // Close art/ven pinch valves setValvePosition( H1_VALV, VALVE_POSITION_C_CLOSE ); @@ -271,9 +275,7 @@ 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; } else @@ -316,18 +318,19 @@ else if ( TRUE == pendingPauseRequest ) { pendingPauseRequest = FALSE; - lastBloodPrimeFlowRate_mL_min = getMeasuredBloodFlowRate(); + bloodPrimeResumeState = BLOOD_PRIME_RUN_STATE; + lastBloodPrimeFlowRate_mL_min = getTargetBloodFlowRate(); 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; } // 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; } return result; @@ -354,7 +357,7 @@ 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; + result = bloodPrimeResumeState; } return result; @@ -380,19 +383,20 @@ * @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. +* @return TRUE if request is accepted, FALSE if rejected. *************************************************************************/ BOOL bloodPrimeHandleCmdRequest( MESSAGE_T *message ) { BOOL result = FALSE; + U32 action = 0; REQUEST_REJECT_REASON_CODE_T rejReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + UI_RESPONSE_PAYLOAD_T response; + // Verify message payload length is valid if ( sizeof(U32) == message->hdr.payloadLen ) { - U32 action; + memcpy( &action, message->payload, sizeof( U32 ) ); - memcpy( &action, message->payload[0], sizeof(U32) ); - if ( action < NUM_OF_REQUESTED_BLOOD_PRIME_USER_ACTIONS ) { result = TRUE; @@ -412,11 +416,10 @@ } } - // Send response - { - U08 respPayload = (U08)rejReason; - sendMessage( MSG_ID_TD_BLOOD_PRIME_CMD_RESPONSE, COMM_BUFFER_OUT_CAN_TD_2_UI, &respPayload, sizeof(U08) ); - } + // Respond to request + response.accepted = result; + response.rejectionReason = rejReason; + sendMessage( MSG_ID_TD_BLOOD_PRIME_CMD_RESPONSE, COMM_BUFFER_OUT_CAN_TD_2_UI, (U08*)(&response), sizeof( UI_RESPONSE_PAYLOAD_T ) ); return result; } @@ -428,29 +431,28 @@ * @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. +* @return TRUE if request is accepted, FALSE if rejected. *************************************************************************/ BOOL bloodPrimeHandleBloodFlowChangeRequest( MESSAGE_T *message ) { BOOL result = FALSE; REQUEST_REJECT_REASON_CODE_T rejReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + UI_RESPONSE_PAYLOAD_T response; + if ( sizeof(U32) == message->hdr.payloadLen ) { - U32 requestedRate; - memcpy( &requestedRate, message->payload, sizeof(U32) ); + memcpy( &requestedBloodFlowRate_mL_min, 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) ); - } + // Respond to request + response.accepted = result; + response.rejectionReason = rejReason; + sendMessage( MSG_ID_TD_TREATMENT_SET_POINT_BLOOD_FLOW_CHANGE_RESPONSE, COMM_BUFFER_OUT_CAN_TD_2_UI, (U08*)(&response), sizeof( UI_RESPONSE_PAYLOAD_T ) ); - return result; + return result; } /*********************************************************************//** Index: firmware/App/Services/Messaging.c =================================================================== diff -u -rfa48af23c2b1cf940c485ad2602fdd186e775a0e -r82a7dfcafb8524efb11a5e92bcd97945802a0180 --- firmware/App/Services/Messaging.c (.../Messaging.c) (revision fa48af23c2b1cf940c485ad2602fdd186e775a0e) +++ firmware/App/Services/Messaging.c (.../Messaging.c) (revision 82a7dfcafb8524efb11a5e92bcd97945802a0180) @@ -181,6 +181,8 @@ { MSG_ID_TD_EJECTOR_OPT_SENSOR_OVERRIDE_REQUEST, &testEjectorOpticalSensorOverride }, { MSG_ID_TD_BLOOD_PRIME_VOLUME_OVERRIDE, &testBloodPrimeVolumeOverride }, { MSG_ID_TD_BLOOD_PRIME_PUBLISH_INTERVAL_OVERRIDE_REQUEST, &testBloodPrimePublishIntervalOverride }, + { MSG_ID_UI_BLOOD_PRIME_CMD_REQUEST, &bloodPrimeHandleCmdRequest }, + { MSG_ID_UI_TREATMENT_SET_POINT_BLOOD_FLOW_CHANGE_REQUEST, &bloodPrimeHandleBloodFlowChangeRequest }, }; #define NUM_OF_FUNCTION_HANDLERS (sizeof(MSG_FUNCTION_HANDLER_LOOKUP) / sizeof(MSG_HANDLER_LOOKUP_T))