Index: firmware/App/Modes/OperationModes.c =================================================================== diff -u -r57dd046b04afac3364f6adc7d47252d73cacab4d -rf1157c760b320bf088921a25eb78e973d6341578 --- firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision 57dd046b04afac3364f6adc7d47252d73cacab4d) +++ firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision f1157c760b320bf088921a25eb78e973d6341578) @@ -7,8 +7,8 @@ * * @file OperationModes.c * -* @author (last) Michael Garthwaite -* @date (last) 17-Mar-2023 +* @author (last) Dara Navaei +* @date (last) 04-Jun-2023 * * @author (original) Dara Navaei * @date (original) 05-Nov-2019 @@ -61,6 +61,8 @@ static HD_OP_MODE_T currentMode; ///< Current operation mode. static U32 currentSubMode; ///< The currently active state of the active mode. static U32 broadcastModeIntervalCtr; ///< Interval counter used to determine when to broadcast operation mode. Initialize to 11 to stagger broadcast. +static U32 currentSubState; ///< current sub state. +static U32 current4thLevelState; ///< current 4th level state. /// Interval (in task intervals) at which to publish operation mode data to CAN bus. static OVERRIDE_U32_T opModePublishInterval = { BROADCAST_HD_OP_MODE_INTERVAL, BROADCAST_HD_OP_MODE_INTERVAL, BROADCAST_HD_OP_MODE_INTERVAL, 0 }; /// Local structure init for saving confirmation requests @@ -74,7 +76,7 @@ static const HD_OP_MODE_T MODE_TRANSITION_TABLE[ NUM_OF_MODES - 1 ][ NUM_OF_MODES - 1 ] = { // From to-> FAULT SERVICE INIT STANBY TRT.PARAMS PRE-TREAT TREATMENT POST_TREA /* FAUL */{ MODE_FAUL, MODE_SERV, MODE_NLEG, MODE_NLEG, MODE_NLEG, MODE_NLEG, MODE_NLEG, MODE_NLEG, }, -/* SERV */{ MODE_FAUL, MODE_SERV, MODE_NLEG, MODE_NLEG, MODE_NLEG, MODE_NLEG, MODE_NLEG, MODE_NLEG, }, +/* SERV */{ MODE_NLEG, MODE_SERV, MODE_NLEG, MODE_NLEG, MODE_NLEG, MODE_NLEG, MODE_NLEG, MODE_NLEG, }, /* INIT */{ MODE_FAUL, MODE_NLEG, MODE_INIT, MODE_STAN, MODE_NLEG, MODE_NLEG, MODE_NLEG, MODE_NLEG, }, /* STAN */{ MODE_FAUL, MODE_SERV, MODE_INIT, MODE_STAN, MODE_TPAR, MODE_NLEG, MODE_NLEG, MODE_NLEG, }, /* TPAR */{ MODE_FAUL, MODE_NLEG, MODE_NLEG, MODE_STAN, MODE_TPAR, MODE_PRET, MODE_NLEG, MODE_NLEG, }, @@ -88,6 +90,7 @@ static void transitionToNewOperationMode( HD_OP_MODE_T newMode ); static void broadcastOperationMode( void ); static void updateConfirmationRequestTimeouts( void ); +static void sendOperationStatusEvent( void ); /*********************************************************************//** * @brief @@ -110,6 +113,8 @@ lastMode = MODE_INIT; currentMode = MODE_INIT; currentSubMode = 0; + currentSubState = NO_SUB_STATE; + current4thLevelState = NO_SUB_STATE; broadcastModeIntervalCtr = DATA_PUBLISH_COUNTER_START_COUNT; transitionToNewOperationMode( MODE_INIT ); @@ -136,11 +141,18 @@ { HD_OP_MODE_T newMode; U32 priorSubMode = currentSubMode; + U32 priorSubState = currentSubState; + U32 priorOpMode = (U32)currentMode; + U32 prior4thLevelState = current4thLevelState; // Any new mode requests? newMode = arbitrateModeRequest(); // Will return current mode if no pending requests - newMode = MODE_TRANSITION_TABLE[ currentMode ][ newMode ]; + if ( getTestConfigStatus( TEST_CONFIG_RECOVER_TREATMENT ) != TRUE ) + { + newMode = MODE_TRANSITION_TABLE[ currentMode ][ newMode ]; + } + // Is requested new mode valid and legal at this time? if ( newMode >= MODE_NLEG ) { @@ -151,8 +163,8 @@ // Has mode changed? if ( currentMode != newMode ) { - // Handle transition to new mode lastMode = currentMode; + // Handle transition to new mode transitionToNewOperationMode( newMode ); currentMode = newMode; @@ -209,9 +221,11 @@ break; } // End switch - // Send sub-mode change event when appropriate - if ( priorSubMode != currentSubMode ) + // Send operation status event when appropriate + if ( priorOpMode != currentMode || priorSubMode != currentSubMode || + priorSubState != currentSubState || prior4thLevelState != current4thLevelState ) { + sendOperationStatusEvent(); SEND_EVENT_WITH_2_U32_DATA( HD_EVENT_SUB_MODE_CHANGE, priorSubMode, currentSubMode ) } @@ -372,8 +386,6 @@ *************************************************************************/ static void transitionToNewOperationMode( HD_OP_MODE_T newMode ) { - SEND_EVENT_WITH_2_U32_DATA( HD_EVENT_OP_MODE_CHANGE, lastMode, newMode ) - // Setup for new operating mode switch ( newMode ) { @@ -436,9 +448,9 @@ * @details Outputs: confirmRequests[] status updated if timeout. * @return none *************************************************************************/ -void updateConfirmationRequestTimeouts( void ) +static void updateConfirmationRequestTimeouts( void ) { - U08 i; + U32 i; for ( i = 0; i < MAX_PENDING_CONFIRM_REQUESTS; i++ ) { @@ -457,22 +469,22 @@ * The getConfirmationRequestStatus function returns the status of a confirmation request * @details Inputs: confirmRequests[] * @details Outputs: confirmRequests[] consumed/cleared if completed. - * @param request_id ID of confirmation being requested + * @param requestID ID of confirmation being requested * @return Status of given confirmation *************************************************************************/ -CONFIRMATION_REQUEST_STATUS_T getConfirmationRequestStatus( GENERIC_CONFIRM_ID_T request_id ) +CONFIRMATION_REQUEST_STATUS_T getConfirmationRequestStatus( GENERIC_CONFIRM_ID_T requestID ) { - U08 i; + BOOL pending = FALSE; + U32 pendingIndex = 0; CONFIRMATION_REQUEST_STATUS_T status = CONFIRMATION_REQUEST_STATUS_PENDING; - BOOL pending = FALSE; - U08 pending_index = 0; + U32 i; for ( i = 0; i < MAX_PENDING_CONFIRM_REQUESTS; i++ ) { - if ( confirmRequests[ i ].requestID == request_id ) + if ( confirmRequests[ i ].requestID == requestID ) { status = confirmRequests[ i ].status; - if ( CONFIRMATION_REQUEST_STATUS_PENDING != status ) + if ( status != CONFIRMATION_REQUEST_STATUS_PENDING ) { // Send UI clear if ( CONFIRMATION_REQUEST_STATUS_TIMEOUT == status ) @@ -496,23 +508,23 @@ if ( TRUE == pending ) { // Is this newer than other pending request? - if ( confirmRequests[ i ].timeStamp > confirmRequests[ pending_index ].timeStamp ) + if ( confirmRequests[ i ].timeStamp > confirmRequests[ pendingIndex ].timeStamp ) { - pending_index = i; - pending = TRUE; + pendingIndex = i; } } else { - pending_index = i; + pendingIndex = i; pending = TRUE; } } } + if ( ( CONFIRMATION_REQUEST_STATUS_PENDING != status ) && ( TRUE == pending ) ) { // Last confirmation cleared, pending request must be resent to UI - sendConfirmationRequest( confirmRequests[ pending_index ].requestID, confirmRequests[ pending_index ].requestType, 0 ); + sendConfirmationRequest( confirmRequests[ pendingIndex ].requestID, confirmRequests[ pendingIndex ].requestType, 0 ); } return status; @@ -523,17 +535,17 @@ * The setConfirmationRequestStatus function sets the status of a confirmation request * @details Inputs: confirmRequests[] * @details Outputs: confirmRequests[]. - * @param request_id ID of confirmation being requested + * @param requestID ID of confirmation being requested * @param status Status to set for given confirmation (open, close, reject) * @return none *************************************************************************/ -void setConfirmationRequestStatus( GENERIC_CONFIRM_ID_T request_id, CONFIRMATION_REQUEST_STATUS_T status ) +void setConfirmationRequestStatus( GENERIC_CONFIRM_ID_T requestID, CONFIRMATION_REQUEST_STATUS_T status ) { - U08 i; + U32 i; for ( i = 0; i < MAX_PENDING_CONFIRM_REQUESTS; i++ ) { - if ( confirmRequests[ i ].requestID == request_id ) + if ( confirmRequests[ i ].requestID == requestID ) { confirmRequests[ i ].status = status; break; @@ -546,35 +558,88 @@ * The addConfirmationRequest function sends a confirmation request to UI * @details Inputs: confirmRequests[] * @details Outputs: confirmRequests[] new added. - * @param request_id ID of confirmation being requested - * @param request_type Type of confirmation being requested (open, close, reject) - * @param reject_Reason Reason for reject if type is reject + * @param requestID ID of confirmation being requested + * @param requestType Type of confirmation being requested (open, close, reject) + * @param rejectReason Reason for reject if type is reject * @return request ID - will be non-zero if added *************************************************************************/ -GENERIC_CONFIRM_ID_T addConfirmationRequest( GENERIC_CONFIRM_ID_T request_id, GENERIC_CONFIRM_COMMAND_T request_type, U32 reject_reason ) +GENERIC_CONFIRM_ID_T addConfirmationRequest( GENERIC_CONFIRM_ID_T requestID, GENERIC_CONFIRM_COMMAND_T requestType, U32 rejectReason ) { - U08 i; - GENERIC_CONFIRM_ID_T new_id = GENERIC_CONFIRM_ID_NONE; + U32 i; + GENERIC_CONFIRM_ID_T newID = GENERIC_CONFIRM_ID_NONE; for ( i = 0; i < MAX_PENDING_CONFIRM_REQUESTS; i++ ) { if ( CONFIRMATION_REQUEST_STATUS_UNUSED == confirmRequests[ i ].status ) { // Save the confirmation request info - confirmRequests[ i ].requestID = request_id; - confirmRequests[ i ].requestType = request_type; + confirmRequests[ i ].requestID = requestID; + confirmRequests[ i ].requestType = requestType; confirmRequests[ i ].timeStamp = getMSTimerCount(); confirmRequests[ i ].status = CONFIRMATION_REQUEST_STATUS_PENDING; - new_id = request_id; - sendConfirmationRequest( request_id, request_type, reject_reason ); + newID = requestID; + sendConfirmationRequest( requestID, requestType, rejectReason ); break; } } - return new_id; + return newID; } +/*********************************************************************//** + * @brief + * The setCurrentSubState function sets the current subState. + * @details Inputs: subState + * @details Outputs: currentSubState + * @param subState the enumerated sub state. + * @return none + *************************************************************************/ +void setCurrentSubState( U32 subState ) +{ + currentSubState = subState; +} +/*********************************************************************//** + * @brief + * The setCurrent4thLevelState function sets the current 4th level state. + * @details Inputs: state + * @details Outputs: current4thLevelState + * @param subState the enumerated sub state. + * @return none + *************************************************************************/ +void setCurrent4thLevelState( U32 state ) +{ + current4thLevelState = state; +} + +/*********************************************************************//** + * @brief + * The sendOperationStatusEvent function constructs and sends an HD operation + * status event. + * @details Inputs: currentMode, currentSubMode, currentSubState, current4thLevelState + * @details Outputs: dat1, dat2. + * @param none + * @return none + *************************************************************************/ +static void sendOperationStatusEvent( void ) +{ + EVENT_DATA_T dat1; + EVENT_DATA_T dat2; + U32 opData = ( (U08)currentMode + + ( (U08)currentSubMode << SHIFT_8_BITS_FOR_BYTE_SHIFT ) + + ( (U08)currentSubState << SHIFT_16_BITS_FOR_WORD_SHIFT ) + + ( (U08)current4thLevelState << SHIFT_24_BITS ) ); + + dat2.dataType = EVENT_DATA_TYPE_U32; + dat2.data.uInt.data = 0; + + dat1.dataType = EVENT_DATA_TYPE_U32; + dat1.data.uInt.data = opData; + + sendEvent( HD_EVENT_OPERATION_STATUS, dat1, dat2 ); +} + + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/