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