refs #369, revised FSUIPC

* removed own aircraft member
* split into read / write, removed process
This commit is contained in:
Klaus Basan
2015-02-01 20:47:00 +01:00
parent fe4613a868
commit 24e6dcef54
2 changed files with 41 additions and 51 deletions

View File

@@ -19,11 +19,12 @@
#include <QLatin1Char>
#include <QDateTime>
using namespace BlackMisc;
using namespace BlackSim::FsCommon;
using namespace BlackMisc::Aviation;
using namespace BlackMisc;
using namespace BlackMisc::Network;
using namespace BlackMisc::Geo;
using namespace BlackMisc::Simulation;
using namespace BlackMisc::PhysicalQuantities;
namespace BlackSimPlugin
@@ -31,8 +32,7 @@ namespace BlackSimPlugin
namespace FsCommon
{
CFsuipc::CFsuipc() : m_connected(false), m_validReadValues(false)
{ }
CFsuipc::CFsuipc() { }
CFsuipc::~CFsuipc()
{
@@ -44,7 +44,6 @@ namespace BlackSimPlugin
DWORD result;
this->m_lastErrorMessage = "";
if (this->m_connected) return this->m_connected; // already connected
this->m_validReadValues = false;
if (FSUIPC_Open(SIM_ANY, &result))
{
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
this->m_connected = false;
this->m_validReadValues = false;
}
void CFsuipc::process()
bool CFsuipc::write(const CSimulatedAircraft &aircraft)
{
if (!this->m_connected) return;
this->read();
if (!this->isConnected()) { return false; }
Q_UNUSED(aircraft);
//! \todo FSUIPC write values
return false;
}
void CFsuipc::write()
{
}
void CFsuipc::read()
bool CFsuipc::read(CSimulatedAircraft &aircraft)
{
DWORD dwResult;
char localFsTimeRaw[3];
@@ -115,6 +111,9 @@ namespace BlackSimPlugin
// https://www.ivao.aero/softdev/ivap/fsuipc_sdk.asp
// http://squawkbox.ca/doc/sdk/fsuipc.php
if (!this->isConnected()) { return false; }
bool read = false;
if (FSUIPC_Read(0x0238, 3, localFsTimeRaw, &dwResult) &&
// COM settings
@@ -146,7 +145,7 @@ namespace BlackSimPlugin
// If we wanted other reads/writes at the same time, we could put them here
FSUIPC_Process(&dwResult))
{
this->m_validReadValues = true;
read = true;
// time, basically as a heartbeat
QString fsTime;
@@ -154,12 +153,12 @@ namespace BlackSimPlugin
// model
const QString modelName = QString(modelNameRaw); // to be used to distinguish offsets for different models
m_model.setModelString(modelName);
aircraft.setModelString(modelName);
// COMs
CComSystem com1 = this->m_aircraft.getCom1System();
CComSystem com2 = this->m_aircraft.getCom2System();
CTransponder xpdr = this->m_aircraft.getTransponder();
CComSystem com1 = aircraft.getCom1System();
CComSystem com2 = aircraft.getCom2System();
CTransponder xpdr = aircraft.getTransponder();
// 2710 => 12710 => / 100.0 => 127.1
com1ActiveRaw = (10000 + CBcdConversions::bcd2Dec(com1ActiveRaw));
@@ -178,21 +177,19 @@ namespace BlackSimPlugin
{
//! \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);
aircraft.setCockpit(com1, com2, xpdr);
// position
const double latCorrectionFactor = 90.0 / (10001750.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();
CLatitude lat(latitudeRaw * latCorrectionFactor, CAngleUnit::deg());
CLongitude lon(longitudeRaw * lonCorrectionFactor, CAngleUnit::deg());
@@ -214,12 +211,9 @@ namespace BlackSimPlugin
situation.setPitch(pitch);
situation.setGroundspeed(groundspeed);
situation.setAltitude(altitude);
this->m_aircraft.setSituation(situation);
}
else
{
this->m_validReadValues = false;
aircraft.setSituation(situation);
}
return read;
}
double CFsuipc::intToFractional(double fractional)
@@ -228,5 +222,5 @@ namespace BlackSimPlugin
if (f < 1.0) return f;
return intToFractional(f);
}
}
}
} // namespace
} // namespace

View File

@@ -1,13 +1,18 @@
/* 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) 2014
* 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.
*/
//! \file
#ifndef BLACKSIMPLUGIN_FSUIPC_H
#define BLACKSIMPLUGIN_FSUIPC_H
#include "blackmisc/simulation/aircraftmodel.h"
#include "blackmisc/avaircraft.h"
#include "blackmisc/simulation/simulatedaircraft.h"
#include <QStringList>
namespace BlackSimPlugin
@@ -34,17 +39,14 @@ namespace BlackSimPlugin
//! Is 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
void process();
void process(BlackMisc::Simulation::CSimulatedAircraft &aircraft);
//! Write variables
void write();
bool write(const BlackMisc::Simulation::CSimulatedAircraft &aircraft);
//! Read data from FSUIPC
bool read(BlackMisc::Simulation::CSimulatedAircraft &aircraft);
//! Error messages
static const QStringList &errorMessages()
@@ -87,15 +89,9 @@ namespace BlackSimPlugin
static QString getMessageCategory() { return "swift.fscommon.fsuipc"; }
private:
bool m_connected;
bool m_validReadValues;
bool m_connected = false;
QString m_lastErrorMessage;
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
static double intToFractional(double fractional);