Index: firmware/App/Controllers/BalancingChamber.c =================================================================== diff -u -r3c3ce491ef31e52b19e5166a04467ea359fbfdae -r081b2525e3a650671d770513eb841057d88ea505 --- firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision 3c3ce491ef31e52b19e5166a04467ea359fbfdae) +++ firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision 081b2525e3a650671d770513eb841057d88ea505) @@ -7,8 +7,8 @@ * * @file BalancingChamber.c * -* @author (last) Sameer Kalliadan Poyil -* @date (last) 24-Jun-2026 +* @author (last) Santhosh Reddy +* @date (last) 06-Jul-2026 * * @author (original) Vinayakam Mani * @date (original) 28-Jan-2025 @@ -23,10 +23,11 @@ #include "FpgaDD.h" #include "Heaters.h" #include "Level.h" +#include "MessageSupport.h" +#include "Messaging.h" #include "MixingControl.h" #include "ModeGenDialysate.h" #include "ModeStandby.h" -#include "Messaging.h" #include "OperationModes.h" #include "Pressure.h" #include "TaskGeneral.h" @@ -61,6 +62,8 @@ #define BICARB_CHAMBER_PERIODIC_FILL_TIME ( 1 * SEC_PER_MIN * \ ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ) ///< Periodic bicarb chamber fill request 60 sec x 20 = 1200 #define BAL_CHAMBER_FILL_TIMEOUT_FACTOR 3.0F ///< Balancing Chamber fill timeout factor (300% of observed fill count) +#define COMP_SLOPE -0.000376F ///< Balancing chamber temperature compensation slope factor +#define COMP_INTERCEPT 1.007269F ///< Balancing chamber temperature compensation intercept factor /// Payload record structure for balancing chamber switch only request typedef struct @@ -108,9 +111,12 @@ static F32 pendingTdDialysateFlowrate; ///< Pending TD dialysate flow rate; applied at FillEnd after a BC switch completes. static BOOL isBalChamberSwitchingPeriodUpdatePending; ///< BC switching period update pending apply at fill end. static U32 bcSwitchingBasedOnClosedPeriodCounter; ///< Valve-close segments remaining before first-cycle relaxations clear after Qd timing apply. +static F32 balancingError; ///< Balancing error that has been calculated during balancing chamber switching. //TODO: remove later once level sensor working static U32 bicarbChamberPeriodicFillCounter; +// Balancing chamber state change tracker +static BAL_CHAMBER_EXEC_STATE_T prevBalChamberState; ///< Balancing chamber Previous State tracking variable // ********** private function prototypes ********** @@ -132,6 +138,7 @@ static void valveControlForBCState1FreshSideClose( void ); static void valveControlForBCState2FreshSideClose( void ); static void closeFreshSideValvesWhenFillComplete( void ); +static void calculateBalancingChamberError( void ); /*********************************************************************//** * @brief @@ -191,6 +198,8 @@ pendingTdDialysateFlowrate = 0.0F; isBalChamberSwitchingPeriodUpdatePending = FALSE; bcSwitchingBasedOnClosedPeriodCounter = 0; + balancingError = 0.0F; + prevBalChamberState = BAL_CHAMBER_STATE_IDLE; //TODO:remove once level sensor working bicarbChamberPeriodicFillCounter = 0; } @@ -366,8 +375,8 @@ /*********************************************************************//** * @brief * The execBalancingChamberControl function executes the balancing chamber state machine. - * @details \b Inputs: balChamberExecState - * @details \b Outputs: balChamberExecState + * @details \b Inputs: balChamberExecState, prevBalChamberState + * @details \b Outputs: balChamberExecState prevBalChamberState * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT when wrong balancing chamber state invoked. * @return current state. *************************************************************************/ @@ -452,6 +461,17 @@ break; } + if ( prevBalChamberState != balChamberExecState ) + { + if ( ( BAL_CHAMBER_STATE_IDLE == balChamberExecState ) || + ( BAL_CHAMBER_STATE1_FILL_START == balChamberExecState ) || + ( BAL_CHAMBER_STATE2_FILL_START == balChamberExecState ) ) + { + SEND_EVENT_WITH_2_U32_DATA( DD_EVENT_BC_STATE_CHANGE, prevBalChamberState, balChamberExecState ); + } + } + prevBalChamberState = balChamberExecState; + //Publish balancing chamber data publishBalChamberData(); @@ -1610,14 +1630,15 @@ * @brief * The setBalChamberSwitchingOnlyStatus function sets the balancing chamber * switching only On/Off status. - * @details \b Inputs: balanceChamberSwitchingOnly + * @details \b Inputs: balanceChamberSwitchingOnly, isBalChamberSwitchingActive * @details \b Outputs: none * @param OnOff to set the BC switch status * @return none *************************************************************************/ void setBalChamberSwitchingOnlyStatus( BOOL OnOff ) { balanceChamberSwitchingOnly = OnOff; + SEND_EVENT_WITH_2_U32_DATA( DD_EVENT_BC_SWITCH_ONLY_MODE_CHANGE, balanceChamberSwitchingOnly, isBalChamberSwitchingActive ); } /*********************************************************************//** @@ -1669,6 +1690,50 @@ /*********************************************************************//** * @brief + * The calculateBalancingChamberError function calculates the balancing error + * based on the fresh and spent dialysate temperature differences. + * @details \b Inputs: D4 and D50 temperature + * @details \b Outputs: balancing error + * @return balancing error the balancing error that impacts ultrafilteration. + *************************************************************************/ +static void calculateBalancingChamberError( void ) +{ + F32 freshDensity = 0.0F; + F32 spentDensity = 0.0F; + F32 compFreshFlowrate = 0.0F; + F32 compSpentFlowrate = 0.0F; + + // Fresh side dialysate density + if ( getTestConfigStatus( TEST_CONFIG_DD_FP_ENABLE_BETA_1_0_HW ) == TRUE ) + { + freshDensity = ( COMP_SLOPE * getFilteredTemperatureValue( D4_TEMP ) ) + COMP_INTERCEPT; + } + else + { + freshDensity = ( COMP_SLOPE * getFilteredTemperatureValue( D99_TEMP ) ) + COMP_INTERCEPT; + } + + spentDensity = ( COMP_SLOPE * getFilteredTemperatureValue( D50_TEMP ) ) + COMP_INTERCEPT; // spent side dialysate density + compFreshFlowrate = getTDDialysateFlowrate() * freshDensity; // Qd * fresh density + compSpentFlowrate = getTDDialysateFlowrate() * spentDensity; // Qd * spent density + balancingError = compFreshFlowrate - compSpentFlowrate; // Error in g/min +} + +/*********************************************************************//** + * @brief + * The getBalancingChamberError function gets the calculated balancing chamber + * error that may be used for adjusting the ultrafiltration rate. + * @details \b Inputs: balancingError + * @details \b Outputs: none + * @return balancing chamber error + *************************************************************************/ +F32 getBalancingChamberError( void ) +{ + return balancingError; +} + +/*********************************************************************//** + * @brief * The publishBalChamberData function broadcasts the balancing chamber * execution data at defined interval. * @details \b Inputs: balChamberDataPublicationTimerCounter Index: firmware/App/Controllers/DryBiCart.c =================================================================== diff -u -r3c3ce491ef31e52b19e5166a04467ea359fbfdae -r081b2525e3a650671d770513eb841057d88ea505 --- firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision 3c3ce491ef31e52b19e5166a04467ea359fbfdae) +++ firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision 081b2525e3a650671d770513eb841057d88ea505) @@ -7,8 +7,8 @@ * * @file DryBiCart.c * -* @author (last) Sameer Kalliadan Poyil -* @date (last) 25-Jun-2026 +* @author (last) Santhosh Reddy +* @date (last) 01-Jul-2026 * * @author (original) Vinayakam Mani * @date (original) 19-Nov-2025 @@ -24,6 +24,7 @@ #include "DryBiCart.h" #include "Level.h" #include "Messaging.h" +#include "MessageSupport.h" #include "MixingControl.h" #include "ModeGenDialysate.h" #include "OperationModes.h" @@ -142,6 +143,8 @@ static BOOL dryBiCartPressureDecayStartTimeFlag; ///< Dry bicart d66 pressure decay start timer. static DRY_BICART_OPERATION_T dryBicartStartRequest; ///< Dry bicart operation, fill or supply or drain request +static DRY_BICART_OPERATION_T prevDryBicartState; ///< Dry BiCart State Change Tracker + // ********** private function prototypes ********** static void updateDrybicartOperation(void); @@ -250,6 +253,7 @@ dryBiCartDrainTimePeriod = 0; dryBiCartPersistenceStartTime = 0; drybicartPersistenceOnLowercartPressureStartTime = 0; + prevDryBicartState = DRY_BICART_IDLE; } /*********************************************************************//** @@ -269,8 +273,8 @@ * @brief * The execDryBicart function executes the set of dry bicarbonate cartridge fill, * bicarbonate chamber fill and bicarbonate cartridge drain related state machines one at time - * @details \b Inputs: dryBicartStartRequest - * @details \b Outputs: none + * @details \b Inputs: dryBicartStartRequest, prevDryBicartState + * @details \b Outputs: prevDryBicartState * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT when wrong dry bicart state machine is * invoked. * @return none. @@ -314,6 +318,12 @@ break; } + if ( prevDryBicartState != dryBicartStartRequest ) + { + SEND_EVENT_WITH_2_U32_DATA( DD_EVENT_DRY_BICART_STATE_CHANGE, prevDryBicartState, dryBicartStartRequest ); + prevDryBicartState = dryBicartStartRequest; + } + // Publish dry bicart data publishDryBicartData(); } Index: firmware/App/DDCommon.h =================================================================== diff -u -rebc66999208b337d8cdef22c07f73d47bb0720a4 -r081b2525e3a650671d770513eb841057d88ea505 --- firmware/App/DDCommon.h (.../DDCommon.h) (revision ebc66999208b337d8cdef22c07f73d47bb0720a4) +++ firmware/App/DDCommon.h (.../DDCommon.h) (revision 081b2525e3a650671d770513eb841057d88ea505) @@ -25,7 +25,7 @@ #define DD_VERSION_MAJOR 0 #define DD_VERSION_MINOR 0 #define DD_VERSION_MICRO 0 -#define DD_VERSION_BUILD 93 +#define DD_VERSION_BUILD 95 // ********** development build switches **********