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