mDot AT-Firmware for testing
Dependencies: MTS-Serial libmDot-mbed5
Fork of Dot-AT-Firmware by
CommandTerminal/CmdSendString.cpp@2:e5eebd74d36d, 2015-07-10 (annotated)
- Committer:
- Mike Fiore
- Date:
- Fri Jul 10 09:43:56 2015 -0500
- Revision:
- 2:e5eebd74d36d
- Parent:
- 1:e52ae6584f1c
- Child:
- 4:666017851052
update from rev 6d77074fdfa315ba86bedecc44515b11bfa6e9a0 - add support for commas in payloads of +SEND and +SENDI
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mike Fiore |
1:e52ae6584f1c | 1 | #include "CmdSendString.h" |
Mike Fiore |
1:e52ae6584f1c | 2 | #include "CommandTerminal.h" |
Mike Fiore |
1:e52ae6584f1c | 3 | |
Mike Fiore |
1:e52ae6584f1c | 4 | CmdSendString::CmdSendString(mDot* dot, mts::MTSSerial& serial) |
Mike Fiore |
1:e52ae6584f1c | 5 | : |
Mike Fiore |
1:e52ae6584f1c | 6 | Command(dot, "Send Once", "AT+SEND", "Sends supplied packet data one time and return response, (max:242 bytes)"), |
Mike Fiore |
1:e52ae6584f1c | 7 | _serial(serial) { |
Mike Fiore |
1:e52ae6584f1c | 8 | _help = std::string(text()) + ": " + std::string(desc()); |
Mike Fiore |
1:e52ae6584f1c | 9 | _usage = "(string:242)"; |
Mike Fiore |
1:e52ae6584f1c | 10 | } |
Mike Fiore |
1:e52ae6584f1c | 11 | |
Mike Fiore |
1:e52ae6584f1c | 12 | uint32_t CmdSendString::action(std::vector<std::string> args) { |
Mike Fiore |
1:e52ae6584f1c | 13 | // Argument had been split on each comma, rebuild payload |
Mike Fiore |
1:e52ae6584f1c | 14 | int32_t code; |
Mike Fiore |
1:e52ae6584f1c | 15 | std::string text; |
Mike Fiore |
1:e52ae6584f1c | 16 | for (size_t i = 1; i < args.size(); i++) { |
Mike Fiore |
1:e52ae6584f1c | 17 | text.append(args[i]); |
Mike Fiore |
1:e52ae6584f1c | 18 | if (i != args.size() - 1) |
Mike Fiore |
1:e52ae6584f1c | 19 | text.append(","); |
Mike Fiore |
1:e52ae6584f1c | 20 | } |
Mike Fiore |
1:e52ae6584f1c | 21 | |
Mike Fiore |
1:e52ae6584f1c | 22 | std::vector<uint8_t> data(text.begin(), text.end()); |
Mike Fiore |
1:e52ae6584f1c | 23 | if ((code = _dot->send(data, _dot->getTxWait())) != mDot::MDOT_OK) { |
Mike Fiore |
1:e52ae6584f1c | 24 | std::string error = mDot::getReturnCodeString(code); |
Mike Fiore |
1:e52ae6584f1c | 25 | |
Mike Fiore |
1:e52ae6584f1c | 26 | if (code != mDot::MDOT_NOT_JOINED) |
Mike Fiore |
1:e52ae6584f1c | 27 | error += + " - " + _dot->getLastError(); |
Mike Fiore |
1:e52ae6584f1c | 28 | |
Mike Fiore |
1:e52ae6584f1c | 29 | setErrorMessage(error); |
Mike Fiore |
1:e52ae6584f1c | 30 | return 1; |
Mike Fiore |
1:e52ae6584f1c | 31 | } |
Mike Fiore |
1:e52ae6584f1c | 32 | |
Mike Fiore |
1:e52ae6584f1c | 33 | if (_dot->getTxWait()) { |
Mike Fiore |
1:e52ae6584f1c | 34 | data.clear(); |
Mike Fiore |
1:e52ae6584f1c | 35 | |
Mike Fiore |
1:e52ae6584f1c | 36 | if (_dot->recv(data) == mDot::MDOT_OK) { |
Mike Fiore |
1:e52ae6584f1c | 37 | if (!data.empty()) { |
Mike Fiore |
1:e52ae6584f1c | 38 | if (_dot->getVerbose()) |
Mike Fiore |
1:e52ae6584f1c | 39 | _serial.writef("Packet data:\r\n"); |
Mike Fiore |
1:e52ae6584f1c | 40 | _serial.writef("%s\r\n", CommandTerminal::formatPacketData(data, _dot->getRxOutput()).c_str()); |
Mike Fiore |
1:e52ae6584f1c | 41 | } |
Mike Fiore |
1:e52ae6584f1c | 42 | } |
Mike Fiore |
1:e52ae6584f1c | 43 | } |
Mike Fiore |
1:e52ae6584f1c | 44 | |
Mike Fiore |
1:e52ae6584f1c | 45 | return 0; |
Mike Fiore |
1:e52ae6584f1c | 46 | } |
Mike Fiore |
1:e52ae6584f1c | 47 | |
Mike Fiore |
1:e52ae6584f1c | 48 | bool CmdSendString::verify(std::vector<std::string> args) { |
Mike Fiore |
1:e52ae6584f1c | 49 | |
Mike Fiore |
1:e52ae6584f1c | 50 | if (args.size() == 1) { |
Mike Fiore |
1:e52ae6584f1c | 51 | // allow sending empty packet to retrieve downstream messages |
Mike Fiore |
1:e52ae6584f1c | 52 | return true; |
Mike Fiore |
1:e52ae6584f1c | 53 | } |
Mike Fiore |
1:e52ae6584f1c | 54 | |
Mike Fiore |
2:e5eebd74d36d | 55 | if (args.size() >= 2) { |
Mike Fiore |
2:e5eebd74d36d | 56 | size_t size = 0; |
Mike Fiore |
2:e5eebd74d36d | 57 | for (int i = 1; i < args.size(); i++) |
Mike Fiore |
2:e5eebd74d36d | 58 | size += args[i].size(); |
Mike Fiore |
2:e5eebd74d36d | 59 | if (size > 242) { |
Mike Fiore |
1:e52ae6584f1c | 60 | setErrorMessage("Invalid packet, expects (string:242)"); |
Mike Fiore |
1:e52ae6584f1c | 61 | return false; |
Mike Fiore |
1:e52ae6584f1c | 62 | } |
Mike Fiore |
1:e52ae6584f1c | 63 | |
Mike Fiore |
1:e52ae6584f1c | 64 | return true; |
Mike Fiore |
1:e52ae6584f1c | 65 | } |
Mike Fiore |
1:e52ae6584f1c | 66 | |
Mike Fiore |
1:e52ae6584f1c | 67 | setErrorMessage("Invalid arguments"); |
Mike Fiore |
1:e52ae6584f1c | 68 | return false; |
Mike Fiore |
1:e52ae6584f1c | 69 | } |