MultiTech / Mbed OS Dot-AT-Firmware

Fork of mDot_AT_firmware by MultiTech

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers CmdDisableDutyCycle.cpp Source File

CmdDisableDutyCycle.cpp

00001 #include "CmdDisableDutyCycle.h"
00002 
00003 CmdDisableDutyCycle::CmdDisableDutyCycle() :
00004 #if MTS_CMD_TERM_VERBOSE
00005     Command("Disable Duty Cycle", "AT+DD", "Disable duty cycle or auto join datarate. This setting will not be saved to config.", "(0-1),(0-1)")
00006 #else
00007     Command("AT+DD")
00008 #endif
00009 {
00010     _queryable = true;
00011 }
00012 
00013 uint32_t CmdDisableDutyCycle::action(const std::vector<std::string>& args) {
00014 
00015     if (args.size() == 1) {
00016         CommandTerminal::Serial()->writef("%d,%d\r\n", CommandTerminal::Dot()->getDisableDutyCycle(), CommandTerminal::Dot()->getDisableAutoJoinDatarate());
00017     } else if (args.size() == 2) {
00018         CommandTerminal::Dot()->setDisableDutyCycle(args[1] == "1");
00019     } else if (args.size() == 3) {
00020         CommandTerminal::Dot()->setDisableDutyCycle(args[1] == "1");
00021         CommandTerminal::Dot()->setDisableAutoJoinDatarate(args[1] == "1");
00022     }
00023 
00024     return 0;
00025 }
00026 
00027 bool CmdDisableDutyCycle::verify(const std::vector<std::string>& args) {
00028 
00029     if (args.size() > 2) {
00030 #if MTS_CMD_TERM_VERBOSE
00031         CommandTerminal::setErrorMessage("Invalid parameter, expects (0-1)");
00032 #endif
00033         return false;
00034     }
00035 
00036     if (args.size() == 2) {
00037         int bytes;
00038 
00039         sscanf(args[1].c_str(), "%d", &bytes);
00040 
00041         if (!(bytes == 0 || bytes == 1)) {
00042 #if MTS_CMD_TERM_VERBOSE
00043             CommandTerminal::setErrorMessage("Invalid parameter, expects (0-1)");
00044 #endif
00045             return false;
00046         }
00047     }
00048 
00049     if (args.size() == 3) {
00050         int bytes;
00051 
00052         sscanf(args[1].c_str(), "%d", &bytes);
00053 
00054         if (!(bytes == 0 || bytes == 1)) {
00055 #if MTS_CMD_TERM_VERBOSE
00056             CommandTerminal::setErrorMessage("Invalid 1st parameter, expects (0-1)");
00057 #endif
00058             return false;
00059         }
00060 
00061         sscanf(args[2].c_str(), "%d", &bytes);
00062 
00063         if (!(bytes == 0 || bytes == 1)) {
00064 #if MTS_CMD_TERM_VERBOSE
00065             CommandTerminal::setErrorMessage("Invalid 2nd parameter, expects (0-1)");
00066 #endif
00067             return false;
00068         }
00069     }
00070 
00071     return true;
00072 }