send the reports every ten seconds
This commit is contained in:
@@ -34,7 +34,10 @@ PlugIn::PlugIn() :
|
|||||||
PLUGIN_VERSION,
|
PLUGIN_VERSION,
|
||||||
PLUGIN_DEVELOPER,
|
PLUGIN_DEVELOPER,
|
||||||
PLUGIN_COPYRIGHT),
|
PLUGIN_COPYRIGHT),
|
||||||
m_configuration() {
|
m_configuration(),
|
||||||
|
m_screen(),
|
||||||
|
m_updateQueueLock(),
|
||||||
|
m_updateQueue() {
|
||||||
GOOGLE_PROTOBUF_VERIFY_VERSION;
|
GOOGLE_PROTOBUF_VERIFY_VERSION;
|
||||||
|
|
||||||
this->DisplayUserMessage(PLUGIN_NAME, "INFO", (std::string("Loaded ") + PLUGIN_NAME + " " + PLUGIN_VERSION).c_str(), true, true, false, false, false);
|
this->DisplayUserMessage(PLUGIN_NAME, "INFO", (std::string("Loaded ") + PLUGIN_NAME + " " + PLUGIN_VERSION).c_str(), true, true, false, false, false);
|
||||||
@@ -201,8 +204,8 @@ void PlugIn::generateAircraftReportMessage(const EuroScopePlugIn::CRadarTarget&
|
|||||||
std::string iafName;
|
std::string iafName;
|
||||||
|
|
||||||
for (auto element = this->SectorFileElementSelectFirst(EuroScopePlugIn::SECTOR_ELEMENT_STAR);
|
for (auto element = this->SectorFileElementSelectFirst(EuroScopePlugIn::SECTOR_ELEMENT_STAR);
|
||||||
true == element.IsValid();
|
true == element.IsValid();
|
||||||
element = this->SectorFileElementSelectNext(element, EuroScopePlugIn::SECTOR_ELEMENT_STAR))
|
element = this->SectorFileElementSelectNext(element, EuroScopePlugIn::SECTOR_ELEMENT_STAR))
|
||||||
{
|
{
|
||||||
auto split = String::splitString(element.GetName(), " ");
|
auto split = String::splitString(element.GetName(), " ");
|
||||||
|
|
||||||
@@ -260,6 +263,34 @@ void PlugIn::generateAircraftReportMessage(const EuroScopePlugIn::CRadarTarget&
|
|||||||
auto reportTime = std::chrono::utc_clock::now();
|
auto reportTime = std::chrono::utc_clock::now();
|
||||||
stream << std::format("{0:%Y%m%d%H%M%S}", reportTime);
|
stream << std::format("{0:%Y%m%d%H%M%S}", reportTime);
|
||||||
report->set_reporttime(String::splitString(stream.str(), ".")[0]);
|
report->set_reporttime(String::splitString(stream.str(), ".")[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlugIn::OnRadarTargetPositionUpdate(EuroScopePlugIn::CRadarTarget radarTarget) {
|
||||||
|
/* do nothing if the reporter is not initialized and ignore invalid targets */
|
||||||
|
if (false == BackendNotification::instance().initialized() || false == radarTarget.IsValid())
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::lock_guard guard(this->m_updateQueueLock);
|
||||||
|
this->m_updateQueue.push_back(radarTarget.GetCallsign());
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlugIn::OnTimer(int counter) {
|
||||||
|
if (false == BackendNotification::instance().initialized() || 0 != (counter % 10))
|
||||||
|
return;
|
||||||
|
|
||||||
|
this->m_updateQueueLock.lock();
|
||||||
|
aman::AircraftUpdate update;
|
||||||
|
|
||||||
|
for (auto target = this->RadarTargetSelectFirst(); true == target.IsValid(); target = this->RadarTargetSelectNext(target)) {
|
||||||
|
auto it = std::find(this->m_updateQueue.cbegin(), this->m_updateQueue.cend(), target.GetCallsign());
|
||||||
|
if (this->m_updateQueue.cend() != it) {
|
||||||
|
auto report = update.add_reports();
|
||||||
|
this->generateAircraftReportMessage(target, report);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this->m_updateQueue.clear();
|
||||||
|
this->m_updateQueueLock.unlock();
|
||||||
|
|
||||||
/* send the report */
|
/* send the report */
|
||||||
if (false == BackendNotification::instance().send(update))
|
if (false == BackendNotification::instance().send(update))
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ namespace aman {
|
|||||||
|
|
||||||
Communication m_configuration;
|
Communication m_configuration;
|
||||||
std::shared_ptr<RadarScreen> m_screen;
|
std::shared_ptr<RadarScreen> m_screen;
|
||||||
|
std::mutex m_updateQueueLock;
|
||||||
|
std::list<std::string> m_updateQueue;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@@ -73,6 +75,11 @@ namespace aman {
|
|||||||
*/
|
*/
|
||||||
EuroScopePlugIn::CRadarScreen* OnRadarScreenCreated(const char* displayName, bool needsRadarContent, bool geoReferenced,
|
EuroScopePlugIn::CRadarScreen* OnRadarScreenCreated(const char* displayName, bool needsRadarContent, bool geoReferenced,
|
||||||
bool canBeSaved, bool canBeCreated) override;
|
bool canBeSaved, bool canBeCreated) override;
|
||||||
|
/**
|
||||||
|
* @brief Called every second
|
||||||
|
* @param[in] counter The counter that indicates the seconds
|
||||||
|
*/
|
||||||
|
void OnTimer(int counter) override;
|
||||||
/**
|
/**
|
||||||
* @brief Called as soon as a radar target position is updated
|
* @brief Called as soon as a radar target position is updated
|
||||||
* @param[in] radarTarget The updated radar target
|
* @param[in] radarTarget The updated radar target
|
||||||
|
|||||||
Reference in New Issue
Block a user