summaryrefslogtreecommitdiff
path: root/src/dev_console
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2022-11-15 16:36:42 +1100
committerjacqueline <me@jacqueline.id.au>2022-11-15 16:39:54 +1100
commit07e1b5a3284201b4eac36a15c361b85dfba147b5 (patch)
treed623b7b31192486aa4fb0293f5ea5aa36c936a9c /src/dev_console
parentaef2eb7566e7f8f6caf2481942ce67a31f007563 (diff)
downloadtangara-fw-07e1b5a3284201b4eac36a15c361b85dfba147b5.tar.gz
WIP debug console for testing playback
Diffstat (limited to 'src/dev_console')
-rw-r--r--src/dev_console/CMakeLists.txt5
-rw-r--r--src/dev_console/console.cpp87
-rw-r--r--src/dev_console/include/console.hpp22
3 files changed, 114 insertions, 0 deletions
diff --git a/src/dev_console/CMakeLists.txt b/src/dev_console/CMakeLists.txt
new file mode 100644
index 00000000..b7e6357e
--- /dev/null
+++ b/src/dev_console/CMakeLists.txt
@@ -0,0 +1,5 @@
+idf_component_register(
+ SRCS "console.cpp"
+ INCLUDE_DIRS "include"
+ REQUIRES "console")
+target_compile_options(${COMPONENT_LIB} PRIVATE ${EXTRA_WARNINGS})
diff --git a/src/dev_console/console.cpp b/src/dev_console/console.cpp
new file mode 100644
index 00000000..9b51caaf
--- /dev/null
+++ b/src/dev_console/console.cpp
@@ -0,0 +1,87 @@
+#include "console.hpp"
+#include <stdio.h>
+#include <string.h>
+
+#include <algorithm>
+#include <iostream>
+#include <string>
+
+#include "esp_console.h"
+#include "esp_log.h"
+#include "esp_system.h"
+
+namespace console {
+
+int CmdLogLevel(int argc, char** argv) {
+ static const std::string usage =
+ "usage: loglevel [VERBOSE,DEBUG,INFO,WARN,ERROR,NONE]";
+ if (argc != 2) {
+ std::cout << usage << std::endl;
+ return 1;
+ }
+ std::string level_str = argv[1];
+ std::transform(level_str.begin(), level_str.end(), level_str.begin(),
+ [](unsigned char c) { return std::toupper(c); });
+
+ esp_log_level_t level;
+ if (level_str == "VERBOSE") {
+ level = ESP_LOG_VERBOSE;
+ } else if (level_str == "DEBUG") {
+ level = ESP_LOG_DEBUG;
+ } else if (level_str == "INFO") {
+ level = ESP_LOG_INFO;
+ } else if (level_str == "WARN") {
+ level = ESP_LOG_WARN;
+ } else if (level_str == "ERROR") {
+ level = ESP_LOG_ERROR;
+ } else if (level_str == "NONE") {
+ level = ESP_LOG_NONE;
+ } else {
+ std::cout << usage << std::endl;
+ return 1;
+ }
+
+ esp_log_level_set("*", level);
+
+ return 0;
+}
+
+void RegisterLogLevel() {
+ esp_console_cmd_t cmd{
+ .command = "loglevel",
+ .help =
+ "Sets the log level to one of \"VERBOSE\", \"DEBUG\", \"INFO\", "
+ "\"WARN\", \"ERROR\", \"NONE\"",
+ .hint = "level",
+ .func = &CmdLogLevel,
+ .argtable = NULL};
+ esp_console_cmd_register(&cmd);
+}
+
+Console::Console() {}
+Console::~Console() {}
+
+auto Console::RegisterCommonComponents() -> void {
+ esp_console_register_help_command();
+ RegisterLogLevel();
+}
+
+auto Console::Launch() -> void {
+ esp_console_repl_t* repl = nullptr;
+ esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();
+ repl_config.max_history_len = 16;
+ repl_config.prompt = " →";
+ repl_config.max_cmdline_length = 256;
+ repl_config.task_stack_size = 1024 * GetStackSizeKiB();
+
+ esp_console_dev_uart_config_t hw_config =
+ ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
+ ESP_ERROR_CHECK(esp_console_new_repl_uart(&hw_config, &repl_config, &repl));
+
+ RegisterCommonComponents();
+ RegisterExtraComponents();
+
+ ESP_ERROR_CHECK(esp_console_start_repl(repl));
+}
+
+} // namespace console
diff --git a/src/dev_console/include/console.hpp b/src/dev_console/include/console.hpp
new file mode 100644
index 00000000..cf5180dd
--- /dev/null
+++ b/src/dev_console/include/console.hpp
@@ -0,0 +1,22 @@
+#pragma once
+
+#include <cstdint>
+
+namespace console {
+
+class Console {
+ public:
+ Console();
+ virtual ~Console();
+
+ auto Launch() -> void;
+
+ protected:
+ virtual auto GetStackSizeKiB() -> uint16_t { return 0; }
+ virtual auto RegisterExtraComponents() -> void {}
+
+ private:
+ auto RegisterCommonComponents() -> void;
+};
+
+} // namespace console