Index: firmware/App/Modes/ModeGenIdle.c =================================================================== diff -u -rbe3f2d4ba1150228d6ed41e2ff44a15d326de020 -r38f0a6046eeccc72f3360cd189abd33a89fc3dd8 --- firmware/App/Modes/ModeGenIdle.c (.../ModeGenIdle.c) (revision be3f2d4ba1150228d6ed41e2ff44a15d326de020) +++ firmware/App/Modes/ModeGenIdle.c (.../ModeGenIdle.c) (revision 38f0a6046eeccc72f3360cd189abd33a89fc3dd8) @@ -29,6 +29,7 @@ #include "Reservoirs.h" #include "ROPump.h" #include "SystemComm.h" +#include "SystemCommMessages.h" #include "TaskGeneral.h" #include "TemperatureSensors.h" #include "Timers.h" @@ -48,14 +49,19 @@ /// The time of HD lost comm before DG transition back to standby. #define HD_LOST_COMM_TIMEOUT_MS (5 * SEC_PER_MIN * MS_PER_SECOND ) +#define BAD_FILL_SUBSTATES_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the bad fill sub-states is published on the CAN bus. // ********** private data ********** -static DG_GEN_IDLE_MODE_STATE_T genIdleState; ///< Currently active generation idle state. -static DG_GEN_IDLE_MODE_BAD_FILL_STATE_T badFillState = DG_HANDLE_BAD_FILL_STATE_START; ///< Initialize bad fill sub-state. -static U32 hdLostCommStartTime_ms = 0; ///< Lost communication with HD start time in ms. -static U32 targetFillVolumeML; ///< Save the target fill volume before calling startFillCmd(). -static BOOL handleBadFillFlag; ///< Internal signal flag to handle bad fill. +static DG_GEN_IDLE_MODE_STATE_T genIdleState; ///< Currently active generation idle state. +static DG_GEN_IDLE_MODE_BAD_FILL_STATE_T badFillState = DG_HANDLE_BAD_FILL_STATE_START; ///< Initialize bad fill sub-state. +static U32 hdLostCommStartTime_ms = 0; ///< Lost communication with HD start time in ms. +static U32 badFillSubstatesPublicationTimerCounter; ///< Used to schedule bad fill sub-states publication to CAN bus. +static U32 targetFillVolumeML; ///< Save the target fill volume before calling startFillCmd(). +static BOOL handleBadFillFlag; ///< Internal signal flag to handle bad fill. +static OVERRIDE_U32_T badFillSubstatesPublishInterval = { BAD_FILL_SUBSTATES_PUB_INTERVAL, ///< Interval (in ms) at which to publish bad fill sub-states to CAN bus. + BAD_FILL_SUBSTATES_PUB_INTERVAL, + 0, 0 }; // ********** private function prototypes ********** @@ -69,6 +75,8 @@ static DG_GEN_IDLE_MODE_BAD_FILL_STATE_T handleRefillState( void ); // idle 1.3 static DG_GEN_IDLE_MODE_BAD_FILL_STATE_T handleClearAlarmState( void ); // idle 1.4 +static void publishBadFillSubstates( void ); + /*********************************************************************//** * @brief * The initGenIdleMode function initializes the generation idle mode module. @@ -182,6 +190,7 @@ checkInletWaterTemperature(); checkInletPressure(); checkRORejectionRatio(); + publishBadFillSubstates(); // Transition to standby mode when HD is not communicating if ( TRUE == isHDCommunicating() ) @@ -409,4 +418,68 @@ return result; } +/*********************************************************************//** + * @brief + * The publishBadFillSubstates function publishes idle mode bad fill + * sub-states at the set interval. + * @details Inputs: badFillSubstatesPublicationTimerCounter + * @details Outputs: badFillSubstatesPublicationTimerCounter + * @return none + *************************************************************************/ +static void publishBadFillSubstates( void ) +{ + // publish bad fill sub-states on interval + if ( ++badFillSubstatesPublicationTimerCounter >= getU32OverrideValue( &badFillSubstatesPublishInterval ) ) + { + broadcastData( MSG_ID_DG_BAD_FILL_SUBSTATES, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&badFillState, sizeof( U32 ) ); + badFillSubstatesPublicationTimerCounter = 0; + } +} + +/*********************************************************************//** + * @brief + * The testSetBadFillSubstatesPublishIntervalOverride function overrides the + * bad fill sub-states publish interval. + * @details Inputs: badFillSubstatesPublishInterval + * @details Outputs: badFillSubstatesPublishInterval + * @param: value override bad fill sub-states publish interval with (in ms) + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetBadFillSubstatesPublishIntervalOverride( U32 value ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + U32 intvl = value / TASK_GENERAL_INTERVAL; + badFillSubstatesPublishInterval.ovData = intvl; + badFillSubstatesPublishInterval.override = OVERRIDE_KEY; + result = TRUE; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testResetBadFillSubstatesPublishIntervalOverride function resets the + * override of the bad fill sub-states publish interval. + * @details Inputs: badFillSubstatesPublishInterval + * @details Outputs: badFillSubstatesPublishInterval + * @return TRUE if override reset successful, FALSE if not + *************************************************************************/ +BOOL testResetBadFillSubstatesPublishIntervalOverride( void ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + badFillSubstatesPublishInterval.override = OVERRIDE_RESET; + badFillSubstatesPublishInterval.ovData = badFillSubstatesPublishInterval.ovInitData; + result = TRUE; + } + + return result; +} + /**@}*/