Index: firmware/App/Services/Messaging.c =================================================================== diff -u -r73d8423edc56daed591bc0b3f7baee5540aea423 -r1631728a0f2506fb4e29c5f6c6e1a5f55018caab --- firmware/App/Services/Messaging.c (.../Messaging.c) (revision 73d8423edc56daed591bc0b3f7baee5540aea423) +++ firmware/App/Services/Messaging.c (.../Messaging.c) (revision 1631728a0f2506fb4e29c5f6c6e1a5f55018caab) @@ -42,6 +42,40 @@ } BLOCKED_MSGS_DATA_T; #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_NOT_USED, ///< Buffer for outgoing TD alarm messages so no response buffer + COMM_BUFFER_OUT_CAN_TD_ALARM, ///< Buffer for responding to incoming DD alarm messages + COMM_BUFFER_OUT_CAN_TD_ALARM, ///< Buffer for responding to incoming RO alarm messages + COMM_BUFFER_OUT_CAN_TD_ALARM, ///< Buffer for responding to incoming UI alarm messages + COMM_BUFFER_NOT_USED, ///< Buffer for outgoing TD to DD messages so no response buffer + COMM_BUFFER_OUT_CAN_TD_2_DD, ///< Buffer for responding to incoming DD to HD messages + COMM_BUFFER_NOT_USED, ///< Buffer for outgoing TD to UI messages so no response buffer + COMM_BUFFER_OUT_CAN_TD_2_UI, ///< Buffer for responding to incoming UI to HD messages + COMM_BUFFER_NOT_USED, ///< Buffer for outgoing TD broadcast messages so no response buffer + COMM_BUFFER_OUT_CAN_TD_BROADCAST, ///< Buffer for responding to incoming DD broadcast messages + COMM_BUFFER_OUT_CAN_TD_BROADCAST, ///< Buffer for responding to incoming RO broadcast messages + COMM_BUFFER_OUT_CAN_TD_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[][2] = { + { MSG_ID_TESTER_LOGIN_REQUEST, 0 }, +}; + +/// Message handling function table +static const MsgFuncPtr MSG_FUNCTION_HANDLERS[] = { + &handleTesterLogInRequest, +}; + +#define NUM_OF_FUNCTION_HANDLERS (sizeof(MSG_FUNCTION_HANDLERS) / sizeof(MsgFuncPtr)) + // ********** private data ********** static BOOL testerLoggedIn = FALSE; ///< Flag indicates whether an external tester (connected PC) has sent a valid login message. @@ -52,10 +86,10 @@ // ********** private function prototypes ********** +static MsgFuncPtr getMsgHandler( U16 msgID ); 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, BOOL accepted, U32 reason ); -static void sendInstitutionalRecordToUI( HD_INSTITUTIONAL_LOCAL_RECORD_T* instit ); /*********************************************************************//** * @brief @@ -225,6 +259,72 @@ /*********************************************************************//** * @brief + * The getMsgHandler function finds the appropriate handler function + * for the given message. + * @details Inputs: MSG_FUNCTION_HANDLER_LOOKUP[], + * @details Outputs: Appropriate message handler function called + * @param message Incoming message to handle + * @return none + *************************************************************************/ +static MsgFuncPtr getMsgHandler( U16 msgID ) +{ + U32 i; +// U32 numOfHandlers = sizeof(MSG_FUNCTION_HANDLERS) / sizeof(MsgFuncPtr); + MsgFuncPtr func = 0; + + // 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][0] == msgID ) + { + func = MSG_FUNCTION_HANDLERS[i]; + break; + } + } + return func; +} + +/*********************************************************************//** + * @brief + * The handleIncomingMessage function calls the appropriate handler function + * for the given message. + * @details Inputs: + * @details Outputs: Appropriate message handler function called + * @param message Incoming message to handle + * @return none + *************************************************************************/ +void handleIncomingMessage( MESSAGE_T *message ) +{ + BOOL result = FALSE; // assume we will NAK until we have successful handling of message + COMM_BUFFER_T respBuffer = tdResponseBuffers[ message->in_buffer ]; + + // if Dialin message, ensure Dialin is logged in before processing it + if ( ( message->hdr.msgID <= MSG_ID_FIRST_TD_TESTER_MESSAGE ) || + ( TRUE == isTestingActivated() ) ) + { + MsgFuncPtr msgFuncPtr; + + // 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 override command handling function with the given override parameters + result = (*msgFuncPtr)( message ); + } + } + // ACK/NAK request + if ( message->hdr.msgID < MSG_ID_FIRST_TD_TESTER_MESSAGE ) + { + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, respBuffer, result ); + } + else + { + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); + } +} + +/*********************************************************************//** + * @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 @@ -263,57 +363,39 @@ /*********************************************************************//** * @brief - * The sendInstitutionalRecordToUI function sends the institutional record to UI + * The sendEvent function constructs an TD event message to the UI and + * queues the msg for transmit on the appropriate CAN channel. * @details Inputs: none - * @details Outputs: none - * @param instit a pointer to the local institutional recored in the system - * messages that is without calibration time and crc - * @return none + * @details Outputs: TD event msg constructed and queued. + * @param event Enumeration of event type that occurred + * @param dat1 First data associated with event + * @param dat2 Second data associated with event + * @return TRUE if msg successfully queued for transmit, FALSE if not *************************************************************************/ -static void sendInstitutionalRecordToUI( HD_INSTITUTIONAL_LOCAL_RECORD_T* instit ) +BOOL sendEvent( TD_EVENT_ID_T event, EVENT_DATA_T dat1, EVENT_DATA_T dat2 ) { + BOOL result; MESSAGE_T msg; + EVENT_PAYLOAD_T eventStruct; - U08 *payloadPtr = msg.payload; - U32 accept = 1; - U32 reason = 0; + eventStruct.event = (U32)event; + eventStruct.dataType1 = (U32)dat1.dataType; + eventStruct.data1 = dat1.data; + eventStruct.dataType2 = (U32)dat2.dataType; + eventStruct.data2 = dat2.data; // Create a message record blankMessage( &msg ); - msg.hdr.msgID = MSG_ID_HD_INSTITUTIONAL_RECORD_RESPONSE; - msg.hdr.payloadLen = sizeof( U32 ) + sizeof( U32 ) + sizeof( HD_INSTITUTIONAL_LOCAL_RECORD_T ); + msg.hdr.msgID = MSG_ID_HD_EVENT; + // The payload length is the event ID, 2 event datas and the events data types for each of the event data + msg.hdr.payloadLen = sizeof( EVENT_PAYLOAD_T ); - memcpy( payloadPtr, &accept, sizeof( U32 ) ); - payloadPtr += sizeof( U32 ); - memcpy( payloadPtr, &reason, sizeof( U32 ) ); - payloadPtr += sizeof( U32 ); - memcpy( payloadPtr, instit, sizeof( HD_INSTITUTIONAL_LOCAL_RECORD_T ) ); + 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 - serializeMessage( msg, COMM_BUFFER_OUT_CAN_TD_2_UI, ACK_NOT_REQUIRED ); -} + result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_TD_2_UI, ACK_NOT_REQUIRED ); -/*********************************************************************//** - * @brief - * The handleUITDResetInServiceModeRequest function handles the UI request - * to reset HD in service mode - * @details Inputs: none - * @details Outputs: none - * @param message a pointer to the message to handle - * @return none - *************************************************************************/ -void handleUITDResetInServiceModeRequest( MESSAGE_T* message ) -{ - // Verify payload length - if ( ( 0 == message->hdr.payloadLen ) && ( MODE_SERV == getCurrentOperationMode() ) ) - { -#ifndef _VECTORCAST_ - systemREG1->SYSECR = (0x2) << 14; // Reset processor -#endif - } - - // Respond to request - sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_TD_2_UI, FALSE ); + return result; } @@ -378,51 +460,14 @@ /*********************************************************************//** * @brief - * The sendEvent function constructs an TD event message to the UI and - * queues the msg for transmit on the appropriate CAN channel. - * @details Inputs: none - * @details Outputs: TD event msg constructed and queued. - * @param event Enumeration of event type that occurred - * @param dat1 First data associated with event - * @param dat2 Second data associated with event - * @return TRUE if msg successfully queued for transmit, FALSE if not - *************************************************************************/ -BOOL sendEvent( TD_EVENT_ID_T event, EVENT_DATA_T dat1, EVENT_DATA_T dat2 ) -{ - BOOL result; - MESSAGE_T msg; - EVENT_PAYLOAD_T eventStruct; - - eventStruct.event = (U32)event; - eventStruct.dataType1 = (U32)dat1.dataType; - eventStruct.data1 = dat1.data; - eventStruct.dataType2 = (U32)dat2.dataType; - eventStruct.data2 = dat2.data; - - // Create a message record - blankMessage( &msg ); - msg.hdr.msgID = MSG_ID_HD_EVENT; - // The payload length is the event ID, 2 event datas and the events data types for each of the event data - msg.hdr.payloadLen = sizeof( EVENT_PAYLOAD_T ); - - 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_TD_2_UI, ACK_NOT_REQUIRED ); - - return result; -} - -/*********************************************************************//** - * @brief * The handleTesterLogInRequest function handles a request to login as a * tester. * @details Inputs: none * @details Outputs: message handled * @param message a pointer to the message to handle - * @return none + * @return TRUE if log in successful, FALSE if not *************************************************************************/ -void handleTesterLogInRequest( MESSAGE_T *message ) +BOOL handleTesterLogInRequest( MESSAGE_T *message ) { // Verify pass code // TODO - placeholder - how do we want to authenticate tester? @@ -439,6 +484,8 @@ } // Respond to would be tester sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, testerLoggedIn ); + + return testerLoggedIn; } /**@}*/