Skip to content

Commit

Permalink
ensure RAW subghz signals repeat
Browse files Browse the repository at this point in the history
  • Loading branch information
rdefeo committed May 5, 2024
1 parent 0cfc811 commit d366342
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 22 deletions.
48 changes: 26 additions & 22 deletions actions/action_subghz.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static const SubGhzDevice* action_subghz_get_device(uint32_t* device_ind) {
void action_subghz_tx(void* context, const FuriString* action_path, FuriString* error) {
App* app = context;
const char* file_name = furi_string_get_cstr(action_path);
uint32_t repeat = 1; // This is set to 10 in the cli - why?
uint32_t repeat = app->settings.subghz_repeat; // Defaults to 10 in the CLI
uint32_t device_ind = app->settings.subghz_use_ext_antenna ? 1 : 0;

FlipperFormat* fff_data_file = flipper_format_file_alloc(app->storage);
Expand All @@ -94,10 +94,10 @@ void action_subghz_tx(void* context, const FuriString* action_path, FuriString*
subghz_devices_init();
SubGhzEnvironment* environment = subghz_environment_alloc();
if(!subghz_environment_load_keystore(environment, SUBGHZ_KEYSTORE_DIR_NAME)) {
FURI_LOG_E(TAG, "Load_keystore keeloq_mfcodes ERROR");
FURI_LOG_W(TAG, "Load_keystore keeloq_mfcodes - failed to load");
}
if(!subghz_environment_load_keystore(environment, SUBGHZ_KEYSTORE_DIR_USER_NAME)) {
FURI_LOG_E(TAG, "Load_keystore keeloq_mfcodes_user ERROR");
FURI_LOG_W(TAG, "Load_keystore keeloq_mfcodes_user - failed to load");
}
subghz_environment_set_came_atomo_rainbow_table_file_name(
environment, SUBGHZ_CAME_ATOMO_DIR_NAME);
Expand Down Expand Up @@ -154,16 +154,17 @@ void action_subghz_tx(void* context, const FuriString* action_path, FuriString*
break;
}

if(action_subghz_get_preset_name(furi_string_get_cstr(temp_str)) ==
FuriHalSubGhzPresetIDLE) {
FuriHalSubGhzPreset preset = action_subghz_get_preset_name(furi_string_get_cstr(temp_str));
if(preset == FuriHalSubGhzPresetIDLE) {
ACTION_SET_ERROR("SUBGHZ: Unknown preset");
break;
}

subghz_devices_begin(device);
subghz_devices_reset(device);
subghz_devices_idle(device);

if(!strcmp(furi_string_get_cstr(temp_str), "FuriHalSubGhzPresetCustom")) {
if(preset == FuriHalSubGhzPresetCustom) {
uint8_t* custom_preset_data;
uint32_t custom_preset_data_size;
if(!flipper_format_get_value_count(fff_data_file, "Custom_preset_data", &temp_data32))
Expand All @@ -184,14 +185,10 @@ void action_subghz_tx(void* context, const FuriString* action_path, FuriString*
ACTION_SET_ERROR("SUBGHZ: Custom_preset_data read error");
break;
}
subghz_devices_load_preset(
device,
action_subghz_get_preset_name(furi_string_get_cstr(temp_str)),
custom_preset_data);
subghz_devices_load_preset(device, preset, custom_preset_data);
free(custom_preset_data);
} else {
subghz_devices_load_preset(
device, action_subghz_get_preset_name(furi_string_get_cstr(temp_str)), NULL);
subghz_devices_load_preset(device, preset, NULL);
}

subghz_devices_set_frequency(device, frequency);
Expand All @@ -205,7 +202,7 @@ void action_subghz_tx(void* context, const FuriString* action_path, FuriString*

SubGhzProtocolStatus status;
bool is_init_protocol = true;
if(!strcmp(furi_string_get_cstr(temp_str), "RAW")) {
if(furi_string_equal(temp_str, "RAW")) {
FURI_LOG_I(TAG, "Protocol = RAW");
subghz_protocol_raw_gen_fff_data(
fff_data_raw, file_name, subghz_devices_get_name(device));
Expand All @@ -225,7 +222,10 @@ void action_subghz_tx(void* context, const FuriString* action_path, FuriString*
}
} else { // if not RAW protocol
FURI_LOG_I(TAG, "Protocol != RAW");
flipper_format_insert_or_update_uint32(fff_data_file, "Repeat", &repeat, 1);
bool repeat_exists = flipper_format_key_exist(fff_data_file, "Repeat");
if(!repeat_exists) {
flipper_format_write_uint32(fff_data_file, "Repeat", &repeat, 1);
}
transmitter =
subghz_transmitter_alloc_init(environment, furi_string_get_cstr(temp_str));
if(transmitter == NULL) {
Expand All @@ -240,7 +240,9 @@ void action_subghz_tx(void* context, const FuriString* action_path, FuriString*
is_init_protocol = false;
}
}
flipper_format_delete_key(fff_data_file, "Repeat");
if(!repeat_exists) {
flipper_format_delete_key(fff_data_file, "Repeat");
}
}

if(is_init_protocol) {
Expand All @@ -256,32 +258,34 @@ void action_subghz_tx(void* context, const FuriString* action_path, FuriString*

if(check_file) {
furi_hal_power_suppress_charge_enter();
subghz_devices_set_tx(device);
FURI_LOG_I(
TAG,
"Transmitting at %s. Frequency=%lu, Protocol=%s",
file_name,
frequency,
furi_string_get_cstr(temp_str));
do {
// delay in downloading files and other preparatory processes
furi_delay_ms(200);
// FURI_LOG_I(TAG, "delaying 200ms");
furi_delay_ms(100); // needed? orig 200
if(subghz_devices_start_async_tx(device, subghz_transmitter_yield, transmitter)) {
while(!(subghz_devices_is_async_complete_tx(
device))) { // || cli_cmd_interrupt_received
furi_delay_ms(333);
while(!subghz_devices_is_async_complete_tx(device)) {
// || cli_cmd_interrupt_received
furi_delay_ms(100); // orig 333
}
subghz_devices_stop_async_tx(device);
} else {
FURI_LOG_W(TAG, "Transmission on this frequency is restricted in your region");
}

if(!strcmp(furi_string_get_cstr(temp_str), "RAW")) {
if(furi_string_equal(temp_str, "RAW")) {
subghz_transmitter_stop(transmitter);
repeat--;
// FURI_LOG_I(TAG, "decrementing repeat: %lu", repeat);
if(repeat) subghz_transmitter_deserialize(transmitter, fff_data_raw);
}

} while(repeat && !strcmp(furi_string_get_cstr(temp_str), "RAW"));
} while(repeat && furi_string_equal(temp_str, "RAW"));

subghz_devices_sleep(device);
subghz_devices_end(device);
Expand Down
1 change: 1 addition & 0 deletions quac.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ typedef struct App {
bool show_headers; // Defaults to True
uint32_t rfid_duration; // Defaults to 2500 ms
uint32_t nfc_duration; // Defaults to 1000 ms
uint32_t subghz_repeat; // Defaults to 10, just like the CLI
bool subghz_use_ext_antenna; // Defaults to False
bool show_hidden; // Defaults to False
} settings;
Expand Down
12 changes: 12 additions & 0 deletions quac_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void quac_set_default_settings(App* app) {
app->settings.show_headers = true;
app->settings.rfid_duration = 2500;
app->settings.nfc_duration = 1000;
app->settings.subghz_repeat = 10;
app->settings.subghz_use_ext_antenna = false;
app->settings.show_hidden = false;
}
Expand Down Expand Up @@ -81,6 +82,12 @@ void quac_load_settings(App* app) {
app->settings.nfc_duration = temp_data32;
}

if(!flipper_format_read_uint32(fff_settings, "SubGHz Repeat", &temp_data32, 1)) {
FURI_LOG_W(TAG, "SETTINGS: Missing 'SubGHz Repeat'");
} else {
app->settings.subghz_repeat = temp_data32;
}

if(!flipper_format_read_uint32(fff_settings, "SubGHz Ext Antenna", &temp_data32, 1)) {
FURI_LOG_W(TAG, "SETTINGS: Missing 'SubGHz Ext Antenna'");
} else {
Expand Down Expand Up @@ -144,6 +151,11 @@ void quac_save_settings(App* app) {
FURI_LOG_E(TAG, "SETTINGS: Failed to write 'NFC Duration'");
break;
}
if(!flipper_format_write_uint32(
fff_settings, "SubGHz Repeat", &app->settings.subghz_repeat, 1)) {
FURI_LOG_E(TAG, "SETTINGS: Failed to write 'SubGHz Repeat'");
break;
}
temp_data32 = app->settings.subghz_use_ext_antenna ? 1 : 0;
if(!flipper_format_write_uint32(fff_settings, "SubGHz Ext Antenna", &temp_data32, 1)) {
FURI_LOG_E(TAG, "SETTINGS: Failed to write 'SubGHz Ext Antenna'");
Expand Down
27 changes: 27 additions & 0 deletions scenes/scene_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ typedef enum {
SceneSettingsHeaders,
SceneSettingsRFIDDuration,
SceneSettingsNFCDuration,
SceneSettingsSubGHzRepeat,
SceneSettingsSubGHzExtAnt,
SceneSettingsHidden,
SceneSettingsAbout
Expand Down Expand Up @@ -53,6 +54,19 @@ static const uint32_t duration_value[V_DURATION_COUNT] = {
10000,
};

#define V_REPEAT_COUNT 9
static const char* const repeat_text[V_REPEAT_COUNT] = {
"1",
"2",
"3",
"5",
"8",
"10", // default
"15",
"20",
"50"};
static const uint32_t repeat_value[V_REPEAT_COUNT] = {1, 2, 3, 5, 8, 10, 15, 20, 50};

static const char* const subghz_ext_text[2] = {"Disabled", "Enabled"};
static const uint32_t subghz_ext_value[2] = {false, true};

Expand Down Expand Up @@ -91,6 +105,13 @@ static void scene_settings_nfc_duration_changed(VariableItem* item) {
app->settings.nfc_duration = duration_value[index];
}

static void scene_settings_subghz_repeat_changed(VariableItem* item) {
App* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, repeat_text[index]);
app->settings.subghz_repeat = repeat_value[index];
}

static void scene_settings_subghz_ext_changed(VariableItem* item) {
App* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
Expand Down Expand Up @@ -149,6 +170,12 @@ void scene_settings_on_enter(void* context) {
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, duration_text[value_index]);

item = variable_item_list_add(
vil, "SubGHz Repeat", V_REPEAT_COUNT, scene_settings_subghz_repeat_changed, app);
value_index = value_index_uint32(app->settings.subghz_repeat, repeat_value, V_REPEAT_COUNT);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, repeat_text[value_index]);

item =
variable_item_list_add(vil, "SubGHz Ext Ant", 2, scene_settings_subghz_ext_changed, app);
value_index = value_index_uint32(app->settings.subghz_use_ext_antenna, subghz_ext_value, 2);
Expand Down

0 comments on commit d366342

Please sign in to comment.