AT command firmware for MultiTech Dot devices.

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. 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.

libmDot-dev

Stable library for mDot.

libmDot

xDot Library

Development library for xDot.

libxDot-dev

Stable library for xDot.

libxDot

Revision:
36:b586cd6e91f3
Parent:
34:3b696c2b1e4b
Child:
42:23e2df6714f4
--- a/CommandTerminal/CommandTerminal.cpp	Fri Aug 12 11:08:59 2022 -0500
+++ b/CommandTerminal/CommandTerminal.cpp	Fri Sep 08 08:34:24 2023 -0500
@@ -7,17 +7,20 @@
 #include <cstdarg>
 #include <deque>
 #include "mts_at_version.h"
+#include "LowPower.h"
 
 #if defined(TARGET_XDOT_L151CC)
 #include "xdot_low_power.h"
 #endif
 
-#if defined(TARGET_MTS_MDOT_F411RE)
-const char CommandTerminal::banner[] = "\r\n\nMultiTech Systems LoRa XBee Module\r\n\n";
-#else
-const char CommandTerminal::banner[] = "\r\n\nMultiTech Systems LoRa xDot Module\r\n\n";
+#if defined(TARGET_MTS_MDOT_F411RE) || defined(TARGET_XDOT_MAX32670)
+#define MTS_DOT_COMMAND_HISTORY_FEATURE 1
 #endif
-const char CommandTerminal::helpline[] = "Enter '?' for help\r\n";
+
+#if !defined(TARGET_XDOT_L151CC) || defined(MTS_RADIO_DEBUG_COMMANDS) || defined(MTS_CERT_TEST_MODE)
+#define MTS_DOT_ENABLE_LORAWAN_TESTMODE 1
+#endif
+
 
 const char CommandTerminal::newline[] = "\r\n";
 
@@ -54,11 +57,55 @@
 static uint32_t _rxFcnt = 0;
 
 #if defined(TARGET_MTS_MDOT_F411RE)
-DigitalOut _packet_rx_pin(D12);
-DigitalOut _join_status_pin(A2);
+#define PIN_PACKET_RX       D12
+#define PIN_JOIN_STATUS     A2
+#define PIN_ON_SLEEP        XBEE_ON_SLEEP
+#elif defined(TARGET_XDOT_L151CC)
+#define PIN_PACKET_RX       GPIO1
+#define PIN_JOIN_STATUS     GPIO0
+#define PIN_ON_SLEEP        GPIO2
+#elif defined(TARGET_MAX32630FTHR)
+#define PIN_PACKET_RX       LED_RED
+#define PIN_JOIN_STATUS     LED3
+#define PIN_ON_SLEEP        P5_5
+#elif defined(TARGET_XDOT_MAX32670) || defined(TARGET_XDOTES_MAX32670)
+#define PIN_PACKET_RX       GPIO1
+#define PIN_JOIN_STATUS     GPIO0
+#define PIN_ON_SLEEP        GPIO2
+#elif defined(TARGET_MAX32660EVSYS) || defined(TARGET_MAX32660EVSYS)
+// NO-OP: no pins to define, will default to NC
 #else
