@@ -103,7 +103,6 @@ void CellularStateMachine::stop()
103
103
{
104
104
tr_debug (" CellularStateMachine stop" );
105
105
if (_queue_thread) {
106
- _queue.break_dispatch ();
107
106
_queue_thread->terminate ();
108
107
delete _queue_thread;
109
108
_queue_thread = NULL ;
@@ -366,6 +365,9 @@ void CellularStateMachine::state_device_ready()
366
365
_status = 0 ;
367
366
enter_to_state (STATE_SIM_PIN);
368
367
}
368
+ } else {
369
+ _status = 0 ;
370
+ enter_to_state (STATE_INIT);
369
371
}
370
372
}
371
373
if (_cb_data.error != NSAPI_ERROR_OK) {
@@ -546,7 +548,7 @@ bool CellularStateMachine::get_current_status(CellularStateMachine::CellularStat
546
548
void CellularStateMachine::event ()
547
549
{
548
550
// 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) {
550
552
_cb_data.error = _network.get_signal_quality (_signal_quality.rssi , &_signal_quality.ber );
551
553
_cb_data.data = &_signal_quality;
552
554
@@ -624,15 +626,21 @@ void CellularStateMachine::event()
624
626
625
627
nsapi_error_t CellularStateMachine::start_dispatch ()
626
628
{
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
+ }
628
633
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
+ }
634
640
}
635
641
642
+ _event_id = -1 ;
643
+
636
644
return NSAPI_ERROR_OK;
637
645
}
638
646
0 commit comments