firm newest

Dependencies:   MTS-Serial libmDot-dev-mbed5-deprecated

Committer:
nguyenhoang9x5555
Date:
Mon Oct 22 01:56:09 2018 +0000
Revision:
1:c1c6549b9333
Parent:
0:3c869a8cb8f8
hey

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nguyenhoang9x5555 0:3c869a8cb8f8 1 #ifndef ATSERIAL_H
nguyenhoang9x5555 0:3c869a8cb8f8 2 #define ATSERIAL_H
nguyenhoang9x5555 0:3c869a8cb8f8 3
nguyenhoang9x5555 0:3c869a8cb8f8 4 #include "MTSSerial.h"
nguyenhoang9x5555 0:3c869a8cb8f8 5 #include "MTSBufferedIO.h"
nguyenhoang9x5555 0:3c869a8cb8f8 6
nguyenhoang9x5555 0:3c869a8cb8f8 7 namespace mts
nguyenhoang9x5555 0:3c869a8cb8f8 8 {
nguyenhoang9x5555 0:3c869a8cb8f8 9
nguyenhoang9x5555 0:3c869a8cb8f8 10 /** This class derives from MTSBufferedIO and provides a buffered wrapper to the
nguyenhoang9x5555 0:3c869a8cb8f8 11 * standard mbed Serial class. Since it depends only on the mbed Serial class for
nguyenhoang9x5555 0:3c869a8cb8f8 12 * accessing serial data, this class is inherently portable accross different mbed
nguyenhoang9x5555 0:3c869a8cb8f8 13 * platforms.
nguyenhoang9x5555 0:3c869a8cb8f8 14 */
nguyenhoang9x5555 0:3c869a8cb8f8 15 class ATSerial : public MTSSerial
nguyenhoang9x5555 0:3c869a8cb8f8 16 {
nguyenhoang9x5555 0:3c869a8cb8f8 17 public:
nguyenhoang9x5555 0:3c869a8cb8f8 18 /** Creates a new ATSerial object that can be used to talk to an mbed serial port
nguyenhoang9x5555 0:3c869a8cb8f8 19 * through internal SW buffers.
nguyenhoang9x5555 0:3c869a8cb8f8 20 *
nguyenhoang9x5555 0:3c869a8cb8f8 21 * @param TXD the transmit data pin on the desired mbed Serial interface.
nguyenhoang9x5555 0:3c869a8cb8f8 22 * @param RXD the receive data pin on the desired mbed Serial interface.
nguyenhoang9x5555 0:3c869a8cb8f8 23 * @param txBufferSize the size in bytes of the internal SW transmit buffer. The
nguyenhoang9x5555 0:3c869a8cb8f8 24 * default is 256 bytes.
nguyenhoang9x5555 0:3c869a8cb8f8 25 * @param rxBufferSize the size in bytes of the internal SW receive buffer. The
nguyenhoang9x5555 0:3c869a8cb8f8 26 * default is 256 bytes.
nguyenhoang9x5555 0:3c869a8cb8f8 27 */
nguyenhoang9x5555 0:3c869a8cb8f8 28 ATSerial(PinName TXD, PinName RXD, int txBufferSize = 256, int rxBufferSize = 256);
nguyenhoang9x5555 0:3c869a8cb8f8 29
nguyenhoang9x5555 0:3c869a8cb8f8 30 /** Destructs an ATSerial object and frees all related resources, including
nguyenhoang9x5555 0:3c869a8cb8f8 31 * internal buffers.
nguyenhoang9x5555 0:3c869a8cb8f8 32 */
nguyenhoang9x5555 0:3c869a8cb8f8 33 virtual ~ATSerial();
nguyenhoang9x5555 0:3c869a8cb8f8 34
nguyenhoang9x5555 0:3c869a8cb8f8 35 /**
nguyenhoang9x5555 0:3c869a8cb8f8 36 * Attach the internal serial object to provided pins
nguyenhoang9x5555 0:3c869a8cb8f8 37 * @param TXD the transmit data pin on the desired mbed Serial interface.
nguyenhoang9x5555 0:3c869a8cb8f8 38 * @param RXD the receive data pin on the desired mbed Serial interface.
nguyenhoang9x5555 0:3c869a8cb8f8 39 */
nguyenhoang9x5555 0:3c869a8cb8f8 40 void reattach(PinName TXD, PinName RXD);
nguyenhoang9x5555 0:3c869a8cb8f8 41
nguyenhoang9x5555 0:3c869a8cb8f8 42 /** This method is used to the set the baud rate of the serial port.
nguyenhoang9x5555 0:3c869a8cb8f8 43 *
nguyenhoang9x5555 0:3c869a8cb8f8 44 * @param baudrate the baudrate in bps as an int. The default is 9600 bps.
nguyenhoang9x5555 0:3c869a8cb8f8 45 */
nguyenhoang9x5555 0:3c869a8cb8f8 46 void baud(int baudrate);
nguyenhoang9x5555 0:3c869a8cb8f8 47
nguyenhoang9x5555 0:3c869a8cb8f8 48 /** This method sets the transmission format used by the serial port.
nguyenhoang9x5555 0:3c869a8cb8f8 49 *
nguyenhoang9x5555 0:3c869a8cb8f8 50 * @param bits the number of bits in a word (5-8; default = 8)
nguyenhoang9x5555 0:3c869a8cb8f8 51 * @param parity the parity used (SerialBase::None, SerialBase::Odd, SerialBase::Even,
nguyenhoang9x5555 0:3c869a8cb8f8 52 * SerialBase::Forced1, SerialBase::Forced0; default = SerialBase::None)
nguyenhoang9x5555 0:3c869a8cb8f8 53 * @param stop the number of stop bits (1 or 2; default = 1)
nguyenhoang9x5555 0:3c869a8cb8f8 54 */
nguyenhoang9x5555 0:3c869a8cb8f8 55 void format(int bits=8, SerialBase::Parity parity=mbed::SerialBase::None, int stop_bits=1);
nguyenhoang9x5555 0:3c869a8cb8f8 56
nguyenhoang9x5555 0:3c869a8cb8f8 57 /** Generate a break condition on the serial line
nguyenhoang9x5555 0:3c869a8cb8f8 58 */
nguyenhoang9x5555 0:3c869a8cb8f8 59 void sendBreak();
nguyenhoang9x5555 0:3c869a8cb8f8 60
nguyenhoang9x5555 0:3c869a8cb8f8 61 /** Check for escape sequence detected on serial input
nguyenhoang9x5555 0:3c869a8cb8f8 62 * @return true if escape sequence was seen
nguyenhoang9x5555 0:3c869a8cb8f8 63 */
nguyenhoang9x5555 0:3c869a8cb8f8 64 bool escaped();
nguyenhoang9x5555 0:3c869a8cb8f8 65
nguyenhoang9x5555 0:3c869a8cb8f8 66 void escapeChar(char esc);
nguyenhoang9x5555 0:3c869a8cb8f8 67
nguyenhoang9x5555 0:3c869a8cb8f8 68 char escapeChar();
nguyenhoang9x5555 0:3c869a8cb8f8 69
nguyenhoang9x5555 0:3c869a8cb8f8 70 void clearEscaped();
nguyenhoang9x5555 0:3c869a8cb8f8 71
nguyenhoang9x5555 0:3c869a8cb8f8 72
nguyenhoang9x5555 0:3c869a8cb8f8 73 protected:
nguyenhoang9x5555 0:3c869a8cb8f8 74
nguyenhoang9x5555 0:3c869a8cb8f8 75 RawSerial* _serial; // Internal mbed Serial object
nguyenhoang9x5555 0:3c869a8cb8f8 76 int _baudrate;
nguyenhoang9x5555 0:3c869a8cb8f8 77 int _bits;
nguyenhoang9x5555 0:3c869a8cb8f8 78 SerialBase::Parity _parity;
nguyenhoang9x5555 0:3c869a8cb8f8 79 int _stop_bits;
nguyenhoang9x5555 0:3c869a8cb8f8 80 Timer timer;
nguyenhoang9x5555 0:3c869a8cb8f8 81 int _last_time;
nguyenhoang9x5555 0:3c869a8cb8f8 82 int _esc_cnt;
nguyenhoang9x5555 0:3c869a8cb8f8 83 char _esc_ch;
nguyenhoang9x5555 0:3c869a8cb8f8 84 bool _escaped;
nguyenhoang9x5555 0:3c869a8cb8f8 85
nguyenhoang9x5555 0:3c869a8cb8f8 86 virtual void handleWrite(); // Method for handling data to be written
nguyenhoang9x5555 0:3c869a8cb8f8 87 virtual void handleRead(); // Method for handling data to be read
nguyenhoang9x5555 0:3c869a8cb8f8 88
nguyenhoang9x5555 0:3c869a8cb8f8 89
nguyenhoang9x5555 0:3c869a8cb8f8 90 };
nguyenhoang9x5555 0:3c869a8cb8f8 91
nguyenhoang9x5555 0:3c869a8cb8f8 92 }
nguyenhoang9x5555 0:3c869a8cb8f8 93
nguyenhoang9x5555 0:3c869a8cb8f8 94 #endif /* ATSERIAL_H */