/************************************************************************** * * Copyright (c) 2024-2024 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * @file MessageSupport.c * * @author (last) Sean * @date (last) 30-Jul-2024 * * @author (original) Sean * @date (original) 30-Jul-2024 * ***************************************************************************/ #include "Messaging.h" #include "Utilities.h" /** * @addtogroup MessageSupport * @{ */ /*********************************************************************//** * @brief * The broadcastData function queues a broadcast message for transmission. * @details Inputs: none * @details Outputs: broadcast data msg constructed and queued for transmission. * @param msgID message ID of the data message to broadcast * @param buffer comm buffer ID * @param dataPtr pointer to the start of the payload data buffer * @param length number of bytes of data in the given data buffer * @return TRUE if msg successfully queued for transmit, FALSE if not *************************************************************************/ BOOL broadcastData( MSG_ID_T msgID, COMM_BUFFER_T buffer, U08* dataPtr, U32 length ) { BOOL result; MESSAGE_T msg; U08 *payloadPtr = msg.payload; // create a message record blankMessage( &msg ); msg.hdr.msgID = msgID; msg.hdr.payloadLen = length; if ( ( length > 0 ) && ( dataPtr != 0 ) ) { memcpy( payloadPtr, dataPtr, length ); } // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer result = serializeMessage( msg, buffer, ACK_NOT_REQUIRED ); return result; } /*********************************************************************//** * @brief * The sendMessage function queues a cmd/resp message for transmission. * @details Inputs: none * @details Outputs: Message constructed and queued for transmission. * @param msgID message ID of the message to broadcast * @param buffer comm buffer ID * @param dataPtr pointer to the start of the payload data buffer * @param length number of bytes of data in the given data buffer * @return TRUE if msg successfully queued for transmit, FALSE if not *************************************************************************/ BOOL sendMessage( MSG_ID_T msgID, COMM_BUFFER_T buffer, U08* dataPtr, U32 length ) { BOOL result; MESSAGE_T msg; U08 *payloadPtr = msg.payload; // create a message record blankMessage( &msg ); msg.hdr.msgID = (U16)msgID; msg.hdr.payloadLen = (U08)length; if ( ( length > 0 ) && ( length < BITS_8_FULL_SCALE ) && ( dataPtr != 0 ) ) { memcpy( payloadPtr, dataPtr, length ); } // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer result = serializeMessage( msg, buffer, ACK_REQUIRED ); return result; } /**@}*/