Data Sheet

UM7 DATASHEET
Rev. 1.6 Released 1/10/2016
36
uint8_t packet_index = index;
// Check to see if the variable ‘packet_index’ is equal to (rx_length - 2). If it is, then the above
// loop executed to completion and never found a packet header.
if( packet_index == (rx_length 2) )
{
return 2;
}
// If we get here, a packet header was found. Now check to see if we have enough room
// left in the buffer to contain a full packet. Note that at this point, the variable ‘packet_index’
// contains the location of the ‘s’ character in the buffer (the first byte in the header)
if( (rx_length packet_index) < 7 )
{
return 3;
}
// We’ve found a packet header, and there is enough space left in the buffer for at least
// the smallest allowable packet length (7 bytes). Pull out the packet type byte to determine
// the actual length of this packet
uint8_t PT = rx_data[packet_index + 3];
// Do some bit-level manipulation to determine if the packet contains data and if it is a batch
// We have to do this because the individual bits in the PT byte specify the contents of the
// packet.
uint8_t packet_has_data = (PT >> 7) & 0x01; // Check bit 7 (HAS_DATA)
uint8_t packet_is_batch = (PT >> 6) & 0x01; // Check bit 6 (IS_BATCH)
uint8_t batch_length = (PT >> 2) & 0x0F; // Extract the batch length (bits 2 through 5)
// Now finally figure out the actual packet length
uint8_t data_length = 0;
if( packet_has_data )
{
if( packet_is_batch )