Skip to content

Commit 573b6ce

Browse files
author
Teppo Järvelin
committed
Cellular: Fixed CellularStateMachine to stop on all target states.
1 parent c1c94c8 commit 573b6ce

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

features/cellular/framework/device/CellularStateMachine.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ void CellularStateMachine::event()
633633
break;
634634
}
635635

636-
if ((_target_state == _state && _cb_data.error == NSAPI_ERROR_OK && !_is_retry) || _event_id == STM_STOPPED) {
636+
if (check_is_target_reached()) {
637637
_event_id = -1;
638638
return;
639639
}
@@ -676,6 +676,18 @@ void CellularStateMachine::set_cellular_callback(mbed::Callback<void(nsapi_event
676676
_event_status_cb = status_cb;
677677
}
678678

679+
bool CellularStateMachine::check_is_target_reached()
680+
{
681+
tr_debug("check_is_target_reached(): target state %s, _state: %s, _cb_data.error: %d, _event_id: %d,_is_retry: %d", get_state_string(_target_state), get_state_string(_state), _cb_data.error, _event_id, _is_retry);
682+
683+
if ((_target_state == _state && _cb_data.error == NSAPI_ERROR_OK && !_is_retry) || _event_id == STM_STOPPED) {
684+
tr_debug("Target state reached: %s, _cb_data.error: %d, _event_id: %d", get_state_string(_target_state), _cb_data.error, _event_id);
685+
_event_id = -1;
686+
return true;
687+
}
688+
return false;
689+
}
690+
679691
void CellularStateMachine::cellular_event_changed(nsapi_event_t ev, intptr_t ptr)
680692
{
681693
cell_callback_data_t *data = (cell_callback_data_t *)ptr;
@@ -688,12 +700,20 @@ void CellularStateMachine::cellular_event_changed(nsapi_event_t ev, intptr_t ptr
688700
if (!_plmn_network_found) {
689701
_plmn_network_found = true;
690702
_queue.cancel(_event_id);
691-
continue_from_state(STATE_ATTACHING_NETWORK);
703+
_is_retry = false;
704+
_event_id = -1;
705+
if (!check_is_target_reached()) {
706+
continue_from_state(STATE_ATTACHING_NETWORK);
707+
}
692708
}
693709
}
694710
} else {
695711
_queue.cancel(_event_id);
696-
continue_from_state(STATE_ATTACHING_NETWORK);
712+
_is_retry = false;
713+
_event_id = -1;
714+
if (!check_is_target_reached()) {
715+
continue_from_state(STATE_ATTACHING_NETWORK);
716+
}
697717
}
698718
}
699719
}
@@ -705,8 +725,12 @@ void CellularStateMachine::ready_urc_cb()
705725
if (_state == STATE_DEVICE_READY && _power->set_at_mode() == NSAPI_ERROR_OK) {
706726
tr_debug("State was STATE_DEVICE_READY and at mode ready, cancel state and move to next");
707727
_queue.cancel(_event_id);
728+
_event_id = -1;
708729
if (device_ready()) {
709-
continue_from_state(STATE_SIM_PIN);
730+
_is_retry = false;
731+
if (!check_is_target_reached()) {
732+
continue_from_state(STATE_SIM_PIN);
733+
}
710734
} else {
711735
continue_from_state(STATE_DEVICE_READY);
712736
}

features/cellular/framework/device/CellularStateMachine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ class CellularStateMachine {
157157
void event();
158158
void ready_urc_cb();
159159
void pre_event(CellularState state);
160+
bool check_is_target_reached();
160161

161162
CellularDevice &_cellularDevice;
162163
CellularState _state;

0 commit comments

Comments
 (0)