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
2402fc33
Commit
2402fc33
authored
Aug 18, 2010
by
Bryan Godbolt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Heartbeats working, but uas not created
parent
036d1bef
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
96 additions
and
3 deletions
+96
-3
OpalLink.cc
src/comm/OpalLink.cc
+65
-1
OpalLink.h
src/comm/OpalLink.h
+31
-2
No files found.
src/comm/OpalLink.cc
View file @
2402fc33
#include "OpalLink.h"
OpalLink
::
OpalLink
()
:
connectState
(
false
)
OpalLink
::
OpalLink
()
:
connectState
(
false
),
heartbeatTimer
(
new
QTimer
(
this
)),
heartbeatRate
(
MAVLINK_HEARTBEAT_DEFAULT_RATE
),
m_heartbeatsEnabled
(
true
),
receiveBuffer
(
new
QQueue
<
QByteArray
>
()),
systemID
(
1
),
componentID
(
1
)
{
start
(
QThread
::
LowPriority
);
// Set unique ID and add link to the list of links
this
->
id
=
getNextLinkId
();
this
->
name
=
tr
(
"OpalRT link "
)
+
QString
::
number
(
getId
());
LinkManager
::
instance
()
->
add
(
this
);
// Start heartbeat timer, emitting a heartbeat at the configured rate
qDebug
()
<<
"OpalLink::OpalLink:: Connect the timer"
;
QObject
::
connect
(
heartbeatTimer
,
SIGNAL
(
timeout
()),
this
,
SLOT
(
heartbeat
()));
heartbeatTimer
->
start
(
1000
/
heartbeatRate
);
}
void
OpalLink
::
run
()
{
qDebug
()
<<
"OpalLink::run():: Starting the thread"
;
}
int
OpalLink
::
getId
()
...
...
@@ -134,4 +152,50 @@ void OpalLink::writeBytes(const char *bytes, qint64 length)
void
OpalLink
::
readBytes
(
char
*
bytes
,
qint64
maxLength
)
{
receiveDataMutex
.
lock
();
qDebug
()
<<
"OpalLink::readBytes(): Reading a message. size of buffer: "
<<
receiveBuffer
->
count
();
QByteArray
message
=
receiveBuffer
->
dequeue
();
if
(
maxLength
<
message
.
size
())
{
qDebug
()
<<
"OpalLink::readBytes:: Buffer Overflow"
;
memcpy
(
bytes
,
message
.
data
(),
maxLength
);
}
else
{
memcpy
(
bytes
,
message
.
data
(),
message
.
size
());
}
emit
bytesReceived
(
this
,
message
);
receiveDataMutex
.
unlock
();
}
void
OpalLink
::
heartbeat
()
{
if
(
m_heartbeatsEnabled
)
{
qDebug
()
<<
"OpalLink::heartbeat(): Generate a heartbeat"
;
mavlink_message_t
beat
;
mavlink_msg_heartbeat_pack
(
systemID
,
componentID
,
&
beat
,
MAV_HELICOPTER
,
MAV_AUTOPILOT_GENERIC
);
receiveMessage
(
beat
);
}
}
void
OpalLink
::
receiveMessage
(
mavlink_message_t
message
)
{
// Create buffer
char
buffer
[
MAVLINK_MAX_PACKET_LEN
];
// Write message into buffer, prepending start sign
int
len
=
mavlink_msg_to_send_buffer
((
uint8_t
*
)(
buffer
),
&
message
);
// If link is connected
if
(
isConnected
())
{
receiveBuffer
->
enqueue
(
QByteArray
(
buffer
,
len
));
emit
bytesReady
(
this
);
}
}
src/comm/OpalLink.h
View file @
2402fc33
...
...
@@ -10,17 +10,28 @@
#include <QMutex>
#include <QDebug>
#include <QMessageBox>
#include <QTimer>
#include <QQueue>
#include <QByteArray>
#include <QObject>
#include "LinkInterface.h"
#include "LinkManager.h"
#include "MG.h"
#include "mavlink.h"
#include "mavlink_types.h"
#include "configuration.h"
#include "errno.h"
#include "OpalApi.h"
#include "string.h"
class
OpalLink
:
public
LinkInterface
{
Q_OBJECT
public:
OpalLink
();
/* Connection management */
int
getId
();
...
...
@@ -49,6 +60,8 @@ class OpalLink : public LinkInterface
qint64
bytesAvailable
();
void
run
();
public
slots
:
...
...
@@ -57,9 +70,13 @@ public slots:
void
readBytes
(
char
*
bytes
,
qint64
maxLength
);
void
heartbeat
();
protected
slots
:
void
receiveMessage
(
mavlink_message_t
message
);
public:
OpalLink
();
protected:
QString
name
;
...
...
@@ -75,10 +92,22 @@ protected:
quint64
connectionStartTime
;
QMutex
statisticsMutex
;
QMutex
receiveDataMutex
;
QString
lastErrorMsg
;
void
setLastErrorMsg
();
void
setName
(
QString
name
);
QTimer
*
heartbeatTimer
;
///< Timer to emit heartbeats
int
heartbeatRate
;
///< Heartbeat rate, controls the timer interval
bool
m_heartbeatsEnabled
;
///< Enabled/disable heartbeat emission
QQueue
<
QByteArray
>*
receiveBuffer
;
QByteArray
*
sendBuffer
;
const
int
systemID
;
const
int
componentID
;
};
#endif // OPALLINK_H
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