mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-19 04:44:47 -07:00
Merge remote-tracking branch 'OFW/dev' into dev
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
#include <cli/cli.h>
|
||||
#include <toolbox/cli/cli_command.h>
|
||||
#include <toolbox/cli/cli_ansi.h>
|
||||
#include <cli/cli_main_commands.h>
|
||||
#include <lib/toolbox/args.h>
|
||||
#include <lib/toolbox/dir_walk.h>
|
||||
#include <lib/toolbox/md5_calc.h>
|
||||
@@ -10,6 +12,7 @@
|
||||
#include <storage/storage.h>
|
||||
#include <storage/storage_sd_api.h>
|
||||
#include <power/power_service/power.h>
|
||||
#include <toolbox/pipe.h>
|
||||
|
||||
#define MAX_NAME_LENGTH 255
|
||||
|
||||
@@ -19,8 +22,8 @@ static void storage_cli_print_error(FS_Error error) {
|
||||
printf("Storage error: %s\r\n", storage_error_get_desc(error));
|
||||
}
|
||||
|
||||
static void storage_cli_info(Cli* cli, FuriString* path, FuriString* args) {
|
||||
UNUSED(cli);
|
||||
static void storage_cli_info(PipeSide* pipe, FuriString* path, FuriString* args) {
|
||||
UNUSED(pipe);
|
||||
UNUSED(args);
|
||||
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
@@ -69,13 +72,14 @@ static void storage_cli_info(Cli* cli, FuriString* path, FuriString* args) {
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
static void storage_cli_format(Cli* cli, FuriString* path, FuriString* args) {
|
||||
static void storage_cli_format(PipeSide* pipe, FuriString* path, FuriString* args) {
|
||||
UNUSED(pipe);
|
||||
UNUSED(args);
|
||||
if(furi_string_cmp_str(path, STORAGE_INT_PATH_PREFIX) == 0) {
|
||||
storage_cli_print_error(FSE_NOT_IMPLEMENTED);
|
||||
} else if(furi_string_cmp_str(path, STORAGE_EXT_PATH_PREFIX) == 0) {
|
||||
printf("Formatting SD card, All data will be lost! Are you sure (y/n)?\r\n");
|
||||
char answer = cli_getc(cli);
|
||||
char answer = getchar();
|
||||
if(answer == 'y' || answer == 'Y') {
|
||||
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||
printf("Formatting, please wait...\r\n");
|
||||
@@ -96,8 +100,8 @@ static void storage_cli_format(Cli* cli, FuriString* path, FuriString* args) {
|
||||
}
|
||||
}
|
||||
|
||||
static void storage_cli_list(Cli* cli, FuriString* path, FuriString* args) {
|
||||
UNUSED(cli);
|
||||
static void storage_cli_list(PipeSide* pipe, FuriString* path, FuriString* args) {
|
||||
UNUSED(pipe);
|
||||
UNUSED(args);
|
||||
if(furi_string_cmp_str(path, "/") == 0) {
|
||||
printf("\t[D] int\r\n");
|
||||
@@ -134,13 +138,13 @@ static void storage_cli_list(Cli* cli, FuriString* path, FuriString* args) {
|
||||
}
|
||||
}
|
||||
|
||||
static void storage_cli_tree(Cli* cli, FuriString* path, FuriString* args) {
|
||||
static void storage_cli_tree(PipeSide* pipe, FuriString* path, FuriString* args) {
|
||||
UNUSED(args);
|
||||
if(furi_string_cmp_str(path, "/") == 0) {
|
||||
furi_string_set(path, STORAGE_INT_PATH_PREFIX);
|
||||
storage_cli_tree(cli, path, NULL);
|
||||
storage_cli_tree(pipe, path, NULL);
|
||||
furi_string_set(path, STORAGE_EXT_PATH_PREFIX);
|
||||
storage_cli_tree(cli, path, NULL);
|
||||
storage_cli_tree(pipe, path, NULL);
|
||||
} else {
|
||||
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||
DirWalk* dir_walk = dir_walk_alloc(api);
|
||||
@@ -176,8 +180,8 @@ static void storage_cli_tree(Cli* cli, FuriString* path, FuriString* args) {
|
||||
}
|
||||
}
|
||||
|
||||
static void storage_cli_read(Cli* cli, FuriString* path, FuriString* args) {
|
||||
UNUSED(cli);
|
||||
static void storage_cli_read(PipeSide* pipe, FuriString* path, FuriString* args) {
|
||||
UNUSED(pipe);
|
||||
UNUSED(args);
|
||||
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||
File* file = storage_file_alloc(api);
|
||||
@@ -208,7 +212,8 @@ static void storage_cli_read(Cli* cli, FuriString* path, FuriString* args) {
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
static void storage_cli_write(Cli* cli, FuriString* path, FuriString* args) {
|
||||
static void storage_cli_write(PipeSide* pipe, FuriString* path, FuriString* args) {
|
||||
UNUSED(pipe);
|
||||
UNUSED(args);
|
||||
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||
File* file = storage_file_alloc(api);
|
||||
@@ -222,9 +227,9 @@ static void storage_cli_write(Cli* cli, FuriString* path, FuriString* args) {
|
||||
uint32_t read_index = 0;
|
||||
|
||||
while(true) {
|
||||
uint8_t symbol = cli_getc(cli);
|
||||
uint8_t symbol = getchar();
|
||||
|
||||
if(symbol == CliSymbolAsciiETX) {
|
||||
if(symbol == CliKeyETX) {
|
||||
size_t write_size = read_index % buffer_size;
|
||||
|
||||
if(write_size > 0) {
|
||||
@@ -263,7 +268,8 @@ static void storage_cli_write(Cli* cli, FuriString* path, FuriString* args) {
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
static void storage_cli_read_chunks(Cli* cli, FuriString* path, FuriString* args) {
|
||||
static void storage_cli_read_chunks(PipeSide* pipe, FuriString* path, FuriString* args) {
|
||||
UNUSED(pipe);
|
||||
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||
File* file = storage_file_alloc(api);
|
||||
|
||||
@@ -280,7 +286,7 @@ static void storage_cli_read_chunks(Cli* cli, FuriString* path, FuriString* args
|
||||
uint8_t* data = malloc(buffer_size);
|
||||
while(file_size > 0) {
|
||||
printf("\r\nReady?\r\n");
|
||||
cli_getc(cli);
|
||||
getchar();
|
||||
|
||||
size_t read_size = storage_file_read(file, data, buffer_size);
|
||||
for(size_t i = 0; i < read_size; i++) {
|
||||
@@ -302,31 +308,34 @@ static void storage_cli_read_chunks(Cli* cli, FuriString* path, FuriString* args
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
static void storage_cli_write_chunk(Cli* cli, FuriString* path, FuriString* args) {
|
||||
static void storage_cli_write_chunk(PipeSide* pipe, FuriString* path, FuriString* args) {
|
||||
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||
File* file = storage_file_alloc(api);
|
||||
|
||||
uint32_t buffer_size;
|
||||
if(strint_to_uint32(furi_string_get_cstr(args), NULL, &buffer_size, 10) !=
|
||||
uint32_t need_to_read;
|
||||
if(strint_to_uint32(furi_string_get_cstr(args), NULL, &need_to_read, 10) !=
|
||||
StrintParseNoError) {
|
||||
storage_cli_print_usage();
|
||||
} else {
|
||||
if(storage_file_open(file, furi_string_get_cstr(path), FSAM_WRITE, FSOM_OPEN_APPEND)) {
|
||||
printf("Ready\r\n");
|
||||
const size_t buffer_size = 1024;
|
||||
uint8_t* buffer = malloc(buffer_size);
|
||||
|
||||
if(buffer_size) {
|
||||
uint8_t* buffer = malloc(buffer_size);
|
||||
while(need_to_read) {
|
||||
size_t to_read_this_time = MIN(buffer_size, need_to_read);
|
||||
size_t read_this_time = pipe_receive(pipe, buffer, to_read_this_time);
|
||||
if(read_this_time != to_read_this_time) break;
|
||||
|
||||
size_t read_bytes = cli_read(cli, buffer, buffer_size);
|
||||
|
||||
size_t written_size = storage_file_write(file, buffer, read_bytes);
|
||||
|
||||
if(written_size != buffer_size) {
|
||||
size_t wrote_this_time = storage_file_write(file, buffer, read_this_time);
|
||||
if(wrote_this_time != read_this_time) {
|
||||
storage_cli_print_error(storage_file_get_error(file));
|
||||
break;
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
need_to_read -= read_this_time;
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
} else {
|
||||
storage_cli_print_error(storage_file_get_error(file));
|
||||
}
|
||||
@@ -337,8 +346,8 @@ static void storage_cli_write_chunk(Cli* cli, FuriString* path, FuriString* args
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
static void storage_cli_stat(Cli* cli, FuriString* path, FuriString* args) {
|
||||
UNUSED(cli);
|
||||
static void storage_cli_stat(PipeSide* pipe, FuriString* path, FuriString* args) {
|
||||
UNUSED(pipe);
|
||||
UNUSED(args);
|
||||
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
@@ -379,8 +388,8 @@ static void storage_cli_stat(Cli* cli, FuriString* path, FuriString* args) {
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
static void storage_cli_timestamp(Cli* cli, FuriString* path, FuriString* args) {
|
||||
UNUSED(cli);
|
||||
static void storage_cli_timestamp(PipeSide* pipe, FuriString* path, FuriString* args) {
|
||||
UNUSED(pipe);
|
||||
UNUSED(args);
|
||||
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
@@ -396,8 +405,8 @@ static void storage_cli_timestamp(Cli* cli, FuriString* path, FuriString* args)
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
static void storage_cli_copy(Cli* cli, FuriString* old_path, FuriString* args) {
|
||||
UNUSED(cli);
|
||||
static void storage_cli_copy(PipeSide* pipe, FuriString* old_path, FuriString* args) {
|
||||
UNUSED(pipe);
|
||||
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||
FuriString* new_path;
|
||||
new_path = furi_string_alloc();
|
||||
@@ -417,8 +426,8 @@ static void storage_cli_copy(Cli* cli, FuriString* old_path, FuriString* args) {
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
static void storage_cli_remove(Cli* cli, FuriString* path, FuriString* args) {
|
||||
UNUSED(cli);
|
||||
static void storage_cli_remove(PipeSide* pipe, FuriString* path, FuriString* args) {
|
||||
UNUSED(pipe);
|
||||
UNUSED(args);
|
||||
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||
FS_Error error = storage_common_remove(api, furi_string_get_cstr(path));
|
||||
@@ -430,8 +439,8 @@ static void storage_cli_remove(Cli* cli, FuriString* path, FuriString* args) {
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
static void storage_cli_rename(Cli* cli, FuriString* old_path, FuriString* args) {
|
||||
UNUSED(cli);
|
||||
static void storage_cli_rename(PipeSide* pipe, FuriString* old_path, FuriString* args) {
|
||||
UNUSED(pipe);
|
||||
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||
FuriString* new_path;
|
||||
new_path = furi_string_alloc();
|
||||
@@ -451,8 +460,8 @@ static void storage_cli_rename(Cli* cli, FuriString* old_path, FuriString* args)
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
static void storage_cli_mkdir(Cli* cli, FuriString* path, FuriString* args) {
|
||||
UNUSED(cli);
|
||||
static void storage_cli_mkdir(PipeSide* pipe, FuriString* path, FuriString* args) {
|
||||
UNUSED(pipe);
|
||||
UNUSED(args);
|
||||
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||
FS_Error error = storage_common_mkdir(api, furi_string_get_cstr(path));
|
||||
@@ -464,8 +473,8 @@ static void storage_cli_mkdir(Cli* cli, FuriString* path, FuriString* args) {
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
static void storage_cli_md5(Cli* cli, FuriString* path, FuriString* args) {
|
||||
UNUSED(cli);
|
||||
static void storage_cli_md5(PipeSide* pipe, FuriString* path, FuriString* args) {
|
||||
UNUSED(pipe);
|
||||
UNUSED(args);
|
||||
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||
File* file = storage_file_alloc(api);
|
||||
@@ -491,8 +500,8 @@ static bool tar_extract_file_callback(const char* name, bool is_directory, void*
|
||||
return true;
|
||||
}
|
||||
|
||||
static void storage_cli_extract(Cli* cli, FuriString* old_path, FuriString* args) {
|
||||
UNUSED(cli);
|
||||
static void storage_cli_extract(PipeSide* pipe, FuriString* old_path, FuriString* args) {
|
||||
UNUSED(pipe);
|
||||
FuriString* new_path = furi_string_alloc();
|
||||
|
||||
if(!args_read_probably_quoted_string_and_trim(args, new_path)) {
|
||||
@@ -526,7 +535,7 @@ static void storage_cli_extract(Cli* cli, FuriString* old_path, FuriString* args
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
typedef void (*StorageCliCommandCallback)(Cli* cli, FuriString* path, FuriString* args);
|
||||
typedef void (*StorageCliCommandCallback)(PipeSide* pipe, FuriString* path, FuriString* args);
|
||||
|
||||
typedef struct {
|
||||
const char* command;
|
||||
@@ -631,7 +640,7 @@ static void storage_cli_print_usage(void) {
|
||||
}
|
||||
}
|
||||
|
||||
void storage_cli(Cli* cli, FuriString* args, void* context) {
|
||||
void storage_cli(PipeSide* pipe, FuriString* args, void* context) {
|
||||
UNUSED(context);
|
||||
FuriString* cmd;
|
||||
FuriString* path;
|
||||
@@ -653,7 +662,7 @@ void storage_cli(Cli* cli, FuriString* args, void* context) {
|
||||
for(; i < COUNT_OF(storage_cli_commands); ++i) {
|
||||
const StorageCliCommand* command_descr = &storage_cli_commands[i];
|
||||
if(furi_string_cmp_str(cmd, command_descr->command) == 0) {
|
||||
command_descr->impl(cli, path, args);
|
||||
command_descr->impl(pipe, path, args);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -667,11 +676,12 @@ void storage_cli(Cli* cli, FuriString* args, void* context) {
|
||||
furi_string_free(cmd);
|
||||
}
|
||||
|
||||
static void storage_cli_factory_reset(Cli* cli, FuriString* args, void* context) {
|
||||
static void storage_cli_factory_reset(PipeSide* pipe, FuriString* args, void* context) {
|
||||
UNUSED(pipe);
|
||||
UNUSED(args);
|
||||
UNUSED(context);
|
||||
printf("All data will be lost! Are you sure (y/n)?\r\n");
|
||||
char c = cli_getc(cli);
|
||||
char c = getchar();
|
||||
if(c == 'y' || c == 'Y') {
|
||||
printf("Data will be wiped after reboot.\r\n");
|
||||
|
||||
@@ -687,10 +697,15 @@ static void storage_cli_factory_reset(Cli* cli, FuriString* args, void* context)
|
||||
|
||||
void storage_on_system_start(void) {
|
||||
#ifdef SRV_CLI
|
||||
Cli* cli = furi_record_open(RECORD_CLI);
|
||||
cli_add_command(cli, RECORD_STORAGE, CliCommandFlagParallelSafe, storage_cli, NULL);
|
||||
cli_add_command(
|
||||
cli, "factory_reset", CliCommandFlagParallelSafe, storage_cli_factory_reset, NULL);
|
||||
CliRegistry* registry = furi_record_open(RECORD_CLI);
|
||||
cli_registry_add_command(
|
||||
registry,
|
||||
"storage",
|
||||
CliCommandFlagParallelSafe | CliCommandFlagUseShellThread,
|
||||
storage_cli,
|
||||
NULL);
|
||||
cli_registry_add_command(
|
||||
registry, "factory_reset", CliCommandFlagParallelSafe, storage_cli_factory_reset, NULL);
|
||||
furi_record_close(RECORD_CLI);
|
||||
#else
|
||||
UNUSED(storage_cli_factory_reset);
|
||||
|
||||
Reference in New Issue
Block a user