Index: firmware/App/Services/TDInterface.c =================================================================== diff -u -r57dd20557f066bf5d790ce25dd11c97bb93e3cde -rc07917caced76b53a0ed8f35167fac6f9d8310a4 --- firmware/App/Services/TDInterface.c (.../TDInterface.c) (revision 57dd20557f066bf5d790ce25dd11c97bb93e3cde) +++ firmware/App/Services/TDInterface.c (.../TDInterface.c) (revision c07917caced76b53a0ed8f35167fac6f9d8310a4) @@ -1,24 +1,27 @@ /************************************************************************** * -* Copyright (c) 2024-2024 Diality Inc. - All Rights Reserved. +* Copyright (c) 2024-2025 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * @file TDInterface.c * -* @author (last) Vinayakam Mani -* @date (last) 28-Oct-2024 +* @author (last) Michael Garthwaite +* @date (last) 30-Oct-2025 * * @author (original) Vinayakam Mani -* @date (original) 28-Oct-2024 +* @date (original) 06-Nov-2024 * ***************************************************************************/ +#include "DialysatePumps.h" +#include "FPInterface.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" @@ -42,7 +45,7 @@ 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. @@ -66,7 +69,7 @@ // Initialize unit variables tdCurrentOpMode = MODE_INIT; tdSubMode = 0; - tdDialysateFlowrate = 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; @@ -190,7 +193,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 ) @@ -221,7 +224,7 @@ * @param Dialyzer Bypass enable. * @return none. *************************************************************************/ -void setTDDialyzerBypass( F32 dialBypass ) +void setTDDialyzerBypass( BOOL dialBypass ) { tdDialyzerBypass = dialBypass; } @@ -257,7 +260,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 @@ -322,6 +325,56 @@ /*********************************************************************//** * @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; + REQUEST_REJECT_REASON_CODE_T fpReason = REQUEST_REJECT_REASON_NONE; + + 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 FP Pre-Generate Permeate + fpReason = signalStartGenPermeate(); + // 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(); + // stop FP Pre-Generate Permeate + fpReason = signalStopGenPermeate(); + } + } + } + + 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 @@ -334,6 +387,7 @@ BOOL handleDialysateDeliveryRequestMsg( MESSAGE_T *message ) { BOOL result = FALSE; + REQUEST_REJECT_REASON_CODE_T fpReason = REQUEST_REJECT_REASON_NONE; if ( message->hdr.payloadLen == sizeof( DIALYSATE_DELIVERY_REQ_PAYLOAD_T ) ) { @@ -343,7 +397,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 ); @@ -355,14 +409,16 @@ 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(); + // stop FP Pre-Generate Permeate + fpReason = signalStopGenPermeate(); } else { @@ -376,10 +432,10 @@ setTDDialyzerBypass( startTxRequest.bypassDialyzer ); // Signal to update treatement parameters - setTreatementParamUpdate(); - } + setTreatmentParamUpdate(); - result = TRUE; + result = TRUE; + } } }