Skip to content

Commit af2890d

Browse files
author
Teppo Järvelin
committed
Improved registration phase in state machine.
1 parent 6072407 commit af2890d

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

features/cellular/easy_cellular/CellularConnectionFSM.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ namespace mbed
4040
{
4141

4242
CellularConnectionFSM::CellularConnectionFSM() :
43-
_serial(0), _state(STATE_INIT), _next_state(_state), _status_callback(0), _event_status_cb(0), _network(0), _power(0), _sim(0),
44-
_queue(8 * EVENTS_EVENT_SIZE), _queue_thread(0), _cellularDevice(0), _retry_count(0), _event_timeout(-1),
45-
_at_queue(8 * EVENTS_EVENT_SIZE), _eventID(0)
43+
_serial(0), _state(STATE_INIT), _next_state(_state), _status_callback(0), _event_status_cb(0), _network(0), _power(0), _sim(0),
44+
_queue(8 * EVENTS_EVENT_SIZE), _queue_thread(0), _cellularDevice(0), _retry_count(0), _event_timeout(-1),
45+
_at_queue(8 * EVENTS_EVENT_SIZE), _eventID(0), _auto_registration(false)
4646
{
4747
memset(_sim_pin, 0, sizeof(_sim_pin));
4848
#if MBED_CONF_CELLULAR_RANDOM_MAX_START_DELAY == 0
@@ -164,7 +164,7 @@ bool CellularConnectionFSM::open_sim()
164164
tr_warn("PIN required but No SIM pin provided.");
165165
}
166166
}
167-
break;
167+
break;
168168
case CellularSIM::SimStatePukNeeded:
169169
tr_info("SIM PUK code needed...");
170170
break;
@@ -290,18 +290,22 @@ const char* CellularConnectionFSM::get_state_string(CellularState state)
290290
return strings[state];
291291
}
292292

293-
bool CellularConnectionFSM::is_automatic_registering()
293+
nsapi_error_t CellularConnectionFSM::is_automatic_registering(bool& auto_reg)
294294
{
295+
if (_auto_registration == CellularNetwork::NWModeAutomatic) {
296+
auto_reg = _auto_registration;
297+
return NSAPI_ERROR_OK;
298+
}
295299
CellularNetwork::NWRegisteringMode mode;
296300
nsapi_error_t err = _network->get_network_registering_mode(mode);
297-
tr_debug("automatic registering mode: %d", mode);
298-
if (err == NSAPI_ERROR_OK && mode == CellularNetwork::NWModeAutomatic) {
299-
return true;
301+
if (err == NSAPI_ERROR_OK) {
302+
tr_info("automatic registering mode: %d", mode);
303+
_auto_registration = (mode == CellularNetwork::NWModeAutomatic);
304+
auto_reg = _auto_registration;
300305
}
301-
return false;
306+
return err;
302307
}
303308

304-
305309
nsapi_error_t CellularConnectionFSM::continue_from_state(CellularState state)
306310
{
307311
tr_info("Continue state from %s to %s", get_state_string((CellularConnectionFSM::CellularState)_state),
@@ -427,7 +431,9 @@ void CellularConnectionFSM::state_registering()
427431
// we are already registered, go to attach
428432
enter_to_state(STATE_ATTACHING_NETWORK);
429433
} else {
430-
if (!is_automatic_registering()) { // when we support plmn add this : || plmn
434+
bool auto_reg = false;
435+
nsapi_error_t err = is_automatic_registering(auto_reg);
436+
if (err == NSAPI_ERROR_OK && !auto_reg) { // when we support plmn add this : || plmn
431437
// automatic registering is not on, set registration and retry
432438
_cellularDevice->set_timeout(TIMEOUT_REGISTRATION);
433439
set_network_registration();
@@ -456,8 +462,7 @@ void CellularConnectionFSM::state_connect_to_network()
456462
{
457463
_cellularDevice->set_timeout(TIMEOUT_NETWORK);
458464
tr_info("Connect to cellular network (timeout %d ms)", TIMEOUT_NETWORK);
459-
nsapi_error_t err = _network->connect();
460-
if (err == NSAPI_ERROR_OK) {
465+
if (_network->connect() == NSAPI_ERROR_OK) {
461466
// when using modems stack connect is synchronous
462467
_next_state = STATE_CONNECTED;
463468
} else {
@@ -582,7 +587,7 @@ void CellularConnectionFSM::ready_urc_cb()
582587
{
583588
tr_debug("Device ready URC func called");
584589
if (_state == STATE_DEVICE_READY && _power->set_at_mode() == NSAPI_ERROR_OK) {
585-
tr_info("State was STATE_DEVICE_READY and at mode ready, cancel state and move to next");
590+
tr_debug("State was STATE_DEVICE_READY and at mode ready, cancel state and move to next");
586591
_queue.cancel(_eventID);
587592
if (device_ready()) {
588593
continue_from_state(STATE_SIM_PIN);

features/cellular/easy_cellular/CellularConnectionFSM.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ class CellularConnectionFSM
138138
*/
139139
void set_retry_timeout_array(uint16_t timeout[], int array_len);
140140

141-
bool is_automatic_registering();
142141
const char* get_state_string(CellularState state);
143142
private:
144143
bool power_on();
@@ -149,6 +148,7 @@ class CellularConnectionFSM
149148
bool set_attach_network();
150149
bool is_registered();
151150
bool device_ready();
151+
nsapi_error_t is_automatic_registering(bool& auto_reg);
152152

153153
// state functions to keep state machine simple
154154
void state_init();
@@ -196,6 +196,7 @@ class CellularConnectionFSM
196196
events::EventQueue _at_queue;
197197
char _st_string[20];
198198
int _eventID;
199+
bool _auto_registration;
199200
};
200201

201202
} // namespace

0 commit comments

Comments
 (0)