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