Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
db5c070a
Commit
db5c070a
authored
Aug 22, 2019
by
Gus Grubba
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle pairing status
parent
3d4f2d8f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
89 additions
and
46 deletions
+89
-46
PairingManager.cc
src/PairingManager/PairingManager.cc
+28
-22
PairingManager.h
src/PairingManager/PairingManager.h
+7
-5
PairingIndicator.qml
src/ui/toolbar/PairingIndicator.qml
+54
-19
No files found.
src/PairingManager/PairingManager.cc
View file @
db5c070a
...
...
@@ -72,8 +72,7 @@ PairingManager::_pairingCompleted(QString name)
_remotePairingMap
[
"NM"
]
=
name
;
emit
pairedListChanged
();
_app
->
informationMessageBoxOnMainThread
(
""
,
tr
(
"Paired with %1"
).
arg
(
name
));
_status
=
PairingSuccess
;
setPairingStatus
(
tr
(
"Pairing successfull"
));
setPairingStatus
(
PairingSuccess
,
tr
(
"Pairing Successfull"
));
}
//-----------------------------------------------------------------------------
...
...
@@ -83,8 +82,7 @@ PairingManager::_connectionCompleted(QString name)
//QString pwd = _remotePairingMap["PWD"].toString();
//_toolbox->microhardManager()->switchToConnectionEncryptionKey(pwd);
_app
->
informationMessageBoxOnMainThread
(
""
,
tr
(
"Connected to %1"
).
arg
(
name
));
_status
=
PairingConnected
;
setPairingStatus
(
tr
(
"Connection successfull"
));
setPairingStatus
(
PairingConnected
,
tr
(
"Connection Successfull"
));
}
//-----------------------------------------------------------------------------
...
...
@@ -111,7 +109,6 @@ PairingManager::_startUploadRequest()
QNetworkRequest
req
;
req
.
setUrl
(
QUrl
(
_uploadURL
));
req
.
setHeader
(
QNetworkRequest
::
ContentTypeHeader
,
"application/x-www-form-urlencoded"
);
QNetworkReply
*
reply
=
_uploadManager
->
post
(
req
,
_uploadData
.
toUtf8
());
connect
(
reply
,
&
QNetworkReply
::
finished
,
this
,
&
PairingManager
::
_uploadFinished
);
}
...
...
@@ -146,15 +143,19 @@ PairingManager::_uploadFinished(void)
}
else
if
(
a
[
0
]
==
"Connected"
&&
a
.
length
()
>
1
)
{
_connectionCompleted
(
a
[
1
]);
}
else
if
(
a
[
0
]
==
"Connection"
&&
a
.
length
()
>
1
)
{
_status
=
PairingConnectionRejected
;
setPairingStatus
(
tr
(
"Connection rejected."
));
setPairingStatus
(
PairingConnectionRejected
,
tr
(
"Connection Rejected"
));
qCDebug
(
PairingManagerLog
)
<<
"Connection error: "
<<
str
;
}
else
{
_status
=
PairingRejected
;
setPairingStatus
(
tr
(
"Pairing rejected."
));
setPairingStatus
(
PairingRejected
,
tr
(
"Pairing Rejected"
));
qCDebug
(
PairingManagerLog
)
<<
"Pairing error: "
<<
str
;
}
delete
_uploadManager
;
_uploadManager
->
deleteLater
();
_uploadManager
=
nullptr
;
}
else
{
if
(
++
_pairRetryCount
>
3
)
{
qCDebug
(
PairingManagerLog
)
<<
"Giving up"
;
setPairingStatus
(
PairingError
,
tr
(
"Too Many Errors"
));
_uploadManager
->
deleteLater
();
_uploadManager
=
nullptr
;
}
else
{
qCDebug
(
PairingManagerLog
)
<<
"Upload error: "
+
reply
->
errorString
();
...
...
@@ -162,6 +163,7 @@ PairingManager::_uploadFinished(void)
}
}
}
}
}
//-----------------------------------------------------------------------------
...
...
@@ -181,8 +183,7 @@ PairingManager::_parsePairingJsonFile()
void
PairingManager
::
connectToPairedDevice
(
QString
name
)
{
_status
=
PairingConnecting
;
setPairingStatus
(
tr
(
"Connecting to %1"
).
arg
(
name
));
setPairingStatus
(
PairingConnecting
,
tr
(
"Connecting to %1"
).
arg
(
name
));
QFile
file
(
_pairingCacheFile
(
name
));
file
.
open
(
QIODevice
::
ReadOnly
|
QIODevice
::
Text
);
QString
json
=
file
.
readAll
();
...
...
@@ -198,6 +199,7 @@ PairingManager::pairedDeviceNameList(void)
while
(
it
.
hasNext
())
{
QFileInfo
fileInfo
(
it
.
next
());
list
.
append
(
fileInfo
.
fileName
());
qCDebug
(
PairingManagerLog
)
<<
"Listing: "
<<
fileInfo
.
fileName
();
}
return
list
;
...
...
@@ -234,10 +236,12 @@ PairingManager::_parsePairingJson(QString jsonEnc)
_jsonDoc
=
QJsonDocument
::
fromJson
(
json
.
toUtf8
());
if
(
_jsonDoc
.
isNull
())
{
setPairingStatus
(
PairingError
,
tr
(
"Invalid Pairing File"
));
qCDebug
(
PairingManagerLog
)
<<
"Failed to create Pairing JSON doc."
;
return
;
}
if
(
!
_jsonDoc
.
isObject
())
{
setPairingStatus
(
PairingError
,
tr
(
"Error Parsing Pairing File"
));
qCDebug
(
PairingManagerLog
)
<<
"Pairing JSON is not an object."
;
return
;
}
...
...
@@ -245,6 +249,7 @@ PairingManager::_parsePairingJson(QString jsonEnc)
QJsonObject
jsonObj
=
_jsonDoc
.
object
();
if
(
jsonObj
.
isEmpty
())
{
setPairingStatus
(
PairingError
,
tr
(
"Error Parsing Pairing File"
));
qCDebug
(
PairingManagerLog
)
<<
"Pairing JSON object is empty."
;
return
;
}
...
...
@@ -257,6 +262,7 @@ PairingManager::_parsePairingJson(QString jsonEnc)
}
if
(
linkType
.
length
()
==
0
)
{
setPairingStatus
(
PairingError
,
tr
(
"Error Parsing Pairing File"
));
qCDebug
(
PairingManagerLog
)
<<
"Pairing JSON is malformed."
;
return
;
}
...
...
@@ -452,9 +458,10 @@ PairingManager::pairingLinkTypeStrings(void)
//-----------------------------------------------------------------------------
void
PairingManager
::
_setPairingStatus
(
QString
status
)
PairingManager
::
_setPairingStatus
(
PairingStatus
status
,
QString
statusStr
)
{
_pairingStatus
=
status
;
_status
=
status
;
_statusString
=
statusStr
;
emit
pairingStatusChanged
();
}
...
...
@@ -462,7 +469,7 @@ PairingManager::_setPairingStatus(QString status)
QString
PairingManager
::
pairingStatusStr
(
void
)
const
{
return
_
pairingStatus
;
return
_
statusString
;
}
#if QGC_GST_MICROHARD_ENABLED
...
...
@@ -471,8 +478,8 @@ void
PairingManager
::
startMicrohardPairing
()
{
stopPairing
();
_
status
=
PairingActive
;
setPairingStatus
(
tr
(
"Microhard pairing running
."
));
_
pairRetryCount
=
0
;
setPairingStatus
(
PairingActive
,
tr
(
"Pairing..
."
));
_parsePairingJson
(
_assumeMicrohardPairingJson
());
}
#endif
...
...
@@ -485,8 +492,7 @@ PairingManager::stopPairing()
pairingNFC
.
stop
();
#endif
_stopUpload
();
_status
=
PairingIdle
;
setPairingStatus
(
""
);
setPairingStatus
(
PairingIdle
,
""
);
}
#if defined QGC_ENABLE_NFC || defined QGC_ENABLE_QTNFC
...
...
@@ -495,7 +501,7 @@ void
PairingManager
::
startNFCScan
()
{
stopPairing
();
emit
pairingStatusChanged
(
);
setPairingStatus
(
PairingActive
,
tr
(
"Pairing..."
)
);
pairingNFC
.
start
();
}
...
...
src/PairingManager/PairingManager.h
View file @
db5c070a
...
...
@@ -55,7 +55,8 @@ public:
PairingConnecting
,
PairingConnected
,
PairingRejected
,
PairingConnectionRejected
PairingConnectionRejected
,
PairingError
};
Q_ENUM
(
PairingStatus
)
...
...
@@ -66,7 +67,7 @@ public:
PairingStatus
pairingStatus
()
{
return
_status
;
}
int
nfcIndex
(
void
)
{
return
_nfcIndex
;
}
int
microhardIndex
(
void
)
{
return
_microhardIndex
;
}
void
setStatusMessage
(
QString
status
)
{
emit
setPairingStatus
(
status
);
}
void
setStatusMessage
(
PairingStatus
status
,
QString
statusStr
)
{
emit
setPairingStatus
(
status
,
statusStr
);
}
void
jsonReceived
(
QString
json
)
{
emit
parsePairingJson
(
json
);
}
#ifdef __android__
static
void
setNativeMethods
(
void
);
...
...
@@ -95,7 +96,7 @@ signals:
void
nameListChanged
();
void
pairingStatusChanged
();
void
parsePairingJson
(
QString
json
);
void
setPairingStatus
(
QString
pairingStatus
);
void
setPairingStatus
(
PairingStatus
status
,
QString
pairingStatus
);
void
pairedListChanged
();
private
slots
:
...
...
@@ -103,14 +104,15 @@ private slots:
void
_stopUpload
();
void
_startUploadRequest
();
void
_parsePairingJson
(
QString
jsonEnc
);
void
_setPairingStatus
(
QString
pairingStatus
);
void
_setPairingStatus
(
PairingStatus
status
,
QString
pairingStatus
);
private:
QString
_
pairingStatus
;
QString
_
statusString
;
QString
_jsonFileName
;
QVariantMap
_remotePairingMap
;
int
_nfcIndex
=
-
1
;
int
_microhardIndex
=
-
1
;
int
_pairRetryCount
=
0
;
PairingStatus
_status
=
PairingIdle
;
AES
_aes
;
QJsonDocument
_jsonDoc
{};
...
...
src/ui/toolbar/PairingIndicator.qml
View file @
db5c070a
...
...
@@ -56,6 +56,9 @@ Item {
MouseArea
{
anchors.fill
:
parent
onClicked
:
{
if
(
QGroundControl
.
pairingManager
.
pairedDeviceNameList
.
length
>
1
)
{
connectionPopup
.
open
()
}
else
{
if
(
QGroundControl
.
pairingManager
.
pairingLinkTypeStrings
.
length
>
1
)
pairingPopup
.
open
()
else
{
...
...
@@ -63,6 +66,7 @@ Item {
}
}
}
}
//-------------------------------------------------------------------------
//-- Pairing
Popup
{
...
...
@@ -91,7 +95,7 @@ Item {
anchors.centerIn
:
parent
Item
{
width
:
1
;
height
:
1
;
}
QGCLabel
{
text
:
qsTr
(
"
No Vehicles Availab
le
"
)
text
:
qsTr
(
"
Pair New Vehic
le
"
)
font.pointSize
:
ScreenTools
.
mediumFontPointSize
font.family
:
ScreenTools
.
demiboldFontFamily
anchors.horizontalCenter
:
parent
.
horizontalCenter
...
...
@@ -166,7 +170,7 @@ Item {
anchors.centerIn
:
parent
Item
{
width
:
1
;
height
:
1
;
}
QGCLabel
{
text
:
qsTr
(
"
No Vehicles Availab
le
"
)
text
:
qsTr
(
"
Pair New Vehic
le
"
)
font.pointSize
:
ScreenTools
.
mediumFontPointSize
font.family
:
ScreenTools
.
demiboldFontFamily
anchors.horizontalCenter
:
parent
.
horizontalCenter
...
...
@@ -235,7 +239,7 @@ Item {
anchors.centerIn
:
parent
Item
{
width
:
1
;
height
:
1
;
}
QGCLabel
{
text
:
qsTr
(
"
No Vehicles Availab
le
"
)
text
:
qsTr
(
"
Pair New Vehic
le
"
)
font.pointSize
:
ScreenTools
.
mediumFontPointSize
font.family
:
ScreenTools
.
demiboldFontFamily
anchors.horizontalCenter
:
parent
.
horizontalCenter
...
...
@@ -287,7 +291,7 @@ Item {
parent
:
Overlay
.
overlay
x
:
Math
.
round
((
mainWindow
.
width
-
width
)
*
0.5
)
y
:
Math
.
round
((
mainWindow
.
height
-
height
)
*
0.5
)
closePolicy
:
Popup
.
CloseOnEscape
|
Popup
.
CloseOnPressOutside
closePolicy
:
cancelButton
.
visible
?
Popup
.
NoAutoClose
:
(
Popup
.
CloseOnEscape
|
Popup
.
CloseOnPressOutside
)
background
:
Rectangle
{
anchors.fill
:
parent
color
:
qgcPal
.
globalTheme
===
QGCPalette
.
Light
?
Qt
.
rgba
(
1
,
1
,
1
,
0.95
)
:
Qt
.
rgba
(
0
,
0
,
0
,
0.75
)
...
...
@@ -310,22 +314,46 @@ Item {
anchors.horizontalCenter
:
parent
.
horizontalCenter
}
Item
{
width
:
1
;
height
:
1
;
}
QGCColoredImage
{
id
:
busyIndicator
height
:
ScreenTools
.
defaultFontPixelHeight
*
2
width
:
height
source
:
"
/qmlimages/MapSync.svg
"
sourceSize.height
:
height
fillMode
:
Image
.
PreserveAspectFit
mipmap
:
true
smooth
:
true
color
:
qgcPal
.
text
visible
:
cancelButton
.
visible
anchors.horizontalCenter
:
parent
.
horizontalCenter
RotationAnimation
on
rotation
{
loops
:
Animation
.
Infinite
from
:
360
to
:
0
duration
:
720
running
:
busyIndicator
.
visible
}
}
QGCLabel
{
text
:
qsTr
(
"
List Of Available Devices
"
)
visible
:
QGroundControl
.
pairingManager
.
pairedDeviceNameList
.
length
>
0
visible
:
QGroundControl
.
pairingManager
.
pairedDeviceNameList
.
length
>
0
&&
!
cancelButton
.
visible
font.pointSize
:
ScreenTools
.
mediumFontPointSize
font.family
:
ScreenTools
.
demiboldFontFamily
}
Item
{
width
:
1
;
height
:
1
;
}
GridLayout
{
columns
:
3
visible
:
QGroundControl
.
pairingManager
.
pairedDeviceNameList
.
length
>
0
visible
:
QGroundControl
.
pairingManager
.
pairedDeviceNameList
.
length
>
0
&&
!
cancelButton
.
visible
columnSpacing
:
ScreenTools
.
defaultFontPixelWidth
rowSpacing
:
ScreenTools
.
defaultFontPixelHeight
*
0.25
anchors.horizontalCenter
:
parent
.
horizontalCenter
Repeater
{
model
:
QGroundControl
.
pairingManager
.
pairedDeviceNameList
QGCLabel
{
text
:
modelData
Layout.minimumWidth
:
ScreenTools
.
defaultFontPixelWidth
*
20
Layout.row
:
index
Layout.column
:
0
Layout.minimumWidth
:
ScreenTools
.
defaultFontPixelWidth
*
14
Layout.fillWidth
:
true
}
}
...
...
@@ -333,6 +361,11 @@ Item {
model
:
QGroundControl
.
pairingManager
.
pairedDeviceNameList
QGCButton
{
text
:
qsTr
(
"
Connect
"
)
Layout.row
:
index
Layout.column
:
1
onClicked
:
{
QGroundControl
.
pairingManager
.
connectToPairedDevice
(
modelData
)
}
}
}
Repeater
{
...
...
@@ -343,6 +376,8 @@ Item {
sourceSize.height
:
height
source
:
"
/res/TrashDelete.svg
"
color
:
qgcPal
.
colorRed
Layout.row
:
index
Layout.column
:
2
MouseArea
{
anchors.fill
:
parent
onClicked
:
{
...
...
@@ -354,8 +389,8 @@ Item {
}
Item
{
width
:
1
;
height
:
1
;
}
RowLayout
{
id
:
pairing
Buttons
visible
:
QGroundControl
.
pairingManager
.
status
===
PairingManager
.
PairingConnected
id
:
connected
Buttons
visible
:
QGroundControl
.
pairingManager
.
pairingStatus
===
PairingManager
.
PairingConnected
||
QGroundControl
.
pairingManager
.
pairingStatus
===
PairingManager
.
PairingIdle
spacing
:
ScreenTools
.
defaultFontPixelWidth
*
4
anchors.horizontalCenter
:
parent
.
horizontalCenter
QGCButton
{
...
...
@@ -372,7 +407,7 @@ Item {
}
}
QGCButton
{
text
:
qsTr
(
"
Go And Fly
"
)
text
:
QGroundControl
.
pairingManager
.
pairingStatus
===
PairingManager
.
PairingConnected
?
qsTr
(
"
Go And Fly
"
)
:
qsTr
(
"
Close
"
)
Layout.minimumWidth
:
_contentWidth
*
0.333
Layout.fillWidth
:
true
onClicked
:
{
...
...
@@ -382,12 +417,12 @@ Item {
}
QGCButton
{
id
:
cancelButton
visible
:
QGroundControl
.
pairingManager
.
status
===
PairingManager
.
PairingActive
||
QGroundControl
.
pairingManager
.
s
tatus
===
PairingManager
.
PairingConnecting
visible
:
QGroundControl
.
pairingManager
.
pairingStatus
===
PairingManager
.
PairingActive
||
QGroundControl
.
pairingManager
.
pairingS
tatus
===
PairingManager
.
PairingConnecting
text
:
qsTr
(
"
Cancel
"
)
width
:
_contentWidth
anchors.horizontalCenter
:
parent
.
horizontalCenter
onClicked
:
{
if
(
QGroundControl
.
pairingManager
.
s
tatus
===
PairingManager
.
PairingActive
)
if
(
QGroundControl
.
pairingManager
.
pairingS
tatus
===
PairingManager
.
PairingActive
)
QGroundControl
.
pairingManager
.
stopPairing
()
else
{
//-- TODO: Cancel connection to paired device
...
...
@@ -396,7 +431,7 @@ Item {
}
}
QGCButton
{
visible
:
!
cancelButton
.
visible
&&
!
pairing
Buttons
.
visible
visible
:
!
cancelButton
.
visible
&&
!
connected
Buttons
.
visible
text
:
qsTr
(
"
Close
"
)
width
:
_contentWidth
anchors.horizontalCenter
:
parent
.
horizontalCenter
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment