Index: firmware/App/Controllers/SubstitutionPump.c =================================================================== diff -u -r9cdec1997f5ee13f553229a9c9a2da4a7420e48a -rf90c1eef73251d75ce49645eb05deb492a486ff0 --- firmware/App/Controllers/SubstitutionPump.c (.../SubstitutionPump.c) (revision 9cdec1997f5ee13f553229a9c9a2da4a7420e48a) +++ firmware/App/Controllers/SubstitutionPump.c (.../SubstitutionPump.c) (revision f90c1eef73251d75ce49645eb05deb492a486ff0) @@ -10,8 +10,8 @@ * @author (last) Jashwant Gantyada * @date (last) 02-Apr-2026 * -* @author (original) Vinayakam Mani -* @date (original) 19-Sep-2024 +* @author (original) Michael Garthwaite +* @date (original) 5-May-2026 * ***************************************************************************/ #include "SubstitutionPump.h" @@ -45,7 +45,7 @@ #define SUBSTITUTION_PUMP_FORWARD_DIR 0x1 ///< Concentrate pump forward direction configuration. #define SUBSTITUTION_PUMP_REVERSE_DIR 0x0 ///< Concentrate pump reverse direction configuration. -#define SUBSTITUTION_PUMP_CONTROL_EIGHTH_STEP 0x04 ///< Substitution pump control 1/8th step. +#define SUBSTITUTION_PUMP_CONTROL_SIXTY_FOUR_STEP 0x04 ///< Substitution pump control 1/8th step. #define SUBSTITUTION_PUMP_CONTROL_REVERSE_DIR 0x00 ///< Substitution pump control reverse direction. #define SUBSTITUTION_PUMP_CONTROL_FORWARD_DIR 0x08 ///< Substitution pump control forward direction. #define SUBSTITUTION_PUMP_CONTROL_ENABLE 0x00 ///< Substitution pump control enable pump. @@ -61,13 +61,13 @@ SUBSTITUTION_PUMP_CONTROL_NOT_RESET | SUBSTITUTION_PUMP_CONTROL_ENABLE | SUBSTITUTION_PUMP_CONTROL_REVERSE_DIR | - SUBSTITUTION_PUMP_CONTROL_EIGHTH_STEP; + SUBSTITUTION_PUMP_CONTROL_SIXTY_FOUR_STEP; static const U32 SUBSTITUTION_PUMP_CONTROL_STOP = SUBSTITUTION_PUMP_CONTROL_SLEEP_OFF | SUBSTITUTION_PUMP_CONTROL_NOT_RESET | SUBSTITUTION_PUMP_CONTROL_DISABLE | SUBSTITUTION_PUMP_CONTROL_REVERSE_DIR | - SUBSTITUTION_PUMP_CONTROL_EIGHTH_STEP; + SUBSTITUTION_PUMP_CONTROL_SIXTY_FOUR_STEP; /// Enumeration of Substitution pump states. @@ -83,12 +83,12 @@ typedef struct { U32 controlTimerCounter; ///< Timer counter to perform control on Substitution pump. - SUBSTITUTION_PUMP_STATE_T execState; ///< Concentrate pump execute current state. + SUBSTITUTION_PUMP_STATE_T execState; ///< Substitution pump execute current state. BOOL hasTurnOnPumpsBeenRequested; ///< Flag indicates a request to turn Substitution pumps on. F32 currentPumpSpeed; ///< Current controlled Substitution pumps' speed (mL/min). U32 togglePeriodCount; ///< Converted pump speed (mL/min) to toggle period counts (0.5 uS increment counts per step). U08 direction; ///< Substitution pump motor direction. - U08 controlSet; ///< Substitution pump control set. (Used in DVT). + U08 controlSet; ///< Substitution pump control set. } SUBSTITUTION_PUMP_T; /// Payload record structure for Substitution pump start/stop request @@ -103,9 +103,9 @@ static OVERRIDE_U32_T substitutionPumpDataPublishInterval; ///< Substitution pump data publish interval. static SUBSTITUTION_PUMP_T substitutionPumps[ NUM_OF_SUB_PUMPS ]; ///< Array of Substitution pumps' data structure. -static OVERRIDE_F32_T pumpTargetSpeed[ NUM_OF_SUB_PUMPS ]; ///< Target concentrate pumps' speed (mL/min). +static OVERRIDE_F32_T pumpTargetSpeed[ NUM_OF_SUB_PUMPS ]; ///< Target substitution pumps' speed (mL/min). +static U32 substitutionPumpPublishTimerCounter; - // ********** private function prototypes ********** static void stopSubstitutionPump( SUBSTITUTION_PUMPS_T pumpId ); @@ -137,6 +137,7 @@ setFPGAD92PumpRevolutionCount( SUBSTITUTION_PUMP_ZERO_FLOW_RATE ); setFPGAD92PumpControl( SUBSTITUTION_PUMP_CONTROL_STOP ); + substitutionPumpPublishTimerCounter = SUBSTITUTION_PUMP_DATA_PUBLISH_COUNTER_START_COUNT; substitutionPumpDataPublishInterval.data = SUBSTITUTION_PUMP_DATA_PUBLISH_INTERVAL; substitutionPumpDataPublishInterval.ovInitData = SUBSTITUTION_PUMP_DATA_PUBLISH_INTERVAL; substitutionPumpDataPublishInterval.ovData = 0; @@ -163,6 +164,8 @@ substitutionPumps[ pumpId ].execState = handleSubstitutionPumpOffState( pumpId ); break; + ///TODO: Ramp state to be implemented when details for ramp rate are provided. + /// Pump ramps on its own over 2-5 seconds from start dependent on set rpm. case SUBSTITUTION_PUMP_CONTROL_TARGET_SPEED_STATE: substitutionPumps[ pumpId ].execState = handleSubstitutionPumpControlTargetSpeedState( pumpId ); break; @@ -174,6 +177,9 @@ break; } } + + // Publish data on an interval + publishSubstitutionPumpData(); } /*********************************************************************//** @@ -189,7 +195,6 @@ { SUBSTITUTION_PUMP_STATE_T state = SUBSTITUTION_PUMP_OFF_STATE; - if ( TRUE == substitutionPumps[ pumpId ].hasTurnOnPumpsBeenRequested ) { U08 controlSet = substitutionPumps[ pumpId ].controlSet; @@ -269,10 +274,10 @@ /*********************************************************************//** * @brief * The stepSubstitutionPumpToTargetSpeed function steps current step speed - * toward target speed for the given concentrate pump,with predefined step increase. + * toward target speed for the given substitution pump,with predefined step increase. * @details \b Inputs: none * @details \b Outputs: currentPumpSpeed[] - * @param pumpId concentrate pump id to increase current step speed + * @param pumpId substitution pump id to increase current step speed * @return TRUE if the pump has reached to target otherwise, FALSE *************************************************************************/ static BOOL stepSubstitutionPumpToTargetSpeed( SUBSTITUTION_PUMPS_T pumpId ) @@ -378,10 +383,9 @@ /*********************************************************************//** * @brief * The requestSubstitutionPumpOn function requests the module to turn on - * the concentrate pumps. + * the substitution pumps. * @details \b Inputs: none - * @details \b Outputs: concentratePumps[],acidConcentratePumpParkPersistenceClear, - * bicarbConcentratePumpParkPersistenceClear, ufPumpParkPersistenceClear + * @details \b Outputs: substitutionPumps[] * @details \b Alarms: ALARM_ID_DD_SOFTWARE_FAULT when invalid pump ID is seen. * @param pumpId concentrate pump id * @return none @@ -401,11 +405,11 @@ /*********************************************************************//** * @brief * The requestSubstitutionPumpOff function requests the module to turn off - * the concentrate pumps. + * the substitution pumps. * @details \b Inputs: none * @details \b Outputs: concentratePumps[] * @details \b Alarms: ALARM_ID_DD_SOFTWARE_FAULT when invalid pump ID is seen. - * @param pumpId ID of concentrate pump + * @param pumpId ID of substitution pump * @param park TRUE if pump should be parked, FALSE if not * @return none *************************************************************************/ @@ -424,13 +428,12 @@ /*********************************************************************//** * @brief * The setSubstitutionPumpTargetSpeed function sets the target step speed based on - * given speed in mL/min to specified concentrate pump. + * given speed in mL/min to specified substitution pump. * @details \b Inputs: none - * @details \b Outputs: concentratePumps[] + * @details \b Outputs: substitutionPumps[] * @details \b Alarms: ALARM_ID_DD_SOFTWARE_FAULT when invalid pump ID is seen. * @param pumpId pump id to set step speed * @param targetSpeed_ml_min target speed in mL/min - * @param targetVolume_ml dosing volume to be delivered in ml. * @return none *************************************************************************/ void setSubstitutionPumpTargetSpeed( SUBSTITUTION_PUMPS_T pumpId, F32 targetSpeed_ml_min ) @@ -449,11 +452,6 @@ targetSpeed_ml_min *= -1.0; } - /* - * If 0.0 <= speed <= 200 set it - * If speed < 0.0 set to 0 - * else speed > 200 set to 200 - */ pumpTargetSpeed[ pumpId ].data = targetSpeed_ml_min; } else @@ -462,16 +460,40 @@ } } +/*********************************************************************//** + * @brief + * The publishSubstitutionPumpData function publishes D92 pump data at the set interval. + * @details \b Message \b Sent: MSG_ID_DD_SUBSTITUTION_PUMP_DATA + * @details \b Inputs: substitutionPumpPublishTimerCounter + * @details \b Outputs: substitutionPumpPublishTimerCounter + * @return none + *************************************************************************/ +static void publishSubstitutionPumpData( void ) +{ + // publish RO pump data on interval + if ( ++substitutionPumpPublishTimerCounter >= getU32OverrideValue( &substitutionPumpDataPublishInterval ) ) + { + SUBSTITUTION_PUMP_DATA_T pumpData; + pumpData.d92_PumpTargetSpeed = pumpTargetSpeed[ D92_PUMP ].data; + pumpData.d92_PumpCurrentSetSpeed = substitutionPumps[ D92_PUMP ].currentPumpSpeed; + pumpData.d92_PumpState = (U32)substitutionPumps[ D92_PUMP ].execState; + + broadcastData( MSG_ID_DD_SUBSTITUTION_PUMP_DATA, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&pumpData, sizeof( SUBSTITUTION_PUMP_DATA_T ) ); + substitutionPumpPublishTimerCounter = 0; + } +} + + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ /*********************************************************************//** * @brief - * The testConcentratePumpDataPublishIntervalOverride function overrides the - * concentrate pump data publish interval. + * The testSubstitutionPumpDataPublishIntervalOverride function overrides the + * substitution pump data publish interval. * @details \b Inputs: none * @details \b Outputs: concentratePumpDataPublishInterval * @param Override message from Dialin which includes the interval @@ -487,16 +509,16 @@ /*********************************************************************//** * @brief - * The testConcentratePumpTargetSpeedOverride function overrides the target - * speed value of given concentrate pump id. + * The testSubstitutionPumpTargetSpeedOverride function overrides the target + * speed value of given substitution pump id. * @details \b Inputs: none * @details \b Outputs: pumpTargetSpeed * @param message Override message from Dialin which includes an ID of * the pump to override and the state to override the pump to. * @return TRUE if override successful, FALSE if not * @note pump traget speed range should be between 3.0F and 45.0F. *************************************************************************/ -BOOL testSubstituionPumpTargetSpeedOverride( MESSAGE_T *message ) +BOOL testSubstitutionPumpTargetSpeedOverride( MESSAGE_T *message ) { BOOL result = f32ArrayOverride( message, &pumpTargetSpeed[ 0 ], NUM_OF_SUB_PUMPS - 1 ); @@ -505,12 +527,12 @@ /*********************************************************************//** * @brief - * The testSubstitutionPumpStartStopOverride function starts a given substituion pump - * at mentioned speed/flowrate ( ml/min) or stops the substituion pump. + * The testSubstitutionPumpStartStopOverride function starts a given substitution pump + * at mentioned speed/flowrate ( ml/min) or stops the substitution pump. * @details \b Inputs: tester logged in * @details \b Outputs: substituionPumps[] - * @param message set message from Dialin which includes the substituion pump to set - * and the state to set the substituion pump to. + * @param message set message from Dialin which includes the substitution pump to set + * and the state to set the substitution pump to. * @return TRUE if set request is successful, FALSE if not *************************************************************************/ BOOL testSubstitutionPumpStartStopOverride( MESSAGE_T *message )