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() {
this->refreshMode();
this->baseConn->refreshConnections();
if(this->baseConn->state != "connected"){
if(this->mode != REMOTE){
this->baseStationSyncTimer->start();
return;
}
this->baseConn->refreshConnections();
QVariantMap tmpReply = this->baseConn->sendCommand(2000);
if(tmpReply["status"] != 200){
@ -214,15 +215,6 @@ void ClimbingRace::syncWithBaseStation() {
this->setState( raceState( tmpReply["data"].toInt() ) );
switch (this->state) {
case 0:
{
// case IDLE
if(speedTimers[0]->state != 0){
speedTimers[0]->setState(SpeedTimer::IDLE);
}
break;
}
case 1:
{
// case STARTING
@ -371,6 +363,23 @@ void ClimbingRace::refreshMode() {
}
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;
emit this->modeChanged();
}
@ -428,7 +437,8 @@ void ClimbingRace::refreshTimerText() {
bool ClimbingRace::refreshRemoteTimers() {
// get current time
QVariantMap tmpReply = this->baseConn->sendCommand(2007);
if(tmpReply["status"] != 200){
if(tmpReply["status"].toInt() != 200){
//handle error!!
qDebug() << "+ --- getting timers from basestation failed";
this->baseStationSyncTimer->start();
@ -437,14 +447,34 @@ bool ClimbingRace::refreshRemoteTimers() {
else {
QVariantList timers = tmpReply["data"].toList();
speedTimers[0]->startTime = this->date->currentMSecsSinceEpoch() - timers[0].toMap()["currTime"].toDouble();
speedTimers[0]->stoppedTime = timers[0].toMap()["currTime"].toDouble();
speedTimers[0]->reactionTime = timers[0].toMap()["reactTime"].toDouble();
if(timers.length() != speedTimers.length()){
// local timers are out of sync
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 -