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

CmdJoinRequest.cpp

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