forked from EdgeTX/edgetx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cpn): support more than just FrSky S.Port telemetry simulation (E…
- Loading branch information
Showing
17 changed files
with
6,717 additions
and
3,915 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
/* | ||
* Copyright (C) EdgeTX | ||
* | ||
* Based on code named | ||
* opentx - https://github.com/opentx/opentx | ||
* th9x - http://code.google.com/p/th9x | ||
* er9x - http://code.google.com/p/er9x | ||
* gruvin9x - http://code.google.com/p/gruvin9x | ||
* | ||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2 as | ||
* published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
*/ | ||
|
||
#include "simulatedgps.h" | ||
#include <QtMath> | ||
#include <QDebug> | ||
|
||
SimulatedGPS::SimulatedGPS() | ||
{ | ||
lat = 0; | ||
lon = 0; | ||
courseDegrees = 0; | ||
speedKMH = 0; | ||
altitude = 0; | ||
satellites = 0; | ||
dt = QDateTime::currentDateTime(); | ||
running = false; | ||
timer.setInterval(250); | ||
connect(&timer, &QTimer::timeout, this, &SimulatedGPS::update); | ||
} | ||
|
||
SimulatedGPS::~SimulatedGPS() | ||
{ | ||
} | ||
|
||
void SimulatedGPS::setDateTime(QDateTime dateTime) | ||
{ | ||
dt = dateTime; | ||
} | ||
|
||
void SimulatedGPS::setDateTime(QString dateTime) | ||
{ | ||
if (dateTime.startsWith("*")) { | ||
dt = QDateTime::currentDateTime(); | ||
} else { | ||
dt = QDateTime::fromString(dateTime, Qt::ISODate); | ||
} | ||
} | ||
|
||
void SimulatedGPS::setLatLon(QString latLon) | ||
{ | ||
QStringList coords = latLon.split(","); | ||
if (coords.length() < 2) { | ||
coords = latLon.split(" "); | ||
} | ||
lat = 0.0; | ||
lon = 0.0; | ||
if (coords.length() > 1) { | ||
lat = coords[0].simplified().toDouble(); | ||
lon = coords[1].simplified().toDouble(); | ||
} else { | ||
stop(); | ||
} | ||
} | ||
|
||
void SimulatedGPS::setCourseDegrees(double course) | ||
{ | ||
courseDegrees = course; | ||
} | ||
|
||
void SimulatedGPS::setSpeedKMH(double speed) | ||
{ | ||
speedKMH = speed; | ||
} | ||
|
||
void SimulatedGPS::setAltitude(double altitude) | ||
{ | ||
this->altitude = altitude; | ||
} | ||
|
||
void SimulatedGPS::setSatelliteCount(int sats) | ||
{ | ||
satellites = sats; | ||
} | ||
|
||
void SimulatedGPS::start() | ||
{ | ||
running = true; | ||
timer.start(); | ||
} | ||
|
||
void SimulatedGPS::stop() | ||
{ | ||
running = false; | ||
timer.stop(); | ||
} | ||
|
||
void SimulatedGPS::update() | ||
{ | ||
if (!running) { | ||
return; | ||
} | ||
|
||
dt = QDateTime::currentDateTime().toTimeSpec(Qt::UTC); | ||
emitDateTimeChange(); | ||
|
||
double b2 = lat; | ||
double c2 = lon; | ||
double d3 = speedKMH / 14400; | ||
double f3 = courseDegrees; | ||
double j2 = 6378.1; | ||
double b3 = qRadiansToDegrees(qAsin( qSin(qDegreesToRadians(b2))*qCos(d3/j2) + qCos(qDegreesToRadians(b2))*qSin(d3/j2)*qCos(qDegreesToRadians(f3)))); | ||
double bb3 = b3; | ||
if (bb3 < 0) { | ||
bb3 = bb3 * -1; | ||
} | ||
if (bb3 > 89.99) { | ||
f3 = f3 + 180; | ||
if (f3 > 360) { | ||
f3 = f3 - 360; | ||
} | ||
courseDegrees = f3; | ||
emit courseDegreesChanged(courseDegrees); | ||
} | ||
double c3 = qRadiansToDegrees(qDegreesToRadians(c2) + qAtan2(qSin(qDegreesToRadians(f3))*qSin(d3/j2)*qCos(qDegreesToRadians(b2)),qCos(d3/j2)-qSin(qDegreesToRadians(b2))*qSin(qDegreesToRadians(b3)))); | ||
if (c3 > 180) { | ||
c3 = c3 - 360; | ||
} | ||
if (c3 < -180) { | ||
c3 = c3 + 360; | ||
} | ||
lat = b3; | ||
lon = c3; | ||
|
||
emitPositionChange(); | ||
} | ||
|
||
void SimulatedGPS::emitPositionChange() | ||
{ | ||
QString lats = QString::number(lat, 'f', 8); | ||
QString lons = QString::number(lon, 'f', 8); | ||
QString qs = lats + "," + lons; | ||
|
||
emit positionChanged(qs); | ||
} | ||
|
||
void SimulatedGPS::emitDateTimeChange() | ||
{ | ||
QString formatted = dt.toString(Qt::ISODate); | ||
emit dateTimeChanged(formatted); | ||
emit dateTimeChanged(dt); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (C) EdgeTX | ||
* | ||
* Based on code named | ||
* opentx - https://github.com/opentx/opentx | ||
* th9x - http://code.google.com/p/th9x | ||
* er9x - http://code.google.com/p/er9x | ||
* gruvin9x - http://code.google.com/p/gruvin9x | ||
* | ||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2 as | ||
* published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <QTimer> | ||
#include <QDateTime> | ||
|
||
class SimulatedGPS : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
SimulatedGPS(); | ||
~SimulatedGPS(); | ||
|
||
QDateTime dt; | ||
double lat; | ||
double lon; | ||
double courseDegrees; | ||
double speedKMH; | ||
double altitude; // in meters | ||
uint8_t satellites; | ||
bool running; | ||
|
||
signals: | ||
void positionChanged(const QString latLon); | ||
void dateTimeChanged(const QString dateTime); | ||
void dateTimeChanged(const QDateTime dateTime); | ||
void courseDegreesChanged(double course); | ||
|
||
public slots: | ||
void setDateTime(QDateTime dateTime); | ||
void setDateTime(QString dateTime); | ||
void setLatLon(QString latLon); | ||
void setCourseDegrees(double course); | ||
void setSpeedKMH(double speed); | ||
void setAltitude(double altitude); | ||
void setSatelliteCount(int sats); | ||
void start(); | ||
void stop(); | ||
|
||
protected slots: | ||
void update(); | ||
void emitPositionChange(); | ||
void emitDateTimeChange(); | ||
|
||
private: | ||
QTimer timer; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (C) EdgeTX | ||
* | ||
* Based on code named | ||
* opentx - https://github.com/opentx/opentx | ||
* th9x - http://code.google.com/p/th9x | ||
* er9x - http://code.google.com/p/er9x | ||
* gruvin9x - http://code.google.com/p/gruvin9x | ||
* | ||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2 as | ||
* published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "simulatorinterface.h" | ||
#include <QHash> | ||
|
||
class TelemetryProvider | ||
{ | ||
public: | ||
virtual ~TelemetryProvider() {} | ||
|
||
virtual void resetRssi() = 0; | ||
|
||
// Simulator has been updated externally, update the UI to match | ||
virtual void loadUiFromSimulator(SimulatorInterface * simulator) = 0; | ||
|
||
// Load a telemetry item from the log replay. value must be in the correct units, | ||
// see supportLogItems | ||
virtual void loadItemFromLog(QString itemName, QString value) = 0; | ||
|
||
// Tell the log replayer what items we can accept and what units we need them in | ||
// - returns e.g. { "Alt" => "m", "GSpd" => "kmh" } | ||
virtual QHash<QString, QString> * getSupportedLogItems() = 0; | ||
|
||
// In hopes of being able to load a file and select the appropriate provider in one step | ||
virtual QString getLogfileIdentifier() = 0; | ||
|
||
// do the work every however often | ||
virtual void generateTelemetryFrame(SimulatorInterface * simulator) = 0; | ||
}; |
Oops, something went wrong.