dev

Dependencies:   MTS-Serial libmDot-mbed5

Fork of Dot-AT-Firmware by MultiTech

Revision:
14:f9a77400b622
Parent:
9:ff62b20f7000
--- a/CommandTerminal/CmdNetworkKey.cpp	Fri Nov 04 19:10:24 2016 +0000
+++ b/CommandTerminal/CmdNetworkKey.cpp	Fri Nov 04 14:25:43 2016 -0500
@@ -1,11 +1,8 @@
 #include "CmdNetworkKey.h"
 
-CmdNetworkKey::CmdNetworkKey(mDot* dot, mts::MTSSerial& serial) :
-    Command(dot, "Network Key", "AT+NK", "Configured network key/passphrase (App Key in LoRaWAN) ##  AT+NK=0,hex  AT+NK=1,passphrase (Net key = cmac(passphrase)) (16 bytes)"),
-    _serial(serial)
+CmdNetworkKey::CmdNetworkKey() :
+    Command("Network Key", "AT+NK", "Configured network key/passphrase (App Key in LoRaWAN) ##  AT+NK=0,hex  AT+NK=1,passphrase (Net key = cmac(passphrase)) (16 bytes)", "(0,(hex:16)),(1,(string:128))")
 {
-    _help = std::string(text()) + ": " + std::string(desc());
-    _usage = "(0,(hex:16)),(1,(string:128))";
     _queryable = true;
 }
 
@@ -13,18 +10,12 @@
 {
     if (args.size() == 1)
     {
-        if (_dot->getVerbose())
-            _serial.writef("Network Key: ");
-
-        _serial.writef("%s\r\n", mts::Text::bin2hexString(_dot->getNetworkKey(), ".").c_str());
-        if (!_dot->getNetworkPassphrase().empty())
-            _serial.writef("Passphrase: '%s'\r\n", _dot->getNetworkPassphrase().c_str());
-
+        CommandTerminal::Serial()->writef("%s\r\n", mts::Text::bin2hexString(CommandTerminal::Dot()->getNetworkKey(), ".").c_str());
+        if (!CommandTerminal::Dot()->getNetworkPassphrase().empty())
+            CommandTerminal::Serial()->writef("Passphrase: '%s'\r\n", CommandTerminal::Dot()->getNetworkPassphrase().c_str());
     }
     else if (args.size() == 3)
     {
-        int32_t code;
-
         if (args[1].find("1") == 0 && args[1].size() == 1)
         {
             std::string text;
@@ -43,15 +34,14 @@
                 text = args[2];
             }
 
-            if ((code = _dot->setNetworkPassphrase(text)) == mDot::MDOT_OK)
+            if (CommandTerminal::Dot()->setNetworkPassphrase(text) == mDot::MDOT_OK)
             {
-                _serial.writef("Set Network Passphrase: ");
-                _serial.writef("%s\r\n", text.c_str());
+                CommandTerminal::Serial()->writef("Set Network Passphrase: ");
+                CommandTerminal::Serial()->writef("%s\r\n", text.c_str());
             }
             else
             {
-                
-                setErrorMessage(_dot->getLastError());;
+                CommandTerminal::setErrorMessage(CommandTerminal::Dot()->getLastError());;
                 return 1;
             }
         }
@@ -59,15 +49,14 @@
         {
             std::vector<uint8_t> NewKey;
             readByteArray(args[2], NewKey, KEY_LENGTH);
-            if ((code = _dot->setNetworkKey(NewKey)) == mDot::MDOT_OK)
+            if (CommandTerminal::Dot()->setNetworkKey(NewKey) == mDot::MDOT_OK)
             {
-                _serial.writef("Set Network Key: ");
-                _serial.writef("%s\r\n", mts::Text::bin2hexString(NewKey, ".").c_str());
+                CommandTerminal::Serial()->writef("Set Network Key: ");
+                CommandTerminal::Serial()->writef("%s\r\n", mts::Text::bin2hexString(NewKey, ".").c_str());
             }
             else
             {
-                
-                setErrorMessage(_dot->getLastError());;
+                CommandTerminal::setErrorMessage(CommandTerminal::Dot()->getLastError());;
                 return 1;
             }
         }
@@ -83,28 +72,28 @@
 
     if (args.size() == 3) {
         if (args[1] != "0" && args[1] != "1") {
-            setErrorMessage("Invalid type, expects (0,1)");
+            CommandTerminal::setErrorMessage("Invalid type, expects (0,1)");
             return false;
         }
         if (args[1] == "0" && !isHexString(args[2], 16)) {
-            setErrorMessage("Invalid key, expects (hex:16)");
+            CommandTerminal::setErrorMessage("Invalid key, expects (hex:16)");
             return false;
         }
 
         if (args[1] == "1" && args[2].size() < 8) {
-            setErrorMessage("Invalid name, expects minimum 8 characters");
+            CommandTerminal::setErrorMessage("Invalid name, expects minimum 8 characters");
             return false;
         }
 
         if (args[1] == "1" && (args[2].size() > 128 || args[2].size() < 8)) {
-            setErrorMessage("Invalid passphrase, expects (string:8-128)");
+            CommandTerminal::setErrorMessage("Invalid passphrase, expects (string:8-128)");
             return false;
         }
 
         return true;
     }
 
-    setErrorMessage("Invalid arguments");
+    CommandTerminal::setErrorMessage("Invalid arguments");
     return false;
 }