refs #349, housekeeping

* formatting
* tweaks (such as changing to new log style),
* Doxygen
* int instead of qint
This commit is contained in:
Klaus Basan
2014-12-02 17:25:58 +01:00
parent 7361ec8963
commit 78e4900243
16 changed files with 120 additions and 94 deletions

View File

@@ -64,7 +64,7 @@ namespace BlackCore
// TODO: This would need to come from somewhere (mappings)
// Own callsign, plane ICAO status, model used
this->m_ownAircraft.setCallsign(CCallsign("BLACK"));
this->m_ownAircraft.setCallsign(CCallsign("SWIFT"));
this->m_ownAircraft.setIcaoInfo(CAircraftIcao("C172", "L1P", "GA", "GA", "0000ff"));
// voice rooms

View File

@@ -18,4 +18,4 @@ namespace BlackCore
{
emit simulatorStatusChanged(isConnected(), isRunning(), isPaused());
}
}
} // namespace

View File

@@ -127,9 +127,11 @@ namespace BlackGui
this->updateFrequencyDisplaysFromComSystems(com1, com2);
// update transponder
qint32 tc = transponder.getTransponderCode();
if (tc != static_cast<qint32>(this->ui->sbp_ComPanelTransponder->value()))
int tc = transponder.getTransponderCode();
if (tc != this->ui->sbp_ComPanelTransponder->value())
{
this->ui->sbp_ComPanelTransponder->setValue(tc);
}
this->ui->cbp_ComPanelTransponderMode->setSelectedTransponderMode(transponder.getTransponderMode());

View File

@@ -121,10 +121,10 @@ namespace BlackGui
//! \copydoc QWidget::paintEvent
virtual void paintEvent(QPaintEvent *event) override;
//! \copy QMainWindow::mouseMoveEvent
//! \copydoc QMainWindow::mouseMoveEvent
virtual void mouseMoveEvent(QMouseEvent *event) override { if (!handleMouseMoveEvent(event)) { QDockWidget::mouseMoveEvent(event); } ; }
//! \copy QMainWindow::mousePressEvent
//! \copydoc QMainWindow::mousePressEvent
virtual void mousePressEvent(QMouseEvent *event) override { if (!handleMousePressEvent(event)) { QDockWidget::mousePressEvent(event); } }
//! Contribute to menu

View File

@@ -116,7 +116,7 @@ namespace BlackMisc
QString getTransponderCodeAndModeFormatted() const;
//! Set transponder code
void setTransponderCode(qint32 transponderCode) { this->m_transponderCode = transponderCode; }
void setTransponderCode(int transponderCode) { this->m_transponderCode = transponderCode; }
//! Set transponder code
void setTransponderCode(const QString &transponderCode);

View File

@@ -81,7 +81,7 @@ namespace BlackSimPlugin
return situation;
}
MPPositionVelocity aircraftSituationtoFS9(const CAircraftSituation &oldSituation, const CAircraftSituation &newSituation, double updateInterval)
MPPositionVelocity aircraftSituationToFS9(const CAircraftSituation &oldSituation, const CAircraftSituation &newSituation, double updateInterval)
{
MPPositionVelocity positionVelocity;
@@ -137,7 +137,7 @@ namespace BlackSimPlugin
return positionVelocity;
}
MPPositionSlewMode aircraftSituationtoFS9(const CAircraftSituation &situation)
MPPositionSlewMode aircraftSituationToFS9(const CAircraftSituation &situation)
{
MPPositionSlewMode positionSlewMode;
@@ -208,7 +208,8 @@ namespace BlackSimPlugin
break;
}
BlackMisc::CLogMessage().error(errorMessage);
errorMessage = "DirectPlay: " + errorMessage;
BlackMisc::CLogMessage("swift.fs9.freefunctions").error(errorMessage);
return error;
}

View File

