Skip to content

Commit 2533344

Browse files
author
Ari Parkkila
committed
Cellular: Fix statemachine stop
1 parent 5db6d16 commit 2533344

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

features/cellular/framework/device/CellularDevice.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -118,25 +118,26 @@ nsapi_error_t CellularDevice::attach_to_network()
118118
nsapi_error_t CellularDevice::create_state_machine()
119119
{
120120
nsapi_error_t err = NSAPI_ERROR_OK;
121+
_nw = open_network(_fh);
122+
// Attach to network so we can get update status from the network
123+
_nw->attach(callback(this, &CellularDevice::stm_callback));
121124
if (!_state_machine) {
122-
_nw = open_network(_fh);
123-
// Attach to network so we can get update status from the network
124-
_nw->attach(callback(this, &CellularDevice::stm_callback));
125125
_state_machine = new CellularStateMachine(*this, *get_queue(), *_nw);
126-
_state_machine->set_cellular_callback(callback(this, &CellularDevice::stm_callback));
127-
err = _state_machine->start_dispatch();
128-
if (err) {
129-
tr_error("Start state machine failed.");
130-
delete _state_machine;
131-
_state_machine = NULL;
132-
}
126+
}
127+
_state_machine->set_cellular_callback(callback(this, &CellularDevice::stm_callback));
128+
err = _state_machine->start_dispatch();
129+
if (err) {
130+
tr_error("Start state machine failed.");
131+
delete _state_machine;
132+
_state_machine = NULL;
133+
return err;
134+
}
133135

134-
if (strlen(_plmn)) {
135-
_state_machine->set_plmn(_plmn);
136-
}
137-
if (strlen(_sim_pin)) {
138-
_state_machine->set_sim_pin(_sim_pin);
139-
}
136+
if (strlen(_plmn)) {
137+
_state_machine->set_plmn(_plmn);
138+
}
139+
if (strlen(_sim_pin)) {
140+
_state_machine->set_sim_pin(_sim_pin);
140141
}
141142
return err;
142143
}

features/cellular/framework/device/CellularStateMachine.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ void CellularStateMachine::stop()
103103
{
104104
tr_debug("CellularStateMachine stop");
105105
if (_queue_thread) {
106-
_queue.break_dispatch();
107106
_queue_thread->terminate();
108107
delete _queue_thread;
109108
_queue_thread = NULL;
@@ -366,6 +365,9 @@ void CellularStateMachine::state_device_ready()
366365
_status = 0;
367366
enter_to_state(STATE_SIM_PIN);
368367
}
368+
} else {
369+
_status = 0;
370+
enter_to_state(STATE_INIT);
369371
}
370372
}
371373
if (_cb_data.error != NSAPI_ERROR_OK) {
@@ -546,7 +548,7 @@ bool CellularStateMachine::get_current_status(CellularStateMachine::CellularStat
546548
void CellularStateMachine::event()
547549
{
548550
// Don't send Signal quality when in signal quality state or it can confuse callback functions when running retry logic
549-
if (_state != STATE_SIGNAL_QUALITY) {
551+
if (_state > STATE_SIGNAL_QUALITY) {
550552
_cb_data.error = _network.get_signal_quality(_signal_quality.rssi, &_signal_quality.ber);
551553
_cb_data.data = &_signal_quality;
552554

@@ -633,6 +635,8 @@ nsapi_error_t CellularStateMachine::start_dispatch()
633635
return NSAPI_ERROR_NO_MEMORY;
634636
}
635637

638+
_event_id = -1;
639+
636640
return NSAPI_ERROR_OK;
637641
}
638642

0 commit comments

Comments
 (0)