1
0
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:
dankers 2010-06-23 02:33:53 +00:00 committed by dankers
parent 61c7be7765
commit 882cd5d006
82 changed files with 6976 additions and 7002 deletions

View File

@ -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> <vendor>The OpenPilot Project</vendor>
<copyright>(C) 2010 OpenPilot Project</copyright> <copyright>(C) 2010 OpenPilot Project</copyright>
<license>Your License goes here</license> <license>Your License goes here</license>

View File

@ -5,7 +5,7 @@
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief QIODevice interface for USB RawHID * @brief QIODevice interface for USB RawHID
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup rawhid_plugin * @defgroup rawhidplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/

View File

@ -5,7 +5,7 @@
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup rawhid_plugin * @defgroup rawhidplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/

View File

@ -5,7 +5,7 @@
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup rawhid_plugin * @defgroup rawhidplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/

View File

@ -1,39 +1,39 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file rawhid_global.h * @file rawhid_global.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup rawhid_plugin * @defgroup rawhidplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef RAWHID_GLOBAL_H #ifndef RAWHID_GLOBAL_H
#define RAWHID_GLOBAL_H #define RAWHID_GLOBAL_H
#include <QtCore/qglobal.h> #include <QtCore/qglobal.h>
#if defined(RAWHID_LIBRARY) #if defined(RAWHID_LIBRARY)
# define RAWHID_EXPORT Q_DECL_EXPORT # define RAWHID_EXPORT Q_DECL_EXPORT
#else #else
# define RAWHID_EXPORT Q_DECL_IMPORT # define RAWHID_EXPORT Q_DECL_IMPORT
#endif #endif
#endif // RAWHID_GLOBAL_H #endif // RAWHID_GLOBAL_H

View File

@ -1,202 +1,202 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file rawhidplugin.cpp * @file rawhidplugin.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Register connection object for the core connection manager * @brief Register connection object for the core connection manager
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup rawhid_plugin * @defgroup rawhidplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "rawhidplugin.h" #include "rawhidplugin.h"
#include "rawhid.h" #include "rawhid.h"
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
#include <QtCore/QtPlugin> #include <QtCore/QtPlugin>
#include <QtCore/QMutexLocker> #include <QtCore/QMutexLocker>
#include "pjrc_rawhid.h" #include "pjrc_rawhid.h"
#include "rawhid_const.h" #include "rawhid_const.h"
RawHIDEnumerationThread::RawHIDEnumerationThread(RawHIDConnection *rawhid) RawHIDEnumerationThread::RawHIDEnumerationThread(RawHIDConnection *rawhid)
: m_rawhid(rawhid), : m_rawhid(rawhid),
m_running(true) m_running(true)
{ {
} }
RawHIDEnumerationThread::~RawHIDEnumerationThread() RawHIDEnumerationThread::~RawHIDEnumerationThread()
{ {
m_running = false; m_running = false;
//wait for the thread to terminate //wait for the thread to terminate
if(wait(1000) == false) if(wait(1000) == false)
qDebug() << "Cannot terminate RawHIDEnumerationThread"; qDebug() << "Cannot terminate RawHIDEnumerationThread";
} }
void RawHIDEnumerationThread::run() void RawHIDEnumerationThread::run()
{ {
QStringList devices = m_rawhid->availableDevices(); QStringList devices = m_rawhid->availableDevices();
while(m_running) while(m_running)
{ {
if(!m_rawhid->deviceOpened()) if(!m_rawhid->deviceOpened())
{ {
QStringList newDev = m_rawhid->availableDevices(); QStringList newDev = m_rawhid->availableDevices();
if(devices != newDev) if(devices != newDev)
{ {
devices = newDev; devices = newDev;
emit enumerationChanged(); emit enumerationChanged();
} }
} }
msleep(500); //update available devices twice per second (doesn't need more) msleep(500); //update available devices twice per second (doesn't need more)
} }
} }
RawHIDConnection::RawHIDConnection() RawHIDConnection::RawHIDConnection()
: m_enumerateThread(this) : m_enumerateThread(this)
{ {
QObject::connect(&m_enumerateThread, SIGNAL(enumerationChanged()), QObject::connect(&m_enumerateThread, SIGNAL(enumerationChanged()),
this, SLOT(onEnumerationChanged())); this, SLOT(onEnumerationChanged()));
m_enumerateThread.start(); m_enumerateThread.start();
} }
RawHIDConnection::~RawHIDConnection() RawHIDConnection::~RawHIDConnection()
{} {}
void RawHIDConnection::onEnumerationChanged() void RawHIDConnection::onEnumerationChanged()
{ {
emit availableDevChanged(this); emit availableDevChanged(this);
} }
QStringList RawHIDConnection::availableDevices() QStringList RawHIDConnection::availableDevices()
{ {
QMutexLocker locker(&m_enumMutex); QMutexLocker locker(&m_enumMutex);
QStringList devices; QStringList devices;
pjrc_rawhid dev; pjrc_rawhid dev;
//open all device we can //open all device we can
int opened = dev.open(MAX_DEVICES, VID, PID, USAGE_PAGE, USAGE); int opened = dev.open(MAX_DEVICES, VID, PID, USAGE_PAGE, USAGE);
//for each devices found, get serial number and close it back //for each devices found, get serial number and close it back
for(int i=0; i<opened; i++) for(int i=0; i<opened; i++)
{ {
char serial[256]; char serial[256];
dev.getserial(i, serial); dev.getserial(i, serial);
devices.append(QString::fromAscii(serial, DEV_SERIAL_LEN)); devices.append(QString::fromAscii(serial, DEV_SERIAL_LEN));
dev.close(i); dev.close(i);
} }
return devices; return devices;
} }
QIODevice *RawHIDConnection::openDevice(const QString &deviceName) QIODevice *RawHIDConnection::openDevice(const QString &deviceName)
{ {
m_deviceOpened = true; m_deviceOpened = true;
return new RawHID(deviceName); return new RawHID(deviceName);
} }
void RawHIDConnection::closeDevice(const QString &deviceName) void RawHIDConnection::closeDevice(const QString &deviceName)
{ {
m_deviceOpened = false; m_deviceOpened = false;
} }
QString RawHIDConnection::connectionName() QString RawHIDConnection::connectionName()
{ {
return QString("Raw HID USB"); return QString("Raw HID USB");
} }
QString RawHIDConnection::shortName() QString RawHIDConnection::shortName()
{ {
return QString("USB"); return QString("USB");
} }
//usb hid test thread //usb hid test thread
//temporary... //temporary...
RawHIDTestThread::RawHIDTestThread() RawHIDTestThread::RawHIDTestThread()
{ {
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager(); Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
QObject::connect(cm, SIGNAL(deviceConnected(QIODevice *)), QObject::connect(cm, SIGNAL(deviceConnected(QIODevice *)),
this, SLOT(onDeviceConnect(QIODevice *))); this, SLOT(onDeviceConnect(QIODevice *)));
QObject::connect(cm, SIGNAL(deviceDisconnected()), QObject::connect(cm, SIGNAL(deviceDisconnected()),
this, SLOT(onDeviceDisconnect())); this, SLOT(onDeviceDisconnect()));
} }
void RawHIDTestThread::onDeviceConnect(QIODevice *dev) void RawHIDTestThread::onDeviceConnect(QIODevice *dev)
{ {
this->dev = dev; this->dev = dev;
dev->open(QIODevice::ReadWrite); dev->open(QIODevice::ReadWrite);
QObject::connect(dev, SIGNAL(readyRead()), QObject::connect(dev, SIGNAL(readyRead()),
this, SLOT(onReadyRead())); this, SLOT(onReadyRead()));
QObject::connect(dev, SIGNAL(bytesWritten(qint64)), QObject::connect(dev, SIGNAL(bytesWritten(qint64)),
this, SLOT(onBytesWritten(qint64))); this, SLOT(onBytesWritten(qint64)));
dev->write("Hello raw hid device\n"); dev->write("Hello raw hid device\n");
} }
void RawHIDTestThread::onDeviceDisconnect() void RawHIDTestThread::onDeviceDisconnect()
{ {
dev->close(); dev->close();
} }
void RawHIDTestThread::onReadyRead() void RawHIDTestThread::onReadyRead()
{ {
qDebug() << "Rx:" << dev->readLine(32); qDebug() << "Rx:" << dev->readLine(32);
} }
void RawHIDTestThread::onBytesWritten(qint64 sz) void RawHIDTestThread::onBytesWritten(qint64 sz)
{ {
qDebug() << "Sent " << sz << " bytes"; qDebug() << "Sent " << sz << " bytes";
} }
RawHIDPlugin::RawHIDPlugin() RawHIDPlugin::RawHIDPlugin()
{ {
} }
RawHIDPlugin::~RawHIDPlugin() RawHIDPlugin::~RawHIDPlugin()
{ {
} }
void RawHIDPlugin::extensionsInitialized() void RawHIDPlugin::extensionsInitialized()
{ {
addAutoReleasedObject(new RawHIDConnection); addAutoReleasedObject(new RawHIDConnection);
//temp for test //temp for test
//addAutoReleasedObject(new RawHIDTestThread); //addAutoReleasedObject(new RawHIDTestThread);
} }
bool RawHIDPlugin::initialize(const QStringList & arguments, QString * errorString) bool RawHIDPlugin::initialize(const QStringList & arguments, QString * errorString)
{ {
Q_UNUSED(arguments); Q_UNUSED(arguments);
Q_UNUSED(errorString); Q_UNUSED(errorString);
return true; return true;
} }
Q_EXPORT_PLUGIN(RawHIDPlugin) Q_EXPORT_PLUGIN(RawHIDPlugin)

View File

@ -1,128 +1,128 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file rawhid.h * @file rawhid.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup rawhid_plugin * @defgroup rawhidplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef RAWHIDPLUGIN_H #ifndef RAWHIDPLUGIN_H
#define RAWHIDPLUGIN_H #define RAWHIDPLUGIN_H
#include "rawhid_global.h" #include "rawhid_global.h"
#include "coreplugin/iconnection.h" #include "coreplugin/iconnection.h"
#include <extensionsystem/iplugin.h> #include <extensionsystem/iplugin.h>
#include <QtCore/QMutex> #include <QtCore/QMutex>
#include <QtCore/QThread> #include <QtCore/QThread>
class IConnection; class IConnection;
class RawHIDConnection; class RawHIDConnection;
/** /**
* Helper thread to check on device connection/disconnection * Helper thread to check on device connection/disconnection
* Underlying HID library is not really easy to use, * Underlying HID library is not really easy to use,
* so we have to poll for device modification in a separate thread * so we have to poll for device modification in a separate thread
*/ */
class RAWHID_EXPORT RawHIDEnumerationThread : public QThread class RAWHID_EXPORT RawHIDEnumerationThread : public QThread
{ {
Q_OBJECT Q_OBJECT
public: public:
RawHIDEnumerationThread(RawHIDConnection *rawhid); RawHIDEnumerationThread(RawHIDConnection *rawhid);
virtual ~RawHIDEnumerationThread(); virtual ~RawHIDEnumerationThread();
virtual void run(); virtual void run();
signals: signals:
void enumerationChanged(); void enumerationChanged();
protected: protected:
RawHIDConnection *m_rawhid; RawHIDConnection *m_rawhid;
bool m_running; bool m_running;
}; };
/** /**
* Define a connection via the IConnection interface * Define a connection via the IConnection interface
* Plugin will add a instance of this class to the pool, * Plugin will add a instance of this class to the pool,
* so the connection manager can use it. * so the connection manager can use it.
*/ */
class RAWHID_EXPORT RawHIDConnection class RAWHID_EXPORT RawHIDConnection
: public Core::IConnection : public Core::IConnection
{ {
Q_OBJECT Q_OBJECT
public: public:
RawHIDConnection(); RawHIDConnection();
virtual ~RawHIDConnection(); virtual ~RawHIDConnection();
virtual QStringList availableDevices(); virtual QStringList availableDevices();
virtual QIODevice *openDevice(const QString &deviceName); virtual QIODevice *openDevice(const QString &deviceName);
virtual void closeDevice(const QString &deviceName); virtual void closeDevice(const QString &deviceName);
virtual QString connectionName(); virtual QString connectionName();
virtual QString shortName(); virtual QString shortName();
bool deviceOpened() {return m_deviceOpened;} bool deviceOpened() {return m_deviceOpened;}
protected slots: protected slots:
void onEnumerationChanged(); void onEnumerationChanged();
protected: protected:
QMutex m_enumMutex; QMutex m_enumMutex;
RawHIDEnumerationThread m_enumerateThread; RawHIDEnumerationThread m_enumerateThread;
bool m_deviceOpened; bool m_deviceOpened;
}; };
class RAWHID_EXPORT RawHIDPlugin class RAWHID_EXPORT RawHIDPlugin
: public ExtensionSystem::IPlugin : public ExtensionSystem::IPlugin
{ {
Q_OBJECT Q_OBJECT
public: public:
RawHIDPlugin(); RawHIDPlugin();
~RawHIDPlugin(); ~RawHIDPlugin();
virtual bool initialize(const QStringList &arguments, QString *error_message); virtual bool initialize(const QStringList &arguments, QString *error_message);
virtual void extensionsInitialized(); virtual void extensionsInitialized();
}; };
//usb hid test thread //usb hid test thread
#include "coreplugin/icore.h" #include "coreplugin/icore.h"
#include "coreplugin/connectionmanager.h" #include "coreplugin/connectionmanager.h"
class RawHIDTestThread: public QObject class RawHIDTestThread: public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
RawHIDTestThread(); RawHIDTestThread();
protected slots: protected slots:
void onDeviceConnect(QIODevice *); void onDeviceConnect(QIODevice *);
void onDeviceDisconnect(); void onDeviceDisconnect();
void onReadyRead(); void onReadyRead();
void onBytesWritten(qint64 sz); void onBytesWritten(qint64 sz);
protected: protected:
QIODevice *dev; QIODevice *dev;
}; };
#endif // RAWHIDPLUGIN_H #endif // RAWHIDPLUGIN_H

View File

@ -1,39 +1,39 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file serial_global.h * @file serial_global.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup serial_plugin * @defgroup serialplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef SERIAL_GLOBAL_H #ifndef SERIAL_GLOBAL_H
#define SERIAL_GLOBAL_H #define SERIAL_GLOBAL_H
#include <QtCore/qglobal.h> #include <QtCore/qglobal.h>
#if defined(SERIAL_LIBRARY) #if defined(SERIAL_LIBRARY)
# define SERIAL_EXPORT Q_DECL_EXPORT # define SERIAL_EXPORT Q_DECL_EXPORT
#else #else
# define SERIAL_EXPORT Q_DECL_IMPORT # define SERIAL_EXPORT Q_DECL_IMPORT
#endif #endif
#endif // SERIAL_GLOBAL_H #endif // SERIAL_GLOBAL_H

View File

@ -5,7 +5,7 @@
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Register connection object for the core connection manager * @brief Register connection object for the core connection manager
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup serial_plugin * @defgroup serialplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/

View File

@ -1,79 +1,79 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file serialplugin.h * @file serialplugin.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup serial_plugin * @defgroup serialplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef SERIALPLUGIN_H #ifndef SERIALPLUGIN_H
#define SERIALPLUGIN_H #define SERIALPLUGIN_H
#include "serial_global.h" #include "serial_global.h"
#include <qextserialport.h> #include <qextserialport.h>
#include <qextserialenumerator.h> #include <qextserialenumerator.h>
#include "coreplugin/iconnection.h" #include "coreplugin/iconnection.h"
#include <extensionsystem/iplugin.h> #include <extensionsystem/iplugin.h>
class IConnection; class IConnection;
class QextSerialEnumerator; class QextSerialEnumerator;
/** /**
* Define a connection via the IConnection interface * Define a connection via the IConnection interface
* Plugin will add a instance of this class to the pool, * Plugin will add a instance of this class to the pool,
* so the connection manager can use it. * so the connection manager can use it.
*/ */
class SERIAL_EXPORT SerialConnection class SERIAL_EXPORT SerialConnection
: public Core::IConnection : public Core::IConnection
{ {
Q_OBJECT Q_OBJECT
public: public:
SerialConnection(); SerialConnection();
virtual ~SerialConnection(); virtual ~SerialConnection();
virtual QStringList availableDevices(); virtual QStringList availableDevices();
virtual QIODevice *openDevice(const QString &deviceName); virtual QIODevice *openDevice(const QString &deviceName);
virtual void closeDevice(const QString &deviceName); virtual void closeDevice(const QString &deviceName);
virtual QString connectionName(); virtual QString connectionName();
virtual QString shortName(); virtual QString shortName();
protected slots: protected slots:
void onEnumerationChanged(); void onEnumerationChanged();
}; };
class SERIAL_EXPORT SerialPlugin class SERIAL_EXPORT SerialPlugin
: public ExtensionSystem::IPlugin : public ExtensionSystem::IPlugin
{ {
Q_OBJECT Q_OBJECT
public: public:
SerialPlugin(); SerialPlugin();
~SerialPlugin(); ~SerialPlugin();
virtual bool initialize(const QStringList &arguments, QString *error_message); virtual bool initialize(const QStringList &arguments, QString *error_message);
virtual void extensionsInitialized(); virtual void extensionsInitialized();
}; };
#endif // SERIALPLUGIN_H #endif // SERIALPLUGIN_H

View File

@ -1,52 +1,52 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file systemhealthgadget.cpp * @file systemhealthgadget.cpp
* @author Edouard Lafargue Copyright (C) 2010. * @author Edouard Lafargue Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup systemhealth * @defgroup systemhealthplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "systemhealthgadget.h" #include "systemhealthgadget.h"
#include "systemhealthgadgetwidget.h" #include "systemhealthgadgetwidget.h"
#include "systemhealthgadgetconfiguration.h" #include "systemhealthgadgetconfiguration.h"
SystemHealthGadget::SystemHealthGadget(QString classId, SystemHealthGadgetWidget *widget, QWidget *parent) : SystemHealthGadget::SystemHealthGadget(QString classId, SystemHealthGadgetWidget *widget, QWidget *parent) :
IUAVGadget(classId, parent), IUAVGadget(classId, parent),
m_widget(widget) m_widget(widget)
{ {
} }
SystemHealthGadget::~SystemHealthGadget() SystemHealthGadget::~SystemHealthGadget()
{ {
} }
/* /*
This is called when a configuration is loaded, and updates the plugin's settings. 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 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 first time, so you have to be careful not to assume all the plugin values are initialized
the first time you use them the first time you use them
*/ */
void SystemHealthGadget::loadConfiguration(IUAVGadgetConfiguration* config) void SystemHealthGadget::loadConfiguration(IUAVGadgetConfiguration* config)
{ {
SystemHealthGadgetConfiguration *m = qobject_cast<SystemHealthGadgetConfiguration*>(config); SystemHealthGadgetConfiguration *m = qobject_cast<SystemHealthGadgetConfiguration*>(config);
m_widget->setSystemFile(m->getSystemFile()); // Triggers widget repaint m_widget->setSystemFile(m->getSystemFile()); // Triggers widget repaint
} }

View File

@ -1,56 +1,56 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file systemhealthgadget.h * @file systemhealthgadget.h
* @author Edouard Lafargue Copyright (C) 2010. * @author Edouard Lafargue Copyright (C) 2010.
* @brief System health gadget to display system alarms * @brief System health gadget to display system alarms
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup systemhealth * @defgroup systemhealthplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef SYSTEMHEALTHGADGET_H_ #ifndef SYSTEMHEALTHGADGET_H_
#define SYSTEMHEALTHGADGET_H_ #define SYSTEMHEALTHGADGET_H_
#include <coreplugin/iuavgadget.h> #include <coreplugin/iuavgadget.h>
#include "systemhealthgadgetwidget.h" #include "systemhealthgadgetwidget.h"
class IUAVGadget; class IUAVGadget;
class QWidget; class QWidget;
class QString; class QString;
class SystemHealthGadgetWidget; class SystemHealthGadgetWidget;
using namespace Core; using namespace Core;
class SystemHealthGadget : public Core::IUAVGadget class SystemHealthGadget : public Core::IUAVGadget
{ {
Q_OBJECT Q_OBJECT
public: public:
SystemHealthGadget(QString classId, SystemHealthGadgetWidget *widget, QWidget *parent = 0); SystemHealthGadget(QString classId, SystemHealthGadgetWidget *widget, QWidget *parent = 0);
~SystemHealthGadget(); ~SystemHealthGadget();
QWidget *widget() { return m_widget; } QWidget *widget() { return m_widget; }
void loadConfiguration(IUAVGadgetConfiguration* config); void loadConfiguration(IUAVGadgetConfiguration* config);
private: private:
SystemHealthGadgetWidget *m_widget; SystemHealthGadgetWidget *m_widget;
}; };
#endif // SYSTEMHEALTHGADGET_H_ #endif // SYSTEMHEALTHGADGET_H_

View File

@ -5,7 +5,7 @@
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief System Health Plugin Gadget configuration * @brief System Health Plugin Gadget configuration
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup systemhealth * @defgroup systemhealthplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/

View File

@ -5,7 +5,7 @@
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief System Health Plugin Gadget configuration * @brief System Health Plugin Gadget configuration
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup systemhealth * @defgroup systemhealthplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/

View File

@ -1,60 +1,60 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file systemhealthgadgetfactory.cpp * @file systemhealthgadgetfactory.cpp
* @author Edouard Lafargue Copyright (C) 2010. * @author Edouard Lafargue Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup systemhealth * @defgroup systemhealthplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "systemhealthgadgetfactory.h" #include "systemhealthgadgetfactory.h"
#include "systemhealthgadgetwidget.h" #include "systemhealthgadgetwidget.h"
#include "systemhealthgadget.h" #include "systemhealthgadget.h"
#include "systemhealthgadgetconfiguration.h" #include "systemhealthgadgetconfiguration.h"
#include "systemhealthgadgetoptionspage.h" #include "systemhealthgadgetoptionspage.h"
#include <coreplugin/iuavgadget.h> #include <coreplugin/iuavgadget.h>
SystemHealthGadgetFactory::SystemHealthGadgetFactory(QObject *parent) : SystemHealthGadgetFactory::SystemHealthGadgetFactory(QObject *parent) :
IUAVGadgetFactory(QString("SystemHealthGadget"), IUAVGadgetFactory(QString("SystemHealthGadget"),
tr("System Health Gadget"), tr("System Health Gadget"),
parent) parent)
{ {
} }
SystemHealthGadgetFactory::~SystemHealthGadgetFactory() SystemHealthGadgetFactory::~SystemHealthGadgetFactory()
{ {
} }
Core::IUAVGadget* SystemHealthGadgetFactory::createGadget(QWidget *parent) Core::IUAVGadget* SystemHealthGadgetFactory::createGadget(QWidget *parent)
{ {
SystemHealthGadgetWidget* gadgetWidget = new SystemHealthGadgetWidget(parent); SystemHealthGadgetWidget* gadgetWidget = new SystemHealthGadgetWidget(parent);
return new SystemHealthGadget(QString("SystemHealthGadget"), gadgetWidget, parent); return new SystemHealthGadget(QString("SystemHealthGadget"), gadgetWidget, parent);
} }
IUAVGadgetConfiguration *SystemHealthGadgetFactory::createConfiguration(const QByteArray &state) IUAVGadgetConfiguration *SystemHealthGadgetFactory::createConfiguration(const QByteArray &state)
{ {
return new SystemHealthGadgetConfiguration(QString("SystemHealthGadget"), state); return new SystemHealthGadgetConfiguration(QString("SystemHealthGadget"), state);
} }
IOptionsPage *SystemHealthGadgetFactory::createOptionsPage(IUAVGadgetConfiguration *config) IOptionsPage *SystemHealthGadgetFactory::createOptionsPage(IUAVGadgetConfiguration *config)
{ {
return new SystemHealthGadgetOptionsPage(qobject_cast<SystemHealthGadgetConfiguration*>(config)); return new SystemHealthGadgetOptionsPage(qobject_cast<SystemHealthGadgetConfiguration*>(config));
} }

View File

@ -1,52 +1,52 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file systemhealthgadgetfactory.h * @file systemhealthgadgetfactory.h
* @author Edouard Lafargue Copyright (C) 2010. * @author Edouard Lafargue Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup systemhealth * @defgroup systemhealthplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef SYSTEMHEALTHGADGETFACTORY_H_ #ifndef SYSTEMHEALTHGADGETFACTORY_H_
#define SYSTEMHEALTHGADGETFACTORY_H_ #define SYSTEMHEALTHGADGETFACTORY_H_
#include <coreplugin/iuavgadgetfactory.h> #include <coreplugin/iuavgadgetfactory.h>
namespace Core { namespace Core {
class IUAVGadget; class IUAVGadget;
class IUAVGadgetFactory; class IUAVGadgetFactory;
} }
using namespace Core; using namespace Core;
class SystemHealthGadgetFactory : public IUAVGadgetFactory class SystemHealthGadgetFactory : public IUAVGadgetFactory
{ {
Q_OBJECT Q_OBJECT
public: public:
SystemHealthGadgetFactory(QObject *parent = 0); SystemHealthGadgetFactory(QObject *parent = 0);
~SystemHealthGadgetFactory(); ~SystemHealthGadgetFactory();
Core::IUAVGadget *createGadget(QWidget *parent); Core::IUAVGadget *createGadget(QWidget *parent);
IUAVGadgetConfiguration *createConfiguration(const QByteArray &state); IUAVGadgetConfiguration *createConfiguration(const QByteArray &state);
IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config); IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config);
}; };
#endif // SYSTEMHEALTHGADGETFACTORY_H_ #endif // SYSTEMHEALTHGADGETFACTORY_H_

View File

@ -5,7 +5,7 @@
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief System Health Plugin Gadget options page * @brief System Health Plugin Gadget options page
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup systemhealth * @defgroup systemhealthplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/

View File

@ -5,7 +5,7 @@
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief System Health Plugin Gadget options page * @brief System Health Plugin Gadget options page
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup systemhealth * @defgroup systemhealthplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/

View File

@ -1,173 +1,173 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file systemhealthgadgetwidget.cpp * @file systemhealthgadgetwidget.cpp
* @author Edouard Lafargue Copyright (C) 2010. * @author Edouard Lafargue Copyright (C) 2010.
* @brief System Health widget, does the actual drawing * @brief System Health widget, does the actual drawing
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup systemhealth * @defgroup systemhealthplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "systemhealthgadgetwidget.h" #include "systemhealthgadgetwidget.h"
#include "extensionsystem/pluginmanager.h" #include "extensionsystem/pluginmanager.h"
#include "uavobjects/uavobjectmanager.h" #include "uavobjects/uavobjectmanager.h"
#include "uavobjects/systemalarms.h" #include "uavobjects/systemalarms.h"
#include <iostream> #include <iostream>
#include <QtGui/QFileDialog> #include <QtGui/QFileDialog>
#include <QDebug> #include <QDebug>
/* /*
* Initialize the widget * Initialize the widget
*/ */
SystemHealthGadgetWidget::SystemHealthGadgetWidget(QWidget *parent) : QGraphicsView(parent) SystemHealthGadgetWidget::SystemHealthGadgetWidget(QWidget *parent) : QGraphicsView(parent)
{ {
setMinimumSize(128,128); setMinimumSize(128,128);
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
setScene(new QGraphicsScene(this)); setScene(new QGraphicsScene(this));
m_renderer = new QSvgRenderer(); m_renderer = new QSvgRenderer();
background = new QGraphicsSvgItem(); background = new QGraphicsSvgItem();
foreground = new QGraphicsSvgItem(); foreground = new QGraphicsSvgItem();
paint(); paint();
// Now connect the widget to the SystemAlarms UAVObject // Now connect the widget to the SystemAlarms UAVObject
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>(); UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
SystemAlarms* obj = dynamic_cast<SystemAlarms*>(objManager->getObject(QString("SystemAlarms"))); SystemAlarms* obj = dynamic_cast<SystemAlarms*>(objManager->getObject(QString("SystemAlarms")));
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(updateAlarms(UAVObject*))); connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(updateAlarms(UAVObject*)));
// Test code for timer to move the index // Test code for timer to move the index
testValue=0; testValue=0;
connect(&m_testTimer, SIGNAL(timeout()), this, SLOT(testRotate())); connect(&m_testTimer, SIGNAL(timeout()), this, SLOT(testRotate()));
m_testTimer.start(1000); m_testTimer.start(1000);
} }
void SystemHealthGadgetWidget::updateAlarms(UAVObject* systemAlarm) void SystemHealthGadgetWidget::updateAlarms(UAVObject* systemAlarm)
{ {
// This code does not know anything about alarms beforehand, and // This code does not know anything about alarms beforehand, and
// I found to efficient way to locate items inside the scene by // I found to efficient way to locate items inside the scene by
// name, so it's just as simple to reset the scene: // name, so it's just as simple to reset the scene:
// And add the one with the right name. // And add the one with the right name.
QGraphicsScene *m_scene = scene(); QGraphicsScene *m_scene = scene();
foreach ( QGraphicsItem* item , m_scene->items()){ foreach ( QGraphicsItem* item , m_scene->items()){
m_scene->removeItem(item); m_scene->removeItem(item);
} }
m_scene->addItem(background); m_scene->addItem(background);
QString alarm = systemAlarm->getName(); QString alarm = systemAlarm->getName();
foreach (UAVObjectField *field, systemAlarm->getFields()) { foreach (UAVObjectField *field, systemAlarm->getFields()) {
for (uint i = 0; i < field->getNumElements(); ++i) { for (uint i = 0; i < field->getNumElements(); ++i) {
QString element = field->getElementNames()[i]; QString element = field->getElementNames()[i];
QString value = field->getValue(i).toString(); QString value = field->getValue(i).toString();
if (m_renderer->elementExists(element)) { if (m_renderer->elementExists(element)) {
QMatrix blockMatrix = m_renderer->matrixForElement(element); QMatrix blockMatrix = m_renderer->matrixForElement(element);
qreal startX = blockMatrix.mapRect(m_renderer->boundsOnElement(element)).x(); qreal startX = blockMatrix.mapRect(m_renderer->boundsOnElement(element)).x();
qreal startY = blockMatrix.mapRect(m_renderer->boundsOnElement(element)).y(); qreal startY = blockMatrix.mapRect(m_renderer->boundsOnElement(element)).y();
QString element2 = element + "-" + value; QString element2 = element + "-" + value;
if (m_renderer->elementExists(element2)) { if (m_renderer->elementExists(element2)) {
QGraphicsSvgItem *ind = new QGraphicsSvgItem(); QGraphicsSvgItem *ind = new QGraphicsSvgItem();
ind->setSharedRenderer(m_renderer); ind->setSharedRenderer(m_renderer);
ind->setElementId(element2); ind->setElementId(element2);
QTransform matrix; QTransform matrix;
matrix.translate(startX,startY); matrix.translate(startX,startY);
ind->setTransform(matrix,false); ind->setTransform(matrix,false);
m_scene->addItem(ind); m_scene->addItem(ind);
} else { } else {
std::cout << "Warning: element " << element2.toStdString() << " not found in SVG."<<std::endl; std::cout << "Warning: element " << element2.toStdString() << " not found in SVG."<<std::endl;
} }
} else { } else {
std::cout << "Warning: Element " << element.toStdString() << " not found in SVG." << std::endl; std::cout << "Warning: Element " << element.toStdString() << " not found in SVG." << std::endl;
} }
} }
} }
m_scene->addItem(foreground); m_scene->addItem(foreground);
} }
SystemHealthGadgetWidget::~SystemHealthGadgetWidget() SystemHealthGadgetWidget::~SystemHealthGadgetWidget()
{ {
// Do nothing // Do nothing
} }
void SystemHealthGadgetWidget::setSystemFile(QString dfn) void SystemHealthGadgetWidget::setSystemFile(QString dfn)
{ {
if (QFile::exists(dfn)) if (QFile::exists(dfn))
{ {
m_renderer->load(dfn); m_renderer->load(dfn);
if(m_renderer->isValid()) if(m_renderer->isValid())
{ {
fgenabled = false; fgenabled = false;
background->setSharedRenderer(m_renderer); background->setSharedRenderer(m_renderer);
background->setElementId("background"); background->setElementId("background");
if (m_renderer->elementExists("foreground")) { if (m_renderer->elementExists("foreground")) {
foreground->setSharedRenderer(m_renderer); foreground->setSharedRenderer(m_renderer);
foreground->setElementId("foreground"); foreground->setElementId("foreground");
foreground->setZValue(99); foreground->setZValue(99);
fgenabled = true; fgenabled = true;
} }
std::cout<<"Dial file loaded"<<std::endl; std::cout<<"Dial file loaded"<<std::endl;
QGraphicsScene *l_scene = scene(); QGraphicsScene *l_scene = scene();
l_scene->setSceneRect(background->boundingRect()); l_scene->setSceneRect(background->boundingRect());
fitInView(background, Qt::KeepAspectRatio ); fitInView(background, Qt::KeepAspectRatio );
} }
} }
else else
{ std::cout<<"no file: "<<std::endl; } { std::cout<<"no file: "<<std::endl; }
} }
void SystemHealthGadgetWidget::paint() void SystemHealthGadgetWidget::paint()
{ {
QGraphicsScene *l_scene = scene(); QGraphicsScene *l_scene = scene();
l_scene->clear(); l_scene->clear();
l_scene->addItem(background); l_scene->addItem(background);
l_scene->addItem(foreground); l_scene->addItem(foreground);
update(); update();
} }
void SystemHealthGadgetWidget::paintEvent(QPaintEvent *event) void SystemHealthGadgetWidget::paintEvent(QPaintEvent *event)
{ {
// Skip painting until the dial file is loaded // Skip painting until the dial file is loaded
if (! m_renderer->isValid()) { if (! m_renderer->isValid()) {
std::cout<<"System file not loaded, not rendering"<<std::endl; std::cout<<"System file not loaded, not rendering"<<std::endl;
return; return;
} }
QGraphicsView::paintEvent(event); QGraphicsView::paintEvent(event);
} }
// This event enables the dial to be dynamically resized // This event enables the dial to be dynamically resized
// whenever the gadget is resized, taking advantage of the vector // whenever the gadget is resized, taking advantage of the vector
// nature of SVG dials. // nature of SVG dials.
void SystemHealthGadgetWidget::resizeEvent(QResizeEvent *event) void SystemHealthGadgetWidget::resizeEvent(QResizeEvent *event)
{ {
fitInView(background, Qt::KeepAspectRatio ); fitInView(background, Qt::KeepAspectRatio );
} }
// Test function for timer to rotate needles // Test function for timer to rotate needles
void SystemHealthGadgetWidget::test() void SystemHealthGadgetWidget::test()
{ {
testValue=0; testValue=0;
} }

View File

@ -1,74 +1,74 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file systemhealthgadgetwidget.h * @file systemhealthgadgetwidget.h
* @author Edouard Lafargue Copyright (C) 2010. * @author Edouard Lafargue Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup systemhealth * @defgroup systemhealthplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef SYSTEMHEALTHGADGETWIDGET_H_ #ifndef SYSTEMHEALTHGADGETWIDGET_H_
#define SYSTEMHEALTHGADGETWIDGET_H_ #define SYSTEMHEALTHGADGETWIDGET_H_
#include "systemhealthgadgetconfiguration.h" #include "systemhealthgadgetconfiguration.h"
#include "uavobjects/uavobject.h" #include "uavobjects/uavobject.h"
#include <QGraphicsView> #include <QGraphicsView>
#include <QtSvg/QSvgRenderer> #include <QtSvg/QSvgRenderer>
#include <QtSvg/QGraphicsSvgItem> #include <QtSvg/QGraphicsSvgItem>
#include <QFile> #include <QFile>
#include <QTimer> #include <QTimer>
class SystemHealthGadgetWidget : public QGraphicsView class SystemHealthGadgetWidget : public QGraphicsView
{ {
Q_OBJECT Q_OBJECT
public: public:
SystemHealthGadgetWidget(QWidget *parent = 0); SystemHealthGadgetWidget(QWidget *parent = 0);
~SystemHealthGadgetWidget(); ~SystemHealthGadgetWidget();
void setSystemFile(QString dfn); void setSystemFile(QString dfn);
void setIndicator(QString indicator); void setIndicator(QString indicator);
void paint(); void paint();
protected: protected:
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event);
void resizeEvent(QResizeEvent *event); void resizeEvent(QResizeEvent *event);
private slots: private slots:
// Test function // Test function
void test(); void test();
void updateAlarms(UAVObject *systemAlarm); // Called by the systemalarms UAVObject void updateAlarms(UAVObject *systemAlarm); // Called by the systemalarms UAVObject
private: private:
QSvgRenderer *m_renderer; QSvgRenderer *m_renderer;
QGraphicsSvgItem *background; QGraphicsSvgItem *background;
QGraphicsSvgItem *foreground; QGraphicsSvgItem *foreground;
// Simple flag to skip rendering if the // Simple flag to skip rendering if the
bool fgenabled; // layer does not exist. bool fgenabled; // layer does not exist.
// Test variables // Test variables
double testValue; double testValue;
QTimer m_testTimer; QTimer m_testTimer;
// End test variables // End test variables
}; };
#endif /* SYSTEMHEALTHGADGETWIDGET_H_ */ #endif /* SYSTEMHEALTHGADGETWIDGET_H_ */

View File

