Eric Wu / Mbed 2 deprecated WifiRobot

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TimeoutMultipleSerial.h Source File

TimeoutMultipleSerial.h

00001 /*
00002 Implementation of a serial connection for mbed
00003 
00004 Depends on Serial class provided by mbed sdk
00005 
00006 Written 2014-11-10 by Eric Wu
00007 
00008 This class writes/reads the specified number of symbols from the
00009     serial connection, and times out if it takes longer than
00010     a specified time to get the symbols
00011 */
00012 
00013 #ifndef TIMEOUTMULTIPLESERIAL_H
00014 #define TIMEOUTMULTIPLESERIAL_H
00015 
00016 #include "mbed.h"
00017 #include <stdint.h>
00018 
00019 class TimeoutMultipleSerial {
00020 
00021     public:
00022         // constructor, @param tout is the timeout time in milliseconds
00023         TimeoutMultipleSerial (PinName tx, PinName rx,
00024             const char* name, uint32_t tout) : port(tx, rx, name),
00025             timeout(tout), timer() { };
00026         
00027         // reads @param size number of symbols from the serial connection
00028         //      into @param dest
00029         int readMultChars (uint8_t* const dest, const size_t size);
00030 
00031         // writes @param size number of symbols from @param source
00032         //      into the serial connection
00033         int writeMultChars (const uint8_t* source, const size_t size);
00034 
00035         // clears all available symbols from the serial connection
00036         int clearAll ();
00037 
00038         // sets the timeout in milliseconds to @param tout
00039         void setTimeout (uint32_t tout);
00040 
00041         // sets the baud to @param baud
00042         void setBaud (uint32_t baud);
00043 
00044         // sets the format for port
00045         void setFormat (int bits=8, SerialBase::Parity parity=SerialBase::None, int stop_bits=1);
00046 
00047     private:
00048         Serial port; // port
00049         uint32_t timeout; // timeout time in millisecondes
00050         Timer timer; // timer which tracks timeout time
00051 };
00052 
00053 #endif