Print more information about loaded season ticket

This commit is contained in:
Sanduuz
2026-06-21 21:53:52 +03:00
parent 25f19a02ce
commit 36f55d303e
3 changed files with 51 additions and 2 deletions
+28 -1
View File
@@ -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);
+6
View File
@@ -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,
+17 -1
View File
@@ -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};