@ -1,65 +1,65 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file systemhealthplugin.h * @file systemhealthplugin.h
* @author Edouard Lafargue Copyright (C) 2010. * @author Edouard Lafargue Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup systemhealth * @defgroup systemhealthplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "systemhealthplugin.h" #include "systemhealthplugin.h"
#include "systemhealthgadgetfactory.h" #include "systemhealthgadgetfactory.h"
#include <QDebug> #include <QDebug>
#include <QtPlugin> #include <QtPlugin>
#include <QStringList> #include <QStringList>
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
SystemHealthPlugin::SystemHealthPlugin() SystemHealthPlugin::SystemHealthPlugin()
{ {
// Do nothing // Do nothing
} }
SystemHealthPlugin::~SystemHealthPlugin() SystemHealthPlugin::~SystemHealthPlugin()
{ {
// Do nothing // Do nothing
} }
bool SystemHealthPlugin::initialize(const QStringList& args, QString *errMsg) bool SystemHealthPlugin::initialize(const QStringList& args, QString *errMsg)
{ {
Q_UNUSED(args); Q_UNUSED(args);
Q_UNUSED(errMsg); Q_UNUSED(errMsg);
mf = new SystemHealthGadgetFactory(this); mf = new SystemHealthGadgetFactory(this);
addAutoReleasedObject(mf); addAutoReleasedObject(mf);
return true; return true;
} }
void SystemHealthPlugin::extensionsInitialized() void SystemHealthPlugin::extensionsInitialized()
{ {
// Do nothing // Do nothing
} }
void SystemHealthPlugin::shutdown() void SystemHealthPlugin::shutdown()
{ {
// Do nothing // Do nothing
} }
Q_EXPORT_PLUGIN(SystemHealthPlugin) Q_EXPORT_PLUGIN(SystemHealthPlugin)

View File

@ -1,47 +1,47 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file systemhealthplugin.h * @file systemhealthplugin.h
* @author Edouard Lafargue Copyright (C) 2010. * @author Edouard Lafargue Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup systemhealth * @defgroup systemhealthplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef SYSTEMHEALTHPLUGIN_H_ #ifndef SYSTEMHEALTHPLUGIN_H_
#define SYSTEMHEALTHPLUGIN_H_ #define SYSTEMHEALTHPLUGIN_H_
#include <extensionsystem/iplugin.h> #include <extensionsystem/iplugin.h>
class SystemHealthGadgetFactory; class SystemHealthGadgetFactory;
class SystemHealthPlugin : public ExtensionSystem::IPlugin class SystemHealthPlugin : public ExtensionSystem::IPlugin
{ {
public: public:
SystemHealthPlugin(); SystemHealthPlugin();
~SystemHealthPlugin(); ~SystemHealthPlugin();
void extensionsInitialized(); void extensionsInitialized();
bool initialize(const QStringList & arguments, QString * errorString); bool initialize(const QStringList & arguments, QString * errorString);
void shutdown(); void shutdown();
private: private:
SystemHealthGadgetFactory *mf; SystemHealthGadgetFactory *mf;
}; };
#endif /* SYSTEMHEALTHPLUGIN_H_ */ #endif /* SYSTEMHEALTHPLUGIN_H_ */

View File

@ -1,72 +1,72 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file browseritemdelegate.cpp * @file browseritemdelegate.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser * @defgroup uavobjectbrowserplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "browseritemdelegate.h" #include "browseritemdelegate.h"
#include "fieldtreeitem.h" #include "fieldtreeitem.h"
BrowserItemDelegate::BrowserItemDelegate(QObject *parent) : BrowserItemDelegate::BrowserItemDelegate(QObject *parent) :
QStyledItemDelegate(parent) QStyledItemDelegate(parent)
{ {
} }
QWidget *BrowserItemDelegate::createEditor(QWidget *parent, QWidget *BrowserItemDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem & option , const QStyleOptionViewItem & option ,
const QModelIndex & index ) const const QModelIndex & index ) const
{ {
FieldTreeItem *item = static_cast<FieldTreeItem*>(index.internalPointer()); FieldTreeItem *item = static_cast<FieldTreeItem*>(index.internalPointer());
QWidget *editor = item->createEditor(parent); QWidget *editor = item->createEditor(parent);
Q_ASSERT(editor); Q_ASSERT(editor);
return editor; return editor;
} }
void BrowserItemDelegate::setEditorData(QWidget *editor, void BrowserItemDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const const QModelIndex &index) const
{ {
FieldTreeItem *item = static_cast<FieldTreeItem*>(index.internalPointer()); FieldTreeItem *item = static_cast<FieldTreeItem*>(index.internalPointer());
QVariant value = index.model()->data(index, Qt::EditRole); QVariant value = index.model()->data(index, Qt::EditRole);
item->setEditorValue(editor, value); item->setEditorValue(editor, value);
} }
void BrowserItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, void BrowserItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const const QModelIndex &index) const
{ {
FieldTreeItem *item = static_cast<FieldTreeItem*>(index.internalPointer()); FieldTreeItem *item = static_cast<FieldTreeItem*>(index.internalPointer());
QVariant value = item->getEditorValue(editor); QVariant value = item->getEditorValue(editor);
model->setData(index, value, Qt::EditRole); model->setData(index, value, Qt::EditRole);
} }
void BrowserItemDelegate::updateEditorGeometry(QWidget *editor, void BrowserItemDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
{ {
editor->setGeometry(option.rect); editor->setGeometry(option.rect);
} }
QSize BrowserItemDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex &index) const QSize BrowserItemDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex &index) const
{ {
return QSpinBox().sizeHint(); return QSpinBox().sizeHint();
} }

View File

@ -1,58 +1,58 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file browseritemdelegate.h * @file browseritemdelegate.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser * @defgroup uavobjectbrowserplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef BROWSERITEMDELEGATE_H #ifndef BROWSERITEMDELEGATE_H
#define BROWSERITEMDELEGATE_H #define BROWSERITEMDELEGATE_H
#include <QStyledItemDelegate> #include <QStyledItemDelegate>
class BrowserItemDelegate : public QStyledItemDelegate class BrowserItemDelegate : public QStyledItemDelegate
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit BrowserItemDelegate(QObject *parent = 0); explicit BrowserItemDelegate(QObject *parent = 0);
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const; const QModelIndex &index) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const; void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model, void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const; const QModelIndex &index) const;
void updateEditorGeometry(QWidget *editor, void updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &index) const; const QStyleOptionViewItem &option, const QModelIndex &index) const;
QSize sizeHint(const QStyleOptionViewItem & option, QSize sizeHint(const QStyleOptionViewItem & option,
const QModelIndex &index) const; const QModelIndex &index) const;
signals: signals:
public slots: public slots:
}; };
#endif // BROWSERITEMDELEGATE_H #endif // BROWSERITEMDELEGATE_H

View File

@ -1,63 +1,63 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file mapplugin.cpp * @file mapplugin.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser * @defgroup uavobjectbrowserplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "browserplugin.h" #include "browserplugin.h"
#include "uavobjectbrowserfactory.h" #include "uavobjectbrowserfactory.h"
#include <QtPlugin> #include <QtPlugin>
#include <QStringList> #include <QStringList>
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
BrowserPlugin::BrowserPlugin() BrowserPlugin::BrowserPlugin()
{ {
// Do nothing // Do nothing
} }
BrowserPlugin::~BrowserPlugin() BrowserPlugin::~BrowserPlugin()
{ {
// Do nothing // Do nothing
} }
bool BrowserPlugin::initialize(const QStringList& args, QString *errMsg) bool BrowserPlugin::initialize(const QStringList& args, QString *errMsg)
{ {
Q_UNUSED(args); Q_UNUSED(args);
Q_UNUSED(errMsg); Q_UNUSED(errMsg);
mf = new UAVObjectBrowserFactory(this); mf = new UAVObjectBrowserFactory(this);
addAutoReleasedObject(mf); addAutoReleasedObject(mf);
return true; return true;
} }
void BrowserPlugin::extensionsInitialized() void BrowserPlugin::extensionsInitialized()
{ {
// Do nothing // Do nothing
} }
void BrowserPlugin::shutdown() void BrowserPlugin::shutdown()
{ {
// Do nothing // Do nothing
} }
Q_EXPORT_PLUGIN(BrowserPlugin) Q_EXPORT_PLUGIN(BrowserPlugin)

View File

@ -1,47 +1,47 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file browserplugin.h * @file browserplugin.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser * @defgroup uavobjectbrowserplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef UAVOBJECTBROWSERPLUGIN_H_ #ifndef UAVOBJECTBROWSERPLUGIN_H_
#define UAVOBJECTBROWSERPLUGIN_H_ #define UAVOBJECTBROWSERPLUGIN_H_
#include <extensionsystem/iplugin.h> #include <extensionsystem/iplugin.h>
class UAVObjectBrowserFactory; class UAVObjectBrowserFactory;
class BrowserPlugin : public ExtensionSystem::IPlugin class BrowserPlugin : public ExtensionSystem::IPlugin
{ {
public: public:
BrowserPlugin(); BrowserPlugin();
~BrowserPlugin(); ~BrowserPlugin();
void extensionsInitialized(); void extensionsInitialized();
bool initialize(const QStringList & arguments, QString * errorString); bool initialize(const QStringList & arguments, QString * errorString);
void shutdown(); void shutdown();
private: private:
UAVObjectBrowserFactory *mf; UAVObjectBrowserFactory *mf;
}; };
#endif /* UAVOBJECTBROWSERPLUGIN_H_ */ #endif /* UAVOBJECTBROWSERPLUGIN_H_ */

View File

@ -1,29 +1,29 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file fieldtreeitem.cpp * @file fieldtreeitem.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser * @defgroup uavobjectbrowserplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "fieldtreeitem.h" #include "fieldtreeitem.h"

View File

@ -1,250 +1,250 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file fieldtreeitem.h * @file fieldtreeitem.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser * @defgroup uavobjectbrowserplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef FIELDTREEITEM_H #ifndef FIELDTREEITEM_H
#define FIELDTREEITEM_H #define FIELDTREEITEM_H
#include "treeitem.h" #include "treeitem.h"
#include <QtCore/QStringList> #include <QtCore/QStringList>
#include <QtGui/QWidget> #include <QtGui/QWidget>
#include <QtGui/QSpinBox> #include <QtGui/QSpinBox>
#include <QtGui/QDoubleSpinBox> #include <QtGui/QDoubleSpinBox>
#include <QtGui/QComboBox> #include <QtGui/QComboBox>
#include <limits> #include <limits>
#define QINT8MIN std::numeric_limits<qint8>::min() #define QINT8MIN std::numeric_limits<qint8>::min()
#define QINT8MAX std::numeric_limits<qint8>::max() #define QINT8MAX std::numeric_limits<qint8>::max()
#define QUINTMIN std::numeric_limits<quint8>::min() #define QUINTMIN std::numeric_limits<quint8>::min()
#define QUINT8MAX std::numeric_limits<quint8>::max() #define QUINT8MAX std::numeric_limits<quint8>::max()
#define QINT16MIN std::numeric_limits<qint16>::min() #define QINT16MIN std::numeric_limits<qint16>::min()
#define QINT16MAX std::numeric_limits<qint16>::max() #define QINT16MAX std::numeric_limits<qint16>::max()
#define QUINT16MAX std::numeric_limits<quint16>::max() #define QUINT16MAX std::numeric_limits<quint16>::max()
#define QINT32MIN std::numeric_limits<qint32>::min() #define QINT32MIN std::numeric_limits<qint32>::min()
#define QINT32MAX std::numeric_limits<qint32>::max() #define QINT32MAX std::numeric_limits<qint32>::max()
#define QUINT32MAX std::numeric_limits<qint32>::max() #define QUINT32MAX std::numeric_limits<qint32>::max()
class FieldTreeItem : public TreeItem class FieldTreeItem : public TreeItem
{ {
Q_OBJECT Q_OBJECT
public: public:
FieldTreeItem(int index, const QList<QVariant> &data, TreeItem *parent = 0) : FieldTreeItem(int index, const QList<QVariant> &data, TreeItem *parent = 0) :
TreeItem(data, parent), m_index(index) { } TreeItem(data, parent), m_index(index) { }
FieldTreeItem(int index, const QVariant &data, TreeItem *parent = 0) : FieldTreeItem(int index, const QVariant &data, TreeItem *parent = 0) :
TreeItem(data, parent), m_index(index) { } TreeItem(data, parent), m_index(index) { }
bool isEditable() { return true; } bool isEditable() { return true; }
virtual QWidget *createEditor(QWidget *parent) = 0; virtual QWidget *createEditor(QWidget *parent) = 0;
virtual QVariant getEditorValue(QWidget *editor) = 0; virtual QVariant getEditorValue(QWidget *editor) = 0;
virtual void setEditorValue(QWidget *editor, QVariant value) = 0; virtual void setEditorValue(QWidget *editor, QVariant value) = 0;
virtual void apply() { } virtual void apply() { }
protected: protected:
int m_index; int m_index;
}; };
class EnumFieldTreeItem : public FieldTreeItem class EnumFieldTreeItem : public FieldTreeItem
{ {
Q_OBJECT Q_OBJECT
public: public:
EnumFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, EnumFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data,
TreeItem *parent = 0) : TreeItem *parent = 0) :
FieldTreeItem(index, data, parent), m_enumOptions(field->getOptions()), m_field(field) { } FieldTreeItem(index, data, parent), m_enumOptions(field->getOptions()), m_field(field) { }
EnumFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, EnumFieldTreeItem(UAVObjectField *field, int index, const QVariant &data,
TreeItem *parent = 0) : TreeItem *parent = 0) :
FieldTreeItem(index, data, parent), m_enumOptions(field->getOptions()), m_field(field) { } FieldTreeItem(index, data, parent), m_enumOptions(field->getOptions()), m_field(field) { }
void setData(QVariant value, int column) { void setData(QVariant value, int column) {
QStringList options = m_field->getOptions(); QStringList options = m_field->getOptions();
QVariant tmpValue = m_field->getValue(m_index); QVariant tmpValue = m_field->getValue(m_index);
int tmpValIndex = options.indexOf(tmpValue.toString()); int tmpValIndex = options.indexOf(tmpValue.toString());
setChanged(tmpValIndex != value); setChanged(tmpValIndex != value);
TreeItem::setData(value, column); TreeItem::setData(value, column);
} }
QString enumOptions(int index) { return m_enumOptions.at(index); } QString enumOptions(int index) { return m_enumOptions.at(index); }
void apply() { void apply() {
int value = data(dataColumn).toInt(); int value = data(dataColumn).toInt();
QStringList options = m_field->getOptions(); QStringList options = m_field->getOptions();
m_field->setValue(options[value], m_index); m_field->setValue(options[value], m_index);
setChanged(false); setChanged(false);
} }
void update() { void update() {
QStringList options = m_field->getOptions(); QStringList options = m_field->getOptions();
QVariant value = m_field->getValue(m_index); QVariant value = m_field->getValue(m_index);
int valIndex = options.indexOf(value.toString()); int valIndex = options.indexOf(value.toString());
if (data() != valIndex || changed()) { if (data() != valIndex || changed()) {
TreeItem::setData(valIndex); TreeItem::setData(valIndex);
setHighlight(true); setHighlight(true);
} }
} }
QWidget *createEditor(QWidget *parent) { QWidget *createEditor(QWidget *parent) {
QComboBox *editor = new QComboBox(parent); QComboBox *editor = new QComboBox(parent);
foreach (QString option, m_enumOptions) foreach (QString option, m_enumOptions)
editor->addItem(option); editor->addItem(option);
return editor; return editor;
} }
QVariant getEditorValue(QWidget *editor) { QVariant getEditorValue(QWidget *editor) {
QComboBox *comboBox = static_cast<QComboBox*>(editor); QComboBox *comboBox = static_cast<QComboBox*>(editor);
return comboBox->currentIndex(); return comboBox->currentIndex();
} }
void setEditorValue(QWidget *editor, QVariant value) { void setEditorValue(QWidget *editor, QVariant value) {
QComboBox *comboBox = static_cast<QComboBox*>(editor); QComboBox *comboBox = static_cast<QComboBox*>(editor);
comboBox->setCurrentIndex(value.toInt()); comboBox->setCurrentIndex(value.toInt());
} }
private: private:
QStringList m_enumOptions; QStringList m_enumOptions;
UAVObjectField *m_field; UAVObjectField *m_field;
}; };
class IntFieldTreeItem : public FieldTreeItem class IntFieldTreeItem : public FieldTreeItem
{ {
Q_OBJECT Q_OBJECT
public: public:
IntFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) : IntFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
FieldTreeItem(index, data, parent), m_field(field) { FieldTreeItem(index, data, parent), m_field(field) {
setMinMaxValues(); setMinMaxValues();
} }
IntFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) : IntFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) :
FieldTreeItem(index, data, parent), m_field(field) { FieldTreeItem(index, data, parent), m_field(field) {
setMinMaxValues(); setMinMaxValues();
} }
void setMinMaxValues() { void setMinMaxValues() {
switch (m_field->getType()) { switch (m_field->getType()) {
case UAVObjectField::INT8: case UAVObjectField::INT8:
m_minValue = QINT8MIN; m_minValue = QINT8MIN;
m_maxValue = QINT8MAX; m_maxValue = QINT8MAX;
break; break;
case UAVObjectField::INT16: case UAVObjectField::INT16:
m_minValue = QINT16MIN; m_minValue = QINT16MIN;
m_maxValue = QINT16MAX; m_maxValue = QINT16MAX;
break; break;
case UAVObjectField::INT32: case UAVObjectField::INT32:
m_minValue = QINT32MIN; m_minValue = QINT32MIN;
m_maxValue = QINT32MAX; m_maxValue = QINT32MAX;
break; break;
case UAVObjectField::UINT8: case UAVObjectField::UINT8:
m_minValue = QUINTMIN; m_minValue = QUINTMIN;
m_maxValue = QUINT8MAX; m_maxValue = QUINT8MAX;
break; break;
case UAVObjectField::UINT16: case UAVObjectField::UINT16:
m_minValue = QUINTMIN; m_minValue = QUINTMIN;
m_maxValue = QUINT16MAX; m_maxValue = QUINT16MAX;
break; break;
case UAVObjectField::UINT32: case UAVObjectField::UINT32:
m_minValue = QUINTMIN; m_minValue = QUINTMIN;
m_maxValue = QUINT32MAX; m_maxValue = QUINT32MAX;
break; break;
default: default:
Q_ASSERT(false); Q_ASSERT(false);
break; break;
} }
} }
QWidget *createEditor(QWidget *parent) { QWidget *createEditor(QWidget *parent) {
QSpinBox *editor = new QSpinBox(parent); QSpinBox *editor = new QSpinBox(parent);
editor->setMinimum(m_minValue); editor->setMinimum(m_minValue);
editor->setMaximum(m_maxValue); editor->setMaximum(m_maxValue);
return editor; return editor;
} }
QVariant getEditorValue(QWidget *editor) { QVariant getEditorValue(QWidget *editor) {
QSpinBox *spinBox = static_cast<QSpinBox*>(editor); QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
spinBox->interpretText(); spinBox->interpretText();
return spinBox->value(); return spinBox->value();
} }
void setEditorValue(QWidget *editor, QVariant value) { void setEditorValue(QWidget *editor, QVariant value) {
QSpinBox *spinBox = static_cast<QSpinBox*>(editor); QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
spinBox->setValue(value.toInt()); spinBox->setValue(value.toInt());
} }
void setData(QVariant value, int column) { void setData(QVariant value, int column) {
setChanged(m_field->getValue(m_index) != value); setChanged(m_field->getValue(m_index) != value);
TreeItem::setData(value, column); TreeItem::setData(value, column);
} }
void apply() { void apply() {
m_field->setValue(data(dataColumn).toInt(), m_index); m_field->setValue(data(dataColumn).toInt(), m_index);
setChanged(false); setChanged(false);
} }
void update() { void update() {
int value = m_field->getValue(m_index).toInt(); int value = m_field->getValue(m_index).toInt();
if (data() != value || changed()) { if (data() != value || changed()) {
TreeItem::setData(value); TreeItem::setData(value);
setHighlight(true); setHighlight(true);
} }
} }
private: private:
UAVObjectField *m_field; UAVObjectField *m_field;
int m_minValue; int m_minValue;
int m_maxValue; int m_maxValue;
}; };
class FloatFieldTreeItem : public FieldTreeItem class FloatFieldTreeItem : public FieldTreeItem
{ {
Q_OBJECT Q_OBJECT
public: public:
FloatFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) : FloatFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
FieldTreeItem(index, data, parent), m_field(field) { } FieldTreeItem(index, data, parent), m_field(field) { }
FloatFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) : FloatFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) :
FieldTreeItem(index, data, parent), m_field(field) { } FieldTreeItem(index, data, parent), m_field(field) { }
void setData(QVariant value, int column) { void setData(QVariant value, int column) {
setChanged(m_field->getValue(m_index) != value); setChanged(m_field->getValue(m_index) != value);
TreeItem::setData(value, column); TreeItem::setData(value, column);
} }
void apply() { void apply() {
m_field->setValue(data(dataColumn).toDouble(), m_index); m_field->setValue(data(dataColumn).toDouble(), m_index);
setChanged(false); setChanged(false);
} }
void update() { void update() {
double value = m_field->getValue(m_index).toDouble(); double value = m_field->getValue(m_index).toDouble();
if (data() != value || changed()) { if (data() != value || changed()) {
TreeItem::setData(value); TreeItem::setData(value);
setHighlight(true); setHighlight(true);
} }
} }
QWidget *createEditor(QWidget *parent) { QWidget *createEditor(QWidget *parent) {
QDoubleSpinBox *editor = new QDoubleSpinBox(parent); QDoubleSpinBox *editor = new QDoubleSpinBox(parent);
editor->setDecimals(6); editor->setDecimals(6);
editor->setMinimum(-std::numeric_limits<float>::max()); editor->setMinimum(-std::numeric_limits<float>::max());
editor->setMaximum(std::numeric_limits<float>::max()); editor->setMaximum(std::numeric_limits<float>::max());
return editor; return editor;
} }
QVariant getEditorValue(QWidget *editor) { QVariant getEditorValue(QWidget *editor) {
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor); QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
spinBox->interpretText(); spinBox->interpretText();
return spinBox->value(); return spinBox->value();
} }
void setEditorValue(QWidget *editor, QVariant value) { void setEditorValue(QWidget *editor, QVariant value) {
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor); QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
spinBox->setValue(value.toDouble()); spinBox->setValue(value.toDouble());
} }
private: private:
UAVObjectField *m_field; UAVObjectField *m_field;
}; };
#endif // FIELDTREEITEM_H #endif // FIELDTREEITEM_H

View File

@ -1,128 +1,128 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file treeitem.cpp * @file treeitem.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser * @defgroup uavobjectbrowserplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "treeitem.h" #include "treeitem.h"
int TreeItem::m_highlightTimeMs = 500; int TreeItem::m_highlightTimeMs = 500;
TreeItem::TreeItem(const QList<QVariant> &data, TreeItem *parent) : TreeItem::TreeItem(const QList<QVariant> &data, TreeItem *parent) :
QObject(0), QObject(0),
m_data(data), m_data(data),
m_parent(parent), m_parent(parent),
m_highlight(false), m_highlight(false),
m_changed(false) m_changed(false)
{ {
connect(&m_timer, SIGNAL(timeout()), this, SLOT(removeHighlight())); connect(&m_timer, SIGNAL(timeout()), this, SLOT(removeHighlight()));
} }
TreeItem::TreeItem(const QVariant &data, TreeItem *parent) : TreeItem::TreeItem(const QVariant &data, TreeItem *parent) :
QObject(0), QObject(0),
m_parent(parent), m_parent(parent),
m_highlight(false), m_highlight(false),
m_changed(false) m_changed(false)
{ {
m_data << data << "" << ""; m_data << data << "" << "";
connect(&m_timer, SIGNAL(timeout()), this, SLOT(removeHighlight())); connect(&m_timer, SIGNAL(timeout()), this, SLOT(removeHighlight()));
} }
TreeItem::~TreeItem() TreeItem::~TreeItem()
{ {
qDeleteAll(m_children); qDeleteAll(m_children);
} }
void TreeItem::appendChild(TreeItem *child) void TreeItem::appendChild(TreeItem *child)
{ {
m_children.append(child); m_children.append(child);
child->setParentTree(this); child->setParentTree(this);
} }
void TreeItem::insert(int index, TreeItem *child) void TreeItem::insert(int index, TreeItem *child)
{ {
m_children.insert(index, child); m_children.insert(index, child);
child->setParentTree(this); child->setParentTree(this);
} }
TreeItem *TreeItem::child(int row) TreeItem *TreeItem::child(int row)
{ {
return m_children.value(row); return m_children.value(row);
} }
int TreeItem::childCount() const int TreeItem::childCount() const
{ {
return m_children.count(); return m_children.count();
} }
int TreeItem::row() const int TreeItem::row() const
{ {
if (m_parent) if (m_parent)
return m_parent->m_children.indexOf(const_cast<TreeItem*>(this)); return m_parent->m_children.indexOf(const_cast<TreeItem*>(this));
return 0; return 0;
} }
int TreeItem::columnCount() const int TreeItem::columnCount() const
{ {
return m_data.count(); return m_data.count();
} }
QVariant TreeItem::data(int column) const QVariant TreeItem::data(int column) const
{ {
return m_data.value(column); return m_data.value(column);
} }
void TreeItem::setData(QVariant value, int column) void TreeItem::setData(QVariant value, int column)
{ {
m_data.replace(column, value); m_data.replace(column, value);
} }
void TreeItem::update() { void TreeItem::update() {
foreach(TreeItem *child, treeChildren()) foreach(TreeItem *child, treeChildren())
child->update(); child->update();
} }
void TreeItem::apply() { void TreeItem::apply() {
foreach(TreeItem *child, treeChildren()) foreach(TreeItem *child, treeChildren())
child->apply(); child->apply();
} }
void TreeItem::setHighlight(bool highlight) { void TreeItem::setHighlight(bool highlight) {
m_highlight = highlight; m_highlight = highlight;
m_changed = false; m_changed = false;
if (highlight) { if (highlight) {
if (m_timer.isActive()) { if (m_timer.isActive()) {
m_timer.stop(); m_timer.stop();
} }
m_timer.setSingleShot(true); m_timer.setSingleShot(true);
m_timer.start(m_highlightTimeMs); m_timer.start(m_highlightTimeMs);
} }
emit updateHighlight(this); emit updateHighlight(this);
} }
void TreeItem::removeHighlight() { void TreeItem::removeHighlight() {
m_highlight = false; m_highlight = false;
update(); update();
emit updateHighlight(this); emit updateHighlight(this);
} }

View File

@ -1,183 +1,183 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file treeitem.h * @file treeitem.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser * @defgroup uavobjectbrowserplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef TREEITEM_H #ifndef TREEITEM_H
#define TREEITEM_H #define TREEITEM_H
#include "uavobjects/uavobject.h" #include "uavobjects/uavobject.h"
#include "uavobjects/uavmetaobject.h" #include "uavobjects/uavmetaobject.h"
#include "uavobjects/uavobjectfield.h" #include "uavobjects/uavobjectfield.h"
#include <QtCore/QList> #include <QtCore/QList>
#include <QtCore/QVariant> #include <QtCore/QVariant>
#include <QtCore/QTimer> #include <QtCore/QTimer>
#include <QtCore/QObject> #include <QtCore/QObject>
class TreeItem : public QObject class TreeItem : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
TreeItem(const QList<QVariant> &data, TreeItem *parent = 0); TreeItem(const QList<QVariant> &data, TreeItem *parent = 0);
TreeItem(const QVariant &data, TreeItem *parent = 0); TreeItem(const QVariant &data, TreeItem *parent = 0);
virtual ~TreeItem(); virtual ~TreeItem();
void appendChild(TreeItem *child); void appendChild(TreeItem *child);
void insert(int index, TreeItem *child); void insert(int index, TreeItem *child);
TreeItem *child(int row); TreeItem *child(int row);
inline QList<TreeItem*> treeChildren() const { return m_children; } inline QList<TreeItem*> treeChildren() const { return m_children; }
int childCount() const; int childCount() const;
int columnCount() const; int columnCount() const;
QVariant data(int column = 1) const; QVariant data(int column = 1) const;
// only column 1 (TreeItem::dataColumn) is changed with setData currently // only column 1 (TreeItem::dataColumn) is changed with setData currently
// other columns are initialized in constructor // other columns are initialized in constructor
virtual void setData(QVariant value, int column = 1); virtual void setData(QVariant value, int column = 1);
int row() const; int row() const;
TreeItem *parent() { return m_parent; } TreeItem *parent() { return m_parent; }
void setParentTree(TreeItem *parent) { m_parent = parent; } void setParentTree(TreeItem *parent) { m_parent = parent; }
inline virtual bool isEditable() { return false; } inline virtual bool isEditable() { return false; }
virtual void update(); virtual void update();
virtual void apply(); virtual void apply();
inline bool highlighted() { return m_highlight; } inline bool highlighted() { return m_highlight; }
void setHighlight(bool highlight); void setHighlight(bool highlight);
static void setHighlightTime(int time) { m_highlightTimeMs = time; } static void setHighlightTime(int time) { m_highlightTimeMs = time; }
inline bool changed() { return m_changed; } inline bool changed() { return m_changed; }
inline void setChanged(bool changed) { m_changed = changed; } inline void setChanged(bool changed) { m_changed = changed; }
signals: signals:
void updateHighlight(TreeItem*); void updateHighlight(TreeItem*);
private slots: private slots:
void removeHighlight(); void removeHighlight();
private: private:
QList<TreeItem*> m_children; QList<TreeItem*> m_children;
// m_data contains: [0] property name, [1] value, and [2] unit // m_data contains: [0] property name, [1] value, and [2] unit
QList<QVariant> m_data; QList<QVariant> m_data;
TreeItem *m_parent; TreeItem *m_parent;
bool m_highlight; bool m_highlight;
bool m_changed; bool m_changed;
QTimer m_timer; QTimer m_timer;
public: public:
static const int dataColumn = 1; static const int dataColumn = 1;
private: private:
static int m_highlightTimeMs; static int m_highlightTimeMs;
}; };
class TopTreeItem : public TreeItem class TopTreeItem : public TreeItem
{ {
Q_OBJECT Q_OBJECT
public: public:
TopTreeItem(const QList<QVariant> &data, TreeItem *parent = 0) : TreeItem(data, parent) { } TopTreeItem(const QList<QVariant> &data, TreeItem *parent = 0) : TreeItem(data, parent) { }
TopTreeItem(const QVariant &data, TreeItem *parent = 0) : TreeItem(data, parent) { } TopTreeItem(const QVariant &data, TreeItem *parent = 0) : TreeItem(data, parent) { }
QList<quint32> objIds() { return m_objIds; } QList<quint32> objIds() { return m_objIds; }
void addObjId(quint32 objId) { m_objIds.append(objId); } void addObjId(quint32 objId) { m_objIds.append(objId); }
void insertObjId(int index, quint32 objId) { m_objIds.insert(index, objId); } void insertObjId(int index, quint32 objId) { m_objIds.insert(index, objId); }
int nameIndex(QString name) { int nameIndex(QString name) {
for (int i = 0; i < childCount(); ++i) { for (int i = 0; i < childCount(); ++i) {
if (name < child(i)->data(0).toString()) if (name < child(i)->data(0).toString())
return i; return i;
} }
return childCount(); return childCount();
} }
private: private:
QList<quint32> m_objIds; QList<quint32> m_objIds;
}; };
class ObjectTreeItem : public TreeItem class ObjectTreeItem : public TreeItem
{ {
Q_OBJECT Q_OBJECT
public: public:
ObjectTreeItem(const QList<QVariant> &data, TreeItem *parent = 0) : ObjectTreeItem(const QList<QVariant> &data, TreeItem *parent = 0) :
TreeItem(data, parent), m_obj(0) { } TreeItem(data, parent), m_obj(0) { }
ObjectTreeItem(const QVariant &data, TreeItem *parent = 0) : ObjectTreeItem(const QVariant &data, TreeItem *parent = 0) :
TreeItem(data, parent), m_obj(0) { } TreeItem(data, parent), m_obj(0) { }
void setObject(UAVObject *obj) { m_obj = obj; } void setObject(UAVObject *obj) { m_obj = obj; }
inline UAVObject *object() { return m_obj; } inline UAVObject *object() { return m_obj; }
private: private:
UAVObject *m_obj; UAVObject *m_obj;
}; };
class MetaObjectTreeItem : public ObjectTreeItem class MetaObjectTreeItem : public ObjectTreeItem
{ {
Q_OBJECT Q_OBJECT
public: public:
MetaObjectTreeItem(UAVObject *obj, const QList<QVariant> &data, TreeItem *parent = 0) : MetaObjectTreeItem(UAVObject *obj, const QList<QVariant> &data, TreeItem *parent = 0) :
ObjectTreeItem(data, parent) { setObject(obj); } ObjectTreeItem(data, parent) { setObject(obj); }
MetaObjectTreeItem(UAVObject *obj, const QVariant &data, TreeItem *parent = 0) : MetaObjectTreeItem(UAVObject *obj, const QVariant &data, TreeItem *parent = 0) :
ObjectTreeItem(data, parent) { setObject(obj); } ObjectTreeItem(data, parent) { setObject(obj); }
}; };
class DataObjectTreeItem : public ObjectTreeItem class DataObjectTreeItem : public ObjectTreeItem
{ {
Q_OBJECT Q_OBJECT
public: public:
DataObjectTreeItem(const QList<QVariant> &data, TreeItem *parent = 0) : DataObjectTreeItem(const QList<QVariant> &data, TreeItem *parent = 0) :
ObjectTreeItem(data, parent) { } ObjectTreeItem(data, parent) { }
DataObjectTreeItem(const QVariant &data, TreeItem *parent = 0) : DataObjectTreeItem(const QVariant &data, TreeItem *parent = 0) :
ObjectTreeItem(data, parent) { } ObjectTreeItem(data, parent) { }
virtual void apply() { virtual void apply() {
foreach(TreeItem *child, treeChildren()) { foreach(TreeItem *child, treeChildren()) {
MetaObjectTreeItem *metaChild = dynamic_cast<MetaObjectTreeItem*>(child); MetaObjectTreeItem *metaChild = dynamic_cast<MetaObjectTreeItem*>(child);
if (!metaChild) if (!metaChild)
child->apply(); child->apply();
} }
} }
virtual void update() { virtual void update() {
foreach(TreeItem *child, treeChildren()) { foreach(TreeItem *child, treeChildren()) {
MetaObjectTreeItem *metaChild = dynamic_cast<MetaObjectTreeItem*>(child); MetaObjectTreeItem *metaChild = dynamic_cast<MetaObjectTreeItem*>(child);
if (!metaChild) if (!metaChild)
child->update(); child->update();
} }
} }
}; };
class InstanceTreeItem : public DataObjectTreeItem class InstanceTreeItem : public DataObjectTreeItem
{ {
Q_OBJECT Q_OBJECT
public: public:
InstanceTreeItem(UAVObject *obj, const QList<QVariant> &data, TreeItem *parent = 0) : InstanceTreeItem(UAVObject *obj, const QList<QVariant> &data, TreeItem *parent = 0) :
DataObjectTreeItem(data, parent) { setObject(obj); } DataObjectTreeItem(data, parent) { setObject(obj); }
InstanceTreeItem(UAVObject *obj, const QVariant &data, TreeItem *parent = 0) : InstanceTreeItem(UAVObject *obj, const QVariant &data, TreeItem *parent = 0) :
DataObjectTreeItem(data, parent) { setObject(obj); } DataObjectTreeItem(data, parent) { setObject(obj); }
virtual void apply() { TreeItem::apply(); } virtual void apply() { TreeItem::apply(); }
virtual void update() { TreeItem::update(); } virtual void update() { TreeItem::update(); }
}; };
class ArrayFieldTreeItem : public TreeItem class ArrayFieldTreeItem : public TreeItem
{ {
Q_OBJECT Q_OBJECT
public: public:
ArrayFieldTreeItem(const QList<QVariant> &data, TreeItem *parent = 0) : TreeItem(data, parent) { } ArrayFieldTreeItem(const QList<QVariant> &data, TreeItem *parent = 0) : TreeItem(data, parent) { }
ArrayFieldTreeItem(const QVariant &data, TreeItem *parent = 0) : TreeItem(data, parent) { } ArrayFieldTreeItem(const QVariant &data, TreeItem *parent = 0) : TreeItem(data, parent) { }
}; };
#endif // TREEITEM_H #endif // TREEITEM_H

View File

@ -1,49 +1,49 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavobjectbrowser.cpp * @file uavobjectbrowser.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser * @defgroup uavobjectbrowserplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "uavobjectbrowser.h" #include "uavobjectbrowser.h"
#include "uavobjectbrowserwidget.h" #include "uavobjectbrowserwidget.h"
#include "uavobjectbrowserconfiguration.h" #include "uavobjectbrowserconfiguration.h"
UAVObjectBrowser::UAVObjectBrowser(QString classId, UAVObjectBrowserWidget *widget, QWidget *parent) : UAVObjectBrowser::UAVObjectBrowser(QString classId, UAVObjectBrowserWidget *widget, QWidget *parent) :
IUAVGadget(classId, parent), IUAVGadget(classId, parent),
m_widget(widget) m_widget(widget)
{ {
} }
UAVObjectBrowser::~UAVObjectBrowser() UAVObjectBrowser::~UAVObjectBrowser()
{ {
} }
void UAVObjectBrowser::loadConfiguration(IUAVGadgetConfiguration* config) void UAVObjectBrowser::loadConfiguration(IUAVGadgetConfiguration* config)
{ {
UAVObjectBrowserConfiguration *m = qobject_cast<UAVObjectBrowserConfiguration*>(config); UAVObjectBrowserConfiguration *m = qobject_cast<UAVObjectBrowserConfiguration*>(config);
m_widget->setRecentlyUpdatedColor(m->recentlyUpdatedColor()); m_widget->setRecentlyUpdatedColor(m->recentlyUpdatedColor());
m_widget->setManuallyChangedColor(m->manuallyChangedColor()); m_widget->setManuallyChangedColor(m->manuallyChangedColor());
m_widget->setRecentlyUpdatedTimeout(m->recentlyUpdatedTimeout()); m_widget->setRecentlyUpdatedTimeout(m->recentlyUpdatedTimeout());
} }

View File

