ESPHome 2025.12.4
Loading...
Searching...
No Matches
uart_debugger.h
Go to the documentation of this file.
1#pragma once
3#ifdef USE_UART_DEBUGGER
4
5#include <vector>
8#include "uart.h"
9#include "uart_component.h"
10
11namespace esphome::uart {
12
20class UARTDebugger : public Component, public Trigger<UARTDirection, std::vector<uint8_t>> {
21 public:
22 explicit UARTDebugger(UARTComponent *parent);
23 void loop() override;
24
29
32 void set_after_bytes(size_t size) { this->after_bytes_ = size; }
33
36 void set_after_timeout(uint32_t timeout) { this->after_timeout_ = timeout; }
37
42 void add_delimiter_byte(uint8_t byte) { this->after_delimiter_.push_back(byte); }
43
44 protected:
47 std::vector<uint8_t> bytes_{};
50 uint32_t last_time_{};
51 std::vector<uint8_t> after_delimiter_{};
53 bool is_triggering_{false};
54
56 bool is_recursive_();
57 void store_byte_(UARTDirection direction, uint8_t byte);
59 void trigger_after_delimiter_(uint8_t byte);
63 void fire_trigger_();
64};
65
72class UARTDummyReceiver : public Component, public UARTDevice {
73 public:
75 void loop() override;
76};
77
80class UARTDebug {
81 public:
84 static void log_hex(UARTDirection direction, std::vector<uint8_t> bytes, uint8_t separator);
85
87 static void log_string(UARTDirection direction, std::vector<uint8_t> bytes);
88
91 static void log_int(UARTDirection direction, std::vector<uint8_t> bytes, uint8_t separator);
92
95 static void log_binary(UARTDirection direction, std::vector<uint8_t> bytes, uint8_t separator);
96};
97
98} // namespace esphome::uart
99#endif
This class contains some static methods, that can be used to easily create a logging action for the d...
static void log_hex(UARTDirection direction, std::vector< uint8_t > bytes, uint8_t separator)
Log the bytes as hex values, separated by the provided separator character.
static void log_binary(UARTDirection direction, std::vector< uint8_t > bytes, uint8_t separator)
Log the bytes as '<binary> (<hex>)' values, separated by the provided separator.
static void log_string(UARTDirection direction, std::vector< uint8_t > bytes)
Log the bytes as string values, escaping unprintable characters.
static void log_int(UARTDirection direction, std::vector< uint8_t > bytes, uint8_t separator)
Log the bytes as integer values, separated by the provided separator character.
The UARTDebugger class adds debugging support to a UART bus.
void store_byte_(UARTDirection direction, uint8_t byte)
void set_after_timeout(uint32_t timeout)
Set a timeout for the data stream.
bool is_my_direction_(UARTDirection direction)
void add_delimiter_byte(uint8_t byte)
Add a delimiter byte.
void trigger_after_direction_change_(UARTDirection direction)
void set_direction(UARTDirection direction)
Set the direction in which to inspect the bytes: incoming, outgoing or both.
void set_after_bytes(size_t size)
Set the maximum number of bytes to accumulate.
std::vector< uint8_t > bytes_
std::vector< uint8_t > after_delimiter_
void trigger_after_delimiter_(uint8_t byte)
UARTDebugger(UARTComponent *parent)
This UARTDevice is used by the serial debugger to read data from a serial interface when the 'dummy_r...
UARTDummyReceiver(UARTComponent *parent)
FanDirection direction
Definition fan.h:3