mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-15 01:05:35 +08:00
Initial commit
This commit is contained in:
0
blacklib/include/blackcore/CMakeLists.txt
Normal file
0
blacklib/include/blackcore/CMakeLists.txt
Normal file
55
blacklib/include/blackcore/constants.h
Normal file
55
blacklib/include/blackcore/constants.h
Normal file
@@ -0,0 +1,55 @@
|
||||
//! Copyright (C) 2013 Roland Winklmeier
|
||||
//! 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/
|
||||
|
||||
#ifndef CONSTANTS_H
|
||||
#define CONSTANTS_H
|
||||
|
||||
#include "math.h"
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
namespace Constants
|
||||
{
|
||||
//! Conversion from Degree to Radians
|
||||
const double DegToRad = 4.0 * atan(1.0) / 180.0;
|
||||
|
||||
//! Conversion from Radians to Degree
|
||||
const double RadToDeg = 180.0 / (4.0 * atan(1.0));
|
||||
|
||||
//! Mathematical constant Pi
|
||||
const double PI = 4.0 * atan(1.0);
|
||||
|
||||
//! 2 * Pi
|
||||
const double TwoPI = 2.0 * PI;
|
||||
|
||||
//! Conversion from feet to meter
|
||||
const double FeetToMeter = 0.3048;
|
||||
|
||||
//! Conversion from meter to feed
|
||||
const double MeterToFeet = 3.28084;
|
||||
|
||||
//! Conversion from knots to meter/second
|
||||
const double KnotsToMeterPerSecond = 0.5144444444;
|
||||
|
||||
//! Equatorial radius of WGS84 ellipsoid (6378137 m)
|
||||
const double EarthRadius = 6378137.0;
|
||||
|
||||
//! Flattening of WGS84 ellipsoid (1/298.257223563).
|
||||
const double Flattening = 1/298.257223563;
|
||||
|
||||
//! First eccentricity squared
|
||||
const double e2 = (Flattening * (2 - Flattening));
|
||||
|
||||
//! First eccentricity to the power of four
|
||||
const double e4 = CMath::square(e2);
|
||||
|
||||
const double e2m = CMath::square(1 - Flattening);
|
||||
|
||||
const double e2absolute = abs(e2);
|
||||
}
|
||||
|
||||
} // namespace BlackCore
|
||||
|
||||
#endif // CONSTANTS_H
|
||||
42
blacklib/include/blackcore/ecef.h
Normal file
42
blacklib/include/blackcore/ecef.h
Normal file
@@ -0,0 +1,42 @@
|
||||
//! Copyright (C) 2013 Roland Winklmeier
|
||||
//! 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/
|
||||
|
||||
#ifndef ECEF_H
|
||||
#define ECEF_H
|
||||
|
||||
#include "vector_3d.h"
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
|
||||
class CNed;
|
||||
class CVectorGeo;
|
||||
|
||||
class CEcef : public CVector3D
|
||||
{
|
||||
public:
|
||||
CEcef();
|
||||
CEcef(double X, double Y, double Z);
|
||||
|
||||
//! Converts this velocity vector into the NED format
|
||||
/*!
|
||||
\param pos This position is needed for correct calculation
|
||||
\return velocity in NED coordinate system
|
||||
*/
|
||||
CNed toNED(const CVectorGeo &pos);
|
||||
|
||||
//! Converts this position vector into the geodetic format
|
||||
/*!
|
||||
\return Position in latitude, longitude and altitude
|
||||
*/
|
||||
CVectorGeo toGeodetic();
|
||||
|
||||
//! Assignment operator
|
||||
void operator= (const CVector3D &rhs);
|
||||
};
|
||||
|
||||
} // namespace BlackCore
|
||||
|
||||
#endif // ECEF_H
|
||||
126
blacklib/include/blackcore/fsd_client.h
Normal file
126
blacklib/include/blackcore/fsd_client.h
Normal file
@@ -0,0 +1,126 @@
|
||||
//! Copyright (C) 2013 Roland Winklmeier
|
||||
//! 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/
|
||||
|
||||
#ifndef FSD_CLIENT_H
|
||||
#define FSD_CLIENT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QTcpSocket>
|
||||
|
||||
#include <blackcore/fsd_protocol.h>
|
||||
|
||||
|
||||
namespace FSD
|
||||
{
|
||||
|
||||
typedef struct {
|
||||
QString m_host;
|
||||
quint16 m_port;
|
||||
QString m_callsign;
|
||||
QString m_userid;
|
||||
QString m_password;
|
||||
FSD::SimulatorType m_simType;
|
||||
QString m_realName;
|
||||
} TClientInfo;
|
||||
|
||||
class CFSDClient : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CFSDClient();
|
||||
|
||||
void connectTo(const QString &host, quint16 port);
|
||||
void disconnectFrom();
|
||||
void reconnect();
|
||||
|
||||
void updateClientInfo(TClientInfo &clientInfo );
|
||||
|
||||
TClientInfo& clientInfo();
|
||||
|
||||
bool isConnected();
|
||||
|
||||
//! Returns a human readable description of the last error that occurred.
|
||||
QString getErrorMessage(QAbstractSocket::SocketError error);
|
||||
|
||||
bool sendMessage(const QString &message);
|
||||
|
||||
//////////////////////////////////
|
||||
// FSD specific senders functions
|
||||
//////////////////////////////////
|
||||
|
||||
void sendText ( QString &message);
|
||||
|
||||
void sendTextonRadios ( QList<qint16> &frequencies, QString &message);
|
||||
|
||||
void sendClientQuery ( TQueryType type, QString &callsign);
|
||||
|
||||
void sendClientQueryReponse ( TQueryType type, QString &data);
|
||||
|
||||
void sendPilotPosition ( TPositionMessage *posMessage );
|
||||
|
||||
void sendFlightPlan ();
|
||||
|
||||
signals:
|
||||
|
||||
//! emitted when new data were received
|
||||
void doReceivedMessage(QString &messageID, QByteArray &message);
|
||||
|
||||
//! emitted when cliebt connected
|
||||
void doConnected();
|
||||
|
||||
//! emitted when client disconnected
|
||||
void doDisconnected();
|
||||
|
||||
//! emitted when an error has occured
|
||||
void doError(QAbstractSocket::SocketError error, const QString& error_message);
|
||||
|
||||
protected slots:
|
||||
|
||||
//! Call this slot .
|
||||
/*!
|
||||
\param data Reference to the raw byte data to be sent.
|
||||
\return Returns true if sending was successfull, otherwise false.
|
||||
*/
|
||||
void onConnected();
|
||||
void onDisconnected();
|
||||
void onError(QAbstractSocket::SocketError error);
|
||||
void onReceivingData();
|
||||
|
||||
protected:
|
||||
|
||||
void sendAddPilot();
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
CFSDClient( const CFSDClient& other);
|
||||
const CFSDClient& operator = ( const CFSDClient& other);
|
||||
|
||||
void init();
|
||||
void registerMessages();
|
||||
|
||||
void processLine(QString &line);
|
||||
|
||||
QTcpSocket* m_tcp_socket;
|
||||
|
||||
QString m_host;
|
||||
quint16 m_port;
|
||||
QString m_callsign;
|
||||
QString m_userid;
|
||||
QString m_password;
|
||||
FSD::SimulatorType m_simType;
|
||||
QString m_realName;
|
||||
|
||||
QString m_last_error;
|
||||
|
||||
};
|
||||
|
||||
} // namespace FSD
|
||||
|
||||
#endif // FSD_CLIENT_H
|
||||
156
blacklib/include/blackcore/fsd_messages.h
Normal file
156
blacklib/include/blackcore/fsd_messages.h
Normal file
@@ -0,0 +1,156 @@
|
||||
//! Copyright (C) 2013 Roland Winklmeier
|
||||
//! 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/
|
||||
|
||||
#ifndef FSD_MESSAGES_H
|
||||
#define FSD_MESSAGES_H
|
||||
|
||||
#include "blackmisc/message_system.h"
|
||||
|
||||
#define VATSIM_PROTOCOL_REV 9
|
||||
|
||||
// Qt includes
|
||||
#include <QtGlobal>
|
||||
#include <QVector>
|
||||
|
||||
typedef QVector<QString> QStringVector;
|
||||
|
||||
namespace FSD
|
||||
{
|
||||
class FSD_MSG : public BlackMisc::IMessage
|
||||
{
|
||||
public:
|
||||
FSD_MSG(QString& id) : IMessage(id)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void setSource(const QString &source) {m_source = source; }
|
||||
void setDest(const QString &destination) {m_destination = destination; }
|
||||
|
||||
protected:
|
||||
qint32 unpack(const QString &line, QStringVector &tokens);
|
||||
QString pack(const QStringVector &tokens) const;
|
||||
|
||||
QString m_destination;
|
||||
QString m_source;
|
||||
};
|
||||
|
||||
class FSD_MSG_AddPilot : public FSD_MSG
|
||||
{
|
||||
public:
|
||||
FSD_MSG_AddPilot() : FSD_MSG(QString("#AP")), m_revision(VATSIM_PROTOCOL_REV),
|
||||
m_rating(1)
|
||||
{
|
||||
}
|
||||
|
||||
void setUserID(const QString &userID) { m_userID = userID; }
|
||||
void setPassword(const QString &password) { m_password = password; }
|
||||
void setSimulator(const quint16 &simulator) { m_simulator = simulator; }
|
||||
void setRealName(const QString &name) { m_realName = name; }
|
||||
|
||||
virtual QDataStream& operator<< (QDataStream& in) { return in; }
|
||||
virtual QDataStream& operator>> (QDataStream& out) const { return out; }
|
||||
|
||||
virtual QTextStream& operator<< ( QTextStream& in)
|
||||
{ return in; }
|
||||
virtual QTextStream& operator>> (QTextStream& out) const
|
||||
{
|
||||
QStringVector tokens;
|
||||
tokens << m_source << m_destination << m_userID << m_password;
|
||||
tokens << QString("%1").arg(m_rating) << QString("%1").arg(m_revision);
|
||||
tokens << QString("%1").arg(m_simulator) << m_realName;
|
||||
out << pack(tokens);
|
||||
return out;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
QString m_userID;
|
||||
QString m_password;
|
||||
quint16 m_rating;
|
||||
quint16 m_revision;
|
||||
quint16 m_simulator;
|
||||
QString m_realName;
|
||||
};
|
||||
|
||||
class FSD_MSG_TextMessage : public FSD_MSG
|
||||
{
|
||||
public:
|
||||
FSD_MSG_TextMessage() : FSD_MSG(QString("#TM"))
|
||||
{
|
||||
}
|
||||
|
||||
virtual QDataStream& operator<< (QDataStream& in) { return in; }
|
||||
virtual QDataStream& operator>> (QDataStream& out) const { return out;}
|
||||
|
||||
virtual QTextStream& operator<< ( QTextStream& in)
|
||||
{
|
||||
QString message = in.readAll();
|
||||
QStringVector tokens;
|
||||
|
||||
//tokens.resize(3);
|
||||
unpack(message, tokens);
|
||||
m_source = tokens.at(0);
|
||||
m_destination = tokens.at(1);
|
||||
int size = tokens.size();
|
||||
QString m_textmessage;
|
||||
for ( int ii = 2; ii < tokens.size(); ++ii)
|
||||
m_textmessage += tokens.at(ii);
|
||||
bInfo << m_textmessage;
|
||||
return in;
|
||||
}
|
||||
|
||||
virtual QTextStream& operator>> (QTextStream& out) const
|
||||
{
|
||||
QStringVector tokens;
|
||||
tokens << m_source << m_destination;
|
||||
out << pack(tokens);
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
||||
class FSD_MSG_Plane_Position : public FSD_MSG
|
||||
{
|
||||
public:
|
||||
|
||||
FSD_MSG_Plane_Position() : FSD_MSG(QString("@"))
|
||||
{
|
||||
}
|
||||
|
||||
inline QString SquawkMode() const { return m_message_tokens.at(0); }
|
||||
inline QString Callsign() const { return m_message_tokens.at(1); }
|
||||
inline QString Squawk() const { return m_message_tokens.at(2); }
|
||||
inline quint16 Rating() const { return m_message_tokens.at(3).toUInt(); }
|
||||
inline double Latitude() const { return m_message_tokens.at(4).toDouble(); }
|
||||
inline double Longitude() const { return m_message_tokens.at(5).toDouble(); }
|
||||
inline qint32 Altitude() const { return m_message_tokens.at(6).toInt(); }
|
||||
inline qint32 Speed() const { return m_message_tokens.at(7).toInt(); }
|
||||
inline quint32 PBH() const { return m_message_tokens.at(8).toUInt(); }
|
||||
inline qint32 AltDiff() const { return m_message_tokens.at(9).toInt(); }
|
||||
|
||||
inline void setSquawkMode( const QString &squawk_mode) { m_message_tokens.replace(0, squawk_mode); }
|
||||
inline void setCallsign ( const QString &callsign) { m_message_tokens.replace(1, callsign); }
|
||||
inline void setSquawk ( const QString &squawk) { m_message_tokens.replace(2, squawk); }
|
||||
inline void setRating ( const quint16 rating) { m_message_tokens.replace(3, QString("%1").arg(rating)); }
|
||||
inline void setLatitude ( const double latitude) { m_message_tokens.replace(4, QString("%1").arg(latitude)); }
|
||||
inline void setLongitude ( const double longitude) { m_message_tokens.replace(5, QString("%1").arg(longitude)); }
|
||||
inline void setAltitude ( const qint32 altitude) { m_message_tokens.replace(6, QString("%1").arg(altitude)); }
|
||||
inline void setSpeed ( const qint32 speed) { m_message_tokens.replace(7, QString("%1").arg(speed)); }
|
||||
inline void setPBH ( const quint32 pbh) { m_message_tokens.replace(8, QString("%1").arg(pbh)); }
|
||||
inline void setAltDiff ( const qint32 altdiff) { m_message_tokens.replace(9, QString("%1").arg(altdiff)); }
|
||||
|
||||
virtual QTextStream& operator<< ( QTextStream& in);
|
||||
virtual QTextStream& operator>> (QTextStream& out) const;
|
||||
|
||||
virtual QDataStream& operator<< (QDataStream& in) { return in; }
|
||||
virtual QDataStream& operator>> (QDataStream& out) const { return out;}
|
||||
|
||||
private:
|
||||
QStringVector m_message_tokens;
|
||||
};
|
||||
|
||||
} // namespace FSD
|
||||
|
||||
#endif // FSD_MESSAGES_H
|
||||
61
blacklib/include/blackcore/fsd_protocol.h
Normal file
61
blacklib/include/blackcore/fsd_protocol.h
Normal file
@@ -0,0 +1,61 @@
|
||||
//! Copyright (C) 2013 Roland Winklmeier
|
||||
//! 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/
|
||||
|
||||
#ifndef FSD_PROTOCOL_H
|
||||
#define FSD_PROTOCOL_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace FSD
|
||||
{
|
||||
enum SimulatorType {
|
||||
SIM_UNKNOWN = -1,
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
Query_FP,
|
||||
Query_Frequency,
|
||||
Query_Server,
|
||||
Query_RealName,
|
||||
Query_isATC,
|
||||
Query_Capabilities,
|
||||
Query_IP
|
||||
} TQueryType;
|
||||
|
||||
typedef enum {
|
||||
TMode_Standby = 'S',
|
||||
TMode_Charly = 'N',
|
||||
TMode_Ident = 'Y'
|
||||
} TTransponderMode;
|
||||
|
||||
typedef struct {
|
||||
TTransponderMode transponderMode;
|
||||
quint16 squawk;
|
||||
quint8 rating;
|
||||
double latitude;
|
||||
double longitude;
|
||||
qint32 altitude;
|
||||
qint32 groundSpeed;
|
||||
double pitch;
|
||||
double bank;
|
||||
double heading;
|
||||
qint32 diffPressureTrueAlt;
|
||||
} TPositionMessage;
|
||||
|
||||
|
||||
const QString Headers[] = {
|
||||
"@",
|
||||
"%",
|
||||
"#AA",
|
||||
"#AP",
|
||||
"#DA",
|
||||
"#DP",
|
||||
"#TM"
|
||||
};
|
||||
|
||||
#define MAX_FSD_HEADERS 7
|
||||
}
|
||||
|
||||
#endif // FSD_PROTOCOL_H
|
||||
78
blacklib/include/blackcore/interpolator.h
Normal file
78
blacklib/include/blackcore/interpolator.h
Normal file
@@ -0,0 +1,78 @@
|
||||
//! Copyright (C) 2013 Roland Winklmeier
|
||||
//! 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/
|
||||
|
||||
#ifndef INTERPOLATOR_H
|
||||
#define INTERPOLATOR_H
|
||||
|
||||
#include <QElapsedTimer>
|
||||
|
||||
#include "blackcore/vector_geo.h"
|
||||
#include <blackcore/ecef.h>
|
||||
#include "blackcore/vector_3d.h"
|
||||
#include "blackcore/ned.h"
|
||||
#include "blackcore/ecef.h"
|
||||
#include "blackcore/constants.h"
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
|
||||
typedef struct
|
||||
{
|
||||
double heading;
|
||||
double pitch;
|
||||
double bank;
|
||||
|
||||
} TOrientation;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void reset()
|
||||
{
|
||||
}
|
||||
|
||||
qint64 timestamp;
|
||||
CEcef position;
|
||||
TOrientation orientation;
|
||||
double groundspeed;
|
||||
CVector3D velocity;
|
||||
CNed velNED;
|
||||
|
||||
} TPlaneState;
|
||||
|
||||
class CInterpolator
|
||||
{
|
||||
public:
|
||||
CInterpolator();
|
||||
|
||||
void initialize();
|
||||
|
||||
void pushUpdate(CVectorGeo pos, double groundVelocity, double heading, double pitch, double bank);
|
||||
|
||||
bool isValid();
|
||||
|
||||
|
||||
|
||||
bool stateNow(TPlaneState *state);
|
||||
private:
|
||||
double normalizeRadians(double radian);
|
||||
|
||||
|
||||
QElapsedTimer m_time;
|
||||
TPlaneState *m_state_begin;
|
||||
TPlaneState *m_state_end;
|
||||
|
||||
bool m_valid;
|
||||
|
||||
CVector3D m_a;
|
||||
CVector3D m_b;
|
||||
|
||||
double m_timeEnd;
|
||||
double m_timeBegin;
|
||||
|
||||
};
|
||||
|
||||
} // namespace BlackCore
|
||||
|
||||
#endif // INTERPOLATOR_H
|
||||
56
blacklib/include/blackcore/math.h
Normal file
56
blacklib/include/blackcore/math.h
Normal file
@@ -0,0 +1,56 @@
|
||||
//! Copyright (C) 2013 Roland Winklmeier
|
||||
//! 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/
|
||||
|
||||
#ifndef MATH_H
|
||||
#define MATH_H
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
|
||||
class CMath
|
||||
{
|
||||
public:
|
||||
//! Calculates the hypotenuse of x and y without overflow
|
||||
/*!
|
||||
\param x
|
||||
\param y
|
||||
*/
|
||||
static double hypot(double x, double y);
|
||||
|
||||
//! Calculates the square of x
|
||||
/*!
|
||||
\param x
|
||||
\return x^2
|
||||
*/
|
||||
static inline double square(const double x)
|
||||
{
|
||||
return x*x;
|
||||
}
|
||||
|
||||
//! Calculates x to the power of three
|
||||
/*!
|
||||
\param x
|
||||
\return x^3
|
||||
*/
|
||||
static inline double cubic(const double x)
|
||||
{
|
||||
return x*x*x;
|
||||
}
|
||||
|
||||
//! Calculates the real cubic root
|
||||
/*!
|
||||
\param x
|
||||
\param y
|
||||
\return Returns the real part of the solution
|
||||
*/
|
||||
static double cubicRootReal(const double x);
|
||||
|
||||
private:
|
||||
CMath() {}
|
||||
};
|
||||
|
||||
} // namespace BlackCore
|
||||
|
||||
#endif // MATH_H
|
||||
86
blacklib/include/blackcore/matrix_3d.h
Normal file
86
blacklib/include/blackcore/matrix_3d.h
Normal file
@@ -0,0 +1,86 @@
|
||||
//! Copyright (C) 2013 Roland Winklmeier
|
||||
//! 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/
|
||||
|
||||
#ifndef MATRIX_3D_H
|
||||
#define MATRIX_3D_H
|
||||
|
||||
#include "blackcore/vector_3d.h"
|
||||
#include "blackcore/ecef.h"
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
|
||||
class CMatrix3D
|
||||
{
|
||||
public:
|
||||
CMatrix3D();
|
||||
|
||||
CMatrix3D(const CMatrix3D & other);
|
||||
|
||||
/*!
|
||||
Basic Matrix functions
|
||||
*/
|
||||
|
||||
//! Fills the matrix with random elements
|
||||
void random();
|
||||
|
||||
//! Calculates the determinant of the matrix
|
||||
double determinant();
|
||||
|
||||
//! Returns the inverse matrix
|
||||
CMatrix3D inverse();
|
||||
|
||||
//! Sets all elements to zero
|
||||
void zeros();
|
||||
|
||||
//! Prints the matrix to stdout
|
||||
void print();
|
||||
|
||||
//! Returns an element
|
||||
/*!
|
||||
\param row Specifies elements row
|
||||
\param column Specifies elements column
|
||||
\return Returns element of [row, column]
|
||||
*/
|
||||
double getElement(qint8 row, qint8 column) const;
|
||||
|
||||
//! Sets a matrix element
|
||||
/*!
|
||||
\param row Specifies elements row
|
||||
\param column Specifies elements column
|
||||
\param value Specifies the new elements value
|
||||
*/
|
||||
void setElement(qint8 row, qint8 column, double value);
|
||||
|
||||
/*!
|
||||
Operators
|
||||
*/
|
||||
|
||||
CMatrix3D & operator +=(const CMatrix3D &rhs);
|
||||
CMatrix3D & operator -=(const CMatrix3D &rhs);
|
||||
|
||||
CMatrix3D & operator = (const CMatrix3D &rhs);
|
||||
|
||||
CMatrix3D operator +(const CMatrix3D &rhs);
|
||||
CMatrix3D operator -(const CMatrix3D &rhs);
|
||||
|
||||
bool operator ==(const CMatrix3D &rhs);
|
||||
bool operator !=(const CMatrix3D &rhs);
|
||||
|
||||
CMatrix3D & operator *=(const CMatrix3D &rhs);
|
||||
CMatrix3D operator *(const CMatrix3D &rhs);
|
||||
|
||||
CVector3D operator * ( const CVector3D &rhs);
|
||||
CEcef operator * ( const CEcef &rhs);
|
||||
|
||||
double& operator() (const qint8 row, const qint8 column);
|
||||
|
||||
private:
|
||||
double m[3][3];
|
||||
};
|
||||
|
||||
} // namespace BlackCore
|
||||
|
||||
#endif // MATRIX_3D_H
|
||||
100
blacklib/include/blackcore/multiplayer.h
Normal file
100
blacklib/include/blackcore/multiplayer.h
Normal file
@@ -0,0 +1,100 @@
|
||||
//! Copyright (C) 2013 Roland Winklmeier
|
||||
//! 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/
|
||||
|
||||
#ifndef MULTIPLAYER_H
|
||||
#define MULTIPLAYER_H
|
||||
|
||||
#include <QHash>
|
||||
#include <QString>
|
||||
#include <qglobal.h>
|
||||
#include <blackmisc/message_system.h>
|
||||
#include <blackcore/fsd_messages.h>
|
||||
|
||||
namespace BlackCore {
|
||||
|
||||
class CPlane;
|
||||
class ISimulator;
|
||||
|
||||
union FS_PBH {
|
||||
quint32 pbh;
|
||||
struct {
|
||||
quint32 unused : 1;
|
||||
quint32 onground : 1;
|
||||
quint32 hdg : 10;
|
||||
quint32 bank : 10;
|
||||
quint32 pitch : 10;
|
||||
};
|
||||
};
|
||||
|
||||
class CMultiPlayer : public BlackMisc::CMessageHandler
|
||||
{
|
||||
public:
|
||||
CMultiPlayer();
|
||||
|
||||
//! Starts the multiplayer mode.
|
||||
void start ();
|
||||
|
||||
//! Stops the multiplayer mode.
|
||||
void stop ();
|
||||
|
||||
//! Returns true if the multiplayer mode has been started. Otherwise false. \sa start()
|
||||
/*!
|
||||
\return Return true if running, otherwise false.
|
||||
*/
|
||||
inline bool isRunning() const { return m_isRunning; }
|
||||
|
||||
//! This is the trigger, to do all frequent calculations and send everything to the simulator.
|
||||
//! CMultiPlayer does nothing by itself, the parent has to call this.
|
||||
void run();
|
||||
|
||||
//! Returns true the plane is known, othwewise false.
|
||||
/*!
|
||||
\return Return true if the given plane is in the hash map, otherwise false.
|
||||
*/
|
||||
bool isKnown(const QString &callsign) const;
|
||||
|
||||
//! Enables or disables the injection of AI planes
|
||||
/*!
|
||||
\param enable If enable is true, injection is enabled, otherwise it will be disabled
|
||||
*/
|
||||
void enableAIPlanes(bool enable);
|
||||
|
||||
//! Returns true if rendering of AI planes is enabled
|
||||
/*!
|
||||
\return Return true if enabled, otherwise false.
|
||||
*/
|
||||
bool areAIPlanesEnabled() const;
|
||||
|
||||
|
||||
//! Use this method if you need a specific plane object.
|
||||
/*!
|
||||
\param callsign Callsign of the players plane
|
||||
\return Returns the pointer to the Plane object.
|
||||
*/
|
||||
CPlane *getPlane ( const QString &callsign);
|
||||
|
||||
private:
|
||||
|
||||
void onPositionUpdate(const FSD::FSD_MSG_Plane_Position *plane_position);
|
||||
|
||||
void addPlane(CPlane *plane);
|
||||
|
||||
void removePlane(CPlane *plane);
|
||||
|
||||
bool needsToRemoved(CPlane *plane);
|
||||
|
||||
typedef QHash<QString, CPlane*> TPlaneManager;
|
||||
TPlaneManager m_multiplayer_planes;
|
||||
|
||||
bool m_isRunning;
|
||||
|
||||
bool m_enableAIPlanes;
|
||||
|
||||
ISimulator *m_simulator;
|
||||
};
|
||||
|
||||
} //! namespace BlackCore
|
||||
|
||||
#endif // MULTIPLAYER_H
|
||||
47
blacklib/include/blackcore/ned.h
Normal file
47
blacklib/include/blackcore/ned.h
Normal file
@@ -0,0 +1,47 @@
|
||||
//! Copyright (C) 2013 Roland Winklmeier
|
||||
//! 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/
|
||||
|
||||
#ifndef VECTOR_NED_H
|
||||
#define VECTOR_NED_H
|
||||
|
||||
#include "vector_3d.h"
|
||||
#include "vector_geo.h"
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
|
||||
class CEcef;
|
||||
|
||||
class CNed : public CVector3D
|
||||
{
|
||||
public:
|
||||
CNed();
|
||||
CNed(CVectorGeo &pos, double N, double E, double D);
|
||||
|
||||
double North() const {return v[0];}
|
||||
|
||||
double East() const {return v[1];}
|
||||
|
||||
double Down() const {return v[2];}
|
||||
|
||||
CVectorGeo position() const { return m_position; }
|
||||
|
||||
void setNorth(const double num) { v[0] = num; }
|
||||
|
||||
void setEast(const double num) { v[1] = num; }
|
||||
|
||||
void setDown(const double num) { v[2] = num; }
|
||||
|
||||
void setPosition(const CVectorGeo &pos ) { m_position = pos; }
|
||||
|
||||
CEcef toECEF();
|
||||
|
||||
private:
|
||||
CVectorGeo m_position;
|
||||
};
|
||||
|
||||
} // namespace BlackCore
|
||||
|
||||
#endif // VECTOR_NED_H
|
||||
52
blacklib/include/blackcore/plane.h
Normal file
52
blacklib/include/blackcore/plane.h
Normal file
@@ -0,0 +1,52 @@
|
||||
//! Copyright (C) 2013 Roland Winklmeier
|
||||
//! 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/
|
||||
|
||||
#ifndef PLANE_H
|
||||
#define PLANE_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace BlackCore {
|
||||
|
||||
class ISimulator;
|
||||
class CInterpolator;
|
||||
|
||||
class CPlane
|
||||
{
|
||||
public:
|
||||
|
||||
enum ESquawkMode {Standby = 'S',
|
||||
Charlie = 'N',
|
||||
Ident = 'Y'};
|
||||
|
||||
CPlane();
|
||||
CPlane(const QString &callsign, ISimulator *driver);
|
||||
|
||||
|
||||
|
||||
void addPosition(const CVectorGeo &position, double groundVelocity, double heading, double pitch, double bank);
|
||||
|
||||
//! Returns the callsign of the multiplayer plane
|
||||
/*!
|
||||
\return callsign.
|
||||
*/
|
||||
inline QString& Callsign() { return m_callsign; }
|
||||
|
||||
void render();
|
||||
|
||||
double getLastUpdateTime();
|
||||
|
||||
private:
|
||||
|
||||
QString m_callsign;
|
||||
|
||||
CInterpolator *m_interpolator;
|
||||
|
||||
ISimulator *m_driver;
|
||||
};
|
||||
|
||||
} // namespace BlackCore
|
||||
|
||||
#endif // PLANE_H
|
||||
16
blacklib/include/blackcore/sim_callbacks.h
Normal file
16
blacklib/include/blackcore/sim_callbacks.h
Normal file
@@ -0,0 +1,16 @@
|
||||
//! Copyright (C) 2013 Roland Winklmeier
|
||||
//! 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/
|
||||
|
||||
#ifndef SIM_CALLBACKS_H
|
||||
#define SIM_CALLBACKS_H
|
||||
|
||||
typedef void (* cbChangedRadioFreq)(const int radioNumber, const QString &frequency);
|
||||
typedef void (* cbChangedGearPosition)(const int percentage);
|
||||
typedef void (* cbChangedLights)(const int map);
|
||||
typedef void (* cbSimStarted)(const bool status);
|
||||
typedef void (* cbChangedAircraftType)(const QString &type);
|
||||
typedef void (* cbChangedFlaps)(const int percentage);
|
||||
|
||||
#endif // CALLBACKS_H
|
||||
135
blacklib/include/blackcore/simulator.h
Normal file
135
blacklib/include/blackcore/simulator.h
Normal file
@@ -0,0 +1,135 @@
|
||||
//! Copyright (C) 2013 Roland Winklmeier
|
||||
//! 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/
|
||||
|
||||
#ifndef SIMULATOR_H
|
||||
#define SIMULATOR_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include <blackcore/sim_callbacks.h>
|
||||
|
||||
#include "blackcore/vector_geo.h"
|
||||
class CLibraryContext;
|
||||
|
||||
#define SHARED_LIBRARY_NAME_FS9 "bb_driver_fs9"
|
||||
#define SHARED_LIBRARY_NAME_FSX "bb_driver_fsx"
|
||||
#define SHARED_LIBRARY_NAME_XPLANE "bb_driver_xplane"
|
||||
|
||||
namespace BlackCore {
|
||||
|
||||
class CVector3D;
|
||||
class CVectorGEO;
|
||||
class IContext;
|
||||
|
||||
class ISimulator
|
||||
{
|
||||
public:
|
||||
|
||||
/// Version of the driver interface. To increment when the interface change.
|
||||
static const quint32 InterfaceVersionMajor;
|
||||
static const quint32 InterfaceVersionMinor;
|
||||
|
||||
|
||||
enum ESimulator { FS9 = 0,
|
||||
FSX,
|
||||
XPLANE};
|
||||
|
||||
ISimulator(void) {}
|
||||
virtual ~ISimulator() {}
|
||||
|
||||
virtual void setLibraryContext(IContext *context) = 0;
|
||||
|
||||
////////////////////////////////
|
||||
// Global section
|
||||
////////////////////////////////
|
||||
|
||||
virtual int init() = 0;
|
||||
|
||||
virtual int connectTo() = 0;
|
||||
|
||||
// Callback when the Simulation starts
|
||||
virtual void setcbSimStarted(cbSimStarted func, void *context);
|
||||
|
||||
virtual bool isRunning() = 0;
|
||||
|
||||
virtual QString getLastErrorMessage() = 0;
|
||||
|
||||
virtual qint32 sendTextMessage(const QString &text) = 0;
|
||||
|
||||
////////////////////////////////
|
||||
// Remote plane section
|
||||
////////////////////////////////
|
||||
|
||||
virtual qint32 addPlane(const QString& callsign, const QString &type, const CVectorGEO * const pos, const double groundSpeed) = 0;
|
||||
|
||||
virtual bool removePlane(const qint32 id) = 0;
|
||||
|
||||
virtual bool updatePositionAndSpeed(const qint32 id, const CVectorGEO * const pos, const double groundSpeed) = 0;
|
||||
|
||||
virtual bool setGear(const qint32 id, const qint32 percentage) = 0;
|
||||
|
||||
virtual bool setFlaps(const qint32 id, const qint32 percentage) = 0;
|
||||
|
||||
virtual bool setLights(const qint32 id, const qint32 map) = 0;
|
||||
|
||||
////////////////////////////////
|
||||
// User plane section
|
||||
////////////////////////////////
|
||||
|
||||
// Callback frequency tuner
|
||||
virtual void setChangedRadioFreq(cbChangedRadioFreq func, void * context);
|
||||
|
||||
// Callback when the gear is moving
|
||||
virtual void setcbChangedGearPosition(cbChangedGearPosition func, void *context);
|
||||
|
||||
// Callback if the user switched on/off a light
|
||||
virtual void setcbChangedLights(cbChangedLights func, void *context);
|
||||
|
||||
// Callback, when the Aircraft is set or gets changed
|
||||
virtual void setcbChangedAircraftType(cbChangedAircraftType func, void *context);
|
||||
|
||||
// Callback, when the Flaps are moving
|
||||
virtual void setcbChangedFlaps(cbChangedFlaps func, void *context);
|
||||
|
||||
// This one is called regular and when we actually need it, therefor not a callback
|
||||
virtual double getUserSpeed() const = 0;
|
||||
|
||||
// This one is called regular and when we actually need it, therefor not a callback
|
||||
virtual CVectorGEO getUserPosition() const = 0;
|
||||
|
||||
// This one is called regular and when we actually need it, therefor not a callback
|
||||
virtual qint32 getUserPitch() const = 0;
|
||||
|
||||
// This one is called regular and when we actually need it, therefor not a callback
|
||||
virtual qint32 getUserBank() const = 0;
|
||||
|
||||
// This one is called regular and when we actually need it, therefor not a callback
|
||||
virtual qint32 getUserHeading() const = 0;
|
||||
|
||||
// This one is called regular and when we actually need it, therefor not a callback
|
||||
virtual qint32 getUserPitchBankHeading() const = 0;
|
||||
|
||||
virtual bool isOnGround() const = 0;
|
||||
|
||||
static ISimulator *createDriver(ESimulator sim);
|
||||
|
||||
protected:
|
||||
|
||||
CLibraryContext * mLibraryContext;
|
||||
|
||||
cbSimStarted mSimStarted;
|
||||
cbChangedRadioFreq mChangedRadioFreq;
|
||||
cbChangedGearPosition mChangedGearPosition;
|
||||
cbChangedLights mChangedLights;
|
||||
cbChangedAircraftType mChangedAircraftType;
|
||||
cbChangedFlaps mChangedFlaps;
|
||||
|
||||
void *m_CallbackContext;
|
||||
|
||||
};
|
||||
|
||||
} //! namespace BlackCore
|
||||
|
||||
#endif // SIMULATOR_H
|
||||
73
blacklib/include/blackcore/vector_3d.h
Normal file
73
blacklib/include/blackcore/vector_3d.h
Normal file
@@ -0,0 +1,73 @@
|
||||
//! Copyright (C) 2013 Roland Winklmeier
|
||||
//! 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/
|
||||
|
||||
#include <qglobal.h>
|
||||
|
||||
#ifndef VECTOR_3D_H
|
||||
#define VECTOR_3D_H
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
|
||||
class CMatrix3D;
|
||||
|
||||
class CVector3D
|
||||
{
|
||||
public:
|
||||
CVector3D();
|
||||
CVector3D(double x, double y, double z);
|
||||
CVector3D( const CVector3D & other);
|
||||
|
||||
double X() const {return v[0];}
|
||||
|
||||
double Y() const {return v[1];}
|
||||
|
||||
double Z() const {return v[2];}
|
||||
|
||||
void setX(const double num) { v[0] = num; }
|
||||
|
||||
void setY(const double num) { v[1] = num; }
|
||||
|
||||
void setZ(const double num) { v[2] = num; }
|
||||
|
||||
double getElement(qint8 row) const;
|
||||
|
||||
void print();
|
||||
|
||||
void zeros();
|
||||
|
||||
CVector3D & operator +=(const CVector3D &rhs);
|
||||
CVector3D & operator -=(const CVector3D &rhs);
|
||||
|
||||
CVector3D & operator = (const CVector3D &rhs);
|
||||
|
||||
CVector3D operator +(const CVector3D &rhs);
|
||||
CVector3D operator -(const CVector3D &rhs);
|
||||
|
||||
bool operator ==(const CVector3D &rhs);
|
||||
bool operator !=(const CVector3D &rhs);
|
||||
|
||||
//double crossProduct(qint32 );
|
||||
|
||||
CVector3D & operator *=(const CVector3D &rhs);
|
||||
CVector3D operator *( const CVector3D &rhs);
|
||||
|
||||
CVector3D & operator *=( const double rhs);
|
||||
CVector3D operator *( const double rhs);
|
||||
|
||||
CVector3D & operator /=( const double rhs);
|
||||
CVector3D operator /( const double rhs);
|
||||
|
||||
double magnitude();
|
||||
|
||||
protected:
|
||||
double v[3];
|
||||
|
||||
friend class CMatrix3D;
|
||||
};
|
||||
|
||||
} //! namespace BlackCore
|
||||
|
||||
#endif // VECTOR_3D_H
|
||||
56
blacklib/include/blackcore/vector_geo.h
Normal file
56
blacklib/include/blackcore/vector_geo.h
Normal file
@@ -0,0 +1,56 @@
|
||||
//! Copyright (C) 2013 Roland Winklmeier
|
||||
//! 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/
|
||||
|
||||
#ifndef VECTOR_GEO_H
|
||||
#define VECTOR_GEO_H
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
|
||||
class CEcef;
|
||||
|
||||
class CVectorGeo
|
||||
{
|
||||
public:
|
||||
CVectorGeo();
|
||||
CVectorGeo(double lat, double lon, double alt);
|
||||
CVectorGeo( const CVectorGeo &other );
|
||||
|
||||
void setLatitude( double latitude)
|
||||
{
|
||||
m_latitude = latitude;
|
||||
}
|
||||
|
||||
void setLongitude( double longitude)
|
||||
{
|
||||
m_longitude = longitude;
|
||||
}
|
||||
|
||||
void setAltitude( double altitude)
|
||||
{
|
||||
m_altitude = altitude;
|
||||
}
|
||||
|
||||
double latitude() const {return m_latitude;}
|
||||
double longitude() const {return m_longitude;}
|
||||
double altitude() const {return m_altitude;}
|
||||
|
||||
CEcef toCartesian();
|
||||
|
||||
void zeros();
|
||||
|
||||
void print();
|
||||
|
||||
CVectorGeo & operator = (const CVectorGeo &rhs);
|
||||
|
||||
private:
|
||||
double m_latitude;
|
||||
double m_longitude;
|
||||
double m_altitude;
|
||||
};
|
||||
|
||||
} // namespace BlackCore
|
||||
|
||||
#endif // VECTOR_GEO_H
|
||||
Reference in New Issue
Block a user