@ -1,56 +1,56 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavobjectbrowser.h * @file uavobjectbrowser.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser * @defgroup uavobjectbrowserplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef UAVOBJECTBROWSER_H_ #ifndef UAVOBJECTBROWSER_H_
#define UAVOBJECTBROWSER_H_ #define UAVOBJECTBROWSER_H_
#include <coreplugin/iuavgadget.h> #include <coreplugin/iuavgadget.h>
#include "uavobjectbrowserwidget.h" #include "uavobjectbrowserwidget.h"
class IUAVGadget; class IUAVGadget;
class QWidget; class QWidget;
class QString; class QString;
class UAVObjectBrowserWidget; class UAVObjectBrowserWidget;
using namespace Core; using namespace Core;
class UAVObjectBrowser : public Core::IUAVGadget class UAVObjectBrowser : public Core::IUAVGadget
{ {
Q_OBJECT Q_OBJECT
public: public:
UAVObjectBrowser(QString classId, UAVObjectBrowserWidget *widget, QWidget *parent = 0); UAVObjectBrowser(QString classId, UAVObjectBrowserWidget *widget, QWidget *parent = 0);
~UAVObjectBrowser(); ~UAVObjectBrowser();
QWidget *widget() { return m_widget; } QWidget *widget() { return m_widget; }
void loadConfiguration(IUAVGadgetConfiguration* config); void loadConfiguration(IUAVGadgetConfiguration* config);
private: private:
UAVObjectBrowserWidget *m_widget; UAVObjectBrowserWidget *m_widget;
}; };
#endif // UAVOBJECTBROWSER_H_ #endif // UAVOBJECTBROWSER_H_

View File

@ -1,69 +1,69 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavobjectbrowserconfiguration.cpp * @file uavobjectbrowserconfiguration.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser * @defgroup uavobjectbrowserplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "uavobjectbrowserconfiguration.h" #include "uavobjectbrowserconfiguration.h"
#include <QtCore/QDataStream> #include <QtCore/QDataStream>
UAVObjectBrowserConfiguration::UAVObjectBrowserConfiguration(QString classId, const QByteArray &state, QObject *parent) : UAVObjectBrowserConfiguration::UAVObjectBrowserConfiguration(QString classId, const QByteArray &state, QObject *parent) :
IUAVGadgetConfiguration(classId, parent), IUAVGadgetConfiguration(classId, parent),
m_recentlyUpdatedColor(QColor(255, 230, 230)), m_recentlyUpdatedColor(QColor(255, 230, 230)),
m_manuallyChangedColor(QColor(230, 230, 255)), m_manuallyChangedColor(QColor(230, 230, 255)),
m_recentlyUpdatedTimeout(500) m_recentlyUpdatedTimeout(500)
{ {
if (state.count() > 0) { if (state.count() > 0) {
QDataStream stream(state); QDataStream stream(state);
QColor recent; QColor recent;
QColor manual; QColor manual;
int timeout; int timeout;
stream >> recent; stream >> recent;
stream >> manual; stream >> manual;
stream >> timeout; stream >> timeout;
m_recentlyUpdatedColor = recent; m_recentlyUpdatedColor = recent;
m_manuallyChangedColor = manual; m_manuallyChangedColor = manual;
m_recentlyUpdatedTimeout = timeout; m_recentlyUpdatedTimeout = timeout;
} }
} }
IUAVGadgetConfiguration *UAVObjectBrowserConfiguration::clone() IUAVGadgetConfiguration *UAVObjectBrowserConfiguration::clone()
{ {
UAVObjectBrowserConfiguration *m = new UAVObjectBrowserConfiguration(this->classId()); UAVObjectBrowserConfiguration *m = new UAVObjectBrowserConfiguration(this->classId());
m->m_recentlyUpdatedColor = m_recentlyUpdatedColor; m->m_recentlyUpdatedColor = m_recentlyUpdatedColor;
m->m_manuallyChangedColor = m_manuallyChangedColor; m->m_manuallyChangedColor = m_manuallyChangedColor;
m->m_recentlyUpdatedTimeout = m_recentlyUpdatedTimeout; m->m_recentlyUpdatedTimeout = m_recentlyUpdatedTimeout;
return m; return m;
} }
QByteArray UAVObjectBrowserConfiguration::saveState() const QByteArray UAVObjectBrowserConfiguration::saveState() const
{ {
QByteArray bytes; QByteArray bytes;
QDataStream stream(&bytes, QIODevice::WriteOnly); QDataStream stream(&bytes, QIODevice::WriteOnly);
stream << m_recentlyUpdatedColor; stream << m_recentlyUpdatedColor;
stream << m_manuallyChangedColor; stream << m_manuallyChangedColor;
stream << m_recentlyUpdatedTimeout; stream << m_recentlyUpdatedTimeout;
return bytes; return bytes;
} }

View File

@ -1,64 +1,64 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavobjectbrowserconfiguration.h * @file uavobjectbrowserconfiguration.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser * @defgroup uavobjectbrowserplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef UAVOBJECTBROWSERCONFIGURATION_H #ifndef UAVOBJECTBROWSERCONFIGURATION_H
#define UAVOBJECTBROWSERCONFIGURATION_H #define UAVOBJECTBROWSERCONFIGURATION_H
#include <coreplugin/iuavgadgetconfiguration.h> #include <coreplugin/iuavgadgetconfiguration.h>
#include <QtGui/QColor> #include <QtGui/QColor>
using namespace Core; using namespace Core;
class UAVObjectBrowserConfiguration : public IUAVGadgetConfiguration class UAVObjectBrowserConfiguration : public IUAVGadgetConfiguration
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QColor m_recentlyUpdatedColor READ recentlyUpdatedColor WRITE setRecentlyUpdatedColor) Q_PROPERTY(QColor m_recentlyUpdatedColor READ recentlyUpdatedColor WRITE setRecentlyUpdatedColor)
Q_PROPERTY(QColor m_manuallyChangedColor READ manuallyChangedColor WRITE setManuallyChangedColor) Q_PROPERTY(QColor m_manuallyChangedColor READ manuallyChangedColor WRITE setManuallyChangedColor)
Q_PROPERTY(int m_recentlyUpdatedTimeout READ recentlyUpdatedTimeout WRITE setRecentlyUpdatedTimeout) Q_PROPERTY(int m_recentlyUpdatedTimeout READ recentlyUpdatedTimeout WRITE setRecentlyUpdatedTimeout)
public: public:
explicit UAVObjectBrowserConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0); explicit UAVObjectBrowserConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0);
QByteArray saveState() const; QByteArray saveState() const;
IUAVGadgetConfiguration *clone(); IUAVGadgetConfiguration *clone();
QColor recentlyUpdatedColor() const { return m_recentlyUpdatedColor; } QColor recentlyUpdatedColor() const { return m_recentlyUpdatedColor; }
QColor manuallyChangedColor() const { return m_manuallyChangedColor; } QColor manuallyChangedColor() const { return m_manuallyChangedColor; }
int recentlyUpdatedTimeout() const { return m_recentlyUpdatedTimeout; } int recentlyUpdatedTimeout() const { return m_recentlyUpdatedTimeout; }
signals: signals:
public slots: public slots:
void setRecentlyUpdatedColor(QColor color) { m_recentlyUpdatedColor = color; } void setRecentlyUpdatedColor(QColor color) { m_recentlyUpdatedColor = color; }
void setManuallyChangedColor(QColor color) { m_manuallyChangedColor = color; } void setManuallyChangedColor(QColor color) { m_manuallyChangedColor = color; }
void setRecentlyUpdatedTimeout(int timeout) { m_recentlyUpdatedTimeout = timeout; } void setRecentlyUpdatedTimeout(int timeout) { m_recentlyUpdatedTimeout = timeout; }
private: private:
QColor m_recentlyUpdatedColor; QColor m_recentlyUpdatedColor;
QColor m_manuallyChangedColor; QColor m_manuallyChangedColor;
int m_recentlyUpdatedTimeout; int m_recentlyUpdatedTimeout;
}; };
#endif // UAVOBJECTBROWSERCONFIGURATION_H #endif // UAVOBJECTBROWSERCONFIGURATION_H

View File

@ -1,58 +1,58 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavobjectbrowserfactory.cpp * @file uavobjectbrowserfactory.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser * @defgroup uavobjectbrowserplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "uavobjectbrowserfactory.h" #include "uavobjectbrowserfactory.h"
#include "uavobjectbrowserwidget.h" #include "uavobjectbrowserwidget.h"
#include "uavobjectbrowser.h" #include "uavobjectbrowser.h"
#include "uavobjectbrowserconfiguration.h" #include "uavobjectbrowserconfiguration.h"
#include "uavobjectbrowseroptionspage.h" #include "uavobjectbrowseroptionspage.h"
#include <coreplugin/iuavgadget.h> #include <coreplugin/iuavgadget.h>
UAVObjectBrowserFactory::UAVObjectBrowserFactory(QObject *parent) : UAVObjectBrowserFactory::UAVObjectBrowserFactory(QObject *parent) :
IUAVGadgetFactory(QString("UAVObjectBrowser"), tr("UAVObject Browser"), parent) IUAVGadgetFactory(QString("UAVObjectBrowser"), tr("UAVObject Browser"), parent)
{ {
} }
UAVObjectBrowserFactory::~UAVObjectBrowserFactory() UAVObjectBrowserFactory::~UAVObjectBrowserFactory()
{ {
} }
Core::IUAVGadget* UAVObjectBrowserFactory::createGadget(QWidget *parent) Core::IUAVGadget* UAVObjectBrowserFactory::createGadget(QWidget *parent)
{ {
UAVObjectBrowserWidget* gadgetWidget = new UAVObjectBrowserWidget(parent); UAVObjectBrowserWidget* gadgetWidget = new UAVObjectBrowserWidget(parent);
return new UAVObjectBrowser(QString("UAVObjectBrowser"), gadgetWidget, parent); return new UAVObjectBrowser(QString("UAVObjectBrowser"), gadgetWidget, parent);
} }
IUAVGadgetConfiguration *UAVObjectBrowserFactory::createConfiguration(const QByteArray &state) IUAVGadgetConfiguration *UAVObjectBrowserFactory::createConfiguration(const QByteArray &state)
{ {
return new UAVObjectBrowserConfiguration(QString("UAVObjectBrowser"), state); return new UAVObjectBrowserConfiguration(QString("UAVObjectBrowser"), state);
} }
IOptionsPage *UAVObjectBrowserFactory::createOptionsPage(IUAVGadgetConfiguration *config) IOptionsPage *UAVObjectBrowserFactory::createOptionsPage(IUAVGadgetConfiguration *config)
{ {
return new UAVObjectBrowserOptionsPage(qobject_cast<UAVObjectBrowserConfiguration*>(config)); return new UAVObjectBrowserOptionsPage(qobject_cast<UAVObjectBrowserConfiguration*>(config));
} }

View File

@ -1,52 +1,52 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavobjectbrowserfactory.h * @file uavobjectbrowserfactory.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser * @defgroup uavobjectbrowserplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef UAVOBJECTBROWSERFACTORY_H_ #ifndef UAVOBJECTBROWSERFACTORY_H_
#define UAVOBJECTBROWSERFACTORY_H_ #define UAVOBJECTBROWSERFACTORY_H_
#include <coreplugin/iuavgadgetfactory.h> #include <coreplugin/iuavgadgetfactory.h>
namespace Core { namespace Core {
class IUAVGadget; class IUAVGadget;
class IUAVGadgetFactory; class IUAVGadgetFactory;
} }
using namespace Core; using namespace Core;
class UAVObjectBrowserFactory : public Core::IUAVGadgetFactory class UAVObjectBrowserFactory : public Core::IUAVGadgetFactory
{ {
Q_OBJECT Q_OBJECT
public: public:
UAVObjectBrowserFactory(QObject *parent = 0); UAVObjectBrowserFactory(QObject *parent = 0);
~UAVObjectBrowserFactory(); ~UAVObjectBrowserFactory();
Core::IUAVGadget *createGadget(QWidget *parent); Core::IUAVGadget *createGadget(QWidget *parent);
IUAVGadgetConfiguration *createConfiguration(const QByteArray &state); IUAVGadgetConfiguration *createConfiguration(const QByteArray &state);
IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config); IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config);
}; };
#endif // UAVOBJECTBROWSERFACTORY_H_ #endif // UAVOBJECTBROWSERFACTORY_H_

View File

@ -1,70 +1,70 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavobjectbrowseroptionspage.cpp * @file uavobjectbrowseroptionspage.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief * @brief Options page for the UAVObject Browser Plugin
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser * @defgroup uavobjectbrowserplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "uavobjectbrowseroptionspage.h" #include "uavobjectbrowseroptionspage.h"
#include "uavobjectbrowserconfiguration.h" #include "uavobjectbrowserconfiguration.h"
#include <QtGui/QLabel> #include <QtGui/QLabel>
#include <QtGui/QSpinBox> #include <QtGui/QSpinBox>
#include <QtGui/QPushButton> #include <QtGui/QPushButton>
#include <QtGui/QHBoxLayout> #include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout> #include <QtGui/QVBoxLayout>
#include <QtGui/QColorDialog> #include <QtGui/QColorDialog>
#include "ui_uavobjectbrowseroptionspage.h" #include "ui_uavobjectbrowseroptionspage.h"
UAVObjectBrowserOptionsPage::UAVObjectBrowserOptionsPage(UAVObjectBrowserConfiguration *config, QObject *parent) : UAVObjectBrowserOptionsPage::UAVObjectBrowserOptionsPage(UAVObjectBrowserConfiguration *config, QObject *parent) :
IOptionsPage(parent), IOptionsPage(parent),
m_config(config) m_config(config)
{ {
} }
QWidget *UAVObjectBrowserOptionsPage::createPage(QWidget *parent) QWidget *UAVObjectBrowserOptionsPage::createPage(QWidget *parent)
{ {
m_page = new Ui::UAVObjectBrowserOptionsPage(); m_page = new Ui::UAVObjectBrowserOptionsPage();
QWidget *w = new QWidget(parent); QWidget *w = new QWidget(parent);
m_page->setupUi(w); m_page->setupUi(w);
m_page->recentlyUpdatedButton->setColor(m_config->recentlyUpdatedColor()); m_page->recentlyUpdatedButton->setColor(m_config->recentlyUpdatedColor());
m_page->manuallyChangedButton->setColor(m_config->manuallyChangedColor()); m_page->manuallyChangedButton->setColor(m_config->manuallyChangedColor());
m_page->recentlyUpdatedTimeoutSpinBox->setValue(m_config->recentlyUpdatedTimeout()); m_page->recentlyUpdatedTimeoutSpinBox->setValue(m_config->recentlyUpdatedTimeout());
return w; return w;
} }
void UAVObjectBrowserOptionsPage::apply() void UAVObjectBrowserOptionsPage::apply()
{ {
m_config->setRecentlyUpdatedColor(m_page->recentlyUpdatedButton->color()); m_config->setRecentlyUpdatedColor(m_page->recentlyUpdatedButton->color());
m_config->setManuallyChangedColor(m_page->manuallyChangedButton->color()); m_config->setManuallyChangedColor(m_page->manuallyChangedButton->color());
m_config->setRecentlyUpdatedTimeout(m_page->recentlyUpdatedTimeoutSpinBox->value()); m_config->setRecentlyUpdatedTimeout(m_page->recentlyUpdatedTimeoutSpinBox->value());
} }
void UAVObjectBrowserOptionsPage::finish() void UAVObjectBrowserOptionsPage::finish()
{ {
delete m_page; delete m_page;
} }

View File

@ -1,68 +1,68 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavobjectbrowseroptionspage.h * @file uavobjectbrowseroptionspage.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser * @defgroup uavobjectbrowserplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef UAVOBJECTBROWSEROPTIONSPAGE_H #ifndef UAVOBJECTBROWSEROPTIONSPAGE_H
#define UAVOBJECTBROWSEROPTIONSPAGE_H #define UAVOBJECTBROWSEROPTIONSPAGE_H
#include "coreplugin/dialogs/ioptionspage.h" #include "coreplugin/dialogs/ioptionspage.h"
#include <QtGui/QColor> #include <QtGui/QColor>
#include <utils/qtcolorbutton.h> #include <utils/qtcolorbutton.h>
namespace Core { namespace Core {
class IUAVGadgetConfiguration; class IUAVGadgetConfiguration;
} }
class UAVObjectBrowserConfiguration; class UAVObjectBrowserConfiguration;
class QLabel; class QLabel;
class QPushButton; class QPushButton;
class QSpinBox; class QSpinBox;
using namespace Core; using namespace Core;
namespace Ui { namespace Ui {
class UAVObjectBrowserOptionsPage; class UAVObjectBrowserOptionsPage;
} }
class UAVObjectBrowserOptionsPage : public IOptionsPage class UAVObjectBrowserOptionsPage : public IOptionsPage
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit UAVObjectBrowserOptionsPage(UAVObjectBrowserConfiguration *config, QObject *parent = 0); explicit UAVObjectBrowserOptionsPage(UAVObjectBrowserConfiguration *config, QObject *parent = 0);
QWidget *createPage(QWidget *parent); QWidget *createPage(QWidget *parent);
void apply(); void apply();
void finish(); void finish();
signals: signals:
private slots: private slots:
private: private:
UAVObjectBrowserConfiguration *m_config; UAVObjectBrowserConfiguration *m_config;
Ui::UAVObjectBrowserOptionsPage *m_page; Ui::UAVObjectBrowserOptionsPage *m_page;
}; };
#endif // UAVOBJECTBROWSEROPTIONSPAGE_H #endif // UAVOBJECTBROWSEROPTIONSPAGE_H

View File

@ -1,187 +1,187 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavobjectbrowserwidget.cpp * @file uavobjectbrowserwidget.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser * @defgroup uavobjectbrowserplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "uavobjectbrowserwidget.h" #include "uavobjectbrowserwidget.h"
#include "uavobjecttreemodel.h" #include "uavobjecttreemodel.h"
#include "browseritemdelegate.h" #include "browseritemdelegate.h"
#include "treeitem.h" #include "treeitem.h"
#include "ui_uavobjectbrowser.h" #include "ui_uavobjectbrowser.h"
#include "uavobjects/uavobjectmanager.h" #include "uavobjects/uavobjectmanager.h"
#include <QStringList> #include <QStringList>
#include <QtGui/QHBoxLayout> #include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout> #include <QtGui/QVBoxLayout>
#include <QtGui/QPushButton> #include <QtGui/QPushButton>
#include <QtGui/QComboBox> #include <QtGui/QComboBox>
#include <QtCore/QDebug> #include <QtCore/QDebug>
#include <QtGui/QItemEditorFactory> #include <QtGui/QItemEditorFactory>
#include "extensionsystem/pluginmanager.h" #include "extensionsystem/pluginmanager.h"
UAVObjectBrowserWidget::UAVObjectBrowserWidget(QWidget *parent) : QWidget(parent) UAVObjectBrowserWidget::UAVObjectBrowserWidget(QWidget *parent) : QWidget(parent)
{ {
m_browser = new Ui_UAVObjectBrowser(); m_browser = new Ui_UAVObjectBrowser();
m_browser->setupUi(this); m_browser->setupUi(this);
m_model = new UAVObjectTreeModel(); m_model = new UAVObjectTreeModel();
m_browser->treeView->setModel(m_model); m_browser->treeView->setModel(m_model);
m_browser->treeView->setColumnWidth(0, 300); m_browser->treeView->setColumnWidth(0, 300);
//m_browser->treeView->expandAll(); //m_browser->treeView->expandAll();
BrowserItemDelegate *m_delegate = new BrowserItemDelegate(); BrowserItemDelegate *m_delegate = new BrowserItemDelegate();
m_browser->treeView->setItemDelegate(m_delegate); m_browser->treeView->setItemDelegate(m_delegate);
m_browser->treeView->setEditTriggers(QAbstractItemView::AllEditTriggers); m_browser->treeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
m_browser->treeView->setSelectionBehavior(QAbstractItemView::SelectItems); m_browser->treeView->setSelectionBehavior(QAbstractItemView::SelectItems);
showMetaData(m_browser->metaCheckBox->isChecked()); showMetaData(m_browser->metaCheckBox->isChecked());
connect(m_browser->treeView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged(QModelIndex,QModelIndex))); 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->metaCheckBox, SIGNAL(toggled(bool)), this, SLOT(showMetaData(bool)));
connect(m_browser->saveSDButton, SIGNAL(clicked()), this, SLOT(saveObject())); connect(m_browser->saveSDButton, SIGNAL(clicked()), this, SLOT(saveObject()));
connect(m_browser->readSDButton, SIGNAL(clicked()), this, SLOT(loadObject())); connect(m_browser->readSDButton, SIGNAL(clicked()), this, SLOT(loadObject()));
connect(m_browser->eraseSDButton, SIGNAL(clicked()), this, SLOT(eraseObject())); connect(m_browser->eraseSDButton, SIGNAL(clicked()), this, SLOT(eraseObject()));
connect(m_browser->sendButton, SIGNAL(clicked()), this, SLOT(sendUpdate())); connect(m_browser->sendButton, SIGNAL(clicked()), this, SLOT(sendUpdate()));
connect(m_browser->requestButton, SIGNAL(clicked()), this, SLOT(requestUpdate())); connect(m_browser->requestButton, SIGNAL(clicked()), this, SLOT(requestUpdate()));
enableSendRequest(false); enableSendRequest(false);
} }
UAVObjectBrowserWidget::~UAVObjectBrowserWidget() UAVObjectBrowserWidget::~UAVObjectBrowserWidget()
{ {
delete m_browser; delete m_browser;
} }
void UAVObjectBrowserWidget::showMetaData(bool show) void UAVObjectBrowserWidget::showMetaData(bool show)
{ {
int topRowCount = m_model->rowCount(QModelIndex()); int topRowCount = m_model->rowCount(QModelIndex());
for (int i = 0; i < topRowCount; ++i) { for (int i = 0; i < topRowCount; ++i) {
QModelIndex index = m_model->index(i, 0, QModelIndex()); QModelIndex index = m_model->index(i, 0, QModelIndex());
int subRowCount = m_model->rowCount(index); int subRowCount = m_model->rowCount(index);
for (int j = 0; j < subRowCount; ++j) { for (int j = 0; j < subRowCount; ++j) {
m_browser->treeView->setRowHidden(0, index.child(j,0), !show); m_browser->treeView->setRowHidden(0, index.child(j,0), !show);
} }
} }
} }
void UAVObjectBrowserWidget::sendUpdate() void UAVObjectBrowserWidget::sendUpdate()
{ {
ObjectTreeItem *objItem = findCurrentObjectTreeItem(); ObjectTreeItem *objItem = findCurrentObjectTreeItem();
Q_ASSERT(objItem); Q_ASSERT(objItem);
objItem->apply(); objItem->apply();
UAVObject *obj = objItem->object(); UAVObject *obj = objItem->object();
Q_ASSERT(obj); Q_ASSERT(obj);
obj->updated(); obj->updated();
} }
void UAVObjectBrowserWidget::requestUpdate() void UAVObjectBrowserWidget::requestUpdate()
{ {
ObjectTreeItem *objItem = findCurrentObjectTreeItem(); ObjectTreeItem *objItem = findCurrentObjectTreeItem();
Q_ASSERT(objItem); Q_ASSERT(objItem);
UAVObject *obj = objItem->object(); UAVObject *obj = objItem->object();
Q_ASSERT(obj); Q_ASSERT(obj);
obj->requestUpdate(); obj->requestUpdate();
} }
ObjectTreeItem *UAVObjectBrowserWidget::findCurrentObjectTreeItem() ObjectTreeItem *UAVObjectBrowserWidget::findCurrentObjectTreeItem()
{ {
QModelIndex current = m_browser->treeView->currentIndex(); QModelIndex current = m_browser->treeView->currentIndex();
TreeItem *item = static_cast<TreeItem*>(current.internalPointer()); TreeItem *item = static_cast<TreeItem*>(current.internalPointer());
ObjectTreeItem *objItem = 0; ObjectTreeItem *objItem = 0;
while (item) { while (item) {
objItem = dynamic_cast<ObjectTreeItem*>(item); objItem = dynamic_cast<ObjectTreeItem*>(item);
if (objItem) if (objItem)
break; break;
item = item->parent(); item = item->parent();
} }
return objItem; return objItem;
} }
void UAVObjectBrowserWidget::saveObject() void UAVObjectBrowserWidget::saveObject()
{ {
// Send update so that the latest value is saved // Send update so that the latest value is saved
sendUpdate(); sendUpdate();
// Save object // Save object
ObjectTreeItem *objItem = findCurrentObjectTreeItem(); ObjectTreeItem *objItem = findCurrentObjectTreeItem();
Q_ASSERT(objItem); Q_ASSERT(objItem);
UAVObject *obj = objItem->object(); UAVObject *obj = objItem->object();
Q_ASSERT(obj); Q_ASSERT(obj);
updateObjectPersistance(ObjectPersistence::OPERATION_SAVE, obj); updateObjectPersistance(ObjectPersistence::OPERATION_SAVE, obj);
} }
void UAVObjectBrowserWidget::loadObject() void UAVObjectBrowserWidget::loadObject()
{ {
// Load object // Load object
ObjectTreeItem *objItem = findCurrentObjectTreeItem(); ObjectTreeItem *objItem = findCurrentObjectTreeItem();
Q_ASSERT(objItem); Q_ASSERT(objItem);
UAVObject *obj = objItem->object(); UAVObject *obj = objItem->object();
Q_ASSERT(obj); Q_ASSERT(obj);
updateObjectPersistance(ObjectPersistence::OPERATION_LOAD, obj); updateObjectPersistance(ObjectPersistence::OPERATION_LOAD, obj);
// Retrieve object so that latest value is displayed // Retrieve object so that latest value is displayed
requestUpdate(); requestUpdate();
} }
void UAVObjectBrowserWidget::eraseObject() void UAVObjectBrowserWidget::eraseObject()
{ {
ObjectTreeItem *objItem = findCurrentObjectTreeItem(); ObjectTreeItem *objItem = findCurrentObjectTreeItem();
Q_ASSERT(objItem); Q_ASSERT(objItem);
UAVObject *obj = objItem->object(); UAVObject *obj = objItem->object();
Q_ASSERT(obj); Q_ASSERT(obj);
updateObjectPersistance(ObjectPersistence::OPERATION_DELETE, obj); updateObjectPersistance(ObjectPersistence::OPERATION_DELETE, obj);
} }
void UAVObjectBrowserWidget::updateObjectPersistance(ObjectPersistence::OperationOptions op, UAVObject *obj) void UAVObjectBrowserWidget::updateObjectPersistance(ObjectPersistence::OperationOptions op, UAVObject *obj)
{ {
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>(); UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
ObjectPersistence* objper = dynamic_cast<ObjectPersistence*>( objManager->getObject(ObjectPersistence::NAME) ); ObjectPersistence* objper = dynamic_cast<ObjectPersistence*>( objManager->getObject(ObjectPersistence::NAME) );
if (obj != NULL) if (obj != NULL)
{ {
ObjectPersistence::DataFields data; ObjectPersistence::DataFields data;
data.Operation = op; data.Operation = op;
data.Selection = ObjectPersistence::SELECTION_SINGLEOBJECT; data.Selection = ObjectPersistence::SELECTION_SINGLEOBJECT;
data.ObjectID = obj->getObjID(); data.ObjectID = obj->getObjID();
data.InstanceID = obj->getInstID(); data.InstanceID = obj->getInstID();
objper->setData(data); objper->setData(data);
objper->updated(); objper->updated();
} }
} }
void UAVObjectBrowserWidget::currentChanged(const QModelIndex &current, const QModelIndex &previous) void UAVObjectBrowserWidget::currentChanged(const QModelIndex &current, const QModelIndex &previous)
{ {
TreeItem *item = static_cast<TreeItem*>(current.internalPointer()); TreeItem *item = static_cast<TreeItem*>(current.internalPointer());
bool enable = true; bool enable = true;
if (current == QModelIndex()) if (current == QModelIndex())
enable = false; enable = false;
TopTreeItem *top = dynamic_cast<TopTreeItem*>(item); TopTreeItem *top = dynamic_cast<TopTreeItem*>(item);
ObjectTreeItem *data = dynamic_cast<ObjectTreeItem*>(item); ObjectTreeItem *data = dynamic_cast<ObjectTreeItem*>(item);
if (top || (data && !data->object())) if (top || (data && !data->object()))
enable = false; enable = false;
enableSendRequest(enable); enableSendRequest(enable);
} }
void UAVObjectBrowserWidget::enableSendRequest(bool enable) void UAVObjectBrowserWidget::enableSendRequest(bool enable)
{ {
m_browser->sendButton->setEnabled(enable); m_browser->sendButton->setEnabled(enable);
m_browser->requestButton->setEnabled(enable); m_browser->requestButton->setEnabled(enable);
m_browser->saveSDButton->setEnabled(enable); m_browser->saveSDButton->setEnabled(enable);
m_browser->readSDButton->setEnabled(enable); m_browser->readSDButton->setEnabled(enable);
m_browser->eraseSDButton->setEnabled(enable); m_browser->eraseSDButton->setEnabled(enable);
} }

View File

@ -1,74 +1,74 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavobjectbrowserwidget.h * @file uavobjectbrowserwidget.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser * @defgroup uavobjectbrowserplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef UAVOBJECTBROWSERWIDGET_H_ #ifndef UAVOBJECTBROWSERWIDGET_H_
#define UAVOBJECTBROWSERWIDGET_H_ #define UAVOBJECTBROWSERWIDGET_H_
#include <QtGui/QWidget> #include <QtGui/QWidget>
#include <QtGui/QTreeView> #include <QtGui/QTreeView>
#include "uavobjects/objectpersistence.h" #include "uavobjects/objectpersistence.h"
#include "uavobjecttreemodel.h" #include "uavobjecttreemodel.h"
class QPushButton; class QPushButton;
class ObjectTreeItem; class ObjectTreeItem;
class Ui_UAVObjectBrowser; class Ui_UAVObjectBrowser;
class UAVObjectBrowserWidget : public QWidget class UAVObjectBrowserWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
UAVObjectBrowserWidget(QWidget *parent = 0); UAVObjectBrowserWidget(QWidget *parent = 0);
~UAVObjectBrowserWidget(); ~UAVObjectBrowserWidget();
void setRecentlyUpdatedColor(QColor color) { m_model->setRecentlyUpdatedColor(color); } void setRecentlyUpdatedColor(QColor color) { m_model->setRecentlyUpdatedColor(color); }
void setManuallyChangedColor(QColor color) { m_model->setManuallyChangedColor(color); } void setManuallyChangedColor(QColor color) { m_model->setManuallyChangedColor(color); }
void setRecentlyUpdatedTimeout(int timeout) { m_model->setRecentlyUpdatedTimeout(timeout); } void setRecentlyUpdatedTimeout(int timeout) { m_model->setRecentlyUpdatedTimeout(timeout); }
public slots: public slots:
void showMetaData(bool show); void showMetaData(bool show);
private slots: private slots:
void sendUpdate(); void sendUpdate();
void requestUpdate(); void requestUpdate();
void saveObject(); void saveObject();
void loadObject(); void loadObject();
void eraseObject(); void eraseObject();
void currentChanged(const QModelIndex &current, const QModelIndex &previous); void currentChanged(const QModelIndex &current, const QModelIndex &previous);
private: private:
QPushButton *m_requestUpdate; QPushButton *m_requestUpdate;
QPushButton *m_sendUpdate; QPushButton *m_sendUpdate;
Ui_UAVObjectBrowser *m_browser; Ui_UAVObjectBrowser *m_browser;
UAVObjectTreeModel *m_model; UAVObjectTreeModel *m_model;
void updateObjectPersistance(ObjectPersistence::OperationOptions op, UAVObject *obj); void updateObjectPersistance(ObjectPersistence::OperationOptions op, UAVObject *obj);
void enableSendRequest(bool enable); void enableSendRequest(bool enable);
ObjectTreeItem *findCurrentObjectTreeItem(); ObjectTreeItem *findCurrentObjectTreeItem();
}; };
#endif /* UAVOBJECTBROWSERWIDGET_H_ */ #endif /* UAVOBJECTBROWSERWIDGET_H_ */

View File

