firm newest
Dependencies: MTS-Serial libmDot-dev-mbed5-deprecated
CommandTerminal/CmdTxChannel.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 "CmdTxChannel.h" |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 2 | #include "ChannelPlan.h" |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 3 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 4 | CmdTxChannel::CmdTxChannel() |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 5 | : Command("Tx Channels", "AT+TXCH", "List Tx channel frequencies for sub-band", "<INDEX>,<FREQUENCY>,<DR_RANGE>") { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 6 | _queryable = true; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 7 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 8 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 9 | uint32_t CmdTxChannel::action(std::vector<std::string> args) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 10 | if (args.size() == 1) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 11 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 12 | std::vector<uint32_t> channels = CommandTerminal::Dot()->getChannels(); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 13 | std::vector<uint8_t> ranges = CommandTerminal::Dot()->getChannelRanges(); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 14 | std::vector<uint16_t> mask = CommandTerminal::Dot()->getChannelMask(); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 15 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 16 | CommandTerminal::Serial()->writef("Index\tFrequency DR Max Min On\r\n"); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 17 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 18 | if (lora::ChannelPlan::IsPlanDynamic(CommandTerminal::Dot()->getFrequencyBand())) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 19 | for (int8_t i = 0; i < 16; i++) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 20 | if (channels[i] != 0) |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 21 | CommandTerminal::Serial()->writef(" %d\t%d %X %X %d\r\n", i, channels[i], ranges[i] >> 4, ranges[i] & 0xF, (mask[0] & (0x1 << i)) ? 1 : 0); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 22 | else |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 23 | CommandTerminal::Serial()->writef(" %d\t %d %X %X 0\r\n", i, channels[i], ranges[i] >> 4, ranges[i] & 0xF); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 24 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 25 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 26 | if (channels[16] != 0) |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 27 | CommandTerminal::Serial()->writef(" R2\t%d %X %X\r\n", channels[16], ranges[16] >> 4, ranges[16] & 0xF); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 28 | else |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 29 | CommandTerminal::Serial()->writef(" R2\t %d %X %X\r\n", channels[16], ranges[16], ranges[168]); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 30 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 31 | } else { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 32 | if (CommandTerminal::Dot()->getFrequencySubBand() > 0) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 33 | uint8_t offset = (CommandTerminal::Dot()->getFrequencySubBand() - 1) * 8; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 34 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 35 | for (int i = 0; i < 8; i++) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 36 | if ((CommandTerminal::Dot()->getFrequencySubBand() % 2) == 1) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 37 | CommandTerminal::Serial()->writef(" %d\t%d %X %X %d\r\n", i, channels[i], ranges[i] >> 4, ranges[i] & 0xF, (mask[(offset + i)/16] & (0x0001 << i)) ? 1 : 0); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 38 | } else { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 39 | CommandTerminal::Serial()->writef(" %d\t%d %X %X %d\r\n", i, channels[i], ranges[i] >> 4, ranges[i] & 0xF, (mask[(offset + i)/16] & (0x0001 << (i + 8))) ? 1 : 0); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 40 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 41 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 42 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 43 | CommandTerminal::Serial()->writef(" U\t%d %X %X %d\r\n", channels[8], ranges[8] >> 4, ranges[8] & 0xF, (mask[4] & (0x0001 << (CommandTerminal::Dot()->getFrequencySubBand() - 1))) ? 1 : 0); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 44 | CommandTerminal::Serial()->writef(" R2\t%d %X %X\r\n", channels[9], ranges[9], ranges[9]); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 45 | } else { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 46 | for (size_t i = 0; i < channels.size() - 1; i++) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 47 | CommandTerminal::Serial()->writef(" %d\t%d %X %X %d\r\n", i, channels[i], ranges[i] >> 4, ranges[i] & 0xF, (mask[i/16] & (0x0001 << (i%16))) ? 1 : 0); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 48 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 49 | uint8_t last = channels.size() - 1; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 50 | CommandTerminal::Serial()->writef(" R2\t%d %X %X\r\n", channels[last], ranges[last], ranges[last]); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 51 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 52 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 53 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 54 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 55 | if (args.size() == 4) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 56 | int index; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 57 | int frequency; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 58 | int datarateRange; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 59 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 60 | sscanf(args[1].c_str(), "%d", &index); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 61 | sscanf(args[2].c_str(), "%d", &frequency); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 62 | sscanf(args[3].c_str(), "%02x", &datarateRange); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 63 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 64 | if (CommandTerminal::Dot()->addChannel(index, frequency, datarateRange) != mDot::MDOT_OK) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 65 | CommandTerminal::setErrorMessage("Failed to add channel"); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 66 | return 1; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 67 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 68 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 69 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 70 | return 0; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 71 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 72 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 73 | bool CmdTxChannel::verify(std::vector<std::string> args) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 74 | if (args.size() == 1) |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 75 | return true; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 76 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 77 | if (args.size() == 4) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 78 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 79 | int index; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 80 | int frequency; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 81 | int datarateRange; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 82 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 83 | sscanf(args[1].c_str(), "%d", &index); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 84 | sscanf(args[2].c_str(), "%d", &frequency); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 85 | sscanf(args[3].c_str(), "%02x", &datarateRange); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 86 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 87 | if (lora::ChannelPlan::IsPlanDynamic(CommandTerminal::Dot()->getFrequencyBand())) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 88 | if (frequency != 0 && (frequency < int(CommandTerminal::Dot()->getMinFrequency()) || frequency > int(CommandTerminal::Dot()->getMaxFrequency()))) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 89 | char tmp[256]; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 90 | sprintf(tmp, "Invalid frequency, expects (0,%lu-%lu)", CommandTerminal::Dot()->getMinFrequency(), CommandTerminal::Dot()->getMaxFrequency()); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 91 | CommandTerminal::setErrorMessage(tmp); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 92 | return false; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 93 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 94 | } else { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 95 | CommandTerminal::setErrorMessage("Fixed channel plans cannot be changed, use AT+FSB or AT+CHM to limit"); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 96 | return false; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 97 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 98 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 99 | return true; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 100 | } else { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 101 | CommandTerminal::setErrorMessage("Invalid arguments"); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 102 | return false; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 103 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 104 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 105 | } |