From fd265eccbb7991f8eb0e847db59437abbfbc586f Mon Sep 17 00:00:00 2001 From: Harpalyke <33022534+Harpalyke@users.noreply.github.com> Date: Mon, 13 Nov 2017 21:21:22 +0000 Subject: [PATCH] =?UTF-8?q?Adding=20regex=20check=20for=20crossfire=20gps?= =?UTF-8?q?=20format=20when=20reading=20logs=20in=20tele=E2=80=A6=20(#5347?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- companion/src/simulation/telemetrysimu.cpp | 39 ++++++++++++++++++++-- companion/src/simulation/telemetrysimu.h | 2 ++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/companion/src/simulation/telemetrysimu.cpp b/companion/src/simulation/telemetrysimu.cpp index 6a5991cfe..d48772b6f 100644 --- a/companion/src/simulation/telemetrysimu.cpp +++ b/companion/src/simulation/telemetrysimu.cpp @@ -23,6 +23,7 @@ #include "ui_telemetrysimu.h" #include "simulatorinterface.h" #include "radio/src/telemetry/frsky.h" +#include 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); } diff --git a/companion/src/simulation/telemetrysimu.h b/companion/src/simulation/telemetrysimu.h index 332a147e1..e9810ce59 100644 --- a/companion/src/simulation/telemetrysimu.h +++ b/companion/src/simulation/telemetrysimu.h @@ -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 colToFuncMap; // contains all 'known' column headings and how they are to be processed Ui::TelemetrySimulator * ui;