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
0e73f417
Commit
0e73f417
authored
Apr 24, 2011
by
lm
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'new-uart' into opmapcontrol
parents
79948c12
4b2663b5
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
233 additions
and
298 deletions
+233
-298
qgroundcontrol.pro
qgroundcontrol.pro
+1
-2
SerialInterface.h
src/comm/SerialInterface.h
+0
-62
SerialLink.cc
src/comm/SerialLink.cc
+171
-214
SerialLink.h
src/comm/SerialLink.h
+11
-12
SerialConfigurationWindow.cc
src/ui/SerialConfigurationWindow.cc
+41
-3
LinechartWidget.cc
src/ui/linechart/LinechartWidget.cc
+2
-2
qportsettings.h
thirdParty/qserialport/include/QtSerialPort/qportsettings.h
+7
-3
No files found.
qgroundcontrol.pro
View file @
0e73f417
...
...
@@ -128,7 +128,7 @@ INCLUDEPATH += . \
thirdParty
/
qserialport
/
src
#
Include
serial
port
library
include
(
src
/
lib
/
qextserialport
/
qextserialport
.
pri
)
#
include
(
src
/
lib
/
qextserialport
/
qextserialport
.
pri
)
#
include
qserial
library
include
(
thirdParty
/
qserialport
/
qgroundcontrol
-
qserialport
.
pri
)
...
...
@@ -208,7 +208,6 @@ HEADERS += src/MG.h \
src
/
comm
/
LinkManager
.
h
\
src
/
comm
/
LinkInterface
.
h
\
src
/
comm
/
SerialLinkInterface
.
h
\
src
/
comm
/
SerialInterface
.
h
\
src
/
comm
/
SerialLink
.
h
\
src
/
comm
/
SerialSimulationLink
.
h
\
src
/
comm
/
ProtocolInterface
.
h
\
...
...
src/comm/SerialInterface.h
View file @
0e73f417
...
...
@@ -33,7 +33,6 @@ This file is part of the QGROUNDCONTROL project
#define SERIALINTERFACE_H
#include <QIODevice>
#include "qextserialport.h"
#include <QtSerialPort/QSerialPort>
#include <iostream>
...
...
@@ -138,67 +137,6 @@ public:
virtual
void
setFlow
(
flowType
flow
)
=
0
;
};
class
SerialQextserial
:
public
SerialInterface
{
Q_OBJECT
private:
QextSerialPort
*
_port
;
signals:
void
aboutToClose
();
public:
SerialQextserial
(
QString
porthandle
,
QextSerialPort
::
QueryMode
mode
)
:
_port
(
NULL
)
{
_port
=
new
QextSerialPort
(
porthandle
,
QextSerialPort
::
Polling
);
QObject
::
connect
(
_port
,
SIGNAL
(
aboutToClose
()),
this
,
SIGNAL
(
aboutToClose
()));
}
~
SerialQextserial
()
{
delete
_port
;
_port
=
NULL
;
}
virtual
bool
isOpen
()
{
return
_port
->
isOpen
();
}
virtual
bool
isWritable
()
{
return
_port
->
isWritable
();
}
virtual
qint64
bytesAvailable
()
{
return
_port
->
bytesAvailable
();
}
virtual
int
write
(
const
char
*
data
,
qint64
size
)
{
return
_port
->
write
(
data
,
size
);
}
virtual
void
read
(
char
*
data
,
qint64
numBytes
)
{
_port
->
read
(
data
,
numBytes
);
}
virtual
void
flush
()
{
_port
->
flush
();
}
virtual
void
close
()
{
_port
->
close
();
}
virtual
void
open
(
QIODevice
::
OpenModeFlag
flag
)
{
_port
->
open
(
flag
);
}
virtual
void
setBaudRate
(
SerialInterface
::
baudRateType
baudrate
)
{
_port
->
setBaudRate
((
BaudRateType
)
baudrate
);
}
virtual
void
setParity
(
SerialInterface
::
parityType
parity
)
{
_port
->
setParity
((
ParityType
)
parity
);
}
virtual
void
setStopBits
(
SerialInterface
::
stopBitsType
stopBits
)
{
_port
->
setStopBits
((
StopBitsType
)
stopBits
);
}
virtual
void
setDataBits
(
SerialInterface
::
dataBitsType
dataBits
)
{
_port
->
setDataBits
((
DataBitsType
)
dataBits
);
}
virtual
void
setTimeout
(
qint64
timeout
)
{
_port
->
setTimeout
(
timeout
);
}
virtual
void
setFlow
(
SerialInterface
::
flowType
flow
)
{
// TODO implement
_port
->
setFlowControl
((
FlowType
)
flow
);
}
};
using
namespace
TNX
;
class
SerialQserial
:
public
SerialInterface
...
...
src/comm/SerialLink.cc
View file @
0e73f417
...
...
@@ -21,10 +21,12 @@
#include "windows.h"
#endif
using
namespace
TNX
;
//#define USE_QEXTSERIAL // this allows us to revert to old serial library during transition
SerialLink
::
SerialLink
(
QString
portname
,
SerialInterface
::
baudRateType
baudrate
,
SerialInterface
::
flowType
flow
,
SerialInterface
::
parityType
parity
,
SerialInterface
::
dataBitsType
dataBits
,
SerialInterface
::
stopBitsType
stopBits
)
:
SerialLink
::
SerialLink
(
QString
portname
,
int
baudRate
,
bool
hardwareFlowControl
,
bool
parity
,
int
dataBits
,
int
stopBits
)
:
port
(
NULL
)
{
// Setup settings
...
...
@@ -40,12 +42,25 @@ SerialLink::SerialLink(QString portname, SerialInterface::baudRateType baudrate,
// Set unique ID and add link to the list of links
this
->
id
=
getNextLinkId
();
this
->
baudrate
=
baudrate
;
this
->
flow
=
flow
;
this
->
parity
=
parity
;
this
->
dataBits
=
dataBits
;
this
->
stopBits
=
stopBits
;
this
->
timeout
=
1
;
///< The timeout controls how long the program flow should wait for new serial bytes. As we're polling, we don't want to wait at all.
setBaudRate
(
baudRate
);
if
(
hardwareFlowControl
)
{
portSettings
.
setFlowControl
(
QPortSettings
::
FLOW_HARDWARE
);
}
else
{
portSettings
.
setFlowControl
(
QPortSettings
::
FLOW_OFF
);
}
if
(
parity
)
{
portSettings
.
setParity
(
QPortSettings
::
PAR_EVEN
);
}
else
{
portSettings
.
setParity
(
QPortSettings
::
PAR_NONE
);
}
setDataBits
(
dataBits
);
setStopBits
(
stopBits
);
// Set the port name
if
(
porthandle
==
""
)
...
...
@@ -224,7 +239,8 @@ bool SerialLink::disconnect()
/* Block the thread until it returns from run() */
//#endif
// dataMutex.lock();
port
->
flush
();
port
->
flushInBuffer
();
port
->
flushOutBuffer
();
port
->
close
();
delete
port
;
port
=
NULL
;
...
...
@@ -237,7 +253,7 @@ bool SerialLink::disconnect()
emit
disconnected
();
emit
connected
(
false
);
return
!
closed
;
return
closed
;
}
else
{
// No port, so we're disconnected
return
true
;
...
...
@@ -252,12 +268,8 @@ bool SerialLink::disconnect()
**/
bool
SerialLink
::
connect
()
{
if
(
!
isConnected
())
{
qDebug
()
<<
"CONNECTING LINK: "
<<
__FILE__
<<
__LINE__
<<
"with settings"
<<
porthandle
<<
baudrate
<<
dataBits
<<
parity
<<
stopBits
;
if
(
!
this
->
isRunning
())
{
this
->
start
(
LowPriority
);
}
}
if
(
this
->
isRunning
())
this
->
disconnect
();
this
->
start
(
LowPriority
);
return
true
;
}
...
...
@@ -275,27 +287,22 @@ bool SerialLink::hardwareConnect()
port
->
close
();
delete
port
;
}
#ifdef USE_QEXTSERIAL
port
=
new
SerialQextserial
(
porthandle
,
QextSerialPort
::
Polling
);
#else
port
=
new
SerialQserial
(
porthandle
,
QIODevice
::
ReadWrite
);
#endif
QObject
::
connect
(
port
,
SIGNAL
(
aboutToClose
()),
this
,
SIGNAL
(
disconnected
()));
port
->
open
(
QIODevice
::
ReadWrite
);
port
->
setBaudRate
(
this
->
baudrate
);
port
->
setParity
(
this
->
parity
);
port
->
setStopBits
(
this
->
stopBits
);
port
->
setDataBits
(
this
->
dataBits
);
port
->
setTimeout
(
timeout
);
// Timeout of 0 ms, we don't want to wait for data, we just poll again next time
port
=
new
QSerialPort
(
porthandle
,
portSettings
);
QObject
::
connect
(
port
,
SIGNAL
(
aboutToClose
()),
this
,
SIGNAL
(
disconnected
()));
port
->
setCommTimeouts
(
QSerialPort
::
CtScheme_NonBlockingRead
);
connectionStartTime
=
MG
::
TIME
::
getGroundTimeNow
();
port
->
open
();
bool
connectionUp
=
isConnected
();
if
(
connectionUp
)
{
emit
connected
();
emit
connected
(
true
);
}
qDebug
()
<<
"CONNECTING LINK: "
<<
__FILE__
<<
__LINE__
<<
"with settings"
<<
port
->
portName
()
<<
getBaudRate
()
<<
getDataBits
()
<<
getParityType
()
<<
getStopBits
();
writeSettings
();
return
connectionUp
;
...
...
@@ -336,80 +343,93 @@ void SerialLink::setName(QString name)
qint64
SerialLink
::
getNominalDataRate
()
{
qint64
dataRate
=
0
;
switch
(
baudrate
)
{
case
SerialInterface
:
:
BAUD
50
:
switch
(
portSettings
.
baudRate
()
)
{
case
QPortSettings
:
:
BAUDR_
50
:
dataRate
=
50
;
break
;
case
SerialInterface
:
:
BAUD
75
:
case
QPortSettings
:
:
BAUDR_
75
:
dataRate
=
75
;
break
;
case
SerialInterface
:
:
BAUD
110
:
case
QPortSettings
:
:
BAUDR_
110
:
dataRate
=
110
;
break
;
case
SerialInterface
:
:
BAUD
134
:
case
QPortSettings
:
:
BAUDR_
134
:
dataRate
=
134
;
break
;
case
SerialInterface
:
:
BAUD
150
:
case
QPortSettings
:
:
BAUDR_
150
:
dataRate
=
150
;
break
;
case
SerialInterface
:
:
BAUD
200
:
case
QPortSettings
:
:
BAUDR_
200
:
dataRate
=
200
;
break
;
case
SerialInterface
:
:
BAUD
300
:
case
QPortSettings
:
:
BAUDR_
300
:
dataRate
=
300
;
break
;
case
SerialInterface
:
:
BAUD
600
:
case
QPortSettings
:
:
BAUDR_
600
:
dataRate
=
600
;
break
;
case
SerialInterface
:
:
BAUD
1200
:
case
QPortSettings
:
:
BAUDR_
1200
:
dataRate
=
1200
;
break
;
case
SerialInterface
:
:
BAUD
1800
:
case
QPortSettings
:
:
BAUDR_
1800
:
dataRate
=
1800
;
break
;
case
SerialInterface
:
:
BAUD
2400
:
case
QPortSettings
:
:
BAUDR_
2400
:
dataRate
=
2400
;
break
;
case
SerialInterface
:
:
BAUD
4800
:
case
QPortSettings
:
:
BAUDR_
4800
:
dataRate
=
4800
;
break
;
case
SerialInterface
:
:
BAUD
9600
:
case
QPortSettings
:
:
BAUDR_
9600
:
dataRate
=
9600
;
break
;
case
SerialInterface
:
:
BAUD14400
:
#ifdef Q_OS_WIN
case
QPortSettings
:
:
BAUDR_14400
:
dataRate
=
14400
;
break
;
case
SerialInterface
:
:
BAUD19200
:
#endif
case
QPortSettings
:
:
BAUDR_19200
:
dataRate
=
19200
;
break
;
case
SerialInterface
:
:
BAUD
38400
:
case
QPortSettings
:
:
BAUDR_
38400
:
dataRate
=
38400
;
break
;
case
SerialInterface
:
:
BAUD56000
:
#ifdef Q_OS_WIN
case
QPortSettings
:
:
BAUDR_56000
:
dataRate
=
56000
;
break
;
case
SerialInterface
:
:
BAUD57600
:
#endif
case
QPortSettings
:
:
BAUDR_57600
:
dataRate
=
57600
;
break
;
case
SerialInterface
:
:
BAUD76800
:
#ifdef Q_OS_WIN
case
QPortSettings
:
:
BAUDR_76800
:
dataRate
=
76800
;
break
;
case
SerialInterface
:
:
BAUD115200
:
#endif
case
QPortSettings
:
:
BAUDR_115200
:
dataRate
=
115200
;
break
;
case
SerialInterface
:
:
BAUD128000
:
#ifdef Q_OS_WIN
// Windows-specific high-end baudrates
case
QPortSettings
:
:
BAUDR_128000
:
dataRate
=
128000
;
break
;
case
SerialInterface
:
:
BAUD
256000
:
case
QPortSettings
:
:
BAUDR_
256000
:
dataRate
=
256000
;
// Windows-specific high-end baudrates
case
SerialInterface
:
:
BAUD230400
:
case
QPortSettings
:
:
BAUDR_230400
:
dataRate
=
230400
;
case
SerialInterface
:
:
BAUD
460800
:
case
QPortSettings
:
:
BAUDR_
460800
:
dataRate
=
460800
;
case
SerialInterface
:
:
BAUD921600
:
#endif
// All-OS high-speed
case
QPortSettings
:
:
BAUDR_921600
:
dataRate
=
921600
;
break
;
case
QPortSettings
:
:
BAUDR_UNKNOWN
:
default:
// Do nothing
break
;
}
return
dataRate
;
}
...
...
@@ -482,47 +502,47 @@ int SerialLink::getBaudRate()
int
SerialLink
::
getBaudRateType
()
{
return
baudrate
;
return
portSettings
.
baudRate
()
;
}
int
SerialLink
::
getFlowType
()
{
return
flow
;
return
portSettings
.
flowControl
()
;
}
int
SerialLink
::
getParityType
()
{
return
p
arity
;
return
p
ortSettings
.
parity
()
;
}
int
SerialLink
::
getDataBitsType
()
{
return
dataBits
;
return
portSettings
.
dataBits
()
;
}
int
SerialLink
::
getStopBitsType
()
{
return
stopBits
;
return
portSettings
.
stopBits
()
;
}
int
SerialLink
::
getDataBits
()
{
int
ret
;
switch
(
dataBits
)
{
case
SerialInterface
:
:
DATA
_5
:
int
ret
=
-
1
;
switch
(
portSettings
.
dataBits
()
)
{
case
QPortSettings
:
:
DB
_5
:
ret
=
5
;
break
;
case
SerialInterface
:
:
DATA
_6
:
case
QPortSettings
:
:
DB
_6
:
ret
=
6
;
break
;
case
SerialInterface
:
:
DATA
_7
:
case
QPortSettings
:
:
DB
_7
:
ret
=
7
;
break
;
case
SerialInterface
:
:
DATA
_8
:
case
QPortSettings
:
:
DB
_8
:
ret
=
8
;
break
;
default:
ret
=
0
;
ret
=
-
1
;
break
;
}
return
ret
;
...
...
@@ -530,18 +550,18 @@ int SerialLink::getDataBits()
int
SerialLink
::
getStopBits
()
{
int
ret
;
switch
(
stopBits
)
{
case
SerialInterface
:
:
STOP_1
:
ret
=
1
;
break
;
case
SerialInterface
:
:
STOP_2
:
ret
=
2
;
break
;
default:
ret
=
0
;
break
;
}
int
ret
=
-
1
;
switch
(
portSettings
.
stopBits
()
)
{
case
QPortSettings
:
:
STOP_1
:
ret
=
1
;
break
;
case
QPortSettings
:
:
STOP_2
:
ret
=
2
;
break
;
default:
ret
=
-
1
;
break
;
}
return
ret
;
}
...
...
@@ -578,96 +598,27 @@ bool SerialLink::setBaudRateType(int rateIndex)
if
(
isConnected
())
reconnect
=
true
;
disconnect
();
switch
(
rateIndex
)
{
case
0
:
baudrate
=
SerialInterface
::
BAUD50
;
break
;
case
1
:
baudrate
=
SerialInterface
::
BAUD75
;
break
;
case
2
:
baudrate
=
SerialInterface
::
BAUD110
;
break
;
case
3
:
baudrate
=
SerialInterface
::
BAUD134
;
break
;
case
4
:
baudrate
=
SerialInterface
::
BAUD150
;
break
;
case
5
:
baudrate
=
SerialInterface
::
BAUD200
;
break
;
case
6
:
baudrate
=
SerialInterface
::
BAUD300
;
break
;
case
7
:
baudrate
=
SerialInterface
::
BAUD600
;
break
;
case
8
:
baudrate
=
SerialInterface
::
BAUD1200
;
break
;
case
9
:
baudrate
=
SerialInterface
::
BAUD1800
;
break
;
case
10
:
baudrate
=
SerialInterface
::
BAUD2400
;
break
;
case
11
:
baudrate
=
SerialInterface
::
BAUD4800
;
break
;
case
12
:
baudrate
=
SerialInterface
::
BAUD9600
;
break
;
case
13
:
baudrate
=
SerialInterface
::
BAUD14400
;
break
;
case
14
:
baudrate
=
SerialInterface
::
BAUD19200
;
break
;
case
15
:
baudrate
=
SerialInterface
::
BAUD38400
;
break
;
case
16
:
baudrate
=
SerialInterface
::
BAUD56000
;
break
;
case
17
:
baudrate
=
SerialInterface
::
BAUD57600
;
break
;
case
18
:
baudrate
=
SerialInterface
::
BAUD76800
;
break
;
case
19
:
baudrate
=
SerialInterface
::
BAUD115200
;
break
;
case
20
:
baudrate
=
SerialInterface
::
BAUD128000
;
break
;
case
21
:
baudrate
=
SerialInterface
::
BAUD230400
;
break
;
case
22
:
baudrate
=
SerialInterface
::
BAUD256000
;
break
;
case
23
:
baudrate
=
SerialInterface
::
BAUD460800
;
break
;
case
24
:
baudrate
=
SerialInterface
::
BAUD921600
;
break
;
default:
// If none of the above cases matches, there must be an error
accepted
=
false
;
break
;
if
(
rateIndex
>=
(
int
)
QPortSettings
::
BAUDR_50
&&
rateIndex
<=
(
int
)
QPortSettings
::
BAUDR_921600
)
{
portSettings
.
setBaudRate
((
QPortSettings
::
BaudRate
)
rateIndex
);
}
if
(
reconnect
)
connect
();
return
accepted
;
}
bool
SerialLink
::
setBaudRateString
(
const
QString
&
rate
)
{
bool
ok
;
int
intrate
=
rate
.
toInt
(
&
ok
);
if
(
!
ok
)
return
false
;
return
setBaudRate
(
intrate
);
}
bool
SerialLink
::
setBaudRate
(
int
rate
)
{
qDebug
()
<<
"BAUD RATE:"
<<
rate
;
bool
reconnect
=
false
;
bool
accepted
=
true
;
// This is changed if none of the data rates matches
if
(
isConnected
())
{
...
...
@@ -677,79 +628,87 @@ bool SerialLink::setBaudRate(int rate)
switch
(
rate
)
{
case
50
:
baudrate
=
SerialInterface
::
BAUD50
;
portSettings
.
setBaudRate
(
QPortSettings
::
BAUDR_50
)
;
break
;
case
75
:
baudrate
=
SerialInterface
::
BAUD75
;
portSettings
.
setBaudRate
(
QPortSettings
::
BAUDR_75
)
;
break
;
case
110
:
baudrate
=
SerialInterface
::
BAUD110
;
portSettings
.
setBaudRate
(
QPortSettings
::
BAUDR_110
)
;
break
;
case
134
:
baudrate
=
SerialInterface
::
BAUD134
;
portSettings
.
setBaudRate
(
QPortSettings
::
BAUDR_134
)
;
break
;
case
150
:
baudrate
=
SerialInterface
::
BAUD150
;
portSettings
.
setBaudRate
(
QPortSettings
::
BAUDR_150
)
;
break
;
case
200
:
baudrate
=
SerialInterface
::
BAUD200
;
portSettings
.
setBaudRate
(
QPortSettings
::
BAUDR_200
)
;
break
;
case
300
:
baudrate
=
SerialInterface
::
BAUD300
;
portSettings
.
setBaudRate
(
QPortSettings
::
BAUDR_300
)
;
break
;
case
600
:
baudrate
=
SerialInterface
::
BAUD600
;
portSettings
.
setBaudRate
(
QPortSettings
::
BAUDR_600
)
;
break
;
case
1200
:
baudrate
=
SerialInterface
::
BAUD1200
;
portSettings
.
setBaudRate
(
QPortSettings
::
BAUDR_1200
)
;
break
;
case
1800
:
baudrate
=
SerialInterface
::
BAUD1800
;
portSettings
.
setBaudRate
(
QPortSettings
::
BAUDR_1800
)
;
break
;
case
2400
:
baudrate
=
SerialInterface
::
BAUD2400
;
portSettings
.
setBaudRate
(
QPortSettings
::
BAUDR_2400
)
;
break
;
case
4800
:
baudrate
=
SerialInterface
::
BAUD4800
;
portSettings
.
setBaudRate
(
QPortSettings
::
BAUDR_4800
)
;
break
;
case
9600
:
baudrate
=
SerialInterface
::
BAUD9600
;
portSettings
.
setBaudRate
(
QPortSettings
::
BAUDR_9600
)
;
break
;
#ifdef Q_OS_WIN
case
14400
:
baudrate
=
SerialInterface
::
BAUD14400
;
portSettings
.
setBaudRate
(
QPortSettings
::
BAUDR_14400
)
;
break
;
#endif
case
19200
:
baudrate
=
SerialInterface
::
BAUD19200
;
portSettings
.
setBaudRate
(
QPortSettings
::
BAUDR_19200
)
;
break
;
case
38400
:
baudrate
=
SerialInterface
::
BAUD38400
;
portSettings
.
setBaudRate
(
QPortSettings
::
BAUDR_38400
)
;
break
;
#ifdef Q_OS_WIN
case
56000
:
baudrate
=
SerialInterface
::
BAUD56000
;
portSettings
.
setBaudRate
(
QPortSettings
::
BAUDR_56000
)
;
break
;
#endif
case
57600
:
baudrate
=
SerialInterface
::
BAUD57600
;
portSettings
.
setBaudRate
(
QPortSettings
::
BAUDR_57600
)
;
break
;
#ifdef Q_OS_WIN
case
76800
:
baudrate
=
SerialInterface
::
BAUD76800
;
portSettings
.
setBaudRate
(
QPortSettings
::
BAUDR_76800
)
;
break
;
#endif
case
115200
:
baudrate
=
SerialInterface
::
BAUD115200
;
portSettings
.
setBaudRate
(
QPortSettings
::
BAUDR_115200
)
;
break
;
#ifdef Q_OS_WIN
case
128000
:
baudrate
=
SerialInterface
::
BAUD128000
;
portSettings
.
setBaudRate
(
QPortSettings
::
BAUDR_128000
)
;
break
;
case
230400
:
baudrate
=
SerialInterface
::
BAUD230400
;
portSettings
.
setBaudRate
(
QPortSettings
::
BAUDR_230400
)
;
break
;
case
256000
:
baudrate
=
SerialInterface
::
BAUD256000
;
portSettings
.
setBaudRate
(
QPortSettings
::
BAUDR_256000
)
;
break
;
case
460800
:
baudrate
=
SerialInterface
::
BAUD460800
;
portSettings
.
setBaudRate
(
QPortSettings
::
BAUDR_460800
)
;
break
;
#endif
case
921600
:
baudrate
=
SerialInterface
::
BAUD921600
;
portSettings
.
setBaudRate
(
QPortSettings
::
BAUDR_921600
)
;
break
;
default:
// If none of the above cases matches, there must be an error
...
...
@@ -770,14 +729,14 @@ bool SerialLink::setFlowType(int flow)
disconnect
();
switch
(
flow
)
{
case
SerialInterface
:
:
FLOW_OFF
:
this
->
flow
=
SerialInterface
::
FLOW_OFF
;
case
(
int
)
QPortSettings
:
:
FLOW_OFF
:
portSettings
.
setFlowControl
(
QPortSettings
::
FLOW_OFF
)
;
break
;
case
SerialInterface
:
:
FLOW_HARDWARE
:
this
->
flow
=
SerialInterface
::
FLOW_HARDWARE
;
case
(
int
)
QPortSettings
:
:
FLOW_HARDWARE
:
portSettings
.
setFlowControl
(
QPortSettings
::
FLOW_HARDWARE
)
;
break
;
case
SerialInterface
:
:
FLOW_XONXOFF
:
this
->
flow
=
SerialInterface
::
FLOW_XONXOFF
;
case
(
int
)
QPortSettings
:
:
FLOW_XONXOFF
:
portSettings
.
setFlowControl
(
QPortSettings
::
FLOW_XONXOFF
)
;
break
;
default:
// If none of the above cases matches, there must be an error
...
...
@@ -797,20 +756,17 @@ bool SerialLink::setParityType(int parity)
disconnect
();
switch
(
parity
)
{
case
(
int
)
PAR_NONE
:
this
->
parity
=
SerialInterface
::
PAR_NONE
;
case
(
int
)
QPortSettings
:
:
PAR_NONE
:
portSettings
.
setParity
(
QPortSettings
::
PAR_NONE
)
;
break
;
case
(
int
)
PAR_ODD
:
this
->
parity
=
SerialInterface
::
PAR_ODD
;
case
(
int
)
QPortSettings
:
:
PAR_ODD
:
portSettings
.
setParity
(
QPortSettings
::
PAR_ODD
)
;
break
;
case
(
int
)
PAR_EVEN
:
this
->
parity
=
SerialInterface
::
PAR_EVEN
;
case
(
int
)
QPortSettings
:
:
PAR_EVEN
:
portSettings
.
setParity
(
QPortSettings
::
PAR_EVEN
)
;
break
;
case
(
int
)
PAR_MARK
:
this
->
parity
=
SerialInterface
::
PAR_MARK
;
break
;
case
(
int
)
PAR_SPACE
:
this
->
parity
=
SerialInterface
::
PAR_SPACE
;
case
(
int
)
QPortSettings
:
:
PAR_SPACE
:
portSettings
.
setParity
(
QPortSettings
::
PAR_SPACE
);
break
;
default:
// If none of the above cases matches, there must be an error
...
...
@@ -825,6 +781,7 @@ bool SerialLink::setParityType(int parity)
bool
SerialLink
::
setDataBits
(
int
dataBits
)
{
qDebug
()
<<
"Setting"
<<
dataBits
<<
"data bits"
;
bool
reconnect
=
false
;
if
(
isConnected
())
reconnect
=
true
;
bool
accepted
=
true
;
...
...
@@ -832,16 +789,16 @@ bool SerialLink::setDataBits(int dataBits)
switch
(
dataBits
)
{
case
5
:
this
->
dataBits
=
SerialInterface
::
DATA_5
;
portSettings
.
setDataBits
(
QPortSettings
::
DB_5
)
;
break
;
case
6
:
this
->
dataBits
=
SerialInterface
::
DATA_6
;
portSettings
.
setDataBits
(
QPortSettings
::
DB_6
)
;
break
;
case
7
:
this
->
dataBits
=
SerialInterface
::
DATA_7
;
portSettings
.
setDataBits
(
QPortSettings
::
DB_7
)
;
break
;
case
8
:
this
->
dataBits
=
SerialInterface
::
DATA_8
;
portSettings
.
setDataBits
(
QPortSettings
::
DB_8
)
;
break
;
default:
// If none of the above cases matches, there must be an error
...
...
@@ -863,10 +820,10 @@ bool SerialLink::setStopBits(int stopBits)
switch
(
stopBits
)
{
case
1
:
this
->
stopBits
=
SerialInterface
::
STOP_1
;
portSettings
.
setStopBits
(
QPortSettings
::
STOP_1
)
;
break
;
case
2
:
this
->
stopBits
=
SerialInterface
::
STOP_2
;
portSettings
.
setStopBits
(
QPortSettings
::
STOP_2
)
;
break
;
default:
// If none of the above cases matches, there must be an error
...
...
@@ -886,8 +843,8 @@ bool SerialLink::setDataBitsType(int dataBits)
if
(
isConnected
())
reconnect
=
true
;
disconnect
();
if
(
dataBits
>=
(
int
)
SerialInterface
::
DATA_5
&&
dataBits
<=
(
int
)
SerialInterface
::
DATA
_8
)
{
this
->
dataBits
=
(
SerialInterface
::
dataBitsType
)
dataBits
;
if
(
dataBits
>=
(
int
)
QPortSettings
::
DB_5
&&
dataBits
<=
(
int
)
QPortSettings
::
DB
_8
)
{
portSettings
.
setDataBits
((
QPortSettings
::
DataBits
)
dataBits
)
;
if
(
reconnect
)
connect
();
accepted
=
true
;
...
...
@@ -903,10 +860,10 @@ bool SerialLink::setStopBitsType(int stopBits)
if
(
isConnected
())
reconnect
=
true
;
disconnect
();
if
(
stopBits
>=
(
int
)
SerialInterface
::
STOP_1
&&
dataBits
<=
(
int
)
SerialInterface
::
STOP_2
)
{
SerialInterface
::
stopBitsType
newBits
=
(
SerialInterface
::
stopBitsType
)
stopBits
;
if
(
stopBits
>=
(
int
)
QPortSettings
::
STOP_1
&&
stopBits
<=
(
int
)
QPortSettings
::
STOP_2
)
{
portSettings
.
setStopBits
((
QPortSettings
::
StopBits
)
stopBits
)
;
port
->
setStopBits
(
newBits
);
if
(
reconnect
)
connect
(
);
accepted
=
true
;
}
...
...
src/comm/SerialLink.h
View file @
0e73f417
...
...
@@ -36,7 +36,7 @@ This file is part of the QGROUNDCONTROL project
#include <QThread>
#include <QMutex>
#include <QString>
#include "
SerialInterface
.h"
#include "
qserialport
.h"
#include <configuration.h>
#include "SerialLinkInterface.h"
#ifdef _WIN32
...
...
@@ -59,11 +59,11 @@ class SerialLink : public SerialLinkInterface
public:
SerialLink
(
QString
portname
=
""
,
SerialInterface
::
baudRateType
baudrate
=
SerialInterface
::
BAUD
57600
,
SerialInterface
::
flowType
flow
=
SerialInterface
::
FLOW_OFF
,
SerialInterface
::
parityType
parity
=
SerialInterface
::
PAR_NONE
,
SerialInterface
::
dataBitsType
dataBits
=
SerialInterface
::
DATA_
8
,
SerialInterface
::
stopBitsType
stopBits
=
SerialInterface
::
STOP_
1
);
int
baudrate
=
57600
,
bool
flow
=
false
,
bool
parity
=
false
,
int
dataBits
=
8
,
int
stopBits
=
1
);
~
SerialLink
();
static
const
int
poll_interval
=
SERIAL_POLL_INTERVAL
;
///< Polling interval, defined in configuration.h
...
...
@@ -116,6 +116,9 @@ public slots:
bool
setDataBits
(
int
dataBits
);
bool
setStopBits
(
int
stopBits
);
// Set string rate
bool
setBaudRateString
(
const
QString
&
rate
);
// Set ENUM values
bool
setBaudRateType
(
int
rateIndex
);
bool
setFlowType
(
int
flow
);
...
...
@@ -138,18 +141,14 @@ protected slots:
void
checkForBytes
();
protected:
SerialInterface
*
port
;
TNX
::
QSerialPort
*
port
;
TNX
::
QPortSettings
portSettings
;
#ifdef _WIN32
HANDLE
winPort
;
DCB
winPortSettings
;
#endif
QString
porthandle
;
QString
name
;
SerialInterface
::
baudRateType
baudrate
;
SerialInterface
::
flowType
flow
;
SerialInterface
::
parityType
parity
;
SerialInterface
::
dataBitsType
dataBits
;
SerialInterface
::
stopBitsType
stopBits
;
int
timeout
;
int
id
;
...
...
src/ui/SerialConfigurationWindow.cc
View file @
0e73f417
...
...
@@ -243,6 +243,44 @@ SerialConfigurationWindow::SerialConfigurationWindow(LinkInterface* link, QWidge
setupPortList
();
// Set up baud rates
ui
.
baudRate
->
addItem
(
"115200"
,
115200
);
ui
.
baudRate
->
clear
();
ui
.
baudRate
->
addItem
(
"50"
,
50
);
ui
.
baudRate
->
addItem
(
"70"
,
70
);
ui
.
baudRate
->
addItem
(
"110"
,
110
);
ui
.
baudRate
->
addItem
(
"134"
,
134
);
ui
.
baudRate
->
addItem
(
"150"
,
150
);
ui
.
baudRate
->
addItem
(
"200"
,
200
);
ui
.
baudRate
->
addItem
(
"300"
,
300
);
ui
.
baudRate
->
addItem
(
"600"
,
600
);
ui
.
baudRate
->
addItem
(
"1200"
,
1200
);
ui
.
baudRate
->
addItem
(
"1800"
,
1800
);
ui
.
baudRate
->
addItem
(
"2400"
,
2400
);
ui
.
baudRate
->
addItem
(
"4800"
,
4800
);
ui
.
baudRate
->
addItem
(
"9600"
,
9600
);
#ifdef Q_OS_WIN
ui
.
baudRate
->
addItem
(
"14400"
,
14400
);
#endif
ui
.
baudRate
->
addItem
(
"19200"
,
19200
);
ui
.
baudRate
->
addItem
(
"34800"
,
34800
);
#ifdef Q_OS_WIN
ui
.
baudRate
->
addItem
(
"56000"
,
56000
);
#endif
ui
.
baudRate
->
addItem
(
"57600"
,
57600
);
#ifdef Q_OS_WIN
ui
.
baudRate
->
addItem
(
"76800"
,
76800
);
#endif
ui
.
baudRate
->
addItem
(
"115200"
,
115200
);
#ifdef Q_OS_WIN
ui
.
baudRate
->
addItem
(
"128000"
,
128000
);
ui
.
baudRate
->
addItem
(
"230400"
,
230400
);
ui
.
baudRate
->
addItem
(
"256000"
,
256000
);
ui
.
baudRate
->
addItem
(
"460800"
,
460800
);
#endif
ui
.
baudRate
->
addItem
(
"921600"
,
921600
);
connect
(
action
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
configureCommunication
()));
// Make sure that a change in the link name will be reflected in the UI
...
...
@@ -251,7 +289,7 @@ SerialConfigurationWindow::SerialConfigurationWindow(LinkInterface* link, QWidge
// Connect the individual user interface inputs
connect
(
ui
.
portName
,
SIGNAL
(
editTextChanged
(
QString
)),
this
,
SLOT
(
setPortName
(
QString
)));
connect
(
ui
.
portName
,
SIGNAL
(
currentIndexChanged
(
QString
)),
this
,
SLOT
(
setPortName
(
QString
)));
connect
(
ui
.
baudRate
,
SIGNAL
(
activated
(
int
)),
this
->
link
,
SLOT
(
setBaudRateType
(
int
)));
connect
(
ui
.
baudRate
,
SIGNAL
(
activated
(
QString
)),
this
->
link
,
SLOT
(
setBaudRateString
(
QString
)));
connect
(
ui
.
flowControlCheckBox
,
SIGNAL
(
toggled
(
bool
)),
this
,
SLOT
(
enableFlowControl
(
bool
)));
connect
(
ui
.
parNone
,
SIGNAL
(
toggled
(
bool
)),
this
,
SLOT
(
setParityNone
(
bool
)));
connect
(
ui
.
parOdd
,
SIGNAL
(
toggled
(
bool
)),
this
,
SLOT
(
setParityOdd
(
bool
)));
...
...
@@ -292,7 +330,7 @@ SerialConfigurationWindow::SerialConfigurationWindow(LinkInterface* link, QWidge
enableFlowControl
(
false
);
}
ui
.
baudRate
->
setCurrentIndex
(
this
->
link
->
getBaudRateType
(
));
ui
.
baudRate
->
setCurrentIndex
(
ui
.
baudRate
->
findText
(
QString
(
"%1"
).
arg
(
this
->
link
->
getBaudRate
())
));
ui
.
dataBitsSpinBox
->
setValue
(
this
->
link
->
getDataBits
());
ui
.
stopBitsSpinBox
->
setValue
(
this
->
link
->
getStopBits
());
...
...
@@ -466,7 +504,7 @@ void SerialConfigurationWindow::setParityEven(bool accept)
void
SerialConfigurationWindow
::
setPortName
(
QString
port
)
{
#ifdef
_WIN32
#ifdef
Q_OS_WIN
port
=
port
.
split
(
"-"
).
first
();
#endif
port
=
port
.
remove
(
" "
);
...
...
src/ui/linechart/LinechartWidget.cc
View file @
0e73f417
...
...
@@ -310,7 +310,7 @@ void LinechartWidget::appendData(int uasId, QString curve, double value, quint64
qint64
time
=
usec
-
logStartTime
;
if
(
time
<
0
)
time
=
0
;
logFile
->
write
(
QString
(
QString
::
number
(
time
)
+
"
\t
"
+
QString
::
number
(
uasId
)
+
"
\t
"
+
curve
+
"
\t
"
+
QString
::
number
(
value
)
+
"
\n
"
).
toLatin1
());
logFile
->
write
(
QString
(
QString
::
number
(
time
)
+
"
\t
"
+
QString
::
number
(
uasId
)
+
"
\t
"
+
curve
+
"
\t
"
+
QString
::
number
(
value
,
'g'
,
10
)
+
"
\n
"
).
toLatin1
());
logFile
->
flush
();
}
}
...
...
@@ -338,7 +338,7 @@ void LinechartWidget::appendData(int uasId, const QString& curve, const QString&
qint64
time
=
usec
-
logStartTime
;
if
(
time
<
0
)
time
=
0
;
logFile
->
write
(
QString
(
QString
::
number
(
time
)
+
"
\t
"
+
QString
::
number
(
uasId
)
+
"
\t
"
+
curve
+
"
\t
"
+
QString
::
number
(
value
)
+
"
\n
"
).
toLatin1
());
logFile
->
write
(
QString
(
QString
::
number
(
time
)
+
"
\t
"
+
QString
::
number
(
uasId
)
+
"
\t
"
+
curve
+
"
\t
"
+
QString
::
number
(
value
,
'g'
,
10
)
+
"
\n
"
).
toLatin1
());
logFile
->
flush
();
}
}
...
...
thirdParty/qserialport/include/QtSerialPort/qportsettings.h
View file @
0e73f417
...
...
@@ -99,13 +99,14 @@ public:
BAUDR_460800
,
BAUDR_500000
,
BAUDR_576000
,
BAUDR_921600
,
#endif
#ifdef TNX_WINDOWS_SERIAL_PORT
BAUDR_14400
,
BAUDR_56000
,
BAUDR_128000
,
BAUDR_230400
,
BAUDR_256000
,
BAUDR_460800
,
#endif
// baud rates supported by all OSs
BAUDR_110
,
...
...
@@ -118,7 +119,8 @@ public:
BAUDR_19200
,
BAUDR_38400
,
BAUDR_57600
,
BAUDR_115200
BAUDR_115200
,
BAUDR_921600
};
enum
DataBits
{
...
...
@@ -184,13 +186,14 @@ public:
case
BAUDR_56000
:
baudRateInt_
=
56000
;
break
;
case
BAUDR_128000
:
baudRateInt_
=
128000
;
break
;
case
BAUDR_256000
:
baudRateInt_
=
256000
;
break
;
case
BAUDR_230400
:
baudRateInt_
=
230400
;
break
;
case
BAUDR_460800
:
baudRateInt_
=
460800
;
break
;
#endif
#if defined(Q_OS_LINUX)
case
BAUDR_230400
:
baudRateInt_
=
230400
;
break
;
case
BAUDR_460800
:
baudRateInt_
=
460800
;
break
;
case
BAUDR_500000
:
baudRateInt_
=
500000
;
break
;
case
BAUDR_576000
:
baudRateInt_
=
576000
;
break
;
case
BAUDR_921600
:
baudRateInt_
=
921600
;
break
;
#endif
// baud rates supported by all platforms
case
BAUDR_110
:
baudRateInt_
=
110
;
break
;
...
...
@@ -204,6 +207,7 @@ public:
case
BAUDR_38400
:
baudRateInt_
=
38400
;
break
;
case
BAUDR_57600
:
baudRateInt_
=
57600
;
break
;
case
BAUDR_115200
:
baudRateInt_
=
115200
;
break
;
case
BAUDR_921600
:
baudRateInt_
=
921600
;
break
;
default:
baudRateInt_
=
0
;
// unknown baudrate
}
...
...
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