diff --git a/src/PlugIn.cpp b/src/PlugIn.cpp index 2b6ea35..3344fd6 100644 --- a/src/PlugIn.cpp +++ b/src/PlugIn.cpp @@ -177,17 +177,55 @@ void PlugIn::OnRadarTargetPositionUpdate(EuroScopePlugIn::CRadarTarget radarTarg /* create the report */ aman::AircraftReport report; + switch (this->ControllerMyself().GetFacility()) { + case 1: + case 6: + report.set_reportedby(aman::AircraftReport::CENTER); + break; + case 2: + report.set_reportedby(aman::AircraftReport::DELIVERY); + break; + case 3: + report.set_reportedby(aman::AircraftReport::GROUND); + break; + case 4: + report.set_reportedby(aman::AircraftReport::TOWER); + break; + case 5: + report.set_reportedby(aman::AircraftReport::APPROACH); + break; + default: + report.set_reportedby(aman::AircraftReport::UNKNOWN); + break; + } + if (2 <= flightPlan.GetExtractedRoute().GetPointsNumber()) { + auto currentPosition = radarTarget.GetPosition().GetPosition(); int lastIdx = flightPlan.GetExtractedRoute().GetPointsNumber() - 2; + auto iafPosition = flightPlan.GetExtractedRoute().GetPointPosition(lastIdx); + auto iafName = flightPlan.GetExtractedRoute().GetPointName(lastIdx); + auto iafDistance = currentPosition.DistanceTo(iafPosition); - auto timeAtIAF = std::chrono::utc_clock::now(); - timeAtIAF += std::chrono::minutes(flightPlan.GetExtractedRoute().GetPointDistanceInMinutes(lastIdx)); + /* calculate the distance to the IAF */ + double distanceToIaf = 0.0f, lastDistance = 100000.0f; + for (int i = 0; i < flightPlan.GetPositionPredictions().GetPointsNumber(); ++i) { + double distance = flightPlan.GetPositionPredictions().GetPosition(i).DistanceTo(currentPosition); - std::stringstream stream; - stream << std::format("{0:%y%m%d%H%M}", timeAtIAF); - report.set_timeatiaf(stream.str()); + /* + * 1. no direct way to IAF -> some direct given -> stop after lateral passing + * 2. passed the IAF on a way to a direct + */ + if (distance > lastDistance || iafDistance < distance) + break; - report.set_initialapproachfix(std::string(flightPlan.GetExtractedRoute().GetPointName(lastIdx))); + distanceToIaf += distance; + lastDistance = distance; + } + if (0.0f == distanceToIaf) + distanceToIaf = iafDistance; + report.set_distancetoiaf(static_cast(std::round(distanceToIaf))); + + report.set_initialapproachfix(std::string(iafName)); } report.set_destination(std::string(destination)); report.set_allocated_aircraft(aircraft);