Skip to content

Commit

Permalink
Fine-tune tpuart inter-byte delay handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bmalinowsky committed May 9, 2024
1 parent 5aea35b commit ad9f92c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/io/calimero/serial/TpuartConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public class TpuartConnection implements Connection<byte[]>
private static final int Tp1BaudRate = 9_600;

private static final int OneBitTime = (int) Math.ceil(1d / Tp1BaudRate * 1_000_000);
private static final int BitTimes_50 = 50 * OneBitTime; // [us]
private static final int BitTimes_50 = 50 * OneBitTime; // [us] -> 5250 us for 9600 Bd

private static final int MaxSendAttempts = 4;

Expand Down Expand Up @@ -511,7 +511,7 @@ private boolean isValidChecksum(final byte[] frame)
// Defaults to 50 bit times [us]
private static final AtomicInteger maxInterByteDelay = new AtomicInteger(BitTimes_50);
static {
final var key = "calimero.serial.tpuart.maxInterByteDelay";
final var key = "io.calimero.serial.tpuart.maxInterByteDelay";
try {
final var delay = System.getProperty(key);
if (delay != null) {
Expand Down Expand Up @@ -638,8 +638,8 @@ void quit()

private int maxInterByteDelay()
{
// cond: consecutively losing 4 frames (1 msg w/ 1 .ind + 2 .ind repetitions, and 1st .ind of next msg)
if (consecutiveFrameDrops >= 3) {
// cond: consecutively losing 3 frames (1 msg w/ 1 .ind + 2 .ind repetitions)
if (consecutiveFrameDrops >= 2) {
maxDelay = maxInterByteDelay.accumulateAndGet(Math.min(maxDelay + 500, 20_000), Math::max);
logger.log(WARNING, "{0} partial frames discarded, increase max. inter-byte delay to {1} us",
consecutiveFrameDrops + 1, maxDelay);
Expand Down

0 comments on commit ad9f92c

Please sign in to comment.