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

Embed: (wiki syntax)

« Back to documentation index

MTSBufferedIO Class Reference

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=128, int rxBufferSize=128)
 Creates a new BufferedIO object with the passed in static buffer sizes.
 ~MTSBufferedIO ()
 Destructs an MTSBufferedIO object and frees all related resources, including internal buffers.
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 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 signle 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 ot 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 or its HW buffers.

Definition at line 32 of file MTSBufferedIO.h.


Constructor & Destructor Documentation

MTSBufferedIO ( int  txBufferSize = 128,
int  rxBufferSize = 128 
)

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:
txBufferSizethe size of the Tx or write buffer in bytes. The default is 128 bytes.
rxBufferSizethe size of the Rx or read buffer in bytes. The default is 128 bytes.

Definition at line 21 of file MTSBufferedIO.cpp.

~MTSBufferedIO (  )

Destructs an MTSBufferedIO object and frees all related resources, including internal buffers.

Definition at line 28 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 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 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 everytime new data is written to the txBuffer though one of the write calls.

int read ( char *  data,
int  length,
unsigned int  timeoutMillis 
)

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.

Parameters:
datathe buffer where data read will be added to.
lengththe 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 81 of file MTSBufferedIO.cpp.

int read ( char &  data )

This method reads a single byte from the Rx or read buffer.

Parameters:
datachar where the read byte will be stored.
Returns:
1 if byte is read or 0 if no byte is available.

Definition at line 108 of file MTSBufferedIO.cpp.

int read ( char &  data,
unsigned int  timeoutMillis 
)

This method reads a single byte from the Rx or read buffer.

Parameters:
datachar 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 103 of file MTSBufferedIO.cpp.

int read ( char *  data,
int  length 
)

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.

Parameters:
datathe buffer where data read will be added to.
lengththe amount of data in bytes to be read into the buffer.
Returns:
the total number of bytes that were read.

Definition at line 93 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 113 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 142 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 122 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 132 of file MTSBufferedIO.cpp.

void txClear (  ) [virtual]

This method clears all the data from the internal Tx or write buffer.

Definition at line 137 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 117 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 127 of file MTSBufferedIO.cpp.

int write ( char  data )

This method writes a signle byte as a char to the Tx or write buffer.

Parameters:
datathe byte to be written as a char.
Returns:
1 if the byte was written or 0 if the buffer was full.

Definition at line 72 of file MTSBufferedIO.cpp.

int write ( const char *  data,
int  length 
)

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 and returns the actual amount written.

Parameters:
datathe byte array to be written.
lengththe length of data to be written from the data parameter.
Returns:
the number of bytes written to the buffer, which is 0 if the buffer is full.

Definition at line 52 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:
datathe byte array to be written.
lengththe 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 33 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:
datathe 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.

Definition at line 67 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 77 of file MTSBufferedIO.cpp.