MultiTech / Mbed OS Dot-AT-Firmware

Fork of mDot_AT_firmware by MultiTech

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers CmdJoinNonce.cpp Source File

CmdJoinNonce.cpp

00001 #include "CmdJoinNonce.h"
00002 
00003 CmdJoinNonce::CmdJoinNonce() :
00004 #if MTS_CMD_TERM_VERBOSE
00005     Command("Join Nonces", "AT+JN", "Set OTA Join Nonce", "(0-65535),(0-16777215)")
00006 #else
00007     Command("AT+JN")
00008 #endif
00009 {
00010     _queryable = true;
00011 }
00012 
00013 uint32_t CmdJoinNonce::action(const std::vector<std::string>& args) {
00014     if (args.size() == 1) {
00015         CommandTerminal::Serial()->writef("%u,%u\r\n", CommandTerminal::Dot()->getDevNonce(), CommandTerminal::Dot()->getAppNonce());
00016     } else if (args.size() == 3) {
00017 
00018         int nonce;
00019         int parsed = sscanf(args[1].c_str(), "%d", &nonce);
00020 
00021         if (parsed == 0 || CommandTerminal::Dot()->setDevNonce(nonce) != mDot::MDOT_OK) {
00022             return 1;
00023         }
00024 
00025         parsed = sscanf(args[2].c_str(), "%d", &nonce);
00026 
00027         if (parsed == 0 || CommandTerminal::Dot()->setAppNonce(nonce) != mDot::MDOT_OK) {
00028             return 1;
00029         }
00030     }
00031 
00032     return 0;
00033 }
00034 
00035 bool CmdJoinNonce::verify(const std::vector<std::string>& args) {
00036     bool ret = false;
00037 
00038     if (args.size() == 1)
00039         ret = true;
00040 
00041     if (args.size() == 3) {
00042         ret = true;
00043 
00044         int nonce;
00045         if (sscanf(args[1].c_str(), "%d", &nonce) == 1) {
00046             if (nonce < 0 || nonce > 65535) {
00047 #if MTS_CMD_TERM_VERBOSE
00048                 CommandTerminal::setErrorMessage("Invalid dev nonce, expects (0-65535)");
00049 #endif
00050                 ret = false;
00051             }
00052         } else {
00053 #if MTS_CMD_TERM_VERBOSE
00054             CommandTerminal::setErrorMessage("Invalid arguments");
00055 #endif
00056             ret = false;
00057         }
00058 
00059         if (sscanf(args[2].c_str(), "%d", &nonce) == 1) {
00060             if (nonce < 0 || nonce > 16777215) {
00061 #if MTS_CMD_TERM_VERBOSE
00062                 CommandTerminal::setErrorMessage("Invalid app nonce, expects (0-16777215)");
00063 #endif
00064                 ret = false;
00065             }
00066         } else {
00067 #if MTS_CMD_TERM_VERBOSE
00068                 CommandTerminal::setErrorMessage("Invalid arguments");
00069 #endif
00070             ret = false;
00071         }
00072     }
00073 
00074     return ret;
00075 }
00076