Serial write function

Hello folks,

I am trying to send some data from my arduino due to a beagleboard over the programming micro-USB port. However I have run into a problem where the data.az_value seems to be stuck UNTIL the data.el_value begins to change (both are quadrature encoder values read from a stand)… Could someone please take a look at my send_data() function and provide some input on it? I believe the send data function is not optimized for a microcontroller and I seem to be stuck at this point. Code is attached and any help is appreciated!

Thank ytou,
TechnicRC

void send_data()
{
  // Initialize the data struct
  EncoderDataMessage data;
  
  // Compute the pointing angles
  data.az_value = (float) (_AzimuthEncoderTicks / EncoderCountsPerRev) * (2*PI);
  data.el_value = (float) (_ElevationEncoderTicks / EncoderCountsPerRev) * (2*PI);
  
  // Compute the checksum
  char tmp_buffer[data_size];
  memcpy(&tmp_buffer, (void*)&data, data_size);

  char cs = 0;
  for(uint32_t i = 0; i < data_size; i++)
  {
    cs = cs ^ tmp_buffer[i];
  }
   
  // Create the buffer    
  char buffer[message_size];
  
  // Convert to network byte order
  uint32_t size_n = htonl(message_size);
  uint32_t type_n = htonl(1);

  // Initialize the index
  uint32_t index = 0;
  
  /*
   * Create the buffer
   */
   
  // Magic character #1, defined by AnsibleCodec.h
  buffer[index++] = 0xA;
  
  // Magic character #2, defined by AnsibleCodec.h
  buffer[index++] = 0xB;
    
  // Copy the message size
  memcpy(buffer + index, &size_n, 4);
  index += 4;

  // Copy the message type
  memcpy(buffer + index, &type_n, 4);
  index += 4;

  // Copy the checksum
  memcpy(buffer + index, &cs, 1);
  index += 1;

  // Copy the data structure
  memcpy(buffer + index, &data, data_size);
    
  // Send this data
  Serial.write((uint8_t*)buffer, message_size);
}

QuadratureDecoder_v4.ino (9.48 KB)

Without seeing variable/constant values (eg. data_size, tmp_buffer) it's largely guesswork.