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:
28:c222ca8383f4
Parent:
27:5fafd3b26ac3
Child:
36:b586cd6e91f3
--- a/CommandTerminal/CmdTxChannel.cpp	Fri Sep 11 13:16:33 2020 -0500
+++ b/CommandTerminal/CmdTxChannel.cpp	Thu Nov 19 09:58:25 2020 -0600
@@ -1,14 +1,46 @@
 #include "CmdTxChannel.h"
 #include "ChannelPlan.h"
 
-CmdTxChannel::CmdTxChannel()
-: Command("Tx Channels", "AT+TXCH",
-#if defined(TARGET_MTS_MDOT_F411RE)
-    "List Tx channel frequencies for sub-band",
+namespace {
+void parseArgs(const std::vector<std::string>& args, int& index, int& frequency, int& datarateRange) {
+    sscanf(args[1].c_str(), "%d", &index);
+    sscanf(args[2].c_str(), "%d", &frequency);
+    sscanf(args[3].c_str(), "%02x", &datarateRange);
+}
+
+
+void printChannel(const char* name, uint32_t channel, uint8_t range_max, uint8_t range_min, int16_t on) {
+#if MTS_CMD_TERM_VERBOSE
+    if (on != -1) {
+        CommandTerminal::Serial()->writef("  %-6s%9d%7X%4X%5d\r\n", name, channel, range_max, range_min, on);
+    } else {
+        CommandTerminal::Serial()->writef("  %-6s%9d%7X%4X\r\n", name, channel, range_max, range_min);
+    }
 #else
-    "",
+    CommandTerminal::Serial()->writef("%s,%d,%X,%X,%d\r\n", name, channel, range_max, range_min, on);
 #endif
-    "<INDEX>,<FREQUENCY>,<DR_RANGE>") {
+}
+
+void assignName(char* name, int i) {
+    if (i > 9) {
+        int t = i - (i % 10);
+        name[0] = '0' + (t / 10);
+        name[1] = '0' + (i - t);
+    } else {
+        name[0] = i + '0';
+        name[1] = '\0';
+    }
+}
+
+} // namespace
+
+CmdTxChannel::CmdTxChannel() :
+#if MTS_CMD_TERM_VERBOSE
+    Command("Tx Channels", "AT+TXCH", "List Tx channel frequencies for sub-band", "<INDEX>,<FREQUENCY>,<DR_RANGE>")
+#else
+    Command("AT+TXCH")
+#endif
+{
     _queryable = true;
 }
 
@@ -19,41 +51,89 @@
         std::vector<uint8_t> ranges = CommandTerminal::Dot()->getChannelRanges();
         std::vector<uint16_t> mask = CommandTerminal::Dot()->getChannelMask();
 
+        //channelProps props { "\0\0", 0, 0, 0, 0 };
+        char name[3] = "\0\0";
+        uint32_t channel;
+        uint8_t range_max;
+        uint8_t range_min;
+        int16_t on;
+
+#if MTS_CMD_TERM_VERBOSE
         CommandTerminal::Serial()->writef("Index\tFrequency  DR Max Min  On\r\n");
+#endif
 
         if (lora::ChannelPlan::IsPlanDynamic(CommandTerminal::Dot()->getFrequencyBand())) {
-            for (int8_t i = 0; i < 16; i++) {
-                if (channels[i] != 0)
-                    CommandTerminal::Serial()->writef("  %d\t%d      %X   %X    %d\r\n", i, channels[i], ranges[i] >> 4, ranges[i] & 0xF, (mask[0] & (0x1 << i)) ? 1 : 0);
-                else
-                    CommandTerminal::Serial()->writef("  %d\t    %d          %X   %X    0\r\n", i, channels[i], ranges[i] >> 4, ranges[i] & 0xF);
-            }
-
-            if (channels[16] != 0)
-                CommandTerminal::Serial()->writef("  R2\t%d      %X   %X\r\n", channels[16], ranges[16] >> 4, ranges[16] & 0xF);
-            else
-                CommandTerminal::Serial()->writef("  R2\t    %d          %X   %X\r\n", channels[16], ranges[16], ranges[168]);
-
-        } else {
-            if (CommandTerminal::Dot()->getFrequencySubBand() > 0) {
-                uint8_t offset = (CommandTerminal::Dot()->getFrequencySubBand() - 1) * 8;
-
-                for (int i = 0; i < 8; i++) {
-                    if ((CommandTerminal::Dot()->getFrequencySubBand() % 2) == 1) {
-                        CommandTerminal::Serial()->writef("  %d\t%d      %X   %X    %d\r\n", i, channels[i], ranges[i] >> 4, ranges[i] & 0xF, (mask[(offset + i)/16] & (0x0001 << i)) ? 1 : 0);
+            for (int8_t i = 0; i < 17; i++) {
+                channel = channels[i];
+                range_max = ranges[i] >> 4;
+                range_min = ranges[i] & 0xF;
+                if (i == 16) {
+                    name[0] = 'R';
+                    name[1] = '2';
+                    on = -1;
+                    if (channels[16] == 0) {
+                        range_max = ranges[16];
+                        range_min = ranges[168];
+                    }
+                } else {
+                    assignName(name, i);
+                    channel = channels[i];
+                    if (channels[i] != 0) {
+                        on = (mask[0] & (0x1 << i)) ? 1 : 0;
                     } else {
-                        CommandTerminal::Serial()->writef("  %d\t%d      %X   %X    %d\r\n", i, channels[i], ranges[i] >> 4, ranges[i] & 0xF, (mask[(offset + i)/16] & (0x0001 << (i + 8))) ? 1 : 0);
+                        on = 0;
                     }
                 }
+                
+                printChannel(name, channel, range_max, range_min, on);
+            }
+        } else {
+            uint8_t sub_band = CommandTerminal::Dot()->getFrequencySubBand();
+            if (sub_band > 0) {
+                uint8_t offset = (sub_band - 1) * 8;
 
-                CommandTerminal::Serial()->writef("  U\t%d      %X   %X    %d\r\n", channels[8], ranges[8] >> 4, ranges[8] & 0xF, (mask[4] & (0x0001 << (CommandTerminal::Dot()->getFrequencySubBand() - 1))) ? 1 : 0);
-                CommandTerminal::Serial()->writef("  R2\t%d      %X   %X\r\n", channels[9], ranges[9], ranges[9]);
+                for (int i = 0; i < 10; i++) {
+                    channel = channels[i];
+                    if (i == 9) {
+                        name[0] = 'R';
+                        name[1] = '2';
+                        range_max = ranges[i];
+                        range_min = ranges[i];
+                        on = -1;
+                    } else {
+                        if (i == 8) {
+                            name[0] = 'U';
+                            on = (mask[4] & (0x0001 << (sub_band - 1))) ? 1 : 0;
+                        } else {
+                            assignName(name, i);
+                            if ((sub_band % 2) == 1) {
+                                on = (mask[(offset + i)/16] & (0x0001 << i)) ? 1 : 0;
+                            } else {
+                                on = (mask[(offset + i)/16] & (0x0001 << (i + 8))) ? 1 : 0;
+                            }
+                        }
+                        range_max = ranges[i] >> 4;
+                        range_min = ranges[i] & 0xF;
+                    }
+                    printChannel(name, channel, range_max, range_min, on);
+                }
             } else {
-                for (size_t i = 0; i < channels.size() - 1; i++) {
-                    CommandTerminal::Serial()->writef("  %d\t%d      %X   %X    %d\r\n", i, channels[i], ranges[i] >> 4, ranges[i] & 0xF, (mask[i/16] & (0x0001 << (i%16))) ? 1 : 0);
+                for (size_t i = 0; i < channels.size(); i++) {
+                    channel = channels[i];
+                    if (i == channels.size() - 1) {
+                        name[0] = 'R';
+                        name[1] = '2';
+                        range_max = ranges[i];
+                        range_min = ranges[i];
+                        on = -1;
+                    } else {
+                        assignName(name, i);
+                        range_max = ranges[i] >> 4;
+                        range_min = ranges[i] & 0xF;
+                        on = (mask[i/16] & (0x0001 << (i%16))) ? 1 : 0;
+                    }
+                    printChannel(name, channel, range_max, range_min, on);
                 }
-                uint8_t last = channels.size() - 1;
-                CommandTerminal::Serial()->writef("  R2\t%d      %X   %X\r\n", channels[last], ranges[last], ranges[last]);
             }
         }
     }
@@ -63,12 +143,12 @@
         int frequency;
         int datarateRange;
 
-        sscanf(args[1].c_str(), "%d", &index);
-        sscanf(args[2].c_str(), "%d", &frequency);
-        sscanf(args[3].c_str(), "%02x", &datarateRange);
+        parseArgs(args, index, frequency, datarateRange);
 
         if (CommandTerminal::Dot()->addChannel(index, frequency, datarateRange) != mDot::MDOT_OK) {
+#if MTS_CMD_TERM_VERBOSE
             CommandTerminal::setErrorMessage("Failed to add channel");
+#endif
             return 1;
         }
     }
@@ -80,31 +160,36 @@
     if (args.size() == 1)
         return true;
 
+
     if (args.size() == 4) {
 
         int index;
         int frequency;
         int datarateRange;
 
-        sscanf(args[1].c_str(), "%d", &index);
-        sscanf(args[2].c_str(), "%d", &frequency);
-        sscanf(args[3].c_str(), "%02x", &datarateRange);
+        parseArgs(args, index, frequency, datarateRange);
 
         if (lora::ChannelPlan::IsPlanDynamic(CommandTerminal::Dot()->getFrequencyBand())) {
             if (frequency != 0 && (frequency < int(CommandTerminal::Dot()->getMinFrequency()) || frequency > int(CommandTerminal::Dot()->getMaxFrequency()))) {
+#if MTS_CMD_TERM_VERBOSE
                 char tmp[256];
                 sprintf(tmp, "Invalid frequency, expects (0,%lu-%lu)", CommandTerminal::Dot()->getMinFrequency(), CommandTerminal::Dot()->getMaxFrequency());
                 CommandTerminal::setErrorMessage(tmp);
+#endif
                 return false;
             }
         } else {
+#if MTS_CMD_TERM_VERBOSE
             CommandTerminal::setErrorMessage("Fixed channel plans cannot be changed, use AT+FSB or AT+CHM to limit");
+#endif
             return false;
         }
 
         return true;
     } else {
+#if MTS_CMD_TERM_VERBOSE
         CommandTerminal::setErrorMessage("Invalid arguments");
+#endif
         return false;
     }