Readded queue
This commit is contained in:
@ -18,6 +18,7 @@ constexpr const char * const TAG = "BOBBY_ESP_NOW";
|
|||||||
|
|
||||||
uint16_t lastYear; // Used for esp-now timesync
|
uint16_t lastYear; // Used for esp-now timesync
|
||||||
|
|
||||||
|
std::deque<esp_now_message_t> message_queue{};
|
||||||
std::vector<esp_now_peer_info_t> peers{};
|
std::vector<esp_now_peer_info_t> peers{};
|
||||||
uint8_t initialized{0};
|
uint8_t initialized{0};
|
||||||
|
|
||||||
@ -40,39 +41,7 @@ extern "C" void onReceive(const uint8_t *mac_addr, const uint8_t *data, int data
|
|||||||
|
|
||||||
ESP_LOGD(TAG, "Type: %s - Message: %s", msg.type.c_str(), msg.content.c_str());
|
ESP_LOGD(TAG, "Type: %s - Message: %s", msg.type.c_str(), msg.content.c_str());
|
||||||
|
|
||||||
if (msg.type == "T")
|
message_queue.push_back(msg);
|
||||||
{
|
|
||||||
if (!receiveTimeStamp || !settings.espnow.syncTime)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (const auto result = cpputils::fromString<uint64_t>(msg.content); result)
|
|
||||||
{
|
|
||||||
onRecvTs(*result);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ESP_LOGW(TAG, "could not parse number: %.*s", result.error().size(), result.error().data());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (msg.type == "BOBBYT")
|
|
||||||
{
|
|
||||||
if (!receiveTsFromOtherBobbycars || !settings.espnow.syncTimeWithOthers)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (const auto result = cpputils::fromString<uint64_t>(msg.content); result)
|
|
||||||
{
|
|
||||||
ESP_LOGI(TAG, "setting current time to %" PRIu64, *result);
|
|
||||||
onRecvTs(*result, true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ESP_LOGW(TAG, "could not parse number: %.*s", result.error().size(), result.error().data());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ESP_LOGI(TAG, "Unkown Type: %s - Message: %s", msg.type.c_str(), msg.content.c_str());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -212,6 +181,47 @@ void handle()
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (message_queue.size())
|
||||||
|
{
|
||||||
|
for (const esp_now_message_t &msg : message_queue)
|
||||||
|
{
|
||||||
|
if (msg.type == "T")
|
||||||
|
{
|
||||||
|
if (!receiveTimeStamp || !settings.espnow.syncTime)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (const auto result = cpputils::fromString<uint64_t>(msg.content); result)
|
||||||
|
{
|
||||||
|
onRecvTs(*result);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ESP_LOGW(TAG, "could not parse number: %.*s", result.error().size(), result.error().data());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (msg.type == "BOBBYT")
|
||||||
|
{
|
||||||
|
if (!receiveTsFromOtherBobbycars || !settings.espnow.syncTimeWithOthers)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (const auto result = cpputils::fromString<uint64_t>(msg.content); result)
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG, "setting current time to %" PRIu64, *result);
|
||||||
|
onRecvTs(*result, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ESP_LOGW(TAG, "could not parse number: %.*s", result.error().size(), result.error().data());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG, "Unkown Type: %s - Message: %s", msg.type.c_str(), msg.content.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
message_queue.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onRecvTs(uint64_t millis, bool isFromBobbycar)
|
void onRecvTs(uint64_t millis, bool isFromBobbycar)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#ifdef FEATURE_ESPNOW
|
#ifdef FEATURE_ESPNOW
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <deque>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -18,6 +19,7 @@ struct esp_now_message_t
|
|||||||
extern bool receiveTimeStamp;
|
extern bool receiveTimeStamp;
|
||||||
extern bool receiveTsFromOtherBobbycars;
|
extern bool receiveTsFromOtherBobbycars;
|
||||||
|
|
||||||
|
extern std::deque<esp_now_message_t> message_queue;
|
||||||
extern std::vector<esp_now_peer_info_t> peers;
|
extern std::vector<esp_now_peer_info_t> peers;
|
||||||
|
|
||||||
void initESPNow();
|
void initESPNow();
|
||||||
|
Reference in New Issue
Block a user