Skip to content

Commit

Permalink
Seems to be sending, but doesn't close nicely
Browse files Browse the repository at this point in the history
  • Loading branch information
David Lee committed Dec 9, 2023
1 parent 52f1e75 commit 49cfa7f
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 61 deletions.
7 changes: 5 additions & 2 deletions helpers/subghz/subghz.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Reduced variant of the Flipper Zero SubGhz Class */

#include "subghz_i.h"
#include "../meal_pager_storage.h"
//#include "../meal_pager_storage.h"

static SubGhz* subghz_alloc() {
SubGhz* subghz = malloc(sizeof(SubGhz));
Expand All @@ -28,6 +28,8 @@ void subghz_send(void* context) {
UNUSED(context);
SubGhz* subghz = subghz_alloc();

subghz_load_protocol_from_file(subghz);

Storage* storage = furi_record_open(RECORD_STORAGE);
FlipperFormat* ff = flipper_format_file_alloc(storage);

Expand All @@ -38,7 +40,8 @@ void subghz_send(void* context) {
return;
}

subghz_txrx_tx_start(subghz->txrx, ff);
//subghz_txrx_tx_start(subghz->txrx, ff);
subghz_txrx_tx_start(subghz->txrx, subghz_txrx_get_fff_data(subghz->txrx)); //Seems like it must be done this way

flipper_format_rewind(ff);
flipper_format_file_close(ff);
Expand Down
2 changes: 1 addition & 1 deletion helpers/subghz/subghz.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

#include "subghz_i.h"

typedef struct SubGhz SubGhz;
//typedef struct SubGhz SubGhz;

void subghz_send(void* context);
58 changes: 31 additions & 27 deletions helpers/subghz/subghz_i.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "subghz_i.h"

//#include "assets_icons.h"
//#include "subghz/types.h"
#include "subghz/types.h"
#include <math.h>
#include <furi.h>
#include <furi_hal.h>
Expand All @@ -16,7 +16,7 @@
#include <lib/toolbox/stream/stream.h>
#include <lib/subghz/protocols/raw.h>

#define TAG "SubGhz"
//#define TAG "SubGhz"
/*
void subghz_set_default_preset(SubGhz* subghz) {
furi_assert(subghz);
Expand Down Expand Up @@ -45,10 +45,10 @@ void subghz_set_default_preset(SubGhz* subghz) {
return false;
}*/

/*bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) {
bool subghz_key_load(SubGhz* subghz, const char* file_path) { //, bool show_dialog) {
furi_assert(subghz);
furi_assert(file_path);
Storage* storage = furi_record_open(RECORD_STORAGE);
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
Stream* fff_data_stream =
Expand All @@ -57,7 +57,7 @@ void subghz_set_default_preset(SubGhz* subghz) {
SubGhzLoadKeyState load_key_state = SubGhzLoadKeyStateParseErr;
FuriString* temp_str = furi_string_alloc();
uint32_t temp_data32;
do {
stream_clean(fff_data_stream);
if(!flipper_format_file_open_existing(fff_data_file, file_path)) {
Expand Down Expand Up @@ -143,12 +143,12 @@ void subghz_set_default_preset(SubGhz* subghz) {

if(subghz_txrx_load_decoder_by_name_protocol(
subghz->txrx, furi_string_get_cstr(temp_str))) {
//SubGhzProtocolStatus status = subghz_protocol_decoder_base_deserialize(
// subghz_txrx_get_decoder(subghz->txrx), fff_data);
//if(status != SubGhzProtocolStatusOk) {
// load_key_state = SubGhzLoadKeyStateProtocolDescriptionErr;
// break;
//}
SubGhzProtocolStatus status = subghz_protocol_decoder_base_deserialize(
subghz_txrx_get_decoder(subghz->txrx), fff_data);
if(status != SubGhzProtocolStatusOk) {
load_key_state = SubGhzLoadKeyStateProtocolDescriptionErr;
break;
}
} else {
FURI_LOG_E(TAG, "Protocol not found");
break;
Expand All @@ -163,15 +163,15 @@ void subghz_set_default_preset(SubGhz* subghz) {

switch(load_key_state) {
case SubGhzLoadKeyStateParseErr:
if(show_dialog) {
dialog_message_show_storage_error(subghz->dialogs, "Cannot parse\nfile");
}
//if(show_dialog) {
// dialog_message_show_storage_error(subghz->dialogs, "Cannot parse\nfile");
//}
return false;
case SubGhzLoadKeyStateProtocolDescriptionErr:
if(show_dialog) {
dialog_message_show_storage_error(
subghz->dialogs, "Error in protocol\nparameters\ndescription");
}
//if(show_dialog) {
// dialog_message_show_storage_error(
// subghz->dialogs, "Error in protocol\nparameters\ndescription");
//}
return false;

case SubGhzLoadKeyStateOK:
Expand All @@ -181,19 +181,22 @@ void subghz_set_default_preset(SubGhz* subghz) {
furi_crash("SubGhz: Unknown load_key_state.");
return false;
}
}*/
return false;
}

/*SubGhzLoadTypeFile subghz_get_load_type_file(SubGhz* subghz) {
furi_assert(subghz);
return subghz->load_type_file;
}*/

/*bool subghz_load_protocol_from_file(SubGhz* subghz) {
bool subghz_load_protocol_from_file(SubGhz* subghz) {
furi_assert(subghz);

FuriString* file_path = furi_string_alloc();
//FuriString* file_path = furi_string_alloc();

bool res = false;

DialogsFileBrowserOptions browser_options;
/*DialogsFileBrowserOptions browser_options;
dialog_file_browser_set_basic_options(
&browser_options, SUBGHZ_APP_FILENAME_EXTENSION, &I_sub1_10px);
browser_options.base_path = SUBGHZ_APP_FOLDER;
Expand All @@ -202,14 +205,15 @@ void subghz_set_default_preset(SubGhz* subghz) {
bool res = dialog_file_browser_show(
subghz->dialogs, subghz->file_path, subghz->file_path, &browser_options);
if(res) {
res = subghz_key_load(subghz, furi_string_get_cstr(subghz->file_path), true);
}
if(res) {*/
//res = subghz_key_load(subghz, furi_string_get_cstr(subghz->file_path), true);
res = subghz_key_load(subghz, MEAL_PAGER_TMP_FILE); //, true);
//}

furi_string_free(file_path);
//furi_string_free(file_path);

return res;
}*/
}

