AT command firmware for MultiTech Dot devices.
Fork of mDot_AT_firmware by
Dot Library Not Included!
Because these example programs can be used for both mDot and xDot devices, the LoRa stack is not included. The libmDot library should be imported if building for mDot devices. The libxDot library should be imported if building for xDot devices. The AT firmware was last tested with mbed-os-5.4.7. Using a version past mbed-os-5.4.7 will cause the build to fail. The library used with the AT firmware has to match the mbed-os version.
Dot Library Version 3 Updates
Dot Library versions 3.x.x require a channel plan to be injected into the stack. The Dot-Examples and Dot-AT-Firmware do this by defining a macro called "CHANNEL_PLAN" that controls the channel plan that will be used in the examples. Available channel plans will be in the Dot Library repository in the plans folder.
Revision 20 and earlier of Dot-Examples and revision 15 and earlier of Dot-AT-Firmware should be used with Dot Library versions prior to 3.0.0.
Fota Library
Th Fota Library must be added to compile for mDot 3.1.0 with Fota support. Latest dev libraries and 3.2.0 release will include Fota with libmDot/libxDot.
AT Firmware Description
This AT Firmware is what ships on mDot and xDot devices. It provides an AT command interface for using the mDot or xDot for LoRa communication.
AT command documentation can be found on Multitech.com.
The firmware changelog can be found here.
The library changelog can be found here.
Dot Libraries
Dot Library Limitations
The commit messages in libmDot-mbed5 and libmDot-dev-mbed5 specify the version of the Dot library the commit contains and the version of mbed-os it was compiled against. We recommend building your application with the version of mbed-os specified in the commit message of the version of the Dot library you're using. This will ensure that you don't run into any runtime issues caused by differences in the mbed-os versions.
Stable and development libraries are available for both mDot and xDot platforms. The library chosen must match the target platform. Compiling for the mDot platform with the xDot library or vice versa will not succeed.
mDot Library
Development library for mDot.
Stable library for mDot.
xDot Library
Development library for xDot.
Stable library for xDot.
ATSerial.h@42:23e2df6714f4, 5 months ago (annotated)
- Committer:
- Jason Reiss
- Date:
- Wed Dec 06 13:33:52 2023 -0600
- Revision:
- 42:23e2df6714f4
- Parent:
- 36:b586cd6e91f3
TestMode: reset appnonce to 0 on reset to accomodate LCTT 3.12.0 and earlier. If the test suite changes to test AppNonce loaded from NVM this will fail tests.
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 | |
Jason Reiss |
28:c222ca8383f4 | 4 | #include "mbed.h" |
Mike Fiore |
9:ff62b20f7000 | 5 | |
Jason Reiss |
36:b586cd6e91f3 | 6 | #define AT_SERIAL_RX_BUFFER_SIZE 512 |
Jason Reiss |
36:b586cd6e91f3 | 7 | #define AT_SERIAL_TX_BUFFER_SIZE 256 |
Jason Reiss |
36:b586cd6e91f3 | 8 | |
Jason Reiss |
36:b586cd6e91f3 | 9 | #define AT_SERIAL_DEFAULT_BAUD_RATE 115200 |
Jason Reiss |
36:b586cd6e91f3 | 10 | |
Mike Fiore |
9:ff62b20f7000 | 11 | namespace mts |
Mike Fiore |
9:ff62b20f7000 | 12 | { |
Mike Fiore |
9:ff62b20f7000 | 13 | |
Jason Reiss |
36:b586cd6e91f3 | 14 | /** This class provides a buffered wrapper to the mbed::UnbufferedSerial |
Jason Reiss |
28:c222ca8383f4 | 15 | * class. Looks for an escape sequence within received byte stream. |
Jason Reiss |
28:c222ca8383f4 | 16 | */ |
Jason Reiss |
28:c222ca8383f4 | 17 | class ATSerial : private mbed::NonCopyable<ATSerial> |
Mike Fiore |
9:ff62b20f7000 | 18 | { |
Mike Fiore |
9:ff62b20f7000 | 19 | public: |
Mike Fiore |
9:ff62b20f7000 | 20 | /** Creates a new ATSerial object that can be used to talk to an mbed serial port |
Jason Reiss |
28:c222ca8383f4 | 21 | * through internal SW buffers. Providing RTS and CTS will enable flow control. |
Mike Fiore |
9:ff62b20f7000 | 22 | * |
Jason Reiss |
28:c222ca8383f4 | 23 | * @param txd the transmit data pin on the desired mbed Serial interface. |
Jason Reiss |
28:c222ca8383f4 | 24 | * @param rxd the receive data pin on the desired mbed Serial interface. |
Jason Reiss |
28:c222ca8383f4 | 25 | * @param rts the request-to-send pin on the desired mbed Serial interface. |
Jason Reiss |
28:c222ca8383f4 | 26 | * @param cts the clear-to-send pin on the desired mbed Serial interface. |
Jason Reiss |
28:c222ca8383f4 | 27 | * @param baud The initial baudrate |
Mike Fiore |
9:ff62b20f7000 | 28 | */ |
Jason Reiss |
28:c222ca8383f4 | 29 | ATSerial(PinName txd, PinName rxd, PinName rts = NC, PinName cts = NC, |
Jason Reiss |
36:b586cd6e91f3 | 30 | int baud = AT_SERIAL_DEFAULT_BAUD_RATE); |
Mike Fiore |
9:ff62b20f7000 | 31 | |
Mike Fiore |
9:ff62b20f7000 | 32 | /** Destructs an ATSerial object and frees all related resources, including |
Mike Fiore |
9:ff62b20f7000 | 33 | * internal buffers. |
Mike Fiore |
9:ff62b20f7000 | 34 | */ |
Mike Fiore |
9:ff62b20f7000 | 35 | virtual ~ATSerial(); |
Mike Fiore |
9:ff62b20f7000 | 36 | |
Mike Fiore |
9:ff62b20f7000 | 37 | /** This method is used to the set the baud rate of the serial port. |
Mike Fiore |
9:ff62b20f7000 | 38 | * |
Mike Fiore |
9:ff62b20f7000 | 39 | * @param baudrate the baudrate in bps as an int. The default is 9600 bps. |
Mike Fiore |
9:ff62b20f7000 | 40 | */ |
Mike Fiore |
9:ff62b20f7000 | 41 | void baud(int baudrate); |
Mike Fiore |
9:ff62b20f7000 | 42 | |
Mike Fiore |
9:ff62b20f7000 | 43 | /** This method sets the transmission format used by the serial port. |
Mike Fiore |
9:ff62b20f7000 | 44 | * |
Mike Fiore |
9:ff62b20f7000 | 45 | * @param bits the number of bits in a word (5-8; default = 8) |
Mike Fiore |
9:ff62b20f7000 | 46 | * @param parity the parity used (SerialBase::None, SerialBase::Odd, SerialBase::Even, |
Mike Fiore |
9:ff62b20f7000 | 47 | * SerialBase::Forced1, SerialBase::Forced0; default = SerialBase::None) |
Mike Fiore |
9:ff62b20f7000 | 48 | * @param stop the number of stop bits (1 or 2; default = 1) |
Mike Fiore |
9:ff62b20f7000 | 49 | */ |
Jason Reiss |
28:c222ca8383f4 | 50 | void format(int bits=8, mbed::SerialBase::Parity parity=mbed::SerialBase::None, int stop_bits=1); |
Jason Reiss |
28:c222ca8383f4 | 51 | |
Jason Reiss |
36:b586cd6e91f3 | 52 | void flowControl(bool enable); |
Jason Reiss |
36:b586cd6e91f3 | 53 | |
Jason Reiss |
36:b586cd6e91f3 | 54 | bool flowControl(); |
Jason Reiss |
36:b586cd6e91f3 | 55 | |
Jason Reiss |
28:c222ca8383f4 | 56 | /** Check if bytes are available to read. |
Jason Reiss |
28:c222ca8383f4 | 57 | * @return True if receive buffer is not empty. |
Jason Reiss |
28:c222ca8383f4 | 58 | */ |
Jason Reiss |
28:c222ca8383f4 | 59 | bool readable(); |
Mike Fiore |
9:ff62b20f7000 | 60 | |
Jason Reiss |
28:c222ca8383f4 | 61 | /** Check if bytes can be written. |
Jason Reiss |
28:c222ca8383f4 | 62 | * @return True if transmit buffer is not full. |
Mike Fiore |
9:ff62b20f7000 | 63 | */ |
Jason Reiss |
28:c222ca8383f4 | 64 | bool writeable(); |
Jason Reiss |
28:c222ca8383f4 | 65 | |
Jason Reiss |
28:c222ca8383f4 | 66 | /** Clear the receive buffer. */ |
Jason Reiss |
28:c222ca8383f4 | 67 | void rxClear(); |
Jason Reiss |
28:c222ca8383f4 | 68 | |
Jason Reiss |
28:c222ca8383f4 | 69 | /** Clear the transmist buffer. */ |
Jason Reiss |
28:c222ca8383f4 | 70 | void txClear(); |
Mike Fiore |
9:ff62b20f7000 | 71 | |
Mike Fiore |
9:ff62b20f7000 | 72 | /** Check for escape sequence detected on serial input |
Jason Reiss |
28:c222ca8383f4 | 73 | * @return true if escape sequence was seen |
Mike Fiore |
9:ff62b20f7000 | 74 | */ |
Mike Fiore |
9:ff62b20f7000 | 75 | bool escaped(); |
Mike Fiore |
9:ff62b20f7000 | 76 | |
Jason Reiss |
28:c222ca8383f4 | 77 | /** Set escape character. */ |
Mike Fiore |
9:ff62b20f7000 | 78 | void escapeChar(char esc); |
Mike Fiore |
9:ff62b20f7000 | 79 | |
Jason Reiss |
28:c222ca8383f4 | 80 | /** Get the escape character. */ |
Mike Fiore |
9:ff62b20f7000 | 81 | char escapeChar(); |
Mike Fiore |
9:ff62b20f7000 | 82 | |
Jason Reiss |
28:c222ca8383f4 | 83 | /** Clear escaped state. */ |
Mike Fiore |
9:ff62b20f7000 | 84 | void clearEscaped(); |
Mike Fiore |
9:ff62b20f7000 | 85 | |
Jason Reiss |
28:c222ca8383f4 | 86 | /** Read a byte from receive buffer |
Jason Reiss |
36:b586cd6e91f3 | 87 | * @param[out] c Storage for read character |
Jason Reiss |
28:c222ca8383f4 | 88 | * @return True if a character was read |
Jason Reiss |
28:c222ca8383f4 | 89 | */ |
Jason Reiss |
28:c222ca8383f4 | 90 | bool read(char& c); |
Jason Reiss |
28:c222ca8383f4 | 91 | |
Jason Reiss |
28:c222ca8383f4 | 92 | /** Read bytes from the receive buffer. |
Jason Reiss |
28:c222ca8383f4 | 93 | * @param[out] buffer Allocated memory to store read bytes |
Jason Reiss |
28:c222ca8383f4 | 94 | * @param length Size of buffer in bytes |
Jason Reiss |
28:c222ca8383f4 | 95 | * @return Number of bytes read |
Jason Reiss |
27:5fafd3b26ac3 | 96 | */ |
Jason Reiss |
28:c222ca8383f4 | 97 | int read(char *buffer, size_t length); |
Jason Reiss |
28:c222ca8383f4 | 98 | |
Jason Reiss |
28:c222ca8383f4 | 99 | /** Write bytes from to transmit buffer. |
Jason Reiss |
28:c222ca8383f4 | 100 | * @param buffer Bytes to write |
Jason Reiss |
28:c222ca8383f4 | 101 | * @param length Size of buffer in bytes |
Jason Reiss |
28:c222ca8383f4 | 102 | * @return Number of bytes written |
Jason Reiss |
28:c222ca8383f4 | 103 | */ |
Jason Reiss |
28:c222ca8383f4 | 104 | int write(const char *buffer, size_t length); |
Jason Reiss |
28:c222ca8383f4 | 105 | |
Jason Reiss |
28:c222ca8383f4 | 106 | /** Write formatted string to transmit buffer. |
Jason Reiss |
28:c222ca8383f4 | 107 | * @param format Format string |
Jason Reiss |
28:c222ca8383f4 | 108 | * @param ... Items to format |
Jason Reiss |
28:c222ca8383f4 | 109 | * @return Number of bytes written |
Jason Reiss |
28:c222ca8383f4 | 110 | */ |
Jason Reiss |
28:c222ca8383f4 | 111 | int writef(const char* format, ... ); |
Mike Fiore |
9:ff62b20f7000 | 112 | |
Mike Fiore |
9:ff62b20f7000 | 113 | protected: |
Jason Reiss |
28:c222ca8383f4 | 114 | mbed::UnbufferedSerial _serial; // Using unbuffered serial so reads can be done in event handler |
Mike Fiore |
9:ff62b20f7000 | 115 | |
Jason Reiss |
28:c222ca8383f4 | 116 | // Receive buffer |
Jason Reiss |
36:b586cd6e91f3 | 117 | mbed::CircularBuffer<char, AT_SERIAL_RX_BUFFER_SIZE>* _rxbuf; |
Jason Reiss |
28:c222ca8383f4 | 118 | // Transmit buffer |
Jason Reiss |
36:b586cd6e91f3 | 119 | mbed::CircularBuffer<char, AT_SERIAL_TX_BUFFER_SIZE>* _txbuf; |
Jason Reiss |
36:b586cd6e91f3 | 120 | |
Jason Reiss |
28:c222ca8383f4 | 121 | bool _tx_irq_enabled; // Flag indicating transmit IRQ is enabled |
Mike Fiore |
9:ff62b20f7000 | 122 | |
Jason Reiss |
28:c222ca8383f4 | 123 | Timer _timer; // Inter-byte receive timer |
Jason Reiss |
28:c222ca8383f4 | 124 | std::chrono::milliseconds _last_time; // Last time a byte was received |
Jason Reiss |
28:c222ca8383f4 | 125 | int _esc_cnt; // Number of escape characters received |
Jason Reiss |
28:c222ca8383f4 | 126 | char _esc_ch; // Escape character |
Jason Reiss |
28:c222ca8383f4 | 127 | bool _escaped; // True if escape sequence has been received |
Jason Reiss |
28:c222ca8383f4 | 128 | void handleRead(); // Method for handling data to be read |
Jason Reiss |
28:c222ca8383f4 | 129 | void handleWrite(); // Method for handling data writes |
Jason Reiss |
28:c222ca8383f4 | 130 | void startWrite(); // Method for starting data writes |
Jason Reiss |
28:c222ca8383f4 | 131 | PlatformMutex _mutex; // Lock for API accesses |
Jason Reiss |
28:c222ca8383f4 | 132 | bool _flow; // Flag indicates flow control is enabled |
Jason Reiss |
28:c222ca8383f4 | 133 | DigitalOut _rts; // Request to send signal |
Jason Reiss |
28:c222ca8383f4 | 134 | InterruptIn _cts; // Clear to send signal |
Jason Reiss |
28:c222ca8383f4 | 135 | size_t _hwm; // RX buffer high water mark for setting RTS to stop |
Jason Reiss |
28:c222ca8383f4 | 136 | size_t _lwm; // RX buffer low water mark for setting RTS to start |
Mike Fiore |
9:ff62b20f7000 | 137 | }; |
Mike Fiore |
9:ff62b20f7000 | 138 | |
Mike Fiore |
9:ff62b20f7000 | 139 | } |
Mike Fiore |
9:ff62b20f7000 | 140 | |
Mike Fiore |
9:ff62b20f7000 | 141 | #endif /* ATSERIAL_H */ |