minor bugfxes and optimizations
This commit is contained in:
parent
5ad720ecf3
commit
1f055931f7
8 changed files with 45 additions and 41 deletions
|
@ -51,6 +51,8 @@ private:
|
||||||
QTcpSocket *socket;
|
QTcpSocket *socket;
|
||||||
//socket for communication with the extention
|
//socket for communication with the extention
|
||||||
|
|
||||||
|
QTimer *timeoutTimer;
|
||||||
|
|
||||||
QString readBuffer;
|
QString readBuffer;
|
||||||
|
|
||||||
QSemaphore remoteSessions;
|
QSemaphore remoteSessions;
|
||||||
|
@ -86,9 +88,11 @@ signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
Q_INVOKABLE bool connectToHost();
|
Q_INVOKABLE void connectToHost();
|
||||||
//function to connect to the base station
|
//function to connect to the base station
|
||||||
|
|
||||||
|
void connectionTimeout();
|
||||||
|
|
||||||
Q_INVOKABLE bool init();
|
Q_INVOKABLE bool init();
|
||||||
Q_INVOKABLE void deInit();
|
Q_INVOKABLE void deInit();
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ public slots:
|
||||||
Q_INVOKABLE void writeSetting(QString key, QVariant value);
|
Q_INVOKABLE void writeSetting(QString key, QVariant value);
|
||||||
Q_INVOKABLE QString readSetting(QString key);
|
Q_INVOKABLE QString readSetting(QString key);
|
||||||
|
|
||||||
Q_INVOKABLE bool connectBaseStation();
|
Q_INVOKABLE void connectBaseStation();
|
||||||
Q_INVOKABLE void disconnectBaseStation();
|
Q_INVOKABLE void disconnectBaseStation();
|
||||||
Q_INVOKABLE QString getBaseStationState();
|
Q_INVOKABLE QString getBaseStationState();
|
||||||
Q_INVOKABLE QVariant getBaseStationConnections();
|
Q_INVOKABLE QVariant getBaseStationConnections();
|
||||||
|
|
|
@ -118,7 +118,7 @@ Popup {
|
||||||
id: headlineUnderline
|
id: headlineUnderline
|
||||||
height: 1
|
height: 1
|
||||||
width: parent.width
|
width: parent.width
|
||||||
color: "grey"
|
color: "transparent"
|
||||||
anchors {
|
anchors {
|
||||||
bottom: parent.bottom
|
bottom: parent.bottom
|
||||||
left: parent.left
|
left: parent.left
|
||||||
|
|
|
@ -357,7 +357,7 @@ Popup {
|
||||||
id: connectToBaseDel
|
id: connectToBaseDel
|
||||||
text: status.status === "connected" ? qsTr("disconnect"): status.status === "disconnected" ? qsTr("connect"):qsTr("connecting...")
|
text: status.status === "connected" ? qsTr("disconnect"): status.status === "disconnected" ? qsTr("connect"):qsTr("connecting...")
|
||||||
|
|
||||||
status: { "status": speedBackend.baseStationState }
|
status: { "status": speedBackend.baseStationState, "progress": 100 }
|
||||||
connect: speedBackend.connectBaseStation
|
connect: speedBackend.connectBaseStation
|
||||||
disconnect: speedBackend.disconnectBaseStation
|
disconnect: speedBackend.disconnectBaseStation
|
||||||
type: "baseStation"
|
type: "baseStation"
|
||||||
|
|
|
@ -5,6 +5,7 @@ SmoothItemDelegate {
|
||||||
id: control
|
id: control
|
||||||
|
|
||||||
property var status
|
property var status
|
||||||
|
property string oldState: ""
|
||||||
property var connect
|
property var connect
|
||||||
property var disconnect
|
property var disconnect
|
||||||
|
|
||||||
|
@ -16,16 +17,22 @@ SmoothItemDelegate {
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if(status.status === "disconnected"){
|
if(status.status === "disconnected"){
|
||||||
connect()
|
connect()
|
||||||
if(status.status !== "connected"){
|
|
||||||
statusIndicator.color_override = "red"
|
|
||||||
shortDelay.start()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
disconnect()
|
disconnect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onStatusChanged: {
|
||||||
|
if(oldState !== status.status) {
|
||||||
|
if(status.status === "disconnected" && oldState === "connecting") {
|
||||||
|
statusIndicator.color_override = "red"
|
||||||
|
shortDelay.start()
|
||||||
|
}
|
||||||
|
oldState = status.status
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
id: shortDelay
|
id: shortDelay
|
||||||
running: false
|
running: false
|
||||||
|
@ -77,19 +84,11 @@ SmoothItemDelegate {
|
||||||
lineWidth: height * 0.1
|
lineWidth: height * 0.1
|
||||||
|
|
||||||
arcBegin: 0
|
arcBegin: 0
|
||||||
arcEnd: 0
|
arcEnd: 360 * ( status.progress / 100 )
|
||||||
colorCircle: "grey"
|
colorCircle: "grey"
|
||||||
onColorCircleChanged: prog.repaint()
|
onColorCircleChanged: prog.repaint()
|
||||||
|
onArcEndChanged: prog.repaint()
|
||||||
|
|
||||||
Timer {
|
|
||||||
id: prog_refresh
|
|
||||||
running: status.status === "connecting"
|
|
||||||
interval: 1
|
|
||||||
repeat: true
|
|
||||||
onTriggered: {
|
|
||||||
prog.arcEnd = 360 * ( status.progress / 100 )
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Behavior on opacity {
|
Behavior on opacity {
|
||||||
NumberAnimation {
|
NumberAnimation {
|
||||||
duration: 200
|
duration: 200
|
||||||
|
|
|
@ -67,18 +67,22 @@ Window {
|
||||||
case 1:
|
case 1:
|
||||||
stateString = "STARTING"
|
stateString = "STARTING"
|
||||||
settingsDialog.close()
|
settingsDialog.close()
|
||||||
|
profilesDialog.close()
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
stateString = "WAITING"
|
stateString = "WAITING"
|
||||||
settingsDialog.close()
|
settingsDialog.close()
|
||||||
|
profilesDialog.close()
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
stateString = "RUNNING"
|
stateString = "RUNNING"
|
||||||
settingsDialog.close()
|
settingsDialog.close()
|
||||||
|
profilesDialog.close()
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
stateString = "STOPPED"
|
stateString = "STOPPED"
|
||||||
settingsDialog.close()
|
settingsDialog.close()
|
||||||
|
profilesDialog.close()
|
||||||
}
|
}
|
||||||
root.state = stateString
|
root.state = stateString
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,13 @@ BaseConn * pGlobalBaseConn = nullptr;
|
||||||
BaseConn::BaseConn(QObject *parent) : QObject(parent)
|
BaseConn::BaseConn(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
pGlobalBaseConn = this;
|
pGlobalBaseConn = this;
|
||||||
|
|
||||||
socket = new QTcpSocket(this);
|
socket = new QTcpSocket(this);
|
||||||
this->setState("disconnected");
|
|
||||||
|
this->timeoutTimer = new QTimer(this);
|
||||||
|
this->timeoutTimer->setSingleShot(true);
|
||||||
|
|
||||||
|
this->state = "disconnected";
|
||||||
|
|
||||||
connect(this->socket, SIGNAL(error(QAbstractSocket::SocketError)),
|
connect(this->socket, SIGNAL(error(QAbstractSocket::SocketError)),
|
||||||
this, SLOT(gotError(QAbstractSocket::SocketError)));
|
this, SLOT(gotError(QAbstractSocket::SocketError)));
|
||||||
|
@ -17,30 +22,28 @@ BaseConn::BaseConn(QObject *parent) : QObject(parent)
|
||||||
this->connections = QVariantList({});
|
this->connections = QVariantList({});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseConn::connectToHost() {
|
void BaseConn::connectToHost() {
|
||||||
qDebug() << "connecting";
|
qDebug() << "connecting";
|
||||||
setState("connecting");
|
setState("connecting");
|
||||||
this->connection_progress = 0;
|
this->connection_progress = 0;
|
||||||
|
|
||||||
QEventLoop loop;
|
connect(this->timeoutTimer, SIGNAL(timeout()), this, SLOT(connectionTimeout()));
|
||||||
|
|
||||||
// quit loop when state changed (successfull connection is handled elswhere
|
|
||||||
loop.connect(this, SIGNAL(stateChanged()), &loop, SLOT(quit()));
|
|
||||||
|
|
||||||
//connect
|
//connect
|
||||||
this->socket->connectToHost(this->ip, this->port);
|
this->socket->connectToHost(this->ip, this->port);
|
||||||
|
|
||||||
while(this->state != "connected" && this->state != "disconnected"){
|
timeoutTimer->start(3000);
|
||||||
loop.exec();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this->state == "connected") {
|
void BaseConn::connectionTimeout() {
|
||||||
return true;
|
this->socket->abort();
|
||||||
}
|
disconnect(this->timeoutTimer, SIGNAL(timeout()), this, SLOT(connectionTimeout()));
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseConn::init() {
|
bool BaseConn::init() {
|
||||||
|
disconnect(this->timeoutTimer, SIGNAL(timeout()), this, SLOT(connectionTimeout()));
|
||||||
|
this->timeoutTimer->stop();
|
||||||
|
|
||||||
connect(this->socket, &QTcpSocket::readyRead, this, &BaseConn::readyRead);
|
connect(this->socket, &QTcpSocket::readyRead, this, &BaseConn::readyRead);
|
||||||
this->connection_progress = 50;
|
this->connection_progress = 50;
|
||||||
|
|
||||||
|
@ -69,13 +72,7 @@ void BaseConn::closeConnection()
|
||||||
socket->abort();
|
socket->abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
this->deInit();
|
|
||||||
setState("disconnected");
|
setState("disconnected");
|
||||||
// for(int i = 0; i < this->waitingRequests.length(); i++){
|
|
||||||
// this->waitingRequests[i].reply = "ERR_NOT_CONNECTED";
|
|
||||||
// this->waitingRequests[i].loop->quit();
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseConn::gotError(QAbstractSocket::SocketError err)
|
void BaseConn::gotError(QAbstractSocket::SocketError err)
|
||||||
|
@ -113,7 +110,6 @@ void BaseConn::socketStateChanged(QAbstractSocket::SocketState socketState) {
|
||||||
switch (socketState) {
|
switch (socketState) {
|
||||||
case QAbstractSocket::UnconnectedState:
|
case QAbstractSocket::UnconnectedState:
|
||||||
{
|
{
|
||||||
this->deInit();
|
|
||||||
this->setState("disconnected");
|
this->setState("disconnected");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -143,7 +139,7 @@ QVariantMap BaseConn::sendCommand(int header, QJsonValue data){
|
||||||
|
|
||||||
// generate id and witing requests entry
|
// generate id and witing requests entry
|
||||||
int thisId = nextConnectionId;
|
int thisId = nextConnectionId;
|
||||||
qDebug() << "sending command: " << header << " with data: " << data << " and id: " << thisId;
|
//qDebug() << "sending command: " << header << " with data: " << data << " and id: " << thisId;
|
||||||
nextConnectionId ++;
|
nextConnectionId ++;
|
||||||
|
|
||||||
QEventLoop *loop = new QEventLoop(this);
|
QEventLoop *loop = new QEventLoop(this);
|
||||||
|
@ -325,6 +321,7 @@ QString BaseConn::getState() const
|
||||||
|
|
||||||
void BaseConn::setState(QString newState){
|
void BaseConn::setState(QString newState){
|
||||||
if(this->state != newState) {
|
if(this->state != newState) {
|
||||||
|
qDebug() << "+--- BaseConn state changed: " << newState;
|
||||||
this->state = newState;
|
this->state = newState;
|
||||||
emit stateChanged();
|
emit stateChanged();
|
||||||
if(this->state == "disconnected") {
|
if(this->state == "disconnected") {
|
||||||
|
|
|
@ -611,9 +611,9 @@ QString ClimbingRace::readSetting(QString key) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClimbingRace::connectBaseStation() {
|
void ClimbingRace::connectBaseStation() {
|
||||||
this->reloadBaseStationIpAdress();
|
this->reloadBaseStationIpAdress();
|
||||||
return this->baseConn->connectToHost();
|
this->baseConn->connectToHost();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClimbingRace::disconnectBaseStation() {
|
void ClimbingRace::disconnectBaseStation() {
|
||||||
|
|
Reference in a new issue