forking
Revision 21:621f823a2c2d, committed 2019-05-07
- Comitter:
- SanaMasood
- Date:
- Tue May 07 15:46:31 2019 +0500
- Parent:
- 20:2e8e1c573e18
- Commit message:
- Static warnings removed
Changed in this revision
diff -r 2e8e1c573e18 -r 621f823a2c2d TESTS/unit_tests/default/main.cpp --- a/TESTS/unit_tests/default/main.cpp Tue Feb 12 18:42:43 2019 +0500 +++ b/TESTS/unit_tests/default/main.cpp Tue May 07 15:46:31 2019 +0500 @@ -399,9 +399,6 @@ { char ntp_values[48] = { 0 }; time_t timestamp = 0; - struct tm *localTime; - char timeString[25]; - time_t TIME1970 = 2208988800U; int len; bool comms_done = false; @@ -419,6 +416,8 @@ tr_debug("UDP: %d byte(s) returned by NTP server.", len); if (len >= 43) { + struct tm *localTime; + time_t TIME1970 = 2208988800U; timestamp |= ((int) *(ntp_values + 40)) << 24; timestamp |= ((int) *(ntp_values + 41)) << 16; timestamp |= ((int) *(ntp_values + 42)) << 8; @@ -428,6 +427,7 @@ tr_debug("srand() called"); localTime = localtime(×tamp); if (localTime) { + char timeString[25]; if (strftime(timeString, sizeof(timeString), "%a %b %d %H:%M:%S %Y", localTime) > 0) { printf("NTP timestamp is %s.\n", timeString); }
diff -r 2e8e1c573e18 -r 621f823a2c2d TESTS/unit_tests/dynamic/main.cpp --- a/TESTS/unit_tests/dynamic/main.cpp Tue Feb 12 18:42:43 2019 +0500 +++ b/TESTS/unit_tests/dynamic/main.cpp Tue May 07 15:46:31 2019 +0500 @@ -128,9 +128,6 @@ { char ntp_values[48] = { 0 }; time_t timestamp = 0; - struct tm *localTime; - char timeString[25]; - time_t TIME1970 = 2208988800U; int len; bool comms_done = false; @@ -148,6 +145,8 @@ tr_debug("UDP: %d byte(s) returned by NTP server.", len); if (len >= 43) { + struct tm *localTime; + time_t TIME1970 = 2208988800U; timestamp |= ((int) *(ntp_values + 40)) << 24; timestamp |= ((int) *(ntp_values + 41)) << 16; timestamp |= ((int) *(ntp_values + 42)) << 8; @@ -157,6 +156,7 @@ tr_debug("srand() called"); localTime = localtime(×tamp); if (localTime) { + char timeString[25]; if (strftime(timeString, sizeof(timeString), "%a %b %d %H:%M:%S %Y", localTime) > 0) { printf("NTP timestamp is %s.\n", timeString); }
diff -r 2e8e1c573e18 -r 621f823a2c2d UbloxATCellularInterface.cpp --- a/UbloxATCellularInterface.cpp Tue Feb 12 18:42:43 2019 +0500 +++ b/UbloxATCellularInterface.cpp Tue May 07 15:46:31 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;
diff -r 2e8e1c573e18 -r 621f823a2c2d UbloxATCellularInterface.h --- a/UbloxATCellularInterface.h Tue Feb 12 18:42:43 2019 +0500 +++ b/UbloxATCellularInterface.h Tue May 07 15:46:31 2019 +0500 @@ -75,7 +75,7 @@ PinName rx = MDMRXD, int baud = MBED_CONF_UBLOX_CELL_BAUD_RATE, bool debug_on = false, - osPriority priority = osPriorityNormal); + osPriority priority = osPriorityNormal); /* Destructor. */