mDot AT-Firmware for testing
Dependencies: MTS-Serial libmDot-mbed5
Fork of Dot-AT-Firmware by
CommandTerminal/CmdSendBinary.cpp@14:f9a77400b622, 2016-11-04 (annotated)
- Committer:
- Mike Fiore
- Date:
- Fri Nov 04 14:25:43 2016 -0500
- Revision:
- 14:f9a77400b622
- Parent:
- 9:ff62b20f7000
update from git revision 2.0.16
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mike Fiore |
1:e52ae6584f1c | 1 | #include "CmdSendBinary.h" |
Mike Fiore |
1:e52ae6584f1c | 2 | #include "CommandTerminal.h" |
Mike Fiore |
1:e52ae6584f1c | 3 | |
Mike Fiore |
14:f9a77400b622 | 4 | CmdSendBinary::CmdSendBinary() |
Mike Fiore |
1:e52ae6584f1c | 5 | : |
Mike Fiore |
14:f9a77400b622 | 6 | Command("Send Binary", "AT+SENDB", "Sends supplied binary (hex) packet data one time and return response", "(hex:242)") |
Mike Fiore |
14:f9a77400b622 | 7 | { |
Mike Fiore |
1:e52ae6584f1c | 8 | } |
Mike Fiore |
1:e52ae6584f1c | 9 | |
Mike Fiore |
1:e52ae6584f1c | 10 | uint32_t CmdSendBinary::action(std::vector<std::string> args) { |
Mike Fiore |
1:e52ae6584f1c | 11 | std::vector<uint8_t> data; |
Mike Fiore |
14:f9a77400b622 | 12 | |
Mike Fiore |
9:ff62b20f7000 | 13 | int temp; |
Mike Fiore |
1:e52ae6584f1c | 14 | uint32_t length = args[1].size(); |
Mike Fiore |
1:e52ae6584f1c | 15 | |
Mike Fiore |
1:e52ae6584f1c | 16 | // Convert the ASCII hex data to binary... |
Mike Fiore |
1:e52ae6584f1c | 17 | for (uint32_t i = 0; i < length; i += 2) { |
Mike Fiore |
1:e52ae6584f1c | 18 | sscanf(&args[1][i], "%2x", &temp); |
Mike Fiore |
1:e52ae6584f1c | 19 | data.push_back(temp); |
Mike Fiore |
1:e52ae6584f1c | 20 | } |
Mike Fiore |
1:e52ae6584f1c | 21 | |
Mike Fiore |
14:f9a77400b622 | 22 | if (CommandTerminal::Dot()->send(data, CommandTerminal::Dot()->getTxWait()) != mDot::MDOT_OK) { |
Mike Fiore |
14:f9a77400b622 | 23 | CommandTerminal::setErrorMessage(CommandTerminal::Dot()->getLastError());; |
Mike Fiore |
1:e52ae6584f1c | 24 | return 1; |
Mike Fiore |
1:e52ae6584f1c | 25 | } |
Mike Fiore |
1:e52ae6584f1c | 26 | |
Mike Fiore |
1:e52ae6584f1c | 27 | data.clear(); |
Mike Fiore |
1:e52ae6584f1c | 28 | |
Mike Fiore |
14:f9a77400b622 | 29 | if (CommandTerminal::Dot()->getTxWait() && CommandTerminal::Dot()->recv(data) == mDot::MDOT_OK) { |
Mike Fiore |
1:e52ae6584f1c | 30 | if (!data.empty()) { |
Mike Fiore |
14:f9a77400b622 | 31 | if (CommandTerminal::Dot()->getRxOutput() == mDot::HEXADECIMAL) { |
Mike Fiore |
14:f9a77400b622 | 32 | for (size_t i = 0; i < data.size(); i++) { |
Mike Fiore |
14:f9a77400b622 | 33 | CommandTerminal::Serial()->writef("%02x", data[i]); |
Mike Fiore |
14:f9a77400b622 | 34 | } |
Mike Fiore |
14:f9a77400b622 | 35 | CommandTerminal::Serial()->writef("\r\n"); |
Mike Fiore |
14:f9a77400b622 | 36 | } else { |
Mike Fiore |
14:f9a77400b622 | 37 | CommandTerminal::Serial()->writef("%s\r\n", CommandTerminal::formatPacketData(data, CommandTerminal::Dot()->getRxOutput()).c_str()); |
Mike Fiore |
14:f9a77400b622 | 38 | } |
Mike Fiore |
1:e52ae6584f1c | 39 | } |
Mike Fiore |
1:e52ae6584f1c | 40 | } |
Mike Fiore |
1:e52ae6584f1c | 41 | |
Mike Fiore |
1:e52ae6584f1c | 42 | return 0; |
Mike Fiore |
1:e52ae6584f1c | 43 | } |
Mike Fiore |
1:e52ae6584f1c | 44 | |
Mike Fiore |
1:e52ae6584f1c | 45 | bool CmdSendBinary::verify(std::vector<std::string> args) { |
Mike Fiore |
1:e52ae6584f1c | 46 | if (args.size() == 2) { |
Mike Fiore |
1:e52ae6584f1c | 47 | if (args[1].size() > 484 || !isHexString(args[1], args[1].size() / 2)) { |
Mike Fiore |
14:f9a77400b622 | 48 | CommandTerminal::setErrorMessage("Invalid hex string, (hex:242)"); |
Mike Fiore |
1:e52ae6584f1c | 49 | return false; |
Mike Fiore |
1:e52ae6584f1c | 50 | } |
Mike Fiore |
1:e52ae6584f1c | 51 | |
Mike Fiore |
1:e52ae6584f1c | 52 | return true; |
Mike Fiore |
1:e52ae6584f1c | 53 | } |
Mike Fiore |
1:e52ae6584f1c | 54 | |
Mike Fiore |
14:f9a77400b622 | 55 | CommandTerminal::setErrorMessage("Invalid arguments"); |
Mike Fiore |
1:e52ae6584f1c | 56 | return false; |
Mike Fiore |
1:e52ae6584f1c | 57 | } |
Mike Fiore |
1:e52ae6584f1c | 58 |