Skip to content

Commit

Permalink
Initial work on Condor data source. Still WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
vranki committed May 22, 2018
1 parent 18d3e8b commit ca5ce54
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 7 deletions.
10 changes: 10 additions & 0 deletions extplane-transformer/datasources/DataSourceCondor.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import QtQuick 2.0
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.0

TextArea {
Layout.fillWidth: true
Layout.fillHeight: true
readOnly: true
text: transformer.dataSource ? transformer.dataSource.helpText : ""
}
89 changes: 89 additions & 0 deletions extplane-transformer/datasources/condordatasource.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#include "condordatasource.h"
#include <QNetworkDatagram>
#include <QDebug>
#include <datarefs/dataref.h>

CondorDatasource::CondorDatasource() : DataSource() {
m_port = 55278;

m_supportedRefs << "sim/cockpit2/gauges/indicators/heading_electric_deg_mag_pilot"
<< "sim/cockpit2/gauges/indicators/airspeed_kts_pilot"
<< "sim/cockpit2/gauges/indicators/pitch_vacuum_deg_pilot"
<< "sim/cockpit2/gauges/indicators/roll_vacuum_deg_pilot"
<< "sim/flightmodel/misc/h_ind"
<< "sim/flightmodel/position/vh_ind"
<< "sim/cockpit2/gauges/indicators/slip_deg";
}


void CondorDatasource::connectToSource() {
setNetworkError(QString());

connect(&m_udpSocket, &QUdpSocket::readyRead, this, &CondorDatasource::readPendingDatagrams);
if(m_udpSocket.bind(QHostAddress::LocalHost, m_port)) {
setHelpText(QString("Listening to UDP transmissions on port %1. Please run Condor.\nSee config help at http://www.condorsoaring.com/manual/#simkits-and-udp-outputs").arg(m_port));
} else {
setNetworkError(QString("Unable to bind to UDP port %1!").arg(m_port));
}
}

void CondorDatasource::readPendingDatagrams() {
while (m_udpSocket.hasPendingDatagrams()) {
QNetworkDatagram datagram = m_udpSocket.receiveDatagram();
QString data = QString::fromUtf8(datagram.data());
qDebug() << Q_FUNC_INFO << "RX datagram" << data;

QStringList lines = data.split("\n");
for(QString line : lines) {
QStringList splitLine = line.split("=");
if(splitLine.length() == 2) {
QString param = splitLine[0];
QString value = splitLine[1];
rxValue(param, value);
}
}
}
}

void CondorDatasource::rxValue(QString &param, QString &value) {
qDebug() << Q_FUNC_INFO << param << value;
}

DataRef *CondorDatasource::subscribeRef(QString &name)
{
if(m_supportedRefs.contains(name)) {
FloatDataRef *newRef = new FloatDataRef(this, name, nullptr);
floatRefs.append(newRef);
return newRef;
}
return nullptr;
}

void CondorDatasource::unsubscribeRef(DataRef *ref)
{
qDebug() << Q_FUNC_INFO << ref->name();
if(ref->type() == extplaneRefTypeFloat)
floatRefs.removeOne(qobject_cast<FloatDataRef*> (ref));
ref->deleteLater();
}

void CondorDatasource::updateDataRef(DataRef *ref)
{}

void CondorDatasource::changeDataRef(DataRef *ref)
{}

void CondorDatasource::keyStroke(int keyid)
{}

void CondorDatasource::buttonPress(int buttonid)
{}

void CondorDatasource::buttonRelease(int buttonid)
{}

void CondorDatasource::command(QString &name, extplaneCommandType type)
{}

bool CondorDatasource::loadSituation(QString sitFileLocation)
{}
47 changes: 47 additions & 0 deletions extplane-transformer/datasources/condordatasource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#ifndef CONDORDATASOURCE_H
#define CONDORDATASOURCE_H

#include <QObject>
#include <QUdpSocket>
#include <datarefs/floatdataref.h>
#include "datasource.h"

/**
* @brief The CondorDatasource class decodes Condor (2) UDP datagrams
*
* Use to transform data from Condor or Condor 2 (same protocol) to ExtPlane.
*
* @see https://github.com/kbobrowski/CondorUDP2COM/blob/master/CondorUDP2COM.py
*/

