few changes for RTS/CTS control

Dependencies:   MTS-Serial libmDot mbed-rtos mbed

Fork of mDot_AT_firmware by MultiTech

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers CmdWakeInterval.cpp Source File

CmdWakeInterval.cpp

00001 #include "CmdWakeInterval.h"
00002 
00003 CmdWakeInterval::CmdWakeInterval(mDot* dot, mts::MTSSerial& serial) :
00004         Command(dot, "Wake Interval", "AT+WI", "Wakeup interval (seconds)"),
00005         _serial(serial)
00006 {
00007     _help = std::string(text()) + ": " + std::string(desc());
00008     _usage = "(2-2147483647) s";
00009     _queryable = true;
00010 }
00011 
00012 uint32_t CmdWakeInterval::action(std::vector<std::string> args)
00013 {
00014     if (args.size() == 1)
00015     {
00016         if (_dot->getVerbose())
00017             _serial.writef("%s: ", name());
00018 
00019         _serial.writef("%lu\r\n", _dot->getWakeInterval());
00020     }
00021     else if (args.size() == 2)
00022     {
00023         int32_t code;
00024         int timeout;
00025         sscanf(args[1].c_str(), "%d", &timeout);
00026 
00027         if ((code = _dot->setWakeInterval(timeout)) != mDot::MDOT_OK) {
00028             setErrorMessage(_dot->getLastError());;
00029             return 1;
00030         }
00031     }
00032 
00033     return 0;
00034 }
00035 
00036 bool CmdWakeInterval::verify(std::vector<std::string> args)
00037 {
00038     if (args.size() == 1)
00039         return true;
00040     
00041     if (args.size() == 2) {
00042         int timeout;
00043         if (sscanf(args[1].c_str(), "%d", &timeout) != 1) {
00044             setErrorMessage("Invalid argument");
00045             return false;
00046         }
00047 
00048         if (timeout < 2 || timeout > INT_MAX) {
00049             setErrorMessage("Invalid interval, expects (2-2147483647) s");
00050             return false;
00051         }
00052 
00053         return true;
00054     }
00055 
00056     setErrorMessage("Invalid arguments");
00057     return false;
00058 }