unleashed-firmware/applications/subghz/subghz.c

317 lines
10 KiB
C
Raw Normal View History

/* Abandon hope, all ye who enter here. */
#include "subghz_i.h"
#include <lib/toolbox/path.h>
const char* const subghz_frequencies_text[] = {
"315.00",
"433.08",
"433.42",
"433.92",
"434.42",
"868.35",
"915.00",
};
const uint32_t subghz_frequencies[] = {
/* 300 - 348 */
315000000,
/* 387 - 464 */
433075000, /* LPD433 first */
433420000,
433920000, /* LPD433 mid */
434420000,
/* 779 - 928 */
868350000,
915000000,
};
const uint32_t subghz_hopper_frequencies[] = {
315000000,
433920000,
868350000,
};
const uint32_t subghz_frequencies_count = sizeof(subghz_frequencies) / sizeof(uint32_t);
const uint32_t subghz_hopper_frequencies_count =
sizeof(subghz_hopper_frequencies) / sizeof(uint32_t);
const uint32_t subghz_frequencies_433_92 = 3;
2021-08-12 14:42:56 +00:00
bool subghz_custom_event_callback(void* context, uint32_t event) {
furi_assert(context);
SubGhz* subghz = context;
2021-08-12 14:42:56 +00:00
return scene_manager_handle_custom_event(subghz->scene_manager, event);
}
2021-08-12 14:42:56 +00: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 14:42:56 +00:00
void subghz_tick_event_callback(void* context) {
furi_assert(context);
SubGhz* subghz = context;
scene_manager_handle_tick_event(subghz->scene_manager);
}
SubGhz* subghz_alloc() {
[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 19:53:46 +00:00
SubGhz* subghz = malloc(sizeof(SubGhz));
// GUI
subghz->gui = furi_record_open("gui");
// View Dispatcher
subghz->view_dispatcher = view_dispatcher_alloc();
view_dispatcher_enable_queue(subghz->view_dispatcher);
view_dispatcher_attach_to_gui(
subghz->view_dispatcher, subghz->gui, ViewDispatcherTypeFullscreen);
2021-08-12 14:42:56 +00: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 19:56:23 +00:00
// Open Notification record
subghz->notifications = furi_record_open("notification");
2021-08-12 14:42:56 +00:00
// SubMenu
subghz->submenu = submenu_alloc();
2021-08-12 14:42:56 +00:00
view_dispatcher_add_view(
subghz->view_dispatcher, SubGhzViewMenu, submenu_get_view(subghz->submenu));
// Receiver
subghz->subghz_receiver = subghz_receiver_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher,
2021-08-12 14:42:56 +00:00
SubGhzViewReceiver,
subghz_receiver_get_view(subghz->subghz_receiver));
2021-08-12 14:42:56 +00:00
// Popup
subghz->popup = popup_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher, SubGhzViewPopup, popup_get_view(subghz->popup));
// Text Input
subghz->text_input = text_input_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher, SubGhzViewTextInput, text_input_get_view(subghz->text_input));
// Custom Widget
subghz->widget = widget_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher, SubGhzViewWidget, widget_get_view(subghz->widget));
//Dialog
subghz->dialogs = furi_record_open("dialogs");
2021-08-12 14:42:56 +00:00
// Transmitter
subghz->subghz_transmitter = subghz_transmitter_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher,
2021-08-12 14:42:56 +00:00
SubGhzViewTransmitter,
subghz_transmitter_get_view(subghz->subghz_transmitter));
// Variable Item List
subghz->variable_item_list = variable_item_list_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher,
SubGhzViewVariableItemList,
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,
SubGhzViewFrequencyAnalyzer,
subghz_frequency_analyzer_get_view(subghz->subghz_frequency_analyzer));
// Read RAW
subghz->subghz_read_raw = subghz_read_raw_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher,
SubGhzViewReadRAW,
subghz_read_raw_get_view(subghz->subghz_read_raw));
2021-08-12 14:42:56 +00:00
// Carrier Test Module
subghz->subghz_test_carrier = subghz_test_carrier_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher,
SubGhzViewTestCarrier,
subghz_test_carrier_get_view(subghz->subghz_test_carrier));
// Packet Test
subghz->subghz_test_packet = subghz_test_packet_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher,
SubGhzViewTestPacket,
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,
SubGhzViewStatic,
subghz_test_static_get_view(subghz->subghz_test_static));
//init Worker & Protocol & History
[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 19:53:46 +00:00
subghz->txrx = malloc(sizeof(SubGhzTxRx));
subghz->txrx->frequency = subghz_frequencies[subghz_frequencies_433_92];
subghz->txrx->preset = FuriHalSubGhzPresetOok650Async;
subghz->txrx->txrx_state = SubGhzTxRxStateSleep;
subghz->txrx->hopper_state = SubGhzHopperStateOFF;
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
subghz->txrx->history = subghz_history_alloc();
subghz->txrx->worker = subghz_worker_alloc();
subghz->txrx->parser = subghz_parser_alloc();
2021-08-12 14:42:56 +00:00
subghz_worker_set_overrun_callback(
subghz->txrx->worker, (SubGhzWorkerOverrunCallback)subghz_parser_reset);
2021-08-12 14:42:56 +00:00
subghz_worker_set_pair_callback(
subghz->txrx->worker, (SubGhzWorkerPairCallback)subghz_parser_parse);
subghz_worker_set_context(subghz->txrx->worker, subghz->txrx->parser);
2021-08-12 14:42:56 +00:00
//Init Error_str
string_init(subghz->error_str);
return subghz;
}
void subghz_free(SubGhz* subghz) {
furi_assert(subghz);
// Packet Test
2021-08-12 14:42:56 +00:00
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewTestPacket);
subghz_test_packet_free(subghz->subghz_test_packet);
// Carrier Test
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewTestCarrier);
subghz_test_carrier_free(subghz->subghz_test_carrier);
// Static
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewStatic);
subghz_test_static_free(subghz->subghz_test_static);
2021-08-12 14:42:56 +00:00
// Receiver
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewReceiver);
subghz_receiver_free(subghz->subghz_receiver);
// TextInput
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewTextInput);
text_input_free(subghz->text_input);
// Custom Widget
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewWidget);
widget_free(subghz->widget);
//Dialog
furi_record_close("dialogs");
// Transmitter
2021-08-12 14:42:56 +00:00
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewTransmitter);
subghz_transmitter_free(subghz->subghz_transmitter);
// Variable Item List
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewVariableItemList);
variable_item_list_free(subghz->variable_item_list);
// Frequency Analyzer
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewFrequencyAnalyzer);
subghz_frequency_analyzer_free(subghz->subghz_frequency_analyzer);
// Read RAW
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewReadRAW);
subghz_read_raw_free(subghz->subghz_read_raw);
// Submenu
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewMenu);
submenu_free(subghz->submenu);
2021-08-12 14:42:56 +00:00
// Popup
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewPopup);
popup_free(subghz->popup);
// Scene manager
scene_manager_free(subghz->scene_manager);
// View Dispatcher
view_dispatcher_free(subghz->view_dispatcher);
// GUI
furi_record_close("gui");
subghz->gui = NULL;
//Worker & Protocol & History
subghz_parser_free(subghz->txrx->parser);
subghz_worker_free(subghz->txrx->worker);
subghz_history_free(subghz->txrx->history);
free(subghz->txrx);
//Error string
string_clear(subghz->error_str);
2021-08-12 14:42:56 +00: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 19:56:23 +00:00
// Notifications
furi_record_close("notification");
subghz->notifications = NULL;
// The rest
free(subghz);
}
2021-08-12 14:42:56 +00:00
int32_t subghz_app(void* p) {
SubGhz* subghz = subghz_alloc();
//Load database
bool load_database =
subghz_parser_load_keeloq_file(subghz->txrx->parser, "/ext/subghz/assets/keeloq_mfcodes");
subghz_parser_load_keeloq_file(subghz->txrx->parser, "/ext/subghz/assets/keeloq_mfcodes_user");
subghz_parser_load_nice_flor_s_file(subghz->txrx->parser, "/ext/subghz/assets/nice_flor_s_rx");
subghz_parser_load_came_atomo_file(subghz->txrx->parser, "/ext/subghz/assets/came_atomo");
2021-08-12 14:42:56 +00:00
// Check argument and run corresponding scene
if(p && subghz_key_load(subghz, p)) {
string_t filename;
2021-11-12 15:45:51 +00:00
string_init(filename);
path_extract_filename_no_ext(p, filename);
strcpy(subghz->file_name, string_get_cstr(filename));
string_clear(filename);
if((!strcmp(subghz->txrx->protocol_result->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);
}
2021-08-12 14:42:56 +00:00
} else {
if(load_database) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneStart);
} else {
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneShowError, SubghzCustomEventManagerSet);
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 14:42:56 +00:00
}
furi_hal_power_suppress_charge_enter();
view_dispatcher_run(subghz->view_dispatcher);
furi_hal_power_suppress_charge_exit();
subghz_free(subghz);
return 0;
}