I'm trying to build a simple protocol on top of the UART between GAP8 and STM.
But even detecting a protocol header does not work properly. If it turns out that it is my own inability and lack of C knowledge, just ignore me - but I think what I observe may have something to do with the DEBUG_PRINT define.
All of the following is part of aideck.c and readUartMessage() is called from Gap8Task()
The attached screenshots show what I see in the console and what I see in the terminal where the cfclient is running.
I obviously receive the header both on the flie as well as in the cfclient, but why does all this other stuff show up? 0xBC - that sounds familiar. Is this part of the crazyradio protocol, and if yes, why does it appear?! And why does the decoding of the message in the cfclient fail? Any pointers to what I need to adjust would be welcome. Thank you!
Code: Select all
#define HEADER_LENGTH 4
#define BUFFER_LENGTH 2
#define HEADER "!INO"
static uint8_t header_buffer[HEADER_LENGTH];
static uint8_t rx_buffer[BUFFER_LENGTH];
bool rxHead()
{
uint8_t *rx_ptr = header_buffer;
bool rx_valid_header = false;
int i = 0;
while(i < HEADER_LENGTH)
{
bool no_timeout = uart1GetDataWithDefaultTimeout(rx_ptr);
if(no_timeout)
{
consolePutchar(*rx_ptr);
rx_valid_header = (*rx_ptr == (HEADER)[i]);
if (rx_valid_header) // check if the next byte fits the protocol's predefined header
{
rx_ptr++;
i++;
}
else
{
break;
}
}
else
{
rx_valid_header = false;
break;
}
}
return rx_valid_header;
}
void readUartMessage()
{
bool valid_msg_start = rxHead();
if (valid_msg_start)
{
DEBUG_PRINT("HEAD! %s \n", (char *)header_buffer);
}
}