Index: firmware/App/Services/TDInterface.c =================================================================== diff -u -rbce6e6d1cfb6e8a0b186419416460ead3a44e5e1 -r333e2d0c0462dcb4343a279420949cce716ebab7 --- firmware/App/Services/TDInterface.c (.../TDInterface.c) (revision bce6e6d1cfb6e8a0b186419416460ead3a44e5e1) +++ firmware/App/Services/TDInterface.c (.../TDInterface.c) (revision 333e2d0c0462dcb4343a279420949cce716ebab7) @@ -15,10 +15,12 @@ * ***************************************************************************/ +#include "DialysatePumps.h" #include "Messaging.h" #include "MessagePayloads.h" #include "ModeGenDialysate.h" #include "ModeInitPOST.h" +#include "ModePreGenDialysate.h" #include "ModeStandby.h" #include "OperationModes.h" #include "PersistentAlarm.h" @@ -35,15 +37,14 @@ // ********** private definitions ********** #define TD_DATA_FRESHNESS_TIMEOUT_MS ( 3 * MS_PER_SECOND ) ///< TD data freshness timeout (in ms). -#define TD_MAX_DIALYSIS_FLOW_RATE ( 600.0F ) ///< TD Max dialysis flow rate // ********** private data ********** // TD status static TD_OP_MODE_T tdCurrentOpMode; ///< Current TD operation mode. static U32 tdSubMode; ///< Current state (sub-mode) of current TD operation mode. static F32 tdDialysateFlowrate; ///< TD dialysate flow rate -static F32 tdUFRate; ///< TD ultrafilteration rate +static F32 tdUFRate; ///< TD ultrafiltration rate static F32 tdTargetDialysateTemp; ///< TD target dialysate temperature static BOOL tdDialyzerBypass; ///< TD dialyzer bypass static DD_ACID_TYPES_T tdAcidType; ///< TD Acid type. @@ -67,7 +68,7 @@ // Initialize unit variables tdCurrentOpMode = MODE_INIT; tdSubMode = 0; - tdDialysateFlowrate = TD_MAX_DIALYSIS_FLOW_RATE; // Will update later based on the TD value + tdDialysateFlowrate = MAX_DIALYSATE_FLOW_RATE; // Will update later based on the TD value tdUFRate = 0.0F; tdTargetDialysateTemp = 0.0F; tdDialyzerBypass = FALSE; @@ -191,7 +192,7 @@ * The setTDUFRate function sets the latest TD UF rate. * @details \b Inputs: none * @details \b Outputs: tdUFRate - * @param ultrafilteration flow rate. + * @param ultrafiltration flow rate. * @return none. *************************************************************************/ void setTDUFRate( F32 ufRate ) @@ -222,7 +223,7 @@ * @param Dialyzer Bypass enable. * @return none. *************************************************************************/ -void setTDDialyzerBypass( F32 dialBypass ) +void setTDDialyzerBypass( BOOL dialBypass ) { tdDialyzerBypass = dialBypass; } @@ -258,7 +259,7 @@ /*********************************************************************//** * @brief - * The getTDUFrate function gets the latest TD ultrafilteration flow + * The getTDUFrate function gets the latest TD ultrafiltration flow * rate. * @details \b Inputs: tdUFRate * @details \b Outputs: none @@ -323,6 +324,51 @@ /*********************************************************************//** * @brief + * The handlePreGenDialysateRequestMsg function handles a pre gen dailysate + * delivery request from TD to perform required self test and priming process. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return TRUE if message is sucessfully parsed, FALSE if not. + *************************************************************************/ +BOOL handlePreGenDialysateRequestMsg( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + if ( message->hdr.payloadLen == sizeof( PRE_GEN_DIALYSATE_REQ_PAYLOAD_T ) ) + { + PRE_GEN_DIALYSATE_REQ_PAYLOAD_T startPreGenRequest; + DD_OP_MODE_T ddMode = getCurrentOperationMode(); + + memcpy( &startPreGenRequest, message->payload, sizeof( PRE_GEN_DIALYSATE_REQ_PAYLOAD_T ) ); + + // Process the pre-gen dialysate delivery request message + if ( ( DD_MODE_STAN == ddMode ) && ( TRUE == startPreGenRequest.start ) ) + { + // start pre-gen dialysate + result = requestDDPreGenStart(); + // Update Temperature, Acid/Bicarb type and dialysate rate for pregen process. + setTDDialysateFlowrate( startPreGenRequest.dialRate ); + setTDTargetDialysateTemperature( startPreGenRequest.dialTemp ); + setTDAcidAndBicarbType( startPreGenRequest.acidType, startPreGenRequest.bicarbType ); + } + else if ( DD_MODE_PREG == ddMode ) + { + if ( FALSE == startPreGenRequest.start ) + { + // stop pre generate diaysate delivery + result = requestDDPreGenStop(); + } + } + } + + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_DD_2_TD, result ); + + return result; +} + +/*********************************************************************//** + * @brief * The handleDialysateDeliveryRequestMsg function handles a dailysate * delivery request from TD and updates dialysate flowrate, UF rate, * dialysate temperature, dialyzer bypass and concentrate types ( acid @@ -344,7 +390,7 @@ memcpy( &startTxRequest, message->payload, sizeof( DIALYSATE_DELIVERY_REQ_PAYLOAD_T ) ); // Process the dialysate delivery request message - if ( ( DD_MODE_STAN == ddMode ) && ( TRUE == startTxRequest.start ) ) + if ( ( DD_MODE_PREG == ddMode ) && ( TRUE == startTxRequest.start ) ) { // Set dialysate flow rate, UF rate and dialysate temperature setTDDialysateFlowrate( startTxRequest.dialRate ); @@ -356,14 +402,14 @@ setTDDialyzerBypass( startTxRequest.bypassDialyzer ); // start dialysate generation - result = requestDDStart(); + result = requestDDGenDialStart(); } else if ( DD_MODE_GEND == ddMode ) { if ( FALSE == startTxRequest.start ) { - // stop dialysate generation by transitioning to standby mode - requestNewOperationMode( DD_MODE_STAN ); + // stop dialysate generation + result = requestDDGenDialyasteStop(); } else { @@ -375,9 +421,12 @@ // Set concentrate types, Bypass dialyzer setTDAcidAndBicarbType( startTxRequest.acidType, startTxRequest.bicarbType ); setTDDialyzerBypass( startTxRequest.bypassDialyzer ); - } - result = TRUE; + // Signal to update treatement parameters + setTreatmentParamUpdate(); + + result = TRUE; + } } }