Multitech xDot AT Firmware

Dependencies:   MTS-Serial libxDot-mbed5

Files at this revision

API Documentation at this revision

Comitter:
Mike Fiore
Date:
Tue Aug 18 11:21:43 2015 -0500
Parent:
3:1ee9417f6707
Child:
5:59f60bedc6df
Commit message:
update mdot-firmware to 0.1.2

Changed in this revision

CommandTerminal/CmdDisplayConfig.cpp Show annotated file Show diff for this revision Revisions of this file
CommandTerminal/CmdJoinByteOrder.cpp Show annotated file Show diff for this revision Revisions of this file
CommandTerminal/CmdJoinByteOrder.h Show annotated file Show diff for this revision Revisions of this file
CommandTerminal/CmdLinkCheckThreshold.cpp Show annotated file Show diff for this revision Revisions of this file
CommandTerminal/CmdReceiveContinuous.cpp Show annotated file Show diff for this revision Revisions of this file
CommandTerminal/CmdResetStats.cpp Show annotated file Show diff for this revision Revisions of this file
CommandTerminal/CmdResetStats.h Show annotated file Show diff for this revision Revisions of this file
CommandTerminal/CmdSendContinuous.cpp Show annotated file Show diff for this revision Revisions of this file
CommandTerminal/CmdSendContinuous.h Show annotated file Show diff for this revision Revisions of this file
CommandTerminal/CmdSendString.cpp Show annotated file Show diff for this revision Revisions of this file
CommandTerminal/CmdSendStringOnInterval.cpp Show annotated file Show diff for this revision Revisions of this file
CommandTerminal/CmdSerialReceiveTimeout.cpp Show diff for this revision Revisions of this file
CommandTerminal/CmdSerialReceiveTimeout.h Show diff for this revision Revisions of this file
CommandTerminal/CmdSerialWakeDelay.cpp Show diff for this revision Revisions of this file
CommandTerminal/CmdSerialWakeDelay.h Show diff for this revision Revisions of this file
CommandTerminal/CmdSerialWakeInterval.cpp Show diff for this revision Revisions of this file
CommandTerminal/CmdSerialWakeInterval.h Show diff for this revision Revisions of this file
CommandTerminal/CmdTxWait.cpp Show annotated file Show diff for this revision Revisions of this file
CommandTerminal/CmdWakeDelay.cpp Show annotated file Show diff for this revision Revisions of this file
CommandTerminal/CmdWakeDelay.h Show annotated file Show diff for this revision Revisions of this file
CommandTerminal/CmdWakeInterval.cpp Show annotated file Show diff for this revision Revisions of this file
CommandTerminal/CmdWakeInterval.h Show annotated file Show diff for this revision Revisions of this file
CommandTerminal/CmdWakeMode.cpp Show annotated file Show diff for this revision Revisions of this file
CommandTerminal/CmdWakeMode.h Show annotated file Show diff for this revision Revisions of this file
CommandTerminal/CmdWakePin.cpp Show annotated file Show diff for this revision Revisions of this file
CommandTerminal/CmdWakePin.h Show annotated file Show diff for this revision Revisions of this file
CommandTerminal/CmdWakeTimeout.cpp Show annotated file Show diff for this revision Revisions of this file
CommandTerminal/CmdWakeTimeout.h Show annotated file Show diff for this revision Revisions of this file
CommandTerminal/CommandTerminal.cpp Show annotated file Show diff for this revision Revisions of this file
CommandTerminal/CommandTerminal.h Show annotated file Show diff for this revision Revisions of this file
CommandTerminal/Commands.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
version.h Show annotated file Show diff for this revision Revisions of this file
--- a/CommandTerminal/CmdDisplayConfig.cpp	Tue Aug 18 15:58:59 2015 +0000
+++ b/CommandTerminal/CmdDisplayConfig.cpp	Tue Aug 18 11:21:43 2015 -0500
@@ -40,6 +40,8 @@
 
     _serial.writef("Network Join Retries:\t%u\r\n", _dot->getJoinRetries());
 