@ -1,411 +1,411 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavobjecttreemodel.cpp * @file uavobjecttreemodel.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser * @defgroup uavobjectbrowserplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "uavobjecttreemodel.h" #include "uavobjecttreemodel.h"
#include "fieldtreeitem.h" #include "fieldtreeitem.h"
#include "uavobjects/uavobjectmanager.h" #include "uavobjects/uavobjectmanager.h"
#include "uavobjects/uavdataobject.h" #include "uavobjects/uavdataobject.h"
#include "uavobjects/uavmetaobject.h" #include "uavobjects/uavmetaobject.h"
#include "uavobjects/uavobjectfield.h" #include "uavobjects/uavobjectfield.h"
#include "extensionsystem/pluginmanager.h" #include "extensionsystem/pluginmanager.h"
#include <QtGui/QColor> #include <QtGui/QColor>
//#include <QtGui/QIcon> //#include <QtGui/QIcon>
#include <QtCore/QTimer> #include <QtCore/QTimer>
#include <QtCore/QSignalMapper> #include <QtCore/QSignalMapper>
#include <QtCore/QDebug> #include <QtCore/QDebug>
UAVObjectTreeModel::UAVObjectTreeModel(QObject *parent) : UAVObjectTreeModel::UAVObjectTreeModel(QObject *parent) :
QAbstractItemModel(parent), QAbstractItemModel(parent),
m_recentlyUpdatedTimeout(500), // ms m_recentlyUpdatedTimeout(500), // ms
m_recentlyUpdatedColor(QColor(255, 230, 230)), m_recentlyUpdatedColor(QColor(255, 230, 230)),
m_manuallyChangedColor(QColor(230, 230, 255)) m_manuallyChangedColor(QColor(230, 230, 255))
{ {
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>(); UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
connect(objManager, SIGNAL(newObject(UAVObject*)), this, SLOT(newObject(UAVObject*))); connect(objManager, SIGNAL(newObject(UAVObject*)), this, SLOT(newObject(UAVObject*)));
connect(objManager, SIGNAL(newInstance(UAVObject*)), this, SLOT(newObject(UAVObject*))); connect(objManager, SIGNAL(newInstance(UAVObject*)), this, SLOT(newObject(UAVObject*)));
TreeItem::setHighlightTime(m_recentlyUpdatedTimeout); TreeItem::setHighlightTime(m_recentlyUpdatedTimeout);
setupModelData(objManager); setupModelData(objManager);
} }
UAVObjectTreeModel::~UAVObjectTreeModel() UAVObjectTreeModel::~UAVObjectTreeModel()
{ {
delete m_rootItem; delete m_rootItem;
} }
void UAVObjectTreeModel::setupModelData(UAVObjectManager *objManager) void UAVObjectTreeModel::setupModelData(UAVObjectManager *objManager)
{ {
// root // root
QList<QVariant> rootData; QList<QVariant> rootData;
rootData << tr("Property") << tr("Value") << tr("Unit"); rootData << tr("Property") << tr("Value") << tr("Unit");
m_rootItem = new TreeItem(rootData); m_rootItem = new TreeItem(rootData);
m_settingsTree = new TopTreeItem(tr("Settings"), m_rootItem); m_settingsTree = new TopTreeItem(tr("Settings"), m_rootItem);
m_rootItem->appendChild(m_settingsTree); m_rootItem->appendChild(m_settingsTree);
m_nonSettingsTree = new TopTreeItem(tr("Data Objects"), m_rootItem); m_nonSettingsTree = new TopTreeItem(tr("Data Objects"), m_rootItem);
m_rootItem->appendChild(m_nonSettingsTree); m_rootItem->appendChild(m_nonSettingsTree);
connect(m_settingsTree, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*))); connect(m_settingsTree, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
connect(m_nonSettingsTree, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*))); connect(m_nonSettingsTree, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
QList< QList<UAVDataObject*> > objList = objManager->getDataObjects(); QList< QList<UAVDataObject*> > objList = objManager->getDataObjects();
foreach (QList<UAVDataObject*> list, objList) { foreach (QList<UAVDataObject*> list, objList) {
foreach (UAVDataObject* obj, list) { foreach (UAVDataObject* obj, list) {
addDataObject(obj); addDataObject(obj);
} }
} }
} }
void UAVObjectTreeModel::newObject(UAVObject *obj) void UAVObjectTreeModel::newObject(UAVObject *obj)
{ {
UAVDataObject *dobj = qobject_cast<UAVDataObject*>(obj); UAVDataObject *dobj = qobject_cast<UAVDataObject*>(obj);
if (dobj) if (dobj)
addDataObject(dobj); addDataObject(dobj);
} }
void UAVObjectTreeModel::addDataObject(UAVDataObject *obj) void UAVObjectTreeModel::addDataObject(UAVDataObject *obj)
{ {
TopTreeItem *root = obj->isSettings() ? m_settingsTree : m_nonSettingsTree; TopTreeItem *root = obj->isSettings() ? m_settingsTree : m_nonSettingsTree;
if (root->objIds().contains(obj->getObjID())) { if (root->objIds().contains(obj->getObjID())) {
int index = root->objIds().indexOf(obj->getObjID()); int index = root->objIds().indexOf(obj->getObjID());
addInstance(obj, root->child(index)); addInstance(obj, root->child(index));
} else { } else {
DataObjectTreeItem *data = new DataObjectTreeItem(obj->getName()); DataObjectTreeItem *data = new DataObjectTreeItem(obj->getName());
connect(data, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*))); connect(data, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
int index = root->nameIndex(obj->getName()); int index = root->nameIndex(obj->getName());
root->insert(index, data); root->insert(index, data);
root->insertObjId(index, obj->getObjID()); root->insertObjId(index, obj->getObjID());
UAVMetaObject *meta = obj->getMetaObject(); UAVMetaObject *meta = obj->getMetaObject();
addMetaObject(meta, data); addMetaObject(meta, data);
addInstance(obj, data); addInstance(obj, data);
} }
} }
void UAVObjectTreeModel::addMetaObject(UAVMetaObject *obj, TreeItem *parent) void UAVObjectTreeModel::addMetaObject(UAVMetaObject *obj, TreeItem *parent)
{ {
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(highlightUpdatedObject(UAVObject*))); connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(highlightUpdatedObject(UAVObject*)));
MetaObjectTreeItem *meta = new MetaObjectTreeItem(obj, tr("Meta Data")); MetaObjectTreeItem *meta = new MetaObjectTreeItem(obj, tr("Meta Data"));
connect(meta, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*))); connect(meta, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
foreach (UAVObjectField *field, obj->getFields()) { foreach (UAVObjectField *field, obj->getFields()) {
if (field->getNumElements() > 1) { if (field->getNumElements() > 1) {
addArrayField(field, meta); addArrayField(field, meta);
} else { } else {
addSingleField(0, field, meta); addSingleField(0, field, meta);
} }
} }
parent->appendChild(meta); parent->appendChild(meta);
} }
void UAVObjectTreeModel::addInstance(UAVObject *obj, TreeItem *parent) void UAVObjectTreeModel::addInstance(UAVObject *obj, TreeItem *parent)
{ {
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(highlightUpdatedObject(UAVObject*))); connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(highlightUpdatedObject(UAVObject*)));
TreeItem *item; TreeItem *item;
if (obj->isSingleInstance()) { if (obj->isSingleInstance()) {
item = parent; item = parent;
DataObjectTreeItem *p = static_cast<DataObjectTreeItem*>(parent); DataObjectTreeItem *p = static_cast<DataObjectTreeItem*>(parent);
p->setObject(obj); p->setObject(obj);
} else { } else {
QString name = tr("Instance") + " " + QString::number(obj->getInstID()); QString name = tr("Instance") + " " + QString::number(obj->getInstID());
item = new InstanceTreeItem(obj, name); item = new InstanceTreeItem(obj, name);
connect(item, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*))); connect(item, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
parent->appendChild(item); parent->appendChild(item);
} }
foreach (UAVObjectField *field, obj->getFields()) { foreach (UAVObjectField *field, obj->getFields()) {
if (field->getNumElements() > 1) { if (field->getNumElements() > 1) {
addArrayField(field, item); addArrayField(field, item);
} else { } else {
addSingleField(0, field, item); addSingleField(0, field, item);
} }
} }
} }
void UAVObjectTreeModel::addArrayField(UAVObjectField *field, TreeItem *parent) void UAVObjectTreeModel::addArrayField(UAVObjectField *field, TreeItem *parent)
{ {
TreeItem *item = new ArrayFieldTreeItem(field->getName()); TreeItem *item = new ArrayFieldTreeItem(field->getName());
connect(item, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*))); connect(item, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
for (uint i = 0; i < field->getNumElements(); ++i) { for (uint i = 0; i < field->getNumElements(); ++i) {
addSingleField(i, field, item); addSingleField(i, field, item);
} }
parent->appendChild(item); parent->appendChild(item);
} }
void UAVObjectTreeModel::addSingleField(int index, UAVObjectField *field, TreeItem *parent) void UAVObjectTreeModel::addSingleField(int index, UAVObjectField *field, TreeItem *parent)
{ {
QList<QVariant> data; QList<QVariant> data;
if (field->getNumElements() == 1) if (field->getNumElements() == 1)
data.append(field->getName()); data.append(field->getName());
else else
data.append( QString("[%1]").arg((field->getElementNames())[index]) ); data.append( QString("[%1]").arg((field->getElementNames())[index]) );
FieldTreeItem *item; FieldTreeItem *item;
UAVObjectField::FieldType type = field->getType(); UAVObjectField::FieldType type = field->getType();
switch (type) { switch (type) {
case UAVObjectField::ENUM: { case UAVObjectField::ENUM: {
QStringList options = field->getOptions(); QStringList options = field->getOptions();
QVariant value = field->getValue(); QVariant value = field->getValue();
data.append( options.indexOf(value.toString()) ); data.append( options.indexOf(value.toString()) );
data.append(field->getUnits()); data.append(field->getUnits());
item = new EnumFieldTreeItem(field, index, data); item = new EnumFieldTreeItem(field, index, data);
break; break;
} }
case UAVObjectField::INT8: case UAVObjectField::INT8:
case UAVObjectField::INT16: case UAVObjectField::INT16:
case UAVObjectField::INT32: case UAVObjectField::INT32:
case UAVObjectField::UINT8: case UAVObjectField::UINT8:
case UAVObjectField::UINT16: case UAVObjectField::UINT16:
case UAVObjectField::UINT32: case UAVObjectField::UINT32:
data.append(field->getValue(index)); data.append(field->getValue(index));
data.append(field->getUnits()); data.append(field->getUnits());
item = new IntFieldTreeItem(field, index, data); item = new IntFieldTreeItem(field, index, data);
break; break;
case UAVObjectField::FLOAT32: case UAVObjectField::FLOAT32:
data.append(field->getValue(index)); data.append(field->getValue(index));
data.append(field->getUnits()); data.append(field->getUnits());
item = new FloatFieldTreeItem(field, index, data); item = new FloatFieldTreeItem(field, index, data);
break; break;
default: default:
Q_ASSERT(false); Q_ASSERT(false);
} }
connect(item, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*))); connect(item, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
parent->appendChild(item); parent->appendChild(item);
} }
QModelIndex UAVObjectTreeModel::index(int row, int column, const QModelIndex &parent) QModelIndex UAVObjectTreeModel::index(int row, int column, const QModelIndex &parent)
const const
{ {
if (!hasIndex(row, column, parent)) if (!hasIndex(row, column, parent))
return QModelIndex(); return QModelIndex();
TreeItem *parentItem; TreeItem *parentItem;
if (!parent.isValid()) if (!parent.isValid())
parentItem = m_rootItem; parentItem = m_rootItem;
else else
parentItem = static_cast<TreeItem*>(parent.internalPointer()); parentItem = static_cast<TreeItem*>(parent.internalPointer());
TreeItem *childItem = parentItem->child(row); TreeItem *childItem = parentItem->child(row);
if (childItem) if (childItem)
return createIndex(row, column, childItem); return createIndex(row, column, childItem);
else else
return QModelIndex(); return QModelIndex();
} }
QModelIndex UAVObjectTreeModel::index(TreeItem *item) QModelIndex UAVObjectTreeModel::index(TreeItem *item)
{ {
if (item->parent() == 0) if (item->parent() == 0)
return QModelIndex(); return QModelIndex();
QModelIndex root = index(item->parent()); QModelIndex root = index(item->parent());
for (int i = 0; i < rowCount(root); ++i) { for (int i = 0; i < rowCount(root); ++i) {
QModelIndex childIndex = index(i, 0, root); QModelIndex childIndex = index(i, 0, root);
TreeItem *child = static_cast<TreeItem*>(childIndex.internalPointer()); TreeItem *child = static_cast<TreeItem*>(childIndex.internalPointer());
if (child == item) if (child == item)
return childIndex; return childIndex;
} }
Q_ASSERT(false); Q_ASSERT(false);
return QModelIndex(); return QModelIndex();
} }
QModelIndex UAVObjectTreeModel::parent(const QModelIndex &index) const QModelIndex UAVObjectTreeModel::parent(const QModelIndex &index) const
{ {
if (!index.isValid()) if (!index.isValid())
return QModelIndex(); return QModelIndex();
TreeItem *childItem = static_cast<TreeItem*>(index.internalPointer()); TreeItem *childItem = static_cast<TreeItem*>(index.internalPointer());
TreeItem *parentItem = childItem->parent(); TreeItem *parentItem = childItem->parent();
if (parentItem == m_rootItem) if (parentItem == m_rootItem)
return QModelIndex(); return QModelIndex();
return createIndex(parentItem->row(), 0, parentItem); return createIndex(parentItem->row(), 0, parentItem);
} }
int UAVObjectTreeModel::rowCount(const QModelIndex &parent) const int UAVObjectTreeModel::rowCount(const QModelIndex &parent) const
{ {
TreeItem *parentItem; TreeItem *parentItem;
if (parent.column() > 0) if (parent.column() > 0)
return 0; return 0;
if (!parent.isValid()) if (!parent.isValid())
parentItem = m_rootItem; parentItem = m_rootItem;
else else
parentItem = static_cast<TreeItem*>(parent.internalPointer()); parentItem = static_cast<TreeItem*>(parent.internalPointer());
return parentItem->childCount(); return parentItem->childCount();
} }
int UAVObjectTreeModel::columnCount(const QModelIndex &parent) const int UAVObjectTreeModel::columnCount(const QModelIndex &parent) const
{ {
if (parent.isValid()) if (parent.isValid())
return static_cast<TreeItem*>(parent.internalPointer())->columnCount(); return static_cast<TreeItem*>(parent.internalPointer())->columnCount();
else else
return m_rootItem->columnCount(); return m_rootItem->columnCount();
} }
QVariant UAVObjectTreeModel::data(const QModelIndex &index, int role) const QVariant UAVObjectTreeModel::data(const QModelIndex &index, int role) const
{ {
if (!index.isValid()) if (!index.isValid())
return QVariant(); return QVariant();
if (index.column() == TreeItem::dataColumn && role == Qt::EditRole) { if (index.column() == TreeItem::dataColumn && role == Qt::EditRole) {
TreeItem *item = static_cast<TreeItem*>(index.internalPointer()); TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
return item->data(index.column()); return item->data(index.column());
} }
// if (role == Qt::DecorationRole) // if (role == Qt::DecorationRole)
// return QIcon(":/core/images/openpilot_logo_128.png"); // return QIcon(":/core/images/openpilot_logo_128.png");
TreeItem *item = static_cast<TreeItem*>(index.internalPointer()); TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
if (index.column() == 0 && role == Qt::BackgroundRole) { if (index.column() == 0 && role == Qt::BackgroundRole) {
ObjectTreeItem *objItem = dynamic_cast<ObjectTreeItem*>(item); ObjectTreeItem *objItem = dynamic_cast<ObjectTreeItem*>(item);
if (objItem && objItem->highlighted()) if (objItem && objItem->highlighted())
return QVariant(m_recentlyUpdatedColor); return QVariant(m_recentlyUpdatedColor);
} }
if (index.column() == TreeItem::dataColumn && role == Qt::BackgroundRole) { if (index.column() == TreeItem::dataColumn && role == Qt::BackgroundRole) {
FieldTreeItem *fieldItem = dynamic_cast<FieldTreeItem*>(item); FieldTreeItem *fieldItem = dynamic_cast<FieldTreeItem*>(item);
if (fieldItem && fieldItem->highlighted()) if (fieldItem && fieldItem->highlighted())
return QVariant(m_recentlyUpdatedColor); return QVariant(m_recentlyUpdatedColor);
if (fieldItem && fieldItem->changed()) if (fieldItem && fieldItem->changed())
return QVariant(m_manuallyChangedColor); return QVariant(m_manuallyChangedColor);
} }
if (role != Qt::DisplayRole) if (role != Qt::DisplayRole)
return QVariant(); return QVariant();
if (index.column() == TreeItem::dataColumn) { if (index.column() == TreeItem::dataColumn) {
EnumFieldTreeItem *fieldItem = dynamic_cast<EnumFieldTreeItem*>(item); EnumFieldTreeItem *fieldItem = dynamic_cast<EnumFieldTreeItem*>(item);
if (fieldItem) { if (fieldItem) {
int enumIndex = fieldItem->data(index.column()).toInt(); int enumIndex = fieldItem->data(index.column()).toInt();
return fieldItem->enumOptions(enumIndex); return fieldItem->enumOptions(enumIndex);
} }
} }
return item->data(index.column()); return item->data(index.column());
} }
bool UAVObjectTreeModel::setData(const QModelIndex &index, const QVariant & value, int role) bool UAVObjectTreeModel::setData(const QModelIndex &index, const QVariant & value, int role)
{ {
TreeItem *item = static_cast<TreeItem*>(index.internalPointer()); TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
item->setData(value, index.column()); item->setData(value, index.column());
return true; return true;
} }
Qt::ItemFlags UAVObjectTreeModel::flags(const QModelIndex &index) const Qt::ItemFlags UAVObjectTreeModel::flags(const QModelIndex &index) const
{ {
if (!index.isValid()) if (!index.isValid())
return 0; return 0;
if (index.column() == TreeItem::dataColumn) { if (index.column() == TreeItem::dataColumn) {
TreeItem *item = static_cast<TreeItem*>(index.internalPointer()); TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
if (item->isEditable()) if (item->isEditable())
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable; return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
} }
return Qt::ItemIsEnabled | Qt::ItemIsSelectable; return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
} }
QVariant UAVObjectTreeModel::headerData(int section, Qt::Orientation orientation, QVariant UAVObjectTreeModel::headerData(int section, Qt::Orientation orientation,
int role) const int role) const
{ {
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
return m_rootItem->data(section); return m_rootItem->data(section);
return QVariant(); return QVariant();
} }
void UAVObjectTreeModel::highlightUpdatedObject(UAVObject *obj) void UAVObjectTreeModel::highlightUpdatedObject(UAVObject *obj)
{ {
Q_ASSERT(obj); Q_ASSERT(obj);
ObjectTreeItem *item = findObjectTreeItem(obj); ObjectTreeItem *item = findObjectTreeItem(obj);
Q_ASSERT(item); Q_ASSERT(item);
item->setHighlight(true); item->setHighlight(true);
item->update(); item->update();
QModelIndex itemIndex = index(item); QModelIndex itemIndex = index(item);
Q_ASSERT(itemIndex != QModelIndex()); Q_ASSERT(itemIndex != QModelIndex());
emit dataChanged(itemIndex, itemIndex); emit dataChanged(itemIndex, itemIndex);
} }
ObjectTreeItem *UAVObjectTreeModel::findObjectTreeItem(UAVObject *object) ObjectTreeItem *UAVObjectTreeModel::findObjectTreeItem(UAVObject *object)
{ {
UAVDataObject *dobj = qobject_cast<UAVDataObject*>(object); UAVDataObject *dobj = qobject_cast<UAVDataObject*>(object);
UAVMetaObject *mobj = qobject_cast<UAVMetaObject*>(object); UAVMetaObject *mobj = qobject_cast<UAVMetaObject*>(object);
Q_ASSERT(dobj || mobj); Q_ASSERT(dobj || mobj);
if (dobj) { if (dobj) {
return findDataObjectTreeItem(dobj); return findDataObjectTreeItem(dobj);
} else { } else {
dobj = qobject_cast<UAVDataObject*>(mobj->getParentObject()); dobj = qobject_cast<UAVDataObject*>(mobj->getParentObject());
Q_ASSERT(dobj); Q_ASSERT(dobj);
ObjectTreeItem *dItem = findDataObjectTreeItem(dobj); ObjectTreeItem *dItem = findDataObjectTreeItem(dobj);
Q_ASSERT(dItem); Q_ASSERT(dItem);
Q_ASSERT(dItem->object()); Q_ASSERT(dItem->object());
if (!dItem->object()->isSingleInstance()) if (!dItem->object()->isSingleInstance())
dItem = dynamic_cast<ObjectTreeItem*>(dItem->parent()); dItem = dynamic_cast<ObjectTreeItem*>(dItem->parent());
foreach (TreeItem *child, dItem->treeChildren()) { foreach (TreeItem *child, dItem->treeChildren()) {
MetaObjectTreeItem *mItem = dynamic_cast<MetaObjectTreeItem*>(child); MetaObjectTreeItem *mItem = dynamic_cast<MetaObjectTreeItem*>(child);
if (mItem && mItem->object()) { if (mItem && mItem->object()) {
Q_ASSERT(mItem->object() == mobj); Q_ASSERT(mItem->object() == mobj);
return mItem; return mItem;
} }
} }
} }
return 0; return 0;
} }
DataObjectTreeItem *UAVObjectTreeModel::findDataObjectTreeItem(UAVDataObject *object) DataObjectTreeItem *UAVObjectTreeModel::findDataObjectTreeItem(UAVDataObject *object)
{ {
Q_ASSERT(object); Q_ASSERT(object);
TopTreeItem *root = object->isSettings() ? m_settingsTree : m_nonSettingsTree; TopTreeItem *root = object->isSettings() ? m_settingsTree : m_nonSettingsTree;
foreach (TreeItem *child, root->treeChildren()) { foreach (TreeItem *child, root->treeChildren()) {
DataObjectTreeItem *dItem = dynamic_cast<DataObjectTreeItem*>(child); DataObjectTreeItem *dItem = dynamic_cast<DataObjectTreeItem*>(child);
if (dItem && dItem->object() && dItem->object()->isSingleInstance()) { if (dItem && dItem->object() && dItem->object()->isSingleInstance()) {
if(dItem->object() == object) { if(dItem->object() == object) {
return dItem; return dItem;
} }
} else { } else {
foreach (TreeItem *c, dItem->treeChildren()) { foreach (TreeItem *c, dItem->treeChildren()) {
DataObjectTreeItem *d = dynamic_cast<DataObjectTreeItem*>(c); DataObjectTreeItem *d = dynamic_cast<DataObjectTreeItem*>(c);
if (d && d->object() == object) if (d && d->object() == object)
return d; return d;
} }
} }
} }
return 0; return 0;
} }
void UAVObjectTreeModel::updateHighlight(TreeItem *item) void UAVObjectTreeModel::updateHighlight(TreeItem *item)
{ {
QModelIndex itemIndex = index(item); QModelIndex itemIndex = index(item);
Q_ASSERT(itemIndex != QModelIndex()); Q_ASSERT(itemIndex != QModelIndex());
emit dataChanged(itemIndex, itemIndex.sibling(itemIndex.row(), TreeItem::dataColumn)); emit dataChanged(itemIndex, itemIndex.sibling(itemIndex.row(), TreeItem::dataColumn));
} }

View File

@ -1,102 +1,102 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavobjecttreemodel.h * @file uavobjecttreemodel.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser * @defgroup uavobjectbrowserplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef UAVOBJECTTREEMODEL_H #ifndef UAVOBJECTTREEMODEL_H
#define UAVOBJECTTREEMODEL_H #define UAVOBJECTTREEMODEL_H
#include "treeitem.h" #include "treeitem.h"
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <QtCore/QMap> #include <QtCore/QMap>
#include <QtGui/QColor> #include <QtGui/QColor>
class TopTreeItem; class TopTreeItem;
class ObjectTreeItem; class ObjectTreeItem;
class DataObjectTreeItem; class DataObjectTreeItem;
class UAVObject; class UAVObject;
class UAVDataObject; class UAVDataObject;
class UAVMetaObject; class UAVMetaObject;
class UAVObjectField; class UAVObjectField;
class UAVObjectManager; class UAVObjectManager;
class QSignalMapper; class QSignalMapper;
class QTimer; class QTimer;
class UAVObjectTreeModel : public QAbstractItemModel class UAVObjectTreeModel : public QAbstractItemModel
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit UAVObjectTreeModel(QObject *parent = 0); explicit UAVObjectTreeModel(QObject *parent = 0);
~UAVObjectTreeModel(); ~UAVObjectTreeModel();
QVariant data(const QModelIndex &index, int role) const; QVariant data(const QModelIndex &index, int role) const;
bool setData(const QModelIndex &index, const QVariant & value, int role); bool setData(const QModelIndex &index, const QVariant & value, int role);
Qt::ItemFlags flags(const QModelIndex &index) const; Qt::ItemFlags flags(const QModelIndex &index) const;
QVariant headerData(int section, Qt::Orientation orientation, QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const; int role = Qt::DisplayRole) const;
QModelIndex index(int row, int column, QModelIndex index(int row, int column,
const QModelIndex &parent = QModelIndex()) const; const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &index) const; QModelIndex parent(const QModelIndex &index) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const; int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const;
void setRecentlyUpdatedColor(QColor color) { m_recentlyUpdatedColor = color; } void setRecentlyUpdatedColor(QColor color) { m_recentlyUpdatedColor = color; }
void setManuallyChangedColor(QColor color) { m_manuallyChangedColor = color; } void setManuallyChangedColor(QColor color) { m_manuallyChangedColor = color; }
void setRecentlyUpdatedTimeout(int timeout) { void setRecentlyUpdatedTimeout(int timeout) {
m_recentlyUpdatedTimeout = timeout; m_recentlyUpdatedTimeout = timeout;
TreeItem::setHighlightTime(timeout); TreeItem::setHighlightTime(timeout);
} }
signals: signals:
public slots: public slots:
void newObject(UAVObject *obj); void newObject(UAVObject *obj);
private slots: private slots:
void highlightUpdatedObject(UAVObject *obj); void highlightUpdatedObject(UAVObject *obj);
void updateHighlight(TreeItem*); void updateHighlight(TreeItem*);
private: private:
QModelIndex index(TreeItem *item); QModelIndex index(TreeItem *item);
void addDataObject(UAVDataObject *obj); void addDataObject(UAVDataObject *obj);
void addMetaObject(UAVMetaObject *obj, TreeItem *parent); void addMetaObject(UAVMetaObject *obj, TreeItem *parent);
void addArrayField(UAVObjectField *field, TreeItem *parent); void addArrayField(UAVObjectField *field, TreeItem *parent);
void addSingleField(int index, UAVObjectField *field, TreeItem *parent); void addSingleField(int index, UAVObjectField *field, TreeItem *parent);
void addInstance(UAVObject *obj, TreeItem *parent); void addInstance(UAVObject *obj, TreeItem *parent);
QString updateMode(quint8 updateMode); QString updateMode(quint8 updateMode);
void setupModelData(UAVObjectManager *objManager); void setupModelData(UAVObjectManager *objManager);
ObjectTreeItem *findObjectTreeItem(UAVObject *obj); ObjectTreeItem *findObjectTreeItem(UAVObject *obj);
DataObjectTreeItem *findDataObjectTreeItem(UAVDataObject *obj); DataObjectTreeItem *findDataObjectTreeItem(UAVDataObject *obj);
TreeItem *m_rootItem; TreeItem *m_rootItem;
TopTreeItem *m_settingsTree; TopTreeItem *m_settingsTree;
TopTreeItem *m_nonSettingsTree; TopTreeItem *m_nonSettingsTree;
int m_recentlyUpdatedTimeout; int m_recentlyUpdatedTimeout;
QColor m_recentlyUpdatedColor; QColor m_recentlyUpdatedColor;
QColor m_manuallyChangedColor; QColor m_manuallyChangedColor;
}; };
#endif // UAVOBJECTTREEMODEL_H #endif // UAVOBJECTTREEMODEL_H

View File

@ -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> <vendor>The OpenPilot Project</vendor>
<copyright>(C) 2010 OpenPilot Project</copyright> <copyright>(C) 2010 OpenPilot Project</copyright>
<license>The GNU Public License (GPL) Version 3</license> <license>The GNU Public License (GPL) Version 3</license>

View File

@ -1,100 +1,99 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavdataobject.cpp * @file uavdataobject.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. * @brief
* @brief * @see The GNU Public License (GPL) Version 3
* @see The GNU Public License (GPL) Version 3 * @defgroup uavobjectsplugin
* @defgroup uavobjects_plugin * @{
* @{ *
* *****************************************************************************/
*****************************************************************************/ /*
/* * This program is free software; you can redistribute it and/or modify
* 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
* it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or
* the Free Software Foundation; either version 3 of the License, or * (at your option) any later version.
* (at your option) any later version. *
* * This program is distributed in the hope that it will be useful, but
* This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details.
* for more details. *
* * You should have received a copy of the GNU General Public License along
* 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.,
* with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
*/ #include "uavdataobject.h"
#include "uavdataobject.h"
/**
/** * Constructor
* Constructor */
*/ UAVDataObject::UAVDataObject(quint32 objID, bool isSingleInst, bool isSet,const QString& name):
UAVDataObject::UAVDataObject(quint32 objID, bool isSingleInst, bool isSet,const QString& name): UAVObject(objID, isSingleInst, name)
UAVObject(objID, isSingleInst, name) {
{ mobj = NULL;
mobj = NULL; this->isSet = isSet;
this->isSet = isSet; }
}
/**
/** * Initialize instance ID and assign a metaobject
* Initialize instance ID and assign a metaobject */
*/ void UAVDataObject::initialize(quint32 instID, UAVMetaObject* mobj)
void UAVDataObject::initialize(quint32 instID, UAVMetaObject* mobj) {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); this->mobj = mobj;
this->mobj = mobj; UAVObject::initialize(instID);
UAVObject::initialize(instID); }
}
/**
/** * Assign a metaobject
* Assign a metaobject */
*/ void UAVDataObject::initialize(UAVMetaObject* mobj)
void UAVDataObject::initialize(UAVMetaObject* mobj) {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); this->mobj = mobj;
this->mobj = mobj; }
}
/**
/** * Returns true if this is a data object holding module settings
* Returns true if this is a data object holding module settings */
*/ bool UAVDataObject::isSettings()
bool UAVDataObject::isSettings() {
{ return isSet;
return isSet; }
}
/**
/** * Set the object's metadata
* Set the object's metadata */
*/ void UAVDataObject::setMetadata(const Metadata& mdata)
void UAVDataObject::setMetadata(const Metadata& mdata) {
{ if ( mobj!=NULL )
if ( mobj!=NULL ) {
{ mobj->setData(mdata);
mobj->setData(mdata); }
} }
}
/**
/** * Get the object's metadata
* Get the object's metadata */
*/ UAVObject::Metadata UAVDataObject::getMetadata(void)
UAVObject::Metadata UAVDataObject::getMetadata(void) {
{ if ( mobj!=NULL)
if ( mobj!=NULL) {
{ return mobj->getData();
return mobj->getData(); }
} else
else {
{ return getDefaultMetadata();
return getDefaultMetadata(); }
} }
}
/**
/** * Get the metaobject
* Get the metaobject */
*/ UAVMetaObject* UAVDataObject::getMetaObject()
UAVMetaObject* UAVDataObject::getMetaObject() {
{ return mobj;
return mobj; }
}

View File

@ -1,57 +1,56 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavdataobject.h * @file uavdataobject.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. * @brief
* @brief * @see The GNU Public License (GPL) Version 3
* @see The GNU Public License (GPL) Version 3 * @defgroup uavobjectsplugin
* @defgroup uavobjects_plugin * @{
* @{ *
* *****************************************************************************/
*****************************************************************************/ /*
/* * This program is free software; you can redistribute it and/or modify
* 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
* it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or
* the Free Software Foundation; either version 3 of the License, or * (at your option) any later version.
* (at your option) any later version. *
* * This program is distributed in the hope that it will be useful, but
* This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details.
* for more details. *
* * You should have received a copy of the GNU General Public License along
* 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.,
* with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
*/ #ifndef UAVDATAOBJECT_H
#ifndef UAVDATAOBJECT_H #define UAVDATAOBJECT_H
#define UAVDATAOBJECT_H
#include "uavobjects_global.h"
#include "uavobjects_global.h" #include "uavobject.h"
#include "uavobject.h" #include "uavobjectfield.h"
#include "uavobjectfield.h" #include "uavmetaobject.h"
#include "uavmetaobject.h" #include <QList>
#include <QList>
class UAVOBJECTS_EXPORT UAVDataObject: public UAVObject
class UAVOBJECTS_EXPORT UAVDataObject: public UAVObject {
{ Q_OBJECT
Q_OBJECT
public:
public: UAVDataObject(quint32 objID, bool isSingleInst, bool isSet, const QString& name);
UAVDataObject(quint32 objID, bool isSingleInst, bool isSet, const QString& name); void initialize(quint32 instID, UAVMetaObject* mobj);
void initialize(quint32 instID, UAVMetaObject* mobj); void initialize(UAVMetaObject* mobj);
void initialize(UAVMetaObject* mobj); bool isSettings();
bool isSettings(); void setMetadata(const Metadata& mdata);
void setMetadata(const Metadata& mdata); Metadata getMetadata();
Metadata getMetadata(); UAVMetaObject* getMetaObject();
UAVMetaObject* getMetaObject(); virtual UAVDataObject* clone(quint32 instID = 0) = 0;
virtual UAVDataObject* clone(quint32 instID = 0) = 0;
private:
private: UAVMetaObject* mobj;
UAVMetaObject* mobj; bool isSet;
bool isSet;
};
};
#endif // UAVDATAOBJECT_H
#endif // UAVDATAOBJECT_H

View File

@ -1,127 +1,126 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavmetaobject.cpp * @file uavmetaobject.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. * @brief
* @brief * @see The GNU Public License (GPL) Version 3
* @see The GNU Public License (GPL) Version 3 * @defgroup uavobjectsplugin
* @defgroup uavobjects_plugin * @{
* @{ *
* *****************************************************************************/
*****************************************************************************/ /*
/* * This program is free software; you can redistribute it and/or modify
* 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
* it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or
* the Free Software Foundation; either version 3 of the License, or * (at your option) any later version.
* (at your option) any later version. *
* * This program is distributed in the hope that it will be useful, but
* This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details.
* for more details. *
* * You should have received a copy of the GNU General Public License along
* 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.,
* with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
*/ #include "uavmetaobject.h"
#include "uavmetaobject.h" #include "uavobjectfield.h"
#include "uavobjectfield.h"
/**
/** * Constructor
* Constructor */
*/ UAVMetaObject::UAVMetaObject(quint32 objID, const QString& name, UAVObject* parent):
UAVMetaObject::UAVMetaObject(quint32 objID, const QString& name, UAVObject* parent): UAVObject(objID, true, name)
UAVObject(objID, true, name) {
{ this->parent = parent;
this->parent = parent; // Setup default metadata of metaobject (can not be changed)
// Setup default metadata of metaobject (can not be changed) ownMetadata.flightAccess = ACCESS_READWRITE;
ownMetadata.flightAccess = ACCESS_READWRITE; ownMetadata.gcsAccess = ACCESS_READWRITE;
ownMetadata.gcsAccess = ACCESS_READWRITE; ownMetadata.flightTelemetryAcked = 1;
ownMetadata.flightTelemetryAcked = 1; ownMetadata.flightTelemetryUpdateMode = UPDATEMODE_ONCHANGE;
ownMetadata.flightTelemetryUpdateMode = UPDATEMODE_ONCHANGE; ownMetadata.flightTelemetryUpdatePeriod = 0;
ownMetadata.flightTelemetryUpdatePeriod = 0; ownMetadata.gcsTelemetryAcked = 1;
ownMetadata.gcsTelemetryAcked = 1; ownMetadata.gcsTelemetryUpdateMode = UPDATEMODE_ONCHANGE;
ownMetadata.gcsTelemetryUpdateMode = UPDATEMODE_ONCHANGE; ownMetadata.gcsTelemetryUpdatePeriod = 0;
ownMetadata.gcsTelemetryUpdatePeriod = 0; ownMetadata.loggingUpdateMode = UPDATEMODE_ONCHANGE;
ownMetadata.loggingUpdateMode = UPDATEMODE_ONCHANGE; ownMetadata.loggingUpdatePeriod = 0;
ownMetadata.loggingUpdatePeriod = 0; // Setup fields
// Setup fields QStringList boolEnum;
QStringList boolEnum; boolEnum << tr("False") << tr("True");
boolEnum << tr("False") << tr("True"); QStringList updateModeEnum;
QStringList updateModeEnum; updateModeEnum << tr("Periodic") << tr("On Change") << tr("Manual") << tr("Never");
updateModeEnum << tr("Periodic") << tr("On Change") << tr("Manual") << tr("Never"); QStringList accessModeEnum;
QStringList accessModeEnum; accessModeEnum << tr("Read/Write") << tr("Read Only");
accessModeEnum << tr("Read/Write") << tr("Read Only"); QList<UAVObjectField*> fields;
QList<UAVObjectField*> fields; fields.append( new UAVObjectField(tr("Flight Access Mode"), tr(""), UAVObjectField::ENUM, 1, accessModeEnum) );
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("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 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 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("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 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 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("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 Mode"), tr(""), UAVObjectField::ENUM, 1, updateModeEnum) ); fields.append( new UAVObjectField(tr("Logging Update Period"), tr(""), UAVObjectField::UINT32, 1, QStringList()) );
fields.append( new UAVObjectField(tr("Logging Update Period"), tr(""), UAVObjectField::UINT32, 1, QStringList()) ); // Initialize parent
// Initialize parent UAVObject::initialize(0);
UAVObject::initialize(0); UAVObject::initializeFields(fields, (quint8*)&parentMetadata, sizeof(Metadata));
UAVObject::initializeFields(fields, (quint8*)&parentMetadata, sizeof(Metadata)); // Setup metadata of parent
// Setup metadata of parent parentMetadata = parent->getDefaultMetadata();
parentMetadata = parent->getDefaultMetadata(); }
}
/**
/** * Get the parent object
* Get the parent object */
*/ UAVObject* UAVMetaObject::getParentObject()
UAVObject* UAVMetaObject::getParentObject() {
{ return parent;
return parent; }
}
/**
/** * Set the metadata of the metaobject, this function will
* Set the metadata of the metaobject, this function will * do nothing since metaobjects have read-only metadata.
* do nothing since metaobjects have read-only metadata. */
*/ void UAVMetaObject::setMetadata(const Metadata& mdata)
void UAVMetaObject::setMetadata(const Metadata& mdata) {
{ return; // can not update metaobject's metadata
return; // can not update metaobject's metadata }
}
/**
/** * Get the metadata of the metaobject
* Get the metadata of the metaobject */
*/ UAVObject::Metadata UAVMetaObject::getMetadata()
UAVObject::Metadata UAVMetaObject::getMetadata() {
{ return ownMetadata;
return ownMetadata; }
}
/**
/** * Get the default metadata
* Get the default metadata */
*/ UAVObject::Metadata UAVMetaObject::getDefaultMetadata()
UAVObject::Metadata UAVMetaObject::getDefaultMetadata() {
{ return ownMetadata;
return ownMetadata; }
}
/**
/** * Set the metadata held by the metaobject
* Set the metadata held by the metaobject */
*/ void UAVMetaObject::setData(const Metadata& mdata)
void UAVMetaObject::setData(const Metadata& mdata) {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); parentMetadata = mdata;
parentMetadata = mdata; emit objectUpdatedAuto(this); // trigger object updated event
emit objectUpdatedAuto(this); // trigger object updated event emit objectUpdated(this);
emit objectUpdated(this); }
}
/**
/** * Get the metadata held by the metaobject
* Get the metadata held by the metaobject */
*/ UAVObject::Metadata UAVMetaObject::getData()
UAVObject::Metadata UAVMetaObject::getData() {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); return parentMetadata;
return parentMetadata; }
}

View File

