fix the code to find the correct arrival route
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
#include <aman/com/AircraftScheduler.h>
|
#include <aman/com/AircraftScheduler.h>
|
||||||
#include <aman/config/CommunicationFileFormat.h>
|
#include <aman/config/CommunicationFileFormat.h>
|
||||||
#include <aman/config/IdentifierFileFormat.h>
|
#include <aman/config/IdentifierFileFormat.h>
|
||||||
|
#include <aman/helper/String.h>
|
||||||
|
|
||||||
#include "com/ZmqContext.h"
|
#include "com/ZmqContext.h"
|
||||||
#include "PlugIn.h"
|
#include "PlugIn.h"
|
||||||
@@ -199,33 +200,59 @@ void PlugIn::OnRadarTargetPositionUpdate(EuroScopePlugIn::CRadarTarget radarTarg
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (2 <= flightPlan.GetExtractedRoute().GetPointsNumber()) {
|
|
||||||
auto currentPosition = radarTarget.GetPosition().GetPosition();
|
auto currentPosition = radarTarget.GetPosition().GetPosition();
|
||||||
int lastIdx = flightPlan.GetExtractedRoute().GetPointsNumber() - 2;
|
EuroScopePlugIn::CPosition iafPosition;
|
||||||
auto iafPosition = flightPlan.GetExtractedRoute().GetPointPosition(lastIdx);
|
std::string iafName;
|
||||||
auto iafName = flightPlan.GetExtractedRoute().GetPointName(lastIdx);
|
|
||||||
|
for (auto element = this->SectorFileElementSelectFirst(EuroScopePlugIn::SECTOR_ELEMENT_STAR);
|
||||||
|
true == element.IsValid();
|
||||||
|
element = this->SectorFileElementSelectNext(element, EuroScopePlugIn::SECTOR_ELEMENT_STAR))
|
||||||
|
{
|
||||||
|
auto split = String::splitString(element.GetName(), " ");
|
||||||
|
|
||||||
|
/* find the correct star */
|
||||||
|
if (0 != split.size() && destination == split[0]) {
|
||||||
|
/* get the IAF */
|
||||||
|
EuroScopePlugIn::CPosition position;
|
||||||
|
if (true == element.GetPosition(&position, 0)) {
|
||||||
|
/* match the waypoints to get the name*/
|
||||||
|
for (int i = 0; i < flightPlan.GetExtractedRoute().GetPointsNumber(); ++i) {
|
||||||
|
if (1.0f >= flightPlan.GetExtractedRoute().GetPointPosition(i).DistanceTo(position)) {
|
||||||
|
iafPosition = flightPlan.GetExtractedRoute().GetPointPosition(i);
|
||||||
|
iafName = flightPlan.GetExtractedRoute().GetPointName(i);
|
||||||
|
report.set_initialapproachfix(iafName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 != iafName.length())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 != iafName.length()) {
|
||||||
auto iafDistance = currentPosition.DistanceTo(iafPosition);
|
auto iafDistance = currentPosition.DistanceTo(iafPosition);
|
||||||
|
|
||||||
/* calculate the distance to the IAF */
|
/* calculate the distance to the IAF */
|
||||||
double distanceToIaf = 0.0f, lastDistance = 100000.0f;
|
double distanceToIaf = 0.0f, lastIafHeading = 100000.0f;
|
||||||
for (int i = 0; i < flightPlan.GetPositionPredictions().GetPointsNumber(); ++i) {
|
for (int i = 1; i < flightPlan.GetPositionPredictions().GetPointsNumber(); ++i) {
|
||||||
double distance = flightPlan.GetPositionPredictions().GetPosition(i).DistanceTo(currentPosition);
|
double distance = flightPlan.GetPositionPredictions().GetPosition(i).DistanceTo(currentPosition);
|
||||||
|
double headingDelta = std::abs(radarTarget.GetPosition().GetReportedHeading() - flightPlan.GetPositionPredictions().GetPosition(i).DirectionTo(iafPosition));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 1. no direct way to IAF -> some direct given -> stop after lateral passing
|
* 1. no direct way to IAF -> some direct given -> stop after lateral passing
|
||||||
* 2. passed the IAF on a way to a direct
|
* 2. passed the IAF on a way to a direct
|
||||||
*/
|
*/
|
||||||
if (distance > lastDistance || iafDistance < distance)
|
if ((90.0 < headingDelta && 270.0 > headingDelta) || iafDistance < distance)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
distanceToIaf += distance;
|
distanceToIaf += distance;
|
||||||
lastDistance = distance;
|
currentPosition = flightPlan.GetPositionPredictions().GetPosition(i);
|
||||||
}
|
}
|
||||||
if (0.0f == distanceToIaf)
|
if (0.01f >= std::abs(distanceToIaf))
|
||||||
distanceToIaf = iafDistance;
|
distanceToIaf = iafDistance;
|
||||||
report.set_distancetoiaf(static_cast<int>(std::round(distanceToIaf)));
|
report.set_distancetoiaf(static_cast<int>(std::round(distanceToIaf)));
|
||||||
|
|
||||||
report.set_initialapproachfix(std::string(iafName));
|
|
||||||
}
|
}
|
||||||
report.set_destination(std::string(destination));
|
report.set_destination(std::string(destination));
|
||||||
report.set_allocated_aircraft(aircraft);
|
report.set_allocated_aircraft(aircraft);
|
||||||
|
|||||||
Reference in New Issue
Block a user