few changes for RTS/CTS control
Dependencies: MTS-Serial libmDot mbed-rtos mbed
Fork of mDot_AT_firmware by
Diff: CommandTerminal/CmdSendStringOnInterval.cpp
- Revision:
- 9:ff62b20f7000
- Parent:
- 4:666017851052
--- a/CommandTerminal/CmdSendStringOnInterval.cpp Mon Apr 04 13:17:44 2016 +0000 +++ b/CommandTerminal/CmdSendStringOnInterval.cpp Mon Apr 04 09:00:31 2016 -0500 @@ -3,7 +3,7 @@ CmdSendStringOnInterval::CmdSendStringOnInterval(mDot* dot, mts::MTSSerial& serial) : - Command(dot, "Send Continuous", "AT+SENDI", "Sends supplied packet data on interval between sends, output any recevied packets (escape sequence: +++)"), + 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)"; @@ -11,10 +11,10 @@ uint32_t CmdSendStringOnInterval::action(std::vector<std::string> args) { int32_t code; - uint32_t interval; + int interval; std::string text; - sscanf(args[1].c_str(), "%lu", &interval); + sscanf(args[1].c_str(), "%d", &interval); for (size_t i = 2; i < args.size(); i++) { text.append(args[i]); @@ -27,22 +27,17 @@ if (_dot->getJoinMode() == mDot::AUTO_OTA) { Timer timer; timer.start(); - uint32_t backoff = 2000; while (!_dot->getNetworkJoinStatus()) { _serial.writef("Joining network... "); if (_dot->joinNetworkOnce() == mDot::MDOT_OK) { _serial.writef("Network Joined\r\n"); } else { - _serial.writef("Join failed\r\n"); + _serial.writef("%s\r\n", _dot->getLastError().c_str()); } - if (CommandTerminal::waitForEscape(backoff)) { + if (CommandTerminal::waitForEscape(_dot->getNextTxMs())) { return 0; } - - if (backoff < 60 * 60 * 1000) { - backoff *= 2; - } } } else if (!_dot->getNetworkJoinStatus()) { setErrorMessage(mDot::getReturnCodeString(mDot::MDOT_NOT_JOINED)); @@ -50,13 +45,10 @@ } if ((code = _dot->send(data, _dot->getTxWait())) != mDot::MDOT_OK) { - std::string error = mDot::getReturnCodeString(code); - - if (code != mDot::MDOT_NOT_JOINED) - error += + " - " + _dot->getLastError(); + std::string error = _dot->getLastError(); if (code == mDot::MDOT_INVALID_PARAM) { - setErrorMessage(error); + setErrorMessage(_dot->getLastError());; return 1; } else { _serial.writef("%s\r\n", error.c_str()); @@ -91,10 +83,10 @@ bool CmdSendStringOnInterval::verify(std::vector<std::string> args) { if (args.size() >= 3) { - uint32_t interval; + int interval; size_t size = 0; - if (sscanf(args[1].c_str(), "%lu", &interval) != 1) { + if (sscanf(args[1].c_str(), "%d", &interval) != 1) { setErrorMessage("Invalid argument"); return false; } @@ -104,7 +96,7 @@ return false; } - for (int i = 2; i < args.size() - 1; i++) + for (size_t i = 2; i < args.size() - 1; i++) size += args[i].size() + 1; if (size > 242) { setErrorMessage("Invalid packet, expects (string:242)");