Serial library for MTS Socket Modem Arduino Shield devices from Multi-Tech Systems
Dependents: mDot_AT_firmware mtsas mtsas MTDOT-EVB-LinkCheck-AL ... more
MTSBufferedIO Class Reference
This is an abstract class for lightweight buffered io to an underlying data interface. More...
#include <MTSBufferedIO.h>
Inherited by MTSSerial.
Public Member Functions | |
MTSBufferedIO (int txBufferSize=256, int rxBufferSize=256) | |
Creates a new BufferedIO object with the passed in static buffer sizes. | |
~MTSBufferedIO () | |
Destructs an MTSBufferedIO object and frees all related resources. | |
int | write (const char *data, int length, unsigned int timeoutMillis) |
This method enables bulk writes to the Tx or write buffer. | |
int | write (const char *data, int length) |
This method enables bulk writes to the Tx or write buffer. | |
int | writef (const char *format,...) |
This method enables bulk writes to the Tx or write buffer. | |
int | write (char data, unsigned int timeoutMillis) |
This method attempts to write a single byte to the tx buffer within the timeout period. | |
int | write (char data) |
This method writes a single byte as a char to the Tx or write buffer. | |
int | writeable () |
This method is used to get the space available to write bytes to the Tx buffer. | |
int | read (char *data, int length, unsigned int timeoutMillis) |
This method enables bulk reads from the Rx or read buffer. | |
int | read (char *data, int length) |
This method enables bulk reads from the Rx or read buffer. | |
int | read (char &data, unsigned int timeoutMillis) |
This method reads a single byte from the Rx or read buffer. | |
int | read (char &data) |
This method reads a single byte from the Rx or read buffer. | |
int | readable () |
This method is used to get the number of bytes available to read from the Rx or read buffer. | |
bool | txEmpty () |
This method determines if the Tx or write buffer is empty. | |
bool | rxEmpty () |
This method determines if the Rx or read buffer is empty. | |
bool | txFull () |
This method determines if the Tx or write buffer is full. | |
bool | rxFull () |
This method determines if the Rx or read buffer is full. | |
virtual void | txClear () |
This method clears all the data from the internal Tx or write buffer. | |
virtual void | rxClear () |
This method clears all the data from the internal Rx or read buffer. | |
virtual void | handleWrite ()=0 |
This abstract method should be used by the deriving class to transfer data from the internal write buffer (txBuffer) to the physical interface. | |
virtual void | handleRead ()=0 |
This abstract method should be used by the deriving class to transfer data from the physical interface to the internal read buffer (rxBuffer). |
Detailed Description
This is an abstract class for lightweight buffered io to an underlying data interface.
Specifically the inheriting class will need to override both the handleRead and handleWrite methods which transfer data between the class's internal read and write buffers and the physical communications link and its HW buffers.
Definition at line 16 of file MTSBufferedIO.h.
Constructor & Destructor Documentation
MTSBufferedIO | ( | int | txBufferSize = 256 , |
int | rxBufferSize = 256 |
||
) |
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 one of its derived classes like MTSSerial or MTSSerialFlowControl.
- Parameters:
-
txBufferSize the size of the Tx or write buffer in bytes. The default is 256 bytes. rxBufferSize the size of the Rx or read buffer in bytes. The default is 256 bytes.
Definition at line 7 of file MTSBufferedIO.cpp.
~MTSBufferedIO | ( | ) |
Destructs an MTSBufferedIO object and frees all related resources.
Definition at line 14 of file MTSBufferedIO.cpp.
Member Function Documentation
virtual void handleRead | ( | ) | [pure virtual] |
This abstract method should be used by the deriving class to transfer data from the physical interface to 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 handleWrite | ( | ) | [pure virtual] |
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 every time new data is written to the txBuffer through one of the write calls.
int read | ( | char & | data, |
unsigned int | timeoutMillis | ||
) |
This method reads a single byte from the Rx or read buffer.
This method attempts to read a byte, but will return without reading one if the specified timeout is reached.
- Parameters:
-
data char where the read byte will be stored. amount of time to complete operation.
- Returns:
- 1 if byte is read or 0 if no byte is available.
Definition at line 101 of file MTSBufferedIO.cpp.
int read | ( | char * | data, |
int | length, | ||
unsigned int | timeoutMillis | ||
) |
This method enables bulk reads from the Rx or read buffer.
It attempts to read the amount specified, but will complete early if the specified timeout expires.
- Parameters:
-
data the buffer where data read will be added to. length the amount of data in bytes to be read into the buffer. amount of time to complete operation.
- Returns:
- the total number of bytes that were read.
Definition at line 79 of file MTSBufferedIO.cpp.
int read | ( | char * | data, |
int | length | ||
) |
This method enables bulk reads from the Rx or read buffer.
This method blocks until the amount of data requested is received.
- Parameters:
-
data the buffer where data read will be added to. length the amount of data in bytes to be read into the buffer.
- Returns:
- the total number of bytes that were read. This should be equal to the length parameter since this is a blocking call.
Definition at line 91 of file MTSBufferedIO.cpp.
int read | ( | char & | data ) |
This method reads a single byte from the Rx or read buffer.
This method blocks until the single byte is read.
- Parameters:
-
data char where the read byte will be stored.
- Returns:
- 1 once the byte has been read.
Definition at line 106 of file MTSBufferedIO.cpp.
int readable | ( | ) |
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.
Definition at line 111 of file MTSBufferedIO.cpp.
void rxClear | ( | ) | [virtual] |
This method clears all the data from the internal Rx or read buffer.
Reimplemented in MTSSerialFlowControl.
Definition at line 140 of file MTSBufferedIO.cpp.
bool rxEmpty | ( | ) |
This method determines if the Rx or read buffer is empty.
- Returns:
- true if empty, otherwise false.
Definition at line 120 of file MTSBufferedIO.cpp.
bool rxFull | ( | ) |
This method determines if the Rx or read buffer is full.
- Returns:
- true if full, otherwise false.
Definition at line 130 of file MTSBufferedIO.cpp.
void txClear | ( | ) | [virtual] |
This method clears all the data from the internal Tx or write buffer.
Definition at line 135 of file MTSBufferedIO.cpp.
bool txEmpty | ( | ) |
This method determines if the Tx or write buffer is empty.
- Returns:
- true if empty, otherwise false.
Definition at line 115 of file MTSBufferedIO.cpp.
bool txFull | ( | ) |
This method determines if the Tx or write buffer is full.
- Returns:
- true if full, otherwise false.
Definition at line 125 of file MTSBufferedIO.cpp.
int write | ( | const char * | data, |
int | length, | ||
unsigned int | timeoutMillis | ||
) |
This method enables bulk writes to the Tx or write buffer.
If more data is requested to be written then space available the method writes as much data as possible within the timeout period and returns the actual amount written.
- Parameters:
-
data the byte array to be written. length the length of data to be written from the data parameter. amount of time in milliseconds to complete operation.
- Returns:
- the number of bytes written to the buffer, which is 0 if the buffer is full.
Definition at line 31 of file MTSBufferedIO.cpp.
int write | ( | char | data, |
unsigned int | timeoutMillis | ||
) |
This method attempts to write a single byte to the tx buffer within the timeout period.
- Parameters:
-
data the byte to be written as a char. amount of time in milliseconds to complete operation.
- Returns:
- 1 if the byte was written or 0 if the buffer was full and the timeout expired.
Definition at line 65 of file MTSBufferedIO.cpp.
int write | ( | char | data ) |
This method writes a single byte as a char to the Tx or write buffer.
This method blocks until the byte is written.
- Parameters:
-
data the byte to be written as a char.
- Returns:
- 1 once the byte has been written.
Definition at line 70 of file MTSBufferedIO.cpp.
int write | ( | const char * | data, |
int | length | ||
) |
This method enables bulk writes to the Tx or write buffer.
This method blocks until all the bytes are written.
- Parameters:
-
data the byte array to be written. length the length of data to be written from the data parameter.
- Returns:
- the number of bytes written to the buffer, which should be equal to the length parameter since this method blocks.
Definition at line 50 of file MTSBufferedIO.cpp.
int writeable | ( | ) |
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.
Definition at line 75 of file MTSBufferedIO.cpp.
int writef | ( | const char * | format, |
... | |||
) |
This method enables bulk writes to the Tx or write buffer.
This method blocks until all the bytes are written.
- Parameters:
-
format of the string to be written. additional arguments will be placed in the format string.
- Returns:
- the number of bytes written to the buffer.
Definition at line 18 of file MTSBufferedIO.cpp.
Generated on Thu Jul 14 2022 05:10:02 by 1.7.2