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:38:01 2013 +0000
Revision:
45:40745c2036cf
Parent:
36:bb6b293c7495
Child:
46:b30547bf07d5
Added a ton of documentation, made the notify start and stop methods private in MTSSerialFlowControl, added format method to the serial classes, fixed an issue in the bulk write method of MTSCircularBuffer

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