testing subghz dynamic limit based on freeheap + RPC

by Willy-JL

5cd2d3eabe

e8d9325bec
This commit is contained in:
MX 2023-12-21 03:17:21 +03:00
parent 8fa21c49b2
commit 77f458fb6e
No known key found for this signature in database
GPG Key ID: 7CCC66B7DBDD1C83
5 changed files with 46 additions and 8 deletions

View File

@ -1,10 +1,11 @@
#include "subghz_history.h" #include "subghz_history.h"
#include <lib/subghz/receiver.h> #include <lib/subghz/receiver.h>
#include <rpc/rpc.h>
#include <furi.h> #include <furi.h>
#define SUBGHZ_HISTORY_MAX 55 #define SUBGHZ_HISTORY_MAX 65530 // uint16_t index max, ram limit below
#define SUBGHZ_HISTORY_FREE_HEAP 20480 #define SUBGHZ_HISTORY_FREE_HEAP (10240 * (3 - MIN(rpc_get_sessions_count(instance->rpc), 2U)))
#define TAG "SubGhzHistory" #define TAG "SubGhzHistory"
typedef struct { typedef struct {
@ -29,6 +30,7 @@ struct SubGhzHistory {
uint8_t code_last_hash_data; uint8_t code_last_hash_data;
FuriString* tmp_string; FuriString* tmp_string;
SubGhzHistoryStruct* history; SubGhzHistoryStruct* history;
Rpc* rpc;
}; };
SubGhzHistory* subghz_history_alloc(void) { SubGhzHistory* subghz_history_alloc(void) {
@ -36,6 +38,7 @@ SubGhzHistory* subghz_history_alloc(void) {
instance->tmp_string = furi_string_alloc(); instance->tmp_string = furi_string_alloc();
instance->history = malloc(sizeof(SubGhzHistoryStruct)); instance->history = malloc(sizeof(SubGhzHistoryStruct));
SubGhzHistoryItemArray_init(instance->history->data); SubGhzHistoryItemArray_init(instance->history->data);
instance->rpc = furi_record_open(RECORD_RPC);
return instance; return instance;
} }
@ -52,6 +55,7 @@ void subghz_history_free(SubGhzHistory* instance) {
} }
SubGhzHistoryItemArray_clear(instance->history->data); SubGhzHistoryItemArray_clear(instance->history->data);
free(instance->history); free(instance->history);
furi_record_close(RECORD_RPC);
free(instance); 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) { bool subghz_history_get_text_space_left(SubGhzHistory* instance, FuriString* output) {
furi_assert(instance); furi_assert(instance);
if(memmgr_get_free_heap() < SUBGHZ_HISTORY_FREE_HEAP) { if(memmgr_get_free_heap() < SUBGHZ_HISTORY_FREE_HEAP) {
if(output != NULL) furi_string_printf(output, " Free heap LOW"); if(output != NULL) furi_string_printf(output, " Memory is FULL");
return true; return true;
} }
if(instance->last_index_write == SUBGHZ_HISTORY_MAX) { if(instance->last_index_write == SUBGHZ_HISTORY_MAX) {
if(output != NULL) furi_string_printf(output, " Memory is FULL"); if(output != NULL) furi_string_printf(output, " History is FULL");
return true; return true;
} }
if(output != NULL) if(output != NULL) furi_string_printf(output, "%02u", instance->last_index_write);
furi_string_printf(output, "%02u/%02u", instance->last_index_write, SUBGHZ_HISTORY_MAX);
return false; return false;
} }

View File

@ -383,7 +383,16 @@ void subghz_view_receiver_draw(Canvas* canvas, SubGhzViewReceiverModel* model) {
#else #else
canvas_draw_str(canvas, 79, 62, furi_string_get_cstr(model->preset_str)); canvas_draw_str(canvas, 79, 62, furi_string_get_cstr(model->preset_str));
#endif #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); canvas_set_font(canvas, FontSecondary);
elements_bold_rounded_frame(canvas, 14, 8, 99, 48); elements_bold_rounded_frame(canvas, 14, 8, 99, 48);
elements_multiline_text(canvas, 65, 26, "To unlock\npress:"); elements_multiline_text(canvas, 65, 26, "To unlock\npress:");
@ -419,7 +428,16 @@ void subghz_view_receiver_draw(Canvas* canvas, SubGhzViewReceiverModel* model) {
#else #else
canvas_draw_str(canvas, 79, 62, furi_string_get_cstr(model->preset_str)); canvas_draw_str(canvas, 79, 62, furi_string_get_cstr(model->preset_str));
#endif #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; } break;
} }
} }

View File

@ -87,6 +87,7 @@ struct RpcSession {
struct Rpc { struct Rpc {
FuriMutex* busy_mutex; FuriMutex* busy_mutex;
size_t sessions_count;
}; };
RpcOwner rpc_session_get_owner(RpcSession* session) { RpcOwner rpc_session_get_owner(RpcSession* session) {
@ -407,6 +408,8 @@ RpcSession* rpc_session_open(Rpc* rpc, RpcOwner owner) {
furi_thread_start(session->thread); furi_thread_start(session->thread);
rpc->sessions_count++;
return session; return session;
} }
@ -414,6 +417,8 @@ void rpc_session_close(RpcSession* session) {
furi_assert(session); furi_assert(session);
furi_assert(session->rpc); furi_assert(session->rpc);
session->rpc->sessions_count--;
rpc_session_set_send_bytes_callback(session, NULL); rpc_session_set_send_bytes_callback(session, NULL);
rpc_session_set_close_callback(session, NULL); rpc_session_set_close_callback(session, NULL);
rpc_session_set_buffer_is_empty_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); rpc_send_and_release(session, &message);
pb_release(&PB_Main_msg, &message); pb_release(&PB_Main_msg, &message);
} }
size_t rpc_get_sessions_count(Rpc* rpc) {
return rpc->sessions_count;
}

View File

@ -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); 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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -2709,6 +2709,7 @@ Function,-,rintl,long double,long double
Function,-,round,double,double Function,-,round,double,double
Function,+,roundf,float,float Function,+,roundf,float,float
Function,-,roundl,long double,long double Function,-,roundl,long double,long double
Function,+,rpc_get_sessions_count,size_t,Rpc*
Function,+,rpc_session_close,void,RpcSession* Function,+,rpc_session_close,void,RpcSession*
Function,+,rpc_session_feed,size_t,"RpcSession*, uint8_t*, size_t, uint32_t" Function,+,rpc_session_feed,size_t,"RpcSession*, uint8_t*, size_t, uint32_t"
Function,+,rpc_session_get_available_size,size_t,RpcSession* Function,+,rpc_session_get_available_size,size_t,RpcSession*

1 entry status name type params
2709 Function - round double double
2710 Function + roundf float float
2711 Function - roundl long double long double
2712 Function + rpc_get_sessions_count size_t Rpc*
2713 Function + rpc_session_close void RpcSession*
2714 Function + rpc_session_feed size_t RpcSession*, uint8_t*, size_t, uint32_t
2715 Function + rpc_session_get_available_size size_t RpcSession*