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:05:34 2012 +0000
Revision:
7:f46ec146f3de
Parent:
4:6971bded3ebd
Child:
8:fc50785435c5
Removed debug statements. Fixed typo.

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