Improved registration phase in state machine.

pull/6496/head
Teppo Järvelin 2018-03-26 14:16:29 +03:00
parent 6072407ec9
commit af2890da03
2 changed files with 21 additions and 15 deletions

View File

@ -42,7 +42,7 @@ namespace mbed
CellularConnectionFSM::CellularConnectionFSM() : CellularConnectionFSM::CellularConnectionFSM() :
_serial(0), _state(STATE_INIT), _next_state(_state), _status_callback(0), _event_status_cb(0), _network(0), _power(0), _sim(0), _serial(0), _state(STATE_INIT), _next_state(_state), _status_callback(0), _event_status_cb(0), _network(0), _power(0), _sim(0),
_queue(8 * EVENTS_EVENT_SIZE), _queue_thread(0), _cellularDevice(0), _retry_count(0), _event_timeout(-1), _queue(8 * EVENTS_EVENT_SIZE), _queue_thread(0), _cellularDevice(0), _retry_count(0), _event_timeout(-1),
_at_queue(8 * EVENTS_EVENT_SIZE), _eventID(0) _at_queue(8 * EVENTS_EVENT_SIZE), _eventID(0), _auto_registration(false)
{ {
memset(_sim_pin, 0, sizeof(_sim_pin)); memset(_sim_pin, 0, sizeof(_sim_pin));
#if MBED_CONF_CELLULAR_RANDOM_MAX_START_DELAY == 0 #if MBED_CONF_CELLULAR_RANDOM_MAX_START_DELAY == 0
@ -290,18 +290,22 @@ const char* CellularConnectionFSM::get_state_string(CellularState state)
return strings[state]; return strings[state];
} }
bool CellularConnectionFSM::is_automatic_registering() nsapi_error_t CellularConnectionFSM::is_automatic_registering(bool& auto_reg)
{ {
if (_auto_registration == CellularNetwork::NWModeAutomatic) {
auto_reg = _auto_registration;
return NSAPI_ERROR_OK;
}
CellularNetwork::NWRegisteringMode mode; CellularNetwork::NWRegisteringMode mode;
nsapi_error_t err = _network->get_network_registering_mode(mode); nsapi_error_t err = _network->get_network_registering_mode(mode);
tr_debug("automatic registering mode: %d", mode); if (err == NSAPI_ERROR_OK) {
if (err == NSAPI_ERROR_OK && mode == CellularNetwork::NWModeAutomatic) { tr_info("automatic registering mode: %d", mode);
return true; _auto_registration = (mode == CellularNetwork::NWModeAutomatic);
auto_reg = _auto_registration;
} }
return false; return err;
} }
nsapi_error_t CellularConnectionFSM::continue_from_state(CellularState state) nsapi_error_t CellularConnectionFSM::continue_from_state(CellularState state)
{ {
tr_info("Continue state from %s to %s", get_state_string((CellularConnectionFSM::CellularState)_state), tr_info("Continue state from %s to %s", get_state_string((CellularConnectionFSM::CellularState)_state),
@ -427,7 +431,9 @@ void CellularConnectionFSM::state_registering()
// we are already registered, go to attach // we are already registered, go to attach
enter_to_state(STATE_ATTACHING_NETWORK); enter_to_state(STATE_ATTACHING_NETWORK);
} else { } else {
if (!is_automatic_registering()) { // when we support plmn add this : || plmn bool auto_reg = false;
nsapi_error_t err = is_automatic_registering(auto_reg);
if (err == NSAPI_ERROR_OK && !auto_reg) { // when we support plmn add this : || plmn
// automatic registering is not on, set registration and retry // automatic registering is not on, set registration and retry
_cellularDevice->set_timeout(TIMEOUT_REGISTRATION); _cellularDevice->set_timeout(TIMEOUT_REGISTRATION);
set_network_registration(); set_network_registration();
@ -456,8 +462,7 @@ void CellularConnectionFSM::state_connect_to_network()
{ {
_cellularDevice->set_timeout(TIMEOUT_NETWORK); _cellularDevice->set_timeout(TIMEOUT_NETWORK);
tr_info("Connect to cellular network (timeout %d ms)", TIMEOUT_NETWORK); tr_info("Connect to cellular network (timeout %d ms)", TIMEOUT_NETWORK);
nsapi_error_t err = _network->connect(); if (_network->connect() == NSAPI_ERROR_OK) {
if (err == NSAPI_ERROR_OK) {
// when using modems stack connect is synchronous // when using modems stack connect is synchronous
_next_state = STATE_CONNECTED; _next_state = STATE_CONNECTED;
} else { } else {
@ -582,7 +587,7 @@ void CellularConnectionFSM::ready_urc_cb()
{ {
tr_debug("Device ready URC func called"); tr_debug("Device ready URC func called");
if (_state == STATE_DEVICE_READY && _power->set_at_mode() == NSAPI_ERROR_OK) { if (_state == STATE_DEVICE_READY && _power->set_at_mode() == NSAPI_ERROR_OK) {
tr_info("State was STATE_DEVICE_READY and at mode ready, cancel state and move to next"); tr_debug("State was STATE_DEVICE_READY and at mode ready, cancel state and move to next");
_queue.cancel(_eventID); _queue.cancel(_eventID);
if (device_ready()) { if (device_ready()) {
continue_from_state(STATE_SIM_PIN); continue_from_state(STATE_SIM_PIN);

View File

@ -138,7 +138,6 @@ public:
*/ */
void set_retry_timeout_array(uint16_t timeout[], int array_len); void set_retry_timeout_array(uint16_t timeout[], int array_len);
bool is_automatic_registering();
const char* get_state_string(CellularState state); const char* get_state_string(CellularState state);
private: private:
bool power_on(); bool power_on();
@ -149,6 +148,7 @@ private:
bool set_attach_network(); bool set_attach_network();
bool is_registered(); bool is_registered();
bool device_ready(); bool device_ready();
nsapi_error_t is_automatic_registering(bool& auto_reg);
// state functions to keep state machine simple // state functions to keep state machine simple
void state_init(); void state_init();
@ -196,6 +196,7 @@ private:
events::EventQueue _at_queue; events::EventQueue _at_queue;
char _st_string[20]; char _st_string[20];
int _eventID; int _eventID;
bool _auto_registration;
}; };
} // namespace } // namespace