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
db465d5a
Commit
db465d5a
authored
Nov 28, 2013
by
Don Gagne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Final TCP link support
parent
d9fe0069
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
184 additions
and
45 deletions
+184
-45
qgcunittest.pro
qgcunittest.pro
+3
-0
qgroundcontrol.pro
qgroundcontrol.pro
+3
-0
TCPLink.cc
src/comm/TCPLink.cc
+43
-41
TCPLink.h
src/comm/TCPLink.h
+12
-2
CommConfigurationWindow.cc
src/ui/CommConfigurationWindow.cc
+5
-2
QGCTCPLinkConfiguration.cc
src/ui/QGCTCPLinkConfiguration.cc
+35
-0
QGCTCPLinkConfiguration.h
src/ui/QGCTCPLinkConfiguration.h
+32
-0
QGCTCPLinkConfiguration.ui
src/ui/QGCTCPLinkConfiguration.ui
+51
-0
No files found.
qgcunittest.pro
View file @
db465d5a
...
...
@@ -200,6 +200,7 @@ FORMS += src/ui/MainWindow.ui \
src
/
ui
/
QGCMAVLinkLogPlayer
.
ui
\
src
/
ui
/
QGCWaypointListMulti
.
ui
\
src
/
ui
/
QGCUDPLinkConfiguration
.
ui
\
src
/
ui
/
QGCTCPLinkConfiguration
.
ui
\
src
/
ui
/
QGCSettingsWidget
.
ui
\
src
/
ui
/
UASControlParameters
.
ui
\
src
/
ui
/
map
/
QGCMapTool
.
ui
\
...
...
@@ -323,6 +324,7 @@ HEADERS += src/MG.h \
src
/
uas
/
QGCMAVLinkUASFactory
.
h
\
src
/
ui
/
QGCWaypointListMulti
.
h
\
src
/
ui
/
QGCUDPLinkConfiguration
.
h
\
src
/
ui
/
QGCTCPLinkConfiguration
.
h
\
src
/
ui
/
QGCSettingsWidget
.
h
\
src
/
ui
/
uas
/
UASControlParameters
.
h
\
src
/
uas
/
QGCUASParamManager
.
h
\
...
...
@@ -490,6 +492,7 @@ SOURCES += src/QGCCore.cc \
src
/
uas
/
QGCMAVLinkUASFactory
.
cc
\
src
/
ui
/
QGCWaypointListMulti
.
cc
\
src
/
ui
/
QGCUDPLinkConfiguration
.
cc
\
src
/
ui
/
QGCTCPLinkConfiguration
.
cc
\
src
/
ui
/
QGCSettingsWidget
.
cc
\
src
/
ui
/
uas
/
UASControlParameters
.
cpp
\
src
/
uas
/
QGCUASParamManager
.
cc
\
...
...
qgroundcontrol.pro
View file @
db465d5a
...
...
@@ -227,6 +227,7 @@ FORMS += src/ui/MainWindow.ui \
src
/
ui
/
QGCMAVLinkLogPlayer
.
ui
\
src
/
ui
/
QGCWaypointListMulti
.
ui
\
src
/
ui
/
QGCUDPLinkConfiguration
.
ui
\
src
/
ui
/
QGCTCPLinkConfiguration
.
ui
\
src
/
ui
/
QGCSettingsWidget
.
ui
\
src
/
ui
/
UASControlParameters
.
ui
\
src
/
ui
/
map
/
QGCMapTool
.
ui
\
...
...
@@ -408,6 +409,7 @@ HEADERS += src/MG.h \
src
/
uas
/
QGCMAVLinkUASFactory
.
h
\
src
/
ui
/
QGCWaypointListMulti
.
h
\
src
/
ui
/
QGCUDPLinkConfiguration
.
h
\
src
/
ui
/
QGCTCPLinkConfiguration
.
h
\
src
/
ui
/
QGCSettingsWidget
.
h
\
src
/
ui
/
uas
/
UASControlParameters
.
h
\
src
/
uas
/
QGCUASParamManager
.
h
\
...
...
@@ -634,6 +636,7 @@ SOURCES += src/main.cc \
src
/
uas
/
QGCMAVLinkUASFactory
.
cc
\
src
/
ui
/
QGCWaypointListMulti
.
cc
\
src
/
ui
/
QGCUDPLinkConfiguration
.
cc
\
src
/
ui
/
QGCTCPLinkConfiguration
.
cc
\
src
/
ui
/
QGCSettingsWidget
.
cc
\
src
/
ui
/
uas
/
UASControlParameters
.
cpp
\
src
/
uas
/
QGCUASParamManager
.
cc
\
...
...
src/comm/TCPLink.cc
View file @
db465d5a
...
...
@@ -37,24 +37,20 @@
#include "LinkManager.h"
#include "QGC.h"
#include <QHostInfo>
//#include <netinet/in.h>
TCPLink
::
TCPLink
(
QHostAddress
host
,
quint16
port
)
:
socket
(
NULL
)
TCPLink
::
TCPLink
(
QHostAddress
hostAddress
,
quint16
socketPort
)
:
host
(
hostAddress
),
port
(
socketPort
),
socket
(
NULL
),
socketIsConnected
(
false
)
{
// FIXFIX: host and port and hard-wired
this
->
host
=
"127.0.0.1"
;
this
->
port
=
5760
;
this
->
socketIsConnected
=
false
;
// Set unique ID and add link to the list of links
this
->
id
=
getNextLinkId
();
// FIXFIX: What about host name?
this
->
name
=
tr
(
"TCP Link (port:%1)"
).
arg
(
this
->
port
);
emit
nameChanged
(
this
->
name
);
qDebug
()
<<
"TCP Created "
<<
name
;
qDebug
()
<<
"TCP Created "
<<
this
->
name
;
}
TCPLink
::~
TCPLink
()
...
...
@@ -63,25 +59,26 @@ TCPLink::~TCPLink()
this
->
deleteLater
();
}
/**
* @brief Runs the thread
*
**/
void
TCPLink
::
run
()
{
exec
();
}
void
TCPLink
::
setAddress
(
const
QString
&
text
)
{
setAddress
(
QHostAddress
(
text
));
}
void
TCPLink
::
setAddress
(
QHostAddress
host
)
{
bool
reconnect
(
false
);
if
(
this
->
isConnected
())
if
(
this
->
isConnected
())
{
disconnect
();
reconnect
=
true
;
}
this
->
host
=
host
;
if
(
reconnect
)
if
(
reconnect
)
{
connect
();
}
...
...
@@ -104,10 +101,9 @@ void TCPLink::setPort(int port)
}
}
void
TCPLink
::
writeBytes
(
const
char
*
data
,
qint64
size
)
#ifdef TCPLINK_READWRITE_DEBUG
void
TCPLink
::
writeDebugBytes
(
const
char
*
data
,
qint16
size
)
{
//#define TCPLINK_DEBUG
#ifdef TCPLINK_DEBUG
QString
bytes
;
QString
ascii
;
for
(
int
i
=
0
;
i
<
size
;
i
++
)
...
...
@@ -123,9 +119,16 @@ void TCPLink::writeBytes(const char* data, qint64 size)
ascii
.
append
(
219
);
}
}
qDebug
()
<<
"Sent"
<<
size
<<
"bytes to"
<<
currentHost
.
toString
()
<<
":"
<<
currentP
ort
<<
"data:"
;
qDebug
()
<<
"Sent"
<<
size
<<
"bytes to"
<<
host
.
toString
()
<<
":"
<<
p
ort
<<
"data:"
;
qDebug
()
<<
bytes
;
qDebug
()
<<
"ASCII:"
<<
ascii
;
}
#endif
void
TCPLink
::
writeBytes
(
const
char
*
data
,
qint64
size
)
{
#ifdef TCPLINK_READWRITE_DEBUG
writeDebugBytes
(
data
,
size
);
#endif
socket
->
write
(
data
,
size
);
}
...
...
@@ -148,17 +151,10 @@ void TCPLink::readBytes()
socket
->
read
(
buffer
.
data
(),
buffer
.
size
());
emit
bytesReceived
(
this
,
buffer
);
// // Echo data for debugging purposes
// std::cerr << __FILE__ << __LINE__ << "Received datagram:" << std::endl;
// int i;
// for (i=0; i<s; i++)
// {
// unsigned int v=data[i];
// fprintf(stderr,"%02x ", v);
// }
// std::cerr << std::endl;
#ifdef TCPLINK_READWRITE_DEBUG
writeDebugBytes
(
buffer
.
data
(),
buffer
.
size
());
#endif
}
}
...
...
@@ -185,10 +181,8 @@ bool TCPLink::disconnect()
if
(
socket
)
{
if
(
socketIsConnected
)
{
socket
->
disconnect
();
socketIsConnected
=
false
;
}
socket
->
disconnect
();
socketIsConnected
=
false
;
delete
socket
;
socket
=
NULL
;
}
...
...
@@ -220,17 +214,25 @@ bool TCPLink::hardwareConnect(void)
socket
->
connectToHost
(
host
,
port
);
QObject
::
connect
(
socket
,
SIGNAL
(
readyRead
()),
this
,
SLOT
(
readBytes
()));
//QObject::connect(socket, SIGNAL(connected()), this, SLOT(socketConnected()));
socketIsConnected
=
true
;
QObject
::
connect
(
socket
,
SIGNAL
(
error
(
QAbstractSocket
::
SocketError
)),
this
,
SLOT
(
socketError
(
QAbstractSocket
::
SocketError
)));
// Give the socket a second to connect to the other side otherwise error out
if
(
!
socket
->
waitForConnected
(
1000
))
{
emit
communicationError
(
getName
(),
"connection failed"
);
return
false
;
}
socketIsConnected
=
true
;
connectionStartTime
=
QGC
::
groundTimeUsecs
()
/
1000
;
emit
connected
(
true
);
return
true
;
}
void
TCPLink
::
socket
Connected
(
)
void
TCPLink
::
socket
Error
(
QAbstractSocket
::
SocketError
socketError
)
{
socketIsConnected
=
true
;
emit
communicationError
(
getName
(),
"Error on socket: "
+
socket
->
errorString
())
;
}
/**
...
...
src/comm/TCPLink.h
View file @
db465d5a
...
...
@@ -40,12 +40,14 @@
#include <LinkInterface.h>
#include <configuration.h>
//#define TCPLINK_READWRITE_DEBUG // Use to debug data reads/writes
class
TCPLink
:
public
LinkInterface
{
Q_OBJECT
public:
TCPLink
(
QHostAddress
host
=
QHostAddress
::
Any
,
quint16
port
=
1455
0
);
TCPLink
(
QHostAddress
host
Address
=
QHostAddress
::
LocalHost
,
quint16
socketPort
=
576
0
);
~
TCPLink
();
void
requestReset
()
{
}
...
...
@@ -55,6 +57,9 @@ public:
int
getPort
()
const
{
return
port
;
}
QHostAddress
getHostAddress
()
const
{
return
host
;
}
QString
getName
()
const
;
int
getBaudRate
()
const
;
...
...
@@ -88,7 +93,9 @@ public slots:
void
writeBytes
(
const
char
*
data
,
qint64
length
);
bool
connect
();
bool
disconnect
();
void
socketConnected
();
void
socketError
(
QAbstractSocket
::
SocketError
socketError
);
void
setAddress
(
const
QString
&
text
);
protected:
QString
name
;
...
...
@@ -112,6 +119,9 @@ protected:
private:
bool
hardwareConnect
(
void
);
#ifdef TCPLINK_READWRITE_DEBUG
void
writeDebugBytes
(
const
char
*
data
,
qint16
size
);
#endif
signals:
//Signals are defined by LinkInterface
...
...
src/ui/CommConfigurationWindow.cc
View file @
db465d5a
...
...
@@ -53,6 +53,7 @@ This file is part of the QGROUNDCONTROL project
#include "MAVLinkProtocol.h"
#include "MAVLinkSettingsWidget.h"
#include "QGCUDPLinkConfiguration.h"
#include "QGCTCPLinkConfiguration.h"
#include "LinkManager.h"
#include "MainWindow.h"
...
...
@@ -152,6 +153,8 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn
}
TCPLink
*
tcp
=
dynamic_cast
<
TCPLink
*>
(
link
);
if
(
tcp
!=
0
)
{
QWidget
*
conf
=
new
QGCTCPLinkConfiguration
(
tcp
,
this
);
ui
.
linkScrollArea
->
setWidget
(
conf
);
ui
.
linkGroupBox
->
setTitle
(
tr
(
"TCP Link"
));
ui
.
linkType
->
setCurrentIndex
(
ui
.
linkType
->
findData
(
QGC_LINK_TCP
));
}
...
...
@@ -264,12 +267,12 @@ void CommConfigurationWindow::setLinkType(qgc_link_t linktype)
}
case
QGC_LINK_TCP
:
{
{
TCPLink
*
tcp
=
new
TCPLink
();
tmpLink
=
tcp
;
MainWindow
::
instance
()
->
addLink
(
tmpLink
);
break
;
}
}
#ifdef OPAL_RT
case
QGC_LINK_OPAL
:
...
...
src/ui/QGCTCPLinkConfiguration.cc
0 → 100644
View file @
db465d5a
#include <QInputDialog>
#include "QGCTCPLinkConfiguration.h"
#include "ui_QGCTCPLinkConfiguration.h"
QGCTCPLinkConfiguration
::
QGCTCPLinkConfiguration
(
TCPLink
*
link
,
QWidget
*
parent
)
:
QWidget
(
parent
),
link
(
link
),
ui
(
new
Ui
::
QGCTCPLinkConfiguration
)
{
ui
->
setupUi
(
this
);
uint16_t
port
=
link
->
getPort
();
ui
->
portSpinBox
->
setValue
(
port
);
QString
addr
=
link
->
getHostAddress
().
toString
();
ui
->
hostAddressLineEdit
->
setText
(
addr
);
connect
(
ui
->
portSpinBox
,
SIGNAL
(
valueChanged
(
int
)),
link
,
SLOT
(
setPort
(
int
)));
connect
(
ui
->
hostAddressLineEdit
,
SIGNAL
(
textChanged
(
const
QString
&
)),
link
,
SLOT
(
setAddress
(
const
QString
&
)));
}
QGCTCPLinkConfiguration
::~
QGCTCPLinkConfiguration
()
{
delete
ui
;
}
void
QGCTCPLinkConfiguration
::
changeEvent
(
QEvent
*
e
)
{
QWidget
::
changeEvent
(
e
);
switch
(
e
->
type
())
{
case
QEvent
:
:
LanguageChange
:
ui
->
retranslateUi
(
this
);
break
;
default:
break
;
}
}
\ No newline at end of file
src/ui/QGCTCPLinkConfiguration.h
0 → 100644
View file @
db465d5a
#ifndef QGCTCPLINKCONFIGURATION_H
#define QGCTCPLINKCONFIGURATION_H
#include <QWidget>
#include "TCPLink.h"
namespace
Ui
{
class
QGCTCPLinkConfiguration
;
}
class
QGCTCPLinkConfiguration
:
public
QWidget
{
Q_OBJECT
public:
explicit
QGCTCPLinkConfiguration
(
TCPLink
*
link
,
QWidget
*
parent
=
0
);
~
QGCTCPLinkConfiguration
();
public
slots
:
protected:
void
changeEvent
(
QEvent
*
e
);
TCPLink
*
link
;
///< TCP link instance this widget configures
private:
Ui
::
QGCTCPLinkConfiguration
*
ui
;
};
#endif // QGCTCPLINKCONFIGURATION_H
src/ui/QGCTCPLinkConfiguration.ui
0 → 100644
View file @
db465d5a
<?xml version="1.0" encoding="UTF-8"?>
<ui
version=
"4.0"
>
<class>
QGCTCPLinkConfiguration
</class>
<widget
class=
"QWidget"
name=
"QGCTCPLinkConfiguration"
>
<property
name=
"geometry"
>
<rect>
<x>
0
</x>
<y>
0
</y>
<width>
400
</width>
<height>
300
</height>
</rect>
</property>
<property
name=
"windowTitle"
>
<string>
Form
</string>
</property>
<layout
class=
"QFormLayout"
name=
"formLayout"
>
<property
name=
"fieldGrowthPolicy"
>
<enum>
QFormLayout::FieldsStayAtSizeHint
</enum>
</property>
<item
row=
"0"
column=
"0"
>
<widget
class=
"QLabel"
name=
"portLabel"
>
<property
name=
"text"
>
<string>
TCP Port
</string>
</property>
</widget>
</item>
<item
row=
"0"
column=
"1"
>
<widget
class=
"QSpinBox"
name=
"portSpinBox"
>
<property
name=
"minimum"
>
<number>
3000
</number>
</property>
<property
name=
"maximum"
>
<number>
100000
</number>
</property>
</widget>
</item>
<item
row=
"1"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label"
>
<property
name=
"text"
>
<string>
Host Address
</string>
</property>
</widget>
</item>
<item
row=
"1"
column=
"1"
>
<widget
class=
"QLineEdit"
name=
"hostAddressLineEdit"
/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
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