diff --git a/esphome/components/packet_interface/packet_interface.h b/esphome/components/packet_interface/packet_interface.h index c44955a98a9..e2948da3d5f 100644 --- a/esphome/components/packet_interface/packet_interface.h +++ b/esphome/components/packet_interface/packet_interface.h @@ -44,8 +44,8 @@ class PacketMetaData { * * The operations defined are: * - * Transmit: the function transmit() takes a PacketBuffer of bytes, and returns when all bytes are queued for - * transmission at least. + * Transmit: the function send_to_interface() takes a PacketBuffer of bytes, and returns when all data is + * written or buffered for transmission. * * Receive: The callbacks for an instance of this class are called with currently received data. */ @@ -119,7 +119,7 @@ class PacketInterface : public Component { lower->upper_ = this; this->inherit_from_(lower, capability); } - /// Takes the name and capabilities of \p lower without becoming its top, for one of several stacks on a link. + /// Takes the name and capabilities of `lower` without becoming its top, for one of several stacks on a link. void inherit_from_(PacketInterface *lower, Capability capability) { this->name_ = lower->name_; this->capabilities_ = lower->capabilities_ | capability; diff --git a/esphome/components/packet_interface/packet_transport/packet_interface_transport.cpp b/esphome/components/packet_interface/packet_transport/packet_interface_transport.cpp index 0bc25ead875..ab779d03042 100644 --- a/esphome/components/packet_interface/packet_transport/packet_interface_transport.cpp +++ b/esphome/components/packet_interface/packet_transport/packet_interface_transport.cpp @@ -13,19 +13,12 @@ void PacketInterfaceTransport::setup() { } void PacketInterfaceTransport::receive_(const PacketBuffer &data) { - if (data.is_contiguous()) { - this->process_(data.as_span()); + // Packet interface layers deliver packets in one piece + if (!data.is_contiguous()) { + ESP_LOGW(TAG, "Packet split across buffers is not supported"); return; } - size_t max_size = this->interface_->get_max_packet_size(); - if (data.size() > max_size) { - ESP_LOGW(TAG, "Received packet of %zu bytes is larger than %zu", data.size(), max_size); - return; - } - if (!this->rx_copy_) - this->rx_copy_ = std::make_unique(max_size); - size_t len = data.copy_to(this->rx_copy_.get(), max_size); - this->process_(std::span(this->rx_copy_.get(), len)); + this->process_(data.as_span()); } void PacketInterfaceTransport::send_packet(const std::vector &buf) const { diff --git a/tests/components/packet_interface/packet_buffer.cpp b/tests/components/packet_interface/packet_buffer.cpp index 43dda616240..8605880373b 100644 --- a/tests/components/packet_interface/packet_buffer.cpp +++ b/tests/components/packet_interface/packet_buffer.cpp @@ -3,9 +3,7 @@ #include #include "esphome/components/packet_interface/packet_buffer.h" -namespace esphome { -namespace packet_interface { -namespace testing { +namespace esphome::packet_interface::testing { // Test default constructor TEST(PacketBufferTest, DefaultConstructor) { @@ -243,6 +241,4 @@ TEST(PacketBufferTest, LargeBuffer) { EXPECT_EQ(buffer[999], 231); // 999 % 256 = 231 } -} // namespace testing -} // namespace packet_interface -} // namespace esphome +} // namespace esphome::packet_interface::testing