Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Checks:
-readability-inconsistent-declaration-parameter-name,
-readability-isolate-declaration,
-readability-magic-numbers,
-readability-math-missing-parentheses,
-readability-named-parameter,
-readability-non-const-parameter,
-readability-qualified-auto,
Expand Down
5 changes: 2 additions & 3 deletions libqf/plugins/qf/core/core.qrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<RCC>
<qresource prefix="/qf/core">
<file>qml/js/stringext.js</file>
<file>qml/js/timeext.js</file>
<file>qml/js/treetable.js</file>
<file>qml/js/stringext.js</file>
<file>qml/js/treetable.js</file>
</qresource>
</RCC>
1 change: 1 addition & 0 deletions libquickevent/libquickeventcore/libquickeventcore.qrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<RCC>
<qresource prefix="/quickevent/core">
<file>js/ogtime.js</file>
<file>js/timeext.js</file>
</qresource>
</RCC>
2 changes: 1 addition & 1 deletion libquickevent/libquickeventcore/src/si/checkedcard.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class QUICKEVENTCORE_DECL_EXPORT CheckedCard : public QVariantMap
QF_VARIANTMAP_FIELD(QVariantList, p, setP, unches)
QF_VARIANTMAP_FIELD(bool, is, set, BadCheck)
QF_VARIANTMAP_FIELD(bool, is, set, MisPunch)

QF_VARIANTMAP_FIELD(QVariantMap, d, setD, ata)
public:
CheckedCard(const QVariantMap &data = QVariantMap());

Expand Down
3 changes: 3 additions & 0 deletions libquickevent/libquickeventcore/src/si/readcard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ ReadCard::ReadCard(const QSqlRecord &rec)
punchlst << punch;
}
this->setPunches(punchlst);
auto s = rec.value("data").toString();
auto data = qf::core::Utils::jsonToQVariant(s).toMap();
setData(data);
}

int ReadCard::punchCount() const
Expand Down
9 changes: 3 additions & 6 deletions libquickevent/libquickeventcore/src/si/readcard.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@

class QSqlRecord;

namespace siut { class SICard; }

namespace quickevent {
namespace core {
namespace si {
namespace quickevent::core::si {

class QUICKEVENTCORE_DECL_EXPORT ReadPunch : public QVariantMap
{
Expand Down Expand Up @@ -49,6 +45,7 @@ class QUICKEVENTCORE_DECL_EXPORT ReadCard : public QVariantMap
QF_VARIANTMAP_FIELD(int, f, setF, inishTimeMs)
QF_VARIANTMAP_FIELD(QVariantList, p, setP, unches)
QF_VARIANTMAP_FIELD(QString, r, setR, unIdAssignError)
QF_VARIANTMAP_FIELD(QVariantMap, d, setD, ata)
public:
ReadCard(const QVariantMap &data = QVariantMap()) : QVariantMap(data) {}
ReadCard(const QSqlRecord &rec);
Expand All @@ -59,5 +56,5 @@ class QUICKEVENTCORE_DECL_EXPORT ReadCard : public QVariantMap
QString toString() const;
};

}}}
}

101 changes: 92 additions & 9 deletions libsiut/src/device/sitask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,70 @@ void SiTaskReadCard8::start()
sendCommand((int)SIMessageData::Command::GetSICard8, QByteArray(1, 0x00));
}
}

