Fix crashing bug -- can't append 1000s of times?

This commit is contained in:
Derek Jamison 2023-10-02 11:46:57 -05:00
parent 54c1f4fd13
commit 1044c0bf8c
5 changed files with 116 additions and 32 deletions

View File

@ -3,6 +3,18 @@
## Description
This program was written to allow the Flipper Zero to press buttons on a Genie garage door opened and record the rolling code. The goal is to capture all 65,536 signals (which hopefully repeats when it gets to the end). Our click speed is current 2000ms per click + however long it takes to get the signal. So if we assume it's 1000-1500/hr = about 3 days?
## Connecting to remote
<img src="wiring.png">
You only need to connect two wires between the Flipper and the remote. One wire is GND on the Flipper. It should connect to the pin that is the same as the battery negative pad on the remote. The second wire is the signal wire, it should connect to A7 on the Flipper Zero. On the remote side, it should connect to a pin that transmits the signal. If you remove the wires from the Flipper Zero and touch the two wires together, the remote should send a signal.
<p/><p/>
In my testing, a new CR2032 battery was able to send all 65,536 codes & still had power left over! IF YOU WANT TO USE THE FLIPPER 3V3 FOR A POWER SOURCE, THEN YOU MUST MAKE SURE THAT GND ON THE FLIPPER IS GOING TO GND ON THE REMOTE (and not the signal pin). IN YOU ARE 100% SURE, THEN YOU CAN REMOVE THE BATTERY FROM YOUR REMOTE AND CONNECT 3V3 PIN ON THE FLIPPER TO THE BATTERY POSITIVE BAR ON THE REMOTE.
<p/><p/>
WARNING -- For my remote, the codes wrapped after 65,536 codes were sent. I'm not sure if this is the case for all remotes. If it doesn't wrap, it's possible that the remote could stop working (if the manufacture implemented OVR bits).
<p/><p/>
WARNING -- This could desync your remote from the receiver.
<p/><p/>
WARNING -- Don't run this near your garage. There is no reason to open the physical garage door & you will likely burn out the motor.
## Running
Step 1. Deploy custom firmware (keeloq.c with te_short=200, te_long=400, te_delta=70)
Step 2. Connect a genie garage door opener to pins A7 and GND.

View File

