Index: firmware/App/Modes/OperationModes.c =================================================================== diff -u -r70f10c77f4f9a48d51030c00504d520fe25d0ba9 -re9f15ff59ac0350adcbe544df8b3451e15ee7287 --- firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision 70f10c77f4f9a48d51030c00504d520fe25d0ba9) +++ firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision e9f15ff59ac0350adcbe544df8b3451e15ee7287) @@ -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" @@ -446,7 +448,8 @@ broadcastModeIntervalCtr = 0; data.opMode = (U32)currentMode; data.subMode = currentSubMode; - broadcastData( MSG_ID_TD_OP_MODE_DATA, COMM_BUFFER_OUT_CAN_TD_BROADCAST, (U08*)&data, sizeof( OP_MODE_PAYLOAD_T ) ); + broadcastData( MSG_ID_TD_OP_MODE_DATA, COMM_BUFFER_OUT_CAN_TD_BROADCAST, + (U08*)&data, sizeof( OP_MODE_PAYLOAD_T ) ); } } @@ -460,59 +463,71 @@ *************************************************************************/ 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 ); -// } + GENERIC_CONFIRMATION_REQUEST_T cmd = { 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.requestID = requestID; + // Send UI clear + if ( CONFIRMATION_REQUEST_STATUS_TIMEOUT == status ) + { + cmd.requestType = GENERIC_CONFIRM_CMD_TIMEOUT_CLOSE; + sendMessage( MSG_ID_TD_UI_GENERIC_CONFIRMATION_REQUEST, + COMM_BUFFER_OUT_CAN_TD_2_UI, (U08 *)&cmd, + sizeof( GENERIC_CONFIRMATION_REQUEST_T ) ); + } + else + { + cmd.requestType = GENERIC_CONFIRM_CMD_ACCEPT_CLOSE; + sendMessage( MSG_ID_TD_UI_GENERIC_CONFIRMATION_REQUEST, + COMM_BUFFER_OUT_CAN_TD_2_UI, (U08 *)&cmd, + sizeof( GENERIC_CONFIRMATION_REQUEST_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.requestType = confirmRequests[ pendingIndex ].requestType; + sendMessage( MSG_ID_TD_UI_GENERIC_CONFIRMATION_REQUEST, + COMM_BUFFER_OUT_CAN_TD_2_UI, (U08 *)&cmd, + sizeof( GENERIC_CONFIRMATION_REQUEST_T ) ); + } + return status; } @@ -551,40 +566,47 @@ *************************************************************************/ 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; + GENERIC_CONFIRMATION_REQUEST_T cmd = { 0 }; -// // 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 ) && + ( CONFIRMATION_REQUEST_STATUS_UNUSED != confirmRequests[ i ].status ) ) + { + confirmAlreadyPending = TRUE; + return requestID; + } + } + if ( confirmAlreadyPending != TRUE) + { + // Find an unused slot + for ( i = 0; i < MAX_PENDING_CONFIRM_REQUESTS; i++ ) + { + if ( CONFIRMATION_REQUEST_STATUS_UNUSED == confirmRequests[i].status ) + { + confirmRequests[ i ].requestID = requestID; + confirmRequests[ i ].requestType = requestType; + confirmRequests[ i ].timeStamp = getMSTimerCount(); + confirmRequests[ i ].status = CONFIRMATION_REQUEST_STATUS_PENDING; + + newID = requestID; + + cmd.requestID = requestID; + cmd.requestType = requestType; + cmd.rejectReason = rejectReason; + + sendMessage( MSG_ID_TD_UI_GENERIC_CONFIRMATION_REQUEST, COMM_BUFFER_OUT_CAN_TD_2_UI, + (U08 *)&cmd, sizeof( GENERIC_CONFIRMATION_REQUEST_T ) ); + + break; + } + } + } return newID; } @@ -641,7 +663,36 @@ 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: none + * @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 *************************************************************************/