ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
radio_link.cpp
Go to the documentation of this file.
1#include "radio_link.h"
2#include <cinttypes>
4#include "esphome/core/log.h"
5
7
8ESPHOME_LOG_TAG(TAG, "packet_interface.radio");
9
10bool RadioLinkBase::check_size_(size_t size) const {
12 return true;
13 ESP_LOGW(TAG, "Packet of %zu bytes is larger than %zu", size, this->max_packet_size_);
14 return false;
15}
16
17bool RadioLinkBase::may_send_(bool busy) {
18 if (busy)
19 this->enable_loop();
21}
22
23bool RadioLinkBase::sent_(bool sent, bool busy) {
24 if (busy) {
26 // The radio listens again, and a reception that starts now must be waited for afresh
28 // The limit is longer than any packet takes, so the radio's busy indication is stuck or the channel is jammed
29 ESP_LOGW(TAG, "Radio busy for %" PRIu32 "ms, %s", busy_ms,
30 sent ? LOG_STR_LITERAL("sent anyway") : LOG_STR_LITERAL("tried to send anyway, which failed"));
31 }
32 if (sent)
34 return sent;
35}
36
38 ESP_LOGV(TAG, "Empty packet not sent");
39 return true;
40}
41
43 if (!failed || this->failed_warned_)
44 return;
45 this->failed_warned_ = true;
46 ESP_LOGW(TAG, "%s: The radio failed to set up, so nothing can be sent", this->name_);
47}
48
53
54void RadioLinkBase::receive_(std::span<const uint8_t> packet, float rssi, float snr) {
55 // The radio takes packets up to its own limit, so a larger one is from a device configured differently
56 if (packet.size() > this->max_packet_size_) {
57 ESP_LOGV(TAG, "%s: Packet of %zu bytes is larger than %zu, dropped", this->name_, packet.size(),
58 this->max_packet_size_);
59 this->note_received_(false);
60 return;
61 }
62 this->note_received_(true);
64 PacketMetaData meta_data;
65 meta_data.rssi = rssi;
66 meta_data.snr = snr;
67 this->on_receive_from_interface_(PacketBuffer(packet.data(), packet.size()), meta_data);
68}
69
70} // namespace esphome::packet_interface
uint32_t IRAM_ATTR HOT get_loop_component_start_time() const
Get the cached time in milliseconds from when the current component started its loop execution.
void enable_loop()
Enable this component's loop.
Definition component.h:262
void disable_loop()
Disable this component's loop.
void received()
A packet arrived, so the peer has taken its turn.
void end_busy()
Ends the busy period, when the radio is seen to be free other than by a send.
void sent(uint32_t now, uint32_t pass)
A packet was sent, ending at now, in the loop pass that started at pass.
uint32_t busy_for(uint32_t now) const
How long the current busy period has lasted at now.
bool may_send(bool busy, uint32_t now, uint32_t pass)
True if a packet may be sent at now, in the loop pass that started at pass; busy says whether the rad...
A buffer class that efficiently represents a composite buffer with three sections:
void note_received_(bool understood)
Called by a layer for each received packet it understood, or could not make sense of.
void on_receive_from_interface_(const PacketBuffer &data, const PacketMetaData &meta_data)
This function should be called by implementing classes with received data to be passed to any listene...
A struct to hold metadata about a packet.
ESPHOME_LOG_TAG(TAG, "packet_interface.addressing")
uint16_t size
Definition helpers.cpp:44
Application App
Global storage of Application pointer - only one Application can exist.
static void uint32_t