@ -1,54 +1,53 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavmetaobject.h * @file uavmetaobject.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. * @brief
* @brief * @see The GNU Public License (GPL) Version 3
* @see The GNU Public License (GPL) Version 3 * @defgroup uavobjectsplugin
* @defgroup uavobjects_plugin * @{
* @{ *
* *****************************************************************************/
*****************************************************************************/ /*
/* * This program is free software; you can redistribute it and/or modify
* 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
* it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or
* the Free Software Foundation; either version 3 of the License, or * (at your option) any later version.
* (at your option) any later version. *
* * This program is distributed in the hope that it will be useful, but
* This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details.
* for more details. *
* * You should have received a copy of the GNU General Public License along
* 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.,
* with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
*/ #ifndef UAVMETAOBJECT_H
#ifndef UAVMETAOBJECT_H #define UAVMETAOBJECT_H
#define UAVMETAOBJECT_H
#include "uavobjects_global.h"
#include "uavobjects_global.h" #include "uavobject.h"
#include "uavobject.h"
class UAVOBJECTS_EXPORT UAVMetaObject: public UAVObject
class UAVOBJECTS_EXPORT UAVMetaObject: public UAVObject {
{ Q_OBJECT
Q_OBJECT
public:
public: UAVMetaObject(quint32 objID, const QString& name, UAVObject* parent);
UAVMetaObject(quint32 objID, const QString& name, UAVObject* parent); UAVObject* getParentObject();
UAVObject* getParentObject(); void setMetadata(const Metadata& mdata);
void setMetadata(const Metadata& mdata); Metadata getMetadata();
Metadata getMetadata(); Metadata getDefaultMetadata();
Metadata getDefaultMetadata(); void setData(const Metadata& mdata);
void setData(const Metadata& mdata); Metadata getData();
Metadata getData();
private:
private: UAVObject* parent;
UAVObject* parent; Metadata ownMetadata;
Metadata ownMetadata; Metadata parentMetadata;
Metadata parentMetadata;
};
};
#endif // UAVMETAOBJECT_H
#endif // UAVMETAOBJECT_H

View File

@ -1,438 +1,437 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavobject.cpp * @file uavobject.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. * @brief
* @brief * @see The GNU Public License (GPL) Version 3
* @see The GNU Public License (GPL) Version 3 * @defgroup uavobjectsplugin
* @defgroup uavobjects_plugin * @{
* @{ *
* *****************************************************************************/
*****************************************************************************/ /*
/* * This program is free software; you can redistribute it and/or modify
* 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
* it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or
* the Free Software Foundation; either version 3 of the License, or * (at your option) any later version.
* (at your option) any later version. *
* * This program is distributed in the hope that it will be useful, but
* This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details.
* for more details. *
* * You should have received a copy of the GNU General Public License along
* 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.,
* with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
*/ #include "uavobject.h"
#include "uavobject.h" #include <QtEndian>
#include <QtEndian>
/**
/** * Constructor
* Constructor * @param objID The object ID
* @param objID The object ID * @param isSingleInst True if this object can only have a single instance
* @param isSingleInst True if this object can only have a single instance * @param name Object name
* @param name Object name */
*/ UAVObject::UAVObject(quint32 objID, bool isSingleInst, const QString& name)
UAVObject::UAVObject(quint32 objID, bool isSingleInst, const QString& name) {
{ this->objID = objID;
this->objID = objID; this->instID = 0;
this->instID = 0; this->isSingleInst = isSingleInst;
this->isSingleInst = isSingleInst; this->name = name;
this->name = name; this->mutex = new QMutex(QMutex::Recursive);
this->mutex = new QMutex(QMutex::Recursive); }
}
/**
/** * Initialize object with its instance ID
* Initialize object with its instance ID */
*/ void UAVObject::initialize(quint32 instID)
void UAVObject::initialize(quint32 instID) {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); this->instID = instID;
this->instID = instID; }
}
/**
/** * Initialize objects' data fields
* Initialize objects' data fields * @param fields List of fields held by the object
* @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 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)
* @param numBytes Number of bytes in the object (total, including all fields) */
*/ void UAVObject::initializeFields(QList<UAVObjectField*>& fields, quint8* data, quint32 numBytes)
void UAVObject::initializeFields(QList<UAVObjectField*>& fields, quint8* data, quint32 numBytes) {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); this->numBytes = numBytes;
this->numBytes = numBytes; this->data = data;
this->data = data; this->fields = fields;
this->fields = fields; // Initialize fields
// Initialize fields quint32 offset = 0;
quint32 offset = 0; for (int n = 0; n < fields.length(); ++n)
for (int n = 0; n < fields.length(); ++n) {
{ fields[n]->initialize(data, offset, this);
fields[n]->initialize(data, offset, this); offset += fields[n]->getNumBytes();
offset += fields[n]->getNumBytes(); connect(fields[n], SIGNAL(fieldUpdated(UAVObjectField*)), this, SLOT(fieldUpdated(UAVObjectField*)));
connect(fields[n], SIGNAL(fieldUpdated(UAVObjectField*)), this, SLOT(fieldUpdated(UAVObjectField*))); }
} }
}
/**
/** * Called from the fields each time they are updated
* Called from the fields each time they are updated */
*/ void UAVObject::fieldUpdated(UAVObjectField* field)
void UAVObject::fieldUpdated(UAVObjectField* field) {
{ // emit objectUpdatedAuto(this); // trigger object updated event
// emit objectUpdatedAuto(this); // trigger object updated event // emit objectUpdated(this);
// emit objectUpdated(this); }
}
/**
/** * Get the object ID
* Get the object ID */
*/ quint32 UAVObject::getObjID()
quint32 UAVObject::getObjID() {
{ return objID;
return objID; }
}
/**
/** * Get the instance ID
* Get the instance ID */
*/ quint32 UAVObject::getInstID()
quint32 UAVObject::getInstID() {
{ return instID;
return instID; }
}
/**
/** * Returns true if this is a single instance object
* Returns true if this is a single instance object */
*/ bool UAVObject::isSingleInstance()
bool UAVObject::isSingleInstance() {
{ return isSingleInst;
return isSingleInst; }
}
/**
/** * Get the name of the object
* Get the name of the object */
*/ QString UAVObject::getName()
QString UAVObject::getName() {
{ return name;
return name; }
}
/**
/** * Get the total number of bytes of the object's data
* Get the total number of bytes of the object's data */
*/ quint32 UAVObject::getNumBytes()
quint32 UAVObject::getNumBytes() {
{ return numBytes;
return numBytes; }
}
/**
/** * Request that this object is updated with the latest values from the autopilot
* Request that this object is updated with the latest values from the autopilot */
*/ void UAVObject::requestUpdate()
void UAVObject::requestUpdate() {
{ emit updateRequested(this);
emit updateRequested(this); }
}
/**
/** * Signal that the object has been updated
* Signal that the object has been updated */
*/ void UAVObject::updated()
void UAVObject::updated() {
{ emit objectUpdatedManual(this);
emit objectUpdatedManual(this); emit objectUpdated(this);
emit objectUpdated(this); }
}
/**
/** * Lock mutex of this object
* Lock mutex of this object */
*/ void UAVObject::lock()
void UAVObject::lock() {
{ mutex->lock();
mutex->lock(); }
}
/**
/** * Lock mutex of this object
* Lock mutex of this object */
*/ void UAVObject::lock(int timeoutMs)
void UAVObject::lock(int timeoutMs) {
{ mutex->tryLock(timeoutMs);
mutex->tryLock(timeoutMs); }
}
/**
/** * Unlock mutex of this object
* Unlock mutex of this object */
*/ void UAVObject::unlock()
void UAVObject::unlock() {
{ mutex->unlock();
mutex->unlock(); }
}
/**
/** * Get object's mutex
* Get object's mutex */
*/ QMutex* UAVObject::getMutex()
QMutex* UAVObject::getMutex() {
{ return mutex;
return mutex; }
}
/**
/** * Get the number of fields held by this object
* Get the number of fields held by this object */
*/ qint32 UAVObject::getNumFields()
qint32 UAVObject::getNumFields() {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); return fields.count();
return fields.count(); }
}
/**
/** * Get the object's fields
* Get the object's fields */
*/ QList<UAVObjectField*> UAVObject::getFields()
QList<UAVObjectField*> UAVObject::getFields() {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); return fields;
return fields; }
}
/**
/** * Get a specific field
* Get a specific field * @returns The field or NULL if not found
* @returns The field or NULL if not found */
*/ UAVObjectField* UAVObject::getField(QString& name)
UAVObjectField* UAVObject::getField(QString& name) {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); // Look for field
// Look for field for (int n = 0; n < fields.length(); ++n)
for (int n = 0; n < fields.length(); ++n) {
{ if (name.compare(fields[n]->getName()) == 0)
if (name.compare(fields[n]->getName()) == 0) {
{ return fields[n];
return fields[n]; }
} }
} // If this point is reached then the field was not found
// If this point is reached then the field was not found return NULL;
return NULL; }
}
/**
/** * Pack the object data into a byte array
* Pack the object data into a byte array * @returns The number of bytes copied
* @returns The number of bytes copied */
*/ qint32 UAVObject::pack(quint8* dataOut)
qint32 UAVObject::pack(quint8* dataOut) {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); qint32 offset = 0;
qint32 offset = 0; for (int n = 0; n < fields.length(); ++n)
for (int n = 0; n < fields.length(); ++n) {
{ fields[n]->pack(&dataOut[offset]);
fields[n]->pack(&dataOut[offset]); offset += fields[n]->getNumBytes();
offset += fields[n]->getNumBytes(); }
} return numBytes;
return numBytes; }
}
/**
/** * Unpack the object data from a byte array
* Unpack the object data from a byte array * @returns The number of bytes copied
* @returns The number of bytes copied */
*/ qint32 UAVObject::unpack(const quint8* dataIn)
qint32 UAVObject::unpack(const quint8* dataIn) {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); qint32 offset = 0;
qint32 offset = 0; for (int n = 0; n < fields.length(); ++n)
for (int n = 0; n < fields.length(); ++n) {
{ fields[n]->unpack(&dataIn[offset]);
fields[n]->unpack(&dataIn[offset]); offset += fields[n]->getNumBytes();
offset += fields[n]->getNumBytes(); }
} emit objectUnpacked(this); // trigger object updated event
emit objectUnpacked(this); // trigger object updated event emit objectUpdated(this);
emit objectUpdated(this);
return numBytes;
return numBytes; }
}
/**
/** * Save the object data to the file.
* Save the object data to the file. * The file will be created in the current directory
* The file will be created in the current directory * and its name will be the same as the object with
* and its name will be the same as the object with * the .uavobj extension.
* the .uavobj extension. * @returns True on success, false on failure
* @returns True on success, false on failure */
*/ bool UAVObject::save()
bool UAVObject::save() {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex);
// Open file
// Open file QFile file(name + ".uavobj");
QFile file(name + ".uavobj"); if (!file.open(QFile::WriteOnly))
if (!file.open(QFile::WriteOnly)) {
{ return false;
return false; }
}
// Write object
// Write object if ( !save(file) )
if ( !save(file) ) {
{ return false;
return false; }
}
// Close file
// Close file file.close();
file.close(); return true;
return true; }
}
/**
/** * Save the object data to the file.
* Save the object data to the file. * The file is expected to be already open for writting.
* The file is expected to be already open for writting. * The data will be appended and the file will not be closed.
* The data will be appended and the file will not be closed. * @returns True on success, false on failure
* @returns True on success, false on failure */
*/ bool UAVObject::save(QFile& file)
bool UAVObject::save(QFile& file) {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); quint8 buffer[numBytes];
quint8 buffer[numBytes]; quint8 tmpId[4];
quint8 tmpId[4];
// Write the object ID
// Write the object ID qToLittleEndian<quint32>(objID, tmpId);
qToLittleEndian<quint32>(objID, tmpId); if ( file.write((const char*)tmpId, 4) == -1 )
if ( file.write((const char*)tmpId, 4) == -1 ) {
{ return false;
return false; }
}
// Write the instance ID
// Write the instance ID if (!isSingleInst)
if (!isSingleInst) {
{ qToLittleEndian<quint16>(instID, tmpId);
qToLittleEndian<quint16>(instID, tmpId); if ( file.write((const char*)tmpId, 2) == -1 )
if ( file.write((const char*)tmpId, 2) == -1 ) {
{ return false;
return false; }
} }
}
// Write the data
// Write the data pack(buffer);
pack(buffer); if ( file.write((const char*)buffer, numBytes) == -1 )
if ( file.write((const char*)buffer, numBytes) == -1 ) {
{ return false;
return false; }
}
// Done
// Done return true;
return true; }
}
/**
/** * Load the object data from a file.
* Load the object data from a file. * The file will be openned in the current directory
* The file will be openned in the current directory * and its name will be the same as the object with
* and its name will be the same as the object with * the .uavobj extension.
* the .uavobj extension. * @returns True on success, false on failure
* @returns True on success, false on failure */
*/ bool UAVObject::load()
bool UAVObject::load() {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex);
// Open file
// Open file QFile file(name + ".uavobj");
QFile file(name + ".uavobj"); if (!file.open(QFile::ReadOnly))
if (!file.open(QFile::ReadOnly)) {
{ return false;
return false; }
}
// Load object
// Load object if ( !load(file) )
if ( !load(file) ) {
{ return false;
return false; }
}
// Close file
// Close file file.close();
file.close(); return true;
return true; }
}
/**
/** * Load the object data from file.
* Load the object data from file. * The file is expected to be already open for reading.
* The file is expected to be already open for reading. * The data will be read and the file will not be closed.
* The data will be read and the file will not be closed. * @returns True on success, false on failure
* @returns True on success, false on failure */
*/ bool UAVObject::load(QFile& file)
bool UAVObject::load(QFile& file) {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); quint8 buffer[numBytes];
quint8 buffer[numBytes]; quint8 tmpId[4];
quint8 tmpId[4];
// Read the object ID
// Read the object ID if ( file.read((char*)tmpId, 4) != 4 )
if ( file.read((char*)tmpId, 4) != 4 ) {
{ return false;
return false; }
}
// Check that the IDs match
// Check that the IDs match if (qFromLittleEndian<quint32>(tmpId) != objID)
if (qFromLittleEndian<quint32>(tmpId) != objID) {
{ return false;
return false; }
}
// Read the instance ID
// Read the instance ID if ( file.read((char*)tmpId, 2) != 2 )
if ( file.read((char*)tmpId, 2) != 2 ) {
{ return false;
return false; }
}
// Check that the IDs match
// Check that the IDs match if (qFromLittleEndian<quint16>(tmpId) != instID)
if (qFromLittleEndian<quint16>(tmpId) != instID) {
{ return false;
return false; }
}
// Read and unpack the data
// Read and unpack the data if ( file.read((char*)buffer, numBytes) != numBytes )
if ( file.read((char*)buffer, numBytes) != numBytes ) {
{ return false;
return false; }
} unpack(buffer);
unpack(buffer);
// Done
// Done return true;
return true; }
}
/**
/** * Return a string with the object information
* Return a string with the object information */
*/ QString UAVObject::toString()
QString UAVObject::toString() {
{ QString sout;
QString sout; sout.append( toStringBrief() );
sout.append( toStringBrief() ); sout.append( toStringData() );
sout.append( toStringData() ); return sout;
return sout; }
}
/**
/** * Return a string with the object information (only the header)
* Return a string with the object information (only the header) */
*/ QString UAVObject::toStringBrief()
QString UAVObject::toStringBrief() {
{ QString sout;
QString sout; sout.append( QString("%1 (ID: %2, InstID: %3, NumBytes: %4, SInst: %5)\n")
sout.append( QString("%1 (ID: %2, InstID: %3, NumBytes: %4, SInst: %5)\n") .arg(getName())
.arg(getName()) .arg(getObjID())
.arg(getObjID()) .arg(getInstID())
.arg(getInstID()) .arg(getNumBytes())
.arg(getNumBytes()) .arg(isSingleInstance()) );
.arg(isSingleInstance()) ); return sout;
return sout; }
}
/**
/** * Return a string with the object information (only the data)
* Return a string with the object information (only the data) */
*/ QString UAVObject::toStringData()
QString UAVObject::toStringData() {
{ QString sout;
QString sout; sout.append("Data:\n");
sout.append("Data:\n"); for (int n = 0; n < fields.length(); ++n)
for (int n = 0; n < fields.length(); ++n) {
{ sout.append( QString("\t%1").arg(fields[n]->toString()) );
sout.append( QString("\t%1").arg(fields[n]->toString()) ); }
} return sout;
return sout; }
}
/**
/** * Emit the transactionCompleted event (used by the UAVTalk plugin)
* Emit the transactionCompleted event (used by the UAVTalk plugin) */
*/ void UAVObject::emitTransactionCompleted(bool success)
void UAVObject::emitTransactionCompleted(bool success) {
{ emit transactionCompleted(this, success);
emit transactionCompleted(this, success); }
}

View File

@ -1,139 +1,138 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavobject.h * @file uavobject.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. * @brief
* @brief * @see The GNU Public License (GPL) Version 3
* @see The GNU Public License (GPL) Version 3 * @defgroup uavobjectsplugin
* @defgroup uavobjects_plugin * @{
* @{ *
* *****************************************************************************/
*****************************************************************************/ /*
/* * This program is free software; you can redistribute it and/or modify
* 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
* it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or
* the Free Software Foundation; either version 3 of the License, or * (at your option) any later version.
* (at your option) any later version. *
* * This program is distributed in the hope that it will be useful, but
* This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details.
* for more details. *
* * You should have received a copy of the GNU General Public License along
* 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.,
* with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
*/ #ifndef UAVOBJECT_H
#ifndef UAVOBJECT_H #define UAVOBJECT_H
#define UAVOBJECT_H
#include "uavobjects_global.h"
#include "uavobjects_global.h" #include <QtGlobal>
#include <QtGlobal> #include <QObject>
#include <QObject> #include <QMutex>
#include <QMutex> #include <QMutexLocker>
#include <QMutexLocker> #include <QString>
#include <QString> #include <QList>
#include <QList> #include <QFile>
#include <QFile> #include "uavobjectfield.h"
#include "uavobjectfield.h"
class UAVObjectField;
class UAVObjectField;
class UAVOBJECTS_EXPORT UAVObject: public QObject
class UAVOBJECTS_EXPORT UAVObject: public QObject {
{ Q_OBJECT
Q_OBJECT
public:
public:
/**
/** * Object update mode
* Object update mode */
*/ typedef enum {
typedef enum { UPDATEMODE_PERIODIC = 0, /** Automatically update object at periodic intervals */
UPDATEMODE_PERIODIC = 0, /** Automatically update object at periodic intervals */ UPDATEMODE_ONCHANGE = 1, /** Only update object when its data changes */
UPDATEMODE_ONCHANGE = 1, /** Only update object when its data changes */ UPDATEMODE_MANUAL = 2, /** Manually update object, by calling the updated() function */
UPDATEMODE_MANUAL = 2, /** Manually update object, by calling the updated() function */ UPDATEMODE_NEVER = 3 /** Object is never updated */
UPDATEMODE_NEVER = 3 /** Object is never updated */ } UpdateMode;
} UpdateMode;
/**
/** * Access mode
* Access mode */
*/ typedef enum {
typedef enum { ACCESS_READWRITE = 0,
ACCESS_READWRITE = 0, ACCESS_READONLY = 1
ACCESS_READONLY = 1 } AccessMode;
} AccessMode;
/**
/** * Object metadata, each object has a meta object that holds its metadata. The metadata define
* 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)
* properties for each object and can be used by multiple modules (e.g. telemetry and logger) */
*/ typedef struct {
typedef struct { quint8 flightAccess; /** Defines the access level for the local flight transactions (readonly and readwrite) */
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 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 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) */
quint8 flightTelemetryUpdateMode; /** Update mode used by the autopilot (UpdateMode) */ qint32 flightTelemetryUpdatePeriod; /** Update period used by the autopilot (only if telemetry mode is PERIODIC) */
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 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) */
quint8 gcsTelemetryUpdateMode; /** Update mode used by the GCS (UpdateMode) */ qint32 gcsTelemetryUpdatePeriod; /** Update period used by the GCS (only if telemetry mode is PERIODIC) */
qint32 gcsTelemetryUpdatePeriod; /** Update period used by the GCS (only if telemetry mode is PERIODIC) */ quint8 loggingUpdateMode; /** Update mode used by the logging module (UpdateMode) */
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) */
qint32 loggingUpdatePeriod; /** Update period used by the logging module (only if logging mode is PERIODIC) */ } __attribute__((packed)) Metadata;
} __attribute__((packed)) Metadata;
UAVObject(quint32 objID, bool isSingleInst, const QString& name);
UAVObject(quint32 objID, bool isSingleInst, const QString& name); void initialize(quint32 instID);
void initialize(quint32 instID); quint32 getObjID();
quint32 getObjID(); quint32 getInstID();
quint32 getInstID(); bool isSingleInstance();
bool isSingleInstance(); QString getName();
QString getName(); quint32 getNumBytes();
quint32 getNumBytes(); qint32 pack(quint8* dataOut);
qint32 pack(quint8* dataOut); qint32 unpack(const quint8* dataIn);
qint32 unpack(const quint8* dataIn); bool save();
bool save(); bool save(QFile& file);
bool save(QFile& file); bool load();
bool load(); bool load(QFile& file);
bool load(QFile& file); virtual void setMetadata(const Metadata& mdata) = 0;
virtual void setMetadata(const Metadata& mdata) = 0; virtual Metadata getMetadata() = 0;
virtual Metadata getMetadata() = 0; virtual Metadata getDefaultMetadata() = 0;
virtual Metadata getDefaultMetadata() = 0; void requestUpdate();
void requestUpdate(); void updated();
void updated(); void lock();
void lock(); void lock(int timeoutMs);
void lock(int timeoutMs); void unlock();
void unlock(); QMutex* getMutex();
QMutex* getMutex(); qint32 getNumFields();
qint32 getNumFields(); QList<UAVObjectField*> getFields();
QList<UAVObjectField*> getFields(); UAVObjectField* getField(QString& name);
UAVObjectField* getField(QString& name); QString toString();
QString toString(); QString toStringBrief();
QString toStringBrief(); QString toStringData();
QString toStringData(); void emitTransactionCompleted(bool success);
void emitTransactionCompleted(bool success);
signals:
signals: void objectUpdated(UAVObject* obj);
void objectUpdated(UAVObject* obj); void objectUpdatedAuto(UAVObject* obj);
void objectUpdatedAuto(UAVObject* obj); void objectUpdatedManual(UAVObject* obj);
void objectUpdatedManual(UAVObject* obj); void objectUnpacked(UAVObject* obj);
void objectUnpacked(UAVObject* obj); void updateRequested(UAVObject* obj);
void updateRequested(UAVObject* obj); void transactionCompleted(UAVObject* obj, bool success);
void transactionCompleted(UAVObject* obj, bool success);
private slots:
private slots: void fieldUpdated(UAVObjectField* field);
void fieldUpdated(UAVObjectField* field);
protected:
protected: quint32 objID;
quint32 objID; quint32 instID;
quint32 instID; bool isSingleInst;
bool isSingleInst; QString name;
QString name; quint32 numBytes;
quint32 numBytes; QMutex* mutex;
QMutex* mutex; quint8* data;
quint8* data; QList<UAVObjectField*> fields;
QList<UAVObjectField*> fields;
void initializeFields(QList<UAVObjectField*>& fields, quint8* data, quint32 numBytes);
void initializeFields(QList<UAVObjectField*>& fields, quint8* data, quint32 numBytes); };
};
#endif // UAVOBJECT_H
#endif // UAVOBJECT_H

View File

@ -1,550 +1,549 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavobjectfield.cpp * @file uavobjectfield.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. * @brief
* @brief * @see The GNU Public License (GPL) Version 3
* @see The GNU Public License (GPL) Version 3 * @defgroup uavobjectsplugin
* @defgroup uavobjects_plugin * @{
* @{ *
* *****************************************************************************/
*****************************************************************************/ /*
/* * This program is free software; you can redistribute it and/or modify
* 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
* it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or
* the Free Software Foundation; either version 3 of the License, or * (at your option) any later version.
* (at your option) any later version. *
* * This program is distributed in the hope that it will be useful, but
* This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details.
* for more details. *
* * You should have received a copy of the GNU General Public License along
* 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.,
* with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
*/ #include "uavobjectfield.h"
#include "uavobjectfield.h" #include <QtEndian>
#include <QtEndian>
UAVObjectField::UAVObjectField(const QString& name, const QString& units, FieldType type, quint32 numElements, const QStringList& options)
UAVObjectField::UAVObjectField(const QString& name, const QString& units, FieldType type, quint32 numElements, const QStringList& options) {
{ QStringList elementNames;
QStringList elementNames; // Set element names
// Set element names for (quint32 n = 0; n < numElements; ++n)
for (quint32 n = 0; n < numElements; ++n) {
{ elementNames.append(QString("%1").arg(n));
elementNames.append(QString("%1").arg(n)); }
} // Initialize
// Initialize constructorInitialize(name, units, type, elementNames, options);
constructorInitialize(name, units, type, elementNames, options);
}
}
UAVObjectField::UAVObjectField(const QString& name, const QString& units, FieldType type, const QStringList& elementNames, const QStringList& options)
UAVObjectField::UAVObjectField(const QString& name, const QString& units, FieldType type, const QStringList& elementNames, const QStringList& options) {
{ constructorInitialize(name, units, type, elementNames, options);
constructorInitialize(name, units, type, elementNames, options); }
}
void UAVObjectField::constructorInitialize(const QString& name, const QString& units, FieldType type, const QStringList& elementNames, const QStringList& options)
void UAVObjectField::constructorInitialize(const QString& name, const QString& units, FieldType type, const QStringList& elementNames, const QStringList& options) {
{ // Copy params
// Copy params this->name = name;
this->name = name; this->units = units;
this->units = units; this->type = type;
this->type = type; this->options = options;
this->options = options; this->numElements = elementNames.length();
this->numElements = elementNames.length(); this->offset = 0;
this->offset = 0; this->data = NULL;
this->data = NULL; this->obj = NULL;
this->obj = NULL; this->elementNames = elementNames;
this->elementNames = elementNames; // Set field size
// Set field size switch (type)
switch (type) {
{ case INT8:
case INT8: numBytesPerElement = sizeof(qint8);
numBytesPerElement = sizeof(qint8); break;
break; case INT16:
case INT16: numBytesPerElement = sizeof(qint16);
numBytesPerElement = sizeof(qint16); break;
break; case INT32:
case INT32: numBytesPerElement = sizeof(qint32);
numBytesPerElement = sizeof(qint32); break;
break; case UINT8:
case UINT8: numBytesPerElement = sizeof(quint8);
numBytesPerElement = sizeof(quint8); break;
break; case UINT16:
case UINT16: numBytesPerElement = sizeof(quint16);
numBytesPerElement = sizeof(quint16); break;
break; case UINT32:
case UINT32: numBytesPerElement = sizeof(quint32);
numBytesPerElement = sizeof(quint32); break;
break; case FLOAT32:
case FLOAT32: numBytesPerElement = sizeof(quint32);
numBytesPerElement = sizeof(quint32); break;
break; case ENUM:
case ENUM: numBytesPerElement = sizeof(quint8);
numBytesPerElement = sizeof(quint8); break;
break; case STRING:
case STRING: numBytesPerElement = sizeof(quint8);
numBytesPerElement = sizeof(quint8); break;
break; default:
default: numBytesPerElement = 0;
numBytesPerElement = 0; }
} }
}
void UAVObjectField::initialize(quint8* data, quint32 dataOffset, UAVObject* obj)
void UAVObjectField::initialize(quint8* data, quint32 dataOffset, UAVObject* obj) {
{ this->data = data;
this->data = data; this->offset = dataOffset;
this->offset = dataOffset; this->obj = obj;
this->obj = obj; clear();
clear(); }
}
UAVObjectField::FieldType UAVObjectField::getType()
UAVObjectField::FieldType UAVObjectField::getType() {
{ return type;
return type; }
}
QStringList UAVObjectField::getElementNames()
QStringList UAVObjectField::getElementNames() {
{ return elementNames;
return elementNames; }
}
UAVObject* UAVObjectField::getObject()
UAVObject* UAVObjectField::getObject() {
{ return obj;
return obj; }
}
void UAVObjectField::clear()
void UAVObjectField::clear() {
{ QMutexLocker locker(obj->getMutex());
QMutexLocker locker(obj->getMutex()); memset(&data[offset], 0, numBytesPerElement*numElements);
memset(&data[offset], 0, numBytesPerElement*numElements); }
}
QString UAVObjectField::getName()
QString UAVObjectField::getName() {
{ return name;
return name; }
}
QString UAVObjectField::getUnits()
QString UAVObjectField::getUnits() {
{ return units;
return units; }
}
QStringList UAVObjectField::getOptions()
QStringList UAVObjectField::getOptions() {
{ return options;
return options; }
}
quint32 UAVObjectField::getNumElements()
quint32 UAVObjectField::getNumElements() {
{ return numElements;
return numElements; }
}
quint32 UAVObjectField::getDataOffset()
quint32 UAVObjectField::getDataOffset() {
{ return offset;
return offset; }
}
quint32 UAVObjectField::getNumBytes()
quint32 UAVObjectField::getNumBytes() {
{ return numBytesPerElement * numElements;
return numBytesPerElement * numElements; }
}
QString UAVObjectField::toString()
QString UAVObjectField::toString() {
{ QString sout;
QString sout; sout.append ( QString("%1: [ ").arg(name) );
sout.append ( QString("%1: [ ").arg(name) ); for (unsigned int n = 0; n < numElements; ++n)
for (unsigned int n = 0; n < numElements; ++n) {
{ sout.append( QString("%1 ").arg(getDouble(n)) );
sout.append( QString("%1 ").arg(getDouble(n)) ); }
} sout.append( QString("] %1\n").arg(units) );
sout.append( QString("] %1\n").arg(units) ); return sout;
return sout; }
}
qint32 UAVObjectField::pack(quint8* dataOut)
qint32 UAVObjectField::pack(quint8* dataOut) {
{ QMutexLocker locker(obj->getMutex());
QMutexLocker locker(obj->getMutex()); // Pack each element in output buffer
// Pack each element in output buffer switch (type)
switch (type) {
{ case INT8:
case INT8: memcpy(dataOut, &data[offset], numElements);
memcpy(dataOut, &data[offset], numElements); break;
break; case INT16:
case INT16: for (quint32 index = 0; index < numElements; ++index)
for (quint32 index = 0; index < numElements; ++index) {
{ qint16 value;
qint16 value; memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement); qToLittleEndian<qint16>(value, &dataOut[numBytesPerElement*index]);
qToLittleEndian<qint16>(value, &dataOut[numBytesPerElement*index]); }
} break;
break; case INT32:
case INT32: for (quint32 index = 0; index < numElements; ++index)
for (quint32 index = 0; index < numElements; ++index) {
{ qint32 value;
qint32 value; memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement); qToLittleEndian<qint32>(value, &dataOut[numBytesPerElement*index]);
qToLittleEndian<qint32>(value, &dataOut[numBytesPerElement*index]); }
} break;
break; case UINT8:
case UINT8: for (quint32 index = 0; index < numElements; ++index)
for (quint32 index = 0; index < numElements; ++index) {
{ dataOut[numBytesPerElement*index] = data[offset + numBytesPerElement*index];
dataOut[numBytesPerElement*index] = data[offset + numBytesPerElement*index]; }
} break;
break; case UINT16:
case UINT16: for (quint32 index = 0; index < numElements; ++index)
for (quint32 index = 0; index < numElements; ++index) {
{ quint16 value;
quint16 value; memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement); qToLittleEndian<quint16>(value, &dataOut[numBytesPerElement*index]);
qToLittleEndian<quint16>(value, &dataOut[numBytesPerElement*index]); }
} break;
break; case UINT32:
case UINT32: for (quint32 index = 0; index < numElements; ++index)
for (quint32 index = 0; index < numElements; ++index) {
{ quint32 value;
quint32 value; memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement); qToLittleEndian<quint32>(value, &dataOut[numBytesPerElement*index]);
qToLittleEndian<quint32>(value, &dataOut[numBytesPerElement*index]); }
} break;
break; case FLOAT32:
case FLOAT32: for (quint32 index = 0; index < numElements; ++index)
for (quint32 index = 0; index < numElements; ++index) {
{ quint32 value;
quint32 value; memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement); qToLittleEndian<quint32>(value, &dataOut[numBytesPerElement*index]);
qToLittleEndian<quint32>(value, &dataOut[numBytesPerElement*index]); }
} break;
break; case ENUM:
case ENUM: for (quint32 index = 0; index < numElements; ++index)
for (quint32 index = 0; index < numElements; ++index) {
{ dataOut[numBytesPerElement*index] = data[offset + numBytesPerElement*index];
dataOut[numBytesPerElement*index] = data[offset + numBytesPerElement*index]; }
} break;
break; case STRING:
case STRING: memcpy(dataOut, &data[offset], numElements);
memcpy(dataOut, &data[offset], numElements); break;
break; }
} // Done
// Done return getNumBytes();
return getNumBytes(); }
}
qint32 UAVObjectField::unpack(const quint8* dataIn)
qint32 UAVObjectField::unpack(const quint8* dataIn) {
{ QMutexLocker locker(obj->getMutex());
QMutexLocker locker(obj->getMutex()); // Unpack each element from input buffer
// Unpack each element from input buffer switch (type)
switch (type) {
{ case INT8:
case INT8: memcpy(&data[offset], dataIn, numElements);
memcpy(&data[offset], dataIn, numElements); break;
break; case INT16:
case INT16: for (quint32 index = 0; index < numElements; ++index)
for (quint32 index = 0; index < numElements; ++index) {
{ qint16 value;
qint16 value; value = qFromLittleEndian<qint16>(&dataIn[numBytesPerElement*index]);
value = qFromLittleEndian<qint16>(&dataIn[numBytesPerElement*index]); memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement); }
} break;
break; case INT32:
case INT32: for (quint32 index = 0; index < numElements; ++index)
for (quint32 index = 0; index < numElements; ++index) {
{ qint32 value;
qint32 value; value = qFromLittleEndian<qint32>(&dataIn[numBytesPerElement*index]);
value = qFromLittleEndian<qint32>(&dataIn[numBytesPerElement*index]); memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement); }
} break;
break; case UINT8:
case UINT8: for (quint32 index = 0; index < numElements; ++index)
for (quint32 index = 0; index < numElements; ++index) {
{ data[offset + numBytesPerElement*index] = dataIn[numBytesPerElement*index];
data[offset + numBytesPerElement*index] = dataIn[numBytesPerElement*index]; }
} break;
break; case UINT16:
case UINT16: for (quint32 index = 0; index < numElements; ++index)
for (quint32 index = 0; index < numElements; ++index) {
{ quint16 value;
quint16 value; value = qFromLittleEndian<quint16>(&dataIn[numBytesPerElement*index]);
value = qFromLittleEndian<quint16>(&dataIn[numBytesPerElement*index]); memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement); }
} break;
break; case UINT32:
case UINT32: for (quint32 index = 0; index < numElements; ++index)
for (quint32 index = 0; index < numElements; ++index) {
{ quint32 value;
quint32 value; value = qFromLittleEndian<quint32>(&dataIn[numBytesPerElement*index]);
value = qFromLittleEndian<quint32>(&dataIn[numBytesPerElement*index]); memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement); }
} break;
break; case FLOAT32:
case FLOAT32: for (quint32 index = 0; index < numElements; ++index)
for (quint32 index = 0; index < numElements; ++index) {
{ quint32 value;
quint32 value; value = qFromLittleEndian<quint32>(&dataIn[numBytesPerElement*index]);
value = qFromLittleEndian<quint32>(&dataIn[numBytesPerElement*index]); memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement); }
} break;
break; case ENUM:
case ENUM: for (quint32 index = 0; index < numElements; ++index)
for (quint32 index = 0; index < numElements; ++index) {
{ data[offset + numBytesPerElement*index] = dataIn[numBytesPerElement*index];
data[offset + numBytesPerElement*index] = dataIn[numBytesPerElement*index]; }
} break;
break; case STRING:
case STRING: memcpy(&data[offset], dataIn, numElements);
memcpy(&data[offset], dataIn, numElements); break;
break; }
} // Done
// Done return getNumBytes();
return getNumBytes(); }
}
quint32 UAVObjectField::getNumBytesElement()
quint32 UAVObjectField::getNumBytesElement() {
{ return numBytesPerElement;
return numBytesPerElement; }
}
bool UAVObjectField::isNumeric()
bool UAVObjectField::isNumeric() {
{ switch (type)
switch (type) {
{ case INT8:
case INT8: return true;
return true; break;
break; case INT16:
case INT16: return true;
return true; break;
break; case INT32:
case INT32: return true;
return true; break;
break; case UINT8:
case UINT8: return true;
return true; break;
break; case UINT16:
case UINT16: return true;
return true; break;
break; case UINT32:
case UINT32: return true;
return true; break;
break; case FLOAT32:
case FLOAT32: return true;
return true; break;
break; case ENUM:
case ENUM: return false;
return false; break;
break; case STRING:
case STRING: return false;
return false; break;
break; default:
default: return false;
return false; }
} }
}
bool UAVObjectField::isText()
bool UAVObjectField::isText() {
{ switch (type)
switch (type) {
{ case INT8:
case INT8: return false;
return false; break;
break; case INT16:
case INT16: return false;
return false; break;
break; case INT32:
case INT32: return false;
return false; break;
break; case UINT8:
case UINT8: return false;
return false; break;
break; case UINT16:
case UINT16: return false;
return false; break;
break; case UINT32:
case UINT32: return false;
return false; break;
break; case FLOAT32:
case FLOAT32: return false;
return false; break;
break; case ENUM:
case ENUM: return true;
return true; break;
break; case STRING:
case STRING: return true;
return true; break;
break; default:
default: return false;
return false; }
} }
}
QVariant UAVObjectField::getValue(quint32 index)
QVariant UAVObjectField::getValue(quint32 index) {
{ QMutexLocker locker(obj->getMutex());
QMutexLocker locker(obj->getMutex()); // Check that index is not out of bounds
// Check that index is not out of bounds if ( index >= numElements )
if ( index >= numElements ) {
{ return QVariant();
return QVariant(); }
} // Get value
// Get value switch (type)
switch (type) {
{ case INT8:
case INT8: {
{ qint8 tmpint8;
qint8 tmpint8; memcpy(&tmpint8, &data[offset + numBytesPerElement*index], numBytesPerElement);
memcpy(&tmpint8, &data[offset + numBytesPerElement*index], numBytesPerElement); return QVariant(tmpint8);
return QVariant(tmpint8); break;
break; }
} case INT16:
case INT16: {
{ qint16 tmpint16;
qint16 tmpint16; memcpy(&tmpint16, &data[offset + numBytesPerElement*index], numBytesPerElement);
memcpy(&tmpint16, &data[offset + numBytesPerElement*index], numBytesPerElement); return QVariant(tmpint16);
return QVariant(tmpint16); break;
break; }
} case INT32:
case INT32: {
{ qint32 tmpint32;
qint32 tmpint32; memcpy(&tmpint32, &data[offset + numBytesPerElement*index], numBytesPerElement);
memcpy(&tmpint32, &data[offset + numBytesPerElement*index], numBytesPerElement); return QVariant(tmpint32);
return QVariant(tmpint32); break;
break; }
} case UINT8:
case UINT8: {
{ quint8 tmpuint8;
quint8 tmpuint8; memcpy(&tmpuint8, &data[offset + numBytesPerElement*index], numBytesPerElement);
memcpy(&tmpuint8, &data[offset + numBytesPerElement*index], numBytesPerElement); return QVariant(tmpuint8);
return QVariant(tmpuint8); break;
break; }
} case UINT16:
case UINT16: {
{ quint16 tmpuint16;
quint16 tmpuint16; memcpy(&tmpuint16, &data[offset + numBytesPerElement*index], numBytesPerElement);
memcpy(&tmpuint16, &data[offset + numBytesPerElement*index], numBytesPerElement); return QVariant(tmpuint16);
return QVariant(tmpuint16); break;
break; }
} case UINT32:
case UINT32: {
{ quint32 tmpuint32;
quint32 tmpuint32; memcpy(&tmpuint32, &data[offset + numBytesPerElement*index], numBytesPerElement);
memcpy(&tmpuint32, &data[offset + numBytesPerElement*index], numBytesPerElement); return QVariant(tmpuint32);
return QVariant(tmpuint32); break;
break; }
} case FLOAT32:
case FLOAT32: {
{ float tmpfloat;
float tmpfloat; memcpy(&tmpfloat, &data[offset + numBytesPerElement*index], numBytesPerElement);
memcpy(&tmpfloat, &data[offset + numBytesPerElement*index], numBytesPerElement); return QVariant(tmpfloat);
return QVariant(tmpfloat); break;
break; }
} case ENUM:
case ENUM: {
{ quint8 tmpenum;
quint8 tmpenum; memcpy(&tmpenum, &data[offset + numBytesPerElement*index], numBytesPerElement);
memcpy(&tmpenum, &data[offset + numBytesPerElement*index], numBytesPerElement); return QVariant( options[tmpenum] );
return QVariant( options[tmpenum] ); break;
break; }
} case STRING:
case STRING: {
{ data[offset + numElements - 1] = '\0';
data[offset + numElements - 1] = '\0'; QString str((char*)&data[offset]);
QString str((char*)&data[offset]); return QVariant( str );
return QVariant( str ); break;
break; }
} }
} // If this point is reached then we got an invalid type
// If this point is reached then we got an invalid type return QVariant();
return QVariant(); }
}
void UAVObjectField::setValue(const QVariant& value, quint32 index)
void UAVObjectField::setValue(const QVariant& value, quint32 index) {
{ QMutexLocker locker(obj->getMutex());
QMutexLocker locker(obj->getMutex()); // Check that index is not out of bounds
// Check that index is not out of bounds if ( index >= numElements )
if ( index >= numElements ) {
{ return;
return; }
} // Get metadata
// Get metadata UAVObject::Metadata mdata = obj->getMetadata();
UAVObject::Metadata mdata = obj->getMetadata(); // Update value if the access mode permits
// Update value if the access mode permits if ( mdata.gcsAccess == UAVObject::ACCESS_READWRITE )
if ( mdata.gcsAccess == UAVObject::ACCESS_READWRITE ) {
{ switch (type)
switch (type) {
{ case INT8:
case INT8: {
{ qint8 tmpint8 = value.toInt();
qint8 tmpint8 = value.toInt(); memcpy(&data[offset + numBytesPerElement*index], &tmpint8, numBytesPerElement);
memcpy(&data[offset + numBytesPerElement*index], &tmpint8, numBytesPerElement); break;
break; }
} case INT16:
case INT16: {
{ qint16 tmpint16 = value.toInt();
qint16 tmpint16 = value.toInt(); memcpy(&data[offset + numBytesPerElement*index], &tmpint16, numBytesPerElement);
memcpy(&data[offset + numBytesPerElement*index], &tmpint16, numBytesPerElement); break;
break; }
} case INT32:
case INT32: {
{ qint32 tmpint32 = value.toInt();
qint32 tmpint32 = value.toInt(); memcpy(&data[offset + numBytesPerElement*index], &tmpint32, numBytesPerElement);
memcpy(&data[offset + numBytesPerElement*index], &tmpint32, numBytesPerElement); break;
break; }
} case UINT8:
case UINT8: {
{ quint8 tmpuint8 = value.toUInt();
quint8 tmpuint8 = value.toUInt(); memcpy(&data[offset + numBytesPerElement*index], &tmpuint8, numBytesPerElement);
memcpy(&data[offset + numBytesPerElement*index], &tmpuint8, numBytesPerElement); break;
break; }
} case UINT16:
case UINT16: {
{ quint16 tmpuint16 = value.toUInt();
quint16 tmpuint16 = value.toUInt(); memcpy(&data[offset + numBytesPerElement*index], &tmpuint16, numBytesPerElement);
memcpy(&data[offset + numBytesPerElement*index], &tmpuint16, numBytesPerElement); break;
break; }
} case UINT32:
case UINT32: {
{ quint32 tmpuint32 = value.toUInt();
quint32 tmpuint32 = value.toUInt(); memcpy(&data[offset + numBytesPerElement*index], &tmpuint32, numBytesPerElement);
memcpy(&data[offset + numBytesPerElement*index], &tmpuint32, numBytesPerElement); break;
break; }
} case FLOAT32:
case FLOAT32: {
{ float tmpfloat = value.toFloat();
float tmpfloat = value.toFloat(); memcpy(&data[offset + numBytesPerElement*index], &tmpfloat, numBytesPerElement);
memcpy(&data[offset + numBytesPerElement*index], &tmpfloat, numBytesPerElement); break;
break; }
} case ENUM:
case ENUM: {
{ qint8 tmpenum = options.indexOf( value.toString() );
qint8 tmpenum = options.indexOf( value.toString() ); memcpy(&data[offset + numBytesPerElement*index], &tmpenum, numBytesPerElement);
memcpy(&data[offset + numBytesPerElement*index], &tmpenum, numBytesPerElement); break;
break; }
} case STRING:
case STRING: {
{ QString str = value.toString();
QString str = value.toString(); QByteArray barray = str.toAscii();
QByteArray barray = str.toAscii(); quint32 index;
quint32 index; for (index = 0; index < (quint32)barray.length() && index < (numElements-1); ++index)
for (index = 0; index < (quint32)barray.length() && index < (numElements-1); ++index) {
{ data[offset+index] = barray[index];
data[offset+index] = barray[index]; }
} barray[index] = '\0';
barray[index] = '\0'; break;
break; }
} }
} }
} }
}
double UAVObjectField::getDouble(quint32 index)
double UAVObjectField::getDouble(quint32 index) {
{ return getValue().toDouble();
return getValue().toDouble(); }
}
void UAVObjectField::setDouble(double value, quint32 index)
void UAVObjectField::setDouble(double value, quint32 index) {
{ setValue(QVariant(value));
setValue(QVariant(value)); }
}

