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

ATConsole.cpp

Committer:
ashleymills
Date:
2013-09-25
Revision:
14:3f5fd1d95f5f
Parent:
12:c087d25ec3b8

File content as of revision 14:3f5fd1d95f5f:

#include "ATConsole.h"
#include "ATCommandsInterface.h"

ATConsole::ATConsole(
   Serial *terminal,
   int lineLength,
   int numLines,
   bool characterBased,
   ATCommandsInterface* atInterface)
   : Console(terminal,lineLength,numLines,characterBased), _atInterface(atInterface)  {
   
   // constructor
   atInterface->registerEventsHandler(this);
   _gettingSMSData = false;
}

ATConsole::~ATConsole() {
   
}

void ATConsole::processCommand() {
   if(strlen(_lineBuffer)==0)
       return;
   //_terminal->printf("ATConsole::processCommand()\r\n");
   _terminal->printf("\r\n");
    if(_gettingSMSData) {
       _terminal->printf("_gettingSMSData %s\r\n",_lineBuffer);
       strcpy(_smsMessage,_lineBuffer);
       _gettingSMSData = false;
       return;
    }
    
    if((strncmp(_lineBuffer,"h",_lineLength)==0)||
       (strncmp(_lineBuffer,"help",_lineLength)==0)) {
        _terminal->printf("Help.\r\n");
        _terminal->printf("   \"connect\": Connect to 3G network.\r\n");
        _terminal->printf("   \"disconnect\": Disconnect from 3G network.\r\n");
        return;
    }
    
    if(!_characterBased) {
       _lineBuffer[strlen(_lineBuffer)-2]=0x00;
    }
    
    //_terminal->printf("\r\ncmd: \"%s\"(%d)\r\n",_lineBuffer,strlen(_lineBuffer));
    _atInterface->execute(_lineBuffer, this, &_cmdResult, 1000);
    
    if(_cmdResult.result==ATCommandsInterface::ATResult::AT_OK&&!_gettingSMSData) {
       clearBuffer();
       _terminal->printf("OK\r\n");
    }
}

void ATConsole::update() {
    Console::update();
}

int ATConsole::onNewATResponseLine(ATCommandsInterface* pInst, const char* line) {
   _terminal->printf("%s\r\n",line);
   return OK;
}
  
int ATConsole::onNewEntryPrompt(ATCommandsInterface* pInst) {
   storeBuffer();
   clearBuffer();
   _terminal->printf("new entry prompt\r\n");
   _terminal->printf(">\r\n");
   _gettingSMSData = true;
   while(_gettingSMSData) {
      update();
      Thread::wait(10);
   }
   _terminal->printf("about to send: \"%s\"\r\n",_smsMessage);
   _atInterface->sendData(_smsMessage);
   return OK;
}

void ATConsole::onEvent(const char* atCode, const char* evt) {
   _terminal->printf("Unsolicited result code: %s - %s\r\n", atCode, evt);
}

/*virtual*/ void ATConsole::onDispatchStart() { }

/*virtual*/ void ATConsole::onDispatchStop() { }

bool ATConsole::isATCodeHandled(const char* atCode) { 
   if(strcmp("+CUSD", atCode) == 0 ) {
      return true;
   }
   if(strcmp("+COPS",atCode)==0) {
      return true;
   }
   return false;
}

/*virtual*/ char* ATConsole::getEventsEnableCommand() {
   return NULL; // no need to disable or enable commands
}

/*virtual*/ char* ATConsole::getEventsDisableCommand() {
   return NULL;
}