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
CmdChannelMask.cpp
00001 #include "CmdChannelMask.h" 00002 #include "ChannelPlan.h" 00003 00004 CmdChannelMask::CmdChannelMask() 00005 : 00006 Command("Channel Mask", "AT+CHM", "Get/set channel mask (OFFSET:0-4,MASK:0000-FFFF)", "(OFFSET:0-4,MASK:0000-FFFF)") 00007 { 00008 _queryable = true; 00009 } 00010 00011 uint32_t CmdChannelMask::action(std::vector<std::string> args) { 00012 00013 if (args.size() == 1) { 00014 if (CommandTerminal::Dot()->getVerbose()) 00015 CommandTerminal::Serial()->writef("Channel Mask: "); 00016 00017 std::vector<uint16_t> mask = CommandTerminal::Dot()->getChannelMask(); 00018 00019 for (int i = int(mask.size()) - 1; i >= 0; i--) { 00020 CommandTerminal::Serial()->writef("%04X", mask[i]); 00021 } 00022 00023 CommandTerminal::Serial()->writef("\r\n"); 00024 00025 } else if (args.size() == 3) { 00026 int code = 0; 00027 int temp = 0; 00028 int offset = 0; 00029 uint16_t mask = 0; 00030 00031 sscanf(args[1].c_str(), "%d", &offset); 00032 00033 // Convert the ASCII hex data to binary... 00034 sscanf(&args[2][0], "%02x", &temp); 00035 mask = uint8_t(temp) << 8; 00036 sscanf(&args[2][2], "%02x", &temp); 00037 mask |= uint8_t(temp); 00038 00039 if ((code = CommandTerminal::Dot()->setChannelMask(offset, mask)) != mDot::MDOT_OK) { 00040 CommandTerminal::setErrorMessage(CommandTerminal::Dot()->getLastError()); 00041 return 1; 00042 } 00043 } 00044 00045 return 0; 00046 } 00047 00048 bool CmdChannelMask::verify(std::vector<std::string> args) { 00049 if (args.size() == 1) 00050 return true; 00051 00052 if (args.size() == 3) { 00053 00054 int offset; 00055 if (sscanf(args[1].c_str(), "%d", &offset) != 1) { 00056 CommandTerminal::setErrorMessage("Invalid argument"); 00057 return false; 00058 } 00059 00060 if (lora::ChannelPlan::IsPlanDynamic(CommandTerminal::Dot()->getFrequencyBand())) { 00061 if (offset > 0) { 00062 CommandTerminal::setErrorMessage("Invalid offset, expects (0)"); 00063 return false; 00064 } 00065 } else { 00066 if (offset < 0 || offset > 4) { 00067 CommandTerminal::setErrorMessage("Invalid offset, expects (0-4)"); 00068 return false; 00069 } 00070 } 00071 00072 if (!isHexString(args[2], 2)) { 00073 CommandTerminal::setErrorMessage("Invalid mask, expect (0000-FFFF)"); 00074 return false; 00075 } 00076 00077 return true; 00078 } 00079 00080 CommandTerminal::setErrorMessage("Invalid arguments"); 00081 return false; 00082 }
Generated on Wed Jul 13 2022 08:58:48 by
1.7.2
