few changes for RTS/CTS control
Dependencies: MTS-Serial libmDot mbed-rtos mbed
Fork of mDot_AT_firmware by
CommandTerminal/CmdUplinkCounter.cpp@11:77b7911263da, 2016-10-25 (annotated)
- Committer:
- serg838
- Date:
- Tue Oct 25 05:39:39 2016 +0000
- Revision:
- 11:77b7911263da
- Parent:
- 9:ff62b20f7000
RTS/CTS changes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mike Fiore |
9:ff62b20f7000 | 1 | #include "CmdUplinkCounter.h" |
Mike Fiore |
9:ff62b20f7000 | 2 | |
Mike Fiore |
9:ff62b20f7000 | 3 | CmdUplinkCounter::CmdUplinkCounter(mDot* dot, mts::MTSSerial& serial) |
Mike Fiore |
9:ff62b20f7000 | 4 | : |
Mike Fiore |
9:ff62b20f7000 | 5 | Command(dot, "Uplink Counter", "AT+ULC", "Get or set the uplink counter for the next packet"), |
Mike Fiore |
9:ff62b20f7000 | 6 | _serial(serial) { |
Mike Fiore |
9:ff62b20f7000 | 7 | _help = std::string(text()) + ": " + std::string(desc()); |
Mike Fiore |
9:ff62b20f7000 | 8 | _usage = "(0-4294967295)"; |
Mike Fiore |
9:ff62b20f7000 | 9 | _queryable = true; |
Mike Fiore |
9:ff62b20f7000 | 10 | } |
Mike Fiore |
9:ff62b20f7000 | 11 | |
Mike Fiore |
9:ff62b20f7000 | 12 | uint32_t CmdUplinkCounter::action(std::vector<std::string> args) { |
Mike Fiore |
9:ff62b20f7000 | 13 | if (args.size() == 1) { |
Mike Fiore |
9:ff62b20f7000 | 14 | if (_dot->getVerbose()) |
Mike Fiore |
9:ff62b20f7000 | 15 | _serial.writef("Uplink Counter: "); |
Mike Fiore |
9:ff62b20f7000 | 16 | |
Mike Fiore |
9:ff62b20f7000 | 17 | _serial.writef("%u\r\n", _dot->getUpLinkCounter()); |
Mike Fiore |
9:ff62b20f7000 | 18 | } else if (args.size() == 2) { |
Mike Fiore |
9:ff62b20f7000 | 19 | int32_t code; |
Mike Fiore |
9:ff62b20f7000 | 20 | int count; |
Mike Fiore |
9:ff62b20f7000 | 21 | sscanf(args[1].c_str(), "%d", &count); |
Mike Fiore |
9:ff62b20f7000 | 22 | |
Mike Fiore |
9:ff62b20f7000 | 23 | if ((code = _dot->setUpLinkCounter(count)) != mDot::MDOT_OK) { |
Mike Fiore |
9:ff62b20f7000 | 24 | setErrorMessage(_dot->getLastError());; |
Mike Fiore |
9:ff62b20f7000 | 25 | return 1; |
Mike Fiore |
9:ff62b20f7000 | 26 | } |
Mike Fiore |
9:ff62b20f7000 | 27 | } |
Mike Fiore |
9:ff62b20f7000 | 28 | return 0; |
Mike Fiore |
9:ff62b20f7000 | 29 | } |
Mike Fiore |
9:ff62b20f7000 | 30 | |
Mike Fiore |
9:ff62b20f7000 | 31 | bool CmdUplinkCounter::verify(std::vector<std::string> args) { |
Mike Fiore |
9:ff62b20f7000 | 32 | if (args.size() == 1) |
Mike Fiore |
9:ff62b20f7000 | 33 | return true; |
Mike Fiore |
9:ff62b20f7000 | 34 | |
Mike Fiore |
9:ff62b20f7000 | 35 | if (args.size() == 2) { |
Mike Fiore |
9:ff62b20f7000 | 36 | |
Mike Fiore |
9:ff62b20f7000 | 37 | int count; |
Mike Fiore |
9:ff62b20f7000 | 38 | if (sscanf(args[1].c_str(), "%d", &count) == 1) { |
Mike Fiore |
9:ff62b20f7000 | 39 | if (count > 4294967295) { |
Mike Fiore |
9:ff62b20f7000 | 40 | setErrorMessage("Invalid uplink counter, expects (0-4294967295)"); |
Mike Fiore |
9:ff62b20f7000 | 41 | return false; |
Mike Fiore |
9:ff62b20f7000 | 42 | } |
Mike Fiore |
9:ff62b20f7000 | 43 | return true; |
Mike Fiore |
9:ff62b20f7000 | 44 | } |
Mike Fiore |
9:ff62b20f7000 | 45 | } |
Mike Fiore |
9:ff62b20f7000 | 46 | |
Mike Fiore |
9:ff62b20f7000 | 47 | setErrorMessage("Invalid arguments"); |
Mike Fiore |
9:ff62b20f7000 | 48 | return false; |
Mike Fiore |
9:ff62b20f7000 | 49 | } |
Mike Fiore |
9:ff62b20f7000 | 50 |