mDot AT-Firmware for testing

Dependencies:   MTS-Serial libmDot-mbed5

Fork of Dot-AT-Firmware by MultiTech

Revision:
14:f9a77400b622
Parent:
1:e52ae6584f1c
--- a/CommandTerminal/CmdFrequencyBand.cpp	Fri Nov 04 19:10:24 2016 +0000
+++ b/CommandTerminal/CmdFrequencyBand.cpp	Fri Nov 04 14:25:43 2016 -0500
@@ -1,31 +1,68 @@
 #include "CmdFrequencyBand.h"
 
-CmdFrequencyBand::CmdFrequencyBand(mDot* dot, mts::MTSSerial& serial) :
-        Command(dot, "Frequency Band", "AT+FREQ", "Configured Frequency Band '868' or '915'"), _serial(serial)
+
+CmdFrequencyBand::CmdFrequencyBand() :
+        Command("Frequency Band", "AT+FREQ", "Configured Frequency Band 'EU868', 'US915' or 'AU915'", "(EU868,US915,AU915)")
 {
-    _help = std::string(text()) + ": " + std::string(desc());
-    _usage = "(868,915)";
     _queryable = true;
 }
 
 uint32_t CmdFrequencyBand::action(std::vector<std::string> args)
-{
+                                  {
     if (args.size() == 1)
     {
-        if (_dot->getVerbose())
-            _serial.writef("Frequency Band: ");
+        CommandTerminal::Serial()->writef("%s\r\n", mDot::FrequencyBandStr(CommandTerminal::Dot()->getFrequencyBand()).c_str());
+    }
+
+#ifdef DEBUG_MAC
+    else if (args.size() == 2)
+    {
+        uint8_t band = mDot::FB_US915;
+        std::string band_str = mts::Text::toUpper(args[1]);
+
 
-        _serial.writef("%s\r\n", mDot::FrequencyBandStr(_dot->getFrequencyBand()).c_str());
+        if (mDot::FrequencyBandStr(mDot::FB_EU868).find(band_str) != std::string::npos) {
+            band = mDot::FB_EU868;
+        }
+        if (mDot::FrequencyBandStr(mDot::FB_AU915).find(band_str) != std::string::npos) {
+            band = mDot::FB_AU915;
+        }
+        if (mDot::FrequencyBandStr(mDot::FB_US915).find(band_str) != std::string::npos) {
+            band = mDot::FB_US915;
+        }
+
+        if (CommandTerminal::Dot()->setFrequencyBand(band) != mDot::MDOT_OK) {
+            CommandTerminal::setErrorMessage(CommandTerminal::Dot()->getLastError());;
+            return 1;
+        }
     }
+#endif
 
     return 0;
 }
 
 bool CmdFrequencyBand::verify(std::vector<std::string> args)
-{
+                              {
     if (args.size() == 1)
         return true;
 
-    setErrorMessage("Invalid arguments");
+#ifdef DEBUG_MAC
+    if (args.size() == 2)
+    {
+        std::string band = mts::Text::toUpper(args[1]);
+
+        if (mDot::FrequencyBandStr(mDot::FB_EU868).find(band) == std::string::npos &&
+            mDot::FrequencyBandStr(mDot::FB_US915).find(band) == std::string::npos &&
+            mDot::FrequencyBandStr(mDot::FB_AU915).find(band) == std::string::npos)
+        {
+            CommandTerminal::setErrorMessage("Invalid parameter, expects (EU868,US915,AU915)");
+            return false;
+        }
+
+        return true;
+    }
+#endif
+
+    CommandTerminal::setErrorMessage("Invalid arguments");
     return false;
 }