[FL-1610] SubGhz: scene based application, PT save and replay (#630)

* SubGhz: scene based application
* SubGhz: encoder/decoder separation, DMA streaming, update app and cli.
* SubGhz: 2 stage async tx complete, minor cleanup
* SubGhz: 2 stage async tx complete, FIX state pin end transmit
* SubGhz: Pricenton, receive TE signal
* SubGhz: Pricenton, add save data, add load data
* SubGhz: Add Read scene, Fix pricenton save, load funtion
* SubGhz: Add Read, Receiver, SaveName scene
* SubGhz: Read and Save (pricenton)
* SubGhz: add Load scence
* SubGhz: Fix select file scene, add load scene, add transmitter view, add send tx pricenton
* SubGhz: Fix pricenton encoder, fix transmitter send
* SubGhz: modified Pricenton Encoder (added guard time at the beginning), modified CC1101 config, code refactoring
* SubGhz: Fix pricenton encoder defalut TE
* Archive: Fix path and name SubGhz
* Archive: Fix name app SubGhz
* GubGhz: Came: add Save, Load key
* GubGhz: GateTX: add Save, Load key
* GubGhz: NeroSketch: add Save, Load key
* Github: better linters triggers
* SubGhz: adding fast loading keys Archive -> Run in app
* GubGhz: KeeLog: add Save, Load key, key generation from the serial number of the meter and the button
* SubGhz: format sources and fix compilation
* FuriHal: add subghz configuration description for AGC section
* SubGhz: save only protocols that can be saved. Cleanup.
* Github: lint on pull requests

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
Skorpionm
2021-08-12 18:42:56 +04:00
committed by GitHub
parent 37d7870e52
commit 1cfa857f98
51 changed files with 2466 additions and 671 deletions

View File

@@ -35,7 +35,7 @@ static const char* flipper_app_name[] = {
static const char* known_ext[] = {
[ArchiveFileTypeIButton] = ".ibtn",
[ArchiveFileTypeNFC] = ".nfc",
[ArchiveFileTypeSubOne] = ".sub1",
[ArchiveFileTypeSubOne] = ".sub",
[ArchiveFileTypeLFRFID] = ".rfid",
[ArchiveFileTypeIrda] = ".ir",
};
@@ -44,7 +44,7 @@ static const char* tab_default_paths[] = {
[ArchiveTabFavorites] = "/any/favorites",
[ArchiveTabIButton] = "/any/ibutton",
[ArchiveTabNFC] = "/any/nfc",
[ArchiveTabSubOne] = "/any/subone",
[ArchiveTabSubOne] = "/any/subghz/saved",
[ArchiveTabLFRFID] = "/any/lfrfid",
[ArchiveTabIrda] = "/any/irda",
[ArchiveTabBrowser] = "/any",

View File

@@ -4,7 +4,7 @@ static const char* ArchiveTabNames[] = {
[ArchiveTabFavorites] = "Favorites",
[ArchiveTabIButton] = "iButton",
[ArchiveTabNFC] = "NFC",
[ArchiveTabSubOne] = "SubOne",
[ArchiveTabSubOne] = "SubGhz",
[ArchiveTabLFRFID] = "RFID LF",
[ArchiveTabIrda] = "Infrared",
[ArchiveTabBrowser] = "Browser"};

View File

@@ -0,0 +1,30 @@
#include "subghz_scene.h"
// Generate scene on_enter handlers array
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
void (*const subghz_on_enter_handlers[])(void*) = {
#include "subghz_scene_config.h"
};
#undef ADD_SCENE
// Generate scene on_event handlers array
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
bool (*const subghz_on_event_handlers[])(void* context, SceneManagerEvent event) = {
#include "subghz_scene_config.h"
};
#undef ADD_SCENE
// Generate scene on_exit handlers array
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
void (*const subghz_on_exit_handlers[])(void* context) = {
#include "subghz_scene_config.h"
};
#undef ADD_SCENE
// Initialize scene handlers configuration structure
const SceneManagerHandlers subghz_scene_handlers = {
.on_enter_handlers = subghz_on_enter_handlers,
.on_event_handlers = subghz_on_event_handlers,
.on_exit_handlers = subghz_on_exit_handlers,
.scene_num = SubGhzSceneNum,
};

View File

@@ -0,0 +1,29 @@
#pragma once
#include <gui/scene_manager.h>
// Generate scene id and total number
#define ADD_SCENE(prefix, name, id) SubGhzScene##id,
typedef enum {
#include "subghz_scene_config.h"
SubGhzSceneNum,
} SubGhzScene;
#undef ADD_SCENE
extern const SceneManagerHandlers subghz_scene_handlers;
// Generate scene on_enter handlers declaration
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
#include "subghz_scene_config.h"
#undef ADD_SCENE
// Generate scene on_event handlers declaration
#define ADD_SCENE(prefix, name, id) \
bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event);
#include "subghz_scene_config.h"
#undef ADD_SCENE
// Generate scene on_exit handlers declaration
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
#include "subghz_scene_config.h"
#undef ADD_SCENE

View File

@@ -0,0 +1,15 @@
#include "../subghz_i.h"
const void subghz_scene_analyze_on_enter(void* context) {
SubGhz* subghz = context;
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewAnalyze);
}
const bool subghz_scene_analyze_on_event(void* context, SceneManagerEvent event) {
// SubGhz* subghz = context;
return false;
}
const void subghz_scene_analyze_on_exit(void* context) {
// SubGhz* subghz = context;
}

View File

@@ -0,0 +1,12 @@
ADD_SCENE(subghz, start, Start)
ADD_SCENE(subghz, analyze, Analyze)
ADD_SCENE(subghz, read, Read)
ADD_SCENE(subghz, receiver, Receiver)
ADD_SCENE(subghz, save_name, SaveName)
ADD_SCENE(subghz, save_success, SaveSuccess)
ADD_SCENE(subghz, saved, Saved)
ADD_SCENE(subghz, transmitter, Transmitter)
ADD_SCENE(subghz, static, Static)
ADD_SCENE(subghz, test, Test)
ADD_SCENE(subghz, test_carrier, TestCarrier)
ADD_SCENE(subghz, test_packet, TestPacket)

View File

@@ -0,0 +1,57 @@
#include "../subghz_i.h"
#define GUBGHZ_READ_CUSTOM_EVENT (10UL)
void subghz_read_protocol_callback(SubGhzProtocolCommon* parser, void* context) {
furi_assert(context);
SubGhz* subghz = context;
subghz->protocol_result = parser;
view_dispatcher_send_custom_event(subghz->view_dispatcher, GUBGHZ_READ_CUSTOM_EVENT);
}
void subghz_scene_read_callback(DialogExResult result, void* context) {
SubGhz* subghz = context;
view_dispatcher_send_custom_event(subghz->view_dispatcher, result);
}
const void subghz_scene_read_on_enter(void* context) {
SubGhz* subghz = context;
// Setup view
DialogEx* dialog_ex = subghz->dialog_ex;
dialog_ex_set_header(dialog_ex, "SubGhz 433.92", 36, 6, AlignLeft, AlignCenter);
dialog_ex_set_icon(dialog_ex, 10, 12, &I_RFIDDolphinReceive_97x61);
//Start CC1101 rx
subghz_begin(FuriHalSubGhzPresetOokAsync);
subghz_rx(433920000);
furi_hal_subghz_start_async_rx(subghz_worker_rx_callback, subghz->worker);
subghz_worker_start(subghz->worker);
subghz_protocol_enable_dump(subghz->protocol, subghz_read_protocol_callback, subghz);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewDialogEx);
}
const bool subghz_scene_read_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == GUBGHZ_READ_CUSTOM_EVENT) {
scene_manager_next_scene(subghz->scene_manager, SubGhzViewReceiver);
return true;
}
}
return false;
}
const void subghz_scene_read_on_exit(void* context) {
SubGhz* subghz = context;
//Stop CC1101
subghz_worker_stop(subghz->worker);
furi_hal_subghz_stop_async_rx();
subghz_end();
DialogEx* dialog_ex = subghz->dialog_ex;
dialog_ex_set_header(dialog_ex, NULL, 0, 0, AlignCenter, AlignCenter);
dialog_ex_set_icon(dialog_ex, 0, 0, NULL);
}

View File

@@ -0,0 +1,37 @@
#include "../subghz_i.h"
#include "../views/subghz_receiver.h"
void subghz_scene_receiver_callback(SubghzReceverEvent event, void* context) {
furi_assert(context);
SubGhz* subghz = context;
view_dispatcher_send_custom_event(subghz->view_dispatcher, event);
}
const void subghz_scene_receiver_on_enter(void* context) {
SubGhz* subghz = context;
SubghzReceiver* subghz_receiver = subghz->subghz_receiver;
subghz_receiver_set_callback(subghz_receiver, subghz_scene_receiver_callback, subghz);
subghz_receiver_set_protocol(subghz_receiver, subghz->protocol_result);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewReceiver);
}
const bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubghzReceverEventSave) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName);
return true;
} else if(event.event == SubghzReceverEventBack) {
scene_manager_previous_scene(subghz->scene_manager);
return true;
}
}
return false;
}
const void subghz_scene_receiver_on_exit(void* context) {
// SubGhz* subghz = context;
}

View File

