mirror of https://github.com/ARMmbed/mbed-os.git
Cellular: fix state machine to check network attach
Added check to state machine that if modem is attached to a network it is considered to be registered to a network and state machine can continue to next states. This fixed issues seen in IoT network that network does not allow registering if already attached.pull/9370/head
parent
baab309f8b
commit
fcc9bb7d4d
|
@ -40,6 +40,8 @@
|
||||||
#define RETRY_COUNT_DEFAULT 3
|
#define RETRY_COUNT_DEFAULT 3
|
||||||
|
|
||||||
const int STM_STOPPED = -99;
|
const int STM_STOPPED = -99;
|
||||||
|
const int ACTIVE_PDP_CONTEXT = 0x01;
|
||||||
|
const int ATTACHED_TO_NETWORK = 0x02;
|
||||||
|
|
||||||
namespace mbed {
|
namespace mbed {
|
||||||
|
|
||||||
|
@ -48,7 +50,7 @@ CellularStateMachine::CellularStateMachine(CellularDevice &device, events::Event
|
||||||
_event_status_cb(0), _network(0), _power(0), _sim(0), _queue(queue), _queue_thread(0), _sim_pin(0),
|
_event_status_cb(0), _network(0), _power(0), _sim(0), _queue(queue), _queue_thread(0), _sim_pin(0),
|
||||||
_retry_count(0), _event_timeout(-1), _event_id(-1), _plmn(0), _command_success(false),
|
_retry_count(0), _event_timeout(-1), _event_id(-1), _plmn(0), _command_success(false),
|
||||||
_plmn_network_found(false), _is_retry(false), _cb_data(), _current_event(NSAPI_EVENT_CONNECTION_STATUS_CHANGE),
|
_plmn_network_found(false), _is_retry(false), _cb_data(), _current_event(NSAPI_EVENT_CONNECTION_STATUS_CHANGE),
|
||||||
_active_context(false)
|
_network_status(0)
|
||||||
{
|
{
|
||||||
#if MBED_CONF_CELLULAR_RANDOM_MAX_START_DELAY == 0
|
#if MBED_CONF_CELLULAR_RANDOM_MAX_START_DELAY == 0
|
||||||
_start_time = 0;
|
_start_time = 0;
|
||||||
|
@ -83,7 +85,7 @@ void CellularStateMachine::reset()
|
||||||
_event_id = -1;
|
_event_id = -1;
|
||||||
_plmn_network_found = false;
|
_plmn_network_found = false;
|
||||||
_is_retry = false;
|
_is_retry = false;
|
||||||
_active_context = false;
|
_network_status = 0;
|
||||||
enter_to_state(STATE_INIT);
|
enter_to_state(STATE_INIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,7 +195,7 @@ bool CellularStateMachine::is_registered()
|
||||||
}
|
}
|
||||||
|
|
||||||
_cb_data.status_data = status;
|
_cb_data.status_data = status;
|
||||||
return is_registered || _active_context;
|
return is_registered || _network_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CellularStateMachine::get_network_registration(CellularNetwork::RegistrationType type,
|
bool CellularStateMachine::get_network_registration(CellularNetwork::RegistrationType type,
|
||||||
|
@ -440,8 +442,15 @@ void CellularStateMachine::state_sim_pin()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_active_context = false;
|
if (_network->is_active_context()) { // check if context was already activated
|
||||||
_active_context = _network->is_active_context(); // check if context was already activated
|
tr_debug("ACTIVE CONTEXT FOUND, skip registering.");
|
||||||
|
_network_status |= ACTIVE_PDP_CONTEXT;
|
||||||
|
}
|
||||||
|
CellularNetwork::AttachStatus status; // check if modem is already attached to a network
|
||||||
|
if (_network->get_attach(status) == NSAPI_ERROR_OK && status == CellularNetwork::Attached) {
|
||||||
|
_network_status |= ATTACHED_TO_NETWORK;
|
||||||
|
tr_debug("DEVICE IS ALREADY ATTACHED TO NETWORK, skip registering and attach.");
|
||||||
|
}
|
||||||
if (_plmn) {
|
if (_plmn) {
|
||||||
enter_to_state(STATE_MANUAL_REGISTERING_NETWORK);
|
enter_to_state(STATE_MANUAL_REGISTERING_NETWORK);
|
||||||
} else {
|
} else {
|
||||||
|
@ -499,7 +508,9 @@ void CellularStateMachine::state_attaching()
|
||||||
{
|
{
|
||||||
_cellularDevice.set_timeout(TIMEOUT_CONNECT);
|
_cellularDevice.set_timeout(TIMEOUT_CONNECT);
|
||||||
tr_info("Attaching network (timeout %d s)", TIMEOUT_CONNECT / 1000);
|
tr_info("Attaching network (timeout %d s)", TIMEOUT_CONNECT / 1000);
|
||||||
_cb_data.error = _network->set_attach();
|
if (_network_status != ATTACHED_TO_NETWORK) {
|
||||||
|
_cb_data.error = _network->set_attach();
|
||||||
|
}
|
||||||
if (_cb_data.error == NSAPI_ERROR_OK) {
|
if (_cb_data.error == NSAPI_ERROR_OK) {
|
||||||
_cellularDevice.close_sim();
|
_cellularDevice.close_sim();
|
||||||
_sim = NULL;
|
_sim = NULL;
|
||||||
|
|
|
@ -185,7 +185,7 @@ private:
|
||||||
bool _is_retry;
|
bool _is_retry;
|
||||||
cell_callback_data_t _cb_data;
|
cell_callback_data_t _cb_data;
|
||||||
nsapi_event_t _current_event;
|
nsapi_event_t _current_event;
|
||||||
bool _active_context; // Is there any active context?
|
int _network_status; // Is there any active context or is modem attached to a network?
|
||||||
PlatformMutex _mutex;
|
PlatformMutex _mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue