Skip to content

Commit f7e95aa

Browse files
author
Veijo Pesonen
committed
Introduces background thread for OOB processing
1 parent b95baad commit f7e95aa

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

ESP8266/ESP8266.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,13 @@ void ESP8266::_process_oob(uint32_t timeout, bool all) {
590590
set_timeout();
591591
}
592592

593+
void ESP8266::bg_process_oob(uint32_t timeout, bool all)
594+
{
595+
_smutex.lock();
596+
_process_oob(timeout, all);
597+
_smutex.unlock();
598+
}
599+
593600
int32_t ESP8266::_recv_tcp_passive(int id, void *data, uint32_t amount, uint32_t timeout)
594601
{
595602
int32_t len;

ESP8266/ESP8266.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,14 @@ class ESP8266
343343
*/
344344
bool cond_enable_tcp_passive_mode();
345345

346+
/**
347+
* For executing OOB processing on background
348+
*
349+
* @param timeout AT parser receive timeout
350+
* @param if TRUE, process all OOBs instead of only one
351+
*/
352+
void bg_process_oob(uint32_t timeout, bool all);
353+
346354
static const int8_t WIFIMODE_STATION = 1;
347355
static const int8_t WIFIMODE_SOFTAP = 2;
348356
static const int8_t WIFIMODE_STATION_SOFTAP = 3;

ESP8266Interface.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
#include <cstring>
18+
#include "Callback.h"
1819
#include "ESP8266.h"
1920
#include "ESP8266Interface.h"
2021
#include "mbed_debug.h"
@@ -123,6 +124,10 @@ int ESP8266Interface::connect()
123124
return status;
124125
}
125126

127+
if (_oob_thread.get_state() == rtos::Thread::Deleted) {
128+
_oob_thread.start(callback(this, &ESP8266Interface::bg_process_oob));
129+
}
130+
126131
if(get_ip_address()) {
127132
return NSAPI_ERROR_IS_CONNECTED;
128133
}
@@ -196,9 +201,6 @@ int ESP8266Interface::set_channel(uint8_t channel)
196201

197202
int ESP8266Interface::disconnect()
198203
{
199-
_started = false;
200-
_initialized = false;
201-
202204
return _esp.disconnect() ? NSAPI_ERROR_OK : NSAPI_ERROR_DEVICE_ERROR;
203205
}
204206

@@ -627,3 +629,11 @@ void ESP8266Interface::update_conn_state_cb()
627629
_conn_stat_cb(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, _conn_stat);
628630
}
629631
}
632+
633+
void ESP8266Interface::bg_process_oob()
634+
{
635+
for(;;) {
636+
_esp.bg_process_oob(ESP8266_RECV_TIMEOUT, true);
637+
wait_ms(ESP8266_RECV_TIMEOUT);
638+
}
639+
}

ESP8266Interface.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "mbed.h"
2121

22+
#include "Thread.h"
2223
#include "Callback.h"
2324
#include "netsocket/nsapi_types.h"
2425
#include "netsocket/NetworkInterface.h"
@@ -361,6 +362,10 @@ class ESP8266Interface : public NetworkStack, public WiFiInterface
361362
// Connection state reporting to application
362363
nsapi_connection_status_t _conn_stat;
363364
Callback<void(nsapi_event_t, intptr_t)> _conn_stat_cb;
365+
366+
// Background OOB processing
367+
rtos::Thread _oob_thread;
368+
void bg_process_oob();
364369
};
365370

366371
#endif

0 commit comments

Comments
 (0)