mDot AT-Firmware for testing

Dependencies:   MTS-Serial libmDot-mbed5

Fork of Dot-AT-Firmware by MultiTech

Committer:
Fran6
Date:
Mon Aug 14 12:40:21 2017 +0000
Revision:
16:3b1d46c1db11
Parent:
14:f9a77400b622
mDot AT-Firmware

Who changed what in which revision?

UserRevisionLine numberNew 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 14:f9a77400b622 4 CmdSendString::CmdSendString()
Mike Fiore 14:f9a77400b622 5 : Command("Send Once", "AT+SEND", "Sends supplied packet data one time and return response, (max:242 bytes)", "(string:242)") {
Mike Fiore 1:e52ae6584f1c 6 }
Mike Fiore 1:e52ae6584f1c 7
Mike Fiore 1:e52ae6584f1c 8 uint32_t CmdSendString::action(std::vector<std::string> args) {
Mike Fiore 1:e52ae6584f1c 9 // Argument had been split on each comma, rebuild payload
Mike Fiore 14:f9a77400b622 10
Mike Fiore 1:e52ae6584f1c 11 std::string text;
Mike Fiore 1:e52ae6584f1c 12 for (size_t i = 1; i < args.size(); i++) {
Mike Fiore 1:e52ae6584f1c 13 text.append(args[i]);
Mike Fiore 1:e52ae6584f1c 14 if (i != args.size() - 1)
Mike Fiore 1:e52ae6584f1c 15 text.append(",");
Mike Fiore 1:e52ae6584f1c 16 }
Mike Fiore 1:e52ae6584f1c 17
Mike Fiore 1:e52ae6584f1c 18 std::vector<uint8_t> data(text.begin(), text.end());
Mike Fiore 14:f9a77400b622 19 if (CommandTerminal::Dot()->send(data, CommandTerminal::Dot()->getTxWait()) != mDot::MDOT_OK) {
Mike Fiore 14:f9a77400b622 20 CommandTerminal::setErrorMessage(CommandTerminal::Dot()->getLastError());
Mike Fiore 1:e52ae6584f1c 21 return 1;
Mike Fiore 14:f9a77400b622 22 } else if (CommandTerminal::Dot()->getTxWait()) {
Mike Fiore 1:e52ae6584f1c 23 data.clear();
Mike Fiore 1:e52ae6584f1c 24
Mike Fiore 14:f9a77400b622 25 if (CommandTerminal::Dot()->recv(data) == mDot::MDOT_OK) {
Mike Fiore 1:e52ae6584f1c 26 if (!data.empty()) {
Mike Fiore 14:f9a77400b622 27 if (CommandTerminal::Dot()->getRxOutput() == mDot::HEXADECIMAL) {
Mike Fiore 14:f9a77400b622 28 for (size_t i = 0; i < data.size(); i++) {
Mike Fiore 14:f9a77400b622 29 CommandTerminal::Serial()->writef("%02x", data[i]);
Mike Fiore 14:f9a77400b622 30 }
Mike Fiore 14:f9a77400b622 31 CommandTerminal::Serial()->writef("\r\n");
Mike Fiore 14:f9a77400b622 32 } else {
Mike Fiore 14:f9a77400b622 33 CommandTerminal::Serial()->writef("%s\r\n", CommandTerminal::formatPacketData(data, CommandTerminal::Dot()->getRxOutput()).c_str());
Mike Fiore 14:f9a77400b622 34 }
Mike Fiore 1:e52ae6584f1c 35 }
Mike Fiore 1:e52ae6584f1c 36 }
Mike Fiore 1:e52ae6584f1c 37 }
Mike Fiore 1:e52ae6584f1c 38
Mike Fiore 1:e52ae6584f1c 39 return 0;
Mike Fiore 1:e52ae6584f1c 40 }
Mike Fiore 1:e52ae6584f1c 41
Mike Fiore 1:e52ae6584f1c 42 bool CmdSendString::verify(std::vector<std::string> args) {
Mike Fiore 1:e52ae6584f1c 43
Mike Fiore 1:e52ae6584f1c 44 if (args.size() == 1) {
Mike Fiore 1:e52ae6584f1c 45 // allow sending empty packet to retrieve downstream messages
Mike Fiore 1:e52ae6584f1c 46 return true;
Mike Fiore 1:e52ae6584f1c 47 }
Mike Fiore 1:e52ae6584f1c 48
Mike Fiore 2:e5eebd74d36d 49 if (args.size() >= 2) {
Mike Fiore 2:e5eebd74d36d 50 size_t size = 0;
Mike Fiore 9:ff62b20f7000 51 for (size_t i = 1; i < args.size() - 1; i++)
Mike Fiore 4:666017851052 52 size += args[i].size() + 1;
Mike Fiore 2:e5eebd74d36d 53 if (size > 242) {
Mike Fiore 14:f9a77400b622 54 CommandTerminal::setErrorMessage("Invalid packet, expects (string:242)");
Mike Fiore 1:e52ae6584f1c 55 return false;
Mike Fiore 1:e52ae6584f1c 56 }
Mike Fiore 1:e52ae6584f1c 57
Mike Fiore 1:e52ae6584f1c 58 return true;
Mike Fiore 1:e52ae6584f1c 59 }
Mike Fiore 1:e52ae6584f1c 60
Mike Fiore 14:f9a77400b622 61 CommandTerminal::setErrorMessage("Invalid arguments");
Mike Fiore 1:e52ae6584f1c 62 return false;
Mike Fiore 1:e52ae6584f1c 63 }