local fork

Dependencies:   Socket USBHostWANDongle_bleedingedge lwip-sys lwip

Dependents:   Encrypted

Fork of VodafoneUSBModem_bleedingedge by Donatien Garnier

Files at this revision

API Documentation at this revision

Comitter:
donatien
Date:
Thu Aug 30 12:58:10 2012 +0000
Parent:
28:c94ffb45a848
Child:
30:494c1d9d9389
Commit message:
USSD support on K3772Z (3GPP rev < 6)

Changed in this revision

ussd/USSDInterface.cpp Show annotated file Show diff for this revision Revisions of this file
ussd/USSDInterface.h Show annotated file Show diff for this revision Revisions of this file
--- 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
 }
--- a/ussd/USSDInterface.h	Thu Aug 30 10:48:35 2012 +0000
+++ b/ussd/USSDInterface.h	Thu Aug 30 12:58:10 2012 +0000
@@ -29,7 +29,7 @@
 /** Component to send/receive Unstructured Supplementary Service Data (USSD)
  *
  */
-class USSDInterface : protected IATEventsHandler
+class USSDInterface : protected IATCommandsProcessor, IATEventsHandler
 {
 public:
   /** Create USSDInterface instance
@@ -51,13 +51,19 @@
   int send(const char* command, char* result, size_t maxLength);
 
 protected:
-  //IATEventsHandler
+  //IATCommandsProcessor, needed for implementations of 3GGP standard < r06
+  virtual int onNewATResponseLine(ATCommandsInterface* pInst, const char* line);
+  virtual int onNewEntryPrompt(ATCommandsInterface* pInst);
+  
+  //IATEventsHandler, needed for implementations of 3GGP standard >= r06
   virtual bool isATCodeHandled(const char* atCode); //Is this AT code handled
   virtual void onDispatchStart();
   virtual void onDispatchStop();
   virtual void onEvent(const char* atCode, const char* evt);
 
 private:
+  void processResult(const char* data);
+
   ATCommandsInterface* m_pIf;
   Mutex m_responseMtx; //To protect concurrent accesses btw the user's thread and the AT thread
   Semaphore m_responseSphre;