fixup! use esphome::crc16

This commit is contained in:
Jonas Rabenstein 2025-12-27 20:52:21 +01:00
commit b83f7b8e16

View file

@ -65,17 +65,6 @@ uint8_t crc(const std::span<uint8_t, size> &bytes, uint8_t init = 0x00) {
return init; return init;
} }
uint16_t crc16(const std::span<const uint8_t> &data, const uint16_t seed = 0xFFFF) {
return ~esphome::crc16(
data.data(),
data.size(),
seed,
0x1021,
true, // refin
true // refout
);
}
std::span<uint8_t> inner(const std::span<uint8_t> &buffer, Light::Id id, const std::span<uint8_t> &light_data) { std::span<uint8_t> inner(const std::span<uint8_t> &buffer, Light::Id id, const std::span<uint8_t> &light_data) {
if (id.kind() != 'L') if (id.kind() != 'L')
return {}; return {};
@ -169,13 +158,17 @@ std::span<uint8_t> payload(const std::span<uint8_t> &buffer, const Key &key, Lig
if (result.empty()) if (result.empty())
return {}; return {};
const auto crc_guarded = subspan(buffer, prefix.size(), address.size() + command.size());
if (crc_guarded.empty())
return {};
// static values // static values
std::copy(PREFIX.cbegin(), PREFIX.cend(), prefix.begin()); std::copy(PREFIX.cbegin(), PREFIX.cend(), prefix.begin());
// copy // copy
std::copy(ADDRESS.cbegin(), ADDRESS.cend(), address.begin()); 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[0] = crc_value;
crc[1] = crc_value >> 8; crc[1] = crc_value >> 8;