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:
sgodinez
Date:
Thu Dec 26 23:32:02 2013 +0000
Revision:
78:ef3ee53cf5df
Parent:
77:d7b14688a704
Child:
83:9813f9b8ee68
Setup RTS/CTS as DTE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jengbrecht 0:563b70517320 1 #ifndef MTSSERIALFLOWCONTROL_H
jengbrecht 0:563b70517320 2 #define MTSSERIALFLOWCONTROL_H
jengbrecht 0:563b70517320 3
jengbrecht 0:563b70517320 4 #include "mbed.h"
jengbrecht 0:563b70517320 5 #include "MTSBufferedIO.h"
mfiore 2:8d3ea0dfce39 6
jengbrecht 77:d7b14688a704 7 namespace mts
jengbrecht 77:d7b14688a704 8 {
mfiore 39:6e94520a3217 9
jengbrecht 45:40745c2036cf 10 /** This class derives from MTSBufferedIO and provides a buffered wrapper to the
jengbrecht 45:40745c2036cf 11 * standard mbed Serial class along with generic RTS/CTS HW flow control. Since it
jengbrecht 45:40745c2036cf 12 * depends only on the mbed Serial, DigitalOut and InterruptIn classes for accessing
jengbrecht 45:40745c2036cf 13 * the serial data, this class is inherently portable accross different mbed platforms
jengbrecht 45:40745c2036cf 14 * and provides HW flow control even when not natively supported by the processors
jengbrecht 45:40745c2036cf 15 * serial port. If HW flow control is not needed, use MTSSerial instead.
jengbrecht 45:40745c2036cf 16 */
jengbrecht 0:563b70517320 17 class MTSSerialFlowControl : public MTSBufferedIO
jengbrecht 0:563b70517320 18 {
jengbrecht 0:563b70517320 19 public:
jengbrecht 45:40745c2036cf 20 /** Creates a new MTSSerialFlowControl object that can be used to talk to an mbed serial
jengbrecht 36:bb6b293c7495 21 * port through internal SW buffers. Note that this class also adds the ability to use
jengbrecht 45:40745c2036cf 22 * RTS/CTS HW Flow Conrtol through and standard mbed InterruptIn and DigitalOut pins.
jengbrecht 36:bb6b293c7495 23 *
jengbrecht 45:40745c2036cf 24 * @param TXD the transmit data pin on the desired mbed serial interface.
jengbrecht 45:40745c2036cf 25 * @param RXD the receive data pin on the desired mbed serial interface.
jengbrecht 45:40745c2036cf 26 * @param RTS the InterruptIn pin that RTS will be attached to.
jengbrecht 36:bb6b293c7495 27 * @param CTS the DigitalOut pin that CTS will be attached to.
jengbrecht 36:bb6b293c7495 28 * @param txBufferSize the size in bytes of the internal SW transmit buffer. The
jengbrecht 36:bb6b293c7495 29 * default is 64 bytes.
jengbrecht 36:bb6b293c7495 30 * @param rxBufferSize the size in bytes of the internal SW receive buffer. The
jengbrecht 36:bb6b293c7495 31 * default is 64 bytes.
jengbrecht 36:bb6b293c7495 32 * @param name an optional name for the serial port. The default is blank.
jengbrecht 36:bb6b293c7495 33 */
mfiore 10:2bd727a4b329 34 MTSSerialFlowControl(PinName TXD, PinName RXD, PinName RTS, PinName CTS, int txBufSize = 64, int rxBufSize = 64, char* name = "");
jengbrecht 36:bb6b293c7495 35
jengbrecht 36:bb6b293c7495 36 /** Destructs an MTSSerialFlowControl object and frees all related resources,
jengbrecht 36:bb6b293c7495 37 * including internal buffers.
jengbrecht 36:bb6b293c7495 38 */
jengbrecht 0:563b70517320 39 ~MTSSerialFlowControl();
jengbrecht 36:bb6b293c7495 40
jengbrecht 36:bb6b293c7495 41 /** This method is used to the set the baud rate of the serial port.
jengbrecht 36:bb6b293c7495 42 *
jengbrecht 36:bb6b293c7495 43 * @param baudrate the baudrate in bps as an int. The internal interface
jengbrecht 36:bb6b293c7495 44 * default is 9600 bps.
jengbrecht 36:bb6b293c7495 45 */
mfiore 10:2bd727a4b329 46 void baud(int baudrate);
jengbrecht 36:bb6b293c7495 47
jengbrecht 45:40745c2036cf 48 /** This method sets the transmission format used by the serial port.
jengbrecht 45:40745c2036cf 49 *
jengbrecht 45:40745c2036cf 50 * @param bits the number of bits in a word (5-8; default = 8)
jengbrecht 45:40745c2036cf 51 * @param parity the parity used (SerialBase::None, SerialBase::Odd, SerialBase::Even,
jengbrecht 45:40745c2036cf 52 * SerialBase::Forced1, SerialBase::Forced0; default = SerialBase::None)
jengbrecht 45:40745c2036cf 53 * @param stop the number of stop bits (1 or 2; default = 1)
jengbrecht 45:40745c2036cf 54 */
mfiore 51:d22d3d87391f 55 void format(int bits=8, SerialBase::Parity parity=mbed::SerialBase::None, int stop_bits=1);
jengbrecht 0:563b70517320 56
jengbrecht 0:563b70517320 57 private:
jengbrecht 77:d7b14688a704 58 void notifyStartSending(); // Used to set cts start signal
jengbrecht 77:d7b14688a704 59 void notifyStopSending(); // Used to set cts stop signal
sgodinez 78:ef3ee53cf5df 60
sgodinez 78:ef3ee53cf5df 61 //This device acts as a DTE
sgodinez 78:ef3ee53cf5df 62 DigitalOut* rts; // Used to tell DCE to send or not send data
sgodinez 78:ef3ee53cf5df 63 DigitalIn* cts; // Used to check if DCE is ready for data
jengbrecht 36:bb6b293c7495 64 Serial* serial; // Internal Mbed Serial object
jengbrecht 45:40745c2036cf 65 int highThreshold; // High water mark for setting cts to stop
jengbrecht 45:40745c2036cf 66 int lowThreshold; // Low water mark for setting cts to start
jengbrecht 45:40745c2036cf 67 char* if_name; // Internal variable for interface name
jengbrecht 36:bb6b293c7495 68
jengbrecht 45:40745c2036cf 69 virtual void handleRead(); // Method for handling data to be read
jengbrecht 45:40745c2036cf 70 virtual void handleWrite(); // Method for handling data to be written
jengbrecht 0:563b70517320 71 };
mfiore 2:8d3ea0dfce39 72
mfiore 39:6e94520a3217 73 }
mfiore 39:6e94520a3217 74
jengbrecht 0:563b70517320 75 #endif /* MTSSERIALFLOWCONTROL */