mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-10 15:04:19 +00:00
Merge branch 'fz-dev' into dev
This commit is contained in:
commit
f3ab4bc292
143 changed files with 4716 additions and 2754 deletions
|
@ -44,3 +44,6 @@
|
|||
|
||||
# Functions that always return the same error code
|
||||
//-V:picopass_device_decrypt:1048
|
||||
|
||||
# Examples
|
||||
//V_EXCLUDE_PATH applications/examples/
|
|
@ -191,7 +191,7 @@ static void clean_directory(Storage* fs_api, const char* clean_dir) {
|
|||
size_t size = strlen(clean_dir) + strlen(name) + 1 + 1;
|
||||
char* fullname = malloc(size);
|
||||
snprintf(fullname, size, "%s/%s", clean_dir, name);
|
||||
if(fileinfo.flags & FSF_DIRECTORY) {
|
||||
if(file_info_is_dir(&fileinfo)) {
|
||||
clean_directory(fs_api, fullname);
|
||||
}
|
||||
FS_Error error = storage_common_remove(fs_api, fullname);
|
||||
|
@ -608,9 +608,8 @@ static void test_rpc_storage_list_create_expected_list(
|
|||
}
|
||||
|
||||
if(path_contains_only_ascii(name)) {
|
||||
list->file[i].type = (fileinfo.flags & FSF_DIRECTORY) ?
|
||||
PB_Storage_File_FileType_DIR :
|
||||
PB_Storage_File_FileType_FILE;
|
||||
list->file[i].type = file_info_is_dir(&fileinfo) ? PB_Storage_File_FileType_DIR :
|
||||
PB_Storage_File_FileType_FILE;
|
||||
list->file[i].size = fileinfo.size;
|
||||
list->file[i].data = NULL;
|
||||
/* memory free inside rpc_encode_and_send() -> pb_release() */
|
||||
|
@ -873,7 +872,7 @@ static void test_rpc_storage_stat_run(const char* path, uint32_t command_id) {
|
|||
if(error == FSE_OK) {
|
||||
response->which_content = PB_Main_storage_stat_response_tag;
|
||||
response->content.storage_stat_response.has_file = true;
|
||||
response->content.storage_stat_response.file.type = (fileinfo.flags & FSF_DIRECTORY) ?
|
||||
response->content.storage_stat_response.file.type = file_info_is_dir(&fileinfo) ?
|
||||
PB_Storage_File_FileType_DIR :
|
||||
PB_Storage_File_FileType_FILE;
|
||||
response->content.storage_stat_response.file.size = fileinfo.size;
|
||||
|
|
|
@ -179,7 +179,7 @@ MU_TEST_1(test_dirwalk_full, Storage* storage) {
|
|||
|
||||
while(dir_walk_read(dir_walk, path, &fileinfo) == DirWalkOK) {
|
||||
furi_string_right(path, strlen(EXT_PATH("dirwalk/")));
|
||||
mu_check(storage_test_paths_mark(paths, path, (fileinfo.flags & FSF_DIRECTORY)));
|
||||
mu_check(storage_test_paths_mark(paths, path, file_info_is_dir(&fileinfo)));
|
||||
}
|
||||
|
||||
dir_walk_free(dir_walk);
|
||||
|
@ -204,7 +204,7 @@ MU_TEST_1(test_dirwalk_no_recursive, Storage* storage) {
|
|||
|
||||
while(dir_walk_read(dir_walk, path, &fileinfo) == DirWalkOK) {
|
||||
furi_string_right(path, strlen(EXT_PATH("dirwalk/")));
|
||||
mu_check(storage_test_paths_mark(paths, path, (fileinfo.flags & FSF_DIRECTORY)));
|
||||
mu_check(storage_test_paths_mark(paths, path, file_info_is_dir(&fileinfo)));
|
||||
}
|
||||
|
||||
dir_walk_free(dir_walk);
|
||||
|
@ -219,7 +219,7 @@ static bool test_dirwalk_filter_no_folder_ext(const char* name, FileInfo* filein
|
|||
UNUSED(ctx);
|
||||
|
||||
// only files
|
||||
if(!(fileinfo->flags & FSF_DIRECTORY)) {
|
||||
if(!file_info_is_dir(fileinfo)) {
|
||||
// with ".test" in name
|
||||
if(strstr(name, ".test") != NULL) {
|
||||
return true;
|
||||
|
@ -243,7 +243,7 @@ MU_TEST_1(test_dirwalk_filter, Storage* storage) {
|
|||
|
||||
while(dir_walk_read(dir_walk, path, &fileinfo) == DirWalkOK) {
|
||||
furi_string_right(path, strlen(EXT_PATH("dirwalk/")));
|
||||
mu_check(storage_test_paths_mark(paths, path, (fileinfo.flags & FSF_DIRECTORY)));
|
||||
mu_check(storage_test_paths_mark(paths, path, file_info_is_dir(&fileinfo)));
|
||||
}
|
||||
|
||||
dir_walk_free(dir_walk);
|
||||
|
|
|
@ -2,9 +2,40 @@
|
|||
#include <furi.h>
|
||||
#include <storage/storage.h>
|
||||
|
||||
// DO NOT USE THIS IN PRODUCTION CODE
|
||||
// This is a hack to access internal storage functions and definitions
|
||||
#include <storage/storage_i.h>
|
||||
|
||||
#define UNIT_TESTS_PATH(path) EXT_PATH("unit_tests/" path)
|
||||
|
||||
#define STORAGE_LOCKED_FILE EXT_PATH("locked_file.test")
|
||||
#define STORAGE_LOCKED_DIR STORAGE_INT_PATH_PREFIX
|
||||
|
||||
#define STORAGE_TEST_DIR UNIT_TESTS_PATH("test_dir")
|
||||
|
||||
static bool storage_file_create(Storage* storage, const char* path, const char* data) {
|
||||
File* file = storage_file_alloc(storage);
|
||||
bool result = false;
|
||||
do {
|
||||
if(!storage_file_open(file, path, FSAM_WRITE, FSOM_CREATE_NEW)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(storage_file_write(file, data, strlen(data)) != strlen(data)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(!storage_file_close(file)) {
|
||||
break;
|
||||
}
|
||||
|
||||
result = true;
|
||||
} while(0);
|
||||
|
||||
storage_file_free(file);
|
||||
return result;
|
||||
}
|
||||
|
||||
static void storage_file_open_lock_setup() {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
File* file = storage_file_alloc(storage);
|
||||
|
@ -115,7 +146,7 @@ static int32_t storage_dir_locker(void* ctx) {
|
|||
File* file = storage_file_alloc(storage);
|
||||
furi_check(storage_dir_open(file, STORAGE_LOCKED_DIR));
|
||||
furi_semaphore_release(semaphore);
|
||||
furi_delay_ms(1000);
|
||||
furi_delay_ms(100);
|
||||
|
||||
furi_check(storage_dir_close(file));
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
@ -152,9 +183,21 @@ MU_TEST(storage_dir_open_lock) {
|
|||
mu_assert(result, "cannot open locked dir");
|
||||
}
|
||||
|
||||
MU_TEST(storage_dir_exists_test) {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
mu_check(!storage_dir_exists(storage, STORAGE_TEST_DIR));
|
||||
mu_assert_int_eq(FSE_OK, storage_common_mkdir(storage, STORAGE_TEST_DIR));
|
||||
mu_check(storage_dir_exists(storage, STORAGE_TEST_DIR));
|
||||
mu_assert_int_eq(FSE_OK, storage_common_remove(storage, STORAGE_TEST_DIR));
|
||||
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
MU_TEST_SUITE(storage_dir) {
|
||||
MU_RUN_TEST(storage_dir_open_close);
|
||||
MU_RUN_TEST(storage_dir_open_lock);
|
||||
MU_RUN_TEST(storage_dir_exists_test);
|
||||
}
|
||||
|
||||
static const char* const storage_copy_test_paths[] = {
|
||||
|
@ -303,9 +346,256 @@ MU_TEST_SUITE(storage_rename) {
|
|||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
#define APPSDATA_APP_PATH(path) APPS_DATA_PATH "/" path
|
||||
|
||||
static const char* storage_test_apps[] = {
|
||||
"-_twilight_-",
|
||||
"-_rainbow_-",
|
||||
"-_pinkie_-",
|
||||
"-_apple_-",
|
||||
"-_flutter_-",
|
||||
"-_rare_-",
|
||||
};
|
||||
|
||||
static size_t storage_test_apps_count = COUNT_OF(storage_test_apps);
|
||||
|
||||
static int32_t storage_test_app(void* arg) {
|
||||
UNUSED(arg);
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
storage_common_remove(storage, "/app/test");
|
||||
int32_t ret = storage_file_create(storage, "/app/test", "test");
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
return ret;
|
||||
}
|
||||
|
||||
MU_TEST(test_storage_data_path_apps) {
|
||||
for(size_t i = 0; i < storage_test_apps_count; i++) {
|
||||
FuriThread* thread =
|
||||
furi_thread_alloc_ex(storage_test_apps[i], 1024, storage_test_app, NULL);
|
||||
furi_thread_set_appid(thread, storage_test_apps[i]);
|
||||
furi_thread_start(thread);
|
||||
furi_thread_join(thread);
|
||||
|
||||
mu_assert_int_eq(true, furi_thread_get_return_code(thread));
|
||||
|
||||
// Check if app data dir and file exists
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FuriString* expected = furi_string_alloc();
|
||||
furi_string_printf(expected, APPSDATA_APP_PATH("%s"), storage_test_apps[i]);
|
||||
|
||||
mu_check(storage_dir_exists(storage, furi_string_get_cstr(expected)));
|
||||
furi_string_cat(expected, "/test");
|
||||
mu_check(storage_file_exists(storage, furi_string_get_cstr(expected)));
|
||||
|
||||
furi_string_printf(expected, APPSDATA_APP_PATH("%s"), storage_test_apps[i]);
|
||||
storage_simply_remove_recursive(storage, furi_string_get_cstr(expected));
|
||||
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
furi_string_free(expected);
|
||||
furi_thread_free(thread);
|
||||
}
|
||||
}
|
||||
|
||||
MU_TEST(test_storage_data_path) {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
File* file = storage_file_alloc(storage);
|
||||
mu_check(storage_dir_open(file, "/app"));
|
||||
mu_check(storage_dir_close(file));
|
||||
storage_file_free(file);
|
||||
|
||||
// check that appsdata folder exists
|
||||
mu_check(storage_dir_exists(storage, APPS_DATA_PATH));
|
||||
|
||||
// check that cli folder exists
|
||||
mu_check(storage_dir_exists(storage, APPSDATA_APP_PATH("cli")));
|
||||
|
||||
storage_simply_remove(storage, APPSDATA_APP_PATH("cli"));
|
||||
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
MU_TEST(test_storage_common_migrate) {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
// Setup test folders
|
||||
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_old"));
|
||||
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_new"));
|
||||
|
||||
// Test migration from non existing
|
||||
mu_assert_int_eq(
|
||||
FSE_OK,
|
||||
storage_common_migrate(
|
||||
storage, UNIT_TESTS_PATH("migrate_old"), UNIT_TESTS_PATH("migrate_new")));
|
||||
|
||||
// Test migration from existing folder to non existing
|
||||
mu_assert_int_eq(FSE_OK, storage_common_mkdir(storage, UNIT_TESTS_PATH("migrate_old")));
|
||||
mu_check(storage_file_create(storage, UNIT_TESTS_PATH("migrate_old/file1"), "test1"));
|
||||
mu_check(storage_file_create(storage, UNIT_TESTS_PATH("migrate_old/file2.ext"), "test2"));
|
||||
mu_check(storage_file_create(storage, UNIT_TESTS_PATH("migrate_old/file3.ext.ext"), "test3"));
|
||||
mu_assert_int_eq(
|
||||
FSE_OK,
|
||||
storage_common_migrate(
|
||||
storage, UNIT_TESTS_PATH("migrate_old"), UNIT_TESTS_PATH("migrate_new")));
|
||||
|
||||
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new/file1")));
|
||||
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new/file2.ext")));
|
||||
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new/file3.ext.ext")));
|
||||
mu_check(storage_dir_exists(storage, UNIT_TESTS_PATH("migrate_new")));
|
||||
mu_check(!storage_dir_exists(storage, UNIT_TESTS_PATH("migrate_old")));
|
||||
|
||||
// Test migration from existing folder to existing folder
|
||||
mu_assert_int_eq(FSE_OK, storage_common_mkdir(storage, UNIT_TESTS_PATH("migrate_old")));
|
||||
mu_check(storage_file_create(storage, UNIT_TESTS_PATH("migrate_old/file1"), "test1"));
|
||||
mu_check(storage_file_create(storage, UNIT_TESTS_PATH("migrate_old/file2.ext"), "test2"));
|
||||
mu_check(storage_file_create(storage, UNIT_TESTS_PATH("migrate_old/file3.ext.ext"), "test3"));
|
||||
|
||||
mu_assert_int_eq(
|
||||
FSE_OK,
|
||||
storage_common_migrate(
|
||||
storage, UNIT_TESTS_PATH("migrate_old"), UNIT_TESTS_PATH("migrate_new")));
|
||||
|
||||
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new/file1")));
|
||||
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new/file2.ext")));
|
||||
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new/file3.ext.ext")));
|
||||
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new/file11")));
|
||||
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new/file21.ext")));
|
||||
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new/file3.ext1.ext")));
|
||||
mu_check(storage_dir_exists(storage, UNIT_TESTS_PATH("migrate_new")));
|
||||
mu_check(!storage_dir_exists(storage, UNIT_TESTS_PATH("migrate_old")));
|
||||
|
||||
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_old"));
|
||||
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_new"));
|
||||
|
||||
// Test migration from empty folder to existing file
|
||||
// Expected result: FSE_OK, folder removed, file untouched
|
||||
mu_assert_int_eq(FSE_OK, storage_common_mkdir(storage, UNIT_TESTS_PATH("migrate_old")));
|
||||
mu_check(storage_file_create(storage, UNIT_TESTS_PATH("migrate_new"), "test1"));
|
||||
|
||||
mu_assert_int_eq(
|
||||
FSE_OK,
|
||||
storage_common_migrate(
|
||||
storage, UNIT_TESTS_PATH("migrate_old"), UNIT_TESTS_PATH("migrate_new")));
|
||||
|
||||
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new")));
|
||||
mu_check(!storage_dir_exists(storage, UNIT_TESTS_PATH("migrate_old")));
|
||||
|
||||
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_old"));
|
||||
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_new"));
|
||||
|
||||
// Test migration from empty folder to existing folder
|
||||
// Expected result: FSE_OK, old folder removed, new folder untouched
|
||||
mu_assert_int_eq(FSE_OK, storage_common_mkdir(storage, UNIT_TESTS_PATH("migrate_old")));
|
||||
mu_assert_int_eq(FSE_OK, storage_common_mkdir(storage, UNIT_TESTS_PATH("migrate_new")));
|
||||
|
||||
mu_assert_int_eq(
|
||||
FSE_OK,
|
||||
storage_common_migrate(
|
||||
storage, UNIT_TESTS_PATH("migrate_old"), UNIT_TESTS_PATH("migrate_new")));
|
||||
|
||||
mu_check(storage_dir_exists(storage, UNIT_TESTS_PATH("migrate_new")));
|
||||
mu_check(!storage_dir_exists(storage, UNIT_TESTS_PATH("migrate_old")));
|
||||
|
||||
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_old"));
|
||||
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_new"));
|
||||
|
||||
// Test migration from existing file to non existing, no extension
|
||||
mu_check(storage_file_create(storage, UNIT_TESTS_PATH("migrate_old"), "test1"));
|
||||
|
||||
mu_assert_int_eq(
|
||||
FSE_OK,
|
||||
storage_common_migrate(
|
||||
storage, UNIT_TESTS_PATH("migrate_old"), UNIT_TESTS_PATH("migrate_new")));
|
||||
|
||||
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new")));
|
||||
mu_check(!storage_file_exists(storage, UNIT_TESTS_PATH("migrate_old")));
|
||||
|
||||
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_old"));
|
||||
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_new"));
|
||||
|
||||
// Test migration from existing file to non existing, with extension
|
||||
mu_check(storage_file_create(storage, UNIT_TESTS_PATH("migrate_old.file"), "test1"));
|
||||
|
||||
mu_assert_int_eq(
|
||||
FSE_OK,
|
||||
storage_common_migrate(
|
||||
storage, UNIT_TESTS_PATH("migrate_old.file"), UNIT_TESTS_PATH("migrate_new.file")));
|
||||
|
||||
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new.file")));
|
||||
mu_check(!storage_file_exists(storage, UNIT_TESTS_PATH("migrate_old.file")));
|
||||
|
||||
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_old.file"));
|
||||
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_new.file"));
|
||||
|
||||
// Test migration from existing file to existing file, no extension
|
||||
mu_check(storage_file_create(storage, UNIT_TESTS_PATH("migrate_old"), "test1"));
|
||||
mu_check(storage_file_create(storage, UNIT_TESTS_PATH("migrate_new"), "test2"));
|
||||
|
||||
mu_assert_int_eq(
|
||||
FSE_OK,
|
||||
storage_common_migrate(
|
||||
storage, UNIT_TESTS_PATH("migrate_old"), UNIT_TESTS_PATH("migrate_new")));
|
||||
|
||||
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new")));
|
||||
mu_check(!storage_file_exists(storage, UNIT_TESTS_PATH("migrate_old")));
|
||||
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new1")));
|
||||
|
||||
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_old"));
|
||||
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_new"));
|
||||
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_new1"));
|
||||
|
||||
// Test migration from existing file to existing file, with extension
|
||||
mu_check(storage_file_create(storage, UNIT_TESTS_PATH("migrate_old.file"), "test1"));
|
||||
mu_check(storage_file_create(storage, UNIT_TESTS_PATH("migrate_new.file"), "test2"));
|
||||
|
||||
mu_assert_int_eq(
|
||||
FSE_OK,
|
||||
storage_common_migrate(
|
||||
storage, UNIT_TESTS_PATH("migrate_old.file"), UNIT_TESTS_PATH("migrate_new.file")));
|
||||
|
||||
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new.file")));
|
||||
mu_check(!storage_file_exists(storage, UNIT_TESTS_PATH("migrate_old.file")));
|
||||
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new1.file")));
|
||||
|
||||
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_old.file"));
|
||||
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_new.file"));
|
||||
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_new1.file"));
|
||||
|
||||
// Test migration from existing file to existing folder
|
||||
mu_check(storage_file_create(storage, UNIT_TESTS_PATH("migrate_old"), "test1"));
|
||||
mu_assert_int_eq(FSE_OK, storage_common_mkdir(storage, UNIT_TESTS_PATH("migrate_new")));
|
||||
|
||||
mu_assert_int_eq(
|
||||
FSE_OK,
|
||||
storage_common_migrate(
|
||||
storage, UNIT_TESTS_PATH("migrate_old"), UNIT_TESTS_PATH("migrate_new")));
|
||||
|
||||
mu_check(storage_dir_exists(storage, UNIT_TESTS_PATH("migrate_new")));
|
||||
mu_check(!storage_file_exists(storage, UNIT_TESTS_PATH("migrate_old")));
|
||||
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new1")));
|
||||
|
||||
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_old"));
|
||||
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_new"));
|
||||
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_new1"));
|
||||
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
MU_TEST_SUITE(test_data_path) {
|
||||
MU_RUN_TEST(test_storage_data_path);
|
||||
MU_RUN_TEST(test_storage_data_path_apps);
|
||||
}
|
||||
|
||||
MU_TEST_SUITE(test_storage_common) {
|
||||
MU_RUN_TEST(test_storage_common_migrate);
|
||||
}
|
||||
|
||||
int run_minunit_test_storage() {
|
||||
MU_RUN_SUITE(storage_file);
|
||||
MU_RUN_SUITE(storage_dir);
|
||||
MU_RUN_SUITE(storage_rename);
|
||||
MU_RUN_SUITE(test_data_path);
|
||||
MU_RUN_SUITE(test_storage_common);
|
||||
return MU_EXIT_CODE;
|
||||
}
|
||||
|
|
18
applications/examples/example_apps_data/README.md
Normal file
18
applications/examples/example_apps_data/README.md
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Apps Data folder Example
|
||||
|
||||
This example demonstrates how to utilize the Apps Data folder to store data that is not part of the app itself, such as user data, configuration files, and so forth.
|
||||
|
||||
## What is the Apps Data Folder?
|
||||
|
||||
The **Apps Data** folder is a folder used to store data for external apps that are not part of the main firmware.
|
||||
|
||||
The path to the current application folder is related to the `appid` of the app. The `appid` is used to identify the app in the app store and is stored in the `application.fam` file.
|
||||
The Apps Data folder is located only on the external storage, the SD card.
|
||||
|
||||
For example, if the `appid` of the app is `snake_game`, the path to the Apps Data folder will be `/ext/apps_data/snake_game`. But using raw paths is not recommended, because the path to the Apps Data folder can change in the future. Use the `/app` alias instead.
|
||||
|
||||
## How to get the path to the Apps Data folder?
|
||||
|
||||
You can use `/app` alias to get the path to the current application data folder. For example, if you want to open a file `config.txt` in the Apps Data folder, you can use the next path: `/app/config.txt`. But this way is not recommended, because even the `/app` alias can change in the future.
|
||||
|
||||
We recommend to use the `APP_DATA_PATH` macro to get the path to the Apps Data folder. For example, if you want to open a file `config.txt` in the Apps Data folder, you can use the next path: `APP_DATA_PATH("config.txt")`.
|
9
applications/examples/example_apps_data/application.fam
Normal file
9
applications/examples/example_apps_data/application.fam
Normal file
|
@ -0,0 +1,9 @@
|
|||
App(
|
||||
appid="example_apps_data",
|
||||
name="Example: Apps Data",
|
||||
apptype=FlipperAppType.EXTERNAL,
|
||||
entry_point="example_apps_data_main",
|
||||
requires=["gui"],
|
||||
stack_size=1 * 1024,
|
||||
fap_category="Examples",
|
||||
)
|
40
applications/examples/example_apps_data/example_apps_data.c
Normal file
40
applications/examples/example_apps_data/example_apps_data.c
Normal file
|
@ -0,0 +1,40 @@
|
|||
#include <furi.h>
|
||||
#include <storage/storage.h>
|
||||
|
||||
// Define log tag
|
||||
#define TAG "example_apps_data"
|
||||
|
||||
// Application entry point
|
||||
int32_t example_apps_data_main(void* p) {
|
||||
// Mark argument as unused
|
||||
UNUSED(p);
|
||||
|
||||
// Open storage
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
// Allocate file
|
||||
File* file = storage_file_alloc(storage);
|
||||
|
||||
// Get the path to the current application data folder
|
||||
// That is: /ext/apps_data/<app_name>
|
||||
// And it will create folders in the path if they don't exist
|
||||
// In this example it will create /ext/apps_data/example_apps_data
|
||||
// And file will be /ext/apps_data/example_apps_data/test.txt
|
||||
|
||||
// Open file, write data and close it
|
||||
if(!storage_file_open(file, APP_DATA_PATH("test.txt"), FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
|
||||
FURI_LOG_E(TAG, "Failed to open file");
|
||||
}
|
||||
if(!storage_file_write(file, "Hello World!", strlen("Hello World!"))) {
|
||||
FURI_LOG_E(TAG, "Failed to write to file");
|
||||
}
|
||||
storage_file_close(file);
|
||||
|
||||
// Deallocate file
|
||||
storage_file_free(file);
|
||||
|
||||
// Close storage
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -451,7 +451,7 @@ static bool archive_is_dir_exists(FuriString* path) {
|
|||
FileInfo file_info;
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
if(storage_common_stat(storage, furi_string_get_cstr(path), &file_info) == FSE_OK) {
|
||||
if(file_info.flags & FSF_DIRECTORY) {
|
||||
if(file_info_is_dir(&file_info)) {
|
||||
state = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -160,7 +160,7 @@ bool archive_favorites_read(void* context) {
|
|||
if(storage_file_exists(storage, furi_string_get_cstr(buffer))) {
|
||||
storage_common_stat(storage, furi_string_get_cstr(buffer), &file_info);
|
||||
archive_add_file_item(
|
||||
browser, (file_info.flags & FSF_DIRECTORY), furi_string_get_cstr(buffer));
|
||||
browser, file_info_is_dir(&file_info), furi_string_get_cstr(buffer));
|
||||
file_count++;
|
||||
} else {
|
||||
need_refresh = true;
|
||||
|
|
|
@ -96,7 +96,7 @@ void archive_delete_file(void* context, const char* format, ...) {
|
|||
|
||||
bool res = false;
|
||||
|
||||
if(fileinfo.flags & FSF_DIRECTORY) {
|
||||
if(file_info_is_dir(&fileinfo)) {
|
||||
res = storage_simply_remove_recursive(fs_api, furi_string_get_cstr(filename));
|
||||
} else {
|
||||
res = (storage_common_remove(fs_api, furi_string_get_cstr(filename)) == FSE_OK);
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <storage/storage.h>
|
||||
#include <gui/modules/loading.h>
|
||||
#include <dialogs/dialogs.h>
|
||||
#include <toolbox/path.h>
|
||||
#include <flipper_application/flipper_application.h>
|
||||
#include "elf_cpp/elf_hashtable.h"
|
||||
#include "fap_loader_app.h"
|
||||
|
@ -105,6 +106,12 @@ static bool fap_loader_run_selected_app(FapLoader* loader) {
|
|||
FURI_LOG_I(TAG, "FAP Loader is starting app");
|
||||
|
||||
FuriThread* thread = flipper_application_spawn(loader->app, NULL);
|
||||
|
||||
FuriString* app_name = furi_string_alloc();
|
||||
path_extract_filename_no_ext(furi_string_get_cstr(loader->fap_path), app_name);
|
||||
furi_thread_set_appid(thread, furi_string_get_cstr(app_name));
|
||||
furi_string_free(app_name);
|
||||
|
||||
furi_thread_start(thread);
|
||||
furi_thread_join(thread);
|
||||
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
#include "ibutton.h"
|
||||
#include "assets_icons.h"
|
||||
#include "ibutton_i.h"
|
||||
#include "ibutton/scenes/ibutton_scene.h"
|
||||
|
||||
#include <toolbox/path.h>
|
||||
#include <flipper_format/flipper_format.h>
|
||||
#include <rpc/rpc_app.h>
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
#define TAG "iButtonApp"
|
||||
|
@ -34,50 +30,13 @@ static const NotificationSequence* ibutton_notification_sequences[] = {
|
|||
};
|
||||
|
||||
static void ibutton_make_app_folder(iButton* ibutton) {
|
||||
if(!storage_simply_mkdir(ibutton->storage, IBUTTON_APP_FOLDER)) {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
if(!storage_simply_mkdir(storage, IBUTTON_APP_FOLDER)) {
|
||||
dialog_message_show_storage_error(ibutton->dialogs, "Cannot create\napp folder");
|
||||
}
|
||||
}
|
||||
|
||||
bool ibutton_load_key_data(iButton* ibutton, FuriString* key_path, bool show_dialog) {
|
||||
FlipperFormat* file = flipper_format_file_alloc(ibutton->storage);
|
||||
bool result = false;
|
||||
FuriString* data;
|
||||
data = furi_string_alloc();
|
||||
|
||||
do {
|
||||
if(!flipper_format_file_open_existing(file, furi_string_get_cstr(key_path))) break;
|
||||
|
||||
// header
|
||||
uint32_t version;
|
||||
if(!flipper_format_read_header(file, data, &version)) break;
|
||||
if(furi_string_cmp_str(data, IBUTTON_APP_FILE_TYPE) != 0) break;
|
||||
if(version != 1) break;
|
||||
|
||||
// key type
|
||||
iButtonKeyType type;
|
||||
if(!flipper_format_read_string(file, "Key type", data)) break;
|
||||
if(!ibutton_key_get_type_by_string(furi_string_get_cstr(data), &type)) break;
|
||||
|
||||
// key data
|
||||
uint8_t key_data[IBUTTON_KEY_DATA_SIZE] = {0};
|
||||
if(!flipper_format_read_hex(file, "Data", key_data, ibutton_key_get_size_by_type(type)))
|
||||
break;
|
||||
|
||||
ibutton_key_set_type(ibutton->key, type);
|
||||
ibutton_key_set_data(ibutton->key, key_data, IBUTTON_KEY_DATA_SIZE);
|
||||
|
||||
result = true;
|
||||
} while(false);
|
||||
|
||||
flipper_format_free(file);
|
||||
furi_string_free(data);
|
||||
|
||||
if((!result) && (show_dialog)) {
|
||||
dialog_message_show_storage_error(ibutton->dialogs, "Cannot load\nkey file");
|
||||
}
|
||||
|
||||
return result;
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
static void ibutton_rpc_command_callback(RpcAppSystemEvent event, void* context) {
|
||||
|
@ -87,14 +46,14 @@ static void ibutton_rpc_command_callback(RpcAppSystemEvent event, void* context)
|
|||
if(event == RpcAppEventSessionClose) {
|
||||
view_dispatcher_send_custom_event(
|
||||
ibutton->view_dispatcher, iButtonCustomEventRpcSessionClose);
|
||||
rpc_system_app_set_callback(ibutton->rpc_ctx, NULL, NULL);
|
||||
ibutton->rpc_ctx = NULL;
|
||||
rpc_system_app_set_callback(ibutton->rpc, NULL, NULL);
|
||||
ibutton->rpc = NULL;
|
||||
} else if(event == RpcAppEventAppExit) {
|
||||
view_dispatcher_send_custom_event(ibutton->view_dispatcher, iButtonCustomEventRpcExit);
|
||||
} else if(event == RpcAppEventLoadFile) {
|
||||
view_dispatcher_send_custom_event(ibutton->view_dispatcher, iButtonCustomEventRpcLoad);
|
||||
} else {
|
||||
rpc_system_app_confirm(ibutton->rpc_ctx, event, false);
|
||||
rpc_system_app_confirm(ibutton->rpc, event, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,13 +94,13 @@ iButton* ibutton_alloc() {
|
|||
|
||||
ibutton->gui = furi_record_open(RECORD_GUI);
|
||||
|
||||
ibutton->storage = furi_record_open(RECORD_STORAGE);
|
||||
ibutton->dialogs = furi_record_open(RECORD_DIALOGS);
|
||||
ibutton->notifications = furi_record_open(RECORD_NOTIFICATION);
|
||||
|
||||
ibutton->key = ibutton_key_alloc();
|
||||
ibutton->key_worker = ibutton_worker_alloc();
|
||||
ibutton_worker_start_thread(ibutton->key_worker);
|
||||
ibutton->protocols = ibutton_protocols_alloc();
|
||||
ibutton->key = ibutton_key_alloc(ibutton_protocols_get_max_data_size(ibutton->protocols));
|
||||
ibutton->worker = ibutton_worker_alloc(ibutton->protocols);
|
||||
ibutton_worker_start_thread(ibutton->worker);
|
||||
|
||||
ibutton->submenu = submenu_alloc();
|
||||
view_dispatcher_add_view(
|
||||
|
@ -163,9 +122,9 @@ iButton* ibutton_alloc() {
|
|||
view_dispatcher_add_view(
|
||||
ibutton->view_dispatcher, iButtonViewWidget, widget_get_view(ibutton->widget));
|
||||
|
||||
ibutton->dialog_ex = dialog_ex_alloc();
|
||||
ibutton->loading = loading_alloc();
|
||||
view_dispatcher_add_view(
|
||||
ibutton->view_dispatcher, iButtonViewDialogEx, dialog_ex_get_view(ibutton->dialog_ex));
|
||||
ibutton->view_dispatcher, iButtonViewLoading, loading_get_view(ibutton->loading));
|
||||
|
||||
return ibutton;
|
||||
}
|
||||
|
@ -173,8 +132,8 @@ iButton* ibutton_alloc() {
|
|||
void ibutton_free(iButton* ibutton) {
|
||||
furi_assert(ibutton);
|
||||
|
||||
view_dispatcher_remove_view(ibutton->view_dispatcher, iButtonViewDialogEx);
|
||||
dialog_ex_free(ibutton->dialog_ex);
|
||||
view_dispatcher_remove_view(ibutton->view_dispatcher, iButtonViewLoading);
|
||||
loading_free(ibutton->loading);
|
||||
|
||||
view_dispatcher_remove_view(ibutton->view_dispatcher, iButtonViewWidget);
|
||||
widget_free(ibutton->widget);
|
||||
|
@ -194,9 +153,6 @@ void ibutton_free(iButton* ibutton) {
|
|||
view_dispatcher_free(ibutton->view_dispatcher);
|
||||
scene_manager_free(ibutton->scene_manager);
|
||||
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
ibutton->storage = NULL;
|
||||
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
ibutton->notifications = NULL;
|
||||
|
||||
|
@ -206,103 +162,83 @@ void ibutton_free(iButton* ibutton) {
|
|||
furi_record_close(RECORD_GUI);
|
||||
ibutton->gui = NULL;
|
||||
|
||||
ibutton_worker_stop_thread(ibutton->key_worker);
|
||||
ibutton_worker_free(ibutton->key_worker);
|
||||
ibutton_worker_stop_thread(ibutton->worker);
|
||||
ibutton_worker_free(ibutton->worker);
|
||||
ibutton_key_free(ibutton->key);
|
||||
ibutton_protocols_free(ibutton->protocols);
|
||||
|
||||
furi_string_free(ibutton->file_path);
|
||||
|
||||
free(ibutton);
|
||||
}
|
||||
|
||||
bool ibutton_file_select(iButton* ibutton) {
|
||||
DialogsFileBrowserOptions browser_options;
|
||||
dialog_file_browser_set_basic_options(&browser_options, IBUTTON_APP_EXTENSION, &I_ibutt_10px);
|
||||
browser_options.base_path = IBUTTON_APP_FOLDER;
|
||||
bool ibutton_load_key(iButton* ibutton) {
|
||||
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewLoading);
|
||||
|
||||
bool success = dialog_file_browser_show(
|
||||
ibutton->dialogs, ibutton->file_path, ibutton->file_path, &browser_options);
|
||||
const bool success = ibutton_protocols_load(
|
||||
ibutton->protocols, ibutton->key, furi_string_get_cstr(ibutton->file_path));
|
||||
|
||||
if(success) {
|
||||
success = ibutton_load_key_data(ibutton, ibutton->file_path, true);
|
||||
if(!success) {
|
||||
dialog_message_show_storage_error(ibutton->dialogs, "Cannot load\nkey file");
|
||||
|
||||
} else {
|
||||
FuriString* tmp = furi_string_alloc();
|
||||
|
||||
path_extract_filename(ibutton->file_path, tmp, true);
|
||||
strncpy(ibutton->key_name, furi_string_get_cstr(tmp), IBUTTON_KEY_NAME_SIZE);
|
||||
|
||||
furi_string_free(tmp);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool ibutton_save_key(iButton* ibutton, const char* key_name) {
|
||||
// Create ibutton directory if necessary
|
||||
bool ibutton_select_and_load_key(iButton* ibutton) {
|
||||
DialogsFileBrowserOptions browser_options;
|
||||
dialog_file_browser_set_basic_options(&browser_options, IBUTTON_APP_EXTENSION, &I_ibutt_10px);
|
||||
browser_options.base_path = IBUTTON_APP_FOLDER;
|
||||
|
||||
if(furi_string_empty(ibutton->file_path)) {
|
||||
furi_string_set(ibutton->file_path, browser_options.base_path);
|
||||
}
|
||||
|
||||
return dialog_file_browser_show(
|
||||
ibutton->dialogs, ibutton->file_path, ibutton->file_path, &browser_options) &&
|
||||
ibutton_load_key(ibutton);
|
||||
}
|
||||
|
||||
bool ibutton_save_key(iButton* ibutton) {
|
||||
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewLoading);
|
||||
|
||||
ibutton_make_app_folder(ibutton);
|
||||
|
||||
FlipperFormat* file = flipper_format_file_alloc(ibutton->storage);
|
||||
iButtonKey* key = ibutton->key;
|
||||
const bool success =
|
||||
ibutton_protocols_save(ibutton->protocols, key, furi_string_get_cstr(ibutton->file_path));
|
||||
|
||||
bool result = false;
|
||||
|
||||
do {
|
||||
// Check if we has old key
|
||||
if(furi_string_end_with(ibutton->file_path, IBUTTON_APP_EXTENSION)) {
|
||||
// First remove old key
|
||||
ibutton_delete_key(ibutton);
|
||||
|
||||
// Remove old key name from path
|
||||
size_t filename_start = furi_string_search_rchar(ibutton->file_path, '/');
|
||||
furi_string_left(ibutton->file_path, filename_start);
|
||||
}
|
||||
|
||||
furi_string_cat_printf(ibutton->file_path, "/%s%s", key_name, IBUTTON_APP_EXTENSION);
|
||||
|
||||
// Open file for write
|
||||
if(!flipper_format_file_open_always(file, furi_string_get_cstr(ibutton->file_path))) break;
|
||||
|
||||
// Write header
|
||||
if(!flipper_format_write_header_cstr(file, IBUTTON_APP_FILE_TYPE, 1)) break;
|
||||
|
||||
// Write key type
|
||||
if(!flipper_format_write_comment_cstr(file, "Key type can be Cyfral, Dallas or Metakom"))
|
||||
break;
|
||||
const char* key_type = ibutton_key_get_string_by_type(ibutton_key_get_type(key));
|
||||
if(!flipper_format_write_string_cstr(file, "Key type", key_type)) break;
|
||||
|
||||
// Write data
|
||||
if(!flipper_format_write_comment_cstr(
|
||||
file, "Data size for Cyfral is 2, for Metakom is 4, for Dallas is 8"))
|
||||
break;
|
||||
|
||||
if(!flipper_format_write_hex(
|
||||
file, "Data", ibutton_key_get_data_p(key), ibutton_key_get_data_size(key)))
|
||||
break;
|
||||
result = true;
|
||||
|
||||
} while(false);
|
||||
|
||||
flipper_format_free(file);
|
||||
|
||||
if(!result) { //-V547
|
||||
if(!success) {
|
||||
dialog_message_show_storage_error(ibutton->dialogs, "Cannot save\nkey file");
|
||||
}
|
||||
|
||||
return result;
|
||||
return success;
|
||||
}
|
||||
|
||||
bool ibutton_delete_key(iButton* ibutton) {
|
||||
bool result = false;
|
||||
result = storage_simply_remove(ibutton->storage, furi_string_get_cstr(ibutton->file_path));
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
result = storage_simply_remove(storage, furi_string_get_cstr(ibutton->file_path));
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
ibutton_reset_key(ibutton);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void ibutton_text_store_set(iButton* ibutton, const char* text, ...) {
|
||||
va_list args;
|
||||
va_start(args, text);
|
||||
|
||||
vsnprintf(ibutton->text_store, IBUTTON_TEXT_STORE_SIZE, text, args);
|
||||
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void ibutton_text_store_clear(iButton* ibutton) {
|
||||
memset(ibutton->text_store, 0, IBUTTON_TEXT_STORE_SIZE + 1);
|
||||
void ibutton_reset_key(iButton* ibutton) {
|
||||
memset(ibutton->key_name, 0, IBUTTON_KEY_NAME_SIZE + 1);
|
||||
furi_string_reset(ibutton->file_path);
|
||||
ibutton_key_reset(ibutton->key);
|
||||
}
|
||||
|
||||
void ibutton_notification_message(iButton* ibutton, uint32_t message) {
|
||||
|
@ -310,36 +246,44 @@ void ibutton_notification_message(iButton* ibutton, uint32_t message) {
|
|||
notification_message(ibutton->notifications, ibutton_notification_sequences[message]);
|
||||
}
|
||||
|
||||
int32_t ibutton_app(void* p) {
|
||||
void ibutton_submenu_callback(void* context, uint32_t index) {
|
||||
iButton* ibutton = context;
|
||||
view_dispatcher_send_custom_event(ibutton->view_dispatcher, index);
|
||||
}
|
||||
|
||||
void ibutton_widget_callback(GuiButtonType result, InputType type, void* context) {
|
||||
iButton* ibutton = context;
|
||||
if(type == InputTypeShort) {
|
||||
view_dispatcher_send_custom_event(ibutton->view_dispatcher, result);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t ibutton_app(void* arg) {
|
||||
iButton* ibutton = ibutton_alloc();
|
||||
|
||||
ibutton_make_app_folder(ibutton);
|
||||
|
||||
bool key_loaded = false;
|
||||
bool rpc_mode = false;
|
||||
|
||||
if(p && strlen(p)) {
|
||||
uint32_t rpc_ctx = 0;
|
||||
if(sscanf(p, "RPC %lX", &rpc_ctx) == 1) {
|
||||
if((arg != NULL) && (strlen(arg) != 0)) {
|
||||
if(sscanf(arg, "RPC %lX", (uint32_t*)&ibutton->rpc) == 1) {
|
||||
FURI_LOG_D(TAG, "Running in RPC mode");
|
||||
ibutton->rpc_ctx = (void*)rpc_ctx;
|
||||
rpc_mode = true;
|
||||
rpc_system_app_set_callback(ibutton->rpc_ctx, ibutton_rpc_command_callback, ibutton);
|
||||
rpc_system_app_send_started(ibutton->rpc_ctx);
|
||||
|
||||
rpc_system_app_set_callback(ibutton->rpc, ibutton_rpc_command_callback, ibutton);
|
||||
rpc_system_app_send_started(ibutton->rpc);
|
||||
|
||||
} else {
|
||||
furi_string_set(ibutton->file_path, (const char*)p);
|
||||
if(ibutton_load_key_data(ibutton, ibutton->file_path, true)) {
|
||||
key_loaded = true;
|
||||
// TODO: Display an error if the key from p could not be loaded
|
||||
}
|
||||
furi_string_set(ibutton->file_path, (const char*)arg);
|
||||
key_loaded = ibutton_load_key(ibutton);
|
||||
}
|
||||
}
|
||||
|
||||
if(rpc_mode) {
|
||||
if(ibutton->rpc != NULL) {
|
||||
view_dispatcher_attach_to_gui(
|
||||
ibutton->view_dispatcher, ibutton->gui, ViewDispatcherTypeDesktop);
|
||||
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneRpc);
|
||||
DOLPHIN_DEED(DolphinDeedIbuttonEmulate);
|
||||
|
||||
} else {
|
||||
view_dispatcher_attach_to_gui(
|
||||
ibutton->view_dispatcher, ibutton->gui, ViewDispatcherTypeFullscreen);
|
||||
|
@ -353,9 +297,9 @@ int32_t ibutton_app(void* p) {
|
|||
|
||||
view_dispatcher_run(ibutton->view_dispatcher);
|
||||
|
||||
if(ibutton->rpc_ctx) {
|
||||
rpc_system_app_set_callback(ibutton->rpc_ctx, NULL, NULL);
|
||||
rpc_system_app_send_exited(ibutton->rpc_ctx);
|
||||
if(ibutton->rpc) {
|
||||
rpc_system_app_set_callback(ibutton->rpc, NULL, NULL);
|
||||
rpc_system_app_send_exited(ibutton->rpc);
|
||||
}
|
||||
ibutton_free(ibutton);
|
||||
return 0;
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <cli/cli.h>
|
||||
#include <lib/toolbox/args.h>
|
||||
#include <one_wire/ibutton/ibutton_worker.h>
|
||||
#include <toolbox/args.h>
|
||||
|
||||
#include <one_wire/one_wire_host.h>
|
||||
|
||||
#include <one_wire/ibutton/ibutton_key.h>
|
||||
#include <one_wire/ibutton/ibutton_worker.h>
|
||||
#include <one_wire/ibutton/ibutton_protocols.h>
|
||||
|
||||
static void ibutton_cli(Cli* cli, FuriString* args, void* context);
|
||||
static void onewire_cli(Cli* cli, FuriString* args, void* context);
|
||||
|
||||
|
@ -22,7 +26,7 @@ void ibutton_on_system_start() {
|
|||
#endif
|
||||
}
|
||||
|
||||
void ibutton_cli_print_usage() {
|
||||
static void ibutton_cli_print_usage() {
|
||||
printf("Usage:\r\n");
|
||||
printf("ikey read\r\n");
|
||||
printf("ikey emulate <key_type> <key_data>\r\n");
|
||||
|
@ -34,30 +38,52 @@ void ibutton_cli_print_usage() {
|
|||
printf("\t<key_data> are hex-formatted\r\n");
|
||||
};
|
||||
|
||||
bool ibutton_cli_get_key_type(FuriString* data, iButtonKeyType* type) {
|
||||
static bool ibutton_cli_parse_key(iButtonProtocols* protocols, iButtonKey* key, FuriString* args) {
|
||||
bool result = false;
|
||||
FuriString* name = furi_string_alloc();
|
||||
|
||||
if(furi_string_cmp_str(data, "Dallas") == 0 || furi_string_cmp_str(data, "dallas") == 0) {
|
||||
result = true;
|
||||
*type = iButtonKeyDS1990;
|
||||
} else if(furi_string_cmp_str(data, "Cyfral") == 0 || furi_string_cmp_str(data, "cyfral") == 0) {
|
||||
result = true;
|
||||
*type = iButtonKeyCyfral;
|
||||
} else if(furi_string_cmp_str(data, "Metakom") == 0 || furi_string_cmp_str(data, "metakom") == 0) {
|
||||
result = true;
|
||||
*type = iButtonKeyMetakom;
|
||||
}
|
||||
do {
|
||||
// Read protocol name
|
||||
if(!args_read_string_and_trim(args, name)) break;
|
||||
|
||||
// Make the protocol name uppercase
|
||||
const char first = furi_string_get_char(name, 0);
|
||||
furi_string_set_char(name, 0, toupper((int)first));
|
||||
|
||||
const iButtonProtocolId id =
|
||||
ibutton_protocols_get_id_by_name(protocols, furi_string_get_cstr(name));
|
||||
if(id == iButtonProtocolIdInvalid) break;
|
||||
|
||||
ibutton_key_set_protocol_id(key, id);
|
||||
|
||||
// Get the data pointer
|
||||
iButtonEditableData data;
|
||||
ibutton_protocols_get_editable_data(protocols, key, &data);
|
||||
|
||||
// Read data
|
||||
if(!args_read_hex_bytes(args, data.ptr, data.size)) break;
|
||||
|
||||
result = true;
|
||||
} while(false);
|
||||
|
||||
furi_string_free(name);
|
||||
return result;
|
||||
}
|
||||
|
||||
void ibutton_cli_print_key_data(iButtonKey* key) {
|
||||
const uint8_t* key_data = ibutton_key_get_data_p(key);
|
||||
iButtonKeyType type = ibutton_key_get_type(key);
|
||||
static void ibutton_cli_print_key(iButtonProtocols* protocols, iButtonKey* key) {
|
||||
const char* name = ibutton_protocols_get_name(protocols, ibutton_key_get_protocol_id(key));
|
||||
|
||||
printf("%s ", ibutton_key_get_string_by_type(type));
|
||||
for(size_t i = 0; i < ibutton_key_get_size_by_type(type); i++) {
|
||||
printf("%02X", key_data[i]);
|
||||
if(strncmp(name, "DS", 2) == 0) {
|
||||
name = "Dallas";
|
||||
}
|
||||
|
||||
printf("%s ", name);
|
||||
|
||||
iButtonEditableData data;
|
||||
ibutton_protocols_get_editable_data(protocols, key, &data);
|
||||
|
||||
for(size_t i = 0; i < data.size; i++) {
|
||||
printf("%02X", data.ptr[i]);
|
||||
}
|
||||
|
||||
printf("\r\n");
|
||||
|
@ -71,9 +97,10 @@ static void ibutton_cli_worker_read_cb(void* context) {
|
|||
furi_event_flag_set(event, EVENT_FLAG_IBUTTON_COMPLETE);
|
||||
}
|
||||
|
||||
void ibutton_cli_read(Cli* cli) {
|
||||
iButtonKey* key = ibutton_key_alloc();
|
||||
iButtonWorker* worker = ibutton_worker_alloc();
|
||||
static void ibutton_cli_read(Cli* cli) {
|
||||
iButtonProtocols* protocols = ibutton_protocols_alloc();
|
||||
iButtonWorker* worker = ibutton_worker_alloc(protocols);
|
||||
iButtonKey* key = ibutton_key_alloc(ibutton_protocols_get_max_data_size(protocols));
|
||||
FuriEventFlag* event = furi_event_flag_alloc();
|
||||
|
||||
ibutton_worker_start_thread(worker);
|
||||
|
@ -81,32 +108,25 @@ void ibutton_cli_read(Cli* cli) {
|
|||
|
||||
printf("Reading iButton...\r\nPress Ctrl+C to abort\r\n");
|
||||
ibutton_worker_read_start(worker, key);
|
||||
|
||||
while(true) {
|
||||
uint32_t flags =
|
||||
furi_event_flag_wait(event, EVENT_FLAG_IBUTTON_COMPLETE, FuriFlagWaitAny, 100);
|
||||
|
||||
if(flags & EVENT_FLAG_IBUTTON_COMPLETE) {
|
||||
ibutton_cli_print_key_data(key);
|
||||
|
||||
if(ibutton_key_get_type(key) == iButtonKeyDS1990) {
|
||||
if(!ibutton_key_dallas_crc_is_valid(key)) {
|
||||
printf("Warning: invalid CRC\r\n");
|
||||
}
|
||||
|
||||
if(!ibutton_key_dallas_is_1990_key(key)) {
|
||||
printf("Warning: not a key\r\n");
|
||||
}
|
||||
}
|
||||
ibutton_cli_print_key(protocols, key);
|
||||
break;
|
||||
}
|
||||
|
||||
if(cli_cmd_interrupt_received(cli)) break;
|
||||
}
|
||||
ibutton_worker_stop(worker);
|
||||
|
||||
ibutton_worker_stop(worker);
|
||||
ibutton_worker_stop_thread(worker);
|
||||
ibutton_worker_free(worker);
|
||||
|
||||
ibutton_key_free(key);
|
||||
ibutton_worker_free(worker);
|
||||
ibutton_protocols_free(protocols);
|
||||
|
||||
furi_event_flag_free(event);
|
||||
};
|
||||
|
@ -124,48 +144,33 @@ static void ibutton_cli_worker_write_cb(void* context, iButtonWorkerWriteResult
|
|||
}
|
||||
|
||||
void ibutton_cli_write(Cli* cli, FuriString* args) {
|
||||
iButtonKey* key = ibutton_key_alloc();
|
||||
iButtonWorker* worker = ibutton_worker_alloc();
|
||||
iButtonKeyType type;
|
||||
iButtonWriteContext write_context;
|
||||
uint8_t key_data[IBUTTON_KEY_DATA_SIZE];
|
||||
FuriString* data;
|
||||
iButtonProtocols* protocols = ibutton_protocols_alloc();
|
||||
iButtonWorker* worker = ibutton_worker_alloc(protocols);
|
||||
iButtonKey* key = ibutton_key_alloc(ibutton_protocols_get_max_data_size(protocols));
|
||||
|
||||
iButtonWriteContext write_context;
|
||||
write_context.event = furi_event_flag_alloc();
|
||||
|
||||
data = furi_string_alloc();
|
||||
ibutton_worker_start_thread(worker);
|
||||
ibutton_worker_write_set_callback(worker, ibutton_cli_worker_write_cb, &write_context);
|
||||
|
||||
do {
|
||||
if(!args_read_string_and_trim(args, data)) {
|
||||
if(!ibutton_cli_parse_key(protocols, key, args)) {
|
||||
ibutton_cli_print_usage();
|
||||
break;
|
||||
}
|
||||
|
||||
if(!ibutton_cli_get_key_type(data, &type)) {
|
||||
if(!(ibutton_protocols_get_features(protocols, ibutton_key_get_protocol_id(key)) &
|
||||
iButtonProtocolFeatureWriteBlank)) {
|
||||
ibutton_cli_print_usage();
|
||||
break;
|
||||
}
|
||||
|
||||
if(type != iButtonKeyDS1990) {
|
||||
ibutton_cli_print_usage();
|
||||
break;
|
||||
}
|
||||
|
||||
if(!args_read_hex_bytes(args, key_data, ibutton_key_get_size_by_type(type))) {
|
||||
ibutton_cli_print_usage();
|
||||
break;
|
||||
}
|
||||
|
||||
ibutton_key_set_type(key, type);
|
||||
ibutton_key_set_data(key, key_data, ibutton_key_get_size_by_type(type));
|
||||
|
||||
printf("Writing key ");
|
||||
ibutton_cli_print_key_data(key);
|
||||
ibutton_cli_print_key(protocols, key);
|
||||
printf("Press Ctrl+C to abort\r\n");
|
||||
|
||||
ibutton_worker_write_start(worker, key);
|
||||
ibutton_worker_write_blank_start(worker, key);
|
||||
while(true) {
|
||||
uint32_t flags = furi_event_flag_wait(
|
||||
write_context.event, EVENT_FLAG_IBUTTON_COMPLETE, FuriFlagWaitAny, 100);
|
||||
|
@ -183,64 +188,53 @@ void ibutton_cli_write(Cli* cli, FuriString* args) {
|
|||
|
||||
if(cli_cmd_interrupt_received(cli)) break;
|
||||
}
|
||||
ibutton_worker_stop(worker);
|
||||
} while(false);
|
||||
|
||||
furi_string_free(data);
|
||||
ibutton_worker_stop(worker);
|
||||
ibutton_worker_stop_thread(worker);
|
||||
ibutton_worker_free(worker);
|
||||
|
||||
ibutton_key_free(key);
|
||||
ibutton_worker_free(worker);
|
||||
ibutton_protocols_free(protocols);
|
||||
|
||||
furi_event_flag_free(write_context.event);
|
||||
};
|
||||
}
|
||||
|
||||
void ibutton_cli_emulate(Cli* cli, FuriString* args) {
|
||||
iButtonKey* key = ibutton_key_alloc();
|
||||
iButtonWorker* worker = ibutton_worker_alloc();
|
||||
iButtonKeyType type;
|
||||
uint8_t key_data[IBUTTON_KEY_DATA_SIZE];
|
||||
FuriString* data;
|
||||
iButtonProtocols* protocols = ibutton_protocols_alloc();
|
||||
iButtonWorker* worker = ibutton_worker_alloc(protocols);
|
||||
iButtonKey* key = ibutton_key_alloc(ibutton_protocols_get_max_data_size(protocols));
|
||||
|
||||
data = furi_string_alloc();
|
||||
ibutton_worker_start_thread(worker);
|
||||
|
||||
do {
|
||||
if(!args_read_string_and_trim(args, data)) {
|
||||
if(!ibutton_cli_parse_key(protocols, key, args)) {
|
||||
ibutton_cli_print_usage();
|
||||
break;
|
||||
}
|
||||
|
||||
if(!ibutton_cli_get_key_type(data, &type)) {
|
||||
ibutton_cli_print_usage();
|
||||
break;
|
||||
}
|
||||
|
||||
if(!args_read_hex_bytes(args, key_data, ibutton_key_get_size_by_type(type))) {
|
||||
ibutton_cli_print_usage();
|
||||
break;
|
||||
}
|
||||
|
||||
ibutton_key_set_type(key, type);
|
||||
ibutton_key_set_data(key, key_data, ibutton_key_get_size_by_type(type));
|
||||
|
||||
printf("Emulating key ");
|
||||
ibutton_cli_print_key_data(key);
|
||||
ibutton_cli_print_key(protocols, key);
|
||||
printf("Press Ctrl+C to abort\r\n");
|
||||
|
||||
ibutton_worker_emulate_start(worker, key);
|
||||
|
||||
while(!cli_cmd_interrupt_received(cli)) {
|
||||
furi_delay_ms(100);
|
||||
};
|
||||
ibutton_worker_stop(worker);
|
||||
|
||||
} while(false);
|
||||
|
||||
furi_string_free(data);
|
||||
ibutton_worker_stop(worker);
|
||||
ibutton_worker_stop_thread(worker);
|
||||
ibutton_worker_free(worker);
|
||||
|
||||
ibutton_key_free(key);
|
||||
ibutton_worker_free(worker);
|
||||
ibutton_protocols_free(protocols);
|
||||
};
|
||||
|
||||
static void ibutton_cli(Cli* cli, FuriString* args, void* context) {
|
||||
void ibutton_cli(Cli* cli, FuriString* args, void* context) {
|
||||
UNUSED(cli);
|
||||
UNUSED(context);
|
||||
FuriString* cmd;
|
||||
cmd = furi_string_alloc();
|
||||
|
@ -264,7 +258,7 @@ static void ibutton_cli(Cli* cli, FuriString* args, void* context) {
|
|||
furi_string_free(cmd);
|
||||
}
|
||||
|
||||
void onewire_cli_print_usage() {
|
||||
static void onewire_cli_print_usage() {
|
||||
printf("Usage:\r\n");
|
||||
printf("onewire search\r\n");
|
||||
};
|
||||
|
@ -281,7 +275,7 @@ static void onewire_cli_search(Cli* cli) {
|
|||
furi_hal_power_enable_otg();
|
||||
|
||||
while(!done) {
|
||||
if(onewire_host_search(onewire, address, NORMAL_SEARCH) != 1) {
|
||||
if(onewire_host_search(onewire, address, OneWireHostSearchModeNormal) != 1) {
|
||||
printf("Search finished\r\n");
|
||||
onewire_host_reset_search(onewire);
|
||||
done = true;
|
||||
|
|
|
@ -6,6 +6,7 @@ enum iButtonCustomEvent {
|
|||
|
||||
iButtonCustomEventBack,
|
||||
iButtonCustomEventTextEditResult,
|
||||
iButtonCustomEventByteEditChanged,
|
||||
iButtonCustomEventByteEditResult,
|
||||
iButtonCustomEventWorkerEmulated,
|
||||
iButtonCustomEventWorkerRead,
|
||||
|
|
|
@ -4,31 +4,40 @@
|
|||
|
||||
#include <gui/gui.h>
|
||||
#include <gui/view.h>
|
||||
#include <assets_icons.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
#include <gui/scene_manager.h>
|
||||
#include <notification/notification_messages.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
|
||||
#include <one_wire/ibutton/ibutton_worker.h>
|
||||
#include <one_wire/ibutton/ibutton_protocols.h>
|
||||
|
||||
#include <rpc/rpc_app.h>
|
||||
#include <storage/storage.h>
|
||||
#include <dialogs/dialogs.h>
|
||||
#include <notification/notification.h>
|
||||
#include <notification/notification_messages.h>
|
||||
|
||||
#include <gui/modules/submenu.h>
|
||||
#include <gui/modules/popup.h>
|
||||
#include <gui/modules/dialog_ex.h>
|
||||
#include <gui/modules/text_input.h>
|
||||
#include <gui/modules/byte_input.h>
|
||||
#include <gui/modules/widget.h>
|
||||
#include <gui/modules/loading.h>
|
||||
|
||||
#include <assets_icons.h>
|
||||
|
||||
#include "ibutton_custom_event.h"
|
||||
#include "scenes/ibutton_scene.h"
|
||||
|
||||
#define IBUTTON_FILE_NAME_SIZE 100
|
||||
#define IBUTTON_TEXT_STORE_SIZE 128
|
||||
|
||||
#define IBUTTON_APP_FOLDER ANY_PATH("ibutton")
|
||||
#define IBUTTON_APP_EXTENSION ".ibtn"
|
||||
#define IBUTTON_APP_FILE_TYPE "Flipper iButton key"
|
||||
|
||||
#define IBUTTON_KEY_NAME_SIZE 22
|
||||
|
||||
typedef enum {
|
||||
iButtonWriteModeInvalid,
|
||||
iButtonWriteModeBlank,
|
||||
iButtonWriteModeCopy,
|
||||
} iButtonWriteMode;
|
||||
|
||||
struct iButton {
|
||||
SceneManager* scene_manager;
|
||||
|
@ -38,21 +47,22 @@ struct iButton {
|
|||
Storage* storage;
|
||||
DialogsApp* dialogs;
|
||||
NotificationApp* notifications;
|
||||
RpcAppSystem* rpc;
|
||||
|
||||
iButtonWorker* key_worker;
|
||||
iButtonKey* key;
|
||||
iButtonWorker* worker;
|
||||
iButtonProtocols* protocols;
|
||||
iButtonWriteMode write_mode;
|
||||
|
||||
FuriString* file_path;
|
||||
char text_store[IBUTTON_TEXT_STORE_SIZE + 1];
|
||||
char key_name[IBUTTON_KEY_NAME_SIZE + 1];
|
||||
|
||||
Submenu* submenu;
|
||||
ByteInput* byte_input;
|
||||
TextInput* text_input;
|
||||
Popup* popup;
|
||||
Widget* widget;
|
||||
DialogEx* dialog_ex;
|
||||
|
||||
void* rpc_ctx;
|
||||
Loading* loading;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
|
@ -61,7 +71,7 @@ typedef enum {
|
|||
iButtonViewTextInput,
|
||||
iButtonViewPopup,
|
||||
iButtonViewWidget,
|
||||
iButtonViewDialogEx,
|
||||
iButtonViewLoading,
|
||||
} iButtonView;
|
||||
|
||||
typedef enum {
|
||||
|
@ -78,10 +88,12 @@ typedef enum {
|
|||
iButtonNotificationMessageBlinkStop,
|
||||
} iButtonNotificationMessage;
|
||||
|
||||
bool ibutton_file_select(iButton* ibutton);
|
||||
bool ibutton_load_key_data(iButton* ibutton, FuriString* key_path, bool show_dialog);
|
||||
bool ibutton_save_key(iButton* ibutton, const char* key_name);
|
||||
bool ibutton_select_and_load_key(iButton* ibutton);
|
||||
bool ibutton_load_key(iButton* ibutton);
|
||||
bool ibutton_save_key(iButton* ibutton);
|
||||
bool ibutton_delete_key(iButton* ibutton);
|
||||
void ibutton_text_store_set(iButton* ibutton, const char* text, ...);
|
||||
void ibutton_text_store_clear(iButton* ibutton);
|
||||
void ibutton_reset_key(iButton* ibutton);
|
||||
void ibutton_notification_message(iButton* ibutton, uint32_t message);
|
||||
|
||||
void ibutton_submenu_callback(void* context, uint32_t index);
|
||||
void ibutton_widget_callback(GuiButtonType result, InputType type, void* context);
|
||||
|
|
|
@ -1,54 +1,48 @@
|
|||
#include "../ibutton_i.h"
|
||||
|
||||
enum SubmenuIndex {
|
||||
SubmenuIndexCyfral,
|
||||
SubmenuIndexDallas,
|
||||
SubmenuIndexMetakom,
|
||||
};
|
||||
|
||||
void ibutton_scene_add_type_submenu_callback(void* context, uint32_t index) {
|
||||
iButton* ibutton = context;
|
||||
view_dispatcher_send_custom_event(ibutton->view_dispatcher, index);
|
||||
}
|
||||
|
||||
void ibutton_scene_add_type_on_enter(void* context) {
|
||||
iButton* ibutton = context;
|
||||
Submenu* submenu = ibutton->submenu;
|
||||
|
||||
submenu_add_item(
|
||||
submenu, "Cyfral", SubmenuIndexCyfral, ibutton_scene_add_type_submenu_callback, ibutton);
|
||||
submenu_add_item(
|
||||
submenu, "Dallas", SubmenuIndexDallas, ibutton_scene_add_type_submenu_callback, ibutton);
|
||||
submenu_add_item(
|
||||
submenu, "Metakom", SubmenuIndexMetakom, ibutton_scene_add_type_submenu_callback, ibutton);
|
||||
FuriString* tmp = furi_string_alloc();
|
||||
|
||||
submenu_set_selected_item(
|
||||
submenu, scene_manager_get_scene_state(ibutton->scene_manager, iButtonSceneAddType));
|
||||
for(uint32_t protocol_id = 0; protocol_id < ibutton_protocols_get_protocol_count();
|
||||
++protocol_id) {
|
||||
furi_string_printf(
|
||||
tmp,
|
||||
"%s %s",
|
||||
ibutton_protocols_get_manufacturer(ibutton->protocols, protocol_id),
|
||||
ibutton_protocols_get_name(ibutton->protocols, protocol_id));
|
||||
|
||||
submenu_add_item(
|
||||
submenu, furi_string_get_cstr(tmp), protocol_id, ibutton_submenu_callback, context);
|
||||
}
|
||||
|
||||
const uint32_t prev_protocol_id =
|
||||
scene_manager_get_scene_state(ibutton->scene_manager, iButtonSceneAddType);
|
||||
submenu_set_selected_item(submenu, prev_protocol_id);
|
||||
|
||||
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewSubmenu);
|
||||
furi_string_free(tmp);
|
||||
}
|
||||
|
||||
bool ibutton_scene_add_type_on_event(void* context, SceneManagerEvent event) {
|
||||
iButton* ibutton = context;
|
||||
iButtonKey* key = ibutton->key;
|
||||
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
scene_manager_set_scene_state(ibutton->scene_manager, iButtonSceneAddType, event.event);
|
||||
consumed = true;
|
||||
if(event.event == SubmenuIndexCyfral) {
|
||||
ibutton_key_set_type(key, iButtonKeyCyfral);
|
||||
} else if(event.event == SubmenuIndexDallas) {
|
||||
ibutton_key_set_type(key, iButtonKeyDS1990);
|
||||
} else if(event.event == SubmenuIndexMetakom) {
|
||||
ibutton_key_set_type(key, iButtonKeyMetakom);
|
||||
} else {
|
||||
furi_crash("Unknown key type");
|
||||
}
|
||||
const iButtonProtocolId protocol_id = event.event;
|
||||
|
||||
furi_string_set(ibutton->file_path, IBUTTON_APP_FOLDER);
|
||||
ibutton_key_clear_data(key);
|
||||
ibutton_key_reset(key);
|
||||
ibutton_key_set_protocol_id(key, protocol_id);
|
||||
ibutton_protocols_apply_edits(ibutton->protocols, key);
|
||||
|
||||
scene_manager_set_scene_state(ibutton->scene_manager, iButtonSceneAddType, protocol_id);
|
||||
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneAddValue);
|
||||
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
|
|
|
@ -1,42 +1,52 @@
|
|||
#include "../ibutton_i.h"
|
||||
|
||||
void ibutton_scene_add_type_byte_input_callback(void* context) {
|
||||
static void ibutton_scene_add_type_byte_input_callback(void* context) {
|
||||
iButton* ibutton = context;
|
||||
view_dispatcher_send_custom_event(ibutton->view_dispatcher, iButtonCustomEventByteEditResult);
|
||||
}
|
||||
|
||||
static void ibutton_scene_add_type_byte_changed_callback(void* context) {
|
||||
iButton* ibutton = context;
|
||||
view_dispatcher_send_custom_event(ibutton->view_dispatcher, iButtonCustomEventByteEditChanged);
|
||||
}
|
||||
|
||||
void ibutton_scene_add_value_on_enter(void* context) {
|
||||
iButton* ibutton = context;
|
||||
iButtonKey* key = ibutton->key;
|
||||
uint8_t* new_key_data = malloc(IBUTTON_KEY_DATA_SIZE);
|
||||
byte_input_set_header_text(ibutton->byte_input, "Enter the key");
|
||||
|
||||
scene_manager_set_scene_state(
|
||||
ibutton->scene_manager, iButtonSceneAddValue, (uint32_t)new_key_data);
|
||||
memcpy(new_key_data, ibutton_key_get_data_p(key), ibutton_key_get_data_size(key));
|
||||
iButtonEditableData editable_data;
|
||||
ibutton_protocols_get_editable_data(ibutton->protocols, ibutton->key, &editable_data);
|
||||
|
||||
byte_input_set_result_callback(
|
||||
ibutton->byte_input,
|
||||
ibutton_scene_add_type_byte_input_callback,
|
||||
NULL,
|
||||
ibutton,
|
||||
new_key_data,
|
||||
ibutton_key_get_data_size(key));
|
||||
ibutton_scene_add_type_byte_changed_callback,
|
||||
context,
|
||||
editable_data.ptr,
|
||||
editable_data.size);
|
||||
|
||||
byte_input_set_header_text(ibutton->byte_input, "Enter the key");
|
||||
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewByteInput);
|
||||
}
|
||||
|
||||
bool ibutton_scene_add_value_on_event(void* context, SceneManagerEvent event) {
|
||||
iButton* ibutton = context;
|
||||
uint8_t* new_key_data =
|
||||
(uint8_t*)scene_manager_get_scene_state(ibutton->scene_manager, iButtonSceneAddValue);
|
||||
SceneManager* scene_manager = ibutton->scene_manager;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
consumed = true;
|
||||
if(event.event == iButtonCustomEventByteEditResult) {
|
||||
ibutton_key_set_data(ibutton->key, new_key_data, IBUTTON_KEY_DATA_SIZE);
|
||||
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneSaveName);
|
||||
scene_manager_next_scene(scene_manager, iButtonSceneSaveName);
|
||||
} else if(event.event == iButtonCustomEventByteEditChanged) {
|
||||
ibutton_protocols_apply_edits(ibutton->protocols, ibutton->key);
|
||||
}
|
||||
} else if(event.type == SceneManagerEventTypeBack) {
|
||||
// User cancelled editing, reload the key from storage
|
||||
if(scene_manager_has_previous_scene(scene_manager, iButtonSceneSavedKeyMenu)) {
|
||||
if(!ibutton_load_key(ibutton)) {
|
||||
consumed = scene_manager_search_and_switch_to_previous_scene(
|
||||
scene_manager, iButtonSceneStart);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,10 +55,7 @@ bool ibutton_scene_add_value_on_event(void* context, SceneManagerEvent event) {
|
|||
|
||||
void ibutton_scene_add_value_on_exit(void* context) {
|
||||
iButton* ibutton = context;
|
||||
uint8_t* new_key_data =
|
||||
(uint8_t*)scene_manager_get_scene_state(ibutton->scene_manager, iButtonSceneAddValue);
|
||||
|
||||
byte_input_set_result_callback(ibutton->byte_input, NULL, NULL, NULL, NULL, 0);
|
||||
byte_input_set_header_text(ibutton->byte_input, NULL);
|
||||
free(new_key_data);
|
||||
}
|
||||
|
|
|
@ -6,8 +6,7 @@ ADD_SCENE(ibutton, info, Info)
|
|||
ADD_SCENE(ibutton, read, Read)
|
||||
ADD_SCENE(ibutton, read_key_menu, ReadKeyMenu)
|
||||
ADD_SCENE(ibutton, read_success, ReadSuccess)
|
||||
ADD_SCENE(ibutton, read_crc_error, ReadCRCError)
|
||||
ADD_SCENE(ibutton, read_not_key_error, ReadNotKeyError)
|
||||
ADD_SCENE(ibutton, read_error, ReadError)
|
||||
ADD_SCENE(ibutton, select_key, SelectKey)
|
||||
ADD_SCENE(ibutton, add_type, AddType)
|
||||
ADD_SCENE(ibutton, add_value, AddValue)
|
||||
|
@ -18,4 +17,5 @@ ADD_SCENE(ibutton, delete_confirm, DeleteConfirm)
|
|||
ADD_SCENE(ibutton, delete_success, DeleteSuccess)
|
||||
ADD_SCENE(ibutton, retry_confirm, RetryConfirm)
|
||||
ADD_SCENE(ibutton, exit_confirm, ExitConfirm)
|
||||
ADD_SCENE(ibutton, view_data, ViewData)
|
||||
ADD_SCENE(ibutton, rpc, Rpc)
|
||||
|
|
|
@ -1,74 +1,29 @@
|
|||
#include "../ibutton_i.h"
|
||||
#include <toolbox/path.h>
|
||||
|
||||
static void ibutton_scene_delete_confirm_widget_callback(
|
||||
GuiButtonType result,
|
||||
InputType type,
|
||||
void* context) {
|
||||
iButton* ibutton = context;
|
||||
if(type == InputTypeShort) {
|
||||
view_dispatcher_send_custom_event(ibutton->view_dispatcher, result);
|
||||
}
|
||||
}
|
||||
|
||||
void ibutton_scene_delete_confirm_on_enter(void* context) {
|
||||
iButton* ibutton = context;
|
||||
Widget* widget = ibutton->widget;
|
||||
iButtonKey* key = ibutton->key;
|
||||
const uint8_t* key_data = ibutton_key_get_data_p(key);
|
||||
Widget* widget = ibutton->widget;
|
||||
|
||||
FuriString* key_name;
|
||||
key_name = furi_string_alloc();
|
||||
path_extract_filename(ibutton->file_path, key_name, true);
|
||||
FuriString* tmp = furi_string_alloc();
|
||||
|
||||
ibutton_text_store_set(ibutton, "\e#Delete %s?\e#", furi_string_get_cstr(key_name));
|
||||
widget_add_text_box_element(
|
||||
widget, 0, 0, 128, 27, AlignCenter, AlignCenter, ibutton->text_store, true);
|
||||
widget_add_button_element(widget, GuiButtonTypeLeft, "Back", ibutton_widget_callback, context);
|
||||
widget_add_button_element(
|
||||
widget, GuiButtonTypeLeft, "Cancel", ibutton_scene_delete_confirm_widget_callback, ibutton);
|
||||
widget_add_button_element(
|
||||
widget,
|
||||
GuiButtonTypeRight,
|
||||
"Delete",
|
||||
ibutton_scene_delete_confirm_widget_callback,
|
||||
ibutton);
|
||||
widget, GuiButtonTypeRight, "Delete", ibutton_widget_callback, context);
|
||||
|
||||
switch(ibutton_key_get_type(key)) {
|
||||
case iButtonKeyDS1990:
|
||||
ibutton_text_store_set(
|
||||
ibutton,
|
||||
"%02X %02X %02X %02X %02X %02X %02X %02X",
|
||||
key_data[0],
|
||||
key_data[1],
|
||||
key_data[2],
|
||||
key_data[3],
|
||||
key_data[4],
|
||||
key_data[5],
|
||||
key_data[6],
|
||||
key_data[7]);
|
||||
widget_add_string_element(
|
||||
widget, 64, 34, AlignCenter, AlignBottom, FontSecondary, "Dallas");
|
||||
break;
|
||||
|
||||
case iButtonKeyCyfral:
|
||||
ibutton_text_store_set(ibutton, "%02X %02X", key_data[0], key_data[1]);
|
||||
widget_add_string_element(
|
||||
widget, 64, 34, AlignCenter, AlignBottom, FontSecondary, "Cyfral");
|
||||
break;
|
||||
|
||||
case iButtonKeyMetakom:
|
||||
ibutton_text_store_set(
|
||||
ibutton, "%02X %02X %02X %02X", key_data[0], key_data[1], key_data[2], key_data[3]);
|
||||
widget_add_string_element(
|
||||
widget, 64, 34, AlignCenter, AlignBottom, FontSecondary, "Metakom");
|
||||
break;
|
||||
}
|
||||
furi_string_printf(tmp, "Delete %s?", ibutton->key_name);
|
||||
widget_add_string_element(
|
||||
widget, 64, 46, AlignCenter, AlignBottom, FontSecondary, ibutton->text_store);
|
||||
widget, 128 / 2, 0, AlignCenter, AlignTop, FontPrimary, furi_string_get_cstr(tmp));
|
||||
|
||||
furi_string_reset(tmp);
|
||||
ibutton_protocols_render_brief_data(ibutton->protocols, key, tmp);
|
||||
|
||||
widget_add_string_multiline_element(
|
||||
widget, 128 / 2, 16, AlignCenter, AlignTop, FontSecondary, furi_string_get_cstr(tmp));
|
||||
|
||||
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewWidget);
|
||||
|
||||
furi_string_free(key_name);
|
||||
furi_string_free(tmp);
|
||||
}
|
||||
|
||||
bool ibutton_scene_delete_confirm_on_event(void* context, SceneManagerEvent event) {
|
||||
|
@ -81,8 +36,10 @@ bool ibutton_scene_delete_confirm_on_event(void* context, SceneManagerEvent even
|
|||
if(event.event == GuiButtonTypeRight) {
|
||||
if(ibutton_delete_key(ibutton)) {
|
||||
scene_manager_next_scene(scene_manager, iButtonSceneDeleteSuccess);
|
||||
} else {
|
||||
dialog_message_show_storage_error(ibutton->dialogs, "Cannot delete\nkey file");
|
||||
scene_manager_previous_scene(scene_manager);
|
||||
}
|
||||
//TODO: What if the key could not be deleted?
|
||||
} else if(event.event == GuiButtonTypeLeft) {
|
||||
scene_manager_previous_scene(scene_manager);
|
||||
}
|
||||
|
@ -93,6 +50,5 @@ bool ibutton_scene_delete_confirm_on_event(void* context, SceneManagerEvent even
|
|||
|
||||
void ibutton_scene_delete_confirm_on_exit(void* context) {
|
||||
iButton* ibutton = context;
|
||||
ibutton_text_store_clear(ibutton);
|
||||
widget_reset(ibutton->widget);
|
||||
}
|
||||
|
|
|
@ -14,61 +14,32 @@ static void ibutton_scene_emulate_callback(void* context, bool emulated) {
|
|||
|
||||
void ibutton_scene_emulate_on_enter(void* context) {
|
||||
iButton* ibutton = context;
|
||||
Widget* widget = ibutton->widget;
|
||||
iButtonKey* key = ibutton->key;
|
||||
|
||||
const uint8_t* key_data = ibutton_key_get_data_p(key);
|
||||
Widget* widget = ibutton->widget;
|
||||
FuriString* tmp = furi_string_alloc();
|
||||
|
||||
FuriString* key_name;
|
||||
key_name = furi_string_alloc();
|
||||
if(furi_string_end_with(ibutton->file_path, IBUTTON_APP_EXTENSION)) {
|
||||
path_extract_filename(ibutton->file_path, key_name, true);
|
||||
}
|
||||
widget_add_icon_element(widget, 3, 10, &I_iButtonKey_49x44);
|
||||
|
||||
// check that stored key has name
|
||||
if(!furi_string_empty(key_name)) {
|
||||
ibutton_text_store_set(ibutton, "%s", furi_string_get_cstr(key_name));
|
||||
} else {
|
||||
// if not, show key data
|
||||
switch(ibutton_key_get_type(key)) {
|
||||
case iButtonKeyDS1990:
|
||||
ibutton_text_store_set(
|
||||
ibutton,
|
||||
"%02X %02X %02X %02X\n%02X %02X %02X %02X",
|
||||
key_data[0],
|
||||
key_data[1],
|
||||
key_data[2],
|
||||
key_data[3],
|
||||
key_data[4],
|
||||
key_data[5],
|
||||
key_data[6],
|
||||
key_data[7]);
|
||||
break;
|
||||
case iButtonKeyCyfral:
|
||||
ibutton_text_store_set(ibutton, "%02X %02X", key_data[0], key_data[1]);
|
||||
break;
|
||||
case iButtonKeyMetakom:
|
||||
ibutton_text_store_set(
|
||||
ibutton, "%02X %02X %02X %02X", key_data[0], key_data[1], key_data[2], key_data[3]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
furi_string_printf(
|
||||
tmp,
|
||||
"%s\n[%s]",
|
||||
furi_string_empty(ibutton->file_path) ? "Unsaved Key" : ibutton->key_name,
|
||||
ibutton_protocols_get_name(ibutton->protocols, ibutton_key_get_protocol_id(key)));
|
||||
|
||||
widget_add_text_box_element(
|
||||
widget, 52, 38, 75, 26, AlignCenter, AlignCenter, furi_string_get_cstr(tmp), true);
|
||||
|
||||
widget_add_string_multiline_element(
|
||||
widget, 90, 10, AlignCenter, AlignTop, FontPrimary, "iButton\nemulating");
|
||||
widget_add_icon_element(widget, 3, 10, &I_iButtonKey_49x44);
|
||||
widget_add_text_box_element(
|
||||
widget, 54, 39, 75, 22, AlignCenter, AlignCenter, ibutton->text_store, true);
|
||||
widget, 88, 10, AlignCenter, AlignTop, FontPrimary, "iButton\nemulating");
|
||||
|
||||
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewWidget);
|
||||
|
||||
ibutton_worker_emulate_set_callback(
|
||||
ibutton->key_worker, ibutton_scene_emulate_callback, ibutton);
|
||||
ibutton_worker_emulate_start(ibutton->key_worker, key);
|
||||
|
||||
furi_string_free(key_name);
|
||||
ibutton_worker_emulate_set_callback(ibutton->worker, ibutton_scene_emulate_callback, ibutton);
|
||||
ibutton_worker_emulate_start(ibutton->worker, key);
|
||||
|
||||
ibutton_notification_message(ibutton, iButtonNotificationMessageEmulateStart);
|
||||
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewWidget);
|
||||
|
||||
furi_string_free(tmp);
|
||||
}
|
||||
|
||||
bool ibutton_scene_emulate_on_event(void* context, SceneManagerEvent event) {
|
||||
|
@ -78,8 +49,7 @@ bool ibutton_scene_emulate_on_event(void* context, SceneManagerEvent event) {
|
|||
if(event.type == SceneManagerEventTypeTick) {
|
||||
uint32_t cnt = scene_manager_get_scene_state(ibutton->scene_manager, iButtonSceneEmulate);
|
||||
if(cnt > 0) {
|
||||
cnt--;
|
||||
if(cnt == 0) {
|
||||
if(--cnt == 0) {
|
||||
ibutton_notification_message(ibutton, iButtonNotificationMessageEmulateBlink);
|
||||
}
|
||||
scene_manager_set_scene_state(ibutton->scene_manager, iButtonSceneEmulate, cnt);
|
||||
|
@ -101,7 +71,7 @@ bool ibutton_scene_emulate_on_event(void* context, SceneManagerEvent event) {
|
|||
|
||||
void ibutton_scene_emulate_on_exit(void* context) {
|
||||
iButton* ibutton = context;
|
||||
ibutton_worker_stop(ibutton->key_worker);
|
||||
ibutton_worker_stop(ibutton->worker);
|
||||
widget_reset(ibutton->widget);
|
||||
ibutton_notification_message(ibutton, iButtonNotificationMessageBlinkStop);
|
||||
}
|
||||
|
|
|
@ -1,66 +1,54 @@
|
|||
#include "../ibutton_i.h"
|
||||
#include <toolbox/path.h>
|
||||
|
||||
void ibutton_scene_info_on_enter(void* context) {
|
||||
iButton* ibutton = context;
|
||||
Widget* widget = ibutton->widget;
|
||||
iButtonKey* key = ibutton->key;
|
||||
Widget* widget = ibutton->widget;
|
||||
|
||||
const uint8_t* key_data = ibutton_key_get_data_p(key);
|
||||
const iButtonProtocolId protocol_id = ibutton_key_get_protocol_id(key);
|
||||
|
||||
FuriString* key_name;
|
||||
key_name = furi_string_alloc();
|
||||
path_extract_filename(ibutton->file_path, key_name, true);
|
||||
FuriString* tmp = furi_string_alloc();
|
||||
|
||||
furi_string_printf(
|
||||
tmp,
|
||||
"\e#%s [%s]\e#",
|
||||
ibutton->key_name,
|
||||
ibutton_protocols_get_name(ibutton->protocols, protocol_id));
|
||||
|
||||
ibutton_text_store_set(ibutton, "%s", furi_string_get_cstr(key_name));
|
||||
widget_add_text_box_element(
|
||||
widget, 0, 0, 128, 23, AlignCenter, AlignCenter, ibutton->text_store, true);
|
||||
widget, 0, 2, 128, 12, AlignLeft, AlignTop, furi_string_get_cstr(tmp), true);
|
||||
|
||||
switch(ibutton_key_get_type(key)) {
|
||||
case iButtonKeyDS1990:
|
||||
ibutton_text_store_set(
|
||||
ibutton,
|
||||
"%02X %02X %02X %02X %02X %02X %02X %02X",
|
||||
key_data[0],
|
||||
key_data[1],
|
||||
key_data[2],
|
||||
key_data[3],
|
||||
key_data[4],
|
||||
key_data[5],
|
||||
key_data[6],
|
||||
key_data[7]);
|
||||
widget_add_string_element(widget, 64, 36, AlignCenter, AlignBottom, FontPrimary, "Dallas");
|
||||
break;
|
||||
furi_string_reset(tmp);
|
||||
ibutton_protocols_render_brief_data(ibutton->protocols, key, tmp);
|
||||
|
||||
case iButtonKeyMetakom:
|
||||
ibutton_text_store_set(
|
||||
ibutton, "%02X %02X %02X %02X", key_data[0], key_data[1], key_data[2], key_data[3]);
|
||||
widget_add_string_element(
|
||||
widget, 64, 36, AlignCenter, AlignBottom, FontPrimary, "Metakom");
|
||||
break;
|
||||
widget_add_string_multiline_element(
|
||||
widget, 0, 16, AlignLeft, AlignTop, FontSecondary, furi_string_get_cstr(tmp));
|
||||
|
||||
case iButtonKeyCyfral:
|
||||
ibutton_text_store_set(ibutton, "%02X %02X", key_data[0], key_data[1]);
|
||||
widget_add_string_element(widget, 64, 36, AlignCenter, AlignBottom, FontPrimary, "Cyfral");
|
||||
break;
|
||||
if(ibutton_protocols_get_features(ibutton->protocols, protocol_id) &
|
||||
iButtonProtocolFeatureExtData) {
|
||||
widget_add_button_element(
|
||||
widget, GuiButtonTypeRight, "More", ibutton_widget_callback, context);
|
||||
}
|
||||
|
||||
widget_add_string_element(
|
||||
widget, 64, 50, AlignCenter, AlignBottom, FontSecondary, ibutton->text_store);
|
||||
|
||||
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewWidget);
|
||||
|
||||
furi_string_free(key_name);
|
||||
furi_string_free(tmp);
|
||||
}
|
||||
|
||||
bool ibutton_scene_info_on_event(void* context, SceneManagerEvent event) {
|
||||
UNUSED(context);
|
||||
UNUSED(event);
|
||||
return false;
|
||||
iButton* ibutton = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
consumed = true;
|
||||
if(event.event == GuiButtonTypeRight) {
|
||||
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneViewData);
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void ibutton_scene_info_on_exit(void* context) {
|
||||
iButton* ibutton = context;
|
||||
ibutton_text_store_clear(ibutton);
|
||||
widget_reset(ibutton->widget);
|
||||
}
|
||||
|
|
|
@ -10,14 +10,13 @@ void ibutton_scene_read_on_enter(void* context) {
|
|||
iButton* ibutton = context;
|
||||
Popup* popup = ibutton->popup;
|
||||
iButtonKey* key = ibutton->key;
|
||||
iButtonWorker* worker = ibutton->key_worker;
|
||||
iButtonWorker* worker = ibutton->worker;
|
||||
|
||||
popup_set_header(popup, "iButton", 95, 26, AlignCenter, AlignBottom);
|
||||
popup_set_text(popup, "Waiting\nfor key ...", 95, 30, AlignCenter, AlignTop);
|
||||
popup_set_icon(popup, 0, 5, &I_DolphinWait_61x59);
|
||||
|
||||
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewPopup);
|
||||
furi_string_set(ibutton->file_path, IBUTTON_APP_FOLDER);
|
||||
|
||||
ibutton_worker_read_set_callback(worker, ibutton_scene_read_callback, ibutton);
|
||||
ibutton_worker_read_start(worker, key);
|
||||
|
@ -35,25 +34,14 @@ bool ibutton_scene_read_on_event(void* context, SceneManagerEvent event) {
|
|||
} else if(event.type == SceneManagerEventTypeCustom) {
|
||||
consumed = true;
|
||||
if(event.event == iButtonCustomEventWorkerRead) {
|
||||
bool success = false;
|
||||
iButtonKey* key = ibutton->key;
|
||||
|
||||
if(ibutton_key_get_type(key) == iButtonKeyDS1990) {
|
||||
if(!ibutton_key_dallas_crc_is_valid(key)) {
|
||||
scene_manager_next_scene(scene_manager, iButtonSceneReadCRCError);
|
||||
} else if(!ibutton_key_dallas_is_1990_key(key)) {
|
||||
scene_manager_next_scene(scene_manager, iButtonSceneReadNotKeyError);
|
||||
} else {
|
||||
success = true;
|
||||
}
|
||||
} else {
|
||||
success = true;
|
||||
}
|
||||
|
||||
if(success) {
|
||||
if(ibutton_protocols_is_valid(ibutton->protocols, ibutton->key)) {
|
||||
ibutton_notification_message(ibutton, iButtonNotificationMessageSuccess);
|
||||
scene_manager_next_scene(scene_manager, iButtonSceneReadSuccess);
|
||||
|
||||
DOLPHIN_DEED(DolphinDeedIbuttonReadSuccess);
|
||||
|
||||
} else {
|
||||
scene_manager_next_scene(scene_manager, iButtonSceneReadError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +52,7 @@ bool ibutton_scene_read_on_event(void* context, SceneManagerEvent event) {
|
|||
void ibutton_scene_read_on_exit(void* context) {
|
||||
iButton* ibutton = context;
|
||||
Popup* popup = ibutton->popup;
|
||||
ibutton_worker_stop(ibutton->key_worker);
|
||||
ibutton_worker_stop(ibutton->worker);
|
||||
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
|
||||
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
popup_set_icon(popup, 0, 0, NULL);
|
||||
|
|
|
@ -1,70 +0,0 @@
|
|||
#include "../ibutton_i.h"
|
||||
#include <one_wire/maxim_crc.h>
|
||||
|
||||
static void ibutton_scene_read_crc_error_dialog_ex_callback(DialogExResult result, void* context) {
|
||||
iButton* ibutton = context;
|
||||
view_dispatcher_send_custom_event(ibutton->view_dispatcher, result);
|
||||
}
|
||||
|
||||
void ibutton_scene_read_crc_error_on_enter(void* context) {
|
||||
iButton* ibutton = context;
|
||||
DialogEx* dialog_ex = ibutton->dialog_ex;
|
||||
iButtonKey* key = ibutton->key;
|
||||
const uint8_t* key_data = ibutton_key_get_data_p(key);
|
||||
|
||||
ibutton_text_store_set(
|
||||
ibutton,
|
||||
"%02X %02X %02X %02X %02X %02X %02X %02X\nExpected CRC: %X",
|
||||
key_data[0],
|
||||
key_data[1],
|
||||
key_data[2],
|
||||
key_data[3],
|
||||
key_data[4],
|
||||
key_data[5],
|
||||
key_data[6],
|
||||
key_data[7],
|
||||
maxim_crc8(key_data, 7, MAXIM_CRC8_INIT));
|
||||
|
||||
dialog_ex_set_header(dialog_ex, "CRC ERROR", 64, 10, AlignCenter, AlignCenter);
|
||||
dialog_ex_set_text(dialog_ex, ibutton->text_store, 64, 19, AlignCenter, AlignTop);
|
||||
dialog_ex_set_left_button_text(dialog_ex, "Retry");
|
||||
dialog_ex_set_right_button_text(dialog_ex, "More");
|
||||
dialog_ex_set_result_callback(dialog_ex, ibutton_scene_read_crc_error_dialog_ex_callback);
|
||||
dialog_ex_set_context(dialog_ex, ibutton);
|
||||
|
||||
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewDialogEx);
|
||||
|
||||
ibutton_notification_message(ibutton, iButtonNotificationMessageError);
|
||||
ibutton_notification_message(ibutton, iButtonNotificationMessageRedOn);
|
||||
}
|
||||
|
||||
bool ibutton_scene_read_crc_error_on_event(void* context, SceneManagerEvent event) {
|
||||
iButton* ibutton = context;
|
||||
SceneManager* scene_manager = ibutton->scene_manager;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeBack) {
|
||||
consumed = true;
|
||||
scene_manager_next_scene(scene_manager, iButtonSceneExitConfirm);
|
||||
} else if(event.type == SceneManagerEventTypeCustom) {
|
||||
consumed = true;
|
||||
if(event.event == DialogExResultRight) {
|
||||
scene_manager_next_scene(scene_manager, iButtonSceneReadKeyMenu);
|
||||
} else if(event.event == DialogExResultLeft) {
|
||||
scene_manager_previous_scene(scene_manager);
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void ibutton_scene_read_crc_error_on_exit(void* context) {
|
||||
iButton* ibutton = context;
|
||||
DialogEx* dialog_ex = ibutton->dialog_ex;
|
||||
|
||||
ibutton_text_store_clear(ibutton);
|
||||
|
||||
dialog_ex_reset(dialog_ex);
|
||||
|
||||
ibutton_notification_message(ibutton, iButtonNotificationMessageRedOff);
|
||||
}
|
58
applications/main/ibutton/scenes/ibutton_scene_read_error.c
Normal file
58
applications/main/ibutton/scenes/ibutton_scene_read_error.c
Normal file
|
@ -0,0 +1,58 @@
|
|||
#include "../ibutton_i.h"
|
||||
#include <one_wire/maxim_crc.h>
|
||||
|
||||
void ibutton_scene_read_error_on_enter(void* context) {
|
||||
iButton* ibutton = context;
|
||||
iButtonKey* key = ibutton->key;
|
||||
|
||||
Widget* widget = ibutton->widget;
|
||||
|
||||
FuriString* tmp = furi_string_alloc();
|
||||
|
||||
widget_add_button_element(
|
||||
widget, GuiButtonTypeLeft, "Retry", ibutton_widget_callback, context);
|
||||
widget_add_button_element(
|
||||
widget, GuiButtonTypeRight, "More", ibutton_widget_callback, context);
|
||||
|
||||
widget_add_string_element(
|
||||
widget, 128 / 2, 2, AlignCenter, AlignTop, FontPrimary, "Read Error");
|
||||
|
||||
ibutton_protocols_render_error(ibutton->protocols, key, tmp);
|
||||
|
||||
widget_add_string_multiline_element(
|
||||
widget, 128 / 2, 16, AlignCenter, AlignTop, FontSecondary, furi_string_get_cstr(tmp));
|
||||
|
||||
ibutton_notification_message(ibutton, iButtonNotificationMessageError);
|
||||
ibutton_notification_message(ibutton, iButtonNotificationMessageRedOn);
|
||||
|
||||
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewWidget);
|
||||
furi_string_free(tmp);
|
||||
}
|
||||
|
||||
bool ibutton_scene_read_error_on_event(void* context, SceneManagerEvent event) {
|
||||
iButton* ibutton = context;
|
||||
SceneManager* scene_manager = ibutton->scene_manager;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeBack) {
|
||||
consumed = true;
|
||||
scene_manager_next_scene(scene_manager, iButtonSceneExitConfirm);
|
||||
|
||||
} else if(event.type == SceneManagerEventTypeCustom) {
|
||||
consumed = true;
|
||||
if(event.event == GuiButtonTypeLeft) {
|
||||
scene_manager_previous_scene(scene_manager);
|
||||
} else if(event.event == GuiButtonTypeRight) {
|
||||
scene_manager_next_scene(scene_manager, iButtonSceneReadKeyMenu);
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void ibutton_scene_read_error_on_exit(void* context) {
|
||||
iButton* ibutton = context;
|
||||
|
||||
ibutton_notification_message(ibutton, iButtonNotificationMessageRedOff);
|
||||
widget_reset(ibutton->widget);
|
||||
}
|
|
@ -4,7 +4,9 @@
|
|||
typedef enum {
|
||||
SubmenuIndexSave,
|
||||
SubmenuIndexEmulate,
|
||||
SubmenuIndexWrite,
|
||||
SubmenuIndexViewData,
|
||||
SubmenuIndexWriteBlank,
|
||||
SubmenuIndexWriteCopy,
|
||||
} SubmenuIndex;
|
||||
|
||||
void ibutton_scene_read_key_menu_submenu_callback(void* context, uint32_t index) {
|
||||
|
@ -16,6 +18,9 @@ void ibutton_scene_read_key_menu_on_enter(void* context) {
|
|||
iButton* ibutton = context;
|
||||
Submenu* submenu = ibutton->submenu;
|
||||
|
||||
const iButtonProtocolId protocol_id = ibutton_key_get_protocol_id(ibutton->key);
|
||||
const uint32_t features = ibutton_protocols_get_features(ibutton->protocols, protocol_id);
|
||||
|
||||
submenu_add_item(
|
||||
submenu, "Save", SubmenuIndexSave, ibutton_scene_read_key_menu_submenu_callback, ibutton);
|
||||
submenu_add_item(
|
||||
|
@ -24,36 +29,66 @@ void ibutton_scene_read_key_menu_on_enter(void* context) {
|
|||
SubmenuIndexEmulate,
|
||||
ibutton_scene_read_key_menu_submenu_callback,
|
||||
ibutton);
|
||||
if(ibutton_key_get_type(ibutton->key) == iButtonKeyDS1990) {
|
||||
|
||||
if(features & iButtonProtocolFeatureExtData) {
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Write",
|
||||
SubmenuIndexWrite,
|
||||
"View Data",
|
||||
SubmenuIndexViewData,
|
||||
ibutton_scene_read_key_menu_submenu_callback,
|
||||
ibutton);
|
||||
}
|
||||
|
||||
if(features & iButtonProtocolFeatureWriteBlank) {
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Write Blank",
|
||||
SubmenuIndexWriteBlank,
|
||||
ibutton_scene_read_key_menu_submenu_callback,
|
||||
ibutton);
|
||||
}
|
||||
|
||||
if(features & iButtonProtocolFeatureWriteCopy) {
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Write Copy",
|
||||
SubmenuIndexWriteCopy,
|
||||
ibutton_scene_read_key_menu_submenu_callback,
|
||||
ibutton);
|
||||
}
|
||||
|
||||
submenu_set_selected_item(
|
||||
submenu, scene_manager_get_scene_state(ibutton->scene_manager, iButtonSceneReadKeyMenu));
|
||||
|
||||
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewSubmenu);
|
||||
}
|
||||
|
||||
bool ibutton_scene_read_key_menu_on_event(void* context, SceneManagerEvent event) {
|
||||
iButton* ibutton = context;
|
||||
SceneManager* scene_manager = ibutton->scene_manager;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
scene_manager_set_scene_state(
|
||||
ibutton->scene_manager, iButtonSceneReadKeyMenu, event.event);
|
||||
scene_manager_set_scene_state(scene_manager, iButtonSceneReadKeyMenu, event.event);
|
||||
consumed = true;
|
||||
|
||||
if(event.event == SubmenuIndexSave) {
|
||||
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneSaveName);
|
||||
scene_manager_next_scene(scene_manager, iButtonSceneSaveName);
|
||||
} else if(event.event == SubmenuIndexEmulate) {
|
||||
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneEmulate);
|
||||
scene_manager_next_scene(scene_manager, iButtonSceneEmulate);
|
||||
DOLPHIN_DEED(DolphinDeedIbuttonEmulate);
|
||||
} else if(event.event == SubmenuIndexWrite) {
|
||||
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneWrite);
|
||||
} else if(event.event == SubmenuIndexViewData) {
|
||||
scene_manager_next_scene(scene_manager, iButtonSceneViewData);
|
||||
} else if(event.event == SubmenuIndexWriteBlank) {
|
||||
ibutton->write_mode = iButtonWriteModeBlank;
|
||||
scene_manager_next_scene(scene_manager, iButtonSceneWrite);
|
||||
} else if(event.event == SubmenuIndexWriteCopy) {
|
||||
ibutton->write_mode = iButtonWriteModeCopy;
|
||||
scene_manager_next_scene(scene_manager, iButtonSceneWrite);
|
||||
}
|
||||
} else if(event.event == SceneManagerEventTypeBack) {
|
||||
scene_manager_set_scene_state(
|
||||
ibutton->scene_manager, iButtonSceneReadKeyMenu, SubmenuIndexSave);
|
||||
// Event is not consumed
|
||||
}
|
||||
|
||||
return consumed;
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
#include "../ibutton_i.h"
|
||||
#include <one_wire/maxim_crc.h>
|
||||
|
||||
static void
|
||||
ibutton_scene_read_not_key_error_dialog_ex_callback(DialogExResult result, void* context) {
|
||||
iButton* ibutton = context;
|
||||
view_dispatcher_send_custom_event(ibutton->view_dispatcher, result);
|
||||
}
|
||||
|
||||
void ibutton_scene_read_not_key_error_on_enter(void* context) {
|
||||
iButton* ibutton = context;
|
||||
DialogEx* dialog_ex = ibutton->dialog_ex;
|
||||
iButtonKey* key = ibutton->key;
|
||||
const uint8_t* key_data = ibutton_key_get_data_p(key);
|
||||
|
||||
ibutton_text_store_set(
|
||||
ibutton,
|
||||
"THIS IS NOT A KEY\n%02X %02X %02X %02X %02X %02X %02X %02X",
|
||||
key_data[0],
|
||||
key_data[1],
|
||||
key_data[2],
|
||||
key_data[3],
|
||||
key_data[4],
|
||||
key_data[5],
|
||||
key_data[6],
|
||||
key_data[7],
|
||||
maxim_crc8(key_data, 7, MAXIM_CRC8_INIT));
|
||||
|
||||
dialog_ex_set_header(dialog_ex, "CRC ERROR", 64, 10, AlignCenter, AlignCenter);
|
||||
dialog_ex_set_text(dialog_ex, ibutton->text_store, 64, 19, AlignCenter, AlignTop);
|
||||
dialog_ex_set_left_button_text(dialog_ex, "Retry");
|
||||
dialog_ex_set_right_button_text(dialog_ex, "More");
|
||||
dialog_ex_set_result_callback(dialog_ex, ibutton_scene_read_not_key_error_dialog_ex_callback);
|
||||
dialog_ex_set_context(dialog_ex, ibutton);
|
||||
|
||||
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewDialogEx);
|
||||
|
||||
ibutton_notification_message(ibutton, iButtonNotificationMessageError);
|
||||
ibutton_notification_message(ibutton, iButtonNotificationMessageRedOn);
|
||||
}
|
||||
|
||||
bool ibutton_scene_read_not_key_error_on_event(void* context, SceneManagerEvent event) {
|
||||
iButton* ibutton = context;
|
||||
SceneManager* scene_manager = ibutton->scene_manager;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeBack) {
|
||||
consumed = true;
|
||||
scene_manager_next_scene(scene_manager, iButtonSceneExitConfirm);
|
||||
} else if(event.type == SceneManagerEventTypeCustom) {
|
||||
consumed = true;
|
||||
if(event.event == DialogExResultRight) {
|
||||
scene_manager_next_scene(scene_manager, iButtonSceneReadKeyMenu);
|
||||
} else if(event.event == DialogExResultLeft) {
|
||||
scene_manager_previous_scene(scene_manager);
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void ibutton_scene_read_not_key_error_on_exit(void* context) {
|
||||
iButton* ibutton = context;
|
||||
DialogEx* dialog_ex = ibutton->dialog_ex;
|
||||
|
||||
ibutton_text_store_clear(ibutton);
|
||||
|
||||
dialog_ex_reset(dialog_ex);
|
||||
|
||||
ibutton_notification_message(ibutton, iButtonNotificationMessageRedOff);
|
||||
}
|
|
@ -1,55 +1,40 @@
|
|||
#include "../ibutton_i.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
static void ibutton_scene_read_success_dialog_ex_callback(DialogExResult result, void* context) {
|
||||
iButton* ibutton = context;
|
||||
view_dispatcher_send_custom_event(ibutton->view_dispatcher, result);
|
||||
}
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
void ibutton_scene_read_success_on_enter(void* context) {
|
||||
iButton* ibutton = context;
|
||||
DialogEx* dialog_ex = ibutton->dialog_ex;
|
||||
iButtonKey* key = ibutton->key;
|
||||
const uint8_t* key_data = ibutton_key_get_data_p(key);
|
||||
Widget* widget = ibutton->widget;
|
||||
|
||||
switch(ibutton_key_get_type(key)) {
|
||||
case iButtonKeyDS1990:
|
||||
ibutton_text_store_set(
|
||||
ibutton,
|
||||
"Dallas\n%02X %02X %02X %02X\n%02X %02X %02X %02X",
|
||||
key_data[0],
|
||||
key_data[1],
|
||||
key_data[2],
|
||||
key_data[3],
|
||||
key_data[4],
|
||||
key_data[5],
|
||||
key_data[6],
|
||||
key_data[7]);
|
||||
break;
|
||||
case iButtonKeyCyfral:
|
||||
ibutton_text_store_set(ibutton, "Cyfral\n%02X %02X", key_data[0], key_data[1]);
|
||||
break;
|
||||
case iButtonKeyMetakom:
|
||||
ibutton_text_store_set(
|
||||
ibutton,
|
||||
"Metakom\n%02X %02X %02X %02X",
|
||||
key_data[0],
|
||||
key_data[1],
|
||||
key_data[2],
|
||||
key_data[3]);
|
||||
break;
|
||||
}
|
||||
FuriString* tmp = furi_string_alloc();
|
||||
|
||||
dialog_ex_set_text(dialog_ex, ibutton->text_store, 95, 30, AlignCenter, AlignCenter);
|
||||
dialog_ex_set_left_button_text(dialog_ex, "Retry");
|
||||
dialog_ex_set_right_button_text(dialog_ex, "More");
|
||||
dialog_ex_set_icon(dialog_ex, 0, 1, &I_DolphinReadingSuccess_59x63);
|
||||
dialog_ex_set_result_callback(dialog_ex, ibutton_scene_read_success_dialog_ex_callback);
|
||||
dialog_ex_set_context(dialog_ex, ibutton);
|
||||
const iButtonProtocolId protocol_id = ibutton_key_get_protocol_id(key);
|
||||
|
||||
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewDialogEx);
|
||||
widget_add_button_element(
|
||||
widget, GuiButtonTypeLeft, "Retry", ibutton_widget_callback, context);
|
||||
widget_add_button_element(
|
||||
widget, GuiButtonTypeRight, "More", ibutton_widget_callback, context);
|
||||
|
||||
furi_string_printf(
|
||||
tmp,
|
||||
"%s[%s]",
|
||||
ibutton_protocols_get_name(ibutton->protocols, protocol_id),
|
||||
ibutton_protocols_get_manufacturer(ibutton->protocols, protocol_id));
|
||||
|
||||
widget_add_string_element(
|
||||
widget, 0, 2, AlignLeft, AlignTop, FontPrimary, furi_string_get_cstr(tmp));
|
||||
|
||||
furi_string_reset(tmp);
|
||||
ibutton_protocols_render_brief_data(ibutton->protocols, key, tmp);
|
||||
|
||||
widget_add_string_multiline_element(
|
||||
widget, 0, 16, AlignLeft, AlignTop, FontSecondary, furi_string_get_cstr(tmp));
|
||||
|
||||
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewWidget);
|
||||
ibutton_notification_message(ibutton, iButtonNotificationMessageGreenOn);
|
||||
|
||||
furi_string_free(tmp);
|
||||
}
|
||||
|
||||
bool ibutton_scene_read_success_on_event(void* context, SceneManagerEvent event) {
|
||||
|
@ -62,9 +47,9 @@ bool ibutton_scene_read_success_on_event(void* context, SceneManagerEvent event)
|
|||
scene_manager_next_scene(scene_manager, iButtonSceneExitConfirm);
|
||||
} else if(event.type == SceneManagerEventTypeCustom) {
|
||||
consumed = true;
|
||||
if(event.event == DialogExResultRight) {
|
||||
if(event.event == GuiButtonTypeRight) {
|
||||
scene_manager_next_scene(scene_manager, iButtonSceneReadKeyMenu);
|
||||
} else if(event.event == DialogExResultLeft) {
|
||||
} else if(event.event == GuiButtonTypeLeft) {
|
||||
scene_manager_next_scene(scene_manager, iButtonSceneRetryConfirm);
|
||||
}
|
||||
}
|
||||
|
@ -74,11 +59,8 @@ bool ibutton_scene_read_success_on_event(void* context, SceneManagerEvent event)
|
|||
|
||||
void ibutton_scene_read_success_on_exit(void* context) {
|
||||
iButton* ibutton = context;
|
||||
DialogEx* dialog_ex = ibutton->dialog_ex;
|
||||
|
||||
ibutton_text_store_clear(ibutton);
|
||||
|
||||
dialog_ex_reset(dialog_ex);
|
||||
widget_reset(ibutton->widget);
|
||||
|
||||
ibutton_notification_message(ibutton, iButtonNotificationMessageGreenOff);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
#include "../ibutton_i.h"
|
||||
#include <toolbox/path.h>
|
||||
#include <rpc/rpc_app.h>
|
||||
|
||||
void ibutton_scene_rpc_on_enter(void* context) {
|
||||
iButton* ibutton = context;
|
||||
|
@ -17,8 +15,6 @@ void ibutton_scene_rpc_on_enter(void* context) {
|
|||
}
|
||||
|
||||
bool ibutton_scene_rpc_on_event(void* context, SceneManagerEvent event) {
|
||||
UNUSED(context);
|
||||
UNUSED(event);
|
||||
iButton* ibutton = context;
|
||||
Popup* popup = ibutton->popup;
|
||||
|
||||
|
@ -26,40 +22,32 @@ bool ibutton_scene_rpc_on_event(void* context, SceneManagerEvent event) {
|
|||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
consumed = true;
|
||||
if(event.event == iButtonCustomEventRpcLoad) {
|
||||
const char* arg = rpc_system_app_get_data(ibutton->rpc_ctx);
|
||||
bool result = false;
|
||||
if(arg && (furi_string_empty(ibutton->file_path))) {
|
||||
furi_string_set(ibutton->file_path, arg);
|
||||
if(ibutton_load_key_data(ibutton, ibutton->file_path, false)) {
|
||||
ibutton_worker_emulate_start(ibutton->key_worker, ibutton->key);
|
||||
FuriString* key_name;
|
||||
key_name = furi_string_alloc();
|
||||
if(furi_string_end_with(ibutton->file_path, IBUTTON_APP_EXTENSION)) {
|
||||
path_extract_filename(ibutton->file_path, key_name, true);
|
||||
}
|
||||
|
||||
if(!furi_string_empty(key_name)) {
|
||||
ibutton_text_store_set(
|
||||
ibutton, "emulating\n%s", furi_string_get_cstr(key_name));
|
||||
} else {
|
||||
ibutton_text_store_set(ibutton, "emulating");
|
||||
}
|
||||
popup_set_text(popup, ibutton->text_store, 82, 32, AlignCenter, AlignTop);
|
||||
if(event.event == iButtonCustomEventRpcLoad) {
|
||||
bool result = false;
|
||||
const char* file_path = rpc_system_app_get_data(ibutton->rpc);
|
||||
|
||||
if(file_path && (furi_string_empty(ibutton->file_path))) {
|
||||
furi_string_set(ibutton->file_path, file_path);
|
||||
|
||||
if(ibutton_load_key(ibutton)) {
|
||||
popup_set_text(popup, ibutton->key_name, 82, 32, AlignCenter, AlignTop);
|
||||
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewPopup);
|
||||
|
||||
ibutton_notification_message(ibutton, iButtonNotificationMessageEmulateStart);
|
||||
ibutton_worker_emulate_start(ibutton->worker, ibutton->key);
|
||||
|
||||
furi_string_free(key_name);
|
||||
result = true;
|
||||
} else {
|
||||
furi_string_reset(ibutton->file_path);
|
||||
}
|
||||
}
|
||||
rpc_system_app_confirm(ibutton->rpc_ctx, RpcAppEventLoadFile, result);
|
||||
|
||||
rpc_system_app_confirm(ibutton->rpc, RpcAppEventLoadFile, result);
|
||||
|
||||
} else if(event.event == iButtonCustomEventRpcExit) {
|
||||
rpc_system_app_confirm(ibutton->rpc_ctx, RpcAppEventAppExit, true);
|
||||
rpc_system_app_confirm(ibutton->rpc, RpcAppEventAppExit, true);
|
||||
scene_manager_stop(ibutton->scene_manager);
|
||||
view_dispatcher_stop(ibutton->view_dispatcher);
|
||||
|
||||
} else if(event.event == iButtonCustomEventRpcSessionClose) {
|
||||
scene_manager_stop(ibutton->scene_manager);
|
||||
view_dispatcher_stop(ibutton->view_dispatcher);
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include "../ibutton_i.h"
|
||||
#include <lib/toolbox/random_name.h>
|
||||
|
||||
#include <toolbox/random_name.h>
|
||||
#include <toolbox/path.h>
|
||||
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
static void ibutton_scene_save_name_text_input_callback(void* context) {
|
||||
|
@ -12,17 +14,10 @@ void ibutton_scene_save_name_on_enter(void* context) {
|
|||
iButton* ibutton = context;
|
||||
TextInput* text_input = ibutton->text_input;
|
||||
|
||||
FuriString* key_name;
|
||||
key_name = furi_string_alloc();
|
||||
if(furi_string_end_with(ibutton->file_path, IBUTTON_APP_EXTENSION)) {
|
||||
path_extract_filename(ibutton->file_path, key_name, true);
|
||||
}
|
||||
const bool is_new_file = furi_string_empty(ibutton->file_path);
|
||||
|
||||
const bool key_name_is_empty = furi_string_empty(key_name);
|
||||
if(key_name_is_empty) {
|
||||
set_random_name(ibutton->text_store, IBUTTON_TEXT_STORE_SIZE);
|
||||
} else {
|
||||
ibutton_text_store_set(ibutton, "%s", furi_string_get_cstr(key_name));
|
||||
if(is_new_file) {
|
||||
set_random_name(ibutton->key_name, IBUTTON_KEY_NAME_SIZE);
|
||||
}
|
||||
|
||||
text_input_set_header_text(text_input, "Name the key");
|
||||
|
@ -30,23 +25,15 @@ void ibutton_scene_save_name_on_enter(void* context) {
|
|||
text_input,
|
||||
ibutton_scene_save_name_text_input_callback,
|
||||
ibutton,
|
||||
ibutton->text_store,
|
||||
ibutton->key_name,
|
||||
IBUTTON_KEY_NAME_SIZE,
|
||||
key_name_is_empty);
|
||||
is_new_file);
|
||||
|
||||
FuriString* folder_path;
|
||||
folder_path = furi_string_alloc();
|
||||
|
||||
path_extract_dirname(furi_string_get_cstr(ibutton->file_path), folder_path);
|
||||
|
||||
ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
|
||||
furi_string_get_cstr(folder_path), IBUTTON_APP_EXTENSION, furi_string_get_cstr(key_name));
|
||||
ValidatorIsFile* validator_is_file =
|
||||
validator_is_file_alloc_init(IBUTTON_APP_FOLDER, IBUTTON_APP_EXTENSION, ibutton->key_name);
|
||||
text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
|
||||
|
||||
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewTextInput);
|
||||
|
||||
furi_string_free(key_name);
|
||||
furi_string_free(folder_path);
|
||||
}
|
||||
|
||||
bool ibutton_scene_save_name_on_event(void* context, SceneManagerEvent event) {
|
||||
|
@ -56,8 +43,16 @@ bool ibutton_scene_save_name_on_event(void* context, SceneManagerEvent event) {
|
|||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
consumed = true;
|
||||
if(event.event == iButtonCustomEventTextEditResult) {
|
||||
if(ibutton_save_key(ibutton, ibutton->text_store)) {
|
||||
furi_string_printf(
|
||||
ibutton->file_path,
|
||||
"%s/%s%s",
|
||||
IBUTTON_APP_FOLDER,
|
||||
ibutton->key_name,
|
||||
IBUTTON_APP_EXTENSION);
|
||||
|
||||
if(ibutton_save_key(ibutton)) {
|
||||
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneSaveSuccess);
|
||||
|
||||
if(scene_manager_has_previous_scene(
|
||||
ibutton->scene_manager, iButtonSceneSavedKeyMenu)) {
|
||||
// Nothing, do not count editing as saving
|
||||
|
@ -67,6 +62,7 @@ bool ibutton_scene_save_name_on_event(void* context, SceneManagerEvent event) {
|
|||
} else {
|
||||
DOLPHIN_DEED(DolphinDeedIbuttonSave);
|
||||
}
|
||||
|
||||
} else {
|
||||
const uint32_t possible_scenes[] = {
|
||||
iButtonSceneReadKeyMenu, iButtonSceneSavedKeyMenu, iButtonSceneAddType};
|
||||
|
|
|
@ -3,72 +3,70 @@
|
|||
|
||||
enum SubmenuIndex {
|
||||
SubmenuIndexEmulate,
|
||||
SubmenuIndexWrite,
|
||||
SubmenuIndexWriteBlank,
|
||||
SubmenuIndexWriteCopy,
|
||||
SubmenuIndexEdit,
|
||||
SubmenuIndexDelete,
|
||||
SubmenuIndexInfo,
|
||||
};
|
||||
|
||||
void ibutton_scene_saved_key_menu_submenu_callback(void* context, uint32_t index) {
|
||||
iButton* ibutton = context;
|
||||
view_dispatcher_send_custom_event(ibutton->view_dispatcher, index);
|
||||
}
|
||||
|
||||
void ibutton_scene_saved_key_menu_on_enter(void* context) {
|
||||
iButton* ibutton = context;
|
||||
Submenu* submenu = ibutton->submenu;
|
||||
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Emulate",
|
||||
SubmenuIndexEmulate,
|
||||
ibutton_scene_saved_key_menu_submenu_callback,
|
||||
ibutton);
|
||||
if(ibutton_key_get_type(ibutton->key) == iButtonKeyDS1990) {
|
||||
const uint32_t features = ibutton_protocols_get_features(
|
||||
ibutton->protocols, ibutton_key_get_protocol_id(ibutton->key));
|
||||
|
||||
submenu_add_item(submenu, "Emulate", SubmenuIndexEmulate, ibutton_submenu_callback, ibutton);
|
||||
|
||||
if(features & iButtonProtocolFeatureWriteBlank) {
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Write",
|
||||
SubmenuIndexWrite,
|
||||
ibutton_scene_saved_key_menu_submenu_callback,
|
||||
ibutton);
|
||||
submenu, "Write Blank", SubmenuIndexWriteBlank, ibutton_submenu_callback, ibutton);
|
||||
}
|
||||
submenu_add_item(
|
||||
submenu, "Edit", SubmenuIndexEdit, ibutton_scene_saved_key_menu_submenu_callback, ibutton);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Delete",
|
||||
SubmenuIndexDelete,
|
||||
ibutton_scene_saved_key_menu_submenu_callback,
|
||||
ibutton);
|
||||
submenu_add_item(
|
||||
submenu, "Info", SubmenuIndexInfo, ibutton_scene_saved_key_menu_submenu_callback, ibutton);
|
||||
|
||||
if(features & iButtonProtocolFeatureWriteCopy) {
|
||||
submenu_add_item(
|
||||
submenu, "Write Copy", SubmenuIndexWriteCopy, ibutton_submenu_callback, ibutton);
|
||||
}
|
||||
|
||||
submenu_add_item(submenu, "Edit", SubmenuIndexEdit, ibutton_submenu_callback, ibutton);
|
||||
submenu_add_item(submenu, "Delete", SubmenuIndexDelete, ibutton_submenu_callback, ibutton);
|
||||
submenu_add_item(submenu, "Info", SubmenuIndexInfo, ibutton_submenu_callback, ibutton);
|
||||
|
||||
submenu_set_selected_item(
|
||||
submenu, scene_manager_get_scene_state(ibutton->scene_manager, iButtonSceneSavedKeyMenu));
|
||||
|
||||
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewSubmenu);
|
||||
}
|
||||
|
||||
bool ibutton_scene_saved_key_menu_on_event(void* context, SceneManagerEvent event) {
|
||||
iButton* ibutton = context;
|
||||
SceneManager* scene_manager = ibutton->scene_manager;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
scene_manager_set_scene_state(
|
||||
ibutton->scene_manager, iButtonSceneSavedKeyMenu, event.event);
|
||||
scene_manager_set_scene_state(scene_manager, iButtonSceneSavedKeyMenu, event.event);
|
||||
consumed = true;
|
||||
if(event.event == SubmenuIndexEmulate) {
|
||||
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneEmulate);
|
||||
scene_manager_next_scene(scene_manager, iButtonSceneEmulate);
|
||||
DOLPHIN_DEED(DolphinDeedIbuttonEmulate);
|
||||
} else if(event.event == SubmenuIndexWrite) {
|
||||
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneWrite);
|
||||
} else if(event.event == SubmenuIndexWriteBlank) {
|
||||
ibutton->write_mode = iButtonWriteModeBlank;
|
||||
scene_manager_next_scene(scene_manager, iButtonSceneWrite);
|
||||
} else if(event.event == SubmenuIndexWriteCopy) {
|
||||
ibutton->write_mode = iButtonWriteModeCopy;
|
||||
scene_manager_next_scene(scene_manager, iButtonSceneWrite);
|
||||
} else if(event.event == SubmenuIndexEdit) {
|
||||
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneAddValue);
|
||||
scene_manager_next_scene(scene_manager, iButtonSceneAddValue);
|
||||
} else if(event.event == SubmenuIndexDelete) {
|
||||
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneDeleteConfirm);
|
||||
scene_manager_next_scene(scene_manager, iButtonSceneDeleteConfirm);
|
||||
} else if(event.event == SubmenuIndexInfo) {
|
||||
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneInfo);
|
||||
scene_manager_next_scene(scene_manager, iButtonSceneInfo);
|
||||
}
|
||||
|
||||
} else if(event.type == SceneManagerEventTypeBack) {
|
||||
scene_manager_set_scene_state(
|
||||
scene_manager, iButtonSceneSavedKeyMenu, SubmenuIndexEmulate);
|
||||
// Event is not consumed
|
||||
}
|
||||
|
||||
return consumed;
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
void ibutton_scene_select_key_on_enter(void* context) {
|
||||
iButton* ibutton = context;
|
||||
|
||||
if(!ibutton_file_select(ibutton)) {
|
||||
if(ibutton_select_and_load_key(ibutton)) {
|
||||
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneSavedKeyMenu);
|
||||
} else {
|
||||
scene_manager_search_and_switch_to_previous_scene(
|
||||
ibutton->scene_manager, iButtonSceneStart);
|
||||
} else {
|
||||
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneSavedKeyMenu);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,21 +8,15 @@ enum SubmenuIndex {
|
|||
SubmenuIndexAdd,
|
||||
};
|
||||
|
||||
void ibutton_scene_start_submenu_callback(void* context, uint32_t index) {
|
||||
iButton* ibutton = context;
|
||||
view_dispatcher_send_custom_event(ibutton->view_dispatcher, index);
|
||||
}
|
||||
|
||||
void ibutton_scene_start_on_enter(void* context) {
|
||||
iButton* ibutton = context;
|
||||
Submenu* submenu = ibutton->submenu;
|
||||
|
||||
submenu_add_item(
|
||||
submenu, "Read", SubmenuIndexRead, ibutton_scene_start_submenu_callback, ibutton);
|
||||
submenu_add_item(
|
||||
submenu, "Saved", SubmenuIndexSaved, ibutton_scene_start_submenu_callback, ibutton);
|
||||
submenu_add_item(
|
||||
submenu, "Add Manually", SubmenuIndexAdd, ibutton_scene_start_submenu_callback, ibutton);
|
||||
ibutton_reset_key(ibutton);
|
||||
|
||||
submenu_add_item(submenu, "Read", SubmenuIndexRead, ibutton_submenu_callback, ibutton);
|
||||
submenu_add_item(submenu, "Saved", SubmenuIndexSaved, ibutton_submenu_callback, ibutton);
|
||||
submenu_add_item(submenu, "Add Manually", SubmenuIndexAdd, ibutton_submenu_callback, ibutton);
|
||||
|
||||
submenu_set_selected_item(
|
||||
submenu, scene_manager_get_scene_state(ibutton->scene_manager, iButtonSceneStart));
|
||||
|
@ -41,7 +35,6 @@ bool ibutton_scene_start_on_event(void* context, SceneManagerEvent event) {
|
|||
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneRead);
|
||||
DOLPHIN_DEED(DolphinDeedIbuttonRead);
|
||||
} else if(event.event == SubmenuIndexSaved) {
|
||||
furi_string_set(ibutton->file_path, IBUTTON_APP_FOLDER);
|
||||
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneSelectKey);
|
||||
} else if(event.event == SubmenuIndexAdd) {
|
||||
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneAddType);
|
||||
|
|
26
applications/main/ibutton/scenes/ibutton_scene_view_data.c
Normal file
26
applications/main/ibutton/scenes/ibutton_scene_view_data.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include "../ibutton_i.h"
|
||||
|
||||
void ibutton_scene_view_data_on_enter(void* context) {
|
||||
iButton* ibutton = context;
|
||||
iButtonKey* key = ibutton->key;
|
||||
Widget* widget = ibutton->widget;
|
||||
|
||||
FuriString* tmp = furi_string_alloc();
|
||||
ibutton_protocols_render_data(ibutton->protocols, key, tmp);
|
||||
|
||||
widget_add_text_scroll_element(widget, 0, 0, 128, 64, furi_string_get_cstr(tmp));
|
||||
|
||||
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewWidget);
|
||||
furi_string_free(tmp);
|
||||
}
|
||||
|
||||
bool ibutton_scene_view_data_on_event(void* context, SceneManagerEvent event) {
|
||||
UNUSED(context);
|
||||
UNUSED(event);
|
||||
return false;
|
||||
}
|
||||
|
||||
void ibutton_scene_view_data_on_exit(void* context) {
|
||||
iButton* ibutton = context;
|
||||
widget_reset(ibutton->widget);
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
#include "../ibutton_i.h"
|
||||
#include "toolbox/path.h"
|
||||
|
||||
typedef enum {
|
||||
iButtonSceneWriteStateDefault,
|
||||
|
@ -13,61 +12,46 @@ static void ibutton_scene_write_callback(void* context, iButtonWorkerWriteResult
|
|||
|
||||
void ibutton_scene_write_on_enter(void* context) {
|
||||
iButton* ibutton = context;
|
||||
furi_assert(ibutton->write_mode != iButtonWriteModeInvalid);
|
||||
|
||||
iButtonKey* key = ibutton->key;
|
||||
iButtonWorker* worker = ibutton->worker;
|
||||
const iButtonProtocolId protocol_id = ibutton_key_get_protocol_id(key);
|
||||
|
||||
Widget* widget = ibutton->widget;
|
||||
iButtonWorker* worker = ibutton->key_worker;
|
||||
FuriString* tmp = furi_string_alloc();
|
||||
|
||||
const uint8_t* key_data = ibutton_key_get_data_p(key);
|
||||
widget_add_icon_element(widget, 3, 10, &I_iButtonKey_49x44);
|
||||
|
||||
FuriString* key_name;
|
||||
key_name = furi_string_alloc();
|
||||
if(furi_string_end_with(ibutton->file_path, IBUTTON_APP_EXTENSION)) {
|
||||
path_extract_filename(ibutton->file_path, key_name, true);
|
||||
}
|
||||
furi_string_printf(
|
||||
tmp,
|
||||
"%s\n[%s]",
|
||||
ibutton->key_name,
|
||||
ibutton_protocols_get_name(ibutton->protocols, protocol_id));
|
||||
|
||||
// check that stored key has name
|
||||
if(!furi_string_empty(key_name)) {
|
||||
ibutton_text_store_set(ibutton, "%s", furi_string_get_cstr(key_name));
|
||||
} else {
|
||||
// if not, show key data
|
||||
switch(ibutton_key_get_type(key)) {
|
||||
case iButtonKeyDS1990:
|
||||
ibutton_text_store_set(
|
||||
ibutton,
|
||||
"%02X %02X %02X %02X\n%02X %02X %02X %02X",
|
||||
key_data[0],
|
||||
key_data[1],
|
||||
key_data[2],
|
||||
key_data[3],
|
||||
key_data[4],
|
||||
key_data[5],
|
||||
key_data[6],
|
||||
key_data[7]);
|
||||
break;
|
||||
case iButtonKeyCyfral:
|
||||
ibutton_text_store_set(ibutton, "%02X %02X", key_data[0], key_data[1]);
|
||||
break;
|
||||
case iButtonKeyMetakom:
|
||||
ibutton_text_store_set(
|
||||
ibutton, "%02X %02X %02X %02X", key_data[0], key_data[1], key_data[2], key_data[3]);
|
||||
break;
|
||||
}
|
||||
widget_add_text_box_element(
|
||||
widget, 52, 38, 75, 26, AlignCenter, AlignCenter, furi_string_get_cstr(tmp), true);
|
||||
|
||||
ibutton_worker_write_set_callback(worker, ibutton_scene_write_callback, ibutton);
|
||||
|
||||
furi_string_set(tmp, "iButton\nwriting ");
|
||||
|
||||
if(ibutton->write_mode == iButtonWriteModeBlank) {
|
||||
furi_string_cat(tmp, "Blank");
|
||||
ibutton_worker_write_blank_start(worker, key);
|
||||
|
||||
} else if(ibutton->write_mode == iButtonWriteModeCopy) {
|
||||
furi_string_cat(tmp, "Copy");
|
||||
ibutton_worker_write_copy_start(worker, key);
|
||||
}
|
||||
|
||||
widget_add_string_multiline_element(
|
||||
widget, 90, 10, AlignCenter, AlignTop, FontPrimary, "iButton\nwriting");
|
||||
widget_add_icon_element(widget, 3, 10, &I_iButtonKey_49x44);
|
||||
widget_add_text_box_element(
|
||||
widget, 54, 39, 75, 22, AlignCenter, AlignCenter, ibutton->text_store, true);
|
||||
|
||||
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewWidget);
|
||||
|
||||
ibutton_worker_write_set_callback(worker, ibutton_scene_write_callback, ibutton);
|
||||
ibutton_worker_write_start(worker, key);
|
||||
|
||||
furi_string_free(key_name);
|
||||
widget, 88, 10, AlignCenter, AlignTop, FontPrimary, furi_string_get_cstr(tmp));
|
||||
|
||||
ibutton_notification_message(ibutton, iButtonNotificationMessageEmulateStart);
|
||||
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewWidget);
|
||||
|
||||
furi_string_free(tmp);
|
||||
}
|
||||
|
||||
bool ibutton_scene_write_on_event(void* context, SceneManagerEvent event) {
|
||||
|
@ -94,7 +78,9 @@ bool ibutton_scene_write_on_event(void* context, SceneManagerEvent event) {
|
|||
|
||||
void ibutton_scene_write_on_exit(void* context) {
|
||||
iButton* ibutton = context;
|
||||
ibutton_worker_stop(ibutton->key_worker);
|
||||
ibutton->write_mode = iButtonWriteModeInvalid;
|
||||
|
||||
ibutton_worker_stop(ibutton->worker);
|
||||
widget_reset(ibutton->widget);
|
||||
|
||||
ibutton_notification_message(ibutton, iButtonNotificationMessageBlinkStop);
|
||||
|
|
|
@ -376,7 +376,17 @@ int32_t hid_ble_app(void* p) {
|
|||
// Wait 2nd core to update nvm storage
|
||||
furi_delay_ms(200);
|
||||
|
||||
bt_keys_storage_set_storage_path(app->bt, HID_BT_KEYS_STORAGE_PATH);
|
||||
// Migrate data from old sd-card folder
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
storage_common_migrate(
|
||||
storage,
|
||||
EXT_PATH("apps/Tools/" HID_BT_KEYS_STORAGE_NAME),
|
||||
APP_DATA_PATH(HID_BT_KEYS_STORAGE_NAME));
|
||||
|
||||
bt_keys_storage_set_storage_path(app->bt, APP_DATA_PATH(HID_BT_KEYS_STORAGE_NAME));
|
||||
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
if(!bt_set_profile(app->bt, BtProfileHidKeyboard)) {
|
||||
FURI_LOG_E(TAG, "Failed to switch to HID profile");
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include "views/hid_mouse_jiggler.h"
|
||||
#include "views/hid_tiktok.h"
|
||||
|
||||
#define HID_BT_KEYS_STORAGE_PATH EXT_PATH("apps/Tools/.bt_hid.keys")
|
||||
#define HID_BT_KEYS_STORAGE_NAME ".bt_hid.keys"
|
||||
|
||||
typedef enum {
|
||||
HidTransportUsb,
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
#define TAG "MusicPlayer"
|
||||
|
||||
#define MUSIC_PLAYER_APP_PATH_FOLDER ANY_PATH("music_player")
|
||||
#define MUSIC_PLAYER_APP_EXTENSION "*"
|
||||
|
||||
#define MUSIC_PLAYER_SEMITONE_HISTORY_SIZE 4
|
||||
|
@ -307,18 +306,24 @@ int32_t music_player_app(void* p) {
|
|||
if(p && strlen(p)) {
|
||||
furi_string_set(file_path, (const char*)p);
|
||||
} else {
|
||||
furi_string_set(file_path, MUSIC_PLAYER_APP_PATH_FOLDER);
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
storage_common_migrate(
|
||||
storage, EXT_PATH("music_player"), STORAGE_APP_DATA_PATH_PREFIX);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
furi_string_set(file_path, STORAGE_APP_DATA_PATH_PREFIX);
|
||||
|
||||
DialogsFileBrowserOptions browser_options;
|
||||
dialog_file_browser_set_basic_options(
|
||||
&browser_options, MUSIC_PLAYER_APP_EXTENSION, &I_music_10px);
|
||||
browser_options.hide_ext = false;
|
||||
browser_options.base_path = MUSIC_PLAYER_APP_PATH_FOLDER;
|
||||
browser_options.base_path = STORAGE_APP_DATA_PATH_PREFIX;
|
||||
|
||||
DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
|
||||
bool res = dialog_file_browser_show(dialogs, file_path, file_path, &browser_options);
|
||||
|
||||
furi_record_close(RECORD_DIALOGS);
|
||||
|
||||
if(!res) {
|
||||
FURI_LOG_E(TAG, "No file selected");
|
||||
break;
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
#include <lib/toolbox/args.h>
|
||||
#include <lib/flipper_format/flipper_format.h>
|
||||
|
||||
#define ICLASS_ELITE_DICT_FLIPPER_PATH EXT_PATH("picopass/assets/iclass_elite_dict.txt")
|
||||
#define ICLASS_ELITE_DICT_USER_PATH EXT_PATH("picopass/assets/iclass_elite_dict_user.txt")
|
||||
#define ICLASS_ELITE_DICT_FLIPPER_NAME APP_DATA_PATH("assets/iclass_elite_dict.txt")
|
||||
#define ICLASS_ELITE_DICT_USER_NAME APP_DATA_PATH("assets/iclass_elite_dict_user.txt")
|
||||
|
||||
#define TAG "IclassEliteDict"
|
||||
|
||||
|
@ -21,10 +21,10 @@ bool iclass_elite_dict_check_presence(IclassEliteDictType dict_type) {
|
|||
|
||||
bool dict_present = false;
|
||||
if(dict_type == IclassEliteDictTypeFlipper) {
|
||||
dict_present = storage_common_stat(storage, ICLASS_ELITE_DICT_FLIPPER_PATH, NULL) ==
|
||||
FSE_OK;
|
||||
dict_present =
|
||||
(storage_common_stat(storage, ICLASS_ELITE_DICT_FLIPPER_NAME, NULL) == FSE_OK);
|
||||
} else if(dict_type == IclassEliteDictTypeUser) {
|
||||
dict_present = storage_common_stat(storage, ICLASS_ELITE_DICT_USER_PATH, NULL) == FSE_OK;
|
||||
dict_present = (storage_common_stat(storage, ICLASS_ELITE_DICT_USER_NAME, NULL) == FSE_OK);
|
||||
}
|
||||
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
@ -36,27 +36,26 @@ IclassEliteDict* iclass_elite_dict_alloc(IclassEliteDictType dict_type) {
|
|||
IclassEliteDict* dict = malloc(sizeof(IclassEliteDict));
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
dict->stream = buffered_file_stream_alloc(storage);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
FuriString* next_line = furi_string_alloc();
|
||||
|
||||
bool dict_loaded = false;
|
||||
do {
|
||||
if(dict_type == IclassEliteDictTypeFlipper) {
|
||||
if(!buffered_file_stream_open(
|
||||
dict->stream, ICLASS_ELITE_DICT_FLIPPER_PATH, FSAM_READ, FSOM_OPEN_EXISTING)) {
|
||||
dict->stream, ICLASS_ELITE_DICT_FLIPPER_NAME, FSAM_READ, FSOM_OPEN_EXISTING)) {
|
||||
buffered_file_stream_close(dict->stream);
|
||||
break;
|
||||
}
|
||||
} else if(dict_type == IclassEliteDictTypeUser) {
|
||||
if(!buffered_file_stream_open(
|
||||
dict->stream, ICLASS_ELITE_DICT_USER_PATH, FSAM_READ_WRITE, FSOM_OPEN_ALWAYS)) {
|
||||
dict->stream, ICLASS_ELITE_DICT_USER_NAME, FSAM_READ_WRITE, FSOM_OPEN_ALWAYS)) {
|
||||
buffered_file_stream_close(dict->stream);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Read total amount of keys
|
||||
while(true) {
|
||||
while(true) { //-V547
|
||||
if(!stream_read_line(dict->stream, next_line)) break;
|
||||
if(furi_string_get_char(next_line, 0) == '#') continue;
|
||||
if(furi_string_size(next_line) != ICLASS_ELITE_KEY_LINE_LEN) continue;
|
||||
|
@ -69,12 +68,13 @@ IclassEliteDict* iclass_elite_dict_alloc(IclassEliteDictType dict_type) {
|
|||
FURI_LOG_I(TAG, "Loaded dictionary with %lu keys", dict->total_keys);
|
||||
} while(false);
|
||||
|
||||
if(!dict_loaded) {
|
||||
if(!dict_loaded) { //-V547
|
||||
buffered_file_stream_close(dict->stream);
|
||||
free(dict);
|
||||
dict = NULL;
|
||||
}
|
||||
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
furi_string_free(next_line);
|
||||
|
||||
return dict;
|
||||
|
|
|
@ -171,6 +171,12 @@ void picopass_show_loading_popup(void* context, bool show) {
|
|||
}
|
||||
}
|
||||
|
||||
static void picopass_migrate_from_old_folder() {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
storage_common_migrate(storage, "/ext/picopass", STORAGE_APP_DATA_PATH_PREFIX);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
bool picopass_is_memset(const uint8_t* data, const uint8_t pattern, size_t size) {
|
||||
bool result = size > 0;
|
||||
while(size > 0) {
|
||||
|
@ -183,6 +189,8 @@ bool picopass_is_memset(const uint8_t* data, const uint8_t pattern, size_t size)
|
|||
|
||||
int32_t picopass_app(void* p) {
|
||||
UNUSED(p);
|
||||
picopass_migrate_from_old_folder();
|
||||
|
||||
Picopass* picopass = picopass_alloc();
|
||||
|
||||
scene_manager_next_scene(picopass->scene_manager, PicopassSceneStart);
|
||||
|
|
|
@ -48,13 +48,9 @@ static bool picopass_device_save_file(
|
|||
if(use_load_path && !furi_string_empty(dev->load_path)) {
|
||||
// Get directory name
|
||||
path_extract_dirname(furi_string_get_cstr(dev->load_path), temp_str);
|
||||
// Create picopass directory if necessary
|
||||
if(!storage_simply_mkdir(dev->storage, furi_string_get_cstr(temp_str))) break;
|
||||
// Make path to file to save
|
||||
furi_string_cat_printf(temp_str, "/%s%s", dev_name, extension);
|
||||
} else {
|
||||
// Create picopass directory if necessary
|
||||
if(!storage_simply_mkdir(dev->storage, PICOPASS_APP_FOLDER)) break;
|
||||
// First remove picopass device file if it was saved
|
||||
furi_string_printf(temp_str, "%s/%s%s", folder, dev_name, extension);
|
||||
}
|
||||
|
@ -126,10 +122,11 @@ static bool picopass_device_save_file(
|
|||
bool picopass_device_save(PicopassDevice* dev, const char* dev_name) {
|
||||
if(dev->format == PicopassDeviceSaveFormatHF) {
|
||||
return picopass_device_save_file(
|
||||
dev, dev_name, PICOPASS_APP_FOLDER, PICOPASS_APP_EXTENSION, true);
|
||||
dev, dev_name, STORAGE_APP_DATA_PATH_PREFIX, PICOPASS_APP_EXTENSION, true);
|
||||
} else if(dev->format == PicopassDeviceSaveFormatLF) {
|
||||
return picopass_device_save_file(dev, dev_name, ANY_PATH("lfrfid"), ".rfid", true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -225,13 +222,12 @@ void picopass_device_free(PicopassDevice* picopass_dev) {
|
|||
bool picopass_file_select(PicopassDevice* dev) {
|
||||
furi_assert(dev);
|
||||
|
||||
// Input events and views are managed by file_browser
|
||||
FuriString* picopass_app_folder;
|
||||
picopass_app_folder = furi_string_alloc_set(PICOPASS_APP_FOLDER);
|
||||
picopass_app_folder = furi_string_alloc_set(STORAGE_APP_DATA_PATH_PREFIX);
|
||||
|
||||
DialogsFileBrowserOptions browser_options;
|
||||
dialog_file_browser_set_basic_options(&browser_options, PICOPASS_APP_EXTENSION, &I_Nfc_10px);
|
||||
browser_options.base_path = PICOPASS_APP_FOLDER;
|
||||
browser_options.base_path = STORAGE_APP_DATA_PATH_PREFIX;
|
||||
|
||||
bool res = dialog_file_browser_show(
|
||||
dev->dialogs, dev->load_path, picopass_app_folder, &browser_options);
|
||||
|
@ -274,7 +270,7 @@ bool picopass_device_delete(PicopassDevice* dev, bool use_load_path) {
|
|||
furi_string_set(file_path, dev->load_path);
|
||||
} else {
|
||||
furi_string_printf(
|
||||
file_path, "%s/%s%s", PICOPASS_APP_FOLDER, dev->dev_name, PICOPASS_APP_EXTENSION);
|
||||
file_path, APP_DATA_PATH("%s%s"), dev->dev_name, PICOPASS_APP_EXTENSION);
|
||||
}
|
||||
if(!storage_simply_remove(dev->storage, furi_string_get_cstr(file_path))) break;
|
||||
deleted = true;
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#define PICOPASS_AIA_BLOCK_INDEX 5
|
||||
#define PICOPASS_PACS_CFG_BLOCK_INDEX 6
|
||||
|
||||
#define PICOPASS_APP_FOLDER ANY_PATH("picopass")
|
||||
#define PICOPASS_APP_EXTENSION ".picopass"
|
||||
#define PICOPASS_APP_SHADOW_EXTENSION ".pas"
|
||||
|
||||
|
@ -81,7 +80,6 @@ typedef struct {
|
|||
PicopassDeviceSaveFormat format;
|
||||
PicopassLoadingCallback loading_cb;
|
||||
void* loading_cb_ctx;
|
||||
|
||||
} PicopassDevice;
|
||||
|
||||
PicopassDevice* picopass_device_alloc();
|
||||
|
|
|
@ -31,12 +31,10 @@ void picopass_scene_save_name_on_enter(void* context) {
|
|||
dev_name_empty);
|
||||
|
||||
FuriString* folder_path;
|
||||
folder_path = furi_string_alloc();
|
||||
folder_path = furi_string_alloc_set(STORAGE_APP_DATA_PATH_PREFIX);
|
||||
|
||||
if(furi_string_end_with(picopass->dev->load_path, PICOPASS_APP_EXTENSION)) {
|
||||
path_extract_dirname(furi_string_get_cstr(picopass->dev->load_path), folder_path);
|
||||
} else {
|
||||
furi_string_set(folder_path, PICOPASS_APP_FOLDER);
|
||||
}
|
||||
|
||||
ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
|
||||
|
|
|
@ -60,7 +60,7 @@ bool spi_mem_scene_start_on_event(void* context, SceneManagerEvent event) {
|
|||
scene_manager_next_scene(app->scene_manager, SPIMemSceneChipDetect);
|
||||
success = true;
|
||||
} else if(event.event == SPIMemSceneStartSubmenuIndexSaved) {
|
||||
furi_string_set(app->file_path, SPI_MEM_FILE_FOLDER);
|
||||
furi_string_set(app->file_path, STORAGE_APP_DATA_PATH_PREFIX);
|
||||
scene_manager_next_scene(app->scene_manager, SPIMemSceneSelectFile);
|
||||
success = true;
|
||||
} else if(event.event == SPIMemSceneStartSubmenuIndexErase) {
|
||||
|
|
|
@ -16,9 +16,9 @@ static bool spi_mem_back_event_callback(void* context) {
|
|||
}
|
||||
|
||||
SPIMemApp* spi_mem_alloc(void) {
|
||||
SPIMemApp* instance = malloc(sizeof(SPIMemApp));
|
||||
SPIMemApp* instance = malloc(sizeof(SPIMemApp)); //-V799
|
||||
|
||||
instance->file_path = furi_string_alloc();
|
||||
instance->file_path = furi_string_alloc_set(STORAGE_APP_DATA_PATH_PREFIX);
|
||||
instance->gui = furi_record_open(RECORD_GUI);
|
||||
instance->notifications = furi_record_open(RECORD_NOTIFICATION);
|
||||
instance->view_dispatcher = view_dispatcher_alloc();
|
||||
|
@ -37,7 +37,8 @@ SPIMemApp* spi_mem_alloc(void) {
|
|||
instance->text_input = text_input_alloc();
|
||||
instance->mode = SPIMemModeUnknown;
|
||||
|
||||
furi_string_set(instance->file_path, SPI_MEM_FILE_FOLDER);
|
||||
// Migrate data from old sd-card folder
|
||||
storage_common_migrate(instance->storage, EXT_PATH("spimem"), STORAGE_APP_DATA_PATH_PREFIX);
|
||||
|
||||
view_dispatcher_enable_queue(instance->view_dispatcher);
|
||||
view_dispatcher_set_event_callback_context(instance->view_dispatcher, instance);
|
||||
|
@ -70,7 +71,7 @@ SPIMemApp* spi_mem_alloc(void) {
|
|||
furi_hal_spi_bus_handle_init(&furi_hal_spi_bus_handle_external);
|
||||
scene_manager_next_scene(instance->scene_manager, SPIMemSceneStart);
|
||||
return instance;
|
||||
}
|
||||
} //-V773
|
||||
|
||||
void spi_mem_free(SPIMemApp* instance) {
|
||||
view_dispatcher_remove_view(instance->view_dispatcher, SPIMemViewSubmenu);
|
||||
|
@ -105,7 +106,6 @@ void spi_mem_free(SPIMemApp* instance) {
|
|||
int32_t spi_mem_app(void* p) {
|
||||
UNUSED(p);
|
||||
SPIMemApp* instance = spi_mem_alloc();
|
||||
spi_mem_file_create_folder(instance);
|
||||
view_dispatcher_run(instance->view_dispatcher);
|
||||
spi_mem_free(instance);
|
||||
return 0;
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
|
||||
#define TAG "SPIMem"
|
||||
#define SPI_MEM_FILE_EXTENSION ".bin"
|
||||
#define SPI_MEM_FILE_FOLDER EXT_PATH("spimem")
|
||||
#define SPI_MEM_FILE_NAME_SIZE 100
|
||||
#define SPI_MEM_TEXT_BUFFER_SIZE 128
|
||||
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
#include "spi_mem_app_i.h"
|
||||
|
||||
void spi_mem_file_create_folder(SPIMemApp* app) {
|
||||
if(!storage_simply_mkdir(app->storage, SPI_MEM_FILE_FOLDER)) {
|
||||
dialog_message_show_storage_error(app->dialogs, "Cannot create\napp folder");
|
||||
}
|
||||
}
|
||||
|
||||
bool spi_mem_file_delete(SPIMemApp* app) {
|
||||
return (storage_simply_remove(app->storage, furi_string_get_cstr(app->file_path)));
|
||||
}
|
||||
|
@ -13,7 +7,7 @@ bool spi_mem_file_delete(SPIMemApp* app) {
|
|||
bool spi_mem_file_select(SPIMemApp* app) {
|
||||
DialogsFileBrowserOptions browser_options;
|
||||
dialog_file_browser_set_basic_options(&browser_options, SPI_MEM_FILE_EXTENSION, &I_Dip8_10px);
|
||||
browser_options.base_path = SPI_MEM_FILE_FOLDER;
|
||||
browser_options.base_path = STORAGE_APP_DATA_PATH_PREFIX;
|
||||
bool success =
|
||||
dialog_file_browser_show(app->dialogs, app->file_path, app->file_path, &browser_options);
|
||||
return success;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
#include "spi_mem_app.h"
|
||||
|
||||
void spi_mem_file_create_folder(SPIMemApp* app);
|
||||
bool spi_mem_file_select(SPIMemApp* app);
|
||||
bool spi_mem_file_create(SPIMemApp* app, const char* file_name);
|
||||
bool spi_mem_file_delete(SPIMemApp* app);
|
||||
|
|
|
@ -11,6 +11,7 @@ typedef enum {
|
|||
typedef struct {
|
||||
const FuriThreadCallback app;
|
||||
const char* name;
|
||||
const char* appid;
|
||||
const size_t stack_size;
|
||||
const Icon* icon;
|
||||
const FlipperApplicationFlag flags;
|
||||
|
|
|
@ -45,7 +45,14 @@ void bt_keys_storage_set_storage_path(Bt* bt, const char* keys_storage_path) {
|
|||
furi_assert(bt->keys_storage);
|
||||
furi_assert(keys_storage_path);
|
||||
|
||||
bt_keys_storage_set_file_path(bt->keys_storage, keys_storage_path);
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FuriString* path = furi_string_alloc_set(keys_storage_path);
|
||||
storage_common_resolve_path_and_ensure_app_directory(storage, path);
|
||||
|
||||
bt_keys_storage_set_file_path(bt->keys_storage, furi_string_get_cstr(path));
|
||||
|
||||
furi_string_free(path);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
void bt_keys_storage_set_default_path(Bt* bt) {
|
||||
|
|
|
@ -382,11 +382,18 @@ void cli_command_ps(Cli* cli, FuriString* args, void* context) {
|
|||
FuriThreadId threads_ids[threads_num_max];
|
||||
uint8_t thread_num = furi_thread_enumerate(threads_ids, threads_num_max);
|
||||
printf(
|
||||
"%-20s %-14s %-8s %-8s %s\r\n", "Name", "Stack start", "Heap", "Stack", "Stack min free");
|
||||
"%-20s %-20s %-14s %-8s %-8s %s\r\n",
|
||||
"AppID",
|
||||
"Name",
|
||||
"Stack start",
|
||||
"Heap",
|
||||
"Stack",
|
||||
"Stack min free");
|
||||
for(uint8_t i = 0; i < thread_num; i++) {
|
||||
TaskControlBlock* tcb = (TaskControlBlock*)threads_ids[i];
|
||||
printf(
|
||||
"%-20s 0x%-12lx %-8zu %-8lu %-8lu\r\n",
|
||||
"%-20s %-20s 0x%-12lx %-8zu %-8lu %-8lu\r\n",
|
||||
furi_thread_get_appid(threads_ids[i]),
|
||||
furi_thread_get_name(threads_ids[i]),
|
||||
(uint32_t)tcb->pxStack,
|
||||
memmgr_heap_get_thread_memory(threads_ids[i]),
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "dialogs_i.h"
|
||||
#include <toolbox/api_lock.h>
|
||||
#include <assets_icons.h>
|
||||
#include <storage/storage.h>
|
||||
|
||||
/****************** File browser ******************/
|
||||
|
||||
|
@ -13,6 +14,22 @@ bool dialog_file_browser_show(
|
|||
FuriApiLock lock = api_lock_alloc_locked();
|
||||
furi_check(lock != NULL);
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FuriString* base_path = furi_string_alloc();
|
||||
|
||||
if(options && options->base_path) {
|
||||
furi_string_set(base_path, options->base_path);
|
||||
storage_common_resolve_path_and_ensure_app_directory(storage, base_path);
|
||||
}
|
||||
|
||||
if(result_path) {
|
||||
storage_common_resolve_path_and_ensure_app_directory(storage, result_path);
|
||||
}
|
||||
|
||||
if(path) {
|
||||
storage_common_resolve_path_and_ensure_app_directory(storage, path);
|
||||
}
|
||||
|
||||
DialogsAppData data = {
|
||||
.file_browser = {
|
||||
.extension = options ? options->extension : "",
|
||||
|
@ -24,7 +41,7 @@ bool dialog_file_browser_show(
|
|||
.preselected_filename = path,
|
||||
.item_callback = options ? options->item_loader_callback : NULL,
|
||||
.item_callback_context = options ? options->item_loader_context : NULL,
|
||||
.base_path = options ? options->base_path : NULL,
|
||||
.base_path = furi_string_get_cstr(base_path),
|
||||
}};
|
||||
|
||||
DialogsAppReturn return_data;
|
||||
|
@ -39,6 +56,9 @@ bool dialog_file_browser_show(
|
|||
furi_message_queue_put(context->message_queue, &message, FuriWaitForever) == FuriStatusOk);
|
||||
api_lock_wait_unlock_and_free(lock);
|
||||
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
furi_string_free(base_path);
|
||||
|
||||
return return_data.bool_value;
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ static bool browser_path_is_file(FuriString* path) {
|
|||
FileInfo file_info;
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
if(storage_common_stat(storage, furi_string_get_cstr(path), &file_info) == FSE_OK) {
|
||||
if((file_info.flags & FSF_DIRECTORY) == 0) {
|
||||
if(!file_info_is_dir(&file_info)) {
|
||||
state = true;
|
||||
}
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ static bool browser_folder_check_and_switch(FuriString* path) {
|
|||
while(1) {
|
||||
// Check if folder is existing and navigate back if not
|
||||
if(storage_common_stat(storage, furi_string_get_cstr(path), &file_info) == FSE_OK) {
|
||||
if(file_info.flags & FSF_DIRECTORY) {
|
||||
if(file_info_is_dir(&file_info)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ static bool browser_folder_init(
|
|||
if((storage_file_get_error(directory) == FSE_OK) && (name_temp[0] != '\0')) {
|
||||
total_files_cnt++;
|
||||
furi_string_set(name_str, name_temp);
|
||||
if(browser_filter_by_name(browser, name_str, (file_info.flags & FSF_DIRECTORY))) {
|
||||
if(browser_filter_by_name(browser, name_str, file_info_is_dir(&file_info))) {
|
||||
if(!furi_string_empty(filename)) {
|
||||
if(furi_string_cmp(name_str, filename) == 0) {
|
||||
*file_idx = *item_cnt;
|
||||
|
@ -218,7 +218,7 @@ static bool browser_folder_load_chunked(
|
|||
}
|
||||
if(storage_file_get_error(directory) == FSE_OK) {
|
||||
furi_string_set(name_str, name_temp);
|
||||
if(browser_filter_by_name(browser, name_str, (file_info.flags & FSF_DIRECTORY))) {
|
||||
if(browser_filter_by_name(browser, name_str, file_info_is_dir(&file_info))) {
|
||||
items_cnt++;
|
||||
}
|
||||
} else {
|
||||
|
@ -240,14 +240,14 @@ static bool browser_folder_load_chunked(
|
|||
}
|
||||
if(storage_file_get_error(directory) == FSE_OK) {
|
||||
furi_string_set(name_str, name_temp);
|
||||
if(browser_filter_by_name(browser, name_str, (file_info.flags & FSF_DIRECTORY))) {
|
||||
if(browser_filter_by_name(browser, name_str, file_info_is_dir(&file_info))) {
|
||||
furi_string_printf(name_str, "%s/%s", furi_string_get_cstr(path), name_temp);
|
||||
if(browser->list_item_cb) {
|
||||
browser->list_item_cb(
|
||||
browser->cb_ctx,
|
||||
name_str,
|
||||
items_cnt,
|
||||
(file_info.flags & FSF_DIRECTORY),
|
||||
file_info_is_dir(&file_info),
|
||||
false);
|
||||
}
|
||||
items_cnt++;
|
||||
|
|
|
@ -115,6 +115,7 @@ void widget_add_text_box_element(
|
|||
* @param[in] text Formatted text. Default format: align left, Secondary font.
|
||||
* The following formats are available:
|
||||
* "\e#Bold text" - sets bold font before until next '\n' symbol
|
||||
* "\e*Monospaced text\e*" - sets monospaced font before until next '\n' symbol
|
||||
* "\ecCenter-aligned text" - sets center horizontal align until the next '\n' symbol
|
||||
* "\erRight-aligned text" - sets right horizontal align until the next '\n' symbol
|
||||
*/
|
||||
|
|
|
@ -37,6 +37,8 @@ static bool
|
|||
line->horizontal = AlignRight;
|
||||
} else if(ctrl_symbol == '#') {
|
||||
line->font = FontPrimary;
|
||||
} else if(ctrl_symbol == '*') {
|
||||
line->font = FontKeyboard;
|
||||
}
|
||||
furi_string_right(text, 2);
|
||||
processed = true;
|
||||
|
|
|
@ -29,6 +29,8 @@ static bool
|
|||
}
|
||||
|
||||
furi_thread_set_name(loader_instance->application_thread, loader_instance->application->name);
|
||||
furi_thread_set_appid(
|
||||
loader_instance->application_thread, loader_instance->application->appid);
|
||||
furi_thread_set_stack_size(
|
||||
loader_instance->application_thread, loader_instance->application->stack_size);
|
||||
furi_thread_set_context(
|
||||
|
|
|
@ -201,7 +201,7 @@ static void rpc_system_storage_stat_process(const PB_Main* request, void* contex
|
|||
if(error == FSE_OK) {
|
||||
response->which_content = PB_Main_storage_stat_response_tag;
|
||||
response->content.storage_stat_response.has_file = true;
|
||||
response->content.storage_stat_response.file.type = (fileinfo.flags & FSF_DIRECTORY) ?
|
||||
response->content.storage_stat_response.file.type = file_info_is_dir(&fileinfo) ?
|
||||
PB_Storage_File_FileType_DIR :
|
||||
PB_Storage_File_FileType_FILE;
|
||||
response->content.storage_stat_response.file.size = fileinfo.size;
|
||||
|
@ -291,9 +291,8 @@ static void rpc_system_storage_list_process(const PB_Main* request, void* contex
|
|||
rpc_send_and_release(session, &response);
|
||||
i = 0;
|
||||
}
|
||||
list->file[i].type = (fileinfo.flags & FSF_DIRECTORY) ?
|
||||
PB_Storage_File_FileType_DIR :
|
||||
PB_Storage_File_FileType_FILE;
|
||||
list->file[i].type = file_info_is_dir(&fileinfo) ? PB_Storage_File_FileType_DIR :
|
||||
PB_Storage_File_FileType_FILE;
|
||||
list->file[i].size = fileinfo.size;
|
||||
list->file[i].data = NULL;
|
||||
list->file[i].name = name;
|
||||
|
@ -458,7 +457,7 @@ static bool rpc_system_storage_is_dir_is_empty(Storage* fs_api, const char* path
|
|||
FileInfo fileinfo;
|
||||
bool is_dir_is_empty = true;
|
||||
FS_Error error = storage_common_stat(fs_api, path, &fileinfo);
|
||||
if((error == FSE_OK) && (fileinfo.flags & FSF_DIRECTORY)) {
|
||||
if((error == FSE_OK) && file_info_is_dir(&fileinfo)) {
|
||||
File* dir = storage_file_alloc(fs_api);
|
||||
if(storage_dir_open(dir, path)) {
|
||||
char* name = malloc(MAX_NAME_LENGTH);
|
||||
|
|
|
@ -36,3 +36,7 @@ const char* filesystem_api_error_get_desc(FS_Error error_id) {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool file_info_is_dir(const FileInfo* file_info) {
|
||||
return (file_info->flags & FSF_DIRECTORY);
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -40,10 +41,10 @@ typedef enum {
|
|||
FSF_DIRECTORY = (1 << 0), /**< Directory */
|
||||
} FS_Flags;
|
||||
|
||||
/** Structure that hold file index and returned api errors */
|
||||
/** Structure that hold file index and returned api errors */
|
||||
typedef struct File File;
|
||||
|
||||
/** Structure that hold file info */
|
||||
/** Structure that hold file info */
|
||||
typedef struct {
|
||||
uint8_t flags; /**< flags from FS_Flags enum */
|
||||
uint64_t size; /**< file size */
|
||||
|
@ -55,6 +56,12 @@ typedef struct {
|
|||
*/
|
||||
const char* filesystem_api_error_get_desc(FS_Error error_id);
|
||||
|
||||
/** Checks if file info is directory
|
||||
* @param file_info file info pointer
|
||||
* @return bool is directory
|
||||
*/
|
||||
bool file_info_is_dir(const FileInfo* file_info);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -10,10 +10,12 @@ extern "C" {
|
|||
#define STORAGE_INT_PATH_PREFIX "/int"
|
||||
#define STORAGE_EXT_PATH_PREFIX "/ext"
|
||||
#define STORAGE_ANY_PATH_PREFIX "/any"
|
||||
#define STORAGE_APP_DATA_PATH_PREFIX "/app"
|
||||
|
||||
#define INT_PATH(path) STORAGE_INT_PATH_PREFIX "/" path
|
||||
#define EXT_PATH(path) STORAGE_EXT_PATH_PREFIX "/" path
|
||||
#define ANY_PATH(path) STORAGE_ANY_PATH_PREFIX "/" path
|
||||
#define APP_DATA_PATH(path) STORAGE_APP_DATA_PATH_PREFIX "/" path
|
||||
|
||||
#define RECORD_STORAGE "storage"
|
||||
|
||||
|
@ -175,6 +177,15 @@ bool storage_dir_read(File* file, FileInfo* fileinfo, char* name, uint16_t name_
|
|||
*/
|
||||
bool storage_dir_rewind(File* file);
|
||||
|
||||
/**
|
||||
* @brief Check that dir exists
|
||||
*
|
||||
* @param storage
|
||||
* @param path
|
||||
* @return bool
|
||||
*/
|
||||
bool storage_dir_exists(Storage* storage, const char* path);
|
||||
|
||||
/******************* Common Functions *******************/
|
||||
|
||||
/** Retrieves unix timestamp of last access
|
||||
|
@ -246,6 +257,36 @@ FS_Error storage_common_fs_info(
|
|||
uint64_t* total_space,
|
||||
uint64_t* free_space);
|
||||
|
||||
/**
|
||||
* @brief Parse aliases in path and replace them with real path
|
||||
* Also will create special folders if they are not exist
|
||||
*
|
||||
* @param storage
|
||||
* @param path
|
||||
* @return bool
|
||||
*/
|
||||
void storage_common_resolve_path_and_ensure_app_directory(Storage* storage, FuriString* path);
|
||||
|
||||
/**
|
||||
* @brief Move content of one folder to another, with rename of all conflicting files.
|
||||
* Source folder will be deleted if the migration is successful.
|
||||
*
|
||||
* @param storage
|
||||
* @param source
|
||||
* @param dest
|
||||
* @return FS_Error
|
||||
*/
|
||||
FS_Error storage_common_migrate(Storage* storage, const char* source, const char* dest);
|
||||
|
||||
/**
|
||||
* @brief Check that file or dir exists
|
||||
*
|
||||
* @param storage
|
||||
* @param path
|
||||
* @return bool
|
||||
*/
|
||||
bool storage_common_exists(Storage* storage, const char* path);
|
||||
|
||||
/******************* Error Functions *******************/
|
||||
|
||||
/** Retrieves the error text from the error id
|
||||
|
|
|
@ -131,7 +131,7 @@ static void storage_cli_list(Cli* cli, FuriString* path) {
|
|||
|
||||
while(storage_dir_read(file, &fileinfo, name, MAX_NAME_LENGTH)) {
|
||||
read_done = true;
|
||||
if(fileinfo.flags & FSF_DIRECTORY) {
|
||||
if(file_info_is_dir(&fileinfo)) {
|
||||
printf("\t[D] %s\r\n", name);
|
||||
} else {
|
||||
printf("\t[F] %s %lub\r\n", name, (uint32_t)(fileinfo.size));
|
||||
|
@ -169,7 +169,7 @@ static void storage_cli_tree(Cli* cli, FuriString* path) {
|
|||
|
||||
while(dir_walk_read(dir_walk, name, &fileinfo) == DirWalkOK) {
|
||||
read_done = true;
|
||||
if(fileinfo.flags & FSF_DIRECTORY) {
|
||||
if(file_info_is_dir(&fileinfo)) {
|
||||
printf("\t[D] %s\r\n", furi_string_get_cstr(name));
|
||||
} else {
|
||||
printf(
|
||||
|
@ -383,7 +383,7 @@ static void storage_cli_stat(Cli* cli, FuriString* path) {
|
|||
FS_Error error = storage_common_stat(api, furi_string_get_cstr(path), &fileinfo);
|
||||
|
||||
if(error == FSE_OK) {
|
||||
if(fileinfo.flags & FSF_DIRECTORY) {
|
||||
if(file_info_is_dir(&fileinfo)) {
|
||||
printf("Directory\r\n");
|
||||
} else {
|
||||
printf("File, size: %lub\r\n", (uint32_t)(fileinfo.size));
|
||||
|
|
|
@ -39,12 +39,6 @@
|
|||
.file = file, \
|
||||
}};
|
||||
|
||||
#define S_API_DATA_PATH \
|
||||
SAData data = { \
|
||||
.path = { \
|
||||
.path = path, \
|
||||
}};
|
||||
|
||||
#define S_RETURN_BOOL (return_data.bool_value);
|
||||
#define S_RETURN_UINT16 (return_data.uint16_value);
|
||||
#define S_RETURN_UINT64 (return_data.uint64_value);
|
||||
|
@ -70,6 +64,7 @@ static bool storage_file_open_internal(
|
|||
.path = path,
|
||||
.access_mode = access_mode,
|
||||
.open_mode = open_mode,
|
||||
.thread_id = furi_thread_get_current_id(),
|
||||
}};
|
||||
|
||||
file->type = FileTypeOpenFile;
|
||||
|
@ -249,7 +244,7 @@ bool storage_file_exists(Storage* storage, const char* path) {
|
|||
FileInfo fileinfo;
|
||||
FS_Error error = storage_common_stat(storage, path, &fileinfo);
|
||||
|
||||
if(error == FSE_OK && !(fileinfo.flags & FSF_DIRECTORY)) {
|
||||
if(error == FSE_OK && !file_info_is_dir(&fileinfo)) {
|
||||
exist = true;
|
||||
}
|
||||
|
||||
|
@ -266,6 +261,7 @@ static bool storage_dir_open_internal(File* file, const char* path) {
|
|||
.dopen = {
|
||||
.file = file,
|
||||
.path = path,
|
||||
.thread_id = furi_thread_get_current_id(),
|
||||
}};
|
||||
|
||||
file->type = FileTypeOpenDir;
|
||||
|
@ -349,12 +345,28 @@ bool storage_dir_rewind(File* file) {
|
|||
return S_RETURN_BOOL;
|
||||
}
|
||||
|
||||
bool storage_dir_exists(Storage* storage, const char* path) {
|
||||
bool exist = false;
|
||||
FileInfo fileinfo;
|
||||
FS_Error error = storage_common_stat(storage, path, &fileinfo);
|
||||
|
||||
if(error == FSE_OK && file_info_is_dir(&fileinfo)) {
|
||||
exist = true;
|
||||
}
|
||||
|
||||
return exist;
|
||||
}
|
||||
/****************** COMMON ******************/
|
||||
|
||||
FS_Error storage_common_timestamp(Storage* storage, const char* path, uint32_t* timestamp) {
|
||||
S_API_PROLOGUE;
|
||||
|
||||
SAData data = {.ctimestamp = {.path = path, .timestamp = timestamp}};
|
||||
SAData data = {
|
||||
.ctimestamp = {
|
||||
.path = path,
|
||||
.timestamp = timestamp,
|
||||
.thread_id = furi_thread_get_current_id(),
|
||||
}};
|
||||
|
||||
S_API_MESSAGE(StorageCommandCommonTimestamp);
|
||||
S_API_EPILOGUE;
|
||||
|
@ -363,8 +375,12 @@ FS_Error storage_common_timestamp(Storage* storage, const char* path, uint32_t*
|
|||
|
||||
FS_Error storage_common_stat(Storage* storage, const char* path, FileInfo* fileinfo) {
|
||||
S_API_PROLOGUE;
|
||||
|
||||
SAData data = {.cstat = {.path = path, .fileinfo = fileinfo}};
|
||||
SAData data = {
|
||||
.cstat = {
|
||||
.path = path,
|
||||
.fileinfo = fileinfo,
|
||||
.thread_id = furi_thread_get_current_id(),
|
||||
}};
|
||||
|
||||
S_API_MESSAGE(StorageCommandCommonStat);
|
||||
S_API_EPILOGUE;
|
||||
|
@ -373,7 +389,12 @@ FS_Error storage_common_stat(Storage* storage, const char* path, FileInfo* filei
|
|||
|
||||
FS_Error storage_common_remove(Storage* storage, const char* path) {
|
||||
S_API_PROLOGUE;
|
||||
S_API_DATA_PATH;
|
||||
SAData data = {
|
||||
.path = {
|
||||
.path = path,
|
||||
.thread_id = furi_thread_get_current_id(),
|
||||
}};
|
||||
|
||||
S_API_MESSAGE(StorageCommandCommonRemove);
|
||||
S_API_EPILOGUE;
|
||||
return S_RETURN_ERROR;
|
||||
|
@ -423,7 +444,7 @@ static FS_Error
|
|||
furi_string_right(path, strlen(old_path));
|
||||
furi_string_printf(tmp_new_path, "%s%s", new_path, furi_string_get_cstr(path));
|
||||
|
||||
if(fileinfo.flags & FSF_DIRECTORY) {
|
||||
if(file_info_is_dir(&fileinfo)) {
|
||||
error = storage_common_mkdir(storage, furi_string_get_cstr(tmp_new_path));
|
||||
} else {
|
||||
error = storage_common_copy(
|
||||
|
@ -452,7 +473,7 @@ FS_Error storage_common_copy(Storage* storage, const char* old_path, const char*
|
|||
error = storage_common_stat(storage, old_path, &fileinfo);
|
||||
|
||||
if(error == FSE_OK) {
|
||||
if(fileinfo.flags & FSF_DIRECTORY) {
|
||||
if(file_info_is_dir(&fileinfo)) {
|
||||
error = storage_copy_recursive(storage, old_path, new_path);
|
||||
} else {
|
||||
Stream* stream_from = file_stream_alloc(storage);
|
||||
|
@ -479,7 +500,7 @@ FS_Error storage_common_copy(Storage* storage, const char* old_path, const char*
|
|||
|
||||
static FS_Error
|
||||
storage_merge_recursive(Storage* storage, const char* old_path, const char* new_path) {
|
||||
FS_Error error = storage_common_mkdir(storage, new_path);
|
||||
FS_Error error = FSE_OK;
|
||||
DirWalk* dir_walk = dir_walk_alloc(storage);
|
||||
FuriString *path, *file_basename, *tmp_new_path;
|
||||
FileInfo fileinfo;
|
||||
|
@ -488,7 +509,7 @@ static FS_Error
|
|||
tmp_new_path = furi_string_alloc();
|
||||
|
||||
do {
|
||||
if((error != FSE_OK) && (error != FSE_EXIST)) break;
|
||||
if(!storage_simply_mkdir(storage, new_path)) break;
|
||||
|
||||
dir_walk_set_recursive(dir_walk, false);
|
||||
if(!dir_walk_open(dir_walk, old_path)) {
|
||||
|
@ -508,13 +529,13 @@ static FS_Error
|
|||
path_extract_basename(furi_string_get_cstr(path), file_basename);
|
||||
path_concat(new_path, furi_string_get_cstr(file_basename), tmp_new_path);
|
||||
|
||||
if(fileinfo.flags & FSF_DIRECTORY) {
|
||||
if(file_info_is_dir(&fileinfo)) {
|
||||
if(storage_common_stat(
|
||||
storage, furi_string_get_cstr(tmp_new_path), &fileinfo) == FSE_OK) {
|
||||
if(fileinfo.flags & FSF_DIRECTORY) {
|
||||
if(file_info_is_dir(&fileinfo)) {
|
||||
error =
|
||||
storage_common_mkdir(storage, furi_string_get_cstr(tmp_new_path));
|
||||
if(error != FSE_OK) {
|
||||
if(error != FSE_OK && error != FSE_EXIST) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -548,7 +569,7 @@ FS_Error storage_common_merge(Storage* storage, const char* old_path, const char
|
|||
error = storage_common_stat(storage, old_path, &fileinfo);
|
||||
|
||||
if(error == FSE_OK) {
|
||||
if(fileinfo.flags & FSF_DIRECTORY) {
|
||||
if(file_info_is_dir(&fileinfo)) {
|
||||
error = storage_merge_recursive(storage, old_path, new_path);
|
||||
} else {
|
||||
error = storage_common_stat(storage, new_path, &fileinfo);
|
||||
|
@ -556,7 +577,7 @@ FS_Error storage_common_merge(Storage* storage, const char* old_path, const char
|
|||
furi_string_set(new_path_next, new_path);
|
||||
FuriString* dir_path;
|
||||
FuriString* filename;
|
||||
char extension[MAX_EXT_LEN];
|
||||
char extension[MAX_EXT_LEN] = {0};
|
||||
|
||||
dir_path = furi_string_alloc();
|
||||
filename = furi_string_alloc();
|
||||
|
@ -608,7 +629,12 @@ FS_Error storage_common_merge(Storage* storage, const char* old_path, const char
|
|||
|
||||
FS_Error storage_common_mkdir(Storage* storage, const char* path) {
|
||||
S_API_PROLOGUE;
|
||||
S_API_DATA_PATH;
|
||||
SAData data = {
|
||||
.path = {
|
||||
.path = path,
|
||||
.thread_id = furi_thread_get_current_id(),
|
||||
}};
|
||||
|
||||
S_API_MESSAGE(StorageCommandCommonMkDir);
|
||||
S_API_EPILOGUE;
|
||||
return S_RETURN_ERROR;
|
||||
|
@ -626,6 +652,7 @@ FS_Error storage_common_fs_info(
|
|||
.fs_path = fs_path,
|
||||
.total_space = total_space,
|
||||
.free_space = free_space,
|
||||
.thread_id = furi_thread_get_current_id(),
|
||||
}};
|
||||
|
||||
S_API_MESSAGE(StorageCommandCommonFSInfo);
|
||||
|
@ -633,6 +660,38 @@ FS_Error storage_common_fs_info(
|
|||
return S_RETURN_ERROR;
|
||||
}
|
||||
|
||||
void storage_common_resolve_path_and_ensure_app_directory(Storage* storage, FuriString* path) {
|
||||
S_API_PROLOGUE;
|
||||
|
||||
SAData data = {
|
||||
.cresolvepath = {
|
||||
.path = path,
|
||||
.thread_id = furi_thread_get_current_id(),
|
||||
}};
|
||||
|
||||
S_API_MESSAGE(StorageCommandCommonResolvePath);
|
||||
S_API_EPILOGUE;
|
||||
}
|
||||
|
||||
FS_Error storage_common_migrate(Storage* storage, const char* source, const char* dest) {
|
||||
if(!storage_common_exists(storage, source)) {
|
||||
return FSE_OK;
|
||||
}
|
||||
|
||||
FS_Error error = storage_common_merge(storage, source, dest);
|
||||
|
||||
if(error == FSE_OK) {
|
||||
storage_simply_remove_recursive(storage, source);
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
bool storage_common_exists(Storage* storage, const char* path) {
|
||||
FileInfo file_info;
|
||||
return storage_common_stat(storage, path, &file_info) == FSE_OK;
|
||||
}
|
||||
|
||||
/****************** ERROR ******************/
|
||||
|
||||
const char* storage_error_get_desc(FS_Error error_id) {
|
||||
|
@ -750,7 +809,7 @@ bool storage_simply_remove_recursive(Storage* storage, const char* path) {
|
|||
}
|
||||
|
||||
while(storage_dir_read(dir, &fileinfo, name, MAX_NAME_LENGTH)) {
|
||||
if(fileinfo.flags & FSF_DIRECTORY) {
|
||||
if(file_info_is_dir(&fileinfo)) {
|
||||
furi_string_cat_printf(cur_dir, "/%s", name);
|
||||
go_deeper = true;
|
||||
break;
|
||||
|
|
|
@ -5,21 +5,18 @@
|
|||
|
||||
void storage_file_init(StorageFile* obj) {
|
||||
obj->file = NULL;
|
||||
obj->type = ST_ERROR;
|
||||
obj->file_data = NULL;
|
||||
obj->path = furi_string_alloc();
|
||||
}
|
||||
|
||||
void storage_file_init_set(StorageFile* obj, const StorageFile* src) {
|
||||
obj->file = src->file;
|
||||
obj->type = src->type;
|
||||
obj->file_data = src->file_data;
|
||||
obj->path = furi_string_alloc_set(src->path);
|
||||
}
|
||||
|
||||
void storage_file_set(StorageFile* obj, const StorageFile* src) { //-V524
|
||||
obj->file = src->file;
|
||||
obj->type = src->type;
|
||||
obj->file_data = src->file_data;
|
||||
furi_string_set(obj->path, src->path);
|
||||
}
|
||||
|
@ -150,16 +147,10 @@ void* storage_get_storage_file_data(const File* file, StorageData* storage) {
|
|||
return founded_file->file_data;
|
||||
}
|
||||
|
||||
void storage_push_storage_file(
|
||||
File* file,
|
||||
FuriString* path,
|
||||
StorageType type,
|
||||
StorageData* storage) {
|
||||
void storage_push_storage_file(File* file, FuriString* path, StorageData* storage) {
|
||||
StorageFile* storage_file = StorageFileList_push_new(storage->files);
|
||||
|
||||
file->file_id = (uint32_t)storage_file;
|
||||
storage_file->file = file;
|
||||
storage_file->type = type;
|
||||
furi_string_set(storage_file->path, path);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
File* file;
|
||||
StorageType type;
|
||||
void* file_data;
|
||||
FuriString* path;
|
||||
} StorageFile;
|
||||
|
@ -66,11 +65,7 @@ bool storage_path_already_open(FuriString* path, StorageFileList_t files);
|
|||
void storage_set_storage_file_data(const File* file, void* file_data, StorageData* storage);
|
||||
void* storage_get_storage_file_data(const File* file, StorageData* storage);
|
||||
|
||||
void storage_push_storage_file(
|
||||
File* file,
|
||||
FuriString* path,
|
||||
StorageType type,
|
||||
StorageData* storage);
|
||||
void storage_push_storage_file(File* file, FuriString* path, StorageData* storage);
|
||||
bool storage_pop_storage_file(File* file, StorageData* storage);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -12,6 +12,8 @@ extern "C" {
|
|||
|
||||
#define STORAGE_COUNT (ST_INT + 1)
|
||||
|
||||
#define APPS_DATA_PATH EXT_PATH("apps_data")
|
||||
|
||||
typedef struct {
|
||||
ViewPort* view_port;
|
||||
bool enabled;
|
||||
|
|
|
@ -11,6 +11,7 @@ typedef struct {
|
|||
const char* path;
|
||||
FS_AccessMode access_mode;
|
||||
FS_OpenMode open_mode;
|
||||
FuriThreadId thread_id;
|
||||
} SADataFOpen;
|
||||
|
||||
typedef struct {
|
||||
|
@ -34,6 +35,7 @@ typedef struct {
|
|||
typedef struct {
|
||||
File* file;
|
||||
const char* path;
|
||||
FuriThreadId thread_id;
|
||||
} SADataDOpen;
|
||||
|
||||
typedef struct {
|
||||
|
@ -46,25 +48,34 @@ typedef struct {
|
|||
typedef struct {
|
||||
const char* path;
|
||||
uint32_t* timestamp;
|
||||
FuriThreadId thread_id;
|
||||
} SADataCTimestamp;
|
||||
|
||||
typedef struct {
|
||||
const char* path;
|
||||
FileInfo* fileinfo;
|
||||
FuriThreadId thread_id;
|
||||
} SADataCStat;
|
||||
|
||||
typedef struct {
|
||||
const char* fs_path;
|
||||
uint64_t* total_space;
|
||||
uint64_t* free_space;
|
||||
FuriThreadId thread_id;
|
||||
} SADataCFSInfo;
|
||||
|
||||
typedef struct {
|
||||
FuriString* path;
|
||||
FuriThreadId thread_id;
|
||||
} SADataCResolvePath;
|
||||
|
||||
typedef struct {
|
||||
uint32_t id;
|
||||
} SADataError;
|
||||
|
||||
typedef struct {
|
||||
const char* path;
|
||||
FuriThreadId thread_id;
|
||||
} SADataPath;
|
||||
|
||||
typedef struct {
|
||||
|
@ -87,6 +98,7 @@ typedef union {
|
|||
SADataCTimestamp ctimestamp;
|
||||
SADataCStat cstat;
|
||||
SADataCFSInfo cfsinfo;
|
||||
SADataCResolvePath cresolvepath;
|
||||
|
||||
SADataError error;
|
||||
|
||||
|
@ -128,6 +140,7 @@ typedef enum {
|
|||
StorageCommandSDUnmount,
|
||||
StorageCommandSDInfo,
|
||||
StorageCommandSDStatus,
|
||||
StorageCommandCommonResolvePath,
|
||||
} StorageCommand;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -4,17 +4,11 @@
|
|||
|
||||
#define FS_CALL(_storage, _fn) ret = _storage->fs_api->_fn;
|
||||
|
||||
static StorageData* storage_get_storage_by_type(Storage* app, StorageType type) {
|
||||
furi_check(type == ST_EXT || type == ST_INT);
|
||||
StorageData* storage = &app->storage[type];
|
||||
return storage;
|
||||
}
|
||||
|
||||
static bool storage_type_is_not_valid(StorageType type) {
|
||||
static bool storage_type_is_valid(StorageType type) {
|
||||
#ifdef FURI_RAM_EXEC
|
||||
return type != ST_EXT;
|
||||
return type == ST_EXT;
|
||||
#else
|
||||
return type >= ST_ERROR;
|
||||
return type < ST_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -30,25 +24,21 @@ static StorageData* get_storage_by_file(File* file, StorageData* storages) {
|
|||
return storage_data;
|
||||
}
|
||||
|
||||
static const char* remove_vfs(const char* path) {
|
||||
return path + MIN(4u, strlen(path));
|
||||
static const char* cstr_path_without_vfs_prefix(FuriString* path) {
|
||||
const char* path_cstr = furi_string_get_cstr(path);
|
||||
return path_cstr + MIN(4u, strlen(path_cstr));
|
||||
}
|
||||
|
||||
static StorageType storage_get_type_by_path(Storage* app, const char* path) {
|
||||
static StorageType storage_get_type_by_path(FuriString* path) {
|
||||
StorageType type = ST_ERROR;
|
||||
if(memcmp(path, STORAGE_EXT_PATH_PREFIX, strlen(STORAGE_EXT_PATH_PREFIX)) == 0) {
|
||||
type = ST_EXT;
|
||||
} else if(memcmp(path, STORAGE_INT_PATH_PREFIX, strlen(STORAGE_INT_PATH_PREFIX)) == 0) {
|
||||
type = ST_INT;
|
||||
} else if(memcmp(path, STORAGE_ANY_PATH_PREFIX, strlen(STORAGE_ANY_PATH_PREFIX)) == 0) {
|
||||
type = ST_ANY;
|
||||
}
|
||||
const char* path_cstr = furi_string_get_cstr(path);
|
||||
|
||||
if(type == ST_ANY) {
|
||||
if(memcmp(path_cstr, STORAGE_EXT_PATH_PREFIX, strlen(STORAGE_EXT_PATH_PREFIX)) == 0) {
|
||||
type = ST_EXT;
|
||||
} else if(memcmp(path_cstr, STORAGE_INT_PATH_PREFIX, strlen(STORAGE_INT_PATH_PREFIX)) == 0) {
|
||||
type = ST_INT;
|
||||
if(storage_data_status(&app->storage[ST_EXT]) == StorageStatusOK) {
|
||||
type = ST_EXT;
|
||||
}
|
||||
} else if(memcmp(path_cstr, STORAGE_ANY_PATH_PREFIX, strlen(STORAGE_ANY_PATH_PREFIX)) == 0) {
|
||||
type = ST_ANY;
|
||||
}
|
||||
|
||||
return type;
|
||||
|
@ -71,38 +61,51 @@ static void storage_path_change_to_real_storage(FuriString* path, StorageType re
|
|||
}
|
||||
}
|
||||
|
||||
FS_Error storage_get_data(Storage* app, FuriString* path, StorageData** storage) {
|
||||
StorageType type = storage_get_type_by_path(path);
|
||||
|
||||
if(storage_type_is_valid(type)) {
|
||||
if(type == ST_ANY) {
|
||||
type = ST_INT;
|
||||
if(storage_data_status(&app->storage[ST_EXT]) == StorageStatusOK) {
|
||||
type = ST_EXT;
|
||||
}
|
||||
storage_path_change_to_real_storage(path, type);
|
||||
}
|
||||
|
||||
furi_assert(type == ST_EXT || type == ST_INT);
|
||||
*storage = &app->storage[type];
|
||||
|
||||
return FSE_OK;
|
||||
} else {
|
||||
return FSE_INVALID_NAME;
|
||||
}
|
||||
}
|
||||
|
||||
/******************* File Functions *******************/
|
||||
|
||||
bool storage_process_file_open(
|
||||
Storage* app,
|
||||
File* file,
|
||||
const char* path,
|
||||
FuriString* path,
|
||||
FS_AccessMode access_mode,
|
||||
FS_OpenMode open_mode) {
|
||||
bool ret = false;
|
||||
StorageType type = storage_get_type_by_path(app, path);
|
||||
StorageData* storage;
|
||||
file->error_id = FSE_OK;
|
||||
file->error_id = storage_get_data(app, path, &storage);
|
||||
|
||||
if(storage_type_is_not_valid(type)) {
|
||||
file->error_id = FSE_INVALID_NAME;
|
||||
} else {
|
||||
storage = storage_get_storage_by_type(app, type);
|
||||
FuriString* real_path;
|
||||
real_path = furi_string_alloc_set(path);
|
||||
storage_path_change_to_real_storage(real_path, type);
|
||||
|
||||
if(storage_path_already_open(real_path, storage->files)) {
|
||||
if(file->error_id == FSE_OK) {
|
||||
if(storage_path_already_open(path, storage->files)) {
|
||||
file->error_id = FSE_ALREADY_OPEN;
|
||||
} else {
|
||||
if(access_mode & FSAM_WRITE) {
|
||||
storage_data_timestamp(storage);
|
||||
}
|
||||
storage_push_storage_file(file, real_path, type, storage);
|
||||
FS_CALL(storage, file.open(storage, file, remove_vfs(path), access_mode, open_mode));
|
||||
}
|
||||
storage_push_storage_file(file, path, storage);
|
||||
|
||||
furi_string_free(real_path);
|
||||
const char* path_cstr_no_vfs = cstr_path_without_vfs_prefix(path);
|
||||
FS_CALL(storage, file.open(storage, file, path_cstr_no_vfs, access_mode, open_mode));
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -243,27 +246,18 @@ static bool storage_process_file_eof(Storage* app, File* file) {
|
|||
|
||||
/******************* Dir Functions *******************/
|
||||
|
||||
bool storage_process_dir_open(Storage* app, File* file, const char* path) {
|
||||
bool storage_process_dir_open(Storage* app, File* file, FuriString* path) {
|
||||
bool ret = false;
|
||||
StorageType type = storage_get_type_by_path(app, path);
|
||||
StorageData* storage;
|
||||
file->error_id = FSE_OK;
|
||||
file->error_id = storage_get_data(app, path, &storage);
|
||||
|
||||
if(storage_type_is_not_valid(type)) {
|
||||
file->error_id = FSE_INVALID_NAME;
|
||||
} else {
|
||||
storage = storage_get_storage_by_type(app, type);
|
||||
FuriString* real_path;
|
||||
real_path = furi_string_alloc_set(path);
|
||||
storage_path_change_to_real_storage(real_path, type);
|
||||
|
||||
if(storage_path_already_open(real_path, storage->files)) {
|
||||
if(file->error_id == FSE_OK) {
|
||||
if(storage_path_already_open(path, storage->files)) {
|
||||
file->error_id = FSE_ALREADY_OPEN;
|
||||
} else {
|
||||
storage_push_storage_file(file, real_path, type, storage);
|
||||
FS_CALL(storage, dir.open(storage, file, remove_vfs(path)));
|
||||
storage_push_storage_file(file, path, storage);
|
||||
FS_CALL(storage, dir.open(storage, file, cstr_path_without_vfs_prefix(path)));
|
||||
}
|
||||
furi_string_free(real_path);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -320,73 +314,52 @@ bool storage_process_dir_rewind(Storage* app, File* file) {
|
|||
/******************* Common FS Functions *******************/
|
||||
|
||||
static FS_Error
|
||||
storage_process_common_timestamp(Storage* app, const char* path, uint32_t* timestamp) {
|
||||
FS_Error ret = FSE_OK;
|
||||
StorageType type = storage_get_type_by_path(app, path);
|
||||
storage_process_common_timestamp(Storage* app, FuriString* path, uint32_t* timestamp) {
|
||||
StorageData* storage;
|
||||
FS_Error ret = storage_get_data(app, path, &storage);
|
||||
|
||||
if(storage_type_is_not_valid(type)) {
|
||||
ret = FSE_INVALID_NAME;
|
||||
} else {
|
||||
StorageData* storage = storage_get_storage_by_type(app, type);
|
||||
if(ret == FSE_OK) {
|
||||
*timestamp = storage_data_get_timestamp(storage);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static FS_Error storage_process_common_stat(Storage* app, const char* path, FileInfo* fileinfo) {
|
||||
FS_Error ret = FSE_OK;
|
||||
StorageType type = storage_get_type_by_path(app, path);
|
||||
static FS_Error storage_process_common_stat(Storage* app, FuriString* path, FileInfo* fileinfo) {
|
||||
StorageData* storage;
|
||||
FS_Error ret = storage_get_data(app, path, &storage);
|
||||
|
||||
if(storage_type_is_not_valid(type)) {
|
||||
ret = FSE_INVALID_NAME;
|
||||
} else {
|
||||
StorageData* storage = storage_get_storage_by_type(app, type);
|
||||
FS_CALL(storage, common.stat(storage, remove_vfs(path), fileinfo));
|
||||
if(ret == FSE_OK) {
|
||||
FS_CALL(storage, common.stat(storage, cstr_path_without_vfs_prefix(path), fileinfo));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static FS_Error storage_process_common_remove(Storage* app, const char* path) {
|
||||
FS_Error ret = FSE_OK;
|
||||
StorageType type = storage_get_type_by_path(app, path);
|
||||
|
||||
FuriString* real_path;
|
||||
real_path = furi_string_alloc_set(path);
|
||||
storage_path_change_to_real_storage(real_path, type);
|
||||
static FS_Error storage_process_common_remove(Storage* app, FuriString* path) {
|
||||
StorageData* storage;
|
||||
FS_Error ret = storage_get_data(app, path, &storage);
|
||||
|
||||
do {
|
||||
if(storage_type_is_not_valid(type)) {
|
||||
ret = FSE_INVALID_NAME;
|
||||
break;
|
||||
}
|
||||
|
||||
StorageData* storage = storage_get_storage_by_type(app, type);
|
||||
if(storage_path_already_open(real_path, storage->files)) {
|
||||
if(storage_path_already_open(path, storage->files)) {
|
||||
ret = FSE_ALREADY_OPEN;
|
||||
break;
|
||||
}
|
||||
|
||||
storage_data_timestamp(storage);
|
||||
FS_CALL(storage, common.remove(storage, remove_vfs(path)));
|
||||
FS_CALL(storage, common.remove(storage, cstr_path_without_vfs_prefix(path)));
|
||||
} while(false);
|
||||
|
||||
furi_string_free(real_path);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static FS_Error storage_process_common_mkdir(Storage* app, const char* path) {
|
||||
FS_Error ret = FSE_OK;
|
||||
StorageType type = storage_get_type_by_path(app, path);
|
||||
static FS_Error storage_process_common_mkdir(Storage* app, FuriString* path) {
|
||||
StorageData* storage;
|
||||
FS_Error ret = storage_get_data(app, path, &storage);
|
||||
|
||||
if(storage_type_is_not_valid(type)) {
|
||||
ret = FSE_INVALID_NAME;
|
||||
} else {
|
||||
StorageData* storage = storage_get_storage_by_type(app, type);
|
||||
if(ret == FSE_OK) {
|
||||
storage_data_timestamp(storage);
|
||||
FS_CALL(storage, common.mkdir(storage, remove_vfs(path)));
|
||||
FS_CALL(storage, common.mkdir(storage, cstr_path_without_vfs_prefix(path)));
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -394,17 +367,16 @@ static FS_Error storage_process_common_mkdir(Storage* app, const char* path) {
|
|||
|
||||
static FS_Error storage_process_common_fs_info(
|
||||
Storage* app,
|
||||
const char* fs_path,
|
||||
FuriString* path,
|
||||
uint64_t* total_space,
|
||||
uint64_t* free_space) {
|
||||
FS_Error ret = FSE_OK;
|
||||
StorageType type = storage_get_type_by_path(app, fs_path);
|
||||
StorageData* storage;
|
||||
FS_Error ret = storage_get_data(app, path, &storage);
|
||||
|
||||
if(storage_type_is_not_valid(type)) {
|
||||
ret = FSE_INVALID_NAME;
|
||||
} else {
|
||||
StorageData* storage = storage_get_storage_by_type(app, type);
|
||||
FS_CALL(storage, common.fs_info(storage, remove_vfs(fs_path), total_space, free_space));
|
||||
if(ret == FSE_OK) {
|
||||
FS_CALL(
|
||||
storage,
|
||||
common.fs_info(storage, cstr_path_without_vfs_prefix(path), total_space, free_space));
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -471,14 +443,52 @@ static FS_Error storage_process_sd_status(Storage* app) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
/******************** Aliases processing *******************/
|
||||
|
||||
void storage_process_alias(
|
||||
Storage* app,
|
||||
FuriString* path,
|
||||
FuriThreadId thread_id,
|
||||
bool create_folders) {
|
||||
if(furi_string_start_with(path, STORAGE_APP_DATA_PATH_PREFIX)) {
|
||||
FuriString* apps_data_path_with_appsid = furi_string_alloc_set(APPS_DATA_PATH "/");
|
||||
furi_string_cat(apps_data_path_with_appsid, furi_thread_get_appid(thread_id));
|
||||
|
||||
// "/app" -> "/ext/apps_data/appsid"
|
||||
furi_string_replace_at(
|
||||
path,
|
||||
0,
|
||||
strlen(STORAGE_APP_DATA_PATH_PREFIX),
|
||||
furi_string_get_cstr(apps_data_path_with_appsid));
|
||||
|
||||
// Create app data folder if not exists
|
||||
if(create_folders &&
|
||||
storage_process_common_stat(app, apps_data_path_with_appsid, NULL) != FSE_OK) {
|
||||
furi_string_set(apps_data_path_with_appsid, APPS_DATA_PATH);
|
||||
storage_process_common_mkdir(app, apps_data_path_with_appsid);
|
||||
furi_string_cat(apps_data_path_with_appsid, "/");
|
||||
furi_string_cat(apps_data_path_with_appsid, furi_thread_get_appid(thread_id));
|
||||
storage_process_common_mkdir(app, apps_data_path_with_appsid);
|
||||
}
|
||||
|
||||
furi_string_free(apps_data_path_with_appsid);
|
||||
}
|
||||
}
|
||||
|
||||
/****************** API calls processing ******************/
|
||||
|
||||
void storage_process_message_internal(Storage* app, StorageMessage* message) {
|
||||
FuriString* path = NULL;
|
||||
|
||||
switch(message->command) {
|
||||
// File operations
|
||||
case StorageCommandFileOpen:
|
||||
path = furi_string_alloc_set(message->data->fopen.path);
|
||||
storage_process_alias(app, path, message->data->fopen.thread_id, true);
|
||||
message->return_data->bool_value = storage_process_file_open(
|
||||
app,
|
||||
message->data->fopen.file,
|
||||
message->data->fopen.path,
|
||||
path,
|
||||
message->data->fopen.access_mode,
|
||||
message->data->fopen.open_mode);
|
||||
break;
|
||||
|
@ -527,9 +537,12 @@ void storage_process_message_internal(Storage* app, StorageMessage* message) {
|
|||
message->return_data->bool_value = storage_process_file_eof(app, message->data->file.file);
|
||||
break;
|
||||
|
||||
// Dir operations
|
||||
case StorageCommandDirOpen:
|
||||
path = furi_string_alloc_set(message->data->dopen.path);
|
||||
storage_process_alias(app, path, message->data->dopen.thread_id, true);
|
||||
message->return_data->bool_value =
|
||||
storage_process_dir_open(app, message->data->dopen.file, message->data->dopen.path);
|
||||
storage_process_dir_open(app, message->data->dopen.file, path);
|
||||
break;
|
||||
case StorageCommandDirClose:
|
||||
message->return_data->bool_value =
|
||||
|
@ -547,29 +560,42 @@ void storage_process_message_internal(Storage* app, StorageMessage* message) {
|
|||
message->return_data->bool_value =
|
||||
storage_process_dir_rewind(app, message->data->file.file);
|
||||
break;
|
||||
|
||||
// Common operations
|
||||
case StorageCommandCommonTimestamp:
|
||||
message->return_data->error_value = storage_process_common_timestamp(
|
||||
app, message->data->ctimestamp.path, message->data->ctimestamp.timestamp);
|
||||
path = furi_string_alloc_set(message->data->ctimestamp.path);
|
||||
storage_process_alias(app, path, message->data->ctimestamp.thread_id, false);
|
||||
message->return_data->error_value =
|
||||
storage_process_common_timestamp(app, path, message->data->ctimestamp.timestamp);
|
||||
break;
|
||||
case StorageCommandCommonStat:
|
||||
message->return_data->error_value = storage_process_common_stat(
|
||||
app, message->data->cstat.path, message->data->cstat.fileinfo);
|
||||
path = furi_string_alloc_set(message->data->cstat.path);
|
||||
storage_process_alias(app, path, message->data->cstat.thread_id, false);
|
||||
message->return_data->error_value =
|
||||
storage_process_common_stat(app, path, message->data->cstat.fileinfo);
|
||||
break;
|
||||
case StorageCommandCommonRemove:
|
||||
message->return_data->error_value =
|
||||
storage_process_common_remove(app, message->data->path.path);
|
||||
path = furi_string_alloc_set(message->data->path.path);
|
||||
storage_process_alias(app, path, message->data->path.thread_id, false);
|
||||
message->return_data->error_value = storage_process_common_remove(app, path);
|
||||
break;
|
||||
case StorageCommandCommonMkDir:
|
||||
message->return_data->error_value =
|
||||
storage_process_common_mkdir(app, message->data->path.path);
|
||||
path = furi_string_alloc_set(message->data->path.path);
|
||||
storage_process_alias(app, path, message->data->path.thread_id, true);
|
||||
message->return_data->error_value = storage_process_common_mkdir(app, path);
|
||||
break;
|
||||
case StorageCommandCommonFSInfo:
|
||||
path = furi_string_alloc_set(message->data->cfsinfo.fs_path);
|
||||
storage_process_alias(app, path, message->data->cfsinfo.thread_id, false);
|
||||
message->return_data->error_value = storage_process_common_fs_info(
|
||||
app,
|
||||
message->data->cfsinfo.fs_path,
|
||||
message->data->cfsinfo.total_space,
|
||||
message->data->cfsinfo.free_space);
|
||||
app, path, message->data->cfsinfo.total_space, message->data->cfsinfo.free_space);
|
||||
break;
|
||||
case StorageCommandCommonResolvePath:
|
||||
storage_process_alias(
|
||||
app, message->data->cresolvepath.path, message->data->cresolvepath.thread_id, true);
|
||||
break;
|
||||
|
||||
// SD operations
|
||||
case StorageCommandSDFormat:
|
||||
message->return_data->error_value = storage_process_sd_format(app);
|
||||
break;
|
||||
|
@ -585,6 +611,10 @@ void storage_process_message_internal(Storage* app, StorageMessage* message) {
|
|||
break;
|
||||
}
|
||||
|
||||
if(path != NULL) { //-V547
|
||||
furi_string_free(path);
|
||||
}
|
||||
|
||||
api_lock_unlock(message->lock);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,341 +0,0 @@
|
|||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <storage/storage.h>
|
||||
|
||||
#define TAG "StorageTest"
|
||||
#define BYTES_COUNT 16
|
||||
#define TEST_STRING "TestDataStringProvidedByDiceRoll"
|
||||
#define SEEK_OFFSET_FROM_START 10
|
||||
#define SEEK_OFFSET_INCREASE 12
|
||||
#define SEEK_OFFSET_SUM (SEEK_OFFSET_FROM_START + SEEK_OFFSET_INCREASE)
|
||||
|
||||
static void do_file_test(Storage* api, const char* path) {
|
||||
File* file = storage_file_alloc(api);
|
||||
bool result;
|
||||
uint8_t bytes[BYTES_COUNT + 1];
|
||||
uint8_t bytes_count;
|
||||
uint64_t position;
|
||||
uint64_t size;
|
||||
|
||||
FURI_LOG_I(TAG, "--------- FILE \"%s\" ---------", path);
|
||||
|
||||
// open
|
||||
result = storage_file_open(file, path, FSAM_WRITE, FSOM_CREATE_ALWAYS);
|
||||
if(result) {
|
||||
FURI_LOG_I(TAG, "open");
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "open, %s", storage_file_get_error_desc(file));
|
||||
}
|
||||
|
||||
// write
|
||||
bytes_count = storage_file_write(file, TEST_STRING, strlen(TEST_STRING));
|
||||
if(bytes_count == 0) {
|
||||
FURI_LOG_E(TAG, "write, %s", storage_file_get_error_desc(file));
|
||||
} else {
|
||||
FURI_LOG_I(TAG, "write");
|
||||
}
|
||||
|
||||
// sync
|
||||
result = storage_file_sync(file);
|
||||
if(result) {
|
||||
FURI_LOG_I(TAG, "sync");
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "sync, %s", storage_file_get_error_desc(file));
|
||||
}
|
||||
|
||||
// eof #1
|
||||
result = storage_file_eof(file);
|
||||
if(result) {
|
||||
FURI_LOG_I(TAG, "eof #1");
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "eof #1, %s", storage_file_get_error_desc(file));
|
||||
}
|
||||
|
||||
// seek from start and tell
|
||||
result = storage_file_seek(file, SEEK_OFFSET_FROM_START, true);
|
||||
if(result) {
|
||||
FURI_LOG_I(TAG, "seek #1");
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "seek #1, %s", storage_file_get_error_desc(file));
|
||||
}
|
||||
position = storage_file_tell(file);
|
||||
if(position != SEEK_OFFSET_FROM_START) {
|
||||
FURI_LOG_E(TAG, "tell #1, %s", storage_file_get_error_desc(file));
|
||||
} else {
|
||||
FURI_LOG_I(TAG, "tell #1");
|
||||
}
|
||||
|
||||
// size
|
||||
size = storage_file_size(file);
|
||||
if(size != strlen(TEST_STRING)) {
|
||||
FURI_LOG_E(TAG, "size #1, %s", storage_file_get_error_desc(file));
|
||||
} else {
|
||||
FURI_LOG_I(TAG, "size #1");
|
||||
}
|
||||
|
||||
// seek and tell
|
||||
result = storage_file_seek(file, SEEK_OFFSET_INCREASE, false);
|
||||
if(result) {
|
||||
FURI_LOG_I(TAG, "seek #2");
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "seek #2, %s", storage_file_get_error_desc(file));
|
||||
}
|
||||
position = storage_file_tell(file);
|
||||
if(position != SEEK_OFFSET_SUM) {
|
||||
FURI_LOG_E(TAG, "tell #2, %s", storage_file_get_error_desc(file));
|
||||
} else {
|
||||
FURI_LOG_I(TAG, "tell #2");
|
||||
}
|
||||
|
||||
// eof #2
|
||||
result = storage_file_eof(file);
|
||||
if(!result) {
|
||||
FURI_LOG_I(TAG, "eof #2");
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "eof #2, %s", storage_file_get_error_desc(file));
|
||||
}
|
||||
|
||||
// truncate
|
||||
result = storage_file_truncate(file);
|
||||
if(result) {
|
||||
FURI_LOG_I(TAG, "truncate");
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "truncate, %s", storage_file_get_error_desc(file));
|
||||
}
|
||||
size = storage_file_size(file);
|
||||
if(size != SEEK_OFFSET_SUM) {
|
||||
FURI_LOG_E(TAG, "size #2, %s", storage_file_get_error_desc(file));
|
||||
} else {
|
||||
FURI_LOG_I(TAG, "size #2");
|
||||
}
|
||||
|
||||
// close
|
||||
result = storage_file_close(file);
|
||||
if(result) {
|
||||
FURI_LOG_I(TAG, "close");
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "close, error");
|
||||
}
|
||||
|
||||
// open
|
||||
result = storage_file_open(file, path, FSAM_READ, FSOM_OPEN_EXISTING);
|
||||
if(result) {
|
||||
FURI_LOG_I(TAG, "open");
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "open, %s", storage_file_get_error_desc(file));
|
||||
}
|
||||
|
||||
// read
|
||||
memset(bytes, 0, BYTES_COUNT + 1);
|
||||
bytes_count = storage_file_read(file, bytes, BYTES_COUNT);
|
||||
if(bytes_count == 0) {
|
||||
FURI_LOG_E(TAG, "read, %s", storage_file_get_error_desc(file));
|
||||
} else {
|
||||
if(memcmp(TEST_STRING, bytes, bytes_count) == 0) {
|
||||
FURI_LOG_I(TAG, "read");
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "read, garbage");
|
||||
}
|
||||
}
|
||||
|
||||
// close
|
||||
result = storage_file_close(file);
|
||||
if(result) {
|
||||
FURI_LOG_I(TAG, "close");
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "close, error");
|
||||
}
|
||||
|
||||
storage_file_free(file);
|
||||
}
|
||||
|
||||
static void do_dir_test(Storage* api, const char* path) {
|
||||
File* file = storage_file_alloc(api);
|
||||
bool result;
|
||||
|
||||
FURI_LOG_I(TAG, "--------- DIR \"%s\" ---------", path);
|
||||
|
||||
// open
|
||||
result = storage_dir_open(file, path);
|
||||
if(result) {
|
||||
FURI_LOG_I(TAG, "open");
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "open, %s", storage_file_get_error_desc(file));
|
||||
}
|
||||
|
||||
// read
|
||||
const uint8_t filename_size = 100;
|
||||
char* filename = malloc(filename_size);
|
||||
FileInfo fileinfo;
|
||||
|
||||
do {
|
||||
result = storage_dir_read(file, &fileinfo, filename, filename_size);
|
||||
if(result) {
|
||||
if(strlen(filename)) {
|
||||
FURI_LOG_I(
|
||||
TAG,
|
||||
"read #1, [%s]%s",
|
||||
((fileinfo.flags & FSF_DIRECTORY) ? "D" : "F"),
|
||||
filename);
|
||||
}
|
||||
} else if(storage_file_get_error(file) != FSE_NOT_EXIST) {
|
||||
FURI_LOG_E(TAG, "read #1, %s", storage_file_get_error_desc(file));
|
||||
break;
|
||||
}
|
||||
|
||||
} while(result);
|
||||
|
||||
// rewind
|
||||
result = storage_dir_rewind(file);
|
||||
if(result) {
|
||||
FURI_LOG_I(TAG, "rewind");
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "rewind, %s", storage_file_get_error_desc(file));
|
||||
}
|
||||
|
||||
// read
|
||||
do {
|
||||
result = storage_dir_read(file, &fileinfo, filename, filename_size);
|
||||
if(result) {
|
||||
if(strlen(filename)) {
|
||||
FURI_LOG_I(
|
||||
TAG,
|
||||
"read #2, [%s]%s",
|
||||
((fileinfo.flags & FSF_DIRECTORY) ? "D" : "F"),
|
||||
filename);
|
||||
}
|
||||
} else if(storage_file_get_error(file) != FSE_NOT_EXIST) {
|
||||
FURI_LOG_E(TAG, "read #2, %s", storage_file_get_error_desc(file));
|
||||
break;
|
||||
}
|
||||
|
||||
} while((strlen(filename)));
|
||||
|
||||
// close
|
||||
result = storage_dir_close(file);
|
||||
if(result) {
|
||||
FURI_LOG_I(TAG, "close");
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "close, error");
|
||||
}
|
||||
|
||||
storage_file_free(file);
|
||||
free(filename);
|
||||
}
|
||||
|
||||
static void do_test_start(Storage* api, const char* path) {
|
||||
FuriString* str_path = furi_string_alloc_printf("%s/test-folder", path);
|
||||
|
||||
FURI_LOG_I(TAG, "--------- START \"%s\" ---------", path);
|
||||
|
||||
// mkdir
|
||||
FS_Error result = storage_common_mkdir(api, furi_string_get_cstr(str_path));
|
||||
|
||||
if(result == FSE_OK) {
|
||||
FURI_LOG_I(TAG, "mkdir ok");
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "mkdir, %s", storage_error_get_desc(result));
|
||||
}
|
||||
|
||||
// stat
|
||||
FileInfo fileinfo;
|
||||
result = storage_common_stat(api, furi_string_get_cstr(str_path), &fileinfo);
|
||||
|
||||
if(result == FSE_OK) {
|
||||
if(fileinfo.flags & FSF_DIRECTORY) {
|
||||
FURI_LOG_I(TAG, "stat #1 ok");
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "stat #1, %s", storage_error_get_desc(result));
|
||||
}
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "stat #1, %s", storage_error_get_desc(result));
|
||||
}
|
||||
|
||||
furi_string_free(str_path);
|
||||
}
|
||||
|
||||
static void do_test_end(Storage* api, const char* path) {
|
||||
uint64_t total_space;
|
||||
uint64_t free_space;
|
||||
FuriString* str_path_1 = furi_string_alloc_printf("%s/test-folder", path);
|
||||
FuriString* str_path_2 = furi_string_alloc_printf("%s/test-folder2", path);
|
||||
|
||||
FURI_LOG_I(TAG, "--------- END \"%s\" ---------", path);
|
||||
|
||||
// fs stat
|
||||
FS_Error result = storage_common_fs_info(api, path, &total_space, &free_space);
|
||||
|
||||
if(result == FSE_OK) {
|
||||
uint32_t total_kb = total_space / 1024;
|
||||
uint32_t free_kb = free_space / 1024;
|
||||
FURI_LOG_I(TAG, "fs_info: total %luk, free %luk", total_kb, free_kb);
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "fs_info, %s", storage_error_get_desc(result));
|
||||
}
|
||||
|
||||
// rename #1
|
||||
result = storage_common_rename(
|
||||
api, furi_string_get_cstr(str_path_1), furi_string_get_cstr(str_path_2));
|
||||
if(result == FSE_OK) {
|
||||
FURI_LOG_I(TAG, "rename #1 ok");
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "rename #1, %s", storage_error_get_desc(result));
|
||||
}
|
||||
|
||||
// remove #1
|
||||
result = storage_common_remove(api, furi_string_get_cstr(str_path_2));
|
||||
if(result == FSE_OK) {
|
||||
FURI_LOG_I(TAG, "remove #1 ok");
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "remove #1, %s", storage_error_get_desc(result));
|
||||
}
|
||||
|
||||
// rename #2
|
||||
furi_string_printf(str_path_1, "%s/test.txt", path);
|
||||
furi_string_printf(str_path_2, "%s/test2.txt", path);
|
||||
|
||||
result = storage_common_rename(
|
||||
api, furi_string_get_cstr(str_path_1), furi_string_get_cstr(str_path_2));
|
||||
if(result == FSE_OK) {
|
||||
FURI_LOG_I(TAG, "rename #2 ok");
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "rename #2, %s", storage_error_get_desc(result));
|
||||
}
|
||||
|
||||
// remove #2
|
||||
result = storage_common_remove(api, furi_string_get_cstr(str_path_2));
|
||||
if(result == FSE_OK) {
|
||||
FURI_LOG_I(TAG, "remove #2 ok");
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "remove #2, %s", storage_error_get_desc(result));
|
||||
}
|
||||
|
||||
furi_string_free(str_path_1);
|
||||
furi_string_free(str_path_2);
|
||||
}
|
||||
|
||||
int32_t storage_test_app(void* p) {
|
||||
UNUSED(p);
|
||||
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||
do_test_start(api, STORAGE_INT_PATH_PREFIX);
|
||||
do_test_start(api, STORAGE_ANY_PATH_PREFIX);
|
||||
do_test_start(api, STORAGE_EXT_PATH_PREFIX);
|
||||
|
||||
do_file_test(api, INT_PATH("test.txt"));
|
||||
do_file_test(api, ANY_PATH("test.txt"));
|
||||
do_file_test(api, EXT_PATH("test.txt"));
|
||||
|
||||
do_dir_test(api, STORAGE_INT_PATH_PREFIX);
|
||||
do_dir_test(api, STORAGE_ANY_PATH_PREFIX);
|
||||
do_dir_test(api, STORAGE_EXT_PATH_PREFIX);
|
||||
|
||||
do_test_end(api, STORAGE_INT_PATH_PREFIX);
|
||||
do_test_end(api, STORAGE_ANY_PATH_PREFIX);
|
||||
do_test_end(api, STORAGE_EXT_PATH_PREFIX);
|
||||
|
||||
while(true) {
|
||||
furi_delay_ms(1000);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
static bool storage_move_to_sd_check_entry(const char* name, FileInfo* fileinfo, void* ctx) {
|
||||
UNUSED(ctx);
|
||||
if((fileinfo->flags & FSF_DIRECTORY) != 0) {
|
||||
if(file_info_is_dir(fileinfo)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
BIN
assets/icons/ErasePin/Erase_pin_128x64.png
Normal file
BIN
assets/icons/ErasePin/Erase_pin_128x64.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.1 KiB |
|
@ -4,26 +4,47 @@
|
|||
|
||||
```
|
||||
Filetype: Flipper iButton key
|
||||
Version: 1
|
||||
# Key type can be Cyfral, Dallas or Metakom
|
||||
Key type: Dallas
|
||||
# Data size for Cyfral is 2, for Metakom is 4, for Dallas is 8
|
||||
Data: 12 34 56 78 9A BC DE F0
|
||||
Version: 2
|
||||
Protocol: DS1992
|
||||
Rom Data: 08 DE AD BE EF FA CE 4E
|
||||
Sram Data: 4E 65 76 65 72 47 6F 6E 6E 61 47 69 76 65 59 6F 75 55 70 4E 65 76 65 72 47 6F 6E 6E 61 4C 65 74 59 6F 75 44 6F 77 6E 4E 65 76 65 72 47 6F 6E 6E 61 52 75 6E 41 72 6F 75 6E 64 41 6E 64 44 65 73 65 72 74 59 6F 75 4E 65 76 65 72 47 6F 6E 6E 61 4D 61 6B 65 59 6F 75 43 72 79 4E 65 76 65 72 47 6F 6E 6E 61 53 61 79 47 6F 6F 64 62 79 65 4E 65 76 65 72 47 6F 6E 6E 61 54 65 6C 6C 41 4C 69 65
|
||||
```
|
||||
|
||||
## Description
|
||||
|
||||
Filename extension: `.ibtn`
|
||||
|
||||
The file stores a single iButton key of the type defined by the `Key type` parameter.
|
||||
The file stores a single iButton key, complete with all data required by the protocol.
|
||||
|
||||
### Version history
|
||||
## Version history
|
||||
### 2. Current version.
|
||||
Changelog:
|
||||
- Added support for different Dallas protocols
|
||||
- Fields after `Protocol` are protocol-dependent for flexibiliy
|
||||
|
||||
#### Format fields
|
||||
|
||||
| Name | Type | Description |
|
||||
| --------- | ------ | -------------------------------------------- |
|
||||
| Protocol | string | Currently supported: DS1990, DS1992, DS1996, DSGeneric*, Cyfral, Metakom |
|
||||
| Rom Data | hex | Read-only memory data (Dallas protocols only) |
|
||||
| Sram Data | hex | Static RAM data (DS1992 and DS1996 only)
|
||||
| Data | hex | Key data (Cyfral & Metakom only) |
|
||||
|
||||
NOTE 1: DSGeneric is a catch-all protocol for all unknown 1-Wire devices. It reads only the ROM and does not perform any checks on the read data.
|
||||
It can also be used if a key with a deliberately invalid family code or checksum is required.
|
||||
|
||||
NOTE 2: When adding new protocols, it is not necessarily to increase the format version, define the format in the protocol implementation instead.
|
||||
|
||||
### 1. Initial version.
|
||||
Deprecated, will be converted to current version upon saving.
|
||||
|
||||
#### Format fields
|
||||
|
||||
| Name | Type | Description |
|
||||
| -------- | ------ | -------------------------------------------- |
|
||||
| Key type | string | Currently supported: Cyfral, Dallas, Metakom |
|
||||
| Data | hex | Key data |
|
||||
|
||||
1. Initial version.
|
||||
|
||||
### Format fields
|
||||
|
||||
| Name | Description |
|
||||
| -------- | -------------------------------------------- |
|
||||
| Key type | Currently supported: Cyfral, Dallas, Metakom |
|
||||
| Data | Key data (HEX values) |
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
entry,status,name,type,params
|
||||
Version,+,15.0,,
|
||||
Version,+,16.0,,
|
||||
Header,+,applications/services/bt/bt_service/bt.h,,
|
||||
Header,+,applications/services/cli/cli.h,,
|
||||
Header,+,applications/services/cli/cli_vcp.h,,
|
||||
|
|
|
|
@ -1,5 +1,5 @@
|
|||
entry,status,name,type,params
|
||||
Version,+,15.0,,
|
||||
Version,+,16.0,,
|
||||
Header,+,applications/services/bt/bt_service/bt.h,,
|
||||
Header,+,applications/services/cli/cli.h,,
|
||||
Header,+,applications/services/cli/cli_vcp.h,,
|
||||
|
@ -165,9 +165,10 @@ Header,+,lib/mlib/m-rbtree.h,,
|
|||
Header,+,lib/mlib/m-tuple.h,,
|
||||
Header,+,lib/mlib/m-variant.h,,
|
||||
Header,+,lib/nfc/nfc_device.h,,
|
||||
Header,+,lib/one_wire/ibutton/ibutton_key.h,,
|
||||
Header,+,lib/one_wire/ibutton/ibutton_protocols.h,,
|
||||
Header,+,lib/one_wire/ibutton/ibutton_worker.h,,
|
||||
Header,+,lib/one_wire/maxim_crc.h,,
|
||||
Header,+,lib/one_wire/one_wire_device.h,,
|
||||
Header,+,lib/one_wire/one_wire_host.h,,
|
||||
Header,+,lib/one_wire/one_wire_host_timing.h,,
|
||||
Header,+,lib/one_wire/one_wire_slave.h,,
|
||||
|
@ -195,6 +196,7 @@ Header,+,lib/toolbox/manchester_decoder.h,,
|
|||
Header,+,lib/toolbox/manchester_encoder.h,,
|
||||
Header,+,lib/toolbox/md5.h,,
|
||||
Header,+,lib/toolbox/path.h,,
|
||||
Header,+,lib/toolbox/pretty_format.h,,
|
||||
Header,+,lib/toolbox/protocols/protocol_dict.h,,
|
||||
Header,+,lib/toolbox/random_name.h,,
|
||||
Header,+,lib/toolbox/saved_struct.h,,
|
||||
|
@ -867,6 +869,7 @@ Function,+,file_browser_worker_set_folder_callback,void,"BrowserWorker*, Browser
|
|||
Function,+,file_browser_worker_set_item_callback,void,"BrowserWorker*, BrowserWorkerListItemCallback"
|
||||
Function,+,file_browser_worker_set_list_callback,void,"BrowserWorker*, BrowserWorkerListLoadCallback"
|
||||
Function,+,file_browser_worker_set_long_load_callback,void,"BrowserWorker*, BrowserWorkerLongLoadCallback"
|
||||
Function,+,file_info_is_dir,_Bool,const FileInfo*
|
||||
Function,+,file_stream_alloc,Stream*,Storage*
|
||||
Function,+,file_stream_close,_Bool,Stream*
|
||||
Function,+,file_stream_get_error,FS_Error,Stream*
|
||||
|
@ -893,6 +896,7 @@ Function,-,flipper_application_preload_status_to_string,const char*,FlipperAppli
|
|||
Function,+,flipper_application_spawn,FuriThread*,"FlipperApplication*, void*"
|
||||
Function,+,flipper_format_buffered_file_alloc,FlipperFormat*,Storage*
|
||||
Function,+,flipper_format_buffered_file_close,_Bool,FlipperFormat*
|
||||
Function,+,flipper_format_buffered_file_open_always,_Bool,"FlipperFormat*, const char*"
|
||||
Function,+,flipper_format_buffered_file_open_existing,_Bool,"FlipperFormat*, const char*"
|
||||
Function,+,flipper_format_delete_key,_Bool,"FlipperFormat*, const char*"
|
||||
Function,+,flipper_format_file_alloc,FlipperFormat*,Storage*
|
||||
|
@ -1553,6 +1557,7 @@ Function,+,furi_thread_flags_get,uint32_t,
|
|||
Function,+,furi_thread_flags_set,uint32_t,"FuriThreadId, uint32_t"
|
||||
Function,+,furi_thread_flags_wait,uint32_t,"uint32_t, uint32_t, uint32_t"
|
||||
Function,+,furi_thread_free,void,FuriThread*
|
||||
Function,+,furi_thread_get_appid,const char*,FuriThreadId
|
||||
Function,+,furi_thread_get_current,FuriThread*,
|
||||
Function,+,furi_thread_get_current_id,FuriThreadId,
|
||||
Function,+,furi_thread_get_current_priority,FuriThreadPriority,
|
||||
|
@ -1567,6 +1572,7 @@ Function,+,furi_thread_is_suspended,_Bool,FuriThreadId
|
|||
Function,+,furi_thread_join,_Bool,FuriThread*
|
||||
Function,+,furi_thread_mark_as_service,void,FuriThread*
|
||||
Function,+,furi_thread_resume,void,FuriThreadId
|
||||
Function,+,furi_thread_set_appid,void,"FuriThread*, const char*"
|
||||
Function,+,furi_thread_set_callback,void,"FuriThread*, FuriThreadCallback"
|
||||
Function,+,furi_thread_set_context,void,"FuriThread*, void*"
|
||||
Function,+,furi_thread_set_current_priority,void,FuriThreadPriority
|
||||
|
@ -1626,22 +1632,33 @@ Function,+,hmac_sha256_update,void,"const hmac_sha256_context*, const uint8_t*,
|
|||
Function,-,hypot,double,"double, double"
|
||||
Function,-,hypotf,float,"float, float"
|
||||
Function,-,hypotl,long double,"long double, long double"
|
||||
Function,+,ibutton_key_alloc,iButtonKey*,
|
||||
Function,+,ibutton_key_clear_data,void,iButtonKey*
|
||||
Function,+,ibutton_key_dallas_crc_is_valid,_Bool,iButtonKey*
|
||||
Function,+,ibutton_key_dallas_is_1990_key,_Bool,iButtonKey*
|
||||
Function,+,ibutton_key_alloc,iButtonKey*,size_t
|
||||
Function,+,ibutton_key_free,void,iButtonKey*
|
||||
Function,+,ibutton_key_get_data_p,const uint8_t*,iButtonKey*
|
||||
Function,+,ibutton_key_get_data_size,uint8_t,iButtonKey*
|
||||
Function,+,ibutton_key_get_max_size,uint8_t,
|
||||
Function,+,ibutton_key_get_size_by_type,uint8_t,iButtonKeyType
|
||||
Function,+,ibutton_key_get_string_by_type,const char*,iButtonKeyType
|
||||
Function,+,ibutton_key_get_type,iButtonKeyType,iButtonKey*
|
||||
Function,+,ibutton_key_get_type_by_string,_Bool,"const char*, iButtonKeyType*"
|
||||
Function,+,ibutton_key_set,void,"iButtonKey*, const iButtonKey*"
|
||||
Function,+,ibutton_key_set_data,void,"iButtonKey*, uint8_t*, uint8_t"
|
||||
Function,+,ibutton_key_set_type,void,"iButtonKey*, iButtonKeyType"
|
||||
Function,+,ibutton_worker_alloc,iButtonWorker*,
|
||||
Function,+,ibutton_key_get_protocol_id,iButtonProtocolId,const iButtonKey*
|
||||
Function,+,ibutton_key_reset,void,iButtonKey*
|
||||
Function,+,ibutton_key_set_protocol_id,void,"iButtonKey*, iButtonProtocolId"
|
||||
Function,+,ibutton_protocols_alloc,iButtonProtocols*,
|
||||
Function,+,ibutton_protocols_apply_edits,void,"iButtonProtocols*, const iButtonKey*"
|
||||
Function,+,ibutton_protocols_emulate_start,void,"iButtonProtocols*, iButtonKey*"
|
||||
Function,+,ibutton_protocols_emulate_stop,void,"iButtonProtocols*, iButtonKey*"
|
||||
Function,+,ibutton_protocols_free,void,iButtonProtocols*
|
||||
Function,+,ibutton_protocols_get_editable_data,void,"iButtonProtocols*, const iButtonKey*, iButtonEditableData*"
|
||||
Function,+,ibutton_protocols_get_features,uint32_t,"iButtonProtocols*, iButtonProtocolId"
|
||||
Function,+,ibutton_protocols_get_id_by_name,iButtonProtocolId,"iButtonProtocols*, const char*"
|
||||
Function,+,ibutton_protocols_get_manufacturer,const char*,"iButtonProtocols*, iButtonProtocolId"
|
||||
Function,+,ibutton_protocols_get_max_data_size,size_t,iButtonProtocols*
|
||||
Function,+,ibutton_protocols_get_name,const char*,"iButtonProtocols*, iButtonProtocolId"
|
||||
Function,+,ibutton_protocols_get_protocol_count,uint32_t,
|
||||
Function,+,ibutton_protocols_is_valid,_Bool,"iButtonProtocols*, const iButtonKey*"
|
||||
Function,+,ibutton_protocols_load,_Bool,"iButtonProtocols*, iButtonKey*, const char*"
|
||||
Function,+,ibutton_protocols_read,_Bool,"iButtonProtocols*, iButtonKey*"
|
||||
Function,+,ibutton_protocols_render_brief_data,void,"iButtonProtocols*, const iButtonKey*, FuriString*"
|
||||
Function,+,ibutton_protocols_render_data,void,"iButtonProtocols*, const iButtonKey*, FuriString*"
|
||||
Function,+,ibutton_protocols_render_error,void,"iButtonProtocols*, const iButtonKey*, FuriString*"
|
||||
Function,+,ibutton_protocols_save,_Bool,"iButtonProtocols*, const iButtonKey*, const char*"
|
||||
Function,+,ibutton_protocols_write_blank,_Bool,"iButtonProtocols*, iButtonKey*"
|
||||
Function,+,ibutton_protocols_write_copy,_Bool,"iButtonProtocols*, iButtonKey*"
|
||||
Function,+,ibutton_worker_alloc,iButtonWorker*,iButtonProtocols*
|
||||
Function,+,ibutton_worker_emulate_set_callback,void,"iButtonWorker*, iButtonWorkerEmulateCallback, void*"
|
||||
Function,+,ibutton_worker_emulate_start,void,"iButtonWorker*, iButtonKey*"
|
||||
Function,+,ibutton_worker_free,void,iButtonWorker*
|
||||
|
@ -1650,8 +1667,9 @@ Function,+,ibutton_worker_read_start,void,"iButtonWorker*, iButtonKey*"
|
|||
Function,+,ibutton_worker_start_thread,void,iButtonWorker*
|
||||
Function,+,ibutton_worker_stop,void,iButtonWorker*
|
||||
Function,+,ibutton_worker_stop_thread,void,iButtonWorker*
|
||||
Function,+,ibutton_worker_write_blank_start,void,"iButtonWorker*, iButtonKey*"
|
||||
Function,+,ibutton_worker_write_copy_start,void,"iButtonWorker*, iButtonKey*"
|
||||
Function,+,ibutton_worker_write_set_callback,void,"iButtonWorker*, iButtonWorkerWriteCallback, void*"
|
||||
Function,+,ibutton_worker_write_start,void,"iButtonWorker*, iButtonKey*"
|
||||
Function,+,icon_animation_alloc,IconAnimation*,const Icon*
|
||||
Function,+,icon_animation_free,void,IconAnimation*
|
||||
Function,+,icon_animation_get_height,uint8_t,const IconAnimation*
|
||||
|
@ -2073,12 +2091,6 @@ Function,+,notification_message,void,"NotificationApp*, const NotificationSequen
|
|||
Function,+,notification_message_block,void,"NotificationApp*, const NotificationSequence*"
|
||||
Function,-,nrand48,long,unsigned short[3]
|
||||
Function,-,on_exit,int,"void (*)(int, void*), void*"
|
||||
Function,+,onewire_device_alloc,OneWireDevice*,"uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t"
|
||||
Function,+,onewire_device_attach,void,"OneWireDevice*, OneWireSlave*"
|
||||
Function,+,onewire_device_detach,void,OneWireDevice*
|
||||
Function,+,onewire_device_free,void,OneWireDevice*
|
||||
Function,+,onewire_device_get_id_p,uint8_t*,OneWireDevice*
|
||||
Function,+,onewire_device_send_id,void,OneWireDevice*
|
||||
Function,+,onewire_host_alloc,OneWireHost*,const GpioPin*
|
||||
Function,+,onewire_host_free,void,OneWireHost*
|
||||
Function,+,onewire_host_read,uint8_t,OneWireHost*
|
||||
|
@ -2093,10 +2105,15 @@ Function,+,onewire_host_stop,void,OneWireHost*
|
|||
Function,+,onewire_host_target_search,void,"OneWireHost*, uint8_t"
|
||||
Function,+,onewire_host_write,void,"OneWireHost*, uint8_t"
|
||||
Function,+,onewire_host_write_bit,void,"OneWireHost*, _Bool"
|
||||
Function,+,onewire_host_write_bytes,void,"OneWireHost*, const uint8_t*, uint16_t"
|
||||
Function,+,onewire_slave_alloc,OneWireSlave*,const GpioPin*
|
||||
Function,+,onewire_slave_attach,void,"OneWireSlave*, OneWireDevice*"
|
||||
Function,+,onewire_slave_detach,void,OneWireSlave*
|
||||
Function,+,onewire_slave_free,void,OneWireSlave*
|
||||
Function,+,onewire_slave_receive,_Bool,"OneWireSlave*, uint8_t*, size_t"
|
||||
Function,+,onewire_slave_receive_bit,_Bool,OneWireSlave*
|
||||
Function,+,onewire_slave_send,_Bool,"OneWireSlave*, const uint8_t*, size_t"
|
||||
Function,+,onewire_slave_send_bit,_Bool,"OneWireSlave*, _Bool"
|
||||
Function,+,onewire_slave_set_command_callback,void,"OneWireSlave*, OneWireSlaveCommandCallback, void*"
|
||||
Function,+,onewire_slave_set_reset_callback,void,"OneWireSlave*, OneWireSlaveResetCallback, void*"
|
||||
Function,+,onewire_slave_set_result_callback,void,"OneWireSlave*, OneWireSlaveResultCallback, void*"
|
||||
Function,+,onewire_slave_start,void,OneWireSlave*
|
||||
Function,+,onewire_slave_stop,void,OneWireSlave*
|
||||
|
@ -2144,6 +2161,7 @@ Function,+,power_off,void,Power*
|
|||
Function,+,power_reboot,void,PowerBootMode
|
||||
Function,+,powf,float,"float, float"
|
||||
Function,-,powl,long double,"long double, long double"
|
||||
Function,+,pretty_format_bytes_hex_canonical,void,"FuriString*, size_t, const char*, const uint8_t*, size_t"
|
||||
Function,-,printf,int,"const char*, ..."
|
||||
Function,-,prng_successor,uint32_t,"uint32_t, uint32_t"
|
||||
Function,+,property_value_out,void,"PropertyValueContext*, const char*, unsigned int, ..."
|
||||
|
@ -2478,14 +2496,18 @@ Function,+,sscanf,int,"const char*, const char*, ..."
|
|||
Function,-,star_line_reset_kl_type,void,
|
||||
Function,-,star_line_reset_mfname,void,
|
||||
Function,+,storage_common_copy,FS_Error,"Storage*, const char*, const char*"
|
||||
Function,+,storage_common_exists,_Bool,"Storage*, const char*"
|
||||
Function,+,storage_common_fs_info,FS_Error,"Storage*, const char*, uint64_t*, uint64_t*"
|
||||
Function,+,storage_common_merge,FS_Error,"Storage*, const char*, const char*"
|
||||
Function,+,storage_common_migrate,FS_Error,"Storage*, const char*, const char*"
|
||||
Function,+,storage_common_mkdir,FS_Error,"Storage*, const char*"
|
||||
Function,+,storage_common_remove,FS_Error,"Storage*, const char*"
|
||||
Function,+,storage_common_rename,FS_Error,"Storage*, const char*, const char*"
|
||||
Function,+,storage_common_resolve_path_and_ensure_app_directory,void,"Storage*, FuriString*"
|
||||
Function,+,storage_common_stat,FS_Error,"Storage*, const char*, FileInfo*"
|
||||
Function,+,storage_common_timestamp,FS_Error,"Storage*, const char*, uint32_t*"
|
||||
Function,+,storage_dir_close,_Bool,File*
|
||||
Function,+,storage_dir_exists,_Bool,"Storage*, const char*"
|
||||
Function,+,storage_dir_open,_Bool,"File*, const char*"
|
||||
Function,+,storage_dir_read,_Bool,"File*, FileInfo*, char*, uint16_t"
|
||||
Function,-,storage_dir_rewind,_Bool,File*
|
||||
|
|
|
|
@ -5,24 +5,20 @@
|
|||
#include <u8g2_glue.h>
|
||||
#include <assets_icons.h>
|
||||
|
||||
#define COUNTER_VALUE (100U)
|
||||
#define COUNTER_VALUE (136U)
|
||||
|
||||
static void flipper_boot_recovery_draw_splash(u8g2_t* fb, size_t progress) {
|
||||
u8g2_ClearBuffer(fb);
|
||||
u8g2_SetDrawColor(fb, 0x01);
|
||||
|
||||
u8g2_SetFont(fb, u8g2_font_helvB08_tr);
|
||||
u8g2_DrawStr(fb, 2, 8, "PIN and Factory Reset");
|
||||
u8g2_SetFont(fb, u8g2_font_haxrcorp4089_tr);
|
||||
u8g2_DrawStr(fb, 2, 21, "Hold Right to confirm");
|
||||
u8g2_DrawStr(fb, 2, 31, "Press Down to cancel");
|
||||
|
||||
if(progress < COUNTER_VALUE) {
|
||||
size_t width = progress / (COUNTER_VALUE / 100);
|
||||
u8g2_DrawBox(fb, 14 + (50 - width / 2), 54, width, 3);
|
||||
// Fill the progress bar while the progress is going down
|
||||
u8g2_SetDrawColor(fb, 0x01);
|
||||
u8g2_DrawRFrame(fb, 59, 41, 69, 8, 2);
|
||||
size_t width = (COUNTER_VALUE - progress) * 68 / COUNTER_VALUE;
|
||||
u8g2_DrawBox(fb, 60, 42, width, 6);
|
||||
} else {
|
||||
u8g2_SetDrawColor(fb, 0x00);
|
||||
u8g2_DrawRBox(fb, 59, 41, 69, 8, 2);
|
||||
}
|
||||
|
||||
u8g2_SetPowerSave(fb, 0);
|
||||
u8g2_SendBuffer(fb);
|
||||
}
|
||||
|
||||
|
@ -31,6 +27,18 @@ void flipper_boot_recovery_exec() {
|
|||
u8g2_Setup_st756x_flipper(fb, U8G2_R0, u8x8_hw_spi_stm32, u8g2_gpio_and_delay_stm32);
|
||||
u8g2_InitDisplay(fb);
|
||||
|
||||
furi_hal_compress_icon_init();
|
||||
uint8_t* splash_data = NULL;
|
||||
furi_hal_compress_icon_decode(icon_get_data(&I_Erase_pin_128x64), &splash_data);
|
||||
|
||||
u8g2_ClearBuffer(fb);
|
||||
u8g2_SetDrawColor(fb, 0x01);
|
||||
|
||||
// Draw the recovery picture
|
||||
u8g2_DrawXBM(fb, 0, 0, 128, 64, splash_data);
|
||||
u8g2_SendBuffer(fb);
|
||||
u8g2_SetPowerSave(fb, 0);
|
||||
|
||||
size_t counter = COUNTER_VALUE;
|
||||
while(counter) {
|
||||
if(!furi_hal_gpio_read(&gpio_button_down)) {
|
||||
|
|
|
@ -35,6 +35,8 @@ struct FuriThread {
|
|||
void* state_context;
|
||||
|
||||
char* name;
|
||||
char* appid;
|
||||
|
||||
configSTACK_DEPTH_TYPE stack_size;
|
||||
FuriThreadPriority priority;
|
||||
|
||||
|
@ -122,11 +124,25 @@ FuriThread* furi_thread_alloc() {
|
|||
thread->output.buffer = furi_string_alloc();
|
||||
thread->is_service = false;
|
||||
|
||||
FuriThread* parent = NULL;
|
||||
if(xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
|
||||
// TLS is not available, if we called not from thread context
|
||||
parent = pvTaskGetThreadLocalStoragePointer(NULL, 0);
|
||||
|
||||
if(parent && parent->appid) {
|
||||
furi_thread_set_appid(thread, parent->appid);
|
||||
} else {
|
||||
furi_thread_set_appid(thread, "unknown");
|
||||
}
|
||||
} else {
|
||||
// if scheduler is not started, we are starting driver thread
|
||||
furi_thread_set_appid(thread, "driver");
|
||||
}
|
||||
|
||||
FuriHalRtcHeapTrackMode mode = furi_hal_rtc_get_heap_track_mode();
|
||||
if(mode == FuriHalRtcHeapTrackModeAll) {
|
||||
thread->heap_trace_enabled = true;
|
||||
} else if(mode == FuriHalRtcHeapTrackModeTree && furi_thread_get_current_id()) {
|
||||
FuriThread* parent = pvTaskGetThreadLocalStoragePointer(NULL, 0);
|
||||
if(parent) thread->heap_trace_enabled = parent->heap_trace_enabled;
|
||||
} else {
|
||||
thread->heap_trace_enabled = false;
|
||||
|
@ -153,6 +169,7 @@ void furi_thread_free(FuriThread* thread) {
|
|||
furi_assert(thread->state == FuriThreadStateStopped);
|
||||
|
||||
if(thread->name) free((void*)thread->name);
|
||||
if(thread->appid) free((void*)thread->appid);
|
||||
furi_string_free(thread->output.buffer);
|
||||
|
||||
free(thread);
|
||||
|
@ -165,6 +182,13 @@ void furi_thread_set_name(FuriThread* thread, const char* name) {
|
|||
thread->name = name ? strdup(name) : NULL;
|
||||
}
|
||||
|
||||
void furi_thread_set_appid(FuriThread* thread, const char* appid) {
|
||||
furi_assert(thread);
|
||||
furi_assert(thread->state == FuriThreadStateStopped);
|
||||
if(thread->appid) free((void*)thread->appid);
|
||||
thread->appid = appid ? strdup(appid) : NULL;
|
||||
}
|
||||
|
||||
void furi_thread_mark_as_service(FuriThread* thread) {
|
||||
thread->is_service = true;
|
||||
}
|
||||
|
@ -498,6 +522,20 @@ const char* furi_thread_get_name(FuriThreadId thread_id) {
|
|||
return (name);
|
||||
}
|
||||
|
||||
const char* furi_thread_get_appid(FuriThreadId thread_id) {
|
||||
TaskHandle_t hTask = (TaskHandle_t)thread_id;
|
||||
const char* appid = "system";
|
||||
|
||||
if(!FURI_IS_IRQ_MODE() && (hTask != NULL)) {
|
||||
FuriThread* thread = (FuriThread*)pvTaskGetThreadLocalStoragePointer(hTask, 0);
|
||||
if(thread) {
|
||||
appid = thread->appid;
|
||||
}
|
||||
}
|
||||
|
||||
return (appid);
|
||||
}
|
||||
|
||||
uint32_t furi_thread_get_stack_space(FuriThreadId thread_id) {
|
||||
TaskHandle_t hTask = (TaskHandle_t)thread_id;
|
||||
uint32_t sz;
|
||||
|
|
|
@ -87,6 +87,16 @@ void furi_thread_free(FuriThread* thread);
|
|||
*/
|
||||
void furi_thread_set_name(FuriThread* thread, const char* name);
|
||||
|
||||
/**
|
||||
* @brief Set FuriThread appid
|
||||
* Technically, it is like a "process id", but it is not a system-wide unique identifier.
|
||||
* All threads spawned by the same app will have the same appid.
|
||||
*
|
||||
* @param thread
|
||||
* @param appid
|
||||
*/
|
||||
void furi_thread_set_appid(FuriThread* thread, const char* appid);
|
||||
|
||||
/** Mark thread as service
|
||||
* The service cannot be stopped or removed, and cannot exit from the thread body
|
||||
*
|
||||
|
@ -233,10 +243,37 @@ uint32_t furi_thread_flags_get(void);
|
|||
|
||||
uint32_t furi_thread_flags_wait(uint32_t flags, uint32_t options, uint32_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Enumerate threads
|
||||
*
|
||||
* @param thread_array array of FuriThreadId, where thread ids will be stored
|
||||
* @param array_items array size
|
||||
* @return uint32_t threads count
|
||||
*/
|
||||
uint32_t furi_thread_enumerate(FuriThreadId* thread_array, uint32_t array_items);
|
||||
|
||||
/**
|
||||
* @brief Get thread name
|
||||
*
|
||||
* @param thread_id
|
||||
* @return const char* name or NULL
|
||||
*/
|
||||
const char* furi_thread_get_name(FuriThreadId thread_id);
|
||||
|
||||
/**
|
||||
* @brief Get thread appid
|
||||
*
|
||||
* @param thread_id
|
||||
* @return const char* appid
|
||||
*/
|
||||
const char* furi_thread_get_appid(FuriThreadId thread_id);
|
||||
|
||||
/**
|
||||
* @brief Get thread stack watermark
|
||||
*
|
||||
* @param thread_id
|
||||
* @return uint32_t
|
||||
*/
|
||||
uint32_t furi_thread_get_stack_space(FuriThreadId thread_id);
|
||||
|
||||
/** Get STDOUT callback for thead
|
||||
|
|
|
@ -41,6 +41,7 @@ void flipper_init() {
|
|||
FLIPPER_SERVICES[i].app,
|
||||
NULL);
|
||||
furi_thread_mark_as_service(thread);
|
||||
furi_thread_set_appid(thread, FLIPPER_SERVICES[i].appid);
|
||||
|
||||
furi_thread_start(thread);
|
||||
}
|
||||
|
|
|
@ -91,6 +91,12 @@ bool flipper_format_file_open_always(FlipperFormat* flipper_format, const char*
|
|||
return file_stream_open(flipper_format->stream, path, FSAM_READ_WRITE, FSOM_CREATE_ALWAYS);
|
||||
}
|
||||
|
||||
bool flipper_format_buffered_file_open_always(FlipperFormat* flipper_format, const char* path) {
|
||||
furi_assert(flipper_format);
|
||||
return buffered_file_stream_open(
|
||||
flipper_format->stream, path, FSAM_READ_WRITE, FSOM_CREATE_ALWAYS);
|
||||
}
|
||||
|
||||
bool flipper_format_file_open_new(FlipperFormat* flipper_format, const char* path) {
|
||||
furi_assert(flipper_format);
|
||||
return file_stream_open(flipper_format->stream, path, FSAM_READ_WRITE, FSOM_CREATE_NEW);
|
||||
|
|
|
@ -131,7 +131,7 @@ bool flipper_format_file_open_existing(FlipperFormat* flipper_format, const char
|
|||
|
||||
/**
|
||||
* Open existing file, buffered mode.
|
||||
* Use only if FlipperFormat allocated as a file.
|
||||
* Use only if FlipperFormat allocated as a buffered file.
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @param path File path
|
||||
* @return True on success
|
||||
|
@ -156,6 +156,15 @@ bool flipper_format_file_open_append(FlipperFormat* flipper_format, const char*
|
|||
*/
|
||||
bool flipper_format_file_open_always(FlipperFormat* flipper_format, const char* path);
|
||||
|
||||
/**
|
||||
* Open file. Creates a new file, or deletes the contents of the file if it already exists, buffered mode.
|
||||
* Use only if FlipperFormat allocated as a buffered file.
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @param path File path
|
||||
* @return True on success
|
||||
*/
|
||||
bool flipper_format_buffered_file_open_always(FlipperFormat* flipper_format, const char* path);
|
||||
|
||||
/**
|
||||
* Open file. Creates a new file, fails if file already exists.
|
||||
* Use only if FlipperFormat allocated as a file.
|
||||
|
|
|
@ -11,8 +11,9 @@ env.Append(
|
|||
File("one_wire_host_timing.h"),
|
||||
File("one_wire_host.h"),
|
||||
File("one_wire_slave.h"),
|
||||
File("one_wire_device.h"),
|
||||
File("ibutton/ibutton_key.h"),
|
||||
File("ibutton/ibutton_worker.h"),
|
||||
File("ibutton/ibutton_protocols.h"),
|
||||
File("maxim_crc.h"),
|
||||
],
|
||||
)
|
||||
|
|
|
@ -1,110 +1,43 @@
|
|||
#include <furi.h>
|
||||
#include <one_wire/maxim_crc.h>
|
||||
#include "ibutton_key.h"
|
||||
#include "ibutton_key_i.h"
|
||||
|
||||
struct iButtonKey {
|
||||
uint8_t data[IBUTTON_KEY_DATA_SIZE];
|
||||
iButtonKeyType type;
|
||||
iButtonProtocolId protocol_id;
|
||||
iButtonProtocolData* protocol_data;
|
||||
size_t protocol_data_size;
|
||||
};
|
||||
|
||||
iButtonKey* ibutton_key_alloc() {
|
||||
iButtonKey* ibutton_key_alloc(size_t data_size) {
|
||||
iButtonKey* key = malloc(sizeof(iButtonKey));
|
||||
memset(key, 0, sizeof(iButtonKey));
|
||||
|
||||
key->protocol_id = iButtonProtocolIdInvalid;
|
||||
key->protocol_data = malloc(data_size);
|
||||
key->protocol_data_size = data_size;
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
void ibutton_key_free(iButtonKey* key) {
|
||||
free(key->protocol_data);
|
||||
free(key);
|
||||
}
|
||||
|
||||
void ibutton_key_set(iButtonKey* to, const iButtonKey* from) {
|
||||
memcpy(to, from, sizeof(iButtonKey));
|
||||
void ibutton_key_reset(iButtonKey* key) {
|
||||
key->protocol_id = iButtonProtocolIdInvalid;
|
||||
memset(key->protocol_data, 0, key->protocol_data_size);
|
||||
}
|
||||
|
||||
void ibutton_key_set_data(iButtonKey* key, uint8_t* data, uint8_t data_count) {
|
||||
furi_check(data_count > 0);
|
||||
furi_check(data_count <= IBUTTON_KEY_DATA_SIZE);
|
||||
|
||||
memset(key->data, 0, IBUTTON_KEY_DATA_SIZE);
|
||||
memcpy(key->data, data, data_count);
|
||||
iButtonProtocolId ibutton_key_get_protocol_id(const iButtonKey* key) {
|
||||
return key->protocol_id;
|
||||
}
|
||||
|
||||
void ibutton_key_clear_data(iButtonKey* key) {
|
||||
memset(key->data, 0, IBUTTON_KEY_DATA_SIZE);
|
||||
void ibutton_key_set_protocol_id(iButtonKey* key, iButtonProtocolId protocol_id) {
|
||||
key->protocol_id = protocol_id;
|
||||
}
|
||||
|
||||
const uint8_t* ibutton_key_get_data_p(iButtonKey* key) {
|
||||
return key->data;
|
||||
iButtonProtocolData* ibutton_key_get_protocol_data(const iButtonKey* key) {
|
||||
return key->protocol_data;
|
||||
}
|
||||
|
||||
uint8_t ibutton_key_get_data_size(iButtonKey* key) {
|
||||
return ibutton_key_get_size_by_type(key->type);
|
||||
}
|
||||
|
||||
void ibutton_key_set_type(iButtonKey* key, iButtonKeyType key_type) {
|
||||
key->type = key_type;
|
||||
}
|
||||
|
||||
iButtonKeyType ibutton_key_get_type(iButtonKey* key) {
|
||||
return key->type;
|
||||
}
|
||||
|
||||
const char* ibutton_key_get_string_by_type(iButtonKeyType key_type) {
|
||||
switch(key_type) {
|
||||
case iButtonKeyCyfral:
|
||||
return "Cyfral";
|
||||
break;
|
||||
case iButtonKeyMetakom:
|
||||
return "Metakom";
|
||||
break;
|
||||
case iButtonKeyDS1990:
|
||||
return "Dallas";
|
||||
break;
|
||||
default:
|
||||
furi_crash("Invalid iButton type");
|
||||
}
|
||||
}
|
||||
|
||||
bool ibutton_key_get_type_by_string(const char* type_string, iButtonKeyType* key_type) {
|
||||
if(strcmp(type_string, ibutton_key_get_string_by_type(iButtonKeyCyfral)) == 0) {
|
||||
*key_type = iButtonKeyCyfral;
|
||||
} else if(strcmp(type_string, ibutton_key_get_string_by_type(iButtonKeyMetakom)) == 0) {
|
||||
*key_type = iButtonKeyMetakom;
|
||||
} else if(strcmp(type_string, ibutton_key_get_string_by_type(iButtonKeyDS1990)) == 0) {
|
||||
*key_type = iButtonKeyDS1990;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t ibutton_key_get_size_by_type(iButtonKeyType key_type) {
|
||||
uint8_t size = 0;
|
||||
|
||||
switch(key_type) {
|
||||
case iButtonKeyCyfral:
|
||||
size = 2;
|
||||
break;
|
||||
case iButtonKeyMetakom:
|
||||
size = 4;
|
||||
break;
|
||||
case iButtonKeyDS1990:
|
||||
size = 8;
|
||||
break;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
uint8_t ibutton_key_get_max_size() {
|
||||
return IBUTTON_KEY_DATA_SIZE;
|
||||
}
|
||||
|
||||
bool ibutton_key_dallas_crc_is_valid(iButtonKey* key) {
|
||||
return (maxim_crc8(key->data, 8, MAXIM_CRC8_INIT) == 0);
|
||||
}
|
||||
|
||||
bool ibutton_key_dallas_is_1990_key(iButtonKey* key) {
|
||||
return (key->data[0] == 0x01);
|
||||
size_t ibutton_key_get_protocol_data_size(const iButtonKey* key) {
|
||||
return key->protocol_data_size;
|
||||
}
|
||||
|
|
|
@ -5,127 +5,49 @@
|
|||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
#include <core/string.h>
|
||||
|
||||
#include "protocols/protocol_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define IBUTTON_KEY_DATA_SIZE 8
|
||||
#define IBUTTON_KEY_NAME_SIZE 22
|
||||
|
||||
typedef enum {
|
||||
iButtonKeyDS1990,
|
||||
iButtonKeyCyfral,
|
||||
iButtonKeyMetakom,
|
||||
} iButtonKeyType;
|
||||
|
||||
typedef struct iButtonKey iButtonKey;
|
||||
|
||||
/**
|
||||
* Allocate key
|
||||
* @return iButtonKey*
|
||||
* Allocate a key object
|
||||
* @param [in] data_size maximum data size held by the key
|
||||
* @return pointer to the key object
|
||||
*/
|
||||
iButtonKey* ibutton_key_alloc();
|
||||
iButtonKey* ibutton_key_alloc(size_t data_size);
|
||||
|
||||
/**
|
||||
* Free key
|
||||
* @param key
|
||||
* Destroy the key object, free resources
|
||||
* @param [in] key pointer to the key object
|
||||
*/
|
||||
void ibutton_key_free(iButtonKey* key);
|
||||
|
||||
/**
|
||||
* Copy key
|
||||
* @param to
|
||||
* @param from
|
||||
* Get the protocol id held by the key
|
||||
* @param [in] key pointer to the key object
|
||||
* @return protocol id held by the key
|
||||
*/
|
||||
void ibutton_key_set(iButtonKey* to, const iButtonKey* from);
|
||||
iButtonProtocolId ibutton_key_get_protocol_id(const iButtonKey* key);
|
||||
|
||||
/**
|
||||
* Set key data
|
||||
* @param key
|
||||
* @param data
|
||||
* @param data_count
|
||||
* Set the protocol id held by the key
|
||||
* @param [in] key pointer to the key object
|
||||
* @param [in] protocol_id new protocol id
|
||||
*/
|
||||
void ibutton_key_set_data(iButtonKey* key, uint8_t* data, uint8_t data_count);
|
||||
void ibutton_key_set_protocol_id(iButtonKey* key, iButtonProtocolId protocol_id);
|
||||
|
||||
/**
|
||||
* Clear key data
|
||||
* @param key
|
||||
* Reset the protocol id and data held by the key
|
||||
* @param [in] key pointer to the key object
|
||||
*/
|
||||
void ibutton_key_clear_data(iButtonKey* key);
|
||||
|
||||
/**
|
||||
* Get pointer to key data
|
||||
* @param key
|
||||
* @return const uint8_t*
|
||||
*/
|
||||
const uint8_t* ibutton_key_get_data_p(iButtonKey* key);
|
||||
|
||||
/**
|
||||
* Get key data size
|
||||
* @param key
|
||||
* @return uint8_t
|
||||
*/
|
||||
uint8_t ibutton_key_get_data_size(iButtonKey* key);
|
||||
|
||||
/**
|
||||
* Set key type
|
||||
* @param key
|
||||
* @param key_type
|
||||
*/
|
||||
void ibutton_key_set_type(iButtonKey* key, iButtonKeyType key_type);
|
||||
|
||||
/**
|
||||
* Get key type
|
||||
* @param key
|
||||
* @return iButtonKeyType
|
||||
*/
|
||||
iButtonKeyType ibutton_key_get_type(iButtonKey* key);
|
||||
|
||||
/**
|
||||
* Get type string from key type
|
||||
* @param key_type
|
||||
* @return const char*
|
||||
*/
|
||||
const char* ibutton_key_get_string_by_type(iButtonKeyType key_type);
|
||||
|
||||
/**
|
||||
* Get key type from string
|
||||
* @param type_string
|
||||
* @param key_type
|
||||
* @return bool
|
||||
*/
|
||||
bool ibutton_key_get_type_by_string(const char* type_string, iButtonKeyType* key_type);
|
||||
|
||||
/**
|
||||
* Get key data size from type
|
||||
* @param key_type
|
||||
* @return uint8_t
|
||||
*/
|
||||
uint8_t ibutton_key_get_size_by_type(iButtonKeyType key_type);
|
||||
|
||||
/**
|
||||
* Get max key size
|
||||
* @return uint8_t
|
||||
*/
|
||||
uint8_t ibutton_key_get_max_size();
|
||||
|
||||
/**
|
||||
* Check if CRC for onewire key is valid
|
||||
* @param key
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
bool ibutton_key_dallas_crc_is_valid(iButtonKey* key);
|
||||
|
||||
/**
|
||||
* Check if onewire key is a DS1990 key
|
||||
* @param key
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
bool ibutton_key_dallas_is_1990_key(iButtonKey* key);
|
||||
void ibutton_key_reset(iButtonKey* key);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
/**
|
||||
* @file ibutton_key_command.h
|
||||
*
|
||||
* List of misc commands for Dallas and blanks
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define RW1990_1_CMD_WRITE_RECORD_FLAG 0xD1
|
||||
#define RW1990_1_CMD_READ_RECORD_FLAG 0xB5
|
||||
#define RW1990_1_CMD_WRITE_ROM 0xD5
|
||||
|
||||
#define RW1990_2_CMD_WRITE_RECORD_FLAG 0x1D
|
||||
#define RW1990_2_CMD_READ_RECORD_FLAG 0x1E
|
||||
#define RW1990_2_CMD_WRITE_ROM 0xD5
|
||||
|
||||
#define TM2004_CMD_READ_STATUS 0xAA
|
||||
#define TM2004_CMD_READ_MEMORY 0xF0
|
||||
#define TM2004_CMD_WRITE_ROM 0x3C
|
||||
#define TM2004_CMD_FINALIZATION 0x35
|
||||
#define TM2004_ANSWER_READ_MEMORY 0xF5
|
||||
|
||||
#define TM01_CMD_WRITE_RECORD_FLAG 0xC1
|
||||
#define TM01_CMD_WRITE_ROM 0xC5
|
||||
#define TM01_CMD_SWITCH_TO_CYFRAL 0xCA
|
||||
#define TM01_CMD_SWITCH_TO_METAKOM 0xCB
|
||||
|
||||
#define DS1990_CMD_READ_ROM 0x33
|
9
lib/one_wire/ibutton/ibutton_key_i.h
Normal file
9
lib/one_wire/ibutton/ibutton_key_i.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include "ibutton_key.h"
|
||||
|
||||
#include "protocols/protocol_common_i.h"
|
||||
|
||||
iButtonProtocolData* ibutton_key_get_protocol_data(const iButtonKey* key);
|
||||
|
||||
size_t ibutton_key_get_protocol_data_size(const iButtonKey* key);
|
309
lib/one_wire/ibutton/ibutton_protocols.c
Normal file
309
lib/one_wire/ibutton/ibutton_protocols.c
Normal file
|
@ -0,0 +1,309 @@
|
|||
#include "ibutton_protocols.h"
|
||||
|
||||
#include <storage/storage.h>
|
||||
|
||||
#include "ibutton_key_i.h"
|
||||
|
||||
#include "protocols/protocol_group_defs.h"
|
||||
|
||||
#define IBUTTON_FILE_TYPE "Flipper iButton key"
|
||||
|
||||
#define IBUTTON_PROTOCOL_KEY_V1 "Key type"
|
||||
#define IBUTTON_PROTOCOL_KEY_V2 "Protocol"
|
||||
|
||||
#define IBUTTON_CURRENT_FORMAT_VERSION 2U
|
||||
|
||||
#define GET_PROTOCOL_GROUP(id) \
|
||||
iButtonProtocolGroupInfo info; \
|
||||
ibutton_protocols_get_group_by_id(protocols, (id), &info);
|
||||
|
||||
#define GROUP_BASE (info.base)
|
||||
#define GROUP_DATA (info.group)
|
||||
#define PROTOCOL_ID (info.id)
|
||||
|
||||
struct iButtonProtocols {
|
||||
iButtonProtocolGroupData** group_datas;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
const iButtonProtocolGroupBase* base;
|
||||
iButtonProtocolGroupData* group;
|
||||
iButtonProtocolLocalId id;
|
||||
} iButtonProtocolGroupInfo;
|
||||
|
||||
static void ibutton_protocols_get_group_by_id(
|
||||
iButtonProtocols* protocols,
|
||||
iButtonProtocolId id,
|
||||
iButtonProtocolGroupInfo* info) {
|
||||
iButtonProtocolLocalId local_id = id;
|
||||
|
||||
for(iButtonProtocolGroupId i = 0; i < iButtonProtocolGroupMax; ++i) {
|
||||
if(local_id < (signed)ibutton_protocol_groups[i]->protocol_count) {
|
||||
info->base = ibutton_protocol_groups[i];
|
||||
info->group = protocols->group_datas[i];
|
||||
info->id = local_id;
|
||||
return;
|
||||
|
||||
} else {
|
||||
local_id -= ibutton_protocol_groups[i]->protocol_count;
|
||||
}
|
||||
}
|
||||
furi_crash(NULL);
|
||||
}
|
||||
|
||||
iButtonProtocols* ibutton_protocols_alloc() {
|
||||
iButtonProtocols* protocols = malloc(sizeof(iButtonProtocols*));
|
||||
|
||||
protocols->group_datas = malloc(sizeof(iButtonProtocolGroupData*) * iButtonProtocolGroupMax);
|
||||
|
||||
for(iButtonProtocolGroupId i = 0; i < iButtonProtocolGroupMax; ++i) {
|
||||
protocols->group_datas[i] = ibutton_protocol_groups[i]->alloc();
|
||||
}
|
||||
|
||||
return protocols;
|
||||
}
|
||||
|
||||
void ibutton_protocols_free(iButtonProtocols* protocols) {
|
||||
for(iButtonProtocolGroupId i = 0; i < iButtonProtocolGroupMax; ++i) {
|
||||
ibutton_protocol_groups[i]->free(protocols->group_datas[i]);
|
||||
}
|
||||
|
||||
free(protocols->group_datas);
|
||||
free(protocols);
|
||||
}
|
||||
|
||||
uint32_t ibutton_protocols_get_protocol_count() {
|
||||
uint32_t count = 0;
|
||||
|
||||
for(iButtonProtocolGroupId i = 0; i < iButtonProtocolGroupMax; ++i) {
|
||||
count += ibutton_protocol_groups[i]->protocol_count;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
iButtonProtocolId ibutton_protocols_get_id_by_name(iButtonProtocols* protocols, const char* name) {
|
||||
iButtonProtocolLocalId offset = 0;
|
||||
|
||||
for(iButtonProtocolGroupId i = 0; i < iButtonProtocolGroupMax; ++i) {
|
||||
iButtonProtocolLocalId local_id;
|
||||
if(ibutton_protocol_groups[i]->get_id_by_name(protocols->group_datas[i], &local_id, name)) {
|
||||
return local_id + offset;
|
||||
}
|
||||
offset += ibutton_protocol_groups[i]->protocol_count;
|
||||
}
|
||||
return iButtonProtocolIdInvalid;
|
||||
}
|
||||
|
||||
uint32_t ibutton_protocols_get_features(iButtonProtocols* protocols, iButtonProtocolId id) {
|
||||
GET_PROTOCOL_GROUP(id);
|
||||
return GROUP_BASE->get_features(GROUP_DATA, PROTOCOL_ID);
|
||||
}
|
||||
|
||||
size_t ibutton_protocols_get_max_data_size(iButtonProtocols* protocols) {
|
||||
size_t max_size = 0;
|
||||
|
||||
for(iButtonProtocolGroupId i = 0; i < iButtonProtocolGroupMax; ++i) {
|
||||
const size_t current_max_size =
|
||||
ibutton_protocol_groups[i]->get_max_data_size(protocols->group_datas[i]);
|
||||
if(current_max_size > max_size) {
|
||||
max_size = current_max_size;
|
||||
}
|
||||
}
|
||||
|
||||
return max_size;
|
||||
}
|
||||
|
||||
const char* ibutton_protocols_get_manufacturer(iButtonProtocols* protocols, iButtonProtocolId id) {
|
||||
GET_PROTOCOL_GROUP(id);
|
||||
return GROUP_BASE->get_manufacturer(GROUP_DATA, PROTOCOL_ID);
|
||||
}
|
||||
|
||||
const char* ibutton_protocols_get_name(iButtonProtocols* protocols, iButtonProtocolId id) {
|
||||
GET_PROTOCOL_GROUP(id);
|
||||
return GROUP_BASE->get_name(GROUP_DATA, PROTOCOL_ID);
|
||||
}
|
||||
|
||||
bool ibutton_protocols_read(iButtonProtocols* protocols, iButtonKey* key) {
|
||||
iButtonProtocolLocalId id = iButtonProtocolIdInvalid;
|
||||
iButtonProtocolData* data = ibutton_key_get_protocol_data(key);
|
||||
|
||||
iButtonProtocolLocalId offset = 0;
|
||||
for(iButtonProtocolGroupId i = 0; i < iButtonProtocolGroupMax; ++i) {
|
||||
if(ibutton_protocol_groups[i]->read(protocols->group_datas[i], data, &id)) {
|
||||
id += offset;
|
||||
break;
|
||||
}
|
||||
offset += ibutton_protocol_groups[i]->protocol_count;
|
||||
}
|
||||
|
||||
ibutton_key_set_protocol_id(key, id);
|
||||
return id != iButtonProtocolIdInvalid;
|
||||
}
|
||||
|
||||
bool ibutton_protocols_write_blank(iButtonProtocols* protocols, iButtonKey* key) {
|
||||
const iButtonProtocolId id = ibutton_key_get_protocol_id(key);
|
||||
iButtonProtocolData* data = ibutton_key_get_protocol_data(key);
|
||||
|
||||
GET_PROTOCOL_GROUP(id);
|
||||
return GROUP_BASE->write_blank(GROUP_DATA, data, PROTOCOL_ID);
|
||||
}
|
||||
|
||||
bool ibutton_protocols_write_copy(iButtonProtocols* protocols, iButtonKey* key) {
|
||||
const iButtonProtocolId id = ibutton_key_get_protocol_id(key);
|
||||
iButtonProtocolData* data = ibutton_key_get_protocol_data(key);
|
||||
|
||||
GET_PROTOCOL_GROUP(id);
|
||||
return GROUP_BASE->write_copy(GROUP_DATA, data, PROTOCOL_ID);
|
||||
}
|
||||
|
||||
void ibutton_protocols_emulate_start(iButtonProtocols* protocols, iButtonKey* key) {
|
||||
const iButtonProtocolId id = ibutton_key_get_protocol_id(key);
|
||||
iButtonProtocolData* data = ibutton_key_get_protocol_data(key);
|
||||
|
||||
GET_PROTOCOL_GROUP(id);
|
||||
GROUP_BASE->emulate_start(GROUP_DATA, data, PROTOCOL_ID);
|
||||
}
|
||||
|
||||
void ibutton_protocols_emulate_stop(iButtonProtocols* protocols, iButtonKey* key) {
|
||||
const iButtonProtocolId id = ibutton_key_get_protocol_id(key);
|
||||
iButtonProtocolData* data = ibutton_key_get_protocol_data(key);
|
||||
|
||||
GET_PROTOCOL_GROUP(id);
|
||||
GROUP_BASE->emulate_stop(GROUP_DATA, data, PROTOCOL_ID);
|
||||
}
|
||||
|
||||
bool ibutton_protocols_save(
|
||||
iButtonProtocols* protocols,
|
||||
const iButtonKey* key,
|
||||
const char* file_name) {
|
||||
const iButtonProtocolId id = ibutton_key_get_protocol_id(key);
|
||||
const iButtonProtocolData* data = ibutton_key_get_protocol_data(key);
|
||||
|
||||
bool success = false;
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
FlipperFormat* ff = flipper_format_buffered_file_alloc(storage);
|
||||
|
||||
do {
|
||||
const char* protocol_name = ibutton_protocols_get_name(protocols, id);
|
||||
|
||||
if(!flipper_format_buffered_file_open_always(ff, file_name)) break;
|
||||
|
||||
if(!flipper_format_write_header_cstr(ff, IBUTTON_FILE_TYPE, IBUTTON_CURRENT_FORMAT_VERSION))
|
||||
break;
|
||||
if(!flipper_format_write_string_cstr(ff, IBUTTON_PROTOCOL_KEY_V2, protocol_name)) break;
|
||||
|
||||
GET_PROTOCOL_GROUP(id);
|
||||
if(!GROUP_BASE->save(GROUP_DATA, data, PROTOCOL_ID, ff)) break;
|
||||
|
||||
success = true;
|
||||
} while(false);
|
||||
|
||||
flipper_format_free(ff);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool ibutton_protocols_load(iButtonProtocols* protocols, iButtonKey* key, const char* file_name) {
|
||||
iButtonProtocolData* data = ibutton_key_get_protocol_data(key);
|
||||
|
||||
bool success = false;
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
FlipperFormat* ff = flipper_format_buffered_file_alloc(storage);
|
||||
FuriString* tmp = furi_string_alloc();
|
||||
|
||||
do {
|
||||
if(!flipper_format_buffered_file_open_existing(ff, file_name)) break;
|
||||
|
||||
uint32_t version;
|
||||
|
||||
if(!flipper_format_read_header(ff, tmp, &version)) break;
|
||||
if(!furi_string_equal(tmp, IBUTTON_FILE_TYPE)) break;
|
||||
|
||||
if(version == 1) {
|
||||
if(!flipper_format_read_string(ff, IBUTTON_PROTOCOL_KEY_V1, tmp)) break;
|
||||
} else if(version == 2) {
|
||||
if(!flipper_format_read_string(ff, IBUTTON_PROTOCOL_KEY_V2, tmp)) break;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
const iButtonProtocolId id =
|
||||
ibutton_protocols_get_id_by_name(protocols, furi_string_get_cstr(tmp));
|
||||
ibutton_key_set_protocol_id(key, id);
|
||||
|
||||
GET_PROTOCOL_GROUP(id);
|
||||
if(!GROUP_BASE->load(GROUP_DATA, data, PROTOCOL_ID, version, ff)) break;
|
||||
|
||||
success = true;
|
||||
} while(false);
|
||||
|
||||
flipper_format_free(ff);
|
||||
furi_string_free(tmp);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void ibutton_protocols_render_data(
|
||||
iButtonProtocols* protocols,
|
||||
const iButtonKey* key,
|
||||
FuriString* result) {
|
||||
const iButtonProtocolId id = ibutton_key_get_protocol_id(key);
|
||||
const iButtonProtocolData* data = ibutton_key_get_protocol_data(key);
|
||||
|
||||
GET_PROTOCOL_GROUP(id);
|
||||
GROUP_BASE->render_data(GROUP_DATA, data, PROTOCOL_ID, result);
|
||||
}
|
||||
|
||||
void ibutton_protocols_render_brief_data(
|
||||
iButtonProtocols* protocols,
|
||||
const iButtonKey* key,
|
||||
FuriString* result) {
|
||||
const iButtonProtocolId id = ibutton_key_get_protocol_id(key);
|
||||
const iButtonProtocolData* data = ibutton_key_get_protocol_data(key);
|
||||
|
||||
GET_PROTOCOL_GROUP(id);
|
||||
GROUP_BASE->render_brief_data(GROUP_DATA, data, PROTOCOL_ID, result);
|
||||
}
|
||||
|
||||
void ibutton_protocols_render_error(
|
||||
iButtonProtocols* protocols,
|
||||
const iButtonKey* key,
|
||||
FuriString* result) {
|
||||
const iButtonProtocolId id = ibutton_key_get_protocol_id(key);
|
||||
const iButtonProtocolData* data = ibutton_key_get_protocol_data(key);
|
||||
|
||||
GET_PROTOCOL_GROUP(id);
|
||||
GROUP_BASE->render_error(GROUP_DATA, data, PROTOCOL_ID, result);
|
||||
}
|
||||
|
||||
bool ibutton_protocols_is_valid(iButtonProtocols* protocols, const iButtonKey* key) {
|
||||
const iButtonProtocolId id = ibutton_key_get_protocol_id(key);
|
||||
const iButtonProtocolData* data = ibutton_key_get_protocol_data(key);
|
||||
|
||||
GET_PROTOCOL_GROUP(id);
|
||||
return GROUP_BASE->is_valid(GROUP_DATA, data, PROTOCOL_ID);
|
||||
}
|
||||
|
||||
void ibutton_protocols_get_editable_data(
|
||||
iButtonProtocols* protocols,
|
||||
const iButtonKey* key,
|
||||
iButtonEditableData* editable) {
|
||||
const iButtonProtocolId id = ibutton_key_get_protocol_id(key);
|
||||
iButtonProtocolData* data = ibutton_key_get_protocol_data(key);
|
||||
|
||||
GET_PROTOCOL_GROUP(id);
|
||||
GROUP_BASE->get_editable_data(GROUP_DATA, data, PROTOCOL_ID, editable);
|
||||
}
|
||||
|
||||
void ibutton_protocols_apply_edits(iButtonProtocols* protocols, const iButtonKey* key) {
|
||||
const iButtonProtocolId id = ibutton_key_get_protocol_id(key);
|
||||
iButtonProtocolData* data = ibutton_key_get_protocol_data(key);
|
||||
|
||||
GET_PROTOCOL_GROUP(id);
|
||||
GROUP_BASE->apply_edits(GROUP_DATA, data, PROTOCOL_ID);
|
||||
}
|
197
lib/one_wire/ibutton/ibutton_protocols.h
Normal file
197
lib/one_wire/ibutton/ibutton_protocols.h
Normal file
|
@ -0,0 +1,197 @@
|
|||
/**
|
||||
* @file ibutton_protocols.h
|
||||
*
|
||||
* Common interface for accessing various iButton protocols
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "protocols/protocol_common.h"
|
||||
|
||||
#include "ibutton_key.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct iButtonProtocols iButtonProtocols;
|
||||
|
||||
/**
|
||||
* Allocate an iButtonProtocols object
|
||||
* @return pointer to an iButtonProtocols object
|
||||
*/
|
||||
iButtonProtocols* ibutton_protocols_alloc();
|
||||
|
||||
/**
|
||||
* Destroy an iButtonProtocols object, free resources
|
||||
* @param [in] protocols pointer to an iButtonProtocols object
|
||||
*/
|
||||
void ibutton_protocols_free(iButtonProtocols* protocols);
|
||||
|
||||
/**
|
||||
* Get the total number of available protocols
|
||||
*/
|
||||
uint32_t ibutton_protocols_get_protocol_count();
|
||||
|
||||
/**
|
||||
* Get maximum data size out of all protocols available
|
||||
* @param [in] protocols pointer to an iButtonProtocols object
|
||||
* @return maximum data size in bytes
|
||||
*/
|
||||
size_t ibutton_protocols_get_max_data_size(iButtonProtocols* protocols);
|
||||
|
||||
/**
|
||||
* Get the protocol id based on its name
|
||||
* @param [in] protocols pointer to an iButtonProtocols object
|
||||
* @param [in] name pointer to a string containing the name
|
||||
* @return protocol id on success on iButtonProtocolIdInvalid on failure
|
||||
*/
|
||||
iButtonProtocolId ibutton_protocols_get_id_by_name(iButtonProtocols* protocols, const char* name);
|
||||
|
||||
/**
|
||||
* Get the manufacturer name based on the protocol id
|
||||
* @param [in] protocols pointer to an iButtonProtocols object
|
||||
* @param [in] id id of the protocol in question
|
||||
* @return pointer to a statically allocated string with manufacturer name
|
||||
*/
|
||||
const char* ibutton_protocols_get_manufacturer(iButtonProtocols* protocols, iButtonProtocolId id);
|
||||
|
||||
/**
|
||||
* Get the protocol name based on the protocol id
|
||||
* @param [in] protocols pointer to an iButtonProtocols object
|
||||
* @param [in] id id of the protocol in question
|
||||
* @return pointer to a statically allocated string with protocol name
|
||||
*/
|
||||
const char* ibutton_protocols_get_name(iButtonProtocols* protocols, iButtonProtocolId id);
|
||||
|
||||
/**
|
||||
* Get protocol features bitmask by protocol id
|
||||
* @param [in] protocols pointer to an iButtonProtocols object
|
||||
* @param [in] id id of the protocol in question
|
||||
*/
|
||||
uint32_t ibutton_protocols_get_features(iButtonProtocols* protocols, iButtonProtocolId id);
|
||||
|
||||
/**
|
||||
* Read a physical device (a key or an emulator)
|
||||
* @param [in] protocols pointer to an iButtonProtocols object
|
||||
* @param [out] key pointer to the key to read into (must be allocated before)
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
bool ibutton_protocols_read(iButtonProtocols* protocols, iButtonKey* key);
|
||||
|
||||
/**
|
||||
* Write the key to a blank
|
||||
* @param [in] protocols pointer to an iButtonProtocols object
|
||||
* @param [in] key pointer to the key to be written
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
bool ibutton_protocols_write_blank(iButtonProtocols* protocols, iButtonKey* key);
|
||||
|
||||
/**
|
||||
* Write the key to another one of the same type
|
||||
* @param [in] protocols pointer to an iButtonProtocols object
|
||||
* @param [in] key pointer to the key to be written
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
bool ibutton_protocols_write_copy(iButtonProtocols* protocols, iButtonKey* key);
|
||||
|
||||
/**
|
||||
* Start emulating the key
|
||||
* @param [in] protocols pointer to an iButtonProtocols object
|
||||
* @param [in] key pointer to the key to be emulated
|
||||
*/
|
||||
void ibutton_protocols_emulate_start(iButtonProtocols* protocols, iButtonKey* key);
|
||||
|
||||
/**
|
||||
* Stop emulating the key
|
||||
* @param [in] protocols pointer to an iButtonProtocols object
|
||||
* @param [in] key pointer to the key to be emulated
|
||||
*/
|
||||
void ibutton_protocols_emulate_stop(iButtonProtocols* protocols, iButtonKey* key);
|
||||
|
||||
/**
|
||||
* Save the key data to a file.
|
||||
* @param [in] protocols pointer to an iButtonProtocols object
|
||||
* @param [in] key pointer to the key to be saved
|
||||
* @param [in] file_name full absolute path to the file name
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
bool ibutton_protocols_save(
|
||||
iButtonProtocols* protocols,
|
||||
const iButtonKey* key,
|
||||
const char* file_name);
|
||||
|
||||
/**
|
||||
* Load the key from a file.
|
||||
* @param [in] protocols pointer to an iButtonProtocols object
|
||||
* @param [out] key pointer to the key to load into (must be allocated before)
|
||||
* @param [in] file_name full absolute path to the file name
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
bool ibutton_protocols_load(iButtonProtocols* protocols, iButtonKey* key, const char* file_name);
|
||||
|
||||
/**
|
||||
* Format a string containing device full data
|
||||
* @param [in] protocols pointer to an iButtonProtocols object
|
||||
* @param [in] key pointer to the key to be rendered
|
||||
* @param [out] result pointer to the FuriString instance (must be initialized)
|
||||
*/
|
||||
void ibutton_protocols_render_data(
|
||||
iButtonProtocols* protocols,
|
||||
const iButtonKey* key,
|
||||
FuriString* result);
|
||||
|
||||
/**
|
||||
* Format a string containing device brief data
|
||||
* @param [in] protocols pointer to an iButtonProtocols object
|
||||
* @param [in] key pointer to the key to be rendered
|
||||
* @param [out] result pointer to the FuriString instance (must be initialized)
|
||||
*/
|
||||
void ibutton_protocols_render_brief_data(
|
||||
iButtonProtocols* protocols,
|
||||
const iButtonKey* key,
|
||||
FuriString* result);
|
||||
|
||||
/**
|
||||
* Format a string containing error message (for invalid keys)
|
||||
* @param [in] protocols pointer to an iButtonProtocols object
|
||||
* @param [in] key pointer to the key to be rendered
|
||||
* @param [out] result pointer to the FuriString instance (must be initialized)
|
||||
*/
|
||||
void ibutton_protocols_render_error(
|
||||
iButtonProtocols* protocols,
|
||||
const iButtonKey* key,
|
||||
FuriString* result);
|
||||
|
||||
/**
|
||||
* Check whether the key data is valid
|
||||
* @param [in] protocols pointer to an iButtonProtocols object
|
||||
* @param [in] key pointer to the key to be checked
|
||||
* @return true if data is valid, false otherwise
|
||||
*/
|
||||
bool ibutton_protocols_is_valid(iButtonProtocols* protocols, const iButtonKey* key);
|
||||
|
||||
/**
|
||||
* Get a pointer to the key's editable data (for in-place editing)
|
||||
* @param [in] protocols pointer to an iButtonProtocols object
|
||||
* @param [in] key pointer to the key to be checked
|
||||
* @param [out] editable pointer to a structure to contain the editable data
|
||||
*/
|
||||
void ibutton_protocols_get_editable_data(
|
||||
iButtonProtocols* protocols,
|
||||
const iButtonKey* key,
|
||||
iButtonEditableData* editable);
|
||||
|
||||
/**
|
||||
* Make all necessary internal adjustments after editing the key
|
||||
* @param [in] protocols pointer to an iButtonProtocols object
|
||||
* @param [in,out] key pointer to the key to be adjusted
|
||||
*/
|
||||
void ibutton_protocols_apply_edits(iButtonProtocols* protocols, const iButtonKey* key);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -1,13 +1,14 @@
|
|||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <atomic.h>
|
||||
#include "ibutton_worker_i.h"
|
||||
#include "ibutton_protocols.h"
|
||||
|
||||
#include <core/check.h>
|
||||
|
||||
typedef enum {
|
||||
iButtonMessageEnd,
|
||||
iButtonMessageStop,
|
||||
iButtonMessageRead,
|
||||
iButtonMessageWrite,
|
||||
iButtonMessageWriteBlank,
|
||||
iButtonMessageWriteCopy,
|
||||
iButtonMessageEmulate,
|
||||
iButtonMessageNotifyEmulate,
|
||||
} iButtonMessageType;
|
||||
|
@ -21,26 +22,15 @@ typedef struct {
|
|||
|
||||
static int32_t ibutton_worker_thread(void* thread_context);
|
||||
|
||||
iButtonWorker* ibutton_worker_alloc() {
|
||||
iButtonWorker* ibutton_worker_alloc(iButtonProtocols* protocols) {
|
||||
iButtonWorker* worker = malloc(sizeof(iButtonWorker));
|
||||
worker->key_p = NULL;
|
||||
worker->key_data = malloc(ibutton_key_get_max_size());
|
||||
worker->host = onewire_host_alloc(&ibutton_gpio);
|
||||
worker->slave = onewire_slave_alloc(&ibutton_gpio);
|
||||
worker->writer = ibutton_writer_alloc(worker->host);
|
||||
worker->device = onewire_device_alloc(0, 0, 0, 0, 0, 0, 0, 0);
|
||||
|
||||
worker->protocols = protocols;
|
||||
worker->messages = furi_message_queue_alloc(1, sizeof(iButtonMessage));
|
||||
|
||||
worker->mode_index = iButtonWorkerIdle;
|
||||
worker->read_cb = NULL;
|
||||
worker->write_cb = NULL;
|
||||
worker->emulate_cb = NULL;
|
||||
worker->cb_ctx = NULL;
|
||||
|
||||
worker->mode_index = iButtonWorkerModeIdle;
|
||||
worker->thread = furi_thread_alloc_ex("iButtonWorker", 2048, ibutton_worker_thread, worker);
|
||||
|
||||
worker->protocols = protocol_dict_alloc(ibutton_protocols, iButtonProtocolMax);
|
||||
|
||||
return worker;
|
||||
}
|
||||
|
||||
|
@ -48,7 +38,7 @@ void ibutton_worker_read_set_callback(
|
|||
iButtonWorker* worker,
|
||||
iButtonWorkerReadCallback callback,
|
||||
void* context) {
|
||||
furi_check(worker->mode_index == iButtonWorkerIdle);
|
||||
furi_check(worker->mode_index == iButtonWorkerModeIdle);
|
||||
worker->read_cb = callback;
|
||||
worker->cb_ctx = context;
|
||||
}
|
||||
|
@ -57,7 +47,7 @@ void ibutton_worker_write_set_callback(
|
|||
iButtonWorker* worker,
|
||||
iButtonWorkerWriteCallback callback,
|
||||
void* context) {
|
||||
furi_check(worker->mode_index == iButtonWorkerIdle);
|
||||
furi_check(worker->mode_index == iButtonWorkerModeIdle);
|
||||
worker->write_cb = callback;
|
||||
worker->cb_ctx = context;
|
||||
}
|
||||
|
@ -66,7 +56,7 @@ void ibutton_worker_emulate_set_callback(
|
|||
iButtonWorker* worker,
|
||||
iButtonWorkerEmulateCallback callback,
|
||||
void* context) {
|
||||
furi_check(worker->mode_index == iButtonWorkerIdle);
|
||||
furi_check(worker->mode_index == iButtonWorkerModeIdle);
|
||||
worker->emulate_cb = callback;
|
||||
worker->cb_ctx = context;
|
||||
}
|
||||
|
@ -77,8 +67,14 @@ void ibutton_worker_read_start(iButtonWorker* worker, iButtonKey* key) {
|
|||
furi_message_queue_put(worker->messages, &message, FuriWaitForever) == FuriStatusOk);
|
||||
}
|
||||
|
||||
void ibutton_worker_write_start(iButtonWorker* worker, iButtonKey* key) {
|
||||
iButtonMessage message = {.type = iButtonMessageWrite, .data.key = key};
|
||||
void ibutton_worker_write_blank_start(iButtonWorker* worker, iButtonKey* key) {
|
||||
iButtonMessage message = {.type = iButtonMessageWriteBlank, .data.key = key};
|
||||
furi_check(
|
||||
furi_message_queue_put(worker->messages, &message, FuriWaitForever) == FuriStatusOk);
|
||||
}
|
||||
|
||||
void ibutton_worker_write_copy_start(iButtonWorker* worker, iButtonKey* key) {
|
||||
iButtonMessage message = {.type = iButtonMessageWriteCopy, .data.key = key};
|
||||
furi_check(
|
||||
furi_message_queue_put(worker->messages, &message, FuriWaitForever) == FuriStatusOk);
|
||||
}
|
||||
|
@ -96,19 +92,8 @@ void ibutton_worker_stop(iButtonWorker* worker) {
|
|||
}
|
||||
|
||||
void ibutton_worker_free(iButtonWorker* worker) {
|
||||
ibutton_writer_free(worker->writer);
|
||||
|
||||
onewire_slave_free(worker->slave);
|
||||
|
||||
onewire_host_free(worker->host);
|
||||
onewire_device_free(worker->device);
|
||||
|
||||
protocol_dict_free(worker->protocols);
|
||||
|
||||
furi_message_queue_free(worker->messages);
|
||||
|
||||
furi_thread_free(worker->thread);
|
||||
free(worker->key_data);
|
||||
free(worker);
|
||||
}
|
||||
|
||||
|
@ -137,7 +122,7 @@ void ibutton_worker_notify_emulate(iButtonWorker* worker) {
|
|||
}
|
||||
|
||||
void ibutton_worker_set_key_p(iButtonWorker* worker, iButtonKey* key) {
|
||||
worker->key_p = key;
|
||||
worker->key = key;
|
||||
}
|
||||
|
||||
static int32_t ibutton_worker_thread(void* thread_context) {
|
||||
|
@ -154,25 +139,29 @@ static int32_t ibutton_worker_thread(void* thread_context) {
|
|||
if(status == FuriStatusOk) {
|
||||
switch(message.type) {
|
||||
case iButtonMessageEnd:
|
||||
ibutton_worker_switch_mode(worker, iButtonWorkerIdle);
|
||||
ibutton_worker_switch_mode(worker, iButtonWorkerModeIdle);
|
||||
ibutton_worker_set_key_p(worker, NULL);
|
||||
running = false;
|
||||
break;
|
||||
case iButtonMessageStop:
|
||||
ibutton_worker_switch_mode(worker, iButtonWorkerIdle);
|
||||
ibutton_worker_switch_mode(worker, iButtonWorkerModeIdle);
|
||||
ibutton_worker_set_key_p(worker, NULL);
|
||||
break;
|
||||
case iButtonMessageRead:
|
||||
ibutton_worker_set_key_p(worker, message.data.key);
|
||||
ibutton_worker_switch_mode(worker, iButtonWorkerRead);
|
||||
ibutton_worker_switch_mode(worker, iButtonWorkerModeRead);
|
||||
break;
|
||||
case iButtonMessageWrite:
|
||||
case iButtonMessageWriteBlank:
|
||||
ibutton_worker_set_key_p(worker, message.data.key);
|
||||
ibutton_worker_switch_mode(worker, iButtonWorkerWrite);
|
||||
ibutton_worker_switch_mode(worker, iButtonWorkerModeWriteBlank);
|
||||
break;
|
||||
case iButtonMessageWriteCopy:
|
||||
ibutton_worker_set_key_p(worker, message.data.key);
|
||||
ibutton_worker_switch_mode(worker, iButtonWorkerModeWriteCopy);
|
||||
break;
|
||||
case iButtonMessageEmulate:
|
||||
ibutton_worker_set_key_p(worker, message.data.key);
|
||||
ibutton_worker_switch_mode(worker, iButtonWorkerEmulate);
|
||||
ibutton_worker_switch_mode(worker, iButtonWorkerModeEmulate);
|
||||
break;
|
||||
case iButtonMessageNotifyEmulate:
|
||||
if(worker->emulate_cb) {
|
||||
|
|
|
@ -5,7 +5,9 @@
|
|||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ibutton_key.h"
|
||||
#include "ibutton_protocols.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -28,7 +30,7 @@ typedef struct iButtonWorker iButtonWorker;
|
|||
* Allocate ibutton worker
|
||||
* @return iButtonWorker*
|
||||
*/
|
||||
iButtonWorker* ibutton_worker_alloc();
|
||||
iButtonWorker* ibutton_worker_alloc(iButtonProtocols* protocols);
|
||||
|
||||
/**
|
||||
* Free ibutton worker
|
||||
|
@ -78,11 +80,18 @@ void ibutton_worker_write_set_callback(
|
|||
void* context);
|
||||
|
||||
/**
|
||||
* Start write mode
|
||||
* Start write blank mode
|
||||
* @param worker
|
||||
* @param key
|
||||
*/
|
||||
void ibutton_worker_write_start(iButtonWorker* worker, iButtonKey* key);
|
||||
void ibutton_worker_write_blank_start(iButtonWorker* worker, iButtonKey* key);
|
||||
|
||||
/**
|
||||
* Start write copy mode
|
||||
* @param worker
|
||||
* @param key
|
||||
*/
|
||||
void ibutton_worker_write_copy_start(iButtonWorker* worker, iButtonKey* key);
|
||||
|
||||
/**
|
||||
* Set "emulate success" callback
|
||||
|
|
|
@ -5,13 +5,11 @@
|
|||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <core/thread.h>
|
||||
#include <core/message_queue.h>
|
||||
|
||||
#include "ibutton_worker.h"
|
||||
#include "ibutton_writer.h"
|
||||
#include "../one_wire_host.h"
|
||||
#include "../one_wire_slave.h"
|
||||
#include "../one_wire_device.h"
|
||||
#include <toolbox/protocols/protocol_dict.h>
|
||||
#include "protocols/ibutton_protocols.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -25,19 +23,16 @@ typedef struct {
|
|||
} iButtonWorkerModeType;
|
||||
|
||||
typedef enum {
|
||||
iButtonWorkerIdle = 0,
|
||||
iButtonWorkerRead = 1,
|
||||
iButtonWorkerWrite = 2,
|
||||
iButtonWorkerEmulate = 3,
|
||||
iButtonWorkerModeIdle,
|
||||
iButtonWorkerModeRead,
|
||||
iButtonWorkerModeWriteBlank,
|
||||
iButtonWorkerModeWriteCopy,
|
||||
iButtonWorkerModeEmulate,
|
||||
} iButtonWorkerMode;
|
||||
|
||||
struct iButtonWorker {
|
||||
iButtonKey* key_p;
|
||||
uint8_t* key_data;
|
||||
OneWireHost* host;
|
||||
OneWireSlave* slave;
|
||||
OneWireDevice* device;
|
||||
iButtonWriter* writer;
|
||||
iButtonKey* key;
|
||||
iButtonProtocols* protocols;
|
||||
iButtonWorkerMode mode_index;
|
||||
FuriMessageQueue* messages;
|
||||
FuriThread* thread;
|
||||
|
@ -45,10 +40,8 @@ struct iButtonWorker {
|
|||
iButtonWorkerReadCallback read_cb;
|
||||
iButtonWorkerWriteCallback write_cb;
|
||||
iButtonWorkerEmulateCallback emulate_cb;
|
||||
void* cb_ctx;
|
||||
|
||||
ProtocolDict* protocols;
|
||||
iButtonProtocol protocol_to_encode;
|
||||
void* cb_ctx;
|
||||
};
|
||||
|
||||
extern const iButtonWorkerModeType ibutton_worker_modes[];
|
||||
|
|
|
@ -1,23 +1,28 @@
|
|||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include "ibutton_worker_i.h"
|
||||
#include "ibutton_key_command.h"
|
||||
|
||||
void ibutton_worker_mode_idle_start(iButtonWorker* worker);
|
||||
void ibutton_worker_mode_idle_tick(iButtonWorker* worker);
|
||||
void ibutton_worker_mode_idle_stop(iButtonWorker* worker);
|
||||
#include <core/check.h>
|
||||
|
||||
void ibutton_worker_mode_emulate_start(iButtonWorker* worker);
|
||||
void ibutton_worker_mode_emulate_tick(iButtonWorker* worker);
|
||||
void ibutton_worker_mode_emulate_stop(iButtonWorker* worker);
|
||||
#include <furi_hal_rfid.h>
|
||||
#include <furi_hal_power.h>
|
||||
|
||||
void ibutton_worker_mode_read_start(iButtonWorker* worker);
|
||||
void ibutton_worker_mode_read_tick(iButtonWorker* worker);
|
||||
void ibutton_worker_mode_read_stop(iButtonWorker* worker);
|
||||
#include "ibutton_protocols.h"
|
||||
|
||||
void ibutton_worker_mode_write_start(iButtonWorker* worker);
|
||||
void ibutton_worker_mode_write_tick(iButtonWorker* worker);
|
||||
void ibutton_worker_mode_write_stop(iButtonWorker* worker);
|
||||
static void ibutton_worker_mode_idle_start(iButtonWorker* worker);
|
||||
static void ibutton_worker_mode_idle_tick(iButtonWorker* worker);
|
||||
static void ibutton_worker_mode_idle_stop(iButtonWorker* worker);
|
||||
|
||||
static void ibutton_worker_mode_emulate_start(iButtonWorker* worker);
|
||||
static void ibutton_worker_mode_emulate_tick(iButtonWorker* worker);
|
||||
static void ibutton_worker_mode_emulate_stop(iButtonWorker* worker);
|
||||
|
||||
static void ibutton_worker_mode_read_start(iButtonWorker* worker);
|
||||
static void ibutton_worker_mode_read_tick(iButtonWorker* worker);
|
||||
static void ibutton_worker_mode_read_stop(iButtonWorker* worker);
|
||||
|
||||
static void ibutton_worker_mode_write_common_start(iButtonWorker* worker);
|
||||
static void ibutton_worker_mode_write_blank_tick(iButtonWorker* worker);
|
||||
static void ibutton_worker_mode_write_copy_tick(iButtonWorker* worker);
|
||||
static void ibutton_worker_mode_write_common_stop(iButtonWorker* worker);
|
||||
|
||||
const iButtonWorkerModeType ibutton_worker_modes[] = {
|
||||
{
|
||||
|
@ -34,9 +39,15 @@ const iButtonWorkerModeType ibutton_worker_modes[] = {
|
|||
},
|
||||
{
|
||||
.quant = 1000,
|
||||
.start = ibutton_worker_mode_write_start,
|
||||
.tick = ibutton_worker_mode_write_tick,
|
||||
.stop = ibutton_worker_mode_write_stop,
|
||||
.start = ibutton_worker_mode_write_common_start,
|
||||
.tick = ibutton_worker_mode_write_blank_tick,
|
||||
.stop = ibutton_worker_mode_write_common_stop,
|
||||
},
|
||||
{
|
||||
.quant = 1000,
|
||||
.start = ibutton_worker_mode_write_common_start,
|
||||
.tick = ibutton_worker_mode_write_copy_tick,
|
||||
.stop = ibutton_worker_mode_write_common_stop,
|
||||
},
|
||||
{
|
||||
.quant = 1000,
|
||||
|
@ -62,143 +73,18 @@ void ibutton_worker_mode_idle_stop(iButtonWorker* worker) {
|
|||
|
||||
/*********************** READ ***********************/
|
||||
|
||||
typedef struct {
|
||||
uint32_t last_dwt_value;
|
||||
FuriStreamBuffer* stream;
|
||||
} iButtonReadContext;
|
||||
|
||||
void ibutton_worker_comparator_callback(bool level, void* context) {
|
||||
iButtonReadContext* read_context = context;
|
||||
|
||||
uint32_t current_dwt_value = DWT->CYCCNT;
|
||||
|
||||
LevelDuration data =
|
||||
level_duration_make(level, current_dwt_value - read_context->last_dwt_value);
|
||||
furi_stream_buffer_send(read_context->stream, &data, sizeof(LevelDuration), 0);
|
||||
|
||||
read_context->last_dwt_value = current_dwt_value;
|
||||
}
|
||||
|
||||
bool ibutton_worker_read_comparator(iButtonWorker* worker) {
|
||||
bool result = false;
|
||||
|
||||
protocol_dict_decoders_start(worker->protocols);
|
||||
|
||||
furi_hal_rfid_pins_reset();
|
||||
// pulldown pull pin, we sense the signal through the analog part of the RFID schematic
|
||||
furi_hal_rfid_pin_pull_pulldown();
|
||||
|
||||
iButtonReadContext read_context = {
|
||||
.last_dwt_value = DWT->CYCCNT,
|
||||
.stream = furi_stream_buffer_alloc(sizeof(LevelDuration) * 512, 1),
|
||||
};
|
||||
|
||||
furi_hal_rfid_comp_set_callback(ibutton_worker_comparator_callback, &read_context);
|
||||
furi_hal_rfid_comp_start();
|
||||
|
||||
uint32_t tick_start = furi_get_tick();
|
||||
while(true) {
|
||||
LevelDuration level;
|
||||
size_t ret =
|
||||
furi_stream_buffer_receive(read_context.stream, &level, sizeof(LevelDuration), 100);
|
||||
|
||||
if((furi_get_tick() - tick_start) > 100) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(ret > 0) {
|
||||
ProtocolId decoded_index = protocol_dict_decoders_feed(
|
||||
worker->protocols,
|
||||
level_duration_get_level(level),
|
||||
level_duration_get_duration(level));
|
||||
|
||||
if(decoded_index == PROTOCOL_NO) continue;
|
||||
|
||||
protocol_dict_get_data(
|
||||
worker->protocols, decoded_index, worker->key_data, ibutton_key_get_max_size());
|
||||
|
||||
switch(decoded_index) {
|
||||
case iButtonProtocolCyfral:
|
||||
furi_check(worker->key_p != NULL);
|
||||
ibutton_key_set_type(worker->key_p, iButtonKeyCyfral);
|
||||
ibutton_key_set_data(worker->key_p, worker->key_data, ibutton_key_get_max_size());
|
||||
result = true;
|
||||
break;
|
||||
case iButtonProtocolMetakom:
|
||||
furi_check(worker->key_p != NULL);
|
||||
ibutton_key_set_type(worker->key_p, iButtonKeyMetakom);
|
||||
ibutton_key_set_data(worker->key_p, worker->key_data, ibutton_key_get_max_size());
|
||||
result = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
furi_hal_rfid_comp_stop();
|
||||
furi_hal_rfid_comp_set_callback(NULL, NULL);
|
||||
furi_hal_rfid_pins_reset();
|
||||
|
||||
furi_stream_buffer_free(read_context.stream);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ibutton_worker_read_dallas(iButtonWorker* worker) {
|
||||
bool result = false;
|
||||
onewire_host_start(worker->host);
|
||||
furi_delay_ms(100);
|
||||
FURI_CRITICAL_ENTER();
|
||||
if(onewire_host_search(worker->host, worker->key_data, NORMAL_SEARCH)) {
|
||||
onewire_host_reset_search(worker->host);
|
||||
|
||||
// key found, verify
|
||||
if(onewire_host_reset(worker->host)) {
|
||||
onewire_host_write(worker->host, DS1990_CMD_READ_ROM);
|
||||
bool key_valid = true;
|
||||
for(uint8_t i = 0; i < ibutton_key_get_max_size(); i++) {
|
||||
if(onewire_host_read(worker->host) != worker->key_data[i]) {
|
||||
key_valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(key_valid) {
|
||||
result = true;
|
||||
|
||||
furi_check(worker->key_p != NULL);
|
||||
ibutton_key_set_type(worker->key_p, iButtonKeyDS1990);
|
||||
ibutton_key_set_data(worker->key_p, worker->key_data, ibutton_key_get_max_size());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
onewire_host_reset_search(worker->host);
|
||||
}
|
||||
onewire_host_stop(worker->host);
|
||||
FURI_CRITICAL_EXIT();
|
||||
return result;
|
||||
}
|
||||
|
||||
void ibutton_worker_mode_read_start(iButtonWorker* worker) {
|
||||
UNUSED(worker);
|
||||
furi_hal_power_enable_otg();
|
||||
}
|
||||
|
||||
void ibutton_worker_mode_read_tick(iButtonWorker* worker) {
|
||||
bool valid = false;
|
||||
if(ibutton_worker_read_dallas(worker)) {
|
||||
valid = true;
|
||||
} else if(ibutton_worker_read_comparator(worker)) {
|
||||
valid = true;
|
||||
}
|
||||
|
||||
if(valid) {
|
||||
if(ibutton_protocols_read(worker->protocols, worker->key)) {
|
||||
if(worker->read_cb != NULL) {
|
||||
worker->read_cb(worker->cb_ctx);
|
||||
}
|
||||
|
||||
ibutton_worker_switch_mode(worker, iButtonWorkerIdle);
|
||||
ibutton_worker_switch_mode(worker, iButtonWorkerModeIdle);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -208,83 +94,14 @@ void ibutton_worker_mode_read_stop(iButtonWorker* worker) {
|
|||
}
|
||||
|
||||
/*********************** EMULATE ***********************/
|
||||
static void onewire_slave_callback(void* context) {
|
||||
furi_assert(context);
|
||||
iButtonWorker* worker = context;
|
||||
ibutton_worker_notify_emulate(worker);
|
||||
}
|
||||
|
||||
void ibutton_worker_emulate_dallas_start(iButtonWorker* worker) {
|
||||
uint8_t* device_id = onewire_device_get_id_p(worker->device);
|
||||
const uint8_t* key_id = ibutton_key_get_data_p(worker->key_p);
|
||||
const uint8_t key_size = ibutton_key_get_max_size();
|
||||
memcpy(device_id, key_id, key_size);
|
||||
|
||||
onewire_slave_attach(worker->slave, worker->device);
|
||||
onewire_slave_set_result_callback(worker->slave, onewire_slave_callback, worker);
|
||||
onewire_slave_start(worker->slave);
|
||||
}
|
||||
|
||||
void ibutton_worker_emulate_dallas_stop(iButtonWorker* worker) {
|
||||
onewire_slave_stop(worker->slave);
|
||||
onewire_slave_detach(worker->slave);
|
||||
}
|
||||
|
||||
void ibutton_worker_emulate_timer_cb(void* context) {
|
||||
furi_assert(context);
|
||||
iButtonWorker* worker = context;
|
||||
|
||||
const LevelDuration level_duration =
|
||||
protocol_dict_encoder_yield(worker->protocols, worker->protocol_to_encode);
|
||||
|
||||
furi_hal_ibutton_emulate_set_next(level_duration_get_duration(level_duration));
|
||||
furi_hal_ibutton_pin_write(level_duration_get_level(level_duration));
|
||||
}
|
||||
|
||||
void ibutton_worker_emulate_timer_start(iButtonWorker* worker) {
|
||||
furi_assert(worker->key_p);
|
||||
const uint8_t* key_id = ibutton_key_get_data_p(worker->key_p);
|
||||
const uint8_t key_size = ibutton_key_get_max_size();
|
||||
|
||||
switch(ibutton_key_get_type(worker->key_p)) {
|
||||
case iButtonKeyDS1990:
|
||||
return;
|
||||
break;
|
||||
case iButtonKeyCyfral:
|
||||
worker->protocol_to_encode = iButtonProtocolCyfral;
|
||||
break;
|
||||
case iButtonKeyMetakom:
|
||||
worker->protocol_to_encode = iButtonProtocolMetakom;
|
||||
break;
|
||||
}
|
||||
|
||||
protocol_dict_set_data(worker->protocols, worker->protocol_to_encode, key_id, key_size);
|
||||
protocol_dict_encoder_start(worker->protocols, worker->protocol_to_encode);
|
||||
|
||||
furi_hal_ibutton_pin_configure();
|
||||
furi_hal_ibutton_emulate_start(0, ibutton_worker_emulate_timer_cb, worker);
|
||||
}
|
||||
|
||||
void ibutton_worker_emulate_timer_stop(iButtonWorker* worker) {
|
||||
UNUSED(worker);
|
||||
furi_hal_ibutton_emulate_stop();
|
||||
}
|
||||
|
||||
void ibutton_worker_mode_emulate_start(iButtonWorker* worker) {
|
||||
furi_assert(worker->key_p);
|
||||
furi_assert(worker->key);
|
||||
|
||||
furi_hal_rfid_pins_reset();
|
||||
furi_hal_rfid_pin_pull_pulldown();
|
||||
|
||||
switch(ibutton_key_get_type(worker->key_p)) {
|
||||
case iButtonKeyDS1990:
|
||||
ibutton_worker_emulate_dallas_start(worker);
|
||||
break;
|
||||
case iButtonKeyCyfral:
|
||||
case iButtonKeyMetakom:
|
||||
ibutton_worker_emulate_timer_start(worker);
|
||||
break;
|
||||
}
|
||||
ibutton_protocols_emulate_start(worker->protocols, worker->key);
|
||||
}
|
||||
|
||||
void ibutton_worker_mode_emulate_tick(iButtonWorker* worker) {
|
||||
|
@ -292,56 +109,45 @@ void ibutton_worker_mode_emulate_tick(iButtonWorker* worker) {
|
|||
}
|
||||
|
||||
void ibutton_worker_mode_emulate_stop(iButtonWorker* worker) {
|
||||
furi_assert(worker->key_p);
|
||||
furi_assert(worker->key);
|
||||
|
||||
ibutton_protocols_emulate_stop(worker->protocols, worker->key);
|
||||
|
||||
furi_hal_rfid_pins_reset();
|
||||
|
||||
switch(ibutton_key_get_type(worker->key_p)) {
|
||||
case iButtonKeyDS1990:
|
||||
ibutton_worker_emulate_dallas_stop(worker);
|
||||
break;
|
||||
case iButtonKeyCyfral:
|
||||
case iButtonKeyMetakom:
|
||||
ibutton_worker_emulate_timer_stop(worker);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*********************** WRITE ***********************/
|
||||
|
||||
void ibutton_worker_mode_write_start(iButtonWorker* worker) {
|
||||
void ibutton_worker_mode_write_common_start(iButtonWorker* worker) { //-V524
|
||||
UNUSED(worker);
|
||||
furi_hal_power_enable_otg();
|
||||
onewire_host_start(worker->host);
|
||||
}
|
||||
|
||||
void ibutton_worker_mode_write_tick(iButtonWorker* worker) {
|
||||
furi_check(worker->key_p != NULL);
|
||||
iButtonWriterResult writer_result = ibutton_writer_write(worker->writer, worker->key_p);
|
||||
iButtonWorkerWriteResult result;
|
||||
switch(writer_result) {
|
||||
case iButtonWriterOK:
|
||||
result = iButtonWorkerWriteOK;
|
||||
break;
|
||||
case iButtonWriterSameKey:
|
||||
result = iButtonWorkerWriteSameKey;
|
||||
break;
|
||||
case iButtonWriterNoDetect:
|
||||
result = iButtonWorkerWriteNoDetect;
|
||||
break;
|
||||
case iButtonWriterCannotWrite:
|
||||
result = iButtonWorkerWriteCannotWrite;
|
||||
break;
|
||||
default:
|
||||
result = iButtonWorkerWriteNoDetect;
|
||||
break;
|
||||
}
|
||||
void ibutton_worker_mode_write_blank_tick(iButtonWorker* worker) {
|
||||
furi_assert(worker->key);
|
||||
|
||||
const bool success = ibutton_protocols_write_blank(worker->protocols, worker->key);
|
||||
// TODO: pass a proper result to the callback
|
||||
const iButtonWorkerWriteResult result = success ? iButtonWorkerWriteOK :
|
||||
iButtonWorkerWriteNoDetect;
|
||||
if(worker->write_cb != NULL) {
|
||||
worker->write_cb(worker->cb_ctx, result);
|
||||
}
|
||||
}
|
||||
|
||||
void ibutton_worker_mode_write_stop(iButtonWorker* worker) {
|
||||
furi_hal_power_disable_otg();
|
||||
onewire_host_stop(worker->host);
|
||||
void ibutton_worker_mode_write_copy_tick(iButtonWorker* worker) {
|
||||
furi_assert(worker->key);
|
||||
|
||||
const bool success = ibutton_protocols_write_copy(worker->protocols, worker->key);
|
||||
// TODO: pass a proper result to the callback
|
||||
const iButtonWorkerWriteResult result = success ? iButtonWorkerWriteOK :
|
||||
iButtonWorkerWriteNoDetect;
|
||||
if(worker->write_cb != NULL) {
|
||||
worker->write_cb(worker->cb_ctx, result);
|
||||
}
|
||||
}
|
||||
|
||||
void ibutton_worker_mode_write_common_stop(iButtonWorker* worker) { //-V524
|
||||
UNUSED(worker);
|
||||
furi_hal_power_disable_otg();
|
||||
}
|
||||
|
|
|
@ -1,298 +0,0 @@
|
|||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include "ibutton_writer.h"
|
||||
#include "ibutton_key_command.h"
|
||||
|
||||
/*********************** PRIVATE ***********************/
|
||||
|
||||
struct iButtonWriter {
|
||||
OneWireHost* host;
|
||||
};
|
||||
|
||||
static void writer_write_one_bit(iButtonWriter* writer, bool value, uint32_t delay) {
|
||||
onewire_host_write_bit(writer->host, value);
|
||||
furi_delay_us(delay);
|
||||
}
|
||||
|
||||
static void writer_write_byte_ds1990(iButtonWriter* writer, uint8_t data) {
|
||||
for(uint8_t n_bit = 0; n_bit < 8; n_bit++) {
|
||||
onewire_host_write_bit(writer->host, data & 1);
|
||||
furi_delay_us(5000);
|
||||
data = data >> 1;
|
||||
}
|
||||
}
|
||||
|
||||
static bool writer_compare_key_ds1990(iButtonWriter* writer, iButtonKey* key) {
|
||||
bool result = false;
|
||||
|
||||
if(ibutton_key_get_type(key) == iButtonKeyDS1990) {
|
||||
FURI_CRITICAL_ENTER();
|
||||
bool presence = onewire_host_reset(writer->host);
|
||||
|
||||
if(presence) {
|
||||
onewire_host_write(writer->host, DS1990_CMD_READ_ROM);
|
||||
|
||||
result = true;
|
||||
for(uint8_t i = 0; i < ibutton_key_get_data_size(key); i++) {
|
||||
if(ibutton_key_get_data_p(key)[i] != onewire_host_read(writer->host)) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FURI_CRITICAL_EXIT();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool writer_write_TM2004(iButtonWriter* writer, iButtonKey* key) {
|
||||
uint8_t answer;
|
||||
bool result = true;
|
||||
|
||||
if(ibutton_key_get_type(key) == iButtonKeyDS1990) {
|
||||
FURI_CRITICAL_ENTER();
|
||||
|
||||
// write rom, addr is 0x0000
|
||||
onewire_host_reset(writer->host);
|
||||
onewire_host_write(writer->host, TM2004_CMD_WRITE_ROM);
|
||||
onewire_host_write(writer->host, 0x00);
|
||||
onewire_host_write(writer->host, 0x00);
|
||||
|
||||
// write key
|
||||
for(uint8_t i = 0; i < ibutton_key_get_data_size(key); i++) {
|
||||
// write key byte
|
||||
onewire_host_write(writer->host, ibutton_key_get_data_p(key)[i]);
|
||||
answer = onewire_host_read(writer->host);
|
||||
// TODO: check answer CRC
|
||||
|
||||
// pulse indicating that data is correct
|
||||
furi_delay_us(600);
|
||||
writer_write_one_bit(writer, 1, 50000);
|
||||
|
||||
// read written key byte
|
||||
answer = onewire_host_read(writer->host); //-V519
|
||||
|
||||
// check that written and read are same
|
||||
if(ibutton_key_get_data_p(key)[i] != answer) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!writer_compare_key_ds1990(writer, key)) {
|
||||
result = false;
|
||||
}
|
||||
|
||||
onewire_host_reset(writer->host);
|
||||
|
||||
FURI_CRITICAL_EXIT();
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool writer_write_1990_1(iButtonWriter* writer, iButtonKey* key) {
|
||||
bool result = false;
|
||||
|
||||
if(ibutton_key_get_type(key) == iButtonKeyDS1990) {
|
||||
FURI_CRITICAL_ENTER();
|
||||
|
||||
// unlock
|
||||
onewire_host_reset(writer->host);
|
||||
onewire_host_write(writer->host, RW1990_1_CMD_WRITE_RECORD_FLAG);
|
||||
furi_delay_us(10);
|
||||
writer_write_one_bit(writer, 0, 5000);
|
||||
|
||||
// write key
|
||||
onewire_host_reset(writer->host);
|
||||
onewire_host_write(writer->host, RW1990_1_CMD_WRITE_ROM);
|
||||
for(uint8_t i = 0; i < ibutton_key_get_data_size(key); i++) {
|
||||
// inverted key for RW1990.1
|
||||
writer_write_byte_ds1990(writer, ~ibutton_key_get_data_p(key)[i]);
|
||||
furi_delay_us(30000);
|
||||
}
|
||||
|
||||
// lock
|
||||
onewire_host_write(writer->host, RW1990_1_CMD_WRITE_RECORD_FLAG);
|
||||
writer_write_one_bit(writer, 1, 10000);
|
||||
|
||||
FURI_CRITICAL_EXIT();
|
||||
|
||||
if(writer_compare_key_ds1990(writer, key)) {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool writer_write_1990_2(iButtonWriter* writer, iButtonKey* key) {
|
||||
bool result = false;
|
||||
|
||||
if(ibutton_key_get_type(key) == iButtonKeyDS1990) {
|
||||
FURI_CRITICAL_ENTER();
|
||||
|
||||
// unlock
|
||||
onewire_host_reset(writer->host);
|
||||
onewire_host_write(writer->host, RW1990_2_CMD_WRITE_RECORD_FLAG);
|
||||
furi_delay_us(10);
|
||||
writer_write_one_bit(writer, 1, 5000);
|
||||
|
||||
// write key
|
||||
onewire_host_reset(writer->host);
|
||||
onewire_host_write(writer->host, RW1990_2_CMD_WRITE_ROM);
|
||||
for(uint8_t i = 0; i < ibutton_key_get_data_size(key); i++) {
|
||||
writer_write_byte_ds1990(writer, ibutton_key_get_data_p(key)[i]);
|
||||
furi_delay_us(30000);
|
||||
}
|
||||
|
||||
// lock
|
||||
onewire_host_write(writer->host, RW1990_2_CMD_WRITE_RECORD_FLAG);
|
||||
writer_write_one_bit(writer, 0, 10000);
|
||||
|
||||
FURI_CRITICAL_EXIT();
|
||||
|
||||
if(writer_compare_key_ds1990(writer, key)) {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
// TODO: adapt and test
|
||||
static bool writer_write_TM01(
|
||||
iButtonWriter* writer,
|
||||
iButtonKey type,
|
||||
const uint8_t* key,
|
||||
uint8_t key_length) {
|
||||
bool result = true;
|
||||
|
||||
{
|
||||
// TODO test and encoding
|
||||
FURI_CRITICAL_ENTER();
|
||||
|
||||
// unlock
|
||||
onewire_host_reset(writer->host);
|
||||
onewire_host_write(writer->host, TM01::CMD_WRITE_RECORD_FLAG);
|
||||
onewire_write_one_bit(1, 10000);
|
||||
|
||||
// write key
|
||||
onewire_host_reset(writer->host);
|
||||
onewire_host_write(writer->host, TM01::CMD_WRITE_ROM);
|
||||
|
||||
// TODO: key types
|
||||
//if(type == KEY_METAKOM || type == KEY_CYFRAL) {
|
||||
//} else {
|
||||
for(uint8_t i = 0; i < key->get_type_data_size(); i++) {
|
||||
write_byte_ds1990(key->get_data()[i]);
|
||||
furi_delay_us(10000);
|
||||
}
|
||||
//}
|
||||
|
||||
// lock
|
||||
onewire_host_write(writer->host, TM01::CMD_WRITE_RECORD_FLAG);
|
||||
onewire_write_one_bit(0, 10000);
|
||||
|
||||
FURI_CRITICAL_EXIT();
|
||||
}
|
||||
|
||||
if(!compare_key_ds1990(key)) {
|
||||
result = false;
|
||||
}
|
||||
|
||||
{
|
||||
FURI_CRITICAL_ENTER();
|
||||
|
||||
if(key->get_key_type() == iButtonKeyType::KeyMetakom ||
|
||||
key->get_key_type() == iButtonKeyType::KeyCyfral) {
|
||||
onewire_host_reset(writer->host);
|
||||
if(key->get_key_type() == iButtonKeyType::KeyCyfral)
|
||||
onewire_host_write(writer->host, TM01::CMD_SWITCH_TO_CYFRAL);
|
||||
else
|
||||
onewire_host_write(writer->host, TM01::CMD_SWITCH_TO_METAKOM);
|
||||
onewire_write_one_bit(1);
|
||||
}
|
||||
|
||||
FURI_CRITICAL_EXIT();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
*/
|
||||
|
||||
static iButtonWriterResult writer_write_DS1990(iButtonWriter* writer, iButtonKey* key) {
|
||||
iButtonWriterResult result = iButtonWriterNoDetect;
|
||||
bool same_key = writer_compare_key_ds1990(writer, key);
|
||||
|
||||
if(!same_key) {
|
||||
// currently we can write:
|
||||
// RW1990_1, TM08v2, TM08vi-2 by write_1990_1()
|
||||
// RW1990_2 by write_1990_2()
|
||||
// RW2004, RW2004, TM2004 with EEPROM by write_TM2004();
|
||||
|
||||
bool write_result = true;
|
||||
do {
|
||||
if(writer_write_1990_1(writer, key)) break;
|
||||
if(writer_write_1990_2(writer, key)) break;
|
||||
if(writer_write_TM2004(writer, key)) break;
|
||||
write_result = false;
|
||||
} while(false);
|
||||
|
||||
if(write_result) {
|
||||
result = iButtonWriterOK;
|
||||
} else {
|
||||
result = iButtonWriterCannotWrite;
|
||||
}
|
||||
} else {
|
||||
result = iButtonWriterSameKey;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*********************** PUBLIC ***********************/
|
||||
|
||||
iButtonWriter* ibutton_writer_alloc(OneWireHost* host) {
|
||||
iButtonWriter* writer = malloc(sizeof(iButtonWriter));
|
||||
writer->host = host;
|
||||
return writer;
|
||||
}
|
||||
|
||||
void ibutton_writer_free(iButtonWriter* writer) {
|
||||
free(writer);
|
||||
}
|
||||
|
||||
iButtonWriterResult ibutton_writer_write(iButtonWriter* writer, iButtonKey* key) {
|
||||
iButtonWriterResult result = iButtonWriterNoDetect;
|
||||
|
||||
furi_kernel_lock();
|
||||
bool blank_present = onewire_host_reset(writer->host);
|
||||
furi_kernel_unlock();
|
||||
|
||||
if(blank_present) {
|
||||
switch(ibutton_key_get_type(key)) {
|
||||
case iButtonKeyDS1990:
|
||||
result = writer_write_DS1990(writer, key);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void ibutton_writer_start(iButtonWriter* writer) {
|
||||
furi_hal_power_enable_otg();
|
||||
onewire_host_start(writer->host);
|
||||
}
|
||||
|
||||
void ibutton_writer_stop(iButtonWriter* writer) {
|
||||
onewire_host_stop(writer->host);
|
||||
furi_hal_power_disable_otg();
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
/**
|
||||
* @file ibutton_writer.h
|
||||
*
|
||||
* iButton blanks writer
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <furi_hal_gpio.h>
|
||||
#include "ibutton_key.h"
|
||||
#include "../one_wire_host.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
iButtonWriterOK,
|
||||
iButtonWriterSameKey,
|
||||
iButtonWriterNoDetect,
|
||||
iButtonWriterCannotWrite,
|
||||
} iButtonWriterResult;
|
||||
|
||||
typedef struct iButtonWriter iButtonWriter;
|
||||
|
||||
/**
|
||||
* Allocate writer
|
||||
* @param host
|
||||
* @return iButtonWriter*
|
||||
*/
|
||||
iButtonWriter* ibutton_writer_alloc(OneWireHost* host);
|
||||
|
||||
/**
|
||||
* Deallocate writer
|
||||
* @param writer
|
||||
*/
|
||||
void ibutton_writer_free(iButtonWriter* writer);
|
||||
|
||||
/**
|
||||
* Write key to blank
|
||||
* @param writer
|
||||
* @param key
|
||||
* @return iButtonWriterResult
|
||||
*/
|
||||
iButtonWriterResult ibutton_writer_write(iButtonWriter* writer, iButtonKey* key);
|
||||
|
||||
/**
|
||||
* Start writing. Must be called before write attempt
|
||||
* @param writer
|
||||
*/
|
||||
void ibutton_writer_start(iButtonWriter* writer);
|
||||
|
||||
/**
|
||||
* Stop writing
|
||||
* @param writer
|
||||
*/
|
||||
void ibutton_writer_stop(iButtonWriter* writer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
95
lib/one_wire/ibutton/protocols/blanks/rw1990.c
Normal file
95
lib/one_wire/ibutton/protocols/blanks/rw1990.c
Normal file
|
@ -0,0 +1,95 @@
|
|||
#include "rw1990.h"
|
||||
|
||||
#include <core/kernel.h>
|
||||
|
||||
#define RW1990_1_CMD_WRITE_RECORD_FLAG 0xD1
|
||||
#define RW1990_1_CMD_READ_RECORD_FLAG 0xB5
|
||||
#define RW1990_1_CMD_WRITE_ROM 0xD5
|
||||
|
||||
#define RW1990_2_CMD_WRITE_RECORD_FLAG 0x1D
|
||||
#define RW1990_2_CMD_READ_RECORD_FLAG 0x1E
|
||||
#define RW1990_2_CMD_WRITE_ROM 0xD5
|
||||
|
||||
#define DS1990_CMD_READ_ROM 0x33
|
||||
|
||||
static void rw1990_write_byte(OneWireHost* host, uint8_t value) {
|
||||
for(uint8_t bitMask = 0x01; bitMask; bitMask <<= 1) {
|
||||
onewire_host_write_bit(host, (bool)(bitMask & value));
|
||||
furi_delay_us(5000);
|
||||
}
|
||||
}
|
||||
|
||||
static bool rw1990_read_and_compare(OneWireHost* host, const uint8_t* data, size_t data_size) {
|
||||
bool success = false;
|
||||
|
||||
if(onewire_host_reset(host)) {
|
||||
success = true;
|
||||
onewire_host_write(host, DS1990_CMD_READ_ROM);
|
||||
|
||||
for(size_t i = 0; i < data_size; ++i) {
|
||||
if(data[i] != onewire_host_read(host)) {
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool rw1990_write_v1(OneWireHost* host, const uint8_t* data, size_t data_size) {
|
||||
// Unlock sequence
|
||||
onewire_host_reset(host);
|
||||
onewire_host_write(host, RW1990_1_CMD_WRITE_RECORD_FLAG);
|
||||
furi_delay_us(10);
|
||||
|
||||
onewire_host_write_bit(host, false);
|
||||
furi_delay_us(5000);
|
||||
|
||||
// Write data
|
||||
onewire_host_reset(host);
|
||||
onewire_host_write(host, RW1990_1_CMD_WRITE_ROM);
|
||||
|
||||
for(size_t i = 0; i < data_size; ++i) {
|
||||
// inverted key for RW1990.1
|
||||
rw1990_write_byte(host, ~(data[i]));
|
||||
furi_delay_us(30000);
|
||||
}
|
||||
|
||||
// Lock sequence
|
||||
onewire_host_write(host, RW1990_1_CMD_WRITE_RECORD_FLAG);
|
||||
|
||||
onewire_host_write_bit(host, true);
|
||||
furi_delay_us(10000);
|
||||
|
||||
// TODO: Better error handling
|
||||
return rw1990_read_and_compare(host, data, data_size);
|
||||
}
|
||||
|
||||
bool rw1990_write_v2(OneWireHost* host, const uint8_t* data, size_t data_size) {
|
||||
// Unlock sequence
|
||||
onewire_host_reset(host);
|
||||
onewire_host_write(host, RW1990_2_CMD_WRITE_RECORD_FLAG);
|
||||
furi_delay_us(10);
|
||||
|
||||
onewire_host_write_bit(host, true);
|
||||
furi_delay_us(5000);
|
||||
|
||||
// Write data
|
||||
onewire_host_reset(host);
|
||||
onewire_host_write(host, RW1990_2_CMD_WRITE_ROM);
|
||||
|
||||
for(size_t i = 0; i < data_size; ++i) {
|
||||
rw1990_write_byte(host, data[i]);
|
||||
furi_delay_us(30000);
|
||||
}
|
||||
|
||||
// Lock sequence
|
||||
onewire_host_write(host, RW1990_2_CMD_WRITE_RECORD_FLAG);
|
||||
|
||||
onewire_host_write_bit(host, false);
|
||||
furi_delay_us(10000);
|
||||
|
||||
// TODO: Better error handling
|
||||
return rw1990_read_and_compare(host, data, data_size);
|
||||
}
|
9
lib/one_wire/ibutton/protocols/blanks/rw1990.h
Normal file
9
lib/one_wire/ibutton/protocols/blanks/rw1990.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <one_wire/one_wire_host.h>
|
||||
|
||||
bool rw1990_write_v1(OneWireHost* host, const uint8_t* data, size_t data_size);
|
||||
|
||||
bool rw1990_write_v2(OneWireHost* host, const uint8_t* data, size_t data_size);
|
42
lib/one_wire/ibutton/protocols/blanks/tm2004.c
Normal file
42
lib/one_wire/ibutton/protocols/blanks/tm2004.c
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include "tm2004.h"
|
||||
|
||||
#include <core/kernel.h>
|
||||
|
||||
#define TM2004_CMD_READ_STATUS 0xAA
|
||||
#define TM2004_CMD_READ_MEMORY 0xF0
|
||||
#define TM2004_CMD_WRITE_ROM 0x3C
|
||||
#define TM2004_CMD_FINALIZATION 0x35
|
||||
#define TM2004_ANSWER_READ_MEMORY 0xF5
|
||||
|
||||
bool tm2004_write(OneWireHost* host, const uint8_t* data, size_t data_size) {
|
||||
onewire_host_reset(host);
|
||||
onewire_host_write(host, TM2004_CMD_WRITE_ROM);
|
||||
// Starting writing from address 0x0000
|
||||
onewire_host_write(host, 0x00);
|
||||
onewire_host_write(host, 0x00);
|
||||
|
||||
size_t i;
|
||||
for(i = 0; i < data_size; ++i) {
|
||||
uint8_t answer;
|
||||
|
||||
onewire_host_write(host, data[i]);
|
||||
answer = onewire_host_read(host);
|
||||
// TODO: check answer CRC
|
||||
|
||||
// pulse indicating that data is correct
|
||||
furi_delay_us(600);
|
||||
onewire_host_write_bit(host, true);
|
||||
furi_delay_us(50000);
|
||||
|
||||
// read written key byte
|
||||
answer = onewire_host_read(host); //-V519
|
||||
|
||||
// check that written and read are same
|
||||
if(data[i] != answer) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Better error handling
|
||||
return i == data_size;
|
||||
}
|
7
lib/one_wire/ibutton/protocols/blanks/tm2004.h
Normal file
7
lib/one_wire/ibutton/protocols/blanks/tm2004.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <one_wire/one_wire_host.h>
|
||||
|
||||
bool tm2004_write(OneWireHost* host, const uint8_t* data, size_t data_size);
|
250
lib/one_wire/ibutton/protocols/dallas/dallas_common.c
Normal file
250
lib/one_wire/ibutton/protocols/dallas/dallas_common.c
Normal file
|
@ -0,0 +1,250 @@
|
|||
#include "dallas_common.h"
|
||||
|
||||
#include <core/common_defines.h>
|
||||
#include <one_wire/maxim_crc.h>
|
||||
|
||||
#define BITS_IN_BYTE 8U
|
||||
|
||||
#define DALLAS_COMMON_ROM_DATA_KEY_V1 "Data"
|
||||
#define DALLAS_COMMON_ROM_DATA_KEY_V2 "Rom Data"
|
||||
|
||||
#define DALLAS_COMMON_COPY_SCRATCH_MIN_TIMEOUT_US 5U
|
||||
#define DALLAS_COMMON_COPY_SCRATCH_POLL_COUNT 20U
|
||||
|
||||
#define DALLAS_COMMON_END_ADDRESS_MASK 0x01F
|
||||
#define DALLAS_COMMON_STATUS_FLAG_PF (1U << 5)
|
||||
#define DALLAS_COMMON_STATUS_FLAG_OF (1U << 6)
|
||||
#define DALLAS_COMMON_STATUS_FLAG_AA (1U << 7)
|
||||
|
||||
#define DALLAS_COMMON_BRIEF_HEAD_COUNT 4U
|
||||
#define DALLAS_COMMON_BRIEF_TAIL_COUNT 3U
|
||||
|
||||
#define BITS_IN_BYTE 8U
|
||||
#define BITS_IN_KBIT 1024U
|
||||
|
||||
bool dallas_common_skip_rom(OneWireHost* host) {
|
||||
onewire_host_write(host, DALLAS_COMMON_CMD_SKIP_ROM);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool dallas_common_read_rom(OneWireHost* host, DallasCommonRomData* rom_data) {
|
||||
onewire_host_write(host, DALLAS_COMMON_CMD_READ_ROM);
|
||||
onewire_host_read_bytes(host, rom_data->bytes, sizeof(DallasCommonRomData));
|
||||
|
||||
return dallas_common_is_valid_crc(rom_data);
|
||||
}
|
||||
|
||||
bool dallas_common_write_scratchpad(
|
||||
OneWireHost* host,
|
||||
uint16_t address,
|
||||
const uint8_t* data,
|
||||
size_t data_size) {
|
||||
onewire_host_write(host, DALLAS_COMMON_CMD_WRITE_SCRATCH);
|
||||
onewire_host_write(host, (uint8_t)address);
|
||||
onewire_host_write(host, (uint8_t)(address >> BITS_IN_BYTE));
|
||||
|
||||
onewire_host_write_bytes(host, data, data_size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool dallas_common_read_scratchpad(
|
||||
OneWireHost* host,
|
||||
DallasCommonAddressRegs* regs,
|
||||
uint8_t* data,
|
||||
size_t data_size) {
|
||||
onewire_host_write(host, DALLAS_COMMON_CMD_READ_SCRATCH);
|
||||
onewire_host_read_bytes(host, regs->bytes, sizeof(DallasCommonAddressRegs));
|
||||
onewire_host_read_bytes(host, data, data_size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool dallas_common_copy_scratchpad(
|
||||
OneWireHost* host,
|
||||
const DallasCommonAddressRegs* regs,
|
||||
uint32_t timeout_us) {
|
||||
onewire_host_write(host, DALLAS_COMMON_CMD_COPY_SCRATCH);
|
||||
onewire_host_write_bytes(host, regs->bytes, sizeof(DallasCommonAddressRegs));
|
||||
|
||||
const uint32_t poll_delay =
|
||||
MAX(timeout_us / DALLAS_COMMON_COPY_SCRATCH_POLL_COUNT,
|
||||
DALLAS_COMMON_COPY_SCRATCH_MIN_TIMEOUT_US);
|
||||
|
||||
uint32_t time_elapsed;
|
||||
for(time_elapsed = 0; time_elapsed < timeout_us; time_elapsed += poll_delay) {
|
||||
if(!onewire_host_read_bit(host)) break;
|
||||
furi_delay_us(poll_delay);
|
||||
}
|
||||
|
||||
return time_elapsed < timeout_us;
|
||||
}
|
||||
|
||||
bool dallas_common_read_mem(OneWireHost* host, uint16_t address, uint8_t* data, size_t data_size) {
|
||||
onewire_host_write(host, DALLAS_COMMON_CMD_READ_MEM);
|
||||
|
||||
onewire_host_write(host, (uint8_t)address);
|
||||
onewire_host_write(host, (uint8_t)(address > BITS_IN_BYTE));
|
||||
|
||||
onewire_host_read_bytes(host, data, (uint16_t)data_size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool dallas_common_write_mem(
|
||||
OneWireHost* host,
|
||||
uint32_t timeout_us,
|
||||
size_t page_size,
|
||||
const uint8_t* data,
|
||||
size_t data_size) {
|
||||
// Data size must be a multiple of page size
|
||||
furi_check(data_size % page_size == 0);
|
||||
|
||||
DallasCommonAddressRegs regs;
|
||||
uint8_t* scratch = malloc(page_size);
|
||||
|
||||
size_t i;
|
||||
for(i = 0; i < data_size; i += page_size) {
|
||||
const uint8_t* data_ptr = data + i;
|
||||
|
||||
// Write scratchpad with the next page value
|
||||
if(!onewire_host_reset(host)) break;
|
||||
if(!dallas_common_skip_rom(host)) break;
|
||||
if(!dallas_common_write_scratchpad(host, i, data_ptr, page_size)) break;
|
||||
|
||||
// Read back the scratchpad contents and address registers
|
||||
if(!onewire_host_reset(host)) break;
|
||||
if(!dallas_common_skip_rom(host)) break;
|
||||
if(!dallas_common_read_scratchpad(host, ®s, scratch, page_size)) break;
|
||||
|
||||
// Verify scratchpad contents
|
||||
if(memcmp(data_ptr, scratch, page_size) != 0) break;
|
||||
|
||||
// Write scratchpad to internal memory
|
||||
if(!onewire_host_reset(host)) break;
|
||||
if(!dallas_common_skip_rom(host)) break;
|
||||
if(!dallas_common_copy_scratchpad(host, ®s, timeout_us)) break;
|
||||
|
||||
// Read back the address registers again
|
||||
if(!onewire_host_reset(host)) break;
|
||||
if(!dallas_common_skip_rom(host)) break;
|
||||
if(!dallas_common_read_scratchpad(host, ®s, scratch, 0)) break;
|
||||
|
||||
// Check if AA flag is set
|
||||
if(!(regs.fields.status & DALLAS_COMMON_STATUS_FLAG_AA)) break;
|
||||
}
|
||||
|
||||
free(scratch);
|
||||
|
||||
return i == data_size;
|
||||
}
|
||||
|
||||
bool dallas_common_emulate_search_rom(OneWireSlave* bus, const DallasCommonRomData* rom_data) {
|
||||
for(size_t i = 0; i < sizeof(DallasCommonRomData); i++) {
|
||||
for(size_t j = 0; j < BITS_IN_BYTE; j++) {
|
||||
bool bit = (rom_data->bytes[i] >> j) & 0x01;
|
||||
|
||||
if(!onewire_slave_send_bit(bus, bit)) return false;
|
||||
if(!onewire_slave_send_bit(bus, !bit)) return false;
|
||||
|
||||
onewire_slave_receive_bit(bus);
|
||||
// TODO: check for errors and return if any
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool dallas_common_emulate_read_rom(OneWireSlave* bus, const DallasCommonRomData* rom_data) {
|
||||
return onewire_slave_send(bus, rom_data->bytes, sizeof(DallasCommonRomData));
|
||||
}
|
||||
|
||||
bool dallas_common_emulate_read_mem(OneWireSlave* bus, const uint8_t* data, size_t data_size) {
|
||||
bool success = false;
|
||||
|
||||
union {
|
||||
uint8_t bytes[sizeof(uint16_t)];
|
||||
uint16_t word;
|
||||
} address;
|
||||
|
||||
do {
|
||||
if(!onewire_slave_receive(bus, address.bytes, sizeof(address))) break;
|
||||
if(address.word >= data_size) break;
|
||||
if(!onewire_slave_send(bus, data + address.word, data_size - address.word)) break;
|
||||
|
||||
success = true;
|
||||
} while(false);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool dallas_common_save_rom_data(FlipperFormat* ff, const DallasCommonRomData* rom_data) {
|
||||
return flipper_format_write_hex(
|
||||
ff, DALLAS_COMMON_ROM_DATA_KEY_V2, rom_data->bytes, sizeof(DallasCommonRomData));
|
||||
}
|
||||
|
||||
bool dallas_common_load_rom_data(
|
||||
FlipperFormat* ff,
|
||||
uint32_t format_version,
|
||||
DallasCommonRomData* rom_data) {
|
||||
switch(format_version) {
|
||||
case 1:
|
||||
return flipper_format_read_hex(
|
||||
ff, DALLAS_COMMON_ROM_DATA_KEY_V1, rom_data->bytes, sizeof(DallasCommonRomData));
|
||||
case 2:
|
||||
return flipper_format_read_hex(
|
||||
ff, DALLAS_COMMON_ROM_DATA_KEY_V2, rom_data->bytes, sizeof(DallasCommonRomData));
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool dallas_common_is_valid_crc(const DallasCommonRomData* rom_data) {
|
||||
const uint8_t crc_calculated =
|
||||
maxim_crc8(rom_data->bytes, sizeof(DallasCommonRomData) - 1, MAXIM_CRC8_INIT);
|
||||
const uint8_t crc_received = rom_data->fields.checksum;
|
||||
|
||||
return crc_calculated == crc_received;
|
||||
}
|
||||
|
||||
void dallas_common_render_brief_data(
|
||||
FuriString* result,
|
||||
const DallasCommonRomData* rom_data,
|
||||
const uint8_t* sram_data,
|
||||
size_t sram_data_size) {
|
||||
for(size_t i = 0; i < sizeof(rom_data->bytes); ++i) {
|
||||
furi_string_cat_printf(result, "%02X ", rom_data->bytes[i]);
|
||||
}
|
||||
|
||||
furi_string_cat_printf(
|
||||
result,
|
||||
"\nInternal SRAM: %zu Kbit\n",
|
||||
(size_t)(sram_data_size * BITS_IN_BYTE / BITS_IN_KBIT));
|
||||
|
||||
for(size_t i = 0; i < DALLAS_COMMON_BRIEF_HEAD_COUNT; ++i) {
|
||||
furi_string_cat_printf(result, "%02X ", sram_data[i]);
|
||||
}
|
||||
|
||||
furi_string_cat_printf(result, "[ . . . ]");
|
||||
|
||||
for(size_t i = sram_data_size - DALLAS_COMMON_BRIEF_TAIL_COUNT; i < sram_data_size; ++i) {
|
||||
furi_string_cat_printf(result, " %02X", sram_data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void dallas_common_render_crc_error(FuriString* result, const DallasCommonRomData* rom_data) {
|
||||
furi_string_set(result, "CRC Error\n");
|
||||
|
||||
const size_t data_size = sizeof(DallasCommonRomData);
|
||||
|
||||
for(size_t i = 0; i < data_size; ++i) {
|
||||
furi_string_cat_printf(result, (i < data_size - 1) ? "%02X " : "%02X", rom_data->bytes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void dallas_common_apply_edits(DallasCommonRomData* rom_data, uint8_t family_code) {
|
||||
rom_data->fields.family_code = family_code;
|
||||
const uint8_t crc =
|
||||
maxim_crc8(rom_data->bytes, sizeof(DallasCommonRomData) - 1, MAXIM_CRC8_INIT);
|
||||
rom_data->fields.checksum = crc;
|
||||
}
|
107
lib/one_wire/ibutton/protocols/dallas/dallas_common.h
Normal file
107
lib/one_wire/ibutton/protocols/dallas/dallas_common.h
Normal file
|
@ -0,0 +1,107 @@
|
|||
#pragma once
|
||||
|
||||
#include <flipper_format.h>
|
||||
|
||||
#include <one_wire/one_wire_host.h>
|
||||
#include <one_wire/one_wire_slave.h>
|
||||
|
||||
#define DALLAS_COMMON_MANUFACTURER_NAME "Dallas"
|
||||
|
||||
#define DALLAS_COMMON_CMD_READ_ROM 0x33U
|
||||
#define DALLAS_COMMON_CMD_MATCH_ROM 0x55U
|
||||
#define DALLAS_COMMON_CMD_SKIP_ROM 0xCCU
|
||||
#define DALLAS_COMMON_CMD_COND_SEARCH 0xECU
|
||||
#define DALLAS_COMMON_CMD_SEARCH_ROM 0xF0U
|
||||
|
||||
#define DALLAS_COMMON_CMD_READ_SCRATCH 0xAAU
|
||||
#define DALLAS_COMMON_CMD_WRITE_SCRATCH 0x0FU
|
||||
#define DALLAS_COMMON_CMD_COPY_SCRATCH 0x55U
|
||||
|
||||
#define DALLAS_COMMON_CMD_READ_MEM 0xF0U
|
||||
|
||||
#define DALLAS_COMMON_CMD_OVERDRIVE_SKIP_ROM 0x3CU
|
||||
#define DALLAS_COMMON_CMD_OVERDRIVE_MATCH_ROM 0x69U
|
||||
|
||||
typedef enum {
|
||||
DallasCommonCommandStateIdle,
|
||||
DallasCommonCommandStateRomCmd,
|
||||
DallasCommonCommandStateMemCmd,
|
||||
} DallasCommonCommandState;
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t family_code;
|
||||
uint8_t serial_number[6];
|
||||
uint8_t checksum;
|
||||
} fields;
|
||||
uint8_t bytes[8];
|
||||
} DallasCommonRomData;
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t address_lo;
|
||||
uint8_t address_hi;
|
||||
uint8_t status;
|
||||
} fields;
|
||||
uint8_t bytes[3];
|
||||
} DallasCommonAddressRegs;
|
||||
|
||||
/* Standard(ish) iButton commands */
|
||||
bool dallas_common_skip_rom(OneWireHost* host);
|
||||
|
||||
bool dallas_common_read_rom(OneWireHost* host, DallasCommonRomData* rom_data);
|
||||
|
||||
bool dallas_common_write_scratchpad(
|
||||
OneWireHost* host,
|
||||
uint16_t address,
|
||||
const uint8_t* data,
|
||||
size_t data_size);
|
||||
|
||||
bool dallas_common_read_scratchpad(
|
||||
OneWireHost* host,
|
||||
DallasCommonAddressRegs* regs,
|
||||
uint8_t* data,
|
||||
size_t data_size);
|
||||
|
||||
bool dallas_common_copy_scratchpad(
|
||||
OneWireHost* host,
|
||||
const DallasCommonAddressRegs* regs,
|
||||
uint32_t timeout_us);
|
||||
|
||||
bool dallas_common_read_mem(OneWireHost* host, uint16_t address, uint8_t* data, size_t data_size);
|
||||
|
||||
/* Combined operations */
|
||||
bool dallas_common_write_mem(
|
||||
OneWireHost* host,
|
||||
uint32_t timeout_us,
|
||||
size_t page_size,
|
||||
const uint8_t* data,
|
||||
size_t data_size);
|
||||
|
||||
/* Emulation */
|
||||
bool dallas_common_emulate_search_rom(OneWireSlave* bus, const DallasCommonRomData* rom_data);
|
||||
|
||||
bool dallas_common_emulate_read_rom(OneWireSlave* bus, const DallasCommonRomData* rom_data);
|
||||
|
||||
bool dallas_common_emulate_read_mem(OneWireSlave* bus, const uint8_t* data, size_t data_size);
|
||||
|
||||
/* Save & Load */
|
||||
bool dallas_common_save_rom_data(FlipperFormat* ff, const DallasCommonRomData* rom_data);
|
||||
|
||||
bool dallas_common_load_rom_data(
|
||||
FlipperFormat* ff,
|
||||
uint32_t format_version,
|
||||
DallasCommonRomData* rom_data);
|
||||
|
||||
/* Miscellaneous */
|
||||
bool dallas_common_is_valid_crc(const DallasCommonRomData* rom_data);
|
||||
|
||||
void dallas_common_render_brief_data(
|
||||
FuriString* result,
|
||||
const DallasCommonRomData* rom_data,
|
||||
const uint8_t* sram_data,
|
||||
size_t sram_data_size);
|
||||
|
||||
void dallas_common_render_crc_error(FuriString* result, const DallasCommonRomData* rom_data);
|
||||
|
||||
void dallas_common_apply_edits(DallasCommonRomData* rom_data, uint8_t family_code);
|
39
lib/one_wire/ibutton/protocols/dallas/protocol_dallas_base.h
Normal file
39
lib/one_wire/ibutton/protocols/dallas/protocol_dallas_base.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
#pragma once
|
||||
|
||||
#include "../protocol_common_i.h"
|
||||
|
||||
#include <flipper_format.h>
|
||||
|
||||
#include <one_wire/one_wire_host.h>
|
||||
#include <one_wire/one_wire_slave.h>
|
||||
|
||||
typedef bool (*iButtonProtocolDallasReadWriteFunc)(OneWireHost*, iButtonProtocolData*);
|
||||
typedef void (*iButtonProtocolDallasEmulateFunc)(OneWireSlave*, iButtonProtocolData*);
|
||||
typedef bool (*iButtonProtocolDallasSaveFunc)(FlipperFormat*, const iButtonProtocolData*);
|
||||
typedef bool (*iButtonProtocolDallasLoadFunc)(FlipperFormat*, uint32_t, iButtonProtocolData*);
|
||||
typedef void (*iButtonProtocolDallasRenderDataFunc)(FuriString*, const iButtonProtocolData*);
|
||||
typedef bool (*iButtonProtocolDallasIsValidFunc)(const iButtonProtocolData*);
|
||||
typedef void (
|
||||
*iButtonProtocolDallasGetEditableDataFunc)(iButtonEditableData*, iButtonProtocolData*);
|
||||
typedef void (*iButtonProtocolDallasApplyEditsFunc)(iButtonProtocolData*);
|
||||
|
||||
typedef struct {
|
||||
const uint8_t family_code;
|
||||
const uint32_t features;
|
||||
const size_t data_size;
|
||||
const char* manufacturer;
|
||||
const char* name;
|
||||
|
||||
iButtonProtocolDallasReadWriteFunc read;
|
||||
iButtonProtocolDallasReadWriteFunc write_blank;
|
||||
iButtonProtocolDallasReadWriteFunc write_copy;
|
||||
iButtonProtocolDallasEmulateFunc emulate;
|
||||
iButtonProtocolDallasSaveFunc save;
|
||||
iButtonProtocolDallasLoadFunc load;
|
||||
iButtonProtocolDallasRenderDataFunc render_data;
|
||||
iButtonProtocolDallasRenderDataFunc render_brief_data;
|
||||
iButtonProtocolDallasRenderDataFunc render_error;
|
||||
iButtonProtocolDallasIsValidFunc is_valid;
|
||||
iButtonProtocolDallasGetEditableDataFunc get_editable_data;
|
||||
iButtonProtocolDallasApplyEditsFunc apply_edits;
|
||||
} iButtonProtocolDallasBase;
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue