refs #146 added updating and reading of VATSIM data file , so name and cid are available almost immediately

This commit is contained in:
Klaus Basan
2014-02-25 01:15:27 +01:00
parent 724b424d60
commit 4c81a6f86d
4 changed files with 39 additions and 12 deletions

View File

@@ -24,7 +24,7 @@ namespace BlackCore
* Init this context
*/
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()->getIContextSettings());
@@ -35,17 +35,24 @@ namespace BlackCore
// 2. Init own aircraft
this->initOwnAircraft();
// 3a. Init VATSIM bookings
this->m_bookingReader = new CVatsimBookingReader(this->getRuntime()->getIContextSettings()->getNetworkSettings().getBookingServiceUrl(), this);
this->connect(this->m_bookingReader, &CVatsimBookingReader::bookingsRead, this, &CContextNetwork::psReceivedBookings);
this->m_bookingReader->setInterval(10 * 1000); // first read
// 3. Init VATSIM bookings
this->m_vatsimBookingReader = new CVatsimBookingReader(this->getRuntime()->getIContextSettings()->getNetworkSettings().getBookingServiceUrl(), this);
this->connect(this->m_vatsimBookingReader, &CVatsimBookingReader::dataRead, this, &CContextNetwork::psReceivedBookings);
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->connect(this->m_dataUpdateTimer, &QTimer::timeout, this, &CContextNetwork::requestDataUpdates);
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::atcPositionUpdate, this, &CContextNetwork::psFsdAtcPositionUpdate);
this->connect(this->m_network, &INetwork::atisReplyReceived, this, &CContextNetwork::psFsdAtisQueryReceived);
@@ -291,4 +298,13 @@ namespace BlackCore
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

View File

@@ -10,6 +10,7 @@
#include "blackcore/network_vatlib.h"
#include "blackcore/coreruntime.h"
#include "blackcore/vatsimbookingreader.h"
#include "blackcore/vatsimdatafilereader.h"
#include "blackcore/context_network_interface.h"
#include "blackcore/context_settings_interface.h"
#include "blackmisc/avcallsignlist.h"
@@ -145,8 +146,9 @@ namespace BlackCore
BlackMisc::Aviation::CAircraft m_ownAircraft;
QMap<QString, BlackMisc::Aviation::CInformationMessage> m_metarCache /*!< Keep METARs for a while */;
// for reading XML
CVatsimBookingReader *m_bookingReader;
// for reading XML and VATSIM data files
CVatsimBookingReader *m_vatsimBookingReader;
CVatsimDataFileReader *m_vatsimDataFileReader;
QTimer *m_dataUpdateTimer; //!< general updates such as ATIS, frequencies, see requestDataUpdates()
//! \brief Replace value by new values
@@ -182,6 +184,9 @@ namespace BlackCore
//! \brief ATC bookings received
void psReceivedBookings(BlackMisc::Aviation::CAtcStationList bookedStations);
//! \brief Data file has been read
void psDataFileRead();
/*!
* \brief Connection status changed?
* \param from old status

View File

@@ -63,6 +63,7 @@ namespace BlackCore
aircraft.setSituation(situation);
aircraft.setTransponder(transponder);
aircraft.calculcateDistanceToPlane(this->m_ownAircraft.getPosition());
this->m_vatsimDataFileReader->getAircrafts().updateFromVatsimDataFileAircraft(aircraft);
this->m_aircraftsInRange.push_back(aircraft);
if (this->isConnected())

View File

@@ -30,8 +30,8 @@ namespace BlackCore
*/
void CContextNetwork::readAtcBookingsFromSource()
{
Q_ASSERT(this->m_bookingReader);
this->m_bookingReader->read();
Q_ASSERT(this->m_vatsimBookingReader);
this->m_vatsimBookingReader->read();
}
/*
@@ -40,11 +40,15 @@ namespace BlackCore
void CContextNetwork::psReceivedBookings(CAtcStationList bookedStations)
{
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();
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);
// into list
this->m_atcStationsBooked.push_back(bookedStation);
}
}
@@ -235,6 +239,7 @@ namespace BlackCore
station.setPosition(position);
station.setOnline(true);
station.calculcateDistanceToPlane(this->m_ownAircraft.getPosition());
this->m_vatsimDataFileReader->getAtcStations().updateFromVatsimDataFileStation(station); // prefill
this->m_atcStationsOnline.push_back(station);
emit this->changedAtcStationsOnline();