Home IO Control
ESPHome add-on for IO-Homecontrol devices
Loading...
Searching...
No Matches
log_frame.h
Go to the documentation of this file.
1#pragma once
2
3/// @file log_frame.h
4/// @brief Shared frame logging helpers for IO-Homecontrol.
5
6#include "esphome/core/log.h"
7#include <cstddef>
8#include <cstdint>
9#include <cstdio>
10
11namespace esphome {
12namespace home_io_control {
13
14inline constexpr size_t FRAME_LOG_HEX_BUFFER_SIZE = 220; ///< Fits a full 32-byte frame rendered as spaced hex text.
15
16inline void bytes_to_hex(const uint8_t *data, uint8_t len, char *out, size_t out_size) {
17 size_t pos = 0;
18 if (out_size == 0)
19 return;
20 out[0] = '\0';
21 for (uint8_t i = 0; i < len && pos + 4 < out_size; i++)
22 pos += snprintf(out + pos, out_size - pos, "%02X ", data[i]);
23}
24
25#ifdef IOHOME_FRAME_LOG
26inline void log_frame(const char *prefix, const uint8_t *data, uint8_t len, uint32_t freq, uint16_t preamble = 0) {
28 bytes_to_hex(data, len, hex, sizeof(hex));
29 if (preamble > 0)
30 ESP_LOGI("io_frame", "%s [%u bytes] freq=%u preamble=%u: %s", prefix, len, freq, preamble, hex);
31 else
32 ESP_LOGI("io_frame", "%s [%u bytes] freq=%u: %s", prefix, len, freq, hex);
33}
34#endif
35
36} // namespace home_io_control
37} // namespace esphome
void bytes_to_hex(const uint8_t *data, uint8_t len, char *out, size_t out_size)
Definition log_frame.h:16
constexpr size_t FRAME_LOG_HEX_BUFFER_SIZE
Fits a full 32-byte frame rendered as spaced hex text.
Definition log_frame.h:14