mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +08:00
Ref T730, style
This commit is contained in:
committed by
Mat Sutcliffe
parent
cd58108bfe
commit
6a9109bf8f
@@ -16,29 +16,29 @@ namespace BlackCore
|
||||
{
|
||||
CCryptoDtoChannel::CCryptoDtoChannel(QString channelTag, const QByteArray &aeadReceiveKey, const QByteArray &aeadTransmitKey, int receiveSequenceHistorySize)
|
||||
{
|
||||
ChannelTag = channelTag;
|
||||
m_channelTag = channelTag;
|
||||
m_aeadReceiveKey = aeadReceiveKey;
|
||||
m_aeadTransmitKey = aeadTransmitKey;
|
||||
|
||||
receiveSequenceSizeMaxSize = receiveSequenceHistorySize;
|
||||
if (receiveSequenceSizeMaxSize < 1)
|
||||
receiveSequenceSizeMaxSize = 1;
|
||||
receiveSequenceHistory = new uint[receiveSequenceSizeMaxSize];
|
||||
receiveSequenceHistoryDepth = 0;
|
||||
m_receiveSequenceSizeMaxSize = receiveSequenceHistorySize;
|
||||
if (m_receiveSequenceSizeMaxSize < 1)
|
||||
m_receiveSequenceSizeMaxSize = 1;
|
||||
m_receiveSequenceHistory = new uint[m_receiveSequenceSizeMaxSize];
|
||||
m_receiveSequenceHistoryDepth = 0;
|
||||
}
|
||||
|
||||
CCryptoDtoChannel::CCryptoDtoChannel(CryptoDtoChannelConfigDto channelConfig, int receiveSequenceHistorySize)
|
||||
{
|
||||
ChannelTag = channelConfig.channelTag;
|
||||
m_channelTag = channelConfig.channelTag;
|
||||
m_aeadReceiveKey = channelConfig.aeadReceiveKey;
|
||||
m_aeadTransmitKey = channelConfig.aeadTransmitKey;
|
||||
hmacKey = channelConfig.hmacKey;
|
||||
m_hmacKey = channelConfig.hmacKey;
|
||||
|
||||
receiveSequenceSizeMaxSize = receiveSequenceHistorySize;
|
||||
if (receiveSequenceSizeMaxSize < 1)
|
||||
receiveSequenceSizeMaxSize = 1;
|
||||
receiveSequenceHistory = new uint[receiveSequenceSizeMaxSize];
|
||||
receiveSequenceHistoryDepth = 0;
|
||||
m_receiveSequenceSizeMaxSize = receiveSequenceHistorySize;
|
||||
if (m_receiveSequenceSizeMaxSize < 1)
|
||||
m_receiveSequenceSizeMaxSize = 1;
|
||||
m_receiveSequenceHistory = new uint[m_receiveSequenceSizeMaxSize];
|
||||
m_receiveSequenceHistoryDepth = 0;
|
||||
}
|
||||
|
||||
QByteArray CCryptoDtoChannel::getTransmitKey(CryptoDtoMode mode)
|
||||
@@ -56,9 +56,9 @@ namespace BlackCore
|
||||
|
||||
QByteArray CCryptoDtoChannel::getTransmitKey(CryptoDtoMode mode, uint &sequenceToSend)
|
||||
{
|
||||
sequenceToSend = transmitSequence;
|
||||
transmitSequence++;
|
||||
LastTransmitUtc = QDateTime::currentDateTimeUtc();
|
||||
sequenceToSend = m_transmitSequence;
|
||||
m_transmitSequence++;
|
||||
m_LastTransmitUtc = QDateTime::currentDateTimeUtc();
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
@@ -73,7 +73,7 @@ namespace BlackCore
|
||||
|
||||
QString CCryptoDtoChannel::getChannelTag() const
|
||||
{
|
||||
return ChannelTag;
|
||||
return m_channelTag;
|
||||
}
|
||||
|
||||
QByteArray CCryptoDtoChannel::getReceiveKey(CryptoDtoMode mode)
|
||||
@@ -97,27 +97,27 @@ namespace BlackCore
|
||||
return false;
|
||||
}
|
||||
|
||||
if (receiveSequenceHistoryDepth < receiveSequenceSizeMaxSize) //If the buffer has been filled...
|
||||
if (m_receiveSequenceHistoryDepth < m_receiveSequenceSizeMaxSize) //If the buffer has been filled...
|
||||
{
|
||||
receiveSequenceHistory[receiveSequenceHistoryDepth++] = sequenceReceived;
|
||||
m_receiveSequenceHistory[m_receiveSequenceHistoryDepth++] = sequenceReceived;
|
||||
}
|
||||
else
|
||||
{
|
||||
int minIndex;
|
||||
uint minValue = getMin(minIndex);
|
||||
if (sequenceReceived < minValue) { return false; } // Possible replay attack
|
||||
receiveSequenceHistory[minIndex] = sequenceReceived;
|
||||
m_receiveSequenceHistory[minIndex] = sequenceReceived;
|
||||
}
|
||||
|
||||
LastReceiveUtc = QDateTime::currentDateTimeUtc();
|
||||
m_lastReceiveUtc = QDateTime::currentDateTimeUtc();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CCryptoDtoChannel::contains(uint sequence)
|
||||
{
|
||||
for (int i = 0; i < receiveSequenceHistoryDepth; i++)
|
||||
for (int i = 0; i < m_receiveSequenceHistoryDepth; i++)
|
||||
{
|
||||
if (receiveSequenceHistory[i] == sequence)
|
||||
if (m_receiveSequenceHistory[i] == sequence)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -129,12 +129,12 @@ namespace BlackCore
|
||||
minIndex = -1;
|
||||
int index = -1;
|
||||
|
||||
for (int i = 0; i < receiveSequenceHistoryDepth; i++)
|
||||
for (int i = 0; i < m_receiveSequenceHistoryDepth; i++)
|
||||
{
|
||||
index++;
|
||||
if (receiveSequenceHistory[i] <= minValue)
|
||||
if (m_receiveSequenceHistory[i] <= minValue)
|
||||
{
|
||||
minValue = receiveSequenceHistory[i];
|
||||
minValue = m_receiveSequenceHistory[i];
|
||||
minIndex = index;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,32 +35,36 @@ namespace BlackCore
|
||||
//! Ctor
|
||||
CCryptoDtoChannel(CryptoDtoChannelConfigDto channelConfig, int receiveSequenceHistorySize = 10);
|
||||
|
||||
//! Transmit key @{
|
||||
QByteArray getTransmitKey(CryptoDtoMode mode);
|
||||
QByteArray getTransmitKey(CryptoDtoMode mode, uint &sequenceToSend);
|
||||
//! @}
|
||||
|
||||
//! Channel tag
|
||||
QString getChannelTag() const;
|
||||
|
||||
//! Receiver key
|
||||
QByteArray getReceiveKey(CryptoDtoMode mode);
|
||||
|
||||
//! check the received sequence
|
||||
bool checkReceivedSequence(uint sequenceReceived);
|
||||
|
||||
private:
|
||||
bool contains(uint sequence);
|
||||
uint getMin(int &minIndex);
|
||||
|
||||
|
||||
QByteArray m_aeadTransmitKey;
|
||||
uint transmitSequence = 0;
|
||||
|
||||
QByteArray m_aeadReceiveKey;
|
||||
|
||||
uint *receiveSequenceHistory;
|
||||
int receiveSequenceHistoryDepth;
|
||||
int receiveSequenceSizeMaxSize;
|
||||
uint m_transmitSequence = 0;
|
||||
uint *m_receiveSequenceHistory;
|
||||
int m_receiveSequenceHistoryDepth;
|
||||
int m_receiveSequenceSizeMaxSize;
|
||||
|
||||
QByteArray hmacKey;
|
||||
|
||||
QString ChannelTag;
|
||||
QDateTime LastTransmitUtc;
|
||||
QDateTime LastReceiveUtc;
|
||||
QByteArray m_hmacKey;
|
||||
QString m_channelTag;
|
||||
QDateTime m_LastTransmitUtc;
|
||||
QDateTime m_lastReceiveUtc;
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -75,24 +75,24 @@ namespace BlackCore
|
||||
this->setObjectName("CAirspaceMonitor");
|
||||
this->enableReverseLookupMessages(sApp->isDeveloperFlagSet() || CBuildConfig::isLocalDeveloperDebugBuild() ? RevLogEnabled : RevLogEnabledSimplified);
|
||||
|
||||
connect(m_fsdClient, &CFSDClient::atcDataUpdateReceived, this, &CAirspaceMonitor::onAtcPositionUpdate);
|
||||
connect(m_fsdClient, &CFSDClient::atcDataUpdateReceived, this, &CAirspaceMonitor::onAtcPositionUpdate);
|
||||
// FSD TODO
|
||||
connect(m_fsdClient, &CFSDClient::atisReplyReceived, this, &CAirspaceMonitor::onAtisReceived);
|
||||
connect(m_fsdClient, &CFSDClient::atisVoiceRoomReplyReceived, this, &CAirspaceMonitor::onAtisVoiceRoomReceived);
|
||||
connect(m_fsdClient, &CFSDClient::atisLogoffTimeReplyReceived, this, &CAirspaceMonitor::onAtisLogoffTimeReceived);
|
||||
connect(m_fsdClient, &CFSDClient::flightPlanReceived, this, &CAirspaceMonitor::onFlightPlanReceived);
|
||||
connect(m_fsdClient, &CFSDClient::realNameResponseReceived, this, &CAirspaceMonitor::onRealNameReplyReceived);
|
||||
connect(m_fsdClient, &CFSDClient::atisReplyReceived, this, &CAirspaceMonitor::onAtisReceived);
|
||||
connect(m_fsdClient, &CFSDClient::atisVoiceRoomReplyReceived, this, &CAirspaceMonitor::onAtisVoiceRoomReceived);
|
||||
connect(m_fsdClient, &CFSDClient::atisLogoffTimeReplyReceived, this, &CAirspaceMonitor::onAtisLogoffTimeReceived);
|
||||
connect(m_fsdClient, &CFSDClient::flightPlanReceived, this, &CAirspaceMonitor::onFlightPlanReceived);
|
||||
connect(m_fsdClient, &CFSDClient::realNameResponseReceived, this, &CAirspaceMonitor::onRealNameReplyReceived);
|
||||
connect(m_fsdClient, &CFSDClient::planeInformationReceived, this, &CAirspaceMonitor::onIcaoCodesReceived);
|
||||
connect(m_fsdClient, &CFSDClient::deletePilotReceived, this, &CAirspaceMonitor::onPilotDisconnected);
|
||||
connect(m_fsdClient, &CFSDClient::deleteAtcReceived, this, &CAirspaceMonitor::onAtcControllerDisconnected);
|
||||
connect(m_fsdClient, &CFSDClient::pilotDataUpdateReceived, this, &CAirspaceMonitor::onAircraftUpdateReceived);
|
||||
connect(m_fsdClient, &CFSDClient::pilotDataUpdateReceived, this, &CAirspaceMonitor::onAircraftUpdateReceived);
|
||||
connect(m_fsdClient, &CFSDClient::interimPilotDataUpdatedReceived, this, &CAirspaceMonitor::onAircraftInterimUpdateReceived);
|
||||
connect(m_fsdClient, &CFSDClient::com1FrequencyResponseReceived, this, &CAirspaceMonitor::onFrequencyReceived);
|
||||
connect(m_fsdClient, &CFSDClient::capabilityResponseReceived, this, &CAirspaceMonitor::onCapabilitiesReplyReceived);
|
||||
connect(m_fsdClient, &CFSDClient::planeInformationFsinnReceived, this, &CAirspaceMonitor::onCustomFSInnPacketReceived);
|
||||
connect(m_fsdClient, &CFSDClient::serverResponseReceived, this, &CAirspaceMonitor::onServerReplyReceived);
|
||||
connect(m_fsdClient, &CFSDClient::aircraftConfigReceived, this, &CAirspaceMonitor::onAircraftConfigReceived);
|
||||
connect(m_fsdClient, &CFSDClient::connectionStatusChanged, this, &CAirspaceMonitor::onConnectionStatusChanged);
|
||||
connect(m_fsdClient, &CFSDClient::com1FrequencyResponseReceived, this, &CAirspaceMonitor::onFrequencyReceived);
|
||||
connect(m_fsdClient, &CFSDClient::capabilityResponseReceived, this, &CAirspaceMonitor::onCapabilitiesReplyReceived);
|
||||
connect(m_fsdClient, &CFSDClient::planeInformationFsinnReceived, this, &CAirspaceMonitor::onCustomFSInnPacketReceived);
|
||||
connect(m_fsdClient, &CFSDClient::serverResponseReceived, this, &CAirspaceMonitor::onServerReplyReceived);
|
||||
connect(m_fsdClient, &CFSDClient::aircraftConfigReceived, this, &CAirspaceMonitor::onAircraftConfigReceived);
|
||||
connect(m_fsdClient, &CFSDClient::connectionStatusChanged, this, &CAirspaceMonitor::onConnectionStatusChanged);
|
||||
|
||||
// AutoConnection: this should also avoid race conditions by updating the bookings
|
||||
Q_ASSERT_X(sApp && sApp->getWebDataServices(), Q_FUNC_INFO, "Missing data reader");
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace BlackCore
|
||||
{
|
||||
BlackMisc::CLogMessage(static_cast<ClientQuery *>(nullptr)).debug(u"Wrong number of arguments.");
|
||||
return {};
|
||||
};
|
||||
}
|
||||
|
||||
QStringList payload;
|
||||
if (tokens.size() > 3) { payload = tokens.mid(3); }
|
||||
|
||||
@@ -78,14 +78,14 @@ namespace BlackCore
|
||||
}
|
||||
|
||||
CFSDClient::CFSDClient(IClientProvider *clientProvider,
|
||||
IOwnAircraftProvider *ownAircraftProvider,
|
||||
IRemoteAircraftProvider *remoteAircraftProvider,
|
||||
QObject *parent)
|
||||
: QObject(parent),
|
||||
CClientAware(clientProvider),
|
||||
COwnAircraftAware(ownAircraftProvider),
|
||||
CRemoteAircraftAware(remoteAircraftProvider),
|
||||
m_tokenBucket(10, CTime(5, CTimeUnit::s()), 1)
|
||||
IOwnAircraftProvider *ownAircraftProvider,
|
||||
IRemoteAircraftProvider *remoteAircraftProvider,
|
||||
QObject *parent)
|
||||
: QObject(parent),
|
||||
CClientAware(clientProvider),
|
||||
COwnAircraftAware(ownAircraftProvider),
|
||||
CRemoteAircraftAware(remoteAircraftProvider),
|
||||
m_tokenBucket(10, CTime(5, CTimeUnit::s()), 1)
|
||||
{
|
||||
initializeMessageTypes();
|
||||
connect(&m_socket, &QTcpSocket::readyRead, this, &CFSDClient::readDataFromSocket);
|
||||
@@ -308,15 +308,15 @@ namespace BlackCore
|
||||
if (m_connectionStatus.isDisconnected()) { return; }
|
||||
CSimulatedAircraft myAircraft(getOwnAircraft());
|
||||
InterimPilotDataUpdate interimPilotDataUpdate(m_ownCallsign.asString(),
|
||||
QString(),
|
||||
myAircraft.latitude().value(CAngleUnit::deg()),
|
||||
myAircraft.longitude().value(CAngleUnit::deg()),
|
||||
myAircraft.getAltitude().valueInteger(CLengthUnit::ft()),
|
||||
myAircraft.getGroundSpeed().valueInteger(CSpeedUnit::kts()),
|
||||
myAircraft.getPitch().value(CAngleUnit::deg()),
|
||||
myAircraft.getBank().value(CAngleUnit::deg()),
|
||||
myAircraft.getHeading().value(CAngleUnit::deg()),
|
||||
myAircraft.getParts().isOnGround());
|
||||
QString(),
|
||||
myAircraft.latitude().value(CAngleUnit::deg()),
|
||||
myAircraft.longitude().value(CAngleUnit::deg()),
|
||||
myAircraft.getAltitude().valueInteger(CLengthUnit::ft()),
|
||||
myAircraft.getGroundSpeed().valueInteger(CSpeedUnit::kts()),
|
||||
myAircraft.getPitch().value(CAngleUnit::deg()),
|
||||
myAircraft.getBank().value(CAngleUnit::deg()),
|
||||
myAircraft.getHeading().value(CAngleUnit::deg()),
|
||||
myAircraft.getParts().isOnGround());
|
||||
|
||||
for (const auto &receiver : as_const(m_interimPositionReceivers))
|
||||
{
|
||||
@@ -376,7 +376,7 @@ namespace BlackCore
|
||||
|
||||
void CFSDClient::sendClientQueryFlightPlan(const CCallsign callsign)
|
||||
{
|
||||
sendClientQuery(ClientQueryType::FP, {}, { callsign.toQString() } );
|
||||
sendClientQuery(ClientQueryType::FP, {}, { callsign.toQString() });
|
||||
}
|
||||
|
||||
void CFSDClient::sendClientQueryAircraftConfig(const CCallsign callsign)
|
||||
@@ -520,7 +520,7 @@ namespace BlackCore
|
||||
|
||||
void CFSDClient::sendTextMessage(const QString &receiver, const QString &message)
|
||||
{
|
||||
const CTextMessage msg (message, getOwnCallsign(), { receiver });
|
||||
const CTextMessage msg(message, getOwnCallsign(), { receiver });
|
||||
sendTextMessage(msg);
|
||||
}
|
||||
|
||||
@@ -598,10 +598,10 @@ namespace BlackCore
|
||||
if (modelString.isEmpty()) { modelString = noModelString(); }
|
||||
|
||||
PlaneInfoRequestFsinn planeInfoRequestFsinn(m_ownCallsign.asString(), callsign.toQString(),
|
||||
myAircraft.getAirlineIcaoCodeDesignator(),
|
||||
myAircraft.getAircraftIcaoCodeDesignator(),
|
||||
myAircraft.getAircraftIcaoCombinedType(),
|
||||
m_sendMModelString ? modelString : QString());
|
||||
myAircraft.getAirlineIcaoCodeDesignator(),
|
||||
myAircraft.getAircraftIcaoCodeDesignator(),
|
||||
myAircraft.getAircraftIcaoCombinedType(),
|
||||
m_sendMModelString ? modelString : QString());
|
||||
sendMessage(planeInfoRequestFsinn);
|
||||
this->increaseStatisticsValue(QStringLiteral("sendPlaneInfoRequestFsinn"));
|
||||
}
|
||||
@@ -621,10 +621,10 @@ namespace BlackCore
|
||||
if (modelString.isEmpty()) { modelString = noModelString(); }
|
||||
|
||||
PlaneInformationFsinn planeInformationFsinn(m_ownCallsign.asString(), callsign.toQString(),
|
||||
myAircraft.getAirlineIcaoCodeDesignator(),
|
||||
myAircraft.getAircraftIcaoCodeDesignator(),
|
||||
myAircraft.getAircraftIcaoCombinedType(),
|
||||
m_sendMModelString ? modelString : QString());
|
||||
myAircraft.getAirlineIcaoCodeDesignator(),
|
||||
myAircraft.getAircraftIcaoCodeDesignator(),
|
||||
myAircraft.getAircraftIcaoCombinedType(),
|
||||
m_sendMModelString ? modelString : QString());
|
||||
sendMessage(planeInformationFsinn);
|
||||
this->increaseStatisticsValue(QStringLiteral("sendPlaneInformationFsinn"));
|
||||
}
|
||||
@@ -740,9 +740,9 @@ namespace BlackCore
|
||||
vatsim_get_system_unique_id(sysuid);
|
||||
|
||||
userInfo += QString("CID=") % cid % " " % m_clientName % " IP=" % m_socket.localAddress().toString() %
|
||||
" SYS_UID=" % sysuid % " FSVER=" % m_hostApplication % " LT=" % QString::number(latitude) %
|
||||
" LO=" % QString::number(longitude) % " AL=" % QString::number(altitude) %
|
||||
" " % realName;
|
||||
" SYS_UID=" % sysuid % " FSVER=" % m_hostApplication % " LT=" % QString::number(latitude) %
|
||||
" LO=" % QString::number(longitude) % " AL=" % QString::number(altitude) %
|
||||
" " % realName;
|
||||
|
||||
TextMessage textMessage(m_ownCallsign.asString(), receiver, userInfo);
|
||||
sendMessage(textMessage);
|
||||
@@ -806,7 +806,7 @@ namespace BlackCore
|
||||
{
|
||||
m_messageTypeMapping["#AA"] = MessageType::AddAtc;
|
||||
m_messageTypeMapping["#AP"] = MessageType::AddPilot;
|
||||
m_messageTypeMapping["%"] = MessageType::AtcDataUpdate;
|
||||
m_messageTypeMapping["%"] = MessageType::AtcDataUpdate;
|
||||
m_messageTypeMapping["$ZC"] = MessageType::AuthChallenge;
|
||||
m_messageTypeMapping["$ZR"] = MessageType::AuthResponse;
|
||||
m_messageTypeMapping["$ID"] = MessageType::ClientIdentification;
|
||||
@@ -817,7 +817,7 @@ namespace BlackCore
|
||||
m_messageTypeMapping["$FP"] = MessageType::FlightPlan;
|
||||
m_messageTypeMapping["$DI"] = MessageType::FsdIdentification;
|
||||
m_messageTypeMapping["$!!"] = MessageType::KillRequest;
|
||||
m_messageTypeMapping["@"] = MessageType::PilotDataUpdate;
|
||||
m_messageTypeMapping["@"] = MessageType::PilotDataUpdate;
|
||||
m_messageTypeMapping["$PI"] = MessageType::Ping;
|
||||
m_messageTypeMapping["$PO"] = MessageType::Pong;
|
||||
m_messageTypeMapping["$ER"] = MessageType::ServerError;
|
||||
@@ -938,12 +938,12 @@ namespace BlackCore
|
||||
const CCallsign callsign(dataUpdate.sender(), CCallsign::Aircraft);
|
||||
|
||||
CAircraftSituation situation(
|
||||
callsign,
|
||||
CCoordinateGeodetic(dataUpdate.m_latitude, dataUpdate.m_longitude, dataUpdate.m_altitudeTrue),
|
||||
CHeading(dataUpdate.m_heading, CHeading::True, CAngleUnit::deg()),
|
||||
CAngle(dataUpdate.m_pitch, CAngleUnit::deg()),
|
||||
CAngle(dataUpdate.m_bank, CAngleUnit::deg()),
|
||||
CSpeed(dataUpdate.m_groundSpeed, CSpeedUnit::kts()));
|
||||
callsign,
|
||||
CCoordinateGeodetic(dataUpdate.m_latitude, dataUpdate.m_longitude, dataUpdate.m_altitudeTrue),
|
||||
CHeading(dataUpdate.m_heading, CHeading::True, CAngleUnit::deg()),
|
||||
CAngle(dataUpdate.m_pitch, CAngleUnit::deg()),
|
||||
CAngle(dataUpdate.m_bank, CAngleUnit::deg()),
|
||||
CSpeed(dataUpdate.m_groundSpeed, CSpeedUnit::kts()));
|
||||
situation.setPressureAltitude(CAltitude(dataUpdate.m_altitudePressure, CAltitude::MeanSeaLevel, CAltitude::PressureAltitude, CLengthUnit::ft()));
|
||||
situation.setOnGround(dataUpdate.m_onGround);
|
||||
|
||||
@@ -1328,12 +1328,12 @@ namespace BlackCore
|
||||
const CCallsign callsign(interimPilotDataUpdate.sender(), CCallsign::Aircraft);
|
||||
|
||||
CAircraftSituation situation(
|
||||
callsign,
|
||||
CCoordinateGeodetic(interimPilotDataUpdate.m_latitude, interimPilotDataUpdate.m_longitude, interimPilotDataUpdate.m_altitudeTrue),
|
||||
CHeading(interimPilotDataUpdate.m_heading, CHeading::True, CAngleUnit::deg()),
|
||||
CAngle(interimPilotDataUpdate.m_pitch, CAngleUnit::deg()),
|
||||
CAngle(interimPilotDataUpdate.m_bank, CAngleUnit::deg()),
|
||||
CSpeed(interimPilotDataUpdate.m_groundSpeed, CSpeedUnit::kts()));
|
||||
callsign,
|
||||
CCoordinateGeodetic(interimPilotDataUpdate.m_latitude, interimPilotDataUpdate.m_longitude, interimPilotDataUpdate.m_altitudeTrue),
|
||||
CHeading(interimPilotDataUpdate.m_heading, CHeading::True, CAngleUnit::deg()),
|
||||
CAngle(interimPilotDataUpdate.m_pitch, CAngleUnit::deg()),
|
||||
CAngle(interimPilotDataUpdate.m_bank, CAngleUnit::deg()),
|
||||
CSpeed(interimPilotDataUpdate.m_groundSpeed, CSpeedUnit::kts()));
|
||||
situation.setOnGround(interimPilotDataUpdate.m_onGround);
|
||||
|
||||
// Ref T297, default offset time
|
||||
|
||||
@@ -32,8 +32,10 @@ namespace BlackSound
|
||||
//! Noise generator
|
||||
CPinkNoiseGenerator(QObject *parent = nullptr) : ISampleProvider(parent) {}
|
||||
|
||||
//! Read samples
|
||||
virtual int readSamples(QVector<qint16> &samples, qint64 count) override;
|
||||
|
||||
//! Gain
|
||||
void setGain(double gain) { m_gain = gain; }
|
||||
|
||||
private:
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace BlackSound
|
||||
{
|
||||
CResourceSound::CResourceSound(const QString &audioFileName)
|
||||
{
|
||||
m_wavFile = new WavFile;
|
||||
m_wavFile = new CWavFile();
|
||||
m_wavFile->open(audioFileName);
|
||||
if (m_wavFile->fileFormat().sampleType() == QAudioFormat::Float)
|
||||
{
|
||||
@@ -30,10 +30,5 @@ namespace BlackSound
|
||||
m_samples = convertBytesTo16BitPCM(m_wavFile->audioData());
|
||||
}
|
||||
}
|
||||
|
||||
const QVector<qint16> &CResourceSound::audioData()
|
||||
{
|
||||
return m_samples;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -28,13 +28,14 @@ namespace BlackSound
|
||||
//! Sound of audio file
|
||||
CResourceSound(const QString &audioFileName);
|
||||
|
||||
const QVector<qint16> &audioData();
|
||||
//! Audio data
|
||||
const QVector<qint16> &audioData() const { return m_samples; }
|
||||
|
||||
private:
|
||||
Wav::WavFile *m_wavFile = nullptr;
|
||||
Wav::WavFile *m_wavFile = nullptr;
|
||||
QVector<qint16> m_samples;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -24,11 +24,11 @@ namespace BlackSound
|
||||
|
||||
const qint64 samplesToCopy = qMin(availableSamples, count);
|
||||
samples.clear();
|
||||
samples.fill(0, samplesToCopy);
|
||||
samples.fill(0, static_cast<int>(samplesToCopy));
|
||||
|
||||
for (int i = 0; i < samplesToCopy; i++)
|
||||
{
|
||||
m_tempBuffer[i] = m_resourceSound.audioData().at(m_position + i);
|
||||
m_tempBuffer[i] = m_resourceSound.audioData().at(static_cast<int>(m_position) + i);
|
||||
}
|
||||
|
||||
if (!qFuzzyCompare(m_gain, 1.0))
|
||||
@@ -54,5 +54,5 @@ namespace BlackSound
|
||||
|
||||
return static_cast<int>(samplesToCopy);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -26,21 +26,30 @@ namespace BlackSound
|
||||
//! Ctor
|
||||
CResourceSoundSampleProvider(const CResourceSound &resourceSound, QObject *parent = nullptr);
|
||||
|
||||
//! copydoc ISampleProvider::readSamples
|
||||
virtual int readSamples(QVector<qint16> &samples, qint64 count) override;
|
||||
|
||||
//! copydoc ISampleProvider::isFinished
|
||||
virtual bool isFinished() const override { return m_isFinished; }
|
||||
|
||||
//! Looping @{
|
||||
bool looping() const { return m_looping; }
|
||||
void setLooping(bool looping) { m_looping = looping; }
|
||||
// @}
|
||||
|
||||
//! Gain @{
|
||||
double gain() const { return m_gain; }
|
||||
void setGain(double gain) { m_gain = gain; }
|
||||
//! @}
|
||||
|
||||
//! Temp buffer @{
|
||||
QVector<qint16> getTempBuffer() const { return m_tempBuffer; }
|
||||
void setTempBuffer(const QVector<qint16> &value) { m_tempBuffer = value; }
|
||||
//! @}
|
||||
|
||||
private:
|
||||
double m_gain = 1.0;
|
||||
bool m_looping = false;
|
||||
double m_gain = 1.0;
|
||||
bool m_looping = false;
|
||||
|
||||
CResourceSound m_resourceSound;
|
||||
qint64 m_position = 0;
|
||||
@@ -48,7 +57,7 @@ namespace BlackSound
|
||||
QVector<qint16> m_tempBuffer;
|
||||
bool m_isFinished = false;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -21,20 +21,24 @@ namespace BlackSound
|
||||
class BLACKSOUND_EXPORT Samples
|
||||
{
|
||||
public:
|
||||
//! Singleton
|
||||
static Samples &instance();
|
||||
|
||||
//! Various samples (sounds) @{
|
||||
CResourceSound crackle() const;
|
||||
CResourceSound click() const;
|
||||
CResourceSound whiteNoise() const;
|
||||
//! @}
|
||||
|
||||
private:
|
||||
//! Ctor
|
||||
Samples();
|
||||
|
||||
CResourceSound m_crackle;
|
||||
CResourceSound m_click;
|
||||
CResourceSound m_whiteNoise;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
#endif // SAMPLES_H
|
||||
#endif // guard
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
#include <qendian.h>
|
||||
#include <QVector>
|
||||
#include <QDebug>
|
||||
// #include "utils.h"
|
||||
#include "wavfile.h"
|
||||
// #include "utils.h"
|
||||
|
||||
namespace BlackSound
|
||||
{
|
||||
@@ -50,29 +50,29 @@ namespace BlackSound
|
||||
WAVEHeader wave;
|
||||
};
|
||||
|
||||
WavFile::WavFile(QObject *parent) :
|
||||
CWavFile::CWavFile(QObject *parent) :
|
||||
QFile(parent),
|
||||
m_headerLength(0)
|
||||
{ }
|
||||
|
||||
bool WavFile::open(const QString &fileName)
|
||||
bool CWavFile::open(const QString &fileName)
|
||||
{
|
||||
close();
|
||||
setFileName(fileName);
|
||||
return QFile::open(QIODevice::ReadOnly) && readHeader();
|
||||
}
|
||||
|
||||
const QAudioFormat &WavFile::fileFormat() const
|
||||
const QAudioFormat &CWavFile::fileFormat() const
|
||||
{
|
||||
return m_fileFormat;
|
||||
}
|
||||
|
||||
qint64 WavFile::headerLength() const
|
||||
qint64 CWavFile::headerLength() const
|
||||
{
|
||||
return m_headerLength;
|
||||
}
|
||||
|
||||
bool WavFile::readHeader()
|
||||
bool CWavFile::readHeader()
|
||||
{
|
||||
seek(0);
|
||||
CombinedHeader header;
|
||||
@@ -132,15 +132,14 @@ namespace BlackSound
|
||||
|
||||
if (memcmp(&dataHeader.descriptor.id, "data", 4) == 0)
|
||||
{
|
||||
qint32 dataLength = qFromLittleEndian<qint32>(dataHeader.descriptor.size);
|
||||
const qint32 dataLength = qFromLittleEndian<qint32>(dataHeader.descriptor.size);
|
||||
m_audioData = read(dataLength);
|
||||
if (m_audioData.size() != dataLength)
|
||||
{
|
||||
return false;
|
||||
m_audioData.clear();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
} // ns
|
||||
|
||||
@@ -20,22 +20,30 @@ namespace BlackSound
|
||||
namespace Wav
|
||||
{
|
||||
//! * WAV file
|
||||
class WavFile : public QFile
|
||||
class CWavFile : public QFile
|
||||
{
|
||||
public:
|
||||
//! Ctor
|
||||
WavFile(QObject *parent = nullptr);
|
||||
CWavFile(QObject *parent = nullptr);
|
||||
|
||||
//! Standard open
|
||||
using QFile::open;
|
||||
|
||||
//! Open
|
||||
bool open(const QString &fileName);
|
||||
|
||||
//! Audio format
|
||||
const QAudioFormat &fileFormat() const;
|
||||
|
||||
//! Header length
|
||||
qint64 headerLength() const;
|
||||
QByteArray audioData() { return m_audioData; }
|
||||
|
||||
//! The audio data
|
||||
const QByteArray &audioData() const { return m_audioData; }
|
||||
|
||||
private:
|
||||
bool readHeader();
|
||||
|
||||
private:
|
||||
QAudioFormat m_fileFormat;
|
||||
qint64 m_headerLength;
|
||||
QByteArray m_audioData;
|
||||
|
||||
Reference in New Issue
Block a user