Implementation of the CellularInterface for u-blox C027 and C030 (non-N2xx flavour) modems that uses the IP stack on-board the cellular modem, hence not requiring LWIP (and so less RAM) and allowing any AT command exchanges to be carried out at the same time as data transfers (since the modem remains in AT mode all the time). This library may be used from mbed 5.5 onwards. If you need to use SMS, USSD or access the modem file system at the same time as using the CellularInterface then use ublox-at-cellular-interface-ext instead.

Dependents:   example-ublox-cellular-interface example-ublox-cellular-interface_r410M example-ublox-mbed-client example-ublox-cellular-interface ... more

Revision:
25:aabc50bc418e
Parent:
24:35d5b2a02df8
Parent:
21:2a500a881a5a
Child:
26:4f28a1eaa2aa
--- a/UbloxATCellularInterface.cpp	Fri Apr 19 15:40:46 2019 +0500
+++ b/UbloxATCellularInterface.cpp	Mon May 20 07:56:16 2019 +0000
@@ -34,13 +34,12 @@
 // Event thread for asynchronous received data handling.
 void UbloxATCellularInterface::handle_event(){
     pollfh fhs;
-    int count;
     int at_timeout;
-
     fhs.fh = _fh;
     fhs.events = POLLIN;
 
     while (_run_event_thread) {
+    	int count;
         count = poll(&fhs, 1, 1000);
         if (count > 0 && (fhs.revents & POLLIN)) {
             LOCK();
@@ -137,13 +136,13 @@
     int a;
     int b;
     char buf[32];
-    SockCtrl *socket;
-
     // Note: not calling _at->recv() from here as we're
     // already in an _at->recv()
     // +UUSORD: <socket>,<length>
     if (read_at_to_char(buf, sizeof (buf), '\n') > 0) {
+
         if (sscanf(buf, ": %d,%d", &a, &b) == 2) {
+        	SockCtrl *socket;
             socket = find_socket(a);
             if (socket != NULL) {
                 socket->pending = b;
@@ -163,13 +162,12 @@
     int a;
     int b;
     char buf[32];
-    SockCtrl *socket;
-
     // Note: not calling _at->recv() from here as we're
     // already in an _at->recv()
     // +UUSORF: <socket>,<length>
     if (read_at_to_char(buf, sizeof (buf), '\n') > 0) {
         if (sscanf(buf, ": %d,%d", &a, &b) == 2) {
+        	SockCtrl *socket;
             socket = find_socket(a);
             if (socket != NULL) {
                 socket->pending = b;
@@ -188,13 +186,12 @@
 {
     int a;
     char buf[32];
-    SockCtrl *socket;
-
     // Note: not calling _at->recv() from here as we're
     // already in an _at->recv()
     // +UUSOCL: <socket>
     if (read_at_to_char(buf, sizeof (buf), '\n') > 0) {
         if (sscanf(buf, ": %d", &a) == 1) {
+        	SockCtrl *socket;
             socket = find_socket(a);
             tr_debug("Socket 0x%08x: handle %d closed by remote host",
                      (unsigned int) socket, a);
@@ -208,13 +205,12 @@
 {
     int a;
     char buf[32];
-    SockCtrl *socket;
-
     // Note: not calling _at->recv() from here as we're
     // already in an _at->recv()
     // +UUPSDD: <socket>
     if (read_at_to_char(buf, sizeof (buf), '\n') > 0) {
         if (sscanf(buf, ": %d", &a) == 1) {
+        	SockCtrl *socket;
             socket = find_socket(a);
             tr_debug("Socket 0x%08x: handle %d connection lost",
                      (unsigned int) socket, a);
@@ -296,13 +292,13 @@
 {
     bool success = false;
     int cid = -1;
-    char ip[NSAPI_IP_SIZE];
     SocketAddress address;
     int t;
     int at_timeout = _at_timeout;
 
     //+CGDCONT: <cid>,"IP","<apn name>","<ip adr>",0,0,0,0,0,0
     if (_at->send("AT+CGDCONT?")) {
+    	char ip[NSAPI_IP_SIZE];
         if (_at->recv("+CGDCONT: %d,\"IP\",\"%*[^\"]\",\"%" u_stringify(NSAPI_IP_SIZE) "[^\"]\",%*d,%*d,%*d,%*d,%*d,%*d",
                       &t, ip) &&
             _at->recv("OK")) {
@@ -501,7 +497,6 @@
                                                     nsapi_protocol_t proto)
 {
     nsapi_error_t nsapi_error = NSAPI_ERROR_DEVICE_ERROR;
-    bool success = false;
     int modem_handle;
     SockCtrl *socket;
     LOCK();
@@ -511,6 +506,7 @@
     tr_debug("socket_open(%d)", proto);
 
     if (socket != NULL) {
+    	bool success = false;
         if (proto == NSAPI_UDP) {
             success = _at->send("AT+USOCR=17");
         } else if (proto == NSAPI_TCP) {
@@ -743,7 +739,7 @@
     int read_sz;
     Timer timer;
     SockCtrl *socket = (SockCtrl *) handle;
-    int at_timeout;
+
 
     tr_debug("socket_recv(0x%08x, 0x%08x, %d)",
              (unsigned int) handle, (unsigned int) data, size);
@@ -758,6 +754,7 @@
     timer.start();
 
     while (success && (size > 0)) {
+    	int at_timeout;
         LOCK();
         at_timeout = _at_timeout;
         at_set_timeout(1000);
@@ -854,7 +851,6 @@
     int read_sz;
     Timer timer;
     SockCtrl *socket = (SockCtrl *) handle;
-    int at_timeout;
 
     tr_debug("socket_recvfrom(0x%08x, 0x%08x, %d)",
              (unsigned int) handle, (unsigned int) data, size);
@@ -864,6 +860,7 @@
     timer.start();
 
     while (success && (size > 0)) {
+    	int at_timeout;
         LOCK();
         at_timeout = _at_timeout;
         at_set_timeout(1000);
@@ -1025,7 +1022,9 @@
     _apn = NULL;
     _uname = NULL;
     _pwd = NULL;
-    _connection_status_cb = NULL;
+
+
+
 
     // Initialise sockets storage
     memset(_sockets, 0, sizeof(_sockets));
@@ -1040,6 +1039,8 @@
 
     // Nullify the temporary IP address storage
     _ip = NULL;
+    _connection_status_cb = NULL;
+
 
     // Initialise the base class, which starts the AT parser
     baseClassInit(tx, rx, baud, debug_on);
@@ -1094,12 +1095,13 @@
                                                       nsapi_version_t version)
 {
     nsapi_error_t nsapi_error = NSAPI_ERROR_DEVICE_ERROR;
-    int at_timeout;
-    char ipAddress[NSAPI_IP_SIZE];
+
 
     if (address->set_ip_address(host)) {
         nsapi_error = NSAPI_ERROR_OK;
     } else {
+    	int at_timeout;
+    	char ipAddress[NSAPI_IP_SIZE];
         LOCK();
         // This interrogation can sometimes take longer than the usual 8 seconds
         at_timeout = _at_timeout;