dual timers on the base station side are now supported

This commit is contained in:
Dorian Zedler 2019-06-12 14:53:37 +02:00
parent 9bb64027b4
commit 96cbadcf09

View file

@ -196,14 +196,15 @@ int ClimbingRace::resetRace() {
// ------------------------- // -------------------------
void ClimbingRace::syncWithBaseStation() { void ClimbingRace::syncWithBaseStation() {
this->refreshMode();
this->baseConn->refreshConnections(); if(this->mode != REMOTE){
if(this->baseConn->state != "connected"){
this->baseStationSyncTimer->start(); this->baseStationSyncTimer->start();
return; return;
} }
this->baseConn->refreshConnections();
QVariantMap tmpReply = this->baseConn->sendCommand(2000); QVariantMap tmpReply = this->baseConn->sendCommand(2000);
if(tmpReply["status"] != 200){ if(tmpReply["status"] != 200){
@ -214,15 +215,6 @@ void ClimbingRace::syncWithBaseStation() {
this->setState( raceState( tmpReply["data"].toInt() ) ); this->setState( raceState( tmpReply["data"].toInt() ) );
switch (this->state) { switch (this->state) {
case 0:
{
// case IDLE
if(speedTimers[0]->state != 0){
speedTimers[0]->setState(SpeedTimer::IDLE);
}
break;
}
case 1: case 1:
{ {
// case STARTING // case STARTING
@ -371,6 +363,23 @@ void ClimbingRace::refreshMode() {
} }
if(this->mode != newMode){ if(this->mode != newMode){
if(newMode == LOCAL){
// if the new mode is local -> connection to base station has been lost
// go back to one timer
for (int i = 0;i<this->speedTimers.length();i++) {
delete this->speedTimers[i];
}
this->speedTimers.clear();
this->speedTimers.append(new SpeedTimer);
// clear extensions
this->baseConn->connections.clear();
}
this->mode = newMode; this->mode = newMode;
emit this->modeChanged(); emit this->modeChanged();
} }
@ -428,7 +437,8 @@ void ClimbingRace::refreshTimerText() {
bool ClimbingRace::refreshRemoteTimers() { bool ClimbingRace::refreshRemoteTimers() {
// get current time // get current time
QVariantMap tmpReply = this->baseConn->sendCommand(2007); QVariantMap tmpReply = this->baseConn->sendCommand(2007);
if(tmpReply["status"] != 200){
if(tmpReply["status"].toInt() != 200){
//handle error!! //handle error!!
qDebug() << "+ --- getting timers from basestation failed"; qDebug() << "+ --- getting timers from basestation failed";
this->baseStationSyncTimer->start(); this->baseStationSyncTimer->start();
@ -437,15 +447,35 @@ bool ClimbingRace::refreshRemoteTimers() {
else { else {
QVariantList timers = tmpReply["data"].toList(); QVariantList timers = tmpReply["data"].toList();
speedTimers[0]->startTime = this->date->currentMSecsSinceEpoch() - timers[0].toMap()["currTime"].toDouble(); if(timers.length() != speedTimers.length()){
speedTimers[0]->stoppedTime = timers[0].toMap()["currTime"].toDouble(); // local timers are out of sync
speedTimers[0]->reactionTime = timers[0].toMap()["reactTime"].toDouble();
speedTimers[0]->setState(SpeedTimer::timerState(timers[0].toMap()["state"].toInt())); // delete all current timers
foreach(SpeedTimer * locTimer, this->speedTimers){
delete locTimer;
}
speedTimers.clear();
foreach(QVariant remTimer, timers){
// create a local timer for each remote timer
this->speedTimers.append(new SpeedTimer);
}
}
foreach(QVariant remTimer, timers){
int currId = remTimer.toMap()["id"].toInt();
speedTimers[currId]->startTime = this->date->currentMSecsSinceEpoch() - remTimer.toMap()["currTime"].toDouble();
speedTimers[currId]->stoppedTime = remTimer.toMap()["currTime"].toDouble();
speedTimers[currId]->reactionTime = remTimer.toMap()["reactTime"].toDouble();
speedTimers[currId]->setState(SpeedTimer::timerState(remTimer.toMap()["state"].toInt()));
}
return true;
} }
} }
// - athlete management - // - athlete management -
QVariant ClimbingRace::getAthletes() { QVariant ClimbingRace::getAthletes() {