@@ -0,0 +1,102 @@
#include "../subghz_i.h"
#include <lib/toolbox/random_name.h>
#include "file-worker.h"
#define SCENE_SAVE_NAME_CUSTOM_EVENT (0UL)
bool subghz_scene_save_data_to_file(void* context, const char* dev_name) {
SubGhz* subghz = context;
FileWorker* file_worker = file_worker_alloc(false);
string_t dev_file_name;
string_init(dev_file_name);
string_t temp_str;
string_init(temp_str);
bool saved = false;
do {
// Create subghz folder directory if necessary
if(!file_worker_mkdir(file_worker, SUBGHZ_APP_FOLDER)) {
break;
}
// Create saved directory if necessary
if(!file_worker_mkdir(file_worker, SUBGHZ_APP_PATH_FOLDER)) {
break;
}
// First remove subghz device file if it was saved
string_printf(
dev_file_name, "%s/%s%s", SUBGHZ_APP_PATH_FOLDER, dev_name, SUBGHZ_APP_EXTENSION);
if(!file_worker_remove(file_worker, string_get_cstr(dev_file_name))) {
break;
}
// Open file
if(!file_worker_open(
file_worker, string_get_cstr(dev_file_name), FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
break;
}
//Get string save
subghz->protocol_result->to_save_string(subghz->protocol_result, temp_str);
// Prepare and write data to file
if(!file_worker_write(file_worker, string_get_cstr(temp_str), string_size(temp_str))) {
break;
}
saved = true;
} while(0);
string_clear(temp_str);
string_clear(dev_file_name);
file_worker_close(file_worker);
file_worker_free(file_worker);
return saved;
}
void subghz_scene_save_name_text_input_callback(void* context) {
SubGhz* subghz = context;
view_dispatcher_send_custom_event(subghz->view_dispatcher, SCENE_SAVE_NAME_CUSTOM_EVENT);
}
const void subghz_scene_save_name_on_enter(void* context) {
SubGhz* subghz = context;
// Setup view
TextInput* text_input = subghz->text_input;
bool dev_name_empty = false;
set_random_name(subghz->text_store, sizeof(subghz->text_store));
dev_name_empty = true;
text_input_set_header_text(text_input, "Name the KEY");
text_input_set_result_callback(
text_input,
subghz_scene_save_name_text_input_callback,
subghz,
subghz->text_store,
22, //Max len name
dev_name_empty);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewTextInput);
}
const bool subghz_scene_save_name_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SCENE_SAVE_NAME_CUSTOM_EVENT) {
if(subghz_scene_save_data_to_file(subghz, subghz->text_store)) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveSuccess);
return true;
} else {
//Error save
return true;
}
}
}
return false;
}
const void subghz_scene_save_name_on_exit(void* context) {
SubGhz* subghz = context;
// Clear view
text_input_set_header_text(subghz->text_input, NULL);
text_input_set_result_callback(subghz->text_input, NULL, NULL, NULL, 0, false);
}

View File

@@ -0,0 +1,47 @@
#include "../subghz_i.h"
#define SCENE_SAVE_SUCCESS_CUSTOM_EVENT (0UL)
void subghz_scene_save_success_popup_callback(void* context) {
SubGhz* subghz = context;
view_dispatcher_send_custom_event(subghz->view_dispatcher, SCENE_SAVE_SUCCESS_CUSTOM_EVENT);
}
const void subghz_scene_save_success_on_enter(void* context) {
SubGhz* subghz = context;
// Setup view
Popup* popup = subghz->popup;
popup_set_icon(popup, 32, 5, &I_DolphinNice_96x59);
popup_set_header(popup, "Saved!", 13, 22, AlignLeft, AlignBottom);
popup_set_timeout(popup, 1500);
popup_set_context(popup, subghz);
popup_set_callback(popup, subghz_scene_save_success_popup_callback);
popup_enable_timeout(popup);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewPopup);
}
const bool subghz_scene_save_success_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SCENE_SAVE_SUCCESS_CUSTOM_EVENT) {
return scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneStart);
}
}
return false;
}
const void subghz_scene_save_success_on_exit(void* context) {
SubGhz* subghz = context;
// Clear view
Popup* popup = subghz->popup;
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
popup_set_icon(popup, 0, 0, NULL);
popup_set_callback(popup, NULL);
popup_set_context(popup, NULL);
popup_set_timeout(popup, 0);
popup_disable_timeout(popup);
}

View File

@@ -0,0 +1,88 @@
#include "../subghz_i.h"
bool subghz_scene_saved_file_select(SubGhz* subghz) {
furi_assert(subghz);
FileWorker* file_worker = file_worker_alloc(false);
string_t protocol_file_name;
string_init(protocol_file_name);
string_t temp_str;
string_init(temp_str);
// Input events and views are managed by file_select
bool res = file_worker_file_select(
file_worker,
SUBGHZ_APP_PATH_FOLDER,
SUBGHZ_APP_EXTENSION,
subghz->text_store,
sizeof(subghz->text_store),
NULL);
if(res) {
// Get key file path
string_printf(
protocol_file_name,
"%s/%s%s",
SUBGHZ_APP_PATH_FOLDER,
subghz->text_store,
SUBGHZ_APP_EXTENSION);
} else {
string_clear(temp_str);
string_clear(protocol_file_name);
file_worker_close(file_worker);
file_worker_free(file_worker);
return res;
}
do {
if(!file_worker_open(
file_worker, string_get_cstr(protocol_file_name), FSAM_READ, FSOM_OPEN_EXISTING)) {
break;
}
// Read and parse name protocol from 1st line
if(!file_worker_read_until(file_worker, temp_str, '\n')) {
break;
}
// strlen("Protocol: ") = 10
string_right(temp_str, 10);
subghz->protocol_result =
subghz_protocol_get_by_name(subghz->protocol, string_get_cstr(temp_str));
if(subghz->protocol_result == NULL) {
file_worker_show_error(file_worker, "Cannot parse\nfile");
break;
}
if(!subghz->protocol_result->to_load_protocol(file_worker, subghz->protocol_result)) {
file_worker_show_error(file_worker, "Cannot parse\nfile");
break;
}
res = true;
} while(0);
string_clear(temp_str);
string_clear(protocol_file_name);
file_worker_close(file_worker);
file_worker_free(file_worker);
return res;
}
const void subghz_scene_saved_on_enter(void* context) {
SubGhz* subghz = context;
if(subghz_scene_saved_file_select(subghz)) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneTransmitter);
} else {
scene_manager_search_and_switch_to_previous_scene(subghz->scene_manager, SubGhzSceneStart);
}
}
const bool subghz_scene_saved_on_event(void* context, SceneManagerEvent event) {
// SubGhz* subghz = context;
return false;
}
const void subghz_scene_saved_on_exit(void* context) {
// SubGhz* subghz = context;
}

View File

@@ -0,0 +1,77 @@
#include "../subghz_i.h"
enum SubmenuIndex {
SubmenuIndexAnalyze,
SubmenuIndexRead,
SubmenuIndexSaved,
SubmenuIndexStatic,
SubmenuIndexTest,
};
void subghz_scene_start_submenu_callback(void* context, uint32_t index) {
SubGhz* subghz = context;
view_dispatcher_send_custom_event(subghz->view_dispatcher, index);
}
const void subghz_scene_start_on_enter(void* context) {
SubGhz* subghz = context;
submenu_add_item(
subghz->submenu,
"Analyze",
SubmenuIndexAnalyze,
subghz_scene_start_submenu_callback,
subghz);
submenu_add_item(
subghz->submenu, "Read", SubmenuIndexRead, subghz_scene_start_submenu_callback, subghz);
submenu_add_item(
subghz->submenu, "Saved", SubmenuIndexSaved, subghz_scene_start_submenu_callback, subghz);
submenu_add_item(
subghz->submenu, "Static", SubmenuIndexStatic, subghz_scene_start_submenu_callback, subghz);
submenu_add_item(
subghz->submenu, "Test", SubmenuIndexTest, subghz_scene_start_submenu_callback, subghz);
submenu_set_selected_item(
subghz->submenu, scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneStart));
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewMenu);
}
const bool subghz_scene_start_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubmenuIndexAnalyze) {
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexAnalyze);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneAnalyze);
return true;
} else if(event.event == SubmenuIndexRead) {
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexRead);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneRead);
return true;
} else if(event.event == SubmenuIndexSaved) {
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexSaved);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaved);
return true;
} else if(event.event == SubmenuIndexStatic) {
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexStatic);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneStatic);
return true;
} else if(event.event == SubmenuIndexTest) {
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexTest);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneTest);
return true;
}
}
return false;
}
const void subghz_scene_start_on_exit(void* context) {
SubGhz* subghz = context;
submenu_clean(subghz->submenu);
}

View File

@@ -0,0 +1,15 @@
#include "../subghz_i.h"
const void subghz_scene_static_on_enter(void* context) {
SubGhz* subghz = context;
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewStatic);
}
const bool subghz_scene_static_on_event(void* context, SceneManagerEvent event) {
// SubGhz* subghz = context;
return false;
}
const void subghz_scene_static_on_exit(void* context) {
// SubGhz* subghz = context;
}

View File

@@ -0,0 +1,53 @@
#include "../subghz_i.h"
enum SubmenuIndex {
SubmenuIndexCarrier,
SubmenuIndexPacket,
};
void subghz_scene_test_submenu_callback(void* context, uint32_t index) {
SubGhz* subghz = context;
view_dispatcher_send_custom_event(subghz->view_dispatcher, index);
}
const void subghz_scene_test_on_enter(void* context) {
SubGhz* subghz = context;
submenu_add_item(
subghz->submenu,
"Carrier",
SubmenuIndexCarrier,
subghz_scene_test_submenu_callback,
subghz);
submenu_add_item(
subghz->submenu, "Packet", SubmenuIndexPacket, subghz_scene_test_submenu_callback, subghz);
submenu_set_selected_item(
subghz->submenu, scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneTest));
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewMenu);
}
const bool subghz_scene_test_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubmenuIndexCarrier) {
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneTest, SubmenuIndexCarrier);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneTestCarrier);
return true;
} else if(event.event == SubmenuIndexPacket) {
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneTest, SubmenuIndexPacket);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneTestPacket);
return true;
}
}
return false;
}
const void subghz_scene_test_on_exit(void* context) {
SubGhz* subghz = context;
submenu_clean(subghz->submenu);
}

View File

