mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 19:05:31 +08:00
refs #395, improved synchronization of booked and online stations
* moved sync functionality into CAtcStation * consolidated function names
This commit is contained in:
committed by
Mathew Sutcliffe
parent
f7158f17f9
commit
79e2a7b805
@@ -30,7 +30,7 @@ namespace BlackCore
|
|||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
COwnAircraftAwareReadOnly(ownAircraftProvider),
|
COwnAircraftAwareReadOnly(ownAircraftProvider),
|
||||||
m_network(network), m_vatsimBookingReader(bookings), m_vatsimDataFileReader(dataFile),
|
m_network(network), m_vatsimBookingReader(bookings), m_vatsimDataFileReader(dataFile),
|
||||||
m_analyzer(new CAirspaceAnalyzer(network, this))
|
m_analyzer(new CAirspaceAnalyzer(ownAircraftProvider, this, network, this))
|
||||||
{
|
{
|
||||||
this->connect(this->m_network, &INetwork::atcPositionUpdate, this, &CAirspaceMonitor::ps_atcPositionUpdate);
|
this->connect(this->m_network, &INetwork::atcPositionUpdate, this, &CAirspaceMonitor::ps_atcPositionUpdate);
|
||||||
this->connect(this->m_network, &INetwork::atisReplyReceived, this, &CAirspaceMonitor::ps_atisReceived);
|
this->connect(this->m_network, &INetwork::atisReplyReceived, this, &CAirspaceMonitor::ps_atisReceived);
|
||||||
@@ -549,15 +549,19 @@ namespace BlackCore
|
|||||||
void CAirspaceMonitor::ps_receivedBookings(const CAtcStationList &bookedStations)
|
void CAirspaceMonitor::ps_receivedBookings(const CAtcStationList &bookedStations)
|
||||||
{
|
{
|
||||||
Q_ASSERT(BlackCore::isCurrentThreadCreatingThread(this));
|
Q_ASSERT(BlackCore::isCurrentThreadCreatingThread(this));
|
||||||
this->m_atcStationsBooked.clear();
|
if (bookedStations.isEmpty())
|
||||||
foreach(CAtcStation bookedStation, bookedStations)
|
{
|
||||||
|
this->m_atcStationsBooked.clear();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CAtcStationList newBookedStations(bookedStations); // modifyable copy
|
||||||
|
for (CAtcStation &bookedStation : newBookedStations)
|
||||||
{
|
{
|
||||||
// complete by VATSIM data file data
|
|
||||||
this->m_vatsimDataFileReader->getAtcStations().updateFromVatsimDataFileStation(bookedStation);
|
|
||||||
// exchange booking and online data, both sides are updated
|
// exchange booking and online data, both sides are updated
|
||||||
this->m_atcStationsOnline.mergeWithBooking(bookedStation);
|
this->m_atcStationsOnline.syncronizeWithBookedStation(bookedStation);
|
||||||
// into list
|
}
|
||||||
this->m_atcStationsBooked.push_back(bookedStation);
|
this->m_atcStationsBooked = newBookedStations;
|
||||||
}
|
}
|
||||||
emit this->changedAtcStationsBooked(); // all booked stations reloaded
|
emit this->changedAtcStationsBooked(); // all booked stations reloaded
|
||||||
}
|
}
|
||||||
@@ -614,17 +618,26 @@ namespace BlackCore
|
|||||||
CAtcStationList stationsWithCallsign = this->m_atcStationsOnline.findByCallsign(callsign);
|
CAtcStationList stationsWithCallsign = this->m_atcStationsOnline.findByCallsign(callsign);
|
||||||
if (stationsWithCallsign.isEmpty())
|
if (stationsWithCallsign.isEmpty())
|
||||||
{
|
{
|
||||||
// new station
|
// new station, init with data from data file
|
||||||
CAtcStation station;
|
CAtcStation station(this->m_vatsimDataFileReader->getAtcStationsForCallsign(callsign).frontOrDefault());
|
||||||
station.setCallsign(callsign);
|
station.setCallsign(callsign);
|
||||||
station.setRange(range);
|
station.setRange(range);
|
||||||
station.setFrequency(frequency);
|
station.setFrequency(frequency);
|
||||||
station.setPosition(position);
|
station.setPosition(position);
|
||||||
station.setOnline(true);
|
station.setOnline(true);
|
||||||
station.calculcateDistanceAndBearingToOwnAircraft(ownAircraft().getPosition());
|
station.calculcateDistanceAndBearingToOwnAircraft(ownAircraft().getPosition());
|
||||||
this->m_vatsimDataFileReader->getAtcStations().updateFromVatsimDataFileStation(station); // prefill
|
|
||||||
|
// sync with bookings
|
||||||
|
if (this->m_atcStationsBooked.containsCallsign(callsign))
|
||||||
|
{
|
||||||
|
CAtcStation bookedStation(this->m_atcStationsBooked.findFirstByCallsign(callsign));
|
||||||
|
station.syncronizeWithBookedStation(bookedStation);
|
||||||
|
this->m_atcStationsBooked.replaceIf(&CAtcStation::getCallsign, callsign, bookedStation);
|
||||||
|
}
|
||||||
|
|
||||||
this->m_atcStationsOnline.push_back(station);
|
this->m_atcStationsOnline.push_back(station);
|
||||||
|
|
||||||
|
// subsequent queries
|
||||||
if (this->m_network->isConnected())
|
if (this->m_network->isConnected())
|
||||||
{
|
{
|
||||||
emit this->m_network->sendRealNameQuery(callsign);
|
emit this->m_network->sendRealNameQuery(callsign);
|
||||||
@@ -633,7 +646,7 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
|
|
||||||
emit this->changedAtcStationsOnline();
|
emit this->changedAtcStationsOnline();
|
||||||
// Remark: this->changedAtcStationOnlineConnectionStatus(station, true);
|
// Remark: this->changedAtcStationOnlineConnectionStatus
|
||||||
// will be sent in psFsdAtisVoiceRoomReceived
|
// will be sent in psFsdAtisVoiceRoomReceived
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -229,14 +229,20 @@ namespace BlackCore
|
|||||||
private slots:
|
private slots:
|
||||||
//! Create aircraft in range, this is the only place where a new aircraft should be added
|
//! Create aircraft in range, this is the only place where a new aircraft should be added
|
||||||
void ps_aircraftUpdateReceived(const BlackMisc::Aviation::CAircraftSituation &situation, const BlackMisc::Aviation::CTransponder &transponder);
|
void ps_aircraftUpdateReceived(const BlackMisc::Aviation::CAircraftSituation &situation, const BlackMisc::Aviation::CTransponder &transponder);
|
||||||
void ps_aircraftInterimUpdateReceived(const BlackMisc::Aviation::CAircraftSituation &situation);
|
|
||||||
|
//! Create ATC station, this is the only place where an online ATC station should be added
|
||||||
|
void ps_atcPositionUpdate(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::PhysicalQuantities::CFrequency &frequency, const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::PhysicalQuantities::CLength &range);
|
||||||
|
|
||||||
|
//! Send the information if aircraft and(!) client are available
|
||||||
|
//! \note it can take some time to obtain all data for model matching, so function recursively calls itself if something is still missing (trial)
|
||||||
|
void ps_sendReadyForModelMatching(const BlackMisc::Aviation::CCallsign &callsign, int trial);
|
||||||
|
|
||||||
void ps_realNameReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &realname);
|
void ps_realNameReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &realname);
|
||||||
void ps_capabilitiesReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, quint32 flags);
|
void ps_capabilitiesReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, quint32 flags);
|
||||||
void ps_customFSinnPacketReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &p1, const QString &aircraftDesignator, const QString &combinedAircraftType, const QString &model);
|
void ps_customFSinnPacketReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &p1, const QString &aircraftDesignator, const QString &combinedAircraftType, const QString &model);
|
||||||
void ps_serverReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &server);
|
void ps_serverReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &server);
|
||||||
void ps_metarReceived(const QString &metarMessage);
|
void ps_metarReceived(const QString &metarMessage);
|
||||||
void ps_flightPlanReceived(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CFlightPlan &flightPlan);
|
void ps_flightPlanReceived(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CFlightPlan &flightPlan);
|
||||||
void ps_atcPositionUpdate(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::PhysicalQuantities::CFrequency &frequency, const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::PhysicalQuantities::CLength &range);
|
|
||||||
void ps_atcControllerDisconnected(const BlackMisc::Aviation::CCallsign &callsign);
|
void ps_atcControllerDisconnected(const BlackMisc::Aviation::CCallsign &callsign);
|
||||||
void ps_atisReceived(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CInformationMessage &atisMessage);
|
void ps_atisReceived(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CInformationMessage &atisMessage);
|
||||||
void ps_atisVoiceRoomReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &url);
|
void ps_atisVoiceRoomReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &url);
|
||||||
@@ -247,10 +253,7 @@ namespace BlackCore
|
|||||||
void ps_receivedBookings(const BlackMisc::Aviation::CAtcStationList &bookedStations);
|
void ps_receivedBookings(const BlackMisc::Aviation::CAtcStationList &bookedStations);
|
||||||
void ps_receivedDataFile();
|
void ps_receivedDataFile();
|
||||||
void ps_aircraftConfigReceived(const BlackMisc::Aviation::CCallsign &callsign, const QJsonObject &jsonObject, bool isFull);
|
void ps_aircraftConfigReceived(const BlackMisc::Aviation::CCallsign &callsign, const QJsonObject &jsonObject, bool isFull);
|
||||||
|
void ps_aircraftInterimUpdateReceived(const BlackMisc::Aviation::CAircraftSituation &situation);
|
||||||
//! Send the information if aircraft and(!) client are vailable
|
|
||||||
void ps_sendReadyForModelMatching(const BlackMisc::Aviation::CCallsign &callsign, int trial);
|
|
||||||
|
|
||||||
void ps_sendInterimPosition();
|
void ps_sendInterimPosition();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,17 @@ namespace BlackCore
|
|||||||
return this->m_atcStations;
|
return this->m_atcStations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CAtcStationList CVatsimDataFileReader::getAtcStationsForCallsign(const CCallsign &callsign) const
|
||||||
|
{
|
||||||
|
CCallsignSet cs({callsign});
|
||||||
|
return this->getAtcStationsForCallsigns(cs);
|
||||||
|
}
|
||||||
|
|
||||||
|
CAtcStationList CVatsimDataFileReader::getAtcStationsForCallsigns(const CCallsignSet &callsigns) const
|
||||||
|
{
|
||||||
|
return this->getAtcStations().findByCallsigns(callsigns);
|
||||||
|
}
|
||||||
|
|
||||||
CServerList CVatsimDataFileReader::getVoiceServers() const
|
CServerList CVatsimDataFileReader::getVoiceServers() const
|
||||||
{
|
{
|
||||||
QReadLocker rl(&this->m_lock);
|
QReadLocker rl(&this->m_lock);
|
||||||
@@ -64,8 +75,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
CUserList CVatsimDataFileReader::getPilotsForCallsign(const CCallsign &callsign)
|
CUserList CVatsimDataFileReader::getPilotsForCallsign(const CCallsign &callsign)
|
||||||
{
|
{
|
||||||
CCallsignSet callsigns;
|
CCallsignSet callsigns({callsign});
|
||||||
callsigns.push_back(callsign);
|
|
||||||
return this->getPilotsForCallsigns(callsigns);
|
return this->getPilotsForCallsigns(callsigns);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,16 +105,8 @@ namespace BlackCore
|
|||||||
|
|
||||||
CUserList CVatsimDataFileReader::getControllersForCallsign(const CCallsign &callsign)
|
CUserList CVatsimDataFileReader::getControllersForCallsign(const CCallsign &callsign)
|
||||||
{
|
{
|
||||||
CCallsignSet callsigns;
|
CCallsignSet cs({callsign});
|
||||||
callsigns.push_back(callsign);
|
return this->getControllersForCallsigns(cs);
|
||||||
return this->getControllersForCallsigns(callsigns);
|
|
||||||
}
|
|
||||||
|
|
||||||
CUserList CVatsimDataFileReader::getUsersForCallsign(const CCallsign &callsign)
|
|
||||||
{
|
|
||||||
CCallsignSet callsigns;
|
|
||||||
callsigns.push_back(callsign);
|
|
||||||
return this->getUsersForCallsigns(callsigns);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CUserList CVatsimDataFileReader::getControllersForCallsigns(const CCallsignSet &callsigns)
|
CUserList CVatsimDataFileReader::getControllersForCallsigns(const CCallsignSet &callsigns)
|
||||||
@@ -112,6 +114,12 @@ namespace BlackCore
|
|||||||
return this->getAtcStations().findByCallsigns(callsigns).transform(Predicates::MemberTransform(&CAtcStation::getController));
|
return this->getAtcStations().findByCallsigns(callsigns).transform(Predicates::MemberTransform(&CAtcStation::getController));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CUserList CVatsimDataFileReader::getUsersForCallsign(const CCallsign &callsign)
|
||||||
|
{
|
||||||
|
CCallsignSet callsigns({callsign});
|
||||||
|
return this->getUsersForCallsigns(callsigns);
|
||||||
|
}
|
||||||
|
|
||||||
CUserList CVatsimDataFileReader::getUsersForCallsigns(const CCallsignSet &callsigns)
|
CUserList CVatsimDataFileReader::getUsersForCallsigns(const CCallsignSet &callsigns)
|
||||||
{
|
{
|
||||||
CUserList users;
|
CUserList users;
|
||||||
|
|||||||
@@ -28,9 +28,7 @@
|
|||||||
|
|
||||||
namespace BlackCore
|
namespace BlackCore
|
||||||
{
|
{
|
||||||
/*!
|
//! Read bookings from VATSIM
|
||||||
* Read bookings from VATSIM
|
|
||||||
*/
|
|
||||||
class BLACKCORE_EXPORT CVatsimDataFileReader : public BlackMisc::CThreadedReader
|
class BLACKCORE_EXPORT CVatsimDataFileReader : public BlackMisc::CThreadedReader
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -39,14 +37,22 @@ namespace BlackCore
|
|||||||
//! Constructor
|
//! Constructor
|
||||||
explicit CVatsimDataFileReader(QObject *owner, const QStringList &urls);
|
explicit CVatsimDataFileReader(QObject *owner, const QStringList &urls);
|
||||||
|
|
||||||
//! Get aircrafts
|
//! Get aircraft
|
||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
BlackMisc::Aviation::CAircraftList getAircraft() const;
|
BlackMisc::Aviation::CAircraftList getAircraft() const;
|
||||||
|
|
||||||
//! Get aircrafts
|
//! Get ATC station
|
||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
BlackMisc::Aviation::CAtcStationList getAtcStations() const;
|
BlackMisc::Aviation::CAtcStationList getAtcStations() const;
|
||||||
|
|
||||||
|
//! Get ATC stations for callsign
|
||||||
|
//! \threadsafe
|
||||||
|
BlackMisc::Aviation::CAtcStationList getAtcStationsForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const;
|
||||||
|
|
||||||
|
//! Get ATC stations for callsigns
|
||||||
|
//! \threadsafe
|
||||||
|
BlackMisc::Aviation::CAtcStationList getAtcStationsForCallsigns(const BlackMisc::Aviation::CCallsignSet &callsigns) const;
|
||||||
|
|
||||||
//! Get all voice servers
|
//! Get all voice servers
|
||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
BlackMisc::Network::CServerList getVoiceServers() const;
|
BlackMisc::Network::CServerList getVoiceServers() const;
|
||||||
@@ -103,7 +109,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QNetworkAccessManager *m_networkManager = nullptr;
|
QNetworkAccessManager *m_networkManager = nullptr;
|
||||||
QStringList m_serviceUrls; /*!< URL of the service */
|
QStringList m_serviceUrls; //!< URL of the service
|
||||||
int m_currentUrlIndex;
|
int m_currentUrlIndex;
|
||||||
BlackMisc::Network::CServerList m_voiceServers;
|
BlackMisc::Network::CServerList m_voiceServers;
|
||||||
BlackMisc::Network::CServerList m_fsdServers;
|
BlackMisc::Network::CServerList m_fsdServers;
|
||||||
|
|||||||
@@ -180,12 +180,88 @@ namespace BlackMisc
|
|||||||
|
|
||||||
void CAtcStation::syncronizeControllerData(CAtcStation &otherStation)
|
void CAtcStation::syncronizeControllerData(CAtcStation &otherStation)
|
||||||
{
|
{
|
||||||
if (this->m_controller == otherStation.getController()) return;
|
if (this->m_controller == otherStation.getController()) { return; }
|
||||||
CUser otherController = otherStation.getController();
|
CUser otherController = otherStation.getController();
|
||||||
this->m_controller.syncronizeData(otherController);
|
this->m_controller.syncronizeData(otherController);
|
||||||
otherStation.setController(otherController);
|
otherStation.setController(otherController);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CAtcStation::syncronizeWithBookedStation(CAtcStation &bookedStation)
|
||||||
|
{
|
||||||
|
if (bookedStation.getCallsign() != this->getCallsign()) { return; }
|
||||||
|
|
||||||
|
// from online to booking
|
||||||
|
bookedStation.setOnline(true);
|
||||||
|
bookedStation.setFrequency(this->getFrequency());
|
||||||
|
|
||||||
|
// Logoff Zulu Time set?
|
||||||
|
// comes directly from the online controller and is most likely more accurate
|
||||||
|
if (!this->getBookedUntilUtc().isNull())
|
||||||
|
{
|
||||||
|
bookedStation.setBookedUntilUtc(this->getBookedUntilUtc());
|
||||||
|
}
|
||||||
|
|
||||||
|
// from booking to online
|
||||||
|
// booked now stations have valid data and need no update
|
||||||
|
if (!this->isBookedNow() && bookedStation.hasValidBookingTimes())
|
||||||
|
{
|
||||||
|
if (this->hasValidBookingTimes())
|
||||||
|
{
|
||||||
|
if (bookedStation.isBookedNow())
|
||||||
|
{
|
||||||
|
// can't get any better, we just copy from / to over
|
||||||
|
this->setBookedFromUntil(bookedStation);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// we already have some booking dates, we will verify those now
|
||||||
|
// and will set the most appropriate booking dates
|
||||||
|
CTime timeDiffBooking(bookedStation.bookedWhen());
|
||||||
|
CTime timeDiffOnline(this->bookedWhen()); // diff to now
|
||||||
|
if (timeDiffBooking.isNegativeWithEpsilonConsidered() && timeDiffOnline.isNegativeWithEpsilonConsidered())
|
||||||
|
{
|
||||||
|
// both in past
|
||||||
|
if (timeDiffBooking > timeDiffOnline)
|
||||||
|
{
|
||||||
|
this->setBookedFromUntil(bookedStation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (timeDiffBooking.isPositiveWithEpsilonConsidered() && timeDiffOnline.isPositiveWithEpsilonConsidered())
|
||||||
|
{
|
||||||
|
// both in future
|
||||||
|
if (timeDiffBooking < timeDiffOnline)
|
||||||
|
{
|
||||||
|
this->setBookedFromUntil(bookedStation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (timeDiffBooking.isPositiveWithEpsilonConsidered() && timeDiffOnline.isNegativeWithEpsilonConsidered())
|
||||||
|
{
|
||||||
|
// future booking is better than past booking
|
||||||
|
this->setBookedFromUntil(bookedStation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// no booking info so far, so we just copy over
|
||||||
|
this->setBookedFromUntil(bookedStation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// both ways
|
||||||
|
this->syncronizeControllerData(bookedStation);
|
||||||
|
if (this->hasValidDistance())
|
||||||
|
{
|
||||||
|
bookedStation.setDistanceToOwnAircraft(this->getDistanceToOwnAircraft());
|
||||||
|
bookedStation.setBearingToOwnAircraft(this->getBearingToOwnAircraft());
|
||||||
|
}
|
||||||
|
else if (bookedStation.hasValidDistance())
|
||||||
|
{
|
||||||
|
this->setDistanceToOwnAircraft(bookedStation.getDistanceToOwnAircraft());
|
||||||
|
this->setBearingToOwnAircraft(bookedStation.getBearingToOwnAircraft());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool CAtcStation::isInRange() const
|
bool CAtcStation::isInRange() const
|
||||||
{
|
{
|
||||||
if (m_range.isNull() || !hasValidDistance()) { return false; }
|
if (m_range.isNull() || !hasValidDistance()) { return false; }
|
||||||
@@ -206,10 +282,10 @@ namespace BlackMisc
|
|||||||
|
|
||||||
bool CAtcStation::isBookedNow() const
|
bool CAtcStation::isBookedNow() const
|
||||||
{
|
{
|
||||||
if (!this->hasValidBookingTimes()) return false;
|
if (!this->hasValidBookingTimes()) { return false; }
|
||||||
QDateTime now = QDateTime::currentDateTimeUtc();
|
QDateTime now = QDateTime::currentDateTimeUtc();
|
||||||
if (this->m_bookedFromUtc > now) return false;
|
if (this->m_bookedFromUtc > now) { return false; }
|
||||||
if (now > this->m_bookedUntilUtc) return false;
|
if (now > this->m_bookedUntilUtc) { return false; }
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -134,9 +134,15 @@ namespace BlackMisc
|
|||||||
void setPosition(const BlackMisc::Geo::CCoordinateGeodetic &position) { this->m_position = position; }
|
void setPosition(const BlackMisc::Geo::CCoordinateGeodetic &position) { this->m_position = position; }
|
||||||
|
|
||||||
//! Syncronize controller data
|
//! Syncronize controller data
|
||||||
//! Updates two stations (namely a booked and online ATC station) with complementary data
|
//! Updates two stations (normally a booked and online ATC station) with complementary data
|
||||||
void syncronizeControllerData(CAtcStation &otherStation);
|
void syncronizeControllerData(CAtcStation &otherStation);
|
||||||
|
|
||||||
|
|
||||||
|
//! Syncronize station data
|
||||||
|
//! Updates the two stations (a booked and online ATC station) with complementary data
|
||||||
|
//! \pre this object is the online station, the passed station the booked station
|
||||||
|
void syncronizeWithBookedStation(CAtcStation &bookedStation);
|
||||||
|
|
||||||
//! Get the radius of the controller's area of visibility.
|
//! Get the radius of the controller's area of visibility.
|
||||||
const BlackMisc::PhysicalQuantities::CLength &getRange() const { return m_range; }
|
const BlackMisc::PhysicalQuantities::CLength &getRange() const { return m_range; }
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ namespace BlackMisc
|
|||||||
return this->findBy(Predicates::MemberValid(&CAtcStation::getController)).transform(Predicates::MemberTransform(&CAtcStation::getController));
|
return this->findBy(Predicates::MemberValid(&CAtcStation::getController)).transform(Predicates::MemberTransform(&CAtcStation::getController));
|
||||||
}
|
}
|
||||||
|
|
||||||
int CAtcStationList::mergeWithBooking(CAtcStation &bookedAtcStation)
|
int CAtcStationList::syncronizeWithBookedStation(CAtcStation &bookedAtcStation)
|
||||||
{
|
{
|
||||||
int c = 0;
|
int c = 0;
|
||||||
bookedAtcStation.setOnline(false); // reset
|
bookedAtcStation.setOnline(false); // reset
|
||||||
@@ -61,105 +61,16 @@ namespace BlackMisc
|
|||||||
|
|
||||||
for (auto i = this->begin(); i != this->end(); ++i)
|
for (auto i = this->begin(); i != this->end(); ++i)
|
||||||
{
|
{
|
||||||
CAtcStation onlineAtcStation = *i;
|
if (i->getCallsign() != bookedAtcStation.getCallsign()) { continue; }
|
||||||
if (onlineAtcStation.getCallsign() != bookedAtcStation.getCallsign()) continue;
|
i->syncronizeWithBookedStation(bookedAtcStation);
|
||||||
|
|
||||||
// from online to booking
|
|
||||||
bookedAtcStation.setOnline(true);
|
|
||||||
bookedAtcStation.setFrequency(onlineAtcStation.getFrequency());
|
|
||||||
|
|
||||||
// Logoff Zulu Time set?
|
|
||||||
// comes directly from the online controller and is most likely more accurate
|
|
||||||
if (!onlineAtcStation.getBookedUntilUtc().isNull())
|
|
||||||
bookedAtcStation.setBookedUntilUtc(onlineAtcStation.getBookedUntilUtc());
|
|
||||||
|
|
||||||
// from booking to online
|
|
||||||
if (!onlineAtcStation.isBookedNow() && bookedAtcStation.hasValidBookingTimes())
|
|
||||||
{
|
|
||||||
if (onlineAtcStation.hasValidBookingTimes())
|
|
||||||
{
|
|
||||||
if (bookedAtcStation.isBookedNow())
|
|
||||||
{
|
|
||||||
// can't get any better
|
|
||||||
onlineAtcStation.setBookedFromUntil(bookedAtcStation);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// we already have some booking dates
|
|
||||||
CTime timeDiffBooking = bookedAtcStation.bookedWhen();
|
|
||||||
CTime timeDiffOnline = onlineAtcStation.bookedWhen();
|
|
||||||
if (timeDiffBooking.isNegativeWithEpsilonConsidered() && timeDiffOnline.isNegativeWithEpsilonConsidered())
|
|
||||||
{
|
|
||||||
// both in past
|
|
||||||
if (timeDiffBooking > timeDiffOnline)
|
|
||||||
onlineAtcStation.setBookedFromUntil(bookedAtcStation);
|
|
||||||
}
|
|
||||||
else if (timeDiffBooking.isPositiveWithEpsilonConsidered() && timeDiffOnline.isPositiveWithEpsilonConsidered())
|
|
||||||
{
|
|
||||||
// both in future
|
|
||||||
if (timeDiffBooking < timeDiffOnline)
|
|
||||||
onlineAtcStation.setBookedFromUntil(bookedAtcStation);
|
|
||||||
}
|
|
||||||
else if (timeDiffBooking.isPositiveWithEpsilonConsidered() && timeDiffOnline.isNegativeWithEpsilonConsidered())
|
|
||||||
{
|
|
||||||
// future booking is better than past booking
|
|
||||||
onlineAtcStation.setBookedFromUntil(bookedAtcStation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// no booking info so far
|
|
||||||
onlineAtcStation.setBookedFromUntil(bookedAtcStation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// both ways
|
|
||||||
onlineAtcStation.syncronizeControllerData(bookedAtcStation);
|
|
||||||
if (onlineAtcStation.hasValidDistance())
|
|
||||||
{
|
|
||||||
bookedAtcStation.setDistanceToOwnAircraft(onlineAtcStation.getDistanceToOwnAircraft());
|
|
||||||
bookedAtcStation.setBearingToOwnAircraft(onlineAtcStation.getBearingToOwnAircraft());
|
|
||||||
}
|
|
||||||
else if (bookedAtcStation.hasValidDistance())
|
|
||||||
{
|
|
||||||
onlineAtcStation.setDistanceToOwnAircraft(bookedAtcStation.getDistanceToOwnAircraft());
|
|
||||||
onlineAtcStation.setBearingToOwnAircraft(bookedAtcStation.getBearingToOwnAircraft());
|
|
||||||
}
|
|
||||||
|
|
||||||
// update
|
|
||||||
*i = onlineAtcStation;
|
|
||||||
c++;
|
c++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// normally 1 expected, as I should find
|
// normally 1 expected, as I should find
|
||||||
// only one online station for this booking
|
// only one online station for this booking
|
||||||
Q_ASSERT(c == 0 || c == 1);
|
Q_ASSERT_X(c == 0 || c == 1, Q_FUNC_INFO, "Found >1 matching station");
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CAtcStationList::updateFromVatsimDataFileStation(CAtcStation &stationToBeUpdated) const
|
|
||||||
{
|
|
||||||
if (this->isEmpty()) return false;
|
|
||||||
if (stationToBeUpdated.hasValidRealName() && stationToBeUpdated.hasValidId() && stationToBeUpdated.hasValidFrequency()) return 0;
|
|
||||||
|
|
||||||
CAtcStation dataFileStation = this->findFirstByCallsign(stationToBeUpdated.getCallsign());
|
|
||||||
if (dataFileStation.getCallsign().isEmpty()) return false; // not found
|
|
||||||
|
|
||||||
if (!stationToBeUpdated.hasValidRealName() || !stationToBeUpdated.hasValidId())
|
|
||||||
{
|
|
||||||
CUser user = stationToBeUpdated.getController();
|
|
||||||
if (!stationToBeUpdated.hasValidRealName()) user.setRealName(dataFileStation.getControllerRealName());
|
|
||||||
if (!stationToBeUpdated.hasValidId()) user.setId(dataFileStation.getControllerId());
|
|
||||||
stationToBeUpdated.setController(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!stationToBeUpdated.hasValidFrequency())
|
|
||||||
{
|
|
||||||
stationToBeUpdated.setFrequency(dataFileStation.getFrequency());
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -50,14 +50,10 @@ namespace BlackMisc
|
|||||||
//! All controllers (with valid data)
|
//! All controllers (with valid data)
|
||||||
BlackMisc::Network::CUserList getControllers() const;
|
BlackMisc::Network::CUserList getControllers() const;
|
||||||
|
|
||||||
//! Merge with ATC station representing booking information.
|
//! Syncronize with ATC station representing booking information.
|
||||||
//! Both sides (booking, online station) will be updated.
|
//! Both sides (booking, online station) will be updated.
|
||||||
//! \remarks Can be used if the stored data in this list are online ATC stations
|
//! \pre Can be used only if the stored data in this list are online ATC stations
|
||||||
int mergeWithBooking(CAtcStation &bookedAtcStation);
|
int syncronizeWithBookedStation(CAtcStation &bookedAtcStation);
|
||||||
|
|
||||||
//! Merge with the data from the VATSIM data file
|
|
||||||
//! \remarks Can be used if the stored data in this list are VATSIM data file stations
|
|
||||||
bool updateFromVatsimDataFileStation(CAtcStation &stationToBeUpdated) const;
|
|
||||||
|
|
||||||
//! \copydoc CValueObject::toQVariant
|
//! \copydoc CValueObject::toQVariant
|
||||||
QVariant toQVariant() const { return QVariant::fromValue(*this); }
|
QVariant toQVariant() const { return QVariant::fromValue(*this); }
|
||||||
|
|||||||
Reference in New Issue
Block a user