Data Sheet
UM7 DATASHEET
Rev. 1.6 – Released 1/10/2016
35
uint8_t data_length;
uint8_t data[30];
} UM7_packet;
// parse_serial_data
// This function parses the data in ‘rx_data’ with length ‘rx_length’ and attempts to find a packet
// in the data. If a packet is found, the structure ‘packet’ is filled with the packet data.
// If there is not enough data for a full packet in the provided array, parse_serial_data returns 1.
// If there is enough data, but no packet header was found, parse_serial_data returns 2.
// If a packet header was found, but there was insufficient data to parse the whole packet,
// then parse_serial_data returns 3. This could happen if not all of the serial data has been
// received when parse_serial_data is called.
// If a packet was received, but the checksum was bad, parse_serial_data returns 4.
// If a good packet was received, parse_serial_data fills the UM7_packet structure and returns 0.
uint8_t parse_serial_data( uint8_t* rx_data, uint8_t rx_length, UM7_packet* packet )
{
uint8_t index;
// Make sure that the data buffer provided is long enough to contain a full packet
// The minimum packet length is 7 bytes
if( rx_length < 7 )
{
return 1;
}
// Try to find the ‘snp’ start sequence for the packet
for( index = 0; index < (rx_length – 2); index++ )
{
// Check for ‘snp’. If found, immediately exit the loop
if( rx_data[index] == ‘s’ && rx_data[index+1] == ‘n’ && rx_data[index+2] == ‘p’ )
{
break;
}
}