Skorp subghz signal archive (#667)
* SubGhz: Add millis() furi, add subghz history struct * SubGhz: Fix subghz history * Gubghz: Fix code repeat history, add clean history * SubGhz: reading and adding keys to history * Gui: Renaming Sub 1-Ghz -> SubGhz * Archive: Renaming Sub 1-Ghz -> SubGhz * SubGhz: Add menu history, modified button for sending a signal, changed output of data about accepted protocol * Archive: Fix name subghz * SubGhz: Menu navigation * Assets: Add assets/SubGHz/icon.png * Assets: add new icons for subghz * SubGhz: Fix name Add manually scene * SubGhz: Fix load icon Read scene. rename encoder struct, rename protocol function load from file, add load raw data protocol, add info pleasant signals all protocol * SubGhz: fix memory leak * SubGhz: change of receiving frequency for read scene * SubGhz: Add save/load frequency and preset, add automatic configuration of transmit/receive to the desired frequency and modulation, add button "save" config scene * SubGhz: Fix frequency and preset, fix frequency add manualli scene, fix re-executing the parser * Furi-hal-subghz: add 2-FSK config, fix ook config 650KHz BW Tx filter * Fix formatting and release build * SubGhz: Delete read scene * SubGhz: Fix frequency add manualli scene, refactoring code * SubGhz: 2 profiles for OOK, fix broken build. * SubGhz: Add passing static codes from read scene, add notification read scene, refactoring code * SubGhz: fix assert on worker double stop. Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <notification/notification-messages.h>
|
||||
#include "file-worker.h"
|
||||
#include "../notification/notification.h"
|
||||
#include "views/subghz_receiver.h"
|
||||
|
||||
void subghz_begin(FuriHalSubGhzPreset preset) {
|
||||
furi_hal_subghz_reset();
|
||||
@@ -16,30 +17,59 @@ void subghz_begin(FuriHalSubGhzPreset preset) {
|
||||
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
}
|
||||
|
||||
void subghz_rx(uint32_t frequency) {
|
||||
uint32_t subghz_rx(void* context, uint32_t frequency) {
|
||||
furi_assert(context);
|
||||
SubGhzWorker* worker = context;
|
||||
|
||||
furi_hal_subghz_idle();
|
||||
furi_hal_subghz_set_frequency_and_path(frequency);
|
||||
uint32_t value = 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();
|
||||
|
||||
furi_hal_subghz_start_async_rx(subghz_worker_rx_callback, worker);
|
||||
subghz_worker_start(worker);
|
||||
return value;
|
||||
}
|
||||
|
||||
void subghz_tx(uint32_t frequency) {
|
||||
uint32_t subghz_tx(uint32_t frequency) {
|
||||
furi_hal_subghz_idle();
|
||||
furi_hal_subghz_set_frequency_and_path(frequency);
|
||||
uint32_t value = 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();
|
||||
return value;
|
||||
}
|
||||
|
||||
void subghz_idle(void) {
|
||||
furi_hal_subghz_idle();
|
||||
}
|
||||
|
||||
void subghz_end(void) {
|
||||
void subghz_rx_end(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzWorker* worker = context;
|
||||
|
||||
if(subghz_worker_is_running(worker)) {
|
||||
subghz_worker_stop(worker);
|
||||
furi_hal_subghz_stop_async_rx();
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_sleep(void) {
|
||||
furi_hal_subghz_sleep();
|
||||
}
|
||||
|
||||
void subghz_frequency_preset_to_str(void* context, string_t output) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
string_cat_printf(
|
||||
output,
|
||||
"Frequency: %d\n"
|
||||
"Preset: %d\n",
|
||||
(int)subghz->frequency,
|
||||
(int)subghz->preset);
|
||||
}
|
||||
|
||||
void subghz_transmitter_tx_start(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
subghz->encoder = subghz_protocol_encoder_common_alloc();
|
||||
@@ -47,8 +77,17 @@ void subghz_transmitter_tx_start(void* context) {
|
||||
//get upload
|
||||
if(subghz->protocol_result->get_upload_protocol) {
|
||||
if(subghz->protocol_result->get_upload_protocol(subghz->protocol_result, subghz->encoder)) {
|
||||
subghz_begin(FuriHalSubGhzPresetOokAsync);
|
||||
subghz_tx(433920000);
|
||||
if(subghz->preset) {
|
||||
subghz_begin(subghz->preset);
|
||||
} else {
|
||||
subghz_begin(FuriHalSubGhzPresetOok650Async);
|
||||
}
|
||||
if(subghz->frequency) {
|
||||
subghz_tx(subghz->frequency);
|
||||
} else {
|
||||
subghz_tx(433920000);
|
||||
}
|
||||
|
||||
//Start TX
|
||||
furi_hal_subghz_start_async_tx(subghz_protocol_encoder_common_yield, subghz->encoder);
|
||||
}
|
||||
@@ -59,7 +98,6 @@ void subghz_transmitter_tx_stop(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
//Stop TX
|
||||
furi_hal_subghz_stop_async_tx();
|
||||
subghz_end();
|
||||
subghz_protocol_encoder_common_free(subghz->encoder);
|
||||
//if protocol dynamic then we save the last upload
|
||||
if(subghz->protocol_result->type_protocol == TYPE_PROTOCOL_DYNAMIC) {
|
||||
@@ -79,12 +117,35 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path) {
|
||||
string_init_set_str(path, file_path);
|
||||
string_t temp_str;
|
||||
string_init(temp_str);
|
||||
int res = 0;
|
||||
int data = 0;
|
||||
|
||||
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
|
||||
|
||||
// Read and parse frequency from 1st line
|
||||
if(!file_worker_read_until(file_worker, temp_str, '\n')) {
|
||||
break;
|
||||
}
|
||||
res = sscanf(string_get_cstr(temp_str), "Frequency: %d\n", &data);
|
||||
if(res != 1) {
|
||||
break;
|
||||
}
|
||||
subghz->frequency = (uint32_t)data;
|
||||
|
||||
// Read and parse preset from 2st line
|
||||
if(!file_worker_read_until(file_worker, temp_str, '\n')) {
|
||||
break;
|
||||
}
|
||||
res = sscanf(string_get_cstr(temp_str), "Preset: %d\n", &data);
|
||||
if(res != 1) {
|
||||
break;
|
||||
}
|
||||
subghz->preset = (FuriHalSubGhzPreset)data;
|
||||
|
||||
// Read and parse name protocol from 2st line
|
||||
if(!file_worker_read_until(file_worker, temp_str, '\n')) {
|
||||
break;
|
||||
}
|
||||
@@ -93,16 +154,18 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path) {
|
||||
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");
|
||||
if(!subghz->protocol_result->to_load_protocol_from_file(
|
||||
file_worker, subghz->protocol_result)) {
|
||||
break;
|
||||
}
|
||||
loaded = true;
|
||||
} while(0);
|
||||
|
||||
if(!loaded) {
|
||||
file_worker_show_error(file_worker, "Cannot parse\nfile");
|
||||
}
|
||||
string_clear(temp_str);
|
||||
string_clear(path);
|
||||
file_worker_close(file_worker);
|
||||
@@ -113,6 +176,7 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path) {
|
||||
|
||||
bool subghz_save_protocol_to_file(void* context, const char* dev_name) {
|
||||
SubGhz* subghz = context;
|
||||
furi_assert(subghz->protocol_result);
|
||||
FileWorker* file_worker = file_worker_alloc(false);
|
||||
string_t dev_file_name;
|
||||
string_init(dev_file_name);
|
||||
@@ -140,6 +204,11 @@ bool subghz_save_protocol_to_file(void* context, const char* dev_name) {
|
||||
file_worker, string_get_cstr(dev_file_name), FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
|
||||
break;
|
||||
}
|
||||
//Get string frequency preset protocol
|
||||
subghz_frequency_preset_to_str(subghz, temp_str);
|
||||
if(!file_worker_write(file_worker, string_get_cstr(temp_str), string_size(temp_str))) {
|
||||
break;
|
||||
}
|
||||
//Get string save
|
||||
subghz->protocol_result->to_save_string(subghz->protocol_result, temp_str);
|
||||
// Prepare and write data to file
|
||||
@@ -157,7 +226,7 @@ bool subghz_save_protocol_to_file(void* context, const char* dev_name) {
|
||||
return saved;
|
||||
}
|
||||
|
||||
bool subghz_saved_protocol_select(SubGhz* subghz) {
|
||||
bool subghz_load_protocol_from_file(SubGhz* subghz) {
|
||||
furi_assert(subghz);
|
||||
|
||||
FileWorker* file_worker = file_worker_alloc(false);
|
||||
@@ -165,6 +234,8 @@ bool subghz_saved_protocol_select(SubGhz* subghz) {
|
||||
string_init(protocol_file_name);
|
||||
string_t temp_str;
|
||||
string_init(temp_str);
|
||||
int sscanf_res = 0;
|
||||
int data = 0;
|
||||
|
||||
// Input events and views are managed by file_select
|
||||
bool res = file_worker_file_select(
|
||||
@@ -197,7 +268,27 @@ bool subghz_saved_protocol_select(SubGhz* subghz) {
|
||||
file_worker, string_get_cstr(protocol_file_name), FSAM_READ, FSOM_OPEN_EXISTING)) {
|
||||
break;
|
||||
}
|
||||
// Read and parse name protocol from 1st line
|
||||
// Read and parse frequency from 1st line
|
||||
if(!file_worker_read_until(file_worker, temp_str, '\n')) {
|
||||
break;
|
||||
}
|
||||
sscanf_res = sscanf(string_get_cstr(temp_str), "Frequency: %d\n", &data);
|
||||
if(sscanf_res != 1) {
|
||||
break;
|
||||
}
|
||||
subghz->frequency = (uint32_t)data;
|
||||
|
||||
// Read and parse preset from 2st line
|
||||
if(!file_worker_read_until(file_worker, temp_str, '\n')) {
|
||||
break;
|
||||
}
|
||||
sscanf_res = sscanf(string_get_cstr(temp_str), "Preset: %d\n", &data);
|
||||
if(sscanf_res != 1) {
|
||||
break;
|
||||
}
|
||||
subghz->preset = (FuriHalSubGhzPreset)data;
|
||||
|
||||
// Read and parse name protocol from 3st line
|
||||
if(!file_worker_read_until(file_worker, temp_str, '\n')) {
|
||||
break;
|
||||
}
|
||||
@@ -206,16 +297,19 @@ bool subghz_saved_protocol_select(SubGhz* subghz) {
|
||||
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");
|
||||
if(!subghz->protocol_result->to_load_protocol_from_file(
|
||||
file_worker, subghz->protocol_result)) {
|
||||
break;
|
||||
}
|
||||
res = true;
|
||||
} while(0);
|
||||
|
||||
if(!res) {
|
||||
file_worker_show_error(file_worker, "Cannot parse\nfile");
|
||||
}
|
||||
|
||||
string_clear(temp_str);
|
||||
string_clear(protocol_file_name);
|
||||
|
||||
|
Reference in New Issue
Block a user