Adding regex check for crossfire gps format when reading logs in tele… (#5347)
* Adding regex check for crossfire gps format when reading logs in telemetry simulator Adding a regex check when the telemetry simulator parses gps cords from a log file to see if the if the cords are in the crossfire gps log format. The GPS telemetry sensor from crossfire logs the coordinates as latitude with a precision of six decimal places followed by a space and then longitude also to six decimal places. e.g. "53.279969 -7.701416" When the cords are already in this format their is no need to call convertDegMin on the values * Fixing code styling * Updating code style * Updating code style * Checking the gps coordinates format once before the full file is processed instead of evaluating the regex for every line of the file. Optimize regex by removing surrounding parenthesis
This commit is contained in:
committed by
Bertrand Songis
parent
57d53abd6e
commit
fd265eccbb
@@ -23,6 +23,7 @@
|
||||
#include "ui_telemetrysimu.h"
|
||||
#include "simulatorinterface.h"
|
||||
#include "radio/src/telemetry/frsky.h"
|
||||
#include <QRegularExpression>
|
||||
|
||||
TelemetrySimulator::TelemetrySimulator(QWidget * parent, SimulatorInterface * simulator):
|
||||
QWidget(parent),
|
||||
@@ -627,6 +628,7 @@ TelemetrySimulator::LogPlaybackController::LogPlaybackController(Ui::TelemetrySi
|
||||
{
|
||||
TelemetrySimulator::LogPlaybackController::ui = ui;
|
||||
stepping = false;
|
||||
logFileGpsCordsInDecimalFormat = false;
|
||||
// initialize the map - TODO: how should this be localized?
|
||||
colToFuncMap.clear();
|
||||
colToFuncMap.insert("RxBt(V)", RXBT_V);
|
||||
@@ -692,6 +694,31 @@ QDateTime TelemetrySimulator::LogPlaybackController::parseTransmittterTimestamp(
|
||||
return QDateTime::fromString(datePart + " " + timePart, format);
|
||||
}
|
||||
|
||||
void TelemetrySimulator::LogPlaybackController::checkGpsFormat()
|
||||
{
|
||||
// sample the first record to check if cords are in decimal format
|
||||
logFileGpsCordsInDecimalFormat = false;
|
||||
if(csvRecords.count() > 1) {
|
||||
QStringList keys = csvRecords[0].split(',');
|
||||
if(keys.contains("GPS")) {
|
||||
int gpsColIndex = keys.indexOf("GPS");
|
||||
QStringList firstRowVlues = csvRecords[1].split(',');
|
||||
QString gpsSample = firstRowVlues[gpsColIndex];
|
||||
QStringList cords = gpsSample.simplified().split(' ');
|
||||
if (cords.count() == 2) {
|
||||
// frsky and TBS crossfire GPS sensor logs cords in decimal format with a precision of 6 places
|
||||
// if this format is met there is no need to call convertDegMin later on when processing the file
|
||||
QRegularExpression decimalCoordinateFormatRegex("^[-+]?\\d{1,2}[.]\\d{6}$");
|
||||
QRegularExpressionMatch latFormatMatch = decimalCoordinateFormatRegex.match(cords[0]);
|
||||
QRegularExpressionMatch lonFormatMatch = decimalCoordinateFormatRegex.match(cords[1]);
|
||||
if (lonFormatMatch.hasMatch() && latFormatMatch.hasMatch()) {
|
||||
logFileGpsCordsInDecimalFormat = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TelemetrySimulator::LogPlaybackController::calcLogFrequency()
|
||||
{
|
||||
// examine up to 20 rows to determine log frequency in seconds
|
||||
@@ -760,6 +787,7 @@ void TelemetrySimulator::LogPlaybackController::loadLogFile()
|
||||
supportedCols.clear();
|
||||
recordIndex = 1;
|
||||
calcLogFrequency();
|
||||
checkGpsFormat();
|
||||
}
|
||||
ui->logFileLabel->setText(QFileInfo(logFileNameAndPath).fileName());
|
||||
// iterate through all known mappings and add those that are used
|
||||
@@ -868,8 +896,15 @@ QString TelemetrySimulator::LogPlaybackController::convertGPS(QString input)
|
||||
if (lonLat.count() < 2) {
|
||||
return ""; // invalid format
|
||||
}
|
||||
double lon = convertDegMin(lonLat[0]);
|
||||
double lat = convertDegMin(lonLat[1]);
|
||||
double lon, lat;
|
||||
if (logFileGpsCordsInDecimalFormat) {
|
||||
lat = lonLat[0].toDouble();
|
||||
lon = lonLat[1].toDouble();
|
||||
}
|
||||
else {
|
||||
lon = convertDegMin(lonLat[0]);
|
||||
lat = convertDegMin(lonLat[1]);
|
||||
}
|
||||
return QString::number(lat) + ", " + QString::number(lon);
|
||||
}
|
||||
|
||||
|
||||
@@ -96,6 +96,7 @@ class TelemetrySimulator : public QWidget
|
||||
void updatePositionLabel(int32_t percentage);
|
||||
void setUiDataValues();
|
||||
double logFrequency; // in seconds
|
||||
bool logFileGpsCordsInDecimalFormat;
|
||||
|
||||
private:
|
||||
enum CONVERT_TYPE {
|
||||
@@ -149,6 +150,7 @@ class TelemetrySimulator : public QWidget
|
||||
double convertDegMin(QString input);
|
||||
QDateTime parseTransmittterTimestamp(QString row);
|
||||
void calcLogFrequency();
|
||||
void checkGpsFormat();
|
||||
|
||||
QMap<QString, CONVERT_TYPE> colToFuncMap; // contains all 'known' column headings and how they are to be processed
|
||||
Ui::TelemetrySimulator * ui;
|
||||
|
||||
Reference in New Issue
Block a user