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
CmdSendBinary.cpp
00001 #include "CmdSendBinary.h" 00002 #include "CommandTerminal.h" 00003 00004 CmdSendBinary::CmdSendBinary(mDot* dot, mts::MTSSerial& serial) 00005 : 00006 Command(dot, "Send Binary", "AT+SENDB", "Sends supplied binary (hex) packet data one time and return response"), 00007 _serial(serial) { 00008 _help = std::string(text()) + ": " + std::string(desc()); 00009 _usage = "(hex:242)"; 00010 } 00011 00012 uint32_t CmdSendBinary::action(std::vector<std::string> args) { 00013 std::vector<uint8_t> data; 00014 int32_t code; 00015 uint8_t temp; 00016 uint32_t length = args[1].size(); 00017 00018 // Convert the ASCII hex data to binary... 00019 for (uint32_t i = 0; i < length; i += 2) { 00020 sscanf(&args[1][i], "%2x", &temp); 00021 data.push_back(temp); 00022 } 00023 00024 if ((code = _dot->send(data, _dot->getTxWait())) != mDot::MDOT_OK) { 00025 std::string error = mDot::getReturnCodeString(code); 00026 00027 if (code != mDot::MDOT_NOT_JOINED) 00028 error += + " - " + _dot->getLastError(); 00029 00030 setErrorMessage(error); 00031 return 1; 00032 } 00033 00034 data.clear(); 00035 00036 if (_dot->getTxWait() && _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 return 0; 00045 } 00046 00047 bool CmdSendBinary::verify(std::vector<std::string> args) { 00048 if (args.size() == 2) { 00049 if (args[1].size() > 484 || !isHexString(args[1], args[1].size() / 2)) { 00050 setErrorMessage("Invalid hex string, (hex:242)"); 00051 return false; 00052 } 00053 00054 return true; 00055 } 00056 00057 setErrorMessage("Invalid arguments"); 00058 return false; 00059 } 00060
Generated on Tue Jul 12 2022 21:40:57 by
1.7.2
