Add a simple hello test
This commit is contained in:
parent
3c29475b82
commit
3720ec76d2
@ -3,6 +3,7 @@
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <variant>
|
||||
#include <cstdio>
|
||||
|
||||
#include "esp_event.h"
|
||||
#include "esp_mac.h"
|
||||
@ -35,6 +36,11 @@ bool s_isBroadcastAddress(const esp_now_recv_info_t* sender)
|
||||
return s_isBroadcastAddress(sender->src_addr);
|
||||
}
|
||||
|
||||
constexpr MacAddress s_getBroadcastAddress()
|
||||
{
|
||||
return MacAddress{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
||||
}
|
||||
|
||||
esp_err_t s_addPeer(const MacAddress& peer_address)
|
||||
{
|
||||
esp_now_peer_info_t broadcast_peer;
|
||||
@ -96,7 +102,7 @@ QueueHandle_t setupEspNow()
|
||||
ESP_ERROR_CHECK(esp_now_register_send_cb(s_cbEspNowSendComplete));
|
||||
ESP_ERROR_CHECK(esp_now_register_recv_cb(s_cbEspNowReceiveComplete));
|
||||
|
||||
const auto broadcast_mac = MacAddress{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
||||
const auto broadcast_mac = s_getBroadcastAddress();
|
||||
s_peer = broadcast_mac;
|
||||
|
||||
ESP_ERROR_CHECK(s_addPeer(broadcast_mac));
|
||||
@ -104,6 +110,19 @@ QueueHandle_t setupEspNow()
|
||||
return s_esp_now_queue;
|
||||
}
|
||||
|
||||
void sendHello()
|
||||
{
|
||||
MacAddress mac;
|
||||
ESP_ERROR_CHECK(esp_read_mac(mac.data(), ESP_MAC_WIFI_STA));
|
||||
|
||||
char buffer[100];
|
||||
const std::size_t length = std::sprintf(buffer, "Hello from %02X:%02X:%02X:%02X:%02X:%02X.\n\r",
|
||||
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
|
||||
const auto broadcast_mac = s_getBroadcastAddress();
|
||||
ESP_ERROR_CHECK(esp_now_send(broadcast_mac.data(), (uint8_t*)buffer, length));
|
||||
}
|
||||
|
||||
const std::array<std::uint8_t, 128>& getRxBuffer()
|
||||
{
|
||||
return s_rx_buffer;
|
||||
|
||||
@ -26,6 +26,7 @@ using MacAddress = std::array<std::uint8_t, 6>;
|
||||
|
||||
void setupWifi();
|
||||
[[nodiscard]] QueueHandle_t setupEspNow();
|
||||
void sendHello();
|
||||
|
||||
void sendData(const std::array<std::uint8_t, 128>& buffer, const std::size_t length);
|
||||
const std::array<std::uint8_t, 128>& getRxBuffer();
|
||||
|
||||
@ -151,6 +151,9 @@ extern "C" void app_main(void)
|
||||
xQueueAddToSet(s_esp_now_queue, s_queue_set);
|
||||
xQueueAddToSet(s_uart_queue, s_queue_set);
|
||||
|
||||
ESP_LOGI(LOG_TAG, "Setup completed.");
|
||||
ESP_LOGI(LOG_TAG, "Setup completed. Sending hello.");
|
||||
|
||||
Networking::sendHello();
|
||||
|
||||
xTaskCreate(s_mainTask, "main_task", 2048, nullptr, 4, &s_main_task);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user