Skip to content

Commit

Permalink
fix(squawks): assign squawks when aircraft connect during C-Mode corr…
Browse files Browse the repository at this point in the history
…elation

When an aircraft connects with a flightplan in C-Mode correlation, the data ES presents to the
plugin can sometimes be invalid - e.g. exactly 0ft at exactly 0.0nm from origin. This prevents
squawks from assigning. This change adds a regular poll to squawks, initial altitudes and initial
headings to check for required updates - which apparently works as during these polls ES returns us
complete data.

fix VATSIM-UK#284 VATSIM-UK#285 VATSIM-UK#286
  • Loading branch information
AndyTWF committed Jul 3, 2021
1 parent de50349 commit e5bdab8
Show file tree
Hide file tree
Showing 19 changed files with 436 additions and 355 deletions.
76 changes: 36 additions & 40 deletions src/initialaltitude/InitialAltitudeEventHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
#include "euroscope/EuroScopeCRadarTargetInterface.h"
#include "ownership/AirfieldOwnershipManager.h"
#include "controller/ActiveCallsignCollection.h"
#include "timedevent/DeferredEventHandler.h"
#include "login/Login.h"
#include "flightplan/DeferredFlightplanEvent.h"
#include "euroscope/EuroscopePluginLoopbackInterface.h"
#include "euroscope/GeneralSettingsEntries.h"
#include "sid/SidCollection.h"
Expand All @@ -20,10 +18,7 @@ using UKControllerPlugin::Ownership::AirfieldOwnershipManager;
using UKControllerPlugin::Controller::ActiveCallsignCollection;
using UKControllerPlugin::Controller::ActiveCallsign;
using UKControllerPlugin::Airfield::NormaliseSid;
using UKControllerPlugin::TimedEvent::DeferredEventHandler;
using UKControllerPlugin::Controller::Login;
using UKControllerPlugin::Flightplan::DeferredFlightPlanEvent;
using UKControllerPlugin::Flightplan::StoredFlightplanCollection;
using UKControllerPlugin::Euroscope::EuroscopePluginLoopbackInterface;
using UKControllerPlugin::Euroscope::GeneralSettingsEntries;

Expand All @@ -35,13 +30,10 @@ namespace UKControllerPlugin {
const ActiveCallsignCollection & activeCallsigns,
const AirfieldOwnershipManager & airfieldOwnership,
const Login & login,
DeferredEventHandler & deferredEvents,
EuroscopePluginLoopbackInterface & plugin,
const StoredFlightplanCollection& storedFlightplans
EuroscopePluginLoopbackInterface& plugin
)
: minimumLoginTimeBeforeAssignment(5), sids(sids), activeCallsigns(activeCallsigns),
airfieldOwnership(airfieldOwnership), deferredEvents(deferredEvents), login(login),
storedFlightplans(storedFlightplans), plugin(plugin)
airfieldOwnership(airfieldOwnership), login(login), plugin(plugin)
{

}
Expand All @@ -60,11 +52,8 @@ namespace UKControllerPlugin {
// If we've not been logged in for long, wait a bit
if (this->login.GetSecondsLoggedIn() < this->minimumLoginTimeBeforeAssignment) {
LogDebug(
"Deferring initial altitude assignment for " + flightPlan.GetCallsign()
);
this->deferredEvents.DeferFor(
std::make_unique<DeferredFlightPlanEvent>(*this, this->plugin, flightPlan.GetCallsign()),
this->minimumLoginTimeBeforeAssignment
"Deferring initial altitude assignment for " + flightPlan.GetCallsign() +
" for now, user has only recently logged in"
);
return;
}
Expand Down Expand Up @@ -105,10 +94,6 @@ namespace UKControllerPlugin {
this->alreadySetMap[flightPlan.GetCallsign()] = flightPlan.GetSidName();
}

InitialAltitudeEventHandler::~InitialAltitudeEventHandler(void)
{
}

/*
Handle events regarding when a flightplan disconnects.
*/
Expand Down Expand Up @@ -228,24 +213,8 @@ namespace UKControllerPlugin {
}


LogInfo("Mass assigning initial altitudes");

std::shared_ptr<EuroScopeCFlightPlanInterface> fp;
std::shared_ptr<EuroScopeCRadarTargetInterface> rt;
for (
StoredFlightplanCollection::const_iterator it = this->storedFlightplans.cbegin();
it != this->storedFlightplans.cend();
++it
) {
fp = this->plugin.GetFlightplanForCallsign(it->second->GetCallsign());
rt = this->plugin.GetRadarTargetForCallsign(it->second->GetCallsign());

if (!fp || !rt) {
continue;
}

this->FlightPlanEvent(*fp, *rt);
}
LogInfo("User now active, mass assigning initial altitudes");
this->CheckAllFlightplansForAssignment();
}

