Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -ra303cd4258157a8fbcbd8af4dd2bbaadec1a736c -r7acb9d914f79aaa921c95e1a4049594c889bf795 --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision a303cd4258157a8fbcbd8af4dd2bbaadec1a736c) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 7acb9d914f79aaa921c95e1a4049594c889bf795) @@ -18,66 +18,108 @@ #include // for memcpy() -#include "Common.h" -#include "AlarmLamp.h" #include "MsgQueues.h" #include "WatchdogMgmt.h" #include "SystemCommMessages.h" -#include "SystemComm.h" -#include "CPLD.h" -#include "OperationModes.h" #include "Utilities.h" +#include "SystemComm.h" +#include "RTC.h" +#include "LoadCell.h" // ********** private definitions ********** +#define ACK_REQUIRED TRUE +#define ACK_NOT_REQUIRED FALSE + #pragma pack(push,1) typedef struct { - U08 confirmed; // 1 = confirmed, 0 = rejected/timed out -} OFF_BUTTON_MESSAGE_FROM_UI_PAYLOAD_T; + U32 alarmState; // 0 = no alarms, 1 = low priority, 2 = medium priority, 3 = high priority + U32 alarmTop; // ID of top active alarm + U32 escalatesIn; // seconds + U32 silenceExpiresIn; // seconds + U16 alarmsFlags; // bit flags: 1 = true, 0 = false for each bit +} ALARM_COMP_STATUS_PAYLOAD_T; +typedef struct +{ + U32 treatmentTimePrescribedinSec; + U32 treatmentTimeElapsedinSec; + U32 treatmentTimeRemaininginSec; +} TREATMENT_TIME_DATA_T; + +typedef struct +{ + F32 loadCellA1inGram; + F32 loadCellA2inGram; + F32 loadCellB1inGram; + F32 loadCellB2inGram; +} LOAD_CELL_DATA_T; + #pragma pack(pop) // ********** private data ********** static BOOL testerLoggedIn = FALSE; +static volatile U16 nextSeqNo = 1; // ********** private function prototypes ********** -static U32 serializeMessage( MESSAGE_T msg, U08 *data ); +static U32 serializeMessage( MESSAGE_T msg, COMM_BUFFER_T buffer, BOOL ackReq ); static BOOL sendTestAckResponseMsg( MSG_ID_T msgID, BOOL ack ); /************************************************************************* * @brief serializeMessage * The serializeMessage function serializes a given message into a given \n - * array of bytes. A sync byte is inserted at the beginning of the message \n - * and an 8-bit CRC is appended to the end of the message. The given array \n - * must be large enough to hold the message + 1 sync byte and 1 CRC byte and \n - * up to 7 CAN padding bytes. + * array of bytes. A sequence # is added to the message here and the ACK \n + * bit of the sequence # is set if ACK is required per parameter. A sync byte \n + * is inserted at the beginning of the message and an 8-bit CRC is appended to \n + * the end of the message. The message is queued for transmission in the given buffer. * @details * Inputs : none - * Outputs : given data array populated with serialized message data. + * Outputs : given data array populated with serialized message data and queued for transmit. * @param msg : message to serialize - * @param data : byte array to populate with message data + * @param buffer : outgoing buffer that message should be queued in + * @param ackReq : is an acknowledgement from receiver required? * @return size (in bytes) of serialized message populated in given data array. *************************************************************************/ -static U32 serializeMessage( MESSAGE_T msg, U08 *data ) +static U32 serializeMessage( MESSAGE_T msg, COMM_BUFFER_T buffer, BOOL ackReq ) { + BOOL result = 0; + BOOL error = FALSE; U32 msgSize = 0; U32 sizeMod, sizePad; U32 i; - U08 crc = crc8( (U08*)(&msg), sizeof( MESSAGE_HEADER_T ) + msg.hdr.payloadLen ); + U08 crc; + U08 data[ MAX_ACK_MSG_SIZE ]; // byte array to populate with message data // prefix data with message sync byte - data[msgSize++] = MESSAGE_SYNC_BYTE; + data[ msgSize++ ] = MESSAGE_SYNC_BYTE; + // set sequence # and ACK bit (unless this is an ACK to a received message) + if ( msg.hdr.msgID != MSG_ID_ACK ) + { + // thread protect next sequence # access & increment + _disable_IRQ(); + msg.hdr.seqNo = nextSeqNo; + nextSeqNo = INC_WRAP( nextSeqNo, MIN_MSG_SEQ_NO, MAX_MSG_SEQ_NO ); + _enable_IRQ(); + if ( TRUE == ackReq ) + { + msg.hdr.seqNo *= -1; + } + } + + // calculate message CRC + crc = crc8( (U08*)(&msg), sizeof( MESSAGE_HEADER_T ) + msg.hdr.payloadLen ); + // serialize message header data - memcpy( &data[msgSize], &(msg.hdr), sizeof(MESSAGE_HEADER_T) ); - msgSize += sizeof(MESSAGE_HEADER_T); + memcpy( &data[ msgSize ], &( msg.hdr ), sizeof( MESSAGE_HEADER_T ) ); + msgSize += sizeof( MESSAGE_HEADER_T ); // serialize message payload (only used bytes per payloadLen field) - memcpy( &data[msgSize], &(msg.payload), msg.hdr.payloadLen ); + memcpy( &data[ msgSize ], &( msg.payload ), msg.hdr.payloadLen ); msgSize += msg.hdr.payloadLen; // add 8-bit CRC @@ -88,55 +130,253 @@ sizePad = ( sizeMod == 0 ? 0 : CAN_MESSAGE_PAYLOAD_SIZE - sizeMod ); for ( i = 0; i < sizePad; i++ ) { - data[msgSize++] = 0; + data[ msgSize++ ] = 0; } - return msgSize; + // if ACK required, add to pending ACK list + if ( TRUE == ackReq ) + { + if ( FALSE == addMsgToPendingACKList( &msg, buffer, data, msgSize ) ) + { + error = TRUE; + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_SOFTWARE_FAULT, SW_FAULT_ID_MSG_PENDING_ACK_LIST_FULL ) + } + } + + if ( FALSE == error ) + { + // add serialized message data to appropriate out-going comm buffer + result = addToCommBuffer( buffer, data, msgSize ); + } + + return result; } +/************************************************************************* + * @brief sendACKMsg + * The sendACKMsg function constructs and queues for transmit an ACK message \n + * for a given received message. + * @details + * Inputs : none + * Outputs : ACK message queued for transmit on broadcast CAN channel. + * @param message : message to send an ACK for + * @return TRUE if ACK message queued successfully, FALSE if not + *************************************************************************/ +BOOL sendACKMsg( MESSAGE_T *message ) +{ + BOOL result; + MESSAGE_T msg; + + // create a message record + blankMessage( &msg ); + // send ACK back with same seq. #, but w/o ACK bit + msg.hdr.seqNo = message->hdr.seqNo * -1; + // ACK messages always have this ID + msg.hdr.msgID = MSG_ID_ACK; + // ACK messages always have no payload + msg.hdr.payloadLen = 0; + + // serialize and queue the message for transmit on broadcast channel + result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_DG_BROADCAST, ACK_NOT_REQUIRED ); + + return result; +} + // *********************************************************************** // ********************* MSG_ID_OFF_BUTTON_PRESS ************************* // *********************************************************************** +/************************************************************************* + * @brief broadcastAlarmTriggered + * The broadcastAlarmTriggered function constructs an alarm triggered msg to \n + * be broadcast and queues the msg for transmit on the appropriate CAN channel. + * @details + * Inputs : none + * Outputs : alarm triggered msg constructed and queued. + * @param alarm : ID of alarm triggered + * @param almData1 : 1st data associated with alarm + * @param almData2 : 2nd data associated with alarm + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL broadcastAlarmTriggered( U16 alarm, ALARM_DATA_T almData1, ALARM_DATA_T almData2 ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_ALARM_TRIGGERED; + msg.hdr.payloadLen = sizeof( U16 ) + sizeof( ALARM_DATA_T ) + sizeof( ALARM_DATA_T ); + memcpy( payloadPtr, &alarm, sizeof( U16 ) ); + payloadPtr += sizeof( U16 ); + memcpy( payloadPtr, &almData1, sizeof( ALARM_DATA_T ) ); + payloadPtr += sizeof( ALARM_DATA_T ); + memcpy( payloadPtr, &almData2, sizeof( ALARM_DATA_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_DG_ALARM, ACK_REQUIRED ); + + return result; +} + /************************************************************************* - * @brief handleDGFillStartStopMessages - * The handleDGFillStartStopMessages function handles a response to the - * start and stop messages thru the CAN bus. + * @brief broadcastAlarmCleared + * The broadcastAlarmCleared function constructs an alarm cleared msg to be \n + * broadcast and queues the msg for transmit on the appropriate CAN channel. * @details * Inputs : none - * Outputs : message handled - * @param message : a pointer to the message to handle - * @return none + * Outputs : alarm cleared msg constructed and queued. + * @param alarm : ID of alarm cleared + * @return TRUE if msg successfully queued for transmit, FALSE if not *************************************************************************/ -void handleDGFillStartStopMessages( MESSAGE_T *message ) +BOOL broadcastAlarmCleared( U16 alarm ) { - # define STOP 0 - # define START 1 + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; - #ifdef RM46_EVAL_BOARD_TARGET - toggleUserLED(); - #endif + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_ALARM_CLEARED; + msg.hdr.payloadLen = sizeof( U16 ); - // If we start therapy - if (message->payload[0] == START && getCurrentOperationMode() == MODE_STAN) + memcpy( payloadPtr, &alarm, sizeof( U16 ) ); + + // 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_DG_ALARM, ACK_REQUIRED ); + + return result; +} + +/************************************************************************* + * @brief broadcastRTCEpoch + * The broadcastRTCEpoch function constructs an epoch msg to \n + * be broadcast and queues the msg for transmit on the appropriate CAN channel. + * @details + * Inputs : none + * Outputs : RTC time and date in epoch + * @param epoch : Current time and date in epoch + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL broadcastRTCEpoch( U32 epoch ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_RTC_EPOCH; + msg.hdr.payloadLen = sizeof( U32 ); + + memcpy( payloadPtr, &epoch, sizeof( U32 ) ); + + // 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_HD_BROADCAST, ACK_NOT_REQUIRED ); + result = TRUE; // TODO - don't want DG broadcasting its time + + return result; +} + +/************************************************************************* + * @brief + * The broadcastTreatmentTime function constructs a treatment time msg to \n + * be broadcast and queues the msg for transmit on the appropriate CAN channel. + * @details + * Inputs : none + * Outputs : treatment time data msg constructed and queued + * @param secsTotTreatment : Total treatment time prescribed (in seconds). + * @param secsElapsed : Treatment time elapsed (in seconds). + * @param secsRemaining : Treatment time remaining (in seconds). + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL broadcastTreatmentTime( U32 secsTotTreatment, U32 secsElapsed, U32 secsRemaining ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + TREATMENT_TIME_DATA_T payload; + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_TREATMENT_TIME; + msg.hdr.payloadLen = sizeof( TREATMENT_TIME_DATA_T ); + + payload.treatmentTimePrescribedinSec = secsTotTreatment; + payload.treatmentTimeElapsedinSec = secsElapsed; + payload.treatmentTimeRemaininginSec = secsRemaining; + + memcpy( payloadPtr, &payload, sizeof( TREATMENT_TIME_DATA_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_DG_BROADCAST, ACK_NOT_REQUIRED ); + + return result; +} + +/************************************************************************* + * @brief + * The broadcastLoadCellData function sends out load cell data. + * @details + * Inputs : load cell data + * Outputs : load cell data msg constructed and queued + * @param loadCellA1 : load cell A 1 data in grams. + * @param loadCellA2 : load cell A 2 data in grams. + * @param loadCellB1 : load cell B 1 data in grams. + * @param loadCellB2 : load cell B 2 data in grams. + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL broadcastLoadCellData( F32 loadCellA1, F32 loadCellA2, F32 loadCellB1, F32 loadCellB2 ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + LOAD_CELL_DATA_T payload; + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_LOAD_CELL_READINGS; + msg.hdr.payloadLen = sizeof( LOAD_CELL_DATA_T ); + + payload.loadCellA1inGram = loadCellA1; + payload.loadCellA2inGram = loadCellA2; + payload.loadCellB1inGram = loadCellB1; + payload.loadCellB2inGram = loadCellB2; + + memcpy( payloadPtr, &payload, sizeof( LOAD_CELL_DATA_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_DG_BROADCAST, ACK_NOT_REQUIRED ); + + return result; +} + +#ifdef CAN_TEST +void broadcastCANTest1LargeFrequentMessage() +{ + static U16 seqNo = 0; + MESSAGE_T msg; + U32 i; + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_DG_CAN_TEST_1_LARGE_FREQ; + msg.hdr.payloadLen = 96; + + for ( i = 0; i < 12; i++ ) { - requestNewOperationMode(MODE_FILL); - sendTestAckResponseMsg((MSG_ID_T)message->hdr.msgID, TRUE); - } // We can only stop fill if we are in fill mode - else if (message->payload[0] == STOP && getCurrentOperationMode() == MODE_FILL) - { - requestNewOperationMode(MODE_STAN); - sendTestAckResponseMsg((MSG_ID_T)message->hdr.msgID, TRUE); + memcpy(&msg.payload[i*8], &seqNo, 2); + seqNo++; } - else - { - // TODO: Print to log that either start was called when t he machine was not - // in standby or that stop was called when the machine was not in fill - sendTestAckResponseMsg((MSG_ID_T)message->hdr.msgID, FALSE); - } + memcpy(&msg.payload[94], &seqNo, 2); + seqNo++; + + // 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_DG_BROADCAST, ACK_NOT_REQUIRED ); } +#endif /************************************************************************* @@ -154,27 +394,17 @@ * @param len : # of bytes of debug data * @return TRUE if debug data was successfully queued for transmit, FALSE if not *************************************************************************/ +#ifdef DEBUG_ENABLED BOOL sendDebugData( U08 *dbgData, U32 len ) { BOOL result; - MESSAGE_T msg; - U32 msgSize; - U08 data[sizeof(MESSAGE_WRAPPER_T) + 1 + CAN_MESSAGE_PAYLOAD_SIZE]; // must hold full (wrapped) message + sync + any CAN padding - // create a message record - blankMessage( &msg ); - msg.hdr.msgID = 2; - msg.hdr.payloadLen = len; - memcpy( msg.payload, dbgData, len ); - - // 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 ); + result = addToCommBuffer( COMM_BUFFER_OUT_UART_PC, dbgData, len ); return result; } +#endif /************************************************************************* * @brief isTestingActivated @@ -188,8 +418,7 @@ *************************************************************************/ BOOL isTestingActivated( void ) { - //TODO: Disable all login related functions - return TRUE; + return testerLoggedIn; } /************************************************************************* @@ -208,21 +437,16 @@ { BOOL result; MESSAGE_T msg; - U32 msgSize; - U08 data[PC_MESSAGE_PACKET_SIZE]; // create a message record blankMessage( &msg ); msg.hdr.msgID = msgID; - msg.hdr.payloadLen = 1; - msg.payload[0] = (U08)ack; + msg.hdr.payloadLen = sizeof( U08 ); + msg.payload[ 0 ] = (U08)ack; - // serialize the message (w/ sync, CRC, and appropriate CAN padding) - msgSize = serializeMessage( msg, data ); + // 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_PC, ACK_NOT_REQUIRED ); - // add serialized message data to appropriate comm buffer - result = addToCommBuffer( COMM_BUFFER_OUT_CAN_DG_2_HD, data, msgSize ); - return result; } @@ -240,7 +464,7 @@ { // verify pass code // TODO - placeholder - how do we want to authenticate tester? - if ( ( 3 == message->hdr.payloadLen ) && ( 0x31 == message->payload[0] ) && ( 0x32 == message->payload[1] ) && ( 0x33 == message->payload[2] ) ) + if ( ( 3 == message->hdr.payloadLen ) && ( 0x31 == message->payload[ 0 ] ) && ( 0x32 == message->payload[ 1 ] ) && ( 0x33 == message->payload[ 2 ] ) ) { testerLoggedIn = TRUE; } @@ -253,94 +477,129 @@ } /************************************************************************* - * @brief handleTestHDMessageRequest - * The handleTestHDMessageRequest function handles a request to add an \n - * HD message to the received message queue. + * @brief + * The handleTestDGMessageRequest function handles a request to add a \n + * DG message to the received message queue. * @details * Inputs : none * Outputs : message handled * @param message : a pointer to the message to handle * @return none *************************************************************************/ -void handleTestHDMessageRequest( MESSAGE_T *message ) +void handleTestDGMessageRequest( MESSAGE_T *message ) { - MESSAGE_WRAPPER_T hdMessage; + MESSAGE_WRAPPER_T dgMessage; U32 msgLen = (U32)(message->hdr.payloadLen); - U08 *msgBytes = (U08*)(&(hdMessage)); + U08 *msgBytes = (U08*)(&(dgMessage)); BOOL result; memcpy( msgBytes, message->payload, msgLen ); // add HD message to received message queue - result = addToMsgQueue( MSG_Q_IN, &hdMessage ); + result = addToMsgQueue( MSG_Q_IN, &dgMessage ); // respond to request sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); } /************************************************************************* - * @brief handleTestAlarmLampPatternOverrideRequest - * The handleTestAlarmLampPatternOverrideRequest function handles a request to \n - * override the alarm lamp pattern. + * @brief handleTestWatchdogCheckInStateOverrideRequest + * The handleTestWatchdogCheckInStateOverrideRequest function handles a \n + * request to override the check-in status of a given task. * @details * Inputs : none * Outputs : message handled * @param message : a pointer to the message to handle * @return none *************************************************************************/ -void handleTestAlarmLampPatternOverrideRequest( MESSAGE_T *message ) -{ - TEST_OVERRIDE_PAYLOAD_T payload; - BOOL result = FALSE; +DATA_ARRAY_OVERRIDE_HANDLER_FUNC_U32( BOOL, handleTestWatchdogCheckInStateOverrideRequest, testSetWatchdogTaskCheckInOverride, testResetWatchdogTaskCheckInOverride ) - // verify payload length - if ( sizeof(TEST_OVERRIDE_PAYLOAD_T) == message->hdr.payloadLen ) - { - memcpy( &payload, message->payload, sizeof(TEST_OVERRIDE_PAYLOAD_T) ); +/************************************************************************* + * @brief handleTestAlarmStateOverrideRequest + * The handleTestAlarmStateOverrideRequest function handles a request to \n + * override the active status of a given alarm. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +DATA_ARRAY_OVERRIDE_HANDLER_FUNC_U32( BOOL, handleTestAlarmStateOverrideRequest, testSetAlarmStateOverride, testResetAlarmStateOverride ) - if ( FALSE == payload.reset ) - { - result = testSetCurrentLampPatternOverride( (LAMP_PATTERN_T)(payload.state) ); - } - else - { - result = testResetCurrentLampPatternOverride(); - } - } - // respond to request - sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); -} +/************************************************************************* + * @brief handleTestLoadCellA1OverrideRequest + * The handleTestLoadCellA1OverrideRequest function handles a request to \n + * override the value read from load cell A1 adc. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +DATA_OVERRIDE_HANDLER_FUNC_U32( BOOL, handleTestLoadCellA1OverrideRequest, testSetLoadCellA1Override, testResetLoadCellA1Override ) /************************************************************************* - * @brief handleTestAlarmLampPatternOverrideRequest - * The handleTestAlarmLampPatternOverrideRequest function handles a request to \n - * override the alarm lamp pattern. + * @brief handleTestLoadCellA2OverrideRequest + * The handleTestLoadCellA2OverrideRequest function handles a request to \n + * override the value read from load cell A1 adc. * @details * Inputs : none * Outputs : message handled * @param message : a pointer to the message to handle * @return none *************************************************************************/ -void handleTestWatchdogCheckInStateOverrideRequest( MESSAGE_T *message ) +DATA_OVERRIDE_HANDLER_FUNC_U32( BOOL, handleTestLoadCellA2OverrideRequest, testSetLoadCellA2Override, testResetLoadCellA2Override ) + +/************************************************************************* + * @brief handleTestLoadCellB1OverrideRequest + * The handleTestLoadCellB1OverrideRequest function handles a request to \n + * override the value read from load cell A1 adc. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +DATA_OVERRIDE_HANDLER_FUNC_U32( BOOL, handleTestLoadCellB1OverrideRequest, testSetLoadCellB1Override, testResetLoadCellB1Override ) + +/************************************************************************* + * @brief handleTestLoadCellB2OverrideRequest + * The handleTestLoadCellB2OverrideRequest function handles a request to \n + * override the value read from load cell A1 adc. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +DATA_OVERRIDE_HANDLER_FUNC_U32( BOOL, handleTestLoadCellB2OverrideRequest, testSetLoadCellB2Override, testResetLoadCellB2Override ) + +/************************************************************************* + * @brief handleSetRTCTimestamp + * The handleSetRTCTimestamp function handles a request to write time and + * date to RTC + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleSetRTCTimestamp( MESSAGE_T *message ) { - TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; - BOOL result = FALSE; + BOOL result; + U08 seconds = message->payload[0]; + U08 minutes = message->payload[1]; + U08 hours = message->payload[2]; + U08 days = message->payload[3]; + U08 months = message->payload[4]; + U32 years; + memcpy(&years, &message->payload[5], sizeof(U32)); - // verify payload length - if ( sizeof(TEST_OVERRIDE_ARRAY_PAYLOAD_T) == message->hdr.payloadLen ) - { - memcpy( &payload, message->payload, sizeof(TEST_OVERRIDE_ARRAY_PAYLOAD_T) ); + // TODO: Change setRTCTimestamp to return a boolean for this + result = TRUE; - if ( FALSE == payload.reset ) - { - result = testSetWatchdogTaskCheckInOverride( payload.index, (BOOL)(payload.state) ); - } - else - { - result = testResetWatchdogTaskCheckInOverride( payload.index ); - } - } + setRTCTimestamp( seconds, minutes, hours, days, months, years ); + // respond to request sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); } -