Commit 3b66eae3 authored by Volker Krause's avatar Volker Krause
Browse files

Properly decode long numerical fields in ERA SSB v1 tickets

parent d6ba3c3a
......@@ -18,9 +18,9 @@ enum {
SSBTicketBase::SSBTicketBase() = default;
SSBTicketBase::~SSBTicketBase() = default;
int SSBTicketBase::readNumber(int start, int length) const
uint64_t SSBTicketBase::readNumber(int start, int length) const
{
if (start < 0 || length < 1 || start / 8 >= m_data.size() || (start + length) / 8 >= m_data.size() || length > 31) {
if (start < 0 || length < 1 || start / 8 >= m_data.size() || (start + length) / 8 >= m_data.size() || length > 63) {
qWarning() << "invalid SSB read:" << start << length;
return {};
}
......
......@@ -11,6 +11,8 @@
#include <QByteArray>
#include <cstdint>
namespace KItinerary {
/** Internal base class for ERA SSB tickets. */
......@@ -21,7 +23,7 @@ protected:
~SSBTicketBase();
// start and length in bits
int readNumber(int start, int length) const;
uint64_t readNumber(int start, int length) const;
QString readString(int start, int length) const;
QByteArray m_data;
......@@ -31,6 +33,10 @@ protected:
public: \
inline int Name() const { return readNumber(Start, Len); } \
Q_PROPERTY(int Name READ Name)
#define SSB_LONG_PROPERTY(Name, Start, Len) \
public: \
inline quint64 Name() const { return readNumber(Start, Len); } \
Q_PROPERTY(quint64 Name READ Name)
#define SSB_STR_PROPERTY(Name, Start, Len) \
public: \
inline QString Name() const { return readString(Start, Len); } \
......
......@@ -29,7 +29,7 @@ class KITINERARY_EXPORT SSBv1Ticket : protected SSBTicketBase
SSB_NUM_PROPERTY(firstDayOfValidity, 39, 9)
SSB_NUM_PROPERTY(lastDayOfValidity, 48, 9)
SSB_NUM_PROPERTY(customerNumberType, 57, 1)
SSB_NUM_PROPERTY(customerNumber, 58, 47) // ???
SSB_LONG_PROPERTY(customerNumber, 58, 47)
SSB_NUM_PROPERTY(departureStationType, 105, 1)
SSB_NUM_PROPERTY(departureStationNum, 106, 30)
SSB_STR_PROPERTY(departureStationAlpha, 106, 5)
......@@ -38,7 +38,7 @@ class KITINERARY_EXPORT SSBv1Ticket : protected SSBTicketBase
SSB_STR_PROPERTY(arrivalStationAlpha, 137, 5)
SSB_NUM_PROPERTY(departureTime, 167, 6)
SSB_NUM_PROPERTY(trainNumber, 173, 17)
SSB_NUM_PROPERTY(reservationReference, 190, 40)
SSB_LONG_PROPERTY(reservationReference, 190, 40)
SSB_NUM_PROPERTY(classOfTransport, 230, 6)
SSB_NUM_PROPERTY(coachNumber, 236, 10)
SSB_NUM_PROPERTY(seatNumber, 246, 7)
......
......@@ -41,7 +41,7 @@ QString SSBv3Ticket::readString(int start, int length) const
QString res;
res.resize(length);
for (int i = 0; i < length; ++i) {
res[i] = QChar(readNumber(start + SSB_CHAR_WIDTH * i, SSB_CHAR_WIDTH) + 32);
res[i] = QLatin1Char((uint8_t)readNumber(start + SSB_CHAR_WIDTH * i, SSB_CHAR_WIDTH) + 32);
}
return res;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment