@@ -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
546548void 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
@@ -624,15 +626,21 @@ void CellularStateMachine::event()
624626
625627nsapi_error_t CellularStateMachine::start_dispatch ()
626628{
627- MBED_ASSERT (!_queue_thread);
629+ if (!_queue_thread) {
630+ _queue_thread = new rtos::Thread (osPriorityNormal, 2048 , NULL , " stm_queue" );
631+ _event_id = STM_STOPPED;
632+ }
628633
629- _queue_thread = new rtos::Thread (osPriorityNormal, 2048 , NULL , " stm_queue" );
630- if (_queue_thread->start (callback (&_queue, &events::EventQueue::dispatch_forever)) != osOK) {
631- report_failure (" Failed to start thread." );
632- stop ();
633- return NSAPI_ERROR_NO_MEMORY;
634+ if (_event_id == STM_STOPPED) {
635+ if (_queue_thread->start (callback (&_queue, &events::EventQueue::dispatch_forever)) != osOK) {
636+ report_failure (" Failed to start thread." );
637+ stop ();
638+ return NSAPI_ERROR_NO_MEMORY;
639+ }
634640 }
635641
642+ _event_id = -1 ;
643+
636644 return NSAPI_ERROR_OK;
637645}
638646
0 commit comments