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 "CmdSendBinary.h"
nguyenhoang9x5555 0:3c869a8cb8f8 2 #include "CommandTerminal.h"
nguyenhoang9x5555 0:3c869a8cb8f8 3
nguyenhoang9x5555 0:3c869a8cb8f8 4 CmdSendBinary::CmdSendBinary()
nguyenhoang9x5555 0:3c869a8cb8f8 5 :
nguyenhoang9x5555 0:3c869a8cb8f8 6 Command("Send Binary", "AT+SENDB", "Sends supplied binary (hex) packet data one time and return response", "(hex:242)")
nguyenhoang9x5555 0:3c869a8cb8f8 7 {
nguyenhoang9x5555 0:3c869a8cb8f8 8 }
nguyenhoang9x5555 0:3c869a8cb8f8 9
nguyenhoang9x5555 0:3c869a8cb8f8 10 uint32_t CmdSendBinary::action(std::vector<std::string> args) {
nguyenhoang9x5555 0:3c869a8cb8f8 11 std::vector<uint8_t> data;
nguyenhoang9x5555 0:3c869a8cb8f8 12
nguyenhoang9x5555 0:3c869a8cb8f8 13 int temp;
nguyenhoang9x5555 0:3c869a8cb8f8 14 uint32_t length = args[1].size();
nguyenhoang9x5555 0:3c869a8cb8f8 15
nguyenhoang9x5555 0:3c869a8cb8f8 16 // Convert the ASCII hex data to binary...
nguyenhoang9x5555 0:3c869a8cb8f8 17 for (uint32_t i = 0; i < length; i += 2) {
nguyenhoang9x5555 0:3c869a8cb8f8 18 sscanf(&args[1][i], "%2x", &temp);
nguyenhoang9x5555 0:3c869a8cb8f8 19 data.push_back(temp);
nguyenhoang9x5555 0:3c869a8cb8f8 20 }
nguyenhoang9x5555 0:3c869a8cb8f8 21
nguyenhoang9x5555 0:3c869a8cb8f8 22 if (CommandTerminal::Dot()->send(data, CommandTerminal::Dot()->getTxWait()) != mDot::MDOT_OK) {
nguyenhoang9x5555 0:3c869a8cb8f8 23 CommandTerminal::setErrorMessage(CommandTerminal::Dot()->getLastError());;
nguyenhoang9x5555 0:3c869a8cb8f8 24 return 1;
nguyenhoang9x5555 0:3c869a8cb8f8 25 }
nguyenhoang9x5555 0:3c869a8cb8f8 26
nguyenhoang9x5555 0:3c869a8cb8f8 27 data.clear();
nguyenhoang9x5555 0:3c869a8cb8f8 28
nguyenhoang9x5555 0:3c869a8cb8f8 29 if (CommandTerminal::Dot()->getTxWait() && CommandTerminal::Dot()->recv(data) == mDot::MDOT_OK) {
nguyenhoang9x5555 0:3c869a8cb8f8 30 if (!data.empty()) {
nguyenhoang9x5555 0:3c869a8cb8f8 31 if (CommandTerminal::Dot()->getRxOutput() == mDot::HEXADECIMAL) {
nguyenhoang9x5555 0:3c869a8cb8f8 32 for (size_t i = 0; i < data.size(); i++) {
nguyenhoang9x5555 0:3c869a8cb8f8 33 CommandTerminal::Serial()->writef("%02x", data[i]);
nguyenhoang9x5555 0:3c869a8cb8f8 34 }
nguyenhoang9x5555 0:3c869a8cb8f8 35 CommandTerminal::Serial()->writef("\r\n");
nguyenhoang9x5555 0:3c869a8cb8f8 36 } else {
nguyenhoang9x5555 0:3c869a8cb8f8 37 CommandTerminal::Serial()->writef("%s\r\n", CommandTerminal::formatPacketData(data, CommandTerminal::Dot()->getRxOutput()).c_str());
nguyenhoang9x5555 0:3c869a8cb8f8 38 }
nguyenhoang9x5555 0:3c869a8cb8f8 39 }
nguyenhoang9x5555 0:3c869a8cb8f8 40 }
nguyenhoang9x5555 0:3c869a8cb8f8 41
nguyenhoang9x5555 0:3c869a8cb8f8 42 return 0;
nguyenhoang9x5555 0:3c869a8cb8f8 43 }
nguyenhoang9x5555 0:3c869a8cb8f8 44
nguyenhoang9x5555 0:3c869a8cb8f8 45 bool CmdSendBinary::verify(std::vector<std::string> args) {
nguyenhoang9x5555 0:3c869a8cb8f8 46 if (args.size() == 2) {
nguyenhoang9x5555 0:3c869a8cb8f8 47 if (args[1].size() > 484 || !isHexString(args[1], args[1].size() / 2)) {
nguyenhoang9x5555 0:3c869a8cb8f8 48 CommandTerminal::setErrorMessage("Invalid hex string, (hex:242)");
nguyenhoang9x5555 0:3c869a8cb8f8 49 return false;
nguyenhoang9x5555 0:3c869a8cb8f8 50 }
nguyenhoang9x5555 0:3c869a8cb8f8 51
nguyenhoang9x5555 0:3c869a8cb8f8 52 return true;
nguyenhoang9x5555 0:3c869a8cb8f8 53 }
nguyenhoang9x5555 0:3c869a8cb8f8 54
nguyenhoang9x5555 0:3c869a8cb8f8 55 CommandTerminal::setErrorMessage("Invalid arguments");
nguyenhoang9x5555 0:3c869a8cb8f8 56 return false;
nguyenhoang9x5555 0:3c869a8cb8f8 57 }
nguyenhoang9x5555 0:3c869a8cb8f8 58