RPC: more asserts and checks (#1606)
Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
parent
4e1470cef2
commit
84e2e321b4
@ -80,13 +80,11 @@ struct Rpc {
|
||||
FuriMutex* busy_mutex;
|
||||
};
|
||||
|
||||
static bool content_callback(pb_istream_t* stream, const pb_field_t* field, void** arg);
|
||||
|
||||
static void rpc_close_session_process(const PB_Main* request, void* context) {
|
||||
furi_assert(request);
|
||||
furi_assert(context);
|
||||
|
||||
RpcSession* session = (RpcSession*)context;
|
||||
furi_assert(session);
|
||||
|
||||
rpc_send_and_release_empty(session, request->command_id, PB_CommandStatus_OK);
|
||||
furi_mutex_acquire(session->callbacks_mutex, FuriWaitForever);
|
||||
@ -98,264 +96,6 @@ static void rpc_close_session_process(const PB_Main* request, void* context) {
|
||||
furi_mutex_release(session->callbacks_mutex);
|
||||
}
|
||||
|
||||
static size_t rpc_sprintf_msg_file(
|
||||
string_t str,
|
||||
const char* prefix,
|
||||
const PB_Storage_File* msg_file,
|
||||
size_t msg_files_size) {
|
||||
size_t cnt = 0;
|
||||
|
||||
for(size_t i = 0; i < msg_files_size; ++i, ++msg_file) {
|
||||
string_cat_printf(
|
||||
str,
|
||||
"%s[%c] size: %5ld",
|
||||
prefix,
|
||||
msg_file->type == PB_Storage_File_FileType_DIR ? 'd' : 'f',
|
||||
msg_file->size);
|
||||
|
||||
if(msg_file->name) {
|
||||
string_cat_printf(str, " \'%s\'", msg_file->name);
|
||||
}
|
||||
|
||||
if(msg_file->data && msg_file->data->size) {
|
||||
string_cat_printf(
|
||||
str,
|
||||
" (%d):\'%.*s%s\'",
|
||||
msg_file->data->size,
|
||||
MIN(msg_file->data->size, 30),
|
||||
msg_file->data->bytes,
|
||||
msg_file->data->size > 30 ? "..." : "");
|
||||
}
|
||||
|
||||
string_cat_printf(str, "\r\n");
|
||||
}
|
||||
|
||||
return cnt;
|
||||
}
|
||||
|
||||
void rpc_print_data(const char* prefix, uint8_t* buffer, size_t size) {
|
||||
string_t str;
|
||||
string_init(str);
|
||||
string_reserve(str, 100 + size * 5);
|
||||
|
||||
string_cat_printf(str, "\r\n%s DEC(%d): {", prefix, size);
|
||||
for(size_t i = 0; i < size; ++i) {
|
||||
string_cat_printf(str, "%d, ", buffer[i]);
|
||||
}
|
||||
string_cat_printf(str, "}\r\n");
|
||||
|
||||
printf("%s", string_get_cstr(str));
|
||||
string_reset(str);
|
||||
string_reserve(str, 100 + size * 3);
|
||||
|
||||
string_cat_printf(str, "%s HEX(%d): {", prefix, size);
|
||||
for(size_t i = 0; i < size; ++i) {
|
||||
string_cat_printf(str, "%02X", buffer[i]);
|
||||
}
|
||||
string_cat_printf(str, "}\r\n\r\n");
|
||||
|
||||
printf("%s", string_get_cstr(str));
|
||||
string_clear(str);
|
||||
}
|
||||
|
||||
void rpc_print_message(const PB_Main* message) {
|
||||
string_t str;
|
||||
string_init(str);
|
||||
|
||||
string_cat_printf(
|
||||
str,
|
||||
"PB_Main: {\r\n\tresult: %d cmd_id: %ld (%s)\r\n",
|
||||
message->command_status,
|
||||
message->command_id,
|
||||
message->has_next ? "has_next" : "last");
|
||||
switch(message->which_content) {
|
||||
default:
|
||||
/* not implemented yet */
|
||||
string_cat_printf(str, "\tNOT_IMPLEMENTED (%d) {\r\n", message->which_content);
|
||||
break;
|
||||
case PB_Main_stop_session_tag:
|
||||
string_cat_printf(str, "\tstop_session {\r\n");
|
||||
break;
|
||||
case PB_Main_app_start_request_tag: {
|
||||
string_cat_printf(str, "\tapp_start {\r\n");
|
||||
const char* name = message->content.app_start_request.name;
|
||||
const char* args = message->content.app_start_request.args;
|
||||
if(name) {
|
||||
string_cat_printf(str, "\t\tname: %s\r\n", name);
|
||||
}
|
||||
if(args) {
|
||||
string_cat_printf(str, "\t\targs: %s\r\n", args);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PB_Main_app_lock_status_request_tag: {
|
||||
string_cat_printf(str, "\tapp_lock_status_request {\r\n");
|
||||
break;
|
||||
}
|
||||
case PB_Main_app_lock_status_response_tag: {
|
||||
string_cat_printf(str, "\tapp_lock_status_response {\r\n");
|
||||
bool lock_status = message->content.app_lock_status_response.locked;
|
||||
string_cat_printf(str, "\t\tlocked: %s\r\n", lock_status ? "true" : "false");
|
||||
break;
|
||||
}
|
||||
case PB_Main_storage_md5sum_request_tag: {
|
||||
string_cat_printf(str, "\tmd5sum_request {\r\n");
|
||||
const char* path = message->content.storage_md5sum_request.path;
|
||||
if(path) {
|
||||
string_cat_printf(str, "\t\tpath: %s\r\n", path);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PB_Main_storage_md5sum_response_tag: {
|
||||
string_cat_printf(str, "\tmd5sum_response {\r\n");
|
||||
const char* path = message->content.storage_md5sum_response.md5sum;
|
||||
if(path) {
|
||||
string_cat_printf(str, "\t\tmd5sum: %s\r\n", path);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PB_Main_system_ping_request_tag:
|
||||
string_cat_printf(str, "\tping_request {\r\n");
|
||||
break;
|
||||
case PB_Main_system_ping_response_tag:
|
||||
string_cat_printf(str, "\tping_response {\r\n");
|
||||
break;
|
||||
case PB_Main_system_device_info_request_tag:
|
||||
string_cat_printf(str, "\tdevice_info_request {\r\n");
|
||||
break;
|
||||
case PB_Main_system_device_info_response_tag:
|
||||
string_cat_printf(str, "\tdevice_info_response {\r\n");
|
||||
string_cat_printf(
|
||||
str,
|
||||
"\t\t%s: %s\r\n",
|
||||
message->content.system_device_info_response.key,
|
||||
message->content.system_device_info_response.value);
|
||||
break;
|
||||
case PB_Main_storage_mkdir_request_tag:
|
||||
string_cat_printf(str, "\tmkdir {\r\n");
|
||||
break;
|
||||
case PB_Main_storage_delete_request_tag: {
|
||||
string_cat_printf(str, "\tdelete {\r\n");
|
||||
const char* path = message->content.storage_delete_request.path;
|
||||
if(path) {
|
||||
string_cat_printf(str, "\t\tpath: %s\r\n", path);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PB_Main_empty_tag:
|
||||
string_cat_printf(str, "\tempty {\r\n");
|
||||
break;
|
||||
case PB_Main_storage_info_request_tag: {
|
||||
string_cat_printf(str, "\tinfo_request {\r\n");
|
||||
const char* path = message->content.storage_info_request.path;
|
||||
if(path) {
|
||||
string_cat_printf(str, "\t\tpath: %s\r\n", path);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PB_Main_storage_info_response_tag: {
|
||||
string_cat_printf(str, "\tinfo_response {\r\n");
|
||||
string_cat_printf(
|
||||
str, "\t\ttotal_space: %lu\r\n", message->content.storage_info_response.total_space);
|
||||
string_cat_printf(
|
||||
str, "\t\tfree_space: %lu\r\n", message->content.storage_info_response.free_space);
|
||||
break;
|
||||
}
|
||||
case PB_Main_storage_stat_request_tag: {
|
||||
string_cat_printf(str, "\tstat_request {\r\n");
|
||||
const char* path = message->content.storage_stat_request.path;
|
||||
if(path) {
|
||||
string_cat_printf(str, "\t\tpath: %s\r\n", path);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PB_Main_storage_stat_response_tag: {
|
||||
string_cat_printf(str, "\tstat_response {\r\n");
|
||||
if(message->content.storage_stat_response.has_file) {
|
||||
const PB_Storage_File* msg_file = &message->content.storage_stat_response.file;
|
||||
rpc_sprintf_msg_file(str, "\t\t\t", msg_file, 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PB_Main_storage_list_request_tag: {
|
||||
string_cat_printf(str, "\tlist_request {\r\n");
|
||||
const char* path = message->content.storage_list_request.path;
|
||||
if(path) {
|
||||
string_cat_printf(str, "\t\tpath: %s\r\n", path);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PB_Main_storage_read_request_tag: {
|
||||
string_cat_printf(str, "\tread_request {\r\n");
|
||||
const char* path = message->content.storage_read_request.path;
|
||||
if(path) {
|
||||
string_cat_printf(str, "\t\tpath: %s\r\n", path);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PB_Main_storage_write_request_tag: {
|
||||
string_cat_printf(str, "\twrite_request {\r\n");
|
||||
const char* path = message->content.storage_write_request.path;
|
||||
if(path) {
|
||||
string_cat_printf(str, "\t\tpath: %s\r\n", path);
|
||||
}
|
||||
if(message->content.storage_write_request.has_file) {
|
||||
const PB_Storage_File* msg_file = &message->content.storage_write_request.file;
|
||||
rpc_sprintf_msg_file(str, "\t\t\t", msg_file, 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PB_Main_storage_read_response_tag:
|
||||
string_cat_printf(str, "\tread_response {\r\n");
|
||||
if(message->content.storage_read_response.has_file) {
|
||||
const PB_Storage_File* msg_file = &message->content.storage_read_response.file;
|
||||
rpc_sprintf_msg_file(str, "\t\t\t", msg_file, 1);
|
||||
}
|
||||
break;
|
||||
case PB_Main_storage_list_response_tag: {
|
||||
const PB_Storage_File* msg_file = message->content.storage_list_response.file;
|
||||
size_t msg_file_count = message->content.storage_list_response.file_count;
|
||||
string_cat_printf(str, "\tlist_response {\r\n");
|
||||
rpc_sprintf_msg_file(str, "\t\t", msg_file, msg_file_count);
|
||||
break;
|
||||
}
|
||||
case PB_Main_storage_rename_request_tag: {
|
||||
string_cat_printf(str, "\trename_request {\r\n");
|
||||
string_cat_printf(
|
||||
str, "\t\told_path: %s\r\n", message->content.storage_rename_request.old_path);
|
||||
string_cat_printf(
|
||||
str, "\t\tnew_path: %s\r\n", message->content.storage_rename_request.new_path);
|
||||
break;
|
||||
}
|
||||
case PB_Main_gui_start_screen_stream_request_tag:
|
||||
string_cat_printf(str, "\tstart_screen_stream {\r\n");
|
||||
break;
|
||||
case PB_Main_gui_stop_screen_stream_request_tag:
|
||||
string_cat_printf(str, "\tstop_screen_stream {\r\n");
|
||||
break;
|
||||
case PB_Main_gui_screen_frame_tag:
|
||||
string_cat_printf(str, "\tscreen_frame {\r\n");
|
||||
break;
|
||||
case PB_Main_gui_send_input_event_request_tag:
|
||||
string_cat_printf(str, "\tsend_input_event {\r\n");
|
||||
string_cat_printf(
|
||||
str, "\t\tkey: %d\r\n", message->content.gui_send_input_event_request.key);
|
||||
string_cat_printf(
|
||||
str, "\t\type: %d\r\n", message->content.gui_send_input_event_request.type);
|
||||
break;
|
||||
case PB_Main_gui_start_virtual_display_request_tag:
|
||||
string_cat_printf(str, "\tstart_virtual_display {\r\n");
|
||||
break;
|
||||
case PB_Main_gui_stop_virtual_display_request_tag:
|
||||
string_cat_printf(str, "\tstop_virtual_display {\r\n");
|
||||
break;
|
||||
}
|
||||
string_cat_printf(str, "\t}\r\n}\r\n");
|
||||
printf("%s", string_get_cstr(str));
|
||||
|
||||
string_clear(str);
|
||||
}
|
||||
|
||||
void rpc_session_set_context(RpcSession* session, void* context) {
|
||||
furi_assert(session);
|
||||
|
||||
@ -409,6 +149,9 @@ void rpc_session_set_terminated_callback(
|
||||
size_t
|
||||
rpc_session_feed(RpcSession* session, uint8_t* encoded_bytes, size_t size, TickType_t timeout) {
|
||||
furi_assert(session);
|
||||
furi_assert(encoded_bytes);
|
||||
furi_assert(size > 0);
|
||||
|
||||
size_t bytes_sent = xStreamBufferSend(session->stream, encoded_bytes, size, timeout);
|
||||
|
||||
furi_thread_flags_set(furi_thread_get_id(session->thread), RpcEvtNewData);
|
||||
@ -422,6 +165,8 @@ size_t rpc_session_get_available_size(RpcSession* session) {
|
||||
}
|
||||
|
||||
bool rpc_pb_stream_read(pb_istream_t* istream, pb_byte_t* buf, size_t count) {
|
||||
furi_assert(istream);
|
||||
furi_assert(buf);
|
||||
RpcSession* session = istream->state;
|
||||
furi_assert(session);
|
||||
furi_assert(istream->bytes_left);
|
||||
@ -462,16 +207,17 @@ bool rpc_pb_stream_read(pb_istream_t* istream, pb_byte_t* buf, size_t count) {
|
||||
}
|
||||
|
||||
#if SRV_RPC_DEBUG
|
||||
rpc_print_data("INPUT", buf, bytes_received);
|
||||
rpc_debug_print_data("INPUT", buf, bytes_received);
|
||||
#endif
|
||||
|
||||
return (count == bytes_received);
|
||||
}
|
||||
|
||||
static bool content_callback(pb_istream_t* stream, const pb_field_t* field, void** arg) {
|
||||
static bool rpc_pb_content_callback(pb_istream_t* stream, const pb_field_t* field, void** arg) {
|
||||
furi_assert(stream);
|
||||
RpcSession* session = stream->state;
|
||||
furi_assert(session);
|
||||
furi_assert(field);
|
||||
|
||||
RpcHandler* handler = RpcHandlerDict_get(session->handlers, field->tag);
|
||||
|
||||
@ -502,7 +248,7 @@ static int32_t rpc_session_worker(void* context) {
|
||||
if(pb_decode_ex(&istream, &PB_Main_msg, session->decoded_message, PB_DECODE_DELIMITED)) {
|
||||
#if SRV_RPC_DEBUG
|
||||
FURI_LOG_I(TAG, "INPUT:");
|
||||
rpc_print_message(session->decoded_message);
|
||||
rpc_debug_print_message(session->decoded_message);
|
||||
#endif
|
||||
RpcHandler* handler =
|
||||
RpcHandlerDict_get(session->handlers, session->decoded_message->which_content);
|
||||
@ -610,7 +356,7 @@ RpcSession* rpc_session_open(Rpc* rpc) {
|
||||
RpcHandlerDict_init(session->handlers);
|
||||
|
||||
session->decoded_message = malloc(sizeof(PB_Main));
|
||||
session->decoded_message->cb_content.funcs.decode = content_callback;
|
||||
session->decoded_message->cb_content.funcs.decode = rpc_pb_content_callback;
|
||||
session->decoded_message->cb_content.arg = session;
|
||||
|
||||
session->system_contexts = malloc(COUNT_OF(rpc_systems) * sizeof(void*));
|
||||
@ -678,7 +424,7 @@ void rpc_send(RpcSession* session, PB_Main* message) {
|
||||
|
||||
#if SRV_RPC_DEBUG
|
||||
FURI_LOG_I(TAG, "OUTPUT:");
|
||||
rpc_print_message(message);
|
||||
rpc_debug_print_message(message);
|
||||
#endif
|
||||
|
||||
bool result = pb_encode_ex(&ostream, &PB_Main_msg, message, PB_ENCODE_DELIMITED);
|
||||
@ -690,7 +436,7 @@ void rpc_send(RpcSession* session, PB_Main* message) {
|
||||
pb_encode_ex(&ostream, &PB_Main_msg, message, PB_ENCODE_DELIMITED);
|
||||
|
||||
#if SRV_RPC_DEBUG
|
||||
rpc_print_data("OUTPUT", buffer, ostream.bytes_written);
|
||||
rpc_debug_print_data("OUTPUT", buffer, ostream.bytes_written);
|
||||
#endif
|
||||
|
||||
furi_mutex_acquire(session->callbacks_mutex, FuriWaitForever);
|
||||
|
@ -299,6 +299,7 @@ void* rpc_system_app_alloc(RpcSession* session) {
|
||||
|
||||
void rpc_system_app_free(void* context) {
|
||||
RpcAppSystem* rpc_app = context;
|
||||
furi_assert(rpc_app);
|
||||
RpcSession* session = rpc_app->session;
|
||||
furi_assert(session);
|
||||
|
||||
|
@ -14,23 +14,23 @@ typedef struct {
|
||||
|
||||
#define CLI_READ_BUFFER_SIZE 64
|
||||
|
||||
static void rpc_send_bytes_callback(void* context, uint8_t* bytes, size_t bytes_len) {
|
||||
static void rpc_cli_send_bytes_callback(void* context, uint8_t* bytes, size_t bytes_len) {
|
||||
furi_assert(context);
|
||||
furi_assert(bytes);
|
||||
furi_assert(bytes_len);
|
||||
furi_assert(bytes_len > 0);
|
||||
CliRpc* cli_rpc = context;
|
||||
|
||||
cli_write(cli_rpc->cli, bytes, bytes_len);
|
||||
}
|
||||
|
||||
static void rpc_session_close_callback(void* context) {
|
||||
static void rpc_cli_session_close_callback(void* context) {
|
||||
furi_assert(context);
|
||||
CliRpc* cli_rpc = context;
|
||||
|
||||
cli_rpc->session_close_request = true;
|
||||
}
|
||||
|
||||
static void rpc_session_terminated_callback(void* context) {
|
||||
static void rpc_cli_session_terminated_callback(void* context) {
|
||||
furi_check(context);
|
||||
CliRpc* cli_rpc = context;
|
||||
|
||||
@ -39,6 +39,8 @@ static void rpc_session_terminated_callback(void* context) {
|
||||
|
||||
void rpc_cli_command_start_session(Cli* cli, string_t args, void* context) {
|
||||
UNUSED(args);
|
||||
furi_assert(cli);
|
||||
furi_assert(context);
|
||||
Rpc* rpc = context;
|
||||
|
||||
uint32_t mem_before = memmgr_get_free_heap();
|
||||
@ -55,9 +57,9 @@ void rpc_cli_command_start_session(Cli* cli, string_t args, void* context) {
|
||||
CliRpc cli_rpc = {.cli = cli, .session_close_request = false};
|
||||
cli_rpc.terminate_semaphore = furi_semaphore_alloc(1, 0);
|
||||
rpc_session_set_context(rpc_session, &cli_rpc);
|
||||
rpc_session_set_send_bytes_callback(rpc_session, rpc_send_bytes_callback);
|
||||
rpc_session_set_close_callback(rpc_session, rpc_session_close_callback);
|
||||
rpc_session_set_terminated_callback(rpc_session, rpc_session_terminated_callback);
|
||||
rpc_session_set_send_bytes_callback(rpc_session, rpc_cli_send_bytes_callback);
|
||||
rpc_session_set_close_callback(rpc_session, rpc_cli_session_close_callback);
|
||||
rpc_session_set_terminated_callback(rpc_session, rpc_cli_session_terminated_callback);
|
||||
|
||||
uint8_t* buffer = malloc(CLI_READ_BUFFER_SIZE);
|
||||
size_t size_received = 0;
|
||||
|
260
applications/rpc/rpc_debug.c
Normal file
260
applications/rpc/rpc_debug.c
Normal file
@ -0,0 +1,260 @@
|
||||
#include "rpc_i.h"
|
||||
#include <m-string.h>
|
||||
|
||||
static size_t rpc_debug_print_file_msg(
|
||||
string_t str,
|
||||
const char* prefix,
|
||||
const PB_Storage_File* msg_file,
|
||||
size_t msg_files_size) {
|
||||
size_t cnt = 0;
|
||||
|
||||
for(size_t i = 0; i < msg_files_size; ++i, ++msg_file) {
|
||||
string_cat_printf(
|
||||
str,
|
||||
"%s[%c] size: %5ld",
|
||||
prefix,
|
||||
msg_file->type == PB_Storage_File_FileType_DIR ? 'd' : 'f',
|
||||
msg_file->size);
|
||||
|
||||
if(msg_file->name) {
|
||||
string_cat_printf(str, " \'%s\'", msg_file->name);
|
||||
}
|
||||
|
||||
if(msg_file->data && msg_file->data->size) {
|
||||
string_cat_printf(
|
||||
str,
|
||||
" (%d):\'%.*s%s\'",
|
||||
msg_file->data->size,
|
||||
MIN(msg_file->data->size, 30),
|
||||
msg_file->data->bytes,
|
||||
msg_file->data->size > 30 ? "..." : "");
|
||||
}
|
||||
|
||||
string_cat_printf(str, "\r\n");
|
||||
}
|
||||
|
||||
return cnt;
|
||||
}
|
||||
|
||||
void rpc_debug_print_data(const char* prefix, uint8_t* buffer, size_t size) {
|
||||
string_t str;
|
||||
string_init(str);
|
||||
string_reserve(str, 100 + size * 5);
|
||||
|
||||
string_cat_printf(str, "\r\n%s DEC(%d): {", prefix, size);
|
||||
for(size_t i = 0; i < size; ++i) {
|
||||
string_cat_printf(str, "%d, ", buffer[i]);
|
||||
}
|
||||
string_cat_printf(str, "}\r\n");
|
||||
|
||||
printf("%s", string_get_cstr(str));
|
||||
string_reset(str);
|
||||
string_reserve(str, 100 + size * 3);
|
||||
|
||||
string_cat_printf(str, "%s HEX(%d): {", prefix, size);
|
||||
for(size_t i = 0; i < size; ++i) {
|
||||
string_cat_printf(str, "%02X", buffer[i]);
|
||||
}
|
||||
string_cat_printf(str, "}\r\n\r\n");
|
||||
|
||||
printf("%s", string_get_cstr(str));
|
||||
string_clear(str);
|
||||
}
|
||||
|
||||
void rpc_debug_print_message(const PB_Main* message) {
|
||||
string_t str;
|
||||
string_init(str);
|
||||
|
||||
string_cat_printf(
|
||||
str,
|
||||
"PB_Main: {\r\n\tresult: %d cmd_id: %ld (%s)\r\n",
|
||||
message->command_status,
|
||||
message->command_id,
|
||||
message->has_next ? "has_next" : "last");
|
||||
switch(message->which_content) {
|
||||
default:
|
||||
/* not implemented yet */
|
||||
string_cat_printf(str, "\tNOT_IMPLEMENTED (%d) {\r\n", message->which_content);
|
||||
break;
|
||||
case PB_Main_stop_session_tag:
|
||||
string_cat_printf(str, "\tstop_session {\r\n");
|
||||
break;
|
||||
case PB_Main_app_start_request_tag: {
|
||||
string_cat_printf(str, "\tapp_start {\r\n");
|
||||
const char* name = message->content.app_start_request.name;
|
||||
const char* args = message->content.app_start_request.args;
|
||||
if(name) {
|
||||
string_cat_printf(str, "\t\tname: %s\r\n", name);
|
||||
}
|
||||
if(args) {
|
||||
string_cat_printf(str, "\t\targs: %s\r\n", args);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PB_Main_app_lock_status_request_tag: {
|
||||
string_cat_printf(str, "\tapp_lock_status_request {\r\n");
|
||||
break;
|
||||
}
|
||||
case PB_Main_app_lock_status_response_tag: {
|
||||
string_cat_printf(str, "\tapp_lock_status_response {\r\n");
|
||||
bool lock_status = message->content.app_lock_status_response.locked;
|
||||
string_cat_printf(str, "\t\tlocked: %s\r\n", lock_status ? "true" : "false");
|
||||
break;
|
||||
}
|
||||
case PB_Main_storage_md5sum_request_tag: {
|
||||
string_cat_printf(str, "\tmd5sum_request {\r\n");
|
||||
const char* path = message->content.storage_md5sum_request.path;
|
||||
if(path) {
|
||||
string_cat_printf(str, "\t\tpath: %s\r\n", path);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PB_Main_storage_md5sum_response_tag: {
|
||||
string_cat_printf(str, "\tmd5sum_response {\r\n");
|
||||
const char* path = message->content.storage_md5sum_response.md5sum;
|
||||
if(path) {
|
||||
string_cat_printf(str, "\t\tmd5sum: %s\r\n", path);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PB_Main_system_ping_request_tag:
|
||||
string_cat_printf(str, "\tping_request {\r\n");
|
||||
break;
|
||||
case PB_Main_system_ping_response_tag:
|
||||
string_cat_printf(str, "\tping_response {\r\n");
|
||||
break;
|
||||
case PB_Main_system_device_info_request_tag:
|
||||
string_cat_printf(str, "\tdevice_info_request {\r\n");
|
||||
break;
|
||||
case PB_Main_system_device_info_response_tag:
|
||||
string_cat_printf(str, "\tdevice_info_response {\r\n");
|
||||
string_cat_printf(
|
||||
str,
|
||||
"\t\t%s: %s\r\n",
|
||||
message->content.system_device_info_response.key,
|
||||
message->content.system_device_info_response.value);
|
||||
break;
|
||||
case PB_Main_storage_mkdir_request_tag:
|
||||
string_cat_printf(str, "\tmkdir {\r\n");
|
||||
break;
|
||||
case PB_Main_storage_delete_request_tag: {
|
||||
string_cat_printf(str, "\tdelete {\r\n");
|
||||
const char* path = message->content.storage_delete_request.path;
|
||||
if(path) {
|
||||
string_cat_printf(str, "\t\tpath: %s\r\n", path);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PB_Main_empty_tag:
|
||||
string_cat_printf(str, "\tempty {\r\n");
|
||||
break;
|
||||
case PB_Main_storage_info_request_tag: {
|
||||
string_cat_printf(str, "\tinfo_request {\r\n");
|
||||
const char* path = message->content.storage_info_request.path;
|
||||
if(path) {
|
||||
string_cat_printf(str, "\t\tpath: %s\r\n", path);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PB_Main_storage_info_response_tag: {
|
||||
string_cat_printf(str, "\tinfo_response {\r\n");
|
||||
string_cat_printf(
|
||||
str, "\t\ttotal_space: %lu\r\n", message->content.storage_info_response.total_space);
|
||||
string_cat_printf(
|
||||
str, "\t\tfree_space: %lu\r\n", message->content.storage_info_response.free_space);
|
||||
break;
|
||||
}
|
||||
case PB_Main_storage_stat_request_tag: {
|
||||
string_cat_printf(str, "\tstat_request {\r\n");
|
||||
const char* path = message->content.storage_stat_request.path;
|
||||
if(path) {
|
||||
string_cat_printf(str, "\t\tpath: %s\r\n", path);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PB_Main_storage_stat_response_tag: {
|
||||
string_cat_printf(str, "\tstat_response {\r\n");
|
||||
if(message->content.storage_stat_response.has_file) {
|
||||
const PB_Storage_File* msg_file = &message->content.storage_stat_response.file;
|
||||
rpc_debug_print_file_msg(str, "\t\t\t", msg_file, 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PB_Main_storage_list_request_tag: {
|
||||
string_cat_printf(str, "\tlist_request {\r\n");
|
||||
const char* path = message->content.storage_list_request.path;
|
||||
if(path) {
|
||||
string_cat_printf(str, "\t\tpath: %s\r\n", path);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PB_Main_storage_read_request_tag: {
|
||||
string_cat_printf(str, "\tread_request {\r\n");
|
||||
const char* path = message->content.storage_read_request.path;
|
||||
if(path) {
|
||||
string_cat_printf(str, "\t\tpath: %s\r\n", path);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PB_Main_storage_write_request_tag: {
|
||||
string_cat_printf(str, "\twrite_request {\r\n");
|
||||
const char* path = message->content.storage_write_request.path;
|
||||
if(path) {
|
||||
string_cat_printf(str, "\t\tpath: %s\r\n", path);
|
||||
}
|
||||
if(message->content.storage_write_request.has_file) {
|
||||
const PB_Storage_File* msg_file = &message->content.storage_write_request.file;
|
||||
rpc_debug_print_file_msg(str, "\t\t\t", msg_file, 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PB_Main_storage_read_response_tag:
|
||||
string_cat_printf(str, "\tread_response {\r\n");
|
||||
if(message->content.storage_read_response.has_file) {
|
||||
const PB_Storage_File* msg_file = &message->content.storage_read_response.file;
|
||||
rpc_debug_print_file_msg(str, "\t\t\t", msg_file, 1);
|
||||
}
|
||||
break;
|
||||
case PB_Main_storage_list_response_tag: {
|
||||
const PB_Storage_File* msg_file = message->content.storage_list_response.file;
|
||||
size_t msg_file_count = message->content.storage_list_response.file_count;
|
||||
string_cat_printf(str, "\tlist_response {\r\n");
|
||||
rpc_debug_print_file_msg(str, "\t\t", msg_file, msg_file_count);
|
||||
break;
|
||||
}
|
||||
case PB_Main_storage_rename_request_tag: {
|
||||
string_cat_printf(str, "\trename_request {\r\n");
|
||||
string_cat_printf(
|
||||
str, "\t\told_path: %s\r\n", message->content.storage_rename_request.old_path);
|
||||
string_cat_printf(
|
||||
str, "\t\tnew_path: %s\r\n", message->content.storage_rename_request.new_path);
|
||||
break;
|
||||
}
|
||||
case PB_Main_gui_start_screen_stream_request_tag:
|
||||
string_cat_printf(str, "\tstart_screen_stream {\r\n");
|
||||
break;
|
||||
case PB_Main_gui_stop_screen_stream_request_tag:
|
||||
string_cat_printf(str, "\tstop_screen_stream {\r\n");
|
||||
break;
|
||||
case PB_Main_gui_screen_frame_tag:
|
||||
string_cat_printf(str, "\tscreen_frame {\r\n");
|
||||
break;
|
||||
case PB_Main_gui_send_input_event_request_tag:
|
||||
string_cat_printf(str, "\tsend_input_event {\r\n");
|
||||
string_cat_printf(
|
||||
str, "\t\tkey: %d\r\n", message->content.gui_send_input_event_request.key);
|
||||
string_cat_printf(
|
||||
str, "\t\type: %d\r\n", message->content.gui_send_input_event_request.type);
|
||||
break;
|
||||
case PB_Main_gui_start_virtual_display_request_tag:
|
||||
string_cat_printf(str, "\tstart_virtual_display {\r\n");
|
||||
break;
|
||||
case PB_Main_gui_stop_virtual_display_request_tag:
|
||||
string_cat_printf(str, "\tstop_virtual_display {\r\n");
|
||||
break;
|
||||
}
|
||||
string_cat_printf(str, "\t}\r\n}\r\n");
|
||||
printf("%s", string_get_cstr(str));
|
||||
|
||||
string_clear(str);
|
||||
}
|
@ -57,7 +57,6 @@ static void rpc_system_gpio_set_pin_mode(const PB_Main* request, void* context)
|
||||
furi_assert(request->which_content == PB_Main_gpio_set_pin_mode_tag);
|
||||
|
||||
RpcSession* session = context;
|
||||
furi_assert(session);
|
||||
|
||||
PB_Gpio_SetPinMode cmd = request->content.gpio_set_pin_mode;
|
||||
const GpioPin* pin = rpc_pin_to_hal_pin(cmd.pin);
|
||||
@ -77,7 +76,6 @@ static void rpc_system_gpio_write_pin(const PB_Main* request, void* context) {
|
||||
furi_assert(request->which_content == PB_Main_gpio_write_pin_tag);
|
||||
|
||||
RpcSession* session = context;
|
||||
furi_assert(session);
|
||||
|
||||
PB_Gpio_WritePin cmd = request->content.gpio_write_pin;
|
||||
const GpioPin* pin = rpc_pin_to_hal_pin(cmd.pin);
|
||||
@ -105,7 +103,6 @@ static void rpc_system_gpio_read_pin(const PB_Main* request, void* context) {
|
||||
furi_assert(request->which_content == PB_Main_gpio_read_pin_tag);
|
||||
|
||||
RpcSession* session = context;
|
||||
furi_assert(session);
|
||||
|
||||
PB_Gpio_ReadPin cmd = request->content.gpio_read_pin;
|
||||
const GpioPin* pin = rpc_pin_to_hal_pin(cmd.pin);
|
||||
@ -133,7 +130,6 @@ void rpc_system_gpio_get_pin_mode(const PB_Main* request, void* context) {
|
||||
furi_assert(request->which_content == PB_Main_gpio_get_pin_mode_tag);
|
||||
|
||||
RpcSession* session = context;
|
||||
furi_assert(session);
|
||||
|
||||
PB_Gpio_GetPinMode cmd = request->content.gpio_get_pin_mode;
|
||||
const GpioPin* pin = rpc_pin_to_hal_pin(cmd.pin);
|
||||
@ -170,7 +166,6 @@ void rpc_system_gpio_set_input_pull(const PB_Main* request, void* context) {
|
||||
furi_assert(request->which_content == PB_Main_gpio_set_input_pull_tag);
|
||||
|
||||
RpcSession* session = context;
|
||||
furi_assert(session);
|
||||
|
||||
PB_Gpio_SetInputPull cmd = request->content.gpio_set_input_pull;
|
||||
const GpioPin* pin = rpc_pin_to_hal_pin(cmd.pin);
|
||||
|
@ -35,7 +35,9 @@ void rpc_system_gui_free(void* ctx);
|
||||
void* rpc_system_gpio_alloc(RpcSession* session);
|
||||
void rpc_system_gpio_free(void* ctx);
|
||||
|
||||
void rpc_print_message(const PB_Main* message);
|
||||
void rpc_debug_print_message(const PB_Main* message);
|
||||
void rpc_debug_print_data(const char* prefix, uint8_t* buffer, size_t size);
|
||||
|
||||
void rpc_cli_command_start_session(Cli* cli, string_t args, void* context);
|
||||
|
||||
PB_CommandStatus rpc_system_storage_get_error(FS_Error fs_error);
|
||||
|
@ -37,6 +37,7 @@ static void rpc_system_storage_reset_state(
|
||||
RpcSession* session,
|
||||
bool send_error) {
|
||||
furi_assert(rpc_storage);
|
||||
furi_assert(session);
|
||||
|
||||
if(rpc_storage->state != RpcStorageStateIdle) {
|
||||
if(send_error) {
|
||||
@ -177,6 +178,8 @@ static void rpc_system_storage_stat_process(const PB_Main* request, void* contex
|
||||
}
|
||||
|
||||
static void rpc_system_storage_list_root(const PB_Main* request, void* context) {
|
||||
furi_assert(request);
|
||||
furi_assert(context);
|
||||
RpcStorageSystem* rpc_storage = context;
|
||||
RpcSession* session = rpc_storage->session;
|
||||
furi_assert(session);
|
||||
@ -411,6 +414,8 @@ static void rpc_system_storage_write_process(const PB_Main* request, void* conte
|
||||
}
|
||||
|
||||
static bool rpc_system_storage_is_dir_is_empty(Storage* fs_api, const char* path) {
|
||||
furi_assert(fs_api);
|
||||
furi_assert(path);
|
||||
FileInfo fileinfo;
|
||||
bool is_dir_is_empty = true;
|
||||
FS_Error error = storage_common_stat(fs_api, path, &fileinfo);
|
||||
@ -605,6 +610,7 @@ static void rpc_system_storage_rename_process(const PB_Main* request, void* cont
|
||||
static void rpc_system_storage_backup_create_process(const PB_Main* request, void* context) {
|
||||
furi_assert(request);
|
||||
furi_assert(request->which_content == PB_Main_storage_backup_create_request_tag);
|
||||
furi_assert(context);
|
||||
|
||||
FURI_LOG_D(TAG, "BackupCreate");
|
||||
|
||||
@ -626,6 +632,7 @@ static void rpc_system_storage_backup_create_process(const PB_Main* request, voi
|
||||
static void rpc_system_storage_backup_restore_process(const PB_Main* request, void* context) {
|
||||
furi_assert(request);
|
||||
furi_assert(request->which_content == PB_Main_storage_backup_restore_request_tag);
|
||||
furi_assert(context);
|
||||
|
||||
FURI_LOG_D(TAG, "BackupRestore");
|
||||
|
||||
@ -695,6 +702,7 @@ void* rpc_system_storage_alloc(RpcSession* session) {
|
||||
}
|
||||
|
||||
void rpc_system_storage_free(void* context) {
|
||||
furi_assert(context);
|
||||
RpcStorageSystem* rpc_storage = context;
|
||||
RpcSession* session = rpc_storage->session;
|
||||
furi_assert(session);
|
||||
|
@ -77,6 +77,7 @@ static void rpc_system_system_device_info_callback(
|
||||
furi_assert(key);
|
||||
furi_assert(value);
|
||||
RpcSystemContext* ctx = context;
|
||||
furi_assert(ctx);
|
||||
|
||||
furi_assert(key);
|
||||
furi_assert(value);
|
||||
@ -233,6 +234,7 @@ static void rpc_system_system_power_info_callback(
|
||||
furi_assert(key);
|
||||
furi_assert(value);
|
||||
RpcSystemContext* ctx = context;
|
||||
furi_assert(ctx);
|
||||
|
||||
furi_assert(key);
|
||||
furi_assert(value);
|
||||
@ -297,6 +299,8 @@ static void rpc_system_system_update_request_process(const PB_Main* request, voi
|
||||
#endif
|
||||
|
||||
void* rpc_system_system_alloc(RpcSession* session) {
|
||||
furi_assert(session);
|
||||
|
||||
RpcHandler rpc_handler = {
|
||||
.message_handler = NULL,
|
||||
.decode_submessage = NULL,
|
||||
|
@ -215,7 +215,7 @@ static void test_rpc_print_message_list(MsgList_t msg_list) {
|
||||
MsgList_reverse(msg_list);
|
||||
for
|
||||
M_EACH(msg, msg_list, MsgList_t) {
|
||||
rpc_print_message(msg);
|
||||
rpc_debug_print_message(msg);
|
||||
}
|
||||
MsgList_reverse(msg_list);
|
||||
#else
|
||||
|
Loading…
Reference in New Issue
Block a user