irsan julfikar / C027_Support_New_

Fork of C027_Support_Plus_Dialing by irsan julfikar

Files at this revision

API Documentation at this revision

Comitter:
irsanjul
Date:
Thu Oct 08 04:05:30 2015 +0000
Parent:
119:db878a234544
Child:
121:3e1d84b2d34c
Commit message:
Adding new AT command for Call and for check debug from modem

Changed in this revision

MDM.cpp Show annotated file Show diff for this revision Revisions of this file
MDM.h Show annotated file Show diff for this revision Revisions of this file
--- a/MDM.cpp	Thu Mar 12 17:10:17 2015 +0000
+++ b/MDM.cpp	Thu Oct 08 04:05:30 2015 +0000
@@ -4,6 +4,9 @@
  #include "C027_api.h"
 #endif
 #include "MDMAPN.h"
+#include <sstream>
+
+extern Serial dbg;
                 
 #define PROFILE         "0"   //!< this is the psd profile used
 #define MAX_SIZE        128   //!< max expected messages
@@ -148,7 +151,9 @@
                             (type == TYPE_OK   )  ? GRE "OK " DEF : 
                             (type == TYPE_ERROR)  ? RED "ERR" DEF : 
                             (type == TYPE_PLUS)   ? CYA " + " DEF : 
-                            (type == TYPE_PROMPT) ? BLU " > " DEF : 
+                            (type == TYPE_PROMPT) ? BLU " > " DEF :
+                            (type == TYPE_NOCARRIER)? CYA "NO" DEF :
+                            (type == TYPE_RING) ? CYA "RING" DEF : 
                                                         "..." ;
             ::printf("%10.3f AT read %s", _debugTime.read_ms()*0.001, s);
             dumpAtCmd(buf, len);
@@ -321,9 +326,9 @@
         DigitalOut pin(pn, 1);
         while (i--) {
             // SARA-U2/LISA-U2 50..80us
-            pin = 0; ::wait_us(50);
+            /*pin = 0; ::wait_us(50);
             pin = 1; ::wait_ms(10); 
-            
+            */
             // SARA-G35 >5ms, LISA-C2 > 150ms, LEON-G2 >5ms
             pin = 0; ::wait_ms(150);
             pin = 1; ::wait_ms(100);
@@ -441,7 +446,7 @@
         // get the 
         sendFormated("AT+CGMR\r\n");
         if (RESP_OK != waitFinalResp(_cbString, _dev.ver))
-            goto failure;            
+            goto failure;
         // Returns the ICCID (Integrated Circuit Card ID) of the SIM-card. 
         // ICCID is a serial number identifying the SIM.
         sendFormated("AT+CCID\r\n");
@@ -476,10 +481,31 @@
     sendFormated("AT+CNMI=2,1\r\n");
     if (RESP_OK != waitFinalResp())
         goto failure;
+    // setup audio path mode
+    sendFormated("AT+USPM=0,3,0,0,0\r\n");
+    if (RESP_OK != waitFinalResp())
+        goto failure;
+    // setup loudness speaker
+    sendFormated("ATL2\r\n");
+    if (RESP_OK != waitFinalResp())
+        goto failure;
+    // setup report
+    sendFormated("AT+CMER=1,0,0,2,1\r\n");
+    if (RESP_OK != waitFinalResp())
+        goto failure;
+    // setup call status
+    sendFormated("AT+UCALLSTAT=1\r\n");
+    if (RESP_OK != waitFinalResp())
+        goto failure;
+    // setup calling line identification
+    sendFormated("AT+CLIP=1\r\n");
+    if (RESP_OK != waitFinalResp())
+        goto failure;
     // Request IMSI (International Mobile Subscriber Identification)
     sendFormated("AT+CIMI\r\n");
     if (RESP_OK != waitFinalResp(_cbString, _dev.imsi))
         goto failure;
+    
     if (status)
         memcpy(status, &_dev, sizeof(DevStatus));
     UNLOCK();
@@ -1298,7 +1324,189 @@
     UNLOCK();
     return ok;
 }
