Skip to content

Commit

Permalink
Updated aircraft performance class and collection handler for permane…
Browse files Browse the repository at this point in the history
…nt data collection.

More get methods for fuel volume and weight in performance.
albar965/littlenavmap#340
  • Loading branch information
albar965 committed Jun 19, 2019
1 parent 4aeb8a7 commit 59e1a73
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 51 deletions.
96 changes: 88 additions & 8 deletions src/fs/perf/aircraftperf.cpp
Expand Up @@ -92,6 +92,11 @@ void AircraftPerf::save(const QString& filepath)
throw atools::Exception(tr("Cannot open aircraft performance file \"%1\" for writing.").arg(filepath));
}

void AircraftPerf::resetToDefault()
{
*this = AircraftPerf();
}

void AircraftPerf::setNull()
{
resetToDefault();
Expand All @@ -107,11 +112,6 @@ void AircraftPerf::setNull()
runwayType = SOFT;
}

void AircraftPerf::resetToDefault()
{
*this = AircraftPerf();
}

void AircraftPerf::fromGalToLbs()
{
using atools::geo::fromGalToLbs;
Expand Down Expand Up @@ -142,7 +142,7 @@ void AircraftPerf::fromLbsToGal()

bool AircraftPerf::operator==(const AircraftPerf& other) const
{
return fuelAsVolume == other.fuelAsVolume &&
return volume == other.volume &&
name == other.name &&
type == other.type &&
description == other.description &&
Expand All @@ -166,6 +166,86 @@ bool AircraftPerf::operator==(const AircraftPerf& other) const

}

float AircraftPerf::getTaxiFuelLbs() const
{
return volume ? atools::geo::fromGalToLbs(jetFuel, taxiFuel) : taxiFuel;
}

float AircraftPerf::getTaxiFuelGal() const
{
return volume ? taxiFuel : atools::geo::fromLbsToGal(jetFuel, taxiFuel);
}

float AircraftPerf::getReserveFuelLbs() const
{
return volume ? atools::geo::fromGalToLbs(jetFuel, reserveFuel) : reserveFuel;
}

float AircraftPerf::getReserveFuelGal() const
{
return volume ? reserveFuel : atools::geo::fromLbsToGal(jetFuel, reserveFuel);
}

float AircraftPerf::getExtraFuelLbs() const
{
return volume ? atools::geo::fromGalToLbs(jetFuel, extraFuel) : extraFuel;
}

float AircraftPerf::getExtraFuelGal() const
{
return volume ? extraFuel : atools::geo::fromLbsToGal(jetFuel, extraFuel);
}

float AircraftPerf::getClimbFuelFlowLbs() const
{
return volume ? atools::geo::fromGalToLbs(jetFuel, climbFuelFlow) : climbFuelFlow;
}

float AircraftPerf::getClimbFuelFlowGal() const
{
return volume ? climbFuelFlow : atools::geo::fromLbsToGal(jetFuel, climbFuelFlow);
}

float AircraftPerf::getCruiseFuelFlowLbs() const
{
return volume ? atools::geo::fromGalToLbs(jetFuel, cruiseFuelFlow) : cruiseFuelFlow;
}

float AircraftPerf::getCruiseFuelFlowGal() const
{
return volume ? cruiseFuelFlow : atools::geo::fromLbsToGal(jetFuel, cruiseFuelFlow);
}

float AircraftPerf::getDescentFuelFlowLbs() const
{
return volume ? atools::geo::fromGalToLbs(jetFuel, descentFuelFlow) : descentFuelFlow;
}

float AircraftPerf::getDescentFuelFlowGal() const
{
return volume ? descentFuelFlow : atools::geo::fromLbsToGal(jetFuel, descentFuelFlow);
}

float AircraftPerf::getUsableFuelLbs() const
{
return volume ? atools::geo::fromGalToLbs(jetFuel, usableFuel) : usableFuel;
}

float AircraftPerf::getUsableFuelGal() const
{
return volume ? usableFuel : atools::geo::fromLbsToGal(jetFuel, usableFuel);
}

float AircraftPerf::getAlternateFuelFlowLbs() const
{
return volume ? atools::geo::fromGalToLbs(jetFuel, alternateFuelFlow) : alternateFuelFlow;
}

float AircraftPerf::getAlternateFuelFlowGal() const
{
return volume ? alternateFuelFlow : atools::geo::fromLbsToGal(jetFuel, alternateFuelFlow);
}

void AircraftPerf::readFromSettings(const QSettings& settings)
{
name = settings.value("Options/Name").toString();
Expand All @@ -174,7 +254,7 @@ void AircraftPerf::readFromSettings(const QSettings& settings)
programVersion = settings.value("Options/ProgramVersion").toString();
formatVersion = settings.value("Options/FormatVersion").toString();

fuelAsVolume = settings.value("Options/FuelAsVolume").toBool();
volume = settings.value("Options/FuelAsVolume").toBool();
jetFuel = settings.value("Options/JetFuel").toBool();

usableFuel = settings.value("Perf/UsableFuel").toFloat();
Expand Down Expand Up @@ -227,7 +307,7 @@ void AircraftPerf::writeToSettings(QSettings& settings)
settings.setValue("Options/AircraftType", type);
settings.setValue("Options/Description", description);

settings.setValue("Options/FuelAsVolume", fuelAsVolume);
settings.setValue("Options/FuelAsVolume", volume);
settings.setValue("Options/JetFuel", jetFuel);

settings.setValue("Perf/UsableFuel", QString::number(usableFuel));
Expand Down
34 changes: 28 additions & 6 deletions src/fs/perf/aircraftperf.h
Expand Up @@ -26,9 +26,6 @@
class QSettings;

namespace atools {
namespace geo {
class LineString;
}

namespace fs {
namespace perf {
Expand All @@ -37,6 +34,7 @@ namespace perf {
* Aircraft performance data which can be loaded and saved from or to an ini-file.
*
* All speeds are TAS knots, fuel is gallons/lbs and vertical speeds are feet/minute.
* Fuel flow is gallons/lbs per hour.
*/
class AircraftPerf
{
Expand Down Expand Up @@ -93,12 +91,12 @@ class AircraftPerf

bool useFuelAsVolume() const
{
return fuelAsVolume;
return volume;
}

void setFuelAsVolume(bool fuelAsVol)
{
fuelAsVolume = fuelAsVol;
volume = fuelAsVol;
}

/* lbs or gallons - not part of trip fuel */
Expand All @@ -107,6 +105,9 @@ class AircraftPerf
return taxiFuel;
}

float getTaxiFuelLbs() const;
float getTaxiFuelGal() const;

void setTaxiFuel(float value)
{
taxiFuel = value;
Expand All @@ -118,6 +119,9 @@ class AircraftPerf
return reserveFuel;
}

float getReserveFuelLbs() const;
float getReserveFuelGal() const;

void setReserveFuel(float value)
{
reserveFuel = value;
Expand All @@ -129,6 +133,9 @@ class AircraftPerf
return extraFuel;
}

float getExtraFuelLbs() const;
float getExtraFuelGal() const;

void setExtraFuel(float value)
{
extraFuel = value;
Expand Down Expand Up @@ -179,6 +186,9 @@ class AircraftPerf
return climbFuelFlow;
}

float getClimbFuelFlowLbs() const;
float getClimbFuelFlowGal() const;

void setClimbFuelFlow(float value)
{
climbFuelFlow = value;
Expand All @@ -201,6 +211,9 @@ class AircraftPerf
return cruiseFuelFlow;
}

float getCruiseFuelFlowLbs() const;
float getCruiseFuelFlowGal() const;

void setCruiseFuelFlow(float value)
{
cruiseFuelFlow = value;
Expand All @@ -223,6 +236,9 @@ class AircraftPerf
return descentFuelFlow;
}

float getDescentFuelFlowLbs() const;
float getDescentFuelFlowGal() const;

void setDescentFuelFlow(float value)
{
descentFuelFlow = value;
Expand Down Expand Up @@ -306,6 +322,9 @@ class AircraftPerf
return usableFuel;
}

float getUsableFuelLbs() const;
float getUsableFuelGal() const;

void setUsableFuel(float value)
{
usableFuel = value;
Expand All @@ -328,6 +347,9 @@ class AircraftPerf
return alternateFuelFlow;
}

float getAlternateFuelFlowLbs() const;
float getAlternateFuelFlowGal() const;

void setAlternateFuelFlow(float value)
{
alternateFuelFlow = value;
Expand Down Expand Up @@ -364,7 +386,7 @@ class AircraftPerf
void readFromSettings(const QSettings& settings);
void writeToSettings(QSettings& settings);

bool fuelAsVolume = false, jetFuel = false;
bool volume = false, jetFuel = false;

QString name, type, description, programVersion, formatVersion;

Expand Down
4 changes: 2 additions & 2 deletions src/fs/perf/aircraftperfconstants.h
Expand Up @@ -25,7 +25,7 @@ namespace fs {
namespace perf {

/* Flight segment as detected by the AircraftPerfHandler for simulator events.
* Numeric order is important */
* Numeric order is important for comparing. */
enum FlightSegment
{
NONE,
Expand All @@ -35,7 +35,7 @@ enum FlightSegment
CRUISE,
DESCENT,
DESTINATION_TAXI,
DESTINTATION_PARKING,
DESTINATION_PARKING,
INVALID
};

Expand Down
65 changes: 48 additions & 17 deletions src/fs/perf/aircraftperfhandler.cpp
Expand Up @@ -29,27 +29,46 @@ namespace perf {
using atools::fs::sc::SimConnectUserAircraft;
using atools::fs::sc::SimConnectData;
using atools::roundToInt;
using atools::fs::perf::AircraftPerf;

AircraftPerfHandler::AircraftPerfHandler(QObject *parent)
: QObject(parent)
{
perf = new AircraftPerf;
perf->setNull();
}

AircraftPerfHandler::~AircraftPerfHandler()
{
delete perf;
}

void AircraftPerfHandler::simDataChanged(const sc::SimConnectData& simulatorData)
void AircraftPerfHandler::start()
{
if(perf == nullptr)
return;
currentFlightSegment = NONE;
startFuel = totalFuelConsumed = weightVolRatio = 0.f;
lastSampleTimeMs = lastCruiseSampleTimeMs = lastClimbSampleTimeMs = lastDescentSampleTimeMs = 0L;

if(!simulatorData.isUserAircraftValid() ||
simulatorData.getUserAircraftConst().isSimPaused() ||
simulatorData.getUserAircraftConst().isSimReplay())
return;
perf->setNull();

const SimConnectUserAircraft& aircraft = simulatorData.getUserAircraftConst();
active = true;
}

void AircraftPerfHandler::reset()
{
start();
}

void AircraftPerfHandler::stop()
{
active = false;
}

void AircraftPerfHandler::simDataChanged(const sc::SimConnectData& simulatorData)
{
const sc::SimConnectUserAircraft& aircraft = simulatorData.getUserAircraftConst();
if(!active || !aircraft.isValid() || aircraft.isSimPaused() || aircraft.isSimReplay())
return;

// Fill metadata if still empty
if(perf->getAircraftType().isEmpty())
Expand Down Expand Up @@ -140,10 +159,12 @@ void AircraftPerfHandler::simDataChanged(const sc::SimConnectData& simulatorData
case DESTINATION_TAXI:
if(!aircraft.hasFuelFlow())
// Engine shutdown
flightSegment = DESTINTATION_PARKING;
flightSegment = DESTINATION_PARKING;
break;

case DESTINTATION_PARKING:
case DESTINATION_PARKING:
// Finish on engine shutdown - stop collecting
active = false;
break;
}
}
Expand Down Expand Up @@ -179,6 +200,16 @@ void AircraftPerfHandler::simDataChanged(const sc::SimConnectData& simulatorData
}
}

bool AircraftPerfHandler::isFinished() const
{
return currentFlightSegment == DESTINATION_TAXI || currentFlightSegment == DESTINATION_PARKING;
}

void AircraftPerfHandler::setAircraftPerformance(const AircraftPerf& value)
{
*perf = value;
}

float AircraftPerfHandler::sampleValue(qint64 lastSampleDuration, qint64 curSampleDuration, float lastValue,
float curValue)
{
Expand All @@ -197,12 +228,12 @@ void AircraftPerfHandler::samplePhase(FlightSegment flightSegment, const SimConn
// Calculate all average values for each flight phase
switch(flightSegment)
{
case atools::fs::perf::NONE:
case atools::fs::perf::DEPARTURE_PARKING:
case atools::fs::perf::INVALID:
case atools::fs::perf::DESTINTATION_PARKING:
case atools::fs::perf::DESTINATION_TAXI:
case atools::fs::perf::DEPARTURE_TAXI:
case NONE:
case DEPARTURE_PARKING:
case INVALID:
case DESTINATION_PARKING:
case DESTINATION_TAXI:
case DEPARTURE_TAXI:
break;

case atools::fs::perf::CLIMB:
Expand Down Expand Up @@ -308,7 +339,7 @@ QString AircraftPerfHandler::getFlightSegmentString(atools::fs::perf::FlightSegm
case DESTINATION_TAXI:
return tr("Destination Taxi");

case DESTINTATION_PARKING:
case DESTINATION_PARKING:
return tr("Destination Parking");

}
Expand Down

0 comments on commit 59e1a73

Please sign in to comment.