AT command firmware for MultiTech Dot devices.

Fork of mDot_AT_firmware by MultiTech

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers CmdPublicNetwork.cpp Source File

CmdPublicNetwork.cpp

00001 #include "CmdPublicNetwork.h"
00002 
00003 CmdPublicNetwork::CmdPublicNetwork() :
00004 #if MTS_CMD_TERM_VERBOSE
00005     Command("Network Mode", "AT+PN", "Set public network mode (0: PRIVATE_MTS, 1: PUBLIC_LORAWAN, 2: PRIVATE_LORAWAN)", "(0-2)")
00006 #else
00007     Command("AT+PN")
00008 #endif
00009 {
00010     _queryable = true;
00011 }
00012 
00013 uint32_t CmdPublicNetwork::action(const std::vector<std::string>& args)
00014 {
00015     if (args.size() == 1)
00016     {
00017         CommandTerminal::Serial()->writef("%d\r\n", CommandTerminal::Dot()->getPublicNetwork());
00018     }
00019     else if (args.size() == 2)
00020     {
00021         uint8_t mode = lora::PRIVATE_MTS;
00022 
00023         if (args[1] == "1") {
00024             mode = lora::PUBLIC_LORAWAN;
00025         } else if (args[1] == "2") {
00026             mode = lora::PRIVATE_LORAWAN;
00027         }
00028 
00029         if (CommandTerminal::Dot()->setPublicNetwork(mode) != mDot::MDOT_OK) {
00030             return 1;
00031         }
00032     }
00033 
00034     return 0;
00035 }
00036 
00037 bool CmdPublicNetwork::verify(const std::vector<std::string>& args)
00038 {
00039     if (args.size() == 1)
00040         return true;
00041 
00042     if (args.size() == 2)
00043     {
00044         if (args[1] != "2" && args[1] != "1" && args[1] != "0") {
00045 #if MTS_CMD_TERM_VERBOSE
00046             CommandTerminal::setErrorMessage("Invalid parameter, expects (0: PRIVATE_MTS, 1: PUBLIC_LORAWAN, 2: PRIVATE_LORAWAN)");
00047 #endif
00048             return false;
00049         }
00050 
00051         return true;
00052     }
00053 
00054 #if MTS_CMD_TERM_VERBOSE
00055     CommandTerminal::setErrorMessage("Invalid arguments");
00056 #endif
00057     return false;
00058 }