From 36f55d303e5bb8d76be2a2b6f0b69a0d29afdbc0 Mon Sep 17 00:00:00 2001 From: Sanduuz Date: Sun, 21 Jun 2026 21:53:52 +0300 Subject: [PATCH] Print more information about loaded season ticket --- client/src/parsers/hrtparser/hrtparser.c | 29 +++++++++++++++++++++++- client/src/parsers/hrtparser/hrtparser.h | 6 +++++ client/src/parsers/parsehrt.c | 18 ++++++++++++++- 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/client/src/parsers/hrtparser/hrtparser.c b/client/src/parsers/hrtparser/hrtparser.c index d754c5a38..eca9816b3 100644 --- a/client/src/parsers/hrtparser/hrtparser.c +++ b/client/src/parsers/hrtparser/hrtparser.c @@ -133,6 +133,33 @@ int convert_get_short_value( return (int)((value >> shift) & mask); } +int convert_get_int_value( + const uint8_t *data, + size_t data_len, + int bit_offset, + int bit_length +) { + if (!data || bit_length <= 0) return 0; + + if (bit_length > 25) bit_length = 25; + + int byte_idx = bit_offset / 8; + int bit_idx = bit_offset % 8; + + if ((size_t)(byte_idx + 3) >= data_len) return 0; + + uint32_t value = + ((uint32_t)data[byte_idx] << 24) | + ((uint32_t)data[byte_idx + 1] << 16) | + ((uint32_t)data[byte_idx + 2] << 8) | + ((uint32_t)data[byte_idx + 3]); + + uint32_t mask = (1U << bit_length) - 1U; + int shift = (32 - bit_idx) - bit_length; + + return (int)((value >> shift) & mask); +} + static time_t hrt_apply_local_offset(time_t time) { struct tm local_time = {0}; struct tm utc_time = {0}; @@ -615,7 +642,7 @@ void hrt_read_period_pass_v2(hrt_travel_card_t *card, const uint8_t *data, size_ convert_get_short_value(data, data_len, 141, 11) ); card->loaded_period_length = convert_get_short_value(data, data_len, 152, 9); - card->loaded_period_price = convert_get_short_value(data, data_len, 161, 20); + card->loaded_period_price = convert_get_int_value(data, data_len, 161, 20); card->period_loading_organization = convert_get_short_value(data, data_len, 181, 14); card->period_loading_device_number = convert_get_short_value(data, data_len, 195, 13); diff --git a/client/src/parsers/hrtparser/hrtparser.h b/client/src/parsers/hrtparser/hrtparser.h index 3285723d1..c3925713f 100644 --- a/client/src/parsers/hrtparser/hrtparser.h +++ b/client/src/parsers/hrtparser/hrtparser.h @@ -161,6 +161,12 @@ int convert_get_byte_value( int bit_offset, int bit_length ); +int convert_get_int_value( + const uint8_t *data, + size_t data_len, + int bit_offset, + int bit_length +); int convert_get_short_value( const uint8_t *data, size_t data_len, diff --git a/client/src/parsers/parsehrt.c b/client/src/parsers/parsehrt.c index 7ff79a897..c92afcc7b 100644 --- a/client/src/parsers/parsehrt.c +++ b/client/src/parsers/parsehrt.c @@ -170,6 +170,17 @@ static void hrt_print_time(const char *label, time_t value) { PrintAndLogEx(SUCCESS, "%s " _GREEN_("%s"), label, buf); } +static bool hrt_has_loaded_period_info(const hrt_travel_card_t *card) { + if (card == NULL) return false; + + return hrt_travelcard_get_loaded_period_product(card) > 0 || + hrt_travelcard_get_loaded_period_length(card) > 0 || + hrt_travelcard_get_loaded_period_price(card) > 0 || + hrt_travelcard_get_period_loading_date(card) != (time_t)0 || + hrt_travelcard_get_period_loading_organization(card) > 0 || + hrt_travelcard_get_period_loading_device_number(card) > 0; +} + static void hrt_print_card(const hrt_travel_card_t *card) { if (card == NULL) return; @@ -217,7 +228,12 @@ static void hrt_print_card(const hrt_travel_card_t *card) { } hrt_print_time(" Start date.............", hrt_travelcard_get_period_start_date1(card)); hrt_print_time(" End date...............", hrt_travelcard_get_period_end_date1(card)); - PrintAndLogEx(SUCCESS, " Season ticket length... " _GREEN_("%d days"), hrt_travelcard_get_period_length1(card)); + PrintAndLogEx(SUCCESS, " Length................. " _GREEN_("%d days"), hrt_travelcard_get_period_length1(card)); + + if (hrt_has_loaded_period_info(card)) { + PrintAndLogEx(SUCCESS, " Organization........... " _GREEN_("%d"), hrt_travelcard_get_period_loading_organization(card)); + PrintAndLogEx(SUCCESS, " Device number.......... " _GREEN_("%d"), hrt_travelcard_get_period_loading_device_number(card)); + } if (hrt_eticket_is_defined(value_ticket)) { char fare_buf[32] = {0};