mirror of https://github.com/ARMmbed/mbed-os.git
Cellular: added to reset state machine is we get disconnected so application can try again.
parent
609b0f71be
commit
d1ff9ed68d
|
@ -73,12 +73,12 @@ AT_CellularNetwork::~AT_CellularNetwork()
|
|||
|
||||
for (int type = 0; type < CellularNetwork::C_MAX; type++) {
|
||||
if (has_registration((RegistrationType)type) != RegistrationModeDisable) {
|
||||
_at.remove_urc_handler(at_reg[type].urc_prefix, _urc_funcs[type]);
|
||||
_at.remove_urc_handler(at_reg[type].urc_prefix);
|
||||
}
|
||||
}
|
||||
|
||||
_at.remove_urc_handler("NO CARRIER", callback(this, &AT_CellularNetwork::urc_no_carrier));
|
||||
_at.remove_urc_handler("+CGEV:", callback(this, &AT_CellularNetwork::urc_cgev));
|
||||
_at.remove_urc_handler("NO CARRIER");
|
||||
_at.remove_urc_handler("+CGEV:");
|
||||
}
|
||||
|
||||
void AT_CellularNetwork::urc_no_carrier()
|
||||
|
|
|
@ -184,6 +184,12 @@ void CellularDevice::cellular_callback(nsapi_event_t ev, intptr_t ptr)
|
|||
}
|
||||
} else {
|
||||
tr_debug("Device: network_callback called with event: %d, ptr: %d", ev, ptr);
|
||||
if (ev == NSAPI_EVENT_CONNECTION_STATUS_CHANGE && ptr == NSAPI_STATUS_DISCONNECTED) {
|
||||
// we have been disconnected, reset state machine so that application can start connect sequence again
|
||||
if (_state_machine) {
|
||||
_state_machine->reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// broadcast network and cellular changes to state machine and CellularContext.
|
||||
|
|
|
@ -74,6 +74,17 @@ CellularStateMachine::~CellularStateMachine()
|
|||
stop();
|
||||
}
|
||||
|
||||
void CellularStateMachine::reset()
|
||||
{
|
||||
_state = STATE_INIT;
|
||||
_event_timeout = -1;
|
||||
_event_id = -1;
|
||||
_plmn_network_found = false;
|
||||
_is_retry = false;
|
||||
_active_context = false;
|
||||
enter_to_state(STATE_INIT);
|
||||
}
|
||||
|
||||
void CellularStateMachine::stop()
|
||||
{
|
||||
_queue.cancel(_event_id);
|
||||
|
@ -85,15 +96,7 @@ void CellularStateMachine::stop()
|
|||
_queue_thread = NULL;
|
||||
}
|
||||
|
||||
_state = STATE_INIT;
|
||||
_next_state = _state;
|
||||
_target_state = _state;
|
||||
_cb_data.error = NSAPI_ERROR_OK;
|
||||
_cb_data.status_data = -1;
|
||||
_cb_data.final_try = false;
|
||||
_event_id = -1;
|
||||
_is_retry = false;
|
||||
|
||||
reset();
|
||||
if (_power) {
|
||||
_cellularDevice.close_power();
|
||||
_power = NULL;
|
||||
|
|
|
@ -135,6 +135,9 @@ private:
|
|||
*/
|
||||
void cellular_event_changed(nsapi_event_t ev, intptr_t ptr);
|
||||
|
||||
/** Reset the state machine to init state. After reset state machine can be used again to run to wanted state.
|
||||
*/
|
||||
void reset();
|
||||
private:
|
||||
bool power_on();
|
||||
bool open_sim();
|
||||
|
|
Loading…
Reference in New Issue