Ashley Mills / ATConsole

Dependencies:   mbed-rtos VodafoneUSBModem mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ATConsole.cpp Source File

ATConsole.cpp

00001 #include "ATConsole.h"
00002 #include "ATCommandsInterface.h"
00003 
00004 ATConsole::ATConsole(
00005    Serial *terminal,
00006    int lineLength,
00007    int numLines,
00008    bool characterBased,
00009    ATCommandsInterface* atInterface)
00010    : Console(terminal,lineLength,numLines,characterBased), _atInterface(atInterface)  {
00011    
00012    // constructor
00013    atInterface->registerEventsHandler(this);
00014    _gettingSMSData = false;
00015 }
00016 
00017 ATConsole::~ATConsole() {
00018    
00019 }
00020 
00021 void ATConsole::processCommand() {
00022    if(strlen(_lineBuffer)==0)
00023        return;
00024    //_terminal->printf("ATConsole::processCommand()\r\n");
00025    _terminal->printf("\r\n");
00026     if(_gettingSMSData) {
00027        _terminal->printf("_gettingSMSData %s\r\n",_lineBuffer);
00028        strcpy(_smsMessage,_lineBuffer);
00029        _gettingSMSData = false;
00030        return;
00031     }
00032     
00033     if((strncmp(_lineBuffer,"h",_lineLength)==0)||
00034        (strncmp(_lineBuffer,"help",_lineLength)==0)) {
00035         _terminal->printf("Help.\r\n");
00036         _terminal->printf("   \"connect\": Connect to 3G network.\r\n");
00037         _terminal->printf("   \"disconnect\": Disconnect from 3G network.\r\n");
00038         return;
00039     }
00040     
00041     if(!_characterBased) {
00042        _lineBuffer[strlen(_lineBuffer)-2]=0x00;
00043     }
00044     
00045     //_terminal->printf("\r\ncmd: \"%s\"(%d)\r\n",_lineBuffer,strlen(_lineBuffer));
00046     _atInterface->execute(_lineBuffer, this, &_cmdResult, 1000);
00047     
00048     if(_cmdResult.result==ATCommandsInterface::ATResult::AT_OK&&!_gettingSMSData) {
00049        clearBuffer();
00050        _terminal->printf("OK\r\n");
00051     }
00052 }
00053 
00054 void ATConsole::update() {
00055     Console::update();
00056 }
00057 
00058 int ATConsole::onNewATResponseLine(ATCommandsInterface* pInst, const char* line) {
00059    _terminal->printf("%s\r\n",line);
00060    return OK;
00061 }
00062   
00063 int ATConsole::onNewEntryPrompt(ATCommandsInterface* pInst) {
00064    storeBuffer();
00065    clearBuffer();
00066    _terminal->printf("new entry prompt\r\n");
00067    _terminal->printf(">\r\n");
00068    _gettingSMSData = true;
00069    while(_gettingSMSData) {
00070       update();
00071       Thread::wait(10);
00072    }
00073    _terminal->printf("about to send: \"%s\"\r\n",_smsMessage);
00074    _atInterface->sendData(_smsMessage);
00075    return OK;
00076 }
00077 
00078 void ATConsole::onEvent(const char* atCode, const char* evt) {
00079    _terminal->printf("Unsolicited result code: %s - %s\r\n", atCode, evt);
00080 }
00081 
00082 /*virtual*/ void ATConsole::onDispatchStart() { }
00083 
00084 /*virtual*/ void ATConsole::onDispatchStop() { }
00085 
00086 bool ATConsole::isATCodeHandled(const char* atCode) { 
00087    if(strcmp("+CUSD", atCode) == 0 ) {
00088       return true;
00089    }
00090    if(strcmp("+COPS",atCode)==0) {
00091       return true;
00092    }
00093    return false;
00094 }
00095 
00096 /*virtual*/ char* ATConsole::getEventsEnableCommand() {
00097    return NULL; // no need to disable or enable commands
00098 }
00099 
00100 /*virtual*/ char* ATConsole::getEventsDisableCommand() {
00101    return NULL;
00102 }