Index: firmware/App/Modes/OperationModes.c =================================================================== diff -u -r70f10c77f4f9a48d51030c00504d520fe25d0ba9 -rad2492d1c1b63ec2727e5a7a13c5b3a4f8021f86 --- firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision 70f10c77f4f9a48d51030c00504d520fe25d0ba9) +++ firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision ad2492d1c1b63ec2727e5a7a13c5b3a4f8021f86) @@ -17,6 +17,7 @@ #include "gio.h" +#include "Buttons.h" #include "Messaging.h" #include "ModeFault.h" #include "ModeInitPOST.h" @@ -28,6 +29,7 @@ #include "ModeUpdate.h" //#include "NVDataMgmt.h" #include "OperationModes.h" +#include "SystemCommTD.h" #include "TaskGeneral.h" #include "Timers.h" @@ -460,59 +462,66 @@ *************************************************************************/ 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; + UI_PAYLOAD_T cmd; + cmd.id = 0; + cmd.reason = 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; -// } -// } -// 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 ) + { + cmd.id = requestID; + // Send UI clear + if ( CONFIRMATION_REQUEST_STATUS_TIMEOUT == status ) + { + cmd.command = GENERIC_CONFIRM_CMD_TIMEOUT_CLOSE; + sendMessage( MSG_ID_TD_UI_GENERIC_CONFIRMATION_REQUEST, COMM_BUFFER_OUT_CAN_TD_2_UI, (U08 *)&cmd, sizeof( UI_PAYLOAD_T ) ); + } + else + { + cmd.command = GENERIC_CONFIRM_CMD_ACCEPT_CLOSE; + sendMessage( MSG_ID_TD_UI_GENERIC_CONFIRMATION_REQUEST, COMM_BUFFER_OUT_CAN_TD_2_UI, (U08 *)&cmd, sizeof( UI_PAYLOAD_T ) ); + } + // 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 + cmd.command = confirmRequests[ pendingIndex ].requestType; + sendMessage( MSG_ID_TD_UI_GENERIC_CONFIRMATION_REQUEST, COMM_BUFFER_OUT_CAN_TD_2_UI, (U08 *)&cmd, sizeof( UI_PAYLOAD_T ) ); + } + return status; } @@ -551,40 +560,42 @@ *************************************************************************/ GENERIC_CONFIRM_ID_T addConfirmationRequest( GENERIC_CONFIRM_ID_T requestID, GENERIC_CONFIRM_COMMAND_T requestType, U32 rejectReason ) { -// U32 i; -// BOOL confirmAlreadyPending = FALSE; + U32 i; GENERIC_CONFIRM_ID_T newID = GENERIC_CONFIRM_ID_NONE; + UI_PAYLOAD_T cmd; -// // 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 whether this confirmation is already pending + for ( i = 0; i < MAX_PENDING_CONFIRM_REQUESTS; i++ ) + { + if ( ( confirmRequests[i].requestID == requestID ) && + ( confirmRequests[i].status == CONFIRMATION_REQUEST_STATUS_PENDING ) ) + { + return requestID; + } + } + // Find an unused slot + for ( i = 0; i < MAX_PENDING_CONFIRM_REQUESTS; i++ ) + { + if ( confirmRequests[i].status == CONFIRMATION_REQUEST_STATUS_UNUSED ) + { + confirmRequests[i].requestID = requestID; + confirmRequests[i].requestType = requestType; + confirmRequests[i].timeStamp = getMSTimerCount(); + confirmRequests[i].status = CONFIRMATION_REQUEST_STATUS_PENDING; + + newID = requestID; + + cmd.id = requestID; + cmd.command = requestType; + cmd.reason = rejectReason; + + sendMessage( MSG_ID_TD_UI_GENERIC_CONFIRMATION_REQUEST, COMM_BUFFER_OUT_CAN_TD_2_UI, (U08 *)&cmd, sizeof( UI_PAYLOAD_T ) ); + + break; + } + } + return newID; } @@ -641,7 +652,35 @@ sendEvent( TD_EVENT_OPERATION_STATUS, dat1, dat2 ); } +/*********************************************************************//** + * @brief + * The handleUIConfirmationResponse function handles a UI response for + * confirmation request. + * @details \b Inputs: none + * @details \b Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +BOOL handleUIConfirmationResponse( MESSAGE_T *message ) +{ + BOOL result = FALSE; + U32 request_id; + U32 status; + if ( message->hdr.payloadLen == (2 * sizeof(U32)) ) + { + memcpy( &request_id, &message->payload[0], sizeof(U32) ); + memcpy( &status, &message->payload[sizeof(U32)], sizeof(U32) ); + + setConfirmationRequestStatus( (GENERIC_CONFIRM_ID_T)request_id, (CONFIRMATION_REQUEST_STATUS_T)status ); + + result = TRUE; + } + + return result; +} + + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/