2020-04-15 21:47:55 +02:00
|
|
|
#include "../headers/scstwappbackend.h"
|
|
|
|
|
|
|
|
ScStwAppBackend::ScStwAppBackend(QObject *parent) : QObject(parent)
|
|
|
|
{
|
2020-07-10 15:20:41 +02:00
|
|
|
this->scStwClient = new ScStwClient(this);
|
2020-07-06 15:04:02 +02:00
|
|
|
|
2020-10-03 18:35:37 +02:00
|
|
|
this->appSettings = new ScStwAppSettings(this->scStwClient, this);
|
2020-07-06 15:04:02 +02:00
|
|
|
|
2020-10-03 18:35:37 +02:00
|
|
|
this->race = new ScStwRemoteRace(this->scStwClient, this->appSettings, this);
|
|
|
|
this->race->addTimer(new ScStwTimer(this));
|
2020-07-06 15:04:02 +02:00
|
|
|
|
|
|
|
this->scStwClient->setIP(this->appSettings->readSetting(ScStwAppSettings::BaseStationIpSetting).toString());
|
2020-07-10 15:20:41 +02:00
|
|
|
|
2020-04-15 21:47:55 +02:00
|
|
|
this->timerTextRefreshTimer = new QTimer(this);
|
|
|
|
this->timerTextRefreshTimer->setInterval(1);
|
|
|
|
this->timerTextRefreshTimer->setSingleShot(true);
|
|
|
|
this->timerTextRefreshTimer->connect(this->timerTextRefreshTimer, &QTimer::timeout, this, &ScStwAppBackend::refreshTimerText);
|
|
|
|
this->refreshTimerText();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------
|
|
|
|
// --- helper functions ---
|
|
|
|
// ------------------------
|
|
|
|
|
|
|
|
void ScStwAppBackend::refreshTimerText() {
|
|
|
|
|
|
|
|
// --- refresh timer text ---
|
2020-04-17 19:57:33 +02:00
|
|
|
if(this->getRace()->getState() == ScStwRace::RUNNING) {
|
|
|
|
emit this->getRace()->timersChanged();
|
|
|
|
}
|
2020-04-15 21:47:55 +02:00
|
|
|
|
|
|
|
// --- refresh next start action delay progress ---
|
2020-10-01 14:19:47 +02:00
|
|
|
if(this->getRace()->getState() == ScStwRace::WAITING || this->getRace()->getState() == ScStwRace::PREPAIRING) {
|
2020-10-02 16:49:43 +02:00
|
|
|
emit this->getRace()->currentStartDelayChanged();
|
2020-04-17 19:57:33 +02:00
|
|
|
}
|
2020-04-15 21:47:55 +02:00
|
|
|
|
|
|
|
this->timerTextRefreshTimer->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
// - athlete management -
|
|
|
|
|
2020-04-19 13:09:46 +02:00
|
|
|
// TODO: move to client
|
2020-04-15 21:47:55 +02:00
|
|
|
QVariant ScStwAppBackend::getAthletes() {
|
|
|
|
QVariantMap reply = this->scStwClient->sendCommand(4003);
|
|
|
|
|
|
|
|
if(reply["status"] != 200){
|
|
|
|
//handle Error!!
|
|
|
|
qDebug() << "+ --- error getting athletes: " << reply["status"];
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariantMap tmpAthletes = reply["data"].toMap();
|
|
|
|
|
|
|
|
//qDebug() << tmpAthletes;
|
|
|
|
|
|
|
|
return tmpAthletes;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScStwAppBackend::createAthlete(QString userName, QString fullName) {
|
|
|
|
|
|
|
|
QVariant requestData = QVariantMap({{"fullName", fullName}, {"userName", userName}});
|
|
|
|
|
|
|
|
QVariantMap reply = this->scStwClient->sendCommand(4001, requestData.toJsonValue());
|
|
|
|
|
|
|
|
if(reply["status"] != 200){
|
|
|
|
//handle Error!!
|
|
|
|
qDebug() << "+ --- error creating athlete: " << reply["status"];
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScStwAppBackend::deleteAthlete( QString userName ){
|
|
|
|
|
|
|
|
QVariant requestData = QVariantMap({{"userName", userName}});
|
|
|
|
|
|
|
|
QVariantMap reply = this->scStwClient->sendCommand(4002, requestData.toJsonValue());
|
|
|
|
|
|
|
|
if(reply["status"] != 200){
|
|
|
|
//handle Error!!
|
|
|
|
qDebug() << "+ --- error deleting athlete: " << reply["status"];
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScStwAppBackend::selectAthlete( QString userName, int timerId ){
|
|
|
|
|
|
|
|
QVariant requestData = QVariantMap({{"userName", userName}, {"timerId", timerId}});
|
|
|
|
|
|
|
|
QVariantMap reply = this->scStwClient->sendCommand(4000, requestData.toJsonValue());
|
|
|
|
|
|
|
|
if(reply["status"] != 200){
|
|
|
|
//handle Error!!
|
|
|
|
qDebug() << "+ --- error selecting athlete: " << reply["status"];
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant ScStwAppBackend::getResults( QString userName ){
|
|
|
|
QVariantMap reply = this->scStwClient->sendCommand(4004, userName);
|
|
|
|
|
|
|
|
if(reply["status"] != 200){
|
|
|
|
//handle Error!!
|
|
|
|
qDebug() << "+ --- error getting results: " << reply["status"];
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariantList tmpAthletes = reply["data"].toList();
|
|
|
|
|
|
|
|
//qDebug() << tmpAthletes;
|
|
|
|
|
|
|
|
return tmpAthletes;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------
|
|
|
|
// --- functions for qml ---
|
|
|
|
// -------------------------
|
|
|
|
|
|
|
|
ScStwRace* ScStwAppBackend::getRace() {
|
2020-10-03 18:35:37 +02:00
|
|
|
return this->race;
|
2020-04-19 13:09:46 +02:00
|
|
|
}
|
|
|
|
|
2020-07-06 15:04:02 +02:00
|
|
|
ScStwAppSettings * ScStwAppBackend::getSettings() {
|
|
|
|
return this->appSettings;
|
|
|
|
}
|
|
|
|
|
2020-04-19 13:09:46 +02:00
|
|
|
ScStwClient* ScStwAppBackend::getScStwClient() {
|
|
|
|
return this->scStwClient;
|
2020-04-15 21:47:55 +02:00
|
|
|
}
|