/*bool subghz_file_available(SubGhz* subghz) {
furi_assert(subghz);
Expand Down
9 changes: 6 additions & 3 deletions helpers/subghz/subghz_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "subghz_error_type.h"
#include <lib/subghz/types.h>
#include "subghz.h"
#include "../meal_pager_storage.h"

/*#include "views/receiver.h"
#include "views/transmitter.h"
Expand Down Expand Up @@ -38,6 +39,8 @@

#define SUBGHZ_MAX_LEN_NAME 64

typedef struct SubGhz SubGhz;

struct SubGhz {
SubGhzTxRx* txrx;
FuriString* file_path;
Expand All @@ -57,7 +60,7 @@ struct SubGhz {
//SubGhzThresholdRssi* threshold_rssi;
//SubGhzRxKeyState rx_key_state;
//SubGhzHistory* history;
//SubGhzLoadTypeFile load_type_file;
SubGhzLoadTypeFile load_type_file;
//void* rpc_ctx;
};

Expand All @@ -68,8 +71,8 @@ struct SubGhz {
//bool subghz_tx_start(SubGhz* subghz, FlipperFormat* flipper_format);
//void subghz_dialog_message_show_only_rx(SubGhz* subghz);

//bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog);
//bool subghz_load_protocol_from_file(SubGhz* subghz);
bool subghz_key_load(SubGhz* subghz, const char* file_path); //, bool show_dialog);
bool subghz_load_protocol_from_file(SubGhz* subghz);
//bool subghz_file_available(SubGhz* subghz);
//SubGhzLoadTypeFile subghz_get_load_type_file(SubGhz* subghz);

Expand Down
45 changes: 28 additions & 17 deletions helpers/subghz/subghz_txrx.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ SubGhzTxRx* subghz_txrx_alloc() {
subghz_txrx_speaker_set_state(instance, SubGhzSpeakerStateDisable);

instance->worker = subghz_worker_alloc();
/* instance->fff_data = flipper_format_string_alloc(); */
instance->fff_data = flipper_format_string_alloc();

