- some renaming
- added INCIDENT state for race
This commit is contained in:
parent
c6af1f8985
commit
6460714b62
3 changed files with 53 additions and 40 deletions
|
@ -147,10 +147,10 @@ public:
|
||||||
* \brief The ExtensionState enum contains all possible states of an extension
|
* \brief The ExtensionState enum contains all possible states of an extension
|
||||||
*/
|
*/
|
||||||
enum ExtensionState {
|
enum ExtensionState {
|
||||||
Disconnected = 0,
|
ExtensionDisconnected = 0,
|
||||||
Connecting = 1,
|
ExtensionConnecting = 1,
|
||||||
Initialising = 2,
|
ExtensionInitialising = 2,
|
||||||
Connected = 3
|
ExtensionConnected = 3
|
||||||
};
|
};
|
||||||
Q_ENUM(ExtensionState);
|
Q_ENUM(ExtensionState);
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ class ScStwRace : public QObject
|
||||||
public:
|
public:
|
||||||
explicit ScStwRace(QObject *parent = nullptr);
|
explicit ScStwRace(QObject *parent = nullptr);
|
||||||
|
|
||||||
enum RaceState { IDLE, PREPAIRING, WAITING, STARTING, RUNNING, STOPPED };
|
enum RaceState { IDLE, PREPAIRING, WAITING, STARTING, RUNNING, STOPPED, INCIDENT };
|
||||||
Q_ENUM(RaceState)
|
Q_ENUM(RaceState)
|
||||||
|
|
||||||
enum StartAction { None = -1, AtYourMarks = 0, Ready = 1, Start = 2 };
|
enum StartAction { None = -1, AtYourMarks = 0, Ready = 1, Start = 2 };
|
||||||
|
@ -79,7 +79,6 @@ private:
|
||||||
|
|
||||||
QTimer *nextActionTimer;
|
QTimer *nextActionTimer;
|
||||||
QEventLoop *nextActionLoop;
|
QEventLoop *nextActionLoop;
|
||||||
QTimer *climberReadyWaitTimer;
|
|
||||||
QEventLoop *climberReadyWaitLoop;
|
QEventLoop *climberReadyWaitLoop;
|
||||||
|
|
||||||
// sounds
|
// sounds
|
||||||
|
|
|
@ -58,7 +58,7 @@ int ScStwRace::start(bool asyncronous) {
|
||||||
if(timer->getState() == ScStwTimer::DISABLED)
|
if(timer->getState() == ScStwTimer::DISABLED)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(timer->getReadyState() != ScStwTimer::ClimberIsNotReady) {
|
if(timer->getReadyState() == ScStwTimer::ExtensionIsNotConnected || timer->getReadyState() == ScStwTimer::ExtensionBatteryNotFine) {
|
||||||
|
|
||||||
if(this->allowAutomaticTimerDisable) {
|
if(this->allowAutomaticTimerDisable) {
|
||||||
timer->setDisabled(true);
|
timer->setDisabled(true);
|
||||||
|
@ -70,13 +70,13 @@ int ScStwRace::start(bool asyncronous) {
|
||||||
timer->technicalIncident();
|
timer->technicalIncident();
|
||||||
|
|
||||||
foreach (ScStwTimer *subTimer, this->timers) {
|
foreach (ScStwTimer *subTimer, this->timers) {
|
||||||
if(timer != subTimer && subTimer->getReadyState() != ScStwTimer::ClimberIsNotReady)
|
if(timer != subTimer && (timer->getReadyState() == ScStwTimer::ExtensionIsNotConnected || timer->getReadyState() == ScStwTimer::ExtensionBatteryNotFine))
|
||||||
subTimer->technicalIncident();
|
subTimer->technicalIncident();
|
||||||
else if(timer != subTimer)
|
else if(timer != subTimer)
|
||||||
subTimer->setState(ScStwTimer::CANCELLED);
|
subTimer->setState(ScStwTimer::CANCELLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->setState(STOPPED);
|
this->setState(INCIDENT);
|
||||||
|
|
||||||
qDebug() << "[ERROR][RACE] Could not start due to not-ready timers";
|
qDebug() << "[ERROR][RACE] Could not start due to not-ready timers";
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ void ScStwRace::handleTimerStop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScStwRace::reset() {
|
int ScStwRace::reset() {
|
||||||
if(this->state != STOPPED) {
|
if(this->state != STOPPED && this->state != INCIDENT) {
|
||||||
return ScStw::CurrentStateNotVaildForOperationError;
|
return ScStw::CurrentStateNotVaildForOperationError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,7 +183,7 @@ int ScStwRace::reset() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScStwRace::cancel() {
|
int ScStwRace::cancel() {
|
||||||
if(this->state != STARTING && this->state != RUNNING)
|
if(this->state != PREPAIRING && this->state != WAITING && this->state != STARTING && this->state != RUNNING)
|
||||||
return ScStw::CurrentStateNotVaildForOperationError;
|
return ScStw::CurrentStateNotVaildForOperationError;
|
||||||
|
|
||||||
qDebug() << "[INFO][RACE] cancelling race";
|
qDebug() << "[INFO][RACE] cancelling race";
|
||||||
|
@ -191,6 +191,7 @@ int ScStwRace::cancel() {
|
||||||
this->soundPlayer->cancel(this->soundVolume);
|
this->soundPlayer->cancel(this->soundVolume);
|
||||||
this->nextActionTimer->stop();
|
this->nextActionTimer->stop();
|
||||||
this->nextActionLoop->quit();
|
this->nextActionLoop->quit();
|
||||||
|
this->climberReadyWaitLoop->quit();
|
||||||
this->nextStartAction = None;
|
this->nextStartAction = None;
|
||||||
|
|
||||||
int returnCode = ScStw::Success;
|
int returnCode = ScStw::Success;
|
||||||
|
@ -230,6 +231,10 @@ bool ScStwRace::playSoundsAndStartTimers() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if the start was cancelled
|
||||||
|
if(this->state != PREPAIRING)
|
||||||
|
return false;
|
||||||
|
|
||||||
qDebug() << "NOW IN WAITING";
|
qDebug() << "NOW IN WAITING";
|
||||||
this->setState(WAITING);
|
this->setState(WAITING);
|
||||||
|
|
||||||
|
@ -258,6 +263,10 @@ bool ScStwRace::playSoundsAndStartTimers() {
|
||||||
|
|
||||||
if(!allClimbersReady)
|
if(!allClimbersReady)
|
||||||
this->climberReadyWaitLoop->exec();
|
this->climberReadyWaitLoop->exec();
|
||||||
|
|
||||||
|
// check if the start was cancelled
|
||||||
|
if(this->state != WAITING)
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "[RACE][DEBUG] Initial wait finished";
|
qDebug() << "[RACE][DEBUG] Initial wait finished";
|
||||||
|
@ -269,6 +278,11 @@ bool ScStwRace::playSoundsAndStartTimers() {
|
||||||
this->nextActionTimer->stop();
|
this->nextActionTimer->stop();
|
||||||
this->nextActionTimer->start(minimumReadyDelay);
|
this->nextActionTimer->start(minimumReadyDelay);
|
||||||
this->climberReadyWaitLoop->exec();
|
this->climberReadyWaitLoop->exec();
|
||||||
|
|
||||||
|
// check if the start was cancelled
|
||||||
|
if(this->state != WAITING)
|
||||||
|
return false;
|
||||||
|
|
||||||
} while(this->nextActionTimer->remainingTime() > 0);
|
} while(this->nextActionTimer->remainingTime() > 0);
|
||||||
|
|
||||||
qDebug() << "[RACE][DEBUG] Wait finished, starting now!";
|
qDebug() << "[RACE][DEBUG] Wait finished, starting now!";
|
||||||
|
|
Reference in a new issue