Mitesh Patel
/
CameraC328_TestProgram1
CameraC328/SerialBuffered.h@1:78aaadfd1ece, 2010-12-14 (annotated)
- Committer:
- mitesh2patel
- Date:
- Tue Dec 14 13:27:41 2010 +0000
- Revision:
- 1:78aaadfd1ece
- Parent:
- 0:162e214baa3d
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mitesh2patel | 0:162e214baa3d | 1 | #ifndef _SERIAL_BUFFERED_H_ |
mitesh2patel | 0:162e214baa3d | 2 | #define _SERIAL_BUFFERED_H_ |
mitesh2patel | 0:162e214baa3d | 3 | |
mitesh2patel | 0:162e214baa3d | 4 | /** |
mitesh2patel | 0:162e214baa3d | 5 | * Buffered serial class. |
mitesh2patel | 0:162e214baa3d | 6 | */ |
mitesh2patel | 0:162e214baa3d | 7 | class SerialBuffered : public Serial { |
mitesh2patel | 0:162e214baa3d | 8 | public: |
mitesh2patel | 0:162e214baa3d | 9 | /** |
mitesh2patel | 0:162e214baa3d | 10 | * Create a buffered serial class. |
mitesh2patel | 0:162e214baa3d | 11 | * |
mitesh2patel | 0:162e214baa3d | 12 | * @param tx A pin for transmit. |
mitesh2patel | 0:162e214baa3d | 13 | * @param rx A pin for receive. |
mitesh2patel | 0:162e214baa3d | 14 | */ |
mitesh2patel | 0:162e214baa3d | 15 | SerialBuffered(PinName tx, PinName rx); |
mitesh2patel | 0:162e214baa3d | 16 | |
mitesh2patel | 0:162e214baa3d | 17 | /** |
mitesh2patel | 0:162e214baa3d | 18 | * Destroy. |
mitesh2patel | 0:162e214baa3d | 19 | */ |
mitesh2patel | 0:162e214baa3d | 20 | virtual ~SerialBuffered(); |
mitesh2patel | 0:162e214baa3d | 21 | |
mitesh2patel | 0:162e214baa3d | 22 | /** |
mitesh2patel | 0:162e214baa3d | 23 | * Get a character. |
mitesh2patel | 0:162e214baa3d | 24 | * |
mitesh2patel | 0:162e214baa3d | 25 | * @return A character. (-1:timeout) |
mitesh2patel | 0:162e214baa3d | 26 | */ |
mitesh2patel | 0:162e214baa3d | 27 | int getc(); |
mitesh2patel | 0:162e214baa3d | 28 | |
mitesh2patel | 0:162e214baa3d | 29 | /** |
mitesh2patel | 0:162e214baa3d | 30 | * Returns 1 if there is a character available to read, 0 otherwise. |
mitesh2patel | 0:162e214baa3d | 31 | */ |
mitesh2patel | 0:162e214baa3d | 32 | int readable(); |
mitesh2patel | 0:162e214baa3d | 33 | |
mitesh2patel | 0:162e214baa3d | 34 | /** |
mitesh2patel | 0:162e214baa3d | 35 | * Set timeout for getc(). |
mitesh2patel | 0:162e214baa3d | 36 | * |
mitesh2patel | 0:162e214baa3d | 37 | * @param ms milliseconds. (-1:Disable timeout) |
mitesh2patel | 0:162e214baa3d | 38 | */ |
mitesh2patel | 0:162e214baa3d | 39 | void setTimeout(int ms); |
mitesh2patel | 0:162e214baa3d | 40 | |
mitesh2patel | 0:162e214baa3d | 41 | /** |
mitesh2patel | 0:162e214baa3d | 42 | * Read requested bytes. |
mitesh2patel | 0:162e214baa3d | 43 | * |
mitesh2patel | 0:162e214baa3d | 44 | * @param bytes A pointer to a buffer. |
mitesh2patel | 0:162e214baa3d | 45 | * @param requested Length. |
mitesh2patel | 0:162e214baa3d | 46 | * |
mitesh2patel | 0:162e214baa3d | 47 | * @return Readed byte length. |
mitesh2patel | 0:162e214baa3d | 48 | */ |
mitesh2patel | 0:162e214baa3d | 49 | size_t readBytes(uint8_t *bytes, size_t requested); |
mitesh2patel | 0:162e214baa3d | 50 | |
mitesh2patel | 0:162e214baa3d | 51 | private: |
mitesh2patel | 0:162e214baa3d | 52 | void handleInterrupt(); |
mitesh2patel | 0:162e214baa3d | 53 | static const int BUFFERSIZE = 4096; |
mitesh2patel | 0:162e214baa3d | 54 | uint8_t buffer[BUFFERSIZE]; // points at a circular buffer, containing data from m_contentStart, for m_contentSize bytes, wrapping when you get to the end |
mitesh2patel | 0:162e214baa3d | 55 | uint16_t indexContentStart; // index of first bytes of content |
mitesh2patel | 0:162e214baa3d | 56 | uint16_t indexContentEnd; // index of bytes after last byte of content |
mitesh2patel | 0:162e214baa3d | 57 | int timeout; |
mitesh2patel | 0:162e214baa3d | 58 | Timer timer; |
mitesh2patel | 0:162e214baa3d | 59 | }; |
mitesh2patel | 0:162e214baa3d | 60 | |
mitesh2patel | 0:162e214baa3d | 61 | #endif |