Skip to content

Commit

Permalink
Don't let FS9 overwrite an 8.33 kHz frequency
Browse files Browse the repository at this point in the history
  • Loading branch information
oktal3700 authored and ltoenning committed Nov 12, 2023
1 parent 67073d0 commit 2f3dc5a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/blackmisc/simulation/ownaircraftprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ namespace BlackMisc::Simulation
return this->provider()->getOwnCallsign();
}

CComSystem COwnAircraftAware::getOwnComSystem(CComSystem::ComUnit unit) const
{
Q_ASSERT_X(this->provider(), Q_FUNC_INFO, "No object available");
return this->provider()->getOwnComSystem(unit);
}

CTransponder COwnAircraftAware::getOwnTransponder() const
{
Q_ASSERT_X(this->provider(), Q_FUNC_INFO, "No object available");
return this->provider()->getOwnTransponder();
}

CCoordinateGeodetic COwnAircraftAware::getOwnAircraftPosition() const
{
Q_ASSERT_X(this->provider(), Q_FUNC_INFO, "No object available");
Expand Down
6 changes: 6 additions & 0 deletions src/blackmisc/simulation/ownaircraftprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ namespace BlackMisc
//! \copydoc IOwnAircraftProvider::getOwnCallsign
Aviation::CCallsign getOwnCallsign() const;

//! \copydoc IOwnAircraftProvider::getOwnComSystem
Aviation::CComSystem getOwnComSystem(Aviation::CComSystem::ComUnit unit) const;

//! \copydoc IOwnAircraftProvider::getOwnTransponder
Aviation::CTransponder getOwnTransponder() const;

//! \copydoc IOwnAircraftProvider::getOwnAircraftPosition
BlackMisc::Geo::CCoordinateGeodetic getOwnAircraftPosition() const;

Expand Down
24 changes: 19 additions & 5 deletions src/plugins/simulator/fs9/simulatorfs9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,25 @@ namespace BlackSimPlugin::Fs9
// To avoid jitters, I wait some update cylces to stabilize the values
if (m_skipCockpitUpdateCycles < 1)
{
this->updateCockpit(
simDataOwnAircraft.getCom1System(),
simDataOwnAircraft.getCom2System(),
simDataOwnAircraft.getTransponder(),
this->identifier());
const auto dontOverwrite = [](const CFrequency &from, const CFrequency &to) {
// don't overwrite 8.33 kHz frequencies
return CComSystem::isExclusiveWithin8_33kHzChannel(from) &&
from.valueInteger(CFrequencyUnit::kHz()) / 10 == to.valueInteger(CFrequencyUnit::kHz()) / 10;
};
CComSystem com1 = simDataOwnAircraft.getCom1System();
CComSystem com2 = simDataOwnAircraft.getCom2System();
const CComSystem oldCom1 = getOwnComSystem(CComSystem::Com1);
const CComSystem oldCom2 = getOwnComSystem(CComSystem::Com2);
if (dontOverwrite(oldCom1.getFrequencyActive(), com1.getFrequencyActive()))
com1.setFrequencyActive(oldCom1.getFrequencyActive());
if (dontOverwrite(oldCom1.getFrequencyStandby(), com1.getFrequencyStandby()))
com1.setFrequencyStandby(oldCom1.getFrequencyStandby());
if (dontOverwrite(oldCom2.getFrequencyActive(), com2.getFrequencyActive()))
com2.setFrequencyActive(oldCom2.getFrequencyActive());
if (dontOverwrite(oldCom2.getFrequencyStandby(), com2.getFrequencyStandby()))
com2.setFrequencyStandby(oldCom2.getFrequencyStandby());

this->updateCockpit(com1, com2, simDataOwnAircraft.getTransponder(), this->identifier());
}
else
{
Expand Down

0 comments on commit 2f3dc5a

Please sign in to comment.