From 588e3f831d74baedf4efc1260027e2c965675491 Mon Sep 17 00:00:00 2001 From: Terje Io Date: Sat, 14 Mar 2026 21:18:52 +0100 Subject: [PATCH] Added latency (in ms) to $MODBUSSTATS output. --- README.md | 2 +- changelog.md | 16 +++++++++++++++- grbl.h | 2 +- modbus_rtu.c | 9 ++++++--- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c2833e0..4cc1d1f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## grblHAL ## -Latest build date is 20260312, see the [changelog](changelog.md) for details. +Latest build date is 20260314, see the [changelog](changelog.md) for details. > [!NOTE] > A settings reset will be performed on an update of builds prior to 20241208. Backup and restore of settings is recommended. diff --git a/changelog.md b/changelog.md index 7339ac3..18b4696 100644 --- a/changelog.md +++ b/changelog.md @@ -1,10 +1,24 @@ ## grblHAL changelog +Build 20260314 + +Core: + +* Added latency \(in ms\) to `$MODBUSSTATS` output. + +Plugins: + +* Spindle, all VFDs: "hardened" code against potential hardfault. + +* SD card: allow tasks to run during long file listings. + +--- + Build 20260312 Core: -* Added platform specific formatting strings for int32_t, "hardened" task handler code. +* Added platform specific formatting strings for `int32_t`, "hardened" task handler code. --- diff --git a/grbl.h b/grbl.h index 867a696..db13c3e 100644 --- a/grbl.h +++ b/grbl.h @@ -42,7 +42,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_BUILD 20260312 +#define GRBL_BUILD 20260314 #define GRBL_URL "https://github.com/grblHAL" diff --git a/modbus_rtu.c b/modbus_rtu.c index bbf3897..4dbba94 100644 --- a/modbus_rtu.c +++ b/modbus_rtu.c @@ -72,6 +72,7 @@ static int8_t stream_instance = -1; static uint32_t rx_timeout = 0, silence_until = 0, silence_timeout; static modbus_exception_t exception_code = ModBus_NoException; static modbus_silence_timeout_t silence; +static uint32_t latency = 0; static queue_entry_t queue[MODBUS_QUEUE_LENGTH]; static rtu_settings_t modbus; static volatile bool spin_lock = false, is_blocking = false, is_up = false; @@ -202,6 +203,8 @@ static void modbus_poll (void *data) char *buf = (char *)((queue_entry_t *)packet)->msg.adu; uint16_t rx_len = packet->msg.rx_length; // store original length for CRC check + latency = max(latency, modbus.rx_timeout - rx_timeout); + do { *buf++ = stream.read(); } while(--packet->msg.rx_length); @@ -533,13 +536,13 @@ FLASHMEM static status_code_t report_stats (sys_state_t state, char *args) { char buf[110]; - snprintf(buf, sizeof(buf) - 1, "TX: " UINT32FMT ", retries: " UINT32FMT ", timeouts: " UINT32FMT ", RX exceptions: " UINT32FMT ", CRC errors: " UINT32FMT, - stats.tx_count, stats.retries, stats.timeouts, stats.rx_exceptions, stats.crc_errors); + snprintf(buf, sizeof(buf) - 1, "TX: " UINT32FMT ", retries: " UINT32FMT ", timeouts: " UINT32FMT ", RX exceptions: " UINT32FMT ", CRC errors: " UINT32FMT ", latency: " UINT32FMT, + stats.tx_count, stats.retries, stats.timeouts, stats.rx_exceptions, stats.crc_errors, latency); report_message(buf, Message_Info); if(args && (*args == 'r' || *args == 'R')) - stats.tx_count = stats.retries = stats.timeouts = stats.rx_exceptions = stats.crc_errors = 0; + stats.tx_count = stats.retries = stats.timeouts = stats.rx_exceptions = stats.crc_errors = latency = 0; return Status_OK; }