mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-03-22 14:19:42 +01:00
GCS - added an UDP UAVTalk mirror.
This commit is contained in:
parent
d612f67b8d
commit
bc5a1dd43b
@ -39,6 +39,7 @@
|
||||
#include <QtCore/QSettings>
|
||||
|
||||
#include "ui_generalsettings.h"
|
||||
#include <QKeyEvent>
|
||||
|
||||
using namespace Utils;
|
||||
using namespace Core::Internal;
|
||||
@ -47,7 +48,8 @@ GeneralSettings::GeneralSettings():
|
||||
m_saveSettingsOnExit(true),
|
||||
m_dialog(0),
|
||||
m_autoConnect(true),
|
||||
m_autoSelect(true)
|
||||
m_autoSelect(true),
|
||||
m_useUDPMirror(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -107,18 +109,21 @@ void GeneralSettings::fillLanguageBox() const
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QWidget *GeneralSettings::createPage(QWidget *parent)
|
||||
{
|
||||
m_page = new Ui::GeneralSettings();
|
||||
QWidget *w = new QWidget(parent);
|
||||
globalSettingsWidget *w = new globalSettingsWidget(parent);
|
||||
connect(w,SIGNAL(showHidden()),this,SLOT(showHidden()));
|
||||
m_page->setupUi(w);
|
||||
m_page->labelUDP->setVisible(false);
|
||||
m_page->cbUseUDPMirror->setVisible(false);
|
||||
|
||||
fillLanguageBox();
|
||||
connect(m_page->checkAutoConnect,SIGNAL(stateChanged(int)),this,SLOT(slotAutoConnect(int)));
|
||||
m_page->checkBoxSaveOnExit->setChecked(m_saveSettingsOnExit);
|
||||
m_page->checkAutoConnect->setChecked(m_autoConnect);
|
||||
m_page->checkAutoSelect->setChecked(m_autoSelect);
|
||||
m_page->cbUseUDPMirror->setChecked(m_useUDPMirror);
|
||||
m_page->colorButton->setColor(StyleHelper::baseColor());
|
||||
|
||||
connect(m_page->resetButton, SIGNAL(clicked()),
|
||||
@ -135,6 +140,7 @@ void GeneralSettings::apply()
|
||||
StyleHelper::setBaseColor(m_page->colorButton->color());
|
||||
|
||||
m_saveSettingsOnExit = m_page->checkBoxSaveOnExit->isChecked();
|
||||
m_useUDPMirror=m_page->cbUseUDPMirror->isChecked();
|
||||
m_autoConnect = m_page->checkAutoConnect->isChecked();
|
||||
m_autoSelect = m_page->checkAutoSelect->isChecked();
|
||||
}
|
||||
@ -151,6 +157,7 @@ void GeneralSettings::readSettings(QSettings* qs)
|
||||
m_saveSettingsOnExit = qs->value(QLatin1String("SaveSettingsOnExit"),m_saveSettingsOnExit).toBool();
|
||||
m_autoConnect = qs->value(QLatin1String("AutoConnect"),m_autoConnect).toBool();
|
||||
m_autoSelect = qs->value(QLatin1String("AutoSelect"),m_autoSelect).toBool();
|
||||
m_useUDPMirror = qs->value(QLatin1String("UDPMirror"),m_useUDPMirror).toBool();
|
||||
qs->endGroup();
|
||||
}
|
||||
|
||||
@ -166,6 +173,7 @@ void GeneralSettings::saveSettings(QSettings* qs)
|
||||
qs->setValue(QLatin1String("SaveSettingsOnExit"), m_saveSettingsOnExit);
|
||||
qs->setValue(QLatin1String("AutoConnect"), m_autoConnect);
|
||||
qs->setValue(QLatin1String("AutoSelect"), m_autoSelect);
|
||||
qs->setValue(QLatin1String("UDPMirror"), m_useUDPMirror);
|
||||
qs->endGroup();
|
||||
}
|
||||
|
||||
@ -231,6 +239,11 @@ bool GeneralSettings::autoSelect() const
|
||||
return m_autoSelect;
|
||||
}
|
||||
|
||||
bool GeneralSettings::useUDPMirror() const
|
||||
{
|
||||
return m_useUDPMirror;
|
||||
}
|
||||
|
||||
void GeneralSettings::slotAutoConnect(int value)
|
||||
{
|
||||
if (value==Qt::Checked)
|
||||
@ -238,3 +251,19 @@ void GeneralSettings::slotAutoConnect(int value)
|
||||
else
|
||||
m_page->checkAutoSelect->setEnabled(true);
|
||||
}
|
||||
|
||||
void GeneralSettings::showHidden()
|
||||
{
|
||||
m_page->labelUDP->setVisible(true);
|
||||
m_page->cbUseUDPMirror->setVisible(true);
|
||||
}
|
||||
|
||||
globalSettingsWidget::globalSettingsWidget(QWidget *parent):QWidget(parent){}
|
||||
|
||||
void globalSettingsWidget::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if(event->key()==Qt::Key_F7)
|
||||
{
|
||||
emit showHidden();
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +58,7 @@ public:
|
||||
bool saveSettingsOnExit() const;
|
||||
bool autoConnect() const;
|
||||
bool autoSelect() const;
|
||||
bool useUDPMirror() const;
|
||||
void readSettings(QSettings* qs);
|
||||
void saveSettings(QSettings* qs);
|
||||
|
||||
@ -68,6 +69,7 @@ private slots:
|
||||
void resetLanguage();
|
||||
void showHelpForExternalEditor();
|
||||
void slotAutoConnect(int);
|
||||
void showHidden();
|
||||
|
||||
private:
|
||||
void fillLanguageBox() const;
|
||||
@ -78,10 +80,21 @@ private:
|
||||
bool m_saveSettingsOnExit;
|
||||
bool m_autoConnect;
|
||||
bool m_autoSelect;
|
||||
bool m_useUDPMirror;
|
||||
QPointer<QWidget> m_dialog;
|
||||
QList<QTextCodec *> m_codecs;
|
||||
|
||||
};
|
||||
class globalSettingsWidget:public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
globalSettingsWidget(QWidget * parent);
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent *);
|
||||
signals:
|
||||
void showHidden();
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Core
|
||||
|
@ -178,6 +178,20 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="12" column="1">
|
||||
<widget class="QCheckBox" name="cbUseUDPMirror">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="12" column="0">
|
||||
<widget class="QLabel" name="labelUDP">
|
||||
<property name="text">
|
||||
<string>Use UDP Mirror</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -27,7 +27,8 @@
|
||||
#include "uavtalk.h"
|
||||
#include <QtEndian>
|
||||
#include <QDebug>
|
||||
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <coreplugin/generalsettings.h>
|
||||
//#define UAVTALK_DEBUG
|
||||
#ifdef UAVTALK_DEBUG
|
||||
#include "qxtlogger.h"
|
||||
@ -75,6 +76,19 @@ UAVTalk::UAVTalk(QIODevice* iodev, UAVObjectManager* objMngr)
|
||||
memset(&stats, 0, sizeof(ComStats));
|
||||
|
||||
connect(io, SIGNAL(readyRead()), this, SLOT(processInputStream()));
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
Core::Internal::GeneralSettings * settings=pm->getObject<Core::Internal::GeneralSettings>();
|
||||
useUDPMirror=settings->useUDPMirror();
|
||||
qDebug()<<"USE UDP:::::::::::."<<useUDPMirror;
|
||||
if(useUDPMirror)
|
||||
{
|
||||
udpSocketTx=new QUdpSocket(this);
|
||||
udpSocketRx=new QUdpSocket(this);
|
||||
udpSocketTx->bind(9000);
|
||||
udpSocketRx->connectToHost(QHostAddress::LocalHost,9000);
|
||||
connect(udpSocketTx,SIGNAL(readyRead()),this,SLOT(dummyUDPRead()));
|
||||
connect(udpSocketRx,SIGNAL(readyRead()),this,SLOT(dummyUDPRead()));
|
||||
}
|
||||
}
|
||||
|
||||
UAVTalk::~UAVTalk()
|
||||
@ -119,6 +133,17 @@ void UAVTalk::processInputStream()
|
||||
}
|
||||
}
|
||||
|
||||
void UAVTalk::dummyUDPRead()
|
||||
{
|
||||
QUdpSocket *socket=qobject_cast<QUdpSocket*>(sender());
|
||||
QByteArray junk;
|
||||
while(socket->hasPendingDatagrams())
|
||||
{
|
||||
junk.resize(socket->pendingDatagramSize());
|
||||
socket->readDatagram(junk.data(),junk.size());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Request an update for the specified object, on success the object data would have been
|
||||
* updated by the GCS.
|
||||
@ -219,6 +244,9 @@ bool UAVTalk::processInputByte(quint8 rxbyte)
|
||||
|
||||
rxPacketLength++; // update packet byte count
|
||||
|
||||
if(useUDPMirror)
|
||||
rxDataArray.append(rxbyte);
|
||||
|
||||
// Receive state machine
|
||||
switch (rxState)
|
||||
{
|
||||
@ -235,6 +263,12 @@ bool UAVTalk::processInputByte(quint8 rxbyte)
|
||||
|
||||
rxPacketLength = 1;
|
||||
|
||||
if(useUDPMirror)
|
||||
{
|
||||
rxDataArray.clear();
|
||||
rxDataArray.append(rxbyte);
|
||||
}
|
||||
|
||||
rxState = STATE_TYPE;
|
||||
UAVTALK_QXTLOG_DEBUG("UAVTalk: Sync->Type");
|
||||
break;
|
||||
@ -446,6 +480,10 @@ bool UAVTalk::processInputByte(quint8 rxbyte)
|
||||
|
||||
mutex->lock();
|
||||
receiveObject(rxType, rxObjId, rxInstId, rxBuffer, rxLength);
|
||||
if(useUDPMirror)
|
||||
{
|
||||
udpSocketTx->writeDatagram(rxDataArray,QHostAddress::LocalHost,udpSocketRx->localPort());
|
||||
}
|
||||
stats.rxObjectBytes += rxLength;
|
||||
stats.rxObjects++;
|
||||
mutex->unlock();
|
||||
@ -476,7 +514,6 @@ bool UAVTalk::processInputByte(quint8 rxbyte)
|
||||
bool UAVTalk::receiveObject(quint8 type, quint32 objId, quint16 instId, quint8* data, qint32 length)
|
||||
{
|
||||
Q_UNUSED(length);
|
||||
|
||||
UAVObject* obj = NULL;
|
||||
bool error = false;
|
||||
bool allInstances = (instId == ALL_INSTANCES);
|
||||
@ -742,6 +779,10 @@ bool UAVTalk::transmitNack(quint32 objId)
|
||||
if (io && io->isWritable() && io->bytesToWrite() < TX_BUFFER_SIZE )
|
||||
{
|
||||
io->write((const char*)txBuffer, dataOffset+CHECKSUM_LENGTH);
|
||||
if(useUDPMirror)
|
||||
{
|
||||
udpSocketRx->writeDatagram((const char*)txBuffer,dataOffset+CHECKSUM_LENGTH,QHostAddress::LocalHost,udpSocketTx->localPort());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -832,6 +873,10 @@ bool UAVTalk::transmitSingleObject(UAVObject* obj, quint8 type, bool allInstance
|
||||
if (!io.isNull() && io->isWritable() && io->bytesToWrite() < TX_BUFFER_SIZE )
|
||||
{
|
||||
io->write((const char*)txBuffer, dataOffset+length+CHECKSUM_LENGTH);
|
||||
if(useUDPMirror)
|
||||
{
|
||||
udpSocketRx->writeDatagram((const char*)txBuffer,dataOffset+length+CHECKSUM_LENGTH,QHostAddress::LocalHost,udpSocketTx->localPort());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include <QSemaphore>
|
||||
#include "uavobjectmanager.h"
|
||||
#include "uavtalk_global.h"
|
||||
#include <QtNetwork/QUdpSocket>
|
||||
|
||||
class UAVTALK_EXPORT UAVTalk: public QObject
|
||||
{
|
||||
@ -65,6 +66,7 @@ signals:
|
||||
|
||||
private slots:
|
||||
void processInputStream(void);
|
||||
void dummyUDPRead();
|
||||
|
||||
private:
|
||||
|
||||
@ -122,6 +124,11 @@ private:
|
||||
RxStateType rxState;
|
||||
ComStats stats;
|
||||
|
||||
bool useUDPMirror;
|
||||
QUdpSocket * udpSocketTx;
|
||||
QUdpSocket * udpSocketRx;
|
||||
QByteArray rxDataArray;
|
||||
|
||||
// Methods
|
||||
bool objectTransaction(UAVObject* obj, quint8 type, bool allInstances);
|
||||
bool processInputByte(quint8 rxbyte);
|
||||
@ -134,7 +141,6 @@ private:
|
||||
bool transmitSingleObject(UAVObject* obj, quint8 type, bool allInstances);
|
||||
quint8 updateCRC(quint8 crc, const quint8 data);
|
||||
quint8 updateCRC(quint8 crc, const quint8* data, qint32 length);
|
||||
|
||||
};
|
||||
|
||||
#endif // UAVTALK_H
|
||||
|
@ -1,3 +1,4 @@
|
||||
QT += network
|
||||
TEMPLATE = lib
|
||||
TARGET = UAVTalk
|
||||
include(../../openpilotgcsplugin.pri)
|
||||
|
Loading…
x
Reference in New Issue
Block a user