mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-23 04:53:08 +00:00
testing subghz dynamic limit based on freeheap + RPC
by Willy-JL5cd2d3eabe
e8d9325bec
This commit is contained in:
parent
8fa21c49b2
commit
77f458fb6e
5 changed files with 46 additions and 8 deletions
|
@ -1,10 +1,11 @@
|
|||
#include "subghz_history.h"
|
||||
#include <lib/subghz/receiver.h>
|
||||
#include <rpc/rpc.h>
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
#define SUBGHZ_HISTORY_MAX 55
|
||||
#define SUBGHZ_HISTORY_FREE_HEAP 20480
|
||||
#define SUBGHZ_HISTORY_MAX 65530 // uint16_t index max, ram limit below
|
||||
#define SUBGHZ_HISTORY_FREE_HEAP (10240 * (3 - MIN(rpc_get_sessions_count(instance->rpc), 2U)))
|
||||
#define TAG "SubGhzHistory"
|
||||
|
||||
typedef struct {
|
||||
|
@ -29,6 +30,7 @@ struct SubGhzHistory {
|
|||
uint8_t code_last_hash_data;
|
||||
FuriString* tmp_string;
|
||||
SubGhzHistoryStruct* history;
|
||||
Rpc* rpc;
|
||||
};
|
||||
|
||||
SubGhzHistory* subghz_history_alloc(void) {
|
||||
|
@ -36,6 +38,7 @@ SubGhzHistory* subghz_history_alloc(void) {
|
|||
instance->tmp_string = furi_string_alloc();
|
||||
instance->history = malloc(sizeof(SubGhzHistoryStruct));
|
||||
SubGhzHistoryItemArray_init(instance->history->data);
|
||||
instance->rpc = furi_record_open(RECORD_RPC);
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
@ -52,6 +55,7 @@ void subghz_history_free(SubGhzHistory* instance) {
|
|||
}
|
||||
SubGhzHistoryItemArray_clear(instance->history->data);
|
||||
free(instance->history);
|
||||
furi_record_close(RECORD_RPC);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
|
@ -143,15 +147,14 @@ FlipperFormat* subghz_history_get_raw_data(SubGhzHistory* instance, uint16_t idx
|
|||
bool subghz_history_get_text_space_left(SubGhzHistory* instance, FuriString* output) {
|
||||
furi_assert(instance);
|
||||
if(memmgr_get_free_heap() < SUBGHZ_HISTORY_FREE_HEAP) {
|
||||
if(output != NULL) furi_string_printf(output, " Free heap LOW");
|
||||
return true;
|
||||
}
|
||||
if(instance->last_index_write == SUBGHZ_HISTORY_MAX) {
|
||||
if(output != NULL) furi_string_printf(output, " Memory is FULL");
|
||||
return true;
|
||||
}
|
||||
if(output != NULL)
|
||||
furi_string_printf(output, "%02u/%02u", instance->last_index_write, SUBGHZ_HISTORY_MAX);
|
||||
if(instance->last_index_write == SUBGHZ_HISTORY_MAX) {
|
||||
if(output != NULL) furi_string_printf(output, " History is FULL");
|
||||
return true;
|
||||
}
|
||||
if(output != NULL) furi_string_printf(output, "%02u", instance->last_index_write);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -383,7 +383,16 @@ void subghz_view_receiver_draw(Canvas* canvas, SubGhzViewReceiverModel* model) {
|
|||
#else
|
||||
canvas_draw_str(canvas, 79, 62, furi_string_get_cstr(model->preset_str));
|
||||
#endif
|
||||
canvas_draw_str(canvas, 96, 62, furi_string_get_cstr(model->history_stat_str));
|
||||
if(!furi_string_empty(model->history_stat_str)) {
|
||||
canvas_draw_str_aligned(
|
||||
canvas,
|
||||
114,
|
||||
62,
|
||||
AlignRight,
|
||||
AlignBottom,
|
||||
furi_string_get_cstr(model->history_stat_str));
|
||||
canvas_draw_icon(canvas, 116, 53, &I_sub1_10px);
|
||||
}
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
elements_bold_rounded_frame(canvas, 14, 8, 99, 48);
|
||||
elements_multiline_text(canvas, 65, 26, "To unlock\npress:");
|
||||
|
@ -419,7 +428,16 @@ void subghz_view_receiver_draw(Canvas* canvas, SubGhzViewReceiverModel* model) {
|
|||
#else
|
||||
canvas_draw_str(canvas, 79, 62, furi_string_get_cstr(model->preset_str));
|
||||
#endif
|
||||
canvas_draw_str(canvas, 96, 62, furi_string_get_cstr(model->history_stat_str));
|
||||
if(!furi_string_empty(model->history_stat_str)) {
|
||||
canvas_draw_str_aligned(
|
||||
canvas,
|
||||
114,
|
||||
62,
|
||||
AlignRight,
|
||||
AlignBottom,
|
||||
furi_string_get_cstr(model->history_stat_str));
|
||||
canvas_draw_icon(canvas, 116, 53, &I_sub1_10px);
|
||||
}
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,6 +87,7 @@ struct RpcSession {
|
|||
|
||||
struct Rpc {
|
||||
FuriMutex* busy_mutex;
|
||||
size_t sessions_count;
|
||||
};
|
||||
|
||||
RpcOwner rpc_session_get_owner(RpcSession* session) {
|
||||
|
@ -407,6 +408,8 @@ RpcSession* rpc_session_open(Rpc* rpc, RpcOwner owner) {
|
|||
|
||||
furi_thread_start(session->thread);
|
||||
|
||||
rpc->sessions_count++;
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
|
@ -414,6 +417,8 @@ void rpc_session_close(RpcSession* session) {
|
|||
furi_assert(session);
|
||||
furi_assert(session->rpc);
|
||||
|
||||
session->rpc->sessions_count--;
|
||||
|
||||
rpc_session_set_send_bytes_callback(session, NULL);
|
||||
rpc_session_set_close_callback(session, NULL);
|
||||
rpc_session_set_buffer_is_empty_callback(session, NULL);
|
||||
|
@ -489,3 +494,7 @@ void rpc_send_and_release_empty(RpcSession* session, uint32_t command_id, PB_Com
|
|||
rpc_send_and_release(session, &message);
|
||||
pb_release(&PB_Main_msg, &message);
|
||||
}
|
||||
|
||||
size_t rpc_get_sessions_count(Rpc* rpc) {
|
||||
return rpc->sessions_count;
|
||||
}
|
||||
|
|
|
@ -134,6 +134,13 @@ size_t rpc_session_feed(RpcSession* session, uint8_t* buffer, size_t size, uint3
|
|||
*/
|
||||
size_t rpc_session_get_available_size(RpcSession* session);
|
||||
|
||||
/** Get number of open RPC sessions
|
||||
*
|
||||
* @param rpc instance
|
||||
* @return sessions count
|
||||
*/
|
||||
size_t rpc_get_sessions_count(Rpc* rpc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -2709,6 +2709,7 @@ Function,-,rintl,long double,long double
|
|||
Function,-,round,double,double
|
||||
Function,+,roundf,float,float
|
||||
Function,-,roundl,long double,long double
|
||||
Function,+,rpc_get_sessions_count,size_t,Rpc*
|
||||
Function,+,rpc_session_close,void,RpcSession*
|
||||
Function,+,rpc_session_feed,size_t,"RpcSession*, uint8_t*, size_t, uint32_t"
|
||||
Function,+,rpc_session_get_available_size,size_t,RpcSession*
|
||||
|
|
|
Loading…
Reference in a new issue