/* * iperf.h * * Copyright (c) 2025 Umber Networks & Robert McMahon * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef IPERF_H #define IPERF_H #include #include #include "esp_err.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) // --- Defaults --- #define IPERF_DEFAULT_PORT 5001 #define IPERF_UDP_TX_LEN 1470 typedef struct { uint32_t flag; uint32_t dip; // Destination IP uint16_t dport; // Destination Port 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; uint64_t total_packets; uint32_t err_mem; // ENOMEM (12) uint32_t err_route; // EHOSTUNREACH (118) uint32_t err_other; // All other errors } 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); 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