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 mbed-rtos mbed-src
Fork of mDot_AT_firmware by
CmdSendString.cpp
00001 #include "CmdSendString.h" 00002 #include "CommandTerminal.h" 00003 00004 CmdSendString::CmdSendString(mDot* dot, mts::MTSSerial& serial) 00005 : 00006 Command(dot, "Send Once", "AT+SEND", "Sends supplied packet data one time and return response, (max:242 bytes)"), 00007 _serial(serial) { 00008 _help = std::string(text()) + ": " + std::string(desc()); 00009 _usage = "(string:242)"; 00010 } 00011 00012 uint32_t CmdSendString::action(std::vector<std::string> args) { 00013 // Argument had been split on each comma, rebuild payload 00014 int32_t code; 00015 std::string text; 00016 for (size_t i = 1; i < args.size(); i++) { 00017 text.append(args[i]); 00018 if (i != args.size() - 1) 00019 text.append(","); 00020 } 00021 00022 std::vector<uint8_t> data(text.begin(), text.end()); 00023 if ((code = _dot->send(data, _dot->getTxWait())) != mDot::MDOT_OK) { 00024 std::string error = mDot::getReturnCodeString(code); 00025 00026 if (code != mDot::MDOT_NOT_JOINED) 00027 error += + " - " + _dot->getLastError(); 00028 00029 setErrorMessage(error); 00030 return 1; 00031 } 00032 00033 if (_dot->getTxWait()) { 00034 data.clear(); 00035 00036 if (_dot->recv(data) == mDot::MDOT_OK) { 00037 if (!data.empty()) { 00038 if (_dot->getVerbose()) 00039 _serial.writef("Packet data:\r\n"); 00040 _serial.writef("%s\r\n", CommandTerminal::formatPacketData(data, _dot->getRxOutput()).c_str()); 00041 } 00042 } 00043 } 00044 00045 return 0; 00046 } 00047 00048 bool CmdSendString::verify(std::vector<std::string> args) { 00049 00050 if (args.size() == 1) { 00051 // allow sending empty packet to retrieve downstream messages 00052 return true; 00053 } 00054 00055 if (args.size() >= 2) { 00056 size_t size = 0; 00057 for (int i = 1; i < args.size(); i++) 00058 size += args[i].size(); 00059 if (size > 242) { 00060 setErrorMessage("Invalid packet, expects (string:242)"); 00061 return false; 00062 } 00063 00064 return true; 00065 } 00066 00067 setErrorMessage("Invalid arguments"); 00068 return false; 00069 }
Generated on Tue Jul 12 2022 21:40:57 by
1.7.2
