diff --git a/connectivity/cellular/source/framework/device/CellularContext.cpp b/connectivity/cellular/source/framework/device/CellularContext.cpp index 6773a24dce..6a2801888a 100644 --- a/connectivity/cellular/source/framework/device/CellularContext.cpp +++ b/connectivity/cellular/source/framework/device/CellularContext.cpp @@ -107,7 +107,7 @@ void CellularContext::validate_ip_address() CellularContext::pdp_type_t CellularContext::string_to_pdp_type(const char *pdp_type_str) { pdp_type_t pdp_type = DEFAULT_PDP_TYPE; - int len = strlen(pdp_type_str); + size_t len = strlen(pdp_type_str); if (len == 6 && memcmp(pdp_type_str, "IPV4V6", len) == 0) { pdp_type = IPV4V6_PDP_TYPE; diff --git a/connectivity/cellular/source/framework/device/CellularStateMachine.cpp b/connectivity/cellular/source/framework/device/CellularStateMachine.cpp index 5476411e8c..44d67b729a 100644 --- a/connectivity/cellular/source/framework/device/CellularStateMachine.cpp +++ b/connectivity/cellular/source/framework/device/CellularStateMachine.cpp @@ -307,7 +307,7 @@ void CellularStateMachine::retry_state_or_fail() void CellularStateMachine::state_init() { change_timeout(_state_timeout_power_on); - tr_info("Start connecting (timeout %d ms)", _state_timeout_power_on); + tr_info("Start connecting (timeout %d ms)", _state_timeout_power_on.count()); _cb_data.error = _cellularDevice.is_ready(); _status = _cb_data.error ? 0 : DEVICE_READY; if (_cb_data.error != NSAPI_ERROR_OK) { @@ -324,7 +324,7 @@ void CellularStateMachine::state_init() void CellularStateMachine::state_power_on() { change_timeout(_state_timeout_power_on); - tr_info("Modem power ON (timeout %d ms)", _state_timeout_power_on); + tr_info("Modem power ON (timeout %d ms)", _state_timeout_power_on.count()); if (power_on()) { enter_to_state(STATE_DEVICE_READY); } else { @@ -408,7 +408,7 @@ void CellularStateMachine::state_device_ready() void CellularStateMachine::state_sim_pin() { change_timeout(_state_timeout_sim_pin); - tr_info("Setup SIM (timeout %d ms)", _state_timeout_sim_pin); + tr_info("Setup SIM (timeout %d ms)", _state_timeout_sim_pin.count()); if (open_sim()) { bool success = false; for (int type = 0; type < CellularNetwork::C_MAX; type++) { @@ -473,7 +473,7 @@ void CellularStateMachine::state_registering() // we are already registered, go to attach enter_to_state(STATE_ATTACHING_NETWORK); } else { - tr_info("Network registration (timeout %d ms)", _state_timeout_registration); + tr_info("Network registration (timeout %d ms)", _state_timeout_registration.count()); change_timeout(_state_timeout_registration); if (!_command_success && !_plmn) { // don't call set_registration twice for manual registration _cb_data.error = _network.set_registration(_plmn); @@ -487,7 +487,7 @@ void CellularStateMachine::state_attaching() { if (_status != ATTACHED_TO_NETWORK) { change_timeout(_state_timeout_connect); - tr_info("Attaching network (timeout %d ms)", _state_timeout_connect); + tr_info("Attaching network (timeout %d ms)", _state_timeout_connect.count()); _cb_data.error = _network.set_attach(); } if (_cb_data.error == NSAPI_ERROR_OK) { @@ -635,7 +635,7 @@ void CellularStateMachine::event() tr_debug("%s => %s", get_state_string((CellularStateMachine::CellularState)_state), get_state_string((CellularStateMachine::CellularState)_next_state)); } else { - tr_info("Continue after %d seconds", _event_timeout); + tr_info("Continue after %d seconds", _event_timeout.count()); } _state = _next_state; if (_event_timeout == -1s) { diff --git a/connectivity/drivers/cellular/QUECTEL/BC95/QUECTEL_BC95_CellularStack.cpp b/connectivity/drivers/cellular/QUECTEL/BC95/QUECTEL_BC95_CellularStack.cpp index 5ff3d78587..1c92fe36e8 100644 --- a/connectivity/drivers/cellular/QUECTEL/BC95/QUECTEL_BC95_CellularStack.cpp +++ b/connectivity/drivers/cellular/QUECTEL/BC95/QUECTEL_BC95_CellularStack.cpp @@ -225,8 +225,13 @@ retry_send: // check for network congestion device_err_t err = _at.get_last_device_error(); - if (err.errType == DeviceErrorTypeErrorCME && - (err.errCode == AT_UART_BUFFER_ERROR || err.errCode == AT_BACK_OFF_TIMER) || err.errCode == AT_UPLINK_BUSY) { + if ( + ( + err.errType == DeviceErrorTypeErrorCME + && (err.errCode == AT_UART_BUFFER_ERROR || err.errCode == AT_BACK_OFF_TIMER) + ) + || err.errCode == AT_UPLINK_BUSY + ) { if (socket->proto == NSAPI_UDP) { if (retry < 3) { retry++; diff --git a/connectivity/drivers/cellular/TELIT/ME310/TELIT_ME310_CellularStack.cpp b/connectivity/drivers/cellular/TELIT/ME310/TELIT_ME310_CellularStack.cpp index fa297cc78a..ad06352656 100644 --- a/connectivity/drivers/cellular/TELIT/ME310/TELIT_ME310_CellularStack.cpp +++ b/connectivity/drivers/cellular/TELIT/ME310/TELIT_ME310_CellularStack.cpp @@ -21,9 +21,13 @@ #include "CellularLog.h" #include "netsocket/TLSSocket.h" -static const int sslctxID = 1; using namespace mbed; +using namespace std::chrono_literals; + +constexpr int sslctxID = 1; +constexpr auto socket_timeout = 1s; + TELIT_ME310_CellularStack::TELIT_ME310_CellularStack(ATHandler &atHandler, int cid, nsapi_ip_stack_t stack_type, AT_CellularDevice &device) : AT_CellularStack(atHandler, cid, stack_type, device) @@ -66,7 +70,6 @@ nsapi_error_t TELIT_ME310_CellularStack::socket_connect(nsapi_socket_t handle, c activate_ipeasy_context(_cid); } - int modem_connect_id = -1; int err = NSAPI_ERROR_NO_CONNECTION; int request_connect_id = find_socket_index(socket); @@ -224,9 +227,7 @@ nsapi_error_t TELIT_ME310_CellularStack::deactivate_ipeasy_context(int context_i nsapi_error_t TELIT_ME310_CellularStack::create_socket_impl(CellularSocket *socket) { - int modem_connect_id = -1; int remote_port = 1; - int err = -1; if (!is_ipeasy_context_activated(_cid)) { tr_debug("IPEasy context not active for %d", _cid); @@ -399,7 +400,6 @@ nsapi_size_or_error_t TELIT_ME310_CellularStack::socket_recvfrom_impl(CellularSo } if (socket->proto == NSAPI_UDP) { - int data_left = -1; // UDP has remote_IP and remote_port parameters _at.read_string(ip_address, sizeof(ip_address)); port = _at.read_int(); @@ -408,7 +408,7 @@ nsapi_size_or_error_t TELIT_ME310_CellularStack::socket_recvfrom_impl(CellularSo _at.skip_param(); srecv_size = _at.read_int(); - data_left = _at.read_int(); + _at.read_int(); if (srecv_size > size) { srecv_size = size; } @@ -440,7 +440,7 @@ nsapi_size_or_error_t TELIT_ME310_CellularStack::socket_recvfrom_impl(CellularSo // read() should not fail success = false; } - } else if (timer.read_ms() < ME310_SOCKET_TIMEOUT) { + } else if (timer.elapsed_time() < socket_timeout) { // Wait for URCs _at.process_oob(); } else { @@ -643,4 +643,4 @@ nsapi_error_t TELIT_ME310_CellularStack::setsockopt(nsapi_socket_t handle, int l return ret; } -#endif \ No newline at end of file +#endif diff --git a/connectivity/drivers/cellular/TELIT/ME310/TELIT_ME310_CellularStack.h b/connectivity/drivers/cellular/TELIT/ME310/TELIT_ME310_CellularStack.h index ee5e65689f..b24a6763e9 100644 --- a/connectivity/drivers/cellular/TELIT/ME310/TELIT_ME310_CellularStack.h +++ b/connectivity/drivers/cellular/TELIT/ME310/TELIT_ME310_CellularStack.h @@ -34,7 +34,6 @@ namespace mbed { #define ME310_SOCKET_BIND_FAIL 556 #define ME310_IPEASY_ACTIVATED_CONTEXT 1 #define ME310_IPEASY_DEACTIVATED_CONTEXT 0 -#define ME310_SOCKET_TIMEOUT 1000 #define CTRL_Z "\x1a" #define ESC "\x1b" diff --git a/connectivity/drivers/cellular/UBLOX/AT/UBLOX_AT_CellularStack.cpp b/connectivity/drivers/cellular/UBLOX/AT/UBLOX_AT_CellularStack.cpp index d8cec3f7da..4709afc0a3 100644 --- a/connectivity/drivers/cellular/UBLOX/AT/UBLOX_AT_CellularStack.cpp +++ b/connectivity/drivers/cellular/UBLOX/AT/UBLOX_AT_CellularStack.cpp @@ -169,7 +169,6 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_sendto_impl(CellularSocket MBED_ASSERT(socket->id != -1); int sent_len = 0; - uint8_t ch = 0; if (socket->proto == NSAPI_UDP) { if (size > UBLOX_MAX_PACKET_SIZE) { @@ -372,7 +371,7 @@ UBLOX_AT_CellularStack::CellularSocket *UBLOX_AT_CellularStack::find_socket(int { CellularSocket *socket = NULL; - for (unsigned int x = 0; (socket == NULL) && (x < _device.get_property(AT_CellularDevice::PROPERTY_SOCKET_COUNT)); x++) { + for (ptrdiff_t x = 0; (socket == NULL) && (x < _device.get_property(AT_CellularDevice::PROPERTY_SOCKET_COUNT)); x++) { if (_socket) { if (_socket[x]->id == id) { socket = (_socket[x]); diff --git a/connectivity/libraries/ppp/source/ppp_service.cpp b/connectivity/libraries/ppp/source/ppp_service.cpp index 374bf52e89..efdbd2732b 100644 --- a/connectivity/libraries/ppp/source/ppp_service.cpp +++ b/connectivity/libraries/ppp/source/ppp_service.cpp @@ -60,7 +60,9 @@ extern "C" { // "pppos.h" is missing extern C /* Timeout to wait for PPP connection to be terminated * (LCP Terminate-Request is answered with Terminate-Ack) */ -#define PPP_TERMINATION_TIMEOUT 30000 +using namespace std::chrono_literals; +constexpr auto PPP_TERMINATION_TIMEOUT = 30s; + // If both IPCP and IPCP6 are made, how long to wait for both to complete #define PPP_IPCP_IPCP6_DELAY 5000 @@ -655,4 +657,3 @@ MBED_WEAK PPP &PPP::get_default_instance() */ /* --------------------------------- End Of File ------------------------------ */ - diff --git a/connectivity/libraries/ppp/source/ppp_service_if.cpp b/connectivity/libraries/ppp/source/ppp_service_if.cpp index 72b6d7980a..aa58972852 100644 --- a/connectivity/libraries/ppp/source/ppp_service_if.cpp +++ b/connectivity/libraries/ppp/source/ppp_service_if.cpp @@ -517,7 +517,8 @@ extern "C" { } void *cb_ptr = reinterpret_cast(ppp_service_sys_timeout_id); - int unique_id = ppp_service_ptr->event_queue_get()->call_in(msecs, mbed::callback(ppp_sys_timeout_callback, cb_ptr)); + auto duration = std::chrono::milliseconds(msecs); + int unique_id = ppp_service_ptr->event_queue_get()->call_in(duration, mbed::callback(ppp_sys_timeout_callback, cb_ptr)); if (unique_id == 0) { tr_error("No free memory for timeout equeue"); ppp_service_if_mutex->unlock(); diff --git a/connectivity/nanostack/sal-stack-nanostack/source/Common_Protocols/tcp.c b/connectivity/nanostack/sal-stack-nanostack/source/Common_Protocols/tcp.c index 311a0e96a7..aacd6d894d 100644 --- a/connectivity/nanostack/sal-stack-nanostack/source/Common_Protocols/tcp.c +++ b/connectivity/nanostack/sal-stack-nanostack/source/Common_Protocols/tcp.c @@ -82,7 +82,7 @@ void tcp_test_drop_reset() } #endif -#ifdef FEA_TRACE_SUPPORT +#if defined(FEA_TRACE_SUPPORT) && MBED_CONF_MBED_TRACE_ENABLE && (MBED_TRACE_MAX_LEVEL >= TRACE_LEVEL_DEBUG) static const char *trace_tcp_flags(uint16_t flags) { static char buf[9]; diff --git a/connectivity/netsocket/source/nsapi_dns.cpp b/connectivity/netsocket/source/nsapi_dns.cpp index 04d7de45d9..ccf711c28c 100644 --- a/connectivity/netsocket/source/nsapi_dns.cpp +++ b/connectivity/netsocket/source/nsapi_dns.cpp @@ -489,11 +489,12 @@ static nsapi_size_or_error_t nsapi_dns_query_multiple(NetworkStack *stack, const nsapi_addr *tmp = new (std::nothrow) nsapi_addr_t [MBED_CONF_NSAPI_DNS_ADDRESSES_LIMIT]; int cached = nsapi_dns_cache_find(host, version, tmp); if (cached > 0) { - for (int i = 0; i < MIN(cached, addr_count); i++) { + unsigned int us_cached = cached; + for (unsigned int i = 0; i < MIN(us_cached, addr_count); i++) { addr[i] = tmp[i]; } delete [] tmp; - return MIN(cached, addr_count); + return MIN(us_cached, addr_count); } delete [] tmp; // create a udp socket diff --git a/drivers/source/SFDP.cpp b/drivers/source/SFDP.cpp index 3c461b5cf5..203acd6df1 100644 --- a/drivers/source/SFDP.cpp +++ b/drivers/source/SFDP.cpp @@ -412,7 +412,7 @@ int sfdp_iterate_next_largest_erase_type(uint8_t &bitfield, largest_erase_type = idx; if ((size > (int)(smptbl.erase_type_size_arr[largest_erase_type])) && ((smptbl.region_high_boundary[region] - offset) - > (int)(smptbl.erase_type_size_arr[largest_erase_type]))) { + > (uint64_t)(smptbl.erase_type_size_arr[largest_erase_type]))) { break; } else { bitfield &= ~type_mask;