use the new interface to create the reports

This commit is contained in:
Sven Czarnian
2021-11-13 23:02:55 +01:00
parent 2b4840d2af
commit a8f2dba40e
2 changed files with 22 additions and 18 deletions

View File

@@ -131,11 +131,7 @@ aman::Aircraft* PlugIn::generateAircraftMessage(const EuroScopePlugIn::CRadarTar
return retval; return retval;
} }
void PlugIn::OnRadarTargetPositionUpdate(EuroScopePlugIn::CRadarTarget radarTarget) { void PlugIn::generateAircraftReportMessage(const EuroScopePlugIn::CRadarTarget& radarTarget, aman::AircraftReport* report) {
/* do nothing if the reporter is not initialized and ignore invalid targets */
if (false == AircraftReporter::instance().initialized() || false == radarTarget.IsValid())
return;
auto flightPlan = radarTarget.GetCorrelatedFlightPlan(); auto flightPlan = radarTarget.GetCorrelatedFlightPlan();
/* ignore invalid flightplans */ /* ignore invalid flightplans */
@@ -178,26 +174,25 @@ void PlugIn::OnRadarTargetPositionUpdate(EuroScopePlugIn::CRadarTarget radarTarg
coordinate->set_longitude(radarTarget.GetPosition().GetPosition().m_Longitude); coordinate->set_longitude(radarTarget.GetPosition().GetPosition().m_Longitude);
/* create the report */ /* create the report */
aman::AircraftReport report;
switch (this->ControllerMyself().GetFacility()) { switch (this->ControllerMyself().GetFacility()) {
case 1: case 1:
case 6: case 6:
report.set_reportedby(aman::AircraftReport::CENTER); report->set_reportedby(aman::AircraftReport::CENTER);
break; break;
case 2: case 2:
report.set_reportedby(aman::AircraftReport::DELIVERY); report->set_reportedby(aman::AircraftReport::DELIVERY);
break; break;
case 3: case 3:
report.set_reportedby(aman::AircraftReport::GROUND); report->set_reportedby(aman::AircraftReport::GROUND);
break; break;
case 4: case 4:
report.set_reportedby(aman::AircraftReport::TOWER); report->set_reportedby(aman::AircraftReport::TOWER);
break; break;
case 5: case 5:
report.set_reportedby(aman::AircraftReport::APPROACH); report->set_reportedby(aman::AircraftReport::APPROACH);
break; break;
default: default:
report.set_reportedby(aman::AircraftReport::UNKNOWN); report->set_reportedby(aman::AircraftReport::UNKNOWN);
break; break;
} }
@@ -221,7 +216,7 @@ void PlugIn::OnRadarTargetPositionUpdate(EuroScopePlugIn::CRadarTarget radarTarg
if (1.0f >= flightPlan.GetExtractedRoute().GetPointPosition(i).DistanceTo(position)) { if (1.0f >= flightPlan.GetExtractedRoute().GetPointPosition(i).DistanceTo(position)) {
iafPosition = flightPlan.GetExtractedRoute().GetPointPosition(i); iafPosition = flightPlan.GetExtractedRoute().GetPointPosition(i);
iafName = flightPlan.GetExtractedRoute().GetPointName(i); iafName = flightPlan.GetExtractedRoute().GetPointName(i);
report.set_initialapproachfix(iafName); report->set_initialapproachfix(iafName);
break; break;
} }
} }
@@ -253,12 +248,18 @@ void PlugIn::OnRadarTargetPositionUpdate(EuroScopePlugIn::CRadarTarget radarTarg
} }
if (0.01f >= std::abs(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_destination(std::string(destination)); report->set_destination(std::string(destination));
report.set_allocated_aircraft(aircraft); report->set_allocated_aircraft(aircraft);
report.set_allocated_dynamics(dynamics); report->set_allocated_dynamics(dynamics);
report.set_allocated_position(coordinate); 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 */ /* send the report */
if (false == BackendNotification::instance().send(update)) if (false == BackendNotification::instance().send(update))

View File

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