Own fork of C027_Support
Dependents: MbedSmartRestMain MbedSmartRestMain
Fork of C027_Support by
Revision 23:05a1aeeb5fd9, committed 2014-04-08
- Comitter:
- mazgch
- Date:
- Tue Apr 08 11:11:20 2014 +0000
- Parent:
- 22:29322c22577e
- Child:
- 24:0e287a85ac9e
- Commit message:
- parse phone number and fix rssi
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 Tue Apr 08 09:17:50 2014 +0000 +++ b/MDM.cpp Tue Apr 08 11:11:20 2014 +0000 @@ -2,7 +2,7 @@ #include <ctype.h> #include "MDM.h" -#define TRACE (1)?:printf +#define TRACE (0)?:printf //#define DEBUG #define PROFILE "0" // this is the psd profile used #define MAX_SIZE 256 // max expected messages @@ -32,6 +32,7 @@ _net = NET_UNKNOWN; _ip = 0; _rssi = 0; + *_num = '\0'; for (int socket = 0; socket < sizeof(_sockets)/sizeof(*_sockets); socket++) { _sockets[socket].state = SOCK_FREE; _sockets[socket].pending = 0; @@ -81,11 +82,11 @@ if (type == TYPE_PLUS) { const char* cmd = buf+3; int a, b, c, d; - char s[8]; + char s[32]; // +CSQ: <rssi>,<qual> if (sscanf(cmd, "CSQ: %d,%d",&a,&b) == 2) { - if (a != 99) _rssi = -113 - 2*a; // 0: -113 1: -111 ... 30: -53 dBm with 2 dBm steps + if (a != 99) _rssi = -113 + 2*a; // 0: -113 1: -111 ... 30: -53 dBm with 2 dBm steps //if (b != 99) int qual = b; // // Socket Specific Command --------------------------------- // +UUSORD: <socket>,<length> @@ -145,8 +146,11 @@ // if (a == 0) ; // 0: GSM, // else if (a == 2) ; // 2: UTRAN // +CPIN: <code> - } else if (sscanf(cmd, "CPIN: %8s",s) == 1) { + } else if (sscanf(cmd, "CPIN: %7s",s) == 1) { _sim = (strcmp("READY", s) == 0) ? SIM_READY : SIM_UNKNOWN; + // +CNUM: <code> + } else if (sscanf(cmd, "CNUM: \"My Number\",\"%31[^\"]\",%d", s, &a) == 2) { + if ((a == 129) || (a == 145)) strncpy(_num, s, sizeof(_num)); // +UPSND=<profile_id>,<param_tag>[,<dynamic_param_val>] } else if (sscanf(cmd, "UPSND: " PROFILE ",0,\"" IPSTR "\"", &a,&b,&c,&d) == 4) { _ip = IPADR(a,b,c,d); @@ -313,6 +317,10 @@ sendFormated("AT+CSQ\r\n"); if (OK != waitFinalResp()) return false; + if (*_num) + TRACE("Phone number: \"%s\"\n", _num); + if (_rssi) + TRACE("Signal Strength: %d dBm\n", _rssi); return true; } @@ -392,7 +400,7 @@ } if (!_ip) return false; - printf("Got IP address: " IPSTR "\n", IPNUM(_ip)); + TRACE("Got IP address: " IPSTR "\n", IPNUM(_ip)); return true; }
--- a/MDM.h Tue Apr 08 09:17:50 2014 +0000 +++ b/MDM.h Tue Apr 08 11:11:20 2014 +0000 @@ -60,7 +60,7 @@ bool join(const char* apn, const char* user = NULL, const char* password = NULL); bool disconnect(void); bool gethostbyname(const char* host, IP* ip); - // sockets + // socket interface typedef enum { IPPROTO_TCP, IPPROTO_UDP } IpProtocol; int socketSocket(IpProtocol ipproto); bool socketConnect(int socket, const char * host, int port); @@ -84,8 +84,8 @@ virtual int _send(const void* buf, int len) = 0; private: typedef enum { MODEL_UNKNOWN, MODEL_SARA_G350, MODEL_LISA_U200, MODEL_LISA_C200 } Model; + typedef enum { NET_UNKNOWN, NET_DENIED, NET_NONE, NET_HOME, NET_ROAMING } Net; typedef enum { SIM_UNKNOWN, SIM_PIN, SIM_READY } Sim; - typedef enum { NET_UNKNOWN, NET_DENIED, NET_NONE, NET_HOME, NET_ROAMING } Net; static int _cbATI(int type, const char* buf, int len, Model* model); static int _cbUDNSRN(int type, const char* buf, int len, IP* ip); static int _cbUSOCR(int type, const char* buf, int len, int* socket); @@ -100,6 +100,7 @@ Model _model; Sim _sim; Net _net; + char _num[32]; int _rssi; private: typedef enum { SOCK_FREE, SOCK_CREATED, SOCK_CONNECTED } SockState;