Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SubGhz App #516

Merged
merged 5 commits into from
Jul 2, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 29 additions & 49 deletions applications/main/subghz/scenes/subghz_scene_receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,35 +92,41 @@ static void subghz_scene_add_to_history_callback(
void* context) {
furi_assert(context);
SubGhz* subghz = context;
SubGhzHistory* history = subghz->history;
FuriString* item_name = furi_string_alloc();
FuriString* item_time = furi_string_alloc();
uint16_t idx = subghz_history_get_item(history);

SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx);
if(subghz_history_add_to_history(history, decoder_base, &preset)) {
furi_string_reset(item_name);
furi_string_reset(item_time);
// The check can be moved to /lib/subghz/receiver.c, but may result in false positives
if((decoder_base->protocol->flag & subghz->ignore_filter) == 0) {
SubGhzHistory* history = subghz->history;
FuriString* item_name = furi_string_alloc();
FuriString* item_time = furi_string_alloc();
uint16_t idx = subghz_history_get_item(history);

subghz->state_notifications = SubGhzNotificationStateRxDone;
SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx);
if(subghz_history_add_to_history(history, decoder_base, &preset)) {
furi_string_reset(item_name);
furi_string_reset(item_time);

subghz_history_get_text_item_menu(history, item_name, idx);
subghz_history_get_time_item_menu(history, item_time, idx);
subghz_view_receiver_add_item_to_menu(
subghz->subghz_receiver,
furi_string_get_cstr(item_name),
furi_string_get_cstr(item_time),
subghz_history_get_type_protocol(history, idx));
subghz->state_notifications = SubGhzNotificationStateRxDone;

subghz_history_get_text_item_menu(history, item_name, idx);
subghz_history_get_time_item_menu(history, item_time, idx);
subghz_view_receiver_add_item_to_menu(
subghz->subghz_receiver,
furi_string_get_cstr(item_name),
furi_string_get_cstr(item_time),
subghz_history_get_type_protocol(history, idx));

subghz_scene_receiver_update_statusbar(subghz);
if(subghz_history_get_text_space_left(subghz->history, NULL)) {
notification_message(subghz->notifications, &sequence_error);
subghz_scene_receiver_update_statusbar(subghz);
if(subghz_history_get_text_space_left(subghz->history, NULL)) {
notification_message(subghz->notifications, &sequence_error);
}
}
subghz_receiver_reset(receiver);
furi_string_free(item_name);
furi_string_free(item_time);
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateAddKey);
} else {
FURI_LOG_I(TAG, "%s protocol ignored", decoder_base->protocol->name);
}
subghz_receiver_reset(receiver);
furi_string_free(item_name);
furi_string_free(item_time);
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateAddKey);
}

