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

Committer:
jengbrecht
Date:
Thu Dec 19 21:48:32 2013 +0000
Revision:
46:b30547bf07d5
Parent:
45:40745c2036cf
Parent:
43:3cacf019ed7d
Child:
68:c490e4a51778
Merged, removed Axeda Wrapper

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jengbrecht 0:563b70517320 1 #ifndef MTSBUFFEREDIO_H
jengbrecht 0:563b70517320 2 #define MTSBUFFEREDIO_H
jengbrecht 0:563b70517320 3
jengbrecht 0:563b70517320 4 #include "mbed.h"
jengbrecht 0:563b70517320 5 #include "MTSCircularBuffer.h"
jengbrecht 0:563b70517320 6
mfiore 39:6e94520a3217 7 namespace mts {
mfiore 39:6e94520a3217 8
jengbrecht 36:bb6b293c7495 9 /** This is an abstract class for lightweight buffered io to an underlying
jengbrecht 36:bb6b293c7495 10 * data interface. Specifically the inheriting class will need to override
jengbrecht 45:40745c2036cf 11 * both the handleRead and handleWrite methods which transfer data between
jengbrecht 45:40745c2036cf 12 * the class's internal read and write buffers and the physical communications
jengbrecht 36:bb6b293c7495 13 * link or its HW buffers.
jengbrecht 36:bb6b293c7495 14 */
mfiore 40:14342c4de476 15
jengbrecht 0:563b70517320 16 class MTSBufferedIO
jengbrecht 0:563b70517320 17 {
jengbrecht 0:563b70517320 18 public:
jengbrecht 36:bb6b293c7495 19 /** Creates a new BufferedIO object with the passed in static buffer sizes.
jengbrecht 36:bb6b293c7495 20 * Note that because this class is abstract you cannot construct it directly.
jengbrecht 45:40745c2036cf 21 * Instead, please construct one of its derived classes like MTSSerial or
jengbrecht 36:bb6b293c7495 22 * MTSSerialFlowControl.
jengbrecht 45:40745c2036cf 23 *
jengbrecht 45:40745c2036cf 24 * @param txBufferSize the size of the Tx or write buffer in bytes. The default is
jengbrecht 45:40745c2036cf 25 * 128 bytes.
jengbrecht 45:40745c2036cf 26 * @param rxBufferSize the size of the Rx or read buffer in bytes. The default is
jengbrecht 45:40745c2036cf 27 * 128 bytes.
jengbrecht 36:bb6b293c7495 28 */
jengbrecht 0:563b70517320 29 MTSBufferedIO(int txBufferSize = 128, int rxBufferSize = 128);
jengbrecht 36:bb6b293c7495 30
jengbrecht 36:bb6b293c7495 31 /** Destructs an MTSBufferedIO object and frees all related resources, including
jengbrecht 36:bb6b293c7495 32 * internal buffers.
jengbrecht 36:bb6b293c7495 33 */
jengbrecht 0:563b70517320 34 ~MTSBufferedIO();
jengbrecht 0:563b70517320 35
jengbrecht 45:40745c2036cf 36 /** This method enables bulk writes to the Tx or wriet buffer. If more data
jengbrecht 45:40745c2036cf 37 * is requested to be written then space available the method writes
jengbrecht 45:40745c2036cf 38 * as much data as possible and returns the actual amount written.
jengbrecht 45:40745c2036cf 39 *
jengbrecht 45:40745c2036cf 40 * @param data the byte array to be written.
jengbrecht 45:40745c2036cf 41 * @param length the length of data to be written from the data paramter.
jengbrecht 45:40745c2036cf 42 * @returns the number of bytes written to the buffer, which is 0 if
jengbrecht 45:40745c2036cf 43 * the buffer is full.
jengbrecht 45:40745c2036cf 44 */
sgodinez 41:81d035fb0b6a 45 int write(const char* data, int length);
jengbrecht 45:40745c2036cf 46
jengbrecht 45:40745c2036cf 47 /** This method writes a signle byte as a char to the Tx or write buffer.
jengbrecht 45:40745c2036cf 48 *
jengbrecht 45:40745c2036cf 49 * @param data the byte to be written as a char.
jengbrecht 45:40745c2036cf 50 * @returns 1 if the byte was written or 0 if the buffer was full.
jengbrecht 45:40745c2036cf 51 */
jengbrecht 0:563b70517320 52 int write(char data);
jengbrecht 45:40745c2036cf 53
jengbrecht 45:40745c2036cf 54 /** This method is used to get the space available to write bytes to the Tx buffer.
jengbrecht 45:40745c2036cf 55 *
jengbrecht 45:40745c2036cf 56 * @returns the number of bytes that can be written, 0 if the buffer is full.
jengbrecht 45:40745c2036cf 57 */
sgodinez 17:2d7c4ea7491b 58 int writeable();
jengbrecht 45:40745c2036cf 59
jengbrecht 45:40745c2036cf 60 /** This method enables bulk reads from the Rx or read buffer. If more data is
jengbrecht 45:40745c2036cf 61 * requested then available it simply returns all remaining data within the
jengbrecht 45:40745c2036cf 62 * buffer.
jengbrecht 45:40745c2036cf 63 *
jengbrecht 45:40745c2036cf 64 * @param data the buffer where data read will be added to.
jengbrecht 45:40745c2036cf 65 * @param length the amount of data in bytes to be read into the buffer.
jengbrecht 45:40745c2036cf 66 * @returns the total number of bytes that were read.
jengbrecht 45:40745c2036cf 67 */
jengbrecht 0:563b70517320 68 int read(char* data, int length);
jengbrecht 45:40745c2036cf 69
jengbrecht 45:40745c2036cf 70 /** This method reads a single byte from the Rx or read buffer.
jengbrecht 45:40745c2036cf 71 *
jengbrecht 45:40745c2036cf 72 * @param data char where the read byte will be stored.
jengbrecht 45:40745c2036cf 73 * @returns 1 if byte is read or 0 if no byte is available.
jengbrecht 45:40745c2036cf 74 */
sgodinez 17:2d7c4ea7491b 75 int read(char& data);
jengbrecht 45:40745c2036cf 76
jengbrecht 45:40745c2036cf 77 /** This method is used to get the number of bytes available to read from
jengbrecht 45:40745c2036cf 78 * the Rx or read buffer.
jengbrecht 45:40745c2036cf 79 *
jengbrecht 45:40745c2036cf 80 * @returns the number of bytes available, 0 if there are no bytes to read.
jengbrecht 45:40745c2036cf 81 */
sgodinez 17:2d7c4ea7491b 82 int readable();
jengbrecht 0:563b70517320 83
jengbrecht 36:bb6b293c7495 84 /** This method determines if the Tx or write buffer is empty.
jengbrecht 36:bb6b293c7495 85 *
jengbrecht 36:bb6b293c7495 86 * @returns true if empty, otherwise false.
jengbrecht 36:bb6b293c7495 87 */
jengbrecht 0:563b70517320 88 bool txEmpty();
jengbrecht 36:bb6b293c7495 89
jengbrecht 36:bb6b293c7495 90 /** This method determines if the Rx or read buffer is empty.
jengbrecht 36:bb6b293c7495 91 *
jengbrecht 36:bb6b293c7495 92 * @returns true if empty, otherwise false.
jengbrecht 36:bb6b293c7495 93 */
jengbrecht 0:563b70517320 94 bool rxEmpty();
jengbrecht 36:bb6b293c7495 95
jengbrecht 36:bb6b293c7495 96 /** This method determines if the Tx or write buffer is full.
jengbrecht 36:bb6b293c7495 97 *
jengbrecht 36:bb6b293c7495 98 * @returns true if full, otherwise false.
jengbrecht 36:bb6b293c7495 99 */
jengbrecht 0:563b70517320 100 bool txFull();
jengbrecht 36:bb6b293c7495 101
jengbrecht 36:bb6b293c7495 102 /** This method determines if the Rx or read buffer is full.
jengbrecht 36:bb6b293c7495 103 *
jengbrecht 36:bb6b293c7495 104 * @returns true if full, otherwise false.
jengbrecht 36:bb6b293c7495 105 */
jengbrecht 0:563b70517320 106 bool rxFull();
jengbrecht 36:bb6b293c7495 107
jengbrecht 36:bb6b293c7495 108 /** This method clears all the data from the internal Tx or write buffer.
jengbrecht 36:bb6b293c7495 109 */
jengbrecht 0:563b70517320 110 void txClear();
jengbrecht 36:bb6b293c7495 111
jengbrecht 36:bb6b293c7495 112 /** This method clears all the data from the internal Rx or read buffer.
jengbrecht 36:bb6b293c7495 113 */
jengbrecht 0:563b70517320 114 void rxClear();
jengbrecht 0:563b70517320 115
jengbrecht 36:bb6b293c7495 116 /** This abstract method should be used by the deriving class to transfer
jengbrecht 36:bb6b293c7495 117 * data from the internal write buffer (txBuffer) to the physical interface.
jengbrecht 36:bb6b293c7495 118 * Note that this function is called everytime new data is written to the
jengbrecht 36:bb6b293c7495 119 * txBuffer though one of the write calls.
jengbrecht 36:bb6b293c7495 120 */
jengbrecht 0:563b70517320 121 virtual void handleWrite() = 0;
jengbrecht 36:bb6b293c7495 122
jengbrecht 36:bb6b293c7495 123 /** This abstract method should be used by the deriving class to transfer
jengbrecht 36:bb6b293c7495 124 * data from the physical interface ot the internal read buffer (rxBuffer).
jengbrecht 36:bb6b293c7495 125 * Note that this function is never called in this class and typically should
jengbrecht 36:bb6b293c7495 126 * be called as part of a receive data interrupt routine.
jengbrecht 36:bb6b293c7495 127 */
jengbrecht 0:563b70517320 128 virtual void handleRead() = 0;
jengbrecht 0:563b70517320 129
jengbrecht 0:563b70517320 130 protected:
jengbrecht 36:bb6b293c7495 131 MTSCircularBuffer* txBuffer; // Internal write or transmit circular buffer
jengbrecht 36:bb6b293c7495 132 MTSCircularBuffer* rxBuffer; // Internal read or receieve circular buffer
jengbrecht 0:563b70517320 133 };
jengbrecht 0:563b70517320 134
mfiore 39:6e94520a3217 135 }
mfiore 39:6e94520a3217 136
jengbrecht 0:563b70517320 137 #endif /* MTSBUFFEREDIO_H */