MultiTech / Mbed OS Dot-AT-Firmware

Fork of mDot_AT_firmware by MultiTech

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. Check the commit messages of the Dot library version used to find the correct mbed-os version to use with it. The mbed-os version must match the version used in that version of Dot library or it will likely cause it to fail to compile or have unexpected problems while running.

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.

libmDot-dev

Stable library for mDot.

libmDot

xDot Library

Development library for xDot.

libxDot-dev

Stable library for xDot.

libxDot

Revision:
36:b586cd6e91f3
Parent:
28:c222ca8383f4
--- a/ATSerial.cpp	Fri Aug 12 11:08:59 2022 -0500
+++ b/ATSerial.cpp	Fri Sep 08 08:34:24 2023 -0500
@@ -17,13 +17,20 @@
     _rts(rts),
     _cts(cts)
 {
+
     if (rts != NC && cts != NC) {   // RTS and CTS must both be provided for flow control
         _flow = true;
         _rts = 0;   // Start with receive enabled
         _cts.fall(callback(this, &ATSerial::startWrite));   // Restart writes when able to send
-        _hwm = mts_max(MBED_CONF_DRIVERS_UART_SERIAL_RXBUF_SIZE - 10, MBED_CONF_DRIVERS_UART_SERIAL_RXBUF_SIZE * 0.85);
-        _lwm = MBED_CONF_DRIVERS_UART_SERIAL_RXBUF_SIZE * 0.3;
+        _hwm = mts_max(AT_SERIAL_RX_BUFFER_SIZE - 10, AT_SERIAL_RX_BUFFER_SIZE * 0.85);
+        _lwm = AT_SERIAL_RX_BUFFER_SIZE * 0.3;
     }
+
+    // Receive buffer
+    _rxbuf = new mbed::CircularBuffer<char, AT_SERIAL_RX_BUFFER_SIZE>();
+    // Transmit buffer
+    _txbuf = new mbed::CircularBuffer<char, AT_SERIAL_TX_BUFFER_SIZE>();
+
     _timer.start();
     _serial.attach(callback(this, &ATSerial::handleRead), SerialBase::RxIrq);
 }
@@ -43,18 +50,35 @@
     _serial.format(bits, parity, stop_bits);
     _mutex.unlock();
 }
