- some renaming

- added INCIDENT state for race
This commit is contained in:
Dorian Zedler 2020-09-29 15:21:00 +02:00
parent c6af1f8985
commit 6460714b62
Signed by: dorian
GPG key ID: D3B255CB8BC7CD37
3 changed files with 53 additions and 40 deletions

View file

@ -147,10 +147,10 @@ public:
* \brief The ExtensionState enum contains all possible states of an extension
*/
enum ExtensionState {
Disconnected = 0,
Connecting = 1,
Initialising = 2,
Connected = 3
ExtensionDisconnected = 0,
ExtensionConnecting = 1,
ExtensionInitialising = 2,
ExtensionConnected = 3
};
Q_ENUM(ExtensionState);

View file

@ -56,7 +56,7 @@ class ScStwRace : public QObject
public:
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)
enum StartAction { None = -1, AtYourMarks = 0, Ready = 1, Start = 2 };
@ -79,7 +79,6 @@ private:
QTimer *nextActionTimer;
QEventLoop *nextActionLoop;
QTimer *climberReadyWaitTimer;
QEventLoop *climberReadyWaitLoop;
// sounds

View file

@ -58,7 +58,7 @@ int ScStwRace::start(bool asyncronous) {
if(timer->getState() == ScStwTimer::DISABLED)
continue;
if(timer->getReadyState() != ScStwTimer::ClimberIsNotReady) {
if(timer->getReadyState() == ScStwTimer::ExtensionIsNotConnected || timer->getReadyState() == ScStwTimer::ExtensionBatteryNotFine) {
if(this->allowAutomaticTimerDisable) {
timer->setDisabled(true);
@ -70,13 +70,13 @@ int ScStwRace::start(bool asyncronous) {
timer->technicalIncident();
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();
else if(timer != subTimer)
subTimer->setState(ScStwTimer::CANCELLED);
}
this->setState(STOPPED);
this->setState(INCIDENT);
qDebug() << "[ERROR][RACE] Could not start due to not-ready timers";
@ -161,7 +161,7 @@ void ScStwRace::handleTimerStop() {
}
int ScStwRace::reset() {
if(this->state != STOPPED) {
if(this->state != STOPPED && this->state != INCIDENT) {
return ScStw::CurrentStateNotVaildForOperationError;
}
@ -183,7 +183,7 @@ int ScStwRace::reset() {
}
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;
qDebug() << "[INFO][RACE] cancelling race";
@ -191,6 +191,7 @@ int ScStwRace::cancel() {
this->soundPlayer->cancel(this->soundVolume);
this->nextActionTimer->stop();
this->nextActionLoop->quit();
this->climberReadyWaitLoop->quit();
this->nextStartAction = None;
int returnCode = ScStw::Success;
@ -230,6 +231,10 @@ bool ScStwRace::playSoundsAndStartTimers() {
return false;
}
// check if the start was cancelled
if(this->state != PREPAIRING)
return false;
qDebug() << "NOW IN WAITING";
this->setState(WAITING);
@ -258,6 +263,10 @@ bool ScStwRace::playSoundsAndStartTimers() {
if(!allClimbersReady)
this->climberReadyWaitLoop->exec();
// check if the start was cancelled
if(this->state != WAITING)
return false;
}
qDebug() << "[RACE][DEBUG] Initial wait finished";
@ -269,6 +278,11 @@ bool ScStwRace::playSoundsAndStartTimers() {
this->nextActionTimer->stop();
this->nextActionTimer->start(minimumReadyDelay);
this->climberReadyWaitLoop->exec();
// check if the start was cancelled
if(this->state != WAITING)
return false;
} while(this->nextActionTimer->remainingTime() > 0);
qDebug() << "[RACE][DEBUG] Wait finished, starting now!";