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
d1db6938
Commit
d1db6938
authored
Dec 05, 2018
by
Willian Galvani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create UdpIODevice
parent
93d38743
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
0 deletions
+83
-0
qgroundcontrol.pro
qgroundcontrol.pro
+2
-0
CMakeLists.txt
src/comm/CMakeLists.txt
+1
-0
UdpIODevice.cc
src/comm/UdpIODevice.cc
+45
-0
UdpIODevice.h
src/comm/UdpIODevice.h
+35
-0
No files found.
qgroundcontrol.pro
View file @
d1db6938
...
@@ -620,6 +620,7 @@ HEADERS += \
...
@@ -620,6 +620,7 @@ HEADERS += \
src
/
comm
/
QGCMAVLink
.
h
\
src
/
comm
/
QGCMAVLink
.
h
\
src
/
comm
/
TCPLink
.
h
\
src
/
comm
/
TCPLink
.
h
\
src
/
comm
/
UDPLink
.
h
\
src
/
comm
/
UDPLink
.
h
\
src
/
comm
/
UdpIODevice
.
h
\
src
/
uas
/
UAS
.
h
\
src
/
uas
/
UAS
.
h
\
src
/
uas
/
UASInterface
.
h
\
src
/
uas
/
UASInterface
.
h
\
src
/
uas
/
UASMessageHandler
.
h
\
src
/
uas
/
UASMessageHandler
.
h
\
...
@@ -820,6 +821,7 @@ SOURCES += \
...
@@ -820,6 +821,7 @@ SOURCES += \
src
/
comm
/
QGCMAVLink
.
cc
\
src
/
comm
/
QGCMAVLink
.
cc
\
src
/
comm
/
TCPLink
.
cc
\
src
/
comm
/
TCPLink
.
cc
\
src
/
comm
/
UDPLink
.
cc
\
src
/
comm
/
UDPLink
.
cc
\
src
/
comm
/
UdpIODevice
.
cc
\
src
/
main
.
cc
\
src
/
main
.
cc
\
src
/
uas
/
UAS
.
cc
\
src
/
uas
/
UAS
.
cc
\
src
/
uas
/
UASMessageHandler
.
cc
\
src
/
uas
/
UASMessageHandler
.
cc
\
...
...
src/comm/CMakeLists.txt
View file @
d1db6938
...
@@ -24,6 +24,7 @@ add_library(comm
...
@@ -24,6 +24,7 @@ add_library(comm
SerialLink.cc
SerialLink.cc
TCPLink.cc
TCPLink.cc
UDPLink.cc
UDPLink.cc
UdpIODevice.cc
${
EXTRA_SRC
}
${
EXTRA_SRC
}
...
...
src/comm/UdpIODevice.cc
0 → 100644
View file @
d1db6938
/****************************************************************************
*
* (c) 2009-2018 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/
#include "UdpIODevice.h"
#include <algorithm>
UdpIODevice
::
UdpIODevice
(
QObject
*
parent
)
:
QUdpSocket
(
parent
)
{
// this might cause data to be available only after a second readyRead() signal
connect
(
this
,
&
QUdpSocket
::
readyRead
,
this
,
&
UdpIODevice
::
_readAvailableData
);
}
bool
UdpIODevice
::
canReadLine
()
const
{
return
_buffer
.
indexOf
(
'\n'
)
>
-
1
;
}
qint64
UdpIODevice
::
readLineData
(
char
*
data
,
qint64
maxSize
)
{
int
length
=
_buffer
.
indexOf
(
'\n'
)
+
1
;
// add 1 to include the '\n'
if
(
length
==
0
)
{
return
0
;
}
length
=
std
::
min
(
length
,
static_cast
<
int
>
(
maxSize
));
// copy lines to output
std
::
copy
(
_buffer
.
data
(),
_buffer
.
data
()
+
length
,
data
);
// trim buffer to remove consumed line
_buffer
=
_buffer
.
right
(
_buffer
.
size
()
-
length
);
// return number of bytes read
return
length
;
}
void
UdpIODevice
::
_readAvailableData
()
{
while
(
hasPendingDatagrams
())
{
int
previousSize
=
_buffer
.
size
();
_buffer
.
resize
(
static_cast
<
int
>
(
_buffer
.
size
()
+
pendingDatagramSize
()));
readDatagram
((
_buffer
.
data
()
+
previousSize
),
pendingDatagramSize
());
}
}
src/comm/UdpIODevice.h
0 → 100644
View file @
d1db6938
/****************************************************************************
*
* (c) 2009-2018 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/
#pragma once
#include <QUdpSocket>
/**
* @brief QUdpSocket implementation of canReadLine() readLineData() in server mode.
* The UdpIODevice class works almost exactly as a QUdpSocket, but
* also implements canReadLine() and readLineData() while in the bound state.
* Regular QUdpSocket only allows to use these QIODevice interfaces when using
* connectToHost(), which means it is working as a client instead of server.
*
**/
class
UdpIODevice
:
public
QUdpSocket
{
Q_OBJECT
public:
UdpIODevice
(
QObject
*
parent
=
nullptr
);
bool
canReadLine
()
const
;
qint64
readLineData
(
char
*
data
,
qint64
maxSize
);
private
slots
:
void
_readAvailableData
();
private:
QByteArray
_buffer
;
};
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