instance->environment = subghz_environment_alloc();
instance->is_database_loaded =
Expand Down Expand Up @@ -90,7 +90,7 @@ void subghz_txrx_free(SubGhzTxRx* instance) {
subghz_worker_free(instance->worker);
subghz_receiver_free(instance->receiver);
subghz_environment_free(instance->environment);
/*flipper_format_free(instance->fff_data);*/
flipper_format_free(instance->fff_data);
furi_string_free(instance->preset->name);
subghz_setting_free(instance->setting);

Expand All @@ -117,7 +117,7 @@ void subghz_txrx_set_preset(
preset->data_size = preset_data_size;
}

/*const char* subghz_txrx_get_preset_name(SubGhzTxRx* instance, const char* preset) {
const char* subghz_txrx_get_preset_name(SubGhzTxRx* instance, const char* preset) {
UNUSED(instance);
const char* preset_name = "";
if(!strcmp(preset, "FuriHalSubGhzPresetOok270Async")) {
Expand All @@ -134,7 +134,7 @@ void subghz_txrx_set_preset(
FURI_LOG_E(TAG, "Unknown preset");
}
return preset_name;
}*/
}

/*SubGhzRadioPreset subghz_txrx_get_preset(SubGhzTxRx* instance) {
furi_assert(instance);
Expand Down Expand Up @@ -244,6 +244,7 @@ SubGhzTxRxStartTxState subghz_txrx_tx_start(SubGhzTxRx* instance, FlipperFormat*

FURI_LOG_D(TAG, "starting loop in subghz_txrx_tx_start");
do {
FURI_LOG_D(TAG, "looping");
if(!flipper_format_rewind(flipper_format)) {
FURI_LOG_E(TAG, "Rewind error");
break;
Expand All @@ -256,25 +257,32 @@ SubGhzTxRxStartTxState subghz_txrx_tx_start(SubGhzTxRx* instance, FlipperFormat*
FURI_LOG_E(TAG, "Unable Repeat");
break;
}
//FURI_LOG_D(TAG, "File loaded");
ret = SubGhzTxRxStartTxStateOk;

SubGhzRadioPreset* preset = instance->preset;
instance->transmitter =
subghz_transmitter_alloc_init(instance->environment, furi_string_get_cstr(temp_str));

if(instance->transmitter) {
FURI_LOG_D(TAG, "transmitter found");
if(subghz_transmitter_deserialize(instance->transmitter, flipper_format) ==
SubGhzProtocolStatusOk) {
//if (false) {
FURI_LOG_D(TAG, "deserialization");
if(strcmp(furi_string_get_cstr(preset->name), "") != 0) {
FURI_LOG_D(TAG, "got preset name");
subghz_txrx_begin(
instance,
subghz_setting_get_preset_data_by_name(
instance->setting, furi_string_get_cstr(preset->name)));
FURI_LOG_D(TAG, "loaded preset by name");
if(preset->frequency) {
if(!subghz_txrx_tx(instance, preset->frequency)) {
FURI_LOG_E(TAG, "Only Rx");
ret = SubGhzTxRxStartTxStateErrorOnlyRx;
}
FURI_LOG_D(TAG, "got frequency");
} else {
ret = SubGhzTxRxStartTxStateErrorParserOthers;
}
Expand All @@ -287,17 +295,20 @@ SubGhzTxRxStartTxState subghz_txrx_tx_start(SubGhzTxRx* instance, FlipperFormat*

if(ret == SubGhzTxRxStartTxStateOk) {
//Start TX
FURI_LOG_D(TAG, "starting Async TX");
subghz_devices_start_async_tx(
instance->radio_device, subghz_transmitter_yield, instance->transmitter);
}
} else {
FURI_LOG_D(TAG, "no deserialization");
ret = SubGhzTxRxStartTxStateErrorParserOthers;
}
} else {
ret = SubGhzTxRxStartTxStateErrorParserOthers;
}
if(ret != SubGhzTxRxStartTxStateOk) {
subghz_transmitter_free(instance->transmitter);
FURI_LOG_D(TAG, "state not ok");
//subghz_transmitter_free(instance->transmitter); // Crashes here
if(instance->txrx_state != SubGhzTxRxStateIDLE) {
subghz_txrx_idle(instance);
}
Expand Down Expand Up @@ -344,15 +355,15 @@ static void subghz_txrx_tx_stop(SubGhzTxRx* instance) {
subghz_txrx_speaker_off(instance);
}

/*FlipperFormat* subghz_txrx_get_fff_data(SubGhzTxRx* instance) {
FlipperFormat* subghz_txrx_get_fff_data(SubGhzTxRx* instance) {
furi_assert(instance);
return instance->fff_data;
}*/
}

