Index: firmware/App/Services/Reservoirs.c =================================================================== diff -u -r45f4646609e6dd39691102e109d0b5c14f97e054 -r3eb7c2e62c727be195cd937d49957db9d4ba83b4 --- firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 45f4646609e6dd39691102e109d0b5c14f97e054) +++ firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 3eb7c2e62c727be195cd937d49957db9d4ba83b4) @@ -23,34 +23,35 @@ #include "Reservoirs.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" -#include "Timers.h" -#include "Valves.h" +#include "Timers.h" +#include "Valves.h" + +/** + * @addtogroup Reservoirs + * @{ + */ + +// ********** private definitions ********** + +#define MIN_RESERVOIR_VOLUME_ML 0 ///< Minimum reservoir volume in mL. +#define MAX_RESERVOIR_VOLUME_ML 2000 ///< Maximum reservoir volume in mL. +#define DEFAULT_FILL_VOLUME_ML 1700 ///< Default fill volume for treatment in mL. +#define DISINFECT_FILL_VOLUME_ML 2400 ///< Fill volume for disinfection in mL. +#define MAX_FILL_VOLUME_ML MAX_RESERVOIR_VOLUME_ML ///< Maximum fill volume in mL. +#define DEFAULT_DRAIN_VOLUME_ML 0 ///< Default drain volume in mL. +#define MAX_DRAIN_VOLUME_ML MAX_RESERVOIR_VOLUME_ML ///< Maximum drain volume in mL. -/** - * @addtogroup Reservoirs - * @{ - */ +#define MAX_RESERVOIR_WEIGHT 10000 ///< Maximum reservoir weight in grams. + +#define RESERVOIR_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< interval (ms/task time) at which the reservoir data is published on the CAN bus. -// ********** private definitions ********** +// ********** private data ********** + +static U32 reservoirDataPublicationTimerCounter = 0; ///< used to schedule reservoir data publication to CAN bus. + +static OVERRIDE_U32_T activeReservoir = { 0, 0, 0, 0 }; ///< The active reservoir that the DG is filling/draining/etc. +static OVERRIDE_U32_T fillVolumeTargetMl = { 0, 0, 0, 0 }; ///< The target reservoir fill volume (in mL). -#define MIN_RESERVOIR_VOLUME_ML 0 ///< Minimum reservoir volume in mL. -#define MAX_RESERVOIR_VOLUME_ML 2000 ///< Maximum reservoir volume in mL. -#define DEFAULT_FILL_VOLUME_ML 1700 ///< Default fill volume for treatment in mL. -#define DISINFECT_FILL_VOLUME_ML 2400 ///< Fill volume for disinfection in mL. -#define MAX_FILL_VOLUME_ML MAX_RESERVOIR_VOLUME_ML ///< Maximum fill volume in mL. -#define DEFAULT_DRAIN_VOLUME_ML 0 ///< Default drain volume in mL. -#define MAX_DRAIN_VOLUME_ML MAX_RESERVOIR_VOLUME_ML ///< Maximum drain volume in mL. - -#define MAX_RESERVOIR_WEIGHT 10000 ///< Maximum reservoir weight in grams. - -#define RESERVOIR_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< interval (ms/task time) at which the reservoir data is published on the CAN bus. - -// ********** private data ********** - -static U32 reservoirDataPublicationTimerCounter = 0; ///< used to schedule reservoir data publication to CAN bus. - -static OVERRIDE_U32_T activeReservoir = { 0, 0, 0, 0 }; ///< The active reservoir that the DG is filling/draining/etc. -static OVERRIDE_U32_T fillVolumeTargetMl = { 0, 0, 0, 0 }; ///< The target reservoir fill volume (in mL). static OVERRIDE_U32_T drainVolumeTargetMl = { 0, 0, 0, 0 }; ///< The target reservoir drain volume (in mL). /// The reservoirs' associate load cell. @@ -67,58 +68,54 @@ static DG_RESERVOIR_ID_T getActiveReservoir( void ); static U32 getReservoirFillVolumeTargetMl( void ); -static U32 getReservoirDrainVolumeTargetMl( void ); -/*********************************************************************//** - * @brief - * The initReservoirs function initializes the Reservoirs module. - * @details Inputs: none - * @details Outputs: Reservoirs module initialized - * @return none - *************************************************************************/ -void initReservoirs( void ) +static U32 getReservoirDrainVolumeTargetMl( void ); + +/*********************************************************************//** + * @brief + * The initReservoirs function initializes the Reservoirs module. + * @details Inputs: none + * @details Outputs: Reservoirs module initialized + * @return none + *************************************************************************/ +void initReservoirs( void ) { activeReservoir.data = (U32)DG_RESERVOIR_1; - setValveState( VRF, VALVE_STATE_R2_C_TO_NO ); - setValveState( VRD, VALVE_STATE_R2_C_TO_NO ); - setValveState( VRO, VALVE_STATE_R1_C_TO_NO ); - setValveState( VRI, VALVE_STATE_R1_C_TO_NO ); - - fillVolumeTargetMl.data = DEFAULT_FILL_VOLUME_ML; - drainVolumeTargetMl.data = DEFAULT_DRAIN_VOLUME_ML; -} - -/*********************************************************************//** - * @brief - * The execReservoirs function manages periodic tasks for the Reservoirs module. - * @details Inputs: none - * @details Outputs: Reservoir data broadcast on interval - * @return none - *************************************************************************/ -void execReservoirs( void ) + fillVolumeTargetMl.data = DEFAULT_FILL_VOLUME_ML; + drainVolumeTargetMl.data = DEFAULT_DRAIN_VOLUME_ML; +} + +/*********************************************************************//** + * @brief + * The execReservoirs function manages periodic tasks for the Reservoirs module. + * @details Inputs: none + * @details Outputs: Reservoir data broadcast on interval + * @return none + *************************************************************************/ +void execReservoirs( void ) +{ + // publish active reservoir, fill/drain volume targets at 1 Hz. + if ( ++reservoirDataPublicationTimerCounter >= RESERVOIR_DATA_PUB_INTERVAL ) + { + U32 actRes = getActiveReservoir(); + U32 filVol = getReservoirFillVolumeTargetMl(); + U32 drnVol = getReservoirDrainVolumeTargetMl(); + broadcastReservoirData( actRes, filVol, drnVol ); + reservoirDataPublicationTimerCounter = 0; + } +} + +/*********************************************************************//** + * @brief + * The setActiveReservoirCmd function sets the given reservoir as active + * (meaning HD will be drawing from this reservoir). + * @details Inputs: none + * @details Outputs: Specified reservoir is set as active. + * @param resID ID of reservoir to set as active + * @return none + *************************************************************************/ +void setActiveReservoirCmd( DG_RESERVOIR_ID_T resID ) { - // publish active reservoir, fill/drain volume targets at 1 Hz. - if ( ++reservoirDataPublicationTimerCounter >= RESERVOIR_DATA_PUB_INTERVAL ) - { - U32 actRes = getActiveReservoir(); - U32 filVol = getReservoirFillVolumeTargetMl(); - U32 drnVol = getReservoirDrainVolumeTargetMl(); - broadcastReservoirData( actRes, filVol, drnVol ); - reservoirDataPublicationTimerCounter = 0; - } -} - -/*********************************************************************//** - * @brief - * The setActiveReservoirCmd function sets the given reservoir as active - * (meaning HD will be drawing from this reservoir). - * @details Inputs: none - * @details Outputs: Specified reservoir is set as active. - * @param resID ID of reservoir to set as active - * @return none - *************************************************************************/ -void setActiveReservoirCmd( DG_RESERVOIR_ID_T resID ) -{ DG_CMD_RESPONSE_T cmdResponse; cmdResponse.commandID = DG_CMD_SWITCH_RESERVOIR; @@ -440,7 +437,21 @@ BOOL hasTargetDrainVolumeBeenReached( DG_RESERVOIR_ID_T reservoirId, U32 timeout ) { BOOL result = FALSE; - F32 const loadcellWeight = getLoadCellSmallFilteredWeight( associatedLoadCell[ reservoirId ] ); + + F32 loadcellWeight = 0.0; + + // TODO remove this code once the load cell is repaired + if ( DG_RESERVOIR_1 == reservoirId ) + { + loadcellWeight = getLoadCellSmallFilteredWeight( LOAD_CELL_RESERVOIR_1_BACKUP ); + } + else + { + loadcellWeight = getLoadCellSmallFilteredWeight( associatedLoadCell[ reservoirId ] ); + } + // TODO remove the above code the load cell is repaired + + //F32 const loadcellWeight = getLoadCellSmallFilteredWeight( associatedLoadCell[ reservoirId ] ); U32 const targetDrainVolume = getReservoirDrainVolumeTargetMl(); if ( loadcellWeight < reservoirLowestWeight[ reservoirId ] ) @@ -470,21 +481,6 @@ /*********************************************************************//** * @brief - * The resetReservoirLoadCellsOffset function sets the reservoir's load cells - * offset to zero. - * @details Inputs: associateLoadCell[], redundantLoadCell[] - * @details Outputs: reset reservoir's associate load cells auto calibration offset - * @param reservoirId reservoir id - * @return none - *************************************************************************/ -void resetReservoirLoadCellsOffset( DG_RESERVOIR_ID_T reservoirId ) -{ - resetLoadCellOffset( associatedLoadCell[ reservoirId ] ); - resetLoadCellOffset( redundantLoadCell[ reservoirId ] ); -} - -/*********************************************************************//** - * @brief * The getActiveReservoir function gets the active reservoir. * @details Inputs: activeReservoir * @details Outputs: none