void subghz_scene_receiver_on_enter(void* context) {
Expand Down Expand Up @@ -161,32 +167,6 @@ void subghz_scene_receiver_on_enter(void* context) {
subghz->subghz_receiver, subghz_scene_receiver_callback, subghz);
subghz_txrx_set_rx_calback(subghz->txrx, subghz_scene_add_to_history_callback, subghz);

// TODO: Replace with proper solution based on protocol flags, remove kostily and velosipedy from here
// Needs to be done after subghz refactoring merge!!!
if(subghz->ignore_starline == true) {
if(subghz_txrx_load_decoder_by_name_protocol(subghz->txrx, "Star Line")) {
subghz_protocol_decoder_base_set_decoder_callback(
subghz_txrx_get_decoder(subghz->txrx), NULL, NULL);
}
}
if(subghz->ignore_auto_alarms == true) {
if(subghz_txrx_load_decoder_by_name_protocol(subghz->txrx, "KIA Seed")) {
subghz_protocol_decoder_base_set_decoder_callback(
subghz_txrx_get_decoder(subghz->txrx), NULL, NULL);
}

if(subghz_txrx_load_decoder_by_name_protocol(subghz->txrx, "Scher-Khan")) {
subghz_protocol_decoder_base_set_decoder_callback(
subghz_txrx_get_decoder(subghz->txrx), NULL, NULL);
}
}
if(subghz->ignore_magellan == true) {
if(subghz_txrx_load_decoder_by_name_protocol(subghz->txrx, "Magellan")) {
subghz_protocol_decoder_base_set_decoder_callback(
subghz_txrx_get_decoder(subghz->txrx), NULL, NULL);
}
}

if(!subghz_history_get_text_space_left(subghz->history, NULL)) {
subghz->state_notifications = SubGhzNotificationStateRx;
}
Expand Down
70 changes: 34 additions & 36 deletions applications/main/subghz/scenes/subghz_scene_receiver_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,8 @@ const uint32_t bin_raw_value[BIN_RAW_COUNT] = {
SubGhzProtocolFlag_Decodable,
SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_BinRAW,
};
#define STARLINE_COUNT 2
const char* const starline_text[STARLINE_COUNT] = {
"OFF",
"ON",
};

#define AUTO_ALARMS_COUNT 2
const char* const auto_alarms_text[AUTO_ALARMS_COUNT] = {
"OFF",
"ON",
};

#define MAGELLAN_COUNT 2
const char* const magellan_text[MAGELLAN_COUNT] = {
#define PROTOCOL_IGNORE_COUNT 2
const char* const protocol_ignore_text[PROTOCOL_IGNORE_COUNT] = {
"OFF",
"ON",
};
Expand Down Expand Up @@ -257,28 +245,35 @@ static void subghz_scene_receiver_config_set_raw_threshold_rssi(VariableItem* it
subghz_threshold_rssi_set(subghz->threshold_rssi, raw_threshold_rssi_value[index]);
}

static void subghz_scene_receiver_config_set_starline(VariableItem* item) {
static inline void
subghz_scene_receiver_config_set_ignore_filter(VariableItem* item, SubGhzProtocolFlag filter) {
SubGhz* subghz = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);

variable_item_set_current_value_text(item, starline_text[index]);
subghz->ignore_starline = (index == 1);
variable_item_set_current_value_text(item, protocol_ignore_text[index]);

if(index == 0) {
CLEAR_BIT(subghz->ignore_filter, filter);
} else {
SET_BIT(subghz->ignore_filter, filter);
}
}
static inline bool subghz_scene_receiver_config_ignore_filter_get_index(
SubGhzProtocolFlag filter,
SubGhzProtocolFlag flag) {
return READ_BIT(filter, flag) > 0;
}

static void subghz_scene_receiver_config_set_starline(VariableItem* item) {
subghz_scene_receiver_config_set_ignore_filter(item, SubGhzProtocolFlag_StarLine);
}

static void subghz_scene_receiver_config_set_auto_alarms(VariableItem* item) {
SubGhz* subghz = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);

variable_item_set_current_value_text(item, auto_alarms_text[index]);
subghz->ignore_auto_alarms = (index == 1);
subghz_scene_receiver_config_set_ignore_filter(item, SubGhzProtocolFlag_AutoAlarms);
}

static void subghz_scene_receiver_config_set_magellan(VariableItem* item) {
SubGhz* subghz = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);

variable_item_set_current_value_text(item, magellan_text[index]);
subghz->ignore_magellan = (index == 1);
subghz_scene_receiver_config_set_ignore_filter(item, SubGhzProtocolFlag_Magelan);
}

