modify log file to provide PACS binary string only for downgrades

This commit is contained in:
Xavier 2023-11-21 16:13:09 -05:00
parent 07c286642b
commit 54785fe8d9

View File

@ -1,29 +1,38 @@
#include "../wiegand.h" #include "../wiegand.h"
void wiegand_data_scene_save_name_text_input_callback(void* context) { void wiegand_data_scene_save_name_text_input_callback(void *context)
{
App *app = context; App *app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, WiegandDataSceneSaveFileEvent); view_dispatcher_send_custom_event(app->view_dispatcher, WiegandDataSceneSaveFileEvent);
} }
void ensure_dir_exists(Storage* storage) { void ensure_dir_exists(Storage *storage)
{
// If apps_data directory doesn't exist, create it. // If apps_data directory doesn't exist, create it.
if(!storage_dir_exists(storage, WIEGAND_APPS_DATA_FOLDER)) { if (!storage_dir_exists(storage, WIEGAND_APPS_DATA_FOLDER))
{
FURI_LOG_I(TAG, "Creating directory: %s", WIEGAND_APPS_DATA_FOLDER); FURI_LOG_I(TAG, "Creating directory: %s", WIEGAND_APPS_DATA_FOLDER);
storage_simply_mkdir(storage, WIEGAND_APPS_DATA_FOLDER); storage_simply_mkdir(storage, WIEGAND_APPS_DATA_FOLDER);
} else { }
else
{
FURI_LOG_I(TAG, "Directory exists: %s", WIEGAND_APPS_DATA_FOLDER); FURI_LOG_I(TAG, "Directory exists: %s", WIEGAND_APPS_DATA_FOLDER);
} }
// If wiegand directory doesn't exist, create it. // If wiegand directory doesn't exist, create it.
if(!storage_dir_exists(storage, WIEGAND_SAVE_FOLDER)) { if (!storage_dir_exists(storage, WIEGAND_SAVE_FOLDER))
{
FURI_LOG_I(TAG, "Creating directory: %s", WIEGAND_SAVE_FOLDER); FURI_LOG_I(TAG, "Creating directory: %s", WIEGAND_SAVE_FOLDER);
storage_simply_mkdir(storage, WIEGAND_SAVE_FOLDER); storage_simply_mkdir(storage, WIEGAND_SAVE_FOLDER);
} else { }
else
{
FURI_LOG_I(TAG, "Directory exists: %s", WIEGAND_SAVE_FOLDER); FURI_LOG_I(TAG, "Directory exists: %s", WIEGAND_SAVE_FOLDER);
} }
} }
void wiegand_save(void* context) { void wiegand_save(void *context)
{
App *app = context; App *app = context;
FuriString *buffer = furi_string_alloc(1024); FuriString *buffer = furi_string_alloc(1024);
FuriString *file_path = furi_string_alloc(); FuriString *file_path = furi_string_alloc();
@ -34,7 +43,8 @@ void wiegand_save(void* context) {
ensure_dir_exists(storage); ensure_dir_exists(storage);
File *data_file = storage_file_alloc(storage); File *data_file = storage_file_alloc(storage);
if (storage_file_open( if (storage_file_open(
data_file, furi_string_get_cstr(file_path), FSAM_WRITE, FSOM_OPEN_ALWAYS)) { data_file, furi_string_get_cstr(file_path), FSAM_WRITE, FSOM_OPEN_ALWAYS))
{
furi_string_printf(buffer, "Filetype: Flipper Wiegand Key File\n"); furi_string_printf(buffer, "Filetype: Flipper Wiegand Key File\n");
storage_file_write(data_file, furi_string_get_cstr(buffer), furi_string_size(buffer)); storage_file_write(data_file, furi_string_get_cstr(buffer), furi_string_size(buffer));
furi_string_printf(buffer, "Version: 1\n"); furi_string_printf(buffer, "Version: 1\n");
@ -44,13 +54,9 @@ void wiegand_save(void* context) {
furi_string_printf(buffer, "Bits: %d\n", bit_count); furi_string_printf(buffer, "Bits: %d\n", bit_count);
storage_file_write(data_file, furi_string_get_cstr(buffer), furi_string_size(buffer)); storage_file_write(data_file, furi_string_get_cstr(buffer), furi_string_size(buffer));
furi_string_printf(buffer, "RAW_Data: "); furi_string_printf(buffer, "RAW_Data: ");
for(int i = 0; i < bit_count; i++) { for (int i = 0; i < bit_count; i++)
furi_string_cat_printf( {
buffer, furi_string_cat_printf(buffer, "%d", data[i] ? 1 : 0);
"D%d %ld %ld ",
data[i] ? 1 : 0,
data_fall[i] - data_fall[0],
data_rise[i] - data_fall[0]);
} }
furi_string_push_back(buffer, '\n'); furi_string_push_back(buffer, '\n');
storage_file_write(data_file, furi_string_get_cstr(buffer), furi_string_size(buffer)); storage_file_write(data_file, furi_string_get_cstr(buffer), furi_string_size(buffer));
@ -63,7 +69,8 @@ void wiegand_save(void* context) {
furi_string_free(buffer); furi_string_free(buffer);
} }
void wiegand_save_scene_on_enter(void* context) { void wiegand_save_scene_on_enter(void *context)
{
App *app = context; App *app = context;
text_input_reset(app->text_input); text_input_reset(app->text_input);
@ -93,12 +100,15 @@ void wiegand_save_scene_on_enter(void* context) {
view_dispatcher_switch_to_view(app->view_dispatcher, WiegandTextInputView); view_dispatcher_switch_to_view(app->view_dispatcher, WiegandTextInputView);
} }
bool wiegand_save_scene_on_event(void* context, SceneManagerEvent event) { bool wiegand_save_scene_on_event(void *context, SceneManagerEvent event)
{
App *app = context; App *app = context;
bool consumed = false; bool consumed = false;
switch(event.type) { switch (event.type)
{
case SceneManagerEventTypeCustom: case SceneManagerEventTypeCustom:
switch(event.event) { switch (event.event)
{
case WiegandDataSceneSaveFileEvent: case WiegandDataSceneSaveFileEvent:
wiegand_save(app); wiegand_save(app);
data_saved = true; data_saved = true;