firm newest
Dependencies: MTS-Serial libmDot-dev-mbed5-deprecated
CommandTerminal/CmdLbt.cpp@0:3c869a8cb8f8, 2018-10-18 (annotated)
- Committer:
- nguyenhoang9x5555
- Date:
- Thu Oct 18 04:18:48 2018 +0000
- Revision:
- 0:3c869a8cb8f8
DOT AT FIRMWARE 18102018
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 1 | #include "CmdLbt.h" |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 2 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 3 | CmdLbt::CmdLbt() : |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 4 | Command("Listen Before Talk", "AT+LBT", "Enable/Disable listen before talk (0,0: disable, time,threshold: enable)", "time(0-65535 us),threshold(-127-128 dBm) (0,0: disable, time,threshold: enable)") |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 5 | { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 6 | _queryable = true; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 7 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 8 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 9 | uint32_t CmdLbt::action(std::vector<std::string> args) |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 10 | { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 11 | if (args.size() == 1) |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 12 | { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 13 | CommandTerminal::Serial()->writef("%u,%d\r\n", CommandTerminal::Dot()->getLbtTimeUs(), CommandTerminal::Dot()->getLbtThreshold()); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 14 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 15 | else |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 16 | { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 17 | uint32_t us; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 18 | int32_t rssi; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 19 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 20 | sscanf(args[1].c_str(), "%lu", &us); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 21 | sscanf(args[2].c_str(), "%ld", &rssi); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 22 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 23 | CommandTerminal::Dot()->setLbtTimeUs((uint16_t)us); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 24 | CommandTerminal::Dot()->setLbtThreshold((int8_t)rssi); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 25 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 26 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 27 | return 0; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 28 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 29 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 30 | bool CmdLbt::verify(std::vector<std::string> args) |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 31 | { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 32 | if (args.size() == 1) |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 33 | return true; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 34 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 35 | if (args.size() == 3) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 36 | uint32_t us; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 37 | int32_t rssi; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 38 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 39 | if (args[1].find("-") != std::string::npos || sscanf(args[1].c_str(), "%lu", &us) != 1 || us > 65535) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 40 | CommandTerminal::setErrorMessage("Invalid LBT time, expects 0-65535 us"); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 41 | return false; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 42 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 43 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 44 | if (sscanf(args[2].c_str(), "%ld", &rssi) != 1 || rssi < -127 || rssi > 128) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 45 | CommandTerminal::setErrorMessage("Invalid LBT threshold, expects -127-128 dBm"); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 46 | return false; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 47 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 48 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 49 | return true; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 50 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 51 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 52 | CommandTerminal::setErrorMessage("Invalid arguments"); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 53 | return false; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 54 | } |