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