some fixes

This commit is contained in:
Dorian Zedler 2020-10-02 16:49:24 +02:00
parent 72b03c0e66
commit a247a6c305
Signed by: dorian
GPG key ID: D3B255CB8BC7CD37
3 changed files with 52 additions and 79 deletions

View file

@ -30,17 +30,18 @@ public:
ScStwRemoteMonitorRace(ScStwClient *monitorClient, QObject *parent = nullptr); ScStwRemoteMonitorRace(ScStwClient *monitorClient, QObject *parent = nullptr);
protected: protected:
double nextStartActionTotalDelay; double currentStartTotalDelay;
double nextStartActionDelayStartedAt; double currentStartDelayStartedAt;
bool currentlyWaitingForClimbers;
private: private:
ScStwClient *scStwClient; ScStwClient *scStwClient;
public slots: public slots:
int start(); ScStw::StatusCode start();
int cancel(); ScStw::StatusCode cancel();
int stop(); ScStw::StatusCode stop();
int reset(); ScStw::StatusCode reset();
bool addTimer(ScStwTimer *timer); bool addTimer(ScStwTimer *timer);
QVariantList getCurrentStartDelay(); QVariantList getCurrentStartDelay();

View file

@ -20,11 +20,13 @@
ScStwRemoteMonitorRace::ScStwRemoteMonitorRace(ScStwClient *monitorClient, QObject *parent) : ScStwRace(parent) ScStwRemoteMonitorRace::ScStwRemoteMonitorRace(ScStwClient *monitorClient, QObject *parent) : ScStwRace(parent)
{ {
this->currentlyWaitingForClimbers = false;
this->scStwClient = monitorClient; this->scStwClient = monitorClient;
this->scStwClient->addSignalSubscription(ScStw::RaceStateChanged); this->scStwClient->addSignalSubscription(ScStw::RaceStateChanged);
this->scStwClient->addSignalSubscription(ScStw::TimersChanged); 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::stateChanged, this, &ScStwRemoteMonitorRace::handleClientStateChanged);
connect(this->scStwClient, &ScStwClient::gotSignal, this, &ScStwRemoteMonitorRace::handleBaseStationSignal); connect(this->scStwClient, &ScStwClient::gotSignal, this, &ScStwRemoteMonitorRace::handleBaseStationSignal);
@ -34,84 +36,48 @@ ScStwRemoteMonitorRace::ScStwRemoteMonitorRace(ScStwClient *monitorClient, QObje
// --- Main Functionality --- // --- Main Functionality ---
// -------------------------- // --------------------------
int ScStwRemoteMonitorRace::start() { ScStw::StatusCode ScStwRemoteMonitorRace::start() {
if(this->getState() != ScStwRace::IDLE && this->getState() != ScStwRace::WAITING)
if(this->getState() != ScStwRace::IDLE) { return ScStw::CurrentStateNotVaildForOperationError;
return 904;
}
qDebug() << "+ --- starting race"; 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 ScStw::StatusCode(reply["status"].toInt());
} }
ScStw::StatusCode ScStwRemoteMonitorRace::cancel() {
return returnCode; if(this->getState() != PREPAIRING && this->getState() != WAITING && this->getState() != STARTING && this->getState() != RUNNING)
} return ScStw::CurrentStateNotVaildForOperationError;
int ScStwRemoteMonitorRace::cancel() {
return this->stop();
}
int ScStwRemoteMonitorRace::stop() {
if(this->getState() != ScStwRace::RUNNING && this->getState() != ScStwRace::STARTING) {
return 904;
}
qDebug() << "+ --- stopping race"; qDebug() << "+ --- stopping race";
int returnCode = 900; QVariantMap reply = this->scStwClient->sendCommand(ScStw::CancelRaceCommand);
QVariantMap reply = this->scStwClient->sendCommand(1001); return ScStw::StatusCode(reply["status"].toInt());
if(reply["status"] != 200){
returnCode = reply["status"].toInt();
}
else {
returnCode = 200;
} }
ScStw::StatusCode ScStwRemoteMonitorRace::stop() {
if(this->getState() != ScStwRace::RUNNING && this->getState() != ScStwRace::STARTING)
return ScStw::CurrentStateNotVaildForOperationError;
return returnCode; qDebug() << "+ --- stopping race";
QVariantMap reply = this->scStwClient->sendCommand(ScStw::StopRaceCommand);
return ScStw::StatusCode(reply["status"].toInt());
} }
int ScStwRemoteMonitorRace::reset() { ScStw::StatusCode ScStwRemoteMonitorRace::reset() {
if(this->getState() != ScStwRace::STOPPED && this->getState() != ScStwRace::INCIDENT)
if(this->getState() != ScStwRace::STOPPED && this->getState() != ScStwRace::INCIDENT) { return ScStw::CurrentStateNotVaildForOperationError;
return 904;
}
qDebug() << "+ --- resetting race"; qDebug() << "+ --- resetting race";
int returnCode = 900; QVariantMap reply = this->scStwClient->sendCommand(ScStw::ResetRaceCommand);
return ScStw::StatusCode(reply["status"].toInt());
QVariantMap reply = this->scStwClient->sendCommand(1002);
if(reply["status"] != 200){
//handle Error!!
returnCode = reply["status"].toInt();
}
else {
returnCode = 200;
}
return returnCode;
} }
@ -154,14 +120,17 @@ void ScStwRemoteMonitorRace::handleBaseStationSignal(ScStw::SignalKey key, QVari
this->refreshRemoteTimers(data.toList()); this->refreshRemoteTimers(data.toList());
break; break;
} }
case ScStw::NextStartActionChanged: case ScStw::CurrentStartDelayChanged:
{ {
// the next start action has changed // the next start action has changed
this->nextStartActionTotalDelay = data.toList()[ScStwRace::NextStartActionTotalDelay].toDouble(); this->currentStartTotalDelay = data.toList()[ScStwRace::CurrentStartStateTotalDelay].toInt();
this->nextStartActionDelayStartedAt = QDateTime::currentMSecsSinceEpoch() - (this->nextStartActionTotalDelay * data.toList()[ScStwRace::NextStartActionDelayProgress].toDouble()); this->currentStartDelayStartedAt = QDateTime::currentMSecsSinceEpoch() - (this->currentStartTotalDelay * data.toList()[ScStwRace::CurrentStartStateDelayProgress].toDouble());
this->nextStartAction = ScStwRace::StartAction( data.toList()[ScStwRace::NextStartAction].toInt() ); 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; break;
} }
case ScStw::InvalidSignal: case ScStw::InvalidSignal:
@ -218,14 +187,17 @@ bool ScStwRemoteMonitorRace::addTimer(ScStwTimer* timer) {
return false; return false;
} }
QVariantList ScStwRemoteMonitorRace::getNextStartActionDetails() { QVariantList ScStwRemoteMonitorRace::getCurrentStartDelay() {
int nextActionDelay = 0; int nextActionDelay = -1;
double nextActionDelayProg = -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 // get the total delay and the delay progress of the next action timer
double elapsed = QDateTime::currentMSecsSinceEpoch() - this->nextStartActionDelayStartedAt; double elapsed = QDateTime::currentMSecsSinceEpoch() - this->currentStartDelayStartedAt;
nextActionDelay = this->nextStartActionTotalDelay; nextActionDelay = this->currentStartTotalDelay;
if(elapsed < 0 || elapsed > nextActionDelay) { if(elapsed < 0 || elapsed > nextActionDelay) {
elapsed = nextActionDelay; elapsed = nextActionDelay;
} }
@ -233,7 +205,6 @@ QVariantList ScStwRemoteMonitorRace::getNextStartActionDetails() {
} }
return { return {
this->nextStartAction,
nextActionDelay, nextActionDelay,
nextActionDelayProg nextActionDelayProg
}; };

View file

@ -28,6 +28,7 @@ void ScStwLibraries::init() {
qmlRegisterType<ScStw>("de.itsblue.ScStw", 2, 0, "ScStw"); qmlRegisterType<ScStw>("de.itsblue.ScStw", 2, 0, "ScStw");
qRegisterMetaType<ScStwSettings::BaseStationSetting>("ScStwSettings::BaseStationSetting"); qRegisterMetaType<ScStwSettings::BaseStationSetting>("ScStwSettings::BaseStationSetting");
qRegisterMetaType<ScStw::SocketCommand>("ScStw::SocketCommand"); qRegisterMetaType<ScStw::SocketCommand>("ScStw::SocketCommand");
qRegisterMetaType<ScStw::StatusCode>("ScStw::StatusCode");
qmlRegisterType<ScStwRace>("de.itsblue.ScStw", 2, 0, "ScStwRace"); qmlRegisterType<ScStwRace>("de.itsblue.ScStw", 2, 0, "ScStwRace");
qmlRegisterType<ScStwTimer>("de.itsblue.ScStw", 2, 0, "ScStwTimer"); qmlRegisterType<ScStwTimer>("de.itsblue.ScStw", 2, 0, "ScStwTimer");