@@ -0,0 +1,15 @@
#include "../subghz_i.h"
const void subghz_scene_test_carrier_on_enter(void* context) {
SubGhz* subghz = context;
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewTestCarrier);
}
const bool subghz_scene_test_carrier_on_event(void* context, SceneManagerEvent event) {
// SubGhz* subghz = context;
return false;
}
const void subghz_scene_test_carrier_on_exit(void* context) {
// SubGhz* subghz = context;
}

View File

@@ -0,0 +1,15 @@
#include "../subghz_i.h"
const void subghz_scene_test_packet_on_enter(void* context) {
SubGhz* subghz = context;
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewTestPacket);
}
const bool subghz_scene_test_packet_on_event(void* context, SceneManagerEvent event) {
// SubGhz* subghz = context;
return false;
}
const void subghz_scene_test_packet_on_exit(void* context) {
// SubGhz* subghz = context;
}

View File

@@ -0,0 +1,65 @@
#include "../subghz_i.h"
#include "../views/subghz_transmitter.h"
#include "lib/subghz/protocols/subghz_protocol_princeton.h"
void subghz_scene_transmitter_tx(void* context) {
SubGhz* subghz = context;
SubGhzEncoderPrinceton* encoder = subghz_encoder_princeton_alloc();
subghz_encoder_princeton_reset(encoder, subghz->protocol_result->code_last_found, 4);
subghz_encoder_princeton_set_te(encoder, subghz->protocol_result);
subghz_begin(FuriHalSubGhzPresetOokAsync);
subghz_tx(433920000);
furi_hal_subghz_start_async_tx(subghz_encoder_princeton_yield, encoder);
while(!furi_hal_subghz_is_async_tx_complete()) {
osDelay(20);
}
//Stop tx
furi_hal_subghz_stop_async_tx();
subghz_end();
subghz_encoder_princeton_free(encoder);
}
void subghz_scene_transmitter_callback(SubghzTransmitterEvent event, void* context) {
furi_assert(context);
SubGhz* subghz = context;
view_dispatcher_send_custom_event(subghz->view_dispatcher, event);
}
const void subghz_scene_transmitter_on_enter(void* context) {
SubGhz* subghz = context;
SubghzTransmitter* subghz_transmitter = subghz->subghz_transmitter;
subghz_transmitter_set_callback(subghz_transmitter, subghz_scene_transmitter_callback, subghz);
subghz_transmitter_set_protocol(subghz_transmitter, subghz->protocol_result);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewTransmitter);
}
const bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubghzTransmitterEventSend) {
//scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName);
subghz_scene_transmitter_tx(subghz);
return true;
} else if(event.event == SubghzTransmitterEventBack) {
scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneStart);
return true;
}
}
return false;
}
const void subghz_scene_transmitter_on_exit(void* context) {
SubGhz* subghz = context;
SubghzTransmitter* subghz_transmitter = subghz->subghz_transmitter;
subghz_transmitter_set_callback(subghz_transmitter, NULL, subghz);
}

View File

@@ -23,15 +23,22 @@ const uint32_t subghz_frequencies[] = {
const uint32_t subghz_frequencies_count = sizeof(subghz_frequencies) / sizeof(uint32_t);
const uint32_t subghz_frequencies_433_92 = 5;
void subghz_menu_callback(void* context, uint32_t index) {
bool subghz_custom_event_callback(void* context, uint32_t event) {
furi_assert(context);
SubGhz* subghz = context;
view_dispatcher_switch_to_view(subghz->view_dispatcher, index);
return scene_manager_handle_custom_event(subghz->scene_manager, event);
}
uint32_t subghz_exit(void* context) {
return VIEW_NONE;
bool subghz_back_event_callback(void* context) {
furi_assert(context);
SubGhz* subghz = context;
return scene_manager_handle_back_event(subghz->scene_manager);
}
void subghz_tick_event_callback(void* context) {
furi_assert(context);
SubGhz* subghz = context;
scene_manager_handle_tick_event(subghz->scene_manager);
}
SubGhz* subghz_alloc() {
@@ -46,33 +53,62 @@ SubGhz* subghz_alloc() {
view_dispatcher_attach_to_gui(
subghz->view_dispatcher, subghz->gui, ViewDispatcherTypeFullscreen);
// Menu
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);
// SubMenu
subghz->submenu = submenu_alloc();
submenu_add_item(subghz->submenu, "Capture", SubGhzViewCapture, subghz_menu_callback, subghz);
submenu_add_item(
subghz->submenu, "Basic Test", SubGhzViewTestBasic, subghz_menu_callback, subghz);
submenu_add_item(
subghz->submenu, "Packet Test", SubGhzViewTestPacket, subghz_menu_callback, subghz);
submenu_add_item(
subghz->submenu, "Static Code", SubGhzViewStatic, subghz_menu_callback, subghz);
view_dispatcher_add_view(
subghz->view_dispatcher, SubGhzViewMenu, submenu_get_view(subghz->submenu));
View* submenu_view = submenu_get_view(subghz->submenu);
view_set_previous_callback(submenu_view, subghz_exit);
view_dispatcher_add_view(subghz->view_dispatcher, SubGhzViewMenu, submenu_view);
// Capture
subghz->subghz_capture = subghz_capture_alloc();
// Analyze
subghz->subghz_analyze = subghz_analyze_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher,
SubGhzViewCapture,
subghz_capture_get_view(subghz->subghz_capture));
SubGhzViewAnalyze,
subghz_analyze_get_view(subghz->subghz_analyze));
// Basic Test Module
subghz->subghz_test_basic = subghz_test_basic_alloc();
// Receiver
subghz->subghz_receiver = subghz_receiver_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher,
SubGhzViewTestBasic,
subghz_test_basic_get_view(subghz->subghz_test_basic));
SubGhzViewReceiver,
subghz_receiver_get_view(subghz->subghz_receiver));
// Dialog
subghz->dialog_ex = dialog_ex_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher, SubGhzViewDialogEx, dialog_ex_get_view(subghz->dialog_ex));
// 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));
// Transmitter
subghz->subghz_transmitter = subghz_transmitter_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher,
SubGhzViewTransmitter,
subghz_transmitter_get_view(subghz->subghz_transmitter));
// 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();
@@ -86,8 +122,19 @@ SubGhz* subghz_alloc() {
view_dispatcher_add_view(
subghz->view_dispatcher, SubGhzViewStatic, subghz_static_get_view(subghz->subghz_static));
// Switch to menu
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewMenu);
//init Worker & Protocol
subghz->worker = subghz_worker_alloc();
subghz->protocol = subghz_protocol_alloc();
subghz_worker_set_overrun_callback(
subghz->worker, (SubGhzWorkerOverrunCallback)subghz_protocol_reset);
subghz_worker_set_pair_callback(
subghz->worker, (SubGhzWorkerPairCallback)subghz_protocol_parse);
subghz_worker_set_context(subghz->worker, subghz->protocol);
subghz_protocol_load_keeloq_file(subghz->protocol, "/ext/assets/subghz/keeloq_mfcodes");
subghz_protocol_load_nice_flor_s_file(subghz->protocol, "/ext/assets/subghz/nice_floor_s_rx");
//subghz_protocol_enable_dump_text(subghz->protocol, subghz_text_callback, subghz);
return subghz;
}
@@ -95,25 +142,48 @@ SubGhz* subghz_alloc() {
void subghz_free(SubGhz* subghz) {
furi_assert(subghz);
// Packet Test
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewStatic);
subghz_static_free(subghz->subghz_static);
// Packet Test
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewTestPacket);
subghz_test_packet_free(subghz->subghz_test_packet);
// Basic Test
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewTestBasic);
subghz_test_basic_free(subghz->subghz_test_basic);
// 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_static_free(subghz->subghz_static);
// Analyze
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewAnalyze);
subghz_analyze_free(subghz->subghz_analyze);
// 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);
// Receiver
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewTransmitter);
subghz_transmitter_free(subghz->subghz_transmitter);
// Submenu
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewMenu);
submenu_free(subghz->submenu);
// Capture
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewCapture);
subghz_capture_free(subghz->subghz_capture);
// DialogEx
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewDialogEx);
dialog_ex_free(subghz->dialog_ex);
// 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);
@@ -122,13 +192,24 @@ void subghz_free(SubGhz* subghz) {
furi_record_close("gui");
subghz->gui = NULL;
//Worker & Protocol
subghz_protocol_free(subghz->protocol);
subghz_worker_free(subghz->worker);
// The rest
free(subghz);
}
int32_t subghz_app(void* context) {
int32_t subghz_app(void* p) {
SubGhz* subghz = subghz_alloc();
// Check argument and run corresponding scene
if(p && subghz_key_load(subghz, p)) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneTransmitter);
} else {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneStart);
}
view_dispatcher_run(subghz->view_dispatcher);
subghz_free(subghz);

View File