-   
+
+//-----------------------------------------------------------------
+bool MDMParser::dialStart(const char* num)
+{
+    bool ok = false;
+    LOCK();
+        //sendFormated("AT\r\n");
+        //wait(0.5);
+        sendFormated("ATD%s;\r\n",num);
+        ok = (RESP_OK == waitFinalResp());
+    UNLOCK();
+    return ok;
+}
+
+bool MDMParser::dialStop()
+{
+    bool ok = false;
+    LOCK();
+        sendFormated("ATH\r\n");
+        ok = (RESP_OK == waitFinalResp());    
+    UNLOCK();
+    return ok;
+}
+
+int MDMParser::_cbRing(int type, const char* buf, int len, char* str)
+{
+    if(type == TYPE_RING)
+    {
+        return RESP_OK;
+    }
+    return WAIT;
+}
+
+bool MDMParser::dialAns()
+{
+    bool ok = false;
+    LOCK();
+    char dbg[64];
+    if(RESP_OK == waitFinalResp(_cbRing, dbg))
+    {
+        sendFormated("ATA\r\n");
+        wait_us(200);
+        ok = (RESP_OK == waitFinalResp());
+        TRACE("ATA YES\\r\n");
+    }
+    UNLOCK();
+    return ok;
+}
+
+int MDMParser::_cbATA(int type, const char* buf, int len, ATAparam* param)
+{
+   if (param) 
+   {
+        if (type == TYPE_PLUS) 
+        {
+            if (sscanf(buf, "\r\n+CLIP: %31[^\"]\",%d,,,,%*d", param->num, param->stat) == 2) {
+                dbg.printf("number %s call you\r\n",param->num);
+            }
+        }
+    }
+    return WAIT;
+}
+
+bool MDMParser::dialStatus(const char* number)
+{
+   bool ok = false;
+   LOCK();
+   ATAparam param;
+   //ok = (RESP_OK == waitFinalResp(_cbATA, &param));
+   waitFinalResp(_cbATA, &param);
+   ok = (number == param.num);
+   UNLOCK();
+   return ok;
+}
+
+// ----------------------------------------------------------------
+int MDMParser::chkSig(MDMParser::NetStatus *status)
+{
+    /*
+    int sigStr;
+    LOCK();
+    sendFormated("AT+CSQ\r\n");
+    CSQparam param;
+    param.sig = &sigStr;
+    waitFinalResp(_cbCSQ, &param);
+    UNLOCK();
+    return sigStr;
+    */
+    int sigStr = 0;
+    LOCK();
+    sendFormated("AT+CSQ\r\n");
+    waitFinalResp(_cbCSQ, &_net);
+    if(status)
+        memcpy(status, &_net, sizeof(NetStatus));
+    sigStr = status->rssi;
+    UNLOCK();
+    return sigStr;
+}
+
+// ----------------------------------------------------------------
+int MDMParser::_cbDBG(int type, const char* buf, int len, DBGparam* param)
+{
+   if(type == TYPE_PLUS)
+   {
+        int a, b;
+        if(sscanf(buf, "\r\n+CLIP: \"%[^\"],%*d",param->num) == 1)
+        {
+            return RESP_OK;
+        }
+        else if(sscanf(buf, "\r\n+UCALLSTAT: %*d,%d",&a) == 1)
+        {
+                /*
+                    get call status format:
+                    +UCALLSTAT: <id>,<status>
+                    <id> : id call;
+                    <status> :  0 = active (saat terhubung)
+                                1 = hold
+                                2 = dialling (melakukan panggilan namun blm terhubung)
+                                3 = alerting (melakukan panggilan dan dalam kedalam menunggu)
+                                4 = ringing (saat ada panggilan)
+                                5 = waiting
+                                6 = disconected (dialling dihentikan)
+                                7 = connected
+                */
+            *param->status = a;
+            return RESP_OK;
+        }
+        else if(sscanf(buf, "\r\n+CIEV: %d,%d", &a, &b) == 2)
+        {
+            if(a == 2)
+            {
+                *param->signal = b;
+                return RESP_OK;
+            }
+            else return WAIT;
+        }
+        else if(sscanf(buf, "\r\n+CMTI: \"%*[^\"]\",%d", &a) == 1)
+        {
+            // a is indeks for sms
+            if(a == 0)
+                return WAIT;
+                
+            *param->indeks = a;
+            return RESP_OK;
+        }
+        else return WAIT;
+    }
+    else return WAIT;
+}
+
+bool MDMParser::readDbg(int* status, char* num, int *signal, int* idx)
+{
+   bool ok = 0;
+   LOCK();
+   DBGparam param;
+   param.status = status;
+   param.num = num;
+   param.signal = signal;
+   param.indeks = idx;
+   ok = (RESP_OK == waitFinalResp(_cbDBG, &param, 1000));
+   UNLOCK();
+   return ok;
+}
+
+bool MDMParser::mute(bool act)
+{
+    if(act)
+    {
+        LOCK();
+        //sendFormated("AT+CALM=1\r\n");
+        sendFormated("AT+CRSL=2\r\n");
+        UNLOCK();
+        return true;
+    }
+    else
+    {
+        LOCK();
+        //sendFormated("AT+CALM=0\r\n");
+        sendFormated("AT+CRSL=5\r\n");
+        UNLOCK();
+        return false;
+    }
+}
 // ----------------------------------------------------------------
   
 int MDMParser::_cbCUSD(int type, const char* buf, int len, char* resp)
