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
Fork of mDot_USB_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 setErrorMessage(_dot->getLastError()); 00025 return 1; 00026 } else if (_dot->getTxWait()) { 00027 data.clear(); 00028 00029 if (_dot->recv(data) == mDot::MDOT_OK) { 00030 if (!data.empty()) { 00031 if (_dot->getVerbose()) 00032 _serial.writef("Packet data:\r\n"); 00033 _serial.writef("%s\r\n", CommandTerminal::formatPacketData(data, _dot->getRxOutput()).c_str()); 00034 } 00035 } 00036 } 00037 00038 return 0; 00039 } 00040 00041 bool CmdSendString::verify(std::vector<std::string> args) { 00042 00043 if (args.size() == 1) { 00044 // allow sending empty packet to retrieve downstream messages 00045 return true; 00046 } 00047 00048 if (args.size() >= 2) { 00049 size_t size = 0; 00050 for (size_t i = 1; i < args.size() - 1; i++) 00051 size += args[i].size() + 1; 00052 if (size > 242) { 00053 setErrorMessage("Invalid packet, expects (string:242)"); 00054 return false; 00055 } 00056 00057 return true; 00058 } 00059 00060 setErrorMessage("Invalid arguments"); 00061 return false; 00062 }
Generated on Tue Jul 12 2022 20:37:29 by
1.7.2
