firm newest
Dependencies: MTS-Serial libmDot-dev-mbed5-deprecated
CommandTerminal/CmdChannelMask.cpp@1:c1c6549b9333, 2018-10-22 (annotated)
- Committer:
- nguyenhoang9x5555
- Date:
- Mon Oct 22 01:56:09 2018 +0000
- Revision:
- 1:c1c6549b9333
- Parent:
- 0:3c869a8cb8f8
hey
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 1 | #include "CmdChannelMask.h" |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 2 | #include "ChannelPlan.h" |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 3 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 4 | CmdChannelMask::CmdChannelMask() |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 5 | : |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 6 | Command("Channel Mask", "AT+CHM", "Get/set channel mask (OFFSET:0-4,MASK:0000-FFFF)", "(OFFSET:0-4,MASK:0000-FFFF)") |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 7 | { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 8 | _queryable = true; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 9 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 10 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 11 | uint32_t CmdChannelMask::action(std::vector<std::string> args) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 12 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 13 | if (args.size() == 1) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 14 | if (CommandTerminal::Dot()->getVerbose()) |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 15 | CommandTerminal::Serial()->writef("Channel Mask: "); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 16 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 17 | std::vector<uint16_t> mask = CommandTerminal::Dot()->getChannelMask(); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 18 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 19 | for (int i = int(mask.size()) - 1; i >= 0; i--) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 20 | CommandTerminal::Serial()->writef("%04X", mask[i]); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 21 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 22 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 23 | CommandTerminal::Serial()->writef("\r\n"); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 24 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 25 | } else if (args.size() == 3) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 26 | int code = 0; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 27 | int temp = 0; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 28 | int offset = 0; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 29 | uint16_t mask = 0; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 30 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 31 | sscanf(args[1].c_str(), "%d", &offset); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 32 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 33 | // Convert the ASCII hex data to binary... |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 34 | sscanf(&args[2][0], "%02x", &temp); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 35 | mask = uint8_t(temp) << 8; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 36 | sscanf(&args[2][2], "%02x", &temp); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 37 | mask |= uint8_t(temp); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 38 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 39 | if ((code = CommandTerminal::Dot()->setChannelMask(offset, mask)) != mDot::MDOT_OK) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 40 | CommandTerminal::setErrorMessage(CommandTerminal::Dot()->getLastError()); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 41 | return 1; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 42 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 43 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 44 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 45 | return 0; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 46 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 47 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 48 | bool CmdChannelMask::verify(std::vector<std::string> args) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 49 | if (args.size() == 1) |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 50 | return true; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 51 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 52 | if (args.size() == 3) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 53 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 54 | int offset; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 55 | if (sscanf(args[1].c_str(), "%d", &offset) != 1) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 56 | CommandTerminal::setErrorMessage("Invalid argument"); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 57 | return false; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 58 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 59 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 60 | if (lora::ChannelPlan::IsPlanDynamic(CommandTerminal::Dot()->getFrequencyBand())) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 61 | if (offset > 0) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 62 | CommandTerminal::setErrorMessage("Invalid offset, expects (0)"); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 63 | return false; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 64 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 65 | } else { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 66 | if (offset < 0 || offset > 4) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 67 | CommandTerminal::setErrorMessage("Invalid offset, expects (0-4)"); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 68 | return false; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 69 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 70 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 71 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 72 | if (!isHexString(args[2], 2)) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 73 | CommandTerminal::setErrorMessage("Invalid mask, expect (0000-FFFF)"); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 74 | return false; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 75 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 76 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 77 | return true; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 78 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 79 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 80 | CommandTerminal::setErrorMessage("Invalid arguments"); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 81 | return false; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 82 | } |