console.c: fail to understand some code

Firmware/software/electronics/mechanics
Post Reply
Nyothan
Beginner
Posts: 15
Joined: Tue Feb 10, 2015 4:36 pm

console.c: fail to understand some code

Post by Nyothan »

Hi everybody,

I'm currently trying to translate the Crazyflie 2.0 firmware in ADA. Looking deeper in the code, I don't understand this piece of code, located in console.c:

Code: Select all


static const char fullMsg[] = "<F>\n";

// ...

int consolePutchar(int ch)
{
  int i;

    // ...
    if (ch == '\n' || messageToPrint.size >= CRTP_MAX_DATA_SIZE)
    {
      if (crtpGetFreeTxQueuePackets() == 1)
      {
        for (i = 0; i < sizeof(fullMsg) && (messageToPrint.size - i) > 0; i++)
        {
          messageToPrint.data[messageToPrint.size - i] =
              (uint8_t)fullMsg[sizeof(fullMsg) - i - 1];
        }
      }
      consoleSendMessage();
    }
    xSemaphoreGive(synch);
  }
  
  return (unsigned char)ch;
}
I don't understand the purpose of the 'fullMsg' static variable, and why we replace some data we want to send by these characters when the CRTP Tx queue has only one free packet.

Could you explain this to me, please? :)
Nyothan
Beginner
Posts: 15
Joined: Tue Feb 10, 2015 4:36 pm

Re: console.c: fail to understand some code

Post by Nyothan »

Nobody can help? :)
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: console.c: fail to understand some code

Post by tobias »

Hehe, it's a compromise using the fullMsg. It is to notify that the queue limit has been reached and that text might be missing after that as console messages will be dropped. It can often be triggered during startup before it is connected since nothing will be sent out and the queue might quickly become full.
Nyothan
Beginner
Posts: 15
Joined: Tue Feb 10, 2015 4:36 pm

Re: console.c: fail to understand some code

Post by Nyothan »

Ok I see. But nothing is done to recover from this situation, right?

So if many calls to 'consolePuts' (via DEBUG_PRINT) are done during startup, when the CF is not yet connected, some of these messages will never be sent to the client python, am I right?
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: console.c: fail to understand some code

Post by tobias »

So if many calls to 'consolePuts' (via DEBUG_PRINT) are done during startup, when the CF is not yet connected, some of these messages will never be sent to the client python, am I right?
Yes exactly and you would be able to see this in the console output when "<F>" is displayed.
Nyothan
Beginner
Posts: 15
Joined: Tue Feb 10, 2015 4:36 pm

Re: console.c: fail to understand some code

Post by Nyothan »

Yes exactly and you would be able to see this in the console output when "<F>" is displayed.
Ok, I see how the things work now.

Thank you for your answers ;)
Post Reply