/*SubGhzSetting* subghz_txrx_get_setting(SubGhzTxRx* instance) {
SubGhzSetting* subghz_txrx_get_setting(SubGhzTxRx* instance) {
furi_assert(instance);
return instance->setting;
}*/
}

void subghz_txrx_stop(SubGhzTxRx* instance) {
furi_assert(instance);
Expand Down Expand Up @@ -496,7 +507,7 @@ void subghz_txrx_speaker_set_state(SubGhzTxRx* instance, SubGhzSpeakerState stat
return instance->speaker_state;
}*/

/*bool subghz_txrx_load_decoder_by_name_protocol(SubGhzTxRx* instance, const char* name_protocol) {
bool subghz_txrx_load_decoder_by_name_protocol(SubGhzTxRx* instance, const char* name_protocol) {
furi_assert(instance);
furi_assert(name_protocol);
bool res = false;
Expand All @@ -506,12 +517,12 @@ void subghz_txrx_speaker_set_state(SubGhzTxRx* instance, SubGhzSpeakerState stat
res = true;
}
return res;
}*/
}

/*SubGhzProtocolDecoderBase* subghz_txrx_get_decoder(SubGhzTxRx* instance) {
SubGhzProtocolDecoderBase* subghz_txrx_get_decoder(SubGhzTxRx* instance) {
furi_assert(instance);
return instance->decoder_result;
}*/
}

/*bool subghz_txrx_protocol_is_serializable(SubGhzTxRx* instance) {
furi_assert(instance);
Expand Down Expand Up @@ -608,12 +619,12 @@ SubGhzRadioDeviceType
return subghz_devices_get_rssi(instance->radio_device);
}*/

/*const char* subghz_txrx_radio_device_get_name(SubGhzTxRx* instance) {
const char* subghz_txrx_radio_device_get_name(SubGhzTxRx* instance) {
furi_assert(instance);
return subghz_devices_get_name(instance->radio_device);
}*/
}

/*bool subghz_txrx_radio_device_is_frequecy_valid(SubGhzTxRx* instance, uint32_t frequency) {
bool subghz_txrx_radio_device_is_frequecy_valid(SubGhzTxRx* instance, uint32_t frequency) {
furi_assert(instance);
return subghz_devices_is_frequency_valid(instance->radio_device, frequency);
}*/
}
Loading

0 comments on commit 49cfa7f

Please sign in to comment.