Skip to content

Commit

Permalink
Version 1001 - Fixes data dateref issues and crash when exiting X-Pla…
Browse files Browse the repository at this point in the history
…ne. Adds non-functional menu entry.
  • Loading branch information
vranki committed Sep 9, 2019
1 parent 141e806 commit b695ff2
Show file tree
Hide file tree
Showing 27 changed files with 409 additions and 264 deletions.
24 changes: 9 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
A plugin for X-Plane and other simulators that allows commanding the simulation from
external programs through an easy-to-use TCP protocol.

Current version 1001

## Supported simulators ##

* X-Plane 9, 10 & 11 - native support. X-Plane 11 currently only tested.
Expand Down Expand Up @@ -59,32 +61,24 @@ License:

## Downloads ##

### Ext-Plane Plugin ###
### ExtPlane Plugin ###

* Up to date Linux & windows versions
* GitHub releases page: https://github.com/vranki/ExtPlane/releases/
* Older version: Linux, Windows, OS-X (32bit & 64bit), 8MB
* [https://github.com/dankrusi/ExtPlane-Panel/releases/tag/v0.1](https://github.com/dankrusi/ExtPlane-Panel/releases/tag/v0.1)

### Ext-Plane Plugin + Panel ###

Older versions
## Installing ##

* Linux 32bit, 15MB
* [https://github.com/dankrusi/ExtPlane-Panel/releases/download/v0.1/ExtPlane-Panel-v0.1-Linux32.zip](https://github.com/dankrusi/ExtPlane-Panel/releases/download/v0.1/ExtPlane-Panel-v0.1-Linux32.zip)
* Linux 64bit, 15MB
* [https://github.com/dankrusi/ExtPlane-Panel/releases/download/v0.1/ExtPlane-Panel-v0.1-Linux64.zip](https://github.com/dankrusi/ExtPlane-Panel/releases/download/v0.1/ExtPlane-Panel-v0.1-Linux64.zip)
* Windows 32bit, 12MB
* [https://github.com/dankrusi/ExtPlane-Panel/releases/download/v0.1/ExtPlane-Panel-v0.1-Win32.zip](https://github.com/dankrusi/ExtPlane-Panel/releases/download/v0.1/ExtPlane-Panel-v0.1-Win32.zip)
* Windows 64bit, 13MB
* [https://github.com/dankrusi/ExtPlane-Panel/releases/download/v0.1/ExtPlane-Panel-v0.1-Win64.zip](https://github.com/dankrusi/ExtPlane-Panel/releases/download/v0.1/ExtPlane-Panel-v0.1-Win64.zip)
* OS-X 64bit, 15MB
* [https://github.com/dankrusi/ExtPlane-Panel/releases/download/v0.1/ExtPlane-Panel-v0.1-OSX64.zip](https://github.com/dankrusi/ExtPlane-Panel/releases/download/v0.1/ExtPlane-Panel-v0.1-OSX64.zip)
This is a fat plugin - just copy "extplane" directory under X-Plane/Resources/plugins.

Start X-Plane. You should see ExtPlane menu entry in plugins menu.

## Building ##

ExtPlane uses the Qt Framework for cross-platform compatibility. Before building you'll need to setup Qt 5 or greater to compile. You'll also need to check out the X-Plane SDK (http://www.xsquawkbox.net/xpsdk/mediawiki/Download) to the directory next to the ExtPlane directory. The X-Plane SDK can be either at ~/SDK or ../SDK or ../XPlaneSDK relative to the ExtPlane directory.
ExtPlane uses the Qt Framework for cross-platform compatibility. Before building you'll need to setup Qt 5 or greater to compile. You'll
also need to check out the X-Plane SDK (http://www.xsquawkbox.net/xpsdk/mediawiki/Download) to the directory next to the ExtPlane directory.
The X-Plane SDK can be either at ~/SDK or ../SDK or ../XPlaneSDK relative to the ExtPlane directory.

The requirements for ExtPlane are as follows:
* C++ Toolchain
Expand Down
60 changes: 40 additions & 20 deletions clients/extplane-client-qt/clientdataref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,86 @@
#include "extplaneclient.h"

ClientDataRef::ClientDataRef(QObject *parent, QString newName, double accuracy) : QObject(parent)
, m_name(newName)
, m_accuracy(accuracy)
, m_subscribers(0)
, m_client(nullptr) {
m_values.reserve(1); // Always at least 1 size
, m_name(newName)
, m_accuracy(accuracy)
, m_subscribers(0)
, m_client(nullptr)
, m_changedOnce(false)
{ }

ClientDataRef::~ClientDataRef() {
unsubscribe();
}

QString& ClientDataRef::name() {
return m_name;
}

void ClientDataRef::setName(QString &name)
{
void ClientDataRef::setName(QString &name) {
if (m_name == name)
return;

m_name = name;
emit nameChanged(m_name);
}

QString ClientDataRef::value()
{
QString ClientDataRef::value() {
return m_values.isEmpty() ? "" : m_values.first();
}

ExtPlaneClient *ClientDataRef::client() const
{
ExtPlaneClient *ClientDataRef::client() const {
return m_client;
}

void ClientDataRef::setClient(ExtPlaneClient *client)
{
void ClientDataRef::setClient(ExtPlaneClient *client) {
if (m_client == client)
return;

m_client = client;
if(m_client) {
connect(m_client, &ExtPlaneClient::destroyed, this, &ClientDataRef::clientDestroyed);
}
emit clientChanged(m_client);
}

void ClientDataRef::clientDestroyed() {
setClient(nullptr);
}

void ClientDataRef::setDataFormat(QString dataFormat) {
if (m_dataFormat == dataFormat)
return;

m_dataFormat = dataFormat;
emit dataFormatChanged(m_dataFormat);
}

QStringList& ClientDataRef::values() {
return m_values;
}

void ClientDataRef::updateValue(QString newValue) {
if(!m_values.isEmpty() && newValue == m_values.first()) return;
if(m_changedOnce && !m_values.isEmpty() && newValue == m_values.first()) return;

if(m_values.isEmpty()) {
m_values.push_back(newValue);
} else {
m_values.replace(0, newValue);
}
m_changedOnce = true;
emit changed(this);
}

void ClientDataRef::updateValue(QStringList &newValues) {
if(newValues == m_values) return;
if(m_changedOnce && newValues == m_values) return;
m_values = newValues;
m_changedOnce = true;
emit changed(this);
}

void ClientDataRef::setValue(QString _newValue, int index) {
if(m_values.size() < index + 1)
m_values.reserve(index+1);
while(m_values.size() < index + 1) // Resize list if needed
m_values.append(QString(""));
m_values[index] = _newValue;
emit valueSet(this);
}
Expand All @@ -80,8 +97,7 @@ double ClientDataRef::accuracy() {
return m_accuracy;
}

void ClientDataRef::setAccuracy(double accuracy)
{
void ClientDataRef::setAccuracy(double accuracy) {
// http://doc.qt.io/qt-5/qtglobal.html#qFuzzyCompare
if (qFuzzyIsNull(accuracy)) {
if (qFuzzyCompare(1 + m_accuracy, 1 + accuracy))
Expand All @@ -104,7 +120,11 @@ void ClientDataRef::setSubscribers(int sub) {
}

void ClientDataRef::unsubscribe() {
emit unsubscribed(this);
if(m_client) emit unsubscribed(this);
}

QString ClientDataRef::dataFormat() const {
return m_dataFormat;
}

bool ClientDataRef::isArray() {
Expand Down
17 changes: 17 additions & 0 deletions clients/extplane-client-qt/clientdataref.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,25 @@ class ExtPlaneClient;
* Never call delete or deleteLater() on this - memory is managed by ExtPlaneConnection.
*
* This is supposed to be used from C++. See DataRef class for QML friendly version.
*
* dataFormat variable contains hints how to interpret data in ambigous situations.
*
* Current values:
* (empty) - default behavior
* (binary) - Returns binary data dataref in an array of bytes, that you get with values()
*
*/
class ClientDataRef : public QObject {
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(QString value READ value WRITE setValue NOTIFY changed)
Q_PROPERTY(QStringList values READ values WRITE setValues NOTIFY changed)
Q_PROPERTY(double accuracy READ accuracy WRITE setAccuracy NOTIFY accuracyChanged)
Q_PROPERTY(QString dataFormat READ dataFormat WRITE setDataFormat NOTIFY dataFormatChanged)

public:
explicit ClientDataRef(QObject *parent, QString newName, double accuracy=0);
virtual ~ClientDataRef();
QString& name();
QStringList& values(); // Returns all values
double accuracy();
Expand All @@ -38,13 +47,15 @@ class ClientDataRef : public QObject {
void setSubscribers(int sub);
bool isArray();
void unsubscribe(); // Call to unsubscribe ref.
QString dataFormat() const;

public slots:
void setName(QString &name);
void setAccuracy(double accuracy);
void setValue(QString _newValue, int index=0); // Set value (from client)
void setValues(QStringList values); // Set full array (from client)
void setClient(ExtPlaneClient* client);
void setDataFormat(QString dataFormat);

signals:
void changed(ClientDataRef *ref); // Emitted when simulator updates value
Expand All @@ -53,13 +64,19 @@ public slots:
void nameChanged(QString name);
void accuracyChanged(double accuracy);
void clientChanged(ExtPlaneClient* client);
void dataFormatChanged(QString dataFormat);

private slots:
void clientDestroyed();

private:
QString m_name;
QStringList m_values; // Length 1 if not array
double m_accuracy;
int m_subscribers;
ExtPlaneClient* m_client;
QString m_dataFormat;
bool m_changedOnce; // False until first update sent.
};

#endif // CLIENTDATAREF_H
52 changes: 38 additions & 14 deletions clients/extplane-client-qt/dataref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@
#include <extplaneclient.h>

DataRef::DataRef(QObject *parent) : QObject(parent)
, m_clientDataRef(nullptr)
, m_client(nullptr)
, m_clientDataRef(nullptr)
, m_client(nullptr)
, m_accuracy(0)
{
// Connect both valueset and changed to valuechanged
connect(this, &DataRef::valueSet, this, &DataRef::valueChanged);
connect(this, &DataRef::changed, this, &DataRef::valueChanged);

setClient(&ExtPlaneClient::instance());
}

void DataRef::subscribeIfPossible()
{
DataRef::~DataRef() {
if(m_clientDataRef) m_clientDataRef->unsubscribe();
}

void DataRef::subscribeIfPossible() {
if(m_clientDataRef)
return;

Expand All @@ -22,11 +30,14 @@ void DataRef::subscribeIfPossible()
if(!m_clientDataRef) {
qDebug() << Q_FUNC_INFO << "Unable to subscribe to " << m_name;
} else {
m_clientDataRef->setDataFormat(m_dataFormat);
connect(m_clientDataRef, &ClientDataRef::changed, this, &DataRef::changed);
connect(m_clientDataRef, &ClientDataRef::valueSet, this, &DataRef::valueSet);
connect(m_clientDataRef, &ClientDataRef::unsubscribed, this, &DataRef::unsubscribed);
connect(m_clientDataRef, &ClientDataRef::nameChanged, this, &DataRef::nameChanged);
connect(m_clientDataRef, &ClientDataRef::accuracyChanged, this, &DataRef::accuracyChanged);
connect(m_clientDataRef, &ClientDataRef::dataFormatChanged, this, &DataRef::dataFormatChanged);
connect(m_clientDataRef, &ClientDataRef::destroyed, this, &DataRef::clientDatarefDestroyed);
}
}
}
Expand All @@ -35,27 +46,33 @@ QString& DataRef::name() {
return m_name;
}

void DataRef::setName(QString &name)
{
void DataRef::setName(QString &name) {
if (m_name == name)
return;

m_name = name;
emit nameChanged(m_name);

if(m_clientDataRef) { // Unsub old dataref..
m_clientDataRef->unsubscribe();
m_clientDataRef = nullptr;
}
subscribeIfPossible();
}

QString DataRef::value()
{
QString DataRef::value() {
return m_clientDataRef ? m_clientDataRef->value() : "";
}

ExtPlaneClient *DataRef::client() const {
return m_client;
}

void DataRef::setClient(ExtPlaneClient *client)
{
QString DataRef::dataFormat() const {
return m_clientDataRef ? m_clientDataRef->dataFormat() : "";
}

void DataRef::setClient(ExtPlaneClient *client) {
if (m_client == client)
return;

Expand All @@ -71,6 +88,15 @@ void DataRef::setDataRefProvider() {
if(client()->datarefProvider()) subscribeIfPossible();
}

void DataRef::setDataFormat(QString dataFormat) {
m_dataFormat = dataFormat;
if(m_clientDataRef) m_clientDataRef->setDataFormat(m_dataFormat);
}

void DataRef::clientDatarefDestroyed() {
m_clientDataRef = nullptr;
}

QStringList& DataRef::values() {
return m_clientDataRef ? m_clientDataRef->values() : m_emptyStringList;
}
Expand All @@ -79,17 +105,15 @@ void DataRef::setValue(QString _newValue, int index) {
if(m_clientDataRef) m_clientDataRef->setValue(_newValue, index);
}

void DataRef::setValues(QStringList values)
{
void DataRef::setValues(QStringList values) {
if(m_clientDataRef) m_clientDataRef->setValues(values);
}

double DataRef::accuracy() {
return m_clientDataRef ? m_clientDataRef->accuracy() : m_accuracy;
}

void DataRef::setAccuracy(double accuracy)
{
void DataRef::setAccuracy(double accuracy) {
m_accuracy = accuracy;
if(m_clientDataRef) m_clientDataRef->setAccuracy(accuracy);
}
Loading

0 comments on commit b695ff2

Please sign in to comment.