Skip to content

Commit 259f9fd

Browse files
author
Cruz Monrreal
authored
Merge pull request #6570 from jarvte/add_cellular_detach
Cellular: add detach from the network
2 parents 7dabd24 + 0b5fae3 commit 259f9fd

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

features/cellular/framework/API/CellularNetwork.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,11 @@ class CellularNetwork : public NetworkInterface
272272

273273
/** Request attach to network.
274274
*
275+
* @deprecated Parameter timeout will be deprecated. Use mbed-os/features/cellular/framework/API/CellularDevice.h set_timeout instead.
275276
* @param timeout milliseconds to wait for attach response
276277
* @return zero on success
277278
*/
279+
MBED_DEPRECATED_SINCE("mbed-os-5.9", "Parameter timeout will be deprecated. Use mbed-os/features/cellular/framework/API/CellularDevice.h set_timeout instead.")
278280
virtual nsapi_error_t set_attach(int timeout = 10*1000) = 0;
279281

280282
/** Request attach status from network.
@@ -284,6 +286,12 @@ class CellularNetwork : public NetworkInterface
284286
*/
285287
virtual nsapi_error_t get_attach(AttachStatus &status) = 0;
286288

289+
/** Request detach from a network.
290+
*
291+
* @return zero on success
292+
*/
293+
virtual nsapi_error_t detach() = 0;
294+
287295
/** Get APN rate control.
288296
*
289297
* @remark optional params are not updated if not received from network, so use good defaults

features/cellular/framework/AT/AT_CellularNetwork.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ bool AT_CellularNetwork::has_registration(RegistrationType reg_type)
753753
return true;
754754
}
755755

756-
nsapi_error_t AT_CellularNetwork::set_attach(int timeout)
756+
nsapi_error_t AT_CellularNetwork::set_attach(int /*timeout*/)
757757
{
758758
_at.lock();
759759

@@ -790,6 +790,19 @@ nsapi_error_t AT_CellularNetwork::get_attach(AttachStatus &status)
790790
return _at.unlock_return_error();
791791
}
792792

793+
nsapi_error_t AT_CellularNetwork::detach()
794+
{
795+
_at.lock();
796+
797+
tr_debug("Network detach");
798+
_at.cmd_start("AT+CGATT=0");
799+
_at.cmd_stop();
800+
_at.resp_start();
801+
_at.resp_stop();
802+
803+
return _at.unlock_return_error();
804+
}
805+
793806
nsapi_error_t AT_CellularNetwork::get_apn_backoff_timer(int &backoff_timer)
794807
{
795808
// If apn is set

features/cellular/framework/AT/AT_CellularNetwork.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ class AT_CellularNetwork : public CellularNetwork, public AT_CellularBase
7474

7575
virtual nsapi_error_t get_attach(AttachStatus &status);
7676

77+
virtual nsapi_error_t detach();
78+
7779
virtual nsapi_error_t get_rate_control(CellularNetwork::RateControlExceptionReports &reports,
7880
CellularNetwork::RateControlUplinkTimeUnit &time_unit, int &uplink_rate);
7981

0 commit comments

Comments
 (0)