This is a console for interacting with Vodafone dongles.

Dependencies:   mbed-rtos VodafoneUSBModem mbed

This is a bridge between a serial driven console and a serial driven cellular modem or modem interface. This was written to complement our collaboration with mbed: See https://mbed.org/users/mbed_official/code/VodafoneUSBModem/ for further information.

For example, one can use GNU screen or PuTTY (two popular consoles) to interact with a Vodafone K3770 USB dongle. In the image below I used the UNIX version of PuTTY:

/media/uploads/ashleymills/atcons.png

Support is provided for line-based consoles, which send one line at a time, and for character based consoles.

For character based consoles, the following line-editing features are provided:

  • In-line editing (deletion, left/right arrow keys, insertion)
  • Command history (via up/down arrow keys)

Line buffer length, and command history depth, are compile-time options.

--

How to use:

Compile and save to mbed.

Connect PuTTY or GNU screen to serial port.

If you use GNU screen you probably already know what you are doing.

If you use PuTTY, you need to set the options to specify the serial device and, set the baud rate, and set the "Connection Type" to "Serial":

/media/uploads/ashleymills/putty0.png

You need to set the keyboard to send Control-H for backspace, and use "Linux" function keys and keypad:

/media/uploads/ashleymills/putty1.png

Revision:
4:6971bded3ebd
Parent:
0:6c831cc49d22
Child:
5:6841a01b3a69
--- a/Console.cpp	Tue Aug 28 12:47:45 2012 +0000
+++ b/Console.cpp	Tue Sep 18 09:24:41 2012 +0000
@@ -1,25 +1,29 @@
 #include "Console.h"
 //#define DEBUG
 
-Console::Console(Serial *terminal, int lineLength, int numLines)
-    : _terminal(terminal), _lineLength(lineLength), _numLines(numLines) {
+Console::Console(Serial *terminal, int lineLength, int numLines, bool characterBased)
+    : _terminal(terminal), _lineLength(lineLength), _numLines(numLines), _characterBased(characterBased) {
     
     _terminal->printf("Console ready!\r\n");
     
     // set the buffer timeout
     _bufferWaitTimeout = BUFFER_WAIT_TIMEOUT;
-    
+     
     // allocate space for current line
     _lineBuffer = (char*)malloc((_lineLength+1)*sizeof(char));
-    _lines = (char**)malloc(_numLines*sizeof(char*));
-    for(int i=0; i<_numLines; i++) {
-        _lines[i] = (char*)malloc((_lineLength+1)*sizeof(char));
+    
+    // character based consoles need a history
+    if(_characterBased) {
+       _lines = (char**)malloc(_numLines*sizeof(char*));
+       for(int i=0; i<_numLines; i++) {
+          _lines[i] = (char*)malloc((_lineLength+1)*sizeof(char));
+       }
+    
+       // blank out current line with NULLs
+       for(int i=0; i<=_lineLength; i++)
+          _lineBuffer[i] = 0x00;
     }
     
-    // blank out current line with NULLs
-    for(int i=0; i<=_lineLength; i++)
-        _lineBuffer[i] = 0x00;
-    
     // set line position, number of used lines, and line buffer pointer to 0    
     _linePos = 0;
     _prevLinePos = 0;
@@ -125,12 +129,14 @@
     _terminal->printf("%d) \"%s\"\r\n",index,_lines[index]);
 }
 
+
 void Console::reprintBuffer() {
     //printf("plp: %d, lB: %d\r\n",_prevLinePos,_lineLength);
     _terminal->putc('\r');
     for(int i=0; i<_lineLength; i++) {;
         _terminal->putc(' ');
     }
+    
     _terminal->putc('\r');
     if(_linePos>0) {
        _terminal->printf("%s",_lineBuffer);
@@ -162,9 +168,30 @@
     _terminal->printf("\r\n");
 }
 
-// process the console
-void Console::update() {
-    // process console input
+void Console::updateLineBased() {
+   //_terminal->printf("line based\r\n");
+   // save until a line is read and then dump to the modem
+   while(_terminal->readable()) {
+      int c = _terminal->getc();
+      if(_linePos<_lineLength) {
+         
+         _lineBuffer[_linePos++] = c;
+         _terminal->printf("%c",c);
+         // activate process command when
+         if(c==0x0a) {
+            processCommand();
+            clearBuffer();
+            return;
+         }
+      } else {
+         _terminal->printf("WARNING, max line length exceeded!!!");
+      }
+      
+   }      
+}
+
+void Console::updateCharacterBased() {
+// process console input
     while(_terminal->readable()) {
         int c = _terminal->getc();
         switch(c) {
@@ -182,6 +209,7 @@
                             copyPointer++;
                         }
                     }
+                    
                     reprintBuffer();
                 }           
             break;
@@ -273,4 +301,13 @@
         printLineBuffer();
         #endif
     }
+}
+
+// process the console
+void Console::update() {
+   if(_characterBased) {
+      updateCharacterBased();
+   } else {
+      updateLineBased();
+   }
 }
\ No newline at end of file