void register_ethernet() { eth_event_group = xEventGroupCreate(); tcpip_adapter_init(); ESP_ERROR_CHECK(esp_event_loop_init(eth_event_handler, NULL)); eth_config_t config = DEFAULT_ETHERNET_PHY_CONFIG; config.phy_addr = CONFIG_PHY_ADDRESS; config.gpio_config = eth_gpio_config_rmii; config.tcpip_input = tcpip_adapter_eth_input; config.clock_mode = CONFIG_PHY_CLOCK_MODE; #ifdef CONFIG_PHY_USE_POWER_PIN /* Replace the default 'power enable' function with an example-specific one that toggles a power GPIO. */ config.phy_power_enable = phy_device_power_enable_via_gpio; #endif ESP_ERROR_CHECK(esp_eth_init(&config)); eth_control_args.control = arg_str1(NULL, NULL, "<start|stop|info>", "Start/Stop Ethernet or Get info of Ethernet"); eth_control_args.end = arg_end(1); const esp_console_cmd_t cmd = { .command = "ethernet", .help = "Control Ethernet interface", .hint = NULL, .func = eth_cmd_control, .argtable = ð_control_args }; ESP_ERROR_CHECK(esp_console_cmd_register(&cmd)); iperf_args.ip = arg_str0("c", "client", "<ip>", "run in client mode, connecting to <host>"); iperf_args.server = arg_lit0("s", "server", "run in server mode"); iperf_args.udp = arg_lit0("u", "udp", "use UDP rather than TCP"); iperf_args.port = arg_int0("p", "port", "<port>", "server port to listen on/connect to"); iperf_args.interval = arg_int0("i", "interval", "<interval>", "seconds between periodic bandwidth reports"); iperf_args.time = arg_int0("t", "time", "<time>", "time in seconds to transmit for (default 10 secs)"); iperf_args.abort = arg_lit0("a", "abort", "abort running iperf"); iperf_args.end = arg_end(1); const esp_console_cmd_t iperf_cmd = { .command = "iperf", .help = "iperf command", .hint = NULL, .func = ð_cmd_iperf, .argtable = &iperf_args }; ESP_ERROR_CHECK(esp_console_cmd_register(&iperf_cmd)); }
void run_console() { initialize_console(); /* Register commands */ esp_console_register_help_command(); const esp_console_cmd_t cmd1 = { .command = "motortest", .help = "Test the motors", .hint = NULL, .func = &motor_test, .argtable = nullptr }; ESP_ERROR_CHECK(esp_console_cmd_register(&cmd1)); const esp_console_cmd_t cmd2 = { .command = "i2cscan", .help = "Scan for I2C devices", .hint = NULL, .func = &i2c_scan, .argtable = nullptr }; ESP_ERROR_CHECK(esp_console_cmd_register(&cmd2)); /* Prompt to be printed before each line. * This can be customized, made dynamic, etc. */ const char* prompt = LOG_COLOR_I "esp32> " LOG_RESET_COLOR; printf("\n" "This is an example of ESP-IDF console component.\n" "Type 'help' to get the list of commands.\n" "Use UP/DOWN arrows to navigate through command history.\n" "Press TAB when typing command name to auto-complete.\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 */ while(true) { /* Get a line using linenoise. * The line is returned when ENTER is pressed. */ char* line = linenoise(prompt); if (line == NULL) { /* Ignore empty lines */ continue; } /* Add the command to the history */ linenoiseHistoryAdd(line); #if CONFIG_STORE_HISTORY /* Save command history to filesystem */ linenoiseHistorySave(HISTORY_PATH); #endif /* 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_ERR_INVALID_ARG) { // command was empty } else if (err == ESP_OK && ret != ESP_OK) { printf("Command returned non-zero error code: 0x%x (%s)\n", ret, esp_err_to_name(err)); } else if (err != ESP_OK) { printf("Internal error: %s\n", esp_err_to_name(err)); } /* linenoise allocates line buffer on the heap, so need to free it */ linenoiseFree(line); } }