mDot AT-Firmware for testing
Dependencies: MTS-Serial libmDot-mbed5
Fork of Dot-AT-Firmware by
CommandTerminal/CmdWakeInterval.cpp@4:666017851052, 2015-08-18 (annotated)
- Committer:
- Mike Fiore
- Date:
- Tue Aug 18 11:21:43 2015 -0500
- Revision:
- 4:666017851052
- Child:
- 9:ff62b20f7000
update mdot-firmware to 0.1.2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mike Fiore |
4:666017851052 | 1 | #include "CmdWakeInterval.h" |
Mike Fiore |
4:666017851052 | 2 | |
Mike Fiore |
4:666017851052 | 3 | CmdWakeInterval::CmdWakeInterval(mDot* dot, mts::MTSSerial& serial) : |
Mike Fiore |
4:666017851052 | 4 | Command(dot, "Wake Interval", "AT+WI", "Wakeup interval (seconds)"), |
Mike Fiore |
4:666017851052 | 5 | _serial(serial) |
Mike Fiore |
4:666017851052 | 6 | { |
Mike Fiore |
4:666017851052 | 7 | _help = std::string(text()) + ": " + std::string(desc()); |
Mike Fiore |
4:666017851052 | 8 | _usage = "(2-2147483647) s"; |
Mike Fiore |
4:666017851052 | 9 | _queryable = true; |
Mike Fiore |
4:666017851052 | 10 | } |
Mike Fiore |
4:666017851052 | 11 | |
Mike Fiore |
4:666017851052 | 12 | uint32_t CmdWakeInterval::action(std::vector<std::string> args) |
Mike Fiore |
4:666017851052 | 13 | { |
Mike Fiore |
4:666017851052 | 14 | if (args.size() == 1) |
Mike Fiore |
4:666017851052 | 15 | { |
Mike Fiore |
4:666017851052 | 16 | if (_dot->getVerbose()) |
Mike Fiore |
4:666017851052 | 17 | _serial.writef("%s: ", name()); |
Mike Fiore |
4:666017851052 | 18 | |
Mike Fiore |
4:666017851052 | 19 | _serial.writef("%lu\r\n", _dot->getWakeInterval()); |
Mike Fiore |
4:666017851052 | 20 | } |
Mike Fiore |
4:666017851052 | 21 | else if (args.size() == 2) |
Mike Fiore |
4:666017851052 | 22 | { |
Mike Fiore |
4:666017851052 | 23 | int32_t code; |
Mike Fiore |
4:666017851052 | 24 | uint32_t timeout; |
Mike Fiore |
4:666017851052 | 25 | sscanf(args[1].c_str(), "%lu", &timeout); |
Mike Fiore |
4:666017851052 | 26 | |
Mike Fiore |
4:666017851052 | 27 | if ((code = _dot->setWakeInterval(timeout)) != mDot::MDOT_OK) { |
Mike Fiore |
4:666017851052 | 28 | std::string error = mDot::getReturnCodeString(code) + " - " + _dot->getLastError(); |
Mike Fiore |
4:666017851052 | 29 | setErrorMessage(error); |
Mike Fiore |
4:666017851052 | 30 | return 1; |
Mike Fiore |
4:666017851052 | 31 | } |
Mike Fiore |
4:666017851052 | 32 | } |
Mike Fiore |
4:666017851052 | 33 | |
Mike Fiore |
4:666017851052 | 34 | return 0; |
Mike Fiore |
4:666017851052 | 35 | } |
Mike Fiore |
4:666017851052 | 36 | |
Mike Fiore |
4:666017851052 | 37 | bool CmdWakeInterval::verify(std::vector<std::string> args) |
Mike Fiore |
4:666017851052 | 38 | { |
Mike Fiore |
4:666017851052 | 39 | if (args.size() == 1) |
Mike Fiore |
4:666017851052 | 40 | return true; |
Mike Fiore |
4:666017851052 | 41 | |
Mike Fiore |
4:666017851052 | 42 | if (args.size() == 2) { |
Mike Fiore |
4:666017851052 | 43 | uint32_t timeout; |
Mike Fiore |
4:666017851052 | 44 | if (sscanf(args[1].c_str(), "%lu", &timeout) != 1) { |
Mike Fiore |
4:666017851052 | 45 | setErrorMessage("Invalid argument"); |
Mike Fiore |
4:666017851052 | 46 | return false; |
Mike Fiore |
4:666017851052 | 47 | } |
Mike Fiore |
4:666017851052 | 48 | |
Mike Fiore |
4:666017851052 | 49 | if (timeout < 2 || timeout > INT_MAX) { |
Mike Fiore |
4:666017851052 | 50 | setErrorMessage("Invalid interval, expects (2-2147483647) s"); |
Mike Fiore |
4:666017851052 | 51 | return false; |
Mike Fiore |
4:666017851052 | 52 | } |
Mike Fiore |
4:666017851052 | 53 | |
Mike Fiore |
4:666017851052 | 54 | return true; |
Mike Fiore |
4:666017851052 | 55 | } |
Mike Fiore |
4:666017851052 | 56 | |
Mike Fiore |
4:666017851052 | 57 | setErrorMessage("Invalid arguments"); |
Mike Fiore |
4:666017851052 | 58 | return false; |
Mike Fiore |
4:666017851052 | 59 | } |