Complete the message at the beginning of the send function.
@@ -143,19 +143,9 @@ void Robus_ContainersClear(void)
******************************************************************************/
error_return_t Robus_SendMsg(ll_container_t *ll_container, msg_t *msg)
{
- // Compute the full message size based on the header size info.
uint16_t data_size = 0;
uint16_t crc_val = 0xFFFF;
-
- if (msg->header.size > MAX_DATA_MSG_SIZE)
- {
- data_size = MAX_DATA_MSG_SIZE;
- }
- else
- {
- data_size = msg->header.size;
- }
- uint16_t full_size = sizeof(header_t) + data_size;
+ // Prepare the message
// Set protocol revision and source ID on the message
msg->header.protocol = PROTOCOL_REVISION;
if (ll_container->id != 0)
@@ -166,10 +156,20 @@ error_return_t Robus_SendMsg(ll_container_t *ll_container, msg_t *msg)
{
msg->header.source = ctx.node.node_id;
}
+
+ // Compute the full message size based on the header size info.
+ if (msg->header.size > MAX_DATA_MSG_SIZE)
+ {
+ data_size = MAX_DATA_MSG_SIZE;
+ }
+ else
+ {
+ data_size = msg->header.size;
+ }
+ uint16_t full_size = sizeof(header_t) + data_size;
// Add the CRC to the total size of the message
full_size += 2;
-
// compute the CRC
for (uint16_t i = 0; i < full_size - 2; i++)
{
@@ -178,7 +178,6 @@ error_return_t Robus_SendMsg(ll_container_t *ll_container, msg_t *msg)
msg->stream[full_size - 2] = (uint8_t)(crc_val);
msg->stream[full_size - 1] = (uint8_t)(crc_val >> 8);
-
//try to send msg computed
error_return_t result = SUCCEED;
uint8_t nbr_nak_retry = 0;
@@ -322,8 +321,7 @@ static error_return_t Robus_ResetNetworkDetection(ll_container_t *ll_container)
{
msg_t msg;
uint8_t
- try
- = 0;
+ try = 0;
msg.header.target = BROADCAST_VAL;
msg.header.target_mode = BROADCAST;
