forked from espressif/esp-idf
iperf: add output format change function for iperf
This commit is contained in:
@@ -52,6 +52,10 @@ extern "C" {
|
|||||||
#define IPERF_SOCKET_RX_TIMEOUT 10
|
#define IPERF_SOCKET_RX_TIMEOUT 10
|
||||||
#define IPERF_SOCKET_ACCEPT_TIMEOUT 5
|
#define IPERF_SOCKET_ACCEPT_TIMEOUT 5
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
MBITS_PER_SEC, KBITS_PER_SEC, BITS_PER_SEC
|
||||||
|
} iperf_output_format;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t flag;
|
uint32_t flag;
|
||||||
union {
|
union {
|
||||||
@@ -69,6 +73,7 @@ typedef struct {
|
|||||||
uint32_t time;
|
uint32_t time;
|
||||||
uint16_t len_send_buf;
|
uint16_t len_send_buf;
|
||||||
int32_t bw_lim;
|
int32_t bw_lim;
|
||||||
|
iperf_output_format format;
|
||||||
} iperf_cfg_t;
|
} iperf_cfg_t;
|
||||||
|
|
||||||
esp_err_t iperf_start(iperf_cfg_t *cfg);
|
esp_err_t iperf_start(iperf_cfg_t *cfg);
|
||||||
|
@@ -76,20 +76,23 @@ static void iperf_report_task(void *arg)
|
|||||||
double average = 0;
|
double average = 0;
|
||||||
double actual_bandwidth = 0;
|
double actual_bandwidth = 0;
|
||||||
int k = 1;
|
int k = 1;
|
||||||
|
const double coefficient[3] = {1048576.0, 1024.0, 1.0};
|
||||||
|
const char unit[3] = {'M', 'K', '\0'};
|
||||||
|
iperf_output_format format = s_iperf_ctrl.cfg.format;
|
||||||
|
|
||||||
printf("\n%16s %s\n", "Interval", "Bandwidth");
|
printf("\n%16s %s\n", "Interval", "Bandwidth");
|
||||||
while (!s_iperf_ctrl.finish) {
|
while (!s_iperf_ctrl.finish) {
|
||||||
vTaskDelay(delay_interval);
|
vTaskDelay(delay_interval);
|
||||||
actual_bandwidth = (s_iperf_ctrl.actual_len / 1e6 * 8) / interval;
|
actual_bandwidth = (s_iperf_ctrl.actual_len / coefficient[format] * 8) / interval;
|
||||||
printf("%4d-%4d sec %.2f Mbits/sec\n", cur, cur + interval,
|
printf("%4d-%4d sec %.2f %cbits/sec\n", cur, cur + interval,
|
||||||
actual_bandwidth);
|
actual_bandwidth, unit[format]);
|
||||||
cur += interval;
|
cur += interval;
|
||||||
average = ((average * (k - 1) / k) + (actual_bandwidth / k));
|
average = ((average * (k - 1) / k) + (actual_bandwidth / k));
|
||||||
k++;
|
k++;
|
||||||
s_iperf_ctrl.actual_len = 0;
|
s_iperf_ctrl.actual_len = 0;
|
||||||
if (cur >= time) {
|
if (cur >= time) {
|
||||||
printf("%4d-%4d sec %.2f Mbits/sec\n", 0, time,
|
printf("%4d-%4d sec %.2f %cbits/sec\n", 0, time,
|
||||||
average);
|
average, unit[format]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user