/*
CARD 10, block 0
00 0000 02 ef 83 00 01 00 85 df c1 9b ea ea ea ea 0c 0f
01 0010 9c d0 ee ee ee ee 8c a5 a6 3a 08 2c 09 31 0f 7b
02 0020 3a e3 0b 17 58 66 38 30 37 36 30 30 33 3b 4b 65
03 0030 41 72 20 73 2e 72 2e 6f 2e 3b 3b 3b 3b 3b 3b 3b
04 0040 3b 3b 3b ee ee ee ee ee ee ee ee ee ee ee ee ee
05 0050 ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee
06 0060 ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee
07 0070 ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee
08 0080 ee ee ee ee ee ee 5b f8 03

SIAC, block 0
00 0000 02 ef 83 00 04 00 ad 49 13 9e ea ea ea ea 0d 03
01 0010 55 1b ee ee ee ee 8d da 6a 58 11 14 12 33 0f 7d
02 0020 86 13 07 18 3f 78 38 32 32 36 33 32 33 3b 48 2e
03 0030 53 2e 48 2e 20 53 70 6f 72 74 20 73 2e 72 2e 6f
04 0040 2e 3b 3b 3b 3b 3b 3b 3b 3b 3b 3b ee ee ee ee ee
05 0050 ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee
06 0060 ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee
07 0070 ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee
08 0080 ee ee ee ee ee ee 0c b1 03

both have card serie == 15
*/
namespace {
enum class CardTypeByNumber {
InvalidNumber,
Siac,
Card11,
Card10,
Card9,
Card8,
Card6,
Card5,
pCard,
};

CardTypeByNumber cardNumberToType(int number)
{
if (number < 500000) {
return CardTypeByNumber::Card5;
}
if (number < 1000000 || (number >= 2003000 && number < 2004000)) {
return CardTypeByNumber::Card6;
}
if ((number >= 2000000 && number < 2003000) || (number >= 2004000 && number < 3000000)) {
return CardTypeByNumber::Card8;
}
if (number >= 1000000 && number < 2000000) {
return CardTypeByNumber::Card9;
}
if (number >= 7000000 && number < 8000000) {
return CardTypeByNumber::Card10;
}
if (number >= 8000000 && number < 9000000) {
return CardTypeByNumber::Siac;
}
if (number >= 9000000 && number < 10000000) {
return CardTypeByNumber::Card11;
}
return CardTypeByNumber::InvalidNumber;
}
}
void SiTaskReadCard8::onSiMessageReceived(const SIMessageData &msg)
{
SIMessageData::Command cmd = msg.command();
Expand All @@ -586,6 +649,7 @@ void SiTaskReadCard8::onSiMessageReceived(const SIMessageData &msg)
int station_number = (int)SIPunch::getUnsigned(data, base - 3);
int card_number = (int)SIPunch::getUnsigned(data, base + 0x19, 3);
m_cardSerie = static_cast<CardSerie>(((uint8_t)data[base + 0x18]) & 15);
qfInfo() << "CS:" << m_cardSerie;
logCardRead() << "CS:" << m_cardSerie << cardSerieToString(m_cardSerie) << "SI:" << card_number;
m_card.setStationNumber(station_number);
m_card.setCardNumber(card_number);
Expand Down Expand Up @@ -619,8 +683,17 @@ void SiTaskReadCard8::onSiMessageReceived(const SIMessageData &msg)
sendCommand((int)SIMessageData::Command::GetSICard8, QByteArray(1, 0x01));
else if(m_cardSerie == pCard)
sendCommand((int)SIMessageData::Command::GetSICard8, QByteArray(1, 0x01));
else if(m_cardSerie == Siac)
sendCommand((int)SIMessageData::Command::GetSICard8, QByteArray(1, 0x03));
else if(m_cardSerie == Siac) {
if (cardNumberToType(m_card.cardNumber()) == CardTypeByNumber::Siac) {
// Invoke battery voltage measurement
// 02 EA 05 7E 05 05 05 05 B2 31 03 - EA - PROBABLY SIAC battery measurement request
auto ba = QByteArray::fromHex("7E05050505");
sendCommand((int)SIMessageData::Command::SiacMeasureBattery, ba);
} else {
// Card 10, 11
sendCommand((int)SIMessageData::Command::GetSICard8, QByteArray(1, 0x04));
}
}
}
}
else {
Expand Down Expand Up @@ -682,11 +755,14 @@ void SiTaskReadCard8::onSiMessageReceived(const SIMessageData &msg)
}
else if(m_cardSerie == Siac) {
if(block_number == 3) {
// read battery date
// read battery data
SiCardBatteryStatus battery_status;
int yy = (uint8_t)data[base + (0xf*4) + 0];
int mm = (uint8_t)data[base + (0xf*4) + 1];
int dd = (uint8_t)data[base + (0xf*4) + 2];
logCardRead().nospace() << "SIAC batery date: " << (2000 + yy) << '-' << mm << '-' << dd;
QDate date(yy + 2000, mm, dd);
battery_status.setReplaceDate(date.toString(Qt::ISODate));
logCardRead().nospace() << "SIAC batery date: " << battery_status.replaceDate();
auto hw_ver_1 = (uint8_t)data[base + (0x10*4) + 0];
auto hw_ver_0 = (uint8_t)data[base + (0x10*4) + 1];
auto sw_ver_1 = (uint8_t)data[base + (0x10*4) + 2];
Expand All @@ -696,11 +772,14 @@ void SiTaskReadCard8::onSiMessageReceived(const SIMessageData &msg)
auto mvbat = (uint8_t)data[base + (0x11*4) + 3];
auto rbat = (uint8_t)data[base + (0x15*4) + 0];
auto lbat = (uint8_t)data[base + (0x15*4) + 1];
logCardRead().nospace() << "MVBAT: " << mvbat << " 0x" << QString::number(mvbat, 16);
logCardRead().nospace() << "RBAT : " << rbat << " 0x" << QString::number(rbat, 16);
logCardRead().nospace() << "LBAT : " << lbat << " 0x" << QString::number(lbat, 16) << " " << (lbat == 0xAA? "OK": "LOW");
battery_status.setLow(lbat != 0xAA);
battery_status.setVoltage(1.9 + 0.09 * mvbat);
battery_status.setReferenceVoltage(1.9 + 0.09 * rbat);
logCardRead().nospace() << "MVBAT: " << " 0x" << QString::number(mvbat, 16);
logCardRead().nospace() << "RBAT : " << " 0x" << QString::number(rbat, 16);
logCardRead().nospace() << "LBAT : " << " 0x" << QString::number(lbat, 16) << " " << (lbat == 0xAA? "OK": "LOW");
m_card.setBatteryStatus(battery_status);

// read battery status
sendCommand((int)SIMessageData::Command::GetSICard8, QByteArray(1, (char)(block_number + 1)));
}
else if(block_number >= 4 && block_number <= 7) {
Expand Down Expand Up @@ -734,6 +813,10 @@ void SiTaskReadCard8::onSiMessageReceived(const SIMessageData &msg)
}
}
}
else if (cmd == SIMessageData::Command::SiacMeasureBattery) {
// continue SIAC card read out
sendCommand((int)SIMessageData::Command::GetSICard8, QByteArray(1, 0x03));
}
else {
qfError() << "Invalid command:" << "0x" + QString::number((int)cmd, 16) << "received";
if(cmd == SIMessageData::Command::SICardRemoved)
Expand Down
2 changes: 2 additions & 0 deletions libsiut/src/message/simessagedata.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ class SIUT_DECL_EXPORT SIMessageData
SICardRemoved=0xE7,
GetSICard5=0xB1,
GetSICard6=0xE1,
SiacMeasureBattery=0xEA,
GetSICard8=0xEF,

//GetPunch2=0x53, /// autosend only (ie. punch)
SetDirectRemoteMode=0xF0,
//TimeSend=0x54, /// autosend only (ie. trigger data)
Expand Down
4 changes: 1 addition & 3 deletions libsiut/src/sicard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ static QString ob_time_str(int _time)
}
*/

