Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of C027_Support_New by
Diff: MDM.cpp
- Revision:
- 120:353754a2bcd9
- Parent:
- 118:c2c4b6b421c8
- Child:
- 121:3e1d84b2d34c
--- 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, ¶m)); + waitFinalResp(_cbATA, ¶m); + 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, ¶m); + 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, ¶m, 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; }