ESPHome 2025.5.0
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 {
12namespace uart {
13
21class UARTDebugger : public Component, public Trigger<UARTDirection, std::vector<uint8_t>> {
22 public:
23 explicit UARTDebugger(UARTComponent *parent);
24 void loop() override;
25
30
33 void set_after_bytes(size_t size) { this->after_bytes_ = size; }
34
37 void set_after_timeout(uint32_t timeout) { this->after_timeout_ = timeout; }
38
43 void add_delimiter_byte(uint8_t byte) { this->after_delimiter_.push_back(byte); }
44
45 protected:
48 std::vector<uint8_t> bytes_{};
51 uint32_t last_time_{};
52 std::vector<uint8_t> after_delimiter_{};
54 bool is_triggering_{false};
55
57 bool is_recursive_();
58 void store_byte_(UARTDirection direction, uint8_t byte);
60 void trigger_after_delimiter_(uint8_t byte);
64 void fire_trigger_();
65};
66
73class UARTDummyReceiver : public Component, public UARTDevice {
74 public:
76 void loop() override;
77};
78
81class UARTDebug {
82 public:
85 static void log_hex(UARTDirection direction, std::vector<uint8_t> bytes, uint8_t separator);
86
88 static void log_string(UARTDirection direction, std::vector<uint8_t> bytes);
89
92 static void log_int(UARTDirection direction, std::vector<uint8_t> bytes, uint8_t separator);
93
96 static void log_binary(UARTDirection direction, std::vector<uint8_t> bytes, uint8_t separator);
97};
98
99} // namespace uart
100} // namespace esphome
101#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
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7