Index: firmware/App/Services/Reservoirs.c =================================================================== diff -u -r5a61bccd959265c00e5276ba23391198ca82b6dd -r5ff39fd6948ae3656b4035c85325bd8fca0a37f3 --- firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 5a61bccd959265c00e5276ba23391198ca82b6dd) +++ firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 5ff39fd6948ae3656b4035c85325bd8fca0a37f3) @@ -17,6 +17,7 @@ #include // for memcpy() +#include "TaskGeneral.h" #include "OperationModes.h" #include "SystemCommMessages.h" #include "Reservoirs.h" @@ -37,8 +38,12 @@ #define MAX_DRAIN_VOLUME_ML MAX_RESERVOIR_VOLUME_ML ///> Maximum drain volume in mL. #define MIN_DRAIN_VOLUME_ML 20 ///> Minimum drain volume in mL. +#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). @@ -61,17 +66,35 @@ drainVolumeTargetMl.data = DEFAULT_DRAIN_VOLUME_ML; } +void execReservoirs( void ) +{ + // TODO - 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; + } +} + BOOL setActiveReservoir( RESERVOIR_ID_T resID ) { + BOOL result = FALSE; + // switch reservoir command only valid in re-circulate mode if ( MODE_CIRC == getCurrentOperationMode() ) { // validate parameters if ( resID < NUM_OF_RESERVOIRS ) { activeReservoir.data = (U32)resID; + result = TRUE; } } + + return result; } /*********************************************************************//**