2022-04-14 14:05:40 +00:00
|
|
|
#include "subghz_setting.h"
|
2022-10-19 17:27:26 +00:00
|
|
|
#include "types.h"
|
|
|
|
//#include "subghz_i.h"
|
2022-04-14 14:05:40 +00:00
|
|
|
|
|
|
|
#include <furi.h>
|
|
|
|
#include <m-list.h>
|
2023-06-30 14:03:36 +00:00
|
|
|
#include <lib/subghz/devices/cc1101_configs.h>
|
2022-04-14 14:05:40 +00:00
|
|
|
|
|
|
|
#define TAG "SubGhzSetting"
|
|
|
|
|
|
|
|
#define SUBGHZ_SETTING_FILE_TYPE "Flipper SubGhz Setting File"
|
2022-05-31 15:50:50 +00:00
|
|
|
#define SUBGHZ_SETTING_FILE_VERSION 1
|
2022-04-14 14:05:40 +00:00
|
|
|
|
2022-05-31 15:50:50 +00:00
|
|
|
#define FREQUENCY_FLAG_DEFAULT (1 << 31)
|
|
|
|
#define FREQUENCY_MASK (0xFFFFFFFF ^ FREQUENCY_FLAG_DEFAULT)
|
2022-04-14 14:05:40 +00:00
|
|
|
|
2022-05-31 15:50:50 +00:00
|
|
|
/* Default */
|
|
|
|
static const uint32_t subghz_frequency_list[] = {
|
2022-04-14 14:05:40 +00:00
|
|
|
/* 300 - 348 */
|
|
|
|
300000000,
|
|
|
|
303875000,
|
|
|
|
304250000,
|
2022-05-31 15:50:50 +00:00
|
|
|
310000000,
|
2022-04-14 14:05:40 +00:00
|
|
|
315000000,
|
|
|
|
318000000,
|
|
|
|
|
|
|
|
/* 387 - 464 */
|
|
|
|
390000000,
|
|
|
|
418000000,
|
|
|
|
433075000, /* LPD433 first */
|
|
|
|
433420000,
|
2022-05-31 15:50:50 +00:00
|
|
|
433920000 | FREQUENCY_FLAG_DEFAULT, /* LPD433 mid */
|
2022-04-14 14:05:40 +00:00
|
|
|
434420000,
|
|
|
|
434775000, /* LPD433 last channels */
|
|
|
|
438900000,
|
|
|
|
|
|
|
|
/* 779 - 928 */
|
|
|
|
868350000,
|
|
|
|
915000000,
|
|
|
|
925000000,
|
|
|
|
0,
|
|
|
|
};
|
2022-05-31 15:50:50 +00:00
|
|
|
|
|
|
|
static const uint32_t subghz_hopper_frequency_list[] = {
|
|
|
|
310000000,
|
2022-04-14 14:05:40 +00:00
|
|
|
315000000,
|
|
|
|
318000000,
|
|
|
|
390000000,
|
|
|
|
433920000,
|
|
|
|
868350000,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
2022-05-31 15:50:50 +00:00
|
|
|
/* Europe and Russia */
|
|
|
|
static const uint32_t subghz_frequency_list_region_eu_ru[] = {
|
2022-04-14 14:05:40 +00:00
|
|
|
/* 300 - 348 */
|
|
|
|
300000000,
|
|
|
|
303875000,
|
|
|
|
304250000,
|
2022-05-31 15:50:50 +00:00
|
|
|
310000000,
|
2022-04-14 14:05:40 +00:00
|
|
|
315000000,
|
|
|
|
318000000,
|
|
|
|
|
|
|
|
/* 387 - 464 */
|
|
|
|
390000000,
|
|
|
|
418000000,
|
|
|
|
433075000, /* LPD433 first */
|
|
|
|
433420000,
|
2022-05-31 15:50:50 +00:00
|
|
|
433920000 | FREQUENCY_FLAG_DEFAULT, /* LPD433 mid */
|
2022-04-14 14:05:40 +00:00
|
|
|
434420000,
|
|
|
|
434775000, /* LPD433 last channels */
|
|
|
|
438900000,
|
|
|
|
|
|
|
|
/* 779 - 928 */
|
|
|
|
868350000,
|
|
|
|
915000000,
|
|
|
|
925000000,
|
|
|
|
0,
|
|
|
|
};
|
2022-05-31 15:50:50 +00:00
|
|
|
static const uint32_t subghz_hopper_frequency_list_region_eu_ru[] = {
|
|
|
|
310000000,
|
2022-04-14 14:05:40 +00:00
|
|
|
315000000,
|
|
|
|
318000000,
|
|
|
|
390000000,
|
|
|
|
433920000,
|
|
|
|
868350000,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
2022-05-31 15:50:50 +00:00
|
|
|
/* Region 0 */
|
|
|
|
static const uint32_t subghz_frequency_list_region_us_ca_au[] = {
|
2022-04-14 14:05:40 +00:00
|
|
|
/* 300 - 348 */
|
|
|
|
300000000,
|
|
|
|
303875000,
|
|
|
|
304250000,
|
2022-05-31 15:50:50 +00:00
|
|
|
310000000,
|
2022-04-14 14:05:40 +00:00
|
|
|
315000000,
|
|
|
|
318000000,
|
|
|
|
|
|
|
|
/* 387 - 464 */
|
|
|
|
390000000,
|
|
|
|
418000000,
|
|
|
|
433075000, /* LPD433 first */
|
|
|
|
433420000,
|
2022-05-31 15:50:50 +00:00
|
|
|
433920000 | FREQUENCY_FLAG_DEFAULT, /* LPD433 mid */
|
2022-04-14 14:05:40 +00:00
|
|
|
434420000,
|
|
|
|
434775000, /* LPD433 last channels */
|
|
|
|
438900000,
|
|
|
|
|
|
|
|
/* 779 - 928 */
|
|
|
|
868350000,
|
|
|
|
915000000,
|
|
|
|
925000000,
|
|
|
|
0,
|
|
|
|
};
|
2022-05-31 15:50:50 +00:00
|
|
|
static const uint32_t subghz_hopper_frequency_list_region_us_ca_au[] = {
|
|
|
|
310000000,
|
2022-04-14 14:05:40 +00:00
|
|
|
315000000,
|
|
|
|
318000000,
|
|
|
|
390000000,
|
|
|
|
433920000,
|
|
|
|
868350000,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
2022-05-31 15:50:50 +00:00
|
|
|
static const uint32_t subghz_frequency_list_region_jp[] = {
|
2022-04-14 14:05:40 +00:00
|
|
|
/* 300 - 348 */
|
|
|
|
300000000,
|
|
|
|
303875000,
|
|
|
|
304250000,
|
2022-05-31 15:50:50 +00:00
|
|
|
310000000,
|
2022-04-14 14:05:40 +00:00
|
|
|
315000000,
|
|
|
|
318000000,
|
|
|
|
|
|
|
|
/* 387 - 464 */
|
|
|
|
390000000,
|
|
|
|
418000000,
|
|
|
|
433075000, /* LPD433 first */
|
|
|
|
433420000,
|
2022-05-31 15:50:50 +00:00
|
|
|
433920000 | FREQUENCY_FLAG_DEFAULT, /* LPD433 mid */
|
2022-04-14 14:05:40 +00:00
|
|
|
434420000,
|
|
|
|
434775000, /* LPD433 last channels */
|
|
|
|
438900000,
|
|
|
|
|
|
|
|
/* 779 - 928 */
|
|
|
|
868350000,
|
|
|
|
915000000,
|
|
|
|
925000000,
|
|
|
|
0,
|
|
|
|
};
|
2022-05-31 15:50:50 +00:00
|
|
|
static const uint32_t subghz_hopper_frequency_list_region_jp[] = {
|
|
|
|
310000000,
|
2022-04-14 14:05:40 +00:00
|
|
|
315000000,
|
|
|
|
318000000,
|
|
|
|
390000000,
|
|
|
|
433920000,
|
|
|
|
868350000,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
2022-07-26 14:16:59 +00:00
|
|
|
typedef struct {
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriString* custom_preset_name;
|
2022-07-26 14:16:59 +00:00
|
|
|
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)
|
|
|
|
|
2022-05-31 15:50:50 +00:00
|
|
|
LIST_DEF(FrequencyList, uint32_t)
|
|
|
|
|
|
|
|
#define M_OPL_FrequencyList_t() LIST_OPLIST(FrequencyList)
|
2022-04-14 14:05:40 +00:00
|
|
|
|
2022-07-26 14:16:59 +00:00
|
|
|
typedef struct {
|
|
|
|
SubGhzSettingCustomPresetItemArray_t data;
|
|
|
|
} SubGhzSettingCustomPresetStruct;
|
|
|
|
|
2022-04-14 14:05:40 +00:00
|
|
|
struct SubGhzSetting {
|
2022-05-31 15:50:50 +00:00
|
|
|
FrequencyList_t frequencies;
|
|
|
|
FrequencyList_t hopper_frequencies;
|
2022-07-26 14:16:59 +00:00
|
|
|
SubGhzSettingCustomPresetStruct* preset;
|
2022-04-14 14:05:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
SubGhzSetting* subghz_setting_alloc(void) {
|
|
|
|
SubGhzSetting* instance = malloc(sizeof(SubGhzSetting));
|
2022-05-31 15:50:50 +00:00
|
|
|
FrequencyList_init(instance->frequencies);
|
|
|
|
FrequencyList_init(instance->hopper_frequencies);
|
2022-07-26 14:16:59 +00:00
|
|
|
instance->preset = malloc(sizeof(SubGhzSettingCustomPresetStruct));
|
|
|
|
SubGhzSettingCustomPresetItemArray_init(instance->preset->data);
|
2022-04-14 14:05:40 +00:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2022-07-26 14:16:59 +00:00
|
|
|
static void subghz_setting_preset_reset(SubGhzSetting* instance) {
|
|
|
|
for
|
|
|
|
M_EACH(item, instance->preset->data, SubGhzSettingCustomPresetItemArray_t) {
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_free(item->custom_preset_name);
|
2022-07-26 14:16:59 +00:00
|
|
|
free(item->custom_preset_data);
|
|
|
|
}
|
|
|
|
SubGhzSettingCustomPresetItemArray_reset(instance->preset->data);
|
|
|
|
}
|
|
|
|
|
2022-04-14 14:05:40 +00:00
|
|
|
void subghz_setting_free(SubGhzSetting* instance) {
|
2024-03-19 14:43:52 +00:00
|
|
|
furi_check(instance);
|
2022-05-31 15:50:50 +00:00
|
|
|
FrequencyList_clear(instance->frequencies);
|
|
|
|
FrequencyList_clear(instance->hopper_frequencies);
|
2022-07-26 14:16:59 +00:00
|
|
|
for
|
|
|
|
M_EACH(item, instance->preset->data, SubGhzSettingCustomPresetItemArray_t) {
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_free(item->custom_preset_name);
|
2022-07-26 14:16:59 +00:00
|
|
|
free(item->custom_preset_data);
|
|
|
|
}
|
|
|
|
SubGhzSettingCustomPresetItemArray_clear(instance->preset->data);
|
|
|
|
free(instance->preset);
|
2022-04-14 14:05:40 +00:00
|
|
|
free(instance);
|
|
|
|
}
|
|
|
|
|
2022-07-26 14:16:59 +00:00
|
|
|
static void subghz_setting_load_default_preset(
|
|
|
|
SubGhzSetting* instance,
|
|
|
|
const char* preset_name,
|
2023-06-30 14:03:36 +00:00
|
|
|
const uint8_t* preset_data) {
|
2022-07-26 14:16:59 +00:00
|
|
|
furi_assert(instance);
|
|
|
|
furi_assert(preset_data);
|
|
|
|
uint32_t preset_data_count = 0;
|
|
|
|
SubGhzSettingCustomPresetItem* item =
|
|
|
|
SubGhzSettingCustomPresetItemArray_push_raw(instance->preset->data);
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
item->custom_preset_name = furi_string_alloc();
|
|
|
|
furi_string_set(item->custom_preset_name, preset_name);
|
2022-07-26 14:16:59 +00:00
|
|
|
|
|
|
|
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);
|
2023-06-30 14:03:36 +00:00
|
|
|
//load preset register + pa table
|
|
|
|
memcpy(&item->custom_preset_data[0], &preset_data[0], item->custom_preset_data_size);
|
2022-07-26 14:16:59 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 15:50:50 +00:00
|
|
|
static void subghz_setting_load_default_region(
|
2022-04-14 14:05:40 +00:00
|
|
|
SubGhzSetting* instance,
|
|
|
|
const uint32_t frequencies[],
|
2022-05-31 15:50:50 +00:00
|
|
|
const uint32_t hopper_frequencies[]) {
|
2022-04-14 14:05:40 +00:00
|
|
|
furi_assert(instance);
|
2022-05-31 15:50:50 +00:00
|
|
|
|
|
|
|
FrequencyList_reset(instance->frequencies);
|
|
|
|
FrequencyList_reset(instance->hopper_frequencies);
|
2022-07-26 14:16:59 +00:00
|
|
|
subghz_setting_preset_reset(instance);
|
2022-05-31 15:50:50 +00:00
|
|
|
|
|
|
|
while(*frequencies) {
|
|
|
|
FrequencyList_push_back(instance->frequencies, *frequencies);
|
|
|
|
frequencies++;
|
2022-04-14 14:05:40 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 15:50:50 +00:00
|
|
|
while(*hopper_frequencies) {
|
|
|
|
FrequencyList_push_back(instance->hopper_frequencies, *hopper_frequencies);
|
|
|
|
hopper_frequencies++;
|
2022-04-14 14:05:40 +00:00
|
|
|
}
|
2022-07-26 14:16:59 +00:00
|
|
|
|
|
|
|
subghz_setting_load_default_preset(
|
2023-06-30 14:03:36 +00:00
|
|
|
instance, "AM270", subghz_device_cc1101_preset_ook_270khz_async_regs);
|
2022-07-26 14:16:59 +00:00
|
|
|
subghz_setting_load_default_preset(
|
2023-06-30 14:03:36 +00:00
|
|
|
instance, "AM650", subghz_device_cc1101_preset_ook_650khz_async_regs);
|
2022-07-26 14:16:59 +00:00
|
|
|
subghz_setting_load_default_preset(
|
2023-06-30 14:03:36 +00:00
|
|
|
instance, "FM238", subghz_device_cc1101_preset_2fsk_dev2_38khz_async_regs);
|
2022-07-26 14:16:59 +00:00
|
|
|
subghz_setting_load_default_preset(
|
2023-06-30 14:03:36 +00:00
|
|
|
instance, "FM476", subghz_device_cc1101_preset_2fsk_dev47_6khz_async_regs);
|
2022-05-31 15:50:50 +00:00
|
|
|
}
|
2022-04-14 14:05:40 +00:00
|
|
|
|
2022-05-31 15:50:50 +00:00
|
|
|
void subghz_setting_load_default(SubGhzSetting* instance) {
|
|
|
|
switch(furi_hal_version_get_hw_region()) {
|
|
|
|
case FuriHalVersionRegionEuRu:
|
|
|
|
subghz_setting_load_default_region(
|
|
|
|
instance,
|
|
|
|
subghz_frequency_list_region_eu_ru,
|
|
|
|
subghz_hopper_frequency_list_region_eu_ru);
|
|
|
|
break;
|
|
|
|
case FuriHalVersionRegionUsCaAu:
|
|
|
|
subghz_setting_load_default_region(
|
|
|
|
instance,
|
|
|
|
subghz_frequency_list_region_us_ca_au,
|
|
|
|
subghz_hopper_frequency_list_region_us_ca_au);
|
|
|
|
break;
|
|
|
|
case FuriHalVersionRegionJp:
|
|
|
|
subghz_setting_load_default_region(
|
|
|
|
instance, subghz_frequency_list_region_jp, subghz_hopper_frequency_list_region_jp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
subghz_setting_load_default_region(
|
|
|
|
instance, subghz_frequency_list, subghz_hopper_frequency_list);
|
|
|
|
break;
|
|
|
|
}
|
2022-04-14 14:05:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void subghz_setting_load(SubGhzSetting* instance, const char* file_path) {
|
2024-03-19 14:43:52 +00:00
|
|
|
furi_check(instance);
|
2022-04-14 14:05:40 +00:00
|
|
|
|
2022-07-26 12:21:51 +00:00
|
|
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
2022-04-14 14:05:40 +00:00
|
|
|
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriString* temp_str;
|
|
|
|
temp_str = furi_string_alloc();
|
2022-04-14 14:05:40 +00:00
|
|
|
uint32_t temp_data32;
|
2022-05-31 15:50:50 +00:00
|
|
|
bool temp_bool;
|
|
|
|
|
|
|
|
subghz_setting_load_default(instance);
|
2022-04-14 14:05:40 +00:00
|
|
|
|
|
|
|
if(file_path) {
|
|
|
|
do {
|
|
|
|
if(!flipper_format_file_open_existing(fff_data_file, file_path)) {
|
2022-10-19 17:27:26 +00:00
|
|
|
FURI_LOG_I(TAG, "File is not used %s", file_path);
|
2022-04-14 14:05:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!flipper_format_read_header(fff_data_file, temp_str, &temp_data32)) {
|
|
|
|
FURI_LOG_E(TAG, "Missing or incorrect header");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
if((!strcmp(furi_string_get_cstr(temp_str), SUBGHZ_SETTING_FILE_TYPE)) &&
|
2022-04-14 14:05:40 +00:00
|
|
|
temp_data32 == SUBGHZ_SETTING_FILE_VERSION) {
|
|
|
|
} else {
|
|
|
|
FURI_LOG_E(TAG, "Type or version mismatch");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-05-31 15:50:50 +00:00
|
|
|
// Standard frequencies (optional)
|
|
|
|
temp_bool = true;
|
2022-07-26 14:16:59 +00:00
|
|
|
flipper_format_read_bool(fff_data_file, "Add_standard_frequencies", &temp_bool, 1);
|
2022-05-31 15:50:50 +00:00
|
|
|
if(!temp_bool) {
|
|
|
|
FURI_LOG_I(TAG, "Removing standard frequencies");
|
|
|
|
FrequencyList_reset(instance->frequencies);
|
|
|
|
FrequencyList_reset(instance->hopper_frequencies);
|
|
|
|
} else {
|
|
|
|
FURI_LOG_I(TAG, "Keeping standard frequencies");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load frequencies
|
2022-04-14 14:05:40 +00:00
|
|
|
if(!flipper_format_rewind(fff_data_file)) {
|
|
|
|
FURI_LOG_E(TAG, "Rewind error");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
while(flipper_format_read_uint32(
|
2022-07-26 14:16:59 +00:00
|
|
|
fff_data_file, "Frequency", (uint32_t*)&temp_data32, 1)) {
|
2023-08-22 17:56:27 +00:00
|
|
|
//Todo FL-3535: add a frequency support check depending on the selected radio device
|
2022-04-14 14:05:40 +00:00
|
|
|
if(furi_hal_subghz_is_frequency_valid(temp_data32)) {
|
|
|
|
FURI_LOG_I(TAG, "Frequency loaded %lu", temp_data32);
|
2022-05-31 15:50:50 +00:00
|
|
|
FrequencyList_push_back(instance->frequencies, temp_data32);
|
2022-04-14 14:05:40 +00:00
|
|
|
} else {
|
|
|
|
FURI_LOG_E(TAG, "Frequency not supported %lu", temp_data32);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-31 15:50:50 +00:00
|
|
|
// Load hopper frequencies
|
2022-04-14 14:05:40 +00:00
|
|
|
if(!flipper_format_rewind(fff_data_file)) {
|
|
|
|
FURI_LOG_E(TAG, "Rewind error");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
while(flipper_format_read_uint32(
|
2022-07-26 14:16:59 +00:00
|
|
|
fff_data_file, "Hopper_frequency", (uint32_t*)&temp_data32, 1)) {
|
2022-04-14 14:05:40 +00:00
|
|
|
if(furi_hal_subghz_is_frequency_valid(temp_data32)) {
|
|
|
|
FURI_LOG_I(TAG, "Hopper frequency loaded %lu", temp_data32);
|
2022-05-31 15:50:50 +00:00
|
|
|
FrequencyList_push_back(instance->hopper_frequencies, temp_data32);
|
2022-04-14 14:05:40 +00:00
|
|
|
} else {
|
|
|
|
FURI_LOG_E(TAG, "Hopper frequency not supported %lu", temp_data32);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-31 15:50:50 +00:00
|
|
|
// Default frequency (optional)
|
2022-04-14 14:05:40 +00:00
|
|
|
if(!flipper_format_rewind(fff_data_file)) {
|
|
|
|
FURI_LOG_E(TAG, "Rewind error");
|
|
|
|
break;
|
|
|
|
}
|
2022-07-26 14:16:59 +00:00
|
|
|
if(flipper_format_read_uint32(fff_data_file, "Default_frequency", &temp_data32, 1)) {
|
2022-05-31 15:50:50 +00:00
|
|
|
for
|
|
|
|
M_EACH(frequency, instance->frequencies, FrequencyList_t) {
|
|
|
|
*frequency &= FREQUENCY_MASK;
|
|
|
|
if(*frequency == temp_data32) {
|
|
|
|
*frequency |= FREQUENCY_FLAG_DEFAULT;
|
|
|
|
}
|
|
|
|
}
|
2022-04-14 14:05:40 +00:00
|
|
|
}
|
2022-07-26 14:16:59 +00:00
|
|
|
|
|
|
|
// 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)) {
|
2022-10-05 15:15:23 +00:00
|
|
|
FURI_LOG_I(TAG, "Custom preset loaded %s", furi_string_get_cstr(temp_str));
|
2022-07-26 14:16:59 +00:00
|
|
|
subghz_setting_load_custom_preset(
|
2022-10-05 15:15:23 +00:00
|
|
|
instance, furi_string_get_cstr(temp_str), fff_data_file);
|
2022-07-26 14:16:59 +00:00
|
|
|
}
|
|
|
|
|
2022-04-14 14:05:40 +00:00
|
|
|
} while(false);
|
|
|
|
}
|
2022-04-15 16:31:25 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_free(temp_str);
|
2022-04-14 14:05:40 +00:00
|
|
|
flipper_format_free(fff_data_file);
|
2022-07-26 12:21:51 +00:00
|
|
|
furi_record_close(RECORD_STORAGE);
|
2022-04-14 14:05:40 +00:00
|
|
|
|
2022-05-31 15:50:50 +00:00
|
|
|
if(!FrequencyList_size(instance->frequencies) ||
|
|
|
|
!FrequencyList_size(instance->hopper_frequencies)) {
|
|
|
|
FURI_LOG_E(TAG, "Error loading user settings, loading default settings");
|
|
|
|
subghz_setting_load_default(instance);
|
2022-04-14 14:05:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t subghz_setting_get_frequency_count(SubGhzSetting* instance) {
|
2024-03-19 14:43:52 +00:00
|
|
|
furi_check(instance);
|
2022-05-31 15:50:50 +00:00
|
|
|
return FrequencyList_size(instance->frequencies);
|
2022-04-14 14:05:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t subghz_setting_get_hopper_frequency_count(SubGhzSetting* instance) {
|
2024-03-19 14:43:52 +00:00
|
|
|
furi_check(instance);
|
2022-05-31 15:50:50 +00:00
|
|
|
return FrequencyList_size(instance->hopper_frequencies);
|
2022-04-14 14:05:40 +00:00
|
|
|
}
|
|
|
|
|
2022-07-26 14:16:59 +00:00
|
|
|
size_t subghz_setting_get_preset_count(SubGhzSetting* instance) {
|
2024-03-19 14:43:52 +00:00
|
|
|
furi_check(instance);
|
2022-07-26 14:16:59 +00:00
|
|
|
return SubGhzSettingCustomPresetItemArray_size(instance->preset->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* subghz_setting_get_preset_name(SubGhzSetting* instance, size_t idx) {
|
2024-03-19 14:43:52 +00:00
|
|
|
furi_check(instance);
|
2022-07-26 14:16:59 +00:00
|
|
|
SubGhzSettingCustomPresetItem* item =
|
|
|
|
SubGhzSettingCustomPresetItemArray_get(instance->preset->data, idx);
|
2022-10-05 15:15:23 +00:00
|
|
|
return furi_string_get_cstr(item->custom_preset_name);
|
2022-07-26 14:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int subghz_setting_get_inx_preset_by_name(SubGhzSetting* instance, const char* preset_name) {
|
2024-03-19 14:43:52 +00:00
|
|
|
furi_check(instance);
|
2022-07-26 14:16:59 +00:00
|
|
|
size_t idx = 0;
|
2022-08-23 11:29:26 +00:00
|
|
|
for
|
|
|
|
M_EACH(item, instance->preset->data, SubGhzSettingCustomPresetItemArray_t) {
|
2022-10-05 15:15:23 +00:00
|
|
|
if(strcmp(furi_string_get_cstr(item->custom_preset_name), preset_name) == 0) {
|
2022-08-23 11:29:26 +00:00
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
furi_crash("SubGhz: No name preset.");
|
|
|
|
return -1;
|
2022-07-26 14:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool subghz_setting_load_custom_preset(
|
|
|
|
SubGhzSetting* instance,
|
|
|
|
const char* preset_name,
|
|
|
|
FlipperFormat* fff_data_file) {
|
2024-03-19 14:43:52 +00:00
|
|
|
furi_check(instance);
|
|
|
|
furi_check(preset_name);
|
2022-07-26 14:16:59 +00:00
|
|
|
uint32_t temp_data32;
|
|
|
|
SubGhzSettingCustomPresetItem* item =
|
|
|
|
SubGhzSettingCustomPresetItemArray_push_raw(instance->preset->data);
|
2022-10-05 15:15:23 +00:00
|
|
|
item->custom_preset_name = furi_string_alloc();
|
|
|
|
furi_string_set(item->custom_preset_name, preset_name);
|
2022-07-26 14:16:59 +00:00
|
|
|
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) {
|
2024-03-19 14:43:52 +00:00
|
|
|
furi_check(instance);
|
|
|
|
furi_check(preset_name);
|
2022-07-26 14:16:59 +00:00
|
|
|
SubGhzSettingCustomPresetItemArray_it_t it;
|
|
|
|
SubGhzSettingCustomPresetItemArray_it_last(it, instance->preset->data);
|
|
|
|
while(!SubGhzSettingCustomPresetItemArray_end_p(it)) {
|
|
|
|
SubGhzSettingCustomPresetItem* item = SubGhzSettingCustomPresetItemArray_ref(it);
|
2022-10-05 15:15:23 +00:00
|
|
|
if(strcmp(furi_string_get_cstr(item->custom_preset_name), preset_name) == 0) {
|
|
|
|
furi_string_free(item->custom_preset_name);
|
2022-07-26 14:16:59 +00:00
|
|
|
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) {
|
2024-03-19 14:43:52 +00:00
|
|
|
furi_check(instance);
|
2022-07-26 14:16:59 +00:00
|
|
|
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) {
|
2024-03-19 14:43:52 +00:00
|
|
|
furi_check(instance);
|
2022-07-26 14:16:59 +00:00
|
|
|
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) {
|
2024-03-19 14:43:52 +00:00
|
|
|
furi_check(instance);
|
2022-07-26 14:16:59 +00:00
|
|
|
SubGhzSettingCustomPresetItem* item = SubGhzSettingCustomPresetItemArray_get(
|
|
|
|
instance->preset->data, subghz_setting_get_inx_preset_by_name(instance, preset_name));
|
|
|
|
return item->custom_preset_data;
|
|
|
|
}
|
|
|
|
|
2022-04-14 14:05:40 +00:00
|
|
|
uint32_t subghz_setting_get_frequency(SubGhzSetting* instance, size_t idx) {
|
2024-03-19 14:43:52 +00:00
|
|
|
furi_check(instance);
|
2022-12-26 12:13:30 +00:00
|
|
|
if(idx < FrequencyList_size(instance->frequencies)) {
|
|
|
|
return (*FrequencyList_get(instance->frequencies, idx)) & FREQUENCY_MASK;
|
2022-05-31 15:50:50 +00:00
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2022-04-14 14:05:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t subghz_setting_get_hopper_frequency(SubGhzSetting* instance, size_t idx) {
|
2024-03-19 14:43:52 +00:00
|
|
|
furi_check(instance);
|
2023-03-20 16:30:57 +00:00
|
|
|
if(idx < FrequencyList_size(instance->hopper_frequencies)) {
|
2022-12-26 12:13:30 +00:00
|
|
|
return *FrequencyList_get(instance->hopper_frequencies, idx);
|
2022-05-31 15:50:50 +00:00
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2022-04-14 14:05:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t subghz_setting_get_frequency_default_index(SubGhzSetting* instance) {
|
2024-03-19 14:43:52 +00:00
|
|
|
furi_check(instance);
|
2022-05-31 15:50:50 +00:00
|
|
|
for(size_t i = 0; i < FrequencyList_size(instance->frequencies); i++) {
|
|
|
|
uint32_t frequency = *FrequencyList_get(instance->frequencies, i);
|
|
|
|
if(frequency & FREQUENCY_FLAG_DEFAULT) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2022-04-15 16:31:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t subghz_setting_get_default_frequency(SubGhzSetting* instance) {
|
2024-03-19 14:43:52 +00:00
|
|
|
furi_check(instance);
|
2022-05-31 15:50:50 +00:00
|
|
|
return subghz_setting_get_frequency(
|
|
|
|
instance, subghz_setting_get_frequency_default_index(instance));
|
2022-04-15 16:31:25 +00:00
|
|
|
}
|