View File

@ -1,89 +1,88 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavobjectfield.h * @file uavobjectfield.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. * @brief
* @brief * @see The GNU Public License (GPL) Version 3
* @see The GNU Public License (GPL) Version 3 * @defgroup uavobjectsplugin
* @defgroup uavobjects_plugin * @{
* @{ *
* *****************************************************************************/
*****************************************************************************/ /*
/* * This program is free software; you can redistribute it and/or modify
* 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
* it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or
* the Free Software Foundation; either version 3 of the License, or * (at your option) any later version.
* (at your option) any later version. *
* * This program is distributed in the hope that it will be useful, but
* This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details.
* for more details. *
* * You should have received a copy of the GNU General Public License along
* 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.,
* with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
*/ #ifndef UAVOBJECTFIELD_H
#ifndef UAVOBJECTFIELD_H #define UAVOBJECTFIELD_H
#define UAVOBJECTFIELD_H
#include "uavobjects_global.h"
#include "uavobjects_global.h" #include "uavobject.h"
#include "uavobject.h" #include <QStringList>
#include <QStringList> #include <QVariant>
#include <QVariant>
class UAVObject;
class UAVObject;
class UAVOBJECTS_EXPORT UAVObjectField: public QObject
class UAVOBJECTS_EXPORT UAVObjectField: public QObject {
{ Q_OBJECT
Q_OBJECT
public:
public: typedef enum { INT8 = 0, INT16, INT32, UINT8, UINT16, UINT32, FLOAT32, ENUM, STRING } FieldType;
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, quint32 numElements, const QStringList& options); UAVObjectField(const QString& name, const QString& units, FieldType type, const QStringList& elementNames, 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);
void initialize(quint8* data, quint32 dataOffset, UAVObject* obj); UAVObject* getObject();
UAVObject* getObject(); FieldType getType();
FieldType getType(); QString getName();
QString getName(); QString getUnits();
QString getUnits(); quint32 getNumElements();
quint32 getNumElements(); QStringList getElementNames();
QStringList getElementNames(); QStringList getOptions();
QStringList getOptions(); qint32 pack(quint8* dataOut);
qint32 pack(quint8* dataOut); qint32 unpack(const quint8* dataIn);
qint32 unpack(const quint8* dataIn); QVariant getValue(quint32 index = 0);
QVariant getValue(quint32 index = 0); void setValue(const QVariant& data, quint32 index = 0);
void setValue(const QVariant& data, quint32 index = 0); double getDouble(quint32 index = 0);
double getDouble(quint32 index = 0); void setDouble(double value, quint32 index = 0);
void setDouble(double value, quint32 index = 0); quint32 getDataOffset();
quint32 getDataOffset(); quint32 getNumBytes();
quint32 getNumBytes(); quint32 getNumBytesElement();
quint32 getNumBytesElement(); bool isNumeric();
bool isNumeric(); bool isText();
bool isText(); QString toString();
QString toString();
signals:
signals: void fieldUpdated(UAVObjectField* field);
void fieldUpdated(UAVObjectField* field);
protected:
protected: QString name;
QString name; QString units;
QString units; FieldType type;
FieldType type; QStringList elementNames;
QStringList elementNames; QStringList options;
QStringList options; quint32 numElements;
quint32 numElements; quint32 numBytesPerElement;
quint32 numBytesPerElement; quint32 offset;
quint32 offset; quint8* data;
quint8* data; UAVObject* obj;
UAVObject* obj;
void clear();
void clear(); void constructorInitialize(const QString& name, const QString& units, FieldType type, const QStringList& elementNames, const QStringList& options);
void constructorInitialize(const QString& name, const QString& units, FieldType type, const QStringList& elementNames, const QStringList& options);
};
};
#endif // UAVOBJECTFIELD_H
#endif // UAVOBJECTFIELD_H

View File

@ -1,340 +1,339 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavobjectmanager.cpp * @file uavobjectmanager.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. * @brief
* @brief * @see The GNU Public License (GPL) Version 3
* @see The GNU Public License (GPL) Version 3 * @defgroup uavobjectsplugin
* @defgroup uavobjects_plugin * @{
* @{ *
* *****************************************************************************/
*****************************************************************************/ /*
/* * This program is free software; you can redistribute it and/or modify
* 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
* it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or
* the Free Software Foundation; either version 3 of the License, or * (at your option) any later version.
* (at your option) any later version. *
* * This program is distributed in the hope that it will be useful, but
* This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details.
* for more details. *
* * You should have received a copy of the GNU General Public License along
* 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.,
* with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
*/ #include "uavobjectmanager.h"
#include "uavobjectmanager.h"
/**
/** * Constructor
* Constructor */
*/ UAVObjectManager::UAVObjectManager()
UAVObjectManager::UAVObjectManager() {
{ mutex = new QMutex(QMutex::Recursive);
mutex = new QMutex(QMutex::Recursive); }
}
UAVObjectManager::~UAVObjectManager()
UAVObjectManager::~UAVObjectManager() {
{ delete mutex;
delete mutex; }
}
/**
/** * Register an object with the manager. This function must be called for all newly created instances.
* 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
* 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
* an existing object. The object will be registered and will be properly initialized so that it can accept * updates.
* updates. */
*/ bool UAVObjectManager::registerObject(UAVDataObject* obj)
bool UAVObjectManager::registerObject(UAVDataObject* obj) {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); // Check if this object type is already in the list
// Check if this object type is already in the list for (int objidx = 0; objidx < objects.length(); ++objidx)
for (int objidx = 0; objidx < objects.length(); ++objidx) {
{ // Check if the object ID is in the list
// Check if the object ID is in the list if (objects[objidx].length() > 0 && objects[objidx][0]->getObjID() == obj->getObjID())
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
// Check if this is a single instance object, if yes we can not add a new instance if (obj->isSingleInstance())
if (obj->isSingleInstance()) {
{ return false;
return false; }
} // The object type has alredy been added, so now we need to initialize the new instance with the appropriate id
// 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
// 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
// Get object type metaobject from existing instance UAVDataObject* refObj = dynamic_cast<UAVDataObject*>(objects[objidx][0]);
UAVDataObject* refObj = dynamic_cast<UAVDataObject*>(objects[objidx][0]); if (refObj == NULL)
if (refObj == NULL) {
{ return false;
return false; }
} UAVMetaObject* mobj = refObj->getMetaObject();
UAVMetaObject* mobj = refObj->getMetaObject(); // If the instance ID is specified and not at the default value (0) then we need to make sure
// 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
// that there are no gaps in the instance list. If gaps are found then then additional instances // will be created.
// will be created. if ( (obj->getInstID() > 0) && (obj->getInstID() < MAX_INSTANCES) )
if ( (obj->getInstID() > 0) && (obj->getInstID() < MAX_INSTANCES) ) {
{ for (int instidx = 0; instidx < objects[objidx].length(); ++instidx)
for (int instidx = 0; instidx < objects[objidx].length(); ++instidx) {
{ if ( objects[objidx][instidx]->getInstID() == obj->getInstID() )
if ( objects[objidx][instidx]->getInstID() == obj->getInstID() ) {
{ // Instance conflict, do not add
// Instance conflict, do not add return false;
return false; }
} }
} // Check if there are any gaps between the requested instance ID and the ones in the list,
// Check if there are any gaps between the requested instance ID and the ones in the list, // if any then create the missing instances.
// if any then create the missing instances. for (quint32 instidx = objects[objidx].length(); instidx < obj->getInstID(); ++instidx)
for (quint32 instidx = objects[objidx].length(); instidx < obj->getInstID(); ++instidx) {
{ UAVDataObject* cobj = obj->clone(instidx);
UAVDataObject* cobj = obj->clone(instidx); cobj->initialize(mobj);
cobj->initialize(mobj); objects[objidx].append(cobj);
objects[objidx].append(cobj); emit newInstance(cobj);
emit newInstance(cobj); }
} // Finally, initialize the actual object instance
// Finally, initialize the actual object instance obj->initialize(mobj);
obj->initialize(mobj); }
} else if (obj->getInstID() == 0)
else if (obj->getInstID() == 0) {
{ // Assign the next available ID and initialize the object instance
// Assign the next available ID and initialize the object instance obj->initialize(objects[objidx].length(), mobj);
obj->initialize(objects[objidx].length(), mobj); }
} else
else {
{ return false;
return false; }
} // Add the actual object instance in the list
// Add the actual object instance in the list objects[objidx].append(obj);
objects[objidx].append(obj); emit newInstance(obj);
emit newInstance(obj); return true;
return true; }
} }
} // If this point is reached then this is the first time this object type (ID) is added in the list
// 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 a new list of the instances, add in the object collection and create the object's metaobject // Create metaobject
// Create metaobject QString mname = obj->getName();
QString mname = obj->getName(); mname.append("Meta");
mname.append("Meta"); UAVMetaObject* mobj = new UAVMetaObject(obj->getObjID()+1, mname, obj);
UAVMetaObject* mobj = new UAVMetaObject(obj->getObjID()+1, mname, obj); // Initialize object
// Initialize object obj->initialize(0, mobj);
obj->initialize(0, mobj); // Add to list
// Add to list addObject(obj);
addObject(obj); addObject(mobj);
addObject(mobj); return true;
return true; }
}
void UAVObjectManager::addObject(UAVObject* obj)
void UAVObjectManager::addObject(UAVObject* obj) {
{ // Add to list
// Add to list QList<UAVObject*> list;
QList<UAVObject*> list; list.append(obj);
list.append(obj); objects.append(list);
objects.append(list); emit newObject(obj);
emit newObject(obj); }
}
/**
/** * Get all objects. A two dimentional QList is returned. Objects are grouped by
* Get all objects. A two dimentional QList is returned. Objects are grouped by * instances of the same object type.
* instances of the same object type. */
*/ QList< QList<UAVObject*> > UAVObjectManager::getObjects()
QList< QList<UAVObject*> > UAVObjectManager::getObjects() {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); return objects;
return objects; }
}
/**
/** * Same as getObjects() but will only return DataObjects.
* Same as getObjects() but will only return DataObjects. */
*/ QList< QList<UAVDataObject*> > UAVObjectManager::getDataObjects()
QList< QList<UAVDataObject*> > UAVObjectManager::getDataObjects() {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); QList< QList<UAVDataObject*> > dObjects;
QList< QList<UAVDataObject*> > dObjects;
// Go through objects and copy to new list when types match
// Go through objects and copy to new list when types match for (int objidx = 0; objidx < objects.length(); ++objidx)
for (int objidx = 0; objidx < objects.length(); ++objidx) {
{ if (objects[objidx].length() > 0)
if (objects[objidx].length() > 0) {
{ // Check type
// Check type UAVDataObject* obj = dynamic_cast<UAVDataObject*>(objects[objidx][0]);
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(objects[objidx][0]); if (obj != NULL)
if (obj != NULL) {
{ // Create instance list
// Create instance list QList<UAVDataObject*> list;
QList<UAVDataObject*> list; // Go through instances and cast them to UAVDataObject, then add to list
// Go through instances and cast them to UAVDataObject, then add to list for (int instidx = 0; instidx < objects[objidx].length(); ++instidx)
for (int instidx = 0; instidx < objects[objidx].length(); ++instidx) {
{ obj = dynamic_cast<UAVDataObject*>(objects[objidx][instidx]);
obj = dynamic_cast<UAVDataObject*>(objects[objidx][instidx]); if (obj != NULL)
if (obj != NULL) {
{ list.append(obj);
list.append(obj); }
} }
} // Append to object list
// Append to object list dObjects.append(list);
dObjects.append(list); }
} }
} }
} // Done
// Done return dObjects;
return dObjects; }
}
/**
/** * Same as getObjects() but will only return MetaObjects.
* Same as getObjects() but will only return MetaObjects. */
*/ QList <QList<UAVMetaObject*> > UAVObjectManager::getMetaObjects()
QList <QList<UAVMetaObject*> > UAVObjectManager::getMetaObjects() {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); QList< QList<UAVMetaObject*> > mObjects;
QList< QList<UAVMetaObject*> > mObjects;
// Go through objects and copy to new list when types match
// Go through objects and copy to new list when types match for (int objidx = 0; objidx < objects.length(); ++objidx)
for (int objidx = 0; objidx < objects.length(); ++objidx) {
{ if (objects[objidx].length() > 0)
if (objects[objidx].length() > 0) {
{ // Check type
// Check type UAVMetaObject* obj = dynamic_cast<UAVMetaObject*>(objects[objidx][0]);
UAVMetaObject* obj = dynamic_cast<UAVMetaObject*>(objects[objidx][0]); if (obj != NULL)
if (obj != NULL) {
{ // Create instance list
// Create instance list QList<UAVMetaObject*> list;
QList<UAVMetaObject*> list; // Go through instances and cast them to UAVMetaObject, then add to list
// Go through instances and cast them to UAVMetaObject, then add to list for (int instidx = 0; instidx < objects[objidx].length(); ++instidx)
for (int instidx = 0; instidx < objects[objidx].length(); ++instidx) {
{ obj = dynamic_cast<UAVMetaObject*>(objects[objidx][instidx]);
obj = dynamic_cast<UAVMetaObject*>(objects[objidx][instidx]); if (obj != NULL)
if (obj != NULL) {
{ list.append(obj);
list.append(obj); }
} }
} // Append to object list
// Append to object list mObjects.append(list);
mObjects.append(list); }
} }
} }
} // Done
// Done return mObjects;
return mObjects; }
}
/**
/** * Get a specific object given its name and instance ID
* Get a specific object given its name and instance ID * @returns The object is found or NULL if not
* @returns The object is found or NULL if not */
*/ UAVObject* UAVObjectManager::getObject(const QString& name, quint32 instId)
UAVObject* UAVObjectManager::getObject(const QString& name, quint32 instId) {
{ return getObject(&name, 0, instId);
return getObject(&name, 0, instId); }
}
/**
/** * Get a specific object given its object and instance ID
* Get a specific object given its object and instance ID * @returns The object is found or NULL if not
* @returns The object is found or NULL if not */
*/ UAVObject* UAVObjectManager::getObject(quint32 objId, quint32 instId)
UAVObject* UAVObjectManager::getObject(quint32 objId, quint32 instId) {
{ return getObject(NULL, objId, instId);
return getObject(NULL, objId, instId); }
}
/**
/** * Helper function for the public getObject() functions.
* Helper function for the public getObject() functions. */
*/ UAVObject* UAVObjectManager::getObject(const QString* name, quint32 objId, quint32 instId)
UAVObject* UAVObjectManager::getObject(const QString* name, quint32 objId, quint32 instId) {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); // Check if this object type is already in the list
// Check if this object type is already in the list for (int objidx = 0; objidx < objects.length(); ++objidx)
for (int objidx = 0; objidx < objects.length(); ++objidx) {
{ // Check if the object ID is in the list
// Check if the object ID is in the list if (objects[objidx].length() > 0)
if (objects[objidx].length() > 0) {
{ if ( (name != NULL && objects[objidx][0]->getName().compare(name) == 0) || (name == NULL && objects[objidx][0]->getObjID() == objId) )
if ( (name != NULL && objects[objidx][0]->getName().compare(name) == 0) || (name == NULL && objects[objidx][0]->getObjID() == objId) ) {
{ // Look for the requested instance ID
// Look for the requested instance ID for (int instidx = 0; instidx < objects[objidx].length(); ++instidx)
for (int instidx = 0; instidx < objects[objidx].length(); ++instidx) {
{ if (objects[objidx][instidx]->getInstID() == instId)
if (objects[objidx][instidx]->getInstID() == instId) {
{ return objects[objidx][instidx];
return objects[objidx][instidx]; }
} }
} }
} }
} }
} // If this point is reached then the requested object could not be found
// If this point is reached then the requested object could not be found return NULL;
return NULL; }
}
/**
/** * Get all the instances of the object specified by name
* Get all the instances of the object specified by name */
*/ QList<UAVObject*> UAVObjectManager::getObjectInstances(const QString& name)
QList<UAVObject*> UAVObjectManager::getObjectInstances(const QString& name) {
{ return getObjectInstances(&name, 0);
return getObjectInstances(&name, 0); }
}
/**
/** * Get all the instances of the object specified by its ID
* Get all the instances of the object specified by its ID */
*/ QList<UAVObject*> UAVObjectManager::getObjectInstances(quint32 objId)
QList<UAVObject*> UAVObjectManager::getObjectInstances(quint32 objId) {
{ return getObjectInstances(NULL, objId);
return getObjectInstances(NULL, objId); }
}
/**
/** * Helper function for the public getObjectInstances()
* Helper function for the public getObjectInstances() */
*/ QList<UAVObject*> UAVObjectManager::getObjectInstances(const QString* name, quint32 objId)
QList<UAVObject*> UAVObjectManager::getObjectInstances(const QString* name, quint32 objId) {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); // Check if this object type is already in the list
// Check if this object type is already in the list for (int objidx = 0; objidx < objects.length(); ++objidx)
for (int objidx = 0; objidx < objects.length(); ++objidx) {
{ // Check if the object ID is in the list
// Check if the object ID is in the list if (objects[objidx].length() > 0)
if (objects[objidx].length() > 0) {
{ if ( (name != NULL && objects[objidx][0]->getName().compare(name) == 0) || (name == NULL && objects[objidx][0]->getObjID() == objId) )
if ( (name != NULL && objects[objidx][0]->getName().compare(name) == 0) || (name == NULL && objects[objidx][0]->getObjID() == objId) ) {
{ return objects[objidx];
return objects[objidx]; }
} }
} }
} // If this point is reached then the requested object could not be found
// If this point is reached then the requested object could not be found return QList<UAVObject*>();
return QList<UAVObject*>(); }
}
/**
/** * Get the number of instances for an object given its name
* Get the number of instances for an object given its name */
*/ qint32 UAVObjectManager::getNumInstances(const QString& name)
qint32 UAVObjectManager::getNumInstances(const QString& name) {
{ return getNumInstances(&name, 0);
return getNumInstances(&name, 0); }
}
/**
/** * Get the number of instances for an object given its ID
* Get the number of instances for an object given its ID */
*/ qint32 UAVObjectManager::getNumInstances(quint32 objId)
qint32 UAVObjectManager::getNumInstances(quint32 objId) {
{ return getNumInstances(NULL, objId);
return getNumInstances(NULL, objId); }
}
/**
/** * Helper function for public getNumInstances
* Helper function for public getNumInstances */
*/ qint32 UAVObjectManager::getNumInstances(const QString* name, quint32 objId)
qint32 UAVObjectManager::getNumInstances(const QString* name, quint32 objId) {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); // Check if this object type is already in the list
// Check if this object type is already in the list for (int objidx = 0; objidx < objects.length(); ++objidx)
for (int objidx = 0; objidx < objects.length(); ++objidx) {
{ // Check if the object ID is in the list
// Check if the object ID is in the list if (objects[objidx].length() > 0)
if (objects[objidx].length() > 0) {
{ if ( (name != NULL && objects[objidx][0]->getName().compare(name) == 0) || (name == NULL && objects[objidx][0]->getObjID() == objId) )
if ( (name != NULL && objects[objidx][0]->getName().compare(name) == 0) || (name == NULL && objects[objidx][0]->getObjID() == objId) ) {
{ return objects[objidx].length();
return objects[objidx].length(); }
} }
} }
} // If this point is reached then the requested object could not be found
// If this point is reached then the requested object could not be found return -1;
return -1; }
}

View File

