MultiTech / Mbed OS Dot-AT-Firmware

Fork of mDot_AT_firmware by MultiTech

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers CmdLogLevel.cpp Source File

CmdLogLevel.cpp

00001 #include "CmdLogLevel.h"
00002 
00003 CmdLogLevel::CmdLogLevel() :
00004 #if MTS_CMD_TERM_VERBOSE
00005         Command("Debug Log Level", "AT+LOG", "Enable/disable debug logging. (0: off, 1:Fatal - 6:Trace)", "(0-6)")
00006 #else
00007         Command("AT+LOG")
00008 #endif
00009 {
00010     _queryable = true;
00011 }
00012 
00013 uint32_t CmdLogLevel::action(const std::vector<std::string>& args)
00014 {
00015     if (args.size() == 1)
00016     {
00017         CommandTerminal::Serial()->writef("%u\r\n", CommandTerminal::Dot()->getLogLevel());
00018     }
00019     else if (args.size() == 2)
00020     {
00021         int level;
00022         sscanf(args[1].c_str(), "%d", &level);
00023 
00024         if (CommandTerminal::Dot()->setLogLevel(level) != mDot::MDOT_OK)
00025         {
00026             return 1;
00027         }
00028     }
00029 
00030     return 0;
00031 }
00032 
00033 bool CmdLogLevel::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 level;
00041         if (sscanf(args[1].c_str(), "%d", &level) != 1) {
00042 #if MTS_CMD_TERM_VERBOSE
00043             CommandTerminal::setErrorMessage("Invalid argument");
00044 #endif
00045             return false;
00046         }
00047 
00048         if (level < 0 || level > 6) {
00049 #if MTS_CMD_TERM_VERBOSE
00050             CommandTerminal::setErrorMessage("Invalid level, expects (0-6)");
00051 #endif
00052             return false;
00053         }
00054 
00055         return true;
00056     }
00057 
00058 #if MTS_CMD_TERM_VERBOSE
00059     CommandTerminal::setErrorMessage("Invalid arguments");
00060 #endif
00061     return false;
00062 }