Cmera and GPS labrary
Dependents: HEPTA_SENSOR HEPTA_SENSOR
SerialBuffered.h
00001 #ifndef _SERIAL_BUFFERED_H_ 00002 #define _SERIAL_BUFFERED_H_ 00003 00004 /** 00005 * Buffered serial class. 00006 */ 00007 class SerialBuffered : public Serial { 00008 public: 00009 /** 00010 * Create a buffered serial class. 00011 * 00012 * @param tx A pin for transmit. 00013 * @param rx A pin for receive. 00014 */ 00015 SerialBuffered(PinName tx, PinName rx); 00016 00017 /** 00018 * Destroy. 00019 */ 00020 virtual ~SerialBuffered(); 00021 00022 /** 00023 * Get a character. 00024 * 00025 * @return A character. (-1:timeout) 00026 */ 00027 int getc(); 00028 00029 /** 00030 * Returns 1 if there is a character available to read, 0 otherwise. 00031 */ 00032 int readable(); 00033 00034 /** 00035 * Set timeout for getc(). 00036 * 00037 * @param ms milliseconds. (-1:Disable timeout) 00038 */ 00039 void setTimeout(int ms); 00040 00041 /** 00042 * Read requested bytes. 00043 * 00044 * @param bytes A pointer to a buffer. 00045 * @param requested Length. 00046 * 00047 * @return Readed byte length. 00048 */ 00049 size_t readBytes(uint8_t *bytes, size_t requested); 00050 00051 void _baud(int b); 00052 private: 00053 void handleInterrupt(); 00054 static const int BUFFERSIZE = 4096; 00055 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 00056 uint16_t indexContentStart; // index of first bytes of content 00057 uint16_t indexContentEnd; // index of bytes after last byte of content 00058 int timeout; 00059 Timer timer; 00060 }; 00061 00062 #endif
Generated on Sat Jul 16 2022 13:32:45 by 1.7.2