Commit 2dfa002e authored by lm's avatar lm

Added ports for FlightGear in/out

parent 5ab17db6
...@@ -236,6 +236,7 @@ HEADERS += src/MG.h \ ...@@ -236,6 +236,7 @@ HEADERS += src/MG.h \
src/comm/ProtocolInterface.h \ src/comm/ProtocolInterface.h \
src/comm/MAVLinkProtocol.h \ src/comm/MAVLinkProtocol.h \
src/comm/AS4Protocol.h \ src/comm/AS4Protocol.h \
src/comm/QGCFlightGearLink.h \
src/ui/CommConfigurationWindow.h \ src/ui/CommConfigurationWindow.h \
src/ui/SerialConfigurationWindow.h \ src/ui/SerialConfigurationWindow.h \
src/ui/MainWindow.h \ src/ui/MainWindow.h \
...@@ -364,6 +365,7 @@ SOURCES += src/main.cc \ ...@@ -364,6 +365,7 @@ SOURCES += src/main.cc \
src/comm/SerialSimulationLink.cc \ src/comm/SerialSimulationLink.cc \
src/comm/MAVLinkProtocol.cc \ src/comm/MAVLinkProtocol.cc \
src/comm/AS4Protocol.cc \ src/comm/AS4Protocol.cc \
src/comm/QGCFlightGearLink.cc \
src/ui/CommConfigurationWindow.cc \ src/ui/CommConfigurationWindow.cc \
src/ui/SerialConfigurationWindow.cc \ src/ui/SerialConfigurationWindow.cc \
src/ui/MainWindow.cc \ src/ui/MainWindow.cc \
......
...@@ -34,19 +34,20 @@ This file is part of the QGROUNDCONTROL project ...@@ -34,19 +34,20 @@ This file is part of the QGROUNDCONTROL project
#include <QMutexLocker> #include <QMutexLocker>
#include <iostream> #include <iostream>
#include "QGCFlightGearLink.h" #include "QGCFlightGearLink.h"
#include "LinkManager.h"
#include "QGC.h" #include "QGC.h"
#include <QHostInfo> #include <QHostInfo>
//#include <netinet/in.h>
QGCFlightGearLink::QGCFlightGearLink(QHostAddress host, quint16 port) QGCFlightGearLink::QGCFlightGearLink(QHostAddress host, quint16 port)
{ {
this->host = host; this->host = host;
this->port = port; this->port = port;
this->connectState = false; this->connectState = false;
// Set unique ID and add link to the list of links // Set unique ID and add link to the list of links
this->name = tr("FlightGear Link (port:%1)").arg(5401); this->name = tr("FlightGear Link (port:%1)").arg(port);
LinkManager::instance()->add(this); setRemoteHost(QString("127.0.0.1:%1").arg(port));
connect(&refreshTimer, SIGNAL(timeout()), this, SLOT(sendUAVUpdate()));
refreshTimer.start(20); // 50 Hz UAV -> Simulation update rate
} }
QGCFlightGearLink::~QGCFlightGearLink() QGCFlightGearLink::~QGCFlightGearLink()
...@@ -70,8 +71,8 @@ void QGCFlightGearLink::run() ...@@ -70,8 +71,8 @@ void QGCFlightGearLink::run()
void QGCFlightGearLink::setPort(int port) void QGCFlightGearLink::setPort(int port)
{ {
this->port = port; this->port = port;
disconnect(); disconnectSimulation();
connect(); connectSimulation();
} }
/** /**
...@@ -100,7 +101,7 @@ void QGCFlightGearLink::setRemoteHost(const QString& host) ...@@ -100,7 +101,7 @@ void QGCFlightGearLink::setRemoteHost(const QString& host)
currentHost = address; currentHost = address;
//qDebug() << "Address:" << address.toString(); //qDebug() << "Address:" << address.toString();
// Set port according to user input // Set port according to user input
currentPort = host.split(":"); currentPort = host.split(":").last().toInt();
} }
} }
else else
...@@ -114,12 +115,19 @@ void QGCFlightGearLink::setRemoteHost(const QString& host) ...@@ -114,12 +115,19 @@ void QGCFlightGearLink::setRemoteHost(const QString& host)
} }
} }
void QGCFlightGearLink::updateGlobalPosition(quint64 time, double lat, double lon, double alt)
{
}
void QGCFlightGearLink::sendUAVUpdate()
{
QString state("");
writeBytes(state.toAscii().constData(), state.length());
}
void QGCFlightGearLink::writeBytes(const char* data, qint64 size) void QGCFlightGearLink::writeBytes(const char* data, qint64 size)
{ {
// Broadcast to all connected systems
for (int h = 0; h < hosts.size(); h++)
{
quint16 currentPort = ports.at(h);
//#define QGCFlightGearLink_DEBUG //#define QGCFlightGearLink_DEBUG
#ifdef QGCFlightGearLink_DEBUG #ifdef QGCFlightGearLink_DEBUG
QString bytes; QString bytes;
...@@ -142,7 +150,6 @@ void QGCFlightGearLink::writeBytes(const char* data, qint64 size) ...@@ -142,7 +150,6 @@ void QGCFlightGearLink::writeBytes(const char* data, qint64 size)
qDebug() << "ASCII:" << ascii; qDebug() << "ASCII:" << ascii;
#endif #endif
socket->writeDatagram(data, size, currentHost, currentPort); socket->writeDatagram(data, size, currentHost, currentPort);
}
} }
/** /**
...@@ -164,7 +171,10 @@ void QGCFlightGearLink::readBytes() ...@@ -164,7 +171,10 @@ void QGCFlightGearLink::readBytes()
// FIXME TODO Check if this method is better than retrieving the data by individual processes // FIXME TODO Check if this method is better than retrieving the data by individual processes
QByteArray b(data, s); QByteArray b(data, s);
emit bytesReceived(this, b); //emit bytesReceived(this, b);
// Print string
qDebug() << "FG LINK GOT:" << QString(b);
// // Echo data for debugging purposes // // Echo data for debugging purposes
// std::cerr << __FILE__ << __LINE__ << "Received datagram:" << std::endl; // std::cerr << __FILE__ << __LINE__ << "Received datagram:" << std::endl;
...@@ -175,21 +185,6 @@ void QGCFlightGearLink::readBytes() ...@@ -175,21 +185,6 @@ void QGCFlightGearLink::readBytes()
// fprintf(stderr,"%02x ", v); // fprintf(stderr,"%02x ", v);
// } // }
// std::cerr << std::endl; // std::cerr << std::endl;
// Add host to broadcast list if not yet present
if (!hosts.contains(sender))
{
hosts.append(sender);
ports.append(senderPort);
// ports->insert(sender, senderPort);
}
else
{
int index = hosts.indexOf(sender);
ports.replace(index, senderPort);
}
} }
...@@ -208,15 +203,15 @@ qint64 QGCFlightGearLink::bytesAvailable() ...@@ -208,15 +203,15 @@ qint64 QGCFlightGearLink::bytesAvailable()
* *
* @return True if connection has been disconnected, false if connection couldn't be disconnected. * @return True if connection has been disconnected, false if connection couldn't be disconnected.
**/ **/
bool QGCFlightGearLink::disconnect() bool QGCFlightGearLink::disconnectSimulation()
{ {
delete socket; delete socket;
socket = NULL; socket = NULL;
connectState = false; connectState = false;
emit disconnected(); emit flightGearDisconnected();
emit connected(false); emit flightGearConnected(false);
return !connectState; return !connectState;
} }
...@@ -225,7 +220,7 @@ bool QGCFlightGearLink::disconnect() ...@@ -225,7 +220,7 @@ bool QGCFlightGearLink::disconnect()
* *
* @return True if connection has been established, false if connection couldn't be established. * @return True if connection has been established, false if connection couldn't be established.
**/ **/
bool QGCFlightGearLink::connect() bool QGCFlightGearLink::connectSimulation()
{ {
socket = new QUdpSocket(this); socket = new QUdpSocket(this);
...@@ -269,9 +264,9 @@ bool QGCFlightGearLink::connect() ...@@ -269,9 +264,9 @@ bool QGCFlightGearLink::connect()
//QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams())); //QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));
QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(readBytes())); QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(readBytes()));
emit connected(connectState); emit flightGearConnected(connectState);
if (connectState) { if (connectState) {
emit connected(); emit flightGearConnected();
connectionStartTime = QGC::groundTimeUsecs()/1000; connectionStartTime = QGC::groundTimeUsecs()/1000;
} }
...@@ -297,5 +292,5 @@ QString QGCFlightGearLink::getName() ...@@ -297,5 +292,5 @@ QString QGCFlightGearLink::getName()
void QGCFlightGearLink::setName(QString name) void QGCFlightGearLink::setName(QString name)
{ {
this->name = name; this->name = name;
emit nameChanged(this->name); // emit nameChanged(this->name);
} }
...@@ -36,6 +36,7 @@ This file is part of the QGROUNDCONTROL project ...@@ -36,6 +36,7 @@ This file is part of the QGROUNDCONTROL project
#include <QMap> #include <QMap>
#include <QMutex> #include <QMutex>
#include <QUdpSocket> #include <QUdpSocket>
#include <QTimer>
#include <LinkInterface.h> #include <LinkInterface.h>
#include <configuration.h> #include <configuration.h>
...@@ -45,8 +46,7 @@ class QGCFlightGearLink : public QThread ...@@ -45,8 +46,7 @@ class QGCFlightGearLink : public QThread
//Q_INTERFACES(QGCFlightGearLinkInterface:LinkInterface) //Q_INTERFACES(QGCFlightGearLinkInterface:LinkInterface)
public: public:
QGCFlightGearLink(QHostAddress host = QHostAddress::Any, quint16 port = 5401); QGCFlightGearLink(QHostAddress host = QHostAddress::Any, quint16 port = 49005);
//QGCFlightGearLink(QHostAddress host = "239.255.76.67", quint16 port = 7667);
~QGCFlightGearLink(); ~QGCFlightGearLink();
bool isConnected(); bool isConnected();
...@@ -63,12 +63,14 @@ public: ...@@ -63,12 +63,14 @@ public:
void run(); void run();
public slots: public slots:
void setAddress(QString address); // void setAddress(QString address);
void setPort(int port); void setPort(int port);
/** @brief Add a new host to broadcast messages to */ /** @brief Add a new host to broadcast messages to */
void addHost(const QString& host); void setRemoteHost(const QString& host);
/** @brief Remove a host from broadcasting messages to */ void updateGlobalPosition(quint64 time, double lat, double lon, double alt);
void removeHost(const QString& host); void sendUAVUpdate();
// /** @brief Remove a host from broadcasting messages to */
// void removeHost(const QString& host);
// void readPendingDatagrams(); // void readPendingDatagrams();
void readBytes(); void readBytes();
...@@ -79,13 +81,13 @@ public slots: ...@@ -79,13 +81,13 @@ public slots:
* @param size The size of the bytes array * @param size The size of the bytes array
**/ **/
void writeBytes(const char* data, qint64 length); void writeBytes(const char* data, qint64 length);
bool connect(); bool connectSimulation();
bool disconnect(); bool disconnectSimulation();
protected: protected:
QString name; QString name;
QHostAddress host; QHostAddress host;
QHostAddress currentHost QHostAddress currentHost;
quint16 currentPort; quint16 currentPort;
quint16 port; quint16 port;
int id; int id;
...@@ -101,11 +103,26 @@ protected: ...@@ -101,11 +103,26 @@ protected:
quint64 connectionStartTime; quint64 connectionStartTime;
QMutex statisticsMutex; QMutex statisticsMutex;
QMutex dataMutex; QMutex dataMutex;
QTimer refreshTimer;
void setName(QString name); void setName(QString name);
signals: signals:
// Signals are defined by LinkInterface /**
* @brief This signal is emitted instantly when the link is connected
**/
void flightGearConnected();
/**
* @brief This signal is emitted instantly when the link is disconnected
**/
void flightGearDisconnected();
/**
* @brief This signal is emitted instantly when the link status changes
**/
void flightGearConnected(bool connected);
}; };
......
...@@ -157,6 +157,11 @@ MainWindow::MainWindow(QWidget *parent): ...@@ -157,6 +157,11 @@ MainWindow::MainWindow(QWidget *parent):
joystickWidget = 0; joystickWidget = 0;
joystick = new JoystickInput(); joystick = new JoystickInput();
// Connect flighgear test link
// FIXME MOVE INTO UAV OBJECT
fgLink = new QGCFlightGearLink();
fgLink->connectSimulation();
// Load Toolbar // Load Toolbar
toolBar = new QGCToolBar(this); toolBar = new QGCToolBar(this);
this->addToolBar(toolBar); this->addToolBar(toolBar);
......
...@@ -75,6 +75,7 @@ This file is part of the QGROUNDCONTROL project ...@@ -75,6 +75,7 @@ This file is part of the QGROUNDCONTROL project
#include "SlugsPadCameraControl.h" #include "SlugsPadCameraControl.h"
#include "UASControlParameters.h" #include "UASControlParameters.h"
#include "QGCFlightGearLink.h"
class QGCMapTool; class QGCMapTool;
...@@ -445,6 +446,7 @@ protected: ...@@ -445,6 +446,7 @@ protected:
QGC_MAINWINDOW_STYLE currentStyle; QGC_MAINWINDOW_STYLE currentStyle;
Qt::WindowStates windowStateVal; Qt::WindowStates windowStateVal;
bool lowPowerMode; ///< If enabled, QGC reduces the update rates of all widgets bool lowPowerMode; ///< If enabled, QGC reduces the update rates of all widgets
QGCFlightGearLink* fgLink;
private: private:
Ui::MainWindow ui; Ui::MainWindow ui;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment