mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-12 12:42:30 +04:00
[FL-2957] Unified Info API, App Error, Data Xchange (#1998)
* Update protobuf definitions * Add Property subsystem entry point function * Key-based system info and power info function stubs * Remove unneeded functions * Working power info * Working system info * Replace #defines with string literals * Remove unneeded field * Simplify system info formatting * Refactor output callback handling * Handle the last info element correctly * Optimise power info, rename methods * Add comments * Add power debug * Remove unneeded definitions * Rename some files and functions * Update protobuf definitions * Implement App GetError and DataExchange APIs * Send GetErrorReply with correct command_id * Add RPC debug app stub * Add more scenes * Add warning, increase stack size * Add receive data exchange scene * Improve data exchange * Add notifications * Update application requirements * Bump format version for property-based infos * Correctly reset error text * RCP: sync protobuf repo to latest release tag Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -9,9 +9,15 @@
|
||||
|
||||
struct RpcAppSystem {
|
||||
RpcSession* session;
|
||||
|
||||
RpcAppSystemCallback app_callback;
|
||||
void* app_context;
|
||||
|
||||
RpcAppSystemDataExchangeCallback data_exchange_callback;
|
||||
void* data_exchange_context;
|
||||
|
||||
PB_Main* state_msg;
|
||||
PB_Main* error_msg;
|
||||
|
||||
uint32_t last_id;
|
||||
char* last_data;
|
||||
@@ -195,6 +201,50 @@ static void rpc_system_app_button_release(const PB_Main* request, void* context)
|
||||
}
|
||||
}
|
||||
|
||||
static void rpc_system_app_get_error_process(const PB_Main* request, void* context) {
|
||||
furi_assert(request);
|
||||
furi_assert(request->which_content == PB_Main_app_get_error_request_tag);
|
||||
furi_assert(context);
|
||||
|
||||
RpcAppSystem* rpc_app = context;
|
||||
RpcSession* session = rpc_app->session;
|
||||
furi_assert(session);
|
||||
|
||||
rpc_app->error_msg->command_id = request->command_id;
|
||||
|
||||
FURI_LOG_D(TAG, "GetError");
|
||||
rpc_send(session, rpc_app->error_msg);
|
||||
}
|
||||
|
||||
static void rpc_system_app_data_exchange_process(const PB_Main* request, void* context) {
|
||||
furi_assert(request);
|
||||
furi_assert(request->which_content == PB_Main_app_data_exchange_request_tag);
|
||||
furi_assert(context);
|
||||
|
||||
RpcAppSystem* rpc_app = context;
|
||||
RpcSession* session = rpc_app->session;
|
||||
furi_assert(session);
|
||||
|
||||
PB_CommandStatus command_status;
|
||||
pb_bytes_array_t* data = request->content.app_data_exchange_request.data;
|
||||
|
||||
if(rpc_app->data_exchange_callback) {
|
||||
uint8_t* data_bytes = NULL;
|
||||
size_t data_size = 0;
|
||||
if(data) {
|
||||
data_bytes = data->bytes;
|
||||
data_size = data->size;
|
||||
}
|
||||
rpc_app->data_exchange_callback(data_bytes, data_size, rpc_app->data_exchange_context);
|
||||
command_status = PB_CommandStatus_OK;
|
||||
} else {
|
||||
command_status = PB_CommandStatus_ERROR_APP_CMD_ERROR;
|
||||
}
|
||||
|
||||
FURI_LOG_D(TAG, "DataExchange");
|
||||
rpc_send_and_release_empty(session, request->command_id, command_status);
|
||||
}
|
||||
|
||||
void rpc_system_app_send_started(RpcAppSystem* rpc_app) {
|
||||
furi_assert(rpc_app);
|
||||
RpcSession* session = rpc_app->session;
|
||||
@@ -259,6 +309,58 @@ void rpc_system_app_set_callback(RpcAppSystem* rpc_app, RpcAppSystemCallback cal
|
||||
rpc_app->app_context = ctx;
|
||||
}
|
||||
|
||||
void rpc_system_app_set_error_code(RpcAppSystem* rpc_app, uint32_t error_code) {
|
||||
furi_assert(rpc_app);
|
||||
PB_App_GetErrorResponse* content = &rpc_app->error_msg->content.app_get_error_response;
|
||||
content->code = error_code;
|
||||
}
|
||||
|
||||
void rpc_system_app_set_error_text(RpcAppSystem* rpc_app, const char* error_text) {
|
||||
furi_assert(rpc_app);
|
||||
PB_App_GetErrorResponse* content = &rpc_app->error_msg->content.app_get_error_response;
|
||||
|
||||
if(content->text) {
|
||||
free(content->text);
|
||||
}
|
||||
|
||||
content->text = error_text ? strdup(error_text) : NULL;
|
||||
}
|
||||
|
||||
void rpc_system_app_set_data_exchange_callback(
|
||||
RpcAppSystem* rpc_app,
|
||||
RpcAppSystemDataExchangeCallback callback,
|
||||
void* ctx) {
|
||||
furi_assert(rpc_app);
|
||||
|
||||
rpc_app->data_exchange_callback = callback;
|
||||
rpc_app->data_exchange_context = ctx;
|
||||
}
|
||||
|
||||
void rpc_system_app_exchange_data(RpcAppSystem* rpc_app, const uint8_t* data, size_t data_size) {
|
||||
furi_assert(rpc_app);
|
||||
RpcSession* session = rpc_app->session;
|
||||
furi_assert(session);
|
||||
|
||||
PB_Main message = {
|
||||
.command_id = 0,
|
||||
.command_status = PB_CommandStatus_OK,
|
||||
.has_next = false,
|
||||
.which_content = PB_Main_app_data_exchange_request_tag,
|
||||
};
|
||||
|
||||
PB_App_DataExchangeRequest* content = &message.content.app_data_exchange_request;
|
||||
|
||||
if(data && data_size) {
|
||||
content->data = malloc(PB_BYTES_ARRAY_T_ALLOCSIZE(data_size));
|
||||
content->data->size = data_size;
|
||||
memcpy(content->data->bytes, data, data_size);
|
||||
} else {
|
||||
content->data = NULL;
|
||||
}
|
||||
|
||||
rpc_send_and_release(session, &message);
|
||||
}
|
||||
|
||||
void* rpc_system_app_alloc(RpcSession* session) {
|
||||
furi_assert(session);
|
||||
|
||||
@@ -270,6 +372,13 @@ void* rpc_system_app_alloc(RpcSession* session) {
|
||||
rpc_app->state_msg->which_content = PB_Main_app_state_response_tag;
|
||||
rpc_app->state_msg->command_status = PB_CommandStatus_OK;
|
||||
|
||||
// App error message
|
||||
rpc_app->error_msg = malloc(sizeof(PB_Main));
|
||||
rpc_app->error_msg->which_content = PB_Main_app_get_error_response_tag;
|
||||
rpc_app->error_msg->command_status = PB_CommandStatus_OK;
|
||||
rpc_app->error_msg->content.app_get_error_response.code = 0;
|
||||
rpc_app->error_msg->content.app_get_error_response.text = NULL;
|
||||
|
||||
RpcHandler rpc_handler = {
|
||||
.message_handler = NULL,
|
||||
.decode_submessage = NULL,
|
||||
@@ -294,6 +403,12 @@ void* rpc_system_app_alloc(RpcSession* session) {
|
||||
rpc_handler.message_handler = rpc_system_app_button_release;
|
||||
rpc_add_handler(session, PB_Main_app_button_release_request_tag, &rpc_handler);
|
||||
|
||||
rpc_handler.message_handler = rpc_system_app_get_error_process;
|
||||
rpc_add_handler(session, PB_Main_app_get_error_request_tag, &rpc_handler);
|
||||
|
||||
rpc_handler.message_handler = rpc_system_app_data_exchange_process;
|
||||
rpc_add_handler(session, PB_Main_app_data_exchange_request_tag, &rpc_handler);
|
||||
|
||||
return rpc_app;
|
||||
}
|
||||
|
||||
@@ -311,8 +426,13 @@ void rpc_system_app_free(void* context) {
|
||||
furi_delay_tick(1);
|
||||
}
|
||||
|
||||
furi_assert(!rpc_app->data_exchange_callback);
|
||||
|
||||
if(rpc_app->last_data) free(rpc_app->last_data);
|
||||
|
||||
pb_release(&PB_Main_msg, rpc_app->error_msg);
|
||||
|
||||
free(rpc_app->error_msg);
|
||||
free(rpc_app->state_msg);
|
||||
free(rpc_app);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user