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

CmdEncryption.cpp

00001 #include "CmdEncryption.h"
00002 
00003 CmdEncryption::CmdEncryption() :
00004         Command("AES Encryption", "AT+ENC", "Enable/disable AES encryption (0: off, 1: on)", "(0,1)")
00005 {
00006     _queryable = true;
00007 }
00008 
00009 uint32_t CmdEncryption::action(std::vector<std::string> args)
00010 {
00011     if (args.size() == 1)
00012     {
00013         CommandTerminal::Serial()->writef("%d\r\n", CommandTerminal::Dot()->getAesEncryption());
00014     }
00015     else if (args.size() == 2)
00016     {
00017         bool enable = (args[1] == "1");
00018 
00019         if (CommandTerminal::Dot()->setAesEncryption(enable) != mDot::MDOT_OK)
00020         {
00021             CommandTerminal::setErrorMessage(CommandTerminal::Dot()->getLastError());;
00022             return 1;
00023         }
00024     }
00025 
00026     return 0;
00027 }
00028 
00029 bool CmdEncryption::verify(std::vector<std::string> args)
00030 {
00031     if (args.size() == 1)
00032         return true;
00033 
00034     if (args.size() == 2)
00035     {
00036         if (args[1] != "1" && args[1] != "0") {
00037             CommandTerminal::setErrorMessage("Invalid parameter, expects (0: off, 1: on)");
00038             return false;
00039         }
00040 
00041         return true;
00042     }
00043 
00044     CommandTerminal::setErrorMessage("Invalid arguments");
00045     return false;
00046 }