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

Committer:
ashleymills
Date:
Wed Sep 25 08:43:19 2013 +0000
Revision:
14:3f5fd1d95f5f
Parent:
11:76ecb8799b0d
Updated dependencies.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ashleymills 10:b2c5a4b21bd8 1 /* Console.h */
ashleymills 10:b2c5a4b21bd8 2 /* Copyright (C) 2012 Ashley Mills, MIT License
ashleymills 10:b2c5a4b21bd8 3 *
ashleymills 10:b2c5a4b21bd8 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
ashleymills 10:b2c5a4b21bd8 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
ashleymills 10:b2c5a4b21bd8 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
ashleymills 10:b2c5a4b21bd8 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
ashleymills 10:b2c5a4b21bd8 8 * furnished to do so, subject to the following conditions:
ashleymills 10:b2c5a4b21bd8 9 *
ashleymills 10:b2c5a4b21bd8 10 * The above copyright notice and this permission notice shall be included in all copies or
ashleymills 10:b2c5a4b21bd8 11 * substantial portions of the Software.
ashleymills 10:b2c5a4b21bd8 12 *
ashleymills 10:b2c5a4b21bd8 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
ashleymills 10:b2c5a4b21bd8 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
ashleymills 10:b2c5a4b21bd8 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
ashleymills 10:b2c5a4b21bd8 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ashleymills 10:b2c5a4b21bd8 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ashleymills 10:b2c5a4b21bd8 18 */
ashleymills 10:b2c5a4b21bd8 19
ashleymills 0:6c831cc49d22 20 #pragma once
ashleymills 0:6c831cc49d22 21 #include "mbed.h"
ashleymills 0:6c831cc49d22 22
ashleymills 5:6841a01b3a69 23 #define BUFFER_WAIT_TIMEOUT_MS 2000
ashleymills 0:6c831cc49d22 24
ashleymills 10:b2c5a4b21bd8 25 /** Console interface with line editing and command history.
ashleymills 10:b2c5a4b21bd8 26 */
ashleymills 0:6c831cc49d22 27 class Console {
ashleymills 6:93003e18889c 28
ashleymills 0:6c831cc49d22 29 public:
ashleymills 9:578003606ccc 30 /** Construct an interface to a serial terminal.
ashleymills 10:b2c5a4b21bd8 31 *
ashleymills 6:93003e18889c 32 * @param terminal The serial device to interface to.
ashleymills 6:93003e18889c 33 * @param lineLength The maximum line-length to process.
ashleymills 6:93003e18889c 34 * @param numLines The number of lines to hold in the command-history.
ashleymills 6:93003e18889c 35 * @param characterBased true for character based serial devices, false for line based.
ashleymills 6:93003e18889c 36 */
ashleymills 4:6971bded3ebd 37 Console(Serial *terminal, int lineLength, int numLines, bool characterBased);
ashleymills 0:6c831cc49d22 38 ~Console();
ashleymills 10:b2c5a4b21bd8 39 /** This is called by the instantiating program to update the console.
ashleymills 6:93003e18889c 40 */
ashleymills 2:8cc63f7a24cf 41 virtual void update();
ashleymills 6:93003e18889c 42
ashleymills 6:93003e18889c 43 protected:
ashleymills 6:93003e18889c 44 char *_lineBuffer; //< Buffer for current-line.
ashleymills 6:93003e18889c 45 int _lineLength; //< Length of current-line buffer.
ashleymills 6:93003e18889c 46 int _numLines; //< Number of lines in the command history.
ashleymills 6:93003e18889c 47 Serial *_terminal; //< Pointer to terminal interface.
ashleymills 6:93003e18889c 48 /// Whether or not this console is character based (true) or line based (false).
ashleymills 7:f46ec146f3de 49 bool _characterBased;
ashleymills 6:93003e18889c 50
ashleymills 11:76ecb8799b0d 51 protected:
ashleymills 11:76ecb8799b0d 52 void storeBuffer(); //< Store the current-line in the command history.
ashleymills 6:93003e18889c 53 void clearBuffer(); //< Clears the current-line buffer.
ashleymills 6:93003e18889c 54
ashleymills 6:93003e18889c 55 private:
ashleymills 6:93003e18889c 56 char **_lines; //< Command history
ashleymills 6:93003e18889c 57 int _currentLine; //< Index of current line in command history.
ashleymills 6:93003e18889c 58 int _usedLines; //< Number of lines that have been used in the command history.
ashleymills 6:93003e18889c 59
ashleymills 6:93003e18889c 60 long _bufferWaitTimeout_ms; //< This is used when multi-byte sequences are predicted.
ashleymills 6:93003e18889c 61
ashleymills 6:93003e18889c 62 int _linePos; //< Keeps track of the cursor in the current-line.
ashleymills 6:93003e18889c 63 int _prevLinePos; //< Used when a new line is selected from command history, to clear old line.
ashleymills 0:6c831cc49d22 64
ashleymills 6:93003e18889c 65 bool waitForInput(); //< Waits for _bufferWaitTimeout_ms for input from the console.
ashleymills 6:93003e18889c 66 void loadPreviousBuffer(); //< Load the previous line in the command history.
ashleymills 6:93003e18889c 67 void loadNextBuffer(); //< Load the next line in the command history.
ashleymills 6:93003e18889c 68
ashleymills 6:93003e18889c 69 void printLineBuffer(); //< Prints the current-line buffer.
ashleymills 6:93003e18889c 70 void printHistory(); //< Print the entire command-history.
ashleymills 6:93003e18889c 71 void printBuffer(int index); //< Print buffer at index in the command-history.
ashleymills 6:93003e18889c 72 void reprintBuffer(); //< Clears old buffer and reprints it, used for insertion etc.
ashleymills 11:76ecb8799b0d 73
ashleymills 6:93003e18889c 74 void updateCharacterBased(); //< Called by update() for character-based consoles.
ashleymills 6:93003e18889c 75 void updateLineBased(); //< Called by update() for line-based consoles.
ashleymills 6:93003e18889c 76
ashleymills 6:93003e18889c 77 virtual void processCommand(); //< Process a command retrieved from the console.
ashleymills 6:93003e18889c 78
ashleymills 0:6c831cc49d22 79 };