Page 1 of 1

console.c: fail to understand some code

Posted: Fri Apr 17, 2015 3:18 pm
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? :)

Re: console.c: fail to understand some code

Posted: Mon Apr 20, 2015 7:25 am
by Nyothan
Nobody can help? :)

Re: console.c: fail to understand some code

Posted: Tue Apr 21, 2015 9:17 am
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.

Re: console.c: fail to understand some code

Posted: Tue Apr 21, 2015 9:52 am
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?

Re: console.c: fail to understand some code

Posted: Wed Apr 22, 2015 8:42 am
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.

Re: console.c: fail to understand some code

Posted: Wed Apr 22, 2015 9:52 am
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 ;)