diff options
29 files changed, 229 insertions, 309 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.h b/CommandTerminal/CommandTerminal.h deleted file mode 100644 index 0fcb9c4..0000000 --- a/CommandTerminal/CommandTerminal.h +++ /dev/null @@ -1,107 +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" - -/* 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); - - // 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[]; - - void 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; - - 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" diff --git a/CommandTerminal/CommandTerminal.cpp b/Mode/ModeConfig.cpp index 28c047f..2d24716 100644 --- a/CommandTerminal/CommandTerminal.cpp +++ b/Mode/ModeConfig.cpp @@ -1,40 +1,35 @@ +#include "ModeConfig.h" #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"; +const char ModeConfig::newline[] = "\r\n"; // Command error text... -const char CommandTerminal::command_error[] = "Command not found!\r\n"; +const char ModeConfig::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[] = "+++"; +const char ModeConfig::done[] = "\r\nOK\r\n"; +const char ModeConfig::error[] = "\r\nERROR\r\n"; -mts::MTSSerial* CommandTerminal::_serialp = NULL; +mts::MTSSerial* ModeConfig::_serialp = NULL; -void CommandTerminal::addCommand(Command* cmd) { +void ModeConfig::addCommand(Command* cmd) { _commands.push_back(cmd); } -CommandTerminal::CommandTerminal(mts::MTSSerial& serial, mDot* dot) -: +ModeConfig::ModeConfig(DOGS102* lcd, mts::MTSSerial& serial, mDot* dot, ButtonHandler* buttons) +: Mode(lcd, buttons), + _lc(lcd), _serial(serial), _dot(dot), _mode(mDot::COMMAND_MODE), _idle_thread(idle, NULL, osPriorityLow), - _serial_up(false) { + _serial_up(false), + _buttons(buttons) { _serialp = &serial; @@ -44,6 +39,7 @@ CommandTerminal::CommandTerminal(mts::MTSSerial& serial, mDot* dot) addCommand(new CmdSaveConfig(_dot)); addCommand(new CmdDisplayConfig(_dot, serial)); + addCommand(new CmdFrequencyBand(_dot, serial)); addCommand(new CmdFrequencySubBand(_dot, serial)); addCommand(new CmdPublicNetwork(_dot, serial)); addCommand(new CmdDeviceId(_dot, serial)); @@ -65,11 +61,10 @@ CommandTerminal::CommandTerminal(mts::MTSSerial& serial, mDot* dot) addCommand(new CmdData(_dot, serial)); addCommand(new CmdGetSurveyDataFile(_dot, serial)); addCommand(new CmdDeleteSurveyDataFile(_dot, serial)); - addCommand(new CmdExit(_dot, serial)); } -void CommandTerminal::printHelp() { +void ModeConfig::printHelp() { const char* name = NULL; const char* text = NULL; const char* desc = NULL; @@ -109,27 +104,27 @@ void CommandTerminal::printHelp() { write(newline); } -bool CommandTerminal::writeable() { +bool ModeConfig::writeable() { return _serial.writeable(); } -bool CommandTerminal::readable() { +bool ModeConfig::readable() { return _serial.readable(); } -char CommandTerminal::read() { +char ModeConfig::read() { char ch; _serial.read(&ch, 1); return ch; } -void CommandTerminal::write(const char* message) { +void ModeConfig::write(const char* message) { while (!writeable()) ; _serial.write(message, strlen(message)); } -void CommandTerminal::writef(const char* format, ...) { +void ModeConfig::writef(const char* format, ...) { char buff[256]; va_list ap; @@ -141,7 +136,7 @@ void CommandTerminal::writef(const char* format, ...) { va_end(ap); } -void CommandTerminal::start() { +bool ModeConfig::start() { char ch; bool running = true; bool echo = _dot->getEcho(); @@ -150,41 +145,28 @@ void CommandTerminal::start() { int history_index = -1; std::vector<std::string> args; - if (_dot->getStartUpMode() == mDot::SERIAL_MODE) { - std::string escape_buffer; - char ch; - - int escape_timeout = 1000; - Timer tmr; - Timer escape_tmr; - - // wait one second for possible escape - tmr.reset(); - tmr.start(); - escape_tmr.reset(); - escape_tmr.start(); - while (tmr.read_ms() < escape_timeout) { - if (_serial.readable()) { - _serial.read(&ch, 1); - escape_buffer += ch; - } - - if (escape_buffer.find(escape_sequence) != std::string::npos) { - _mode = mDot::COMMAND_MODE; - command.clear(); - break; - } - - if (escape_tmr.read_ms() > escape_timeout) - escape_buffer.clear(); + osSignalClear(_main_id, buttonSignal); - osDelay(1); - } - - } + _lc.display(); //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 @@ -294,6 +276,9 @@ void CommandTerminal::start() { if ((args[0].find("?") == 0 || args[0].find("HELP") == 0) && args.size() == 1) { printHelp(); command.clear(); + } else if (args[0].find("AT+EXIT") == 0 && args[0].length() == 7) { + write(done); + return true; } else { bool found = false; bool query = false; @@ -354,4 +339,5 @@ void CommandTerminal::start() { history.pop_back(); } + return false; } diff --git a/Mode/ModeConfig.h b/Mode/ModeConfig.h new file mode 100644 index 0000000..ade3093 --- /dev/null +++ b/Mode/ModeConfig.h @@ -0,0 +1,59 @@ +#ifndef __MODECONFIG_H__ +#define __MODECONFIG_H__ + +#include "Mode.h" +#include "LayoutConfig.h" +#include "mbed.h" +#include "MTSSerial.h" +#include "Commands.h" +#include "mDot.h" +#include "ButtonHandler.h" + +class ModeConfig : public Mode { + +public: + + ModeConfig(DOGS102* lcd, mts::MTSSerial& serial, mDot* dot, ButtonHandler* buttons); + + // Command error text... + static const char command_error[]; + + // Response texts... + static const char newline[]; + static const char done[]; + static const char error[]; + + bool start(); + +private: + + static void idle(void const* args) { + while (1) + __WFI(); + } + + mts::MTSSerial& _serial; + static mts::MTSSerial* _serialp; + + LayoutConfig _lc; + ButtonHandler::ButtonEvent _be; + ButtonHandler* _buttons; + mDot* _dot; + mDot::Mode _mode; + std::vector<Command*> _commands; + Thread _idle_thread; + bool _serial_up; + + void addCommand(Command* cmd); + + void printHelp(); + + bool readable(); + bool writeable(); + char read(); + void write(const char* message); + void writef(const char* format, ... ); + +}; + +#endif // __MODECONFIG_H__ @@ -23,6 +23,7 @@ // mode objects #include "ModeJoin.h" #include "ModeSingle.h" +#include "ModeConfig.h" // misc heders #include <string> @@ -47,9 +48,11 @@ mDot* dot; // Modes ModeJoin* modeJoin; ModeSingle* modeSingle; +ModeConfig* modeConfig; // Serial debug port Serial debug(USBTX, USBRX); +// Config mode serial port. mts::MTSSerial serial(USBTX, USBRX, 512, 512); // Prototypes @@ -71,6 +74,11 @@ int main() { dot = mDot::getInstance(); lora = new LoRaHandler(main_id); + // display startup screen for 3 seconds + LayoutStartup ls(lcd); + ls.display(); + osDelay(3000); + // start of temporary stuff! //dot->setFrequencyBand(mDot::FB_868); if (dot->getFrequencyBand() == mDot::FB_915) @@ -83,6 +91,7 @@ int main() { modeJoin = new ModeJoin(lcd, buttons, dot, lora); modeSingle = new ModeSingle(lcd, buttons, dot, lora); + modeConfig = new ModeConfig(lcd, serial, dot, buttons); // display startup screen for 3 seconds LayoutStartup ls(lcd); @@ -153,7 +162,7 @@ void mainMenu() { if (modeJoin->start()) loraDemo(); } else if (selected == menu_strings[config]) { - configuration(); + modeConfig->start(); } else if (selected == menu_strings[single]) { if (modeJoin->start()) modeSingle->start(); @@ -166,33 +175,6 @@ void mainMenu() { } } -void configuration() { - LayoutConfig lc(lcd); - - // clear any stale signals - osSignalClear(main_id, buttonSignal | loraSignal); - - lc.display(); - logInfo("config mode"); - - while (true) { - osEvent e = Thread::signal_wait(buttonSignal); - if (e.status == osEventSignal) { - ButtonHandler::ButtonEvent ev = buttons->getButtonEvent(); - switch (ev) { - case ButtonHandler::sw1_press: - break; - case ButtonHandler::sw2_press: - break; - case ButtonHandler::sw1_hold: - return; - default: - break; - } - } - } -} - void loraDemo() { LayoutHelp lh(lcd); lh.display(); |