Skip to content

Commit 94ecc45

Browse files
author
Teppo Järvelin
committed
Cellular: Separated context activation in CellularConnectionSFM.
1 parent a463b07 commit 94ecc45

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

features/cellular/easy_cellular/CellularConnectionFSM.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ void CellularConnectionFSM::stop()
7979
if (_cellularDevice) {
8080
_cellularDevice->close_power();
8181
_cellularDevice->close_network();
82+
_cellularDevice->close_sim();
83+
_power = NULL;
84+
_network = NULL;
85+
_sim = NULL;
8286
}
8387
if (_queue_thread) {
8488
_queue_thread->terminate();
@@ -289,7 +293,7 @@ void CellularConnectionFSM::report_failure(const char* msg)
289293

290294
const char* CellularConnectionFSM::get_state_string(CellularState state)
291295
{
292-
static const char *strings[] = { "Init", "Power", "Device ready", "SIM pin", "Registering network", "Attaching network", "Connecting network", "Connected"};
296+
static const char *strings[] = { "Init", "Power", "Device ready", "SIM pin", "Registering network", "Attaching network", "Activating PDP Context", "Connecting network", "Connected"};
293297
return strings[state];
294298
}
295299

@@ -446,7 +450,7 @@ void CellularConnectionFSM::state_attaching()
446450
CellularNetwork::AttachStatus attach_status;
447451
if (get_attach_network(attach_status)) {
448452
if (attach_status == CellularNetwork::Attached) {
449-
enter_to_state(STATE_CONNECTING_NETWORK);
453+
enter_to_state(STATE_ACTIVATING_PDP_CONTEXT);
450454
} else {
451455
set_attach_network();
452456
retry_state_or_fail();
@@ -456,6 +460,18 @@ void CellularConnectionFSM::state_attaching()
456460
}
457461
}
458462

463+
void CellularConnectionFSM::state_activating_pdp_context()
464+
{
465+
_cellularDevice->set_timeout(TIMEOUT_CONNECT);
466+
tr_info("Activate PDP Context (timeout %d ms)", TIMEOUT_CONNECT);
467+
if (_network->activate_context() == NSAPI_ERROR_OK) {
468+
// when using modems stack connect is synchronous
469+
_next_state = STATE_CONNECTING_NETWORK;
470+
} else {
471+
retry_state_or_fail();
472+
}
473+
}
474+
459475
void CellularConnectionFSM::state_connect_to_network()
460476
{
461477
_cellularDevice->set_timeout(TIMEOUT_CONNECT);
@@ -501,6 +517,9 @@ void CellularConnectionFSM::event()
501517
case STATE_ATTACHING_NETWORK:
502518
state_attaching();
503519
break;
520+
case STATE_ACTIVATING_PDP_CONTEXT:
521+
state_activating_pdp_context();
522+
break;
504523
case STATE_CONNECTING_NETWORK:
505524
state_connect_to_network();
506525
break;

features/cellular/easy_cellular/CellularConnectionFSM.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class CellularConnectionFSM
5959
STATE_SIM_PIN,
6060
STATE_REGISTERING_NETWORK,
6161
STATE_ATTACHING_NETWORK,
62+
STATE_ACTIVATING_PDP_CONTEXT,
6263
STATE_CONNECTING_NETWORK,
6364
STATE_CONNECTED
6465
};
@@ -120,10 +121,10 @@ class CellularConnectionFSM
120121
CellularSIM* get_sim();
121122

122123
/** Change cellular connection to the target state
123-
* @param state to continue
124+
* @param state to continue. Default is to connect.
124125
* @return see nsapi_error_t, 0 on success
125126
*/
126-
nsapi_error_t continue_to_state(CellularState state);
127+
nsapi_error_t continue_to_state(CellularState state = STATE_CONNECTED);
127128

128129
/** Set cellular device SIM PIN code
129130
* @param sim_pin PIN code
@@ -157,6 +158,7 @@ class CellularConnectionFSM
157158
void state_sim_pin();
158159
void state_registering();
159160
void state_attaching();
161+
void state_activating_pdp_context();
160162
void state_connect_to_network();
161163
void state_connected();
162164
void enter_to_state(CellularState state);

features/cellular/framework/AT/AT_CellularNetwork.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ nsapi_error_t AT_CellularNetwork::activate_context()
259259
// If new PDP context was created and failed to activate, delete it
260260
if (err != NSAPI_ERROR_OK && _new_context_set) {
261261
delete_current_context();
262+
} else if (err == NSAPI_ERROR_OK) {
263+
_is_context_active = true;
262264
}
263265

264266
_at.unlock();

0 commit comments

Comments
 (0)