mirror of
https://github.com/esphome/esphome.git
synced 2026-08-22 22:26:21 +00:00
[ld24xx] Use MAC address size constants instead of literals (#18253)
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "esphome/core/application.h"
|
#include "esphome/core/application.h"
|
||||||
|
#include "esphome/core/helpers.h"
|
||||||
|
|
||||||
namespace esphome::ld2410 {
|
namespace esphome::ld2410 {
|
||||||
|
|
||||||
@@ -178,7 +179,7 @@ static inline bool validate_header_footer(const uint8_t *header_footer, const ui
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LD2410Component::dump_config() {
|
void LD2410Component::dump_config() {
|
||||||
char mac_s[18];
|
char mac_s[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
|
||||||
char version_s[20];
|
char version_s[20];
|
||||||
const char *mac_str = ld24xx::format_mac_str(this->mac_address_, mac_s);
|
const char *mac_str = ld24xx::format_mac_str(this->mac_address_, mac_s);
|
||||||
ld24xx::format_version_str(this->version_, version_s);
|
ld24xx::format_version_str(this->version_, version_s);
|
||||||
@@ -511,7 +512,7 @@ bool LD2410Component::handle_ack_data_() {
|
|||||||
std::memcpy(this->mac_address_, &this->buffer_data_[10], sizeof(this->mac_address_));
|
std::memcpy(this->mac_address_, &this->buffer_data_[10], sizeof(this->mac_address_));
|
||||||
}
|
}
|
||||||
|
|
||||||
char mac_s[18];
|
char mac_s[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
|
||||||
const char *mac_str = ld24xx::format_mac_str(this->mac_address_, mac_s);
|
const char *mac_str = ld24xx::format_mac_str(this->mac_address_, mac_s);
|
||||||
ESP_LOGV(TAG, "MAC address: %s", mac_str);
|
ESP_LOGV(TAG, "MAC address: %s", mac_str);
|
||||||
#ifdef USE_TEXT_SENSOR
|
#ifdef USE_TEXT_SENSOR
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ class LD2410Component final : public Component, public uart::UARTDevice {
|
|||||||
uint8_t out_pin_level_ = 0;
|
uint8_t out_pin_level_ = 0;
|
||||||
uint8_t buffer_pos_ = 0; // where to resume processing/populating buffer
|
uint8_t buffer_pos_ = 0; // where to resume processing/populating buffer
|
||||||
uint8_t buffer_data_[MAX_LINE_LENGTH];
|
uint8_t buffer_data_[MAX_LINE_LENGTH];
|
||||||
uint8_t mac_address_[6] = {0, 0, 0, 0, 0, 0};
|
uint8_t mac_address_[MAC_ADDRESS_SIZE] = {0, 0, 0, 0, 0, 0};
|
||||||
uint8_t version_[6] = {0, 0, 0, 0, 0, 0};
|
uint8_t version_[6] = {0, 0, 0, 0, 0, 0};
|
||||||
bool bluetooth_on_{false};
|
bool bluetooth_on_{false};
|
||||||
#ifdef USE_NUMBER
|
#ifdef USE_NUMBER
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ static inline bool validate_header_footer(const uint8_t *header_footer, const ui
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LD2412Component::dump_config() {
|
void LD2412Component::dump_config() {
|
||||||
char mac_s[18];
|
char mac_s[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
|
||||||
char version_s[20];
|
char version_s[20];
|
||||||
const char *mac_str = ld24xx::format_mac_str(this->mac_address_, mac_s);
|
const char *mac_str = ld24xx::format_mac_str(this->mac_address_, mac_s);
|
||||||
ld24xx::format_version_str(this->version_, version_s);
|
ld24xx::format_version_str(this->version_, version_s);
|
||||||
@@ -555,7 +555,7 @@ bool LD2412Component::handle_ack_data_() {
|
|||||||
std::memcpy(this->mac_address_, &this->buffer_data_[10], sizeof(this->mac_address_));
|
std::memcpy(this->mac_address_, &this->buffer_data_[10], sizeof(this->mac_address_));
|
||||||
}
|
}
|
||||||
|
|
||||||
char mac_s[18];
|
char mac_s[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
|
||||||
const char *mac_str = ld24xx::format_mac_str(this->mac_address_, mac_s);
|
const char *mac_str = ld24xx::format_mac_str(this->mac_address_, mac_s);
|
||||||
ESP_LOGV(TAG, "MAC address: %s", mac_str);
|
ESP_LOGV(TAG, "MAC address: %s", mac_str);
|
||||||
#ifdef USE_TEXT_SENSOR
|
#ifdef USE_TEXT_SENSOR
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ class LD2412Component final : public Component, public uart::UARTDevice {
|
|||||||
uint8_t out_pin_level_ = 0;
|
uint8_t out_pin_level_ = 0;
|
||||||
uint8_t buffer_pos_ = 0; // where to resume processing/populating buffer
|
uint8_t buffer_pos_ = 0; // where to resume processing/populating buffer
|
||||||
uint8_t buffer_data_[MAX_LINE_LENGTH];
|
uint8_t buffer_data_[MAX_LINE_LENGTH];
|
||||||
uint8_t mac_address_[6] = {0, 0, 0, 0, 0, 0};
|
uint8_t mac_address_[MAC_ADDRESS_SIZE] = {0, 0, 0, 0, 0, 0};
|
||||||
uint8_t version_[6] = {0, 0, 0, 0, 0, 0};
|
uint8_t version_[6] = {0, 0, 0, 0, 0, 0};
|
||||||
bool bluetooth_on_{false};
|
bool bluetooth_on_{false};
|
||||||
bool dynamic_background_correction_active_{false};
|
bool dynamic_background_correction_active_{false};
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ void LD2450Component::setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LD2450Component::dump_config() {
|
void LD2450Component::dump_config() {
|
||||||
char mac_s[18];
|
char mac_s[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
|
||||||
char version_s[20];
|
char version_s[20];
|
||||||
const char *mac_str = ld24xx::format_mac_str(this->mac_address_, mac_s);
|
const char *mac_str = ld24xx::format_mac_str(this->mac_address_, mac_s);
|
||||||
ld24xx::format_version_str(this->version_, version_s);
|
ld24xx::format_version_str(this->version_, version_s);
|
||||||
@@ -680,7 +680,7 @@ bool LD2450Component::handle_ack_data_() {
|
|||||||
std::memcpy(this->mac_address_, &this->buffer_data_[10], sizeof(this->mac_address_));
|
std::memcpy(this->mac_address_, &this->buffer_data_[10], sizeof(this->mac_address_));
|
||||||
}
|
}
|
||||||
|
|
||||||
char mac_s[18];
|
char mac_s[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
|
||||||
const char *mac_str = ld24xx::format_mac_str(this->mac_address_, mac_s);
|
const char *mac_str = ld24xx::format_mac_str(this->mac_address_, mac_s);
|
||||||
ESP_LOGV(TAG, "MAC address: %s", mac_str);
|
ESP_LOGV(TAG, "MAC address: %s", mac_str);
|
||||||
#ifdef USE_TEXT_SENSOR
|
#ifdef USE_TEXT_SENSOR
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ class LD2450Component : public Component, public uart::UARTDevice {
|
|||||||
uint32_t moving_presence_millis_ = 0;
|
uint32_t moving_presence_millis_ = 0;
|
||||||
uint32_t timeout_ = 5;
|
uint32_t timeout_ = 5;
|
||||||
uint8_t buffer_data_[MAX_LINE_LENGTH];
|
uint8_t buffer_data_[MAX_LINE_LENGTH];
|
||||||
uint8_t mac_address_[6] = {0, 0, 0, 0, 0, 0};
|
uint8_t mac_address_[MAC_ADDRESS_SIZE] = {0, 0, 0, 0, 0, 0};
|
||||||
uint8_t version_[6] = {0, 0, 0, 0, 0, 0};
|
uint8_t version_[6] = {0, 0, 0, 0, 0, 0};
|
||||||
uint8_t buffer_pos_ = 0; // where to resume processing/populating buffer
|
uint8_t buffer_pos_ = 0; // where to resume processing/populating buffer
|
||||||
uint8_t zone_type_ = 0;
|
uint8_t zone_type_ = 0;
|
||||||
|
|||||||
@@ -45,8 +45,7 @@ static const char *const VERSION_FMT = "%u.%02X.%02X%02X%02X%02X";
|
|||||||
|
|
||||||
// Helper function to format MAC address with stack allocation
|
// Helper function to format MAC address with stack allocation
|
||||||
// Returns pointer to UNKNOWN_MAC constant or formatted buffer
|
// Returns pointer to UNKNOWN_MAC constant or formatted buffer
|
||||||
// Buffer must be exactly 18 bytes (17 for "XX:XX:XX:XX:XX:XX" + null terminator)
|
inline const char *format_mac_str(const uint8_t *mac_address, std::span<char, MAC_ADDRESS_PRETTY_BUFFER_SIZE> buffer) {
|
||||||
inline const char *format_mac_str(const uint8_t *mac_address, std::span<char, 18> buffer) {
|
|
||||||
if (mac_address_is_valid(mac_address)) {
|
if (mac_address_is_valid(mac_address)) {
|
||||||
format_mac_addr_upper(mac_address, buffer.data());
|
format_mac_addr_upper(mac_address, buffer.data());
|
||||||
return buffer.data();
|
return buffer.data();
|
||||||
|
|||||||
Reference in New Issue
Block a user