mDot AT-Firmware for testing

Dependencies:   MTS-Serial libmDot-mbed5

Fork of Dot-AT-Firmware by MultiTech

Revision:
14:f9a77400b622
Parent:
9:ff62b20f7000
--- a/CommandTerminal/CmdSendBinary.cpp	Fri Nov 04 19:10:24 2016 +0000
+++ b/CommandTerminal/CmdSendBinary.cpp	Fri Nov 04 14:25:43 2016 -0500
@@ -1,17 +1,15 @@
 #include "CmdSendBinary.h"
 #include "CommandTerminal.h"
 
-CmdSendBinary::CmdSendBinary(mDot* dot, mts::MTSSerial& serial)
+CmdSendBinary::CmdSendBinary()
 :
-  Command(dot, "Send Binary", "AT+SENDB", "Sends supplied binary (hex) packet data one time and return response"),
-  _serial(serial) {
-    _help = std::string(text()) + ": " + std::string(desc());
-    _usage = "(hex:242)";
+  Command("Send Binary", "AT+SENDB", "Sends supplied binary (hex) packet data one time and return response", "(hex:242)")
+   {
 }
 
 uint32_t CmdSendBinary::action(std::vector<std::string> args) {
     std::vector<uint8_t> data;
-    int32_t code;
+    
     int temp;
     uint32_t length = args[1].size();
 
@@ -21,23 +19,23 @@
         data.push_back(temp);
     }
 
-    if ((code = _dot->send(data, _dot->getTxWait())) != mDot::MDOT_OK) {
-        std::string error = mDot::getReturnCodeString(code);
-
-        if (code != mDot::MDOT_NOT_JOINED)
-            error +=  + " - " + _dot->getLastError();
-
-        setErrorMessage(_dot->getLastError());;
+    if (CommandTerminal::Dot()->send(data, CommandTerminal::Dot()->getTxWait()) != mDot::MDOT_OK) {
+        CommandTerminal::setErrorMessage(CommandTerminal::Dot()->getLastError());;
         return 1;
     }
 
     data.clear();
 
-    if (_dot->getTxWait() && _dot->recv(data) == mDot::MDOT_OK) {
+    if (CommandTerminal::Dot()->getTxWait() && CommandTerminal::Dot()->recv(data) == mDot::MDOT_OK) {
         if (!data.empty()) {
-            if (_dot->getVerbose())
-                _serial.writef("Packet data:\r\n");
-            _serial.writef("%s\r\n", CommandTerminal::formatPacketData(data, _dot->getRxOutput()).c_str());
+            if (CommandTerminal::Dot()->getRxOutput() == mDot::HEXADECIMAL) {
+                for (size_t i = 0; i < data.size(); i++) {
+                    CommandTerminal::Serial()->writef("%02x", data[i]);
+                }
+                CommandTerminal::Serial()->writef("\r\n");
+            } else {
+                CommandTerminal::Serial()->writef("%s\r\n", CommandTerminal::formatPacketData(data, CommandTerminal::Dot()->getRxOutput()).c_str());
+            }
         }
     }
 
@@ -47,14 +45,14 @@
 bool CmdSendBinary::verify(std::vector<std::string> args) {
     if (args.size() == 2) {
         if (args[1].size() > 484 || !isHexString(args[1], args[1].size() / 2)) {
-            setErrorMessage("Invalid hex string, (hex:242)");
+            CommandTerminal::setErrorMessage("Invalid hex string, (hex:242)");
             return false;
         }
 
         return true;
     }
 
-    setErrorMessage("Invalid arguments");
+    CommandTerminal::setErrorMessage("Invalid arguments");
     return false;
 }