Removed queue
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
#ifdef FEATURE_ESPNOW
|
#ifdef FEATURE_ESPNOW
|
||||||
#include "espnowfunctions.h"
|
#include "espnowfunctions.h"
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include <espchrono.h>
|
#include <espchrono.h>
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
#include <numberparsing.h>
|
#include <numberparsing.h>
|
||||||
@@ -20,7 +18,6 @@ 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};
|
||||||
|
|
||||||
@@ -36,14 +33,46 @@ extern "C" void onReceive(const uint8_t *mac_addr, const uint8_t *data, int data
|
|||||||
size_t sep_pos = data_str.find(":");
|
size_t sep_pos = data_str.find(":");
|
||||||
if (std::string_view::npos != sep_pos)
|
if (std::string_view::npos != sep_pos)
|
||||||
{
|
{
|
||||||
std::string_view msg_type = data_str.substr(0, sep_pos);
|
esp_now_message_t msg{
|
||||||
std::string_view msg = data_str.substr(sep_pos+1, data_str.length()-sep_pos-1);
|
.content = std::string{data_str.substr(sep_pos+1, data_str.length()-sep_pos-1)},
|
||||||
ESP_LOGD(TAG, "Type: %.*s - Message: %.*s", msg_type.size(), msg_type.data(), msg.size(), msg.data());
|
.type = std::string{data_str.substr(0, sep_pos)}
|
||||||
|
};
|
||||||
|
|
||||||
message_queue.push_back(esp_now_message_t {
|
ESP_LOGD(TAG, "Type: %s - Message: %s", msg.type.c_str(), msg.content.c_str());
|
||||||
.content = std::string{msg},
|
|
||||||
.type = std::string{msg_type}
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -183,49 +212,6 @@ void handle()
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(message_queue.size())
|
|
||||||
{
|
|
||||||
for (const esp_now_message_t &msg : message_queue)
|
|
||||||
{
|
|
||||||
ESP_LOGD(TAG, "queue has processed message of type '%s' with content '%s'", msg.type.c_str(), msg.content.c_str());
|
|
||||||
message_queue.pop_front();
|
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void onRecvTs(uint64_t millis, bool isFromBobbycar)
|
void onRecvTs(uint64_t millis, bool isFromBobbycar)
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
#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>
|
||||||
@@ -19,7 +18,6 @@ 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