Skip to content

Cellular: Separated context activation in CellularConnectionFSM. #6626

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

Merged
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
23 changes: 21 additions & 2 deletions features/cellular/easy_cellular/CellularConnectionFSM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ void CellularConnectionFSM::stop()
if (_cellularDevice) {
_cellularDevice->close_power();
_cellularDevice->close_network();
_cellularDevice->close_sim();
_power = NULL;
_network = NULL;
_sim = NULL;
}
if (_queue_thread) {
_queue_thread->terminate();
Expand Down Expand Up @@ -289,7 +293,7 @@ void CellularConnectionFSM::report_failure(const char* msg)

const char* CellularConnectionFSM::get_state_string(CellularState state)
{
static const char *strings[] = { "Init", "Power", "Device ready", "SIM pin", "Registering network", "Attaching network", "Connecting network", "Connected"};
static const char *strings[] = { "Init", "Power", "Device ready", "SIM pin", "Registering network", "Attaching network", "Activating PDP Context", "Connecting network", "Connected"};
return strings[state];
}

Expand Down Expand Up @@ -446,7 +450,7 @@ void CellularConnectionFSM::state_attaching()
CellularNetwork::AttachStatus attach_status;
if (get_attach_network(attach_status)) {
if (attach_status == CellularNetwork::Attached) {
enter_to_state(STATE_CONNECTING_NETWORK);
enter_to_state(STATE_ACTIVATING_PDP_CONTEXT);
} else {
set_attach_network();
retry_state_or_fail();
Expand All @@ -456,6 +460,18 @@ void CellularConnectionFSM::state_attaching()
}
}

void CellularConnectionFSM::state_activating_pdp_context()
{
_cellularDevice->set_timeout(TIMEOUT_CONNECT);
tr_info("Activate PDP Context (timeout %d ms)", TIMEOUT_CONNECT);
if (_network->activate_context() == NSAPI_ERROR_OK) {
// when using modems stack connect is synchronous
_next_state = STATE_CONNECTING_NETWORK;
} else {
retry_state_or_fail();
}
}

void CellularConnectionFSM::state_connect_to_network()
{
_cellularDevice->set_timeout(TIMEOUT_CONNECT);
Expand Down Expand Up @@ -501,6 +517,9 @@ void CellularConnectionFSM::event()
case STATE_ATTACHING_NETWORK:
state_attaching();
break;
case STATE_ACTIVATING_PDP_CONTEXT:
state_activating_pdp_context();
break;
case STATE_CONNECTING_NETWORK:
state_connect_to_network();
break;
Expand Down
6 changes: 4 additions & 2 deletions features/cellular/easy_cellular/CellularConnectionFSM.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class CellularConnectionFSM
STATE_SIM_PIN,
STATE_REGISTERING_NETWORK,
STATE_ATTACHING_NETWORK,
STATE_ACTIVATING_PDP_CONTEXT,
STATE_CONNECTING_NETWORK,
STATE_CONNECTED
};
Expand Down Expand Up @@ -120,10 +121,10 @@ class CellularConnectionFSM
CellularSIM* get_sim();

/** Change cellular connection to the target state
* @param state to continue
* @param state to continue. Default is to connect.
* @return see nsapi_error_t, 0 on success
*/
nsapi_error_t continue_to_state(CellularState state);
nsapi_error_t continue_to_state(CellularState state = STATE_CONNECTED);

/** Set cellular device SIM PIN code
* @param sim_pin PIN code
Expand Down Expand Up @@ -157,6 +158,7 @@ class CellularConnectionFSM
void state_sim_pin();
void state_registering();
void state_attaching();
void state_activating_pdp_context();
void state_connect_to_network();
void state_connected();
void enter_to_state(CellularState state);
Expand Down
2 changes: 2 additions & 0 deletions features/cellular/framework/AT/AT_CellularNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ nsapi_error_t AT_CellularNetwork::activate_context()
// If new PDP context was created and failed to activate, delete it
if (err != NSAPI_ERROR_OK && _new_context_set) {
delete_current_context();
} else if (err == NSAPI_ERROR_OK) {
_is_context_active = true;
}

_at.unlock();
Expand Down