mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-05 01:35:45 +08:00
refs #369, revised FSUIPC
* removed own aircraft member * split into read / write, removed process
This commit is contained in:
@@ -19,11 +19,12 @@
|
|||||||
#include <QLatin1Char>
|
#include <QLatin1Char>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
|
||||||
|
using namespace BlackMisc;
|
||||||
using namespace BlackSim::FsCommon;
|
using namespace BlackSim::FsCommon;
|
||||||
using namespace BlackMisc::Aviation;
|
using namespace BlackMisc::Aviation;
|
||||||
using namespace BlackMisc;
|
|
||||||
using namespace BlackMisc::Network;
|
using namespace BlackMisc::Network;
|
||||||
using namespace BlackMisc::Geo;
|
using namespace BlackMisc::Geo;
|
||||||
|
using namespace BlackMisc::Simulation;
|
||||||
using namespace BlackMisc::PhysicalQuantities;
|
using namespace BlackMisc::PhysicalQuantities;
|
||||||
|
|
||||||
namespace BlackSimPlugin
|
namespace BlackSimPlugin
|
||||||
@@ -31,8 +32,7 @@ namespace BlackSimPlugin
|
|||||||
namespace FsCommon
|
namespace FsCommon
|
||||||
{
|
{
|
||||||
|
|
||||||
CFsuipc::CFsuipc() : m_connected(false), m_validReadValues(false)
|
CFsuipc::CFsuipc() { }
|
||||||
{ }
|
|
||||||
|
|
||||||
CFsuipc::~CFsuipc()
|
CFsuipc::~CFsuipc()
|
||||||
{
|
{
|
||||||
@@ -44,7 +44,6 @@ namespace BlackSimPlugin
|
|||||||
DWORD result;
|
DWORD result;
|
||||||
this->m_lastErrorMessage = "";
|
this->m_lastErrorMessage = "";
|
||||||
if (this->m_connected) return this->m_connected; // already connected
|
if (this->m_connected) return this->m_connected; // already connected
|
||||||
this->m_validReadValues = false;
|
|
||||||
if (FSUIPC_Open(SIM_ANY, &result))
|
if (FSUIPC_Open(SIM_ANY, &result))
|
||||||
{
|
{
|
||||||
this->m_connected = true;
|
this->m_connected = true;
|
||||||
@@ -76,21 +75,18 @@ namespace BlackSimPlugin
|
|||||||
{
|
{
|
||||||
FSUIPC_Close(); // Closing when it wasn't open is okay, so this is safe here
|
FSUIPC_Close(); // Closing when it wasn't open is okay, so this is safe here
|
||||||
this->m_connected = false;
|
this->m_connected = false;
|
||||||
this->m_validReadValues = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFsuipc::process()
|
bool CFsuipc::write(const CSimulatedAircraft &aircraft)
|
||||||
{
|
{
|
||||||
if (!this->m_connected) return;
|
if (!this->isConnected()) { return false; }
|
||||||
this->read();
|
|
||||||
|
Q_UNUSED(aircraft);
|
||||||
|
//! \todo FSUIPC write values
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFsuipc::write()
|
bool CFsuipc::read(CSimulatedAircraft &aircraft)
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void CFsuipc::read()
|
|
||||||
{
|
{
|
||||||
DWORD dwResult;
|
DWORD dwResult;
|
||||||
char localFsTimeRaw[3];
|
char localFsTimeRaw[3];
|
||||||
@@ -115,6 +111,9 @@ namespace BlackSimPlugin
|
|||||||
// https://www.ivao.aero/softdev/ivap/fsuipc_sdk.asp
|
// https://www.ivao.aero/softdev/ivap/fsuipc_sdk.asp
|
||||||
// http://squawkbox.ca/doc/sdk/fsuipc.php
|
// http://squawkbox.ca/doc/sdk/fsuipc.php
|
||||||
|
|
||||||
|
if (!this->isConnected()) { return false; }
|
||||||
|
|
||||||
|
bool read = false;
|
||||||
if (FSUIPC_Read(0x0238, 3, localFsTimeRaw, &dwResult) &&
|
if (FSUIPC_Read(0x0238, 3, localFsTimeRaw, &dwResult) &&
|
||||||
|
|
||||||
// COM settings
|
// COM settings
|
||||||
@@ -146,7 +145,7 @@ namespace BlackSimPlugin
|
|||||||
// If we wanted other reads/writes at the same time, we could put them here
|
// If we wanted other reads/writes at the same time, we could put them here
|
||||||
FSUIPC_Process(&dwResult))
|
FSUIPC_Process(&dwResult))
|
||||||
{
|
{
|
||||||
this->m_validReadValues = true;
|
read = true;
|
||||||
|
|
||||||
// time, basically as a heartbeat
|
// time, basically as a heartbeat
|
||||||
QString fsTime;
|
QString fsTime;
|
||||||
@@ -154,12 +153,12 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
// model
|
// model
|
||||||
const QString modelName = QString(modelNameRaw); // to be used to distinguish offsets for different models
|
const QString modelName = QString(modelNameRaw); // to be used to distinguish offsets for different models
|
||||||
m_model.setModelString(modelName);
|
aircraft.setModelString(modelName);
|
||||||
|
|
||||||
// COMs
|
// COMs
|
||||||
CComSystem com1 = this->m_aircraft.getCom1System();
|
CComSystem com1 = aircraft.getCom1System();
|
||||||
CComSystem com2 = this->m_aircraft.getCom2System();
|
CComSystem com2 = aircraft.getCom2System();
|
||||||
CTransponder xpdr = this->m_aircraft.getTransponder();
|
CTransponder xpdr = aircraft.getTransponder();
|
||||||
|
|
||||||
// 2710 => 12710 => / 100.0 => 127.1
|
// 2710 => 12710 => / 100.0 => 127.1
|
||||||
com1ActiveRaw = (10000 + CBcdConversions::bcd2Dec(com1ActiveRaw));
|
com1ActiveRaw = (10000 + CBcdConversions::bcd2Dec(com1ActiveRaw));
|
||||||
@@ -178,21 +177,19 @@ namespace BlackSimPlugin
|
|||||||
{
|
{
|
||||||
//! \todo Reset value for FSUIPC
|
//! \todo Reset value for FSUIPC
|
||||||
xpdr.setTransponderMode(CTransponder::StateIdent);
|
xpdr.setTransponderMode(CTransponder::StateIdent);
|
||||||
// qDebug() << "xpdr ident" << xpdrIdentSb3Raw;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
xpdr.setTransponderMode(
|
xpdr.setTransponderMode(
|
||||||
xpdrModeSb3Raw == 0 ? CTransponder::ModeC : CTransponder::StateStandby
|
xpdrModeSb3Raw == 0 ? CTransponder::ModeC : CTransponder::StateStandby
|
||||||
);
|
);
|
||||||
// qDebug() << "xpdr mode" << xpdrModeSb3Raw;
|
|
||||||
}
|
}
|
||||||
this->m_aircraft.setCockpit(com1, com2, xpdr);
|
aircraft.setCockpit(com1, com2, xpdr);
|
||||||
|
|
||||||
// position
|
// position
|
||||||
const double latCorrectionFactor = 90.0 / (10001750.0 * 65536.0 * 65536.0);
|
const double latCorrectionFactor = 90.0 / (10001750.0 * 65536.0 * 65536.0);
|
||||||
const double lonCorrectionFactor = 360.0 / (65536.0 * 65536.0 * 65536.0 * 65536.0);
|
const double lonCorrectionFactor = 360.0 / (65536.0 * 65536.0 * 65536.0 * 65536.0);
|
||||||
CAircraftSituation situation = this->m_aircraft.getSituation();
|
CAircraftSituation situation = aircraft.getSituation();
|
||||||
CCoordinateGeodetic position = situation.getPosition();
|
CCoordinateGeodetic position = situation.getPosition();
|
||||||
CLatitude lat(latitudeRaw * latCorrectionFactor, CAngleUnit::deg());
|
CLatitude lat(latitudeRaw * latCorrectionFactor, CAngleUnit::deg());
|
||||||
CLongitude lon(longitudeRaw * lonCorrectionFactor, CAngleUnit::deg());
|
CLongitude lon(longitudeRaw * lonCorrectionFactor, CAngleUnit::deg());
|
||||||
@@ -214,12 +211,9 @@ namespace BlackSimPlugin
|
|||||||
situation.setPitch(pitch);
|
situation.setPitch(pitch);
|
||||||
situation.setGroundspeed(groundspeed);
|
situation.setGroundspeed(groundspeed);
|
||||||
situation.setAltitude(altitude);
|
situation.setAltitude(altitude);
|
||||||
this->m_aircraft.setSituation(situation);
|
aircraft.setSituation(situation);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this->m_validReadValues = false;
|
|
||||||
}
|
}
|
||||||
|
return read;
|
||||||
}
|
}
|
||||||
|
|
||||||
double CFsuipc::intToFractional(double fractional)
|
double CFsuipc::intToFractional(double fractional)
|
||||||
@@ -228,5 +222,5 @@ namespace BlackSimPlugin
|
|||||||
if (f < 1.0) return f;
|
if (f < 1.0) return f;
|
||||||
return intToFractional(f);
|
return intToFractional(f);
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
}
|
} // namespace
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
/* Copyright (C) 2013 VATSIM Community / contributors
|
/* Copyright (C) 2014
|
||||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
* swift project community / contributors
|
||||||
* 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/. */
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//! \file
|
||||||
|
|
||||||
#ifndef BLACKSIMPLUGIN_FSUIPC_H
|
#ifndef BLACKSIMPLUGIN_FSUIPC_H
|
||||||
#define BLACKSIMPLUGIN_FSUIPC_H
|
#define BLACKSIMPLUGIN_FSUIPC_H
|
||||||
|
|
||||||
#include "blackmisc/simulation/aircraftmodel.h"
|
#include "blackmisc/simulation/simulatedaircraft.h"
|
||||||
#include "blackmisc/avaircraft.h"
|
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
namespace BlackSimPlugin
|
namespace BlackSimPlugin
|
||||||
@@ -34,17 +39,14 @@ namespace BlackSimPlugin
|
|||||||
//! Is connected?
|
//! Is connected?
|
||||||
bool isConnected() const { return m_connected; }
|
bool isConnected() const { return m_connected; }
|
||||||
|
|
||||||
//! Valid read values
|
|
||||||
bool validReadValues() const { return m_validReadValues; }
|
|
||||||
|
|
||||||
//! Get own aircraft from FSUIPC
|
|
||||||
const BlackMisc::Aviation::CAircraft &getOwnAircraft() const { return m_aircraft; }
|
|
||||||
|
|
||||||
//! Process reading and writing variables
|
//! Process reading and writing variables
|
||||||
void process();
|
void process(BlackMisc::Simulation::CSimulatedAircraft &aircraft);
|
||||||
|
|
||||||
//! Write variables
|
//! Write variables
|
||||||
void write();
|
bool write(const BlackMisc::Simulation::CSimulatedAircraft &aircraft);
|
||||||
|
|
||||||
|
//! Read data from FSUIPC
|
||||||
|
bool read(BlackMisc::Simulation::CSimulatedAircraft &aircraft);
|
||||||
|
|
||||||
//! Error messages
|
//! Error messages
|
||||||
static const QStringList &errorMessages()
|
static const QStringList &errorMessages()
|
||||||
@@ -87,15 +89,9 @@ namespace BlackSimPlugin
|
|||||||
static QString getMessageCategory() { return "swift.fscommon.fsuipc"; }
|
static QString getMessageCategory() { return "swift.fscommon.fsuipc"; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_connected;
|
bool m_connected = false;
|
||||||
bool m_validReadValues;
|
|
||||||
QString m_lastErrorMessage;
|
QString m_lastErrorMessage;
|
||||||
QString m_fsuipcVersion;
|
QString m_fsuipcVersion;
|
||||||
BlackMisc::Aviation::CAircraft m_aircraft; //!< FSUIPC read aircraft
|
|
||||||
BlackMisc::Simulation::CAircraftModel m_model; //!< FSUIPC read model
|
|
||||||
|
|
||||||
//! Read data from FSUIPC
|
|
||||||
void read();
|
|
||||||
|
|
||||||
//! Integer representing fractional
|
//! Integer representing fractional
|
||||||
static double intToFractional(double fractional);
|
static double intToFractional(double fractional);
|
||||||
|
|||||||
Reference in New Issue
Block a user