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 #pragma once 00002 00003 // This is a buffered serial reading class, using the serial interrupt introduced in mbed library version 18 on 17/11/09 00004 00005 // In the simplest case, construct it with a buffer size at least equal to the largest message you 00006 // expect your program to receive in one go. 00007 00008 class SerialBuffered : public RawSerial 00009 { 00010 public: 00011 SerialBuffered( size_t bufferSize, PinName tx, PinName rx, int baud ); 00012 virtual ~SerialBuffered(); 00013 00014 int getc(); // will block till the next character turns up, or return -1 if there is a timeout 00015 00016 int readable(); // returns 1 if there is a character available to read, 0 otherwise 00017 00018 void setTimeout( float seconds ); // maximum time in seconds that getc() should block 00019 // while waiting for a character 00020 // Pass -1 to disable the timeout. 00021 00022 size_t readBytes( uint8_t *bytes, size_t requested ); // read requested bytes into a buffer, 00023 // return number actually read, 00024 // which may be less than requested if there has been a timeout 00025 00026 00027 private: 00028 00029 void handleInterrupt(); 00030 00031 00032 uint8_t *m_buff; // points at a circular buffer, containing data from m_contentStart, for m_contentSize bytes, wrapping when you get to the end 00033 uint16_t m_contentStart; // index of first bytes of content 00034 uint16_t m_contentEnd; // index of bytes after last byte of content 00035 uint16_t m_buffSize; 00036 float m_timeout; 00037 Timer m_timer; 00038 00039 };
Generated on Wed Jul 20 2022 12:01:51 by
1.7.2