Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MTS-Serial libmDot-mbed5
Fork of Dot-AT-Firmware by
Diff: CommandTerminal/CmdSendStringOnInterval.cpp
- Revision:
- 1:e52ae6584f1c
- Child:
- 2:e5eebd74d36d
diff -r e2b8246361bc -r e52ae6584f1c CommandTerminal/CmdSendStringOnInterval.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CommandTerminal/CmdSendStringOnInterval.cpp Thu Jun 25 10:23:41 2015 -0500
@@ -0,0 +1,108 @@
+#include "CmdSendStringOnInterval.h"
+#include "CommandTerminal.h"
+
+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: +++)"),
+ _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;
+ uint32_t interval;
+ std::vector<uint8_t> data(args[2].begin(), args[2].end());
+
+ sscanf(args[1].c_str(), "%lu", &interval);
+
+ while (true) {
+ 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");
+ }
+
+ if (CommandTerminal::waitForEscape(backoff)) {
+ return 0;
+ }
+
+ if (backoff < 60 * 60 * 1000) {
+ backoff *= 2;
+ }
+ }
+ } 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 = mDot::getReturnCodeString(code);
+
+ if (code != mDot::MDOT_NOT_JOINED)
+ error += + " - " + _dot->getLastError();
+
+ if (code == mDot::MDOT_INVALID_PARAM) {
+ setErrorMessage(error);
+ 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) {
+ uint32_t interval;
+ if (sscanf(args[1].c_str(), "%lu", &interval) != 1) {
+ setErrorMessage("Invalid argument");
+ return false;
+ }
+
+ if (interval < 100 || interval > INT_MAX) {
+ setErrorMessage("Invalid interval, expects (100-2147483647) ms");
+ return false;
+ }
+
+ if (args[2].size() > 242) {
+ setErrorMessage("Invalid packet, expects (string:242)");
+ return false;
+ }
+
+ return true;
+ }
+
+ setErrorMessage("Invalid arguments");
+ return false;
+}
