Index: firmware/App/Services/DDInterface.c =================================================================== diff -u -r6f876554db45a19590eaf2122ef47e33f7a7d69b -r1abc0349c736a70fb56db6895947abfbba0eee22 --- firmware/App/Services/DDInterface.c (.../DDInterface.c) (revision 6f876554db45a19590eaf2122ef47e33f7a7d69b) +++ firmware/App/Services/DDInterface.c (.../DDInterface.c) (revision 1abc0349c736a70fb56db6895947abfbba0eee22) @@ -8,7 +8,7 @@ * @file DDInterface.c * * @author (last) Raghu Kallala -* @date (last) 21-Apr-2026 +* @date (last) 01-May-2026 * * @author (original) Sean Nash * @date (original) 01-Aug-2024 @@ -42,11 +42,12 @@ static F32 dialysatePressure; ///< Current dialysate pressure reported by DD. static BOOL ddStartCommandSent; ///< Flag indicates command to start DD has been sent. static BOOL ddStarted; ///< Flag indicates whether we have commanded the DD to start or stop. +static BOOL isDialysateGoodtoDeliver; ///< Flag indicating whether dialysate is good to deliver. static BOOL ddOpModeDataFreshFlag; ///< Flag to signal the handleDDOpMode() to process fresh dd op mode data. static BOOL ddDialysatePressureFreshFlag; ///< Flag to signal -static BOOL dialysateGoodToDeliver; ///< Flag indicates dialysate readiness (from GEN_DIALYSATE_MODE_DATA_T broadcast). +static PRE_GEN_DIALYSATE_REQ_PAYLOAD_T preGenDialysateCmdSet; ///< Set of pre-generate dialysate parameters to send to the DD static DIALYSATE_DELIVERY_REQ_PAYLOAD_T dialysateDeliveryCmdSet; ///< Set of dialysate delivery parameters to send to the DD during treatment. // DD command response @@ -71,10 +72,10 @@ ddCurrentOpMode = DD_MODE_INIT; ddSubMode = 0; dialysatePressure = 0.0F; + isDialysateGoodtoDeliver = FALSE; ddOpModeDataFreshFlag = FALSE; ddDialysatePressureFreshFlag = FALSE; - dialysateGoodToDeliver = FALSE; resetDDInterface(); @@ -102,6 +103,14 @@ ddStarted = FALSE; ddStartCommandSent = FALSE; + preGenDialysateCmdSet.start = FALSE; + preGenDialysateCmdSet.dialRate = 0.0F; + preGenDialysateCmdSet.dialTemp = 0.0F; + preGenDialysateCmdSet.acidConvFactor = 0.0F; + preGenDialysateCmdSet.bicarbConvFactor = 0.0F; + preGenDialysateCmdSet.sodium = 0; + preGenDialysateCmdSet.bicarbonate = 0; + dialysateDeliveryCmdSet.start = FALSE; dialysateDeliveryCmdSet.dialRate = 0.0F; dialysateDeliveryCmdSet.ufRate = 0.0F; @@ -239,6 +248,38 @@ /*********************************************************************//** * @brief + * The setDialysateData function sets the latest DD dialysate data reported by + * the DD (called by DD published message handler). + * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if message is invalid. + * @details \b Inputs: none + * @details \b Outputs: isDialysateGoodtoDeliver + * @param message Pointer to the DD dialysate mode data broadcast message + * @return TRUE if message handled successfully, FALSE if not + *************************************************************************/ +BOOL setDialysateData( MESSAGE_T *message ) +{ + BOOL result = FALSE; + GEN_DIALYSATE_MODE_DATA_T payload; + + // parse message payload + memcpy( &payload, &message->payload[ 0 ], sizeof( GEN_DIALYSATE_MODE_DATA_T ) ); + + if ( message->hdr.payloadLen == sizeof( GEN_DIALYSATE_MODE_DATA_T ) ) + { + isDialysateGoodtoDeliver = payload.isDialysateGoodtoDeliver; + result = TRUE; + } + else + { +#ifndef TEST_UI_ONLY + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_DD_DIALYSATE_DATA, (U32)message->hdr.payloadLen ); +#endif + } + return result; +} + +/*********************************************************************//** + * @brief * The getDialysatePressure function gets the latest reported dialysate * pressure. * @details \b Inputs: dialysatePressure @@ -252,6 +293,20 @@ /*********************************************************************//** * @brief + * The getDialysateGoodToDeliverStatus function gets the status + * whether dialysate is good to deliver + * pressure. + * @details \b Inputs: isDialysateGoodtoDeliver + * @details \b Outputs: none + * @return Latest dialysate good to delivery status. + *************************************************************************/ +BOOL getDialysateGoodToDeliverStatus( void ) +{ + return isDialysateGoodtoDeliver; +} + +/*********************************************************************//** + * @brief * The setDialysatePressure function sets the latest dialysate pressure * reported by the DD sub-system. * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if message invalid. @@ -288,14 +343,45 @@ /*********************************************************************//** * @brief + * The cmdStartPreGenerateDialysate function sends a pre generate dialysate command + * to the DD with a given set of details. DD will transition to pre generate + * dialysate mode if it hasn't already. + * @details \b Inputs: none + * @details \b Outputs: preGenDialysateCmdSet + * @details \b Message \b Sent: Start/continue pre-generate dialysate command. + * @param qd Target dialysate flow rate (Qd). + * @param dialTemp Target dialysate temperature in deg C. + * @param acidConvFactor Conversion factor for the acid used. + * @param bicarbConvFactor Conversion factor for the bicarbonate used. + * @param sodium Level of sodium used in mEq/L. + * @param bicarbonate Level of bicarbonate used in mEq/L. + * @return none + *************************************************************************/ +void cmdStartPreGenerateDialysate( F32 qd, F32 dialTemp, F32 acidConvFactor, F32 bicarbConvFactor, U32 sodium, U32 bicarbonate ) +{ + preGenDialysateCmdSet.start = TRUE; + preGenDialysateCmdSet.dialRate = qd; + preGenDialysateCmdSet.dialTemp = dialTemp; + preGenDialysateCmdSet.acidConvFactor = acidConvFactor; + preGenDialysateCmdSet.bicarbConvFactor = bicarbConvFactor; + preGenDialysateCmdSet.sodium = sodium; + preGenDialysateCmdSet.bicarbonate = bicarbonate; + +#ifndef TEST_UI_ONLY + sendMessage( MSG_ID_DD_PRE_GEN_DIALYSATE_REQUEST_DATA, COMM_BUFFER_OUT_CAN_TD_2_DD, (U08*)(&preGenDialysateCmdSet), sizeof( PRE_GEN_DIALYSATE_REQ_PAYLOAD_T ) ); +#endif +} + +/*********************************************************************//** + * @brief * The cmdStartGenerateDialysate function sends a generate dialysate command * to the DD with a given set of details. DD will transition to dialysate * delivery mode if it hasn't already. * @details \b Inputs: none * @details \b Outputs: dialysateDeliveryCmdSet * @details \b Message \b Sent: Start/continue generate dialysate command. * @param qd Target dialysate flow rate (Qd). - * @param quf Target ultrafiltration rate (Quf). + * @param quf Target ultrafiltration rate (Quf) (in mL/min). * @param dialTemp Target dialysate temperature in deg C. * @param bypass Flag indicating whether dialyzer should be bypassed. * @param acidConvFactor Conversion factor for the acid used. @@ -355,7 +441,7 @@ * @details \b Inputs: none * @details \b Outputs: dialysateDeliveryCmdSet * @details \b Message \b Sent: Continue generate dialysate command w/ new Quf. - * @param quf Target ultrafiltration flow rate (in L/hr). + * @param quf Target ultrafiltration flow rate (in mL/min). * @return none *************************************************************************/ void cmdChangeQuf( F32 quf ) @@ -539,53 +625,7 @@ } } -/*********************************************************************//** - * @brief - * The isDialysateGoodToDeliver function returns the latest DD-reported - * dialysate readiness flag, cached from the DD gen-dialysate state - * broadcast. Used by the fluid bolus service to gate substitution bolus - * start and to monitor during delivery. - * @details \b Inputs: dialysateGoodToDeliver - * @details \b Outputs: none - * @return TRUE if dialysate is ready to deliver per DD, FALSE otherwise. -**************************************************************************/ -BOOL isDialysateGoodToDeliver( void ) -{ - return dialysateGoodToDeliver; -} -/*********************************************************************//** - * @brief - * The setGenDialysateModeData function processes the DD generate-dialysate - * mode data broadcast and caches the dialysate readiness flag. - * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if message payload invalid. - * @details \b Inputs: none - * @details \b Outputs: dialysateGoodToDeliver - * @param message Pointer to DD generate-dialysate state broadcast message. - * @return TRUE if message handled successfully, FALSE if not. - *************************************************************************/ -BOOL setGenDialysateModeData( MESSAGE_T *message ) -{ - BOOL result = FALSE; - GEN_DIALYSATE_MODE_DATA_T payload; - - if ( sizeof( GEN_DIALYSATE_MODE_DATA_T ) == message->hdr.payloadLen ) - { - memcpy( &payload, &message->payload[0], sizeof( GEN_DIALYSATE_MODE_DATA_T ) ); - dialysateGoodToDeliver = payload.isDialysateGoodtoDeliver; - result = TRUE; - } - else - { -#ifndef TEST_UI_ONLY - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_DD_GEN_DIALYSATE_DATA, (U32)message->hdr.payloadLen ); -#endif - } - - return result; -} - - /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/