summaryrefslogtreecommitdiff
path: root/CommandTerminal
diff options
context:
space:
mode:
authorLeon Lindenfelser <llindenfelser@multitech.com>2015-11-20 16:21:44 -0600
committerLeon Lindenfelser <llindenfelser@multitech.com>2015-11-20 16:21:44 -0600
commit4ea46cbfee73c43579ea657cabc7f1fc7de97874 (patch)
tree96c7451f54600d847e7d0231090bb79d02f0ac50 /CommandTerminal
parent393317f7d04753d6e9773393a96c311a88a27f7b (diff)
downloadmtdot-box-evb-factory-firmware-4ea46cbfee73c43579ea657cabc7f1fc7de97874.tar.gz
mtdot-box-evb-factory-firmware-4ea46cbfee73c43579ea657cabc7f1fc7de97874.tar.bz2
mtdot-box-evb-factory-firmware-4ea46cbfee73c43579ea657cabc7f1fc7de97874.zip
1. Merged CommandTerminal into ModeConfig and deleted CommandTerminal.
2. Fixed AT&V output. 3. Cleaned up some unused code. 4. Added +FREQ back in. 5. Removed CmdExit and put the +EXIT command right in the command parsing code.
Diffstat (limited to 'CommandTerminal')
-rw-r--r--CommandTerminal/CmdData.h2
-rw-r--r--CommandTerminal/CmdDataSessionKey.h2
-rw-r--r--CommandTerminal/CmdDeleteSurveyDataFile.h2
-rw-r--r--CommandTerminal/CmdDeviceId.h2
-rw-r--r--CommandTerminal/CmdDisplayConfig.cpp71
-rw-r--r--CommandTerminal/CmdExit.cpp19
-rw-r--r--CommandTerminal/CmdExit.h20
-rw-r--r--CommandTerminal/CmdFactoryDefault.cpp2
-rw-r--r--CommandTerminal/CmdFrequencyBand.cpp63
-rw-r--r--CommandTerminal/CmdFrequencyBand.h21
-rw-r--r--CommandTerminal/CmdFrequencySubBand.h2
-rw-r--r--CommandTerminal/CmdGetSurveyDataFile.h2
-rw-r--r--CommandTerminal/CmdMaximumPower.h2
-rw-r--r--CommandTerminal/CmdMaximumSize.h2
-rw-r--r--CommandTerminal/CmdMinimumPower.h2
-rw-r--r--CommandTerminal/CmdMinimumSize.h2
-rw-r--r--CommandTerminal/CmdNetworkAddress.h2
-rw-r--r--CommandTerminal/CmdNetworkId.h2
-rw-r--r--CommandTerminal/CmdNetworkJoinMode.h2
-rw-r--r--CommandTerminal/CmdNetworkKey.h2
-rw-r--r--CommandTerminal/CmdNetworkSessionKey.h2
-rw-r--r--CommandTerminal/CmdPublicNetwork.h2
-rw-r--r--CommandTerminal/CmdTxDataRate.h2
-rw-r--r--CommandTerminal/CmdTxPower.h2
-rw-r--r--CommandTerminal/CommandTerminal.cpp343
-rw-r--r--CommandTerminal/CommandTerminal.h111
-rw-r--r--CommandTerminal/Commands.h2
27 files changed, 117 insertions, 571 deletions
diff --git a/CommandTerminal/CmdData.h b/CommandTerminal/CmdData.h
index ac2a874..5fc2c87 100644
--- a/CommandTerminal/CmdData.h
+++ b/CommandTerminal/CmdData.h
@@ -3,7 +3,7 @@
#include "Command.h"
-class CommandTerminal;
+class ModeConfig;
class CmdData: public Command
{
diff --git a/CommandTerminal/CmdDataSessionKey.h b/CommandTerminal/CmdDataSessionKey.h
index 704af6e..350e8ab 100644
--- a/CommandTerminal/CmdDataSessionKey.h
+++ b/CommandTerminal/CmdDataSessionKey.h
@@ -3,7 +3,7 @@
#include "Command.h"
-class CommandTerminal;
+class ModeConfig;
class CmdDataSessionKey : public Command {
diff --git a/CommandTerminal/CmdDeleteSurveyDataFile.h b/CommandTerminal/CmdDeleteSurveyDataFile.h
index a0e1663..bfeeb29 100644
--- a/CommandTerminal/CmdDeleteSurveyDataFile.h
+++ b/CommandTerminal/CmdDeleteSurveyDataFile.h
@@ -3,7 +3,7 @@
#include "Command.h"
-class CommandTerminal;
+class ModeConfig;
class CmdDeleteSurveyDataFile: public Command
{
diff --git a/CommandTerminal/CmdDeviceId.h b/CommandTerminal/CmdDeviceId.h
index 9e1ad74..228a5a0 100644
--- a/CommandTerminal/CmdDeviceId.h
+++ b/CommandTerminal/CmdDeviceId.h
@@ -3,7 +3,7 @@
#include "Command.h"
-class CommandTerminal;
+class ModeConfig;
class CmdDeviceId : public Command {
diff --git a/CommandTerminal/CmdDisplayConfig.cpp b/CommandTerminal/CmdDisplayConfig.cpp
index 6ef6e92..2f11218 100644
--- a/CommandTerminal/CmdDisplayConfig.cpp
+++ b/CommandTerminal/CmdDisplayConfig.cpp
@@ -1,4 +1,7 @@
#include "CmdDisplayConfig.h"
+#include "version.h"
+
+std::string version = MTDOT_BOX_VERSION;
CmdDisplayConfig::CmdDisplayConfig(mDot* dot, mts::MTSSerial& serial)
:
@@ -9,6 +12,9 @@ CmdDisplayConfig::CmdDisplayConfig(mDot* dot, mts::MTSSerial& serial)
}
uint32_t CmdDisplayConfig::action(std::vector<std::string> args) {
+ _serial.writef("Firmware: \t\t%s\r\n", version.c_str());
+ _serial.writef("Library : \t\t%s\r\n", _dot->getId().c_str());
+
_serial.writef("Device ID:\t\t");
_serial.writef("%s\r\n", mts::Text::bin2hexString(_dot->getDeviceId(), ":").c_str());
@@ -16,7 +22,6 @@ uint32_t CmdDisplayConfig::action(std::vector<std::string> args) {
_serial.writef("Frequency Sub Band:\t%u\r\n", _dot->getFrequencySubBand());
_serial.writef("Public Network:\t\t%s\r\n", _dot->getPublicNetwork() ? "on" : "off");
- _serial.writef("Start Up Mode:\t\t%s\r\n", mDot::ModeStr(_dot->getStartUpMode()).c_str());
_serial.writef("Network Address:\t%s\r\n", mts::Text::bin2hexString(_dot->getNetworkAddress()).c_str());
@@ -38,68 +43,16 @@ uint32_t CmdDisplayConfig::action(std::vector<std::string> args) {
_serial.writef("Network Join Mode:\t%s\r\n", mDot::JoinModeStr(_dot->getJoinMode()).c_str());
- _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");
- } else {
- _serial.writef("%lu\r\n", _dot->getLinkCheckThreshold());
- }
-
- _serial.writef("Link Check Count:\t");
- if (_dot->getLinkCheckCount() == 0) {
- _serial.writef("off\r\n");
- } else {
- _serial.writef("%lu packets\r\n", _dot->getLinkCheckCount());
- }
-
- _serial.writef("Error Correction:\t");
- if (_dot->getFec() == 0) {
- _serial.writef("off\r\n");
- } else {
- _serial.writef("%u bytes\r\n", _dot->getFec());
- }
-
- _serial.writef("ACK Retries:\t\t");
- if (_dot->getAck() == 0) {
- _serial.writef("off\r\n");
- } else {
- _serial.writef("%u\r\n", _dot->getAck());
- }
-
- _serial.writef("Encryption:\t\t%s\r\n", _dot->getAesEncryption() ? "on" : "off");
- _serial.writef("CRC:\t\t\t%s\r\n", _dot->getCrc() ? "on" : "off");
- _serial.writef("Adaptive Data Rate:\t%s\r\n", _dot->getAdr() ? "on" : "off");
- _serial.writef("Command Echo:\t\t%s\r\n", _dot->getEcho() ? "on" : "off");
- _serial.writef("Verbose Response:\t%s\r\n", _dot->getVerbose() ? "on" : "off");
-
- _serial.writef("Tx Frequency:\t\t%lu\r\n", _dot->getTxFrequency());
_serial.writef("Tx Data Rate:\t\t%s\r\n", mDot::DataRateStr(_dot->getTxDataRate()).c_str());
_serial.writef("Tx Power:\t\t%u\r\n", _dot->getTxPower());
- _serial.writef("Tx Wait:\t\t%s\r\n", _dot->getTxWait() ? "on" : "off");
-
- _serial.writef("Tx Inverted Signal:\t%s\r\n", _dot->getTxInverted() ? "on" : "off");
-
- _serial.writef("Rx Frequency:\t\t%lu\r\n", _dot->getRxFrequency());
- _serial.writef("Rx Data Rate:\t\t%s\r\n", mDot::DataRateStr(_dot->getRxDataRate()).c_str());
- _serial.writef("Rx Inverted Signal:\t%s\r\n", _dot->getRxInverted() ? "on" : "off");
-
- _serial.writef("Rx Output Style:\t%s\r\n", mDot::RxOutputStr(_dot->getRxOutput()).c_str());
-
- _serial.writef("Debug Baud Rate:\t%lu\r\n", _dot->getDebugBaud());
- _serial.writef("Serial Baud Rate:\t%lu\r\n", _dot->getBaud());
-
- _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("Log Level:\t\t%ld\r\n", _dot->getLogLevel());
- //_serial.writef("Wake Pin:\t\t%s\r\n", mDot::pinName2Str(_dot->getWakePin()).c_str());
+ _serial.writef("Maximum Size:\t\t%u\r\n", _dot->getWakeDelay()); //DotBox +MaxSize is stored here.
+ _serial.writef("Minimum Size:\t\t%u\r\n", _dot->getWakeInterval()); //DotBox +MinSize is stored here.
+ _serial.writef("Maximum Power:\t\t%u\r\n", _dot->getWakeMode()); //DotBox +MaxPwr is stored here.
+ _serial.writef("Minimum Power:\t\t%u\r\n", _dot->getWakeTimeout()); //DotBox +MinPwr is stored here.
+ _serial.writef("Data:\t\t\t%d\r\n", _dot->getStartUpMode()); //DotBox +Data is stored here.
- _serial.writef("Log Level:\t\t%ld\r\n", _dot->getLogLevel());
return 0;
}
diff --git a/CommandTerminal/CmdExit.cpp b/CommandTerminal/CmdExit.cpp
deleted file mode 100644
index 46923b3..0000000
--- a/CommandTerminal/CmdExit.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-#include "CmdExit.h"
-
-CmdExit::CmdExit(mDot* dot, mts::MTSSerial& serial) :
- Command(dot, "Exit", "AT+EXIT", "Exit from command mode to main menu"), _serial(serial)
-{
- _help = std::string(text()) + ": " + std::string(desc());
-}
-
-uint32_t CmdExit::action(std::vector<std::string> args)
-{
-//ToDo: Probably setting or clearing a flag to indicate to some other task to shut down command mode and display the main menu.
- if (!_dot->saveConfig()) {
- setErrorMessage("Failed to save to flash");
- return 1;
- }
-
- return 0;
-
-}
diff --git a/CommandTerminal/CmdExit.h b/CommandTerminal/CmdExit.h
deleted file mode 100644
index 20231db..0000000
--- a/CommandTerminal/CmdExit.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#ifndef __CMDEXIT_H__
-#define __CMDEXIT_H__
-
-#include "Command.h"
-
-class CommandTerminal;
-
-class CmdExit: public Command
-{
-
-public:
-
- CmdExit(mDot* dot, mts::MTSSerial& serial);
- virtual uint32_t action(std::vector<std::string> args);
-
-private:
- mts::MTSSerial& _serial;
-};
-
-#endif // __CMDEXIT_H__
diff --git a/CommandTerminal/CmdFactoryDefault.cpp b/CommandTerminal/CmdFactoryDefault.cpp
index 3e366e8..c310083 100644
--- a/CommandTerminal/CmdFactoryDefault.cpp
+++ b/CommandTerminal/CmdFactoryDefault.cpp
@@ -16,6 +16,8 @@ uint32_t CmdFactoryDefault::action(std::vector<std::string> args)
_dot->setWakeMode(20); //DotBox +MaxPwr is stored here. Default is 20.
_dot->setWakeTimeout(2); //DotBox +MinPwr is stored here. Default is 2.
_dot->setStartUpMode(0); //DotBox +Data is stored here. Default is 0.
+ _dot->setVerbose(1);
+ _dot->setEcho(1);
_dot->resetNetworkSession();
return 0;
diff --git a/CommandTerminal/CmdFrequencyBand.cpp b/CommandTerminal/CmdFrequencyBand.cpp
new file mode 100644
index 0000000..2a37af5
--- /dev/null
+++ b/CommandTerminal/CmdFrequencyBand.cpp
@@ -0,0 +1,63 @@
+#include "CmdFrequencyBand.h"
+
+CmdFrequencyBand::CmdFrequencyBand(mDot* dot, mts::MTSSerial& serial) :
+ Command(dot, "Frequency Band", "AT+FREQ", "Configured Frequency Band '868' or '915'"), _serial(serial)
+{
+ _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: ");
+
+ _serial.writef("%s\r\n", mDot::FrequencyBandStr(_dot->getFrequencyBand()).c_str());
+ }
+
+#ifdef DEBUG_MAC
+ else if (args.size() == 2)
+ {
+ int32_t code;
+ uint8_t band = mDot::FB_915;
+
+ if (mDot::FrequencyBandStr(mDot::FB_868).find(args[1]) != std::string::npos) {
+ band = mDot::FB_868;
+ }
+
+ if ((code = _dot->setFrequencyBand(band)) != mDot::MDOT_OK) {
+ std::string error = mDot::getReturnCodeString(code) + " - " + _dot->getLastError();
+ setErrorMessage(error);
+ return 1;
+ }
+ }
+#endif
+
+ return 0;
+}
+
+bool CmdFrequencyBand::verify(std::vector<std::string> args)
+{
+ if (args.size() == 1)
+ return true;
+
+#ifdef DEBUG_MAC
+ if (args.size() == 2)
+ {
+ if (mDot::FrequencyBandStr(mDot::FB_868).find(args[1]) == std::string::npos &&
+ mDot::FrequencyBandStr(mDot::FB_915).find(args[1]) == std::string::npos)
+ {
+ setErrorMessage("Invalid parameter, expects (868,915)");
+ return false;
+ }
+
+ return true;
+ }
+#endif
+
+ setErrorMessage("Invalid arguments");
+ return false;
+}
diff --git a/CommandTerminal/CmdFrequencyBand.h b/CommandTerminal/CmdFrequencyBand.h
new file mode 100644
index 0000000..a7fe156
--- /dev/null
+++ b/CommandTerminal/CmdFrequencyBand.h
@@ -0,0 +1,21 @@
+#ifndef __CMDFREQUENCYBAND_H__
+#define __CMDFREQUENCYBAND_H__
+
+#include "Command.h"
+
+class CommandTerminal;
+
+class CmdFrequencyBand : public Command {
+
+public:
+
+ CmdFrequencyBand(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 // __CMDFREQUENCYBAND_H__
diff --git a/CommandTerminal/CmdFrequencySubBand.h b/CommandTerminal/CmdFrequencySubBand.h
index 14d50c9..322fa1e 100644
--- a/CommandTerminal/CmdFrequencySubBand.h
+++ b/CommandTerminal/CmdFrequencySubBand.h
@@ -3,7 +3,7 @@
#include "Command.h"
-class CommandTerminal;
+class ModeConfig;
class CmdFrequencySubBand : public Command {
diff --git a/CommandTerminal/CmdGetSurveyDataFile.h b/CommandTerminal/CmdGetSurveyDataFile.h
index ff4cf57..5451e4a 100644
--- a/CommandTerminal/CmdGetSurveyDataFile.h
+++ b/CommandTerminal/CmdGetSurveyDataFile.h
@@ -3,7 +3,7 @@
#include "Command.h"
-class CommandTerminal;
+class ModeConfig;
class CmdGetSurveyDataFile: public Command
{
diff --git a/CommandTerminal/CmdMaximumPower.h b/CommandTerminal/CmdMaximumPower.h
index f5d3bca..3a38b0f 100644
--- a/CommandTerminal/CmdMaximumPower.h
+++ b/CommandTerminal/CmdMaximumPower.h
@@ -3,7 +3,7 @@
#include "Command.h"
-class CommandTerminal;
+class ModeConfig;
class CmdMaximumPower: public Command
{
diff --git a/CommandTerminal/CmdMaximumSize.h b/CommandTerminal/CmdMaximumSize.h
index 4a7e416..50c7ab6 100644
--- a/CommandTerminal/CmdMaximumSize.h
+++ b/CommandTerminal/CmdMaximumSize.h
@@ -3,7 +3,7 @@
#include "Command.h"
-class CommandTerminal;
+class ModeConfig;
class CmdMaximumSize: public Command
{
diff --git a/CommandTerminal/CmdMinimumPower.h b/CommandTerminal/CmdMinimumPower.h
index a8656ee..0adf5c4 100644
--- a/CommandTerminal/CmdMinimumPower.h
+++ b/CommandTerminal/CmdMinimumPower.h
@@ -3,7 +3,7 @@
#include "Command.h"
-class CommandTerminal;
+class ModeConfig;
class CmdMinimumPower: public Command
{
diff --git a/CommandTerminal/CmdMinimumSize.h b/CommandTerminal/CmdMinimumSize.h
index ec5d3aa..12f9c2f 100644
--- a/CommandTerminal/CmdMinimumSize.h
+++ b/CommandTerminal/CmdMinimumSize.h
@@ -3,7 +3,7 @@
#include "Command.h"
-class CommandTerminal;
+class ModeConfig;
class CmdMinimumSize: public Command
{
diff --git a/CommandTerminal/CmdNetworkAddress.h b/CommandTerminal/CmdNetworkAddress.h
index 7be2dd0..989ee93 100644
--- a/CommandTerminal/CmdNetworkAddress.h
+++ b/CommandTerminal/CmdNetworkAddress.h
@@ -3,7 +3,7 @@
#include "Command.h"
-class CommandTerminal;
+class ModeConfig;
class CmdNetworkAddress : public Command {
diff --git a/CommandTerminal/CmdNetworkId.h b/CommandTerminal/CmdNetworkId.h
index 09acdc6..6ad81dd 100644
--- a/CommandTerminal/CmdNetworkId.h
+++ b/CommandTerminal/CmdNetworkId.h
@@ -3,7 +3,7 @@
#include "Command.h"
-class CommandTerminal;
+class ModeConfig;
class CmdNetworkId : public Command {
diff --git a/CommandTerminal/CmdNetworkJoinMode.h b/CommandTerminal/CmdNetworkJoinMode.h
index 81d00d0..03cc979 100644
--- a/CommandTerminal/CmdNetworkJoinMode.h
+++ b/CommandTerminal/CmdNetworkJoinMode.h
@@ -3,7 +3,7 @@
#include "Command.h"
-class CommandTerminal;
+class ModeConfig;
class CmdNetworkJoinMode : public Command {
diff --git a/CommandTerminal/CmdNetworkKey.h b/CommandTerminal/CmdNetworkKey.h
index f2874cc..34edb31 100644
--- a/CommandTerminal/CmdNetworkKey.h
+++ b/CommandTerminal/CmdNetworkKey.h
@@ -5,7 +5,7 @@
#include "Command.h"
-class CommandTerminal;
+class ModeConfig;
class CmdNetworkKey : public Command {
diff --git a/CommandTerminal/CmdNetworkSessionKey.h b/CommandTerminal/CmdNetworkSessionKey.h
index 4d8cc46..e998237 100644
--- a/CommandTerminal/CmdNetworkSessionKey.h
+++ b/CommandTerminal/CmdNetworkSessionKey.h
@@ -3,7 +3,7 @@
#include "Command.h"
-class CommandTerminal;
+class ModeConfig;
class CmdNetworkSessionKey : public Command {
diff --git a/CommandTerminal/CmdPublicNetwork.h b/CommandTerminal/CmdPublicNetwork.h
index 9efec06..36691f7 100644
--- a/CommandTerminal/CmdPublicNetwork.h
+++ b/CommandTerminal/CmdPublicNetwork.h
@@ -3,7 +3,7 @@
#include "Command.h"
-class CommandTerminal;
+class ModeConfig;
class CmdPublicNetwork : public Command {
diff --git a/CommandTerminal/CmdTxDataRate.h b/CommandTerminal/CmdTxDataRate.h
index e848b9a..8b90439 100644
--- a/CommandTerminal/CmdTxDataRate.h
+++ b/CommandTerminal/CmdTxDataRate.h
@@ -3,7 +3,7 @@
#include "Command.h"
-class CommandTerminal;
+class ModeConfig;
class CmdTxDataRate : public Command {
diff --git a/CommandTerminal/CmdTxPower.h b/CommandTerminal/CmdTxPower.h
index 4b12b08..c582389 100644
--- a/CommandTerminal/CmdTxPower.h
+++ b/CommandTerminal/CmdTxPower.h
@@ -3,7 +3,7 @@
#include "Command.h"
-class CommandTerminal;
+class ModeConfig;
class CmdTxPower: public Command
{
diff --git a/CommandTerminal/CommandTerminal.cpp b/CommandTerminal/CommandTerminal.cpp
deleted file mode 100644
index 285b0fd..0000000
--- a/CommandTerminal/CommandTerminal.cpp
+++ /dev/null
@@ -1,343 +0,0 @@
-#include "ctype.h"
-#include "CommandTerminal.h"
-#include "Command.h"
-#include "MTSLog.h"
-#include "ButtonHandler.h"
-#include <cstdarg>
-#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";
-
-const char CommandTerminal::newline[] = "\r\n";
-
-// Command error text...
-const char CommandTerminal::command_error[] = "Command not found!\r\n";
-
-// Response texts...
-const char CommandTerminal::help[] = "\r\nHelp\r\n";
-const char CommandTerminal::cmd_error[] = "Invalid command\r\n";
-const char CommandTerminal::done[] = "\r\nOK\r\n";
-const char CommandTerminal::error[] = "\r\nERROR\r\n";
-
-// Escape sequence...
-const char CommandTerminal::escape_sequence[] = "+++";
-
-mts::MTSSerial* CommandTerminal::_serialp = NULL;
-
-void CommandTerminal::addCommand(Command* cmd) {
- _commands.push_back(cmd);
-}
-
-CommandTerminal::CommandTerminal(mts::MTSSerial& serial, mDot* dot, ButtonHandler* buttons)
-:
- _serial(serial),
- _dot(dot),
- _mode(mDot::COMMAND_MODE),
- _idle_thread(idle, NULL, osPriorityLow),
- _serial_up(false),
- _buttons(buttons) {
-
- _serialp = &serial;
-
- addCommand(new CmdAttention(_dot));
- addCommand(new CmdIdentification(_dot, serial));
- addCommand(new CmdFactoryDefault(_dot));
- addCommand(new CmdSaveConfig(_dot));
- addCommand(new CmdDisplayConfig(_dot, serial));
-
- addCommand(new CmdFrequencySubBand(_dot, serial));
- addCommand(new CmdPublicNetwork(_dot, serial));
- addCommand(new CmdDeviceId(_dot, serial));
-
- addCommand(new CmdNetworkAddress(_dot, serial));
- addCommand(new CmdNetworkSessionKey(_dot, serial));
- addCommand(new CmdDataSessionKey(_dot, serial));
- addCommand(new CmdNetworkKey(_dot, serial));
- addCommand(new CmdNetworkId(_dot, serial));
-
- addCommand(new CmdNetworkJoinMode(_dot, serial));
- addCommand(new CmdTxDataRate(_dot, serial));
- addCommand(new CmdTxPower(_dot, serial));
-
- addCommand(new CmdMinimumSize(_dot, serial));
- addCommand(new CmdMaximumSize(_dot, serial));
- addCommand(new CmdMinimumPower(_dot, serial));
- addCommand(new CmdMaximumPower(_dot, serial));
- addCommand(new CmdData(_dot, serial));
- addCommand(new CmdGetSurveyDataFile(_dot, serial));
- addCommand(new CmdDeleteSurveyDataFile(_dot, serial));
- addCommand(new CmdExit(_dot, serial));
-
-}
-
-void CommandTerminal::printHelp() {
- const char* name = NULL;
- const char* text = NULL;
- const char* desc = NULL;
- const char* tab = "\t";
-
- std::string header("Command");
- header.append(tab);
- header.append(tab);
- header.append("Name");
- header.append(tab);
- header.append(tab);
- header.append(tab);
- header.append("Description");
-
- write(newline);
- write(header.c_str());
- write(newline);
- write(newline);
- for (std::vector<Command*>::iterator it = _commands.begin(); it != _commands.end(); ++it) {
- name = (*it)->name();
- text = (*it)->text();
- desc = (*it)->desc();
- write(text);
- if (strlen(text) < 8)
- write(tab);
- write(tab);
- write(name);
- if (strlen(name) < 8)
- write(tab);
- if (strlen(name) < 16)
- write(tab);
- write(tab);
- write(desc);
- write(newline);
- }
-
- write(newline);
-}
-
-bool CommandTerminal::writeable() {
- return _serial.writeable();
-}
-
-bool CommandTerminal::readable() {
- return _serial.readable();
-}
-
-char CommandTerminal::read() {
- char ch;
- _serial.read(&ch, 1);
- return ch;
-}
-
-void CommandTerminal::write(const char* message) {
- while (!writeable())
- ;
- _serial.write(message, strlen(message));
-}
-
-void CommandTerminal::writef(const char* format, ...) {
- char buff[256];
-
- va_list ap;
- va_start(ap, format);
- int size = vsnprintf(buff, 256, format, ap);
- while (!writeable())
- ;
- _serial.write(buff, size);
- va_end(ap);
-}
-
-bool CommandTerminal::start() {
- 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;
-
- //Run terminal session
- while (running) {
-
- osEvent e = Thread::signal_wait(buttonSignal, 20);
- if (e.status == osEventSignal) {
- ButtonHandler::ButtonEvent _be = _buttons->getButtonEvent();
- switch (_be) {
- case ButtonHandler::sw1_press:
- break;
- case ButtonHandler::sw2_press:
- break;
- case ButtonHandler::sw1_hold:
- return true;
- default:
- break;
- }
- }
-
- ch = '\0';
-
- // read characters
- if (readable()) {
- ch = read();
-
- 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;
- }
-
- // echo chars if enabled
- if (echo && !(ch == '\r' || ch == '\n'))
- writef("%c", ch);
- }
-
- // look for end of command line
- if (command.find("\n") != std::string::npos || command.find("\r") != std::string::npos) {
- // remove new line or cr character
- command.erase(command.size() - 1);
- write("\r"); // match standard modem output
- write(newline);
- } else {
- continue;
- }
-
- // trim whitespace from command
- mts::Text::trim(command, "\r\n\t ");
-
- if (command.size() < 1) {
- command.clear();
- continue;
- }
-
- // parse command and args
- args.clear();
-
- // find first '=' character
- size_t delim_index = command.find("=");
- if (delim_index != std::string::npos) {
- args.push_back(command.substr(0, delim_index));
- } else {
- // find first ' ' character
- delim_index = command.find(" ");
- if (delim_index != std::string::npos) {
- args.push_back(command.substr(0, delim_index));
- } else {
- args.push_back(command);
- }
- }
-
- if (delim_index != std::string::npos) {
- std::vector<std::string> params = mts::Text::split(command.substr(delim_index + 1), ",");
- args.insert(args.end(), params.begin(), params.end());
- }
-
- args[0] = mts::Text::toUpper(args[0]);
-
- // print help
- if ((args[0].find("?") == 0 || args[0].find("HELP") == 0) && args.size() == 1) {
- printHelp();
- command.clear();
- } else {
- bool found = false;
- bool query = false;
-
- std::string lookfor = args[0];
-
- // per command help
- if ((args[0].find("?") == 0 || args[0].find("HELP") == 0))
- lookfor = mts::Text::toUpper(args[1]);
-
- // trim off any trailing '?' and mark as a query command
- if (args[0].rfind("?") == args[0].length() - 1) {
- query = true;
- lookfor = args[0].substr(0, args[0].length() - 1);
- }
-
- // search for command
- for (std::vector<Command*>::iterator it = _commands.begin(); it != _commands.end() && !found; ++it) {
- Command* cmd = *it;
-
- // match CMD or CMD? syntax if command is queryable
- if (lookfor == cmd->text() && (!query || (query && cmd->queryable()))) {
- found = true;
- if (args[0] == "HELP") {
- writef("%s%s", cmd->help(), newline);
- write(done);
- }
-
- else if (args.size() > 1 && args[1] == "?") {
- writef("%s%s", cmd->usage().c_str(), newline);
- write(done);
- } else if (!cmd->verify(args)) {
- writef("%s%s", cmd->errorMessage().c_str(), newline);
- writef("%s", error);
- } else {
- if (cmd->action(args) == 0) {
- writef("%s", done);
- } else {
- writef("%s%s", cmd->errorMessage().c_str(), newline);
- writef("%s", error);
- }
- }
- }
- }
-
- if (!found) {
- writef("%s", command_error);
- writef("%s", error);
- }
- }
-
- if (history.size() == 0 || history.front() != command)
- history.push_front(command);
- history_index = -1;
- command.clear();
-
- while (history.size() > 10)
- history.pop_back();
-
- }
- return false;
-}
diff --git a/CommandTerminal/CommandTerminal.h b/CommandTerminal/CommandTerminal.h
deleted file mode 100644
index b6c58c8..0000000
--- a/CommandTerminal/CommandTerminal.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/**
- ******************************************************************************
- * File Name : command.h
- * Date : 18/04/2014 10:57:12
- * Description : This file provides code for command line prompt
- ******************************************************************************
- *
- * COPYRIGHT(c) 2014 MultiTech Systems, Inc.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of STMicroelectronics nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************
- */
-
-#include "mbed.h"
-#include "MTSSerial.h"
-#include "Commands.h"
-#include "mDot.h"
-#include "ButtonHandler.h"
-
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __command_terminal_H__
-#define __command_terminal_H__
-
-class CommandTerminal {
-
-public:
-
- enum WaitType {
- WAIT_JOIN,
- WAIT_RECV,
- WAIT_LINK,
- WAIT_SEND,
- WAIT_NA
- };
-
- CommandTerminal(mts::MTSSerial& serial, mDot* dot, ButtonHandler* buttons);
-
- // Command prompt text...
- static const char banner[];
- static const char helpline[];
- static const char prompt[];
-
- // Command error text...
- static const char command_error[];
-
- // Response texts...
- static const char help[];
- static const char cmd_error[];
- static const char newline[];
- static const char done[];
- static const char error[];
-
- // Escape sequence
- static const char escape_sequence[];
-
- bool start();
-
-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 _serial_up;
-
- ButtonHandler* _buttons;
-
- void addCommand(Command* cmd);
-
- void printHelp();
-
- bool readable();
- bool writeable();
- char read();
- void write(const char* message);
- void writef(const char* format, ... );
-
-};
-
-#endif // __command_terminal_H__
-
diff --git a/CommandTerminal/Commands.h b/CommandTerminal/Commands.h
index 3797036..5caa6e4 100644
--- a/CommandTerminal/Commands.h
+++ b/CommandTerminal/Commands.h
@@ -6,6 +6,7 @@
#include "CmdFactoryDefault.h"
#include "CmdSaveConfig.h"
#include "CmdDisplayConfig.h"
+#include "CmdFrequencyBand.h"
#include "CmdDeviceId.h"
#include "CmdPublicNetwork.h"
#include "CmdNetworkAddress.h"
@@ -25,4 +26,3 @@
#include "CmdData.h"
#include "CmdGetSurveyDataFile.h"
#include "CmdDeleteSurveyDataFile.h"
-#include "CmdExit.h"