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
256fa44c
Commit
256fa44c
authored
Feb 17, 2015
by
Don Gagne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove disconnect/re-connect on too many link errors
Also converted qDebug statements to logging category
parent
f6ef676a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
58 deletions
+35
-58
SerialLink.cc
src/comm/SerialLink.cc
+32
-58
SerialLink.h
src/comm/SerialLink.h
+3
-0
No files found.
src/comm/SerialLink.cc
View file @
256fa44c
...
...
@@ -14,9 +14,12 @@
#include <QMutexLocker>
#include <QSerialPort>
#include <QSerialPortInfo>
#include "SerialLink.h"
#include "QGC.h"
#include <MG.h>
#include "MG.h"
Q_LOGGING_CATEGORY
(
SerialLinkLog
,
"SerialLinkLog"
)
SerialLink
::
SerialLink
(
SerialConfiguration
*
config
)
{
...
...
@@ -33,9 +36,9 @@ SerialLink::SerialLink(SerialConfiguration* config)
// Set unique ID and add link to the list of links
_id
=
getNextLinkId
();
q
Debug
(
)
<<
"Create SerialLink "
<<
config
->
portName
()
<<
config
->
baud
()
<<
config
->
flowControl
()
q
CDebug
(
SerialLinkLog
)
<<
"Create SerialLink "
<<
config
->
portName
()
<<
config
->
baud
()
<<
config
->
flowControl
()
<<
config
->
parity
()
<<
config
->
dataBits
()
<<
config
->
stopBits
();
q
Debug
(
)
<<
"portName: "
<<
config
->
portName
();
q
CDebug
(
SerialLinkLog
)
<<
"portName: "
<<
config
->
portName
();
}
void
SerialLink
::
requestReset
()
...
...
@@ -65,16 +68,14 @@ bool SerialLink::_isBootloader()
}
foreach
(
const
QSerialPortInfo
&
info
,
portList
)
{
// XXX debug statements will be removed once we have 100% stable link reports
// qDebug() << "PortName : " << info.portName()
// << "Description : " << info.description();
// qDebug() << "Manufacturer: " << info.manufacturer();
if
(
info
.
portName
().
trimmed
()
==
_config
->
portName
()
&&
(
info
.
description
().
toLower
().
contains
(
"bootloader"
)
||
info
.
description
().
toLower
().
contains
(
"px4 bl"
)
||
info
.
description
().
toLower
().
contains
(
"px4 fmu v1.6"
)))
{
// qDebug() << "BOOTLOADER FOUND";
return
true
;
qCDebug
(
SerialLinkLog
)
<<
"PortName : "
<<
info
.
portName
()
<<
"Description : "
<<
info
.
description
();
qCDebug
(
SerialLinkLog
)
<<
"Manufacturer: "
<<
info
.
manufacturer
();
if
(
info
.
portName
().
trimmed
()
==
_config
->
portName
()
&&
(
info
.
description
().
toLower
().
contains
(
"bootloader"
)
||
info
.
description
().
toLower
().
contains
(
"px4 bl"
)
||
info
.
description
().
toLower
().
contains
(
"px4 fmu v1.6"
)))
{
qCDebug
(
SerialLinkLog
)
<<
"BOOTLOADER FOUND"
;
return
true
;
}
}
// Not found
...
...
@@ -114,30 +115,6 @@ void SerialLink::run()
}
}
// TODO This needs a bit of TLC still...
// If there are too many errors on this link, disconnect.
if
(
isConnected
()
&&
(
linkErrorCount
>
150
))
{
qDebug
()
<<
"linkErrorCount too high: re-connecting!"
;
linkErrorCount
=
0
;
emit
communicationUpdate
(
getName
(),
tr
(
"Link timeout, not receiving any data, attempting reconnect"
));
if
(
_port
)
{
_port
->
close
();
delete
_port
;
_port
=
NULL
;
}
QGC
::
SLEEP
::
msleep
(
500
);
unsigned
tries
=
0
;
const
unsigned
tries_max
=
15
;
while
(
!
_hardwareConnect
(
_type
)
&&
tries
<
tries_max
)
{
tries
++
;
QGC
::
SLEEP
::
msleep
(
500
);
}
// Give up
if
(
tries
==
tries_max
)
{
break
;
}
}
// Write all our buffered data out the serial port.
if
(
_transmitBuffer
.
count
()
>
0
)
{
_writeMutex
.
lock
();
...
...
@@ -146,7 +123,7 @@ void SerialLink::run()
txSuccess
|=
_port
->
waitForBytesWritten
(
10
);
if
(
!
txSuccess
||
(
numWritten
!=
_transmitBuffer
.
count
()))
{
linkErrorCount
++
;
q
Debug
(
)
<<
"TX Error! written:"
<<
txSuccess
<<
"wrote"
<<
numWritten
<<
", asked for "
<<
_transmitBuffer
.
count
()
<<
"bytes"
;
q
CDebug
(
SerialLinkLog
)
<<
"TX Error! written:"
<<
txSuccess
<<
"wrote"
<<
numWritten
<<
", asked for "
<<
_transmitBuffer
.
count
()
<<
"bytes"
;
}
else
{
...
...
@@ -213,7 +190,7 @@ void SerialLink::run()
}
// end of forever
if
(
_port
)
{
q
Debug
(
)
<<
"Closing Port #"
<<
__LINE__
<<
_port
->
portName
();
q
CDebug
(
SerialLinkLog
)
<<
"Closing Port #"
<<
__LINE__
<<
_port
->
portName
();
_port
->
close
();
delete
_port
;
_port
=
NULL
;
...
...
@@ -276,7 +253,7 @@ bool SerialLink::_disconnect(void)
return
true
;
}
_transmitBuffer
.
clear
();
//clear the output buffer to avoid sending garbage at next connect
q
Debug
(
)
<<
"Already disconnected"
;
q
CDebug
(
SerialLinkLog
)
<<
"Already disconnected"
;
return
true
;
}
...
...
@@ -287,7 +264,7 @@ bool SerialLink::_disconnect(void)
**/
bool
SerialLink
::
_connect
(
void
)
{
q
Debug
(
)
<<
"CONNECT CALLED"
;
q
CDebug
(
SerialLinkLog
)
<<
"CONNECT CALLED"
;
if
(
isRunning
())
_disconnect
();
{
...
...
@@ -309,17 +286,18 @@ bool SerialLink::_connect(void)
bool
SerialLink
::
_hardwareConnect
(
QString
&
type
)
{
if
(
_port
)
{
q
Debug
(
)
<<
"SerialLink:"
<<
QString
::
number
((
long
)
this
,
16
)
<<
"closing port"
;
q
CDebug
(
SerialLinkLog
)
<<
"SerialLink:"
<<
QString
::
number
((
long
)
this
,
16
)
<<
"closing port"
;
_port
->
close
();
QGC
::
SLEEP
::
usleep
(
50000
);
delete
_port
;
_port
=
NULL
;
}
q
Debug
(
)
<<
"SerialLink: hardwareConnect to "
<<
_config
->
portName
();
q
CDebug
(
SerialLinkLog
)
<<
"SerialLink: hardwareConnect to "
<<
_config
->
portName
();
// If we are in the Pixhawk bootloader code wait for it to timeout
if
(
_isBootloader
())
{
q
Debug
(
)
<<
"Not connecting to a bootloader, waiting for 2nd chance"
;
q
CDebug
(
SerialLinkLog
)
<<
"Not connecting to a bootloader, waiting for 2nd chance"
;
const
unsigned
retry_limit
=
12
;
unsigned
retries
;
for
(
retries
=
0
;
retries
<
retry_limit
;
retries
++
)
{
...
...
@@ -353,11 +331,11 @@ bool SerialLink::_hardwareConnect(QString &type)
// TODO This needs a bit of TLC still...
// After the bootloader times out, it still can take a second or so for the USB driver to come up and make
// After the bootloader times out, it still can take a second or so for the
Pixhawk
USB driver to come up and make
// the port available for open. So we retry a few times to wait for it.
for
(
int
openRetries
=
0
;
openRetries
<
4
;
openRetries
++
)
{
if
(
!
_port
->
open
(
QIODevice
::
ReadWrite
))
{
q
Debug
(
)
<<
"Port open failed, retrying"
;
q
CDebug
(
SerialLinkLog
)
<<
"Port open failed, retrying"
;
QGC
::
SLEEP
::
msleep
(
500
);
}
else
{
break
;
...
...
@@ -369,7 +347,7 @@ bool SerialLink::_hardwareConnect(QString &type)
return
false
;
// couldn't open serial port
}
q
Debug
(
)
<<
"Configuring port"
;
q
CDebug
(
SerialLinkLog
)
<<
"Configuring port"
;
_port
->
setBaudRate
(
_config
->
baud
());
_port
->
setDataBits
(
static_cast
<
QSerialPort
::
DataBits
>
(
_config
->
dataBits
()));
_port
->
setFlowControl
(
static_cast
<
QSerialPort
::
FlowControl
>
(
_config
->
flowControl
()));
...
...
@@ -379,7 +357,7 @@ bool SerialLink::_hardwareConnect(QString &type)
emit
communicationUpdate
(
getName
(),
"Opened port!"
);
emit
connected
();
q
Debug
(
)
<<
"CONNECTING LINK: "
<<
__FILE__
<<
__LINE__
<<
"type:"
<<
type
<<
"with settings"
<<
_config
->
portName
()
q
CDebug
(
SerialLinkLog
)
<<
"CONNECTING LINK: "
<<
__FILE__
<<
__LINE__
<<
"type:"
<<
type
<<
"with settings"
<<
_config
->
portName
()
<<
_config
->
baud
()
<<
_config
->
dataBits
()
<<
_config
->
parity
()
<<
_config
->
stopBits
();
return
true
;
// successful connection
...
...
@@ -392,7 +370,7 @@ void SerialLink::linkError(QSerialPort::SerialPortError error)
// when you are done. The reason for this is that this signal is very noisy. For example if you try to
// connect to a PixHawk before it is ready to accept the connection it will output a continuous stream
// of errors until the Pixhawk responds.
//q
Debug(
) << "SerialLink::linkError" << error;
//q
CDebug(SerialLinkLog
) << "SerialLink::linkError" << error;
}
}
...
...
@@ -403,17 +381,13 @@ void SerialLink::linkError(QSerialPort::SerialPortError error)
**/
bool
SerialLink
::
isConnected
()
const
{
bool
isConnected
=
false
;
if
(
_port
)
{
bool
isConnected
=
_port
->
isOpen
();
// qDebug() << "SerialLink #" << __LINE__ << ":"<< m_port->portName()
// << " isConnected =" << QString::number(isConnected);
return
isConnected
;
}
else
{
// qDebug() << "SerialLink #" << __LINE__ << ":" << m_portName
// << " isConnected = NULL";
return
false
;
isConnected
=
_port
->
isOpen
();
}
return
isConnected
;
}
int
SerialLink
::
getId
()
const
...
...
@@ -484,7 +458,7 @@ void SerialLink::_resetConfiguration()
somethingChanged
|=
_port
->
setParity
(
static_cast
<
QSerialPort
::
Parity
>
(
_config
->
parity
()));
}
if
(
somethingChanged
)
{
q
Debug
(
)
<<
"Reconfiguring port"
;
q
CDebug
(
SerialLinkLog
)
<<
"Reconfiguring port"
;
emit
updateLink
(
this
);
}
}
...
...
src/comm/SerialLink.h
View file @
256fa44c
...
...
@@ -42,6 +42,7 @@ class SerialLink;
#include <QString>
#include <QSerialPort>
#include <QMetaType>
#include <QLoggingCategory>
// We use QSerialPort::SerialPortError in a signal so we must declare it as a meta type
Q_DECLARE_METATYPE
(
QSerialPort
::
SerialPortError
)
...
...
@@ -49,6 +50,8 @@ Q_DECLARE_METATYPE(QSerialPort::SerialPortError)
#include "QGCConfig.h"
#include "LinkManager.h"
Q_DECLARE_LOGGING_CATEGORY
(
SerialLinkLog
)
class
SerialConfiguration
:
public
LinkConfiguration
{
public:
...
...
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