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