Scheiß
This commit is contained in:
@@ -118,6 +118,7 @@ set(BOBBYCAR_BUILDFLAGS
|
|||||||
-DOLD_NVS
|
-DOLD_NVS
|
||||||
-DFEATURE_DNS_NS
|
-DFEATURE_DNS_NS
|
||||||
-DSWITCH_BLINK
|
-DSWITCH_BLINK
|
||||||
|
# -DFEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_FUNKTIONIERT
|
||||||
-DFEATURE_ESPNOW
|
-DFEATURE_ESPNOW
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -92,10 +92,13 @@ set(BOBBYCAR_BUILDFLAGS
|
|||||||
-DFEATURE_LEDSTRIP
|
-DFEATURE_LEDSTRIP
|
||||||
-DPINS_LEDSTRIP=26
|
-DPINS_LEDSTRIP=26
|
||||||
-DLEDSTRIP_LENGTH=200
|
-DLEDSTRIP_LENGTH=200
|
||||||
|
# -DHEAP_LRGST_CRASH_TEXT_FIX
|
||||||
# -DLEDSTRIP_WRONG_DIRECTION
|
# -DLEDSTRIP_WRONG_DIRECTION
|
||||||
-DLEDSTRIP_ANIMATION_DEFAULT=0
|
-DLEDSTRIP_ANIMATION_DEFAULT=0
|
||||||
-DLEDS_PER_METER=144
|
-DLEDS_PER_METER=144
|
||||||
-DOLD_NVS
|
-DOLD_NVS
|
||||||
# -DFEATURE_DNS_NS
|
# -DFEATURE_DNS_NS
|
||||||
|
# -DSWITCH_BLINK
|
||||||
-DFEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_FUNKTIONIERT
|
-DFEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_FUNKTIONIERT
|
||||||
|
-DFEATURE_ESPNOW
|
||||||
)
|
)
|
||||||
|
@@ -20,33 +20,32 @@ 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::deque<esp_now_message_t> message_queue{};
|
||||||
std::list<esp_now_peer_info_t> peers{};
|
std::vector<esp_now_peer_info_t> peers{};
|
||||||
uint8_t initialized{0};
|
uint8_t initialized{0};
|
||||||
|
|
||||||
bool receiveTimeStamp{true};
|
bool receiveTimeStamp{true};
|
||||||
bool receiveTsFromOtherBobbycars{true};
|
bool receiveTsFromOtherBobbycars{true};
|
||||||
|
|
||||||
void onReceive(const uint8_t *mac_addr, const uint8_t *data, int data_len)
|
extern "C" void onReceive(const uint8_t *mac_addr, const char *data, int data_len)
|
||||||
{
|
{
|
||||||
ESP_LOGD(TAG, "Received data");
|
ESP_LOGD(TAG, "Received data");
|
||||||
const std::string data_str(data, data+data_len);
|
const std::string_view data_str{data, size_t(data_len)};
|
||||||
|
|
||||||
size_t sep_pos = data_str.find(":");
|
size_t sep_pos = data_str.find(":");
|
||||||
if (std::string::npos != sep_pos)
|
if (std::string_view::npos != sep_pos)
|
||||||
{
|
{
|
||||||
std::string msg_type = data_str.substr(0, sep_pos);
|
std::string_view msg_type = data_str.substr(0, sep_pos);
|
||||||
std::string msg = data_str.substr(sep_pos+1, data_str.length()-3); // - 3 may needs to be converted to sep_pos+1
|
std::string_view msg = data_str.substr(sep_pos+1, data_str.length()-3); // - 3 may needs to be converted to sep_pos+1
|
||||||
ESP_LOGD(TAG, "Type: %s - Message: %s", msg_type.c_str(), msg.c_str());
|
ESP_LOGD(TAG, "Type: %.*s - Message: %.*s", msg_type.size(), msg_type.data(), msg.size(), msg.data());
|
||||||
|
|
||||||
const esp_now_message_t message{
|
message_queue.push_back(esp_now_message_t {
|
||||||
.content = msg,
|
.content = std::string{msg},
|
||||||
.type = msg_type
|
.type = std::string{msg_type}
|
||||||
};
|
});
|
||||||
message_queue.push_back(message);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ESP_LOGW(TAG, "Invalid message: Could not find ':' (%s)", data_str.c_str());
|
ESP_LOGW(TAG, "Invalid message: Could not find ':' (%.*s)", data_str.size(), data_str.data());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,7 +244,7 @@ void onRecvTs(uint64_t millis, bool isFromBobbycar)
|
|||||||
receiveTsFromOtherBobbycars = false;
|
receiveTsFromOtherBobbycars = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t send_espnow_message(std::string message)
|
esp_err_t send_espnow_message(std::string_view message)
|
||||||
{
|
{
|
||||||
if (initialized < 255)
|
if (initialized < 255)
|
||||||
return ESP_ERR_ESPNOW_NOT_INIT;
|
return ESP_ERR_ESPNOW_NOT_INIT;
|
||||||
|
@@ -3,27 +3,29 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <string_view>
|
||||||
|
#include <vector>
|
||||||
#include <esp_now.h>
|
#include <esp_now.h>
|
||||||
|
|
||||||
namespace espnow {
|
namespace espnow {
|
||||||
extern uint16_t lastYear;
|
extern uint16_t lastYear;
|
||||||
constexpr const uint8_t broadcast_address[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
constexpr const uint8_t broadcast_address[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
||||||
struct esp_now_message_t {
|
struct esp_now_message_t
|
||||||
const std::string content;
|
{
|
||||||
const std::string type;
|
std::string content;
|
||||||
|
std::string type;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern bool receiveTimeStamp;
|
extern bool receiveTimeStamp;
|
||||||
extern bool receiveTsFromOtherBobbycars;
|
extern bool receiveTsFromOtherBobbycars;
|
||||||
|
|
||||||
extern std::deque<esp_now_message_t> message_queue;
|
extern std::deque<esp_now_message_t> message_queue;
|
||||||
extern std::list<esp_now_peer_info_t> peers;
|
extern std::vector<esp_now_peer_info_t> peers;
|
||||||
|
|
||||||
void onReceive(const uint8_t *mac_addr, const uint8_t *data, int data_len);
|
void onReceive(const uint8_t *mac_addr, const uint8_t *data, int data_len);
|
||||||
void initESPNow();
|
void initESPNow();
|
||||||
void handle();
|
void handle();
|
||||||
void onRecvTs(uint64_t millis, bool isFromBobbycar = false);
|
void onRecvTs(uint64_t millis, bool isFromBobbycar = false);
|
||||||
esp_err_t send_espnow_message(std::string message);
|
esp_err_t send_espnow_message(std::string_view message);
|
||||||
} // namespace espnow
|
} // namespace espnow
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user