Index: firmware/App/Modes/OperationModes.c =================================================================== diff -u -r70f10c77f4f9a48d51030c00504d520fe25d0ba9 -r1275f9e92eb1ab0cd1b321c0c8eb940524e22117 --- firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision 70f10c77f4f9a48d51030c00504d520fe25d0ba9) +++ firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision 1275f9e92eb1ab0cd1b321c0c8eb940524e22117) @@ -41,6 +41,7 @@ #define BROADCAST_TD_OP_MODE_INTERVAL ( 250 / TASK_GENERAL_INTERVAL ) ///< TD operation mode broadcast interval (in task interval/sec). #define DATA_PUBLISH_COUNTER_START_COUNT 11 ///< Data publish counter start count. #define MAX_PENDING_CONFIRM_REQUESTS 4 ///< Maximum number of confirmation requests allowed at any given time. +#define CONFIRMATION_DIALOG_TIMEOUT_MS ( 60U * MS_PER_SECOND ) ///< Timeout period for user confirmation dialogs (ms). /// Structure for confirmation request. typedef struct @@ -61,6 +62,8 @@ static U32 currentSubState; ///< current sub state. static U32 current4thLevelState; ///< current 4th level state. +static U32 pendingConfirmIndex; ///< Index of pending confirm requests + /// Interval (in task intervals) at which to publish operation mode data to CAN bus. static OVERRIDE_U32_T opModePublishInterval; /// Local structure init for saving confirmation requests @@ -116,6 +119,7 @@ opModePublishInterval.ovData = BROADCAST_TD_OP_MODE_INTERVAL; opModePublishInterval.ovInitData = BROADCAST_TD_OP_MODE_INTERVAL; opModePublishInterval.override = OVERRIDE_RESET; + pendingConfirmIndex = MAX_PENDING_CONFIRM_REQUESTS; transitionToNewOperationMode( MODE_INIT ); @@ -460,59 +464,60 @@ *************************************************************************/ CONFIRMATION_REQUEST_STATUS_T getConfirmationRequestStatus( GENERIC_CONFIRM_ID_T requestID ) { -// BOOL pending = FALSE; -// U32 pendingIndex = 0; + BOOL pending = FALSE; + U32 pendingIndex = 0; CONFIRMATION_REQUEST_STATUS_T status = CONFIRMATION_REQUEST_STATUS_PENDING; -// U32 i; + U32 i; -// for ( i = 0; i < MAX_PENDING_CONFIRM_REQUESTS; i++ ) -// { -// if ( confirmRequests[ i ].requestID == requestID ) -// { -// status = confirmRequests[ i ].status; -// if ( status != CONFIRMATION_REQUEST_STATUS_PENDING ) -// { -// // Send UI clear -// if ( CONFIRMATION_REQUEST_STATUS_TIMEOUT == status ) -// { -// sendConfirmationRequest( confirmRequests[ i ].requestID, GENERIC_CONFIRM_CMD_TIMEOUT_CLOSE, 0 ); -// } -// else -// { -// sendConfirmationRequest( confirmRequests[ i ].requestID, GENERIC_CONFIRM_CMD_ACCEPT_CLOSE, 0 ); -// } -// -// // Clear the confirmation request, it is done and consumed -// confirmRequests[ i ].requestID = GENERIC_CONFIRM_ID_NONE; -// confirmRequests[ i ].requestType = GENERIC_CONFIRM_CMD_REQUEST_OPEN; -// confirmRequests[ i ].timeStamp = 0; -// confirmRequests[ i ].status = CONFIRMATION_REQUEST_STATUS_UNUSED; -// } -// } -// else if ( CONFIRMATION_REQUEST_STATUS_PENDING == confirmRequests[ i ].status ) -// { -// if ( TRUE == pending ) -// { -// // Is this newer than other pending request? -// if ( confirmRequests[ i ].timeStamp > confirmRequests[ pendingIndex ].timeStamp ) -// { -// pendingIndex = i; -// } -// } -// else -// { -// pendingIndex = i; -// pending = TRUE; -// } -// } -// } -// -// if ( ( CONFIRMATION_REQUEST_STATUS_PENDING != status ) && ( TRUE == pending ) ) -// { -// // Last confirmation cleared, pending request must be resent to UI -// sendConfirmationRequest( confirmRequests[ pendingIndex ].requestID, confirmRequests[ pendingIndex ].requestType, 0 ); -// } + for ( i = 0; i < MAX_PENDING_CONFIRM_REQUESTS; i++ ) + { + if ( confirmRequests[ i ].requestID == requestID ) + { + status = confirmRequests[ i ].status; + if ( status != CONFIRMATION_REQUEST_STATUS_PENDING ) + { + // Send UI clear + if ( CONFIRMATION_REQUEST_STATUS_TIMEOUT == status ) + { + sendConfirmationRequest( confirmRequests[ i ].requestID, GENERIC_CONFIRM_CMD_TIMEOUT_CLOSE, 0 ); + } + else + { + sendConfirmationRequest( confirmRequests[ i ].requestID, GENERIC_CONFIRM_CMD_ACCEPT_CLOSE, 0 ); + } + // Clear the confirmation request, it is done and consumed + confirmRequests[ i ].requestID = GENERIC_CONFIRM_ID_NONE; + confirmRequests[ i ].requestType = GENERIC_CONFIRM_CMD_REQUEST_OPEN; + confirmRequests[ i ].timeStamp = 0; + confirmRequests[ i ].status = CONFIRMATION_REQUEST_STATUS_UNUSED; + pendingConfirmIndex = MAX_PENDING_CONFIRM_REQUESTS; + } + } + else if ( CONFIRMATION_REQUEST_STATUS_PENDING == confirmRequests[ i ].status ) + { + if ( TRUE == pending ) + { + // Is this newer than other pending request? + if ( confirmRequests[ i ].timeStamp > confirmRequests[ pendingIndex ].timeStamp ) + { + pendingIndex = i; + } + } + else + { + pendingIndex = i; + pending = TRUE; + } + } + } + + if ( ( CONFIRMATION_REQUEST_STATUS_PENDING != status ) && ( TRUE == pending ) ) + { + // Last confirmation cleared, pending request must be resent to UI + sendConfirmationRequest( confirmRequests[ pendingIndex ].requestID, confirmRequests[ pendingIndex ].requestType, 0 ); + } + return status; } @@ -551,40 +556,41 @@ *************************************************************************/ GENERIC_CONFIRM_ID_T addConfirmationRequest( GENERIC_CONFIRM_ID_T requestID, GENERIC_CONFIRM_COMMAND_T requestType, U32 rejectReason ) { -// U32 i; -// BOOL confirmAlreadyPending = FALSE; + U32 i; + BOOL confirmAlreadyPending = FALSE; GENERIC_CONFIRM_ID_T newID = GENERIC_CONFIRM_ID_NONE; -// // Check to make sure specified confirmation is not already pending -// for ( i = 0; i < MAX_PENDING_CONFIRM_REQUESTS; i++ ) -// { -// if ( ( confirmRequests[ i ].requestID == requestID ) && -// ( confirmRequests[ i ].status != CONFIRMATION_REQUEST_STATUS_UNUSED ) ) -// { -// confirmAlreadyPending = TRUE; -// break; -// } -// } -// -// // If not already pending, add confirmation to list of pending confirmations and send to UI to be displayed -// if ( confirmAlreadyPending != TRUE ) -// { -// 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 = requestID; -// confirmRequests[ i ].requestType = requestType; -// confirmRequests[ i ].timeStamp = getMSTimerCount(); -// confirmRequests[ i ].status = CONFIRMATION_REQUEST_STATUS_PENDING; -// newID = requestID; -// sendConfirmationRequest( requestID, requestType, rejectReason ); -// break; -// } -// } -// } + // Check to make sure specified confirmation is not already pending + for ( i = 0; i < MAX_PENDING_CONFIRM_REQUESTS; i++ ) + { + if ( ( confirmRequests[ i ].requestID == requestID ) && + ( confirmRequests[ i ].status != CONFIRMATION_REQUEST_STATUS_UNUSED ) ) + { + confirmAlreadyPending = TRUE; + break; + } + } + // If not already pending, add confirmation to list of pending confirmations and send to UI to be displayed + if ( confirmAlreadyPending != TRUE ) + { + 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 = requestID; + confirmRequests[ i ].requestType = requestType; + confirmRequests[ i ].timeStamp = getMSTimerCount(); + confirmRequests[ i ].status = CONFIRMATION_REQUEST_STATUS_PENDING; + newID = requestID; + pendingConfirmIndex = i; + sendConfirmationRequest( requestID, requestType, rejectReason ); + break; + } + } + } + return newID; } @@ -641,7 +647,48 @@ sendEvent( TD_EVENT_OPERATION_STATUS, dat1, dat2 ); } +/*********************************************************************//** + * @brief + * The handleConfirmationDialogTimeout function checks if a pending + * confirmation dialog has exceeded the timeout period and triggers + * a timeout if so. + * @details \b Inputs: confirmRequests[], pendingConfirmIndex + * @details \b Outputs: confirmRequests[], pendingConfirmIndex + * @return none + *************************************************************************/ +void handleConfirmationDialogTimeout( void ) +{ + if ( ( pendingConfirmIndex < MAX_PENDING_CONFIRM_REQUESTS ) && + ( CONFIRMATION_REQUEST_STATUS_PENDING == confirmRequests[ pendingConfirmIndex ].status ) && + ( TRUE == didTimeout( confirmRequests[ pendingConfirmIndex ].timeStamp, CONFIRMATION_DIALOG_TIMEOUT_MS ) ) ) + { + confirmRequests[ pendingConfirmIndex ].status = CONFIRMATION_REQUEST_STATUS_TIMEOUT; + pendingConfirmIndex = MAX_PENDING_CONFIRM_REQUESTS; + } +} +/*********************************************************************//** + * @brief + * The getPendingConfirmationID function returns the ID of the currently + * pending confirmation dialog + * @details \b Inputs: pendingConfirmIndex, confirmRequests[] + * @details \b Outputs: none + * @return ID of the currently pending confirmation dialog, or + * GENERIC_CONFIRM_ID_NONE if no confirmation dialog is pending. + *************************************************************************/ +GENERIC_CONFIRM_ID_T getPendingConfirmationID( void ) +{ + GENERIC_CONFIRM_ID_T result = GENERIC_CONFIRM_ID_NONE; + + if ( pendingConfirmIndex < MAX_PENDING_CONFIRM_REQUESTS ) + { + result = confirmRequests[ pendingConfirmIndex ].requestID; + } + + return result; +} + + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/