Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/flipperzero-firmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--applications/archive/archive.c2
-rw-r--r--applications/archive/views/archive_browser_view.c2
-rw-r--r--applications/bad_usb/bad_usb_app.c2
-rw-r--r--applications/bad_usb/bad_usb_script.c2
-rw-r--r--applications/bad_usb/views/bad_usb_view.c2
-rw-r--r--applications/bt/bt_debug_app/bt_debug_app.c2
-rwxr-xr-xapplications/bt/bt_debug_app/views/bt_carrier_test.c2
-rw-r--r--applications/bt/bt_debug_app/views/bt_packet_test.c2
-rwxr-xr-xapplications/bt/bt_debug_app/views/bt_test.c2
-rwxr-xr-xapplications/bt/bt_hid_app/bt_hid.c2
-rwxr-xr-xapplications/bt/bt_hid_app/views/bt_hid_keynote.c2
-rwxr-xr-xapplications/bt/bt_hid_app/views/bt_hid_media.c2
-rwxr-xr-xapplications/bt/bt_service/bt.c2
-rwxr-xr-xapplications/bt/bt_settings_app/bt_settings_app.c2
-rw-r--r--applications/cli/cli.c2
-rw-r--r--applications/crypto/crypto_cli.c6
-rw-r--r--applications/debug_tools/display_test/display_test.c2
-rw-r--r--applications/debug_tools/display_test/view_display_test.c2
-rw-r--r--applications/debug_tools/uart_echo.c6
-rw-r--r--applications/debug_tools/usb_test.c2
-rw-r--r--applications/desktop/animations/animation_manager.c2
-rw-r--r--applications/desktop/animations/animation_storage.c129
-rw-r--r--applications/desktop/animations/views/bubble_animation_view.c8
-rw-r--r--applications/desktop/animations/views/one_shot_animation_view.c2
-rw-r--r--applications/desktop/desktop.c2
-rw-r--r--applications/desktop/desktop_settings/desktop_settings_app.c2
-rw-r--r--applications/desktop/desktop_settings/views/desktop_settings_view_pin_setup_howto.c2
-rw-r--r--applications/desktop/desktop_settings/views/desktop_settings_view_pin_setup_howto2.c3
-rw-r--r--applications/desktop/scenes/desktop_scene_hw_mismatch.c2
-rw-r--r--applications/desktop/scenes/desktop_scene_pin_input.c2
-rw-r--r--applications/desktop/views/desktop_view_debug.c2
-rw-r--r--applications/desktop/views/desktop_view_first_start.c2
-rw-r--r--applications/desktop/views/desktop_view_lock_menu.c2
-rw-r--r--applications/desktop/views/desktop_view_locked.c2
-rw-r--r--applications/desktop/views/desktop_view_main.c2
-rw-r--r--applications/desktop/views/desktop_view_pin_input.c2
-rw-r--r--applications/desktop/views/desktop_view_pin_setup_done.c2
-rw-r--r--applications/desktop/views/desktop_view_pin_timeout.c2
-rw-r--r--applications/dialogs/dialogs.c2
-rw-r--r--applications/dialogs/dialogs_module_file_select.c5
-rw-r--r--applications/dialogs/dialogs_module_message.c6
-rw-r--r--applications/dialogs/view_holder.c4
-rw-r--r--applications/dolphin/dolphin.c2
-rw-r--r--applications/dolphin/helpers/dolphin_state.c2
-rw-r--r--applications/gpio/gpio_app.c2
-rw-r--r--applications/gpio/scenes/gpio_scene_usb_uart.c2
-rw-r--r--applications/gpio/scenes/gpio_scene_usb_uart_config.c2
-rw-r--r--applications/gpio/usb_uart_bridge.c2
-rwxr-xr-xapplications/gpio/views/gpio_test.c2
-rw-r--r--applications/gpio/views/gpio_usb_uart.c2
-rw-r--r--applications/gui/canvas.c2
-rw-r--r--applications/gui/gui.c2
-rw-r--r--applications/gui/icon_animation.c2
-rw-r--r--applications/gui/modules/button_menu.c2
-rw-r--r--applications/gui/modules/button_panel.c4
-rw-r--r--applications/gui/modules/byte_input.c2
-rw-r--r--applications/gui/modules/dialog.c2
-rwxr-xr-xapplications/gui/modules/dialog_ex.c2
-rw-r--r--applications/gui/modules/empty_screen.c4
-rw-r--r--applications/gui/modules/file_select.c10
-rw-r--r--applications/gui/modules/menu.c2
-rw-r--r--applications/gui/modules/popup.c2
-rw-r--r--applications/gui/modules/submenu.c2
-rwxr-xr-xapplications/gui/modules/text_box.c2
-rwxr-xr-xapplications/gui/modules/text_input.c2
-rw-r--r--applications/gui/modules/validators.c2
-rw-r--r--applications/gui/modules/variable_item_list.c2
-rwxr-xr-xapplications/gui/modules/widget.c2
-rw-r--r--applications/gui/modules/widget_elements/widget_element_button.c4
-rwxr-xr-xapplications/gui/modules/widget_elements/widget_element_frame.c4
-rw-r--r--applications/gui/modules/widget_elements/widget_element_icon.c4
-rwxr-xr-xapplications/gui/modules/widget_elements/widget_element_string.c4
-rw-r--r--applications/gui/modules/widget_elements/widget_element_string_multiline.c4
-rw-r--r--applications/gui/modules/widget_elements/widget_element_text_box.c4
-rwxr-xr-xapplications/gui/scene_manager.c162
-rw-r--r--applications/gui/view.c8
-rw-r--r--applications/gui/view_dispatcher.c2
-rw-r--r--applications/gui/view_port.c2
-rw-r--r--applications/gui/view_stack.c2
-rw-r--r--applications/ibutton/ibutton_app.cpp33
-rw-r--r--applications/input/input.c4
-rw-r--r--applications/irda/cli/irda_cli.cpp2
-rw-r--r--applications/irda/helpers/irda_parser.cpp51
-rw-r--r--applications/irda/helpers/irda_parser.h9
-rw-r--r--applications/irda/irda_app_brute_force.cpp19
-rw-r--r--applications/irda/irda_app_brute_force.h4
-rw-r--r--applications/irda/irda_app_remote_manager.cpp20
-rw-r--r--applications/irda/view/irda_app_brut_view.c2
-rw-r--r--applications/irda_monitor/irda_monitor.c2
-rw-r--r--applications/lfrfid/lfrfid_app.cpp33
-rw-r--r--applications/loader/loader.c2
-rwxr-xr-xapplications/nfc/helpers/nfc_emv_parser.c12
-rwxr-xr-xapplications/nfc/nfc.c2
-rwxr-xr-xapplications/nfc/nfc_device.c113
-rwxr-xr-xapplications/nfc/nfc_worker.c11
-rwxr-xr-xapplications/nfc/views/bank_card.c2
-rw-r--r--applications/notification/notification_app.c4
-rw-r--r--applications/notification/notification_settings_app.c2
-rwxr-xr-xapplications/power/battery_test_app/battery_test_app.c4
-rwxr-xr-xapplications/power/power_service/power.c2
-rwxr-xr-xapplications/power/power_service/views/power_off.c2
-rwxr-xr-xapplications/power/power_settings_app/power_settings_app.c2
-rw-r--r--applications/power/power_settings_app/views/battery_info.c2
-rw-r--r--applications/rpc/rpc.c8
-rw-r--r--applications/rpc/rpc_cli.c2
-rw-r--r--applications/rpc/rpc_gui.c8
-rw-r--r--applications/rpc/rpc_storage.c16
-rw-r--r--applications/rpc/rpc_system.c8
-rw-r--r--applications/snake_game/snake_game.c2
-rw-r--r--applications/storage/filesystem_api_defines.h1
-rw-r--r--applications/storage/storage_cli.c8
-rw-r--r--applications/storage/storage_external_api.c4
-rw-r--r--applications/storage/storage_test_app.c2
-rw-r--r--applications/storage/storages/storage_ext.c2
-rw-r--r--applications/storage/storages/storage_int.c10
-rw-r--r--applications/storage_settings/storage_settings.c2
-rw-r--r--applications/subghz/helpers/subghz_chat.c4
-rw-r--r--applications/subghz/helpers/subghz_frequency_analyzer_worker.c2
-rw-r--r--applications/subghz/subghz.c4
-rw-r--r--applications/subghz/subghz_cli.c2
-rw-r--r--applications/subghz/subghz_history.c2
-rwxr-xr-xapplications/subghz/subghz_i.c38
-rw-r--r--applications/subghz/views/subghz_frequency_analyzer.c4
-rw-r--r--applications/subghz/views/subghz_read_raw.c6
-rw-r--r--applications/subghz/views/subghz_receiver.c6
-rw-r--r--applications/subghz/views/subghz_test_carrier.c2
-rw-r--r--applications/subghz/views/subghz_test_packet.c2
-rw-r--r--applications/subghz/views/subghz_test_static.c4
-rw-r--r--applications/subghz/views/subghz_transmitter.c2
-rw-r--r--applications/system/system_settings.c2
-rw-r--r--applications/tests/flipper_format/flipper_format_string_test.c227
-rw-r--r--applications/tests/flipper_format/flipper_format_test.c (renamed from applications/tests/flipper_file/flipper_file_test.c)222
-rw-r--r--applications/tests/furi_memmgr_test.c3
-rw-r--r--applications/tests/irda_decoder_encoder/irda_decoder_encoder_test.c4
-rw-r--r--applications/tests/minunit.h20
-rw-r--r--applications/tests/rpc/rpc_test.c22
-rw-r--r--applications/tests/stream/stream_test.c381
-rw-r--r--applications/tests/test_index.c10
-rw-r--r--applications/u2f/u2f.c2
-rw-r--r--applications/u2f/u2f_app.c2
-rw-r--r--applications/u2f/u2f_data.c92
-rw-r--r--applications/u2f/u2f_hid.c2
-rw-r--r--applications/u2f/views/u2f_view.c2
-rw-r--r--core/furi/memmgr.c49
-rw-r--r--core/furi/memmgr.h10
-rw-r--r--core/furi/memmgr_heap.c132
-rw-r--r--core/furi/pubsub.c2
-rw-r--r--core/furi/record.c2
-rw-r--r--core/furi/stdglue.c2
-rw-r--r--core/furi/thread.c2
-rw-r--r--firmware/targets/f6/Src/main.c3
-rw-r--r--firmware/targets/f6/ble_glue/battery_service.c2
-rw-r--r--firmware/targets/f6/ble_glue/ble_app.c2
-rw-r--r--firmware/targets/f6/ble_glue/ble_glue.c2
-rw-r--r--firmware/targets/f6/ble_glue/dev_info_service.c2
-rwxr-xr-xfirmware/targets/f6/ble_glue/gap.c4
-rw-r--r--firmware/targets/f6/ble_glue/hid_service.c2
-rw-r--r--firmware/targets/f6/ble_glue/serial_service.c2
-rw-r--r--firmware/targets/f6/fatfs/stm32_adafruit_sd.c4
-rw-r--r--firmware/targets/f6/furi_hal/furi_hal.c7
-rw-r--r--firmware/targets/f6/furi_hal/furi_hal_bt_hid.c4
-rw-r--r--firmware/targets/f6/furi_hal/furi_hal_compress.c6
-rw-r--r--firmware/targets/f6/furi_hal/furi_hal_console.c6
-rw-r--r--firmware/targets/f6/furi_hal/furi_hal_irda.c8
-rw-r--r--firmware/targets/f6/furi_hal/furi_hal_subghz.c2
-rw-r--r--firmware/targets/f6/furi_hal/furi_hal_usb_cdc.c4
-rw-r--r--firmware/targets/f6/furi_hal/furi_hal_vcp.c2
-rw-r--r--firmware/targets/f7/Src/main.c3
-rw-r--r--firmware/targets/f7/ble_glue/battery_service.c2
-rw-r--r--firmware/targets/f7/ble_glue/ble_app.c2
-rw-r--r--firmware/targets/f7/ble_glue/ble_glue.c2
-rw-r--r--firmware/targets/f7/ble_glue/dev_info_service.c2
-rwxr-xr-xfirmware/targets/f7/ble_glue/gap.c4
-rw-r--r--firmware/targets/f7/ble_glue/hid_service.c2
-rw-r--r--firmware/targets/f7/ble_glue/serial_service.c2
-rw-r--r--firmware/targets/f7/fatfs/stm32_adafruit_sd.c4
-rw-r--r--firmware/targets/f7/furi_hal/furi_hal.c7
-rw-r--r--firmware/targets/f7/furi_hal/furi_hal_bt_hid.c4
-rw-r--r--firmware/targets/f7/furi_hal/furi_hal_compress.c6
-rw-r--r--firmware/targets/f7/furi_hal/furi_hal_console.c6
-rw-r--r--firmware/targets/f7/furi_hal/furi_hal_irda.c8
-rw-r--r--firmware/targets/f7/furi_hal/furi_hal_subghz.c2
-rw-r--r--firmware/targets/f7/furi_hal/furi_hal_usb_cdc.c4
-rw-r--r--firmware/targets/f7/furi_hal/furi_hal_vcp.c2
-rw-r--r--firmware/targets/furi_hal_include/furi_hal.h6
-rw-r--r--lib/flipper_file/file_helper.c204
-rw-r--r--lib/flipper_file/file_helper.h81
-rw-r--r--lib/flipper_file/flipper_file.c402
-rw-r--r--lib/flipper_file/flipper_file.h465
-rw-r--r--lib/flipper_file/flipper_file_float.c42
-rw-r--r--lib/flipper_file/flipper_file_helper.c121
-rw-r--r--lib/flipper_file/flipper_file_helper.h52
-rw-r--r--lib/flipper_file/flipper_file_hex.c42
-rw-r--r--lib/flipper_file/flipper_file_i.h74
-rw-r--r--lib/flipper_file/flipper_file_int32.c42
-rw-r--r--lib/flipper_file/flipper_file_string.c67
-rw-r--r--lib/flipper_file/flipper_file_uint32.c47
-rw-r--r--lib/flipper_format/flipper_format.c410
-rw-r--r--lib/flipper_format/flipper_format.h471
-rw-r--r--lib/flipper_format/flipper_format_i.h19
-rw-r--r--lib/flipper_format/flipper_format_stream.c497
-rw-r--r--lib/flipper_format/flipper_format_stream.h94
-rw-r--r--lib/flipper_format/flipper_format_stream_i.h23
-rw-r--r--lib/heatshrink/heatshrink_config.h2
-rw-r--r--lib/irda/encoder_decoder/common/irda_common_decoder.c2
-rw-r--r--lib/irda/encoder_decoder/common/irda_common_encoder.c2
-rw-r--r--lib/irda/encoder_decoder/irda.c6
-rw-r--r--lib/irda/encoder_decoder/rc5/irda_decoder_rc5.c2
-rw-r--r--lib/irda/encoder_decoder/rc5/irda_encoder_rc5.c2
-rw-r--r--lib/irda/encoder_decoder/rc6/irda_decoder_rc6.c2
-rw-r--r--lib/irda/encoder_decoder/rc6/irda_encoder_rc6.c2
-rw-r--r--lib/irda/worker/irda_worker.c2
-rw-r--r--lib/lib.mk10
-rw-r--r--lib/subghz/protocols/subghz_protocol_came.c10
-rw-r--r--lib/subghz/protocols/subghz_protocol_came.h8
-rw-r--r--lib/subghz/protocols/subghz_protocol_came_atomo.c2
-rw-r--r--lib/subghz/protocols/subghz_protocol_came_twee.c10
-rw-r--r--lib/subghz/protocols/subghz_protocol_came_twee.h8
-rw-r--r--lib/subghz/protocols/subghz_protocol_common.c24
-rw-r--r--lib/subghz/protocols/subghz_protocol_common.h16
-rw-r--r--lib/subghz/protocols/subghz_protocol_faac_slh.c4
-rw-r--r--lib/subghz/protocols/subghz_protocol_gate_tx.c10
-rw-r--r--lib/subghz/protocols/subghz_protocol_gate_tx.h8
-rw-r--r--lib/subghz/protocols/subghz_protocol_hormann.c10
-rw-r--r--lib/subghz/protocols/subghz_protocol_hormann.h8
-rw-r--r--lib/subghz/protocols/subghz_protocol_ido.c4
-rw-r--r--lib/subghz/protocols/subghz_protocol_keeloq.c12
-rw-r--r--lib/subghz/protocols/subghz_protocol_keeloq.h10
-rw-r--r--lib/subghz/protocols/subghz_protocol_kia.c4
-rw-r--r--lib/subghz/protocols/subghz_protocol_nero_radio.c12
-rw-r--r--lib/subghz/protocols/subghz_protocol_nero_radio.h8
-rw-r--r--lib/subghz/protocols/subghz_protocol_nero_sketch.c10
-rw-r--r--lib/subghz/protocols/subghz_protocol_nero_sketch.h8
-rw-r--r--lib/subghz/protocols/subghz_protocol_nice_flo.c10
-rw-r--r--lib/subghz/protocols/subghz_protocol_nice_flo.h8
-rw-r--r--lib/subghz/protocols/subghz_protocol_nice_flor_s.c4
-rw-r--r--lib/subghz/protocols/subghz_protocol_princeton.c17
-rw-r--r--lib/subghz/protocols/subghz_protocol_princeton.h8
-rwxr-xr-xlib/subghz/protocols/subghz_protocol_raw.c37
-rw-r--r--lib/subghz/protocols/subghz_protocol_raw.h2
-rw-r--r--lib/subghz/protocols/subghz_protocol_scher_khan.c4
-rw-r--r--lib/subghz/protocols/subghz_protocol_somfy_keytis.c2
-rw-r--r--lib/subghz/protocols/subghz_protocol_somfy_telis.c2
-rw-r--r--lib/subghz/protocols/subghz_protocol_star_line.c4
-rw-r--r--lib/subghz/subghz_file_encoder_worker.c29
-rw-r--r--lib/subghz/subghz_keystore.c136
-rw-r--r--lib/subghz/subghz_parser.c2
-rw-r--r--lib/subghz/subghz_tx_rx_worker.c2
-rw-r--r--lib/subghz/subghz_worker.c2
-rw-r--r--lib/toolbox/saved_struct.c2
-rw-r--r--lib/toolbox/stream/file_stream.c224
-rw-r--r--lib/toolbox/stream/file_stream.h40
-rw-r--r--lib/toolbox/stream/stream.c337
-rw-r--r--lib/toolbox/stream/stream.h336
-rw-r--r--lib/toolbox/stream/stream_i.h46
-rw-r--r--lib/toolbox/stream/string_stream.c179
-rw-r--r--lib/toolbox/stream/string_stream.h18
257 files changed, 4477 insertions, 2654 deletions
diff --git a/applications/archive/archive.c b/applications/archive/archive.c
index c2fe4c6d..79f26f0e 100644
--- a/applications/archive/archive.c
+++ b/applications/archive/archive.c
@@ -13,7 +13,7 @@ bool archive_back_event_callback(void* context) {
}
ArchiveApp* archive_alloc() {
- ArchiveApp* archive = furi_alloc(sizeof(ArchiveApp));
+ ArchiveApp* archive = malloc(sizeof(ArchiveApp));
archive->gui = furi_record_open("gui");
archive->text_input = text_input_alloc();
diff --git a/applications/archive/views/archive_browser_view.c b/applications/archive/views/archive_browser_view.c
index 5e079436..67a4ce02 100644
--- a/applications/archive/views/archive_browser_view.c
+++ b/applications/archive/views/archive_browser_view.c
@@ -305,7 +305,7 @@ bool archive_view_input(InputEvent* event, void* context) {
}
ArchiveBrowserView* browser_alloc() {
- ArchiveBrowserView* browser = furi_alloc(sizeof(ArchiveBrowserView));
+ ArchiveBrowserView* browser = malloc(sizeof(ArchiveBrowserView));
browser->view = view_alloc();
view_allocate_model(browser->view, ViewModelTypeLocking, sizeof(ArchiveBrowserViewModel));
view_set_context(browser->view, browser);
diff --git a/applications/bad_usb/bad_usb_app.c b/applications/bad_usb/bad_usb_app.c
index 49809562..adf9b7c8 100644
--- a/applications/bad_usb/bad_usb_app.c
+++ b/applications/bad_usb/bad_usb_app.c
@@ -41,7 +41,7 @@ static bool bad_usb_check_assets() {
}
BadUsbApp* bad_usb_app_alloc(char* arg) {
- BadUsbApp* app = furi_alloc(sizeof(BadUsbApp));
+ BadUsbApp* app = malloc(sizeof(BadUsbApp));
if(arg != NULL) {
string_t filename;
diff --git a/applications/bad_usb/bad_usb_script.c b/applications/bad_usb/bad_usb_script.c
index 53710372..07df2bd1 100644
--- a/applications/bad_usb/bad_usb_script.c
+++ b/applications/bad_usb/bad_usb_script.c
@@ -524,7 +524,7 @@ static int32_t bad_usb_worker(void* context) {
BadUsbScript* bad_usb_script_open(string_t file_path) {
furi_assert(file_path);
- BadUsbScript* bad_usb = furi_alloc(sizeof(BadUsbScript));
+ BadUsbScript* bad_usb = malloc(sizeof(BadUsbScript));
string_init(bad_usb->file_path);
string_set(bad_usb->file_path, file_path);
diff --git a/applications/bad_usb/views/bad_usb_view.c b/applications/bad_usb/views/bad_usb_view.c
index 6d226ca7..22e5143d 100644
--- a/applications/bad_usb/views/bad_usb_view.c
+++ b/applications/bad_usb/views/bad_usb_view.c
@@ -115,7 +115,7 @@ static bool bad_usb_input_callback(InputEvent* event, void* context) {
}
BadUsb* bad_usb_alloc() {
- BadUsb* bad_usb = furi_alloc(sizeof(BadUsb));
+ BadUsb* bad_usb = malloc(sizeof(BadUsb));
bad_usb->view = view_alloc();
view_allocate_model(bad_usb->view, ViewModelTypeLocking, sizeof(BadUsbModel));
diff --git a/applications/bt/bt_debug_app/bt_debug_app.c b/applications/bt/bt_debug_app/bt_debug_app.c
index 218692c0..a4363b91 100644
--- a/applications/bt/bt_debug_app/bt_debug_app.c
+++ b/applications/bt/bt_debug_app/bt_debug_app.c
@@ -27,7 +27,7 @@ uint32_t bt_debug_start_view(void* context) {
}
BtDebugApp* bt_debug_app_alloc() {
- BtDebugApp* app = furi_alloc(sizeof(BtDebugApp));
+ BtDebugApp* app = malloc(sizeof(BtDebugApp));
// Load settings
bt_settings_load(&app->settings);
diff --git a/applications/bt/bt_debug_app/views/bt_carrier_test.c b/applications/bt/bt_debug_app/views/bt_carrier_test.c
index a3dfd65c..22b80cd8 100755
--- a/applications/bt/bt_debug_app/views/bt_carrier_test.c
+++ b/applications/bt/bt_debug_app/views/bt_carrier_test.c
@@ -130,7 +130,7 @@ static void bt_test_carrier_timer_callback(void* context) {
}
BtCarrierTest* bt_carrier_test_alloc() {
- BtCarrierTest* bt_carrier_test = furi_alloc(sizeof(BtCarrierTest));
+ BtCarrierTest* bt_carrier_test = malloc(sizeof(BtCarrierTest));
bt_carrier_test->bt_test = bt_test_alloc();
bt_test_set_context(bt_carrier_test->bt_test, bt_carrier_test);
bt_test_set_change_state_callback(
diff --git a/applications/bt/bt_debug_app/views/bt_packet_test.c b/applications/bt/bt_debug_app/views/bt_packet_test.c
index 19dd6b21..e9d3883a 100644
--- a/applications/bt/bt_debug_app/views/bt_packet_test.c
+++ b/applications/bt/bt_debug_app/views/bt_packet_test.c
@@ -98,7 +98,7 @@ static void bt_test_packet_timer_callback(void* context) {
}
BtPacketTest* bt_packet_test_alloc() {
- BtPacketTest* bt_packet_test = furi_alloc(sizeof(BtPacketTest));
+ BtPacketTest* bt_packet_test = malloc(sizeof(BtPacketTest));
bt_packet_test->bt_test = bt_test_alloc();
bt_test_set_context(bt_packet_test->bt_test, bt_packet_test);
bt_test_set_change_state_callback(
diff --git a/applications/bt/bt_debug_app/views/bt_test.c b/applications/bt/bt_debug_app/views/bt_test.c
index 747ce6a4..ac10e0a8 100755
--- a/applications/bt/bt_debug_app/views/bt_test.c
+++ b/applications/bt/bt_debug_app/views/bt_test.c
@@ -291,7 +291,7 @@ void bt_test_process_back(BtTest* bt_test) {
}
BtTest* bt_test_alloc() {
- BtTest* bt_test = furi_alloc(sizeof(BtTest));
+ BtTest* bt_test = malloc(sizeof(BtTest));
bt_test->view = view_alloc();
view_set_context(bt_test->view, bt_test);
view_allocate_model(bt_test->view, ViewModelTypeLocking, sizeof(BtTestModel));
diff --git a/applications/bt/bt_hid_app/bt_hid.c b/applications/bt/bt_hid_app/bt_hid.c
index 9d6fdae7..ab13f6f3 100755
--- a/applications/bt/bt_hid_app/bt_hid.c
+++ b/applications/bt/bt_hid_app/bt_hid.c
@@ -54,7 +54,7 @@ void bt_hid_connection_status_changed_callback(BtStatus status, void* context) {
}
BtHid* bt_hid_app_alloc() {
- BtHid* app = furi_alloc(sizeof(BtHid));
+ BtHid* app = malloc(sizeof(BtHid));
// Gui
app->gui = furi_record_open("gui");
diff --git a/applications/bt/bt_hid_app/views/bt_hid_keynote.c b/applications/bt/bt_hid_app/views/bt_hid_keynote.c
index c9507726..c4225227 100755
--- a/applications/bt/bt_hid_app/views/bt_hid_keynote.c
+++ b/applications/bt/bt_hid_app/views/bt_hid_keynote.c
@@ -161,7 +161,7 @@ static bool bt_hid_keynote_input_callback(InputEvent* event, void* context) {
}
BtHidKeynote* bt_hid_keynote_alloc() {
- BtHidKeynote* bt_hid_keynote = furi_alloc(sizeof(BtHidKeynote));
+ BtHidKeynote* bt_hid_keynote = malloc(sizeof(BtHidKeynote));
bt_hid_keynote->view = view_alloc();
view_set_context(bt_hid_keynote->view, bt_hid_keynote);
view_allocate_model(bt_hid_keynote->view, ViewModelTypeLocking, sizeof(BtHidKeynoteModel));
diff --git a/applications/bt/bt_hid_app/views/bt_hid_media.c b/applications/bt/bt_hid_app/views/bt_hid_media.c
index 1b205b84..695ce3c3 100755
--- a/applications/bt/bt_hid_app/views/bt_hid_media.c
+++ b/applications/bt/bt_hid_app/views/bt_hid_media.c
@@ -162,7 +162,7 @@ static bool bt_hid_media_input_callback(InputEvent* event, void* context) {
}
BtHidMedia* bt_hid_media_alloc() {
- BtHidMedia* bt_hid_media = furi_alloc(sizeof(BtHidMedia));
+ BtHidMedia* bt_hid_media = malloc(sizeof(BtHidMedia));
bt_hid_media->view = view_alloc();
view_set_context(bt_hid_media->view, bt_hid_media);
view_allocate_model(bt_hid_media->view, ViewModelTypeLocking, sizeof(BtHidMediaModel));
diff --git a/applications/bt/bt_service/bt.c b/applications/bt/bt_service/bt.c
index 0015c08c..720f4854 100755
--- a/applications/bt/bt_service/bt.c
+++ b/applications/bt/bt_service/bt.c
@@ -101,7 +101,7 @@ static void bt_battery_level_changed_callback(const void* _event, void* context)
}
Bt* bt_alloc() {
- Bt* bt = furi_alloc(sizeof(Bt));
+ Bt* bt = malloc(sizeof(Bt));
// Init default maximum packet size
bt->max_packet_size = FURI_HAL_BT_SERIAL_PACKET_SIZE_MAX;
bt->profile = BtProfileSerial;
diff --git a/applications/bt/bt_settings_app/bt_settings_app.c b/applications/bt/bt_settings_app/bt_settings_app.c
index be57223e..d9dfa74d 100755
--- a/applications/bt/bt_settings_app/bt_settings_app.c
+++ b/applications/bt/bt_settings_app/bt_settings_app.c
@@ -13,7 +13,7 @@ static bool bt_settings_back_event_callback(void* context) {
}
BtSettingsApp* bt_settings_app_alloc() {
- BtSettingsApp* app = furi_alloc(sizeof(BtSettingsApp));
+ BtSettingsApp* app = malloc(sizeof(BtSettingsApp));
// Load settings
bt_settings_load(&app->settings);
diff --git a/applications/cli/cli.c b/applications/cli/cli.c
index dc2037d5..4b36521b 100644
--- a/applications/cli/cli.c
+++ b/applications/cli/cli.c
@@ -5,7 +5,7 @@
#include <loader/loader.h>
Cli* cli_alloc() {
- Cli* cli = furi_alloc(sizeof(Cli));
+ Cli* cli = malloc(sizeof(Cli));
CliCommandTree_init(cli->commands);
diff --git a/applications/crypto/crypto_cli.c b/applications/crypto/crypto_cli.c
index cd77fe61..60e32b2b 100644
--- a/applications/crypto/crypto_cli.c
+++ b/applications/crypto/crypto_cli.c
@@ -67,7 +67,7 @@ void crypto_cli_encrypt(Cli* cli, string_t args) {
size = size - remain + 16;
}
string_reserve(input, size);
- uint8_t* output = furi_alloc(size);
+ uint8_t* output = malloc(size);
if(!furi_hal_crypto_encrypt((const uint8_t*)string_get_cstr(input), output, size)) {
printf("Failed to encrypt input");
} else {
@@ -135,8 +135,8 @@ void crypto_cli_decrypt(Cli* cli, string_t args) {
size_t hex_size = string_size(hex_input);
if(hex_size > 0 && hex_size % 2 == 0) {
size_t size = hex_size / 2;
- uint8_t* input = furi_alloc(size);
- uint8_t* output = furi_alloc(size);
+ uint8_t* input = malloc(size);
+ uint8_t* output = malloc(size);
if(args_read_hex_bytes(hex_input, input, size)) {
if(furi_hal_crypto_decrypt(input, output, size)) {
diff --git a/applications/debug_tools/display_test/display_test.c b/applications/debug_tools/display_test/display_test.c
index 2efac325..1a9a0e43 100644
--- a/applications/debug_tools/display_test/display_test.c
+++ b/applications/debug_tools/display_test/display_test.c
@@ -121,7 +121,7 @@ static void display_config_set_contrast(VariableItem* item) {
}
DisplayTest* display_test_alloc() {
- DisplayTest* instance = furi_alloc(sizeof(DisplayTest));
+ DisplayTest* instance = malloc(sizeof(DisplayTest));
View* view = NULL;
diff --git a/applications/debug_tools/display_test/view_display_test.c b/applications/debug_tools/display_test/view_display_test.c
index 0ba6df80..cc5f5dcf 100644
--- a/applications/debug_tools/display_test/view_display_test.c
+++ b/applications/debug_tools/display_test/view_display_test.c
@@ -155,7 +155,7 @@ static void view_display_test_timer_callback(void* context) {
}
ViewDisplayTest* view_display_test_alloc() {
- ViewDisplayTest* instance = furi_alloc(sizeof(ViewDisplayTest));
+ ViewDisplayTest* instance = malloc(sizeof(ViewDisplayTest));
instance->view = view_alloc();
view_set_context(instance->view, instance);
diff --git a/applications/debug_tools/uart_echo.c b/applications/debug_tools/uart_echo.c
index 8c30a93c..73af1e66 100644
--- a/applications/debug_tools/uart_echo.c
+++ b/applications/debug_tools/uart_echo.c
@@ -178,7 +178,7 @@ static int32_t uart_echo_worker(void* context) {
}
static UartEchoApp* uart_echo_app_alloc() {
- UartEchoApp* app = furi_alloc(sizeof(UartEchoApp));
+ UartEchoApp* app = malloc(sizeof(UartEchoApp));
app->rx_stream = xStreamBufferCreate(2048, 1);
@@ -201,7 +201,7 @@ static UartEchoApp* uart_echo_app_alloc() {
for(size_t i = 0; i < LINES_ON_SCREEN; i++) {
model->line = 0;
model->escape = false;
- model->list[i] = furi_alloc(sizeof(ListElement));
+ model->list[i] = malloc(sizeof(ListElement));
string_init(model->list[i]->text);
}
return true;
@@ -265,4 +265,4 @@ int32_t uart_echo_app(void* p) {
view_dispatcher_run(app->view_dispatcher);
uart_echo_app_free(app);
return 0;
-} \ No newline at end of file
+}
diff --git a/applications/debug_tools/usb_test.c b/applications/debug_tools/usb_test.c
index ff32198a..cdc1aa40 100644
--- a/applications/debug_tools/usb_test.c
+++ b/applications/debug_tools/usb_test.c
@@ -47,7 +47,7 @@ uint32_t usb_test_exit(void* context) {
}
UsbTestApp* usb_test_app_alloc() {
- UsbTestApp* app = furi_alloc(sizeof(UsbTestApp));
+ UsbTestApp* app = malloc(sizeof(UsbTestApp));
// Gui
app->gui = furi_record_open("gui");
diff --git a/applications/desktop/animations/animation_manager.c b/applications/desktop/animations/animation_manager.c
index 1cb06d4f..afc9c42e 100644
--- a/applications/desktop/animations/animation_manager.c
+++ b/applications/desktop/animations/animation_manager.c
@@ -258,7 +258,7 @@ static void animation_manager_replace_current_animation(
}
AnimationManager* animation_manager_alloc(void) {
- AnimationManager* animation_manager = furi_alloc(sizeof(AnimationManager));
+ AnimationManager* animation_manager = malloc(sizeof(AnimationManager));
animation_manager->animation_view = bubble_animation_view_alloc();
animation_manager->view_stack = view_stack_alloc();
View* animation_view = bubble_animation_get_view(animation_manager->animation_view);
diff --git a/applications/desktop/animations/animation_storage.c b/applications/desktop/animations/animation_storage.c
index 24c0aab1..aa0f274b 100644
--- a/applications/desktop/animations/animation_storage.c
+++ b/applications/desktop/animations/animation_storage.c
@@ -1,6 +1,6 @@
#include <stdint.h>
-#include <flipper_file.h>
+#include <flipper_format/flipper_format.h>
#include <furi.h>
#include <furi/dangerous_defines.h>
#include <storage/storage.h>
@@ -30,41 +30,41 @@ static bool animation_storage_load_single_manifest_info(
bool result = false;
Storage* storage = furi_record_open("storage");
- FlipperFile* file = flipper_file_alloc(storage);
- flipper_file_set_strict_mode(file, true);
+ FlipperFormat* file = flipper_format_file_alloc(storage);
+ flipper_format_set_strict_mode(file, true);
string_t read_string;
string_init(read_string);
do {
uint32_t u32value;
if(FSE_OK != storage_sd_status(storage)) break;
- if(!flipper_file_open_existing(file, ANIMATION_MANIFEST_FILE)) break;
+ if(!flipper_format_file_open_existing(file, ANIMATION_MANIFEST_FILE)) break;
- if(!flipper_file_read_header(file, read_string, &u32value)) break;
+ if(!flipper_format_read_header(file, read_string, &u32value)) break;
if(string_cmp_str(read_string, "Flipper Animation Manifest")) break;
manifest_info->name = NULL;
/* skip other animation names */
- flipper_file_set_strict_mode(file, false);
- while(flipper_file_read_string(file, "Name", read_string) &&
+ flipper_format_set_strict_mode(file, false);
+ while(flipper_format_read_string(file, "Name", read_string) &&
string_cmp_str(read_string, name))
;
if(string_cmp_str(read_string, name)) break;
- flipper_file_set_strict_mode(file, true);
+ flipper_format_set_strict_mode(file, true);
- manifest_info->name = furi_alloc(string_size(read_string) + 1);
+ manifest_info->name = malloc(string_size(read_string) + 1);
strcpy((char*)manifest_info->name, string_get_cstr(read_string));
- if(!flipper_file_read_uint32(file, "Min butthurt", &u32value, 1)) break;
+ if(!flipper_format_read_uint32(file, "Min butthurt", &u32value, 1)) break;
manifest_info->min_butthurt = u32value;
- if(!flipper_file_read_uint32(file, "Max butthurt", &u32value, 1)) break;
+ if(!flipper_format_read_uint32(file, "Max butthurt", &u32value, 1)) break;
manifest_info->max_butthurt = u32value;
- if(!flipper_file_read_uint32(file, "Min level", &u32value, 1)) break;
+ if(!flipper_format_read_uint32(file, "Min level", &u32value, 1)) break;
manifest_info->min_level = u32value;
- if(!flipper_file_read_uint32(file, "Max level", &u32value, 1)) break;
+ if(!flipper_format_read_uint32(file, "Max level", &u32value, 1)) break;
manifest_info->max_level = u32value;
- if(!flipper_file_read_uint32(file, "Weight", &u32value, 1)) break;
+ if(!flipper_format_read_uint32(file, "Weight", &u32value, 1)) break;
manifest_info->weight = u32value;
result = true;
} while(0);
@@ -73,8 +73,7 @@ static bool animation_storage_load_single_manifest_info(
free((void*)manifest_info->name);
}
string_clear(read_string);
- flipper_file_close(file);
- flipper_file_free(file);
+ flipper_format_free(file);
furi_record_close("storage");
@@ -86,9 +85,9 @@ void animation_storage_fill_animation_list(StorageAnimationList_t* animation_lis
furi_assert(!StorageAnimationList_size(*animation_list));
Storage* storage = furi_record_open("storage");
- FlipperFile* file = flipper_file_alloc(storage);
+ FlipperFormat* file = flipper_format_file_alloc(storage);
/* Forbid skipping fields */
- flipper_file_set_strict_mode(file, true);
+ flipper_format_set_strict_mode(file, true);
string_t read_string;
string_init(read_string);
@@ -97,28 +96,28 @@ void animation_storage_fill_animation_list(StorageAnimationList_t* animation_lis
StorageAnimation* storage_animation = NULL;
if(FSE_OK != storage_sd_status(storage)) break;
- if(!flipper_file_open_existing(file, ANIMATION_MANIFEST_FILE)) break;
- if(!flipper_file_read_header(file, read_string, &u32value)) break;
+ if(!flipper_format_file_open_existing(file, ANIMATION_MANIFEST_FILE)) break;
+ if(!flipper_format_read_header(file, read_string, &u32value)) break;
if(string_cmp_str(read_string, "Flipper Animation Manifest")) break;
do {
- storage_animation = furi_alloc(sizeof(StorageAnimation));
+ storage_animation = malloc(sizeof(StorageAnimation));
storage_animation->external = true;
storage_animation->animation = NULL;
storage_animation->manifest_info.name = NULL;
- if(!flipper_file_read_string(file, "Name", read_string)) break;
- storage_animation->manifest_info.name = furi_alloc(string_size(read_string) + 1);
+ if(!flipper_format_read_string(file, "Name", read_string)) break;
+ storage_animation->manifest_info.name = malloc(string_size(read_string) + 1);
strcpy((char*)storage_animation->manifest_info.name, string_get_cstr(read_string));
- if(!flipper_file_read_uint32(file, "Min butthurt", &u32value, 1)) break;
+ if(!flipper_format_read_uint32(file, "Min butthurt", &u32value, 1)) break;
storage_animation->manifest_info.min_butthurt = u32value;
- if(!flipper_file_read_uint32(file, "Max butthurt", &u32value, 1)) break;
+ if(!flipper_format_read_uint32(file, "Max butthurt", &u32value, 1)) break;
storage_animation->manifest_info.max_butthurt = u32value;
- if(!flipper_file_read_uint32(file, "Min level", &u32value, 1)) break;
+ if(!flipper_format_read_uint32(file, "Min level", &u32value, 1)) break;
storage_animation->manifest_info.min_level = u32value;
- if(!flipper_file_read_uint32(file, "Max level", &u32value, 1)) break;
+ if(!flipper_format_read_uint32(file, "Max level", &u32value, 1)) break;
storage_animation->manifest_info.max_level = u32value;
- if(!flipper_file_read_uint32(file, "Weight", &u32value, 1)) break;
+ if(!flipper_format_read_uint32(file, "Weight", &u32value, 1)) break;
storage_animation->manifest_info.weight = u32value;
StorageAnimationList_push_back(*animation_list, storage_animation);
@@ -128,8 +127,7 @@ void animation_storage_fill_animation_list(StorageAnimationList_t* animation_lis
} while(0);
string_clear(read_string);
- flipper_file_close(file);
- flipper_file_free(file);
+ flipper_format_free(file);
// add hard-coded animations
for(int i = 0; i < dolphin_internal_size; ++i) {
@@ -162,7 +160,7 @@ StorageAnimation* animation_storage_find_animation(const char* name) {
/* look through external animations */
if(!storage_animation) {
- storage_animation = furi_alloc(sizeof(StorageAnimation));
+ storage_animation = malloc(sizeof(StorageAnimation));
storage_animation->external = true;
bool result = false;
@@ -288,7 +286,7 @@ static bool animation_storage_load_frames(
FURI_CONST_ASSIGN(icon->frame_rate, 0);
FURI_CONST_ASSIGN(icon->height, height);
FURI_CONST_ASSIGN(icon->width, width);
- icon->frames = furi_alloc(sizeof(const uint8_t*) * icon->frame_count);
+ icon->frames = malloc(sizeof(const uint8_t*) * icon->frame_count);
bool frames_ok = false;
File* file = storage_file_alloc(storage);
@@ -317,7 +315,7 @@ static bool animation_storage_load_frames(
break;
}
- FURI_CONST_ASSIGN_PTR(icon->frames[i], furi_alloc(file_info.size));
+ FURI_CONST_ASSIGN_PTR(icon->frames[i], malloc(file_info.size));
if(storage_file_read(file, (void*)icon->frames[i], file_info.size) != file_info.size) {
FURI_LOG_E(TAG, "Read failed: \'%s\'", string_get_cstr(filename));
break;
@@ -348,7 +346,7 @@ static bool animation_storage_load_frames(
return frames_ok;
}
-static bool animation_storage_load_bubbles(BubbleAnimation* animation, FlipperFile* ff) {
+static bool animation_storage_load_bubbles(BubbleAnimation* animation, FlipperFormat* ff) {
uint32_t u32value;
string_t str;
string_init(str);
@@ -356,7 +354,7 @@ static bool animation_storage_load_bubbles(BubbleAnimation* animation, FlipperFi
furi_assert(!animation->frame_bubble_sequences);
do {
- if(!flipper_file_read_uint32(ff, "Bubble slots", &u32value, 1)) break;
+ if(!flipper_format_read_uint32(ff, "Bubble slots", &u32value, 1)) break;
if(u32value > 20) break;
animation->frame_bubble_sequences_count = u32value;
if(animation->frame_bubble_sequences_count == 0) {
@@ -365,22 +363,22 @@ static bool animation_storage_load_bubbles(BubbleAnimation* animation, FlipperFi
break;
}
animation->frame_bubble_sequences =
- furi_alloc(sizeof(FrameBubble*) * animation->frame_bubble_sequences_count);
+ malloc(sizeof(FrameBubble*) * animation->frame_bubble_sequences_count);
uint32_t current_slot = 0;
for(int i = 0; i < animation->frame_bubble_sequences_count; ++i) {
FURI_CONST_ASSIGN_PTR(
- animation->frame_bubble_sequences[i], furi_alloc(sizeof(FrameBubble)));
+ animation->frame_bubble_sequences[i], malloc(sizeof(FrameBubble)));
}
const FrameBubble* bubble = animation->frame_bubble_sequences[0];
int8_t index = -1;
for(;;) {
- if(!flipper_file_read_uint32(ff, "Slot", &current_slot, 1)) break;
+ if(!flipper_format_read_uint32(ff, "Slot", &current_slot, 1)) break;
if((current_slot != 0) && (index == -1)) break;
if(current_slot == index) {
- FURI_CONST_ASSIGN_PTR(bubble->next_bubble, furi_alloc(sizeof(FrameBubble)));
+ FURI_CONST_ASSIGN_PTR(bubble->next_bubble, malloc(sizeof(FrameBubble)));
bubble = bubble->next_bubble;
} else if(current_slot == index + 1) {
++index;
@@ -392,27 +390,27 @@ static bool animation_storage_load_bubbles(BubbleAnimation* animation, FlipperFi
}
if(index >= animation->frame_bubble_sequences_count) break;
- if(!flipper_file_read_uint32(ff, "X", &u32value, 1)) break;
+ if(!flipper_format_read_uint32(ff, "X", &u32value, 1)) break;
FURI_CONST_ASSIGN(bubble->bubble.x, u32value);
- if(!flipper_file_read_uint32(ff, "Y", &u32value, 1)) break;
+ if(!flipper_format_read_uint32(ff, "Y", &u32value, 1)) break;
FURI_CONST_ASSIGN(bubble->bubble.y, u32value);
- if(!flipper_file_read_string(ff, "Text", str)) break;
+ if(!flipper_format_read_string(ff, "Text", str)) break;
if(string_size(str) > 100) break;
string_replace_all_str(str, "\\n", "\n");
- FURI_CONST_ASSIGN_PTR(bubble->bubble.text, furi_alloc(string_size(str) + 1));
+ FURI_CONST_ASSIGN_PTR(bubble->bubble.text, malloc(string_size(str) + 1));
strcpy((char*)bubble->bubble.text, string_get_cstr(str));
- if(!flipper_file_read_string(ff, "AlignH", str)) break;
+ if(!flipper_format_read_string(ff, "AlignH", str)) break;
if(!animation_storage_cast_align(str, (Align*)&bubble->bubble.align_h)) break;
- if(!flipper_file_read_string(ff, "AlignV", str)) break;
+ if(!flipper_format_read_string(ff, "AlignV", str)) break;
if(!animation_storage_cast_align(str, (Align*)&bubble->bubble.align_v)) break;
- if(!flipper_file_read_uint32(ff, "StartFrame", &u32value, 1)) break;
+ if(!flipper_format_read_uint32(ff, "StartFrame", &u32value, 1)) break;
FURI_CONST_ASSIGN(bubble->start_frame, u32value);
- if(!flipper_file_read_uint32(ff, "EndFrame", &u32value, 1)) break;
+ if(!flipper_format_read_uint32(ff, "EndFrame", &u32value, 1)) break;
FURI_CONST_ASSIGN(bubble->end_frame, u32value);
}
success = (index + 1) == animation->frame_bubble_sequences_count;
@@ -431,15 +429,15 @@ static bool animation_storage_load_bubbles(BubbleAnimation* animation, FlipperFi
static BubbleAnimation* animation_storage_load_animation(const char* name) {
furi_assert(name);
- BubbleAnimation* animation = furi_alloc(sizeof(BubbleAnimation));
+ BubbleAnimation* animation = malloc(sizeof(BubbleAnimation));
uint32_t height = 0;
uint32_t width = 0;
uint32_t* u32array = NULL;
Storage* storage = furi_record_open("storage");
- FlipperFile* ff = flipper_file_alloc(storage);
+ FlipperFormat* ff = flipper_format_file_alloc(storage);
/* Forbid skipping fields */
- flipper_file_set_strict_mode(ff, true);
+ flipper_format_set_strict_mode(ff, true);
string_t str;
string_init(str);
animation->frame_bubble_sequences = NULL;
@@ -451,28 +449,28 @@ static BubbleAnimation* animation_storage_load_animation(const char* name) {
if(FSE_OK != storage_sd_status(storage)) break;
string_printf(str, ANIMATION_DIR "/%s/" ANIMATION_META_FILE, name);
- if(!flipper_file_open_existing(ff, string_get_cstr(str))) break;
- if(!flipper_file_read_header(ff, str, &u32value)) break;
+ if(!flipper_format_file_open_existing(ff, string_get_cstr(str))) break;
+ if(!flipper_format_read_header(ff, str, &u32value)) break;
if(string_cmp_str(str, "Flipper Animation")) break;
- if(!flipper_file_read_uint32(ff, "Width", &width, 1)) break;
- if(!flipper_file_read_uint32(ff, "Height", &height, 1)) break;
+ if(!flipper_format_read_uint32(ff, "Width", &width, 1)) break;
+ if(!flipper_format_read_uint32(ff, "Height", &height, 1)) break;
- if(!flipper_file_read_uint32(ff, "Passive frames", &u32value, 1)) break;
+ if(!flipper_format_read_uint32(ff, "Passive frames", &u32value, 1)) break;
animation->passive_frames = u32value;
- if(!flipper_file_read_uint32(ff, "Active frames", &u32value, 1)) break;
+ if(!flipper_format_read_uint32(ff, "Active frames", &u32value, 1)) break;
animation->active_frames = u32value;
uint8_t frames = animation->passive_frames + animation->active_frames;
uint32_t count = 0;
- if(!flipper_file_get_value_count(ff, "Frames order", &count)) break;
+ if(!flipper_format_get_value_count(ff, "Frames order", &count)) break;
if(count != frames) {
FURI_LOG_E(TAG, "Error loading animation: frames order");
break;
}
- u32array = furi_alloc(sizeof(uint32_t) * frames);
- if(!flipper_file_read_uint32(ff, "Frames order", u32array, frames)) break;
- animation->frame_order = furi_alloc(sizeof(uint8_t) * frames);
+ u32array = malloc(sizeof(uint32_t) * frames);
+ if(!flipper_format_read_uint32(ff, "Frames order", u32array, frames)) break;
+ animation->frame_order = malloc(sizeof(uint8_t) * frames);
for(int i = 0; i < frames; ++i) {
FURI_CONST_ASSIGN(animation->frame_order[i], u32array[i]);
}
@@ -481,13 +479,13 @@ static BubbleAnimation* animation_storage_load_animation(const char* name) {
if(!animation_storage_load_frames(storage, name, animation, u32array, width, height))
break;
- if(!flipper_file_read_uint32(ff, "Active cycles", &u32value, 1)) break;
+ if(!flipper_format_read_uint32(ff, "Active cycles", &u32value, 1)) break;
animation->active_cycles = u32value;
- if(!flipper_file_read_uint32(ff, "Frame rate", &u32value, 1)) break;
+ if(!flipper_format_read_uint32(ff, "Frame rate", &u32value, 1)) break;
FURI_CONST_ASSIGN(animation->icon_animation.frame_rate, u32value);
- if(!flipper_file_read_uint32(ff, "Duration", &u32value, 1)) break;
+ if(!flipper_format_read_uint32(ff, "Duration", &u32value, 1)) break;
animation->duration = u32value;
- if(!flipper_file_read_uint32(ff, "Active cooldown", &u32value, 1)) break;
+ if(!flipper_format_read_uint32(ff, "Active cooldown", &u32value, 1)) break;
animation->active_cooldown = u32value;
if(!animation_storage_load_bubbles(animation, ff)) break;
@@ -495,8 +493,7 @@ static BubbleAnimation* animation_storage_load_animation(const char* name) {
} while(0);
string_clear(str);
- flipper_file_close(ff);
- flipper_file_free(ff);
+ flipper_format_free(ff);
if(u32array) {
free(u32array);
}
diff --git a/applications/desktop/animations/views/bubble_animation_view.c b/applications/desktop/animations/views/bubble_animation_view.c
index 596f0aa1..9b60d45c 100644
--- a/applications/desktop/animations/views/bubble_animation_view.c
+++ b/applications/desktop/animations/views/bubble_animation_view.c
@@ -256,17 +256,17 @@ static Icon* bubble_animation_clone_first_frame(const Icon* icon_orig) {
furi_assert(icon_orig->frames);
furi_assert(icon_orig->frames[0]);
- Icon* icon_clone = furi_alloc(sizeof(Icon));
+ Icon* icon_clone = malloc(sizeof(Icon));
memcpy(icon_clone, icon_orig, sizeof(Icon));
- icon_clone->frames = furi_alloc(sizeof(uint8_t*));
+ icon_clone->frames = malloc(sizeof(uint8_t*));
/* icon bitmap can be either compressed or not. It is compressed if
* compressed size is less than original, so max size for bitmap is
* uncompressed (width * height) + 1 byte (in uncompressed case)
* for compressed header
*/
size_t max_bitmap_size = ROUND_UP_TO(icon_orig->width, 8) * icon_orig->height + 1;
- FURI_CONST_ASSIGN_PTR(icon_clone->frames[0], furi_alloc(max_bitmap_size));
+ FURI_CONST_ASSIGN_PTR(icon_clone->frames[0], malloc(max_bitmap_size));
memcpy((void*)icon_clone->frames[0], icon_orig->frames[0], max_bitmap_size);
FURI_CONST_ASSIGN(icon_clone->frame_count, 1);
@@ -304,7 +304,7 @@ static void bubble_animation_exit(void* context) {
}
BubbleAnimationView* bubble_animation_view_alloc(void) {
- BubbleAnimationView* view = furi_alloc(sizeof(BubbleAnimationView));
+ BubbleAnimationView* view = malloc(sizeof(BubbleAnimationView));
view->view = view_alloc();
view->interact_callback = NULL;
view->timer = osTimerNew(bubble_animation_timer_callback, osTimerPeriodic, view, NULL);
diff --git a/applications/desktop/animations/views/one_shot_animation_view.c b/applications/desktop/animations/views/one_shot_animation_view.c
index d7e9915a..9a4dff06 100644
--- a/applications/desktop/animations/views/one_shot_animation_view.c
+++ b/applications/desktop/animations/views/one_shot_animation_view.c
@@ -78,7 +78,7 @@ static bool one_shot_view_input(InputEvent* event, void* context) {
}
OneShotView* one_shot_view_alloc(void) {
- OneShotView* view = furi_alloc(sizeof(OneShotView));
+ OneShotView* view = malloc(sizeof(OneShotView));
view->view = view_alloc();
view->update_timer =
xTimerCreate(NULL, 1000, pdTRUE, view, one_shot_view_update_timer_callback);
diff --git a/applications/desktop/desktop.c b/applications/desktop/desktop.c
index b3d80e7a..1e3edf77 100644
--- a/applications/desktop/desktop.c
+++ b/applications/desktop/desktop.c
@@ -39,7 +39,7 @@ static void desktop_tick_event_callback(void* context) {
}
Desktop* desktop_alloc() {
- Desktop* desktop = furi_alloc(sizeof(Desktop));
+ Desktop* desktop = malloc(sizeof(Desktop));
desktop->unload_animation_semaphore = osSemaphoreNew(1, 0, NULL);
desktop->animation_manager = animation_manager_alloc();
diff --git a/applications/desktop/desktop_settings/desktop_settings_app.c b/applications/desktop/desktop_settings/desktop_settings_app.c
index ca078ccd..46e0bdc5 100644
--- a/applications/desktop/desktop_settings/desktop_settings_app.c
+++ b/applications/desktop/desktop_settings/desktop_settings_app.c
@@ -19,7 +19,7 @@ static bool desktop_settings_back_event_callback(void* context) {
}
DesktopSettingsApp* desktop_settings_app_alloc() {
- DesktopSettingsApp* app = furi_alloc(sizeof(DesktopSettingsApp));
+ DesktopSettingsApp* app = malloc(sizeof(DesktopSettingsApp));
app->gui = furi_record_open("gui");
app->view_dispatcher = view_dispatcher_alloc();
diff --git a/applications/desktop/desktop_settings/views/desktop_settings_view_pin_setup_howto.c b/applications/desktop/desktop_settings/views/desktop_settings_view_pin_setup_howto.c
index c87de756..3831be8c 100644
--- a/applications/desktop/desktop_settings/views/desktop_settings_view_pin_setup_howto.c
+++ b/applications/desktop/desktop_settings/views/desktop_settings_view_pin_setup_howto.c
@@ -55,7 +55,7 @@ void desktop_settings_view_pin_setup_howto_set_callback(
}
DesktopSettingsViewPinSetupHowto* desktop_settings_view_pin_setup_howto_alloc() {
- DesktopSettingsViewPinSetupHowto* view = furi_alloc(sizeof(DesktopSettingsViewPinSetupHowto));
+ DesktopSettingsViewPinSetupHowto* view = malloc(sizeof(DesktopSettingsViewPinSetupHowto));
view->view = view_alloc();
view_allocate_model(view->view, ViewModelTypeLockFree, 1);
view_set_context(view->view, view);
diff --git a/applications/desktop/desktop_settings/views/desktop_settings_view_pin_setup_howto2.c b/applications/desktop/desktop_settings/views/desktop_settings_view_pin_setup_howto2.c
index 3ef22b46..ab1fa238 100644
--- a/applications/desktop/desktop_settings/views/desktop_settings_view_pin_setup_howto2.c
+++ b/applications/desktop/desktop_settings/views/desktop_settings_view_pin_setup_howto2.c
@@ -77,8 +77,7 @@ void desktop_settings_view_pin_setup_howto2_set_ok_callback(
}
DesktopSettingsViewPinSetupHowto2* desktop_settings_view_pin_setup_howto2_alloc() {
- DesktopSettingsViewPinSetupHowto2* view =
- furi_alloc(sizeof(DesktopSettingsViewPinSetupHowto2));
+ DesktopSettingsViewPinSetupHowto2* view = malloc(sizeof(DesktopSettingsViewPinSetupHowto2));
view->view = view_alloc();
view_allocate_model(view->view, ViewModelTypeLockFree, 1);
view_set_context(view->view, view);
diff --git a/applications/desktop/scenes/desktop_scene_hw_mismatch.c b/applications/desktop/scenes/desktop_scene_hw_mismatch.c
index 05a6fd68..35c50610 100644
--- a/applications/desktop/scenes/desktop_scene_hw_mismatch.c
+++ b/applications/desktop/scenes/desktop_scene_hw_mismatch.c
@@ -16,7 +16,7 @@ void desktop_scene_hw_mismatch_on_enter(void* context) {
furi_assert(desktop);
Popup* popup = desktop->hw_mismatch_popup;
- char* text_buffer = furi_alloc(256);
+ char* text_buffer = malloc(256);
scene_manager_set_scene_state(
desktop->scene_manager, DesktopSceneHwMismatch, (uint32_t)text_buffer);
diff --git a/applications/desktop/scenes/desktop_scene_pin_input.c b/applications/desktop/scenes/desktop_scene_pin_input.c
index 8d714ff9..5a0f63f0 100644
--- a/applications/desktop/scenes/desktop_scene_pin_input.c
+++ b/applications/desktop/scenes/desktop_scene_pin_input.c
@@ -80,7 +80,7 @@ void desktop_scene_pin_input_on_enter(void* context) {
desktop_view_pin_input_set_done_callback(
desktop->pin_input_view, desktop_scene_pin_input_done_callback);
- DesktopScenePinInputState* state = furi_alloc(sizeof(DesktopScenePinInputState));
+ DesktopScenePinInputState* state = malloc(sizeof(DesktopScenePinInputState));
state->timer =
xTimerCreate(NULL, 10000, pdFALSE, desktop, desktop_scene_pin_input_timer_callback);
scene_manager_set_scene_state(desktop->scene_manager, DesktopScenePinInput, (uint32_t)state);
diff --git a/applications/desktop/views/desktop_view_debug.c b/applications/desktop/views/desktop_view_debug.c
index 0ffd8d17..4cb8e8ea 100644
--- a/applications/desktop/views/desktop_view_debug.c
+++ b/applications/desktop/views/desktop_view_debug.c
@@ -150,7 +150,7 @@ bool desktop_debug_input(InputEvent* event, void* context) {
}
DesktopDebugView* desktop_debug_alloc() {
- DesktopDebugView* debug_view = furi_alloc(sizeof(DesktopDebugView));
+ DesktopDebugView* debug_view = malloc(sizeof(DesktopDebugView));
debug_view->view = view_alloc();
view_allocate_model(debug_view->view, ViewModelTypeLocking, sizeof(DesktopDebugViewModel));
view_set_context(debug_view->view, debug_view);
diff --git a/applications/desktop/views/desktop_view_first_start.c b/applications/desktop/views/desktop_view_first_start.c
index 5408dac0..87c07ad2 100644
--- a/applications/desktop/views/desktop_view_first_start.c
+++ b/applications/desktop/views/desktop_view_first_start.c
@@ -131,7 +131,7 @@ static void desktop_first_start_exit(void* context) {
}
DesktopFirstStartView* desktop_first_start_alloc() {
- DesktopFirstStartView* instance = furi_alloc(sizeof(DesktopFirstStartView));
+ DesktopFirstStartView* instance = malloc(sizeof(DesktopFirstStartView));
instance->view = view_alloc();
view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(DesktopFirstStartViewModel));
view_set_context(instance->view, instance);
diff --git a/applications/desktop/views/desktop_view_lock_menu.c b/applications/desktop/views/desktop_view_lock_menu.c
index 005512cf..1b2bd76b 100644
--- a/applications/desktop/views/desktop_view_lock_menu.c
+++ b/applications/desktop/views/desktop_view_lock_menu.c
@@ -112,7 +112,7 @@ bool desktop_lock_menu_input(InputEvent* event, void* context) {
}
DesktopLockMenuView* desktop_lock_menu_alloc() {
- DesktopLockMenuView* lock_menu = furi_alloc(sizeof(DesktopLockMenuView));
+ DesktopLockMenuView* lock_menu = malloc(sizeof(DesktopLockMenuView));
lock_menu->view = view_alloc();
view_allocate_model(lock_menu->view, ViewModelTypeLocking, sizeof(DesktopLockMenuViewModel));
view_set_context(lock_menu->view, lock_menu);
diff --git a/applications/desktop/views/desktop_view_locked.c b/applications/desktop/views/desktop_view_locked.c
index 8e3f22ee..766f2b20 100644
--- a/applications/desktop/views/desktop_view_locked.c
+++ b/applications/desktop/views/desktop_view_locked.c
@@ -184,7 +184,7 @@ static bool desktop_view_locked_input(InputEvent* event, void* context) {
}
DesktopViewLocked* desktop_view_locked_alloc() {
- DesktopViewLocked* locked_view = furi_alloc(sizeof(DesktopViewLocked));
+ DesktopViewLocked* locked_view = malloc(sizeof(DesktopViewLocked));
locked_view->view = view_alloc();
locked_view->timer =
xTimerCreate(NULL, 1000 / 16, pdTRUE, locked_view, locked_view_timer_callback);
diff --git a/applications/desktop/views/desktop_view_main.c b/applications/desktop/views/desktop_view_main.c
index 51520863..091b0855 100644
--- a/applications/desktop/views/desktop_view_main.c
+++ b/applications/desktop/views/desktop_view_main.c
@@ -58,7 +58,7 @@ bool desktop_main_input(InputEvent* event, void* context) {
}
DesktopMainView* desktop_main_alloc() {
- DesktopMainView* main_view = furi_alloc(sizeof(DesktopMainView));
+ DesktopMainView* main_view = malloc(sizeof(DesktopMainView));
main_view->view = view_alloc();
view_allocate_model(main_view->view, ViewModelTypeLockFree, 1);
diff --git a/applications/desktop/views/desktop_view_pin_input.c b/applications/desktop/views/desktop_view_pin_input.c
index b8976ca2..11af5f4a 100644
--- a/applications/desktop/views/desktop_view_pin_input.c
+++ b/applications/desktop/views/desktop_view_pin_input.c
@@ -185,7 +185,7 @@ static void desktop_view_pin_input_exit(void* context) {
}
DesktopViewPinInput* desktop_view_pin_input_alloc(void) {
- DesktopViewPinInput* pin_input = furi_alloc(sizeof(DesktopViewPinInput));
+ DesktopViewPinInput* pin_input = malloc(sizeof(DesktopViewPinInput));
pin_input->view = view_alloc();
view_allocate_model(pin_input->view, ViewModelTypeLocking, sizeof(DesktopViewPinInputModel));
view_set_context(pin_input->view, pin_input);
diff --git a/applications/desktop/views/desktop_view_pin_setup_done.c b/applications/desktop/views/desktop_view_pin_setup_done.c
index a90903e9..1d82aeaa 100644
--- a/applications/desktop/views/desktop_view_pin_setup_done.c
+++ b/applications/desktop/views/desktop_view_pin_setup_done.c
@@ -57,7 +57,7 @@ void desktop_view_pin_done_set_callback(
}
DesktopViewPinSetupDone* desktop_view_pin_done_alloc() {
- DesktopViewPinSetupDone* view = furi_alloc(sizeof(DesktopViewPinSetupDone));
+ DesktopViewPinSetupDone* view = malloc(sizeof(DesktopViewPinSetupDone));
view->view = view_alloc();
view_allocate_model(view->view, ViewModelTypeLockFree, 1);
view_set_context(view->view, view);
diff --git a/applications/desktop/views/desktop_view_pin_timeout.c b/applications/desktop/views/desktop_view_pin_timeout.c
index 7cc0860f..d9827339 100644
--- a/applications/desktop/views/desktop_view_pin_timeout.c
+++ b/applications/desktop/views/desktop_view_pin_timeout.c
@@ -77,7 +77,7 @@ void desktop_view_pin_timeout_free(DesktopViewPinTimeout* instance) {
}
DesktopViewPinTimeout* desktop_view_pin_timeout_alloc(void) {
- DesktopViewPinTimeout* instance = furi_alloc(sizeof(DesktopViewPinTimeout));
+ DesktopViewPinTimeout* instance = malloc(sizeof(DesktopViewPinTimeout));
instance->timer = xTimerCreate(
NULL, pdMS_TO_TICKS(1000), pdTRUE, instance, desktop_view_pin_timeout_timer_callback);
diff --git a/applications/dialogs/dialogs.c b/applications/dialogs/dialogs.c
index 660b646f..2c8d2418 100644
--- a/applications/dialogs/dialogs.c
+++ b/applications/dialogs/dialogs.c
@@ -36,4 +36,4 @@ int32_t dialogs_srv(void* p) {
}
return 0;
-} \ No newline at end of file
+}
diff --git a/applications/dialogs/dialogs_module_file_select.c b/applications/dialogs/dialogs_module_file_select.c
index 177ecdef..f133c00a 100644
--- a/applications/dialogs/dialogs_module_file_select.c
+++ b/applications/dialogs/dialogs_module_file_select.c
@@ -25,8 +25,7 @@ bool dialogs_app_process_module_file_select(const DialogsAppMessageDataFileSelec
bool ret = false;
Gui* gui = furi_record_open("gui");
- DialogsAppFileSelectContext* file_select_context =
- furi_alloc(sizeof(DialogsAppFileSelectContext));
+ DialogsAppFileSelectContext* file_select_context = malloc(sizeof(DialogsAppFileSelectContext));
file_select_context->lock = API_LOCK_INIT_LOCKED();
ViewHolder* view_holder = view_holder_alloc();
@@ -57,4 +56,4 @@ bool dialogs_app_process_module_file_select(const DialogsAppMessageDataFileSelec
furi_record_close("gui");
return ret;
-} \ No newline at end of file
+}
diff --git a/applications/dialogs/dialogs_module_message.c b/applications/dialogs/dialogs_module_message.c
index 045d8692..2607940f 100644
--- a/applications/dialogs/dialogs_module_message.c
+++ b/applications/dialogs/dialogs_module_message.c
@@ -54,7 +54,7 @@ DialogMessageButton dialogs_app_process_module_message(const DialogsAppMessageDa
DialogMessageButton ret = DialogMessageButtonBack;
Gui* gui = furi_record_open("gui");
const DialogMessage* message = data->message;
- DialogsAppMessageContext* message_context = furi_alloc(sizeof(DialogsAppMessageContext));
+ DialogsAppMessageContext* message_context = malloc(sizeof(DialogsAppMessageContext));
message_context->lock = API_LOCK_INIT_LOCKED();
ViewHolder* view_holder = view_holder_alloc();
@@ -100,7 +100,7 @@ DialogMessageButton dialogs_app_process_module_message(const DialogsAppMessageDa
}
DialogMessage* dialog_message_alloc() {
- DialogMessage* message = furi_alloc(sizeof(DialogMessage));
+ DialogMessage* message = malloc(sizeof(DialogMessage));
return message;
}
@@ -150,4 +150,4 @@ void dialog_message_set_buttons(
message->left_button_text = left;
message->center_button_text = center;
message->right_button_text = right;
-} \ No newline at end of file
+}
diff --git a/applications/dialogs/view_holder.c b/applications/dialogs/view_holder.c
index 577f5282..eb8a1502 100644
--- a/applications/dialogs/view_holder.c
+++ b/applications/dialogs/view_holder.c
@@ -21,7 +21,7 @@ static void view_holder_draw_callback(Canvas* canvas, void* context);
static void view_holder_input_callback(InputEvent* event, void* context);
ViewHolder* view_holder_alloc() {
- ViewHolder* view_holder = furi_alloc(sizeof(ViewHolder));
+ ViewHolder* view_holder = malloc(sizeof(ViewHolder));
view_holder->view_port = view_port_alloc();
view_port_draw_callback_set(view_holder->view_port, view_holder_draw_callback, view_holder);
@@ -147,4 +147,4 @@ static void view_holder_input_callback(InputEvent* event, void* context) {
}
}
}
-} \ No newline at end of file
+}
diff --git a/applications/dolphin/dolphin.c b/applications/dolphin/dolphin.c
index 92c6d7a7..60068aff 100644
--- a/applications/dolphin/dolphin.c
+++ b/applications/dolphin/dolphin.c
@@ -74,7 +74,7 @@ void dolphin_clear_limits_timer_callback(TimerHandle_t xTimer) {
}
Dolphin* dolphin_alloc() {
- Dolphin* dolphin = furi_alloc(sizeof(Dolphin));
+ Dolphin* dolphin = malloc(sizeof(Dolphin));
dolphin->state = dolphin_state_alloc();
dolphin->event_queue = osMessageQueueNew(8, sizeof(DolphinEvent), NULL);
diff --git a/applications/dolphin/helpers/dolphin_state.c b/applications/dolphin/helpers/dolphin_state.c
index a14b106d..08a7dae3 100644
--- a/applications/dolphin/helpers/dolphin_state.c
+++ b/applications/dolphin/helpers/dolphin_state.c
@@ -17,7 +17,7 @@
#define BUTTHURT_MIN 0
DolphinState* dolphin_state_alloc() {
- return furi_alloc(sizeof(DolphinState));
+ return malloc(sizeof(DolphinState));
}
void dolphin_state_free(DolphinState* dolphin_state) {
diff --git a/applications/gpio/gpio_app.c b/applications/gpio/gpio_app.c
index ba7a230e..489c9854 100644
--- a/applications/gpio/gpio_app.c
+++ b/applications/gpio/gpio_app.c
@@ -22,7 +22,7 @@ static void gpio_app_tick_event_callback(void* context) {
}
GpioApp* gpio_app_alloc() {
- GpioApp* app = furi_alloc(sizeof(GpioApp));
+ GpioApp* app = malloc(sizeof(GpioApp));
app->gui = furi_record_open("gui");
diff --git a/applications/gpio/scenes/gpio_scene_usb_uart.c b/applications/gpio/scenes/gpio_scene_usb_uart.c
index 2e34bc8d..e2babcac 100644
--- a/applications/gpio/scenes/gpio_scene_usb_uart.c
+++ b/applications/gpio/scenes/gpio_scene_usb_uart.c
@@ -18,7 +18,7 @@ void gpio_scene_usb_uart_on_enter(void* context) {
GpioApp* app = context;
uint32_t prev_state = scene_manager_get_scene_state(app->scene_manager, GpioAppViewUsbUart);
if(prev_state == 0) {
- scene_usb_uart = furi_alloc(sizeof(SceneUsbUartBridge));
+ scene_usb_uart = malloc(sizeof(SceneUsbUartBridge));
scene_usb_uart->cfg.vcp_ch = 0; // TODO: settings load
scene_usb_uart->cfg.uart_ch = 0;
scene_usb_uart->cfg.flow_pins = 0;
diff --git a/applications/gpio/scenes/gpio_scene_usb_uart_config.c b/applications/gpio/scenes/gpio_scene_usb_uart_config.c
index 72f6db69..6fba0d1e 100644
--- a/applications/gpio/scenes/gpio_scene_usb_uart_config.c
+++ b/applications/gpio/scenes/gpio_scene_usb_uart_config.c
@@ -91,7 +91,7 @@ void gpio_scene_usb_uart_cfg_on_enter(void* context) {
GpioApp* app = context;
VariableItemList* var_item_list = app->var_item_list;
- cfg_set = furi_alloc(sizeof(UsbUartConfig));
+ cfg_set = malloc(sizeof(UsbUartConfig));
usb_uart_get_config(app->usb_uart_bridge, cfg_set);
VariableItem* item;
diff --git a/applications/gpio/usb_uart_bridge.c b/applications/gpio/usb_uart_bridge.c
index c9085af7..e8762ca9 100644
--- a/applications/gpio/usb_uart_bridge.c
+++ b/applications/gpio/usb_uart_bridge.c
@@ -312,7 +312,7 @@ static void vcp_on_line_config(void* context, struct usb_cdc_line_coding* config
}
UsbUartBridge* usb_uart_enable(UsbUartConfig* cfg) {
- UsbUartBridge* usb_uart = furi_alloc(sizeof(UsbUartBridge));
+ UsbUartBridge* usb_uart = malloc(sizeof(UsbUartBridge));
memcpy(&(usb_uart->cfg_new), cfg, sizeof(UsbUartConfig));
diff --git a/applications/gpio/views/gpio_test.c b/applications/gpio/views/gpio_test.c
index 62f3426e..cf05dafa 100755
--- a/applications/gpio/views/gpio_test.c
+++ b/applications/gpio/views/gpio_test.c
@@ -96,7 +96,7 @@ static bool gpio_test_process_ok(GpioTest* gpio_test, InputEvent* event) {
}
GpioTest* gpio_test_alloc() {
- GpioTest* gpio_test = furi_alloc(sizeof(GpioTest));
+ GpioTest* gpio_test = malloc(sizeof(GpioTest));
gpio_test->view = view_alloc();
view_allocate_model(gpio_test->view, ViewModelTypeLocking, sizeof(GpioTestModel));
diff --git a/applications/gpio/views/gpio_usb_uart.c b/applications/gpio/views/gpio_usb_uart.c
index be80f019..cd507570 100644
--- a/applications/gpio/views/gpio_usb_uart.c
+++ b/applications/gpio/views/gpio_usb_uart.c
@@ -102,7 +102,7 @@ static bool gpio_usb_uart_input_callback(InputEvent* event, void* context) {
}
GpioUsbUart* gpio_usb_uart_alloc() {
- GpioUsbUart* usb_uart = furi_alloc(sizeof(GpioUsbUart));
+ GpioUsbUart* usb_uart = malloc(sizeof(GpioUsbUart));
usb_uart->view = view_alloc();
view_allocate_model(usb_uart->view, ViewModelTypeLocking, sizeof(GpioUsbUartModel));
diff --git a/applications/gui/canvas.c b/applications/gui/canvas.c
index 3706b176..fe07bd5e 100644
--- a/applications/gui/canvas.c
+++ b/applications/gui/canvas.c
@@ -15,7 +15,7 @@ const CanvasFontParameters canvas_font_params[FontTotalNumber] = {
};
Canvas* canvas_init() {
- Canvas* canvas = furi_alloc(sizeof(Canvas));
+ Canvas* canvas = malloc(sizeof(Canvas));
furi_hal_power_insomnia_enter();
diff --git a/applications/gui/gui.c b/applications/gui/gui.c
index bc333bb1..7d34f5e2 100644
--- a/applications/gui/gui.c
+++ b/applications/gui/gui.c
@@ -417,7 +417,7 @@ void gui_set_lockdown(Gui* gui, bool lockdown) {
}
Gui* gui_alloc() {
- Gui* gui = furi_alloc(sizeof(Gui));
+ Gui* gui = malloc(sizeof(Gui));
// Thread ID
gui->thread = osThreadGetId();
// Allocate mutex
diff --git a/applications/gui/icon_animation.c b/applications/gui/icon_animation.c
index 530f3fa7..5170eea4 100644
--- a/applications/gui/icon_animation.c
+++ b/applications/gui/icon_animation.c
@@ -5,7 +5,7 @@
IconAnimation* icon_animation_alloc(const Icon* icon) {
furi_assert(icon);
- IconAnimation* instance = furi_alloc(sizeof(IconAnimation));
+ IconAnimation* instance = malloc(sizeof(IconAnimation));
instance->icon = icon;
instance->timer = osTimerNew(icon_animation_timer_callback, osTimerPeriodic, instance, NULL);
return instance;
diff --git a/applications/gui/modules/button_menu.c b/applications/gui/modules/button_menu.c
index e8bbb6a1..0f379b74 100644
--- a/applications/gui/modules/button_menu.c
+++ b/applications/gui/modules/button_menu.c
@@ -290,7 +290,7 @@ ButtonMenuItem* button_menu_add_item(
}
ButtonMenu* button_menu_alloc(void) {
- ButtonMenu* button_menu = furi_alloc(sizeof(ButtonMenu));
+ ButtonMenu* button_menu = malloc(sizeof(ButtonMenu));
button_menu->view = view_alloc();
view_set_orientation(button_menu->view, ViewOrientationVertical);
view_set_context(button_menu->view, button_menu);
diff --git a/applications/gui/modules/button_panel.c b/applications/gui/modules/button_panel.c
index 075e0c76..07bb6b62 100644
--- a/applications/gui/modules/button_panel.c
+++ b/applications/gui/modules/button_panel.c
@@ -65,7 +65,7 @@ static void button_panel_view_draw_callback(Canvas* canvas, void* _model);
static bool button_panel_view_input_callback(InputEvent* event, void* context);
ButtonPanel* button_panel_alloc() {
- ButtonPanel* button_panel = furi_alloc(sizeof(ButtonPanel));
+ ButtonPanel* button_panel = malloc(sizeof(ButtonPanel));
button_panel->view = view_alloc();
view_set_orientation(button_panel->view, ViewOrientationVertical);
view_set_context(button_panel->view, button_panel);
@@ -173,7 +173,7 @@ void button_panel_add_item(
ButtonItem** button_item_ptr =
button_panel_get_item(model, matrix_place_x, matrix_place_y);
furi_check(*button_item_ptr == NULL);
- *button_item_ptr = furi_alloc(sizeof(ButtonItem));
+ *button_item_ptr = malloc(sizeof(ButtonItem));
ButtonItem* button_item = *button_item_ptr;
button_item->callback = callback;
button_item->callback_context = callback_context;
diff --git a/applications/gui/modules/byte_input.c b/applications/gui/modules/byte_input.c
index b116030f..bb18a107 100644
--- a/applications/gui/modules/byte_input.c
+++ b/applications/gui/modules/byte_input.c
@@ -695,7 +695,7 @@ static void byte_input_reset_model_input_data(ByteInputModel* model) {
* @return ByteInput instance pointer
*/
ByteInput* byte_input_alloc() {
- ByteInput* byte_input = furi_alloc(sizeof(ByteInput));
+ ByteInput* byte_input = malloc(sizeof(ByteInput));
byte_input->view = view_alloc();
view_set_context(byte_input->view, byte_input);
view_allocate_model(byte_input->view, ViewModelTypeLocking, sizeof(ByteInputModel));
diff --git a/applications/gui/modules/dialog.c b/applications/gui/modules/dialog.c
index af649086..5d36f93f 100644
--- a/applications/gui/modules/dialog.c
+++ b/applications/gui/modules/dialog.c
@@ -60,7 +60,7 @@ static bool dialog_view_input_callback(InputEvent* event, void* context) {
}
Dialog* dialog_alloc() {
- Dialog* dialog = furi_alloc(sizeof(Dialog));
+ Dialog* dialog = malloc(sizeof(Dialog));
dialog->view = view_alloc();
view_set_context(dialog->view, dialog);
view_allocate_model(dialog->view, ViewModelTypeLockFree, sizeof(DialogModel));
diff --git a/applications/gui/modules/dialog_ex.c b/applications/gui/modules/dialog_ex.c
index 5dd0e410..6be455f8 100755
--- a/applications/gui/modules/dialog_ex.c
+++ b/applications/gui/modules/dialog_ex.c
@@ -114,7 +114,7 @@ static bool dialog_ex_view_input_callback(InputEvent* event, void* context) {
}
DialogEx* dialog_ex_alloc() {
- DialogEx* dialog_ex = furi_alloc(sizeof(DialogEx));
+ DialogEx* dialog_ex = malloc(sizeof(DialogEx));
dialog_ex->view = view_alloc();
view_set_context(dialog_ex->view, dialog_ex);
view_allocate_model(dialog_ex->view, ViewModelTypeLockFree, sizeof(DialogExModel));
diff --git a/applications/gui/modules/empty_screen.c b/applications/gui/modules/empty_screen.c
index a887786d..61b4af36 100644
--- a/applications/gui/modules/empty_screen.c
+++ b/applications/gui/modules/empty_screen.c
@@ -14,7 +14,7 @@ static bool empty_screen_view_input_callback(InputEvent* event, void* context) {
}
EmptyScreen* empty_screen_alloc() {
- EmptyScreen* empty_screen = furi_alloc(sizeof(EmptyScreen));
+ EmptyScreen* empty_screen = malloc(sizeof(EmptyScreen));
empty_screen->view = view_alloc();
view_set_context(empty_screen->view, empty_screen);
view_set_draw_callback(empty_screen->view, empty_screen_view_draw_callback);
@@ -31,4 +31,4 @@ void empty_screen_free(EmptyScreen* empty_screen) {
View* empty_screen_get_view(EmptyScreen* empty_screen) {
furi_assert(empty_screen);
return empty_screen->view;
-} \ No newline at end of file
+}
diff --git a/applications/gui/modules/file_select.c b/applications/gui/modules/file_select.c
index 78ecd241..14541196 100644
--- a/applications/gui/modules/file_select.c
+++ b/applications/gui/modules/file_select.c
@@ -181,7 +181,7 @@ static bool file_select_init_inner(FileSelect* file_select) {
}
FileSelect* file_select_alloc() {
- FileSelect* file_select = furi_alloc(sizeof(FileSelect));
+ FileSelect* file_select = malloc(sizeof(FileSelect));
file_select->view = view_alloc();
file_select->fs_api = furi_record_open("storage");
@@ -278,7 +278,7 @@ bool file_select_fill_strings(FileSelect* file_select) {
uint8_t string_counter = 0;
uint16_t file_counter = 0;
const uint8_t name_length = 100;
- char* name = furi_alloc(name_length);
+ char* name = malloc(name_length);
uint16_t first_file_index = 0;
with_view_model(
@@ -346,7 +346,7 @@ bool file_select_fill_count(FileSelect* file_select) {
uint16_t file_counter = 0;
const uint8_t name_length = 100;
- char* name = furi_alloc(name_length);
+ char* name = malloc(name_length);
if(!storage_dir_open(directory, file_select->path)) {
storage_dir_close(directory);
@@ -397,7 +397,7 @@ void file_select_set_selected_file_internal(FileSelect* file_select, const char*
File* directory = storage_file_alloc(file_select->fs_api);
const uint8_t name_length = 100;
- char* name = furi_alloc(name_length);
+ char* name = malloc(name_length);
uint16_t file_position = 0;
bool file_found = false;
@@ -472,4 +472,4 @@ void file_select_set_selected_file(FileSelect* file_select, const char* filename
if(!file_select_fill_strings(file_select)) {
file_select->callback(false, file_select->context);
}
-} \ No newline at end of file
+}
diff --git a/applications/gui/modules/menu.c b/applications/gui/modules/menu.c
index 0fb95d70..67d46d5f 100644
--- a/applications/gui/modules/menu.c
+++ b/applications/gui/modules/menu.c
@@ -125,7 +125,7 @@ static void menu_exit(void* context) {
}
Menu* menu_alloc() {
- Menu* menu = furi_alloc(sizeof(Menu));
+ Menu* menu = malloc(sizeof(Menu));
menu->view = view_alloc(menu->view);
view_set_context(menu->view, menu);
view_allocate_model(menu->view, ViewModelTypeLocking, sizeof(MenuModel));
diff --git a/applications/gui/modules/popup.c b/applications/gui/modules/popup.c
index 0e3b3889..3b53d962 100644
--- a/applications/gui/modules/popup.c
+++ b/applications/gui/modules/popup.c
@@ -108,7 +108,7 @@ void popup_stop_timer(void* context) {
}
Popup* popup_alloc() {
- Popup* popup = furi_alloc(sizeof(Popup));
+ Popup* popup = malloc(sizeof(Popup));
popup->view = view_alloc();
popup->timer = osTimerNew(popup_timer_callback, osTimerOnce, popup, NULL);
furi_assert(popup->timer);
diff --git a/applications/gui/modules/submenu.c b/applications/gui/modules/submenu.c
index e9e27203..9fefeca0 100644
--- a/applications/gui/modules/submenu.c
+++ b/applications/gui/modules/submenu.c
@@ -120,7 +120,7 @@ static bool submenu_view_input_callback(InputEvent* event, void* context) {
}
Submenu* submenu_alloc() {
- Submenu* submenu = furi_alloc(sizeof(Submenu));
+ Submenu* submenu = malloc(sizeof(Submenu));
submenu->view = view_alloc();
view_set_context(submenu->view, submenu);
view_allocate_model(submenu->view, ViewModelTypeLocking, sizeof(SubmenuModel));
diff --git a/applications/gui/modules/text_box.c b/applications/gui/modules/text_box.c
index 7e7eacd6..e2a99c22 100755
--- a/applications/gui/modules/text_box.c
+++ b/applications/gui/modules/text_box.c
@@ -128,7 +128,7 @@ static bool text_box_view_input_callback(InputEvent* event, void* context) {
}
TextBox* text_box_alloc() {
- TextBox* text_box = furi_alloc(sizeof(TextBox));
+ TextBox* text_box = malloc(sizeof(TextBox));
text_box->view = view_alloc();
view_set_context(text_box->view, text_box);
view_allocate_model(text_box->view, ViewModelTypeLocking, sizeof(TextBoxModel));
diff --git a/applications/gui/modules/text_input.c b/applications/gui/modules/text_input.c
index bb200606..d42f9dcf 100755
--- a/applications/gui/modules/text_input.c
+++ b/applications/gui/modules/text_input.c
@@ -410,7 +410,7 @@ void text_input_timer_callback(void* context) {
}
TextInput* text_input_alloc() {
- TextInput* text_input = furi_alloc(sizeof(TextInput));
+ TextInput* text_input = malloc(sizeof(TextInput));
text_input->view = view_alloc();
view_set_context(text_input->view, text_input);
view_allocate_model(text_input->view, ViewModelTypeLocking, sizeof(TextInputModel));
diff --git a/applications/gui/modules/validators.c b/applications/gui/modules/validators.c
index dc752e95..df0be729 100644
--- a/applications/gui/modules/validators.c
+++ b/applications/gui/modules/validators.c
@@ -28,7 +28,7 @@ bool validator_is_file_callback(const char* text, string_t error, void* context)
ValidatorIsFile*
validator_is_file_alloc_init(const char* app_path_folder, const char* app_extension) {
- ValidatorIsFile* instance = furi_alloc(sizeof(ValidatorIsFile));
+ ValidatorIsFile* instance = malloc(sizeof(ValidatorIsFile));
instance->app_path_folder = app_path_folder;
instance->app_extension = app_extension;
diff --git a/applications/gui/modules/variable_item_list.c b/applications/gui/modules/variable_item_list.c
index cf2b01a1..ebbdd434 100644
--- a/applications/gui/modules/variable_item_list.c
+++ b/applications/gui/modules/variable_item_list.c
@@ -276,7 +276,7 @@ void variable_item_list_process_ok(VariableItemList* variable_item_list) {
}
VariableItemList* variable_item_list_alloc() {
- VariableItemList* variable_item_list = furi_alloc(sizeof(VariableItemList));
+ VariableItemList* variable_item_list = malloc(sizeof(VariableItemList));
variable_item_list->view = view_alloc();
view_set_context(variable_item_list->view, variable_item_list);
view_allocate_model(
diff --git a/applications/gui/modules/widget.c b/applications/gui/modules/widget.c
index d6c50aaa..09729ee6 100755
--- a/applications/gui/modules/widget.c
+++ b/applications/gui/modules/widget.c
@@ -52,7 +52,7 @@ static bool gui_widget_view_input_callback(InputEvent* event, void* context) {
}
Widget* widget_alloc() {
- Widget* widget = furi_alloc(sizeof(Widget));
+ Widget* widget = malloc(sizeof(Widget));
widget->view = view_alloc();
view_set_context(widget->view, widget);
view_allocate_model(widget->view, ViewModelTypeLocking, sizeof(GuiWidgetModel));
diff --git a/applications/gui/modules/widget_elements/widget_element_button.c b/applications/gui/modules/widget_elements/widget_element_button.c
index 2fbfb892..92be2590 100644
--- a/applications/gui/modules/widget_elements/widget_element_button.c
+++ b/applications/gui/modules/widget_elements/widget_element_button.c
@@ -61,14 +61,14 @@ WidgetElement* widget_element_button_create(
ButtonCallback callback,
void* context) {
// Allocate and init model
- GuiButtonModel* model = furi_alloc(sizeof(GuiButtonModel));
+ GuiButtonModel* model = malloc(sizeof(GuiButtonModel));
model->button_type = button_type;
model->callback = callback;
model->context = context;
string_init_set_str(model->text, text);
// Allocate and init Element
- WidgetElement* gui_button = furi_alloc(sizeof(WidgetElement));
+ WidgetElement* gui_button = malloc(sizeof(WidgetElement));
gui_button->parent = NULL;
gui_button->input = gui_button_input;
gui_button->draw = gui_button_draw;
diff --git a/applications/gui/modules/widget_elements/widget_element_frame.c b/applications/gui/modules/widget_elements/widget_element_frame.c
index a8e00d9a..a7265348 100755
--- a/applications/gui/modules/widget_elements/widget_element_frame.c
+++ b/applications/gui/modules/widget_elements/widget_element_frame.c
@@ -29,7 +29,7 @@ WidgetElement* widget_element_frame_create(
uint8_t height,
uint8_t radius) {
// Allocate and init model
- GuiFrameModel* model = furi_alloc(sizeof(GuiFrameModel));
+ GuiFrameModel* model = malloc(sizeof(GuiFrameModel));
model->x = x;
model->y = y;
model->width = width;
@@ -37,7 +37,7 @@ WidgetElement* widget_element_frame_create(
model->radius = radius;
// Allocate and init Element
- WidgetElement* gui_frame = furi_alloc(sizeof(WidgetElement));
+ WidgetElement* gui_frame = malloc(sizeof(WidgetElement));
gui_frame->parent = NULL;
gui_frame->input = NULL;
gui_frame->draw = gui_frame_draw;
diff --git a/applications/gui/modules/widget_elements/widget_element_icon.c b/applications/gui/modules/widget_elements/widget_element_icon.c
index e9ff3a97..1340f48f 100644
--- a/applications/gui/modules/widget_elements/widget_element_icon.c
+++ b/applications/gui/modules/widget_elements/widget_element_icon.c
@@ -27,13 +27,13 @@ WidgetElement* widget_element_icon_create(uint8_t x, uint8_t y, const Icon* icon
furi_assert(icon);
// Allocate and init model
- GuiIconModel* model = furi_alloc(sizeof(GuiIconModel));
+ GuiIconModel* model = malloc(sizeof(GuiIconModel));
model->x = x;
model->y = y;
model->icon = icon;
// Allocate and init Element
- WidgetElement* gui_icon = furi_alloc(sizeof(WidgetElement));
+ WidgetElement* gui_icon = malloc(sizeof(WidgetElement));
gui_icon->parent = NULL;
gui_icon->input = NULL;
gui_icon->draw = gui_icon_draw;
diff --git a/applications/gui/modules/widget_elements/widget_element_string.c b/applications/gui/modules/widget_elements/widget_element_string.c
index e81cd439..a03c2b6d 100755
--- a/applications/gui/modules/widget_elements/widget_element_string.c
+++ b/applications/gui/modules/widget_elements/widget_element_string.c
@@ -46,7 +46,7 @@ WidgetElement* widget_element_string_create(
furi_assert(text);
// Allocate and init model
- GuiStringModel* model = furi_alloc(sizeof(GuiStringModel));
+ GuiStringModel* model = malloc(sizeof(GuiStringModel));
model->x = x;
model->y = y;
model->horizontal = horizontal;
@@ -55,7 +55,7 @@ WidgetElement* widget_element_string_create(
string_init_set_str(model->text, text);
// Allocate and init Element
- WidgetElement* gui_string = furi_alloc(sizeof(WidgetElement));
+ WidgetElement* gui_string = malloc(sizeof(WidgetElement));
gui_string->parent = NULL;
gui_string->input = NULL;
gui_string->draw = gui_string_draw;
diff --git a/applications/gui/modules/widget_elements/widget_element_string_multiline.c b/applications/gui/modules/widget_elements/widget_element_string_multiline.c
index f37eb3fc..01a70a0d 100644
--- a/applications/gui/modules/widget_elements/widget_element_string_multiline.c
+++ b/applications/gui/modules/widget_elements/widget_element_string_multiline.c
@@ -47,7 +47,7 @@ WidgetElement* widget_element_string_multiline_create(
furi_assert(text);
// Allocate and init model
- GuiStringMultiLineModel* model = furi_alloc(sizeof(GuiStringMultiLineModel));
+ GuiStringMultiLineModel* model = malloc(sizeof(GuiStringMultiLineModel));
model->x = x;
model->y = y;
model->horizontal = horizontal;
@@ -56,7 +56,7 @@ WidgetElement* widget_element_string_multiline_create(
string_init_set_str(model->text, text);
// Allocate and init Element
- WidgetElement* gui_string = furi_alloc(sizeof(WidgetElement));
+ WidgetElement* gui_string = malloc(sizeof(WidgetElement));
gui_string->parent = NULL;
gui_string->input = NULL;
gui_string->draw = gui_string_multiline_draw;
diff --git a/applications/gui/modules/widget_elements/widget_element_text_box.c b/applications/gui/modules/widget_elements/widget_element_text_box.c
index 9ee33188..a4dee5f6 100644
--- a/applications/gui/modules/widget_elements/widget_element_text_box.c
+++ b/applications/gui/modules/widget_elements/widget_element_text_box.c
@@ -50,7 +50,7 @@ WidgetElement* widget_element_text_box_create(
furi_assert(text);
// Allocate and init model
- GuiTextBoxModel* model = furi_alloc(sizeof(GuiTextBoxModel));
+ GuiTextBoxModel* model = malloc(sizeof(GuiTextBoxModel));
model->x = x;
model->y = y;
model->width = width;
@@ -60,7 +60,7 @@ WidgetElement* widget_element_text_box_create(
string_init_set_str(model->text, text);
// Allocate and init Element
- WidgetElement* gui_string = furi_alloc(sizeof(WidgetElement));
+ WidgetElement* gui_string = malloc(sizeof(WidgetElement));
gui_string->parent = NULL;
gui_string->input = NULL;
gui_string->draw = gui_text_box_draw;
diff --git a/applications/gui/scene_manager.c b/applications/gui/scene_manager.c
index a3aadb74..a8c40320 100755
--- a/applications/gui/scene_manager.c
+++ b/applications/gui/scene_manager.c
@@ -4,12 +4,12 @@
SceneManager* scene_manager_alloc(const SceneManagerHandlers* app_scene_handlers, void* context) {
furi_assert(context);
- SceneManager* scene_manager = furi_alloc(sizeof(SceneManager));
+ SceneManager* scene_manager = malloc(sizeof(SceneManager));
// Set SceneManager context and scene handlers
scene_manager->context = context;
scene_manager->scene_handlers = app_scene_handlers;
// Allocate all scenes
- scene_manager->scene = furi_alloc(sizeof(AppScene) * app_scene_handlers->scene_num);
+ scene_manager->scene = malloc(sizeof(AppScene) * app_scene_handlers->scene_num);
// Initialize ScaneManager array for navigation
SceneManagerIdStack_init(scene_manager->scene_id_stack);
@@ -48,9 +48,16 @@ bool scene_manager_handle_custom_event(SceneManager* scene_manager, uint32_t cus
.type = SceneManagerEventTypeCustom,
.event = custom_event,
};
- uint32_t scene_id = *SceneManagerIdStack_back(scene_manager->scene_id_stack);
- return scene_manager->scene_handlers->on_event_handlers[scene_id](
- scene_manager->context, event);
+
+ bool result = false;
+ if(SceneManagerIdStack_size(scene_manager->scene_id_stack) > 0) {
+ uint32_t* scene_id_p = SceneManagerIdStack_back(scene_manager->scene_id_stack);
+ uint32_t scene_id = *scene_id_p;
+ result = scene_manager->scene_handlers->on_event_handlers[scene_id](
+ scene_manager->context, event);
+ }
+
+ return result;
}
bool scene_manager_handle_back_event(SceneManager* scene_manager) {
@@ -59,9 +66,15 @@ bool scene_manager_handle_back_event(SceneManager* scene_manager) {
SceneManagerEvent event = {
.type = SceneManagerEventTypeBack,
};
- uint32_t scene_id = *SceneManagerIdStack_back(scene_manager->scene_id_stack);
- bool consumed =
- scene_manager->scene_handlers->on_event_handlers[scene_id](scene_manager->context, event);
+
+ bool consumed = false;
+ if(SceneManagerIdStack_size(scene_manager->scene_id_stack) > 0) {
+ uint32_t* scene_id_p = SceneManagerIdStack_back(scene_manager->scene_id_stack);
+ uint32_t scene_id = *scene_id_p;
+ consumed = scene_manager->scene_handlers->on_event_handlers[scene_id](
+ scene_manager->context, event);
+ }
+
if(!consumed) {
consumed = scene_manager_previous_scene(scene_manager);
}
@@ -74,8 +87,12 @@ void scene_manager_handle_tick_event(SceneManager* scene_manager) {
SceneManagerEvent event = {
.type = SceneManagerEventTypeTick,
};
- uint32_t scene_id = *SceneManagerIdStack_back(scene_manager->scene_id_stack);
- scene_manager->scene_handlers->on_event_handlers[scene_id](scene_manager->context, event);
+
+ if(SceneManagerIdStack_size(scene_manager->scene_id_stack) > 0) {
+ uint32_t* scene_id_p = SceneManagerIdStack_back(scene_manager->scene_id_stack);
+ uint32_t scene_id = *scene_id_p;
+ scene_manager->scene_handlers->on_event_handlers[scene_id](scene_manager->context, event);
+ }
}
void scene_manager_next_scene(SceneManager* scene_manager, uint32_t next_scene_id) {
@@ -83,7 +100,7 @@ void scene_manager_next_scene(SceneManager* scene_manager, uint32_t next_scene_i
furi_assert(next_scene_id < scene_manager->scene_handlers->scene_num);
// Check if it is not the first scene
- if(SceneManagerIdStack_size(scene_manager->scene_id_stack)) {
+ if(SceneManagerIdStack_size(scene_manager->scene_id_stack) > 0) {
uint32_t cur_scene_id = *SceneManagerIdStack_back(scene_manager->scene_id_stack);
scene_manager->scene_handlers->on_exit_handlers[cur_scene_id](scene_manager->context);
}
@@ -95,18 +112,22 @@ void scene_manager_next_scene(SceneManager* scene_manager, uint32_t next_scene_i
bool scene_manager_previous_scene(SceneManager* scene_manager) {
furi_assert(scene_manager);
- uint32_t cur_scene_id = 0;
- SceneManagerIdStack_pop_back(&cur_scene_id, scene_manager->scene_id_stack);
+ if(SceneManagerIdStack_size(scene_manager->scene_id_stack) > 0) {
+ uint32_t cur_scene_id = 0;
+ SceneManagerIdStack_pop_back(&cur_scene_id, scene_manager->scene_id_stack);
- // Handle exit from start scene separately
- if(SceneManagerIdStack_size(scene_manager->scene_id_stack) == 0) {
+ // Handle exit from start scene separately
+ if(SceneManagerIdStack_size(scene_manager->scene_id_stack) == 0) {
+ scene_manager->scene_handlers->on_exit_handlers[cur_scene_id](scene_manager->context);
+ return false;
+ }
+ uint32_t prev_scene_id = *SceneManagerIdStack_back(scene_manager->scene_id_stack);
scene_manager->scene_handlers->on_exit_handlers[cur_scene_id](scene_manager->context);
+ scene_manager->scene_handlers->on_enter_handlers[prev_scene_id](scene_manager->context);
+ return true;
+ } else {
return false;
}
- uint32_t prev_scene_id = *SceneManagerIdStack_back(scene_manager->scene_id_stack);
- scene_manager->scene_handlers->on_exit_handlers[cur_scene_id](scene_manager->context);
- scene_manager->scene_handlers->on_enter_handlers[prev_scene_id](scene_manager->context);
- return true;
}
bool scene_manager_search_and_switch_to_previous_scene(
@@ -114,48 +135,55 @@ bool scene_manager_search_and_switch_to_previous_scene(
uint32_t scene_id) {
furi_assert(scene_manager);
- uint32_t prev_scene_id = 0;
- uint32_t cur_scene_id = *SceneManagerIdStack_back(scene_manager->scene_id_stack);
- SceneManagerIdStack_it_t scene_it;
- SceneManagerIdStack_it_last(scene_it, scene_manager->scene_id_stack);
- // Search scene with given id in navigation stack
- bool scene_found = false;
- while(!scene_found) {
- SceneManagerIdStack_previous(scene_it);
- if(SceneManagerIdStack_end_p(scene_it)) {
- return false;
- }
- prev_scene_id = *SceneManagerIdStack_ref(scene_it);
- if(prev_scene_id == scene_id) {
- scene_found = true;
+ if(SceneManagerIdStack_size(scene_manager->scene_id_stack) > 0) {
+ uint32_t prev_scene_id = 0;
+ uint32_t cur_scene_id = *SceneManagerIdStack_back(scene_manager->scene_id_stack);
+ SceneManagerIdStack_it_t scene_it;
+ SceneManagerIdStack_it_last(scene_it, scene_manager->scene_id_stack);
+ // Search scene with given id in navigation stack
+ bool scene_found = false;
+ while(!scene_found) {
+ SceneManagerIdStack_previous(scene_it);
+ if(SceneManagerIdStack_end_p(scene_it)) {
+ return false;
+ }
+ prev_scene_id = *SceneManagerIdStack_ref(scene_it);
+ if(prev_scene_id == scene_id) {
+ scene_found = true;
+ }
}
- }
- // Remove all scene id from navigation stack
- SceneManagerIdStack_next(scene_it);
- SceneManagerIdStack_pop_until(scene_manager->scene_id_stack, scene_it);
+ // Remove all scene id from navigation stack
+ SceneManagerIdStack_next(scene_it);
+ SceneManagerIdStack_pop_until(scene_manager->scene_id_stack, scene_it);
- scene_manager->scene_handlers->on_exit_handlers[cur_scene_id](scene_manager->context);
- scene_manager->scene_handlers->on_enter_handlers[prev_scene_id](scene_manager->context);
+ scene_manager->scene_handlers->on_exit_handlers[cur_scene_id](scene_manager->context);
+ scene_manager->scene_handlers->on_enter_handlers[prev_scene_id](scene_manager->context);
- return true;
+ return true;
+ } else {
+ return false;
+ }
}
bool scene_manager_has_previous_scene(SceneManager* scene_manager, uint32_t scene_id) {
furi_assert(scene_manager);
bool scene_found = false;
- uint32_t prev_scene_id;
- SceneManagerIdStack_it_t scene_it;
- SceneManagerIdStack_it_last(scene_it, scene_manager->scene_id_stack);
-
- // Perform search in scene stack
- while(!scene_found) {
- SceneManagerIdStack_previous(scene_it);
- if(SceneManagerIdStack_end_p(scene_it)) {
- break;
- }
- prev_scene_id = *SceneManagerIdStack_ref(scene_it);
- if(prev_scene_id == scene_id) {
- scene_found = true;
+
+ if(SceneManagerIdStack_size(scene_manager->scene_id_stack) > 0) {
+ uint32_t prev_scene_id;
+ SceneManagerIdStack_it_t scene_it;
+ SceneManagerIdStack_it_last(scene_it, scene_manager->scene_id_stack);
+
+ // Perform search in scene stack
+ while(!scene_found) {
+ SceneManagerIdStack_previous(scene_it);
+ if(SceneManagerIdStack_end_p(scene_it)) {
+ break;
+ }
+ prev_scene_id = *SceneManagerIdStack_ref(scene_it);
+ if(prev_scene_id == scene_id) {
+ scene_found = true;
+ }
}
}
return scene_found;
@@ -167,25 +195,29 @@ bool scene_manager_search_and_switch_to_another_scene(
furi_assert(scene_manager);
furi_assert(scene_id < scene_manager->scene_handlers->scene_num);
- uint32_t cur_scene_id = *SceneManagerIdStack_back(scene_manager->scene_id_stack);
- SceneManagerIdStack_it_t scene_it;
- SceneManagerIdStack_it(scene_it, scene_manager->scene_id_stack);
- SceneManagerIdStack_next(scene_it);
- // Remove all scene id from navigation stack until first scene
- SceneManagerIdStack_pop_until(scene_manager->scene_id_stack, scene_it);
- // Add next scene
- SceneManagerIdStack_push_back(scene_manager->scene_id_stack, scene_id);
+ if(SceneManagerIdStack_size(scene_manager->scene_id_stack) > 0) {
+ uint32_t cur_scene_id = *SceneManagerIdStack_back(scene_manager->scene_id_stack);
+ SceneManagerIdStack_it_t scene_it;
+ SceneManagerIdStack_it(scene_it, scene_manager->scene_id_stack);
+ SceneManagerIdStack_next(scene_it);
+ // Remove all scene id from navigation stack until first scene
+ SceneManagerIdStack_pop_until(scene_manager->scene_id_stack, scene_it);
+ // Add next scene
+ SceneManagerIdStack_push_back(scene_manager->scene_id_stack, scene_id);
- scene_manager->scene_handlers->on_exit_handlers[cur_scene_id](scene_manager->context);
- scene_manager->scene_handlers->on_enter_handlers[scene_id](scene_manager->context);
+ scene_manager->scene_handlers->on_exit_handlers[cur_scene_id](scene_manager->context);
+ scene_manager->scene_handlers->on_enter_handlers[scene_id](scene_manager->context);
- return true;
+ return true;
+ } else {
+ return false;
+ }
}
void scene_manager_stop(SceneManager* scene_manager) {
furi_assert(scene_manager);
- if(SceneManagerIdStack_size(scene_manager->scene_id_stack)) {
+ if(SceneManagerIdStack_size(scene_manager->scene_id_stack) > 0) {
uint32_t cur_scene_id = *SceneManagerIdStack_back(scene_manager->scene_id_stack);
scene_manager->scene_handlers->on_exit_handlers[cur_scene_id](scene_manager->context);
}
diff --git a/applications/gui/view.c b/applications/gui/view.c
index c0420bd8..e9642d9b 100644
--- a/applications/gui/view.c
+++ b/applications/gui/view.c
@@ -1,7 +1,7 @@
#include "view_i.h"
View* view_alloc() {
- View* view = furi_alloc(sizeof(View));
+ View* view = malloc(sizeof(View));
view->orientation = ViewOrientationHorizontal;
return view;
}
@@ -78,12 +78,12 @@ void view_allocate_model(View* view, ViewModelType type, size_t size) {
furi_assert(view->model == NULL);
view->model_type = type;
if(view->model_type == ViewModelTypeLockFree) {
- view->model = furi_alloc(size);
+ view->model = malloc(size);
} else if(view->model_type == ViewModelTypeLocking) {
- ViewModelLocking* model = furi_alloc(sizeof(ViewModelLocking));
+ ViewModelLocking* model = malloc(sizeof(ViewModelLocking));
model->mutex = osMutexNew(NULL);
furi_check(model->mutex);
- model->data = furi_alloc(size);
+ model->data = malloc(size);
view->model = model;
} else {
furi_assert(false);
diff --git a/applications/gui/view_dispatcher.c b/applications/gui/view_dispatcher.c
index a32dde97..8bfb9e4e 100644
--- a/applications/gui/view_dispatcher.c
+++ b/applications/gui/view_dispatcher.c
@@ -3,7 +3,7 @@
#define TAG "ViewDispatcher"
ViewDispatcher* view_dispatcher_alloc() {
- ViewDispatcher* view_dispatcher = furi_alloc(sizeof(ViewDispatcher));
+ ViewDispatcher* view_dispatcher = malloc(sizeof(ViewDispatcher));
view_dispatcher->view_port = view_port_alloc();
view_port_draw_callback_set(
diff --git a/applications/gui/view_port.c b/applications/gui/view_port.c
index 66560bbc..8069a02e 100644
--- a/applications/gui/view_port.c
+++ b/applications/gui/view_port.c
@@ -35,7 +35,7 @@ static void view_port_setup_canvas_orientation(const ViewPort* view_port, Canvas
}
ViewPort* view_port_alloc() {
- ViewPort* view_port = furi_alloc(sizeof(ViewPort));
+ ViewPort* view_port = malloc(sizeof(ViewPort));
view_port->orientation = ViewPortOrientationHorizontal;
view_port->is_enabled = true;
return view_port;
diff --git a/applications/gui/view_stack.c b/applications/gui/view_stack.c
index d790b801..715b5486 100644
--- a/applications/gui/view_stack.c
+++ b/applications/gui/view_stack.c
@@ -62,7 +62,7 @@ static void view_stack_exit(void* context) {
}
ViewStack* view_stack_alloc(void) {
- ViewStack* view_stack = furi_alloc(sizeof(ViewStack));
+ ViewStack* view_stack = malloc(sizeof(ViewStack));
view_stack->view = view_alloc();
view_allocate_model(view_stack->view, ViewModelTypeLocking, sizeof(ViewStackModel));
diff --git a/applications/ibutton/ibutton_app.cpp b/applications/ibutton/ibutton_app.cpp
index 820cb74a..d69f0097 100644
--- a/applications/ibutton/ibutton_app.cpp
+++ b/applications/ibutton/ibutton_app.cpp
@@ -3,7 +3,7 @@
#include <callback-connector.h>
#include <m-string.h>
#include <toolbox/path.h>
-#include <flipper_file/flipper_file.h>
+#include <flipper_format/flipper_format.h>
const char* iButtonApp::app_folder = "/any/ibutton";
const char* iButtonApp::app_extension = ".ibtn";
@@ -191,7 +191,7 @@ bool iButtonApp::save_key(const char* key_name) {
// Create ibutton directory if necessary
make_app_folder();
- FlipperFile* file = flipper_file_alloc(storage);
+ FlipperFormat* file = flipper_format_file_alloc(storage);
string_t key_file_name;
bool result = false;
string_init(key_file_name);
@@ -207,29 +207,29 @@ bool iButtonApp::save_key(const char* key_name) {
string_printf(key_file_name, "%s/%s%s", app_folder, key.get_name(), app_extension);
// Open file for write
- if(!flipper_file_open_always(file, string_get_cstr(key_file_name))) break;
+ if(!flipper_format_file_open_always(file, string_get_cstr(key_file_name))) break;
// Write header
- if(!flipper_file_write_header_cstr(file, iButtonApp::app_filetype, 1)) break;
+ if(!flipper_format_write_header_cstr(file, iButtonApp::app_filetype, 1)) break;
// Write key type
- if(!flipper_file_write_comment_cstr(file, "Key type can be Cyfral, Dallas or Metakom"))
+ if(!flipper_format_write_comment_cstr(file, "Key type can be Cyfral, Dallas or Metakom"))
break;
const char* key_type = key.get_key_type_string_by_type(key.get_key_type());
- if(!flipper_file_write_string_cstr(file, "Key type", key_type)) break;
+ if(!flipper_format_write_string_cstr(file, "Key type", key_type)) break;
// Write data
- if(!flipper_file_write_comment_cstr(
+ if(!flipper_format_write_comment_cstr(
file, "Data size for Cyfral is 2, for Metakom is 4, for Dallas is 8"))
break;
- if(!flipper_file_write_hex(file, "Data", key.get_data(), key.get_type_data_size())) break;
+ if(!flipper_format_write_hex(file, "Data", key.get_data(), key.get_type_data_size()))
+ break;
result = true;
} while(false);
- flipper_file_close(file);
- flipper_file_free(file);
+ flipper_format_free(file);
string_clear(key_file_name);
@@ -241,28 +241,28 @@ bool iButtonApp::save_key(const char* key_name) {
}
bool iButtonApp::load_key_data(string_t key_path) {
- FlipperFile* file = flipper_file_alloc(storage);
+ FlipperFormat* file = flipper_format_file_alloc(storage);
bool result = false;
string_t data;
string_init(data);
do {
- if(!flipper_file_open_existing(file, string_get_cstr(key_path))) break;
+ if(!flipper_format_file_open_existing(file, string_get_cstr(key_path))) break;
// header
uint32_t version;
- if(!flipper_file_read_header(file, data, &version)) break;
+ if(!flipper_format_read_header(file, data, &version)) break;
if(string_cmp_str(data, iButtonApp::app_filetype) != 0) break;
if(version != 1) break;
// key type
iButtonKeyType type;
- if(!flipper_file_read_string(file, "Key type", data)) break;
+ if(!flipper_format_read_string(file, "Key type", data)) break;
if(!key.get_key_type_by_type_string(string_get_cstr(data), &type)) break;
// key data
uint8_t key_data[IBUTTON_KEY_DATA_SIZE] = {0};
- if(!flipper_file_read_hex(file, "Data", key_data, key.get_type_data_size_by_type(type)))
+ if(!flipper_format_read_hex(file, "Data", key_data, key.get_type_data_size_by_type(type)))
break;
key.set_type(type);
@@ -271,8 +271,7 @@ bool iButtonApp::load_key_data(string_t key_path) {
result = true;
} while(false);
- flipper_file_close(file);
- flipper_file_free(file);
+ flipper_format_free(file);
string_clear(data);
if(!result) {
diff --git a/applications/input/input.c b/applications/input/input.c
index 55a10113..46a9c369 100644
--- a/applications/input/input.c
+++ b/applications/input/input.c
@@ -66,7 +66,7 @@ const char* input_get_type_name(InputType type) {
}
int32_t input_srv() {
- input = furi_alloc(sizeof(Input));
+ input = malloc(sizeof(Input));
input->thread = osThreadGetId();
input->event_pubsub = furi_pubsub_alloc();
furi_record_create("input_events", input->event_pubsub);
@@ -78,7 +78,7 @@ int32_t input_srv() {
}
#endif
- input->pin_states = furi_alloc(input_pins_count * sizeof(InputPinState));
+ input->pin_states = malloc(input_pins_count * sizeof(InputPinState));
for(size_t i = 0; i < input_pins_count; i++) {
GpioPin gpio = {(GPIO_TypeDef*)input_pins[i].port, (uint16_t)input_pins[i].pin};
diff --git a/applications/irda/cli/irda_cli.cpp b/applications/irda/cli/irda_cli.cpp
index 3a4121df..e8a61dc3 100644
--- a/applications/irda/cli/irda_cli.cpp
+++ b/applications/irda/cli/irda_cli.cpp
@@ -145,7 +145,7 @@ static void irda_cli_start_ir_tx(Cli* cli, string_t args) {
uint32_t frequency;
float duty_cycle;
uint32_t timings_cnt = MAX_TIMINGS_AMOUNT;
- uint32_t* timings = (uint32_t*)furi_alloc(sizeof(uint32_t) * timings_cnt);
+ uint32_t* timings = (uint32_t*)malloc(sizeof(uint32_t) * timings_cnt);
if(parse_message(str, &message)) {
irda_send(&message, 1);
diff --git a/applications/irda/helpers/irda_parser.cpp b/applications/irda/helpers/irda_parser.cpp
index be0b17aa..a23a9b6d 100644
--- a/applications/irda/helpers/irda_parser.cpp
+++ b/applications/irda/helpers/irda_parser.cpp
@@ -4,37 +4,42 @@
#include "irda/helpers/irda_parser.h"
#include "irda_worker.h"
#include "m-string.h"
-#include <flipper_file.h>
+#include <flipper_format/flipper_format.h>
#include <memory>
#include <string>
#include <furi_hal_irda.h>
#define TAG "IrdaParser"
-bool irda_parser_save_signal(FlipperFile* ff, const IrdaAppSignal& signal, const std::string& name) {
+bool irda_parser_save_signal(
+ FlipperFormat* ff,
+ const IrdaAppSignal& signal,
+ const std::string& name) {
furi_assert(ff);
furi_assert(!name.empty());
bool result = false;
do {
- if(!flipper_file_write_comment_cstr(ff, "")) break;
- if(!flipper_file_write_string_cstr(ff, "name", name.c_str())) break;
+ if(!flipper_format_write_comment_cstr(ff, "")) break;
+ if(!flipper_format_write_string_cstr(ff, "name", name.c_str())) break;
if(signal.is_raw()) {
furi_assert(signal.get_raw_signal().timings_cnt <= MAX_TIMINGS_AMOUNT);
auto raw_signal = signal.get_raw_signal();
- if(!flipper_file_write_string_cstr(ff, "type", "raw")) break;
- if(!flipper_file_write_uint32(ff, "frequency", &raw_signal.frequency, 1)) break;
- if(!flipper_file_write_float(ff, "duty_cycle", &raw_signal.duty_cycle, 1)) break;
- if(!flipper_file_write_uint32(ff, "data", raw_signal.timings, raw_signal.timings_cnt))
+ if(!flipper_format_write_string_cstr(ff, "type", "raw")) break;
+ if(!flipper_format_write_uint32(ff, "frequency", &raw_signal.frequency, 1)) break;
+ if(!flipper_format_write_float(ff, "duty_cycle", &raw_signal.duty_cycle, 1)) break;
+ if(!flipper_format_write_uint32(ff, "data", raw_signal.timings, raw_signal.timings_cnt))
break;
} else {
auto parsed_signal = signal.get_message();
const char* protocol_name = irda_get_protocol_name(parsed_signal.protocol);
- if(!flipper_file_write_string_cstr(ff, "type", "parsed")) break;
- if(!flipper_file_write_string_cstr(ff, "protocol", protocol_name)) break;
- if(!flipper_file_write_hex(ff, "address", (uint8_t*)&parsed_signal.address, 4)) break;
- if(!flipper_file_write_hex(ff, "command", (uint8_t*)&parsed_signal.command, 4)) break;
+ if(!flipper_format_write_string_cstr(ff, "type", "parsed")) break;
+ if(!flipper_format_write_string_cstr(ff, "protocol", protocol_name)) break;
+ if(!flipper_format_write_hex(ff, "address", (uint8_t*)&parsed_signal.address, 4))
+ break;
+ if(!flipper_format_write_hex(ff, "command", (uint8_t*)&parsed_signal.command, 4))
+ break;
}
result = true;
} while(0);
@@ -42,7 +47,7 @@ bool irda_parser_save_signal(FlipperFile* ff, const IrdaAppSignal& signal, const
return result;
}
-bool irda_parser_read_signal(FlipperFile* ff, IrdaAppSignal& signal, std::string& name) {
+bool irda_parser_read_signal(FlipperFormat* ff, IrdaAppSignal& signal, std::string& name) {
furi_assert(ff);
bool result = false;
@@ -50,31 +55,31 @@ bool irda_parser_read_signal(FlipperFile* ff, IrdaAppSignal& signal, std::string
string_init(read_string);
do {
- if(!flipper_file_read_string(ff, "name", read_string)) break;
+ if(!flipper_format_read_string(ff, "name", read_string)) break;
name = string_get_cstr(read_string);
- if(!flipper_file_read_string(ff, "type", read_string)) break;
+ if(!flipper_format_read_string(ff, "type", read_string)) break;
if(!string_cmp_str(read_string, "raw")) {
uint32_t* timings = nullptr;
uint32_t timings_cnt = 0;
uint32_t frequency = 0;
float duty_cycle = 0;
- if(!flipper_file_read_uint32(ff, "frequency", &frequency, 1)) break;
- if(!flipper_file_read_float(ff, "duty_cycle", &duty_cycle, 1)) break;
- if(!flipper_file_get_value_count(ff, "data", &timings_cnt)) break;
+ if(!flipper_format_read_uint32(ff, "frequency", &frequency, 1)) break;
+ if(!flipper_format_read_float(ff, "duty_cycle", &duty_cycle, 1)) break;
+ if(!flipper_format_get_value_count(ff, "data", &timings_cnt)) break;
if(timings_cnt > MAX_TIMINGS_AMOUNT) break;
- timings = (uint32_t*)furi_alloc(sizeof(uint32_t) * timings_cnt);
- if(flipper_file_read_uint32(ff, "data", timings, timings_cnt)) {
+ timings = (uint32_t*)malloc(sizeof(uint32_t) * timings_cnt);
+ if(flipper_format_read_uint32(ff, "data", timings, timings_cnt)) {
signal.set_raw_signal(timings, timings_cnt, frequency, duty_cycle);
result = true;
}
free(timings);
} else if(!string_cmp_str(read_string, "parsed")) {
IrdaMessage parsed_signal;
- if(!flipper_file_read_string(ff, "protocol", read_string)) break;
+ if(!flipper_format_read_string(ff, "protocol", read_string)) break;
parsed_signal.protocol = irda_get_protocol_by_name(string_get_cstr(read_string));
- if(!flipper_file_read_hex(ff, "address", (uint8_t*)&parsed_signal.address, 4)) break;
- if(!flipper_file_read_hex(ff, "command", (uint8_t*)&parsed_signal.command, 4)) break;
+ if(!flipper_format_read_hex(ff, "address", (uint8_t*)&parsed_signal.address, 4)) break;
+ if(!flipper_format_read_hex(ff, "command", (uint8_t*)&parsed_signal.command, 4)) break;
if(!irda_parser_is_parsed_signal_valid(&parsed_signal)) break;
signal.set_message(&parsed_signal);
result = true;
diff --git a/applications/irda/helpers/irda_parser.h b/applications/irda/helpers/irda_parser.h
index bc68825c..d8065607 100644
--- a/applications/irda/helpers/irda_parser.h
+++ b/applications/irda/helpers/irda_parser.h
@@ -1,10 +1,13 @@
#pragma once
#include "../irda_app_signal.h"
-#include <flipper_file.h>
+#include <flipper_format/flipper_format.h>
#include <string>
-bool irda_parser_save_signal(FlipperFile* ff, const IrdaAppSignal& signal, const std::string& name);
-bool irda_parser_read_signal(FlipperFile* ff, IrdaAppSignal& signal, std::string& name);
+bool irda_parser_save_signal(
+ FlipperFormat* ff,
+ const IrdaAppSignal& signal,
+ const std::string& name);
+bool irda_parser_read_signal(FlipperFormat* ff, IrdaAppSignal& signal, std::string& name);
bool irda_parser_is_parsed_signal_valid(const IrdaMessage* signal);
bool irda_parser_is_raw_signal_valid(uint32_t frequency, float duty_cycle, uint32_t timings_cnt);
diff --git a/applications/irda/irda_app_brute_force.cpp b/applications/irda/irda_app_brute_force.cpp
index 43f91150..8d7d684d 100644
--- a/applications/irda/irda_app_brute_force.cpp
+++ b/applications/irda/irda_app_brute_force.cpp
@@ -16,15 +16,15 @@ bool IrdaAppBruteForce::calculate_messages() {
bool result = false;
Storage* storage = static_cast<Storage*>(furi_record_open("storage"));
- FlipperFile* ff = flipper_file_alloc(storage);
- result = flipper_file_open_existing(ff, universal_db_filename);
+ FlipperFormat* ff = flipper_format_file_alloc(storage);
+ result = flipper_format_file_open_existing(ff, universal_db_filename);
if(result) {
IrdaAppSignal signal;
string_t signal_name;
string_init(signal_name);
- while(flipper_file_read_string(ff, "name", signal_name)) {
+ while(flipper_format_read_string(ff, "name", signal_name)) {
auto element = records.find(string_get_cstr(signal_name));
if(element != records.cend()) {
++element->second.amount;
@@ -33,8 +33,7 @@ bool IrdaAppBruteForce::calculate_messages() {
string_clear(signal_name);
}
- flipper_file_close(ff);
- flipper_file_free(ff);
+ flipper_format_free(ff);
furi_record_close("storage");
return result;
}
@@ -45,8 +44,7 @@ void IrdaAppBruteForce::stop_bruteforce() {
if(current_record.size()) {
furi_assert(ff);
current_record.clear();
- flipper_file_close(ff);
- flipper_file_free(ff);
+ flipper_format_free(ff);
furi_record_close("storage");
}
}
@@ -84,11 +82,10 @@ bool IrdaAppBruteForce::start_bruteforce(int index, int& record_amount) {
if(record_amount) {
Storage* storage = static_cast<Storage*>(furi_record_open("storage"));
- ff = flipper_file_alloc(storage);
- result = flipper_file_open_existing(ff, universal_db_filename);
+ ff = flipper_format_file_alloc(storage);
+ result = flipper_format_file_open_existing(ff, universal_db_filename);
if(!result) {
- flipper_file_close(ff);
- flipper_file_free(ff);
+ flipper_format_free(ff);
furi_record_close("storage");
}
}
diff --git a/applications/irda/irda_app_brute_force.h b/applications/irda/irda_app_brute_force.h
index 439eba4f..97d78dc6 100644
--- a/applications/irda/irda_app_brute_force.h
+++ b/applications/irda/irda_app_brute_force.h
@@ -2,12 +2,12 @@
#include <unordered_map>
#include <memory>
-#include <flipper_file.h>
+#include <flipper_format/flipper_format.h>
class IrdaAppBruteForce {
const char* universal_db_filename;
std::string current_record;
- FlipperFile* ff;
+ FlipperFormat* ff;
typedef struct {
int index;
diff --git a/applications/irda/irda_app_remote_manager.cpp b/applications/irda/irda_app_remote_manager.cpp
index 8b88d37d..d2081b42 100644
--- a/applications/irda/irda_app_remote_manager.cpp
+++ b/applications/irda/irda_app_remote_manager.cpp
@@ -1,5 +1,5 @@
#include <file_worker_cpp.h>
-#include <flipper_file.h>
+#include <flipper_format/flipper_format.h>
#include "irda_app_remote_manager.h"
#include "irda/helpers/irda_parser.h"
#include "irda/irda_app_signal.h"
@@ -169,12 +169,12 @@ bool IrdaAppRemoteManager::store(void) {
if(!file_worker.mkdir(IrdaApp::irda_directory)) return false;
Storage* storage = static_cast<Storage*>(furi_record_open("storage"));
- FlipperFile* ff = flipper_file_alloc(storage);
+ FlipperFormat* ff = flipper_format_file_alloc(storage);
FURI_LOG_I("RemoteManager", "store file: \'%s\'", make_full_name(remote->name).c_str());
- result = flipper_file_open_always(ff, make_full_name(remote->name).c_str());
+ result = flipper_format_file_open_always(ff, make_full_name(remote->name).c_str());
if(result) {
- result = flipper_file_write_header_cstr(ff, "IR signals file", 1);
+ result = flipper_format_write_header_cstr(ff, "IR signals file", 1);
}
if(result) {
for(const auto& button : remote->buttons) {
@@ -185,8 +185,7 @@ bool IrdaAppRemoteManager::store(void) {
}
}
- flipper_file_close(ff);
- flipper_file_free(ff);
+ flipper_format_free(ff);
furi_record_close("storage");
return result;
}
@@ -194,15 +193,15 @@ bool IrdaAppRemoteManager::store(void) {
bool IrdaAppRemoteManager::load(const std::string& remote_name) {
bool result = false;
Storage* storage = static_cast<Storage*>(furi_record_open("storage"));
- FlipperFile* ff = flipper_file_alloc(storage);
+ FlipperFormat* ff = flipper_format_file_alloc(storage);
FURI_LOG_I("RemoteManager", "load file: \'%s\'", make_full_name(remote_name).c_str());
- result = flipper_file_open_existing(ff, make_full_name(remote_name).c_str());
+ result = flipper_format_file_open_existing(ff, make_full_name(remote_name).c_str());
if(result) {
string_t header;
string_init(header);
uint32_t version;
- result = flipper_file_read_header(ff, header, &version);
+ result = flipper_format_read_header(ff, header, &version);
if(result) {
result = !string_cmp_str(header, "IR signals file") && (version == 1);
}
@@ -217,8 +216,7 @@ bool IrdaAppRemoteManager::load(const std::string& remote_name) {
}
}
- flipper_file_close(ff);
- flipper_file_free(ff);
+ flipper_format_free(ff);
furi_record_close("storage");
return result;
}
diff --git a/applications/irda/view/irda_app_brut_view.c b/applications/irda/view/irda_app_brut_view.c
index 4b2db642..91429a35 100644
--- a/applications/irda/view/irda_app_brut_view.c
+++ b/applications/irda/view/irda_app_brut_view.c
@@ -76,7 +76,7 @@ void popup_brut_set_progress_max(IrdaAppPopupBrut* popup_brut, uint16_t progress
}
IrdaAppPopupBrut* popup_brut_alloc(void) {
- return (IrdaAppPopupBrut*)furi_alloc(sizeof(IrdaAppPopupBrut));
+ return (IrdaAppPopupBrut*)malloc(sizeof(IrdaAppPopupBrut));
}
void popup_brut_free(IrdaAppPopupBrut* popup_brut) {
diff --git a/applications/irda_monitor/irda_monitor.c b/applications/irda_monitor/irda_monitor.c
index d2032e38..5325d192 100644
--- a/applications/irda_monitor/irda_monitor.c
+++ b/applications/irda_monitor/irda_monitor.c
@@ -99,7 +99,7 @@ static void signal_received_callback(void* context, IrdaWorkerSignal* received_s
int32_t irda_monitor_app(void* p) {
(void)p;
- IrdaMonitor* irda_monitor = furi_alloc(sizeof(IrdaMonitor));
+ IrdaMonitor* irda_monitor = malloc(sizeof(IrdaMonitor));
irda_monitor->display_text[0] = 0;
irda_monitor->event_queue = osMessageQueueNew(1, sizeof(InputEvent), NULL);
irda_monitor->view_port = view_port_alloc();
diff --git a/applications/lfrfid/lfrfid_app.cpp b/applications/lfrfid/lfrfid_app.cpp
index 870952d5..fecf15a7 100644
--- a/applications/lfrfid/lfrfid_app.cpp
+++ b/applications/lfrfid/lfrfid_app.cpp
@@ -17,7 +17,7 @@
#include "scene/lfrfid_app_scene_delete_success.h"
#include <toolbox/path.h>
-#include <flipper_file/flipper_file.h>
+#include <flipper_format/flipper_format.h>
const char* LfRfidApp::app_folder = "/any/lfrfid";
const char* LfRfidApp::app_extension = ".rfid";
@@ -119,17 +119,17 @@ bool LfRfidApp::delete_key(RfidKey* key) {
}
bool LfRfidApp::load_key_data(const char* path, RfidKey* key) {
- FlipperFile* file = flipper_file_alloc(storage);
+ FlipperFormat* file = flipper_format_file_alloc(storage);
bool result = false;
string_t str_result;
string_init(str_result);
do {
- if(!flipper_file_open_existing(file, path)) break;
+ if(!flipper_format_file_open_existing(file, path)) break;
// header
uint32_t version;
- if(!flipper_file_read_header(file, str_result, &version)) break;
+ if(!flipper_format_read_header(file, str_result, &version)) break;
if(string_cmp_str(str_result, app_filetype) != 0) break;
if(version != 1) break;
@@ -137,13 +137,14 @@ bool LfRfidApp::load_key_data(const char* path, RfidKey* key) {
LfrfidKeyType type;
RfidKey loaded_key;
- if(!flipper_file_read_string(file, "Key type", str_result)) break;
+ if(!flipper_format_read_string(file, "Key type", str_result)) break;
if(!lfrfid_key_get_string_type(string_get_cstr(str_result), &type)) break;
loaded_key.set_type(type);
// key data
uint8_t key_data[loaded_key.get_type_data_count()] = {};
- if(!flipper_file_read_hex(file, "Data", key_data, loaded_key.get_type_data_count())) break;
+ if(!flipper_format_read_hex(file, "Data", key_data, loaded_key.get_type_data_count()))
+ break;
loaded_key.set_data(key_data, loaded_key.get_type_data_count());
path_extract_filename_no_ext(path, str_result);
@@ -153,8 +154,7 @@ bool LfRfidApp::load_key_data(const char* path, RfidKey* key) {
result = true;
} while(0);
- flipper_file_close(file);
- flipper_file_free(file);
+ flipper_format_free(file);
string_clear(str_result);
if(!result) {
@@ -165,27 +165,26 @@ bool LfRfidApp::load_key_data(const char* path, RfidKey* key) {
}
bool LfRfidApp::save_key_data(const char* path, RfidKey* key) {
- FlipperFile* file = flipper_file_alloc(storage);
+ FlipperFormat* file = flipper_format_file_alloc(storage);
bool result = false;
do {
- if(!flipper_file_open_always(file, path)) break;
- if(!flipper_file_write_header_cstr(file, app_filetype, 1)) break;
- if(!flipper_file_write_comment_cstr(file, "Key type can be EM4100, H10301 or I40134"))
+ if(!flipper_format_file_open_always(file, path)) break;
+ if(!flipper_format_write_header_cstr(file, app_filetype, 1)) break;
+ if(!flipper_format_write_comment_cstr(file, "Key type can be EM4100, H10301 or I40134"))
break;
- if(!flipper_file_write_string_cstr(
+ if(!flipper_format_write_string_cstr(
file, "Key type", lfrfid_key_get_type_string(key->get_type())))
break;
- if(!flipper_file_write_comment_cstr(
+ if(!flipper_format_write_comment_cstr(
file, "Data size for EM4100 is 5, for H10301 is 3, for I40134 is 3"))
break;
- if(!flipper_file_write_hex(file, "Data", key->get_data(), key->get_type_data_count()))
+ if(!flipper_format_write_hex(file, "Data", key->get_data(), key->get_type_data_count()))
break;
result = true;
} while(0);
- flipper_file_close(file);
- flipper_file_free(file);
+ flipper_format_free(file);
if(!result) {
dialog_message_show_storage_error(dialogs, "Cannot save\nkey file");
diff --git a/applications/loader/loader.c b/applications/loader/loader.c
index b8f67a59..552b46f2 100644
--- a/applications/loader/loader.c
+++ b/applications/loader/loader.c
@@ -278,7 +278,7 @@ static uint32_t loader_back_to_primary_menu(void* context) {
}
static Loader* loader_alloc() {
- Loader* instance = furi_alloc(sizeof(Loader));
+ Loader* instance = malloc(sizeof(Loader));
instance->application_thread = furi_thread_alloc();
furi_thread_enable_heap_trace(instance->application_thread);
diff --git a/applications/nfc/helpers/nfc_emv_parser.c b/applications/nfc/helpers/nfc_emv_parser.c
index 4012ff45..2e060999 100755
--- a/applications/nfc/helpers/nfc_emv_parser.c
+++ b/applications/nfc/helpers/nfc_emv_parser.c
@@ -1,5 +1,5 @@
#include "nfc_emv_parser.h"
-#include <lib/flipper_file/flipper_file.h>
+#include <flipper_format/flipper_format.h>
static const char* nfc_resources_header = "Flipper EMV resources";
static const uint32_t nfc_resources_file_version = 1;
@@ -10,25 +10,25 @@ static bool nfc_emv_parser_search_data(
string_t key,
string_t data) {
bool parsed = false;
- FlipperFile* file = flipper_file_alloc(storage);
+ FlipperFormat* file = flipper_format_file_alloc(storage);
string_t temp_str;
string_init(temp_str);
do {
// Open file
- if(!flipper_file_open_existing(file, file_name)) break;
+ if(!flipper_format_file_open_existing(file, file_name)) break;
// Read file header and version
uint32_t version = 0;
- if(!flipper_file_read_header(file, temp_str, &version)) break;
+ if(!flipper_format_read_header(file, temp_str, &version)) break;
if(string_cmp_str(temp_str, nfc_resources_header) ||
(version != nfc_resources_file_version))
break;
- if(!flipper_file_read_string(file, string_get_cstr(key), data)) break;
+ if(!flipper_format_read_string(file, string_get_cstr(key), data)) break;
parsed = true;
} while(false);
string_clear(temp_str);
- flipper_file_free(file);
+ flipper_format_free(file);
return parsed;
}
diff --git a/applications/nfc/nfc.c b/applications/nfc/nfc.c
index acf4c7cf..5b3453d8 100755
--- a/applications/nfc/nfc.c
+++ b/applications/nfc/nfc.c
@@ -20,7 +20,7 @@ void nfc_tick_event_callback(void* context) {
}
Nfc* nfc_alloc() {
- Nfc* nfc = furi_alloc(sizeof(Nfc));
+ Nfc* nfc = malloc(sizeof(Nfc));
nfc->worker = nfc_worker_alloc();
nfc->view_dispatcher = view_dispatcher_alloc();
diff --git a/applications/nfc/nfc_device.c b/applications/nfc/nfc_device.c
index d6996b3f..1f4c35cc 100755
--- a/applications/nfc/nfc_device.c
+++ b/applications/nfc/nfc_device.c
@@ -1,14 +1,14 @@
#include "nfc_device.h"
#include "nfc_types.h"
-#include <lib/toolbox/path.h>
-#include <lib/flipper_file/flipper_file.h>
+#include <toolbox/path.h>
+#include <flipper_format/flipper_format.h>
static const char* nfc_file_header = "Flipper NFC device";
static const uint32_t nfc_file_version = 2;
NfcDevice* nfc_device_alloc() {
- NfcDevice* nfc_dev = furi_alloc(sizeof(NfcDevice));
+ NfcDevice* nfc_dev = malloc(sizeof(NfcDevice));
nfc_dev->storage = furi_record_open("storage");
nfc_dev->dialogs = furi_record_open("dialogs");
return nfc_dev;
@@ -56,7 +56,7 @@ bool nfc_device_parse_format_string(NfcDevice* dev, string_t format_string) {
return false;
}
-static bool nfc_device_save_mifare_ul_data(FlipperFile* file, NfcDevice* dev) {
+static bool nfc_device_save_mifare_ul_data(FlipperFormat* file, NfcDevice* dev) {
bool saved = false;
MifareUlData* data = &dev->dev_data.mf_ul_data;
string_t temp_str;
@@ -64,22 +64,23 @@ static bool nfc_device_save_mifare_ul_data(FlipperFile* file, NfcDevice* dev) {
// Save Mifare Ultralight specific data
do {
- if(!flipper_file_write_comment_cstr(file, "Mifare Ultralight specific data")) break;
- if(!flipper_file_write_hex(file, "Signature", data->signature, sizeof(data->signature)))
+ if(!flipper_format_write_comment_cstr(file, "Mifare Ultralight specific data")) break;
+ if(!flipper_format_write_hex(file, "Signature", data->signature, sizeof(data->signature)))
break;
- if(!flipper_file_write_hex(
+ if(!flipper_format_write_hex(
file, "Mifare version", (uint8_t*)&data->version, sizeof(data->version)))
break;
// Write conters and tearing flags data
bool counters_saved = true;
for(uint8_t i = 0; i < 3; i++) {
string_printf(temp_str, "Counter %d", i);
- if(!flipper_file_write_uint32(file, string_get_cstr(temp_str), &data->counter[i], 1)) {
+ if(!flipper_format_write_uint32(
+ file, string_get_cstr(temp_str), &data->counter[i], 1)) {
counters_saved = false;
break;
}
string_printf(temp_str, "Tearing %d", i);
- if(!flipper_file_write_hex(file, string_get_cstr(temp_str), &data->tearing[i], 1)) {
+ if(!flipper_format_write_hex(file, string_get_cstr(temp_str), &data->tearing[i], 1)) {
counters_saved = false;
break;
}
@@ -87,11 +88,11 @@ static bool nfc_device_save_mifare_ul_data(FlipperFile* file, NfcDevice* dev) {
if(!counters_saved) break;
// Write pages data
uint32_t pages_total = data->data_size / 4;
- if(!flipper_file_write_uint32(file, "Pages total", &pages_total, 1)) break;
+ if(!flipper_format_write_uint32(file, "Pages total", &pages_total, 1)) break;
bool pages_saved = true;
for(uint16_t i = 0; i < data->data_size; i += 4) {
string_printf(temp_str, "Page %d", i / 4);
- if(!flipper_file_write_hex(file, string_get_cstr(temp_str), &data->data[i], 4)) {
+ if(!flipper_format_write_hex(file, string_get_cstr(temp_str), &data->data[i], 4)) {
pages_saved = false;
break;
}
@@ -104,7 +105,7 @@ static bool nfc_device_save_mifare_ul_data(FlipperFile* file, NfcDevice* dev) {
return saved;
}
-bool nfc_device_load_mifare_ul_data(FlipperFile* file, NfcDevice* dev) {
+bool nfc_device_load_mifare_ul_data(FlipperFormat* file, NfcDevice* dev) {
bool parsed = false;
MifareUlData* data = &dev->dev_data.mf_ul_data;
string_t temp_str;
@@ -112,22 +113,22 @@ bool nfc_device_load_mifare_ul_data(FlipperFile* file, NfcDevice* dev) {
do {
// Read signature
- if(!flipper_file_read_hex(file, "Signature", data->signature, sizeof(data->signature)))
+ if(!flipper_format_read_hex(file, "Signature", data->signature, sizeof(data->signature)))
break;
// Read Mifare version
- if(!flipper_file_read_hex(
+ if(!flipper_format_read_hex(
file, "Mifare version", (uint8_t*)&data->version, sizeof(data->version)))
break;
// Read counters and tearing flags
bool counters_parsed = true;
for(uint8_t i = 0; i < 3; i++) {
string_printf(temp_str, "Counter %d", i);
- if(!flipper_file_read_uint32(file, string_get_cstr(temp_str), &data->counter[i], 1)) {
+ if(!flipper_format_read_uint32(file, string_get_cstr(temp_str), &data->counter[i], 1)) {
counters_parsed = false;
break;
}
string_printf(temp_str, "Tearing %d", i);
- if(!flipper_file_read_hex(file, string_get_cstr(temp_str), &data->tearing[i], 1)) {
+ if(!flipper_format_read_hex(file, string_get_cstr(temp_str), &data->tearing[i], 1)) {
counters_parsed = false;
break;
}
@@ -135,12 +136,12 @@ bool nfc_device_load_mifare_ul_data(FlipperFile* file, NfcDevice* dev) {
if(!counters_parsed) break;
// Read pages
uint32_t pages = 0;
- if(!flipper_file_read_uint32(file, "Pages total", &pages, 1)) break;
+ if(!flipper_format_read_uint32(file, "Pages total", &pages, 1)) break;
data->data_size = pages * 4;
bool pages_parsed = true;
for(uint16_t i = 0; i < pages; i++) {
string_printf(temp_str, "Page %d", i);
- if(!flipper_file_read_hex(file, string_get_cstr(temp_str), &data->data[i * 4], 4)) {
+ if(!flipper_format_read_hex(file, string_get_cstr(temp_str), &data->data[i * 4], 4)) {
pages_parsed = false;
break;
}
@@ -153,28 +154,28 @@ bool nfc_device_load_mifare_ul_data(FlipperFile* file, NfcDevice* dev) {
return parsed;
}
-static bool nfc_device_save_bank_card_data(FlipperFile* file, NfcDevice* dev) {
+static bool nfc_device_save_bank_card_data(FlipperFormat* file, NfcDevice* dev) {
bool saved = false;
NfcEmvData* data = &dev->dev_data.emv_data;
uint32_t data_temp = 0;
do {
// Write Bank card specific data
- if(!flipper_file_write_comment_cstr(file, "Bank card specific data")) break;
- if(!flipper_file_write_hex(file, "AID", data->aid, data->aid_len)) break;
- if(!flipper_file_write_string_cstr(file, "Name", data->name)) break;
- if(!flipper_file_write_hex(file, "Number", data->number, data->number_len)) break;
+ if(!flipper_format_write_comment_cstr(file, "Bank card specific data")) break;
+ if(!flipper_format_write_hex(file, "AID", data->aid, data->aid_len)) break;
+ if(!flipper_format_write_string_cstr(file, "Name", data->name)) break;
+ if(!flipper_format_write_hex(file, "Number", data->number, data->number_len)) break;
if(data->exp_mon) {
uint8_t exp_data[2] = {data->exp_mon, data->exp_year};
- if(!flipper_file_write_hex(file, "Exp data", exp_data, sizeof(exp_data))) break;
+ if(!flipper_format_write_hex(file, "Exp data", exp_data, sizeof(exp_data))) break;
}
if(data->country_code) {
data_temp = data->country_code;
- if(!flipper_file_write_uint32(file, "Country code", &data_temp, 1)) break;
+ if(!flipper_format_write_uint32(file, "Country code", &data_temp, 1)) break;
}
if(data->currency_code) {
data_temp = data->currency_code;
- if(!flipper_file_write_uint32(file, "Currency code", &data_temp, 1)) break;
+ if(!flipper_format_write_uint32(file, "Currency code", &data_temp, 1)) break;
}
saved = true;
} while(false);
@@ -182,7 +183,7 @@ static bool nfc_device_save_bank_card_data(FlipperFile* file, NfcDevice* dev) {
return saved;
}
-bool nfc_device_load_bank_card_data(FlipperFile* file, NfcDevice* dev) {
+bool nfc_device_load_bank_card_data(FlipperFormat* file, NfcDevice* dev) {
bool parsed = false;
NfcEmvData* data = &dev->dev_data.emv_data;
memset(data, 0, sizeof(NfcEmvData));
@@ -192,25 +193,25 @@ bool nfc_device_load_bank_card_data(FlipperFile* file, NfcDevice* dev) {
do {
// Load essential data
- if(!flipper_file_get_value_count(file, "AID", &data_cnt)) break;
+ if(!flipper_format_get_value_count(file, "AID", &data_cnt)) break;
data->aid_len = data_cnt;
- if(!flipper_file_read_hex(file, "AID", data->aid, data->aid_len)) break;
- if(!flipper_file_read_string(file, "Name", temp_str)) break;
+ if(!flipper_format_read_hex(file, "AID", data->aid, data->aid_len)) break;
+ if(!flipper_format_read_string(file, "Name", temp_str)) break;
strlcpy(data->name, string_get_cstr(temp_str), sizeof(data->name));
- if(!flipper_file_get_value_count(file, "Number", &data_cnt)) break;
+ if(!flipper_format_get_value_count(file, "Number", &data_cnt)) break;
data->number_len = data_cnt;
- if(!flipper_file_read_hex(file, "Number", data->number, data->number_len)) break;
+ if(!flipper_format_read_hex(file, "Number", data->number, data->number_len)) break;
parsed = true;
// Load optional data
uint8_t exp_data[2] = {};
- if(flipper_file_read_hex(file, "Exp data", exp_data, 2)) {
+ if(flipper_format_read_hex(file, "Exp data", exp_data, 2)) {
data->exp_mon = exp_data[0];
data->exp_year = exp_data[1];
}
- if(flipper_file_read_uint32(file, "Country code", &data_cnt, 1)) {
+ if(flipper_format_read_uint32(file, "Country code", &data_cnt, 1)) {
data->country_code = data_cnt;
}
- if(flipper_file_read_uint32(file, "Currency code", &data_cnt, 1)) {
+ if(flipper_format_read_uint32(file, "Currency code", &data_cnt, 1)) {
data->currency_code = data_cnt;
}
} while(false);
@@ -233,7 +234,7 @@ static bool nfc_device_save_file(
furi_assert(dev);
bool saved = false;
- FlipperFile* file = flipper_file_alloc(dev->storage);
+ FlipperFormat* file = flipper_format_file_alloc(dev->storage);
NfcDeviceCommonData* data = &dev->dev_data.nfc_data;
string_t temp_str;
string_init(temp_str);
@@ -244,21 +245,21 @@ static bool nfc_device_save_file(
// First remove nfc device file if it was saved
string_printf(temp_str, "%s/%s%s", folder, dev_name, extension);
// Open file
- if(!flipper_file_open_always(file, string_get_cstr(temp_str))) break;
+ if(!flipper_format_file_open_always(file, string_get_cstr(temp_str))) break;
// Write header
- if(!flipper_file_write_header_cstr(file, nfc_file_header, nfc_file_version)) break;
+ if(!flipper_format_write_header_cstr(file, nfc_file_header, nfc_file_version)) break;
// Write nfc device type
- if(!flipper_file_write_comment_cstr(
+ if(!flipper_format_write_comment_cstr(
file, "Nfc device type can be UID, Mifare Ultralight, Bank card"))
break;
nfc_device_prepare_format_string(dev, temp_str);
- if(!flipper_file_write_string(file, "Device type", temp_str)) break;
+ if(!flipper_format_write_string(file, "Device type", temp_str)) break;
// Write UID, ATQA, SAK
- if(!flipper_file_write_comment_cstr(file, "UID, ATQA and SAK are common for all formats"))
+ if(!flipper_format_write_comment_cstr(file, "UID, ATQA and SAK are common for all formats"))
break;
- if(!flipper_file_write_hex(file, "UID", data->uid, data->uid_len)) break;
- if(!flipper_file_write_hex(file, "ATQA", data->atqa, 2)) break;
- if(!flipper_file_write_hex(file, "SAK", &data->sak, 1)) break;
+ if(!flipper_format_write_hex(file, "UID", data->uid, data->uid_len)) break;
+ if(!flipper_format_write_hex(file, "ATQA", data->atqa, 2)) break;
+ if(!flipper_format_write_hex(file, "SAK", &data->sak, 1)) break;
// Save more data if necessary
if(dev->format == NfcDeviceSaveFormatMifareUl) {
if(!nfc_device_save_mifare_ul_data(file, dev)) break;
@@ -272,8 +273,7 @@ static bool nfc_device_save_file(
dialog_message_show_storage_error(dev->dialogs, "Can not save\nkey file");
}
string_clear(temp_str);
- flipper_file_close(file);
- flipper_file_free(file);
+ flipper_format_free(file);
return saved;
}
@@ -288,7 +288,7 @@ bool nfc_device_save_shadow(NfcDevice* dev, const char* dev_name) {
static bool nfc_device_load_data(NfcDevice* dev, string_t path) {
bool parsed = false;
- FlipperFile* file = flipper_file_alloc(dev->storage);
+ FlipperFormat* file = flipper_format_file_alloc(dev->storage);
NfcDeviceCommonData* data = &dev->dev_data.nfc_data;
uint32_t data_cnt = 0;
string_t temp_str;
@@ -304,26 +304,26 @@ static bool nfc_device_load_data(NfcDevice* dev, string_t path) {
storage_common_stat(dev->storage, string_get_cstr(temp_str), NULL) == FSE_OK;
// Open shadow file if it exists. If not - open original
if(dev->shadow_file_exist) {
- if(!flipper_file_open_existing(file, string_get_cstr(temp_str))) break;
+ if(!flipper_format_file_open_existing(file, string_get_cstr(temp_str))) break;
} else {
- if(!flipper_file_open_existing(file, string_get_cstr(path))) break;
+ if(!flipper_format_file_open_existing(file, string_get_cstr(path))) break;
}
// Read and verify file header
uint32_t version = 0;
- if(!flipper_file_read_header(file, temp_str, &version)) break;
+ if(!flipper_format_read_header(file, temp_str, &version)) break;
if(string_cmp_str(temp_str, nfc_file_header) || (version != nfc_file_version)) {
depricated_version = true;
break;
}
// Read Nfc device type
- if(!flipper_file_read_string(file, "Device type", temp_str)) break;
+ if(!flipper_format_read_string(file, "Device type", temp_str)) break;
if(!nfc_device_parse_format_string(dev, temp_str)) break;
// Read and parse UID, ATQA and SAK
- if(!flipper_file_get_value_count(file, "UID", &data_cnt)) break;
+ if(!flipper_format_get_value_count(file, "UID", &data_cnt)) break;
data->uid_len = data_cnt;
- if(!flipper_file_read_hex(file, "UID", data->uid, data->uid_len)) break;
- if(!flipper_file_read_hex(file, "ATQA", data->atqa, 2)) break;
- if(!flipper_file_read_hex(file, "SAK", &data->sak, 1)) break;
+ if(!flipper_format_read_hex(file, "UID", data->uid, data->uid_len)) break;
+ if(!flipper_format_read_hex(file, "ATQA", data->atqa, 2)) break;
+ if(!flipper_format_read_hex(file, "SAK", &data->sak, 1)) break;
// Parse other data
if(dev->format == NfcDeviceSaveFormatMifareUl) {
if(!nfc_device_load_mifare_ul_data(file, dev)) break;
@@ -342,8 +342,7 @@ static bool nfc_device_load_data(NfcDevice* dev, string_t path) {
}
string_clear(temp_str);
- flipper_file_close(file);
- flipper_file_free(file);
+ flipper_format_free(file);
return parsed;
}
diff --git a/applications/nfc/nfc_worker.c b/applications/nfc/nfc_worker.c
index 4f969188..2056fd9f 100755
--- a/applications/nfc/nfc_worker.c
+++ b/applications/nfc/nfc_worker.c
@@ -8,18 +8,17 @@
/***************************** NFC Worker API *******************************/
NfcWorker* nfc_worker_alloc() {
- NfcWorker* nfc_worker = furi_alloc(sizeof(NfcWorker));
+ NfcWorker* nfc_worker = malloc(sizeof(NfcWorker));
// Worker thread attributes
nfc_worker->thread_attr.name = "NfcWorker";
nfc_worker->thread_attr.stack_size = 8192;
nfc_worker->callback = NULL;
nfc_worker->context = NULL;
// Initialize rfal
- if(!furi_hal_nfc_is_busy()) {
- nfc_worker_change_state(nfc_worker, NfcWorkerStateReady);
- } else {
- nfc_worker_change_state(nfc_worker, NfcWorkerStateBroken);
+ while(furi_hal_nfc_is_busy()) {
+ osDelay(10);
}
+ nfc_worker_change_state(nfc_worker, NfcWorkerStateReady);
return nfc_worker;
}
@@ -41,7 +40,7 @@ void nfc_worker_start(
void* context) {
furi_assert(nfc_worker);
furi_assert(dev_data);
- while(nfc_worker->state != NfcWorkerStateReady) {
+ while(furi_hal_nfc_is_busy()) {
osDelay(10);
}
diff --git a/applications/nfc/views/bank_card.c b/applications/nfc/views/bank_card.c
index ee54c4b0..31cc56ee 100755
--- a/applications/nfc/views/bank_card.c
+++ b/applications/nfc/views/bank_card.c
@@ -7,7 +7,7 @@ struct BankCard {
};
BankCard* bank_card_alloc() {
- BankCard* bank_card = furi_alloc(sizeof(BankCard));
+ BankCard* bank_card = malloc(sizeof(BankCard));
bank_card->widget = widget_alloc();
return bank_card;
}
diff --git a/applications/notification/notification_app.c b/applications/notification/notification_app.c
index 99d9bce8..9dfa4d1a 100644
--- a/applications/notification/notification_app.c
+++ b/applications/notification/notification_app.c
@@ -403,7 +403,7 @@ static void input_event_callback(const void* value, void* context) {
// App alloc
static NotificationApp* notification_app_alloc() {
- NotificationApp* app = furi_alloc(sizeof(NotificationApp));
+ NotificationApp* app = malloc(sizeof(NotificationApp));
app->queue = osMessageQueueNew(8, sizeof(NotificationAppMessage), NULL);
app->display_timer = osTimerNew(notification_display_timer, osTimerOnce, app, NULL);
@@ -482,4 +482,4 @@ int32_t notification_srv(void* p) {
}
return 0;
-}; \ No newline at end of file
+};
diff --git a/applications/notification/notification_settings_app.c b/applications/notification/notification_settings_app.c
index 6b60a98d..4f05a103 100644
--- a/applications/notification/notification_settings_app.c
+++ b/applications/notification/notification_settings_app.c
@@ -221,4 +221,4 @@ int32_t notification_settings_app(void* p) {
notification_message_save_settings(app->notification);
free_settings(app);
return 0;
-} \ No newline at end of file
+}
diff --git a/applications/power/battery_test_app/battery_test_app.c b/applications/power/battery_test_app/battery_test_app.c
index 33b2c65b..4d73fee5 100755
--- a/applications/power/battery_test_app/battery_test_app.c
+++ b/applications/power/battery_test_app/battery_test_app.c
@@ -32,7 +32,7 @@ static void battery_test_battery_info_update_model(void* context) {
}
BatteryTestApp* battery_test_alloc() {
- BatteryTestApp* app = furi_alloc(sizeof(BatteryTestApp));
+ BatteryTestApp* app = malloc(sizeof(BatteryTestApp));
// Records
app->gui = furi_record_open("gui");
@@ -97,4 +97,4 @@ int32_t battery_test_app(void* p) {
power_enable_low_battery_level_notification(app->power, true);
battery_test_free(app);
return 0;
-} \ No newline at end of file
+}
diff --git a/applications/power/power_service/power.c b/applications/power/power_service/power.c
index 3934b20d..8c2ecd17 100755
--- a/applications/power/power_service/power.c
+++ b/applications/power/power_service/power.c
@@ -32,7 +32,7 @@ static ViewPort* power_battery_view_port_alloc(Power* power) {
}
Power* power_alloc() {
- Power* power = furi_alloc(sizeof(Power));
+ Power* power = malloc(sizeof(Power));
// Records
power->notification = furi_record_open("notification");
diff --git a/applications/power/power_service/views/power_off.c b/applications/power/power_service/views/power_off.c
index 73abc16b..46344b9b 100755
--- a/applications/power/power_service/views/power_off.c
+++ b/applications/power/power_service/views/power_off.c
@@ -29,7 +29,7 @@ static void power_off_draw_callback(Canvas* canvas, void* _model) {
}
PowerOff* power_off_alloc() {
- PowerOff* power_off = furi_alloc(sizeof(PowerOff));
+ PowerOff* power_off = malloc(sizeof(PowerOff));
power_off->view = view_alloc();
view_allocate_model(power_off->view, ViewModelTypeLocking, sizeof(PowerOffModel));
view_set_draw_callback(power_off->view, power_off_draw_callback);
diff --git a/applications/power/power_settings_app/power_settings_app.c b/applications/power/power_settings_app/power_settings_app.c
index 8e77716e..1e87e7d6 100755
--- a/applications/power/power_settings_app/power_settings_app.c
+++ b/applications/power/power_settings_app/power_settings_app.c
@@ -19,7 +19,7 @@ static void power_settings_tick_event_callback(void* context) {
}
PowerSettingsApp* power_settings_app_alloc() {
- PowerSettingsApp* app = furi_alloc(sizeof(PowerSettingsApp));
+ PowerSettingsApp* app = malloc(sizeof(PowerSettingsApp));
// Records
app->gui = furi_record_open("gui");
diff --git a/applications/power/power_settings_app/views/battery_info.c b/applications/power/power_settings_app/views/battery_info.c
index 599aefee..aa3a1e96 100644
--- a/applications/power/power_settings_app/views/battery_info.c
+++ b/applications/power/power_settings_app/views/battery_info.c
@@ -95,7 +95,7 @@ static void battery_info_draw_callback(Canvas* canvas, void* context) {
}
BatteryInfo* battery_info_alloc() {
- BatteryInfo* battery_info = furi_alloc(sizeof(BatteryInfo));
+ BatteryInfo* battery_info = malloc(sizeof(BatteryInfo));
battery_info->view = view_alloc();
view_set_context(battery_info->view, battery_info);
view_allocate_model(battery_info->view, ViewModelTypeLocking, sizeof(BatteryInfoModel));
diff --git a/applications/rpc/rpc.c b/applications/rpc/rpc.c
index f76f455e..f4dfc31f 100644
--- a/applications/rpc/rpc.c
+++ b/applications/rpc/rpc.c
@@ -349,13 +349,13 @@ void rpc_print_message(const PB_Main* message) {
}
static Rpc* rpc_alloc(void) {
- Rpc* rpc = furi_alloc(sizeof(Rpc));
+ Rpc* rpc = malloc(sizeof(Rpc));
rpc->busy_mutex = osMutexNew(NULL);
rpc->busy = false;
rpc->events = osEventFlagsNew(NULL);
rpc->stream = xStreamBufferCreate(RPC_BUFFER_SIZE, 1);
- rpc->decoded_message = furi_alloc(sizeof(PB_Main));
+ rpc->decoded_message = malloc(sizeof(PB_Main));
rpc->decoded_message->cb_content.funcs.decode = content_callback;
rpc->decoded_message->cb_content.arg = rpc;
@@ -384,7 +384,7 @@ RpcSession* rpc_session_open(Rpc* rpc) {
session->decode_error = false;
xStreamBufferReset(rpc->stream);
- session->system_contexts = furi_alloc(COUNT_OF(rpc_systems) * sizeof(void*));
+ session->system_contexts = malloc(COUNT_OF(rpc_systems) * sizeof(void*));
for(int i = 0; i < COUNT_OF(rpc_systems); ++i) {
session->system_contexts[i] = rpc_systems[i].alloc(rpc);
}
@@ -554,7 +554,7 @@ void rpc_send_and_release(Rpc* rpc, PB_Main* message) {
bool result = pb_encode_ex(&ostream, &PB_Main_msg, message, PB_ENCODE_DELIMITED);
furi_check(result && ostream.bytes_written);
- uint8_t* buffer = furi_alloc(ostream.bytes_written);
+ uint8_t* buffer = malloc(ostream.bytes_written);
ostream = pb_ostream_from_buffer(buffer, ostream.bytes_written);
pb_encode_ex(&ostream, &PB_Main_msg, message, PB_ENCODE_DELIMITED);
diff --git a/applications/rpc/rpc_cli.c b/applications/rpc/rpc_cli.c
index 59f9458f..55cc3e49 100644
--- a/applications/rpc/rpc_cli.c
+++ b/applications/rpc/rpc_cli.c
@@ -40,7 +40,7 @@ void rpc_cli_command_start_session(Cli* cli, string_t args, void* context) {
rpc_session_set_send_bytes_callback(rpc_session, rpc_send_bytes_callback);
rpc_session_set_close_callback(rpc_session, rpc_session_close_callback);
- uint8_t* buffer = furi_alloc(CLI_READ_BUFFER_SIZE);
+ uint8_t* buffer = malloc(CLI_READ_BUFFER_SIZE);
size_t size_received = 0;
while(1) {
diff --git a/applications/rpc/rpc_gui.c b/applications/rpc/rpc_gui.c
index 8e3d2c46..7ee637a0 100644
--- a/applications/rpc/rpc_gui.c
+++ b/applications/rpc/rpc_gui.c
@@ -21,11 +21,11 @@ static void
RpcGuiSystem* rpc_gui = context;
- PB_Main* frame = furi_alloc(sizeof(PB_Main));
+ PB_Main* frame = malloc(sizeof(PB_Main));
frame->which_content = PB_Main_gui_screen_frame_tag;
frame->command_status = PB_CommandStatus_OK;
- frame->content.gui_screen_frame.data = furi_alloc(PB_BYTES_ARRAY_T_ALLOCSIZE(size));
+ frame->content.gui_screen_frame.data = malloc(PB_BYTES_ARRAY_T_ALLOCSIZE(size));
uint8_t* buffer = frame->content.gui_screen_frame.data->bytes;
uint16_t* frame_size_msg = &frame->content.gui_screen_frame.data->size;
*frame_size_msg = size;
@@ -160,7 +160,7 @@ static void rpc_system_gui_start_virtual_display_process(const PB_Main* request,
// Using display framebuffer size as an XBM buffer size is like comparing apples and oranges
// Glad they both are 1024 for now
size_t buffer_size = canvas_get_buffer_size(rpc_gui->gui->canvas);
- rpc_gui->virtual_display_buffer = furi_alloc(buffer_size);
+ rpc_gui->virtual_display_buffer = malloc(buffer_size);
if(request->content.gui_start_virtual_display_request.has_first_frame) {
size_t buffer_size = canvas_get_buffer_size(rpc_gui->gui->canvas);
@@ -223,7 +223,7 @@ static void rpc_system_gui_virtual_display_frame_process(const PB_Main* request,
void* rpc_system_gui_alloc(Rpc* rpc) {
furi_assert(rpc);
- RpcGuiSystem* rpc_gui = furi_alloc(sizeof(RpcGuiSystem));
+ RpcGuiSystem* rpc_gui = malloc(sizeof(RpcGuiSystem));
rpc_gui->gui = furi_record_open("gui");
rpc_gui->rpc = rpc;
diff --git a/applications/rpc/rpc_storage.c b/applications/rpc/rpc_storage.c
index bf50c7b1..ed43e48d 100644
--- a/applications/rpc/rpc_storage.c
+++ b/applications/rpc/rpc_storage.c
@@ -104,7 +104,7 @@ static void rpc_system_storage_info_process(const PB_Main* request, void* contex
RpcStorageSystem* rpc_storage = context;
rpc_system_storage_reset_state(rpc_storage, true);
- PB_Main* response = furi_alloc(sizeof(PB_Main));
+ PB_Main* response = malloc(sizeof(PB_Main));
response->command_id = request->command_id;
Storage* fs_api = furi_record_open("storage");
@@ -135,7 +135,7 @@ static void rpc_system_storage_stat_process(const PB_Main* request, void* contex
RpcStorageSystem* rpc_storage = context;
rpc_system_storage_reset_state(rpc_storage, true);
- PB_Main* response = furi_alloc(sizeof(PB_Main));
+ PB_Main* response = malloc(sizeof(PB_Main));
response->command_id = request->command_id;
Storage* fs_api = furi_record_open("storage");
@@ -178,7 +178,7 @@ static void rpc_system_storage_list_root(const PB_Main* request, void* context)
response.content.storage_list_response.file[i].data = NULL;
response.content.storage_list_response.file[i].size = 0;
response.content.storage_list_response.file[i].type = PB_Storage_File_FileType_DIR;
- char* str = furi_alloc(strlen(hard_coded_dirs[i]) + 1);
+ char* str = malloc(strlen(hard_coded_dirs[i]) + 1);
strcpy(str, hard_coded_dirs[i]);
response.content.storage_list_response.file[i].name = str;
}
@@ -221,7 +221,7 @@ static void rpc_system_storage_list_process(const PB_Main* request, void* contex
while(!finish) {
FileInfo fileinfo;
- char* name = furi_alloc(MAX_NAME_LENGTH + 1);
+ char* name = malloc(MAX_NAME_LENGTH + 1);
if(storage_dir_read(dir, &fileinfo, name, MAX_NAME_LENGTH)) {
if(i == COUNT_OF(list->file)) {
list->file_count = i;
@@ -259,7 +259,7 @@ static void rpc_system_storage_read_process(const PB_Main* request, void* contex
rpc_system_storage_reset_state(rpc_storage, true);
/* use same message memory to send reponse */
- PB_Main* response = furi_alloc(sizeof(PB_Main));
+ PB_Main* response = malloc(sizeof(PB_Main));
const char* path = request->content.storage_read_request.path;
Storage* fs_api = furi_record_open("storage");
File* file = storage_file_alloc(fs_api);
@@ -273,7 +273,7 @@ static void rpc_system_storage_read_process(const PB_Main* request, void* contex
response->command_status = PB_CommandStatus_OK;
response->content.storage_read_response.has_file = true;
response->content.storage_read_response.file.data =
- furi_alloc(PB_BYTES_ARRAY_T_ALLOCSIZE(MIN(size_left, MAX_DATA_SIZE)));
+ malloc(PB_BYTES_ARRAY_T_ALLOCSIZE(MIN(size_left, MAX_DATA_SIZE)));
uint8_t* buffer = response->content.storage_read_response.file.data->bytes;
uint16_t* read_size_msg = &response->content.storage_read_response.file.data->size;
@@ -357,7 +357,7 @@ static bool rpc_system_storage_is_dir_is_empty(Storage* fs_api, const char* path
if((error == FSE_OK) && (fileinfo.flags & FSF_DIRECTORY)) {
File* dir = storage_file_alloc(fs_api);
if(storage_dir_open(dir, path)) {
- char* name = furi_alloc(MAX_NAME_LENGTH);
+ char* name = malloc(MAX_NAME_LENGTH);
is_dir_is_empty = !storage_dir_read(dir, &fileinfo, name, MAX_NAME_LENGTH);
free(name);
}
@@ -508,7 +508,7 @@ static void rpc_system_storage_rename_process(const PB_Main* request, void* cont
void* rpc_system_storage_alloc(Rpc* rpc) {
furi_assert(rpc);
- RpcStorageSystem* rpc_storage = furi_alloc(sizeof(RpcStorageSystem));
+ RpcStorageSystem* rpc_storage = malloc(sizeof(RpcStorageSystem));
rpc_storage->api = furi_record_open("storage");
rpc_storage->rpc = rpc;
rpc_storage->state = RpcStorageStateIdle;
diff --git a/applications/rpc/rpc_system.c b/applications/rpc/rpc_system.c
index ed5b889a..e718ad8a 100644
--- a/applications/rpc/rpc_system.c
+++ b/applications/rpc/rpc_system.c
@@ -27,7 +27,7 @@ static void rpc_system_system_ping_process(const PB_Main* msg_request, void* con
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));
+ response->data = malloc(PB_BYTES_ARRAY_T_ALLOCSIZE(request->data->size));
memcpy(response->data->bytes, request->data->bytes, request->data->size);
response->data->size = request->data->size;
}
@@ -84,7 +84,7 @@ static void rpc_system_system_device_info_process(const PB_Main* request, void*
furi_assert(context);
Rpc* rpc = context;
- PB_Main* response = furi_alloc(sizeof(PB_Main));
+ PB_Main* response = malloc(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;
@@ -108,7 +108,7 @@ static void rpc_system_system_get_datetime_process(const PB_Main* request, void*
FuriHalRtcDateTime datetime;
furi_hal_rtc_get_datetime(&datetime);
- PB_Main* response = furi_alloc(sizeof(PB_Main));
+ PB_Main* response = malloc(sizeof(PB_Main));
response->command_id = request->command_id;
response->which_content = PB_Main_system_get_datetime_response_tag;
response->command_status = PB_CommandStatus_OK;
@@ -180,7 +180,7 @@ static void rpc_system_system_protobuf_version_process(const PB_Main* request, v
Rpc* rpc = context;
- PB_Main* response = furi_alloc(sizeof(PB_Main));
+ PB_Main* response = malloc(sizeof(PB_Main));
response->command_id = request->command_id;
response->has_next = false;
response->command_status = PB_CommandStatus_OK;
diff --git a/applications/snake_game/snake_game.c b/applications/snake_game/snake_game.c
index e3fde566..2bc0a6a3 100644
--- a/applications/snake_game/snake_game.c
+++ b/applications/snake_game/snake_game.c
@@ -317,7 +317,7 @@ int32_t snake_game_app(void* p) {
osMessageQueueId_t event_queue = osMessageQueueNew(8, sizeof(SnakeEvent), NULL);
- SnakeState* snake_state = furi_alloc(sizeof(SnakeState));
+ SnakeState* snake_state = malloc(sizeof(SnakeState));
snake_game_init_game(snake_state);
ValueMutex state_mutex;
diff --git a/applications/storage/filesystem_api_defines.h b/applications/storage/filesystem_api_defines.h
index dc6d0679..e90e642f 100644
--- a/applications/storage/filesystem_api_defines.h
+++ b/applications/storage/filesystem_api_defines.h
@@ -9,6 +9,7 @@ extern "C" {
typedef enum {
FSAM_READ = (1 << 0), /**< Read access */
FSAM_WRITE = (1 << 1), /**< Write access */
+ FSAM_READ_WRITE = FSAM_READ | FSAM_WRITE, /**< Read and write access */
} FS_AccessMode;
/** Open mode flags */
diff --git a/applications/storage/storage_cli.c b/applications/storage/storage_cli.c
index 0c7dc4d8..07fa638f 100644
--- a/applications/storage/storage_cli.c
+++ b/applications/storage/storage_cli.c
@@ -143,7 +143,7 @@ static void storage_cli_read(Cli* cli, string_t path) {
if(storage_file_open(file, string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) {
const uint16_t read_size = 128;
uint16_t readed_size = 0;
- uint8_t* data = furi_alloc(read_size);
+ uint8_t* data = malloc(read_size);
printf("Size: %lu\r\n", (uint32_t)storage_file_size(file));
@@ -171,7 +171,7 @@ static void storage_cli_write(Cli* cli, string_t path) {
File* file = storage_file_alloc(api);
const uint16_t buffer_size = 512;
- uint8_t* buffer = furi_alloc(buffer_size);
+ uint8_t* buffer = malloc(buffer_size);
if(storage_file_open(file, string_get_cstr(path), FSAM_WRITE, FSOM_OPEN_APPEND)) {
printf("Just write your text data. New line by Ctrl+Enter, exit by Ctrl+C.\r\n");
@@ -230,7 +230,7 @@ static void storage_cli_read_chunks(Cli* cli, string_t path, string_t args) {
if(parsed_count == EOF || parsed_count != 1) {
storage_cli_print_usage();
} else if(storage_file_open(file, string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) {
- uint8_t* data = furi_alloc(buffer_size);
+ uint8_t* data = malloc(buffer_size);
uint64_t file_size = storage_file_size(file);
printf("Size: %lu\r\n", (uint32_t)file_size);
@@ -271,7 +271,7 @@ static void storage_cli_write_chunk(Cli* cli, string_t path, string_t args) {
if(storage_file_open(file, string_get_cstr(path), FSAM_WRITE, FSOM_OPEN_APPEND)) {
printf("Ready\r\n");
- uint8_t* buffer = furi_alloc(buffer_size);
+ uint8_t* buffer = malloc(buffer_size);
for(uint32_t i = 0; i < buffer_size; i++) {
buffer[i] = cli_getc(cli);
diff --git a/applications/storage/storage_external_api.c b/applications/storage/storage_external_api.c
index f55cbb3b..9acc9ea4 100644
--- a/applications/storage/storage_external_api.c
+++ b/applications/storage/storage_external_api.c
@@ -372,7 +372,7 @@ FS_Error storage_sd_status(Storage* storage) {
}
File* storage_file_alloc(Storage* storage) {
- File* file = furi_alloc(sizeof(File));
+ File* file = malloc(sizeof(File));
file->file_id = FILE_CLOSED;
file->storage = storage;
@@ -407,7 +407,7 @@ bool storage_simply_remove_recursive(Storage* storage, const char* path) {
return true;
}
- char* name = furi_alloc(MAX_NAME_LENGTH + 1);
+ char* name = malloc(MAX_NAME_LENGTH + 1);
File* dir = storage_file_alloc(storage);
string_init_set_str(cur_dir, path);
bool go_deeper = false;
diff --git a/applications/storage/storage_test_app.c b/applications/storage/storage_test_app.c
index 4c4f08a2..79569116 100644
--- a/applications/storage/storage_test_app.c
+++ b/applications/storage/storage_test_app.c
@@ -338,4 +338,4 @@ int32_t storage_test_app(void* p) {
}
return 0;
-} \ No newline at end of file
+}
diff --git a/applications/storage/storages/storage_ext.c b/applications/storage/storages/storage_ext.c
index 8eacba4e..309ec1cf 100644
--- a/applications/storage/storages/storage_ext.c
+++ b/applications/storage/storages/storage_ext.c
@@ -512,7 +512,7 @@ static FS_Error storage_ext_common_fs_info(
/******************* Init Storage *******************/
void storage_ext_init(StorageData* storage) {
- SDData* sd_data = furi_alloc(sizeof(SDData));
+ SDData* sd_data = malloc(sizeof(SDData));
sd_data->fs = &USERFatFS;
sd_data->path = "0:/";
sd_data->sd_was_present = true;
diff --git a/applications/storage/storages/storage_int.c b/applications/storage/storages/storage_int.c
index 5c3223ed..811a1d6a 100644
--- a/applications/storage/storages/storage_int.c
+++ b/applications/storage/storages/storage_int.c
@@ -18,14 +18,14 @@ typedef struct {
} LFSHandle;
static LFSHandle* lfs_handle_alloc_file() {
- LFSHandle* handle = furi_alloc(sizeof(LFSHandle));
- handle->data = furi_alloc(sizeof(lfs_file_t));
+ LFSHandle* handle = malloc(sizeof(LFSHandle));
+ handle->data = malloc(sizeof(lfs_file_t));
return handle;
}
static LFSHandle* lfs_handle_alloc_dir() {
- LFSHandle* handle = furi_alloc(sizeof(LFSHandle));
- handle->data = furi_alloc(sizeof(lfs_dir_t));
+ LFSHandle* handle = malloc(sizeof(LFSHandle));
+ handle->data = malloc(sizeof(lfs_dir_t));
return handle;
}
@@ -134,7 +134,7 @@ static int storage_int_device_sync(const struct lfs_config* c) {
}
static LFSData* storage_int_lfs_data_alloc() {
- LFSData* lfs_data = furi_alloc(sizeof(LFSData));
+ LFSData* lfs_data = malloc(sizeof(LFSData));
// Internal storage start address
*(size_t*)(&lfs_data->start_address) = furi_hal_flash_get_free_page_start_address();
diff --git a/applications/storage_settings/storage_settings.c b/applications/storage_settings/storage_settings.c
index ac61cd3b..bc982b16 100644
--- a/applications/storage_settings/storage_settings.c
+++ b/applications/storage_settings/storage_settings.c
@@ -72,4 +72,4 @@ int32_t storage_settings_app(void* p) {
storage_settings_free(app);
return 0;
-} \ No newline at end of file
+}
diff --git a/applications/subghz/helpers/subghz_chat.c b/applications/subghz/helpers/subghz_chat.c
index 4bc79b89..38529a10 100644
--- a/applications/subghz/helpers/subghz_chat.c
+++ b/applications/subghz/helpers/subghz_chat.c
@@ -52,7 +52,7 @@ static void subghz_chat_worker_update_rx_event_chat(void* context) {
}
SubGhzChatWorker* subghz_chat_worker_alloc() {
- SubGhzChatWorker* instance = furi_alloc(sizeof(SubGhzChatWorker));
+ SubGhzChatWorker* instance = malloc(sizeof(SubGhzChatWorker));
instance->thread = furi_thread_alloc();
furi_thread_set_name(instance->thread, "SubghzChat");
@@ -138,4 +138,4 @@ size_t subghz_chat_worker_read(SubGhzChatWorker* instance, uint8_t* data, size_t
bool subghz_chat_worker_write(SubGhzChatWorker* instance, uint8_t* data, size_t size) {
furi_assert(instance);
return subghz_tx_rx_worker_write(instance->subghz_txrx, data, size);
-} \ No newline at end of file
+}
diff --git a/applications/subghz/helpers/subghz_frequency_analyzer_worker.c b/applications/subghz/helpers/subghz_frequency_analyzer_worker.c
index ddf557a6..b79cfe04 100644
--- a/applications/subghz/helpers/subghz_frequency_analyzer_worker.c
+++ b/applications/subghz/helpers/subghz_frequency_analyzer_worker.c
@@ -142,7 +142,7 @@ static int32_t subghz_frequency_analyzer_worker_thread(void* context) {
}
SubGhzFrequencyAnalyzerWorker* subghz_frequency_analyzer_worker_alloc() {
- SubGhzFrequencyAnalyzerWorker* instance = furi_alloc(sizeof(SubGhzFrequencyAnalyzerWorker));
+ SubGhzFrequencyAnalyzerWorker* instance = malloc(sizeof(SubGhzFrequencyAnalyzerWorker));
instance->thread = furi_thread_alloc();
furi_thread_set_name(instance->thread, "SubghzFAWorker");
diff --git a/applications/subghz/subghz.c b/applications/subghz/subghz.c
index 4f442562..705be7d4 100644
--- a/applications/subghz/subghz.c
+++ b/applications/subghz/subghz.c
@@ -74,7 +74,7 @@ void subghz_tick_event_callback(void* context) {
}
SubGhz* subghz_alloc() {
- SubGhz* subghz = furi_alloc(sizeof(SubGhz));
+ SubGhz* subghz = malloc(sizeof(SubGhz));
// GUI
subghz->gui = furi_record_open("gui");
@@ -177,7 +177,7 @@ SubGhz* subghz_alloc() {
subghz_test_static_get_view(subghz->subghz_test_static));
//init Worker & Protocol & History
- subghz->txrx = furi_alloc(sizeof(SubGhzTxRx));
+ subghz->txrx = malloc(sizeof(SubGhzTxRx));
subghz->txrx->frequency = subghz_frequencies[subghz_frequencies_433_92];
subghz->txrx->preset = FuriHalSubGhzPresetOok650Async;
subghz->txrx->txrx_state = SubGhzTxRxStateSleep;
diff --git a/applications/subghz/subghz_cli.c b/applications/subghz/subghz_cli.c
index c54533d9..37946298 100644
--- a/applications/subghz/subghz_cli.c
+++ b/applications/subghz/subghz_cli.c
@@ -210,7 +210,7 @@ void subghz_cli_command_rx(Cli* cli, string_t args, void* context) {
}
// Allocate context and buffers
- SubGhzCliCommandRx* instance = furi_alloc(sizeof(SubGhzCliCommandRx));
+ SubGhzCliCommandRx* instance = malloc(sizeof(SubGhzCliCommandRx));
instance->stream = xStreamBufferCreate(sizeof(LevelDuration) * 1024, sizeof(LevelDuration));
furi_check(instance->stream);
diff --git a/applications/subghz/subghz_history.c b/applications/subghz/subghz_history.c
index ad6c3d4c..bb821e40 100644
--- a/applications/subghz/subghz_history.c
+++ b/applications/subghz/subghz_history.c
@@ -31,7 +31,7 @@ struct SubGhzHistory {
};
SubGhzHistory* subghz_history_alloc(void) {
- SubGhzHistory* instance = furi_alloc(sizeof(SubGhzHistory));
+ SubGhzHistory* instance = malloc(sizeof(SubGhzHistory));
return instance;
}
diff --git a/applications/subghz/subghz_i.c b/applications/subghz/subghz_i.c
index 87537ca2..5eb99f85 100755
--- a/applications/subghz/subghz_i.c
+++ b/applications/subghz/subghz_i.c
@@ -6,7 +6,7 @@
#include <input/input.h>
#include <gui/elements.h>
#include <notification/notification_messages.h>
-#include <lib/flipper_file/flipper_file.h>
+#include <flipper_format/flipper_format.h>
#include "../notification/notification.h"
#include "views/subghz_receiver.h"
@@ -198,7 +198,7 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path) {
furi_assert(file_path);
Storage* storage = furi_record_open("storage");
- FlipperFile* flipper_file = flipper_file_alloc(storage);
+ FlipperFormat* flipper_format = flipper_format_file_alloc(storage);
// Load device data
bool loaded = false;
@@ -209,12 +209,12 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path) {
uint32_t version;
do {
- if(!flipper_file_open_existing(flipper_file, string_get_cstr(path))) {
+ if(!flipper_format_file_open_existing(flipper_format, string_get_cstr(path))) {
FURI_LOG_E(
SUBGHZ_PARSER_TAG, "Unable to open file for read: %s", string_get_cstr(path));
break;
}
- if(!flipper_file_read_header(flipper_file, temp_str, &version)) {
+ if(!flipper_format_read_header(flipper_format, temp_str, &version)) {
FURI_LOG_E(SUBGHZ_PARSER_TAG, "Missing or incorrect header");
break;
}
@@ -227,13 +227,13 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path) {
break;
}
- if(!flipper_file_read_uint32(
- flipper_file, "Frequency", (uint32_t*)&subghz->txrx->frequency, 1)) {
+ if(!flipper_format_read_uint32(
+ flipper_format, "Frequency", (uint32_t*)&subghz->txrx->frequency, 1)) {
FURI_LOG_E(SUBGHZ_PARSER_TAG, "Missing Frequency");
break;
}
- if(!flipper_file_read_string(flipper_file, "Preset", temp_str)) {
+ if(!flipper_format_read_string(flipper_format, "Preset", temp_str)) {
FURI_LOG_E(SUBGHZ_PARSER_TAG, "Missing Preset");
break;
}
@@ -241,7 +241,7 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path) {
break;
}
- if(!flipper_file_read_string(flipper_file, "Protocol", temp_str)) {
+ if(!flipper_format_read_string(flipper_format, "Protocol", temp_str)) {
FURI_LOG_E(SUBGHZ_PARSER_TAG, "Missing Protocol");
break;
}
@@ -253,7 +253,7 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path) {
break;
}
if(!subghz->txrx->protocol_result->to_load_protocol_from_file(
- flipper_file, subghz->txrx->protocol_result, string_get_cstr(path))) {
+ flipper_format, subghz->txrx->protocol_result, string_get_cstr(path))) {
break;
}
loaded = true;
@@ -265,8 +265,7 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path) {
string_clear(temp_str);
string_clear(path);
- flipper_file_close(flipper_file);
- flipper_file_free(flipper_file);
+ flipper_format_free(flipper_format);
furi_record_close("storage");
@@ -301,7 +300,7 @@ bool subghz_save_protocol_to_file(SubGhz* subghz, const char* dev_name) {
furi_assert(subghz->txrx->protocol_result);
Storage* storage = furi_record_open("storage");
- FlipperFile* flipper_file = flipper_file_alloc(storage);
+ FlipperFormat* flipper_format = flipper_format_file_alloc(storage);
string_t dev_file_name;
string_init(dev_file_name);
string_t temp_str;
@@ -328,18 +327,18 @@ bool subghz_save_protocol_to_file(SubGhz* subghz, const char* dev_name) {
}
// Open file
- if(!flipper_file_open_always(flipper_file, string_get_cstr(dev_file_name))) {
+ if(!flipper_format_file_open_always(flipper_format, string_get_cstr(dev_file_name))) {
FURI_LOG_E(SUBGHZ_PARSER_TAG, "Unable to open file for write: %s", dev_file_name);
break;
}
- if(!flipper_file_write_header_cstr(
- flipper_file, SUBGHZ_KEY_FILE_TYPE, SUBGHZ_KEY_FILE_VERSION)) {
+ if(!flipper_format_write_header_cstr(
+ flipper_format, SUBGHZ_KEY_FILE_TYPE, SUBGHZ_KEY_FILE_VERSION)) {
FURI_LOG_E(SUBGHZ_PARSER_TAG, "Unable to add header");
break;
}
- if(!flipper_file_write_uint32(flipper_file, "Frequency", &subghz->txrx->frequency, 1)) {
+ if(!flipper_format_write_uint32(flipper_format, "Frequency", &subghz->txrx->frequency, 1)) {
FURI_LOG_E(SUBGHZ_PARSER_TAG, "Unable to add Frequency");
break;
}
@@ -347,13 +346,13 @@ bool subghz_save_protocol_to_file(SubGhz* subghz, const char* dev_name) {
if(!subghz_get_preset_name(subghz, temp_str)) {
break;
}
- if(!flipper_file_write_string_cstr(flipper_file, "Preset", string_get_cstr(temp_str))) {
+ if(!flipper_format_write_string_cstr(flipper_format, "Preset", string_get_cstr(temp_str))) {
FURI_LOG_E(SUBGHZ_PARSER_TAG, "Unable to add Preset");
break;
}
if(!subghz->txrx->protocol_result->to_save_file(
- subghz->txrx->protocol_result, flipper_file)) {
+ subghz->txrx->protocol_result, flipper_format)) {
break;
}
@@ -363,8 +362,7 @@ bool subghz_save_protocol_to_file(SubGhz* subghz, const char* dev_name) {
string_clear(temp_str);
string_clear(dev_file_name);
- flipper_file_close(flipper_file);
- flipper_file_free(flipper_file);
+ flipper_format_free(flipper_format);
furi_record_close("storage");
diff --git a/applications/subghz/views/subghz_frequency_analyzer.c b/applications/subghz/views/subghz_frequency_analyzer.c
index 1cc3d4f9..afb7b012 100644
--- a/applications/subghz/views/subghz_frequency_analyzer.c
+++ b/applications/subghz/views/subghz_frequency_analyzer.c
@@ -136,7 +136,7 @@ void subghz_frequency_analyzer_exit(void* context) {
}
SubghzFrequencyAnalyzer* subghz_frequency_analyzer_alloc() {
- SubghzFrequencyAnalyzer* instance = furi_alloc(sizeof(SubghzFrequencyAnalyzer));
+ SubghzFrequencyAnalyzer* instance = malloc(sizeof(SubghzFrequencyAnalyzer));
// View allocation and configuration
instance->view = view_alloc();
@@ -167,4 +167,4 @@ void subghz_frequency_analyzer_free(SubghzFrequencyAnalyzer* instance) {
View* subghz_frequency_analyzer_get_view(SubghzFrequencyAnalyzer* instance) {
furi_assert(instance);
return instance->view;
-} \ No newline at end of file
+}
diff --git a/applications/subghz/views/subghz_read_raw.c b/applications/subghz/views/subghz_read_raw.c
index 27d1c31f..f786b7a0 100644
--- a/applications/subghz/views/subghz_read_raw.c
+++ b/applications/subghz/views/subghz_read_raw.c
@@ -484,7 +484,7 @@ void subghz_read_raw_exit(void* context) {
}
SubghzReadRAW* subghz_read_raw_alloc() {
- SubghzReadRAW* instance = furi_alloc(sizeof(SubghzReadRAW));
+ SubghzReadRAW* instance = malloc(sizeof(SubghzReadRAW));
// View allocation and configuration
instance->view = view_alloc();
@@ -501,7 +501,7 @@ SubghzReadRAW* subghz_read_raw_alloc() {
string_init(model->preset_str);
string_init(model->sample_write);
string_init(model->file_name);
- model->rssi_history = furi_alloc(SUBGHZ_READ_RAW_RSSI_HISTORY_SIZE * sizeof(uint8_t));
+ model->rssi_history = malloc(SUBGHZ_READ_RAW_RSSI_HISTORY_SIZE * sizeof(uint8_t));
return true;
});
@@ -527,4 +527,4 @@ void subghz_read_raw_free(SubghzReadRAW* instance) {
View* subghz_read_raw_get_view(SubghzReadRAW* instance) {
furi_assert(instance);
return instance->view;
-} \ No newline at end of file
+}
diff --git a/applications/subghz/views/subghz_receiver.c b/applications/subghz/views/subghz_receiver.c
index b158d870..92bfbb53 100644
--- a/applications/subghz/views/subghz_receiver.c
+++ b/applications/subghz/views/subghz_receiver.c
@@ -243,7 +243,7 @@ void subghz_receiver_exit(void* context) {
}
SubghzReceiver* subghz_receiver_alloc() {
- SubghzReceiver* subghz_receiver = furi_alloc(sizeof(SubghzReceiver));
+ SubghzReceiver* subghz_receiver = malloc(sizeof(SubghzReceiver));
// View allocation and configuration
subghz_receiver->view = view_alloc();
@@ -259,7 +259,7 @@ SubghzReceiver* subghz_receiver_alloc() {
string_init(model->frequency_str);
string_init(model->preset_str);
string_init(model->history_stat_str);
- model->history = furi_alloc(sizeof(SubGhzReceiverHistory));
+ model->history = malloc(sizeof(SubGhzReceiverHistory));
SubGhzReceiverMenuItemArray_init(model->history->data);
return true;
});
@@ -313,4 +313,4 @@ void subghz_receiver_set_idx_menu(SubghzReceiver* subghz_receiver, uint16_t idx)
return true;
});
subghz_receiver_update_offset(subghz_receiver);
-} \ No newline at end of file
+}
diff --git a/applications/subghz/views/subghz_test_carrier.c b/applications/subghz/views/subghz_test_carrier.c
index 4d7b1189..82d95bff 100644
--- a/applications/subghz/views/subghz_test_carrier.c
+++ b/applications/subghz/views/subghz_test_carrier.c
@@ -181,7 +181,7 @@ void subghz_test_carrier_rssi_timer_callback(void* context) {
}
SubghzTestCarrier* subghz_test_carrier_alloc() {
- SubghzTestCarrier* subghz_test_carrier = furi_alloc(sizeof(SubghzTestCarrier));
+ SubghzTestCarrier* subghz_test_carrier = malloc(sizeof(SubghzTestCarrier));
// View allocation and configuration
subghz_test_carrier->view = view_alloc();
diff --git a/applications/subghz/views/subghz_test_packet.c b/applications/subghz/views/subghz_test_packet.c
index 335afbb9..c856dc74 100644
--- a/applications/subghz/views/subghz_test_packet.c
+++ b/applications/subghz/views/subghz_test_packet.c
@@ -227,7 +227,7 @@ void subghz_test_packet_exit(void* context) {
}
SubghzTestPacket* subghz_test_packet_alloc() {
- SubghzTestPacket* instance = furi_alloc(sizeof(SubghzTestPacket));
+ SubghzTestPacket* instance = malloc(sizeof(SubghzTestPacket));
// View allocation and configuration
instance->view = view_alloc();
diff --git a/applications/subghz/views/subghz_test_static.c b/applications/subghz/views/subghz_test_static.c
index d3485d73..35001bdc 100644
--- a/applications/subghz/views/subghz_test_static.c
+++ b/applications/subghz/views/subghz_test_static.c
@@ -161,7 +161,7 @@ void subghz_test_static_exit(void* context) {
}
SubghzTestStatic* subghz_test_static_alloc() {
- SubghzTestStatic* instance = furi_alloc(sizeof(SubghzTestStatic));
+ SubghzTestStatic* instance = malloc(sizeof(SubghzTestStatic));
// View allocation and configuration
instance->view = view_alloc();
@@ -187,4 +187,4 @@ void subghz_test_static_free(SubghzTestStatic* instance) {
View* subghz_test_static_get_view(SubghzTestStatic* instance) {
furi_assert(instance);
return instance->view;
-} \ No newline at end of file
+}
diff --git a/applications/subghz/views/subghz_transmitter.c b/applications/subghz/views/subghz_transmitter.c
index b9421e4f..f1afccfa 100644
--- a/applications/subghz/views/subghz_transmitter.c
+++ b/applications/subghz/views/subghz_transmitter.c
@@ -134,7 +134,7 @@ void subghz_transmitter_exit(void* context) {
}
SubghzTransmitter* subghz_transmitter_alloc() {
- SubghzTransmitter* subghz_transmitter = furi_alloc(sizeof(SubghzTransmitter));
+ SubghzTransmitter* subghz_transmitter = malloc(sizeof(SubghzTransmitter));
// View allocation and configuration
subghz_transmitter->view = view_alloc();
diff --git a/applications/system/system_settings.c b/applications/system/system_settings.c
index 7d48451f..fde07745 100644
--- a/applications/system/system_settings.c
+++ b/applications/system/system_settings.c
@@ -63,7 +63,7 @@ static uint32_t system_settings_exit(void* context) {
}
SystemSettings* system_settings_alloc() {
- SystemSettings* app = furi_alloc(sizeof(SystemSettings));
+ SystemSettings* app = malloc(sizeof(SystemSettings));
// Load settings
app->gui = furi_record_open("gui");
diff --git a/applications/tests/flipper_format/flipper_format_string_test.c b/applications/tests/flipper_format/flipper_format_string_test.c
new file mode 100644
index 00000000..9986c523
--- /dev/null
+++ b/applications/tests/flipper_format/flipper_format_string_test.c
@@ -0,0 +1,227 @@
+#include <furi.h>
+#include <flipper_format/flipper_format.h>
+#include <flipper_format/flipper_format_i.h>
+#include <toolbox/stream/stream.h>
+#include <storage/storage.h>
+#include "../minunit.h"
+
+static const char* test_filetype = "Flipper Format test";
+static const uint32_t test_version = 666;
+
+static const char* test_string_key = "String data";
+static const char* test_string_data = "String";
+static const char* test_string_updated_data = "New string";
+
+static const char* test_int_key = "Int32 data";
+static const int32_t test_int_data[] = {1234, -6345, 7813, 0};
+static const int32_t test_int_updated_data[] = {-1337, 69};
+
+static const char* test_uint_key = "Uint32 data";
+static const uint32_t test_uint_data[] = {1234, 0, 5678, 9098, 7654321};
+static const uint32_t test_uint_updated_data[] = {8, 800, 555, 35, 35};
+
+static const char* test_float_key = "Float data";
+static const float test_float_data[] = {1.5f, 1000.0f};
+static const float test_float_updated_data[] = {1.2f};
+
+static const char* test_hex_key = "Hex data";
+static const uint8_t test_hex_data[] = {0xDE, 0xAD, 0xBE};
+static const uint8_t test_hex_updated_data[] = {0xFE, 0xCA};
+
+static const char* test_data_nix = "Filetype: Flipper Format test\n"
+ "Version: 666\n"
+ "# This is comment\n"
+ "String data: String\n"
+ "Int32 data: 1234 -6345 7813 0\n"
+ "Uint32 data: 1234 0 5678 9098 7654321\n"
+ "Float data: 1.5 1000.0\n"
+ "Hex data: DE AD BE";
+
+static const char* test_data_win = "Filetype: Flipper Format test\r\n"
+ "Version: 666\r\n"
+ "# This is comment\r\n"
+ "String data: String\r\n"
+ "Int32 data: 1234 -6345 7813 0\r\n"
+ "Uint32 data: 1234 0 5678 9098 7654321\r\n"
+ "Float data: 1.5 1000.0\r\n"
+ "Hex data: DE AD BE";
+
+#define ARRAY_W_COUNT(x) (x), (COUNT_OF(x))
+#define ARRAY_W_BSIZE(x) (x), (sizeof(x))
+
+MU_TEST_1(flipper_format_read_and_update_test, FlipperFormat* flipper_format) {
+ string_t tmpstr;
+ uint32_t version;
+ uint32_t uint32_data[COUNT_OF(test_uint_data)];
+ int32_t int32_data[COUNT_OF(test_int_data)];
+ float float_data[COUNT_OF(test_float_data)];
+ uint8_t hex_data[COUNT_OF(test_hex_data)];
+
+ uint32_t count;
+
+ mu_check(flipper_format_rewind(flipper_format));
+ string_init(tmpstr);
+
+ mu_check(flipper_format_read_header(flipper_format, tmpstr, &version));
+ mu_assert_string_eq(test_filetype, string_get_cstr(tmpstr));
+ mu_assert_int_eq(test_version, version);
+
+ mu_check(flipper_format_read_string(flipper_format, test_string_key, tmpstr));
+ mu_assert_string_eq(test_string_data, string_get_cstr(tmpstr));
+
+ mu_check(flipper_format_get_value_count(flipper_format, test_int_key, &count));
+ mu_assert_int_eq(COUNT_OF(test_int_data), count);
+ mu_check(flipper_format_read_int32(flipper_format, test_int_key, ARRAY_W_COUNT(int32_data)));
+ mu_check(memcmp(test_int_data, ARRAY_W_BSIZE(int32_data)) == 0);
+
+ mu_check(flipper_format_get_value_count(flipper_format, test_uint_key, &count));
+ mu_assert_int_eq(COUNT_OF(test_uint_data), count);
+ mu_check(
+ flipper_format_read_uint32(flipper_format, test_uint_key, ARRAY_W_COUNT(uint32_data)));
+ mu_check(memcmp(test_uint_data, ARRAY_W_BSIZE(uint32_data)) == 0);
+
+ mu_check(flipper_format_get_value_count(flipper_format, test_float_key, &count));
+ mu_assert_int_eq(COUNT_OF(test_float_data), count);
+ mu_check(flipper_format_read_float(flipper_format, test_float_key, ARRAY_W_COUNT(float_data)));
+ mu_check(memcmp(test_float_data, ARRAY_W_BSIZE(float_data)) == 0);
+
+ mu_check(flipper_format_get_value_count(flipper_format, test_hex_key, &count));
+ mu_assert_int_eq(COUNT_OF(test_hex_data), count);
+ mu_check(flipper_format_read_hex(flipper_format, test_hex_key, ARRAY_W_COUNT(hex_data)));
+ mu_check(memcmp(test_hex_data, ARRAY_W_BSIZE(hex_data)) == 0);
+
+ mu_check(!flipper_format_read_string(flipper_format, "Key that doesn't exist", tmpstr));
+
+ string_clear(tmpstr);
+
+ mu_check(flipper_format_rewind(flipper_format));
+ mu_check(flipper_format_update_string_cstr(
+ flipper_format, test_string_key, test_string_updated_data));
+ mu_check(flipper_format_update_int32(
+ flipper_format, test_int_key, ARRAY_W_COUNT(test_int_updated_data)));
+ mu_check(flipper_format_update_uint32(
+ flipper_format, test_uint_key, ARRAY_W_COUNT(test_uint_updated_data)));
+ mu_check(flipper_format_update_float(
+ flipper_format, test_float_key, ARRAY_W_COUNT(test_float_updated_data)));
+ mu_check(flipper_format_update_hex(
+ flipper_format, test_hex_key, ARRAY_W_COUNT(test_hex_updated_data)));
+
+ uint32_t uint32_updated_data[COUNT_OF(test_uint_updated_data)];
+ int32_t int32_updated_data[COUNT_OF(test_int_updated_data)];
+ float float_updated_data[COUNT_OF(test_float_updated_data)];
+ uint8_t hex_updated_data[COUNT_OF(test_hex_updated_data)];
+
+ mu_check(flipper_format_rewind(flipper_format));
+ string_init(tmpstr);
+
+ mu_check(flipper_format_read_header(flipper_format, tmpstr, &version));
+ mu_assert_string_eq(test_filetype, string_get_cstr(tmpstr));
+ mu_assert_int_eq(test_version, version);
+
+ mu_check(flipper_format_read_string(flipper_format, test_string_key, tmpstr));
+ mu_assert_string_eq(test_string_updated_data, string_get_cstr(tmpstr));
+
+ mu_check(flipper_format_get_value_count(flipper_format, test_int_key, &count));
+ mu_assert_int_eq(COUNT_OF(test_int_updated_data), count);
+ mu_check(flipper_format_read_int32(
+ flipper_format, test_int_key, ARRAY_W_COUNT(int32_updated_data)));
+ mu_check(memcmp(test_int_updated_data, ARRAY_W_BSIZE(int32_updated_data)) == 0);
+
+ mu_check(flipper_format_get_value_count(flipper_format, test_uint_key, &count));
+ mu_assert_int_eq(COUNT_OF(test_uint_updated_data), count);
+ mu_check(flipper_format_read_uint32(
+ flipper_format, test_uint_key, ARRAY_W_COUNT(uint32_updated_data)));
+ mu_check(memcmp(test_uint_updated_data, ARRAY_W_BSIZE(uint32_updated_data)) == 0);
+
+ mu_check(flipper_format_get_value_count(flipper_format, test_float_key, &count));
+ mu_assert_int_eq(COUNT_OF(test_float_updated_data), count);
+ mu_check(flipper_format_read_float(
+ flipper_format, test_float_key, ARRAY_W_COUNT(float_updated_data)));
+ mu_check(memcmp(test_float_updated_data, ARRAY_W_BSIZE(float_updated_data)) == 0);
+
+ mu_check(flipper_format_get_value_count(flipper_format, test_hex_key, &count));
+ mu_assert_int_eq(COUNT_OF(test_hex_updated_data), count);
+ mu_check(
+ flipper_format_read_hex(flipper_format, test_hex_key, ARRAY_W_COUNT(hex_updated_data)));
+ mu_check(memcmp(test_hex_updated_data, ARRAY_W_BSIZE(hex_updated_data)) == 0);
+
+ mu_check(!flipper_format_read_string(flipper_format, "Key that doesn't exist", tmpstr));
+
+ string_clear(tmpstr);
+
+ mu_check(flipper_format_rewind(flipper_format));
+ mu_check(flipper_format_delete_key(flipper_format, test_uint_key));
+
+ mu_check(flipper_format_rewind(flipper_format));
+ mu_check(!flipper_format_read_uint32(
+ flipper_format, test_uint_key, ARRAY_W_COUNT(uint32_updated_data)));
+}
+
+MU_TEST(flipper_format_string_test) {
+ FlipperFormat* flipper_format = flipper_format_string_alloc();
+ Stream* stream = flipper_format_get_raw_stream(flipper_format);
+
+ mu_check(flipper_format_write_header_cstr(flipper_format, test_filetype, test_version));
+ mu_check(flipper_format_write_comment_cstr(flipper_format, "This is comment"));
+ mu_check(flipper_format_write_string_cstr(flipper_format, test_string_key, test_string_data));
+ mu_check(
+ flipper_format_write_int32(flipper_format, test_int_key, ARRAY_W_COUNT(test_int_data)));
+ mu_check(
+ flipper_format_write_uint32(flipper_format, test_uint_key, ARRAY_W_COUNT(test_uint_data)));
+ mu_check(flipper_format_write_float(
+ flipper_format, test_float_key, ARRAY_W_COUNT(test_float_data)));
+ mu_check(flipper_format_write_hex(flipper_format, test_hex_key, ARRAY_W_COUNT(test_hex_data)));
+
+ MU_RUN_TEST_1(flipper_format_read_and_update_test, flipper_format);
+
+ stream_clean(stream);
+ stream_write_cstring(stream, test_data_nix);
+ MU_RUN_TEST_1(flipper_format_read_and_update_test, flipper_format);
+
+ stream_clean(stream);
+ stream_write_cstring(stream, test_data_win);
+ MU_RUN_TEST_1(flipper_format_read_and_update_test, flipper_format);
+
+ flipper_format_free(flipper_format);
+}
+
+MU_TEST(flipper_format_file_test) {
+ Storage* storage = furi_record_open("storage");
+ FlipperFormat* flipper_format = flipper_format_file_alloc(storage);
+ mu_check(flipper_format_file_open_always(flipper_format, "/ext/flipper.fff"));
+ Stream* stream = flipper_format_get_raw_stream(flipper_format);
+
+ mu_check(flipper_format_write_header_cstr(flipper_format, test_filetype, test_version));
+ mu_check(flipper_format_write_comment_cstr(flipper_format, "This is comment"));
+ mu_check(flipper_format_write_string_cstr(flipper_format, test_string_key, test_string_data));
+ mu_check(
+ flipper_format_write_int32(flipper_format, test_int_key, ARRAY_W_COUNT(test_int_data)));
+ mu_check(
+ flipper_format_write_uint32(flipper_format, test_uint_key, ARRAY_W_COUNT(test_uint_data)));
+ mu_check(flipper_format_write_float(
+ flipper_format, test_float_key, ARRAY_W_COUNT(test_float_data)));
+ mu_check(flipper_format_write_hex(flipper_format, test_hex_key, ARRAY_W_COUNT(test_hex_data)));
+
+ MU_RUN_TEST_1(flipper_format_read_and_update_test, flipper_format);
+
+ stream_clean(stream);
+ stream_write_cstring(stream, test_data_nix);
+ MU_RUN_TEST_1(flipper_format_read_and_update_test, flipper_format);
+
+ stream_clean(stream);
+ stream_write_cstring(stream, test_data_win);
+ MU_RUN_TEST_1(flipper_format_read_and_update_test, flipper_format);
+
+ flipper_format_free(flipper_format);
+ furi_record_close("storage");
+}
+
+MU_TEST_SUITE(flipper_format_string_suite) {
+ MU_RUN_TEST(flipper_format_string_test);
+ MU_RUN_TEST(flipper_format_file_test);
+}
+
+int run_minunit_test_flipper_format_string() {
+ MU_RUN_SUITE(flipper_format_string_suite);
+ return MU_EXIT_CODE;
+} \ No newline at end of file
diff --git a/applications/tests/flipper_file/flipper_file_test.c b/applications/tests/flipper_format/flipper_format_test.c
index 8d21bb42..62171817 100644
--- a/applications/tests/flipper_file/flipper_file_test.c
+++ b/applications/tests/flipper_format/flipper_format_test.c
@@ -1,5 +1,7 @@
#include <furi.h>
-#include <flipper_file/flipper_file.h>
+#include <flipper_format/flipper_format.h>
+#include <flipper_format/flipper_format_i.h>
+#include <toolbox/stream/stream.h>
#include "../minunit.h"
#define TEST_DIR TEST_DIR_NAME "/"
@@ -28,8 +30,8 @@ static const char* test_hex_key = "Hex data";
static const uint8_t test_hex_data[] = {0xDE, 0xAD, 0xBE};
static const uint8_t test_hex_updated_data[] = {0xFE, 0xCA};
-#define READ_TEST_WIN "ff_win.test"
-static const char* test_data_win = "Filetype: Flipper File test\n"
+#define READ_TEST_NIX "ff_nix.test"
+static const char* test_data_nix = "Filetype: Flipper File test\n"
"Version: 666\n"
"# This is comment\n"
"String data: String\n"
@@ -38,8 +40,8 @@ static const char* test_data_win = "Filetype: Flipper File test\n"
"Float data: 1.5 1000.0\n"
"Hex data: DE AD BE";
-#define READ_TEST_NIX "ff_nix.test"
-static const char* test_data_nix = "Filetype: Flipper File test\r\n"
+#define READ_TEST_WIN "ff_win.test"
+static const char* test_data_win = "Filetype: Flipper File test\r\n"
"Version: 666\r\n"
"# This is comment\r\n"
"String data: String\r\n"
@@ -51,11 +53,11 @@ static const char* test_data_nix = "Filetype: Flipper File test\r\n"
#define READ_TEST_FLP "ff_flp.test"
// data created by user on linux machine
-const char* test_file_linux = TEST_DIR READ_TEST_WIN;
+static const char* test_file_linux = TEST_DIR READ_TEST_NIX;
// data created by user on windows machine
-const char* test_file_windows = TEST_DIR READ_TEST_NIX;
+static const char* test_file_windows = TEST_DIR READ_TEST_WIN;
// data created by flipper itself
-const char* test_file_flipper = TEST_DIR READ_TEST_FLP;
+static const char* test_file_flipper = TEST_DIR READ_TEST_FLP;
static bool storage_write_string(const char* path, const char* data) {
Storage* storage = furi_record_open("storage");
@@ -93,43 +95,43 @@ static bool test_read(const char* file_name) {
Storage* storage = furi_record_open("storage");
bool result = false;
- FlipperFile* file = flipper_file_alloc(storage);
+ FlipperFormat* file = flipper_format_file_alloc(storage);
string_t string_value;
string_init(string_value);
uint32_t uint32_value;
void* scratchpad = malloc(512);
do {
- if(!flipper_file_open_existing(file, file_name)) break;
+ if(!flipper_format_file_open_existing(file, file_name)) break;
- if(!flipper_file_read_header(file, string_value, &uint32_value)) break;
+ if(!flipper_format_read_header(file, string_value, &uint32_value)) break;
if(string_cmp_str(string_value, test_filetype) != 0) break;
if(uint32_value != test_version) break;
- if(!flipper_file_read_string(file, test_string_key, string_value)) break;
+ if(!flipper_format_read_string(file, test_string_key, string_value)) break;
if(string_cmp_str(string_value, test_string_data) != 0) break;
- if(!flipper_file_get_value_count(file, test_int_key, &uint32_value)) break;
+ if(!flipper_format_get_value_count(file, test_int_key, &uint32_value)) break;
if(uint32_value != COUNT_OF(test_int_data)) break;
- if(!flipper_file_read_int32(file, test_int_key, scratchpad, uint32_value)) break;
+ if(!flipper_format_read_int32(file, test_int_key, scratchpad, uint32_value)) break;
if(memcmp(scratchpad, test_int_data, sizeof(int32_t) * COUNT_OF(test_int_data)) != 0)
break;
- if(!flipper_file_get_value_count(file, test_uint_key, &uint32_value)) break;
+ if(!flipper_format_get_value_count(file, test_uint_key, &uint32_value)) break;
if(uint32_value != COUNT_OF(test_uint_data)) break;
- if(!flipper_file_read_uint32(file, test_uint_key, scratchpad, uint32_value)) break;
+ if(!flipper_format_read_uint32(file, test_uint_key, scratchpad, uint32_value)) break;
if(memcmp(scratchpad, test_uint_data, sizeof(uint32_t) * COUNT_OF(test_uint_data)) != 0)
break;
- if(!flipper_file_get_value_count(file, test_float_key, &uint32_value)) break;
+ if(!flipper_format_get_value_count(file, test_float_key, &uint32_value)) break;
if(uint32_value != COUNT_OF(test_float_data)) break;
- if(!flipper_file_read_float(file, test_float_key, scratchpad, uint32_value)) break;
+ if(!flipper_format_read_float(file, test_float_key, scratchpad, uint32_value)) break;
if(memcmp(scratchpad, test_float_data, sizeof(float) * COUNT_OF(test_float_data)) != 0)
break;
- if(!flipper_file_get_value_count(file, test_hex_key, &uint32_value)) break;
+ if(!flipper_format_get_value_count(file, test_hex_key, &uint32_value)) break;
if(uint32_value != COUNT_OF(test_hex_data)) break;
- if(!flipper_file_read_hex(file, test_hex_key, scratchpad, uint32_value)) break;
+ if(!flipper_format_read_hex(file, test_hex_key, scratchpad, uint32_value)) break;
if(memcmp(scratchpad, test_hex_data, sizeof(uint8_t) * COUNT_OF(test_hex_data)) != 0)
break;
@@ -138,8 +140,8 @@ static bool test_read(const char* file_name) {
free(scratchpad);
string_clear(string_value);
- flipper_file_close(file);
- flipper_file_free(file);
+
+ flipper_format_free(file);
furi_record_close("storage");
@@ -150,52 +152,52 @@ static bool test_read_updated(const char* file_name) {
Storage* storage = furi_record_open("storage");
bool result = false;
- FlipperFile* file = flipper_file_alloc(storage);
+ FlipperFormat* file = flipper_format_file_alloc(storage);
string_t string_value;
string_init(string_value);
uint32_t uint32_value;
void* scratchpad = malloc(512);
do {
- if(!flipper_file_open_existing(file, file_name)) break;
+ if(!flipper_format_file_open_existing(file, file_name)) break;
- if(!flipper_file_read_header(file, string_value, &uint32_value)) break;
+ if(!flipper_format_read_header(file, string_value, &uint32_value)) break;
if(string_cmp_str(string_value, test_filetype) != 0) break;
if(uint32_value != test_version) break;
- if(!flipper_file_read_string(file, test_string_key, string_value)) break;
+ if(!flipper_format_read_string(file, test_string_key, string_value)) break;
if(string_cmp_str(string_value, test_string_updated_data) != 0) break;
- if(!flipper_file_get_value_count(file, test_int_key, &uint32_value)) break;
+ if(!flipper_format_get_value_count(file, test_int_key, &uint32_value)) break;
if(uint32_value != COUNT_OF(test_int_updated_data)) break;
- if(!flipper_file_read_int32(file, test_int_key, scratchpad, uint32_value)) break;
+ if(!flipper_format_read_int32(file, test_int_key, scratchpad, uint32_value)) break;
if(memcmp(
scratchpad,
test_int_updated_data,
sizeof(int32_t) * COUNT_OF(test_int_updated_data)) != 0)
break;
- if(!flipper_file_get_value_count(file, test_uint_key, &uint32_value)) break;
+ if(!flipper_format_get_value_count(file, test_uint_key, &uint32_value)) break;
if(uint32_value != COUNT_OF(test_uint_updated_data)) break;
- if(!flipper_file_read_uint32(file, test_uint_key, scratchpad, uint32_value)) break;
+ if(!flipper_format_read_uint32(file, test_uint_key, scratchpad, uint32_value)) break;
if(memcmp(
scratchpad,
test_uint_updated_data,
sizeof(uint32_t) * COUNT_OF(test_uint_updated_data)) != 0)
break;
- if(!flipper_file_get_value_count(file, test_float_key, &uint32_value)) break;
+ if(!flipper_format_get_value_count(file, test_float_key, &uint32_value)) break;
if(uint32_value != COUNT_OF(test_float_updated_data)) break;
- if(!flipper_file_read_float(file, test_float_key, scratchpad, uint32_value)) break;
+ if(!flipper_format_read_float(file, test_float_key, scratchpad, uint32_value)) break;
if(memcmp(
scratchpad,
test_float_updated_data,
sizeof(float) * COUNT_OF(test_float_updated_data)) != 0)
break;
- if(!flipper_file_get_value_count(file, test_hex_key, &uint32_value)) break;
+ if(!flipper_format_get_value_count(file, test_hex_key, &uint32_value)) break;
if(uint32_value != COUNT_OF(test_hex_updated_data)) break;
- if(!flipper_file_read_hex(file, test_hex_key, scratchpad, uint32_value)) break;
+ if(!flipper_format_read_hex(file, test_hex_key, scratchpad, uint32_value)) break;
if(memcmp(
scratchpad,
test_hex_updated_data,
@@ -207,8 +209,8 @@ static bool test_read_updated(const char* file_name) {
free(scratchpad);
string_clear(string_value);
- flipper_file_close(file);
- flipper_file_free(file);
+
+ flipper_format_free(file);
furi_record_close("storage");
@@ -218,28 +220,27 @@ static bool test_read_updated(const char* file_name) {
static bool test_write(const char* file_name) {
Storage* storage = furi_record_open("storage");
bool result = false;
- FlipperFile* file = flipper_file_alloc(storage);
+ FlipperFormat* file = flipper_format_file_alloc(storage);
do {
- if(!flipper_file_open_always(file, file_name)) break;
- if(!flipper_file_write_header_cstr(file, test_filetype, test_version)) break;
- if(!flipper_file_write_comment_cstr(file, "This is comment")) break;
- if(!flipper_file_write_string_cstr(file, test_string_key, test_string_data)) break;
- if(!flipper_file_write_int32(file, test_int_key, test_int_data, COUNT_OF(test_int_data)))
+ if(!flipper_format_file_open_always(file, file_name)) break;
+ if(!flipper_format_write_header_cstr(file, test_filetype, test_version)) break;
+ if(!flipper_format_write_comment_cstr(file, "This is comment")) break;
+ if(!flipper_format_write_string_cstr(file, test_string_key, test_string_data)) break;
+ if(!flipper_format_write_int32(file, test_int_key, test_int_data, COUNT_OF(test_int_data)))
break;
- if(!flipper_file_write_uint32(
+ if(!flipper_format_write_uint32(
file, test_uint_key, test_uint_data, COUNT_OF(test_uint_data)))
break;
- if(!flipper_file_write_float(
+ if(!flipper_format_write_float(
file, test_float_key, test_float_data, COUNT_OF(test_float_data)))
break;
- if(!flipper_file_write_hex(file, test_hex_key, test_hex_data, COUNT_OF(test_hex_data)))
+ if(!flipper_format_write_hex(file, test_hex_key, test_hex_data, COUNT_OF(test_hex_data)))
break;
result = true;
} while(false);
- flipper_file_close(file);
- flipper_file_free(file);
+ flipper_format_free(file);
furi_record_close("storage");
return result;
@@ -248,16 +249,15 @@ static bool test_write(const char* file_name) {
static bool test_delete_last_key(const char* file_name) {
Storage* storage = furi_record_open("storage");
bool result = false;
- FlipperFile* file = flipper_file_alloc(storage);
+ FlipperFormat* file = flipper_format_file_alloc(storage);
do {
- if(!flipper_file_open_existing(file, file_name)) break;
- if(!flipper_file_delete_key(file, test_hex_key)) break;
+ if(!flipper_format_file_open_existing(file, file_name)) break;
+ if(!flipper_format_delete_key(file, test_hex_key)) break;
result = true;
} while(false);
- flipper_file_close(file);
- flipper_file_free(file);
+ flipper_format_free(file);
furi_record_close("storage");
return result;
@@ -266,17 +266,16 @@ static bool test_delete_last_key(const char* file_name) {
static bool test_append_key(const char* file_name) {
Storage* storage = furi_record_open("storage");
bool result = false;
- FlipperFile* file = flipper_file_alloc(storage);
+ FlipperFormat* file = flipper_format_file_alloc(storage);
do {
- if(!flipper_file_open_append(file, file_name)) break;
- if(!flipper_file_write_hex(file, test_hex_key, test_hex_data, COUNT_OF(test_hex_data)))
+ if(!flipper_format_file_open_append(file, file_name)) break;
+ if(!flipper_format_write_hex(file, test_hex_key, test_hex_data, COUNT_OF(test_hex_data)))
break;
result = true;
} while(false);
- flipper_file_close(file);
- flipper_file_free(file);
+ flipper_format_free(file);
furi_record_close("storage");
return result;
@@ -285,30 +284,29 @@ static bool test_append_key(const char* file_name) {
static bool test_update(const char* file_name) {
Storage* storage = furi_record_open("storage");
bool result = false;
- FlipperFile* file = flipper_file_alloc(storage);
+ FlipperFormat* file = flipper_format_file_alloc(storage);
do {
- if(!flipper_file_open_existing(file, file_name)) break;
- if(!flipper_file_update_string_cstr(file, test_string_key, test_string_updated_data))
+ if(!flipper_format_file_open_existing(file, file_name)) break;
+ if(!flipper_format_update_string_cstr(file, test_string_key, test_string_updated_data))
break;
- if(!flipper_file_update_int32(
+ if(!flipper_format_update_int32(
file, test_int_key, test_int_updated_data, COUNT_OF(test_int_updated_data)))
break;
- if(!flipper_file_update_uint32(
+ if(!flipper_format_update_uint32(
file, test_uint_key, test_uint_updated_data, COUNT_OF(test_uint_updated_data)))
break;
- if(!flipper_file_update_float(
+ if(!flipper_format_update_float(
file, test_float_key, test_float_updated_data, COUNT_OF(test_float_updated_data)))
break;
- if(!flipper_file_update_hex(
+ if(!flipper_format_update_hex(
file, test_hex_key, test_hex_updated_data, COUNT_OF(test_hex_updated_data)))
break;
result = true;
} while(false);
- flipper_file_close(file);
- flipper_file_free(file);
+ flipper_format_free(file);
furi_record_close("storage");
return result;
@@ -317,27 +315,26 @@ static bool test_update(const char* file_name) {
static bool test_update_backward(const char* file_name) {
Storage* storage = furi_record_open("storage");
bool result = false;
- FlipperFile* file = flipper_file_alloc(storage);
+ FlipperFormat* file = flipper_format_file_alloc(storage);
do {
- if(!flipper_file_open_existing(file, file_name)) break;
- if(!flipper_file_update_string_cstr(file, test_string_key, test_string_data)) break;
- if(!flipper_file_update_int32(file, test_int_key, test_int_data, COUNT_OF(test_int_data)))
+ if(!flipper_format_file_open_existing(file, file_name)) break;
+ if(!flipper_format_update_string_cstr(file, test_string_key, test_string_data)) break;
+ if(!flipper_format_update_int32(file, test_int_key, test_int_data, COUNT_OF(test_int_data)))
break;
- if(!flipper_file_update_uint32(
+ if(!flipper_format_update_uint32(
file, test_uint_key, test_uint_data, COUNT_OF(test_uint_data)))
break;
- if(!flipper_file_update_float(
+ if(!flipper_format_update_float(
file, test_float_key, test_float_data, COUNT_OF(test_float_data)))
break;
- if(!flipper_file_update_hex(file, test_hex_key, test_hex_data, COUNT_OF(test_hex_data)))
+ if(!flipper_format_update_hex(file, test_hex_key, test_hex_data, COUNT_OF(test_hex_data)))
break;
result = true;
} while(false);
- flipper_file_close(file);
- flipper_file_free(file);
+ flipper_format_free(file);
furi_record_close("storage");
return result;
@@ -346,15 +343,15 @@ static bool test_update_backward(const char* file_name) {
static bool test_write_multikey(const char* file_name) {
Storage* storage = furi_record_open("storage");
bool result = false;
- FlipperFile* file = flipper_file_alloc(storage);
+ FlipperFormat* file = flipper_format_file_alloc(storage);
do {
- if(!flipper_file_open_always(file, file_name)) break;
- if(!flipper_file_write_header_cstr(file, test_filetype, test_version)) break;
+ if(!flipper_format_file_open_always(file, file_name)) break;
+ if(!flipper_format_write_header_cstr(file, test_filetype, test_version)) break;
bool error = false;
for(uint8_t index = 0; index < 100; index++) {
- if(!flipper_file_write_hex(file, test_hex_key, &index, 1)) {
+ if(!flipper_format_write_hex(file, test_hex_key, &index, 1)) {
error = true;
break;
}
@@ -364,8 +361,7 @@ static bool test_write_multikey(const char* file_name) {
result = true;
} while(false);
- flipper_file_close(file);
- flipper_file_free(file);
+ flipper_format_free(file);
furi_record_close("storage");
return result;
@@ -374,22 +370,22 @@ static bool test_write_multikey(const char* file_name) {
static bool test_read_multikey(const char* file_name) {
Storage* storage = furi_record_open("storage");
bool result = false;
- FlipperFile* file = flipper_file_alloc(storage);
+ FlipperFormat* file = flipper_format_file_alloc(storage);
string_t string_value;
string_init(string_value);
uint32_t uint32_value;
do {
- if(!flipper_file_open_existing(file, file_name)) break;
- if(!flipper_file_read_header(file, string_value, &uint32_value)) break;
+ if(!flipper_format_file_open_existing(file, file_name)) break;
+ if(!flipper_format_read_header(file, string_value, &uint32_value)) break;
if(string_cmp_str(string_value, test_filetype) != 0) break;
if(uint32_value != test_version) break;
bool error = false;
uint8_t uint8_value;
for(uint8_t index = 0; index < 100; index++) {
- if(!flipper_file_read_hex(file, test_hex_key, &uint8_value, 1)) {
+ if(!flipper_format_read_hex(file, test_hex_key, &uint8_value, 1)) {
error = true;
break;
}
@@ -405,96 +401,96 @@ static bool test_read_multikey(const char* file_name) {
} while(false);
string_clear(string_value);
- flipper_file_close(file);
- flipper_file_free(file);
+
+ flipper_format_free(file);
furi_record_close("storage");
return result;
}
-MU_TEST(flipper_file_write_test) {
+MU_TEST(flipper_format_write_test) {
mu_assert(storage_write_string(test_file_linux, test_data_nix), "Write test error [Linux]");
mu_assert(
storage_write_string(test_file_windows, test_data_win), "Write test error [Windows]");
mu_assert(test_write(test_file_flipper), "Write test error [Flipper]");
}
-MU_TEST(flipper_file_read_test) {
+MU_TEST(flipper_format_read_test) {
mu_assert(test_read(test_file_linux), "Read test error [Linux]");
mu_assert(test_read(test_file_windows), "Read test error [Windows]");
mu_assert(test_read(test_file_flipper), "Read test error [Flipper]");
}
-MU_TEST(flipper_file_delete_test) {
+MU_TEST(flipper_format_delete_test) {
mu_assert(test_delete_last_key(test_file_linux), "Cannot delete key [Linux]");
mu_assert(test_delete_last_key(test_file_windows), "Cannot delete key [Windows]");
mu_assert(test_delete_last_key(test_file_flipper), "Cannot delete key [Flipper]");
}
-MU_TEST(flipper_file_delete_result_test) {
+MU_TEST(flipper_format_delete_result_test) {
mu_assert(!test_read(test_file_linux), "Key deleted incorrectly [Linux]");
mu_assert(!test_read(test_file_windows), "Key deleted incorrectly [Windows]");
mu_assert(!test_read(test_file_flipper), "Key deleted incorrectly [Flipper]");
}
-MU_TEST(flipper_file_append_test) {
+MU_TEST(flipper_format_append_test) {
mu_assert(test_append_key(test_file_linux), "Cannot append data [Linux]");
mu_assert(test_append_key(test_file_windows), "Cannot append data [Windows]");
mu_assert(test_append_key(test_file_flipper), "Cannot append data [Flipper]");
}
-MU_TEST(flipper_file_append_result_test) {
+MU_TEST(flipper_format_append_result_test) {
mu_assert(test_read(test_file_linux), "Data appended incorrectly [Linux]");
mu_assert(test_read(test_file_windows), "Data appended incorrectly [Windows]");
mu_assert(test_read(test_file_flipper), "Data appended incorrectly [Flipper]");
}
-MU_TEST(flipper_file_update_1_test) {
+MU_TEST(flipper_format_update_1_test) {
mu_assert(test_update(test_file_linux), "Cannot update data #1 [Linux]");
mu_assert(test_update(test_file_windows), "Cannot update data #1 [Windows]");
mu_assert(test_update(test_file_flipper), "Cannot update data #1 [Flipper]");
}
-MU_TEST(flipper_file_update_1_result_test) {
+MU_TEST(flipper_format_update_1_result_test) {
mu_assert(test_read_updated(test_file_linux), "Data #1 updated incorrectly [Linux]");
mu_assert(test_read_updated(test_file_windows), "Data #1 updated incorrectly [Windows]");
mu_assert(test_read_updated(test_file_flipper), "Data #1 updated incorrectly [Flipper]");
}
-MU_TEST(flipper_file_update_2_test) {
+MU_TEST(flipper_format_update_2_test) {
mu_assert(test_update_backward(test_file_linux), "Cannot update data #2 [Linux]");
mu_assert(test_update_backward(test_file_windows), "Cannot update data #2 [Windows]");
mu_assert(test_update_backward(test_file_flipper), "Cannot update data #2 [Flipper]");
}
-MU_TEST(flipper_file_update_2_result_test) {
+MU_TEST(flipper_format_update_2_result_test) {
mu_assert(test_read(test_file_linux), "Data #2 updated incorrectly [Linux]");
mu_assert(test_read(test_file_windows), "Data #2 updated incorrectly [Windows]");
mu_assert(test_read(test_file_flipper), "Data #2 updated incorrectly [Flipper]");
}
-MU_TEST(flipper_file_multikey_test) {
+MU_TEST(flipper_format_multikey_test) {
mu_assert(test_write_multikey(TEST_DIR "ff_multiline.test"), "Multikey write test error");
mu_assert(test_read_multikey(TEST_DIR "ff_multiline.test"), "Multikey read test error");
}
-MU_TEST_SUITE(flipper_file) {
+MU_TEST_SUITE(flipper_format) {
tests_setup();
- MU_RUN_TEST(flipper_file_write_test);
- MU_RUN_TEST(flipper_file_read_test);
- MU_RUN_TEST(flipper_file_delete_test);
- MU_RUN_TEST(flipper_file_delete_result_test);
- MU_RUN_TEST(flipper_file_append_test);
- MU_RUN_TEST(flipper_file_append_result_test);
- MU_RUN_TEST(flipper_file_update_1_test);
- MU_RUN_TEST(flipper_file_update_1_result_test);
- MU_RUN_TEST(flipper_file_update_2_test);
- MU_RUN_TEST(flipper_file_update_2_result_test);
- MU_RUN_TEST(flipper_file_multikey_test);
+ MU_RUN_TEST(flipper_format_write_test);
+ MU_RUN_TEST(flipper_format_read_test);
+ MU_RUN_TEST(flipper_format_delete_test);
+ MU_RUN_TEST(flipper_format_delete_result_test);
+ MU_RUN_TEST(flipper_format_append_test);
+ MU_RUN_TEST(flipper_format_append_result_test);
+ MU_RUN_TEST(flipper_format_update_1_test);
+ MU_RUN_TEST(flipper_format_update_1_result_test);
+ MU_RUN_TEST(flipper_format_update_2_test);
+ MU_RUN_TEST(flipper_format_update_2_result_test);
+ MU_RUN_TEST(flipper_format_multikey_test);
tests_teardown();
}
-int run_minunit_test_flipper_file() {
- MU_RUN_SUITE(flipper_file);
+int run_minunit_test_flipper_format() {
+ MU_RUN_SUITE(flipper_format);
return MU_EXIT_CODE;
-} \ No newline at end of file
+}
diff --git a/applications/tests/furi_memmgr_test.c b/applications/tests/furi_memmgr_test.c
index 99925be8..732856ec 100644
--- a/applications/tests/furi_memmgr_test.c
+++ b/applications/tests/furi_memmgr_test.c
@@ -2,6 +2,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
+
// this test is not accurate, but gives a basic understanding
// that memory management is working fine
@@ -96,4 +97,4 @@ void test_furi_memmgr() {
free(original_ptr);
free(ptr);
-} \ No newline at end of file
+}
diff --git a/applications/tests/irda_decoder_encoder/irda_decoder_encoder_test.c b/applications/tests/irda_decoder_encoder/irda_decoder_encoder_test.c
index 3e2a6831..7ab27430 100644
--- a/applications/tests/irda_decoder_encoder/irda_decoder_encoder_test.c
+++ b/applications/tests/irda_decoder_encoder/irda_decoder_encoder_test.c
@@ -88,7 +88,7 @@ static void run_encoder(
uint32_t* timings = 0;
uint32_t timings_len = 200;
uint32_t j = 0;
- timings = furi_alloc(sizeof(uint32_t) * timings_len);
+ timings = malloc(sizeof(uint32_t) * timings_len);
for(uint32_t message_counter = 0; message_counter < input_messages_len; ++message_counter) {
const IrdaMessage* message = &input_messages[message_counter];
@@ -113,7 +113,7 @@ static void run_encoder_decoder(const IrdaMessage input_messages[], uint32_t inp
uint32_t* timings = 0;
uint32_t timings_len = 200;
bool level = false;
- timings = furi_alloc(sizeof(uint32_t) * timings_len);
+ timings = malloc(sizeof(uint32_t) * timings_len);
for(uint32_t message_counter = 0; message_counter < input_messages_len; ++message_counter) {
const IrdaMessage* message_encoded = &input_messages[message_counter];
diff --git a/applications/tests/minunit.h b/applications/tests/minunit.h
index b12a87ca..d1efd13e 100644
--- a/applications/tests/minunit.h
+++ b/applications/tests/minunit.h
@@ -84,6 +84,7 @@ void minunit_print_fail(const char* error);
/* Definitions */
#define MU_TEST(method_name) static void method_name(void)
+#define MU_TEST_1(method_name, arg_1) static void method_name(arg_1)
#define MU_TEST_SUITE(suite_name) static void suite_name(void)
#define MU__SAFE_BLOCK(block) \
@@ -107,11 +108,30 @@ void minunit_print_fail(const char* error);
minunit_proc_timer = mu_timer_cpu(); \
} if(minunit_setup) (*minunit_setup)(); \
minunit_status = 0; \
+ printf(#test "()\r\n"); \
test(); \
minunit_run++; \
if(minunit_status) { \
minunit_fail++; \
minunit_print_fail(minunit_last_message); \
+ minunit_status = 0; \
+ } fflush(stdout); \
+ if(minunit_teardown)(*minunit_teardown)();)
+
+#define MU_RUN_TEST_1(test, arg_1) \
+ MU__SAFE_BLOCK( \
+ if(minunit_real_timer == 0 && minunit_proc_timer == 0) { \
+ minunit_real_timer = mu_timer_real(); \
+ minunit_proc_timer = mu_timer_cpu(); \
+ } if(minunit_setup) (*minunit_setup)(); \
+ minunit_status = 0; \
+ printf(#test "(" #arg_1 ")\r\n"); \
+ test(arg_1); \
+ minunit_run++; \
+ if(minunit_status) { \
+ minunit_fail++; \
+ minunit_print_fail(minunit_last_message); \
+ minunit_status = 0; \
} fflush(stdout); \
if(minunit_teardown)(*minunit_teardown)();)
diff --git a/applications/tests/rpc/rpc_test.c b/applications/tests/rpc/rpc_test.c
index ccd8ea78..b51a1278 100644
--- a/applications/tests/rpc/rpc_test.c
+++ b/applications/tests/rpc/rpc_test.c
@@ -136,9 +136,9 @@ static void clean_directory(Storage* fs_api, const char* clean_dir) {
File* dir = storage_file_alloc(fs_api);
if(storage_dir_open(dir, clean_dir)) {
FileInfo fileinfo;
- char* name = furi_alloc(MAX_NAME_LENGTH + 1);
+ char* name = malloc(MAX_NAME_LENGTH + 1);
while(storage_dir_read(dir, &fileinfo, name, MAX_NAME_LENGTH)) {
- char* fullname = furi_alloc(strlen(clean_dir) + strlen(name) + 1 + 1);
+ char* fullname = malloc(strlen(clean_dir) + strlen(name) + 1 + 1);
sprintf(fullname, "%s/%s", clean_dir, name);
if(fileinfo.flags & FSF_DIRECTORY) {
clean_directory(fs_api, fullname);
@@ -310,7 +310,7 @@ static void test_rpc_add_read_or_write_to_list(
msg_file = &request->content.storage_read_response.file;
}
- msg_file->data = furi_alloc(PB_BYTES_ARRAY_T_ALLOCSIZE(pattern_size));
+ msg_file->data = malloc(PB_BYTES_ARRAY_T_ALLOCSIZE(pattern_size));
msg_file->data->size = pattern_size;
memcpy(msg_file->data->bytes, pattern, pattern_size);
@@ -328,7 +328,7 @@ static void test_rpc_encode_and_feed_one(PB_Main* request) {
bool result = pb_encode_ex(&ostream, &PB_Main_msg, request, PB_ENCODE_DELIMITED);
furi_check(result && ostream.bytes_written);
- uint8_t* buffer = furi_alloc(ostream.bytes_written);
+ uint8_t* buffer = malloc(ostream.bytes_written);
ostream = pb_ostream_from_buffer(buffer, ostream.bytes_written);
pb_encode_ex(&ostream, &PB_Main_msg, request, PB_ENCODE_DELIMITED);
@@ -501,13 +501,13 @@ static void
message->content.storage_list_response.file[1].type = PB_Storage_File_FileType_DIR;
message->content.storage_list_response.file[2].type = PB_Storage_File_FileType_DIR;
- char* str = furi_alloc(4);
+ char* str = malloc(4);
strcpy(str, "any");
message->content.storage_list_response.file[0].name = str;
- str = furi_alloc(4);
+ str = malloc(4);
strcpy(str, "int");
message->content.storage_list_response.file[1].name = str;
- str = furi_alloc(4);
+ str = malloc(4);
strcpy(str, "ext");
message->content.storage_list_response.file[2].name = str;
}
@@ -540,7 +540,7 @@ static void test_rpc_storage_list_create_expected_list(
while(!finish) {
FileInfo fileinfo;
- char* name = furi_alloc(MAX_NAME_LENGTH + 1);
+ char* name = malloc(MAX_NAME_LENGTH + 1);
if(storage_dir_read(dir, &fileinfo, name, MAX_NAME_LENGTH)) {
if(i == COUNT_OF(list->file)) {
list->file_count = i;
@@ -675,7 +675,7 @@ static void test_rpc_add_read_to_list_by_reading_real_file(
response->content.storage_read_response.has_file = true;
response->content.storage_read_response.file.data =
- furi_alloc(PB_BYTES_ARRAY_T_ALLOCSIZE(MIN(size_left, MAX_DATA_SIZE)));
+ malloc(PB_BYTES_ARRAY_T_ALLOCSIZE(MIN(size_left, MAX_DATA_SIZE)));
uint8_t* buffer = response->content.storage_read_response.file.data->bytes;
uint16_t* read_size_msg = &response->content.storage_read_response.file.data->size;
size_t read_size = MIN(size_left, MAX_DATA_SIZE);
@@ -873,7 +873,7 @@ static void test_storage_write_run(
MsgList_t expected_msg_list;
MsgList_init(expected_msg_list);
- uint8_t* buf = furi_alloc(write_size);
+ uint8_t* buf = malloc(write_size);
for(int i = 0; i < write_size; ++i) {
buf[i] = '0' + (i % 10);
}
@@ -1497,7 +1497,7 @@ MU_TEST_SUITE(test_rpc_app) {
static void
test_send_rubbish(RpcSession* session, const char* pattern, size_t pattern_size, size_t size) {
- uint8_t* buf = furi_alloc(size);
+ uint8_t* buf = malloc(size);
for(int i = 0; i < size; ++i) {
buf[i] = pattern[i % pattern_size];
}
diff --git a/applications/tests/stream/stream_test.c b/applications/tests/stream/stream_test.c
new file mode 100644
index 00000000..eed8a7bc
--- /dev/null
+++ b/applications/tests/stream/stream_test.c
@@ -0,0 +1,381 @@
+#include <furi.h>
+#include <toolbox/stream/stream.h>
+#include <toolbox/stream/string_stream.h>
+#include <toolbox/stream/file_stream.h>
+#include <storage/storage.h>
+#include "../minunit.h"
+
+static const char* stream_test_data = "I write differently from what I speak, "
+ "I speak differently from what I think, "
+ "I think differently from the way I ought to think, "
+ "and so it all proceeds into deepest darkness.";
+
+static const char* stream_test_left_data = "There are two cardinal human sins ";
+static const char* stream_test_right_data =
+ "from which all others derive: impatience and indolence.";
+
+MU_TEST_1(stream_composite_subtest, Stream* stream) {
+ const size_t data_size = 128;
+ uint8_t data[data_size];
+ string_t string_lee;
+ string_init_set(string_lee, "lee");
+
+ // test that stream is empty
+ // "" -> ""
+ mu_check(stream_size(stream) == 0);
+ mu_check(stream_eof(stream));
+ mu_check(stream_tell(stream) == 0);
+ mu_check(stream_read(stream, data, data_size) == 0);
+ mu_check(stream_eof(stream));
+ mu_check(stream_tell(stream) == 0);
+
+ // write char
+ // "" -> "2"
+ mu_check(stream_write_char(stream, '2') == 1);
+ mu_check(stream_size(stream) == 1);
+ mu_check(stream_tell(stream) == 1);
+ mu_check(stream_eof(stream));
+
+ // test rewind and eof
+ stream_rewind(stream);
+ mu_check(stream_size(stream) == 1);
+ mu_check(stream_tell(stream) == 0);
+ mu_check(!stream_eof(stream));
+
+ // add another char with replacement
+ // "2" -> "1"
+ mu_check(stream_write_char(stream, '1') == 1);
+ mu_check(stream_size(stream) == 1);
+ mu_check(stream_tell(stream) == 1);
+ mu_check(stream_eof(stream));
+
+ // write string
+ // "1" -> "1337_69"
+ mu_check(stream_write_cstring(stream, "337_69") == 6);
+ mu_check(stream_size(stream) == 7);
+ mu_check(stream_tell(stream) == 7);
+ mu_check(stream_eof(stream));
+
+ // read data
+ memset(data, 0, data_size);
+ stream_rewind(stream);
+ mu_check(stream_read(stream, data, data_size) == 7);
+ mu_check(strcmp((char*)data, "1337_69") == 0);
+
+ // test misc seeks
+ mu_check(stream_seek(stream, 2, StreamOffsetFromStart));
+ mu_check(stream_tell(stream) == 2);
+ mu_check(!stream_seek(stream, 9000, StreamOffsetFromStart));
+ mu_check(stream_tell(stream) == 7);
+ mu_check(stream_eof(stream));
+ mu_check(stream_seek(stream, -3, StreamOffsetFromEnd));
+ mu_check(stream_tell(stream) == 4);
+
+ // write string with replacemet
+ // "1337_69" -> "1337lee"
+ mu_check(stream_write_string(stream, string_lee) == 3);
+ mu_check(stream_size(stream) == 7);
+ mu_check(stream_tell(stream) == 7);
+ mu_check(stream_eof(stream));
+
+ // append char
+ // "1337lee" -> "1337leet"
+ mu_check(stream_write(stream, (uint8_t*)"t", 1) == 1);
+ mu_check(stream_size(stream) == 8);
+ mu_check(stream_tell(stream) == 8);
+ mu_check(stream_eof(stream));
+
+ // read data
+ memset(data, 0, data_size);
+ stream_rewind(stream);
+ mu_check(stream_read(stream, data, data_size) == 8);
+ mu_check(strcmp((char*)data, "1337leet") == 0);
+ mu_check(stream_tell(stream) == 8);
+ mu_check(stream_eof(stream));
+
+ // negative seek from current position -> clamp to 0
+ mu_check(!stream_seek(stream, -9000, StreamOffsetFromCurrent));
+ mu_check(stream_tell(stream) == 0);
+
+ // negative seek from start position -> clamp to 0
+ stream_rewind(stream);
+ mu_check(!stream_seek(stream, -3, StreamOffsetFromStart));
+ mu_check(stream_tell(stream) == 0);
+
+ // zero seek from current position -> clamp to stream size
+ mu_check(stream_seek(stream, 0, StreamOffsetFromEnd));
+ mu_check(stream_tell(stream) == 8);
+
+ // negative seek from end position -> clamp to 0
+ mu_check(!stream_seek(stream, -9000, StreamOffsetFromEnd));
+ mu_check(stream_tell(stream) == 0);
+
+ // clean stream
+ stream_clean(stream);
+ mu_check(stream_size(stream) == 0);
+ mu_check(stream_eof(stream));
+ mu_check(stream_tell(stream) == 0);
+
+ // write format
+ // "" -> "dio666"
+ mu_check(stream_write_format(stream, "%s%d", "dio", 666) == 6);
+ mu_check(stream_size(stream) == 6);
+ mu_check(stream_eof(stream));
+ mu_check(stream_tell(stream) == 6);
+
+ // read data
+ memset(data, 0, data_size);
+ stream_rewind(stream);
+ mu_check(stream_read(stream, data, data_size) == 6);
+ mu_check(strcmp((char*)data, "dio666") == 0);
+
+ // clean and write cstring
+ // "dio666" -> "" -> "1234567890"
+ stream_clean(stream);
+ mu_check(stream_write_cstring(stream, "1234567890") == 10);
+
+ // delete 4 bytes from 1 pos
+ // "1xxxx67890" -> "167890"
+ mu_check(stream_seek(stream, 1, StreamOffsetFromStart));
+ mu_check(stream_delete(stream, 4));
+ mu_assert_int_eq(6, stream_size(stream));
+
+ // read data
+ memset(data, 0, data_size);
+ stream_rewind(stream);
+ mu_assert_int_eq(6, stream_read(stream, data, data_size));
+ mu_check(strcmp((char*)data, "167890") == 0);
+
+ // write cstring
+ // "167890" -> "167890It Was Me, Dio!"
+ mu_check(stream_write_cstring(stream, "It Was Me, Dio!") == 15);
+
+ // delete 1337 bytes from 1 pos
+ // and check that we can delete only 20 bytes
+ // "1xxxxxxxxxxxxxxxxxxxx" -> "1"
+ mu_check(stream_seek(stream, 1, StreamOffsetFromStart));
+ mu_check(stream_delete(stream, 1337));
+ mu_assert_int_eq(1, stream_size(stream));
+
+ // read data
+ memset(data, 0, data_size);
+ stream_rewind(stream);
+ mu_check(stream_read(stream, data, data_size) == 1);
+ mu_check(strcmp((char*)data, "1") == 0);
+
+ // write cstring from 0 pos, replacing 1 byte
+ // "1" -> "Oh? You're roaching me?"
+ mu_check(stream_rewind(stream));
+ mu_assert_int_eq(23, stream_write_cstring(stream, "Oh? You're roaching me?"));
+
+ // insert 11 bytes to 0 pos
+ // "Oh? You're roaching me?" -> "Za Warudo! Oh? You're roaching me?"
+ mu_check(stream_rewind(stream));
+ mu_check(stream_insert(stream, (uint8_t*)"Za Warudo! ", 11));
+ mu_assert_int_eq(34, stream_size(stream));
+
+ // read data
+ memset(data, 0, data_size);
+ stream_rewind(stream);
+ mu_assert_int_eq(34, stream_read(stream, data, data_size));
+ mu_assert_string_eq("Za Warudo! Oh? You're roaching me?", (char*)data);
+
+ // insert cstring to 22 pos
+ // "Za Warudo! Oh? You're roaching me?" -> "Za Warudo! Oh? You're approaching me?"
+ mu_check(stream_seek(stream, 22, StreamOffsetFromStart));
+ mu_check(stream_insert_cstring(stream, "app"));
+ mu_assert_int_eq(37, stream_size(stream));
+
+ // read data
+ memset(data, 0, data_size);
+ stream_rewind(stream);
+ mu_assert_int_eq(37, stream_read(stream, data, data_size));
+ mu_assert_string_eq("Za Warudo! Oh? You're approaching me?", (char*)data);
+
+ // insert cstring to the end of the stream
+ // "Za Warudo! Oh? You're approaching me?" -> "Za Warudo! Oh? You're approaching me? It was me, Dio!"
+ mu_check(stream_seek(stream, 0, StreamOffsetFromEnd));
+ mu_check(stream_insert_cstring(stream, " It was me, Dio!"));
+ mu_assert_int_eq(53, stream_size(stream));
+
+ // read data
+ memset(data, 0, data_size);
+ stream_rewind(stream);
+ mu_assert_int_eq(53, stream_read(stream, data, data_size));
+ mu_assert_string_eq("Za Warudo! Oh? You're approaching me? It was me, Dio!", (char*)data);
+
+ // delete 168430090 bytes from stream
+ // and test that we can delete only 53
+ mu_check(stream_rewind(stream));
+ mu_check(stream_delete(stream, 0x0A0A0A0A));
+ mu_assert_int_eq(0, stream_size(stream));
+ mu_check(stream_eof(stream));
+ mu_assert_int_eq(0, stream_tell(stream));
+
+ // clean stream
+ stream_clean(stream);
+ mu_assert_int_eq(0, stream_size(stream));
+ mu_check(stream_eof(stream));
+ mu_assert_int_eq(0, stream_tell(stream));
+
+ // insert formated string at the end of stream
+ // "" -> "dio666"
+ mu_check(stream_insert_format(stream, "%s%d", "dio", 666));
+ mu_assert_int_eq(6, stream_size(stream));
+ mu_check(stream_eof(stream));
+ mu_assert_int_eq(6, stream_tell(stream));
+
+ // insert formated string at the end of stream
+ // "dio666" -> "dio666zlo555"
+ mu_check(stream_insert_format(stream, "%s%d", "zlo", 555));
+ mu_assert_int_eq(12, stream_size(stream));
+ mu_check(stream_eof(stream));
+ mu_assert_int_eq(12, stream_tell(stream));
+
+ // insert formated string at the 6 pos
+ // "dio666" -> "dio666baba13zlo555"
+ mu_check(stream_seek(stream, 6, StreamOffsetFromStart));
+ mu_check(stream_insert_format(stream, "%s%d", "baba", 13));
+ mu_assert_int_eq(18, stream_size(stream));
+ mu_assert_int_eq(12, stream_tell(stream));
+
+ // read data
+ memset(data, 0, data_size);
+ stream_rewind(stream);
+ mu_assert_int_eq(18, stream_read(stream, data, data_size));
+ mu_assert_string_eq("dio666baba13zlo555", (char*)data);
+
+ // delete 6 chars from pos 6 and insert 1 chars
+ // "dio666baba13zlo555" -> "dio666xzlo555"
+ mu_check(stream_seek(stream, 6, StreamOffsetFromStart));
+ mu_check(stream_delete_and_insert_char(stream, 6, 'x'));
+ mu_assert_int_eq(13, stream_size(stream));
+ mu_assert_int_eq(7, stream_tell(stream));
+
+ // read data
+ memset(data, 0, data_size);
+ stream_rewind(stream);
+ mu_check(stream_read(stream, data, data_size) == 13);
+ mu_assert_string_eq("dio666xzlo555", (char*)data);
+
+ // delete 9000 chars from pos 6 and insert 3 chars from string
+ // "dio666xzlo555" -> "dio666777"
+ mu_check(stream_seek(stream, 6, StreamOffsetFromStart));
+ mu_check(stream_delete_and_insert_cstring(stream, 9000, "777"));
+ mu_assert_int_eq(9, stream_size(stream));
+ mu_assert_int_eq(9, stream_tell(stream));
+ mu_check(stream_eof(stream));
+
+ string_clear(string_lee);
+}
+
+MU_TEST(stream_composite_test) {
+ // test string stream
+ Stream* stream;
+ stream = string_stream_alloc();
+ MU_RUN_TEST_1(stream_composite_subtest, stream);
+ stream_free(stream);
+
+ // test file stream
+ Storage* storage = furi_record_open("storage");
+ stream = file_stream_alloc(storage);
+ mu_check(file_stream_open(stream, "/ext/filestream.str", FSAM_READ_WRITE, FSOM_CREATE_ALWAYS));
+ MU_RUN_TEST_1(stream_composite_subtest, stream);
+ stream_free(stream);
+ furi_record_close("storage");
+}
+
+MU_TEST_1(stream_write_subtest, Stream* stream) {
+ mu_assert_int_eq(strlen(stream_test_data), stream_write_cstring(stream, stream_test_data));
+}
+
+MU_TEST_1(stream_read_subtest, Stream* stream) {
+ uint8_t data[256] = {0};
+ mu_check(stream_rewind(stream));
+ mu_assert_int_eq(strlen(stream_test_data), stream_read(stream, data, 256));
+ mu_assert_string_eq(stream_test_data, (const char*)data);
+}
+
+MU_TEST(stream_write_read_save_load_test) {
+ Stream* stream_orig = string_stream_alloc();
+ Stream* stream_copy = string_stream_alloc();
+ Storage* storage = furi_record_open("storage");
+
+ // write, read
+ MU_RUN_TEST_1(stream_write_subtest, stream_orig);
+ MU_RUN_TEST_1(stream_read_subtest, stream_orig);
+
+ // copy, read
+ mu_assert_int_eq(strlen(stream_test_data), stream_copy_full(stream_orig, stream_copy));
+ MU_RUN_TEST_1(stream_read_subtest, stream_orig);
+
+ // save to file
+ mu_check(stream_seek(stream_orig, 0, StreamOffsetFromStart));
+ mu_assert_int_eq(
+ strlen(stream_test_data),
+ stream_save_to_file(stream_orig, storage, "/ext/filestream.str", FSOM_CREATE_ALWAYS));
+
+ stream_free(stream_copy);
+ stream_free(stream_orig);
+
+ // load from file, read
+ Stream* stream_new = string_stream_alloc();
+ mu_assert_int_eq(
+ strlen(stream_test_data),
+ stream_load_from_file(stream_new, storage, "/ext/filestream.str"));
+ MU_RUN_TEST_1(stream_read_subtest, stream_new);
+ stream_free(stream_new);
+
+ furi_record_close("storage");
+}
+
+MU_TEST_1(stream_split_subtest, Stream* stream) {
+ stream_clean(stream);
+ stream_write_cstring(stream, stream_test_left_data);
+ stream_write_cstring(stream, stream_test_right_data);
+
+ Stream* stream_left = string_stream_alloc();
+ Stream* stream_right = string_stream_alloc();
+
+ mu_check(stream_seek(stream, strlen(stream_test_left_data), StreamOffsetFromStart));
+ mu_check(stream_split(stream, stream_left, stream_right));
+
+ uint8_t data[256] = {0};
+ mu_check(stream_rewind(stream_left));
+ mu_assert_int_eq(strlen(stream_test_left_data), stream_read(stream_left, data, 256));
+ mu_assert_string_eq(stream_test_left_data, (const char*)data);
+
+ mu_check(stream_rewind(stream_right));
+ mu_assert_int_eq(strlen(stream_test_right_data), stream_read(stream_right, data, 256));
+ mu_assert_string_eq(stream_test_right_data, (const char*)data);
+
+ stream_free(stream_right);
+ stream_free(stream_left);
+}
+
+MU_TEST(stream_split_test) {
+ // test string stream
+ Stream* stream;
+ stream = string_stream_alloc();
+ MU_RUN_TEST_1(stream_split_subtest, stream);
+ stream_free(stream);
+
+ // test file stream
+ Storage* storage = furi_record_open("storage");
+ stream = file_stream_alloc(storage);
+ mu_check(file_stream_open(stream, "/ext/filestream.str", FSAM_READ_WRITE, FSOM_CREATE_ALWAYS));
+ MU_RUN_TEST_1(stream_split_subtest, stream);
+ stream_free(stream);
+ furi_record_close("storage");
+}
+
+MU_TEST_SUITE(stream_suite) {
+ MU_RUN_TEST(stream_write_read_save_load_test);
+ MU_RUN_TEST(stream_composite_test);
+ MU_RUN_TEST(stream_split_test);
+}
+
+int run_minunit_test_stream() {
+ MU_RUN_SUITE(stream_suite);
+ return MU_EXIT_CODE;
+} \ No newline at end of file
diff --git a/applications/tests/test_index.c b/applications/tests/test_index.c
index 3c70969f..6f934318 100644
--- a/applications/tests/test_index.c
+++ b/applications/tests/test_index.c
@@ -13,7 +13,9 @@
int run_minunit();
int run_minunit_test_irda_decoder_encoder();
int run_minunit_test_rpc();
-int run_minunit_test_flipper_file();
+int run_minunit_test_flipper_format();
+int run_minunit_test_flipper_format_string();
+int run_minunit_test_stream();
void minunit_print_progress(void) {
static char progress[] = {'\\', '|', '/', '-'};
@@ -27,7 +29,7 @@ void minunit_print_progress(void) {
}
void minunit_print_fail(const char* str) {
- printf("%s\n", str);
+ printf(FURI_LOG_CLR_E "%s\n" FURI_LOG_CLR_RESET, str);
}
void unit_tests_cli(Cli* cli, string_t args, void* context) {
@@ -53,7 +55,9 @@ void unit_tests_cli(Cli* cli, string_t args, void* context) {
test_result |= run_minunit();
test_result |= run_minunit_test_irda_decoder_encoder();
test_result |= run_minunit_test_rpc();
- test_result |= run_minunit_test_flipper_file();
+ test_result |= run_minunit_test_stream();
+ test_result |= run_minunit_test_flipper_format();
+ test_result |= run_minunit_test_flipper_format_string();
cycle_counter = (DWT->CYCCNT - cycle_counter);
FURI_LOG_I(TAG, "Consumed: %0.2fs", (float)cycle_counter / (SystemCoreClock));
diff --git a/applications/u2f/u2f.c b/applications/u2f/u2f.c
index 2a1286ef..051dca69 100644
--- a/applications/u2f/u2f.c
+++ b/applications/u2f/u2f.c
@@ -93,7 +93,7 @@ static int u2f_uecc_random(uint8_t* dest, unsigned size) {
}
U2fData* u2f_alloc() {
- return furi_alloc(sizeof(U2fData));
+ return malloc(sizeof(U2fData));
}
void u2f_free(U2fData* U2F) {
diff --git a/applications/u2f/u2f_app.c b/applications/u2f/u2f_app.c
index 9dde0f0d..88d86855 100644
--- a/applications/u2f/u2f_app.c
+++ b/applications/u2f/u2f_app.c
@@ -22,7 +22,7 @@ static void u2f_app_tick_event_callback(void* context) {
}
U2fApp* u2f_app_alloc() {
- U2fApp* app = furi_alloc(sizeof(U2fApp));
+ U2fApp* app = malloc(sizeof(U2fApp));
app->gui = furi_record_open("gui");
app->notifications = furi_record_open("notification");
diff --git a/applications/u2f/u2f_data.c b/applications/u2f/u2f_data.c
index e39eb95c..5143b27b 100644
--- a/applications/u2f/u2f_data.c
+++ b/applications/u2f/u2f_data.c
@@ -3,7 +3,7 @@
#include <furi_hal.h>
#include <storage/storage.h>
#include <furi_hal_random.h>
-#include <flipper_file.h>
+#include <flipper_format/flipper_format.h>
#define TAG "U2F"
@@ -147,22 +147,21 @@ static bool u2f_data_cert_key_encrypt(uint8_t* cert_key) {
furi_hal_crypto_store_unload_key(U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_UNIQUE);
Storage* storage = furi_record_open("storage");
- FlipperFile* flipper_file = flipper_file_alloc(storage);
+ FlipperFormat* flipper_format = flipper_format_file_alloc(storage);
- if(flipper_file_open_always(flipper_file, U2F_CERT_KEY_FILE)) {
+ if(flipper_format_file_open_always(flipper_format, U2F_CERT_KEY_FILE)) {
do {
- if(!flipper_file_write_header_cstr(
- flipper_file, U2F_CERT_KEY_FILE_TYPE, U2F_CERT_KEY_VERSION))
+ if(!flipper_format_write_header_cstr(
+ flipper_format, U2F_CERT_KEY_FILE_TYPE, U2F_CERT_KEY_VERSION))
break;
- if(!flipper_file_write_uint32(flipper_file, "Type", &cert_type, 1)) break;
- if(!flipper_file_write_hex(flipper_file, "IV", iv, 16)) break;
- if(!flipper_file_write_hex(flipper_file, "Data", key, 48)) break;
+ if(!flipper_format_write_uint32(flipper_format, "Type", &cert_type, 1)) break;
+ if(!flipper_format_write_hex(flipper_format, "IV", iv, 16)) break;
+ if(!flipper_format_write_hex(flipper_format, "Data", key, 48)) break;
state = true;
} while(0);
}
- flipper_file_close(flipper_file);
- flipper_file_free(flipper_file);
+ flipper_format_free(flipper_format);
furi_record_close("storage");
return state;
@@ -185,11 +184,11 @@ bool u2f_data_cert_key_load(uint8_t* cert_key) {
string_init(filetype);
Storage* storage = furi_record_open("storage");
- FlipperFile* flipper_file = flipper_file_alloc(storage);
+ FlipperFormat* flipper_format = flipper_format_file_alloc(storage);
- if(flipper_file_open_existing(flipper_file, U2F_CERT_KEY_FILE)) {
+ if(flipper_format_file_open_existing(flipper_format, U2F_CERT_KEY_FILE)) {
do {
- if(!flipper_file_read_header(flipper_file, filetype, &version)) {
+ if(!flipper_format_read_header(flipper_format, filetype, &version)) {
FURI_LOG_E(TAG, "Missing or incorrect header");
break;
}
@@ -200,7 +199,7 @@ bool u2f_data_cert_key_load(uint8_t* cert_key) {
break;
}
- if(!flipper_file_read_uint32(flipper_file, "Type", &cert_type, 1)) {
+ if(!flipper_format_read_uint32(flipper_format, "Type", &cert_type, 1)) {
FURI_LOG_E(TAG, "Missing cert type");
break;
}
@@ -216,12 +215,12 @@ bool u2f_data_cert_key_load(uint8_t* cert_key) {
break;
}
if(key_slot != 0) {
- if(!flipper_file_read_hex(flipper_file, "IV", iv, 16)) {
+ if(!flipper_format_read_hex(flipper_format, "IV", iv, 16)) {
FURI_LOG_E(TAG, "Missing IV");
break;
}
- if(!flipper_file_read_hex(flipper_file, "Data", key, 48)) {
+ if(!flipper_format_read_hex(flipper_format, "Data", key, 48)) {
FURI_LOG_E(TAG, "Missing data");
break;
}
@@ -239,7 +238,7 @@ bool u2f_data_cert_key_load(uint8_t* cert_key) {
}
furi_hal_crypto_store_unload_key(key_slot);
} else {
- if(!flipper_file_read_hex(flipper_file, "Data", cert_key, 32)) {
+ if(!flipper_format_read_hex(flipper_format, "Data", cert_key, 32)) {
FURI_LOG_E(TAG, "Missing data");
break;
}
@@ -248,8 +247,7 @@ bool u2f_data_cert_key_load(uint8_t* cert_key) {
} while(0);
}
- flipper_file_close(flipper_file);
- flipper_file_free(flipper_file);
+ flipper_format_free(flipper_format);
furi_record_close("storage");
string_clear(filetype);
@@ -272,11 +270,11 @@ bool u2f_data_key_load(uint8_t* device_key) {
string_init(filetype);
Storage* storage = furi_record_open("storage");
- FlipperFile* flipper_file = flipper_file_alloc(storage);
+ FlipperFormat* flipper_format = flipper_format_file_alloc(storage);
- if(flipper_file_open_existing(flipper_file, U2F_KEY_FILE)) {
+ if(flipper_format_file_open_existing(flipper_format, U2F_KEY_FILE)) {
do {
- if(!flipper_file_read_header(flipper_file, filetype, &version)) {
+ if(!flipper_format_read_header(flipper_format, filetype, &version)) {
FURI_LOG_E(TAG, "Missing or incorrect header");
break;
}
@@ -285,11 +283,11 @@ bool u2f_data_key_load(uint8_t* device_key) {
FURI_LOG_E(TAG, "Type or version mismatch");
break;
}
- if(!flipper_file_read_hex(flipper_file, "IV", iv, 16)) {
+ if(!flipper_format_read_hex(flipper_format, "IV", iv, 16)) {
FURI_LOG_E(TAG, "Missing IV");
break;
}
- if(!flipper_file_read_hex(flipper_file, "Data", key, 48)) {
+ if(!flipper_format_read_hex(flipper_format, "Data", key, 48)) {
FURI_LOG_E(TAG, "Missing data");
break;
}
@@ -307,8 +305,7 @@ bool u2f_data_key_load(uint8_t* device_key) {
state = true;
} while(0);
}
- flipper_file_close(flipper_file);
- flipper_file_free(flipper_file);
+ flipper_format_free(flipper_format);
furi_record_close("storage");
string_clear(filetype);
return state;
@@ -338,22 +335,21 @@ bool u2f_data_key_generate(uint8_t* device_key) {
furi_hal_crypto_store_unload_key(U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_UNIQUE);
Storage* storage = furi_record_open("storage");
- FlipperFile* flipper_file = flipper_file_alloc(storage);
+ FlipperFormat* flipper_format = flipper_format_file_alloc(storage);
- if(flipper_file_open_always(flipper_file, U2F_KEY_FILE)) {
+ if(flipper_format_file_open_always(flipper_format, U2F_KEY_FILE)) {
do {
- if(!flipper_file_write_header_cstr(
- flipper_file, U2F_DEVICE_KEY_FILE_TYPE, U2F_DEVICE_KEY_VERSION))
+ if(!flipper_format_write_header_cstr(
+ flipper_format, U2F_DEVICE_KEY_FILE_TYPE, U2F_DEVICE_KEY_VERSION))
break;
- if(!flipper_file_write_hex(flipper_file, "IV", iv, 16)) break;
- if(!flipper_file_write_hex(flipper_file, "Data", key_encrypted, 48)) break;
+ if(!flipper_format_write_hex(flipper_format, "IV", iv, 16)) break;
+ if(!flipper_format_write_hex(flipper_format, "Data", key_encrypted, 48)) break;
state = true;
memcpy(device_key, key, 32);
} while(0);
}
- flipper_file_close(flipper_file);
- flipper_file_free(flipper_file);
+ flipper_format_free(flipper_format);
furi_record_close("storage");
return state;
@@ -372,11 +368,11 @@ bool u2f_data_cnt_read(uint32_t* cnt_val) {
string_init(filetype);
Storage* storage = furi_record_open("storage");
- FlipperFile* flipper_file = flipper_file_alloc(storage);
+ FlipperFormat* flipper_format = flipper_format_file_alloc(storage);
- if(flipper_file_open_existing(flipper_file, U2F_CNT_FILE)) {
+ if(flipper_format_file_open_existing(flipper_format, U2F_CNT_FILE)) {
do {
- if(!flipper_file_read_header(flipper_file, filetype, &version)) {
+ if(!flipper_format_read_header(flipper_format, filetype, &version)) {
FURI_LOG_E(TAG, "Missing or incorrect header");
break;
}
@@ -385,11 +381,11 @@ bool u2f_data_cnt_read(uint32_t* cnt_val) {
FURI_LOG_E(TAG, "Type or version mismatch");
break;
}
- if(!flipper_file_read_hex(flipper_file, "IV", iv, 16)) {
+ if(!flipper_format_read_hex(flipper_format, "IV", iv, 16)) {
FURI_LOG_E(TAG, "Missing IV");
break;
}
- if(!flipper_file_read_hex(flipper_file, "Data", cnt_encr, 48)) {
+ if(!flipper_format_read_hex(flipper_format, "Data", cnt_encr, 48)) {
FURI_LOG_E(TAG, "Missing data");
break;
}
@@ -410,8 +406,7 @@ bool u2f_data_cnt_read(uint32_t* cnt_val) {
}
} while(0);
}
- flipper_file_close(flipper_file);
- flipper_file_free(flipper_file);
+ flipper_format_free(flipper_format);
furi_record_close("storage");
string_clear(filetype);
return state;
@@ -441,21 +436,20 @@ bool u2f_data_cnt_write(uint32_t cnt_val) {
furi_hal_crypto_store_unload_key(U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_UNIQUE);
Storage* storage = furi_record_open("storage");
- FlipperFile* flipper_file = flipper_file_alloc(storage);
+ FlipperFormat* flipper_format = flipper_format_file_alloc(storage);
- if(flipper_file_open_always(flipper_file, U2F_CNT_FILE)) {
+ if(flipper_format_file_open_always(flipper_format, U2F_CNT_FILE)) {
do {
- if(!flipper_file_write_header_cstr(
- flipper_file, U2F_COUNTER_FILE_TYPE, U2F_COUNTER_VERSION))
+ if(!flipper_format_write_header_cstr(
+ flipper_format, U2F_COUNTER_FILE_TYPE, U2F_COUNTER_VERSION))
break;
- if(!flipper_file_write_hex(flipper_file, "IV", iv, 16)) break;
- if(!flipper_file_write_hex(flipper_file, "Data", cnt_encr, 48)) break;
+ if(!flipper_format_write_hex(flipper_format, "IV", iv, 16)) break;
+ if(!flipper_format_write_hex(flipper_format, "Data", cnt_encr, 48)) break;
state = true;
} while(0);
}
- flipper_file_close(flipper_file);
- flipper_file_free(flipper_file);
+ flipper_format_free(flipper_format);
furi_record_close("storage");
return state;
diff --git a/applications/u2f/u2f_hid.c b/applications/u2f/u2f_hid.c
index 1ddfecaf..ff1109fe 100644
--- a/applications/u2f/u2f_hid.c
+++ b/applications/u2f/u2f_hid.c
@@ -277,7 +277,7 @@ static int32_t u2f_hid_worker(void* context) {
}
U2fHid* u2f_hid_start(U2fData* u2f_inst) {
- U2fHid* u2f_hid = furi_alloc(sizeof(U2fHid));
+ U2fHid* u2f_hid = malloc(sizeof(U2fHid));
u2f_hid->u2f_instance = u2f_inst;
diff --git a/applications/u2f/views/u2f_view.c b/applications/u2f/views/u2f_view.c
index 8a6f441a..d04c656d 100644
--- a/applications/u2f/views/u2f_view.c
+++ b/applications/u2f/views/u2f_view.c
@@ -59,7 +59,7 @@ static bool u2f_view_input_callback(InputEvent* event, void* context) {
}
U2fView* u2f_view_alloc() {
- U2fView* u2f = furi_alloc(sizeof(U2fView));
+ U2fView* u2f = malloc(sizeof(U2fView));
u2f->view = view_alloc();
view_allocate_model(u2f->view, ViewModelTypeLocking, sizeof(U2fModel));
diff --git a/core/furi/memmgr.c b/core/furi/memmgr.c
index 12146247..f7a24a76 100644
--- a/core/furi/memmgr.c
+++ b/core/furi/memmgr.c
@@ -20,26 +20,17 @@ void* realloc(void* ptr, size_t size) {
return NULL;
}
- void* p;
- p = pvPortMalloc(size);
- if(p) {
- // TODO implement secure realloc
- // insecure, but will do job in our case
- if(ptr != NULL) {
- memcpy(p, ptr, size);
- vPortFree(ptr);
- }
+ void* p = pvPortMalloc(size);
+ if(ptr != NULL) {
+ memcpy(p, ptr, size);
+ vPortFree(ptr);
}
+
return p;
}
void* calloc(size_t count, size_t size) {
- void* ptr = pvPortMalloc(count * size);
- if(ptr) {
- // zero the memory
- memset(ptr, 0, count * size);
- }
- return ptr;
+ return pvPortMalloc(count * size);
}
char* strdup(const char* s) {
@@ -49,13 +40,8 @@ char* strdup(const char* s) {
}
size_t siz = strlen(s) + 1;
- char* y = malloc(siz);
-
- if(y != NULL) {
- memcpy(y, s, siz);
- } else {
- return NULL;
- }
+ char* y = pvPortMalloc(siz);
+ memcpy(y, s, siz);
return y;
}
@@ -68,27 +54,18 @@ size_t memmgr_get_minimum_free_heap(void) {
return xPortGetMinimumEverFreeHeapSize();
}
-void* furi_alloc(size_t size) {
- void* p = malloc(size);
- furi_check(p);
- return memset(p, 0, size);
-}
-
void* __wrap__malloc_r(struct _reent* r, size_t size) {
- void* pointer = malloc(size);
- return pointer;
+ return pvPortMalloc(size);
}
void __wrap__free_r(struct _reent* r, void* ptr) {
- free(ptr);
+ vPortFree(ptr);
}
void* __wrap__calloc_r(struct _reent* r, size_t count, size_t size) {
- void* pointer = calloc(count, size);
- return pointer;
+ return calloc(count, size);
}
void* __wrap__realloc_r(struct _reent* r, void* ptr, size_t size) {
- void* pointer = realloc(ptr, size);
- return pointer;
-} \ No newline at end of file
+ return realloc(ptr, size);
+}
diff --git a/core/furi/memmgr.h b/core/furi/memmgr.h
index 7c8a3fe9..b749c8e5 100644
--- a/core/furi/memmgr.h
+++ b/core/furi/memmgr.h
@@ -29,16 +29,6 @@ size_t memmgr_get_free_heap(void);
*/
size_t memmgr_get_minimum_free_heap(void);
-/** Allocate memory from heap
- *
- * @note performs memset with 0, will crash system if not enough memory
- *
- * @param[in] size bytes to allocate
- *
- * @return pointer to allocated memory
- */
-void* furi_alloc(size_t size);
-
#ifdef __cplusplus
}
#endif
diff --git a/core/furi/memmgr_heap.c b/core/furi/memmgr_heap.c
index 3fe7822c..fef7a54b 100644
--- a/core/furi/memmgr_heap.c
+++ b/core/furi/memmgr_heap.c
@@ -38,6 +38,10 @@
#include "check.h"
#include <stdlib.h>
#include <cmsis_os2.h>
+#include <stm32wbxx.h>
+#include <furi_hal_console.h>
+#include <furi/common_defines.h>
+#include <furi_hal_task.h>
/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining
all the API functions to use the MPU wrappers. That should only be done when
@@ -235,23 +239,115 @@ void memmgr_heap_printf_free_blocks() {
//osKernelUnlock();
}
+
+#ifdef HEAP_PRINT_DEBUG
+char* ultoa(unsigned long num, char* str, int radix) {
+ char temp[33]; // at radix 2 the string is at most 32 + 1 null long.
+ int temp_loc = 0;
+ int digit;
+ int str_loc = 0;
+
+ //construct a backward string of the number.
+ do {
+ digit = (unsigned long)num % ((unsigned long)radix);
+ if(digit < 10)
+ temp[temp_loc++] = digit + '0';
+ else
+ temp[temp_loc++] = digit - 10 + 'A';
+ num = ((unsigned long)num) / ((unsigned long)radix);
+ } while((unsigned long)num > 0);
+
+ temp_loc--;
+
+ //now reverse the string.
+ while(temp_loc >= 0) { // while there are still chars
+ str[str_loc++] = temp[temp_loc--];
+ }
+ str[str_loc] = 0; // add null termination.
+
+ return str;
+}
+
+static void print_heap_init() {
+ char tmp_str[33];
+ size_t heap_start = (size_t)&__heap_start__;
+ size_t heap_end = (size_t)&__heap_end__;
+
+ // {PHStart|heap_start|heap_end}
+ FURI_CRITICAL_ENTER();
+ furi_hal_console_puts("{PHStart|");
+ ultoa(heap_start, tmp_str, 16);
+ furi_hal_console_puts(tmp_str);
+ furi_hal_console_puts("|");
+ ultoa(heap_end, tmp_str, 16);
+ furi_hal_console_puts(tmp_str);
+ furi_hal_console_puts("}\r\n");
+ FURI_CRITICAL_EXIT();
+}
+
+static void print_heap_malloc(void* ptr, size_t size) {
+ char tmp_str[33];
+ const char* name = osThreadGetName(osThreadGetId());
+
+ // {thread name|m|address|size}
+ FURI_CRITICAL_ENTER();
+ furi_hal_console_puts("{");
+ furi_hal_console_puts(name);
+ furi_hal_console_puts("|m|0x");
+ ultoa((unsigned long)ptr, tmp_str, 16);
+ furi_hal_console_puts(tmp_str);
+ furi_hal_console_puts("|");
+ utoa(size, tmp_str, 10);
+ furi_hal_console_puts(tmp_str);
+ furi_hal_console_puts("}\r\n");
+ FURI_CRITICAL_EXIT();
+}
+
+static void print_heap_free(void* ptr) {
+ char tmp_str[33];
+ const char* name = osThreadGetName(osThreadGetId());
+
+ // {thread name|f|address}
+ FURI_CRITICAL_ENTER();
+ furi_hal_console_puts("{");
+ furi_hal_console_puts(name);
+ furi_hal_console_puts("|f|0x");
+ ultoa((unsigned long)ptr, tmp_str, 16);
+ furi_hal_console_puts(tmp_str);
+ furi_hal_console_puts("}\r\n");
+ FURI_CRITICAL_EXIT();
+}
+#endif
/*-----------------------------------------------------------*/
void* pvPortMalloc(size_t xWantedSize) {
BlockLink_t *pxBlock, *pxPreviousBlock, *pxNewBlockLink;
void* pvReturn = NULL;
+ size_t to_wipe = xWantedSize;
- vTaskSuspendAll();
- {
- /* If this is the first call to malloc then the heap will require
+#ifdef HEAP_PRINT_DEBUG
+ BlockLink_t* print_heap_block = NULL;
+#endif
+
+ /* If this is the first call to malloc then the heap will require
initialisation to setup the list of free blocks. */
- if(pxEnd == NULL) {
+ if(pxEnd == NULL) {
+#ifdef HEAP_PRINT_DEBUG
+ print_heap_init();
+#endif
+
+ vTaskSuspendAll();
+ {
prvHeapInit();
memmgr_heap_init();
- } else {
- mtCOVERAGE_TEST_MARKER();
}
+ (void)xTaskResumeAll();
+ } else {
+ mtCOVERAGE_TEST_MARKER();
+ }
+ vTaskSuspendAll();
+ {
/* Check the requested block size is not so large that the top bit is
set. The top bit of the block size member of the BlockLink_t structure
is used to determine who owns the block - the application or the
@@ -330,6 +426,10 @@ void* pvPortMalloc(size_t xWantedSize) {
by the application and has no "next" block. */
pxBlock->xBlockSize |= xBlockAllocatedBit;
pxBlock->pxNextFreeBlock = NULL;
+
+#ifdef HEAP_PRINT_DEBUG
+ print_heap_block = pxBlock;
+#endif
} else {
mtCOVERAGE_TEST_MARKER();
}
@@ -344,6 +444,10 @@ void* pvPortMalloc(size_t xWantedSize) {
}
(void)xTaskResumeAll();
+#ifdef HEAP_PRINT_DEBUG
+ print_heap_malloc(print_heap_block, print_heap_block->xBlockSize & ~xBlockAllocatedBit);
+#endif
+
#if(configUSE_MALLOC_FAILED_HOOK == 1)
{
if(pvReturn == NULL) {
@@ -356,6 +460,9 @@ void* pvPortMalloc(size_t xWantedSize) {
#endif
configASSERT((((size_t)pvReturn) & (size_t)portBYTE_ALIGNMENT_MASK) == 0);
+
+ furi_check(pvReturn);
+ pvReturn = memset(pvReturn, 0, to_wipe);
return pvReturn;
}
/*-----------------------------------------------------------*/
@@ -382,8 +489,17 @@ void vPortFree(void* pv) {
allocated. */
pxLink->xBlockSize &= ~xBlockAllocatedBit;
+#ifdef HEAP_PRINT_DEBUG
+ print_heap_free(pxLink);
+#endif
+
vTaskSuspendAll();
{
+ furi_assert((size_t)pv >= SRAM_BASE);
+ furi_assert((size_t)pv < SRAM_BASE + 1024 * 256);
+ furi_assert((pxLink->xBlockSize - xHeapStructSize) < 1024 * 256);
+ furi_assert((int32_t)(pxLink->xBlockSize - xHeapStructSize) >= 0);
+
/* Add this block to the list of free blocks. */
xFreeBytesRemaining += pxLink->xBlockSize;
traceFREE(pv, pxLink->xBlockSize);
@@ -397,6 +513,10 @@ void vPortFree(void* pv) {
} else {
mtCOVERAGE_TEST_MARKER();
}
+ } else {
+#ifdef HEAP_PRINT_DEBUG
+ print_heap_free(pv);
+#endif
}
}
/*-----------------------------------------------------------*/
diff --git a/core/furi/pubsub.c b/core/furi/pubsub.c
index 3fbcb51c..8e9adda8 100644
--- a/core/furi/pubsub.c
+++ b/core/furi/pubsub.c
@@ -18,7 +18,7 @@ struct FuriPubSub {
};
FuriPubSub* furi_pubsub_alloc() {
- FuriPubSub* pubsub = furi_alloc(sizeof(FuriPubSub));
+ FuriPubSub* pubsub = malloc(sizeof(FuriPubSub));
pubsub->mutex = osMutexNew(NULL);
furi_assert(pubsub->mutex);
diff --git a/core/furi/record.c b/core/furi/record.c
index fe75c7bc..501091d4 100644
--- a/core/furi/record.c
+++ b/core/furi/record.c
@@ -24,7 +24,7 @@ typedef struct {
static FuriRecord* furi_record = NULL;
void furi_record_init() {
- furi_record = furi_alloc(sizeof(FuriRecord));
+ furi_record = malloc(sizeof(FuriRecord));
furi_record->mutex = osMutexNew(NULL);
furi_check(furi_record->mutex);
FuriRecordDataDict_init(furi_record->records);
diff --git a/core/furi/stdglue.c b/core/furi/stdglue.c
index 575350d6..52fb3fd9 100644
--- a/core/furi/stdglue.c
+++ b/core/furi/stdglue.c
@@ -67,7 +67,7 @@ static ssize_t stdout_write(void* _cookie, const char* data, size_t size) {
}
void furi_stdglue_init() {
- furi_stdglue = furi_alloc(sizeof(FuriStdglue));
+ furi_stdglue = malloc(sizeof(FuriStdglue));
// Init outputs structures
furi_stdglue->mutex = osMutexNew(NULL);
furi_check(furi_stdglue->mutex);
diff --git a/core/furi/thread.c b/core/furi/thread.c
index 20e3b252..de86cbdc 100644
--- a/core/furi/thread.c
+++ b/core/furi/thread.c
@@ -56,7 +56,7 @@ void furi_thread_body(void* context) {
}
FuriThread* furi_thread_alloc() {
- FuriThread* thread = furi_alloc(sizeof(FuriThread));
+ FuriThread* thread = malloc(sizeof(FuriThread));
return thread;
}
diff --git a/firmware/targets/f6/Src/main.c b/firmware/targets/f6/Src/main.c
index b1ab4dcd..a265c4c1 100644
--- a/firmware/targets/f6/Src/main.c
+++ b/firmware/targets/f6/Src/main.c
@@ -7,6 +7,9 @@
#define TAG "Main"
int main(void) {
+ // Flipper critical FURI HAL
+ furi_hal_init_critical();
+
// Initialize FURI layer
furi_init();
diff --git a/firmware/targets/f6/ble_glue/battery_service.c b/firmware/targets/f6/ble_glue/battery_service.c
index fcf640c8..1ee155bb 100644
--- a/firmware/targets/f6/ble_glue/battery_service.c
+++ b/firmware/targets/f6/ble_glue/battery_service.c
@@ -17,7 +17,7 @@ static const uint16_t service_uuid = BATTERY_SERVICE_UUID;
static const uint16_t char_battery_level_uuid = BATTERY_LEVEL_CHAR_UUID;
void battery_svc_start() {
- battery_svc = furi_alloc(sizeof(BatterySvc));
+ battery_svc = malloc(sizeof(BatterySvc));
tBleStatus status;
// Add Battery service
diff --git a/firmware/targets/f6/ble_glue/ble_app.c b/firmware/targets/f6/ble_glue/ble_app.c
index 6afd3648..052b3a9f 100644
--- a/firmware/targets/f6/ble_glue/ble_app.c
+++ b/firmware/targets/f6/ble_glue/ble_app.c
@@ -35,7 +35,7 @@ static void ble_app_hci_status_not_handler(HCI_TL_CmdStatus_t status);
bool ble_app_init() {
SHCI_CmdStatus_t status;
- ble_app = furi_alloc(sizeof(BleApp));
+ ble_app = malloc(sizeof(BleApp));
// Allocate semafore and mutex for ble command buffer access
ble_app->hci_mtx = osMutexNew(NULL);
ble_app->hci_sem = osSemaphoreNew(1, 0, NULL);
diff --git a/firmware/targets/f6/ble_glue/ble_glue.c b/firmware/targets/f6/ble_glue/ble_glue.c
index 4c26e086..a509a96e 100644
--- a/firmware/targets/f6/ble_glue/ble_glue.c
+++ b/firmware/targets/f6/ble_glue/ble_glue.c
@@ -64,7 +64,7 @@ void ble_glue_set_key_storage_changed_callback(
}
void ble_glue_init() {
- ble_glue = furi_alloc(sizeof(BleGlue));
+ ble_glue = malloc(sizeof(BleGlue));
ble_glue->status = BleGlueStatusStartup;
// Configure the system Power Mode
diff --git a/firmware/targets/f6/ble_glue/dev_info_service.c b/firmware/targets/f6/ble_glue/dev_info_service.c
index 1c9b94eb..80d7b0eb 100644
--- a/firmware/targets/f6/ble_glue/dev_info_service.c
+++ b/firmware/targets/f6/ble_glue/dev_info_service.c
@@ -23,7 +23,7 @@ static const char dev_info_software_rev_num[] = GIT_COMMIT " " GIT_BRANCH " " GI
" " BUILD_DATE;
void dev_info_svc_start() {
- dev_info_svc = furi_alloc(sizeof(DevInfoSvc));
+ dev_info_svc = malloc(sizeof(DevInfoSvc));
tBleStatus status;
// Add Device Information Service
diff --git a/firmware/targets/f6/ble_glue/gap.c b/firmware/targets/f6/ble_glue/gap.c
index 1bd0cbbf..d1b1b766 100755
--- a/firmware/targets/f6/ble_glue/gap.c
+++ b/firmware/targets/f6/ble_glue/gap.c
@@ -463,7 +463,7 @@ bool gap_init(GapConfig* config, GapEventCallback on_event_cb, void* context) {
return false;
}
- gap = furi_alloc(sizeof(Gap));
+ gap = malloc(sizeof(Gap));
gap->config = config;
srand(DWT->CYCCNT);
// Create advertising timer
@@ -516,7 +516,7 @@ GapState gap_get_state() {
void gap_start_scan(GapScanCallback callback, void* context) {
furi_assert(callback);
- gap_scan = furi_alloc(sizeof(GapScan));
+ gap_scan = malloc(sizeof(GapScan));
gap_scan->callback = callback;
gap_scan->context = context;
// Scan interval 250 ms
diff --git a/firmware/targets/f6/ble_glue/hid_service.c b/firmware/targets/f6/ble_glue/hid_service.c
index ec8854e6..e30cdcb0 100644
--- a/firmware/targets/f6/ble_glue/hid_service.c
+++ b/firmware/targets/f6/ble_glue/hid_service.c
@@ -38,7 +38,7 @@ static SVCCTL_EvtAckStatus_t hid_svc_event_handler(void* event) {
void hid_svc_start() {
tBleStatus status;
- hid_svc = furi_alloc(sizeof(HIDSvc));
+ hid_svc = malloc(sizeof(HIDSvc));
Service_UUID_t svc_uuid = {};
Char_Desc_Uuid_t desc_uuid = {};
Char_UUID_t char_uuid = {};
diff --git a/firmware/targets/f6/ble_glue/serial_service.c b/firmware/targets/f6/ble_glue/serial_service.c
index 4acba7f0..a5d3b97a 100644
--- a/firmware/targets/f6/ble_glue/serial_service.c
+++ b/firmware/targets/f6/ble_glue/serial_service.c
@@ -82,7 +82,7 @@ static SVCCTL_EvtAckStatus_t serial_svc_event_handler(void* event) {
void serial_svc_start() {
tBleStatus status;
- serial_svc = furi_alloc(sizeof(SerialSvc));
+ serial_svc = malloc(sizeof(SerialSvc));
// Register event handler
SVCCTL_RegisterSvcHandler(serial_svc_event_handler);
diff --git a/firmware/targets/f6/fatfs/stm32_adafruit_sd.c b/firmware/targets/f6/fatfs/stm32_adafruit_sd.c
index b97b95c8..9225a90b 100644
--- a/firmware/targets/f6/fatfs/stm32_adafruit_sd.c
+++ b/firmware/targets/f6/fatfs/stm32_adafruit_sd.c
@@ -435,7 +435,7 @@ uint8_t
goto error;
}
- ptr = furi_alloc(sizeof(uint8_t) * BlockSize);
+ ptr = malloc(sizeof(uint8_t) * BlockSize);
if(ptr == NULL) {
goto error;
}
@@ -516,7 +516,7 @@ uint8_t BSP_SD_WriteBlocks(
goto error;
}
- ptr = furi_alloc(sizeof(uint8_t) * BlockSize);
+ ptr = malloc(sizeof(uint8_t) * BlockSize);
if(ptr == NULL) {
goto error;
}
diff --git a/firmware/targets/f6/furi_hal/furi_hal.c b/firmware/targets/f6/furi_hal/furi_hal.c
index 082956b1..2821182c 100644
--- a/firmware/targets/f6/furi_hal/furi_hal.c
+++ b/firmware/targets/f6/furi_hal/furi_hal.c
@@ -11,9 +11,7 @@
#define TAG "FuriHal"
void furi_hal_init() {
- furi_hal_clock_init();
furi_hal_rtc_init();
- furi_hal_console_init();
furi_hal_interrupt_init();
furi_hal_delay_init();
@@ -71,3 +69,8 @@ void furi_hal_init() {
LL_MPU_INSTRUCTION_ACCESS_ENABLE);
LL_MPU_Enable(LL_MPU_CTRL_PRIVILEGED_DEFAULT);
}
+
+void furi_hal_init_critical() {
+ furi_hal_clock_init();
+ furi_hal_console_init();
+} \ No newline at end of file
diff --git a/firmware/targets/f6/furi_hal/furi_hal_bt_hid.c b/firmware/targets/f6/furi_hal/furi_hal_bt_hid.c
index 6b7128d8..507dedfb 100644
--- a/firmware/targets/f6/furi_hal/furi_hal_bt_hid.c
+++ b/firmware/targets/f6/furi_hal/furi_hal_bt_hid.c
@@ -147,8 +147,8 @@ void furi_hal_bt_hid_start() {
hid_svc_start();
}
// Configure HID Keyboard
- kb_report = furi_alloc(sizeof(FuriHalBtHidKbReport));
- media_report = furi_alloc(sizeof(FuriHalBtHidMediaReport));
+ kb_report = malloc(sizeof(FuriHalBtHidKbReport));
+ media_report = malloc(sizeof(FuriHalBtHidMediaReport));
// Configure Report Map characteristic
hid_svc_update_report_map(
furi_hal_bt_hid_report_map_data, sizeof(furi_hal_bt_hid_report_map_data));
diff --git a/firmware/targets/f6/furi_hal/furi_hal_compress.c b/firmware/targets/f6/furi_hal/furi_hal_compress.c
index d0efb143..7e31dbbf 100644
--- a/firmware/targets/f6/furi_hal/furi_hal_compress.c
+++ b/firmware/targets/f6/furi_hal/furi_hal_compress.c
@@ -41,7 +41,7 @@ static void furi_hal_compress_reset(FuriHalCompress* compress) {
}
void furi_hal_compress_icon_init() {
- icon_decoder = furi_alloc(sizeof(FuriHalCompressIcon));
+ icon_decoder = malloc(sizeof(FuriHalCompressIcon));
icon_decoder->decoder = heatshrink_decoder_alloc(
icon_decoder->compress_buff,
FURI_HAL_COMPRESS_ICON_ENCODED_BUFF_SIZE,
@@ -84,8 +84,8 @@ void furi_hal_compress_icon_decode(const uint8_t* icon_data, uint8_t** decoded_b
}
FuriHalCompress* furi_hal_compress_alloc(uint16_t compress_buff_size) {
- FuriHalCompress* compress = furi_alloc(sizeof(FuriHalCompress));
- compress->compress_buff = furi_alloc(compress_buff_size + FURI_HAL_COMPRESS_EXP_BUFF_SIZE);
+ FuriHalCompress* compress = malloc(sizeof(FuriHalCompress));
+ compress->compress_buff = malloc(compress_buff_size + FURI_HAL_COMPRESS_EXP_BUFF_SIZE);
compress->encoder = heatshrink_encoder_alloc(
compress->compress_buff,
FURI_HAL_COMPRESS_EXP_BUFF_SIZE_LOG,
diff --git a/firmware/targets/f6/furi_hal/furi_hal_console.c b/firmware/targets/f6/furi_hal/furi_hal_console.c
index dd51716f..f3cf06da 100644
--- a/firmware/targets/f6/furi_hal/furi_hal_console.c
+++ b/firmware/targets/f6/furi_hal/furi_hal_console.c
@@ -12,15 +12,17 @@
#define TAG "FuriHalConsole"
+#ifdef HEAP_PRINT_DEBUG
+#define CONSOLE_BAUDRATE 1843200
+#else
#define CONSOLE_BAUDRATE 230400
+#endif
volatile bool furi_hal_console_alive = false;
void furi_hal_console_init() {
furi_hal_uart_init(FuriHalUartIdUSART1, CONSOLE_BAUDRATE);
furi_hal_console_alive = true;
-
- FURI_LOG_I(TAG, "Init OK");
}
void furi_hal_console_enable() {
diff --git a/firmware/targets/f6/furi_hal/furi_hal_irda.c b/firmware/targets/f6/furi_hal/furi_hal_irda.c
index cd984741..6fe051a9 100644
--- a/firmware/targets/f6/furi_hal/furi_hal_irda.c
+++ b/firmware/targets/f6/furi_hal/furi_hal_irda.c
@@ -588,13 +588,13 @@ void furi_hal_irda_async_tx_start(uint32_t freq, float duty_cycle) {
furi_assert(irda_tim_tx.buffer[1].polarity == NULL);
size_t alloc_size_data = IRDA_TIM_TX_DMA_BUFFER_SIZE * sizeof(uint16_t);
- irda_tim_tx.buffer[0].data = furi_alloc(alloc_size_data);
- irda_tim_tx.buffer[1].data = furi_alloc(alloc_size_data);
+ irda_tim_tx.buffer[0].data = malloc(alloc_size_data);
+ irda_tim_tx.buffer[1].data = malloc(alloc_size_data);
size_t alloc_size_polarity =
(IRDA_TIM_TX_DMA_BUFFER_SIZE + IRDA_POLARITY_SHIFT) * sizeof(uint8_t);
- irda_tim_tx.buffer[0].polarity = furi_alloc(alloc_size_polarity);
- irda_tim_tx.buffer[1].polarity = furi_alloc(alloc_size_polarity);
+ irda_tim_tx.buffer[0].polarity = malloc(alloc_size_polarity);
+ irda_tim_tx.buffer[1].polarity = malloc(alloc_size_polarity);
irda_tim_tx.stop_semaphore = osSemaphoreNew(1, 0, NULL);
irda_tim_tx.cycle_duration = 1000000.0 / freq;
diff --git a/firmware/targets/f6/furi_hal/furi_hal_subghz.c b/firmware/targets/f6/furi_hal/furi_hal_subghz.c
index e2de0038..8dacd3f0 100644
--- a/firmware/targets/f6/furi_hal/furi_hal_subghz.c
+++ b/firmware/targets/f6/furi_hal/furi_hal_subghz.c
@@ -874,7 +874,7 @@ bool furi_hal_subghz_start_async_tx(FuriHalSubGhzAsyncTxCallback callback, void*
furi_hal_subghz_async_tx.duty_high = 0;
furi_hal_subghz_async_tx.buffer =
- furi_alloc(API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL * sizeof(uint32_t));
+ malloc(API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL * sizeof(uint32_t));
furi_hal_subghz_async_tx_refill(
furi_hal_subghz_async_tx.buffer, API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL);
diff --git a/firmware/targets/f6/furi_hal/furi_hal_usb_cdc.c b/firmware/targets/f6/furi_hal/furi_hal_usb_cdc.c
index d7fcbc58..bf0fd7d4 100644
--- a/firmware/targets/f6/furi_hal/furi_hal_usb_cdc.c
+++ b/firmware/targets/f6/furi_hal/furi_hal_usb_cdc.c
@@ -434,14 +434,14 @@ static void cdc_init(usbd_device* dev, FuriHalUsbInterface* intf) {
char* name = (char*)furi_hal_version_get_device_name_ptr();
uint8_t len = (name == NULL) ? (0) : (strlen(name));
- struct usb_string_descriptor* dev_prod_desc = furi_alloc(len * 2 + 2);
+ struct usb_string_descriptor* dev_prod_desc = malloc(len * 2 + 2);
dev_prod_desc->bLength = len * 2 + 2;
dev_prod_desc->bDescriptorType = USB_DTYPE_STRING;
for(uint8_t i = 0; i < len; i++) dev_prod_desc->wString[i] = name[i];
name = (char*)furi_hal_version_get_name_ptr();
len = (name == NULL) ? (0) : (strlen(name));
- struct usb_string_descriptor* dev_serial_desc = furi_alloc((len + 5) * 2 + 2);
+ struct usb_string_descriptor* dev_serial_desc = malloc((len + 5) * 2 + 2);
dev_serial_desc->bLength = (len + 5) * 2 + 2;
dev_serial_desc->bDescriptorType = USB_DTYPE_STRING;
memcpy(dev_serial_desc->wString, "f\0l\0i\0p\0_\0", 5 * 2);
diff --git a/firmware/targets/f6/furi_hal/furi_hal_vcp.c b/firmware/targets/f6/furi_hal/furi_hal_vcp.c
index 409a61a0..828fc619 100644
--- a/firmware/targets/f6/furi_hal/furi_hal_vcp.c
+++ b/firmware/targets/f6/furi_hal/furi_hal_vcp.c
@@ -58,7 +58,7 @@ static const uint8_t ascii_soh = 0x01;
static const uint8_t ascii_eot = 0x04;
void furi_hal_vcp_init() {
- vcp = furi_alloc(sizeof(FuriHalVcp));
+ vcp = malloc(sizeof(FuriHalVcp));
vcp->connected = false;
vcp->tx_stream = xStreamBufferCreate(VCP_TX_BUF_SIZE, 1);
diff --git a/firmware/targets/f7/Src/main.c b/firmware/targets/f7/Src/main.c
index b1ab4dcd..a265c4c1 100644
--- a/firmware/targets/f7/Src/main.c
+++ b/firmware/targets/f7/Src/main.c
@@ -7,6 +7,9 @@
#define TAG "Main"
int main(void) {
+ // Flipper critical FURI HAL
+ furi_hal_init_critical();
+
// Initialize FURI layer
furi_init();
diff --git a/firmware/targets/f7/ble_glue/battery_service.c b/firmware/targets/f7/ble_glue/battery_service.c
index fcf640c8..1ee155bb 100644
--- a/firmware/targets/f7/ble_glue/battery_service.c
+++ b/firmware/targets/f7/ble_glue/battery_service.c
@@ -17,7 +17,7 @@ static const uint16_t service_uuid = BATTERY_SERVICE_UUID;
static const uint16_t char_battery_level_uuid = BATTERY_LEVEL_CHAR_UUID;
void battery_svc_start() {
- battery_svc = furi_alloc(sizeof(BatterySvc));
+ battery_svc = malloc(sizeof(BatterySvc));
tBleStatus status;
// Add Battery service
diff --git a/firmware/targets/f7/ble_glue/ble_app.c b/firmware/targets/f7/ble_glue/ble_app.c
index 6afd3648..052b3a9f 100644
--- a/firmware/targets/f7/ble_glue/ble_app.c
+++ b/firmware/targets/f7/ble_glue/ble_app.c
@@ -35,7 +35,7 @@ static void ble_app_hci_status_not_handler(HCI_TL_CmdStatus_t status);
bool ble_app_init() {
SHCI_CmdStatus_t status;
- ble_app = furi_alloc(sizeof(BleApp));
+ ble_app = malloc(sizeof(BleApp));
// Allocate semafore and mutex for ble command buffer access
ble_app->hci_mtx = osMutexNew(NULL);
ble_app->hci_sem = osSemaphoreNew(1, 0, NULL);
diff --git a/firmware/targets/f7/ble_glue/ble_glue.c b/firmware/targets/f7/ble_glue/ble_glue.c
index 4c26e086..a509a96e 100644
--- a/firmware/targets/f7/ble_glue/ble_glue.c
+++ b/firmware/targets/f7/ble_glue/ble_glue.c
@@ -64,7 +64,7 @@ void ble_glue_set_key_storage_changed_callback(
}
void ble_glue_init() {
- ble_glue = furi_alloc(sizeof(BleGlue));
+ ble_glue = malloc(sizeof(BleGlue));
ble_glue->status = BleGlueStatusStartup;
// Configure the system Power Mode
diff --git a/firmware/targets/f7/ble_glue/dev_info_service.c b/firmware/targets/f7/ble_glue/dev_info_service.c
index 1c9b94eb..80d7b0eb 100644
--- a/firmware/targets/f7/ble_glue/dev_info_service.c
+++ b/firmware/targets/f7/ble_glue/dev_info_service.c
@@ -23,7 +23,7 @@ static const char dev_info_software_rev_num[] = GIT_COMMIT " " GIT_BRANCH " " GI
" " BUILD_DATE;
void dev_info_svc_start() {
- dev_info_svc = furi_alloc(sizeof(DevInfoSvc));
+ dev_info_svc = malloc(sizeof(DevInfoSvc));
tBleStatus status;
// Add Device Information Service
diff --git a/firmware/targets/f7/ble_glue/gap.c b/firmware/targets/f7/ble_glue/gap.c
index 1bd0cbbf..d1b1b766 100755
--- a/firmware/targets/f7/ble_glue/gap.c
+++ b/firmware/targets/f7/ble_glue/gap.c
@@ -463,7 +463,7 @@ bool gap_init(GapConfig* config, GapEventCallback on_event_cb, void* context) {
return false;
}
- gap = furi_alloc(sizeof(Gap));
+ gap = malloc(sizeof(Gap));
gap->config = config;
srand(DWT->CYCCNT);
// Create advertising timer
@@ -516,7 +516,7 @@ GapState gap_get_state() {
void gap_start_scan(GapScanCallback callback, void* context) {
furi_assert(callback);
- gap_scan = furi_alloc(sizeof(GapScan));
+ gap_scan = malloc(sizeof(GapScan));
gap_scan->callback = callback;
gap_scan->context = context;
// Scan interval 250 ms
diff --git a/firmware/targets/f7/ble_glue/hid_service.c b/firmware/targets/f7/ble_glue/hid_service.c
index ec8854e6..e30cdcb0 100644
--- a/firmware/targets/f7/ble_glue/hid_service.c
+++ b/firmware/targets/f7/ble_glue/hid_service.c
@@ -38,7 +38,7 @@ static SVCCTL_EvtAckStatus_t hid_svc_event_handler(void* event) {
void hid_svc_start() {
tBleStatus status;
- hid_svc = furi_alloc(sizeof(HIDSvc));
+ hid_svc = malloc(sizeof(HIDSvc));
Service_UUID_t svc_uuid = {};
Char_Desc_Uuid_t desc_uuid = {};
Char_UUID_t char_uuid = {};
diff --git a/firmware/targets/f7/ble_glue/serial_service.c b/firmware/targets/f7/ble_glue/serial_service.c
index 4acba7f0..a5d3b97a 100644
--- a/firmware/targets/f7/ble_glue/serial_service.c
+++ b/firmware/targets/f7/ble_glue/serial_service.c
@@ -82,7 +82,7 @@ static SVCCTL_EvtAckStatus_t serial_svc_event_handler(void* event) {
void serial_svc_start() {
tBleStatus status;
- serial_svc = furi_alloc(sizeof(SerialSvc));
+ serial_svc = malloc(sizeof(SerialSvc));
// Register event handler
SVCCTL_RegisterSvcHandler(serial_svc_event_handler);
diff --git a/firmware/targets/f7/fatfs/stm32_adafruit_sd.c b/firmware/targets/f7/fatfs/stm32_adafruit_sd.c
index b97b95c8..9225a90b 100644
--- a/firmware/targets/f7/fatfs/stm32_adafruit_sd.c
+++ b/firmware/targets/f7/fatfs/stm32_adafruit_sd.c
@@ -435,7 +435,7 @@ uint8_t
goto error;
}
- ptr = furi_alloc(sizeof(uint8_t) * BlockSize);
+ ptr = malloc(sizeof(uint8_t) * BlockSize);
if(ptr == NULL) {
goto error;
}
@@ -516,7 +516,7 @@ uint8_t BSP_SD_WriteBlocks(
goto error;
}
- ptr = furi_alloc(sizeof(uint8_t) * BlockSize);
+ ptr = malloc(sizeof(uint8_t) * BlockSize);
if(ptr == NULL) {
goto error;
}
diff --git a/firmware/targets/f7/furi_hal/furi_hal.c b/firmware/targets/f7/furi_hal/furi_hal.c
index 082956b1..2821182c 100644
--- a/firmware/targets/f7/furi_hal/furi_hal.c
+++ b/firmware/targets/f7/furi_hal/furi_hal.c
@@ -11,9 +11,7 @@
#define TAG "FuriHal"
void furi_hal_init() {
- furi_hal_clock_init();
furi_hal_rtc_init();
- furi_hal_console_init();
furi_hal_interrupt_init();
furi_hal_delay_init();
@@ -71,3 +69,8 @@ void furi_hal_init() {
LL_MPU_INSTRUCTION_ACCESS_ENABLE);
LL_MPU_Enable(LL_MPU_CTRL_PRIVILEGED_DEFAULT);
}
+
+void furi_hal_init_critical() {
+ furi_hal_clock_init();
+ furi_hal_console_init();
+} \ No newline at end of file
diff --git a/firmware/targets/f7/furi_hal/furi_hal_bt_hid.c b/firmware/targets/f7/furi_hal/furi_hal_bt_hid.c
index 6b7128d8..507dedfb 100644
--- a/firmware/targets/f7/furi_hal/furi_hal_bt_hid.c
+++ b/firmware/targets/f7/furi_hal/furi_hal_bt_hid.c
@@ -147,8 +147,8 @@ void furi_hal_bt_hid_start() {
hid_svc_start();
}
// Configure HID Keyboard
- kb_report = furi_alloc(sizeof(FuriHalBtHidKbReport));
- media_report = furi_alloc(sizeof(FuriHalBtHidMediaReport));
+ kb_report = malloc(sizeof(FuriHalBtHidKbReport));
+ media_report = malloc(sizeof(FuriHalBtHidMediaReport));
// Configure Report Map characteristic
hid_svc_update_report_map(
furi_hal_bt_hid_report_map_data, sizeof(furi_hal_bt_hid_report_map_data));
diff --git a/firmware/targets/f7/furi_hal/furi_hal_compress.c b/firmware/targets/f7/furi_hal/furi_hal_compress.c
index d0efb143..7e31dbbf 100644
--- a/firmware/targets/f7/furi_hal/furi_hal_compress.c
+++ b/firmware/targets/f7/furi_hal/furi_hal_compress.c
@@ -41,7 +41,7 @@ static void furi_hal_compress_reset(FuriHalCompress* compress) {
}
void furi_hal_compress_icon_init() {
- icon_decoder = furi_alloc(sizeof(FuriHalCompressIcon));
+ icon_decoder = malloc(sizeof(FuriHalCompressIcon));
icon_decoder->decoder = heatshrink_decoder_alloc(
icon_decoder->compress_buff,
FURI_HAL_COMPRESS_ICON_ENCODED_BUFF_SIZE,
@@ -84,8 +84,8 @@ void furi_hal_compress_icon_decode(const uint8_t* icon_data, uint8_t** decoded_b
}
FuriHalCompress* furi_hal_compress_alloc(uint16_t compress_buff_size) {
- FuriHalCompress* compress = furi_alloc(sizeof(FuriHalCompress));
- compress->compress_buff = furi_alloc(compress_buff_size + FURI_HAL_COMPRESS_EXP_BUFF_SIZE);
+ FuriHalCompress* compress = malloc(sizeof(FuriHalCompress));
+ compress->compress_buff = malloc(compress_buff_size + FURI_HAL_COMPRESS_EXP_BUFF_SIZE);
compress->encoder = heatshrink_encoder_alloc(
compress->compress_buff,
FURI_HAL_COMPRESS_EXP_BUFF_SIZE_LOG,
diff --git a/firmware/targets/f7/furi_hal/furi_hal_console.c b/firmware/targets/f7/furi_hal/furi_hal_console.c
index dd51716f..f3cf06da 100644
--- a/firmware/targets/f7/furi_hal/furi_hal_console.c
+++ b/firmware/targets/f7/furi_hal/furi_hal_console.c
@@ -12,15 +12,17 @@
#define TAG "FuriHalConsole"
+#ifdef HEAP_PRINT_DEBUG
+#define CONSOLE_BAUDRATE 1843200
+#else
#define CONSOLE_BAUDRATE 230400
+#endif
volatile bool furi_hal_console_alive = false;
void furi_hal_console_init() {
furi_hal_uart_init(FuriHalUartIdUSART1, CONSOLE_BAUDRATE);
furi_hal_console_alive = true;
-
- FURI_LOG_I(TAG, "Init OK");
}
void furi_hal_console_enable() {
diff --git a/firmware/targets/f7/furi_hal/furi_hal_irda.c b/firmware/targets/f7/furi_hal/furi_hal_irda.c
index cd984741..6fe051a9 100644
--- a/firmware/targets/f7/furi_hal/furi_hal_irda.c
+++ b/firmware/targets/f7/furi_hal/furi_hal_irda.c
@@ -588,13 +588,13 @@ void furi_hal_irda_async_tx_start(uint32_t freq, float duty_cycle) {
furi_assert(irda_tim_tx.buffer[1].polarity == NULL);
size_t alloc_size_data = IRDA_TIM_TX_DMA_BUFFER_SIZE * sizeof(uint16_t);
- irda_tim_tx.buffer[0].data = furi_alloc(alloc_size_data);
- irda_tim_tx.buffer[1].data = furi_alloc(alloc_size_data);
+ irda_tim_tx.buffer[0].data = malloc(alloc_size_data);
+ irda_tim_tx.buffer[1].data = malloc(alloc_size_data);
size_t alloc_size_polarity =
(IRDA_TIM_TX_DMA_BUFFER_SIZE + IRDA_POLARITY_SHIFT) * sizeof(uint8_t);
- irda_tim_tx.buffer[0].polarity = furi_alloc(alloc_size_polarity);
- irda_tim_tx.buffer[1].polarity = furi_alloc(alloc_size_polarity);
+ irda_tim_tx.buffer[0].polarity = malloc(alloc_size_polarity);
+ irda_tim_tx.buffer[1].polarity = malloc(alloc_size_polarity);
irda_tim_tx.stop_semaphore = osSemaphoreNew(1, 0, NULL);
irda_tim_tx.cycle_duration = 1000000.0 / freq;
diff --git a/firmware/targets/f7/furi_hal/furi_hal_subghz.c b/firmware/targets/f7/furi_hal/furi_hal_subghz.c
index e2de0038..8dacd3f0 100644
--- a/firmware/targets/f7/furi_hal/furi_hal_subghz.c
+++ b/firmware/targets/f7/furi_hal/furi_hal_subghz.c
@@ -874,7 +874,7 @@ bool furi_hal_subghz_start_async_tx(FuriHalSubGhzAsyncTxCallback callback, void*
furi_hal_subghz_async_tx.duty_high = 0;
furi_hal_subghz_async_tx.buffer =
- furi_alloc(API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL * sizeof(uint32_t));
+ malloc(API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL * sizeof(uint32_t));
furi_hal_subghz_async_tx_refill(
furi_hal_subghz_async_tx.buffer, API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL);
diff --git a/firmware/targets/f7/furi_hal/furi_hal_usb_cdc.c b/firmware/targets/f7/furi_hal/furi_hal_usb_cdc.c
index d7fcbc58..bf0fd7d4 100644
--- a/firmware/targets/f7/furi_hal/furi_hal_usb_cdc.c
+++ b/firmware/targets/f7/furi_hal/furi_hal_usb_cdc.c
@@ -434,14 +434,14 @@ static void cdc_init(usbd_device* dev, FuriHalUsbInterface* intf) {
char* name = (char*)furi_hal_version_get_device_name_ptr();
uint8_t len = (name == NULL) ? (0) : (strlen(name));
- struct usb_string_descriptor* dev_prod_desc = furi_alloc(len * 2 + 2);
+ struct usb_string_descriptor* dev_prod_desc = malloc(len * 2 + 2);
dev_prod_desc->bLength = len * 2 + 2;
dev_prod_desc->bDescriptorType = USB_DTYPE_STRING;
for(uint8_t i = 0; i < len; i++) dev_prod_desc->wString[i] = name[i];
name = (char*)furi_hal_version_get_name_ptr();
len = (name == NULL) ? (0) : (strlen(name));
- struct usb_string_descriptor* dev_serial_desc = furi_alloc((len + 5) * 2 + 2);
+ struct usb_string_descriptor* dev_serial_desc = malloc((len + 5) * 2 + 2);
dev_serial_desc->bLength = (len + 5) * 2 + 2;
dev_serial_desc->bDescriptorType = USB_DTYPE_STRING;
memcpy(dev_serial_desc->wString, "f\0l\0i\0p\0_\0", 5 * 2);
diff --git a/firmware/targets/f7/furi_hal/furi_hal_vcp.c b/firmware/targets/f7/furi_hal/furi_hal_vcp.c
index 409a61a0..828fc619 100644
--- a/firmware/targets/f7/furi_hal/furi_hal_vcp.c
+++ b/firmware/targets/f7/furi_hal/furi_hal_vcp.c
@@ -58,7 +58,7 @@ static const uint8_t ascii_soh = 0x01;
static const uint8_t ascii_eot = 0x04;
void furi_hal_vcp_init() {
- vcp = furi_alloc(sizeof(FuriHalVcp));
+ vcp = malloc(sizeof(FuriHalVcp));
vcp->connected = false;
vcp->tx_stream = xStreamBufferCreate(VCP_TX_BUF_SIZE, 1);
diff --git a/firmware/targets/furi_hal_include/furi_hal.h b/firmware/targets/furi_hal_include/furi_hal.h
index 334c628f..12bddebb 100644
--- a/firmware/targets/furi_hal_include/furi_hal.h
+++ b/firmware/targets/furi_hal_include/furi_hal.h
@@ -44,3 +44,9 @@ template <unsigned int N> struct STOP_EXTERNING_ME {};
/** Init furi_hal */
void furi_hal_init();
+
+/**
+ * Init critical parts of furi_hal
+ * That code should not use memory allocations
+ */
+void furi_hal_init_critical();
diff --git a/lib/flipper_file/file_helper.c b/lib/flipper_file/file_helper.c
deleted file mode 100644
index 0eabf0d1..00000000
--- a/lib/flipper_file/file_helper.c
+++ /dev/null
@@ -1,204 +0,0 @@
-#include "file_helper.h"
-
-const char flipper_file_eoln = '\n';
-const char flipper_file_eolr = '\r';
-
-bool file_helper_seek(File* file, int32_t offset) {
- uint64_t position = storage_file_tell(file);
- return storage_file_seek(file, position + offset, true);
-}
-
-bool file_helper_write_hex(File* file, const uint8_t* data, const uint16_t data_size) {
- const uint8_t byte_text_size = 3;
- char byte_text[byte_text_size];
-
- bool result = true;
- uint16_t bytes_written;
- for(uint8_t i = 0; i < data_size; i++) {
- snprintf(byte_text, byte_text_size, "%02X", data[i]);
-
- if(i != 0) {
- // space
- const char space = ' ';
- bytes_written = storage_file_write(file, &space, sizeof(char));
- if(bytes_written != sizeof(char)) {
- result = false;
- break;
- }
- }
-
- bytes_written = storage_file_write(file, &byte_text, strlen(byte_text));
- if(bytes_written != strlen(byte_text)) {
- result = false;
- break;
- }
- }
-
- return result;
-}
-
-bool file_helper_read_line(File* file, string_t str_result) {
- string_reset(str_result);
- const uint8_t buffer_size = 32;
- uint8_t buffer[buffer_size];
-
- do {
- uint16_t bytes_were_read = storage_file_read(file, buffer, buffer_size);
- // TODO process EOF
- if(bytes_were_read == 0) break;
-
- bool result = false;
- bool error = false;
- for(uint16_t i = 0; i < bytes_were_read; i++) {
- if(buffer[i] == flipper_file_eoln) {
- if(!file_helper_seek(file, i - bytes_were_read)) {
- error = true;
- break;
- }
-
- result = true;
- break;
- } else if(buffer[i] == flipper_file_eolr) {
- // Ignore
- } else {
- string_push_back(str_result, buffer[i]);
- }
- }
-
- if(result || error) {
- break;
- }
- } while(true);
-
- return string_size(str_result) != 0;
-}
-
-bool file_helper_seek_to_next_line(File* file) {
- const uint8_t buffer_size = 32;
- uint8_t buffer[buffer_size];
- bool result = false;
- bool error = false;
-
- do {
- uint16_t bytes_were_read = storage_file_read(file, buffer, buffer_size);
- if(bytes_were_read == 0) {
- if(storage_file_eof(file)) {
- result = true;
- break;
- }
- }
-
- for(uint16_t i = 0; i < bytes_were_read; i++) {
- if(buffer[i] == flipper_file_eoln) {
- if(!file_helper_seek(file, i - bytes_were_read)) {
- error = true;
- break;
- }
-
- result = true;
- break;
- }
- }
-
- if(result || error) {
- break;
- }
- } while(true);
-
- return result;
-}
-
-bool file_helper_read_value(File* file, string_t value, bool* last) {
- string_reset(value);
- const uint8_t buffer_size = 32;
- uint8_t buffer[buffer_size];
- bool result = false;
- bool error = false;
-
- while(true) {
- uint16_t bytes_were_read = storage_file_read(file, buffer, buffer_size);
-
- if(bytes_were_read == 0) {
- // check EOF
- if(storage_file_eof(file) && string_size(value) > 0) {
- result = true;
- *last = true;
- break;
- }
- }
-
- for(uint16_t i = 0; i < bytes_were_read; i++) {
- if(buffer[i] == flipper_file_eoln) {
- if(string_size(value) > 0) {
- if(!file_helper_seek(file, i - bytes_were_read)) {
- error = true;
- break;
- }
-
- result = true;
- *last = true;
- break;
- } else {
- error = true;
- }
- } else if(buffer[i] == ' ') {
- if(string_size(value) > 0) {
- if(!file_helper_seek(file, i - bytes_were_read)) {
- error = true;
- break;
- }
-
- result = true;
- *last = false;
- break;
- }
-
- } else if(buffer[i] == flipper_file_eolr) {
- // Ignore
- } else {
- string_push_back(value, buffer[i]);
- }
- }
-
- if(error || result) break;
- }
-
- return result;
-}
-
-bool file_helper_write(File* file, const void* data, uint16_t data_size) {
- uint16_t bytes_written = storage_file_write(file, data, data_size);
- return bytes_written == data_size;
-}
-
-bool file_helper_write_eol(File* file) {
- return file_helper_write(file, &flipper_file_eoln, sizeof(char));
-}
-
-bool file_helper_copy(File* file_from, File* file_to, uint64_t start_offset, uint64_t stop_offset) {
- bool result = false;
-
- const uint8_t buffer_size = 32;
- uint8_t buffer[buffer_size];
- uint64_t current_offset = start_offset;
-
- if(storage_file_seek(file_from, start_offset, true)) {
- do {
- int32_t bytes_count = MIN(buffer_size, stop_offset - current_offset);
- if(bytes_count <= 0) {
- result = true;
- break;
- }
-
- uint16_t bytes_were_read = storage_file_read(file_from, buffer, bytes_count);
- if(bytes_were_read != bytes_count) break;
-
- uint16_t bytes_were_written = storage_file_write(file_to, buffer, bytes_count);
- if(bytes_were_written != bytes_count) break;
-
- current_offset += bytes_count;
- } while(true);
- }
-
- return result;
-} \ No newline at end of file
diff --git a/lib/flipper_file/file_helper.h b/lib/flipper_file/file_helper.h
deleted file mode 100644
index 66306797..00000000
--- a/lib/flipper_file/file_helper.h
+++ /dev/null
@@ -1,81 +0,0 @@
-#pragma once
-#include <stdint.h>
-#include <mlib/m-string.h>
-#include <storage/storage.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern const char flipper_file_eoln;
-extern const char flipper_file_eolr;
-
-/**
- * Negative seek helper
- * @param file
- * @param offset
- * @return bool
- */
-bool file_helper_seek(File* file, int32_t offset);
-
-/**
- * Writes data to a file as a hexadecimal array.
- * @param file
- * @param data
- * @param data_size
- * @return true on success write
- */
-bool file_helper_write_hex(File* file, const uint8_t* data, const uint16_t data_size);
-
-/**
- * Reads data as a string from the stored rw pointer to the \\n symbol position. Ignores \r.
- * @param file
- * @param str_result
- * @return true on success read
- */
-bool file_helper_read_line(File* file, string_t str_result);
-
-/**
- * Moves the RW pointer to the beginning of the next line
- * @param file
- * @return bool
- */
-bool file_helper_seek_to_next_line(File* file);
-
-/**
- * Read one value from array-like string (separated by ' ')
- * @param file
- * @param value
- * @return bool
- */
-bool file_helper_read_value(File* file, string_t value, bool* last);
-
-/**
- * Write helper
- * @param file
- * @param data
- * @param data_size
- * @return bool
- */
-bool file_helper_write(File* file, const void* data, uint16_t data_size);
-
-/**
- * Write EOL
- * @param file
- * @return bool
- */
-bool file_helper_write_eol(File* file);
-
-/**
- * Appends part of one file to the end of another file
- * @param file_from
- * @param file_to
- * @param start_offset
- * @param stop_offset
- * @return bool
- */
-bool file_helper_copy(File* file_from, File* file_to, uint64_t start_offset, uint64_t stop_offset);
-
-#ifdef __cplusplus
-}
-#endif \ No newline at end of file
diff --git a/lib/flipper_file/flipper_file.c b/lib/flipper_file/flipper_file.c
deleted file mode 100644
index 5e96c13a..00000000
--- a/lib/flipper_file/flipper_file.c
+++ /dev/null
@@ -1,402 +0,0 @@
-#include <furi.h>
-#include "file_helper.h"
-#include "flipper_file_helper.h"
-#include "flipper_file.h"
-#include "flipper_file_i.h"
-#include <inttypes.h>
-#include <toolbox/hex.h>
-
-FlipperFile* flipper_file_alloc(Storage* storage) {
- // furi_assert(storage);
-
- FlipperFile* flipper_file = malloc(sizeof(FlipperFile));
- flipper_file->storage = storage;
- flipper_file->file = storage_file_alloc(flipper_file->storage);
- flipper_file->strict_mode = false;
-
- return flipper_file;
-}
-
-void flipper_file_free(FlipperFile* flipper_file) {
- furi_assert(flipper_file);
- if(storage_file_is_open(flipper_file->file)) {
- storage_file_close(flipper_file->file);
- }
- storage_file_free(flipper_file->file);
- free(flipper_file);
-}
-
-void flipper_file_set_strict_mode(FlipperFile* flipper_file, bool strict_mode) {
- furi_assert(flipper_file);
- flipper_file->strict_mode = strict_mode;
-}
-
-bool flipper_file_open_existing(FlipperFile* flipper_file, const char* filename) {
- furi_assert(flipper_file);
- bool result = storage_file_open(
- flipper_file->file, filename, FSAM_READ | FSAM_WRITE, FSOM_OPEN_EXISTING);
- return result;
-}
-
-bool flipper_file_open_append(FlipperFile* flipper_file, const char* filename) {
- furi_assert(flipper_file);
-
- bool result =
- storage_file_open(flipper_file->file, filename, FSAM_READ | FSAM_WRITE, FSOM_OPEN_APPEND);
-
- // Add EOL if it is not there
- if(storage_file_size(flipper_file->file) >= 1) {
- do {
- char last_char;
- result = false;
-
- if(!file_helper_seek(flipper_file->file, -1)) break;
-
- uint16_t bytes_were_read = storage_file_read(flipper_file->file, &last_char, 1);
- if(bytes_were_read != 1) break;
-
- if(last_char != flipper_file_eoln) {
- if(!file_helper_write_eol(flipper_file->file)) break;
- }
-
- result = true;
- } while(false);
- }
-
- return result;
-}
-
-bool flipper_file_open_always(FlipperFile* flipper_file, const char* filename) {
- furi_assert(flipper_file);
- bool result = storage_file_open(
- flipper_file->file, filename, FSAM_READ | FSAM_WRITE, FSOM_CREATE_ALWAYS);
- return result;
-}
-
-bool flipper_file_open_new(FlipperFile* flipper_file, const char* filename) {
- furi_assert(flipper_file);
- bool result =
- storage_file_open(flipper_file->file, filename, FSAM_READ | FSAM_WRITE, FSOM_CREATE_NEW);
- return result;
-}
-
-bool flipper_file_close(FlipperFile* flipper_file) {
- furi_assert(flipper_file);
- if(storage_file_is_open(flipper_file->file)) {
- return storage_file_close(flipper_file->file);
- }
- return true;
-}
-
-bool flipper_file_rewind(FlipperFile* flipper_file) {
- furi_assert(flipper_file);
- return storage_file_seek(flipper_file->file, 0, true);
-}
-
-bool flipper_file_read_header(FlipperFile* flipper_file, string_t filetype, uint32_t* version) {
- bool result = false;
- do {
- result = flipper_file_read_string(flipper_file, flipper_file_filetype_key, filetype);
- if(!result) break;
- result = flipper_file_read_uint32(flipper_file, flipper_file_version_key, version, 1);
- if(!result) break;
- } while(false);
-
- return result;
-}
-
-bool flipper_file_write_header(
- FlipperFile* flipper_file,
- string_t filetype,
- const uint32_t version) {
- bool result = false;
- do {
- result = flipper_file_write_string(flipper_file, flipper_file_filetype_key, filetype);
- if(!result) break;
- result = flipper_file_write_uint32(flipper_file, flipper_file_version_key, &version, 1);
- if(!result) break;
- } while(false);
-
- return result;
-}
-
-bool flipper_file_write_header_cstr(
- FlipperFile* flipper_file,
- const char* filetype,
- const uint32_t version) {
- bool result = false;
- string_t value;
- string_init_set(value, filetype);
- result = flipper_file_write_header(flipper_file, value, version);
- string_clear(value);
- return result;
-}
-
-bool flipper_file_get_value_count(FlipperFile* flipper_file, const char* key, uint32_t* count) {
- furi_assert(flipper_file);
- bool result = false;
- bool last = false;
-
- string_t value;
- string_init(value);
-
- uint32_t position = storage_file_tell(flipper_file->file);
- do {
- if(!flipper_file_seek_to_key(flipper_file->file, key, flipper_file->strict_mode)) break;
-
- // Balance between speed and memory consumption
- // I prefer lower speed but less memory consumption
- *count = 0;
-
- result = true;
- while(true) {
- if(!file_helper_read_value(flipper_file->file, value, &last)) {
- result = false;
- break;
- }
-
- *count = *count + 1;
- if(last) break;
- }
-
- } while(false);
-
- if(!storage_file_seek(flipper_file->file, position, true)) {
- result = false;
- }
-
- string_clear(value);
- return result;
-}
-
-bool flipper_file_write_comment(FlipperFile* flipper_file, string_t data) {
- furi_assert(flipper_file);
-
- bool result = false;
- do {
- const char comment_buffer[2] = {flipper_file_comment, ' '};
- result = file_helper_write(flipper_file->file, comment_buffer, sizeof(comment_buffer));
- if(!result) break;
-
- result = file_helper_write(flipper_file->file, string_get_cstr(data), string_size(data));
- if(!result) break;
-
- result = file_helper_write_eol(flipper_file->file);
- } while(false);
-
- return result;
-}
-
-bool flipper_file_write_comment_cstr(FlipperFile* flipper_file, const char* data) {
- bool result = false;
- string_t value;
- string_init_set(value, data);
- result = flipper_file_write_comment(flipper_file, value);
- string_clear(value);
- return result;
-}
-
-bool flipper_file_delete_key_and_call(
- FlipperFile* flipper_file,
- const char* key,
- flipper_file_cb call,
- const char* cb_key,
- const void* cb_data,
- const uint16_t cb_data_size) {
- bool result = false;
- File* scratch_file = storage_file_alloc(flipper_file->storage);
-
- do {
- // get size
- uint64_t file_size = storage_file_size(flipper_file->file);
- if(file_size == 0) break;
-
- if(!storage_file_seek(flipper_file->file, 0, true)) break;
-
- // find key
- if(!flipper_file_seek_to_key(flipper_file->file, key, flipper_file->strict_mode)) break;
- // get key start position
- uint64_t start_position = storage_file_tell(flipper_file->file) - strlen(key);
- if(start_position >= 2) {
- start_position -= 2;
- } else {
- // something wrong
- break;
- }
-
- // get value end position
- if(!file_helper_seek_to_next_line(flipper_file->file)) break;
- uint64_t end_position = storage_file_tell(flipper_file->file);
- // newline symbol
- if(end_position < file_size) {
- end_position += 1;
- }
-
- // open scratchpad
- const char* scratch_name = "";
- if(!flipper_file_get_scratchpad_name(&scratch_name)) break;
-
- if(!storage_file_open(
- scratch_file, scratch_name, FSAM_READ | FSAM_WRITE, FSOM_CREATE_ALWAYS))
- break;
-
- // copy key file before key to scratchpad
- if(!file_helper_copy(flipper_file->file, scratch_file, 0, start_position)) break;
-
- // do something in between if needed
- if(call != NULL) {
- if(!call(scratch_file, cb_key, cb_data, cb_data_size)) break;
- };
-
- // copy key file after key value to scratchpad
- if(!file_helper_copy(flipper_file->file, scratch_file, end_position, file_size)) break;
-
- file_size = storage_file_tell(scratch_file);
- if(file_size == 0) break;
-
- if(!storage_file_seek(flipper_file->file, 0, true)) break;
-
- // copy whole scratchpad file to the original file
- if(!file_helper_copy(scratch_file, flipper_file->file, 0, file_size)) break;
-
- // and truncate original file
- if(!storage_file_truncate(flipper_file->file)) break;
-
- // close and remove scratchpad file
- if(!storage_file_close(scratch_file)) break;
- if(storage_common_remove(flipper_file->storage, scratch_name) != FSE_OK) break;
- result = true;
- } while(false);
-
- storage_file_free(scratch_file);
-
- return result;
-}
-
-bool flipper_file_delete_key(FlipperFile* flipper_file, const char* key) {
- furi_assert(flipper_file);
- return flipper_file_delete_key_and_call(flipper_file, key, NULL, NULL, NULL, 0);
-}
-
-bool flipper_file_write_internal(
- File* file,
- const char* key,
- const void* _data,
- const uint16_t data_size,
- FlipperFileValueType type) {
- bool result = false;
- string_t value;
- string_init(value);
-
- do {
- result = flipper_file_write_key(file, key);
- if(!result) break;
-
- for(uint16_t i = 0; i < data_size; i++) {
- switch(type) {
- case FlipperFileValueHex: {
- const uint8_t* data = _data;
- string_printf(value, "%02X", data[i]);
- }; break;
- case FlipperFileValueFloat: {
- const float* data = _data;
- string_printf(value, "%f", data[i]);
- }; break;
- case FlipperFileValueInt32: {
- const int32_t* data = _data;
- string_printf(value, "%" PRIi32, data[i]);
- }; break;
- case FlipperFileValueUint32: {
- const uint32_t* data = _data;
- string_printf(value, "%" PRId32, data[i]);
- }; break;
- }
-
- if((i + 1) < data_size) {
- string_cat(value, " ");
- }
-
- result = file_helper_write(file, string_get_cstr(value), string_size(value));
- if(!result) break;
- }
-
- result = file_helper_write_eol(file);
- } while(false);
-
- string_clear(value);
- return result;
-}
-
-bool flipper_file_read_internal(
- File* file,
- const char* key,
- void* _data,
- const uint16_t data_size,
- bool strict_mode,
- FlipperFileValueType type) {
- bool result = false;
- string_t value;
- string_init(value);
-
- if(flipper_file_seek_to_key(file, key, strict_mode)) {
- result = true;
- for(uint16_t i = 0; i < data_size; i++) {
- bool last = false;
- result = file_helper_read_value(file, value, &last);
- if(result) {
- int scan_values = 0;
- switch(type) {
- case FlipperFileValueHex: {
- uint8_t* data = _data;
- // sscanf "%02X" does not work here
- if(hex_chars_to_uint8(
- string_get_char(value, 0), string_get_char(value, 1), &data[i])) {
- scan_values = 1;
- }
- }; break;
- case FlipperFileValueFloat: {
- float* data = _data;
- // newlib-nano does not have sscanf for floats
- // scan_values = sscanf(string_get_cstr(value), "%f", &data[i]);
- char* end_char;
- data[i] = strtof(string_get_cstr(value), &end_char);
- if(*end_char == 0) {
- // very probably ok
- scan_values = 1;
- }
- }; break;
- case FlipperFileValueInt32: {
- int32_t* data = _data;
- scan_values = sscanf(string_get_cstr(value), "%" PRIi32, &data[i]);
- }; break;
- case FlipperFileValueUint32: {
- uint32_t* data = _data;
- scan_values = sscanf(string_get_cstr(value), "%" PRId32, &data[i]);
- }; break;
- }
-
- if(scan_values != 1) {
- result = false;
- break;
- }
- } else {
- break;
- }
-
- if(last && ((i + 1) != data_size)) {
- result = false;
- break;
- }
- }
- }
-
- string_clear(value);
- return result;
-}
-
-File* flipper_file_get_file(FlipperFile* flipper_file) {
- furi_assert(flipper_file);
- furi_assert(flipper_file->file);
-
- return flipper_file->file;
-}
diff --git a/lib/flipper_file/flipper_file.h b/lib/flipper_file/flipper_file.h
deleted file mode 100644
index 0a8c3c9e..00000000
--- a/lib/flipper_file/flipper_file.h
+++ /dev/null
@@ -1,465 +0,0 @@
-/**
- * @file flipper-file.h
- * Flipper File Format helper library.
- *
- * Flipper File Format is a fairly simple format for storing data in a file.
- *
- * Flipper file structure:
- *
- * ~~~~~~~~~~~~~~~~~~~~~
- * # Commentary
- * Field name: field value
- * ~~~~~~~~~~~~~~~~~~~~~
- *
- * Lines starting with the # character are ignored (considered as comments). The separator between the name of the value and the value itself is the string ": ".
- *
- * Currently supported types:
- *
- * ~~~~~~~~~~~~~~~~~~~~~
- * String: text
- * Int32: 1 2 -3 4
- * Uint32: 1 2 3 4
- * Float: 1.0 1234.654
- * Hex: A4 B3 C2 D1 12 FF
- * ~~~~~~~~~~~~~~~~~~~~~
- *
- * End of line is LF when writing, but CR is supported when reading.
- *
- * The library is designed in such a way that comments and field values are completely ignored when searching for keys, that is, they do not consume memory.
- *
- * File example:
- *
- * ~~~~~~~~~~~~~~~~~~~~~
- * Filetype: Flipper Test File
- * Version: 1
- * # Just test file
- * String: String value
- * UINT: 1234
- * Hex: 00 01 FF A3
- * ~~~~~~~~~~~~~~~~~~~~~
- *
- * Writing:
- *
- * ~~~~~~~~~~~~~~~~~~~~~
- * FlipperFile file = flipper_file_alloc(storage);
- *
- * do {
- * const uint32_t version = 1;
- * const char* string_value = "String value";
- * const uint32_t uint32_value = 1234;
- * const uint16_t array_size = 4;
- * const uint8_t* array[array_size] = {0x00, 0x01, 0xFF, 0xA3};
- *
- * if(!flipper_file_open_new(file, "/ext/flipper_file_test")) break;
- * if(!flipper_file_write_header_cstr(file, "Flipper Test File", version)) break;
- * if(!flipper_file_write_comment_cstr(file, "Just test file")) break;
- * if(!flipper_file_write_string_cstr(file, "String", string_value)) break;
- * if(!flipper_file_flipper_file_write_uint32(file, "UINT", &uint32_value, 1)) break;
- * if(!flipper_file_write_hex(file, "Hex Array", array, array_size)) break;
- *
- * // signal that the file was written successfully
- * } while(0);
- *
- * flipper_file_close(file);
- * flipper_file_free(file);
- * ~~~~~~~~~~~~~~~~~~~~~
- *
- * Reading:
- *
- * ~~~~~~~~~~~~~~~~~~~~~
- * FlipperFile file = flipper_file_alloc(storage);
- *
- * do {
- * uint32_t version = 1;
- * string_t file_type;
- * string_t string_value;
- * uint32_t uint32_value = 1;
- * uint16_t array_size = 4;
- * uint8_t* array[array_size] = {0};
- * string_init(file_type);
- * string_init(string_value);
- *
- * if(!flipper_file_open_existing(file, "/ext/flipper_file_test")) break;
- * if(!flipper_file_read_header(file, file_type, &version)) break;
- * if(!flipper_file_read_string(file, "String", string_value)) break;
- * if(!flipper_file_read_uint32(file, "UINT", &uint32_value, 1)) break;
- * if(!flipper_file_read_hex(file, "Hex Array", array, array_size)) break;
- *
- * // signal that the file was read successfully
- * } while(0);
- *
- * flipper_file_close(file);
- * flipper_file_free(file);
- * ~~~~~~~~~~~~~~~~~~~~~
- *
- */
-
-#pragma once
-#include <stdint.h>
-#include <mlib/m-string.h>
-#include <storage/storage.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/** FlipperFile type anonymous structure. */
-typedef struct FlipperFile FlipperFile;
-
-/**
- * Allocate FlipperFile.
- * @param storage storage api
- * @return FlipperFile* Pointer to a FlipperFile instance
- */
-FlipperFile* flipper_file_alloc(Storage* storage);
-
-/**
- * Free FlipperFile.
- * @param flipper_file Pointer to a FlipperFile instance
- */
-void flipper_file_free(FlipperFile* flipper_file);
-
-/**
- * Free FlipperFile.
- * @param flipper_file Pointer to a FlipperFile instance
- * @param strict_mode True obligates not to skip valid fields. False by default.
- */
-void flipper_file_set_strict_mode(FlipperFile* flipper_file, bool strict_mode);
-
-/**
- * Open existing file.
- * @param flipper_file Pointer to a FlipperFile instance
- * @param filename File name and path
- * @return True on success
- */
-bool flipper_file_open_existing(FlipperFile* flipper_file, const char* filename);
-
-/**
- * Open existing file for writing and add values to the end of file.
- * @param flipper_file Pointer to a FlipperFile instance
- * @param filename File name and path
- * @return True on success
- */
-bool flipper_file_open_append(FlipperFile* flipper_file, const char* filename);
-
-/**
- * Open file. Creates a new file, or deletes the contents of the file if it already exists.
- * @param flipper_file Pointer to a FlipperFile instance
- * @param filename File name and path
- * @return True on success
- */
-bool flipper_file_open_always(FlipperFile* flipper_file, const char* filename);
-
-/**
- * Open file. Creates a new file, fails if file already exists.
- * @param flipper_file Pointer to a FlipperFile instance
- * @param filename File name and path
- * @return True on success
- */
-bool flipper_file_open_new(FlipperFile* flipper_file, const char* filename);
-
-/**
- * Close the file.
- * @param flipper_file Pointer to a FlipperFile instance
- * @return True on success
- */
-bool flipper_file_close(FlipperFile* flipper_file);
-
-/**
- * Rewind the file RW pointer.
- * @param flipper_file Pointer to a FlipperFile instance
- * @return True on success
- */
-bool flipper_file_rewind(FlipperFile* flipper_file);
-
-/**
- * Read the header (file type and version) from the file.
- * @param flipper_file Pointer to a FlipperFile instance
- * @param filetype File type string
- * @param version Version Value
- * @return True on success
- */
-bool flipper_file_read_header(FlipperFile* flipper_file, string_t filetype, uint32_t* version);
-
-/**
- * Write the header (file type and version) to the file.
- * @param flipper_file Pointer to a FlipperFile instance
- * @param filetype File type string
- * @param version Version Value
- * @return True on success
- */
-bool flipper_file_write_header(
- FlipperFile* flipper_file,
- string_t filetype,
- const uint32_t version);
-
-/**
- * Write the header (file type and version) to the file. Plain C string version.
- * @param flipper_file Pointer to a FlipperFile instance
- * @param filetype File type string
- * @param version Version Value
- * @return True on success
- */
-bool flipper_file_write_header_cstr(
- FlipperFile* flipper_file,
- const char* filetype,
- const uint32_t version);
-
-/**
- * Get the count of values by key
- * @param flipper_file
- * @param key
- * @param count
- * @return bool
- */
-bool flipper_file_get_value_count(FlipperFile* flipper_file, const char* key, uint32_t* count);
-
-/**
- * Read a string from a file by Key
- * @param flipper_file Pointer to a FlipperFile instance
- * @param key Key
- * @param data Value
- * @return True on success
- */
-bool flipper_file_read_string(FlipperFile* flipper_file, const char* key, string_t data);
-
-/**
- * Write key and string to file.
- * @param flipper_file Pointer to a FlipperFile instance
- * @param key Key
- * @param data Value
- * @return True on success
- */
-bool flipper_file_write_string(FlipperFile* flipper_file, const char* key, string_t data);
-
-/**
- * Write key and string to file. Plain C string version.
- * @param flipper_file Pointer to a FlipperFile instance
- * @param key Key
- * @param data Value
- * @return True on success
- */
-bool flipper_file_write_string_cstr(FlipperFile* flipper_file, const char* key, const char* data);
-
-/**
- * Read array of uint32 from a file by Key
- * @param flipper_file Pointer to a FlipperFile instance
- * @param key Key
- * @param data Value
- * @param data_size Values count
- * @return True on success
- */
-bool flipper_file_read_uint32(
- FlipperFile* flipper_file,
- const char* key,
- uint32_t* data,
- const uint16_t data_size);
-
-/**
- * Write key and array of uint32 to file.
- * @param flipper_file Pointer to a FlipperFile instance
- * @param key Key
- * @param data Value
- * @param data_size Values count
- * @return True on success
- */
-bool flipper_file_write_uint32(
- FlipperFile* flipper_file,
- const char* key,
- const uint32_t* data,
- const uint16_t data_size);
-
-/**
- * Read array of int32 from a file by Key
- * @param flipper_file Pointer to a FlipperFile instance
- * @param key Key
- * @param data Value
- * @param data_size Values count
- * @return True on success
- */
-bool flipper_file_read_int32(
- FlipperFile* flipper_file,
- const char* key,
- int32_t* data,
- const uint16_t data_size);
-
-/**
- * Write key and array of int32 to file.
- * @param flipper_file Pointer to a FlipperFile instance
- * @param key Key
- * @param data Value
- * @param data_size Values count
- * @return True on success
- */
-bool flipper_file_write_int32(
- FlipperFile* flipper_file,
- const char* key,
- const int32_t* data,
- const uint16_t data_size);
-
-/**
- * Read array of float from a file by Key
- * @param flipper_file Pointer to a FlipperFile instance
- * @param key Key
- * @param data Value
- * @param data_size Values count
- * @return True on success
- */
-bool flipper_file_read_float(
- FlipperFile* flipper_file,
- const char* key,
- float* data,
- const uint16_t data_size);
-
-/**
- * Write key and array of float to file.
- * @param flipper_file Pointer to a FlipperFile instance
- * @param key Key
- * @param data Value
- * @param data_size Values count
- * @return True on success
- */
-bool flipper_file_write_float(
- FlipperFile* flipper_file,
- const char* key,
- const float* data,
- const uint16_t data_size);
-
-/**
- * Read hex array from a file by Key
- * @param flipper_file Pointer to a FlipperFile instance
- * @param key Key
- * @param data Value
- * @param data_size Value size
- * @return True on success
- */
-bool flipper_file_read_hex(
- FlipperFile* flipper_file,
- const char* key,
- uint8_t* data,
- const uint16_t data_size);
-
-/**
- * Write key and hex array to file.
- * @param flipper_file Pointer to a FlipperFile instance
- * @param key Key
- * @param data Value
- * @param data_size Values count
- * @return True on success
- */
-bool flipper_file_write_hex(
- FlipperFile* flipper_file,
- const char* key,
- const uint8_t* data,
- const uint16_t data_size);
-
-/**
- * Write comment to file.
- * @param flipper_file Pointer to a FlipperFile instance
- * @param data Comment text
- * @return True on success
- */
-bool flipper_file_write_comment(FlipperFile* flipper_file, string_t data);
-
-/**
- * Write comment to file. Plain C string version.
- * @param flipper_file Pointer to a FlipperFile instance
- * @param data Comment text
- * @return True on success
- */
-bool flipper_file_write_comment_cstr(FlipperFile* flipper_file, const char* data);
-
-/**
- * Removes the first matching key and its value from the file. Changes the RW pointer to an undefined position.
- * @param flipper_file Pointer to a FlipperFile instance
- * @param key Key
- * @return True on success
- */
-bool flipper_file_delete_key(FlipperFile* flipper_file, const char* key);
-
-/**
- * Updates the value of the first matching key to a string value. Changes the RW pointer to an undefined position.
- * @param flipper_file Pointer to a FlipperFile instance
- * @param key Key
- * @param data Value
- * @return True on success
- */
-bool flipper_file_update_string(FlipperFile* flipper_file, const char* key, string_t data);
-
-/**
- * Updates the value of the first matching key to a string value. Plain C version. Changes the RW pointer to an undefined position.
- * @param flipper_file Pointer to a FlipperFile instance
- * @param key Key
- * @param data Value
- * @return True on success
- */
-bool flipper_file_update_string_cstr(FlipperFile* flipper_file, const char* key, const char* data);
-
-/**
- * Updates the value of the first matching key to a uint32 array value. Changes the RW pointer to an undefined position.
- * @param flipper_file Pointer to a FlipperFile instance
- * @param key Key
- * @param data Value
- * @param data_size Values count
- * @return True on success
- */
-bool flipper_file_update_uint32(
- FlipperFile* flipper_file,
- const char* key,
- const uint32_t* data,
- const uint16_t data_size);
-
-/**
- * Updates the value of the first matching key to a int32 array value. Changes the RW pointer to an undefined position.
- * @param flipper_file Pointer to a FlipperFile instance
- * @param key Key
- * @param data Value
- * @param data_size Values count
- * @return True on success
- */
-bool flipper_file_update_int32(
- FlipperFile* flipper_file,
- const char* key,
- const int32_t* data,
- const uint16_t data_size);
-
-/**
- * Updates the value of the first matching key to a float array value. Changes the RW pointer to an undefined position.
- * @param flipper_file Pointer to a FlipperFile instance
- * @param key Key
- * @param data Value
- * @param data_size Values count
- * @return True on success
- */
-bool flipper_file_update_float(
- FlipperFile* flipper_file,
- const char* key,
- const float* data,
- const uint16_t data_size);
-
-/**
- * Updates the value of the first matching key to a hex array value. Changes the RW pointer to an undefined position.
- * @param flipper_file Pointer to a FlipperFile instance
- * @param key Key
- * @param data Value
- * @param data_size Values count
- * @return True on success
- */
-bool flipper_file_update_hex(
- FlipperFile* flipper_file,
- const char* key,
- const uint8_t* data,
- const uint16_t data_size);
-
-/** Get file descriptor.
- *
- * We higly don't recommend to use it.
- * This instance is owned by FlipperFile.
- * @param flipper_file
- * @return File*
- */
-File* flipper_file_get_file(FlipperFile* flipper_file);
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/lib/flipper_file/flipper_file_float.c b/lib/flipper_file/flipper_file_float.c
deleted file mode 100644
index 299ff61c..00000000
--- a/lib/flipper_file/flipper_file_float.c
+++ /dev/null
@@ -1,42 +0,0 @@
-#include <furi.h>
-
-#include "flipper_file.h"
-#include "flipper_file_i.h"
-#include "flipper_file_helper.h"
-
-static bool flipper_file_write_float_internal(
- File* file,
- const char* key,
- const void* _data,
- const uint16_t data_size) {
- return flipper_file_write_internal(file, key, _data, data_size, FlipperFileValueFloat);
-};
-
-bool flipper_file_read_float(
- FlipperFile* flipper_file,
- const char* key,
- float* data,
- const uint16_t data_size) {
- furi_assert(flipper_file);
- return flipper_file_read_internal(
- flipper_file->file, key, data, data_size, flipper_file->strict_mode, FlipperFileValueFloat);
-}
-
-bool flipper_file_write_float(
- FlipperFile* flipper_file,
- const char* key,
- const float* data,
- const uint16_t data_size) {
- furi_assert(flipper_file);
- return flipper_file_write_float_internal(flipper_file->file, key, data, data_size);
-}
-
-bool flipper_file_update_float(
- FlipperFile* flipper_file,
- const char* key,
- const float* data,
- const uint16_t data_size) {
- furi_assert(flipper_file);
- return flipper_file_delete_key_and_call(
- flipper_file, key, flipper_file_write_float_internal, key, data, data_size);
-}
diff --git a/lib/flipper_file/flipper_file_helper.c b/lib/flipper_file/flipper_file_helper.c
deleted file mode 100644
index c06945bd..00000000
--- a/lib/flipper_file/flipper_file_helper.c
+++ /dev/null
@@ -1,121 +0,0 @@
-#include "flipper_file_helper.h"
-
-const char* const flipper_file_filetype_key = "Filetype";
-const char* const flipper_file_version_key = "Version";
-const char flipper_file_delimiter = ':';
-const char flipper_file_comment = '#';
-
-#ifdef __linux__
-const char* flipper_file_scratchpad = ".scratch.pad";
-#else
-const char* flipper_file_scratchpad = "/any/.scratch.pad";
-#endif
-
-bool flipper_file_read_valid_key(File* file, string_t key) {
- string_reset(key);
- bool found = false;
- bool error = false;
- const uint8_t buffer_size = 32;
- uint8_t buffer[buffer_size];
- bool accumulate = true;
- bool new_line = true;
-
- while(true) {
- uint16_t bytes_were_read = storage_file_read(file, buffer, buffer_size);
- if(bytes_were_read == 0) break;
-
- for(uint16_t i = 0; i < bytes_were_read; i++) {
- if(buffer[i] == flipper_file_eoln) {
- // EOL found, clean data, start accumulating data and set the new_line flag
- string_reset(key);
- accumulate = true;
- new_line = true;
- } else if(buffer[i] == flipper_file_eolr) {
- // Ignore
- } else if(buffer[i] == flipper_file_comment && new_line) {
- // if there is a comment character and we are at the beginning of a new line
- // do not accumulate comment data and reset the new_line flag
- accumulate = false;
- new_line = false;
- } else if(buffer[i] == flipper_file_delimiter) {
- if(new_line) {
- // we are on a "new line" and found the delimiter
- // this can only be if we have previously found some kind of key, so
- // clear the data, set the flag that we no longer want to accumulate data
- // and reset the new_line flag
- string_reset(key);
- accumulate = false;
- new_line = false;
- } else {
- // parse the delimiter only if we are accumulating data
- if(accumulate) {
- // we found the delimiter, move the rw pointer to the correct location
- // and signal that we have found something
- if(!file_helper_seek(file, i - bytes_were_read)) {
- error = true;
- break;
- }
-
- found = true;
- break;
- }
- }
- } else {
- // just new symbol, reset the new_line flag
- new_line = false;
- if(accumulate) {
- // and accumulate data if we want
- string_push_back(key, buffer[i]);
- }
- }
- }
-
- if(found || error) break;
- }
-
- return found;
-}
-
-bool flipper_file_seek_to_key(File* file, const char* key, bool strict_mode) {
- bool found = false;
- string_t readed_key;
-
- string_init(readed_key);
-
- while(!storage_file_eof(file)) {
- if(flipper_file_read_valid_key(file, readed_key)) {
- if(string_cmp_str(readed_key, key) == 0) {
- if(!file_helper_seek(file, 2)) break;
-
- found = true;
- break;
- } else if(strict_mode) {
- found = false;
- break;
- }
- }
- }
- string_clear(readed_key);
-
- return found;
-}
-
-bool flipper_file_write_key(File* file, const char* key) {
- bool result = false;
-
- do {
- result = file_helper_write(file, key, strlen(key));
- if(!result) break;
-
- const char delimiter_buffer[2] = {flipper_file_delimiter, ' '};
- result = file_helper_write(file, delimiter_buffer, sizeof(delimiter_buffer));
- } while(false);
-
- return result;
-}
-
-bool flipper_file_get_scratchpad_name(const char** name) {
- // TODO do not rewrite existing file
- *name = flipper_file_scratchpad;
- return true;
-}
diff --git a/lib/flipper_file/flipper_file_helper.h b/lib/flipper_file/flipper_file_helper.h
deleted file mode 100644
index 53dc3ad9..00000000
--- a/lib/flipper_file/flipper_file_helper.h
+++ /dev/null
@@ -1,52 +0,0 @@
-#pragma once
-#include <stdint.h>
-#include <mlib/m-string.h>
-#include <storage/storage.h>
-#include "file_helper.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern const char* const flipper_file_filetype_key;
-extern const char* const flipper_file_version_key;
-extern const char flipper_file_delimiter;
-extern const char flipper_file_comment;
-
-/**
- * Reads a valid key from a file as a string.
- * After reading, the rw pointer will be on the flipper_file_delimiter symbol.
- * Optimized not to read comments and values into RAM.
- * @param file
- * @param key
- * @return true on success read
- */
-bool flipper_file_read_valid_key(File* file, string_t key);
-
-/**
- * Sets rw pointer to the data after the key
- * @param file
- * @param key
- * @param strict
- * @return true if key was found
- */
-bool flipper_file_seek_to_key(File* file, const char* key, bool strict);
-
-/**
- * Write key and key delimiter
- * @param file
- * @param key
- * @return bool
- */
-bool flipper_file_write_key(File* file, const char* key);
-
-/**
- * Get scratchpad name and path
- * @param name
- * @return bool
- */
-bool flipper_file_get_scratchpad_name(const char** name);
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/lib/flipper_file/flipper_file_hex.c b/lib/flipper_file/flipper_file_hex.c
deleted file mode 100644
index a529dd28..00000000
--- a/lib/flipper_file/flipper_file_hex.c
+++ /dev/null
@@ -1,42 +0,0 @@
-#include <furi.h>
-
-#include "flipper_file.h"
-#include "flipper_file_i.h"
-#include "flipper_file_helper.h"
-
-static bool flipper_file_write_hex_internal(
- File* file,
- const char* key,
- const void* _data,
- const uint16_t data_size) {
- return flipper_file_write_internal(file, key, _data, data_size, FlipperFileValueHex);
-};
-
-bool flipper_file_write_hex(
- FlipperFile* flipper_file,
- const char* key,
- const uint8_t* data,
- const uint16_t data_size) {
- furi_assert(flipper_file);
- return flipper_file_write_hex_internal(flipper_file->file, key, data, data_size);
-}
-
-bool flipper_file_read_hex(
- FlipperFile* flipper_file,
- const char* key,
- uint8_t* data,
- const uint16_t data_size) {
- furi_assert(flipper_file);
- return flipper_file_read_internal(
- flipper_file->file, key, data, data_size, flipper_file->strict_mode, FlipperFileValueHex);
-}
-
-bool flipper_file_update_hex(
- FlipperFile* flipper_file,
- const char* key,
- const uint8_t* data,
- const uint16_t data_size) {
- furi_assert(flipper_file);
- return flipper_file_delete_key_and_call(
- flipper_file, key, flipper_file_write_hex_internal, key, data, data_size);
-}
diff --git a/lib/flipper_file/flipper_file_i.h b/lib/flipper_file/flipper_file_i.h
deleted file mode 100644
index 585f0b85..00000000
--- a/lib/flipper_file/flipper_file_i.h
+++ /dev/null
@@ -1,74 +0,0 @@
-#include <stdint.h>
-#include <storage/storage.h>
-
-struct FlipperFile {
- File* file;
- Storage* storage;
- bool strict_mode;
-};
-
-/**
- * Value write type callback
- */
-typedef bool (*flipper_file_cb)(File* file, const char* key, const void* data, uint16_t data_size);
-
-/**
- *
- * @param flipper_file
- * @param key
- * @param cb
- * @param cb_key
- * @param cb_data
- * @param cb_data_size
- * @return bool
- */
-bool flipper_file_delete_key_and_call(
- FlipperFile* flipper_file,
- const char* key,
- flipper_file_cb cb,
- const char* cb_key,
- const void* cb_data,
- const uint16_t cb_data_size);
-
-/**
- * Value types
- */
-typedef enum {
- FlipperFileValueHex,
- FlipperFileValueFloat,
- FlipperFileValueInt32,
- FlipperFileValueUint32,
-} FlipperFileValueType;
-
-/**
- * Internal write values function
- * @param file
- * @param key
- * @param _data
- * @param data_size
- * @param type
- * @return bool
- */
-bool flipper_file_write_internal(
- File* file,
- const char* key,
- const void* _data,
- const uint16_t data_size,
- FlipperFileValueType type);
-
-/**
- * Internal read values function
- * @param file
- * @param key
- * @param _data
- * @param data_size
- * @param type
- * @return bool
- */
-bool flipper_file_read_internal(
- File* file,
- const char* key,
- void* _data,
- const uint16_t data_size,
- bool strict_mode,
- FlipperFileValueType type);
diff --git a/lib/flipper_file/flipper_file_int32.c b/lib/flipper_file/flipper_file_int32.c
deleted file mode 100644
index 7b6b72e1..00000000
--- a/lib/flipper_file/flipper_file_int32.c
+++ /dev/null
@@ -1,42 +0,0 @@
-#include <furi.h>
-
-#include "flipper_file.h"
-#include "flipper_file_i.h"
-#include "flipper_file_helper.h"
-
-static bool flipper_file_write_int32_internal(
- File* file,
- const char* key,
- const void* _data,
- const uint16_t data_size) {
- return flipper_file_write_internal(file, key, _data, data_size, FlipperFileValueInt32);
-};
-
-bool flipper_file_read_int32(
- FlipperFile* flipper_file,
- const char* key,
- int32_t* data,
- const uint16_t data_size) {
- furi_assert(flipper_file);
- return flipper_file_read_internal(
- flipper_file->file, key, data, data_size, flipper_file->strict_mode, FlipperFileValueInt32);
-}
-
-bool flipper_file_write_int32(
- FlipperFile* flipper_file,
- const char* key,
- const int32_t* data,
- const uint16_t data_size) {
- furi_assert(flipper_file);
- return flipper_file_write_int32_internal(flipper_file->file, key, data, data_size);
-}
-
-bool flipper_file_update_int32(
- FlipperFile* flipper_file,
- const char* key,
- const int32_t* data,
- const uint16_t data_size) {
- furi_assert(flipper_file);
- return flipper_file_delete_key_and_call(
- flipper_file, key, flipper_file_write_int32_internal, key, data, data_size);
-}
diff --git a/lib/flipper_file/flipper_file_string.c b/lib/flipper_file/flipper_file_string.c
deleted file mode 100644
index de536191..00000000
--- a/lib/flipper_file/flipper_file_string.c
+++ /dev/null
@@ -1,67 +0,0 @@
-#include <furi.h>
-
-#include "flipper_file.h"
-#include "flipper_file_i.h"
-#include "flipper_file_helper.h"
-
-static bool flipper_file_write_string_internal(
- File* file,
- const char* key,
- const void* data,
- const uint16_t data_size) {
- bool result = false;
- (void)data_size;
-
- do {
- result = flipper_file_write_key(file, key);
- if(!result) break;
-
- result = file_helper_write(file, string_get_cstr(data), string_size(data));
- if(!result) break;
-
- result = file_helper_write_eol(file);
- } while(false);
-
- return result;
-};
-
-bool flipper_file_read_string(FlipperFile* flipper_file, const char* key, string_t data) {
- furi_assert(flipper_file);
-
- bool result = false;
- if(flipper_file_seek_to_key(flipper_file->file, key, flipper_file->strict_mode)) {
- if(file_helper_read_line(flipper_file->file, data)) {
- result = true;
- }
- }
- return result;
-}
-
-bool flipper_file_write_string(FlipperFile* flipper_file, const char* key, string_t data) {
- furi_assert(flipper_file);
- return flipper_file_write_string_internal(flipper_file->file, key, data, 0);
-}
-
-bool flipper_file_write_string_cstr(FlipperFile* flipper_file, const char* key, const char* data) {
- bool result = false;
- string_t value;
- string_init_set(value, data);
- result = flipper_file_write_string(flipper_file, key, value);
- string_clear(value);
- return result;
-}
-
-bool flipper_file_update_string(FlipperFile* flipper_file, const char* key, string_t data) {
- furi_assert(flipper_file);
- return flipper_file_delete_key_and_call(
- flipper_file, key, flipper_file_write_string_internal, key, data, 0);
-}
-
-bool flipper_file_update_string_cstr(FlipperFile* flipper_file, const char* key, const char* data) {
- bool result = false;
- string_t value;
- string_init_set(value, data);
- result = flipper_file_update_string(flipper_file, key, value);
- string_clear(value);
- return result;
-}
diff --git a/lib/flipper_file/flipper_file_uint32.c b/lib/flipper_file/flipper_file_uint32.c
deleted file mode 100644
index fbc62978..00000000
--- a/lib/flipper_file/flipper_file_uint32.c
+++ /dev/null
@@ -1,47 +0,0 @@
-#include <furi.h>
-
-#include "flipper_file.h"
-#include "flipper_file_i.h"
-#include "flipper_file_helper.h"
-
-static bool flipper_file_write_uint32_internal(
- File* file,
- const char* key,
- const void* _data,
- const uint16_t data_size) {
- return flipper_file_write_internal(file, key, _data, data_size, FlipperFileValueUint32);
-};
-
-bool flipper_file_read_uint32(
- FlipperFile* flipper_file,
- const char* key,
- uint32_t* data,
- const uint16_t data_size) {
- furi_assert(flipper_file);
- return flipper_file_read_internal(
- flipper_file->file,
- key,
- data,
- data_size,
- flipper_file->strict_mode,
- FlipperFileValueUint32);
-}
-
-bool flipper_file_write_uint32(
- FlipperFile* flipper_file,
- const char* key,
- const uint32_t* data,
- const uint16_t data_size) {
- furi_assert(flipper_file);
- return flipper_file_write_uint32_internal(flipper_file->file, key, data, data_size);
-}
-
-bool flipper_file_update_uint32(
- FlipperFile* flipper_file,
- const char* key,
- const uint32_t* data,
- const uint16_t data_size) {
- furi_assert(flipper_file);
- return flipper_file_delete_key_and_call(
- flipper_file, key, flipper_file_write_uint32_internal, key, data, data_size);
-}
diff --git a/lib/flipper_format/flipper_format.c b/lib/flipper_format/flipper_format.c
new file mode 100644
index 00000000..074d6da2
--- /dev/null
+++ b/lib/flipper_format/flipper_format.c
@@ -0,0 +1,410 @@
+#include <furi/check.h>
+#include <toolbox/stream/stream.h>
+#include <toolbox/stream/string_stream.h>
+#include <toolbox/stream/file_stream.h>
+#include "flipper_format.h"
+#include "flipper_format_i.h"
+#include "flipper_format_stream.h"
+#include "flipper_format_stream_i.h"
+
+/********************************** Private **********************************/
+struct FlipperFormat {
+ Stream* stream;
+ bool strict_mode;
+};
+
+static const char* const flipper_format_filetype_key = "Filetype";
+static const char* const flipper_format_version_key = "Version";
+
+Stream* flipper_format_get_raw_stream(FlipperFormat* flipper_format) {
+ return flipper_format->stream;
+}
+
+/********************************** Public **********************************/
+
+FlipperFormat* flipper_format_string_alloc() {
+ FlipperFormat* flipper_format = malloc(sizeof(FlipperFormat));
+ flipper_format->stream = string_stream_alloc();
+ flipper_format->strict_mode = false;
+ return flipper_format;
+}
+
+FlipperFormat* flipper_format_file_alloc(Storage* storage) {
+ FlipperFormat* flipper_format = malloc(sizeof(FlipperFormat));
+ flipper_format->stream = file_stream_alloc(storage);
+ flipper_format->strict_mode = false;
+ return flipper_format;
+}
+
+bool flipper_format_file_open_existing(FlipperFormat* flipper_format, const char* path) {
+ furi_assert(flipper_format);
+ return file_stream_open(flipper_format->stream, path, FSAM_READ_WRITE, FSOM_OPEN_EXISTING);
+}
+
+bool flipper_format_file_open_append(FlipperFormat* flipper_format, const char* path) {
+ furi_assert(flipper_format);
+
+ bool result =
+ file_stream_open(flipper_format->stream, path, FSAM_READ_WRITE, FSOM_OPEN_APPEND);
+
+ // Add EOL if it is not there
+ if(stream_size(flipper_format->stream) >= 1) {
+ do {
+ char last_char;
+ result = false;
+
+ if(!stream_seek(flipper_format->stream, -1, StreamOffsetFromEnd)) break;
+
+ uint16_t bytes_were_read =
+ stream_read(flipper_format->stream, (uint8_t*)&last_char, 1);
+ if(bytes_were_read != 1) break;
+
+ if(last_char != flipper_format_eoln) {
+ if(!flipper_format_stream_write_eol(flipper_format->stream)) break;
+ }
+
+ result = true;
+ } while(false);
+ } else {
+ stream_seek(flipper_format->stream, 0, StreamOffsetFromEnd);
+ }
+
+ return result;
+}
+
+bool flipper_format_file_open_always(FlipperFormat* flipper_format, const char* path) {
+ furi_assert(flipper_format);
+ return file_stream_open(flipper_format->stream, path, FSAM_READ_WRITE, FSOM_CREATE_ALWAYS);
+}
+
+bool flipper_format_file_open_new(FlipperFormat* flipper_format, const char* path) {
+ furi_assert(flipper_format);
+ return file_stream_open(flipper_format->stream, path, FSAM_READ_WRITE, FSOM_CREATE_NEW);
+}
+
+bool flipper_format_file_close(FlipperFormat* flipper_format) {
+ furi_assert(flipper_format);
+ return file_stream_close(flipper_format->stream);
+}
+
+void flipper_format_free(FlipperFormat* flipper_format) {
+ furi_assert(flipper_format);
+ stream_free(flipper_format->stream);
+ free(flipper_format);
+}
+
+void flipper_format_set_strict_mode(FlipperFormat* flipper_format, bool strict_mode) {
+ flipper_format->strict_mode = strict_mode;
+}
+
+bool flipper_format_rewind(FlipperFormat* flipper_format) {
+ furi_assert(flipper_format);
+ return stream_rewind(flipper_format->stream);
+}
+
+bool flipper_format_read_header(
+ FlipperFormat* flipper_format,
+ string_t filetype,
+ uint32_t* version) {
+ furi_assert(flipper_format);
+ return flipper_format_read_string(flipper_format, flipper_format_filetype_key, filetype) &&
+ flipper_format_read_uint32(flipper_format, flipper_format_version_key, version, 1);
+}
+
+bool flipper_format_write_header(
+ FlipperFormat* flipper_format,
+ string_t filetype,
+ const uint32_t version) {
+ furi_assert(flipper_format);
+ return flipper_format_write_header_cstr(flipper_format, string_get_cstr(filetype), version);
+}
+
+bool flipper_format_write_header_cstr(
+ FlipperFormat* flipper_format,
+ const char* filetype,
+ const uint32_t version) {
+ furi_assert(flipper_format);
+ return flipper_format_write_string_cstr(
+ flipper_format, flipper_format_filetype_key, filetype) &&
+ flipper_format_write_uint32(flipper_format, flipper_format_version_key, &version, 1);
+}
+
+bool flipper_format_get_value_count(
+ FlipperFormat* flipper_format,
+ const char* key,
+ uint32_t* count) {
+ furi_assert(flipper_format);
+ return flipper_format_stream_get_value_count(
+ flipper_format->stream, key, count, flipper_format->strict_mode);
+}
+
+bool flipper_format_read_string(FlipperFormat* flipper_format, const char* key, string_t data) {
+ furi_assert(flipper_format);
+ return flipper_format_stream_read_value_line(
+ flipper_format->stream, key, FlipperStreamValueStr, data, 1, flipper_format->strict_mode);
+}
+
+bool flipper_format_write_string(FlipperFormat* flipper_format, const char* key, string_t data) {
+ furi_assert(flipper_format);
+ FlipperStreamWriteData write_data = {
+ .key = key,
+ .type = FlipperStreamValueStr,
+ .data = string_get_cstr(data),
+ .data_size = 1,
+ };
+ bool result = flipper_format_stream_write_value_line(flipper_format->stream, &write_data);
+ return result;
+}
+
+bool flipper_format_write_string_cstr(
+ FlipperFormat* flipper_format,
+ const char* key,
+ const char* data) {
+ furi_assert(flipper_format);
+ FlipperStreamWriteData write_data = {
+ .key = key,
+ .type = FlipperStreamValueStr,
+ .data = data,
+ .data_size = 1,
+ };
+ bool result = flipper_format_stream_write_value_line(flipper_format->stream, &write_data);
+ return result;
+}
+
+bool flipper_format_read_uint32(
+ FlipperFormat* flipper_format,
+ const char* key,
+ uint32_t* data,
+ const uint16_t data_size) {
+ furi_assert(flipper_format);
+ return flipper_format_stream_read_value_line(
+ flipper_format->stream,
+ key,
+ FlipperStreamValueUint32,
+ data,
+ data_size,
+ flipper_format->strict_mode);
+}
+
+bool flipper_format_write_uint32(
+ FlipperFormat* flipper_format,
+ const char* key,
+ const uint32_t* data,
+ const uint16_t data_size) {
+ furi_assert(flipper_format);
+ FlipperStreamWriteData write_data = {
+ .key = key,
+ .type = FlipperStreamValueUint32,
+ .data = data,
+ .data_size = data_size,
+ };
+ bool result = flipper_format_stream_write_value_line(flipper_format->stream, &write_data);
+ return result;
+}
+
+bool flipper_format_read_int32(
+ FlipperFormat* flipper_format,
+ const char* key,
+ int32_t* data,
+ const uint16_t data_size) {
+ return flipper_format_stream_read_value_line(
+ flipper_format->stream,
+ key,
+ FlipperStreamValueInt32,
+ data,
+ data_size,
+ flipper_format->strict_mode);
+}
+
+bool flipper_format_write_int32(
+ FlipperFormat* flipper_format,
+ const char* key,
+ const int32_t* data,
+ const uint16_t data_size) {
+ furi_assert(flipper_format);
+ FlipperStreamWriteData write_data = {
+ .key = key,
+ .type = FlipperStreamValueInt32,
+ .data = data,
+ .data_size = data_size,
+ };
+ bool result = flipper_format_stream_write_value_line(flipper_format->stream, &write_data);
+ return result;
+}
+
+bool flipper_format_read_float(
+ FlipperFormat* flipper_format,
+ const char* key,
+ float* data,
+ const uint16_t data_size) {
+ return flipper_format_stream_read_value_line(
+ flipper_format->stream,
+ key,
+ FlipperStreamValueFloat,
+ data,
+ data_size,
+ flipper_format->strict_mode);
+}
+
+bool flipper_format_write_float(
+ FlipperFormat* flipper_format,
+ const char* key,
+ const float* data,
+ const uint16_t data_size) {
+ furi_assert(flipper_format);
+ FlipperStreamWriteData write_data = {
+ .key = key,
+ .type = FlipperStreamValueFloat,
+ .data = data,
+ .data_size = data_size,
+ };
+ bool result = flipper_format_stream_write_value_line(flipper_format->stream, &write_data);
+ return result;
+}
+
+bool flipper_format_read_hex(
+ FlipperFormat* flipper_format,
+ const char* key,
+ uint8_t* data,
+ const uint16_t data_size) {
+ return flipper_format_stream_read_value_line(
+ flipper_format->stream,
+ key,
+ FlipperStreamValueHex,
+ data,
+ data_size,
+ flipper_format->strict_mode);
+}
+
+bool flipper_format_write_hex(
+ FlipperFormat* flipper_format,
+ const char* key,
+ const uint8_t* data,
+ const uint16_t data_size) {
+ furi_assert(flipper_format);
+ FlipperStreamWriteData write_data = {
+ .key = key,
+ .type = FlipperStreamValueHex,
+ .data = data,
+ .data_size = data_size,
+ };
+ bool result = flipper_format_stream_write_value_line(flipper_format->stream, &write_data);
+ return result;
+}
+
+bool flipper_format_write_comment(FlipperFormat* flipper_format, string_t data) {
+ furi_assert(flipper_format);
+ return flipper_format_write_comment_cstr(flipper_format, string_get_cstr(data));
+}
+
+bool flipper_format_write_comment_cstr(FlipperFormat* flipper_format, const char* data) {
+ furi_assert(flipper_format);
+ return flipper_format_stream_write_comment_cstr(flipper_format->stream, data);
+}
+
+bool flipper_format_delete_key(FlipperFormat* flipper_format, const char* key) {
+ furi_assert(flipper_format);
+ FlipperStreamWriteData write_data = {
+ .key = key,
+ .type = FlipperStreamValueIgnore,
+ .data = NULL,
+ .data_size = 0,
+ };
+ bool result = flipper_format_stream_delete_key_and_write(
+ flipper_format->stream, &write_data, flipper_format->strict_mode);
+ return result;
+}
+
+bool flipper_format_update_string(FlipperFormat* flipper_format, const char* key, string_t data) {
+ furi_assert(flipper_format);
+ FlipperStreamWriteData write_data = {
+ .key = key,
+ .type = FlipperStreamValueStr,
+ .data = data,
+ .data_size = 1,
+ };
+ bool result = flipper_format_stream_delete_key_and_write(
+ flipper_format->stream, &write_data, flipper_format->strict_mode);
+ return result;
+}
+
+bool flipper_format_update_string_cstr(
+ FlipperFormat* flipper_format,
+ const char* key,
+ const char* data) {
+ furi_assert(flipper_format);
+ FlipperStreamWriteData write_data = {
+ .key = key,
+ .type = FlipperStreamValueStr,
+ .data = data,
+ .data_size = 1,
+ };
+ bool result = flipper_format_stream_delete_key_and_write(
+ flipper_format->stream, &write_data, flipper_format->strict_mode);
+ return result;
+}
+
+bool flipper_format_update_uint32(
+ FlipperFormat* flipper_format,
+ const char* key,
+ const uint32_t* data,
+ const uint16_t data_size) {
+ furi_assert(flipper_format);
+ FlipperStreamWriteData write_data = {
+ .key = key,
+ .type = FlipperStreamValueUint32,
+ .data = data,
+ .data_size = data_size,
+ };
+ bool result = flipper_format_stream_delete_key_and_write(
+ flipper_format->stream, &write_data, flipper_format->strict_mode);
+ return result;
+}
+
+bool flipper_format_update_int32(
+ FlipperFormat* flipper_format,
+ const char* key,
+ const int32_t* data,
+ const uint16_t data_size) {
+ FlipperStreamWriteData write_data = {
+ .key = key,
+ .type = FlipperStreamValueInt32,
+ .data = data,
+ .data_size = data_size,
+ };
+ bool result = flipper_format_stream_delete_key_and_write(
+ flipper_format->stream, &write_data, flipper_format->strict_mode);
+ return result;
+}
+
+bool flipper_format_update_float(
+ FlipperFormat* flipper_format,
+ const char* key,
+ const float* data,
+ const uint16_t data_size) {
+ FlipperStreamWriteData write_data = {
+ .key = key,
+ .type = FlipperStreamValueFloat,
+ .data = data,
+ .data_size = data_size,
+ };
+ bool result = flipper_format_stream_delete_key_and_write(
+ flipper_format->stream, &write_data, flipper_format->strict_mode);
+ return result;
+}
+
+bool flipper_format_update_hex(
+ FlipperFormat* flipper_format,
+ const char* key,
+ const uint8_t* data,
+ const uint16_t data_size) {
+ FlipperStreamWriteData write_data = {
+ .key = key,
+ .type = FlipperStreamValueHex,
+ .data = data,
+ .data_size = data_size,
+ };
+ bool result = flipper_format_stream_delete_key_and_write(
+ flipper_format->stream, &write_data, flipper_format->strict_mode);
+ return result;
+}
diff --git a/lib/flipper_format/flipper_format.h b/lib/flipper_format/flipper_format.h
new file mode 100644
index 00000000..c23e02fc
--- /dev/null
+++ b/lib/flipper_format/flipper_format.h
@@ -0,0 +1,471 @@
+/**
+ * @file flipper_format.h
+ * Flipper File Format helper library.
+ *
+ * Flipper File Format is a fairly simple format for storing data in a file.
+ *
+ * Flipper file structure:
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~
+ * # Commentary
+ * Field name: field value
+ * ~~~~~~~~~~~~~~~~~~~~~
+ *
+ * Lines starting with the # character are ignored (considered as comments). The separator between the name of the value and the value itself is the string ": ".
+ *
+ * Currently supported types:
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~
+ * String: text
+ * Int32: 1 2 -3 4
+ * Uint32: 1 2 3 4
+ * Float: 1.0 1234.654
+ * Hex: A4 B3 C2 D1 12 FF
+ * ~~~~~~~~~~~~~~~~~~~~~
+ *
+ * End of line is LF when writing, but CR is supported when reading.
+ *
+ * The library is designed in such a way that comments and field values are completely ignored when searching for keys, that is, they do not consume memory.
+ *
+ * File example:
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~
+ * Filetype: Flipper Test File
+ * Version: 1
+ * # Just test file
+ * String: String value
+ * UINT: 1234
+ * Hex: 00 01 FF A3
+ * ~~~~~~~~~~~~~~~~~~~~~
+ *
+ * Writing:
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~
+ * FlipperFormat format = flipper_format_file_alloc(storage);
+ *
+ * do {
+ * const uint32_t version = 1;
+ * const char* string_value = "String value";
+ * const uint32_t uint32_value = 1234;
+ * const uint16_t array_size = 4;
+ * const uint8_t* array[array_size] = {0x00, 0x01, 0xFF, 0xA3};
+ *
+ * if(!flipper_format_file_open_new(format, "/ext/flipper_format_test")) break;
+ * if(!flipper_format_write_header_cstr(format, "Flipper Test File", version)) break;
+ * if(!flipper_format_write_comment_cstr(format, "Just test file")) break;
+ * if(!flipper_format_write_string_cstr(format, "String", string_value)) break;
+ * if(!flipper_format_write_uint32(format, "UINT", &uint32_value, 1)) break;
+ * if(!flipper_format_write_hex(format, "Hex Array", array, array_size)) break;
+ *
+ * // signal that the file was written successfully
+ * } while(0);
+ *
+ * flipper_format_free(file);
+ * ~~~~~~~~~~~~~~~~~~~~~
+ *
+ * Reading:
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~
+ * FlipperFormat file = flipper_format_file_alloc(storage);
+ *
+ * do {
+ * uint32_t version = 1;
+ * string_t file_type;
+ * string_t string_value;
+ * uint32_t uint32_value = 1;
+ * uint16_t array_size = 4;
+ * uint8_t* array[array_size] = {0};
+ * string_init(file_type);
+ * string_init(string_value);
+ *
+ * if(!flipper_format_file_open_existing(file, "/ext/flipper_format_test")) break;
+ * if(!flipper_format_read_header(file, file_type, &version)) break;
+ * if(!flipper_format_read_string(file, "String", string_value)) break;
+ * if(!flipper_format_read_uint32(file, "UINT", &uint32_value, 1)) break;
+ * if(!flipper_format_read_hex(file, "Hex Array", array, array_size)) break;
+ *
+ * // signal that the file was read successfully
+ * } while(0);
+ *
+ * flipper_format_free(file);
+ * ~~~~~~~~~~~~~~~~~~~~~
+ *
+ */
+
+#pragma once
+#include <stdint.h>
+#include <mlib/m-string.h>
+#include <storage/storage.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct FlipperFormat FlipperFormat;
+
+/**
+ * Allocate FlipperFormat as string.
+ * @return FlipperFormat* pointer to a FlipperFormat instance
+ */
+FlipperFormat* flipper_format_string_alloc();
+
+/**
+ * Allocate FlipperFormat as file.
+ * @return FlipperFormat* pointer to a FlipperFormat instance
+ */
+FlipperFormat* flipper_format_file_alloc(Storage* storage);
+
+/**
+ * Open existing file.
+ * Use only if FlipperFormat allocated as a file.
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @param path File path
+ * @return True on success
+ */
+bool flipper_format_file_open_existing(FlipperFormat* flipper_format, const char* path);
+
+/**
+ * Open existing file for writing and add values to the end of file.
+ * Use only if FlipperFormat allocated as a file.
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @param path File path
+ * @return True on success
+ */
+bool flipper_format_file_open_append(FlipperFormat* flipper_format, const char* path);
+
+/**
+ * Open file. Creates a new file, or deletes the contents of the file if it already exists.
+ * Use only if FlipperFormat allocated as a file.
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @param path File path
+ * @return True on success
+ */
+bool flipper_format_file_open_always(FlipperFormat* flipper_format, const char* path);
+
+/**
+ * Open file. Creates a new file, fails if file already exists.
+ * Use only if FlipperFormat allocated as a file.
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @param path File path
+ * @return True on success
+ */
+bool flipper_format_file_open_new(FlipperFormat* flipper_format, const char* path);
+
+/**
+ * Closes the file, use only if FlipperFormat allocated as a file.
+ * @param flipper_format
+ * @return true
+ * @return false
+ */
+bool flipper_format_file_close(FlipperFormat* flipper_format);
+
+/**
+ * Free FlipperFormat.
+ * @param flipper_format Pointer to a FlipperFormat instance
+ */
+void flipper_format_free(FlipperFormat* flipper_format);
+
+/**
+ * Set FlipperFormat mode.
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @param strict_mode True obligates not to skip valid fields. False by default.
+ */
+void flipper_format_set_strict_mode(FlipperFormat* flipper_format, bool strict_mode);
+
+/**
+ * Rewind the RW pointer.
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @return True on success
+ */
+bool flipper_format_rewind(FlipperFormat* flipper_format);
+
+/**
+ * Read the header (file type and version).
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @param filetype File type string
+ * @param version Version Value
+ * @return True on success
+ */
+bool flipper_format_read_header(
+ FlipperFormat* flipper_format,
+ string_t filetype,
+ uint32_t* version);
+
+/**
+ * Write the header (file type and version).
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @param filetype File type string
+ * @param version Version Value
+ * @return True on success
+ */
+bool flipper_format_write_header(
+ FlipperFormat* flipper_format,
+ string_t filetype,
+ const uint32_t version);
+
+/**
+ * Write the header (file type and version). Plain C string version.
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @param filetype File type string
+ * @param version Version Value
+ * @return True on success
+ */
+bool flipper_format_write_header_cstr(
+ FlipperFormat* flipper_format,
+ const char* filetype,
+ const uint32_t version);
+
+/**
+ * Get the count of values by key
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @param key
+ * @param count
+ * @return bool
+ */
+bool flipper_format_get_value_count(
+ FlipperFormat* flipper_format,
+ const char* key,
+ uint32_t* count);
+
+/**
+ * Read a string by key
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @param key Key
+ * @param data Value
+ * @return True on success
+ */
+bool flipper_format_read_string(FlipperFormat* flipper_format, const char* key, string_t data);
+
+/**
+ * Write key and string
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @param key Key
+ * @param data Value
+ * @return True on success
+ */
+bool flipper_format_write_string(FlipperFormat* flipper_format, const char* key, string_t data);
+
+/**
+ * Write key and string. Plain C string version.
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @param key Key
+ * @param data Value
+ * @return True on success
+ */
+bool flipper_format_write_string_cstr(
+ FlipperFormat* flipper_format,
+ const char* key,
+ const char* data);
+
+/**
+ * Read array of uint32 by key
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @param key Key
+ * @param data Value
+ * @param data_size Values count
+ * @return True on success
+ */
+bool flipper_format_read_uint32(
+ FlipperFormat* flipper_format,
+ const char* key,
+ uint32_t* data,
+ const uint16_t data_size);
+
+/**
+ * Write key and array of uint32
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @param key Key
+ * @param data Value
+ * @param data_size Values count
+ * @return True on success
+ */
+bool flipper_format_write_uint32(
+ FlipperFormat* flipper_format,
+ const char* key,
+ const uint32_t* data,
+ const uint16_t data_size);
+
+/**
+ * Read array of int32 by key
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @param key Key
+ * @param data Value
+ * @param data_size Values count
+ * @return True on success
+ */
+bool flipper_format_read_int32(
+ FlipperFormat* flipper_format,
+ const char* key,
+ int32_t* data,
+ const uint16_t data_size);
+
+/**
+ * Write key and array of int32
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @param key Key
+ * @param data Value
+ * @param data_size Values count
+ * @return True on success
+ */
+bool flipper_format_write_int32(
+ FlipperFormat* flipper_format,
+ const char* key,
+ const int32_t* data,
+ const uint16_t data_size);
+
+/**
+ * Read array of float by key
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @param key Key
+ * @param data Value
+ * @param data_size Values count
+ * @return True on success
+ */
+bool flipper_format_read_float(
+ FlipperFormat* flipper_format,
+ const char* key,
+ float* data,
+ const uint16_t data_size);
+
+/**
+ * Write key and array of float
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @param key Key
+ * @param data Value
+ * @param data_size Values count
+ * @return True on success
+ */
+bool flipper_format_write_float(
+ FlipperFormat* flipper_format,
+ const char* key,
+ const float* data,
+ const uint16_t data_size);
+
+/**
+ * Read array of hex-formatted bytes by key
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @param key Key
+ * @param data Value
+ * @param data_size Values count
+ * @return True on success
+ */
+bool flipper_format_read_hex(
+ FlipperFormat* flipper_format,
+ const char* key,
+ uint8_t* data,
+ const uint16_t data_size);
+
+/**
+ * Write key and array of hex-formatted bytes
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @param key Key
+ * @param data Value
+ * @param data_size Values count
+ * @return True on success
+ */
+bool flipper_format_write_hex(
+ FlipperFormat* flipper_format,
+ const char* key,
+ const uint8_t* data,
+ const uint16_t data_size);
+
+/**
+ * Write comment
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @param data Comment text
+ * @return True on success
+ */
+bool flipper_format_write_comment(FlipperFormat* flipper_format, string_t data);
+
+/**
+ * Write comment. Plain C string version.
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @param data Comment text
+ * @return True on success
+ */
+bool flipper_format_write_comment_cstr(FlipperFormat* flipper_format, const char* data);
+
+/**
+ * Removes the first matching key and its value. Sets the RW pointer to a position of deleted data.
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @param key Key
+ * @return True on success
+ */
+bool flipper_format_delete_key(FlipperFormat* flipper_format, const char* key);
+
+/**
+ * Updates the value of the first matching key to a string value. Sets the RW pointer to a position at the end of inserted data.
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @param key Key
+ * @param data Value
+ * @return True on success
+ */
+bool flipper_format_update_string(FlipperFormat* flipper_format, const char* key, string_t data);
+
+/**
+ * Updates the value of the first matching key to a string value. Plain C version. Sets the RW pointer to a position at the end of inserted data.
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @param key Key
+ * @param data Value
+ * @return True on success
+ */
+bool flipper_format_update_string_cstr(
+ FlipperFormat* flipper_format,
+ const char* key,
+ const char* data);
+
+/**
+ * Updates the value of the first matching key to a uint32 array value. Sets the RW pointer to a position at the end of inserted data.
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @param key Key
+ * @param data Value
+ * @return True on success
+ */
+bool flipper_format_update_uint32(
+ FlipperFormat* flipper_format,
+ const char* key,
+ const uint32_t* data,
+ const uint16_t data_size);
+
+/**
+ * Updates the value of the first matching key to a int32 array value. Sets the RW pointer to a position at the end of inserted data.
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @param key Key
+ * @param data Value
+ * @return True on success
+ */
+bool flipper_format_update_int32(
+ FlipperFormat* flipper_format,
+ const char* key,
+ const int32_t* data,
+ const uint16_t data_size);
+
+/**
+ * Updates the value of the first matching key to a float array value. Sets the RW pointer to a position at the end of inserted data.
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @param key Key
+ * @param data Value
+ * @return True on success
+ */
+bool flipper_format_update_float(
+ FlipperFormat* flipper_format,
+ const char* key,
+ const float* data,
+ const uint16_t data_size);
+
+/**
+ * Updates the value of the first matching key to an array of hex-formatted bytes. Sets the RW pointer to a position at the end of inserted data.
+ * @param flipper_format Pointer to a FlipperFormat instance
+ * @param key Key
+ * @param data Value
+ * @return True on success
+ */
+bool flipper_format_update_hex(
+ FlipperFormat* flipper_format,
+ const char* key,
+ const uint8_t* data,
+ const uint16_t data_size);
+
+#ifdef __cplusplus
+}
+#endif \ No newline at end of file
diff --git a/lib/flipper_format/flipper_format_i.h b/lib/flipper_format/flipper_format_i.h
new file mode 100644
index 00000000..a47d4131
--- /dev/null
+++ b/lib/flipper_format/flipper_format_i.h
@@ -0,0 +1,19 @@
+#pragma once
+#include <toolbox/stream/stream.h>
+#include "flipper_format.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Returns the underlying stream instance.
+ * Use only if you know what you are doing.
+ * @param flipper_format
+ * @return Stream*
+ */
+Stream* flipper_format_get_raw_stream(FlipperFormat* flipper_format);
+
+#ifdef __cplusplus
+}
+#endif \ No newline at end of file
diff --git a/lib/flipper_format/flipper_format_stream.c b/lib/flipper_format/flipper_format_stream.c
new file mode 100644
index 00000000..02425d63
--- /dev/null
+++ b/lib/flipper_format/flipper_format_stream.c
@@ -0,0 +1,497 @@
+#include <inttypes.h>
+#include <toolbox/hex.h>
+#include <furi/check.h>
+#include "flipper_format_stream.h"
+#include "flipper_format_stream_i.h"
+
+static bool flipper_format_stream_write(Stream* stream, const void* data, size_t data_size) {
+ size_t bytes_written = stream_write(stream, data, data_size);
+ return bytes_written == data_size;
+}
+
+static bool flipper_format_stream_write_key(Stream* stream, const char* key) {
+ bool result = false;
+
+ do {
+ if(!flipper_format_stream_write(stream, key, strlen(key))) break;
+ if(!flipper_format_stream_write(stream, &flipper_format_delimiter, 1)) break;
+ if(!flipper_format_stream_write(stream, " ", 1)) break;
+ result = true;
+ } while(false);
+
+ return result;
+}
+
+bool flipper_format_stream_write_eol(Stream* stream) {
+ return flipper_format_stream_write(stream, &flipper_format_eoln, 1);
+}
+
+static bool flipper_format_stream_read_valid_key(Stream* stream, string_t key) {
+ string_reset(key);
+ const size_t buffer_size = 32;
+ uint8_t buffer[buffer_size];
+
+ bool found = false;
+ bool error = false;
+ bool accumulate = true;
+ bool new_line = true;
+
+ while(true) {
+ size_t was_read = stream_read(stream, buffer, buffer_size);
+ if(was_read == 0) break;
+
+ for(size_t i = 0; i < was_read; i++) {
+ uint8_t data = buffer[i];
+ if(data == flipper_format_eoln) {
+ // EOL found, clean data, start accumulating data and set the new_line flag
+ string_reset(key);
+ accumulate = true;
+ new_line = true;
+ } else if(data == flipper_format_eolr) {
+ // ignore
+ } else if(data == flipper_format_comment && new_line) {
+ // if there is a comment character and we are at the beginning of a new line
+ // do not accumulate comment data and reset the new_line flag
+ accumulate = false;
+ new_line = false;
+ } else if(data == flipper_format_delimiter) {
+ if(new_line) {
+ // we are on a "new line" and found the delimiter
+ // this can only be if we have previously found some kind of key, so
+ // clear the data, set the flag that we no longer want to accumulate data
+ // and reset the new_line flag
+ string_reset(key);
+ accumulate = false;
+ new_line = false;
+ } else {
+ // parse the delimiter only if we are accumulating data
+ if(accumulate) {
+ // we found the delimiter, move the rw pointer to the delimiter location
+ // and signal that we have found something
+ if(!stream_seek(stream, i - was_read, StreamOffsetFromCurrent)) {
+ error = true;
+ break;
+ }
+
+ found = true;
+ break;
+ }
+ }
+ } else {
+ // just new symbol, reset the new_line flag
+ new_line = false;
+ if(accumulate) {
+ // and accumulate data if we want
+ string_push_back(key, data);
+ }
+ }
+ }
+
+ if(found || error) break;
+ }
+
+ return found;
+}
+
+static bool flipper_format_stream_seek_to_key(Stream* stream, const char* key, bool strict_mode) {
+ bool found = false;
+ string_t read_key;
+
+ string_init(read_key);
+
+ while(!stream_eof(stream)) {
+ if(flipper_format_stream_read_valid_key(stream, read_key)) {
+ if(string_cmp_str(read_key, key) == 0) {
+ if(!stream_seek(stream, 2, StreamOffsetFromCurrent)) break;
+
+ found = true;
+ break;
+ } else if(strict_mode) {
+ found = false;
+ break;
+ }
+ }
+ }
+ string_clear(read_key);
+
+ return found;
+}
+
+static bool flipper_format_stream_read_value(Stream* stream, string_t value, bool* last) {
+ string_reset(value);
+ const size_t buffer_size = 32;
+ uint8_t buffer[buffer_size];
+ bool result = false;
+ bool error = false;
+
+ while(true) {
+ size_t was_read = stream_read(stream, buffer, buffer_size);
+
+ if(was_read == 0) {
+ // check EOF
+ if(stream_eof(stream) && string_size(value) > 0) {
+ result = true;
+ *last = true;
+ break;
+ }
+ }
+
+ for(uint16_t i = 0; i < was_read; i++) {
+ uint8_t data = buffer[i];
+ if(data == flipper_format_eoln) {
+ if(string_size(value) > 0) {
+ if(!stream_seek(stream, i - was_read, StreamOffsetFromCurrent)) {
+ error = true;
+ break;
+ }
+
+ result = true;
+ *last = true;
+ break;
+ } else {
+ error = true;
+ }
+ } else if(data == ' ') {
+ if(string_size(value) > 0) {
+ if(!stream_seek(stream, i - was_read, StreamOffsetFromCurrent)) {
+ error = true;
+ break;
+ }
+
+ result = true;
+ *last = false;
+ break;
+ }
+
+ } else if(data == flipper_format_eolr) {
+ // Ignore
+ } else {
+ string_push_back(value, data);
+ }
+ }
+
+ if(error || result) break;
+ }
+
+ return result;
+}
+
+static bool flipper_format_stream_read_line(Stream* stream, string_t str_result) {
+ string_reset(str_result);
+ const size_t buffer_size = 32;
+ uint8_t buffer[buffer_size];
+
+ do {
+ size_t was_read = stream_read(stream, buffer, buffer_size);
+ if(was_read == 0) break;
+
+ bool result = false;
+ bool error = false;
+
+ for(size_t i = 0; i < was_read; i++) {
+ uint8_t data = buffer[i];
+ if(data == flipper_format_eoln) {
+ if(!stream_seek(stream, i - was_read, StreamOffsetFromCurrent)) {
+ error = true;
+ break;
+ }
+
+ result = true;
+ break;
+ } else if(data == flipper_format_eolr) {
+ // Ignore
+ } else {
+ string_push_back(str_result, data);
+ }
+ }
+
+ if(result || error) {
+ break;
+ }
+ } while(true);
+
+ return string_size(str_result) != 0;
+}
+
+static bool flipper_format_stream_seek_to_next_line(Stream* stream) {
+ const size_t buffer_size = 32;
+ uint8_t buffer[buffer_size];
+ bool result = false;
+ bool error = false;
+
+ do {
+ size_t was_read = stream_read(stream, buffer, buffer_size);
+ if(was_read == 0) {
+ if(stream_eof(stream)) {
+ result = true;
+ break;
+ }
+ }
+
+ for(size_t i = 0; i < was_read; i++) {
+ if(buffer[i] == flipper_format_eoln) {
+ if(!stream_seek(stream, i - was_read, StreamOffsetFromCurrent)) {
+ error = true;
+ break;
+ }
+
+ result = true;
+ break;
+ }
+ }
+
+ if(result || error) {
+ break;
+ }
+ } while(true);
+
+ return result;
+}
+
+bool flipper_format_stream_write_value_line(Stream* stream, FlipperStreamWriteData* write_data) {
+ bool result = false;
+
+ if(write_data->type == FlipperStreamValueIgnore) {
+ result = true;
+ } else {
+ string_t value;
+ string_init(value);
+
+ do {
+ if(!flipper_format_stream_write_key(stream, write_data->key)) break;
+
+ if(write_data->type == FlipperStreamValueStr) write_data->data_size = 1;
+
+ bool cycle_error = false;
+ for(uint16_t i = 0; i < write_data->data_size; i++) {
+ switch(write_data->type) {
+ case FlipperStreamValueStr: {
+ const char* data = write_data->data;
+ string_printf(value, "%s", data);
+ }; break;
+ case FlipperStreamValueHex: {
+ const uint8_t* data = write_data->data;
+ string_printf(value, "%02X", data[i]);
+ }; break;
+ case FlipperStreamValueFloat: {
+ const float* data = write_data->data;
+ string_printf(value, "%f", data[i]);
+ }; break;
+ case FlipperStreamValueInt32: {
+ const int32_t* data = write_data->data;
+ string_printf(value, "%" PRIi32, data[i]);
+ }; break;
+ case FlipperStreamValueUint32: {
+ const uint32_t* data = write_data->data;
+ string_printf(value, "%" PRId32, data[i]);
+ }; break;
+ default:
+ furi_crash("Unknown FF type");
+ }
+
+ if((i + 1) < write_data->data_size) {
+ string_cat(value, " ");
+ }
+
+ if(!flipper_format_stream_write(
+ stream, string_get_cstr(value), string_size(value))) {
+ cycle_error = true;
+ break;
+ }
+ }
+ if(cycle_error) break;
+
+ if(!flipper_format_stream_write_eol(stream)) break;
+ result = true;
+ } while(false);
+
+ string_clear(value);
+ }
+
+ return result;
+}
+
+bool flipper_format_stream_read_value_line(
+ Stream* stream,
+ const char* key,
+ FlipperStreamValue type,
+ void* _data,
+ size_t data_size,
+ bool strict_mode) {
+ bool result = false;
+
+ do {
+ if(!flipper_format_stream_seek_to_key(stream, key, strict_mode)) break;
+
+ if(type == FlipperStreamValueStr) {
+ string_ptr data = (string_ptr)_data;
+ if(flipper_format_stream_read_line(stream, data)) {
+ result = true;
+ break;
+ }
+ } else {
+ result = true;
+ string_t value;
+ string_init(value);
+
+ for(uint16_t i = 0; i < data_size; i++) {
+ bool last = false;
+ result = flipper_format_stream_read_value(stream, value, &last);
+ if(result) {
+ int scan_values = 0;
+
+ switch(type) {
+ case FlipperStreamValueHex: {
+ uint8_t* data = _data;
+ if(string_size(value) >= 2) {
+ // sscanf "%02X" does not work here
+ if(hex_chars_to_uint8(
+ string_get_char(value, 0),
+ string_get_char(value, 1),
+ &data[i])) {
+ scan_values = 1;
+ }
+ }
+ }; break;
+ case FlipperStreamValueFloat: {
+ float* data = _data;
+ // newlib-nano does not have sscanf for floats
+ // scan_values = sscanf(string_get_cstr(value), "%f", &data[i]);
+ char* end_char;
+ data[i] = strtof(string_get_cstr(value), &end_char);
+ if(*end_char == 0) {
+ // most likely ok
+ scan_values = 1;
+ }
+ }; break;
+ case FlipperStreamValueInt32: {
+ int32_t* data = _data;
+ scan_values = sscanf(string_get_cstr(value), "%" PRIi32, &data[i]);
+ }; break;
+ case FlipperStreamValueUint32: {
+ uint32_t* data = _data;
+ scan_values = sscanf(string_get_cstr(value), "%" PRId32, &data[i]);
+ }; break;
+ default:
+ furi_crash("Unknown FF type");
+ }
+
+ if(scan_values != 1) {
+ result = false;
+ break;
+ }
+ } else {
+ break;
+ }
+
+ if(last && ((i + 1) != data_size)) {
+ result = false;
+ break;
+ }
+ }
+
+ string_clear(value);
+ }
+ } while(false);
+
+ return result;
+}
+
+bool flipper_format_stream_get_value_count(
+ Stream* stream,
+ const char* key,
+ uint32_t* count,
+ bool strict_mode) {
+ bool result = false;
+ bool last = false;
+
+ string_t value;
+ string_init(value);
+
+ uint32_t position = stream_tell(stream);
+ do {
+ if(!flipper_format_stream_seek_to_key(stream, key, strict_mode)) break;
+ *count = 0;
+
+ result = true;
+ while(true) {
+ if(!flipper_format_stream_read_value(stream, value, &last)) {
+ result = false;
+ break;
+ }
+
+ *count = *count + 1;
+ if(last) break;
+ }
+
+ } while(false);
+
+ if(!stream_seek(stream, position, StreamOffsetFromStart)) {
+ result = false;
+ }
+
+ string_clear(value);
+ return result;
+}
+
+bool flipper_format_stream_delete_key_and_write(
+ Stream* stream,
+ FlipperStreamWriteData* write_data,
+ bool strict_mode) {
+ bool result = false;
+
+ do {
+ size_t size = stream_size(stream);
+ if(size == 0) break;
+
+ if(!stream_rewind(stream)) break;
+
+ // find key
+ if(!flipper_format_stream_seek_to_key(stream, write_data->key, strict_mode)) break;
+
+ // get key start position
+ size_t start_position = stream_tell(stream) - strlen(write_data->key);
+ if(start_position >= 2) {
+ start_position -= 2;
+ } else {
+ // something wrong
+ break;
+ }
+
+ // get value end position
+ if(!flipper_format_stream_seek_to_next_line(stream)) break;
+ size_t end_position = stream_tell(stream);
+ // newline symbol
+ if(end_position < size) {
+ end_position += 1;
+ }
+
+ if(!stream_seek(stream, start_position, StreamOffsetFromStart)) break;
+ if(!stream_delete_and_insert(
+ stream,
+ end_position - start_position,
+ (StreamWriteCB)flipper_format_stream_write_value_line,
+ write_data))
+ break;
+
+ result = true;
+ } while(false);
+
+ return result;
+}
+
+bool flipper_format_stream_write_comment_cstr(Stream* stream, const char* data) {
+ bool result = false;
+ do {
+ const char comment_buffer[2] = {flipper_format_comment, ' '};
+ result = flipper_format_stream_write(stream, comment_buffer, sizeof(comment_buffer));
+ if(!result) break;
+
+ result = flipper_format_stream_write(stream, data, strlen(data));
+ if(!result) break;
+
+ result = flipper_format_stream_write_eol(stream);
+ } while(false);
+
+ return result;
+}
diff --git a/lib/flipper_format/flipper_format_stream.h b/lib/flipper_format/flipper_format_stream.h
new file mode 100644
index 00000000..6bf50c57
--- /dev/null
+++ b/lib/flipper_format/flipper_format_stream.h
@@ -0,0 +1,94 @@
+#pragma once
+#include <stdlib.h>
+#include <stdbool.h>
+#include <toolbox/stream/stream.h>
+#include <mlib/m-string.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+ FlipperStreamValueIgnore,
+ FlipperStreamValueStr,
+ FlipperStreamValueHex,
+ FlipperStreamValueFloat,
+ FlipperStreamValueInt32,
+ FlipperStreamValueUint32,
+} FlipperStreamValue;
+
+typedef struct {
+ const char* key;
+ FlipperStreamValue type;
+ const void* data;
+ size_t data_size;
+} FlipperStreamWriteData;
+
+/**
+ * Writes a key/value pair to the stream.
+ * @param stream
+ * @param write_data
+ * @return true
+ * @return false
+ */
+bool flipper_format_stream_write_value_line(Stream* stream, FlipperStreamWriteData* write_data);
+
+/**
+ * Reads a value by key from a stream.
+ * @param stream
+ * @param key
+ * @param type
+ * @param _data
+ * @param data_size
+ * @param strict_mode
+ * @return true
+ * @return false
+ */
+bool flipper_format_stream_read_value_line(
+ Stream* stream,
+ const char* key,
+ FlipperStreamValue type,
+ void* _data,
+ size_t data_size,
+ bool strict_mode);
+
+/**
+ * Get the count of values by key from a stream.
+ * @param stream
+ * @param key
+ * @param count
+ * @param strict_mode
+ * @return true
+ * @return false
+ */
+bool flipper_format_stream_get_value_count(
+ Stream* stream,
+ const char* key,
+ uint32_t* count,
+ bool strict_mode);
+
+/**
+ * Removes a key and the corresponding value string from the stream and inserts a new key/value pair.
+ * @param stream
+ * @param write_data
+ * @param strict_mode
+ * @return true
+ * @return false
+ */
+bool flipper_format_stream_delete_key_and_write(
+ Stream* stream,
+ FlipperStreamWriteData* write_data,
+ bool strict_mode);
+
+/**
+ * Writes a comment string to the stream.
+ * @param stream
+ * @param data
+ * @return true
+ * @return false
+ */
+bool flipper_format_stream_write_comment_cstr(Stream* stream, const char* data);
+
+#ifdef __cplusplus
+}
+#endif \ No newline at end of file
diff --git a/lib/flipper_format/flipper_format_stream_i.h b/lib/flipper_format/flipper_format_stream_i.h
new file mode 100644
index 00000000..ee825d0e
--- /dev/null
+++ b/lib/flipper_format/flipper_format_stream_i.h
@@ -0,0 +1,23 @@
+#pragma once
+#include "flipper_format_stream.h"
+
+static const char flipper_format_delimiter = ':';
+static const char flipper_format_comment = '#';
+static const char flipper_format_eoln = '\n';
+static const char flipper_format_eolr = '\r';
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Write Flipper Format EOL to the stream
+ * @param stream
+ * @return true
+ * @return false
+ */
+bool flipper_format_stream_write_eol(Stream* stream);
+
+#ifdef __cplusplus
+}
+#endif \ No newline at end of file
diff --git a/lib/heatshrink/heatshrink_config.h b/lib/heatshrink/heatshrink_config.h
index 270eeede..7f2373c0 100644
--- a/lib/heatshrink/heatshrink_config.h
+++ b/lib/heatshrink/heatshrink_config.h
@@ -10,7 +10,7 @@
#if HEATSHRINK_DYNAMIC_ALLOC
/* Optional replacement of malloc/free */
- #define HEATSHRINK_MALLOC(SZ) furi_alloc(SZ)
+ #define HEATSHRINK_MALLOC(SZ) malloc(SZ)
#define HEATSHRINK_FREE(P, SZ) free(P)
#else
/* Required parameters for static configuration */
diff --git a/lib/irda/encoder_decoder/common/irda_common_decoder.c b/lib/irda/encoder_decoder/common/irda_common_decoder.c
index 47df62d3..9e597925 100644
--- a/lib/irda/encoder_decoder/common/irda_common_decoder.c
+++ b/lib/irda/encoder_decoder/common/irda_common_decoder.c
@@ -283,7 +283,7 @@ void* irda_common_decoder_alloc(const IrdaCommonProtocolSpec* protocol) {
uint32_t alloc_size = sizeof(IrdaCommonDecoder) + protocol->databit_len[0] / 8 +
!!(protocol->databit_len[0] % 8);
- IrdaCommonDecoder* decoder = furi_alloc(alloc_size);
+ IrdaCommonDecoder* decoder = malloc(alloc_size);
decoder->protocol = protocol;
decoder->level = true;
return decoder;
diff --git a/lib/irda/encoder_decoder/common/irda_common_encoder.c b/lib/irda/encoder_decoder/common/irda_common_encoder.c
index b42c16a4..81067650 100644
--- a/lib/irda/encoder_decoder/common/irda_common_encoder.c
+++ b/lib/irda/encoder_decoder/common/irda_common_encoder.c
@@ -148,7 +148,7 @@ void* irda_common_encoder_alloc(const IrdaCommonProtocolSpec* protocol) {
uint32_t alloc_size = sizeof(IrdaCommonDecoder) + protocol->databit_len[0] / 8 +
!!(protocol->databit_len[0] % 8);
- IrdaCommonEncoder* encoder = furi_alloc(alloc_size);
+ IrdaCommonEncoder* encoder = malloc(alloc_size);
memset(encoder, 0, alloc_size);
encoder->protocol = protocol;
diff --git a/lib/irda/encoder_decoder/irda.c b/lib/irda/encoder_decoder/irda.c
index 0fad0d89..f6fbb6af 100644
--- a/lib/irda/encoder_decoder/irda.c
+++ b/lib/irda/encoder_decoder/irda.c
@@ -134,8 +134,8 @@ const IrdaMessage* irda_decode(IrdaDecoderHandler* handler, bool level, uint32_t
}
IrdaDecoderHandler* irda_alloc_decoder(void) {
- IrdaDecoderHandler* handler = furi_alloc(sizeof(IrdaDecoderHandler));
- handler->ctx = furi_alloc(sizeof(void*) * COUNT_OF(irda_encoder_decoder));
+ IrdaDecoderHandler* handler = malloc(sizeof(IrdaDecoderHandler));
+ handler->ctx = malloc(sizeof(void*) * COUNT_OF(irda_encoder_decoder));
for(int i = 0; i < COUNT_OF(irda_encoder_decoder); ++i) {
handler->ctx[i] = 0;
@@ -186,7 +186,7 @@ const IrdaMessage* irda_check_decoder_ready(IrdaDecoderHandler* handler) {
}
IrdaEncoderHandler* irda_alloc_encoder(void) {
- IrdaEncoderHandler* handler = furi_alloc(sizeof(IrdaEncoderHandler));
+ IrdaEncoderHandler* handler = malloc(sizeof(IrdaEncoderHandler));
handler->handler = NULL;
handler->encoder = NULL;
return handler;
diff --git a/lib/irda/encoder_decoder/rc5/irda_decoder_rc5.c b/lib/irda/encoder_decoder/rc5/irda_decoder_rc5.c
index 0afd30c3..a9c72e65 100644
--- a/lib/irda/encoder_decoder/rc5/irda_decoder_rc5.c
+++ b/lib/irda/encoder_decoder/rc5/irda_decoder_rc5.c
@@ -58,7 +58,7 @@ bool irda_decoder_rc5_interpret(IrdaCommonDecoder* decoder) {
}
void* irda_decoder_rc5_alloc(void) {
- IrdaRc5Decoder* decoder = furi_alloc(sizeof(IrdaRc5Decoder));
+ IrdaRc5Decoder* decoder = malloc(sizeof(IrdaRc5Decoder));
decoder->toggle = false;
decoder->common_decoder = irda_common_decoder_alloc(&protocol_rc5);
decoder->common_decoder->context = decoder;
diff --git a/lib/irda/encoder_decoder/rc5/irda_encoder_rc5.c b/lib/irda/encoder_decoder/rc5/irda_encoder_rc5.c
index 8d234186..36e742cd 100644
--- a/lib/irda/encoder_decoder/rc5/irda_encoder_rc5.c
+++ b/lib/irda/encoder_decoder/rc5/irda_encoder_rc5.c
@@ -40,7 +40,7 @@ IrdaStatus irda_encoder_rc5_encode(void* encoder_ptr, uint32_t* duration, bool*
}
void* irda_encoder_rc5_alloc(void) {
- IrdaEncoderRC5* encoder = furi_alloc(sizeof(IrdaEncoderRC5));
+ IrdaEncoderRC5* encoder = malloc(sizeof(IrdaEncoderRC5));
encoder->common_encoder = irda_common_encoder_alloc(&protocol_rc5);
encoder->toggle_bit = false;
return encoder;
diff --git a/lib/irda/encoder_decoder/rc6/irda_decoder_rc6.c b/lib/irda/encoder_decoder/rc6/irda_decoder_rc6.c
index 0899b3cc..a38d2c77 100644
--- a/lib/irda/encoder_decoder/rc6/irda_decoder_rc6.c
+++ b/lib/irda/encoder_decoder/rc6/irda_decoder_rc6.c
@@ -89,7 +89,7 @@ IrdaStatus
}
void* irda_decoder_rc6_alloc(void) {
- IrdaRc6Decoder* decoder = furi_alloc(sizeof(IrdaRc6Decoder));
+ IrdaRc6Decoder* decoder = malloc(sizeof(IrdaRc6Decoder));
decoder->toggle = false;
decoder->common_decoder = irda_common_decoder_alloc(&protocol_rc6);
decoder->common_decoder->context = decoder;
diff --git a/lib/irda/encoder_decoder/rc6/irda_encoder_rc6.c b/lib/irda/encoder_decoder/rc6/irda_encoder_rc6.c
index 85710506..41a397cf 100644
--- a/lib/irda/encoder_decoder/rc6/irda_encoder_rc6.c
+++ b/lib/irda/encoder_decoder/rc6/irda_encoder_rc6.c
@@ -34,7 +34,7 @@ IrdaStatus irda_encoder_rc6_encode(void* encoder_ptr, uint32_t* duration, bool*
}
void* irda_encoder_rc6_alloc(void) {
- IrdaEncoderRC6* encoder = furi_alloc(sizeof(IrdaEncoderRC6));
+ IrdaEncoderRC6* encoder = malloc(sizeof(IrdaEncoderRC6));
encoder->common_encoder = irda_common_encoder_alloc(&protocol_rc6);
encoder->toggle_bit = false;
return encoder;
diff --git a/lib/irda/worker/irda_worker.c b/lib/irda/worker/irda_worker.c
index 0f9d3660..18de4f15 100644
--- a/lib/irda/worker/irda_worker.c
+++ b/lib/irda/worker/irda_worker.c
@@ -218,7 +218,7 @@ void irda_worker_rx_set_received_signal_callback(
}
IrdaWorker* irda_worker_alloc() {
- IrdaWorker* instance = furi_alloc(sizeof(IrdaWorker));
+ IrdaWorker* instance = malloc(sizeof(IrdaWorker));
instance->thread = furi_thread_alloc();
furi_thread_set_name(instance->thread, "IrdaWorker");
diff --git a/lib/lib.mk b/lib/lib.mk
index 9b6001c6..09f929f1 100644
--- a/lib/lib.mk
+++ b/lib/lib.mk
@@ -82,10 +82,6 @@ CFLAGS += -I$(LIB_DIR)/common-api
CFLAGS += -I$(LIB_DIR)/drivers
C_SOURCES += $(wildcard $(LIB_DIR)/drivers/*.c)
-#file reader
-CFLAGS += -I$(LIB_DIR)/file_reader
-CPP_SOURCES += $(wildcard $(LIB_DIR)/file_reader/*.cpp)
-
# IR lib
CFLAGS += -I$(LIB_DIR)/irda/encoder_decoder
CFLAGS += -I$(LIB_DIR)/irda/worker
@@ -105,7 +101,9 @@ CPP_SOURCES += $(wildcard $(LIB_DIR)/app-scened-template/*/*.cpp)
# Toolbox
C_SOURCES += $(wildcard $(LIB_DIR)/toolbox/*.c)
+C_SOURCES += $(wildcard $(LIB_DIR)/toolbox/*/*.c)
CPP_SOURCES += $(wildcard $(LIB_DIR)/toolbox/*.cpp)
+CPP_SOURCES += $(wildcard $(LIB_DIR)/toolbox/*/*.cpp)
# USB Stack
CFLAGS += -I$(LIB_DIR)/libusb_stm32/inc
@@ -123,6 +121,10 @@ C_SOURCES += $(wildcard $(LIB_DIR)/heatshrink/*.c)
CFLAGS += -I$(LIB_DIR)/flipper_file
C_SOURCES += $(wildcard $(LIB_DIR)/flipper_file/*.c)
+# Flipper format
+CFLAGS += -I$(LIB_DIR)/flipper_format
+C_SOURCES += $(wildcard $(LIB_DIR)/flipper_format/*.c)
+
# Micro-ECC
CFLAGS += -I$(LIB_DIR)/micro-ecc
C_SOURCES += $(wildcard $(LIB_DIR)/micro-ecc/*.c)
diff --git a/lib/subghz/protocols/subghz_protocol_came.c b/lib/subghz/protocols/subghz_protocol_came.c
index 47597775..a84f8248 100644
--- a/lib/subghz/protocols/subghz_protocol_came.c
+++ b/lib/subghz/protocols/subghz_protocol_came.c
@@ -19,7 +19,7 @@ typedef enum {
} CameDecoderStep;
SubGhzProtocolCame* subghz_protocol_came_alloc() {
- SubGhzProtocolCame* instance = furi_alloc(sizeof(SubGhzProtocolCame));
+ SubGhzProtocolCame* instance = malloc(sizeof(SubGhzProtocolCame));
instance->common.name = "CAME";
instance->common.code_min_count_bit_for_found = 12;
@@ -167,16 +167,16 @@ void subghz_protocol_came_to_str(SubGhzProtocolCame* instance, string_t output)
code_found_reverse_lo);
}
-bool subghz_protocol_came_to_save_file(SubGhzProtocolCame* instance, FlipperFile* flipper_file) {
- return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_file);
+bool subghz_protocol_came_to_save_file(SubGhzProtocolCame* instance, FlipperFormat* flipper_format) {
+ return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_format);
}
bool subghz_protocol_came_to_load_protocol_from_file(
- FlipperFile* flipper_file,
+ FlipperFormat* flipper_format,
SubGhzProtocolCame* instance,
const char* file_path) {
return subghz_protocol_common_to_load_protocol_from_file(
- (SubGhzProtocolCommon*)instance, flipper_file);
+ (SubGhzProtocolCommon*)instance, flipper_format);
}
void subghz_decoder_came_to_load_protocol(SubGhzProtocolCame* instance, void* context) {
diff --git a/lib/subghz/protocols/subghz_protocol_came.h b/lib/subghz/protocols/subghz_protocol_came.h
index 22805c6b..5d6790da 100644
--- a/lib/subghz/protocols/subghz_protocol_came.h
+++ b/lib/subghz/protocols/subghz_protocol_came.h
@@ -48,20 +48,20 @@ void subghz_protocol_came_to_str(SubGhzProtocolCame* instance, string_t output);
/** Adding data to a file
*
* @param instance - SubGhzProtocolCame instance
- * @param flipper_file - FlipperFile
+ * @param flipper_format - FlipperFormat
* @return bool
*/
-bool subghz_protocol_came_to_save_file(SubGhzProtocolCame* instance, FlipperFile* flipper_file);
+bool subghz_protocol_came_to_save_file(SubGhzProtocolCame* instance, FlipperFormat* flipper_format);
/** Loading protocol from file
*
- * @param flipper_file - FlipperFile
+ * @param flipper_format - FlipperFormat
* @param instance - SubGhzProtocolCame instance
* @param file_path - file path
* @return bool
*/
bool subghz_protocol_came_to_load_protocol_from_file(
- FlipperFile* flipper_file,
+ FlipperFormat* flipper_format,
SubGhzProtocolCame* instance,
const char* file_path);
diff --git a/lib/subghz/protocols/subghz_protocol_came_atomo.c b/lib/subghz/protocols/subghz_protocol_came_atomo.c
index 4565dee2..6bcb336b 100644
--- a/lib/subghz/protocols/subghz_protocol_came_atomo.c
+++ b/lib/subghz/protocols/subghz_protocol_came_atomo.c
@@ -19,7 +19,7 @@ typedef enum {
} CameAtomoDecoderStep;
SubGhzProtocolCameAtomo* subghz_protocol_came_atomo_alloc() {
- SubGhzProtocolCameAtomo* instance = furi_alloc(sizeof(SubGhzProtocolCameAtomo));
+ SubGhzProtocolCameAtomo* instance = malloc(sizeof(SubGhzProtocolCameAtomo));
instance->common.name = "CAME Atomo";
instance->common.code_min_count_bit_for_found = 62;
diff --git a/lib/subghz/protocols/subghz_protocol_came_twee.c b/lib/subghz/protocols/subghz_protocol_came_twee.c
index df55f2f2..714cdf58 100644
--- a/lib/subghz/protocols/subghz_protocol_came_twee.c
+++ b/lib/subghz/protocols/subghz_protocol_came_twee.c
@@ -27,7 +27,7 @@ typedef enum {
} CameTweeDecoderStep;
SubGhzProtocolCameTwee* subghz_protocol_came_twee_alloc() {
- SubGhzProtocolCameTwee* instance = furi_alloc(sizeof(SubGhzProtocolCameTwee));
+ SubGhzProtocolCameTwee* instance = malloc(sizeof(SubGhzProtocolCameTwee));
instance->common.name = "CAME TWEE";
instance->common.code_min_count_bit_for_found = 54;
@@ -327,16 +327,16 @@ void subghz_protocol_came_twee_to_str(SubGhzProtocolCameTwee* instance, string_t
bool subghz_protocol_came_twee_to_save_file(
SubGhzProtocolCameTwee* instance,
- FlipperFile* flipper_file) {
- return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_file);
+ FlipperFormat* flipper_format) {
+ return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_format);
}
bool subghz_protocol_came_twee_to_load_protocol_from_file(
- FlipperFile* flipper_file,
+ FlipperFormat* flipper_format,
SubGhzProtocolCameTwee* instance,
const char* file_path) {
if(subghz_protocol_common_to_load_protocol_from_file(
- (SubGhzProtocolCommon*)instance, flipper_file)) {
+ (SubGhzProtocolCommon*)instance, flipper_format)) {
subghz_protocol_came_twee_remote_controller(instance);
return true;
}
diff --git a/lib/subghz/protocols/subghz_protocol_came_twee.h b/lib/subghz/protocols/subghz_protocol_came_twee.h
index 32e17eff..decb723c 100644
--- a/lib/subghz/protocols/subghz_protocol_came_twee.h
+++ b/lib/subghz/protocols/subghz_protocol_came_twee.h
@@ -51,22 +51,22 @@ void subghz_protocol_came_twee_to_str(SubGhzProtocolCameTwee* instance, string_t
/** Adding data to a file
*
* @param instance - SubGhzProtocolCameTwee instance
- * @param flipper_file - FlipperFile
+ * @param flipper_format - FlipperFormat
* @return bool
*/
bool subghz_protocol_came_twee_to_save_file(
SubGhzProtocolCameTwee* instance,
- FlipperFile* flipper_file);
+ FlipperFormat* flipper_format);
/** Loading protocol from file
*
- * @param flipper_file - FlipperFile
+ * @param flipper_format - FlipperFormat
* @param instance - SubGhzProtocolCameTwee instance
* @param file_path - file path
* @return bool
*/
bool subghz_protocol_came_twee_to_load_protocol_from_file(
- FlipperFile* flipper_file,
+ FlipperFormat* flipper_format,
SubGhzProtocolCameTwee* instance,
const char* file_path);
diff --git a/lib/subghz/protocols/subghz_protocol_common.c b/lib/subghz/protocols/subghz_protocol_common.c
index 3080a44b..b1119a39 100644
--- a/lib/subghz/protocols/subghz_protocol_common.c
+++ b/lib/subghz/protocols/subghz_protocol_common.c
@@ -3,8 +3,8 @@
#include <lib/toolbox/hex.h>
SubGhzProtocolCommonEncoder* subghz_protocol_encoder_common_alloc() {
- SubGhzProtocolCommonEncoder* instance = furi_alloc(sizeof(SubGhzProtocolCommonEncoder));
- instance->upload = furi_alloc(SUBGHZ_ENCODER_UPLOAD_MAX_SIZE * sizeof(LevelDuration));
+ SubGhzProtocolCommonEncoder* instance = malloc(sizeof(SubGhzProtocolCommonEncoder));
+ instance->upload = malloc(SUBGHZ_ENCODER_UPLOAD_MAX_SIZE * sizeof(LevelDuration));
instance->start = true;
instance->repeat = 10; //default number of repeat
return instance;
@@ -169,17 +169,19 @@ bool subghz_protocol_common_read_hex(string_t str, uint8_t* buff, uint16_t len)
return parsed;
}
-bool subghz_protocol_common_to_save_file(SubGhzProtocolCommon* instance, FlipperFile* flipper_file) {
+bool subghz_protocol_common_to_save_file(
+ SubGhzProtocolCommon* instance,
+ FlipperFormat* flipper_format) {
furi_assert(instance);
- furi_assert(flipper_file);
+ furi_assert(flipper_format);
bool res = false;
do {
- if(!flipper_file_write_string_cstr(flipper_file, "Protocol", instance->name)) {
+ if(!flipper_format_write_string_cstr(flipper_format, "Protocol", instance->name)) {
FURI_LOG_E(SUBGHZ_PARSER_TAG, "Unable to add Protocol");
break;
}
uint32_t temp = instance->code_last_count_bit;
- if(!flipper_file_write_uint32(flipper_file, "Bit", &temp, 1)) {
+ if(!flipper_format_write_uint32(flipper_format, "Bit", &temp, 1)) {
FURI_LOG_E(SUBGHZ_PARSER_TAG, "Unable to add Bit");
break;
}
@@ -189,7 +191,7 @@ bool subghz_protocol_common_to_save_file(SubGhzProtocolCommon* instance, Flipper
key_data[sizeof(uint64_t) - i - 1] = (instance->code_last_found >> i * 8) & 0xFF;
}
- if(!flipper_file_write_hex(flipper_file, "Key", key_data, sizeof(uint64_t))) {
+ if(!flipper_format_write_hex(flipper_format, "Key", key_data, sizeof(uint64_t))) {
FURI_LOG_E(SUBGHZ_PARSER_TAG, "Unable to add Key");
break;
}
@@ -201,23 +203,23 @@ bool subghz_protocol_common_to_save_file(SubGhzProtocolCommon* instance, Flipper
bool subghz_protocol_common_to_load_protocol_from_file(
SubGhzProtocolCommon* instance,
- FlipperFile* flipper_file) {
+ FlipperFormat* flipper_format) {
furi_assert(instance);
- furi_assert(flipper_file);
+ furi_assert(flipper_format);
bool loaded = false;
string_t temp_str;
string_init(temp_str);
uint32_t temp_data = 0;
do {
- if(!flipper_file_read_uint32(flipper_file, "Bit", (uint32_t*)&temp_data, 1)) {
+ if(!flipper_format_read_uint32(flipper_format, "Bit", (uint32_t*)&temp_data, 1)) {
FURI_LOG_E(SUBGHZ_PARSER_TAG, "Missing Bit");
break;
}
instance->code_last_count_bit = (uint8_t)temp_data;
uint8_t key_data[sizeof(uint64_t)] = {0};
- if(!flipper_file_read_hex(flipper_file, "Key", key_data, sizeof(uint64_t))) {
+ if(!flipper_format_read_hex(flipper_format, "Key", key_data, sizeof(uint64_t))) {
FURI_LOG_E(SUBGHZ_PARSER_TAG, "Missing Key");
break;
}
diff --git a/lib/subghz/protocols/subghz_protocol_common.h b/lib/subghz/protocols/subghz_protocol_common.h
index 1441e4d5..4abae60b 100644
--- a/lib/subghz/protocols/subghz_protocol_common.h
+++ b/lib/subghz/protocols/subghz_protocol_common.h
@@ -3,7 +3,7 @@
#include <m-string.h>
#include <furi_hal.h>
#include <stdint.h>
-#include <lib/flipper_file/flipper_file.h>
+#include <flipper_format/flipper_format.h>
#define bit_read(value, bit) (((value) >> (bit)) & 0x01)
#define bit_set(value, bit) ((value) |= (1UL << (bit)))
@@ -43,11 +43,11 @@ typedef void (*SubGhzProtocolCommonToStr)(SubGhzProtocolCommon* instance, string
//Get string to save
typedef bool (
- *SubGhzProtocolCommonSaveFile)(SubGhzProtocolCommon* instance, FlipperFile* flipper_file);
+ *SubGhzProtocolCommonSaveFile)(SubGhzProtocolCommon* instance, FlipperFormat* flipper_format);
//Load protocol from file
typedef bool (*SubGhzProtocolCommonLoadFromFile)(
- FlipperFile* flipper_file,
+ FlipperFormat* flipper_format,
SubGhzProtocolCommon* instance,
const char* file_path);
//Load protocol
@@ -208,17 +208,19 @@ bool subghz_protocol_common_read_hex(string_t str, uint8_t* buff, uint16_t len);
/** Adding data to a file
*
* @param instance - SubGhzProtocolCommon instance
- * @param flipper_file - FlipperFile
+ * @param flipper_format - FlipperFormat
* @return bool
*/
-bool subghz_protocol_common_to_save_file(SubGhzProtocolCommon* instance, FlipperFile* flipper_file);
+bool subghz_protocol_common_to_save_file(
+ SubGhzProtocolCommon* instance,
+ FlipperFormat* flipper_format);
/** Loading data to a file
*
* @param instance - SubGhzProtocolCommon instance
- * @param flipper_file - FlipperFile
+ * @param flipper_format - FlipperFormat
* @return bool
*/
bool subghz_protocol_common_to_load_protocol_from_file(
SubGhzProtocolCommon* instance,
- FlipperFile* flipper_file);
+ FlipperFormat* flipper_format);
diff --git a/lib/subghz/protocols/subghz_protocol_faac_slh.c b/lib/subghz/protocols/subghz_protocol_faac_slh.c
index 5bce4f8d..310295d6 100644
--- a/lib/subghz/protocols/subghz_protocol_faac_slh.c
+++ b/lib/subghz/protocols/subghz_protocol_faac_slh.c
@@ -12,7 +12,7 @@ typedef enum {
} FaacSLHDecoderStep;
SubGhzProtocolFaacSLH* subghz_protocol_faac_slh_alloc(void) {
- SubGhzProtocolFaacSLH* instance = furi_alloc(sizeof(SubGhzProtocolFaacSLH));
+ SubGhzProtocolFaacSLH* instance = malloc(sizeof(SubGhzProtocolFaacSLH));
instance->common.name = "Faac SLH";
instance->common.code_min_count_bit_for_found = 64;
@@ -186,4 +186,4 @@ void subghz_decoder_faac_slh_to_load_protocol(SubGhzProtocolFaacSLH* instance, v
instance->common.code_last_found = data->code_found;
instance->common.code_last_count_bit = data->code_count_bit;
subghz_protocol_faac_slh_check_remote_controller(instance);
-} \ No newline at end of file
+}
diff --git a/lib/subghz/protocols/subghz_protocol_gate_tx.c b/lib/subghz/protocols/subghz_protocol_gate_tx.c
index 05e8c151..58736817 100644
--- a/lib/subghz/protocols/subghz_protocol_gate_tx.c
+++ b/lib/subghz/protocols/subghz_protocol_gate_tx.c
@@ -12,7 +12,7 @@ typedef enum {
} GateTXDecoderStep;
SubGhzProtocolGateTX* subghz_protocol_gate_tx_alloc(void) {
- SubGhzProtocolGateTX* instance = furi_alloc(sizeof(SubGhzProtocolGateTX));
+ SubGhzProtocolGateTX* instance = malloc(sizeof(SubGhzProtocolGateTX));
instance->common.name = "GateTX";
instance->common.code_min_count_bit_for_found = 24;
@@ -169,16 +169,16 @@ void subghz_protocol_gate_tx_to_str(SubGhzProtocolGateTX* instance, string_t out
bool subghz_protocol_gate_tx_to_save_file(
SubGhzProtocolGateTX* instance,
- FlipperFile* flipper_file) {
- return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_file);
+ FlipperFormat* flipper_format) {
+ return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_format);
}
bool subghz_protocol_gate_tx_to_load_protocol_from_file(
- FlipperFile* flipper_file,
+ FlipperFormat* flipper_format,
SubGhzProtocolGateTX* instance,
const char* file_path) {
if(subghz_protocol_common_to_load_protocol_from_file(
- (SubGhzProtocolCommon*)instance, flipper_file)) {
+ (SubGhzProtocolCommon*)instance, flipper_format)) {
subghz_protocol_gate_tx_check_remote_controller(instance);
return true;
}
diff --git a/lib/subghz/protocols/subghz_protocol_gate_tx.h b/lib/subghz/protocols/subghz_protocol_gate_tx.h
index 5954f6ca..a72346c8 100644
--- a/lib/subghz/protocols/subghz_protocol_gate_tx.h
+++ b/lib/subghz/protocols/subghz_protocol_gate_tx.h
@@ -48,22 +48,22 @@ void subghz_protocol_gate_tx_to_str(SubGhzProtocolGateTX* instance, string_t out
/** Adding data to a file
*
* @param instance - SubGhzProtocolGateTX instance
- * @param flipper_file - FlipperFile
+ * @param flipper_format - FlipperFormat
* @return bool
*/
bool subghz_protocol_gate_tx_to_save_file(
SubGhzProtocolGateTX* instance,
- FlipperFile* flipper_file);
+ FlipperFormat* flipper_format);
/** Loading protocol from file
*
- * @param flipper_file - FlipperFile
+ * @param flipper_format - FlipperFormat
* @param instance - SubGhzProtocolGateTX instance
* @param file_path - file path
* @return bool
*/
bool subghz_protocol_gate_tx_to_load_protocol_from_file(
- FlipperFile* flipper_file,
+ FlipperFormat* flipper_format,
SubGhzProtocolGateTX* instance,
const char* file_path);
diff --git a/lib/subghz/protocols/subghz_protocol_hormann.c b/lib/subghz/protocols/subghz_protocol_hormann.c
index 4b6a8094..97363002 100644
--- a/lib/subghz/protocols/subghz_protocol_hormann.c
+++ b/lib/subghz/protocols/subghz_protocol_hormann.c
@@ -15,7 +15,7 @@ typedef enum {
} HormannDecoderStep;
SubGhzProtocolHormann* subghz_protocol_hormann_alloc() {
- SubGhzProtocolHormann* instance = furi_alloc(sizeof(SubGhzProtocolHormann));
+ SubGhzProtocolHormann* instance = malloc(sizeof(SubGhzProtocolHormann));
instance->common.name = "Hormann HSM";
instance->common.code_min_count_bit_for_found = 44;
@@ -188,16 +188,16 @@ void subghz_protocol_hormann_to_str(SubGhzProtocolHormann* instance, string_t ou
bool subghz_protocol_hormann_to_save_file(
SubGhzProtocolHormann* instance,
- FlipperFile* flipper_file) {
- return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_file);
+ FlipperFormat* flipper_format) {
+ return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_format);
}
bool subghz_protocol_hormann_to_load_protocol_from_file(
- FlipperFile* flipper_file,
+ FlipperFormat* flipper_format,
SubGhzProtocolHormann* instance,
const char* file_path) {
return subghz_protocol_common_to_load_protocol_from_file(
- (SubGhzProtocolCommon*)instance, flipper_file);
+ (SubGhzProtocolCommon*)instance, flipper_format);
}
void subghz_decoder_hormann_to_load_protocol(SubGhzProtocolHormann* instance, void* context) {
diff --git a/lib/subghz/protocols/subghz_protocol_hormann.h b/lib/subghz/protocols/subghz_protocol_hormann.h
index 6032f7a6..65b80e08 100644
--- a/lib/subghz/protocols/subghz_protocol_hormann.h
+++ b/lib/subghz/protocols/subghz_protocol_hormann.h
@@ -48,22 +48,22 @@ void subghz_protocol_hormann_to_str(SubGhzProtocolHormann* instance, string_t ou
/** Adding data to a file
*
* @param instance - SubGhzProtocolHormann instance
- * @param flipper_file - FlipperFile
+ * @param flipper_format - FlipperFormat
* @return bool
*/
bool subghz_protocol_hormann_to_save_file(
SubGhzProtocolHormann* instance,
- FlipperFile* flipper_file);
+ FlipperFormat* flipper_format);
/** Loading protocol from file
*
- * @param flipper_file - FlipperFile
+ * @param flipper_format - FlipperFormat
* @param instance - SubGhzProtocolHormann instance
* @param file_path - file path
* @return bool
*/
bool subghz_protocol_hormann_to_load_protocol_from_file(
- FlipperFile* flipper_file,
+ FlipperFormat* flipper_format,
SubGhzProtocolHormann* instance,
const char* file_path);
diff --git a/lib/subghz/protocols/subghz_protocol_ido.c b/lib/subghz/protocols/subghz_protocol_ido.c
index ce47c201..5db8d085 100644
--- a/lib/subghz/protocols/subghz_protocol_ido.c
+++ b/lib/subghz/protocols/subghz_protocol_ido.c
@@ -12,7 +12,7 @@ typedef enum {
} IDoDecoderStep;
SubGhzProtocolIDo* subghz_protocol_ido_alloc(void) {
- SubGhzProtocolIDo* instance = furi_alloc(sizeof(SubGhzProtocolIDo));
+ SubGhzProtocolIDo* instance = malloc(sizeof(SubGhzProtocolIDo));
instance->common.name = "iDo 117/111"; // PT4301-X";
instance->common.code_min_count_bit_for_found = 48;
@@ -186,4 +186,4 @@ void subghz_decoder_ido_to_load_protocol(SubGhzProtocolIDo* instance, void* cont
instance->common.code_last_found = data->code_found;
instance->common.code_last_count_bit = data->code_count_bit;
subghz_protocol_ido_check_remote_controller(instance);
-} \ No newline at end of file
+}
diff --git a/lib/subghz/protocols/subghz_protocol_keeloq.c b/lib/subghz/protocols/subghz_protocol_keeloq.c
index bdecb4ee..a5f19c95 100644
--- a/lib/subghz/protocols/subghz_protocol_keeloq.c
+++ b/lib/subghz/protocols/subghz_protocol_keeloq.c
@@ -21,7 +21,7 @@ typedef enum {
} KeeloqDecoderStep;
SubGhzProtocolKeeloq* subghz_protocol_keeloq_alloc(SubGhzKeystore* keystore) {
- SubGhzProtocolKeeloq* instance = furi_alloc(sizeof(SubGhzProtocolKeeloq));
+ SubGhzProtocolKeeloq* instance = malloc(sizeof(SubGhzProtocolKeeloq));
instance->keystore = keystore;
@@ -469,16 +469,18 @@ void subghz_protocol_keeloq_to_str(SubGhzProtocolKeeloq* instance, string_t outp
instance->common.serial);
}
-bool subghz_protocol_keeloq_to_save_file(SubGhzProtocolKeeloq* instance, FlipperFile* flipper_file) {
- return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_file);
+bool subghz_protocol_keeloq_to_save_file(
+ SubGhzProtocolKeeloq* instance,
+ FlipperFormat* flipper_format) {
+ return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_format);
}
bool subghz_protocol_keeloq_to_load_protocol_from_file(
- FlipperFile* flipper_file,
+ FlipperFormat* flipper_format,
SubGhzProtocolKeeloq* instance,
const char* file_path) {
return subghz_protocol_common_to_load_protocol_from_file(
- (SubGhzProtocolCommon*)instance, flipper_file);
+ (SubGhzProtocolCommon*)instance, flipper_format);
}
void subghz_decoder_keeloq_to_load_protocol(SubGhzProtocolKeeloq* instance, void* context) {
diff --git a/lib/subghz/protocols/subghz_protocol_keeloq.h b/lib/subghz/protocols/subghz_protocol_keeloq.h
index 35c0c426..195f0b47 100644
--- a/lib/subghz/protocols/subghz_protocol_keeloq.h
+++ b/lib/subghz/protocols/subghz_protocol_keeloq.h
@@ -79,20 +79,22 @@ void subghz_protocol_keeloq_to_str(SubGhzProtocolKeeloq* instance, string_t outp
/** Adding data to a file
*
* @param instance - SubGhzProtocolKeeloq instance
- * @param flipper_file - FlipperFile
+ * @param flipper_format - FlipperFormat
* @return bool
*/
-bool subghz_protocol_keeloq_to_save_file(SubGhzProtocolKeeloq* instance, FlipperFile* flipper_file);
+bool subghz_protocol_keeloq_to_save_file(
+ SubGhzProtocolKeeloq* instance,
+ FlipperFormat* flipper_format);
/** Loading protocol from file
*
- * @param flipper_file - FlipperFile
+ * @param flipper_format - FlipperFormat
* @param instance - SubGhzProtocolKeeloq instance
* @param file_path - file path
* @return bool
*/
bool subghz_protocol_keeloq_to_load_protocol_from_file(
- FlipperFile* flipper_file,
+ FlipperFormat* flipper_format,
SubGhzProtocolKeeloq* instance,
const char* file_path);
diff --git a/lib/subghz/protocols/subghz_protocol_kia.c b/lib/subghz/protocols/subghz_protocol_kia.c
index 2046497b..3eecb770 100644
--- a/lib/subghz/protocols/subghz_protocol_kia.c
+++ b/lib/subghz/protocols/subghz_protocol_kia.c
@@ -12,7 +12,7 @@ typedef enum {
} KIADecoderStep;
SubGhzProtocolKIA* subghz_protocol_kia_alloc(void) {
- SubGhzProtocolKIA* instance = furi_alloc(sizeof(SubGhzProtocolKIA));
+ SubGhzProtocolKIA* instance = malloc(sizeof(SubGhzProtocolKIA));
instance->common.name = "KIA";
instance->common.code_min_count_bit_for_found = 60;
@@ -185,4 +185,4 @@ void subghz_decoder_kia_to_load_protocol(SubGhzProtocolKIA* instance, void* cont
instance->common.code_last_found = data->code_found;
instance->common.code_last_count_bit = data->code_count_bit;
subghz_protocol_kia_check_remote_controller(instance);
-} \ No newline at end of file
+}
diff --git a/lib/subghz/protocols/subghz_protocol_nero_radio.c b/lib/subghz/protocols/subghz_protocol_nero_radio.c
index 321a74e2..3b2fb1d7 100644
--- a/lib/subghz/protocols/subghz_protocol_nero_radio.c
+++ b/lib/subghz/protocols/subghz_protocol_nero_radio.c
@@ -12,7 +12,7 @@ typedef enum {
} NeroRadioDecoderStep;
SubGhzProtocolNeroRadio* subghz_protocol_nero_radio_alloc(void) {
- SubGhzProtocolNeroRadio* instance = furi_alloc(sizeof(SubGhzProtocolNeroRadio));
+ SubGhzProtocolNeroRadio* instance = malloc(sizeof(SubGhzProtocolNeroRadio));
instance->common.name = "Nero Radio";
instance->common.code_min_count_bit_for_found = 55;
@@ -211,16 +211,16 @@ void subghz_protocol_nero_radio_to_str(SubGhzProtocolNeroRadio* instance, string
bool subghz_protocol_nero_radio_to_save_file(
SubGhzProtocolNeroRadio* instance,
- FlipperFile* flipper_file) {
- return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_file);
+ FlipperFormat* flipper_format) {
+ return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_format);
}
bool subghz_protocol_nero_radio_to_load_protocol_from_file(
- FlipperFile* flipper_file,
+ FlipperFormat* flipper_format,
SubGhzProtocolNeroRadio* instance,
const char* file_path) {
return subghz_protocol_common_to_load_protocol_from_file(
- (SubGhzProtocolCommon*)instance, flipper_file);
+ (SubGhzProtocolCommon*)instance, flipper_format);
}
void subghz_decoder_nero_radio_to_load_protocol(SubGhzProtocolNeroRadio* instance, void* context) {
@@ -229,4 +229,4 @@ void subghz_decoder_nero_radio_to_load_protocol(SubGhzProtocolNeroRadio* instanc
SubGhzProtocolCommonLoad* data = context;
instance->common.code_last_found = data->code_found;
instance->common.code_last_count_bit = data->code_count_bit;
-} \ No newline at end of file
+}
diff --git a/lib/subghz/protocols/subghz_protocol_nero_radio.h b/lib/subghz/protocols/subghz_protocol_nero_radio.h
index 01d85836..437e95f6 100644
--- a/lib/subghz/protocols/subghz_protocol_nero_radio.h
+++ b/lib/subghz/protocols/subghz_protocol_nero_radio.h
@@ -57,22 +57,22 @@ void subghz_protocol_nero_radio_to_str(SubGhzProtocolNeroRadio* instance, string
/** Adding data to a file
*
* @param instance - SubGhzProtocolNeroRadio instance
- * @param flipper_file - FlipperFile
+ * @param flipper_format - FlipperFormat
* @return bool
*/
bool subghz_protocol_nero_radio_to_save_file(
SubGhzProtocolNeroRadio* instance,
- FlipperFile* flipper_file);
+ FlipperFormat* flipper_format);
/** Loading protocol from file
*
- * @param flipper_file - FlipperFile
+ * @param flipper_format - FlipperFormat
* @param instance - SubGhzProtocolNeroRadio instance
* @param file_path - file path
* @return bool
*/
bool subghz_protocol_nero_radio_to_load_protocol_from_file(
- FlipperFile* flipper_file,
+ FlipperFormat* flipper_format,
SubGhzProtocolNeroRadio* instance,
const char* file_path);
diff --git a/lib/subghz/protocols/subghz_protocol_nero_sketch.c b/lib/subghz/protocols/subghz_protocol_nero_sketch.c
index 204ddd18..db87e0a1 100644
--- a/lib/subghz/protocols/subghz_protocol_nero_sketch.c
+++ b/lib/subghz/protocols/subghz_protocol_nero_sketch.c
@@ -12,7 +12,7 @@ typedef enum {
} NeroSketchDecoderStep;
SubGhzProtocolNeroSketch* subghz_protocol_nero_sketch_alloc(void) {
- SubGhzProtocolNeroSketch* instance = furi_alloc(sizeof(SubGhzProtocolNeroSketch));
+ SubGhzProtocolNeroSketch* instance = malloc(sizeof(SubGhzProtocolNeroSketch));
instance->common.name = "Nero Sketch";
instance->common.code_min_count_bit_for_found = 40;
@@ -204,16 +204,16 @@ void subghz_protocol_nero_sketch_to_str(SubGhzProtocolNeroSketch* instance, stri
bool subghz_protocol_nero_sketch_to_save_file(
SubGhzProtocolNeroSketch* instance,
- FlipperFile* flipper_file) {
- return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_file);
+ FlipperFormat* flipper_format) {
+ return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_format);
}
bool subghz_protocol_nero_sketch_to_load_protocol_from_file(
- FlipperFile* flipper_file,
+ FlipperFormat* flipper_format,
SubGhzProtocolNeroSketch* instance,
const char* file_path) {
return subghz_protocol_common_to_load_protocol_from_file(
- (SubGhzProtocolCommon*)instance, flipper_file);
+ (SubGhzProtocolCommon*)instance, flipper_format);
}
void subghz_decoder_nero_sketch_to_load_protocol(SubGhzProtocolNeroSketch* instance, void* context) {
diff --git a/lib/subghz/protocols/subghz_protocol_nero_sketch.h b/lib/subghz/protocols/subghz_protocol_nero_sketch.h
index 33786c42..db95ab76 100644
--- a/lib/subghz/protocols/subghz_protocol_nero_sketch.h
+++ b/lib/subghz/protocols/subghz_protocol_nero_sketch.h
@@ -57,22 +57,22 @@ void subghz_protocol_nero_sketch_to_str(SubGhzProtocolNeroSketch* instance, stri
/** Adding data to a file
*
* @param instance - SubGhzProtocolNeroSketch instance
- * @param flipper_file - FlipperFile
+ * @param flipper_format - FlipperFormat
* @return bool
*/
bool subghz_protocol_nero_sketch_to_save_file(
SubGhzProtocolNeroSketch* instance,
- FlipperFile* flipper_file);
+ FlipperFormat* flipper_format);
/** Loading protocol from file
*
- * @param flipper_file - FlipperFile
+ * @param flipper_format - FlipperFormat
* @param instance - SubGhzProtocolNeroSketch instance
* @param file_path - file path
* @return bool
*/
bool subghz_protocol_nero_sketch_to_load_protocol_from_file(
- FlipperFile* flipper_file,
+ FlipperFormat* flipper_format,
SubGhzProtocolNeroSketch* instance,
const char* file_path);
diff --git a/lib/subghz/protocols/subghz_protocol_nice_flo.c b/lib/subghz/protocols/subghz_protocol_nice_flo.c
index 56ac43c5..2c2da378 100644
--- a/lib/subghz/protocols/subghz_protocol_nice_flo.c
+++ b/lib/subghz/protocols/subghz_protocol_nice_flo.c
@@ -18,7 +18,7 @@ typedef enum {
} NiceFloDecoderStep;
SubGhzProtocolNiceFlo* subghz_protocol_nice_flo_alloc() {
- SubGhzProtocolNiceFlo* instance = furi_alloc(sizeof(SubGhzProtocolNiceFlo));
+ SubGhzProtocolNiceFlo* instance = malloc(sizeof(SubGhzProtocolNiceFlo));
instance->common.name = "Nice FLO";
instance->common.code_min_count_bit_for_found = 12;
@@ -166,16 +166,16 @@ void subghz_protocol_nice_flo_to_str(SubGhzProtocolNiceFlo* instance, string_t o
bool subghz_protocol_nice_flo_to_save_file(
SubGhzProtocolNiceFlo* instance,
- FlipperFile* flipper_file) {
- return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_file);
+ FlipperFormat* flipper_format) {
+ return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_format);
}
bool subghz_protocol_nice_flo_to_load_protocol_from_file(
- FlipperFile* flipper_file,
+ FlipperFormat* flipper_format,
SubGhzProtocolNiceFlo* instance,
const char* file_path) {
return subghz_protocol_common_to_load_protocol_from_file(
- (SubGhzProtocolCommon*)instance, flipper_file);
+ (SubGhzProtocolCommon*)instance, flipper_format);
}
void subghz_decoder_nice_flo_to_load_protocol(SubGhzProtocolNiceFlo* instance, void* context) {
diff --git a/lib/subghz/protocols/subghz_protocol_nice_flo.h b/lib/subghz/protocols/subghz_protocol_nice_flo.h
index a22c416b..5d395071 100644
--- a/lib/subghz/protocols/subghz_protocol_nice_flo.h
+++ b/lib/subghz/protocols/subghz_protocol_nice_flo.h
@@ -48,22 +48,22 @@ void subghz_protocol_nice_flo_to_str(SubGhzProtocolNiceFlo* instance, string_t o
/** Adding data to a file
*
* @param instance - SubGhzProtocolNiceFlo instance
- * @param flipper_file - FlipperFile
+ * @param flipper_format - FlipperFormat
* @return bool
*/
bool subghz_protocol_nice_flo_to_save_file(
SubGhzProtocolNiceFlo* instance,
- FlipperFile* flipper_file);
+ FlipperFormat* flipper_format);
/** Loading protocol from file
*
- * @param flipper_file - FlipperFile
+ * @param flipper_format - FlipperFormat
* @param instance - SubGhzProtocolNiceFlo instance
* @param file_path - file path
* @return bool
*/
bool subghz_protocol_nice_flo_to_load_protocol_from_file(
- FlipperFile* flipper_file,
+ FlipperFormat* flipper_format,
SubGhzProtocolNiceFlo* instance,
const char* file_path);
diff --git a/lib/subghz/protocols/subghz_protocol_nice_flor_s.c b/lib/subghz/protocols/subghz_protocol_nice_flor_s.c
index 28889fd8..f9c7db6a 100644
--- a/lib/subghz/protocols/subghz_protocol_nice_flor_s.c
+++ b/lib/subghz/protocols/subghz_protocol_nice_flor_s.c
@@ -25,7 +25,7 @@ typedef enum {
} NiceFlorSDecoderStep;
SubGhzProtocolNiceFlorS* subghz_protocol_nice_flor_s_alloc() {
- SubGhzProtocolNiceFlorS* instance = furi_alloc(sizeof(SubGhzProtocolNiceFlorS));
+ SubGhzProtocolNiceFlorS* instance = malloc(sizeof(SubGhzProtocolNiceFlorS));
instance->common.name = "Nice FloR-S";
instance->common.code_min_count_bit_for_found = 52;
@@ -261,4 +261,4 @@ void subghz_decoder_nice_flor_s_to_load_protocol(SubGhzProtocolNiceFlorS* instan
instance->common.code_last_found = data->code_found;
instance->common.code_last_count_bit = data->code_count_bit;
subghz_nice_flor_s_decoder_decrypt(instance);
-} \ No newline at end of file
+}
diff --git a/lib/subghz/protocols/subghz_protocol_princeton.c b/lib/subghz/protocols/subghz_protocol_princeton.c
index b026a611..64f8a47c 100644
--- a/lib/subghz/protocols/subghz_protocol_princeton.c
+++ b/lib/subghz/protocols/subghz_protocol_princeton.c
@@ -35,7 +35,7 @@ typedef enum {
} PrincetonDecoderStep;
SubGhzEncoderPrinceton* subghz_encoder_princeton_alloc() {
- SubGhzEncoderPrinceton* instance = furi_alloc(sizeof(SubGhzEncoderPrinceton));
+ SubGhzEncoderPrinceton* instance = malloc(sizeof(SubGhzEncoderPrinceton));
return instance;
}
@@ -171,7 +171,7 @@ LevelDuration subghz_encoder_princeton_yield(void* context) {
}
SubGhzDecoderPrinceton* subghz_decoder_princeton_alloc(void) {
- SubGhzDecoderPrinceton* instance = furi_alloc(sizeof(SubGhzDecoderPrinceton));
+ SubGhzDecoderPrinceton* instance = malloc(sizeof(SubGhzDecoderPrinceton));
instance->te = SUBGHZ_PT_SHORT;
instance->common.name = "Princeton";
@@ -333,23 +333,24 @@ void subghz_decoder_princeton_to_str(SubGhzDecoderPrinceton* instance, string_t
bool subghz_decoder_princeton_to_save_file(
SubGhzDecoderPrinceton* instance,
- FlipperFile* flipper_file) {
- bool res = subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_file);
+ FlipperFormat* flipper_format) {
+ bool res =
+ subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_format);
if(res) {
- res = flipper_file_write_uint32(flipper_file, "TE", &instance->te, 1);
+ res = flipper_format_write_uint32(flipper_format, "TE", &instance->te, 1);
if(!res) FURI_LOG_E(SUBGHZ_PARSER_TAG, "Unable to add Te");
}
return res;
}
bool subghz_decoder_princeton_to_load_protocol_from_file(
- FlipperFile* flipper_file,
+ FlipperFormat* flipper_format,
SubGhzDecoderPrinceton* instance,
const char* file_path) {
bool loaded = subghz_protocol_common_to_load_protocol_from_file(
- (SubGhzProtocolCommon*)instance, flipper_file);
+ (SubGhzProtocolCommon*)instance, flipper_format);
if(loaded) {
- loaded = flipper_file_read_uint32(flipper_file, "TE", (uint32_t*)&instance->te, 1);
+ loaded = flipper_format_read_uint32(flipper_format, "TE", (uint32_t*)&instance->te, 1);
if(!loaded) FURI_LOG_E(SUBGHZ_PARSER_TAG, "Missing TE");
}
return loaded;
diff --git a/lib/subghz/protocols/subghz_protocol_princeton.h b/lib/subghz/protocols/subghz_protocol_princeton.h
index 44224be5..9eccb4ef 100644
--- a/lib/subghz/protocols/subghz_protocol_princeton.h
+++ b/lib/subghz/protocols/subghz_protocol_princeton.h
@@ -110,22 +110,22 @@ void subghz_decoder_princeton_to_str(SubGhzDecoderPrinceton* instance, string_t
/** Adding data to a file
*
* @param instance - SubGhzDecoderPrinceton instance
- * @param flipper_file - FlipperFile
+ * @param flipper_format - FlipperFormat
* @return bool
*/
bool subghz_decoder_princeton_to_save_file(
SubGhzDecoderPrinceton* instance,
- FlipperFile* flipper_file);
+ FlipperFormat* flipper_format);
/** Loading protocol from file
*
- * @param flipper_file - FlipperFile
+ * @param flipper_format - FlipperFormat
* @param instance - SubGhzDecoderPrinceton instance
* @param file_path - file path
* @return bool
*/
bool subghz_decoder_princeton_to_load_protocol_from_file(
- FlipperFile* flipper_file,
+ FlipperFormat* flipper_format,
SubGhzDecoderPrinceton* instance,
const char* file_path);
diff --git a/lib/subghz/protocols/subghz_protocol_raw.c b/lib/subghz/protocols/subghz_protocol_raw.c
index 8b2bcf19..72f540c6 100755
--- a/lib/subghz/protocols/subghz_protocol_raw.c
+++ b/lib/subghz/protocols/subghz_protocol_raw.c
@@ -11,7 +11,7 @@ struct SubGhzProtocolRAW {
int32_t* upload_raw;
uint16_t ind_write;
Storage* storage;
- FlipperFile* flipper_file;
+ FlipperFormat* flipper_format;
SubGhzFileEncoderWorker* file_worker_encoder;
uint32_t file_is_open;
string_t file_name;
@@ -28,7 +28,7 @@ typedef enum {
} RAWFilIsOpen;
SubGhzProtocolRAW* subghz_protocol_raw_alloc(void) {
- SubGhzProtocolRAW* instance = furi_alloc(sizeof(SubGhzProtocolRAW));
+ SubGhzProtocolRAW* instance = malloc(sizeof(SubGhzProtocolRAW));
instance->upload_raw = NULL;
instance->ind_write = 0;
@@ -36,7 +36,7 @@ SubGhzProtocolRAW* subghz_protocol_raw_alloc(void) {
instance->last_level = false;
instance->storage = furi_record_open("storage");
- instance->flipper_file = flipper_file_alloc(instance->storage);
+ instance->flipper_format = flipper_format_file_alloc(instance->storage);
instance->file_is_open = RAWFileIsOpenClose;
string_init(instance->file_name);
@@ -61,7 +61,7 @@ void subghz_protocol_raw_free(SubGhzProtocolRAW* instance) {
furi_assert(instance);
string_clear(instance->file_name);
- flipper_file_free(instance->flipper_file);
+ flipper_format_free(instance->flipper_format);
furi_record_close("storage");
free(instance);
@@ -166,7 +166,7 @@ bool subghz_protocol_raw_save_to_file_init(
const char* preset) {
furi_assert(instance);
- //instance->flipper_file = flipper_file_alloc(instance->storage);
+ //instance->flipper_format = flipper_format_file_alloc(instance->storage);
string_t dev_file_name;
string_init(dev_file_name);
bool init = false;
@@ -186,34 +186,35 @@ bool subghz_protocol_raw_save_to_file_init(
}
// Open file
- if(!flipper_file_open_always(instance->flipper_file, string_get_cstr(dev_file_name))) {
+ if(!flipper_format_file_open_always(
+ instance->flipper_format, string_get_cstr(dev_file_name))) {
FURI_LOG_E(TAG, "Unable to open file for write: %s", dev_file_name);
break;
}
- if(!flipper_file_write_header_cstr(
- instance->flipper_file, SUBGHZ_RAW_FILE_TYPE, SUBGHZ_RAW_FILE_VERSION)) {
+ if(!flipper_format_write_header_cstr(
+ instance->flipper_format, SUBGHZ_RAW_FILE_TYPE, SUBGHZ_RAW_FILE_VERSION)) {
FURI_LOG_E(TAG, "Unable to add header");
break;
}
- if(!flipper_file_write_uint32(instance->flipper_file, "Frequency", &frequency, 1)) {
+ if(!flipper_format_write_uint32(instance->flipper_format, "Frequency", &frequency, 1)) {
FURI_LOG_E(TAG, "Unable to add Frequency");
break;
}
- if(!flipper_file_write_string_cstr(instance->flipper_file, "Preset", preset)) {
+ if(!flipper_format_write_string_cstr(instance->flipper_format, "Preset", preset)) {
FURI_LOG_E(TAG, "Unable to add Preset");
break;
}
- if(!flipper_file_write_string_cstr(
- instance->flipper_file, "Protocol", instance->common.name)) {
+ if(!flipper_format_write_string_cstr(
+ instance->flipper_format, "Protocol", instance->common.name)) {
FURI_LOG_E(TAG, "Unable to add Protocol");
break;
}
- instance->upload_raw = furi_alloc(SUBGHZ_DOWNLOAD_MAX_SIZE * sizeof(int32_t));
+ instance->upload_raw = malloc(SUBGHZ_DOWNLOAD_MAX_SIZE * sizeof(int32_t));
instance->file_is_open = RAWFileIsOpenWrite;
instance->sample_write = 0;
init = true;
@@ -234,7 +235,7 @@ void subghz_protocol_raw_save_to_file_stop(SubGhzProtocolRAW* instance) {
instance->upload_raw = NULL;
}
- flipper_file_close(instance->flipper_file);
+ flipper_format_file_close(instance->flipper_format);
instance->file_is_open = RAWFileIsOpenClose;
}
@@ -243,8 +244,8 @@ bool subghz_protocol_raw_save_to_file_write(SubGhzProtocolRAW* instance) {
bool is_write = false;
if(instance->file_is_open == RAWFileIsOpenWrite) {
- if(!flipper_file_write_int32(
- instance->flipper_file, "RAW_Data", instance->upload_raw, instance->ind_write)) {
+ if(!flipper_format_write_int32(
+ instance->flipper_format, "RAW_Data", instance->upload_raw, instance->ind_write)) {
FURI_LOG_E(TAG, "Unable to add RAW_Data");
} else {
instance->sample_write += instance->ind_write;
@@ -260,10 +261,10 @@ size_t subghz_protocol_raw_get_sample_write(SubGhzProtocolRAW* instance) {
}
bool subghz_protocol_raw_to_load_protocol_from_file(
- FlipperFile* flipper_file,
+ FlipperFormat* flipper_format,
SubGhzProtocolRAW* instance,
const char* file_path) {
furi_assert(file_path);
subghz_protocol_raw_set_last_file_name(instance, file_path);
return true;
-} \ No newline at end of file
+}
diff --git a/lib/subghz/protocols/subghz_protocol_raw.h b/lib/subghz/protocols/subghz_protocol_raw.h
index 9a6f8b9d..ca7fc99c 100644
--- a/lib/subghz/protocols/subghz_protocol_raw.h
+++ b/lib/subghz/protocols/subghz_protocol_raw.h
@@ -66,6 +66,6 @@ bool subghz_protocol_raw_save_to_file_write(SubGhzProtocolRAW* instance);
size_t subghz_protocol_raw_get_sample_write(SubGhzProtocolRAW* instance);
bool subghz_protocol_raw_to_load_protocol_from_file(
- FlipperFile* flipper_file,
+ FlipperFormat* flipper_format,
SubGhzProtocolRAW* instance,
const char* file_path); \ No newline at end of file
diff --git a/lib/subghz/protocols/subghz_protocol_scher_khan.c b/lib/subghz/protocols/subghz_protocol_scher_khan.c
index 5f9786a0..5e5d0446 100644
--- a/lib/subghz/protocols/subghz_protocol_scher_khan.c
+++ b/lib/subghz/protocols/subghz_protocol_scher_khan.c
@@ -18,7 +18,7 @@ typedef enum {
} ScherKhanDecoderStep;
SubGhzProtocolScherKhan* subghz_protocol_scher_khan_alloc(void) {
- SubGhzProtocolScherKhan* instance = furi_alloc(sizeof(SubGhzProtocolScherKhan));
+ SubGhzProtocolScherKhan* instance = malloc(sizeof(SubGhzProtocolScherKhan));
instance->common.name = "Scher-Khan";
instance->common.code_min_count_bit_for_found = 35;
@@ -241,4 +241,4 @@ void subghz_decoder_scher_khan_to_load_protocol(SubGhzProtocolScherKhan* instanc
instance->common.code_last_found = data->code_found;
instance->common.code_last_count_bit = data->code_count_bit;
subghz_protocol_scher_khan_check_remote_controller(instance);
-} \ No newline at end of file
+}
diff --git a/lib/subghz/protocols/subghz_protocol_somfy_keytis.c b/lib/subghz/protocols/subghz_protocol_somfy_keytis.c
index f8e023d9..a58100db 100644
--- a/lib/subghz/protocols/subghz_protocol_somfy_keytis.c
+++ b/lib/subghz/protocols/subghz_protocol_somfy_keytis.c
@@ -19,7 +19,7 @@ typedef enum {
} SomfyKeytisDecoderStep;
SubGhzProtocolSomfyKeytis* subghz_protocol_somfy_keytis_alloc() {
- SubGhzProtocolSomfyKeytis* instance = furi_alloc(sizeof(SubGhzProtocolSomfyKeytis));
+ SubGhzProtocolSomfyKeytis* instance = malloc(sizeof(SubGhzProtocolSomfyKeytis));
instance->common.name = "Somfy Keytis";
instance->common.code_min_count_bit_for_found = 80;
diff --git a/lib/subghz/protocols/subghz_protocol_somfy_telis.c b/lib/subghz/protocols/subghz_protocol_somfy_telis.c
index 02d3c47b..8de0ec27 100644
--- a/lib/subghz/protocols/subghz_protocol_somfy_telis.c
+++ b/lib/subghz/protocols/subghz_protocol_somfy_telis.c
@@ -18,7 +18,7 @@ typedef enum {
} SomfyTelisDecoderStep;
SubGhzProtocolSomfyTelis* subghz_protocol_somfy_telis_alloc() {
- SubGhzProtocolSomfyTelis* instance = furi_alloc(sizeof(SubGhzProtocolSomfyTelis));
+ SubGhzProtocolSomfyTelis* instance = malloc(sizeof(SubGhzProtocolSomfyTelis));
instance->common.name = "Somfy Telis";
instance->common.code_min_count_bit_for_found = 56;
diff --git a/lib/subghz/protocols/subghz_protocol_star_line.c b/lib/subghz/protocols/subghz_protocol_star_line.c
index 089a4540..70d9c805 100644
--- a/lib/subghz/protocols/subghz_protocol_star_line.c
+++ b/lib/subghz/protocols/subghz_protocol_star_line.c
@@ -22,7 +22,7 @@ typedef enum {
} StarLineDecoderStep;
SubGhzProtocolStarLine* subghz_protocol_star_line_alloc(SubGhzKeystore* keystore) {
- SubGhzProtocolStarLine* instance = furi_alloc(sizeof(SubGhzProtocolStarLine));
+ SubGhzProtocolStarLine* instance = malloc(sizeof(SubGhzProtocolStarLine));
instance->keystore = keystore;
@@ -338,4 +338,4 @@ void subghz_decoder_star_line_to_load_protocol(SubGhzProtocolStarLine* instance,
instance->common.code_last_found = data->code_found;
instance->common.code_last_count_bit = data->code_count_bit;
subghz_protocol_star_line_check_remote_controller(instance);
-} \ No newline at end of file
+}
diff --git a/lib/subghz/subghz_file_encoder_worker.c b/lib/subghz/subghz_file_encoder_worker.c
index 2bf8da9d..07acb4f6 100644
--- a/lib/subghz/subghz_file_encoder_worker.c
+++ b/lib/subghz/subghz_file_encoder_worker.c
@@ -1,8 +1,9 @@
#include "subghz_file_encoder_worker.h"
#include <stream_buffer.h>
-#include <lib/flipper_file/flipper_file.h>
-#include <lib/flipper_file/file_helper.h>
+#include <toolbox/stream/stream.h>
+#include <flipper_format/flipper_format.h>
+#include <flipper_format/flipper_format_i.h>
#define TAG "SubGhzFileEncoderWorker"
@@ -13,7 +14,7 @@ struct SubGhzFileEncoderWorker {
StreamBufferHandle_t stream;
Storage* storage;
- FlipperFile* flipper_file;
+ FlipperFormat* flipper_format;
volatile bool worker_running;
volatile bool worker_stoping;
@@ -121,21 +122,21 @@ static int32_t subghz_file_encoder_worker_thread(void* context) {
SubGhzFileEncoderWorker* instance = context;
FURI_LOG_I(TAG, "Worker start");
bool res = false;
- File* file = flipper_file_get_file(instance->flipper_file);
+ Stream* stream = flipper_format_get_raw_stream(instance->flipper_format);
do {
- if(!flipper_file_open_existing(
- instance->flipper_file, string_get_cstr(instance->file_path))) {
+ if(!flipper_format_file_open_existing(
+ instance->flipper_format, string_get_cstr(instance->file_path))) {
FURI_LOG_E(
TAG, "Unable to open file for read: %s", string_get_cstr(instance->file_path));
break;
}
- if(!flipper_file_read_string(instance->flipper_file, "Protocol", instance->str_data)) {
+ if(!flipper_format_read_string(instance->flipper_format, "Protocol", instance->str_data)) {
FURI_LOG_E(TAG, "Missing Protocol");
break;
}
//skip the end of the previous line "\n"
- storage_file_seek(file, 1, false);
+ stream_seek(stream, 1, StreamOffsetFromCurrent);
res = true;
instance->worker_stoping = false;
FURI_LOG_I(TAG, "Start transmission");
@@ -144,9 +145,9 @@ static int32_t subghz_file_encoder_worker_thread(void* context) {
while(res && instance->worker_running) {
size_t stream_free_byte = xStreamBufferSpacesAvailable(instance->stream);
if((stream_free_byte / sizeof(int32_t)) >= SUBGHZ_FILE_ENCODER_LOAD) {
- if(file_helper_read_line(file, instance->str_data)) {
+ if(stream_read_line(stream, instance->str_data)) {
//skip the end of the previous line "\n"
- storage_file_seek(file, 1, false);
+ stream_seek(stream, 1, StreamOffsetFromCurrent);
if(!subghz_file_encoder_worker_data_parse(
instance,
string_get_cstr(instance->str_data),
@@ -174,14 +175,14 @@ static int32_t subghz_file_encoder_worker_thread(void* context) {
}
osDelay(50);
}
- flipper_file_close(instance->flipper_file);
+ flipper_format_file_close(instance->flipper_format);
FURI_LOG_I(TAG, "Worker stop");
return 0;
}
SubGhzFileEncoderWorker* subghz_file_encoder_worker_alloc() {
- SubGhzFileEncoderWorker* instance = furi_alloc(sizeof(SubGhzFileEncoderWorker));
+ SubGhzFileEncoderWorker* instance = malloc(sizeof(SubGhzFileEncoderWorker));
instance->thread = furi_thread_alloc();
furi_thread_set_name(instance->thread, "SubghzFEWorker");
@@ -191,7 +192,7 @@ SubGhzFileEncoderWorker* subghz_file_encoder_worker_alloc() {
instance->stream = xStreamBufferCreate(sizeof(int32_t) * 2048, sizeof(int32_t));
instance->storage = furi_record_open("storage");
- instance->flipper_file = flipper_file_alloc(instance->storage);
+ instance->flipper_format = flipper_format_file_alloc(instance->storage);
string_init(instance->str_data);
string_init(instance->file_path);
@@ -210,7 +211,7 @@ void subghz_file_encoder_worker_free(SubGhzFileEncoderWorker* instance) {
string_clear(instance->str_data);
string_clear(instance->file_path);
- flipper_file_free(instance->flipper_file);
+ flipper_format_free(instance->flipper_format);
furi_record_close("storage");
free(instance);
diff --git a/lib/subghz/subghz_keystore.c b/lib/subghz/subghz_keystore.c
index 2c76f677..b63ea697 100644
--- a/lib/subghz/subghz_keystore.c
+++ b/lib/subghz/subghz_keystore.c
@@ -5,7 +5,9 @@
#include <storage/storage.h>
#include <toolbox/hex.h>
-#include <flipper_file/flipper_file.h>
+#include <toolbox/stream/stream.h>
+#include <flipper_format/flipper_format.h>
+#include <flipper_format/flipper_format_i.h>
#define TAG "SubGhzKeystore"
@@ -29,7 +31,7 @@ struct SubGhzKeystore {
};
SubGhzKeystore* subghz_keystore_alloc() {
- SubGhzKeystore* instance = furi_alloc(sizeof(SubGhzKeystore));
+ SubGhzKeystore* instance = malloc(sizeof(SubGhzKeystore));
SubGhzKeyArray_init(instance->data);
@@ -104,19 +106,19 @@ static void subghz_keystore_mess_with_iv(uint8_t* iv) {
: "r0", "r1", "r2", "r3", "memory");
}
-static bool subghz_keystore_read_file(SubGhzKeystore* instance, File* file, uint8_t* iv) {
+static bool subghz_keystore_read_file(SubGhzKeystore* instance, Stream* stream, uint8_t* iv) {
bool result = true;
- char buffer[FILE_BUFFER_SIZE];
+ uint8_t buffer[FILE_BUFFER_SIZE];
- char* decrypted_line = furi_alloc(SUBGHZ_KEYSTORE_FILE_DECRYPTED_LINE_SIZE);
- char* encrypted_line = furi_alloc(SUBGHZ_KEYSTORE_FILE_ENCRYPTED_LINE_SIZE);
+ char* decrypted_line = malloc(SUBGHZ_KEYSTORE_FILE_DECRYPTED_LINE_SIZE);
+ char* encrypted_line = malloc(SUBGHZ_KEYSTORE_FILE_ENCRYPTED_LINE_SIZE);
size_t encrypted_line_cursor = 0;
if(iv) furi_hal_crypto_store_load_key(SUBGHZ_KEYSTORE_FILE_ENCRYPTION_KEY_SLOT, iv);
size_t ret = 0;
do {
- ret = storage_file_read(file, buffer, FILE_BUFFER_SIZE);
+ ret = stream_read(stream, buffer, FILE_BUFFER_SIZE);
for(uint16_t i = 0; i < ret; i++) {
if(buffer[i] == '\n' && encrypted_line_cursor > 0) {
// Process line
@@ -187,17 +189,17 @@ bool subghz_keystore_load(SubGhzKeystore* instance, const char* file_name) {
Storage* storage = furi_record_open("storage");
- FlipperFile* flipper_file = flipper_file_alloc(storage);
+ FlipperFormat* flipper_format = flipper_format_file_alloc(storage);
do {
- if(!flipper_file_open_existing(flipper_file, file_name)) {
+ if(!flipper_format_file_open_existing(flipper_format, file_name)) {
FURI_LOG_E(TAG, "Unable to open file for read: %s", file_name);
break;
}
- if(!flipper_file_read_header(flipper_file, filetype, &version)) {
+ if(!flipper_format_read_header(flipper_format, filetype, &version)) {
FURI_LOG_E(TAG, "Missing or incorrect header");
break;
}
- if(!flipper_file_read_uint32(flipper_file, "Encryption", (uint32_t*)&encryption, 1)) {
+ if(!flipper_format_read_uint32(flipper_format, "Encryption", (uint32_t*)&encryption, 1)) {
FURI_LOG_E(TAG, "Missing encryption type");
break;
}
@@ -208,23 +210,22 @@ bool subghz_keystore_load(SubGhzKeystore* instance, const char* file_name) {
break;
}
- File* file = flipper_file_get_file(flipper_file);
+ Stream* stream = flipper_format_get_raw_stream(flipper_format);
if(encryption == SubGhzKeystoreEncryptionNone) {
- result = subghz_keystore_read_file(instance, file, NULL);
+ result = subghz_keystore_read_file(instance, stream, NULL);
} else if(encryption == SubGhzKeystoreEncryptionAES256) {
- if(!flipper_file_read_hex(flipper_file, "IV", iv, 16)) {
+ if(!flipper_format_read_hex(flipper_format, "IV", iv, 16)) {
FURI_LOG_E(TAG, "Missing IV");
break;
}
subghz_keystore_mess_with_iv(iv);
- result = subghz_keystore_read_file(instance, file, iv);
+ result = subghz_keystore_read_file(instance, stream, iv);
} else {
FURI_LOG_E(TAG, "Unknown encryption");
break;
}
} while(0);
- flipper_file_close(flipper_file);
- flipper_file_free(flipper_file);
+ flipper_format_free(flipper_format);
furi_record_close("storage");
@@ -238,26 +239,26 @@ bool subghz_keystore_save(SubGhzKeystore* instance, const char* file_name, uint8
bool result = false;
Storage* storage = furi_record_open("storage");
- char* decrypted_line = furi_alloc(SUBGHZ_KEYSTORE_FILE_DECRYPTED_LINE_SIZE);
- char* encrypted_line = furi_alloc(SUBGHZ_KEYSTORE_FILE_ENCRYPTED_LINE_SIZE);
+ char* decrypted_line = malloc(SUBGHZ_KEYSTORE_FILE_DECRYPTED_LINE_SIZE);
+ char* encrypted_line = malloc(SUBGHZ_KEYSTORE_FILE_ENCRYPTED_LINE_SIZE);
- FlipperFile* flipper_file = flipper_file_alloc(storage);
+ FlipperFormat* flipper_format = flipper_format_file_alloc(storage);
do {
- if(!flipper_file_open_always(flipper_file, file_name)) {
+ if(!flipper_format_file_open_always(flipper_format, file_name)) {
FURI_LOG_E(TAG, "Unable to open file for write: %s", file_name);
break;
}
- if(!flipper_file_write_header_cstr(
- flipper_file, SUBGHZ_KEYSTORE_FILE_TYPE, SUBGHZ_KEYSTORE_FILE_VERSION)) {
+ if(!flipper_format_write_header_cstr(
+ flipper_format, SUBGHZ_KEYSTORE_FILE_TYPE, SUBGHZ_KEYSTORE_FILE_VERSION)) {
FURI_LOG_E(TAG, "Unable to add header");
break;
}
uint32_t encryption = SubGhzKeystoreEncryptionAES256;
- if(!flipper_file_write_uint32(flipper_file, "Encryption", &encryption, 1)) {
+ if(!flipper_format_write_uint32(flipper_format, "Encryption", &encryption, 1)) {
FURI_LOG_E(TAG, "Unable to add Encryption");
break;
}
- if(!flipper_file_write_hex(flipper_file, "IV", iv, 16)) {
+ if(!flipper_format_write_hex(flipper_format, "IV", iv, 16)) {
FURI_LOG_E(TAG, "Unable to add IV");
break;
}
@@ -269,7 +270,7 @@ bool subghz_keystore_save(SubGhzKeystore* instance, const char* file_name, uint8
break;
}
- File* file = flipper_file_get_file(flipper_file);
+ Stream* stream = flipper_format_get_raw_stream(flipper_format);
size_t encrypted_line_count = 0;
for
M_EACH(key, instance->data, SubGhzKeyArray_t) {
@@ -306,8 +307,8 @@ bool subghz_keystore_save(SubGhzKeystore* instance, const char* file_name, uint8
encrypted_line[hex_cursor] = xx[encrypted_line[cursor] & 0xF];
encrypted_line[hex_cursor - 1] = xx[(encrypted_line[cursor] >> 4) & 0xF];
}
- storage_file_write(file, encrypted_line, strlen(encrypted_line));
- storage_file_write(file, "\n", 1);
+ stream_write_cstring(stream, encrypted_line);
+ stream_write_char(stream, '\n');
encrypted_line_count++;
}
furi_hal_crypto_store_unload_key(SUBGHZ_KEYSTORE_FILE_ENCRYPTION_KEY_SLOT);
@@ -319,8 +320,7 @@ bool subghz_keystore_save(SubGhzKeystore* instance, const char* file_name, uint8
FURI_LOG_E(TAG, "Failure. Encrypted: %d of %d", encrypted_line_count, total_keys);
}
} while(0);
- flipper_file_close(flipper_file);
- flipper_file_free(flipper_file);
+ flipper_format_free(flipper_format);
free(encrypted_line);
free(decrypted_line);
@@ -346,19 +346,20 @@ bool subghz_keystore_raw_encrypted_save(
Storage* storage = furi_record_open("storage");
- char* encrypted_line = furi_alloc(SUBGHZ_KEYSTORE_FILE_ENCRYPTED_LINE_SIZE);
+ char* encrypted_line = malloc(SUBGHZ_KEYSTORE_FILE_ENCRYPTED_LINE_SIZE);
- FlipperFile* input_flipper_file = flipper_file_alloc(storage);
+ FlipperFormat* input_flipper_format = flipper_format_file_alloc(storage);
do {
- if(!flipper_file_open_existing(input_flipper_file, input_file_name)) {
+ if(!flipper_format_file_open_existing(input_flipper_format, input_file_name)) {
FURI_LOG_E(TAG, "Unable to open file for read: %s", input_file_name);
break;
}
- if(!flipper_file_read_header(input_flipper_file, filetype, &version)) {
+ if(!flipper_format_read_header(input_flipper_format, filetype, &version)) {
FURI_LOG_E(TAG, "Missing or incorrect header");
break;
}
- if(!flipper_file_read_uint32(input_flipper_file, "Encryption", (uint32_t*)&encryption, 1)) {
+ if(!flipper_format_read_uint32(
+ input_flipper_format, "Encryption", (uint32_t*)&encryption, 1)) {
FURI_LOG_E(TAG, "Missing encryption type");
break;
}
@@ -373,30 +374,30 @@ bool subghz_keystore_raw_encrypted_save(
FURI_LOG_E(TAG, "Already encryption");
break;
}
- File* input_file = flipper_file_get_file(input_flipper_file);
+ Stream* input_stream = flipper_format_get_raw_stream(input_flipper_format);
- FlipperFile* output_flipper_file = flipper_file_alloc(storage);
+ FlipperFormat* output_flipper_format = flipper_format_file_alloc(storage);
- if(!flipper_file_open_always(output_flipper_file, output_file_name)) {
+ if(!flipper_format_file_open_always(output_flipper_format, output_file_name)) {
FURI_LOG_E(TAG, "Unable to open file for write: %s", output_file_name);
break;
}
- if(!flipper_file_write_header_cstr(
- output_flipper_file, string_get_cstr(filetype), SUBGHZ_KEYSTORE_FILE_VERSION)) {
+ if(!flipper_format_write_header_cstr(
+ output_flipper_format, string_get_cstr(filetype), SUBGHZ_KEYSTORE_FILE_VERSION)) {
FURI_LOG_E(TAG, "Unable to add header");
break;
}
uint32_t encryption = SubGhzKeystoreEncryptionAES256;
- if(!flipper_file_write_uint32(output_flipper_file, "Encryption", &encryption, 1)) {
+ if(!flipper_format_write_uint32(output_flipper_format, "Encryption", &encryption, 1)) {
FURI_LOG_E(TAG, "Unable to add Encryption");
break;
}
- if(!flipper_file_write_hex(output_flipper_file, "IV", iv, 16)) {
+ if(!flipper_format_write_hex(output_flipper_format, "IV", iv, 16)) {
FURI_LOG_E(TAG, "Unable to add IV");
break;
}
- if(!flipper_file_write_string_cstr(output_flipper_file, "Encrypt_data", "RAW")) {
+ if(!flipper_format_write_string_cstr(output_flipper_format, "Encrypt_data", "RAW")) {
FURI_LOG_E(TAG, "Unable to add Encrypt_data");
break;
}
@@ -408,19 +409,19 @@ bool subghz_keystore_raw_encrypted_save(
break;
}
- File* output_file = flipper_file_get_file(output_flipper_file);
- char buffer[FILE_BUFFER_SIZE];
+ Stream* output_stream = flipper_format_get_raw_stream(output_flipper_format);
+ uint8_t buffer[FILE_BUFFER_SIZE];
bool result = true;
size_t ret = 0;
furi_assert(FILE_BUFFER_SIZE % 16 == 0);
//skip the end of the previous line "\n"
- storage_file_read(input_file, buffer, 1);
+ stream_read(input_stream, buffer, 1);
do {
memset(buffer, 0, FILE_BUFFER_SIZE);
- ret = storage_file_read(input_file, buffer, FILE_BUFFER_SIZE);
+ ret = stream_read(input_stream, buffer, FILE_BUFFER_SIZE);
if(ret == 0) {
break;
}
@@ -450,12 +451,11 @@ bool subghz_keystore_raw_encrypted_save(
encrypted_line[hex_cursor] = xx[encrypted_line[cursor] & 0xF];
encrypted_line[hex_cursor - 1] = xx[(encrypted_line[cursor] >> 4) & 0xF];
}
- storage_file_write(output_file, encrypted_line, strlen(encrypted_line));
+ stream_write_cstring(output_stream, encrypted_line);
} while(ret > 0 && result);
- flipper_file_close(output_flipper_file);
- flipper_file_free(output_flipper_file);
+ flipper_format_free(output_flipper_format);
furi_hal_crypto_store_unload_key(SUBGHZ_KEYSTORE_FILE_ENCRYPTION_KEY_SLOT);
@@ -464,8 +464,7 @@ bool subghz_keystore_raw_encrypted_save(
encrypted = true;
} while(0);
- flipper_file_close(input_flipper_file);
- flipper_file_free(input_flipper_file);
+ flipper_format_free(input_flipper_format);
free(encrypted_line);
@@ -484,19 +483,19 @@ bool subghz_keystore_raw_get_data(const char* file_name, size_t offset, uint8_t*
string_init(str_temp);
Storage* storage = furi_record_open("storage");
- char* decrypted_line = furi_alloc(SUBGHZ_KEYSTORE_FILE_DECRYPTED_LINE_SIZE);
+ char* decrypted_line = malloc(SUBGHZ_KEYSTORE_FILE_DECRYPTED_LINE_SIZE);
- FlipperFile* flipper_file = flipper_file_alloc(storage);
+ FlipperFormat* flipper_format = flipper_format_file_alloc(storage);
do {
- if(!flipper_file_open_existing(flipper_file, file_name)) {
+ if(!flipper_format_file_open_existing(flipper_format, file_name)) {
FURI_LOG_E(TAG, "Unable to open file for read: %s", file_name);
break;
}
- if(!flipper_file_read_header(flipper_file, str_temp, &version)) {
+ if(!flipper_format_read_header(flipper_format, str_temp, &version)) {
FURI_LOG_E(TAG, "Missing or incorrect header");
break;
}
- if(!flipper_file_read_uint32(flipper_file, "Encryption", (uint32_t*)&encryption, 1)) {
+ if(!flipper_format_read_uint32(flipper_format, "Encryption", (uint32_t*)&encryption, 1)) {
FURI_LOG_E(TAG, "Missing encryption type");
break;
}
@@ -507,21 +506,21 @@ bool subghz_keystore_raw_get_data(const char* file_name, size_t offset, uint8_t*
break;
}
- File* file = flipper_file_get_file(flipper_file);
+ Stream* stream = flipper_format_get_raw_stream(flipper_format);
if(encryption != SubGhzKeystoreEncryptionAES256) {
FURI_LOG_E(TAG, "Unknown encryption");
break;
}
if(offset < 16) {
- if(!flipper_file_read_hex(flipper_file, "IV", iv, 16)) {
+ if(!flipper_format_read_hex(flipper_format, "IV", iv, 16)) {
FURI_LOG_E(TAG, "Missing IV");
break;
}
subghz_keystore_mess_with_iv(iv);
}
- if(!flipper_file_read_string(flipper_file, "Encrypt_data", str_temp)) {
+ if(!flipper_format_read_string(flipper_format, "Encrypt_data", str_temp)) {
FURI_LOG_E(TAG, "Missing Encrypt_data");
break;
}
@@ -534,22 +533,22 @@ bool subghz_keystore_raw_get_data(const char* file_name, size_t offset, uint8_t*
}
furi_assert(SUBGHZ_KEYSTORE_FILE_DECRYPTED_LINE_SIZE >= bufer_size / 2);
- char buffer[bufer_size];
+ uint8_t buffer[bufer_size];
size_t ret = 0;
bool decrypted = true;
//skip the end of the previous line "\n"
- storage_file_read(file, buffer, 1);
+ stream_read(stream, buffer, 1);
- size_t size = storage_file_size(file);
- size -= storage_file_tell(file);
+ size_t size = stream_size(stream);
+ size -= stream_tell(stream);
if(size < (offset * 2 + len * 2)) {
FURI_LOG_E(TAG, "Seek position exceeds file size");
break;
}
if(offset >= 16) {
- storage_file_seek(file, ((offset / 16) - 1) * 32, false);
- ret = storage_file_read(file, buffer, 32);
+ stream_seek(stream, ((offset / 16) - 1) * 32, StreamOffsetFromCurrent);
+ ret = stream_read(stream, buffer, 32);
furi_assert(ret == 32);
for(uint16_t i = 0; i < ret - 1; i += 2) {
uint8_t hi_nibble = 0;
@@ -567,7 +566,7 @@ bool subghz_keystore_raw_get_data(const char* file_name, size_t offset, uint8_t*
do {
memset(buffer, 0, bufer_size);
- ret = storage_file_read(file, buffer, bufer_size);
+ ret = stream_read(stream, buffer, bufer_size);
furi_assert(ret == bufer_size);
for(uint16_t i = 0; i < ret - 1; i += 2) {
uint8_t hi_nibble = 0;
@@ -591,8 +590,7 @@ bool subghz_keystore_raw_get_data(const char* file_name, size_t offset, uint8_t*
furi_hal_crypto_store_unload_key(SUBGHZ_KEYSTORE_FILE_ENCRYPTION_KEY_SLOT);
if(decrypted) result = true;
} while(0);
- flipper_file_close(flipper_file);
- flipper_file_free(flipper_file);
+ flipper_format_free(flipper_format);
furi_record_close("storage");
diff --git a/lib/subghz/subghz_parser.c b/lib/subghz/subghz_parser.c
index c4ad873f..f47acca5 100644
--- a/lib/subghz/subghz_parser.c
+++ b/lib/subghz/subghz_parser.c
@@ -85,7 +85,7 @@ static void subghz_parser_parser_rx_callback(SubGhzProtocolCommon* parser, void*
}
SubGhzParser* subghz_parser_alloc() {
- SubGhzParser* instance = furi_alloc(sizeof(SubGhzParser));
+ SubGhzParser* instance = malloc(sizeof(SubGhzParser));
instance->keystore = subghz_keystore_alloc();
diff --git a/lib/subghz/subghz_tx_rx_worker.c b/lib/subghz/subghz_tx_rx_worker.c
index 09b77219..38569039 100644
--- a/lib/subghz/subghz_tx_rx_worker.c
+++ b/lib/subghz/subghz_tx_rx_worker.c
@@ -197,7 +197,7 @@ static int32_t subghz_tx_rx_worker_thread(void* context) {
}
SubGhzTxRxWorker* subghz_tx_rx_worker_alloc() {
- SubGhzTxRxWorker* instance = furi_alloc(sizeof(SubGhzTxRxWorker));
+ SubGhzTxRxWorker* instance = malloc(sizeof(SubGhzTxRxWorker));
instance->thread = furi_thread_alloc();
furi_thread_set_name(instance->thread, "SubghzTxRxWorker");
diff --git a/lib/subghz/subghz_worker.c b/lib/subghz/subghz_worker.c
index 50df2772..46d7fd9a 100644
--- a/lib/subghz/subghz_worker.c
+++ b/lib/subghz/subghz_worker.c
@@ -90,7 +90,7 @@ static int32_t subghz_worker_thread_callback(void* context) {
}
SubGhzWorker* subghz_worker_alloc() {
- SubGhzWorker* instance = furi_alloc(sizeof(SubGhzWorker));
+ SubGhzWorker* instance = malloc(sizeof(SubGhzWorker));
instance->thread = furi_thread_alloc();
furi_thread_set_name(instance->thread, "SubghzWorker");
diff --git a/lib/toolbox/saved_struct.c b/lib/toolbox/saved_struct.c
index d0b65660..ef7dbcf7 100644
--- a/lib/toolbox/saved_struct.c
+++ b/lib/toolbox/saved_struct.c
@@ -67,7 +67,7 @@ bool saved_struct_load(const char* path, void* data, size_t size, uint8_t magic,
SavedStructHeader header;
- uint8_t* data_read = furi_alloc(size);
+ uint8_t* data_read = malloc(size);
Storage* storage = furi_record_open("storage");
File* file = storage_file_alloc(storage);
bool result = true;
diff --git a/lib/toolbox/stream/file_stream.c b/lib/toolbox/stream/file_stream.c
new file mode 100644
index 00000000..56dc1de8
--- /dev/null
+++ b/lib/toolbox/stream/file_stream.c
@@ -0,0 +1,224 @@
+#include "stream.h"
+#include "stream_i.h"
+#include "file_stream.h"
+
+typedef struct {
+ Stream stream_base;
+ Storage* storage;
+ File* file;
+} FileStream;
+
+static void file_stream_free(FileStream* stream);
+static bool file_stream_eof(FileStream* stream);
+static void file_stream_clean(FileStream* stream);
+static bool file_stream_seek(FileStream* stream, int32_t offset, StreamOffset offset_type);
+static size_t file_stream_tell(FileStream* stream);
+static size_t file_stream_size(FileStream* stream);
+static size_t file_stream_write(FileStream* stream, const uint8_t* data, size_t size);
+static size_t file_stream_read(FileStream* stream, uint8_t* data, size_t size);
+static bool file_stream_delete_and_insert(
+ FileStream* stream,
+ size_t delete_size,
+ StreamWriteCB write_callback,
+ const void* ctx);
+
+const StreamVTable file_stream_vtable = {
+ .free = (StreamFreeFn)file_stream_free,
+ .eof = (StreamEOFFn)file_stream_eof,
+ .clean = (StreamCleanFn)file_stream_clean,
+ .seek = (StreamSeekFn)file_stream_seek,
+ .tell = (StreamTellFn)file_stream_tell,
+ .size = (StreamSizeFn)file_stream_size,
+ .write = (StreamWriteFn)file_stream_write,
+ .read = (StreamReadFn)file_stream_read,
+ .delete_and_insert = (StreamDeleteAndInsertFn)file_stream_delete_and_insert,
+};
+
+Stream* file_stream_alloc(Storage* storage) {
+ FileStream* stream = malloc(sizeof(FileStream));
+ stream->file = storage_file_alloc(storage);
+ stream->storage = storage;
+
+ stream->stream_base.vtable = &file_stream_vtable;
+ return (Stream*)stream;
+}
+
+bool file_stream_open(
+ Stream* _stream,
+ const char* path,
+ FS_AccessMode access_mode,
+ FS_OpenMode open_mode) {
+ furi_assert(_stream);
+ FileStream* stream = (FileStream*)_stream;
+ furi_check(stream->stream_base.vtable == &file_stream_vtable);
+ return storage_file_open(stream->file, path, access_mode, open_mode);
+}
+
+bool file_stream_close(Stream* _stream) {
+ furi_assert(_stream);
+ FileStream* stream = (FileStream*)_stream;
+ furi_check(stream->stream_base.vtable == &file_stream_vtable);
+ return storage_file_close(stream->file);
+}
+
+static void file_stream_free(FileStream* stream) {
+ storage_file_free(stream->file);
+ free(stream);
+}
+
+static bool file_stream_eof(FileStream* stream) {
+ return storage_file_eof(stream->file);
+}
+
+static void file_stream_clean(FileStream* stream) {
+ storage_file_seek(stream->file, 0, true);
+ storage_file_truncate(stream->file);
+}
+
+static bool file_stream_seek(FileStream* stream, int32_t offset, StreamOffset offset_type) {
+ bool result = false;
+ size_t seek_position = 0;
+ size_t current_position = file_stream_tell(stream);
+ size_t size = file_stream_size(stream);
+
+ // calc offset and limit to bottom
+ switch(offset_type) {
+ case StreamOffsetFromCurrent: {
+ if((int32_t)(current_position + offset) >= 0) {
+ seek_position = current_position + offset;
+ result = true;
+ }
+ } break;
+ case StreamOffsetFromStart: {
+ if(offset >= 0) {
+ seek_position = offset;
+ result = true;
+ }
+ } break;
+ case StreamOffsetFromEnd: {
+ if((int32_t)(size + offset) >= 0) {
+ seek_position = size + offset;
+ result = true;
+ }
+ } break;
+ }
+
+ if(result) {
+ // limit to top
+ if((int32_t)(seek_position - size) > 0) {
+ storage_file_seek(stream->file, size, true);
+ result = false;
+ } else {
+ result = storage_file_seek(stream->file, seek_position, true);
+ }
+ } else {
+ storage_file_seek(stream->file, 0, true);
+ }
+
+ return result;
+}
+
+static size_t file_stream_tell(FileStream* stream) {
+ return storage_file_tell(stream->file);
+}
+
+static size_t file_stream_size(FileStream* stream) {
+ return storage_file_size(stream->file);
+}
+
+static size_t file_stream_write(FileStream* stream, const uint8_t* data, size_t size) {
+ // TODO cache
+ size_t need_to_write = size;
+ while(need_to_write > 0) {
+ uint16_t was_written =
+ storage_file_write(stream->file, data + (size - need_to_write), need_to_write);
+ need_to_write -= was_written;
+
+ if(was_written == 0) break;
+ }
+
+ return size - need_to_write;
+}
+
+static size_t file_stream_read(FileStream* stream, uint8_t* data, size_t size) {
+ // TODO cache
+ size_t need_to_read = size;
+ while(need_to_read > 0) {
+ uint16_t was_read =
+ storage_file_read(stream->file, data + (size - need_to_read), need_to_read);
+ need_to_read -= was_read;
+
+ if(was_read == 0) break;
+ }
+
+ return size - need_to_read;
+}
+
+static bool file_stream_delete_and_insert(
+ FileStream* _stream,
+ size_t delete_size,
+ StreamWriteCB write_callback,
+ const void* ctx) {
+ bool result = false;
+ Stream* stream = (Stream*)_stream;
+
+ // open scratchpad
+ Stream* scratch_stream = file_stream_alloc(_stream->storage);
+
+ // TODO: we need something like "storage_open_tmpfile and storage_close_tmpfile"
+ string_t scratch_name;
+ string_t tmp_name;
+ string_init(tmp_name);
+ storage_get_next_filename(_stream->storage, "/any", ".scratch", ".pad", tmp_name);
+ string_init_printf(scratch_name, "/any/%s.pad", string_get_cstr(tmp_name));
+ string_clear(tmp_name);
+
+ do {
+ if(!file_stream_open(
+ scratch_stream, string_get_cstr(scratch_name), FSAM_READ_WRITE, FSOM_CREATE_NEW))
+ break;
+
+ size_t current_position = stream_tell(stream);
+ size_t file_size = stream_size(stream);
+
+ size_t size_to_delete = file_size - current_position;
+ size_to_delete = MIN(delete_size, size_to_delete);
+
+ size_t size_to_copy_before = current_position;
+ size_t size_to_copy_after = file_size - current_position - size_to_delete;
+
+ // copy file from 0 to insert position to scratchpad
+ if(!stream_rewind(stream)) break;
+ if(stream_copy(stream, scratch_stream, size_to_copy_before) != size_to_copy_before) break;
+
+ if(write_callback) {
+ if(!write_callback(scratch_stream, ctx)) break;
+ }
+ size_t new_position = stream_tell(scratch_stream);
+
+ // copy key file after insert position + size_to_delete to scratchpad
+ if(!stream_seek(stream, size_to_delete, StreamOffsetFromCurrent)) break;
+ if(stream_copy(stream, scratch_stream, size_to_copy_after) != size_to_copy_after) break;
+
+ size_t new_file_size = stream_size(scratch_stream);
+
+ // copy whole scratchpad file to the original file
+ if(!stream_rewind(stream)) break;
+ if(!stream_rewind(scratch_stream)) break;
+ if(stream_copy(scratch_stream, stream, new_file_size) != new_file_size) break;
+
+ // and truncate original file
+ if(!storage_file_truncate(_stream->file)) break;
+
+ // move seek pointer at insert end
+ if(!stream_seek(stream, new_position, StreamOffsetFromStart)) break;
+
+ result = true;
+ } while(false);
+
+ stream_free(scratch_stream);
+ storage_common_remove(_stream->storage, string_get_cstr(scratch_name));
+ string_clear(scratch_name);
+
+ return result;
+} \ No newline at end of file
diff --git a/lib/toolbox/stream/file_stream.h b/lib/toolbox/stream/file_stream.h
new file mode 100644
index 00000000..3f19d07b
--- /dev/null
+++ b/lib/toolbox/stream/file_stream.h
@@ -0,0 +1,40 @@
+#pragma once
+#include <stdlib.h>
+#include <storage/storage.h>
+#include "stream.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Allocate file stream
+ * @return Stream*
+ */
+Stream* file_stream_alloc(Storage* storage);
+
+/**
+ * Opens an existing file or create a new one.
+ * @param stream pointer to file stream object.
+ * @param path path to file
+ * @param access_mode access mode from FS_AccessMode
+ * @param open_mode open mode from FS_OpenMode
+ * @return success flag. You need to close the file even if the open operation failed.
+ */
+bool file_stream_open(
+ Stream* stream,
+ const char* path,
+ FS_AccessMode access_mode,
+ FS_OpenMode open_mode);
+
+/**
+ * Closes the file.
+ * @param stream
+ * @return true
+ * @return false
+ */
+bool file_stream_close(Stream* stream);
+
+#ifdef __cplusplus
+}
+#endif \ No newline at end of file
diff --git a/lib/toolbox/stream/stream.c b/lib/toolbox/stream/stream.c
new file mode 100644
index 00000000..9f223ab9
--- /dev/null
+++ b/lib/toolbox/stream/stream.c
@@ -0,0 +1,337 @@
+#include "stream.h"
+#include "stream_i.h"
+#include "file_stream.h"
+#include <furi/check.h>
+#include <furi/common_defines.h>
+
+void stream_free(Stream* stream) {
+ furi_assert(stream);
+ stream->vtable->free(stream);
+}
+
+void stream_clean(Stream* stream) {
+ furi_assert(stream);
+ stream->vtable->clean(stream);
+}
+
+bool stream_eof(Stream* stream) {
+ furi_assert(stream);
+ return stream->vtable->eof(stream);
+}
+
+bool stream_seek(Stream* stream, int32_t offset, StreamOffset offset_type) {
+ furi_assert(stream);
+ return stream->vtable->seek(stream, offset, offset_type);
+}
+
+size_t stream_tell(Stream* stream) {
+ furi_assert(stream);
+ return stream->vtable->tell(stream);
+}
+
+size_t stream_size(Stream* stream) {
+ furi_assert(stream);
+ return stream->vtable->size(stream);
+}
+
+size_t stream_write(Stream* stream, const uint8_t* data, size_t size) {
+ furi_assert(stream);
+ return stream->vtable->write(stream, data, size);
+}
+
+size_t stream_read(Stream* stream, uint8_t* data, size_t size) {
+ furi_assert(stream);
+ return stream->vtable->read(stream, data, size);
+}
+
+bool stream_delete_and_insert(
+ Stream* stream,
+ size_t delete_size,
+ StreamWriteCB write_callback,
+ const void* ctx) {
+ furi_assert(stream);
+ return stream->vtable->delete_and_insert(stream, delete_size, write_callback, ctx);
+}
+
+/********************************** Some random helpers starts here **********************************/
+
+typedef struct {
+ const uint8_t* data;
+ size_t size;
+} StreamWriteData;
+
+static bool stream_write_struct(Stream* stream, const void* context) {
+ furi_assert(stream);
+ furi_assert(context);
+ const StreamWriteData* write_data = context;
+ return (stream_write(stream, write_data->data, write_data->size) == write_data->size);
+}
+
+bool stream_read_line(Stream* stream, string_t str_result) {
+ string_reset(str_result);
+ const uint8_t buffer_size = 32;
+ uint8_t buffer[buffer_size];
+
+ do {
+ uint16_t bytes_were_read = stream_read(stream, buffer, buffer_size);
+ // TODO process EOF
+ if(bytes_were_read == 0) break;
+
+ bool result = false;
+ bool error = false;
+ for(uint16_t i = 0; i < bytes_were_read; i++) {
+ if(buffer[i] == '\n') {
+ if(!stream_seek(stream, i - bytes_were_read, StreamOffsetFromCurrent)) {
+ error = true;
+ break;
+ }
+
+ result = true;
+ break;
+ } else if(buffer[i] == '\r') {
+ // Ignore
+ } else {
+ string_push_back(str_result, buffer[i]);
+ }
+ }
+
+ if(result || error) {
+ break;
+ }
+ } while(true);
+
+ return string_size(str_result) != 0;
+}
+
+bool stream_rewind(Stream* stream) {
+ furi_assert(stream);
+ return stream_seek(stream, 0, StreamOffsetFromStart);
+}
+
+size_t stream_write_char(Stream* stream, char c) {
+ furi_assert(stream);
+ return stream_write(stream, (const uint8_t*)&c, 1);
+}
+
+size_t stream_write_string(Stream* stream, string_t string) {
+ furi_assert(stream);
+ return stream_write(stream, (const uint8_t*)string_get_cstr(string), string_size(string));
+}
+
+size_t stream_write_cstring(Stream* stream, const char* string) {
+ furi_assert(stream);
+ return stream_write(stream, (const uint8_t*)string, strlen(string));
+}
+
+size_t stream_write_format(Stream* stream, const char* format, ...) {
+ furi_assert(stream);
+ size_t size;
+ va_list args;
+ va_start(args, format);
+ size = stream_write_vaformat(stream, format, args);
+ va_end(args);
+ return size;
+}
+
+size_t stream_write_vaformat(Stream* stream, const char* format, va_list args) {
+ furi_assert(stream);
+ string_t data;
+ string_init_vprintf(data, format, args);
+ size_t size = stream_write_string(stream, data);
+ string_clear(data);
+
+ return size;
+}
+
+bool stream_insert(Stream* stream, const uint8_t* data, size_t size) {
+ furi_assert(stream);
+ StreamWriteData write_data = {.data = data, .size = size};
+ return stream_delete_and_insert(stream, 0, stream_write_struct, &write_data);
+}
+
+bool stream_insert_char(Stream* stream, char c) {
+ furi_assert(stream);
+ return stream_delete_and_insert_char(stream, 0, c);
+}
+
+bool stream_insert_string(Stream* stream, string_t string) {
+ furi_assert(stream);
+ return stream_delete_and_insert_string(stream, 0, string);
+}
+
+bool stream_insert_cstring(Stream* stream, const char* string) {
+ furi_assert(stream);
+ return stream_delete_and_insert_cstring(stream, 0, string);
+}
+
+bool stream_insert_format(Stream* stream, const char* format, ...) {
+ furi_assert(stream);
+ va_list args;
+ va_start(args, format);
+ bool result = stream_insert_vaformat(stream, format, args);
+ va_end(args);
+
+ return result;
+}
+
+bool stream_insert_vaformat(Stream* stream, const char* format, va_list args) {
+ furi_assert(stream);
+ return stream_delete_and_insert_vaformat(stream, 0, format, args);
+}
+
+bool stream_delete_and_insert_char(Stream* stream, size_t delete_size, char c) {
+ furi_assert(stream);
+ StreamWriteData write_data = {.data = (uint8_t*)&c, .size = 1};
+ return stream_delete_and_insert(stream, delete_size, stream_write_struct, &write_data);
+}
+
+bool stream_delete_and_insert_string(Stream* stream, size_t delete_size, string_t string) {
+ furi_assert(stream);
+ StreamWriteData write_data = {
+ .data = (uint8_t*)string_get_cstr(string), .size = string_size(string)};
+ return stream_delete_and_insert(stream, delete_size, stream_write_struct, &write_data);
+}
+
+bool stream_delete_and_insert_cstring(Stream* stream, size_t delete_size, const char* string) {
+ furi_assert(stream);
+ StreamWriteData write_data = {.data = (uint8_t*)string, .size = strlen(string)};
+ return stream_delete_and_insert(stream, delete_size, stream_write_struct, &write_data);
+}
+
+bool stream_delete_and_insert_format(Stream* stream, size_t delete_size, const char* format, ...) {
+ furi_assert(stream);
+ va_list args;
+ va_start(args, format);
+ bool result = stream_delete_and_insert_vaformat(stream, delete_size, format, args);
+ va_end(args);
+
+ return result;
+}
+
+bool stream_delete_and_insert_vaformat(
+ Stream* stream,
+ size_t delete_size,
+ const char* format,
+ va_list args) {
+ furi_assert(stream);
+ string_t data;
+ string_init_vprintf(data, format, args);
+ StreamWriteData write_data = {
+ .data = (uint8_t*)string_get_cstr(data), .size = string_size(data)};
+ bool result = stream_delete_and_insert(stream, 0, stream_write_struct, &write_data);
+ string_clear(data);
+
+ return result;
+}
+
+bool stream_delete(Stream* stream, size_t size) {
+ furi_assert(stream);
+ return stream_delete_and_insert(stream, size, NULL, NULL);
+}
+
+size_t stream_copy(Stream* stream_from, Stream* stream_to, size_t size) {
+ uint8_t* buffer = malloc(STREAM_CACHE_SIZE);
+ size_t copied = 0;
+
+ do {
+ size_t bytes_count = MIN(STREAM_CACHE_SIZE, size - copied);
+ if(bytes_count <= 0) {
+ break;
+ }
+
+ uint16_t bytes_were_read = stream_read(stream_from, buffer, bytes_count);
+ if(bytes_were_read != bytes_count) break;
+
+ uint16_t bytes_were_written = stream_write(stream_to, buffer, bytes_count);
+ if(bytes_were_written != bytes_count) break;
+
+ copied += bytes_count;
+ } while(true);
+
+ free(buffer);
+ return copied;
+}
+
+size_t stream_copy_full(Stream* stream_from, Stream* stream_to) {
+ size_t was_written = 0;
+
+ do {
+ if(!stream_seek(stream_from, 0, StreamOffsetFromStart)) break;
+ if(!stream_seek(stream_to, 0, StreamOffsetFromStart)) break;
+ was_written = stream_copy(stream_from, stream_to, stream_size(stream_from));
+ } while(false);
+
+ return was_written;
+}
+
+bool stream_split(Stream* stream, Stream* stream_left, Stream* stream_right) {
+ bool result = false;
+ size_t size = stream_size(stream);
+ size_t tell = stream_tell(stream);
+
+ do {
+ // copy right
+ if(stream_copy(stream, stream_right, size - tell) != (size - tell)) break;
+
+ // copy left
+ if(!stream_rewind(stream)) break;
+ if(stream_copy(stream, stream_left, tell) != tell) break;
+
+ // restore RW pointer
+ if(!stream_seek(stream, tell, StreamOffsetFromStart)) break;
+ result = true;
+ } while(false);
+
+ return result;
+}
+
+size_t stream_load_from_file(Stream* stream, Storage* storage, const char* path) {
+ size_t was_written = 0;
+ Stream* file = file_stream_alloc(storage);
+
+ do {
+ if(!file_stream_open(file, path, FSAM_READ, FSOM_OPEN_EXISTING)) break;
+ was_written = stream_copy(file, stream, stream_size(file));
+ } while(false);
+
+ stream_free(file);
+ return was_written;
+}
+
+size_t stream_save_to_file(Stream* stream, Storage* storage, const char* path, FS_OpenMode mode) {
+ size_t was_written = 0;
+ Stream* file = file_stream_alloc(storage);
+
+ do {
+ if(!file_stream_open(file, path, FSAM_WRITE, mode)) break;
+ was_written = stream_copy(stream, file, stream_size(stream));
+ } while(false);
+
+ stream_free(file);
+ return was_written;
+}
+
+void stream_dump_data(Stream* stream) {
+ size_t size = stream_size(stream);
+ size_t tell = stream_tell(stream);
+ printf("stream %p\r\n", stream);
+ printf("size = %u\r\n", size);
+ printf("tell = %u\r\n", tell);
+ printf("DATA START\r\n");
+ uint8_t* data = malloc(STREAM_CACHE_SIZE);
+ stream_rewind(stream);
+
+ while(true) {
+ size_t was_read = stream_read(stream, data, STREAM_CACHE_SIZE);
+ if(was_read == 0) break;
+
+ for(size_t i = 0; i < was_read; i++) {
+ printf("%c", data[i]);
+ }
+ }
+
+ free(data);
+ printf("\r\n");
+ printf("DATA END\r\n");
+ stream_seek(stream, tell, StreamOffsetFromStart);
+} \ No newline at end of file
diff --git a/lib/toolbox/stream/stream.h b/lib/toolbox/stream/stream.h
new file mode 100644
index 00000000..0fb35518
--- /dev/null
+++ b/lib/toolbox/stream/stream.h
@@ -0,0 +1,336 @@
+#pragma once
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <mlib/m-string.h>
+#include <storage/storage.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct Stream Stream;
+
+typedef enum {
+ StreamOffsetFromCurrent,
+ StreamOffsetFromStart,
+ StreamOffsetFromEnd,
+} StreamOffset;
+
+typedef bool (*StreamWriteCB)(Stream* stream, const void* context);
+
+/**
+ * Free Stream
+ * @param stream Stream instance
+ */
+void stream_free(Stream* stream);
+
+/**
+ * Clean (empty) Stream
+ * @param stream Stream instance
+ */
+void stream_clean(Stream* stream);
+
+/**
+ * Indicates that the rw pointer is at the end of the stream
+ * @param stream Stream instance
+ * @return true if rw pointer is at the end of the stream
+ * @return false if rw pointer is not at the end of the stream
+ */
+bool stream_eof(Stream* stream);
+
+/**
+ * Moves the rw pointer.
+ * @param stream Stream instance
+ * @param offset how much to move the pointer
+ * @param offset_type starting from what
+ * @return true
+ * @return false
+ */
+bool stream_seek(Stream* stream, int32_t offset, StreamOffset offset_type);
+
+/**
+ * Gets the value of the rw pointer
+ * @param stream Stream instance
+ * @return size_t value of the rw pointer
+ */
+size_t stream_tell(Stream* stream);
+
+/**
+ * Gets the size of the stream
+ * @param stream Stream instance
+ * @return size_t size of the stream
+ */
+size_t stream_size(Stream* stream);
+
+/**
+ * Write N bytes to the stream
+ * @param stream Stream instance
+ * @param data data to write
+ * @param size size of data to be written
+ * @return size_t how many bytes was written
+ */
+size_t stream_write(Stream* stream, const uint8_t* data, size_t size);
+
+/**
+ * Read N bytes from stream
+ * @param stream Stream instance
+ * @param data data to be read
+ * @param count size of data to be read
+ * @return size_t how many bytes was read
+ */
+size_t stream_read(Stream* stream, uint8_t* data, size_t count);
+
+/**
+ * Delete N chars from the stream and write data by calling write_callback(context)
+ * @param stream Stream instance
+ * @param delete_size size of data to be deleted
+ * @param write_callback write callback
+ * @param context write callback context
+ * @return true if the operation was successful
+ * @return false on error
+ */
+bool stream_delete_and_insert(
+ Stream* stream,
+ size_t delete_size,
+ StreamWriteCB write_callback,
+ const void* context);
+
+/********************************** Some random helpers starts here **********************************/
+
+/**
+ * Read line from a stream (supports LF and CRLF line endings)
+ * @param stream
+ * @param str_result
+ * @return true
+ * @return false
+ */
+bool stream_read_line(Stream* stream, string_t str_result);
+
+/**
+ * Moves the rw pointer to the start
+ * @param stream Stream instance
+ */
+bool stream_rewind(Stream* stream);
+
+/**
+ * Write char to the stream
+ * @param stream Stream instance
+ * @param c char value
+ * @return size_t how many bytes was written
+ */
+size_t stream_write_char(Stream* stream, char c);
+
+/**
+ * Write string to the stream
+ * @param stream Stream instance
+ * @param string string value
+ * @return size_t how many bytes was written
+ */
+size_t stream_write_string(Stream* stream, string_t string);
+
+/**
+ * Write const char* to the stream
+ * @param stream Stream instance
+ * @param string c-string value
+ * @return size_t how many bytes was written
+ */
+size_t stream_write_cstring(Stream* stream, const char* string);
+
+/**
+ * Write formatted string to the stream
+ * @param stream Stream instance
+ * @param format
+ * @param ...
+ * @return size_t how many bytes was written
+ */
+size_t stream_write_format(Stream* stream, const char* format, ...);
+
+/**
+ * Write formatted string to the stream, va_list version
+ * @param stream Stream instance
+ * @param format
+ * @param args
+ * @return size_t how many bytes was written
+ */
+size_t stream_write_vaformat(Stream* stream, const char* format, va_list args);
+
+/**
+ * Insert N chars to the stream, starting at the current pointer.
+ * Data will be inserted, not overwritteт, so the stream will be increased in size.
+ * @param stream Stream instance
+ * @param data data to be inserted
+ * @param size size of data to be inserted
+ * @return true if the operation was successful
+ * @return false on error
+ */
+bool stream_insert(Stream* stream, const uint8_t* data, size_t size);
+
+/**
+ * Insert char to the stream
+ * @param stream Stream instance
+ * @param c char value
+ * @return true if the operation was successful
+ * @return false on error
+ */
+bool stream_insert_char(Stream* stream, char c);
+
+/**
+ * Insert string to the stream
+ * @param stream Stream instance
+ * @param string string value
+ * @return true if the operation was successful
+ * @return false on error
+ */
+bool stream_insert_string(Stream* stream, string_t string);
+
+/**
+ * Insert const char* to the stream
+ * @param stream Stream instance
+ * @param string c-string value
+ * @return true if the operation was successful
+ * @return false on error
+ */
+bool stream_insert_cstring(Stream* stream, const char* string);
+
+/**
+ * Insert formatted string to the stream
+ * @param stream Stream instance
+ * @param format
+ * @param ...
+ * @return true if the operation was successful
+ * @return false on error
+ */
+bool stream_insert_format(Stream* stream, const char* format, ...);
+
+/**
+ * Insert formatted string to the stream, va_list version
+ * @param stream Stream instance
+ * @param format
+ * @param args
+ * @return true if the operation was successful
+ * @return false on error
+ */
+bool stream_insert_vaformat(Stream* stream, const char* format, va_list args);
+
+/**
+ * Delete N chars from the stream and insert char to the stream
+ * @param stream Stream instance
+ * @param delete_size size of data to be deleted
+ * @param c char value
+ * @return true if the operation was successful
+ * @return false on error
+ */
+bool stream_delete_and_insert_char(Stream* stream, size_t delete_size, char c);
+
+/**
+ * Delete N chars from the stream and insert string to the stream
+ * @param stream Stream instance
+ * @param delete_size size of data to be deleted
+ * @param string string value
+ * @return true if the operation was successful
+ * @return false on error
+ */
+bool stream_delete_and_insert_string(Stream* stream, size_t delete_size, string_t string);
+
+/**
+ * Delete N chars from the stream and insert const char* to the stream
+ * @param stream Stream instance
+ * @param delete_size size of data to be deleted
+ * @param string c-string value
+ * @return true if the operation was successful
+ * @return false on error
+ */
+bool stream_delete_and_insert_cstring(Stream* stream, size_t delete_size, const char* string);
+
+/**
+ * Delete N chars from the stream and insert formatted string to the stream
+ * @param stream Stream instance
+ * @param delete_size size of data to be deleted
+ * @param format
+ * @param ...
+ * @return true if the operation was successful
+ * @return false on error
+ */
+bool stream_delete_and_insert_format(Stream* stream, size_t delete_size, const char* format, ...);
+
+/**
+ * Delete N chars from the stream and insert formatted string to the stream, va_list version
+ * @param stream Stream instance
+ * @param delete_size size of data to be deleted
+ * @param format
+ * @param args
+ * @return true if the operation was successful
+ * @return false on error
+ */
+bool stream_delete_and_insert_vaformat(
+ Stream* stream,
+ size_t delete_size,
+ const char* format,
+ va_list args);
+
+/**
+ * Remove N chars from the stream, starting at the current pointer.
+ * The size may be larger than stream size, the stream will be cleared from current rw pointer to the end.
+ * @param stream Stream instance
+ * @param size how many chars need to be deleted
+ * @return true if the operation was successful
+ * @return false on error
+ */
+bool stream_delete(Stream* stream, size_t size);
+
+/**
+ * Copy data from one stream to another. Data will be copied from current rw pointer and to current rw pointer.
+ * @param stream_from
+ * @param stream_to
+ * @param size
+ * @return size_t
+ */
+size_t stream_copy(Stream* stream_from, Stream* stream_to, size_t size);
+
+/**
+ * Copy data from one stream to another. Data will be copied from start of one stream and to start of other stream.
+ * @param stream_from
+ * @param stream_to
+ * @return size_t
+ */
+size_t stream_copy_full(Stream* stream_from, Stream* stream_to);
+
+/**
+ * Splits one stream into two others. The original stream will remain untouched.
+ * @param stream
+ * @param stream_left
+ * @param stream_right
+ * @return true
+ * @return false
+ */
+bool stream_split(Stream* stream, Stream* stream_left, Stream* stream_right);
+
+/**
+ * Loads data to the stream from a file. Data will be loaded to the current RW pointer. RW pointer will be moved to the end of the stream.
+ * @param stream Stream instance
+ * @param storage
+ * @param path
+ * @return size_t
+ */
+size_t stream_load_from_file(Stream* stream, Storage* storage, const char* path);
+
+/**
+ * Writes data from a stream to a file. Data will be saved starting from the current RW pointer. RW pointer will be moved to the end of the stream.
+ * @param stream Stream instance
+ * @param storage
+ * @param path
+ * @param mode
+ * @return size_t
+ */
+size_t stream_save_to_file(Stream* stream, Storage* storage, const char* path, FS_OpenMode mode);
+
+/**
+ * Dump stream inner data (size, RW positiot, content)
+ * @param stream Stream instance
+ */
+void stream_dump_data(Stream* stream);
+
+#ifdef __cplusplus
+}
+#endif \ No newline at end of file
diff --git a/lib/toolbox/stream/stream_i.h b/lib/toolbox/stream/stream_i.h
new file mode 100644
index 00000000..a62e174c
--- /dev/null
+++ b/lib/toolbox/stream/stream_i.h
@@ -0,0 +1,46 @@
+#pragma once
+#include <stdint.h>
+#include <stdbool.h>
+#include "stream.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define STREAM_CACHE_SIZE 512
+
+typedef struct StreamVTable StreamVTable;
+
+typedef void (*StreamFreeFn)(Stream* stream);
+typedef bool (*StreamEOFFn)(Stream* stream);
+typedef void (*StreamCleanFn)(Stream* stream);
+typedef bool (*StreamSeekFn)(Stream* stream, int32_t offset, StreamOffset offset_type);
+typedef size_t (*StreamTellFn)(Stream* stream);
+typedef size_t (*StreamSizeFn)(Stream* stream);
+typedef size_t (*StreamWriteFn)(Stream* stream, const uint8_t* data, size_t size);
+typedef size_t (*StreamReadFn)(Stream* stream, uint8_t* data, size_t count);
+typedef bool (*StreamDeleteAndInsertFn)(
+ Stream* stream,
+ size_t delete_size,
+ StreamWriteCB write_cb,
+ const void* ctx);
+
+struct StreamVTable {
+ const StreamFreeFn free;
+ const StreamEOFFn eof;
+ const StreamCleanFn clean;
+ const StreamSeekFn seek;
+ const StreamTellFn tell;
+ const StreamSizeFn size;
+ const StreamWriteFn write;
+ const StreamReadFn read;
+ const StreamDeleteAndInsertFn delete_and_insert;
+};
+
+struct Stream {
+ const StreamVTable* vtable;
+};
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/lib/toolbox/stream/string_stream.c b/lib/toolbox/stream/string_stream.c
new file mode 100644
index 00000000..5fec06c3
--- /dev/null
+++ b/lib/toolbox/stream/string_stream.c
@@ -0,0 +1,179 @@
+#include "stream.h"
+#include "stream_i.h"
+#include "string_stream.h"
+#include <furi/common_defines.h>
+
+typedef struct {
+ Stream stream_base;
+ string_t string;
+ size_t index;
+} StringStream;
+
+static size_t string_stream_write_char(StringStream* stream, char c);
+
+static void string_stream_free(StringStream* stream);
+static bool string_stream_eof(StringStream* stream);
+static void string_stream_clean(StringStream* stream);
+static bool string_stream_seek(StringStream* stream, int32_t offset, StreamOffset offset_type);
+static size_t string_stream_tell(StringStream* stream);
+static size_t string_stream_size(StringStream* stream);
+static size_t string_stream_write(StringStream* stream, const char* data, size_t size);
+static size_t string_stream_read(StringStream* stream, char* data, size_t size);
+static bool string_stream_delete_and_insert(
+ StringStream* stream,
+ size_t delete_size,
+ StreamWriteCB write_callback,
+ const void* ctx);
+
+const StreamVTable string_stream_vtable = {
+ .free = (StreamFreeFn)string_stream_free,
+ .eof = (StreamEOFFn)string_stream_eof,
+ .clean = (StreamCleanFn)string_stream_clean,
+ .seek = (StreamSeekFn)string_stream_seek,
+ .tell = (StreamTellFn)string_stream_tell,
+ .size = (StreamSizeFn)string_stream_size,
+ .write = (StreamWriteFn)string_stream_write,
+ .read = (StreamReadFn)string_stream_read,
+ .delete_and_insert = (StreamDeleteAndInsertFn)string_stream_delete_and_insert,
+};
+
+Stream* string_stream_alloc() {
+ StringStream* stream = malloc(sizeof(StringStream));
+ string_init(stream->string);
+ stream->index = 0;
+ stream->stream_base.vtable = &string_stream_vtable;
+ return (Stream*)stream;
+}
+
+static void string_stream_free(StringStream* stream) {
+ string_clear(stream->string);
+ free(stream);
+}
+
+static bool string_stream_eof(StringStream* stream) {
+ return (string_stream_tell(stream) >= string_stream_size(stream));
+}
+
+static void string_stream_clean(StringStream* stream) {
+ stream->index = 0;
+ string_reset(stream->string);
+}
+
+static bool string_stream_seek(StringStream* stream, int32_t offset, StreamOffset offset_type) {
+ bool result = true;
+ switch(offset_type) {
+ case StreamOffsetFromStart:
+ if(offset >= 0) {
+ stream->index = offset;
+ } else {
+ result = false;
+ stream->index = 0;
+ }
+ break;
+ case StreamOffsetFromCurrent:
+ if(((int32_t)stream->index + offset) >= 0) {
+ stream->index += offset;
+ } else {
+ result = false;
+ stream->index = 0;
+ }
+ break;
+ case StreamOffsetFromEnd:
+ if(((int32_t)string_size(stream->string) + offset) >= 0) {
+ stream->index = string_size(stream->string) + offset;
+ } else {
+ result = false;
+ stream->index = 0;
+ }
+ break;
+ }
+
+ int32_t diff = (stream->index - string_size(stream->string));
+ if(diff > 0) {
+ stream->index -= diff;
+ result = false;
+ }
+
+ return result;
+}
+
+static size_t string_stream_tell(StringStream* stream) {
+ return stream->index;
+}
+
+static size_t string_stream_size(StringStream* stream) {
+ return string_size(stream->string);
+}
+
+static size_t string_stream_write(StringStream* stream, const char* data, size_t size) {
+ // TODO: can be optimized for edge cases
+ size_t i;
+ for(i = 0; i < size; i++) {
+ string_stream_write_char(stream, data[i]);
+ }
+
+ return i;
+}
+
+static size_t string_stream_read(StringStream* stream, char* data, size_t size) {
+ size_t write_index = 0;
+ const char* cstr = string_get_cstr(stream->string);
+
+ if(!string_stream_eof(stream)) {
+ while(true) {
+ if(write_index >= size) break;
+
+ data[write_index] = cstr[stream->index];
+ write_index++;
+ string_stream_seek(stream, 1, StreamOffsetFromCurrent);
+ if(string_stream_eof(stream)) break;
+ }
+ }
+
+ return write_index;
+}
+
+static bool string_stream_delete_and_insert(
+ StringStream* stream,
+ size_t delete_size,
+ StreamWriteCB write_callback,
+ const void* ctx) {
+ bool result = true;
+
+ if(delete_size) {
+ size_t remain_size = string_stream_size(stream) - string_stream_tell(stream);
+ remain_size = MIN(delete_size, remain_size);
+
+ if(remain_size != 0) {
+ string_replace_at(stream->string, stream->index, remain_size, "");
+ }
+ }
+
+ if(write_callback) {
+ string_t right;
+ string_init_set(right, &string_get_cstr(stream->string)[stream->index]);
+ string_left(stream->string, string_stream_tell(stream));
+ result &= write_callback((Stream*)stream, ctx);
+ string_cat(stream->string, right);
+ string_clear(right);
+ }
+
+ return result;
+}
+
+/**
+ * Write to string stream helper
+ * @param stream
+ * @param c
+ * @return size_t
+ */
+static size_t string_stream_write_char(StringStream* stream, char c) {
+ if(string_stream_eof(stream)) {
+ string_push_back(stream->string, c);
+ } else {
+ string_set_char(stream->string, stream->index, c);
+ }
+ stream->index++;
+
+ return 1;
+} \ No newline at end of file
diff --git a/lib/toolbox/stream/string_stream.h b/lib/toolbox/stream/string_stream.h
new file mode 100644
index 00000000..1827258d
--- /dev/null
+++ b/lib/toolbox/stream/string_stream.h
@@ -0,0 +1,18 @@
+#pragma once
+#include <stdlib.h>
+#include <mlib/m-string.h>
+#include "stream.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Allocate string stream
+ * @return Stream*
+ */
+Stream* string_stream_alloc();
+
+#ifdef __cplusplus
+}
+#endif \ No newline at end of file