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
9b5c656f
Commit
9b5c656f
authored
Jul 19, 2013
by
Bill Bonney
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix to improve QSerialPort integration & stability.
parent
fb6efcee
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
36 deletions
+44
-36
SerialLink.cc
src/comm/SerialLink.cc
+30
-24
SerialLink.h
src/comm/SerialLink.h
+4
-2
SerialLinkInterface.h
src/comm/SerialLinkInterface.h
+1
-1
QGCToolBar.cc
src/ui/QGCToolBar.cc
+3
-3
SerialConfigurationWindow.cc
src/ui/SerialConfigurationWindow.cc
+6
-6
No files found.
src/comm/SerialLink.cc
View file @
9b5c656f
...
...
@@ -23,7 +23,6 @@ SerialLink::SerialLink(QString portname, int baudRate, bool hardwareFlowControl,
int
dataBits
,
int
stopBits
)
:
m_bytesRead
(
0
),
m_port
(
NULL
),
m_ports
(
new
QVector
<
QString
>
()),
m_stopp
(
false
),
m_reqReset
(
false
)
{
...
...
@@ -32,9 +31,9 @@ SerialLink::SerialLink(QString portname, int baudRate, bool hardwareFlowControl,
// Setup settings
m_portName
=
portname
.
trimmed
();
if
(
m_portName
==
""
&&
getCurrentPorts
()
->
size
()
>
0
)
if
(
m_portName
==
""
&&
getCurrentPorts
()
.
size
()
>
0
)
{
m_portName
=
m_ports
->
first
().
trimmed
();
m_portName
=
m_ports
.
first
().
trimmed
();
}
qDebug
()
<<
"m_portName "
<<
m_portName
;
...
...
@@ -87,14 +86,11 @@ SerialLink::~SerialLink()
disconnect
();
if
(
m_port
)
delete
m_port
;
m_port
=
NULL
;
if
(
m_ports
)
delete
m_ports
;
m_ports
=
NULL
;
}
Q
Vector
<
QString
>*
SerialLink
::
getCurrentPorts
()
Q
List
<
QString
>
SerialLink
::
getCurrentPorts
()
{
Q_ASSERT_X
(
m_ports
!=
NULL
,
"getCurrentPorts"
,
"m_ports is NULL"
);
m_ports
->
clear
();
m_ports
.
clear
();
// Example use QSerialPortInfo
// [TODO] make this thread safe
...
...
@@ -110,7 +106,7 @@ QVector<QString>* SerialLink::getCurrentPorts()
// << "Description : " << info.description();
// qDebug() << "Manufacturer: " << info.manufacturer();
m_ports
->
append
(
info
.
portName
());
m_ports
.
append
(
info
.
portName
());
}
return
m_ports
;
}
...
...
@@ -186,6 +182,18 @@ void SerialLink::run()
m_port
->
setDataTerminalReady
(
false
);
}
}
if
(
m_transmitBuffer
.
size
()
>
0
)
{
// send the data
QMutexLocker
lockWrite
(
&
m_writeMutex
);
int
num_written
=
m_port
->
write
(
m_transmitBuffer
.
constData
());
if
(
num_written
>
0
){
m_transmitBuffer
=
m_transmitBuffer
.
remove
(
0
,
num_written
);
}
}
bool
error
=
m_port
->
waitForReadyRead
(
500
);
if
(
error
)
{
// Waits for 1/2 second [TODO][BB] lower to SerialLink::poll_interval?
...
...
@@ -203,7 +211,6 @@ void SerialLink::run()
// qDebug() << "readyReadTime #"<< __LINE__;
}
if
(
bytes
!=
m_bytesRead
)
// i.e things are good and data is being read.
{
bytes
=
m_bytesRead
;
...
...
@@ -265,26 +272,25 @@ void SerialLink::writeBytes(const char* data, qint64 size)
{
if
(
m_port
&&
m_port
->
isOpen
())
{
// qDebug() << "writeBytes" << m_portName << "attempting to tx " << size << "bytes.";
int
b
=
m_port
->
write
(
data
,
size
);
if
(
b
>
0
)
{
Q_ASSERT_X
(
b
=
size
,
"writeBytes"
,
"failed to write all bytes"
);
QByteArray
byteArray
(
data
,
size
);
{
QMutexLocker
writeLocker
(
&
m_writeMutex
);
m_transmitBuffer
.
append
(
byteArray
);
}
//
qDebug() << "writeBytes " << m_portName << "tx'd" << b << "bytes:";
// qDebug() << "writeBytes " << m_portName << "tx'd" << b << "bytes:";
// Increase write counter
m_bitsSentTotal
+=
size
*
8
;
// Increase write counter
m_bitsSentTotal
+=
size
*
8
;
// Extra debug logging
// QByteArray* byteArray = new QByteArray(data,size);
// Extra debug logging
// qDebug() << byteArray->toHex();
// delete byteArray;
}
else
{
disconnect
();
// Error occured
emit
communicationError
(
getName
(),
tr
(
"Could not send data - link %1 is disconnected!"
).
arg
(
getName
()));
}
}
else
{
disconnect
();
// Error occured
emit
communicationError
(
getName
(),
tr
(
"Could not send data - link %1 is disconnected!"
).
arg
(
getName
()));
}
}
...
...
src/comm/SerialLink.h
View file @
9b5c656f
...
...
@@ -65,7 +65,7 @@ public:
static
const
int
poll_interval
=
SERIAL_POLL_INTERVAL
;
///< Polling interval, defined in configuration.h
/** @brief Get a list of the currently available ports */
Q
Vector
<
QString
>*
getCurrentPorts
();
Q
List
<
QString
>
getCurrentPorts
();
void
requestReset
();
...
...
@@ -166,12 +166,14 @@ protected:
quint64
m_connectionStartTime
;
QMutex
m_statisticsMutex
;
QMutex
m_dataMutex
;
Q
Vector
<
QString
>*
m_ports
;
Q
List
<
QString
>
m_ports
;
private:
volatile
bool
m_stopp
;
volatile
bool
m_reqReset
;
QMutex
m_stoppMutex
;
QMutex
m_writeMutex
;
QByteArray
m_transmitBuffer
;
bool
hardwareConnect
();
...
...
src/comm/SerialLinkInterface.h
View file @
9b5c656f
...
...
@@ -42,7 +42,7 @@ class SerialLinkInterface : public LinkInterface
Q_OBJECT
public:
virtual
Q
Vector
<
QString
>*
getCurrentPorts
()
=
0
;
virtual
Q
List
<
QString
>
getCurrentPorts
()
=
0
;
virtual
QString
getPortName
()
=
0
;
virtual
int
getBaudRate
()
=
0
;
virtual
int
getDataBits
()
=
0
;
...
...
src/ui/QGCToolBar.cc
View file @
9b5c656f
...
...
@@ -577,12 +577,12 @@ void QGCToolBar::updateComboBox()
if
(
slink
)
{
//It's a serial link
Q
Vector
<
QString
>
*
portlist
=
slink
->
getCurrentPorts
();
Q
List
<
QString
>
portlist
=
slink
->
getCurrentPorts
();
//if (!slink->isConnected())
//{
for
(
int
j
=
0
;
j
<
portlist
->
size
();
j
++
)
for
(
int
j
=
0
;
j
<
portlist
.
count
();
j
++
)
{
portComboBox
->
addItem
(
"Serial port:"
+
QString
::
number
(
i
)
+
":"
+
portlist
->
at
(
j
)
);
portComboBox
->
addItem
(
"Serial port:"
+
QString
::
number
(
i
)
+
":"
+
portlist
[
j
]
);
}
//}
//We only really want to display from unconnected sources.
...
...
src/ui/SerialConfigurationWindow.cc
View file @
9b5c656f
...
...
@@ -216,23 +216,23 @@ void SerialConfigurationWindow::setupPortList()
if
(
!
link
)
return
;
// Get the ports available on this system
Q
Vector
<
QString
>*
ports
=
link
->
getCurrentPorts
();
Q
List
<
QString
>
ports
=
link
->
getCurrentPorts
();
QString
storedName
=
this
->
link
->
getPortName
();
bool
storedFound
=
false
;
// Add the ports in reverse order, because we prepend them to the list
for
(
int
i
=
ports
->
size
()
-
1
;
i
>=
0
;
--
i
)
for
(
int
i
=
ports
.
count
()
-
1
;
i
>=
0
;
--
i
)
{
// Prepend newly found port to the list
if
(
ui
.
portName
->
findText
(
ports
->
at
(
i
)
)
==
-
1
)
if
(
ui
.
portName
->
findText
(
ports
[
i
]
)
==
-
1
)
{
ui
.
portName
->
insertItem
(
0
,
ports
->
at
(
i
)
);
if
(
!
userConfigured
)
ui
.
portName
->
setEditText
(
ports
->
at
(
i
)
);
ui
.
portName
->
insertItem
(
0
,
ports
[
i
]
);
if
(
!
userConfigured
)
ui
.
portName
->
setEditText
(
ports
[
i
]
);
}
// Check if the stored link name is still present
if
(
ports
->
at
(
i
).
contains
(
storedName
)
||
storedName
.
contains
(
ports
->
at
(
i
)
))
if
(
ports
[
i
].
contains
(
storedName
)
||
storedName
.
contains
(
ports
[
i
]
))
storedFound
=
true
;
}
...
...
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