Skip to content

Commit

Permalink
Stop Programm if cannot open tmp file
Browse files Browse the repository at this point in the history
  • Loading branch information
David Lee committed Jan 3, 2024
1 parent c934ddd commit 238a5b3
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 14 deletions.
16 changes: 9 additions & 7 deletions helpers/meal_pager_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@ static void meal_pager_close_config_file(FlipperFormat* file) {
flipper_format_free(file);
}

FlipperFormat* meal_pager_save_subghz_buffer_file_start(void* context, Storage* storage) {
bool meal_pager_save_subghz_buffer_file_start(void* context, FlipperFormat* ff, Storage* storage) {
// SubGhz TXRX can only be loaded with files, makes sense as to save RAM
Meal_Pager* app = context;
UNUSED(app);
bool success = false;
FURI_LOG_D(TAG, "Creating Temp File");
//Storage* storage = furi_record_open(RECORD_STORAGE);
FlipperFormat* ff = flipper_format_file_alloc(storage);
//FlipperFormat* ff = flipper_format_file_alloc(storage);

// Overwrite wont work, so delete first
if(storage_file_exists(storage, MEAL_PAGER_TMP_FILE)) {
bool stored = storage_simply_remove(storage, MEAL_PAGER_TMP_FILE);
if (!stored) {
FURI_LOG_D(TAG, "Cannot remove file, seems to be open");
return success;
}
}

Expand All @@ -49,16 +51,16 @@ FlipperFormat* meal_pager_save_subghz_buffer_file_start(void* context, Storage*
//totp_close_config_file(fff_file);
FURI_LOG_D(TAG, "Error creating new file %s", MEAL_PAGER_TMP_FILE);
meal_pager_close_storage();
return ff;
return success;
}

bool success = flipper_format_write_header_cstr(ff, MEAL_PAGER_SUBGHZ_FILE_TYPE, MEAL_PAGER_SUBGHZ_FILE_VERSION) &&
success = flipper_format_write_header_cstr(ff, MEAL_PAGER_SUBGHZ_FILE_TYPE, MEAL_PAGER_SUBGHZ_FILE_VERSION) &&
flipper_format_write_string_cstr(ff, "Frequency", MEAL_PAGER_SUBGHZ_FILE_FREQUENCY) &&
flipper_format_write_string_cstr(ff, "Preset", MEAL_PAGER_SUBGHZ_FILE_PRESET) &&
flipper_format_write_string_cstr(ff, "Protocol", MEAL_PAGER_SUBGHZ_FILE_Protocol);
UNUSED(success);

return ff;
//UNUSED(success);
return success;
//return ff;
}

void meal_pager_save_subghz_buffer_stop(void* context, FlipperFormat* ff) {
Expand Down
2 changes: 1 addition & 1 deletion helpers/meal_pager_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#define MEAL_PAGER_SUBGHZ_FILE_PRESET "FuriHalSubGhzPresetOok650Async"
#define MEAL_PAGER_SUBGHZ_FILE_Protocol "RAW"

FlipperFormat* meal_pager_save_subghz_buffer_file_start(void* context, Storage* storage);
bool meal_pager_save_subghz_buffer_file_start(void* context, FlipperFormat* ff, Storage* storage);

void meal_pager_save_subghz_buffer_stop(void* context, FlipperFormat* ff);

Expand Down
15 changes: 12 additions & 3 deletions helpers/retekess/meal_pager_retekess_t119.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,23 @@ static void meal_pager_retekess_t119_generate_station(void* context, uint32_t st
}
}

void meal_pager_retekess_t119_generate_all(void* context) {
bool meal_pager_retekess_t119_generate_all(void* context) {
Meal_Pager* app = context;

app->current_pager = 1;
app->current_station = app->first_station;

Storage* storage = furi_record_open(RECORD_STORAGE);
FlipperFormat* ff = meal_pager_save_subghz_buffer_file_start(app, storage);

FlipperFormat* ff = flipper_format_file_alloc(storage);
bool success = meal_pager_save_subghz_buffer_file_start(app, ff, storage);

if (!success) {
FURI_LOG_D(TAG, "failed to save buffer");
meal_pager_save_subghz_buffer_stop(app, ff);
furi_record_close(RECORD_STORAGE);
return success;
}

for (u_int32_t i = app->current_station;i <= app->last_station; i++) {
meal_pager_retekess_t119_generate_station(app, i, ff);
//furi_thread_flags_wait(0, FuriFlagWaitAny, 100);
Expand All @@ -199,5 +207,6 @@ void meal_pager_retekess_t119_generate_all(void* context) {

meal_pager_save_subghz_buffer_stop(app, ff);
furi_record_close(RECORD_STORAGE);
return success;
}

2 changes: 1 addition & 1 deletion helpers/retekess/meal_pager_retekess_t119.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ void customConcat(char* dest, const char* src);

//void meal_pager_retekess_t119_generate_station(void* context, uint32_t station);

void meal_pager_retekess_t119_generate_all(void* context);
bool meal_pager_retekess_t119_generate_all(void* context);
2 changes: 1 addition & 1 deletion helpers/subghz/subghz_txrx.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ SubGhzTxRxStartTxState subghz_txrx_tx_start(SubGhzTxRx* instance, FlipperFormat*
}
if(ret != SubGhzTxRxStartTxStateOk) {
FURI_LOG_D(TAG, "state not ok");
//subghz_transmitter_free(instance->transmitter); // Crashes here
subghz_transmitter_free(instance->transmitter); // Crashes here
if(instance->txrx_state != SubGhzTxRxStateIDLE) {
subghz_txrx_idle(instance);
}
Expand Down
7 changes: 6 additions & 1 deletion scenes/meal_pager_scene_transmit.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ void meal_pager_scene_transmit_on_enter(void* context) {
meal_pager_transmit_model_set_pager(app->meal_pager_transmit, app->current_pager);
meal_pager_transmit_set_callback(app->meal_pager_transmit, meal_pager_transmit_callback, app);
view_dispatcher_switch_to_view(app->view_dispatcher, Meal_PagerViewIdTransmit);
meal_pager_retekess_t119_generate_all(app);
bool generated = meal_pager_retekess_t119_generate_all(app);
if (!generated) {
FURI_LOG_D(TAG, "Could not generate temp file");
meal_pager_blink_stop(app);
return;
}
FURI_LOG_D(TAG, "Generated tmp.sub");
meal_pager_blink_start_subghz(app);
FURI_LOG_D(TAG, "Start Transmitting");
Expand Down

0 comments on commit 238a5b3

Please sign in to comment.