mirror of https://github.com/ARMmbed/mbed-os.git
Cellular: Fix statemachine stop
parent
7a5e4ca5da
commit
742bfd3709
|
|
@ -124,13 +124,6 @@ nsapi_error_t CellularDevice::create_state_machine()
|
||||||
_nw->attach(callback(this, &CellularDevice::stm_callback));
|
_nw->attach(callback(this, &CellularDevice::stm_callback));
|
||||||
_state_machine = new CellularStateMachine(*this, *get_queue(), *_nw);
|
_state_machine = new CellularStateMachine(*this, *get_queue(), *_nw);
|
||||||
_state_machine->set_cellular_callback(callback(this, &CellularDevice::stm_callback));
|
_state_machine->set_cellular_callback(callback(this, &CellularDevice::stm_callback));
|
||||||
err = _state_machine->start_dispatch();
|
|
||||||
if (err) {
|
|
||||||
tr_error("Start state machine failed.");
|
|
||||||
delete _state_machine;
|
|
||||||
_state_machine = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strlen(_plmn)) {
|
if (strlen(_plmn)) {
|
||||||
_state_machine->set_plmn(_plmn);
|
_state_machine->set_plmn(_plmn);
|
||||||
}
|
}
|
||||||
|
|
@ -138,6 +131,13 @@ nsapi_error_t CellularDevice::create_state_machine()
|
||||||
_state_machine->set_sim_pin(_sim_pin);
|
_state_machine->set_sim_pin(_sim_pin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
err = _state_machine->start_dispatch();
|
||||||
|
if (err) {
|
||||||
|
tr_error("Start state machine failed.");
|
||||||
|
delete _state_machine;
|
||||||
|
_state_machine = NULL;
|
||||||
|
return err;
|
||||||
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,6 @@ void CellularStateMachine::stop()
|
||||||
{
|
{
|
||||||
tr_debug("CellularStateMachine stop");
|
tr_debug("CellularStateMachine stop");
|
||||||
if (_queue_thread) {
|
if (_queue_thread) {
|
||||||
_queue.break_dispatch();
|
|
||||||
_queue_thread->terminate();
|
_queue_thread->terminate();
|
||||||
delete _queue_thread;
|
delete _queue_thread;
|
||||||
_queue_thread = NULL;
|
_queue_thread = NULL;
|
||||||
|
|
@ -366,6 +365,9 @@ void CellularStateMachine::state_device_ready()
|
||||||
_status = 0;
|
_status = 0;
|
||||||
enter_to_state(STATE_SIM_PIN);
|
enter_to_state(STATE_SIM_PIN);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
_status = 0;
|
||||||
|
enter_to_state(STATE_INIT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_cb_data.error != NSAPI_ERROR_OK) {
|
if (_cb_data.error != NSAPI_ERROR_OK) {
|
||||||
|
|
@ -546,7 +548,7 @@ bool CellularStateMachine::get_current_status(CellularStateMachine::CellularStat
|
||||||
void CellularStateMachine::event()
|
void CellularStateMachine::event()
|
||||||
{
|
{
|
||||||
// Don't send Signal quality when in signal quality state or it can confuse callback functions when running retry logic
|
// Don't send Signal quality when in signal quality state or it can confuse callback functions when running retry logic
|
||||||
if (_state != STATE_SIGNAL_QUALITY) {
|
if (_state > STATE_SIGNAL_QUALITY) {
|
||||||
_cb_data.error = _network.get_signal_quality(_signal_quality.rssi, &_signal_quality.ber);
|
_cb_data.error = _network.get_signal_quality(_signal_quality.rssi, &_signal_quality.ber);
|
||||||
_cb_data.data = &_signal_quality;
|
_cb_data.data = &_signal_quality;
|
||||||
|
|
||||||
|
|
@ -624,14 +626,20 @@ void CellularStateMachine::event()
|
||||||
|
|
||||||
nsapi_error_t CellularStateMachine::start_dispatch()
|
nsapi_error_t CellularStateMachine::start_dispatch()
|
||||||
{
|
{
|
||||||
MBED_ASSERT(!_queue_thread);
|
if (!_queue_thread) {
|
||||||
|
|
||||||
_queue_thread = new rtos::Thread(osPriorityNormal, 2048, NULL, "stm_queue");
|
_queue_thread = new rtos::Thread(osPriorityNormal, 2048, NULL, "stm_queue");
|
||||||
|
_event_id = STM_STOPPED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_event_id == STM_STOPPED) {
|
||||||
if (_queue_thread->start(callback(&_queue, &events::EventQueue::dispatch_forever)) != osOK) {
|
if (_queue_thread->start(callback(&_queue, &events::EventQueue::dispatch_forever)) != osOK) {
|
||||||
report_failure("Failed to start thread.");
|
report_failure("Failed to start thread.");
|
||||||
stop();
|
stop();
|
||||||
return NSAPI_ERROR_NO_MEMORY;
|
return NSAPI_ERROR_NO_MEMORY;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_event_id = -1;
|
||||||
|
|
||||||
return NSAPI_ERROR_OK;
|
return NSAPI_ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue