Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -r3e525c0567dd0b7d2153b751169d0ae17648e117 -r1c80d60fe6a95297a8a8033a3c7eade53e72779a --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 3e525c0567dd0b7d2153b751169d0ae17648e117) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 1c80d60fe6a95297a8a8033a3c7eade53e72779a) @@ -29,6 +29,7 @@ #include "SystemCommMessages.h" #include "Utilities.h" #include "SystemComm.h" +#include "RTC.h" // ********** private definitions ********** @@ -488,6 +489,40 @@ } /************************************************************************* + * @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; + U32 msgSize; + U08 data[ sizeof( MESSAGE_WRAPPER_T ) + 1 + CAN_MESSAGE_PAYLOAD_SIZE ]; // must hold full (wrapped) message + sync + any CAN padding + 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) + msgSize = serializeMessage( msg, data ); + + // add serialized message data to appropriate comm buffer + result = addToCommBuffer( COMM_BUFFER_OUT_CAN_HD_BROADCAST, data, msgSize ); + + return result; +} + +/************************************************************************* * @brief handleDGCheckIn * The handleDGCheckIn function handles a check-in from the DG. * @details @@ -961,3 +996,33 @@ *************************************************************************/ DATA_OVERRIDE_HANDLER_FUNC( U32, handleTestPresOcclBroadcastIntervalOverrideRequest, testSetPresOcclDataPublishIntervalOverride, testResetPresOcclDataPublishIntervalOverride ) +/************************************************************************* + * @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 ) +{ + 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)); + + // TODO: Change setRTCTimestamp to return a boolean for this + result = TRUE; + + setRTCTimestamp( seconds, minutes, hours, days, months, years ); + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} +