Skip to content

Commit

Permalink
parsers cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Leptopt1los committed Feb 7, 2024
1 parent 95e653c commit 4265b9c
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 48 deletions.
2 changes: 1 addition & 1 deletion applications/main/nfc/plugins/supported_cards/aime.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static bool aime_read(Nfc* nfc, NfcDevice* device) {

nfc_device_set_data(device, NfcProtocolMfClassic, data);

is_read = mf_classic_is_card_read(data);
is_read = (error == MfClassicErrorNone);
} while(false);

mf_classic_free(data);
Expand Down
2 changes: 1 addition & 1 deletion applications/main/nfc/plugins/supported_cards/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static bool hid_read(Nfc* nfc, NfcDevice* device) {

nfc_device_set_data(device, NfcProtocolMfClassic, data);

is_read = mf_classic_is_card_read(data);
is_read = (error == MfClassicErrorNone);
} while(false);

mf_classic_free(data);
Expand Down
6 changes: 3 additions & 3 deletions applications/main/nfc/plugins/supported_cards/kazan.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,22 +214,22 @@ static bool kazan_read(Nfc* nfc, NfcDevice* device) {
}

error = mf_classic_poller_sync_read(nfc, &keys_v1, data);
if(error != MfClassicErrorNone) {
if(error == MfClassicErrorNotPresent) {
FURI_LOG_W(TAG, "Failed to read data: keys_v1");
break;
}

if(!mf_classic_is_card_read(data)) {
error = mf_classic_poller_sync_read(nfc, &keys_v2, data);
if(error != MfClassicErrorNone) {
if(error == MfClassicErrorNotPresent) {
FURI_LOG_W(TAG, "Failed to read data: keys_v1");
break;
}
}

if(!mf_classic_is_card_read(data)) {
error = mf_classic_poller_sync_read(nfc, &keys_v3, data);
if(error != MfClassicErrorNone) {
if(error == MfClassicErrorNotPresent) {
FURI_LOG_W(TAG, "Failed to read data: keys_v3");
break;
}
Expand Down
4 changes: 2 additions & 2 deletions applications/main/nfc/plugins/supported_cards/metromoney.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ static bool metromoney_read(Nfc* nfc, NfcDevice* device) {
}

error = mf_classic_poller_sync_read(nfc, &keys, data);
if(error != MfClassicErrorNone) {
if(error == MfClassicErrorNotPresent) {
FURI_LOG_W(TAG, "Failed to read data");
break;
}

nfc_device_set_data(device, NfcProtocolMfClassic, data);

is_read = mf_classic_is_card_read(data);
is_read = (error == MfClassicErrorNone);
} while(false);

mf_classic_free(data);
Expand Down
4 changes: 2 additions & 2 deletions applications/main/nfc/plugins/supported_cards/saflok.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ static bool saflok_read(Nfc* nfc, NfcDevice* device) {
}

error = mf_classic_poller_sync_read(nfc, &keys, data);
if(error != MfClassicErrorNone) {
if(error == MfClassicErrorNotPresent) {
FURI_LOG_W(TAG, "Failed to read data");
break;
}

nfc_device_set_data(device, NfcProtocolMfClassic, data);

is_read = mf_classic_is_card_read(data);
is_read = (error == MfClassicErrorNone);
} while(false);

mf_classic_free(data);
Expand Down
4 changes: 2 additions & 2 deletions applications/main/nfc/plugins/supported_cards/social_moscow.c
Original file line number Diff line number Diff line change
Expand Up @@ -1534,14 +1534,14 @@ static bool social_moscow_read(Nfc* nfc, NfcDevice* device) {
}

error = mf_classic_poller_sync_read(nfc, &keys, data);
if(error != MfClassicErrorNone) {
if(error == MfClassicErrorNotPresent) {
FURI_LOG_W(TAG, "Failed to read data");
break;
}

nfc_device_set_data(device, NfcProtocolMfClassic, data);

is_read = mf_classic_is_card_read(data);
is_read = (error == MfClassicErrorNone);
} while(false);

mf_classic_free(data);
Expand Down
4 changes: 2 additions & 2 deletions applications/main/nfc/plugins/supported_cards/troika.c
Original file line number Diff line number Diff line change
Expand Up @@ -1559,14 +1559,14 @@ static bool troika_read(Nfc* nfc, NfcDevice* device) {
}

error = mf_classic_poller_sync_read(nfc, &keys, data);
if(error != MfClassicErrorNone) {
if(error == MfClassicErrorNotPresent) {
FURI_LOG_W(TAG, "Failed to read data");
break;
}

nfc_device_set_data(device, NfcProtocolMfClassic, data);

is_read = mf_classic_is_card_read(data);
is_read = (error == MfClassicErrorNone);
} while(false);

mf_classic_free(data);
Expand Down
4 changes: 2 additions & 2 deletions applications/main/nfc/plugins/supported_cards/washcity.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ static bool washcity_read(Nfc* nfc, NfcDevice* device) {
}

error = mf_classic_poller_sync_read(nfc, &keys, data);
if(error != MfClassicErrorNone) {
if(error == MfClassicErrorNotPresent) {
FURI_LOG_W(TAG, "Failed to read data");
break;
}

nfc_device_set_data(device, NfcProtocolMfClassic, data);

is_read = mf_classic_is_card_read(data);
is_read = (error == MfClassicErrorNone);
} while(false);

mf_classic_free(data);
Expand Down
35 changes: 2 additions & 33 deletions applications/main/nfc/plugins/supported_cards/zolotaya_korona.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,6 @@ static const uint8_t info_sector_signature[] = {0xE2, 0x87, 0x80, 0x8E, 0x20, 0x
0xAE, 0xE0, 0xAE, 0xAD, 0xA0, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00};

#define FURI_HAL_RTC_SECONDS_PER_MINUTE 60
#define FURI_HAL_RTC_SECONDS_PER_HOUR (FURI_HAL_RTC_SECONDS_PER_MINUTE * 60)
#define FURI_HAL_RTC_SECONDS_PER_DAY (FURI_HAL_RTC_SECONDS_PER_HOUR * 24)
#define FURI_HAL_RTC_EPOCH_START_YEAR 1970

void timestamp_to_datetime(uint32_t timestamp, FuriHalRtcDateTime* datetime) {
uint32_t days = timestamp / FURI_HAL_RTC_SECONDS_PER_DAY;
uint32_t seconds_in_day = timestamp % FURI_HAL_RTC_SECONDS_PER_DAY;

datetime->year = FURI_HAL_RTC_EPOCH_START_YEAR;

while(days >= furi_hal_rtc_get_days_per_year(datetime->year)) {
days -= furi_hal_rtc_get_days_per_year(datetime->year);
(datetime->year)++;
}

datetime->month = 1;
while(days >= furi_hal_rtc_get_days_per_month(
furi_hal_rtc_is_leap_year(datetime->year), datetime->month)) {
days -= furi_hal_rtc_get_days_per_month(
furi_hal_rtc_is_leap_year(datetime->year), datetime->month);
(datetime->month)++;
}

datetime->day = days + 1;
datetime->hour = seconds_in_day / FURI_HAL_RTC_SECONDS_PER_HOUR;
datetime->minute =
(seconds_in_day % FURI_HAL_RTC_SECONDS_PER_HOUR) / FURI_HAL_RTC_SECONDS_PER_MINUTE;
datetime->second = seconds_in_day % FURI_HAL_RTC_SECONDS_PER_MINUTE;
}

uint64_t bytes2num_bcd(const uint8_t* src, uint8_t len_bytes, bool* is_bcd) {
furi_assert(src);
furi_assert(len_bytes <= 9);
Expand Down Expand Up @@ -151,7 +120,7 @@ static bool zolotaya_korona_parse(const NfcDevice* device, FuriString* parsed_da
const uint16_t refill_counter = nfc_util_bytes2num_little_endian(block_start_ptr + 10, 2);

FuriHalRtcDateTime last_refill_datetime = {0};
timestamp_to_datetime(last_refill_timestamp, &last_refill_datetime);
furi_hal_rtc_timestamp_to_datetime(last_refill_timestamp, &last_refill_datetime);

// block 2: trip block
block_start_ptr = &data->block[start_trip_block_number + 2].data[0];
Expand All @@ -166,7 +135,7 @@ static bool zolotaya_korona_parse(const NfcDevice* device, FuriString* parsed_da
const uint8_t prev_balance_kop = prev_balance % 100;

FuriHalRtcDateTime last_trip_datetime = {0};
timestamp_to_datetime(last_trip_timestamp, &last_trip_datetime);
furi_hal_rtc_timestamp_to_datetime(last_trip_timestamp, &last_trip_datetime);

// PARSE DATA FROM PURSE SECTOR
const uint8_t start_purse_block_number =
Expand Down

0 comments on commit 4265b9c

Please sign in to comment.