Commit b04c7b10 authored by Volker Krause's avatar Volker Krause
Browse files

Decode ERA SSB v1 date/time fields

parent ce3c602a
......@@ -44,6 +44,25 @@ bool SSBv1Ticket::maybeSSB(const QByteArray& data)
return (data.at(0) >> 4) == SSB_VERSION;
}
QDate SSBv1Ticket::firstDayOfValidity(const QDate &contextDate) const
{
if (!isValid() || firstDayOfValidityDay() == 0 || firstDayOfValidityDay() > 366) {
return {};
}
QDate d(contextDate.year(), 1, 1);
return d.addDays(firstDayOfValidityDay() - 1);
}
QDateTime SSBv1Ticket::departureTime(const QDate &contextDate) const
{
if (!isValid() || departureTimeSlot() == 0 || departureTimeSlot() > 48) {
return {};
}
QDateTime dt(firstDayOfValidity(contextDate), {0, 0});
return dt.addSecs(60 * 30 * (departureTimeSlot() - 1));
}
QByteArray SSBv1Ticket::rawData() const
{
return m_data;
......
......@@ -10,6 +10,7 @@
#include "kitinerary_export.h"
#include "ssbticketbase.h"
#include <QDate>
#include <QMetaType>
namespace KItinerary {
......@@ -26,8 +27,9 @@ class KITINERARY_EXPORT SSBv1Ticket : protected SSBTicketBase
SSB_NUM_PROPERTY(numberOfTickets, 19, 6)
SSB_NUM_PROPERTY(numberOfAdultPassengers, 25, 7)
SSB_NUM_PROPERTY(numberOfChildPassengers, 32, 7)
SSB_NUM_PROPERTY(firstDayOfValidity, 39, 9)
SSB_NUM_PROPERTY(lastDayOfValidity, 48, 9)
/** Days since Jan 01. */
SSB_NUM_PROPERTY(firstDayOfValidityDay, 39, 9)
SSB_NUM_PROPERTY(lastDayOfValidityDay, 48, 9)
SSB_NUM_PROPERTY(customerNumberType, 57, 1)
SSB_LONG_PROPERTY(customerNumber, 58, 47)
SSB_NUM_PROPERTY(departureStationType, 105, 1)
......@@ -36,9 +38,13 @@ class KITINERARY_EXPORT SSBv1Ticket : protected SSBTicketBase
SSB_NUM_PROPERTY(arrivalStationType, 136, 1)
SSB_NUM_PROPERTY(arrivalStationNum, 137, 30)
SSB_STR_PROPERTY(arrivalStationAlpha, 137, 5)
SSB_NUM_PROPERTY(departureTime, 167, 6)
/** departure time encoded as 48 30min time slots */
SSB_NUM_PROPERTY(departureTimeSlot, 167, 6)
SSB_NUM_PROPERTY(trainNumber, 173, 17)
SSB_LONG_PROPERTY(reservationReference, 190, 40)
/** ERA/TD/2009-14/INT: PASSENGER CODE LIST TO TAP TSI - §B.5.24 - Class
* Possible values are: 1 (1st), 2 (2nd), C (Club), P (Superior), T (Tourist)
*/
SSB_NUM_PROPERTY(classOfTransport, 230, 6)
SSB_NUM_PROPERTY(coachNumber, 236, 10)
SSB_NUM_PROPERTY(seatNumber, 246, 7)
......@@ -59,6 +65,11 @@ public:
/** Returns @c true if this is a valid SSB ticket. */
bool isValid() const;
/** First day of validity. */
Q_INVOKABLE QDate firstDayOfValidity(const QDate &contextDate = QDate::currentDate()) const;
/** Decoded departure time slot. */
Q_INVOKABLE QDateTime departureTime(const QDate &contextDate = QDate::currentDate()) const;
/** Raw barcode data. */
QByteArray rawData() const;
......
......@@ -113,6 +113,10 @@ static void dumpSsbv1Ticket(const QByteArray &data)
break;
}
}
std::cout << std::endl;
std::cout << "First day of validitiy: " << qPrintable(ticket.firstDayOfValidity().toString(Qt::ISODate)) << std::endl;
std::cout << "Departure time: " << qPrintable(ticket.departureTime().toString(Qt::ISODate)) << std::endl;
}
static void dumpRawData(const char *data, std::size_t size)
......
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