Index: App/Services/SystemCommMessages.c =================================================================== diff -u -r3323966fe741edbb36dffc78317ccf06ed93a68e -r38ff7a6fbf82b86ab1bac3b7b24c4ea33d5419f9 --- App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 3323966fe741edbb36dffc78317ccf06ed93a68e) +++ App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 38ff7a6fbf82b86ab1bac3b7b24c4ea33d5419f9) @@ -16,10 +16,10 @@ * **************************************************************************/ -#include #include // for memcpy() #include "Common.h" +#include "Buttons.h" #include "MsgQueues.h" #include "SystemCommMessages.h" #include "SystemComm.h" @@ -33,10 +33,18 @@ U08 confirmed; // 1 = confirmed, 0 = rejected/timed out } OFF_BUTTON_MESSAGE_FROM_UI_CARGO_T; +typedef struct +{ + U08 reset; + U08 button_state; +} BUTTON_STATE_OVERRIDE_CARGO_T; + #pragma pack(pop) // ********** private data ********** +static BOOL testerLoggedIn = FALSE; + // ********** private function prototypes ********** static U32 serializeMessage( MESSAGE_T msg, U08 *data ); @@ -106,7 +114,6 @@ MESSAGE_T msg; U32 msgSize; U08 data[sizeof(MESSAGE_WRAPPER_T)+1+CAN_MESSAGE_CARGO_SIZE]; // must hold full (wrapped) message + sync + any CAN padding - U08 *dataPtr = data; // create a message record blankMessage( &msg ); @@ -117,7 +124,7 @@ msgSize = serializeMessage( msg, data ); // add serialized message data to appropriate comm buffer - result = addToCommBuffer( COMM_BUFFER_OUT_CAN_HD_2_UI, dataPtr, msgSize ); + result = addToCommBuffer( COMM_BUFFER_OUT_CAN_HD_2_UI, data, msgSize ); return result; } @@ -140,3 +147,206 @@ userConfirmOffButton( cargo.confirmed ); } + +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ + + +/************************************************************************* + * @brief handleTesterLogInRequest + * The handleTesterLogInRequest function handles a request to login as a \n + * tester. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleTesterLogInRequest( MESSAGE_T *message ) +{ + // verify pass code + // TODO - placeholder - how do we want to authenticate tester? + if ( ( 3 == message->hdr.cargoLen ) && ( 0x31 == message->cargo[0] ) && ( 0x32 == message->cargo[1] ) && ( 0x33 == message->cargo[2] ) ) + { + testerLoggedIn = TRUE; + } + else + { + testerLoggedIn = FALSE; + } + // respond to would be tester + sendTesterLogInResponse(); +} + +/************************************************************************* + * @brief sendTesterLogInResponse + * The sendTesterLogInResponse function constructs a tester login response \n + * msg and queues the msg for transmit on the appropriate UART channel. + * @details + * Inputs : none + * Outputs : Off button msg constructed and queued. + * @param none + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL sendTesterLogInResponse( void ) +{ + BOOL result; + MESSAGE_T msg; + U32 msgSize; + U08 data[sizeof(MESSAGE_WRAPPER_T)+1+1+CAN_MESSAGE_CARGO_SIZE]; // must hold full (wrapped) message + sync + any CAN padding + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_TESTER_LOGIN_REQUEST; + msg.hdr.cargoLen = 1; + msg.cargo[0] = (U08)testerLoggedIn; + + // serialize the message (w/ sync, CRC, and appropriate CAN padding) + msgSize = serializeMessage( msg, data ); + + // add serialized message data to appropriate comm buffer + result = addToCommBuffer( COMM_BUFFER_OUT_UART_PC, data, msgSize ); + + return result; +} + +/************************************************************************* + * @brief isTestingActivated + * The isTestingActivated function determines whether a tester has successfully \n + * logged in to activate testing functionality. + * @details + * Inputs : testerLoggedIn + * Outputs : none + * @param none + * @return TRUE if a tester has logged in to activate testing, FALSE if not + *************************************************************************/ +BOOL isTestingActivated( void ) +{ + return testerLoggedIn; +} + +/************************************************************************* + * @brief handleTestOffButtonStateOverrideRequest + * The handleTestOffButtonStateOverrideRequest function handles a request to \n + * override the state of the off button. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleTestOffButtonStateOverrideRequest( MESSAGE_T *message ) +{ + BUTTON_STATE_OVERRIDE_CARGO_T cargo; + BOOL result; + + memcpy( &cargo, message->cargo, sizeof(BUTTON_STATE_OVERRIDE_CARGO_T) ); + + if ( FALSE == (BOOL)(cargo.reset) ) + { + result = testSetOffButtonStateOverride( (BUTTON_STATE_T)(cargo.button_state) ); + } + else + { + result = testResetOffButtonStateOverride(); + } + // respond to request + sendTestOffButtonStateOverrideResponse( result ); +} + +/************************************************************************* + * @brief sendTestOffButtonStateOverrideResponse + * The sendTestOffButtonStateOverrideResponse function constructs an off \n + * button override response msg and queues the msg for transmit on the \n + * appropriate UART channel. + * @details + * Inputs : none + * Outputs : Off button override response msg constructed and queued. + * @param ack : TRUE if override successful, FALSE if not + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL sendTestOffButtonStateOverrideResponse( BOOL ack ) +{ + BOOL result; + MESSAGE_T msg; + U32 msgSize; + U08 data[sizeof(MESSAGE_WRAPPER_T)+1+1+CAN_MESSAGE_CARGO_SIZE]; // must hold full (wrapped) message + sync + any CAN padding + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_OFF_BUTTON_STATE_OVERRIDE; + msg.hdr.cargoLen = 1; + msg.cargo[0] = (U08)ack; + + // serialize the message (w/ sync, CRC, and appropriate CAN padding) + msgSize = serializeMessage( msg, data ); + + // add serialized message data to appropriate comm buffer + result = addToCommBuffer( COMM_BUFFER_OUT_UART_PC, data, msgSize ); + + return result; +} + +/************************************************************************* + * @brief handleTestStopButtonStateOverrideRequest + * The handleTestStopButtonStateOverrideRequest function handles a request to \n + * override the stop button state. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleTestStopButtonStateOverrideRequest( MESSAGE_T *message ) +{ + BUTTON_STATE_OVERRIDE_CARGO_T cargo; + BOOL result; + + memcpy( &cargo, message->cargo, sizeof(BUTTON_STATE_OVERRIDE_CARGO_T) ); + + if ( FALSE == (BOOL)(cargo.reset) ) + { + result = testSetStopButtonStateOverride( (BUTTON_STATE_T)(cargo.button_state) ); + } + else + { + result = testResetStopButtonStateOverride(); + } + // respond to request + sendTestStopButtonStateOverrideResponse( result ); +} + +/************************************************************************* + * @brief sendTestStopButtonStateOverrideResponse + * The sendTestStopButtonStateOverrideResponse function constructs a stop \n + * button override response msg and queues the msg for transmit on the \n + * appropriate UART channel. + * @details + * Inputs : none + * Outputs : stop button override response msg constructed and queued. + * @param ack : TRUE if override successful, FALSE if not + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL sendTestStopButtonStateOverrideResponse( BOOL ack ) +{ + BOOL result; + MESSAGE_T msg; + U32 msgSize; + U08 data[sizeof(MESSAGE_WRAPPER_T)+1+1+CAN_MESSAGE_CARGO_SIZE]; // must hold full (wrapped) message + sync + any CAN padding + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_STOP_BUTTON_STATE_OVERRIDE; + msg.hdr.cargoLen = 1; + msg.cargo[0] = (U08)ack; + + // serialize the message (w/ sync, CRC, and appropriate CAN padding) + msgSize = serializeMessage( msg, data ); + + // add serialized message data to appropriate comm buffer + result = addToCommBuffer( COMM_BUFFER_OUT_UART_PC, data, msgSize ); + + return result; +} +