[FL-2868] Remove string_push_uint64 (#1832)

* Remove string_pust_uint64
* Oops, furi strings now
* Remove dead code
* Remove unneeded import

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
Astra 2022-10-06 21:51:30 +03:00 committed by GitHub
parent dde18cd343
commit eaa3adf98a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 3 additions and 62 deletions

View File

@ -1,5 +1,4 @@
#include "nfc_supported_card.h" #include "nfc_supported_card.h"
#include "plantain_parser.h" // For luhn and string_push_uint64
#include <gui/modules/widget.h> #include <gui/modules/widget.h>
#include <nfc_worker_i.h> #include <nfc_worker_i.h>
@ -121,26 +120,15 @@ bool plantain_4k_parser_parse(NfcDeviceData* dev_data) {
FuriString* card_number_str; FuriString* card_number_str;
card_number_str = furi_string_alloc(); card_number_str = furi_string_alloc();
// Should look like "361301047292848684" // Should look like "361301047292848684"
// %llu doesn't work for some reason in sprintf, so we use string_push_uint64 instead furi_string_printf(card_number_str, "%llu", card_number);
string_push_uint64(card_number, card_number_str);
// Add suffix with luhn checksum (1 digit) to the card number string // Add suffix with luhn checksum (1 digit) to the card number string
FuriString* card_number_suffix; FuriString* card_number_suffix;
card_number_suffix = furi_string_alloc(); card_number_suffix = furi_string_alloc();
// The number to calculate the checksum on doesn't fit into uint64_t, idk
//uint8_t luhn_checksum = plantain_calculate_luhn(card_number);
// // Convert luhn checksum to string
// FuriString* luhn_checksum_str;
// luhn_checksum_str = furi_string_alloc();
// string_push_uint64(luhn_checksum, luhn_checksum_str);
furi_string_cat_printf(card_number_suffix, "-"); furi_string_cat_printf(card_number_suffix, "-");
// FURI_LOG_D("plant4k", "Card checksum: %d", luhn_checksum);
furi_string_cat_printf(card_number_str, furi_string_get_cstr(card_number_suffix)); furi_string_cat_printf(card_number_str, furi_string_get_cstr(card_number_suffix));
// Free all not needed strings // Free all not needed strings
furi_string_free(card_number_suffix); furi_string_free(card_number_suffix);
// furi_string_free(luhn_checksum_str);
furi_string_printf( furi_string_printf(
dev_data->parsed_data, dev_data->parsed_data,

View File

@ -55,29 +55,6 @@ bool plantain_parser_read(NfcWorker* nfc_worker, FuriHalNfcTxRxContext* tx_rx) {
return mf_classic_read_card(tx_rx, &reader, &nfc_worker->dev_data->mf_classic_data) == 16; return mf_classic_read_card(tx_rx, &reader, &nfc_worker->dev_data->mf_classic_data) == 16;
} }
void string_push_uint64(uint64_t input, FuriString* output) {
const uint8_t base = 10;
do {
char c = input % base;
input /= base;
if(c < 10)
c += '0';
else
c += 'A' - 10;
furi_string_push_back(output, c);
} while(input);
// reverse string
for(uint8_t i = 0; i < furi_string_size(output) / 2; i++) {
char c = furi_string_get_char(output, i);
furi_string_set_char(
output, i, furi_string_get_char(output, furi_string_size(output) - i - 1));
furi_string_set_char(output, furi_string_size(output) - i - 1, c);
}
}
uint8_t plantain_calculate_luhn(uint64_t number) { uint8_t plantain_calculate_luhn(uint64_t number) {
// No. // No.
UNUSED(number); UNUSED(number);
@ -116,26 +93,15 @@ bool plantain_parser_parse(NfcDeviceData* dev_data) {
FuriString* card_number_str; FuriString* card_number_str;
card_number_str = furi_string_alloc(); card_number_str = furi_string_alloc();
// Should look like "361301047292848684" // Should look like "361301047292848684"
// %llu doesn't work for some reason in sprintf, so we use string_push_uint64 instead furi_string_printf(card_number_str, "%llu", card_number);
string_push_uint64(card_number, card_number_str);
// Add suffix with luhn checksum (1 digit) to the card number string // Add suffix with luhn checksum (1 digit) to the card number string
FuriString* card_number_suffix; FuriString* card_number_suffix;
card_number_suffix = furi_string_alloc(); card_number_suffix = furi_string_alloc();
// The number to calculate the checksum on doesn't fit into uint64_t, idk
//uint8_t luhn_checksum = plantain_calculate_luhn(card_number);
// // Convert luhn checksum to string
// FuriString* luhn_checksum_str;
// luhn_checksum_str = furi_string_alloc();
// string_push_uint64(luhn_checksum, luhn_checksum_str);
furi_string_cat_printf(card_number_suffix, "-"); furi_string_cat_printf(card_number_suffix, "-");
// FURI_LOG_D("plant4k", "Card checksum: %d", luhn_checksum);
furi_string_cat_printf(card_number_str, furi_string_get_cstr(card_number_suffix)); furi_string_cat_printf(card_number_str, furi_string_get_cstr(card_number_suffix));
// Free all not needed strings // Free all not needed strings
furi_string_free(card_number_suffix); furi_string_free(card_number_suffix);
// furi_string_free(luhn_checksum_str);
furi_string_printf( furi_string_printf(
dev_data->parsed_data, dev_data->parsed_data,

View File

@ -8,6 +8,4 @@ bool plantain_parser_read(NfcWorker* nfc_worker, FuriHalNfcTxRxContext* tx_rx);
bool plantain_parser_parse(NfcDeviceData* dev_data); bool plantain_parser_parse(NfcDeviceData* dev_data);
void string_push_uint64(uint64_t input, FuriString* output);
uint8_t plantain_calculate_luhn(uint64_t number); uint8_t plantain_calculate_luhn(uint64_t number);

View File

@ -121,26 +121,15 @@ bool two_cities_parser_parse(NfcDeviceData* dev_data) {
FuriString* card_number_str; FuriString* card_number_str;
card_number_str = furi_string_alloc(); card_number_str = furi_string_alloc();
// Should look like "361301047292848684" // Should look like "361301047292848684"
// %llu doesn't work for some reason in sprintf, so we use string_push_uint64 instead furi_string_printf(card_number_str, "%llu", card_number);
string_push_uint64(card_number, card_number_str);
// Add suffix with luhn checksum (1 digit) to the card number string // Add suffix with luhn checksum (1 digit) to the card number string
FuriString* card_number_suffix; FuriString* card_number_suffix;
card_number_suffix = furi_string_alloc(); card_number_suffix = furi_string_alloc();
// The number to calculate the checksum on doesn't fit into uint64_t, idk
//uint8_t luhn_checksum = two_cities_calculate_luhn(card_number);
// // Convert luhn checksum to string
// FuriString* luhn_checksum_str;
// luhn_checksum_str = furi_string_alloc();
// string_push_uint64(luhn_checksum, luhn_checksum_str);
furi_string_cat_printf(card_number_suffix, "-"); furi_string_cat_printf(card_number_suffix, "-");
// FURI_LOG_D("plant4k", "Card checksum: %d", luhn_checksum);
furi_string_cat_printf(card_number_str, furi_string_get_cstr(card_number_suffix)); furi_string_cat_printf(card_number_str, furi_string_get_cstr(card_number_suffix));
// Free all not needed strings // Free all not needed strings
furi_string_free(card_number_suffix); furi_string_free(card_number_suffix);
// furi_string_free(luhn_checksum_str);
// ===== // =====
// --PLANTAIN-- // --PLANTAIN--