- added api firmware check before connection is initialized
This commit is contained in:
parent
66a6ea6297
commit
9d6cf5ab38
4 changed files with 91 additions and 9 deletions
|
@ -80,6 +80,8 @@ public:
|
|||
|
||||
/*!
|
||||
* \brief The SocketCommand enum contains all commands the base station can handle
|
||||
*
|
||||
* \see ScStw::socketCommandFromInt()
|
||||
*/
|
||||
enum SocketCommand {
|
||||
InvalidCommand = -1,
|
||||
|
@ -194,8 +196,32 @@ public:
|
|||
*/
|
||||
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 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);
|
||||
|
||||
|
||||
ScStw() : QObject(nullptr) {};
|
||||
private:
|
||||
};
|
||||
|
|
|
@ -45,6 +45,8 @@ public:
|
|||
enum State {DISCONNECTED, CONNECTING, INITIALISING, CONNECTED};
|
||||
Q_ENUM(State);
|
||||
|
||||
const QString API_VERSION = "1.0.0";
|
||||
|
||||
private:
|
||||
// values for the socket connection
|
||||
QString ip;
|
||||
|
@ -58,6 +60,7 @@ private:
|
|||
|
||||
// some meta data of the base station
|
||||
QString firmwareVersion;
|
||||
QString apiVersion;
|
||||
double timeOffset;
|
||||
|
||||
// the current state
|
||||
|
|
|
@ -73,3 +73,45 @@ ScStw::SocketCommand ScStw::socketCommandFromInt(int i) {
|
|||
else
|
||||
return SocketCommand(i);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -65,7 +65,25 @@ bool ScStwClient::init() {
|
|||
return false;
|
||||
}
|
||||
|
||||
this->firmwareVersion = initResponse["data"].toMap()["version"].toString();
|
||||
this->apiVersion = initResponse["data"].toMap()["apiVersion"].toString();
|
||||
int compareResult = ScStw::firmwareCompare(this->apiVersion, this->API_VERSION);
|
||||
if( compareResult == -3 ){
|
||||
// the client version is out of date!!
|
||||
this->closeConnection();
|
||||
return false;
|
||||
}
|
||||
else if(compareResult == 3){
|
||||
// the server version is out of date!!
|
||||
this->closeConnection();
|
||||
return false;
|
||||
}
|
||||
else if(compareResult == -4){
|
||||
// the server sent an invalid version
|
||||
this->closeConnection();
|
||||
return false;
|
||||
}
|
||||
|
||||
this->firmwareVersion = initResponse["data"].toMap()["firmwareVersion"].toString();
|
||||
this->timeOffset = initResponse["data"].toMap()["time"].toDouble() - this->date->currentMSecsSinceEpoch();
|
||||
|
||||
qDebug() << "[INFO][BaseStation] Init done! firmware: version: " << this->firmwareVersion << " up-to-date: " << this->isFirmwareUpToDate() << " time offset: " << this->timeOffset;
|
||||
|
@ -393,16 +411,9 @@ bool ScStwClient::isFirmwareUpToDate() {
|
|||
QString fileContents = f.readAll();
|
||||
|
||||
QString newFirmwareVersion = fileContents.split("<VER>")[1].split("</VER>")[0];
|
||||
int newFirmwareVersionMajor = newFirmwareVersion.split(".")[0].toInt();
|
||||
int newFirmwareVersionMinor = newFirmwareVersion.split(".")[1].toInt();
|
||||
int newFirmwareVersionPatch = newFirmwareVersion.split(".")[2].toInt();
|
||||
|
||||
QString currentFirmwareVersion = this->firmwareVersion;
|
||||
int currentFirmwareVersionMajor = currentFirmwareVersion.split(".")[0].toInt();
|
||||
int currentFirmwareVersionMinor = currentFirmwareVersion.split(".")[1].toInt();
|
||||
int currentFirmwareVersionPatch = currentFirmwareVersion.split(".")[2].toInt();
|
||||
|
||||
return newFirmwareVersionMajor < currentFirmwareVersionMajor || newFirmwareVersionMinor < currentFirmwareVersionMinor || newFirmwareVersionPatch <= currentFirmwareVersionPatch;
|
||||
return ScStw::firmwareCompare(currentFirmwareVersion, newFirmwareVersion) < 0;
|
||||
}
|
||||
|
||||
// ------------------------
|
||||
|
|
Reference in a new issue