some fixes
This commit is contained in:
parent
72b03c0e66
commit
a247a6c305
3 changed files with 52 additions and 79 deletions
|
@ -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();
|
||||
|
||||
|
|
|
@ -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(1000);
|
||||
|
||||
if(reply["status"] != 200){
|
||||
//handle Error!!
|
||||
returnCode = reply["status"].toInt();
|
||||
}
|
||||
else {
|
||||
|
||||
returnCode = 200;
|
||||
QVariantMap reply = this->scStwClient->sendCommand(ScStw::StartRaceCommand);
|
||||
|
||||
return ScStw::StatusCode(reply["status"].toInt());
|
||||
}
|
||||
|
||||
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
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 ScStw::StatusCode(reply["status"].toInt());
|
||||
}
|
||||
|
||||
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() {
|
||||
|
||||
if(this->getState() != ScStwRace::STOPPED && this->getState() != ScStwRace::INCIDENT) {
|
||||
return 904;
|
||||
}
|
||||
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
|
||||
};
|
||||
|
|
|
@ -28,6 +28,7 @@ void ScStwLibraries::init() {
|
|||
qmlRegisterType<ScStw>("de.itsblue.ScStw", 2, 0, "ScStw");
|
||||
qRegisterMetaType<ScStwSettings::BaseStationSetting>("ScStwSettings::BaseStationSetting");
|
||||
qRegisterMetaType<ScStw::SocketCommand>("ScStw::SocketCommand");
|
||||
qRegisterMetaType<ScStw::StatusCode>("ScStw::StatusCode");
|
||||
|
||||
qmlRegisterType<ScStwRace>("de.itsblue.ScStw", 2, 0, "ScStwRace");
|
||||
qmlRegisterType<ScStwTimer>("de.itsblue.ScStw", 2, 0, "ScStwTimer");
|
||||
|
|
Reference in a new issue