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 CmdRepeat.cpp Source File

CmdRepeat.cpp

00001 #include "CmdRepeat.h"
00002 
00003 CmdRepeat::CmdRepeat() :
00004 #if MTS_CMD_TERM_VERBOSE
00005     Command("Packet Repeats", "AT+REP", "Configure number of times to repeat a packet", "(0-15)")
00006 #else
00007     Command("AT+REP")
00008 #endif
00009 {
00010     _queryable = true;
00011 }
00012 
00013 uint32_t CmdRepeat::action(const std::vector<std::string>& args)
00014 {
00015     if (args.size() == 1)
00016     {
00017         CommandTerminal::Serial()->writef("%u\r\n", CommandTerminal::Dot()->getRepeat());
00018     }
00019     else if (args.size() == 2)
00020     {
00021         int repeat;
00022         sscanf(args[1].c_str(), "%d", &repeat);
00023 
00024         if (CommandTerminal::Dot()->setRepeat(repeat) != mDot::MDOT_OK)
00025         {
00026             return 1;
00027         }
00028     }
00029 
00030     return 0;
00031 }
00032 
00033 bool CmdRepeat::verify(const std::vector<std::string>& args)
00034 {
00035     if (args.size() == 1)
00036         return true;
00037 
00038     if (args.size() == 2)
00039     {
00040         int repeat;
00041         if (sscanf(args[1].c_str(), "%d", &repeat) != 1) {
00042 #if MTS_CMD_TERM_VERBOSE
00043             CommandTerminal::setErrorMessage("Invalid argument");
00044 #endif
00045             return false;
00046         }
00047 
00048         if (repeat < 0 || repeat > 15)
00049         {
00050 #if MTS_CMD_TERM_VERBOSE
00051             CommandTerminal::setErrorMessage("Invalid repeats, expects (0-15)");
00052 #endif
00053             return false;
00054         }
00055 
00056         return true;
00057     }
00058 
00059 #if MTS_CMD_TERM_VERBOSE
00060     CommandTerminal::setErrorMessage("Invalid arguments");
00061 #endif
00062     return false;
00063 }