@ -88,13 +88,12 @@ void genie_view_draw_callback(Canvas* canvas, void* model) {
canvas_draw_str(canvas, 5, 15, "Genie Sub-Ghz Recorder!!!");
canvas_draw_str(canvas, 5, 30, "Make sure A7 is connected");
canvas_draw_str(canvas, 100, 58, (app->pressed) ? "SEND" : "");
FuriString* buffer = furi_string_alloc();
furi_string_printf(buffer, "%ld", app->counter);
canvas_draw_str(canvas, 50, 45, furi_string_get_cstr(buffer));
furi_string_printf(buffer, "%ld", app->save_counter);
canvas_draw_str(canvas, 96, 45, furi_string_get_cstr(buffer));
char buffer[20] = {0};
snprintf(buffer, COUNT_OF(buffer), "%ld", app->counter);
canvas_draw_str(canvas, 50, 45, buffer);
snprintf(buffer, COUNT_OF(buffer), "%ld", app->save_counter);
canvas_draw_str(canvas, 96, 45, buffer);
canvas_draw_str(canvas, 5, 55, furi_string_get_cstr(app->key));
furi_string_free(buffer);
}
bool genie_view_input_callback(InputEvent* event, void* context) {
@ -166,6 +165,7 @@ void genie_tick(void* context) {
void genie_enter_callback(void* context) {
GenieApp* app = (GenieApp*)context;
genie_file_init();
start_listening(app->genie_subghz, FREQUENCY, genie_packet, context);
furi_timer_start(app->timer, furi_ms_to_ticks(CLICK_SPEED));
}
@ -176,6 +176,7 @@ void genie_exit_callback(void* context) {
release_button(app);
stop_listening(app->genie_subghz);
furi_timer_stop(app->timer);
genie_file_close();
}
GenieApp* genie_app_alloc() {
@ -251,8 +252,32 @@ void genie_app_free(GenieApp* app) {
int32_t genie_record_app(void* p) {
UNUSED(p);
Storage* storage = furi_record_open(RECORD_STORAGE);
storage_simply_remove(storage, "/ext/apps_data/bug.txt");
furi_record_close(RECORD_STORAGE);
storage = furi_record_open(RECORD_STORAGE);
for(uint32_t i = 0; i < 0x4000; i++) {
File* file = storage_file_alloc(storage);
if(storage_file_open(file, "/ext/apps_data/bug.txt", FSAM_WRITE, FSOM_OPEN_APPEND)) {
if(!storage_file_write(file, "1", 1)) {
FURI_LOG_E(TAG, "Failed to write to file");
} else {
FURI_LOG_E(TAG, "%lX", i);
}
} else {
FURI_LOG_E(TAG, "Failed to open file");
}
storage_file_close(file);
}
furi_record_close(RECORD_STORAGE);
/*
GenieApp* app = genie_app_alloc();
view_dispatcher_run(app->view_dispatcher);
genie_app_free(app);
*/
return 0;
}

View File

@ -27,47 +27,91 @@ static void ensure_save_folder_exists(Storage* storage) {
ensure_dir_exists(storage, GENIE_SAVE_FOLDER);
}
bool genie_save(uint32_t count, FuriString* key) {
bool success = false;
Storage* storage = furi_record_open(RECORD_STORAGE);
FuriString* file_path = furi_string_alloc();
Storage* _storage;
File* _file;
FuriString* buffer = furi_string_alloc();
furi_string_printf(buffer, "%08lX,%s\r\n", count, furi_string_get_cstr(key));
furi_string_printf(
file_path, "%s/%s%s", GENIE_SAVE_FOLDER, GENIE_SAVE_NAME, GENIE_SAVE_EXTENSION);
File* file = NULL;
do {
if(!storage) {
FURI_LOG_E(TAG, "Failed to access storage");
break;
void genie_file_init() {
_storage = furi_record_open(RECORD_STORAGE);
ensure_save_folder_exists(_storage);
_file = storage_file_alloc(_storage);
storage_file_open(
_file,
(GENIE_SAVE_FOLDER "/" GENIE_SAVE_NAME GENIE_SAVE_EXTENSION),
FSAM_WRITE,
FSOM_OPEN_APPEND);
}
ensure_save_folder_exists(storage);
void genie_file_close() {
if(_file) {
storage_file_close(_file);
_file = NULL;
}
file = storage_file_alloc(storage);
if(storage_file_open(file, furi_string_get_cstr(file_path), FSAM_WRITE, FSOM_OPEN_APPEND)) {
FURI_LOG_D(TAG, "Writing to file: %s", furi_string_get_cstr(file_path));
if(_storage) {
furi_record_close(RECORD_STORAGE);
_storage = NULL;
}
}
if(!storage_file_write(file, furi_string_get_cstr(buffer), furi_string_size(buffer))) {
void demo() {
Storage* storage = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(storage);
if(storage_file_open(
file,
(GENIE_SAVE_FOLDER "/" GENIE_SAVE_NAME GENIE_SAVE_EXTENSION),
FSAM_WRITE,
FSOM_OPEN_APPEND)) {
if(!storage_file_write(_file, "Hello\r\n", 7)) {
FURI_LOG_E(TAG, "Failed to write to file");
}
} else {
FURI_LOG_E(TAG, "Failed to open file");
}
storage_file_close(file);
furi_record_close(RECORD_STORAGE);
}
bool genie_save(uint32_t count, FuriString* key) {
bool success = false;
// Storage* storage = furi_record_open(RECORD_STORAGE);
char buffer[8 + 1 + 16 + 2 + 1] = {0};
snprintf(buffer, 8 + 1 + 16 + 2 + 1, "%08lX,%s\r\n", count, furi_string_get_cstr(key));
// File* file = NULL;
do {
// if(!storage) {
// FURI_LOG_E(TAG, "Failed to access storage");
// break;
// }
// file = storage_file_alloc(storage);
// if(storage_file_open(
// file,
// (GENIE_SAVE_FOLDER "/" GENIE_SAVE_NAME GENIE_SAVE_EXTENSION),
// FSAM_WRITE,
// FSOM_OPEN_APPEND))
if(_file == NULL) {
genie_file_init();
}
if(_file) {
if(!storage_file_write(_file, buffer, COUNT_OF(buffer) - 1)) {
FURI_LOG_E(TAG, "Failed to write to file");
break;
}
storage_file_sync(_file);
success = true;
}
} while(false);
if(file) {
storage_file_close(file);
}
// if(file) {
// storage_file_close(file);
// }
furi_string_free(file_path);
furi_string_free(buffer);
furi_record_close(RECORD_STORAGE);
// furi_record_close(RECORD_STORAGE);
return success;
}

View File

@ -4,3 +4,6 @@
bool genie_save(uint32_t count, FuriString* key);
uint32_t genie_load();
void genie_file_init();
void genie_file_close();

Binary file not shown.

After

Width:  |  Height:  |  Size: 319 KiB