-DigitalOut _packet_rx_pin(GPIO1);
-DigitalOut _join_status_pin(GPIO0);
+#error Unsupported target
+#endif
+
+#ifndef GPIO_PIN_SET
+#define GPIO_PIN_SET 1
+#endif
+
+#ifndef GPIO_PIN_RESET
+#define GPIO_PIN_RESET 0
+#endif
+
+
+#if defined(PIN_PACKET_RX)
+DigitalOut _packet_rx_pin(PIN_PACKET_RX);
+#define USE_PIN_PACKET_RX 1
+#else
+#define PIN_PACKET_RX      NC
+#endif
+
+#if defined(PIN_JOIN_STATUS)
+DigitalOut _join_status_pin(PIN_JOIN_STATUS);
+#define USE_PIN_JOIN_STATUS 1
+#else
+#define PIN_JOIN_STATUS     NC
+#endif
+
+#if defined(PIN_ON_SLEEP)
+DigitalOut _xbee_on_sleep(PIN_ON_SLEEP);
+#define USE_PIN_ON_SLEEP 1
+#else
+#define PIN_ON_SLEEP        NC
 #endif
 
 void CommandTerminal::setErrorMessage(const char* message) {
@@ -73,11 +120,6 @@
   _serial(serial),
   _mode(mDot::COMMAND_MODE),
   _sleep_standby(true),
-#if defined(TARGET_MTS_MDOT_F411RE)
-  _xbee_on_sleep(XBEE_ON_SLEEP),
-#else
-  _xbee_on_sleep(GPIO2),
-#endif
   _autoOTAEnabled(false)
 {
     _serialp = &serial;
@@ -220,8 +262,9 @@
     serial_read_timer.start();
 
     if (_dot->getStartUpMode() == mDot::SERIAL_MODE) {
+#if defined(USE_PIN_ON_SLEEP)
         _xbee_on_sleep = GPIO_PIN_SET;
-
+#endif
         timeout = std::chrono::milliseconds(_dot->getWakeDelay());
         elapsed_time_ms = std::chrono::duration_cast<std::chrono::milliseconds>(serial_read_timer.elapsed_time());
 
@@ -266,7 +309,9 @@
 
         if (!serial_buffer.empty()) {
             if (_dot->getStartUpMode() == mDot::SERIAL_MODE)
+#if defined(USE_PIN_ON_SLEEP)
                  _xbee_on_sleep = GPIO_PIN_RESET;
+#endif
 
 L_SEND:
             // wait for any duty cycle limit to expire
@@ -404,7 +449,7 @@
         }
 
         tmr.reset();
-        while (tmr.read_ms() < sleep && !_serial.escaped()) {
+        while (std::chrono::duration_cast<std::chrono::milliseconds>(tmr.elapsed_time()).count() < sleep && !_serial.escaped()) {
             osDelay(10);
         }
 
@@ -460,7 +505,7 @@
     bool running = true;
     bool echo = _dot->getEcho();
     std::string command;
-#if defined(TARGET_MTS_MDOT_F411RE)
+#if defined(MTS_DOT_COMMAND_HISTORY_FEATURE)
     std::deque<std::string> history;
     int history_index = -1;
 #endif
@@ -489,7 +534,7 @@
             tmr.start();
             escape_tmr.reset();
             escape_tmr.start();
-            while (tmr.read_ms() < escape_timeout) {
+            while (std::chrono::duration_cast<std::chrono::milliseconds>(tmr.elapsed_time()).count() < escape_timeout) {
                 if (_serial.readable()) {
                     _serial.read(&ch, 1);
                     escape_buffer += ch;
@@ -505,7 +550,7 @@
                     break;
                 }
 
-                if (escape_tmr.read_ms() > escape_timeout)
+                if (std::chrono::duration_cast<std::chrono::milliseconds>(escape_tmr.elapsed_time()).count() > escape_timeout)
                     escape_buffer.clear();
 
                 osDelay(1);
@@ -522,6 +567,7 @@
                 _mode = mDot::COMMAND_MODE;
 
                 logWarning("Start Up Mode set to SERIAL_MODE, but join failed.");
+                logWarning("Join Backoff until next join %lu ms", _dot->getNextTxMs());
                 _serial.writef("Network Not Joined\r\n");
                 _serial.writef(error);
             }
@@ -613,6 +659,8 @@
                 continue;
             } else if (ch == 0x1b || ch == 0x09) {
                 osDelay(20);
+
+#if defined(MTS_DOT_COMMAND_HISTORY_FEATURE)
                 // catch escape sequence, or tab
                 char ch1 = 0x00, ch2 = 0x00;
 
@@ -621,7 +669,6 @@
                     if (readable())
                         ch2 = read();
 
-#if defined(TARGET_MTS_MDOT_F411RE)
                     if (ch1 == 0x5b && ch2 == 0x41) {
                         // up key
                         for (size_t i = 0; i < command.size() + 1; i++) {
@@ -632,7 +679,14 @@
                                 history_index = history.size() - 1;
 
                             command = history[history_index];
-                            writef("%s", history[history_index].c_str());
+
+                            if (command.size() > 128) {
+                                for (size_t i = 0; i < command.size(); i++) {
+                                    writef("%c", command[i]);
+                                }
+                            } else {
+                                writef("%s", command.c_str());
+                            }
                         } else {
                             command.clear();
                         }
@@ -648,11 +702,18 @@
                             command.clear();
                         } else {
                             command = history[history_index];
-                            writef("%s", history[history_index].c_str());
+                            if (command.size() > 128) {
+                                for (size_t i = 0; i < command.size(); i++) {
+                                    writef("%c", command[i]);
+                                }
+
+                            } else {
+                                writef("%s", command.c_str());
+                            }
                         }
                     }
+                }
 #endif
-                }
                 while (readable())
                     read();
                 continue;
@@ -683,7 +744,9 @@
             continue;
         }
 
-        _packet_rx_pin = 0;
+#if defined(USE_PIN_PACKET_RX)
+        _packet_rx_pin = GPIO_PIN_RESET;
+#endif
         command_processing = true;
 
         // parse command and args
@@ -831,6 +894,7 @@
                                 write(done);
                             }
                             break;
+#if defined(TARGET_MTS_MDOT_F411RE) || defined(TARGET_XDOT_L151CC) || defined(TARGET_XDOT_MAX32670)
                         case CommandFactory::eATWP:
                             if (!_dot->saveProtectedConfig()) {
 #if MTS_CMD_TERM_VERBOSE
@@ -841,6 +905,7 @@
                                 write(done);
                             }
                             break;
+#endif
                         case CommandFactory::eSS:
                             _dot->saveNetworkSession();
                             write(done);
@@ -915,7 +980,8 @@
                             break;
                     }
                 }
-#ifdef MTS_RADIO_DEBUG_COMMANDS
+
+#if defined(MTS_DOT_ENABLE_LORAWAN_TESTMODE)
             } else if (args[0].find("AT+TM!") == 0 && args[0].length() == 6) {
                 handled = true;
                 if ((args.size() > 1) && (args[1].length() == 1)) {
@@ -1013,12 +1079,13 @@
             }
         }
 
-
+#if defined(USE_PIN_JOIN_STATUS)
         _join_status_pin = CommandTerminal::Dot()->getNetworkJoinStatus();
+#endif
         command_processing = false;
 
 
-#if defined(TARGET_MTS_MDOT_F411RE)
+#if defined(MTS_DOT_COMMAND_HISTORY_FEATURE)
         if (history.size() == 0 || history.front() != command)
             history.push_front(command);
         history_index = -1;
