From a247a6c3054545ec69c4eff14b5134f4c084ec31 Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Fri, 2 Oct 2020 16:49:24 +0200 Subject: [PATCH] some fixes --- .../headers/client/scstwremotemonitorrace.h | 13 +- .../sources/client/scstwremotemonitorrace.cpp | 117 +++++++----------- ScStwLibraries/sources/scstwlibraries.cpp | 1 + 3 files changed, 52 insertions(+), 79 deletions(-) diff --git a/ScStwLibraries/headers/client/scstwremotemonitorrace.h b/ScStwLibraries/headers/client/scstwremotemonitorrace.h index 281c53e..ef134e7 100644 --- a/ScStwLibraries/headers/client/scstwremotemonitorrace.h +++ b/ScStwLibraries/headers/client/scstwremotemonitorrace.h @@ -30,17 +30,18 @@ public: ScStwRemoteMonitorRace(ScStwClient *monitorClient, QObject *parent = nullptr); protected: - double nextStartActionTotalDelay; - double nextStartActionDelayStartedAt; + double currentStartTotalDelay; + double currentStartDelayStartedAt; + bool currentlyWaitingForClimbers; private: ScStwClient *scStwClient; public slots: - int start(); - int cancel(); - int stop(); - int reset(); + ScStw::StatusCode start(); + ScStw::StatusCode cancel(); + ScStw::StatusCode stop(); + ScStw::StatusCode reset(); bool addTimer(ScStwTimer *timer); QVariantList getCurrentStartDelay(); diff --git a/ScStwLibraries/sources/client/scstwremotemonitorrace.cpp b/ScStwLibraries/sources/client/scstwremotemonitorrace.cpp index 40767da..210ce9d 100644 --- a/ScStwLibraries/sources/client/scstwremotemonitorrace.cpp +++ b/ScStwLibraries/sources/client/scstwremotemonitorrace.cpp @@ -20,11 +20,13 @@ ScStwRemoteMonitorRace::ScStwRemoteMonitorRace(ScStwClient *monitorClient, QObject *parent) : ScStwRace(parent) { + this->currentlyWaitingForClimbers = false; + this->scStwClient = monitorClient; this->scStwClient->addSignalSubscription(ScStw::RaceStateChanged); this->scStwClient->addSignalSubscription(ScStw::TimersChanged); - this->scStwClient->addSignalSubscription(ScStw::NextStartActionChanged); + this->scStwClient->addSignalSubscription(ScStw::CurrentStartDelayChanged); connect(this->scStwClient, &ScStwClient::stateChanged, this, &ScStwRemoteMonitorRace::handleClientStateChanged); connect(this->scStwClient, &ScStwClient::gotSignal, this, &ScStwRemoteMonitorRace::handleBaseStationSignal); @@ -34,84 +36,48 @@ ScStwRemoteMonitorRace::ScStwRemoteMonitorRace(ScStwClient *monitorClient, QObje // --- Main Functionality --- // -------------------------- -int ScStwRemoteMonitorRace::start() { - - if(this->getState() != ScStwRace::IDLE) { - return 904; - } +ScStw::StatusCode ScStwRemoteMonitorRace::start() { + if(this->getState() != ScStwRace::IDLE && this->getState() != ScStwRace::WAITING) + return ScStw::CurrentStateNotVaildForOperationError; qDebug() << "+ --- starting race"; - int returnCode = 900; + QVariantMap reply = this->scStwClient->sendCommand(ScStw::StartRaceCommand); - QVariantMap reply = this->scStwClient->sendCommand(1000); - - if(reply["status"] != 200){ - //handle Error!! - returnCode = reply["status"].toInt(); - } - else { - - returnCode = 200; - - } - - - return returnCode; + return ScStw::StatusCode(reply["status"].toInt()); } -int ScStwRemoteMonitorRace::cancel() { - return this->stop(); - -} - -int ScStwRemoteMonitorRace::stop() { - - if(this->getState() != ScStwRace::RUNNING && this->getState() != ScStwRace::STARTING) { - return 904; - } +ScStw::StatusCode ScStwRemoteMonitorRace::cancel() { + if(this->getState() != PREPAIRING && this->getState() != WAITING && this->getState() != STARTING && this->getState() != RUNNING) + return ScStw::CurrentStateNotVaildForOperationError; qDebug() << "+ --- stopping race"; - int returnCode = 900; + QVariantMap reply = this->scStwClient->sendCommand(ScStw::CancelRaceCommand); - QVariantMap reply = this->scStwClient->sendCommand(1001); - - if(reply["status"] != 200){ - returnCode = reply["status"].toInt(); - } - else { - returnCode = 200; - } - - - return returnCode; + return ScStw::StatusCode(reply["status"].toInt()); } -int ScStwRemoteMonitorRace::reset() { +ScStw::StatusCode ScStwRemoteMonitorRace::stop() { + if(this->getState() != ScStwRace::RUNNING && this->getState() != ScStwRace::STARTING) + return ScStw::CurrentStateNotVaildForOperationError; - if(this->getState() != ScStwRace::STOPPED && this->getState() != ScStwRace::INCIDENT) { - return 904; - } + qDebug() << "+ --- stopping race"; + + QVariantMap reply = this->scStwClient->sendCommand(ScStw::StopRaceCommand); + + return ScStw::StatusCode(reply["status"].toInt()); +} + +ScStw::StatusCode ScStwRemoteMonitorRace::reset() { + if(this->getState() != ScStwRace::STOPPED && this->getState() != ScStwRace::INCIDENT) + return ScStw::CurrentStateNotVaildForOperationError; qDebug() << "+ --- resetting race"; - int returnCode = 900; + QVariantMap reply = this->scStwClient->sendCommand(ScStw::ResetRaceCommand); - - QVariantMap reply = this->scStwClient->sendCommand(1002); - - if(reply["status"] != 200){ - //handle Error!! - returnCode = reply["status"].toInt(); - } - else { - returnCode = 200; - } - - - - return returnCode; + return ScStw::StatusCode(reply["status"].toInt()); } @@ -154,14 +120,17 @@ void ScStwRemoteMonitorRace::handleBaseStationSignal(ScStw::SignalKey key, QVari this->refreshRemoteTimers(data.toList()); break; } - case ScStw::NextStartActionChanged: + case ScStw::CurrentStartDelayChanged: { // the next start action has changed - this->nextStartActionTotalDelay = data.toList()[ScStwRace::NextStartActionTotalDelay].toDouble(); - this->nextStartActionDelayStartedAt = QDateTime::currentMSecsSinceEpoch() - (this->nextStartActionTotalDelay * data.toList()[ScStwRace::NextStartActionDelayProgress].toDouble()); - this->nextStartAction = ScStwRace::StartAction( data.toList()[ScStwRace::NextStartAction].toInt() ); + this->currentStartTotalDelay = data.toList()[ScStwRace::CurrentStartStateTotalDelay].toInt(); + this->currentStartDelayStartedAt = QDateTime::currentMSecsSinceEpoch() - (this->currentStartTotalDelay * data.toList()[ScStwRace::CurrentStartStateDelayProgress].toDouble()); + this->currentlyWaitingForClimbers = data.toList()[ScStwRace::CurrentStartStateDelayProgress].toDouble() == 0 && this->currentStartTotalDelay == -1; + + emit this->currentStartDelayChanged(); + + qDebug() << "Current start delay changed: total:" << this->currentStartTotalDelay << " progress: " << data.toList()[ScStwRace::CurrentStartStateDelayProgress].toDouble(); - emit this->nextStartActionChanged(); break; } case ScStw::InvalidSignal: @@ -218,14 +187,17 @@ bool ScStwRemoteMonitorRace::addTimer(ScStwTimer* timer) { return false; } -QVariantList ScStwRemoteMonitorRace::getNextStartActionDetails() { - int nextActionDelay = 0; +QVariantList ScStwRemoteMonitorRace::getCurrentStartDelay() { + int nextActionDelay = -1; double nextActionDelayProg = -1; - if(this->nextStartAction == AtYourMarks || this->nextStartAction == Ready) { + if(this->getState() == WAITING && this->currentlyWaitingForClimbers) { + nextActionDelayProg = 0; + } + else if(this->getState() == PREPAIRING || this->getState() == WAITING) { // get the total delay and the delay progress of the next action timer - double elapsed = QDateTime::currentMSecsSinceEpoch() - this->nextStartActionDelayStartedAt; - nextActionDelay = this->nextStartActionTotalDelay; + double elapsed = QDateTime::currentMSecsSinceEpoch() - this->currentStartDelayStartedAt; + nextActionDelay = this->currentStartTotalDelay; if(elapsed < 0 || elapsed > nextActionDelay) { elapsed = nextActionDelay; } @@ -233,7 +205,6 @@ QVariantList ScStwRemoteMonitorRace::getNextStartActionDetails() { } return { - this->nextStartAction, nextActionDelay, nextActionDelayProg }; diff --git a/ScStwLibraries/sources/scstwlibraries.cpp b/ScStwLibraries/sources/scstwlibraries.cpp index c557e26..34b75b7 100644 --- a/ScStwLibraries/sources/scstwlibraries.cpp +++ b/ScStwLibraries/sources/scstwlibraries.cpp @@ -28,6 +28,7 @@ void ScStwLibraries::init() { qmlRegisterType("de.itsblue.ScStw", 2, 0, "ScStw"); qRegisterMetaType("ScStwSettings::BaseStationSetting"); qRegisterMetaType("ScStw::SocketCommand"); + qRegisterMetaType("ScStw::StatusCode"); qmlRegisterType("de.itsblue.ScStw", 2, 0, "ScStwRace"); qmlRegisterType("de.itsblue.ScStw", 2, 0, "ScStwTimer");