mirror of
https://github.com/esphome/esphome.git
synced 2026-07-10 08:55:36 +00:00
snprintf
This commit is contained in:
@@ -158,31 +158,32 @@ class ABBWelcomeData {
|
||||
std::array<uint8_t, 12 + MAX_DATA_LENGTH> data_;
|
||||
// Calculate checksum
|
||||
uint8_t calc_cs_() const;
|
||||
// Internal format implementation
|
||||
// Internal format implementation - buffer guaranteed >= FORMAT_BUFFER_SIZE by caller
|
||||
char *format_to_internal_(char *buffer, uint8_t max_print_bytes) const {
|
||||
char *ptr = buffer;
|
||||
char *end = buffer + FORMAT_BUFFER_SIZE;
|
||||
|
||||
uint8_t print_bytes = std::min(this->size(), max_print_bytes);
|
||||
if (print_bytes) {
|
||||
char raw_hex[format_hex_pretty_size(12 + MAX_DATA_LENGTH)];
|
||||
format_hex_pretty_to(raw_hex, this->data_.data(), print_bytes, '.');
|
||||
ptr += sprintf(ptr, "%s ", raw_hex);
|
||||
ptr += snprintf(ptr, end - ptr, "%s ", raw_hex);
|
||||
}
|
||||
|
||||
if (this->is_valid()) {
|
||||
ptr += sprintf(ptr,
|
||||
this->get_three_byte_address() ? "[%06" PRIX32 " %s %06" PRIX32 "] Type: %02X"
|
||||
: "[%04" PRIX32 " %s %04" PRIX32 "] Type: %02X",
|
||||
this->get_source_address(), this->get_retransmission() ? "»" : ">",
|
||||
this->get_destination_address(), this->get_message_type());
|
||||
ptr += snprintf(ptr, end - ptr,
|
||||
this->get_three_byte_address() ? "[%06" PRIX32 " %s %06" PRIX32 "] Type: %02X"
|
||||
: "[%04" PRIX32 " %s %04" PRIX32 "] Type: %02X",
|
||||
this->get_source_address(), this->get_retransmission() ? "»" : ">",
|
||||
this->get_destination_address(), this->get_message_type());
|
||||
if (this->get_data_size()) {
|
||||
char data_hex[format_hex_pretty_size(MAX_DATA_LENGTH)];
|
||||
format_hex_pretty_to(data_hex, this->data_.data() + 5 + 2 * this->get_address_length(), this->get_data_size(),
|
||||
'.');
|
||||
sprintf(ptr, ", Data: %s", data_hex);
|
||||
snprintf(ptr, end - ptr, ", Data: %s", data_hex);
|
||||
}
|
||||
} else {
|
||||
sprintf(ptr, "[Invalid]");
|
||||
snprintf(ptr, end - ptr, "[Invalid]");
|
||||
}
|
||||
|
||||
return buffer;
|
||||
|
||||
Reference in New Issue
Block a user