|
|
|
@ -165,10 +165,10 @@ bool QGCAudioWorker::_getMillisecondString(const QString& string, QString& match
@@ -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) {
@@ -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); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 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; |
|
|
|
|
} |
|
|
|
|
if(result.contains(" ADSB ", Qt::CaseInsensitive)) { |
|
|
|
|
result.replace(" ADSB ", " Hey Dee Ess Bee ", Qt::CaseInsensitive); |
|
|
|
|
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); |
|
|
|
|