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

CmdJoinRequest.cpp

00001 #include "CmdJoinRequest.h"
00002 #include "CommandTerminal.h"
00003 
00004 CmdJoinRequest::CmdJoinRequest(mDot* dot, mts::MTSSerial& serial)
00005 :
00006   Command(dot, "Join Network", "AT+JOIN", "Join network, provide argument of '1' to force join (acquire network address and session keys)"),
00007   _serial(serial) {
00008     _help = std::string(text()) + ": " + std::string(desc());
00009     _usage = "(force:1)";
00010 }
00011 
00012 uint32_t CmdJoinRequest::action(std::vector<std::string> args) {
00013     int32_t code;
00014     std::string buf;
00015     char ch;
00016 
00017     if (args.size() > 1 && args[1] == "1")
00018         _dot->resetNetworkSession();
00019 
00020     code = _dot->joinNetworkOnce();
00021 
00022     if (code == mDot::MDOT_OK) {
00023         _serial.writef("Successfully joined network\r\n");
00024         return 0;
00025     } else {
00026         std::string error = mDot::getReturnCodeString(code)  + " - " + _dot->getLastError();
00027         setErrorMessage(error);
00028     }
00029 
00030     return 1;
00031 }
00032 
00033 bool CmdJoinRequest::verify(std::vector<std::string> args) {
00034     if (args.size() == 1 || (args.size() == 2 && args[1] == "1"))
00035         return true;
00036 
00037     setErrorMessage("Invalid arguments");
00038     return false;
00039 }