![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
AT terminal for the mDot using the USB debug port instead of the serial port.
Dependencies: MTS-Serial libmDot-mbed5
Fork of Dot-AT-Firmware by
CommandTerminal/CmdTxChannel.cpp@18:f5d28d621bb0, 2018-03-02 (annotated)
- Committer:
- pferland
- Date:
- Fri Mar 02 20:01:38 2018 +0000
- Revision:
- 18:f5d28d621bb0
- Parent:
- 16:d5cf2af81a6d
Added ability to force the AT terminal to use the USB debug port
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mike Fiore |
1:e52ae6584f1c | 1 | #include "CmdTxChannel.h" |
jenkins@jenkinsdm1 | 16:d5cf2af81a6d | 2 | #include "ChannelPlan.h" |
Mike Fiore |
1:e52ae6584f1c | 3 | |
Mike Fiore |
14:f9a77400b622 | 4 | CmdTxChannel::CmdTxChannel() |
Mike Fiore |
14:f9a77400b622 | 5 | : Command("Tx Channels", "AT+TXCH", "List Tx channel frequencies for sub-band", "<INDEX>,<FREQUENCY>,<DR_RANGE>") { |
Mike Fiore |
1:e52ae6584f1c | 6 | _queryable = true; |
Mike Fiore |
1:e52ae6584f1c | 7 | } |
Mike Fiore |
1:e52ae6584f1c | 8 | |
Mike Fiore |
1:e52ae6584f1c | 9 | uint32_t CmdTxChannel::action(std::vector<std::string> args) { |
Mike Fiore |
1:e52ae6584f1c | 10 | if (args.size() == 1) { |
Mike Fiore |
14:f9a77400b622 | 11 | |
Mike Fiore |
14:f9a77400b622 | 12 | std::vector<uint32_t> channels = CommandTerminal::Dot()->getChannels(); |
Mike Fiore |
14:f9a77400b622 | 13 | std::vector<uint8_t> ranges = CommandTerminal::Dot()->getChannelRanges(); |
Mike Fiore |
14:f9a77400b622 | 14 | std::vector<uint16_t> mask = CommandTerminal::Dot()->getChannelMask(); |
Mike Fiore |
14:f9a77400b622 | 15 | |
Mike Fiore |
14:f9a77400b622 | 16 | CommandTerminal::Serial()->writef("Index\tFrequency DR Max Min On\r\n"); |
Mike Fiore |
1:e52ae6584f1c | 17 | |
jenkins@jenkinsdm1 | 16:d5cf2af81a6d | 18 | if (lora::ChannelPlan::IsPlanDynamic(CommandTerminal::Dot()->getFrequencyBand())) { |
Mike Fiore |
14:f9a77400b622 | 19 | for (int8_t i = 0; i < 16; i++) { |
Mike Fiore |
14:f9a77400b622 | 20 | if (channels[i] != 0) |
Mike Fiore |
14:f9a77400b622 | 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); |
Mike Fiore |
14:f9a77400b622 | 22 | else |
Mike Fiore |
14:f9a77400b622 | 23 | CommandTerminal::Serial()->writef(" %d\t %d %X %X 0\r\n", i, channels[i], ranges[i] >> 4, ranges[i] & 0xF); |
Mike Fiore |
9:ff62b20f7000 | 24 | } |
Mike Fiore |
14:f9a77400b622 | 25 | |
Mike Fiore |
14:f9a77400b622 | 26 | if (channels[16] != 0) |
Mike Fiore |
14:f9a77400b622 | 27 | CommandTerminal::Serial()->writef(" R2\t%d %X %X\r\n", channels[16], ranges[16] >> 4, ranges[16] & 0xF); |
Mike Fiore |
14:f9a77400b622 | 28 | else |
Mike Fiore |
14:f9a77400b622 | 29 | CommandTerminal::Serial()->writef(" R2\t %d %X %X\r\n", channels[16], ranges[16], ranges[168]); |
Mike Fiore |
1:e52ae6584f1c | 30 | |
Mike Fiore |
1:e52ae6584f1c | 31 | } else { |
Mike Fiore |
14:f9a77400b622 | 32 | if (CommandTerminal::Dot()->getFrequencySubBand() > 0) { |
Mike Fiore |
14:f9a77400b622 | 33 | uint8_t offset = (CommandTerminal::Dot()->getFrequencySubBand() - 1) * 8; |
Mike Fiore |
9:ff62b20f7000 | 34 | |
Mike Fiore |
14:f9a77400b622 | 35 | for (int i = 0; i < 8; i++) { |
Mike Fiore |
14:f9a77400b622 | 36 | if ((CommandTerminal::Dot()->getFrequencySubBand() % 2) == 1) { |
Mike Fiore |
14:f9a77400b622 | 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); |
Mike Fiore |
14:f9a77400b622 | 38 | } else { |
Mike Fiore |
14:f9a77400b622 | 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); |
Mike Fiore |
14:f9a77400b622 | 40 | } |
Mike Fiore |
14:f9a77400b622 | 41 | } |
Mike Fiore |
14:f9a77400b622 | 42 | |
Mike Fiore |
14:f9a77400b622 | 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); |
Mike Fiore |
14:f9a77400b622 | 44 | CommandTerminal::Serial()->writef(" R2\t%d %X %X\r\n", channels[9], ranges[9], ranges[9]); |
Mike Fiore |
14:f9a77400b622 | 45 | } else { |
Mike Fiore |
14:f9a77400b622 | 46 | for (size_t i = 0; i < channels.size() - 1; i++) { |
Mike Fiore |
14:f9a77400b622 | 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); |
Mike Fiore |
14:f9a77400b622 | 48 | } |
Mike Fiore |
14:f9a77400b622 | 49 | uint8_t last = channels.size() - 1; |
Mike Fiore |
14:f9a77400b622 | 50 | CommandTerminal::Serial()->writef(" R2\t%d %X %X\r\n", channels[last], ranges[last], ranges[last]); |
Mike Fiore |
9:ff62b20f7000 | 51 | } |
Mike Fiore |
1:e52ae6584f1c | 52 | } |
Mike Fiore |
1:e52ae6584f1c | 53 | } |
Mike Fiore |
1:e52ae6584f1c | 54 | |
Mike Fiore |
9:ff62b20f7000 | 55 | if (args.size() == 4) { |
Mike Fiore |
9:ff62b20f7000 | 56 | int index; |
Mike Fiore |
9:ff62b20f7000 | 57 | int frequency; |
Mike Fiore |
9:ff62b20f7000 | 58 | int datarateRange; |
Mike Fiore |
9:ff62b20f7000 | 59 | |
Mike Fiore |
9:ff62b20f7000 | 60 | sscanf(args[1].c_str(), "%d", &index); |
Mike Fiore |
9:ff62b20f7000 | 61 | sscanf(args[2].c_str(), "%d", &frequency); |
Mike Fiore |
9:ff62b20f7000 | 62 | sscanf(args[3].c_str(), "%02x", &datarateRange); |
Mike Fiore |
9:ff62b20f7000 | 63 | |
jenkins@jenkinsdm1 | 16:d5cf2af81a6d | 64 | if (CommandTerminal::Dot()->addChannel(index, frequency, datarateRange) != mDot::MDOT_OK) { |
jenkins@jenkinsdm1 | 16:d5cf2af81a6d | 65 | CommandTerminal::setErrorMessage("Failed to add channel"); |
jenkins@jenkinsdm1 | 16:d5cf2af81a6d | 66 | return 1; |
jenkins@jenkinsdm1 | 16:d5cf2af81a6d | 67 | } |
Mike Fiore |
9:ff62b20f7000 | 68 | } |
Mike Fiore |
9:ff62b20f7000 | 69 | |
Mike Fiore |
1:e52ae6584f1c | 70 | return 0; |
Mike Fiore |
1:e52ae6584f1c | 71 | } |
Mike Fiore |
1:e52ae6584f1c | 72 | |
Mike Fiore |
9:ff62b20f7000 | 73 | bool CmdTxChannel::verify(std::vector<std::string> args) { |
Mike Fiore |
9:ff62b20f7000 | 74 | if (args.size() == 1) |
Mike Fiore |
9:ff62b20f7000 | 75 | return true; |
Mike Fiore |
9:ff62b20f7000 | 76 | |
Mike Fiore |
9:ff62b20f7000 | 77 | if (args.size() == 4) { |
Mike Fiore |
9:ff62b20f7000 | 78 | |
Mike Fiore |
9:ff62b20f7000 | 79 | int index; |
Mike Fiore |
9:ff62b20f7000 | 80 | int frequency; |
Mike Fiore |
9:ff62b20f7000 | 81 | int datarateRange; |
Mike Fiore |
9:ff62b20f7000 | 82 | |
Mike Fiore |
9:ff62b20f7000 | 83 | sscanf(args[1].c_str(), "%d", &index); |
Mike Fiore |
9:ff62b20f7000 | 84 | sscanf(args[2].c_str(), "%d", &frequency); |
Mike Fiore |
9:ff62b20f7000 | 85 | sscanf(args[3].c_str(), "%02x", &datarateRange); |
Mike Fiore |
9:ff62b20f7000 | 86 | |
jenkins@jenkinsdm1 | 16:d5cf2af81a6d | 87 | if (lora::ChannelPlan::IsPlanDynamic(CommandTerminal::Dot()->getFrequencyBand())) { |
jenkins@jenkinsdm1 | 16:d5cf2af81a6d | 88 | if (frequency != 0 && (frequency < int(CommandTerminal::Dot()->getMinFrequency()) || frequency > int(CommandTerminal::Dot()->getMaxFrequency()))) { |
jenkins@jenkinsdm1 | 16:d5cf2af81a6d | 89 | char tmp[256]; |
jenkins@jenkinsdm1 | 16:d5cf2af81a6d | 90 | sprintf(tmp, "Invalid frequency, expects (0,%lu-%lu)", CommandTerminal::Dot()->getMinFrequency(), CommandTerminal::Dot()->getMaxFrequency()); |
jenkins@jenkinsdm1 | 16:d5cf2af81a6d | 91 | CommandTerminal::setErrorMessage(tmp); |
Mike Fiore |
9:ff62b20f7000 | 92 | return false; |
Mike Fiore |
9:ff62b20f7000 | 93 | } |
Mike Fiore |
9:ff62b20f7000 | 94 | } else { |
jenkins@jenkinsdm1 | 16:d5cf2af81a6d | 95 | CommandTerminal::setErrorMessage("Fixed channel plans cannot be changed, use AT+FSB or AT+CHM to limit"); |
Mike Fiore |
9:ff62b20f7000 | 96 | return false; |
Mike Fiore |
9:ff62b20f7000 | 97 | } |
Mike Fiore |
9:ff62b20f7000 | 98 | |
Mike Fiore |
9:ff62b20f7000 | 99 | return true; |
Mike Fiore |
9:ff62b20f7000 | 100 | } else { |
Mike Fiore |
14:f9a77400b622 | 101 | CommandTerminal::setErrorMessage("Invalid arguments"); |
Mike Fiore |
9:ff62b20f7000 | 102 | return false; |
Mike Fiore |
9:ff62b20f7000 | 103 | } |
Mike Fiore |
9:ff62b20f7000 | 104 | |
Mike Fiore |
9:ff62b20f7000 | 105 | } |