Ring Buffer reconciled with RTOS. If with using RTOS, this lib is enabled Mutex. Default RingBuffer size is 256 Bytes, Max size is 1024 Bytes.
Dependents: RN41 HC05 HC05 mySerial ... more
Diff: RingBuffer.h
- Revision:
- 2:db4675083c8c
- Parent:
- 1:8f2a3144902b
- Child:
- 3:dced590a2d1b
--- a/RingBuffer.h Fri Oct 30 06:34:07 2015 +0000 +++ b/RingBuffer.h Mon Nov 02 06:59:10 2015 +0000 @@ -1,3 +1,40 @@ +/** +Ring Buffer reconciled with RTOS. + +If with using RTOS, this lib is enabled Mutex. +Default RingBuffer size is 256 Bytes, Max size is 1024 Bytes. +*/ + +/** +@code +class tmpSerial{ +public: + tmpSerial(PinName TX, PinName RX) + : serial(TX, RX) + { + // attach rxIrq. because, rx buf of serial equals to 16 Bytes. + this->serial.attach(this, &tmpSerial::_readIrq, Serial::RxIrq); + } + string read() + { + if(ringBuf.empty()) + return ""; + // rxStr is not empty. + return ringBuf.get(); + } +private: + Serial serial; + RingBuffer ringBuf; + void _readIrq(void) + { + while(serial.readable()) + ringBuf.set(hc05.getc()); + return; + } +}; +@endcode +*/ + #pragma once #include "mbed.h" @@ -16,11 +53,21 @@ RingBuffer(unsigned int size= 256); ~RingBuffer(); + /** Returned empty status of ringBuffer. + */ bool empty(); + /** Set char or string to ring-buffer. + * @param; char or string. + * @return; bool(Buffer FULL: true) + */ bool set(char chr); bool set(string &str); // Return Full、参照渡し + /** Get RingBuffer string. + * if this called, RingBuffer is cleared. + * @return; string: buffered string. + */ string get(); private: