diff --git a/components/iperf/iperf.c b/components/iperf/iperf.c index 03b59f3..a5e047a 100644 --- a/components/iperf/iperf.c +++ b/components/iperf/iperf.c @@ -285,7 +285,7 @@ static esp_err_t iperf_start_udp_client(iperf_ctrl_t *ctrl) { int64_t last_rate_check = esp_timer_get_time(); uint32_t packets_since_check = 0; int32_t packet_id = 0; - + uint32_t current_rate_check_interval_us = MIN_RATE_CHECK_INTERVAL_US; struct timespec ts; while (!ctrl->finish && esp_timer_get_time() < end_time) { @@ -320,8 +320,19 @@ static esp_err_t iperf_start_udp_client(iperf_ctrl_t *ctrl) { } now = esp_timer_get_time(); - if (now - last_rate_check > RATE_CHECK_INTERVAL_US) { + // Modified check to use dynamic interval + if (now - last_rate_check > current_rate_check_interval_us) { uint32_t interval_us = (uint32_t)(now - last_rate_check); + + // Dynamic Interval Calculation --- + uint32_t config_pps = iperf_get_pps(); + if (config_pps > 0) { + // Calculate time needed to send 25 packets based on the CONFIG PPS + uint32_t needed_time_us = (25ULL * 1000000ULL) / config_pps; + // Set new interval: needed_time_us, but not lower than 250ms + current_rate_check_interval_us = (needed_time_us > MIN_RATE_CHECK_INTERVAL_US) ? needed_time_us : MIN_RATE_CHECK_INTERVAL_US; + } + if (interval_us > 0) { // Calculate Instantaneous PPS s_stats.actual_pps = (uint32_t)((uint64_t)packets_since_check * 1000000 / interval_us);