DeepPass / mDot_AT_firmware

Dependencies:   MTS-Serial libmDot mbed-rtos mbed-src

Fork of mDot_AT_firmware by MultiTech

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers CmdAdaptiveDataRate.cpp Source File

CmdAdaptiveDataRate.cpp

00001 #include "CmdAdaptiveDataRate.h"
00002 
00003 
00004 CmdAdaptiveDataRate::CmdAdaptiveDataRate(mDot* dot, mts::MTSSerial& serial) :
00005         Command(dot, "Adaptive Data Rate", "AT+ADR", "Enable/disable Adaptive Data Rate (0: off, 1: on)"), _serial(serial)
00006 {
00007     _help = std::string(text()) + ": " + std::string(desc());
00008     _usage = "(0,1)";
00009     _queryable = true;
00010 }
00011 
00012 uint32_t CmdAdaptiveDataRate::action(std::vector<std::string> args)
00013 {
00014     if (args.size() == 1)
00015     {
00016         if (_dot->getVerbose())
00017             _serial.writef("Adaptive Data Rate: ");
00018 
00019         _serial.writef("%d\r\n", _dot->getAdr());
00020     }
00021     else if (args.size() == 2)
00022     {
00023         int32_t code;
00024         bool enable = (args[1] == "1");
00025         if ((code = _dot->setAdr(enable)) != mDot::MDOT_OK)
00026         {
00027             std::string error = mDot::getReturnCodeString(code) + " - " + _dot->getLastError();
00028             setErrorMessage(error);
00029             return 1;
00030         }
00031     }
00032 
00033     return 0;
00034 }
00035 
00036 bool CmdAdaptiveDataRate::verify(std::vector<std::string> args)
00037 {
00038     if (args.size() == 1)
00039         return true;
00040 
00041     if (args.size() == 2)
00042     {
00043         if (args[1] != "1" && args[1] != "0") {
00044             setErrorMessage("Invalid parameter, expects (0: off, 1: on)");
00045             return false;
00046         }
00047 
00048         return true;
00049     }
00050 
00051     setErrorMessage("Invalid arguments");
00052     return false;
00053 }