@@ -1651,11 +1859,11 @@
 
 MDMSerial::~MDMSerial(void)
 {
-    powerOff();
+    /*powerOff();
 #ifdef TARGET_UBLOX_C027
     if (_onboard)
         c027_mdm_powerOff();
-#endif
+#endif*/
 }
 
 int MDMSerial::_send(const void* buf, int len)   
@@ -1686,11 +1894,11 @@
 
 MDMUsb::~MDMUsb(void)
 {
-    powerOff();
+    /*powerOff();
 #ifdef TARGET_UBLOX_C027
     if (_onboard)
         c027_mdm_powerOff();
-#endif
+#endif*/
 }
 
 int MDMUsb::_send(const void* buf, int len)      { return 0; }
--- a/MDM.h	Thu Mar 12 17:10:17 2015 +0000
+++ b/MDM.h	Thu Oct 08 04:05:30 2015 +0000
@@ -5,6 +5,7 @@
 
 #include "Pipe.h"
 #include "SerialPipe.h"
+#include <sstream>
 
 #ifdef TARGET_UBLOX_C027
  #define MDM_IF(onboard,shield) onboard
@@ -281,6 +282,66 @@
     bool smsSend(const char* num, const char* buf);
     
     // ----------------------------------------------------------------
+    // Dial Service
+    // ----------------------------------------------------------------
+    
+    /** Start Dial Phone Number
+        \param num the phone number of the recipient
+        
+        \return true if successful, false otherwise
+    */
+    bool dialStart(const char* num);
+    
+    /** Stop Dial Phone Number
+        \param num the phone number of the recipient
+        
+        \return true if successful, false otherwise
+    */
+    bool dialStop();
+    
+    /** Answer Dial from Other Phone
+        \don't have param for this query
+        
+        return true if successful, alse otherwise
+    */
+    bool dialAns();
+    
+    /** Check Dial Status if Have Call list
+        \param num the phone number of the dialler must same as init(set number).
+        
+        return true if successful, alse otherwise
+    */
+    bool dialStatus(const char* num);
+    
+    bool dbgSts();
+    
+    // ----------------------------------------------------------------
+    // Signal Service
+    // ----------------------------------------------------------------
+    
+    /** Check signal quality
+        \param signal strenght
+        
+        \return value of signal strenght
+    */
+    int chkSig(MDMParser::NetStatus *status);
+    
+    /** Chek status of debug for set the next action
+        \param status debug
+        \param number of dialing
+        \ param signal quality
+        
+        \return status info, matching number, and signal quality
+    */
+    bool readDbg(int* status, char* num, int *signal, int* idx);
+    //bool readDbg(int* status, char* num, int *signal, int* idx);
+    
+    /** make all uplink and downlink are mute
+        \param value for active or inactive
+    */
+    bool mute(bool mut);
+    
+    // ----------------------------------------------------------------
     // USSD Unstructured Supplementary Service Data
     // ----------------------------------------------------------------
     
@@ -536,6 +597,17 @@
     typedef struct { int* ix; int num; } CMGLparam;
     static int _cbCMGL(int type, const char* buf, int len, CMGLparam* param);
     static int _cbCMGR(int type, const char* buf, int len, CMGRparam* param);
+    // dial
+    typedef struct { char* num; int* stat;} ATAparam;
+    static int _cbATA(int type, const char* buf, int len, ATAparam* param);
+    static int _cbSts(int type, const char* buf, int len, char* str);
+    static int _cbRing(int type, const char* buf, int len, char* str);
+    // signal
+    typedef struct { char* buf; int* sig; int* qual;} CSQparam;
+    static int _cbCSQ(int type, const char* buf, int len, CSQparam* param);
+    // status dbg
+    typedef struct { char* buf; int* signal; int *status; char* num; int* indeks;} DBGparam;
+    static int _cbDBG(int type, const char* buf, int len, DBGparam* param);
     // file
     typedef struct { const char* filename; char* buf; int sz; int len; } URDFILEparam;
     static int _cbUDELFILE(int type, const char* buf, int len, void*);
@@ -552,6 +624,7 @@
     int _findSocket(int handle = SOCKET_ERROR/* = CREATE*/);
     static MDMParser* inst;
     bool _init;
+    const char* num;
 #ifdef TARGET_UBLOX_C027
     bool _onboard;
 #endif