简体   繁体   中英

How can I print a message stored in a buffer?

I am trying to write a function called SerialSend that will print the contents of a ring buffer (named testbuff) to my console.This is my definition for SerialSend.

void SerialSend (USInt* pusiBuffer, UDInt len, UDInt connectionId)
{
  USART_WriteByte(DEMO_USART, testbuff[i]); 
  i++;
  i %= DEMO_RING_BUFFER_SIZE;
}

When called, SerialSend is printing the first character in testbuff. How do I get it to print the rest of the contents of the buffer? This is the code in main where I call SerialSend and the break isn't working.

  while(i<17)
  {
    SerialSend(testbuff, 17, 0)  //Sends contents of testbuff to print in console
    if (i==16)
    {
      break;                     //Break isn't working, probably because i never hits 16 due to the ring
    }
  }

It turns out that I had my ring buffer size too small, so I increased the size to 50 and editted the call in main like this:

while(1)
  {
    SerialSend(testbuff, 50, 0); //Sends contents of testbuff to print in console
    if (i==17)
    {
      break;
    }
  }

The testbuff buffer holds 17 characters I want to print, hence the if statement for a break when the index hits the end of the message.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM