mDot AT-Firmware for testing
Dependencies: MTS-Serial libmDot-mbed5
Fork of Dot-AT-Firmware by
CommandTerminal/CmdFrequencyBand.cpp@16:3b1d46c1db11, 2017-08-14 (annotated)
- Committer:
- Fran6
- Date:
- Mon Aug 14 12:40:21 2017 +0000
- Revision:
- 16:3b1d46c1db11
- Parent:
- 14:f9a77400b622
mDot AT-Firmware
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mike Fiore |
1:e52ae6584f1c | 1 | #include "CmdFrequencyBand.h" |
Mike Fiore |
1:e52ae6584f1c | 2 | |
Mike Fiore |
14:f9a77400b622 | 3 | |
Mike Fiore |
14:f9a77400b622 | 4 | CmdFrequencyBand::CmdFrequencyBand() : |
Mike Fiore |
14:f9a77400b622 | 5 | Command("Frequency Band", "AT+FREQ", "Configured Frequency Band 'EU868', 'US915' or 'AU915'", "(EU868,US915,AU915)") |
Mike Fiore |
1:e52ae6584f1c | 6 | { |
Mike Fiore |
1:e52ae6584f1c | 7 | _queryable = true; |
Mike Fiore |
1:e52ae6584f1c | 8 | } |
Mike Fiore |
1:e52ae6584f1c | 9 | |
Mike Fiore |
1:e52ae6584f1c | 10 | uint32_t CmdFrequencyBand::action(std::vector<std::string> args) |
Mike Fiore |
14:f9a77400b622 | 11 | { |
Mike Fiore |
1:e52ae6584f1c | 12 | if (args.size() == 1) |
Mike Fiore |
1:e52ae6584f1c | 13 | { |
Mike Fiore |
14:f9a77400b622 | 14 | CommandTerminal::Serial()->writef("%s\r\n", mDot::FrequencyBandStr(CommandTerminal::Dot()->getFrequencyBand()).c_str()); |
Mike Fiore |
14:f9a77400b622 | 15 | } |
Mike Fiore |
14:f9a77400b622 | 16 | |
Mike Fiore |
14:f9a77400b622 | 17 | #ifdef DEBUG_MAC |
Mike Fiore |
14:f9a77400b622 | 18 | else if (args.size() == 2) |
Mike Fiore |
14:f9a77400b622 | 19 | { |
Mike Fiore |
14:f9a77400b622 | 20 | uint8_t band = mDot::FB_US915; |
Mike Fiore |
14:f9a77400b622 | 21 | std::string band_str = mts::Text::toUpper(args[1]); |
Mike Fiore |
14:f9a77400b622 | 22 | |
Mike Fiore |
1:e52ae6584f1c | 23 | |
Mike Fiore |
14:f9a77400b622 | 24 | if (mDot::FrequencyBandStr(mDot::FB_EU868).find(band_str) != std::string::npos) { |
Mike Fiore |
14:f9a77400b622 | 25 | band = mDot::FB_EU868; |
Mike Fiore |
14:f9a77400b622 | 26 | } |
Mike Fiore |
14:f9a77400b622 | 27 | if (mDot::FrequencyBandStr(mDot::FB_AU915).find(band_str) != std::string::npos) { |
Mike Fiore |
14:f9a77400b622 | 28 | band = mDot::FB_AU915; |
Mike Fiore |
14:f9a77400b622 | 29 | } |
Mike Fiore |
14:f9a77400b622 | 30 | if (mDot::FrequencyBandStr(mDot::FB_US915).find(band_str) != std::string::npos) { |
Mike Fiore |
14:f9a77400b622 | 31 | band = mDot::FB_US915; |
Mike Fiore |
14:f9a77400b622 | 32 | } |
Mike Fiore |
14:f9a77400b622 | 33 | |
Mike Fiore |
14:f9a77400b622 | 34 | if (CommandTerminal::Dot()->setFrequencyBand(band) != mDot::MDOT_OK) { |
Mike Fiore |
14:f9a77400b622 | 35 | CommandTerminal::setErrorMessage(CommandTerminal::Dot()->getLastError());; |
Mike Fiore |
14:f9a77400b622 | 36 | return 1; |
Mike Fiore |
14:f9a77400b622 | 37 | } |
Mike Fiore |
1:e52ae6584f1c | 38 | } |
Mike Fiore |
14:f9a77400b622 | 39 | #endif |
Mike Fiore |
1:e52ae6584f1c | 40 | |
Mike Fiore |
1:e52ae6584f1c | 41 | return 0; |
Mike Fiore |
1:e52ae6584f1c | 42 | } |
Mike Fiore |
1:e52ae6584f1c | 43 | |
Mike Fiore |
1:e52ae6584f1c | 44 | bool CmdFrequencyBand::verify(std::vector<std::string> args) |
Mike Fiore |
14:f9a77400b622 | 45 | { |
Mike Fiore |
1:e52ae6584f1c | 46 | if (args.size() == 1) |
Mike Fiore |
1:e52ae6584f1c | 47 | return true; |
Mike Fiore |
1:e52ae6584f1c | 48 | |
Mike Fiore |
14:f9a77400b622 | 49 | #ifdef DEBUG_MAC |
Mike Fiore |
14:f9a77400b622 | 50 | if (args.size() == 2) |
Mike Fiore |
14:f9a77400b622 | 51 | { |
Mike Fiore |
14:f9a77400b622 | 52 | std::string band = mts::Text::toUpper(args[1]); |
Mike Fiore |
14:f9a77400b622 | 53 | |
Mike Fiore |
14:f9a77400b622 | 54 | if (mDot::FrequencyBandStr(mDot::FB_EU868).find(band) == std::string::npos && |
Mike Fiore |
14:f9a77400b622 | 55 | mDot::FrequencyBandStr(mDot::FB_US915).find(band) == std::string::npos && |
Mike Fiore |
14:f9a77400b622 | 56 | mDot::FrequencyBandStr(mDot::FB_AU915).find(band) == std::string::npos) |
Mike Fiore |
14:f9a77400b622 | 57 | { |
Mike Fiore |
14:f9a77400b622 | 58 | CommandTerminal::setErrorMessage("Invalid parameter, expects (EU868,US915,AU915)"); |
Mike Fiore |
14:f9a77400b622 | 59 | return false; |
Mike Fiore |
14:f9a77400b622 | 60 | } |
Mike Fiore |
14:f9a77400b622 | 61 | |
Mike Fiore |
14:f9a77400b622 | 62 | return true; |
Mike Fiore |
14:f9a77400b622 | 63 | } |
Mike Fiore |
14:f9a77400b622 | 64 | #endif |
Mike Fiore |
14:f9a77400b622 | 65 | |
Mike Fiore |
14:f9a77400b622 | 66 | CommandTerminal::setErrorMessage("Invalid arguments"); |
Mike Fiore |
1:e52ae6584f1c | 67 | return false; |
Mike Fiore |
1:e52ae6584f1c | 68 | } |