Index: firmware/App/Modes/OperationModes.c =================================================================== diff -u -rdcd360fb4dc37db2dcbeb7fb14fb327fe68235f4 -rd323f2fd854e8a5a1acce3f1cc975a995a6efc37 --- firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision dcd360fb4dc37db2dcbeb7fb14fb327fe68235f4) +++ firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision d323f2fd854e8a5a1acce3f1cc975a995a6efc37) @@ -1,14 +1,14 @@ /************************************************************************** * -* Copyright (c) 2019-2021 Diality Inc. - All Rights Reserved. +* Copyright (c) 2019-2022 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * @file OperationModes.c * -* @author (last) Dara Navaei -* @date (last) 06-Nov-2021 +* @author (last) Michael Garthwaite +* @date (last) 12-Oct-2022 * * @author (original) Dara Navaei * @date (original) 05-Nov-2019 @@ -29,7 +29,9 @@ #include "ModeService.h" #include "ModeSolo.h" #include "ModeStandby.h" +#include "NVDataMgmt.h" #include "OperationModes.h" +#include "ROPump.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" @@ -40,7 +42,9 @@ // ********** private definitions ********** -#define BROADCAST_DG_OP_MODE_INTERVAL ( 250 / TASK_GENERAL_INTERVAL ) ///< interval (ms/task time) at which the operation mode is published on the CAN bus. +#define BROADCAST_DG_OP_MODE_INTERVAL ( 250 / TASK_GENERAL_INTERVAL ) ///< interval (ms/task time) at which the operation mode is published on the CAN bus. +// The data publish counter offset is a lower number to make sure DG is sending its status to the HD from the beginning and alarm 140 is not raised +#define DATA_PUBLISH_COUNTER_START_COUNT 2 ///< Data publish counter start count. // ********** private data ********** @@ -50,7 +54,7 @@ static U32 currentSubMode = 0; ///< The currently active state of the active mode. /// DG operation mode data publish interval. static OVERRIDE_U32_T dgOpModePublishInterval = { BROADCAST_DG_OP_MODE_INTERVAL, BROADCAST_DG_OP_MODE_INTERVAL, 0, 0 }; -static U32 broadcastModeIntervalCtr = 11; ///< Interval counter used to determine when to broadcast operation mode. Initialize to 11 to stagger broadcast. +static U32 dataPublishCounter; ///< Interval counter used to determine when to broadcast operation mode. Initialize to 11 to stagger broadcast. static U32 priorSubMode = 0; ///< The prior submode state. /// This matrix determines legal transitions from one mode to another. @@ -61,7 +65,7 @@ /* SERV */{ DG_MODE_FAUL, DG_MODE_SERV, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_NLEG }, /* INIT */{ DG_MODE_FAUL, DG_MODE_NLEG, DG_MODE_INIT, DG_MODE_STAN, DG_MODE_SOLO, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_NLEG }, /* STAN */{ DG_MODE_FAUL, DG_MODE_SERV, DG_MODE_NLEG, DG_MODE_STAN, DG_MODE_SOLO, DG_MODE_GENE, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_FLUS, DG_MODE_HEAT, DG_MODE_CHEM }, - /* SOLO */{ DG_MODE_FAUL, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_STAN, DG_MODE_SOLO, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_FLUS, DG_MODE_HEAT, DG_MODE_CHEM /*DG_MODE_NLEG*/ }, // TODO for testing only + /* SOLO */{ DG_MODE_FAUL, DG_MODE_SERV, DG_MODE_NLEG, DG_MODE_STAN, DG_MODE_SOLO, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_FLUS, DG_MODE_HEAT, DG_MODE_CHEM /*DG_MODE_NLEG*/ }, // TODO for testing only /* GENE */{ DG_MODE_FAUL, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_STAN, DG_MODE_NLEG, DG_MODE_GENE, DG_MODE_FILL, DG_MODE_DRAI, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_NLEG }, /* FILL */{ DG_MODE_FAUL, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_STAN, DG_MODE_NLEG, DG_MODE_GENE, DG_MODE_FILL, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_NLEG }, /* DRAI */{ DG_MODE_FAUL, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_STAN, DG_MODE_NLEG, DG_MODE_GENE, DG_MODE_NLEG, DG_MODE_DRAI, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_NLEG }, @@ -99,6 +103,8 @@ currentMode = DG_MODE_INIT; currentSubMode = 0; priorSubMode = 0; + dataPublishCounter = DATA_PUBLISH_COUNTER_START_COUNT; + transitionToNewOperationMode( DG_MODE_INIT ); // call initializers for the individual modes @@ -369,7 +375,7 @@ *************************************************************************/ static void broadcastOperationMode( void ) { - if ( ++broadcastModeIntervalCtr >= getDGOpModePublishInterval() ) + if ( ++dataPublishCounter >= getDGOpModePublishInterval() ) { OP_MODES_DATA_T data; @@ -378,7 +384,7 @@ broadcastData( MSG_ID_DG_OP_MODE, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&data, sizeof( OP_MODES_DATA_T ) ); - broadcastModeIntervalCtr = 0; + dataPublishCounter = 0; } } @@ -410,6 +416,34 @@ /*********************************************************************//** * @brief + * The testSetOperationMode function will transition to a given operation + * mode if the transition is legal. + * @details Inputs: MODE_TRANSITION_TABLE[][] + * @details Outputs: modeRequest[], result + * @param newMode ID of requested mode to transition to + * @return TRUE if request successful, FALSE if not + *************************************************************************/ +BOOL testSetOperationMode( DG_OP_MODE_T newMode ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + DG_OP_MODE_T check = MODE_TRANSITION_TABLE[ currentMode ][ newMode ]; + + // Is mode transition legal? + if ( check == newMode ) + { + requestNewOperationMode( newMode ); + result = TRUE; + } + } + + return result; +} + +/*********************************************************************//** + * @brief * The testSetDGOpModePublishIntervalOverride function overrides the * DG operation mode publish interval. * @details Inputs: none