MicroLabo / Mbed OS mbed-Dot-AT-Firmware

Dependencies:   MTS-Serial libmDot-mbed5

Fork of Dot-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() :
00004  Command("Wake Interval", "AT+WI", "Wakeup interval (seconds)", "(2-2147483646) s") {
00005     _queryable = true;
00006 }
00007 
00008 uint32_t CmdWakeInterval::action(std::vector<std::string> args)
00009 {
00010     if (args.size() == 1)
00011     {
00012         CommandTerminal::Serial()->writef("%lu\r\n", CommandTerminal::Dot()->getWakeInterval());
00013     }
00014     else if (args.size() == 2)
00015     {
00016         int timeout;
00017         sscanf(args[1].c_str(), "%d", &timeout);
00018 
00019         if (CommandTerminal::Dot()->setWakeInterval(timeout) != mDot::MDOT_OK) {
00020             CommandTerminal::setErrorMessage(CommandTerminal::Dot()->getLastError());;
00021             return 1;
00022         }
00023     }
00024 
00025     return 0;
00026 }
00027 
00028 bool CmdWakeInterval::verify(std::vector<std::string> args)
00029 {
00030     if (args.size() == 1)
00031         return true;
00032     
00033     if (args.size() == 2) {
00034         int timeout;
00035         if (sscanf(args[1].c_str(), "%d", &timeout) != 1) {
00036             CommandTerminal::setErrorMessage("Invalid argument");
00037             return false;
00038         }
00039 
00040         if (timeout < 2 || timeout > INT_MAX-1) {
00041             CommandTerminal::setErrorMessage("Invalid interval, expects (2-2147483646) s");
00042             return false;
00043         }
00044 
00045         return true;
00046     }
00047 
00048     CommandTerminal::setErrorMessage("Invalid arguments");
00049     return false;
00050 }