mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-04 17:30:12 +08:00
refs #146 added updating and reading of VATSIM data file , so name and cid are available almost immediately
This commit is contained in:
@@ -24,7 +24,7 @@ namespace BlackCore
|
|||||||
* Init this context
|
* Init this context
|
||||||
*/
|
*/
|
||||||
CContextNetwork::CContextNetwork(CCoreRuntime *runtime) :
|
CContextNetwork::CContextNetwork(CCoreRuntime *runtime) :
|
||||||
IContextNetwork(runtime), m_network(nullptr), m_bookingReader(nullptr), m_dataUpdateTimer(nullptr)
|
IContextNetwork(runtime), m_network(nullptr), m_vatsimBookingReader(nullptr), m_vatsimDataFileReader(nullptr), m_dataUpdateTimer(nullptr)
|
||||||
{
|
{
|
||||||
Q_ASSERT(this->getRuntime());
|
Q_ASSERT(this->getRuntime());
|
||||||
Q_ASSERT(this->getRuntime()->getIContextSettings());
|
Q_ASSERT(this->getRuntime()->getIContextSettings());
|
||||||
@@ -35,17 +35,24 @@ namespace BlackCore
|
|||||||
// 2. Init own aircraft
|
// 2. Init own aircraft
|
||||||
this->initOwnAircraft();
|
this->initOwnAircraft();
|
||||||
|
|
||||||
// 3a. Init VATSIM bookings
|
// 3. Init VATSIM bookings
|
||||||
this->m_bookingReader = new CVatsimBookingReader(this->getRuntime()->getIContextSettings()->getNetworkSettings().getBookingServiceUrl(), this);
|
this->m_vatsimBookingReader = new CVatsimBookingReader(this->getRuntime()->getIContextSettings()->getNetworkSettings().getBookingServiceUrl(), this);
|
||||||
this->connect(this->m_bookingReader, &CVatsimBookingReader::bookingsRead, this, &CContextNetwork::psReceivedBookings);
|
this->connect(this->m_vatsimBookingReader, &CVatsimBookingReader::dataRead, this, &CContextNetwork::psReceivedBookings);
|
||||||
this->m_bookingReader->setInterval(10 * 1000); // first read
|
this->m_vatsimBookingReader->setInterval(10 * 1000); // first read
|
||||||
|
|
||||||
// 3b. Update timer for data
|
// 4. VATSIM data file
|
||||||
|
QStringList dataFileUrls;
|
||||||
|
dataFileUrls << "http://info.vroute.net/vatsim-data.txt";
|
||||||
|
this->m_vatsimDataFileReader = new CVatsimDataFileReader(dataFileUrls, this);
|
||||||
|
this->connect(this->m_vatsimDataFileReader, &CVatsimDataFileReader::dataRead, this, &CContextNetwork::psDataFileRead);
|
||||||
|
this->m_vatsimDataFileReader->setInterval(5 * 1000); // first read
|
||||||
|
|
||||||
|
// 5. Update timer for data
|
||||||
this->m_dataUpdateTimer = new QTimer(this);
|
this->m_dataUpdateTimer = new QTimer(this);
|
||||||
this->connect(this->m_dataUpdateTimer, &QTimer::timeout, this, &CContextNetwork::requestDataUpdates);
|
this->connect(this->m_dataUpdateTimer, &QTimer::timeout, this, &CContextNetwork::requestDataUpdates);
|
||||||
this->m_dataUpdateTimer->start(30 * 1000);
|
this->m_dataUpdateTimer->start(30 * 1000);
|
||||||
|
|
||||||
// 4. connect signals and slots
|
// 6. connect signals and slots
|
||||||
this->connect(this->m_network, &INetwork::connectionStatusChanged, this, &CContextNetwork::psFsdConnectionStatusChanged);
|
this->connect(this->m_network, &INetwork::connectionStatusChanged, this, &CContextNetwork::psFsdConnectionStatusChanged);
|
||||||
this->connect(this->m_network, &INetwork::atcPositionUpdate, this, &CContextNetwork::psFsdAtcPositionUpdate);
|
this->connect(this->m_network, &INetwork::atcPositionUpdate, this, &CContextNetwork::psFsdAtcPositionUpdate);
|
||||||
this->connect(this->m_network, &INetwork::atisReplyReceived, this, &CContextNetwork::psFsdAtisQueryReceived);
|
this->connect(this->m_network, &INetwork::atisReplyReceived, this, &CContextNetwork::psFsdAtisQueryReceived);
|
||||||
@@ -291,4 +298,13 @@ namespace BlackCore
|
|||||||
this->m_aircraftsInRange.applyIf(&CAircraft::getCallsign, callsign, vm);
|
this->m_aircraftsInRange.applyIf(&CAircraft::getCallsign, callsign, vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Data file has been read
|
||||||
|
*/
|
||||||
|
void CContextNetwork::psDataFileRead()
|
||||||
|
{
|
||||||
|
const int interval = 60 * 1000;
|
||||||
|
if (this->m_vatsimDataFileReader->interval() < interval) this->m_vatsimDataFileReader->setInterval(interval);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include "blackcore/network_vatlib.h"
|
#include "blackcore/network_vatlib.h"
|
||||||
#include "blackcore/coreruntime.h"
|
#include "blackcore/coreruntime.h"
|
||||||
#include "blackcore/vatsimbookingreader.h"
|
#include "blackcore/vatsimbookingreader.h"
|
||||||
|
#include "blackcore/vatsimdatafilereader.h"
|
||||||
#include "blackcore/context_network_interface.h"
|
#include "blackcore/context_network_interface.h"
|
||||||
#include "blackcore/context_settings_interface.h"
|
#include "blackcore/context_settings_interface.h"
|
||||||
#include "blackmisc/avcallsignlist.h"
|
#include "blackmisc/avcallsignlist.h"
|
||||||
@@ -145,8 +146,9 @@ namespace BlackCore
|
|||||||
BlackMisc::Aviation::CAircraft m_ownAircraft;
|
BlackMisc::Aviation::CAircraft m_ownAircraft;
|
||||||
QMap<QString, BlackMisc::Aviation::CInformationMessage> m_metarCache /*!< Keep METARs for a while */;
|
QMap<QString, BlackMisc::Aviation::CInformationMessage> m_metarCache /*!< Keep METARs for a while */;
|
||||||
|
|
||||||
// for reading XML
|
// for reading XML and VATSIM data files
|
||||||
CVatsimBookingReader *m_bookingReader;
|
CVatsimBookingReader *m_vatsimBookingReader;
|
||||||
|
CVatsimDataFileReader *m_vatsimDataFileReader;
|
||||||
QTimer *m_dataUpdateTimer; //!< general updates such as ATIS, frequencies, see requestDataUpdates()
|
QTimer *m_dataUpdateTimer; //!< general updates such as ATIS, frequencies, see requestDataUpdates()
|
||||||
|
|
||||||
//! \brief Replace value by new values
|
//! \brief Replace value by new values
|
||||||
@@ -182,6 +184,9 @@ namespace BlackCore
|
|||||||
//! \brief ATC bookings received
|
//! \brief ATC bookings received
|
||||||
void psReceivedBookings(BlackMisc::Aviation::CAtcStationList bookedStations);
|
void psReceivedBookings(BlackMisc::Aviation::CAtcStationList bookedStations);
|
||||||
|
|
||||||
|
//! \brief Data file has been read
|
||||||
|
void psDataFileRead();
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Connection status changed?
|
* \brief Connection status changed?
|
||||||
* \param from old status
|
* \param from old status
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ namespace BlackCore
|
|||||||
aircraft.setSituation(situation);
|
aircraft.setSituation(situation);
|
||||||
aircraft.setTransponder(transponder);
|
aircraft.setTransponder(transponder);
|
||||||
aircraft.calculcateDistanceToPlane(this->m_ownAircraft.getPosition());
|
aircraft.calculcateDistanceToPlane(this->m_ownAircraft.getPosition());
|
||||||
|
this->m_vatsimDataFileReader->getAircrafts().updateFromVatsimDataFileAircraft(aircraft);
|
||||||
this->m_aircraftsInRange.push_back(aircraft);
|
this->m_aircraftsInRange.push_back(aircraft);
|
||||||
|
|
||||||
if (this->isConnected())
|
if (this->isConnected())
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ namespace BlackCore
|
|||||||
*/
|
*/
|
||||||
void CContextNetwork::readAtcBookingsFromSource()
|
void CContextNetwork::readAtcBookingsFromSource()
|
||||||
{
|
{
|
||||||
Q_ASSERT(this->m_bookingReader);
|
Q_ASSERT(this->m_vatsimBookingReader);
|
||||||
this->m_bookingReader->read();
|
this->m_vatsimBookingReader->read();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -40,11 +40,15 @@ namespace BlackCore
|
|||||||
void CContextNetwork::psReceivedBookings(CAtcStationList bookedStations)
|
void CContextNetwork::psReceivedBookings(CAtcStationList bookedStations)
|
||||||
{
|
{
|
||||||
const int interval = 60 * 1000;
|
const int interval = 60 * 1000;
|
||||||
if (this->m_bookingReader->interval() < interval) this->m_bookingReader->setInterval(interval);
|
if (this->m_vatsimBookingReader->interval() < interval) this->m_vatsimBookingReader->setInterval(interval);
|
||||||
this->m_atcStationsBooked.clear();
|
this->m_atcStationsBooked.clear();
|
||||||
foreach(CAtcStation bookedStation, bookedStations)
|
foreach(CAtcStation bookedStation, bookedStations)
|
||||||
{
|
{
|
||||||
|
// complete by VATSIM data file data
|
||||||
|
this->m_vatsimDataFileReader->getAtcStations().updateFromVatsimDataFileStation(bookedStation);
|
||||||
|
// exchange booking and online data
|
||||||
this->m_atcStationsOnline.mergeWithBooking(bookedStation);
|
this->m_atcStationsOnline.mergeWithBooking(bookedStation);
|
||||||
|
// into list
|
||||||
this->m_atcStationsBooked.push_back(bookedStation);
|
this->m_atcStationsBooked.push_back(bookedStation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -235,6 +239,7 @@ namespace BlackCore
|
|||||||
station.setPosition(position);
|
station.setPosition(position);
|
||||||
station.setOnline(true);
|
station.setOnline(true);
|
||||||
station.calculcateDistanceToPlane(this->m_ownAircraft.getPosition());
|
station.calculcateDistanceToPlane(this->m_ownAircraft.getPosition());
|
||||||
|
this->m_vatsimDataFileReader->getAtcStations().updateFromVatsimDataFileStation(station); // prefill
|
||||||
this->m_atcStationsOnline.push_back(station);
|
this->m_atcStationsOnline.push_back(station);
|
||||||
emit this->changedAtcStationsOnline();
|
emit this->changedAtcStationsOnline();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user