support library for C027 helper functions for Buffer Pipes, Buffered Serial Port (rtos capable) and GPS parsing. It includes modem APIs for USSD, SMS and Sockets.

Dependents:   HTTPClient_Cellular_HelloWorld Cellular_HelloMQTT MbedSmartRestMain Car_Bon_car_module ... more

This library is intended to be used with u-blox products such as the C027 or a shield with u-blox cellular and GPS modules like the cellular and positioning shield from Embedded Artist.

For 2G/GSM and 3G/UMTS you need to:

  • have a SIM card and know its PIN number
  • need to know you network operators APN setting These setting should be passed to the connect or init and join functions. You can also extend the APN database in MDMAPN.h.

For CDMA products you need to make sure that you have provisioned and activated the modem with either Sprint or Verizon.

Files at this revision

API Documentation at this revision

Comitter:
mazgch
Date:
Tue May 13 15:56:28 2014 +0000
Parent:
65:dd94f920a762
Child:
67:ff9472d344d4
Commit message:
use a named constant for blocking timeout

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
Socket/Socket.h Show annotated file Show diff for this revision Revisions of this file
--- a/MDM.cpp	Tue May 13 14:41:03 2014 +0000
+++ b/MDM.cpp	Tue May 13 15:56:28 2014 +0000
@@ -189,7 +189,8 @@
         // relax a bit
         WAIT_MS(10); 
     }
-    while (timer.read_ms() < timeout_ms);
+    while ((timeout_ms == TIMEOUT_BLOCKING) || 
+           (timer.read_ms() < timeout_ms));
     timer.stop();
     timer.reset();
     return WAIT;
@@ -706,7 +707,7 @@
     // successfull
     _sockets[socket].state = SOCK_CREATED;
     _sockets[socket].pending = 0;
-    _sockets[socket].timeout_ms = 0; // non blocking
+    _sockets[socket].timeout_ms = TIMEOUT_BLOCKING;
     return socket;
 }
 
@@ -735,7 +736,7 @@
     return _sockets[socket].state == SOCK_CONNECTED;
 }
 
-bool MDMParser::socketSetBlocking(int socket, unsigned int timeout_ms)
+bool MDMParser::socketSetBlocking(int socket, int timeout_ms)
 {
     TRACE("socketSetBlocking(%d,%d)\r\n", socket, timeout_ms);
     if (!ISSOCKET(socket))
@@ -844,7 +845,7 @@
             buf += blk;
             _sockets[socket].pending -= blk;
         } else if ((_sockets[socket].state == SOCK_CONNECTED) && (
-                   (_sockets[socket].timeout_ms == (unsigned int)-1 /* blocking */) || 
+                   (_sockets[socket].timeout_ms == TIMEOUT_BLOCKING) || 
                    (timer.read_ms() < _sockets[socket].timeout_ms))){
             // allow to receive unsolicited commands 
             waitFinalResp(NULL, NULL, 10);
@@ -900,7 +901,7 @@
             cnt += blk;
             buf += blk;
             _sockets[socket].pending -= blk;
-        } else if ((_sockets[socket].timeout_ms == (unsigned int)-1 /* blocking */) || 
+        } else if ((_sockets[socket].timeout_ms == TIMEOUT_BLOCKING) || 
                    (timer.read_ms() < _sockets[socket].timeout_ms)) {
             // allow to receive unsolicited commands 
             waitFinalResp(NULL, NULL, 10);
--- a/MDM.h	Tue May 13 14:41:03 2014 +0000
+++ b/MDM.h	Tue May 13 15:56:28 2014 +0000
@@ -172,7 +172,7 @@
         \param timeout_ms -1 blocking, else non blocking timeout in ms
         \return 0 if successful or SOCKET_ERROR on failure 
     */
-    bool socketSetBlocking(int socket, unsigned int timeout_ms);
+    bool socketSetBlocking(int socket, int timeout_ms);
     
     /** Write socket data 
         \param socket the socket handle
@@ -324,7 +324,10 @@
         TYPE_NOANSWER   = 0x260000,
         TYPE_PROMPT     = 0x300000,
         TYPE_PLUS       = 0x400000,
-        TYPE_TEXT       = 0x500000
+        TYPE_TEXT       = 0x500000,
+        
+        // special timout constant
+        TIMEOUT_BLOCKING = -1
     };
     
     /** Get a line from the physical interface. This function need 
@@ -457,7 +460,7 @@
     IP          _ip;  //!< assigned ip address
     // management struture for sockets
     typedef enum { SOCK_FREE, SOCK_CREATED, SOCK_CONNECTED } SockState;
-    typedef struct { SockState state; int pending; unsigned int timeout_ms; } SockCtrl;
+    typedef struct { SockState state; int pending; int timeout_ms; } SockCtrl;
     // LISA-C has 6 TCP and 6 UDP sockets starting at index 18
     // LISA-U and SARA-G have 7 sockets starting at index 1
     SockCtrl _sockets[32];
--- a/Socket/Socket.h	Tue May 13 14:41:03 2014 +0000
+++ b/Socket/Socket.h	Tue May 13 15:56:28 2014 +0000
@@ -9,12 +9,12 @@
 public:
     Socket() {
         _socket  = -1;
-        _timeout = -1;
+        _timeout = MDMParser::TIMEOUT_BLOCKING;
         _mdm     = NULL;
     }
     
     void set_blocking(bool blocking, unsigned int timeout=1) {
-        _timeout = blocking ? (unsigned int) -1 /* blocking */ : timeout;
+        _timeout = blocking ? MDMParser::TIMEOUT_BLOCKING : timeout;
         if (_socket >= 0) {
             _mdm->socketSetBlocking(_socket, _timeout); 
         }
@@ -27,6 +27,7 @@
             ret = _mdm->socketClose(_socket);
             _mdm->socketFree(_socket);
             _socket = -1;
+            _timeout = MDMParser::TIMEOUT_BLOCKING;
         }
         return ret ? 0 : -1;
     }
@@ -35,7 +36,7 @@
     
 protected:
     int _socket;
-    int _timeout;
+    unsigned int _timeout;
     MDMParser* _mdm;
 };