Fix printf format specifiers for uint64_t and uint32_t

Use PRIu64 and PRIu32 macros from inttypes.h instead of %llu and %u
to fix compilation errors with newer ESP-IDF versions
This commit is contained in:
Bob 2025-11-08 23:43:29 +00:00
parent 5bb8b03e6b
commit def2034d07
1 changed files with 5 additions and 4 deletions

View File

@ -1,5 +1,6 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <inttypes.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
@ -110,7 +111,7 @@ static esp_err_t iperf_start_tcp_server(iperf_ctrl_t *ctrl)
total_len += recv_len; total_len += recv_len;
} }
ESP_LOGI(TAG, "TCP server received: %llu bytes", total_len); ESP_LOGI(TAG, "TCP server received: %" PRIu64 " bytes", total_len);
close(client_sock); close(client_sock);
} }
@ -154,7 +155,7 @@ static esp_err_t iperf_start_tcp_client(iperf_ctrl_t *ctrl)
uint32_t actual_time = (xTaskGetTickCount() - start_time) / configTICK_RATE_HZ; uint32_t actual_time = (xTaskGetTickCount() - start_time) / configTICK_RATE_HZ;
float bandwidth = (float)total_len * 8 / actual_time / 1000000; // Mbps float bandwidth = (float)total_len * 8 / actual_time / 1000000; // Mbps
ESP_LOGI(TAG, "TCP client sent: %llu bytes in %u seconds (%.2f Mbps)", ESP_LOGI(TAG, "TCP client sent: %" PRIu64 " bytes in %" PRIu32 " seconds (%.2f Mbps)",
total_len, actual_time, bandwidth); total_len, actual_time, bandwidth);
close(sockfd); close(sockfd);
@ -215,7 +216,7 @@ static esp_err_t iperf_start_udp_server(iperf_ctrl_t *ctrl)
} }
float loss_rate = packet_count > 0 ? (float)lost_packets * 100 / packet_count : 0; float loss_rate = packet_count > 0 ? (float)lost_packets * 100 / packet_count : 0;
ESP_LOGI(TAG, "UDP server received: %llu bytes, %u packets, %u lost (%.2f%%)", ESP_LOGI(TAG, "UDP server received: %" PRIu64 " bytes, %" PRIu32 " packets, %" PRIu32 " lost (%.2f%%)",
total_len, packet_count, lost_packets, loss_rate); total_len, packet_count, lost_packets, loss_rate);
close(sockfd); close(sockfd);
@ -264,7 +265,7 @@ static esp_err_t iperf_start_udp_client(iperf_ctrl_t *ctrl)
uint32_t actual_time = (xTaskGetTickCount() - start_time) / configTICK_RATE_HZ; uint32_t actual_time = (xTaskGetTickCount() - start_time) / configTICK_RATE_HZ;
float bandwidth = actual_time > 0 ? (float)total_len * 8 / actual_time / 1000000 : 0; float bandwidth = actual_time > 0 ? (float)total_len * 8 / actual_time / 1000000 : 0;
ESP_LOGI(TAG, "UDP client sent: %llu bytes, %u packets in %u seconds (%.2f Mbps)", ESP_LOGI(TAG, "UDP client sent: %" PRIu64 " bytes, %" PRIu32 " packets in %" PRIu32 " seconds (%.2f Mbps)",
total_len, packet_count, actual_time, bandwidth); total_len, packet_count, actual_time, bandwidth);
close(sockfd); close(sockfd);