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 libxDot-dev-mbed5-deprecated
Fork of Dot-AT-Firmware by
CommandTerminal/CmdSendString.cpp
- Committer:
- Mike Fiore
- Date:
- 2015-08-18
- Revision:
- 4:666017851052
- Parent:
- 2:e5eebd74d36d
- Child:
- 9:ff62b20f7000
File content as of revision 4:666017851052:
#include "CmdSendString.h"
#include "CommandTerminal.h"
CmdSendString::CmdSendString(mDot* dot, mts::MTSSerial& serial)
:
Command(dot, "Send Once", "AT+SEND", "Sends supplied packet data one time and return response, (max:242 bytes)"),
_serial(serial) {
_help = std::string(text()) + ": " + std::string(desc());
_usage = "(string:242)";
}
uint32_t CmdSendString::action(std::vector<std::string> args) {
// Argument had been split on each comma, rebuild payload
int32_t code;
std::string text;
for (size_t i = 1; i < args.size(); i++) {
text.append(args[i]);
if (i != args.size() - 1)
text.append(",");
}
std::vector<uint8_t> data(text.begin(), text.end());
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();
setErrorMessage(error);
return 1;
}
if (_dot->getTxWait()) {
data.clear();
if (_dot->recv(data) == mDot::MDOT_OK) {
if (!data.empty()) {
if (_dot->getVerbose())
_serial.writef("Packet data:\r\n");
_serial.writef("%s\r\n", CommandTerminal::formatPacketData(data, _dot->getRxOutput()).c_str());
}
}
}
return 0;
}
bool CmdSendString::verify(std::vector<std::string> args) {
if (args.size() == 1) {
// allow sending empty packet to retrieve downstream messages
return true;
}
if (args.size() >= 2) {
size_t size = 0;
for (int i = 1; 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;
}
