Index: firmware/App/Modes/OperationModes.c =================================================================== diff -u -r6264a775ffd3bd50c9146e93a5e6f50b21f2981f -ra6e1a62344275a14e4edde1bdda9974eef840827 --- firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision 6264a775ffd3bd50c9146e93a5e6f50b21f2981f) +++ firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision a6e1a62344275a14e4edde1bdda9974eef840827) @@ -1,22 +1,23 @@ /************************************************************************** * -* Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. +* Copyright (c) 2019-2021 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 +* @file OperationModes.c * -* @author (last) Quang Nguyen -* @date (last) 24-Aug-2020 +* @author (last) Sean Nash +* @date (last) 12-Nov-2021 * -* @author (original) Dara Navaei -* @date (original) 05-Nov-2019 +* @author (original) Dara Navaei +* @date (original) 05-Nov-2019 * ***************************************************************************/ #include "gio.h" +#include "MessageSupport.h" #include "ModeChemicalDisinfect.h" #include "ModeDrain.h" #include "ModeFault.h" @@ -50,6 +51,7 @@ /// 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 priorSubMode = 0; ///< The prior submode state. /// This matrix determines legal transitions from one mode to another. static const DG_OP_MODE_T MODE_TRANSITION_TABLE[ NUM_OF_DG_MODES - 1 ][ NUM_OF_DG_MODES - 1 ] = @@ -96,6 +98,7 @@ // start in init mode currentMode = DG_MODE_INIT; currentSubMode = 0; + priorSubMode = 0; transitionToNewOperationMode( DG_MODE_INIT ); // call initializers for the individual modes @@ -122,8 +125,9 @@ void execOperationModes( void ) { DG_OP_MODE_T newMode; - U32 priorSubMode = currentSubMode; + priorSubMode = currentSubMode; + // any new mode requests? newMode = arbitrateModeRequest(); // will return current mode if no pending requests newMode = MODE_TRANSITION_TABLE[ currentMode ][ newMode ]; @@ -139,7 +143,6 @@ if ( currentMode != newMode ) { // handle transition to new mode - priorSubMode = 0; lastMode = currentMode; transitionToNewOperationMode( newMode ); currentMode = newMode; @@ -202,8 +205,9 @@ // Send sub-mode change event when appropriate if ( priorSubMode != currentSubMode ) { - SEND_EVENT_WITH_2_U32_DATA( DG_EVENT_SUB_MODE_CHANGE, priorSubMode, currentSubMode ); + SEND_EVENT_WITH_2_U32_DATA( DG_EVENT_SUB_MODE_CHANGE, priorSubMode, currentSubMode ) } + priorSubMode = currentSubMode; // publish op mode on interval @@ -305,48 +309,52 @@ *************************************************************************/ static void transitionToNewOperationMode( DG_OP_MODE_T newMode ) { - SEND_EVENT_WITH_2_U32_DATA( DG_EVENT_OP_MODE_CHANGE, lastMode, newMode ); + SEND_EVENT_WITH_2_U32_DATA( DG_EVENT_OP_MODE_CHANGE, lastMode, newMode ) // setup for new operating mode switch ( newMode ) { case DG_MODE_FAUL: - transitionToFaultMode(); + currentSubMode = transitionToFaultMode(); break; case DG_MODE_SERV: - transitionToServiceMode(); + currentSubMode = transitionToServiceMode(); break; case DG_MODE_INIT: - transitionToInitAndPOSTMode(); + currentSubMode = transitionToInitAndPOSTMode(); break; case DG_MODE_STAN: - transitionToStandbyMode(); + currentSubMode = transitionToStandbyMode(); break; case DG_MODE_SOLO: - transitionToSoloMode(); + currentSubMode = transitionToSoloMode(); break; case DG_MODE_GENE: - transitionToGenIdleMode(); + currentSubMode = transitionToGenIdleMode(); break; case DG_MODE_FILL: - transitionToFillMode(); + currentSubMode = transitionToFillMode(); break; case DG_MODE_DRAI: - transitionToDrainMode(); + currentSubMode = transitionToDrainMode(); break; case DG_MODE_FLUS: - transitionToFlushMode(); + currentSubMode = transitionToFlushMode(); break; case DG_MODE_HEAT: - transitionToHeatDisinfectMode(); + currentSubMode = transitionToHeatDisinfectMode(); break; case DG_MODE_CHEM: - transitionToChemicalDisinfectMode(); + currentSubMode = transitionToChemicalDisinfectMode(); break; default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_OP_MODES_INVALID_MODE_TO_TRANSITION_TO, (U32)newMode ) break; } + + SEND_EVENT_WITH_2_U32_DATA( DG_EVENT_SUB_MODE_CHANGE, priorSubMode, currentSubMode ) + + priorSubMode = currentSubMode; } /*********************************************************************//** @@ -361,8 +369,14 @@ { if ( ++broadcastModeIntervalCtr >= getDGOpModePublishInterval() ) { + OP_MODES_DATA_T data; + + data.currentMode = (U32)currentMode; + data.currentSubMode = currentSubMode; + + broadcastData( MSG_ID_DG_OP_MODE, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&data, sizeof( OP_MODES_DATA_T ) ); + broadcastModeIntervalCtr = 0; - broadcastDGOperationMode( (U32)currentMode, currentSubMode ); } }