A simple WIP that logs data from a Grove sensor, and can send and receive information over USB and SMS.

Dependencies:   DHT DS_1337 SDFileSystem USBDevice mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers circbuff.h Source File

circbuff.h

00001 #ifndef __CIRC_BUFF_H__
00002 #define __CIRC_BUFF_H__
00003 
00004 #include "mbed.h"
00005 
00006 /*!
00007  * \brief The CircBuff class writes in and reads out byte arrays into a circular buffer
00008  */
00009 class CircBuff {
00010 public:
00011     CircBuff(uint16_t buffSize = 256);
00012     ~CircBuff();
00013 
00014     /*!
00015      * \brief putc adds a single byte, \a c, into the array
00016      * \param c is the byte copied into the circular buffer.
00017      */
00018     void putc(unsigned char c);
00019 
00020     /*!
00021      * \brief add adds \a s into the buffer, up until the NULL byte
00022      * \param s is the byte array copied into the buffer
00023      */
00024     void add(unsigned char *s);
00025 
00026     /*!
00027      * \brief read puts the current data from the buffer into \a s
00028      * \param s is the reference buffer to copy current data into. Caller's responsibility to make it the correct size
00029      * \param len is the number of bytes to copy into \a s
00030      * \return the number of bytes copied into \a s. Will be less than \a len if there was less data in the buffer.
00031      */
00032     uint16_t read(unsigned char *s, uint16_t len);
00033     bool dataAvailable() { return (m_start != m_end); }
00034     
00035 
00036 private:
00037     uint16_t m_start;       ///< The start index of the circular buffer, where the current data starts
00038     uint16_t m_end;         ///< The end index, where the current data goes to
00039     unsigned char *m_buf;   ///< the byte array
00040     uint16_t m_buffSize;    ///< size of \a m_buf
00041     
00042     // helper
00043     uint16_t remainingSize();
00044 };
00045 
00046 #endif // __CIRC_BUFF_H__