ESPHome 2026.10.2
Loading...
Searching...
No Matches
serial_proxy.cpp
Go to the documentation of this file.
1#include "serial_proxy.h"
2
3#ifdef USE_SERIAL_PROXY
4
6#include "esphome/core/log.h"
7
8#include <algorithm>
9#include <cinttypes>
10#include "esphome/core/util.h"
11
12#ifdef USE_API
15#endif
16
17#ifdef USE_SERIAL_PROXY_USB_IDENTITY
19#endif
20
22
23static const char *const TAG = "serial_proxy";
24
27
29 // Set up modem control pins if configured
30 if (this->rts_pin_ != nullptr) {
31 this->rts_pin_->setup();
32 this->rts_pin_->digital_write(this->rts_state_);
33 }
34 if (this->dtr_pin_ != nullptr) {
35 this->dtr_pin_->setup();
36 this->dtr_pin_->digital_write(this->dtr_state_);
37 }
38#ifdef USE_API
39 // instance_index_ is fixed at registration time; pre-set it so loop() only needs to update data
41#endif
42#ifdef USE_SERIAL_PROXY_USB_IDENTITY
43 if (this->usb_channel_ != nullptr) {
44 this->usb_channel_->get_parent()->add_on_connection_callback(
45 [this](bool connected) { this->on_usb_connection_changed_(connected); });
46 }
47#endif
48#ifdef USE_SERIAL_PROXY_TAP
49 // A tap sets itself up before this runs (its setup priority is higher), so it may
50 // already be waiting on the port -- a boot-time handshake with the device, say. Leaving
51 // the loop enabled is what lets that finish; without it the tap would stall until a
52 // client happened to subscribe.
53 if (this->tap_ != nullptr && this->tap_->tap_needs_port()) {
54 return;
55 }
56#endif
57 // No subscriber at startup; disable loop until a client subscribes
58 this->disable_loop();
59}
60
61#ifdef USE_SERIAL_PROXY_TAP
63 // The mode belongs to a session, not to the port. Carrying a departed client's choice
64 // over to the next one would inject protocol bytes into a stream that never asked for
65 // them -- a firmware upload, or any client built before this request existed and so
66 // unable to turn it off. Guessing RAW is the safe direction: a client that wanted
67 // protocol handling and did not ask for it merely sends its own acknowledgements.
69 return;
70 }
71 ESP_LOGD(TAG, "Session ended, returning serial proxy [%" PRIu32 "] to RAW mode", this->instance_index_);
73}
74#endif
75
77#ifdef USE_API
78 // Detect subscriber disconnect
79 if (this->api_connection_ != nullptr && (this->api_connection_->is_marked_for_removal() ||
80 !this->api_connection_->is_connection_setup() || !api_is_connected())) {
81 ESP_LOGW(TAG, "Subscriber disconnected");
82 this->api_connection_ = nullptr;
83 this->reset_mode_();
84 }
85
86 // With no subscriber there is normally nothing to do, but a tap may still need the port
87 // read -- it does its protocol work precisely while nobody else is listening.
88 if (this->api_connection_ == nullptr) [[unlikely]] {
89#ifdef USE_SERIAL_PROXY_TAP
90 if (this->tap_ == nullptr || !this->tap_->tap_needs_port()) {
91 this->disable_loop();
92 return;
93 }
94#else
95 this->disable_loop();
96 return;
97#endif
98 }
99
100 // Read available data from UART and forward to subscribed client
101 size_t available = this->available();
102 if (available == 0)
103 return;
104
105 this->read_and_send_(available);
106#endif
107}
108
109#ifdef USE_API
110void __attribute__((noinline)) SerialProxy::read_and_send_(size_t available) {
111 // Read in chunks up to SERIAL_PROXY_MAX_READ_SIZE
113 size_t to_read = std::min(available, sizeof(buffer));
114
115 if (!this->read_array(buffer, to_read))
116 return;
117
118#ifdef USE_SERIAL_PROXY_TAP
119 // Before forwarding, so a tap that answers the device (an acknowledgement, say) is not
120 // waiting on the network round trip to a subscriber that may not even exist.
121 if (this->tap_observing_()) {
122 this->tap_->on_device_rx(buffer, to_read);
123 }
124#endif
125
126 if (this->api_connection_ == nullptr) {
127 return;
128 }
129 this->outgoing_msg_.set_data(buffer, to_read);
131}
132#endif
133
134#ifdef USE_SERIAL_PROXY_TAP
135
137 if (this->tap_ == nullptr) {
138 return false;
139 }
140 // With no subscriber, a tap doing its own protocol work (the boot-time handshake with
141 // the device, say) is served regardless of mode -- nobody has chosen one yet. Once a
142 // subscriber holds the port, the mode alone decides, so RAW stays inert.
143 if (this->api_connection_ == nullptr && this->tap_->tap_needs_port()) {
144 return true;
145 }
146 // Otherwise the mode decides. RAW must be inert: a client that flips to RAW before
147 // flashing firmware is entitled to a byte pipe with nothing injecting protocol bytes
148 // into it, and "the tap turned out not to recognise the stream" is not good enough.
150}
151
153#ifdef USE_API
154 // Nothing would consume the bytes; leave them in the FIFO
155 if (!this->tap_observing_() && this->api_connection_ == nullptr) {
156 return;
157 }
158 const size_t available = this->available();
159 if (available > 0) {
160 this->read_and_send_(available);
161 }
162#endif
163}
164#endif
165
167 ESP_LOGCONFIG(TAG,
168 "Serial Proxy [%" PRIu32 "]:\n"
169 " Name: %s\n"
170 " Port Type: %s\n"
171 " RTS Pin: %s\n"
172 " DTR Pin: %s",
173 this->instance_index_, this->name_ != nullptr ? this->name_ : "",
174 this->port_type_ == api::enums::SERIAL_PROXY_PORT_TYPE_RS485 ? LOG_STR_LITERAL("RS485")
175 : this->port_type_ == api::enums::SERIAL_PROXY_PORT_TYPE_RS232 ? LOG_STR_LITERAL("RS232")
176 : this->port_type_ == api::enums::SERIAL_PROXY_PORT_TYPE_USB_SERIAL ? LOG_STR_LITERAL("USB_SERIAL")
177 : LOG_STR_LITERAL("TTL"),
178 this->rts_pin_ != nullptr ? LOG_STR_LITERAL("configured") : LOG_STR_LITERAL("not configured"),
179 this->dtr_pin_ != nullptr ? LOG_STR_LITERAL("configured") : LOG_STR_LITERAL("not configured"));
180}
181
182SerialProxyResult SerialProxy::configure(api::APIConnection *api_connection, uint32_t baudrate, bool flow_control,
183 uint8_t parity, uint8_t stop_bits, uint8_t data_size) {
184#ifdef USE_API
185 if (!this->is_subscriber_(api_connection)) {
186 ESP_LOGW(TAG, "Ignoring configure request from client without port subscription [%" PRIu32 "]",
187 this->instance_index_);
189 }
190#endif
191 ESP_LOGD(TAG,
192 "Configuring serial proxy [%" PRIu32 "]: baud=%" PRIu32 ", flow_ctrl=%s, parity=%" PRIu8 ", stop=%" PRIu8
193 ", data=%" PRIu8,
194 this->instance_index_, baudrate, YESNO(flow_control), parity, stop_bits, data_size);
195
196 auto *uart_comp = this->parent_;
197 if (uart_comp == nullptr) {
198 ESP_LOGE(TAG, "UART component not available");
200 }
201
202 // Validate all parameters before applying any (values come from a remote client)
203 if (baudrate == 0) {
204 ESP_LOGW(TAG, "Invalid baud rate: 0");
206 }
208 ESP_LOGW(TAG, "Invalid stop bits: %u (must be 1 or 2)", stop_bits);
210 }
211 if (data_size < 5 || data_size > 8) {
212 ESP_LOGW(TAG, "Invalid data bits: %u (must be 5-8)", data_size);
214 }
215 if (parity > 2) {
216 ESP_LOGW(TAG, "Invalid parity: %u (must be 0-2)", parity);
218 }
219 if (flow_control) {
220 ESP_LOGW(TAG, "Hardware flow control requested but is not yet supported");
222 }
223
224 // Skip a no-op reconfigure. Clients routinely re-send identical settings on every
225 // port open, and on a USB UART each apply is a CDC SET_LINE_CODING control transfer.
226 // Some bridges watch line-coding changes as a signalling channel (a magic baud
227 // sequence to enter a bootloader, say), so redundant applies are not harmless.
228 static const uart::UARTParityOptions PARITY_MAP[] = {
232 };
233 if (uart_comp->get_baud_rate() == baudrate && uart_comp->get_stop_bits() == stop_bits &&
234 uart_comp->get_data_bits() == data_size && uart_comp->get_parity() == PARITY_MAP[parity]) {
235 ESP_LOGV(TAG, "Settings unchanged, skipping reconfigure [%" PRIu32 "]", this->instance_index_);
237 }
238
239 // Apply validated parameters
240 uart_comp->set_baud_rate(baudrate);
241 uart_comp->set_stop_bits(stop_bits);
242 uart_comp->set_data_bits(data_size);
243
244 uart_comp->set_parity(PARITY_MAP[parity]);
245
246 // load_settings() is available on ESP8266 and ESP32 platforms
247#if defined(USE_ESP8266) || defined(USE_ESP32)
248 uart_comp->load_settings(true);
249#endif
251}
252
255#ifdef USE_API
256 // Only the live subscriber may change the mode, so the mode cannot outlive a session
257 if (!this->is_subscriber_(api_connection)) {
258 ESP_LOGW(TAG, "Ignoring mode request from client without port subscription [%" PRIu32 "]", this->instance_index_);
260 }
261#endif
262 // Values come from a remote client
264 ESP_LOGW(TAG, "Invalid mode: %" PRIu32, static_cast<uint32_t>(mode));
266 }
267 // PROTOCOL on a port with no tap would be a silent no-op; refuse so the client knows
268#ifdef USE_SERIAL_PROXY_TAP
269 const bool has_tap = this->tap_ != nullptr;
270#else
271 const bool has_tap = false;
272#endif
273 if (mode == api::enums::SERIAL_PROXY_MODE_PROTOCOL && !has_tap) {
274 ESP_LOGW(TAG, "No tap on serial proxy [%" PRIu32 "]; PROTOCOL mode unavailable", this->instance_index_);
276 }
277 ESP_LOGD(TAG, "Serial proxy [%" PRIu32 "] mode set to %s", this->instance_index_,
278 mode == api::enums::SERIAL_PROXY_MODE_PROTOCOL ? LOG_STR_LITERAL("PROTOCOL") : LOG_STR_LITERAL("RAW"));
279#ifdef USE_SERIAL_PROXY_TAP
280 const bool leaving_protocol_mode =
282 this->mode_ = mode;
283
284 // Only for an explicit client request, not for reset_mode_() at the end of a session:
285 // an ordinary disconnect says nothing about the device, whereas a client deliberately
286 // asking for raw bytes usually precedes changing what the device is.
287 if (leaving_protocol_mode && this->tap_ != nullptr) {
288 this->tap_->on_protocol_disabled();
289 }
290#endif
292}
293
294void SerialProxy::write_from_client(api::APIConnection *api_connection, const uint8_t *data, size_t len) {
295#ifdef USE_API
296 // Bytes from anyone but the live subscriber would interleave with the subscriber's
297 // traffic -- or with an active tap's -- on the wire
298 if (!this->is_subscriber_(api_connection)) {
299 if (this->api_connection_ != nullptr) {
300 ESP_LOGW(TAG, "Ignoring write from client that does not hold serial proxy [%" PRIu32 "]", this->instance_index_);
301 } else {
302 // A legacy client streaming writes without subscribing would flood WARN, one per
303 // request; writes are the only high-rate, unacknowledged operation, so keep this
304 // visible without drowning the log
305 ESP_LOGV(TAG, "Ignoring write from client without port subscription [%" PRIu32 "]", this->instance_index_);
306 }
307 return;
308 }
309#endif
310 if (data == nullptr || len == 0)
311 return;
312 // Whatever the driver cannot buffer stalls the main loop for its wire time. At high baud
313 // rates that is brief and losing nothing is worth it; at low ones it would trip the
314 // watchdog, so cap the stall and drop the rest. The cap covers the whole loop pass:
315 // several writes can arrive in one, and each alone might stay under it.
316 const size_t free = this->parent_->available_for_write();
317 bool trimmed = false;
318 if (len > free) {
319 const uint32_t loop_time = App.get_loop_component_start_time();
320 if (loop_time != stall_loop_time) {
321 stall_loop_time = loop_time;
322 stall_spent_ms = 0;
323 }
324 const uint32_t stall_ms = this->wire_time_ms_(len - free);
325 trimmed = stall_spent_ms + stall_ms > SERIAL_PROXY_MAX_WRITE_STALL_MS;
326 if (trimmed && !this->trim_warned_) {
327 ESP_LOGW(TAG,
328 "TX buffer full on serial proxy [%" PRIu32 "]: dropping %zu of %zu bytes (would stall %" PRIu32
329 " ms at %" PRIu32 " baud); raise the UART tx_buffer_size or pace writes",
330 this->instance_index_, len - free, len, stall_ms, this->parent_->get_baud_rate());
331 }
332 if (trimmed) {
333 len = free;
334 } else {
335 stall_spent_ms += stall_ms;
336 }
337 }
338 this->trim_warned_ = trimmed;
339 if (len == 0)
340 return;
341 this->write_array(data, len);
342
343#ifdef USE_SERIAL_PROXY_TAP
344 // After the write, so the tap observes the same ordering the device does
345 if (this->tap_observing_()) {
346 this->tap_->on_client_tx(data, len);
347 }
348#endif
349}
350
352 const uint32_t bits_per_byte = 1 + this->parent_->get_data_bits() + this->parent_->get_stop_bits() +
354 return static_cast<uint64_t>(bytes) * bits_per_byte * 1000 / std::max<uint32_t>(this->parent_->get_baud_rate(), 1);
355}
356
358#ifdef USE_API
359 if (!this->is_subscriber_(api_connection)) {
360 ESP_LOGW(TAG, "Ignoring modem pin request from client without port subscription [%" PRIu32 "]",
361 this->instance_index_);
363 }
364#endif
365 // Asserting a pin that is not configured must fail so the client learns the signal never
366 // reached the wire; deasserting an absent pin is harmless and stays allowed. Clients can
367 // avoid this by masking against SerialProxyInfo.configured_line_states.
368 if ((line_states & ~this->get_configured_modem_pins()) != 0) {
369 ESP_LOGW(TAG, "Requested modem pin not configured on serial proxy [%" PRIu32 "]", this->instance_index_);
371 }
372 const bool rts = (line_states & SERIAL_PROXY_LINE_STATE_FLAG_RTS) != 0;
373 const bool dtr = (line_states & SERIAL_PROXY_LINE_STATE_FLAG_DTR) != 0;
374 ESP_LOGV(TAG, "Setting modem pins [%" PRIu32 "]: RTS=%s, DTR=%s", this->instance_index_, ONOFF(rts), ONOFF(dtr));
375
376 if (this->rts_pin_ != nullptr) {
377 this->rts_state_ = rts;
378 this->rts_pin_->digital_write(rts);
379 }
380 if (this->dtr_pin_ != nullptr) {
381 this->dtr_state_ = dtr;
382 this->dtr_pin_->digital_write(dtr);
383 }
385}
386
387#ifdef USE_API
391 this->fill_identity_(scratch, msg);
392 api_connection->send_serial_proxy_identity(msg);
393}
394
396 msg.instance = this->instance_index_;
397#ifdef USE_SERIAL_PROXY_USB_IDENTITY
398 // The define is global, so a hardware UART port in the same config also gets here
399 if (this->usb_channel_ != nullptr) {
401 // Covers a removed device, a channel the device has no CDC function for and a failed channel setup
402 if (!this->usb_channel_->is_connected()) {
403 return;
404 }
405 auto *client = this->usb_channel_->get_parent();
407 if (!client->get_device_info(scratch)) {
409 return;
410 }
411 msg.usb.vendor_id = scratch.vendor_id;
412 msg.usb.product_id = scratch.product_id;
413 msg.usb.bcd_device = scratch.bcd_device;
417 msg.manufacturer = StringRef(scratch.manufacturer);
418 msg.product = StringRef(scratch.product);
419 msg.serial_number = StringRef(scratch.serial_number);
420 return;
421 }
422#endif
423 // Zero-initialized message: source NONE, no flags
424}
425#endif
426
427#ifdef USE_SERIAL_PROXY_USB_IDENTITY
429 ESP_LOGD(TAG, "USB device %s serial proxy [%" PRIu32 "]",
430 connected ? LOG_STR_LITERAL("attached to") : LOG_STR_LITERAL("removed from"), this->instance_index_);
431#ifdef USE_API
432 if (api::global_api_server == nullptr) {
433 return;
434 }
437 this->fill_identity_(scratch, msg);
439#endif
440}
441#endif
442
444 return (this->rts_state_ ? static_cast<uint32_t>(SERIAL_PROXY_LINE_STATE_FLAG_RTS) : 0u) |
445 (this->dtr_state_ ? static_cast<uint32_t>(SERIAL_PROXY_LINE_STATE_FLAG_DTR) : 0u);
446}
447
449#ifdef USE_API
450 // Flushing stalls the port, so it gets the same ownership check as writes
451 if (!this->is_subscriber_(api_connection)) {
452 ESP_LOGW(TAG, "Ignoring flush from client without port subscription [%" PRIu32 "]", this->instance_index_);
454 }
455#endif
456 ESP_LOGV(TAG, "Flushing serial proxy [%" PRIu32 "]", this->instance_index_);
457 switch (this->flush()) {
466 }
467 return SerialProxyResult::SERIAL_PROXY_RESULT_ERROR; // Unreachable; all enum values handled above
468}
469
470#ifdef USE_API
473 switch (type) {
475 if (this->api_connection_ == api_connection) {
476 ESP_LOGV(TAG, "API connection is already subscribed to serial proxy [%" PRIu32 "]", this->instance_index_);
478 }
479 if (this->api_connection_ != nullptr) {
480 // A living subscriber keeps exclusive access. Its connection may be dead without
481 // loop() having noticed yet (e.g. the client crashed and reconnected quickly);
482 // in that case let the new client take over instead of locking it out.
484 ESP_LOGE(TAG, "Only one API subscription is allowed at a time");
486 }
487 ESP_LOGW(TAG, "Previous subscriber disconnected; taking over subscription");
488 // End the dead client's session before starting the new one, so its mode
489 // cannot leak into a session that never asked for it
490 this->api_connection_ = nullptr;
491 this->reset_mode_();
492 }
493 this->api_connection_ = api_connection;
494 this->enable_loop();
495 ESP_LOGV(TAG, "API connection subscribed to serial proxy [%" PRIu32 "]", this->instance_index_);
498 // Unsubscribe is idempotent: not being subscribed is not an error
499 if (this->api_connection_ != api_connection) {
500 ESP_LOGV(TAG, "API connection is not subscribed to serial proxy [%" PRIu32 "]", this->instance_index_);
502 }
503 this->api_connection_ = nullptr;
504 this->reset_mode_();
505#ifdef USE_SERIAL_PROXY_TAP
506 // Keep the loop alive for a tap that still needs the port (mirrors loop())
507 if (this->tap_ == nullptr || !this->tap_->tap_needs_port()) {
508 this->disable_loop();
509 }
510#else
511 this->disable_loop();
512#endif
513 ESP_LOGV(TAG, "API connection unsubscribed from serial proxy [%" PRIu32 "]", this->instance_index_);
515 default:
516 ESP_LOGW(TAG, "Unknown serial proxy request type: %" PRIu32, static_cast<uint32_t>(type));
518 }
519}
520#endif
521
522} // namespace esphome::serial_proxy
523
524#endif // USE_SERIAL_PROXY
BedjetMode mode
BedJet operating mode.
uint32_t IRAM_ATTR HOT get_loop_component_start_time() const
Get the cached time in milliseconds from when the current component started its loop execution.
void enable_loop()
Enable this component's loop.
Definition component.h:246
void disable_loop()
Disable this component's loop.
virtual void setup()=0
virtual void digital_write(bool value)=0
T * get_parent() const
Get the parent of this object.
Definition helpers.h:2010
StringRef is a reference to a string owned by something else.
Definition string_ref.h:30
void send_serial_proxy_data(const SerialProxyDataReceived &msg)
void send_serial_proxy_identity(const SerialProxyIdentity &msg)
Send a port identity to this client.
void send_serial_proxy_identity(const SerialProxyIdentity &msg)
Tell every subscribed client that a serial proxy port's identity changed.
void set_data(const uint8_t *data, size_t len)
Definition api_pb2.h:3925
enums::SerialProxyIdentitySource source
Definition api_pb2.h:4109
void fill_identity_(IdentityScratch &scratch, api::SerialProxyIdentity &msg) const
Fill an identity message for this port.
SerialProxyResult configure(api::APIConnection *api_connection, uint32_t baudrate, bool flow_control, uint8_t parity, uint8_t stop_bits, uint8_t data_size)
Configure UART parameters and apply them.
void read_and_send_(size_t available)
Read from UART, hand the bytes to any tap, and forward them to a subscriber (slow path with a 256-byt...
api::enums::SerialProxyMode mode_
How the bytes passing through are treated; zero is SERIAL_PROXY_MODE_RAW.
SerialProxyResult serial_proxy_request(api::APIConnection *api_connection, api::enums::SerialProxyRequestType type)
Handle a subscribe/unsubscribe request from an API client.
uint32_t get_modem_pins() const
Get current modem pin states as a bitmask of SerialProxyLineStateFlag values.
uint32_t instance_index_
Instance index for identifying this proxy in API messages.
bool trim_warned_
Set while writes are being trimmed, so a client streaming into a slow port warns once.
bool rts_state_
Current modem pin states.
SerialProxyResult flush_port(api::APIConnection *api_connection)
Flush the serial port (block until all TX data is sent)
uint32_t get_configured_modem_pins() const
Get the modem pins this instance can drive as a bitmask of SerialProxyLineStateFlag values.
api::SerialProxyDataReceived outgoing_msg_
Pre-allocated outgoing message; instance field is set once in setup()
const char * name_
Human-readable port name (points to a string literal in flash)
api::enums::SerialProxyPortType port_type_
Port type.
GPIOPin * rts_pin_
Optional GPIO pins for modem control.
usb_uart::USBUartChannel * usb_channel_
The USB UART channel behind this port; nullptr on non-USB ports.
void on_usb_connection_changed_(bool connected)
The USB device behind this port was attached or removed; report the port's new identity to every subs...
bool tap_observing_() const
True when the tap should be shown the traffic passing through this port.
SerialProxyResult set_modem_pins(api::APIConnection *api_connection, uint32_t line_states)
Set modem pin states from a bitmask of SerialProxyLineStateFlag values.
SerialProxyResult set_mode_from_client(api::APIConnection *api_connection, api::enums::SerialProxyMode mode)
Handle a mode change requested by an API client.
void write_from_client(api::APIConnection *api_connection, const uint8_t *data, size_t len)
Write data received from an API client to the serial device.
static uint32_t stall_loop_time
Stall spent by writes in the current loop pass, keyed by the pass's cached start time.
bool is_subscriber_(api::APIConnection *api_connection) const
True when the given connection is the live subscriber.
void tap_pump()
Run one read-and-dispatch cycle immediately.
void send_identity(api::APIConnection *api_connection)
Send this port's identity to one client.
void reset_mode_()
Return the port to RAW when a subscriber goes away, so the mode never outlives it.
api::APIConnection * api_connection_
Subscribed API client (only one allowed at a time)
uint32_t wire_time_ms_(size_t bytes) const
Time the wire needs for the given number of bytes at the current framing.
virtual bool tap_needs_port() const =0
True when the port must keep reading even with no subscriber attached, so a tap can do its own protoc...
virtual void on_device_rx(const uint8_t *data, size_t len)=0
Bytes read from the device, before they are forwarded to any subscriber.
virtual void on_client_tx(const uint8_t *data, size_t len)=0
Bytes a subscriber sent towards the device, after they have been written.
virtual void on_protocol_disabled()=0
A client explicitly turned protocol handling off for this port.
UARTParityOptions get_parity() const
void set_baud_rate(uint32_t baud_rate)
virtual size_t available_for_write()
UARTFlushResult flush()
Definition uart.h:50
optional< std::array< uint8_t, N > > read_array()
Definition uart.h:39
UARTComponent * parent_
Definition uart.h:76
void write_array(const uint8_t *data, size_t len)
Definition uart.h:27
uint8_t UARTParityOptions parity
Definition uart.h:73
uint8_t get_interface_class() const
bInterfaceClass of the interface get_interface_number() names
Definition usb_uart.h:193
uint8_t get_port_number() const
Index of this port among the ports on its interface.
Definition usb_uart.h:200
uint8_t get_interface_number() const
USB interface number a host driver binds to for this channel: the communication interface of a CDC AC...
Definition usb_uart.h:187
struct @66::@67 __attribute__
Wake the main loop task from an ISR. ISR-safe.
Definition main_task.h:45
uint16_t type
uint32_t buffer
Definition gif.cpp:50
@ SERIAL_PROXY_PORT_TYPE_RS232
Definition api_pb2.h:24
@ SERIAL_PROXY_PORT_TYPE_RS485
Definition api_pb2.h:25
@ SERIAL_PROXY_PORT_TYPE_USB_SERIAL
Definition api_pb2.h:26
@ SERIAL_PROXY_REQUEST_TYPE_UNSUBSCRIBE
Definition api_pb2.h:356
@ SERIAL_PROXY_REQUEST_TYPE_SUBSCRIBE
Definition api_pb2.h:355
@ SERIAL_PROXY_IDENTITY_FLAG_CONNECTED
Definition api_pb2.h:383
@ SERIAL_PROXY_IDENTITY_FLAG_ERROR
Definition api_pb2.h:384
@ SERIAL_PROXY_IDENTITY_SOURCE_USB
Definition api_pb2.h:378
APIServer * global_api_server
@ SERIAL_PROXY_LINE_STATE_FLAG_RTS
RTS (Request To Send)
@ SERIAL_PROXY_LINE_STATE_FLAG_DTR
DTR (Data Terminal Ready)
SerialProxyResult
Result of a client-initiated operation; mapped to api::enums::SerialProxyStatus by the API layer.
@ SERIAL_PROXY_RESULT_TIMEOUT
Timed out before TX completed.
@ SERIAL_PROXY_RESULT_ERROR
Driver or hardware error.
@ SERIAL_PROXY_RESULT_NOT_SUPPORTED
Requested feature is not available on this instance.
@ SERIAL_PROXY_RESULT_PORT_IN_USE
Denied: another live client holds the port.
@ SERIAL_PROXY_RESULT_OK
Operation completed or request accepted.
@ SERIAL_PROXY_RESULT_INVALID_ARGUMENT
A parameter value is out of range.
@ SERIAL_PROXY_RESULT_ASSUMED_SUCCESS
Platform cannot confirm TX drain; success assumed.
constexpr size_t SERIAL_PROXY_MAX_READ_SIZE
Maximum bytes to read from UART in a single loop iteration.
constexpr uint32_t SERIAL_PROXY_MAX_WRITE_STALL_MS
Longest main-loop stall client writes may cause per loop pass, shared by every instance; bytes the UA...
@ UART_FLUSH_RESULT_ASSUMED_SUCCESS
Platform cannot report result; success is assumed.
@ UART_FLUSH_RESULT_SUCCESS
Confirmed: all bytes left the TX FIFO.
@ UART_FLUSH_RESULT_FAILED
Confirmed: driver or hardware error.
@ UART_FLUSH_RESULT_TIMEOUT
Confirmed: timed out before TX completed.
const void size_t len
Definition hal.h:64
ESPHOME_ALWAYS_INLINE bool api_is_connected()
Return whether the node has at least one client connected to the native API.
Definition util.h:20
Application App
Global storage of Application pointer - only one Application can exist.
static void uint32_t
watchdog_hw scratch[0]