UART Protocol GAP8 <-> STM | DEBUG_PRINT issue?

Post here to get support
Post Reply
bot-motion
Beginner
Posts: 7
Joined: Mon Mar 08, 2021 8:16 pm
Location: Frankfurt, Germany
Contact:

UART Protocol GAP8 <-> STM | DEBUG_PRINT issue?

Post by bot-motion »

Hello,

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?!
Screenshot 2021-05-22 2.png
Screenshot 2021-05-22 2.png (36.31 KiB) Viewed 850 times
And why does the decoding of the message in the cfclient fail?
Screenshot 2021-05-22 1.png
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);
    }
}
Last edited by bot-motion on Sat May 22, 2021 7:54 pm, edited 1 time in total.
bot-motion
Beginner
Posts: 7
Joined: Mon Mar 08, 2021 8:16 pm
Location: Frankfurt, Germany
Contact:

Re: UART Protocol GAP8 <-> STM | DEBUG_PRINT issue?

Post by bot-motion »

I forgot to mention: the GAP sends

!INOxx

where xx = uint16 (two bytes). So the two squares in the console readout of cfclient after the letters are explained. It's generally why the decoding fails that I don't understand. Why does it show 0xBC<square>P<square>?
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: UART Protocol GAP8 <-> STM | DEBUG_PRINT issue?

Post by tobias »

Could it be because the string is not NULL terminated? HEADER_LENGTH is 4 and should be 5 to account for the NULL termination.
Post Reply