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
Diff: io/MTSBufferedIO.h
- Revision:
- 45:40745c2036cf
- Parent:
- 36:bb6b293c7495
- Child:
- 46:b30547bf07d5
--- a/io/MTSBufferedIO.h Thu Dec 19 16:54:09 2013 +0000 +++ b/io/MTSBufferedIO.h Thu Dec 19 21:38:01 2013 +0000 @@ -6,8 +6,8 @@ /** 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 +* both the handleRead and handleWrite methods which transfer data between +* the class's internal read and write buffers and the physical communications * link or its HW buffers. */ class MTSBufferedIO @@ -15,8 +15,13 @@ 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 + * Instead, please construct one of its derived classes like MTSSerial or * MTSSerialFlowControl. + * + * @param txBufferSize the size of the Tx or write buffer in bytes. The default is + * 128 bytes. + * @param rxBufferSize the size of the Rx or read buffer in bytes. The default is + * 128 bytes. */ MTSBufferedIO(int txBufferSize = 128, int rxBufferSize = 128); @@ -25,18 +30,54 @@ */ ~MTSBufferedIO(); + /** This method enables bulk writes to the Tx or wriet buffer. If more data + * is requested to be written then space available the method writes + * as much data as possible and returns the actual amount written. + * + * @param data the byte array to be written. + * @param length the length of data to be written from the data paramter. + * @returns the number of bytes written to the buffer, which is 0 if + * the buffer is full. + */ int write(char* data, int length); + + /** This method writes a signle byte as a char to the Tx or write buffer. + * + * @param data the byte to be written as a char. + * @returns 1 if the byte was written or 0 if the buffer was full. + */ int write(char data); + + /** This method is used to get the space available to write bytes to the Tx buffer. + * + * @returns the number of bytes that can be written, 0 if the buffer is full. + */ int writeable(); + + /** This method enables bulk reads from the Rx or read buffer. If more data is + * requested then available it simply returns all remaining data within the + * buffer. + * + * @param data the buffer where data read will be added to. + * @param length the amount of data in bytes to be read into the buffer. + * @returns the total number of bytes that were read. + */ int read(char* data, int length); + + /** This method reads a single byte from the Rx or read buffer. + * + * @param data char where the read byte will be stored. + * @returns 1 if byte is read or 0 if no byte is available. + */ int read(char& data); + + /** This method is used to get the number of bytes available to read from + * the Rx or read buffer. + * + * @returns the number of bytes available, 0 if there are no bytes to read. + */ 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.