mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-11-29 07:24:13 +01:00
Doxygen consistency and all plugins to version 1.0.0 with compat 1.0.0
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@863 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
61c7be7765
commit
882cd5d006
@ -1,4 +1,4 @@
|
||||
<plugin name="DoNothing" version="0.0.1" compatVersion="1.0.0">
|
||||
<plugin name="DoNothing" version="1.0.0" compatVersion="1.0.0">
|
||||
<vendor>The OpenPilot Project</vendor>
|
||||
<copyright>(C) 2010 OpenPilot Project</copyright>
|
||||
<license>Your License goes here</license>
|
||||
|
@ -5,7 +5,7 @@
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief QIODevice interface for USB RawHID
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup rawhid_plugin
|
||||
* @defgroup rawhidplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
@ -5,7 +5,7 @@
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup rawhid_plugin
|
||||
* @defgroup rawhidplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
@ -5,7 +5,7 @@
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup rawhid_plugin
|
||||
* @defgroup rawhidplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
@ -1,39 +1,39 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file rawhid_global.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup rawhid_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef RAWHID_GLOBAL_H
|
||||
#define RAWHID_GLOBAL_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#if defined(RAWHID_LIBRARY)
|
||||
# define RAWHID_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
# define RAWHID_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
#endif // RAWHID_GLOBAL_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file rawhid_global.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup rawhidplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef RAWHID_GLOBAL_H
|
||||
#define RAWHID_GLOBAL_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#if defined(RAWHID_LIBRARY)
|
||||
# define RAWHID_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
# define RAWHID_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
#endif // RAWHID_GLOBAL_H
|
||||
|
@ -1,202 +1,202 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file rawhidplugin.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Register connection object for the core connection manager
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup rawhid_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "rawhidplugin.h"
|
||||
#include "rawhid.h"
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
#include <QtCore/QMutexLocker>
|
||||
|
||||
#include "pjrc_rawhid.h"
|
||||
|
||||
#include "rawhid_const.h"
|
||||
|
||||
|
||||
RawHIDEnumerationThread::RawHIDEnumerationThread(RawHIDConnection *rawhid)
|
||||
: m_rawhid(rawhid),
|
||||
m_running(true)
|
||||
{
|
||||
}
|
||||
|
||||
RawHIDEnumerationThread::~RawHIDEnumerationThread()
|
||||
{
|
||||
m_running = false;
|
||||
//wait for the thread to terminate
|
||||
if(wait(1000) == false)
|
||||
qDebug() << "Cannot terminate RawHIDEnumerationThread";
|
||||
}
|
||||
|
||||
void RawHIDEnumerationThread::run()
|
||||
{
|
||||
QStringList devices = m_rawhid->availableDevices();
|
||||
|
||||
while(m_running)
|
||||
{
|
||||
if(!m_rawhid->deviceOpened())
|
||||
{
|
||||
QStringList newDev = m_rawhid->availableDevices();
|
||||
if(devices != newDev)
|
||||
{
|
||||
devices = newDev;
|
||||
emit enumerationChanged();
|
||||
}
|
||||
}
|
||||
|
||||
msleep(500); //update available devices twice per second (doesn't need more)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
RawHIDConnection::RawHIDConnection()
|
||||
: m_enumerateThread(this)
|
||||
{
|
||||
QObject::connect(&m_enumerateThread, SIGNAL(enumerationChanged()),
|
||||
this, SLOT(onEnumerationChanged()));
|
||||
m_enumerateThread.start();
|
||||
}
|
||||
|
||||
RawHIDConnection::~RawHIDConnection()
|
||||
{}
|
||||
|
||||
void RawHIDConnection::onEnumerationChanged()
|
||||
{
|
||||
emit availableDevChanged(this);
|
||||
}
|
||||
|
||||
QStringList RawHIDConnection::availableDevices()
|
||||
{
|
||||
QMutexLocker locker(&m_enumMutex);
|
||||
|
||||
QStringList devices;
|
||||
pjrc_rawhid dev;
|
||||
|
||||
//open all device we can
|
||||
int opened = dev.open(MAX_DEVICES, VID, PID, USAGE_PAGE, USAGE);
|
||||
|
||||
//for each devices found, get serial number and close it back
|
||||
for(int i=0; i<opened; i++)
|
||||
{
|
||||
char serial[256];
|
||||
dev.getserial(i, serial);
|
||||
devices.append(QString::fromAscii(serial, DEV_SERIAL_LEN));
|
||||
dev.close(i);
|
||||
}
|
||||
|
||||
return devices;
|
||||
}
|
||||
|
||||
QIODevice *RawHIDConnection::openDevice(const QString &deviceName)
|
||||
{
|
||||
m_deviceOpened = true;
|
||||
return new RawHID(deviceName);
|
||||
}
|
||||
|
||||
void RawHIDConnection::closeDevice(const QString &deviceName)
|
||||
{
|
||||
m_deviceOpened = false;
|
||||
}
|
||||
|
||||
|
||||
QString RawHIDConnection::connectionName()
|
||||
{
|
||||
return QString("Raw HID USB");
|
||||
}
|
||||
|
||||
QString RawHIDConnection::shortName()
|
||||
{
|
||||
return QString("USB");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//usb hid test thread
|
||||
//temporary...
|
||||
RawHIDTestThread::RawHIDTestThread()
|
||||
{
|
||||
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
|
||||
QObject::connect(cm, SIGNAL(deviceConnected(QIODevice *)),
|
||||
this, SLOT(onDeviceConnect(QIODevice *)));
|
||||
QObject::connect(cm, SIGNAL(deviceDisconnected()),
|
||||
this, SLOT(onDeviceDisconnect()));
|
||||
}
|
||||
|
||||
void RawHIDTestThread::onDeviceConnect(QIODevice *dev)
|
||||
{
|
||||
this->dev = dev;
|
||||
dev->open(QIODevice::ReadWrite);
|
||||
QObject::connect(dev, SIGNAL(readyRead()),
|
||||
this, SLOT(onReadyRead()));
|
||||
|
||||
QObject::connect(dev, SIGNAL(bytesWritten(qint64)),
|
||||
this, SLOT(onBytesWritten(qint64)));
|
||||
dev->write("Hello raw hid device\n");
|
||||
}
|
||||
|
||||
void RawHIDTestThread::onDeviceDisconnect()
|
||||
{
|
||||
dev->close();
|
||||
}
|
||||
|
||||
void RawHIDTestThread::onReadyRead()
|
||||
{
|
||||
qDebug() << "Rx:" << dev->readLine(32);
|
||||
}
|
||||
|
||||
void RawHIDTestThread::onBytesWritten(qint64 sz)
|
||||
{
|
||||
qDebug() << "Sent " << sz << " bytes";
|
||||
}
|
||||
|
||||
RawHIDPlugin::RawHIDPlugin()
|
||||
{
|
||||
}
|
||||
|
||||
RawHIDPlugin::~RawHIDPlugin()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RawHIDPlugin::extensionsInitialized()
|
||||
{
|
||||
addAutoReleasedObject(new RawHIDConnection);
|
||||
|
||||
//temp for test
|
||||
//addAutoReleasedObject(new RawHIDTestThread);
|
||||
}
|
||||
|
||||
bool RawHIDPlugin::initialize(const QStringList & arguments, QString * errorString)
|
||||
{
|
||||
Q_UNUSED(arguments);
|
||||
Q_UNUSED(errorString);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Q_EXPORT_PLUGIN(RawHIDPlugin)
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file rawhidplugin.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Register connection object for the core connection manager
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup rawhidplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "rawhidplugin.h"
|
||||
#include "rawhid.h"
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
#include <QtCore/QMutexLocker>
|
||||
|
||||
#include "pjrc_rawhid.h"
|
||||
|
||||
#include "rawhid_const.h"
|
||||
|
||||
|
||||
RawHIDEnumerationThread::RawHIDEnumerationThread(RawHIDConnection *rawhid)
|
||||
: m_rawhid(rawhid),
|
||||
m_running(true)
|
||||
{
|
||||
}
|
||||
|
||||
RawHIDEnumerationThread::~RawHIDEnumerationThread()
|
||||
{
|
||||
m_running = false;
|
||||
//wait for the thread to terminate
|
||||
if(wait(1000) == false)
|
||||
qDebug() << "Cannot terminate RawHIDEnumerationThread";
|
||||
}
|
||||
|
||||
void RawHIDEnumerationThread::run()
|
||||
{
|
||||
QStringList devices = m_rawhid->availableDevices();
|
||||
|
||||
while(m_running)
|
||||
{
|
||||
if(!m_rawhid->deviceOpened())
|
||||
{
|
||||
QStringList newDev = m_rawhid->availableDevices();
|
||||
if(devices != newDev)
|
||||
{
|
||||
devices = newDev;
|
||||
emit enumerationChanged();
|
||||
}
|
||||
}
|
||||
|
||||
msleep(500); //update available devices twice per second (doesn't need more)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
RawHIDConnection::RawHIDConnection()
|
||||
: m_enumerateThread(this)
|
||||
{
|
||||
QObject::connect(&m_enumerateThread, SIGNAL(enumerationChanged()),
|
||||
this, SLOT(onEnumerationChanged()));
|
||||
m_enumerateThread.start();
|
||||
}
|
||||
|
||||
RawHIDConnection::~RawHIDConnection()
|
||||
{}
|
||||
|
||||
void RawHIDConnection::onEnumerationChanged()
|
||||
{
|
||||
emit availableDevChanged(this);
|
||||
}
|
||||
|
||||
QStringList RawHIDConnection::availableDevices()
|
||||
{
|
||||
QMutexLocker locker(&m_enumMutex);
|
||||
|
||||
QStringList devices;
|
||||
pjrc_rawhid dev;
|
||||
|
||||
//open all device we can
|
||||
int opened = dev.open(MAX_DEVICES, VID, PID, USAGE_PAGE, USAGE);
|
||||
|
||||
//for each devices found, get serial number and close it back
|
||||
for(int i=0; i<opened; i++)
|
||||
{
|
||||
char serial[256];
|
||||
dev.getserial(i, serial);
|
||||
devices.append(QString::fromAscii(serial, DEV_SERIAL_LEN));
|
||||
dev.close(i);
|
||||
}
|
||||
|
||||
return devices;
|
||||
}
|
||||
|
||||
QIODevice *RawHIDConnection::openDevice(const QString &deviceName)
|
||||
{
|
||||
m_deviceOpened = true;
|
||||
return new RawHID(deviceName);
|
||||
}
|
||||
|
||||
void RawHIDConnection::closeDevice(const QString &deviceName)
|
||||
{
|
||||
m_deviceOpened = false;
|
||||
}
|
||||
|
||||
|
||||
QString RawHIDConnection::connectionName()
|
||||
{
|
||||
return QString("Raw HID USB");
|
||||
}
|
||||
|
||||
QString RawHIDConnection::shortName()
|
||||
{
|
||||
return QString("USB");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//usb hid test thread
|
||||
//temporary...
|
||||
RawHIDTestThread::RawHIDTestThread()
|
||||
{
|
||||
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
|
||||
QObject::connect(cm, SIGNAL(deviceConnected(QIODevice *)),
|
||||
this, SLOT(onDeviceConnect(QIODevice *)));
|
||||
QObject::connect(cm, SIGNAL(deviceDisconnected()),
|
||||
this, SLOT(onDeviceDisconnect()));
|
||||
}
|
||||
|
||||
void RawHIDTestThread::onDeviceConnect(QIODevice *dev)
|
||||
{
|
||||
this->dev = dev;
|
||||
dev->open(QIODevice::ReadWrite);
|
||||
QObject::connect(dev, SIGNAL(readyRead()),
|
||||
this, SLOT(onReadyRead()));
|
||||
|
||||
QObject::connect(dev, SIGNAL(bytesWritten(qint64)),
|
||||
this, SLOT(onBytesWritten(qint64)));
|
||||
dev->write("Hello raw hid device\n");
|
||||
}
|
||||
|
||||
void RawHIDTestThread::onDeviceDisconnect()
|
||||
{
|
||||
dev->close();
|
||||
}
|
||||
|
||||
void RawHIDTestThread::onReadyRead()
|
||||
{
|
||||
qDebug() << "Rx:" << dev->readLine(32);
|
||||
}
|
||||
|
||||
void RawHIDTestThread::onBytesWritten(qint64 sz)
|
||||
{
|
||||
qDebug() << "Sent " << sz << " bytes";
|
||||
}
|
||||
|
||||
RawHIDPlugin::RawHIDPlugin()
|
||||
{
|
||||
}
|
||||
|
||||
RawHIDPlugin::~RawHIDPlugin()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RawHIDPlugin::extensionsInitialized()
|
||||
{
|
||||
addAutoReleasedObject(new RawHIDConnection);
|
||||
|
||||
//temp for test
|
||||
//addAutoReleasedObject(new RawHIDTestThread);
|
||||
}
|
||||
|
||||
bool RawHIDPlugin::initialize(const QStringList & arguments, QString * errorString)
|
||||
{
|
||||
Q_UNUSED(arguments);
|
||||
Q_UNUSED(errorString);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Q_EXPORT_PLUGIN(RawHIDPlugin)
|
||||
|
@ -1,128 +1,128 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file rawhid.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup rawhid_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef RAWHIDPLUGIN_H
|
||||
#define RAWHIDPLUGIN_H
|
||||
|
||||
#include "rawhid_global.h"
|
||||
|
||||
#include "coreplugin/iconnection.h"
|
||||
#include <extensionsystem/iplugin.h>
|
||||
|
||||
#include <QtCore/QMutex>
|
||||
#include <QtCore/QThread>
|
||||
|
||||
class IConnection;
|
||||
class RawHIDConnection;
|
||||
|
||||
|
||||
/**
|
||||
* Helper thread to check on device connection/disconnection
|
||||
* Underlying HID library is not really easy to use,
|
||||
* so we have to poll for device modification in a separate thread
|
||||
*/
|
||||
class RAWHID_EXPORT RawHIDEnumerationThread : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RawHIDEnumerationThread(RawHIDConnection *rawhid);
|
||||
virtual ~RawHIDEnumerationThread();
|
||||
|
||||
virtual void run();
|
||||
|
||||
signals:
|
||||
void enumerationChanged();
|
||||
|
||||
protected:
|
||||
RawHIDConnection *m_rawhid;
|
||||
bool m_running;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Define a connection via the IConnection interface
|
||||
* Plugin will add a instance of this class to the pool,
|
||||
* so the connection manager can use it.
|
||||
*/
|
||||
class RAWHID_EXPORT RawHIDConnection
|
||||
: public Core::IConnection
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RawHIDConnection();
|
||||
virtual ~RawHIDConnection();
|
||||
|
||||
virtual QStringList availableDevices();
|
||||
virtual QIODevice *openDevice(const QString &deviceName);
|
||||
virtual void closeDevice(const QString &deviceName);
|
||||
|
||||
virtual QString connectionName();
|
||||
virtual QString shortName();
|
||||
|
||||
bool deviceOpened() {return m_deviceOpened;}
|
||||
|
||||
protected slots:
|
||||
void onEnumerationChanged();
|
||||
|
||||
protected:
|
||||
QMutex m_enumMutex;
|
||||
RawHIDEnumerationThread m_enumerateThread;
|
||||
bool m_deviceOpened;
|
||||
};
|
||||
|
||||
class RAWHID_EXPORT RawHIDPlugin
|
||||
: public ExtensionSystem::IPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
RawHIDPlugin();
|
||||
~RawHIDPlugin();
|
||||
|
||||
virtual bool initialize(const QStringList &arguments, QString *error_message);
|
||||
virtual void extensionsInitialized();
|
||||
};
|
||||
|
||||
|
||||
//usb hid test thread
|
||||
#include "coreplugin/icore.h"
|
||||
#include "coreplugin/connectionmanager.h"
|
||||
class RawHIDTestThread: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RawHIDTestThread();
|
||||
protected slots:
|
||||
void onDeviceConnect(QIODevice *);
|
||||
void onDeviceDisconnect();
|
||||
void onReadyRead();
|
||||
void onBytesWritten(qint64 sz);
|
||||
protected:
|
||||
QIODevice *dev;
|
||||
};
|
||||
|
||||
#endif // RAWHIDPLUGIN_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file rawhid.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup rawhidplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef RAWHIDPLUGIN_H
|
||||
#define RAWHIDPLUGIN_H
|
||||
|
||||
#include "rawhid_global.h"
|
||||
|
||||
#include "coreplugin/iconnection.h"
|
||||
#include <extensionsystem/iplugin.h>
|
||||
|
||||
#include <QtCore/QMutex>
|
||||
#include <QtCore/QThread>
|
||||
|
||||
class IConnection;
|
||||
class RawHIDConnection;
|
||||
|
||||
|
||||
/**
|
||||
* Helper thread to check on device connection/disconnection
|
||||
* Underlying HID library is not really easy to use,
|
||||
* so we have to poll for device modification in a separate thread
|
||||
*/
|
||||
class RAWHID_EXPORT RawHIDEnumerationThread : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RawHIDEnumerationThread(RawHIDConnection *rawhid);
|
||||
virtual ~RawHIDEnumerationThread();
|
||||
|
||||
virtual void run();
|
||||
|
||||
signals:
|
||||
void enumerationChanged();
|
||||
|
||||
protected:
|
||||
RawHIDConnection *m_rawhid;
|
||||
bool m_running;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Define a connection via the IConnection interface
|
||||
* Plugin will add a instance of this class to the pool,
|
||||
* so the connection manager can use it.
|
||||
*/
|
||||
class RAWHID_EXPORT RawHIDConnection
|
||||
: public Core::IConnection
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RawHIDConnection();
|
||||
virtual ~RawHIDConnection();
|
||||
|
||||
virtual QStringList availableDevices();
|
||||
virtual QIODevice *openDevice(const QString &deviceName);
|
||||
virtual void closeDevice(const QString &deviceName);
|
||||
|
||||
virtual QString connectionName();
|
||||
virtual QString shortName();
|
||||
|
||||
bool deviceOpened() {return m_deviceOpened;}
|
||||
|
||||
protected slots:
|
||||
void onEnumerationChanged();
|
||||
|
||||
protected:
|
||||
QMutex m_enumMutex;
|
||||
RawHIDEnumerationThread m_enumerateThread;
|
||||
bool m_deviceOpened;
|
||||
};
|
||||
|
||||
class RAWHID_EXPORT RawHIDPlugin
|
||||
: public ExtensionSystem::IPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
RawHIDPlugin();
|
||||
~RawHIDPlugin();
|
||||
|
||||
virtual bool initialize(const QStringList &arguments, QString *error_message);
|
||||
virtual void extensionsInitialized();
|
||||
};
|
||||
|
||||
|
||||
//usb hid test thread
|
||||
#include "coreplugin/icore.h"
|
||||
#include "coreplugin/connectionmanager.h"
|
||||
class RawHIDTestThread: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RawHIDTestThread();
|
||||
protected slots:
|
||||
void onDeviceConnect(QIODevice *);
|
||||
void onDeviceDisconnect();
|
||||
void onReadyRead();
|
||||
void onBytesWritten(qint64 sz);
|
||||
protected:
|
||||
QIODevice *dev;
|
||||
};
|
||||
|
||||
#endif // RAWHIDPLUGIN_H
|
||||
|
@ -1,39 +1,39 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file serial_global.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup serial_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef SERIAL_GLOBAL_H
|
||||
#define SERIAL_GLOBAL_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#if defined(SERIAL_LIBRARY)
|
||||
# define SERIAL_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
# define SERIAL_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
#endif // SERIAL_GLOBAL_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file serial_global.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup serialplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef SERIAL_GLOBAL_H
|
||||
#define SERIAL_GLOBAL_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#if defined(SERIAL_LIBRARY)
|
||||
# define SERIAL_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
# define SERIAL_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
#endif // SERIAL_GLOBAL_H
|
||||
|
@ -5,7 +5,7 @@
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Register connection object for the core connection manager
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup serial_plugin
|
||||
* @defgroup serialplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
@ -1,79 +1,79 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file serialplugin.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup serial_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef SERIALPLUGIN_H
|
||||
#define SERIALPLUGIN_H
|
||||
|
||||
#include "serial_global.h"
|
||||
#include <qextserialport.h>
|
||||
#include <qextserialenumerator.h>
|
||||
#include "coreplugin/iconnection.h"
|
||||
#include <extensionsystem/iplugin.h>
|
||||
|
||||
class IConnection;
|
||||
class QextSerialEnumerator;
|
||||
|
||||
/**
|
||||
* Define a connection via the IConnection interface
|
||||
* Plugin will add a instance of this class to the pool,
|
||||
* so the connection manager can use it.
|
||||
*/
|
||||
class SERIAL_EXPORT SerialConnection
|
||||
: public Core::IConnection
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SerialConnection();
|
||||
virtual ~SerialConnection();
|
||||
|
||||
virtual QStringList availableDevices();
|
||||
virtual QIODevice *openDevice(const QString &deviceName);
|
||||
virtual void closeDevice(const QString &deviceName);
|
||||
|
||||
virtual QString connectionName();
|
||||
virtual QString shortName();
|
||||
|
||||
protected slots:
|
||||
void onEnumerationChanged();
|
||||
};
|
||||
|
||||
|
||||
class SERIAL_EXPORT SerialPlugin
|
||||
: public ExtensionSystem::IPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SerialPlugin();
|
||||
~SerialPlugin();
|
||||
|
||||
virtual bool initialize(const QStringList &arguments, QString *error_message);
|
||||
virtual void extensionsInitialized();
|
||||
};
|
||||
|
||||
|
||||
#endif // SERIALPLUGIN_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file serialplugin.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup serialplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef SERIALPLUGIN_H
|
||||
#define SERIALPLUGIN_H
|
||||
|
||||
#include "serial_global.h"
|
||||
#include <qextserialport.h>
|
||||
#include <qextserialenumerator.h>
|
||||
#include "coreplugin/iconnection.h"
|
||||
#include <extensionsystem/iplugin.h>
|
||||
|
||||
class IConnection;
|
||||
class QextSerialEnumerator;
|
||||
|
||||
/**
|
||||
* Define a connection via the IConnection interface
|
||||
* Plugin will add a instance of this class to the pool,
|
||||
* so the connection manager can use it.
|
||||
*/
|
||||
class SERIAL_EXPORT SerialConnection
|
||||
: public Core::IConnection
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SerialConnection();
|
||||
virtual ~SerialConnection();
|
||||
|
||||
virtual QStringList availableDevices();
|
||||
virtual QIODevice *openDevice(const QString &deviceName);
|
||||
virtual void closeDevice(const QString &deviceName);
|
||||
|
||||
virtual QString connectionName();
|
||||
virtual QString shortName();
|
||||
|
||||
protected slots:
|
||||
void onEnumerationChanged();
|
||||
};
|
||||
|
||||
|
||||
class SERIAL_EXPORT SerialPlugin
|
||||
: public ExtensionSystem::IPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SerialPlugin();
|
||||
~SerialPlugin();
|
||||
|
||||
virtual bool initialize(const QStringList &arguments, QString *error_message);
|
||||
virtual void extensionsInitialized();
|
||||
};
|
||||
|
||||
|
||||
#endif // SERIALPLUGIN_H
|
||||
|
@ -1,52 +1,52 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file systemhealthgadget.cpp
|
||||
* @author Edouard Lafargue Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup systemhealth
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "systemhealthgadget.h"
|
||||
#include "systemhealthgadgetwidget.h"
|
||||
#include "systemhealthgadgetconfiguration.h"
|
||||
|
||||
SystemHealthGadget::SystemHealthGadget(QString classId, SystemHealthGadgetWidget *widget, QWidget *parent) :
|
||||
IUAVGadget(classId, parent),
|
||||
m_widget(widget)
|
||||
{
|
||||
}
|
||||
|
||||
SystemHealthGadget::~SystemHealthGadget()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
This is called when a configuration is loaded, and updates the plugin's settings.
|
||||
Careful: the plugin is already drawn before the loadConfiguration method is called the
|
||||
first time, so you have to be careful not to assume all the plugin values are initialized
|
||||
the first time you use them
|
||||
*/
|
||||
void SystemHealthGadget::loadConfiguration(IUAVGadgetConfiguration* config)
|
||||
{
|
||||
SystemHealthGadgetConfiguration *m = qobject_cast<SystemHealthGadgetConfiguration*>(config);
|
||||
m_widget->setSystemFile(m->getSystemFile()); // Triggers widget repaint
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file systemhealthgadget.cpp
|
||||
* @author Edouard Lafargue Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup systemhealthplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "systemhealthgadget.h"
|
||||
#include "systemhealthgadgetwidget.h"
|
||||
#include "systemhealthgadgetconfiguration.h"
|
||||
|
||||
SystemHealthGadget::SystemHealthGadget(QString classId, SystemHealthGadgetWidget *widget, QWidget *parent) :
|
||||
IUAVGadget(classId, parent),
|
||||
m_widget(widget)
|
||||
{
|
||||
}
|
||||
|
||||
SystemHealthGadget::~SystemHealthGadget()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
This is called when a configuration is loaded, and updates the plugin's settings.
|
||||
Careful: the plugin is already drawn before the loadConfiguration method is called the
|
||||
first time, so you have to be careful not to assume all the plugin values are initialized
|
||||
the first time you use them
|
||||
*/
|
||||
void SystemHealthGadget::loadConfiguration(IUAVGadgetConfiguration* config)
|
||||
{
|
||||
SystemHealthGadgetConfiguration *m = qobject_cast<SystemHealthGadgetConfiguration*>(config);
|
||||
m_widget->setSystemFile(m->getSystemFile()); // Triggers widget repaint
|
||||
}
|
||||
|
@ -1,56 +1,56 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file systemhealthgadget.h
|
||||
* @author Edouard Lafargue Copyright (C) 2010.
|
||||
* @brief System health gadget to display system alarms
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup systemhealth
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef SYSTEMHEALTHGADGET_H_
|
||||
#define SYSTEMHEALTHGADGET_H_
|
||||
|
||||
#include <coreplugin/iuavgadget.h>
|
||||
#include "systemhealthgadgetwidget.h"
|
||||
|
||||
class IUAVGadget;
|
||||
class QWidget;
|
||||
class QString;
|
||||
class SystemHealthGadgetWidget;
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class SystemHealthGadget : public Core::IUAVGadget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SystemHealthGadget(QString classId, SystemHealthGadgetWidget *widget, QWidget *parent = 0);
|
||||
~SystemHealthGadget();
|
||||
|
||||
QWidget *widget() { return m_widget; }
|
||||
void loadConfiguration(IUAVGadgetConfiguration* config);
|
||||
|
||||
private:
|
||||
SystemHealthGadgetWidget *m_widget;
|
||||
};
|
||||
|
||||
|
||||
#endif // SYSTEMHEALTHGADGET_H_
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file systemhealthgadget.h
|
||||
* @author Edouard Lafargue Copyright (C) 2010.
|
||||
* @brief System health gadget to display system alarms
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup systemhealthplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef SYSTEMHEALTHGADGET_H_
|
||||
#define SYSTEMHEALTHGADGET_H_
|
||||
|
||||
#include <coreplugin/iuavgadget.h>
|
||||
#include "systemhealthgadgetwidget.h"
|
||||
|
||||
class IUAVGadget;
|
||||
class QWidget;
|
||||
class QString;
|
||||
class SystemHealthGadgetWidget;
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class SystemHealthGadget : public Core::IUAVGadget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SystemHealthGadget(QString classId, SystemHealthGadgetWidget *widget, QWidget *parent = 0);
|
||||
~SystemHealthGadget();
|
||||
|
||||
QWidget *widget() { return m_widget; }
|
||||
void loadConfiguration(IUAVGadgetConfiguration* config);
|
||||
|
||||
private:
|
||||
SystemHealthGadgetWidget *m_widget;
|
||||
};
|
||||
|
||||
|
||||
#endif // SYSTEMHEALTHGADGET_H_
|
||||
|
@ -5,7 +5,7 @@
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief System Health Plugin Gadget configuration
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup systemhealth
|
||||
* @defgroup systemhealthplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
@ -5,7 +5,7 @@
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief System Health Plugin Gadget configuration
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup systemhealth
|
||||
* @defgroup systemhealthplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
@ -1,60 +1,60 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file systemhealthgadgetfactory.cpp
|
||||
* @author Edouard Lafargue Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup systemhealth
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "systemhealthgadgetfactory.h"
|
||||
#include "systemhealthgadgetwidget.h"
|
||||
#include "systemhealthgadget.h"
|
||||
#include "systemhealthgadgetconfiguration.h"
|
||||
#include "systemhealthgadgetoptionspage.h"
|
||||
#include <coreplugin/iuavgadget.h>
|
||||
|
||||
SystemHealthGadgetFactory::SystemHealthGadgetFactory(QObject *parent) :
|
||||
IUAVGadgetFactory(QString("SystemHealthGadget"),
|
||||
tr("System Health Gadget"),
|
||||
parent)
|
||||
{
|
||||
}
|
||||
|
||||
SystemHealthGadgetFactory::~SystemHealthGadgetFactory()
|
||||
{
|
||||
}
|
||||
|
||||
Core::IUAVGadget* SystemHealthGadgetFactory::createGadget(QWidget *parent)
|
||||
{
|
||||
SystemHealthGadgetWidget* gadgetWidget = new SystemHealthGadgetWidget(parent);
|
||||
return new SystemHealthGadget(QString("SystemHealthGadget"), gadgetWidget, parent);
|
||||
}
|
||||
|
||||
IUAVGadgetConfiguration *SystemHealthGadgetFactory::createConfiguration(const QByteArray &state)
|
||||
{
|
||||
return new SystemHealthGadgetConfiguration(QString("SystemHealthGadget"), state);
|
||||
}
|
||||
|
||||
IOptionsPage *SystemHealthGadgetFactory::createOptionsPage(IUAVGadgetConfiguration *config)
|
||||
{
|
||||
return new SystemHealthGadgetOptionsPage(qobject_cast<SystemHealthGadgetConfiguration*>(config));
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file systemhealthgadgetfactory.cpp
|
||||
* @author Edouard Lafargue Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup systemhealthplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "systemhealthgadgetfactory.h"
|
||||
#include "systemhealthgadgetwidget.h"
|
||||
#include "systemhealthgadget.h"
|
||||
#include "systemhealthgadgetconfiguration.h"
|
||||
#include "systemhealthgadgetoptionspage.h"
|
||||
#include <coreplugin/iuavgadget.h>
|
||||
|
||||
SystemHealthGadgetFactory::SystemHealthGadgetFactory(QObject *parent) :
|
||||
IUAVGadgetFactory(QString("SystemHealthGadget"),
|
||||
tr("System Health Gadget"),
|
||||
parent)
|
||||
{
|
||||
}
|
||||
|
||||
SystemHealthGadgetFactory::~SystemHealthGadgetFactory()
|
||||
{
|
||||
}
|
||||
|
||||
Core::IUAVGadget* SystemHealthGadgetFactory::createGadget(QWidget *parent)
|
||||
{
|
||||
SystemHealthGadgetWidget* gadgetWidget = new SystemHealthGadgetWidget(parent);
|
||||
return new SystemHealthGadget(QString("SystemHealthGadget"), gadgetWidget, parent);
|
||||
}
|
||||
|
||||
IUAVGadgetConfiguration *SystemHealthGadgetFactory::createConfiguration(const QByteArray &state)
|
||||
{
|
||||
return new SystemHealthGadgetConfiguration(QString("SystemHealthGadget"), state);
|
||||
}
|
||||
|
||||
IOptionsPage *SystemHealthGadgetFactory::createOptionsPage(IUAVGadgetConfiguration *config)
|
||||
{
|
||||
return new SystemHealthGadgetOptionsPage(qobject_cast<SystemHealthGadgetConfiguration*>(config));
|
||||
}
|
||||
|
||||
|
@ -1,52 +1,52 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file systemhealthgadgetfactory.h
|
||||
* @author Edouard Lafargue Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup systemhealth
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef SYSTEMHEALTHGADGETFACTORY_H_
|
||||
#define SYSTEMHEALTHGADGETFACTORY_H_
|
||||
|
||||
#include <coreplugin/iuavgadgetfactory.h>
|
||||
|
||||
namespace Core {
|
||||
class IUAVGadget;
|
||||
class IUAVGadgetFactory;
|
||||
}
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class SystemHealthGadgetFactory : public IUAVGadgetFactory
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SystemHealthGadgetFactory(QObject *parent = 0);
|
||||
~SystemHealthGadgetFactory();
|
||||
|
||||
Core::IUAVGadget *createGadget(QWidget *parent);
|
||||
IUAVGadgetConfiguration *createConfiguration(const QByteArray &state);
|
||||
IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config);
|
||||
};
|
||||
|
||||
#endif // SYSTEMHEALTHGADGETFACTORY_H_
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file systemhealthgadgetfactory.h
|
||||
* @author Edouard Lafargue Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup systemhealthplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef SYSTEMHEALTHGADGETFACTORY_H_
|
||||
#define SYSTEMHEALTHGADGETFACTORY_H_
|
||||
|
||||
#include <coreplugin/iuavgadgetfactory.h>
|
||||
|
||||
namespace Core {
|
||||
class IUAVGadget;
|
||||
class IUAVGadgetFactory;
|
||||
}
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class SystemHealthGadgetFactory : public IUAVGadgetFactory
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SystemHealthGadgetFactory(QObject *parent = 0);
|
||||
~SystemHealthGadgetFactory();
|
||||
|
||||
Core::IUAVGadget *createGadget(QWidget *parent);
|
||||
IUAVGadgetConfiguration *createConfiguration(const QByteArray &state);
|
||||
IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config);
|
||||
};
|
||||
|
||||
#endif // SYSTEMHEALTHGADGETFACTORY_H_
|
||||
|
@ -5,7 +5,7 @@
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief System Health Plugin Gadget options page
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup systemhealth
|
||||
* @defgroup systemhealthplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
@ -5,7 +5,7 @@
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief System Health Plugin Gadget options page
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup systemhealth
|
||||
* @defgroup systemhealthplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
@ -1,173 +1,173 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file systemhealthgadgetwidget.cpp
|
||||
* @author Edouard Lafargue Copyright (C) 2010.
|
||||
* @brief System Health widget, does the actual drawing
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup systemhealth
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "systemhealthgadgetwidget.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include "uavobjects/uavobjectmanager.h"
|
||||
#include "uavobjects/systemalarms.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <QtGui/QFileDialog>
|
||||
#include <QDebug>
|
||||
|
||||
/*
|
||||
* Initialize the widget
|
||||
*/
|
||||
SystemHealthGadgetWidget::SystemHealthGadgetWidget(QWidget *parent) : QGraphicsView(parent)
|
||||
{
|
||||
setMinimumSize(128,128);
|
||||
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
setScene(new QGraphicsScene(this));
|
||||
|
||||
m_renderer = new QSvgRenderer();
|
||||
background = new QGraphicsSvgItem();
|
||||
foreground = new QGraphicsSvgItem();
|
||||
|
||||
paint();
|
||||
|
||||
// Now connect the widget to the SystemAlarms UAVObject
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
||||
|
||||
SystemAlarms* obj = dynamic_cast<SystemAlarms*>(objManager->getObject(QString("SystemAlarms")));
|
||||
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(updateAlarms(UAVObject*)));
|
||||
|
||||
// Test code for timer to move the index
|
||||
testValue=0;
|
||||
connect(&m_testTimer, SIGNAL(timeout()), this, SLOT(testRotate()));
|
||||
m_testTimer.start(1000);
|
||||
}
|
||||
|
||||
void SystemHealthGadgetWidget::updateAlarms(UAVObject* systemAlarm)
|
||||
{
|
||||
// This code does not know anything about alarms beforehand, and
|
||||
// I found to efficient way to locate items inside the scene by
|
||||
// name, so it's just as simple to reset the scene:
|
||||
// And add the one with the right name.
|
||||
QGraphicsScene *m_scene = scene();
|
||||
foreach ( QGraphicsItem* item , m_scene->items()){
|
||||
m_scene->removeItem(item);
|
||||
}
|
||||
m_scene->addItem(background);
|
||||
|
||||
QString alarm = systemAlarm->getName();
|
||||
foreach (UAVObjectField *field, systemAlarm->getFields()) {
|
||||
for (uint i = 0; i < field->getNumElements(); ++i) {
|
||||
QString element = field->getElementNames()[i];
|
||||
QString value = field->getValue(i).toString();
|
||||
if (m_renderer->elementExists(element)) {
|
||||
QMatrix blockMatrix = m_renderer->matrixForElement(element);
|
||||
qreal startX = blockMatrix.mapRect(m_renderer->boundsOnElement(element)).x();
|
||||
qreal startY = blockMatrix.mapRect(m_renderer->boundsOnElement(element)).y();
|
||||
QString element2 = element + "-" + value;
|
||||
if (m_renderer->elementExists(element2)) {
|
||||
QGraphicsSvgItem *ind = new QGraphicsSvgItem();
|
||||
ind->setSharedRenderer(m_renderer);
|
||||
ind->setElementId(element2);
|
||||
QTransform matrix;
|
||||
matrix.translate(startX,startY);
|
||||
ind->setTransform(matrix,false);
|
||||
m_scene->addItem(ind);
|
||||
} else {
|
||||
std::cout << "Warning: element " << element2.toStdString() << " not found in SVG."<<std::endl;
|
||||
}
|
||||
} else {
|
||||
std::cout << "Warning: Element " << element.toStdString() << " not found in SVG." << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
m_scene->addItem(foreground);
|
||||
}
|
||||
|
||||
SystemHealthGadgetWidget::~SystemHealthGadgetWidget()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
|
||||
void SystemHealthGadgetWidget::setSystemFile(QString dfn)
|
||||
{
|
||||
if (QFile::exists(dfn))
|
||||
{
|
||||
m_renderer->load(dfn);
|
||||
if(m_renderer->isValid())
|
||||
{
|
||||
fgenabled = false;
|
||||
|
||||
background->setSharedRenderer(m_renderer);
|
||||
background->setElementId("background");
|
||||
|
||||
if (m_renderer->elementExists("foreground")) {
|
||||
foreground->setSharedRenderer(m_renderer);
|
||||
foreground->setElementId("foreground");
|
||||
foreground->setZValue(99);
|
||||
fgenabled = true;
|
||||
}
|
||||
std::cout<<"Dial file loaded"<<std::endl;
|
||||
QGraphicsScene *l_scene = scene();
|
||||
l_scene->setSceneRect(background->boundingRect());
|
||||
fitInView(background, Qt::KeepAspectRatio );
|
||||
}
|
||||
}
|
||||
else
|
||||
{ std::cout<<"no file: "<<std::endl; }
|
||||
}
|
||||
|
||||
void SystemHealthGadgetWidget::paint()
|
||||
{
|
||||
QGraphicsScene *l_scene = scene();
|
||||
l_scene->clear();
|
||||
l_scene->addItem(background);
|
||||
l_scene->addItem(foreground);
|
||||
update();
|
||||
}
|
||||
|
||||
void SystemHealthGadgetWidget::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
// Skip painting until the dial file is loaded
|
||||
if (! m_renderer->isValid()) {
|
||||
std::cout<<"System file not loaded, not rendering"<<std::endl;
|
||||
return;
|
||||
}
|
||||
QGraphicsView::paintEvent(event);
|
||||
}
|
||||
|
||||
// This event enables the dial to be dynamically resized
|
||||
// whenever the gadget is resized, taking advantage of the vector
|
||||
// nature of SVG dials.
|
||||
void SystemHealthGadgetWidget::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
fitInView(background, Qt::KeepAspectRatio );
|
||||
}
|
||||
|
||||
|
||||
// Test function for timer to rotate needles
|
||||
void SystemHealthGadgetWidget::test()
|
||||
{
|
||||
testValue=0;
|
||||
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file systemhealthgadgetwidget.cpp
|
||||
* @author Edouard Lafargue Copyright (C) 2010.
|
||||
* @brief System Health widget, does the actual drawing
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup systemhealthplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "systemhealthgadgetwidget.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include "uavobjects/uavobjectmanager.h"
|
||||
#include "uavobjects/systemalarms.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <QtGui/QFileDialog>
|
||||
#include <QDebug>
|
||||
|
||||
/*
|
||||
* Initialize the widget
|
||||
*/
|
||||
SystemHealthGadgetWidget::SystemHealthGadgetWidget(QWidget *parent) : QGraphicsView(parent)
|
||||
{
|
||||
setMinimumSize(128,128);
|
||||
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
setScene(new QGraphicsScene(this));
|
||||
|
||||
m_renderer = new QSvgRenderer();
|
||||
background = new QGraphicsSvgItem();
|
||||
foreground = new QGraphicsSvgItem();
|
||||
|
||||
paint();
|
||||
|
||||
// Now connect the widget to the SystemAlarms UAVObject
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
||||
|
||||
SystemAlarms* obj = dynamic_cast<SystemAlarms*>(objManager->getObject(QString("SystemAlarms")));
|
||||
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(updateAlarms(UAVObject*)));
|
||||
|
||||
// Test code for timer to move the index
|
||||
testValue=0;
|
||||
connect(&m_testTimer, SIGNAL(timeout()), this, SLOT(testRotate()));
|
||||
m_testTimer.start(1000);
|
||||
}
|
||||
|
||||
void SystemHealthGadgetWidget::updateAlarms(UAVObject* systemAlarm)
|
||||
{
|
||||
// This code does not know anything about alarms beforehand, and
|
||||
// I found to efficient way to locate items inside the scene by
|
||||
// name, so it's just as simple to reset the scene:
|
||||
// And add the one with the right name.
|
||||
QGraphicsScene *m_scene = scene();
|
||||
foreach ( QGraphicsItem* item , m_scene->items()){
|
||||
m_scene->removeItem(item);
|
||||
}
|
||||
m_scene->addItem(background);
|
||||
|
||||
QString alarm = systemAlarm->getName();
|
||||
foreach (UAVObjectField *field, systemAlarm->getFields()) {
|
||||
for (uint i = 0; i < field->getNumElements(); ++i) {
|
||||
QString element = field->getElementNames()[i];
|
||||
QString value = field->getValue(i).toString();
|
||||
if (m_renderer->elementExists(element)) {
|
||||
QMatrix blockMatrix = m_renderer->matrixForElement(element);
|
||||
qreal startX = blockMatrix.mapRect(m_renderer->boundsOnElement(element)).x();
|
||||
qreal startY = blockMatrix.mapRect(m_renderer->boundsOnElement(element)).y();
|
||||
QString element2 = element + "-" + value;
|
||||
if (m_renderer->elementExists(element2)) {
|
||||
QGraphicsSvgItem *ind = new QGraphicsSvgItem();
|
||||
ind->setSharedRenderer(m_renderer);
|
||||
ind->setElementId(element2);
|
||||
QTransform matrix;
|
||||
matrix.translate(startX,startY);
|
||||
ind->setTransform(matrix,false);
|
||||
m_scene->addItem(ind);
|
||||
} else {
|
||||
std::cout << "Warning: element " << element2.toStdString() << " not found in SVG."<<std::endl;
|
||||
}
|
||||
} else {
|
||||
std::cout << "Warning: Element " << element.toStdString() << " not found in SVG." << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
m_scene->addItem(foreground);
|
||||
}
|
||||
|
||||
SystemHealthGadgetWidget::~SystemHealthGadgetWidget()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
|
||||
void SystemHealthGadgetWidget::setSystemFile(QString dfn)
|
||||
{
|
||||
if (QFile::exists(dfn))
|
||||
{
|
||||
m_renderer->load(dfn);
|
||||
if(m_renderer->isValid())
|
||||
{
|
||||
fgenabled = false;
|
||||
|
||||
background->setSharedRenderer(m_renderer);
|
||||
background->setElementId("background");
|
||||
|
||||
if (m_renderer->elementExists("foreground")) {
|
||||
foreground->setSharedRenderer(m_renderer);
|
||||
foreground->setElementId("foreground");
|
||||
foreground->setZValue(99);
|
||||
fgenabled = true;
|
||||
}
|
||||
std::cout<<"Dial file loaded"<<std::endl;
|
||||
QGraphicsScene *l_scene = scene();
|
||||
l_scene->setSceneRect(background->boundingRect());
|
||||
fitInView(background, Qt::KeepAspectRatio );
|
||||
}
|
||||
}
|
||||
else
|
||||
{ std::cout<<"no file: "<<std::endl; }
|
||||
}
|
||||
|
||||
void SystemHealthGadgetWidget::paint()
|
||||
{
|
||||
QGraphicsScene *l_scene = scene();
|
||||
l_scene->clear();
|
||||
l_scene->addItem(background);
|
||||
l_scene->addItem(foreground);
|
||||
update();
|
||||
}
|
||||
|
||||
void SystemHealthGadgetWidget::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
// Skip painting until the dial file is loaded
|
||||
if (! m_renderer->isValid()) {
|
||||
std::cout<<"System file not loaded, not rendering"<<std::endl;
|
||||
return;
|
||||
}
|
||||
QGraphicsView::paintEvent(event);
|
||||
}
|
||||
|
||||
// This event enables the dial to be dynamically resized
|
||||
// whenever the gadget is resized, taking advantage of the vector
|
||||
// nature of SVG dials.
|
||||
void SystemHealthGadgetWidget::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
fitInView(background, Qt::KeepAspectRatio );
|
||||
}
|
||||
|
||||
|
||||
// Test function for timer to rotate needles
|
||||
void SystemHealthGadgetWidget::test()
|
||||
{
|
||||
testValue=0;
|
||||
|
||||
}
|
||||
|
@ -1,74 +1,74 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file systemhealthgadgetwidget.h
|
||||
* @author Edouard Lafargue Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup systemhealth
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef SYSTEMHEALTHGADGETWIDGET_H_
|
||||
#define SYSTEMHEALTHGADGETWIDGET_H_
|
||||
|
||||
#include "systemhealthgadgetconfiguration.h"
|
||||
#include "uavobjects/uavobject.h"
|
||||
#include <QGraphicsView>
|
||||
#include <QtSvg/QSvgRenderer>
|
||||
#include <QtSvg/QGraphicsSvgItem>
|
||||
|
||||
#include <QFile>
|
||||
#include <QTimer>
|
||||
|
||||
class SystemHealthGadgetWidget : public QGraphicsView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SystemHealthGadgetWidget(QWidget *parent = 0);
|
||||
~SystemHealthGadgetWidget();
|
||||
void setSystemFile(QString dfn);
|
||||
void setIndicator(QString indicator);
|
||||
void paint();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
|
||||
private slots:
|
||||
// Test function
|
||||
void test();
|
||||
void updateAlarms(UAVObject *systemAlarm); // Called by the systemalarms UAVObject
|
||||
|
||||
private:
|
||||
QSvgRenderer *m_renderer;
|
||||
QGraphicsSvgItem *background;
|
||||
QGraphicsSvgItem *foreground;
|
||||
|
||||
// Simple flag to skip rendering if the
|
||||
bool fgenabled; // layer does not exist.
|
||||
|
||||
|
||||
// Test variables
|
||||
double testValue;
|
||||
QTimer m_testTimer;
|
||||
// End test variables
|
||||
};
|
||||
#endif /* SYSTEMHEALTHGADGETWIDGET_H_ */
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file systemhealthgadgetwidget.h
|
||||
* @author Edouard Lafargue Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup systemhealthplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef SYSTEMHEALTHGADGETWIDGET_H_
|
||||
#define SYSTEMHEALTHGADGETWIDGET_H_
|
||||
|
||||
#include "systemhealthgadgetconfiguration.h"
|
||||
#include "uavobjects/uavobject.h"
|
||||
#include <QGraphicsView>
|
||||
#include <QtSvg/QSvgRenderer>
|
||||
#include <QtSvg/QGraphicsSvgItem>
|
||||
|
||||
#include <QFile>
|
||||
#include <QTimer>
|
||||
|
||||
class SystemHealthGadgetWidget : public QGraphicsView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SystemHealthGadgetWidget(QWidget *parent = 0);
|
||||
~SystemHealthGadgetWidget();
|
||||
void setSystemFile(QString dfn);
|
||||
void setIndicator(QString indicator);
|
||||
void paint();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
|
||||
private slots:
|
||||
// Test function
|
||||
void test();
|
||||
void updateAlarms(UAVObject *systemAlarm); // Called by the systemalarms UAVObject
|
||||
|
||||
private:
|
||||
QSvgRenderer *m_renderer;
|
||||
QGraphicsSvgItem *background;
|
||||
QGraphicsSvgItem *foreground;
|
||||
|
||||
// Simple flag to skip rendering if the
|
||||
bool fgenabled; // layer does not exist.
|
||||
|
||||
|
||||
// Test variables
|
||||
double testValue;
|
||||
QTimer m_testTimer;
|
||||
// End test variables
|
||||
};
|
||||
#endif /* SYSTEMHEALTHGADGETWIDGET_H_ */
|
||||
|
@ -1,65 +1,65 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file systemhealthplugin.h
|
||||
* @author Edouard Lafargue Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup systemhealth
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "systemhealthplugin.h"
|
||||
#include "systemhealthgadgetfactory.h"
|
||||
#include <QDebug>
|
||||
#include <QtPlugin>
|
||||
#include <QStringList>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
|
||||
SystemHealthPlugin::SystemHealthPlugin()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
SystemHealthPlugin::~SystemHealthPlugin()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
bool SystemHealthPlugin::initialize(const QStringList& args, QString *errMsg)
|
||||
{
|
||||
Q_UNUSED(args);
|
||||
Q_UNUSED(errMsg);
|
||||
mf = new SystemHealthGadgetFactory(this);
|
||||
addAutoReleasedObject(mf);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SystemHealthPlugin::extensionsInitialized()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
void SystemHealthPlugin::shutdown()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
Q_EXPORT_PLUGIN(SystemHealthPlugin)
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file systemhealthplugin.h
|
||||
* @author Edouard Lafargue Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup systemhealthplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "systemhealthplugin.h"
|
||||
#include "systemhealthgadgetfactory.h"
|
||||
#include <QDebug>
|
||||
#include <QtPlugin>
|
||||
#include <QStringList>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
|
||||
SystemHealthPlugin::SystemHealthPlugin()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
SystemHealthPlugin::~SystemHealthPlugin()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
bool SystemHealthPlugin::initialize(const QStringList& args, QString *errMsg)
|
||||
{
|
||||
Q_UNUSED(args);
|
||||
Q_UNUSED(errMsg);
|
||||
mf = new SystemHealthGadgetFactory(this);
|
||||
addAutoReleasedObject(mf);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SystemHealthPlugin::extensionsInitialized()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
void SystemHealthPlugin::shutdown()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
Q_EXPORT_PLUGIN(SystemHealthPlugin)
|
||||
|
@ -1,47 +1,47 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file systemhealthplugin.h
|
||||
* @author Edouard Lafargue Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup systemhealth
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef SYSTEMHEALTHPLUGIN_H_
|
||||
#define SYSTEMHEALTHPLUGIN_H_
|
||||
|
||||
#include <extensionsystem/iplugin.h>
|
||||
|
||||
class SystemHealthGadgetFactory;
|
||||
|
||||
class SystemHealthPlugin : public ExtensionSystem::IPlugin
|
||||
{
|
||||
public:
|
||||
SystemHealthPlugin();
|
||||
~SystemHealthPlugin();
|
||||
|
||||
void extensionsInitialized();
|
||||
bool initialize(const QStringList & arguments, QString * errorString);
|
||||
void shutdown();
|
||||
private:
|
||||
SystemHealthGadgetFactory *mf;
|
||||
};
|
||||
#endif /* SYSTEMHEALTHPLUGIN_H_ */
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file systemhealthplugin.h
|
||||
* @author Edouard Lafargue Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup systemhealthplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef SYSTEMHEALTHPLUGIN_H_
|
||||
#define SYSTEMHEALTHPLUGIN_H_
|
||||
|
||||
#include <extensionsystem/iplugin.h>
|
||||
|
||||
class SystemHealthGadgetFactory;
|
||||
|
||||
class SystemHealthPlugin : public ExtensionSystem::IPlugin
|
||||
{
|
||||
public:
|
||||
SystemHealthPlugin();
|
||||
~SystemHealthPlugin();
|
||||
|
||||
void extensionsInitialized();
|
||||
bool initialize(const QStringList & arguments, QString * errorString);
|
||||
void shutdown();
|
||||
private:
|
||||
SystemHealthGadgetFactory *mf;
|
||||
};
|
||||
#endif /* SYSTEMHEALTHPLUGIN_H_ */
|
||||
|
@ -1,72 +1,72 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file browseritemdelegate.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowser
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "browseritemdelegate.h"
|
||||
#include "fieldtreeitem.h"
|
||||
|
||||
BrowserItemDelegate::BrowserItemDelegate(QObject *parent) :
|
||||
QStyledItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
|
||||
QWidget *BrowserItemDelegate::createEditor(QWidget *parent,
|
||||
const QStyleOptionViewItem & option ,
|
||||
const QModelIndex & index ) const
|
||||
{
|
||||
FieldTreeItem *item = static_cast<FieldTreeItem*>(index.internalPointer());
|
||||
QWidget *editor = item->createEditor(parent);
|
||||
Q_ASSERT(editor);
|
||||
return editor;
|
||||
}
|
||||
|
||||
|
||||
void BrowserItemDelegate::setEditorData(QWidget *editor,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
FieldTreeItem *item = static_cast<FieldTreeItem*>(index.internalPointer());
|
||||
QVariant value = index.model()->data(index, Qt::EditRole);
|
||||
item->setEditorValue(editor, value);
|
||||
}
|
||||
|
||||
void BrowserItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
FieldTreeItem *item = static_cast<FieldTreeItem*>(index.internalPointer());
|
||||
QVariant value = item->getEditorValue(editor);
|
||||
model->setData(index, value, Qt::EditRole);
|
||||
}
|
||||
|
||||
void BrowserItemDelegate::updateEditorGeometry(QWidget *editor,
|
||||
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
|
||||
{
|
||||
editor->setGeometry(option.rect);
|
||||
}
|
||||
|
||||
QSize BrowserItemDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex &index) const
|
||||
{
|
||||
return QSpinBox().sizeHint();
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file browseritemdelegate.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowserplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "browseritemdelegate.h"
|
||||
#include "fieldtreeitem.h"
|
||||
|
||||
BrowserItemDelegate::BrowserItemDelegate(QObject *parent) :
|
||||
QStyledItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
|
||||
QWidget *BrowserItemDelegate::createEditor(QWidget *parent,
|
||||
const QStyleOptionViewItem & option ,
|
||||
const QModelIndex & index ) const
|
||||
{
|
||||
FieldTreeItem *item = static_cast<FieldTreeItem*>(index.internalPointer());
|
||||
QWidget *editor = item->createEditor(parent);
|
||||
Q_ASSERT(editor);
|
||||
return editor;
|
||||
}
|
||||
|
||||
|
||||
void BrowserItemDelegate::setEditorData(QWidget *editor,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
FieldTreeItem *item = static_cast<FieldTreeItem*>(index.internalPointer());
|
||||
QVariant value = index.model()->data(index, Qt::EditRole);
|
||||
item->setEditorValue(editor, value);
|
||||
}
|
||||
|
||||
void BrowserItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
FieldTreeItem *item = static_cast<FieldTreeItem*>(index.internalPointer());
|
||||
QVariant value = item->getEditorValue(editor);
|
||||
model->setData(index, value, Qt::EditRole);
|
||||
}
|
||||
|
||||
void BrowserItemDelegate::updateEditorGeometry(QWidget *editor,
|
||||
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
|
||||
{
|
||||
editor->setGeometry(option.rect);
|
||||
}
|
||||
|
||||
QSize BrowserItemDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex &index) const
|
||||
{
|
||||
return QSpinBox().sizeHint();
|
||||
}
|
||||
|
@ -1,58 +1,58 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file browseritemdelegate.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowser
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef BROWSERITEMDELEGATE_H
|
||||
#define BROWSERITEMDELEGATE_H
|
||||
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
class BrowserItemDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit BrowserItemDelegate(QObject *parent = 0);
|
||||
|
||||
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const;
|
||||
|
||||
void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
||||
void setModelData(QWidget *editor, QAbstractItemModel *model,
|
||||
const QModelIndex &index) const;
|
||||
|
||||
void updateEditorGeometry(QWidget *editor,
|
||||
const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
QSize sizeHint(const QStyleOptionViewItem & option,
|
||||
const QModelIndex &index) const;
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
};
|
||||
|
||||
#endif // BROWSERITEMDELEGATE_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file browseritemdelegate.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowserplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef BROWSERITEMDELEGATE_H
|
||||
#define BROWSERITEMDELEGATE_H
|
||||
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
class BrowserItemDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit BrowserItemDelegate(QObject *parent = 0);
|
||||
|
||||
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const;
|
||||
|
||||
void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
||||
void setModelData(QWidget *editor, QAbstractItemModel *model,
|
||||
const QModelIndex &index) const;
|
||||
|
||||
void updateEditorGeometry(QWidget *editor,
|
||||
const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
QSize sizeHint(const QStyleOptionViewItem & option,
|
||||
const QModelIndex &index) const;
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
};
|
||||
|
||||
#endif // BROWSERITEMDELEGATE_H
|
||||
|
@ -1,63 +1,63 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file mapplugin.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowser
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "browserplugin.h"
|
||||
#include "uavobjectbrowserfactory.h"
|
||||
#include <QtPlugin>
|
||||
#include <QStringList>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
BrowserPlugin::BrowserPlugin()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
BrowserPlugin::~BrowserPlugin()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
bool BrowserPlugin::initialize(const QStringList& args, QString *errMsg)
|
||||
{
|
||||
Q_UNUSED(args);
|
||||
Q_UNUSED(errMsg);
|
||||
mf = new UAVObjectBrowserFactory(this);
|
||||
addAutoReleasedObject(mf);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void BrowserPlugin::extensionsInitialized()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
void BrowserPlugin::shutdown()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
Q_EXPORT_PLUGIN(BrowserPlugin)
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file mapplugin.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowserplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "browserplugin.h"
|
||||
#include "uavobjectbrowserfactory.h"
|
||||
#include <QtPlugin>
|
||||
#include <QStringList>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
BrowserPlugin::BrowserPlugin()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
BrowserPlugin::~BrowserPlugin()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
bool BrowserPlugin::initialize(const QStringList& args, QString *errMsg)
|
||||
{
|
||||
Q_UNUSED(args);
|
||||
Q_UNUSED(errMsg);
|
||||
mf = new UAVObjectBrowserFactory(this);
|
||||
addAutoReleasedObject(mf);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void BrowserPlugin::extensionsInitialized()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
void BrowserPlugin::shutdown()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
Q_EXPORT_PLUGIN(BrowserPlugin)
|
||||
|
||||
|
@ -1,47 +1,47 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file browserplugin.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowser
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UAVOBJECTBROWSERPLUGIN_H_
|
||||
#define UAVOBJECTBROWSERPLUGIN_H_
|
||||
|
||||
#include <extensionsystem/iplugin.h>
|
||||
|
||||
class UAVObjectBrowserFactory;
|
||||
|
||||
class BrowserPlugin : public ExtensionSystem::IPlugin
|
||||
{
|
||||
public:
|
||||
BrowserPlugin();
|
||||
~BrowserPlugin();
|
||||
|
||||
void extensionsInitialized();
|
||||
bool initialize(const QStringList & arguments, QString * errorString);
|
||||
void shutdown();
|
||||
private:
|
||||
UAVObjectBrowserFactory *mf;
|
||||
};
|
||||
#endif /* UAVOBJECTBROWSERPLUGIN_H_ */
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file browserplugin.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowserplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UAVOBJECTBROWSERPLUGIN_H_
|
||||
#define UAVOBJECTBROWSERPLUGIN_H_
|
||||
|
||||
#include <extensionsystem/iplugin.h>
|
||||
|
||||
class UAVObjectBrowserFactory;
|
||||
|
||||
class BrowserPlugin : public ExtensionSystem::IPlugin
|
||||
{
|
||||
public:
|
||||
BrowserPlugin();
|
||||
~BrowserPlugin();
|
||||
|
||||
void extensionsInitialized();
|
||||
bool initialize(const QStringList & arguments, QString * errorString);
|
||||
void shutdown();
|
||||
private:
|
||||
UAVObjectBrowserFactory *mf;
|
||||
};
|
||||
#endif /* UAVOBJECTBROWSERPLUGIN_H_ */
|
||||
|
@ -1,29 +1,29 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file fieldtreeitem.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowser
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "fieldtreeitem.h"
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file fieldtreeitem.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowserplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "fieldtreeitem.h"
|
||||
|
||||
|
@ -1,250 +1,250 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file fieldtreeitem.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowser
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef FIELDTREEITEM_H
|
||||
#define FIELDTREEITEM_H
|
||||
|
||||
#include "treeitem.h"
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtGui/QWidget>
|
||||
#include <QtGui/QSpinBox>
|
||||
#include <QtGui/QDoubleSpinBox>
|
||||
#include <QtGui/QComboBox>
|
||||
#include <limits>
|
||||
|
||||
#define QINT8MIN std::numeric_limits<qint8>::min()
|
||||
#define QINT8MAX std::numeric_limits<qint8>::max()
|
||||
#define QUINTMIN std::numeric_limits<quint8>::min()
|
||||
#define QUINT8MAX std::numeric_limits<quint8>::max()
|
||||
#define QINT16MIN std::numeric_limits<qint16>::min()
|
||||
#define QINT16MAX std::numeric_limits<qint16>::max()
|
||||
#define QUINT16MAX std::numeric_limits<quint16>::max()
|
||||
#define QINT32MIN std::numeric_limits<qint32>::min()
|
||||
#define QINT32MAX std::numeric_limits<qint32>::max()
|
||||
#define QUINT32MAX std::numeric_limits<qint32>::max()
|
||||
|
||||
class FieldTreeItem : public TreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FieldTreeItem(int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
TreeItem(data, parent), m_index(index) { }
|
||||
FieldTreeItem(int index, const QVariant &data, TreeItem *parent = 0) :
|
||||
TreeItem(data, parent), m_index(index) { }
|
||||
bool isEditable() { return true; }
|
||||
virtual QWidget *createEditor(QWidget *parent) = 0;
|
||||
virtual QVariant getEditorValue(QWidget *editor) = 0;
|
||||
virtual void setEditorValue(QWidget *editor, QVariant value) = 0;
|
||||
virtual void apply() { }
|
||||
protected:
|
||||
int m_index;
|
||||
};
|
||||
|
||||
class EnumFieldTreeItem : public FieldTreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
EnumFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data,
|
||||
TreeItem *parent = 0) :
|
||||
FieldTreeItem(index, data, parent), m_enumOptions(field->getOptions()), m_field(field) { }
|
||||
EnumFieldTreeItem(UAVObjectField *field, int index, const QVariant &data,
|
||||
TreeItem *parent = 0) :
|
||||
FieldTreeItem(index, data, parent), m_enumOptions(field->getOptions()), m_field(field) { }
|
||||
void setData(QVariant value, int column) {
|
||||
QStringList options = m_field->getOptions();
|
||||
QVariant tmpValue = m_field->getValue(m_index);
|
||||
int tmpValIndex = options.indexOf(tmpValue.toString());
|
||||
setChanged(tmpValIndex != value);
|
||||
TreeItem::setData(value, column);
|
||||
}
|
||||
QString enumOptions(int index) { return m_enumOptions.at(index); }
|
||||
void apply() {
|
||||
int value = data(dataColumn).toInt();
|
||||
QStringList options = m_field->getOptions();
|
||||
m_field->setValue(options[value], m_index);
|
||||
setChanged(false);
|
||||
}
|
||||
void update() {
|
||||
QStringList options = m_field->getOptions();
|
||||
QVariant value = m_field->getValue(m_index);
|
||||
int valIndex = options.indexOf(value.toString());
|
||||
if (data() != valIndex || changed()) {
|
||||
TreeItem::setData(valIndex);
|
||||
setHighlight(true);
|
||||
}
|
||||
}
|
||||
QWidget *createEditor(QWidget *parent) {
|
||||
QComboBox *editor = new QComboBox(parent);
|
||||
foreach (QString option, m_enumOptions)
|
||||
editor->addItem(option);
|
||||
return editor;
|
||||
}
|
||||
|
||||
QVariant getEditorValue(QWidget *editor) {
|
||||
QComboBox *comboBox = static_cast<QComboBox*>(editor);
|
||||
return comboBox->currentIndex();
|
||||
}
|
||||
|
||||
void setEditorValue(QWidget *editor, QVariant value) {
|
||||
QComboBox *comboBox = static_cast<QComboBox*>(editor);
|
||||
comboBox->setCurrentIndex(value.toInt());
|
||||
}
|
||||
private:
|
||||
QStringList m_enumOptions;
|
||||
UAVObjectField *m_field;
|
||||
};
|
||||
|
||||
class IntFieldTreeItem : public FieldTreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
IntFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
FieldTreeItem(index, data, parent), m_field(field) {
|
||||
setMinMaxValues();
|
||||
}
|
||||
IntFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) :
|
||||
FieldTreeItem(index, data, parent), m_field(field) {
|
||||
setMinMaxValues();
|
||||
}
|
||||
|
||||
void setMinMaxValues() {
|
||||
switch (m_field->getType()) {
|
||||
case UAVObjectField::INT8:
|
||||
m_minValue = QINT8MIN;
|
||||
m_maxValue = QINT8MAX;
|
||||
break;
|
||||
case UAVObjectField::INT16:
|
||||
m_minValue = QINT16MIN;
|
||||
m_maxValue = QINT16MAX;
|
||||
break;
|
||||
case UAVObjectField::INT32:
|
||||
m_minValue = QINT32MIN;
|
||||
m_maxValue = QINT32MAX;
|
||||
break;
|
||||
case UAVObjectField::UINT8:
|
||||
m_minValue = QUINTMIN;
|
||||
m_maxValue = QUINT8MAX;
|
||||
break;
|
||||
case UAVObjectField::UINT16:
|
||||
m_minValue = QUINTMIN;
|
||||
m_maxValue = QUINT16MAX;
|
||||
break;
|
||||
case UAVObjectField::UINT32:
|
||||
m_minValue = QUINTMIN;
|
||||
m_maxValue = QUINT32MAX;
|
||||
break;
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QWidget *createEditor(QWidget *parent) {
|
||||
QSpinBox *editor = new QSpinBox(parent);
|
||||
editor->setMinimum(m_minValue);
|
||||
editor->setMaximum(m_maxValue);
|
||||
return editor;
|
||||
}
|
||||
|
||||
QVariant getEditorValue(QWidget *editor) {
|
||||
QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
||||
spinBox->interpretText();
|
||||
return spinBox->value();
|
||||
}
|
||||
|
||||
void setEditorValue(QWidget *editor, QVariant value) {
|
||||
QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
||||
spinBox->setValue(value.toInt());
|
||||
}
|
||||
void setData(QVariant value, int column) {
|
||||
setChanged(m_field->getValue(m_index) != value);
|
||||
TreeItem::setData(value, column);
|
||||
}
|
||||
void apply() {
|
||||
m_field->setValue(data(dataColumn).toInt(), m_index);
|
||||
setChanged(false);
|
||||
}
|
||||
void update() {
|
||||
int value = m_field->getValue(m_index).toInt();
|
||||
if (data() != value || changed()) {
|
||||
TreeItem::setData(value);
|
||||
setHighlight(true);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
UAVObjectField *m_field;
|
||||
int m_minValue;
|
||||
int m_maxValue;
|
||||
};
|
||||
|
||||
class FloatFieldTreeItem : public FieldTreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FloatFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
FieldTreeItem(index, data, parent), m_field(field) { }
|
||||
FloatFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) :
|
||||
FieldTreeItem(index, data, parent), m_field(field) { }
|
||||
void setData(QVariant value, int column) {
|
||||
setChanged(m_field->getValue(m_index) != value);
|
||||
TreeItem::setData(value, column);
|
||||
}
|
||||
void apply() {
|
||||
m_field->setValue(data(dataColumn).toDouble(), m_index);
|
||||
setChanged(false);
|
||||
}
|
||||
void update() {
|
||||
double value = m_field->getValue(m_index).toDouble();
|
||||
if (data() != value || changed()) {
|
||||
TreeItem::setData(value);
|
||||
setHighlight(true);
|
||||
}
|
||||
}
|
||||
QWidget *createEditor(QWidget *parent) {
|
||||
QDoubleSpinBox *editor = new QDoubleSpinBox(parent);
|
||||
editor->setDecimals(6);
|
||||
editor->setMinimum(-std::numeric_limits<float>::max());
|
||||
editor->setMaximum(std::numeric_limits<float>::max());
|
||||
return editor;
|
||||
}
|
||||
|
||||
QVariant getEditorValue(QWidget *editor) {
|
||||
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
|
||||
spinBox->interpretText();
|
||||
return spinBox->value();
|
||||
}
|
||||
|
||||
void setEditorValue(QWidget *editor, QVariant value) {
|
||||
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
|
||||
spinBox->setValue(value.toDouble());
|
||||
}
|
||||
private:
|
||||
UAVObjectField *m_field;
|
||||
};
|
||||
|
||||
#endif // FIELDTREEITEM_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file fieldtreeitem.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowserplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef FIELDTREEITEM_H
|
||||
#define FIELDTREEITEM_H
|
||||
|
||||
#include "treeitem.h"
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtGui/QWidget>
|
||||
#include <QtGui/QSpinBox>
|
||||
#include <QtGui/QDoubleSpinBox>
|
||||
#include <QtGui/QComboBox>
|
||||
#include <limits>
|
||||
|
||||
#define QINT8MIN std::numeric_limits<qint8>::min()
|
||||
#define QINT8MAX std::numeric_limits<qint8>::max()
|
||||
#define QUINTMIN std::numeric_limits<quint8>::min()
|
||||
#define QUINT8MAX std::numeric_limits<quint8>::max()
|
||||
#define QINT16MIN std::numeric_limits<qint16>::min()
|
||||
#define QINT16MAX std::numeric_limits<qint16>::max()
|
||||
#define QUINT16MAX std::numeric_limits<quint16>::max()
|
||||
#define QINT32MIN std::numeric_limits<qint32>::min()
|
||||
#define QINT32MAX std::numeric_limits<qint32>::max()
|
||||
#define QUINT32MAX std::numeric_limits<qint32>::max()
|
||||
|
||||
class FieldTreeItem : public TreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FieldTreeItem(int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
TreeItem(data, parent), m_index(index) { }
|
||||
FieldTreeItem(int index, const QVariant &data, TreeItem *parent = 0) :
|
||||
TreeItem(data, parent), m_index(index) { }
|
||||
bool isEditable() { return true; }
|
||||
virtual QWidget *createEditor(QWidget *parent) = 0;
|
||||
virtual QVariant getEditorValue(QWidget *editor) = 0;
|
||||
virtual void setEditorValue(QWidget *editor, QVariant value) = 0;
|
||||
virtual void apply() { }
|
||||
protected:
|
||||
int m_index;
|
||||
};
|
||||
|
||||
class EnumFieldTreeItem : public FieldTreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
EnumFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data,
|
||||
TreeItem *parent = 0) :
|
||||
FieldTreeItem(index, data, parent), m_enumOptions(field->getOptions()), m_field(field) { }
|
||||
EnumFieldTreeItem(UAVObjectField *field, int index, const QVariant &data,
|
||||
TreeItem *parent = 0) :
|
||||
FieldTreeItem(index, data, parent), m_enumOptions(field->getOptions()), m_field(field) { }
|
||||
void setData(QVariant value, int column) {
|
||||
QStringList options = m_field->getOptions();
|
||||
QVariant tmpValue = m_field->getValue(m_index);
|
||||
int tmpValIndex = options.indexOf(tmpValue.toString());
|
||||
setChanged(tmpValIndex != value);
|
||||
TreeItem::setData(value, column);
|
||||
}
|
||||
QString enumOptions(int index) { return m_enumOptions.at(index); }
|
||||
void apply() {
|
||||
int value = data(dataColumn).toInt();
|
||||
QStringList options = m_field->getOptions();
|
||||
m_field->setValue(options[value], m_index);
|
||||
setChanged(false);
|
||||
}
|
||||
void update() {
|
||||
QStringList options = m_field->getOptions();
|
||||
QVariant value = m_field->getValue(m_index);
|
||||
int valIndex = options.indexOf(value.toString());
|
||||
if (data() != valIndex || changed()) {
|
||||
TreeItem::setData(valIndex);
|
||||
setHighlight(true);
|
||||
}
|
||||
}
|
||||
QWidget *createEditor(QWidget *parent) {
|
||||
QComboBox *editor = new QComboBox(parent);
|
||||
foreach (QString option, m_enumOptions)
|
||||
editor->addItem(option);
|
||||
return editor;
|
||||
}
|
||||
|
||||
QVariant getEditorValue(QWidget *editor) {
|
||||
QComboBox *comboBox = static_cast<QComboBox*>(editor);
|
||||
return comboBox->currentIndex();
|
||||
}
|
||||
|
||||
void setEditorValue(QWidget *editor, QVariant value) {
|
||||
QComboBox *comboBox = static_cast<QComboBox*>(editor);
|
||||
comboBox->setCurrentIndex(value.toInt());
|
||||
}
|
||||
private:
|
||||
QStringList m_enumOptions;
|
||||
UAVObjectField *m_field;
|
||||
};
|
||||
|
||||
class IntFieldTreeItem : public FieldTreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
IntFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
FieldTreeItem(index, data, parent), m_field(field) {
|
||||
setMinMaxValues();
|
||||
}
|
||||
IntFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) :
|
||||
FieldTreeItem(index, data, parent), m_field(field) {
|
||||
setMinMaxValues();
|
||||
}
|
||||
|
||||
void setMinMaxValues() {
|
||||
switch (m_field->getType()) {
|
||||
case UAVObjectField::INT8:
|
||||
m_minValue = QINT8MIN;
|
||||
m_maxValue = QINT8MAX;
|
||||
break;
|
||||
case UAVObjectField::INT16:
|
||||
m_minValue = QINT16MIN;
|
||||
m_maxValue = QINT16MAX;
|
||||
break;
|
||||
case UAVObjectField::INT32:
|
||||
m_minValue = QINT32MIN;
|
||||
m_maxValue = QINT32MAX;
|
||||
break;
|
||||
case UAVObjectField::UINT8:
|
||||
m_minValue = QUINTMIN;
|
||||
m_maxValue = QUINT8MAX;
|
||||
break;
|
||||
case UAVObjectField::UINT16:
|
||||
m_minValue = QUINTMIN;
|
||||
m_maxValue = QUINT16MAX;
|
||||
break;
|
||||
case UAVObjectField::UINT32:
|
||||
m_minValue = QUINTMIN;
|
||||
m_maxValue = QUINT32MAX;
|
||||
break;
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QWidget *createEditor(QWidget *parent) {
|
||||
QSpinBox *editor = new QSpinBox(parent);
|
||||
editor->setMinimum(m_minValue);
|
||||
editor->setMaximum(m_maxValue);
|
||||
return editor;
|
||||
}
|
||||
|
||||
QVariant getEditorValue(QWidget *editor) {
|
||||
QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
||||
spinBox->interpretText();
|
||||
return spinBox->value();
|
||||
}
|
||||
|
||||
void setEditorValue(QWidget *editor, QVariant value) {
|
||||
QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
||||
spinBox->setValue(value.toInt());
|
||||
}
|
||||
void setData(QVariant value, int column) {
|
||||
setChanged(m_field->getValue(m_index) != value);
|
||||
TreeItem::setData(value, column);
|
||||
}
|
||||
void apply() {
|
||||
m_field->setValue(data(dataColumn).toInt(), m_index);
|
||||
setChanged(false);
|
||||
}
|
||||
void update() {
|
||||
int value = m_field->getValue(m_index).toInt();
|
||||
if (data() != value || changed()) {
|
||||
TreeItem::setData(value);
|
||||
setHighlight(true);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
UAVObjectField *m_field;
|
||||
int m_minValue;
|
||||
int m_maxValue;
|
||||
};
|
||||
|
||||
class FloatFieldTreeItem : public FieldTreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FloatFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
FieldTreeItem(index, data, parent), m_field(field) { }
|
||||
FloatFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) :
|
||||
FieldTreeItem(index, data, parent), m_field(field) { }
|
||||
void setData(QVariant value, int column) {
|
||||
setChanged(m_field->getValue(m_index) != value);
|
||||
TreeItem::setData(value, column);
|
||||
}
|
||||
void apply() {
|
||||
m_field->setValue(data(dataColumn).toDouble(), m_index);
|
||||
setChanged(false);
|
||||
}
|
||||
void update() {
|
||||
double value = m_field->getValue(m_index).toDouble();
|
||||
if (data() != value || changed()) {
|
||||
TreeItem::setData(value);
|
||||
setHighlight(true);
|
||||
}
|
||||
}
|
||||
QWidget *createEditor(QWidget *parent) {
|
||||
QDoubleSpinBox *editor = new QDoubleSpinBox(parent);
|
||||
editor->setDecimals(6);
|
||||
editor->setMinimum(-std::numeric_limits<float>::max());
|
||||
editor->setMaximum(std::numeric_limits<float>::max());
|
||||
return editor;
|
||||
}
|
||||
|
||||
QVariant getEditorValue(QWidget *editor) {
|
||||
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
|
||||
spinBox->interpretText();
|
||||
return spinBox->value();
|
||||
}
|
||||
|
||||
void setEditorValue(QWidget *editor, QVariant value) {
|
||||
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
|
||||
spinBox->setValue(value.toDouble());
|
||||
}
|
||||
private:
|
||||
UAVObjectField *m_field;
|
||||
};
|
||||
|
||||
#endif // FIELDTREEITEM_H
|
||||
|
@ -1,128 +1,128 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file treeitem.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowser
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "treeitem.h"
|
||||
|
||||
int TreeItem::m_highlightTimeMs = 500;
|
||||
|
||||
TreeItem::TreeItem(const QList<QVariant> &data, TreeItem *parent) :
|
||||
QObject(0),
|
||||
m_data(data),
|
||||
m_parent(parent),
|
||||
m_highlight(false),
|
||||
m_changed(false)
|
||||
{
|
||||
connect(&m_timer, SIGNAL(timeout()), this, SLOT(removeHighlight()));
|
||||
}
|
||||
|
||||
TreeItem::TreeItem(const QVariant &data, TreeItem *parent) :
|
||||
QObject(0),
|
||||
m_parent(parent),
|
||||
m_highlight(false),
|
||||
m_changed(false)
|
||||
{
|
||||
m_data << data << "" << "";
|
||||
connect(&m_timer, SIGNAL(timeout()), this, SLOT(removeHighlight()));
|
||||
}
|
||||
|
||||
TreeItem::~TreeItem()
|
||||
{
|
||||
qDeleteAll(m_children);
|
||||
}
|
||||
|
||||
void TreeItem::appendChild(TreeItem *child)
|
||||
{
|
||||
m_children.append(child);
|
||||
child->setParentTree(this);
|
||||
}
|
||||
|
||||
void TreeItem::insert(int index, TreeItem *child)
|
||||
{
|
||||
m_children.insert(index, child);
|
||||
child->setParentTree(this);
|
||||
}
|
||||
|
||||
TreeItem *TreeItem::child(int row)
|
||||
{
|
||||
return m_children.value(row);
|
||||
}
|
||||
|
||||
int TreeItem::childCount() const
|
||||
{
|
||||
return m_children.count();
|
||||
}
|
||||
int TreeItem::row() const
|
||||
{
|
||||
if (m_parent)
|
||||
return m_parent->m_children.indexOf(const_cast<TreeItem*>(this));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int TreeItem::columnCount() const
|
||||
{
|
||||
return m_data.count();
|
||||
}
|
||||
|
||||
QVariant TreeItem::data(int column) const
|
||||
{
|
||||
return m_data.value(column);
|
||||
}
|
||||
|
||||
void TreeItem::setData(QVariant value, int column)
|
||||
{
|
||||
m_data.replace(column, value);
|
||||
}
|
||||
|
||||
void TreeItem::update() {
|
||||
foreach(TreeItem *child, treeChildren())
|
||||
child->update();
|
||||
}
|
||||
|
||||
void TreeItem::apply() {
|
||||
foreach(TreeItem *child, treeChildren())
|
||||
child->apply();
|
||||
}
|
||||
|
||||
void TreeItem::setHighlight(bool highlight) {
|
||||
m_highlight = highlight;
|
||||
m_changed = false;
|
||||
if (highlight) {
|
||||
if (m_timer.isActive()) {
|
||||
m_timer.stop();
|
||||
}
|
||||
m_timer.setSingleShot(true);
|
||||
m_timer.start(m_highlightTimeMs);
|
||||
}
|
||||
emit updateHighlight(this);
|
||||
}
|
||||
|
||||
void TreeItem::removeHighlight() {
|
||||
m_highlight = false;
|
||||
update();
|
||||
emit updateHighlight(this);
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file treeitem.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowserplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "treeitem.h"
|
||||
|
||||
int TreeItem::m_highlightTimeMs = 500;
|
||||
|
||||
TreeItem::TreeItem(const QList<QVariant> &data, TreeItem *parent) :
|
||||
QObject(0),
|
||||
m_data(data),
|
||||
m_parent(parent),
|
||||
m_highlight(false),
|
||||
m_changed(false)
|
||||
{
|
||||
connect(&m_timer, SIGNAL(timeout()), this, SLOT(removeHighlight()));
|
||||
}
|
||||
|
||||
TreeItem::TreeItem(const QVariant &data, TreeItem *parent) :
|
||||
QObject(0),
|
||||
m_parent(parent),
|
||||
m_highlight(false),
|
||||
m_changed(false)
|
||||
{
|
||||
m_data << data << "" << "";
|
||||
connect(&m_timer, SIGNAL(timeout()), this, SLOT(removeHighlight()));
|
||||
}
|
||||
|
||||
TreeItem::~TreeItem()
|
||||
{
|
||||
qDeleteAll(m_children);
|
||||
}
|
||||
|
||||
void TreeItem::appendChild(TreeItem *child)
|
||||
{
|
||||
m_children.append(child);
|
||||
child->setParentTree(this);
|
||||
}
|
||||
|
||||
void TreeItem::insert(int index, TreeItem *child)
|
||||
{
|
||||
m_children.insert(index, child);
|
||||
child->setParentTree(this);
|
||||
}
|
||||
|
||||
TreeItem *TreeItem::child(int row)
|
||||
{
|
||||
return m_children.value(row);
|
||||
}
|
||||
|
||||
int TreeItem::childCount() const
|
||||
{
|
||||
return m_children.count();
|
||||
}
|
||||
int TreeItem::row() const
|
||||
{
|
||||
if (m_parent)
|
||||
return m_parent->m_children.indexOf(const_cast<TreeItem*>(this));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int TreeItem::columnCount() const
|
||||
{
|
||||
return m_data.count();
|
||||
}
|
||||
|
||||
QVariant TreeItem::data(int column) const
|
||||
{
|
||||
return m_data.value(column);
|
||||
}
|
||||
|
||||
void TreeItem::setData(QVariant value, int column)
|
||||
{
|
||||
m_data.replace(column, value);
|
||||
}
|
||||
|
||||
void TreeItem::update() {
|
||||
foreach(TreeItem *child, treeChildren())
|
||||
child->update();
|
||||
}
|
||||
|
||||
void TreeItem::apply() {
|
||||
foreach(TreeItem *child, treeChildren())
|
||||
child->apply();
|
||||
}
|
||||
|
||||
void TreeItem::setHighlight(bool highlight) {
|
||||
m_highlight = highlight;
|
||||
m_changed = false;
|
||||
if (highlight) {
|
||||
if (m_timer.isActive()) {
|
||||
m_timer.stop();
|
||||
}
|
||||
m_timer.setSingleShot(true);
|
||||
m_timer.start(m_highlightTimeMs);
|
||||
}
|
||||
emit updateHighlight(this);
|
||||
}
|
||||
|
||||
void TreeItem::removeHighlight() {
|
||||
m_highlight = false;
|
||||
update();
|
||||
emit updateHighlight(this);
|
||||
}
|
||||
|
@ -1,183 +1,183 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file treeitem.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowser
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef TREEITEM_H
|
||||
#define TREEITEM_H
|
||||
|
||||
#include "uavobjects/uavobject.h"
|
||||
#include "uavobjects/uavmetaobject.h"
|
||||
#include "uavobjects/uavobjectfield.h"
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtCore/QTimer>
|
||||
#include <QtCore/QObject>
|
||||
|
||||
|
||||
class TreeItem : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TreeItem(const QList<QVariant> &data, TreeItem *parent = 0);
|
||||
TreeItem(const QVariant &data, TreeItem *parent = 0);
|
||||
virtual ~TreeItem();
|
||||
|
||||
void appendChild(TreeItem *child);
|
||||
void insert(int index, TreeItem *child);
|
||||
|
||||
TreeItem *child(int row);
|
||||
inline QList<TreeItem*> treeChildren() const { return m_children; }
|
||||
int childCount() const;
|
||||
int columnCount() const;
|
||||
QVariant data(int column = 1) const;
|
||||
// only column 1 (TreeItem::dataColumn) is changed with setData currently
|
||||
// other columns are initialized in constructor
|
||||
virtual void setData(QVariant value, int column = 1);
|
||||
int row() const;
|
||||
TreeItem *parent() { return m_parent; }
|
||||
void setParentTree(TreeItem *parent) { m_parent = parent; }
|
||||
inline virtual bool isEditable() { return false; }
|
||||
virtual void update();
|
||||
virtual void apply();
|
||||
|
||||
inline bool highlighted() { return m_highlight; }
|
||||
void setHighlight(bool highlight);
|
||||
static void setHighlightTime(int time) { m_highlightTimeMs = time; }
|
||||
|
||||
inline bool changed() { return m_changed; }
|
||||
inline void setChanged(bool changed) { m_changed = changed; }
|
||||
|
||||
signals:
|
||||
void updateHighlight(TreeItem*);
|
||||
|
||||
private slots:
|
||||
void removeHighlight();
|
||||
|
||||
private:
|
||||
QList<TreeItem*> m_children;
|
||||
// m_data contains: [0] property name, [1] value, and [2] unit
|
||||
QList<QVariant> m_data;
|
||||
TreeItem *m_parent;
|
||||
bool m_highlight;
|
||||
bool m_changed;
|
||||
QTimer m_timer;
|
||||
public:
|
||||
static const int dataColumn = 1;
|
||||
private:
|
||||
static int m_highlightTimeMs;
|
||||
};
|
||||
|
||||
class TopTreeItem : public TreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TopTreeItem(const QList<QVariant> &data, TreeItem *parent = 0) : TreeItem(data, parent) { }
|
||||
TopTreeItem(const QVariant &data, TreeItem *parent = 0) : TreeItem(data, parent) { }
|
||||
|
||||
QList<quint32> objIds() { return m_objIds; }
|
||||
void addObjId(quint32 objId) { m_objIds.append(objId); }
|
||||
void insertObjId(int index, quint32 objId) { m_objIds.insert(index, objId); }
|
||||
int nameIndex(QString name) {
|
||||
for (int i = 0; i < childCount(); ++i) {
|
||||
if (name < child(i)->data(0).toString())
|
||||
return i;
|
||||
}
|
||||
return childCount();
|
||||
}
|
||||
|
||||
private:
|
||||
QList<quint32> m_objIds;
|
||||
};
|
||||
|
||||
class ObjectTreeItem : public TreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ObjectTreeItem(const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
TreeItem(data, parent), m_obj(0) { }
|
||||
ObjectTreeItem(const QVariant &data, TreeItem *parent = 0) :
|
||||
TreeItem(data, parent), m_obj(0) { }
|
||||
void setObject(UAVObject *obj) { m_obj = obj; }
|
||||
inline UAVObject *object() { return m_obj; }
|
||||
private:
|
||||
UAVObject *m_obj;
|
||||
};
|
||||
|
||||
class MetaObjectTreeItem : public ObjectTreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MetaObjectTreeItem(UAVObject *obj, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
ObjectTreeItem(data, parent) { setObject(obj); }
|
||||
MetaObjectTreeItem(UAVObject *obj, const QVariant &data, TreeItem *parent = 0) :
|
||||
ObjectTreeItem(data, parent) { setObject(obj); }
|
||||
};
|
||||
|
||||
class DataObjectTreeItem : public ObjectTreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DataObjectTreeItem(const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
ObjectTreeItem(data, parent) { }
|
||||
DataObjectTreeItem(const QVariant &data, TreeItem *parent = 0) :
|
||||
ObjectTreeItem(data, parent) { }
|
||||
virtual void apply() {
|
||||
foreach(TreeItem *child, treeChildren()) {
|
||||
MetaObjectTreeItem *metaChild = dynamic_cast<MetaObjectTreeItem*>(child);
|
||||
if (!metaChild)
|
||||
child->apply();
|
||||
}
|
||||
}
|
||||
virtual void update() {
|
||||
foreach(TreeItem *child, treeChildren()) {
|
||||
MetaObjectTreeItem *metaChild = dynamic_cast<MetaObjectTreeItem*>(child);
|
||||
if (!metaChild)
|
||||
child->update();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class InstanceTreeItem : public DataObjectTreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
InstanceTreeItem(UAVObject *obj, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
DataObjectTreeItem(data, parent) { setObject(obj); }
|
||||
InstanceTreeItem(UAVObject *obj, const QVariant &data, TreeItem *parent = 0) :
|
||||
DataObjectTreeItem(data, parent) { setObject(obj); }
|
||||
virtual void apply() { TreeItem::apply(); }
|
||||
virtual void update() { TreeItem::update(); }
|
||||
};
|
||||
|
||||
class ArrayFieldTreeItem : public TreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ArrayFieldTreeItem(const QList<QVariant> &data, TreeItem *parent = 0) : TreeItem(data, parent) { }
|
||||
ArrayFieldTreeItem(const QVariant &data, TreeItem *parent = 0) : TreeItem(data, parent) { }
|
||||
};
|
||||
|
||||
#endif // TREEITEM_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file treeitem.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowserplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef TREEITEM_H
|
||||
#define TREEITEM_H
|
||||
|
||||
#include "uavobjects/uavobject.h"
|
||||
#include "uavobjects/uavmetaobject.h"
|
||||
#include "uavobjects/uavobjectfield.h"
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtCore/QTimer>
|
||||
#include <QtCore/QObject>
|
||||
|
||||
|
||||
class TreeItem : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TreeItem(const QList<QVariant> &data, TreeItem *parent = 0);
|
||||
TreeItem(const QVariant &data, TreeItem *parent = 0);
|
||||
virtual ~TreeItem();
|
||||
|
||||
void appendChild(TreeItem *child);
|
||||
void insert(int index, TreeItem *child);
|
||||
|
||||
TreeItem *child(int row);
|
||||
inline QList<TreeItem*> treeChildren() const { return m_children; }
|
||||
int childCount() const;
|
||||
int columnCount() const;
|
||||
QVariant data(int column = 1) const;
|
||||
// only column 1 (TreeItem::dataColumn) is changed with setData currently
|
||||
// other columns are initialized in constructor
|
||||
virtual void setData(QVariant value, int column = 1);
|
||||
int row() const;
|
||||
TreeItem *parent() { return m_parent; }
|
||||
void setParentTree(TreeItem *parent) { m_parent = parent; }
|
||||
inline virtual bool isEditable() { return false; }
|
||||
virtual void update();
|
||||
virtual void apply();
|
||||
|
||||
inline bool highlighted() { return m_highlight; }
|
||||
void setHighlight(bool highlight);
|
||||
static void setHighlightTime(int time) { m_highlightTimeMs = time; }
|
||||
|
||||
inline bool changed() { return m_changed; }
|
||||
inline void setChanged(bool changed) { m_changed = changed; }
|
||||
|
||||
signals:
|
||||
void updateHighlight(TreeItem*);
|
||||
|
||||
private slots:
|
||||
void removeHighlight();
|
||||
|
||||
private:
|
||||
QList<TreeItem*> m_children;
|
||||
// m_data contains: [0] property name, [1] value, and [2] unit
|
||||
QList<QVariant> m_data;
|
||||
TreeItem *m_parent;
|
||||
bool m_highlight;
|
||||
bool m_changed;
|
||||
QTimer m_timer;
|
||||
public:
|
||||
static const int dataColumn = 1;
|
||||
private:
|
||||
static int m_highlightTimeMs;
|
||||
};
|
||||
|
||||
class TopTreeItem : public TreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TopTreeItem(const QList<QVariant> &data, TreeItem *parent = 0) : TreeItem(data, parent) { }
|
||||
TopTreeItem(const QVariant &data, TreeItem *parent = 0) : TreeItem(data, parent) { }
|
||||
|
||||
QList<quint32> objIds() { return m_objIds; }
|
||||
void addObjId(quint32 objId) { m_objIds.append(objId); }
|
||||
void insertObjId(int index, quint32 objId) { m_objIds.insert(index, objId); }
|
||||
int nameIndex(QString name) {
|
||||
for (int i = 0; i < childCount(); ++i) {
|
||||
if (name < child(i)->data(0).toString())
|
||||
return i;
|
||||
}
|
||||
return childCount();
|
||||
}
|
||||
|
||||
private:
|
||||
QList<quint32> m_objIds;
|
||||
};
|
||||
|
||||
class ObjectTreeItem : public TreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ObjectTreeItem(const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
TreeItem(data, parent), m_obj(0) { }
|
||||
ObjectTreeItem(const QVariant &data, TreeItem *parent = 0) :
|
||||
TreeItem(data, parent), m_obj(0) { }
|
||||
void setObject(UAVObject *obj) { m_obj = obj; }
|
||||
inline UAVObject *object() { return m_obj; }
|
||||
private:
|
||||
UAVObject *m_obj;
|
||||
};
|
||||
|
||||
class MetaObjectTreeItem : public ObjectTreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MetaObjectTreeItem(UAVObject *obj, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
ObjectTreeItem(data, parent) { setObject(obj); }
|
||||
MetaObjectTreeItem(UAVObject *obj, const QVariant &data, TreeItem *parent = 0) :
|
||||
ObjectTreeItem(data, parent) { setObject(obj); }
|
||||
};
|
||||
|
||||
class DataObjectTreeItem : public ObjectTreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DataObjectTreeItem(const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
ObjectTreeItem(data, parent) { }
|
||||
DataObjectTreeItem(const QVariant &data, TreeItem *parent = 0) :
|
||||
ObjectTreeItem(data, parent) { }
|
||||
virtual void apply() {
|
||||
foreach(TreeItem *child, treeChildren()) {
|
||||
MetaObjectTreeItem *metaChild = dynamic_cast<MetaObjectTreeItem*>(child);
|
||||
if (!metaChild)
|
||||
child->apply();
|
||||
}
|
||||
}
|
||||
virtual void update() {
|
||||
foreach(TreeItem *child, treeChildren()) {
|
||||
MetaObjectTreeItem *metaChild = dynamic_cast<MetaObjectTreeItem*>(child);
|
||||
if (!metaChild)
|
||||
child->update();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class InstanceTreeItem : public DataObjectTreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
InstanceTreeItem(UAVObject *obj, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
DataObjectTreeItem(data, parent) { setObject(obj); }
|
||||
InstanceTreeItem(UAVObject *obj, const QVariant &data, TreeItem *parent = 0) :
|
||||
DataObjectTreeItem(data, parent) { setObject(obj); }
|
||||
virtual void apply() { TreeItem::apply(); }
|
||||
virtual void update() { TreeItem::update(); }
|
||||
};
|
||||
|
||||
class ArrayFieldTreeItem : public TreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ArrayFieldTreeItem(const QList<QVariant> &data, TreeItem *parent = 0) : TreeItem(data, parent) { }
|
||||
ArrayFieldTreeItem(const QVariant &data, TreeItem *parent = 0) : TreeItem(data, parent) { }
|
||||
};
|
||||
|
||||
#endif // TREEITEM_H
|
||||
|
@ -1,49 +1,49 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectbrowser.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowser
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavobjectbrowser.h"
|
||||
#include "uavobjectbrowserwidget.h"
|
||||
#include "uavobjectbrowserconfiguration.h"
|
||||
|
||||
UAVObjectBrowser::UAVObjectBrowser(QString classId, UAVObjectBrowserWidget *widget, QWidget *parent) :
|
||||
IUAVGadget(classId, parent),
|
||||
m_widget(widget)
|
||||
{
|
||||
}
|
||||
|
||||
UAVObjectBrowser::~UAVObjectBrowser()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void UAVObjectBrowser::loadConfiguration(IUAVGadgetConfiguration* config)
|
||||
{
|
||||
UAVObjectBrowserConfiguration *m = qobject_cast<UAVObjectBrowserConfiguration*>(config);
|
||||
m_widget->setRecentlyUpdatedColor(m->recentlyUpdatedColor());
|
||||
m_widget->setManuallyChangedColor(m->manuallyChangedColor());
|
||||
m_widget->setRecentlyUpdatedTimeout(m->recentlyUpdatedTimeout());
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectbrowser.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowserplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavobjectbrowser.h"
|
||||
#include "uavobjectbrowserwidget.h"
|
||||
#include "uavobjectbrowserconfiguration.h"
|
||||
|
||||
UAVObjectBrowser::UAVObjectBrowser(QString classId, UAVObjectBrowserWidget *widget, QWidget *parent) :
|
||||
IUAVGadget(classId, parent),
|
||||
m_widget(widget)
|
||||
{
|
||||
}
|
||||
|
||||
UAVObjectBrowser::~UAVObjectBrowser()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void UAVObjectBrowser::loadConfiguration(IUAVGadgetConfiguration* config)
|
||||
{
|
||||
UAVObjectBrowserConfiguration *m = qobject_cast<UAVObjectBrowserConfiguration*>(config);
|
||||
m_widget->setRecentlyUpdatedColor(m->recentlyUpdatedColor());
|
||||
m_widget->setManuallyChangedColor(m->manuallyChangedColor());
|
||||
m_widget->setRecentlyUpdatedTimeout(m->recentlyUpdatedTimeout());
|
||||
}
|
||||
|
||||
|
@ -1,56 +1,56 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectbrowser.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowser
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UAVOBJECTBROWSER_H_
|
||||
#define UAVOBJECTBROWSER_H_
|
||||
|
||||
#include <coreplugin/iuavgadget.h>
|
||||
#include "uavobjectbrowserwidget.h"
|
||||
|
||||
class IUAVGadget;
|
||||
class QWidget;
|
||||
class QString;
|
||||
class UAVObjectBrowserWidget;
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class UAVObjectBrowser : public Core::IUAVGadget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
UAVObjectBrowser(QString classId, UAVObjectBrowserWidget *widget, QWidget *parent = 0);
|
||||
~UAVObjectBrowser();
|
||||
|
||||
QWidget *widget() { return m_widget; }
|
||||
void loadConfiguration(IUAVGadgetConfiguration* config);
|
||||
|
||||
private:
|
||||
UAVObjectBrowserWidget *m_widget;
|
||||
};
|
||||
|
||||
|
||||
#endif // UAVOBJECTBROWSER_H_
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectbrowser.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowserplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UAVOBJECTBROWSER_H_
|
||||
#define UAVOBJECTBROWSER_H_
|
||||
|
||||
#include <coreplugin/iuavgadget.h>
|
||||
#include "uavobjectbrowserwidget.h"
|
||||
|
||||
class IUAVGadget;
|
||||
class QWidget;
|
||||
class QString;
|
||||
class UAVObjectBrowserWidget;
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class UAVObjectBrowser : public Core::IUAVGadget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
UAVObjectBrowser(QString classId, UAVObjectBrowserWidget *widget, QWidget *parent = 0);
|
||||
~UAVObjectBrowser();
|
||||
|
||||
QWidget *widget() { return m_widget; }
|
||||
void loadConfiguration(IUAVGadgetConfiguration* config);
|
||||
|
||||
private:
|
||||
UAVObjectBrowserWidget *m_widget;
|
||||
};
|
||||
|
||||
|
||||
#endif // UAVOBJECTBROWSER_H_
|
||||
|
@ -1,69 +1,69 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectbrowserconfiguration.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowser
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "uavobjectbrowserconfiguration.h"
|
||||
#include <QtCore/QDataStream>
|
||||
|
||||
UAVObjectBrowserConfiguration::UAVObjectBrowserConfiguration(QString classId, const QByteArray &state, QObject *parent) :
|
||||
IUAVGadgetConfiguration(classId, parent),
|
||||
m_recentlyUpdatedColor(QColor(255, 230, 230)),
|
||||
m_manuallyChangedColor(QColor(230, 230, 255)),
|
||||
m_recentlyUpdatedTimeout(500)
|
||||
{
|
||||
if (state.count() > 0) {
|
||||
QDataStream stream(state);
|
||||
QColor recent;
|
||||
QColor manual;
|
||||
int timeout;
|
||||
stream >> recent;
|
||||
stream >> manual;
|
||||
stream >> timeout;
|
||||
m_recentlyUpdatedColor = recent;
|
||||
m_manuallyChangedColor = manual;
|
||||
m_recentlyUpdatedTimeout = timeout;
|
||||
}
|
||||
}
|
||||
|
||||
IUAVGadgetConfiguration *UAVObjectBrowserConfiguration::clone()
|
||||
{
|
||||
UAVObjectBrowserConfiguration *m = new UAVObjectBrowserConfiguration(this->classId());
|
||||
m->m_recentlyUpdatedColor = m_recentlyUpdatedColor;
|
||||
m->m_manuallyChangedColor = m_manuallyChangedColor;
|
||||
m->m_recentlyUpdatedTimeout = m_recentlyUpdatedTimeout;
|
||||
return m;
|
||||
}
|
||||
|
||||
QByteArray UAVObjectBrowserConfiguration::saveState() const
|
||||
{
|
||||
QByteArray bytes;
|
||||
QDataStream stream(&bytes, QIODevice::WriteOnly);
|
||||
stream << m_recentlyUpdatedColor;
|
||||
stream << m_manuallyChangedColor;
|
||||
stream << m_recentlyUpdatedTimeout;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectbrowserconfiguration.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowserplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "uavobjectbrowserconfiguration.h"
|
||||
#include <QtCore/QDataStream>
|
||||
|
||||
UAVObjectBrowserConfiguration::UAVObjectBrowserConfiguration(QString classId, const QByteArray &state, QObject *parent) :
|
||||
IUAVGadgetConfiguration(classId, parent),
|
||||
m_recentlyUpdatedColor(QColor(255, 230, 230)),
|
||||
m_manuallyChangedColor(QColor(230, 230, 255)),
|
||||
m_recentlyUpdatedTimeout(500)
|
||||
{
|
||||
if (state.count() > 0) {
|
||||
QDataStream stream(state);
|
||||
QColor recent;
|
||||
QColor manual;
|
||||
int timeout;
|
||||
stream >> recent;
|
||||
stream >> manual;
|
||||
stream >> timeout;
|
||||
m_recentlyUpdatedColor = recent;
|
||||
m_manuallyChangedColor = manual;
|
||||
m_recentlyUpdatedTimeout = timeout;
|
||||
}
|
||||
}
|
||||
|
||||
IUAVGadgetConfiguration *UAVObjectBrowserConfiguration::clone()
|
||||
{
|
||||
UAVObjectBrowserConfiguration *m = new UAVObjectBrowserConfiguration(this->classId());
|
||||
m->m_recentlyUpdatedColor = m_recentlyUpdatedColor;
|
||||
m->m_manuallyChangedColor = m_manuallyChangedColor;
|
||||
m->m_recentlyUpdatedTimeout = m_recentlyUpdatedTimeout;
|
||||
return m;
|
||||
}
|
||||
|
||||
QByteArray UAVObjectBrowserConfiguration::saveState() const
|
||||
{
|
||||
QByteArray bytes;
|
||||
QDataStream stream(&bytes, QIODevice::WriteOnly);
|
||||
stream << m_recentlyUpdatedColor;
|
||||
stream << m_manuallyChangedColor;
|
||||
stream << m_recentlyUpdatedTimeout;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
|
@ -1,64 +1,64 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectbrowserconfiguration.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowser
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UAVOBJECTBROWSERCONFIGURATION_H
|
||||
#define UAVOBJECTBROWSERCONFIGURATION_H
|
||||
|
||||
#include <coreplugin/iuavgadgetconfiguration.h>
|
||||
#include <QtGui/QColor>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class UAVObjectBrowserConfiguration : public IUAVGadgetConfiguration
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QColor m_recentlyUpdatedColor READ recentlyUpdatedColor WRITE setRecentlyUpdatedColor)
|
||||
Q_PROPERTY(QColor m_manuallyChangedColor READ manuallyChangedColor WRITE setManuallyChangedColor)
|
||||
Q_PROPERTY(int m_recentlyUpdatedTimeout READ recentlyUpdatedTimeout WRITE setRecentlyUpdatedTimeout)
|
||||
public:
|
||||
explicit UAVObjectBrowserConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0);
|
||||
QByteArray saveState() const;
|
||||
IUAVGadgetConfiguration *clone();
|
||||
|
||||
QColor recentlyUpdatedColor() const { return m_recentlyUpdatedColor; }
|
||||
QColor manuallyChangedColor() const { return m_manuallyChangedColor; }
|
||||
int recentlyUpdatedTimeout() const { return m_recentlyUpdatedTimeout; }
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
void setRecentlyUpdatedColor(QColor color) { m_recentlyUpdatedColor = color; }
|
||||
void setManuallyChangedColor(QColor color) { m_manuallyChangedColor = color; }
|
||||
void setRecentlyUpdatedTimeout(int timeout) { m_recentlyUpdatedTimeout = timeout; }
|
||||
|
||||
private:
|
||||
QColor m_recentlyUpdatedColor;
|
||||
QColor m_manuallyChangedColor;
|
||||
int m_recentlyUpdatedTimeout;
|
||||
};
|
||||
|
||||
#endif // UAVOBJECTBROWSERCONFIGURATION_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectbrowserconfiguration.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowserplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UAVOBJECTBROWSERCONFIGURATION_H
|
||||
#define UAVOBJECTBROWSERCONFIGURATION_H
|
||||
|
||||
#include <coreplugin/iuavgadgetconfiguration.h>
|
||||
#include <QtGui/QColor>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class UAVObjectBrowserConfiguration : public IUAVGadgetConfiguration
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QColor m_recentlyUpdatedColor READ recentlyUpdatedColor WRITE setRecentlyUpdatedColor)
|
||||
Q_PROPERTY(QColor m_manuallyChangedColor READ manuallyChangedColor WRITE setManuallyChangedColor)
|
||||
Q_PROPERTY(int m_recentlyUpdatedTimeout READ recentlyUpdatedTimeout WRITE setRecentlyUpdatedTimeout)
|
||||
public:
|
||||
explicit UAVObjectBrowserConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0);
|
||||
QByteArray saveState() const;
|
||||
IUAVGadgetConfiguration *clone();
|
||||
|
||||
QColor recentlyUpdatedColor() const { return m_recentlyUpdatedColor; }
|
||||
QColor manuallyChangedColor() const { return m_manuallyChangedColor; }
|
||||
int recentlyUpdatedTimeout() const { return m_recentlyUpdatedTimeout; }
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
void setRecentlyUpdatedColor(QColor color) { m_recentlyUpdatedColor = color; }
|
||||
void setManuallyChangedColor(QColor color) { m_manuallyChangedColor = color; }
|
||||
void setRecentlyUpdatedTimeout(int timeout) { m_recentlyUpdatedTimeout = timeout; }
|
||||
|
||||
private:
|
||||
QColor m_recentlyUpdatedColor;
|
||||
QColor m_manuallyChangedColor;
|
||||
int m_recentlyUpdatedTimeout;
|
||||
};
|
||||
|
||||
#endif // UAVOBJECTBROWSERCONFIGURATION_H
|
||||
|
@ -1,58 +1,58 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectbrowserfactory.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowser
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavobjectbrowserfactory.h"
|
||||
#include "uavobjectbrowserwidget.h"
|
||||
#include "uavobjectbrowser.h"
|
||||
#include "uavobjectbrowserconfiguration.h"
|
||||
#include "uavobjectbrowseroptionspage.h"
|
||||
#include <coreplugin/iuavgadget.h>
|
||||
|
||||
UAVObjectBrowserFactory::UAVObjectBrowserFactory(QObject *parent) :
|
||||
IUAVGadgetFactory(QString("UAVObjectBrowser"), tr("UAVObject Browser"), parent)
|
||||
{
|
||||
}
|
||||
|
||||
UAVObjectBrowserFactory::~UAVObjectBrowserFactory()
|
||||
{
|
||||
}
|
||||
|
||||
Core::IUAVGadget* UAVObjectBrowserFactory::createGadget(QWidget *parent)
|
||||
{
|
||||
UAVObjectBrowserWidget* gadgetWidget = new UAVObjectBrowserWidget(parent);
|
||||
return new UAVObjectBrowser(QString("UAVObjectBrowser"), gadgetWidget, parent);
|
||||
}
|
||||
|
||||
IUAVGadgetConfiguration *UAVObjectBrowserFactory::createConfiguration(const QByteArray &state)
|
||||
{
|
||||
return new UAVObjectBrowserConfiguration(QString("UAVObjectBrowser"), state);
|
||||
}
|
||||
|
||||
IOptionsPage *UAVObjectBrowserFactory::createOptionsPage(IUAVGadgetConfiguration *config)
|
||||
{
|
||||
return new UAVObjectBrowserOptionsPage(qobject_cast<UAVObjectBrowserConfiguration*>(config));
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectbrowserfactory.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowserplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavobjectbrowserfactory.h"
|
||||
#include "uavobjectbrowserwidget.h"
|
||||
#include "uavobjectbrowser.h"
|
||||
#include "uavobjectbrowserconfiguration.h"
|
||||
#include "uavobjectbrowseroptionspage.h"
|
||||
#include <coreplugin/iuavgadget.h>
|
||||
|
||||
UAVObjectBrowserFactory::UAVObjectBrowserFactory(QObject *parent) :
|
||||
IUAVGadgetFactory(QString("UAVObjectBrowser"), tr("UAVObject Browser"), parent)
|
||||
{
|
||||
}
|
||||
|
||||
UAVObjectBrowserFactory::~UAVObjectBrowserFactory()
|
||||
{
|
||||
}
|
||||
|
||||
Core::IUAVGadget* UAVObjectBrowserFactory::createGadget(QWidget *parent)
|
||||
{
|
||||
UAVObjectBrowserWidget* gadgetWidget = new UAVObjectBrowserWidget(parent);
|
||||
return new UAVObjectBrowser(QString("UAVObjectBrowser"), gadgetWidget, parent);
|
||||
}
|
||||
|
||||
IUAVGadgetConfiguration *UAVObjectBrowserFactory::createConfiguration(const QByteArray &state)
|
||||
{
|
||||
return new UAVObjectBrowserConfiguration(QString("UAVObjectBrowser"), state);
|
||||
}
|
||||
|
||||
IOptionsPage *UAVObjectBrowserFactory::createOptionsPage(IUAVGadgetConfiguration *config)
|
||||
{
|
||||
return new UAVObjectBrowserOptionsPage(qobject_cast<UAVObjectBrowserConfiguration*>(config));
|
||||
}
|
||||
|
||||
|
@ -1,52 +1,52 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectbrowserfactory.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowser
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UAVOBJECTBROWSERFACTORY_H_
|
||||
#define UAVOBJECTBROWSERFACTORY_H_
|
||||
|
||||
#include <coreplugin/iuavgadgetfactory.h>
|
||||
|
||||
namespace Core {
|
||||
class IUAVGadget;
|
||||
class IUAVGadgetFactory;
|
||||
}
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class UAVObjectBrowserFactory : public Core::IUAVGadgetFactory
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
UAVObjectBrowserFactory(QObject *parent = 0);
|
||||
~UAVObjectBrowserFactory();
|
||||
|
||||
Core::IUAVGadget *createGadget(QWidget *parent);
|
||||
IUAVGadgetConfiguration *createConfiguration(const QByteArray &state);
|
||||
IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config);
|
||||
};
|
||||
|
||||
#endif // UAVOBJECTBROWSERFACTORY_H_
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectbrowserfactory.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowserplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UAVOBJECTBROWSERFACTORY_H_
|
||||
#define UAVOBJECTBROWSERFACTORY_H_
|
||||
|
||||
#include <coreplugin/iuavgadgetfactory.h>
|
||||
|
||||
namespace Core {
|
||||
class IUAVGadget;
|
||||
class IUAVGadgetFactory;
|
||||
}
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class UAVObjectBrowserFactory : public Core::IUAVGadgetFactory
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
UAVObjectBrowserFactory(QObject *parent = 0);
|
||||
~UAVObjectBrowserFactory();
|
||||
|
||||
Core::IUAVGadget *createGadget(QWidget *parent);
|
||||
IUAVGadgetConfiguration *createConfiguration(const QByteArray &state);
|
||||
IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config);
|
||||
};
|
||||
|
||||
#endif // UAVOBJECTBROWSERFACTORY_H_
|
||||
|
@ -1,70 +1,70 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectbrowseroptionspage.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowser
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "uavobjectbrowseroptionspage.h"
|
||||
#include "uavobjectbrowserconfiguration.h"
|
||||
#include <QtGui/QLabel>
|
||||
#include <QtGui/QSpinBox>
|
||||
#include <QtGui/QPushButton>
|
||||
#include <QtGui/QHBoxLayout>
|
||||
#include <QtGui/QVBoxLayout>
|
||||
#include <QtGui/QColorDialog>
|
||||
|
||||
#include "ui_uavobjectbrowseroptionspage.h"
|
||||
|
||||
|
||||
UAVObjectBrowserOptionsPage::UAVObjectBrowserOptionsPage(UAVObjectBrowserConfiguration *config, QObject *parent) :
|
||||
IOptionsPage(parent),
|
||||
m_config(config)
|
||||
{
|
||||
}
|
||||
|
||||
QWidget *UAVObjectBrowserOptionsPage::createPage(QWidget *parent)
|
||||
{
|
||||
m_page = new Ui::UAVObjectBrowserOptionsPage();
|
||||
QWidget *w = new QWidget(parent);
|
||||
m_page->setupUi(w);
|
||||
|
||||
m_page->recentlyUpdatedButton->setColor(m_config->recentlyUpdatedColor());
|
||||
m_page->manuallyChangedButton->setColor(m_config->manuallyChangedColor());
|
||||
m_page->recentlyUpdatedTimeoutSpinBox->setValue(m_config->recentlyUpdatedTimeout());
|
||||
|
||||
return w;
|
||||
|
||||
}
|
||||
|
||||
void UAVObjectBrowserOptionsPage::apply()
|
||||
{
|
||||
m_config->setRecentlyUpdatedColor(m_page->recentlyUpdatedButton->color());
|
||||
m_config->setManuallyChangedColor(m_page->manuallyChangedButton->color());
|
||||
m_config->setRecentlyUpdatedTimeout(m_page->recentlyUpdatedTimeoutSpinBox->value());
|
||||
}
|
||||
|
||||
void UAVObjectBrowserOptionsPage::finish()
|
||||
{
|
||||
delete m_page;
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectbrowseroptionspage.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Options page for the UAVObject Browser Plugin
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowserplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "uavobjectbrowseroptionspage.h"
|
||||
#include "uavobjectbrowserconfiguration.h"
|
||||
#include <QtGui/QLabel>
|
||||
#include <QtGui/QSpinBox>
|
||||
#include <QtGui/QPushButton>
|
||||
#include <QtGui/QHBoxLayout>
|
||||
#include <QtGui/QVBoxLayout>
|
||||
#include <QtGui/QColorDialog>
|
||||
|
||||
#include "ui_uavobjectbrowseroptionspage.h"
|
||||
|
||||
|
||||
UAVObjectBrowserOptionsPage::UAVObjectBrowserOptionsPage(UAVObjectBrowserConfiguration *config, QObject *parent) :
|
||||
IOptionsPage(parent),
|
||||
m_config(config)
|
||||
{
|
||||
}
|
||||
|
||||
QWidget *UAVObjectBrowserOptionsPage::createPage(QWidget *parent)
|
||||
{
|
||||
m_page = new Ui::UAVObjectBrowserOptionsPage();
|
||||
QWidget *w = new QWidget(parent);
|
||||
m_page->setupUi(w);
|
||||
|
||||
m_page->recentlyUpdatedButton->setColor(m_config->recentlyUpdatedColor());
|
||||
m_page->manuallyChangedButton->setColor(m_config->manuallyChangedColor());
|
||||
m_page->recentlyUpdatedTimeoutSpinBox->setValue(m_config->recentlyUpdatedTimeout());
|
||||
|
||||
return w;
|
||||
|
||||
}
|
||||
|
||||
void UAVObjectBrowserOptionsPage::apply()
|
||||
{
|
||||
m_config->setRecentlyUpdatedColor(m_page->recentlyUpdatedButton->color());
|
||||
m_config->setManuallyChangedColor(m_page->manuallyChangedButton->color());
|
||||
m_config->setRecentlyUpdatedTimeout(m_page->recentlyUpdatedTimeoutSpinBox->value());
|
||||
}
|
||||
|
||||
void UAVObjectBrowserOptionsPage::finish()
|
||||
{
|
||||
delete m_page;
|
||||
}
|
||||
|
@ -1,68 +1,68 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectbrowseroptionspage.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowser
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UAVOBJECTBROWSEROPTIONSPAGE_H
|
||||
#define UAVOBJECTBROWSEROPTIONSPAGE_H
|
||||
|
||||
#include "coreplugin/dialogs/ioptionspage.h"
|
||||
#include <QtGui/QColor>
|
||||
#include <utils/qtcolorbutton.h>
|
||||
|
||||
|
||||
namespace Core {
|
||||
class IUAVGadgetConfiguration;
|
||||
}
|
||||
class UAVObjectBrowserConfiguration;
|
||||
class QLabel;
|
||||
class QPushButton;
|
||||
class QSpinBox;
|
||||
|
||||
using namespace Core;
|
||||
|
||||
namespace Ui {
|
||||
class UAVObjectBrowserOptionsPage;
|
||||
}
|
||||
|
||||
class UAVObjectBrowserOptionsPage : public IOptionsPage
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit UAVObjectBrowserOptionsPage(UAVObjectBrowserConfiguration *config, QObject *parent = 0);
|
||||
|
||||
QWidget *createPage(QWidget *parent);
|
||||
void apply();
|
||||
void finish();
|
||||
|
||||
signals:
|
||||
|
||||
private slots:
|
||||
private:
|
||||
UAVObjectBrowserConfiguration *m_config;
|
||||
Ui::UAVObjectBrowserOptionsPage *m_page;
|
||||
};
|
||||
|
||||
#endif // UAVOBJECTBROWSEROPTIONSPAGE_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectbrowseroptionspage.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowserplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UAVOBJECTBROWSEROPTIONSPAGE_H
|
||||
#define UAVOBJECTBROWSEROPTIONSPAGE_H
|
||||
|
||||
#include "coreplugin/dialogs/ioptionspage.h"
|
||||
#include <QtGui/QColor>
|
||||
#include <utils/qtcolorbutton.h>
|
||||
|
||||
|
||||
namespace Core {
|
||||
class IUAVGadgetConfiguration;
|
||||
}
|
||||
class UAVObjectBrowserConfiguration;
|
||||
class QLabel;
|
||||
class QPushButton;
|
||||
class QSpinBox;
|
||||
|
||||
using namespace Core;
|
||||
|
||||
namespace Ui {
|
||||
class UAVObjectBrowserOptionsPage;
|
||||
}
|
||||
|
||||
class UAVObjectBrowserOptionsPage : public IOptionsPage
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit UAVObjectBrowserOptionsPage(UAVObjectBrowserConfiguration *config, QObject *parent = 0);
|
||||
|
||||
QWidget *createPage(QWidget *parent);
|
||||
void apply();
|
||||
void finish();
|
||||
|
||||
signals:
|
||||
|
||||
private slots:
|
||||
private:
|
||||
UAVObjectBrowserConfiguration *m_config;
|
||||
Ui::UAVObjectBrowserOptionsPage *m_page;
|
||||
};
|
||||
|
||||
#endif // UAVOBJECTBROWSEROPTIONSPAGE_H
|
||||
|
@ -1,187 +1,187 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectbrowserwidget.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowser
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavobjectbrowserwidget.h"
|
||||
#include "uavobjecttreemodel.h"
|
||||
#include "browseritemdelegate.h"
|
||||
#include "treeitem.h"
|
||||
#include "ui_uavobjectbrowser.h"
|
||||
#include "uavobjects/uavobjectmanager.h"
|
||||
#include <QStringList>
|
||||
#include <QtGui/QHBoxLayout>
|
||||
#include <QtGui/QVBoxLayout>
|
||||
#include <QtGui/QPushButton>
|
||||
#include <QtGui/QComboBox>
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtGui/QItemEditorFactory>
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
|
||||
UAVObjectBrowserWidget::UAVObjectBrowserWidget(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
m_browser = new Ui_UAVObjectBrowser();
|
||||
m_browser->setupUi(this);
|
||||
m_model = new UAVObjectTreeModel();
|
||||
m_browser->treeView->setModel(m_model);
|
||||
m_browser->treeView->setColumnWidth(0, 300);
|
||||
//m_browser->treeView->expandAll();
|
||||
BrowserItemDelegate *m_delegate = new BrowserItemDelegate();
|
||||
m_browser->treeView->setItemDelegate(m_delegate);
|
||||
m_browser->treeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
|
||||
m_browser->treeView->setSelectionBehavior(QAbstractItemView::SelectItems);
|
||||
showMetaData(m_browser->metaCheckBox->isChecked());
|
||||
connect(m_browser->treeView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged(QModelIndex,QModelIndex)));
|
||||
connect(m_browser->metaCheckBox, SIGNAL(toggled(bool)), this, SLOT(showMetaData(bool)));
|
||||
connect(m_browser->saveSDButton, SIGNAL(clicked()), this, SLOT(saveObject()));
|
||||
connect(m_browser->readSDButton, SIGNAL(clicked()), this, SLOT(loadObject()));
|
||||
connect(m_browser->eraseSDButton, SIGNAL(clicked()), this, SLOT(eraseObject()));
|
||||
connect(m_browser->sendButton, SIGNAL(clicked()), this, SLOT(sendUpdate()));
|
||||
connect(m_browser->requestButton, SIGNAL(clicked()), this, SLOT(requestUpdate()));
|
||||
enableSendRequest(false);
|
||||
}
|
||||
|
||||
UAVObjectBrowserWidget::~UAVObjectBrowserWidget()
|
||||
{
|
||||
delete m_browser;
|
||||
}
|
||||
|
||||
void UAVObjectBrowserWidget::showMetaData(bool show)
|
||||
{
|
||||
int topRowCount = m_model->rowCount(QModelIndex());
|
||||
for (int i = 0; i < topRowCount; ++i) {
|
||||
QModelIndex index = m_model->index(i, 0, QModelIndex());
|
||||
int subRowCount = m_model->rowCount(index);
|
||||
for (int j = 0; j < subRowCount; ++j) {
|
||||
m_browser->treeView->setRowHidden(0, index.child(j,0), !show);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UAVObjectBrowserWidget::sendUpdate()
|
||||
{
|
||||
ObjectTreeItem *objItem = findCurrentObjectTreeItem();
|
||||
Q_ASSERT(objItem);
|
||||
objItem->apply();
|
||||
UAVObject *obj = objItem->object();
|
||||
Q_ASSERT(obj);
|
||||
obj->updated();
|
||||
}
|
||||
|
||||
void UAVObjectBrowserWidget::requestUpdate()
|
||||
{
|
||||
ObjectTreeItem *objItem = findCurrentObjectTreeItem();
|
||||
Q_ASSERT(objItem);
|
||||
UAVObject *obj = objItem->object();
|
||||
Q_ASSERT(obj);
|
||||
obj->requestUpdate();
|
||||
}
|
||||
|
||||
ObjectTreeItem *UAVObjectBrowserWidget::findCurrentObjectTreeItem()
|
||||
{
|
||||
QModelIndex current = m_browser->treeView->currentIndex();
|
||||
TreeItem *item = static_cast<TreeItem*>(current.internalPointer());
|
||||
ObjectTreeItem *objItem = 0;
|
||||
while (item) {
|
||||
objItem = dynamic_cast<ObjectTreeItem*>(item);
|
||||
if (objItem)
|
||||
break;
|
||||
item = item->parent();
|
||||
}
|
||||
return objItem;
|
||||
}
|
||||
|
||||
void UAVObjectBrowserWidget::saveObject()
|
||||
{
|
||||
// Send update so that the latest value is saved
|
||||
sendUpdate();
|
||||
// Save object
|
||||
ObjectTreeItem *objItem = findCurrentObjectTreeItem();
|
||||
Q_ASSERT(objItem);
|
||||
UAVObject *obj = objItem->object();
|
||||
Q_ASSERT(obj);
|
||||
updateObjectPersistance(ObjectPersistence::OPERATION_SAVE, obj);
|
||||
}
|
||||
|
||||
void UAVObjectBrowserWidget::loadObject()
|
||||
{
|
||||
// Load object
|
||||
ObjectTreeItem *objItem = findCurrentObjectTreeItem();
|
||||
Q_ASSERT(objItem);
|
||||
UAVObject *obj = objItem->object();
|
||||
Q_ASSERT(obj);
|
||||
updateObjectPersistance(ObjectPersistence::OPERATION_LOAD, obj);
|
||||
// Retrieve object so that latest value is displayed
|
||||
requestUpdate();
|
||||
}
|
||||
|
||||
void UAVObjectBrowserWidget::eraseObject()
|
||||
{
|
||||
ObjectTreeItem *objItem = findCurrentObjectTreeItem();
|
||||
Q_ASSERT(objItem);
|
||||
UAVObject *obj = objItem->object();
|
||||
Q_ASSERT(obj);
|
||||
updateObjectPersistance(ObjectPersistence::OPERATION_DELETE, obj);
|
||||
}
|
||||
|
||||
void UAVObjectBrowserWidget::updateObjectPersistance(ObjectPersistence::OperationOptions op, UAVObject *obj)
|
||||
{
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
||||
ObjectPersistence* objper = dynamic_cast<ObjectPersistence*>( objManager->getObject(ObjectPersistence::NAME) );
|
||||
if (obj != NULL)
|
||||
{
|
||||
ObjectPersistence::DataFields data;
|
||||
data.Operation = op;
|
||||
data.Selection = ObjectPersistence::SELECTION_SINGLEOBJECT;
|
||||
data.ObjectID = obj->getObjID();
|
||||
data.InstanceID = obj->getInstID();
|
||||
objper->setData(data);
|
||||
objper->updated();
|
||||
}
|
||||
}
|
||||
|
||||
void UAVObjectBrowserWidget::currentChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
||||
{
|
||||
TreeItem *item = static_cast<TreeItem*>(current.internalPointer());
|
||||
bool enable = true;
|
||||
if (current == QModelIndex())
|
||||
enable = false;
|
||||
TopTreeItem *top = dynamic_cast<TopTreeItem*>(item);
|
||||
ObjectTreeItem *data = dynamic_cast<ObjectTreeItem*>(item);
|
||||
if (top || (data && !data->object()))
|
||||
enable = false;
|
||||
enableSendRequest(enable);
|
||||
}
|
||||
|
||||
void UAVObjectBrowserWidget::enableSendRequest(bool enable)
|
||||
{
|
||||
m_browser->sendButton->setEnabled(enable);
|
||||
m_browser->requestButton->setEnabled(enable);
|
||||
m_browser->saveSDButton->setEnabled(enable);
|
||||
m_browser->readSDButton->setEnabled(enable);
|
||||
m_browser->eraseSDButton->setEnabled(enable);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectbrowserwidget.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowserplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavobjectbrowserwidget.h"
|
||||
#include "uavobjecttreemodel.h"
|
||||
#include "browseritemdelegate.h"
|
||||
#include "treeitem.h"
|
||||
#include "ui_uavobjectbrowser.h"
|
||||
#include "uavobjects/uavobjectmanager.h"
|
||||
#include <QStringList>
|
||||
#include <QtGui/QHBoxLayout>
|
||||
#include <QtGui/QVBoxLayout>
|
||||
#include <QtGui/QPushButton>
|
||||
#include <QtGui/QComboBox>
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtGui/QItemEditorFactory>
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
|
||||
UAVObjectBrowserWidget::UAVObjectBrowserWidget(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
m_browser = new Ui_UAVObjectBrowser();
|
||||
m_browser->setupUi(this);
|
||||
m_model = new UAVObjectTreeModel();
|
||||
m_browser->treeView->setModel(m_model);
|
||||
m_browser->treeView->setColumnWidth(0, 300);
|
||||
//m_browser->treeView->expandAll();
|
||||
BrowserItemDelegate *m_delegate = new BrowserItemDelegate();
|
||||
m_browser->treeView->setItemDelegate(m_delegate);
|
||||
m_browser->treeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
|
||||
m_browser->treeView->setSelectionBehavior(QAbstractItemView::SelectItems);
|
||||
showMetaData(m_browser->metaCheckBox->isChecked());
|
||||
connect(m_browser->treeView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged(QModelIndex,QModelIndex)));
|
||||
connect(m_browser->metaCheckBox, SIGNAL(toggled(bool)), this, SLOT(showMetaData(bool)));
|
||||
connect(m_browser->saveSDButton, SIGNAL(clicked()), this, SLOT(saveObject()));
|
||||
connect(m_browser->readSDButton, SIGNAL(clicked()), this, SLOT(loadObject()));
|
||||
connect(m_browser->eraseSDButton, SIGNAL(clicked()), this, SLOT(eraseObject()));
|
||||
connect(m_browser->sendButton, SIGNAL(clicked()), this, SLOT(sendUpdate()));
|
||||
connect(m_browser->requestButton, SIGNAL(clicked()), this, SLOT(requestUpdate()));
|
||||
enableSendRequest(false);
|
||||
}
|
||||
|
||||
UAVObjectBrowserWidget::~UAVObjectBrowserWidget()
|
||||
{
|
||||
delete m_browser;
|
||||
}
|
||||
|
||||
void UAVObjectBrowserWidget::showMetaData(bool show)
|
||||
{
|
||||
int topRowCount = m_model->rowCount(QModelIndex());
|
||||
for (int i = 0; i < topRowCount; ++i) {
|
||||
QModelIndex index = m_model->index(i, 0, QModelIndex());
|
||||
int subRowCount = m_model->rowCount(index);
|
||||
for (int j = 0; j < subRowCount; ++j) {
|
||||
m_browser->treeView->setRowHidden(0, index.child(j,0), !show);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UAVObjectBrowserWidget::sendUpdate()
|
||||
{
|
||||
ObjectTreeItem *objItem = findCurrentObjectTreeItem();
|
||||
Q_ASSERT(objItem);
|
||||
objItem->apply();
|
||||
UAVObject *obj = objItem->object();
|
||||
Q_ASSERT(obj);
|
||||
obj->updated();
|
||||
}
|
||||
|
||||
void UAVObjectBrowserWidget::requestUpdate()
|
||||
{
|
||||
ObjectTreeItem *objItem = findCurrentObjectTreeItem();
|
||||
Q_ASSERT(objItem);
|
||||
UAVObject *obj = objItem->object();
|
||||
Q_ASSERT(obj);
|
||||
obj->requestUpdate();
|
||||
}
|
||||
|
||||
ObjectTreeItem *UAVObjectBrowserWidget::findCurrentObjectTreeItem()
|
||||
{
|
||||
QModelIndex current = m_browser->treeView->currentIndex();
|
||||
TreeItem *item = static_cast<TreeItem*>(current.internalPointer());
|
||||
ObjectTreeItem *objItem = 0;
|
||||
while (item) {
|
||||
objItem = dynamic_cast<ObjectTreeItem*>(item);
|
||||
if (objItem)
|
||||
break;
|
||||
item = item->parent();
|
||||
}
|
||||
return objItem;
|
||||
}
|
||||
|
||||
void UAVObjectBrowserWidget::saveObject()
|
||||
{
|
||||
// Send update so that the latest value is saved
|
||||
sendUpdate();
|
||||
// Save object
|
||||
ObjectTreeItem *objItem = findCurrentObjectTreeItem();
|
||||
Q_ASSERT(objItem);
|
||||
UAVObject *obj = objItem->object();
|
||||
Q_ASSERT(obj);
|
||||
updateObjectPersistance(ObjectPersistence::OPERATION_SAVE, obj);
|
||||
}
|
||||
|
||||
void UAVObjectBrowserWidget::loadObject()
|
||||
{
|
||||
// Load object
|
||||
ObjectTreeItem *objItem = findCurrentObjectTreeItem();
|
||||
Q_ASSERT(objItem);
|
||||
UAVObject *obj = objItem->object();
|
||||
Q_ASSERT(obj);
|
||||
updateObjectPersistance(ObjectPersistence::OPERATION_LOAD, obj);
|
||||
// Retrieve object so that latest value is displayed
|
||||
requestUpdate();
|
||||
}
|
||||
|
||||
void UAVObjectBrowserWidget::eraseObject()
|
||||
{
|
||||
ObjectTreeItem *objItem = findCurrentObjectTreeItem();
|
||||
Q_ASSERT(objItem);
|
||||
UAVObject *obj = objItem->object();
|
||||
Q_ASSERT(obj);
|
||||
updateObjectPersistance(ObjectPersistence::OPERATION_DELETE, obj);
|
||||
}
|
||||
|
||||
void UAVObjectBrowserWidget::updateObjectPersistance(ObjectPersistence::OperationOptions op, UAVObject *obj)
|
||||
{
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
||||
ObjectPersistence* objper = dynamic_cast<ObjectPersistence*>( objManager->getObject(ObjectPersistence::NAME) );
|
||||
if (obj != NULL)
|
||||
{
|
||||
ObjectPersistence::DataFields data;
|
||||
data.Operation = op;
|
||||
data.Selection = ObjectPersistence::SELECTION_SINGLEOBJECT;
|
||||
data.ObjectID = obj->getObjID();
|
||||
data.InstanceID = obj->getInstID();
|
||||
objper->setData(data);
|
||||
objper->updated();
|
||||
}
|
||||
}
|
||||
|
||||
void UAVObjectBrowserWidget::currentChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
||||
{
|
||||
TreeItem *item = static_cast<TreeItem*>(current.internalPointer());
|
||||
bool enable = true;
|
||||
if (current == QModelIndex())
|
||||
enable = false;
|
||||
TopTreeItem *top = dynamic_cast<TopTreeItem*>(item);
|
||||
ObjectTreeItem *data = dynamic_cast<ObjectTreeItem*>(item);
|
||||
if (top || (data && !data->object()))
|
||||
enable = false;
|
||||
enableSendRequest(enable);
|
||||
}
|
||||
|
||||
void UAVObjectBrowserWidget::enableSendRequest(bool enable)
|
||||
{
|
||||
m_browser->sendButton->setEnabled(enable);
|
||||
m_browser->requestButton->setEnabled(enable);
|
||||
m_browser->saveSDButton->setEnabled(enable);
|
||||
m_browser->readSDButton->setEnabled(enable);
|
||||
m_browser->eraseSDButton->setEnabled(enable);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,74 +1,74 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectbrowserwidget.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowser
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UAVOBJECTBROWSERWIDGET_H_
|
||||
#define UAVOBJECTBROWSERWIDGET_H_
|
||||
|
||||
#include <QtGui/QWidget>
|
||||
#include <QtGui/QTreeView>
|
||||
#include "uavobjects/objectpersistence.h"
|
||||
#include "uavobjecttreemodel.h"
|
||||
|
||||
class QPushButton;
|
||||
class ObjectTreeItem;
|
||||
class Ui_UAVObjectBrowser;
|
||||
|
||||
|
||||
class UAVObjectBrowserWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UAVObjectBrowserWidget(QWidget *parent = 0);
|
||||
~UAVObjectBrowserWidget();
|
||||
void setRecentlyUpdatedColor(QColor color) { m_model->setRecentlyUpdatedColor(color); }
|
||||
void setManuallyChangedColor(QColor color) { m_model->setManuallyChangedColor(color); }
|
||||
void setRecentlyUpdatedTimeout(int timeout) { m_model->setRecentlyUpdatedTimeout(timeout); }
|
||||
|
||||
public slots:
|
||||
void showMetaData(bool show);
|
||||
|
||||
private slots:
|
||||
void sendUpdate();
|
||||
void requestUpdate();
|
||||
void saveObject();
|
||||
void loadObject();
|
||||
void eraseObject();
|
||||
void currentChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||
|
||||
private:
|
||||
QPushButton *m_requestUpdate;
|
||||
QPushButton *m_sendUpdate;
|
||||
Ui_UAVObjectBrowser *m_browser;
|
||||
UAVObjectTreeModel *m_model;
|
||||
|
||||
void updateObjectPersistance(ObjectPersistence::OperationOptions op, UAVObject *obj);
|
||||
void enableSendRequest(bool enable);
|
||||
ObjectTreeItem *findCurrentObjectTreeItem();
|
||||
};
|
||||
|
||||
#endif /* UAVOBJECTBROWSERWIDGET_H_ */
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectbrowserwidget.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowserplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UAVOBJECTBROWSERWIDGET_H_
|
||||
#define UAVOBJECTBROWSERWIDGET_H_
|
||||
|
||||
#include <QtGui/QWidget>
|
||||
#include <QtGui/QTreeView>
|
||||
#include "uavobjects/objectpersistence.h"
|
||||
#include "uavobjecttreemodel.h"
|
||||
|
||||
class QPushButton;
|
||||
class ObjectTreeItem;
|
||||
class Ui_UAVObjectBrowser;
|
||||
|
||||
|
||||
class UAVObjectBrowserWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UAVObjectBrowserWidget(QWidget *parent = 0);
|
||||
~UAVObjectBrowserWidget();
|
||||
void setRecentlyUpdatedColor(QColor color) { m_model->setRecentlyUpdatedColor(color); }
|
||||
void setManuallyChangedColor(QColor color) { m_model->setManuallyChangedColor(color); }
|
||||
void setRecentlyUpdatedTimeout(int timeout) { m_model->setRecentlyUpdatedTimeout(timeout); }
|
||||
|
||||
public slots:
|
||||
void showMetaData(bool show);
|
||||
|
||||
private slots:
|
||||
void sendUpdate();
|
||||
void requestUpdate();
|
||||
void saveObject();
|
||||
void loadObject();
|
||||
void eraseObject();
|
||||
void currentChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||
|
||||
private:
|
||||
QPushButton *m_requestUpdate;
|
||||
QPushButton *m_sendUpdate;
|
||||
Ui_UAVObjectBrowser *m_browser;
|
||||
UAVObjectTreeModel *m_model;
|
||||
|
||||
void updateObjectPersistance(ObjectPersistence::OperationOptions op, UAVObject *obj);
|
||||
void enableSendRequest(bool enable);
|
||||
ObjectTreeItem *findCurrentObjectTreeItem();
|
||||
};
|
||||
|
||||
#endif /* UAVOBJECTBROWSERWIDGET_H_ */
|
||||
|
@ -1,411 +1,411 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjecttreemodel.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowser
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "uavobjecttreemodel.h"
|
||||
#include "fieldtreeitem.h"
|
||||
#include "uavobjects/uavobjectmanager.h"
|
||||
#include "uavobjects/uavdataobject.h"
|
||||
#include "uavobjects/uavmetaobject.h"
|
||||
#include "uavobjects/uavobjectfield.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include <QtGui/QColor>
|
||||
//#include <QtGui/QIcon>
|
||||
#include <QtCore/QTimer>
|
||||
#include <QtCore/QSignalMapper>
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
UAVObjectTreeModel::UAVObjectTreeModel(QObject *parent) :
|
||||
QAbstractItemModel(parent),
|
||||
m_recentlyUpdatedTimeout(500), // ms
|
||||
m_recentlyUpdatedColor(QColor(255, 230, 230)),
|
||||
m_manuallyChangedColor(QColor(230, 230, 255))
|
||||
{
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
||||
|
||||
connect(objManager, SIGNAL(newObject(UAVObject*)), this, SLOT(newObject(UAVObject*)));
|
||||
connect(objManager, SIGNAL(newInstance(UAVObject*)), this, SLOT(newObject(UAVObject*)));
|
||||
|
||||
TreeItem::setHighlightTime(m_recentlyUpdatedTimeout);
|
||||
setupModelData(objManager);
|
||||
}
|
||||
|
||||
UAVObjectTreeModel::~UAVObjectTreeModel()
|
||||
{
|
||||
delete m_rootItem;
|
||||
}
|
||||
|
||||
void UAVObjectTreeModel::setupModelData(UAVObjectManager *objManager)
|
||||
{
|
||||
// root
|
||||
QList<QVariant> rootData;
|
||||
rootData << tr("Property") << tr("Value") << tr("Unit");
|
||||
m_rootItem = new TreeItem(rootData);
|
||||
|
||||
m_settingsTree = new TopTreeItem(tr("Settings"), m_rootItem);
|
||||
m_rootItem->appendChild(m_settingsTree);
|
||||
m_nonSettingsTree = new TopTreeItem(tr("Data Objects"), m_rootItem);
|
||||
m_rootItem->appendChild(m_nonSettingsTree);
|
||||
connect(m_settingsTree, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
|
||||
connect(m_nonSettingsTree, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
|
||||
|
||||
QList< QList<UAVDataObject*> > objList = objManager->getDataObjects();
|
||||
foreach (QList<UAVDataObject*> list, objList) {
|
||||
foreach (UAVDataObject* obj, list) {
|
||||
addDataObject(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UAVObjectTreeModel::newObject(UAVObject *obj)
|
||||
{
|
||||
UAVDataObject *dobj = qobject_cast<UAVDataObject*>(obj);
|
||||
if (dobj)
|
||||
addDataObject(dobj);
|
||||
}
|
||||
|
||||
void UAVObjectTreeModel::addDataObject(UAVDataObject *obj)
|
||||
{
|
||||
TopTreeItem *root = obj->isSettings() ? m_settingsTree : m_nonSettingsTree;
|
||||
if (root->objIds().contains(obj->getObjID())) {
|
||||
int index = root->objIds().indexOf(obj->getObjID());
|
||||
addInstance(obj, root->child(index));
|
||||
} else {
|
||||
DataObjectTreeItem *data = new DataObjectTreeItem(obj->getName());
|
||||
connect(data, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
|
||||
int index = root->nameIndex(obj->getName());
|
||||
root->insert(index, data);
|
||||
root->insertObjId(index, obj->getObjID());
|
||||
UAVMetaObject *meta = obj->getMetaObject();
|
||||
addMetaObject(meta, data);
|
||||
addInstance(obj, data);
|
||||
}
|
||||
}
|
||||
|
||||
void UAVObjectTreeModel::addMetaObject(UAVMetaObject *obj, TreeItem *parent)
|
||||
{
|
||||
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(highlightUpdatedObject(UAVObject*)));
|
||||
MetaObjectTreeItem *meta = new MetaObjectTreeItem(obj, tr("Meta Data"));
|
||||
connect(meta, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
|
||||
foreach (UAVObjectField *field, obj->getFields()) {
|
||||
if (field->getNumElements() > 1) {
|
||||
addArrayField(field, meta);
|
||||
} else {
|
||||
addSingleField(0, field, meta);
|
||||
}
|
||||
}
|
||||
parent->appendChild(meta);
|
||||
}
|
||||
|
||||
void UAVObjectTreeModel::addInstance(UAVObject *obj, TreeItem *parent)
|
||||
{
|
||||
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(highlightUpdatedObject(UAVObject*)));
|
||||
TreeItem *item;
|
||||
if (obj->isSingleInstance()) {
|
||||
item = parent;
|
||||
DataObjectTreeItem *p = static_cast<DataObjectTreeItem*>(parent);
|
||||
p->setObject(obj);
|
||||
} else {
|
||||
QString name = tr("Instance") + " " + QString::number(obj->getInstID());
|
||||
item = new InstanceTreeItem(obj, name);
|
||||
connect(item, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
|
||||
parent->appendChild(item);
|
||||
}
|
||||
foreach (UAVObjectField *field, obj->getFields()) {
|
||||
if (field->getNumElements() > 1) {
|
||||
addArrayField(field, item);
|
||||
} else {
|
||||
addSingleField(0, field, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UAVObjectTreeModel::addArrayField(UAVObjectField *field, TreeItem *parent)
|
||||
{
|
||||
TreeItem *item = new ArrayFieldTreeItem(field->getName());
|
||||
connect(item, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
|
||||
for (uint i = 0; i < field->getNumElements(); ++i) {
|
||||
addSingleField(i, field, item);
|
||||
}
|
||||
parent->appendChild(item);
|
||||
}
|
||||
|
||||
void UAVObjectTreeModel::addSingleField(int index, UAVObjectField *field, TreeItem *parent)
|
||||
{
|
||||
QList<QVariant> data;
|
||||
if (field->getNumElements() == 1)
|
||||
data.append(field->getName());
|
||||
else
|
||||
data.append( QString("[%1]").arg((field->getElementNames())[index]) );
|
||||
|
||||
FieldTreeItem *item;
|
||||
UAVObjectField::FieldType type = field->getType();
|
||||
switch (type) {
|
||||
case UAVObjectField::ENUM: {
|
||||
QStringList options = field->getOptions();
|
||||
QVariant value = field->getValue();
|
||||
data.append( options.indexOf(value.toString()) );
|
||||
data.append(field->getUnits());
|
||||
item = new EnumFieldTreeItem(field, index, data);
|
||||
break;
|
||||
}
|
||||
case UAVObjectField::INT8:
|
||||
case UAVObjectField::INT16:
|
||||
case UAVObjectField::INT32:
|
||||
case UAVObjectField::UINT8:
|
||||
case UAVObjectField::UINT16:
|
||||
case UAVObjectField::UINT32:
|
||||
data.append(field->getValue(index));
|
||||
data.append(field->getUnits());
|
||||
item = new IntFieldTreeItem(field, index, data);
|
||||
break;
|
||||
case UAVObjectField::FLOAT32:
|
||||
data.append(field->getValue(index));
|
||||
data.append(field->getUnits());
|
||||
item = new FloatFieldTreeItem(field, index, data);
|
||||
break;
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
connect(item, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
|
||||
parent->appendChild(item);
|
||||
}
|
||||
|
||||
QModelIndex UAVObjectTreeModel::index(int row, int column, const QModelIndex &parent)
|
||||
const
|
||||
{
|
||||
if (!hasIndex(row, column, parent))
|
||||
return QModelIndex();
|
||||
|
||||
TreeItem *parentItem;
|
||||
|
||||
if (!parent.isValid())
|
||||
parentItem = m_rootItem;
|
||||
else
|
||||
parentItem = static_cast<TreeItem*>(parent.internalPointer());
|
||||
|
||||
TreeItem *childItem = parentItem->child(row);
|
||||
if (childItem)
|
||||
return createIndex(row, column, childItem);
|
||||
else
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
QModelIndex UAVObjectTreeModel::index(TreeItem *item)
|
||||
{
|
||||
if (item->parent() == 0)
|
||||
return QModelIndex();
|
||||
|
||||
QModelIndex root = index(item->parent());
|
||||
|
||||
for (int i = 0; i < rowCount(root); ++i) {
|
||||
QModelIndex childIndex = index(i, 0, root);
|
||||
TreeItem *child = static_cast<TreeItem*>(childIndex.internalPointer());
|
||||
if (child == item)
|
||||
return childIndex;
|
||||
}
|
||||
Q_ASSERT(false);
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
QModelIndex UAVObjectTreeModel::parent(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QModelIndex();
|
||||
|
||||
TreeItem *childItem = static_cast<TreeItem*>(index.internalPointer());
|
||||
TreeItem *parentItem = childItem->parent();
|
||||
|
||||
if (parentItem == m_rootItem)
|
||||
return QModelIndex();
|
||||
|
||||
return createIndex(parentItem->row(), 0, parentItem);
|
||||
}
|
||||
|
||||
int UAVObjectTreeModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
TreeItem *parentItem;
|
||||
if (parent.column() > 0)
|
||||
return 0;
|
||||
|
||||
if (!parent.isValid())
|
||||
parentItem = m_rootItem;
|
||||
else
|
||||
parentItem = static_cast<TreeItem*>(parent.internalPointer());
|
||||
|
||||
return parentItem->childCount();
|
||||
}
|
||||
|
||||
int UAVObjectTreeModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return static_cast<TreeItem*>(parent.internalPointer())->columnCount();
|
||||
else
|
||||
return m_rootItem->columnCount();
|
||||
}
|
||||
|
||||
QVariant UAVObjectTreeModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
if (index.column() == TreeItem::dataColumn && role == Qt::EditRole) {
|
||||
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
|
||||
return item->data(index.column());
|
||||
}
|
||||
// if (role == Qt::DecorationRole)
|
||||
// return QIcon(":/core/images/openpilot_logo_128.png");
|
||||
|
||||
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
|
||||
|
||||
if (index.column() == 0 && role == Qt::BackgroundRole) {
|
||||
ObjectTreeItem *objItem = dynamic_cast<ObjectTreeItem*>(item);
|
||||
if (objItem && objItem->highlighted())
|
||||
return QVariant(m_recentlyUpdatedColor);
|
||||
}
|
||||
if (index.column() == TreeItem::dataColumn && role == Qt::BackgroundRole) {
|
||||
FieldTreeItem *fieldItem = dynamic_cast<FieldTreeItem*>(item);
|
||||
if (fieldItem && fieldItem->highlighted())
|
||||
return QVariant(m_recentlyUpdatedColor);
|
||||
if (fieldItem && fieldItem->changed())
|
||||
return QVariant(m_manuallyChangedColor);
|
||||
}
|
||||
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
|
||||
if (index.column() == TreeItem::dataColumn) {
|
||||
EnumFieldTreeItem *fieldItem = dynamic_cast<EnumFieldTreeItem*>(item);
|
||||
if (fieldItem) {
|
||||
int enumIndex = fieldItem->data(index.column()).toInt();
|
||||
return fieldItem->enumOptions(enumIndex);
|
||||
}
|
||||
}
|
||||
|
||||
return item->data(index.column());
|
||||
}
|
||||
|
||||
bool UAVObjectTreeModel::setData(const QModelIndex &index, const QVariant & value, int role)
|
||||
{
|
||||
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
|
||||
item->setData(value, index.column());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Qt::ItemFlags UAVObjectTreeModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return 0;
|
||||
|
||||
if (index.column() == TreeItem::dataColumn) {
|
||||
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
|
||||
if (item->isEditable())
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
|
||||
}
|
||||
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
}
|
||||
|
||||
QVariant UAVObjectTreeModel::headerData(int section, Qt::Orientation orientation,
|
||||
int role) const
|
||||
{
|
||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
|
||||
return m_rootItem->data(section);
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void UAVObjectTreeModel::highlightUpdatedObject(UAVObject *obj)
|
||||
{
|
||||
Q_ASSERT(obj);
|
||||
ObjectTreeItem *item = findObjectTreeItem(obj);
|
||||
Q_ASSERT(item);
|
||||
item->setHighlight(true);
|
||||
item->update();
|
||||
QModelIndex itemIndex = index(item);
|
||||
Q_ASSERT(itemIndex != QModelIndex());
|
||||
emit dataChanged(itemIndex, itemIndex);
|
||||
}
|
||||
|
||||
ObjectTreeItem *UAVObjectTreeModel::findObjectTreeItem(UAVObject *object)
|
||||
{
|
||||
UAVDataObject *dobj = qobject_cast<UAVDataObject*>(object);
|
||||
UAVMetaObject *mobj = qobject_cast<UAVMetaObject*>(object);
|
||||
Q_ASSERT(dobj || mobj);
|
||||
if (dobj) {
|
||||
return findDataObjectTreeItem(dobj);
|
||||
} else {
|
||||
dobj = qobject_cast<UAVDataObject*>(mobj->getParentObject());
|
||||
Q_ASSERT(dobj);
|
||||
ObjectTreeItem *dItem = findDataObjectTreeItem(dobj);
|
||||
Q_ASSERT(dItem);
|
||||
Q_ASSERT(dItem->object());
|
||||
if (!dItem->object()->isSingleInstance())
|
||||
dItem = dynamic_cast<ObjectTreeItem*>(dItem->parent());
|
||||
foreach (TreeItem *child, dItem->treeChildren()) {
|
||||
MetaObjectTreeItem *mItem = dynamic_cast<MetaObjectTreeItem*>(child);
|
||||
if (mItem && mItem->object()) {
|
||||
Q_ASSERT(mItem->object() == mobj);
|
||||
return mItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DataObjectTreeItem *UAVObjectTreeModel::findDataObjectTreeItem(UAVDataObject *object)
|
||||
{
|
||||
Q_ASSERT(object);
|
||||
TopTreeItem *root = object->isSettings() ? m_settingsTree : m_nonSettingsTree;
|
||||
foreach (TreeItem *child, root->treeChildren()) {
|
||||
DataObjectTreeItem *dItem = dynamic_cast<DataObjectTreeItem*>(child);
|
||||
if (dItem && dItem->object() && dItem->object()->isSingleInstance()) {
|
||||
if(dItem->object() == object) {
|
||||
return dItem;
|
||||
}
|
||||
} else {
|
||||
foreach (TreeItem *c, dItem->treeChildren()) {
|
||||
DataObjectTreeItem *d = dynamic_cast<DataObjectTreeItem*>(c);
|
||||
if (d && d->object() == object)
|
||||
return d;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void UAVObjectTreeModel::updateHighlight(TreeItem *item)
|
||||
{
|
||||
QModelIndex itemIndex = index(item);
|
||||
Q_ASSERT(itemIndex != QModelIndex());
|
||||
emit dataChanged(itemIndex, itemIndex.sibling(itemIndex.row(), TreeItem::dataColumn));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjecttreemodel.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowserplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "uavobjecttreemodel.h"
|
||||
#include "fieldtreeitem.h"
|
||||
#include "uavobjects/uavobjectmanager.h"
|
||||
#include "uavobjects/uavdataobject.h"
|
||||
#include "uavobjects/uavmetaobject.h"
|
||||
#include "uavobjects/uavobjectfield.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include <QtGui/QColor>
|
||||
//#include <QtGui/QIcon>
|
||||
#include <QtCore/QTimer>
|
||||
#include <QtCore/QSignalMapper>
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
UAVObjectTreeModel::UAVObjectTreeModel(QObject *parent) :
|
||||
QAbstractItemModel(parent),
|
||||
m_recentlyUpdatedTimeout(500), // ms
|
||||
m_recentlyUpdatedColor(QColor(255, 230, 230)),
|
||||
m_manuallyChangedColor(QColor(230, 230, 255))
|
||||
{
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
||||
|
||||
connect(objManager, SIGNAL(newObject(UAVObject*)), this, SLOT(newObject(UAVObject*)));
|
||||
connect(objManager, SIGNAL(newInstance(UAVObject*)), this, SLOT(newObject(UAVObject*)));
|
||||
|
||||
TreeItem::setHighlightTime(m_recentlyUpdatedTimeout);
|
||||
setupModelData(objManager);
|
||||
}
|
||||
|
||||
UAVObjectTreeModel::~UAVObjectTreeModel()
|
||||
{
|
||||
delete m_rootItem;
|
||||
}
|
||||
|
||||
void UAVObjectTreeModel::setupModelData(UAVObjectManager *objManager)
|
||||
{
|
||||
// root
|
||||
QList<QVariant> rootData;
|
||||
rootData << tr("Property") << tr("Value") << tr("Unit");
|
||||
m_rootItem = new TreeItem(rootData);
|
||||
|
||||
m_settingsTree = new TopTreeItem(tr("Settings"), m_rootItem);
|
||||
m_rootItem->appendChild(m_settingsTree);
|
||||
m_nonSettingsTree = new TopTreeItem(tr("Data Objects"), m_rootItem);
|
||||
m_rootItem->appendChild(m_nonSettingsTree);
|
||||
connect(m_settingsTree, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
|
||||
connect(m_nonSettingsTree, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
|
||||
|
||||
QList< QList<UAVDataObject*> > objList = objManager->getDataObjects();
|
||||
foreach (QList<UAVDataObject*> list, objList) {
|
||||
foreach (UAVDataObject* obj, list) {
|
||||
addDataObject(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UAVObjectTreeModel::newObject(UAVObject *obj)
|
||||
{
|
||||
UAVDataObject *dobj = qobject_cast<UAVDataObject*>(obj);
|
||||
if (dobj)
|
||||
addDataObject(dobj);
|
||||
}
|
||||
|
||||
void UAVObjectTreeModel::addDataObject(UAVDataObject *obj)
|
||||
{
|
||||
TopTreeItem *root = obj->isSettings() ? m_settingsTree : m_nonSettingsTree;
|
||||
if (root->objIds().contains(obj->getObjID())) {
|
||||
int index = root->objIds().indexOf(obj->getObjID());
|
||||
addInstance(obj, root->child(index));
|
||||
} else {
|
||||
DataObjectTreeItem *data = new DataObjectTreeItem(obj->getName());
|
||||
connect(data, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
|
||||
int index = root->nameIndex(obj->getName());
|
||||
root->insert(index, data);
|
||||
root->insertObjId(index, obj->getObjID());
|
||||
UAVMetaObject *meta = obj->getMetaObject();
|
||||
addMetaObject(meta, data);
|
||||
addInstance(obj, data);
|
||||
}
|
||||
}
|
||||
|
||||
void UAVObjectTreeModel::addMetaObject(UAVMetaObject *obj, TreeItem *parent)
|
||||
{
|
||||
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(highlightUpdatedObject(UAVObject*)));
|
||||
MetaObjectTreeItem *meta = new MetaObjectTreeItem(obj, tr("Meta Data"));
|
||||
connect(meta, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
|
||||
foreach (UAVObjectField *field, obj->getFields()) {
|
||||
if (field->getNumElements() > 1) {
|
||||
addArrayField(field, meta);
|
||||
} else {
|
||||
addSingleField(0, field, meta);
|
||||
}
|
||||
}
|
||||
parent->appendChild(meta);
|
||||
}
|
||||
|
||||
void UAVObjectTreeModel::addInstance(UAVObject *obj, TreeItem *parent)
|
||||
{
|
||||
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(highlightUpdatedObject(UAVObject*)));
|
||||
TreeItem *item;
|
||||
if (obj->isSingleInstance()) {
|
||||
item = parent;
|
||||
DataObjectTreeItem *p = static_cast<DataObjectTreeItem*>(parent);
|
||||
p->setObject(obj);
|
||||
} else {
|
||||
QString name = tr("Instance") + " " + QString::number(obj->getInstID());
|
||||
item = new InstanceTreeItem(obj, name);
|
||||
connect(item, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
|
||||
parent->appendChild(item);
|
||||
}
|
||||
foreach (UAVObjectField *field, obj->getFields()) {
|
||||
if (field->getNumElements() > 1) {
|
||||
addArrayField(field, item);
|
||||
} else {
|
||||
addSingleField(0, field, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UAVObjectTreeModel::addArrayField(UAVObjectField *field, TreeItem *parent)
|
||||
{
|
||||
TreeItem *item = new ArrayFieldTreeItem(field->getName());
|
||||
connect(item, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
|
||||
for (uint i = 0; i < field->getNumElements(); ++i) {
|
||||
addSingleField(i, field, item);
|
||||
}
|
||||
parent->appendChild(item);
|
||||
}
|
||||
|
||||
void UAVObjectTreeModel::addSingleField(int index, UAVObjectField *field, TreeItem *parent)
|
||||
{
|
||||
QList<QVariant> data;
|
||||
if (field->getNumElements() == 1)
|
||||
data.append(field->getName());
|
||||
else
|
||||
data.append( QString("[%1]").arg((field->getElementNames())[index]) );
|
||||
|
||||
FieldTreeItem *item;
|
||||
UAVObjectField::FieldType type = field->getType();
|
||||
switch (type) {
|
||||
case UAVObjectField::ENUM: {
|
||||
QStringList options = field->getOptions();
|
||||
QVariant value = field->getValue();
|
||||
data.append( options.indexOf(value.toString()) );
|
||||
data.append(field->getUnits());
|
||||
item = new EnumFieldTreeItem(field, index, data);
|
||||
break;
|
||||
}
|
||||
case UAVObjectField::INT8:
|
||||
case UAVObjectField::INT16:
|
||||
case UAVObjectField::INT32:
|
||||
case UAVObjectField::UINT8:
|
||||
case UAVObjectField::UINT16:
|
||||
case UAVObjectField::UINT32:
|
||||
data.append(field->getValue(index));
|
||||
data.append(field->getUnits());
|
||||
item = new IntFieldTreeItem(field, index, data);
|
||||
break;
|
||||
case UAVObjectField::FLOAT32:
|
||||
data.append(field->getValue(index));
|
||||
data.append(field->getUnits());
|
||||
item = new FloatFieldTreeItem(field, index, data);
|
||||
break;
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
connect(item, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
|
||||
parent->appendChild(item);
|
||||
}
|
||||
|
||||
QModelIndex UAVObjectTreeModel::index(int row, int column, const QModelIndex &parent)
|
||||
const
|
||||
{
|
||||
if (!hasIndex(row, column, parent))
|
||||
return QModelIndex();
|
||||
|
||||
TreeItem *parentItem;
|
||||
|
||||
if (!parent.isValid())
|
||||
parentItem = m_rootItem;
|
||||
else
|
||||
parentItem = static_cast<TreeItem*>(parent.internalPointer());
|
||||
|
||||
TreeItem *childItem = parentItem->child(row);
|
||||
if (childItem)
|
||||
return createIndex(row, column, childItem);
|
||||
else
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
QModelIndex UAVObjectTreeModel::index(TreeItem *item)
|
||||
{
|
||||
if (item->parent() == 0)
|
||||
return QModelIndex();
|
||||
|
||||
QModelIndex root = index(item->parent());
|
||||
|
||||
for (int i = 0; i < rowCount(root); ++i) {
|
||||
QModelIndex childIndex = index(i, 0, root);
|
||||
TreeItem *child = static_cast<TreeItem*>(childIndex.internalPointer());
|
||||
if (child == item)
|
||||
return childIndex;
|
||||
}
|
||||
Q_ASSERT(false);
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
QModelIndex UAVObjectTreeModel::parent(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QModelIndex();
|
||||
|
||||
TreeItem *childItem = static_cast<TreeItem*>(index.internalPointer());
|
||||
TreeItem *parentItem = childItem->parent();
|
||||
|
||||
if (parentItem == m_rootItem)
|
||||
return QModelIndex();
|
||||
|
||||
return createIndex(parentItem->row(), 0, parentItem);
|
||||
}
|
||||
|
||||
int UAVObjectTreeModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
TreeItem *parentItem;
|
||||
if (parent.column() > 0)
|
||||
return 0;
|
||||
|
||||
if (!parent.isValid())
|
||||
parentItem = m_rootItem;
|
||||
else
|
||||
parentItem = static_cast<TreeItem*>(parent.internalPointer());
|
||||
|
||||
return parentItem->childCount();
|
||||
}
|
||||
|
||||
int UAVObjectTreeModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return static_cast<TreeItem*>(parent.internalPointer())->columnCount();
|
||||
else
|
||||
return m_rootItem->columnCount();
|
||||
}
|
||||
|
||||
QVariant UAVObjectTreeModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
if (index.column() == TreeItem::dataColumn && role == Qt::EditRole) {
|
||||
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
|
||||
return item->data(index.column());
|
||||
}
|
||||
// if (role == Qt::DecorationRole)
|
||||
// return QIcon(":/core/images/openpilot_logo_128.png");
|
||||
|
||||
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
|
||||
|
||||
if (index.column() == 0 && role == Qt::BackgroundRole) {
|
||||
ObjectTreeItem *objItem = dynamic_cast<ObjectTreeItem*>(item);
|
||||
if (objItem && objItem->highlighted())
|
||||
return QVariant(m_recentlyUpdatedColor);
|
||||
}
|
||||
if (index.column() == TreeItem::dataColumn && role == Qt::BackgroundRole) {
|
||||
FieldTreeItem *fieldItem = dynamic_cast<FieldTreeItem*>(item);
|
||||
if (fieldItem && fieldItem->highlighted())
|
||||
return QVariant(m_recentlyUpdatedColor);
|
||||
if (fieldItem && fieldItem->changed())
|
||||
return QVariant(m_manuallyChangedColor);
|
||||
}
|
||||
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
|
||||
if (index.column() == TreeItem::dataColumn) {
|
||||
EnumFieldTreeItem *fieldItem = dynamic_cast<EnumFieldTreeItem*>(item);
|
||||
if (fieldItem) {
|
||||
int enumIndex = fieldItem->data(index.column()).toInt();
|
||||
return fieldItem->enumOptions(enumIndex);
|
||||
}
|
||||
}
|
||||
|
||||
return item->data(index.column());
|
||||
}
|
||||
|
||||
bool UAVObjectTreeModel::setData(const QModelIndex &index, const QVariant & value, int role)
|
||||
{
|
||||
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
|
||||
item->setData(value, index.column());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Qt::ItemFlags UAVObjectTreeModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return 0;
|
||||
|
||||
if (index.column() == TreeItem::dataColumn) {
|
||||
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
|
||||
if (item->isEditable())
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
|
||||
}
|
||||
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
}
|
||||
|
||||
QVariant UAVObjectTreeModel::headerData(int section, Qt::Orientation orientation,
|
||||
int role) const
|
||||
{
|
||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
|
||||
return m_rootItem->data(section);
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void UAVObjectTreeModel::highlightUpdatedObject(UAVObject *obj)
|
||||
{
|
||||
Q_ASSERT(obj);
|
||||
ObjectTreeItem *item = findObjectTreeItem(obj);
|
||||
Q_ASSERT(item);
|
||||
item->setHighlight(true);
|
||||
item->update();
|
||||
QModelIndex itemIndex = index(item);
|
||||
Q_ASSERT(itemIndex != QModelIndex());
|
||||
emit dataChanged(itemIndex, itemIndex);
|
||||
}
|
||||
|
||||
ObjectTreeItem *UAVObjectTreeModel::findObjectTreeItem(UAVObject *object)
|
||||
{
|
||||
UAVDataObject *dobj = qobject_cast<UAVDataObject*>(object);
|
||||
UAVMetaObject *mobj = qobject_cast<UAVMetaObject*>(object);
|
||||
Q_ASSERT(dobj || mobj);
|
||||
if (dobj) {
|
||||
return findDataObjectTreeItem(dobj);
|
||||
} else {
|
||||
dobj = qobject_cast<UAVDataObject*>(mobj->getParentObject());
|
||||
Q_ASSERT(dobj);
|
||||
ObjectTreeItem *dItem = findDataObjectTreeItem(dobj);
|
||||
Q_ASSERT(dItem);
|
||||
Q_ASSERT(dItem->object());
|
||||
if (!dItem->object()->isSingleInstance())
|
||||
dItem = dynamic_cast<ObjectTreeItem*>(dItem->parent());
|
||||
foreach (TreeItem *child, dItem->treeChildren()) {
|
||||
MetaObjectTreeItem *mItem = dynamic_cast<MetaObjectTreeItem*>(child);
|
||||
if (mItem && mItem->object()) {
|
||||
Q_ASSERT(mItem->object() == mobj);
|
||||
return mItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DataObjectTreeItem *UAVObjectTreeModel::findDataObjectTreeItem(UAVDataObject *object)
|
||||
{
|
||||
Q_ASSERT(object);
|
||||
TopTreeItem *root = object->isSettings() ? m_settingsTree : m_nonSettingsTree;
|
||||
foreach (TreeItem *child, root->treeChildren()) {
|
||||
DataObjectTreeItem *dItem = dynamic_cast<DataObjectTreeItem*>(child);
|
||||
if (dItem && dItem->object() && dItem->object()->isSingleInstance()) {
|
||||
if(dItem->object() == object) {
|
||||
return dItem;
|
||||
}
|
||||
} else {
|
||||
foreach (TreeItem *c, dItem->treeChildren()) {
|
||||
DataObjectTreeItem *d = dynamic_cast<DataObjectTreeItem*>(c);
|
||||
if (d && d->object() == object)
|
||||
return d;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void UAVObjectTreeModel::updateHighlight(TreeItem *item)
|
||||
{
|
||||
QModelIndex itemIndex = index(item);
|
||||
Q_ASSERT(itemIndex != QModelIndex());
|
||||
emit dataChanged(itemIndex, itemIndex.sibling(itemIndex.row(), TreeItem::dataColumn));
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,102 +1,102 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjecttreemodel.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowser
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UAVOBJECTTREEMODEL_H
|
||||
#define UAVOBJECTTREEMODEL_H
|
||||
|
||||
#include "treeitem.h"
|
||||
#include <QAbstractItemModel>
|
||||
#include <QtCore/QMap>
|
||||
#include <QtGui/QColor>
|
||||
|
||||
class TopTreeItem;
|
||||
class ObjectTreeItem;
|
||||
class DataObjectTreeItem;
|
||||
class UAVObject;
|
||||
class UAVDataObject;
|
||||
class UAVMetaObject;
|
||||
class UAVObjectField;
|
||||
class UAVObjectManager;
|
||||
class QSignalMapper;
|
||||
class QTimer;
|
||||
|
||||
class UAVObjectTreeModel : public QAbstractItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit UAVObjectTreeModel(QObject *parent = 0);
|
||||
~UAVObjectTreeModel();
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
bool setData(const QModelIndex &index, const QVariant & value, int role);
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const;
|
||||
QModelIndex index(int row, int column,
|
||||
const QModelIndex &parent = QModelIndex()) const;
|
||||
QModelIndex parent(const QModelIndex &index) const;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
|
||||
void setRecentlyUpdatedColor(QColor color) { m_recentlyUpdatedColor = color; }
|
||||
void setManuallyChangedColor(QColor color) { m_manuallyChangedColor = color; }
|
||||
void setRecentlyUpdatedTimeout(int timeout) {
|
||||
m_recentlyUpdatedTimeout = timeout;
|
||||
TreeItem::setHighlightTime(timeout);
|
||||
}
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
void newObject(UAVObject *obj);
|
||||
|
||||
private slots:
|
||||
void highlightUpdatedObject(UAVObject *obj);
|
||||
void updateHighlight(TreeItem*);
|
||||
|
||||
private:
|
||||
QModelIndex index(TreeItem *item);
|
||||
void addDataObject(UAVDataObject *obj);
|
||||
void addMetaObject(UAVMetaObject *obj, TreeItem *parent);
|
||||
void addArrayField(UAVObjectField *field, TreeItem *parent);
|
||||
|
||||
void addSingleField(int index, UAVObjectField *field, TreeItem *parent);
|
||||
void addInstance(UAVObject *obj, TreeItem *parent);
|
||||
QString updateMode(quint8 updateMode);
|
||||
void setupModelData(UAVObjectManager *objManager);
|
||||
ObjectTreeItem *findObjectTreeItem(UAVObject *obj);
|
||||
DataObjectTreeItem *findDataObjectTreeItem(UAVDataObject *obj);
|
||||
|
||||
TreeItem *m_rootItem;
|
||||
TopTreeItem *m_settingsTree;
|
||||
TopTreeItem *m_nonSettingsTree;
|
||||
int m_recentlyUpdatedTimeout;
|
||||
QColor m_recentlyUpdatedColor;
|
||||
QColor m_manuallyChangedColor;
|
||||
};
|
||||
|
||||
#endif // UAVOBJECTTREEMODEL_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjecttreemodel.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectbrowserplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UAVOBJECTTREEMODEL_H
|
||||
#define UAVOBJECTTREEMODEL_H
|
||||
|
||||
#include "treeitem.h"
|
||||
#include <QAbstractItemModel>
|
||||
#include <QtCore/QMap>
|
||||
#include <QtGui/QColor>
|
||||
|
||||
class TopTreeItem;
|
||||
class ObjectTreeItem;
|
||||
class DataObjectTreeItem;
|
||||
class UAVObject;
|
||||
class UAVDataObject;
|
||||
class UAVMetaObject;
|
||||
class UAVObjectField;
|
||||
class UAVObjectManager;
|
||||
class QSignalMapper;
|
||||
class QTimer;
|
||||
|
||||
class UAVObjectTreeModel : public QAbstractItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit UAVObjectTreeModel(QObject *parent = 0);
|
||||
~UAVObjectTreeModel();
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
bool setData(const QModelIndex &index, const QVariant & value, int role);
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const;
|
||||
QModelIndex index(int row, int column,
|
||||
const QModelIndex &parent = QModelIndex()) const;
|
||||
QModelIndex parent(const QModelIndex &index) const;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
|
||||
void setRecentlyUpdatedColor(QColor color) { m_recentlyUpdatedColor = color; }
|
||||
void setManuallyChangedColor(QColor color) { m_manuallyChangedColor = color; }
|
||||
void setRecentlyUpdatedTimeout(int timeout) {
|
||||
m_recentlyUpdatedTimeout = timeout;
|
||||
TreeItem::setHighlightTime(timeout);
|
||||
}
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
void newObject(UAVObject *obj);
|
||||
|
||||
private slots:
|
||||
void highlightUpdatedObject(UAVObject *obj);
|
||||
void updateHighlight(TreeItem*);
|
||||
|
||||
private:
|
||||
QModelIndex index(TreeItem *item);
|
||||
void addDataObject(UAVDataObject *obj);
|
||||
void addMetaObject(UAVMetaObject *obj, TreeItem *parent);
|
||||
void addArrayField(UAVObjectField *field, TreeItem *parent);
|
||||
|
||||
void addSingleField(int index, UAVObjectField *field, TreeItem *parent);
|
||||
void addInstance(UAVObject *obj, TreeItem *parent);
|
||||
QString updateMode(quint8 updateMode);
|
||||
void setupModelData(UAVObjectManager *objManager);
|
||||
ObjectTreeItem *findObjectTreeItem(UAVObject *obj);
|
||||
DataObjectTreeItem *findDataObjectTreeItem(UAVDataObject *obj);
|
||||
|
||||
TreeItem *m_rootItem;
|
||||
TopTreeItem *m_settingsTree;
|
||||
TopTreeItem *m_nonSettingsTree;
|
||||
int m_recentlyUpdatedTimeout;
|
||||
QColor m_recentlyUpdatedColor;
|
||||
QColor m_manuallyChangedColor;
|
||||
};
|
||||
|
||||
#endif // UAVOBJECTTREEMODEL_H
|
||||
|
@ -1,4 +1,4 @@
|
||||
<plugin name="UAVObjects" version="0.0.1" compatVersion="0.0.1">
|
||||
<plugin name="UAVObjects" version="1.0.0" compatVersion="1.0.0">
|
||||
<vendor>The OpenPilot Project</vendor>
|
||||
<copyright>(C) 2010 OpenPilot Project</copyright>
|
||||
<license>The GNU Public License (GPL) Version 3</license>
|
||||
|
@ -1,100 +1,99 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavdataobject.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavdataobject.h"
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
UAVDataObject::UAVDataObject(quint32 objID, bool isSingleInst, bool isSet,const QString& name):
|
||||
UAVObject(objID, isSingleInst, name)
|
||||
{
|
||||
mobj = NULL;
|
||||
this->isSet = isSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize instance ID and assign a metaobject
|
||||
*/
|
||||
void UAVDataObject::initialize(quint32 instID, UAVMetaObject* mobj)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
this->mobj = mobj;
|
||||
UAVObject::initialize(instID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign a metaobject
|
||||
*/
|
||||
void UAVDataObject::initialize(UAVMetaObject* mobj)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
this->mobj = mobj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this is a data object holding module settings
|
||||
*/
|
||||
bool UAVDataObject::isSettings()
|
||||
{
|
||||
return isSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the object's metadata
|
||||
*/
|
||||
void UAVDataObject::setMetadata(const Metadata& mdata)
|
||||
{
|
||||
if ( mobj!=NULL )
|
||||
{
|
||||
mobj->setData(mdata);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the object's metadata
|
||||
*/
|
||||
UAVObject::Metadata UAVDataObject::getMetadata(void)
|
||||
{
|
||||
if ( mobj!=NULL)
|
||||
{
|
||||
return mobj->getData();
|
||||
}
|
||||
else
|
||||
{
|
||||
return getDefaultMetadata();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the metaobject
|
||||
*/
|
||||
UAVMetaObject* UAVDataObject::getMetaObject()
|
||||
{
|
||||
return mobj;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavdataobject.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectsplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavdataobject.h"
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
UAVDataObject::UAVDataObject(quint32 objID, bool isSingleInst, bool isSet,const QString& name):
|
||||
UAVObject(objID, isSingleInst, name)
|
||||
{
|
||||
mobj = NULL;
|
||||
this->isSet = isSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize instance ID and assign a metaobject
|
||||
*/
|
||||
void UAVDataObject::initialize(quint32 instID, UAVMetaObject* mobj)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
this->mobj = mobj;
|
||||
UAVObject::initialize(instID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign a metaobject
|
||||
*/
|
||||
void UAVDataObject::initialize(UAVMetaObject* mobj)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
this->mobj = mobj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this is a data object holding module settings
|
||||
*/
|
||||
bool UAVDataObject::isSettings()
|
||||
{
|
||||
return isSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the object's metadata
|
||||
*/
|
||||
void UAVDataObject::setMetadata(const Metadata& mdata)
|
||||
{
|
||||
if ( mobj!=NULL )
|
||||
{
|
||||
mobj->setData(mdata);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the object's metadata
|
||||
*/
|
||||
UAVObject::Metadata UAVDataObject::getMetadata(void)
|
||||
{
|
||||
if ( mobj!=NULL)
|
||||
{
|
||||
return mobj->getData();
|
||||
}
|
||||
else
|
||||
{
|
||||
return getDefaultMetadata();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the metaobject
|
||||
*/
|
||||
UAVMetaObject* UAVDataObject::getMetaObject()
|
||||
{
|
||||
return mobj;
|
||||
}
|
||||
|
||||
|
@ -1,57 +1,56 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavdataobject.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef UAVDATAOBJECT_H
|
||||
#define UAVDATAOBJECT_H
|
||||
|
||||
#include "uavobjects_global.h"
|
||||
#include "uavobject.h"
|
||||
#include "uavobjectfield.h"
|
||||
#include "uavmetaobject.h"
|
||||
#include <QList>
|
||||
|
||||
class UAVOBJECTS_EXPORT UAVDataObject: public UAVObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UAVDataObject(quint32 objID, bool isSingleInst, bool isSet, const QString& name);
|
||||
void initialize(quint32 instID, UAVMetaObject* mobj);
|
||||
void initialize(UAVMetaObject* mobj);
|
||||
bool isSettings();
|
||||
void setMetadata(const Metadata& mdata);
|
||||
Metadata getMetadata();
|
||||
UAVMetaObject* getMetaObject();
|
||||
virtual UAVDataObject* clone(quint32 instID = 0) = 0;
|
||||
|
||||
private:
|
||||
UAVMetaObject* mobj;
|
||||
bool isSet;
|
||||
|
||||
};
|
||||
|
||||
#endif // UAVDATAOBJECT_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavdataobject.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectsplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef UAVDATAOBJECT_H
|
||||
#define UAVDATAOBJECT_H
|
||||
|
||||
#include "uavobjects_global.h"
|
||||
#include "uavobject.h"
|
||||
#include "uavobjectfield.h"
|
||||
#include "uavmetaobject.h"
|
||||
#include <QList>
|
||||
|
||||
class UAVOBJECTS_EXPORT UAVDataObject: public UAVObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UAVDataObject(quint32 objID, bool isSingleInst, bool isSet, const QString& name);
|
||||
void initialize(quint32 instID, UAVMetaObject* mobj);
|
||||
void initialize(UAVMetaObject* mobj);
|
||||
bool isSettings();
|
||||
void setMetadata(const Metadata& mdata);
|
||||
Metadata getMetadata();
|
||||
UAVMetaObject* getMetaObject();
|
||||
virtual UAVDataObject* clone(quint32 instID = 0) = 0;
|
||||
|
||||
private:
|
||||
UAVMetaObject* mobj;
|
||||
bool isSet;
|
||||
|
||||
};
|
||||
|
||||
#endif // UAVDATAOBJECT_H
|
||||
|
@ -1,127 +1,126 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavmetaobject.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavmetaobject.h"
|
||||
#include "uavobjectfield.h"
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
UAVMetaObject::UAVMetaObject(quint32 objID, const QString& name, UAVObject* parent):
|
||||
UAVObject(objID, true, name)
|
||||
{
|
||||
this->parent = parent;
|
||||
// Setup default metadata of metaobject (can not be changed)
|
||||
ownMetadata.flightAccess = ACCESS_READWRITE;
|
||||
ownMetadata.gcsAccess = ACCESS_READWRITE;
|
||||
ownMetadata.flightTelemetryAcked = 1;
|
||||
ownMetadata.flightTelemetryUpdateMode = UPDATEMODE_ONCHANGE;
|
||||
ownMetadata.flightTelemetryUpdatePeriod = 0;
|
||||
ownMetadata.gcsTelemetryAcked = 1;
|
||||
ownMetadata.gcsTelemetryUpdateMode = UPDATEMODE_ONCHANGE;
|
||||
ownMetadata.gcsTelemetryUpdatePeriod = 0;
|
||||
ownMetadata.loggingUpdateMode = UPDATEMODE_ONCHANGE;
|
||||
ownMetadata.loggingUpdatePeriod = 0;
|
||||
// Setup fields
|
||||
QStringList boolEnum;
|
||||
boolEnum << tr("False") << tr("True");
|
||||
QStringList updateModeEnum;
|
||||
updateModeEnum << tr("Periodic") << tr("On Change") << tr("Manual") << tr("Never");
|
||||
QStringList accessModeEnum;
|
||||
accessModeEnum << tr("Read/Write") << tr("Read Only");
|
||||
QList<UAVObjectField*> fields;
|
||||
fields.append( new UAVObjectField(tr("Flight Access Mode"), tr(""), UAVObjectField::ENUM, 1, accessModeEnum) );
|
||||
fields.append( new UAVObjectField(tr("GCS Access Mode"), tr(""), UAVObjectField::ENUM, 1, accessModeEnum) );
|
||||
fields.append( new UAVObjectField(tr("Flight Telemetry Acked"), tr(""), UAVObjectField::ENUM, 1, boolEnum) );
|
||||
fields.append( new UAVObjectField(tr("Flight Telemetry Update Mode"), tr(""), UAVObjectField::ENUM, 1, updateModeEnum) );
|
||||
fields.append( new UAVObjectField(tr("Flight Telemetry Update Period"), tr(""), UAVObjectField::UINT32, 1, QStringList()) );
|
||||
fields.append( new UAVObjectField(tr("GCS Telemetry Acked"), tr(""), UAVObjectField::ENUM, 1, boolEnum) );
|
||||
fields.append( new UAVObjectField(tr("GCS Telemetry Update Mode"), tr(""), UAVObjectField::ENUM, 1, updateModeEnum) );
|
||||
fields.append( new UAVObjectField(tr("GCS Telemetry Update Period"), tr(""), UAVObjectField::UINT32, 1, QStringList()) );
|
||||
fields.append( new UAVObjectField(tr("Logging Update Mode"), tr(""), UAVObjectField::ENUM, 1, updateModeEnum) );
|
||||
fields.append( new UAVObjectField(tr("Logging Update Period"), tr(""), UAVObjectField::UINT32, 1, QStringList()) );
|
||||
// Initialize parent
|
||||
UAVObject::initialize(0);
|
||||
UAVObject::initializeFields(fields, (quint8*)&parentMetadata, sizeof(Metadata));
|
||||
// Setup metadata of parent
|
||||
parentMetadata = parent->getDefaultMetadata();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the parent object
|
||||
*/
|
||||
UAVObject* UAVMetaObject::getParentObject()
|
||||
{
|
||||
return parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the metadata of the metaobject, this function will
|
||||
* do nothing since metaobjects have read-only metadata.
|
||||
*/
|
||||
void UAVMetaObject::setMetadata(const Metadata& mdata)
|
||||
{
|
||||
return; // can not update metaobject's metadata
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the metadata of the metaobject
|
||||
*/
|
||||
UAVObject::Metadata UAVMetaObject::getMetadata()
|
||||
{
|
||||
return ownMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default metadata
|
||||
*/
|
||||
UAVObject::Metadata UAVMetaObject::getDefaultMetadata()
|
||||
{
|
||||
return ownMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the metadata held by the metaobject
|
||||
*/
|
||||
void UAVMetaObject::setData(const Metadata& mdata)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
parentMetadata = mdata;
|
||||
emit objectUpdatedAuto(this); // trigger object updated event
|
||||
emit objectUpdated(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the metadata held by the metaobject
|
||||
*/
|
||||
UAVObject::Metadata UAVMetaObject::getData()
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
return parentMetadata;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavmetaobject.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectsplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavmetaobject.h"
|
||||
#include "uavobjectfield.h"
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
UAVMetaObject::UAVMetaObject(quint32 objID, const QString& name, UAVObject* parent):
|
||||
UAVObject(objID, true, name)
|
||||
{
|
||||
this->parent = parent;
|
||||
// Setup default metadata of metaobject (can not be changed)
|
||||
ownMetadata.flightAccess = ACCESS_READWRITE;
|
||||
ownMetadata.gcsAccess = ACCESS_READWRITE;
|
||||
ownMetadata.flightTelemetryAcked = 1;
|
||||
ownMetadata.flightTelemetryUpdateMode = UPDATEMODE_ONCHANGE;
|
||||
ownMetadata.flightTelemetryUpdatePeriod = 0;
|
||||
ownMetadata.gcsTelemetryAcked = 1;
|
||||
ownMetadata.gcsTelemetryUpdateMode = UPDATEMODE_ONCHANGE;
|
||||
ownMetadata.gcsTelemetryUpdatePeriod = 0;
|
||||
ownMetadata.loggingUpdateMode = UPDATEMODE_ONCHANGE;
|
||||
ownMetadata.loggingUpdatePeriod = 0;
|
||||
// Setup fields
|
||||
QStringList boolEnum;
|
||||
boolEnum << tr("False") << tr("True");
|
||||
QStringList updateModeEnum;
|
||||
updateModeEnum << tr("Periodic") << tr("On Change") << tr("Manual") << tr("Never");
|
||||
QStringList accessModeEnum;
|
||||
accessModeEnum << tr("Read/Write") << tr("Read Only");
|
||||
QList<UAVObjectField*> fields;
|
||||
fields.append( new UAVObjectField(tr("Flight Access Mode"), tr(""), UAVObjectField::ENUM, 1, accessModeEnum) );
|
||||
fields.append( new UAVObjectField(tr("GCS Access Mode"), tr(""), UAVObjectField::ENUM, 1, accessModeEnum) );
|
||||
fields.append( new UAVObjectField(tr("Flight Telemetry Acked"), tr(""), UAVObjectField::ENUM, 1, boolEnum) );
|
||||
fields.append( new UAVObjectField(tr("Flight Telemetry Update Mode"), tr(""), UAVObjectField::ENUM, 1, updateModeEnum) );
|
||||
fields.append( new UAVObjectField(tr("Flight Telemetry Update Period"), tr(""), UAVObjectField::UINT32, 1, QStringList()) );
|
||||
fields.append( new UAVObjectField(tr("GCS Telemetry Acked"), tr(""), UAVObjectField::ENUM, 1, boolEnum) );
|
||||
fields.append( new UAVObjectField(tr("GCS Telemetry Update Mode"), tr(""), UAVObjectField::ENUM, 1, updateModeEnum) );
|
||||
fields.append( new UAVObjectField(tr("GCS Telemetry Update Period"), tr(""), UAVObjectField::UINT32, 1, QStringList()) );
|
||||
fields.append( new UAVObjectField(tr("Logging Update Mode"), tr(""), UAVObjectField::ENUM, 1, updateModeEnum) );
|
||||
fields.append( new UAVObjectField(tr("Logging Update Period"), tr(""), UAVObjectField::UINT32, 1, QStringList()) );
|
||||
// Initialize parent
|
||||
UAVObject::initialize(0);
|
||||
UAVObject::initializeFields(fields, (quint8*)&parentMetadata, sizeof(Metadata));
|
||||
// Setup metadata of parent
|
||||
parentMetadata = parent->getDefaultMetadata();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the parent object
|
||||
*/
|
||||
UAVObject* UAVMetaObject::getParentObject()
|
||||
{
|
||||
return parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the metadata of the metaobject, this function will
|
||||
* do nothing since metaobjects have read-only metadata.
|
||||
*/
|
||||
void UAVMetaObject::setMetadata(const Metadata& mdata)
|
||||
{
|
||||
return; // can not update metaobject's metadata
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the metadata of the metaobject
|
||||
*/
|
||||
UAVObject::Metadata UAVMetaObject::getMetadata()
|
||||
{
|
||||
return ownMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default metadata
|
||||
*/
|
||||
UAVObject::Metadata UAVMetaObject::getDefaultMetadata()
|
||||
{
|
||||
return ownMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the metadata held by the metaobject
|
||||
*/
|
||||
void UAVMetaObject::setData(const Metadata& mdata)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
parentMetadata = mdata;
|
||||
emit objectUpdatedAuto(this); // trigger object updated event
|
||||
emit objectUpdated(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the metadata held by the metaobject
|
||||
*/
|
||||
UAVObject::Metadata UAVMetaObject::getData()
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
return parentMetadata;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,54 +1,53 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavmetaobject.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef UAVMETAOBJECT_H
|
||||
#define UAVMETAOBJECT_H
|
||||
|
||||
#include "uavobjects_global.h"
|
||||
#include "uavobject.h"
|
||||
|
||||
class UAVOBJECTS_EXPORT UAVMetaObject: public UAVObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UAVMetaObject(quint32 objID, const QString& name, UAVObject* parent);
|
||||
UAVObject* getParentObject();
|
||||
void setMetadata(const Metadata& mdata);
|
||||
Metadata getMetadata();
|
||||
Metadata getDefaultMetadata();
|
||||
void setData(const Metadata& mdata);
|
||||
Metadata getData();
|
||||
|
||||
private:
|
||||
UAVObject* parent;
|
||||
Metadata ownMetadata;
|
||||
Metadata parentMetadata;
|
||||
|
||||
};
|
||||
|
||||
#endif // UAVMETAOBJECT_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavmetaobject.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectsplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef UAVMETAOBJECT_H
|
||||
#define UAVMETAOBJECT_H
|
||||
|
||||
#include "uavobjects_global.h"
|
||||
#include "uavobject.h"
|
||||
|
||||
class UAVOBJECTS_EXPORT UAVMetaObject: public UAVObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UAVMetaObject(quint32 objID, const QString& name, UAVObject* parent);
|
||||
UAVObject* getParentObject();
|
||||
void setMetadata(const Metadata& mdata);
|
||||
Metadata getMetadata();
|
||||
Metadata getDefaultMetadata();
|
||||
void setData(const Metadata& mdata);
|
||||
Metadata getData();
|
||||
|
||||
private:
|
||||
UAVObject* parent;
|
||||
Metadata ownMetadata;
|
||||
Metadata parentMetadata;
|
||||
|
||||
};
|
||||
|
||||
#endif // UAVMETAOBJECT_H
|
||||
|
@ -1,438 +1,437 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobject.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavobject.h"
|
||||
#include <QtEndian>
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param objID The object ID
|
||||
* @param isSingleInst True if this object can only have a single instance
|
||||
* @param name Object name
|
||||
*/
|
||||
UAVObject::UAVObject(quint32 objID, bool isSingleInst, const QString& name)
|
||||
{
|
||||
this->objID = objID;
|
||||
this->instID = 0;
|
||||
this->isSingleInst = isSingleInst;
|
||||
this->name = name;
|
||||
this->mutex = new QMutex(QMutex::Recursive);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize object with its instance ID
|
||||
*/
|
||||
void UAVObject::initialize(quint32 instID)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
this->instID = instID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize objects' data fields
|
||||
* @param fields List of fields held by the object
|
||||
* @param data Pointer to that actual object data, this is needed by the fields to access the data
|
||||
* @param numBytes Number of bytes in the object (total, including all fields)
|
||||
*/
|
||||
void UAVObject::initializeFields(QList<UAVObjectField*>& fields, quint8* data, quint32 numBytes)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
this->numBytes = numBytes;
|
||||
this->data = data;
|
||||
this->fields = fields;
|
||||
// Initialize fields
|
||||
quint32 offset = 0;
|
||||
for (int n = 0; n < fields.length(); ++n)
|
||||
{
|
||||
fields[n]->initialize(data, offset, this);
|
||||
offset += fields[n]->getNumBytes();
|
||||
connect(fields[n], SIGNAL(fieldUpdated(UAVObjectField*)), this, SLOT(fieldUpdated(UAVObjectField*)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from the fields each time they are updated
|
||||
*/
|
||||
void UAVObject::fieldUpdated(UAVObjectField* field)
|
||||
{
|
||||
// emit objectUpdatedAuto(this); // trigger object updated event
|
||||
// emit objectUpdated(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the object ID
|
||||
*/
|
||||
quint32 UAVObject::getObjID()
|
||||
{
|
||||
return objID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the instance ID
|
||||
*/
|
||||
quint32 UAVObject::getInstID()
|
||||
{
|
||||
return instID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this is a single instance object
|
||||
*/
|
||||
bool UAVObject::isSingleInstance()
|
||||
{
|
||||
return isSingleInst;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the object
|
||||
*/
|
||||
QString UAVObject::getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total number of bytes of the object's data
|
||||
*/
|
||||
quint32 UAVObject::getNumBytes()
|
||||
{
|
||||
return numBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request that this object is updated with the latest values from the autopilot
|
||||
*/
|
||||
void UAVObject::requestUpdate()
|
||||
{
|
||||
emit updateRequested(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal that the object has been updated
|
||||
*/
|
||||
void UAVObject::updated()
|
||||
{
|
||||
emit objectUpdatedManual(this);
|
||||
emit objectUpdated(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock mutex of this object
|
||||
*/
|
||||
void UAVObject::lock()
|
||||
{
|
||||
mutex->lock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock mutex of this object
|
||||
*/
|
||||
void UAVObject::lock(int timeoutMs)
|
||||
{
|
||||
mutex->tryLock(timeoutMs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlock mutex of this object
|
||||
*/
|
||||
void UAVObject::unlock()
|
||||
{
|
||||
mutex->unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get object's mutex
|
||||
*/
|
||||
QMutex* UAVObject::getMutex()
|
||||
{
|
||||
return mutex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of fields held by this object
|
||||
*/
|
||||
qint32 UAVObject::getNumFields()
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
return fields.count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the object's fields
|
||||
*/
|
||||
QList<UAVObjectField*> UAVObject::getFields()
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
return fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific field
|
||||
* @returns The field or NULL if not found
|
||||
*/
|
||||
UAVObjectField* UAVObject::getField(QString& name)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
// Look for field
|
||||
for (int n = 0; n < fields.length(); ++n)
|
||||
{
|
||||
if (name.compare(fields[n]->getName()) == 0)
|
||||
{
|
||||
return fields[n];
|
||||
}
|
||||
}
|
||||
// If this point is reached then the field was not found
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pack the object data into a byte array
|
||||
* @returns The number of bytes copied
|
||||
*/
|
||||
qint32 UAVObject::pack(quint8* dataOut)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
qint32 offset = 0;
|
||||
for (int n = 0; n < fields.length(); ++n)
|
||||
{
|
||||
fields[n]->pack(&dataOut[offset]);
|
||||
offset += fields[n]->getNumBytes();
|
||||
}
|
||||
return numBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpack the object data from a byte array
|
||||
* @returns The number of bytes copied
|
||||
*/
|
||||
qint32 UAVObject::unpack(const quint8* dataIn)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
qint32 offset = 0;
|
||||
for (int n = 0; n < fields.length(); ++n)
|
||||
{
|
||||
fields[n]->unpack(&dataIn[offset]);
|
||||
offset += fields[n]->getNumBytes();
|
||||
}
|
||||
emit objectUnpacked(this); // trigger object updated event
|
||||
emit objectUpdated(this);
|
||||
|
||||
return numBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the object data to the file.
|
||||
* The file will be created in the current directory
|
||||
* and its name will be the same as the object with
|
||||
* the .uavobj extension.
|
||||
* @returns True on success, false on failure
|
||||
*/
|
||||
bool UAVObject::save()
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
|
||||
// Open file
|
||||
QFile file(name + ".uavobj");
|
||||
if (!file.open(QFile::WriteOnly))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Write object
|
||||
if ( !save(file) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Close file
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the object data to the file.
|
||||
* The file is expected to be already open for writting.
|
||||
* The data will be appended and the file will not be closed.
|
||||
* @returns True on success, false on failure
|
||||
*/
|
||||
bool UAVObject::save(QFile& file)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
quint8 buffer[numBytes];
|
||||
quint8 tmpId[4];
|
||||
|
||||
// Write the object ID
|
||||
qToLittleEndian<quint32>(objID, tmpId);
|
||||
if ( file.write((const char*)tmpId, 4) == -1 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Write the instance ID
|
||||
if (!isSingleInst)
|
||||
{
|
||||
qToLittleEndian<quint16>(instID, tmpId);
|
||||
if ( file.write((const char*)tmpId, 2) == -1 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Write the data
|
||||
pack(buffer);
|
||||
if ( file.write((const char*)buffer, numBytes) == -1 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Done
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the object data from a file.
|
||||
* The file will be openned in the current directory
|
||||
* and its name will be the same as the object with
|
||||
* the .uavobj extension.
|
||||
* @returns True on success, false on failure
|
||||
*/
|
||||
bool UAVObject::load()
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
|
||||
// Open file
|
||||
QFile file(name + ".uavobj");
|
||||
if (!file.open(QFile::ReadOnly))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Load object
|
||||
if ( !load(file) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Close file
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the object data from file.
|
||||
* The file is expected to be already open for reading.
|
||||
* The data will be read and the file will not be closed.
|
||||
* @returns True on success, false on failure
|
||||
*/
|
||||
bool UAVObject::load(QFile& file)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
quint8 buffer[numBytes];
|
||||
quint8 tmpId[4];
|
||||
|
||||
// Read the object ID
|
||||
if ( file.read((char*)tmpId, 4) != 4 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check that the IDs match
|
||||
if (qFromLittleEndian<quint32>(tmpId) != objID)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the instance ID
|
||||
if ( file.read((char*)tmpId, 2) != 2 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check that the IDs match
|
||||
if (qFromLittleEndian<quint16>(tmpId) != instID)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read and unpack the data
|
||||
if ( file.read((char*)buffer, numBytes) != numBytes )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
unpack(buffer);
|
||||
|
||||
// Done
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string with the object information
|
||||
*/
|
||||
QString UAVObject::toString()
|
||||
{
|
||||
QString sout;
|
||||
sout.append( toStringBrief() );
|
||||
sout.append( toStringData() );
|
||||
return sout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string with the object information (only the header)
|
||||
*/
|
||||
QString UAVObject::toStringBrief()
|
||||
{
|
||||
QString sout;
|
||||
sout.append( QString("%1 (ID: %2, InstID: %3, NumBytes: %4, SInst: %5)\n")
|
||||
.arg(getName())
|
||||
.arg(getObjID())
|
||||
.arg(getInstID())
|
||||
.arg(getNumBytes())
|
||||
.arg(isSingleInstance()) );
|
||||
return sout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string with the object information (only the data)
|
||||
*/
|
||||
QString UAVObject::toStringData()
|
||||
{
|
||||
QString sout;
|
||||
sout.append("Data:\n");
|
||||
for (int n = 0; n < fields.length(); ++n)
|
||||
{
|
||||
sout.append( QString("\t%1").arg(fields[n]->toString()) );
|
||||
}
|
||||
return sout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit the transactionCompleted event (used by the UAVTalk plugin)
|
||||
*/
|
||||
void UAVObject::emitTransactionCompleted(bool success)
|
||||
{
|
||||
emit transactionCompleted(this, success);
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobject.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectsplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavobject.h"
|
||||
#include <QtEndian>
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param objID The object ID
|
||||
* @param isSingleInst True if this object can only have a single instance
|
||||
* @param name Object name
|
||||
*/
|
||||
UAVObject::UAVObject(quint32 objID, bool isSingleInst, const QString& name)
|
||||
{
|
||||
this->objID = objID;
|
||||
this->instID = 0;
|
||||
this->isSingleInst = isSingleInst;
|
||||
this->name = name;
|
||||
this->mutex = new QMutex(QMutex::Recursive);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize object with its instance ID
|
||||
*/
|
||||
void UAVObject::initialize(quint32 instID)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
this->instID = instID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize objects' data fields
|
||||
* @param fields List of fields held by the object
|
||||
* @param data Pointer to that actual object data, this is needed by the fields to access the data
|
||||
* @param numBytes Number of bytes in the object (total, including all fields)
|
||||
*/
|
||||
void UAVObject::initializeFields(QList<UAVObjectField*>& fields, quint8* data, quint32 numBytes)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
this->numBytes = numBytes;
|
||||
this->data = data;
|
||||
this->fields = fields;
|
||||
// Initialize fields
|
||||
quint32 offset = 0;
|
||||
for (int n = 0; n < fields.length(); ++n)
|
||||
{
|
||||
fields[n]->initialize(data, offset, this);
|
||||
offset += fields[n]->getNumBytes();
|
||||
connect(fields[n], SIGNAL(fieldUpdated(UAVObjectField*)), this, SLOT(fieldUpdated(UAVObjectField*)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from the fields each time they are updated
|
||||
*/
|
||||
void UAVObject::fieldUpdated(UAVObjectField* field)
|
||||
{
|
||||
// emit objectUpdatedAuto(this); // trigger object updated event
|
||||
// emit objectUpdated(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the object ID
|
||||
*/
|
||||
quint32 UAVObject::getObjID()
|
||||
{
|
||||
return objID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the instance ID
|
||||
*/
|
||||
quint32 UAVObject::getInstID()
|
||||
{
|
||||
return instID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this is a single instance object
|
||||
*/
|
||||
bool UAVObject::isSingleInstance()
|
||||
{
|
||||
return isSingleInst;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the object
|
||||
*/
|
||||
QString UAVObject::getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total number of bytes of the object's data
|
||||
*/
|
||||
quint32 UAVObject::getNumBytes()
|
||||
{
|
||||
return numBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request that this object is updated with the latest values from the autopilot
|
||||
*/
|
||||
void UAVObject::requestUpdate()
|
||||
{
|
||||
emit updateRequested(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal that the object has been updated
|
||||
*/
|
||||
void UAVObject::updated()
|
||||
{
|
||||
emit objectUpdatedManual(this);
|
||||
emit objectUpdated(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock mutex of this object
|
||||
*/
|
||||
void UAVObject::lock()
|
||||
{
|
||||
mutex->lock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock mutex of this object
|
||||
*/
|
||||
void UAVObject::lock(int timeoutMs)
|
||||
{
|
||||
mutex->tryLock(timeoutMs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlock mutex of this object
|
||||
*/
|
||||
void UAVObject::unlock()
|
||||
{
|
||||
mutex->unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get object's mutex
|
||||
*/
|
||||
QMutex* UAVObject::getMutex()
|
||||
{
|
||||
return mutex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of fields held by this object
|
||||
*/
|
||||
qint32 UAVObject::getNumFields()
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
return fields.count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the object's fields
|
||||
*/
|
||||
QList<UAVObjectField*> UAVObject::getFields()
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
return fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific field
|
||||
* @returns The field or NULL if not found
|
||||
*/
|
||||
UAVObjectField* UAVObject::getField(QString& name)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
// Look for field
|
||||
for (int n = 0; n < fields.length(); ++n)
|
||||
{
|
||||
if (name.compare(fields[n]->getName()) == 0)
|
||||
{
|
||||
return fields[n];
|
||||
}
|
||||
}
|
||||
// If this point is reached then the field was not found
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pack the object data into a byte array
|
||||
* @returns The number of bytes copied
|
||||
*/
|
||||
qint32 UAVObject::pack(quint8* dataOut)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
qint32 offset = 0;
|
||||
for (int n = 0; n < fields.length(); ++n)
|
||||
{
|
||||
fields[n]->pack(&dataOut[offset]);
|
||||
offset += fields[n]->getNumBytes();
|
||||
}
|
||||
return numBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpack the object data from a byte array
|
||||
* @returns The number of bytes copied
|
||||
*/
|
||||
qint32 UAVObject::unpack(const quint8* dataIn)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
qint32 offset = 0;
|
||||
for (int n = 0; n < fields.length(); ++n)
|
||||
{
|
||||
fields[n]->unpack(&dataIn[offset]);
|
||||
offset += fields[n]->getNumBytes();
|
||||
}
|
||||
emit objectUnpacked(this); // trigger object updated event
|
||||
emit objectUpdated(this);
|
||||
|
||||
return numBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the object data to the file.
|
||||
* The file will be created in the current directory
|
||||
* and its name will be the same as the object with
|
||||
* the .uavobj extension.
|
||||
* @returns True on success, false on failure
|
||||
*/
|
||||
bool UAVObject::save()
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
|
||||
// Open file
|
||||
QFile file(name + ".uavobj");
|
||||
if (!file.open(QFile::WriteOnly))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Write object
|
||||
if ( !save(file) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Close file
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the object data to the file.
|
||||
* The file is expected to be already open for writting.
|
||||
* The data will be appended and the file will not be closed.
|
||||
* @returns True on success, false on failure
|
||||
*/
|
||||
bool UAVObject::save(QFile& file)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
quint8 buffer[numBytes];
|
||||
quint8 tmpId[4];
|
||||
|
||||
// Write the object ID
|
||||
qToLittleEndian<quint32>(objID, tmpId);
|
||||
if ( file.write((const char*)tmpId, 4) == -1 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Write the instance ID
|
||||
if (!isSingleInst)
|
||||
{
|
||||
qToLittleEndian<quint16>(instID, tmpId);
|
||||
if ( file.write((const char*)tmpId, 2) == -1 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Write the data
|
||||
pack(buffer);
|
||||
if ( file.write((const char*)buffer, numBytes) == -1 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Done
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the object data from a file.
|
||||
* The file will be openned in the current directory
|
||||
* and its name will be the same as the object with
|
||||
* the .uavobj extension.
|
||||
* @returns True on success, false on failure
|
||||
*/
|
||||
bool UAVObject::load()
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
|
||||
// Open file
|
||||
QFile file(name + ".uavobj");
|
||||
if (!file.open(QFile::ReadOnly))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Load object
|
||||
if ( !load(file) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Close file
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the object data from file.
|
||||
* The file is expected to be already open for reading.
|
||||
* The data will be read and the file will not be closed.
|
||||
* @returns True on success, false on failure
|
||||
*/
|
||||
bool UAVObject::load(QFile& file)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
quint8 buffer[numBytes];
|
||||
quint8 tmpId[4];
|
||||
|
||||
// Read the object ID
|
||||
if ( file.read((char*)tmpId, 4) != 4 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check that the IDs match
|
||||
if (qFromLittleEndian<quint32>(tmpId) != objID)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the instance ID
|
||||
if ( file.read((char*)tmpId, 2) != 2 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check that the IDs match
|
||||
if (qFromLittleEndian<quint16>(tmpId) != instID)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read and unpack the data
|
||||
if ( file.read((char*)buffer, numBytes) != numBytes )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
unpack(buffer);
|
||||
|
||||
// Done
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string with the object information
|
||||
*/
|
||||
QString UAVObject::toString()
|
||||
{
|
||||
QString sout;
|
||||
sout.append( toStringBrief() );
|
||||
sout.append( toStringData() );
|
||||
return sout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string with the object information (only the header)
|
||||
*/
|
||||
QString UAVObject::toStringBrief()
|
||||
{
|
||||
QString sout;
|
||||
sout.append( QString("%1 (ID: %2, InstID: %3, NumBytes: %4, SInst: %5)\n")
|
||||
.arg(getName())
|
||||
.arg(getObjID())
|
||||
.arg(getInstID())
|
||||
.arg(getNumBytes())
|
||||
.arg(isSingleInstance()) );
|
||||
return sout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string with the object information (only the data)
|
||||
*/
|
||||
QString UAVObject::toStringData()
|
||||
{
|
||||
QString sout;
|
||||
sout.append("Data:\n");
|
||||
for (int n = 0; n < fields.length(); ++n)
|
||||
{
|
||||
sout.append( QString("\t%1").arg(fields[n]->toString()) );
|
||||
}
|
||||
return sout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit the transactionCompleted event (used by the UAVTalk plugin)
|
||||
*/
|
||||
void UAVObject::emitTransactionCompleted(bool success)
|
||||
{
|
||||
emit transactionCompleted(this, success);
|
||||
}
|
||||
|
@ -1,139 +1,138 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobject.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef UAVOBJECT_H
|
||||
#define UAVOBJECT_H
|
||||
|
||||
#include "uavobjects_global.h"
|
||||
#include <QtGlobal>
|
||||
#include <QObject>
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
#include <QFile>
|
||||
#include "uavobjectfield.h"
|
||||
|
||||
class UAVObjectField;
|
||||
|
||||
class UAVOBJECTS_EXPORT UAVObject: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Object update mode
|
||||
*/
|
||||
typedef enum {
|
||||
UPDATEMODE_PERIODIC = 0, /** Automatically update object at periodic intervals */
|
||||
UPDATEMODE_ONCHANGE = 1, /** Only update object when its data changes */
|
||||
UPDATEMODE_MANUAL = 2, /** Manually update object, by calling the updated() function */
|
||||
UPDATEMODE_NEVER = 3 /** Object is never updated */
|
||||
} UpdateMode;
|
||||
|
||||
/**
|
||||
* Access mode
|
||||
*/
|
||||
typedef enum {
|
||||
ACCESS_READWRITE = 0,
|
||||
ACCESS_READONLY = 1
|
||||
} AccessMode;
|
||||
|
||||
/**
|
||||
* Object metadata, each object has a meta object that holds its metadata. The metadata define
|
||||
* properties for each object and can be used by multiple modules (e.g. telemetry and logger)
|
||||
*/
|
||||
typedef struct {
|
||||
quint8 flightAccess; /** Defines the access level for the local flight transactions (readonly and readwrite) */
|
||||
quint8 gcsAccess; /** Defines the access level for the local GCS transactions (readonly and readwrite) */
|
||||
quint8 flightTelemetryAcked; /** Defines if an ack is required for the transactions of this object (1:acked, 0:not acked) */
|
||||
quint8 flightTelemetryUpdateMode; /** Update mode used by the autopilot (UpdateMode) */
|
||||
qint32 flightTelemetryUpdatePeriod; /** Update period used by the autopilot (only if telemetry mode is PERIODIC) */
|
||||
quint8 gcsTelemetryAcked; /** Defines if an ack is required for the transactions of this object (1:acked, 0:not acked) */
|
||||
quint8 gcsTelemetryUpdateMode; /** Update mode used by the GCS (UpdateMode) */
|
||||
qint32 gcsTelemetryUpdatePeriod; /** Update period used by the GCS (only if telemetry mode is PERIODIC) */
|
||||
quint8 loggingUpdateMode; /** Update mode used by the logging module (UpdateMode) */
|
||||
qint32 loggingUpdatePeriod; /** Update period used by the logging module (only if logging mode is PERIODIC) */
|
||||
} __attribute__((packed)) Metadata;
|
||||
|
||||
|
||||
UAVObject(quint32 objID, bool isSingleInst, const QString& name);
|
||||
void initialize(quint32 instID);
|
||||
quint32 getObjID();
|
||||
quint32 getInstID();
|
||||
bool isSingleInstance();
|
||||
QString getName();
|
||||
quint32 getNumBytes();
|
||||
qint32 pack(quint8* dataOut);
|
||||
qint32 unpack(const quint8* dataIn);
|
||||
bool save();
|
||||
bool save(QFile& file);
|
||||
bool load();
|
||||
bool load(QFile& file);
|
||||
virtual void setMetadata(const Metadata& mdata) = 0;
|
||||
virtual Metadata getMetadata() = 0;
|
||||
virtual Metadata getDefaultMetadata() = 0;
|
||||
void requestUpdate();
|
||||
void updated();
|
||||
void lock();
|
||||
void lock(int timeoutMs);
|
||||
void unlock();
|
||||
QMutex* getMutex();
|
||||
qint32 getNumFields();
|
||||
QList<UAVObjectField*> getFields();
|
||||
UAVObjectField* getField(QString& name);
|
||||
QString toString();
|
||||
QString toStringBrief();
|
||||
QString toStringData();
|
||||
void emitTransactionCompleted(bool success);
|
||||
|
||||
signals:
|
||||
void objectUpdated(UAVObject* obj);
|
||||
void objectUpdatedAuto(UAVObject* obj);
|
||||
void objectUpdatedManual(UAVObject* obj);
|
||||
void objectUnpacked(UAVObject* obj);
|
||||
void updateRequested(UAVObject* obj);
|
||||
void transactionCompleted(UAVObject* obj, bool success);
|
||||
|
||||
private slots:
|
||||
void fieldUpdated(UAVObjectField* field);
|
||||
|
||||
protected:
|
||||
quint32 objID;
|
||||
quint32 instID;
|
||||
bool isSingleInst;
|
||||
QString name;
|
||||
quint32 numBytes;
|
||||
QMutex* mutex;
|
||||
quint8* data;
|
||||
QList<UAVObjectField*> fields;
|
||||
|
||||
void initializeFields(QList<UAVObjectField*>& fields, quint8* data, quint32 numBytes);
|
||||
};
|
||||
|
||||
#endif // UAVOBJECT_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobject.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectsplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef UAVOBJECT_H
|
||||
#define UAVOBJECT_H
|
||||
|
||||
#include "uavobjects_global.h"
|
||||
#include <QtGlobal>
|
||||
#include <QObject>
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
#include <QFile>
|
||||
#include "uavobjectfield.h"
|
||||
|
||||
class UAVObjectField;
|
||||
|
||||
class UAVOBJECTS_EXPORT UAVObject: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Object update mode
|
||||
*/
|
||||
typedef enum {
|
||||
UPDATEMODE_PERIODIC = 0, /** Automatically update object at periodic intervals */
|
||||
UPDATEMODE_ONCHANGE = 1, /** Only update object when its data changes */
|
||||
UPDATEMODE_MANUAL = 2, /** Manually update object, by calling the updated() function */
|
||||
UPDATEMODE_NEVER = 3 /** Object is never updated */
|
||||
} UpdateMode;
|
||||
|
||||
/**
|
||||
* Access mode
|
||||
*/
|
||||
typedef enum {
|
||||
ACCESS_READWRITE = 0,
|
||||
ACCESS_READONLY = 1
|
||||
} AccessMode;
|
||||
|
||||
/**
|
||||
* Object metadata, each object has a meta object that holds its metadata. The metadata define
|
||||
* properties for each object and can be used by multiple modules (e.g. telemetry and logger)
|
||||
*/
|
||||
typedef struct {
|
||||
quint8 flightAccess; /** Defines the access level for the local flight transactions (readonly and readwrite) */
|
||||
quint8 gcsAccess; /** Defines the access level for the local GCS transactions (readonly and readwrite) */
|
||||
quint8 flightTelemetryAcked; /** Defines if an ack is required for the transactions of this object (1:acked, 0:not acked) */
|
||||
quint8 flightTelemetryUpdateMode; /** Update mode used by the autopilot (UpdateMode) */
|
||||
qint32 flightTelemetryUpdatePeriod; /** Update period used by the autopilot (only if telemetry mode is PERIODIC) */
|
||||
quint8 gcsTelemetryAcked; /** Defines if an ack is required for the transactions of this object (1:acked, 0:not acked) */
|
||||
quint8 gcsTelemetryUpdateMode; /** Update mode used by the GCS (UpdateMode) */
|
||||
qint32 gcsTelemetryUpdatePeriod; /** Update period used by the GCS (only if telemetry mode is PERIODIC) */
|
||||
quint8 loggingUpdateMode; /** Update mode used by the logging module (UpdateMode) */
|
||||
qint32 loggingUpdatePeriod; /** Update period used by the logging module (only if logging mode is PERIODIC) */
|
||||
} __attribute__((packed)) Metadata;
|
||||
|
||||
|
||||
UAVObject(quint32 objID, bool isSingleInst, const QString& name);
|
||||
void initialize(quint32 instID);
|
||||
quint32 getObjID();
|
||||
quint32 getInstID();
|
||||
bool isSingleInstance();
|
||||
QString getName();
|
||||
quint32 getNumBytes();
|
||||
qint32 pack(quint8* dataOut);
|
||||
qint32 unpack(const quint8* dataIn);
|
||||
bool save();
|
||||
bool save(QFile& file);
|
||||
bool load();
|
||||
bool load(QFile& file);
|
||||
virtual void setMetadata(const Metadata& mdata) = 0;
|
||||
virtual Metadata getMetadata() = 0;
|
||||
virtual Metadata getDefaultMetadata() = 0;
|
||||
void requestUpdate();
|
||||
void updated();
|
||||
void lock();
|
||||
void lock(int timeoutMs);
|
||||
void unlock();
|
||||
QMutex* getMutex();
|
||||
qint32 getNumFields();
|
||||
QList<UAVObjectField*> getFields();
|
||||
UAVObjectField* getField(QString& name);
|
||||
QString toString();
|
||||
QString toStringBrief();
|
||||
QString toStringData();
|
||||
void emitTransactionCompleted(bool success);
|
||||
|
||||
signals:
|
||||
void objectUpdated(UAVObject* obj);
|
||||
void objectUpdatedAuto(UAVObject* obj);
|
||||
void objectUpdatedManual(UAVObject* obj);
|
||||
void objectUnpacked(UAVObject* obj);
|
||||
void updateRequested(UAVObject* obj);
|
||||
void transactionCompleted(UAVObject* obj, bool success);
|
||||
|
||||
private slots:
|
||||
void fieldUpdated(UAVObjectField* field);
|
||||
|
||||
protected:
|
||||
quint32 objID;
|
||||
quint32 instID;
|
||||
bool isSingleInst;
|
||||
QString name;
|
||||
quint32 numBytes;
|
||||
QMutex* mutex;
|
||||
quint8* data;
|
||||
QList<UAVObjectField*> fields;
|
||||
|
||||
void initializeFields(QList<UAVObjectField*>& fields, quint8* data, quint32 numBytes);
|
||||
};
|
||||
|
||||
#endif // UAVOBJECT_H
|
||||
|
@ -1,550 +1,549 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectfield.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavobjectfield.h"
|
||||
#include <QtEndian>
|
||||
|
||||
UAVObjectField::UAVObjectField(const QString& name, const QString& units, FieldType type, quint32 numElements, const QStringList& options)
|
||||
{
|
||||
QStringList elementNames;
|
||||
// Set element names
|
||||
for (quint32 n = 0; n < numElements; ++n)
|
||||
{
|
||||
elementNames.append(QString("%1").arg(n));
|
||||
}
|
||||
// Initialize
|
||||
constructorInitialize(name, units, type, elementNames, options);
|
||||
|
||||
}
|
||||
|
||||
UAVObjectField::UAVObjectField(const QString& name, const QString& units, FieldType type, const QStringList& elementNames, const QStringList& options)
|
||||
{
|
||||
constructorInitialize(name, units, type, elementNames, options);
|
||||
}
|
||||
|
||||
void UAVObjectField::constructorInitialize(const QString& name, const QString& units, FieldType type, const QStringList& elementNames, const QStringList& options)
|
||||
{
|
||||
// Copy params
|
||||
this->name = name;
|
||||
this->units = units;
|
||||
this->type = type;
|
||||
this->options = options;
|
||||
this->numElements = elementNames.length();
|
||||
this->offset = 0;
|
||||
this->data = NULL;
|
||||
this->obj = NULL;
|
||||
this->elementNames = elementNames;
|
||||
// Set field size
|
||||
switch (type)
|
||||
{
|
||||
case INT8:
|
||||
numBytesPerElement = sizeof(qint8);
|
||||
break;
|
||||
case INT16:
|
||||
numBytesPerElement = sizeof(qint16);
|
||||
break;
|
||||
case INT32:
|
||||
numBytesPerElement = sizeof(qint32);
|
||||
break;
|
||||
case UINT8:
|
||||
numBytesPerElement = sizeof(quint8);
|
||||
break;
|
||||
case UINT16:
|
||||
numBytesPerElement = sizeof(quint16);
|
||||
break;
|
||||
case UINT32:
|
||||
numBytesPerElement = sizeof(quint32);
|
||||
break;
|
||||
case FLOAT32:
|
||||
numBytesPerElement = sizeof(quint32);
|
||||
break;
|
||||
case ENUM:
|
||||
numBytesPerElement = sizeof(quint8);
|
||||
break;
|
||||
case STRING:
|
||||
numBytesPerElement = sizeof(quint8);
|
||||
break;
|
||||
default:
|
||||
numBytesPerElement = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void UAVObjectField::initialize(quint8* data, quint32 dataOffset, UAVObject* obj)
|
||||
{
|
||||
this->data = data;
|
||||
this->offset = dataOffset;
|
||||
this->obj = obj;
|
||||
clear();
|
||||
}
|
||||
|
||||
UAVObjectField::FieldType UAVObjectField::getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
QStringList UAVObjectField::getElementNames()
|
||||
{
|
||||
return elementNames;
|
||||
}
|
||||
|
||||
UAVObject* UAVObjectField::getObject()
|
||||
{
|
||||
return obj;
|
||||
}
|
||||
|
||||
void UAVObjectField::clear()
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
memset(&data[offset], 0, numBytesPerElement*numElements);
|
||||
}
|
||||
|
||||
QString UAVObjectField::getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
QString UAVObjectField::getUnits()
|
||||
{
|
||||
return units;
|
||||
}
|
||||
|
||||
QStringList UAVObjectField::getOptions()
|
||||
{
|
||||
return options;
|
||||
}
|
||||
|
||||
quint32 UAVObjectField::getNumElements()
|
||||
{
|
||||
return numElements;
|
||||
}
|
||||
|
||||
quint32 UAVObjectField::getDataOffset()
|
||||
{
|
||||
return offset;
|
||||
}
|
||||
|
||||
quint32 UAVObjectField::getNumBytes()
|
||||
{
|
||||
return numBytesPerElement * numElements;
|
||||
}
|
||||
|
||||
QString UAVObjectField::toString()
|
||||
{
|
||||
QString sout;
|
||||
sout.append ( QString("%1: [ ").arg(name) );
|
||||
for (unsigned int n = 0; n < numElements; ++n)
|
||||
{
|
||||
sout.append( QString("%1 ").arg(getDouble(n)) );
|
||||
}
|
||||
sout.append( QString("] %1\n").arg(units) );
|
||||
return sout;
|
||||
}
|
||||
|
||||
|
||||
qint32 UAVObjectField::pack(quint8* dataOut)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Pack each element in output buffer
|
||||
switch (type)
|
||||
{
|
||||
case INT8:
|
||||
memcpy(dataOut, &data[offset], numElements);
|
||||
break;
|
||||
case INT16:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
qint16 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
qToLittleEndian<qint16>(value, &dataOut[numBytesPerElement*index]);
|
||||
}
|
||||
break;
|
||||
case INT32:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
qint32 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
qToLittleEndian<qint32>(value, &dataOut[numBytesPerElement*index]);
|
||||
}
|
||||
break;
|
||||
case UINT8:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
dataOut[numBytesPerElement*index] = data[offset + numBytesPerElement*index];
|
||||
}
|
||||
break;
|
||||
case UINT16:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
quint16 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
qToLittleEndian<quint16>(value, &dataOut[numBytesPerElement*index]);
|
||||
}
|
||||
break;
|
||||
case UINT32:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
quint32 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
qToLittleEndian<quint32>(value, &dataOut[numBytesPerElement*index]);
|
||||
}
|
||||
break;
|
||||
case FLOAT32:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
quint32 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
qToLittleEndian<quint32>(value, &dataOut[numBytesPerElement*index]);
|
||||
}
|
||||
break;
|
||||
case ENUM:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
dataOut[numBytesPerElement*index] = data[offset + numBytesPerElement*index];
|
||||
}
|
||||
break;
|
||||
case STRING:
|
||||
memcpy(dataOut, &data[offset], numElements);
|
||||
break;
|
||||
}
|
||||
// Done
|
||||
return getNumBytes();
|
||||
}
|
||||
|
||||
qint32 UAVObjectField::unpack(const quint8* dataIn)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Unpack each element from input buffer
|
||||
switch (type)
|
||||
{
|
||||
case INT8:
|
||||
memcpy(&data[offset], dataIn, numElements);
|
||||
break;
|
||||
case INT16:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
qint16 value;
|
||||
value = qFromLittleEndian<qint16>(&dataIn[numBytesPerElement*index]);
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
break;
|
||||
case INT32:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
qint32 value;
|
||||
value = qFromLittleEndian<qint32>(&dataIn[numBytesPerElement*index]);
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
break;
|
||||
case UINT8:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
data[offset + numBytesPerElement*index] = dataIn[numBytesPerElement*index];
|
||||
}
|
||||
break;
|
||||
case UINT16:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
quint16 value;
|
||||
value = qFromLittleEndian<quint16>(&dataIn[numBytesPerElement*index]);
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
break;
|
||||
case UINT32:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
quint32 value;
|
||||
value = qFromLittleEndian<quint32>(&dataIn[numBytesPerElement*index]);
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
break;
|
||||
case FLOAT32:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
quint32 value;
|
||||
value = qFromLittleEndian<quint32>(&dataIn[numBytesPerElement*index]);
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
break;
|
||||
case ENUM:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
data[offset + numBytesPerElement*index] = dataIn[numBytesPerElement*index];
|
||||
}
|
||||
break;
|
||||
case STRING:
|
||||
memcpy(&data[offset], dataIn, numElements);
|
||||
break;
|
||||
}
|
||||
// Done
|
||||
return getNumBytes();
|
||||
}
|
||||
|
||||
quint32 UAVObjectField::getNumBytesElement()
|
||||
{
|
||||
return numBytesPerElement;
|
||||
}
|
||||
|
||||
bool UAVObjectField::isNumeric()
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case INT8:
|
||||
return true;
|
||||
break;
|
||||
case INT16:
|
||||
return true;
|
||||
break;
|
||||
case INT32:
|
||||
return true;
|
||||
break;
|
||||
case UINT8:
|
||||
return true;
|
||||
break;
|
||||
case UINT16:
|
||||
return true;
|
||||
break;
|
||||
case UINT32:
|
||||
return true;
|
||||
break;
|
||||
case FLOAT32:
|
||||
return true;
|
||||
break;
|
||||
case ENUM:
|
||||
return false;
|
||||
break;
|
||||
case STRING:
|
||||
return false;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool UAVObjectField::isText()
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case INT8:
|
||||
return false;
|
||||
break;
|
||||
case INT16:
|
||||
return false;
|
||||
break;
|
||||
case INT32:
|
||||
return false;
|
||||
break;
|
||||
case UINT8:
|
||||
return false;
|
||||
break;
|
||||
case UINT16:
|
||||
return false;
|
||||
break;
|
||||
case UINT32:
|
||||
return false;
|
||||
break;
|
||||
case FLOAT32:
|
||||
return false;
|
||||
break;
|
||||
case ENUM:
|
||||
return true;
|
||||
break;
|
||||
case STRING:
|
||||
return true;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
QVariant UAVObjectField::getValue(quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check that index is not out of bounds
|
||||
if ( index >= numElements )
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
// Get value
|
||||
switch (type)
|
||||
{
|
||||
case INT8:
|
||||
{
|
||||
qint8 tmpint8;
|
||||
memcpy(&tmpint8, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return QVariant(tmpint8);
|
||||
break;
|
||||
}
|
||||
case INT16:
|
||||
{
|
||||
qint16 tmpint16;
|
||||
memcpy(&tmpint16, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return QVariant(tmpint16);
|
||||
break;
|
||||
}
|
||||
case INT32:
|
||||
{
|
||||
qint32 tmpint32;
|
||||
memcpy(&tmpint32, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return QVariant(tmpint32);
|
||||
break;
|
||||
}
|
||||
case UINT8:
|
||||
{
|
||||
quint8 tmpuint8;
|
||||
memcpy(&tmpuint8, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return QVariant(tmpuint8);
|
||||
break;
|
||||
}
|
||||
case UINT16:
|
||||
{
|
||||
quint16 tmpuint16;
|
||||
memcpy(&tmpuint16, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return QVariant(tmpuint16);
|
||||
break;
|
||||
}
|
||||
case UINT32:
|
||||
{
|
||||
quint32 tmpuint32;
|
||||
memcpy(&tmpuint32, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return QVariant(tmpuint32);
|
||||
break;
|
||||
}
|
||||
case FLOAT32:
|
||||
{
|
||||
float tmpfloat;
|
||||
memcpy(&tmpfloat, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return QVariant(tmpfloat);
|
||||
break;
|
||||
}
|
||||
case ENUM:
|
||||
{
|
||||
quint8 tmpenum;
|
||||
memcpy(&tmpenum, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return QVariant( options[tmpenum] );
|
||||
break;
|
||||
}
|
||||
case STRING:
|
||||
{
|
||||
data[offset + numElements - 1] = '\0';
|
||||
QString str((char*)&data[offset]);
|
||||
return QVariant( str );
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If this point is reached then we got an invalid type
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void UAVObjectField::setValue(const QVariant& value, quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check that index is not out of bounds
|
||||
if ( index >= numElements )
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Get metadata
|
||||
UAVObject::Metadata mdata = obj->getMetadata();
|
||||
// Update value if the access mode permits
|
||||
if ( mdata.gcsAccess == UAVObject::ACCESS_READWRITE )
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case INT8:
|
||||
{
|
||||
qint8 tmpint8 = value.toInt();
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpint8, numBytesPerElement);
|
||||
break;
|
||||
}
|
||||
case INT16:
|
||||
{
|
||||
qint16 tmpint16 = value.toInt();
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpint16, numBytesPerElement);
|
||||
break;
|
||||
}
|
||||
case INT32:
|
||||
{
|
||||
qint32 tmpint32 = value.toInt();
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpint32, numBytesPerElement);
|
||||
break;
|
||||
}
|
||||
case UINT8:
|
||||
{
|
||||
quint8 tmpuint8 = value.toUInt();
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpuint8, numBytesPerElement);
|
||||
break;
|
||||
}
|
||||
case UINT16:
|
||||
{
|
||||
quint16 tmpuint16 = value.toUInt();
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpuint16, numBytesPerElement);
|
||||
break;
|
||||
}
|
||||
case UINT32:
|
||||
{
|
||||
quint32 tmpuint32 = value.toUInt();
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpuint32, numBytesPerElement);
|
||||
break;
|
||||
}
|
||||
case FLOAT32:
|
||||
{
|
||||
float tmpfloat = value.toFloat();
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpfloat, numBytesPerElement);
|
||||
break;
|
||||
}
|
||||
case ENUM:
|
||||
{
|
||||
qint8 tmpenum = options.indexOf( value.toString() );
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpenum, numBytesPerElement);
|
||||
break;
|
||||
}
|
||||
case STRING:
|
||||
{
|
||||
QString str = value.toString();
|
||||
QByteArray barray = str.toAscii();
|
||||
quint32 index;
|
||||
for (index = 0; index < (quint32)barray.length() && index < (numElements-1); ++index)
|
||||
{
|
||||
data[offset+index] = barray[index];
|
||||
}
|
||||
barray[index] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double UAVObjectField::getDouble(quint32 index)
|
||||
{
|
||||
return getValue().toDouble();
|
||||
}
|
||||
|
||||
void UAVObjectField::setDouble(double value, quint32 index)
|
||||
{
|
||||
setValue(QVariant(value));
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectfield.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectsplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavobjectfield.h"
|
||||
#include <QtEndian>
|
||||
|
||||
UAVObjectField::UAVObjectField(const QString& name, const QString& units, FieldType type, quint32 numElements, const QStringList& options)
|
||||
{
|
||||
QStringList elementNames;
|
||||
// Set element names
|
||||
for (quint32 n = 0; n < numElements; ++n)
|
||||
{
|
||||
elementNames.append(QString("%1").arg(n));
|
||||
}
|
||||
// Initialize
|
||||
constructorInitialize(name, units, type, elementNames, options);
|
||||
|
||||
}
|
||||
|
||||
UAVObjectField::UAVObjectField(const QString& name, const QString& units, FieldType type, const QStringList& elementNames, const QStringList& options)
|
||||
{
|
||||
constructorInitialize(name, units, type, elementNames, options);
|
||||
}
|
||||
|
||||
void UAVObjectField::constructorInitialize(const QString& name, const QString& units, FieldType type, const QStringList& elementNames, const QStringList& options)
|
||||
{
|
||||
// Copy params
|
||||
this->name = name;
|
||||
this->units = units;
|
||||
this->type = type;
|
||||
this->options = options;
|
||||
this->numElements = elementNames.length();
|
||||
this->offset = 0;
|
||||
this->data = NULL;
|
||||
this->obj = NULL;
|
||||
this->elementNames = elementNames;
|
||||
// Set field size
|
||||
switch (type)
|
||||
{
|
||||
case INT8:
|
||||
numBytesPerElement = sizeof(qint8);
|
||||
break;
|
||||
case INT16:
|
||||
numBytesPerElement = sizeof(qint16);
|
||||
break;
|
||||
case INT32:
|
||||
numBytesPerElement = sizeof(qint32);
|
||||
break;
|
||||
case UINT8:
|
||||
numBytesPerElement = sizeof(quint8);
|
||||
break;
|
||||
case UINT16:
|
||||
numBytesPerElement = sizeof(quint16);
|
||||
break;
|
||||
case UINT32:
|
||||
numBytesPerElement = sizeof(quint32);
|
||||
break;
|
||||
case FLOAT32:
|
||||
numBytesPerElement = sizeof(quint32);
|
||||
break;
|
||||
case ENUM:
|
||||
numBytesPerElement = sizeof(quint8);
|
||||
break;
|
||||
case STRING:
|
||||
numBytesPerElement = sizeof(quint8);
|
||||
break;
|
||||
default:
|
||||
numBytesPerElement = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void UAVObjectField::initialize(quint8* data, quint32 dataOffset, UAVObject* obj)
|
||||
{
|
||||
this->data = data;
|
||||
this->offset = dataOffset;
|
||||
this->obj = obj;
|
||||
clear();
|
||||
}
|
||||
|
||||
UAVObjectField::FieldType UAVObjectField::getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
QStringList UAVObjectField::getElementNames()
|
||||
{
|
||||
return elementNames;
|
||||
}
|
||||
|
||||
UAVObject* UAVObjectField::getObject()
|
||||
{
|
||||
return obj;
|
||||
}
|
||||
|
||||
void UAVObjectField::clear()
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
memset(&data[offset], 0, numBytesPerElement*numElements);
|
||||
}
|
||||
|
||||
QString UAVObjectField::getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
QString UAVObjectField::getUnits()
|
||||
{
|
||||
return units;
|
||||
}
|
||||
|
||||
QStringList UAVObjectField::getOptions()
|
||||
{
|
||||
return options;
|
||||
}
|
||||
|
||||
quint32 UAVObjectField::getNumElements()
|
||||
{
|
||||
return numElements;
|
||||
}
|
||||
|
||||
quint32 UAVObjectField::getDataOffset()
|
||||
{
|
||||
return offset;
|
||||
}
|
||||
|
||||
quint32 UAVObjectField::getNumBytes()
|
||||
{
|
||||
return numBytesPerElement * numElements;
|
||||
}
|
||||
|
||||
QString UAVObjectField::toString()
|
||||
{
|
||||
QString sout;
|
||||
sout.append ( QString("%1: [ ").arg(name) );
|
||||
for (unsigned int n = 0; n < numElements; ++n)
|
||||
{
|
||||
sout.append( QString("%1 ").arg(getDouble(n)) );
|
||||
}
|
||||
sout.append( QString("] %1\n").arg(units) );
|
||||
return sout;
|
||||
}
|
||||
|
||||
|
||||
qint32 UAVObjectField::pack(quint8* dataOut)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Pack each element in output buffer
|
||||
switch (type)
|
||||
{
|
||||
case INT8:
|
||||
memcpy(dataOut, &data[offset], numElements);
|
||||
break;
|
||||
case INT16:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
qint16 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
qToLittleEndian<qint16>(value, &dataOut[numBytesPerElement*index]);
|
||||
}
|
||||
break;
|
||||
case INT32:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
qint32 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
qToLittleEndian<qint32>(value, &dataOut[numBytesPerElement*index]);
|
||||
}
|
||||
break;
|
||||
case UINT8:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
dataOut[numBytesPerElement*index] = data[offset + numBytesPerElement*index];
|
||||
}
|
||||
break;
|
||||
case UINT16:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
quint16 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
qToLittleEndian<quint16>(value, &dataOut[numBytesPerElement*index]);
|
||||
}
|
||||
break;
|
||||
case UINT32:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
quint32 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
qToLittleEndian<quint32>(value, &dataOut[numBytesPerElement*index]);
|
||||
}
|
||||
break;
|
||||
case FLOAT32:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
quint32 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
qToLittleEndian<quint32>(value, &dataOut[numBytesPerElement*index]);
|
||||
}
|
||||
break;
|
||||
case ENUM:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
dataOut[numBytesPerElement*index] = data[offset + numBytesPerElement*index];
|
||||
}
|
||||
break;
|
||||
case STRING:
|
||||
memcpy(dataOut, &data[offset], numElements);
|
||||
break;
|
||||
}
|
||||
// Done
|
||||
return getNumBytes();
|
||||
}
|
||||
|
||||
qint32 UAVObjectField::unpack(const quint8* dataIn)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Unpack each element from input buffer
|
||||
switch (type)
|
||||
{
|
||||
case INT8:
|
||||
memcpy(&data[offset], dataIn, numElements);
|
||||
break;
|
||||
case INT16:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
qint16 value;
|
||||
value = qFromLittleEndian<qint16>(&dataIn[numBytesPerElement*index]);
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
break;
|
||||
case INT32:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
qint32 value;
|
||||
value = qFromLittleEndian<qint32>(&dataIn[numBytesPerElement*index]);
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
break;
|
||||
case UINT8:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
data[offset + numBytesPerElement*index] = dataIn[numBytesPerElement*index];
|
||||
}
|
||||
break;
|
||||
case UINT16:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
quint16 value;
|
||||
value = qFromLittleEndian<quint16>(&dataIn[numBytesPerElement*index]);
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
break;
|
||||
case UINT32:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
quint32 value;
|
||||
value = qFromLittleEndian<quint32>(&dataIn[numBytesPerElement*index]);
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
break;
|
||||
case FLOAT32:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
quint32 value;
|
||||
value = qFromLittleEndian<quint32>(&dataIn[numBytesPerElement*index]);
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
break;
|
||||
case ENUM:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
data[offset + numBytesPerElement*index] = dataIn[numBytesPerElement*index];
|
||||
}
|
||||
break;
|
||||
case STRING:
|
||||
memcpy(&data[offset], dataIn, numElements);
|
||||
break;
|
||||
}
|
||||
// Done
|
||||
return getNumBytes();
|
||||
}
|
||||
|
||||
quint32 UAVObjectField::getNumBytesElement()
|
||||
{
|
||||
return numBytesPerElement;
|
||||
}
|
||||
|
||||
bool UAVObjectField::isNumeric()
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case INT8:
|
||||
return true;
|
||||
break;
|
||||
case INT16:
|
||||
return true;
|
||||
break;
|
||||
case INT32:
|
||||
return true;
|
||||
break;
|
||||
case UINT8:
|
||||
return true;
|
||||
break;
|
||||
case UINT16:
|
||||
return true;
|
||||
break;
|
||||
case UINT32:
|
||||
return true;
|
||||
break;
|
||||
case FLOAT32:
|
||||
return true;
|
||||
break;
|
||||
case ENUM:
|
||||
return false;
|
||||
break;
|
||||
case STRING:
|
||||
return false;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool UAVObjectField::isText()
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case INT8:
|
||||
return false;
|
||||
break;
|
||||
case INT16:
|
||||
return false;
|
||||
break;
|
||||
case INT32:
|
||||
return false;
|
||||
break;
|
||||
case UINT8:
|
||||
return false;
|
||||
break;
|
||||
case UINT16:
|
||||
return false;
|
||||
break;
|
||||
case UINT32:
|
||||
return false;
|
||||
break;
|
||||
case FLOAT32:
|
||||
return false;
|
||||
break;
|
||||
case ENUM:
|
||||
return true;
|
||||
break;
|
||||
case STRING:
|
||||
return true;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
QVariant UAVObjectField::getValue(quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check that index is not out of bounds
|
||||
if ( index >= numElements )
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
// Get value
|
||||
switch (type)
|
||||
{
|
||||
case INT8:
|
||||
{
|
||||
qint8 tmpint8;
|
||||
memcpy(&tmpint8, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return QVariant(tmpint8);
|
||||
break;
|
||||
}
|
||||
case INT16:
|
||||
{
|
||||
qint16 tmpint16;
|
||||
memcpy(&tmpint16, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return QVariant(tmpint16);
|
||||
break;
|
||||
}
|
||||
case INT32:
|
||||
{
|
||||
qint32 tmpint32;
|
||||
memcpy(&tmpint32, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return QVariant(tmpint32);
|
||||
break;
|
||||
}
|
||||
case UINT8:
|
||||
{
|
||||
quint8 tmpuint8;
|
||||
memcpy(&tmpuint8, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return QVariant(tmpuint8);
|
||||
break;
|
||||
}
|
||||
case UINT16:
|
||||
{
|
||||
quint16 tmpuint16;
|
||||
memcpy(&tmpuint16, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return QVariant(tmpuint16);
|
||||
break;
|
||||
}
|
||||
case UINT32:
|
||||
{
|
||||
quint32 tmpuint32;
|
||||
memcpy(&tmpuint32, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return QVariant(tmpuint32);
|
||||
break;
|
||||
}
|
||||
case FLOAT32:
|
||||
{
|
||||
float tmpfloat;
|
||||
memcpy(&tmpfloat, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return QVariant(tmpfloat);
|
||||
break;
|
||||
}
|
||||
case ENUM:
|
||||
{
|
||||
quint8 tmpenum;
|
||||
memcpy(&tmpenum, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return QVariant( options[tmpenum] );
|
||||
break;
|
||||
}
|
||||
case STRING:
|
||||
{
|
||||
data[offset + numElements - 1] = '\0';
|
||||
QString str((char*)&data[offset]);
|
||||
return QVariant( str );
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If this point is reached then we got an invalid type
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void UAVObjectField::setValue(const QVariant& value, quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check that index is not out of bounds
|
||||
if ( index >= numElements )
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Get metadata
|
||||
UAVObject::Metadata mdata = obj->getMetadata();
|
||||
// Update value if the access mode permits
|
||||
if ( mdata.gcsAccess == UAVObject::ACCESS_READWRITE )
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case INT8:
|
||||
{
|
||||
qint8 tmpint8 = value.toInt();
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpint8, numBytesPerElement);
|
||||
break;
|
||||
}
|
||||
case INT16:
|
||||
{
|
||||
qint16 tmpint16 = value.toInt();
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpint16, numBytesPerElement);
|
||||
break;
|
||||
}
|
||||
case INT32:
|
||||
{
|
||||
qint32 tmpint32 = value.toInt();
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpint32, numBytesPerElement);
|
||||
break;
|
||||
}
|
||||
case UINT8:
|
||||
{
|
||||
quint8 tmpuint8 = value.toUInt();
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpuint8, numBytesPerElement);
|
||||
break;
|
||||
}
|
||||
case UINT16:
|
||||
{
|
||||
quint16 tmpuint16 = value.toUInt();
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpuint16, numBytesPerElement);
|
||||
break;
|
||||
}
|
||||
case UINT32:
|
||||
{
|
||||
quint32 tmpuint32 = value.toUInt();
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpuint32, numBytesPerElement);
|
||||
break;
|
||||
}
|
||||
case FLOAT32:
|
||||
{
|
||||
float tmpfloat = value.toFloat();
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpfloat, numBytesPerElement);
|
||||
break;
|
||||
}
|
||||
case ENUM:
|
||||
{
|
||||
qint8 tmpenum = options.indexOf( value.toString() );
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpenum, numBytesPerElement);
|
||||
break;
|
||||
}
|
||||
case STRING:
|
||||
{
|
||||
QString str = value.toString();
|
||||
QByteArray barray = str.toAscii();
|
||||
quint32 index;
|
||||
for (index = 0; index < (quint32)barray.length() && index < (numElements-1); ++index)
|
||||
{
|
||||
data[offset+index] = barray[index];
|
||||
}
|
||||
barray[index] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double UAVObjectField::getDouble(quint32 index)
|
||||
{
|
||||
return getValue().toDouble();
|
||||
}
|
||||
|
||||
void UAVObjectField::setDouble(double value, quint32 index)
|
||||
{
|
||||
setValue(QVariant(value));
|
||||
}
|
||||
|
||||
|
@ -1,89 +1,88 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectfield.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef UAVOBJECTFIELD_H
|
||||
#define UAVOBJECTFIELD_H
|
||||
|
||||
#include "uavobjects_global.h"
|
||||
#include "uavobject.h"
|
||||
#include <QStringList>
|
||||
#include <QVariant>
|
||||
|
||||
class UAVObject;
|
||||
|
||||
class UAVOBJECTS_EXPORT UAVObjectField: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
typedef enum { INT8 = 0, INT16, INT32, UINT8, UINT16, UINT32, FLOAT32, ENUM, STRING } FieldType;
|
||||
|
||||
UAVObjectField(const QString& name, const QString& units, FieldType type, quint32 numElements, const QStringList& options);
|
||||
UAVObjectField(const QString& name, const QString& units, FieldType type, const QStringList& elementNames, const QStringList& options);
|
||||
void initialize(quint8* data, quint32 dataOffset, UAVObject* obj);
|
||||
UAVObject* getObject();
|
||||
FieldType getType();
|
||||
QString getName();
|
||||
QString getUnits();
|
||||
quint32 getNumElements();
|
||||
QStringList getElementNames();
|
||||
QStringList getOptions();
|
||||
qint32 pack(quint8* dataOut);
|
||||
qint32 unpack(const quint8* dataIn);
|
||||
QVariant getValue(quint32 index = 0);
|
||||
void setValue(const QVariant& data, quint32 index = 0);
|
||||
double getDouble(quint32 index = 0);
|
||||
void setDouble(double value, quint32 index = 0);
|
||||
quint32 getDataOffset();
|
||||
quint32 getNumBytes();
|
||||
quint32 getNumBytesElement();
|
||||
bool isNumeric();
|
||||
bool isText();
|
||||
QString toString();
|
||||
|
||||
signals:
|
||||
void fieldUpdated(UAVObjectField* field);
|
||||
|
||||
protected:
|
||||
QString name;
|
||||
QString units;
|
||||
FieldType type;
|
||||
QStringList elementNames;
|
||||
QStringList options;
|
||||
quint32 numElements;
|
||||
quint32 numBytesPerElement;
|
||||
quint32 offset;
|
||||
quint8* data;
|
||||
UAVObject* obj;
|
||||
|
||||
void clear();
|
||||
void constructorInitialize(const QString& name, const QString& units, FieldType type, const QStringList& elementNames, const QStringList& options);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // UAVOBJECTFIELD_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectfield.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectsplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef UAVOBJECTFIELD_H
|
||||
#define UAVOBJECTFIELD_H
|
||||
|
||||
#include "uavobjects_global.h"
|
||||
#include "uavobject.h"
|
||||
#include <QStringList>
|
||||
#include <QVariant>
|
||||
|
||||
class UAVObject;
|
||||
|
||||
class UAVOBJECTS_EXPORT UAVObjectField: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
typedef enum { INT8 = 0, INT16, INT32, UINT8, UINT16, UINT32, FLOAT32, ENUM, STRING } FieldType;
|
||||
|
||||
UAVObjectField(const QString& name, const QString& units, FieldType type, quint32 numElements, const QStringList& options);
|
||||
UAVObjectField(const QString& name, const QString& units, FieldType type, const QStringList& elementNames, const QStringList& options);
|
||||
void initialize(quint8* data, quint32 dataOffset, UAVObject* obj);
|
||||
UAVObject* getObject();
|
||||
FieldType getType();
|
||||
QString getName();
|
||||
QString getUnits();
|
||||
quint32 getNumElements();
|
||||
QStringList getElementNames();
|
||||
QStringList getOptions();
|
||||
qint32 pack(quint8* dataOut);
|
||||
qint32 unpack(const quint8* dataIn);
|
||||
QVariant getValue(quint32 index = 0);
|
||||
void setValue(const QVariant& data, quint32 index = 0);
|
||||
double getDouble(quint32 index = 0);
|
||||
void setDouble(double value, quint32 index = 0);
|
||||
quint32 getDataOffset();
|
||||
quint32 getNumBytes();
|
||||
quint32 getNumBytesElement();
|
||||
bool isNumeric();
|
||||
bool isText();
|
||||
QString toString();
|
||||
|
||||
signals:
|
||||
void fieldUpdated(UAVObjectField* field);
|
||||
|
||||
protected:
|
||||
QString name;
|
||||
QString units;
|
||||
FieldType type;
|
||||
QStringList elementNames;
|
||||
QStringList options;
|
||||
quint32 numElements;
|
||||
quint32 numBytesPerElement;
|
||||
quint32 offset;
|
||||
quint8* data;
|
||||
UAVObject* obj;
|
||||
|
||||
void clear();
|
||||
void constructorInitialize(const QString& name, const QString& units, FieldType type, const QStringList& elementNames, const QStringList& options);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // UAVOBJECTFIELD_H
|
||||
|
@ -1,340 +1,339 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectmanager.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavobjectmanager.h"
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
UAVObjectManager::UAVObjectManager()
|
||||
{
|
||||
mutex = new QMutex(QMutex::Recursive);
|
||||
}
|
||||
|
||||
UAVObjectManager::~UAVObjectManager()
|
||||
{
|
||||
delete mutex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an object with the manager. This function must be called for all newly created instances.
|
||||
* A new instance can be created directly by instantiating a new object or by calling clone() of
|
||||
* an existing object. The object will be registered and will be properly initialized so that it can accept
|
||||
* updates.
|
||||
*/
|
||||
bool UAVObjectManager::registerObject(UAVDataObject* obj)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
// Check if this object type is already in the list
|
||||
for (int objidx = 0; objidx < objects.length(); ++objidx)
|
||||
{
|
||||
// Check if the object ID is in the list
|
||||
if (objects[objidx].length() > 0 && objects[objidx][0]->getObjID() == obj->getObjID())
|
||||
{
|
||||
// Check if this is a single instance object, if yes we can not add a new instance
|
||||
if (obj->isSingleInstance())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// The object type has alredy been added, so now we need to initialize the new instance with the appropriate id
|
||||
// There is a single metaobject for all object instances of this type, so no need to create a new one
|
||||
// Get object type metaobject from existing instance
|
||||
UAVDataObject* refObj = dynamic_cast<UAVDataObject*>(objects[objidx][0]);
|
||||
if (refObj == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
UAVMetaObject* mobj = refObj->getMetaObject();
|
||||
// If the instance ID is specified and not at the default value (0) then we need to make sure
|
||||
// that there are no gaps in the instance list. If gaps are found then then additional instances
|
||||
// will be created.
|
||||
if ( (obj->getInstID() > 0) && (obj->getInstID() < MAX_INSTANCES) )
|
||||
{
|
||||
for (int instidx = 0; instidx < objects[objidx].length(); ++instidx)
|
||||
{
|
||||
if ( objects[objidx][instidx]->getInstID() == obj->getInstID() )
|
||||
{
|
||||
// Instance conflict, do not add
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Check if there are any gaps between the requested instance ID and the ones in the list,
|
||||
// if any then create the missing instances.
|
||||
for (quint32 instidx = objects[objidx].length(); instidx < obj->getInstID(); ++instidx)
|
||||
{
|
||||
UAVDataObject* cobj = obj->clone(instidx);
|
||||
cobj->initialize(mobj);
|
||||
objects[objidx].append(cobj);
|
||||
emit newInstance(cobj);
|
||||
}
|
||||
// Finally, initialize the actual object instance
|
||||
obj->initialize(mobj);
|
||||
}
|
||||
else if (obj->getInstID() == 0)
|
||||
{
|
||||
// Assign the next available ID and initialize the object instance
|
||||
obj->initialize(objects[objidx].length(), mobj);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// Add the actual object instance in the list
|
||||
objects[objidx].append(obj);
|
||||
emit newInstance(obj);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// If this point is reached then this is the first time this object type (ID) is added in the list
|
||||
// create a new list of the instances, add in the object collection and create the object's metaobject
|
||||
// Create metaobject
|
||||
QString mname = obj->getName();
|
||||
mname.append("Meta");
|
||||
UAVMetaObject* mobj = new UAVMetaObject(obj->getObjID()+1, mname, obj);
|
||||
// Initialize object
|
||||
obj->initialize(0, mobj);
|
||||
// Add to list
|
||||
addObject(obj);
|
||||
addObject(mobj);
|
||||
return true;
|
||||
}
|
||||
|
||||
void UAVObjectManager::addObject(UAVObject* obj)
|
||||
{
|
||||
// Add to list
|
||||
QList<UAVObject*> list;
|
||||
list.append(obj);
|
||||
objects.append(list);
|
||||
emit newObject(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all objects. A two dimentional QList is returned. Objects are grouped by
|
||||
* instances of the same object type.
|
||||
*/
|
||||
QList< QList<UAVObject*> > UAVObjectManager::getObjects()
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
return objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as getObjects() but will only return DataObjects.
|
||||
*/
|
||||
QList< QList<UAVDataObject*> > UAVObjectManager::getDataObjects()
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
QList< QList<UAVDataObject*> > dObjects;
|
||||
|
||||
// Go through objects and copy to new list when types match
|
||||
for (int objidx = 0; objidx < objects.length(); ++objidx)
|
||||
{
|
||||
if (objects[objidx].length() > 0)
|
||||
{
|
||||
// Check type
|
||||
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(objects[objidx][0]);
|
||||
if (obj != NULL)
|
||||
{
|
||||
// Create instance list
|
||||
QList<UAVDataObject*> list;
|
||||
// Go through instances and cast them to UAVDataObject, then add to list
|
||||
for (int instidx = 0; instidx < objects[objidx].length(); ++instidx)
|
||||
{
|
||||
obj = dynamic_cast<UAVDataObject*>(objects[objidx][instidx]);
|
||||
if (obj != NULL)
|
||||
{
|
||||
list.append(obj);
|
||||
}
|
||||
}
|
||||
// Append to object list
|
||||
dObjects.append(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Done
|
||||
return dObjects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as getObjects() but will only return MetaObjects.
|
||||
*/
|
||||
QList <QList<UAVMetaObject*> > UAVObjectManager::getMetaObjects()
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
QList< QList<UAVMetaObject*> > mObjects;
|
||||
|
||||
// Go through objects and copy to new list when types match
|
||||
for (int objidx = 0; objidx < objects.length(); ++objidx)
|
||||
{
|
||||
if (objects[objidx].length() > 0)
|
||||
{
|
||||
// Check type
|
||||
UAVMetaObject* obj = dynamic_cast<UAVMetaObject*>(objects[objidx][0]);
|
||||
if (obj != NULL)
|
||||
{
|
||||
// Create instance list
|
||||
QList<UAVMetaObject*> list;
|
||||
// Go through instances and cast them to UAVMetaObject, then add to list
|
||||
for (int instidx = 0; instidx < objects[objidx].length(); ++instidx)
|
||||
{
|
||||
obj = dynamic_cast<UAVMetaObject*>(objects[objidx][instidx]);
|
||||
if (obj != NULL)
|
||||
{
|
||||
list.append(obj);
|
||||
}
|
||||
}
|
||||
// Append to object list
|
||||
mObjects.append(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Done
|
||||
return mObjects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific object given its name and instance ID
|
||||
* @returns The object is found or NULL if not
|
||||
*/
|
||||
UAVObject* UAVObjectManager::getObject(const QString& name, quint32 instId)
|
||||
{
|
||||
return getObject(&name, 0, instId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific object given its object and instance ID
|
||||
* @returns The object is found or NULL if not
|
||||
*/
|
||||
UAVObject* UAVObjectManager::getObject(quint32 objId, quint32 instId)
|
||||
{
|
||||
return getObject(NULL, objId, instId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for the public getObject() functions.
|
||||
*/
|
||||
UAVObject* UAVObjectManager::getObject(const QString* name, quint32 objId, quint32 instId)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
// Check if this object type is already in the list
|
||||
for (int objidx = 0; objidx < objects.length(); ++objidx)
|
||||
{
|
||||
// Check if the object ID is in the list
|
||||
if (objects[objidx].length() > 0)
|
||||
{
|
||||
if ( (name != NULL && objects[objidx][0]->getName().compare(name) == 0) || (name == NULL && objects[objidx][0]->getObjID() == objId) )
|
||||
{
|
||||
// Look for the requested instance ID
|
||||
for (int instidx = 0; instidx < objects[objidx].length(); ++instidx)
|
||||
{
|
||||
if (objects[objidx][instidx]->getInstID() == instId)
|
||||
{
|
||||
return objects[objidx][instidx];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// If this point is reached then the requested object could not be found
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the instances of the object specified by name
|
||||
*/
|
||||
QList<UAVObject*> UAVObjectManager::getObjectInstances(const QString& name)
|
||||
{
|
||||
return getObjectInstances(&name, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the instances of the object specified by its ID
|
||||
*/
|
||||
QList<UAVObject*> UAVObjectManager::getObjectInstances(quint32 objId)
|
||||
{
|
||||
return getObjectInstances(NULL, objId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for the public getObjectInstances()
|
||||
*/
|
||||
QList<UAVObject*> UAVObjectManager::getObjectInstances(const QString* name, quint32 objId)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
// Check if this object type is already in the list
|
||||
for (int objidx = 0; objidx < objects.length(); ++objidx)
|
||||
{
|
||||
// Check if the object ID is in the list
|
||||
if (objects[objidx].length() > 0)
|
||||
{
|
||||
if ( (name != NULL && objects[objidx][0]->getName().compare(name) == 0) || (name == NULL && objects[objidx][0]->getObjID() == objId) )
|
||||
{
|
||||
return objects[objidx];
|
||||
}
|
||||
}
|
||||
}
|
||||
// If this point is reached then the requested object could not be found
|
||||
return QList<UAVObject*>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of instances for an object given its name
|
||||
*/
|
||||
qint32 UAVObjectManager::getNumInstances(const QString& name)
|
||||
{
|
||||
return getNumInstances(&name, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of instances for an object given its ID
|
||||
*/
|
||||
qint32 UAVObjectManager::getNumInstances(quint32 objId)
|
||||
{
|
||||
return getNumInstances(NULL, objId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for public getNumInstances
|
||||
*/
|
||||
qint32 UAVObjectManager::getNumInstances(const QString* name, quint32 objId)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
// Check if this object type is already in the list
|
||||
for (int objidx = 0; objidx < objects.length(); ++objidx)
|
||||
{
|
||||
// Check if the object ID is in the list
|
||||
if (objects[objidx].length() > 0)
|
||||
{
|
||||
if ( (name != NULL && objects[objidx][0]->getName().compare(name) == 0) || (name == NULL && objects[objidx][0]->getObjID() == objId) )
|
||||
{
|
||||
return objects[objidx].length();
|
||||
}
|
||||
}
|
||||
}
|
||||
// If this point is reached then the requested object could not be found
|
||||
return -1;
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectmanager.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectsplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavobjectmanager.h"
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
UAVObjectManager::UAVObjectManager()
|
||||
{
|
||||
mutex = new QMutex(QMutex::Recursive);
|
||||
}
|
||||
|
||||
UAVObjectManager::~UAVObjectManager()
|
||||
{
|
||||
delete mutex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an object with the manager. This function must be called for all newly created instances.
|
||||
* A new instance can be created directly by instantiating a new object or by calling clone() of
|
||||
* an existing object. The object will be registered and will be properly initialized so that it can accept
|
||||
* updates.
|
||||
*/
|
||||
bool UAVObjectManager::registerObject(UAVDataObject* obj)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
// Check if this object type is already in the list
|
||||
for (int objidx = 0; objidx < objects.length(); ++objidx)
|
||||
{
|
||||
// Check if the object ID is in the list
|
||||
if (objects[objidx].length() > 0 && objects[objidx][0]->getObjID() == obj->getObjID())
|
||||
{
|
||||
// Check if this is a single instance object, if yes we can not add a new instance
|
||||
if (obj->isSingleInstance())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// The object type has alredy been added, so now we need to initialize the new instance with the appropriate id
|
||||
// There is a single metaobject for all object instances of this type, so no need to create a new one
|
||||
// Get object type metaobject from existing instance
|
||||
UAVDataObject* refObj = dynamic_cast<UAVDataObject*>(objects[objidx][0]);
|
||||
if (refObj == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
UAVMetaObject* mobj = refObj->getMetaObject();
|
||||
// If the instance ID is specified and not at the default value (0) then we need to make sure
|
||||
// that there are no gaps in the instance list. If gaps are found then then additional instances
|
||||
// will be created.
|
||||
if ( (obj->getInstID() > 0) && (obj->getInstID() < MAX_INSTANCES) )
|
||||
{
|
||||
for (int instidx = 0; instidx < objects[objidx].length(); ++instidx)
|
||||
{
|
||||
if ( objects[objidx][instidx]->getInstID() == obj->getInstID() )
|
||||
{
|
||||
// Instance conflict, do not add
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Check if there are any gaps between the requested instance ID and the ones in the list,
|
||||
// if any then create the missing instances.
|
||||
for (quint32 instidx = objects[objidx].length(); instidx < obj->getInstID(); ++instidx)
|
||||
{
|
||||
UAVDataObject* cobj = obj->clone(instidx);
|
||||
cobj->initialize(mobj);
|
||||
objects[objidx].append(cobj);
|
||||
emit newInstance(cobj);
|
||||
}
|
||||
// Finally, initialize the actual object instance
|
||||
obj->initialize(mobj);
|
||||
}
|
||||
else if (obj->getInstID() == 0)
|
||||
{
|
||||
// Assign the next available ID and initialize the object instance
|
||||
obj->initialize(objects[objidx].length(), mobj);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// Add the actual object instance in the list
|
||||
objects[objidx].append(obj);
|
||||
emit newInstance(obj);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// If this point is reached then this is the first time this object type (ID) is added in the list
|
||||
// create a new list of the instances, add in the object collection and create the object's metaobject
|
||||
// Create metaobject
|
||||
QString mname = obj->getName();
|
||||
mname.append("Meta");
|
||||
UAVMetaObject* mobj = new UAVMetaObject(obj->getObjID()+1, mname, obj);
|
||||
// Initialize object
|
||||
obj->initialize(0, mobj);
|
||||
// Add to list
|
||||
addObject(obj);
|
||||
addObject(mobj);
|
||||
return true;
|
||||
}
|
||||
|
||||
void UAVObjectManager::addObject(UAVObject* obj)
|
||||
{
|
||||
// Add to list
|
||||
QList<UAVObject*> list;
|
||||
list.append(obj);
|
||||
objects.append(list);
|
||||
emit newObject(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all objects. A two dimentional QList is returned. Objects are grouped by
|
||||
* instances of the same object type.
|
||||
*/
|
||||
QList< QList<UAVObject*> > UAVObjectManager::getObjects()
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
return objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as getObjects() but will only return DataObjects.
|
||||
*/
|
||||
QList< QList<UAVDataObject*> > UAVObjectManager::getDataObjects()
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
QList< QList<UAVDataObject*> > dObjects;
|
||||
|
||||
// Go through objects and copy to new list when types match
|
||||
for (int objidx = 0; objidx < objects.length(); ++objidx)
|
||||
{
|
||||
if (objects[objidx].length() > 0)
|
||||
{
|
||||
// Check type
|
||||
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(objects[objidx][0]);
|
||||
if (obj != NULL)
|
||||
{
|
||||
// Create instance list
|
||||
QList<UAVDataObject*> list;
|
||||
// Go through instances and cast them to UAVDataObject, then add to list
|
||||
for (int instidx = 0; instidx < objects[objidx].length(); ++instidx)
|
||||
{
|
||||
obj = dynamic_cast<UAVDataObject*>(objects[objidx][instidx]);
|
||||
if (obj != NULL)
|
||||
{
|
||||
list.append(obj);
|
||||
}
|
||||
}
|
||||
// Append to object list
|
||||
dObjects.append(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Done
|
||||
return dObjects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as getObjects() but will only return MetaObjects.
|
||||
*/
|
||||
QList <QList<UAVMetaObject*> > UAVObjectManager::getMetaObjects()
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
QList< QList<UAVMetaObject*> > mObjects;
|
||||
|
||||
// Go through objects and copy to new list when types match
|
||||
for (int objidx = 0; objidx < objects.length(); ++objidx)
|
||||
{
|
||||
if (objects[objidx].length() > 0)
|
||||
{
|
||||
// Check type
|
||||
UAVMetaObject* obj = dynamic_cast<UAVMetaObject*>(objects[objidx][0]);
|
||||
if (obj != NULL)
|
||||
{
|
||||
// Create instance list
|
||||
QList<UAVMetaObject*> list;
|
||||
// Go through instances and cast them to UAVMetaObject, then add to list
|
||||
for (int instidx = 0; instidx < objects[objidx].length(); ++instidx)
|
||||
{
|
||||
obj = dynamic_cast<UAVMetaObject*>(objects[objidx][instidx]);
|
||||
if (obj != NULL)
|
||||
{
|
||||
list.append(obj);
|
||||
}
|
||||
}
|
||||
// Append to object list
|
||||
mObjects.append(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Done
|
||||
return mObjects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific object given its name and instance ID
|
||||
* @returns The object is found or NULL if not
|
||||
*/
|
||||
UAVObject* UAVObjectManager::getObject(const QString& name, quint32 instId)
|
||||
{
|
||||
return getObject(&name, 0, instId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific object given its object and instance ID
|
||||
* @returns The object is found or NULL if not
|
||||
*/
|
||||
UAVObject* UAVObjectManager::getObject(quint32 objId, quint32 instId)
|
||||
{
|
||||
return getObject(NULL, objId, instId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for the public getObject() functions.
|
||||
*/
|
||||
UAVObject* UAVObjectManager::getObject(const QString* name, quint32 objId, quint32 instId)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
// Check if this object type is already in the list
|
||||
for (int objidx = 0; objidx < objects.length(); ++objidx)
|
||||
{
|
||||
// Check if the object ID is in the list
|
||||
if (objects[objidx].length() > 0)
|
||||
{
|
||||
if ( (name != NULL && objects[objidx][0]->getName().compare(name) == 0) || (name == NULL && objects[objidx][0]->getObjID() == objId) )
|
||||
{
|
||||
// Look for the requested instance ID
|
||||
for (int instidx = 0; instidx < objects[objidx].length(); ++instidx)
|
||||
{
|
||||
if (objects[objidx][instidx]->getInstID() == instId)
|
||||
{
|
||||
return objects[objidx][instidx];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// If this point is reached then the requested object could not be found
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the instances of the object specified by name
|
||||
*/
|
||||
QList<UAVObject*> UAVObjectManager::getObjectInstances(const QString& name)
|
||||
{
|
||||
return getObjectInstances(&name, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the instances of the object specified by its ID
|
||||
*/
|
||||
QList<UAVObject*> UAVObjectManager::getObjectInstances(quint32 objId)
|
||||
{
|
||||
return getObjectInstances(NULL, objId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for the public getObjectInstances()
|
||||
*/
|
||||
QList<UAVObject*> UAVObjectManager::getObjectInstances(const QString* name, quint32 objId)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
// Check if this object type is already in the list
|
||||
for (int objidx = 0; objidx < objects.length(); ++objidx)
|
||||
{
|
||||
// Check if the object ID is in the list
|
||||
if (objects[objidx].length() > 0)
|
||||
{
|
||||
if ( (name != NULL && objects[objidx][0]->getName().compare(name) == 0) || (name == NULL && objects[objidx][0]->getObjID() == objId) )
|
||||
{
|
||||
return objects[objidx];
|
||||
}
|
||||
}
|
||||
}
|
||||
// If this point is reached then the requested object could not be found
|
||||
return QList<UAVObject*>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of instances for an object given its name
|
||||
*/
|
||||
qint32 UAVObjectManager::getNumInstances(const QString& name)
|
||||
{
|
||||
return getNumInstances(&name, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of instances for an object given its ID
|
||||
*/
|
||||
qint32 UAVObjectManager::getNumInstances(quint32 objId)
|
||||
{
|
||||
return getNumInstances(NULL, objId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for public getNumInstances
|
||||
*/
|
||||
qint32 UAVObjectManager::getNumInstances(const QString* name, quint32 objId)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
// Check if this object type is already in the list
|
||||
for (int objidx = 0; objidx < objects.length(); ++objidx)
|
||||
{
|
||||
// Check if the object ID is in the list
|
||||
if (objects[objidx].length() > 0)
|
||||
{
|
||||
if ( (name != NULL && objects[objidx][0]->getName().compare(name) == 0) || (name == NULL && objects[objidx][0]->getObjID() == objId) )
|
||||
{
|
||||
return objects[objidx].length();
|
||||
}
|
||||
}
|
||||
}
|
||||
// If this point is reached then the requested object could not be found
|
||||
return -1;
|
||||
}
|
||||
|
@ -1,75 +1,74 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectmanager.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef UAVOBJECTMANAGER_H
|
||||
#define UAVOBJECTMANAGER_H
|
||||
|
||||
#include "uavobjects_global.h"
|
||||
#include "uavobject.h"
|
||||
#include "uavdataobject.h"
|
||||
#include "uavmetaobject.h"
|
||||
#include <QList>
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
|
||||
class UAVOBJECTS_EXPORT UAVObjectManager: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UAVObjectManager();
|
||||
~UAVObjectManager();
|
||||
|
||||
bool registerObject(UAVDataObject* obj);
|
||||
QList< QList<UAVObject*> > getObjects();
|
||||
QList< QList<UAVDataObject*> > getDataObjects();
|
||||
QList< QList<UAVMetaObject*> > getMetaObjects();
|
||||
UAVObject* getObject(const QString& name, quint32 instId = 0);
|
||||
UAVObject* getObject(quint32 objId, quint32 instId = 0);
|
||||
QList<UAVObject*> getObjectInstances(const QString& name);
|
||||
QList<UAVObject*> getObjectInstances(quint32 objId);
|
||||
qint32 getNumInstances(const QString& name);
|
||||
qint32 getNumInstances(quint32 objId);
|
||||
|
||||
signals:
|
||||
void newObject(UAVObject* obj);
|
||||
void newInstance(UAVObject* obj);
|
||||
|
||||
private:
|
||||
static const quint32 MAX_INSTANCES = 1000;
|
||||
|
||||
QList< QList<UAVObject*> > objects;
|
||||
QMutex* mutex;
|
||||
|
||||
void addObject(UAVObject* obj);
|
||||
UAVObject* getObject(const QString* name, quint32 objId, quint32 instId);
|
||||
QList<UAVObject*> getObjectInstances(const QString* name, quint32 objId);
|
||||
qint32 getNumInstances(const QString* name, quint32 objId);
|
||||
};
|
||||
|
||||
|
||||
#endif // UAVOBJECTMANAGER_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectmanager.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectsplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef UAVOBJECTMANAGER_H
|
||||
#define UAVOBJECTMANAGER_H
|
||||
|
||||
#include "uavobjects_global.h"
|
||||
#include "uavobject.h"
|
||||
#include "uavdataobject.h"
|
||||
#include "uavmetaobject.h"
|
||||
#include <QList>
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
|
||||
class UAVOBJECTS_EXPORT UAVObjectManager: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UAVObjectManager();
|
||||
~UAVObjectManager();
|
||||
|
||||
bool registerObject(UAVDataObject* obj);
|
||||
QList< QList<UAVObject*> > getObjects();
|
||||
QList< QList<UAVDataObject*> > getDataObjects();
|
||||
QList< QList<UAVMetaObject*> > getMetaObjects();
|
||||
UAVObject* getObject(const QString& name, quint32 instId = 0);
|
||||
UAVObject* getObject(quint32 objId, quint32 instId = 0);
|
||||
QList<UAVObject*> getObjectInstances(const QString& name);
|
||||
QList<UAVObject*> getObjectInstances(quint32 objId);
|
||||
qint32 getNumInstances(const QString& name);
|
||||
qint32 getNumInstances(quint32 objId);
|
||||
|
||||
signals:
|
||||
void newObject(UAVObject* obj);
|
||||
void newInstance(UAVObject* obj);
|
||||
|
||||
private:
|
||||
static const quint32 MAX_INSTANCES = 1000;
|
||||
|
||||
QList< QList<UAVObject*> > objects;
|
||||
QMutex* mutex;
|
||||
|
||||
void addObject(UAVObject* obj);
|
||||
UAVObject* getObject(const QString* name, quint32 objId, quint32 instId);
|
||||
QList<UAVObject*> getObjectInstances(const QString* name, quint32 objId);
|
||||
qint32 getNumInstances(const QString* name, quint32 objId);
|
||||
};
|
||||
|
||||
|
||||
#endif // UAVOBJECTMANAGER_H
|
||||
|
@ -1,40 +1,39 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjects_global.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UAVOBJECTS_GLOBAL_H
|
||||
#define UAVOBJECTS_GLOBAL_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#if defined(UAVOBJECTS_LIBRARY)
|
||||
# define UAVOBJECTS_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
# define UAVOBJECTS_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
#endif // UAVOBJECTS_GLOBAL_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjects_global.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectsplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UAVOBJECTS_GLOBAL_H
|
||||
#define UAVOBJECTS_GLOBAL_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#if defined(UAVOBJECTS_LIBRARY)
|
||||
# define UAVOBJECTS_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
# define UAVOBJECTS_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
#endif // UAVOBJECTS_GLOBAL_H
|
||||
|
@ -1,35 +1,34 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectsinit.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef UAVOBJECTSINIT_H
|
||||
#define UAVOBJECTSINIT_H
|
||||
|
||||
#include "uavobjectmanager.h"
|
||||
|
||||
void UAVObjectsInitialize(UAVObjectManager* objMngr);
|
||||
|
||||
#endif // UAVOBJECTSINIT_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectsinit.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectsplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef UAVOBJECTSINIT_H
|
||||
#define UAVOBJECTSINIT_H
|
||||
|
||||
#include "uavobjectmanager.h"
|
||||
|
||||
void UAVObjectsInitialize(UAVObjectManager* objMngr);
|
||||
|
||||
#endif // UAVOBJECTSINIT_H
|
||||
|
@ -1,42 +1,41 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectsinit.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief Initialize all objects.
|
||||
* Automatically generated by the UAVObjectGenerator.
|
||||
*
|
||||
* @note This is an automatically generated file.
|
||||
* DO NOT modify manually.
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavobjectsinit.h"
|
||||
$(OBJINC)
|
||||
|
||||
/**
|
||||
* Function used to initialize the first instance of each object.
|
||||
* This file is automatically updated by the UAVObjectGenerator.
|
||||
*/
|
||||
void UAVObjectsInitialize(UAVObjectManager* objMngr)
|
||||
{
|
||||
$(OBJINIT)
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectsinit.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Initialize all objects.
|
||||
* Automatically generated by the UAVObjectGenerator.
|
||||
*
|
||||
* @note This is an automatically generated file.
|
||||
* DO NOT modify manually.
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectsplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavobjectsinit.h"
|
||||
$(OBJINC)
|
||||
|
||||
/**
|
||||
* Function used to initialize the first instance of each object.
|
||||
* This file is automatically updated by the UAVObjectGenerator.
|
||||
*/
|
||||
void UAVObjectsInitialize(UAVObjectManager* objMngr)
|
||||
{
|
||||
$(OBJINIT)
|
||||
}
|
||||
|
@ -1,64 +1,63 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectsplugin.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavobjectsplugin.h"
|
||||
#include "uavobjectsinit.h"
|
||||
|
||||
UAVObjectsPlugin::UAVObjectsPlugin()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
UAVObjectsPlugin::~UAVObjectsPlugin()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void UAVObjectsPlugin::extensionsInitialized()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool UAVObjectsPlugin::initialize(const QStringList & arguments, QString * errorString)
|
||||
{
|
||||
// Create object manager and expose object
|
||||
UAVObjectManager* objMngr = new UAVObjectManager();
|
||||
addAutoReleasedObject(objMngr);
|
||||
// Initialize UAVObjects
|
||||
UAVObjectsInitialize(objMngr);
|
||||
// Done
|
||||
Q_UNUSED(arguments);
|
||||
Q_UNUSED(errorString);
|
||||
return true;
|
||||
}
|
||||
|
||||
void UAVObjectsPlugin::shutdown()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Q_EXPORT_PLUGIN(UAVObjectsPlugin)
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectsplugin.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectsplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavobjectsplugin.h"
|
||||
#include "uavobjectsinit.h"
|
||||
|
||||
UAVObjectsPlugin::UAVObjectsPlugin()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
UAVObjectsPlugin::~UAVObjectsPlugin()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void UAVObjectsPlugin::extensionsInitialized()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool UAVObjectsPlugin::initialize(const QStringList & arguments, QString * errorString)
|
||||
{
|
||||
// Create object manager and expose object
|
||||
UAVObjectManager* objMngr = new UAVObjectManager();
|
||||
addAutoReleasedObject(objMngr);
|
||||
// Initialize UAVObjects
|
||||
UAVObjectsInitialize(objMngr);
|
||||
// Done
|
||||
Q_UNUSED(arguments);
|
||||
Q_UNUSED(errorString);
|
||||
return true;
|
||||
}
|
||||
|
||||
void UAVObjectsPlugin::shutdown()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Q_EXPORT_PLUGIN(UAVObjectsPlugin)
|
||||
|
@ -1,50 +1,49 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectsplugin.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef UAVOBJECTSPLUGIN_H
|
||||
#define UAVOBJECTSPLUGIN_H
|
||||
|
||||
#include "uavobjects_global.h"
|
||||
#include <extensionsystem/iplugin.h>
|
||||
#include <QtPlugin>
|
||||
#include "uavobjectmanager.h"
|
||||
|
||||
class UAVOBJECTS_EXPORT UAVObjectsPlugin:
|
||||
public ExtensionSystem::IPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UAVObjectsPlugin();
|
||||
~UAVObjectsPlugin();
|
||||
|
||||
void extensionsInitialized();
|
||||
bool initialize(const QStringList & arguments, QString * errorString);
|
||||
void shutdown();
|
||||
};
|
||||
|
||||
#endif // UAVOBJECTSPLUGIN_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectsplugin.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjectsplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef UAVOBJECTSPLUGIN_H
|
||||
#define UAVOBJECTSPLUGIN_H
|
||||
|
||||
#include "uavobjects_global.h"
|
||||
#include <extensionsystem/iplugin.h>
|
||||
#include <QtPlugin>
|
||||
#include "uavobjectmanager.h"
|
||||
|
||||
class UAVOBJECTS_EXPORT UAVObjectsPlugin:
|
||||
public ExtensionSystem::IPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UAVObjectsPlugin();
|
||||
~UAVObjectsPlugin();
|
||||
|
||||
void extensionsInitialized();
|
||||
bool initialize(const QStringList & arguments, QString * errorString);
|
||||
void shutdown();
|
||||
};
|
||||
|
||||
#endif // UAVOBJECTSPLUGIN_H
|
||||
|
@ -1,4 +1,4 @@
|
||||
<plugin name="UAVTalk" version="0.0.1" compatVersion="0.0.1">
|
||||
<plugin name="UAVTalk" version="1.0.0" compatVersion="1.0.0">
|
||||
<vendor>The OpenPilot Project</vendor>
|
||||
<copyright>(C) 2010 OpenPilot Project</copyright>
|
||||
<license>The GNU Public License (GPL) Version 3</license>
|
||||
@ -6,6 +6,6 @@
|
||||
<url>http://www.openpilot.org</url>
|
||||
<dependencyList>
|
||||
<dependency name="Core" version="1.0.0"/>
|
||||
<dependency name="UAVObjects" version="0.0.1"/>
|
||||
<dependency name="UAVObjects" version="1.0.0"/>
|
||||
</dependencyList>
|
||||
</plugin>
|
||||
|
@ -1,522 +1,521 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file telemetry.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "telemetry.h"
|
||||
#include "qxtlogger.h"
|
||||
#include <QTime>
|
||||
#include <QtGlobal>
|
||||
#include <stdlib.h>
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
Telemetry::Telemetry(UAVTalk* utalk, UAVObjectManager* objMngr)
|
||||
{
|
||||
this->utalk = utalk;
|
||||
this->objMngr = objMngr;
|
||||
mutex = new QMutex(QMutex::Recursive);
|
||||
// Process all objects in the list
|
||||
QList< QList<UAVObject*> > objs = objMngr->getObjects();
|
||||
for (int objidx = 0; objidx < objs.length(); ++objidx)
|
||||
{
|
||||
registerObject(objs[objidx][0]); // we only need to register one instance per object type
|
||||
}
|
||||
// Listen to new object creations
|
||||
connect(objMngr, SIGNAL(newObject(UAVObject*)), this, SLOT(newObject(UAVObject*)));
|
||||
connect(objMngr, SIGNAL(newInstance(UAVObject*)), this, SLOT(newInstance(UAVObject*)));
|
||||
// Listen to transaction completions
|
||||
connect(utalk, SIGNAL(transactionCompleted(UAVObject*)), this, SLOT(transactionCompleted(UAVObject*)));
|
||||
// Get GCS stats object
|
||||
gcsStatsObj = GCSTelemetryStats::GetInstance(objMngr);
|
||||
// Setup transaction timer
|
||||
transPending = false;
|
||||
transTimer = new QTimer(this);
|
||||
transTimer->stop();
|
||||
connect(transTimer, SIGNAL(timeout()), this, SLOT(transactionTimeout()));
|
||||
// Setup and start the periodic timer
|
||||
timeToNextUpdateMs = 0;
|
||||
updateTimer = new QTimer(this);
|
||||
connect(updateTimer, SIGNAL(timeout()), this, SLOT(processPeriodicUpdates()));
|
||||
updateTimer->start(1000);
|
||||
// Setup and start the stats timer
|
||||
txErrors = 0;
|
||||
txRetries = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new object for periodic updates (if enabled)
|
||||
*/
|
||||
void Telemetry::registerObject(UAVObject* obj)
|
||||
{
|
||||
// Setup object for periodic updates
|
||||
addObject(obj);
|
||||
|
||||
// Setup object for telemetry updates
|
||||
updateObject(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an object in the list used for periodic updates
|
||||
*/
|
||||
void Telemetry::addObject(UAVObject* obj)
|
||||
{
|
||||
// Check if object type is already in the list
|
||||
for (int n = 0; n < objList.length(); ++n)
|
||||
{
|
||||
if ( objList[n].obj->getObjID() == obj->getObjID() )
|
||||
{
|
||||
// Object type (not instance!) is already in the list, do nothing
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If this point is reached, then the object type is new, let's add it
|
||||
ObjectTimeInfo timeInfo;
|
||||
timeInfo.obj = obj;
|
||||
timeInfo.timeToNextUpdateMs = 0;
|
||||
timeInfo.updatePeriodMs = 0;
|
||||
objList.append(timeInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the object's timers
|
||||
*/
|
||||
void Telemetry::setUpdatePeriod(UAVObject* obj, qint32 periodMs)
|
||||
{
|
||||
// Find object type (not instance!) and update its period
|
||||
for (int n = 0; n < objList.length(); ++n)
|
||||
{
|
||||
if ( objList[n].obj->getObjID() == obj->getObjID() )
|
||||
{
|
||||
objList[n].updatePeriodMs = periodMs;
|
||||
objList[n].timeToNextUpdateMs = quint32((float)periodMs * (float)qrand() / (float)RAND_MAX); // avoid bunching of updates
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to all instances of an object depending on the event mask specified
|
||||
*/
|
||||
void Telemetry::connectToObjectInstances(UAVObject* obj, quint32 eventMask)
|
||||
{
|
||||
QList<UAVObject*> objs = objMngr->getObjectInstances(obj->getObjID());
|
||||
for (int n = 0; n < objs.length(); ++n)
|
||||
{
|
||||
// Disconnect all
|
||||
objs[n]->disconnect(this);
|
||||
// Connect only the selected events
|
||||
if ( (eventMask&EV_UNPACKED) != 0)
|
||||
{
|
||||
connect(objs[n], SIGNAL(objectUnpacked(UAVObject*)), this, SLOT(objectUnpacked(UAVObject*)));
|
||||
}
|
||||
if ( (eventMask&EV_UPDATED) != 0)
|
||||
{
|
||||
connect(objs[n], SIGNAL(objectUpdatedAuto(UAVObject*)), this, SLOT(objectUpdatedAuto(UAVObject*)));
|
||||
}
|
||||
if ( (eventMask&EV_UPDATED_MANUAL) != 0)
|
||||
{
|
||||
connect(objs[n], SIGNAL(objectUpdatedManual(UAVObject*)), this, SLOT(objectUpdatedManual(UAVObject*)));
|
||||
}
|
||||
if ( (eventMask&EV_UPDATE_REQ) != 0)
|
||||
{
|
||||
connect(objs[n], SIGNAL(updateRequested(UAVObject*)), this, SLOT(updateRequested(UAVObject*)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an object based on its metadata properties
|
||||
*/
|
||||
void Telemetry::updateObject(UAVObject* obj)
|
||||
{
|
||||
// Get metadata
|
||||
UAVObject::Metadata metadata = obj->getMetadata();
|
||||
|
||||
// Setup object depending on update mode
|
||||
qint32 eventMask;
|
||||
if ( metadata.gcsTelemetryUpdateMode == UAVObject::UPDATEMODE_PERIODIC )
|
||||
{
|
||||
// Set update period
|
||||
setUpdatePeriod(obj, metadata.gcsTelemetryUpdatePeriod);
|
||||
// Connect signals for all instances
|
||||
eventMask = EV_UPDATED_MANUAL | EV_UPDATE_REQ;
|
||||
if( dynamic_cast<UAVMetaObject*>(obj) != NULL )
|
||||
{
|
||||
eventMask |= EV_UNPACKED; // we also need to act on remote updates (unpack events)
|
||||
}
|
||||
connectToObjectInstances(obj, eventMask);
|
||||
}
|
||||
else if ( metadata.gcsTelemetryUpdateMode == UAVObject::UPDATEMODE_ONCHANGE )
|
||||
{
|
||||
// Set update period
|
||||
setUpdatePeriod(obj, 0);
|
||||
// Connect signals for all instances
|
||||
eventMask = EV_UPDATED | EV_UPDATED_MANUAL | EV_UPDATE_REQ;
|
||||
if( dynamic_cast<UAVMetaObject*>(obj) != NULL )
|
||||
{
|
||||
eventMask |= EV_UNPACKED; // we also need to act on remote updates (unpack events)
|
||||
}
|
||||
connectToObjectInstances(obj, eventMask);
|
||||
}
|
||||
else if ( metadata.gcsTelemetryUpdateMode == UAVObject::UPDATEMODE_MANUAL )
|
||||
{
|
||||
// Set update period
|
||||
setUpdatePeriod(obj, 0);
|
||||
// Connect signals for all instances
|
||||
eventMask = EV_UPDATED_MANUAL | EV_UPDATE_REQ;
|
||||
if( dynamic_cast<UAVMetaObject*>(obj) != NULL )
|
||||
{
|
||||
eventMask |= EV_UNPACKED; // we also need to act on remote updates (unpack events)
|
||||
}
|
||||
connectToObjectInstances(obj, eventMask);
|
||||
}
|
||||
else if ( metadata.gcsTelemetryUpdateMode == UAVObject::UPDATEMODE_NEVER )
|
||||
{
|
||||
// Set update period
|
||||
setUpdatePeriod(obj, 0);
|
||||
// Disconnect from object
|
||||
connectToObjectInstances(obj, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a transaction is successfully completed (uavtalk event)
|
||||
*/
|
||||
void Telemetry::transactionCompleted(UAVObject* obj)
|
||||
{
|
||||
// Check if there is a pending transaction and the objects match
|
||||
if ( transPending && transInfo.obj->getObjID() == obj->getObjID() )
|
||||
{
|
||||
// Send signal
|
||||
obj->emitTransactionCompleted(true);
|
||||
// Complete transaction
|
||||
transTimer->stop();
|
||||
transPending = false;
|
||||
// Process new object updates from queue
|
||||
processObjectQueue();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a transaction is not completed within the timeout period (timer event)
|
||||
*/
|
||||
void Telemetry::transactionTimeout()
|
||||
{
|
||||
transTimer->stop();
|
||||
// Proceed only if there is a pending transaction
|
||||
if ( transPending )
|
||||
{
|
||||
// Check if more retries are pending
|
||||
if (transInfo.retriesRemaining > 0)
|
||||
{
|
||||
--transInfo.retriesRemaining;
|
||||
processObjectTransaction();
|
||||
++txRetries;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Send signal
|
||||
transInfo.obj->emitTransactionCompleted(false);
|
||||
// Terminate transaction
|
||||
utalk->cancelTransaction();
|
||||
transPending = false;
|
||||
// Process new object updates from queue
|
||||
processObjectQueue();
|
||||
++txErrors;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start an object transaction with UAVTalk, all information is stored in transInfo
|
||||
*/
|
||||
void Telemetry::processObjectTransaction()
|
||||
{
|
||||
if (transPending)
|
||||
{
|
||||
// Initiate transaction
|
||||
if (transInfo.objRequest)
|
||||
{
|
||||
utalk->sendObjectRequest(transInfo.obj, transInfo.allInstances);
|
||||
}
|
||||
else
|
||||
{
|
||||
utalk->sendObject(transInfo.obj, transInfo.acked, transInfo.allInstances);
|
||||
}
|
||||
// Start timer if a response is expected
|
||||
if ( transInfo.objRequest || transInfo.acked )
|
||||
{
|
||||
transTimer->start(REQ_TIMEOUT_MS);
|
||||
}
|
||||
else
|
||||
{
|
||||
transTimer->stop();
|
||||
transPending = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the event received from an object
|
||||
*/
|
||||
void Telemetry::processObjectUpdates(UAVObject* obj, EventMask event, bool allInstances, bool priority)
|
||||
{
|
||||
// Push event into queue
|
||||
ObjectQueueInfo objInfo;
|
||||
objInfo.obj = obj;
|
||||
objInfo.event = event;
|
||||
objInfo.allInstances = allInstances;
|
||||
if (priority)
|
||||
{
|
||||
if ( objPriorityQueue.length() < MAX_QUEUE_SIZE )
|
||||
{
|
||||
objPriorityQueue.enqueue(objInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
++txErrors;
|
||||
obj->emitTransactionCompleted(false);
|
||||
qxtLog->warning(tr("Telemetry: priority event queue is full, event lost (%1)").arg(obj->getName()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( objQueue.length() < MAX_QUEUE_SIZE )
|
||||
{
|
||||
objQueue.enqueue(objInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
++txErrors;
|
||||
obj->emitTransactionCompleted(false);
|
||||
}
|
||||
}
|
||||
|
||||
// If there is no transaction in progress then process event
|
||||
if (!transPending)
|
||||
{
|
||||
processObjectQueue();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process events from the object queue
|
||||
*/
|
||||
void Telemetry::processObjectQueue()
|
||||
{
|
||||
// Don nothing if a transaction is already in progress (should not happen)
|
||||
if (transPending)
|
||||
{
|
||||
qxtLog->error("Telemetry: Dequeue while a transaction pending!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Get object information from queue (first the priority and then the regular queue)
|
||||
ObjectQueueInfo objInfo;
|
||||
if ( !objPriorityQueue.isEmpty() )
|
||||
{
|
||||
objInfo = objPriorityQueue.dequeue();
|
||||
}
|
||||
else if ( !objQueue.isEmpty() )
|
||||
{
|
||||
objInfo = objQueue.dequeue();
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if a connection has been established, only process GCSTelemetryStats updates
|
||||
// (used to establish the connection)
|
||||
GCSTelemetryStats::DataFields gcsStats = gcsStatsObj->getData();
|
||||
if ( gcsStats.Status != GCSTelemetryStats::STATUS_CONNECTED )
|
||||
{
|
||||
objQueue.clear();
|
||||
if ( objInfo.obj->getObjID() != GCSTelemetryStats::OBJID )
|
||||
{
|
||||
objInfo.obj->emitTransactionCompleted(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Setup transaction (skip if unpack event)
|
||||
if ( objInfo.event != EV_UNPACKED )
|
||||
{
|
||||
UAVObject::Metadata metadata = objInfo.obj->getMetadata();
|
||||
transInfo.obj = objInfo.obj;
|
||||
transInfo.allInstances = objInfo.allInstances;
|
||||
transInfo.retriesRemaining = MAX_RETRIES;
|
||||
transInfo.acked = metadata.gcsTelemetryAcked;
|
||||
if ( objInfo.event == EV_UPDATED || objInfo.event == EV_UPDATED_MANUAL )
|
||||
{
|
||||
transInfo.objRequest = false;
|
||||
}
|
||||
else if ( objInfo.event == EV_UPDATE_REQ )
|
||||
{
|
||||
transInfo.objRequest = true;
|
||||
}
|
||||
// Start transaction
|
||||
transPending = true;
|
||||
processObjectTransaction();
|
||||
}
|
||||
|
||||
// If this is a metaobject then make necessary telemetry updates
|
||||
UAVMetaObject* metaobj = dynamic_cast<UAVMetaObject*>(objInfo.obj);
|
||||
if ( metaobj != NULL )
|
||||
{
|
||||
updateObject( metaobj->getParentObject() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check is any objects are pending for periodic updates
|
||||
* TODO: Clean-up
|
||||
*/
|
||||
void Telemetry::processPeriodicUpdates()
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
|
||||
// Stop timer
|
||||
updateTimer->stop();
|
||||
|
||||
// Iterate through each object and update its timer, if zero then transmit object.
|
||||
// Also calculate smallest delay to next update (will be used for setting timeToNextUpdateMs)
|
||||
qint32 minDelay = MAX_UPDATE_PERIOD_MS;
|
||||
ObjectTimeInfo objinfo;
|
||||
qint32 elapsedMs = 0;
|
||||
QTime time;
|
||||
for (int n = 0; n < objList.length(); ++n)
|
||||
{
|
||||
objinfo = objList[n];
|
||||
// If object is configured for periodic updates
|
||||
if (objinfo.updatePeriodMs > 0)
|
||||
{
|
||||
objinfo.timeToNextUpdateMs -= timeToNextUpdateMs;
|
||||
// Check if time for the next update
|
||||
if (objinfo.timeToNextUpdateMs <= 0)
|
||||
{
|
||||
// Reset timer
|
||||
objinfo.timeToNextUpdateMs = objinfo.updatePeriodMs;
|
||||
// Send object
|
||||
time.start();
|
||||
processObjectUpdates(objinfo.obj, EV_UPDATED_MANUAL, true, false);
|
||||
elapsedMs = time.elapsed();
|
||||
// Update timeToNextUpdateMs with the elapsed delay of sending the object;
|
||||
timeToNextUpdateMs += elapsedMs;
|
||||
}
|
||||
// Update minimum delay
|
||||
if (objinfo.timeToNextUpdateMs < minDelay)
|
||||
{
|
||||
minDelay = objinfo.timeToNextUpdateMs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if delay for the next update is too short
|
||||
if (minDelay < MIN_UPDATE_PERIOD_MS)
|
||||
{
|
||||
minDelay = MIN_UPDATE_PERIOD_MS;
|
||||
}
|
||||
|
||||
// Done
|
||||
timeToNextUpdateMs = minDelay;
|
||||
|
||||
// Restart timer
|
||||
updateTimer->start(timeToNextUpdateMs);
|
||||
}
|
||||
|
||||
Telemetry::TelemetryStats Telemetry::getStats()
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
|
||||
// Get UAVTalk stats
|
||||
UAVTalk::ComStats utalkStats = utalk->getStats();
|
||||
|
||||
// Update stats
|
||||
TelemetryStats stats;
|
||||
stats.txBytes = utalkStats.txBytes;
|
||||
stats.rxBytes = utalkStats.rxBytes;
|
||||
stats.txObjectBytes = utalkStats.txObjectBytes;
|
||||
stats.rxObjectBytes = utalkStats.rxObjectBytes;
|
||||
stats.rxObjects = utalkStats.rxObjects;
|
||||
stats.txObjects = utalkStats.txObjects;
|
||||
stats.txErrors = utalkStats.txErrors + txErrors;
|
||||
stats.rxErrors = utalkStats.rxErrors;
|
||||
stats.txRetries = txRetries;
|
||||
|
||||
// Done
|
||||
return stats;
|
||||
}
|
||||
|
||||
void Telemetry::resetStats()
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
utalk->resetStats();
|
||||
txErrors = 0;
|
||||
txRetries = 0;
|
||||
}
|
||||
|
||||
void Telemetry::objectUpdatedAuto(UAVObject* obj)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
processObjectUpdates(obj, EV_UPDATED, false, true);
|
||||
}
|
||||
|
||||
void Telemetry::objectUpdatedManual(UAVObject* obj)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
processObjectUpdates(obj, EV_UPDATED_MANUAL, false, true);
|
||||
}
|
||||
|
||||
void Telemetry::objectUnpacked(UAVObject* obj)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
processObjectUpdates(obj, EV_UNPACKED, false, true);
|
||||
}
|
||||
|
||||
void Telemetry::updateRequested(UAVObject* obj)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
processObjectUpdates(obj, EV_UPDATE_REQ, false, true);
|
||||
}
|
||||
|
||||
void Telemetry::newObject(UAVObject* obj)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
registerObject(obj);
|
||||
}
|
||||
|
||||
void Telemetry::newInstance(UAVObject* obj)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
registerObject(obj);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file telemetry.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavtalkplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "telemetry.h"
|
||||
#include "qxtlogger.h"
|
||||
#include <QTime>
|
||||
#include <QtGlobal>
|
||||
#include <stdlib.h>
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
Telemetry::Telemetry(UAVTalk* utalk, UAVObjectManager* objMngr)
|
||||
{
|
||||
this->utalk = utalk;
|
||||
this->objMngr = objMngr;
|
||||
mutex = new QMutex(QMutex::Recursive);
|
||||
// Process all objects in the list
|
||||
QList< QList<UAVObject*> > objs = objMngr->getObjects();
|
||||
for (int objidx = 0; objidx < objs.length(); ++objidx)
|
||||
{
|
||||
registerObject(objs[objidx][0]); // we only need to register one instance per object type
|
||||
}
|
||||
// Listen to new object creations
|
||||
connect(objMngr, SIGNAL(newObject(UAVObject*)), this, SLOT(newObject(UAVObject*)));
|
||||
connect(objMngr, SIGNAL(newInstance(UAVObject*)), this, SLOT(newInstance(UAVObject*)));
|
||||
// Listen to transaction completions
|
||||
connect(utalk, SIGNAL(transactionCompleted(UAVObject*)), this, SLOT(transactionCompleted(UAVObject*)));
|
||||
// Get GCS stats object
|
||||
gcsStatsObj = GCSTelemetryStats::GetInstance(objMngr);
|
||||
// Setup transaction timer
|
||||
transPending = false;
|
||||
transTimer = new QTimer(this);
|
||||
transTimer->stop();
|
||||
connect(transTimer, SIGNAL(timeout()), this, SLOT(transactionTimeout()));
|
||||
// Setup and start the periodic timer
|
||||
timeToNextUpdateMs = 0;
|
||||
updateTimer = new QTimer(this);
|
||||
connect(updateTimer, SIGNAL(timeout()), this, SLOT(processPeriodicUpdates()));
|
||||
updateTimer->start(1000);
|
||||
// Setup and start the stats timer
|
||||
txErrors = 0;
|
||||
txRetries = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new object for periodic updates (if enabled)
|
||||
*/
|
||||
void Telemetry::registerObject(UAVObject* obj)
|
||||
{
|
||||
// Setup object for periodic updates
|
||||
addObject(obj);
|
||||
|
||||
// Setup object for telemetry updates
|
||||
updateObject(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an object in the list used for periodic updates
|
||||
*/
|
||||
void Telemetry::addObject(UAVObject* obj)
|
||||
{
|
||||
// Check if object type is already in the list
|
||||
for (int n = 0; n < objList.length(); ++n)
|
||||
{
|
||||
if ( objList[n].obj->getObjID() == obj->getObjID() )
|
||||
{
|
||||
// Object type (not instance!) is already in the list, do nothing
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If this point is reached, then the object type is new, let's add it
|
||||
ObjectTimeInfo timeInfo;
|
||||
timeInfo.obj = obj;
|
||||
timeInfo.timeToNextUpdateMs = 0;
|
||||
timeInfo.updatePeriodMs = 0;
|
||||
objList.append(timeInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the object's timers
|
||||
*/
|
||||
void Telemetry::setUpdatePeriod(UAVObject* obj, qint32 periodMs)
|
||||
{
|
||||
// Find object type (not instance!) and update its period
|
||||
for (int n = 0; n < objList.length(); ++n)
|
||||
{
|
||||
if ( objList[n].obj->getObjID() == obj->getObjID() )
|
||||
{
|
||||
objList[n].updatePeriodMs = periodMs;
|
||||
objList[n].timeToNextUpdateMs = quint32((float)periodMs * (float)qrand() / (float)RAND_MAX); // avoid bunching of updates
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to all instances of an object depending on the event mask specified
|
||||
*/
|
||||
void Telemetry::connectToObjectInstances(UAVObject* obj, quint32 eventMask)
|
||||
{
|
||||
QList<UAVObject*> objs = objMngr->getObjectInstances(obj->getObjID());
|
||||
for (int n = 0; n < objs.length(); ++n)
|
||||
{
|
||||
// Disconnect all
|
||||
objs[n]->disconnect(this);
|
||||
// Connect only the selected events
|
||||
if ( (eventMask&EV_UNPACKED) != 0)
|
||||
{
|
||||
connect(objs[n], SIGNAL(objectUnpacked(UAVObject*)), this, SLOT(objectUnpacked(UAVObject*)));
|
||||
}
|
||||
if ( (eventMask&EV_UPDATED) != 0)
|
||||
{
|
||||
connect(objs[n], SIGNAL(objectUpdatedAuto(UAVObject*)), this, SLOT(objectUpdatedAuto(UAVObject*)));
|
||||
}
|
||||
if ( (eventMask&EV_UPDATED_MANUAL) != 0)
|
||||
{
|
||||
connect(objs[n], SIGNAL(objectUpdatedManual(UAVObject*)), this, SLOT(objectUpdatedManual(UAVObject*)));
|
||||
}
|
||||
if ( (eventMask&EV_UPDATE_REQ) != 0)
|
||||
{
|
||||
connect(objs[n], SIGNAL(updateRequested(UAVObject*)), this, SLOT(updateRequested(UAVObject*)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an object based on its metadata properties
|
||||
*/
|
||||
void Telemetry::updateObject(UAVObject* obj)
|
||||
{
|
||||
// Get metadata
|
||||
UAVObject::Metadata metadata = obj->getMetadata();
|
||||
|
||||
// Setup object depending on update mode
|
||||
qint32 eventMask;
|
||||
if ( metadata.gcsTelemetryUpdateMode == UAVObject::UPDATEMODE_PERIODIC )
|
||||
{
|
||||
// Set update period
|
||||
setUpdatePeriod(obj, metadata.gcsTelemetryUpdatePeriod);
|
||||
// Connect signals for all instances
|
||||
eventMask = EV_UPDATED_MANUAL | EV_UPDATE_REQ;
|
||||
if( dynamic_cast<UAVMetaObject*>(obj) != NULL )
|
||||
{
|
||||
eventMask |= EV_UNPACKED; // we also need to act on remote updates (unpack events)
|
||||
}
|
||||
connectToObjectInstances(obj, eventMask);
|
||||
}
|
||||
else if ( metadata.gcsTelemetryUpdateMode == UAVObject::UPDATEMODE_ONCHANGE )
|
||||
{
|
||||
// Set update period
|
||||
setUpdatePeriod(obj, 0);
|
||||
// Connect signals for all instances
|
||||
eventMask = EV_UPDATED | EV_UPDATED_MANUAL | EV_UPDATE_REQ;
|
||||
if( dynamic_cast<UAVMetaObject*>(obj) != NULL )
|
||||
{
|
||||
eventMask |= EV_UNPACKED; // we also need to act on remote updates (unpack events)
|
||||
}
|
||||
connectToObjectInstances(obj, eventMask);
|
||||
}
|
||||
else if ( metadata.gcsTelemetryUpdateMode == UAVObject::UPDATEMODE_MANUAL )
|
||||
{
|
||||
// Set update period
|
||||
setUpdatePeriod(obj, 0);
|
||||
// Connect signals for all instances
|
||||
eventMask = EV_UPDATED_MANUAL | EV_UPDATE_REQ;
|
||||
if( dynamic_cast<UAVMetaObject*>(obj) != NULL )
|
||||
{
|
||||
eventMask |= EV_UNPACKED; // we also need to act on remote updates (unpack events)
|
||||
}
|
||||
connectToObjectInstances(obj, eventMask);
|
||||
}
|
||||
else if ( metadata.gcsTelemetryUpdateMode == UAVObject::UPDATEMODE_NEVER )
|
||||
{
|
||||
// Set update period
|
||||
setUpdatePeriod(obj, 0);
|
||||
// Disconnect from object
|
||||
connectToObjectInstances(obj, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a transaction is successfully completed (uavtalk event)
|
||||
*/
|
||||
void Telemetry::transactionCompleted(UAVObject* obj)
|
||||
{
|
||||
// Check if there is a pending transaction and the objects match
|
||||
if ( transPending && transInfo.obj->getObjID() == obj->getObjID() )
|
||||
{
|
||||
// Send signal
|
||||
obj->emitTransactionCompleted(true);
|
||||
// Complete transaction
|
||||
transTimer->stop();
|
||||
transPending = false;
|
||||
// Process new object updates from queue
|
||||
processObjectQueue();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a transaction is not completed within the timeout period (timer event)
|
||||
*/
|
||||
void Telemetry::transactionTimeout()
|
||||
{
|
||||
transTimer->stop();
|
||||
// Proceed only if there is a pending transaction
|
||||
if ( transPending )
|
||||
{
|
||||
// Check if more retries are pending
|
||||
if (transInfo.retriesRemaining > 0)
|
||||
{
|
||||
--transInfo.retriesRemaining;
|
||||
processObjectTransaction();
|
||||
++txRetries;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Send signal
|
||||
transInfo.obj->emitTransactionCompleted(false);
|
||||
// Terminate transaction
|
||||
utalk->cancelTransaction();
|
||||
transPending = false;
|
||||
// Process new object updates from queue
|
||||
processObjectQueue();
|
||||
++txErrors;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start an object transaction with UAVTalk, all information is stored in transInfo
|
||||
*/
|
||||
void Telemetry::processObjectTransaction()
|
||||
{
|
||||
if (transPending)
|
||||
{
|
||||
// Initiate transaction
|
||||
if (transInfo.objRequest)
|
||||
{
|
||||
utalk->sendObjectRequest(transInfo.obj, transInfo.allInstances);
|
||||
}
|
||||
else
|
||||
{
|
||||
utalk->sendObject(transInfo.obj, transInfo.acked, transInfo.allInstances);
|
||||
}
|
||||
// Start timer if a response is expected
|
||||
if ( transInfo.objRequest || transInfo.acked )
|
||||
{
|
||||
transTimer->start(REQ_TIMEOUT_MS);
|
||||
}
|
||||
else
|
||||
{
|
||||
transTimer->stop();
|
||||
transPending = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the event received from an object
|
||||
*/
|
||||
void Telemetry::processObjectUpdates(UAVObject* obj, EventMask event, bool allInstances, bool priority)
|
||||
{
|
||||
// Push event into queue
|
||||
ObjectQueueInfo objInfo;
|
||||
objInfo.obj = obj;
|
||||
objInfo.event = event;
|
||||
objInfo.allInstances = allInstances;
|
||||
if (priority)
|
||||
{
|
||||
if ( objPriorityQueue.length() < MAX_QUEUE_SIZE )
|
||||
{
|
||||
objPriorityQueue.enqueue(objInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
++txErrors;
|
||||
obj->emitTransactionCompleted(false);
|
||||
qxtLog->warning(tr("Telemetry: priority event queue is full, event lost (%1)").arg(obj->getName()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( objQueue.length() < MAX_QUEUE_SIZE )
|
||||
{
|
||||
objQueue.enqueue(objInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
++txErrors;
|
||||
obj->emitTransactionCompleted(false);
|
||||
}
|
||||
}
|
||||
|
||||
// If there is no transaction in progress then process event
|
||||
if (!transPending)
|
||||
{
|
||||
processObjectQueue();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process events from the object queue
|
||||
*/
|
||||
void Telemetry::processObjectQueue()
|
||||
{
|
||||
// Don nothing if a transaction is already in progress (should not happen)
|
||||
if (transPending)
|
||||
{
|
||||
qxtLog->error("Telemetry: Dequeue while a transaction pending!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Get object information from queue (first the priority and then the regular queue)
|
||||
ObjectQueueInfo objInfo;
|
||||
if ( !objPriorityQueue.isEmpty() )
|
||||
{
|
||||
objInfo = objPriorityQueue.dequeue();
|
||||
}
|
||||
else if ( !objQueue.isEmpty() )
|
||||
{
|
||||
objInfo = objQueue.dequeue();
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if a connection has been established, only process GCSTelemetryStats updates
|
||||
// (used to establish the connection)
|
||||
GCSTelemetryStats::DataFields gcsStats = gcsStatsObj->getData();
|
||||
if ( gcsStats.Status != GCSTelemetryStats::STATUS_CONNECTED )
|
||||
{
|
||||
objQueue.clear();
|
||||
if ( objInfo.obj->getObjID() != GCSTelemetryStats::OBJID )
|
||||
{
|
||||
objInfo.obj->emitTransactionCompleted(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Setup transaction (skip if unpack event)
|
||||
if ( objInfo.event != EV_UNPACKED )
|
||||
{
|
||||
UAVObject::Metadata metadata = objInfo.obj->getMetadata();
|
||||
transInfo.obj = objInfo.obj;
|
||||
transInfo.allInstances = objInfo.allInstances;
|
||||
transInfo.retriesRemaining = MAX_RETRIES;
|
||||
transInfo.acked = metadata.gcsTelemetryAcked;
|
||||
if ( objInfo.event == EV_UPDATED || objInfo.event == EV_UPDATED_MANUAL )
|
||||
{
|
||||
transInfo.objRequest = false;
|
||||
}
|
||||
else if ( objInfo.event == EV_UPDATE_REQ )
|
||||
{
|
||||
transInfo.objRequest = true;
|
||||
}
|
||||
// Start transaction
|
||||
transPending = true;
|
||||
processObjectTransaction();
|
||||
}
|
||||
|
||||
// If this is a metaobject then make necessary telemetry updates
|
||||
UAVMetaObject* metaobj = dynamic_cast<UAVMetaObject*>(objInfo.obj);
|
||||
if ( metaobj != NULL )
|
||||
{
|
||||
updateObject( metaobj->getParentObject() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check is any objects are pending for periodic updates
|
||||
* TODO: Clean-up
|
||||
*/
|
||||
void Telemetry::processPeriodicUpdates()
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
|
||||
// Stop timer
|
||||
updateTimer->stop();
|
||||
|
||||
// Iterate through each object and update its timer, if zero then transmit object.
|
||||
// Also calculate smallest delay to next update (will be used for setting timeToNextUpdateMs)
|
||||
qint32 minDelay = MAX_UPDATE_PERIOD_MS;
|
||||
ObjectTimeInfo objinfo;
|
||||
qint32 elapsedMs = 0;
|
||||
QTime time;
|
||||
for (int n = 0; n < objList.length(); ++n)
|
||||
{
|
||||
objinfo = objList[n];
|
||||
// If object is configured for periodic updates
|
||||
if (objinfo.updatePeriodMs > 0)
|
||||
{
|
||||
objinfo.timeToNextUpdateMs -= timeToNextUpdateMs;
|
||||
// Check if time for the next update
|
||||
if (objinfo.timeToNextUpdateMs <= 0)
|
||||
{
|
||||
// Reset timer
|
||||
objinfo.timeToNextUpdateMs = objinfo.updatePeriodMs;
|
||||
// Send object
|
||||
time.start();
|
||||
processObjectUpdates(objinfo.obj, EV_UPDATED_MANUAL, true, false);
|
||||
elapsedMs = time.elapsed();
|
||||
// Update timeToNextUpdateMs with the elapsed delay of sending the object;
|
||||
timeToNextUpdateMs += elapsedMs;
|
||||
}
|
||||
// Update minimum delay
|
||||
if (objinfo.timeToNextUpdateMs < minDelay)
|
||||
{
|
||||
minDelay = objinfo.timeToNextUpdateMs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if delay for the next update is too short
|
||||
if (minDelay < MIN_UPDATE_PERIOD_MS)
|
||||
{
|
||||
minDelay = MIN_UPDATE_PERIOD_MS;
|
||||
}
|
||||
|
||||
// Done
|
||||
timeToNextUpdateMs = minDelay;
|
||||
|
||||
// Restart timer
|
||||
updateTimer->start(timeToNextUpdateMs);
|
||||
}
|
||||
|
||||
Telemetry::TelemetryStats Telemetry::getStats()
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
|
||||
// Get UAVTalk stats
|
||||
UAVTalk::ComStats utalkStats = utalk->getStats();
|
||||
|
||||
// Update stats
|
||||
TelemetryStats stats;
|
||||
stats.txBytes = utalkStats.txBytes;
|
||||
stats.rxBytes = utalkStats.rxBytes;
|
||||
stats.txObjectBytes = utalkStats.txObjectBytes;
|
||||
stats.rxObjectBytes = utalkStats.rxObjectBytes;
|
||||
stats.rxObjects = utalkStats.rxObjects;
|
||||
stats.txObjects = utalkStats.txObjects;
|
||||
stats.txErrors = utalkStats.txErrors + txErrors;
|
||||
stats.rxErrors = utalkStats.rxErrors;
|
||||
stats.txRetries = txRetries;
|
||||
|
||||
// Done
|
||||
return stats;
|
||||
}
|
||||
|
||||
void Telemetry::resetStats()
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
utalk->resetStats();
|
||||
txErrors = 0;
|
||||
txRetries = 0;
|
||||
}
|
||||
|
||||
void Telemetry::objectUpdatedAuto(UAVObject* obj)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
processObjectUpdates(obj, EV_UPDATED, false, true);
|
||||
}
|
||||
|
||||
void Telemetry::objectUpdatedManual(UAVObject* obj)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
processObjectUpdates(obj, EV_UPDATED_MANUAL, false, true);
|
||||
}
|
||||
|
||||
void Telemetry::objectUnpacked(UAVObject* obj)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
processObjectUpdates(obj, EV_UNPACKED, false, true);
|
||||
}
|
||||
|
||||
void Telemetry::updateRequested(UAVObject* obj)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
processObjectUpdates(obj, EV_UPDATE_REQ, false, true);
|
||||
}
|
||||
|
||||
void Telemetry::newObject(UAVObject* obj)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
registerObject(obj);
|
||||
}
|
||||
|
||||
void Telemetry::newInstance(UAVObject* obj)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
registerObject(obj);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,144 +1,143 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file telemetry.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef TELEMETRY_H
|
||||
#define TELEMETRY_H
|
||||
|
||||
#include "uavtalk.h"
|
||||
#include "uavobjects/uavobjectmanager.h"
|
||||
#include "uavobjects/gcstelemetrystats.h"
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
#include <QTimer>
|
||||
#include <QQueue>
|
||||
|
||||
class Telemetry: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
typedef struct {
|
||||
quint32 txBytes;
|
||||
quint32 rxBytes;
|
||||
quint32 txObjectBytes;
|
||||
quint32 rxObjectBytes;
|
||||
quint32 rxObjects;
|
||||
quint32 txObjects;
|
||||
quint32 txErrors;
|
||||
quint32 rxErrors;
|
||||
quint32 txRetries;
|
||||
} TelemetryStats;
|
||||
|
||||
Telemetry(UAVTalk* utalk, UAVObjectManager* objMngr);
|
||||
TelemetryStats getStats();
|
||||
void resetStats();
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
private slots:
|
||||
void objectUpdatedAuto(UAVObject* obj);
|
||||
void objectUpdatedManual(UAVObject* obj);
|
||||
void objectUnpacked(UAVObject* obj);
|
||||
void updateRequested(UAVObject* obj);
|
||||
void newObject(UAVObject* obj);
|
||||
void newInstance(UAVObject* obj);
|
||||
void processPeriodicUpdates();
|
||||
void transactionCompleted(UAVObject* obj);
|
||||
void transactionTimeout();
|
||||
|
||||
private:
|
||||
// Constants
|
||||
static const int REQ_TIMEOUT_MS = 250;
|
||||
static const int MAX_RETRIES = 2;
|
||||
static const int MAX_UPDATE_PERIOD_MS = 1000;
|
||||
static const int MIN_UPDATE_PERIOD_MS = 1;
|
||||
static const int MAX_QUEUE_SIZE = 20;
|
||||
|
||||
// Types
|
||||
/**
|
||||
* Events generated by objects
|
||||
*/
|
||||
typedef enum {
|
||||
EV_UNPACKED = 0x01, /** Object data updated by unpacking */
|
||||
EV_UPDATED = 0x02, /** Object data updated by changing the data structure */
|
||||
EV_UPDATED_MANUAL = 0x04, /** Object update event manually generated */
|
||||
EV_UPDATE_REQ = 0x08 /** Request to update object data */
|
||||
} EventMask;
|
||||
|
||||
typedef struct {
|
||||
UAVObject* obj;
|
||||
qint32 updatePeriodMs; /** Update period in ms or 0 if no periodic updates are needed */
|
||||
qint32 timeToNextUpdateMs; /** Time delay to the next update */
|
||||
} ObjectTimeInfo;
|
||||
|
||||
typedef struct {
|
||||
UAVObject* obj;
|
||||
EventMask event;
|
||||
bool allInstances;
|
||||
} ObjectQueueInfo;
|
||||
|
||||
typedef struct {
|
||||
UAVObject* obj;
|
||||
bool allInstances;
|
||||
bool objRequest;
|
||||
qint32 retriesRemaining;
|
||||
bool acked;
|
||||
} ObjectTransactionInfo;
|
||||
|
||||
// Variables
|
||||
UAVObjectManager* objMngr;
|
||||
UAVTalk* utalk;
|
||||
GCSTelemetryStats* gcsStatsObj;
|
||||
QList<ObjectTimeInfo> objList;
|
||||
QQueue<ObjectQueueInfo> objQueue;
|
||||
QQueue<ObjectQueueInfo> objPriorityQueue;
|
||||
ObjectTransactionInfo transInfo;
|
||||
bool transPending;
|
||||
QMutex* mutex;
|
||||
QTimer* updateTimer;
|
||||
QTimer* transTimer;
|
||||
QTimer* statsTimer;
|
||||
qint32 timeToNextUpdateMs;
|
||||
quint32 txErrors;
|
||||
quint32 txRetries;
|
||||
|
||||
// Methods
|
||||
void registerObject(UAVObject* obj);
|
||||
void addObject(UAVObject* obj);
|
||||
void setUpdatePeriod(UAVObject* obj, qint32 periodMs);
|
||||
void connectToObjectInstances(UAVObject* obj, quint32 eventMask);
|
||||
void updateObject(UAVObject* obj);
|
||||
void processObjectUpdates(UAVObject* obj, EventMask event, bool allInstances, bool priority);
|
||||
void processObjectTransaction();
|
||||
void processObjectQueue();
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // TELEMETRY_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file telemetry.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavtalkplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef TELEMETRY_H
|
||||
#define TELEMETRY_H
|
||||
|
||||
#include "uavtalk.h"
|
||||
#include "uavobjects/uavobjectmanager.h"
|
||||
#include "uavobjects/gcstelemetrystats.h"
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
#include <QTimer>
|
||||
#include <QQueue>
|
||||
|
||||
class Telemetry: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
typedef struct {
|
||||
quint32 txBytes;
|
||||
quint32 rxBytes;
|
||||
quint32 txObjectBytes;
|
||||
quint32 rxObjectBytes;
|
||||
quint32 rxObjects;
|
||||
quint32 txObjects;
|
||||
quint32 txErrors;
|
||||
quint32 rxErrors;
|
||||
quint32 txRetries;
|
||||
} TelemetryStats;
|
||||
|
||||
Telemetry(UAVTalk* utalk, UAVObjectManager* objMngr);
|
||||
TelemetryStats getStats();
|
||||
void resetStats();
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
private slots:
|
||||
void objectUpdatedAuto(UAVObject* obj);
|
||||
void objectUpdatedManual(UAVObject* obj);
|
||||
void objectUnpacked(UAVObject* obj);
|
||||
void updateRequested(UAVObject* obj);
|
||||
void newObject(UAVObject* obj);
|
||||
void newInstance(UAVObject* obj);
|
||||
void processPeriodicUpdates();
|
||||
void transactionCompleted(UAVObject* obj);
|
||||
void transactionTimeout();
|
||||
|
||||
private:
|
||||
// Constants
|
||||
static const int REQ_TIMEOUT_MS = 250;
|
||||
static const int MAX_RETRIES = 2;
|
||||
static const int MAX_UPDATE_PERIOD_MS = 1000;
|
||||
static const int MIN_UPDATE_PERIOD_MS = 1;
|
||||
static const int MAX_QUEUE_SIZE = 20;
|
||||
|
||||
// Types
|
||||
/**
|
||||
* Events generated by objects
|
||||
*/
|
||||
typedef enum {
|
||||
EV_UNPACKED = 0x01, /** Object data updated by unpacking */
|
||||
EV_UPDATED = 0x02, /** Object data updated by changing the data structure */
|
||||
EV_UPDATED_MANUAL = 0x04, /** Object update event manually generated */
|
||||
EV_UPDATE_REQ = 0x08 /** Request to update object data */
|
||||
} EventMask;
|
||||
|
||||
typedef struct {
|
||||
UAVObject* obj;
|
||||
qint32 updatePeriodMs; /** Update period in ms or 0 if no periodic updates are needed */
|
||||
qint32 timeToNextUpdateMs; /** Time delay to the next update */
|
||||
} ObjectTimeInfo;
|
||||
|
||||
typedef struct {
|
||||
UAVObject* obj;
|
||||
EventMask event;
|
||||
bool allInstances;
|
||||
} ObjectQueueInfo;
|
||||
|
||||
typedef struct {
|
||||
UAVObject* obj;
|
||||
bool allInstances;
|
||||
bool objRequest;
|
||||
qint32 retriesRemaining;
|
||||
bool acked;
|
||||
} ObjectTransactionInfo;
|
||||
|
||||
// Variables
|
||||
UAVObjectManager* objMngr;
|
||||
UAVTalk* utalk;
|
||||
GCSTelemetryStats* gcsStatsObj;
|
||||
QList<ObjectTimeInfo> objList;
|
||||
QQueue<ObjectQueueInfo> objQueue;
|
||||
QQueue<ObjectQueueInfo> objPriorityQueue;
|
||||
ObjectTransactionInfo transInfo;
|
||||
bool transPending;
|
||||
QMutex* mutex;
|
||||
QTimer* updateTimer;
|
||||
QTimer* transTimer;
|
||||
QTimer* statsTimer;
|
||||
qint32 timeToNextUpdateMs;
|
||||
quint32 txErrors;
|
||||
quint32 txRetries;
|
||||
|
||||
// Methods
|
||||
void registerObject(UAVObject* obj);
|
||||
void addObject(UAVObject* obj);
|
||||
void setUpdatePeriod(UAVObject* obj, qint32 periodMs);
|
||||
void connectToObjectInstances(UAVObject* obj, quint32 eventMask);
|
||||
void updateObject(UAVObject* obj);
|
||||
void processObjectUpdates(UAVObject* obj, EventMask event, bool allInstances, bool priority);
|
||||
void processObjectTransaction();
|
||||
void processObjectQueue();
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // TELEMETRY_H
|
||||
|
@ -3,10 +3,9 @@
|
||||
*
|
||||
* @file telemetrymanager.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup
|
||||
* @defgroup uavtalkplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
@ -3,10 +3,9 @@
|
||||
*
|
||||
* @file telemetrymanager.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup
|
||||
* @defgroup uavtalkplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
@ -3,10 +3,9 @@
|
||||
*
|
||||
* @file telemetrymonitor.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup
|
||||
* @defgroup uavtalkplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
@ -3,10 +3,9 @@
|
||||
*
|
||||
* @file telemetrymonitor.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup
|
||||
* @defgroup uavtalkplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
@ -1,646 +1,645 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavtalk.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavtalk.h"
|
||||
#include <QtEndian>
|
||||
|
||||
const quint8 UAVTalk::crc_table[256] = {
|
||||
0x00, 0x07, 0x0e, 0x09, 0x1c, 0x1b, 0x12, 0x15, 0x38, 0x3f, 0x36, 0x31, 0x24, 0x23, 0x2a, 0x2d,
|
||||
0x70, 0x77, 0x7e, 0x79, 0x6c, 0x6b, 0x62, 0x65, 0x48, 0x4f, 0x46, 0x41, 0x54, 0x53, 0x5a, 0x5d,
|
||||
0xe0, 0xe7, 0xee, 0xe9, 0xfc, 0xfb, 0xf2, 0xf5, 0xd8, 0xdf, 0xd6, 0xd1, 0xc4, 0xc3, 0xca, 0xcd,
|
||||
0x90, 0x97, 0x9e, 0x99, 0x8c, 0x8b, 0x82, 0x85, 0xa8, 0xaf, 0xa6, 0xa1, 0xb4, 0xb3, 0xba, 0xbd,
|
||||
0xc7, 0xc0, 0xc9, 0xce, 0xdb, 0xdc, 0xd5, 0xd2, 0xff, 0xf8, 0xf1, 0xf6, 0xe3, 0xe4, 0xed, 0xea,
|
||||
0xb7, 0xb0, 0xb9, 0xbe, 0xab, 0xac, 0xa5, 0xa2, 0x8f, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9d, 0x9a,
|
||||
0x27, 0x20, 0x29, 0x2e, 0x3b, 0x3c, 0x35, 0x32, 0x1f, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0d, 0x0a,
|
||||
0x57, 0x50, 0x59, 0x5e, 0x4b, 0x4c, 0x45, 0x42, 0x6f, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7d, 0x7a,
|
||||
0x89, 0x8e, 0x87, 0x80, 0x95, 0x92, 0x9b, 0x9c, 0xb1, 0xb6, 0xbf, 0xb8, 0xad, 0xaa, 0xa3, 0xa4,
|
||||
0xf9, 0xfe, 0xf7, 0xf0, 0xe5, 0xe2, 0xeb, 0xec, 0xc1, 0xc6, 0xcf, 0xc8, 0xdd, 0xda, 0xd3, 0xd4,
|
||||
0x69, 0x6e, 0x67, 0x60, 0x75, 0x72, 0x7b, 0x7c, 0x51, 0x56, 0x5f, 0x58, 0x4d, 0x4a, 0x43, 0x44,
|
||||
0x19, 0x1e, 0x17, 0x10, 0x05, 0x02, 0x0b, 0x0c, 0x21, 0x26, 0x2f, 0x28, 0x3d, 0x3a, 0x33, 0x34,
|
||||
0x4e, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5c, 0x5b, 0x76, 0x71, 0x78, 0x7f, 0x6a, 0x6d, 0x64, 0x63,
|
||||
0x3e, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2c, 0x2b, 0x06, 0x01, 0x08, 0x0f, 0x1a, 0x1d, 0x14, 0x13,
|
||||
0xae, 0xa9, 0xa0, 0xa7, 0xb2, 0xb5, 0xbc, 0xbb, 0x96, 0x91, 0x98, 0x9f, 0x8a, 0x8d, 0x84, 0x83,
|
||||
0xde, 0xd9, 0xd0, 0xd7, 0xc2, 0xc5, 0xcc, 0xcb, 0xe6, 0xe1, 0xe8, 0xef, 0xfa, 0xfd, 0xf4, 0xf3
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
UAVTalk::UAVTalk(QIODevice* iodev, UAVObjectManager* objMngr)
|
||||
{
|
||||
io = iodev;
|
||||
this->objMngr = objMngr;
|
||||
rxState = STATE_SYNC;
|
||||
mutex = new QMutex(QMutex::Recursive);
|
||||
respObj = NULL;
|
||||
memset(&stats, 0, sizeof(ComStats));
|
||||
connect(io, SIGNAL(readyRead()), this, SLOT(processInputStream()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the statistics counters
|
||||
*/
|
||||
void UAVTalk::resetStats()
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
memset(&stats, 0, sizeof(ComStats));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the statistics counters
|
||||
*/
|
||||
UAVTalk::ComStats UAVTalk::getStats()
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
return stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called each time there are data in the input buffer
|
||||
*/
|
||||
void UAVTalk::processInputStream()
|
||||
{
|
||||
quint8 tmp;
|
||||
|
||||
while (io->bytesAvailable() > 0)
|
||||
{
|
||||
io->read((char*)&tmp, 1);
|
||||
processInputByte(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Request an update for the specified object, on success the object data would have been
|
||||
* updated by the GCS.
|
||||
* \param[in] obj Object to update
|
||||
* \param[in] allInstances If set true then all instances will be updated
|
||||
* \return Success (true), Failure (false)
|
||||
*/
|
||||
bool UAVTalk::sendObjectRequest(UAVObject* obj, bool allInstances)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
return objectTransaction(obj, TYPE_OBJ_REQ, allInstances);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the specified object through the telemetry link.
|
||||
* \param[in] obj Object to send
|
||||
* \param[in] acked Selects if an ack is required
|
||||
* \param[in] allInstances If set true then all instances will be updated
|
||||
* \return Success (true), Failure (false)
|
||||
*/
|
||||
bool UAVTalk::sendObject(UAVObject* obj, bool acked, bool allInstances)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
if (acked)
|
||||
{
|
||||
return objectTransaction(obj, TYPE_OBJ_ACK, allInstances);
|
||||
}
|
||||
else
|
||||
{
|
||||
return objectTransaction(obj, TYPE_OBJ, allInstances);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel a pending transaction
|
||||
*/
|
||||
void UAVTalk::cancelTransaction()
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
respObj = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the requested transaction on an object.
|
||||
* \param[in] obj Object
|
||||
* \param[in] type Transaction type
|
||||
* TYPE_OBJ: send object,
|
||||
* TYPE_OBJ_REQ: request object update
|
||||
* TYPE_OBJ_ACK: send object with an ack
|
||||
* \param[in] allInstances If set true then all instances will be updated
|
||||
* \return Success (true), Failure (false)
|
||||
*/
|
||||
bool UAVTalk::objectTransaction(UAVObject* obj, quint8 type, bool allInstances)
|
||||
{
|
||||
// Send object depending on if a response is needed
|
||||
if (type == TYPE_OBJ_ACK || type == TYPE_OBJ_REQ)
|
||||
{
|
||||
if ( transmitObject(obj, type, allInstances) )
|
||||
{
|
||||
respObj = obj;
|
||||
respAllInstances = allInstances;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (type == TYPE_OBJ)
|
||||
{
|
||||
return transmitObject(obj, TYPE_OBJ, allInstances);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process an byte from the telemetry stream.
|
||||
* \param[in] rxbyte Received byte
|
||||
* \return Success (true), Failure (false)
|
||||
*/
|
||||
bool UAVTalk::processInputByte(quint8 rxbyte)
|
||||
{
|
||||
// Update stats
|
||||
++stats.rxBytes;
|
||||
// Receive state machine
|
||||
switch (rxState) {
|
||||
case STATE_SYNC:
|
||||
if ((rxbyte & TYPE_MASK) == TYPE_VER )
|
||||
{
|
||||
rxCS = updateCRC(0, &rxbyte, 1);
|
||||
rxType = rxbyte;
|
||||
rxState = STATE_OBJID;
|
||||
rxCount = 0;
|
||||
}
|
||||
break;
|
||||
case STATE_OBJID:
|
||||
rxTmpBuffer[rxCount++] = rxbyte;
|
||||
if (rxCount == 4)
|
||||
{
|
||||
// Search for object, if not found reset state machine
|
||||
rxObjId = (qint32)qFromLittleEndian<quint32>(rxTmpBuffer);
|
||||
UAVObject* rxObj = objMngr->getObject(rxObjId);
|
||||
if (rxObj == NULL)
|
||||
{
|
||||
rxState = STATE_SYNC;
|
||||
++stats.rxErrors;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Update checksum
|
||||
rxCS = updateCRC(rxCS, rxTmpBuffer, 4);
|
||||
// Determine data length
|
||||
if (rxType == TYPE_OBJ_REQ || rxType == TYPE_ACK)
|
||||
{
|
||||
rxLength = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
rxLength = rxObj->getNumBytes();
|
||||
}
|
||||
// Check length and determine next state
|
||||
if (rxLength >= MAX_PAYLOAD_LENGTH)
|
||||
{
|
||||
rxState = STATE_SYNC;
|
||||
++stats.rxErrors;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check if this is a single instance object (i.e. if the instance ID field is coming next)
|
||||
if ( rxObj->isSingleInstance() )
|
||||
{
|
||||
// If there is a payload get it, otherwise receive checksum
|
||||
if (rxLength > 0)
|
||||
{
|
||||
rxState = STATE_DATA;
|
||||
}
|
||||
else
|
||||
{
|
||||
rxState = STATE_CS;
|
||||
}
|
||||
rxInstId = 0;
|
||||
rxCount = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
rxState = STATE_INSTID;
|
||||
rxCount = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case STATE_INSTID:
|
||||
rxTmpBuffer[rxCount++] = rxbyte;
|
||||
if (rxCount == 2)
|
||||
{
|
||||
rxInstId = (qint16)qFromLittleEndian<quint16>(rxTmpBuffer);
|
||||
rxCS = updateCRC(rxCS, rxTmpBuffer, 2);
|
||||
rxCount = 0;
|
||||
// If there is a payload get it, otherwise receive checksum
|
||||
if (rxLength > 0)
|
||||
{
|
||||
rxState = STATE_DATA;
|
||||
}
|
||||
else
|
||||
{
|
||||
rxState = STATE_CS;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case STATE_DATA:
|
||||
rxBuffer[rxCount++] = rxbyte;
|
||||
if (rxCount == rxLength)
|
||||
{
|
||||
rxCS = updateCRC(rxCS, rxBuffer, rxLength);
|
||||
rxState = STATE_CS;
|
||||
rxCount = 0;
|
||||
}
|
||||
break;
|
||||
case STATE_CS:
|
||||
rxCSPacket = rxbyte;
|
||||
if (rxCS == rxCSPacket)
|
||||
{
|
||||
mutex->lock();
|
||||
receiveObject(rxType, rxObjId, rxInstId, rxBuffer, rxLength);
|
||||
stats.rxObjectBytes += rxLength;
|
||||
++stats.rxObjects;
|
||||
mutex->unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
++stats.rxErrors;
|
||||
}
|
||||
rxState = STATE_SYNC;
|
||||
break;
|
||||
default:
|
||||
rxState = STATE_SYNC;
|
||||
++stats.rxErrors;
|
||||
}
|
||||
|
||||
// Done
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Receive an object. This function process objects received through the telemetry stream.
|
||||
* \param[in] type Type of received message (TYPE_OBJ, TYPE_OBJ_REQ, TYPE_OBJ_ACK, TYPE_ACK)
|
||||
* \param[in] obj Handle of the received object
|
||||
* \param[in] instId The instance ID of UAVOBJ_ALL_INSTANCES for all instances.
|
||||
* \param[in] data Data buffer
|
||||
* \param[in] length Buffer length
|
||||
* \return Success (true), Failure (false)
|
||||
*/
|
||||
bool UAVTalk::receiveObject(quint8 type, quint32 objId, quint16 instId, quint8* data, qint32 length)
|
||||
{
|
||||
UAVObject* obj = NULL;
|
||||
bool error = false;
|
||||
bool allInstances = (instId == ALL_INSTANCES? true : false);
|
||||
|
||||
// Process message type
|
||||
switch (type) {
|
||||
case TYPE_OBJ:
|
||||
// All instances, not allowed for OBJ messages
|
||||
if (!allInstances)
|
||||
{
|
||||
// Get object and update its data
|
||||
obj = updateObject(objId, instId, data);
|
||||
// Check if an ack is pending
|
||||
if ( obj != NULL )
|
||||
{
|
||||
updateAck(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
break;
|
||||
case TYPE_OBJ_ACK:
|
||||
// All instances, not allowed for OBJ_ACK messages
|
||||
if (!allInstances)
|
||||
{
|
||||
// Get object and update its data
|
||||
obj = updateObject(objId, instId, data);
|
||||
// Transmit ACK
|
||||
if ( obj != NULL )
|
||||
{
|
||||
transmitObject(obj, TYPE_ACK, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
break;
|
||||
case TYPE_OBJ_REQ:
|
||||
// Get object, if all instances are requested get instance 0 of the object
|
||||
if (allInstances)
|
||||
{
|
||||
obj = objMngr->getObject(objId);
|
||||
}
|
||||
else
|
||||
{
|
||||
obj = objMngr->getObject(objId, instId);
|
||||
}
|
||||
// If object was found transmit it
|
||||
if (obj != NULL)
|
||||
{
|
||||
transmitObject(obj, TYPE_OBJ, allInstances);
|
||||
}
|
||||
else
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
break;
|
||||
case TYPE_ACK:
|
||||
// All instances, not allowed for ACK messages
|
||||
if (!allInstances)
|
||||
{
|
||||
// Get object
|
||||
obj = objMngr->getObject(objId, instId);
|
||||
// Check if an ack is pending
|
||||
if (obj != NULL)
|
||||
{
|
||||
updateAck(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
error = true;
|
||||
}
|
||||
// Done
|
||||
return !error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the data of an object from a byte array (unpack).
|
||||
* If the object instance could not be found in the list, then a
|
||||
* new one is created.
|
||||
*/
|
||||
UAVObject* UAVTalk::updateObject(quint32 objId, quint16 instId, quint8* data)
|
||||
{
|
||||
// Get object
|
||||
UAVObject* obj = objMngr->getObject(objId, instId);
|
||||
// If the instance does not exist create it
|
||||
if (obj == NULL)
|
||||
{
|
||||
// Get the object type
|
||||
UAVObject* tobj = objMngr->getObject(objId);
|
||||
if (tobj == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
// Make sure this is a data object
|
||||
UAVDataObject* dobj = dynamic_cast<UAVDataObject*>(tobj);
|
||||
if (dobj == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
// Create a new instance, unpack and register
|
||||
UAVDataObject* instobj = dobj->clone(instId);
|
||||
if ( !objMngr->registerObject(instobj) )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
instobj->unpack(data);
|
||||
return instobj;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Unpack data into object instance
|
||||
obj->unpack(data);
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a transaction is pending and if yes complete it.
|
||||
*/
|
||||
void UAVTalk::updateAck(UAVObject* obj)
|
||||
{
|
||||
if (respObj != NULL && respObj->getObjID() == obj->getObjID() && (respObj->getInstID() == obj->getInstID() || respAllInstances))
|
||||
{
|
||||
respObj = NULL;
|
||||
emit transactionCompleted(obj);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an object through the telemetry link.
|
||||
* \param[in] obj Object to send
|
||||
* \param[in] type Transaction type
|
||||
* \param[in] allInstances True is all instances of the object are to be sent
|
||||
* \return Success (true), Failure (false)
|
||||
*/
|
||||
bool UAVTalk::transmitObject(UAVObject* obj, quint8 type, bool allInstances)
|
||||
{
|
||||
// If all instances are requested on a single instance object it is an error
|
||||
if (allInstances && obj->isSingleInstance())
|
||||
{
|
||||
allInstances = false;
|
||||
}
|
||||
|
||||
// Process message type
|
||||
if ( type == TYPE_OBJ || type == TYPE_OBJ_ACK )
|
||||
{
|
||||
if (allInstances)
|
||||
{
|
||||
// Get number of instances
|
||||
quint32 numInst = objMngr->getNumInstances(obj->getObjID());
|
||||
// Send all instances
|
||||
for (quint32 instId = 0; instId < numInst; ++instId)
|
||||
{
|
||||
UAVObject* inst = objMngr->getObject(obj->getObjID(), instId);
|
||||
transmitSingleObject(inst, type, false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return transmitSingleObject(obj, type, false);
|
||||
}
|
||||
}
|
||||
else if (type == TYPE_OBJ_REQ)
|
||||
{
|
||||
return transmitSingleObject(obj, TYPE_OBJ_REQ, allInstances);
|
||||
}
|
||||
else if (type == TYPE_ACK)
|
||||
{
|
||||
if (!allInstances)
|
||||
{
|
||||
return transmitSingleObject(obj, TYPE_ACK, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send an object through the telemetry link.
|
||||
* \param[in] obj Object handle to send
|
||||
* \param[in] type Transaction type
|
||||
* \return Success (true), Failure (false)
|
||||
*/
|
||||
bool UAVTalk::transmitSingleObject(UAVObject* obj, quint8 type, bool allInstances)
|
||||
{
|
||||
qint32 length;
|
||||
qint32 dataOffset;
|
||||
quint32 objId;
|
||||
quint16 instId;
|
||||
quint16 allInstId = ALL_INSTANCES;
|
||||
|
||||
// Setup type and object id fields
|
||||
objId = obj->getObjID();
|
||||
txBuffer[0] = type;
|
||||
qToLittleEndian<quint32>(objId, &txBuffer[1]);
|
||||
|
||||
// Setup instance ID if one is required
|
||||
if ( obj->isSingleInstance() )
|
||||
{
|
||||
dataOffset = 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check if all instances are requested
|
||||
if (allInstances)
|
||||
{
|
||||
qToLittleEndian<quint16>(allInstId, &txBuffer[5]);
|
||||
}
|
||||
else
|
||||
{
|
||||
instId = obj->getInstID();
|
||||
qToLittleEndian<quint16>(instId, &txBuffer[5]);
|
||||
}
|
||||
dataOffset = 7;
|
||||
}
|
||||
|
||||
// Determine data length
|
||||
if (type == TYPE_OBJ_REQ || type == TYPE_ACK)
|
||||
{
|
||||
length = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
length = obj->getNumBytes();
|
||||
}
|
||||
|
||||
// Check length
|
||||
if (length >= MAX_PAYLOAD_LENGTH)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Copy data (if any)
|
||||
if (length > 0)
|
||||
{
|
||||
if ( !obj->pack(&txBuffer[dataOffset]) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate checksum
|
||||
txBuffer[dataOffset+length] = updateCRC(0, txBuffer, dataOffset+length);
|
||||
|
||||
// Send buffer, check that the transmit backlog does not grow above limit
|
||||
if ( io->bytesToWrite() < TX_BUFFER_SIZE )
|
||||
{
|
||||
io->write((const char*)txBuffer, dataOffset+length+CHECKSUM_LENGTH);
|
||||
}
|
||||
else
|
||||
{
|
||||
++stats.txErrors;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Update stats
|
||||
++stats.txObjects;
|
||||
stats.txBytes += dataOffset+length+CHECKSUM_LENGTH;
|
||||
stats.txObjectBytes += length;
|
||||
|
||||
// Done
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the crc value with new data.
|
||||
*
|
||||
* Generated by pycrc v0.7.5, http://www.tty1.net/pycrc/
|
||||
* using the configuration:
|
||||
* Width = 8
|
||||
* Poly = 0x07
|
||||
* XorIn = 0x00
|
||||
* ReflectIn = False
|
||||
* XorOut = 0x00
|
||||
* ReflectOut = False
|
||||
* Algorithm = table-driven
|
||||
*
|
||||
* \param crc The current crc value.
|
||||
* \param data Pointer to a buffer of \a data_len bytes.
|
||||
* \param length Number of bytes in the \a data buffer.
|
||||
* \return The updated crc value.
|
||||
*/
|
||||
quint8 UAVTalk::updateCRC(quint8 crc, const quint8* data, qint32 length)
|
||||
{
|
||||
quint32 tbl_idx;
|
||||
|
||||
while (length--) {
|
||||
tbl_idx = ((crc >> 0) ^ *data) & 0xff;
|
||||
crc = (crc_table[tbl_idx] ^ (crc << 8)) & 0xff;
|
||||
data++;
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavtalk.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavtalkplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavtalk.h"
|
||||
#include <QtEndian>
|
||||
|
||||
const quint8 UAVTalk::crc_table[256] = {
|
||||
0x00, 0x07, 0x0e, 0x09, 0x1c, 0x1b, 0x12, 0x15, 0x38, 0x3f, 0x36, 0x31, 0x24, 0x23, 0x2a, 0x2d,
|
||||
0x70, 0x77, 0x7e, 0x79, 0x6c, 0x6b, 0x62, 0x65, 0x48, 0x4f, 0x46, 0x41, 0x54, 0x53, 0x5a, 0x5d,
|
||||
0xe0, 0xe7, 0xee, 0xe9, 0xfc, 0xfb, 0xf2, 0xf5, 0xd8, 0xdf, 0xd6, 0xd1, 0xc4, 0xc3, 0xca, 0xcd,
|
||||
0x90, 0x97, 0x9e, 0x99, 0x8c, 0x8b, 0x82, 0x85, 0xa8, 0xaf, 0xa6, 0xa1, 0xb4, 0xb3, 0xba, 0xbd,
|
||||
0xc7, 0xc0, 0xc9, 0xce, 0xdb, 0xdc, 0xd5, 0xd2, 0xff, 0xf8, 0xf1, 0xf6, 0xe3, 0xe4, 0xed, 0xea,
|
||||
0xb7, 0xb0, 0xb9, 0xbe, 0xab, 0xac, 0xa5, 0xa2, 0x8f, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9d, 0x9a,
|
||||
0x27, 0x20, 0x29, 0x2e, 0x3b, 0x3c, 0x35, 0x32, 0x1f, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0d, 0x0a,
|
||||
0x57, 0x50, 0x59, 0x5e, 0x4b, 0x4c, 0x45, 0x42, 0x6f, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7d, 0x7a,
|
||||
0x89, 0x8e, 0x87, 0x80, 0x95, 0x92, 0x9b, 0x9c, 0xb1, 0xb6, 0xbf, 0xb8, 0xad, 0xaa, 0xa3, 0xa4,
|
||||
0xf9, 0xfe, 0xf7, 0xf0, 0xe5, 0xe2, 0xeb, 0xec, 0xc1, 0xc6, 0xcf, 0xc8, 0xdd, 0xda, 0xd3, 0xd4,
|
||||
0x69, 0x6e, 0x67, 0x60, 0x75, 0x72, 0x7b, 0x7c, 0x51, 0x56, 0x5f, 0x58, 0x4d, 0x4a, 0x43, 0x44,
|
||||
0x19, 0x1e, 0x17, 0x10, 0x05, 0x02, 0x0b, 0x0c, 0x21, 0x26, 0x2f, 0x28, 0x3d, 0x3a, 0x33, 0x34,
|
||||
0x4e, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5c, 0x5b, 0x76, 0x71, 0x78, 0x7f, 0x6a, 0x6d, 0x64, 0x63,
|
||||
0x3e, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2c, 0x2b, 0x06, 0x01, 0x08, 0x0f, 0x1a, 0x1d, 0x14, 0x13,
|
||||
0xae, 0xa9, 0xa0, 0xa7, 0xb2, 0xb5, 0xbc, 0xbb, 0x96, 0x91, 0x98, 0x9f, 0x8a, 0x8d, 0x84, 0x83,
|
||||
0xde, 0xd9, 0xd0, 0xd7, 0xc2, 0xc5, 0xcc, 0xcb, 0xe6, 0xe1, 0xe8, 0xef, 0xfa, 0xfd, 0xf4, 0xf3
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
UAVTalk::UAVTalk(QIODevice* iodev, UAVObjectManager* objMngr)
|
||||
{
|
||||
io = iodev;
|
||||
this->objMngr = objMngr;
|
||||
rxState = STATE_SYNC;
|
||||
mutex = new QMutex(QMutex::Recursive);
|
||||
respObj = NULL;
|
||||
memset(&stats, 0, sizeof(ComStats));
|
||||
connect(io, SIGNAL(readyRead()), this, SLOT(processInputStream()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the statistics counters
|
||||
*/
|
||||
void UAVTalk::resetStats()
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
memset(&stats, 0, sizeof(ComStats));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the statistics counters
|
||||
*/
|
||||
UAVTalk::ComStats UAVTalk::getStats()
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
return stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called each time there are data in the input buffer
|
||||
*/
|
||||
void UAVTalk::processInputStream()
|
||||
{
|
||||
quint8 tmp;
|
||||
|
||||
while (io->bytesAvailable() > 0)
|
||||
{
|
||||
io->read((char*)&tmp, 1);
|
||||
processInputByte(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Request an update for the specified object, on success the object data would have been
|
||||
* updated by the GCS.
|
||||
* \param[in] obj Object to update
|
||||
* \param[in] allInstances If set true then all instances will be updated
|
||||
* \return Success (true), Failure (false)
|
||||
*/
|
||||
bool UAVTalk::sendObjectRequest(UAVObject* obj, bool allInstances)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
return objectTransaction(obj, TYPE_OBJ_REQ, allInstances);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the specified object through the telemetry link.
|
||||
* \param[in] obj Object to send
|
||||
* \param[in] acked Selects if an ack is required
|
||||
* \param[in] allInstances If set true then all instances will be updated
|
||||
* \return Success (true), Failure (false)
|
||||
*/
|
||||
bool UAVTalk::sendObject(UAVObject* obj, bool acked, bool allInstances)
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
if (acked)
|
||||
{
|
||||
return objectTransaction(obj, TYPE_OBJ_ACK, allInstances);
|
||||
}
|
||||
else
|
||||
{
|
||||
return objectTransaction(obj, TYPE_OBJ, allInstances);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel a pending transaction
|
||||
*/
|
||||
void UAVTalk::cancelTransaction()
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
respObj = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the requested transaction on an object.
|
||||
* \param[in] obj Object
|
||||
* \param[in] type Transaction type
|
||||
* TYPE_OBJ: send object,
|
||||
* TYPE_OBJ_REQ: request object update
|
||||
* TYPE_OBJ_ACK: send object with an ack
|
||||
* \param[in] allInstances If set true then all instances will be updated
|
||||
* \return Success (true), Failure (false)
|
||||
*/
|
||||
bool UAVTalk::objectTransaction(UAVObject* obj, quint8 type, bool allInstances)
|
||||
{
|
||||
// Send object depending on if a response is needed
|
||||
if (type == TYPE_OBJ_ACK || type == TYPE_OBJ_REQ)
|
||||
{
|
||||
if ( transmitObject(obj, type, allInstances) )
|
||||
{
|
||||
respObj = obj;
|
||||
respAllInstances = allInstances;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (type == TYPE_OBJ)
|
||||
{
|
||||
return transmitObject(obj, TYPE_OBJ, allInstances);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process an byte from the telemetry stream.
|
||||
* \param[in] rxbyte Received byte
|
||||
* \return Success (true), Failure (false)
|
||||
*/
|
||||
bool UAVTalk::processInputByte(quint8 rxbyte)
|
||||
{
|
||||
// Update stats
|
||||
++stats.rxBytes;
|
||||
// Receive state machine
|
||||
switch (rxState) {
|
||||
case STATE_SYNC:
|
||||
if ((rxbyte & TYPE_MASK) == TYPE_VER )
|
||||
{
|
||||
rxCS = updateCRC(0, &rxbyte, 1);
|
||||
rxType = rxbyte;
|
||||
rxState = STATE_OBJID;
|
||||
rxCount = 0;
|
||||
}
|
||||
break;
|
||||
case STATE_OBJID:
|
||||
rxTmpBuffer[rxCount++] = rxbyte;
|
||||
if (rxCount == 4)
|
||||
{
|
||||
// Search for object, if not found reset state machine
|
||||
rxObjId = (qint32)qFromLittleEndian<quint32>(rxTmpBuffer);
|
||||
UAVObject* rxObj = objMngr->getObject(rxObjId);
|
||||
if (rxObj == NULL)
|
||||
{
|
||||
rxState = STATE_SYNC;
|
||||
++stats.rxErrors;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Update checksum
|
||||
rxCS = updateCRC(rxCS, rxTmpBuffer, 4);
|
||||
// Determine data length
|
||||
if (rxType == TYPE_OBJ_REQ || rxType == TYPE_ACK)
|
||||
{
|
||||
rxLength = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
rxLength = rxObj->getNumBytes();
|
||||
}
|
||||
// Check length and determine next state
|
||||
if (rxLength >= MAX_PAYLOAD_LENGTH)
|
||||
{
|
||||
rxState = STATE_SYNC;
|
||||
++stats.rxErrors;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check if this is a single instance object (i.e. if the instance ID field is coming next)
|
||||
if ( rxObj->isSingleInstance() )
|
||||
{
|
||||
// If there is a payload get it, otherwise receive checksum
|
||||
if (rxLength > 0)
|
||||
{
|
||||
rxState = STATE_DATA;
|
||||
}
|
||||
else
|
||||
{
|
||||
rxState = STATE_CS;
|
||||
}
|
||||
rxInstId = 0;
|
||||
rxCount = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
rxState = STATE_INSTID;
|
||||
rxCount = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case STATE_INSTID:
|
||||
rxTmpBuffer[rxCount++] = rxbyte;
|
||||
if (rxCount == 2)
|
||||
{
|
||||
rxInstId = (qint16)qFromLittleEndian<quint16>(rxTmpBuffer);
|
||||
rxCS = updateCRC(rxCS, rxTmpBuffer, 2);
|
||||
rxCount = 0;
|
||||
// If there is a payload get it, otherwise receive checksum
|
||||
if (rxLength > 0)
|
||||
{
|
||||
rxState = STATE_DATA;
|
||||
}
|
||||
else
|
||||
{
|
||||
rxState = STATE_CS;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case STATE_DATA:
|
||||
rxBuffer[rxCount++] = rxbyte;
|
||||
if (rxCount == rxLength)
|
||||
{
|
||||
rxCS = updateCRC(rxCS, rxBuffer, rxLength);
|
||||
rxState = STATE_CS;
|
||||
rxCount = 0;
|
||||
}
|
||||
break;
|
||||
case STATE_CS:
|
||||
rxCSPacket = rxbyte;
|
||||
if (rxCS == rxCSPacket)
|
||||
{
|
||||
mutex->lock();
|
||||
receiveObject(rxType, rxObjId, rxInstId, rxBuffer, rxLength);
|
||||
stats.rxObjectBytes += rxLength;
|
||||
++stats.rxObjects;
|
||||
mutex->unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
++stats.rxErrors;
|
||||
}
|
||||
rxState = STATE_SYNC;
|
||||
break;
|
||||
default:
|
||||
rxState = STATE_SYNC;
|
||||
++stats.rxErrors;
|
||||
}
|
||||
|
||||
// Done
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Receive an object. This function process objects received through the telemetry stream.
|
||||
* \param[in] type Type of received message (TYPE_OBJ, TYPE_OBJ_REQ, TYPE_OBJ_ACK, TYPE_ACK)
|
||||
* \param[in] obj Handle of the received object
|
||||
* \param[in] instId The instance ID of UAVOBJ_ALL_INSTANCES for all instances.
|
||||
* \param[in] data Data buffer
|
||||
* \param[in] length Buffer length
|
||||
* \return Success (true), Failure (false)
|
||||
*/
|
||||
bool UAVTalk::receiveObject(quint8 type, quint32 objId, quint16 instId, quint8* data, qint32 length)
|
||||
{
|
||||
UAVObject* obj = NULL;
|
||||
bool error = false;
|
||||
bool allInstances = (instId == ALL_INSTANCES? true : false);
|
||||
|
||||
// Process message type
|
||||
switch (type) {
|
||||
case TYPE_OBJ:
|
||||
// All instances, not allowed for OBJ messages
|
||||
if (!allInstances)
|
||||
{
|
||||
// Get object and update its data
|
||||
obj = updateObject(objId, instId, data);
|
||||
// Check if an ack is pending
|
||||
if ( obj != NULL )
|
||||
{
|
||||
updateAck(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
break;
|
||||
case TYPE_OBJ_ACK:
|
||||
// All instances, not allowed for OBJ_ACK messages
|
||||
if (!allInstances)
|
||||
{
|
||||
// Get object and update its data
|
||||
obj = updateObject(objId, instId, data);
|
||||
// Transmit ACK
|
||||
if ( obj != NULL )
|
||||
{
|
||||
transmitObject(obj, TYPE_ACK, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
break;
|
||||
case TYPE_OBJ_REQ:
|
||||
// Get object, if all instances are requested get instance 0 of the object
|
||||
if (allInstances)
|
||||
{
|
||||
obj = objMngr->getObject(objId);
|
||||
}
|
||||
else
|
||||
{
|
||||
obj = objMngr->getObject(objId, instId);
|
||||
}
|
||||
// If object was found transmit it
|
||||
if (obj != NULL)
|
||||
{
|
||||
transmitObject(obj, TYPE_OBJ, allInstances);
|
||||
}
|
||||
else
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
break;
|
||||
case TYPE_ACK:
|
||||
// All instances, not allowed for ACK messages
|
||||
if (!allInstances)
|
||||
{
|
||||
// Get object
|
||||
obj = objMngr->getObject(objId, instId);
|
||||
// Check if an ack is pending
|
||||
if (obj != NULL)
|
||||
{
|
||||
updateAck(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
error = true;
|
||||
}
|
||||
// Done
|
||||
return !error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the data of an object from a byte array (unpack).
|
||||
* If the object instance could not be found in the list, then a
|
||||
* new one is created.
|
||||
*/
|
||||
UAVObject* UAVTalk::updateObject(quint32 objId, quint16 instId, quint8* data)
|
||||
{
|
||||
// Get object
|
||||
UAVObject* obj = objMngr->getObject(objId, instId);
|
||||
// If the instance does not exist create it
|
||||
if (obj == NULL)
|
||||
{
|
||||
// Get the object type
|
||||
UAVObject* tobj = objMngr->getObject(objId);
|
||||
if (tobj == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
// Make sure this is a data object
|
||||
UAVDataObject* dobj = dynamic_cast<UAVDataObject*>(tobj);
|
||||
if (dobj == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
// Create a new instance, unpack and register
|
||||
UAVDataObject* instobj = dobj->clone(instId);
|
||||
if ( !objMngr->registerObject(instobj) )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
instobj->unpack(data);
|
||||
return instobj;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Unpack data into object instance
|
||||
obj->unpack(data);
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a transaction is pending and if yes complete it.
|
||||
*/
|
||||
void UAVTalk::updateAck(UAVObject* obj)
|
||||
{
|
||||
if (respObj != NULL && respObj->getObjID() == obj->getObjID() && (respObj->getInstID() == obj->getInstID() || respAllInstances))
|
||||
{
|
||||
respObj = NULL;
|
||||
emit transactionCompleted(obj);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an object through the telemetry link.
|
||||
* \param[in] obj Object to send
|
||||
* \param[in] type Transaction type
|
||||
* \param[in] allInstances True is all instances of the object are to be sent
|
||||
* \return Success (true), Failure (false)
|
||||
*/
|
||||
bool UAVTalk::transmitObject(UAVObject* obj, quint8 type, bool allInstances)
|
||||
{
|
||||
// If all instances are requested on a single instance object it is an error
|
||||
if (allInstances && obj->isSingleInstance())
|
||||
{
|
||||
allInstances = false;
|
||||
}
|
||||
|
||||
// Process message type
|
||||
if ( type == TYPE_OBJ || type == TYPE_OBJ_ACK )
|
||||
{
|
||||
if (allInstances)
|
||||
{
|
||||
// Get number of instances
|
||||
quint32 numInst = objMngr->getNumInstances(obj->getObjID());
|
||||
// Send all instances
|
||||
for (quint32 instId = 0; instId < numInst; ++instId)
|
||||
{
|
||||
UAVObject* inst = objMngr->getObject(obj->getObjID(), instId);
|
||||
transmitSingleObject(inst, type, false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return transmitSingleObject(obj, type, false);
|
||||
}
|
||||
}
|
||||
else if (type == TYPE_OBJ_REQ)
|
||||
{
|
||||
return transmitSingleObject(obj, TYPE_OBJ_REQ, allInstances);
|
||||
}
|
||||
else if (type == TYPE_ACK)
|
||||
{
|
||||
if (!allInstances)
|
||||
{
|
||||
return transmitSingleObject(obj, TYPE_ACK, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send an object through the telemetry link.
|
||||
* \param[in] obj Object handle to send
|
||||
* \param[in] type Transaction type
|
||||
* \return Success (true), Failure (false)
|
||||
*/
|
||||
bool UAVTalk::transmitSingleObject(UAVObject* obj, quint8 type, bool allInstances)
|
||||
{
|
||||
qint32 length;
|
||||
qint32 dataOffset;
|
||||
quint32 objId;
|
||||
quint16 instId;
|
||||
quint16 allInstId = ALL_INSTANCES;
|
||||
|
||||
// Setup type and object id fields
|
||||
objId = obj->getObjID();
|
||||
txBuffer[0] = type;
|
||||
qToLittleEndian<quint32>(objId, &txBuffer[1]);
|
||||
|
||||
// Setup instance ID if one is required
|
||||
if ( obj->isSingleInstance() )
|
||||
{
|
||||
dataOffset = 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check if all instances are requested
|
||||
if (allInstances)
|
||||
{
|
||||
qToLittleEndian<quint16>(allInstId, &txBuffer[5]);
|
||||
}
|
||||
else
|
||||
{
|
||||
instId = obj->getInstID();
|
||||
qToLittleEndian<quint16>(instId, &txBuffer[5]);
|
||||
}
|
||||
dataOffset = 7;
|
||||
}
|
||||
|
||||
// Determine data length
|
||||
if (type == TYPE_OBJ_REQ || type == TYPE_ACK)
|
||||
{
|
||||
length = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
length = obj->getNumBytes();
|
||||
}
|
||||
|
||||
// Check length
|
||||
if (length >= MAX_PAYLOAD_LENGTH)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Copy data (if any)
|
||||
if (length > 0)
|
||||
{
|
||||
if ( !obj->pack(&txBuffer[dataOffset]) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate checksum
|
||||
txBuffer[dataOffset+length] = updateCRC(0, txBuffer, dataOffset+length);
|
||||
|
||||
// Send buffer, check that the transmit backlog does not grow above limit
|
||||
if ( io->bytesToWrite() < TX_BUFFER_SIZE )
|
||||
{
|
||||
io->write((const char*)txBuffer, dataOffset+length+CHECKSUM_LENGTH);
|
||||
}
|
||||
else
|
||||
{
|
||||
++stats.txErrors;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Update stats
|
||||
++stats.txObjects;
|
||||
stats.txBytes += dataOffset+length+CHECKSUM_LENGTH;
|
||||
stats.txObjectBytes += length;
|
||||
|
||||
// Done
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the crc value with new data.
|
||||
*
|
||||
* Generated by pycrc v0.7.5, http://www.tty1.net/pycrc/
|
||||
* using the configuration:
|
||||
* Width = 8
|
||||
* Poly = 0x07
|
||||
* XorIn = 0x00
|
||||
* ReflectIn = False
|
||||
* XorOut = 0x00
|
||||
* ReflectOut = False
|
||||
* Algorithm = table-driven
|
||||
*
|
||||
* \param crc The current crc value.
|
||||
* \param data Pointer to a buffer of \a data_len bytes.
|
||||
* \param length Number of bytes in the \a data buffer.
|
||||
* \return The updated crc value.
|
||||
*/
|
||||
quint8 UAVTalk::updateCRC(quint8 crc, const quint8* data, qint32 length)
|
||||
{
|
||||
quint32 tbl_idx;
|
||||
|
||||
while (length--) {
|
||||
tbl_idx = ((crc >> 0) ^ *data) & 0xff;
|
||||
crc = (crc_table[tbl_idx] ^ (crc << 8)) & 0xff;
|
||||
data++;
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,117 +1,116 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavtalk.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef UAVTALK_H
|
||||
#define UAVTALK_H
|
||||
|
||||
#include <QIODevice>
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
#include <QSemaphore>
|
||||
#include "uavobjects/uavobjectmanager.h"
|
||||
|
||||
class UAVTalk: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
typedef struct {
|
||||
quint32 txBytes;
|
||||
quint32 rxBytes;
|
||||
quint32 txObjectBytes;
|
||||
quint32 rxObjectBytes;
|
||||
quint32 rxObjects;
|
||||
quint32 txObjects;
|
||||
quint32 txErrors;
|
||||
quint32 rxErrors;
|
||||
} ComStats;
|
||||
|
||||
UAVTalk(QIODevice* iodev, UAVObjectManager* objMngr);
|
||||
|
||||
bool sendObject(UAVObject* obj, bool acked, bool allInstances);
|
||||
bool sendObjectRequest(UAVObject* obj, bool allInstances);
|
||||
void cancelTransaction();
|
||||
ComStats getStats();
|
||||
void resetStats();
|
||||
|
||||
signals:
|
||||
void transactionCompleted(UAVObject* obj);
|
||||
|
||||
private slots:
|
||||
void processInputStream(void);
|
||||
|
||||
private:
|
||||
// Constants
|
||||
static const int TYPE_MASK = 0xFC;
|
||||
static const int TYPE_VER = 0x10;
|
||||
static const int TYPE_OBJ = (TYPE_VER | 0x00);
|
||||
static const int TYPE_OBJ_REQ = (TYPE_VER | 0x01);
|
||||
static const int TYPE_OBJ_ACK = (TYPE_VER | 0x02);
|
||||
static const int TYPE_ACK = (TYPE_VER | 0x03);
|
||||
static const int HEADER_LENGTH = 7; // type (1), object ID (4), instance ID (2, not used in single objects)
|
||||
static const int CHECKSUM_LENGTH = 1;
|
||||
static const int MAX_PAYLOAD_LENGTH = 256;
|
||||
static const int MAX_PACKET_LENGTH = (HEADER_LENGTH+MAX_PAYLOAD_LENGTH+CHECKSUM_LENGTH);
|
||||
static const quint16 ALL_INSTANCES = 0xFFFF;
|
||||
static const int TX_BUFFER_SIZE = 2*1024;
|
||||
static const quint8 crc_table[256];
|
||||
|
||||
// Types
|
||||
typedef enum {STATE_SYNC, STATE_OBJID, STATE_INSTID, STATE_DATA, STATE_CS} RxStateType;
|
||||
|
||||
// Variables
|
||||
QIODevice* io;
|
||||
UAVObjectManager* objMngr;
|
||||
QMutex* mutex;
|
||||
UAVObject* respObj;
|
||||
bool respAllInstances;
|
||||
quint8 rxBuffer[MAX_PACKET_LENGTH];
|
||||
quint8 txBuffer[MAX_PACKET_LENGTH];
|
||||
// Variables used by the receive state machine
|
||||
quint8 rxTmpBuffer[4];
|
||||
quint8 rxType;
|
||||
quint32 rxObjId;
|
||||
quint16 rxInstId;
|
||||
quint8 rxLength;
|
||||
quint8 rxCSPacket, rxCS;
|
||||
qint32 rxCount;
|
||||
RxStateType rxState;
|
||||
ComStats stats;
|
||||
|
||||
// Methods
|
||||
bool objectTransaction(UAVObject* obj, quint8 type, bool allInstances);
|
||||
bool processInputByte(quint8 rxbyte);
|
||||
bool receiveObject(quint8 type, quint32 objId, quint16 instId, quint8* data, qint32 length);
|
||||
UAVObject* updateObject(quint32 objId, quint16 instId, quint8* data);
|
||||
void updateAck(UAVObject* obj);
|
||||
bool transmitObject(UAVObject* obj, quint8 type, bool allInstances);
|
||||
bool transmitSingleObject(UAVObject* obj, quint8 type, bool allInstances);
|
||||
quint8 updateCRC(quint8 crc, const quint8* data, qint32 length);
|
||||
|
||||
};
|
||||
|
||||
#endif // UAVTALK_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavtalk.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavtalkplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef UAVTALK_H
|
||||
#define UAVTALK_H
|
||||
|
||||
#include <QIODevice>
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
#include <QSemaphore>
|
||||
#include "uavobjects/uavobjectmanager.h"
|
||||
|
||||
class UAVTalk: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
typedef struct {
|
||||
quint32 txBytes;
|
||||
quint32 rxBytes;
|
||||
quint32 txObjectBytes;
|
||||
quint32 rxObjectBytes;
|
||||
quint32 rxObjects;
|
||||
quint32 txObjects;
|
||||
quint32 txErrors;
|
||||
quint32 rxErrors;
|
||||
} ComStats;
|
||||
|
||||
UAVTalk(QIODevice* iodev, UAVObjectManager* objMngr);
|
||||
|
||||
bool sendObject(UAVObject* obj, bool acked, bool allInstances);
|
||||
bool sendObjectRequest(UAVObject* obj, bool allInstances);
|
||||
void cancelTransaction();
|
||||
ComStats getStats();
|
||||
void resetStats();
|
||||
|
||||
signals:
|
||||
void transactionCompleted(UAVObject* obj);
|
||||
|
||||
private slots:
|
||||
void processInputStream(void);
|
||||
|
||||
private:
|
||||
// Constants
|
||||
static const int TYPE_MASK = 0xFC;
|
||||
static const int TYPE_VER = 0x10;
|
||||
static const int TYPE_OBJ = (TYPE_VER | 0x00);
|
||||
static const int TYPE_OBJ_REQ = (TYPE_VER | 0x01);
|
||||
static const int TYPE_OBJ_ACK = (TYPE_VER | 0x02);
|
||||
static const int TYPE_ACK = (TYPE_VER | 0x03);
|
||||
static const int HEADER_LENGTH = 7; // type (1), object ID (4), instance ID (2, not used in single objects)
|
||||
static const int CHECKSUM_LENGTH = 1;
|
||||
static const int MAX_PAYLOAD_LENGTH = 256;
|
||||
static const int MAX_PACKET_LENGTH = (HEADER_LENGTH+MAX_PAYLOAD_LENGTH+CHECKSUM_LENGTH);
|
||||
static const quint16 ALL_INSTANCES = 0xFFFF;
|
||||
static const int TX_BUFFER_SIZE = 2*1024;
|
||||
static const quint8 crc_table[256];
|
||||
|
||||
// Types
|
||||
typedef enum {STATE_SYNC, STATE_OBJID, STATE_INSTID, STATE_DATA, STATE_CS} RxStateType;
|
||||
|
||||
// Variables
|
||||
QIODevice* io;
|
||||
UAVObjectManager* objMngr;
|
||||
QMutex* mutex;
|
||||
UAVObject* respObj;
|
||||
bool respAllInstances;
|
||||
quint8 rxBuffer[MAX_PACKET_LENGTH];
|
||||
quint8 txBuffer[MAX_PACKET_LENGTH];
|
||||
// Variables used by the receive state machine
|
||||
quint8 rxTmpBuffer[4];
|
||||
quint8 rxType;
|
||||
quint32 rxObjId;
|
||||
quint16 rxInstId;
|
||||
quint8 rxLength;
|
||||
quint8 rxCSPacket, rxCS;
|
||||
qint32 rxCount;
|
||||
RxStateType rxState;
|
||||
ComStats stats;
|
||||
|
||||
// Methods
|
||||
bool objectTransaction(UAVObject* obj, quint8 type, bool allInstances);
|
||||
bool processInputByte(quint8 rxbyte);
|
||||
bool receiveObject(quint8 type, quint32 objId, quint16 instId, quint8* data, qint32 length);
|
||||
UAVObject* updateObject(quint32 objId, quint16 instId, quint8* data);
|
||||
void updateAck(UAVObject* obj);
|
||||
bool transmitObject(UAVObject* obj, quint8 type, bool allInstances);
|
||||
bool transmitSingleObject(UAVObject* obj, quint8 type, bool allInstances);
|
||||
quint8 updateCRC(quint8 crc, const quint8* data, qint32 length);
|
||||
|
||||
};
|
||||
|
||||
#endif // UAVTALK_H
|
||||
|
@ -1,40 +1,39 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjects_global.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UAVTALK_GLOBAL_H
|
||||
#define UAVTALK_GLOBAL_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#if defined(UAVTALK_LIBRARY)
|
||||
# define UAVTALK_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
# define UAVTALK_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
#endif // UAVTALK_GLOBAL_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjects_global.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavtalkplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UAVTALK_GLOBAL_H
|
||||
#define UAVTALK_GLOBAL_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#if defined(UAVTALK_LIBRARY)
|
||||
# define UAVTALK_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
# define UAVTALK_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
#endif // UAVTALK_GLOBAL_H
|
||||
|
@ -1,84 +1,83 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavtalkplugin.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavtalkplugin.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/connectionmanager.h>
|
||||
|
||||
UAVTalkPlugin::UAVTalkPlugin()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
UAVTalkPlugin::~UAVTalkPlugin()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void UAVTalkPlugin::extensionsInitialized()
|
||||
{
|
||||
// Get UAVObjectManager instance
|
||||
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
|
||||
objMngr = pm->getObject<UAVObjectManager>();
|
||||
|
||||
// Create TelemetryManager
|
||||
telMngr = new TelemetryManager();
|
||||
addAutoReleasedObject(telMngr);
|
||||
|
||||
// Connect to connection manager so we get notified when the user connect to his device
|
||||
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
|
||||
QObject::connect(cm, SIGNAL(deviceConnected(QIODevice *)),
|
||||
this, SLOT(onDeviceConnect(QIODevice *)));
|
||||
QObject::connect(cm, SIGNAL(deviceDisconnected()),
|
||||
this, SLOT(onDeviceDisconnect()));
|
||||
}
|
||||
|
||||
bool UAVTalkPlugin::initialize(const QStringList & arguments, QString * errorString)
|
||||
{
|
||||
// Done
|
||||
Q_UNUSED(arguments);
|
||||
Q_UNUSED(errorString);
|
||||
return true;
|
||||
}
|
||||
|
||||
void UAVTalkPlugin::shutdown()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void UAVTalkPlugin::onDeviceConnect(QIODevice *dev)
|
||||
{
|
||||
telMngr->start(dev);
|
||||
}
|
||||
|
||||
void UAVTalkPlugin::onDeviceDisconnect()
|
||||
{
|
||||
telMngr->stop();
|
||||
}
|
||||
|
||||
Q_EXPORT_PLUGIN(UAVTalkPlugin)
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavtalkplugin.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavtalkplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavtalkplugin.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/connectionmanager.h>
|
||||
|
||||
UAVTalkPlugin::UAVTalkPlugin()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
UAVTalkPlugin::~UAVTalkPlugin()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void UAVTalkPlugin::extensionsInitialized()
|
||||
{
|
||||
// Get UAVObjectManager instance
|
||||
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
|
||||
objMngr = pm->getObject<UAVObjectManager>();
|
||||
|
||||
// Create TelemetryManager
|
||||
telMngr = new TelemetryManager();
|
||||
addAutoReleasedObject(telMngr);
|
||||
|
||||
// Connect to connection manager so we get notified when the user connect to his device
|
||||
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
|
||||
QObject::connect(cm, SIGNAL(deviceConnected(QIODevice *)),
|
||||
this, SLOT(onDeviceConnect(QIODevice *)));
|
||||
QObject::connect(cm, SIGNAL(deviceDisconnected()),
|
||||
this, SLOT(onDeviceDisconnect()));
|
||||
}
|
||||
|
||||
bool UAVTalkPlugin::initialize(const QStringList & arguments, QString * errorString)
|
||||
{
|
||||
// Done
|
||||
Q_UNUSED(arguments);
|
||||
Q_UNUSED(errorString);
|
||||
return true;
|
||||
}
|
||||
|
||||
void UAVTalkPlugin::shutdown()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void UAVTalkPlugin::onDeviceConnect(QIODevice *dev)
|
||||
{
|
||||
telMngr->start(dev);
|
||||
}
|
||||
|
||||
void UAVTalkPlugin::onDeviceDisconnect()
|
||||
{
|
||||
telMngr->stop();
|
||||
}
|
||||
|
||||
Q_EXPORT_PLUGIN(UAVTalkPlugin)
|
||||
|
@ -1,61 +1,60 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavtalkplugin.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef UAVTALKPLUGIN_H
|
||||
#define UAVTALKPLUGIN_H
|
||||
|
||||
#include <extensionsystem/iplugin.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <QtPlugin>
|
||||
#include "telemetrymonitor.h"
|
||||
#include "telemetry.h"
|
||||
#include "uavtalk.h"
|
||||
#include "telemetrymanager.h"
|
||||
#include "uavobjects/uavobjectmanager.h"
|
||||
|
||||
class UAVTALK_EXPORT UAVTalkPlugin: public ExtensionSystem::IPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UAVTalkPlugin();
|
||||
~UAVTalkPlugin();
|
||||
|
||||
void extensionsInitialized();
|
||||
bool initialize(const QStringList & arguments, QString * errorString);
|
||||
void shutdown();
|
||||
|
||||
protected slots:
|
||||
void onDeviceConnect(QIODevice *dev);
|
||||
void onDeviceDisconnect();
|
||||
|
||||
private:
|
||||
UAVObjectManager* objMngr;
|
||||
TelemetryManager* telMngr;
|
||||
};
|
||||
|
||||
#endif // UAVTALKPLUGIN_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavtalkplugin.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavtalkplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef UAVTALKPLUGIN_H
|
||||
#define UAVTALKPLUGIN_H
|
||||
|
||||
#include <extensionsystem/iplugin.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <QtPlugin>
|
||||
#include "telemetrymonitor.h"
|
||||
#include "telemetry.h"
|
||||
#include "uavtalk.h"
|
||||
#include "telemetrymanager.h"
|
||||
#include "uavobjects/uavobjectmanager.h"
|
||||
|
||||
class UAVTALK_EXPORT UAVTalkPlugin: public ExtensionSystem::IPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UAVTalkPlugin();
|
||||
~UAVTalkPlugin();
|
||||
|
||||
void extensionsInitialized();
|
||||
bool initialize(const QStringList & arguments, QString * errorString);
|
||||
void shutdown();
|
||||
|
||||
protected slots:
|
||||
void onDeviceConnect(QIODevice *dev);
|
||||
void onDeviceDisconnect();
|
||||
|
||||
private:
|
||||
UAVObjectManager* objMngr;
|
||||
TelemetryManager* telMngr;
|
||||
};
|
||||
|
||||
#endif // UAVTALKPLUGIN_H
|
||||
|
@ -5,7 +5,7 @@
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Uploader Plugin Gadget
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup Uploader
|
||||
* @defgroup uploaderplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
@ -5,7 +5,7 @@
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Uploader Plugin Gadget configuration
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup Uploader
|
||||
* @defgroup uploaderplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
@ -5,7 +5,7 @@
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Uploader Plugin Gadget configuration
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup Uploader
|
||||
* @defgroup uploaderplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
@ -5,7 +5,7 @@
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Uploader Plugin Gadget configuration
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup Uploader
|
||||
* @defgroup uploaderplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
@ -5,7 +5,7 @@
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Uploader Plugin Gadget factory
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup Uploader
|
||||
* @defgroup uploaderplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
@ -5,7 +5,7 @@
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Uploader Plugin Gadget factory
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup Uploader
|
||||
* @defgroup uploaderplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
@ -5,7 +5,7 @@
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Uploader Plugin Gadget options page
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup Uploader
|
||||
* @defgroup uploaderplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
@ -5,7 +5,7 @@
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Uploader Plugin Gadget options page
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup Uploader
|
||||
* @defgroup uploaderplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
@ -5,7 +5,7 @@
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Uploader Plugin Gadget widget
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup Uploader
|
||||
* @defgroup uploaderplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
@ -5,7 +5,7 @@
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Uploader Plugin Gadget widget
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup Uploader
|
||||
* @defgroup uploaderplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
@ -6,7 +6,7 @@
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief A plugin to upload a file using y-modem protocol and a serial port
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup Uploader
|
||||
* @defgroup uploaderplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
@ -5,7 +5,7 @@
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief A plugin to upload a file using y-modem protocol and a serial port
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup Uploader
|
||||
* @defgroup uploaderplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
Loading…
Reference in New Issue
Block a user