PHS module SMA-01 library. see: https://developer.mbed.org/users/phsfan/notebook/abitusbmodem/
Dependencies: Socket lwip-sys lwip
Dependents: AbitUSBModem_HTTPTest AbitUSBModem_MQTTTest AbitUSBModem_WebsocketTest AbitUSBModem_SMSTest
Fork of VodafoneUSBModem by
Diff: ussd/USSDInterface.cpp
- Revision:
- 29:870de7db2ccb
- Parent:
- 22:06fb2a93a1f6
- Child:
- 35:be311326ee06
--- a/ussd/USSDInterface.cpp Thu Aug 30 10:48:35 2012 +0000 +++ b/ussd/USSDInterface.cpp Thu Aug 30 12:58:10 2012 +0000 @@ -61,11 +61,13 @@ //Send USSD command to the network char cmd[32]; std::sprintf(cmd, "AT+CUSD=1,\"%s\"", command); - int ret = m_pIf->executeSimple(cmd, NULL, DEFAULT_TIMEOUT); + int ret = m_pIf->execute(cmd, this, NULL, DEFAULT_TIMEOUT); if( ret != OK ) { return NET_PROTOCOL; } + + //Did we already get a response (3GPP rev < 6) ? //Now wait for response int res = m_responseSphre.wait(USSD_TIMEOUT); @@ -90,7 +92,33 @@ DBG("Result received: %s", result); return OK; +} +/*virtual*/ int USSDInterface::onNewATResponseLine(ATCommandsInterface* pInst, const char* line) +{ + const char* pSemicol = strchr(line, ':'); + if( ( (pSemicol - line) != strlen("+CUSD") ) || ( memcmp(line, "+CUSD", strlen("+CUSD")) != 0) ) + { + WARN("Unknown code"); + return OK; + } + + const char* pData = NULL; + if( pSemicol != NULL ) //Split the identifier & the result code (if it exists) + { + pData = pSemicol + 1; + if(pData[0]==' ') + { + pData++; //Suppress whitespace + } + processResult(pData); + } + return OK; +} + +/*virtual*/ int USSDInterface::onNewEntryPrompt(ATCommandsInterface* pInst) +{ + return OK; } /*virtual*/ bool USSDInterface::isATCodeHandled(const char* atCode) //Is this AT code handled @@ -120,29 +148,39 @@ { if( strcmp("+CUSD", atCode) != 0 ) { + WARN("Wrong AT Code"); return; //Not supported } - char* pStart = (char*) strchr(evt,'\"'); + processResult(evt); +} + +void USSDInterface::processResult(const char* data) +{ + char* pStart = (char*) strchr(data,'\"'); if(pStart==NULL) { + WARN("Could not find opening quote"); return; //Invalid/incomplete response } pStart++; //Point to first char of response char* pEnd = (char*) strchr(pStart,'\"'); if(pEnd==NULL) { + WARN("Could not find closing quote"); return; //Invalid/incomplete response } m_responseMtx.lock(); if(m_maxResultLength == 0) //No pending command { + WARN("No pending command"); m_responseMtx.unlock(); return; } size_t cpyLen = MIN( pEnd - pStart, m_maxResultLength - 1 ); memcpy(m_result, pStart, cpyLen); m_result[cpyLen] = '\0'; + DBG("Got USSD response: %s", m_result); m_responseMtx.unlock(); m_responseSphre.release(); //Signal user thread that response is ready }