firm newest

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

Committer:
nguyenhoang9x5555
Date:
Mon Oct 22 01:56:09 2018 +0000
Revision:
1:c1c6549b9333
Parent:
0:3c869a8cb8f8
hey

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nguyenhoang9x5555 0:3c869a8cb8f8 1 #include "CmdNetworkAddress.h"
nguyenhoang9x5555 0:3c869a8cb8f8 2 #include <algorithm>
nguyenhoang9x5555 0:3c869a8cb8f8 3
nguyenhoang9x5555 0:3c869a8cb8f8 4 CmdNetworkAddress::CmdNetworkAddress() :
nguyenhoang9x5555 0:3c869a8cb8f8 5 Command("Network Address", "AT+NA", "Network address (devAddr in LoraMac) (4 bytes)", "(hex:4)")
nguyenhoang9x5555 0:3c869a8cb8f8 6 {
nguyenhoang9x5555 0:3c869a8cb8f8 7 _queryable = true;
nguyenhoang9x5555 0:3c869a8cb8f8 8 }
nguyenhoang9x5555 0:3c869a8cb8f8 9
nguyenhoang9x5555 0:3c869a8cb8f8 10 uint32_t CmdNetworkAddress::action(std::vector<std::string> args)
nguyenhoang9x5555 0:3c869a8cb8f8 11 {
nguyenhoang9x5555 0:3c869a8cb8f8 12 std::vector<uint8_t> addr;
nguyenhoang9x5555 0:3c869a8cb8f8 13
nguyenhoang9x5555 0:3c869a8cb8f8 14 if (args.size() == 1)
nguyenhoang9x5555 0:3c869a8cb8f8 15 {
nguyenhoang9x5555 0:3c869a8cb8f8 16 addr = CommandTerminal::Dot()->getNetworkAddress();
nguyenhoang9x5555 0:3c869a8cb8f8 17 CommandTerminal::Serial()->writef("%02x:%02x:%02x:%02x\r\n", addr[0], addr[1], addr[2], addr[3]);
nguyenhoang9x5555 0:3c869a8cb8f8 18 }
nguyenhoang9x5555 0:3c869a8cb8f8 19 else if (args.size() == 2)
nguyenhoang9x5555 0:3c869a8cb8f8 20 {
nguyenhoang9x5555 0:3c869a8cb8f8 21
nguyenhoang9x5555 0:3c869a8cb8f8 22 int temp;
nguyenhoang9x5555 0:3c869a8cb8f8 23 uint32_t step = 2;
nguyenhoang9x5555 0:3c869a8cb8f8 24
nguyenhoang9x5555 0:3c869a8cb8f8 25 if (args[1].find(":") != std::string::npos || args[1].find(".") != std::string::npos || args[1].find("-") != std::string::npos)
nguyenhoang9x5555 0:3c869a8cb8f8 26 step = 3;
nguyenhoang9x5555 0:3c869a8cb8f8 27
nguyenhoang9x5555 0:3c869a8cb8f8 28 // Convert the ASCII hex data to binary...
nguyenhoang9x5555 0:3c869a8cb8f8 29 for (size_t i = 0; i < args[1].size(); i += step)
nguyenhoang9x5555 0:3c869a8cb8f8 30 {
nguyenhoang9x5555 0:3c869a8cb8f8 31 sscanf(&args[1][i], "%02x", &temp);
nguyenhoang9x5555 0:3c869a8cb8f8 32 addr.push_back(temp);
nguyenhoang9x5555 0:3c869a8cb8f8 33 }
nguyenhoang9x5555 0:3c869a8cb8f8 34
nguyenhoang9x5555 0:3c869a8cb8f8 35 if (CommandTerminal::Dot()->setNetworkAddress(addr) == mDot::MDOT_OK) {
nguyenhoang9x5555 0:3c869a8cb8f8 36 CommandTerminal::Serial()->writef("Set Network Address: ");
nguyenhoang9x5555 0:3c869a8cb8f8 37 CommandTerminal::Serial()->writef("%02x:%02x:%02x:%02x\r\n", addr[0], addr[1], addr[2], addr[3]);
nguyenhoang9x5555 0:3c869a8cb8f8 38 } else {
nguyenhoang9x5555 0:3c869a8cb8f8 39 CommandTerminal::setErrorMessage(CommandTerminal::Dot()->getLastError());;
nguyenhoang9x5555 0:3c869a8cb8f8 40 return 1;
nguyenhoang9x5555 0:3c869a8cb8f8 41 }
nguyenhoang9x5555 0:3c869a8cb8f8 42 }
nguyenhoang9x5555 0:3c869a8cb8f8 43
nguyenhoang9x5555 0:3c869a8cb8f8 44 return 0;
nguyenhoang9x5555 0:3c869a8cb8f8 45 }
nguyenhoang9x5555 0:3c869a8cb8f8 46
nguyenhoang9x5555 0:3c869a8cb8f8 47 bool CmdNetworkAddress::verify(std::vector<std::string> args)
nguyenhoang9x5555 0:3c869a8cb8f8 48 {
nguyenhoang9x5555 0:3c869a8cb8f8 49 if (args.size() == 1) {
nguyenhoang9x5555 0:3c869a8cb8f8 50 return true;
nguyenhoang9x5555 0:3c869a8cb8f8 51 }
nguyenhoang9x5555 0:3c869a8cb8f8 52
nguyenhoang9x5555 0:3c869a8cb8f8 53 if (args.size() == 2) {
nguyenhoang9x5555 0:3c869a8cb8f8 54 if (!isHexString(args[1], 4))
nguyenhoang9x5555 0:3c869a8cb8f8 55 {
nguyenhoang9x5555 0:3c869a8cb8f8 56 CommandTerminal::setErrorMessage("Invalid address, expects (hex:4)");
nguyenhoang9x5555 0:3c869a8cb8f8 57 return false;
nguyenhoang9x5555 0:3c869a8cb8f8 58 }
nguyenhoang9x5555 0:3c869a8cb8f8 59
nguyenhoang9x5555 0:3c869a8cb8f8 60 return true;
nguyenhoang9x5555 0:3c869a8cb8f8 61 }
nguyenhoang9x5555 0:3c869a8cb8f8 62
nguyenhoang9x5555 0:3c869a8cb8f8 63 CommandTerminal::setErrorMessage("Invalid arguments");
nguyenhoang9x5555 0:3c869a8cb8f8 64 return false;
nguyenhoang9x5555 0:3c869a8cb8f8 65 }