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:
Tue Sep 18 12:08:49 2012 +0000
Revision:
8:fc50785435c5
Parent:
7:f46ec146f3de
Child:
11:76ecb8799b0d
Changed the way that things are printed out to reduce clutter.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ashleymills 0:6c831cc49d22 1 #include "ATConsole.h"
ashleymills 2:8cc63f7a24cf 2 #include "ATCommandsInterface.h"
ashleymills 0:6c831cc49d22 3
ashleymills 4:6971bded3ebd 4 ATConsole::ATConsole(
ashleymills 4:6971bded3ebd 5 Serial *terminal,
ashleymills 4:6971bded3ebd 6 int lineLength,
ashleymills 4:6971bded3ebd 7 int numLines,
ashleymills 4:6971bded3ebd 8 bool characterBased,
ashleymills 4:6971bded3ebd 9 ATCommandsInterface* atInterface)
ashleymills 4:6971bded3ebd 10 : Console(terminal,lineLength,numLines,characterBased), _atInterface(atInterface) {
ashleymills 4:6971bded3ebd 11
ashleymills 4:6971bded3ebd 12 // constructor
ashleymills 4:6971bded3ebd 13 atInterface->registerEventsHandler(this);
ashleymills 2:8cc63f7a24cf 14 _gettingSMSData = false;
ashleymills 0:6c831cc49d22 15 }
ashleymills 0:6c831cc49d22 16
ashleymills 0:6c831cc49d22 17 ATConsole::~ATConsole() {
ashleymills 0:6c831cc49d22 18
ashleymills 0:6c831cc49d22 19 }
ashleymills 0:6c831cc49d22 20
ashleymills 0:6c831cc49d22 21 void ATConsole::processCommand() {
ashleymills 3:6b3ca3af97cf 22 if(strlen(_lineBuffer)==0)
ashleymills 3:6b3ca3af97cf 23 return;
ashleymills 7:f46ec146f3de 24 //_terminal->printf("ATConsole::processCommand()\r\n");
ashleymills 8:fc50785435c5 25 _terminal->printf("\r\n");
ashleymills 2:8cc63f7a24cf 26 if(_gettingSMSData) {
ashleymills 3:6b3ca3af97cf 27 _terminal->printf("_gettingSMSData %s\r\n",_lineBuffer);
ashleymills 3:6b3ca3af97cf 28 strcpy(_smsMessage,_lineBuffer);
ashleymills 2:8cc63f7a24cf 29 _gettingSMSData = false;
ashleymills 2:8cc63f7a24cf 30 return;
ashleymills 2:8cc63f7a24cf 31 }
ashleymills 2:8cc63f7a24cf 32
ashleymills 0:6c831cc49d22 33 if((strncmp(_lineBuffer,"h",_lineLength)==0)||
ashleymills 0:6c831cc49d22 34 (strncmp(_lineBuffer,"help",_lineLength)==0)) {
ashleymills 1:719c0f047c34 35 _terminal->printf("Help.\r\n");
ashleymills 1:719c0f047c34 36 _terminal->printf(" \"connect\": Connect to 3G network.\r\n");
ashleymills 1:719c0f047c34 37 _terminal->printf(" \"disconnect\": Disconnect from 3G network.\r\n");
ashleymills 0:6c831cc49d22 38 return;
ashleymills 0:6c831cc49d22 39 }
ashleymills 3:6b3ca3af97cf 40
ashleymills 4:6971bded3ebd 41 if(!_characterBased) {
ashleymills 4:6971bded3ebd 42 _lineBuffer[strlen(_lineBuffer)-2]=0x00;
ashleymills 4:6971bded3ebd 43 }
ashleymills 4:6971bded3ebd 44
ashleymills 7:f46ec146f3de 45 //_terminal->printf("\r\ncmd: \"%s\"(%d)\r\n",_lineBuffer,strlen(_lineBuffer));
ashleymills 1:719c0f047c34 46 _atInterface->execute(_lineBuffer, this, &_cmdResult, 1000);
ashleymills 2:8cc63f7a24cf 47
ashleymills 3:6b3ca3af97cf 48 if(_cmdResult.result==ATCommandsInterface::ATResult::AT_OK&&!_gettingSMSData) {
ashleymills 2:8cc63f7a24cf 49 clearBuffer();
ashleymills 2:8cc63f7a24cf 50 _terminal->printf("OK\r\n");
ashleymills 2:8cc63f7a24cf 51 }
ashleymills 0:6c831cc49d22 52 }
ashleymills 0:6c831cc49d22 53
ashleymills 0:6c831cc49d22 54 void ATConsole::update() {
ashleymills 0:6c831cc49d22 55 Console::update();
ashleymills 1:719c0f047c34 56 }
ashleymills 1:719c0f047c34 57
ashleymills 1:719c0f047c34 58 int ATConsole::onNewATResponseLine(ATCommandsInterface* pInst, const char* line) {
ashleymills 8:fc50785435c5 59 _terminal->printf("%s\r\n",line);
ashleymills 1:719c0f047c34 60 return OK;
ashleymills 1:719c0f047c34 61 }
ashleymills 1:719c0f047c34 62
ashleymills 1:719c0f047c34 63 int ATConsole::onNewEntryPrompt(ATCommandsInterface* pInst) {
ashleymills 3:6b3ca3af97cf 64 _terminal->printf("new entry prompt\r\n");
ashleymills 3:6b3ca3af97cf 65 _terminal->printf(">\r\n");
ashleymills 2:8cc63f7a24cf 66 _gettingSMSData = true;
ashleymills 2:8cc63f7a24cf 67 while(_gettingSMSData) {
ashleymills 2:8cc63f7a24cf 68 update();
ashleymills 2:8cc63f7a24cf 69 Thread::wait(10);
ashleymills 2:8cc63f7a24cf 70 }
ashleymills 3:6b3ca3af97cf 71 _terminal->printf("about to send: \"%s\"\r\n",_smsMessage);
ashleymills 3:6b3ca3af97cf 72 _atInterface->sendData(_smsMessage);
ashleymills 1:719c0f047c34 73 return OK;
ashleymills 2:8cc63f7a24cf 74 }
ashleymills 2:8cc63f7a24cf 75
ashleymills 2:8cc63f7a24cf 76 void ATConsole::onEvent(const char* atCode, const char* evt) {
ashleymills 4:6971bded3ebd 77 _terminal->printf("Unsolicited result code: %s - %s\r\n", atCode, evt);
ashleymills 2:8cc63f7a24cf 78 }
ashleymills 2:8cc63f7a24cf 79
ashleymills 2:8cc63f7a24cf 80 /*virtual*/ void ATConsole::onDispatchStart() { }
ashleymills 2:8cc63f7a24cf 81
ashleymills 2:8cc63f7a24cf 82 /*virtual*/ void ATConsole::onDispatchStop() { }
ashleymills 2:8cc63f7a24cf 83
ashleymills 4:6971bded3ebd 84 bool ATConsole::isATCodeHandled(const char* atCode) {
ashleymills 4:6971bded3ebd 85 if(strcmp("+CUSD", atCode) == 0 ) {
ashleymills 4:6971bded3ebd 86 return true;
ashleymills 4:6971bded3ebd 87 }
ashleymills 4:6971bded3ebd 88 return false;
ashleymills 4:6971bded3ebd 89 }