Merge branch 'master' into release/v3.1.x
This commit is contained in:
commit
9fd1bf362f
5 changed files with 306 additions and 223 deletions
|
|
@ -352,7 +352,7 @@ void BLEAdvertisementData::setCompleteServices(BLEUUID uuid) {
|
||||||
switch (uuid.bitSize()) {
|
switch (uuid.bitSize()) {
|
||||||
case 16:
|
case 16:
|
||||||
{
|
{
|
||||||
// [Len] [0x02] [LL] [HH]
|
// [Len] [0x03] [LL] [HH]
|
||||||
cdata[0] = 3;
|
cdata[0] = 3;
|
||||||
cdata[1] = ESP_BLE_AD_TYPE_16SRV_CMPL; // 0x03
|
cdata[1] = ESP_BLE_AD_TYPE_16SRV_CMPL; // 0x03
|
||||||
addData(String(cdata, 2) + String((char *)&uuid.getNative()->uuid.uuid16, 2));
|
addData(String(cdata, 2) + String((char *)&uuid.getNative()->uuid.uuid16, 2));
|
||||||
|
|
@ -361,7 +361,7 @@ void BLEAdvertisementData::setCompleteServices(BLEUUID uuid) {
|
||||||
|
|
||||||
case 32:
|
case 32:
|
||||||
{
|
{
|
||||||
// [Len] [0x04] [LL] [LL] [HH] [HH]
|
// [Len] [0x05] [LL] [LL] [HH] [HH]
|
||||||
cdata[0] = 5;
|
cdata[0] = 5;
|
||||||
cdata[1] = ESP_BLE_AD_TYPE_32SRV_CMPL; // 0x05
|
cdata[1] = ESP_BLE_AD_TYPE_32SRV_CMPL; // 0x05
|
||||||
addData(String(cdata, 2) + String((char *)&uuid.getNative()->uuid.uuid32, 4));
|
addData(String(cdata, 2) + String((char *)&uuid.getNative()->uuid.uuid32, 4));
|
||||||
|
|
@ -370,7 +370,7 @@ void BLEAdvertisementData::setCompleteServices(BLEUUID uuid) {
|
||||||
|
|
||||||
case 128:
|
case 128:
|
||||||
{
|
{
|
||||||
// [Len] [0x04] [0] [1] ... [15]
|
// [Len] [0x07] [0] [1] ... [15]
|
||||||
cdata[0] = 17;
|
cdata[0] = 17;
|
||||||
cdata[1] = ESP_BLE_AD_TYPE_128SRV_CMPL; // 0x07
|
cdata[1] = ESP_BLE_AD_TYPE_128SRV_CMPL; // 0x07
|
||||||
addData(String(cdata, 2) + String((char *)uuid.getNative()->uuid.uuid128, 16));
|
addData(String(cdata, 2) + String((char *)uuid.getNative()->uuid.uuid128, 16));
|
||||||
|
|
@ -453,7 +453,7 @@ void BLEAdvertisementData::setPartialServices(BLEUUID uuid) {
|
||||||
|
|
||||||
case 128:
|
case 128:
|
||||||
{
|
{
|
||||||
// [Len] [0x04] [0] [1] ... [15]
|
// [Len] [0x06] [0] [1] ... [15]
|
||||||
cdata[0] = 17;
|
cdata[0] = 17;
|
||||||
cdata[1] = ESP_BLE_AD_TYPE_128SRV_PART; // 0x06
|
cdata[1] = ESP_BLE_AD_TYPE_128SRV_PART; // 0x06
|
||||||
addData(String(cdata, 2) + String((char *)&uuid.getNative()->uuid.uuid128, 16));
|
addData(String(cdata, 2) + String((char *)&uuid.getNative()->uuid.uuid128, 16));
|
||||||
|
|
|
||||||
|
|
@ -8,28 +8,6 @@
|
||||||
#include "esp_task.h"
|
#include "esp_task.h"
|
||||||
#include "esp32-hal.h"
|
#include "esp32-hal.h"
|
||||||
|
|
||||||
typedef struct NetworkEventCbList {
|
|
||||||
static network_event_handle_t current_id;
|
|
||||||
network_event_handle_t id;
|
|
||||||
NetworkEventCb cb;
|
|
||||||
NetworkEventFuncCb fcb;
|
|
||||||
NetworkEventSysCb scb;
|
|
||||||
arduino_event_id_t event;
|
|
||||||
|
|
||||||
NetworkEventCbList() : id(current_id++), cb(NULL), fcb(NULL), scb(NULL), event(ARDUINO_EVENT_NONE) {}
|
|
||||||
} NetworkEventCbList_t;
|
|
||||||
network_event_handle_t NetworkEventCbList::current_id = 1;
|
|
||||||
|
|
||||||
// arduino dont like std::vectors move static here
|
|
||||||
static std::vector<NetworkEventCbList_t> cbEventList;
|
|
||||||
|
|
||||||
static void _network_event_task(void *arg) {
|
|
||||||
for (;;) {
|
|
||||||
((NetworkEvents *)arg)->checkForEvent();
|
|
||||||
}
|
|
||||||
vTaskDelete(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
NetworkEvents::NetworkEvents() : _arduino_event_group(NULL), _arduino_event_queue(NULL), _arduino_event_task_handle(NULL) {}
|
NetworkEvents::NetworkEvents() : _arduino_event_group(NULL), _arduino_event_queue(NULL), _arduino_event_task_handle(NULL) {}
|
||||||
|
|
||||||
NetworkEvents::~NetworkEvents() {
|
NetworkEvents::~NetworkEvents() {
|
||||||
|
|
@ -43,8 +21,9 @@ NetworkEvents::~NetworkEvents() {
|
||||||
}
|
}
|
||||||
if (_arduino_event_queue != NULL) {
|
if (_arduino_event_queue != NULL) {
|
||||||
arduino_event_t *event = NULL;
|
arduino_event_t *event = NULL;
|
||||||
|
// consume queue
|
||||||
while (xQueueReceive(_arduino_event_queue, &event, 0) == pdTRUE) {
|
while (xQueueReceive(_arduino_event_queue, &event, 0) == pdTRUE) {
|
||||||
free(event);
|
delete event;
|
||||||
}
|
}
|
||||||
vQueueDelete(_arduino_event_queue);
|
vQueueDelete(_arduino_event_queue);
|
||||||
_arduino_event_queue = NULL;
|
_arduino_event_queue = NULL;
|
||||||
|
|
@ -78,7 +57,14 @@ bool NetworkEvents::initNetworkEvents() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_arduino_event_task_handle) {
|
if (!_arduino_event_task_handle) {
|
||||||
xTaskCreateUniversal(_network_event_task, "arduino_events", 4096, this, ESP_TASKD_EVENT_PRIO - 1, &_arduino_event_task_handle, ARDUINO_EVENT_RUNNING_CORE);
|
xTaskCreateUniversal(
|
||||||
|
[](void *self) {
|
||||||
|
static_cast<NetworkEvents *>(self)->_checkForEvent();
|
||||||
|
},
|
||||||
|
"arduino_events", // label
|
||||||
|
4096, // event task's stack size
|
||||||
|
this, ESP_TASKD_EVENT_PRIO - 1, &_arduino_event_task_handle, ARDUINO_EVENT_RUNNING_CORE
|
||||||
|
);
|
||||||
if (!_arduino_event_task_handle) {
|
if (!_arduino_event_task_handle) {
|
||||||
log_e("Network Event Task Start Failed!");
|
log_e("Network Event Task Start Failed!");
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -88,66 +74,76 @@ bool NetworkEvents::initNetworkEvents() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NetworkEvents::postEvent(arduino_event_t *data) {
|
bool NetworkEvents::postEvent(const arduino_event_t *data) {
|
||||||
if (data == NULL || _arduino_event_queue == NULL) {
|
if (data == NULL || _arduino_event_queue == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
arduino_event_t *event = (arduino_event_t *)malloc(sizeof(arduino_event_t));
|
arduino_event_t *event = new arduino_event_t();
|
||||||
if (event == NULL) {
|
if (event == NULL) {
|
||||||
log_e("Arduino Event Malloc Failed!");
|
log_e("Arduino Event Malloc Failed!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(event, data, sizeof(arduino_event_t));
|
memcpy(event, data, sizeof(arduino_event_t));
|
||||||
if (xQueueSend(_arduino_event_queue, &event, portMAX_DELAY) != pdPASS) {
|
if (xQueueSend(_arduino_event_queue, &event, portMAX_DELAY) != pdPASS) {
|
||||||
log_e("Arduino Event Send Failed!");
|
log_e("Arduino Event Send Failed!");
|
||||||
|
delete event; // release mem on error
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkEvents::checkForEvent() {
|
void NetworkEvents::_checkForEvent() {
|
||||||
arduino_event_t *event = NULL;
|
// this task can't run without the queue
|
||||||
if (_arduino_event_queue == NULL) {
|
if (_arduino_event_queue == NULL) {
|
||||||
|
_arduino_event_task_handle = NULL;
|
||||||
|
vTaskDelete(NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (xQueueReceive(_arduino_event_queue, &event, portMAX_DELAY) != pdTRUE) {
|
|
||||||
return;
|
for (;;) {
|
||||||
}
|
arduino_event_t *event = NULL;
|
||||||
if (event == NULL) {
|
// wait for an event on a queue
|
||||||
return;
|
if (xQueueReceive(_arduino_event_queue, &event, portMAX_DELAY) != pdTRUE) {
|
||||||
}
|
continue;
|
||||||
log_v("Network Event: %d - %s", event->event_id, eventName(event->event_id));
|
}
|
||||||
for (uint32_t i = 0; i < cbEventList.size(); i++) {
|
if (event == NULL) {
|
||||||
NetworkEventCbList_t entry = cbEventList[i];
|
continue;
|
||||||
if (entry.cb || entry.fcb || entry.scb) {
|
}
|
||||||
if (entry.event == (arduino_event_id_t)event->event_id || entry.event == ARDUINO_EVENT_MAX) {
|
log_v("Network Event: %d - %s", event->event_id, eventName(event->event_id));
|
||||||
if (entry.cb) {
|
|
||||||
entry.cb((arduino_event_id_t)event->event_id);
|
#if defined NETWORK_EVENTS_MUTEX && SOC_CPU_CORES_NUM > 1
|
||||||
} else if (entry.fcb) {
|
std::unique_lock<std::mutex> lock(_mtx);
|
||||||
entry.fcb((arduino_event_id_t)event->event_id, (arduino_event_info_t)event->event_info);
|
#endif // defined NETWORK_EVENTS_MUTEX && SOC_CPU_CORES_NUM > 1
|
||||||
} else {
|
|
||||||
entry.scb(event);
|
// iterate over registered callbacks
|
||||||
|
for (auto &i : _cbEventList) {
|
||||||
|
if (i.cb || i.fcb || i.scb) {
|
||||||
|
if (i.event == (arduino_event_id_t)event->event_id || i.event == ARDUINO_EVENT_MAX) {
|
||||||
|
if (i.cb) {
|
||||||
|
i.cb((arduino_event_id_t)event->event_id);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i.fcb) {
|
||||||
|
i.fcb((arduino_event_id_t)event->event_id, (arduino_event_info_t)event->event_info);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
i.scb(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
free(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t NetworkEvents::findEvent(NetworkEventCb cbEvent, arduino_event_id_t event) {
|
#if defined NETWORK_EVENTS_MUTEX && SOC_CPU_CORES_NUM > 1
|
||||||
uint32_t i;
|
lock.unlock();
|
||||||
|
#endif // defined NETWORK_EVENTS_MUTEX && SOC_CPU_CORES_NUM > 1
|
||||||
|
|
||||||
if (!cbEvent) {
|
// release the event object's memory
|
||||||
return cbEventList.size();
|
delete event;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < cbEventList.size(); i++) {
|
vTaskDelete(NULL);
|
||||||
NetworkEventCbList_t entry = cbEventList[i];
|
|
||||||
if (entry.cb == cbEvent && entry.event == event) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename... U> static size_t getStdFunctionAddress(std::function<T(U...)> f) {
|
template<typename T, typename... U> static size_t getStdFunctionAddress(std::function<T(U...)> f) {
|
||||||
|
|
@ -159,55 +155,17 @@ template<typename T, typename... U> static size_t getStdFunctionAddress(std::fun
|
||||||
return (size_t)fnPointer;
|
return (size_t)fnPointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t NetworkEvents::findEvent(NetworkEventFuncCb cbEvent, arduino_event_id_t event) {
|
|
||||||
uint32_t i;
|
|
||||||
|
|
||||||
if (!cbEvent) {
|
|
||||||
return cbEventList.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < cbEventList.size(); i++) {
|
|
||||||
NetworkEventCbList_t entry = cbEventList[i];
|
|
||||||
if (getStdFunctionAddress(entry.fcb) == getStdFunctionAddress(cbEvent) && entry.event == event) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t NetworkEvents::findEvent(NetworkEventSysCb cbEvent, arduino_event_id_t event) {
|
|
||||||
uint32_t i;
|
|
||||||
|
|
||||||
if (!cbEvent) {
|
|
||||||
return cbEventList.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < cbEventList.size(); i++) {
|
|
||||||
NetworkEventCbList_t entry = cbEventList[i];
|
|
||||||
if (entry.scb == cbEvent && entry.event == event) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
network_event_handle_t NetworkEvents::onEvent(NetworkEventCb cbEvent, arduino_event_id_t event) {
|
network_event_handle_t NetworkEvents::onEvent(NetworkEventCb cbEvent, arduino_event_id_t event) {
|
||||||
if (!cbEvent) {
|
if (!cbEvent) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (findEvent(cbEvent, event) < cbEventList.size()) {
|
#if defined NETWORK_EVENTS_MUTEX && SOC_CPU_CORES_NUM > 1
|
||||||
log_w("Attempt to add duplicate event handler!");
|
std::lock_guard<std::mutex> lock(_mtx);
|
||||||
return 0;
|
#endif // defined NETWORK_EVENTS_MUTEX && SOC_CPU_CORES_NUM > 1
|
||||||
}
|
|
||||||
|
|
||||||
NetworkEventCbList_t newEventHandler;
|
_cbEventList.emplace_back(++_current_id, cbEvent, nullptr, nullptr, event);
|
||||||
newEventHandler.cb = cbEvent;
|
return _cbEventList.back().id;
|
||||||
newEventHandler.fcb = NULL;
|
|
||||||
newEventHandler.scb = NULL;
|
|
||||||
newEventHandler.event = event;
|
|
||||||
cbEventList.push_back(newEventHandler);
|
|
||||||
return newEventHandler.id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
network_event_handle_t NetworkEvents::onEvent(NetworkEventFuncCb cbEvent, arduino_event_id_t event) {
|
network_event_handle_t NetworkEvents::onEvent(NetworkEventFuncCb cbEvent, arduino_event_id_t event) {
|
||||||
|
|
@ -215,18 +173,12 @@ network_event_handle_t NetworkEvents::onEvent(NetworkEventFuncCb cbEvent, arduin
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (findEvent(cbEvent, event) < cbEventList.size()) {
|
#if defined NETWORK_EVENTS_MUTEX && SOC_CPU_CORES_NUM > 1
|
||||||
log_w("Attempt to add duplicate event handler!");
|
std::lock_guard<std::mutex> lock(_mtx);
|
||||||
return 0;
|
#endif // defined NETWORK_EVENTS_MUTEX && SOC_CPU_CORES_NUM > 1
|
||||||
}
|
|
||||||
|
|
||||||
NetworkEventCbList_t newEventHandler;
|
_cbEventList.emplace_back(++_current_id, nullptr, cbEvent, nullptr, event);
|
||||||
newEventHandler.cb = NULL;
|
return _cbEventList.back().id;
|
||||||
newEventHandler.fcb = cbEvent;
|
|
||||||
newEventHandler.scb = NULL;
|
|
||||||
newEventHandler.event = event;
|
|
||||||
cbEventList.push_back(newEventHandler);
|
|
||||||
return newEventHandler.id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
network_event_handle_t NetworkEvents::onEvent(NetworkEventSysCb cbEvent, arduino_event_id_t event) {
|
network_event_handle_t NetworkEvents::onEvent(NetworkEventSysCb cbEvent, arduino_event_id_t event) {
|
||||||
|
|
@ -234,18 +186,12 @@ network_event_handle_t NetworkEvents::onEvent(NetworkEventSysCb cbEvent, arduino
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (findEvent(cbEvent, event) < cbEventList.size()) {
|
#if defined NETWORK_EVENTS_MUTEX && SOC_CPU_CORES_NUM > 1
|
||||||
log_w("Attempt to add duplicate event handler!");
|
std::lock_guard<std::mutex> lock(_mtx);
|
||||||
return 0;
|
#endif // defined NETWORK_EVENTS_MUTEX && SOC_CPU_CORES_NUM > 1
|
||||||
}
|
|
||||||
|
|
||||||
NetworkEventCbList_t newEventHandler;
|
_cbEventList.emplace_back(++_current_id, nullptr, nullptr, cbEvent, event);
|
||||||
newEventHandler.cb = NULL;
|
return _cbEventList.back().id;
|
||||||
newEventHandler.fcb = NULL;
|
|
||||||
newEventHandler.scb = cbEvent;
|
|
||||||
newEventHandler.event = event;
|
|
||||||
cbEventList.push_back(newEventHandler);
|
|
||||||
return newEventHandler.id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
network_event_handle_t NetworkEvents::onSysEvent(NetworkEventCb cbEvent, arduino_event_id_t event) {
|
network_event_handle_t NetworkEvents::onSysEvent(NetworkEventCb cbEvent, arduino_event_id_t event) {
|
||||||
|
|
@ -253,18 +199,12 @@ network_event_handle_t NetworkEvents::onSysEvent(NetworkEventCb cbEvent, arduino
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (findEvent(cbEvent, event) < cbEventList.size()) {
|
#if defined NETWORK_EVENTS_MUTEX && SOC_CPU_CORES_NUM > 1
|
||||||
log_w("Attempt to add duplicate event handler!");
|
std::lock_guard<std::mutex> lock(_mtx);
|
||||||
return 0;
|
#endif // defined NETWORK_EVENTS_MUTEX && SOC_CPU_CORES_NUM > 1
|
||||||
}
|
|
||||||
|
|
||||||
NetworkEventCbList_t newEventHandler;
|
_cbEventList.emplace(_cbEventList.begin(), ++_current_id, cbEvent, nullptr, nullptr, event);
|
||||||
newEventHandler.cb = cbEvent;
|
return _cbEventList.front().id;
|
||||||
newEventHandler.fcb = NULL;
|
|
||||||
newEventHandler.scb = NULL;
|
|
||||||
newEventHandler.event = event;
|
|
||||||
cbEventList.insert(cbEventList.begin(), newEventHandler);
|
|
||||||
return newEventHandler.id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
network_event_handle_t NetworkEvents::onSysEvent(NetworkEventFuncCb cbEvent, arduino_event_id_t event) {
|
network_event_handle_t NetworkEvents::onSysEvent(NetworkEventFuncCb cbEvent, arduino_event_id_t event) {
|
||||||
|
|
@ -272,18 +212,12 @@ network_event_handle_t NetworkEvents::onSysEvent(NetworkEventFuncCb cbEvent, ard
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (findEvent(cbEvent, event) < cbEventList.size()) {
|
#if defined NETWORK_EVENTS_MUTEX && SOC_CPU_CORES_NUM > 1
|
||||||
log_w("Attempt to add duplicate event handler!");
|
std::lock_guard<std::mutex> lock(_mtx);
|
||||||
return 0;
|
#endif // defined NETWORK_EVENTS_MUTEX && SOC_CPU_CORES_NUM > 1
|
||||||
}
|
|
||||||
|
|
||||||
NetworkEventCbList_t newEventHandler;
|
_cbEventList.emplace(_cbEventList.begin(), ++_current_id, nullptr, cbEvent, nullptr, event);
|
||||||
newEventHandler.cb = NULL;
|
return _cbEventList.front().id;
|
||||||
newEventHandler.fcb = cbEvent;
|
|
||||||
newEventHandler.scb = NULL;
|
|
||||||
newEventHandler.event = event;
|
|
||||||
cbEventList.insert(cbEventList.begin(), newEventHandler);
|
|
||||||
return newEventHandler.id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
network_event_handle_t NetworkEvents::onSysEvent(NetworkEventSysCb cbEvent, arduino_event_id_t event) {
|
network_event_handle_t NetworkEvents::onSysEvent(NetworkEventSysCb cbEvent, arduino_event_id_t event) {
|
||||||
|
|
@ -291,77 +225,88 @@ network_event_handle_t NetworkEvents::onSysEvent(NetworkEventSysCb cbEvent, ardu
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (findEvent(cbEvent, event) < cbEventList.size()) {
|
#if defined NETWORK_EVENTS_MUTEX && SOC_CPU_CORES_NUM > 1
|
||||||
log_w("Attempt to add duplicate event handler!");
|
std::lock_guard<std::mutex> lock(_mtx);
|
||||||
return 0;
|
#endif // defined NETWORK_EVENTS_MUTEX && SOC_CPU_CORES_NUM > 1
|
||||||
}
|
|
||||||
|
|
||||||
NetworkEventCbList_t newEventHandler;
|
_cbEventList.emplace(_cbEventList.begin(), ++_current_id, nullptr, nullptr, cbEvent, event);
|
||||||
newEventHandler.cb = NULL;
|
return _cbEventList.front().id;
|
||||||
newEventHandler.fcb = NULL;
|
|
||||||
newEventHandler.scb = cbEvent;
|
|
||||||
newEventHandler.event = event;
|
|
||||||
cbEventList.insert(cbEventList.begin(), newEventHandler);
|
|
||||||
return newEventHandler.id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkEvents::removeEvent(NetworkEventCb cbEvent, arduino_event_id_t event) {
|
void NetworkEvents::removeEvent(NetworkEventCb cbEvent, arduino_event_id_t event) {
|
||||||
uint32_t i;
|
|
||||||
|
|
||||||
if (!cbEvent) {
|
if (!cbEvent) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
i = findEvent(cbEvent, event);
|
#if defined NETWORK_EVENTS_MUTEX && SOC_CPU_CORES_NUM > 1
|
||||||
if (i >= cbEventList.size()) {
|
std::lock_guard<std::mutex> lock(_mtx);
|
||||||
log_w("Event handler not found!");
|
#endif // defined NETWORK_EVENTS_MUTEX && SOC_CPU_CORES_NUM > 1
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
cbEventList.erase(cbEventList.begin() + i);
|
_cbEventList.erase(
|
||||||
|
std::remove_if(
|
||||||
|
_cbEventList.begin(), _cbEventList.end(),
|
||||||
|
[cbEvent, event](const NetworkEventCbList_t &e) {
|
||||||
|
return e.cb == cbEvent && e.event == event;
|
||||||
|
}
|
||||||
|
),
|
||||||
|
_cbEventList.end()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkEvents::removeEvent(NetworkEventFuncCb cbEvent, arduino_event_id_t event) {
|
void NetworkEvents::removeEvent(NetworkEventFuncCb cbEvent, arduino_event_id_t event) {
|
||||||
uint32_t i;
|
|
||||||
|
|
||||||
if (!cbEvent) {
|
if (!cbEvent) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
i = findEvent(cbEvent, event);
|
#if defined NETWORK_EVENTS_MUTEX && SOC_CPU_CORES_NUM > 1
|
||||||
if (i >= cbEventList.size()) {
|
std::lock_guard<std::mutex> lock(_mtx);
|
||||||
log_w("Event handler not found!");
|
#endif // defined NETWORK_EVENTS_MUTEX && SOC_CPU_CORES_NUM > 1
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
cbEventList.erase(cbEventList.begin() + i);
|
_cbEventList.erase(
|
||||||
|
std::remove_if(
|
||||||
|
_cbEventList.begin(), _cbEventList.end(),
|
||||||
|
[cbEvent, event](const NetworkEventCbList_t &e) {
|
||||||
|
return getStdFunctionAddress(e.fcb) == getStdFunctionAddress(cbEvent) && e.event == event;
|
||||||
|
}
|
||||||
|
),
|
||||||
|
_cbEventList.end()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkEvents::removeEvent(NetworkEventSysCb cbEvent, arduino_event_id_t event) {
|
void NetworkEvents::removeEvent(NetworkEventSysCb cbEvent, arduino_event_id_t event) {
|
||||||
uint32_t i;
|
|
||||||
|
|
||||||
if (!cbEvent) {
|
if (!cbEvent) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
i = findEvent(cbEvent, event);
|
#if defined NETWORK_EVENTS_MUTEX && SOC_CPU_CORES_NUM > 1
|
||||||
if (i >= cbEventList.size()) {
|
std::lock_guard<std::mutex> lock(_mtx);
|
||||||
log_w("Event handler not found!");
|
#endif // defined NETWORK_EVENTS_MUTEX && SOC_CPU_CORES_NUM > 1
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
cbEventList.erase(cbEventList.begin() + i);
|
_cbEventList.erase(
|
||||||
|
std::remove_if(
|
||||||
|
_cbEventList.begin(), _cbEventList.end(),
|
||||||
|
[cbEvent, event](const NetworkEventCbList_t &e) {
|
||||||
|
return e.scb == cbEvent && e.event == event;
|
||||||
|
}
|
||||||
|
),
|
||||||
|
_cbEventList.end()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkEvents::removeEvent(network_event_handle_t id) {
|
void NetworkEvents::removeEvent(network_event_handle_t id) {
|
||||||
for (uint32_t i = 0; i < cbEventList.size(); i++) {
|
#if defined NETWORK_EVENTS_MUTEX && SOC_CPU_CORES_NUM > 1
|
||||||
NetworkEventCbList_t entry = cbEventList[i];
|
std::lock_guard<std::mutex> lock(_mtx);
|
||||||
if (entry.id == id) {
|
#endif // defined NETWORK_EVENTS_MUTEX && SOC_CPU_CORES_NUM > 1
|
||||||
cbEventList.erase(cbEventList.begin() + i);
|
|
||||||
return;
|
_cbEventList.erase(
|
||||||
}
|
std::remove_if(
|
||||||
}
|
_cbEventList.begin(), _cbEventList.end(),
|
||||||
log_w("Event handler not found!");
|
[id](const NetworkEventCbList_t &e) {
|
||||||
|
return e.id == id;
|
||||||
|
}
|
||||||
|
),
|
||||||
|
_cbEventList.end()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
int NetworkEvents::setStatusBits(int bits) {
|
int NetworkEvents::setStatusBits(int bits) {
|
||||||
|
|
@ -380,7 +325,7 @@ int NetworkEvents::clearStatusBits(int bits) {
|
||||||
return xEventGroupClearBits(_arduino_event_group, bits);
|
return xEventGroupClearBits(_arduino_event_group, bits);
|
||||||
}
|
}
|
||||||
|
|
||||||
int NetworkEvents::getStatusBits() {
|
int NetworkEvents::getStatusBits() const {
|
||||||
if (!_arduino_event_group) {
|
if (!_arduino_event_group) {
|
||||||
return _initial_bits;
|
return _initial_bits;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,9 @@
|
||||||
#include "freertos/semphr.h"
|
#include "freertos/semphr.h"
|
||||||
#include "freertos/event_groups.h"
|
#include "freertos/event_groups.h"
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
|
#if defined NETWORK_EVENTS_MUTEX && SOC_CPU_CORES_NUM > 1
|
||||||
|
#include <mutex>
|
||||||
|
#endif // defined NETWORK_EVENTS_MUTEX && SOC_CPU_CORES_NUM > 1
|
||||||
|
|
||||||
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
|
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
|
||||||
#include "esp_wifi_types.h"
|
#include "esp_wifi_types.h"
|
||||||
|
|
@ -25,8 +28,8 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
|
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
|
||||||
static const int WIFI_SCANNING_BIT = BIT0;
|
constexpr int WIFI_SCANNING_BIT = BIT0;
|
||||||
static const int WIFI_SCAN_DONE_BIT = BIT1;
|
constexpr int WIFI_SCAN_DONE_BIT = BIT1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define NET_HAS_IP6_GLOBAL_BIT 0
|
#define NET_HAS_IP6_GLOBAL_BIT 0
|
||||||
|
|
@ -34,7 +37,7 @@ static const int WIFI_SCAN_DONE_BIT = BIT1;
|
||||||
ESP_EVENT_DECLARE_BASE(ARDUINO_EVENTS);
|
ESP_EVENT_DECLARE_BASE(ARDUINO_EVENTS);
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ARDUINO_EVENT_NONE,
|
ARDUINO_EVENT_NONE = 0,
|
||||||
ARDUINO_EVENT_ETH_START,
|
ARDUINO_EVENT_ETH_START,
|
||||||
ARDUINO_EVENT_ETH_STOP,
|
ARDUINO_EVENT_ETH_STOP,
|
||||||
ARDUINO_EVENT_ETH_CONNECTED,
|
ARDUINO_EVENT_ETH_CONNECTED,
|
||||||
|
|
@ -43,10 +46,11 @@ typedef enum {
|
||||||
ARDUINO_EVENT_ETH_LOST_IP,
|
ARDUINO_EVENT_ETH_LOST_IP,
|
||||||
ARDUINO_EVENT_ETH_GOT_IP6,
|
ARDUINO_EVENT_ETH_GOT_IP6,
|
||||||
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
|
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
|
||||||
ARDUINO_EVENT_WIFI_OFF,
|
ARDUINO_EVENT_WIFI_OFF = 100,
|
||||||
ARDUINO_EVENT_WIFI_READY,
|
ARDUINO_EVENT_WIFI_READY,
|
||||||
ARDUINO_EVENT_WIFI_SCAN_DONE,
|
ARDUINO_EVENT_WIFI_SCAN_DONE,
|
||||||
ARDUINO_EVENT_WIFI_STA_START,
|
ARDUINO_EVENT_WIFI_FTM_REPORT,
|
||||||
|
ARDUINO_EVENT_WIFI_STA_START = 110,
|
||||||
ARDUINO_EVENT_WIFI_STA_STOP,
|
ARDUINO_EVENT_WIFI_STA_STOP,
|
||||||
ARDUINO_EVENT_WIFI_STA_CONNECTED,
|
ARDUINO_EVENT_WIFI_STA_CONNECTED,
|
||||||
ARDUINO_EVENT_WIFI_STA_DISCONNECTED,
|
ARDUINO_EVENT_WIFI_STA_DISCONNECTED,
|
||||||
|
|
@ -54,24 +58,23 @@ typedef enum {
|
||||||
ARDUINO_EVENT_WIFI_STA_GOT_IP,
|
ARDUINO_EVENT_WIFI_STA_GOT_IP,
|
||||||
ARDUINO_EVENT_WIFI_STA_GOT_IP6,
|
ARDUINO_EVENT_WIFI_STA_GOT_IP6,
|
||||||
ARDUINO_EVENT_WIFI_STA_LOST_IP,
|
ARDUINO_EVENT_WIFI_STA_LOST_IP,
|
||||||
ARDUINO_EVENT_WIFI_AP_START,
|
ARDUINO_EVENT_WIFI_AP_START = 130,
|
||||||
ARDUINO_EVENT_WIFI_AP_STOP,
|
ARDUINO_EVENT_WIFI_AP_STOP,
|
||||||
ARDUINO_EVENT_WIFI_AP_STACONNECTED,
|
ARDUINO_EVENT_WIFI_AP_STACONNECTED,
|
||||||
ARDUINO_EVENT_WIFI_AP_STADISCONNECTED,
|
ARDUINO_EVENT_WIFI_AP_STADISCONNECTED,
|
||||||
ARDUINO_EVENT_WIFI_AP_STAIPASSIGNED,
|
ARDUINO_EVENT_WIFI_AP_STAIPASSIGNED,
|
||||||
ARDUINO_EVENT_WIFI_AP_PROBEREQRECVED,
|
ARDUINO_EVENT_WIFI_AP_PROBEREQRECVED,
|
||||||
ARDUINO_EVENT_WIFI_AP_GOT_IP6,
|
ARDUINO_EVENT_WIFI_AP_GOT_IP6,
|
||||||
ARDUINO_EVENT_WIFI_FTM_REPORT,
|
ARDUINO_EVENT_WPS_ER_SUCCESS = 140,
|
||||||
ARDUINO_EVENT_WPS_ER_SUCCESS,
|
|
||||||
ARDUINO_EVENT_WPS_ER_FAILED,
|
ARDUINO_EVENT_WPS_ER_FAILED,
|
||||||
ARDUINO_EVENT_WPS_ER_TIMEOUT,
|
ARDUINO_EVENT_WPS_ER_TIMEOUT,
|
||||||
ARDUINO_EVENT_WPS_ER_PIN,
|
ARDUINO_EVENT_WPS_ER_PIN,
|
||||||
ARDUINO_EVENT_WPS_ER_PBC_OVERLAP,
|
ARDUINO_EVENT_WPS_ER_PBC_OVERLAP,
|
||||||
ARDUINO_EVENT_SC_SCAN_DONE,
|
ARDUINO_EVENT_SC_SCAN_DONE = 150,
|
||||||
ARDUINO_EVENT_SC_FOUND_CHANNEL,
|
ARDUINO_EVENT_SC_FOUND_CHANNEL,
|
||||||
ARDUINO_EVENT_SC_GOT_SSID_PSWD,
|
ARDUINO_EVENT_SC_GOT_SSID_PSWD,
|
||||||
ARDUINO_EVENT_SC_SEND_ACK_DONE,
|
ARDUINO_EVENT_SC_SEND_ACK_DONE,
|
||||||
ARDUINO_EVENT_PROV_INIT,
|
ARDUINO_EVENT_PROV_INIT = 160,
|
||||||
ARDUINO_EVENT_PROV_DEINIT,
|
ARDUINO_EVENT_PROV_DEINIT,
|
||||||
ARDUINO_EVENT_PROV_START,
|
ARDUINO_EVENT_PROV_START,
|
||||||
ARDUINO_EVENT_PROV_END,
|
ARDUINO_EVENT_PROV_END,
|
||||||
|
|
@ -79,7 +82,7 @@ typedef enum {
|
||||||
ARDUINO_EVENT_PROV_CRED_FAIL,
|
ARDUINO_EVENT_PROV_CRED_FAIL,
|
||||||
ARDUINO_EVENT_PROV_CRED_SUCCESS,
|
ARDUINO_EVENT_PROV_CRED_SUCCESS,
|
||||||
#endif
|
#endif
|
||||||
ARDUINO_EVENT_PPP_START,
|
ARDUINO_EVENT_PPP_START = 200,
|
||||||
ARDUINO_EVENT_PPP_STOP,
|
ARDUINO_EVENT_PPP_STOP,
|
||||||
ARDUINO_EVENT_PPP_CONNECTED,
|
ARDUINO_EVENT_PPP_CONNECTED,
|
||||||
ARDUINO_EVENT_PPP_DISCONNECTED,
|
ARDUINO_EVENT_PPP_DISCONNECTED,
|
||||||
|
|
@ -113,36 +116,123 @@ typedef union {
|
||||||
#endif
|
#endif
|
||||||
} arduino_event_info_t;
|
} arduino_event_info_t;
|
||||||
|
|
||||||
typedef struct {
|
/**
|
||||||
|
* @brief struct combines arduino event id and event's data object
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
struct arduino_event_t {
|
||||||
arduino_event_id_t event_id;
|
arduino_event_id_t event_id;
|
||||||
arduino_event_info_t event_info;
|
arduino_event_info_t event_info;
|
||||||
} arduino_event_t;
|
};
|
||||||
|
|
||||||
typedef void (*NetworkEventCb)(arduino_event_id_t event);
|
// type aliases
|
||||||
typedef std::function<void(arduino_event_id_t event, arduino_event_info_t info)> NetworkEventFuncCb;
|
using NetworkEventCb = void (*)(arduino_event_id_t event);
|
||||||
typedef void (*NetworkEventSysCb)(arduino_event_t *event);
|
using NetworkEventFuncCb = std::function<void(arduino_event_id_t event, arduino_event_info_t info)>;
|
||||||
|
using NetworkEventSysCb = void (*)(arduino_event_t *event);
|
||||||
typedef size_t network_event_handle_t;
|
using network_event_handle_t = size_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class that provides network events callback handling
|
||||||
|
* it registers user callback functions for event handling,
|
||||||
|
* maintains the queue of events and propagates the event among subscribed callbacks
|
||||||
|
* callback are called in the context of a dedicated task consuming the queue
|
||||||
|
*
|
||||||
|
*/
|
||||||
class NetworkEvents {
|
class NetworkEvents {
|
||||||
public:
|
public:
|
||||||
NetworkEvents();
|
NetworkEvents();
|
||||||
~NetworkEvents();
|
~NetworkEvents();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief register callback function to be executed on arduino event(s)
|
||||||
|
* @note if same handler is registered twice or more than same handler would be called twice or more times
|
||||||
|
*
|
||||||
|
* @param cbEvent static callback function
|
||||||
|
* @param event event to process, any event by default
|
||||||
|
* @return network_event_handle_t
|
||||||
|
*/
|
||||||
network_event_handle_t onEvent(NetworkEventCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX);
|
network_event_handle_t onEvent(NetworkEventCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief register functional callback to be executed on arduino event(s)
|
||||||
|
* also used for lambda callbacks
|
||||||
|
* @note if same handler is registered twice or more than same handler would be called twice or more times
|
||||||
|
*
|
||||||
|
* @param cbEvent static callback function
|
||||||
|
* @param event event to process, any event by default
|
||||||
|
* @return network_event_handle_t
|
||||||
|
*/
|
||||||
network_event_handle_t onEvent(NetworkEventFuncCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX);
|
network_event_handle_t onEvent(NetworkEventFuncCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief register static system callback to be executed on arduino event(s)
|
||||||
|
* callback function would be supplied with a pointer to arduino_event_t structure as an argument
|
||||||
|
*
|
||||||
|
* @note if same handler is registered twice or more than same handler would be called twice or more times
|
||||||
|
*
|
||||||
|
* @param cbEvent static callback function
|
||||||
|
* @param event event to process, any event by default
|
||||||
|
* @return network_event_handle_t
|
||||||
|
*/
|
||||||
network_event_handle_t onEvent(NetworkEventSysCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX);
|
network_event_handle_t onEvent(NetworkEventSysCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief unregister static function callback
|
||||||
|
* @note a better way to unregister callbacks is to save/unregister via network_event_handle_t
|
||||||
|
*
|
||||||
|
* @param cbEvent static callback function
|
||||||
|
* @param event event to process, any event by default
|
||||||
|
*/
|
||||||
void removeEvent(NetworkEventCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX);
|
void removeEvent(NetworkEventCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX);
|
||||||
void removeEvent(NetworkEventFuncCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX);
|
|
||||||
|
/**
|
||||||
|
* @brief unregister functional callback
|
||||||
|
* @note a better way to unregister callbacks is to save/unregister via network_event_handle_t
|
||||||
|
* @note this does not work for lambda's! Do unregister via network_event_handle_t
|
||||||
|
*
|
||||||
|
* @param cbEvent functional callback
|
||||||
|
* @param event event to process, any event by default
|
||||||
|
*/
|
||||||
|
void removeEvent(NetworkEventFuncCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX)
|
||||||
|
__attribute__((deprecated("removing functional callbacks via pointer is deprecated, use removeEvent(network_event_handle_t) instead")));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief unregister static system function callback
|
||||||
|
* @note a better way to unregister callbacks is to save/unregister via network_event_handle_t
|
||||||
|
*
|
||||||
|
* @param cbEvent static callback function
|
||||||
|
* @param event event to process, any event by default
|
||||||
|
*/
|
||||||
void removeEvent(NetworkEventSysCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX);
|
void removeEvent(NetworkEventSysCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief unregister event callback via handler
|
||||||
|
*
|
||||||
|
* @param cbEvent static callback function
|
||||||
|
* @param event event to process, any event by default
|
||||||
|
*/
|
||||||
void removeEvent(network_event_handle_t event_handle);
|
void removeEvent(network_event_handle_t event_handle);
|
||||||
|
|
||||||
const char *eventName(arduino_event_id_t id);
|
/**
|
||||||
|
* @brief get a human-readable name of an event by it's id
|
||||||
|
*
|
||||||
|
* @param id event id code
|
||||||
|
* @return const char* event name string
|
||||||
|
*/
|
||||||
|
static const char *eventName(arduino_event_id_t id);
|
||||||
|
|
||||||
void checkForEvent();
|
/**
|
||||||
bool postEvent(arduino_event_t *event);
|
* @brief post an event to the queue
|
||||||
|
* and propagade and event to subscribed handlers
|
||||||
|
* @note posting an event will trigger context switch from a lower priority task
|
||||||
|
*
|
||||||
|
* @param event a pointer to arduino_event_t struct
|
||||||
|
* @return true if event was queued susccessfuly
|
||||||
|
* @return false on memrory allocation error or queue is full
|
||||||
|
*/
|
||||||
|
bool postEvent(const arduino_event_t *event);
|
||||||
|
|
||||||
int getStatusBits();
|
int getStatusBits() const;
|
||||||
int waitStatusBits(int bits, uint32_t timeout_ms);
|
int waitStatusBits(int bits, uint32_t timeout_ms);
|
||||||
int setStatusBits(int bits);
|
int setStatusBits(int bits);
|
||||||
int clearStatusBits(int bits);
|
int clearStatusBits(int bits);
|
||||||
|
|
@ -158,15 +248,53 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool initNetworkEvents();
|
bool initNetworkEvents();
|
||||||
uint32_t findEvent(NetworkEventCb cbEvent, arduino_event_id_t event);
|
// same as onEvent() but places newly added handler at the beginning of registered events list
|
||||||
uint32_t findEvent(NetworkEventFuncCb cbEvent, arduino_event_id_t event);
|
|
||||||
uint32_t findEvent(NetworkEventSysCb cbEvent, arduino_event_id_t event);
|
|
||||||
network_event_handle_t onSysEvent(NetworkEventCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX);
|
network_event_handle_t onSysEvent(NetworkEventCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX);
|
||||||
|
// same as onEvent() but places newly added handler at the beginning of registered events list
|
||||||
network_event_handle_t onSysEvent(NetworkEventFuncCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX);
|
network_event_handle_t onSysEvent(NetworkEventFuncCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX);
|
||||||
|
// same as onEvent() but places newly added handler at the beginning of registered events list
|
||||||
network_event_handle_t onSysEvent(NetworkEventSysCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX);
|
network_event_handle_t onSysEvent(NetworkEventSysCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/**
|
||||||
|
* @brief an object holds callback's definitions:
|
||||||
|
* - callback id
|
||||||
|
* - callback function pointers
|
||||||
|
* - binded event id
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
struct NetworkEventCbList_t {
|
||||||
|
network_event_handle_t id;
|
||||||
|
NetworkEventCb cb;
|
||||||
|
NetworkEventFuncCb fcb;
|
||||||
|
NetworkEventSysCb scb;
|
||||||
|
arduino_event_id_t event;
|
||||||
|
|
||||||
|
explicit NetworkEventCbList_t(
|
||||||
|
network_event_handle_t id, NetworkEventCb cb = nullptr, NetworkEventFuncCb fcb = nullptr, NetworkEventSysCb scb = nullptr,
|
||||||
|
arduino_event_id_t event = ARDUINO_EVENT_MAX
|
||||||
|
)
|
||||||
|
: id(id), cb(cb), fcb(fcb), scb(scb), event(event) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
// define initial id's value
|
||||||
|
network_event_handle_t _current_id{0};
|
||||||
|
|
||||||
EventGroupHandle_t _arduino_event_group;
|
EventGroupHandle_t _arduino_event_group;
|
||||||
QueueHandle_t _arduino_event_queue;
|
QueueHandle_t _arduino_event_queue;
|
||||||
TaskHandle_t _arduino_event_task_handle;
|
TaskHandle_t _arduino_event_task_handle;
|
||||||
|
|
||||||
|
// registered events callbacks container
|
||||||
|
std::vector<NetworkEventCbList_t> _cbEventList;
|
||||||
|
|
||||||
|
#if defined NETWORK_EVENTS_MUTEX && SOC_CPU_CORES_NUM > 1
|
||||||
|
// container access mutex
|
||||||
|
std::mutex _mtx;
|
||||||
|
#endif // defined NETWORK_EVENTS_MUTEX && SOC_CPU_CORES_NUM > 1
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief task function that picks events from an event queue and calls registered callbacks
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void _checkForEvent();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -137,8 +137,9 @@ public:
|
||||||
|
|
||||||
/*
|
/*
|
||||||
sets the expected MD5 for the firmware (hexString)
|
sets the expected MD5 for the firmware (hexString)
|
||||||
|
If calc_post_decryption is true, the update library will calculate the MD5 after the decryption, if false the calculation occurs before the decryption
|
||||||
*/
|
*/
|
||||||
bool setMD5(const char *expected_md5);
|
bool setMD5(const char *expected_md5, bool calc_post_decryption = true);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
returns the MD5 String of the successfully ended firmware
|
returns the MD5 String of the successfully ended firmware
|
||||||
|
|
@ -257,6 +258,7 @@ private:
|
||||||
const esp_partition_t *_partition;
|
const esp_partition_t *_partition;
|
||||||
|
|
||||||
String _target_md5;
|
String _target_md5;
|
||||||
|
bool _target_md5_decrypted = true;
|
||||||
MD5Builder _md5;
|
MD5Builder _md5;
|
||||||
|
|
||||||
int _ledPin;
|
int _ledPin;
|
||||||
|
|
|
||||||
|
|
@ -348,6 +348,11 @@ bool UpdateClass::_writeBuffer() {
|
||||||
log_d("Decrypting OTA Image");
|
log_d("Decrypting OTA Image");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!_target_md5_decrypted) {
|
||||||
|
_md5.add(_buffer, _bufferLen);
|
||||||
|
}
|
||||||
|
|
||||||
//check if data in buffer needs decrypting
|
//check if data in buffer needs decrypting
|
||||||
if (_cryptMode & U_AES_IMAGE_DECRYPTING_BIT) {
|
if (_cryptMode & U_AES_IMAGE_DECRYPTING_BIT) {
|
||||||
if (!_decryptBuffer()) {
|
if (!_decryptBuffer()) {
|
||||||
|
|
@ -404,7 +409,9 @@ bool UpdateClass::_writeBuffer() {
|
||||||
if (!_progress && _command == U_FLASH) {
|
if (!_progress && _command == U_FLASH) {
|
||||||
_buffer[0] = ESP_IMAGE_HEADER_MAGIC;
|
_buffer[0] = ESP_IMAGE_HEADER_MAGIC;
|
||||||
}
|
}
|
||||||
_md5.add(_buffer, _bufferLen);
|
if (_target_md5_decrypted) {
|
||||||
|
_md5.add(_buffer, _bufferLen);
|
||||||
|
}
|
||||||
_progress += _bufferLen;
|
_progress += _bufferLen;
|
||||||
_bufferLen = 0;
|
_bufferLen = 0;
|
||||||
if (_progress_callback) {
|
if (_progress_callback) {
|
||||||
|
|
@ -446,12 +453,13 @@ bool UpdateClass::_verifyEnd() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UpdateClass::setMD5(const char *expected_md5) {
|
bool UpdateClass::setMD5(const char *expected_md5, bool calc_post_decryption) {
|
||||||
if (strlen(expected_md5) != 32) {
|
if (strlen(expected_md5) != 32) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
_target_md5 = expected_md5;
|
_target_md5 = expected_md5;
|
||||||
_target_md5.toLowerCase();
|
_target_md5.toLowerCase();
|
||||||
|
_target_md5_decrypted = calc_post_decryption;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue