From b83f7b8e16e3e88bb182e39579272d094f7be67b Mon Sep 17 00:00:00 2001 From: Jonas Rabenstein Date: Sat, 27 Dec 2025 20:52:21 +0100 Subject: [PATCH] fixup! use esphome::crc16 --- components/brmesh/network.cpp | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/components/brmesh/network.cpp b/components/brmesh/network.cpp index b0e68f1..9f39e33 100644 --- a/components/brmesh/network.cpp +++ b/components/brmesh/network.cpp @@ -65,17 +65,6 @@ uint8_t crc(const std::span &bytes, uint8_t init = 0x00) { return init; } -uint16_t crc16(const std::span &data, const uint16_t seed = 0xFFFF) { - return ~esphome::crc16( - data.data(), - data.size(), - seed, - 0x1021, - true, // refin - true // refout - ); -} - std::span inner(const std::span &buffer, Light::Id id, const std::span &light_data) { if (id.kind() != 'L') return {}; @@ -169,13 +158,17 @@ std::span payload(const std::span &buffer, const Key &key, Lig if (result.empty()) return {}; + const auto crc_guarded = subspan(buffer, prefix.size(), address.size() + command.size()); + if (crc_guarded.empty()) + return {}; + // static values std::copy(PREFIX.cbegin(), PREFIX.cend(), prefix.begin()); // copy std::copy(ADDRESS.cbegin(), ADDRESS.cend(), address.begin()); - uint16_t crc_value = crc16(buffer.subspan(prefix.size(), address.size() + command.size())); + uint16_t crc_value = ~crc16(&crc_guarded[0], crc_guarded.size(), 0xFFFF, true, true); crc[0] = crc_value; crc[1] = crc_value >> 8;