2017-03-30 11:12:25 -04:00
|
|
|
/* Iperf Example
|
|
|
|
|
|
|
|
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, this
|
|
|
|
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
|
|
CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
#include "freertos/task.h"
|
|
|
|
#include "esp_wifi.h"
|
|
|
|
#include "esp_log.h"
|
|
|
|
#include "esp_err.h"
|
2017-10-19 21:52:58 -04:00
|
|
|
#include "nvs_flash.h"
|
2017-03-30 11:12:25 -04:00
|
|
|
|
|
|
|
#include "esp_console.h"
|
|
|
|
#include "esp_vfs_dev.h"
|
|
|
|
#include "driver/uart.h"
|
|
|
|
#include "linenoise/linenoise.h"
|
|
|
|
#include "argtable3/argtable3.h"
|
|
|
|
#include "cmd_decl.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define WIFI_CONNECTED_BIT BIT0
|
|
|
|
|
2019-07-16 05:33:30 -04:00
|
|
|
static void initialize_console(void)
|
2017-03-30 11:12:25 -04:00
|
|
|
{
|
2019-03-13 08:19:55 -04:00
|
|
|
/* Disable buffering on stdin */
|
2017-03-30 11:12:25 -04:00
|
|
|
setvbuf(stdin, NULL, _IONBF, 0);
|
|
|
|
|
|
|
|
/* Minicom, screen, idf_monitor send CR when ENTER key is pressed */
|
|
|
|
esp_vfs_dev_uart_set_rx_line_endings(ESP_LINE_ENDINGS_CR);
|
|
|
|
/* Move the caret to the beginning of the next line on '\n' */
|
|
|
|
esp_vfs_dev_uart_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF);
|
|
|
|
|
|
|
|
/* Install UART driver for interrupt-driven reads and writes */
|
2019-04-30 06:51:55 -04:00
|
|
|
ESP_ERROR_CHECK( uart_driver_install(CONFIG_ESP_CONSOLE_UART_NUM,
|
2018-09-20 07:26:14 -04:00
|
|
|
256, 0, 0, NULL, 0) );
|
2017-03-30 11:12:25 -04:00
|
|
|
|
|
|
|
/* Tell VFS to use UART driver */
|
2019-04-30 06:51:55 -04:00
|
|
|
esp_vfs_dev_uart_use_driver(CONFIG_ESP_CONSOLE_UART_NUM);
|
2017-03-30 11:12:25 -04:00
|
|
|
|
|
|
|
/* Initialize the console */
|
|
|
|
esp_console_config_t console_config = {
|
2018-09-20 07:26:14 -04:00
|
|
|
.max_cmdline_args = 32,
|
|
|
|
.max_cmdline_length = 256,
|
2017-03-30 11:12:25 -04:00
|
|
|
#if CONFIG_LOG_COLORS
|
2018-09-20 07:26:14 -04:00
|
|
|
.hint_color = atoi(LOG_COLOR_CYAN)
|
2017-03-30 11:12:25 -04:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
ESP_ERROR_CHECK( esp_console_init(&console_config) );
|
|
|
|
|
|
|
|
/* Configure linenoise line completion library */
|
|
|
|
/* Enable multiline editing. If not set, long commands will scroll within
|
|
|
|
* single line.
|
|
|
|
*/
|
|
|
|
linenoiseSetMultiLine(1);
|
|
|
|
|
|
|
|
/* Tell linenoise where to get command completions and hints */
|
|
|
|
linenoiseSetCompletionCallback(&esp_console_get_completion);
|
2018-09-20 07:26:14 -04:00
|
|
|
linenoiseSetHintsCallback((linenoiseHintsCallback *) &esp_console_get_hint);
|
2017-03-30 11:12:25 -04:00
|
|
|
|
|
|
|
/* Set command history size */
|
|
|
|
linenoiseHistorySetMaxLen(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
void app_main(void)
|
|
|
|
{
|
2017-10-19 21:52:58 -04:00
|
|
|
esp_err_t ret = nvs_flash_init();
|
2018-07-25 11:11:09 -04:00
|
|
|
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
2017-10-19 21:52:58 -04:00
|
|
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
|
|
|
ret = nvs_flash_init();
|
|
|
|
}
|
|
|
|
ESP_ERROR_CHECK( ret );
|
2018-09-20 07:26:14 -04:00
|
|
|
|
2017-03-30 11:12:25 -04:00
|
|
|
initialise_wifi();
|
|
|
|
initialize_console();
|
|
|
|
|
|
|
|
/* Register commands */
|
|
|
|
esp_console_register_help_command();
|
2018-09-20 07:26:14 -04:00
|
|
|
register_system();
|
2017-03-30 11:12:25 -04:00
|
|
|
register_wifi();
|
|
|
|
|
|
|
|
/* Prompt to be printed before each line.
|
|
|
|
* This can be customized, made dynamic, etc.
|
|
|
|
*/
|
2018-09-20 07:26:14 -04:00
|
|
|
const char *prompt = LOG_COLOR_I "esp32> " LOG_RESET_COLOR;
|
2017-03-30 11:12:25 -04:00
|
|
|
|
|
|
|
printf("\n ==================================================\n");
|
|
|
|
printf(" | Steps to test WiFi throughput |\n");
|
|
|
|
printf(" | |\n");
|
|
|
|
printf(" | 1. Print 'help' to gain overview of commands |\n");
|
|
|
|
printf(" | 2. Configure device to station or soft-AP |\n");
|
|
|
|
printf(" | 3. Setup WiFi connection |\n");
|
|
|
|
printf(" | 4. Run iperf to test UDP/TCP RX/TX throughput |\n");
|
|
|
|
printf(" | |\n");
|
|
|
|
printf(" =================================================\n\n");
|
|
|
|
|
|
|
|
/* Figure out if the terminal supports escape sequences */
|
|
|
|
int probe_status = linenoiseProbe();
|
|
|
|
if (probe_status) { /* zero indicates success */
|
|
|
|
printf("\n"
|
|
|
|
"Your terminal application does not support escape sequences.\n"
|
|
|
|
"Line editing and history features are disabled.\n"
|
|
|
|
"On Windows, try using Putty instead.\n");
|
|
|
|
linenoiseSetDumbMode(1);
|
|
|
|
#if CONFIG_LOG_COLORS
|
|
|
|
/* Since the terminal doesn't support escape sequences,
|
|
|
|
* don't use color codes in the prompt.
|
|
|
|
*/
|
|
|
|
prompt = "esp32> ";
|
|
|
|
#endif //CONFIG_LOG_COLORS
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Main loop */
|
2018-09-20 07:26:14 -04:00
|
|
|
while (true) {
|
2017-03-30 11:12:25 -04:00
|
|
|
/* Get a line using linenoise.
|
|
|
|
* The line is returned when ENTER is pressed.
|
|
|
|
*/
|
2018-09-20 07:26:14 -04:00
|
|
|
char *line = linenoise(prompt);
|
2017-03-30 11:12:25 -04:00
|
|
|
if (line == NULL) { /* Ignore empty lines */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* Add the command to the history */
|
|
|
|
linenoiseHistoryAdd(line);
|
|
|
|
|
|
|
|
/* Try to run the command */
|
|
|
|
int ret;
|
|
|
|
esp_err_t err = esp_console_run(line, &ret);
|
|
|
|
if (err == ESP_ERR_NOT_FOUND) {
|
|
|
|
printf("Unrecognized command\n");
|
|
|
|
} else if (err == ESP_OK && ret != ESP_OK) {
|
|
|
|
printf("Command returned non-zero error code: 0x%x\n", ret);
|
|
|
|
} else if (err != ESP_OK) {
|
2018-02-22 08:48:53 -05:00
|
|
|
printf("Internal error: %s\n", esp_err_to_name(err));
|
2017-03-30 11:12:25 -04:00
|
|
|
}
|
|
|
|
/* linenoise allocates line buffer on the heap, so need to free it */
|
|
|
|
linenoiseFree(line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|