[FL-2669] SubGhz: add support for loading custom presets (#1398)
* SubGhz: load custom -preset * SubGhz: fix error prt=0 * SubGhz: load custom preset * SubGhz: code refactoring to support custom preset * SubGhz: add custom presert refactoring * SubGhz: fix alloc history alloc preset * SubGhz: fix error load file * SubGhz: fix start custom preset * SubGhz: fix delete custom preset * SubGhz: add description Custom_preset_data for CC1101 * SubGhz: debug logging and buffer size rounding Co-authored-by: あく <alleteam@gmail.com> Co-authored-by: Aleksandr Kutuzov <aku@plooks.com>
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "m-string.h"
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
/** SubGhzNotification state */
|
||||
typedef enum {
|
||||
SubGhzNotificationStateStarting,
|
||||
@@ -67,3 +71,12 @@ typedef enum {
|
||||
SubGhzViewIdTestCarrier,
|
||||
SubGhzViewIdTestPacket,
|
||||
} SubGhzViewId;
|
||||
|
||||
struct SubGhzPesetDefinition {
|
||||
string_t name;
|
||||
uint32_t frequency;
|
||||
uint8_t* data;
|
||||
size_t data_size;
|
||||
};
|
||||
|
||||
typedef struct SubGhzPesetDefinition SubGhzPesetDefinition;
|
||||
|
@@ -48,8 +48,12 @@ bool subghz_scene_need_saving_on_event(void* context, SceneManagerEvent event) {
|
||||
} else if(event.event == SubGhzCustomEventSceneExit) {
|
||||
if(subghz->txrx->rx_key_state == SubGhzRxKeyStateExit) {
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
|
||||
subghz->txrx->frequency = subghz_setting_get_default_frequency(subghz->setting);
|
||||
subghz->txrx->preset = FuriHalSubGhzPresetOok650Async;
|
||||
subghz_preset_init(
|
||||
subghz,
|
||||
"AM650",
|
||||
subghz_setting_get_default_frequency(subghz->setting),
|
||||
NULL,
|
||||
0);
|
||||
scene_manager_search_and_switch_to_previous_scene(
|
||||
subghz->scene_manager, SubGhzSceneStart);
|
||||
} else {
|
||||
|
@@ -131,8 +131,12 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving);
|
||||
} else {
|
||||
//Restore default setting
|
||||
subghz->txrx->frequency = subghz_setting_get_default_frequency(subghz->setting);
|
||||
subghz->txrx->preset = FuriHalSubGhzPresetOok650Async;
|
||||
subghz_preset_init(
|
||||
subghz,
|
||||
"AM650",
|
||||
subghz_setting_get_default_frequency(subghz->setting),
|
||||
NULL,
|
||||
0);
|
||||
if(!scene_manager_search_and_switch_to_previous_scene(
|
||||
subghz->scene_manager, SubGhzSceneSaved)) {
|
||||
if(!scene_manager_search_and_switch_to_previous_scene(
|
||||
@@ -268,13 +272,15 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
|
||||
if(subghz_protocol_raw_save_to_file_init(
|
||||
(SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result,
|
||||
RAW_FILE_NAME,
|
||||
subghz->txrx->frequency,
|
||||
subghz->txrx->preset)) {
|
||||
DOLPHIN_DEED(DolphinDeedSubGhzRawRec);
|
||||
if((subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) ||
|
||||
(subghz->txrx->txrx_state == SubGhzTxRxStateSleep)) {
|
||||
subghz_begin(subghz, subghz->txrx->preset);
|
||||
subghz_rx(subghz, subghz->txrx->frequency);
|
||||
subghz_begin(
|
||||
subghz,
|
||||
subghz_setting_get_preset_data_by_name(
|
||||
subghz->setting, string_get_cstr(subghz->txrx->preset->name)));
|
||||
subghz_rx(subghz, subghz->txrx->preset->frequency);
|
||||
}
|
||||
subghz->state_notifications = SubGhzNotificationStateRx;
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey;
|
||||
|
@@ -75,8 +75,7 @@ static void subghz_scene_add_to_history_callback(
|
||||
string_t str_buff;
|
||||
string_init(str_buff);
|
||||
|
||||
if(subghz_history_add_to_history(
|
||||
subghz->txrx->history, decoder_base, subghz->txrx->frequency, subghz->txrx->preset)) {
|
||||
if(subghz_history_add_to_history(subghz->txrx->history, decoder_base, subghz->txrx->preset)) {
|
||||
string_reset(str_buff);
|
||||
|
||||
subghz->state_notifications = SubGhzNotificationStateRxDone;
|
||||
@@ -103,8 +102,8 @@ void subghz_scene_receiver_on_enter(void* context) {
|
||||
string_init(str_buff);
|
||||
|
||||
if(subghz->txrx->rx_key_state == SubGhzRxKeyStateIDLE) {
|
||||
subghz->txrx->frequency = subghz_setting_get_default_frequency(subghz->setting);
|
||||
subghz->txrx->preset = FuriHalSubGhzPresetOok650Async;
|
||||
subghz_preset_init(
|
||||
subghz, "AM650", subghz_setting_get_default_frequency(subghz->setting), NULL, 0);
|
||||
subghz_history_reset(subghz->txrx->history);
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateStart;
|
||||
}
|
||||
@@ -135,8 +134,11 @@ void subghz_scene_receiver_on_enter(void* context) {
|
||||
};
|
||||
if((subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) ||
|
||||
(subghz->txrx->txrx_state == SubGhzTxRxStateSleep)) {
|
||||
subghz_begin(subghz, subghz->txrx->preset);
|
||||
subghz_rx(subghz, subghz->txrx->frequency);
|
||||
subghz_begin(
|
||||
subghz,
|
||||
subghz_setting_get_preset_data_by_name(
|
||||
subghz->setting, string_get_cstr(subghz->txrx->preset->name)));
|
||||
subghz_rx(subghz, subghz->txrx->preset->frequency);
|
||||
}
|
||||
subghz_view_receiver_set_idx_menu(subghz->subghz_receiver, subghz->txrx->idx_menu_chosen);
|
||||
|
||||
@@ -164,8 +166,12 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving);
|
||||
} else {
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
|
||||
subghz->txrx->frequency = subghz_setting_get_default_frequency(subghz->setting);
|
||||
subghz->txrx->preset = FuriHalSubGhzPresetOok650Async;
|
||||
subghz_preset_init(
|
||||
subghz,
|
||||
"AM650",
|
||||
subghz_setting_get_default_frequency(subghz->setting),
|
||||
NULL,
|
||||
0);
|
||||
scene_manager_search_and_switch_to_previous_scene(
|
||||
subghz->scene_manager, SubGhzSceneStart);
|
||||
}
|
||||
|
@@ -7,20 +7,6 @@ enum SubGhzSettingIndex {
|
||||
SubGhzSettingIndexLock,
|
||||
};
|
||||
|
||||
#define PRESET_COUNT 4
|
||||
const char* const preset_text[PRESET_COUNT] = {
|
||||
"AM270",
|
||||
"AM650",
|
||||
"FM238",
|
||||
"FM476",
|
||||
};
|
||||
const uint32_t preset_value[PRESET_COUNT] = {
|
||||
FuriHalSubGhzPresetOok270Async, /** OOK, bandwidth 270kHz, asynchronous */
|
||||
FuriHalSubGhzPresetOok650Async, /** OOK, bandwidth 650kHz, asynchronous */
|
||||
FuriHalSubGhzPreset2FSKDev238Async, /** FM, deviation 2.380371 kHz, asynchronous */
|
||||
FuriHalSubGhzPreset2FSKDev476Async, /** FM, deviation 4.760742 kHz, asynchronous */
|
||||
};
|
||||
|
||||
#define HOPPING_COUNT 2
|
||||
const char* const hopping_text[HOPPING_COUNT] = {
|
||||
"OFF",
|
||||
@@ -31,22 +17,6 @@ const uint32_t hopping_value[HOPPING_COUNT] = {
|
||||
SubGhzHopperStateRunnig,
|
||||
};
|
||||
|
||||
uint8_t subghz_scene_receiver_config_uint32_value_index(
|
||||
const uint32_t value,
|
||||
const uint32_t values[],
|
||||
uint8_t values_count) {
|
||||
int64_t last_value = INT64_MIN;
|
||||
uint8_t index = 0;
|
||||
for(uint8_t i = 0; i < values_count; i++) {
|
||||
if((value >= last_value) && (value <= values[i])) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
last_value = values[i];
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
uint8_t subghz_scene_receiver_config_next_frequency(const uint32_t value, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
@@ -62,6 +32,21 @@ uint8_t subghz_scene_receiver_config_next_frequency(const uint32_t value, void*
|
||||
return index;
|
||||
}
|
||||
|
||||
uint8_t subghz_scene_receiver_config_next_preset(const char* preset_name, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
uint8_t index = 0;
|
||||
for(uint8_t i = 0; i < subghz_setting_get_preset_count(subghz->setting); i++) {
|
||||
if(!strcmp(subghz_setting_get_preset_name(subghz->setting, i), preset_name)) {
|
||||
index = i;
|
||||
break;
|
||||
} else {
|
||||
// index = subghz_setting_get_frequency_default_index(subghz->setting);
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
uint8_t subghz_scene_receiver_config_hopper_value_index(
|
||||
const uint32_t value,
|
||||
const uint32_t values[],
|
||||
@@ -94,7 +79,7 @@ static void subghz_scene_receiver_config_set_frequency(VariableItem* item) {
|
||||
subghz_setting_get_frequency(subghz->setting, index) / 1000000,
|
||||
(subghz_setting_get_frequency(subghz->setting, index) % 1000000) / 10000);
|
||||
variable_item_set_current_value_text(item, text_buf);
|
||||
subghz->txrx->frequency = subghz_setting_get_frequency(subghz->setting, index);
|
||||
subghz->txrx->preset->frequency = subghz_setting_get_frequency(subghz->setting, index);
|
||||
} else {
|
||||
variable_item_set_current_value_index(
|
||||
item, subghz_setting_get_frequency_default_index(subghz->setting));
|
||||
@@ -104,9 +89,14 @@ static void subghz_scene_receiver_config_set_frequency(VariableItem* item) {
|
||||
static void subghz_scene_receiver_config_set_preset(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, preset_text[index]);
|
||||
subghz->txrx->preset = preset_value[index];
|
||||
variable_item_set_current_value_text(
|
||||
item, subghz_setting_get_preset_name(subghz->setting, index));
|
||||
subghz_preset_init(
|
||||
subghz,
|
||||
subghz_setting_get_preset_name(subghz->setting, index),
|
||||
subghz->txrx->preset->frequency,
|
||||
subghz_setting_get_preset_data(subghz->setting, index),
|
||||
subghz_setting_get_preset_data_size(subghz->setting, index));
|
||||
}
|
||||
|
||||
static void subghz_scene_receiver_config_set_hopping_runing(VariableItem* item) {
|
||||
@@ -125,7 +115,7 @@ static void subghz_scene_receiver_config_set_hopping_runing(VariableItem* item)
|
||||
(VariableItem*)scene_manager_get_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneReceiverConfig),
|
||||
text_buf);
|
||||
subghz->txrx->frequency = subghz_setting_get_default_frequency(subghz->setting);
|
||||
subghz->txrx->preset->frequency = subghz_setting_get_default_frequency(subghz->setting);
|
||||
variable_item_set_current_value_index(
|
||||
(VariableItem*)scene_manager_get_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneReceiverConfig),
|
||||
@@ -164,7 +154,8 @@ void subghz_scene_receiver_config_on_enter(void* context) {
|
||||
subghz_setting_get_frequency_count(subghz->setting),
|
||||
subghz_scene_receiver_config_set_frequency,
|
||||
subghz);
|
||||
value_index = subghz_scene_receiver_config_next_frequency(subghz->txrx->frequency, subghz);
|
||||
value_index =
|
||||
subghz_scene_receiver_config_next_frequency(subghz->txrx->preset->frequency, subghz);
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneReceiverConfig, (uint32_t)item);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
@@ -193,13 +184,14 @@ void subghz_scene_receiver_config_on_enter(void* context) {
|
||||
item = variable_item_list_add(
|
||||
subghz->variable_item_list,
|
||||
"Modulation:",
|
||||
PRESET_COUNT,
|
||||
subghz_setting_get_preset_count(subghz->setting),
|
||||
subghz_scene_receiver_config_set_preset,
|
||||
subghz);
|
||||
value_index = subghz_scene_receiver_config_uint32_value_index(
|
||||
subghz->txrx->preset, preset_value, PRESET_COUNT);
|
||||
value_index = subghz_scene_receiver_config_next_preset(
|
||||
string_get_cstr(subghz->txrx->preset->name), subghz);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, preset_text[value_index]);
|
||||
variable_item_set_current_value_text(
|
||||
item, subghz_setting_get_preset_name(subghz->setting, value_index));
|
||||
|
||||
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) !=
|
||||
SubGhzCustomEventManagerSet) {
|
||||
|
@@ -27,10 +27,16 @@ static bool subghz_scene_receiver_info_update_parser(void* context) {
|
||||
subghz_protocol_decoder_base_deserialize(
|
||||
subghz->txrx->decoder_result,
|
||||
subghz_history_get_raw_data(subghz->txrx->history, subghz->txrx->idx_menu_chosen));
|
||||
subghz->txrx->frequency =
|
||||
subghz_history_get_frequency(subghz->txrx->history, subghz->txrx->idx_menu_chosen);
|
||||
subghz->txrx->preset =
|
||||
subghz_history_get_preset(subghz->txrx->history, subghz->txrx->idx_menu_chosen);
|
||||
|
||||
SubGhzPesetDefinition* preset =
|
||||
subghz_history_get_presset(subghz->txrx->history, subghz->txrx->idx_menu_chosen);
|
||||
subghz_preset_init(
|
||||
subghz,
|
||||
string_get_cstr(preset->name),
|
||||
preset->frequency,
|
||||
preset->data,
|
||||
preset->data_size);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -137,8 +143,11 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event)
|
||||
subghz_tx_stop(subghz);
|
||||
}
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) {
|
||||
subghz_begin(subghz, subghz->txrx->preset);
|
||||
subghz_rx(subghz, subghz->txrx->frequency);
|
||||
subghz_begin(
|
||||
subghz,
|
||||
subghz_setting_get_preset_data_by_name(
|
||||
subghz->setting, string_get_cstr(subghz->txrx->preset->name)));
|
||||
subghz_rx(subghz, subghz->txrx->preset->frequency);
|
||||
}
|
||||
if(subghz->txrx->hopper_state == SubGhzHopperStatePause) {
|
||||
subghz->txrx->hopper_state = SubGhzHopperStateRunnig;
|
||||
|
@@ -16,12 +16,13 @@ bool subghz_scene_set_type_submenu_gen_data_protocol(
|
||||
uint64_t key,
|
||||
uint32_t bit,
|
||||
uint32_t frequency,
|
||||
FuriHalSubGhzPreset preset) {
|
||||
const char* preset_name) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
|
||||
bool res = false;
|
||||
|
||||
subghz_preset_init(subghz, preset_name, frequency, NULL, 0);
|
||||
subghz->txrx->decoder_result =
|
||||
subghz_receiver_search_decoder_base_by_name(subghz->txrx->receiver, protocol_name);
|
||||
|
||||
@@ -35,7 +36,7 @@ bool subghz_scene_set_type_submenu_gen_data_protocol(
|
||||
Stream* fff_data_stream = flipper_format_get_raw_stream(subghz->txrx->fff_data);
|
||||
stream_clean(fff_data_stream);
|
||||
if(!subghz_protocol_decoder_base_serialize(
|
||||
subghz->txrx->decoder_result, subghz->txrx->fff_data, frequency, preset)) {
|
||||
subghz->txrx->decoder_result, subghz->txrx->fff_data, subghz->txrx->preset)) {
|
||||
FURI_LOG_E(TAG, "Unable to serialize");
|
||||
break;
|
||||
}
|
||||
@@ -177,12 +178,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
|
||||
case SubmenuIndexPricenton:
|
||||
key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8
|
||||
if(subghz_scene_set_type_submenu_gen_data_protocol(
|
||||
subghz,
|
||||
SUBGHZ_PROTOCOL_PRINCETON_NAME,
|
||||
key,
|
||||
24,
|
||||
433920000,
|
||||
FuriHalSubGhzPresetOok650Async)) {
|
||||
subghz, SUBGHZ_PROTOCOL_PRINCETON_NAME, key, 24, 433920000, "AM650")) {
|
||||
uint32_t te = 400;
|
||||
flipper_format_update_uint32(subghz->txrx->fff_data, "TE", (uint32_t*)&te, 1);
|
||||
generated_protocol = true;
|
||||
@@ -191,60 +187,35 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
|
||||
case SubmenuIndexNiceFlo12bit:
|
||||
key = (key & 0x0000FFF0) | 0x1; //btn 0x1, 0x2, 0x4
|
||||
if(subghz_scene_set_type_submenu_gen_data_protocol(
|
||||
subghz,
|
||||
SUBGHZ_PROTOCOL_NICE_FLO_NAME,
|
||||
key,
|
||||
12,
|
||||
433920000,
|
||||
FuriHalSubGhzPresetOok650Async)) {
|
||||
subghz, SUBGHZ_PROTOCOL_NICE_FLO_NAME, key, 12, 433920000, "AM650")) {
|
||||
generated_protocol = true;
|
||||
}
|
||||
break;
|
||||
case SubmenuIndexNiceFlo24bit:
|
||||
key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8
|
||||
if(subghz_scene_set_type_submenu_gen_data_protocol(
|
||||
subghz,
|
||||
SUBGHZ_PROTOCOL_NICE_FLO_NAME,
|
||||
key,
|
||||
24,
|
||||
433920000,
|
||||
FuriHalSubGhzPresetOok650Async)) {
|
||||
subghz, SUBGHZ_PROTOCOL_NICE_FLO_NAME, key, 24, 433920000, "AM650")) {
|
||||
generated_protocol = true;
|
||||
}
|
||||
break;
|
||||
case SubmenuIndexCAME12bit:
|
||||
key = (key & 0x0000FFF0) | 0x1; //btn 0x1, 0x2, 0x4
|
||||
if(subghz_scene_set_type_submenu_gen_data_protocol(
|
||||
subghz,
|
||||
SUBGHZ_PROTOCOL_CAME_NAME,
|
||||
key,
|
||||
12,
|
||||
433920000,
|
||||
FuriHalSubGhzPresetOok650Async)) {
|
||||
subghz, SUBGHZ_PROTOCOL_CAME_NAME, key, 12, 433920000, "AM650")) {
|
||||
generated_protocol = true;
|
||||
}
|
||||
break;
|
||||
case SubmenuIndexCAME24bit:
|
||||
key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8
|
||||
if(subghz_scene_set_type_submenu_gen_data_protocol(
|
||||
subghz,
|
||||
SUBGHZ_PROTOCOL_CAME_NAME,
|
||||
key,
|
||||
24,
|
||||
433920000,
|
||||
FuriHalSubGhzPresetOok650Async)) {
|
||||
subghz, SUBGHZ_PROTOCOL_CAME_NAME, key, 24, 433920000, "AM650")) {
|
||||
generated_protocol = true;
|
||||
}
|
||||
break;
|
||||
case SubmenuIndexLinear_300_00:
|
||||
key = (key & 0x3FF);
|
||||
if(subghz_scene_set_type_submenu_gen_data_protocol(
|
||||
subghz,
|
||||
SUBGHZ_PROTOCOL_LINEAR_NAME,
|
||||
key,
|
||||
10,
|
||||
300000000,
|
||||
FuriHalSubGhzPresetOok650Async)) {
|
||||
subghz, SUBGHZ_PROTOCOL_LINEAR_NAME, key, 10, 300000000, "AM650")) {
|
||||
generated_protocol = true;
|
||||
}
|
||||
break;
|
||||
@@ -252,12 +223,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
|
||||
key = (key & 0x0FFFFFF0);
|
||||
key = 0x003FFF7200000000 | (key ^ 0xE0E0E0EE);
|
||||
if(subghz_scene_set_type_submenu_gen_data_protocol(
|
||||
subghz,
|
||||
SUBGHZ_PROTOCOL_CAME_TWEE_NAME,
|
||||
key,
|
||||
54,
|
||||
433920000,
|
||||
FuriHalSubGhzPresetOok650Async)) {
|
||||
subghz, SUBGHZ_PROTOCOL_CAME_TWEE_NAME, key, 54, 433920000, "AM650")) {
|
||||
generated_protocol = true;
|
||||
}
|
||||
break;
|
||||
@@ -271,18 +237,15 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
|
||||
key = (key & 0x00F0FF00) | 0xF << 16 | 0x40; //btn 0xF, 0xC, 0xA, 0x6 (?)
|
||||
uint64_t rev_key = subghz_protocol_blocks_reverse_key(key, 24);
|
||||
if(subghz_scene_set_type_submenu_gen_data_protocol(
|
||||
subghz,
|
||||
SUBGHZ_PROTOCOL_GATE_TX_NAME,
|
||||
rev_key,
|
||||
24,
|
||||
433920000,
|
||||
FuriHalSubGhzPresetOok650Async)) {
|
||||
subghz, SUBGHZ_PROTOCOL_GATE_TX_NAME, rev_key, 24, 433920000, "AM650")) {
|
||||
generated_protocol = true;
|
||||
}
|
||||
break;
|
||||
case SubmenuIndexDoorHan_433_92:
|
||||
subghz->txrx->transmitter = subghz_transmitter_alloc_init(
|
||||
subghz->txrx->environment, SUBGHZ_PROTOCOL_KEELOQ_NAME);
|
||||
subghz_preset_init(
|
||||
subghz, "AM650", subghz_setting_get_default_frequency(subghz->setting), NULL, 0);
|
||||
if(subghz->txrx->transmitter) {
|
||||
subghz_protocol_keeloq_create_data(
|
||||
subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter),
|
||||
@@ -291,8 +254,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
|
||||
0x2,
|
||||
0x0003,
|
||||
"DoorHan",
|
||||
subghz_setting_get_default_frequency(subghz->setting),
|
||||
FuriHalSubGhzPresetOok650Async);
|
||||
subghz->txrx->preset);
|
||||
generated_protocol = true;
|
||||
} else {
|
||||
generated_protocol = false;
|
||||
@@ -307,6 +269,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
|
||||
case SubmenuIndexDoorHan_315_00:
|
||||
subghz->txrx->transmitter = subghz_transmitter_alloc_init(
|
||||
subghz->txrx->environment, SUBGHZ_PROTOCOL_KEELOQ_NAME);
|
||||
subghz_preset_init(subghz, "AM650", 315000000, NULL, 0);
|
||||
if(subghz->txrx->transmitter) {
|
||||
subghz_protocol_keeloq_create_data(
|
||||
subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter),
|
||||
@@ -315,8 +278,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
|
||||
0x2,
|
||||
0x0003,
|
||||
"DoorHan",
|
||||
315000000,
|
||||
FuriHalSubGhzPresetOok650Async);
|
||||
subghz->txrx->preset);
|
||||
generated_protocol = true;
|
||||
} else {
|
||||
generated_protocol = false;
|
||||
@@ -338,7 +300,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
|
||||
(uint64_t)key << 32 | 0xE6000000,
|
||||
42,
|
||||
315000000,
|
||||
FuriHalSubGhzPresetOok650Async)) {
|
||||
"AM650")) {
|
||||
generated_protocol = true;
|
||||
}
|
||||
break;
|
||||
@@ -352,13 +314,14 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
|
||||
(uint64_t)key << 32 | 0xE6000000,
|
||||
42,
|
||||
390000000,
|
||||
FuriHalSubGhzPresetOok650Async)) {
|
||||
"AM650")) {
|
||||
generated_protocol = true;
|
||||
}
|
||||
break;
|
||||
case SubmenuIndexSecPlus_v2_310_00:
|
||||
subghz->txrx->transmitter = subghz_transmitter_alloc_init(
|
||||
subghz->txrx->environment, SUBGHZ_PROTOCOL_SECPLUS_V2_NAME);
|
||||
subghz_preset_init(subghz, "AM650", 310000000, NULL, 0);
|
||||
if(subghz->txrx->transmitter) {
|
||||
subghz_protocol_secplus_v2_create_data(
|
||||
subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter),
|
||||
@@ -366,8 +329,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
|
||||
key,
|
||||
0x68,
|
||||
0xE500000,
|
||||
310000000,
|
||||
FuriHalSubGhzPresetOok650Async);
|
||||
subghz->txrx->preset);
|
||||
generated_protocol = true;
|
||||
} else {
|
||||
generated_protocol = false;
|
||||
@@ -377,6 +339,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
|
||||
case SubmenuIndexSecPlus_v2_315_00:
|
||||
subghz->txrx->transmitter = subghz_transmitter_alloc_init(
|
||||
subghz->txrx->environment, SUBGHZ_PROTOCOL_SECPLUS_V2_NAME);
|
||||
subghz_preset_init(subghz, "AM650", 315000000, NULL, 0);
|
||||
if(subghz->txrx->transmitter) {
|
||||
subghz_protocol_secplus_v2_create_data(
|
||||
subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter),
|
||||
@@ -384,8 +347,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
|
||||
key,
|
||||
0x68,
|
||||
0xE500000,
|
||||
315000000,
|
||||
FuriHalSubGhzPresetOok650Async);
|
||||
subghz->txrx->preset);
|
||||
generated_protocol = true;
|
||||
} else {
|
||||
generated_protocol = false;
|
||||
@@ -395,6 +357,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
|
||||
case SubmenuIndexSecPlus_v2_390_00:
|
||||
subghz->txrx->transmitter = subghz_transmitter_alloc_init(
|
||||
subghz->txrx->environment, SUBGHZ_PROTOCOL_SECPLUS_V2_NAME);
|
||||
subghz_preset_init(subghz, "AM650", 390000000, NULL, 0);
|
||||
if(subghz->txrx->transmitter) {
|
||||
subghz_protocol_secplus_v2_create_data(
|
||||
subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter),
|
||||
@@ -402,8 +365,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
|
||||
key,
|
||||
0x68,
|
||||
0xE500000,
|
||||
390000000,
|
||||
FuriHalSubGhzPresetOok650Async);
|
||||
subghz->txrx->preset);
|
||||
generated_protocol = true;
|
||||
} else {
|
||||
generated_protocol = false;
|
||||
|
@@ -199,8 +199,11 @@ SubGhz* subghz_alloc() {
|
||||
//init Worker & Protocol & History & KeyBoard
|
||||
subghz->lock = SubGhzLockOff;
|
||||
subghz->txrx = malloc(sizeof(SubGhzTxRx));
|
||||
subghz->txrx->frequency = subghz_setting_get_default_frequency(subghz->setting);
|
||||
subghz->txrx->preset = FuriHalSubGhzPresetOok650Async;
|
||||
subghz->txrx->preset = malloc(sizeof(SubGhzPesetDefinition));
|
||||
string_init(subghz->txrx->preset->name);
|
||||
subghz_preset_init(
|
||||
subghz, "AM650", subghz_setting_get_default_frequency(subghz->setting), NULL, 0);
|
||||
|
||||
subghz->txrx->txrx_state = SubGhzTxRxStateSleep;
|
||||
subghz->txrx->hopper_state = SubGhzHopperStateOFF;
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
|
||||
@@ -308,6 +311,8 @@ void subghz_free(SubGhz* subghz) {
|
||||
subghz_worker_free(subghz->txrx->worker);
|
||||
flipper_format_free(subghz->txrx->fff_data);
|
||||
subghz_history_free(subghz->txrx->history);
|
||||
string_clear(subghz->txrx->preset->name);
|
||||
free(subghz->txrx->preset);
|
||||
free(subghz->txrx);
|
||||
|
||||
//Error string
|
||||
|
@@ -12,8 +12,7 @@ typedef struct {
|
||||
string_t item_str;
|
||||
FlipperFormat* flipper_string;
|
||||
uint8_t type;
|
||||
FuriHalSubGhzPreset preset;
|
||||
uint32_t frequency;
|
||||
SubGhzPesetDefinition* preset;
|
||||
} SubGhzHistoryItem;
|
||||
|
||||
ARRAY_DEF(SubGhzHistoryItemArray, SubGhzHistoryItem, M_POD_OPLIST)
|
||||
@@ -46,6 +45,8 @@ void subghz_history_free(SubGhzHistory* instance) {
|
||||
for
|
||||
M_EACH(item, instance->history->data, SubGhzHistoryItemArray_t) {
|
||||
string_clear(item->item_str);
|
||||
string_clear(item->preset->name);
|
||||
free(item->preset);
|
||||
flipper_format_free(item->flipper_string);
|
||||
item->type = 0;
|
||||
}
|
||||
@@ -57,21 +58,29 @@ void subghz_history_free(SubGhzHistory* instance) {
|
||||
uint32_t subghz_history_get_frequency(SubGhzHistory* instance, uint16_t idx) {
|
||||
furi_assert(instance);
|
||||
SubGhzHistoryItem* item = SubGhzHistoryItemArray_get(instance->history->data, idx);
|
||||
return item->frequency;
|
||||
return item->preset->frequency;
|
||||
}
|
||||
|
||||
FuriHalSubGhzPreset subghz_history_get_preset(SubGhzHistory* instance, uint16_t idx) {
|
||||
SubGhzPesetDefinition* subghz_history_get_presset(SubGhzHistory* instance, uint16_t idx) {
|
||||
furi_assert(instance);
|
||||
SubGhzHistoryItem* item = SubGhzHistoryItemArray_get(instance->history->data, idx);
|
||||
return item->preset;
|
||||
}
|
||||
|
||||
const char* subghz_history_get_preset(SubGhzHistory* instance, uint16_t idx) {
|
||||
furi_assert(instance);
|
||||
SubGhzHistoryItem* item = SubGhzHistoryItemArray_get(instance->history->data, idx);
|
||||
return string_get_cstr(item->preset->name);
|
||||
}
|
||||
|
||||
void subghz_history_reset(SubGhzHistory* instance) {
|
||||
furi_assert(instance);
|
||||
string_reset(instance->tmp_string);
|
||||
for
|
||||
M_EACH(item, instance->history->data, SubGhzHistoryItemArray_t) {
|
||||
string_clear(item->item_str);
|
||||
string_clear(item->preset->name);
|
||||
free(item->preset);
|
||||
flipper_format_free(item->flipper_string);
|
||||
item->type = 0;
|
||||
}
|
||||
@@ -130,8 +139,7 @@ void subghz_history_get_text_item_menu(SubGhzHistory* instance, string_t output,
|
||||
bool subghz_history_add_to_history(
|
||||
SubGhzHistory* instance,
|
||||
void* context,
|
||||
uint32_t frequency,
|
||||
FuriHalSubGhzPreset preset) {
|
||||
SubGhzPesetDefinition* preset) {
|
||||
furi_assert(instance);
|
||||
furi_assert(context);
|
||||
|
||||
@@ -151,13 +159,17 @@ bool subghz_history_add_to_history(
|
||||
string_t text;
|
||||
string_init(text);
|
||||
SubGhzHistoryItem* item = SubGhzHistoryItemArray_push_raw(instance->history->data);
|
||||
item->preset = malloc(sizeof(SubGhzPesetDefinition));
|
||||
item->type = decoder_base->protocol->type;
|
||||
item->frequency = frequency;
|
||||
item->preset = preset;
|
||||
item->preset->frequency = preset->frequency;
|
||||
string_init(item->preset->name);
|
||||
string_set(item->preset->name, preset->name);
|
||||
item->preset->data = preset->data;
|
||||
item->preset->data_size = preset->data_size;
|
||||
|
||||
string_init(item->item_str);
|
||||
item->flipper_string = flipper_format_string_alloc();
|
||||
subghz_protocol_decoder_base_serialize(decoder_base, item->flipper_string, frequency, preset);
|
||||
subghz_protocol_decoder_base_serialize(decoder_base, item->flipper_string, preset);
|
||||
|
||||
do {
|
||||
if(!flipper_format_rewind(item->flipper_string)) {
|
||||
|
@@ -5,6 +5,7 @@
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <lib/flipper_format/flipper_format.h>
|
||||
#include "helpers/subghz_types.h"
|
||||
|
||||
typedef struct SubGhzHistory SubGhzHistory;
|
||||
|
||||
@@ -34,13 +35,15 @@ void subghz_history_reset(SubGhzHistory* instance);
|
||||
*/
|
||||
uint32_t subghz_history_get_frequency(SubGhzHistory* instance, uint16_t idx);
|
||||
|
||||
SubGhzPesetDefinition* subghz_history_get_presset(SubGhzHistory* instance, uint16_t idx);
|
||||
|
||||
/** Get preset to history[idx]
|
||||
*
|
||||
* @param instance - SubGhzHistory instance
|
||||
* @param idx - record index
|
||||
* @return preset - FuriHalSubGhzPreset preset
|
||||
* @return preset - preset name
|
||||
*/
|
||||
FuriHalSubGhzPreset subghz_history_get_preset(SubGhzHistory* instance, uint16_t idx);
|
||||
const char* subghz_history_get_preset(SubGhzHistory* instance, uint16_t idx);
|
||||
|
||||
/** Get history index write
|
||||
*
|
||||
@@ -85,15 +88,13 @@ bool subghz_history_get_text_space_left(SubGhzHistory* instance, string_t output
|
||||
*
|
||||
* @param instance - SubGhzHistory instance
|
||||
* @param context - SubGhzProtocolCommon context
|
||||
* @param frequency - frequency Hz
|
||||
* @param preset - FuriHalSubGhzPreset preset
|
||||
* @param preset - SubGhzPesetDefinition preset
|
||||
* @return bool;
|
||||
*/
|
||||
bool subghz_history_add_to_history(
|
||||
SubGhzHistory* instance,
|
||||
void* context,
|
||||
uint32_t frequency,
|
||||
FuriHalSubGhzPreset preset);
|
||||
SubGhzPesetDefinition* preset);
|
||||
|
||||
/** Get SubGhzProtocolCommonLoad to load into the protocol decoder bin data
|
||||
*
|
||||
|
@@ -1,7 +1,6 @@
|
||||
#include "subghz_i.h"
|
||||
|
||||
#include "assets_icons.h"
|
||||
#include "m-string.h"
|
||||
#include "subghz/types.h"
|
||||
#include <math.h>
|
||||
#include <furi.h>
|
||||
@@ -19,15 +18,31 @@
|
||||
|
||||
#define TAG "SubGhz"
|
||||
|
||||
void subghz_preset_init(
|
||||
void* context,
|
||||
const char* preset_name,
|
||||
uint32_t frequency,
|
||||
uint8_t* preset_data,
|
||||
size_t preset_data_size) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
string_set(subghz->txrx->preset->name, preset_name);
|
||||
subghz->txrx->preset->frequency = frequency;
|
||||
subghz->txrx->preset->data = preset_data;
|
||||
subghz->txrx->preset->data_size = preset_data_size;
|
||||
}
|
||||
|
||||
bool subghz_set_preset(SubGhz* subghz, const char* preset) {
|
||||
if(!strcmp(preset, "FuriHalSubGhzPresetOok270Async")) {
|
||||
subghz->txrx->preset = FuriHalSubGhzPresetOok270Async;
|
||||
string_set(subghz->txrx->preset->name, "AM270");
|
||||
} else if(!strcmp(preset, "FuriHalSubGhzPresetOok650Async")) {
|
||||
subghz->txrx->preset = FuriHalSubGhzPresetOok650Async;
|
||||
string_set(subghz->txrx->preset->name, "AM650");
|
||||
} else if(!strcmp(preset, "FuriHalSubGhzPreset2FSKDev238Async")) {
|
||||
subghz->txrx->preset = FuriHalSubGhzPreset2FSKDev238Async;
|
||||
string_set(subghz->txrx->preset->name, "FM238");
|
||||
} else if(!strcmp(preset, "FuriHalSubGhzPreset2FSKDev476Async")) {
|
||||
subghz->txrx->preset = FuriHalSubGhzPreset2FSKDev476Async;
|
||||
string_set(subghz->txrx->preset->name, "FM476");
|
||||
} else if(!strcmp(preset, "FuriHalSubGhzPresetCustom")) {
|
||||
string_set(subghz->txrx->preset->name, "CUSTOM");
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "Unknown preset");
|
||||
return false;
|
||||
@@ -41,29 +56,19 @@ void subghz_get_frequency_modulation(SubGhz* subghz, string_t frequency, string_
|
||||
string_printf(
|
||||
frequency,
|
||||
"%03ld.%02ld",
|
||||
subghz->txrx->frequency / 1000000 % 1000,
|
||||
subghz->txrx->frequency / 10000 % 100);
|
||||
subghz->txrx->preset->frequency / 1000000 % 1000,
|
||||
subghz->txrx->preset->frequency / 10000 % 100);
|
||||
}
|
||||
|
||||
if(modulation != NULL) {
|
||||
if(subghz->txrx->preset == FuriHalSubGhzPresetOok650Async ||
|
||||
subghz->txrx->preset == FuriHalSubGhzPresetOok270Async) {
|
||||
string_set_str(modulation, "AM");
|
||||
} else if(
|
||||
subghz->txrx->preset == FuriHalSubGhzPreset2FSKDev238Async ||
|
||||
subghz->txrx->preset == FuriHalSubGhzPreset2FSKDev476Async) {
|
||||
string_set_str(modulation, "FM");
|
||||
} else {
|
||||
furi_crash("SubGhz: Modulation is incorrect.");
|
||||
}
|
||||
string_printf(modulation, "%0.2s", string_get_cstr(subghz->txrx->preset->name));
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_begin(SubGhz* subghz, FuriHalSubGhzPreset preset) {
|
||||
void subghz_begin(SubGhz* subghz, uint8_t* preset_data) {
|
||||
furi_assert(subghz);
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_idle();
|
||||
furi_hal_subghz_load_preset(preset);
|
||||
furi_hal_subghz_load_custom_preset(preset_data);
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
subghz->txrx->txrx_state = SubGhzTxRxStateIDLE;
|
||||
}
|
||||
@@ -155,13 +160,21 @@ bool subghz_tx_start(SubGhz* subghz, FlipperFormat* flipper_format) {
|
||||
|
||||
if(subghz->txrx->transmitter) {
|
||||
if(subghz_transmitter_deserialize(subghz->txrx->transmitter, flipper_format)) {
|
||||
if(subghz->txrx->preset) {
|
||||
subghz_begin(subghz, subghz->txrx->preset);
|
||||
if(strcmp(string_get_cstr(subghz->txrx->preset->name), "")) {
|
||||
subghz_begin(
|
||||
subghz,
|
||||
subghz_setting_get_preset_data_by_name(
|
||||
subghz->setting, string_get_cstr(subghz->txrx->preset->name)));
|
||||
} else {
|
||||
subghz_begin(subghz, FuriHalSubGhzPresetOok270Async);
|
||||
FURI_LOG_E(
|
||||
TAG,
|
||||
"Unknown name preset \" %s \"",
|
||||
string_get_cstr(subghz->txrx->preset->name));
|
||||
subghz_begin(
|
||||
subghz, subghz_setting_get_preset_data_by_name(subghz->setting, "AM650"));
|
||||
}
|
||||
if(subghz->txrx->frequency) {
|
||||
ret = subghz_tx(subghz, subghz->txrx->frequency);
|
||||
if(subghz->txrx->preset->frequency) {
|
||||
ret = subghz_tx(subghz, subghz->txrx->preset->frequency);
|
||||
} else {
|
||||
ret = subghz_tx(subghz, 433920000);
|
||||
}
|
||||
@@ -270,16 +283,38 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) {
|
||||
load_key_state = SubGhzLoadKeyStateOnlyRx;
|
||||
break;
|
||||
}
|
||||
subghz->txrx->frequency = temp_data32;
|
||||
subghz->txrx->preset->frequency = temp_data32;
|
||||
|
||||
if(!flipper_format_read_string(fff_data_file, "Preset", temp_str)) {
|
||||
FURI_LOG_E(TAG, "Missing Preset");
|
||||
break;
|
||||
}
|
||||
|
||||
if(!subghz_set_preset(subghz, string_get_cstr(temp_str))) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(!strcmp(string_get_cstr(temp_str), "FuriHalSubGhzPresetCustom")) {
|
||||
//Todo add Custom_preset_module
|
||||
//delete peset if it already exists
|
||||
subghz_setting_delete_custom_preset(
|
||||
subghz->setting, string_get_cstr(subghz->txrx->preset->name));
|
||||
//load custom preset from file
|
||||
if(!subghz_setting_load_custom_preset(
|
||||
subghz->setting, string_get_cstr(subghz->txrx->preset->name), fff_data_file)) {
|
||||
FURI_LOG_E(TAG, "Missing Custom preset");
|
||||
break;
|
||||
}
|
||||
}
|
||||
size_t preset_index = subghz_setting_get_inx_preset_by_name(
|
||||
subghz->setting, string_get_cstr(subghz->txrx->preset->name));
|
||||
subghz_preset_init(
|
||||
subghz,
|
||||
string_get_cstr(subghz->txrx->preset->name),
|
||||
subghz->txrx->preset->frequency,
|
||||
subghz_setting_get_preset_data(subghz->setting, preset_index),
|
||||
subghz_setting_get_preset_data_size(subghz->setting, preset_index));
|
||||
|
||||
if(!flipper_format_read_string(fff_data_file, "Protocol", temp_str)) {
|
||||
FURI_LOG_E(TAG, "Missing Protocol");
|
||||
break;
|
||||
@@ -541,8 +576,8 @@ void subghz_hopper_update(SubGhz* subghz) {
|
||||
};
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) {
|
||||
subghz_receiver_reset(subghz->txrx->receiver);
|
||||
subghz->txrx->frequency = subghz_setting_get_hopper_frequency(
|
||||
subghz->txrx->preset->frequency = subghz_setting_get_hopper_frequency(
|
||||
subghz->setting, subghz->txrx->hopper_idx_frequency);
|
||||
subghz_rx(subghz, subghz->txrx->frequency);
|
||||
subghz_rx(subghz, subghz->txrx->preset->frequency);
|
||||
}
|
||||
}
|
||||
|
@@ -11,8 +11,8 @@
|
||||
#include "views/subghz_test_carrier.h"
|
||||
#include "views/subghz_test_packet.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
// #include <furi.h>
|
||||
// #include <furi_hal.h>
|
||||
#include <gui/gui.h>
|
||||
#include <dialogs/dialogs.h>
|
||||
#include <gui/scene_manager.h>
|
||||
@@ -49,8 +49,7 @@ struct SubGhzTxRx {
|
||||
SubGhzProtocolDecoderBase* decoder_result;
|
||||
FlipperFormat* fff_data;
|
||||
|
||||
uint32_t frequency;
|
||||
FuriHalSubGhzPreset preset;
|
||||
SubGhzPesetDefinition* preset;
|
||||
SubGhzHistory* history;
|
||||
uint16_t idx_menu_chosen;
|
||||
SubGhzTxRxState txrx_state;
|
||||
@@ -97,9 +96,15 @@ struct SubGhz {
|
||||
void* rpc_ctx;
|
||||
};
|
||||
|
||||
void subghz_preset_init(
|
||||
void* context,
|
||||
const char* preset_name,
|
||||
uint32_t frequency,
|
||||
uint8_t* preset_data,
|
||||
size_t preset_data_size);
|
||||
bool subghz_set_preset(SubGhz* subghz, const char* preset);
|
||||
void subghz_get_frequency_modulation(SubGhz* subghz, string_t frequency, string_t modulation);
|
||||
void subghz_begin(SubGhz* subghz, FuriHalSubGhzPreset preset);
|
||||
void subghz_begin(SubGhz* subghz, uint8_t* preset_data);
|
||||
uint32_t subghz_rx(SubGhz* subghz, uint32_t frequency);
|
||||
void subghz_rx_end(SubGhz* subghz);
|
||||
void subghz_sleep(SubGhz* subghz);
|
||||
|
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <furi.h>
|
||||
#include <m-list.h>
|
||||
#include <lib/flipper_format/flipper_format.h>
|
||||
#include "furi_hal_subghz_configs.h"
|
||||
|
||||
#define TAG "SubGhzSetting"
|
||||
|
||||
@@ -157,29 +157,89 @@ static const uint32_t subghz_hopper_frequency_list_region_jp[] = {
|
||||
0,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
string_t custom_preset_name;
|
||||
uint8_t* custom_preset_data;
|
||||
size_t custom_preset_data_size;
|
||||
} SubGhzSettingCustomPresetItem;
|
||||
|
||||
ARRAY_DEF(SubGhzSettingCustomPresetItemArray, SubGhzSettingCustomPresetItem, M_POD_OPLIST)
|
||||
|
||||
#define M_OPL_SubGhzSettingCustomPresetItemArray_t() \
|
||||
ARRAY_OPLIST(SubGhzSettingCustomPresetItemArray, M_POD_OPLIST)
|
||||
|
||||
LIST_DEF(FrequencyList, uint32_t)
|
||||
|
||||
#define M_OPL_FrequencyList_t() LIST_OPLIST(FrequencyList)
|
||||
|
||||
typedef struct {
|
||||
SubGhzSettingCustomPresetItemArray_t data;
|
||||
} SubGhzSettingCustomPresetStruct;
|
||||
|
||||
struct SubGhzSetting {
|
||||
FrequencyList_t frequencies;
|
||||
FrequencyList_t hopper_frequencies;
|
||||
SubGhzSettingCustomPresetStruct* preset;
|
||||
};
|
||||
|
||||
SubGhzSetting* subghz_setting_alloc(void) {
|
||||
SubGhzSetting* instance = malloc(sizeof(SubGhzSetting));
|
||||
FrequencyList_init(instance->frequencies);
|
||||
FrequencyList_init(instance->hopper_frequencies);
|
||||
instance->preset = malloc(sizeof(SubGhzSettingCustomPresetStruct));
|
||||
SubGhzSettingCustomPresetItemArray_init(instance->preset->data);
|
||||
return instance;
|
||||
}
|
||||
|
||||
static void subghz_setting_preset_reset(SubGhzSetting* instance) {
|
||||
for
|
||||
M_EACH(item, instance->preset->data, SubGhzSettingCustomPresetItemArray_t) {
|
||||
string_clear(item->custom_preset_name);
|
||||
free(item->custom_preset_data);
|
||||
}
|
||||
SubGhzSettingCustomPresetItemArray_reset(instance->preset->data);
|
||||
}
|
||||
|
||||
void subghz_setting_free(SubGhzSetting* instance) {
|
||||
furi_assert(instance);
|
||||
FrequencyList_clear(instance->frequencies);
|
||||
FrequencyList_clear(instance->hopper_frequencies);
|
||||
for
|
||||
M_EACH(item, instance->preset->data, SubGhzSettingCustomPresetItemArray_t) {
|
||||
string_clear(item->custom_preset_name);
|
||||
free(item->custom_preset_data);
|
||||
}
|
||||
SubGhzSettingCustomPresetItemArray_clear(instance->preset->data);
|
||||
free(instance->preset);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
static void subghz_setting_load_default_preset(
|
||||
SubGhzSetting* instance,
|
||||
const char* preset_name,
|
||||
const uint8_t* preset_data,
|
||||
const uint8_t preset_pa_table[8]) {
|
||||
furi_assert(instance);
|
||||
furi_assert(preset_data);
|
||||
uint32_t preset_data_count = 0;
|
||||
SubGhzSettingCustomPresetItem* item =
|
||||
SubGhzSettingCustomPresetItemArray_push_raw(instance->preset->data);
|
||||
|
||||
string_init(item->custom_preset_name);
|
||||
string_set(item->custom_preset_name, preset_name);
|
||||
|
||||
while(preset_data[preset_data_count]) {
|
||||
preset_data_count += 2;
|
||||
}
|
||||
preset_data_count += 2;
|
||||
item->custom_preset_data_size = sizeof(uint8_t) * preset_data_count + sizeof(uint8_t) * 8;
|
||||
item->custom_preset_data = malloc(item->custom_preset_data_size);
|
||||
//load preset register
|
||||
memcpy(&item->custom_preset_data[0], &preset_data[0], preset_data_count);
|
||||
//load pa table
|
||||
memcpy(&item->custom_preset_data[preset_data_count], &preset_pa_table[0], 8);
|
||||
}
|
||||
|
||||
static void subghz_setting_load_default_region(
|
||||
SubGhzSetting* instance,
|
||||
const uint32_t frequencies[],
|
||||
@@ -188,6 +248,7 @@ static void subghz_setting_load_default_region(
|
||||
|
||||
FrequencyList_reset(instance->frequencies);
|
||||
FrequencyList_reset(instance->hopper_frequencies);
|
||||
subghz_setting_preset_reset(instance);
|
||||
|
||||
while(*frequencies) {
|
||||
FrequencyList_push_back(instance->frequencies, *frequencies);
|
||||
@@ -198,6 +259,27 @@ static void subghz_setting_load_default_region(
|
||||
FrequencyList_push_back(instance->hopper_frequencies, *hopper_frequencies);
|
||||
hopper_frequencies++;
|
||||
}
|
||||
|
||||
subghz_setting_load_default_preset(
|
||||
instance,
|
||||
"AM270",
|
||||
(uint8_t*)furi_hal_subghz_preset_ook_270khz_async_regs,
|
||||
furi_hal_subghz_preset_ook_async_patable);
|
||||
subghz_setting_load_default_preset(
|
||||
instance,
|
||||
"AM650",
|
||||
(uint8_t*)furi_hal_subghz_preset_ook_650khz_async_regs,
|
||||
furi_hal_subghz_preset_ook_async_patable);
|
||||
subghz_setting_load_default_preset(
|
||||
instance,
|
||||
"FM238",
|
||||
(uint8_t*)furi_hal_subghz_preset_2fsk_dev2_38khz_async_regs,
|
||||
furi_hal_subghz_preset_2fsk_async_patable);
|
||||
subghz_setting_load_default_preset(
|
||||
instance,
|
||||
"FM476",
|
||||
(uint8_t*)furi_hal_subghz_preset_2fsk_dev47_6khz_async_regs,
|
||||
furi_hal_subghz_preset_2fsk_async_patable);
|
||||
}
|
||||
|
||||
void subghz_setting_load_default(SubGhzSetting* instance) {
|
||||
@@ -260,7 +342,7 @@ void subghz_setting_load(SubGhzSetting* instance, const char* file_path) {
|
||||
|
||||
// Standard frequencies (optional)
|
||||
temp_bool = true;
|
||||
flipper_format_read_bool(fff_data_file, "add_standard_frequencies", &temp_bool, 1);
|
||||
flipper_format_read_bool(fff_data_file, "Add_standard_frequencies", &temp_bool, 1);
|
||||
if(!temp_bool) {
|
||||
FURI_LOG_I(TAG, "Removing standard frequencies");
|
||||
FrequencyList_reset(instance->frequencies);
|
||||
@@ -275,7 +357,7 @@ void subghz_setting_load(SubGhzSetting* instance, const char* file_path) {
|
||||
break;
|
||||
}
|
||||
while(flipper_format_read_uint32(
|
||||
fff_data_file, "frequency", (uint32_t*)&temp_data32, 1)) {
|
||||
fff_data_file, "Frequency", (uint32_t*)&temp_data32, 1)) {
|
||||
if(furi_hal_subghz_is_frequency_valid(temp_data32)) {
|
||||
FURI_LOG_I(TAG, "Frequency loaded %lu", temp_data32);
|
||||
FrequencyList_push_back(instance->frequencies, temp_data32);
|
||||
@@ -290,7 +372,7 @@ void subghz_setting_load(SubGhzSetting* instance, const char* file_path) {
|
||||
break;
|
||||
}
|
||||
while(flipper_format_read_uint32(
|
||||
fff_data_file, "hopper_frequency", (uint32_t*)&temp_data32, 1)) {
|
||||
fff_data_file, "Hopper_frequency", (uint32_t*)&temp_data32, 1)) {
|
||||
if(furi_hal_subghz_is_frequency_valid(temp_data32)) {
|
||||
FURI_LOG_I(TAG, "Hopper frequency loaded %lu", temp_data32);
|
||||
FrequencyList_push_back(instance->hopper_frequencies, temp_data32);
|
||||
@@ -304,7 +386,7 @@ void subghz_setting_load(SubGhzSetting* instance, const char* file_path) {
|
||||
FURI_LOG_E(TAG, "Rewind error");
|
||||
break;
|
||||
}
|
||||
if(flipper_format_read_uint32(fff_data_file, "default_frequency", &temp_data32, 1)) {
|
||||
if(flipper_format_read_uint32(fff_data_file, "Default_frequency", &temp_data32, 1)) {
|
||||
for
|
||||
M_EACH(frequency, instance->frequencies, FrequencyList_t) {
|
||||
*frequency &= FREQUENCY_MASK;
|
||||
@@ -313,6 +395,18 @@ void subghz_setting_load(SubGhzSetting* instance, const char* file_path) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// custom preset (optional)
|
||||
if(!flipper_format_rewind(fff_data_file)) {
|
||||
FURI_LOG_E(TAG, "Rewind error");
|
||||
break;
|
||||
}
|
||||
while(flipper_format_read_string(fff_data_file, "Custom_preset_name", temp_str)) {
|
||||
FURI_LOG_I(TAG, "Custom preset loaded %s", string_get_cstr(temp_str));
|
||||
subghz_setting_load_custom_preset(
|
||||
instance, string_get_cstr(temp_str), fff_data_file);
|
||||
}
|
||||
|
||||
} while(false);
|
||||
}
|
||||
|
||||
@@ -337,6 +431,104 @@ size_t subghz_setting_get_hopper_frequency_count(SubGhzSetting* instance) {
|
||||
return FrequencyList_size(instance->hopper_frequencies);
|
||||
}
|
||||
|
||||
size_t subghz_setting_get_preset_count(SubGhzSetting* instance) {
|
||||
furi_assert(instance);
|
||||
return SubGhzSettingCustomPresetItemArray_size(instance->preset->data);
|
||||
}
|
||||
|
||||
const char* subghz_setting_get_preset_name(SubGhzSetting* instance, size_t idx) {
|
||||
furi_assert(instance);
|
||||
SubGhzSettingCustomPresetItem* item =
|
||||
SubGhzSettingCustomPresetItemArray_get(instance->preset->data, idx);
|
||||
return string_get_cstr(item->custom_preset_name);
|
||||
}
|
||||
|
||||
int subghz_setting_get_inx_preset_by_name(SubGhzSetting* instance, const char* preset_name) {
|
||||
furi_assert(instance);
|
||||
size_t idx = 0;
|
||||
for
|
||||
M_EACH(item, instance->preset->data, SubGhzSettingCustomPresetItemArray_t) {
|
||||
if(strcmp(string_get_cstr(item->custom_preset_name), preset_name) == 0) {
|
||||
return idx;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
furi_crash("SubGhz: No name preset.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool subghz_setting_load_custom_preset(
|
||||
SubGhzSetting* instance,
|
||||
const char* preset_name,
|
||||
FlipperFormat* fff_data_file) {
|
||||
furi_assert(instance);
|
||||
furi_assert(preset_name);
|
||||
uint32_t temp_data32;
|
||||
SubGhzSettingCustomPresetItem* item =
|
||||
SubGhzSettingCustomPresetItemArray_push_raw(instance->preset->data);
|
||||
string_init(item->custom_preset_name);
|
||||
string_set(item->custom_preset_name, preset_name);
|
||||
do {
|
||||
if(!flipper_format_get_value_count(fff_data_file, "Custom_preset_data", &temp_data32))
|
||||
break;
|
||||
if(!temp_data32 || (temp_data32 % 2)) {
|
||||
FURI_LOG_E(TAG, "Integrity error Custom_preset_data");
|
||||
break;
|
||||
}
|
||||
item->custom_preset_data_size = sizeof(uint8_t) * temp_data32;
|
||||
item->custom_preset_data = malloc(item->custom_preset_data_size);
|
||||
if(!flipper_format_read_hex(
|
||||
fff_data_file,
|
||||
"Custom_preset_data",
|
||||
item->custom_preset_data,
|
||||
item->custom_preset_data_size)) {
|
||||
FURI_LOG_E(TAG, "Missing Custom_preset_data");
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
} while(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool subghz_setting_delete_custom_preset(SubGhzSetting* instance, const char* preset_name) {
|
||||
furi_assert(instance);
|
||||
furi_assert(preset_name);
|
||||
SubGhzSettingCustomPresetItemArray_it_t it;
|
||||
SubGhzSettingCustomPresetItemArray_it_last(it, instance->preset->data);
|
||||
while(!SubGhzSettingCustomPresetItemArray_end_p(it)) {
|
||||
SubGhzSettingCustomPresetItem* item = SubGhzSettingCustomPresetItemArray_ref(it);
|
||||
if(strcmp(string_get_cstr(item->custom_preset_name), preset_name) == 0) {
|
||||
string_clear(item->custom_preset_name);
|
||||
free(item->custom_preset_data);
|
||||
SubGhzSettingCustomPresetItemArray_remove(instance->preset->data, it);
|
||||
return true;
|
||||
}
|
||||
SubGhzSettingCustomPresetItemArray_previous(it);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t* subghz_setting_get_preset_data(SubGhzSetting* instance, size_t idx) {
|
||||
furi_assert(instance);
|
||||
SubGhzSettingCustomPresetItem* item =
|
||||
SubGhzSettingCustomPresetItemArray_get(instance->preset->data, idx);
|
||||
return item->custom_preset_data;
|
||||
}
|
||||
|
||||
size_t subghz_setting_get_preset_data_size(SubGhzSetting* instance, size_t idx) {
|
||||
furi_assert(instance);
|
||||
SubGhzSettingCustomPresetItem* item =
|
||||
SubGhzSettingCustomPresetItemArray_get(instance->preset->data, idx);
|
||||
return item->custom_preset_data_size;
|
||||
}
|
||||
|
||||
uint8_t* subghz_setting_get_preset_data_by_name(SubGhzSetting* instance, const char* preset_name) {
|
||||
furi_assert(instance);
|
||||
SubGhzSettingCustomPresetItem* item = SubGhzSettingCustomPresetItemArray_get(
|
||||
instance->preset->data, subghz_setting_get_inx_preset_by_name(instance, preset_name));
|
||||
return item->custom_preset_data;
|
||||
}
|
||||
|
||||
uint32_t subghz_setting_get_frequency(SubGhzSetting* instance, size_t idx) {
|
||||
furi_assert(instance);
|
||||
uint32_t* ret = FrequencyList_get(instance->frequencies, idx);
|
||||
|
@@ -4,6 +4,9 @@
|
||||
#include <math.h>
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <lib/flipper_format/flipper_format.h>
|
||||
|
||||
#define SUBGHZ_SETTING_DEFAULT_PRESET_COUNT 4
|
||||
|
||||
typedef struct SubGhzSetting SubGhzSetting;
|
||||
|
||||
@@ -17,6 +20,25 @@ size_t subghz_setting_get_frequency_count(SubGhzSetting* instance);
|
||||
|
||||
size_t subghz_setting_get_hopper_frequency_count(SubGhzSetting* instance);
|
||||
|
||||
size_t subghz_setting_get_preset_count(SubGhzSetting* instance);
|
||||
|
||||
const char* subghz_setting_get_preset_name(SubGhzSetting* instance, size_t idx);
|
||||
|
||||
int subghz_setting_get_inx_preset_by_name(SubGhzSetting* instance, const char* preset_name);
|
||||
|
||||
uint8_t* subghz_setting_get_preset_data(SubGhzSetting* instance, size_t idx);
|
||||
|
||||
size_t subghz_setting_get_preset_data_size(SubGhzSetting* instance, size_t idx);
|
||||
|
||||
uint8_t* subghz_setting_get_preset_data_by_name(SubGhzSetting* instance, const char* preset_name);
|
||||
|
||||
bool subghz_setting_load_custom_preset(
|
||||
SubGhzSetting* instance,
|
||||
const char* preset_name,
|
||||
FlipperFormat* fff_data_file);
|
||||
|
||||
bool subghz_setting_delete_custom_preset(SubGhzSetting* instance, const char* preset_name);
|
||||
|
||||
uint32_t subghz_setting_get_frequency(SubGhzSetting* instance, size_t idx);
|
||||
|
||||
uint32_t subghz_setting_get_hopper_frequency(SubGhzSetting* instance, size_t idx);
|
||||
|
Reference in New Issue
Block a user