MicroLabo / Mbed OS mbed-Dot-AT-Firmware

Dependencies:   MTS-Serial libmDot-mbed5

Fork of Dot-AT-Firmware by MultiTech

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers CmdAppPort.cpp Source File

CmdAppPort.cpp

00001 /*
00002  * CmdAppPort.cpp
00003  *
00004  *  Created on: Nov 4, 2015
00005  *      Author: jreiss
00006  */
00007 
00008 #include "CmdAppPort.h"
00009 
00010 CmdAppPort::CmdAppPort()
00011 :
00012   Command("App Port", "AT+AP", "Port used for application data (1 - 223)", "(1-223)")
00013 {
00014     _queryable = true;
00015 }
00016 
00017 CmdAppPort::~CmdAppPort()
00018 {
00019     // TODO Auto-generated destructor stub
00020 }
00021 
00022 uint32_t CmdAppPort::action(std::vector<std::string> args) {
00023     if (args.size() == 1) {
00024         CommandTerminal::Serial()->writef("%u\r\n", CommandTerminal::Dot()->getAppPort());
00025     } else if (args.size() == 2) {
00026         
00027         int appPort;
00028         sscanf(args[1].c_str(), "%d", &appPort);
00029 
00030         if (CommandTerminal::Dot()->setAppPort(appPort) != mDot::MDOT_OK) {
00031             
00032             CommandTerminal::setErrorMessage(CommandTerminal::Dot()->getLastError());;
00033             return 1;
00034         }
00035     }
00036     return 0;
00037 }
00038 
00039 bool CmdAppPort::verify(std::vector<std::string> args) {
00040     if (args.size() == 1)
00041         return true;
00042 
00043     if (args.size() == 2) {
00044 
00045         int appPort;
00046         if (sscanf(args[1].c_str(), "%d", &appPort) == 1) {
00047             if (appPort > 223 || appPort < 1) {
00048                 CommandTerminal::setErrorMessage("Invalid app port, expects (1-223)");
00049                 return false;
00050             }
00051             return true;
00052         }
00053     }
00054 
00055     CommandTerminal::setErrorMessage("Invalid arguments");
00056     return false;
00057 }