Browse Source

use the new interface to create the reports

Sven Czarnian 3 years ago
parent
commit
a8f2dba40e
2 changed files with 22 additions and 18 deletions
  1. 19 18
      src/PlugIn.cpp
  2. 3 0
      src/PlugIn.h

+ 19 - 18
src/PlugIn.cpp

@@ -131,11 +131,7 @@ aman::Aircraft* PlugIn::generateAircraftMessage(const EuroScopePlugIn::CRadarTar
     return retval;
 }
 
-void PlugIn::OnRadarTargetPositionUpdate(EuroScopePlugIn::CRadarTarget radarTarget) {
-    /* do nothing if the reporter is not initialized and ignore invalid targets */
-    if (false == AircraftReporter::instance().initialized() || false == radarTarget.IsValid())
-        return;
-
+void PlugIn::generateAircraftReportMessage(const EuroScopePlugIn::CRadarTarget& radarTarget, aman::AircraftReport* report) {
     auto flightPlan = radarTarget.GetCorrelatedFlightPlan();
 
     /* ignore invalid flightplans */
@@ -178,26 +174,25 @@ void PlugIn::OnRadarTargetPositionUpdate(EuroScopePlugIn::CRadarTarget radarTarg
     coordinate->set_longitude(radarTarget.GetPosition().GetPosition().m_Longitude);
 
     /* create the report */
-    aman::AircraftReport report;
     switch (this->ControllerMyself().GetFacility()) {
     case 1:
     case 6:
-        report.set_reportedby(aman::AircraftReport::CENTER);
+        report->set_reportedby(aman::AircraftReport::CENTER);
         break;
     case 2:
-        report.set_reportedby(aman::AircraftReport::DELIVERY);
+        report->set_reportedby(aman::AircraftReport::DELIVERY);
         break;
     case 3:
-        report.set_reportedby(aman::AircraftReport::GROUND);
+        report->set_reportedby(aman::AircraftReport::GROUND);
         break;
     case 4:
-        report.set_reportedby(aman::AircraftReport::TOWER);
+        report->set_reportedby(aman::AircraftReport::TOWER);
         break;
     case 5:
-        report.set_reportedby(aman::AircraftReport::APPROACH);
+        report->set_reportedby(aman::AircraftReport::APPROACH);
         break;
     default:
-        report.set_reportedby(aman::AircraftReport::UNKNOWN);
+        report->set_reportedby(aman::AircraftReport::UNKNOWN);
         break;
     }
 
@@ -221,7 +216,7 @@ void PlugIn::OnRadarTargetPositionUpdate(EuroScopePlugIn::CRadarTarget radarTarg
                     if (1.0f >= flightPlan.GetExtractedRoute().GetPointPosition(i).DistanceTo(position)) {
                         iafPosition = flightPlan.GetExtractedRoute().GetPointPosition(i);
                         iafName = flightPlan.GetExtractedRoute().GetPointName(i);
-                        report.set_initialapproachfix(iafName);
+                        report->set_initialapproachfix(iafName);
                         break;
                     }
                 }
@@ -253,12 +248,18 @@ void PlugIn::OnRadarTargetPositionUpdate(EuroScopePlugIn::CRadarTarget radarTarg
         }
         if (0.01f >= std::abs(distanceToIaf))
             distanceToIaf = iafDistance;
-        report.set_distancetoiaf(static_cast<int>(std::round(distanceToIaf)));
+        report->set_distancetoiaf(static_cast<int>(std::round(distanceToIaf)));
     }
-    report.set_destination(std::string(destination));
-    report.set_allocated_aircraft(aircraft);
-    report.set_allocated_dynamics(dynamics);
-    report.set_allocated_position(coordinate);
+    report->set_destination(std::string(destination));
+    report->set_allocated_aircraft(aircraft);
+    report->set_allocated_dynamics(dynamics);
+    report->set_allocated_position(coordinate);
+
+    /* set the report time */
+    std::stringstream stream;
+    auto reportTime = std::chrono::utc_clock::now();
+    stream << std::format("{0:%Y%m%d%H%M%S}", reportTime);
+    report->set_reporttime(String::splitString(stream.str(), ".")[0]);
 
     /* send the report */
     if (false == BackendNotification::instance().send(update))

+ 3 - 0
src/PlugIn.h

@@ -17,7 +17,9 @@
 #include <aman/types/Communication.h>
 
 #pragma warning(push, 0)
+#include <protobuf/BaseTypes.pb.h>
 #include <protobuf/AircraftReport.pb.h>
+#include <protobuf/Communication.pb.h>
 #pragma warning(pop)
 
 #include "RadarScreen.h"
@@ -40,6 +42,7 @@ namespace aman {
         };
 
         aman::Aircraft* generateAircraftMessage(const EuroScopePlugIn::CRadarTarget& target);
+        void generateAircraftReportMessage(const EuroScopePlugIn::CRadarTarget& radarTarget, aman::AircraftReport* report);
 
         Communication                m_configuration;
         std::shared_ptr<RadarScreen> m_screen;