few changes for RTS/CTS control
Dependencies: MTS-Serial libmDot mbed-rtos mbed
Fork of mDot_AT_firmware by
CommandTerminal/CmdSendStringOnInterval.cpp
- Committer:
- serg838
- Date:
- 2016-10-25
- Revision:
- 11:77b7911263da
- Parent:
- 9:ff62b20f7000
File content as of revision 11:77b7911263da:
#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; }