@ -1,75 +1,74 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavobjectmanager.h * @file uavobjectmanager.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. * @brief
* @brief * @see The GNU Public License (GPL) Version 3
* @see The GNU Public License (GPL) Version 3 * @defgroup uavobjectsplugin
* @defgroup uavobjects_plugin * @{
* @{ *
* *****************************************************************************/
*****************************************************************************/ /*
/* * This program is free software; you can redistribute it and/or modify
* 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
* it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or
* the Free Software Foundation; either version 3 of the License, or * (at your option) any later version.
* (at your option) any later version. *
* * This program is distributed in the hope that it will be useful, but
* This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details.
* for more details. *
* * You should have received a copy of the GNU General Public License along
* 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.,
* with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
*/ #ifndef UAVOBJECTMANAGER_H
#ifndef UAVOBJECTMANAGER_H #define UAVOBJECTMANAGER_H
#define UAVOBJECTMANAGER_H
#include "uavobjects_global.h"
#include "uavobjects_global.h" #include "uavobject.h"
#include "uavobject.h" #include "uavdataobject.h"
#include "uavdataobject.h" #include "uavmetaobject.h"
#include "uavmetaobject.h" #include <QList>
#include <QList> #include <QMutex>
#include <QMutex> #include <QMutexLocker>
#include <QMutexLocker>
class UAVOBJECTS_EXPORT UAVObjectManager: public QObject
class UAVOBJECTS_EXPORT UAVObjectManager: public QObject {
{ Q_OBJECT
Q_OBJECT
public:
public: UAVObjectManager();
UAVObjectManager(); ~UAVObjectManager();
~UAVObjectManager();
bool registerObject(UAVDataObject* obj);
bool registerObject(UAVDataObject* obj); QList< QList<UAVObject*> > getObjects();
QList< QList<UAVObject*> > getObjects(); QList< QList<UAVDataObject*> > getDataObjects();
QList< QList<UAVDataObject*> > getDataObjects(); QList< QList<UAVMetaObject*> > getMetaObjects();
QList< QList<UAVMetaObject*> > getMetaObjects(); UAVObject* getObject(const QString& name, quint32 instId = 0);
UAVObject* getObject(const QString& name, quint32 instId = 0); UAVObject* getObject(quint32 objId, quint32 instId = 0);
UAVObject* getObject(quint32 objId, quint32 instId = 0); QList<UAVObject*> getObjectInstances(const QString& name);
QList<UAVObject*> getObjectInstances(const QString& name); QList<UAVObject*> getObjectInstances(quint32 objId);
QList<UAVObject*> getObjectInstances(quint32 objId); qint32 getNumInstances(const QString& name);
qint32 getNumInstances(const QString& name); qint32 getNumInstances(quint32 objId);
qint32 getNumInstances(quint32 objId);
signals:
signals: void newObject(UAVObject* obj);
void newObject(UAVObject* obj); void newInstance(UAVObject* obj);
void newInstance(UAVObject* obj);
private:
private: static const quint32 MAX_INSTANCES = 1000;
static const quint32 MAX_INSTANCES = 1000;
QList< QList<UAVObject*> > objects;
QList< QList<UAVObject*> > objects; QMutex* mutex;
QMutex* mutex;
void addObject(UAVObject* obj);
void addObject(UAVObject* obj); UAVObject* getObject(const QString* name, quint32 objId, quint32 instId);
UAVObject* getObject(const QString* name, quint32 objId, quint32 instId); QList<UAVObject*> getObjectInstances(const QString* name, quint32 objId);
QList<UAVObject*> getObjectInstances(const QString* name, quint32 objId); qint32 getNumInstances(const QString* name, quint32 objId);
qint32 getNumInstances(const QString* name, quint32 objId); };
};
#endif // UAVOBJECTMANAGER_H
#endif // UAVOBJECTMANAGER_H

View File

@ -1,40 +1,39 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavobjects_global.h * @file uavobjects_global.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. * @brief
* @brief * @see The GNU Public License (GPL) Version 3
* @see The GNU Public License (GPL) Version 3 * @defgroup uavobjectsplugin
* @defgroup uavobjects_plugin * @{
* @{ *
* *****************************************************************************/
*****************************************************************************/ /*
/* * This program is free software; you can redistribute it and/or modify
* 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
* it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or
* the Free Software Foundation; either version 3 of the License, or * (at your option) any later version.
* (at your option) any later version. *
* * This program is distributed in the hope that it will be useful, but
* This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details.
* for more details. *
* * You should have received a copy of the GNU General Public License along
* 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.,
* with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
*/
#ifndef UAVOBJECTS_GLOBAL_H
#ifndef UAVOBJECTS_GLOBAL_H #define UAVOBJECTS_GLOBAL_H
#define UAVOBJECTS_GLOBAL_H
#include <QtCore/qglobal.h>
#include <QtCore/qglobal.h>
#if defined(UAVOBJECTS_LIBRARY)
#if defined(UAVOBJECTS_LIBRARY) # define UAVOBJECTS_EXPORT Q_DECL_EXPORT
# define UAVOBJECTS_EXPORT Q_DECL_EXPORT #else
#else # define UAVOBJECTS_EXPORT Q_DECL_IMPORT
# define UAVOBJECTS_EXPORT Q_DECL_IMPORT #endif
#endif
#endif // UAVOBJECTS_GLOBAL_H
#endif // UAVOBJECTS_GLOBAL_H

View File

@ -1,35 +1,34 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavobjectsinit.h * @file uavobjectsinit.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. * @brief
* @brief * @see The GNU Public License (GPL) Version 3
* @see The GNU Public License (GPL) Version 3 * @defgroup uavobjectsplugin
* @defgroup uavobjects_plugin * @{
* @{ *
* *****************************************************************************/
*****************************************************************************/ /*
/* * This program is free software; you can redistribute it and/or modify
* 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
* it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or
* the Free Software Foundation; either version 3 of the License, or * (at your option) any later version.
* (at your option) any later version. *
* * This program is distributed in the hope that it will be useful, but
* This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details.
* for more details. *
* * You should have received a copy of the GNU General Public License along
* 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.,
* with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
*/ #ifndef UAVOBJECTSINIT_H
#ifndef UAVOBJECTSINIT_H #define UAVOBJECTSINIT_H
#define UAVOBJECTSINIT_H
#include "uavobjectmanager.h"
#include "uavobjectmanager.h"
void UAVObjectsInitialize(UAVObjectManager* objMngr);
void UAVObjectsInitialize(UAVObjectManager* objMngr);
#endif // UAVOBJECTSINIT_H
#endif // UAVOBJECTSINIT_H

View File

@ -1,42 +1,41 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavobjectsinit.cpp * @file uavobjectsinit.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @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.
* @brief Initialize all objects. * Automatically generated by the UAVObjectGenerator.
* Automatically generated by the UAVObjectGenerator. *
* * @note This is an automatically generated file.
* @note This is an automatically generated file. * DO NOT modify manually.
* DO NOT modify manually. * @see The GNU Public License (GPL) Version 3
* @see The GNU Public License (GPL) Version 3 * @defgroup uavobjectsplugin
* @defgroup uavobjects_plugin * @{
* @{ *
* *****************************************************************************/
*****************************************************************************/ /*
/* * This program is free software; you can redistribute it and/or modify
* 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
* it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or
* the Free Software Foundation; either version 3 of the License, or * (at your option) any later version.
* (at your option) any later version. *
* * This program is distributed in the hope that it will be useful, but
* This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details.
* for more details. *
* * You should have received a copy of the GNU General Public License along
* 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.,
* with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
*/ #include "uavobjectsinit.h"
#include "uavobjectsinit.h" $(OBJINC)
$(OBJINC)
/**
/** * Function used to initialize the first instance of each object.
* Function used to initialize the first instance of each object. * This file is automatically updated by the UAVObjectGenerator.
* This file is automatically updated by the UAVObjectGenerator. */
*/ void UAVObjectsInitialize(UAVObjectManager* objMngr)
void UAVObjectsInitialize(UAVObjectManager* objMngr) {
{ $(OBJINIT)
$(OBJINIT) }
}

View File

@ -1,64 +1,63 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavobjectsplugin.cpp * @file uavobjectsplugin.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. * @brief
* @brief * @see The GNU Public License (GPL) Version 3
* @see The GNU Public License (GPL) Version 3 * @defgroup uavobjectsplugin
* @defgroup uavobjects_plugin * @{
* @{ *
* *****************************************************************************/
*****************************************************************************/ /*
/* * This program is free software; you can redistribute it and/or modify
* 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
* it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or
* the Free Software Foundation; either version 3 of the License, or * (at your option) any later version.
* (at your option) any later version. *
* * This program is distributed in the hope that it will be useful, but
* This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details.
* for more details. *
* * You should have received a copy of the GNU General Public License along
* 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.,
* with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
*/ #include "uavobjectsplugin.h"
#include "uavobjectsplugin.h" #include "uavobjectsinit.h"
#include "uavobjectsinit.h"
UAVObjectsPlugin::UAVObjectsPlugin()
UAVObjectsPlugin::UAVObjectsPlugin() {
{
}
}
UAVObjectsPlugin::~UAVObjectsPlugin()
UAVObjectsPlugin::~UAVObjectsPlugin() {
{
}
}
void UAVObjectsPlugin::extensionsInitialized()
void UAVObjectsPlugin::extensionsInitialized() {
{
}
}
bool UAVObjectsPlugin::initialize(const QStringList & arguments, QString * errorString)
bool UAVObjectsPlugin::initialize(const QStringList & arguments, QString * errorString) {
{ // Create object manager and expose object
// Create object manager and expose object UAVObjectManager* objMngr = new UAVObjectManager();
UAVObjectManager* objMngr = new UAVObjectManager(); addAutoReleasedObject(objMngr);
addAutoReleasedObject(objMngr); // Initialize UAVObjects
// Initialize UAVObjects UAVObjectsInitialize(objMngr);
UAVObjectsInitialize(objMngr); // Done
// Done Q_UNUSED(arguments);
Q_UNUSED(arguments); Q_UNUSED(errorString);
Q_UNUSED(errorString); return true;
return true; }
}
void UAVObjectsPlugin::shutdown()
void UAVObjectsPlugin::shutdown() {
{
}
}
Q_EXPORT_PLUGIN(UAVObjectsPlugin)
Q_EXPORT_PLUGIN(UAVObjectsPlugin)

View File

@ -1,50 +1,49 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavobjectsplugin.h * @file uavobjectsplugin.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. * @brief
* @brief * @see The GNU Public License (GPL) Version 3
* @see The GNU Public License (GPL) Version 3 * @defgroup uavobjectsplugin
* @defgroup uavobjects_plugin * @{
* @{ *
* *****************************************************************************/
*****************************************************************************/ /*
/* * This program is free software; you can redistribute it and/or modify
* 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
* it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or
* the Free Software Foundation; either version 3 of the License, or * (at your option) any later version.
* (at your option) any later version. *
* * This program is distributed in the hope that it will be useful, but
* This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details.
* for more details. *
* * You should have received a copy of the GNU General Public License along
* 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.,
* with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
*/ #ifndef UAVOBJECTSPLUGIN_H
#ifndef UAVOBJECTSPLUGIN_H #define UAVOBJECTSPLUGIN_H
#define UAVOBJECTSPLUGIN_H
#include "uavobjects_global.h"
#include "uavobjects_global.h" #include <extensionsystem/iplugin.h>
#include <extensionsystem/iplugin.h> #include <QtPlugin>
#include <QtPlugin> #include "uavobjectmanager.h"
#include "uavobjectmanager.h"
class UAVOBJECTS_EXPORT UAVObjectsPlugin:
class UAVOBJECTS_EXPORT UAVObjectsPlugin: public ExtensionSystem::IPlugin
public ExtensionSystem::IPlugin {
{ Q_OBJECT
Q_OBJECT
public:
public: UAVObjectsPlugin();
UAVObjectsPlugin(); ~UAVObjectsPlugin();
~UAVObjectsPlugin();
void extensionsInitialized();
void extensionsInitialized(); bool initialize(const QStringList & arguments, QString * errorString);
bool initialize(const QStringList & arguments, QString * errorString); void shutdown();
void shutdown(); };
};
#endif // UAVOBJECTSPLUGIN_H
#endif // UAVOBJECTSPLUGIN_H

View File

@ -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> <vendor>The OpenPilot Project</vendor>
<copyright>(C) 2010 OpenPilot Project</copyright> <copyright>(C) 2010 OpenPilot Project</copyright>
<license>The GNU Public License (GPL) Version 3</license> <license>The GNU Public License (GPL) Version 3</license>
@ -6,6 +6,6 @@
<url>http://www.openpilot.org</url> <url>http://www.openpilot.org</url>
<dependencyList> <dependencyList>
<dependency name="Core" version="1.0.0"/> <dependency name="Core" version="1.0.0"/>
<dependency name="UAVObjects" version="0.0.1"/> <dependency name="UAVObjects" version="1.0.0"/>
</dependencyList> </dependencyList>
</plugin> </plugin>

View File

@ -1,522 +1,521 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file telemetry.cpp * @file telemetry.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. * @brief
* @brief * @see The GNU Public License (GPL) Version 3
* @see The GNU Public License (GPL) Version 3 * @defgroup uavtalkplugin
* @defgroup * @{
* @{ *
* *****************************************************************************/
*****************************************************************************/ /*
/* * This program is free software; you can redistribute it and/or modify
* 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
* it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or
* the Free Software Foundation; either version 3 of the License, or * (at your option) any later version.
* (at your option) any later version. *
* * This program is distributed in the hope that it will be useful, but
* This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details.
* for more details. *
* * You should have received a copy of the GNU General Public License along
* 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.,
* with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
*/
#include "telemetry.h"
#include "telemetry.h" #include "qxtlogger.h"
#include "qxtlogger.h" #include <QTime>
#include <QTime> #include <QtGlobal>
#include <QtGlobal> #include <stdlib.h>
#include <stdlib.h>
/**
/** * Constructor
* Constructor */
*/ Telemetry::Telemetry(UAVTalk* utalk, UAVObjectManager* objMngr)
Telemetry::Telemetry(UAVTalk* utalk, UAVObjectManager* objMngr) {
{ this->utalk = utalk;
this->utalk = utalk; this->objMngr = objMngr;
this->objMngr = objMngr; mutex = new QMutex(QMutex::Recursive);
mutex = new QMutex(QMutex::Recursive); // Process all objects in the list
// Process all objects in the list QList< QList<UAVObject*> > objs = objMngr->getObjects();
QList< QList<UAVObject*> > objs = objMngr->getObjects(); for (int objidx = 0; objidx < objs.length(); ++objidx)
for (int objidx = 0; objidx < objs.length(); ++objidx) {
{ registerObject(objs[objidx][0]); // we only need to register one instance per object type
registerObject(objs[objidx][0]); // we only need to register one instance per object type }
} // Listen to new object creations
// Listen to new object creations connect(objMngr, SIGNAL(newObject(UAVObject*)), this, SLOT(newObject(UAVObject*)));
connect(objMngr, SIGNAL(newObject(UAVObject*)), this, SLOT(newObject(UAVObject*))); connect(objMngr, SIGNAL(newInstance(UAVObject*)), this, SLOT(newInstance(UAVObject*)));
connect(objMngr, SIGNAL(newInstance(UAVObject*)), this, SLOT(newInstance(UAVObject*))); // Listen to transaction completions
// Listen to transaction completions connect(utalk, SIGNAL(transactionCompleted(UAVObject*)), this, SLOT(transactionCompleted(UAVObject*)));
connect(utalk, SIGNAL(transactionCompleted(UAVObject*)), this, SLOT(transactionCompleted(UAVObject*))); // Get GCS stats object
// Get GCS stats object gcsStatsObj = GCSTelemetryStats::GetInstance(objMngr);
gcsStatsObj = GCSTelemetryStats::GetInstance(objMngr); // Setup transaction timer
// Setup transaction timer transPending = false;
transPending = false; transTimer = new QTimer(this);
transTimer = new QTimer(this); transTimer->stop();
transTimer->stop(); connect(transTimer, SIGNAL(timeout()), this, SLOT(transactionTimeout()));
connect(transTimer, SIGNAL(timeout()), this, SLOT(transactionTimeout())); // Setup and start the periodic timer
// Setup and start the periodic timer timeToNextUpdateMs = 0;
timeToNextUpdateMs = 0; updateTimer = new QTimer(this);
updateTimer = new QTimer(this); connect(updateTimer, SIGNAL(timeout()), this, SLOT(processPeriodicUpdates()));
connect(updateTimer, SIGNAL(timeout()), this, SLOT(processPeriodicUpdates())); updateTimer->start(1000);
updateTimer->start(1000); // Setup and start the stats timer
// Setup and start the stats timer txErrors = 0;
txErrors = 0; txRetries = 0;
txRetries = 0; }
}
/**
/** * Register a new object for periodic updates (if enabled)
* Register a new object for periodic updates (if enabled) */
*/ void Telemetry::registerObject(UAVObject* obj)
void Telemetry::registerObject(UAVObject* obj) {
{ // Setup object for periodic updates
// Setup object for periodic updates addObject(obj);
addObject(obj);
// Setup object for telemetry updates
// Setup object for telemetry updates updateObject(obj);
updateObject(obj); }
}
/**
/** * Add an object in the list used for periodic updates
* Add an object in the list used for periodic updates */
*/ void Telemetry::addObject(UAVObject* obj)
void Telemetry::addObject(UAVObject* obj) {
{ // Check if object type is already in the list
// Check if object type is already in the list for (int n = 0; n < objList.length(); ++n)
for (int n = 0; n < objList.length(); ++n) {
{ if ( objList[n].obj->getObjID() == obj->getObjID() )
if ( objList[n].obj->getObjID() == obj->getObjID() ) {
{ // Object type (not instance!) is already in the list, do nothing
// Object type (not instance!) is already in the list, do nothing return;
return; }
} }
}
// If this point is reached, then the object type is new, let's add it
// If this point is reached, then the object type is new, let's add it ObjectTimeInfo timeInfo;
ObjectTimeInfo timeInfo; timeInfo.obj = obj;
timeInfo.obj = obj; timeInfo.timeToNextUpdateMs = 0;
timeInfo.timeToNextUpdateMs = 0; timeInfo.updatePeriodMs = 0;
timeInfo.updatePeriodMs = 0; objList.append(timeInfo);
objList.append(timeInfo); }
}
/**
/** * Update the object's timers
* Update the object's timers */
*/ void Telemetry::setUpdatePeriod(UAVObject* obj, qint32 periodMs)
void Telemetry::setUpdatePeriod(UAVObject* obj, qint32 periodMs) {
{ // Find object type (not instance!) and update its period
// Find object type (not instance!) and update its period for (int n = 0; n < objList.length(); ++n)
for (int n = 0; n < objList.length(); ++n) {
{ if ( objList[n].obj->getObjID() == obj->getObjID() )
if ( objList[n].obj->getObjID() == obj->getObjID() ) {
{ objList[n].updatePeriodMs = periodMs;
objList[n].updatePeriodMs = periodMs; objList[n].timeToNextUpdateMs = quint32((float)periodMs * (float)qrand() / (float)RAND_MAX); // avoid bunching of updates
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
* Connect to all instances of an object depending on the event mask specified */
*/ void Telemetry::connectToObjectInstances(UAVObject* obj, quint32 eventMask)
void Telemetry::connectToObjectInstances(UAVObject* obj, quint32 eventMask) {
{ QList<UAVObject*> objs = objMngr->getObjectInstances(obj->getObjID());
QList<UAVObject*> objs = objMngr->getObjectInstances(obj->getObjID()); for (int n = 0; n < objs.length(); ++n)
for (int n = 0; n < objs.length(); ++n) {
{ // Disconnect all
// Disconnect all objs[n]->disconnect(this);
objs[n]->disconnect(this); // Connect only the selected events
// Connect only the selected events if ( (eventMask&EV_UNPACKED) != 0)
if ( (eventMask&EV_UNPACKED) != 0) {
{ connect(objs[n], SIGNAL(objectUnpacked(UAVObject*)), this, SLOT(objectUnpacked(UAVObject*)));
connect(objs[n], SIGNAL(objectUnpacked(UAVObject*)), this, SLOT(objectUnpacked(UAVObject*))); }
} if ( (eventMask&EV_UPDATED) != 0)
if ( (eventMask&EV_UPDATED) != 0) {
{ connect(objs[n], SIGNAL(objectUpdatedAuto(UAVObject*)), this, SLOT(objectUpdatedAuto(UAVObject*)));
connect(objs[n], SIGNAL(objectUpdatedAuto(UAVObject*)), this, SLOT(objectUpdatedAuto(UAVObject*))); }
} if ( (eventMask&EV_UPDATED_MANUAL) != 0)
if ( (eventMask&EV_UPDATED_MANUAL) != 0) {
{ connect(objs[n], SIGNAL(objectUpdatedManual(UAVObject*)), this, SLOT(objectUpdatedManual(UAVObject*)));
connect(objs[n], SIGNAL(objectUpdatedManual(UAVObject*)), this, SLOT(objectUpdatedManual(UAVObject*))); }
} if ( (eventMask&EV_UPDATE_REQ) != 0)
if ( (eventMask&EV_UPDATE_REQ) != 0) {
{ connect(objs[n], SIGNAL(updateRequested(UAVObject*)), this, SLOT(updateRequested(UAVObject*)));
connect(objs[n], SIGNAL(updateRequested(UAVObject*)), this, SLOT(updateRequested(UAVObject*))); }
} }
} }
}
/**
/** * Update an object based on its metadata properties
* Update an object based on its metadata properties */
*/ void Telemetry::updateObject(UAVObject* obj)
void Telemetry::updateObject(UAVObject* obj) {
{ // Get metadata
// Get metadata UAVObject::Metadata metadata = obj->getMetadata();
UAVObject::Metadata metadata = obj->getMetadata();
// Setup object depending on update mode
// Setup object depending on update mode qint32 eventMask;
qint32 eventMask; if ( metadata.gcsTelemetryUpdateMode == UAVObject::UPDATEMODE_PERIODIC )
if ( metadata.gcsTelemetryUpdateMode == UAVObject::UPDATEMODE_PERIODIC ) {
{ // Set update period
// Set update period setUpdatePeriod(obj, metadata.gcsTelemetryUpdatePeriod);
setUpdatePeriod(obj, metadata.gcsTelemetryUpdatePeriod); // Connect signals for all instances
// Connect signals for all instances eventMask = EV_UPDATED_MANUAL | EV_UPDATE_REQ;
eventMask = EV_UPDATED_MANUAL | EV_UPDATE_REQ; if( dynamic_cast<UAVMetaObject*>(obj) != NULL )
if( dynamic_cast<UAVMetaObject*>(obj) != NULL ) {
{ eventMask |= EV_UNPACKED; // we also need to act on remote updates (unpack events)
eventMask |= EV_UNPACKED; // we also need to act on remote updates (unpack events) }
} connectToObjectInstances(obj, eventMask);
connectToObjectInstances(obj, eventMask); }
} else if ( metadata.gcsTelemetryUpdateMode == UAVObject::UPDATEMODE_ONCHANGE )
else if ( metadata.gcsTelemetryUpdateMode == UAVObject::UPDATEMODE_ONCHANGE ) {
{ // Set update period
// Set update period setUpdatePeriod(obj, 0);
setUpdatePeriod(obj, 0); // Connect signals for all instances
// Connect signals for all instances eventMask = EV_UPDATED | EV_UPDATED_MANUAL | EV_UPDATE_REQ;
eventMask = EV_UPDATED | EV_UPDATED_MANUAL | EV_UPDATE_REQ; if( dynamic_cast<UAVMetaObject*>(obj) != NULL )
if( dynamic_cast<UAVMetaObject*>(obj) != NULL ) {
{ eventMask |= EV_UNPACKED; // we also need to act on remote updates (unpack events)
eventMask |= EV_UNPACKED; // we also need to act on remote updates (unpack events) }
} connectToObjectInstances(obj, eventMask);
connectToObjectInstances(obj, eventMask); }
} else if ( metadata.gcsTelemetryUpdateMode == UAVObject::UPDATEMODE_MANUAL )
else if ( metadata.gcsTelemetryUpdateMode == UAVObject::UPDATEMODE_MANUAL ) {
{ // Set update period
// Set update period setUpdatePeriod(obj, 0);
setUpdatePeriod(obj, 0); // Connect signals for all instances
// Connect signals for all instances eventMask = EV_UPDATED_MANUAL | EV_UPDATE_REQ;
eventMask = EV_UPDATED_MANUAL | EV_UPDATE_REQ; if( dynamic_cast<UAVMetaObject*>(obj) != NULL )
if( dynamic_cast<UAVMetaObject*>(obj) != NULL ) {
{ eventMask |= EV_UNPACKED; // we also need to act on remote updates (unpack events)
eventMask |= EV_UNPACKED; // we also need to act on remote updates (unpack events) }
} connectToObjectInstances(obj, eventMask);
connectToObjectInstances(obj, eventMask); }
} else if ( metadata.gcsTelemetryUpdateMode == UAVObject::UPDATEMODE_NEVER )
else if ( metadata.gcsTelemetryUpdateMode == UAVObject::UPDATEMODE_NEVER ) {
{ // Set update period
// Set update period setUpdatePeriod(obj, 0);
setUpdatePeriod(obj, 0); // Disconnect from object
// Disconnect from object connectToObjectInstances(obj, 0);
connectToObjectInstances(obj, 0); }
} }
}
/**
/** * Called when a transaction is successfully completed (uavtalk event)
* Called when a transaction is successfully completed (uavtalk event) */
*/ void Telemetry::transactionCompleted(UAVObject* obj)
void Telemetry::transactionCompleted(UAVObject* obj) {
{ // Check if there is a pending transaction and the objects match
// Check if there is a pending transaction and the objects match if ( transPending && transInfo.obj->getObjID() == obj->getObjID() )
if ( transPending && transInfo.obj->getObjID() == obj->getObjID() ) {
{ // Send signal
// Send signal obj->emitTransactionCompleted(true);
obj->emitTransactionCompleted(true); // Complete transaction
// Complete transaction transTimer->stop();
transTimer->stop(); transPending = false;
transPending = false; // Process new object updates from queue
// Process new object updates from queue processObjectQueue();
processObjectQueue(); }
} }
}
/**
/** * Called when a transaction is not completed within the timeout period (timer event)
* Called when a transaction is not completed within the timeout period (timer event) */
*/ void Telemetry::transactionTimeout()
void Telemetry::transactionTimeout() {
{ transTimer->stop();
transTimer->stop(); // Proceed only if there is a pending transaction
// Proceed only if there is a pending transaction if ( transPending )
if ( transPending ) {
{ // Check if more retries are pending
// Check if more retries are pending if (transInfo.retriesRemaining > 0)
if (transInfo.retriesRemaining > 0) {
{ --transInfo.retriesRemaining;
--transInfo.retriesRemaining; processObjectTransaction();
processObjectTransaction(); ++txRetries;
++txRetries; }
} else
else {
{ // Send signal
// Send signal transInfo.obj->emitTransactionCompleted(false);
transInfo.obj->emitTransactionCompleted(false); // Terminate transaction
// Terminate transaction utalk->cancelTransaction();
utalk->cancelTransaction(); transPending = false;
transPending = false; // Process new object updates from queue
// Process new object updates from queue processObjectQueue();
processObjectQueue(); ++txErrors;
++txErrors; }
} }
} }
}
/**
/** * Start an object transaction with UAVTalk, all information is stored in transInfo
* Start an object transaction with UAVTalk, all information is stored in transInfo */
*/ void Telemetry::processObjectTransaction()
void Telemetry::processObjectTransaction() {
{ if (transPending)
if (transPending) {
{ // Initiate transaction
// Initiate transaction if (transInfo.objRequest)
if (transInfo.objRequest) {
{ utalk->sendObjectRequest(transInfo.obj, transInfo.allInstances);
utalk->sendObjectRequest(transInfo.obj, transInfo.allInstances); }
} else
else {
{ utalk->sendObject(transInfo.obj, transInfo.acked, transInfo.allInstances);
utalk->sendObject(transInfo.obj, transInfo.acked, transInfo.allInstances); }
} // Start timer if a response is expected
// Start timer if a response is expected if ( transInfo.objRequest || transInfo.acked )
if ( transInfo.objRequest || transInfo.acked ) {
{ transTimer->start(REQ_TIMEOUT_MS);
transTimer->start(REQ_TIMEOUT_MS); }
} else
else {
{ transTimer->stop();
transTimer->stop(); transPending = false;
transPending = false; }
} }
} }
}
/**
/** * Process the event received from an object
* Process the event received from an object */
*/ void Telemetry::processObjectUpdates(UAVObject* obj, EventMask event, bool allInstances, bool priority)
void Telemetry::processObjectUpdates(UAVObject* obj, EventMask event, bool allInstances, bool priority) {
{ // Push event into queue
// Push event into queue ObjectQueueInfo objInfo;
ObjectQueueInfo objInfo; objInfo.obj = obj;
objInfo.obj = obj; objInfo.event = event;
objInfo.event = event; objInfo.allInstances = allInstances;
objInfo.allInstances = allInstances; if (priority)
if (priority) {
{ if ( objPriorityQueue.length() < MAX_QUEUE_SIZE )
if ( objPriorityQueue.length() < MAX_QUEUE_SIZE ) {
{ objPriorityQueue.enqueue(objInfo);
objPriorityQueue.enqueue(objInfo); }
} else
else {
{ ++txErrors;
++txErrors; obj->emitTransactionCompleted(false);
obj->emitTransactionCompleted(false); qxtLog->warning(tr("Telemetry: priority event queue is full, event lost (%1)").arg(obj->getName()));
qxtLog->warning(tr("Telemetry: priority event queue is full, event lost (%1)").arg(obj->getName())); }
} }
} else
else {
{ if ( objQueue.length() < MAX_QUEUE_SIZE )
if ( objQueue.length() < MAX_QUEUE_SIZE ) {
{ objQueue.enqueue(objInfo);
objQueue.enqueue(objInfo); }
} else
else {
{ ++txErrors;
++txErrors; obj->emitTransactionCompleted(false);
obj->emitTransactionCompleted(false); }
} }
}
// If there is no transaction in progress then process event
// If there is no transaction in progress then process event if (!transPending)
if (!transPending) {
{ processObjectQueue();
processObjectQueue(); }
} }
}
/**
/** * Process events from the object queue
* Process events from the object queue */
*/ void Telemetry::processObjectQueue()
void Telemetry::processObjectQueue() {
{ // Don nothing if a transaction is already in progress (should not happen)
// Don nothing if a transaction is already in progress (should not happen) if (transPending)
if (transPending) {
{ qxtLog->error("Telemetry: Dequeue while a transaction pending!");
qxtLog->error("Telemetry: Dequeue while a transaction pending!"); return;
return; }
}
// Get object information from queue (first the priority and then the regular queue)
// Get object information from queue (first the priority and then the regular queue) ObjectQueueInfo objInfo;
ObjectQueueInfo objInfo; if ( !objPriorityQueue.isEmpty() )
if ( !objPriorityQueue.isEmpty() ) {
{ objInfo = objPriorityQueue.dequeue();
objInfo = objPriorityQueue.dequeue(); }
} else if ( !objQueue.isEmpty() )
else if ( !objQueue.isEmpty() ) {
{ objInfo = objQueue.dequeue();
objInfo = objQueue.dequeue(); }
} else
else {
{ return;
return; }
}
// Check if a connection has been established, only process GCSTelemetryStats updates
// Check if a connection has been established, only process GCSTelemetryStats updates // (used to establish the connection)
// (used to establish the connection) GCSTelemetryStats::DataFields gcsStats = gcsStatsObj->getData();
GCSTelemetryStats::DataFields gcsStats = gcsStatsObj->getData(); if ( gcsStats.Status != GCSTelemetryStats::STATUS_CONNECTED )
if ( gcsStats.Status != GCSTelemetryStats::STATUS_CONNECTED ) {
{ objQueue.clear();
objQueue.clear(); if ( objInfo.obj->getObjID() != GCSTelemetryStats::OBJID )
if ( objInfo.obj->getObjID() != GCSTelemetryStats::OBJID ) {
{ objInfo.obj->emitTransactionCompleted(false);
objInfo.obj->emitTransactionCompleted(false); return;
return; }
} }
}
// Setup transaction (skip if unpack event)
// Setup transaction (skip if unpack event) if ( objInfo.event != EV_UNPACKED )
if ( objInfo.event != EV_UNPACKED ) {
{ UAVObject::Metadata metadata = objInfo.obj->getMetadata();
UAVObject::Metadata metadata = objInfo.obj->getMetadata(); transInfo.obj = objInfo.obj;
transInfo.obj = objInfo.obj; transInfo.allInstances = objInfo.allInstances;
transInfo.allInstances = objInfo.allInstances; transInfo.retriesRemaining = MAX_RETRIES;
transInfo.retriesRemaining = MAX_RETRIES; transInfo.acked = metadata.gcsTelemetryAcked;
transInfo.acked = metadata.gcsTelemetryAcked; if ( objInfo.event == EV_UPDATED || objInfo.event == EV_UPDATED_MANUAL )
if ( objInfo.event == EV_UPDATED || objInfo.event == EV_UPDATED_MANUAL ) {
{ transInfo.objRequest = false;
transInfo.objRequest = false; }
} else if ( objInfo.event == EV_UPDATE_REQ )
else if ( objInfo.event == EV_UPDATE_REQ ) {
{ transInfo.objRequest = true;
transInfo.objRequest = true; }
} // Start transaction
// Start transaction transPending = true;
transPending = true; processObjectTransaction();
processObjectTransaction(); }
}
// If this is a metaobject then make necessary telemetry updates
// If this is a metaobject then make necessary telemetry updates UAVMetaObject* metaobj = dynamic_cast<UAVMetaObject*>(objInfo.obj);
UAVMetaObject* metaobj = dynamic_cast<UAVMetaObject*>(objInfo.obj); if ( metaobj != NULL )
if ( metaobj != NULL ) {
{ updateObject( metaobj->getParentObject() );
updateObject( metaobj->getParentObject() ); }
} }
}
/**
/** * Check is any objects are pending for periodic updates
* Check is any objects are pending for periodic updates * TODO: Clean-up
* TODO: Clean-up */
*/ void Telemetry::processPeriodicUpdates()
void Telemetry::processPeriodicUpdates() {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex);
// Stop timer
// Stop timer updateTimer->stop();
updateTimer->stop();
// Iterate through each object and update its timer, if zero then transmit object.
// 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)
// Also calculate smallest delay to next update (will be used for setting timeToNextUpdateMs) qint32 minDelay = MAX_UPDATE_PERIOD_MS;
qint32 minDelay = MAX_UPDATE_PERIOD_MS; ObjectTimeInfo objinfo;
ObjectTimeInfo objinfo; qint32 elapsedMs = 0;
qint32 elapsedMs = 0; QTime time;
QTime time; for (int n = 0; n < objList.length(); ++n)
for (int n = 0; n < objList.length(); ++n) {
{ objinfo = objList[n];
objinfo = objList[n]; // If object is configured for periodic updates
// If object is configured for periodic updates if (objinfo.updatePeriodMs > 0)
if (objinfo.updatePeriodMs > 0) {
{ objinfo.timeToNextUpdateMs -= timeToNextUpdateMs;
objinfo.timeToNextUpdateMs -= timeToNextUpdateMs; // Check if time for the next update
// Check if time for the next update if (objinfo.timeToNextUpdateMs <= 0)
if (objinfo.timeToNextUpdateMs <= 0) {
{ // Reset timer
// Reset timer objinfo.timeToNextUpdateMs = objinfo.updatePeriodMs;
objinfo.timeToNextUpdateMs = objinfo.updatePeriodMs; // Send object
// Send object time.start();
time.start(); processObjectUpdates(objinfo.obj, EV_UPDATED_MANUAL, true, false);
processObjectUpdates(objinfo.obj, EV_UPDATED_MANUAL, true, false); elapsedMs = time.elapsed();
elapsedMs = time.elapsed(); // Update timeToNextUpdateMs with the elapsed delay of sending the object;
// Update timeToNextUpdateMs with the elapsed delay of sending the object; timeToNextUpdateMs += elapsedMs;
timeToNextUpdateMs += elapsedMs; }
} // Update minimum delay
// Update minimum delay if (objinfo.timeToNextUpdateMs < minDelay)
if (objinfo.timeToNextUpdateMs < minDelay) {
{ minDelay = objinfo.timeToNextUpdateMs;
minDelay = objinfo.timeToNextUpdateMs; }
} }
} }
}
// Check if delay for the next update is too short
// Check if delay for the next update is too short if (minDelay < MIN_UPDATE_PERIOD_MS)
if (minDelay < MIN_UPDATE_PERIOD_MS) {
{ minDelay = MIN_UPDATE_PERIOD_MS;
minDelay = MIN_UPDATE_PERIOD_MS; }
}
// Done
// Done timeToNextUpdateMs = minDelay;
timeToNextUpdateMs = minDelay;
// Restart timer
// Restart timer updateTimer->start(timeToNextUpdateMs);
updateTimer->start(timeToNextUpdateMs); }
}
Telemetry::TelemetryStats Telemetry::getStats()
Telemetry::TelemetryStats Telemetry::getStats() {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex);
// Get UAVTalk stats
// Get UAVTalk stats UAVTalk::ComStats utalkStats = utalk->getStats();
UAVTalk::ComStats utalkStats = utalk->getStats();
// Update stats
// Update stats TelemetryStats stats;
TelemetryStats stats; stats.txBytes = utalkStats.txBytes;
stats.txBytes = utalkStats.txBytes; stats.rxBytes = utalkStats.rxBytes;
stats.rxBytes = utalkStats.rxBytes; stats.txObjectBytes = utalkStats.txObjectBytes;
stats.txObjectBytes = utalkStats.txObjectBytes; stats.rxObjectBytes = utalkStats.rxObjectBytes;
stats.rxObjectBytes = utalkStats.rxObjectBytes; stats.rxObjects = utalkStats.rxObjects;
stats.rxObjects = utalkStats.rxObjects; stats.txObjects = utalkStats.txObjects;
stats.txObjects = utalkStats.txObjects; stats.txErrors = utalkStats.txErrors + txErrors;
stats.txErrors = utalkStats.txErrors + txErrors; stats.rxErrors = utalkStats.rxErrors;
stats.rxErrors = utalkStats.rxErrors; stats.txRetries = txRetries;
stats.txRetries = txRetries;
// Done
// Done return stats;
return stats; }
}
void Telemetry::resetStats()
void Telemetry::resetStats() {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); utalk->resetStats();
utalk->resetStats(); txErrors = 0;
txErrors = 0; txRetries = 0;
txRetries = 0; }
}
void Telemetry::objectUpdatedAuto(UAVObject* obj)
void Telemetry::objectUpdatedAuto(UAVObject* obj) {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); processObjectUpdates(obj, EV_UPDATED, false, true);
processObjectUpdates(obj, EV_UPDATED, false, true); }
}
void Telemetry::objectUpdatedManual(UAVObject* obj)
void Telemetry::objectUpdatedManual(UAVObject* obj) {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); processObjectUpdates(obj, EV_UPDATED_MANUAL, false, true);
processObjectUpdates(obj, EV_UPDATED_MANUAL, false, true); }
}
void Telemetry::objectUnpacked(UAVObject* obj)
void Telemetry::objectUnpacked(UAVObject* obj) {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); processObjectUpdates(obj, EV_UNPACKED, false, true);
processObjectUpdates(obj, EV_UNPACKED, false, true); }
}
void Telemetry::updateRequested(UAVObject* obj)
void Telemetry::updateRequested(UAVObject* obj) {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); processObjectUpdates(obj, EV_UPDATE_REQ, false, true);
processObjectUpdates(obj, EV_UPDATE_REQ, false, true); }
}
void Telemetry::newObject(UAVObject* obj)
void Telemetry::newObject(UAVObject* obj) {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); registerObject(obj);
registerObject(obj); }
}
void Telemetry::newInstance(UAVObject* obj)
void Telemetry::newInstance(UAVObject* obj) {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); registerObject(obj);
registerObject(obj); }
}

View File

@ -1,144 +1,143 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file telemetry.h * @file telemetry.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. * @brief
* @brief * @see The GNU Public License (GPL) Version 3
* @see The GNU Public License (GPL) Version 3 * @defgroup uavtalkplugin
* @defgroup * @{
* @{ *
* *****************************************************************************/
*****************************************************************************/ /*
/* * This program is free software; you can redistribute it and/or modify
* 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
* it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or
* the Free Software Foundation; either version 3 of the License, or * (at your option) any later version.
* (at your option) any later version. *
* * This program is distributed in the hope that it will be useful, but
* This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details.
* for more details. *
* * You should have received a copy of the GNU General Public License along
* 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.,
* with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
*/
#ifndef TELEMETRY_H
#ifndef TELEMETRY_H #define TELEMETRY_H
#define TELEMETRY_H
#include "uavtalk.h"
#include "uavtalk.h" #include "uavobjects/uavobjectmanager.h"
#include "uavobjects/uavobjectmanager.h" #include "uavobjects/gcstelemetrystats.h"
#include "uavobjects/gcstelemetrystats.h" #include <QMutex>
#include <QMutex> #include <QMutexLocker>
#include <QMutexLocker> #include <QTimer>
#include <QTimer> #include <QQueue>
#include <QQueue>
class Telemetry: public QObject
class Telemetry: public QObject {
{ Q_OBJECT
Q_OBJECT
public:
public: typedef struct {
typedef struct { quint32 txBytes;
quint32 txBytes; quint32 rxBytes;
quint32 rxBytes; quint32 txObjectBytes;
quint32 txObjectBytes; quint32 rxObjectBytes;
quint32 rxObjectBytes; quint32 rxObjects;
quint32 rxObjects; quint32 txObjects;
quint32 txObjects; quint32 txErrors;
quint32 txErrors; quint32 rxErrors;
quint32 rxErrors; quint32 txRetries;
quint32 txRetries; } TelemetryStats;
} TelemetryStats;
Telemetry(UAVTalk* utalk, UAVObjectManager* objMngr);
Telemetry(UAVTalk* utalk, UAVObjectManager* objMngr); TelemetryStats getStats();
TelemetryStats getStats(); void resetStats();
void resetStats();
signals:
signals:
private slots:
private slots: void objectUpdatedAuto(UAVObject* obj);
void objectUpdatedAuto(UAVObject* obj); void objectUpdatedManual(UAVObject* obj);
void objectUpdatedManual(UAVObject* obj); void objectUnpacked(UAVObject* obj);
void objectUnpacked(UAVObject* obj); void updateRequested(UAVObject* obj);
void updateRequested(UAVObject* obj); void newObject(UAVObject* obj);
void newObject(UAVObject* obj); void newInstance(UAVObject* obj);
void newInstance(UAVObject* obj); void processPeriodicUpdates();
void processPeriodicUpdates(); void transactionCompleted(UAVObject* obj);
void transactionCompleted(UAVObject* obj); void transactionTimeout();
void transactionTimeout();
private:
private: // Constants
// Constants static const int REQ_TIMEOUT_MS = 250;
static const int REQ_TIMEOUT_MS = 250; static const int MAX_RETRIES = 2;
static const int MAX_RETRIES = 2; static const int MAX_UPDATE_PERIOD_MS = 1000;
static const int MAX_UPDATE_PERIOD_MS = 1000; static const int MIN_UPDATE_PERIOD_MS = 1;
static const int MIN_UPDATE_PERIOD_MS = 1; static const int MAX_QUEUE_SIZE = 20;
static const int MAX_QUEUE_SIZE = 20;
// Types
// Types /**
/** * Events generated by objects
* Events generated by objects */
*/ typedef enum {
typedef enum { EV_UNPACKED = 0x01, /** Object data updated by unpacking */
EV_UNPACKED = 0x01, /** Object data updated by unpacking */ EV_UPDATED = 0x02, /** Object data updated by changing the data structure */
EV_UPDATED = 0x02, /** Object data updated by changing the data structure */ EV_UPDATED_MANUAL = 0x04, /** Object update event manually generated */
EV_UPDATED_MANUAL = 0x04, /** Object update event manually generated */ EV_UPDATE_REQ = 0x08 /** Request to update object data */
EV_UPDATE_REQ = 0x08 /** Request to update object data */ } EventMask;
} EventMask;
typedef struct {
typedef struct { UAVObject* obj;
UAVObject* obj; qint32 updatePeriodMs; /** Update period in ms or 0 if no periodic updates are needed */
qint32 updatePeriodMs; /** Update period in ms or 0 if no periodic updates are needed */ qint32 timeToNextUpdateMs; /** Time delay to the next update */
qint32 timeToNextUpdateMs; /** Time delay to the next update */ } ObjectTimeInfo;
} ObjectTimeInfo;
typedef struct {
typedef struct { UAVObject* obj;
UAVObject* obj; EventMask event;
EventMask event; bool allInstances;
bool allInstances; } ObjectQueueInfo;
} ObjectQueueInfo;
typedef struct {
typedef struct { UAVObject* obj;
UAVObject* obj; bool allInstances;
bool allInstances; bool objRequest;
bool objRequest; qint32 retriesRemaining;
qint32 retriesRemaining; bool acked;
bool acked; } ObjectTransactionInfo;
} ObjectTransactionInfo;
// Variables
// Variables UAVObjectManager* objMngr;
UAVObjectManager* objMngr; UAVTalk* utalk;
UAVTalk* utalk; GCSTelemetryStats* gcsStatsObj;
GCSTelemetryStats* gcsStatsObj; QList<ObjectTimeInfo> objList;
QList<ObjectTimeInfo> objList; QQueue<ObjectQueueInfo> objQueue;
QQueue<ObjectQueueInfo> objQueue; QQueue<ObjectQueueInfo> objPriorityQueue;
QQueue<ObjectQueueInfo> objPriorityQueue; ObjectTransactionInfo transInfo;
ObjectTransactionInfo transInfo; bool transPending;
bool transPending; QMutex* mutex;
QMutex* mutex; QTimer* updateTimer;
QTimer* updateTimer; QTimer* transTimer;
QTimer* transTimer; QTimer* statsTimer;
QTimer* statsTimer; qint32 timeToNextUpdateMs;
qint32 timeToNextUpdateMs; quint32 txErrors;
quint32 txErrors; quint32 txRetries;
quint32 txRetries;
// Methods
// Methods void registerObject(UAVObject* obj);
void registerObject(UAVObject* obj); void addObject(UAVObject* obj);
void addObject(UAVObject* obj); void setUpdatePeriod(UAVObject* obj, qint32 periodMs);
void setUpdatePeriod(UAVObject* obj, qint32 periodMs); void connectToObjectInstances(UAVObject* obj, quint32 eventMask);
void connectToObjectInstances(UAVObject* obj, quint32 eventMask); void updateObject(UAVObject* obj);
void updateObject(UAVObject* obj); void processObjectUpdates(UAVObject* obj, EventMask event, bool allInstances, bool priority);
void processObjectUpdates(UAVObject* obj, EventMask event, bool allInstances, bool priority); void processObjectTransaction();
void processObjectTransaction(); void processObjectQueue();
void processObjectQueue();
};
};
#endif // TELEMETRY_H
#endif // TELEMETRY_H

View File

@ -3,10 +3,9 @@
* *
* @file telemetrymanager.cpp * @file telemetrymanager.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup * @defgroup uavtalkplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/

View File

@ -3,10 +3,9 @@
* *
* @file telemetrymanager.cpp * @file telemetrymanager.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup * @defgroup uavtalkplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/

View File

@ -3,10 +3,9 @@
* *
* @file telemetrymonitor.cpp * @file telemetrymonitor.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup * @defgroup uavtalkplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/

View File

@ -3,10 +3,9 @@
* *
* @file telemetrymonitor.cpp * @file telemetrymonitor.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup * @defgroup uavtalkplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/

View File

@ -1,646 +1,645 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavtalk.cpp * @file uavtalk.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. * @brief
* @brief * @see The GNU Public License (GPL) Version 3
* @see The GNU Public License (GPL) Version 3 * @defgroup uavtalkplugin
* @defgroup * @{
* @{ *
* *****************************************************************************/
*****************************************************************************/ /*
/* * This program is free software; you can redistribute it and/or modify
* 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
* it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or
* the Free Software Foundation; either version 3 of the License, or * (at your option) any later version.
* (at your option) any later version. *
* * This program is distributed in the hope that it will be useful, but
* This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details.
* for more details. *
* * You should have received a copy of the GNU General Public License along
* 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.,
* with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
*/ #include "uavtalk.h"
#include "uavtalk.h" #include <QtEndian>
#include <QtEndian>
const quint8 UAVTalk::crc_table[256] = {
const quint8 UAVTalk::crc_table[256] = { 0x00, 0x07, 0x0e, 0x09, 0x1c, 0x1b, 0x12, 0x15, 0x38, 0x3f, 0x36, 0x31, 0x24, 0x23, 0x2a, 0x2d,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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
0xde, 0xd9, 0xd0, 0xd7, 0xc2, 0xc5, 0xcc, 0xcb, 0xe6, 0xe1, 0xe8, 0xef, 0xfa, 0xfd, 0xf4, 0xf3 };
};
/**
/** * Constructor
* Constructor */
*/ UAVTalk::UAVTalk(QIODevice* iodev, UAVObjectManager* objMngr)
UAVTalk::UAVTalk(QIODevice* iodev, UAVObjectManager* objMngr) {
{ io = iodev;
io = iodev; this->objMngr = objMngr;
this->objMngr = objMngr; rxState = STATE_SYNC;
rxState = STATE_SYNC; mutex = new QMutex(QMutex::Recursive);
mutex = new QMutex(QMutex::Recursive); respObj = NULL;
respObj = NULL; memset(&stats, 0, sizeof(ComStats));
memset(&stats, 0, sizeof(ComStats)); connect(io, SIGNAL(readyRead()), this, SLOT(processInputStream()));
connect(io, SIGNAL(readyRead()), this, SLOT(processInputStream())); }
}
/**
/** * Reset the statistics counters
* Reset the statistics counters */
*/ void UAVTalk::resetStats()
void UAVTalk::resetStats() {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); memset(&stats, 0, sizeof(ComStats));
memset(&stats, 0, sizeof(ComStats)); }
}
/**
/** * Get the statistics counters
* Get the statistics counters */
*/ UAVTalk::ComStats UAVTalk::getStats()
UAVTalk::ComStats UAVTalk::getStats() {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); return stats;
return stats; }
}
/**
/** * Called each time there are data in the input buffer
* Called each time there are data in the input buffer */
*/ void UAVTalk::processInputStream()
void UAVTalk::processInputStream() {
{ quint8 tmp;
quint8 tmp;
while (io->bytesAvailable() > 0)
while (io->bytesAvailable() > 0) {
{ io->read((char*)&tmp, 1);
io->read((char*)&tmp, 1); processInputByte(tmp);
processInputByte(tmp); }
} }
}
/**
/** * Request an update for the specified object, on success the object data would have been
* Request an update for the specified object, on success the object data would have been * updated by the GCS.
* updated by the GCS. * \param[in] obj Object to update
* \param[in] obj Object to update * \param[in] allInstances If set true then all instances will be updated
* \param[in] allInstances If set true then all instances will be updated * \return Success (true), Failure (false)
* \return Success (true), Failure (false) */
*/ bool UAVTalk::sendObjectRequest(UAVObject* obj, bool allInstances)
bool UAVTalk::sendObjectRequest(UAVObject* obj, bool allInstances) {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); return objectTransaction(obj, TYPE_OBJ_REQ, allInstances);
return objectTransaction(obj, TYPE_OBJ_REQ, allInstances); }
}
/**
/** * Send the specified object through the telemetry link.
* Send the specified object through the telemetry link. * \param[in] obj Object to send
* \param[in] obj Object to send * \param[in] acked Selects if an ack is required
* \param[in] acked Selects if an ack is required * \param[in] allInstances If set true then all instances will be updated
* \param[in] allInstances If set true then all instances will be updated * \return Success (true), Failure (false)
* \return Success (true), Failure (false) */
*/ bool UAVTalk::sendObject(UAVObject* obj, bool acked, bool allInstances)
bool UAVTalk::sendObject(UAVObject* obj, bool acked, bool allInstances) {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); if (acked)
if (acked) {
{ return objectTransaction(obj, TYPE_OBJ_ACK, allInstances);
return objectTransaction(obj, TYPE_OBJ_ACK, allInstances); }
} else
else {
{ return objectTransaction(obj, TYPE_OBJ, allInstances);
return objectTransaction(obj, TYPE_OBJ, allInstances); }
} }
}
/**
/** * Cancel a pending transaction
* Cancel a pending transaction */
*/ void UAVTalk::cancelTransaction()
void UAVTalk::cancelTransaction() {
{ QMutexLocker locker(mutex);
QMutexLocker locker(mutex); respObj = NULL;
respObj = NULL; }
}
/**
/** * Execute the requested transaction on an object.
* Execute the requested transaction on an object. * \param[in] obj Object
* \param[in] obj Object * \param[in] type Transaction type
* \param[in] type Transaction type * TYPE_OBJ: send object,
* TYPE_OBJ: send object, * TYPE_OBJ_REQ: request object update
* TYPE_OBJ_REQ: request object update * TYPE_OBJ_ACK: send object with an ack
* TYPE_OBJ_ACK: send object with an ack * \param[in] allInstances If set true then all instances will be updated
* \param[in] allInstances If set true then all instances will be updated * \return Success (true), Failure (false)
* \return Success (true), Failure (false) */
*/ bool UAVTalk::objectTransaction(UAVObject* obj, quint8 type, bool allInstances)
bool UAVTalk::objectTransaction(UAVObject* obj, quint8 type, bool allInstances) {
{ // Send object depending on if a response is needed
// Send object depending on if a response is needed if (type == TYPE_OBJ_ACK || type == TYPE_OBJ_REQ)
if (type == TYPE_OBJ_ACK || type == TYPE_OBJ_REQ) {
{ if ( transmitObject(obj, type, allInstances) )
if ( transmitObject(obj, type, allInstances) ) {
{ respObj = obj;
respObj = obj; respAllInstances = allInstances;
respAllInstances = allInstances; return true;
return true; }
} else
else {
{ return false;
return false; }
} }
} else if (type == TYPE_OBJ)
else if (type == TYPE_OBJ) {
{ return transmitObject(obj, TYPE_OBJ, allInstances);
return transmitObject(obj, TYPE_OBJ, allInstances); }
} else
else {
{ return false;
return false; }
} }
}
/**
/** * Process an byte from the telemetry stream.
* Process an byte from the telemetry stream. * \param[in] rxbyte Received byte
* \param[in] rxbyte Received byte * \return Success (true), Failure (false)
* \return Success (true), Failure (false) */
*/ bool UAVTalk::processInputByte(quint8 rxbyte)
bool UAVTalk::processInputByte(quint8 rxbyte) {
{ // Update stats
// Update stats ++stats.rxBytes;
++stats.rxBytes; // Receive state machine
// Receive state machine switch (rxState) {
switch (rxState) { case STATE_SYNC:
case STATE_SYNC: if ((rxbyte & TYPE_MASK) == TYPE_VER )
if ((rxbyte & TYPE_MASK) == TYPE_VER ) {
{ rxCS = updateCRC(0, &rxbyte, 1);
rxCS = updateCRC(0, &rxbyte, 1); rxType = rxbyte;
rxType = rxbyte; rxState = STATE_OBJID;
rxState = STATE_OBJID; rxCount = 0;
rxCount = 0; }
} break;
break; case STATE_OBJID:
case STATE_OBJID: rxTmpBuffer[rxCount++] = rxbyte;
rxTmpBuffer[rxCount++] = rxbyte; if (rxCount == 4)
if (rxCount == 4) {
{ // Search for object, if not found reset state machine
// Search for object, if not found reset state machine rxObjId = (qint32)qFromLittleEndian<quint32>(rxTmpBuffer);
rxObjId = (qint32)qFromLittleEndian<quint32>(rxTmpBuffer); UAVObject* rxObj = objMngr->getObject(rxObjId);
UAVObject* rxObj = objMngr->getObject(rxObjId); if (rxObj == NULL)
if (rxObj == NULL) {
{ rxState = STATE_SYNC;
rxState = STATE_SYNC; ++stats.rxErrors;
++stats.rxErrors; }
} else
else {
{ // Update checksum
// Update checksum rxCS = updateCRC(rxCS, rxTmpBuffer, 4);
rxCS = updateCRC(rxCS, rxTmpBuffer, 4); // Determine data length
// Determine data length if (rxType == TYPE_OBJ_REQ || rxType == TYPE_ACK)
if (rxType == TYPE_OBJ_REQ || rxType == TYPE_ACK) {
{ rxLength = 0;
rxLength = 0; }
} else
else {
{ rxLength = rxObj->getNumBytes();
rxLength = rxObj->getNumBytes(); }
} // Check length and determine next state
// Check length and determine next state if (rxLength >= MAX_PAYLOAD_LENGTH)
if (rxLength >= MAX_PAYLOAD_LENGTH) {
{ rxState = STATE_SYNC;
rxState = STATE_SYNC; ++stats.rxErrors;
++stats.rxErrors; }
} else
else {
{ // Check if this is a single instance object (i.e. if the instance ID field is coming next)
// Check if this is a single instance object (i.e. if the instance ID field is coming next) if ( rxObj->isSingleInstance() )
if ( rxObj->isSingleInstance() ) {
{ // If there is a payload get it, otherwise receive checksum
// If there is a payload get it, otherwise receive checksum if (rxLength > 0)
if (rxLength > 0) {
{ rxState = STATE_DATA;
rxState = STATE_DATA; }
} else
else {
{ rxState = STATE_CS;
rxState = STATE_CS; }
} rxInstId = 0;
rxInstId = 0; rxCount = 0;
rxCount = 0; }
} else
else {
{ rxState = STATE_INSTID;
rxState = STATE_INSTID; rxCount = 0;
rxCount = 0; }
} }
} }
} }
} break;
break; case STATE_INSTID:
case STATE_INSTID: rxTmpBuffer[rxCount++] = rxbyte;
rxTmpBuffer[rxCount++] = rxbyte; if (rxCount == 2)
if (rxCount == 2) {
{ rxInstId = (qint16)qFromLittleEndian<quint16>(rxTmpBuffer);
rxInstId = (qint16)qFromLittleEndian<quint16>(rxTmpBuffer); rxCS = updateCRC(rxCS, rxTmpBuffer, 2);
rxCS = updateCRC(rxCS, rxTmpBuffer, 2); rxCount = 0;
rxCount = 0; // If there is a payload get it, otherwise receive checksum
// If there is a payload get it, otherwise receive checksum if (rxLength > 0)
if (rxLength > 0) {
{ rxState = STATE_DATA;
rxState = STATE_DATA; }
} else
else {
{ rxState = STATE_CS;
rxState = STATE_CS; }
} }
} break;
break; case STATE_DATA:
case STATE_DATA: rxBuffer[rxCount++] = rxbyte;
rxBuffer[rxCount++] = rxbyte; if (rxCount == rxLength)
if (rxCount == rxLength) {
{ rxCS = updateCRC(rxCS, rxBuffer, rxLength);
rxCS = updateCRC(rxCS, rxBuffer, rxLength); rxState = STATE_CS;
rxState = STATE_CS; rxCount = 0;
rxCount = 0; }
} break;
break; case STATE_CS:
case STATE_CS: rxCSPacket = rxbyte;
rxCSPacket = rxbyte; if (rxCS == rxCSPacket)
if (rxCS == rxCSPacket) {
{ mutex->lock();
mutex->lock(); receiveObject(rxType, rxObjId, rxInstId, rxBuffer, rxLength);
receiveObject(rxType, rxObjId, rxInstId, rxBuffer, rxLength); stats.rxObjectBytes += rxLength;
stats.rxObjectBytes += rxLength; ++stats.rxObjects;
++stats.rxObjects; mutex->unlock();
mutex->unlock(); }
} else
else {
{ ++stats.rxErrors;
++stats.rxErrors; }
} rxState = STATE_SYNC;
rxState = STATE_SYNC; break;
break; default:
default: rxState = STATE_SYNC;
rxState = STATE_SYNC; ++stats.rxErrors;
++stats.rxErrors; }
}
// Done
// Done return true;
return true; }
}
/**
/** * Receive an object. This function process objects received through the telemetry stream.
* 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] 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] obj Handle of the received object * \param[in] instId The instance ID of UAVOBJ_ALL_INSTANCES for all instances.
* \param[in] instId The instance ID of UAVOBJ_ALL_INSTANCES for all instances. * \param[in] data Data buffer
* \param[in] data Data buffer * \param[in] length Buffer length
* \param[in] length Buffer length * \return Success (true), Failure (false)
* \return Success (true), Failure (false) */
*/ bool UAVTalk::receiveObject(quint8 type, quint32 objId, quint16 instId, quint8* data, qint32 length)
bool UAVTalk::receiveObject(quint8 type, quint32 objId, quint16 instId, quint8* data, qint32 length) {
{ UAVObject* obj = NULL;
UAVObject* obj = NULL; bool error = false;
bool error = false; bool allInstances = (instId == ALL_INSTANCES? true : false);
bool allInstances = (instId == ALL_INSTANCES? true : false);
// Process message type
// Process message type switch (type) {
switch (type) { case TYPE_OBJ:
case TYPE_OBJ: // All instances, not allowed for OBJ messages
// All instances, not allowed for OBJ messages if (!allInstances)
if (!allInstances) {
{ // Get object and update its data
// Get object and update its data obj = updateObject(objId, instId, data);
obj = updateObject(objId, instId, data); // Check if an ack is pending
// Check if an ack is pending if ( obj != NULL )
if ( obj != NULL ) {
{ updateAck(obj);
updateAck(obj); }
} else
else {
{ error = true;
error = true; }
} }
} else
else {
{ error = true;
error = true; }
} break;
break; case TYPE_OBJ_ACK:
case TYPE_OBJ_ACK: // All instances, not allowed for OBJ_ACK messages
// All instances, not allowed for OBJ_ACK messages if (!allInstances)
if (!allInstances) {
{ // Get object and update its data
// Get object and update its data obj = updateObject(objId, instId, data);
obj = updateObject(objId, instId, data); // Transmit ACK
// Transmit ACK if ( obj != NULL )
if ( obj != NULL ) {
{ transmitObject(obj, TYPE_ACK, false);
transmitObject(obj, TYPE_ACK, false); }
} else
else {
{ error = true;
error = true; }
} }
} else
else {
{ error = true;
error = true; }
} break;
break; case TYPE_OBJ_REQ:
case TYPE_OBJ_REQ: // Get object, if all instances are requested get instance 0 of the object
// Get object, if all instances are requested get instance 0 of the object if (allInstances)
if (allInstances) {
{ obj = objMngr->getObject(objId);
obj = objMngr->getObject(objId); }
} else
else {
{ obj = objMngr->getObject(objId, instId);
obj = objMngr->getObject(objId, instId); }
} // If object was found transmit it
// If object was found transmit it if (obj != NULL)
if (obj != NULL) {
{ transmitObject(obj, TYPE_OBJ, allInstances);
transmitObject(obj, TYPE_OBJ, allInstances); }
} else
else {
{ error = true;
error = true; }
} break;
break; case TYPE_ACK:
case TYPE_ACK: // All instances, not allowed for ACK messages
// All instances, not allowed for ACK messages if (!allInstances)
if (!allInstances) {
{ // Get object
// Get object obj = objMngr->getObject(objId, instId);
obj = objMngr->getObject(objId, instId); // Check if an ack is pending
// Check if an ack is pending if (obj != NULL)
if (obj != NULL) {
{ updateAck(obj);
updateAck(obj); }
} else
else {
{ error = true;
error = true; }
} }
} break;
break; default:
default: error = true;
error = true; }
} // Done
// Done return !error;
return !error; }
}
/**
/** * Update the data of an object from a byte array (unpack).
* Update the data of an object from a byte array (unpack). * If the object instance could not be found in the list, then a
* If the object instance could not be found in the list, then a * new one is created.
* new one is created. */
*/ UAVObject* UAVTalk::updateObject(quint32 objId, quint16 instId, quint8* data)
UAVObject* UAVTalk::updateObject(quint32 objId, quint16 instId, quint8* data) {
{ // Get object
// Get object UAVObject* obj = objMngr->getObject(objId, instId);
UAVObject* obj = objMngr->getObject(objId, instId); // If the instance does not exist create it
// If the instance does not exist create it if (obj == NULL)
if (obj == NULL) {
{ // Get the object type
// Get the object type UAVObject* tobj = objMngr->getObject(objId);
UAVObject* tobj = objMngr->getObject(objId); if (tobj == NULL)
if (tobj == NULL) {
{ return NULL;
return NULL; }
} // Make sure this is a data object
// Make sure this is a data object UAVDataObject* dobj = dynamic_cast<UAVDataObject*>(tobj);
UAVDataObject* dobj = dynamic_cast<UAVDataObject*>(tobj); if (dobj == NULL)
if (dobj == NULL) {
{ return NULL;
return NULL; }
} // Create a new instance, unpack and register
// Create a new instance, unpack and register UAVDataObject* instobj = dobj->clone(instId);
UAVDataObject* instobj = dobj->clone(instId); if ( !objMngr->registerObject(instobj) )
if ( !objMngr->registerObject(instobj) ) {
{ return NULL;
return NULL; }
} instobj->unpack(data);
instobj->unpack(data); return instobj;
return instobj; }
} else
else {
{ // Unpack data into object instance
// Unpack data into object instance obj->unpack(data);
obj->unpack(data); return obj;
return obj; }
} }
}
/**
/** * Check if a transaction is pending and if yes complete it.
* Check if a transaction is pending and if yes complete it. */
*/ void UAVTalk::updateAck(UAVObject* obj)
void UAVTalk::updateAck(UAVObject* obj) {
{ if (respObj != NULL && respObj->getObjID() == obj->getObjID() && (respObj->getInstID() == obj->getInstID() || respAllInstances))
if (respObj != NULL && respObj->getObjID() == obj->getObjID() && (respObj->getInstID() == obj->getInstID() || respAllInstances)) {
{ respObj = NULL;
respObj = NULL; emit transactionCompleted(obj);
emit transactionCompleted(obj); }
} }
}
/**
/** * Send an object through the telemetry link.
* Send an object through the telemetry link. * \param[in] obj Object to send
* \param[in] obj Object to send * \param[in] type Transaction type
* \param[in] type Transaction type * \param[in] allInstances True is all instances of the object are to be sent
* \param[in] allInstances True is all instances of the object are to be sent * \return Success (true), Failure (false)
* \return Success (true), Failure (false) */
*/ bool UAVTalk::transmitObject(UAVObject* obj, quint8 type, bool allInstances)
bool UAVTalk::transmitObject(UAVObject* obj, quint8 type, bool allInstances) {
{ // If all instances are requested on a single instance object it is an error
// If all instances are requested on a single instance object it is an error if (allInstances && obj->isSingleInstance())
if (allInstances && obj->isSingleInstance()) {
{ allInstances = false;
allInstances = false; }
}
// Process message type
// Process message type if ( type == TYPE_OBJ || type == TYPE_OBJ_ACK )
if ( type == TYPE_OBJ || type == TYPE_OBJ_ACK ) {
{ if (allInstances)
if (allInstances) {
{ // Get number of instances
// Get number of instances quint32 numInst = objMngr->getNumInstances(obj->getObjID());
quint32 numInst = objMngr->getNumInstances(obj->getObjID()); // Send all instances
// Send all instances for (quint32 instId = 0; instId < numInst; ++instId)
for (quint32 instId = 0; instId < numInst; ++instId) {
{ UAVObject* inst = objMngr->getObject(obj->getObjID(), instId);
UAVObject* inst = objMngr->getObject(obj->getObjID(), instId); transmitSingleObject(inst, type, false);
transmitSingleObject(inst, type, false); }
} return true;
return true; }
} else
else {
{ return transmitSingleObject(obj, type, false);
return transmitSingleObject(obj, type, false); }
} }
} else if (type == TYPE_OBJ_REQ)
else if (type == TYPE_OBJ_REQ) {
{ return transmitSingleObject(obj, TYPE_OBJ_REQ, allInstances);
return transmitSingleObject(obj, TYPE_OBJ_REQ, allInstances); }
} else if (type == TYPE_ACK)
else if (type == TYPE_ACK) {
{ if (!allInstances)
if (!allInstances) {
{ return transmitSingleObject(obj, TYPE_ACK, false);
return transmitSingleObject(obj, TYPE_ACK, false); }
} else
else {
{ return false;
return false; }
} }
} else
else {
{ return false;
return false; }
} }
}
/**
/** * Send an object through the telemetry link.
* Send an object through the telemetry link. * \param[in] obj Object handle to send
* \param[in] obj Object handle to send * \param[in] type Transaction type
* \param[in] type Transaction type * \return Success (true), Failure (false)
* \return Success (true), Failure (false) */
*/ bool UAVTalk::transmitSingleObject(UAVObject* obj, quint8 type, bool allInstances)
bool UAVTalk::transmitSingleObject(UAVObject* obj, quint8 type, bool allInstances) {
{ qint32 length;
qint32 length; qint32 dataOffset;
qint32 dataOffset; quint32 objId;
quint32 objId; quint16 instId;
quint16 instId; quint16 allInstId = ALL_INSTANCES;
quint16 allInstId = ALL_INSTANCES;
// Setup type and object id fields
// Setup type and object id fields objId = obj->getObjID();
objId = obj->getObjID(); txBuffer[0] = type;
txBuffer[0] = type; qToLittleEndian<quint32>(objId, &txBuffer[1]);
qToLittleEndian<quint32>(objId, &txBuffer[1]);
// Setup instance ID if one is required
// Setup instance ID if one is required if ( obj->isSingleInstance() )
if ( obj->isSingleInstance() ) {
{ dataOffset = 5;
dataOffset = 5; }
} else
else {
{ // Check if all instances are requested
// Check if all instances are requested if (allInstances)
if (allInstances) {
{ qToLittleEndian<quint16>(allInstId, &txBuffer[5]);
qToLittleEndian<quint16>(allInstId, &txBuffer[5]); }
} else
else {
{ instId = obj->getInstID();
instId = obj->getInstID(); qToLittleEndian<quint16>(instId, &txBuffer[5]);
qToLittleEndian<quint16>(instId, &txBuffer[5]); }
} dataOffset = 7;
dataOffset = 7; }
}
// Determine data length
// Determine data length if (type == TYPE_OBJ_REQ || type == TYPE_ACK)
if (type == TYPE_OBJ_REQ || type == TYPE_ACK) {
{ length = 0;
length = 0; }
} else
else {
{ length = obj->getNumBytes();
length = obj->getNumBytes(); }
}
// Check length
// Check length if (length >= MAX_PAYLOAD_LENGTH)
if (length >= MAX_PAYLOAD_LENGTH) {
{ return false;
return false; }
}
// Copy data (if any)
// Copy data (if any) if (length > 0)
if (length > 0) {
{ if ( !obj->pack(&txBuffer[dataOffset]) )
if ( !obj->pack(&txBuffer[dataOffset]) ) {
{ return false;
return false; }
} }
}
// Calculate checksum
// Calculate checksum txBuffer[dataOffset+length] = updateCRC(0, txBuffer, dataOffset+length);
txBuffer[dataOffset+length] = updateCRC(0, txBuffer, dataOffset+length);
// Send buffer, check that the transmit backlog does not grow above limit
// Send buffer, check that the transmit backlog does not grow above limit if ( io->bytesToWrite() < TX_BUFFER_SIZE )
if ( io->bytesToWrite() < TX_BUFFER_SIZE ) {
{ io->write((const char*)txBuffer, dataOffset+length+CHECKSUM_LENGTH);
io->write((const char*)txBuffer, dataOffset+length+CHECKSUM_LENGTH); }
} else
else {
{ ++stats.txErrors;
++stats.txErrors; return false;
return false; }
}
// Update stats
// Update stats ++stats.txObjects;
++stats.txObjects; stats.txBytes += dataOffset+length+CHECKSUM_LENGTH;
stats.txBytes += dataOffset+length+CHECKSUM_LENGTH; stats.txObjectBytes += length;
stats.txObjectBytes += length;
// Done
// Done return true;
return true; }
}
/**
/** * Update the crc value with new data.
* Update the crc value with new data. *
* * Generated by pycrc v0.7.5, http://www.tty1.net/pycrc/
* Generated by pycrc v0.7.5, http://www.tty1.net/pycrc/ * using the configuration:
* using the configuration: * Width = 8
* Width = 8 * Poly = 0x07
* Poly = 0x07 * XorIn = 0x00
* XorIn = 0x00 * ReflectIn = False
* ReflectIn = False * XorOut = 0x00
* XorOut = 0x00 * ReflectOut = False
* ReflectOut = False * Algorithm = table-driven
* Algorithm = table-driven *
* * \param crc The current crc value.
* \param crc The current crc value. * \param data Pointer to a buffer of \a data_len bytes.
* \param data Pointer to a buffer of \a data_len bytes. * \param length Number of bytes in the \a data buffer.
* \param length Number of bytes in the \a data buffer. * \return The updated crc value.
* \return The updated crc value. */
*/ quint8 UAVTalk::updateCRC(quint8 crc, const quint8* data, qint32 length)
quint8 UAVTalk::updateCRC(quint8 crc, const quint8* data, qint32 length) {
{ quint32 tbl_idx;
quint32 tbl_idx;
while (length--) {
while (length--) { tbl_idx = ((crc >> 0) ^ *data) & 0xff;
tbl_idx = ((crc >> 0) ^ *data) & 0xff; crc = (crc_table[tbl_idx] ^ (crc << 8)) & 0xff;
crc = (crc_table[tbl_idx] ^ (crc << 8)) & 0xff; data++;
data++; }
} return crc;
return crc; }
}

