Commit c571cb8c authored by Dorian Zedler's avatar Dorian Zedler

fixed some connection issues with the basestation and did some cleanup

parent 59bf853f
......@@ -82,7 +82,7 @@
</application>
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="26"/>
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
<!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application.
......
......@@ -47,7 +47,7 @@ RemoteDataListView {
//listData = {}
var retData = speedBackend.getAthletes()
if(retData === undefined){
if(!retData){
status = 500
return
}
......
......@@ -26,36 +26,10 @@ import "./components"
Popup {
id: root
x: startButt.x
y: startButt.y
width: startButt.width
height: startButt.height
modal: true
dim: false
opacity: 0
property var connections
signal connectRequested(var type)
onConnectionsChanged: {
//loop trough all connections
for (var key in connections) {
if(!connections[key])continue; //skip if empty to avoid errors
//check if any connection is in the state "connecting"
if(connections[key]["status"] === "connecting"){
root.closePolicy = Popup.NoAutoClose //make the dalog non-closable
return
}
}
//if no connection is in "conecting" state make popup closable
root.closePolicy = Popup.CloseOnPressOutside
}
function connect(type) {
connectRequested(type)
}
enter: Transition {
NumberAnimation { properties: "opacity"; to: 1; duration: 300; easing.type: Easing.InOutQuad }
NumberAnimation { properties: "scale"; from: 0.9; to: 1; duration: 300; easing.type: Easing.InOutQuad }
......@@ -295,11 +269,7 @@ Popup {
}
function loadSetting(key, del){
var val
val = speedBackend.readSetting(key)
return val
return speedBackend.readSetting(key)
}
SmoothSwitchDelegate {
......@@ -372,7 +342,7 @@ Popup {
}
}
/*-----Page to connect to extenstions like a startpad or buzzer-----*/
/*-----Page to connect to the base station -----*/
Component {
id: connect
Column {
......
......@@ -14,7 +14,6 @@ SmoothItemDelegate {
enabled: (status.status === "disconnected" && control.connect !== undefined) || ( status.status === "connected" && control.disconnect !== undefined )
onClicked: {
if(status.status === "disconnected"){
connect()
if(status.status !== "connected"){
......
......@@ -23,7 +23,7 @@ Item {
ListView {
id: listView
model: control.listData.length
model: control.listData === undefined ? 0:control.listData.length
anchors.fill: parent
......
......@@ -467,20 +467,11 @@ Window {
------*/
SettingsDialog{
id: settingsDialog
connections: root.connections
onConnectRequested: {
switch(type){
case "buzzer":
buzzerConn.connect()
break
case "startpad":
startpadConn.connect()
break
case "baseStation":
baseConn.connectToHost()
break
}
}
x: startButt.x
y: startButt.y
width: startButt.width
height: startButt.height
}
ProfilesDialog {
......@@ -492,8 +483,6 @@ Window {
y: !root.landscape() ? topContainerItm.height + margin:topContainerItm.x + margin
width: root.landscape() ? root.width - topContainerItm.width - menu_container.width - margin * 2 : root.width - margin * 2
height: !root.landscape() ? root.height - topContainerItm.height - menu_container.height - margin * 2 : root.height - margin * 2
}
/*-------------------
......
......@@ -21,46 +21,29 @@ bool BaseConn::connectToHost() {
qDebug() << "connecting";
setState("connecting");
this->connection_progress = 0;
QEventLoop loop;
QTimer timer;
timer.setSingleShot(true);
// quit the loop when the timer times out
loop.connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
//quit the loop when the connection was established
loop.connect(this->socket, SIGNAL(connected()), &loop, SLOT(quit()));
// start the timer before starting to connect
timer.start(3000);
// quit loop when state changed (successfull connection is handled elswhere
loop.connect(this, SIGNAL(stateChanged()), &loop, SLOT(quit()));
//connect
this->socket->connectToHost(this->ip, this->port);
//wait for the connection to finish (programm gets stuck in here)
loop.exec();
//loop finish
if(timer.remainingTime() == -1){
//the time has been triggered -> timeout
this->socket->abort();
return(false);
while(this->state != "connected" && this->state != "disconnected"){
loop.exec();
}
// stop the timer as the connection has been established
timer.stop();
connect(this->socket, &QTcpSocket::readyRead, this, &BaseConn::readyRead);
this->connection_progress = 50;
if(!this->init()){
this->closeConnection();
return false;
if(this->state == "connected") {
return true;
}
this->setState("connected");
return(true);
return false;
}
bool BaseConn::init() {
connect(this->socket, &QTcpSocket::readyRead, this, &BaseConn::readyRead);
this->connection_progress = 50;
return true;
}
......@@ -126,6 +109,33 @@ void BaseConn::gotError(QAbstractSocket::SocketError err)
// --- socket communication handling ---
// -------------------------------------
void BaseConn::socketStateChanged(QAbstractSocket::SocketState socketState) {
switch (socketState) {
case QAbstractSocket::UnconnectedState:
{
this->deInit();
this->setState("disconnected");
break;
}
case QAbstractSocket::ConnectedState:
{
if(this->init()) {
this->setState("connected");
}
else {
this->closeConnection();
}
break;
}
default:
{
//qDebug() << "+ --- UNKNOWN SOCKET STATE: " << socketState;
break;
}
}
}
QVariantMap BaseConn::sendCommand(int header, QJsonValue data){
if(this->state != "connected"){
return {{"status", 910}, {"data", "not connected"}};
......@@ -303,28 +313,12 @@ QString BaseConn::getState() const
}
void BaseConn::setState(QString newState){
this->state = newState;
emit stateChanged();
}
void BaseConn::socketStateChanged(QAbstractSocket::SocketState socketState) {
switch (socketState) {
case QAbstractSocket::UnconnectedState:
{
this->deInit();
this->setState("disconnected");
break;
}
case QAbstractSocket::ConnectedState:
{
//this->setState("connected");
break;
}
default:
{
qDebug() << "+ --- UNKNOWN SOCKET STATE: " << socketState;
break;
}
if(this->state != newState) {
this->state = newState;
emit stateChanged();
if(this->state == "disconnected") {
this->deInit();
}
}
}
......
......@@ -20,6 +20,7 @@ ClimbingRace::ClimbingRace(QObject *parent) : QObject(parent)
this->baseConn->setIP(pGlobalAppSettings->loadSetting("baseStationIpAdress"));
connect(this->baseConn, &BaseConn::stateChanged, this, &ClimbingRace::baseStationStateChanged);
connect(this->baseConn, &BaseConn::stateChanged, this, &ClimbingRace::refreshMode);
connect(this->baseConn, &BaseConn::connectionsChanged, this, &ClimbingRace::baseStationConnectionsChanged);
this->speedTimers.append( new SpeedTimer );
......@@ -53,8 +54,6 @@ int ClimbingRace::startRace() {
return 904;
}
this->refreshMode();
qDebug() << "+ --- starting race";
int returnCode = 900;
......@@ -104,8 +103,6 @@ int ClimbingRace::stopRace(int type) {
// 1: cancel
// 2: fail (fase start)
this->refreshMode();
qDebug() << "+ --- stopping race";
int returnCode = 900;
......@@ -133,7 +130,6 @@ int ClimbingRace::stopRace(int type) {
QVariantMap reply = this->baseConn->sendCommand(1001);
if(reply["status"] != 200){
//handle Error!!
returnCode = reply["status"].toInt();
}
else {
......@@ -153,8 +149,6 @@ int ClimbingRace::resetRace() {
return 904;
}
this->refreshMode();
qDebug() << "+ --- resetting race";
int returnCode = 900;
......@@ -205,6 +199,7 @@ void ClimbingRace::syncWithBaseStation() {
this->baseConn->refreshConnections();
// sync race state
QVariantMap tmpReply = this->baseConn->sendCommand(2000);
if(tmpReply["status"] != 200){
......@@ -367,6 +362,11 @@ void ClimbingRace::refreshMode() {
if(newMode == LOCAL){
// if the new mode is local -> connection to base station has been lost
// reset race
// reset state
this->setState(IDLE);
// reset timers
// go back to one timer
for (int i = 0;i<this->speedTimers.length();i++) {
delete this->speedTimers[i];
......@@ -376,6 +376,7 @@ void ClimbingRace::refreshMode() {
this->speedTimers.append(new SpeedTimer);
// reset base conn
// clear extensions
this->baseConn->connections.clear();
}
......@@ -627,7 +628,6 @@ QVariant ClimbingRace::getBaseStationConnections() {
return baseConn->getConnections();
}
bool ClimbingRace::reloadBaseStationIpAdress() {
if(this->baseConn->state == "disconnected"){
this->baseConn->setIP(pGlobalAppSettings->loadSetting("baseStationIpAdress"));
......
QT += quick sql multimedia
QT += quick qml quickcontrols2 sql multimedia
android {
QT += androidextras
......
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