@@ -1033,257 +1100,18 @@
 }
 
 void CommandTerminal::sleep(bool standby) {
+#if defined(USE_PIN_ON_SLEEP)
     _xbee_on_sleep = GPIO_PIN_RESET;
+#endif
+    _serial.rxClear();
+    _serial.txClear();
+
+    LowPower::configExtGpios(_dot->getWakeMode(), _dot->getWakePin());
+    _dot->sleep(_dot->getWakeInterval(), _dot->getWakeMode(), standby);
 
     _serial.rxClear();
     _serial.txClear();
 
-#if defined(TARGET_XDOT_L151CC)
-    xdot_save_gpio_state();
-
-    /* GPIO Ports Clock Enable */
-    __GPIOA_CLK_ENABLE();
-    __GPIOB_CLK_ENABLE();
-    __GPIOC_CLK_ENABLE();
-    __GPIOH_CLK_ENABLE();
-
-    GPIO_InitTypeDef GPIO_InitStruct;
-
-    // UART1_TX, UART1_RTS & UART1_CTS to analog nopull - RX could be a wakeup source
-    GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_11 | GPIO_PIN_12;
-    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
-    GPIO_InitStruct.Pull = GPIO_NOPULL;
-    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
-
-    // I2C_SDA & I2C_SCL to analog nopull
-    GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9;
-    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
-    GPIO_InitStruct.Pull = GPIO_NOPULL;
-    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-
-    // SPI_MOSI, SPI_MISO, SPI_SCK, & SPI_NSS to analog nopull
-    GPIO_InitStruct.Pin = GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
-    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
-    GPIO_InitStruct.Pull = GPIO_NOPULL;
-    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-
-    // iterate through potential wake pins - leave the configured wake pin alone if one is needed
-    if (_dot->getWakePin() != WAKE || _dot->getWakeMode() == mDot::RTC_ALARM) {
-        GPIO_InitStruct.Pin = GPIO_PIN_0;
-        GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
-        GPIO_InitStruct.Pull = GPIO_NOPULL;
-        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
-    }
-    if (_dot->getWakePin() != GPIO0 || _dot->getWakeMode() == mDot::RTC_ALARM) {
-        GPIO_InitStruct.Pin = GPIO_PIN_4;
-        GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
-        GPIO_InitStruct.Pull = GPIO_NOPULL;
-        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
-    }
-    if (_dot->getWakePin() != GPIO1 || _dot->getWakeMode() == mDot::RTC_ALARM) {
-        GPIO_InitStruct.Pin = GPIO_PIN_5;
-        GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
-        GPIO_InitStruct.Pull = GPIO_NOPULL;
-        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
-    }
-    if (_dot->getWakePin() != GPIO2 || _dot->getWakeMode() == mDot::RTC_ALARM) {
-        GPIO_InitStruct.Pin = GPIO_PIN_0;
-        GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
-        GPIO_InitStruct.Pull = GPIO_NOPULL;
-        HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-    }
-    if (_dot->getWakePin() != GPIO3 || _dot->getWakeMode() == mDot::RTC_ALARM) {
-        GPIO_InitStruct.Pin = GPIO_PIN_2;
-        GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
-        GPIO_InitStruct.Pull = GPIO_NOPULL;
-        HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-    }
-    if (_dot->getWakePin() != UART1_RX || _dot->getWakeMode() == mDot::RTC_ALARM) {
-        GPIO_InitStruct.Pin = GPIO_PIN_10;
-        GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
-        GPIO_InitStruct.Pull = GPIO_NOPULL;
-        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
-    }
-#else
-    uint32_t portA[6];
-    uint32_t portB[6];
-    uint32_t portC[6];
-    uint32_t portD[6];
-    uint32_t portH[6];
-
-    //Save the GPIO state.
-    portA[0] = GPIOA->MODER;
-    portA[1] = GPIOA->OTYPER;
-    portA[2] = GPIOA->OSPEEDR;
-    portA[3] = GPIOA->PUPDR;
-    portA[4] = GPIOA->AFR[0];
-    portA[5] = GPIOA->AFR[1];
-
-    portB[0] = GPIOB->MODER;
-    portB[1] = GPIOB->OTYPER;
-    portB[2] = GPIOB->OSPEEDR;
-    portB[3] = GPIOB->PUPDR;
-    portB[4] = GPIOB->AFR[0];
-    portB[5] = GPIOB->AFR[1];
-
-    portC[0] = GPIOC->MODER;
-    portC[1] = GPIOC->OTYPER;
-    portC[2] = GPIOC->OSPEEDR;
-    portC[3] = GPIOC->PUPDR;
-    portC[4] = GPIOC->AFR[0];
-    portC[5] = GPIOC->AFR[1];
-
-    portD[0] = GPIOD->MODER;
-    portD[1] = GPIOD->OTYPER;
-    portD[2] = GPIOD->OSPEEDR;
-    portD[3] = GPIOD->PUPDR;
-    portD[4] = GPIOD->AFR[0];
-    portD[5] = GPIOD->AFR[1];
-
-    portH[0] = GPIOH->MODER;
-    portH[1] = GPIOH->OTYPER;
-    portH[2] = GPIOH->OSPEEDR;
-    portH[3] = GPIOH->PUPDR;
-    portH[4] = GPIOH->AFR[0];
-    portH[5] = GPIOH->AFR[1];
-
-    /* GPIO Ports Clock Enable */
-    __GPIOA_CLK_ENABLE();
-    __GPIOB_CLK_ENABLE();
-    __GPIOC_CLK_ENABLE();
-
-    GPIO_InitTypeDef GPIO_InitStruct;
-
-    // Set port A pins to analog nopull
-    GPIO_InitStruct.Pin = GPIO_PIN_2 | GPIO_PIN_6 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10
-                | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
-    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
-    GPIO_InitStruct.Pull = GPIO_NOPULL;
-    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
-
-    // Set port B pins to analog nopull
-    GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_3 | GPIO_PIN_4;
-    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
-    GPIO_InitStruct.Pull = GPIO_NOPULL;
-    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-
-    // Set port C pins to analog nopull
-    GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_13;
-    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
-    GPIO_InitStruct.Pull = GPIO_NOPULL;
-    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
-
-    // iterate through potential wake pins - leave the configured wake pin alone if one is needed
-    // XBEE_DIN - PA3
-    // XBEE_DIO2 - PA5
-    // XBEE_DIO3 - PA4
-    // XBEE_DIO4 - PA7
-    // XBEE_DIO5 - PC1
-    // XBEE_DIO6 - PA1
-    // XBEE_DIO7 - PA0
-    // XBEE_SLEEPRQ - PA11
-
-    if (_dot->getWakePin() != XBEE_DIN || _dot->getWakeMode() == mDot::RTC_ALARM) {
-        GPIO_InitStruct.Pin = GPIO_PIN_3;
-        GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
-        GPIO_InitStruct.Pull = GPIO_NOPULL;
-        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
-    }
-
-    if (_dot->getWakePin() != XBEE_DIO2 || _dot->getWakeMode() == mDot::RTC_ALARM) {
-        GPIO_InitStruct.Pin = GPIO_PIN_5;
-        GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
-        GPIO_InitStruct.Pull = GPIO_NOPULL;
-        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
-    }
-
-    if (_dot->getWakePin() != XBEE_DIO3 || _dot->getWakeMode() == mDot::RTC_ALARM) {
-        GPIO_InitStruct.Pin = GPIO_PIN_4;
-        GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
-        GPIO_InitStruct.Pull = GPIO_NOPULL;
-        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
-    }
-
-         if (_dot->getWakePin() != XBEE_DIO4 || _dot->getWakeMode() == mDot::RTC_ALARM) {
-        GPIO_InitStruct.Pin = GPIO_PIN_7;
-        GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
-        GPIO_InitStruct.Pull = GPIO_NOPULL;
-        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
-    }
-
-     if (_dot->getWakePin() != XBEE_DIO5 || _dot->getWakeMode() == mDot::RTC_ALARM) {
-        GPIO_InitStruct.Pin = GPIO_PIN_1;
-        GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
-        GPIO_InitStruct.Pull = GPIO_NOPULL;
-        HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
-    }
-
-     if (_dot->getWakePin() != XBEE_DIO6 || _dot->getWakeMode() == mDot::RTC_ALARM) {
-        GPIO_InitStruct.Pin = GPIO_PIN_1;
-        GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
-        GPIO_InitStruct.Pull = GPIO_NOPULL;
-        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
-    }
-
-     if (_dot->getWakePin() != XBEE_DIO7 || _dot->getWakeMode() == mDot::RTC_ALARM) {
-        GPIO_InitStruct.Pin = GPIO_PIN_0;
-        GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
-        GPIO_InitStruct.Pull = GPIO_NOPULL;
-        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
-    }
-
-     if (_dot->getWakePin() != XBEE_SLEEPRQ|| _dot->getWakeMode() == mDot::RTC_ALARM) {
-        GPIO_InitStruct.Pin = GPIO_PIN_11;
-        GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
-        GPIO_InitStruct.Pull = GPIO_NOPULL;
-        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
-    }
-
-#endif
-    _dot->sleep(_dot->getWakeInterval(), _dot->getWakeMode(), standby);
-
-#if defined(TARGET_XDOT_L151CC)
-    xdot_restore_gpio_state();
-#else
-    //Restore the GPIO state.
-    GPIOA->MODER = portA[0];
-    GPIOA->OTYPER = portA[1];
-    GPIOA->OSPEEDR = portA[2];
-    GPIOA->PUPDR = portA[3];
-    GPIOA->AFR[0] = portA[4];
-    GPIOA->AFR[1] = portA[5];
-
-    GPIOB->MODER = portB[0];
-    GPIOB->OTYPER = portB[1];
-    GPIOB->OSPEEDR = portB[2];
-    GPIOB->PUPDR = portB[3];
-    GPIOB->AFR[0] = portB[4];
-    GPIOB->AFR[1] = portB[5];
-
-    GPIOC->MODER = portC[0];
-    GPIOC->OTYPER = portC[1];
-    GPIOC->OSPEEDR = portC[2];
-    GPIOC->PUPDR = portC[3];
-    GPIOC->AFR[0] = portC[4];
-    GPIOC->AFR[1] = portC[5];
-
-    GPIOD->MODER = portD[0];
-    GPIOD->OTYPER = portD[1];
-    GPIOD->OSPEEDR = portD[2];
-    GPIOD->PUPDR = portD[3];
-    GPIOD->AFR[0] = portD[4];
-    GPIOD->AFR[1] = portD[5];
-
-    GPIOH->MODER = portH[0];
-    GPIOH->OTYPER = portH[1];
-    GPIOH->OSPEEDR = portH[2];
-    GPIOH->PUPDR = portH[3];
-    GPIOH->AFR[0] = portH[4];
-    GPIOH->AFR[1] = portH[5];
-#endif
-
-    _serial.rxClear();
-    _serial.txClear();
     Fota::getInstance()->fixEventQueue();
 }
 
