mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 01:05:34 +08:00
refs #246 refactored FSIPI(R) custom packet encode/decode into INetwork
This commit is contained in:
@@ -6,7 +6,6 @@
|
|||||||
#include "airspace_monitor.h"
|
#include "airspace_monitor.h"
|
||||||
#include "blackmisc/project.h"
|
#include "blackmisc/project.h"
|
||||||
#include "blackmisc/indexvariantmap.h"
|
#include "blackmisc/indexvariantmap.h"
|
||||||
#include "network_vatlib.h" // for createFsipiCustomPacketData
|
|
||||||
|
|
||||||
namespace BlackCore
|
namespace BlackCore
|
||||||
{
|
{
|
||||||
@@ -33,7 +32,7 @@ namespace BlackCore
|
|||||||
this->connect(this->m_network, &INetwork::aircraftPositionUpdate, this, &CAirspaceMonitor::aircraftUpdateReceived);
|
this->connect(this->m_network, &INetwork::aircraftPositionUpdate, this, &CAirspaceMonitor::aircraftUpdateReceived);
|
||||||
this->connect(this->m_network, &INetwork::frequencyReplyReceived, this, &CAirspaceMonitor::frequencyReceived);
|
this->connect(this->m_network, &INetwork::frequencyReplyReceived, this, &CAirspaceMonitor::frequencyReceived);
|
||||||
this->connect(this->m_network, &INetwork::capabilitiesReplyReceived, this, &CAirspaceMonitor::capabilitiesReplyReceived);
|
this->connect(this->m_network, &INetwork::capabilitiesReplyReceived, this, &CAirspaceMonitor::capabilitiesReplyReceived);
|
||||||
this->connect(this->m_network, &INetwork::customPacketReceived, this, &CAirspaceMonitor::customPacketReceived);
|
this->connect(this->m_network, &INetwork::fsipirCustomPacketReceived, this, &CAirspaceMonitor::fsipirCustomPacketReceived);
|
||||||
this->connect(this->m_network, &INetwork::serverReplyReceived, this, &CAirspaceMonitor::serverReplyReceived);
|
this->connect(this->m_network, &INetwork::serverReplyReceived, this, &CAirspaceMonitor::serverReplyReceived);
|
||||||
|
|
||||||
this->connect(this->m_vatsimBookingReader, &CVatsimBookingReader::dataRead, this, &CAirspaceMonitor::receivedBookings);
|
this->connect(this->m_vatsimBookingReader, &CVatsimBookingReader::dataRead, this, &CAirspaceMonitor::receivedBookings);
|
||||||
@@ -237,25 +236,20 @@ namespace BlackCore
|
|||||||
this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm);
|
this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAirspaceMonitor::customPacketReceived(const CCallsign &callsign, const QString &packet, const QStringList &data)
|
void CAirspaceMonitor::fsipirCustomPacketReceived(const CCallsign &callsign, const QString &, const QString &, const QString &, const QString &model)
|
||||||
{
|
{
|
||||||
if (callsign.isEmpty() || data.isEmpty()) return;
|
if (callsign.isEmpty() || model.isEmpty()) return;
|
||||||
if (packet.startsWith("FSIPIR", Qt::CaseInsensitive))
|
|
||||||
|
// Request of other client, I can get the other's model from that
|
||||||
|
CIndexVariantMap vm(CClient::IndexQueriedModelString, QVariant(model));
|
||||||
|
if (!this->m_otherClients.contains(&CClient::getCallsign, callsign))
|
||||||
{
|
{
|
||||||
// Request of other client, I can get the other's model from that
|
// with custom packets it can happen,
|
||||||
// FsInn response is usually my model
|
//the packet is received before any other packet
|
||||||
QString model = data.last();
|
this->m_otherClients.push_back(CClient(callsign));
|
||||||
if (model.isEmpty()) return;
|
|
||||||
CIndexVariantMap vm(CClient::IndexQueriedModelString, QVariant(model));
|
|
||||||
if (!this->m_otherClients.contains(&CClient::getCallsign, callsign))
|
|
||||||
{
|
|
||||||
// with custom packets it can happen,
|
|
||||||
//the packet is received before any other packet
|
|
||||||
this->m_otherClients.push_back(CClient(callsign));
|
|
||||||
}
|
|
||||||
this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm);
|
|
||||||
this->sendFsipiCustomPacket(callsign); // response
|
|
||||||
}
|
}
|
||||||
|
this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm);
|
||||||
|
this->sendFsipiCustomPacket(callsign); // response
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAirspaceMonitor::serverReplyReceived(const CCallsign &callsign, const QString &server)
|
void CAirspaceMonitor::serverReplyReceived(const CCallsign &callsign, const QString &server)
|
||||||
@@ -291,17 +285,19 @@ namespace BlackCore
|
|||||||
|
|
||||||
void CAirspaceMonitor::sendFsipiCustomPacket(const CCallsign &recipientCallsign) const
|
void CAirspaceMonitor::sendFsipiCustomPacket(const CCallsign &recipientCallsign) const
|
||||||
{
|
{
|
||||||
QStringList data = this->createFsipiCustomPacketData();
|
CAircraft me = this->m_ownAircraft;
|
||||||
this->m_network->sendCustomPacket(recipientCallsign.asString(), "FSIPI", data);
|
CAircraftIcao icao = me.getIcaoInfo();
|
||||||
|
QString modelString;
|
||||||
|
// FIXME (MS) simulator or ownaircraft context should send an ownAircraftModelChanged signal, so we wouldn't need to interrogate the simulator context here.
|
||||||
|
//if (this->getIContextSimulator())
|
||||||
|
//{
|
||||||
|
// if (this->getIContextSimulator()->isConnected()) modelString = this->getIContextSimulator()->getOwnAircraftModel().getQueriedModelString();
|
||||||
|
//}
|
||||||
|
if (modelString.isEmpty()) modelString = CProject::systemNameAndVersion();
|
||||||
|
this->m_network->sendFsipiCustomPacket(recipientCallsign, icao.getAirlineDesignator(), icao.getAircraftDesignator(), icao.getAircraftCombinedType(), modelString);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAirspaceMonitor::sendFsipirCustomPacket(const CCallsign &recipientCallsign) const
|
void CAirspaceMonitor::sendFsipirCustomPacket(const CCallsign &recipientCallsign) const
|
||||||
{
|
|
||||||
QStringList data = this->createFsipiCustomPacketData();
|
|
||||||
this->m_network->sendCustomPacket(recipientCallsign.asString(), "FSIPIR", data);
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList CAirspaceMonitor::createFsipiCustomPacketData() const
|
|
||||||
{
|
{
|
||||||
CAircraft me = this->m_ownAircraft;
|
CAircraft me = this->m_ownAircraft;
|
||||||
CAircraftIcao icao = me.getIcaoInfo();
|
CAircraftIcao icao = me.getIcaoInfo();
|
||||||
@@ -312,11 +308,7 @@ namespace BlackCore
|
|||||||
// if (this->getIContextSimulator()->isConnected()) modelString = this->getIContextSimulator()->getOwnAircraftModel().getQueriedModelString();
|
// if (this->getIContextSimulator()->isConnected()) modelString = this->getIContextSimulator()->getOwnAircraftModel().getQueriedModelString();
|
||||||
//}
|
//}
|
||||||
if (modelString.isEmpty()) modelString = CProject::systemNameAndVersion();
|
if (modelString.isEmpty()) modelString = CProject::systemNameAndVersion();
|
||||||
QStringList data = CNetworkVatlib::createFsipiCustomPacketData(
|
this->m_network->sendFsipirCustomPacket(recipientCallsign, icao.getAirlineDesignator(), icao.getAircraftDesignator(), icao.getAircraftCombinedType(), modelString);
|
||||||
"0", icao.getAirlineDesignator(), icao.getAircraftDesignator(),
|
|
||||||
"", "", "", "",
|
|
||||||
icao.getAircraftCombinedType(), modelString);
|
|
||||||
return data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAirspaceMonitor::receivedBookings(const CAtcStationList &bookedStations)
|
void CAirspaceMonitor::receivedBookings(const CAtcStationList &bookedStations)
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ namespace BlackCore
|
|||||||
private slots:
|
private slots:
|
||||||
void realNameReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &realname);
|
void realNameReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &realname);
|
||||||
void capabilitiesReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, quint32 flags);
|
void capabilitiesReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, quint32 flags);
|
||||||
void customPacketReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &packet, const QStringList &data);
|
void fsipirCustomPacketReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &, const QString &, const QString &, const QString &model);
|
||||||
void serverReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &server);
|
void serverReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &server);
|
||||||
void metarReceived(const QString &metarMessage);
|
void metarReceived(const QString &metarMessage);
|
||||||
void flightplanReceived(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CFlightPlan &flightPlan);
|
void flightplanReceived(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CFlightPlan &flightPlan);
|
||||||
|
|||||||
@@ -212,12 +212,41 @@ namespace BlackCore
|
|||||||
*/
|
*/
|
||||||
virtual void sendTextMessages(const BlackMisc::Network::CTextMessageList &messages) = 0;
|
virtual void sendTextMessages(const BlackMisc::Network::CTextMessageList &messages) = 0;
|
||||||
|
|
||||||
|
//! @}
|
||||||
|
////////////////////////////////////////////////////////////////
|
||||||
|
//! \name Custom packets
|
||||||
|
//! @{
|
||||||
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Send a custom packet.
|
* Send a custom packet.
|
||||||
* \pre Network must be connected when calling this function.
|
* \pre Network must be connected when calling this function.
|
||||||
|
* \deprecated As a short cut you can use this slot directly, but it is better to implement the encoding in INetwork and add a new signal.
|
||||||
*/
|
*/
|
||||||
virtual void sendCustomPacket(const BlackMisc::Aviation::CCallsign &callsign, const QString &packetId, const QStringList &data) = 0;
|
virtual void sendCustomPacket(const BlackMisc::Aviation::CCallsign &callsign, const QString &packetId, const QStringList &data) = 0;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Send an FSInn custom packet.
|
||||||
|
* \details FSIPI(R) queries
|
||||||
|
* <BLOCKQUOTE>
|
||||||
|
* index 0 .. 0/1 ???
|
||||||
|
* 1 .. MQT, GEC, DLH -> Airline ICAO, most of the time empty
|
||||||
|
* 2 .. AIRCRAFT ICAO "B747"
|
||||||
|
* 3 .. 10.64195
|
||||||
|
* 4 .. 1.06080:
|
||||||
|
* 5 .. 5825.00000
|
||||||
|
* 6 .. 4.DD89CCB6.EC9BB7D7
|
||||||
|
* 7 .. 3-letter combined L2J
|
||||||
|
* 8 .. Model string
|
||||||
|
* </BLOCKQUOTE>
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
virtual void sendFsipiCustomPacket(const BlackMisc::Aviation::CCallsign &callsign, const QString &airlineDesignator,
|
||||||
|
const QString &aircraftDesignator, const QString &combinedType, const QString &modelString) = 0;
|
||||||
|
virtual void sendFsipirCustomPacket(const BlackMisc::Aviation::CCallsign &callsign, const QString &airlineDesignator,
|
||||||
|
const QString &aircraftDesignator, const QString &combinedType, const QString &modelString) = 0;
|
||||||
|
//! @}
|
||||||
|
|
||||||
//! @}
|
//! @}
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
//! \name ATC slots
|
//! \name ATC slots
|
||||||
@@ -471,10 +500,23 @@ namespace BlackCore
|
|||||||
void textMessagesReceived(const BlackMisc::Network::CTextMessageList &messages);
|
void textMessagesReceived(const BlackMisc::Network::CTextMessageList &messages);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* We received a custom packet. It is the slot's responsibility to decode the data.
|
* We received a custom packet.
|
||||||
|
* \deprecated As a short cut you can use this signal directly, but it is better to implement the decoding in INetwork and add a new signal.
|
||||||
*/
|
*/
|
||||||
void customPacketReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &packetId, const QStringList &data);
|
void customPacketReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &packetId, const QStringList &data);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* We received an FSInn custom packet.
|
||||||
|
*/
|
||||||
|
void fsipiCustomPacketReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &airlineDesignator,
|
||||||
|
const QString &aircraftDesignator, const QString &combinedType, const QString &modelString);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* We received an FSInn custom response packet.
|
||||||
|
*/
|
||||||
|
void fsipirCustomPacketReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &airlineDesignator,
|
||||||
|
const QString &aircraftDesignator, const QString &combinedType, const QString &modelString);
|
||||||
|
|
||||||
//! @}
|
//! @}
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
//! \name Weather signals
|
//! \name Weather signals
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ namespace BlackCore
|
|||||||
m_fsdTextCodec(QTextCodec::codecForName("latin1"))
|
m_fsdTextCodec(QTextCodec::codecForName("latin1"))
|
||||||
{
|
{
|
||||||
connect(this, &CNetworkVatlib::terminate, this, &INetwork::terminateConnection, Qt::QueuedConnection);
|
connect(this, &CNetworkVatlib::terminate, this, &INetwork::terminateConnection, Qt::QueuedConnection);
|
||||||
|
connect(this, &INetwork::customPacketReceived, this, &CNetworkVatlib::customPacketDispatcher);
|
||||||
|
|
||||||
Q_ASSERT_X(m_fsdTextCodec, "CNetworkVatlib", "Missing default wire text encoding");
|
Q_ASSERT_X(m_fsdTextCodec, "CNetworkVatlib", "Missing default wire text encoding");
|
||||||
//TODO reinit m_fsdTextCodec from WireTextEncoding config setting if present
|
//TODO reinit m_fsdTextCodec from WireTextEncoding config setting if present
|
||||||
@@ -779,14 +780,18 @@ namespace BlackCore
|
|||||||
catch (...) { exceptionDispatcher(Q_FUNC_INFO); }
|
catch (...) { exceptionDispatcher(Q_FUNC_INFO); }
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList CNetworkVatlib::createFsipiCustomPacketData(const QString &unknown01, const QString &airlineIcao, const QString &aircraftIcao, const QString &magicNumber1, const QString &magicNumber2, const QString &magicNumber3, const QString &magicNumber4, const QString &combinedType, const QString &modelString)
|
void CNetworkVatlib::sendFsipiCustomPacket(const BlackMisc::Aviation::CCallsign &callsign,
|
||||||
|
const QString &airlineIcao, const QString &aircraftIcao, const QString &combinedType, const QString &modelString)
|
||||||
{
|
{
|
||||||
|
QStringList data { { "0" }, airlineIcao, aircraftIcao, { "" }, { "" }, { "" }, { "" }, combinedType, modelString };
|
||||||
|
sendCustomPacket(callsign, "FSIPI", data);
|
||||||
|
}
|
||||||
|
|
||||||
QStringList data;
|
void CNetworkVatlib::sendFsipirCustomPacket(const BlackMisc::Aviation::CCallsign &callsign,
|
||||||
data << unknown01 << airlineIcao << aircraftIcao
|
const QString &airlineIcao, const QString &aircraftIcao, const QString &combinedType, const QString &modelString)
|
||||||
<< magicNumber1 << magicNumber2 << magicNumber3 << magicNumber4
|
{
|
||||||
<< combinedType << modelString;
|
QStringList data { { "0" }, airlineIcao, aircraftIcao, { "" }, { "" }, { "" }, { "" }, combinedType, modelString };
|
||||||
return data;
|
sendCustomPacket(callsign, "FSIPIR", data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************** * * * * * * * * * * * * * * * * * * * ************************************/
|
/********************************** * * * * * * * * * * * * * * * * * * * ************************************/
|
||||||
@@ -913,6 +918,32 @@ namespace BlackCore
|
|||||||
emit cbvar_cast(cbvar)->customPacketReceived(cbvar_cast(cbvar)->fromFSD(callsign), cbvar_cast(cbvar)->fromFSD(packetId), cbvar_cast(cbvar)->fromFSD(data, dataSize));
|
emit cbvar_cast(cbvar)->customPacketReceived(cbvar_cast(cbvar)->fromFSD(callsign), cbvar_cast(cbvar)->fromFSD(packetId), cbvar_cast(cbvar)->fromFSD(data, dataSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CNetworkVatlib::customPacketDispatcher(const BlackMisc::Aviation::CCallsign &callsign, const QString &packetId, const QStringList &data)
|
||||||
|
{
|
||||||
|
if (packetId.compare("FSIPI", Qt::CaseInsensitive) == 0)
|
||||||
|
{
|
||||||
|
if (data.size() < 9)
|
||||||
|
{
|
||||||
|
qDebug() << "Malformed FSIPI packet";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
emit fsipiCustomPacketReceived(callsign, data[1], data[2], data[7], data[8]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (packetId.compare("FSIPIR", Qt::CaseInsensitive) == 0)
|
||||||
|
{
|
||||||
|
if (data.size() < 9)
|
||||||
|
{
|
||||||
|
qDebug() << "Malformed FSIPIR packet";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
emit fsipirCustomPacketReceived(callsign, data[1], data[2], data[7], data[8]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CNetworkVatlib::onMetarReceived(Cvatlib_Network *, const char *data, void *cbvar)
|
void CNetworkVatlib::onMetarReceived(Cvatlib_Network *, const char *data, void *cbvar)
|
||||||
{
|
{
|
||||||
emit cbvar_cast(cbvar)->metarReplyReceived(cbvar_cast(cbvar)->fromFSD(data));
|
emit cbvar_cast(cbvar)->metarReplyReceived(cbvar_cast(cbvar)->fromFSD(data));
|
||||||
|
|||||||
@@ -52,6 +52,10 @@ namespace BlackCore
|
|||||||
virtual void sendIpQuery() override;
|
virtual void sendIpQuery() override;
|
||||||
virtual void sendServerQuery(const BlackMisc::Aviation::CCallsign &callsign) override;
|
virtual void sendServerQuery(const BlackMisc::Aviation::CCallsign &callsign) override;
|
||||||
virtual void sendCustomPacket(const BlackMisc::Aviation::CCallsign &callsign, const QString &packetId, const QStringList &data) override;
|
virtual void sendCustomPacket(const BlackMisc::Aviation::CCallsign &callsign, const QString &packetId, const QStringList &data) override;
|
||||||
|
virtual void sendFsipiCustomPacket(const BlackMisc::Aviation::CCallsign &callsign, const QString &airlineDesignator,
|
||||||
|
const QString &aircraftDesignator, const QString &combinedType, const QString &modelString) override;
|
||||||
|
virtual void sendFsipirCustomPacket(const BlackMisc::Aviation::CCallsign &callsign, const QString &airlineDesignator,
|
||||||
|
const QString &aircraftDesignator, const QString &combinedType, const QString &modelString) override;
|
||||||
|
|
||||||
// Text message slots
|
// Text message slots
|
||||||
virtual void sendTextMessages(const BlackMisc::Network::CTextMessageList &messages) override;
|
virtual void sendTextMessages(const BlackMisc::Network::CTextMessageList &messages) override;
|
||||||
@@ -78,29 +82,6 @@ namespace BlackCore
|
|||||||
virtual void sendMetarQuery(const BlackMisc::Aviation::CAirportIcao &airportIcao) override;
|
virtual void sendMetarQuery(const BlackMisc::Aviation::CAirportIcao &airportIcao) override;
|
||||||
virtual void sendWeatherDataQuery(const BlackMisc::Aviation::CAirportIcao &airportIcao) override;
|
virtual void sendWeatherDataQuery(const BlackMisc::Aviation::CAirportIcao &airportIcao) override;
|
||||||
|
|
||||||
// some helper methods
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Create the data load for FSIPI(R) packets / FsInn
|
|
||||||
* \details FSIPI(R) queries
|
|
||||||
* <BLOCKQUOTE>
|
|
||||||
* index 0 .. 0/1 ???
|
|
||||||
* 1 .. MQT, GEC, DLH -> Airline ICAO, most of the time empty
|
|
||||||
* 2 .. AIRCRAFT ICAO "B747"
|
|
||||||
* 3 .. 10.64195
|
|
||||||
* 4 .. 1.06080:
|
|
||||||
* 5 .. 5825.00000
|
|
||||||
* 6 .. 4.DD89CCB6.EC9BB7D7
|
|
||||||
* 7 .. 3-letter combined L2J
|
|
||||||
* 8 .. Model string
|
|
||||||
* </BLOCKQUOTE>
|
|
||||||
* \remarks This helper here has more or less the function of documenting the packet,
|
|
||||||
* it is nothing but a little string concatenating
|
|
||||||
*/
|
|
||||||
static QStringList createFsipiCustomPacketData(const QString &unknown01, const QString &airlineDesignator, const QString &aircraftDesignator,
|
|
||||||
const QString &magicNumber1, const QString &magicNumber2, const QString &magicNumber3, const QString &magicNumber4,
|
|
||||||
const QString &combinedType, const QString &modelString);
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void replyToFrequencyQuery(const BlackMisc::Aviation::CCallsign &callsign);
|
void replyToFrequencyQuery(const BlackMisc::Aviation::CCallsign &callsign);
|
||||||
void replyToNameQuery(const BlackMisc::Aviation::CCallsign &callsign);
|
void replyToNameQuery(const BlackMisc::Aviation::CCallsign &callsign);
|
||||||
@@ -146,6 +127,7 @@ namespace BlackCore
|
|||||||
private slots:
|
private slots:
|
||||||
void process();
|
void process();
|
||||||
void update();
|
void update();
|
||||||
|
void customPacketDispatcher(const BlackMisc::Aviation::CCallsign &callsign, const QString &packetId, const QStringList &data);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void terminate(); //!< \private
|
void terminate(); //!< \private
|
||||||
|
|||||||
Reference in New Issue
Block a user