ESP32/components/iperf/iperf.h

69 lines
1.7 KiB
C

#ifndef IPERF_H
#define IPERF_H
#include <stdint.h>
#include <stdbool.h>
#include "led_strip.h"
// --- Configuration Flags ---
#define IPERF_FLAG_CLIENT (1 << 0)
#define IPERF_FLAG_SERVER (1 << 1)
#define IPERF_FLAG_TCP (1 << 2)
#define IPERF_FLAG_UDP (1 << 3)
// --- Standard Iperf2 Header Flags ---
#define HEADER_VERSION1 0x80000000
#define HEADER_EXTEND 0x40000000
#define HEADER_UDPTESTS 0x20000000
#define HEADER_SEQNO64B 0x08000000
// --- Defaults ---
#define IPERF_DEFAULT_PORT 5001
#define IPERF_DEFAULT_INTERVAL 3
#define IPERF_DEFAULT_TIME 30
#define IPERF_UDP_TX_LEN 1470
typedef struct {
uint32_t flag;
uint32_t dip; // Destination IP
uint16_t dport; // Destination Port
uint32_t time; // Duration (seconds), 0 = infinite
uint32_t target_pps; // Packets Per Second (Replaces period)
uint32_t burst_count; // Packets per RTOS tick
uint32_t send_len; // Packet payload length
} iperf_cfg_t;
typedef struct {
bool running;
uint32_t config_pps;
uint32_t actual_pps;
float error_rate;
} iperf_stats_t;
// --- API ---
// Initialization (Call this in app_main to load NVS)
void iperf_param_init(void);
// Parameter Management (Running Config)
void iperf_param_get(iperf_cfg_t *out_cfg);
void iperf_param_set(const iperf_cfg_t *new_cfg);
// Save returns true if NVS was actually updated
esp_err_t iperf_param_save(bool *out_changed);
// Check if dirty
bool iperf_param_is_unsaved(void);
// Control
void iperf_start(void); // Uses current Running Config
void iperf_stop(void);
void iperf_print_status(void);
// Utils
void iperf_init_led(led_strip_handle_t handle);
// Erase NVS and reset RAM defaults
void iperf_param_clear(void);
#endif