unleashed-firmware/applications/main/subghz/subghz.c

455 lines
16 KiB
C
Raw Normal View History

/* Abandon hope, all ye who enter here. */
#include <subghz/types.h>
#include <lib/toolbox/path.h>
#include "subghz_i.h"
#include <lib/subghz/protocols/protocol_items.h>
2022-09-28 01:01:09 +03:00
#define TAG "SubGhzApp"
2021-08-12 17:42:56 +03:00
bool subghz_custom_event_callback(void* context, uint32_t event) {
furi_assert(context);
SubGhz* subghz = context;
2021-08-12 17:42:56 +03:00
return scene_manager_handle_custom_event(subghz->scene_manager, event);
}
2021-08-12 17:42:56 +03:00
bool subghz_back_event_callback(void* context) {
furi_assert(context);
SubGhz* subghz = context;
return scene_manager_handle_back_event(subghz->scene_manager);
}
2021-08-12 17:42:56 +03:00
void subghz_tick_event_callback(void* context) {
furi_assert(context);
SubGhz* subghz = context;
scene_manager_handle_tick_event(subghz->scene_manager);
}
static void subghz_rpc_command_callback(RpcAppSystemEvent event, void* context) {
furi_assert(context);
SubGhz* subghz = context;
furi_assert(subghz->rpc_ctx);
if(event == RpcAppEventSessionClose) {
view_dispatcher_send_custom_event(
subghz->view_dispatcher, SubGhzCustomEventSceneRpcSessionClose);
2022-08-12 05:18:27 +03:00
rpc_system_app_set_callback(subghz->rpc_ctx, NULL, NULL);
subghz->rpc_ctx = NULL;
} else if(event == RpcAppEventAppExit) {
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventSceneExit);
} else if(event == RpcAppEventLoadFile) {
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventSceneRpcLoad);
} else if(event == RpcAppEventButtonPress) {
view_dispatcher_send_custom_event(
subghz->view_dispatcher, SubGhzCustomEventSceneRpcButtonPress);
} else if(event == RpcAppEventButtonRelease) {
view_dispatcher_send_custom_event(
subghz->view_dispatcher, SubGhzCustomEventSceneRpcButtonRelease);
} else {
rpc_system_app_confirm(subghz->rpc_ctx, event, false);
}
}
void subghz_blink_start(SubGhz* instance) {
furi_assert(instance);
notification_message(instance->notifications, &sequence_blink_start_magenta);
}
void subghz_blink_stop(SubGhz* instance) {
furi_assert(instance);
notification_message(instance->notifications, &sequence_blink_stop);
}
SubGhz* subghz_alloc(bool alloc_for_tx_only) {
[FL-2274] Inventing streams and moving FFF to them (#981) * Streams: string stream * String stream: updated insert/delete api * Streams: generic stream interface and string stream implementation * Streams: helpers for insert and delete_and_insert * FFF: now compatible with streams * MinUnit: introduced tests with arguments * FFF: stream access violation * Streams: copy data between streams * Streams: file stream * FFF: documentation * FFStream: documentation * FFF: alloc as file * MinUnit: support for nested tests * Streams: changed delete_and_insert, now it returns success flag. Added ability dump stream inner parameters and data to cout. * FFF: simplified file open function * Streams: unit tests * FFF: tests * Streams: declare cache_size constant as define, to allow variable modified arrays * FFF: lib moved to a separate folder * iButton: new FFF * RFID: new FFF * Animations: new FFF * IR: new FFF * NFC: new FFF * Flipper file format: delete lib * U2F: new FFF * Subghz: new FFF and streams * Streams: read line * Streams: split * FuriCore: implement memset with extra asserts * FuriCore: implement extra heap asserts without inventing memset * Scene manager: protected access to the scene id stack with a size check * NFC worker: dirty fix for issue where hal_nfc was busy on app start * Furi: update allocator to erase memory on allocation. Replace furi_alloc with malloc. * FuriCore: cleanup memmgr code. * Furi HAL: furi_hal_init is split into critical and non-critical parts. The critical part is currently clock and console. * Memmgr: added ability to track allocations and deallocations through console. * FFStream: some speedup * Streams, FF: minor fixes * Tests: restore * File stream: a slightly more thread-safe version of file_stream_delete_and_insert Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2022-02-18 22:53:46 +03:00
SubGhz* subghz = malloc(sizeof(SubGhz));
subghz->file_path = furi_string_alloc();
subghz->file_path_tmp = furi_string_alloc();
2022-06-01 16:07:53 +03:00
// GUI
subghz->gui = furi_record_open(RECORD_GUI);
subghz->in_decoder_scene = false;
subghz->in_decoder_scene_skip = false;
// View Dispatcher
subghz->view_dispatcher = view_dispatcher_alloc();
view_dispatcher_enable_queue(subghz->view_dispatcher);
2021-08-12 17:42:56 +03:00
subghz->scene_manager = scene_manager_alloc(&subghz_scene_handlers, subghz);
view_dispatcher_set_event_callback_context(subghz->view_dispatcher, subghz);
view_dispatcher_set_custom_event_callback(
subghz->view_dispatcher, subghz_custom_event_callback);
view_dispatcher_set_navigation_event_callback(
subghz->view_dispatcher, subghz_back_event_callback);
view_dispatcher_set_tick_event_callback(
subghz->view_dispatcher, subghz_tick_event_callback, 100);
SubGhz: read and save static remotes. Create new static and dynamic remotes. (#646) * SubGhz: the functions of saving loading KeeLog have been modified, saving KeeLog is prohibited * SubGhz: Fix displaying Nice FlorS in the Raed scene * SubGhz: Fix displaying Faac SLH in the Raed scene * SubGhz: Fix displaying iDo in the Raed scene * SubGhz: Fix displaying Star Line in the Raed scene * SubGhz: Fix displaying Nice Flo in the Raed scene, added save and load functions. (testing needed, no remote control) * SubGhz: subghz_beginadded common encoder upload signal * SubGhz: add Came encoder * SubGhz: modified pricenton encoder, fix view transmitter hide the "Send" button if there is no encoder * SubGhz: add nice flo encoder, need testing no remote control * SubGhz: add gate_tx encoder * SubGhz: add nero_sketch encoder * SubGhz: add keelog encoder * SubGhz: add long upload upload while the button is pressed while releasing the transfer is over, with a check for sticking (maximum 200 upload repetitions) * SubGhz: fix max upload * SubGhz: Fix structure subghz add encoder * SubGhz: add generating and sending a dynamic keelog key, refactoring the code * SubGhz: add notifications * SubGhz: add creating a new remote control (Pricenton, Nice Flo 12bit, Nice Flo 24bit, CAME 12bit, CAME 24bit, Gate TX, DoorHan) * SubGhz: Fix load file, fix scene start * Subghz: Fix show key * SubGhz: Fix subghz_cli * SubGhz: Fix furi-hal-subghz * Format sources * SubGhz: standard notification scheme, fix broken assert in DMA. * SubGhz: move level alignment logic to furi-hal-subghz, fix spelling, cleanup. Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-08-16 22:56:23 +03:00
// Open Notification record
subghz->notifications = furi_record_open(RECORD_NOTIFICATION);
SubGhz: read and save static remotes. Create new static and dynamic remotes. (#646) * SubGhz: the functions of saving loading KeeLog have been modified, saving KeeLog is prohibited * SubGhz: Fix displaying Nice FlorS in the Raed scene * SubGhz: Fix displaying Faac SLH in the Raed scene * SubGhz: Fix displaying iDo in the Raed scene * SubGhz: Fix displaying Star Line in the Raed scene * SubGhz: Fix displaying Nice Flo in the Raed scene, added save and load functions. (testing needed, no remote control) * SubGhz: subghz_beginadded common encoder upload signal * SubGhz: add Came encoder * SubGhz: modified pricenton encoder, fix view transmitter hide the "Send" button if there is no encoder * SubGhz: add nice flo encoder, need testing no remote control * SubGhz: add gate_tx encoder * SubGhz: add nero_sketch encoder * SubGhz: add keelog encoder * SubGhz: add long upload upload while the button is pressed while releasing the transfer is over, with a check for sticking (maximum 200 upload repetitions) * SubGhz: fix max upload * SubGhz: Fix structure subghz add encoder * SubGhz: add generating and sending a dynamic keelog key, refactoring the code * SubGhz: add notifications * SubGhz: add creating a new remote control (Pricenton, Nice Flo 12bit, Nice Flo 24bit, CAME 12bit, CAME 24bit, Gate TX, DoorHan) * SubGhz: Fix load file, fix scene start * Subghz: Fix show key * SubGhz: Fix subghz_cli * SubGhz: Fix furi-hal-subghz * Format sources * SubGhz: standard notification scheme, fix broken assert in DMA. * SubGhz: move level alignment logic to furi-hal-subghz, fix spelling, cleanup. Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-08-16 22:56:23 +03:00
if(!alloc_for_tx_only) {
// SubMenu
subghz->submenu = submenu_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher, SubGhzViewIdMenu, submenu_get_view(subghz->submenu));
// Receiver
subghz->subghz_receiver = subghz_view_receiver_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher,
SubGhzViewIdReceiver,
subghz_view_receiver_get_view(subghz->subghz_receiver));
}
2021-08-12 17:42:56 +03:00
// Popup
subghz->popup = popup_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher, SubGhzViewIdPopup, popup_get_view(subghz->popup));
if(!alloc_for_tx_only) {
// Text Input
subghz->text_input = text_input_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher,
SubGhzViewIdTextInput,
text_input_get_view(subghz->text_input));
// Byte Input
subghz->byte_input = byte_input_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher,
SubGhzViewIdByteInput,
byte_input_get_view(subghz->byte_input));
// Custom Widget
subghz->widget = widget_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher, SubGhzViewIdWidget, widget_get_view(subghz->widget));
}
//Dialog
subghz->dialogs = furi_record_open(RECORD_DIALOGS);
2021-08-12 17:42:56 +03:00
// Transmitter
subghz->subghz_transmitter = subghz_view_transmitter_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher,
SubGhzViewIdTransmitter,
subghz_view_transmitter_get_view(subghz->subghz_transmitter));
if(!alloc_for_tx_only) {
// Variable Item List
subghz->variable_item_list = variable_item_list_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher,
SubGhzViewIdVariableItemList,
variable_item_list_get_view(subghz->variable_item_list));
// Frequency Analyzer
subghz->subghz_frequency_analyzer = subghz_frequency_analyzer_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher,
SubGhzViewIdFrequencyAnalyzer,
subghz_frequency_analyzer_get_view(subghz->subghz_frequency_analyzer));
// Carrier Test Module
subghz->subghz_test_carrier = subghz_test_carrier_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher,
SubGhzViewIdTestCarrier,
subghz_test_carrier_get_view(subghz->subghz_test_carrier));
}
// Read RAW
subghz->subghz_read_raw = subghz_read_raw_alloc(alloc_for_tx_only);
view_dispatcher_add_view(
subghz->view_dispatcher,
SubGhzViewIdReadRAW,
subghz_read_raw_get_view(subghz->subghz_read_raw));
#if FURI_DEBUG
// Packet Test
subghz->subghz_test_packet = subghz_test_packet_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher,
SubGhzViewIdTestPacket,
subghz_test_packet_get_view(subghz->subghz_test_packet));
// Static send
subghz->subghz_test_static = subghz_test_static_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher,
SubGhzViewIdStatic,
subghz_test_static_get_view(subghz->subghz_test_static));
#endif
//init setting
subghz->setting = subghz_setting_alloc();
if(alloc_for_tx_only) {
subghz_setting_load(subghz->setting, EXT_PATH("subghz/assets/setting_user"), false);
} else {
subghz_setting_load(subghz->setting, EXT_PATH("subghz/assets/setting_user"), true);
}
2022-09-28 01:01:09 +03:00
// Load last used values for Read, Read RAW, etc. or default
if(!alloc_for_tx_only) {
subghz->last_settings = subghz_last_settings_alloc();
subghz_last_settings_load(subghz->last_settings, 0);
#if FURI_DEBUG
#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING
FURI_LOG_D(
TAG,
2022-10-07 23:05:00 +03:00
"last frequency: %ld, preset: %ld, detect_raw: %d",
subghz->last_settings->frequency,
subghz->last_settings->preset,
subghz->last_settings->detect_raw);
#else
FURI_LOG_D(
TAG,
2022-10-07 23:05:00 +03:00
"last frequency: %ld, preset: %ld",
subghz->last_settings->frequency,
subghz->last_settings->preset);
#endif
2022-09-28 01:01:09 +03:00
#endif
subghz_setting_set_default_frequency(subghz->setting, subghz->last_settings->frequency);
}
//init Worker & Protocol & History & KeyBoard
subghz->lock = SubGhzLockOff;
[FL-2274] Inventing streams and moving FFF to them (#981) * Streams: string stream * String stream: updated insert/delete api * Streams: generic stream interface and string stream implementation * Streams: helpers for insert and delete_and_insert * FFF: now compatible with streams * MinUnit: introduced tests with arguments * FFF: stream access violation * Streams: copy data between streams * Streams: file stream * FFF: documentation * FFStream: documentation * FFF: alloc as file * MinUnit: support for nested tests * Streams: changed delete_and_insert, now it returns success flag. Added ability dump stream inner parameters and data to cout. * FFF: simplified file open function * Streams: unit tests * FFF: tests * Streams: declare cache_size constant as define, to allow variable modified arrays * FFF: lib moved to a separate folder * iButton: new FFF * RFID: new FFF * Animations: new FFF * IR: new FFF * NFC: new FFF * Flipper file format: delete lib * U2F: new FFF * Subghz: new FFF and streams * Streams: read line * Streams: split * FuriCore: implement memset with extra asserts * FuriCore: implement extra heap asserts without inventing memset * Scene manager: protected access to the scene id stack with a size check * NFC worker: dirty fix for issue where hal_nfc was busy on app start * Furi: update allocator to erase memory on allocation. Replace furi_alloc with malloc. * FuriCore: cleanup memmgr code. * Furi HAL: furi_hal_init is split into critical and non-critical parts. The critical part is currently clock and console. * Memmgr: added ability to track allocations and deallocations through console. * FFStream: some speedup * Streams, FF: minor fixes * Tests: restore * File stream: a slightly more thread-safe version of file_stream_delete_and_insert Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2022-02-18 22:53:46 +03:00
subghz->txrx = malloc(sizeof(SubGhzTxRx));
subghz->txrx->preset = malloc(sizeof(SubGhzRadioPreset));
2022-10-05 21:27:13 +03:00
subghz->txrx->preset->name = furi_string_alloc();
if(!alloc_for_tx_only) {
subghz_preset_init(subghz, "AM650", subghz->last_settings->frequency, NULL, 0);
} else {
subghz_preset_init(
subghz, "AM650", subghz_setting_get_default_frequency(subghz->setting), NULL, 0);
}
subghz->txrx->txrx_state = SubGhzTxRxStateSleep;
2022-09-17 20:33:26 +03:00
subghz->txrx->hopper_state = SubGhzHopperStateOFF;
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
if(!alloc_for_tx_only) {
subghz->txrx->history = subghz_history_alloc();
}
2022-10-02 09:51:27 +03:00
subghz->txrx->raw_threshold_rssi = SUBGHZ_RAW_TRESHOLD_MIN;
2022-10-02 09:51:27 +03:00
subghz->txrx->worker = subghz_worker_alloc();
subghz->txrx->fff_data = flipper_format_string_alloc();
2022-04-20 22:23:45 +03:00
subghz->txrx->secure_data = malloc(sizeof(SecureData));
2022-06-01 16:07:53 +03:00
subghz->txrx->environment = subghz_environment_alloc();
subghz_environment_set_came_atomo_rainbow_table_file_name(
subghz->txrx->environment, EXT_PATH("subghz/assets/came_atomo"));
subghz_environment_set_nice_flor_s_rainbow_table_file_name(
subghz->txrx->environment, EXT_PATH("subghz/assets/nice_flor_s"));
subghz_environment_set_protocol_registry(
subghz->txrx->environment, (void*)&subghz_protocol_registry);
subghz->txrx->receiver = subghz_receiver_alloc_init(subghz->txrx->environment);
#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING
subghz_last_settings_set_detect_raw_values(subghz);
#else
2022-10-02 06:38:34 +03:00
subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable);
#endif
2022-10-02 09:51:27 +03:00
subghz_worker_set_overrun_callback(
subghz->txrx->worker, (SubGhzWorkerOverrunCallback)subghz_receiver_reset);
subghz_worker_set_pair_callback(
subghz->txrx->worker, (SubGhzWorkerPairCallback)subghz_receiver_decode);
subghz_worker_set_context(subghz->txrx->worker, subghz->txrx->receiver);
2021-08-12 17:42:56 +03:00
//Init Error_str
subghz->error_str = furi_string_alloc();
return subghz;
}
void subghz_free(SubGhz* subghz, bool alloc_for_tx_only) {
furi_assert(subghz);
if(subghz->rpc_ctx) {
rpc_system_app_set_callback(subghz->rpc_ctx, NULL, NULL);
rpc_system_app_send_exited(subghz->rpc_ctx);
subghz_blink_stop(subghz);
subghz->rpc_ctx = NULL;
}
#if FURI_DEBUG
// Packet Test
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdTestPacket);
2021-08-12 17:42:56 +03:00
subghz_test_packet_free(subghz->subghz_test_packet);
// Static
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdStatic);
subghz_test_static_free(subghz->subghz_test_static);
#endif
2021-08-12 17:42:56 +03:00
if(!alloc_for_tx_only) {
// Carrier Test
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdTestCarrier);
subghz_test_carrier_free(subghz->subghz_test_carrier);
// Receiver
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdReceiver);
subghz_view_receiver_free(subghz->subghz_receiver);
// TextInput
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdTextInput);
text_input_free(subghz->text_input);
2022-04-20 19:04:19 +03:00
// ByteInput
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdByteInput);
byte_input_free(subghz->byte_input);
// Custom Widget
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdWidget);
widget_free(subghz->widget);
}
//Dialog
furi_record_close(RECORD_DIALOGS);
// Transmitter
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdTransmitter);
subghz_view_transmitter_free(subghz->subghz_transmitter);
if(!alloc_for_tx_only) {
// Variable Item List
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdVariableItemList);
variable_item_list_free(subghz->variable_item_list);
// Frequency Analyzer
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdFrequencyAnalyzer);
subghz_frequency_analyzer_free(subghz->subghz_frequency_analyzer);
}
// Read RAW
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdReadRAW);
subghz_read_raw_free(subghz->subghz_read_raw);
if(!alloc_for_tx_only) {
// Submenu
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdMenu);
submenu_free(subghz->submenu);
}
2021-08-12 17:42:56 +03:00
// Popup
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdPopup);
2021-08-12 17:42:56 +03:00
popup_free(subghz->popup);
// Scene manager
scene_manager_free(subghz->scene_manager);
// View Dispatcher
view_dispatcher_free(subghz->view_dispatcher);
// GUI
furi_record_close(RECORD_GUI);
subghz->gui = NULL;
//setting
subghz_setting_free(subghz->setting);
if(!alloc_for_tx_only) {
subghz_last_settings_free(subghz->last_settings);
}
//Worker & Protocol & History
subghz_receiver_free(subghz->txrx->receiver);
subghz_environment_free(subghz->txrx->environment);
2022-10-02 09:51:27 +03:00
subghz_worker_free(subghz->txrx->worker);
flipper_format_free(subghz->txrx->fff_data);
if(!alloc_for_tx_only) {
subghz_history_free(subghz->txrx->history);
}
2022-10-05 21:27:13 +03:00
furi_string_free(subghz->txrx->preset->name);
free(subghz->txrx->preset);
2022-04-20 22:23:45 +03:00
free(subghz->txrx->secure_data);
2022-04-20 19:08:25 +03:00
free(subghz->txrx);
//Error string
furi_string_free(subghz->error_str);
2021-08-12 17:42:56 +03:00
SubGhz: read and save static remotes. Create new static and dynamic remotes. (#646) * SubGhz: the functions of saving loading KeeLog have been modified, saving KeeLog is prohibited * SubGhz: Fix displaying Nice FlorS in the Raed scene * SubGhz: Fix displaying Faac SLH in the Raed scene * SubGhz: Fix displaying iDo in the Raed scene * SubGhz: Fix displaying Star Line in the Raed scene * SubGhz: Fix displaying Nice Flo in the Raed scene, added save and load functions. (testing needed, no remote control) * SubGhz: subghz_beginadded common encoder upload signal * SubGhz: add Came encoder * SubGhz: modified pricenton encoder, fix view transmitter hide the "Send" button if there is no encoder * SubGhz: add nice flo encoder, need testing no remote control * SubGhz: add gate_tx encoder * SubGhz: add nero_sketch encoder * SubGhz: add keelog encoder * SubGhz: add long upload upload while the button is pressed while releasing the transfer is over, with a check for sticking (maximum 200 upload repetitions) * SubGhz: fix max upload * SubGhz: Fix structure subghz add encoder * SubGhz: add generating and sending a dynamic keelog key, refactoring the code * SubGhz: add notifications * SubGhz: add creating a new remote control (Pricenton, Nice Flo 12bit, Nice Flo 24bit, CAME 12bit, CAME 24bit, Gate TX, DoorHan) * SubGhz: Fix load file, fix scene start * Subghz: Fix show key * SubGhz: Fix subghz_cli * SubGhz: Fix furi-hal-subghz * Format sources * SubGhz: standard notification scheme, fix broken assert in DMA. * SubGhz: move level alignment logic to furi-hal-subghz, fix spelling, cleanup. Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-08-16 22:56:23 +03:00
// Notifications
furi_record_close(RECORD_NOTIFICATION);
SubGhz: read and save static remotes. Create new static and dynamic remotes. (#646) * SubGhz: the functions of saving loading KeeLog have been modified, saving KeeLog is prohibited * SubGhz: Fix displaying Nice FlorS in the Raed scene * SubGhz: Fix displaying Faac SLH in the Raed scene * SubGhz: Fix displaying iDo in the Raed scene * SubGhz: Fix displaying Star Line in the Raed scene * SubGhz: Fix displaying Nice Flo in the Raed scene, added save and load functions. (testing needed, no remote control) * SubGhz: subghz_beginadded common encoder upload signal * SubGhz: add Came encoder * SubGhz: modified pricenton encoder, fix view transmitter hide the "Send" button if there is no encoder * SubGhz: add nice flo encoder, need testing no remote control * SubGhz: add gate_tx encoder * SubGhz: add nero_sketch encoder * SubGhz: add keelog encoder * SubGhz: add long upload upload while the button is pressed while releasing the transfer is over, with a check for sticking (maximum 200 upload repetitions) * SubGhz: fix max upload * SubGhz: Fix structure subghz add encoder * SubGhz: add generating and sending a dynamic keelog key, refactoring the code * SubGhz: add notifications * SubGhz: add creating a new remote control (Pricenton, Nice Flo 12bit, Nice Flo 24bit, CAME 12bit, CAME 24bit, Gate TX, DoorHan) * SubGhz: Fix load file, fix scene start * Subghz: Fix show key * SubGhz: Fix subghz_cli * SubGhz: Fix furi-hal-subghz * Format sources * SubGhz: standard notification scheme, fix broken assert in DMA. * SubGhz: move level alignment logic to furi-hal-subghz, fix spelling, cleanup. Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-08-16 22:56:23 +03:00
subghz->notifications = NULL;
2022-06-01 16:07:53 +03:00
// Path strings
furi_string_free(subghz->file_path);
furi_string_free(subghz->file_path_tmp);
// The rest
free(subghz);
}
2021-08-12 17:42:56 +03:00
int32_t subghz_app(void* p) {
bool alloc_for_tx;
if(p && strlen(p)) {
alloc_for_tx = true;
} else {
alloc_for_tx = false;
}
SubGhz* subghz = subghz_alloc(alloc_for_tx);
if(alloc_for_tx) {
subghz->raw_send_only = true;
} else {
subghz->raw_send_only = false;
}
//Load database
bool load_database = subghz_environment_load_keystore(
subghz->txrx->environment, EXT_PATH("subghz/assets/keeloq_mfcodes"));
subghz_environment_load_keystore(
subghz->txrx->environment, EXT_PATH("subghz/assets/keeloq_mfcodes_user"));
2021-08-12 17:42:56 +03:00
// Check argument and run corresponding scene
if(p && strlen(p)) {
uint32_t rpc_ctx = 0;
if(sscanf(p, "RPC %lX", &rpc_ctx) == 1) {
subghz->rpc_ctx = (void*)rpc_ctx;
rpc_system_app_set_callback(subghz->rpc_ctx, subghz_rpc_command_callback, subghz);
rpc_system_app_send_started(subghz->rpc_ctx);
view_dispatcher_attach_to_gui(
subghz->view_dispatcher, subghz->gui, ViewDispatcherTypeDesktop);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneRpc);
} else {
view_dispatcher_attach_to_gui(
subghz->view_dispatcher, subghz->gui, ViewDispatcherTypeFullscreen);
if(subghz_key_load(subghz, p, true)) {
furi_string_set(subghz->file_path, (const char*)p);
if((!strcmp(subghz->txrx->decoder_result->protocol->name, "RAW"))) {
//Load Raw TX
subghz->txrx->rx_key_state = SubGhzRxKeyStateRAWLoad;
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReadRAW);
} else {
//Load transmitter TX
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneTransmitter);
}
} else {
//exit app
scene_manager_stop(subghz->scene_manager);
view_dispatcher_stop(subghz->view_dispatcher);
}
}
2021-08-12 17:42:56 +03:00
} else {
view_dispatcher_attach_to_gui(
subghz->view_dispatcher, subghz->gui, ViewDispatcherTypeFullscreen);
furi_string_set(subghz->file_path, SUBGHZ_APP_FOLDER);
if(load_database) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneStart);
} else {
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneShowError, SubGhzCustomEventManagerSet);
furi_string_set(
subghz->error_str,
"No SD card or\ndatabase found.\nSome app function\nmay be reduced.");
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError);
}
2021-08-12 17:42:56 +03:00
}
furi_hal_power_suppress_charge_enter();
view_dispatcher_run(subghz->view_dispatcher);
furi_hal_power_suppress_charge_exit();
subghz_free(subghz, alloc_for_tx);
return 0;
}