Index: firmware/App/Services/Messaging.c =================================================================== diff -u -rcd3af1ebb7396ba3b2bec1d779510d29c30014f4 -r52ded7b22d4b413aa8182f1343e4fbb78e8c3b0a --- firmware/App/Services/Messaging.c (.../Messaging.c) (revision cd3af1ebb7396ba3b2bec1d779510d29c30014f4) +++ firmware/App/Services/Messaging.c (.../Messaging.c) (revision 52ded7b22d4b413aa8182f1343e4fbb78e8c3b0a) @@ -23,6 +23,7 @@ #include "OperationModes.h" #include "Utilities.h" #include "SystemCommDD.h" +#include "PAL.h" /** * @addtogroup Messaging @@ -42,6 +43,44 @@ #pragma pack(pop) +/// Array of CAN communication buffers to respond on (aligned with enum Comm_Buffers). +static const COMM_BUFFER_T tdResponseBuffers[ NUM_OF_COMM_BUFFERS ] = +{ + COMM_BUFFER_NOT_USED, ///< CAN message boxes start at 1 so we will not use this buffer + COMM_BUFFER_OUT_CAN_DD_ALARM, ///< Buffer for responding to incoming TD alarm messages + COMM_BUFFER_NOT_USED, ///< Buffer for outgoing DD alarm messages so no response buffer + COMM_BUFFER_OUT_CAN_DD_ALARM, ///< Buffer for responding to incoming RO alarm messages + COMM_BUFFER_OUT_CAN_DD_ALARM, ///< Buffer for responding to incoming UI alarm messages + COMM_BUFFER_OUT_CAN_DD_2_TD, ///< Buffer for responding to incoming TD to DD messages + COMM_BUFFER_NOT_USED, ///< Buffer for outgoing DD to TD messages so no response buffer + COMM_BUFFER_NOT_USED, ///< Buffer for outgoing DD to RO messages so no response buffer + COMM_BUFFER_OUT_CAN_DD_2_RO, ///< Buffer for responding to incoming RO to DD messages + COMM_BUFFER_OUT_CAN_DD_BROADCAST, ///< Buffer for responding to incoming TD broadcast messages + COMM_BUFFER_NOT_USED, ///< Buffer for outgoing DD broadcast messages so no response buffer + COMM_BUFFER_OUT_CAN_DD_BROADCAST, ///< Buffer for responding to incoming RO broadcast messages + COMM_BUFFER_OUT_CAN_DD_BROADCAST, ///< Buffer for responding to incoming UI broadcast messages + COMM_BUFFER_OUT_CAN_PC, ///< Buffer for responding to incoming PC to TD messages + COMM_BUFFER_NOT_USED, ///< Buffer for outgoing HD to PC messages so no response buffer +}; + + +typedef BOOL (*MsgFuncPtr)( MESSAGE_T* ); + +/// Message handling function lookup table +static const U16 MSG_FUNCTION_HANDLER_LOOKUP[] = { + MSG_ID_TESTER_LOGIN_REQUEST, + MSG_ID_DD_SOFTWARE_RESET_REQUEST +}; + +/// Message handling function table +static const MsgFuncPtr MSG_FUNCTION_HANDLERS[] = { + &handleTesterLogInRequest, + &handleDDSoftwareResetRequest +}; + +#define NUM_OF_FUNCTION_HANDLERS (sizeof(MSG_FUNCTION_HANDLERS) / sizeof(MsgFuncPtr)) + + // ********** private data ********** static BOOL testerLoggedIn = FALSE; ///< Flag indicates whether tester logged in or not. @@ -53,7 +92,6 @@ static BOOL sendTestAckResponseMsg( MSG_ID_T msgID, BOOL ack ); static BOOL sendAckResponseMsg( MSG_ID_T msgID, COMM_BUFFER_T buffer, BOOL ack ); -static BOOL sendUIResponseMsg( MSG_ID_T msgID, UI_RESPONSE_PAYLOAD_T *uiResponse ); /*********************************************************************//** * @brief @@ -110,9 +148,9 @@ // add 8-bit CRC data[ msgSize++ ] = crc; - // pad with zero bytes to get length a multiple of CAN_MESSAGE_PAYLOAD_SIZE (8) - sizeMod = msgSize % CAN_MESSAGE_PAYLOAD_SIZE; - sizePad = ( sizeMod == 0 ? 0 : CAN_MESSAGE_PAYLOAD_SIZE - sizeMod ); + // pad with zero bytes to get length a multiple of CAN_FRAME_PAYLOAD_SIZE (8) + sizeMod = msgSize % CAN_FRAME_PAYLOAD_SIZE; + sizePad = ( sizeMod == 0 ? 0 : CAN_FRAME_PAYLOAD_SIZE - sizeMod ); for ( i = 0; i < sizePad; i++ ) { data[ msgSize++ ] = 0; @@ -124,7 +162,7 @@ if ( FALSE == addMsgToPendingACKList( &msg, buffer, data, msgSize ) ) { error = TRUE; - //SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_MSG_PENDING_ACK_LIST_FULL ) + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_MSG_PENDING_ACK_LIST_FULL ) } } @@ -169,7 +207,7 @@ /*********************************************************************//** * @brief * The sendTestAckResponseMsg function constructs a simple response message for - * a handled test message and queues it for transmit on the appropriate UART channel. + * a handled test message and queues it for transmit on the appropriate CAN channel. * @details Inputs: none * @details Outputs: response message constructed and queued for transmit. * @param msgID ID of handled message that we are responding to @@ -196,37 +234,72 @@ /*********************************************************************//** * @brief - * The sendUIResponseMsg function constructs an UI response message for a - * handled UI message and queues it for transmit on the appropriate CAN channel. - * @details Inputs: none - * @details Outputs: response message constructed and queued for transmit. - * @param msgID ID of handled message that we are responding to - * @param ui response pointer to the UI response payload - * @return TRUE if response message successfully queued for transmit, FALSE if not + * The getMsgHandler function finds the appropriate handler function + * for the given message. + * @details Inputs: MSG_FUNCTION_HANDLER_LOOKUP[], MSG_FUNCTION_HANDLERS[] + * @details Outputs: none + * @param msgID ID of message to find handler function for + * @return pointer to appropriate function to handle given message *************************************************************************/ -static BOOL sendUIResponseMsg( MSG_ID_T msgID, UI_RESPONSE_PAYLOAD_T *uiResponse ) +static MsgFuncPtr getMsgHandler( U16 msgID ) { - BOOL result; - MESSAGE_T msg; - UI_RESPONSE_PAYLOAD_T cmd; + U32 i; + MsgFuncPtr func = 0; - cmd.fwValue = uiResponse->fwValue; - cmd.accepted = uiResponse->accepted; - cmd.rejectionReason = uiResponse->rejectionReason; + // Search for the index associated with the given override command message ID and then use index to get the handling function + for ( i = 0; i < NUM_OF_FUNCTION_HANDLERS; i++ ) + { + if ( MSG_FUNCTION_HANDLER_LOOKUP[i] == msgID ) + { + func = MSG_FUNCTION_HANDLERS[i]; + break; + } + } + return func; +} - // Create a message record - blankMessage( &msg ); - msg.hdr.msgID = msgID; - msg.hdr.payloadLen = sizeof( UI_RESPONSE_PAYLOAD_T ); - memcpy( &msg.payload, &cmd, sizeof( UI_RESPONSE_PAYLOAD_T ) ); +/*********************************************************************//** + * @brief + * The handleIncomingMessage function calls the appropriate handler function + * for the given message. + * @details Inputs: none + * @details Outputs: Appropriate message handler function called + * @param message Incoming message to handle + * @return none + *************************************************************************/ +void handleIncomingMessage( MESSAGE_T *message ) +{ + BOOL ack = FALSE; // assume we will NAK until we have successful handling of message + COMM_BUFFER_T respBuffer = tdResponseBuffers[ message->in_buffer ]; - // Serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer - //result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_DD_2_UI, ACK_REQUIRED ); + // if Dialin message, ensure Dialin is logged in before processing it + if ( ( message->hdr.msgID <= MSG_ID_FIRST_DD_TESTER_MESSAGE ) || + ( TRUE == isTestingActivated() ) ) + { + MsgFuncPtr msgFuncPtr; - return result; + // Find the appropriate message handling function to call + msgFuncPtr = getMsgHandler( message->hdr.msgID ); + // Ensure a handler is found before calling it + if ( msgFuncPtr != 0 ) + { // Call the appropriate message handling function + ack = (*msgFuncPtr)( message ); + } + } + // ACK/NAK request + if ( message->hdr.msgID < MSG_ID_FIRST_DD_TESTER_MESSAGE ) + { + if ( respBuffer != COMM_BUFFER_NOT_USED ) + { + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, respBuffer, ack ); + } + } + else + { + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, ack ); + } } - // *********************************************************************** // ***************** Message Sending Helper Functions ******************** // *********************************************************************** @@ -262,7 +335,8 @@ memcpy( &msg.payload, &eventStruct, sizeof( EVENT_PAYLOAD_T ) ); // Serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer - //result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_DD_2_UI, ACK_NOT_REQUIRED ); + // TODO : validate the change , DD -> UI channel removed and added DD broadcast instead. + result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_DD_BROADCAST, ACK_NOT_REQUIRED ); return result; } @@ -436,7 +510,7 @@ * @param message a pointer to the message to handle * @return none *************************************************************************/ -void handleTesterLogInRequest( MESSAGE_T *message ) +BOOL handleTesterLogInRequest( MESSAGE_T *message ) { // verify pass code // TODO - placeholder - how do we want to authenticate tester? @@ -452,6 +526,33 @@ } // respond to would be tester sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, testerLoggedIn ); + + return testerLoggedIn; } +/*********************************************************************//** + * @brief + * The handleTDSoftwareResetRequest function handles a request to reset the + * TD firmware processor. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return FALSE if reset command rejected (won't return if reset successful) + *************************************************************************/ +BOOL handleDDSoftwareResetRequest( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + // Verify payload length + if ( 0 == message->hdr.payloadLen ) + { // S/w reset of processor + result = TRUE; // Reset will prevent this from getting transmitted though + setSystemREG1_SYSECR( (0x2) << 14 ); // Reset processor + } + + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); + + return result; +} + /**@}*/