2727#endif // #if DEVICE_SERIAL
2828#include " ThisThread.h"
2929
30- #define NETWORK_TIMEOUT 30 * 60 * 1000 // 30 minutes
31- #define DEVICE_TIMEOUT 5 * 60 * 1000 // 5 minutes
30+ #define NETWORK_TIMEOUT 30min
31+ #define DEVICE_TIMEOUT 5min
3232// Timeout to wait for URC indicating ciot optimization support from network
33- #define CP_OPT_NW_REPLY_TIMEOUT 3000 // 3 seconds
33+ #define CP_OPT_NW_REPLY_TIMEOUT 3s
3434
3535#if NSAPI_PPP_AVAILABLE
36- #define AT_SYNC_TIMEOUT 1000 // 1 second timeout
36+ #define AT_SYNC_TIMEOUT 1s
3737#include " nsapi_ppp.h"
3838#endif
3939
4545using namespace mbed_cellular_util ;
4646using namespace mbed ;
4747using namespace rtos ;
48+ using namespace std ::chrono_literals;
4849
4950AT_CellularContext::AT_CellularContext (ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) :
5051 _current_op(OP_INVALID), _dcd_pin(NC), _active_high(false ), _cp_req(cp_req), _is_connected(false ), _at(at)
@@ -118,7 +119,7 @@ nsapi_error_t AT_CellularContext::connect()
118119 } else {
119120 if (_cb_data.error == NSAPI_ERROR_ALREADY) {
120121 // device is already attached, to be async we must use queue to connect and give proper callbacks
121- int id = _device->get_queue ()->call_in ( 0 , this , &AT_CellularContext::do_connect_with_retry);
122+ int id = _device->get_queue ()->call ( this , &AT_CellularContext::do_connect_with_retry);
122123 if (id == 0 ) {
123124 return NSAPI_ERROR_NO_MEMORY;
124125 }
@@ -162,7 +163,8 @@ nsapi_error_t AT_CellularContext::check_operation(nsapi_error_t err, ContextOper
162163 _current_op = op;
163164 if (err == NSAPI_ERROR_IN_PROGRESS || err == NSAPI_ERROR_OK) {
164165 if (_is_blocking) {
165- int sema_acq = _semaphore.try_acquire_for (get_timeout_for_operation (op)); // cellular network searching may take several minutes
166+ auto d = std::chrono::duration<uint32_t , std::milli>(get_timeout_for_operation (op));
167+ int sema_acq = _semaphore.try_acquire_for (d); // cellular network searching may take several minutes
166168 if (!sema_acq) {
167169 tr_warning (" No cellular connection" );
168170 return NSAPI_ERROR_TIMEOUT;
@@ -181,11 +183,11 @@ nsapi_connection_status_t AT_CellularContext::get_connection_status() const
181183
182184uint32_t AT_CellularContext::get_timeout_for_operation (ContextOperation op) const
183185{
184- uint32_t timeout = NETWORK_TIMEOUT; // default timeout is 30 minutes as registration and attach may take time
186+ std::chrono::duration< uint32_t , std::milli> timeout = NETWORK_TIMEOUT; // default timeout is 30 minutes as registration and attach may take time
185187 if (op == OP_SIM_READY || op == OP_DEVICE_READY) {
186188 timeout = DEVICE_TIMEOUT; // use 5 minutes for device ready and sim
187189 }
188- return timeout;
190+ return timeout. count () ;
189191}
190192
191193bool AT_CellularContext::is_connected ()
@@ -716,7 +718,7 @@ nsapi_error_t AT_CellularContext::disconnect()
716718 do_disconnect ();
717719 return _cb_data.error ;
718720 } else {
719- int event_id = _device->get_queue ()->call_in ( 0 , this , &AT_CellularContext::do_disconnect);
721+ int event_id = _device->get_queue ()->call ( this , &AT_CellularContext::do_disconnect);
720722 if (event_id == 0 ) {
721723 return NSAPI_ERROR_NO_MEMORY;
722724 }
@@ -742,7 +744,7 @@ void AT_CellularContext::deactivate_context()
742744void AT_CellularContext::check_and_deactivate_context ()
743745{
744746 // CGACT and CGATT commands might take up to 3 minutes to respond.
745- _at.set_at_timeout (180 * 1000 );
747+ _at.set_at_timeout (3min );
746748 int active_contexts_count = 0 ;
747749 _is_context_active = _nw->is_active_context (&active_contexts_count, _cid);
748750
0 commit comments