@@ -1310,7 +1138,7 @@
     Timer timer;
 
     timer.start();
-    while (timer.read_ms() < timeout) {
+    while (std::chrono::duration_cast<std::chrono::milliseconds>(timer.elapsed_time()).count() < timeout) {
 
         if (dot != NULL) {
             if (wait == WAIT_SEND && (!dot->getIsTransmitting())) {
@@ -1323,7 +1151,7 @@
             return true;
         }
 
-        osDelay(10);
+        ThisThread::sleep_for(10ms);
     }
 
     return false;
@@ -1339,7 +1167,9 @@
 
 void CommandTerminal::RadioEvent::RxTimeout(uint8_t slot) {
     mDotEvent::RxTimeout(slot);
-    _packet_rx_pin = 0;
+#if defined(USE_PIN_PACKET_RX)
+    _packet_rx_pin = GPIO_PIN_RESET;
+#endif
 }
 
 void CommandTerminal::RadioEvent::PacketRx(uint8_t port, uint8_t *payload, uint16_t size, int16_t rssi, int16_t snr, lora::DownlinkControl ctrl, uint8_t slot, uint8_t retries, uint32_t address, uint32_t fcnt, bool dupRx) {
@@ -1349,12 +1179,24 @@
 
     if(port == 200 || port == 201 || port == 202) {
         Fota::getInstance()->processCmd(payload, port, size);
+
         if (CommandTerminal::Dot()->getRxOutput() < mDot::EXTENDED) {
             return;
         }
     }
+#if defined(USE_PIN_PACKET_RX)
+    _packet_rx_pin = GPIO_PIN_SET;
+#endif
 
-    _packet_rx_pin = 1;
+    if (CommandTerminal::Dot()->getSettings()->Test.TestMode) {
+        if (AckReceived || (PacketReceived && (RxPort != 0 || RxPayloadSize == 0))) {
+            _testDownlinkCounter++;
+            logDebug("Incremented downlink cnt %d", _testDownlinkCounter);
+        } else {
+            logDebug("PacketRx did not increment cnt port: %d size: %d", RxPort, RxPayloadSize);
+            logDebug("PacketRx ACK: %d PKT: %d", AckReceived, PacketReceived);
+        }
+    }
 
     if (serial_data_mode && port != 0) {
         if (size > 0) {
@@ -1384,262 +1226,285 @@
 }
 
 void CommandTerminal::RadioEvent::handleTestModePacket() {
-#ifdef MTS_RADIO_DEBUG_COMMANDS
-    static uint32_t last_rx_seq = 0;
-    bool start_test = false;
+#if defined(MTS_DOT_ENABLE_LORAWAN_TESTMODE)
+    // static uint32_t last_rx_seq = 0;  // For Class B tests
+    // bool start_test = false;
 
     std::string packet = mts::Text::bin2hexString(RxPayload, RxPayloadSize);
 
-        CommandTerminal::Dot()->getSettings()->Test.TestMode = true;
+    CommandTerminal::Dot()->getSettings()->Test.TestMode = true;
+    CommandTerminal::Dot()->setDisableIncrementDR(true);
 
-        last_rx_seq = CommandTerminal::Dot()->getSettings()->Session.UplinkCounter;
+    // last_rx_seq = CommandTerminal::Dot()->getSettings()->Session.UplinkCounter; // for class b tests
 
-        uint16_t testDownlinkCounter = 0;
-        uint32_t txPeriod = 5000;
-        bool testConfirmed = false;
+    uint32_t txPeriod = 5000;
+    bool testConfirmed = false;
 
-        // init counter
-        std::vector<uint8_t> data;
-        uint8_t savedPort = CommandTerminal::Dot()->getAppPort();
-        uint8_t savedAcks = CommandTerminal::Dot()->getAck();
-        bool savedAdr = CommandTerminal::Dot()->getAdr();
+    std::string cls = "A";
+
+    CommandTerminal::Dot()->setAck(0);
+    CommandTerminal::Dot()->setAdr(true);
+    CommandTerminal::Dot()->setAppPort(224);
 
-        CommandTerminal::Dot()->setAck(0);
-        CommandTerminal::Dot()->setAdr(true);
-        CommandTerminal::Dot()->setAppPort(224);
-
-        Timer sentTimer;
-        sentTimer.start();
-        while (CommandTerminal::Dot()->getSettings()->Test.TestMode) {
+    Timer sentTimer;
+    sentTimer.start();
+    while (CommandTerminal::Dot()->getSettings()->Test.TestMode) {
 TEST_START:
-            // if (waitingForBeacon && BeaconLocked) {
-            //     logInfo("send BeaconRxStatusInd");
-            //     data.clear();
-            //     data.push_back(0x40);
-            //     for (size_t i = 0; i < sizeof(BeaconData); ++i) {
-            //         data.push_back(((uint8_t*)&BeaconData)[i]);
-            //     }
-            // } else
+        // if (waitingForBeacon && BeaconLocked) {
+        //     logInfo("send BeaconRxStatusInd");
+        //     _data.clear();
+        //     _data.push_back(0x40);
+        //     for (size_t i = 0; i < sizeof(BeaconData); ++i) {
+        //         _data.push_back(((uint8_t*)&BeaconData)[i]);
+        //     }
+        // } else
+
+        if (RxPort == 224) {
+            _data.clear();
 
-            if (RxPort == 224) {
-                data.clear();
-
-                std::string packet = mts::Text::bin2hexString(RxPayload, RxPayloadSize);
-                logDebug("Test Mode AppPort : %d", CommandTerminal::Dot()->getAppPort());
-                logDebug("Test Mode Packet : %s", packet.c_str());
+            std::string packet = mts::Text::bin2hexString(RxPayload, RxPayloadSize);
+            logDebug("Test Mode AppPort : %d", CommandTerminal::Dot()->getAppPort());
+            logDebug("Test Mode Packet : %s", packet.c_str());
 
-                switch (RxPayload[0]) {
-                    case 0x00: { // PackageVersionReq
-                        data.push_back(0x00);
-                        data.push_back(0x06);
-                        data.push_back(0x01);
-                        break;
+            switch (RxPayload[0]) {
+                case 0x00: { // PackageVersionReq
+                    _data.push_back(0x00);
+                    _data.push_back(0x06);
+                    _data.push_back(0x01);
+                    break;
+                }
+                case 0x01: { // DutResetReq
+                    if (RxPayloadSize == 1) {
+                        CommandTerminal::Dot()->resetCpu();
                     }
-                    case 0x01: { // DutResetReq
-                        if (RxPayloadSize == 1) {
-                            CommandTerminal::Dot()->resetCpu();
+                    break;
+                }
+                case 0x02: { // DutJoinReq
+                    if (RxPayloadSize == 1) {
+                        while (CommandTerminal::Dot()->getNextTxMs() > 0) {
+                            osDelay(1000);
                         }
-                        break;
+                        CommandTerminal::Dot()->joinNetworkOnce();
+                        return;
                     }
-                    case 0x02: { // DutJoinReq
-                        if (RxPayloadSize == 1) {
-                            CommandTerminal::Dot()->joinNetworkOnce();
-                            return;
-                        }
-                        break;
-                    }
-                    case 0x03: { // SwitchClassReq
-                        std::string cls = "A";
-                        if (RxPayload[1] > 0 && RxPayload[1] < 3) {
+                    break;
+                }
+                case 0x03: { // SwitchClassReq
+                    if (RxPayload[1] < 3) {
+                        if (RxPayload[1] == 0x00) {
+                            cls = "A";
+                        } else {
                             cls = RxPayload[1] == 0x01 ? "B" : "C";
                         }
-                        CommandTerminal::Dot()->setClass(cls);
-                        break;
-                    }
-                    case 0x04: { // ADR Enabled/Disable
-                        if (RxPayload[1] == 1)
-                            CommandTerminal::Dot()->setAdr(true);
-                        else
-                            CommandTerminal::Dot()->setAdr(false);
-                        break;
-                    }
-                    case 0x05: { // RegionalDutyCycleCtrlReq
-                        if (RxPayload[1] == 0)
-                            CommandTerminal::Dot()->setDisableDutyCycle(true);
-                        else
-                            CommandTerminal::Dot()->setDisableDutyCycle(false);
-
-                        break;
-                    }
-                    case 0x06: { // TxPeriodicityChangeReq
-                        if (RxPayload[1] < 2)
-                            // 0, 1 => 5s
-                            txPeriod = 5000U;
-                        else if (RxPayload[1] < 8)
-                            // 2 - 7 => 10s - 60s
-                            txPeriod = (RxPayload[1] - 1) * 10000U;
-                        else if (RxPayload[1] < 11) {
-                            // 8, 9, 10 => 120s, 240s, 480s
-                            txPeriod = 120 * (1 << (RxPayload[1] - 8)) * 1000U;
-                        }
-                        break;
                     }
-                    case 0x07: { // TxFramesCtrl
-                        if (RxPayload[1] == 0) {
-                            // NO-OP
-                        } else if (RxPayload[1] == 1) {
-                            testConfirmed = false;
-                            CommandTerminal::Dot()->getSettings()->Network.AckEnabled = 0;
-                        } else if (RxPayload[1] == 2) {
-                            testConfirmed = true;
-                            // if ADR has set nbTrans then use the current setting
-                            CommandTerminal::Dot()->getSettings()->Network.AckEnabled = 1;
-                            if (CommandTerminal::Dot()->getSettings()->Session.Redundancy == 0) {
-                                CommandTerminal::Dot()->getSettings()->Session.Redundancy = 1;
-                            }
-                        }
-                        break;
+                    CommandTerminal::Dot()->setClass(cls);
+                    break;
+                }
+                case 0x04: { // ADR Enabled/Disable
+                    if (RxPayload[1] == 1)
+                        CommandTerminal::Dot()->setAdr(true);
+                    else
+                        CommandTerminal::Dot()->setAdr(false);
+                    break;
+                }
+                case 0x05: { // RegionalDutyCycleCtrlReq
+                    if (RxPayload[1] == 0)
+                        CommandTerminal::Dot()->setDisableDutyCycle(true);
+                    else
+                        CommandTerminal::Dot()->setDisableDutyCycle(false);
+                    break;
+                }
+                case 0x06: { // TxPeriodicityChangeReq
+                    if (RxPayload[1] < 2)
+                        // 0, 1 => 5s
+                        txPeriod = 5000U;
+                    else if (RxPayload[1] < 8)
+                        // 2 - 7 => 10s - 60s
+                        txPeriod = (RxPayload[1] - 1) * 10000U;
+                    else if (RxPayload[1] < 11) {
+                        // 8, 9, 10 => 120s, 240s, 480s
+                        txPeriod = 120 * (1 << (RxPayload[1] - 8)) * 1000U;
                     }
-                    case 0x08: { // EchoPayloadReq
-                        data.push_back(0x08);
-                        for (size_t i = 1; i < RxPayloadSize; i++) {
-                            data.push_back(RxPayload[i] + 1);
+                    break;
+                }
+                case 0x07: { // TxFramesCtrl
+                    if (RxPayload[1] == 0) {
+                        // NO-OP
+                    } else if (RxPayload[1] == 1) {
+                        testConfirmed = false;
+                        CommandTerminal::Dot()->getSettings()->Network.AckEnabled = 0;
+                    } else if (RxPayload[1] == 2) {
+                        testConfirmed = true;
+                        // if ADR has set nbTrans then use the current setting
+                        CommandTerminal::Dot()->getSettings()->Network.AckEnabled = 1;
+                        if (CommandTerminal::Dot()->getSettings()->Session.Redundancy == 0) {
+                            CommandTerminal::Dot()->getSettings()->Session.Redundancy = 1;
                         }
-                        break;
                     }
-                    case 0x09: { // RxAppCntReq
-                        data.push_back(0x09);
-                        data.push_back(testDownlinkCounter & 0xFF);
-                        data.push_back(testDownlinkCounter >> 8);
-                        break;
-                    }
-                    case 0x0A: { // RxAppCntResetReq
-                        testDownlinkCounter = 0;
-                        break;
-                    }
-                    case 0x20: { // LinkCheckReq
-                        CommandTerminal::Dot()->addMacCommand(lora::MOTE_MAC_LINK_CHECK_REQ, 0, 0);
-                        break;
-                    }
-                    case 0x21: { // DeviceTimeReq
-                        CommandTerminal::Dot()->addDeviceTimeRequest();
-                        break;
+                    break;
+                }
+                case 0x08: { // EchoPayloadReq
+                    _data.push_back(0x08);
+                    for (size_t i = 1; i < RxPayloadSize; i++) {
+                        _data.push_back(RxPayload[i] + 1);
                     }
-                    case 0x22: { // PingSlotInfo
-                        CommandTerminal::Dot()->setPingPeriodicity(RxPayload[1]);
-                        CommandTerminal::Dot()->addMacCommand(lora::MOTE_MAC_PING_SLOT_INFO_REQ, RxPayload[1], 0);
-                        break;
-                    }
-                    case 0x7D: { // TxCw
-                        uint32_t freq = 0;
-                        uint16_t timeout = 0;
-                        uint8_t power = 0;
-
-                        timeout = RxPayload[2] << 8 | RxPayload[1];
-                        freq = (RxPayload[5] << 16 | RxPayload[4] << 8 | RxPayload[2]) * 100;
-                        power = RxPayload[6];
+                    break;
+                }
+                case 0x09: { // RxAppCntReq
+                    _data.push_back(0x09);
+                    _data.push_back(_testDownlinkCounter & 0xFF);
+                    _data.push_back(_testDownlinkCounter >> 8);
+                    break;
+                }
+                case 0x0A: { // RxAppCntResetReq
+                    _testDownlinkCounter = 0;
+                    break;
+                }
+                case 0x20: { // LinkCheckReq
+                    CommandTerminal::Dot()->addMacCommand(lora::MOTE_MAC_LINK_CHECK_REQ, 0, 0);
+                    break;
+                }
+                case 0x21: { // DeviceTimeReq
+                    CommandTerminal::Dot()->addDeviceTimeRequest();
+                    break;
+                }
+                case 0x22: { // PingSlotInfo
+                    CommandTerminal::Dot()->setPingPeriodicity(RxPayload[1]);
+                    CommandTerminal::Dot()->addMacCommand(lora::MOTE_MAC_PING_SLOT_INFO_REQ, RxPayload[1], 0);
+                    break;
+                }
+                case 0x7D: { // TxCw
+                    uint32_t freq = 0;
+                    uint16_t timeout = 0;
+                    uint8_t power = 0;
 
-                        CommandTerminal::Dot()->sendContinuous(true, timeout * 1000, freq, power);
-                        break;
-                    }
-                    case 0x7E: { // DutFPort224DisableReq
-                        _dot->setTestModeEnabled(false);
-                        CommandTerminal::Dot()->getSettings()->Test.TestMode = false;
-                        _dot->saveConfig();
-                        CommandTerminal::Dot()->resetCpu();
-                        break;
-                    }
-                    case 0x7F: { // DutVersionReq
-                        std::string version = AT_APPLICATION_VERSION;
-                        int temp = 0;
+                    timeout = RxPayload[2] << 8 | RxPayload[1];
+                    freq = (RxPayload[5] << 16 | RxPayload[4] << 8 | RxPayload[2]) * 100;
+                    power = RxPayload[6];
+
+                    CommandTerminal::Dot()->sendContinuous(true, timeout * 1000, freq, power);
+                    break;
+                }
+                case 0x7E: { // DutFPort224DisableReq
+                    _dot->setTestModeEnabled(false);
+                    CommandTerminal::Dot()->getSettings()->Test.TestMode = false;
+                    _dot->saveConfig();
+                    CommandTerminal::Dot()->resetCpu();
+                    break;
+                }
+                case 0x7F: { // DutVersionReq
+                    std::string version = AT_APPLICATION_VERSION;
+                    int temp = 0;
 
-                        data.push_back(0x7F);
-                        int ret = sscanf(&version[0], "%d", &temp);
-                        data.push_back(temp); // AT_APP_VERSION_MAJOR; // MAJOR
-                        ret = sscanf(&version[2], "%d", &temp);
-                        data.push_back(temp); // AT_APP_VERSION_MINOR; // MINOR
-                        ret = sscanf(&version[4], "%d", &temp);
-                        data.push_back(temp); // AT_APP_VERSION_PATCH; // PATCH
-                        if (version.size() > 7) {
-                            ret = sscanf(&version[6], "%d", &temp);
-                            data.push_back(temp); // AT_APP_VERSION_PATCH; // PATCH
-                        } else {
-                            data.push_back(0); // AT_APP_VERSION_PATCH; // PATCH
-                        }
-                        version = LW_VERSION;
-                        ret = sscanf(&version[0], "%d", &temp);
-                        data.push_back(temp); // AT_APP_VERSION_MAJOR; // MAJOR
-                        ret = sscanf(&version[2], "%d", &temp);
-                        data.push_back(temp); // AT_APP_VERSION_MINOR; // MINOR
-                        ret = sscanf(&version[4], "%d", &temp);
-                        data.push_back(temp); // AT_APP_VERSION_PATCH; // PATCH
-                        if (version.size() > 7) {
-                            ret = sscanf(&version[6], "%d", &temp);
-                            data.push_back(temp); // AT_APP_VERSION_PATCH; // PATCH
-                        } else {
-                            data.push_back(0); // AT_APP_VERSION_PATCH; // PATCH
-                        }
-                        version = RP_VERSION;
-                        ret = sscanf(&version[0], "%d", &temp);
-                        data.push_back(temp); // AT_APP_VERSION_MAJOR; // MAJOR
-                        ret = sscanf(&version[2], "%d", &temp);
-                        data.push_back(temp); // AT_APP_VERSION_MINOR; // MINOR
-                        ret = sscanf(&version[4], "%d", &temp);
-                        data.push_back(temp); // AT_APP_VERSION_PATCH; // PATCH
-                        if (version.size() > 7) {
-                            ret = sscanf(&version[6], "%d", &temp);
-                            data.push_back(temp); // AT_APP_VERSION_PATCH; // PATCH
-                        } else {
-                            data.push_back(0); // AT_APP_VERSION_PATCH; // PATCH
-                        }
-                        break;
+                    _data.push_back(0x7F);
+                    sscanf(&version[0], "%d", &temp);
+                    _data.push_back(temp); // AT_APP_VERSION_MAJOR; // MAJOR
+                    sscanf(&version[2], "%d", &temp);
+                    _data.push_back(temp); // AT_APP_VERSION_MINOR; // MINOR
+                    sscanf(&version[4], "%d", &temp);
+                    _data.push_back(temp); // AT_APP_VERSION_PATCH; // PATCH
+                    if (version.size() > 7) {
+                        sscanf(&version[6], "%d", &temp);
+                        _data.push_back(temp); // AT_APP_VERSION_PATCH; // PATCH
+                    } else {
+                        _data.push_back(0); // AT_APP_VERSION_PATCH; // PATCH
+                    }
+                    version = LW_VERSION;
+                    sscanf(&version[0], "%d", &temp);
+                    _data.push_back(temp); // LW_VERSION; // MAJOR
+                    sscanf(&version[2], "%d", &temp);
+                    _data.push_back(temp); // LW_VERSION; // MINOR
+                    sscanf(&version[4], "%d", &temp);
+                    _data.push_back(temp); // LW_VERSION; // PATCH
+                    if (version.size() > 7) {
+                        sscanf(&version[6], "%d", &temp);
+                        _data.push_back(temp); // LW_VERSION; // PATCH
+                    } else {
+                        _data.push_back(0); // LW_VERSION; // PATCH
                     }
-                    default: {
-                        break;
+                    version = RP_VERSION;
+                    sscanf(&version[0], "%d", &temp);
+                    _data.push_back(temp); // RP_VERSION; // MAJOR
+                    sscanf(&version[2], "%d", &temp);
+                    _data.push_back(temp); // RP_VERSION; // MINOR
+                    sscanf(&version[4], "%d", &temp);
+                    _data.push_back(temp); // RP_VERSION; // PATCH
+                    if (version.size() > 7) {
+                        sscanf(&version[6], "%d", &temp);
+                        _data.push_back(temp); // RP_VERSION; // PATCH
+                    } else {
+                        _data.push_back(0); // RP_VERSION; // PATCH
                     }
+
+
+                    break;
+                }
+                default: {
+                    break;
+                }
+            }
+        }
+
+        do {
+            uint32_t loop_timer = 0;
+            loop_timer = std::chrono::duration_cast<std::chrono::milliseconds>(sentTimer.elapsed_time()).count();
+
+            PacketReceived = false;
+            AckReceived = false;
+
+            while (loop_timer < txPeriod || CommandTerminal::Dot()->getNextTxMs() > 0 || !CommandTerminal::Dot()->getIsIdle()) {
+                // if (waitingForBeacon && BeaconLocked) {
+                //     goto TEST_START;
+                // }
+                osDelay(500);
+                loop_timer = std::chrono::duration_cast<std::chrono::milliseconds>(sentTimer.elapsed_time()).count();
+
+                if (CommandTerminal::Dot()->getAckRequested() && loop_timer > 5000) {
+                    break;
                 }
             }
 
-            do {
-                while (std::chrono::duration_cast<std::chrono::milliseconds>(sentTimer.elapsed_time()).count() < txPeriod
-                    || CommandTerminal::Dot()->getNextTxMs() > 0) {
-                    // if (waitingForBeacon && BeaconLocked) {
-                    //     goto TEST_START;
-                    // }
-                    osDelay(1000);
-                }
+            // packet may have been received while waiting, if ACK req then send uplink
+            // else process data
+            if (!PacketReceived || CommandTerminal::Dot()->getAckRequested()) {
 
                 sentTimer.reset();
 
-                if (data.size() == 0) {
+                if (_data.size() == 0) {
                     CommandTerminal::Dot()->setAppPort(1);
-                    data.push_back(0xFF);
+                    // if (cls == "B") {
+                    //     // class B tests don't like empty packets
+                        _data.push_back(0xFF);
+                    // }
                 } else {
                     CommandTerminal::Dot()->setAppPort(224);
                 }
 
-                if (CommandTerminal::Dot()->send(data, testConfirmed) == mDot::MDOT_MAX_PAYLOAD_EXCEEDED) {
-                    data.clear();
+                PacketReceived = false;
+                AckReceived = false;
+
+                if (CommandTerminal::Dot()->send(_data, testConfirmed) == mDot::MDOT_MAX_PAYLOAD_EXCEEDED) {
+                    _data.clear();
                     RxPort = 0;
                     goto TEST_START;
                 }
 
-                if (PacketReceived) {
-                    last_rx_seq = CommandTerminal::Dot()->getSettings()->Session.UplinkCounter;
-                }
-
-                data.clear();
+                // For Class B tests
+                // if (PacketReceived) {
+                //     last_rx_seq = CommandTerminal::Dot()->getSettings()->Session.UplinkCounter;
+                // }
 
-            } while (!AckReceived && CommandTerminal::Dot()->recv(data) != mDot::MDOT_OK);
+                _data.clear();
 
-            if (AckReceived || (PacketReceived && (RxPort != 0 || RxPayloadSize == 0))) {
-                testDownlinkCounter++;
-                logDebug("Incremented downlink cnt %d", testDownlinkCounter);
             }
 
-            PacketReceived = false;
-            AckReceived = false;
+        } while (!AckReceived && CommandTerminal::Dot()->recv(_data) != mDot::MDOT_OK);
+
+
+        if (cls == "B" && !BeaconLocked) {
+            CommandTerminal::Dot()->setClass(cls);
         }
+    }
 #endif
 }