static void subghz_scene_receiver_config_var_list_enter_callback(void* context, uint32_t index) {
Expand Down Expand Up @@ -362,35 +357,38 @@ void subghz_scene_receiver_config_on_enter(void* context) {
item = variable_item_list_add(
subghz->variable_item_list,
"Ignore Starline:",
STARLINE_COUNT,
PROTOCOL_IGNORE_COUNT,
subghz_scene_receiver_config_set_starline,
subghz);

value_index = subghz->ignore_starline;
value_index = subghz_scene_receiver_config_ignore_filter_get_index(
subghz->ignore_filter, SubGhzProtocolFlag_StarLine);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, starline_text[value_index]);
variable_item_set_current_value_text(item, protocol_ignore_text[value_index]);

item = variable_item_list_add(
subghz->variable_item_list,
"Ignore Cars:",
AUTO_ALARMS_COUNT,
PROTOCOL_IGNORE_COUNT,
subghz_scene_receiver_config_set_auto_alarms,
subghz);

value_index = subghz->ignore_auto_alarms;
value_index = subghz_scene_receiver_config_ignore_filter_get_index(
subghz->ignore_filter, SubGhzProtocolFlag_AutoAlarms);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, auto_alarms_text[value_index]);
variable_item_set_current_value_text(item, protocol_ignore_text[value_index]);

item = variable_item_list_add(
subghz->variable_item_list,
"Ignore Magellan:",
MAGELLAN_COUNT,
PROTOCOL_IGNORE_COUNT,
subghz_scene_receiver_config_set_magellan,
subghz);

value_index = subghz->ignore_magellan;
value_index = subghz_scene_receiver_config_ignore_filter_get_index(
subghz->ignore_filter, SubGhzProtocolFlag_Magelan);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, magellan_text[value_index]);
variable_item_set_current_value_text(item, protocol_ignore_text[value_index]);
}

// Enable speaker, will send all incoming noises and signals to speaker so you can listen how your remote sounds like :)
Expand Down
84 changes: 38 additions & 46 deletions applications/main/subghz/subghz.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,42 @@ static void subghz_rpc_command_callback(RpcAppSystemEvent event, void* context)
}
}

static void subghz_load_custom_presets(SubGhzSetting* setting) {
furi_assert(setting);

const char* presets[][2] = {
{"FM95",
"02 0D 0B 06 08 32 07 04 14 00 13 02 12 04 11 83 10 67 15 24 18 18 19 16 1D 91 1C 00 1B 07 20 FB 22 10 21 56 00 00 C0 00 00 00 00 00 00 00"},

// #2-FSK 200khz BW / 135kHz Filter/ 15.86Khz Deviation + Ramping
{"FM15k",
"02 0D 03 47 08 32 0B 06 15 32 14 00 13 00 12 00 11 32 10 A7 18 18 19 1D 1D 92 1C 00 1B 04 20 FB 22 17 21 B6 00 00 00 12 0E 34 60 C5 C1 C0"},

// Pagers
{"Pagers",
"02 0D 07 04 08 32 0B 06 10 64 11 93 12 0C 13 02 14 00 15 15 18 18 19 16 1B 07 1C 00 1D 91 20 FB 21 56 22 10 00 00 C0 00 00 00 00 00 00 00"},

// # HND - FM preset
{"HND_1",
"02 0D 0B 06 08 32 07 04 14 00 13 02 12 04 11 36 10 69 15 32 18 18 19 16 1D 91 1C 00 1B 07 20 FB 22 10 21 56 00 00 C0 00 00 00 00 00 00 00"},
};

FlipperFormat* fff_temp = flipper_format_string_alloc();

for(uint8_t i = 0; i < COUNT_OF(presets); i++) {
flipper_format_insert_or_update_string_cstr(fff_temp, "Custom_preset_data", presets[i][1]);

flipper_format_rewind(fff_temp);
subghz_setting_load_custom_preset(setting, presets[i][0], fff_temp);
}

flipper_format_free(fff_temp);

#ifdef FURI_DEBUG
subghz_setting_customs_presets_to_log(setting);
#endif
}

