Commit 15631ad0 authored by DonLakeFlyer's avatar DonLakeFlyer

Better reading of numbers like -10.5m

parent 9c5cbf38
......@@ -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 \
......
......@@ -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 qmatch = i.next();
if (qmatch.hasMatch()) {
match = qmatch.captured(0);
number = qmatch.captured(0).replace("ms", "").toInt();
QRegularExpressionMatch reMatch = i.next();
if (reMatch.hasMatch()) {
match = reMatch.captured(0);
number = reMatch.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);
......
/****************************************************************************
*
* (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"));
}
/****************************************************************************
*
* (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);
};
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment