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

CmdDeviceId.cpp

00001 #include "CmdDeviceId.h"
00002 #include <algorithm>
00003 
00004 CmdDeviceId::CmdDeviceId() :
00005 #if MTS_CMD_TERM_VERBOSE
00006     Command("Device ID", "AT+DI", "Device EUI-64 (MSB) (unique, set at factory) (8 bytes)", "(hex:8)")
00007 #else
00008     Command("AT+DI")
00009 #endif
00010 {
00011     _queryable = true;
00012 }
00013 
00014 uint32_t CmdDeviceId::action(const std::vector<std::string>& args)
00015 {
00016     if (args.size() == 1)
00017     {
00018         CommandTerminal::Serial()->writef("%s\r\n", mts::Text::bin2hexString(CommandTerminal::Dot()->getDeviceId(), "-").c_str());
00019     }
00020     else if (args.size() == 2)
00021     {
00022         std::vector<uint8_t> NewEUI;
00023 
00024         // Read in the key components...
00025         readByteArray(args[1], NewEUI, EUI_LENGTH);
00026 
00027         if (CommandTerminal::Dot()->setDeviceId(NewEUI) == mDot::MDOT_OK) {
00028             CommandTerminal::Serial()->writef("%s\r\n", mts::Text::bin2hexString(NewEUI, "-").c_str());
00029         } else {
00030             return 1;
00031         }
00032     }
00033 
00034     return 0;
00035 }
00036 
00037 bool CmdDeviceId::verify(const std::vector<std::string>& args)
00038 {
00039     if (args.size() == 1)
00040         return true;
00041 
00042     if (args.size() == 2 && isHexString(args[1], 8))
00043         return true;
00044 
00045 #if MTS_CMD_TERM_VERBOSE
00046     CommandTerminal::setErrorMessage("Invalid id, expects (hex:8)");
00047 #endif
00048 
00049     return false;
00050 }