This example shows how to use the CircularBuffer library.

Dependencies:   CircularBuffer mbed

Committer:
feb11
Date:
Fri Sep 20 10:47:53 2013 +0000
Revision:
0:aad8c5c41dac
initial import

Who changed what in which revision?

UserRevisionLine numberNew contents of line
feb11 0:aad8c5c41dac 1 #include "mbed.h"
feb11 0:aad8c5c41dac 2 #include "CircularBuffer.h"
feb11 0:aad8c5c41dac 3
feb11 0:aad8c5c41dac 4 int main()
feb11 0:aad8c5c41dac 5 {
feb11 0:aad8c5c41dac 6 CircularBuffer<16> buffer;
feb11 0:aad8c5c41dac 7 uint32_t n = buffer.write((uint8_t*)"Hello World !", strlen("Hello World !"));
feb11 0:aad8c5c41dac 8 printf("wrote %d bytes\n", n);
feb11 0:aad8c5c41dac 9 char str[10];
feb11 0:aad8c5c41dac 10 n = buffer.read((uint8_t*)str, 5);
feb11 0:aad8c5c41dac 11 str[n] = '\0';
feb11 0:aad8c5c41dac 12 printf("str=%s\n", str); // prints:Hello
feb11 0:aad8c5c41dac 13 buffer.read((uint8_t*)str, 1); // discard space
feb11 0:aad8c5c41dac 14 n = buffer.read((uint8_t*)str, 7);
feb11 0:aad8c5c41dac 15 str[n] = '\0';
feb11 0:aad8c5c41dac 16 printf("str=%s\n", str); // prints:World !
feb11 0:aad8c5c41dac 17
feb11 0:aad8c5c41dac 18 return 0;
feb11 0:aad8c5c41dac 19 }