firm newest

Dependencies:   MTS-Serial libmDot-dev-mbed5-deprecated

Committer:
nguyenhoang9x5555
Date:
Thu Oct 18 04:18:48 2018 +0000
Revision:
0:3c869a8cb8f8
DOT AT FIRMWARE 18102018

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nguyenhoang9x5555 0:3c869a8cb8f8 1 #include "CmdNetworkId.h"
nguyenhoang9x5555 0:3c869a8cb8f8 2
nguyenhoang9x5555 0:3c869a8cb8f8 3 CmdNetworkId::CmdNetworkId() :
nguyenhoang9x5555 0:3c869a8cb8f8 4 Command("Network ID", "AT+NI", "Configured Network Name/EUI (MSB, App EUI in LoRaWAN) AT+NI=0,hex AT+NI=1,network_name (Net ID = crc64(network_name)) (8 bytes)", "(0,(hex:8)),(1,(string:128))")
nguyenhoang9x5555 0:3c869a8cb8f8 5 {
nguyenhoang9x5555 0:3c869a8cb8f8 6 _queryable = true;
nguyenhoang9x5555 0:3c869a8cb8f8 7 }
nguyenhoang9x5555 0:3c869a8cb8f8 8
nguyenhoang9x5555 0:3c869a8cb8f8 9 uint32_t CmdNetworkId::action(std::vector<std::string> args)
nguyenhoang9x5555 0:3c869a8cb8f8 10 {
nguyenhoang9x5555 0:3c869a8cb8f8 11 if (args.size() == 1)
nguyenhoang9x5555 0:3c869a8cb8f8 12 {
nguyenhoang9x5555 0:3c869a8cb8f8 13 CommandTerminal::Serial()->writef("%s\r\n", mts::Text::bin2hexString(CommandTerminal::Dot()->getNetworkId(), "-").c_str());
nguyenhoang9x5555 0:3c869a8cb8f8 14
nguyenhoang9x5555 0:3c869a8cb8f8 15 if (!CommandTerminal::Dot()->getNetworkName().empty())
nguyenhoang9x5555 0:3c869a8cb8f8 16 CommandTerminal::Serial()->writef("Passphrase: '%s'\r\n", CommandTerminal::Dot()->getNetworkName().c_str());
nguyenhoang9x5555 0:3c869a8cb8f8 17 }
nguyenhoang9x5555 0:3c869a8cb8f8 18 else
nguyenhoang9x5555 0:3c869a8cb8f8 19 {
nguyenhoang9x5555 0:3c869a8cb8f8 20
nguyenhoang9x5555 0:3c869a8cb8f8 21
nguyenhoang9x5555 0:3c869a8cb8f8 22 if (args[1].find("1") == 0 && args[1].size() == 1)
nguyenhoang9x5555 0:3c869a8cb8f8 23 {
nguyenhoang9x5555 0:3c869a8cb8f8 24 std::string text;
nguyenhoang9x5555 0:3c869a8cb8f8 25 if (args.size() > 3)
nguyenhoang9x5555 0:3c869a8cb8f8 26 {
nguyenhoang9x5555 0:3c869a8cb8f8 27 // passphrase was split on commas
nguyenhoang9x5555 0:3c869a8cb8f8 28 for (size_t i = 2; i < args.size(); i++)
nguyenhoang9x5555 0:3c869a8cb8f8 29 {
nguyenhoang9x5555 0:3c869a8cb8f8 30 text.append(args[i]);
nguyenhoang9x5555 0:3c869a8cb8f8 31 if (i < args.size() - 1)
nguyenhoang9x5555 0:3c869a8cb8f8 32 text.append(",");
nguyenhoang9x5555 0:3c869a8cb8f8 33 }
nguyenhoang9x5555 0:3c869a8cb8f8 34 }
nguyenhoang9x5555 0:3c869a8cb8f8 35 else
nguyenhoang9x5555 0:3c869a8cb8f8 36 {
nguyenhoang9x5555 0:3c869a8cb8f8 37 text = args[2];
nguyenhoang9x5555 0:3c869a8cb8f8 38 }
nguyenhoang9x5555 0:3c869a8cb8f8 39
nguyenhoang9x5555 0:3c869a8cb8f8 40 if (CommandTerminal::Dot()->setNetworkName(text) == mDot::MDOT_OK)
nguyenhoang9x5555 0:3c869a8cb8f8 41 {
nguyenhoang9x5555 0:3c869a8cb8f8 42 CommandTerminal::Serial()->writef("Set Network Name: ");
nguyenhoang9x5555 0:3c869a8cb8f8 43 CommandTerminal::Serial()->writef("%s\r\n", text.c_str());
nguyenhoang9x5555 0:3c869a8cb8f8 44 }
nguyenhoang9x5555 0:3c869a8cb8f8 45 else
nguyenhoang9x5555 0:3c869a8cb8f8 46 {
nguyenhoang9x5555 0:3c869a8cb8f8 47 CommandTerminal::setErrorMessage(CommandTerminal::Dot()->getLastError());;
nguyenhoang9x5555 0:3c869a8cb8f8 48 return 1;
nguyenhoang9x5555 0:3c869a8cb8f8 49 }
nguyenhoang9x5555 0:3c869a8cb8f8 50
nguyenhoang9x5555 0:3c869a8cb8f8 51 }
nguyenhoang9x5555 0:3c869a8cb8f8 52 else
nguyenhoang9x5555 0:3c869a8cb8f8 53 {
nguyenhoang9x5555 0:3c869a8cb8f8 54 std::vector<uint8_t> NewKey;
nguyenhoang9x5555 0:3c869a8cb8f8 55 readByteArray(args[2], NewKey, EUI_LENGTH);
nguyenhoang9x5555 0:3c869a8cb8f8 56 if (CommandTerminal::Dot()->setNetworkId(NewKey) == mDot::MDOT_OK)
nguyenhoang9x5555 0:3c869a8cb8f8 57 {
nguyenhoang9x5555 0:3c869a8cb8f8 58 CommandTerminal::Serial()->writef("Set Network ID: ");
nguyenhoang9x5555 0:3c869a8cb8f8 59 CommandTerminal::Serial()->writef("%s\r\n", mts::Text::bin2hexString(NewKey, "-").c_str());
nguyenhoang9x5555 0:3c869a8cb8f8 60 }
nguyenhoang9x5555 0:3c869a8cb8f8 61 else
nguyenhoang9x5555 0:3c869a8cb8f8 62 {
nguyenhoang9x5555 0:3c869a8cb8f8 63 CommandTerminal::setErrorMessage(CommandTerminal::Dot()->getLastError());;
nguyenhoang9x5555 0:3c869a8cb8f8 64 return 1;
nguyenhoang9x5555 0:3c869a8cb8f8 65 }
nguyenhoang9x5555 0:3c869a8cb8f8 66 }
nguyenhoang9x5555 0:3c869a8cb8f8 67 }
nguyenhoang9x5555 0:3c869a8cb8f8 68
nguyenhoang9x5555 0:3c869a8cb8f8 69 return 0;
nguyenhoang9x5555 0:3c869a8cb8f8 70 }
nguyenhoang9x5555 0:3c869a8cb8f8 71
nguyenhoang9x5555 0:3c869a8cb8f8 72 bool CmdNetworkId::verify(std::vector<std::string> args)
nguyenhoang9x5555 0:3c869a8cb8f8 73 {
nguyenhoang9x5555 0:3c869a8cb8f8 74 if (args.size() == 1)
nguyenhoang9x5555 0:3c869a8cb8f8 75 return true;
nguyenhoang9x5555 0:3c869a8cb8f8 76
nguyenhoang9x5555 0:3c869a8cb8f8 77 if (args.size() == 3) {
nguyenhoang9x5555 0:3c869a8cb8f8 78 if (args[1] != "0" && args[1] != "1") {
nguyenhoang9x5555 0:3c869a8cb8f8 79 CommandTerminal::setErrorMessage("Invalid type, expects (0,1)");
nguyenhoang9x5555 0:3c869a8cb8f8 80 return false;
nguyenhoang9x5555 0:3c869a8cb8f8 81 }
nguyenhoang9x5555 0:3c869a8cb8f8 82 if (args[1] == "0" && !isHexString(args[2], 8)) {
nguyenhoang9x5555 0:3c869a8cb8f8 83 CommandTerminal::setErrorMessage("Invalid ID, expects (hex:8");
nguyenhoang9x5555 0:3c869a8cb8f8 84 return false;
nguyenhoang9x5555 0:3c869a8cb8f8 85 }
nguyenhoang9x5555 0:3c869a8cb8f8 86
nguyenhoang9x5555 0:3c869a8cb8f8 87 if (args[1] == "1" && args[2].size() < 8) {
nguyenhoang9x5555 0:3c869a8cb8f8 88 CommandTerminal::setErrorMessage("Invalid name, expects minimum 8 characters");
nguyenhoang9x5555 0:3c869a8cb8f8 89 return false;
nguyenhoang9x5555 0:3c869a8cb8f8 90 }
nguyenhoang9x5555 0:3c869a8cb8f8 91
nguyenhoang9x5555 0:3c869a8cb8f8 92 if (args[1] == "1" && args[2].size() > 128) {
nguyenhoang9x5555 0:3c869a8cb8f8 93 CommandTerminal::setErrorMessage("Invalid name, expects (string:128)");
nguyenhoang9x5555 0:3c869a8cb8f8 94 return false;
nguyenhoang9x5555 0:3c869a8cb8f8 95 }
nguyenhoang9x5555 0:3c869a8cb8f8 96
nguyenhoang9x5555 0:3c869a8cb8f8 97 return true;
nguyenhoang9x5555 0:3c869a8cb8f8 98 }
nguyenhoang9x5555 0:3c869a8cb8f8 99
nguyenhoang9x5555 0:3c869a8cb8f8 100 CommandTerminal::setErrorMessage("Invalid arguments");
nguyenhoang9x5555 0:3c869a8cb8f8 101 return false;
nguyenhoang9x5555 0:3c869a8cb8f8 102 }