[modem]: Add support for DTE-Tx hooks#1042
Open
david-cermak wants to merge 1 commit intoespressif:masterfrom
Open
[modem]: Add support for DTE-Tx hooks#1042david-cermak wants to merge 1 commit intoespressif:masterfrom
david-cermak wants to merge 1 commit intoespressif:masterfrom
Conversation
94e5116 to
7eae1ac
Compare
7eae1ac to
7f0732c
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 7f0732c. Configure here.
e418b91 to
7df2322
Compare
7df2322 to
3ec901e
Compare
david-cermak
commented
Apr 16, 2026
Comment on lines
+274
to
+278
| #if defined(__cpp_lib_atomic_shared_ptr) | ||
| std::atomic<std::shared_ptr<const TransmitHooks>> transmit_hooks_ {}; /*!< Immutable hook pair */ | ||
| #else | ||
| std::shared_ptr<const TransmitHooks> transmit_hooks_; /*!< Immutable hook pair; use std::atomic_{load,store} */ | ||
| #endif |
Collaborator
Author
There was a problem hiding this comment.
@euripedesrocha Here's my workaround to get atomic load/store with shared_prt<> work across all IDF versions. (atomic_load/store_explicit vs. shared_ptr<>.load is either deprecated or not present)
Perhaps you have a better idea/suggestion how to address this?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Add before/after transmit hooks to DTE so users can toggle a GPIO (DTR / sleep pin) around every UART write; including internal PPP frames, LCP echo-replies, and other traffic that applications cannot wrap today. This enables UART power-save modes (Quectel QSCLK, u-blox UPSV, SIMCom CSCLK, etc.) without silent data loss.
C++ API:
DTE::set_transmit_hooks(before_tx, after_tx)hooks fire in all four DTE write paths (write(uint8_t*,size_t), write(DTE_Command), send(...), and inside command(...))*C API :
esp_modem_set_transmit_hooks(dce, before_tx, after_tx, user_ctx)wraps the C++ hooks with an opaque context pointerPublic terminal factory:
create_uart_terminal()moved from private to public header, enabling C++ users to build custom DTE subclasses without private-include workaroundsFully additive, no breaking changes. When no hooks are registered, overhead is a single null-check per write.
Notes
Note
Medium Risk
Touches core DTE transmit paths and adds callback execution around every write, which could impact timing/concurrency (especially under CMUX) if hooks misbehave, though behavior is additive when hooks are unset.
Overview
Adds before/after transmit hooks to
DTE(set_transmit_hooks) and wraps all DTE transmit paths (command(),write(),write(DTE_Command),send()) so callers can toggle GPIOs around every terminal write, including PPP/data traffic.Exposes
create_uart_terminal()as a public C++ API for building custom DTE subclasses, and adds a C API entrypointesp_modem_set_transmit_hooks()(with opaqueuser_ctx) plus host tests validating hook firing, ordering, and clearing.Reviewed by Cursor Bugbot for commit 3ec901e. Bugbot is set up for automated code reviews on this repo. Configure here.