Rpc: StorageInfo, StorageRename, SystemReboot, SystemDeviceInfo (bonus: +FuriHalInfo) (#862)
* Rpc: update protobuf sources * Rpc: rename Status to System * Rpc: implement StorageInfoRequest * Rpc: implement StorageRenameRequest * Rpc: implement SystemRebootRequest * FuriHal: introduce FuriHalInfo, refactor device_info * Rpc: implement DeviceInfoRequest * Rpc: use strdup where it suites the best. * Make: add do not page align data to linker flag. Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -33,7 +33,7 @@ typedef struct {
|
||||
|
||||
static RpcSystemCallbacks rpc_systems[] = {
|
||||
{
|
||||
.alloc = rpc_system_status_alloc,
|
||||
.alloc = rpc_system_system_alloc,
|
||||
.free = NULL,
|
||||
},
|
||||
{
|
||||
@@ -203,12 +203,23 @@ void rpc_print_message(const PB_Main* message) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PB_Main_ping_request_tag:
|
||||
case PB_Main_system_ping_request_tag:
|
||||
string_cat_printf(str, "\tping_request {\r\n");
|
||||
break;
|
||||
case PB_Main_ping_response_tag:
|
||||
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;
|
||||
@@ -223,6 +234,38 @@ void rpc_print_message(const PB_Main* message) {
|
||||
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;
|
||||
@@ -265,6 +308,14 @@ void rpc_print_message(const PB_Main* message) {
|
||||
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;
|
||||
|
@@ -21,7 +21,7 @@ void rpc_send_and_release(Rpc* rpc, PB_Main* main_message);
|
||||
void rpc_send_and_release_empty(Rpc* rpc, uint32_t command_id, PB_CommandStatus status);
|
||||
void rpc_add_handler(Rpc* rpc, pb_size_t message_tag, RpcHandler* handler);
|
||||
|
||||
void* rpc_system_status_alloc(Rpc* rpc);
|
||||
void* rpc_system_system_alloc(Rpc* rpc);
|
||||
void* rpc_system_storage_alloc(Rpc* rpc);
|
||||
void rpc_system_storage_free(void* ctx);
|
||||
void* rpc_system_app_alloc(Rpc* rpc);
|
||||
|
@@ -1,39 +0,0 @@
|
||||
#include "flipper.pb.h"
|
||||
#include "rpc_i.h"
|
||||
#include "status.pb.h"
|
||||
|
||||
void rpc_system_status_ping_process(const PB_Main* msg_request, void* context) {
|
||||
if(msg_request->has_next) {
|
||||
rpc_send_and_release_empty(
|
||||
context, msg_request->command_id, PB_CommandStatus_ERROR_INVALID_PARAMETERS);
|
||||
return;
|
||||
}
|
||||
|
||||
PB_Main msg_response = PB_Main_init_default;
|
||||
msg_response.has_next = false;
|
||||
msg_response.command_status = PB_CommandStatus_OK;
|
||||
msg_response.command_id = msg_request->command_id;
|
||||
msg_response.which_content = PB_Main_ping_response_tag;
|
||||
|
||||
const PB_Status_PingRequest* request = &msg_request->content.ping_request;
|
||||
PB_Status_PingResponse* response = &msg_response.content.ping_response;
|
||||
if(request->data && (request->data->size > 0)) {
|
||||
response->data = furi_alloc(PB_BYTES_ARRAY_T_ALLOCSIZE(request->data->size));
|
||||
memcpy(response->data->bytes, request->data->bytes, request->data->size);
|
||||
response->data->size = request->data->size;
|
||||
}
|
||||
|
||||
rpc_send_and_release(context, &msg_response);
|
||||
}
|
||||
|
||||
void* rpc_system_status_alloc(Rpc* rpc) {
|
||||
RpcHandler rpc_handler = {
|
||||
.message_handler = rpc_system_status_ping_process,
|
||||
.decode_submessage = NULL,
|
||||
.context = rpc,
|
||||
};
|
||||
|
||||
rpc_add_handler(rpc, PB_Main_ping_request_tag, &rpc_handler);
|
||||
|
||||
return NULL;
|
||||
}
|
@@ -96,6 +96,37 @@ static PB_CommandStatus rpc_system_storage_get_file_error(File* file) {
|
||||
return rpc_system_storage_get_error(storage_file_get_error(file));
|
||||
}
|
||||
|
||||
static void rpc_system_storage_info_process(const PB_Main* request, void* context) {
|
||||
furi_assert(request);
|
||||
furi_assert(context);
|
||||
furi_assert(request->which_content == PB_Main_storage_info_request_tag);
|
||||
|
||||
RpcStorageSystem* rpc_storage = context;
|
||||
rpc_system_storage_reset_state(rpc_storage, true);
|
||||
|
||||
PB_Main* response = furi_alloc(sizeof(PB_Main));
|
||||
response->command_id = request->command_id;
|
||||
|
||||
Storage* fs_api = furi_record_open("storage");
|
||||
|
||||
FS_Error error = storage_common_fs_info(
|
||||
fs_api,
|
||||
request->content.storage_info_request.path,
|
||||
&response->content.storage_info_response.total_space,
|
||||
&response->content.storage_info_response.free_space);
|
||||
|
||||
response->command_status = rpc_system_storage_get_error(error);
|
||||
if(error == FSE_OK) {
|
||||
response->which_content = PB_Main_storage_info_response_tag;
|
||||
} else {
|
||||
response->which_content = PB_Main_empty_tag;
|
||||
}
|
||||
|
||||
rpc_send_and_release(rpc_storage->rpc, response);
|
||||
free(response);
|
||||
furi_record_close("storage");
|
||||
}
|
||||
|
||||
static void rpc_system_storage_stat_process(const PB_Main* request, void* context) {
|
||||
furi_assert(request);
|
||||
furi_assert(context);
|
||||
@@ -388,6 +419,7 @@ static void rpc_system_storage_mkdir_process(const PB_Main* request, void* conte
|
||||
} else {
|
||||
status = PB_CommandStatus_ERROR_INVALID_PARAMETERS;
|
||||
}
|
||||
furi_record_close("storage");
|
||||
rpc_send_and_release_empty(rpc_storage->rpc, request->command_id, status);
|
||||
}
|
||||
|
||||
@@ -453,6 +485,26 @@ static void rpc_system_storage_md5sum_process(const PB_Main* request, void* cont
|
||||
furi_record_close("storage");
|
||||
}
|
||||
|
||||
static void rpc_system_storage_rename_process(const PB_Main* request, void* context) {
|
||||
furi_assert(request);
|
||||
furi_assert(request->which_content == PB_Main_storage_rename_request_tag);
|
||||
furi_assert(context);
|
||||
RpcStorageSystem* rpc_storage = context;
|
||||
PB_CommandStatus status;
|
||||
rpc_system_storage_reset_state(rpc_storage, true);
|
||||
|
||||
Storage* fs_api = furi_record_open("storage");
|
||||
|
||||
FS_Error error = storage_common_rename(
|
||||
fs_api,
|
||||
request->content.storage_rename_request.old_path,
|
||||
request->content.storage_rename_request.new_path);
|
||||
status = rpc_system_storage_get_error(error);
|
||||
|
||||
furi_record_close("storage");
|
||||
rpc_send_and_release_empty(rpc_storage->rpc, request->command_id, status);
|
||||
}
|
||||
|
||||
void* rpc_system_storage_alloc(Rpc* rpc) {
|
||||
furi_assert(rpc);
|
||||
|
||||
@@ -467,6 +519,9 @@ void* rpc_system_storage_alloc(Rpc* rpc) {
|
||||
.context = rpc_storage,
|
||||
};
|
||||
|
||||
rpc_handler.message_handler = rpc_system_storage_info_process;
|
||||
rpc_add_handler(rpc, PB_Main_storage_info_request_tag, &rpc_handler);
|
||||
|
||||
rpc_handler.message_handler = rpc_system_storage_stat_process;
|
||||
rpc_add_handler(rpc, PB_Main_storage_stat_request_tag, &rpc_handler);
|
||||
|
||||
@@ -488,6 +543,9 @@ void* rpc_system_storage_alloc(Rpc* rpc) {
|
||||
rpc_handler.message_handler = rpc_system_storage_md5sum_process;
|
||||
rpc_add_handler(rpc, PB_Main_storage_md5sum_request_tag, &rpc_handler);
|
||||
|
||||
rpc_handler.message_handler = rpc_system_storage_rename_process;
|
||||
rpc_add_handler(rpc, PB_Main_storage_rename_request_tag, &rpc_handler);
|
||||
|
||||
return rpc_storage;
|
||||
}
|
||||
|
||||
|
118
applications/rpc/rpc_system.c
Normal file
118
applications/rpc/rpc_system.c
Normal file
@@ -0,0 +1,118 @@
|
||||
#include "flipper.pb.h"
|
||||
#include "rpc_i.h"
|
||||
#include "status.pb.h"
|
||||
|
||||
#include <furi-hal-info.h>
|
||||
#include <power/power_service/power.h>
|
||||
|
||||
void rpc_system_system_ping_process(const PB_Main* msg_request, void* context) {
|
||||
furi_assert(msg_request);
|
||||
furi_assert(msg_request->which_content == PB_Main_system_ping_request_tag);
|
||||
furi_assert(context);
|
||||
Rpc* rpc = context;
|
||||
|
||||
if(msg_request->has_next) {
|
||||
rpc_send_and_release_empty(
|
||||
rpc, msg_request->command_id, PB_CommandStatus_ERROR_INVALID_PARAMETERS);
|
||||
return;
|
||||
}
|
||||
|
||||
PB_Main msg_response = PB_Main_init_default;
|
||||
msg_response.has_next = false;
|
||||
msg_response.command_status = PB_CommandStatus_OK;
|
||||
msg_response.command_id = msg_request->command_id;
|
||||
msg_response.which_content = PB_Main_system_ping_response_tag;
|
||||
|
||||
const PB_System_PingRequest* request = &msg_request->content.system_ping_request;
|
||||
PB_System_PingResponse* response = &msg_response.content.system_ping_response;
|
||||
if(request->data && (request->data->size > 0)) {
|
||||
response->data = furi_alloc(PB_BYTES_ARRAY_T_ALLOCSIZE(request->data->size));
|
||||
memcpy(response->data->bytes, request->data->bytes, request->data->size);
|
||||
response->data->size = request->data->size;
|
||||
}
|
||||
|
||||
rpc_send_and_release(rpc, &msg_response);
|
||||
}
|
||||
|
||||
void rpc_system_system_reboot_process(const PB_Main* request, void* context) {
|
||||
furi_assert(request);
|
||||
furi_assert(request->which_content == PB_Main_system_reboot_request_tag);
|
||||
furi_assert(context);
|
||||
Rpc* rpc = context;
|
||||
|
||||
const int mode = request->content.system_reboot_request.mode;
|
||||
|
||||
if(mode == PB_System_RebootRequest_RebootMode_OS) {
|
||||
power_reboot(PowerBootModeNormal);
|
||||
} else if(mode == PB_System_RebootRequest_RebootMode_DFU) {
|
||||
power_reboot(PowerBootModeDfu);
|
||||
} else {
|
||||
rpc_send_and_release_empty(
|
||||
rpc, request->command_id, PB_CommandStatus_ERROR_INVALID_PARAMETERS);
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
Rpc* rpc;
|
||||
PB_Main* response;
|
||||
} RpcSystemSystemDeviceInfoContext;
|
||||
|
||||
void rpc_system_system_device_info_callback(
|
||||
const char* key,
|
||||
const char* value,
|
||||
bool last,
|
||||
void* context) {
|
||||
furi_assert(key);
|
||||
furi_assert(value);
|
||||
furi_assert(context);
|
||||
RpcSystemSystemDeviceInfoContext* ctx = context;
|
||||
|
||||
char* str_key = strdup(key);
|
||||
char* str_value = strdup(value);
|
||||
|
||||
ctx->response->has_next = !last;
|
||||
ctx->response->content.system_device_info_response.key = str_key;
|
||||
ctx->response->content.system_device_info_response.value = str_value;
|
||||
|
||||
rpc_send_and_release(ctx->rpc, ctx->response);
|
||||
}
|
||||
|
||||
void rpc_system_system_device_info_process(const PB_Main* request, void* context) {
|
||||
furi_assert(request);
|
||||
furi_assert(request->which_content == PB_Main_system_device_info_request_tag);
|
||||
furi_assert(context);
|
||||
Rpc* rpc = context;
|
||||
|
||||
PB_Main* response = furi_alloc(sizeof(PB_Main));
|
||||
response->command_id = request->command_id;
|
||||
response->which_content = PB_Main_system_device_info_response_tag;
|
||||
response->command_status = PB_CommandStatus_OK;
|
||||
|
||||
RpcSystemSystemDeviceInfoContext device_info_context = {
|
||||
.rpc = rpc,
|
||||
.response = response,
|
||||
};
|
||||
|
||||
furi_hal_info_get(rpc_system_system_device_info_callback, &device_info_context);
|
||||
|
||||
free(response);
|
||||
}
|
||||
|
||||
void* rpc_system_system_alloc(Rpc* rpc) {
|
||||
RpcHandler rpc_handler = {
|
||||
.message_handler = NULL,
|
||||
.decode_submessage = NULL,
|
||||
.context = rpc,
|
||||
};
|
||||
|
||||
rpc_handler.message_handler = rpc_system_system_ping_process;
|
||||
rpc_add_handler(rpc, PB_Main_system_ping_request_tag, &rpc_handler);
|
||||
|
||||
rpc_handler.message_handler = rpc_system_system_reboot_process;
|
||||
rpc_add_handler(rpc, PB_Main_system_reboot_request_tag, &rpc_handler);
|
||||
|
||||
rpc_handler.message_handler = rpc_system_system_device_info_process;
|
||||
rpc_add_handler(rpc, PB_Main_system_device_info_request_tag, &rpc_handler);
|
||||
|
||||
return NULL;
|
||||
}
|
Reference in New Issue
Block a user