Commit 02dd54f9 authored by Volker Krause's avatar Volker Krause
Browse files

Expose the low-level ERA SSB reading methods to JS

Helps with ERA SSB tickets deviating from the standard, such as the
Trenitalia one, removing the need for using the JS bit array API.
parent db677859
Pipeline #81966 passed with stage
in 13 minutes and 54 seconds
......@@ -18,14 +18,14 @@ enum {
SSBTicketBase::SSBTicketBase() = default;
SSBTicketBase::~SSBTicketBase() = default;
uint64_t SSBTicketBase::readNumber(int start, int length) const
quint64 SSBTicketBase::readNumber(int start, int length) const
{
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 {};
}
uint64_t num = 0;
quint64 num = 0;
for (int i = 0; i < 8; ++i) {
num <<= 8;
num |= (uint8_t)*(m_data.constData() + (start / 8) + i);
......
......@@ -8,6 +8,7 @@
#include "kitinerary_export.h"
#include <qobjectdefs.h>
#include <QByteArray>
#include <cstdint>
......@@ -17,13 +18,14 @@ namespace KItinerary {
/** Internal base class for ERA SSB tickets. */
class KITINERARY_EXPORT SSBTicketBase
{
Q_GADGET
protected:
SSBTicketBase();
~SSBTicketBase();
// start and length in bits
uint64_t readNumber(int start, int length) const;
QString readString(int start, int length) const;
Q_INVOKABLE quint64 readNumber(int start, int length) const;
Q_INVOKABLE QString readString(int start, int length) const;
QByteArray m_data;
};
......
......@@ -64,11 +64,10 @@ function parsePdf(pdf) {
personalRes.programMembershipUsed.programName = "CartaFRECCIA";
}
var bitArray = ByteArray.toBitArray(barcode);
var seatNum = bitArray.readNumberMSB(31*8 + 2, 7);
const seatNum = ssb.readNumber(31*8 + 2, 7);
if (seatNum > 0) {
personalRes.reservedTicket.ticketedSeat.seatNumber = "" + seatNum;
var seatCol = bitArray.readNumberMSB(32*8 + 3, 4);
const seatCol = ssb.readNumber(32*8 + 3, 4);
if (seatCol > 0) {
personalRes.reservedTicket.ticketedSeat.seatNumber += seatCol.toString(16).toUpperCase();
}
......
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