Skip to content

Cellular: Provide API to restart cellular device #11159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions UNITTESTS/stubs/AT_CellularDevice_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ void AT_CellularDevice::delete_context(CellularContext *context)
{
}

nsapi_error_t AT_CellularDevice::restart()
{
return NSAPI_ERROR_OK;
}

AT_CellularNetwork *AT_CellularDevice::open_network_impl(ATHandler &at)
{
_network = new AT_CellularNetwork(at);
Expand Down
5 changes: 5 additions & 0 deletions UNITTESTS/target_h/myCellularDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ class myCellularDevice : public CellularDevice {
return NSAPI_ERROR_OK;
}

virtual nsapi_error_t restart()
{
return NSAPI_ERROR_OK;
}

virtual nsapi_error_t shutdown()
{
return NSAPI_ERROR_OK;
Expand Down
5 changes: 5 additions & 0 deletions features/cellular/framework/API/CellularDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ class CellularDevice {
*/
virtual void delete_context(CellularContext *context) = 0;

/** Restart the cellular device and its state machine and tries to reconnect.
*
*/
virtual nsapi_error_t restart() = 0;

/** Stop the current operation. Operations: set_device_ready, set_sim_ready, register_to_network, attach_to_network
*
*/
Expand Down
19 changes: 19 additions & 0 deletions features/cellular/framework/AT/AT_CellularDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,25 @@ void AT_CellularDevice::delete_context(CellularContext *context)
release_at_handler(at);
}

nsapi_error_t AT_CellularDevice::restart()
{
tr_debug("Restart cellular device and try to reconnect");

shutdown();
soft_power_off();
hard_power_off();

AT_CellularContext *curr = _context_list;
while (curr) {
nsapi_error_t error = curr->connect();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should check if a context has called connect and re-connection is really required.
In async mode should wait for DISCONNECTED events before calling connect().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AriParkkila How can we know if connect() was called before? Should I use is_connected() before shutting down the device?
Regarding the async mode I thought it will be handled through the connect() itself through the event queue. Can we change the mode temporary to synchronous mode here and then return it back after connecting? is there a better way for both points?

if (error != NSAPI_ERROR_OK) {
return error;
}
curr = (AT_CellularContext *)curr->_next;
}
return NSAPI_ERROR_OK;
}

CellularNetwork *AT_CellularDevice::open_network(FileHandle *fh)
{
if (!_network) {
Expand Down
2 changes: 2 additions & 0 deletions features/cellular/framework/AT/AT_CellularDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class AT_CellularDevice : public CellularDevice {

virtual void delete_context(CellularContext *context);

virtual nsapi_error_t restart();

virtual CellularNetwork *open_network(FileHandle *fh = NULL);

virtual CellularSMS *open_sms(FileHandle *fh = NULL);
Expand Down