firm newest
Dependencies: MTS-Serial libmDot-dev-mbed5-deprecated
Diff: CommandTerminal/CmdJoinRequest.cpp
- Revision:
- 0:3c869a8cb8f8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CommandTerminal/CmdJoinRequest.cpp Thu Oct 18 04:18:48 2018 +0000 @@ -0,0 +1,44 @@ +#include "CmdJoinRequest.h" +#include "CommandTerminal.h" + +CmdJoinRequest::CmdJoinRequest() +: + Command("Join Network", "AT+JOIN", "Join network, provide argument of '1' to force join (acquire network address and session keys)", "(force:1)") { + +} + +uint32_t CmdJoinRequest::action(std::vector<std::string> args) { + + std::string buf; + + if (args.size() > 1 && args[1] == "1") + CommandTerminal::Dot()->resetNetworkSession(); + + if (CommandTerminal::Dot()->getJoinMode() == 0) { + CommandTerminal::Serial()->writef("Join not necessary for Manual Join Mode\r\n"); + return 0; + } else if (CommandTerminal::Dot()->getJoinMode() == 3) { + CommandTerminal::Serial()->writef("Join not necessary for Peer-to-Peer\r\n"); + return 0; + } + + int32_t code = CommandTerminal::Dot()->joinNetworkOnce(); + + if (code == mDot::MDOT_OK) { + CommandTerminal::Serial()->writef("Successfully joined network\r\n"); + return 0; + } else { + std::string error = mDot::getReturnCodeString(code) + " - " + CommandTerminal::Dot()->getLastError(); + CommandTerminal::setErrorMessage(CommandTerminal::Dot()->getLastError()); + } + + return 1; +} + +bool CmdJoinRequest::verify(std::vector<std::string> args) { + if (args.size() == 1 || (args.size() == 2 && args[1] == "1")) + return true; + + CommandTerminal::setErrorMessage("Invalid arguments"); + return false; +}