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 "CmdMacCmd.h"
nguyenhoang9x5555 0:3c869a8cb8f8 2 #include "CommandTerminal.h"
nguyenhoang9x5555 0:3c869a8cb8f8 3
nguyenhoang9x5555 0:3c869a8cb8f8 4 CmdMacCmd::CmdMacCmd()
nguyenhoang9x5555 0:3c869a8cb8f8 5 :
nguyenhoang9x5555 0:3c869a8cb8f8 6 Command("MAC Command", "AT+MAC", "Inject MAC command to MAC layer or read uplink MAC command buffer, pass '0' argument to clear buffer", "(hex:242)")
nguyenhoang9x5555 0:3c869a8cb8f8 7 {
nguyenhoang9x5555 0:3c869a8cb8f8 8 }
nguyenhoang9x5555 0:3c869a8cb8f8 9
nguyenhoang9x5555 0:3c869a8cb8f8 10 uint32_t CmdMacCmd::action(std::vector<std::string> args) {
nguyenhoang9x5555 0:3c869a8cb8f8 11
nguyenhoang9x5555 0:3c869a8cb8f8 12 if (args.size() == 1) {
nguyenhoang9x5555 0:3c869a8cb8f8 13 std::vector<uint8_t> cmds = CommandTerminal::Dot()->getMacCommands();
nguyenhoang9x5555 0:3c869a8cb8f8 14
nguyenhoang9x5555 0:3c869a8cb8f8 15 if (cmds.size() > 0) {
nguyenhoang9x5555 0:3c869a8cb8f8 16 for (size_t i = 0; i < cmds.size(); i++) {
nguyenhoang9x5555 0:3c869a8cb8f8 17 CommandTerminal::Serial()->writef("%02x", cmds[i]);
nguyenhoang9x5555 0:3c869a8cb8f8 18 }
nguyenhoang9x5555 0:3c869a8cb8f8 19 CommandTerminal::Serial()->writef("\r\n");
nguyenhoang9x5555 0:3c869a8cb8f8 20 }
nguyenhoang9x5555 0:3c869a8cb8f8 21
nguyenhoang9x5555 0:3c869a8cb8f8 22 } else {
nguyenhoang9x5555 0:3c869a8cb8f8 23 if (args[1].size() == 1 && args[1] == "0") {
nguyenhoang9x5555 0:3c869a8cb8f8 24 CommandTerminal::Dot()->clearMacCommands();
nguyenhoang9x5555 0:3c869a8cb8f8 25 } else {
nguyenhoang9x5555 0:3c869a8cb8f8 26 std::vector<uint8_t> data;
nguyenhoang9x5555 0:3c869a8cb8f8 27 int32_t code;
nguyenhoang9x5555 0:3c869a8cb8f8 28 int temp;
nguyenhoang9x5555 0:3c869a8cb8f8 29 uint32_t length = args[1].size();
nguyenhoang9x5555 0:3c869a8cb8f8 30
nguyenhoang9x5555 0:3c869a8cb8f8 31 // Convert the ASCII hex data to binary...
nguyenhoang9x5555 0:3c869a8cb8f8 32 for (uint32_t i = 0; i < length; i += 2) {
nguyenhoang9x5555 0:3c869a8cb8f8 33 sscanf(&args[1][i], "%2x", &temp);
nguyenhoang9x5555 0:3c869a8cb8f8 34 data.push_back(temp);
nguyenhoang9x5555 0:3c869a8cb8f8 35 }
nguyenhoang9x5555 0:3c869a8cb8f8 36
nguyenhoang9x5555 0:3c869a8cb8f8 37 if ((code = CommandTerminal::Dot()->injectMacCommand(data)) != mDot::MDOT_OK) {
nguyenhoang9x5555 0:3c869a8cb8f8 38 std::string error = mDot::getReturnCodeString(code);
nguyenhoang9x5555 0:3c869a8cb8f8 39
nguyenhoang9x5555 0:3c869a8cb8f8 40 if (code != mDot::MDOT_NOT_JOINED)
nguyenhoang9x5555 0:3c869a8cb8f8 41 error += +" - " + CommandTerminal::Dot()->getLastError();
nguyenhoang9x5555 0:3c869a8cb8f8 42
nguyenhoang9x5555 0:3c869a8cb8f8 43 CommandTerminal::setErrorMessage(CommandTerminal::Dot()->getLastError());
nguyenhoang9x5555 0:3c869a8cb8f8 44 return 1;
nguyenhoang9x5555 0:3c869a8cb8f8 45 }
nguyenhoang9x5555 0:3c869a8cb8f8 46 }
nguyenhoang9x5555 0:3c869a8cb8f8 47 }
nguyenhoang9x5555 0:3c869a8cb8f8 48
nguyenhoang9x5555 0:3c869a8cb8f8 49 return 0;
nguyenhoang9x5555 0:3c869a8cb8f8 50 }
nguyenhoang9x5555 0:3c869a8cb8f8 51
nguyenhoang9x5555 0:3c869a8cb8f8 52 bool CmdMacCmd::verify(std::vector<std::string> args) {
nguyenhoang9x5555 0:3c869a8cb8f8 53 if (args.size() == 1) {
nguyenhoang9x5555 0:3c869a8cb8f8 54 return true;
nguyenhoang9x5555 0:3c869a8cb8f8 55 } else if (args.size() == 2) {
nguyenhoang9x5555 0:3c869a8cb8f8 56
nguyenhoang9x5555 0:3c869a8cb8f8 57 if (args[1].size() == 1 && args[1] == "0") {
nguyenhoang9x5555 0:3c869a8cb8f8 58 return true;
nguyenhoang9x5555 0:3c869a8cb8f8 59 } else if (args[1].size() > 484 || !isHexString(args[1], args[1].size() / 2)) {
nguyenhoang9x5555 0:3c869a8cb8f8 60 CommandTerminal::setErrorMessage("Invalid hex string, (hex:242)");
nguyenhoang9x5555 0:3c869a8cb8f8 61 return false;
nguyenhoang9x5555 0:3c869a8cb8f8 62 }
nguyenhoang9x5555 0:3c869a8cb8f8 63
nguyenhoang9x5555 0:3c869a8cb8f8 64 return true;
nguyenhoang9x5555 0:3c869a8cb8f8 65 }
nguyenhoang9x5555 0:3c869a8cb8f8 66
nguyenhoang9x5555 0:3c869a8cb8f8 67 CommandTerminal::setErrorMessage("Invalid arguments");
nguyenhoang9x5555 0:3c869a8cb8f8 68 return false;
nguyenhoang9x5555 0:3c869a8cb8f8 69 }
nguyenhoang9x5555 0:3c869a8cb8f8 70