SICard::SICard()
= default;

SICard::SICard(int card_number)
{
setCardNumber(card_number);
Expand All @@ -46,6 +43,7 @@ QString SICard::toString() const
sl << tr("check: %1").arg(time_str(checkTime()));
sl << tr("start: %1").arg(time_str(startTime()));
sl << tr("finish: %1").arg(time_str(finishTime()));
sl << tr("batteryStatus: %1").arg(qf::core::Utils::qvariantToJson(batteryStatus()));
for (int n = 0; n < punchCount(); ++n) {
SIPunch p = punchAt(n);
sl << (" " + QString::number(n+1)).right(4) + ".\t" + QString::number(p.code()) + "\t" + time_str(p.time());
Expand Down
16 changes: 15 additions & 1 deletion libsiut/src/sicard.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@

namespace siut {

class SIUT_DECL_EXPORT SiCardBatteryStatus : public QVariantMap
{
using Super = QVariantMap;
public:
SiCardBatteryStatus() = default;
SiCardBatteryStatus(const QVariantMap &o) : Super(o) {}

QF_VARIANTMAP_FIELD(double, v, setV, oltage)
QF_VARIANTMAP_FIELD(double, r, setR, eferenceVoltage)
QF_VARIANTMAP_FIELD(bool, is, set, Low)
QF_VARIANTMAP_FIELD(QString, r, setR, eplaceDate)
};

class SIUT_DECL_EXPORT SICard : public QVariantMap
{
Q_DECLARE_TR_FUNCTIONS(SICard)
Expand All @@ -19,7 +32,7 @@ class SIUT_DECL_EXPORT SICard : public QVariantMap
using PunchList = QVariantList;
static constexpr int INVALID_SI_TIME = 0xEEEE;

SICard();
SICard() = default;
SICard(const QVariantMap &o) : Super(o) {}
SICard(int card_number);

Expand All @@ -30,6 +43,7 @@ class SIUT_DECL_EXPORT SICard : public QVariantMap
QF_VARIANTMAP_FIELD(int, f, setF, inishTime)
QF_VARIANTMAP_FIELD(int, f, setF, inishTimeMs)
QF_VARIANTMAP_FIELD(QVariantList, p, setP, unches)
QF_VARIANTMAP_FIELD(SiCardBatteryStatus, b, setB, atteryStatus)

QString toString() const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ quickevent::core::si::CheckedCard CardCheckerClassicCpp::checkCard(const quickev

checked_card.setCourseId(course.id());
checked_card.setRunId(run_id);
//checked_card.setPunches();
checked_card.setData(read_card.data());
//Log.info("course:", JSON.stringify(read_card, null, 2));
int stage_id = stageIdForRun(run_id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ int CardReaderPlugin::saveCardToSql(const quickevent::core::si::ReadCard &read_c
punches << p.toJsonArrayString();
}
qf::core::sql::Query q;
q.prepare(QStringLiteral("INSERT INTO cards (stationNumber, siId, checkTime, startTime, finishTime, punches, runId, stageId, readerConnectionId, runIdAssignError)"
" VALUES (:stationNumber, :siId, :checkTime, :startTime, :finishTime, :punches, :runId, :stageId, :readerConnectionId, :runIdAssignError)")
q.prepare(QStringLiteral("INSERT INTO cards (stationNumber, siId, checkTime, startTime, finishTime, punches, runId, stageId, readerConnectionId, runIdAssignError, data)"
" VALUES (:stationNumber, :siId, :checkTime, :startTime, :finishTime, :punches, :runId, :stageId, :readerConnectionId, :runIdAssignError, :data)")
, qf::core::Exception::Throw);
q.bindValue(QStringLiteral(":stationNumber"), read_card.stationNumber());
q.bindValue(QStringLiteral(":siId"), read_card.cardNumber());
Expand All @@ -277,6 +277,7 @@ int CardReaderPlugin::saveCardToSql(const quickevent::core::si::ReadCard &read_c
q.bindValue(QStringLiteral(":stageId"), currentStageId());
q.bindValue(QStringLiteral(":readerConnectionId"), qf::core::sql::Connection::defaultConnection().connectionId());
q.bindValue(QStringLiteral(":runIdAssignError"), read_card.runIdAssignError());
q.bindValue(QStringLiteral(":data"), qf::core::Utils::qvariantToJson(read_card.data()));
if(q.exec()) {
ret = q.lastInsertId().toInt();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,11 @@ void CardReaderWidget::processSICard(const siut::SICard &card)
quickevent::core::si::ReadCard read_card(card);
read_card.setRunId(run_id);
read_card.setRunIdAssignError(err_msg);
if (card.batteryStatus_isset()) {
auto data = read_card.data();
data["batteryStatus"] = card.batteryStatus();
read_card.setData(data);
}
processReadCardInTransaction(read_card);
}

Expand Down
18 changes: 11 additions & 7 deletions quickevent/app/quickevent/plugins/Event/qml/DbSchema.qml
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ Schema {
Field { name: 'id'; type: Serial { primaryKey: true } },
Field { name: 'code'; type: Int { } },
Field { name: 'altCode'; type: Int { } },
Field { name: 'outOfOrder';
type: Boolean { }
Field { name: 'outOfOrder';
type: Boolean { }
defaultValue: false;
notNull: true
},
Field { name: 'radio';
type: Boolean { }
Field { name: 'radio';
type: Boolean { }
defaultValue: false
notNull: true
},
Expand Down Expand Up @@ -124,13 +124,13 @@ Schema {
},
Field { name: 'startTimeMin'; type: Int { } },
Field { name: 'startIntervalMin'; type: Int { } },
Field { name: 'vacantsBefore'; type: Int { }
Field { name: 'vacantsBefore'; type: Int { }
comment: 'place n vacants gap before first competitor in class start list'
},
Field { name: 'vacantEvery'; type: Int { }
Field { name: 'vacantEvery'; type: Int { }
comment: 'place vacant every n-th competitor in class start list'
},
Field { name: 'vacantsAfter'; type: Int { }
Field { name: 'vacantsAfter'; type: Int { }
comment: 'place n vacants gap after last competitor in class start list'
},
Field { name: 'mapCount'; type: Int { } },
Expand Down Expand Up @@ -419,6 +419,10 @@ Schema {
}
comment: 'JSON of format [[code, time, msec, day_of_week, week_cnt], ...]}'
},
Field { name: 'data'
type: String { }
comment: 'JSON of auxiliary card data like Siac battery status, etc.'
},
Field { name: 'readerConnectionId'
type: Int { }
comment: 'connection id of QuickEvent instance which has read this card'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ DbSchema *EventPlugin::dbSchema()
int EventPlugin::dbVersion()
{
// equals to minimal app version compatible with this DB
return 30300;
return 30301;
}

QString EventPlugin::dbVersionString()
Expand Down
Loading