- 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 * \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);

View file

@ -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

View file

@ -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);
@ -240,42 +245,51 @@ bool ScStwRace::playSoundsAndStartTimers() {
// if the automatic ready tone is enabled, wait for the climbers to become ready // if the automatic ready tone is enabled, wait for the climbers to become ready
if(this->startActionSettings.contains(Ready) && this->startActionSettings[Ready]["Enabled"].toBool()) { if(this->startActionSettings.contains(Ready) && this->startActionSettings[Ready]["Enabled"].toBool()) {
qDebug() << "[RACE][INFO] Now waiting for climbers"; qDebug() << "[RACE][INFO] Now waiting for climbers";
// get delay // get delay
int minimumReadyDelay = 1000; int minimumReadyDelay = 1000;
if(this->startActionSettings[Ready]["Delay"].toInt() > 1000 || !this->allowAutomaticTimerDisable) if(this->startActionSettings[Ready]["Delay"].toInt() > 1000 || !this->allowAutomaticTimerDisable)
minimumReadyDelay = this->startActionSettings[Ready]["Delay"].toInt(); minimumReadyDelay = this->startActionSettings[Ready]["Delay"].toInt();
// wait for climbers to become ready initially // wait for climbers to become ready initially
bool allClimbersReady = false; bool allClimbersReady = false;
while (!allClimbersReady) { while (!allClimbersReady) {
allClimbersReady = true; allClimbersReady = true;
foreach (ScStwTimer *timer, this->timers) { foreach (ScStwTimer *timer, this->timers) {
if(timer->getReadyState() != ScStwTimer::IsReady) if(timer->getReadyState() != ScStwTimer::IsReady)
allClimbersReady = false; allClimbersReady = false;
}
if(!allClimbersReady)
this->climberReadyWaitLoop->exec();
} }
qDebug() << "[RACE][DEBUG] Initial wait finished"; if(!allClimbersReady)
// wait for all climbers to be ready for the ReadyActionDelay, but at least one second continuosly
// the climber ready wait loop will also quit, if the climber steps of the pad
// -> wait for both climbers to stand on the pad for at least one second
do {
this->nextActionTimer->stop();
this->nextActionTimer->start(minimumReadyDelay);
this->climberReadyWaitLoop->exec(); this->climberReadyWaitLoop->exec();
} while(this->nextActionTimer->remainingTime() > 0);
qDebug() << "[RACE][DEBUG] Wait finished, starting now!"; // check if the start was cancelled
if(this->state != WAITING)
// play ready tone
if(!this->soundPlayer->play(Ready, this->soundVolume))
return false; return false;
}
qDebug() << "[RACE][DEBUG] Initial wait finished";
// wait for all climbers to be ready for the ReadyActionDelay, but at least one second continuosly
// the climber ready wait loop will also quit, if the climber steps of the pad
// -> wait for both climbers to stand on the pad for at least one second
do {
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!";
// play ready tone
if(!this->soundPlayer->play(Ready, this->soundVolume))
return false;
} }
// enter starting state // enter starting state