2020-04-11 23:41:34 +02:00
|
|
|
#include "../headers/ScStw.hpp"
|
2020-04-06 17:51:20 +02:00
|
|
|
|
|
|
|
const char *ScStw::SOCKET_MESSAGE_START_KEY = "<message>";
|
|
|
|
const char *ScStw::SOCKET_MESSAGE_END_KEY = "</message>";
|
2020-04-06 22:06:14 +02:00
|
|
|
|
|
|
|
const QMap<QString, ScStw::BaseStationSetting> ScStw::baseStationSettings = {
|
|
|
|
{"ReadySoundEnable", ScStw::ReadySoundEnableSetting},
|
|
|
|
{"ReadySoundDelay", ScStw::ReadySoundDelaySetting},
|
|
|
|
{"AtYourMarksSoundEnable", ScStw::AtYourMarksSoundEnableSetting},
|
|
|
|
{"AtYourMarksSoundDelay", ScStw::AtYourMarksSoundDelaySetting},
|
|
|
|
{"SoundVolume", ScStw::SoundVolumeSetting}
|
|
|
|
};
|
|
|
|
|
|
|
|
ScStw::BaseStationSetting ScStw::baseStationSettingFromString(QString s) {
|
|
|
|
if(!ScStw::baseStationSettings.contains(s))
|
|
|
|
return ScStw::InvalidSetting;
|
|
|
|
|
|
|
|
return ScStw::baseStationSettings[s];
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ScStw::baseStationSettingToString(ScStw::BaseStationSetting s) {
|
|
|
|
for(QString key: ScStw::baseStationSettings.keys()) {
|
|
|
|
if(ScStw::baseStationSettings[key] == s)
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
return "Invalid";
|
|
|
|
}
|
|
|
|
|
|
|
|
ScStw::BaseStationSetting ScStw::baseStationSettingfromInt(int i) {
|
|
|
|
if(i < 0 || i > 4)
|
|
|
|
return InvalidSetting;
|
|
|
|
else
|
|
|
|
return BaseStationSetting(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
ScStw::SignalKey ScStw::signalKeyFromInt(int i) {
|
|
|
|
if(i < 9000 || i > 9003)
|
|
|
|
return InvalidSignal;
|
|
|
|
else
|
|
|
|
return SignalKey(i);
|
|
|
|
}
|
2020-05-10 17:39:16 +02:00
|
|
|
|
|
|
|
ScStw::SocketCommand ScStw::socketCommandFromInt(int i) {
|
|
|
|
QList<SocketCommand> allCommands = {
|
|
|
|
InitializeSessionCommand,
|
|
|
|
|
|
|
|
StartTimersCommand,
|
|
|
|
StopTimersCommand,
|
|
|
|
ResetTimersCommand,
|
|
|
|
|
|
|
|
GetRaceStateCommand,
|
|
|
|
GetNextStartActionCommand,
|
|
|
|
GetExtensionsCommand,
|
|
|
|
GetTimersCommand,
|
|
|
|
GetNextStartActionDetailsCommand,
|
|
|
|
|
|
|
|
WriteSettingCommand,
|
|
|
|
ReadSettingCommand,
|
|
|
|
|
|
|
|
LoginAthleteCommand,
|
|
|
|
CreateAthleteCommand,
|
|
|
|
DeleteAthleteCommand,
|
|
|
|
GetAtheletesCommand,
|
|
|
|
GetAthleteResultsCommand,
|
|
|
|
|
|
|
|
UpdateFirmwareCommand,
|
|
|
|
UpdateSystemTimeCommand,
|
|
|
|
PairExtensionsCommand
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!allCommands.contains(SocketCommand(i)))
|
|
|
|
return InvalidCommand;
|
|
|
|
else
|
|
|
|
return SocketCommand(i);
|
|
|
|
}
|
2020-05-10 18:29:27 +02:00
|
|
|
|
|
|
|
int ScStw::firmwareCompare(QString a, QString b) {
|
|
|
|
/*
|
|
|
|
* * \return -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
|
|
|
|
*/
|
|
|
|
|
|
|
|
if(a.count(".") != 3 || a.length() != 5)
|
|
|
|
return -4;
|
|
|
|
int aMajor = a.split(".")[0].toInt();
|
|
|
|
int aMinor = a.split(".")[1].toInt();
|
|
|
|
int aPatch = a.split(".")[2].toInt();
|
|
|
|
|
|
|
|
if(b.count(".") != 3 || a.length() != 5)
|
|
|
|
return 4;
|
|
|
|
int bMajor = b.split(".")[0].toInt();
|
|
|
|
int bMinor = b.split(".")[1].toInt();
|
|
|
|
int bPatch = b.split(".")[2].toInt();
|
|
|
|
|
|
|
|
if(a == b)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if(aMajor < bMajor)
|
|
|
|
return -3;
|
|
|
|
else
|
|
|
|
return 3;
|
|
|
|
|
|
|
|
if(aMinor < bMinor)
|
|
|
|
return -2;
|
|
|
|
else
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
if(aPatch < bPatch)
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|