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
15631ad0
Commit
15631ad0
authored
Sep 14, 2017
by
DonLakeFlyer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better reading of numbers like -10.5m
parent
9c5cbf38
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
124 additions
and
38 deletions
+124
-38
qgroundcontrol.pro
qgroundcontrol.pro
+3
-1
QGCAudioWorker.cpp
src/audio/QGCAudioWorker.cpp
+64
-37
QGCAudioWorkerTest.cc
src/audio/QGCAudioWorkerTest.cc
+32
-0
QGCAudioWorkerTest.h
src/audio/QGCAudioWorkerTest.h
+23
-0
UnitTestList.cc
src/qgcunittest/UnitTestList.cc
+2
-0
No files found.
qgroundcontrol.pro
View file @
15631ad0
...
...
@@ -42,7 +42,7 @@ MacBuild {
}
}
iOSBuild
{
iOSBuild
{
worker
BUNDLE
.
files
=
$$
files
(
$$
PWD
/
ios
/
AppIcon
*.
png
)
$$
PWD
/
ios
/
QGCLaunchScreen
.
xib
QMAKE_BUNDLE_DATA
+=
BUNDLE
LIBS
+=
-
framework
AVFoundation
...
...
@@ -409,6 +409,7 @@ DebugBuild { PX4FirmwarePlugin { PX4FirmwarePluginFactory { APMFirmwarePlugin {
HEADERS
+=
\
src
/
AnalyzeView
/
LogDownloadTest
.
h
\
src
/
audio
/
QGCAudioWorkerTest
.
h
\
src
/
FactSystem
/
FactSystemTestBase
.
h
\
src
/
FactSystem
/
FactSystemTestGeneric
.
h
\
src
/
FactSystem
/
FactSystemTestPX4
.
h
\
...
...
@@ -444,6 +445,7 @@ DebugBuild { PX4FirmwarePlugin { PX4FirmwarePluginFactory { APMFirmwarePlugin {
SOURCES
+=
\
src
/
AnalyzeView
/
LogDownloadTest
.
cc
\
src
/
audio
/
QGCAudioWorkerTest
.
cc
\
src
/
FactSystem
/
FactSystemTestBase
.
cc
\
src
/
FactSystem
/
FactSystemTestGeneric
.
cc
\
src
/
FactSystem
/
FactSystemTestPX4
.
cc
\
...
...
src/audio/QGCAudioWorker.cpp
View file @
15631ad0
...
...
@@ -165,10 +165,10 @@ bool QGCAudioWorker::_getMillisecondString(const QString& string, QString& match
static
QRegularExpression
re
(
"([0-9]+ms)"
);
QRegularExpressionMatchIterator
i
=
re
.
globalMatch
(
string
);
while
(
i
.
hasNext
())
{
QRegularExpressionMatch
qm
atch
=
i
.
next
();
if
(
qm
atch
.
hasMatch
())
{
match
=
qm
atch
.
captured
(
0
);
number
=
qm
atch
.
captured
(
0
).
replace
(
"ms"
,
""
).
toInt
();
QRegularExpressionMatch
reM
atch
=
i
.
next
();
if
(
reM
atch
.
hasMatch
())
{
match
=
reM
atch
.
captured
(
0
);
number
=
reM
atch
.
captured
(
0
).
replace
(
"ms"
,
""
).
toInt
();
return
true
;
}
}
...
...
@@ -179,64 +179,91 @@ QString QGCAudioWorker::fixTextMessageForAudio(const QString& string) {
QString
match
;
QString
newNumber
;
QString
result
=
string
;
//-- Look for codified terms
if
(
result
.
contains
(
"ERR "
,
Qt
::
CaseInsensitive
))
{
result
.
replace
(
"ERR "
,
"error "
,
Qt
::
CaseInsensitive
);
if
(
result
.
contains
(
QStringLiteral
(
"ERR "
),
Qt
::
CaseInsensitive
))
{
result
.
replace
(
QStringLiteral
(
"ERR "
),
tr
(
"error "
),
Qt
::
CaseInsensitive
);
}
if
(
result
.
contains
(
QStringLiteral
(
"ERR:"
),
Qt
::
CaseInsensitive
))
{
result
.
replace
(
QStringLiteral
(
"ERR:"
),
tr
(
"error."
),
Qt
::
CaseInsensitive
);
}
if
(
result
.
contains
(
"ERR:"
,
Qt
::
CaseInsensitive
))
{
result
.
replace
(
"ERR:"
,
"error."
,
Qt
::
CaseInsensitive
);
if
(
result
.
contains
(
QStringLiteral
(
"POSCTL"
)
,
Qt
::
CaseInsensitive
))
{
result
.
replace
(
QStringLiteral
(
"POSCTL"
),
tr
(
"Position Control"
)
,
Qt
::
CaseInsensitive
);
}
if
(
result
.
contains
(
"POSCTL"
,
Qt
::
CaseInsensitive
))
{
result
.
replace
(
"POSCTL"
,
"Position Control"
,
Qt
::
CaseInsensitive
);
if
(
result
.
contains
(
QStringLiteral
(
"ALTCTL"
)
,
Qt
::
CaseInsensitive
))
{
result
.
replace
(
QStringLiteral
(
"ALTCTL"
),
tr
(
"Altitude Control"
)
,
Qt
::
CaseInsensitive
);
}
if
(
result
.
contains
(
"ALTCTL"
,
Qt
::
CaseInsensitive
))
{
result
.
replace
(
"ALTCTL"
,
"Altitude Control"
,
Qt
::
CaseInsensitive
);
if
(
result
.
contains
(
QStringLiteral
(
"AUTO_RTL"
),
Qt
::
CaseInsensitive
))
{
result
.
replace
(
QStringLiteral
(
"AUTO_RTL"
),
tr
(
"auto Return To Launch"
),
Qt
::
CaseInsensitive
);
}
else
if
(
result
.
contains
(
QStringLiteral
(
"RTL"
),
Qt
::
CaseInsensitive
))
{
result
.
replace
(
QStringLiteral
(
"RTL"
),
tr
(
"Return To Launch"
),
Qt
::
CaseInsensitive
);
}
if
(
result
.
contains
(
"AUTO_RTL"
,
Qt
::
CaseInsensitive
))
{
result
.
replace
(
"AUTO_RTL"
,
"auto Return To Launch"
,
Qt
::
CaseInsensitive
);
}
else
if
(
result
.
contains
(
"RTL"
,
Qt
::
CaseInsensitive
))
{
result
.
replace
(
"RTL"
,
"Return To Launch"
,
Qt
::
CaseInsensitive
);
if
(
result
.
contains
(
QStringLiteral
(
"ACCEL "
),
Qt
::
CaseInsensitive
))
{
result
.
replace
(
QStringLiteral
(
"ACCEL "
),
tr
(
"accelerometer "
),
Qt
::
CaseInsensitive
);
}
if
(
result
.
contains
(
"ACCEL "
,
Qt
::
CaseInsensitive
))
{
result
.
replace
(
"ACCEL "
,
"accelerometer "
,
Qt
::
CaseInsensitive
);
if
(
result
.
contains
(
QStringLiteral
(
"RC_MAP_MODE_SW"
)
,
Qt
::
CaseInsensitive
))
{
result
.
replace
(
QStringLiteral
(
"RC_MAP_MODE_SW"
),
tr
(
"RC mode switch"
)
,
Qt
::
CaseInsensitive
);
}
if
(
result
.
contains
(
"RC_MAP_MODE_SW"
,
Qt
::
CaseInsensitive
))
{
result
.
replace
(
"RC_MAP_MODE_SW"
,
"RC mode switch"
,
Qt
::
CaseInsensitive
);
if
(
result
.
contains
(
QStringLiteral
(
"REJ."
)
,
Qt
::
CaseInsensitive
))
{
result
.
replace
(
QStringLiteral
(
"REJ."
),
tr
(
"Rejected"
)
,
Qt
::
CaseInsensitive
);
}
if
(
result
.
contains
(
"REJ."
,
Qt
::
CaseInsensitive
))
{
result
.
replace
(
"REJ."
,
"Rejected"
,
Qt
::
CaseInsensitive
);
if
(
result
.
contains
(
QStringLiteral
(
"WP"
)
,
Qt
::
CaseInsensitive
))
{
result
.
replace
(
QStringLiteral
(
"WP"
),
tr
(
"way point"
)
,
Qt
::
CaseInsensitive
);
}
if
(
result
.
contains
(
"WP"
,
Qt
::
CaseInsensitive
))
{
result
.
replace
(
"WP"
,
"way point"
,
Qt
::
CaseInsensitive
);
if
(
result
.
contains
(
QStringLiteral
(
"CMD"
)
,
Qt
::
CaseInsensitive
))
{
result
.
replace
(
QStringLiteral
(
"CMD"
),
tr
(
"command"
)
,
Qt
::
CaseInsensitive
);
}
if
(
result
.
contains
(
"CMD"
,
Qt
::
CaseInsensitive
))
{
result
.
replace
(
"CMD"
,
"command"
,
Qt
::
CaseInsensitive
);
if
(
result
.
contains
(
QStringLiteral
(
"COMPID"
)
,
Qt
::
CaseInsensitive
))
{
result
.
replace
(
QStringLiteral
(
"COMPID"
),
tr
(
"component eye dee"
)
,
Qt
::
CaseInsensitive
);
}
if
(
result
.
contains
(
"COMPID"
,
Qt
::
CaseInsensitive
))
{
result
.
replace
(
"COMPID"
,
"component eye dee"
,
Qt
::
CaseInsensitive
);
if
(
result
.
contains
(
QStringLiteral
(
" params "
)
,
Qt
::
CaseInsensitive
))
{
result
.
replace
(
QStringLiteral
(
" params "
),
tr
(
" parameters "
)
,
Qt
::
CaseInsensitive
);
}
if
(
result
.
contains
(
" params "
,
Qt
::
CaseInsensitive
))
{
result
.
replace
(
" params "
,
" parameters "
,
Qt
::
CaseInsensitive
);
if
(
result
.
contains
(
QStringLiteral
(
" id "
)
,
Qt
::
CaseInsensitive
))
{
result
.
replace
(
QStringLiteral
(
" id "
),
QStringLiteral
(
" eye dee "
)
,
Qt
::
CaseInsensitive
);
}
if
(
result
.
contains
(
" id "
,
Qt
::
CaseInsensitive
))
{
result
.
replace
(
" id "
,
" eye dee "
,
Qt
::
CaseInsensitive
);
if
(
result
.
contains
(
QStringLiteral
(
" ADSB "
)
,
Qt
::
CaseInsensitive
))
{
result
.
replace
(
QStringLiteral
(
" ADSB "
),
QStringLiteral
(
" Hey Dee Ess Bee "
)
,
Qt
::
CaseInsensitive
);
}
if
(
result
.
contains
(
" ADSB "
,
Qt
::
CaseInsensitive
))
{
result
.
replace
(
" ADSB "
,
" Hey Dee Ess Bee "
,
Qt
::
CaseInsensitive
);
// Convert negative numbers
QRegularExpression
re
(
QStringLiteral
(
"(-)[0-9]*
\\
.?[0-9]"
));
QRegularExpressionMatch
reMatch
=
re
.
match
(
result
);
while
(
reMatch
.
hasMatch
())
{
if
(
!
reMatch
.
captured
(
1
).
isNull
())
{
// There is a negative prefix
qDebug
()
<<
"negative"
<<
reMatch
.
captured
(
1
)
<<
reMatch
.
capturedStart
(
1
)
<<
reMatch
.
capturedEnd
(
1
);
result
.
replace
(
reMatch
.
capturedStart
(
1
),
reMatch
.
capturedEnd
(
1
)
-
reMatch
.
capturedStart
(
1
),
tr
(
" negative "
));
qDebug
()
<<
result
;
}
reMatch
=
re
.
match
(
result
);
}
// Convert meter postfix after real number
re
.
setPattern
(
QStringLiteral
(
"[0-9]*
\\
.?[0-9]
\\
s?(m)([^A-Za-z]|$)"
));
reMatch
=
re
.
match
(
result
);
while
(
reMatch
.
hasMatch
())
{
if
(
!
reMatch
.
captured
(
1
).
isNull
())
{
// There is a meter postfix
qDebug
()
<<
"meters"
<<
reMatch
.
captured
(
1
)
<<
reMatch
.
capturedStart
(
1
)
<<
reMatch
.
capturedEnd
(
1
);
result
.
replace
(
reMatch
.
capturedStart
(
1
),
reMatch
.
capturedEnd
(
1
)
-
reMatch
.
capturedStart
(
1
),
tr
(
" meters"
));
qDebug
()
<<
result
;
}
reMatch
=
re
.
match
(
result
);
}
int
number
;
if
(
_getMillisecondString
(
string
,
match
,
number
)
&&
number
>
1000
)
{
if
(
number
<
60000
)
{
int
seconds
=
number
/
1000
;
newNumber
=
QString
(
"%1 second%2"
).
arg
(
seconds
).
arg
(
seconds
>
1
?
"s"
:
""
);
newNumber
=
tr
(
"%1 second%2"
).
arg
(
seconds
).
arg
(
seconds
>
1
?
"s"
:
""
);
}
else
{
int
minutes
=
number
/
60000
;
int
seconds
=
(
number
-
(
minutes
*
60000
))
/
1000
;
if
(
!
seconds
)
{
newNumber
=
QString
(
"%1 minute%2"
).
arg
(
minutes
).
arg
(
minutes
>
1
?
"s"
:
""
);
newNumber
=
tr
(
"%1 minute%2"
).
arg
(
minutes
).
arg
(
minutes
>
1
?
"s"
:
""
);
}
else
{
newNumber
=
QString
(
"%1 minute%2 and %3 second%4"
).
arg
(
minutes
).
arg
(
minutes
>
1
?
"s"
:
""
).
arg
(
seconds
).
arg
(
seconds
>
1
?
"s"
:
""
);
newNumber
=
tr
(
"%1 minute%2 and %3 second%4"
).
arg
(
minutes
).
arg
(
minutes
>
1
?
"s"
:
""
).
arg
(
seconds
).
arg
(
seconds
>
1
?
"s"
:
""
);
}
}
result
.
replace
(
match
,
newNumber
);
...
...
src/audio/QGCAudioWorkerTest.cc
0 → 100644
View file @
15631ad0
/****************************************************************************
*
* (c) 2009-2016 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 "QGCAudioWorkerTest.h"
#include "QGCAudioWorker.h"
QGCAudioWorkerTest
::
QGCAudioWorkerTest
(
void
)
{
}
void
QGCAudioWorkerTest
::
_testSpokenReplacements
(
void
)
{
QString
result
=
QGCAudioWorker
::
fixTextMessageForAudio
(
QStringLiteral
(
"-10.5m, -10.5m. -10.5 m"
));
QCOMPARE
(
result
,
QStringLiteral
(
" negative 10.5 meters, negative 10.5 meters. negative 10.5 meters"
));
result
=
QGCAudioWorker
::
fixTextMessageForAudio
(
QStringLiteral
(
"-10m -10 m"
));
QCOMPARE
(
result
,
QStringLiteral
(
" negative 10 meters negative 10 meters"
));
result
=
QGCAudioWorker
::
fixTextMessageForAudio
(
QStringLiteral
(
"foo -10m -10 m bar"
));
QCOMPARE
(
result
,
QStringLiteral
(
"foo negative 10 meters negative 10 meters bar"
));
result
=
QGCAudioWorker
::
fixTextMessageForAudio
(
QStringLiteral
(
"-foom"
));
QCOMPARE
(
result
,
QStringLiteral
(
"-foom"
));
result
=
QGCAudioWorker
::
fixTextMessageForAudio
(
QStringLiteral
(
"10 moo"
));
QCOMPARE
(
result
,
QStringLiteral
(
"10 moo"
));
result
=
QGCAudioWorker
::
fixTextMessageForAudio
(
QStringLiteral
(
"10moo"
));
QCOMPARE
(
result
,
QStringLiteral
(
"10moo"
));
}
src/audio/QGCAudioWorkerTest.h
0 → 100644
View file @
15631ad0
/****************************************************************************
*
* (c) 2009-2016 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 "UnitTest.h"
class
QGCAudioWorkerTest
:
public
UnitTest
{
Q_OBJECT
public:
QGCAudioWorkerTest
(
void
);
private
slots
:
void
_testSpokenReplacements
(
void
);
};
src/qgcunittest/UnitTestList.cc
View file @
15631ad0
...
...
@@ -38,6 +38,7 @@
#include "PlanMasterControllerTest.h"
#include "MissionSettingsTest.h"
#include "QGCMapPolygonTest.h"
#include "QGCAudioWorkerTest.h"
UT_REGISTER_TEST
(
FactSystemTestGeneric
)
UT_REGISTER_TEST
(
FactSystemTestPX4
)
...
...
@@ -62,6 +63,7 @@ UT_REGISTER_TEST(SpeedSectionTest)
UT_REGISTER_TEST
(
PlanMasterControllerTest
)
UT_REGISTER_TEST
(
MissionSettingsTest
)
UT_REGISTER_TEST
(
QGCMapPolygonTest
)
UT_REGISTER_TEST
(
QGCAudioWorkerTest
)
// List of unit test which are currently disabled.
// If disabling a new test, include reason in comment.
...
...
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