Browse Source

calculate the required values

Sven Czarnian 3 years ago
parent
commit
f4cef56164
1 changed files with 47 additions and 9 deletions
  1. 47 9
      src/PlugIn.cpp

+ 47 - 9
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 timeAtIAF = std::chrono::utc_clock::now();
-        timeAtIAF += std::chrono::minutes(flightPlan.GetExtractedRoute().GetPointDistanceInMinutes(lastIdx));
-
-        std::stringstream stream;
-        stream << std::format("{0:%y%m%d%H%M}", timeAtIAF);
-        report.set_timeatiaf(stream.str());
-
-        report.set_initialapproachfix(std::string(flightPlan.GetExtractedRoute().GetPointName(lastIdx)));
+        auto iafPosition = flightPlan.GetExtractedRoute().GetPointPosition(lastIdx);
+        auto iafName = flightPlan.GetExtractedRoute().GetPointName(lastIdx);
+        auto iafDistance = currentPosition.DistanceTo(iafPosition);
+
+        /* 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);
+
+            /*
+             * 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;
+
+            distanceToIaf += distance;
+            lastDistance = distance;
+        }
+        if (0.0f == distanceToIaf)
+            distanceToIaf = iafDistance;
+        report.set_distancetoiaf(static_cast<int>(std::round(distanceToIaf)));
+
+        report.set_initialapproachfix(std::string(iafName));
     }
     report.set_destination(std::string(destination));
     report.set_allocated_aircraft(aircraft);