class CondorDatasource : public DataSource
{
Q_OBJECT

public:
explicit CondorDatasource();
virtual void connectToSource();
// From DataSource:
DataRef *subscribeRef(QString &name);
void unsubscribeRef(DataRef *ref);
void updateDataRef(DataRef *ref);
void changeDataRef(DataRef *ref);
void keyStroke(int keyid);
void buttonPress(int buttonid);
void buttonRelease(int buttonid);
void command(QString &name, extplaneCommandType type);
bool loadSituation(QString sitFileLocation);
//

private slots:
void readPendingDatagrams();

private:
void rxValue(QString &param, QString &value);
unsigned int m_port;
QUdpSocket m_udpSocket;
QStringList m_supportedRefs;
QList<FloatDataRef*> floatRefs; // All float datarefs used
};

#endif // CONDORDATASOURCE_H
2 changes: 1 addition & 1 deletion extplane-transformer/datasources/flightgeardatasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ DataRef *FlightGearDataSource::subscribeRef(QString &name)
{
if(refMap.contains(name)) {
QString fgRef = refMap.value(name);
FloatDataRef *newRef = new FloatDataRef(this, name, 0);
FloatDataRef *newRef = new FloatDataRef(this, name, nullptr);
floatRefs.append(newRef);
tcpClient.writeLine("subscribe " + fgRef);
return newRef;
Expand Down
2 changes: 2 additions & 0 deletions extplane-transformer/datasources/flightgeardatasource.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class FlightGearDataSource : public DataSource

public:
virtual void connectToSource();
// From DataSource:
DataRef *subscribeRef(QString &name);
void unsubscribeRef(DataRef *ref);
void updateDataRef(DataRef *ref);
Expand All @@ -36,6 +37,7 @@ class FlightGearDataSource : public DataSource
void buttonRelease(int buttonid);
void command(QString &name, extplaneCommandType type);
bool loadSituation(QString sitFileLocation);
//

private slots:
void sessionOpened();
Expand Down
6 changes: 4 additions & 2 deletions extplane-transformer/extplane-transformer.pro
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ SOURCES += main.cpp \
../extplane-server/datarefprovider.cpp \
extplanetransformer.cpp \
datasources/flightgeardatasource.cpp \
datasources/condordatasource.cpp \
../util/basictcpclient.cpp \
datasource.cpp
datasource.cpp \

HEADERS += \
extplanetransformer.h \
datasources/flightgeardatasource.h \
datasources/condordatasource.h \
../util/basictcpclient.h \
datasource.h
datasource.h \
12 changes: 8 additions & 4 deletions extplane-transformer/extplanetransformer.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include "extplanetransformer.h"
#include "datasources/flightgeardatasource.h"
#include "datasources/condordatasource.h"
#include <datarefprovider.h>

ExtplaneTransformer::ExtplaneTransformer() :
QObject()
, m_dataSource(nullptr)
{
m_dataSources << "None" << "FlightGear";
m_dataSources << "None" << "FlightGear" << "Condor";
m_dataSourceName = m_dataSources.first(); // None
emit dataSourcesChanged(m_dataSources);
}
Expand Down Expand Up @@ -50,8 +51,12 @@ void ExtplaneTransformer::setDataSourceName(const QString dataSource)
m_dataSourceName = dataSource;
if(m_dataSourceName == m_dataSources.first()) {
m_dataSource = nullptr;
} else {
} else if (m_dataSourceName == "FlightGear") {
m_dataSource = new FlightGearDataSource();
} else if (m_dataSourceName == "Condor") {
m_dataSource = new CondorDatasource();
}
if(m_dataSource) {
connect(m_dataSource, &DataSource::sourceNetworkError,
this, &ExtplaneTransformer::sourceNetworkErrorChanged);
}
Expand All @@ -61,8 +66,7 @@ void ExtplaneTransformer::setDataSourceName(const QString dataSource)
emit dataSourceChanged();
}

void ExtplaneTransformer::sourceNetworkErrorChanged(QString errorString)
{
void ExtplaneTransformer::sourceNetworkErrorChanged(QString errorString) {
m_networkError = errorString;
emit networkErrorChanged(errorString);
}
1 change: 1 addition & 0 deletions extplane-transformer/qml.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<file>main.qml</file>
<file>datasources/DataSourceFlightGear.qml</file>
<file>datasources/DataSourceNone.qml</file>
<file>datasources/DataSourceCondor.qml</file>
</qresource>
</RCC>

0 comments on commit ca5ce54

Please sign in to comment.