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/// @ingroup hioc_protocol
6
7#include "esphome/core/log.h"
8#include <cstddef>
9#include <cstdint>
10#include <cstdio>
11
12namespace esphome {
13namespace home_io_control {
14
15inline constexpr size_t FRAME_LOG_HEX_BUFFER_SIZE = 220; ///< Fits a full 32-byte frame rendered as spaced hex text.
16
17inline void bytes_to_hex(const uint8_t *data, uint8_t len, char *out, size_t out_size) {
18 size_t pos = 0;
19 if (out_size == 0)
20 return;
21 out[0] = '\0';
22 for (uint8_t i = 0; i < len && pos + 4 < out_size; i++)
23 pos += snprintf(out + pos, out_size - pos, "%02X ", data[i]);
24}
25
26#ifdef IOHOME_FRAME_LOG
27inline void log_frame(const char *prefix, const uint8_t *data, uint8_t len, uint32_t freq, uint16_t preamble = 0) {
29 bytes_to_hex(data, len, hex, sizeof(hex));
30 if (preamble > 0)
31 ESP_LOGI("io_frame", "%s [%u bytes] freq=%u preamble=%u: %s", prefix, len, freq, preamble, hex);
32 else
33 ESP_LOGI("io_frame", "%s [%u bytes] freq=%u: %s", prefix, len, freq, hex);
34}
35#endif
36
37} // namespace home_io_control
38} // namespace esphome
void bytes_to_hex(const uint8_t *data, uint8_t len, char *out, size_t out_size)
Definition log_frame.h:17
constexpr size_t FRAME_LOG_HEX_BUFFER_SIZE
Fits a full 32-byte frame rendered as spaced hex text.
Definition log_frame.h:15