firm newest
Dependencies: MTS-Serial libmDot-dev-mbed5-deprecated
CommandTerminal/CmdTxPower.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 "CmdTxPower.h" |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 2 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 3 | CmdTxPower::CmdTxPower() : |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 4 | Command("Tx Power", "AT+TXP", "Set the radio TX power before antenna gain in dBm", "(2-36, Depends on Channel Plan)") { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 5 | _queryable = true; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 6 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 7 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 8 | uint32_t CmdTxPower::action(std::vector<std::string> args) |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 9 | { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 10 | if (args.size() == 1) |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 11 | { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 12 | CommandTerminal::Serial()->writef("%lu\r\n", CommandTerminal::Dot()->getTxPower()); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 13 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 14 | else if (args.size() == 2) |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 15 | { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 16 | int power = 0; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 17 | sscanf(args[1].c_str(), "%d", &power); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 18 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 19 | if (CommandTerminal::Dot()->setTxPower(power) != mDot::MDOT_OK) |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 20 | { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 21 | CommandTerminal::setErrorMessage(CommandTerminal::Dot()->getLastError());; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 22 | return 1; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 23 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 24 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 25 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 26 | return 0; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 27 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 28 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 29 | bool CmdTxPower::verify(std::vector<std::string> args) |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 30 | { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 31 | if (args.size() == 1) |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 32 | return true; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 33 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 34 | if (args.size() == 2) |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 35 | { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 36 | int power = 0; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 37 | if (sscanf(args[1].c_str(), "%d", &power) != 1) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 38 | CommandTerminal::setErrorMessage("Invalid argument"); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 39 | return false; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 40 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 41 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 42 | if (power < CommandTerminal::Dot()->getMinTxPower() || power > CommandTerminal::Dot()->getMaxTxPower()) |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 43 | { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 44 | char buf[8]; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 45 | std::string error = "Invalid power, expects "; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 46 | snprintf(buf, sizeof(buf), "(%d-%d)", CommandTerminal::Dot()->getMinTxPower(), CommandTerminal::Dot()->getMaxTxPower()); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 47 | error.append(buf); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 48 | CommandTerminal::setErrorMessage(error); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 49 | return false; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 50 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 51 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 52 | return true; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 53 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 54 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 55 | CommandTerminal::setErrorMessage("Invalid arguments"); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 56 | return false; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 57 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 58 |