+    _serial.writef("Join Byte Order:\t%s\r\n", _dot->getJoinByteOrder() ? "MSB" : "LSB");
+
     _serial.writef("Link Check Threshold:\t");
     if (_dot->getLinkCheckThreshold() == 0) {
         _serial.writef("off\r\n");
@@ -90,9 +92,12 @@
     _serial.writef("Debug Baud Rate:\t%lu\r\n", _dot->getDebugBaud());
     _serial.writef("Serial Baud Rate:\t%lu\r\n", _dot->getBaud());
 
-    _serial.writef("Serial Wake Interval:\t%lu s\r\n", _dot->getSerialWakeInterval());
-    _serial.writef("Serial Wake Delay:\t%lu ms\r\n", _dot->getSerialWakeDelay());
-    _serial.writef("Serial Receive Timeout:\t%u ms\r\n", _dot->getSerialReceiveTimeout());
+    _serial.writef("Wake Mode:\t\t%s\r\n", _dot->getWakeMode() == 0 ? "INTERVAL" : "INTERRUPT");
+    _serial.writef("Wake Interval:\t\t%lu s\r\n", _dot->getWakeInterval());
+    _serial.writef("Wake Delay:\t\t%lu ms\r\n", _dot->getWakeDelay());
+    _serial.writef("Wake Timeout:\t\t%u ms\r\n", _dot->getWakeTimeout());
+
+    //_serial.writef("Wake Pin:\t\t%s\r\n", mDot::pinName2Str(_dot->getWakePin()).c_str());
 
     _serial.writef("Log Level:\t\t%ld\r\n", _dot->getLogLevel());
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CommandTerminal/CmdJoinByteOrder.cpp	Tue Aug 18 11:21:43 2015 -0500
@@ -0,0 +1,56 @@
+#include "CmdJoinByteOrder.h"
+
+CmdJoinByteOrder::CmdJoinByteOrder(mDot* dot, mts::MTSSerial& serial) :
+        Command(dot, "Join Byte Order", "AT+JBO", "Send EUI's in join request with configured byte ordering (0:LSB,1:MSB)"), _serial(serial)
+{
+    _help = std::string(text()) + ": " + std::string(desc());
+    _usage = "(0:LSB,1:MSB)";
+    _queryable = true;
+}
+
+uint32_t CmdJoinByteOrder::action(std::vector<std::string> args)
+{
+    if (args.size() == 1)
+    {
+        if (_dot->getVerbose())
+            _serial.writef("Join Byte Order: ");
+
+        _serial.writef("%d\r\n", _dot->getJoinByteOrder());
+    }
+    else if (args.size() == 2)
+    {
+        int32_t code;
+        mDot::JoinByteOrder order = mDot::LSB;
+
+        if (args[1] == "1")
+            order = mDot::MSB;
+
+        if ((code = _dot->setJoinByteOrder(order)) != mDot::MDOT_OK)
+        {
+            std::string error = mDot::getReturnCodeString(code) + " - " + _dot->getLastError();
+            setErrorMessage(error);
+            return 1;
+        }
+    }
+
+    return 0;
+}
+
+bool CmdJoinByteOrder::verify(std::vector<std::string> args)
+{
+    if (args.size() == 1)
+        return true;
+
+    if (args.size() == 2)
+    {
+        if (args[1] != "0" && args[1] != "1") {
+            setErrorMessage("Invalid argument");
+            return false;
+        }
+
+        return true;
+    }
+
+    setErrorMessage("Invalid arguments");
+    return false;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CommandTerminal/CmdJoinByteOrder.h	Tue Aug 18 11:21:43 2015 -0500
@@ -0,0 +1,21 @@
+
+#ifndef __CMDJOINBYTEORDER_H__
+#define __CMDJOINBYTEORDER_H__
+
+#include "Command.h"
+
+class CommandTerminal;
+
+class CmdJoinByteOrder : public Command {
+
+public:
+
+    CmdJoinByteOrder(mDot* dot, mts::MTSSerial& serial);
+    virtual uint32_t action(std::vector<std::string> args);
+    virtual bool verify(std::vector<std::string> args);
+    
+private:   
+    mts::MTSSerial& _serial;
+};
+
+#endif // __CMDJOINBYTEORDER_H__
--- a/CommandTerminal/CmdLinkCheckThreshold.cpp	Tue Aug 18 15:58:59 2015 +0000
+++ b/CommandTerminal/CmdLinkCheckThreshold.cpp	Tue Aug 18 11:21:43 2015 -0500
@@ -1,7 +1,7 @@
 #include "CmdLinkCheckThreshold.h"
 
 CmdLinkCheckThreshold::CmdLinkCheckThreshold(mDot* dot, mts::MTSSerial& serial) :
-        Command(dot, "Link Check Threshold", "AT+LCT", "Set threshold for number of link check of ACK failures to tolerate, (0: off, N: number of failures"), _serial(serial)
+        Command(dot, "Link Check Threshold", "AT+LCT", "Set threshold for number of link check of ACK failures to tolerate, (0: off, N: number of failures)"), _serial(serial)
 {
     _help = std::string(text()) + ": " + std::string(desc());
     _usage = "(0-255)";
--- a/CommandTerminal/CmdReceiveContinuous.cpp	Tue Aug 18 15:58:59 2015 +0000
+++ b/CommandTerminal/CmdReceiveContinuous.cpp	Tue Aug 18 11:21:43 2015 -0500
@@ -1,23 +1,25 @@
 #include "CmdReceiveContinuous.h"
 #include "CommandTerminal.h"
 
-CmdReceiveContinuous::CmdReceiveContinuous(mDot* dot, mts::MTSSerial& serial) :
+CmdReceiveContinuous::CmdReceiveContinuous(mDot* dot, mts::MTSSerial& serial)
+:
     Command(dot, "Receive Continuous", "AT+RECVC", "Continuously receive and display packets. (escape sequence: +++)"),
-    _serial(serial)
-{
+  _serial(serial) {
     _help = std::string(text()) + ": " + std::string(desc());
-    _usage = "in: (2000-2147483647) ms; out: (string:242) or (hex:242)";
+    _usage = "out: (string:242) or (hex:242)";
 }
 
-uint32_t CmdReceiveContinuous::action(std::vector<std::string> args)
-{
+uint32_t CmdReceiveContinuous::action(std::vector<std::string> args) {
     std::vector<uint8_t> data;
 
     std::string escape_buffer;
     char ch;
 
-    while (true)
-    {
+    while (true) {
+
+        _dot->openRxWindow(0);
+
+        osDelay(1000);
         if (_dot->recv(data) == mDot::MDOT_OK) {
             if (_dot->getVerbose())
                 _serial.writef("Packet data:\r\n");
@@ -41,8 +43,7 @@
     return 0;
 }
 
-bool CmdReceiveContinuous::verify(std::vector<std::string> args)
-{
+bool CmdReceiveContinuous::verify(std::vector<std::string> args) {
     if (args.size() == 1)
         return true;
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CommandTerminal/CmdResetStats.cpp	Tue Aug 18 11:21:43 2015 -0500
@@ -0,0 +1,16 @@
+#include "CmdResetStats.h"
+
+CmdResetStats::CmdResetStats(mDot* dot, mts::MTSSerial& serial)
+:
+  Command(dot, "Reset Stats", "AT&R", "Reset statistics"),
+  _serial(serial), _dot(dot) {
+    _help = std::string(text()) + ": " + std::string(desc());
+}
+
+uint32_t CmdResetStats::action(std::vector<std::string> args) {
+
+    _dot->resetStats();
+
+    return 0;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CommandTerminal/CmdResetStats.h	Tue Aug 18 11:21:43 2015 -0500
@@ -0,0 +1,20 @@
+#ifndef __CMDRESETSTATS_H__
+#define __CMDRESETSTATS_H__
+
+#include "Command.h"
+
+class CmdResetStats : public Command {
+
+public:
+
+    CmdResetStats(mDot* dot, mts::MTSSerial& serial);
+    virtual uint32_t action(std::vector<std::string> args);
+
+private:
+
+    mts::MTSSerial& _serial;
+    mDot* _dot;
+
+};
+
+#endif // __CMDRESETSTATS_H__
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CommandTerminal/CmdSendContinuous.cpp	Tue Aug 18 11:21:43 2015 -0500
@@ -0,0 +1,21 @@
+#include "CmdSendContinuous.h"
+#include "CommandTerminal.h"
+
+CmdSendContinuous::CmdSendContinuous(mDot* dot, mts::MTSSerial& serial)
+:
+  Command(dot, "Send Continuous", "AT+SENDC", "Send un-modulated data continuously"),
+  _serial(serial) {
+    _help = std::string(text()) + ": " + std::string(desc());
+    _usage = "(string:242)";
+}
+
+uint32_t CmdSendContinuous::action(std::vector<std::string> args) {
+
+    _dot->sendContinuous();
+    return 0;
+}
+
+bool CmdSendContinuous::verify(std::vector<std::string> args) {
+
+    return true;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CommandTerminal/CmdSendContinuous.h	Tue Aug 18 11:21:43 2015 -0500
@@ -0,0 +1,19 @@
+
+#ifndef __CMDSENDCONTINUOUS_H__
+#define __CMDSENDCONTINUOUS_H__
+
+#include "Command.h"
+
+class CmdSendContinuous : public Command {
+
+public:
+
+    CmdSendContinuous(mDot* dot, mts::MTSSerial& serial);
+    virtual uint32_t action(std::vector<std::string> args);
+    virtual bool verify(std::vector<std::string> args);
+    
+private:
+    mts::MTSSerial& _serial;
+};
+
+#endif // __CMDSENDCONTINUOUS_H__
--- a/CommandTerminal/CmdSendString.cpp	Tue Aug 18 15:58:59 2015 +0000
+++ b/CommandTerminal/CmdSendString.cpp	Tue Aug 18 11:21:43 2015 -0500
@@ -54,8 +54,8 @@
 
     if (args.size() >= 2) {
         size_t size = 0;
-        for (int i = 1; i < args.size(); i++)
-            size += args[i].size();
+        for (int i = 1; i < args.size() - 1; i++)
+            size += args[i].size() + 1;
         if (size > 242) {
             setErrorMessage("Invalid packet, expects (string:242)");
             return false;
--- a/CommandTerminal/CmdSendStringOnInterval.cpp	Tue Aug 18 15:58:59 2015 +0000
+++ b/CommandTerminal/CmdSendStringOnInterval.cpp	Tue Aug 18 11:21:43 2015 -0500
@@ -104,8 +104,8 @@
             return false;
         }
 
-        for (int i = 2; i < args.size(); i++)
-            size += args[i].size();
+        for (int i = 2; i < args.size() - 1; i++)
+            size += args[i].size() + 1;
         if (size > 242) {
             setErrorMessage("Invalid packet, expects (string:242)");
             return false;
--- a/CommandTerminal/CmdSerialReceiveTimeout.cpp	Tue Aug 18 15:58:59 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,59 +0,0 @@
-#include "CmdSerialReceiveTimeout.h"
-
-CmdSerialReceiveTimeout::CmdSerialReceiveTimeout(mDot* dot, mts::MTSSerial& serial) :
-        Command(dot, "Serial Receive Timeout", "AT+SDTO", "Read serial data until timeout (milliseconds)"), _serial(serial)
-{
-    _help = std::string(text()) + ": " + std::string(desc());
-    _usage = "(0-65000) ms";
-    _queryable = true;
-}
-
-uint32_t CmdSerialReceiveTimeout::action(std::vector<std::string> args)
-{
-    if (args.size() == 1)
-    {
-        if (_dot->getVerbose())
-            _serial.writef("%s: ", name());
-
-        _serial.writef("%lu\r\n", _dot->getSerialReceiveTimeout());
-    }
-    else if (args.size() == 2)
-    {
-        int32_t code;
-        uint32_t timeout;
-        sscanf(args[1].c_str(), "%lu", &timeout);
-
-        if ((code = _dot->setSerialReceiveTimeout(timeout)) != mDot::MDOT_OK) {
-            std::string error = mDot::getReturnCodeString(code) + " - " + _dot->getLastError();
-            setErrorMessage(error);
-            return 1;
-        }
-    }
-
-    return 0;
-}
-
-bool CmdSerialReceiveTimeout::verify(std::vector<std::string> args)
-{
-    if (args.size() == 1)
-        return true;
-
-    if (args.size() == 2)
-    {
-        uint32_t timeout;
-        if (sscanf(args[1].c_str(), "%lu", &timeout) != 1) {
-            setErrorMessage("Invalid argument");
-            return false;
-        }
-
-        if (timeout < 0 || timeout > 65000) {
-            setErrorMessage("Invalid timeout, expects (0-65000) ms");
-            return false;
-        }
-
-        return true;
-    }
-
-    setErrorMessage("Invalid arguments");
-    return false;
-}
--- a/CommandTerminal/CmdSerialReceiveTimeout.h	Tue Aug 18 15:58:59 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,21 +0,0 @@
-
-#ifndef __CMDSERIALRECEIVETIMEOUT_H__
-#define __CMDSERIALRECEIVETIMEOUT_H__
-
-#include "Command.h"
-
-class CommandTerminal;
-
-class CmdSerialReceiveTimeout : public Command {
-
-public:
-
-    CmdSerialReceiveTimeout(mDot* dot, mts::MTSSerial& serial);
-    virtual uint32_t action(std::vector<std::string> args);
-    virtual bool verify(std::vector<std::string> args);
-    
-private:   
-    mts::MTSSerial& _serial;
-};
-
-#endif // __CMDSERIALRECEIVETIMEOUT_H__
--- a/CommandTerminal/CmdSerialWakeDelay.cpp	Tue Aug 18 15:58:59 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,60 +0,0 @@
-#include "CmdSerialWakeDelay.h"
-
-CmdSerialWakeDelay::CmdSerialWakeDelay(mDot* dot, mts::MTSSerial& serial) :
-        Command(dot, "Serial Wake Delay", "AT+SDWD", "Time to wait for data after wakeup signal  (milliseconds)"),
-        _serial(serial)
-{
-    _help = std::string(text()) + ": " + std::string(desc());
-    _usage = "(2-2147483647) ms";
-    _queryable = true;
-}
-
-uint32_t CmdSerialWakeDelay::action(std::vector<std::string> args)
-{
-    if (args.size() == 1)
-    {
-        if (_dot->getVerbose())
-            _serial.writef("%s: ", name());
-
-        _serial.writef("%lu\r\n", _dot->getSerialWakeDelay());
-    }
-    else if (args.size() == 2)
-    {
-        int32_t code;
-        uint32_t delay;
-        sscanf(args[1].c_str(), "%lu", &delay);
-
-        if ((code = _dot->setSerialWakeDelay(delay)) != mDot::MDOT_OK) {
-            std::string error = mDot::getReturnCodeString(code) + " - " + _dot->getLastError();
-            setErrorMessage(error);
-            return 1;
-        }
-    }
-
-    return 0;
-}
-
-bool CmdSerialWakeDelay::verify(std::vector<std::string> args)
-{
-    if (args.size() == 1)
-        return true;
-
-    if (args.size() == 2)
-    {
-        uint32_t delay;
-        if (sscanf(args[1].c_str(), "%lu", &delay) != 1) {
-            setErrorMessage("Invalid argument");
-            return false;
-        }
-
-        if (delay < 2 || delay > INT_MAX) {
-            setErrorMessage("Invalid delay, expects (2-2147483647) ms");
-            return false;
-        }
-
-        return true;
-    }
-
-    setErrorMessage("Invalid arguments");
-    return false;
-}
--- a/CommandTerminal/CmdSerialWakeDelay.h	Tue Aug 18 15:58:59 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,21 +0,0 @@
-
-#ifndef __CMDSERIALWAKEDELAY_H__
-#define __CMDSERIALWAKEDELAY_H__
-
-#include "Command.h"
-
-class CommandTerminal;
-
-class CmdSerialWakeDelay : public Command {
-
-public:
-
-    CmdSerialWakeDelay(mDot* dot, mts::MTSSerial& serial);
-    virtual uint32_t action(std::vector<std::string> args);
-    virtual bool verify(std::vector<std::string> args);
-    
-private:   
-    mts::MTSSerial& _serial;
-};
-
-#endif // __CMDSERIALWAKEDELAY_H__
--- a/CommandTerminal/CmdSerialWakeInterval.cpp	Tue Aug 18 15:58:59 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,59 +0,0 @@
-#include "CmdSerialWakeInterval.h"
-
-CmdSerialWakeInterval::CmdSerialWakeInterval(mDot* dot, mts::MTSSerial& serial) :
-        Command(dot, "Serial Wake Interval", "AT+SDWI", "Serial data wakeup interval to generate wake signal (seconds)"),
-        _serial(serial)
-{
-    _help = std::string(text()) + ": " + std::string(desc());
-    _usage = "(2-2147483647) s";
-    _queryable = true;
-}
-
-uint32_t CmdSerialWakeInterval::action(std::vector<std::string> args)
-{
-    if (args.size() == 1)
-    {
-        if (_dot->getVerbose())
-            _serial.writef("%s: ", name());
-
-        _serial.writef("%lu\r\n", _dot->getSerialWakeInterval());
-    }
-    else if (args.size() == 2)
-    {
-        int32_t code;
-        uint32_t timeout;
-        sscanf(args[1].c_str(), "%lu", &timeout);
-
-        if ((code = _dot->setSerialWakeInterval(timeout)) != mDot::MDOT_OK) {
-            std::string error = mDot::getReturnCodeString(code) + " - " + _dot->getLastError();
-            setErrorMessage(error);
-            return 1;
-        }
-    }
-
-    return 0;
-}
-
-bool CmdSerialWakeInterval::verify(std::vector<std::string> args)
-{
-    if (args.size() == 1)
-        return true;
-    
-    if (args.size() == 2) {
-        uint32_t timeout;
-        if (sscanf(args[1].c_str(), "%lu", &timeout) != 1) {
-            setErrorMessage("Invalid argument");
-            return false;
-        }
-
-        if (timeout < 2 || timeout > INT_MAX) {
-            setErrorMessage("Invalid interval, expects (2-2147483647) s");
-            return false;
-        }
-
-        return true;
-    }
-
-    setErrorMessage("Invalid arguments");
-    return false;
-}
--- a/CommandTerminal/CmdSerialWakeInterval.h	Tue Aug 18 15:58:59 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,21 +0,0 @@
-
-#ifndef __CMDSERIALWAKEINTERVAL_H__
-#define __CMDSERIALWAKEINTERVAL_H__
-
-#include "Command.h"
-
-class CommandTerminal;
-
-class CmdSerialWakeInterval : public Command {
-
-public:
-
-    CmdSerialWakeInterval(mDot* dot, mts::MTSSerial& serial);
-    virtual uint32_t action(std::vector<std::string> args);
-    virtual bool verify(std::vector<std::string> args);
-    
-private:   
-    mts::MTSSerial& _serial;
-};
-
-#endif // __CMDSERIALWAKEINTERVAL_H__
--- a/CommandTerminal/CmdTxWait.cpp	Tue Aug 18 15:58:59 2015 +0000
+++ b/CommandTerminal/CmdTxWait.cpp	Tue Aug 18 11:21:43 2015 -0500
@@ -1,7 +1,7 @@
 #include "CmdTxWait.h"
 
 CmdTxWait::CmdTxWait(mDot* dot, mts::MTSSerial& serial) :
-        Command(dot, "Tx wait", "AT+TXW", "Enable/disable waiting for rx windows to expire after send. (0: off, 1: on)"), _serial(serial)
+        Command(dot, "Tx Wait", "AT+TXW", "Enable/disable waiting for rx windows to expire after send. (0: off, 1: on)"), _serial(serial)
 {
     _help = std::string(text()) + ": " + std::string(desc());
     _usage = "(0,1)";
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CommandTerminal/CmdWakeDelay.cpp	Tue Aug 18 11:21:43 2015 -0500
@@ -0,0 +1,60 @@
+#include "CmdWakeDelay.h"
+
+CmdWakeDelay::CmdWakeDelay(mDot* dot, mts::MTSSerial& serial) :
+        Command(dot, "Wake Delay", "AT+WD", "Time to wait for data after wakeup signal  (milliseconds)"),
+        _serial(serial)
+{
+    _help = std::string(text()) + ": " + std::string(desc());
+    _usage = "(2-2147483647) ms";
+    _queryable = true;
+}
+
+uint32_t CmdWakeDelay::action(std::vector<std::string> args)
+{
+    if (args.size() == 1)
+    {
+        if (_dot->getVerbose())
+            _serial.writef("%s: ", name());
+
+        _serial.writef("%lu\r\n", _dot->getWakeDelay());
+    }
+    else if (args.size() == 2)
+    {
+        int32_t code;
+        uint32_t delay;
+        sscanf(args[1].c_str(), "%lu", &delay);
+
+        if ((code = _dot->setWakeDelay(delay)) != mDot::MDOT_OK) {
+            std::string error = mDot::getReturnCodeString(code) + " - " + _dot->getLastError();
+            setErrorMessage(error);
+            return 1;
+        }
+    }
+
+    return 0;
+}
+
+bool CmdWakeDelay::verify(std::vector<std::string> args)
+{
+    if (args.size() == 1)
+        return true;
+
+    if (args.size() == 2)
+    {
+        uint32_t delay;
+        if (sscanf(args[1].c_str(), "%lu", &delay) != 1) {
+            setErrorMessage("Invalid argument");
+            return false;
+        }
+
+        if (delay < 2 || delay > INT_MAX) {
+            setErrorMessage("Invalid delay, expects (2-2147483647) ms");
+            return false;
+        }
+
+        return true;
+    }
+
+    setErrorMessage("Invalid arguments");
+    return false;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CommandTerminal/CmdWakeDelay.h	Tue Aug 18 11:21:43 2015 -0500
@@ -0,0 +1,21 @@
+
+#ifndef __CMDWAKEDELAY_H__
+#define __CMDWAKEDELAY_H__
+
+#include "Command.h"
+
+class CommandTerminal;
+
+class CmdWakeDelay : public Command {
+
+public:
+
+    CmdWakeDelay(mDot* dot, mts::MTSSerial& serial);
+    virtual uint32_t action(std::vector<std::string> args);
+    virtual bool verify(std::vector<std::string> args);
+    
+private:   
+    mts::MTSSerial& _serial;
+};
+
+#endif // __CMDWAKEDELAY_H__
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CommandTerminal/CmdWakeInterval.cpp	Tue Aug 18 11:21:43 2015 -0500
@@ -0,0 +1,59 @@
+#include "CmdWakeInterval.h"
+
+CmdWakeInterval::CmdWakeInterval(mDot* dot, mts::MTSSerial& serial) :
+        Command(dot, "Wake Interval", "AT+WI", "Wakeup interval (seconds)"),
+        _serial(serial)
+{
+    _help = std::string(text()) + ": " + std::string(desc());
+    _usage = "(2-2147483647) s";
+    _queryable = true;
+}
+
+uint32_t CmdWakeInterval::action(std::vector<std::string> args)
+{
+    if (args.size() == 1)
+    {
+        if (_dot->getVerbose())
+            _serial.writef("%s: ", name());
+
+        _serial.writef("%lu\r\n", _dot->getWakeInterval());
+    }
+    else if (args.size() == 2)
+    {
+        int32_t code;
+        uint32_t timeout;
+        sscanf(args[1].c_str(), "%lu", &timeout);
+
+        if ((code = _dot->setWakeInterval(timeout)) != mDot::MDOT_OK) {
+            std::string error = mDot::getReturnCodeString(code) + " - " + _dot->getLastError();
+            setErrorMessage(error);
+            return 1;
+        }
+    }
+
+    return 0;
+}
+
+bool CmdWakeInterval::verify(std::vector<std::string> args)
+{
+    if (args.size() == 1)
+        return true;
+    
+    if (args.size() == 2) {
+        uint32_t timeout;
+        if (sscanf(args[1].c_str(), "%lu", &timeout) != 1) {
+            setErrorMessage("Invalid argument");
+            return false;
+        }
+
+        if (timeout < 2 || timeout > INT_MAX) {
+            setErrorMessage("Invalid interval, expects (2-2147483647) s");
+            return false;
+        }
+
+        return true;
+    }
+
+    setErrorMessage("Invalid arguments");
+    return false;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CommandTerminal/CmdWakeInterval.h	Tue Aug 18 11:21:43 2015 -0500
@@ -0,0 +1,21 @@
+
+#ifndef __CMDWAKEINTERVAL_H__
+#define __CMDWAKEINTERVAL_H__
+
+#include "Command.h"
+
+class CommandTerminal;
+
+class CmdWakeInterval : public Command {
+
+public:
+
+    CmdWakeInterval(mDot* dot, mts::MTSSerial& serial);
+    virtual uint32_t action(std::vector<std::string> args);
+    virtual bool verify(std::vector<std::string> args);
+    
+private:   
+    mts::MTSSerial& _serial;
+};
+
+#endif // __CMDWAKEINTERVAL_H__
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CommandTerminal/CmdWakeMode.cpp	Tue Aug 18 11:21:43 2015 -0500
@@ -0,0 +1,59 @@
+#include "CmdWakeMode.h"
+
+CmdWakeMode::CmdWakeMode(mDot* dot, mts::MTSSerial& serial) :
+        Command(dot, "Wake Mode", "AT+WM", "Wakeup mode, INTERRUPT uses DIO7 as wake-up pin (0:INTERVAL,1:INTERRUPT)"),
+        _serial(serial)
+{
+    _help = std::string(text()) + ": " + std::string(desc());
+    _usage = "(0:INTERVAL,1:INTERRUPT)";
+    _queryable = true;
+}
+
+uint32_t CmdWakeMode::action(std::vector<std::string> args)
+{
+    if (args.size() == 1)
+    {
+        if (_dot->getVerbose())
+            _serial.writef("%s: ", name());
+
+        _serial.writef("%lu\r\n", _dot->getWakeMode());
+    }
+    else if (args.size() == 2)
+    {
+        int32_t code;
+        uint32_t mode;
+        sscanf(args[1].c_str(), "%lu", &mode);
+
+        if ((code = _dot->setWakeMode(mode)) != mDot::MDOT_OK) {
+            std::string error = mDot::getReturnCodeString(code) + " - " + _dot->getLastError();
+            setErrorMessage(error);
+            return 1;
+        }
+    }
+
+    return 0;
+}
+
+bool CmdWakeMode::verify(std::vector<std::string> args)
+{
+    if (args.size() == 1)
+        return true;
+    
+    if (args.size() == 2) {
+        uint32_t mode;
+        if (sscanf(args[1].c_str(), "%lu", &mode) != 1) {
+            setErrorMessage("Invalid argument");
+            return false;
+        }
+
+        if (mode != 0 && mode != 1) {
+            setErrorMessage("Invalid interval, expects (0:INTERVAL,1:INTERRUPT)");
+            return false;
+        }
+
+        return true;
+    }
+
+    setErrorMessage("Invalid arguments");
+    return false;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CommandTerminal/CmdWakeMode.h	Tue Aug 18 11:21:43 2015 -0500
@@ -0,0 +1,21 @@
+
+#ifndef __CMDWAKEMODE_H__
+#define __CMDWAKEMODE_H__
+
+#include "Command.h"
+
+class CommandTerminal;
+
+class CmdWakeMode : public Command {
+
+public:
+
+    CmdWakeMode(mDot* dot, mts::MTSSerial& serial);
+    virtual uint32_t action(std::vector<std::string> args);
+    virtual bool verify(std::vector<std::string> args);
+    
+private:   
+    mts::MTSSerial& _serial;
+};
+
+#endif // __CMDWAKEMODE_H__
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CommandTerminal/CmdWakePin.cpp	Tue Aug 18 11:21:43 2015 -0500
@@ -0,0 +1,50 @@
+#include "CmdWakePin.h"
+
+CmdWakePin::CmdWakePin(mDot* dot, mts::MTSSerial& serial)
+:
+  Command(dot, "Wake Pin", "AT+WP", "Wakeup DIO pin of sleep mode (default: DI8), deep-sleep uses DIO7"),
+  _serial(serial) {
+    _help = std::string(text()) + ": " + std::string(desc());
+    _usage = "(2-8)";
+    _queryable = true;
+}
+
+uint32_t CmdWakePin::action(std::vector<std::string> args) {
+    if (args.size() == 1) {
+        if (_dot->getVerbose())
+            _serial.writef("%s: ", name());
+
+        _serial.writef("%s\r\n", mDot::pinName2Str(_dot->getWakePin()).c_str());
+    } else if (args.size() == 2) {
+        int32_t code;
+        uint32_t pin;
+        sscanf(args[1].c_str(), "%lu", &pin);
+
+        _dot->setWakePin(mDot::pinNum2Name(pin));
+    }
+
+    return 0;
+}
+
+bool CmdWakePin::verify(std::vector<std::string> args) {
+    if (args.size() == 1)
+        return true;
+
+    if (args.size() == 2) {
+        uint32_t pin;
+        if (sscanf(args[1].c_str(), "%lu", &pin) != 1) {
+            setErrorMessage("Invalid argument");
+            return false;
+        }
+
+        if (pin < 2 || pin > 8) {
+            setErrorMessage("Invalid pin, expects (2-8)");
+            return false;
+        }
+
+        return true;
+    }
+
+    setErrorMessage("Invalid arguments");
+    return false;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CommandTerminal/CmdWakePin.h	Tue Aug 18 11:21:43 2015 -0500
@@ -0,0 +1,21 @@
+
+#ifndef __CMDWAKEPIN_H__
+#define __CMDWAKEPIN_H__
+
+#include "Command.h"
+
+class CommandTerminal;
+
+class CmdWakePin : public Command {
+
+public:
+
+    CmdWakePin(mDot* dot, mts::MTSSerial& serial);
+    virtual uint32_t action(std::vector<std::string> args);
+    virtual bool verify(std::vector<std::string> args);
+    
+private:   
+    mts::MTSSerial& _serial;
+};
+
+#endif // __CMDWAKEPIN_H__
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CommandTerminal/CmdWakeTimeout.cpp	Tue Aug 18 11:21:43 2015 -0500
@@ -0,0 +1,59 @@
+#include "CmdWakeTimeout.h"
+
+CmdWakeTimeout::CmdWakeTimeout(mDot* dot, mts::MTSSerial& serial) :
+        Command(dot, "Wake Timeout", "AT+WTO", "Read serial data until timeout (milliseconds)"), _serial(serial)
+{
+    _help = std::string(text()) + ": " + std::string(desc());
+    _usage = "(0-65000) ms";
+    _queryable = true;
+}
+
+uint32_t CmdWakeTimeout::action(std::vector<std::string> args)
+{
+    if (args.size() == 1)
+    {
+        if (_dot->getVerbose())
+            _serial.writef("%s: ", name());
+
+        _serial.writef("%lu\r\n", _dot->getWakeTimeout());
+    }
+    else if (args.size() == 2)
+    {
+        int32_t code;
+        uint32_t timeout;
+        sscanf(args[1].c_str(), "%lu", &timeout);
+
+        if ((code = _dot->setWakeTimeout(timeout)) != mDot::MDOT_OK) {
+            std::string error = mDot::getReturnCodeString(code) + " - " + _dot->getLastError();
+            setErrorMessage(error);
+            return 1;
+        }
+    }
+
+    return 0;
+}
+
+bool CmdWakeTimeout::verify(std::vector<std::string> args)
+{
+    if (args.size() == 1)
+        return true;
+
+    if (args.size() == 2)
+    {
+        uint32_t timeout;
+        if (sscanf(args[1].c_str(), "%lu", &timeout) != 1) {
+            setErrorMessage("Invalid argument");
+            return false;
+        }
+
+        if (timeout < 0 || timeout > 65000) {
+            setErrorMessage("Invalid timeout, expects (0-65000) ms");
+            return false;
+        }
+
+        return true;
+    }
+
+    setErrorMessage("Invalid arguments");
+    return false;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CommandTerminal/CmdWakeTimeout.h	Tue Aug 18 11:21:43 2015 -0500
@@ -0,0 +1,21 @@
+
+#ifndef __CMDWAKETIMEOUT_H__
+#define __CMDWAKETIMEOUT_H__
+
+#include "Command.h"
+
+class CommandTerminal;
+
+class CmdWakeTimeout : public Command {
+
+public:
+
+    CmdWakeTimeout(mDot* dot, mts::MTSSerial& serial);
+    virtual uint32_t action(std::vector<std::string> args);
+    virtual bool verify(std::vector<std::string> args);
+    
+private:   
+    mts::MTSSerial& _serial;
+};
+
+#endif // __CMDWAKETIMEOUT_H__
--- a/CommandTerminal/CommandTerminal.cpp	Tue Aug 18 15:58:59 2015 +0000
+++ b/CommandTerminal/CommandTerminal.cpp	Tue Aug 18 11:21:43 2015 -0500
@@ -1,12 +1,10 @@
 #include "ctype.h"
 #include "CommandTerminal.h"
 #include "Command.h"
+#include "MTSLog.h"
 #include <cstdarg>
 
-extern "C" {
-#include "wakeup.h"
-    extern void pin_function(PinName pin, int data);
-}
+#include <deque>
 
 const char CommandTerminal::banner[] = "\r\n\nMultiTech Systems LoRa XBee Module\r\n\n";
 const char CommandTerminal::helpline[] = "Enter '?' for help\r\n";
@@ -36,14 +34,13 @@
   _serial(serial),
   _dot(dot),
   _mode(mDot::COMMAND_MODE),
-  _sleep_standby(false),
+  _idle_thread(idle, NULL, osPriorityLow),
+  _sleep_standby(true),
   _xbee_on_sleep(XBEE_ON_SLEEP),
   _serial_up(false) {
 
     _serialp = &serial;
 
-    wakeup_init(_dot->getSerialWakeInterval());
-
     addCommand(new CmdAttention(_dot));
     addCommand(new CmdIdentification(_dot, serial));
     addCommand(new CmdResetCpu(_dot, serial));
@@ -54,6 +51,7 @@
     addCommand(new CmdSaveConfig(_dot));
     addCommand(new CmdDisplayConfig(_dot, serial));
     addCommand(new CmdDisplayStats(_dot, serial));
+    addCommand(new CmdResetStats(_dot, serial));
     addCommand(new CmdSerialBaudRate(_dot, serial));
     addCommand(new CmdDebugBaudRate(_dot, serial));
     addCommand(new CmdStartUpMode(_dot, serial));
@@ -71,6 +69,7 @@
 
     addCommand(new CmdJoinRequest(_dot, serial));
     addCommand(new CmdJoinRetries(_dot, serial));
+    addCommand(new CmdJoinByteOrder(_dot, serial));
     addCommand(new CmdNetworkJoinMode(_dot, serial));
     addCommand(new CmdNetworkJoinStatus(_dot, serial));
     addCommand(new CmdNetworkLinkCheck(_dot, serial));
@@ -109,10 +108,13 @@
     addCommand(new CmdReceiveOnce(_dot, serial));
     addCommand(new CmdReceiveContinuous(_dot, serial));
 
-    addCommand(new CmdDummy(_dot, "Serial Data Mode", "AT+SD", "Reads serial data and sends Lora packets (escape sequence: +++)"));
-    addCommand(new CmdSerialWakeInterval(_dot, serial));
-    addCommand(new CmdSerialWakeDelay(_dot, serial));
-    addCommand(new CmdSerialReceiveTimeout(_dot, serial));
+    addCommand(new CmdDummy(_dot, "Serial Data Mode", "AT+SD", "Reads serial data, sends packet, then sleeps using wake settings"));
+    addCommand(new CmdDummy(_dot, "Sleep Mode", "AT+SLEEP", "Enter sleep mode"));
+    addCommand(new CmdWakeMode(_dot, serial));
+    addCommand(new CmdWakeInterval(_dot, serial));
+    // addCommand(new CmdWakePin(_dot, serial));
+    addCommand(new CmdWakeDelay(_dot, serial));
+    addCommand(new CmdWakeTimeout(_dot, serial));
     addCommand(new CmdPing(_dot, serial));
     addCommand(new CmdLogLevel(_dot, serial));
 }
@@ -233,10 +235,11 @@
     }
 
     if (_serial_up) {
-        osDelay(_dot->getSerialWakeDelay());
+        osDelay(_dot->getWakeDelay());
 
         serial_read_timer.start();
-        while (_serial_up && serial_read_timer.read_ms() < _dot->getSerialReceiveTimeout()) {
+        uint16_t timeout = _dot->getWakeTimeout();
+        while (_serial_up && serial_read_timer.read_ms() < timeout) {
             while (readable() && serial_buffer.size() < max_send_size) {
                 serial_buffer.push_back(read());
                 serial_read_timer.reset();
@@ -251,7 +254,7 @@
                 std::vector<uint8_t> recv_buffer;
                 DEBUG_PRINTF("Received serial data, sending out radio.\r\n");
 
-                if (!_dot->send(serial_buffer))
+                if (_dot->send(serial_buffer) != mDot::MDOT_OK)
                     DEBUG_PRINTF("Send failed.\r\n");
                 if (_dot->recv(recv_buffer))
                     _serial.writef("%s\r\n", formatPacketData(recv_buffer, _dot->getRxOutput()).c_str());
@@ -352,12 +355,14 @@
 
 void CommandTerminal::start() {
 
-    _dot->resetNetworkSession();
+    wakeup(_sleep_standby);
 
     char ch;
     bool running = true;
     bool echo = _dot->getEcho();
     std::string command;
+    std::deque<std::string> history;
+    int history_index = -1;
     std::vector<std::string> args;
 
     if (_dot->getStartUpMode() == mDot::SERIAL_MODE) {
@@ -423,12 +428,54 @@
         if (readable()) {
             ch = read();
 
-            if (ch == '\b') {
+            if (ch == '\b' || ch == 0x7f) {
                 if (!command.empty()) {
                     writef("\b \b");
                     command.erase(command.size() - 1);
                 }
                 continue;
+            } else if (ch == 0x1b || ch == 0x09) {
+                osDelay(20);
+                // catch escape sequence, or tab
+                char ch1, ch2;
+
+                if (readable()) {
+                    ch1 = read();
+                    if (readable())
+                        ch2 = read();
+
+                    if (ch1 == 0x5b && ch2 == 0x41) {
+                        // up key
+                        for (int i = 0; i < command.size()+1; i++) {
+                            writef("\b \b");
+                        }
+                        if (history.size() > 0) {
+                            if (++history_index >= history.size() - 1)
+                                history_index = history.size() - 1;
+
+                            command = history[history_index];
+                            writef("%s", history[history_index].c_str());
+                        } else {
+                            command.clear();
+                        }
+                    } else if (ch1 == 0x5b && ch2 == 0x42) {
+
+                        // down key
+                        for (int i = 0; i < command.size()+1; i++) {
+                            writef("\b \b");
+                        }
+
+                        if (--history_index < 0) {
+                            history_index = -1;
+                            command.clear();
+                        } else {
+                            command = history[history_index];
+                            writef("%s", history[history_index].c_str());
+                        }
+                    }
+                }
+                while (readable()) read();
+                continue;
             } else {
                 command += ch;
             }
@@ -501,6 +548,21 @@
         } else if (args[0] == "AT+SD") {
             DEBUG_PRINTF("Enter Serial Mode\r\n");
             _mode = mDot::SERIAL_MODE;
+        } else if (args[0] == "AT+SLEEP") {
+            if (args.size() > 1 && (args[1] != "?")) {
+                write("Invalid argument\r\n");
+                write(error);
+            } else {
+                if (args.size() > 1 && args[1] == "?") {
+                    write("AT+SLEEP: NONE\r\n");
+                    write(done);
+                } else {
+                    _sleep_standby = !(args.size() > 1 && args[1] == "1");
+                    this->sleep(_sleep_standby);
+                    wait(0.1);
+                    write(done);
+                }
+            }
         } else {
             bool found = false;
             bool query = false;
@@ -552,8 +614,13 @@
             }
         }
 
+        if (history.size() == 0 || history.front() != command)
+            history.push_front(command);
+        history_index = -1;
         command.clear();
 
+        while (history.size() > 10)
+            history.pop_back();
     }
 }
 
@@ -568,65 +635,10 @@
     _serial_up = false;
     _xbee_on_sleep = GPIO_PIN_RESET;
 
-    HAL_PWREx_EnableMainRegulatorLowVoltage();
-    HAL_PWREx_EnableFlashPowerDown();
-    HAL_PWREx_EnableLowRegulatorLowVoltage();
-
-    DEBUG_PRINTF("Sleep\r\n");
-    _dot->sleep();
-
-    if (standby) {
-
-        DEBUG_PRINTF("RECORD UPLINK: %lu\r\n", _dot->getUpLinkCounter());
-
-        RTC_WriteBackupRegister(RTC_BKP_DR0, _dot->getUpLinkCounter());
-
-        HAL_PWR_EnableBkUpAccess();
-
-        HAL_EnableDBGStandbyMode();
-
-        HAL_PWR_DisableWakeUpPin (PWR_WAKEUP_PIN1);
-
-        __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); // InterruptIn wakeon_serial(XBEE_DIN);
-        // Application is reloaded after wake-up from standby
-HAL_PWR_EnterSTANDBYMode        ();
+    _serial.rxClear();
+    _serial.txClear();
 
-    } else {
-        pin_function(PA_0, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0));
-        pin_function(PA_1, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0));
-        // pin_function(PA_2, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0));
-        // pin_function(PA_3, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0));
-        pin_function(PA_4, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0));
-        pin_function(PA_5, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0));
-        pin_function(PA_6, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0));
-        pin_function(PA_7, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0));
-        // pin_function(PA_8, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0));
-        // pin_function(PA_9, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0));
-        // pin_function(PA_10, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0));
-        pin_function(PA_11, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0));
-        pin_function(PA_12, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0));
-        pin_function(PA_15, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0));
-
-        pin_function(PB_0, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0));
-        pin_function(PB_1, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0));
-        pin_function(PB_2, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0));
-
-        pin_function(PC_1, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0));
-        pin_function(PC_4, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0));
-        pin_function(PC_5, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0));
-        pin_function(PC_9, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0));
-        // pin_function(PC_13, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0));
-
-        pin_function(PD_2, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0));
-
-        HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
-    }
-
-    wakeup_clear();
-    EXTI->PR = (1 << 22);
-
-    // After wake-up from STOP reconfigure the PLL
-    SetSysClock();
+    _dot->sleep(_dot->getWakeInterval(), _dot->getWakeMode(), standby);
 }
 
 bool CommandTerminal::waitForEscape(int timeout, mDot* dot, WaitType wait) {
@@ -665,16 +677,5 @@
 }
 
 void CommandTerminal::wakeup(bool standby) {
-    HAL_PWREx_DisableMainRegulatorLowVoltage();
-    HAL_PWREx_DisableFlashPowerDown();
-    HAL_PWREx_DisableLowRegulatorLowVoltage();
-
-    if (standby) {
-        HAL_DisableDBGStandbyMode();
-
-        HAL_PWR_EnableWakeUpPin (PWR_WAKEUP_PIN1);
-    }
-
-    _dot->wakeup();
 
 }
--- a/CommandTerminal/CommandTerminal.h	Tue Aug 18 15:58:59 2015 +0000
+++ b/CommandTerminal/CommandTerminal.h	Tue Aug 18 11:21:43 2015 -0500
@@ -80,12 +80,18 @@
     
 private: 
 
+    static void idle(void const* args) {
+        while (1)
+            __WFI();
+    }
+
     mts::MTSSerial& _serial;
     static mts::MTSSerial* _serialp;
 
     mDot* _dot;
     mDot::Mode _mode;
     std::vector<Command*> _commands;
+    Thread _idle_thread;
     bool _sleep_standby;
     DigitalOut _xbee_on_sleep;
     bool _serial_up;
--- a/CommandTerminal/Commands.h	Tue Aug 18 15:58:59 2015 +0000
+++ b/CommandTerminal/Commands.h	Tue Aug 18 11:21:43 2015 -0500
@@ -11,6 +11,7 @@
 #include "CmdSaveConfig.h"
 #include "CmdDisplayConfig.h"
 #include "CmdDisplayStats.h"
+#include "CmdResetStats.h"
 
 #include "CmdSerialBaudRate.h"
 #include "CmdDebugBaudRate.h"
@@ -25,6 +26,7 @@
 #include "CmdNetworkKey.h"
 #include "CmdNetworkId.h"
 #include "CmdJoinRequest.h"
+#include "CmdJoinByteOrder.h"
 #include "CmdJoinRetries.h"
 #include "CmdNetworkJoinMode.h"
 #include "CmdNetworkJoinStatus.h"
@@ -61,15 +63,19 @@
 #include "CmdSendStringOnInterval.h"
 #include "CmdReceiveOnce.h"
 #include "CmdReceiveContinuous.h"
+#include "CmdPing.h"
 
 // Serial Data Mode built into command terminal
-#include "CmdSerialWakeInterval.h"
-#include "CmdSerialWakeDelay.h"
-#include "CmdSerialReceiveTimeout.h"
-#include "CmdPing.h"
+// Sleep built into command terminal
+#include "CmdWakeInterval.h"
+#include "CmdWakePin.h"
+#include "CmdWakeMode.h"
+#include "CmdWakeDelay.h"
+#include "CmdWakeTimeout.h"
 
 #include "CmdLogLevel.h"
 
 // Radio debug commands
 
 #include "CmdTxFrequency.h"
+#include "CmdSendContinuous.h"
--- a/main.cpp	Tue Aug 18 15:58:59 2015 +0000
+++ b/main.cpp	Tue Aug 18 11:21:43 2015 -0500
@@ -1,29 +1,21 @@
-#include "mbed.h"
-#include "mDot.h"
-#include "CommandTerminal.h"
-
-Serial debug(USBTX, USBRX);
-
-mts::MTSSerial serial(XBEE_DOUT, XBEE_DIN, 512, 512);
-DigitalOut led(LED1);
-Ticker tick;
-
-void tock() {
-    led = !led;
-}
-
-int main()
-{
-    debug.baud(115200);
-
-    tick.attach(&tock, 0.5);
-
-    mDot* dot = mDot::getInstance();
-
-    debug.baud(dot->getDebugBaud());
-    serial.baud(dot->getBaud());
-
-    CommandTerminal term(serial, dot);
-
-    term.start();
+#include "mbed.h"
+#include "mDot.h"
+#include "CommandTerminal.h"
+
+Serial debug(USBTX, USBRX);
+
+mts::MTSSerial serial(XBEE_DOUT, XBEE_DIN, 512, 512);
+
+int main()
+{
+    debug.baud(115200);
+
+    mDot* dot = mDot::getInstance();
+
+    debug.baud(dot->getDebugBaud());
+    serial.baud(dot->getBaud());
+
+    CommandTerminal term(serial, dot);
+
+    term.start();
 }
--- a/version.h	Tue Aug 18 15:58:59 2015 +0000
+++ b/version.h	Tue Aug 18 11:21:43 2015 -0500
@@ -1,6 +1,6 @@
-#ifndef __VERSION_H__
-#define __VERSION_H__
-
-#define AT_APPLICATION_VERSION "060215_mbed-23-g6d77074"
-
+#ifndef __VERSION_H__
+#define __VERSION_H__
+
+#define AT_APPLICATION_VERSION "0.1.2-mbed"
+
 #endif