ME910 support

Fork of MTS-Cellular by MultiTech

Revision:
1:f155d94d6f3a
Child:
4:1f63354b8d1b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/Terminal.cpp	Mon May 19 12:34:32 2014 -0500
@@ -0,0 +1,53 @@
+#include "Terminal.h"
+
+using namespace mts;
+
+Terminal::Terminal(MTSBufferedIO* io) : io(io), index(0)
+{
+    terminal = new MTSSerial(USBTX, USBRX);
+}
+
+Terminal::~Terminal()
+{
+    delete terminal; 
+}
+
+void Terminal::start()
+{
+    //Setup terminal session
+    printf("Starting Terminal Mode.\n\r");
+    char buffer[256];
+    bool running = true;
+
+    //Run terminal session
+    while (running) {
+        //Write terminal data to interface
+        int terminalRead = terminal->readable();
+        terminal->read(buffer, terminalRead);
+        io->write(buffer, terminalRead);
+        
+        //Check for exit condition
+        for (int i = 0; i < terminalRead; i++) {
+            if (index < (exitMsg.size() - 1)) {
+                if(buffer[i] == exitMsg[index]) {
+                    index++;
+                } else {
+                    index = 0;
+                }
+            } else {
+                running = false;
+                wait(.1);
+            }
+        }
+        
+        //Write interface data to the terminal
+        int ioRead = io->readable();
+        io->read(buffer, ioRead);
+        terminal->write(buffer, ioRead);
+    }
+    
+    //Cleanup and return
+    io->txClear();
+    io->rxClear();
+    printf("\n\rExited Terminal Mode.\n\r");
+}
\ No newline at end of file