Skip to content

Commit d1ff9ed

Browse files
author
Teppo Järvelin
committed
Cellular: added to reset state machine is we get disconnected so application can try again.
1 parent 609b0f7 commit d1ff9ed

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

features/cellular/framework/AT/AT_CellularNetwork.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ AT_CellularNetwork::~AT_CellularNetwork()
7373

7474
for (int type = 0; type < CellularNetwork::C_MAX; type++) {
7575
if (has_registration((RegistrationType)type) != RegistrationModeDisable) {
76-
_at.remove_urc_handler(at_reg[type].urc_prefix, _urc_funcs[type]);
76+
_at.remove_urc_handler(at_reg[type].urc_prefix);
7777
}
7878
}
7979

80-
_at.remove_urc_handler("NO CARRIER", callback(this, &AT_CellularNetwork::urc_no_carrier));
81-
_at.remove_urc_handler("+CGEV:", callback(this, &AT_CellularNetwork::urc_cgev));
80+
_at.remove_urc_handler("NO CARRIER");
81+
_at.remove_urc_handler("+CGEV:");
8282
}
8383

8484
void AT_CellularNetwork::urc_no_carrier()

features/cellular/framework/device/CellularDevice.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ void CellularDevice::cellular_callback(nsapi_event_t ev, intptr_t ptr)
184184
}
185185
} else {
186186
tr_debug("Device: network_callback called with event: %d, ptr: %d", ev, ptr);
187+
if (ev == NSAPI_EVENT_CONNECTION_STATUS_CHANGE && ptr == NSAPI_STATUS_DISCONNECTED) {
188+
// we have been disconnected, reset state machine so that application can start connect sequence again
189+
if (_state_machine) {
190+
_state_machine->reset();
191+
}
192+
}
187193
}
188194

189195
// broadcast network and cellular changes to state machine and CellularContext.

features/cellular/framework/device/CellularStateMachine.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ CellularStateMachine::~CellularStateMachine()
7474
stop();
7575
}
7676

77+
void CellularStateMachine::reset()
78+
{
79+
_state = STATE_INIT;
80+
_event_timeout = -1;
81+
_event_id = -1;
82+
_plmn_network_found = false;
83+
_is_retry = false;
84+
_active_context = false;
85+
enter_to_state(STATE_INIT);
86+
}
87+
7788
void CellularStateMachine::stop()
7889
{
7990
_queue.cancel(_event_id);
@@ -85,15 +96,7 @@ void CellularStateMachine::stop()
8596
_queue_thread = NULL;
8697
}
8798

88-
_state = STATE_INIT;
89-
_next_state = _state;
90-
_target_state = _state;
91-
_cb_data.error = NSAPI_ERROR_OK;
92-
_cb_data.status_data = -1;
93-
_cb_data.final_try = false;
94-
_event_id = -1;
95-
_is_retry = false;
96-
99+
reset();
97100
if (_power) {
98101
_cellularDevice.close_power();
99102
_power = NULL;

features/cellular/framework/device/CellularStateMachine.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ class CellularStateMachine {
135135
*/
136136
void cellular_event_changed(nsapi_event_t ev, intptr_t ptr);
137137

138+
/** Reset the state machine to init state. After reset state machine can be used again to run to wanted state.
139+
*/
140+
void reset();
138141
private:
139142
bool power_on();
140143
bool open_sim();

0 commit comments

Comments
 (0)