2020-04-13 23:48:29 +02:00
|
|
|
#ifndef SCSTW_HPP
|
|
|
|
#define SCSTW_HPP
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QMap>
|
2020-05-27 12:35:01 +02:00
|
|
|
#include <QMetaEnum>
|
2020-04-13 23:48:29 +02:00
|
|
|
|
2020-04-15 19:21:32 +02:00
|
|
|
/*!
|
|
|
|
* \mainpage ScStw Libraries documentation
|
2020-04-13 23:48:29 +02:00
|
|
|
*
|
2020-04-15 19:21:32 +02:00
|
|
|
* \section intro_sec Introduction
|
2020-04-13 23:48:29 +02:00
|
|
|
*
|
|
|
|
* This library is meant for usage with the Speed climbing stopwatch project.
|
|
|
|
* It contains some helper classes to build a client application for the ScStw basestation with Qt.
|
|
|
|
*
|
2020-04-15 19:21:32 +02:00
|
|
|
* \section section Installation
|
|
|
|
* \code{.sh}
|
2020-04-13 23:48:29 +02:00
|
|
|
* cd yourRepo
|
|
|
|
* git submodule add https://git.itsblue.de/ScStw/shared-libraries/
|
|
|
|
* git submodule update --init --recursive
|
2020-04-15 19:21:32 +02:00
|
|
|
* \endcode
|
2020-04-13 23:48:29 +02:00
|
|
|
*
|
|
|
|
* Add to the list of libraries for the Qt-Secret assembly. For an example you can create Main.Pro in which connect Qt-Secret and your project.pro files as subprojects.
|
|
|
|
*
|
|
|
|
* Main.pro:
|
2020-04-15 19:21:32 +02:00
|
|
|
* \code{.pro}
|
2020-04-13 23:48:29 +02:00
|
|
|
* TEMPLATE = subdirs
|
|
|
|
* CONFIG += ordered
|
|
|
|
*
|
|
|
|
* SUBDIRS += \
|
|
|
|
* ScStwLibraries \
|
|
|
|
* MyProject
|
|
|
|
*
|
|
|
|
* ScStwLibraries.file = shared-libraries/ScStwLibraries/ScStwLibraries.pro
|
2020-04-15 19:21:32 +02:00
|
|
|
* \endcode
|
2020-04-13 23:48:29 +02:00
|
|
|
*
|
|
|
|
* And in your MyProject.pro include the .pri file:
|
2020-04-15 19:21:32 +02:00
|
|
|
* \code{.pro}
|
2020-04-13 23:48:29 +02:00
|
|
|
* include($$PWD/../shared-libraries/ScStwLibraries/ScStwLibraries.pri)
|
2020-04-15 19:21:32 +02:00
|
|
|
* \endcode
|
2020-04-13 23:48:29 +02:00
|
|
|
*/
|
|
|
|
|
2020-04-15 19:21:32 +02:00
|
|
|
/*!
|
|
|
|
* \brief The ScStw class provides some shared functions and enums for use in the ScStw project.
|
2020-04-13 23:48:29 +02:00
|
|
|
*/
|
|
|
|
class ScStw : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
|
2020-04-15 19:21:32 +02:00
|
|
|
/*!
|
|
|
|
* \brief The SignalKey enum contains all signal keys a client can subscribe to
|
2020-04-13 23:48:29 +02:00
|
|
|
*
|
2020-04-15 19:21:32 +02:00
|
|
|
* \see ScStw::signalKeyFromInt()
|
2020-04-13 23:48:29 +02:00
|
|
|
*/
|
|
|
|
enum SignalKey {
|
|
|
|
InvalidSignal = -1,
|
|
|
|
RaceStateChanged = 9000,
|
|
|
|
TimersChanged = 9001,
|
|
|
|
ExtensionsChanged = 9002,
|
|
|
|
NextStartActionChanged = 9003 /*, ProfilesChanged*/
|
|
|
|
};
|
|
|
|
Q_ENUM(SignalKey)
|
|
|
|
|
2020-04-15 19:21:32 +02:00
|
|
|
/*!
|
|
|
|
* \brief The BaseStationSetting enum contains all settings of the base station that can be changed by a client
|
2020-04-13 23:48:29 +02:00
|
|
|
*
|
2020-04-15 19:21:32 +02:00
|
|
|
* \see ScStw::baseStationSettingFromInt()
|
|
|
|
* \see ScStw::baseStationSettingToString()
|
|
|
|
* \see ScStw::baseStationSettingFromString()
|
|
|
|
* \see ScStw::baseStationSettings
|
2020-04-13 23:48:29 +02:00
|
|
|
*/
|
|
|
|
enum BaseStationSetting {
|
|
|
|
InvalidSetting = -1,
|
|
|
|
ReadySoundEnableSetting,
|
|
|
|
ReadySoundDelaySetting,
|
|
|
|
AtYourMarksSoundEnableSetting,
|
|
|
|
AtYourMarksSoundDelaySetting,
|
|
|
|
SoundVolumeSetting
|
|
|
|
};
|
|
|
|
Q_ENUM(BaseStationSetting)
|
|
|
|
|
2020-05-10 17:39:16 +02:00
|
|
|
/*!
|
|
|
|
* \brief The SocketCommand enum contains all commands the base station can handle
|
2020-05-10 18:29:27 +02:00
|
|
|
*
|
|
|
|
* \see ScStw::socketCommandFromInt()
|
2020-05-10 17:39:16 +02:00
|
|
|
*/
|
|
|
|
enum SocketCommand {
|
|
|
|
InvalidCommand = -1,
|
|
|
|
|
|
|
|
InitializeSessionCommand = 1,
|
|
|
|
|
|
|
|
StartTimersCommand = 1000,
|
|
|
|
StopTimersCommand = 1001,
|
|
|
|
ResetTimersCommand = 1002,
|
|
|
|
|
|
|
|
GetRaceStateCommand = 2000,
|
|
|
|
GetNextStartActionCommand = 2005,
|
|
|
|
GetExtensionsCommand = 2006,
|
|
|
|
GetTimersCommand = 2007,
|
|
|
|
GetNextStartActionDetailsCommand = 2009,
|
|
|
|
|
|
|
|
WriteSettingCommand = 3000,
|
|
|
|
ReadSettingCommand = 3001,
|
|
|
|
|
|
|
|
LoginAthleteCommand = 4000,
|
|
|
|
CreateAthleteCommand = 4001,
|
|
|
|
DeleteAthleteCommand = 4002,
|
|
|
|
GetAtheletesCommand = 4003,
|
|
|
|
GetAthleteResultsCommand = 4004,
|
|
|
|
|
|
|
|
UpdateFirmwareCommand = 5000,
|
|
|
|
UpdateSystemTimeCommand = 5001,
|
|
|
|
PairExtensionsCommand = 5002
|
|
|
|
};
|
|
|
|
Q_ENUM(SocketCommand);
|
|
|
|
|
2020-04-15 19:21:32 +02:00
|
|
|
/*!
|
|
|
|
* \brief The ErrorCode enum contains all error codes that can occur when sending a command to the basestation
|
2020-04-13 23:48:29 +02:00
|
|
|
*/
|
2020-04-19 13:09:24 +02:00
|
|
|
enum StatusCode {
|
2020-04-13 23:48:29 +02:00
|
|
|
Success = 200,
|
|
|
|
|
2020-05-10 17:39:16 +02:00
|
|
|
FirmwareAlreadyUpToDateInfo = 304,
|
|
|
|
|
|
|
|
|
|
|
|
CommandNotFoundError = 404,
|
|
|
|
ClientSessionAlreadyActiveError = 407,
|
|
|
|
UpdateSignatureInvalidError = 402,
|
|
|
|
TimestampTooSmallError = 406,
|
|
|
|
RequiredParameterNotGivenError = 405,
|
|
|
|
CurrentStateNotVaildForOperationError = 403,
|
|
|
|
AccessDeniedError = 401,
|
2020-05-15 16:22:29 +02:00
|
|
|
NoSessionActiveError = 408,
|
2020-05-10 17:39:16 +02:00
|
|
|
|
2020-04-13 23:48:29 +02:00
|
|
|
Error = 900,
|
|
|
|
NotConnectedError = 910,
|
|
|
|
TimeoutError = 911,
|
2020-04-19 22:39:33 +02:00
|
|
|
SettingNotAccessibleError = 901,
|
|
|
|
InternalError = 950,
|
|
|
|
InternalErrorTimerOperationFailed = 951
|
2020-04-13 23:48:29 +02:00
|
|
|
};
|
2020-04-19 13:09:24 +02:00
|
|
|
Q_ENUM(ScStw::StatusCode)
|
2020-04-13 23:48:29 +02:00
|
|
|
|
2020-04-15 19:21:32 +02:00
|
|
|
/*!
|
|
|
|
* \brief SOCKET_MESSAGE_START_KEY contains the key, a message is supposed to start with
|
2020-04-13 23:48:29 +02:00
|
|
|
*/
|
|
|
|
static const char* SOCKET_MESSAGE_START_KEY;
|
|
|
|
|
2020-04-15 19:21:32 +02:00
|
|
|
/*!
|
|
|
|
* \brief SOCKET_MESSAGE_END_KEY contains the key, a message is supposed to end with
|
2020-04-13 23:48:29 +02:00
|
|
|
*/
|
|
|
|
static const char* SOCKET_MESSAGE_END_KEY;
|
|
|
|
|
2020-04-15 19:21:32 +02:00
|
|
|
/*!
|
|
|
|
* \brief baseStationSettings contains a string with reference to all BaseStationSetting values
|
2020-04-13 23:48:29 +02:00
|
|
|
*
|
2020-04-15 19:21:32 +02:00
|
|
|
* \see ScStw::BaseStationSetting
|
|
|
|
* \see ScStw::baseStationSettingToString()
|
|
|
|
* \see ScStw::baseStationSettingFromString()
|
2020-04-13 23:48:29 +02:00
|
|
|
*/
|
|
|
|
static const QMap<QString, ScStw::BaseStationSetting> baseStationSettings;
|
|
|
|
|
2020-04-15 19:21:32 +02:00
|
|
|
/*!
|
|
|
|
* \brief Function to convert an int to a BaseStationSetting
|
|
|
|
* \param i the int to convert
|
|
|
|
* \return a BaseStationSetting
|
2020-04-13 23:48:29 +02:00
|
|
|
*
|
2020-04-15 19:21:32 +02:00
|
|
|
* \see ScStw::BaseStationSetting
|
2020-04-13 23:48:29 +02:00
|
|
|
*/
|
|
|
|
static BaseStationSetting baseStationSettingfromInt(int i);
|
|
|
|
|
2020-04-15 19:21:32 +02:00
|
|
|
/*!
|
|
|
|
* \brief Function to convert a QString to a BaseStationSetting
|
|
|
|
* \param s the string to convert
|
|
|
|
* \return a BaseStationSetting
|
2020-04-13 23:48:29 +02:00
|
|
|
*
|
2020-04-15 19:21:32 +02:00
|
|
|
* \see ScStw::BaseStationSetting
|
|
|
|
* \see ScStw::baseStationSettingToString()
|
2020-04-13 23:48:29 +02:00
|
|
|
*/
|
|
|
|
static BaseStationSetting baseStationSettingFromString(QString s);
|
|
|
|
|
2020-04-15 19:21:32 +02:00
|
|
|
/*!
|
|
|
|
* \brief Function to convert BaseStationSetting to a QString
|
|
|
|
* \param s the BaseStationSetting to convert
|
|
|
|
* \return a QString
|
2020-04-13 23:48:29 +02:00
|
|
|
*
|
2020-04-15 19:21:32 +02:00
|
|
|
* \see ScStw::BaseStationSetting
|
|
|
|
* \see ScStw::baseStationSettingFromString()
|
2020-04-13 23:48:29 +02:00
|
|
|
*/
|
2020-04-17 19:57:00 +02:00
|
|
|
Q_INVOKABLE static QString baseStationSettingToString(BaseStationSetting s);
|
2020-04-13 23:48:29 +02:00
|
|
|
|
2020-04-15 19:21:32 +02:00
|
|
|
/*!
|
|
|
|
* \brief Function to convert an int to a SignalKey
|
|
|
|
* \param i the int to convert
|
|
|
|
* \return a SignalKey
|
2020-04-13 23:48:29 +02:00
|
|
|
*
|
2020-04-15 19:21:32 +02:00
|
|
|
* \see ScStw::SignalKey
|
2020-04-13 23:48:29 +02:00
|
|
|
*/
|
|
|
|
static SignalKey signalKeyFromInt(int i);
|
|
|
|
|
2020-05-10 18:29:27 +02:00
|
|
|
/*!
|
|
|
|
* \brief Function to convert an int to a SocketCommand
|
|
|
|
* \param i the int to convert
|
|
|
|
* \return a SocketCommand
|
|
|
|
*
|
|
|
|
* \see ScStw::SocketCommand
|
|
|
|
*/
|
2020-05-10 17:39:16 +02:00
|
|
|
static SocketCommand socketCommandFromInt(int i);
|
|
|
|
|
2020-05-10 18:29:27 +02:00
|
|
|
/*!
|
|
|
|
* \brief Function to compare to string firmware versions in <major>.<minor>.<patch> formar
|
|
|
|
* \param a version a
|
|
|
|
* \param b version b
|
|
|
|
* \return -4: a is of invalid format
|
|
|
|
* -3: major of a is lower than b
|
|
|
|
* -2: minor of a is lower than b
|
|
|
|
* -1: patch of a is lower than b
|
|
|
|
* 0: a and b are identical
|
|
|
|
* 1: patch b is lower than a
|
|
|
|
* 2: minor of b is lower than a
|
|
|
|
* 3: major of b is lower than a
|
|
|
|
* 4: b is of invalid format
|
|
|
|
*/
|
|
|
|
static int firmwareCompare(QString a, QString b);
|
|
|
|
|
2020-05-27 12:35:01 +02:00
|
|
|
/*!
|
|
|
|
* \brief Function to convert a value to an enum
|
|
|
|
*/
|
|
|
|
template <typename Enum>
|
|
|
|
static Enum toEnumValue(const int &value, bool *ok)
|
|
|
|
{
|
|
|
|
QMetaEnum enumeration = QMetaEnum::fromType<Enum>();
|
|
|
|
return static_cast<Enum>(enumeration.keyToValue(enumeration.valueToKey(value), ok));
|
|
|
|
}
|
2020-05-10 18:29:27 +02:00
|
|
|
|
2020-04-13 23:48:29 +02:00
|
|
|
ScStw() : QObject(nullptr) {};
|
2020-04-17 19:57:00 +02:00
|
|
|
private:
|
2020-04-13 23:48:29 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SCSTW_HPP
|