Skip to content

Commit fe0df48

Browse files
committed
add fs commands (work around lack of always_link)
1 parent 75824c9 commit fe0df48

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

firmware/main/app_main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "fmt/chrono.h"
1717
#include "fmt/core.h"
1818
#include "freertos/FreeRTOS.h"
19+
#include "linenoise/linenoise.h"
1920

2021
#include "esp_freertos_hooks.h" // depends on FreeRTOS.h
2122

@@ -62,6 +63,7 @@ esp_console_repl_t* InitializeConsole() {
6263
OK_OR_RETURN(esp_console_new_repl_uart(&repl_uart_config, &repl_config, &repl), nullptr);
6364
register_system_common();
6465
OK_OR_RETURN(ConsoleCommandRegistry::GetInstance()->Register(), nullptr);
66+
linenoiseSetMultiLine(0);
6567
return repl;
6668
}
6769

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2022 summivox. All rights reserved.
2+
// Authors: [email protected]
3+
4+
#include <map>
5+
6+
#include "common/console_command.hpp"
7+
#include "io/fs_utils.hpp"
8+
9+
namespace {
10+
const std::map<uint8_t, std::string> kDirentTypeName{
11+
{DT_REG, "DT_REG"},
12+
{DT_DIR, "DT_DIR"},
13+
{DT_UNKNOWN, "DT_UNKNOWN"},
14+
};
15+
} // namespace
16+
17+
DEFINE_CONSOLE_COMMAND(
18+
ls,
19+
"list all directories and files under given path",
20+
/*hint*/ nullptr,
21+
{ arg_str* path = arg_str1(nullptr, nullptr, "<path>", "path to list"); },
22+
/*num_end*/ 1) {
23+
CHECK(path->count == 1);
24+
25+
std::string dir = path->sval[0];
26+
27+
fputs("\n", stdout);
28+
for (dirent* p : io::DirIter(dir.c_str())) {
29+
printf("name='%s' type=%d (%s)", p->d_name, p->d_type, kDirentTypeName.at(p->d_type).c_str());
30+
// if (p->d_type == DT_REG) {
31+
struct stat s {};
32+
stat((dir + "/" + p->d_name).c_str(), &s);
33+
TimeParts mt = ToParts(s.st_mtim);
34+
printf(" size=%d", (int)s.st_size);
35+
// st_ctim is not populated, and we don't have st_birthtim / st_birthtimespec
36+
printf(
37+
" mtim=%04d-%02d-%02d_%02d:%02d:%02d",
38+
mt.tm_year + 1900,
39+
mt.tm_mon + 1,
40+
mt.tm_mday,
41+
mt.tm_hour,
42+
mt.tm_min,
43+
mt.tm_sec);
44+
// }
45+
fputs("\n", stdout);
46+
}
47+
fputs("\n", stdout);
48+
49+
return 0;
50+
}

firmware/main/io/fs_utils.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,5 @@ int64_t GetFreeSpaceBytes(const char* fatfs_root) {
135135
}
136136

137137
} // namespace io
138+
139+
#include "io/fs_commands.inl.cpp"

0 commit comments

Comments
 (0)