/*
Expand All @@ -264,12 +233,39 @@ namespace UKControllerPlugin {

}

/*
* Periodically, check all flightplans to see if they need an initial altitude update.
*/
void InitialAltitudeEventHandler::TimedEventTrigger()
{
if (!this->activeCallsigns.UserHasCallsign()) {
return;
}

this->CheckAllFlightplansForAssignment();
}

/*
* Loop all the flightplans and check if they need an assignment.
*/
void InitialAltitudeEventHandler::CheckAllFlightplansForAssignment()
{
this->plugin.ApplyFunctionToAllFlightplans(
[this]
(
std::shared_ptr<EuroScopeCFlightPlanInterface> fp,
std::shared_ptr<EuroScopeCRadarTargetInterface> rt
)
{
this->FlightPlanEvent(*fp, *rt);
}
);
}

/*
Called when user settings get updated.
*/
void InitialAltitudeEventHandler::UserSettingsUpdated(
UKControllerPlugin::Euroscope::UserSetting & userSettings
)
void InitialAltitudeEventHandler::UserSettingsUpdated(Euroscope::UserSetting& userSettings)
{
this->userAutomaticAssignmentsAllowed = userSettings.GetBooleanEntry(
GeneralSettingsEntries::initialAltitudeToggleSettingsKey,
Expand Down
65 changes: 28 additions & 37 deletions src/initialaltitude/InitialAltitudeEventHandler.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#pragma once
#include "flightplan/FlightPlanEventHandlerInterface.h"
#include "airfield/NormaliseSid.h"
#include "timedevent/DeferredEventHandler.h"
#include "euroscope/UserSettingAwareInterface.h"
#include "controller/ActiveCallsignEventHandlerInterface.h"
#include "flightplan/StoredFlightplanCollection.h"
#include "timedevent/AbstractTimedEvent.h"

// Forward declarations

Expand All @@ -24,9 +23,6 @@ namespace UKControllerPlugin {
class SidCollection;
class StandardInstrumentDeparture;
} // namespace Sid
namespace TimedEvent {
class DeferredEventHandler;
} // namespace TimedEvent
namespace Euroscope {
class EuroscopePluginLoopbackInterface;
} // namespace Euroscope
Expand All @@ -38,51 +34,51 @@ namespace UKControllerPlugin {
/*
Class that responds to events related to initial altitudes.
*/
class InitialAltitudeEventHandler : public UKControllerPlugin::Flightplan::FlightPlanEventHandlerInterface,
public UKControllerPlugin::Euroscope::UserSettingAwareInterface,
public UKControllerPlugin::Controller::ActiveCallsignEventHandlerInterface
class InitialAltitudeEventHandler : public Flightplan::FlightPlanEventHandlerInterface,
public Euroscope::UserSettingAwareInterface,
public Controller::ActiveCallsignEventHandlerInterface,
public TimedEvent::AbstractTimedEvent
{
public:
InitialAltitudeEventHandler(
const Sid::SidCollection& sids,
const UKControllerPlugin::Controller::ActiveCallsignCollection & activeCallsigns,
const UKControllerPlugin::Ownership::AirfieldOwnershipManager & airfieldOwnership,
const UKControllerPlugin::Controller::Login & login,
UKControllerPlugin::TimedEvent::DeferredEventHandler & deferredEvents,
UKControllerPlugin::Euroscope::EuroscopePluginLoopbackInterface & plugin,
const UKControllerPlugin::Flightplan::StoredFlightplanCollection& storedFlightplans
const Controller::ActiveCallsignCollection& activeCallsigns,
const Ownership::AirfieldOwnershipManager& airfieldOwnership,
const Controller::Login& login,
Euroscope::EuroscopePluginLoopbackInterface& plugin
);
void FlightPlanEvent(
UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface & flightPlan,
UKControllerPlugin::Euroscope::EuroScopeCRadarTargetInterface & radarTarget
Euroscope::EuroScopeCFlightPlanInterface& flightPlan,
Euroscope::EuroScopeCRadarTargetInterface& radarTarget
) override;
~InitialAltitudeEventHandler(void);
~InitialAltitudeEventHandler() override = default;
void FlightPlanDisconnectEvent(
UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface & flightPlan
Euroscope::EuroScopeCFlightPlanInterface& flightPlan
) override;
void ControllerFlightPlanDataEvent(
UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface & flightPlan,
Euroscope::EuroScopeCFlightPlanInterface& flightPlan,
int dataType
) override;
void RecycleInitialAltitude(
UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface & flightPlan,
UKControllerPlugin::Euroscope::EuroScopeCRadarTargetInterface & radarTarget,
Euroscope::EuroScopeCFlightPlanInterface& flightPlan,
Euroscope::EuroScopeCRadarTargetInterface& radarTarget,
std::string context,
const POINT & mousePos
);
bool UserAutomaticAssignmentsAllowed(void) const;
void UserSettingsUpdated(UKControllerPlugin::Euroscope::UserSetting & userSettings) override;
void UserSettingsUpdated(Euroscope::UserSetting& userSettings) override;

// Inherited via ActiveCallsignEventHandlerInterface
void ActiveCallsignAdded(
const UKControllerPlugin::Controller::ActiveCallsign& callsign,
const Controller::ActiveCallsign& callsign,
bool userCallsign
) override;
void ActiveCallsignRemoved(
const UKControllerPlugin::Controller::ActiveCallsign& callsign,
const Controller::ActiveCallsign& callsign,
bool userCallsign
) override;
void CallsignsFlushed(void) override;
void TimedEventTrigger() override;

// The maximum distance from the airfield that an aircraft can be untracked
// to be considered for an altitude update.
Expand All @@ -98,14 +94,15 @@ namespace UKControllerPlugin {
const std::chrono::seconds minimumLoginTimeBeforeAssignment;

private:
void CheckAllFlightplansForAssignment();
bool MeetsAssignmentConditions(
Euroscope::EuroScopeCFlightPlanInterface& flightPlan,
Euroscope::EuroScopeCRadarTargetInterface& radarTarget
) const;

static bool MeetsForceAssignmentConditions(
UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface & flightplan,
UKControllerPlugin::Euroscope::EuroScopeCRadarTargetInterface & radarTarget
Euroscope::EuroScopeCFlightPlanInterface& flightplan,
Euroscope::EuroScopeCRadarTargetInterface& radarTarget
);

std::shared_ptr<Sid::StandardInstrumentDeparture> GetSidForFlight(
Expand All @@ -116,25 +113,19 @@ namespace UKControllerPlugin {
const Sid::SidCollection& sids;

// Used to find out the users callsign.
const UKControllerPlugin::Controller::ActiveCallsignCollection & activeCallsigns;
const Controller::ActiveCallsignCollection& activeCallsigns;

// Used to find out if the user owns a particular airfield.
const UKControllerPlugin::Ownership::AirfieldOwnershipManager & airfieldOwnership;

// So we can defer loading IAs on first login
UKControllerPlugin::TimedEvent::DeferredEventHandler & deferredEvents;
const Ownership::AirfieldOwnershipManager& airfieldOwnership;

// For checking how long we've been logged in
const UKControllerPlugin::Controller::Login & login;
const Controller::Login& login;

// Class for parsing SIDs and removing deprecation warnings.
const UKControllerPlugin::Airfield::NormaliseSid normalise;

// Stored flightplans
const UKControllerPlugin::Flightplan::StoredFlightplanCollection& storedFlightplans;
const Airfield::NormaliseSid normalise;

// So we can get flightplans after deferred events
UKControllerPlugin::Euroscope::EuroscopePluginLoopbackInterface & plugin;
Euroscope::EuroscopePluginLoopbackInterface& plugin;

// Has the user enabled automatic assignments
bool userAutomaticAssignmentsAllowed = true;
Expand Down
5 changes: 2 additions & 3 deletions src/initialaltitude/InitialAltitudeModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@ namespace UKControllerPlugin {
*persistence.activeCallsigns,
*persistence.airfieldOwnership,
*persistence.login,
*persistence.deferredHandlers,
*persistence.plugin,
*persistence.flightplans
*persistence.plugin
)
);

persistence.initialAltitudeEvents = initialAltitudeEventHandler;
persistence.userSettingHandlers->RegisterHandler(initialAltitudeEventHandler);
persistence.flightplanHandler->RegisterHandler(initialAltitudeEventHandler);
persistence.activeCallsigns->AddHandler(initialAltitudeEventHandler);
persistence.timedHandler->RegisterEvent(initialAltitudeEventHandler, 10);


TagFunction recycleFunction(
Expand Down

0 comments on commit e5bdab8

Please sign in to comment.