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/>.
|
|
|
|
****************************************************************************/
|
|
|
|
|
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
|
|
|
|
|
|
|
ScStw::SignalKey ScStw::signalKeyFromInt(int i) {
|
2020-05-27 12:35:01 +02:00
|
|
|
bool ok;
|
|
|
|
ScStw::SignalKey k = ScStw::toEnumValue<ScStw::SignalKey>(i, &ok);
|
|
|
|
if(!ok)
|
2020-04-06 22:06:14 +02:00
|
|
|
return InvalidSignal;
|
|
|
|
else
|
2020-05-27 12:35:01 +02:00
|
|
|
return k;
|
2020-04-06 22:06:14 +02:00
|
|
|
}
|
2020-05-10 17:39:16 +02:00
|
|
|
|
|
|
|
ScStw::SocketCommand ScStw::socketCommandFromInt(int i) {
|
2020-05-27 12:35:01 +02:00
|
|
|
bool ok;
|
|
|
|
SocketCommand c = ScStw::toEnumValue<ScStw::SocketCommand>(i, &ok);
|
|
|
|
if(!ok)
|
2020-05-10 17:39:16 +02:00
|
|
|
return InvalidCommand;
|
|
|
|
else
|
2020-05-27 12:35:01 +02:00
|
|
|
return c;
|
2020-05-10 17:39:16 +02:00
|
|
|
}
|
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
|
|
|
|
*/
|
|
|
|
|
2020-05-10 18:39:58 +02:00
|
|
|
if(a.count(".") != 2 || a.length() != 5)
|
2020-05-10 18:29:27 +02:00
|
|
|
return -4;
|
|
|
|
int aMajor = a.split(".")[0].toInt();
|
|
|
|
int aMinor = a.split(".")[1].toInt();
|
|
|
|
int aPatch = a.split(".")[2].toInt();
|
|
|
|
|
2020-05-10 18:39:58 +02:00
|
|
|
if(b.count(".") != 2 || a.length() != 5)
|
2020-05-10 18:29:27 +02:00
|
|
|
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;
|
|
|
|
}
|