- 
+
+void ATSerial::flowControl(bool enable) {
+    if (enable && (_rts != NC) && (_cts != NC)) {   // RTS and CTS must both be provided for flow control
+        _flow = true;
+        _rts = 0;   // Start with receive enabled
+        _cts.fall(callback(this, &ATSerial::startWrite));   // Restart writes when able to send
+        _hwm = mts_max(MBED_CONF_DRIVERS_UART_SERIAL_RXBUF_SIZE - 10, MBED_CONF_DRIVERS_UART_SERIAL_RXBUF_SIZE * 0.85);
+        _lwm = MBED_CONF_DRIVERS_UART_SERIAL_RXBUF_SIZE * 0.3;
+    } else {
+        _flow = false;
+        _rts = 1;
+    }
+}
+
+bool ATSerial::flowControl() {
+    return _flow;
+}
+
 bool ATSerial::readable() {
-    return !_rxbuf.empty();
+    return !_rxbuf->empty();
 }
 
 bool ATSerial::writeable() {
-    return !_txbuf.full();
+    return !_txbuf->full();
 }
 
 void ATSerial::rxClear() {
     _mutex.lock();
-    _rxbuf.reset();
+    _rxbuf->reset();
     if (_flow) {
         _rts = 0;   // Allow receiving because receive buffer is now empty
     }
@@ -63,7 +87,7 @@
 
 void ATSerial::txClear() {
     _mutex.lock();
-    _txbuf.reset();
+    _txbuf->reset();
     _mutex.unlock();
 }
 
@@ -80,7 +104,7 @@
     } else if (_esc_cnt > 0 && _esc_cnt != 3 && elapsed_ms > 500ms) {
         // Write seen esc chars
         while (_esc_cnt) {
-            _rxbuf.push(_esc_ch);
+            _rxbuf->push(_esc_ch);
             _esc_cnt--;
         }
         _escaped = false;
@@ -105,16 +129,16 @@
     _mutex.lock();
     size_t i = 0;
     while (i < length) {
-        if (_txbuf.full()) {
+        if (_txbuf->full()) {
             do {
                 _mutex.unlock();
                 thread_sleep_for(1);
                 _mutex.lock();
-            } while (_txbuf.full());
+            } while (_txbuf->full());
         }
-        while (i < length && !_txbuf.full())
+        while (i < length && !_txbuf->full())
         {
-            _txbuf.push(buffer[i]);
+            _txbuf->push(buffer[i]);
             i++;
         }
         startWrite();   // Start writing data in tx buffer
@@ -122,7 +146,7 @@
     _mutex.unlock();
     return i;
 }
-    
+
 int ATSerial::writef(const char* format, ... ) {
     char buff[256];
 
@@ -139,13 +163,13 @@
     _mutex.lock();
     size_t r = 0;
     while (r < length) {
-        if (_rxbuf.pop(buffer[r])) {
+        if (_rxbuf->pop(buffer[r])) {
             r++;
         } else {
             break;
         }
     }
-    if (_flow && _rts && _rxbuf.size() <= _lwm) {
+    if (_flow && _rts && _rxbuf->size() <= _lwm) {
         _rts = 0;   // RX buffer has room, clear RTS to continue receiving
     }
     _mutex.unlock();
@@ -158,7 +182,7 @@
     if (!_tx_irq_enabled) {
         // only write to hardware in one place
         handleWrite();
-        if (!_txbuf.empty()) {
+        if (!_txbuf->empty()) {
             _serial.attach(callback(this, &ATSerial::handleWrite), SerialBase::TxIrq);
             _tx_irq_enabled = true;
         }
@@ -167,14 +191,14 @@
 }
 
 void ATSerial::handleWrite()
-{ 
+{
     char c;
     while (_serial.writeable()) {
         if (_flow && _cts) {
             break;  // Exit write loop when CTS is set, will resume when it is cleared
         }
 
-        if (_txbuf.pop(c)) {
+        if (_txbuf->pop(c)) {
             _serial.write(&c, 1);
         } else {
             break;
@@ -182,7 +206,7 @@
     }
 
     // Detach TX IRQ if there's no more data to write or CTS is set
-    if (_tx_irq_enabled && (_txbuf.empty() || (_flow && _cts))) {
+    if (_tx_irq_enabled && (_txbuf->empty() || (_flow && _cts))) {
         _serial.attach(NULL, SerialBase::TxIrq);
         _tx_irq_enabled = false;
     }
@@ -197,12 +221,12 @@
     std::chrono::milliseconds now = std::chrono::duration_cast<std::chrono::milliseconds>(_timer.elapsed_time());
     std::chrono::milliseconds elapsed_ms = now - _last_time;
     _last_time = now;
-    
+
     // Have we seen 3 esc chars but this char is before 1 sec end guard time
     if (_esc_cnt == 3 && (elapsed_ms < std::chrono::seconds(1))) {
         // Write the three chars we held back
         while (_esc_cnt) {
-            _rxbuf.push(_esc_ch);
+            _rxbuf->push(_esc_ch);
             _esc_cnt--;
         }
     } else if (byte == _esc_ch) {
@@ -216,21 +240,21 @@
     } else if (_esc_cnt > 0) {
         // Write any esc chars held back
         while (_esc_cnt) {
-            _rxbuf.push(_esc_ch);
+            _rxbuf->push(_esc_ch);
             _esc_cnt--;
         }
     }
 
     if(_esc_cnt == 0) {
-        if (_flow && !_rts && _rxbuf.size() >= _hwm) {
+        if (_flow && !_rts && _rxbuf->size() >= _hwm) {
             _rts = 1;   // RX buffer too full, set RTS to stop receiving
                         // Data will still be received until the buffer is full
         }
 
-        if (_rxbuf.full()) {
+        if (_rxbuf->full()) {
             // Overflow, drop byte
         } else {
-            _rxbuf.push(byte);
+            _rxbuf->push(byte);
         }
     }