@@ -4,6 +4,7 @@
#include <furi-hal.h>
#include <stream_buffer.h>
#include <lib/subghz/protocols/subghz_protocol.h>
#include <lib/subghz/protocols/subghz_protocol_princeton.h>
#define SUBGHZ_FREQUENCY_RANGE_STR \
"299999755...348000000 or 386999938...464000000 or 778999847...928000000"
@@ -94,14 +95,10 @@ void subghz_cli_command_rx_carrier(Cli* cli, string_t args, void* context) {
furi_hal_subghz_sleep();
}
#define SUBGHZ_PT_SHORT 376
#define SUBGHZ_PT_LONG (SUBGHZ_PT_SHORT * 3)
#define SUBGHZ_PT_GUARD 10600
void subghz_cli_command_tx(Cli* cli, string_t args, void* context) {
uint32_t frequency = 433920000;
size_t repeat = 10;
uint32_t key = 0x0074BADE;
size_t repeat = 10;
if(string_size(args)) {
int ret = sscanf(string_get_cstr(args), "%lx %lu %u", &key, &frequency, &repeat);
@@ -126,41 +123,31 @@ void subghz_cli_command_tx(Cli* cli, string_t args, void* context) {
}
}
size_t subghz_test_data_size = 25 * 2 * sizeof(uint32_t);
uint32_t* subghz_test_data = furi_alloc(subghz_test_data_size);
size_t pos = 0;
for(uint8_t i = 0; i < 24; i++) {
uint8_t byte = i / 8;
uint8_t bit = i % 8;
bool value = (((uint8_t*)&key)[2 - byte] >> (7 - bit)) & 1;
if(value) {
subghz_test_data[pos++] = SUBGHZ_PT_SHORT;
subghz_test_data[pos++] = SUBGHZ_PT_LONG;
} else {
subghz_test_data[pos++] = SUBGHZ_PT_LONG;
subghz_test_data[pos++] = SUBGHZ_PT_SHORT;
}
}
subghz_test_data[pos++] = SUBGHZ_PT_SHORT;
subghz_test_data[pos++] = SUBGHZ_PT_SHORT + SUBGHZ_PT_GUARD;
printf(
"Transmitting at %lu, key %lx, repeat %u. Press CTRL+C to stop\r\n",
frequency,
key,
repeat);
SubGhzEncoderPrinceton* encoder = subghz_encoder_princeton_alloc();
subghz_encoder_princeton_reset(encoder, key, repeat);
furi_hal_subghz_reset();
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOokAsync);
frequency = furi_hal_subghz_set_frequency_and_path(frequency);
furi_hal_subghz_start_async_tx(subghz_test_data, subghz_test_data_size, repeat);
furi_hal_subghz_wait_async_tx();
furi_hal_subghz_start_async_tx(subghz_encoder_princeton_yield, encoder);
while(!furi_hal_subghz_is_async_tx_complete()) {
printf(".");
fflush(stdout);
osDelay(333);
}
furi_hal_subghz_stop_async_tx();
free(subghz_test_data);
furi_hal_subghz_sleep();
subghz_encoder_princeton_free(encoder);
}
typedef struct {
@@ -225,8 +212,7 @@ void subghz_cli_command_rx(Cli* cli, string_t args, void* context) {
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
// Prepare and start RX
furi_hal_subghz_set_async_rx_callback(subghz_cli_command_rx_callback, instance);
furi_hal_subghz_start_async_rx();
furi_hal_subghz_start_async_rx(subghz_cli_command_rx_callback, instance);
// Wait for packets to arrive
printf("Listening at %lu. Press CTRL+C to stop\r\n", frequency);

View File

@@ -0,0 +1,83 @@
#include "subghz_i.h"
#include <math.h>
#include <furi.h>
#include <furi-hal.h>
#include <input/input.h>
#include <gui/elements.h>
#include <notification/notification-messages.h>
#include "file-worker.h"
void subghz_begin(FuriHalSubGhzPreset preset) {
furi_hal_subghz_reset();
furi_hal_subghz_idle();
furi_hal_subghz_load_preset(preset);
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
}
void subghz_rx(uint32_t frequency) {
furi_hal_subghz_idle();
furi_hal_subghz_set_frequency_and_path(frequency);
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
furi_hal_subghz_flush_rx();
furi_hal_subghz_rx();
}
void subghz_tx(uint32_t frequency) {
furi_hal_subghz_idle();
furi_hal_subghz_set_frequency_and_path(frequency);
hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
hal_gpio_write(&gpio_cc1101_g0, true);
furi_hal_subghz_tx();
}
void subghz_idle(void) {
furi_hal_subghz_idle();
}
void subghz_end(void) {
furi_hal_subghz_sleep();
}
bool subghz_key_load(SubGhz* subghz, const char* file_path) {
furi_assert(subghz);
furi_assert(file_path);
FileWorker* file_worker = file_worker_alloc(false);
// Load device data
bool loaded = false;
string_t path;
string_init_set_str(path, file_path);
string_t temp_str;
string_init(temp_str);
do {
if(!file_worker_open(file_worker, string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) {
break;
}
// Read and parse name protocol from 1st line
if(!file_worker_read_until(file_worker, temp_str, '\n')) {
break;
}
// strlen("Protocol: ") = 10
string_right(temp_str, 10);
subghz->protocol_result =
subghz_protocol_get_by_name(subghz->protocol, string_get_cstr(temp_str));
if(subghz->protocol_result == NULL) {
file_worker_show_error(file_worker, "Cannot parse\nfile");
break;
}
if(!subghz->protocol_result->to_load_protocol(file_worker, subghz->protocol_result)) {
file_worker_show_error(file_worker, "Cannot parse\nfile");
break;
}
loaded = true;
} while(0);
string_clear(temp_str);
string_clear(path);
file_worker_close(file_worker);
file_worker_free(file_worker);
return loaded;
}

View File

@@ -1,16 +1,31 @@
#pragma once
#include "subghz.h"
#include "views/subghz_capture.h"
#include "views/subghz_test_basic.h"
#include "views/subghz_test_packet.h"
#include "views/subghz_analyze.h"
#include "views/subghz_receiver.h"
#include "views/subghz_transmitter.h"
#include "views/subghz_static.h"
#include "views/subghz_test_carrier.h"
#include "views/subghz_test_packet.h"
#include <furi.h>
#include <furi-hal.h>
#include <gui/gui.h>
#include <gui/scene_manager.h>
#include <gui/view_dispatcher.h>
#include <gui/modules/submenu.h>
#include <gui/modules/dialog_ex.h>
#include <gui/modules/popup.h>
#include <gui/modules/text_input.h>
#include <subghz/scenes/subghz_scene.h>
#include <lib/subghz/subghz_worker.h>
#include <lib/subghz/protocols/subghz_protocol.h>
#include <lib/subghz/protocols/subghz_protocol_common.h>
#define SUBGHZ_TEXT_STORE_SIZE 128
extern const uint32_t subghz_frequencies[];
extern const uint32_t subghz_frequencies_count;
@@ -19,23 +34,47 @@ extern const uint32_t subghz_frequencies_433_92;
struct SubGhz {
Gui* gui;
SubGhzWorker* worker;
SubGhzProtocol* protocol;
SubGhzProtocolCommon* protocol_result;
SceneManager* scene_manager;
ViewDispatcher* view_dispatcher;
Submenu* submenu;
DialogEx* dialog_ex;
Popup* popup;
TextInput* text_input;
char text_store[SUBGHZ_TEXT_STORE_SIZE + 1];
SubghzCapture* subghz_capture;
SubghzTestBasic* subghz_test_basic;
SubghzTestPacket* subghz_test_packet;
SubghzAnalyze* subghz_analyze;
SubghzReceiver* subghz_receiver;
SubghzTransmitter* subghz_transmitter;
SubghzStatic* subghz_static;
SubghzTestCarrier* subghz_test_carrier;
SubghzTestPacket* subghz_test_packet;
};
typedef enum {
SubGhzViewMenu,
SubGhzViewCapture,
SubGhzViewTestBasic,
SubGhzViewTestPacket,
SubGhzViewAnalyze,
SubGhzViewDialogEx,
SubGhzViewReceiver,
SubGhzViewPopup,
SubGhzViewTextInput,
SubGhzViewTransmitter,
SubGhzViewStatic,
SubGhzViewTestCarrier,
SubGhzViewTestPacket,
} SubGhzView;
void subghz_begin(FuriHalSubGhzPreset preset);
void subghz_rx(uint32_t frequency);
void subghz_tx(uint32_t frequency);
void subghz_idle(void);
void subghz_end(void);
bool subghz_key_load(SubGhz* subghz, const char* file_path);

View File

@@ -1,4 +1,4 @@
#include "subghz_capture.h"
#include "subghz_analyze.h"
#include "../subghz_i.h"
#include <math.h>
@@ -13,7 +13,7 @@
#include <assets_icons.h>
struct SubghzCapture {
struct SubghzAnalyze {
View* view;
SubGhzWorker* worker;
SubGhzProtocol* protocol;
@@ -26,11 +26,11 @@ typedef struct {
string_t text;
uint16_t scene;
SubGhzProtocolCommon parser;
} SubghzCaptureModel;
} SubghzAnalyzeModel;
static const char subghz_symbols[] = {'-', '\\', '|', '/'};
void subghz_capture_draw(Canvas* canvas, SubghzCaptureModel* model) {
void subghz_analyze_draw(Canvas* canvas, SubghzAnalyzeModel* model) {
char buffer[64];
canvas_set_color(canvas, ColorBlack);
@@ -39,7 +39,7 @@ void subghz_capture_draw(Canvas* canvas, SubghzCaptureModel* model) {
snprintf(
buffer,
sizeof(buffer),
"Capture: %03ld.%03ldMHz %c",
"Analyze: %03ld.%03ldMHz %c",
model->real_frequency / 1000000 % 1000,
model->real_frequency / 1000 % 1000,
subghz_symbols[model->counter % 4]);
@@ -63,46 +63,47 @@ void subghz_capture_draw(Canvas* canvas, SubghzCaptureModel* model) {
}
}
bool subghz_capture_input(InputEvent* event, void* context) {
bool subghz_analyze_input(InputEvent* event, void* context) {
furi_assert(context);
SubghzCapture* subghz_capture = context;
SubghzAnalyze* subghz_analyze = context;
if(event->type != InputTypeShort) return false;
if(event->key == InputKeyBack) {
return false;
}
with_view_model(
subghz_capture->view, (SubghzCaptureModel * model) {
bool reconfigure = false;
if(event->type == InputTypeShort) {
if(event->key == InputKeyLeft) {
if(model->frequency > 0) model->frequency--;
reconfigure = true;
} else if(event->key == InputKeyRight) {
if(model->frequency < subghz_frequencies_count - 1) model->frequency++;
reconfigure = true;
}
subghz_analyze->view, (SubghzAnalyzeModel * model) {
bool model_updated = false;
if(event->key == InputKeyLeft) {
if(model->frequency > 0) model->frequency--;
model_updated = true;
} else if(event->key == InputKeyRight) {
if(model->frequency < subghz_frequencies_count - 1) model->frequency++;
model_updated = true;
}
if(reconfigure) {
if(model_updated) {
furi_hal_subghz_idle();
model->real_frequency =
furi_hal_subghz_set_frequency_and_path(subghz_frequencies[model->frequency]);
furi_hal_subghz_rx();
}
return reconfigure;
return model_updated;
});
return true;
}
void subghz_capture_text_callback(string_t text, void* context) {
void subghz_analyze_text_callback(string_t text, void* context) {
furi_assert(context);
SubghzCapture* subghz_capture = context;
SubghzAnalyze* subghz_analyze = context;
with_view_model(
subghz_capture->view, (SubghzCaptureModel * model) {
subghz_analyze->view, (SubghzAnalyzeModel * model) {
model->counter++;
string_set(model->text, text);
model->scene = 0;
@@ -110,9 +111,9 @@ void subghz_capture_text_callback(string_t text, void* context) {
});
}
void subghz_capture_protocol_callback(SubGhzProtocolCommon* parser, void* context) {
void subghz_analyze_protocol_callback(SubGhzProtocolCommon* parser, void* context) {
furi_assert(context);
SubghzCapture* subghz_capture = context;
SubghzAnalyze* subghz_analyze = context;
char buffer[64];
snprintf(
buffer,
@@ -128,7 +129,7 @@ void subghz_capture_protocol_callback(SubGhzProtocolCommon* parser, void* contex
parser->btn);
with_view_model(
subghz_capture->view, (SubghzCaptureModel * model) {
subghz_analyze->view, (SubghzAnalyzeModel * model) {
model->counter++;
model->parser = *parser;
string_set(model->text, buffer);
@@ -137,16 +138,16 @@ void subghz_capture_protocol_callback(SubGhzProtocolCommon* parser, void* contex
});
}
void subghz_capture_enter(void* context) {
void subghz_analyze_enter(void* context) {
furi_assert(context);
SubghzCapture* subghz_capture = context;
SubghzAnalyze* subghz_analyze = context;
furi_hal_subghz_reset();
furi_hal_subghz_idle();
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOokAsync);
with_view_model(
subghz_capture->view, (SubghzCaptureModel * model) {
subghz_analyze->view, (SubghzAnalyzeModel * model) {
model->frequency = subghz_frequencies_433_92;
model->real_frequency =
furi_hal_subghz_set_frequency_and_path(subghz_frequencies[model->frequency]);
@@ -156,83 +157,77 @@ void subghz_capture_enter(void* context) {
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
furi_hal_subghz_set_async_rx_callback(subghz_worker_rx_callback, subghz_capture->worker);
furi_hal_subghz_start_async_rx();
furi_hal_subghz_start_async_rx(subghz_worker_rx_callback, subghz_analyze->worker);
subghz_worker_start(subghz_capture->worker);
subghz_worker_start(subghz_analyze->worker);
furi_hal_subghz_flush_rx();
furi_hal_subghz_rx();
}
void subghz_capture_exit(void* context) {
void subghz_analyze_exit(void* context) {
furi_assert(context);
SubghzCapture* subghz_capture = context;
SubghzAnalyze* subghz_analyze = context;
subghz_worker_stop(subghz_capture->worker);
subghz_worker_stop(subghz_analyze->worker);
furi_hal_subghz_stop_async_rx();
furi_hal_subghz_sleep();
}
uint32_t subghz_capture_back(void* context) {
return SubGhzViewMenu;
}
SubghzCapture* subghz_capture_alloc() {
SubghzCapture* subghz_capture = furi_alloc(sizeof(SubghzCapture));
SubghzAnalyze* subghz_analyze_alloc() {
SubghzAnalyze* subghz_analyze = furi_alloc(sizeof(SubghzAnalyze));
// View allocation and configuration
subghz_capture->view = view_alloc();
view_allocate_model(subghz_capture->view, ViewModelTypeLocking, sizeof(SubghzCaptureModel));
view_set_context(subghz_capture->view, subghz_capture);
view_set_draw_callback(subghz_capture->view, (ViewDrawCallback)subghz_capture_draw);
view_set_input_callback(subghz_capture->view, subghz_capture_input);
view_set_enter_callback(subghz_capture->view, subghz_capture_enter);
view_set_exit_callback(subghz_capture->view, subghz_capture_exit);
view_set_previous_callback(subghz_capture->view, subghz_capture_back);
subghz_analyze->view = view_alloc();
view_allocate_model(subghz_analyze->view, ViewModelTypeLocking, sizeof(SubghzAnalyzeModel));
view_set_context(subghz_analyze->view, subghz_analyze);
view_set_draw_callback(subghz_analyze->view, (ViewDrawCallback)subghz_analyze_draw);
view_set_input_callback(subghz_analyze->view, subghz_analyze_input);
view_set_enter_callback(subghz_analyze->view, subghz_analyze_enter);
view_set_exit_callback(subghz_analyze->view, subghz_analyze_exit);
with_view_model(
subghz_capture->view, (SubghzCaptureModel * model) {
subghz_analyze->view, (SubghzAnalyzeModel * model) {
string_init(model->text);
return true;
});
subghz_capture->worker = subghz_worker_alloc();
subghz_capture->protocol = subghz_protocol_alloc();
subghz_analyze->worker = subghz_worker_alloc();
subghz_analyze->protocol = subghz_protocol_alloc();
subghz_worker_set_overrun_callback(
subghz_capture->worker, (SubGhzWorkerOverrunCallback)subghz_protocol_reset);
subghz_analyze->worker, (SubGhzWorkerOverrunCallback)subghz_protocol_reset);
subghz_worker_set_pair_callback(
subghz_capture->worker, (SubGhzWorkerPairCallback)subghz_protocol_parse);
subghz_worker_set_context(subghz_capture->worker, subghz_capture->protocol);
subghz_analyze->worker, (SubGhzWorkerPairCallback)subghz_protocol_parse);
subghz_worker_set_context(subghz_analyze->worker, subghz_analyze->protocol);
subghz_protocol_load_keeloq_file(
subghz_capture->protocol, "/ext/assets/subghz/keeloq_mfcodes");
subghz_analyze->protocol, "/ext/assets/subghz/keeloq_mfcodes");
subghz_protocol_load_nice_flor_s_file(
subghz_capture->protocol, "/ext/assets/subghz/nice_floor_s_rx");
subghz_analyze->protocol, "/ext/assets/subghz/nice_floor_s_rx");
subghz_protocol_enable_dump_text(
subghz_capture->protocol, subghz_capture_text_callback, subghz_capture);
subghz_analyze->protocol, subghz_analyze_text_callback, subghz_analyze);
return subghz_capture;
return subghz_analyze;
}
void subghz_capture_free(SubghzCapture* subghz_capture) {
furi_assert(subghz_capture);
void subghz_analyze_free(SubghzAnalyze* subghz_analyze) {
furi_assert(subghz_analyze);
subghz_protocol_free(subghz_capture->protocol);
subghz_worker_free(subghz_capture->worker);
subghz_protocol_free(subghz_analyze->protocol);
subghz_worker_free(subghz_analyze->worker);
with_view_model(
subghz_capture->view, (SubghzCaptureModel * model) {
subghz_analyze->view, (SubghzAnalyzeModel * model) {
string_clear(model->text);
return true;
});
view_free(subghz_capture->view);
free(subghz_capture);
view_free(subghz_analyze->view);
free(subghz_analyze);
}
View* subghz_capture_get_view(SubghzCapture* subghz_capture) {
furi_assert(subghz_capture);
return subghz_capture->view;
View* subghz_analyze_get_view(SubghzAnalyze* subghz_analyze) {
furi_assert(subghz_analyze);
return subghz_analyze->view;
}

View File

@@ -0,0 +1,11 @@
#pragma once
#include <gui/view.h>
typedef struct SubghzAnalyze SubghzAnalyze;
SubghzAnalyze* subghz_analyze_alloc();
void subghz_analyze_free(SubghzAnalyze* subghz_analyze);
View* subghz_analyze_get_view(SubghzAnalyze* subghz_analyze);

View File

@@ -1,11 +0,0 @@
#pragma once
#include <gui/view.h>
typedef struct SubghzCapture SubghzCapture;
SubghzCapture* subghz_capture_alloc();
void subghz_capture_free(SubghzCapture* subghz_capture);
View* subghz_capture_get_view(SubghzCapture* subghz_capture);

View File

@@ -0,0 +1,146 @@
#include "subghz_receiver.h"
#include "../subghz_i.h"
#include <math.h>
#include <furi.h>
#include <furi-hal.h>
#include <input/input.h>
#include <gui/elements.h>
#include <notification/notification-messages.h>
#include <assets_icons.h>
struct SubghzReceiver {
View* view;
SubghzReceiverCallback callback;
void* context;
};
typedef struct {
string_t text;
uint16_t scene;
SubGhzProtocolCommon* protocol;
} SubghzReceiverModel;
void subghz_receiver_set_callback(
SubghzReceiver* subghz_receiver,
SubghzReceiverCallback callback,
void* context) {
furi_assert(subghz_receiver);
furi_assert(callback);
subghz_receiver->callback = callback;
subghz_receiver->context = context;
}
void subghz_receiver_set_protocol(SubghzReceiver* subghz_receiver, SubGhzProtocolCommon* protocol) {
with_view_model(
subghz_receiver->view, (SubghzReceiverModel * model) {
model->protocol = protocol;
return true;
});
}
void subghz_receiver_draw(Canvas* canvas, SubghzReceiverModel* model) {
canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack);
canvas_set_font(canvas, FontSecondary);
elements_multiline_text(canvas, 0, 10, string_get_cstr(model->text));
elements_button_left(canvas, "Back");
if(model->protocol && model->protocol->to_save_string) {
elements_button_right(canvas, "Save");
}
}
bool subghz_receiver_input(InputEvent* event, void* context) {
furi_assert(context);
SubghzReceiver* subghz_receiver = context;
if(event->type != InputTypeShort) return false;
bool can_be_saved = false;
with_view_model(
subghz_receiver->view, (SubghzReceiverModel * model) {
can_be_saved = (model->protocol && model->protocol->to_save_string);
return false;
});
if(event->key == InputKeyBack) {
return false;
} else if(event->key == InputKeyLeft) {
subghz_receiver->callback(SubghzReceverEventBack, subghz_receiver->context);
} else if(can_be_saved && event->key == InputKeyRight) {
subghz_receiver->callback(SubghzReceverEventSave, subghz_receiver->context);
}
return true;
}
void subghz_receiver_text_callback(string_t text, void* context) {
furi_assert(context);
SubghzReceiver* subghz_receiver = context;
with_view_model(
subghz_receiver->view, (SubghzReceiverModel * model) {
string_set(model->text, text);
model->scene = 0;
return true;
});
}
void subghz_receiver_enter(void* context) {
furi_assert(context);
SubghzReceiver* subghz_receiver = context;
with_view_model(
subghz_receiver->view, (SubghzReceiverModel * model) {
model->protocol->to_string(model->protocol, model->text);
return true;
});
}
void subghz_receiver_exit(void* context) {
furi_assert(context);
SubghzReceiver* subghz_receiver = context;
with_view_model(
subghz_receiver->view, (SubghzReceiverModel * model) {
string_clean(model->text);
return true;
});
}
SubghzReceiver* subghz_receiver_alloc() {
SubghzReceiver* subghz_receiver = furi_alloc(sizeof(SubghzReceiver));
// View allocation and configuration
subghz_receiver->view = view_alloc();
view_allocate_model(subghz_receiver->view, ViewModelTypeLocking, sizeof(SubghzReceiverModel));
view_set_context(subghz_receiver->view, subghz_receiver);
view_set_draw_callback(subghz_receiver->view, (ViewDrawCallback)subghz_receiver_draw);
view_set_input_callback(subghz_receiver->view, subghz_receiver_input);
view_set_enter_callback(subghz_receiver->view, subghz_receiver_enter);
view_set_exit_callback(subghz_receiver->view, subghz_receiver_exit);
with_view_model(
subghz_receiver->view, (SubghzReceiverModel * model) {
string_init(model->text);
return true;
});
return subghz_receiver;
}
void subghz_receiver_free(SubghzReceiver* subghz_receiver) {
furi_assert(subghz_receiver);
with_view_model(
subghz_receiver->view, (SubghzReceiverModel * model) {
string_clear(model->text);
return true;
});
view_free(subghz_receiver->view);
free(subghz_receiver);
}
View* subghz_receiver_get_view(SubghzReceiver* subghz_receiver) {
furi_assert(subghz_receiver);
return subghz_receiver->view;
}

View File

@@ -0,0 +1,26 @@
#pragma once
#include <gui/view.h>
#include <lib/subghz/protocols/subghz_protocol_common.h>
typedef enum {
SubghzReceverEventSave,
SubghzReceverEventBack,
} SubghzReceverEvent;
typedef struct SubghzReceiver SubghzReceiver;
typedef void (*SubghzReceiverCallback)(SubghzReceverEvent event, void* context);
void subghz_receiver_set_callback(
SubghzReceiver* subghz_receiver,
SubghzReceiverCallback callback,
void* context);
SubghzReceiver* subghz_receiver_alloc();
void subghz_receiver_free(SubghzReceiver* subghz_receiver);
View* subghz_receiver_get_view(SubghzReceiver* subghz_receiver);
void subghz_receiver_set_protocol(SubghzReceiver* subghz_receiver, SubGhzProtocolCommon* protocol);

View File

@@ -6,20 +6,18 @@
#include <furi-hal.h>
#include <input/input.h>
#include <notification/notification-messages.h>
#include <lib/subghz/protocols/subghz_protocol_princeton.h>
static const uint8_t subghz_static_keys[][4] = {
{0x74, 0xBA, 0xDE},
{0x74, 0xBA, 0xDD},
{0x74, 0xBA, 0xDB},
{0xE3, 0x4A, 0x4E},
static const uint32_t subghz_static_keys[] = {
0x0074BADE,
0x0074BADD,
0x0074BADB,
0x00E34A4E,
};
#define SUBGHZ_PT_SHORT 376
#define SUBGHZ_PT_LONG (SUBGHZ_PT_SHORT * 3)
#define SUBGHZ_PT_GUARD 10600
struct SubghzStatic {
View* view;
SubGhzEncoderPrinceton* encoder;
};
typedef enum {
@@ -56,14 +54,14 @@ void subghz_static_draw(Canvas* canvas, SubghzStaticModel* model) {
bool subghz_static_input(InputEvent* event, void* context) {
furi_assert(context);
SubghzStatic* subghz_static = context;
SubghzStatic* instance = context;
if(event->key == InputKeyBack) {
return false;
}
with_view_model(
subghz_static->view, (SubghzStaticModel * model) {
instance->view, (SubghzStaticModel * model) {
bool reconfigure = false;
if(event->type == InputTypeShort) {
if(event->key == InputKeyLeft) {
@@ -88,31 +86,16 @@ bool subghz_static_input(InputEvent* event, void* context) {
if(event->key == InputKeyOk) {
if(event->type == InputTypePress) {
const uint8_t* key = subghz_static_keys[model->button];
NotificationApp* notification = furi_record_open("notification");
notification_message_block(notification, &sequence_set_red_255);
__disable_irq();
for(uint8_t r = 0; r < 20; r++) {
//Payload
for(uint8_t i = 0; i < 24; i++) {
uint8_t byte = i / 8;
uint8_t bit = i % 8;
bool value = (key[byte] >> (7 - bit)) & 1;
// Payload send
hal_gpio_write(&gpio_cc1101_g0, true);
delay_us(value ? SUBGHZ_PT_SHORT : SUBGHZ_PT_LONG);
hal_gpio_write(&gpio_cc1101_g0, false);
delay_us(value ? SUBGHZ_PT_LONG : SUBGHZ_PT_SHORT);
}
// Last bit
hal_gpio_write(&gpio_cc1101_g0, true);
delay_us(SUBGHZ_PT_SHORT);
hal_gpio_write(&gpio_cc1101_g0, false);
// Guard time
delay_us(10600);
}
__enable_irq();
subghz_encoder_princeton_reset(
instance->encoder, subghz_static_keys[model->button], 20);
furi_hal_subghz_start_async_tx(
subghz_encoder_princeton_yield, instance->encoder);
while(!furi_hal_subghz_is_async_tx_complete()) osDelay(33);
furi_hal_subghz_stop_async_tx();
notification_message(notification, &sequence_reset_red);
furi_record_close("notification");
}
@@ -126,7 +109,7 @@ bool subghz_static_input(InputEvent* event, void* context) {
void subghz_static_enter(void* context) {
furi_assert(context);
SubghzStatic* subghz_static = context;
SubghzStatic* instance = context;
furi_hal_subghz_reset();
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOokAsync);
@@ -135,7 +118,7 @@ void subghz_static_enter(void* context) {
hal_gpio_write(&gpio_cc1101_g0, false);
with_view_model(
subghz_static->view, (SubghzStaticModel * model) {
instance->view, (SubghzStaticModel * model) {
model->frequency = subghz_frequencies_433_92;
model->real_frequency =
furi_hal_subghz_set_frequency_and_path(subghz_frequencies[model->frequency]);
@@ -148,39 +131,34 @@ void subghz_static_enter(void* context) {
void subghz_static_exit(void* context) {
furi_assert(context);
// SubghzStatic* subghz_static = context;
// Reinitialize IC to default state
furi_hal_subghz_sleep();
}
uint32_t subghz_static_back(void* context) {
return SubGhzViewMenu;
}
SubghzStatic* subghz_static_alloc() {
SubghzStatic* subghz_static = furi_alloc(sizeof(SubghzStatic));
SubghzStatic* instance = furi_alloc(sizeof(SubghzStatic));
// View allocation and configuration
subghz_static->view = view_alloc();
view_allocate_model(subghz_static->view, ViewModelTypeLockFree, sizeof(SubghzStaticModel));
view_set_context(subghz_static->view, subghz_static);
view_set_draw_callback(subghz_static->view, (ViewDrawCallback)subghz_static_draw);
view_set_input_callback(subghz_static->view, subghz_static_input);
view_set_enter_callback(subghz_static->view, subghz_static_enter);
view_set_exit_callback(subghz_static->view, subghz_static_exit);
view_set_previous_callback(subghz_static->view, subghz_static_back);
instance->view = view_alloc();
view_allocate_model(instance->view, ViewModelTypeLockFree, sizeof(SubghzStaticModel));
view_set_context(instance->view, instance);
view_set_draw_callback(instance->view, (ViewDrawCallback)subghz_static_draw);
view_set_input_callback(instance->view, subghz_static_input);
view_set_enter_callback(instance->view, subghz_static_enter);
view_set_exit_callback(instance->view, subghz_static_exit);
return subghz_static;
instance->encoder = subghz_encoder_princeton_alloc();
return instance;
}
void subghz_static_free(SubghzStatic* subghz_static) {
furi_assert(subghz_static);
view_free(subghz_static->view);
free(subghz_static);
void subghz_static_free(SubghzStatic* instance) {
furi_assert(instance);
subghz_encoder_princeton_free(instance->encoder);
view_free(instance->view);
free(instance);
}
View* subghz_static_get_view(SubghzStatic* subghz_static) {
furi_assert(subghz_static);
return subghz_static->view;
View* subghz_static_get_view(SubghzStatic* instance) {
furi_assert(instance);
return instance->view;
}

View File

@@ -1,11 +0,0 @@
#pragma once
#include <gui/view.h>
typedef struct SubghzTestBasic SubghzTestBasic;
SubghzTestBasic* subghz_test_basic_alloc();
void subghz_test_basic_free(SubghzTestBasic* subghz_test_basic);
View* subghz_test_basic_get_view(SubghzTestBasic* subghz_test_basic);

View File

@@ -1,4 +1,4 @@
#include "subghz_test_basic.h"
#include "subghz_test_carrier.h"
#include "../subghz_i.h"
#include <math.h>
@@ -6,25 +6,25 @@
#include <furi-hal.h>
#include <input/input.h>
struct SubghzTestBasic {
struct SubghzTestCarrier {
View* view;
osTimerId timer;
};
typedef enum {
SubghzTestBasicModelStatusRx,
SubghzTestBasicModelStatusTx,
} SubghzTestBasicModelStatus;
SubghzTestCarrierModelStatusRx,
SubghzTestCarrierModelStatusTx,
} SubghzTestCarrierModelStatus;
typedef struct {
uint8_t frequency;
uint32_t real_frequency;
FuriHalSubGhzPath path;
float rssi;
SubghzTestBasicModelStatus status;
} SubghzTestBasicModel;
SubghzTestCarrierModelStatus status;
} SubghzTestCarrierModel;
void subghz_test_basic_draw(Canvas* canvas, SubghzTestBasicModel* model) {
void subghz_test_carrier_draw(Canvas* canvas, SubghzTestCarrierModel* model) {
char buffer[64];
canvas_set_color(canvas, ColorBlack);
@@ -54,7 +54,7 @@ void subghz_test_basic_draw(Canvas* canvas, SubghzTestBasicModel* model) {
}
snprintf(buffer, sizeof(buffer), "Path: %d - %s", model->path, path_name);
canvas_draw_str(canvas, 0, 31, buffer);
if(model->status == SubghzTestBasicModelStatusRx) {
if(model->status == SubghzTestCarrierModelStatusRx) {
snprintf(
buffer,
sizeof(buffer),
@@ -67,17 +67,17 @@ void subghz_test_basic_draw(Canvas* canvas, SubghzTestBasicModel* model) {
}
}
bool subghz_test_basic_input(InputEvent* event, void* context) {
bool subghz_test_carrier_input(InputEvent* event, void* context) {
furi_assert(context);
SubghzTestBasic* subghz_test_basic = context;
SubghzTestCarrier* subghz_test_carrier = context;
if(event->key == InputKeyBack) {
return false;
}
with_view_model(
subghz_test_basic->view, (SubghzTestBasicModel * model) {
osTimerStop(subghz_test_basic->timer);
subghz_test_carrier->view, (SubghzTestCarrierModel * model) {
osTimerStop(subghz_test_carrier->timer);
furi_hal_subghz_idle();
if(event->type == InputTypeShort) {
@@ -90,10 +90,10 @@ bool subghz_test_basic_input(InputEvent* event, void* context) {
} else if(event->key == InputKeyUp) {
if(model->path < FuriHalSubGhzPath868) model->path++;
} else if(event->key == InputKeyOk) {
if(model->status == SubghzTestBasicModelStatusTx) {
model->status = SubghzTestBasicModelStatusRx;
if(model->status == SubghzTestCarrierModelStatusTx) {
model->status = SubghzTestCarrierModelStatusRx;
} else {
model->status = SubghzTestBasicModelStatusTx;
model->status = SubghzTestCarrierModelStatusTx;
}
}
@@ -102,10 +102,10 @@ bool subghz_test_basic_input(InputEvent* event, void* context) {
furi_hal_subghz_set_path(model->path);
}
if(model->status == SubghzTestBasicModelStatusRx) {
if(model->status == SubghzTestCarrierModelStatusRx) {
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
furi_hal_subghz_rx();
osTimerStart(subghz_test_basic->timer, 1024 / 4);
osTimerStart(subghz_test_carrier->timer, 1024 / 4);
} else {
hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
hal_gpio_write(&gpio_cc1101_g0, true);
@@ -118,9 +118,9 @@ bool subghz_test_basic_input(InputEvent* event, void* context) {
return true;
}
void subghz_test_basic_enter(void* context) {
void subghz_test_carrier_enter(void* context) {
furi_assert(context);
SubghzTestBasic* subghz_test_basic = context;
SubghzTestCarrier* subghz_test_carrier = context;
furi_hal_subghz_reset();
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOokAsync);
@@ -128,74 +128,69 @@ void subghz_test_basic_enter(void* context) {
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
with_view_model(
subghz_test_basic->view, (SubghzTestBasicModel * model) {
subghz_test_carrier->view, (SubghzTestCarrierModel * model) {
model->frequency = subghz_frequencies_433_92; // 433
model->real_frequency =
furi_hal_subghz_set_frequency(subghz_frequencies[model->frequency]);
model->path = FuriHalSubGhzPathIsolate; // isolate
model->rssi = 0.0f;
model->status = SubghzTestBasicModelStatusRx;
model->status = SubghzTestCarrierModelStatusRx;
return true;
});
furi_hal_subghz_rx();
osTimerStart(subghz_test_basic->timer, 1024 / 4);
osTimerStart(subghz_test_carrier->timer, 1024 / 4);
}
void subghz_test_basic_exit(void* context) {
void subghz_test_carrier_exit(void* context) {
furi_assert(context);
SubghzTestBasic* subghz_test_basic = context;
SubghzTestCarrier* subghz_test_carrier = context;
osTimerStop(subghz_test_basic->timer);
osTimerStop(subghz_test_carrier->timer);
// Reinitialize IC to default state
furi_hal_subghz_sleep();
}
void subghz_test_basic_rssi_timer_callback(void* context) {
void subghz_test_carrier_rssi_timer_callback(void* context) {
furi_assert(context);
SubghzTestBasic* subghz_test_basic = context;
SubghzTestCarrier* subghz_test_carrier = context;
with_view_model(
subghz_test_basic->view, (SubghzTestBasicModel * model) {
subghz_test_carrier->view, (SubghzTestCarrierModel * model) {
model->rssi = furi_hal_subghz_get_rssi();
return true;
});
}
uint32_t subghz_test_basic_back(void* context) {
return SubGhzViewMenu;
}
SubghzTestBasic* subghz_test_basic_alloc() {
SubghzTestBasic* subghz_test_basic = furi_alloc(sizeof(SubghzTestBasic));
SubghzTestCarrier* subghz_test_carrier_alloc() {
SubghzTestCarrier* subghz_test_carrier = furi_alloc(sizeof(SubghzTestCarrier));
// View allocation and configuration
subghz_test_basic->view = view_alloc();
subghz_test_carrier->view = view_alloc();
view_allocate_model(
subghz_test_basic->view, ViewModelTypeLockFree, sizeof(SubghzTestBasicModel));
view_set_context(subghz_test_basic->view, subghz_test_basic);
view_set_draw_callback(subghz_test_basic->view, (ViewDrawCallback)subghz_test_basic_draw);
view_set_input_callback(subghz_test_basic->view, subghz_test_basic_input);
view_set_enter_callback(subghz_test_basic->view, subghz_test_basic_enter);
view_set_exit_callback(subghz_test_basic->view, subghz_test_basic_exit);
view_set_previous_callback(subghz_test_basic->view, subghz_test_basic_back);
subghz_test_carrier->view, ViewModelTypeLockFree, sizeof(SubghzTestCarrierModel));
view_set_context(subghz_test_carrier->view, subghz_test_carrier);
view_set_draw_callback(subghz_test_carrier->view, (ViewDrawCallback)subghz_test_carrier_draw);
view_set_input_callback(subghz_test_carrier->view, subghz_test_carrier_input);
view_set_enter_callback(subghz_test_carrier->view, subghz_test_carrier_enter);
view_set_exit_callback(subghz_test_carrier->view, subghz_test_carrier_exit);
subghz_test_basic->timer = osTimerNew(
subghz_test_basic_rssi_timer_callback, osTimerPeriodic, subghz_test_basic, NULL);
subghz_test_carrier->timer = osTimerNew(
subghz_test_carrier_rssi_timer_callback, osTimerPeriodic, subghz_test_carrier, NULL);
return subghz_test_basic;
return subghz_test_carrier;
}
void subghz_test_basic_free(SubghzTestBasic* subghz_test_basic) {
furi_assert(subghz_test_basic);
osTimerDelete(subghz_test_basic->timer);
view_free(subghz_test_basic->view);
free(subghz_test_basic);
void subghz_test_carrier_free(SubghzTestCarrier* subghz_test_carrier) {
furi_assert(subghz_test_carrier);
osTimerDelete(subghz_test_carrier->timer);
view_free(subghz_test_carrier->view);
free(subghz_test_carrier);
}
View* subghz_test_basic_get_view(SubghzTestBasic* subghz_test_basic) {
furi_assert(subghz_test_basic);
return subghz_test_basic->view;
View* subghz_test_carrier_get_view(SubghzTestCarrier* subghz_test_carrier) {
furi_assert(subghz_test_carrier);
return subghz_test_carrier->view;
}

View File

@@ -0,0 +1,11 @@
#pragma once
#include <gui/view.h>
typedef struct SubghzTestCarrier SubghzTestCarrier;
SubghzTestCarrier* subghz_test_carrier_alloc();
void subghz_test_carrier_free(SubghzTestCarrier* subghz_test_carrier);
View* subghz_test_carrier_get_view(SubghzTestCarrier* subghz_test_carrier);

View File

@@ -10,16 +10,12 @@
#define SUBGHZ_TEST_PACKET_COUNT 1000
#define SUBGHZ_PT_SHORT 376
#define SUBGHZ_PT_LONG (SUBGHZ_PT_SHORT * 3)
#define SUBGHZ_PT_GUARD 10600
struct SubghzTestPacket {
View* view;
osTimerId timer;
size_t tx_buffer_size;
uint32_t* tx_buffer;
SubGhzProtocolPrinceton* princeton;
SubGhzDecoderPrinceton* decoder;
SubGhzEncoderPrinceton* encoder;
volatile size_t packet_rx;
};
@@ -43,7 +39,7 @@ volatile bool subghz_test_packet_overrun = false;
static void subghz_test_packet_rx_callback(bool level, uint32_t duration, void* context) {
furi_assert(context);
SubghzTestPacket* instance = context;
subghz_protocol_princeton_parse(instance->princeton, level, duration);
subghz_decoder_princeton_parse(instance->decoder, level, duration);
}
static void subghz_test_packet_rx_pt_callback(SubGhzProtocolCommon* parser, void* context) {
@@ -62,8 +58,8 @@ static void subghz_test_packet_rssi_timer_callback(void* context) {
model->rssi = furi_hal_subghz_get_rssi();
model->packets = instance->packet_rx;
} else {
model->packets =
SUBGHZ_TEST_PACKET_COUNT - furi_hal_subghz_get_async_tx_repeat_left();
model->packets = SUBGHZ_TEST_PACKET_COUNT -
subghz_encoder_princeton_get_repeat_left(instance->encoder);
}
return true;
});
@@ -155,10 +151,10 @@ static bool subghz_test_packet_input(InputEvent* event, void* context) {
}
if(model->status == SubghzTestPacketModelStatusRx) {
furi_hal_subghz_start_async_rx();
furi_hal_subghz_start_async_rx(subghz_test_packet_rx_callback, instance);
} else {
furi_hal_subghz_start_async_tx(
instance->tx_buffer, instance->tx_buffer_size, SUBGHZ_TEST_PACKET_COUNT);
subghz_encoder_princeton_reset(instance->encoder, 0x00AABBCC, 1000);
furi_hal_subghz_start_async_tx(subghz_encoder_princeton_yield, instance->encoder);
}
return true;
@@ -171,30 +167,8 @@ void subghz_test_packet_enter(void* context) {
furi_assert(context);
SubghzTestPacket* instance = context;
instance->tx_buffer_size = 25 * 2 * sizeof(uint32_t);
instance->tx_buffer = furi_alloc(instance->tx_buffer_size);
const uint32_t key = 0x00ABCDEF;
size_t pos = 0;
for(uint8_t i = 0; i < 24; i++) {
uint8_t byte = i / 8;
uint8_t bit = i % 8;
bool value = (((uint8_t*)&key)[2 - byte] >> (7 - bit)) & 1;
if(value) {
instance->tx_buffer[pos++] = SUBGHZ_PT_SHORT;
instance->tx_buffer[pos++] = SUBGHZ_PT_LONG;
} else {
instance->tx_buffer[pos++] = SUBGHZ_PT_LONG;
instance->tx_buffer[pos++] = SUBGHZ_PT_SHORT;
}
}
instance->tx_buffer[pos++] = SUBGHZ_PT_SHORT;
instance->tx_buffer[pos++] = SUBGHZ_PT_SHORT + SUBGHZ_PT_GUARD;
furi_hal_subghz_reset();
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOokAsync);
furi_hal_subghz_set_async_rx_callback(subghz_test_packet_rx_callback, instance);
with_view_model(
instance->view, (SubghzTestPacketModel * model) {
@@ -207,7 +181,7 @@ void subghz_test_packet_enter(void* context) {
return true;
});
furi_hal_subghz_start_async_rx();
furi_hal_subghz_start_async_rx(subghz_test_packet_rx_callback, instance);
osTimerStart(instance->timer, 1024 / 4);
}
@@ -228,14 +202,9 @@ void subghz_test_packet_exit(void* context) {
}
return true;
});
furi_hal_subghz_set_async_rx_callback(NULL, NULL);
furi_hal_subghz_sleep();
}
uint32_t subghz_test_packet_back(void* context) {
return SubGhzViewMenu;
}
SubghzTestPacket* subghz_test_packet_alloc() {
SubghzTestPacket* instance = furi_alloc(sizeof(SubghzTestPacket));
@@ -247,14 +216,14 @@ SubghzTestPacket* subghz_test_packet_alloc() {
view_set_input_callback(instance->view, subghz_test_packet_input);
view_set_enter_callback(instance->view, subghz_test_packet_enter);
view_set_exit_callback(instance->view, subghz_test_packet_exit);
view_set_previous_callback(instance->view, subghz_test_packet_back);
instance->timer =
osTimerNew(subghz_test_packet_rssi_timer_callback, osTimerPeriodic, instance, NULL);
instance->princeton = subghz_protocol_princeton_alloc();
instance->decoder = subghz_decoder_princeton_alloc();
subghz_protocol_common_set_callback(
(SubGhzProtocolCommon*)instance->princeton, subghz_test_packet_rx_pt_callback, instance);
(SubGhzProtocolCommon*)instance->decoder, subghz_test_packet_rx_pt_callback, instance);
instance->encoder = subghz_encoder_princeton_alloc();
return instance;
}
@@ -262,7 +231,9 @@ SubghzTestPacket* subghz_test_packet_alloc() {
void subghz_test_packet_free(SubghzTestPacket* instance) {
furi_assert(instance);
subghz_protocol_princeton_free(instance->princeton);
subghz_decoder_princeton_free(instance->decoder);
subghz_encoder_princeton_free(instance->encoder);
osTimerDelete(instance->timer);
view_free(instance->view);
free(instance);

View File

@@ -0,0 +1,138 @@
#include "subghz_transmitter.h"
#include "../subghz_i.h"
#include <math.h>
#include <furi.h>
#include <furi-hal.h>
#include <input/input.h>
#include <gui/elements.h>
#include <notification/notification-messages.h>
#include <assets_icons.h>
struct SubghzTransmitter {
View* view;
SubghzTransmitterCallback callback;
void* context;
};
typedef struct {
string_t text;
uint16_t scene;
SubGhzProtocolCommon* protocol;
} SubghzTransmitterModel;
void subghz_transmitter_set_callback(
SubghzTransmitter* subghz_transmitter,
SubghzTransmitterCallback callback,
void* context) {
furi_assert(subghz_transmitter);
subghz_transmitter->callback = callback;
subghz_transmitter->context = context;
}
void subghz_transmitter_set_protocol(
SubghzTransmitter* subghz_transmitter,
SubGhzProtocolCommon* protocol) {
with_view_model(
subghz_transmitter->view, (SubghzTransmitterModel * model) {
model->protocol = protocol;
return true;
});
}
void subghz_transmitter_draw(Canvas* canvas, SubghzTransmitterModel* model) {
canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack);
canvas_set_font(canvas, FontSecondary);
elements_multiline_text(canvas, 0, 10, string_get_cstr(model->text));
elements_button_center(canvas, "Send");
}
bool subghz_transmitter_input(InputEvent* event, void* context) {
furi_assert(context);
SubghzTransmitter* subghz_transmitter = context;
if(event->type != InputTypeShort) return false;
if(event->key == InputKeyBack) {
return false;
} else if(event->key == InputKeyOk) {
subghz_transmitter->callback(SubghzTransmitterEventSend, subghz_transmitter->context);
return true;
}
return true;
}
void subghz_transmitter_text_callback(string_t text, void* context) {
furi_assert(context);
SubghzTransmitter* subghz_transmitter = context;
with_view_model(
subghz_transmitter->view, (SubghzTransmitterModel * model) {
string_set(model->text, text);
model->scene = 0;
return true;
});
}
void subghz_transmitter_enter(void* context) {
furi_assert(context);
SubghzTransmitter* subghz_transmitter = context;
with_view_model(
subghz_transmitter->view, (SubghzTransmitterModel * model) {
model->protocol->to_string(model->protocol, model->text);
return true;
});
}
void subghz_transmitter_exit(void* context) {
furi_assert(context);
SubghzTransmitter* subghz_transmitter = context;
with_view_model(
subghz_transmitter->view, (SubghzTransmitterModel * model) {
string_clean(model->text);
return true;
});
}
SubghzTransmitter* subghz_transmitter_alloc() {
SubghzTransmitter* subghz_transmitter = furi_alloc(sizeof(SubghzTransmitter));
// View allocation and configuration
subghz_transmitter->view = view_alloc();
view_allocate_model(
subghz_transmitter->view, ViewModelTypeLocking, sizeof(SubghzTransmitterModel));
view_set_context(subghz_transmitter->view, subghz_transmitter);
view_set_draw_callback(subghz_transmitter->view, (ViewDrawCallback)subghz_transmitter_draw);
view_set_input_callback(subghz_transmitter->view, subghz_transmitter_input);
view_set_enter_callback(subghz_transmitter->view, subghz_transmitter_enter);
view_set_exit_callback(subghz_transmitter->view, subghz_transmitter_exit);
with_view_model(
subghz_transmitter->view, (SubghzTransmitterModel * model) {
string_init(model->text);
return true;
});
return subghz_transmitter;
}
void subghz_transmitter_free(SubghzTransmitter* subghz_transmitter) {
furi_assert(subghz_transmitter);
with_view_model(
subghz_transmitter->view, (SubghzTransmitterModel * model) {
string_clear(model->text);
return true;
});
view_free(subghz_transmitter->view);
free(subghz_transmitter);
}
View* subghz_transmitter_get_view(SubghzTransmitter* subghz_transmitter) {
furi_assert(subghz_transmitter);
return subghz_transmitter->view;
}

View File

@@ -0,0 +1,28 @@
#pragma once
#include <gui/view.h>
#include <lib/subghz/protocols/subghz_protocol_common.h>
typedef enum {
SubghzTransmitterEventSend,
SubghzTransmitterEventBack,
} SubghzTransmitterEvent;
typedef struct SubghzTransmitter SubghzTransmitter;
typedef void (*SubghzTransmitterCallback)(SubghzTransmitterEvent event, void* context);
void subghz_transmitter_set_callback(
SubghzTransmitter* subghz_transmitter,
SubghzTransmitterCallback callback,
void* context);
SubghzTransmitter* subghz_transmitter_alloc();
void subghz_transmitter_free(SubghzTransmitter* subghz_transmitter);
View* subghz_transmitter_get_view(SubghzTransmitter* subghz_transmitter);
void subghz_transmitter_set_protocol(
SubghzTransmitter* subghz_transmitter,
SubGhzProtocolCommon* protocol);