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@40:14342c4de476, 2013-12-19 (annotated)
- Committer:
- mfiore
- Date:
- Thu Dec 19 19:53:43 2013 +0000
- Revision:
- 40:14342c4de476
- Parent:
- 36:bb6b293c7495
- Parent:
- 39:6e94520a3217
- Child:
- 43:3cacf019ed7d
merge changes
Who changed what in which revision?
User | Revision | Line number | New 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 | 36:bb6b293c7495 | 11 | * both the handle read and handle write functions which transfer data between |
jengbrecht | 36:bb6b293c7495 | 12 | * the classes 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 | 36:bb6b293c7495 | 21 | * Instead, please construct when of its derived classes like MTSSerial or |
jengbrecht | 36:bb6b293c7495 | 22 | * MTSSerialFlowControl. |
jengbrecht | 36:bb6b293c7495 | 23 | */ |
jengbrecht | 0:563b70517320 | 24 | MTSBufferedIO(int txBufferSize = 128, int rxBufferSize = 128); |
jengbrecht | 36:bb6b293c7495 | 25 | |
jengbrecht | 36:bb6b293c7495 | 26 | /** Destructs an MTSBufferedIO object and frees all related resources, including |
jengbrecht | 36:bb6b293c7495 | 27 | * internal buffers. |
jengbrecht | 36:bb6b293c7495 | 28 | */ |
jengbrecht | 0:563b70517320 | 29 | ~MTSBufferedIO(); |
jengbrecht | 0:563b70517320 | 30 | |
jengbrecht | 0:563b70517320 | 31 | int write(char* data, int length); |
jengbrecht | 0:563b70517320 | 32 | int write(char data); |
sgodinez | 17:2d7c4ea7491b | 33 | int writeable(); |
jengbrecht | 0:563b70517320 | 34 | int read(char* data, int length); |
sgodinez | 17:2d7c4ea7491b | 35 | int read(char& data); |
sgodinez | 17:2d7c4ea7491b | 36 | int readable(); |
jengbrecht | 0:563b70517320 | 37 | |
jengbrecht | 0:563b70517320 | 38 | template<typename T> |
jengbrecht | 0:563b70517320 | 39 | void attach(T *tptr, void(T::*mptr)(void), int threshold, Vars::RelationalOperator op, Serial::IrqType type); |
jengbrecht | 36:bb6b293c7495 | 40 | |
jengbrecht | 0:563b70517320 | 41 | void attach(void(*fptr)(void), int threshold, Vars::RelationalOperator op, Serial::IrqType type); |
jengbrecht | 0:563b70517320 | 42 | |
jengbrecht | 36:bb6b293c7495 | 43 | /** This method determines if the Tx or write buffer is empty. |
jengbrecht | 36:bb6b293c7495 | 44 | * |
jengbrecht | 36:bb6b293c7495 | 45 | * @returns true if empty, otherwise false. |
jengbrecht | 36:bb6b293c7495 | 46 | */ |
jengbrecht | 0:563b70517320 | 47 | bool txEmpty(); |
jengbrecht | 36:bb6b293c7495 | 48 | |
jengbrecht | 36:bb6b293c7495 | 49 | /** This method determines if the Rx or read buffer is empty. |
jengbrecht | 36:bb6b293c7495 | 50 | * |
jengbrecht | 36:bb6b293c7495 | 51 | * @returns true if empty, otherwise false. |
jengbrecht | 36:bb6b293c7495 | 52 | */ |
jengbrecht | 0:563b70517320 | 53 | bool rxEmpty(); |
jengbrecht | 36:bb6b293c7495 | 54 | |
jengbrecht | 36:bb6b293c7495 | 55 | /** This method determines if the Tx or write buffer is full. |
jengbrecht | 36:bb6b293c7495 | 56 | * |
jengbrecht | 36:bb6b293c7495 | 57 | * @returns true if full, otherwise false. |
jengbrecht | 36:bb6b293c7495 | 58 | */ |
jengbrecht | 0:563b70517320 | 59 | bool txFull(); |
jengbrecht | 36:bb6b293c7495 | 60 | |
jengbrecht | 36:bb6b293c7495 | 61 | /** This method determines if the Rx or read buffer is full. |
jengbrecht | 36:bb6b293c7495 | 62 | * |
jengbrecht | 36:bb6b293c7495 | 63 | * @returns true if full, otherwise false. |
jengbrecht | 36:bb6b293c7495 | 64 | */ |
jengbrecht | 0:563b70517320 | 65 | bool rxFull(); |
jengbrecht | 36:bb6b293c7495 | 66 | |
jengbrecht | 36:bb6b293c7495 | 67 | /** This method clears all the data from the internal Tx or write buffer. |
jengbrecht | 36:bb6b293c7495 | 68 | */ |
jengbrecht | 0:563b70517320 | 69 | void txClear(); |
jengbrecht | 36:bb6b293c7495 | 70 | |
jengbrecht | 36:bb6b293c7495 | 71 | /** This method clears all the data from the internal Rx or read buffer. |
jengbrecht | 36:bb6b293c7495 | 72 | */ |
jengbrecht | 0:563b70517320 | 73 | void rxClear(); |
jengbrecht | 0:563b70517320 | 74 | |
jengbrecht | 36:bb6b293c7495 | 75 | /** This abstract method should be used by the deriving class to transfer |
jengbrecht | 36:bb6b293c7495 | 76 | * data from the internal write buffer (txBuffer) to the physical interface. |
jengbrecht | 36:bb6b293c7495 | 77 | * Note that this function is called everytime new data is written to the |
jengbrecht | 36:bb6b293c7495 | 78 | * txBuffer though one of the write calls. |
jengbrecht | 36:bb6b293c7495 | 79 | */ |
jengbrecht | 0:563b70517320 | 80 | virtual void handleWrite() = 0; |
jengbrecht | 36:bb6b293c7495 | 81 | |
jengbrecht | 36:bb6b293c7495 | 82 | /** This abstract method should be used by the deriving class to transfer |
jengbrecht | 36:bb6b293c7495 | 83 | * data from the physical interface ot the internal read buffer (rxBuffer). |
jengbrecht | 36:bb6b293c7495 | 84 | * Note that this function is never called in this class and typically should |
jengbrecht | 36:bb6b293c7495 | 85 | * be called as part of a receive data interrupt routine. |
jengbrecht | 36:bb6b293c7495 | 86 | */ |
jengbrecht | 0:563b70517320 | 87 | virtual void handleRead() = 0; |
jengbrecht | 0:563b70517320 | 88 | |
jengbrecht | 0:563b70517320 | 89 | protected: |
jengbrecht | 36:bb6b293c7495 | 90 | MTSCircularBuffer* txBuffer; // Internal write or transmit circular buffer |
jengbrecht | 36:bb6b293c7495 | 91 | MTSCircularBuffer* rxBuffer; // Internal read or receieve circular buffer |
jengbrecht | 0:563b70517320 | 92 | }; |
jengbrecht | 0:563b70517320 | 93 | |
mfiore | 39:6e94520a3217 | 94 | } |
mfiore | 39:6e94520a3217 | 95 | |
jengbrecht | 0:563b70517320 | 96 | #endif /* MTSBUFFEREDIO_H */ |