few changes for RTS/CTS control
Dependencies: MTS-Serial libmDot mbed-rtos mbed
Fork of mDot_AT_firmware by
CommandTerminal/CmdSendString.cpp@9:ff62b20f7000, 2016-04-04 (annotated)
- Committer:
- Mike Fiore
- Date:
- Mon Apr 04 09:00:31 2016 -0500
- Revision:
- 9:ff62b20f7000
- Parent:
- 4:666017851052
update to version 1.0.8 of AT firmware
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 |
9:ff62b20f7000 | 24 | setErrorMessage(_dot->getLastError()); |
Mike Fiore |
1:e52ae6584f1c | 25 | return 1; |
Mike Fiore |
9:ff62b20f7000 | 26 | } else if (_dot->getTxWait()) { |
Mike Fiore |
1:e52ae6584f1c | 27 | data.clear(); |
Mike Fiore |
1:e52ae6584f1c | 28 | |
Mike Fiore |
1:e52ae6584f1c | 29 | if (_dot->recv(data) == mDot::MDOT_OK) { |
Mike Fiore |
1:e52ae6584f1c | 30 | if (!data.empty()) { |
Mike Fiore |
1:e52ae6584f1c | 31 | if (_dot->getVerbose()) |
Mike Fiore |
1:e52ae6584f1c | 32 | _serial.writef("Packet data:\r\n"); |
Mike Fiore |
1:e52ae6584f1c | 33 | _serial.writef("%s\r\n", CommandTerminal::formatPacketData(data, _dot->getRxOutput()).c_str()); |
Mike Fiore |
1:e52ae6584f1c | 34 | } |
Mike Fiore |
1:e52ae6584f1c | 35 | } |
Mike Fiore |
1:e52ae6584f1c | 36 | } |
Mike Fiore |
1:e52ae6584f1c | 37 | |
Mike Fiore |
1:e52ae6584f1c | 38 | return 0; |
Mike Fiore |
1:e52ae6584f1c | 39 | } |
Mike Fiore |
1:e52ae6584f1c | 40 | |
Mike Fiore |
1:e52ae6584f1c | 41 | bool CmdSendString::verify(std::vector<std::string> args) { |
Mike Fiore |
1:e52ae6584f1c | 42 | |
Mike Fiore |
1:e52ae6584f1c | 43 | if (args.size() == 1) { |
Mike Fiore |
1:e52ae6584f1c | 44 | // allow sending empty packet to retrieve downstream messages |
Mike Fiore |
1:e52ae6584f1c | 45 | return true; |
Mike Fiore |
1:e52ae6584f1c | 46 | } |
Mike Fiore |
1:e52ae6584f1c | 47 | |
Mike Fiore |
2:e5eebd74d36d | 48 | if (args.size() >= 2) { |
Mike Fiore |
2:e5eebd74d36d | 49 | size_t size = 0; |
Mike Fiore |
9:ff62b20f7000 | 50 | for (size_t i = 1; i < args.size() - 1; i++) |
Mike Fiore |
4:666017851052 | 51 | size += args[i].size() + 1; |
Mike Fiore |
2:e5eebd74d36d | 52 | if (size > 242) { |
Mike Fiore |
1:e52ae6584f1c | 53 | setErrorMessage("Invalid packet, expects (string:242)"); |
Mike Fiore |
1:e52ae6584f1c | 54 | return false; |
Mike Fiore |
1:e52ae6584f1c | 55 | } |
Mike Fiore |
1:e52ae6584f1c | 56 | |
Mike Fiore |
1:e52ae6584f1c | 57 | return true; |
Mike Fiore |
1:e52ae6584f1c | 58 | } |
Mike Fiore |
1:e52ae6584f1c | 59 | |
Mike Fiore |
1:e52ae6584f1c | 60 | setErrorMessage("Invalid arguments"); |
Mike Fiore |
1:e52ae6584f1c | 61 | return false; |
Mike Fiore |
1:e52ae6584f1c | 62 | } |