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
CmdSendBinary.cpp
00001 #include "CmdSendBinary.h" 00002 #include "CommandTerminal.h" 00003 00004 CmdSendBinary::CmdSendBinary() 00005 : 00006 Command("Send Binary", "AT+SENDB", "Sends supplied binary (hex) packet data one time and return response", "(hex:242)") 00007 { 00008 } 00009 00010 uint32_t CmdSendBinary::action(std::vector<std::string> args) { 00011 std::vector<uint8_t> data; 00012 00013 int temp; 00014 uint32_t length = args[1].size(); 00015 00016 // Convert the ASCII hex data to binary... 00017 for (uint32_t i = 0; i < length; i += 2) { 00018 sscanf(&args[1][i], "%2x", &temp); 00019 data.push_back(temp); 00020 } 00021 00022 if (CommandTerminal::Dot()->send(data, CommandTerminal::Dot()->getTxWait()) != mDot::MDOT_OK) { 00023 CommandTerminal::setErrorMessage(CommandTerminal::Dot()->getLastError());; 00024 return 1; 00025 } 00026 00027 data.clear(); 00028 00029 if (CommandTerminal::Dot()->getTxWait() && CommandTerminal::Dot()->recv(data) == mDot::MDOT_OK) { 00030 if (!data.empty()) { 00031 if (CommandTerminal::Dot()->getRxOutput() == mDot::HEXADECIMAL) { 00032 for (size_t i = 0; i < data.size(); i++) { 00033 CommandTerminal::Serial()->writef("%02x", data[i]); 00034 } 00035 CommandTerminal::Serial()->writef("\r\n"); 00036 } else { 00037 CommandTerminal::Serial()->writef("%s\r\n", CommandTerminal::formatPacketData(data, CommandTerminal::Dot()->getRxOutput()).c_str()); 00038 } 00039 } 00040 } 00041 00042 return 0; 00043 } 00044 00045 bool CmdSendBinary::verify(std::vector<std::string> args) { 00046 if (args.size() == 2) { 00047 if (args[1].size() > 484 || !isHexString(args[1], args[1].size() / 2)) { 00048 CommandTerminal::setErrorMessage("Invalid hex string, (hex:242)"); 00049 return false; 00050 } 00051 00052 return true; 00053 } 00054 00055 CommandTerminal::setErrorMessage("Invalid arguments"); 00056 return false; 00057 } 00058
Generated on Tue Jul 12 2022 20:40:04 by
