mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-08 12:45:35 +08:00
Fix sending the correct pressure altitude for a pilot position
* Before this commit, only the true altitude was known for an aircraft situation. The pressure altitude was not available anywhere yet. * This caused a wrong altitude in radar clients. * We fix this reading the pressure altitude from the simulators and set it in the own aircraft situation. * MS Flight Simulators have the pressure altitude in the APIs available. * For X-Plane and emulated simulator, we need to calculate it from the pressure at sea level. * Finally, we use the new available pressure altitude to send it to the FSD server. Maniphest Tasks: Ref T223
This commit is contained in:
committed by
Klaus Basan
parent
51a90a9a71
commit
de4fe44156
@@ -9,8 +9,10 @@
|
||||
|
||||
#include "situationform.h"
|
||||
#include "ui_situationform.h"
|
||||
#include "blackmisc/pq/pressure.h"
|
||||
#include "blackmisc/pq/angle.h"
|
||||
#include "blackmisc/stringutils.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include <QDoubleValidator>
|
||||
|
||||
using namespace BlackMisc;
|
||||
@@ -29,14 +31,19 @@ namespace BlackGui
|
||||
|
||||
ui->le_Bank->setValidator(new QDoubleValidator(-180.0 + CAngleUnit::deg().getEpsilon(), 180.0, 3, ui->le_Bank));
|
||||
ui->le_Pitch->setValidator(new QDoubleValidator(-180.0 + CAngleUnit::deg().getEpsilon(), 180.0, 3, ui->le_Pitch));
|
||||
ui->le_Pressure->setValidator(new QDoubleValidator(980.0, 1046.0, 2, ui->le_Pressure));
|
||||
|
||||
connect(ui->hs_Bank, &QSlider::valueChanged, this, &CSituationForm::bankSliderChanged);
|
||||
connect(ui->hs_Pitch, &QSlider::valueChanged, this, &CSituationForm::pitchSliderChanged);
|
||||
connect(ui->hs_Pressure, &QSlider::valueChanged, this, &CSituationForm::pressureSliderChanged);
|
||||
connect(ui->le_Bank, &QLineEdit::editingFinished, this, &CSituationForm::bankEntered);
|
||||
connect(ui->le_Pitch, &QLineEdit::editingFinished, this, &CSituationForm::pitchEntered);
|
||||
connect(ui->le_Pressure, &QLineEdit::editingFinished, this, &CSituationForm::pressureEntered);
|
||||
connect(ui->tb_ResetBank, &QToolButton::clicked, this, &CSituationForm::resetBank);
|
||||
connect(ui->tb_ResetPitch, &QToolButton::clicked, this, &CSituationForm::resetPitch);
|
||||
connect(ui->tb_ResetPressure, &QToolButton::clicked, this, &CSituationForm::resetPressure);
|
||||
connect(ui->pb_Set, &QPushButton::clicked, this, &CSituationForm::changeAircraftSituation);
|
||||
connect(ui->pb_SetEnvironment, &QPushButton::clicked, this, &CSituationForm::changeAircraftSituation);
|
||||
connect(ui->comp_Coordinate, &CCoordinateForm::changeCoordinate, this, &CSituationForm::changeAircraftSituation);
|
||||
}
|
||||
|
||||
@@ -50,9 +57,13 @@ namespace BlackGui
|
||||
|
||||
CAircraftSituation CSituationForm::getSituation() const
|
||||
{
|
||||
CAircraftSituation s(ui->comp_Coordinate->getCoordinate());
|
||||
const BlackMisc::Geo::CCoordinateGeodetic position = ui->comp_Coordinate->getCoordinate();
|
||||
CAircraftSituation s(position);
|
||||
s.setBank(this->getBankAngle());
|
||||
s.setPitch(this->getPitchAngle());
|
||||
|
||||
CAltitude pressureAltitude(position.geodeticHeight().toPressureAltitude(this->getBarometricPressureMsl()));
|
||||
s.setPressureAltitude(pressureAltitude);
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -84,6 +95,20 @@ namespace BlackGui
|
||||
return CAngle::normalizeDegrees180(vd, RoundDigits);
|
||||
}
|
||||
|
||||
double CSituationForm::getBarometricPressureMslMillibar() const
|
||||
{
|
||||
const QString v(ui->le_Pressure->text().replace(',', '.'));
|
||||
bool ok;
|
||||
double vd = v.toDouble(&ok);
|
||||
if (!ok) { vd = 1013.25; }
|
||||
return vd;
|
||||
}
|
||||
|
||||
CPressure CSituationForm::getBarometricPressureMsl() const
|
||||
{
|
||||
return CPressure (getBarometricPressureMslMillibar(), CPressureUnit::mbar());
|
||||
}
|
||||
|
||||
void CSituationForm::setReadOnly(bool readonly)
|
||||
{
|
||||
ui->comp_Coordinate->setReadOnly(readonly);
|
||||
@@ -128,6 +153,13 @@ namespace BlackGui
|
||||
ui->le_Pitch->setText(QString::number(value));
|
||||
}
|
||||
|
||||
void CSituationForm::pressureSliderChanged(int value)
|
||||
{
|
||||
const int pressure = qRound(this->getBarometricPressureMslMillibar());
|
||||
if (value == pressure) { return; } // avoid roundtrips
|
||||
ui->le_Pressure->setText(QString::number(value));
|
||||
}
|
||||
|
||||
void CSituationForm::bankEntered()
|
||||
{
|
||||
const double ad = this->getBankAngleDegrees();
|
||||
@@ -161,5 +193,22 @@ namespace BlackGui
|
||||
ui->le_Pitch->setText("0");
|
||||
ui->hs_Pitch->setValue(0);
|
||||
}
|
||||
|
||||
void CSituationForm::pressureEntered()
|
||||
{
|
||||
const double pd = this->getBarometricPressureMslMillibar();
|
||||
QString n = QString::number(pd, 'g', 4 + RoundDigits);
|
||||
if (ui->le_Pressure->validator()) { dotToLocaleDecimalPoint(n); }
|
||||
ui->le_Pressure->setText(n);
|
||||
const int pi = qRound(pd);
|
||||
if (pi == ui->hs_Pressure->value()) { return; } // avoid roundtrips
|
||||
ui->hs_Pressure->setValue(pi);
|
||||
}
|
||||
|
||||
void CSituationForm::resetPressure()
|
||||
{
|
||||
ui->le_Pressure->setText("1013.00");
|
||||
ui->hs_Pressure->setValue(1013);
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
Reference in New Issue
Block a user