Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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 private: 00052 void handleInterrupt(); 00053 static const int BUFFERSIZE = 4096; 00054 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 00055 uint16_t indexContentStart; // index of first bytes of content 00056 uint16_t indexContentEnd; // index of bytes after last byte of content 00057 int timeout; 00058 Timer timer; 00059 }; 00060 00061 #endif
Generated on Tue Jul 12 2022 20:39:37 by
1.7.2