Index: firmware/App/Services/AlarmMgmtTD.c =================================================================== diff -u -r73d8423edc56daed591bc0b3f7baee5540aea423 -r1631728a0f2506fb4e29c5f6c6e1a5f55018caab --- firmware/App/Services/AlarmMgmtTD.c (.../AlarmMgmtTD.c) (revision 73d8423edc56daed591bc0b3f7baee5540aea423) +++ firmware/App/Services/AlarmMgmtTD.c (.../AlarmMgmtTD.c) (revision 1631728a0f2506fb4e29c5f6c6e1a5f55018caab) @@ -802,7 +802,7 @@ if ( TRUE == isAlarmActive( (ALARM_ID_T)index ) ) { ALARM_TRIGGERED_PAYLOAD_T data; - ALARM_T props = getAlarmProperties( index ); + ALARM_T props = getAlarmProperties( (ALARM_ID_T)index ); data.alarm = index; data.almDataType1 = BLANK_ALARM_DATA.dataType; 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; } /**@}*/ Index: firmware/App/Services/Messaging.h =================================================================== diff -u -r73d8423edc56daed591bc0b3f7baee5540aea423 -r1631728a0f2506fb4e29c5f6c6e1a5f55018caab --- firmware/App/Services/Messaging.h (.../Messaging.h) (revision 73d8423edc56daed591bc0b3f7baee5540aea423) +++ firmware/App/Services/Messaging.h (.../Messaging.h) (revision 1631728a0f2506fb4e29c5f6c6e1a5f55018caab) @@ -154,10 +154,11 @@ BOOL isTestingActivated( void ); void setTesterStatusToLoggedOut( void ); +void handleIncomingMessage( MESSAGE_T *message ); +BOOL handleTesterLogInRequest( MESSAGE_T *message ); + BOOL sendEvent( TD_EVENT_ID_T event, EVENT_DATA_T dat1, EVENT_DATA_T dat2 ); -void handleTesterLogInRequest( MESSAGE_T *message ); - /**@}*/ #endif Index: firmware/App/Services/MsgQueues.h =================================================================== diff -u -r73d8423edc56daed591bc0b3f7baee5540aea423 -r1631728a0f2506fb4e29c5f6c6e1a5f55018caab --- firmware/App/Services/MsgQueues.h (.../MsgQueues.h) (revision 73d8423edc56daed591bc0b3f7baee5540aea423) +++ firmware/App/Services/MsgQueues.h (.../MsgQueues.h) (revision 1631728a0f2506fb4e29c5f6c6e1a5f55018caab) @@ -18,7 +18,8 @@ #ifndef __MSG_QUEUES_H__ #define __MSG_QUEUES_H__ -#include "../TDCommon.h" +#include "TDCommon.h" +#include "CommBuffers.h" /** * @defgroup MsgQueues MsgQueues @@ -52,7 +53,8 @@ /// Record structure for a message (header + payload). typedef struct -{ +{ + COMM_BUFFER_T in_buffer; ///< Message received into this channel buffer MESSAGE_HEADER_T hdr; ///< Message header U08 payload[ MAX_MSG_PAYLOAD_SIZE ]; ///< Message payload } MESSAGE_T; Index: firmware/App/Services/SystemCommTD.c =================================================================== diff -u -r73d8423edc56daed591bc0b3f7baee5540aea423 -r1631728a0f2506fb4e29c5f6c6e1a5f55018caab --- firmware/App/Services/SystemCommTD.c (.../SystemCommTD.c) (revision 73d8423edc56daed591bc0b3f7baee5540aea423) +++ firmware/App/Services/SystemCommTD.c (.../SystemCommTD.c) (revision 1631728a0f2506fb4e29c5f6c6e1a5f55018caab) @@ -349,105 +349,10 @@ *************************************************************************/ void processReceivedMessage( MESSAGE_T *message ) { - U16 msgID = message->hdr.msgID; - - // Handle any messages from other sub-systems - switch ( msgID ) - { -// case MSG_ID_ALARM_TRIGGERED: -// handleAlarmTriggered( message ); -// break; + U16 msgID = message->hdr.msgID; -// case MSG_ID_ALARM_CONDITION_CLEARED: -// handleAlarmCleared( message ); -// break; - -// case MSG_ID_UI_ALARM_USER_ACTION_REQUEST: -// handleAlarmUserAction( message ); -// break; - -// case MSG_ID_UI_CHECK_IN: -// handleUICheckIn( message ); -// break; - -// case MSG_ID_FW_VERSIONS_REQUEST: -// handleFWVersionRequest( message ); -// handleHDSerialNumberRequest(); -// break; - -// case MSG_ID_DG_VERSION_REPONSE: -// handleDGVersionResponse( message ); -// break; - -// case MSG_ID_USER_ALARM_SILENCE_REQUEST: -// handleUIAlarmSilenceRequest( message ); -// break; - -// case MSG_ID_UI_VERSION_INFO_RESPONSE: -// handleUIVersionResponse( message ); -// break; - -// case MSG_ID_UI_ACTIVE_ALARMS_LIST_REQUEST: -// handleUIActiveAlarmsListRequest( message ); -// break; - -// case MSG_ID_UI_SERVICE_MODE_REQUEST: -// handleUIServiceModeRequest( message ); -// break; - -// case MSG_ID_UI_INSTITUTIONAL_RECORD_REQUEST: -// handleSendInstitutionalRecordToUI( message ); -// break; - - case MSG_ID_UI_HD_RESET_IN_SERVICE_MODE_REQUEST: - handleUITDResetInServiceModeRequest( message ); - break; - - // NOTE: this always must be the last case - case MSG_ID_TESTER_LOGIN_REQUEST: - handleTesterLogInRequest( message ); - break; - - default: - // Un-recognized or un-handled message ID received - ignore - break; - } - - // Handle any test messages if tester has logged in successfully - if ( ( msgID > MSG_ID_FIRST_TESTER_MESSAGE ) && ( TRUE == isTestingActivated() ) ) - { - switch ( msgID ) - { -// case MSG_ID_HD_GET_TEST_CONFIGURATION: -// handleTestHDGetTestConfig( message ); -// break; -// -// case MSG_ID_HD_RESET_ALL_TEST_CONFIGURATIONS: -// handleTestHDResetAllTestConfigs( message ); -// break; -// -// case MSG_ID_HD_DIALIN_CHECK_IN: -// handleTestHDDialinCheckIn( message ); -// break; -// -// case MSG_ID_HD_SET_TEST_CONFIGURATION: -// handleTestHDSetTestConfig( message ); -// break; -// -// case MSG_ID_HD_GET_INSTITUTIONAL_RECORD: -// handleGetHDInstitutionalRecord( message ); -// break; -// -// case MSG_ID_HD_SET_INSTITUTIONAL_RECORD: -// handleSetHDInstitutionalRecord( message ); -// break; - - // The default cannot be reached in VectorCAST since the cases are run in a for loop - default: - // Unrecognized message ID received - ignore - break; - } - } + // Handle any messages from other sub-systems + handleIncomingMessage( message ); }