few changes for RTS/CTS control
Dependencies: MTS-Serial libmDot mbed-rtos mbed
Fork of mDot_AT_firmware by
CommandTerminal/CmdTxDataRate.cpp@1:e52ae6584f1c, 2015-06-25 (annotated)
- Committer:
- Mike Fiore
- Date:
- Thu Jun 25 10:23:41 2015 -0500
- Revision:
- 1:e52ae6584f1c
- Child:
- 9:ff62b20f7000
update debug, add command source files
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mike Fiore |
1:e52ae6584f1c | 1 | #include "CmdTxDataRate.h" |
Mike Fiore |
1:e52ae6584f1c | 2 | |
Mike Fiore |
1:e52ae6584f1c | 3 | CmdTxDataRate::CmdTxDataRate(mDot* dot, mts::MTSSerial& serial) : |
Mike Fiore |
1:e52ae6584f1c | 4 | Command(dot, "Tx Data Rate", "AT+TXDR", "Set the Tx data rate for all channels"), _serial(serial) |
Mike Fiore |
1:e52ae6584f1c | 5 | { |
Mike Fiore |
1:e52ae6584f1c | 6 | _help = std::string(text()) + ": " + std::string(desc()); |
Mike Fiore |
1:e52ae6584f1c | 7 | |
Mike Fiore |
1:e52ae6584f1c | 8 | if (_dot->getFrequencyBand() == mDot::FB_915) |
Mike Fiore |
1:e52ae6584f1c | 9 | _usage = "(7-10)"; |
Mike Fiore |
1:e52ae6584f1c | 10 | else |
Mike Fiore |
1:e52ae6584f1c | 11 | _usage = "(7-12)"; |
Mike Fiore |
1:e52ae6584f1c | 12 | _queryable = true; |
Mike Fiore |
1:e52ae6584f1c | 13 | } |
Mike Fiore |
1:e52ae6584f1c | 14 | |
Mike Fiore |
1:e52ae6584f1c | 15 | uint32_t CmdTxDataRate::action(std::vector<std::string> args) |
Mike Fiore |
1:e52ae6584f1c | 16 | { |
Mike Fiore |
1:e52ae6584f1c | 17 | if (args.size() == 1) |
Mike Fiore |
1:e52ae6584f1c | 18 | { |
Mike Fiore |
1:e52ae6584f1c | 19 | if (_dot->getVerbose()) |
Mike Fiore |
1:e52ae6584f1c | 20 | _serial.writef("Tx Data Rate: "); |
Mike Fiore |
1:e52ae6584f1c | 21 | |
Mike Fiore |
1:e52ae6584f1c | 22 | _serial.writef("%s\r\n", mDot::DataRateStr(_dot->getTxDataRate()).c_str()); |
Mike Fiore |
1:e52ae6584f1c | 23 | } |
Mike Fiore |
1:e52ae6584f1c | 24 | else if (args.size() == 2) |
Mike Fiore |
1:e52ae6584f1c | 25 | { |
Mike Fiore |
1:e52ae6584f1c | 26 | int32_t code; |
Mike Fiore |
1:e52ae6584f1c | 27 | uint8_t datarate = 0; |
Mike Fiore |
1:e52ae6584f1c | 28 | uint8_t i; |
Mike Fiore |
1:e52ae6584f1c | 29 | |
Mike Fiore |
1:e52ae6584f1c | 30 | for (i = 0; i < 8; i++) |
Mike Fiore |
1:e52ae6584f1c | 31 | { |
Mike Fiore |
1:e52ae6584f1c | 32 | if (mDot::DataRateStr(i).find(args[1].c_str()) != std::string::npos) |
Mike Fiore |
1:e52ae6584f1c | 33 | { |
Mike Fiore |
1:e52ae6584f1c | 34 | datarate = i; |
Mike Fiore |
1:e52ae6584f1c | 35 | break; |
Mike Fiore |
1:e52ae6584f1c | 36 | } |
Mike Fiore |
1:e52ae6584f1c | 37 | } |
Mike Fiore |
1:e52ae6584f1c | 38 | |
Mike Fiore |
1:e52ae6584f1c | 39 | if ((code = _dot->setTxDataRate(datarate)) != mDot::MDOT_OK) |
Mike Fiore |
1:e52ae6584f1c | 40 | { |
Mike Fiore |
1:e52ae6584f1c | 41 | std::string error = mDot::getReturnCodeString(code) + " - " + _dot->getLastError(); |
Mike Fiore |
1:e52ae6584f1c | 42 | setErrorMessage(error); |
Mike Fiore |
1:e52ae6584f1c | 43 | return 1; |
Mike Fiore |
1:e52ae6584f1c | 44 | } |
Mike Fiore |
1:e52ae6584f1c | 45 | } |
Mike Fiore |
1:e52ae6584f1c | 46 | |
Mike Fiore |
1:e52ae6584f1c | 47 | return 0; |
Mike Fiore |
1:e52ae6584f1c | 48 | } |
Mike Fiore |
1:e52ae6584f1c | 49 | |
Mike Fiore |
1:e52ae6584f1c | 50 | bool CmdTxDataRate::verify(std::vector<std::string> args) |
Mike Fiore |
1:e52ae6584f1c | 51 | { |
Mike Fiore |
1:e52ae6584f1c | 52 | if (args.size() == 1) |
Mike Fiore |
1:e52ae6584f1c | 53 | return true; |
Mike Fiore |
1:e52ae6584f1c | 54 | |
Mike Fiore |
1:e52ae6584f1c | 55 | if (args.size() == 2) |
Mike Fiore |
1:e52ae6584f1c | 56 | { |
Mike Fiore |
1:e52ae6584f1c | 57 | uint8_t i; |
Mike Fiore |
1:e52ae6584f1c | 58 | int datarate = -1; |
Mike Fiore |
1:e52ae6584f1c | 59 | for (i = 0; i < 8; i++) |
Mike Fiore |
1:e52ae6584f1c | 60 | { |
Mike Fiore |
1:e52ae6584f1c | 61 | if (mDot::DataRateStr(i).find(args[1].c_str()) != std::string::npos) |
Mike Fiore |
1:e52ae6584f1c | 62 | { |
Mike Fiore |
1:e52ae6584f1c | 63 | datarate = i; |
Mike Fiore |
1:e52ae6584f1c | 64 | break; |
Mike Fiore |
1:e52ae6584f1c | 65 | } |
Mike Fiore |
1:e52ae6584f1c | 66 | } |
Mike Fiore |
1:e52ae6584f1c | 67 | |
Mike Fiore |
1:e52ae6584f1c | 68 | if (datarate < 0) |
Mike Fiore |
1:e52ae6584f1c | 69 | { |
Mike Fiore |
1:e52ae6584f1c | 70 | if (_dot->getFrequencyBand() == mDot::FB_915) |
Mike Fiore |
1:e52ae6584f1c | 71 | setErrorMessage("Invalid data rate, expects (7-10)"); |
Mike Fiore |
1:e52ae6584f1c | 72 | else |
Mike Fiore |
1:e52ae6584f1c | 73 | setErrorMessage("Invalid data rate, expects (7-12)"); |
Mike Fiore |
1:e52ae6584f1c | 74 | return false; |
Mike Fiore |
1:e52ae6584f1c | 75 | } |
Mike Fiore |
1:e52ae6584f1c | 76 | |
Mike Fiore |
1:e52ae6584f1c | 77 | if (_dot->getFrequencyBand() == mDot::FB_915) { |
Mike Fiore |
1:e52ae6584f1c | 78 | if (datarate < 2) { |
Mike Fiore |
1:e52ae6584f1c | 79 | setErrorMessage("Invalid data rate, expects (7-10)"); |
Mike Fiore |
1:e52ae6584f1c | 80 | return false; |
Mike Fiore |
1:e52ae6584f1c | 81 | } |
Mike Fiore |
1:e52ae6584f1c | 82 | } |
Mike Fiore |
1:e52ae6584f1c | 83 | |
Mike Fiore |
1:e52ae6584f1c | 84 | return true; |
Mike Fiore |
1:e52ae6584f1c | 85 | } |
Mike Fiore |
1:e52ae6584f1c | 86 | |
Mike Fiore |
1:e52ae6584f1c | 87 | setErrorMessage("Invalid arguments"); |
Mike Fiore |
1:e52ae6584f1c | 88 | return false; |
Mike Fiore |
1:e52ae6584f1c | 89 | } |