Merge branch 'UNLEASHED' into 420

This commit is contained in:
RogueMaster
2022-11-29 12:38:01 -05:00
47 changed files with 1870 additions and 450 deletions

View File

@@ -25,7 +25,7 @@ void cli_command_device_info_callback(const char* key, const char* value, bool l
void cli_command_device_info(Cli* cli, FuriString* args, void* context) {
UNUSED(cli);
UNUSED(args);
furi_hal_info_get(cli_command_device_info_callback, context);
furi_hal_info_get(cli_command_device_info_callback, '_', context);
}
void cli_command_help(Cli* cli, FuriString* args, void* context) {

View File

@@ -1,6 +1,6 @@
#include "dialogs/dialogs_message.h"
#include "dialogs_i.h"
#include "dialogs_api_lock.h"
#include <toolbox/api_lock.h>
#include "dialogs_module_file_browser.h"
#include "dialogs_module_message.h"
@@ -35,7 +35,7 @@ static void dialogs_app_process_message(DialogsApp* app, DialogsAppMessage* mess
dialogs_app_process_module_message(&message->data->dialog);
break;
}
API_LOCK_UNLOCK(message->lock);
api_lock_unlock(message->lock);
}
int32_t dialogs_srv(void* p) {

View File

@@ -1,6 +1,6 @@
#include "dialogs/dialogs_message.h"
#include "dialogs_i.h"
#include "dialogs_api_lock.h"
#include <toolbox/api_lock.h>
#include <assets_icons.h>
/****************** File browser ******************/
@@ -10,7 +10,7 @@ bool dialog_file_browser_show(
FuriString* result_path,
FuriString* path,
const DialogsFileBrowserOptions* options) {
FuriApiLock lock = API_LOCK_INIT_LOCKED();
FuriApiLock lock = api_lock_alloc_locked();
furi_check(lock != NULL);
DialogsAppData data = {
@@ -35,7 +35,7 @@ bool dialog_file_browser_show(
furi_check(
furi_message_queue_put(context->message_queue, &message, FuriWaitForever) == FuriStatusOk);
API_LOCK_WAIT_UNTIL_UNLOCK_AND_FREE(lock);
api_lock_wait_unlock_and_free(lock);
return return_data.bool_value;
}
@@ -43,7 +43,7 @@ bool dialog_file_browser_show(
/****************** Message ******************/
DialogMessageButton dialog_message_show(DialogsApp* context, const DialogMessage* dialog_message) {
FuriApiLock lock = API_LOCK_INIT_LOCKED();
FuriApiLock lock = api_lock_alloc_locked();
furi_check(lock != NULL);
DialogsAppData data = {
@@ -61,7 +61,7 @@ DialogMessageButton dialog_message_show(DialogsApp* context, const DialogMessage
furi_check(
furi_message_queue_put(context->message_queue, &message, FuriWaitForever) == FuriStatusOk);
API_LOCK_WAIT_UNTIL_UNLOCK_AND_FREE(lock);
api_lock_wait_unlock_and_free(lock);
return return_data.dialog_value;
}

View File

@@ -1,18 +0,0 @@
#pragma once
typedef FuriEventFlag* FuriApiLock;
#define API_LOCK_EVENT (1U << 0)
#define API_LOCK_INIT_LOCKED() furi_event_flag_alloc();
#define API_LOCK_WAIT_UNTIL_UNLOCK(_lock) \
furi_event_flag_wait(_lock, API_LOCK_EVENT, FuriFlagWaitAny, FuriWaitForever);
#define API_LOCK_FREE(_lock) furi_event_flag_free(_lock);
#define API_LOCK_UNLOCK(_lock) furi_event_flag_set(_lock, API_LOCK_EVENT);
#define API_LOCK_WAIT_UNTIL_UNLOCK_AND_FREE(_lock) \
API_LOCK_WAIT_UNTIL_UNLOCK(_lock); \
API_LOCK_FREE(_lock);

View File

@@ -1,7 +1,7 @@
#pragma once
#include <furi.h>
#include "dialogs_i.h"
#include "dialogs_api_lock.h"
#include <toolbox/api_lock.h>
#ifdef __cplusplus
extern "C" {

View File

@@ -1,5 +1,5 @@
#include "dialogs_i.h"
#include "dialogs_api_lock.h"
#include <toolbox/api_lock.h>
#include "gui/modules/file_browser.h"
typedef struct {
@@ -11,14 +11,14 @@ static void dialogs_app_file_browser_back_callback(void* context) {
furi_assert(context);
DialogsAppFileBrowserContext* file_browser_context = context;
file_browser_context->result = false;
API_LOCK_UNLOCK(file_browser_context->lock);
api_lock_unlock(file_browser_context->lock);
}
static void dialogs_app_file_browser_callback(void* context) {
furi_assert(context);
DialogsAppFileBrowserContext* file_browser_context = context;
file_browser_context->result = true;
API_LOCK_UNLOCK(file_browser_context->lock);
api_lock_unlock(file_browser_context->lock);
}
bool dialogs_app_process_module_file_browser(const DialogsAppMessageDataFileBrowser* data) {
@@ -27,7 +27,7 @@ bool dialogs_app_process_module_file_browser(const DialogsAppMessageDataFileBrow
DialogsAppFileBrowserContext* file_browser_context =
malloc(sizeof(DialogsAppFileBrowserContext));
file_browser_context->lock = API_LOCK_INIT_LOCKED();
file_browser_context->lock = api_lock_alloc_locked();
ViewHolder* view_holder = view_holder_alloc();
view_holder_attach_to_gui(view_holder, gui);
@@ -44,7 +44,7 @@ bool dialogs_app_process_module_file_browser(const DialogsAppMessageDataFileBrow
view_holder_set_view(view_holder, file_browser_get_view(file_browser));
view_holder_start(view_holder);
API_LOCK_WAIT_UNTIL_UNLOCK(file_browser_context->lock);
api_lock_wait_unlock(file_browser_context->lock);
ret = file_browser_context->result;
@@ -52,7 +52,7 @@ bool dialogs_app_process_module_file_browser(const DialogsAppMessageDataFileBrow
view_holder_free(view_holder);
file_browser_stop(file_browser);
file_browser_free(file_browser);
API_LOCK_FREE(file_browser_context->lock);
api_lock_free(file_browser_context->lock);
free(file_browser_context);
furi_record_close(RECORD_GUI);

View File

@@ -1,5 +1,5 @@
#include "dialogs_i.h"
#include "dialogs_api_lock.h"
#include <toolbox/api_lock.h>
#include <gui/modules/dialog_ex.h>
typedef struct {
@@ -30,7 +30,7 @@ static void dialogs_app_message_back_callback(void* context) {
furi_assert(context);
DialogsAppMessageContext* message_context = context;
message_context->result = DialogMessageButtonBack;
API_LOCK_UNLOCK(message_context->lock);
api_lock_unlock(message_context->lock);
}
static void dialogs_app_message_callback(DialogExResult result, void* context) {
@@ -49,7 +49,7 @@ static void dialogs_app_message_callback(DialogExResult result, void* context) {
default:
break;
}
API_LOCK_UNLOCK(message_context->lock);
api_lock_unlock(message_context->lock);
}
DialogMessageButton dialogs_app_process_module_message(const DialogsAppMessageDataDialog* data) {
@@ -57,7 +57,7 @@ DialogMessageButton dialogs_app_process_module_message(const DialogsAppMessageDa
Gui* gui = furi_record_open(RECORD_GUI);
const DialogMessage* message = data->message;
DialogsAppMessageContext* message_context = malloc(sizeof(DialogsAppMessageContext));
message_context->lock = API_LOCK_INIT_LOCKED();
message_context->lock = api_lock_alloc_locked();
ViewHolder* view_holder = view_holder_alloc();
view_holder_attach_to_gui(view_holder, gui);
@@ -87,14 +87,14 @@ DialogMessageButton dialogs_app_process_module_message(const DialogsAppMessageDa
view_holder_set_view(view_holder, dialog_ex_get_view(dialog_ex));
view_holder_start(view_holder);
API_LOCK_WAIT_UNTIL_UNLOCK(message_context->lock);
api_lock_wait_unlock(message_context->lock);
ret = message_context->result;
view_holder_stop(view_holder);
view_holder_free(view_holder);
dialog_ex_free(dialog_ex);
API_LOCK_FREE(message_context->lock);
api_lock_free(message_context->lock);
free(message_context);
furi_record_close(RECORD_GUI);

View File

@@ -26,7 +26,7 @@ void power_cli_reboot2dfu(Cli* cli, FuriString* args) {
power_reboot(PowerBootModeDfu);
}
static void power_cli_info_callback(const char* key, const char* value, bool last, void* context) {
static void power_cli_callback(const char* key, const char* value, bool last, void* context) {
UNUSED(last);
UNUSED(context);
printf("%-24s: %s\r\n", key, value);
@@ -35,13 +35,13 @@ static void power_cli_info_callback(const char* key, const char* value, bool las
void power_cli_info(Cli* cli, FuriString* args) {
UNUSED(cli);
UNUSED(args);
furi_hal_power_info_get(power_cli_info_callback, NULL);
furi_hal_power_info_get(power_cli_callback, '_', NULL);
}
void power_cli_debug(Cli* cli, FuriString* args) {
UNUSED(cli);
UNUSED(args);
furi_hal_power_dump_state();
furi_hal_power_debug_get(power_cli_callback, NULL);
}
void power_cli_5v(Cli* cli, FuriString* args) {

View File

@@ -52,7 +52,12 @@ static RpcSystemCallbacks rpc_systems[] = {
{
.alloc = rpc_system_gpio_alloc,
.free = NULL,
}};
},
{
.alloc = rpc_system_property_alloc,
.free = NULL,
},
};
struct RpcSession {
Rpc* rpc;

View File

@@ -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);
}

View File

@@ -14,6 +14,8 @@ typedef enum {
} RpcAppSystemEvent;
typedef void (*RpcAppSystemCallback)(RpcAppSystemEvent event, void* context);
typedef void (
*RpcAppSystemDataExchangeCallback)(const uint8_t* data, size_t data_size, void* context);
typedef struct RpcAppSystem RpcAppSystem;
@@ -27,6 +29,17 @@ const char* rpc_system_app_get_data(RpcAppSystem* rpc_app);
void rpc_system_app_confirm(RpcAppSystem* rpc_app, RpcAppSystemEvent event, bool result);
void rpc_system_app_set_error_code(RpcAppSystem* rpc_app, uint32_t error_code);
void rpc_system_app_set_error_text(RpcAppSystem* rpc_app, const char* error_text);
void rpc_system_app_set_data_exchange_callback(
RpcAppSystem* rpc_app,
RpcAppSystemDataExchangeCallback callback,
void* ctx);
void rpc_system_app_exchange_data(RpcAppSystem* rpc_app, const uint8_t* data, size_t data_size);
#ifdef __cplusplus
}
#endif

View File

@@ -34,6 +34,7 @@ void* rpc_system_gui_alloc(RpcSession* session);
void rpc_system_gui_free(void* ctx);
void* rpc_system_gpio_alloc(RpcSession* session);
void rpc_system_gpio_free(void* ctx);
void* rpc_system_property_alloc(RpcSession* session);
void rpc_debug_print_message(const PB_Main* message);
void rpc_debug_print_data(const char* prefix, uint8_t* buffer, size_t size);

View File

@@ -0,0 +1,107 @@
#include <flipper.pb.h>
#include <furi_hal.h>
#include <furi_hal_info.h>
#include <furi_hal_power.h>
#include <core/core_defines.h>
#include "rpc_i.h"
#define TAG "RpcProperty"
#define PROPERTY_CATEGORY_DEVICE_INFO "devinfo"
#define PROPERTY_CATEGORY_POWER_INFO "pwrinfo"
#define PROPERTY_CATEGORY_POWER_DEBUG "pwrdebug"
typedef struct {
RpcSession* session;
PB_Main* response;
FuriString* subkey;
} RpcPropertyContext;
static void
rpc_system_property_get_callback(const char* key, const char* value, bool last, void* context) {
furi_assert(key);
furi_assert(value);
furi_assert(context);
furi_assert(key);
furi_assert(value);
RpcPropertyContext* ctx = context;
RpcSession* session = ctx->session;
PB_Main* response = ctx->response;
if(!strncmp(key, furi_string_get_cstr(ctx->subkey), furi_string_size(ctx->subkey))) {
response->content.system_device_info_response.key = strdup(key);
response->content.system_device_info_response.value = strdup(value);
rpc_send_and_release(session, response);
}
if(last) {
rpc_send_and_release_empty(session, response->command_id, PB_CommandStatus_OK);
}
}
static void rpc_system_property_get_process(const PB_Main* request, void* context) {
furi_assert(request);
furi_assert(request->which_content == PB_Main_property_get_request_tag);
FURI_LOG_D(TAG, "GetProperty");
RpcSession* session = (RpcSession*)context;
furi_assert(session);
FuriString* topkey = furi_string_alloc();
FuriString* subkey = furi_string_alloc_set_str(request->content.property_get_request.key);
const size_t sep_idx = furi_string_search_char(subkey, '.');
if(sep_idx == FURI_STRING_FAILURE) {
furi_string_swap(topkey, subkey);
} else {
furi_string_set_n(topkey, subkey, 0, sep_idx);
furi_string_right(subkey, sep_idx + 1);
}
PB_Main* response = malloc(sizeof(PB_Main));
response->command_id = request->command_id;
response->command_status = PB_CommandStatus_OK;
response->has_next = true;
response->which_content = PB_Main_property_get_response_tag;
RpcPropertyContext property_context = {
.session = session,
.response = response,
.subkey = subkey,
};
if(!furi_string_cmp(topkey, PROPERTY_CATEGORY_DEVICE_INFO)) {
furi_hal_info_get(rpc_system_property_get_callback, '.', &property_context);
} else if(!furi_string_cmp(topkey, PROPERTY_CATEGORY_POWER_INFO)) {
furi_hal_power_info_get(rpc_system_property_get_callback, '.', &property_context);
} else if(!furi_string_cmp(topkey, PROPERTY_CATEGORY_POWER_DEBUG)) {
furi_hal_power_debug_get(rpc_system_property_get_callback, &property_context);
} else {
rpc_send_and_release_empty(
session, request->command_id, PB_CommandStatus_ERROR_INVALID_PARAMETERS);
}
furi_string_free(subkey);
furi_string_free(topkey);
free(response);
}
void* rpc_system_property_alloc(RpcSession* session) {
furi_assert(session);
RpcHandler rpc_handler = {
.message_handler = NULL,
.decode_submessage = NULL,
.context = session,
};
rpc_handler.message_handler = rpc_system_property_get_process;
rpc_add_handler(session, PB_Main_property_get_request_tag, &rpc_handler);
return NULL;
}

View File

@@ -109,7 +109,7 @@ static void rpc_system_system_device_info_process(const PB_Main* request, void*
.session = session,
.response = response,
};
furi_hal_info_get(rpc_system_system_device_info_callback, &device_info_context);
furi_hal_info_get(rpc_system_system_device_info_callback, '_', &device_info_context);
free(response);
}
@@ -266,7 +266,7 @@ static void rpc_system_system_get_power_info_process(const PB_Main* request, voi
.session = session,
.response = response,
};
furi_hal_power_info_get(rpc_system_system_power_info_callback, &power_info_context);
furi_hal_power_info_get(rpc_system_system_power_info_callback, '_', &power_info_context);
free(response);
}