2019-03-07 17:18:24 +01:00
|
|
|
#include "headers/climbingrace.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* manages:
|
|
|
|
* - global state
|
|
|
|
* - timers
|
|
|
|
* - sounds
|
|
|
|
* - next start action
|
|
|
|
* - next start action delay progress
|
2019-03-27 22:23:12 +01:00
|
|
|
* - settings (remote and local)
|
2019-03-07 17:18:24 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
ClimbingRace::ClimbingRace(QObject *parent) : QObject(parent)
|
|
|
|
{
|
2020-04-06 17:52:48 +02:00
|
|
|
this->state = ScStw::ScStw::IDLE;
|
2019-03-07 17:18:24 +01:00
|
|
|
this->mode = LOCAL;
|
|
|
|
|
2019-08-20 10:19:35 +02:00
|
|
|
this->appSettings = new AppSettings(this);
|
2020-04-06 17:52:48 +02:00
|
|
|
this->scStwClient = new ScStwClient();
|
2019-03-07 17:18:24 +01:00
|
|
|
|
2020-04-05 14:12:56 +02:00
|
|
|
this->scStwClient->setIP(pGlobalAppSettings->loadSetting("baseStationIpAdress"));
|
|
|
|
connect(this->scStwClient, &ScStwClient::stateChanged, this, &ClimbingRace::baseStationStateChanged);
|
|
|
|
connect(this->scStwClient, &ScStwClient::stateChanged, this, &ClimbingRace::refreshMode);
|
2020-04-06 17:52:48 +02:00
|
|
|
connect(this->scStwClient, &ScStwClient::gotSignal, this, &ClimbingRace::handleBaseStationSignal);
|
|
|
|
connect(this, &ClimbingRace::baseStationStateChanged, this, &ClimbingRace::baseStationPropertiesChanged);
|
2019-03-07 17:18:24 +01:00
|
|
|
|
2019-08-20 10:19:35 +02:00
|
|
|
this->speedTimers.append( new SpeedTimer(this) );
|
2019-03-07 17:18:24 +01:00
|
|
|
|
|
|
|
this->player = new QMediaPlayer;
|
2019-03-24 21:16:16 +01:00
|
|
|
this->date = new QDateTime;
|
2019-03-07 17:18:24 +01:00
|
|
|
|
2019-03-07 22:31:23 +01:00
|
|
|
this->nextStartActionTimer = new QTimer(this);
|
|
|
|
nextStartActionTimer->setSingleShot(true);
|
|
|
|
|
2019-08-20 10:19:35 +02:00
|
|
|
this->timerTextRefreshTimer = new QTimer(this);
|
2019-03-07 17:18:24 +01:00
|
|
|
this->timerTextRefreshTimer->setInterval(1);
|
|
|
|
this->timerTextRefreshTimer->setSingleShot(true);
|
|
|
|
this->timerTextRefreshTimer->connect(this->timerTextRefreshTimer, &QTimer::timeout, this, &ClimbingRace::refreshTimerText);
|
|
|
|
this->refreshTimerText();
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------
|
|
|
|
// --- Main Functionality ---
|
|
|
|
// --------------------------
|
|
|
|
|
|
|
|
int ClimbingRace::startRace() {
|
|
|
|
|
2020-04-06 17:52:48 +02:00
|
|
|
if(this->state != ScStw::IDLE) {
|
2019-03-07 17:18:24 +01:00
|
|
|
return 904;
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug() << "+ --- starting race";
|
|
|
|
|
|
|
|
int returnCode = 900;
|
|
|
|
|
|
|
|
switch (this->mode) {
|
|
|
|
case LOCAL:
|
|
|
|
{
|
|
|
|
|
2020-04-06 17:52:48 +02:00
|
|
|
this->setState(ScStw::STARTING);
|
2019-03-07 17:18:24 +01:00
|
|
|
|
2020-04-06 17:52:48 +02:00
|
|
|
this->nextStartAction = ScStw::None;
|
2019-03-07 17:18:24 +01:00
|
|
|
this->playSoundsAndStartRace();
|
|
|
|
|
|
|
|
returnCode = 200;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case REMOTE:
|
|
|
|
{
|
2020-04-05 14:12:56 +02:00
|
|
|
QVariantMap reply = this->scStwClient->sendCommand(1000);
|
2019-03-07 17:18:24 +01:00
|
|
|
|
|
|
|
if(reply["status"] != 200){
|
|
|
|
//handle Error!!
|
|
|
|
returnCode = reply["status"].toInt();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
returnCode = 200;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return returnCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ClimbingRace::stopRace(int type) {
|
|
|
|
|
2020-04-06 17:52:48 +02:00
|
|
|
if(this->state != ScStw::RUNNING && this->state != ScStw::STARTING) {
|
2019-03-07 17:18:24 +01:00
|
|
|
return 904;
|
|
|
|
}
|
|
|
|
|
|
|
|
// type can be:
|
|
|
|
// 0: stopp
|
|
|
|
// 1: cancel
|
|
|
|
// 2: fail (fase start)
|
|
|
|
|
|
|
|
qDebug() << "+ --- stopping race";
|
|
|
|
|
|
|
|
int returnCode = 900;
|
|
|
|
|
|
|
|
switch (this->mode) {
|
|
|
|
case LOCAL:
|
|
|
|
{
|
|
|
|
|
|
|
|
if(type == 1){
|
|
|
|
this->nextStartActionTimer->stop();
|
|
|
|
this->player->stop();
|
2020-04-06 17:52:48 +02:00
|
|
|
this->nextStartAction = ScStw::None;
|
2019-03-07 17:18:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
returnCode = this->speedTimers[0]->stop(type) ? 200:904;
|
|
|
|
|
|
|
|
if(returnCode == 200) {
|
2020-04-06 17:52:48 +02:00
|
|
|
this->setState(ScStw::STOPPED);
|
2019-03-07 17:18:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case REMOTE:
|
|
|
|
{
|
2020-04-05 14:12:56 +02:00
|
|
|
QVariantMap reply = this->scStwClient->sendCommand(1001);
|
2019-03-07 17:18:24 +01:00
|
|
|
|
|
|
|
if(reply["status"] != 200){
|
|
|
|
returnCode = reply["status"].toInt();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
returnCode = 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return returnCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ClimbingRace::resetRace() {
|
|
|
|
|
2020-04-06 17:52:48 +02:00
|
|
|
if(this->state != ScStw::STOPPED) {
|
2019-03-07 17:18:24 +01:00
|
|
|
return 904;
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug() << "+ --- resetting race";
|
|
|
|
|
|
|
|
int returnCode = 900;
|
|
|
|
|
|
|
|
|
|
|
|
switch (this->mode) {
|
|
|
|
case LOCAL:
|
|
|
|
{
|
|
|
|
returnCode = this->speedTimers[0]->reset() ? 200:904;
|
|
|
|
|
|
|
|
if(returnCode == 200){
|
2020-04-06 17:52:48 +02:00
|
|
|
this->setState(ScStw::IDLE);
|
2019-03-07 17:18:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case REMOTE:
|
|
|
|
{
|
|
|
|
|
2020-04-05 14:12:56 +02:00
|
|
|
QVariantMap reply = this->scStwClient->sendCommand(1002);
|
2019-03-07 17:18:24 +01:00
|
|
|
|
|
|
|
if(reply["status"] != 200){
|
|
|
|
//handle Error!!
|
|
|
|
returnCode = reply["status"].toInt();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
returnCode = 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return returnCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------
|
|
|
|
// --- Base Station sync ---
|
|
|
|
// -------------------------
|
|
|
|
|
2019-10-06 19:02:47 +02:00
|
|
|
/**
|
|
|
|
* @brief ClimbingRace::handleBaseStationUpdate
|
|
|
|
*
|
2020-04-15 21:47:55 +02:00
|
|
|
* Function to handle an update, sent by the base station, which indicates
|
2019-10-06 19:02:47 +02:00
|
|
|
* that some remote value (like a state) has changed
|
|
|
|
*
|
|
|
|
* @param data
|
|
|
|
*/
|
2020-04-06 17:52:48 +02:00
|
|
|
void ClimbingRace::handleBaseStationSignal(ScStw::SignalKey key, QVariant data) {
|
2020-04-06 22:54:28 +02:00
|
|
|
qDebug() << "got signal: " << data;
|
2020-04-06 17:52:48 +02:00
|
|
|
switch (key) {
|
|
|
|
case ScStw::RaceStateChanged:
|
2019-10-06 19:02:47 +02:00
|
|
|
{
|
|
|
|
// the remote race state has changed
|
2020-04-06 22:54:28 +02:00
|
|
|
this->setState( ScStw::RaceState( data.toInt() ) );
|
2019-10-06 19:02:47 +02:00
|
|
|
break;
|
|
|
|
}
|
2020-04-06 17:52:48 +02:00
|
|
|
case ScStw::TimersChanged:
|
2019-10-06 19:02:47 +02:00
|
|
|
{
|
|
|
|
// the remote timers have changed
|
2020-04-06 22:54:28 +02:00
|
|
|
this->refreshRemoteTimers(data.toList());
|
2019-10-06 19:02:47 +02:00
|
|
|
break;
|
|
|
|
}
|
2020-04-06 17:52:48 +02:00
|
|
|
case ScStw::NextStartActionChanged:
|
2019-10-13 16:42:38 +02:00
|
|
|
{
|
|
|
|
// the next start action has changed
|
2020-04-06 22:54:28 +02:00
|
|
|
this->nextStartActionTotalDelay = data.toMap()["nextActionDelay"].toDouble();
|
|
|
|
this->nextStartActionDelayStartedAt = this->date->currentMSecsSinceEpoch() - (this->nextStartActionTotalDelay * data.toMap()["nextActionDelayProg"].toDouble());
|
|
|
|
this->nextStartAction = ScStw::NextStartAction( data.toMap()["nextAction"].toInt() );
|
2019-10-13 16:42:38 +02:00
|
|
|
|
|
|
|
emit this->nextStartActionChanged();
|
2020-04-06 17:52:48 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ScStw::ExtensionsChanged:
|
|
|
|
{
|
|
|
|
emit this->baseStationConnectionsChanged();
|
|
|
|
break;
|
2019-10-13 16:42:38 +02:00
|
|
|
}
|
2020-04-06 22:54:28 +02:00
|
|
|
case ScStw::InvalidSignal:
|
|
|
|
return;
|
2019-10-06 19:02:47 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ClimbingRace::refreshRemoteTimers(QVariantList timers) {
|
|
|
|
|
|
|
|
if(timers.length() != speedTimers.length()){
|
|
|
|
// local timers are out of sync
|
|
|
|
|
|
|
|
// delete all current timers
|
|
|
|
foreach(SpeedTimer * locTimer, this->speedTimers){
|
|
|
|
delete locTimer;
|
|
|
|
}
|
|
|
|
|
|
|
|
speedTimers.clear();
|
|
|
|
|
|
|
|
foreach(QVariant remTimer, timers){
|
|
|
|
// create a local timer for each remote timer
|
|
|
|
this->speedTimers.append(new SpeedTimer(this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach(QVariant remTimer, timers){
|
|
|
|
int currId = remTimer.toMap()["id"].toInt();
|
2020-04-15 21:47:55 +02:00
|
|
|
speedTimers[currId]->startTime = this->date->currentMSecsSinceEpoch() - remTimer.toMap()["currentTime"].toDouble();
|
|
|
|
speedTimers[currId]->stoppedTime = remTimer.toMap()["currentTime"].toDouble();
|
|
|
|
speedTimers[currId]->reactionTime = remTimer.toMap()["reactionTime"].toDouble();
|
2019-10-06 19:02:47 +02:00
|
|
|
|
|
|
|
speedTimers[currId]->setState(SpeedTimer::timerState(remTimer.toMap()["state"].toInt()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-03-07 17:18:24 +01:00
|
|
|
// ------------------------
|
|
|
|
// --- helper functions ---
|
|
|
|
// ------------------------
|
|
|
|
|
|
|
|
void ClimbingRace::playSoundsAndStartRace() {
|
|
|
|
qDebug() << "next Action: " << nextStartAction;
|
|
|
|
|
|
|
|
nextStartActionTimer->disconnect(nextStartActionTimer, SIGNAL(timeout()), this, SLOT(playSoundsAndStartRace()));
|
|
|
|
|
|
|
|
switch (this->nextStartAction) {
|
2020-04-06 17:52:48 +02:00
|
|
|
case ScStw::AtYourMarks:
|
2019-03-07 17:18:24 +01:00
|
|
|
{
|
|
|
|
if(!playSound("qrc:/sounds/at_marks_1.wav")){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(appSettings->loadSetting("ready_en") == "true"){
|
2020-04-06 17:52:48 +02:00
|
|
|
nextStartAction = ScStw::Ready;
|
2019-03-07 17:18:24 +01:00
|
|
|
nextStartActionTimer->setInterval(appSettings->loadSetting("ready_delay").toInt() <= 0 ? 1:appSettings->loadSetting("ready_delay").toInt());
|
|
|
|
}
|
|
|
|
else{
|
2020-04-06 17:52:48 +02:00
|
|
|
nextStartAction = ScStw::Start;
|
2019-03-07 17:18:24 +01:00
|
|
|
nextStartActionTimer->setInterval(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2020-04-06 17:52:48 +02:00
|
|
|
case ScStw::Ready:
|
2019-03-07 17:18:24 +01:00
|
|
|
{
|
|
|
|
if(!playSound("qrc:/sounds/ready_1.wav")){
|
|
|
|
return;
|
|
|
|
}
|
2020-04-06 17:52:48 +02:00
|
|
|
nextStartAction = ScStw::Start;
|
2019-03-07 17:18:24 +01:00
|
|
|
nextStartActionTimer->setInterval(1);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2020-04-06 17:52:48 +02:00
|
|
|
case ScStw::Start:
|
2019-03-07 17:18:24 +01:00
|
|
|
{
|
2019-09-16 00:06:12 +02:00
|
|
|
if(!playSound("qrc:/sounds/IFSC_STARTSIGNAL_SINE.wav")){
|
2019-03-07 17:18:24 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-04-06 17:52:48 +02:00
|
|
|
nextStartAction = ScStw::None;
|
2019-03-07 17:18:24 +01:00
|
|
|
nextStartActionTimer->disconnect(nextStartActionTimer, SIGNAL(timeout()), this, SLOT(playSoundsAndStartRace()));
|
|
|
|
|
2020-04-06 17:52:48 +02:00
|
|
|
this->setState(ScStw::RUNNING);
|
2019-03-07 17:18:24 +01:00
|
|
|
speedTimers[0]->start();
|
|
|
|
|
2019-10-13 16:42:38 +02:00
|
|
|
emit this->nextStartActionChanged();
|
|
|
|
|
2019-03-07 17:18:24 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-04-06 17:52:48 +02:00
|
|
|
case ScStw::None:
|
2019-03-07 17:18:24 +01:00
|
|
|
{
|
|
|
|
this->speedTimers[0]->setState(SpeedTimer::STARTING);
|
|
|
|
if(appSettings->loadSetting("at_marks_en") == "true"){
|
2020-04-06 17:52:48 +02:00
|
|
|
nextStartAction = ScStw::AtYourMarks;
|
2019-03-07 17:18:24 +01:00
|
|
|
nextStartActionTimer->setInterval(appSettings->loadSetting("at_marks_delay").toInt() <= 0 ? 1:appSettings->loadSetting("at_marks_delay").toInt());
|
|
|
|
}
|
|
|
|
else if(appSettings->loadSetting("ready_en") == "true"){
|
2020-04-06 17:52:48 +02:00
|
|
|
nextStartAction = ScStw::Ready;
|
2019-03-07 17:18:24 +01:00
|
|
|
nextStartActionTimer->setInterval(appSettings->loadSetting("ready_delay").toInt() <= 0 ? 1:appSettings->loadSetting("ready_delay").toInt());
|
|
|
|
}
|
|
|
|
else{
|
2020-04-06 17:52:48 +02:00
|
|
|
nextStartAction = ScStw::Start;
|
2019-03-07 17:18:24 +01:00
|
|
|
nextStartActionTimer->setInterval(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-13 16:42:38 +02:00
|
|
|
emit this->nextStartActionChanged();
|
|
|
|
|
2019-03-07 17:18:24 +01:00
|
|
|
nextStartActionTimer->connect(nextStartActionTimer, SIGNAL(timeout()), this, SLOT(playSoundsAndStartRace()));
|
|
|
|
nextStartActionTimer->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ClimbingRace::playSound(QString path) {
|
|
|
|
|
|
|
|
player->setMedia(QUrl(path));
|
|
|
|
player->setVolume(50);
|
|
|
|
player->play();
|
|
|
|
|
|
|
|
QTimer timer;
|
|
|
|
timer.setInterval(1);
|
|
|
|
timer.setSingleShot(true);
|
|
|
|
|
|
|
|
QEventLoop loop;
|
|
|
|
loop.connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
|
|
|
|
|
|
|
|
while (player->mediaStatus() == QMediaPlayer::LoadingMedia || player->mediaStatus() == QMediaPlayer::BufferingMedia || player->mediaStatus() == QMediaPlayer::BufferedMedia) {
|
|
|
|
timer.start();
|
|
|
|
loop.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(player->mediaStatus() == QMediaPlayer::EndOfMedia){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-06 17:52:48 +02:00
|
|
|
void ClimbingRace::setState(ScStw::RaceState newState) {
|
2019-03-07 17:18:24 +01:00
|
|
|
if(newState != this->state) {
|
|
|
|
this->state = newState;
|
|
|
|
this->stateChanged(newState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClimbingRace::refreshMode() {
|
2020-04-06 17:52:48 +02:00
|
|
|
RaceMode newMode;
|
|
|
|
if(this->scStwClient->getState() == ScStwClient::CONNECTED){
|
2019-03-24 21:16:16 +01:00
|
|
|
newMode = REMOTE;
|
2019-03-07 17:18:24 +01:00
|
|
|
}
|
|
|
|
else {
|
2019-03-24 21:16:16 +01:00
|
|
|
newMode = LOCAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(this->mode != newMode){
|
2019-06-12 14:53:37 +02:00
|
|
|
|
|
|
|
if(newMode == LOCAL){
|
|
|
|
// if the new mode is local -> connection to base station has been lost
|
|
|
|
|
2019-08-19 15:14:11 +02:00
|
|
|
// reset race
|
|
|
|
// reset state
|
2020-04-06 17:52:48 +02:00
|
|
|
this->setState(ScStw::IDLE);
|
2019-08-19 15:14:11 +02:00
|
|
|
|
|
|
|
// reset timers
|
2019-06-12 14:53:37 +02:00
|
|
|
// go back to one timer
|
|
|
|
for (int i = 0;i<this->speedTimers.length();i++) {
|
|
|
|
delete this->speedTimers[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
this->speedTimers.clear();
|
|
|
|
|
|
|
|
this->speedTimers.append(new SpeedTimer);
|
|
|
|
}
|
|
|
|
|
2019-03-24 21:16:16 +01:00
|
|
|
this->mode = newMode;
|
|
|
|
emit this->modeChanged();
|
2019-03-07 17:18:24 +01:00
|
|
|
}
|
2019-03-24 21:16:16 +01:00
|
|
|
|
2019-03-07 17:18:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClimbingRace::refreshTimerText() {
|
|
|
|
|
|
|
|
// --- refresh timer text ---
|
|
|
|
|
|
|
|
QVariantList newTimerTextList;
|
|
|
|
|
|
|
|
foreach(SpeedTimer * timer, this->speedTimers){
|
2019-09-08 15:08:50 +02:00
|
|
|
QVariantMap timerMap = {{"text",timer->getText()}, {"reacttime", timer->reactionTime}, {"state", timer->getState()}, {"id", this->speedTimers.indexOf(timer)}};
|
2019-03-07 17:18:24 +01:00
|
|
|
newTimerTextList.append(timerMap);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(newTimerTextList != this->qmlTimers){
|
|
|
|
this->qmlTimers = newTimerTextList;
|
|
|
|
emit timerTextChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
// --- refresh next start action delay progress ---
|
2019-10-13 16:42:38 +02:00
|
|
|
double nextStartActionRemainingDelay = 0;
|
2019-03-07 17:18:24 +01:00
|
|
|
|
2019-10-13 16:42:38 +02:00
|
|
|
switch (this->mode) {
|
|
|
|
case LOCAL: {
|
2019-03-07 17:18:24 +01:00
|
|
|
|
2019-10-13 16:42:38 +02:00
|
|
|
// get remaining and total next start action delay time
|
2019-03-07 17:18:24 +01:00
|
|
|
if(nextStartAction == 0){
|
2019-10-13 16:42:38 +02:00
|
|
|
this->nextStartActionTotalDelay = appSettings->loadSetting("at_marks_delay").toDouble();
|
2019-03-07 17:18:24 +01:00
|
|
|
}
|
|
|
|
else if (nextStartAction == 1) {
|
2019-10-13 16:42:38 +02:00
|
|
|
this->nextStartActionTotalDelay = appSettings->loadSetting("ready_delay").toDouble();
|
2019-03-07 17:18:24 +01:00
|
|
|
}
|
|
|
|
|
2019-10-13 16:42:38 +02:00
|
|
|
nextStartActionRemainingDelay = this->nextStartActionTimer->remainingTime();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case REMOTE: {
|
|
|
|
|
|
|
|
// calculate remaining next start action delay time
|
|
|
|
nextStartActionRemainingDelay = this->nextStartActionTotalDelay - ( this->date->currentMSecsSinceEpoch() - this->nextStartActionDelayStartedAt );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// calculate next start action delay progress
|
|
|
|
if(nextStartActionRemainingDelay > 0){
|
|
|
|
this->nextStartActionDelayProgress = nextStartActionRemainingDelay / this->nextStartActionTotalDelay;
|
|
|
|
emit this->nextStartActionDelayProgressChanged();
|
2019-03-07 17:18:24 +01:00
|
|
|
}
|
2019-10-13 16:42:38 +02:00
|
|
|
else {
|
2019-03-07 22:31:23 +01:00
|
|
|
this->nextStartActionDelayProgress = 0;
|
|
|
|
emit this->nextStartActionDelayProgressChanged();
|
|
|
|
}
|
2019-03-07 17:18:24 +01:00
|
|
|
|
2019-10-13 16:42:38 +02:00
|
|
|
|
2020-04-06 17:52:48 +02:00
|
|
|
/*if (this->mode == REMOTE && this->state == ScStw::IDLE) {
|
2019-10-13 16:42:38 +02:00
|
|
|
this->nextStartActionDelayProgress = 0;
|
|
|
|
emit this->nextStartActionDelayProgressChanged();
|
|
|
|
}*/
|
|
|
|
|
2019-03-07 17:18:24 +01:00
|
|
|
this->timerTextRefreshTimer->start();
|
|
|
|
}
|
|
|
|
|
2019-11-09 23:10:17 +01:00
|
|
|
bool ClimbingRace::pairConnectedUsbExtensions() {
|
2020-04-05 14:12:56 +02:00
|
|
|
QVariantMap ret = this->scStwClient->sendCommand(5002, "", 10000);
|
2019-11-09 23:10:17 +01:00
|
|
|
qDebug() << ret;
|
|
|
|
return ret["status"] == 200;
|
|
|
|
}
|
|
|
|
|
2019-05-02 22:39:22 +02:00
|
|
|
// - athlete management -
|
|
|
|
|
|
|
|
QVariant ClimbingRace::getAthletes() {
|
2020-04-05 14:12:56 +02:00
|
|
|
QVariantMap reply = this->scStwClient->sendCommand(4003);
|
2019-05-02 22:39:22 +02:00
|
|
|
|
|
|
|
if(reply["status"] != 200){
|
|
|
|
//handle Error!!
|
|
|
|
qDebug() << "+ --- error getting athletes: " << reply["status"];
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-19 14:06:05 +02:00
|
|
|
QVariantMap tmpAthletes = reply["data"].toMap();
|
2019-05-02 22:39:22 +02:00
|
|
|
|
2019-06-08 11:14:18 +02:00
|
|
|
//qDebug() << tmpAthletes;
|
2019-05-02 22:39:22 +02:00
|
|
|
|
|
|
|
return tmpAthletes;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ClimbingRace::createAthlete(QString userName, QString fullName) {
|
|
|
|
|
|
|
|
QVariant requestData = QVariantMap({{"fullName", fullName}, {"userName", userName}});
|
|
|
|
|
2020-04-05 14:12:56 +02:00
|
|
|
QVariantMap reply = this->scStwClient->sendCommand(4001, requestData.toJsonValue());
|
2019-05-02 22:39:22 +02:00
|
|
|
|
|
|
|
if(reply["status"] != 200){
|
|
|
|
//handle Error!!
|
|
|
|
qDebug() << "+ --- error creating athlete: " << reply["status"];
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ClimbingRace::deleteAthlete( QString userName ){
|
|
|
|
|
|
|
|
QVariant requestData = QVariantMap({{"userName", userName}});
|
|
|
|
|
2020-04-05 14:12:56 +02:00
|
|
|
QVariantMap reply = this->scStwClient->sendCommand(4002, requestData.toJsonValue());
|
2019-05-02 22:39:22 +02:00
|
|
|
|
|
|
|
if(reply["status"] != 200){
|
|
|
|
//handle Error!!
|
|
|
|
qDebug() << "+ --- error deleting athlete: " << reply["status"];
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-09-08 15:08:50 +02:00
|
|
|
bool ClimbingRace::selectAthlete( QString userName, int timerId ){
|
2019-05-02 22:39:22 +02:00
|
|
|
|
2019-09-08 15:08:50 +02:00
|
|
|
QVariant requestData = QVariantMap({{"userName", userName}, {"timerId", timerId}});
|
2019-05-02 22:39:22 +02:00
|
|
|
|
2020-04-05 14:12:56 +02:00
|
|
|
QVariantMap reply = this->scStwClient->sendCommand(4000, requestData.toJsonValue());
|
2019-05-02 22:39:22 +02:00
|
|
|
|
|
|
|
if(reply["status"] != 200){
|
|
|
|
//handle Error!!
|
2019-05-03 22:54:32 +02:00
|
|
|
qDebug() << "+ --- error selecting athlete: " << reply["status"];
|
2019-05-02 22:39:22 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-05-03 22:54:32 +02:00
|
|
|
QVariant ClimbingRace::getResults( QString userName ){
|
2020-04-05 14:12:56 +02:00
|
|
|
QVariantMap reply = this->scStwClient->sendCommand(4004, userName);
|
2019-05-03 22:54:32 +02:00
|
|
|
|
|
|
|
if(reply["status"] != 200){
|
|
|
|
//handle Error!!
|
|
|
|
qDebug() << "+ --- error getting results: " << reply["status"];
|
|
|
|
return false;
|
|
|
|
}
|
2019-05-02 22:39:22 +02:00
|
|
|
|
2019-05-03 22:54:32 +02:00
|
|
|
QVariantList tmpAthletes = reply["data"].toList();
|
|
|
|
|
|
|
|
//qDebug() << tmpAthletes;
|
|
|
|
|
|
|
|
return tmpAthletes;
|
|
|
|
}
|
2019-05-02 22:39:22 +02:00
|
|
|
|
2019-03-07 17:18:24 +01:00
|
|
|
// -------------------------
|
|
|
|
// --- functions for qml ---
|
|
|
|
// -------------------------
|
|
|
|
|
|
|
|
int ClimbingRace::getState() {
|
|
|
|
return this->state;
|
|
|
|
}
|
|
|
|
|
2019-03-24 21:16:16 +01:00
|
|
|
int ClimbingRace::getMode() {
|
|
|
|
return this->mode;
|
|
|
|
}
|
|
|
|
|
2019-03-07 17:18:24 +01:00
|
|
|
QVariant ClimbingRace::getTimerTextList() {
|
|
|
|
return this->qmlTimers;
|
|
|
|
}
|
|
|
|
|
|
|
|
double ClimbingRace::getNextStartActionDelayProgress() {
|
|
|
|
return this->nextStartActionDelayProgress;
|
|
|
|
}
|
|
|
|
|
2019-10-13 16:42:38 +02:00
|
|
|
int ClimbingRace::getNextStartAction() {
|
|
|
|
return this->nextStartAction;
|
|
|
|
}
|
|
|
|
|
2019-03-07 17:18:24 +01:00
|
|
|
void ClimbingRace::writeSetting(QString key, QVariant value) {
|
2020-04-06 22:54:28 +02:00
|
|
|
if(this->mode == REMOTE && ScStw::baseStationSettingFromString(key) != ScStw::InvalidSetting ){
|
|
|
|
this->scStwClient->writeRemoteSetting(ScStw::baseStationSettingFromString(key), value.toString());
|
2019-03-27 22:23:12 +01:00
|
|
|
}
|
2020-04-06 17:52:48 +02:00
|
|
|
else {
|
2019-03-27 22:23:12 +01:00
|
|
|
this->appSettings->writeSetting(key, value);
|
2019-03-07 17:18:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-07 16:33:02 +02:00
|
|
|
void ClimbingRace::writeSetting(ScStw::BaseStationSetting key, QVariant value) {
|
|
|
|
if(ScStw::baseStationSettingToString(key) != "Invalid" ){
|
|
|
|
this->writeSetting(ScStw::baseStationSettingToString(key), value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-07 17:18:24 +01:00
|
|
|
QString ClimbingRace::readSetting(QString key) {
|
2020-04-06 22:54:28 +02:00
|
|
|
if(this->mode == REMOTE && ScStw::baseStationSettingFromString(key) != ScStw::InvalidSetting){
|
|
|
|
return this->scStwClient->readRemoteSetting(ScStw::baseStationSettingFromString(key));
|
2019-03-27 22:23:12 +01:00
|
|
|
}
|
2019-04-08 18:03:23 +02:00
|
|
|
else {
|
2020-04-06 17:52:48 +02:00
|
|
|
return this->appSettings->loadSetting(key);
|
2019-04-08 18:03:23 +02:00
|
|
|
}
|
2019-03-07 17:18:24 +01:00
|
|
|
}
|
|
|
|
|
2020-04-07 16:33:02 +02:00
|
|
|
QString ClimbingRace::readSetting(ScStw::BaseStationSetting key) {
|
|
|
|
if(ScStw::baseStationSettingToString(key) != "Invalid") {
|
|
|
|
return this->readSetting(ScStw::baseStationSettingToString(key));
|
|
|
|
}
|
|
|
|
return "false";
|
|
|
|
}
|
|
|
|
|
2019-08-20 22:55:37 +02:00
|
|
|
void ClimbingRace::connectBaseStation() {
|
2019-03-29 23:42:56 +01:00
|
|
|
this->reloadBaseStationIpAdress();
|
2020-04-05 14:12:56 +02:00
|
|
|
this->scStwClient->connectToHost();
|
2019-03-07 17:18:24 +01:00
|
|
|
}
|
|
|
|
|
2019-03-29 23:42:56 +01:00
|
|
|
void ClimbingRace::disconnectBaseStation() {
|
2020-04-05 14:12:56 +02:00
|
|
|
this->scStwClient->closeConnection();
|
2019-03-29 23:42:56 +01:00
|
|
|
}
|
|
|
|
|
2019-03-07 17:18:24 +01:00
|
|
|
QString ClimbingRace::getBaseStationState() {
|
2020-04-06 17:52:48 +02:00
|
|
|
switch (this->scStwClient->getState()) {
|
|
|
|
case ScStwClient::CONNECTED:
|
|
|
|
return "connected";
|
|
|
|
case ScStwClient::CONNECTING:
|
|
|
|
return "connecting";
|
|
|
|
case ScStwClient::DISCONNECTED:
|
|
|
|
return "disconnected";
|
|
|
|
case ScStwClient::INITIALISING:
|
|
|
|
return "initialising";
|
|
|
|
}
|
|
|
|
return "";
|
2019-03-07 17:18:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant ClimbingRace::getBaseStationConnections() {
|
2020-04-05 14:12:56 +02:00
|
|
|
return scStwClient->getConnections();
|
2019-03-07 17:18:24 +01:00
|
|
|
}
|
2019-03-29 23:42:56 +01:00
|
|
|
|
2019-11-02 15:22:50 +01:00
|
|
|
QVariantMap ClimbingRace::getBaseStationProperties() {
|
2020-04-06 17:52:48 +02:00
|
|
|
QVariantMap firmware = {{"version", this->scStwClient->getFirmwareVersion()}, {"upToDate", this->scStwClient->isFirmwareUpToDate()}};
|
|
|
|
return {{"firmware", firmware}, {"timeOffset", this->scStwClient->getTimeOffset()}};
|
2019-11-02 15:22:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ClimbingRace::updateBasestationFirmware() {
|
2020-04-05 14:12:56 +02:00
|
|
|
return this->scStwClient->updateFirmware();
|
2019-11-02 15:22:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ClimbingRace::updateBasestationTime() {
|
2020-04-05 14:12:56 +02:00
|
|
|
return this->scStwClient->updateTime();
|
2019-11-02 15:22:50 +01:00
|
|
|
}
|
|
|
|
|
2019-03-29 23:42:56 +01:00
|
|
|
bool ClimbingRace::reloadBaseStationIpAdress() {
|
2020-04-06 17:52:48 +02:00
|
|
|
if(this->scStwClient->getState() == ScStwClient::DISCONNECTED){
|
2020-04-05 14:12:56 +02:00
|
|
|
this->scStwClient->setIP(pGlobalAppSettings->loadSetting("baseStationIpAdress"));
|
2019-03-29 23:42:56 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|