A library for talking to Multi-Tech's Cellular SocketModem Devices.
Dependents: M2X_dev axeda_wrapper_dev MTS_M2x_Example1 MTS_Cellular_Connect_Example ... more
io/MTSBufferedIO.h
- Committer:
- mfiore
- Date:
- 2013-12-19
- Revision:
- 40:14342c4de476
- Parent:
- 36:bb6b293c7495
- Parent:
- 39:6e94520a3217
- Child:
- 43:3cacf019ed7d
File content as of revision 40:14342c4de476:
#ifndef MTSBUFFEREDIO_H #define MTSBUFFEREDIO_H #include "mbed.h" #include "MTSCircularBuffer.h" namespace mts { /** This is an abstract class for lightweight buffered io to an underlying * data interface. Specifically the inheriting class will need to override * both the handle read and handle write functions which transfer data between * the classes internal read and write buffers and the physical communications * link or its HW buffers. */ class MTSBufferedIO { public: /** Creates a new BufferedIO object with the passed in static buffer sizes. * Note that because this class is abstract you cannot construct it directly. * Instead, please construct when of its derived classes like MTSSerial or * MTSSerialFlowControl. */ MTSBufferedIO(int txBufferSize = 128, int rxBufferSize = 128); /** Destructs an MTSBufferedIO object and frees all related resources, including * internal buffers. */ ~MTSBufferedIO(); int write(char* data, int length); int write(char data); int writeable(); int read(char* data, int length); int read(char& data); int readable(); template<typename T> void attach(T *tptr, void(T::*mptr)(void), int threshold, Vars::RelationalOperator op, Serial::IrqType type); void attach(void(*fptr)(void), int threshold, Vars::RelationalOperator op, Serial::IrqType type); /** This method determines if the Tx or write buffer is empty. * * @returns true if empty, otherwise false. */ bool txEmpty(); /** This method determines if the Rx or read buffer is empty. * * @returns true if empty, otherwise false. */ bool rxEmpty(); /** This method determines if the Tx or write buffer is full. * * @returns true if full, otherwise false. */ bool txFull(); /** This method determines if the Rx or read buffer is full. * * @returns true if full, otherwise false. */ bool rxFull(); /** This method clears all the data from the internal Tx or write buffer. */ void txClear(); /** This method clears all the data from the internal Rx or read buffer. */ void rxClear(); /** This abstract method should be used by the deriving class to transfer * data from the internal write buffer (txBuffer) to the physical interface. * Note that this function is called everytime new data is written to the * txBuffer though one of the write calls. */ virtual void handleWrite() = 0; /** This abstract method should be used by the deriving class to transfer * data from the physical interface ot the internal read buffer (rxBuffer). * Note that this function is never called in this class and typically should * be called as part of a receive data interrupt routine. */ virtual void handleRead() = 0; protected: MTSCircularBuffer* txBuffer; // Internal write or transmit circular buffer MTSCircularBuffer* rxBuffer; // Internal read or receieve circular buffer }; } #endif /* MTSBUFFEREDIO_H */