some fixes in race and settings
This commit is contained in:
parent
e8d091e345
commit
8be3541bb5
15 changed files with 192 additions and 159 deletions
|
@ -39,13 +39,15 @@ HEADERS += \
|
||||||
ScStwLibraries_ClientLibs {
|
ScStwLibraries_ClientLibs {
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/sources/client/scstwclient.cpp \
|
$$PWD/sources/client/scstwclient.cpp \
|
||||||
$$PWD/sources/client/scstwremotesettings.cpp \
|
$$PWD/sources/client/scstwremoterace.cpp \
|
||||||
$$PWD/sources/client/scstwremotemonitorrace.cpp
|
$$PWD/sources/client/scstwremotetimer.cpp \
|
||||||
|
$$PWD/sources/client/scstwremotesettings.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
$$PWD/headers/client/scstwclient.h \
|
$$PWD/headers/client/scstwclient.h \
|
||||||
$$PWD/headers/client/scstwremotesettings.h \
|
$$PWD/headers/client/scstwremoterace.h \
|
||||||
$$PWD/headers/client/scstwremotemonitorrace.h
|
$$PWD/headers/client/scstwremotetimer.h \
|
||||||
|
$$PWD/headers/client/scstwremotesettings.h
|
||||||
|
|
||||||
INCLUDEPATH += $$PWD/headers/client
|
INCLUDEPATH += $$PWD/headers/client
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,12 +22,13 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include "scstwrace.h"
|
#include "scstwrace.h"
|
||||||
#include "scstwclient.h"
|
#include "scstwclient.h"
|
||||||
|
#include "scstwremotetimer.h"
|
||||||
|
|
||||||
class ScStwRemoteMonitorRace : public ScStwRace
|
class ScStwRemoteRace : public ScStwRace
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ScStwRemoteMonitorRace(ScStwClient *monitorClient, QObject *parent = nullptr);
|
ScStwRemoteRace(ScStwClient *monitorClient, QObject *parent = nullptr);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
double currentStartTotalDelay;
|
double currentStartTotalDelay;
|
||||||
|
@ -36,8 +37,10 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ScStwClient *scStwClient;
|
ScStwClient *scStwClient;
|
||||||
|
QList<ScStwRemoteTimer*> remoteTimers;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
ScStw::StatusCode start(bool);
|
||||||
ScStw::StatusCode start();
|
ScStw::StatusCode start();
|
||||||
ScStw::StatusCode cancel();
|
ScStw::StatusCode cancel();
|
||||||
ScStw::StatusCode stop();
|
ScStw::StatusCode stop();
|
||||||
|
|
80
ScStwLibraries/headers/client/scstwremotetimer.h
Normal file
80
ScStwLibraries/headers/client/scstwremotetimer.h
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
#ifndef SCSTWREMOTETIMER_H
|
||||||
|
#define SCSTWREMOTETIMER_H
|
||||||
|
|
||||||
|
#include <scstwtimer.h>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class ScStwRemoteTimer : public ScStwTimer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
ScStwRemoteTimer(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
friend class ScStwRemoteRace;
|
||||||
|
|
||||||
|
private:
|
||||||
|
ScStwTimer::ReadyState readyState;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
/*!
|
||||||
|
* \brief Function to get the current ready status of a timer
|
||||||
|
* \return The current ready status
|
||||||
|
*/
|
||||||
|
virtual ScStwTimer::ReadyState getReadyState();
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
/*!
|
||||||
|
* \brief Function to dircetly change the start time
|
||||||
|
*
|
||||||
|
* Only works when directControlEnabled is set to true!
|
||||||
|
*
|
||||||
|
* \param startTime the time to change to
|
||||||
|
* \return false when directControlEnabled is set to false and the startTime was therefore not modified, true otherwise
|
||||||
|
*/
|
||||||
|
void setStartTime(double startTime);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Function to dircetly change the stop time
|
||||||
|
*
|
||||||
|
* Only works when directControlEnabled is set to true!
|
||||||
|
*
|
||||||
|
* \param stopTime the time to change to
|
||||||
|
* \return false when directControlEnabled is set to false and the stopTime was therefore not modified, true otherwise
|
||||||
|
*/
|
||||||
|
void setStopTime(double stopTime);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Function to dircetly change the rection time
|
||||||
|
*
|
||||||
|
* Only works when directControlEnabled is set to true!
|
||||||
|
*
|
||||||
|
* \param reactionTime the time to change to
|
||||||
|
* \return false when directControlEnabled is set to false and the reactionTime was therefore not modified, true otherwise
|
||||||
|
*/
|
||||||
|
void setReactionTime(double rectionTime);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Function to dircetly change the letter
|
||||||
|
*
|
||||||
|
* Only works when directControlEnabled is set to true!
|
||||||
|
*
|
||||||
|
* \param newLetter the letter to change to
|
||||||
|
* \return false when directControlEnabled is set to false and the letter was therefore not modified, true otherwise
|
||||||
|
*/
|
||||||
|
void setLetter(QString newLetter);
|
||||||
|
|
||||||
|
void setReadyState(ScStwTimer::ReadyState);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Function to change the state of the timer
|
||||||
|
*
|
||||||
|
* Doing this will emit the ScStwTimer::stateChanged() signal (only if the new state differs from the current one)
|
||||||
|
*
|
||||||
|
* \param newState The new state
|
||||||
|
*/
|
||||||
|
void setState(TimerState newState);
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SCSTWREMOTETIMER_H
|
|
@ -34,7 +34,7 @@
|
||||||
#include "scstwsettings.h"
|
#include "scstwsettings.h"
|
||||||
#ifdef ScStwLibraries_ClientLibs
|
#ifdef ScStwLibraries_ClientLibs
|
||||||
#include "scstwsetting.h"
|
#include "scstwsetting.h"
|
||||||
#include "scstwremotemonitorrace.h"
|
#include "scstwremoterace.h"
|
||||||
#include "scstwclient.h"
|
#include "scstwclient.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,7 @@ class ScStwRace : public QObject
|
||||||
Q_PROPERTY(RaceState state READ getState NOTIFY stateChanged)
|
Q_PROPERTY(RaceState state READ getState NOTIFY stateChanged)
|
||||||
Q_PROPERTY(QVariantList timers READ getTimerDetailList NOTIFY timersChanged)
|
Q_PROPERTY(QVariantList timers READ getTimerDetailList NOTIFY timersChanged)
|
||||||
Q_PROPERTY(QVariantList currentStartDelay READ getCurrentStartDelay NOTIFY currentStartDelayChanged)
|
Q_PROPERTY(QVariantList currentStartDelay READ getCurrentStartDelay NOTIFY currentStartDelayChanged)
|
||||||
|
Q_PROPERTY(bool isReadyForNextState READ isReadyForNextState NOTIFY isReadyForNextStateChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ScStwRace(QObject *parent = nullptr);
|
explicit ScStwRace(QObject *parent = nullptr);
|
||||||
|
@ -160,6 +161,7 @@ signals:
|
||||||
void stateChanged(RaceState state);
|
void stateChanged(RaceState state);
|
||||||
void currentStartDelayChanged();
|
void currentStartDelayChanged();
|
||||||
void timersChanged();
|
void timersChanged();
|
||||||
|
void isReadyForNextStateChanged();
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -22,23 +22,25 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
|
class ScStwSettings;
|
||||||
|
|
||||||
class ScStwSetting : public QObject
|
class ScStwSetting : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QVariant value READ getValue WRITE setValue NOTIFY valueChanged)
|
Q_PROPERTY(QVariant value READ getValue WRITE setValue NOTIFY valueChanged)
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit ScStwSetting(QObject *parent = nullptr);
|
explicit ScStwSetting(int key, int keyLevel, ScStwSettings*scStwSettings, QObject *parent);
|
||||||
|
|
||||||
|
friend class ScStwSettings;
|
||||||
|
|
||||||
int key;
|
int key;
|
||||||
int keyLevel;
|
int keyLevel;
|
||||||
bool hasToReload;
|
bool hasToReload;
|
||||||
|
|
||||||
virtual bool writeSetting(int, int, QVariant) = 0;
|
|
||||||
virtual QVariant readSetting(int, int) = 0;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVariant valueCache;
|
QVariant valueCache;
|
||||||
|
ScStwSettings *scStwSettings;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
QVariant getValue();
|
QVariant getValue();
|
||||||
|
|
|
@ -109,30 +109,9 @@ private:
|
||||||
|
|
||||||
bool loadSettingsFromFile();
|
bool loadSettingsFromFile();
|
||||||
|
|
||||||
class ScStwSettingInternal: public ScStwSetting {
|
|
||||||
public:
|
|
||||||
ScStwSettingInternal(int key, int keyLevel, ScStwSettings*scStwSettings, QObject *parent):ScStwSetting(parent) {
|
|
||||||
this->scStwSettings = scStwSettings;
|
|
||||||
connect(this->scStwSettings, &ScStwSettings::settingChanged, this, &ScStwSettingInternal::handleSettingChange);
|
|
||||||
this->key = key;
|
|
||||||
this->keyLevel = keyLevel;
|
|
||||||
this->handleSettingChange(-1, 0, QVariant());
|
|
||||||
}
|
|
||||||
protected:
|
|
||||||
ScStwSettings *scStwSettings;
|
|
||||||
|
|
||||||
bool writeSetting(int key, int keyLevel, QVariant value) {
|
|
||||||
return this->scStwSettings->writeSetting(key, keyLevel, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant readSetting(int key, int keyLevel) {
|
|
||||||
return this->scStwSettings->readSetting(key, keyLevel);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
QMap<int, keyToStringConverter> keyToStringConverters;
|
QMap<int, keyToStringConverter> keyToStringConverters;
|
||||||
QMap<int, keyToTypeConverter> keyToTypeConverters;
|
QMap<int, keyToTypeConverter> keyToTypeConverters;
|
||||||
QMap<int, QMap<int, ScStwSettingInternal*>> internalSettingHandlers;
|
QMap<int, QMap<int, ScStwSetting*>> internalSettingHandlers;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
bool writeSettingsToFile();
|
bool writeSettingsToFile();
|
||||||
|
|
|
@ -71,10 +71,9 @@ public:
|
||||||
* \param directControlEnabled Defines if protected properties (startTimer, stopTime, reactionTime and state) can be directly set from outside.
|
* \param directControlEnabled Defines if protected properties (startTimer, stopTime, reactionTime and state) can be directly set from outside.
|
||||||
* \param letter the letter of the timer (only first char will be used!)
|
* \param letter the letter of the timer (only first char will be used!)
|
||||||
*/
|
*/
|
||||||
explicit ScStwTimer(QObject *parent = nullptr, bool directControlEnabled = false, QString letter = "" );
|
explicit ScStwTimer(QObject *parent = nullptr, QString letter = "" );
|
||||||
|
|
||||||
friend class ScStwRace;
|
friend class ScStwRace;
|
||||||
friend class ScStwRemoteRace;
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief The TimerState enum contains all state the timer can be in
|
* \brief The TimerState enum contains all state the timer can be in
|
||||||
|
@ -137,11 +136,6 @@ protected:
|
||||||
*/
|
*/
|
||||||
double reactionTime;
|
double reactionTime;
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Defines if protected properties (startTimer, stopTime, reactionTime and state) can be directly set from outside.
|
|
||||||
*/
|
|
||||||
bool directControlEnabled;
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief The letter (eg. "A" or "B") of the Timer (only one char)
|
* \brief The letter (eg. "A" or "B") of the Timer (only one char)
|
||||||
*/
|
*/
|
||||||
|
@ -267,58 +261,6 @@ public slots:
|
||||||
*/
|
*/
|
||||||
void setDisabled(bool disabled);
|
void setDisabled(bool disabled);
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Function to change the state of the timer
|
|
||||||
*
|
|
||||||
* Only works when directControlEnabled is set to true!
|
|
||||||
* Doing this will emit the ScStwTimer::stateChanged() signal (only if the new state differs from the current one)
|
|
||||||
*
|
|
||||||
* \param newState The new state
|
|
||||||
* \param force whether to force the state change (just to distinguish between protected and public function)
|
|
||||||
* \return false when directControlEnabled or force is set to false and the startTime was therefore not modified, true otherwise
|
|
||||||
*/
|
|
||||||
bool setState(TimerState newState, bool force);
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Function to dircetly change the start time
|
|
||||||
*
|
|
||||||
* Only works when directControlEnabled is set to true!
|
|
||||||
*
|
|
||||||
* \param startTime the time to change to
|
|
||||||
* \return false when directControlEnabled is set to false and the startTime was therefore not modified, true otherwise
|
|
||||||
*/
|
|
||||||
bool setStartTime(double startTime);
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Function to dircetly change the stop time
|
|
||||||
*
|
|
||||||
* Only works when directControlEnabled is set to true!
|
|
||||||
*
|
|
||||||
* \param stopTime the time to change to
|
|
||||||
* \return false when directControlEnabled is set to false and the stopTime was therefore not modified, true otherwise
|
|
||||||
*/
|
|
||||||
bool setStopTime(double stopTime);
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Function to dircetly change the rection time
|
|
||||||
*
|
|
||||||
* Only works when directControlEnabled is set to true!
|
|
||||||
*
|
|
||||||
* \param reactionTime the time to change to
|
|
||||||
* \return false when directControlEnabled is set to false and the reactionTime was therefore not modified, true otherwise
|
|
||||||
*/
|
|
||||||
bool setReactionTime(double rectionTime);
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Function to dircetly change the letter
|
|
||||||
*
|
|
||||||
* Only works when directControlEnabled is set to true!
|
|
||||||
*
|
|
||||||
* \param newLetter the letter to change to
|
|
||||||
* \return false when directControlEnabled is set to false and the letter was therefore not modified, true otherwise
|
|
||||||
*/
|
|
||||||
bool setLetter(QString newLetter);
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Function to check if the timer currently wants to be disabled
|
* \brief Function to check if the timer currently wants to be disabled
|
||||||
* \return true or false
|
* \return true or false
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
** along with this program. If not, see <http://www.gnu.org/licenses/>.
|
** along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "scstwremotemonitorrace.h"
|
#include "scstwremoterace.h"
|
||||||
|
|
||||||
ScStwRemoteMonitorRace::ScStwRemoteMonitorRace(ScStwClient *monitorClient, QObject *parent) : ScStwRace(parent)
|
ScStwRemoteRace::ScStwRemoteRace(ScStwClient *monitorClient, QObject *parent) : ScStwRace(parent)
|
||||||
{
|
{
|
||||||
this->currentlyWaitingForClimbers = false;
|
this->currentlyWaitingForClimbers = false;
|
||||||
|
|
||||||
|
@ -28,15 +28,19 @@ ScStwRemoteMonitorRace::ScStwRemoteMonitorRace(ScStwClient *monitorClient, QObje
|
||||||
this->scStwClient->addSignalSubscription(ScStw::TimersChanged);
|
this->scStwClient->addSignalSubscription(ScStw::TimersChanged);
|
||||||
this->scStwClient->addSignalSubscription(ScStw::CurrentStartDelayChanged);
|
this->scStwClient->addSignalSubscription(ScStw::CurrentStartDelayChanged);
|
||||||
|
|
||||||
connect(this->scStwClient, &ScStwClient::stateChanged, this, &ScStwRemoteMonitorRace::handleClientStateChanged);
|
connect(this->scStwClient, &ScStwClient::stateChanged, this, &ScStwRemoteRace::handleClientStateChanged);
|
||||||
connect(this->scStwClient, &ScStwClient::gotSignal, this, &ScStwRemoteMonitorRace::handleBaseStationSignal);
|
connect(this->scStwClient, &ScStwClient::gotSignal, this, &ScStwRemoteRace::handleBaseStationSignal);
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------
|
// --------------------------
|
||||||
// --- Main Functionality ---
|
// --- Main Functionality ---
|
||||||
// --------------------------
|
// --------------------------
|
||||||
|
|
||||||
ScStw::StatusCode ScStwRemoteMonitorRace::start() {
|
ScStw::StatusCode ScStwRemoteRace::start(bool) {
|
||||||
|
return this->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
ScStw::StatusCode ScStwRemoteRace::start() {
|
||||||
if(this->getState() != ScStwRace::IDLE && this->getState() != ScStwRace::WAITING)
|
if(this->getState() != ScStwRace::IDLE && this->getState() != ScStwRace::WAITING)
|
||||||
return ScStw::CurrentStateNotVaildForOperationError;
|
return ScStw::CurrentStateNotVaildForOperationError;
|
||||||
|
|
||||||
|
@ -47,7 +51,7 @@ ScStw::StatusCode ScStwRemoteMonitorRace::start() {
|
||||||
return ScStw::StatusCode(reply["status"].toInt());
|
return ScStw::StatusCode(reply["status"].toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
ScStw::StatusCode ScStwRemoteMonitorRace::cancel() {
|
ScStw::StatusCode ScStwRemoteRace::cancel() {
|
||||||
if(this->getState() != PREPAIRING && this->getState() != WAITING && this->getState() != STARTING && this->getState() != RUNNING)
|
if(this->getState() != PREPAIRING && this->getState() != WAITING && this->getState() != STARTING && this->getState() != RUNNING)
|
||||||
return ScStw::CurrentStateNotVaildForOperationError;
|
return ScStw::CurrentStateNotVaildForOperationError;
|
||||||
|
|
||||||
|
@ -58,7 +62,7 @@ ScStw::StatusCode ScStwRemoteMonitorRace::cancel() {
|
||||||
return ScStw::StatusCode(reply["status"].toInt());
|
return ScStw::StatusCode(reply["status"].toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
ScStw::StatusCode ScStwRemoteMonitorRace::stop() {
|
ScStw::StatusCode ScStwRemoteRace::stop() {
|
||||||
if(this->getState() != ScStwRace::RUNNING && this->getState() != ScStwRace::STARTING)
|
if(this->getState() != ScStwRace::RUNNING && this->getState() != ScStwRace::STARTING)
|
||||||
return ScStw::CurrentStateNotVaildForOperationError;
|
return ScStw::CurrentStateNotVaildForOperationError;
|
||||||
|
|
||||||
|
@ -69,7 +73,7 @@ ScStw::StatusCode ScStwRemoteMonitorRace::stop() {
|
||||||
return ScStw::StatusCode(reply["status"].toInt());
|
return ScStw::StatusCode(reply["status"].toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
ScStw::StatusCode ScStwRemoteMonitorRace::reset() {
|
ScStw::StatusCode ScStwRemoteRace::reset() {
|
||||||
if(this->getState() != ScStwRace::STOPPED && this->getState() != ScStwRace::INCIDENT)
|
if(this->getState() != ScStwRace::STOPPED && this->getState() != ScStwRace::INCIDENT)
|
||||||
return ScStw::CurrentStateNotVaildForOperationError;
|
return ScStw::CurrentStateNotVaildForOperationError;
|
||||||
|
|
||||||
|
@ -85,7 +89,7 @@ ScStw::StatusCode ScStwRemoteMonitorRace::reset() {
|
||||||
// --- Base Station sync ---
|
// --- Base Station sync ---
|
||||||
// -------------------------
|
// -------------------------
|
||||||
|
|
||||||
void ScStwRemoteMonitorRace::handleClientStateChanged() {
|
void ScStwRemoteRace::handleClientStateChanged() {
|
||||||
// TODO
|
// TODO
|
||||||
switch (this->scStwClient->getState()) {
|
switch (this->scStwClient->getState()) {
|
||||||
case ScStwClient::CONNECTED:
|
case ScStwClient::CONNECTED:
|
||||||
|
@ -105,7 +109,7 @@ void ScStwRemoteMonitorRace::handleClientStateChanged() {
|
||||||
*
|
*
|
||||||
* @param data
|
* @param data
|
||||||
*/
|
*/
|
||||||
void ScStwRemoteMonitorRace::handleBaseStationSignal(ScStw::SignalKey key, QVariant data) {
|
void ScStwRemoteRace::handleBaseStationSignal(ScStw::SignalKey key, QVariant data) {
|
||||||
//qDebug() << "got signal: " << data;
|
//qDebug() << "got signal: " << data;
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case ScStw::RaceStateChanged:
|
case ScStw::RaceStateChanged:
|
||||||
|
@ -141,7 +145,7 @@ void ScStwRemoteMonitorRace::handleBaseStationSignal(ScStw::SignalKey key, QVari
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScStwRemoteMonitorRace::refreshRemoteTimers(QVariantList remoteTimers) {
|
bool ScStwRemoteRace::refreshRemoteTimers(QVariantList remoteTimers) {
|
||||||
|
|
||||||
if(remoteTimers.length() != this->timers.length()){
|
if(remoteTimers.length() != this->timers.length()){
|
||||||
// local timers are out of sync
|
// local timers are out of sync
|
||||||
|
@ -155,8 +159,9 @@ bool ScStwRemoteMonitorRace::refreshRemoteTimers(QVariantList remoteTimers) {
|
||||||
|
|
||||||
foreach(QVariant remoteTimer, remoteTimers){
|
foreach(QVariant remoteTimer, remoteTimers){
|
||||||
// create a local timer for each remote timer
|
// create a local timer for each remote timer
|
||||||
ScStwTimer * timer = new ScStwTimer(this, true);
|
ScStwRemoteTimer * timer = new ScStwRemoteTimer(this);
|
||||||
this->timers.append(timer);
|
this->timers.append(timer);
|
||||||
|
this->remoteTimers.append(timer);
|
||||||
connect(timer, &ScStwTimer::stateChanged, this, &ScStwRace::timersChanged);
|
connect(timer, &ScStwTimer::stateChanged, this, &ScStwRace::timersChanged);
|
||||||
connect(timer, &ScStwTimer::reactionTimeChanged, this, &ScStwRace::timersChanged);
|
connect(timer, &ScStwTimer::reactionTimeChanged, this, &ScStwRace::timersChanged);
|
||||||
}
|
}
|
||||||
|
@ -164,30 +169,34 @@ bool ScStwRemoteMonitorRace::refreshRemoteTimers(QVariantList remoteTimers) {
|
||||||
|
|
||||||
foreach(QVariant remoteTimer, remoteTimers){
|
foreach(QVariant remoteTimer, remoteTimers){
|
||||||
int currId = remoteTimer.toMap()["id"].toInt();
|
int currId = remoteTimer.toMap()["id"].toInt();
|
||||||
|
|
||||||
ScStwTimer::TimerState newState = ScStwTimer::TimerState(remoteTimer.toMap()["state"].toInt());
|
ScStwTimer::TimerState newState = ScStwTimer::TimerState(remoteTimer.toMap()["state"].toInt());
|
||||||
|
|
||||||
|
qDebug() << "refreshing timers: id: " << currId << " state: " << newState << " readyState: " << remoteTimer.toMap()["readyState"].toInt();
|
||||||
|
|
||||||
double currentMSecsSinceEpoch = QDateTime::currentMSecsSinceEpoch();
|
double currentMSecsSinceEpoch = QDateTime::currentMSecsSinceEpoch();
|
||||||
|
|
||||||
this->timers[currId]->setStartTime(currentMSecsSinceEpoch - remoteTimer.toMap()["currentTime"].toDouble());
|
this->remoteTimers[currId]->setStartTime(currentMSecsSinceEpoch - remoteTimer.toMap()["currentTime"].toDouble());
|
||||||
|
|
||||||
if(newState >= ScStwTimer::WAITING)
|
if(newState >= ScStwTimer::WAITING)
|
||||||
this->timers[currId]->setStopTime(currentMSecsSinceEpoch);
|
this->remoteTimers[currId]->setStopTime(currentMSecsSinceEpoch);
|
||||||
|
|
||||||
this->timers[currId]->setReactionTime(remoteTimer.toMap()["reactionTime"].toDouble());
|
this->remoteTimers[currId]->setReactionTime(remoteTimer.toMap()["reactionTime"].toDouble());
|
||||||
|
this->remoteTimers[currId]->setLetter(remoteTimer.toMap()["letter"].toString());
|
||||||
|
this->remoteTimers[currId]->setReadyState(ScStwTimer::ReadyState(remoteTimer.toMap()["readyState"].toInt()));
|
||||||
|
|
||||||
this->timers[currId]->setState(newState, true);
|
this->remoteTimers[currId]->setState(newState);
|
||||||
|
|
||||||
this->timers[currId]->setLetter(remoteTimer.toMap()["letter"].toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScStwRemoteMonitorRace::addTimer(ScStwTimer* timer) {
|
bool ScStwRemoteRace::addTimer(ScStwTimer* timer) {
|
||||||
Q_UNUSED(timer)
|
Q_UNUSED(timer)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantList ScStwRemoteMonitorRace::getCurrentStartDelay() {
|
QVariantList ScStwRemoteRace::getCurrentStartDelay() {
|
||||||
int nextActionDelay = -1;
|
int nextActionDelay = -1;
|
||||||
double nextActionDelayProg = -1;
|
double nextActionDelayProg = -1;
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,8 @@ bool ScStwRemoteSettings::setDefaultSetting(QString key, QVariant defaultVariant
|
||||||
void ScStwRemoteSettings::handleClientStateChange() {
|
void ScStwRemoteSettings::handleClientStateChange() {
|
||||||
if(this->scStwClient->getState() == ScStwClient::DISCONNECTED)
|
if(this->scStwClient->getState() == ScStwClient::DISCONNECTED)
|
||||||
emit this->settingChanged(-1, 0, QVariant());
|
emit this->settingChanged(-1, 0, QVariant());
|
||||||
|
else if(this->scStwClient->getState() == ScStwClient::CONNECTED)
|
||||||
|
emit this->settingChanged(-1, 0, QVariant());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScStwRemoteSettings::handleBaseStationSignal(ScStw::SignalKey key, QVariant data) {
|
void ScStwRemoteSettings::handleBaseStationSignal(ScStw::SignalKey key, QVariant data) {
|
||||||
|
|
41
ScStwLibraries/sources/client/scstwremotetimer.cpp
Normal file
41
ScStwLibraries/sources/client/scstwremotetimer.cpp
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
#include "../../headers/client/scstwremotetimer.h"
|
||||||
|
|
||||||
|
ScStwRemoteTimer::ScStwRemoteTimer(QObject *parent) : ScStwTimer(parent)
|
||||||
|
{
|
||||||
|
this->readyState = ScStwTimer::getReadyState();
|
||||||
|
}
|
||||||
|
|
||||||
|
ScStwTimer::ReadyState ScStwRemoteTimer::getReadyState() {
|
||||||
|
return this->readyState;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScStwRemoteTimer::setStartTime(double startTime) {
|
||||||
|
this->startTime = startTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScStwRemoteTimer::setStopTime(double stopTime) {
|
||||||
|
this->stopTime = stopTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScStwRemoteTimer::setReactionTime(double reactionTime) {
|
||||||
|
this->reactionTime = reactionTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScStwRemoteTimer::setLetter(QString newLetter) {
|
||||||
|
this->letter = newLetter;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScStwRemoteTimer::setReadyState(ScStwTimer::ReadyState readyState) {
|
||||||
|
if(this->readyState != readyState) {
|
||||||
|
this->readyState = readyState;
|
||||||
|
emit this->readyStateChanged(readyState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScStwRemoteTimer::setState(TimerState newState){
|
||||||
|
if(this->state != newState) {
|
||||||
|
this->state = newState;
|
||||||
|
qDebug() << "+ [INFO][REMOTETIMER] timer state changed: " << newState;
|
||||||
|
emit this->stateChanged();
|
||||||
|
}
|
||||||
|
}
|
|
@ -589,6 +589,8 @@ bool ScStwRace::addTimer(ScStwTimer *timer) {
|
||||||
connect(timer, &ScStwTimer::reactionTimeChanged, this, &ScStwRace::timersChanged);
|
connect(timer, &ScStwTimer::reactionTimeChanged, this, &ScStwRace::timersChanged);
|
||||||
connect(timer, &ScStwTimer::readyStateChanged, this->startWaitLoop, &QEventLoop::quit);
|
connect(timer, &ScStwTimer::readyStateChanged, this->startWaitLoop, &QEventLoop::quit);
|
||||||
|
|
||||||
|
connect(timer, &ScStwTimer::readyStateChanged, this, &ScStwRace::isReadyForNextStateChanged);
|
||||||
|
|
||||||
if(this->competitionMode && timer->getState() == ScStwTimer::DISABLED)
|
if(this->competitionMode && timer->getState() == ScStwTimer::DISABLED)
|
||||||
timer->setDisabled(false);
|
timer->setDisabled(false);
|
||||||
|
|
||||||
|
|
|
@ -17,22 +17,32 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "scstwsetting.h"
|
#include "scstwsetting.h"
|
||||||
|
#include "scstwsettings.h"
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
|
||||||
ScStwSetting::ScStwSetting(QObject *parent) : QObject(parent)
|
ScStwSetting::ScStwSetting(int key, int keyLevel, ScStwSettings*scStwSettings, QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
|
this->scStwSettings = scStwSettings;
|
||||||
|
connect(this->scStwSettings, &ScStwSettings::settingChanged, this, &ScStwSetting::handleSettingChange);
|
||||||
|
this->key = key;
|
||||||
|
this->keyLevel = keyLevel;
|
||||||
|
this->handleSettingChange(-1, this->keyLevel, QVariant());
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant ScStwSetting::getValue() {
|
QVariant ScStwSetting::getValue() {
|
||||||
if(this->hasToReload) {
|
if(this->hasToReload) {
|
||||||
this->valueCache = this->readSetting(this->key, this->keyLevel);
|
this->valueCache = this->scStwSettings->readSetting(this->key, this->keyLevel);
|
||||||
this->hasToReload = false;
|
this->hasToReload = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qDebug() << "Setting read: keyLevel: " << this->keyLevel << " key: " << this->key << " value: " << this->valueCache;
|
||||||
|
|
||||||
return this->valueCache;
|
return this->valueCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScStwSetting::setValue(QVariant value) {
|
void ScStwSetting::setValue(QVariant value) {
|
||||||
if(value != this->valueCache) {
|
if(value != this->valueCache) {
|
||||||
this->writeSetting(this->key, this->keyLevel, value);
|
this->scStwSettings->writeSetting(this->key, this->keyLevel, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@ ScStwSetting * ScStwSettings::getSetting(int key, int keyLevel) {
|
||||||
this->internalSettingHandlers.insert(keyLevel, {});
|
this->internalSettingHandlers.insert(keyLevel, {});
|
||||||
|
|
||||||
if(!this->internalSettingHandlers[keyLevel].contains(key))
|
if(!this->internalSettingHandlers[keyLevel].contains(key))
|
||||||
this->internalSettingHandlers[keyLevel].insert(key, new ScStwSettingInternal(key, keyLevel, this, this));
|
this->internalSettingHandlers[keyLevel].insert(key, new ScStwSetting(key, keyLevel, this, this));
|
||||||
|
|
||||||
return this->internalSettingHandlers[keyLevel][key];
|
return this->internalSettingHandlers[keyLevel][key];
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,10 +18,8 @@
|
||||||
|
|
||||||
#include "../headers/scstwtimer.h"
|
#include "../headers/scstwtimer.h"
|
||||||
|
|
||||||
ScStwTimer::ScStwTimer(QObject *parent, bool directControlEnabled, QString letter) : QObject(parent)
|
ScStwTimer::ScStwTimer(QObject *parent, QString letter) : QObject(parent)
|
||||||
{
|
{
|
||||||
this->directControlEnabled = directControlEnabled;
|
|
||||||
|
|
||||||
if(letter.length() > 1)
|
if(letter.length() > 1)
|
||||||
this->letter = letter[0];
|
this->letter = letter[0];
|
||||||
else
|
else
|
||||||
|
@ -30,6 +28,7 @@ ScStwTimer::ScStwTimer(QObject *parent, bool directControlEnabled, QString lette
|
||||||
this->startTime = 0;
|
this->startTime = 0;
|
||||||
this->stopTime = 0;
|
this->stopTime = 0;
|
||||||
this->reactionTime = 0;
|
this->reactionTime = 0;
|
||||||
|
this->wantsToBeDisabled = false;
|
||||||
|
|
||||||
this->state = IDLE;
|
this->state = IDLE;
|
||||||
}
|
}
|
||||||
|
@ -173,38 +172,6 @@ ScStwTimer::ReadyState ScStwTimer::getReadyState() {
|
||||||
// --- helper functions ---
|
// --- helper functions ---
|
||||||
// ------------------------
|
// ------------------------
|
||||||
|
|
||||||
bool ScStwTimer::setStartTime(double startTime) {
|
|
||||||
if(!this->directControlEnabled)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
this->startTime = startTime;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ScStwTimer::setStopTime(double stopTime) {
|
|
||||||
if(!this->directControlEnabled)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
this->stopTime = stopTime;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ScStwTimer::setReactionTime(double reactionTime) {
|
|
||||||
if(!this->directControlEnabled)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
this->reactionTime = reactionTime;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ScStwTimer::setState(TimerState newState, bool force) {
|
|
||||||
if(!this->directControlEnabled || !force)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
this->setState(newState);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScStwTimer::setState(TimerState newState){
|
void ScStwTimer::setState(TimerState newState){
|
||||||
if(this->state == DISABLED && newState != IDLE)
|
if(this->state == DISABLED && newState != IDLE)
|
||||||
return;
|
return;
|
||||||
|
@ -219,14 +186,6 @@ void ScStwTimer::setState(TimerState newState){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScStwTimer::setLetter(QString newLetter) {
|
|
||||||
if(!this->directControlEnabled)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
this->letter = newLetter;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
ScStwTimer::TimerState ScStwTimer::getState() {
|
ScStwTimer::TimerState ScStwTimer::getState() {
|
||||||
return this->state;
|
return this->state;
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue