Commit 1f055931 authored by Dorian Zedler's avatar Dorian Zedler

minor bugfxes and optimizations

parent 5ad720ec
......@@ -51,6 +51,8 @@ private:
QTcpSocket *socket;
//socket for communication with the extention
QTimer *timeoutTimer;
QString readBuffer;
QSemaphore remoteSessions;
......@@ -86,9 +88,11 @@ signals:
public slots:
Q_INVOKABLE bool connectToHost();
Q_INVOKABLE void connectToHost();
//function to connect to the base station
void connectionTimeout();
Q_INVOKABLE bool init();
Q_INVOKABLE void deInit();
......
......@@ -91,7 +91,7 @@ public slots:
Q_INVOKABLE void writeSetting(QString key, QVariant value);
Q_INVOKABLE QString readSetting(QString key);
Q_INVOKABLE bool connectBaseStation();
Q_INVOKABLE void connectBaseStation();
Q_INVOKABLE void disconnectBaseStation();
Q_INVOKABLE QString getBaseStationState();
Q_INVOKABLE QVariant getBaseStationConnections();
......
......@@ -118,7 +118,7 @@ Popup {
id: headlineUnderline
height: 1
width: parent.width
color: "grey"
color: "transparent"
anchors {
bottom: parent.bottom
left: parent.left
......
......@@ -357,7 +357,7 @@ Popup {
id: connectToBaseDel
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
disconnect: speedBackend.disconnectBaseStation
type: "baseStation"
......
......@@ -5,6 +5,7 @@ SmoothItemDelegate {
id: control
property var status
property string oldState: ""
property var connect
property var disconnect
......@@ -16,16 +17,22 @@ SmoothItemDelegate {
onClicked: {
if(status.status === "disconnected"){
connect()
if(status.status !== "connected"){
statusIndicator.color_override = "red"
shortDelay.start()
}
}
else {
disconnect()
}
}
onStatusChanged: {
if(oldState !== status.status) {
if(status.status === "disconnected" && oldState === "connecting") {
statusIndicator.color_override = "red"
shortDelay.start()
}
oldState = status.status
}
}
Timer {
id: shortDelay
running: false
......@@ -77,19 +84,11 @@ SmoothItemDelegate {
lineWidth: height * 0.1
arcBegin: 0
arcEnd: 0
arcEnd: 360 * ( status.progress / 100 )
colorCircle: "grey"
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 {
NumberAnimation {
duration: 200
......
......@@ -67,18 +67,22 @@ Window {
case 1:
stateString = "STARTING"
settingsDialog.close()
profilesDialog.close()
break;
case 2:
stateString = "WAITING"
settingsDialog.close()
profilesDialog.close()
break;
case 3:
stateString = "RUNNING"
settingsDialog.close()
profilesDialog.close()
break;
case 4:
stateString = "STOPPED"
settingsDialog.close()
profilesDialog.close()
}
root.state = stateString
}
......
......@@ -5,8 +5,13 @@ BaseConn * pGlobalBaseConn = nullptr;
BaseConn::BaseConn(QObject *parent) : QObject(parent)
{
pGlobalBaseConn = 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)),
this, SLOT(gotError(QAbstractSocket::SocketError)));
......@@ -17,30 +22,28 @@ BaseConn::BaseConn(QObject *parent) : QObject(parent)
this->connections = QVariantList({});
}
bool BaseConn::connectToHost() {
void BaseConn::connectToHost() {
qDebug() << "connecting";
setState("connecting");
this->connection_progress = 0;
QEventLoop loop;
// quit loop when state changed (successfull connection is handled elswhere
loop.connect(this, SIGNAL(stateChanged()), &loop, SLOT(quit()));
connect(this->timeoutTimer, SIGNAL(timeout()), this, SLOT(connectionTimeout()));
//connect
this->socket->connectToHost(this->ip, this->port);
while(this->state != "connected" && this->state != "disconnected"){
loop.exec();
}
timeoutTimer->start(3000);
}
if(this->state == "connected") {
return true;
}
return false;
void BaseConn::connectionTimeout() {
this->socket->abort();
disconnect(this->timeoutTimer, SIGNAL(timeout()), this, SLOT(connectionTimeout()));
}
bool BaseConn::init() {
disconnect(this->timeoutTimer, SIGNAL(timeout()), this, SLOT(connectionTimeout()));
this->timeoutTimer->stop();
connect(this->socket, &QTcpSocket::readyRead, this, &BaseConn::readyRead);
this->connection_progress = 50;
......@@ -69,13 +72,7 @@ void BaseConn::closeConnection()
socket->abort();
}
this->deInit();
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)
......@@ -113,7 +110,6 @@ void BaseConn::socketStateChanged(QAbstractSocket::SocketState socketState) {
switch (socketState) {
case QAbstractSocket::UnconnectedState:
{
this->deInit();
this->setState("disconnected");
break;
}
......@@ -143,7 +139,7 @@ QVariantMap BaseConn::sendCommand(int header, QJsonValue data){
// generate id and witing requests entry
int thisId = nextConnectionId;
qDebug() << "sending command: " << header << " with data: " << data << " and id: " << thisId;
//qDebug() << "sending command: " << header << " with data: " << data << " and id: " << thisId;
nextConnectionId ++;
QEventLoop *loop = new QEventLoop(this);
......@@ -325,6 +321,7 @@ QString BaseConn::getState() const
void BaseConn::setState(QString newState){
if(this->state != newState) {
qDebug() << "+--- BaseConn state changed: " << newState;
this->state = newState;
emit stateChanged();
if(this->state == "disconnected") {
......
......@@ -611,9 +611,9 @@ QString ClimbingRace::readSetting(QString key) {
}
}
bool ClimbingRace::connectBaseStation() {
void ClimbingRace::connectBaseStation() {
this->reloadBaseStationIpAdress();
return this->baseConn->connectToHost();
this->baseConn->connectToHost();
}
void ClimbingRace::disconnectBaseStation() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment