Add configurable transmit delay via set_transmit_delay() - #31
Open
brocci wants to merge 1 commit into
Open
Conversation
brocci
force-pushed
the
add-transmit-delay-setter
branch
from
August 15, 2026 17:37
f98fceb to
45c8e70
Compare
brocci
force-pushed
the
add-transmit-delay-setter
branch
from
August 15, 2026 17:45
45c8e70 to
4e23f99
Compare
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.
Summary
While the v1.7.x library now supports INIT messages and allow for an init handler, it lacks a way to set the transmit delay.
NMRA CMRInet (LCS-9.10.1) specifies a per-character transmission delay derived from the dH/dL bytes in the INIT message. Each unit represents 10 microseconds. Modern hosts set dH/dL to zero; non-zero values are for legacy compatibility with older Host computers.
The library hardcodes
delayMicroseconds(50)intransmit()as an RS-485 turnaround delay, regardless of the commanded dH/dL value.This PR adds a
set_transmit_delay()method and a compile-time default via#define TRANSMIT_DELAY_US, allowing sketches to configure the turnaround delay. Sketches can parse dH/dL in an init handler and apply the delay automatically for legacy host compatibility.Changes
Compile-time default (
CMRI.h)Runtime override (
CMRI.h,CMRI.cpp)New public method stores the delay in
_transmit_delay_us. Applied intransmit()before sending the GET frame:INIT handler example (
examples/init_handler_with_delay/)Demonstrates parsing dH/dL from the INIT payload and applying the delay:
Unit test
Added
test_set_transmit_delayto verify the setter compiles andtransmit()still produces a valid frame.Backward compatibility
TRANSMIT_DELAY_USis 50, matching previous hardcoded behaviorset_transmit_delay()is optional -- existing sketches work unchanged