AT command firmware for MultiTech Dot devices.

Fork of mDot_AT_firmware by MultiTech

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers CmdPingPeriod.cpp Source File

CmdPingPeriod.cpp

00001 #include "CmdPingPeriod.h"
00002 
00003 CmdPingPeriod::CmdPingPeriod() :
00004 #if MTS_CMD_TERM_VERBOSE
00005     Command("Ping Periodicity", "AT+PP", "Set the periodicity of class B ping slots as number of pings per interval = 2^(7-periodicity)", "(0-7)")
00006 #else
00007     Command("AT+PP")
00008 #endif
00009 {
00010     _queryable = true;
00011 }
00012 
00013 uint32_t CmdPingPeriod::action(const std::vector<std::string>& args)
00014 {
00015     mDot* dot = CommandTerminal::Dot();
00016     if (args.size() == 1) {
00017         CommandTerminal::Serial()->writef("%" SCNu32 "\r\n", dot->getPingPeriodicity());
00018     } else if (args.size() == 2) {
00019         uint32_t periodicity;
00020         sscanf(args[1].c_str(), "%" SCNu32, &periodicity);
00021 
00022         if (dot->setPingPeriodicity(static_cast<uint8_t>(periodicity)) != mDot::MDOT_OK) {
00023             return 1;
00024         }
00025     }
00026 
00027     return 0;
00028 }
00029 
00030 bool CmdPingPeriod::verify(const std::vector<std::string>& args)
00031 {
00032     if (args.size() == 1)
00033         return true;
00034 
00035     if (args.size() == 2) {
00036         uint32_t periodicity;
00037         if (sscanf(args[1].c_str(), "%" SCNu32, &periodicity) == 1) {
00038             if (periodicity > 7) {
00039 #if MTS_CMD_TERM_VERBOSE
00040                 CommandTerminal::setErrorMessage("Invalid periodicity, expects (0-7)");
00041 #endif
00042                 return false;
00043             }
00044 
00045             return true;
00046         }
00047     }
00048 
00049 #if MTS_CMD_TERM_VERBOSE
00050     CommandTerminal::setErrorMessage("Invalid arguments");
00051 #endif
00052     return false;
00053 }