SubGhz* subghz_alloc(bool alloc_for_tx_only) {
SubGhz* subghz = malloc(sizeof(SubGhz));

Expand Down Expand Up @@ -177,52 +213,7 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) {

SubGhzSetting* setting = subghz_txrx_get_setting(subghz->txrx);

// Custom Presets load without using config file
if(!alloc_for_tx_only) {
FlipperFormat* temp_fm_preset = flipper_format_string_alloc();
flipper_format_write_string_cstr(
temp_fm_preset,
(const char*)"Custom_preset_data",
(const char*)"02 0D 0B 06 08 32 07 04 14 00 13 02 12 04 11 83 10 67 15 24 18 18 19 16 1D 91 1C 00 1B 07 20 FB 22 10 21 56 00 00 C0 00 00 00 00 00 00 00");
flipper_format_rewind(temp_fm_preset);
subghz_setting_load_custom_preset(setting, (const char*)"FM95", temp_fm_preset);

flipper_format_free(temp_fm_preset);

// #2-FSK 200khz BW / 135kHz Filter/ 15.86Khz Deviation + Ramping
FlipperFormat* temp_fm_preset2 = flipper_format_string_alloc();
flipper_format_write_string_cstr(
temp_fm_preset2,
(const char*)"Custom_preset_data",
(const char*)"02 0D 03 47 08 32 0B 06 15 32 14 00 13 00 12 00 11 32 10 A7 18 18 19 1D 1D 92 1C 00 1B 04 20 FB 22 17 21 B6 00 00 00 12 0E 34 60 C5 C1 C0");
flipper_format_rewind(temp_fm_preset2);
subghz_setting_load_custom_preset(setting, (const char*)"FM15k", temp_fm_preset2);

flipper_format_free(temp_fm_preset2);

// Pagers
FlipperFormat* temp_fm_preset3 = flipper_format_string_alloc();
flipper_format_write_string_cstr(
temp_fm_preset3,
(const char*)"Custom_preset_data",
(const char*)"02 0D 07 04 08 32 0B 06 10 64 11 93 12 0C 13 02 14 00 15 15 18 18 19 16 1B 07 1C 00 1D 91 20 FB 21 56 22 10 00 00 C0 00 00 00 00 00 00 00");
flipper_format_rewind(temp_fm_preset3);
subghz_setting_load_custom_preset(setting, (const char*)"Pagers", temp_fm_preset3);

flipper_format_free(temp_fm_preset3);

// # HND - FM preset
FlipperFormat* temp_fm_preset4 = flipper_format_string_alloc();
flipper_format_write_string_cstr(
temp_fm_preset4,
(const char*)"Custom_preset_data",
(const char*)"02 0D 0B 06 08 32 07 04 14 00 13 02 12 04 11 36 10 69 15 32 18 18 19 16 1D 91 1C 00 1B 07 20 FB 22 10 21 56 00 00 C0 00 00 00 00 00 00 00");
flipper_format_rewind(temp_fm_preset4);
subghz_setting_load_custom_preset(setting, (const char*)"HND_1", temp_fm_preset4);

flipper_format_free(temp_fm_preset4);
}
// custom presets loading - end
subghz_load_custom_presets(setting);

// Load last used values for Read, Read RAW, etc. or default
subghz->last_settings = subghz_last_settings_alloc();
Expand Down Expand Up @@ -251,6 +242,7 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) {
subghz->secure_data = malloc(sizeof(SecureData));

subghz->filter = SubGhzProtocolFlag_Decodable;
subghz->ignore_filter = 0x0;
subghz_txrx_receiver_set_filter(subghz->txrx, subghz->filter);
subghz_txrx_set_need_save_callback(subghz->txrx, subghz_save_to_file, subghz);

Expand Down
5 changes: 1 addition & 4 deletions applications/main/subghz/subghz_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,10 @@ struct SubGhz {
SubGhzLastSettings* last_settings;

SubGhzProtocolFlag filter;
SubGhzProtocolFlag ignore_filter;
FuriString* error_str;
SubGhzLock lock;

bool ignore_starline;
bool ignore_auto_alarms;
bool ignore_magellan;

SecureData* secure_data;

SubGhzFileEncoderWorker* decode_raw_file_worker_encoder;
Expand Down
1 change: 0 additions & 1 deletion applications/main/subghz/subghz_last_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count

instance->timestamp_file_names = temp_timestamp_file_names;

// Set globally
if(instance->external_module_power_5v_disable) {
furi_hal_subghz_set_external_power_disable(true);
furi_hal_subghz_disable_ext_power();
Expand Down
3 changes: 2 additions & 1 deletion firmware/targets/f7/api_symbols.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,30.1,,
Version,+,31.0,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,,
Header,+,applications/services/cli/cli_vcp.h,,
Expand Down Expand Up @@ -2782,6 +2782,7 @@ Function,+,subghz_receiver_search_decoder_base_by_name,SubGhzProtocolDecoderBase
Function,+,subghz_receiver_set_filter,void,"SubGhzReceiver*, SubGhzProtocolFlag"
Function,+,subghz_receiver_set_rx_callback,void,"SubGhzReceiver*, SubGhzReceiverCallback, void*"
Function,+,subghz_setting_alloc,SubGhzSetting*,
Function,-,subghz_setting_customs_presets_to_log,uint8_t,SubGhzSetting*
Function,+,subghz_setting_delete_custom_preset,_Bool,"SubGhzSetting*, const char*"
Function,+,subghz_setting_free,void,SubGhzSetting*
Function,+,subghz_setting_get_default_frequency,uint32_t,SubGhzSetting*
Expand Down
3 changes: 2 additions & 1 deletion lib/subghz/protocols/kia.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ const SubGhzProtocolEncoder subghz_protocol_kia_encoder = {
const SubGhzProtocol subghz_protocol_kia = {
.name = SUBGHZ_PROTOCOL_KIA_NAME,
.type = SubGhzProtocolTypeDynamic,
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_FM | SubGhzProtocolFlag_Decodable,
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_FM | SubGhzProtocolFlag_Decodable |
SubGhzProtocolFlag_AutoAlarms,

.decoder = &subghz_protocol_kia_decoder,
.encoder = &subghz_protocol_kia_encoder,
Expand Down
3 changes: 2 additions & 1 deletion lib/subghz/protocols/magellan.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ const SubGhzProtocol subghz_protocol_magellan = {
.name = SUBGHZ_PROTOCOL_MAGELLAN_NAME,
.type = SubGhzProtocolTypeStatic,
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable |
SubGhzProtocolFlag_Load | SubGhzProtocolFlag_Save | SubGhzProtocolFlag_Send,
SubGhzProtocolFlag_Load | SubGhzProtocolFlag_Save | SubGhzProtocolFlag_Send |
SubGhzProtocolFlag_Magelan,

.decoder = &subghz_protocol_magellan_decoder,
.encoder = &subghz_protocol_magellan_encoder,
Expand Down
2 changes: 1 addition & 1 deletion lib/subghz/protocols/scher_khan.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const SubGhzProtocol subghz_protocol_scher_khan = {
.name = SUBGHZ_PROTOCOL_SCHER_KHAN_NAME,
.type = SubGhzProtocolTypeDynamic,
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_FM | SubGhzProtocolFlag_Decodable |
SubGhzProtocolFlag_Save,
SubGhzProtocolFlag_Save | SubGhzProtocolFlag_AutoAlarms,

.decoder = &subghz_protocol_scher_khan_decoder,
.encoder = &subghz_protocol_scher_khan_encoder,
Expand Down
3 changes: 2 additions & 1 deletion lib/subghz/protocols/star_line.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ const SubGhzProtocol subghz_protocol_star_line = {
.name = SUBGHZ_PROTOCOL_STAR_LINE_NAME,
.type = SubGhzProtocolTypeDynamic,
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable |
SubGhzProtocolFlag_Load | SubGhzProtocolFlag_Save | SubGhzProtocolFlag_Send,
SubGhzProtocolFlag_Load | SubGhzProtocolFlag_Save | SubGhzProtocolFlag_Send |
SubGhzProtocolFlag_StarLine,

.decoder = &subghz_protocol_star_line_decoder,
.encoder = &subghz_protocol_star_line_encoder,
Expand Down
Loading