View File

@ -1,117 +1,116 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavtalk.h * @file uavtalk.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. * @brief
* @brief * @see The GNU Public License (GPL) Version 3
* @see The GNU Public License (GPL) Version 3 * @defgroup uavtalkplugin
* @defgroup * @{
* @{ *
* *****************************************************************************/
*****************************************************************************/ /*
/* * This program is free software; you can redistribute it and/or modify
* 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
* it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or
* the Free Software Foundation; either version 3 of the License, or * (at your option) any later version.
* (at your option) any later version. *
* * This program is distributed in the hope that it will be useful, but
* This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details.
* for more details. *
* * You should have received a copy of the GNU General Public License along
* 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.,
* with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
*/ #ifndef UAVTALK_H
#ifndef UAVTALK_H #define UAVTALK_H
#define UAVTALK_H
#include <QIODevice>
#include <QIODevice> #include <QMutex>
#include <QMutex> #include <QMutexLocker>
#include <QMutexLocker> #include <QSemaphore>
#include <QSemaphore> #include "uavobjects/uavobjectmanager.h"
#include "uavobjects/uavobjectmanager.h"
class UAVTalk: public QObject
class UAVTalk: public QObject {
{ Q_OBJECT
Q_OBJECT
public:
public: typedef struct {
typedef struct { quint32 txBytes;
quint32 txBytes; quint32 rxBytes;
quint32 rxBytes; quint32 txObjectBytes;
quint32 txObjectBytes; quint32 rxObjectBytes;
quint32 rxObjectBytes; quint32 rxObjects;
quint32 rxObjects; quint32 txObjects;
quint32 txObjects; quint32 txErrors;
quint32 txErrors; quint32 rxErrors;
quint32 rxErrors; } ComStats;
} ComStats;
UAVTalk(QIODevice* iodev, UAVObjectManager* objMngr);
UAVTalk(QIODevice* iodev, UAVObjectManager* objMngr);
bool sendObject(UAVObject* obj, bool acked, bool allInstances);
bool sendObject(UAVObject* obj, bool acked, bool allInstances); bool sendObjectRequest(UAVObject* obj, bool allInstances);
bool sendObjectRequest(UAVObject* obj, bool allInstances); void cancelTransaction();
void cancelTransaction(); ComStats getStats();
ComStats getStats(); void resetStats();
void resetStats();
signals:
signals: void transactionCompleted(UAVObject* obj);
void transactionCompleted(UAVObject* obj);
private slots:
private slots: void processInputStream(void);
void processInputStream(void);
private:
private: // Constants
// Constants static const int TYPE_MASK = 0xFC;
static const int TYPE_MASK = 0xFC; static const int TYPE_VER = 0x10;
static const int TYPE_VER = 0x10; static const int TYPE_OBJ = (TYPE_VER | 0x00);
static const int TYPE_OBJ = (TYPE_VER | 0x00); static const int TYPE_OBJ_REQ = (TYPE_VER | 0x01);
static const int TYPE_OBJ_REQ = (TYPE_VER | 0x01); static const int TYPE_OBJ_ACK = (TYPE_VER | 0x02);
static const int TYPE_OBJ_ACK = (TYPE_VER | 0x02); static const int TYPE_ACK = (TYPE_VER | 0x03);
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 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 CHECKSUM_LENGTH = 1; static const int MAX_PAYLOAD_LENGTH = 256;
static const int MAX_PAYLOAD_LENGTH = 256; static const int MAX_PACKET_LENGTH = (HEADER_LENGTH+MAX_PAYLOAD_LENGTH+CHECKSUM_LENGTH);
static const int MAX_PACKET_LENGTH = (HEADER_LENGTH+MAX_PAYLOAD_LENGTH+CHECKSUM_LENGTH); static const quint16 ALL_INSTANCES = 0xFFFF;
static const quint16 ALL_INSTANCES = 0xFFFF; static const int TX_BUFFER_SIZE = 2*1024;
static const int TX_BUFFER_SIZE = 2*1024; static const quint8 crc_table[256];
static const quint8 crc_table[256];
// Types
// Types typedef enum {STATE_SYNC, STATE_OBJID, STATE_INSTID, STATE_DATA, STATE_CS} RxStateType;
typedef enum {STATE_SYNC, STATE_OBJID, STATE_INSTID, STATE_DATA, STATE_CS} RxStateType;
// Variables
// Variables QIODevice* io;
QIODevice* io; UAVObjectManager* objMngr;
UAVObjectManager* objMngr; QMutex* mutex;
QMutex* mutex; UAVObject* respObj;
UAVObject* respObj; bool respAllInstances;
bool respAllInstances; quint8 rxBuffer[MAX_PACKET_LENGTH];
quint8 rxBuffer[MAX_PACKET_LENGTH]; quint8 txBuffer[MAX_PACKET_LENGTH];
quint8 txBuffer[MAX_PACKET_LENGTH]; // Variables used by the receive state machine
// Variables used by the receive state machine quint8 rxTmpBuffer[4];
quint8 rxTmpBuffer[4]; quint8 rxType;
quint8 rxType; quint32 rxObjId;
quint32 rxObjId; quint16 rxInstId;
quint16 rxInstId; quint8 rxLength;
quint8 rxLength; quint8 rxCSPacket, rxCS;
quint8 rxCSPacket, rxCS; qint32 rxCount;
qint32 rxCount; RxStateType rxState;
RxStateType rxState; ComStats stats;
ComStats stats;
// Methods
// Methods bool objectTransaction(UAVObject* obj, quint8 type, bool allInstances);
bool objectTransaction(UAVObject* obj, quint8 type, bool allInstances); bool processInputByte(quint8 rxbyte);
bool processInputByte(quint8 rxbyte); bool receiveObject(quint8 type, quint32 objId, quint16 instId, quint8* data, qint32 length);
bool receiveObject(quint8 type, quint32 objId, quint16 instId, quint8* data, qint32 length); UAVObject* updateObject(quint32 objId, quint16 instId, quint8* data);
UAVObject* updateObject(quint32 objId, quint16 instId, quint8* data); void updateAck(UAVObject* obj);
void updateAck(UAVObject* obj); bool transmitObject(UAVObject* obj, quint8 type, bool allInstances);
bool transmitObject(UAVObject* obj, quint8 type, bool allInstances); bool transmitSingleObject(UAVObject* obj, quint8 type, bool allInstances);
bool transmitSingleObject(UAVObject* obj, quint8 type, bool allInstances); quint8 updateCRC(quint8 crc, const quint8* data, qint32 length);
quint8 updateCRC(quint8 crc, const quint8* data, qint32 length);
};
};
#endif // UAVTALK_H
#endif // UAVTALK_H

View File

@ -1,40 +1,39 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavobjects_global.h * @file uavobjects_global.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. * @brief
* @brief * @see The GNU Public License (GPL) Version 3
* @see The GNU Public License (GPL) Version 3 * @defgroup uavtalkplugin
* @defgroup uavobjects_plugin * @{
* @{ *
* *****************************************************************************/
*****************************************************************************/ /*
/* * This program is free software; you can redistribute it and/or modify
* 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
* it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or
* the Free Software Foundation; either version 3 of the License, or * (at your option) any later version.
* (at your option) any later version. *
* * This program is distributed in the hope that it will be useful, but
* This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details.
* for more details. *
* * You should have received a copy of the GNU General Public License along
* 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.,
* with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
*/
#ifndef UAVTALK_GLOBAL_H
#ifndef UAVTALK_GLOBAL_H #define UAVTALK_GLOBAL_H
#define UAVTALK_GLOBAL_H
#include <QtCore/qglobal.h>
#include <QtCore/qglobal.h>
#if defined(UAVTALK_LIBRARY)
#if defined(UAVTALK_LIBRARY) # define UAVTALK_EXPORT Q_DECL_EXPORT
# define UAVTALK_EXPORT Q_DECL_EXPORT #else
#else # define UAVTALK_EXPORT Q_DECL_IMPORT
# define UAVTALK_EXPORT Q_DECL_IMPORT #endif
#endif
#endif // UAVTALK_GLOBAL_H
#endif // UAVTALK_GLOBAL_H

View File

@ -1,84 +1,83 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavtalkplugin.cpp * @file uavtalkplugin.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. * @brief
* @brief * @see The GNU Public License (GPL) Version 3
* @see The GNU Public License (GPL) Version 3 * @defgroup uavtalkplugin
* @defgroup * @{
* @{ *
* *****************************************************************************/
*****************************************************************************/ /*
/* * This program is free software; you can redistribute it and/or modify
* 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
* it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or
* the Free Software Foundation; either version 3 of the License, or * (at your option) any later version.
* (at your option) any later version. *
* * This program is distributed in the hope that it will be useful, but
* This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details.
* for more details. *
* * You should have received a copy of the GNU General Public License along
* 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.,
* with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
*/ #include "uavtalkplugin.h"
#include "uavtalkplugin.h"
#include <coreplugin/icore.h>
#include <coreplugin/icore.h> #include <coreplugin/connectionmanager.h>
#include <coreplugin/connectionmanager.h>
UAVTalkPlugin::UAVTalkPlugin()
UAVTalkPlugin::UAVTalkPlugin() {
{
}
}
UAVTalkPlugin::~UAVTalkPlugin()
UAVTalkPlugin::~UAVTalkPlugin() {
{
}
}
void UAVTalkPlugin::extensionsInitialized()
void UAVTalkPlugin::extensionsInitialized() {
{ // Get UAVObjectManager instance
// Get UAVObjectManager instance ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance(); objMngr = pm->getObject<UAVObjectManager>();
objMngr = pm->getObject<UAVObjectManager>();
// Create TelemetryManager
// Create TelemetryManager telMngr = new TelemetryManager();
telMngr = new TelemetryManager(); addAutoReleasedObject(telMngr);
addAutoReleasedObject(telMngr);
// Connect to connection manager so we get notified when the user connect to his device
// Connect to connection manager so we get notified when the user connect to his device Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager(); QObject::connect(cm, SIGNAL(deviceConnected(QIODevice *)),
QObject::connect(cm, SIGNAL(deviceConnected(QIODevice *)), this, SLOT(onDeviceConnect(QIODevice *)));
this, SLOT(onDeviceConnect(QIODevice *))); QObject::connect(cm, SIGNAL(deviceDisconnected()),
QObject::connect(cm, SIGNAL(deviceDisconnected()), this, SLOT(onDeviceDisconnect()));
this, SLOT(onDeviceDisconnect())); }
}
bool UAVTalkPlugin::initialize(const QStringList & arguments, QString * errorString)
bool UAVTalkPlugin::initialize(const QStringList & arguments, QString * errorString) {
{ // Done
// Done Q_UNUSED(arguments);
Q_UNUSED(arguments); Q_UNUSED(errorString);
Q_UNUSED(errorString); return true;
return true; }
}
void UAVTalkPlugin::shutdown()
void UAVTalkPlugin::shutdown() {
{
}
}
void UAVTalkPlugin::onDeviceConnect(QIODevice *dev)
void UAVTalkPlugin::onDeviceConnect(QIODevice *dev) {
{ telMngr->start(dev);
telMngr->start(dev); }
}
void UAVTalkPlugin::onDeviceDisconnect()
void UAVTalkPlugin::onDeviceDisconnect() {
{ telMngr->stop();
telMngr->stop(); }
}
Q_EXPORT_PLUGIN(UAVTalkPlugin)
Q_EXPORT_PLUGIN(UAVTalkPlugin)

View File

@ -1,61 +1,60 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file uavtalkplugin.h * @file uavtalkplugin.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. * @brief
* @brief * @see The GNU Public License (GPL) Version 3
* @see The GNU Public License (GPL) Version 3 * @defgroup uavtalkplugin
* @defgroup * @{
* @{ *
* *****************************************************************************/
*****************************************************************************/ /*
/* * This program is free software; you can redistribute it and/or modify
* 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
* it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or
* the Free Software Foundation; either version 3 of the License, or * (at your option) any later version.
* (at your option) any later version. *
* * This program is distributed in the hope that it will be useful, but
* This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details.
* for more details. *
* * You should have received a copy of the GNU General Public License along
* 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.,
* with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
*/ #ifndef UAVTALKPLUGIN_H
#ifndef UAVTALKPLUGIN_H #define UAVTALKPLUGIN_H
#define UAVTALKPLUGIN_H
#include <extensionsystem/iplugin.h>
#include <extensionsystem/iplugin.h> #include <extensionsystem/pluginmanager.h>
#include <extensionsystem/pluginmanager.h> #include <QtPlugin>
#include <QtPlugin> #include "telemetrymonitor.h"
#include "telemetrymonitor.h" #include "telemetry.h"
#include "telemetry.h" #include "uavtalk.h"
#include "uavtalk.h" #include "telemetrymanager.h"
#include "telemetrymanager.h" #include "uavobjects/uavobjectmanager.h"
#include "uavobjects/uavobjectmanager.h"
class UAVTALK_EXPORT UAVTalkPlugin: public ExtensionSystem::IPlugin
class UAVTALK_EXPORT UAVTalkPlugin: public ExtensionSystem::IPlugin {
{ Q_OBJECT
Q_OBJECT
public:
public: UAVTalkPlugin();
UAVTalkPlugin(); ~UAVTalkPlugin();
~UAVTalkPlugin();
void extensionsInitialized();
void extensionsInitialized(); bool initialize(const QStringList & arguments, QString * errorString);
bool initialize(const QStringList & arguments, QString * errorString); void shutdown();
void shutdown();
protected slots:
protected slots: void onDeviceConnect(QIODevice *dev);
void onDeviceConnect(QIODevice *dev); void onDeviceDisconnect();
void onDeviceDisconnect();
private:
private: UAVObjectManager* objMngr;
UAVObjectManager* objMngr; TelemetryManager* telMngr;
TelemetryManager* telMngr; };
};
#endif // UAVTALKPLUGIN_H
#endif // UAVTALKPLUGIN_H

View File

@ -5,7 +5,7 @@
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Uploader Plugin Gadget * @brief Uploader Plugin Gadget
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup Uploader * @defgroup uploaderplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/

View File

@ -5,7 +5,7 @@
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Uploader Plugin Gadget configuration * @brief Uploader Plugin Gadget configuration
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup Uploader * @defgroup uploaderplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/

View File

@ -5,7 +5,7 @@
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Uploader Plugin Gadget configuration * @brief Uploader Plugin Gadget configuration
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup Uploader * @defgroup uploaderplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/

View File

@ -5,7 +5,7 @@
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Uploader Plugin Gadget configuration * @brief Uploader Plugin Gadget configuration
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup Uploader * @defgroup uploaderplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/

View File

@ -5,7 +5,7 @@
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Uploader Plugin Gadget factory * @brief Uploader Plugin Gadget factory
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup Uploader * @defgroup uploaderplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/

View File

@ -5,7 +5,7 @@
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Uploader Plugin Gadget factory * @brief Uploader Plugin Gadget factory
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup Uploader * @defgroup uploaderplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/

View File

@ -5,7 +5,7 @@
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Uploader Plugin Gadget options page * @brief Uploader Plugin Gadget options page
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup Uploader * @defgroup uploaderplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/

View File

@ -5,7 +5,7 @@
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Uploader Plugin Gadget options page * @brief Uploader Plugin Gadget options page
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup Uploader * @defgroup uploaderplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/

View File

@ -5,7 +5,7 @@
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Uploader Plugin Gadget widget * @brief Uploader Plugin Gadget widget
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup Uploader * @defgroup uploaderplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/

View File

@ -5,7 +5,7 @@
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Uploader Plugin Gadget widget * @brief Uploader Plugin Gadget widget
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup Uploader * @defgroup uploaderplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/

View File

@ -6,7 +6,7 @@
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @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 * @brief A plugin to upload a file using y-modem protocol and a serial port
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup Uploader * @defgroup uploaderplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/

View File

@ -5,7 +5,7 @@
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @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 * @brief A plugin to upload a file using y-modem protocol and a serial port
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup Uploader * @defgroup uploaderplugin
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/