![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
AT terminal for the mDot using the USB debug port instead of the serial port.
Dependencies: MTS-Serial libmDot-mbed5
Fork of Dot-AT-Firmware by
CommandTerminal/CmdSendStringOnInterval.cpp
- Committer:
- Mike Fiore
- Date:
- 2016-04-04
- Revision:
- 9:ff62b20f7000
- Parent:
- 4:666017851052
- Child:
- 14:f9a77400b622
File content as of revision 9:ff62b20f7000:
#include "CmdSendStringOnInterval.h" #include "CommandTerminal.h" CmdSendStringOnInterval::CmdSendStringOnInterval(mDot* dot, mts::MTSSerial& serial) : Command(dot, "Send On Interval", "AT+SENDI", "Sends supplied packet data on interval between sends, output any received packets (escape sequence: +++)"), _serial(serial) { _help = std::string(text()) + ": " + std::string(desc()); _usage = "(100-2147483647) ms,(string:242)"; } uint32_t CmdSendStringOnInterval::action(std::vector<std::string> args) { int32_t code; int interval; std::string text; sscanf(args[1].c_str(), "%d", &interval); for (size_t i = 2; i < args.size(); i++) { text.append(args[i]); if (i != args.size() - 1) text.append(","); } std::vector<uint8_t> data(text.begin(), text.end()); while (true) { if (_dot->getJoinMode() == mDot::AUTO_OTA) { Timer timer; timer.start(); while (!_dot->getNetworkJoinStatus()) { _serial.writef("Joining network... "); if (_dot->joinNetworkOnce() == mDot::MDOT_OK) { _serial.writef("Network Joined\r\n"); } else { _serial.writef("%s\r\n", _dot->getLastError().c_str()); } if (CommandTerminal::waitForEscape(_dot->getNextTxMs())) { return 0; } } } else if (!_dot->getNetworkJoinStatus()) { setErrorMessage(mDot::getReturnCodeString(mDot::MDOT_NOT_JOINED)); return 1; } if ((code = _dot->send(data, _dot->getTxWait())) != mDot::MDOT_OK) { std::string error = _dot->getLastError(); if (code == mDot::MDOT_INVALID_PARAM) { setErrorMessage(_dot->getLastError());; return 1; } else { _serial.writef("%s\r\n", error.c_str()); } } if (code == mDot::MDOT_OK) { if (CommandTerminal::waitForEscape(3000, _dot, CommandTerminal::WAIT_SEND)) { return 0; } if (_dot->getTxWait() || _dot->getAck() > 0) { std::vector<uint8_t> rx_data; if (_dot->recv(rx_data) == mDot::MDOT_OK) { if (!rx_data.empty()) { if (_dot->getVerbose()) _serial.writef("Packet data:\r\n"); _serial.writef("%s\r\n", CommandTerminal::formatPacketData(rx_data, _dot->getRxOutput()).c_str()); } } } } if (CommandTerminal::waitForEscape(interval)) { return 0; } } return 0; } bool CmdSendStringOnInterval::verify(std::vector<std::string> args) { if (args.size() >= 3) { int interval; size_t size = 0; if (sscanf(args[1].c_str(), "%d", &interval) != 1) { setErrorMessage("Invalid argument"); return false; } if (interval < 100 || interval > INT_MAX) { setErrorMessage("Invalid interval, expects (100-2147483647) ms"); return false; } for (size_t i = 2; i < args.size() - 1; i++) size += args[i].size() + 1; if (size > 242) { setErrorMessage("Invalid packet, expects (string:242)"); return false; } return true; } setErrorMessage("Invalid arguments"); return false; }