@@ -7,6 +7,8 @@
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKSIMPLUGIN_FREEFUNCTIONS_H
#define BLACKSIMPLUGIN_FREEFUNCTIONS_H
@@ -51,18 +53,17 @@ namespace BlackSimPlugin
BlackMisc::Aviation::CAircraftSituation aircraftSituationfromFS9(const MPPositionVelocity &positionVelocity);
//! Convert an aircraft situation to a FS9 struct
MPPositionVelocity aircraftSituationtoFS9(const BlackMisc::Aviation::CAircraftSituation &oldSituation,
MPPositionVelocity aircraftSituationToFS9(const BlackMisc::Aviation::CAircraftSituation &oldSituation,
const BlackMisc::Aviation::CAircraftSituation &newSituation,
double updateInterval);
//! Convert an aircraft situation to a FS9 struct
MPPositionSlewMode aircraftSituationtoFS9(const BlackMisc::Aviation::CAircraftSituation &situation);
MPPositionSlewMode aircraftSituationToFS9(const BlackMisc::Aviation::CAircraftSituation &situation);
//! Print the direct play error
HRESULT printDirectPlayError(HRESULT error);
}
}
#endif //BLACKSIMPLUGIN_FREEFUNCTIONS_H
#endif // guard

View File

@@ -10,6 +10,7 @@
#include "directplay_peer.h"
#include "multiplayer_packet_parser.h"
#include "blacksimplugin_freefunctions.h"
#include "blackmisc/logmessage.h"
#include <QDebug>
#include <QTimer>
#include <QFile>
@@ -17,6 +18,8 @@
#include <QScopedPointer>
#include <QMutexLocker>
using namespace BlackMisc;
namespace BlackSimPlugin
{
namespace Fs9
@@ -50,34 +53,34 @@ namespace BlackSimPlugin
{
case DPN_MSGID_CREATE_PLAYER:
{
DPNMSG_CREATE_PLAYER* pCreatePlayerMsg = static_cast<DPNMSG_CREATE_PLAYER*>(msgBuffer);
DPNMSG_CREATE_PLAYER *pCreatePlayerMsg = static_cast<DPNMSG_CREATE_PLAYER *>(msgBuffer);
HRESULT hr;
// Get the peer info and extract its name
DWORD dwSize = 0;
DPN_PLAYER_INFO* pdpPlayerInfo = nullptr;
DPN_PLAYER_INFO *pdpPlayerInfo = nullptr;
hr = DPNERR_CONNECTING;
// GetPeerInfo might return DPNERR_CONNECTING when connecting,
// so just keep calling it if it does
while( hr == DPNERR_CONNECTING )
hr = m_directPlayPeer->GetPeerInfo( pCreatePlayerMsg->dpnidPlayer, pdpPlayerInfo, &dwSize, 0 );
while (hr == DPNERR_CONNECTING)
hr = m_directPlayPeer->GetPeerInfo(pCreatePlayerMsg->dpnidPlayer, pdpPlayerInfo, &dwSize, 0);
if( hr == DPNERR_BUFFERTOOSMALL )
if (hr == DPNERR_BUFFERTOOSMALL)
{
QScopedArrayPointer<unsigned char> memPtr(new unsigned char[dwSize]);
pdpPlayerInfo = reinterpret_cast<DPN_PLAYER_INFO*>(memPtr.data());
if( pdpPlayerInfo == nullptr)
pdpPlayerInfo = reinterpret_cast<DPN_PLAYER_INFO *>(memPtr.data());
if (pdpPlayerInfo == nullptr)
{
break;
}
ZeroMemory( pdpPlayerInfo, dwSize );
ZeroMemory(pdpPlayerInfo, dwSize);
pdpPlayerInfo->dwSize = sizeof(DPN_PLAYER_INFO);
hr = m_directPlayPeer->GetPeerInfo( pCreatePlayerMsg->dpnidPlayer, pdpPlayerInfo, &dwSize, 0 );
if( SUCCEEDED(hr))
hr = m_directPlayPeer->GetPeerInfo(pCreatePlayerMsg->dpnidPlayer, pdpPlayerInfo, &dwSize, 0);
if (SUCCEEDED(hr))
{
if (pdpPlayerInfo->dwPlayerFlags & DPNPLAYER_LOCAL)
m_playerLocal = pCreatePlayerMsg->dpnidPlayer;
@@ -103,7 +106,7 @@ namespace BlackSimPlugin
// Proceeed only, if the sender is our local player
if (pReceiveMsg->dpnidSender == m_playerUser)
{
QByteArray messageData = QByteArray((char*)pReceiveMsg->pReceiveData, pReceiveMsg->dwReceiveDataSize);
QByteArray messageData = QByteArray((char *)pReceiveMsg->pReceiveData, pReceiveMsg->dwReceiveDataSize);
emit customPacketReceived(messageData);
}
@@ -117,12 +120,12 @@ namespace BlackSimPlugin
QMutexLocker locker(&m_mutexHostList);
auto iterator = std::find_if(m_hostNodeList.begin(), m_hostNodeList.end(), [&] (const CHostNode &hostNode)
auto iterator = std::find_if(m_hostNodeList.begin(), m_hostNodeList.end(), [&](const CHostNode & hostNode)
{
return applicationDescription->guidInstance == hostNode.getApplicationDesc().guidInstance;
});
if(iterator == m_hostNodeList.end())
if (iterator == m_hostNodeList.end())
{
// This host session is not in the list then so insert it.
@@ -130,7 +133,7 @@ namespace BlackSimPlugin
HRESULT hr;
// Copy the Host Address
if( FAILED( hr = enumHostsResponseMsg->pAddressSender->Duplicate( hostNode.getHostAddressPtr() ) ) )
if (FAILED(hr = enumHostsResponseMsg->pAddressSender->Duplicate(hostNode.getHostAddressPtr())))
{
qWarning() << "Failed to duplicate host address!";
return hr;
@@ -169,25 +172,25 @@ namespace BlackSimPlugin
CoInitializeEx(nullptr, COINIT_MULTITHREADED);
// Create the IDirectPlay8Peer Object
if( FAILED( hr = CoCreateInstance(CLSID_DirectPlay8Peer,
if (FAILED(hr = CoCreateInstance(CLSID_DirectPlay8Peer,
nullptr,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Peer,
reinterpret_cast<void **>(&m_directPlayPeer) ) ) )
reinterpret_cast<void **>(&m_directPlayPeer))))
{
qWarning() << "Failed to create DirectPlay8Peer object!";
return hr;
}
// Init DirectPlay
if( FAILED( hr = m_directPlayPeer->Initialize(&m_callbackWrapper, m_callbackWrapper.messageHandler, 0 ) ) )
if (FAILED(hr = m_directPlayPeer->Initialize(&m_callbackWrapper, m_callbackWrapper.messageHandler, 0)))
{
qWarning() << "Failed to initialize directplay peer!";
return hr;
}
// Ensure that TCP/IP is a valid Service Provider
if( !isServiceProviderValid( &CLSID_DP8SP_TCPIP ) )
if (!isServiceProviderValid(&CLSID_DP8SP_TCPIP))
{
hr = E_FAIL;
qWarning() << "Service provider is invalid!";
@@ -197,7 +200,7 @@ namespace BlackSimPlugin
return hr;
}
bool CDirectPlayPeer::isServiceProviderValid(const GUID* /*pGuidSP*/)
bool CDirectPlayPeer::isServiceProviderValid(const GUID * /*pGuidSP*/)
{
DWORD dwItems = 0;
DWORD dwSize = 0;
@@ -205,7 +208,7 @@ namespace BlackSimPlugin
// The first call is to retrieve the size of the DPN_SERVICE_PROVIDER_INFO array
HRESULT hr = m_directPlayPeer->EnumServiceProviders(&CLSID_DP8SP_TCPIP, nullptr, nullptr, &dwSize, &dwItems, 0);
if( hr != DPNERR_BUFFERTOOSMALL)
if (hr != DPNERR_BUFFERTOOSMALL)
{
qWarning() << "Failed to enumerate service providers!";
return false;
@@ -214,18 +217,18 @@ namespace BlackSimPlugin
// Allocating an array with new DPN_SERVICE_PROVIDER_INFO[items] does not work, because the struct has
// several pointers in it. Hence EnumServiceProviders tells us how much memory it exactly needs.
QScopedArrayPointer<unsigned char> memPtr(new unsigned char[dwSize]);
DPN_SERVICE_PROVIDER_INFO* dpnSPInfo = reinterpret_cast<DPN_SERVICE_PROVIDER_INFO*>(memPtr.data());
DPN_SERVICE_PROVIDER_INFO *dpnSPInfo = reinterpret_cast<DPN_SERVICE_PROVIDER_INFO *>(memPtr.data());
if( FAILED( hr = m_directPlayPeer->EnumServiceProviders(&CLSID_DP8SP_TCPIP, nullptr, dpnSPInfo, &dwSize, &dwItems, 0 ) ) )
if (FAILED(hr = m_directPlayPeer->EnumServiceProviders(&CLSID_DP8SP_TCPIP, nullptr, dpnSPInfo, &dwSize, &dwItems, 0)))
{
qWarning() << "Failed to enumerate service providers!";
return false;
}
// There are no items returned so the requested SP is not available
if( dwItems == 0) hr = E_FAIL;
if (dwItems == 0) hr = E_FAIL;
if( SUCCEEDED(hr) ) return true;
if (SUCCEEDED(hr)) return true;
else return false;
}
@@ -234,17 +237,17 @@ namespace BlackSimPlugin
HRESULT hr = S_OK;
// Create our IDirectPlay8Address Device Address
if( FAILED( hr = CoCreateInstance( CLSID_DirectPlay8Address, nullptr,
if (FAILED(hr = CoCreateInstance(CLSID_DirectPlay8Address, nullptr,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Address,
reinterpret_cast<void**>(&m_deviceAddress) ) ) )
reinterpret_cast<void **>(&m_deviceAddress))))
{
qWarning() << "Failed to create DirectPlay8Address instance!";
return hr;
}
// Set the SP for our Device Address
if( FAILED( hr = m_deviceAddress->SetSP( &CLSID_DP8SP_TCPIP ) ) )
if (FAILED(hr = m_deviceAddress->SetSP(&CLSID_DP8SP_TCPIP)))
{
qWarning() << "Failed to set SP!";
return hr;
@@ -258,38 +261,37 @@ namespace BlackSimPlugin
HRESULT hr = S_OK;
// Create our IDirectPlay8Address Device Address
if( FAILED( hr = CoCreateInstance( CLSID_DirectPlay8Address, nullptr,
if (FAILED(hr = CoCreateInstance(CLSID_DirectPlay8Address, nullptr,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Address,
reinterpret_cast<void**>(&m_deviceAddress) ) ) )
reinterpret_cast<void **>(&m_deviceAddress))))
return printDirectPlayError(hr);
// Set the SP for our Device Address
if( FAILED( hr = m_deviceAddress->SetSP( &CLSID_DP8SP_TCPIP ) ) )
if (FAILED(hr = m_deviceAddress->SetSP(&CLSID_DP8SP_TCPIP)))
return printDirectPlayError(hr);
return S_OK;
}
HRESULT CDirectPlayPeer::sendMessage( const QByteArray &message)
HRESULT CDirectPlayPeer::sendMessage(const QByteArray &message)
{
HRESULT hr = S_OK;
DPN_BUFFER_DESC dpBufferDesc;
if( ( dpBufferDesc.dwBufferSize = message.size() ) == 0 ) return S_FALSE;
if ((dpBufferDesc.dwBufferSize = message.size()) == 0) return S_FALSE;
dpBufferDesc.pBufferData = (BYTE*)message.data();
dpBufferDesc.pBufferData = (BYTE *)message.data();
// If m_playerUser is non zero, send it only to him
if( FAILED( hr = m_directPlayPeer->SendTo( m_playerUser,
if (FAILED(hr = m_directPlayPeer->SendTo(m_playerUser,
&dpBufferDesc,
1, 0,
nullptr, nullptr,
DPNSEND_SYNC | DPNSEND_NOLOOPBACK ) ) )
DPNSEND_SYNC | DPNSEND_NOLOOPBACK)))
{
qWarning() << "Failed to send message!";
CLogMessage(this).warning("DirectPlay: Failed to send message!");
}
return hr;
}
}

View File

@@ -85,7 +85,7 @@ namespace BlackSimPlugin
if (m_interpolator.hasEnoughAircraftSituations())
{
CAircraftSituation situation = m_interpolator.getCurrentSituation();
MPPositionSlewMode positionSlewMode = aircraftSituationtoFS9(situation);
MPPositionSlewMode positionSlewMode = aircraftSituationToFS9(situation);
QByteArray positionMessage;
MultiPlayerPacketParser::writeType(positionMessage, CFs9Sdk::MULTIPLAYER_PACKET_ID_POSITION_SLEWMODE);

View File

@@ -14,12 +14,14 @@
#include "FSUIPC/FSUIPC_User.h"
#include "blacksim/fscommon/bcdconversions.h"
#include "blackmisc/logmessage.h"
#include <QDebug>
#include <QLatin1Char>
#include <QDateTime>
using namespace BlackSim::FsCommon;
using namespace BlackMisc::Aviation;
using namespace BlackMisc;
using namespace BlackMisc::Network;
using namespace BlackMisc::Geo;
using namespace BlackMisc::PhysicalQuantities;
@@ -58,16 +60,14 @@ namespace BlackSimPlugin
.arg(QLatin1Char(48 + (0x0f & (FSUIPC_Version >> 16))))
.arg((FSUIPC_Version & 0xffff) ? "a" + (FSUIPC_Version & 0xff) - 1 : "");
this->m_fsuipcVersion = QString("FSUIPC %1 (%2)").arg(ver).arg(sim);
// KB_REMOVE: Remove this later
qDebug() << "FSUIPC connected" << this->m_fsuipcVersion;
CLogMessage(this).info("FSUIPC connected: %1") << this->m_fsuipcVersion;
}
else
{
this->m_connected = false;
int index = static_cast<int>(result);
this->m_lastErrorMessage = CFsuipc::errorMessages().at(index);
// KB_REMOVE: Remove this later
qDebug() << "FSUIPC" << this->m_lastErrorMessage;
CLogMessage(this).info("FSUIPC not connected: %1") << this->m_lastErrorMessage;
}
return this->m_connected;
}
@@ -174,16 +174,18 @@ namespace BlackSimPlugin
transponderCodeRaw = CBcdConversions::bcd2Dec(transponderCodeRaw);
xpdr.setTransponderCode(transponderCodeRaw);
// Mode by SB3
if (xpdrIdentSb3Raw > 0)
if (xpdrIdentSb3Raw != 0)
{
// TODO: Reset value
//! \todo Reset value for FSUIPC
xpdr.setTransponderMode(CTransponder::StateIdent);
// qDebug() << "xpdr ident" << xpdrIdentSb3Raw;
}
else
{
xpdr.setTransponderMode(
xpdrModeSb3Raw == 0 ? CTransponder::ModeC : CTransponder::StateStandby
);
// qDebug() << "xpdr mode" << xpdrModeSb3Raw;
}
this->m_aircraft.setCockpit(com1, com2, xpdr);
@@ -213,8 +215,6 @@ namespace BlackSimPlugin
situation.setGroundspeed(groundspeed);
situation.setAltitude(altitude);
this->m_aircraft.setSituation(situation);
// qDebug() << m_aircraft;
}
else
{

View File

@@ -83,6 +83,9 @@ namespace BlackSimPlugin
return sims;
}
//! Log message category
static QString getMessageCategory() { return "swift.fscommon.fsuipc"; }
private:
bool m_connected;
bool m_validReadValues;

View File

@@ -1,7 +1,11 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* Copyright (C) 2013
* swift Project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "simconnect_datadefinition.h"

View File

@@ -1,7 +1,11 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* Copyright (C) 2013
* swift Project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "simconnect_object.h"
#include "blackcore/interpolator_linear.h"

View File

@@ -514,12 +514,13 @@ namespace BlackSimPlugin
position.Heading = situation.getHeading().value(CAngleUnit::deg());
position.Airspeed = situation.getGroundSpeed().value(CSpeedUnit::kts());
// TODO: epic fail for helicopters and VTOPs!
//! \todo : epic fail for helicopters and VTOPs!
position.OnGround = position.Airspeed < 30 ? 1 : 0;
DataDefinitionRemoteAircraftSituation ddAircraftSituation;
ddAircraftSituation.position = position;
//! \todo Gear handling with new protocol extension
DataDefinitionGearHandlePosition gearHandle;
gearHandle.gearHandlePosition = position.Altitude < 1000 ? 1 : 0;
@@ -563,11 +564,11 @@ namespace BlackSimPlugin
if (hr != S_OK)
{
qWarning() << "Sending time sync failed!";
CLogMessage(this).warning("Sending time sync failed!");
}
m_syncDeferredCounter = 5; // allow some time to sync
CLogMessage(this).info("Synchronized time to UTC: %1") << myTime.toString();
}
}
}
} // namespace
} // namespace

View File

@@ -1,7 +1,11 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* Copyright (C) 2013
* swift Project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "simulator_fsx.h"
#include "simconnect_datadefinition.h"
@@ -48,8 +52,9 @@ namespace BlackSimPlugin
ex.sprintf("Exception=%d SendID=%d Index=%d cbData=%d",
static_cast<int>(exception->dwException), static_cast<int>(exception->dwSendID),
static_cast<int>(exception->dwIndex), static_cast<int>(cbData));
qDebug() << "Caught simConnect exception: " << CSimConnectUtilities::simConnectExceptionToString((SIMCONNECT_EXCEPTION)exception->dwException);
qDebug() << ex;
CLogMessage(static_cast<CSimulatorFsx *>(nullptr)).error("Caught simConnect exception: %1 %2")
<< CSimConnectUtilities::simConnectExceptionToString((SIMCONNECT_EXCEPTION)exception->dwException)
<< ex;
break;
}
case SIMCONNECT_RECV_ID_QUIT:
@@ -178,5 +183,8 @@ namespace BlackSimPlugin
break;
} // main switch
} // method
} // namespace
} // namespace
}
}

View File

@@ -82,10 +82,10 @@ signals:
void currentMainInfoAreaChanged(const QWidget *currentWidget);
protected:
//! \copy QMainWindow::mouseMoveEvent
//! \copydoc QMainWindow::mouseMoveEvent
virtual void mouseMoveEvent(QMouseEvent *event) override { if (!handleMouseMoveEvent(event)) { QMainWindow::mouseMoveEvent(event); } ; }
//! \copy QMainWindow::mousePressEvent
//! \copydoc QMainWindow::mousePressEvent
virtual void mousePressEvent(QMouseEvent *event) override { if (!handleMousePressEvent(event)) { QMainWindow::mousePressEvent(event); } }
//! \copydoc QMainWindow::closeEvent