[serial_proxy] Compile out mode state in builds without a tap

PROTOCOL is refused when no tap exists, so mode_ could never leave RAW
there; gate the member and reset_mode_() behind USE_SERIAL_PROXY_TAP
(no-op inline otherwise), saving the member and the four reset calls in
every tapless build.
This commit is contained in:
kbx81
2026-09-03 01:16:55 -05:00
parent 82675a2c78
commit c432ab146f
2 changed files with 11 additions and 4 deletions
@@ -43,6 +43,7 @@ void SerialProxy::setup() {
this->disable_loop();
}
#ifdef USE_SERIAL_PROXY_TAP
void SerialProxy::reset_mode_() {
// The mode belongs to a session, not to the port. Carrying a departed client's choice
// over to the next one would inject protocol bytes into a stream that never asked for
@@ -55,6 +56,7 @@ void SerialProxy::reset_mode_() {
ESP_LOGD(TAG, "Session ended, returning serial proxy [%" PRIu32 "] to RAW mode", this->instance_index_);
this->mode_ = api::enums::SERIAL_PROXY_MODE_RAW;
}
#endif
void SerialProxy::loop() {
#ifdef USE_API
@@ -261,10 +263,8 @@ SerialProxyResult SerialProxy::set_mode_from_client(api::APIConnection *api_conn
#ifdef USE_SERIAL_PROXY_TAP
const bool leaving_protocol_mode =
this->mode_ != api::enums::SERIAL_PROXY_MODE_RAW && mode == api::enums::SERIAL_PROXY_MODE_RAW;
#endif
this->mode_ = mode;
#ifdef USE_SERIAL_PROXY_TAP
// Only for an explicit client request, not for reset_mode_() at the end of a session:
// an ordinary disconnect says nothing about the device, whereas a client deliberately
// asking for raw bytes usually precedes changing what the device is.
@@ -204,9 +204,14 @@ class SerialProxy final : public uart::UARTDevice, public Component {
bool is_subscriber_(api::APIConnection *api_connection) const { return this->api_connection_ == api_connection; }
#endif
/// Return the port to RAW when a subscriber goes away, so the mode never outlives it.
/// Not tap-gated: the mode is a client-visible property whether or not a tap acts on it.
#ifdef USE_SERIAL_PROXY_TAP
/// Return the port to RAW when a subscriber goes away, so the mode never outlives it
void reset_mode_();
#else
/// Without a tap, PROTOCOL is refused, so the mode is fixed at RAW and there is
/// nothing to reset
void reset_mode_() {}
#endif
#ifdef USE_SERIAL_PROXY_TAP
/// True when the tap should be shown the traffic passing through this port
@@ -230,8 +235,10 @@ class SerialProxy final : public uart::UARTDevice, public Component {
/// Port type
api::enums::SerialProxyPortType port_type_{};
#ifdef USE_SERIAL_PROXY_TAP
/// How the bytes passing through are treated; zero is SERIAL_PROXY_MODE_RAW
api::enums::SerialProxyMode mode_{};
#endif
/// Optional GPIO pins for modem control
GPIOPin *rts_pin_{nullptr};