[FL-1931, FL-2005] SubGhz: migration in flipper file format (#807)
* SubGhz: add save key in flipper file format * [FL-2005] SubGhz: fix stored signals cannot be deleted * SubGhz: add load key in flipper file format * SubGhz: fix syntax * SubGhz: fix bad file upload * Storage: add function to get the next free filename * SubGhz: add save RAW in flipper file format * SubGhz: add load RAW in flipper file format * SubGhz: refactoring protocol * SubGhz: refactoring scene * SubGhz: fix SubGhzNotificationState define * Makefile: proper comapre for FORCE Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -168,3 +168,67 @@ bool subghz_protocol_common_read_hex(string_t str, uint8_t* buff, uint16_t len)
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
bool subghz_protocol_common_to_save_file(SubGhzProtocolCommon* instance, FlipperFile* flipper_file) {
|
||||
furi_assert(instance);
|
||||
furi_assert(flipper_file);
|
||||
bool res = false;
|
||||
do {
|
||||
if(!flipper_file_write_string_cstr(flipper_file, "Protocol", instance->name)) {
|
||||
FURI_LOG_E(SUBGHZ_KEY_TAG, "Unable to add Protocol");
|
||||
break;
|
||||
}
|
||||
if(!flipper_file_write_uint32(
|
||||
flipper_file, "Bit", (uint32_t*)&instance->code_last_count_bit, 1)) {
|
||||
FURI_LOG_E(SUBGHZ_KEY_TAG, "Unable to add Bit");
|
||||
break;
|
||||
}
|
||||
|
||||
uint8_t key_data[sizeof(uint64_t)] = {0};
|
||||
for(size_t i = 0; i < sizeof(uint64_t); i++) {
|
||||
key_data[sizeof(uint64_t) - i - 1] = (instance->code_last_found >> i * 8) & 0xFF;
|
||||
}
|
||||
|
||||
if(!flipper_file_write_hex(flipper_file, "Key", key_data, sizeof(uint64_t))) {
|
||||
FURI_LOG_E(SUBGHZ_KEY_TAG, "Unable to add Key");
|
||||
break;
|
||||
}
|
||||
res = true;
|
||||
} while(false);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
bool subghz_protocol_common_to_load_protocol_from_file(
|
||||
SubGhzProtocolCommon* instance,
|
||||
FlipperFile* flipper_file) {
|
||||
furi_assert(instance);
|
||||
furi_assert(flipper_file);
|
||||
bool loaded = false;
|
||||
string_t temp_str;
|
||||
string_init(temp_str);
|
||||
uint32_t temp_data = 0;
|
||||
|
||||
do {
|
||||
if(!flipper_file_read_uint32(flipper_file, "Bit", (uint32_t*)&temp_data, 1)) {
|
||||
FURI_LOG_E(SUBGHZ_KEY_TAG, "Missing Bit");
|
||||
break;
|
||||
}
|
||||
instance->code_last_count_bit = (uint8_t)temp_data;
|
||||
|
||||
uint8_t key_data[sizeof(uint64_t)] = {0};
|
||||
if(!flipper_file_read_hex(flipper_file, "Key", key_data, sizeof(uint64_t))) {
|
||||
FURI_LOG_E(SUBGHZ_KEY_TAG, "Missing Key");
|
||||
break;
|
||||
}
|
||||
for(uint8_t i = 0; i < sizeof(uint64_t); i++) {
|
||||
instance->code_last_found = instance->code_last_found << 8 | key_data[i];
|
||||
}
|
||||
|
||||
loaded = true;
|
||||
} while(0);
|
||||
|
||||
string_clear(temp_str);
|
||||
|
||||
return loaded;
|
||||
}
|
||||
|
Reference in New Issue
Block a user