firm newest
Dependencies: MTS-Serial libmDot-dev-mbed5-deprecated
CommandTerminal/CmdJoinRx2Datarate.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 "CmdJoinRx2Datarate.h" |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 2 | #include "CommandTerminal.h" |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 3 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 4 | CmdJoinRx2Datarate::CmdJoinRx2Datarate() |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 5 | : |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 6 | Command("Join Rx2 Datarate", "AT+JR2D", "Join Rx2 datarate", "(US:DR8-DR13,AU:DR8-DR13,EU:DR0-DR7)") { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 7 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 8 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 9 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 10 | uint32_t CmdJoinRx2Datarate::action(std::vector<std::string> args) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 11 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 12 | if (args.size() == 1) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 13 | CommandTerminal::Serial()->writef("%s\r\n", mDot::DataRateStr(CommandTerminal::Dot()->getJoinRx2DataRate()).c_str()); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 14 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 15 | else if (args.size() == 2) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 16 | std::string dr = mts::Text::toUpper(args[1]); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 17 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 18 | int datarate = 0; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 19 | uint8_t i; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 20 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 21 | int res = sscanf(dr.c_str(), "%d", &datarate); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 22 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 23 | if (res == 0) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 24 | for (i = 0; i < 16; i++) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 25 | if (mDot::DataRateStr(i).find(dr) != std::string::npos) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 26 | datarate = i; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 27 | break; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 28 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 29 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 30 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 31 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 32 | if (CommandTerminal::Dot()->setJoinRx2DataRate(datarate) != mDot::MDOT_OK) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 33 | CommandTerminal::setErrorMessage(CommandTerminal::Dot()->getLastError()); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 34 | return 1; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 35 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 36 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 37 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 38 | return 0; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 39 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 40 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 41 | bool CmdJoinRx2Datarate::verify(std::vector<std::string> args) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 42 | if (args.size() == 1) |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 43 | return true; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 44 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 45 | if (args.size() == 2) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 46 | return true; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 47 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 48 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 49 | CommandTerminal::setErrorMessage("Invalid arguments"); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 50 | return false; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 51 | } |