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
CmdMacCmd.cpp
00001 #include "CmdMacCmd.h" 00002 #include "CommandTerminal.h" 00003 00004 CmdMacCmd::CmdMacCmd() 00005 : 00006 Command("MAC Command", "AT+MAC", "Inject MAC command to MAC layer or read uplink MAC command buffer, pass '0' argument to clear buffer", "(hex:242)") 00007 { 00008 } 00009 00010 uint32_t CmdMacCmd::action(std::vector<std::string> args) { 00011 00012 if (args.size() == 1) { 00013 std::vector<uint8_t> cmds = CommandTerminal::Dot()->getMacCommands(); 00014 00015 if (cmds.size() > 1) { 00016 for (size_t i = 0; i < cmds.size(); i++) { 00017 CommandTerminal::Serial()->writef("%02x", cmds[i]); 00018 } 00019 CommandTerminal::Serial()->writef("\r\n"); 00020 } 00021 00022 } else { 00023 if (args[1].size() == 1 && args[1] == "0") { 00024 CommandTerminal::Dot()->clearMacCommands(); 00025 } else { 00026 std::vector<uint8_t> data; 00027 int32_t code; 00028 int temp; 00029 uint32_t length = args[1].size(); 00030 00031 // Convert the ASCII hex data to binary... 00032 for (uint32_t i = 0; i < length; i += 2) { 00033 sscanf(&args[1][i], "%2x", &temp); 00034 data.push_back(temp); 00035 } 00036 00037 if ((code = CommandTerminal::Dot()->injectMacCommand(data)) != mDot::MDOT_OK) { 00038 std::string error = mDot::getReturnCodeString(code); 00039 00040 if (code != mDot::MDOT_NOT_JOINED) 00041 error += +" - " + CommandTerminal::Dot()->getLastError(); 00042 00043 CommandTerminal::setErrorMessage(CommandTerminal::Dot()->getLastError()); 00044 return 1; 00045 } 00046 } 00047 } 00048 00049 return 0; 00050 } 00051 00052 bool CmdMacCmd::verify(std::vector<std::string> args) { 00053 if (args.size() == 1) { 00054 return true; 00055 } else if (args.size() == 2) { 00056 00057 if (args[1].size() == 1 && args[1] == "0") { 00058 return true; 00059 } else if (args[1].size() > 484 || !isHexString(args[1], args[1].size() / 2)) { 00060 CommandTerminal::setErrorMessage("Invalid hex string, (hex:242)"); 00061 return false; 00062 } 00063 00064 return true; 00065 } 00066 00067 CommandTerminal::setErrorMessage("Invalid arguments"); 00068 return false; 00069 } 00070
Generated on Tue Jul 12 2022 20:40:04 by
