ublox-at-cellular-interface

Revision:
21:2a500a881a5a
Parent:
19:7013521e75e7
Child:
25:aabc50bc418e
--- a/UbloxATCellularInterface.cpp	Tue Feb 12 18:42:43 2019 +0500
+++ b/UbloxATCellularInterface.cpp	Wed May 08 14:54:33 2019 +0500
@@ -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();
@@ -131,13 +130,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;
@@ -157,13 +156,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;
@@ -182,13 +180,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);
@@ -202,13 +199,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);
@@ -290,13 +286,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")) {
@@ -425,7 +421,6 @@
                                                     nsapi_protocol_t proto)
 {
     nsapi_error_t nsapi_error = NSAPI_ERROR_DEVICE_ERROR;
-    bool success = false;
     int modem_handle;
     SockCtrl *socket;
     LOCK();
@@ -435,6 +430,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) {
@@ -667,7 +663,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);
@@ -682,6 +678,7 @@
     timer.start();
 
     while (success && (size > 0)) {
+    	int at_timeout;
         LOCK();
         at_timeout = _at_timeout;
         at_set_timeout(1000);
@@ -778,7 +775,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);
@@ -788,6 +784,7 @@
     timer.start();
 
     while (success && (size > 0)) {
+    	int at_timeout;
         LOCK();
         at_timeout = _at_timeout;
         at_set_timeout(1000);
@@ -949,7 +946,9 @@
     _apn = NULL;
     _uname = NULL;
     _pwd = NULL;
-    _connection_status_cb = NULL;
+
+
+
 
     // Initialise sockets storage
     memset(_sockets, 0, sizeof(_sockets));
@@ -964,6 +963,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);
@@ -1018,12 +1019,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;