This repository has been archived on 2024-06-03. You can view files and clone it, but cannot push or open issues or pull requests.
shared-libraries/ScStwLibraries/headers/ScStw.hpp

222 lines
6.2 KiB
C++
Raw Normal View History

2020-06-07 14:43:47 +02:00
/****************************************************************************
** ScStw Libraries
** Copyright (C) 2020 Itsblue development
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#ifndef SCSTW_HPP
#define SCSTW_HPP
#include <QObject>
#include <QMap>
#include <QMetaEnum>
/*!
* \mainpage ScStw Libraries documentation
*
* \section intro_sec Introduction
*
* 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.
*
* \section section Installation
* \code{.sh}
* cd yourRepo
* git submodule add https://git.itsblue.de/ScStw/shared-libraries/
* git submodule update --init --recursive
* \endcode
*
* And in your MyProject.pro include the .pri file:
* \code{.pro}
* include($$PWD/shared-libraries/ScStwLibraries/ScStwLibraries.pri)
* \endcode
*/
/*!
* \brief The ScStw class provides some shared functions and enums for use in the ScStw project.
*/
class ScStw : public QObject {
Q_OBJECT
public:
/*!
* \brief The SignalKey enum contains all signal keys a client can subscribe to
*
* \see ScStw::signalKeyFromInt()
*/
enum SignalKey {
InvalidSignal = -1,
RaceStateChanged = 9000,
TimersChanged = 9001,
ExtensionsChanged = 9002,
NextStartActionChanged = 9003, /*, ProfilesChanged*/
SettingChanged = 9004
};
Q_ENUM(SignalKey)
/*!
* \brief The SocketCommand enum contains all commands the base station can handle
*
* \see ScStw::socketCommandFromInt()
*/
enum SocketCommand {
InvalidCommand = -1,
InitializeSessionCommand = 1,
StartRaceCommand = 1000,
StopRaceCommand = 1001,
ResetRaceCommand = 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);
/*!
* \brief The ErrorCode enum contains all error codes that can occur when sending a command to the basestation
*/
2020-04-19 13:09:24 +02:00
enum StatusCode {
Success = 200,
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,
UpdateFailedError = 500,
Error = 900,
NotConnectedError = 910,
TimeoutError = 911,
2020-04-19 22:39:33 +02:00
SettingNotAccessibleError = 901,
InternalError = 950,
InternalErrorTimerOperationFailed = 951,
ApiVersionNotSupportedError = 952,
CompetitionModeProhibitsThisError = 953
};
2020-04-19 13:09:24 +02:00
Q_ENUM(ScStw::StatusCode)
/*!
* \brief The ExtensionType enum contains all types of extensions
*/
enum ExtensionType {
StartPad,
TopPad
};
Q_ENUM(ExtensionType);
enum ExtensionState {
Disconnected = 0,
Connecting = 1,
Initialising = 2,
Connected = 3
};
Q_ENUM(ExtensionState);
/*!
* \brief SOCKET_MESSAGE_START_KEY contains the key, a message is supposed to start with
*/
static const char* SOCKET_MESSAGE_START_KEY;
/*!
* \brief SOCKET_MESSAGE_END_KEY contains the key, a message is supposed to end with
*/
static const char* SOCKET_MESSAGE_END_KEY;
/*!
* \brief Function to convert an int to a SignalKey
* \param i the int to convert
* \return a SignalKey
*
* \see ScStw::SignalKey
*/
static SignalKey signalKeyFromInt(int i);
/*!
* \brief Function to convert an int to a SocketCommand
* \param i the int to convert
* \return a SocketCommand
*
* \see ScStw::SocketCommand
*/
static SocketCommand socketCommandFromInt(int i);
/*!
* \brief Function to convert an ExtensionType to a string
* \param t the ExtensionType to convert
* \return String
*
* \see ScStwExtensionType
*/
2020-09-22 16:02:16 +02:00
static QString extensionTypeToString(ExtensionType t);
/*!
* \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);
/*!
* \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));
}
ScStw() : QObject(nullptr) {};
private:
};
#endif // SCSTW_HPP