M*LIB: non-inlined strings, FuriString primitive (#1795)
* Quicksave 1 * Header stage complete * Source stage complete * Lint & merge fixes * Includes * Documentation step 1 * FBT: output free size considering BT STACK * Documentation step 2 * py lint * Fix music player plugin * unit test stage 1: string allocator, mem, getters, setters, appends, compare, search. * unit test: string equality * unit test: string replace * unit test: string start_with, end_with * unit test: string trim * unit test: utf-8 * Rename * Revert fw_size changes * Simplify CLI backspace handling * Simplify CLI character insert * Merge fixes * Furi: correct filenaming and spelling * Bt: remove furi string include Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -143,8 +143,8 @@ ProtocolId lfrfid_dict_file_load(ProtocolDict* dict, const char* filename) {
|
||||
FlipperFormat* file = flipper_format_file_alloc(storage);
|
||||
ProtocolId result = PROTOCOL_NO;
|
||||
uint8_t* data = malloc(protocol_dict_get_max_data_size(dict));
|
||||
string_t str_result;
|
||||
string_init(str_result);
|
||||
FuriString* str_result;
|
||||
str_result = furi_string_alloc();
|
||||
|
||||
do {
|
||||
if(!flipper_format_file_open_existing(file, filename)) break;
|
||||
@@ -152,16 +152,16 @@ ProtocolId lfrfid_dict_file_load(ProtocolDict* dict, const char* filename) {
|
||||
// header
|
||||
uint32_t version;
|
||||
if(!flipper_format_read_header(file, str_result, &version)) break;
|
||||
if(string_cmp_str(str_result, LFRFID_DICT_FILETYPE) != 0) break;
|
||||
if(furi_string_cmp_str(str_result, LFRFID_DICT_FILETYPE) != 0) break;
|
||||
if(version != 1) break;
|
||||
|
||||
// type
|
||||
if(!flipper_format_read_string(file, "Key type", str_result)) break;
|
||||
ProtocolId protocol;
|
||||
protocol = protocol_dict_get_protocol_by_name(dict, string_get_cstr(str_result));
|
||||
protocol = protocol_dict_get_protocol_by_name(dict, furi_string_get_cstr(str_result));
|
||||
|
||||
if(protocol == PROTOCOL_NO) {
|
||||
protocol = lfrfid_dict_protocol_fallback(dict, string_get_cstr(str_result), file);
|
||||
protocol = lfrfid_dict_protocol_fallback(dict, furi_string_get_cstr(str_result), file);
|
||||
if(protocol == PROTOCOL_NO) break;
|
||||
} else {
|
||||
// data
|
||||
@@ -174,7 +174,7 @@ ProtocolId lfrfid_dict_file_load(ProtocolDict* dict, const char* filename) {
|
||||
} while(false);
|
||||
|
||||
free(data);
|
||||
string_clear(str_result);
|
||||
furi_string_free(str_result);
|
||||
flipper_format_free(file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ typedef struct {
|
||||
|
||||
// main worker
|
||||
struct LFRFIDRawWorker {
|
||||
string_t file_path;
|
||||
FuriString* file_path;
|
||||
FuriThread* thread;
|
||||
FuriEventFlag* events;
|
||||
|
||||
@@ -69,14 +69,14 @@ LFRFIDRawWorker* lfrfid_raw_worker_alloc() {
|
||||
|
||||
worker->events = furi_event_flag_alloc(NULL);
|
||||
|
||||
string_init(worker->file_path);
|
||||
worker->file_path = furi_string_alloc();
|
||||
return worker;
|
||||
}
|
||||
|
||||
void lfrfid_raw_worker_free(LFRFIDRawWorker* worker) {
|
||||
furi_thread_free(worker->thread);
|
||||
furi_event_flag_free(worker->events);
|
||||
string_clear(worker->file_path);
|
||||
furi_string_free(worker->file_path);
|
||||
free(worker);
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ void lfrfid_raw_worker_start_read(
|
||||
void* context) {
|
||||
furi_check(furi_thread_get_state(worker->thread) == FuriThreadStateStopped);
|
||||
|
||||
string_set(worker->file_path, file_path);
|
||||
furi_string_set(worker->file_path, file_path);
|
||||
|
||||
worker->frequency = freq;
|
||||
worker->duty_cycle = duty_cycle;
|
||||
@@ -107,7 +107,7 @@ void lfrfid_raw_worker_start_emulate(
|
||||
LFRFIDWorkerEmulateRawCallback callback,
|
||||
void* context) {
|
||||
furi_check(furi_thread_get_state(worker->thread) == FuriThreadStateStopped);
|
||||
string_set(worker->file_path, file_path);
|
||||
furi_string_set(worker->file_path, file_path);
|
||||
worker->emulate_callback = callback;
|
||||
worker->context = context;
|
||||
furi_thread_set_callback(worker->thread, lfrfid_raw_emulate_worker_thread);
|
||||
@@ -147,7 +147,7 @@ static int32_t lfrfid_raw_read_worker_thread(void* thread_context) {
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
LFRFIDRawFile* file = lfrfid_raw_file_alloc(storage);
|
||||
const char* filename = string_get_cstr(worker->file_path);
|
||||
const char* filename = furi_string_get_cstr(worker->file_path);
|
||||
bool file_valid = lfrfid_raw_file_open_write(file, filename);
|
||||
|
||||
LFRFIDRawWorkerReadData* data = malloc(sizeof(LFRFIDRawWorkerReadData));
|
||||
@@ -256,7 +256,7 @@ static int32_t lfrfid_raw_emulate_worker_thread(void* thread_context) {
|
||||
LFRFIDRawFile* file = lfrfid_raw_file_alloc(storage);
|
||||
|
||||
do {
|
||||
file_valid = lfrfid_raw_file_open_read(file, string_get_cstr(worker->file_path));
|
||||
file_valid = lfrfid_raw_file_open_read(file, furi_string_get_cstr(worker->file_path));
|
||||
if(!file_valid) break;
|
||||
file_valid = lfrfid_raw_file_read_header(file, &worker->frequency, &worker->duty_cycle);
|
||||
if(!file_valid) break;
|
||||
|
||||
@@ -270,14 +270,14 @@ static LFRFIDWorkerReadState lfrfid_worker_read_internal(
|
||||
}
|
||||
|
||||
if(furi_log_get_level() >= FuriLogLevelDebug) {
|
||||
string_t string_info;
|
||||
string_init(string_info);
|
||||
FuriString* string_info;
|
||||
string_info = furi_string_alloc();
|
||||
for(uint8_t i = 0; i < protocol_data_size; i++) {
|
||||
if(i != 0) {
|
||||
string_cat_printf(string_info, " ");
|
||||
furi_string_cat_printf(string_info, " ");
|
||||
}
|
||||
|
||||
string_cat_printf(string_info, "%02X", protocol_data[i]);
|
||||
furi_string_cat_printf(string_info, "%02X", protocol_data[i]);
|
||||
}
|
||||
|
||||
FURI_LOG_D(
|
||||
@@ -285,8 +285,8 @@ static LFRFIDWorkerReadState lfrfid_worker_read_internal(
|
||||
"%s, %d, [%s]",
|
||||
protocol_dict_get_name(worker->protocols, protocol),
|
||||
last_read_count,
|
||||
string_get_cstr(string_info));
|
||||
string_clear(string_info);
|
||||
furi_string_get_cstr(string_info));
|
||||
furi_string_free(string_info);
|
||||
}
|
||||
|
||||
protocol_dict_decoders_start(worker->protocols);
|
||||
|
||||
@@ -147,7 +147,7 @@ LevelDuration protocol_awid_encoder_yield(ProtocolAwid* protocol) {
|
||||
return level_duration_make(level, duration);
|
||||
};
|
||||
|
||||
void protocol_awid_render_data(ProtocolAwid* protocol, string_t result) {
|
||||
void protocol_awid_render_data(ProtocolAwid* protocol, FuriString* result) {
|
||||
// Index map
|
||||
// 0 10 20 30 40 50 60
|
||||
// | | | | | | |
|
||||
@@ -164,7 +164,7 @@ void protocol_awid_render_data(ProtocolAwid* protocol, string_t result) {
|
||||
uint8_t* decoded_data = protocol->data;
|
||||
uint8_t format_length = decoded_data[0];
|
||||
|
||||
string_cat_printf(result, "Format: %d\r\n", format_length);
|
||||
furi_string_cat_printf(result, "Format: %d\r\n", format_length);
|
||||
if(format_length == 26) {
|
||||
uint8_t facility;
|
||||
bit_lib_copy_bits(&facility, 0, 8, decoded_data, 9);
|
||||
@@ -172,22 +172,22 @@ void protocol_awid_render_data(ProtocolAwid* protocol, string_t result) {
|
||||
uint16_t card_id;
|
||||
bit_lib_copy_bits((uint8_t*)&card_id, 8, 8, decoded_data, 17);
|
||||
bit_lib_copy_bits((uint8_t*)&card_id, 0, 8, decoded_data, 25);
|
||||
string_cat_printf(result, "Facility: %d\r\n", facility);
|
||||
string_cat_printf(result, "Card: %d", card_id);
|
||||
furi_string_cat_printf(result, "Facility: %d\r\n", facility);
|
||||
furi_string_cat_printf(result, "Card: %d", card_id);
|
||||
} else {
|
||||
// print 66 bits as hex
|
||||
string_cat_printf(result, "Data: ");
|
||||
furi_string_cat_printf(result, "Data: ");
|
||||
for(size_t i = 0; i < AWID_DECODED_DATA_SIZE; i++) {
|
||||
string_cat_printf(result, "%02X", decoded_data[i]);
|
||||
furi_string_cat_printf(result, "%02X", decoded_data[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void protocol_awid_render_brief_data(ProtocolAwid* protocol, string_t result) {
|
||||
void protocol_awid_render_brief_data(ProtocolAwid* protocol, FuriString* result) {
|
||||
uint8_t* decoded_data = protocol->data;
|
||||
uint8_t format_length = decoded_data[0];
|
||||
|
||||
string_cat_printf(result, "Format: %d\r\n", format_length);
|
||||
furi_string_cat_printf(result, "Format: %d\r\n", format_length);
|
||||
if(format_length == 26) {
|
||||
uint8_t facility;
|
||||
bit_lib_copy_bits(&facility, 0, 8, decoded_data, 9);
|
||||
@@ -195,9 +195,9 @@ void protocol_awid_render_brief_data(ProtocolAwid* protocol, string_t result) {
|
||||
uint16_t card_id;
|
||||
bit_lib_copy_bits((uint8_t*)&card_id, 8, 8, decoded_data, 17);
|
||||
bit_lib_copy_bits((uint8_t*)&card_id, 0, 8, decoded_data, 25);
|
||||
string_cat_printf(result, "ID: %03u,%05u", facility, card_id);
|
||||
furi_string_cat_printf(result, "ID: %03u,%05u", facility, card_id);
|
||||
} else {
|
||||
string_cat_printf(result, "Data: unknown");
|
||||
furi_string_cat_printf(result, "Data: unknown");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -251,10 +251,10 @@ bool protocol_em4100_write_data(ProtocolEM4100* protocol, void* data) {
|
||||
// Correct protocol data by redecoding
|
||||
protocol_em4100_encoder_start(protocol);
|
||||
em4100_decode(
|
||||
(uint8_t*)&protocol->encoded_data,
|
||||
sizeof(EM4100DecodedData),
|
||||
protocol->data,
|
||||
EM4100_DECODED_DATA_SIZE);
|
||||
(uint8_t*)&protocol->encoded_data,
|
||||
sizeof(EM4100DecodedData),
|
||||
protocol->data,
|
||||
EM4100_DECODED_DATA_SIZE);
|
||||
|
||||
protocol_em4100_encoder_start(protocol);
|
||||
|
||||
@@ -270,9 +270,10 @@ bool protocol_em4100_write_data(ProtocolEM4100* protocol, void* data) {
|
||||
return result;
|
||||
};
|
||||
|
||||
void protocol_em4100_render_data(ProtocolEM4100* protocol, string_t result) {
|
||||
void protocol_em4100_render_data(ProtocolEM4100* protocol, FuriString* result) {
|
||||
uint8_t* data = protocol->data;
|
||||
string_printf(result, "FC: %03u, Card: %05u", data[2], (uint16_t)((data[3] << 8) | (data[4])));
|
||||
furi_string_printf(
|
||||
result, "FC: %03u, Card: %05u", data[2], (uint16_t)((data[3] << 8) | (data[4])));
|
||||
};
|
||||
|
||||
const ProtocolBase protocol_em4100 = {
|
||||
|
||||
@@ -196,7 +196,7 @@ bool protocol_fdx_a_write_data(ProtocolFDXA* protocol, void* data) {
|
||||
return result;
|
||||
};
|
||||
|
||||
void protocol_fdx_a_render_data(ProtocolFDXA* protocol, string_t result) {
|
||||
void protocol_fdx_a_render_data(ProtocolFDXA* protocol, FuriString* result) {
|
||||
uint8_t data[FDXA_DECODED_DATA_SIZE];
|
||||
memcpy(data, protocol->data, FDXA_DECODED_DATA_SIZE);
|
||||
|
||||
@@ -206,7 +206,7 @@ void protocol_fdx_a_render_data(ProtocolFDXA* protocol, string_t result) {
|
||||
data[i] &= 0x7F;
|
||||
}
|
||||
|
||||
string_printf(
|
||||
furi_string_printf(
|
||||
result,
|
||||
"ID: %02X%02X%02X%02X%02X\r\n"
|
||||
"Parity: %s",
|
||||
|
||||
@@ -273,7 +273,7 @@ static bool protocol_fdx_b_get_temp(const uint8_t* data, float* temp) {
|
||||
}
|
||||
}
|
||||
|
||||
void protocol_fdx_b_render_data(ProtocolFDXB* protocol, string_t result) {
|
||||
void protocol_fdx_b_render_data(ProtocolFDXB* protocol, FuriString* result) {
|
||||
// 38 bits of national code
|
||||
uint64_t national_code = protocol_fdx_b_get_national_code(protocol->data);
|
||||
|
||||
@@ -287,19 +287,19 @@ void protocol_fdx_b_render_data(ProtocolFDXB* protocol, string_t result) {
|
||||
uint8_t replacement_number = bit_lib_get_bits(protocol->data, 60, 3);
|
||||
bool animal_flag = bit_lib_get_bit(protocol->data, 63);
|
||||
|
||||
string_printf(result, "ID: %03u-%012llu\r\n", country_code, national_code);
|
||||
string_cat_printf(result, "Animal: %s, ", animal_flag ? "Yes" : "No");
|
||||
furi_string_printf(result, "ID: %03u-%012llu\r\n", country_code, national_code);
|
||||
furi_string_cat_printf(result, "Animal: %s, ", animal_flag ? "Yes" : "No");
|
||||
|
||||
float temperature;
|
||||
if(protocol_fdx_b_get_temp(protocol->data, &temperature)) {
|
||||
float temperature_c = (temperature - 32) / 1.8;
|
||||
string_cat_printf(
|
||||
furi_string_cat_printf(
|
||||
result, "T: %.2fF, %.2fC\r\n", (double)temperature, (double)temperature_c);
|
||||
} else {
|
||||
string_cat_printf(result, "T: ---\r\n");
|
||||
furi_string_cat_printf(result, "T: ---\r\n");
|
||||
}
|
||||
|
||||
string_cat_printf(
|
||||
furi_string_cat_printf(
|
||||
result,
|
||||
"Bits: %X-%X-%X-%X-%X",
|
||||
block_status,
|
||||
@@ -309,7 +309,7 @@ void protocol_fdx_b_render_data(ProtocolFDXB* protocol, string_t result) {
|
||||
replacement_number);
|
||||
};
|
||||
|
||||
void protocol_fdx_b_render_brief_data(ProtocolFDXB* protocol, string_t result) {
|
||||
void protocol_fdx_b_render_brief_data(ProtocolFDXB* protocol, FuriString* result) {
|
||||
// 38 bits of national code
|
||||
uint64_t national_code = protocol_fdx_b_get_national_code(protocol->data);
|
||||
|
||||
@@ -318,15 +318,15 @@ void protocol_fdx_b_render_brief_data(ProtocolFDXB* protocol, string_t result) {
|
||||
|
||||
bool animal_flag = bit_lib_get_bit(protocol->data, 63);
|
||||
|
||||
string_printf(result, "ID: %03u-%012llu\r\n", country_code, national_code);
|
||||
string_cat_printf(result, "Animal: %s, ", animal_flag ? "Yes" : "No");
|
||||
furi_string_printf(result, "ID: %03u-%012llu\r\n", country_code, national_code);
|
||||
furi_string_cat_printf(result, "Animal: %s, ", animal_flag ? "Yes" : "No");
|
||||
|
||||
float temperature;
|
||||
if(protocol_fdx_b_get_temp(protocol->data, &temperature)) {
|
||||
float temperature_c = (temperature - 32) / 1.8;
|
||||
string_cat_printf(result, "T: %.2fC", (double)temperature_c);
|
||||
furi_string_cat_printf(result, "T: %.2fC", (double)temperature_c);
|
||||
} else {
|
||||
string_cat_printf(result, "T: ---");
|
||||
furi_string_cat_printf(result, "T: ---");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -268,15 +268,15 @@ bool protocol_gallagher_write_data(ProtocolGallagher* protocol, void* data) {
|
||||
return result;
|
||||
};
|
||||
|
||||
void protocol_gallagher_render_data(ProtocolGallagher* protocol, string_t result) {
|
||||
void protocol_gallagher_render_data(ProtocolGallagher* protocol, FuriString* result) {
|
||||
UNUSED(protocol);
|
||||
uint8_t rc = bit_lib_get_bits(protocol->data, 0, 4);
|
||||
uint8_t il = bit_lib_get_bits(protocol->data, 4, 4);
|
||||
uint32_t fc = bit_lib_get_bits_32(protocol->data, 8, 24);
|
||||
uint32_t card_id = bit_lib_get_bits_32(protocol->data, 32, 32);
|
||||
|
||||
string_cat_printf(result, "Region: %u, Issue Level: %u\r\n", rc, il);
|
||||
string_cat_printf(result, "FC: %u, C: %lu\r\n", fc, card_id);
|
||||
furi_string_cat_printf(result, "Region: %u, Issue Level: %u\r\n", rc, il);
|
||||
furi_string_cat_printf(result, "FC: %u, C: %lu\r\n", fc, card_id);
|
||||
};
|
||||
|
||||
const ProtocolBase protocol_gallagher = {
|
||||
|
||||
@@ -340,7 +340,7 @@ bool protocol_h10301_write_data(ProtocolH10301* protocol, void* data) {
|
||||
// Correct protocol data by redecoding
|
||||
protocol_h10301_encoder_start(protocol);
|
||||
protocol_h10301_decode(protocol->encoded_data, protocol->data);
|
||||
|
||||
|
||||
protocol_h10301_encoder_start(protocol);
|
||||
|
||||
if(request->write_type == LFRFIDWriteTypeT5577) {
|
||||
@@ -355,9 +355,9 @@ bool protocol_h10301_write_data(ProtocolH10301* protocol, void* data) {
|
||||
return result;
|
||||
};
|
||||
|
||||
void protocol_h10301_render_data(ProtocolH10301* protocol, string_t result) {
|
||||
void protocol_h10301_render_data(ProtocolH10301* protocol, FuriString* result) {
|
||||
uint8_t* data = protocol->data;
|
||||
string_printf(
|
||||
furi_string_printf(
|
||||
result,
|
||||
"FC: %u\r\n"
|
||||
"Card: %u",
|
||||
|
||||
@@ -192,10 +192,10 @@ bool protocol_hid_ex_generic_write_data(ProtocolHIDEx* protocol, void* data) {
|
||||
return result;
|
||||
};
|
||||
|
||||
void protocol_hid_ex_generic_render_data(ProtocolHIDEx* protocol, string_t result) {
|
||||
void protocol_hid_ex_generic_render_data(ProtocolHIDEx* protocol, FuriString* result) {
|
||||
// TODO: parser and render functions
|
||||
UNUSED(protocol);
|
||||
string_printf(result, "Generic HID Extended\r\nData: Unknown");
|
||||
furi_string_printf(result, "Generic HID Extended\r\nData: Unknown");
|
||||
};
|
||||
|
||||
const ProtocolBase protocol_hid_ex_generic = {
|
||||
|
||||
@@ -221,25 +221,29 @@ bool protocol_hid_generic_write_data(ProtocolHID* protocol, void* data) {
|
||||
return result;
|
||||
};
|
||||
|
||||
static void protocol_hid_generic_string_cat_protocol_bits(ProtocolHID* protocol, uint8_t protocol_size, string_t result) {
|
||||
static void protocol_hid_generic_string_cat_protocol_bits(
|
||||
ProtocolHID* protocol,
|
||||
uint8_t protocol_size,
|
||||
FuriString* result) {
|
||||
// round up to the nearest nibble
|
||||
const uint8_t hex_character_count = (protocol_size + 3) / 4;
|
||||
const uint8_t protocol_bit_index = HID_DECODED_BIT_SIZE - protocol_size;
|
||||
|
||||
for(size_t i = 0; i < hex_character_count; i++) {
|
||||
uint8_t nibble =
|
||||
i == 0 ? bit_lib_get_bits(
|
||||
protocol->data, protocol_bit_index, protocol_size % 4 == 0 ? 4 : protocol_size % 4) :
|
||||
bit_lib_get_bits(protocol->data, protocol_bit_index + i * 4, 4);
|
||||
string_cat_printf(result, "%X", nibble & 0xF);
|
||||
uint8_t nibble = i == 0 ? bit_lib_get_bits(
|
||||
protocol->data,
|
||||
protocol_bit_index,
|
||||
protocol_size % 4 == 0 ? 4 : protocol_size % 4) :
|
||||
bit_lib_get_bits(protocol->data, protocol_bit_index + i * 4, 4);
|
||||
furi_string_cat_printf(result, "%X", nibble & 0xF);
|
||||
}
|
||||
}
|
||||
|
||||
void protocol_hid_generic_render_data(ProtocolHID* protocol, string_t result) {
|
||||
void protocol_hid_generic_render_data(ProtocolHID* protocol, FuriString* result) {
|
||||
const uint8_t protocol_size = protocol_hid_generic_decode_protocol_size(protocol);
|
||||
|
||||
if(protocol_size == HID_PROTOCOL_SIZE_UNKNOWN) {
|
||||
string_printf(
|
||||
furi_string_printf(
|
||||
result,
|
||||
"Generic HID Proximity\r\n"
|
||||
"Data: %02X%02X%02X%02X%02X%X",
|
||||
@@ -250,7 +254,7 @@ void protocol_hid_generic_render_data(ProtocolHID* protocol, string_t result) {
|
||||
protocol->data[4],
|
||||
protocol->data[5] >> 4);
|
||||
} else {
|
||||
string_printf(
|
||||
furi_string_printf(
|
||||
result,
|
||||
"%hhu-bit HID Proximity\r\n"
|
||||
"Data: ",
|
||||
|
||||
@@ -236,7 +236,10 @@ static uint16_t get_cn(const uint8_t* data) {
|
||||
return cn;
|
||||
}
|
||||
|
||||
void protocol_indala26_render_data_internal(ProtocolIndala* protocol, string_t result, bool brief) {
|
||||
void protocol_indala26_render_data_internal(
|
||||
ProtocolIndala* protocol,
|
||||
FuriString* result,
|
||||
bool brief) {
|
||||
bool wiegand_correct = true;
|
||||
bool checksum_correct = true;
|
||||
|
||||
@@ -284,7 +287,7 @@ void protocol_indala26_render_data_internal(ProtocolIndala* protocol, string_t r
|
||||
if(odd_parity_sum % 2 != odd_parity) wiegand_correct = false;
|
||||
|
||||
if(brief) {
|
||||
string_printf(
|
||||
furi_string_printf(
|
||||
result,
|
||||
"FC: %u\r\nCard: %u, Parity:%s%s",
|
||||
fc,
|
||||
@@ -292,7 +295,7 @@ void protocol_indala26_render_data_internal(ProtocolIndala* protocol, string_t r
|
||||
(checksum_correct ? "+" : "-"),
|
||||
(wiegand_correct ? "+" : "-"));
|
||||
} else {
|
||||
string_printf(
|
||||
furi_string_printf(
|
||||
result,
|
||||
"FC: %u\r\n"
|
||||
"Card: %u\r\n"
|
||||
@@ -304,10 +307,10 @@ void protocol_indala26_render_data_internal(ProtocolIndala* protocol, string_t r
|
||||
(wiegand_correct ? "+" : "-"));
|
||||
}
|
||||
}
|
||||
void protocol_indala26_render_data(ProtocolIndala* protocol, string_t result) {
|
||||
void protocol_indala26_render_data(ProtocolIndala* protocol, FuriString* result) {
|
||||
protocol_indala26_render_data_internal(protocol, result, false);
|
||||
}
|
||||
void protocol_indala26_render_brief_data(ProtocolIndala* protocol, string_t result) {
|
||||
void protocol_indala26_render_brief_data(ProtocolIndala* protocol, FuriString* result) {
|
||||
protocol_indala26_render_data_internal(protocol, result, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -232,9 +232,9 @@ LevelDuration protocol_io_prox_xsf_encoder_yield(ProtocolIOProxXSF* protocol) {
|
||||
return level_duration_make(level, duration);
|
||||
};
|
||||
|
||||
void protocol_io_prox_xsf_render_data(ProtocolIOProxXSF* protocol, string_t result) {
|
||||
void protocol_io_prox_xsf_render_data(ProtocolIOProxXSF* protocol, FuriString* result) {
|
||||
uint8_t* data = protocol->data;
|
||||
string_printf(
|
||||
furi_string_printf(
|
||||
result,
|
||||
"FC: %u\r\n"
|
||||
"VС: %u\r\n"
|
||||
@@ -244,9 +244,9 @@ void protocol_io_prox_xsf_render_data(ProtocolIOProxXSF* protocol, string_t resu
|
||||
(uint16_t)((data[2] << 8) | (data[3])));
|
||||
}
|
||||
|
||||
void protocol_io_prox_xsf_render_brief_data(ProtocolIOProxXSF* protocol, string_t result) {
|
||||
void protocol_io_prox_xsf_render_brief_data(ProtocolIOProxXSF* protocol, FuriString* result) {
|
||||
uint8_t* data = protocol->data;
|
||||
string_printf(
|
||||
furi_string_printf(
|
||||
result,
|
||||
"FC: %u, VС: %u\r\n"
|
||||
"Card: %u",
|
||||
|
||||
@@ -160,9 +160,9 @@ LevelDuration protocol_jablotron_encoder_yield(ProtocolJablotron* protocol) {
|
||||
return level_duration_make(protocol->last_level, duration);
|
||||
};
|
||||
|
||||
void protocol_jablotron_render_data(ProtocolJablotron* protocol, string_t result) {
|
||||
void protocol_jablotron_render_data(ProtocolJablotron* protocol, FuriString* result) {
|
||||
uint64_t id = protocol_jablotron_card_id(protocol->data);
|
||||
string_printf(result, "ID: %llX\r\n", id);
|
||||
furi_string_printf(result, "ID: %llX\r\n", id);
|
||||
};
|
||||
|
||||
bool protocol_jablotron_write_data(ProtocolJablotron* protocol, void* data) {
|
||||
|
||||
@@ -211,13 +211,13 @@ LevelDuration protocol_keri_encoder_yield(ProtocolKeri* protocol) {
|
||||
return level_duration;
|
||||
};
|
||||
|
||||
void protocol_keri_render_data(ProtocolKeri* protocol, string_t result) {
|
||||
void protocol_keri_render_data(ProtocolKeri* protocol, FuriString* result) {
|
||||
uint32_t data = bit_lib_get_bits_32(protocol->data, 0, 32);
|
||||
uint32_t internal_id = data & 0x7FFFFFFF;
|
||||
uint32_t fc = 0;
|
||||
uint32_t cn = 0;
|
||||
protocol_keri_descramble(&fc, &cn, &data);
|
||||
string_printf(result, "Internal ID: %u\r\nFC: %u, Card: %u\r\n", internal_id, fc, cn);
|
||||
furi_string_printf(result, "Internal ID: %u\r\nFC: %u, Card: %u\r\n", internal_id, fc, cn);
|
||||
}
|
||||
|
||||
bool protocol_keri_write_data(ProtocolKeri* protocol, void* data) {
|
||||
|
||||
@@ -57,31 +57,31 @@ static void protocol_pac_stanley_decode(ProtocolPACStanley* protocol) {
|
||||
}
|
||||
|
||||
static bool protocol_pac_stanley_can_be_decoded(ProtocolPACStanley* protocol) {
|
||||
// Check preamble
|
||||
if(bit_lib_get_bits(protocol->encoded_data, 0, 8) != 0b11111111) return false;
|
||||
if(bit_lib_get_bit(protocol->encoded_data, 8) != 0) return false;
|
||||
if(bit_lib_get_bit(protocol->encoded_data, 9) != 0) return false;
|
||||
if(bit_lib_get_bit(protocol->encoded_data, 10) != 1) return false;
|
||||
if(bit_lib_get_bits(protocol->encoded_data, 11, 8) != 0b00000010) return false;
|
||||
// Check preamble
|
||||
if(bit_lib_get_bits(protocol->encoded_data, 0, 8) != 0b11111111) return false;
|
||||
if(bit_lib_get_bit(protocol->encoded_data, 8) != 0) return false;
|
||||
if(bit_lib_get_bit(protocol->encoded_data, 9) != 0) return false;
|
||||
if(bit_lib_get_bit(protocol->encoded_data, 10) != 1) return false;
|
||||
if(bit_lib_get_bits(protocol->encoded_data, 11, 8) != 0b00000010) return false;
|
||||
|
||||
// Check next preamble
|
||||
if(bit_lib_get_bits(protocol->encoded_data, 128, 8) != 0b11111111) return false;
|
||||
// Check next preamble
|
||||
if(bit_lib_get_bits(protocol->encoded_data, 128, 8) != 0b11111111) return false;
|
||||
|
||||
// Checksum
|
||||
uint8_t checksum = 0;
|
||||
uint8_t stripped_byte;
|
||||
for(size_t idx = 0; idx < 9; idx++) {
|
||||
uint8_t byte = bit_lib_reverse_8_fast(bit_lib_get_bits(
|
||||
protocol->encoded_data,
|
||||
PAC_STANLEY_DATA_START_INDEX + (PAC_STANLEY_BYTE_LENGTH * idx),
|
||||
8));
|
||||
stripped_byte = byte & 0x7F; // discard the parity bit
|
||||
if(bit_lib_test_parity_32(stripped_byte, BitLibParityOdd) != (byte & 0x80) >> 7) {
|
||||
return false;
|
||||
}
|
||||
if(idx < 8) checksum ^= stripped_byte;
|
||||
// Checksum
|
||||
uint8_t checksum = 0;
|
||||
uint8_t stripped_byte;
|
||||
for(size_t idx = 0; idx < 9; idx++) {
|
||||
uint8_t byte = bit_lib_reverse_8_fast(bit_lib_get_bits(
|
||||
protocol->encoded_data,
|
||||
PAC_STANLEY_DATA_START_INDEX + (PAC_STANLEY_BYTE_LENGTH * idx),
|
||||
8));
|
||||
stripped_byte = byte & 0x7F; // discard the parity bit
|
||||
if(bit_lib_test_parity_32(stripped_byte, BitLibParityOdd) != (byte & 0x80) >> 7) {
|
||||
return false;
|
||||
}
|
||||
if(stripped_byte != checksum) return false;
|
||||
if(idx < 8) checksum ^= stripped_byte;
|
||||
}
|
||||
if(stripped_byte != checksum) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -201,9 +201,9 @@ bool protocol_pac_stanley_write_data(ProtocolPACStanley* protocol, void* data) {
|
||||
return result;
|
||||
}
|
||||
|
||||
void protocol_pac_stanley_render_data(ProtocolPACStanley* protocol, string_t result) {
|
||||
void protocol_pac_stanley_render_data(ProtocolPACStanley* protocol, FuriString* result) {
|
||||
uint8_t* data = protocol->data;
|
||||
string_printf(result, "CIN: %02X%02X%02X%02X", data[0], data[1], data[2], data[3]);
|
||||
furi_string_printf(result, "CIN: %02X%02X%02X%02X", data[0], data[1], data[2], data[3]);
|
||||
}
|
||||
|
||||
const ProtocolBase protocol_pac_stanley = {
|
||||
|
||||
@@ -136,26 +136,26 @@ LevelDuration protocol_paradox_encoder_yield(ProtocolParadox* protocol) {
|
||||
return level_duration_make(level, duration);
|
||||
};
|
||||
|
||||
void protocol_paradox_render_data(ProtocolParadox* protocol, string_t result) {
|
||||
void protocol_paradox_render_data(ProtocolParadox* protocol, FuriString* result) {
|
||||
uint8_t* decoded_data = protocol->data;
|
||||
uint8_t fc = bit_lib_get_bits(decoded_data, 10, 8);
|
||||
uint16_t card_id = bit_lib_get_bits_16(decoded_data, 18, 16);
|
||||
|
||||
string_cat_printf(result, "Facility: %u\r\n", fc);
|
||||
string_cat_printf(result, "Card: %lu\r\n", card_id);
|
||||
string_cat_printf(result, "Data: ");
|
||||
furi_string_cat_printf(result, "Facility: %u\r\n", fc);
|
||||
furi_string_cat_printf(result, "Card: %lu\r\n", card_id);
|
||||
furi_string_cat_printf(result, "Data: ");
|
||||
for(size_t i = 0; i < PARADOX_DECODED_DATA_SIZE; i++) {
|
||||
string_cat_printf(result, "%02X", decoded_data[i]);
|
||||
furi_string_cat_printf(result, "%02X", decoded_data[i]);
|
||||
}
|
||||
};
|
||||
|
||||
void protocol_paradox_render_brief_data(ProtocolParadox* protocol, string_t result) {
|
||||
void protocol_paradox_render_brief_data(ProtocolParadox* protocol, FuriString* result) {
|
||||
uint8_t* decoded_data = protocol->data;
|
||||
|
||||
uint8_t fc = bit_lib_get_bits(decoded_data, 10, 8);
|
||||
uint16_t card_id = bit_lib_get_bits_16(decoded_data, 18, 16);
|
||||
|
||||
string_cat_printf(result, "FC: %03u, Card: %05u", fc, card_id);
|
||||
furi_string_cat_printf(result, "FC: %03u, Card: %05u", fc, card_id);
|
||||
};
|
||||
|
||||
bool protocol_paradox_write_data(ProtocolParadox* protocol, void* data) {
|
||||
|
||||
@@ -238,11 +238,11 @@ bool protocol_pyramid_write_data(ProtocolPyramid* protocol, void* data) {
|
||||
return result;
|
||||
};
|
||||
|
||||
void protocol_pyramid_render_data(ProtocolPyramid* protocol, string_t result) {
|
||||
void protocol_pyramid_render_data(ProtocolPyramid* protocol, FuriString* result) {
|
||||
uint8_t* decoded_data = protocol->data;
|
||||
uint8_t format_length = decoded_data[0];
|
||||
|
||||
string_cat_printf(result, "Format: 26\r\n", format_length);
|
||||
furi_string_cat_printf(result, "Format: 26\r\n", format_length);
|
||||
if(format_length == 26) {
|
||||
uint8_t facility;
|
||||
bit_lib_copy_bits(&facility, 0, 8, decoded_data, 8);
|
||||
@@ -250,9 +250,9 @@ void protocol_pyramid_render_data(ProtocolPyramid* protocol, string_t result) {
|
||||
uint16_t card_id;
|
||||
bit_lib_copy_bits((uint8_t*)&card_id, 8, 8, decoded_data, 16);
|
||||
bit_lib_copy_bits((uint8_t*)&card_id, 0, 8, decoded_data, 24);
|
||||
string_cat_printf(result, "FC: %03u, Card: %05u", facility, card_id);
|
||||
furi_string_cat_printf(result, "FC: %03u, Card: %05u", facility, card_id);
|
||||
} else {
|
||||
string_cat_printf(result, "Data: unknown");
|
||||
furi_string_cat_printf(result, "Data: unknown");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -175,9 +175,9 @@ bool protocol_viking_write_data(ProtocolViking* protocol, void* data) {
|
||||
return result;
|
||||
};
|
||||
|
||||
void protocol_viking_render_data(ProtocolViking* protocol, string_t result) {
|
||||
void protocol_viking_render_data(ProtocolViking* protocol, FuriString* result) {
|
||||
uint32_t id = bit_lib_get_bits_32(protocol->data, 0, 32);
|
||||
string_printf(result, "ID: %08lX\r\n", id);
|
||||
furi_string_printf(result, "ID: %08lX\r\n", id);
|
||||
};
|
||||
|
||||
const ProtocolBase protocol_viking = {
|
||||
|
||||
Reference in New Issue
Block a user